From cdf883c3cdda05e8b84bc637e0ef7b34270d722a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Mon, 13 Nov 2017 17:20:45 +0100 Subject: [PATCH] Compiler - OP_UNIFORMS --- control.hh | 2 ++ opast.cc | 5 +++-- opast.hh | 7 ++++--- opcomp.cc | 12 ++++++++++++ ops.cc | 2 ++ 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/control.hh b/control.hh index 015a418..fbd78bf 100644 --- a/control.hh +++ b/control.hh @@ -23,6 +23,7 @@ enum E_OpType // OP_LOAD , OP_SLOAD , + OP_CONST , // OP_FP_LOAD , OP_FP_STORE , @@ -57,6 +58,7 @@ enum E_OpType OP_USE_PIPELINE , OP_USE_PROGRAM , OP_USE_TEXTURE , + OP_UNIFORMS , // OP_FULLSCREEN , OP_CLEAR , diff --git a/opast.cc b/opast.cc index 1fa44f4..baf62b4 100644 --- a/opast.cc +++ b/opast.cc @@ -260,8 +260,9 @@ A_Node* opast::ASTVisitorBrowser( case A_Node::OP_UNIFORMS: { auto& n( (T_UniformsInstrNode&) node ); - if ( child < n.values( ) ) { - return &n.value( child ); + const auto nv( n.values( ) ); + if ( child < nv ) { + return &n.value( nv - child - 1 ); } break; } diff --git a/opast.hh b/opast.hh index e9c53cc..c7d4d67 100644 --- a/opast.hh +++ b/opast.hh @@ -1032,7 +1032,7 @@ class T_UniformsInstrNode : public A_InstructionNode T_SRDLocation progIdLocation_; uint32_t uloc_; T_SRDLocation ulocLocation_; - T_StaticArray< P_ExpressionNode , 4 > values_; + T_StaticArray< P_ArgumentNode , 4 > values_; public: T_UniformsInstrNode( T_InstrListNode& parent , @@ -1060,13 +1060,14 @@ class T_UniformsInstrNode : public A_InstructionNode void addValue( P_ExpressionNode value ) noexcept { if ( value ) { - values_.add( std::move( value ) ); + values_.add( NewOwned< T_ArgumentNode >( + *this , std::move( value ) ) ); } } uint32_t values( ) const noexcept { return values_.size( ); } - A_ExpressionNode& value( const uint32_t index ) const noexcept + T_ArgumentNode& value( const uint32_t index ) const noexcept { return *values_[ index ]; } }; diff --git a/opcomp.cc b/opcomp.cc index ac4c08d..a564400 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -531,6 +531,18 @@ bool T_CompilerImpl_::compileNode( } break; + case A_Node::OP_UNIFORMS: + if ( exit ) { + auto& un( (T_UniformsInstrNode&) node ); + addInstruction( OP_CONST , un.uloc( ) , un.ulocLocation( ) ); + addInstruction( OP_PUSH , un.ulocLocation( ) ); + processIdentifier( funcIndex , un.progId( ) , un.progIdLocation( ) ); + addInstruction( OP_UNIFORMS , { un.values( ) , un.integers( ) ? 1u : 0u } , + un.location( ) ); + sdMain -= un.values( ); + } + break; + //- RENDERING ------------------------------------------------------------------------- diff --git a/ops.cc b/ops.cc index 694e0a9..3c602ca 100644 --- a/ops.cc +++ b/ops.cc @@ -95,6 +95,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { // infos.add( E_OpType::OP_LOAD , T_OpInfo{ "load" , 1 } ); infos.add( E_OpType::OP_SLOAD , T_OpInfo{ "load-stack" , 1 } ); + infos.add( E_OpType::OP_CONST , T_OpInfo{ "const" , 1 } ); // infos.add( E_OpType::OP_FP_LOAD , T_OpInfo{ "fp-load" , 1 , OpStackFPU{ 1 } } ); infos.add( E_OpType::OP_FP_SLOAD , T_OpInfo{ "fp-load-stack" , 1 , OpStackFPU{ 1 } } ); @@ -129,6 +130,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { infos.add( E_OpType::OP_USE_PIPELINE , T_OpInfo{ "use-pipeline" , 0 , OpStackMain{ -1 } } ); infos.add( E_OpType::OP_USE_PROGRAM , T_OpInfo{ "use-program" , 0 , OpStackMain{ -1 } } ); infos.add( E_OpType::OP_USE_TEXTURE , T_OpInfo{ "use-texture" , 1 , OpStackMain{ -2 } } ); + infos.add( E_OpType::OP_UNIFORMS , T_OpInfo{ "uniforms" , 2 , OpStackMain{ -2 } } ); // infos.add( E_OpType::OP_FULLSCREEN , T_OpInfo{ "fullscreen" } ); infos.add( E_OpType::OP_CLEAR , T_OpInfo{ "clear" , 0 , OpStackMain{ -4 } } );