Skip to content

Commit

Permalink
Modified ShaderWriter::pushScope to push a compound statement instead…
Browse files Browse the repository at this point in the history
… of a container.
  • Loading branch information
DragonJoker committed Jul 11, 2024
1 parent dd07d78 commit cb71ad4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/ShaderWriter/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ namespace sdw

void ShaderWriter::pushScope()
{
m_builder->pushScope( getStmtCache().makeContainer() );
m_builder->pushScope( getStmtCache().makeCompound() );
}

void ShaderWriter::popScope()
Expand Down
66 changes: 66 additions & 0 deletions test/ShaderWriter/TestWriterControlStatements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,70 @@ namespace
, testCounts, CurrentCompilers );
astTestEnd();
}

void testAnonymousScope( test::sdw_test::TestCounts & testCounts )
{
astTestBegin( "testAnonymousScope" );
sdw::ShaderArray shaders;
{
sdw::ComputeWriter writer{ &testCounts.allocator };
auto i = writer.declSharedVariable< sdw::UInt >( "i" );
writer.implementMain( 32u, [&]( sdw::ComputeIn in )
{
if (auto scope = makeScope( writer ) )
{
i = in.globalInvocationID.x();
}
} );
test::writeShader( writer
, testCounts, CurrentCompilers );
shaders.emplace_back( std::move( writer.getShader() ) );
}
test::validateShaders( shaders
, testCounts, CurrentCompilers );
astTestEnd();
}

void testNestedAnonymousScopes( test::sdw_test::TestCounts & testCounts )
{
astTestBegin( "testNestedAnonymousScopes" );
sdw::ShaderArray shaders;
{
sdw::ComputeWriter writer{ &testCounts.allocator };
auto i = writer.declSharedVariable< sdw::UInt >( "i" );
auto j = writer.declSharedVariable< sdw::UInt >( "j" );
auto k = writer.declSharedVariable< sdw::UInt >( "k" );
auto l = writer.declSharedVariable< sdw::UInt >( "l" );
writer.implementMain( 32u, [&]( sdw::ComputeIn in )
{
if (auto scope1 = makeScope( writer ) )
{
l = in.localInvocationIndex;
if ( auto scope2 = makeScope( writer ) )
{
k = in.globalInvocationID.z();
if ( auto scope3 = makeScope( writer ) )
{
j = in.globalInvocationID.y();
if ( auto scope4 = makeScope( writer ) )
{
i = in.globalInvocationID.x();
}
j += in.globalInvocationID.y();
}
k += in.globalInvocationID.z();
}
l += in.localInvocationIndex;
}
} );
test::writeShader( writer
, testCounts, CurrentCompilers );
shaders.emplace_back( std::move( writer.getShader() ) );
}
test::validateShaders( shaders
, testCounts, CurrentCompilers );
astTestEnd();
}
}

sdwTestSuiteMain( TestWriterControlStatements )
Expand Down Expand Up @@ -884,6 +948,8 @@ sdwTestSuiteMain( TestWriterControlStatements )
testConstSwitch0( testCounts );
testConstSwitch1( testCounts );
testConstSwitchDefault( testCounts );
testAnonymousScope( testCounts );
testNestedAnonymousScopes( testCounts );
sdwTestSuiteEnd();
}

Expand Down

0 comments on commit cb71ad4

Please sign in to comment.