Control / compiler - Fixed program initialization

Program initialization returns an identifier, unlike the rest
of the initializers which require an allocated GL ID.
This commit is contained in:
Emmanuel BENOîT 2017-11-14 15:37:42 +01:00
parent 96d821828f
commit 6deb59d884
3 changed files with 11 additions and 2 deletions

View file

@ -22,6 +22,7 @@ enum E_OpType
OP_DUP ,
//
OP_LOAD ,
OP_STORE ,
OP_SLOAD ,
OP_CONST ,
//

View file

@ -456,12 +456,14 @@ bool T_CompilerImpl_::compileNode(
case A_Node::OP_PROGRAM:
if ( exit ) {
auto& pn( (T_ProgramInstrNode&) node );
processIdentifier( funcIndex , pn.id( ) , pn.idLocation( ) );
if ( !output->progNames.contains( pn.path( ) ) ) {
output->progNames.add( pn.path( ) );
}
assert( locations.contains( pn.id( ) ) );
addInstruction( OP_INIT_PROGRAM , output->progNames.indexOf( pn.path( ) ) ,
pn.location( ) );
addInstruction( OP_STORE , *locations.get( pn.id( ) ) , pn.idLocation( ) );
}
break;

8
ops.cc
View file

@ -95,6 +95,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() {
infos.add( E_OpType::OP_DUP , T_OpInfo{ "dup" , 1 , OpStackMain{ 1 } } );
//
infos.add( E_OpType::OP_LOAD , T_OpInfo{ "load" , 1 } );
infos.add( E_OpType::OP_STORE , T_OpInfo{ "store" , 1 } );
infos.add( E_OpType::OP_SLOAD , T_OpInfo{ "load-stack" , 1 } );
infos.add( E_OpType::OP_CONST , T_OpInfo{ "const" , 1 } );
//
@ -122,7 +123,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() {
infos.add( E_OpType::OP_FP_LN , T_OpInfo{ "fp-ln" , 0 } );
//
infos.add( E_OpType::OP_INIT_PIPELINE , T_OpInfo{ "pipeline" , 1 , OpStackMain{ -1 } } );
infos.add( E_OpType::OP_INIT_PROGRAM , T_OpInfo{ "program" , 1 , OpStackMain{ -1 } } );
infos.add( E_OpType::OP_INIT_PROGRAM , T_OpInfo{ "program" , 1 } );
infos.add( E_OpType::OP_INIT_TEXTURE , T_OpInfo{ "texture" , 2 , OpStackMain{ -3 } } );
infos.add( E_OpType::OP_INIT_SAMPLER , T_OpInfo{ "sampler" , 2 , OpStackMain{ -3 } } );
infos.add( E_OpType::OP_FB_ATTACH , T_OpInfo{ "fb-attach" , 2 , OpStackMain{ -1 } } );
@ -312,6 +313,11 @@ void T_OpContext::run(
wreg = values[ instr.args[ 0 ] ];
break;
case OP_STORE:
checkAddress( instr , instr.args[ 0 ] );
values[ instr.args[ 0 ] ] = wreg;
break;
case OP_SLOAD:
ensureStack( instr , instr.args[ 0 ] + 1 );
wreg = stack[ stack.size( ) - instr.args[ 0 ] - 1 ];