Skip to content

Commit 736e415

Browse files
authored
Fix operand access in invalid layout checks (#6151)
* Wrong operand used for OpStore * Added test
1 parent 66fe610 commit 736e415

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

source/val/validate_decorations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,7 +2269,7 @@ spv_result_t CheckInvalidVulkanExplicitLayout(ValidationState_t& vstate) {
22692269
// For untyped pointers, check the type of the data operand for an
22702270
// invalid layout.
22712271
const auto sc = ptr_type->GetOperandAs<spv::StorageClass>(1);
2272-
const auto data_type_id = vstate.GetOperandTypeId(&inst, 2);
2272+
const auto data_type_id = vstate.GetOperandTypeId(&inst, 1);
22732273
if (!AllowsLayout(vstate, sc) &&
22742274
UsesExplicitLayout(vstate, data_type_id, cache)) {
22752275
fail_id = inst.GetOperandAs<uint32_t>(2);

test/val/val_decoration_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10978,6 +10978,37 @@ OpFunctionEnd
1097810978
HasSubstr("Invalid explicit layout decorations on type for operand"));
1097910979
}
1098010980

10981+
TEST_F(ValidateDecorations, InvalidLayoutUntypedStore) {
10982+
const std::string spirv = R"(
10983+
OpCapability Shader
10984+
OpCapability UntypedPointersKHR
10985+
OpExtension "SPV_KHR_untyped_pointers"
10986+
OpExtension "SPV_KHR_storage_buffer_storage_class"
10987+
OpMemoryModel Logical GLSL450
10988+
OpEntryPoint GLCompute %main "main"
10989+
OpExecutionMode %main LocalSize 1 1 1
10990+
OpDecorate %block Block
10991+
OpMemberDecorate %block 0 Offset 0
10992+
OpDecorate %var DescriptorSet 0
10993+
OpDecorate %var Binding 0
10994+
%void = OpTypeVoid
10995+
%int = OpTypeInt 32 0
10996+
%block = OpTypeStruct %int
10997+
%block_null = OpConstantNull %block
10998+
%ptr = OpTypeUntypedPointerKHR StorageBuffer
10999+
%var = OpUntypedVariableKHR %ptr StorageBuffer %block
11000+
%void_fn = OpTypeFunction %void
11001+
%main = OpFunction %void None %void_fn
11002+
%entry = OpLabel
11003+
OpStore %var %block_null
11004+
OpReturn
11005+
OpFunctionEnd
11006+
)";
11007+
11008+
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
11009+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
11010+
}
11011+
1098111012
TEST_F(ValidateDecorations, ExplicitLayoutOnPtrPhysicalStorageBuffer) {
1098211013
const std::string spirv = R"(
1098311014
OpCapability PhysicalStorageBufferAddresses

0 commit comments

Comments
 (0)