Skip to content

Commit bd770f0

Browse files
committed
Ignore ordinary stores when trimming VariablePointers
VariablePointers is about pointer values that remain first-class in the final module. A plain OpStore stores through a pointer. It does not by itself prove that the module still needs VariablePointers.\n\nThe SPIR-V OpStore definition says that Pointer is the pointer to store through and Object is the object to store. The variable pointers rules separately constrain the case where a pointer is the Object operand of OpStore or the result of OpLoad. Ordinary stores of non-pointer objects through StorageBuffer pointers do not require keeping VariablePointers alive.\n\nStop treating every OpStore as a VariablePointers requirement and add a regression test for a normal StorageBuffer store that should trim the stale capability.\n\nSpec references:\nhttps://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpStore\nhttps://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#VariablePointers
1 parent f5339a9 commit bd770f0

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

source/opt/trim_variable_pointers_capabilities_pass.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ void AddVariablePointerCapabilityRequirements(
249249

250250
switch (instruction->opcode()) {
251251
case spv::Op::OpReturnValue:
252-
case spv::Op::OpStore:
253252
case spv::Op::OpPtrAccessChain:
254253
case spv::Op::OpPtrEqual:
255254
case spv::Op::OpPtrNotEqual:

test/opt/trim_variable_pointers_capabilities_pass_test.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,45 @@ TEST_F(TrimVariablePointersCapabilitiesPassTest,
6262
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
6363
}
6464

65+
TEST_F(TrimVariablePointersCapabilitiesPassTest,
66+
VariablePointers_RemovedForOrdinaryStorageBufferStores) {
67+
const std::string kTest = R"(
68+
OpCapability Shader
69+
OpCapability VariablePointers
70+
; CHECK: OpCapability Shader
71+
; CHECK-NOT: OpCapability VariablePointers
72+
OpMemoryModel Logical GLSL450
73+
OpEntryPoint GLCompute %main "main" %buf
74+
OpExecutionMode %main LocalSize 1 1 1
75+
OpDecorate %_struct_4 Block
76+
OpMemberDecorate %_struct_4 0 Offset 0
77+
OpDecorate %buf DescriptorSet 0
78+
OpDecorate %buf Binding 0
79+
%void = OpTypeVoid
80+
%3 = OpTypeFunction %void
81+
%float = OpTypeFloat 32
82+
%v3float = OpTypeVector %float 3
83+
%float_0 = OpConstant %float 0
84+
%11 = OpConstantComposite %v3float %float_0 %float_0 %float_0
85+
%uint = OpTypeInt 32 0
86+
%uint_0 = OpConstant %uint 0
87+
%_struct_4 = OpTypeStruct %v3float
88+
%_ptr_StorageBuffer__struct_4 = OpTypePointer StorageBuffer %_struct_4
89+
%_ptr_StorageBuffer_v3float = OpTypePointer StorageBuffer %v3float
90+
%buf = OpVariable %_ptr_StorageBuffer__struct_4 StorageBuffer
91+
%main = OpFunction %void None %3
92+
%9 = OpLabel
93+
%10 = OpAccessChain %_ptr_StorageBuffer_v3float %buf %uint_0
94+
OpStore %10 %11
95+
OpReturn
96+
OpFunctionEnd
97+
)";
98+
const auto result =
99+
SinglePassRunAndMatch<TrimVariablePointersCapabilitiesPass>(
100+
kTest, /* skip_nop= */ false);
101+
EXPECT_EQ(std::get<1>(result), Pass::Status::SuccessWithChange);
102+
}
103+
65104
TEST_F(TrimVariablePointersCapabilitiesPassTest,
66105
VariablePointers_RemainsForWorkgroupSelect) {
67106
const std::string kTest = R"(

0 commit comments

Comments
 (0)