Skip to content

Commit dd2dfb7

Browse files
ConvertUBOToPushConstantPass: fail if the UBO is not found
1 parent 04feca3 commit dd2dfb7

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Graphics/ShaderTools/src/ConvertUBOToPushConstant.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class ConvertUBOToPushConstantPass : public spvtools::opt::Pass
7474
m_BlockName{block_name}
7575
{}
7676

77+
static spvtools::Optimizer::PassToken Create(std::string BlockName)
78+
{
79+
return spvtools::Optimizer::PassToken{
80+
std::make_unique<ConvertUBOToPushConstantPass>(BlockName)};
81+
}
82+
7783
const char* name() const override { return "convert-ubo-to-push-constant"; }
7884

7985
Status Process() override
@@ -95,8 +101,8 @@ class ConvertUBOToPushConstantPass : public spvtools::opt::Pass
95101

96102
if (candidate_ids.empty())
97103
{
98-
// Block name not found
99-
return Status::SuccessWithoutChange;
104+
LOG_ERROR_MESSAGE("Failed to convert UBO block '", m_BlockName, "': no OpName found.");
105+
return Status::Failure;
100106
}
101107

102108
// Try each candidate ID to find a UniformBuffer
@@ -190,8 +196,8 @@ class ConvertUBOToPushConstantPass : public spvtools::opt::Pass
190196

191197
if (target_var == nullptr)
192198
{
193-
// No UniformBuffer found with the given block name
194-
return Status::SuccessWithoutChange;
199+
LOG_ERROR_MESSAGE("Failed to convert UBO block '", m_BlockName, "': no matching UniformBuffer found.");
200+
return Status::Failure;
195201
}
196202

197203
uint32_t target_var_id = target_var->result_id();
@@ -444,8 +450,7 @@ std::vector<uint32_t> ConvertUBOToPushConstants(
444450
optimizer.SetMessageConsumer(SPIRVToolsInternal::SpvOptimizerMessageConsumer);
445451

446452
// Register the pass to convert UBO to push constant using custom out-of-tree pass
447-
optimizer.RegisterPass(spvtools::Optimizer::PassToken(
448-
std::make_unique<ConvertUBOToPushConstantPass>(BlockName)));
453+
optimizer.RegisterPass(ConvertUBOToPushConstantPass::Create(BlockName));
449454

450455
spvtools::OptimizerOptions options;
451456
#ifdef DILIGENT_DEVELOPMENT

Tests/DiligentCoreTest/src/ShaderTools/SPIRVShaderResourcesTest.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,12 @@ void TestConvertUBOToPushConstant_InvalidBlockName(SHADER_COMPILER Compiler)
345345
if (::testing::Test::IsSkipped())
346346
return;
347347

348-
std::vector<unsigned int> PatchedSPIRV = ConvertUBOToPushConstants(SPIRV, PatchedAttribName);
349-
EXPECT_EQ(SPIRV, PatchedSPIRV);
348+
TestingEnvironment* pEnv = TestingEnvironment::GetInstance();
349+
pEnv->SetErrorAllowance(1, "No worries, errors are expected: testing invalid input\n");
350+
pEnv->PushExpectedErrorSubstring("Failed to convert UBO block 'CB5': no OpName found.");
351+
352+
SPIRV = ConvertUBOToPushConstants(SPIRV, PatchedAttribName);
353+
EXPECT_TRUE(SPIRV.empty());
350354
}
351355

352356
TEST_F(SPIRVShaderResourcesTest, ConvertUBOToPushConstant_InvalidBlockName_GLSLang)
@@ -369,8 +373,12 @@ void TestConvertUBOToPushConstant_InvalidResourceType(SHADER_COMPILER Compiler)
369373
if (::testing::Test::IsSkipped())
370374
return;
371375

372-
std::vector<unsigned int> PatchedSPIRV = ConvertUBOToPushConstants(SPIRV, PatchedAttribName);
373-
EXPECT_EQ(SPIRV, PatchedSPIRV);
376+
TestingEnvironment* pEnv = TestingEnvironment::GetInstance();
377+
pEnv->SetErrorAllowance(1, "No worries, errors are expected: testing invalid input\n");
378+
pEnv->PushExpectedErrorSubstring("Failed to convert UBO block 'g_ROBuffer': no matching UniformBuffer found.");
379+
380+
SPIRV = ConvertUBOToPushConstants(SPIRV, PatchedAttribName);
381+
EXPECT_TRUE(SPIRV.empty());
374382
}
375383

376384
TEST_F(SPIRVShaderResourcesTest, ConvertUBOToPushConstant_InvalidResourceType_GLSLang)

0 commit comments

Comments
 (0)