Compiler - OP_UNIFORMS

This commit is contained in:
Emmanuel BENOîT 2017-11-13 17:20:45 +01:00
parent d6fb6f9831
commit cdf883c3cd
5 changed files with 23 additions and 5 deletions

View file

@ -23,6 +23,7 @@ enum E_OpType
// //
OP_LOAD , OP_LOAD ,
OP_SLOAD , OP_SLOAD ,
OP_CONST ,
// //
OP_FP_LOAD , OP_FP_LOAD ,
OP_FP_STORE , OP_FP_STORE ,
@ -57,6 +58,7 @@ enum E_OpType
OP_USE_PIPELINE , OP_USE_PIPELINE ,
OP_USE_PROGRAM , OP_USE_PROGRAM ,
OP_USE_TEXTURE , OP_USE_TEXTURE ,
OP_UNIFORMS ,
// //
OP_FULLSCREEN , OP_FULLSCREEN ,
OP_CLEAR , OP_CLEAR ,

View file

@ -260,8 +260,9 @@ A_Node* opast::ASTVisitorBrowser(
case A_Node::OP_UNIFORMS: case A_Node::OP_UNIFORMS:
{ {
auto& n( (T_UniformsInstrNode&) node ); auto& n( (T_UniformsInstrNode&) node );
if ( child < n.values( ) ) { const auto nv( n.values( ) );
return &n.value( child ); if ( child < nv ) {
return &n.value( nv - child - 1 );
} }
break; break;
} }

View file

@ -1032,7 +1032,7 @@ class T_UniformsInstrNode : public A_InstructionNode
T_SRDLocation progIdLocation_; T_SRDLocation progIdLocation_;
uint32_t uloc_; uint32_t uloc_;
T_SRDLocation ulocLocation_; T_SRDLocation ulocLocation_;
T_StaticArray< P_ExpressionNode , 4 > values_; T_StaticArray< P_ArgumentNode , 4 > values_;
public: public:
T_UniformsInstrNode( T_InstrListNode& parent , T_UniformsInstrNode( T_InstrListNode& parent ,
@ -1060,13 +1060,14 @@ class T_UniformsInstrNode : public A_InstructionNode
void addValue( P_ExpressionNode value ) noexcept void addValue( P_ExpressionNode value ) noexcept
{ {
if ( value ) { if ( value ) {
values_.add( std::move( value ) ); values_.add( NewOwned< T_ArgumentNode >(
*this , std::move( value ) ) );
} }
} }
uint32_t values( ) const noexcept uint32_t values( ) const noexcept
{ return values_.size( ); } { return values_.size( ); }
A_ExpressionNode& value( const uint32_t index ) const noexcept T_ArgumentNode& value( const uint32_t index ) const noexcept
{ return *values_[ index ]; } { return *values_[ index ]; }
}; };

View file

@ -531,6 +531,18 @@ bool T_CompilerImpl_::compileNode(
} }
break; 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 ------------------------------------------------------------------------- //- RENDERING -------------------------------------------------------------------------

2
ops.cc
View file

@ -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_LOAD , T_OpInfo{ "load" , 1 } );
infos.add( E_OpType::OP_SLOAD , T_OpInfo{ "load-stack" , 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_LOAD , T_OpInfo{ "fp-load" , 1 , OpStackFPU{ 1 } } );
infos.add( E_OpType::OP_FP_SLOAD , T_OpInfo{ "fp-load-stack" , 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_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_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_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_FULLSCREEN , T_OpInfo{ "fullscreen" } );
infos.add( E_OpType::OP_CLEAR , T_OpInfo{ "clear" , 0 , OpStackMain{ -4 } } ); infos.add( E_OpType::OP_CLEAR , T_OpInfo{ "clear" , 0 , OpStackMain{ -4 } } );