Skip to content

Commit 6c6152b

Browse files
authored
spirv-val: fix GetLargestScalarType (KhronosGroup#6275)
Add missing types Clean returns for types already there
1 parent 0c1acc2 commit 6c6152b

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

source/val/validation_state.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,23 +1383,24 @@ bool ValidationState_t::GetPointerTypeInfo(
13831383

13841384
uint32_t ValidationState_t::GetLargestScalarType(uint32_t id) const {
13851385
const Instruction* inst = FindDef(id);
1386-
uint32_t size = 0;
13871386

13881387
switch (inst->opcode()) {
1389-
case spv::Op::OpTypeStruct:
1388+
case spv::Op::OpTypeStruct: {
1389+
uint32_t size = 0;
13901390
for (uint32_t i = 1; i < inst->operands().size(); ++i) {
13911391
const uint32_t member_size =
13921392
GetLargestScalarType(inst->GetOperandAs<uint32_t>(i));
13931393
size = std::max(size, member_size);
13941394
}
1395-
break;
1395+
return size;
1396+
}
1397+
case spv::Op::OpTypeArray:
1398+
return GetLargestScalarType(inst->GetOperandAs<uint32_t>(1));
1399+
case spv::Op::OpTypeVector:
1400+
return GetLargestScalarType(inst->GetOperandAs<uint32_t>(1));
13961401
default:
1397-
const uint32_t bytes = GetBitWidth(id) / 8;
1398-
size = std::max(size, bytes);
1399-
break;
1402+
return GetBitWidth(id) / 8;
14001403
}
1401-
1402-
return size;
14031404
}
14041405

14051406
bool ValidationState_t::IsAccelerationStructureType(uint32_t id) const {

test/val/val_memory_test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9452,6 +9452,48 @@ TEST_F(ValidateMemory, CoopMatMatrixFloat8FAdd) {
94529452
HasSubstr("FAdd doesn't support FP8 E4M3/E5M2 types"));
94539453
}
94549454

9455+
TEST_F(ValidateMemory, PhysicalStorageBufferArray) {
9456+
const std::string body =
9457+
R"(
9458+
OpCapability Shader
9459+
OpCapability Int64
9460+
OpCapability PhysicalStorageBufferAddresses
9461+
OpExtension "SPV_KHR_storage_buffer_storage_class"
9462+
OpExtension "SPV_KHR_physical_storage_buffer"
9463+
OpMemoryModel PhysicalStorageBuffer64 GLSL450
9464+
OpEntryPoint GLCompute %18 "main"
9465+
OpExecutionMode %18 LocalSize 1 1 1
9466+
OpSource OpenCL_C 120
9467+
OpMemberDecorate %S 0 Offset 0
9468+
OpMemberDecorate %S 1 Offset 256
9469+
OpDecorate %array ArrayStride 16
9470+
%uint = OpTypeInt 32 0
9471+
%void = OpTypeVoid
9472+
%ulong = OpTypeInt 64 0
9473+
%float = OpTypeFloat 32
9474+
%v4float = OpTypeVector %float 4
9475+
%17 = OpTypeFunction %void
9476+
%ulong_0 = OpConstant %ulong 0
9477+
%uint_3 = OpConstant %uint 3
9478+
%array = OpTypeArray %v4float %uint_3
9479+
%S = OpTypeStruct %array %uint
9480+
%ptr_S = OpTypePointer PhysicalStorageBuffer %S
9481+
%float_0 = OpConstant %float 0
9482+
%v4float_0 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_0
9483+
%23 = OpConstantComposite %array %v4float_0 %v4float_0 %v4float_0
9484+
%24 = OpConstantComposite %S %23 %uint_3
9485+
%18 = OpFunction %void None %17
9486+
%19 = OpLabel
9487+
%58 = OpConvertUToPtr %ptr_S %ulong_0
9488+
OpStore %58 %24 Aligned 4
9489+
OpReturn
9490+
OpFunctionEnd
9491+
)";
9492+
9493+
CompileSuccessfully(body.c_str(), SPV_ENV_VULKAN_1_0);
9494+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
9495+
}
9496+
94559497
} // namespace
94569498
} // namespace val
94579499
} // namespace spvtools

0 commit comments

Comments
 (0)