Skip to content

Commit

Permalink
Handle shaders without execution model in spread-volatile-semantics (#…
Browse files Browse the repository at this point in the history
…4766)

spread-volatile-semantics pass spreads Volatile semantics for builtin
variables used by certain execution models based on
VUID-StandaloneSpirv-VulkanMemoryModel-04678 and
VUID-StandaloneSpirv-VulkanMemoryModel-04679 (See "Standalone SPIR-V
Validation" section of Vulkan spec "Appendix A: Vulkan Environment for
SPIR-V"). Therefore, shaders without execution model (e.g., used only
for linkage) are not the target of the pass. This commit lets the pass
just return SuccessWithoutChange in that case.
  • Loading branch information
jaebaek authored Mar 25, 2022
1 parent fa5d424 commit 05745cc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions source/opt/spread_volatile_semantics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ bool HasOnlyEntryPointsAsFunctions(IRContext* context, Module* module) {
} // namespace

Pass::Status SpreadVolatileSemantics::Process() {
if (HasNoExecutionModel()) {
return Status::SuccessWithoutChange;
}

if (!HasOnlyEntryPointsAsFunctions(context(), get_module())) {
return Status::Failure;
}
Expand Down
7 changes: 7 additions & 0 deletions source/opt/spread_volatile_semantics.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ class SpreadVolatileSemantics : public Pass {
}

private:
// Returns true if it does not have an execution model. Linkage shaders do not
// have an execution model.
bool HasNoExecutionModel() {
return get_module()->entry_points().empty() &&
context()->get_feature_mgr()->HasCapability(SpvCapabilityLinkage);
}

// Iterates interface variables and spreads the Volatile semantics if it has
// load instructions for the Volatile semantics.
Pass::Status SpreadVolatileSemanticsToVariables(
Expand Down
20 changes: 20 additions & 0 deletions test/opt/spread_volatile_semantics_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,26 @@ OpFunctionEnd
SinglePassRunAndMatch<SpreadVolatileSemantics>(text, true);
}

TEST_F(VolatileSpreadTest, SkipIfItHasNoExecutionModel) {
const std::string text = R"(
OpCapability Shader
OpCapability Linkage
OpMemoryModel Logical GLSL450
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%4 = OpFunction %2 None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
)";

Pass::Status status;
std::tie(std::ignore, status) =
SinglePassRunToBinary<SpreadVolatileSemantics>(text,
/* skip_nop = */ false);
EXPECT_EQ(status, Pass::Status::SuccessWithoutChange);
}

} // namespace
} // namespace opt
} // namespace spvtools

0 comments on commit 05745cc

Please sign in to comment.