diff --git a/control.hh b/control.hh index d7250c9..d555d17 100644 --- a/control.hh +++ b/control.hh @@ -50,6 +50,7 @@ enum E_OpType // OP_INIT_PIPELINE , OP_INIT_PROGRAM , + OP_INIT_SAMPLER , OP_INIT_TEXTURE , OP_FB_ATTACH , // diff --git a/opast.cc b/opast.cc index 02483b5..e402fbe 100644 --- a/opast.cc +++ b/opast.cc @@ -604,7 +604,9 @@ T_Optional< T_SRDLocation > T_SamplerInstrNode::setLOD( if ( lod_ ) { return lod_->location; } - lod_ = T_LOD_{ location , std::move( min ) , std::move( max ) }; + lod_ = T_LOD_{ location , + min ? NewOwned< T_ArgumentNode >( *this , std::move( min ) ) : P_ArgumentNode{} , + max ? NewOwned< T_ArgumentNode >( *this , std::move( max ) ) : P_ArgumentNode{} }; return {}; } diff --git a/opast.hh b/opast.hh index 5741cde..27547f9 100644 --- a/opast.hh +++ b/opast.hh @@ -804,8 +804,8 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode struct T_LOD_ { T_SRDLocation location; - P_ExpressionNode min; - P_ExpressionNode max; + P_ArgumentNode min; + P_ArgumentNode max; }; T_Optional< T_Sampling_ > sampling_; @@ -847,9 +847,9 @@ class T_SamplerInstrNode : public A_ResourceDefInstrNode { return mipmaps_ ? mipmaps_->mode : T_Optional< E_TexSampling >{}; } E_TexWrap wrapping( ) const noexcept { return wrapping_ ? wrapping_->mode : E_TexWrap::REPEAT; } - A_ExpressionNode* minLod( ) const noexcept + T_ArgumentNode* minLod( ) const noexcept { return lod_ ? lod_->min.get( ) : nullptr; } - A_ExpressionNode* maxLod( ) const noexcept + T_ArgumentNode* maxLod( ) const noexcept { return lod_ ? lod_->max.get( ) : nullptr; } }; diff --git a/opcomp.cc b/opcomp.cc index 1025c61..4367691 100644 --- a/opcomp.cc +++ b/opcomp.cc @@ -457,6 +457,25 @@ bool T_CompilerImpl_::compileNode( } break; + case A_Node::OP_SAMPLER: + if ( exit ) { + auto& sn( (T_SamplerInstrNode&) node ); + if ( !sn.minLod( ) ) { + // XXX maybe use OP_RES_STACK + addInstruction( OP_CONST , 0 , node.location( ) ); + addInstruction( OP_PUSH , node.location( ) ); + addInstruction( OP_PUSH , node.location( ) ); + } + processIdentifier( funcIndex , sn.id( ) , sn.idLocation( ) ); + addInstruction( OP_INIT_SAMPLER , { + ( uint32_t( sn.sampling( ) ) << 2 ) + | ( ( sn.mipmap( ) ? 1 : 0 ) << 1 ) + | ( sn.mipmap( ) ? uint32_t( *sn.mipmap( ) ) : 0 ) , + uint32_t( sn.wrapping( ) ) + } , node.location( ) ); + } + break; + case A_Node::OP_TEXTURE: if ( exit ) { auto& tn( (T_TextureInstrNode&) node ); @@ -498,6 +517,14 @@ bool T_CompilerImpl_::compileNode( //- STATE ----------------------------------------------------------------------------- + case A_Node::OP_MAINOUT: + if ( exit ) { + addInstruction( OP_CONST , 0 , node.location( ) ); + addInstruction( OP_PUSH , node.location( ) ); + addInstruction( OP_USE_FRAMEBUFFER , node.location( ) ); + } + break; + case A_Node::OP_USE_FRAMEBUFFER: if ( exit ) { auto& fbn( (T_UseInstrNode&) node ); diff --git a/ops.cc b/ops.cc index 8862dc3..b617c97 100644 --- a/ops.cc +++ b/ops.cc @@ -123,6 +123,7 @@ static T_KeyValueTable< E_OpType , T_OpInfo > OpInfoTable_{ ([]() { 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_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 } } ); // infos.add( E_OpType::OP_USE_FRAMEBUFFER , T_OpInfo{ "use-framebuffer" , 0 , OpStackMain{ -1 } } );