Skip to content

Commit a1eace9

Browse files
authored
Handle OpTypeVectorIdEXT in validate_interfaces.cpp (#6492)
VectorId can be used in input/output storage classes as long as it has a non-specconstant component count. Handle the type and add a couple tests.
1 parent 65b2ace commit a1eace9

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

source/val/validate_interfaces.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,12 @@ spv_result_t NumConsumedLocations(ValidationState_t& _, const Instruction* type,
155155
*num_locations = 1;
156156
break;
157157
case spv::Op::OpTypeVector:
158+
case spv::Op::OpTypeVectorIdEXT:
158159
// 3- and 4-component 64-bit vectors consume two locations.
159160
if ((_.ContainsSizedIntOrFloatType(type->id(), spv::Op::OpTypeInt, 64) ||
160161
_.ContainsSizedIntOrFloatType(type->id(), spv::Op::OpTypeFloat,
161162
64)) &&
162-
(type->GetOperandAs<uint32_t>(2) > 2)) {
163+
(_.GetDimension(type->id()) > 2)) {
163164
*num_locations = 2;
164165
} else {
165166
*num_locations = 1;
@@ -239,12 +240,13 @@ uint32_t NumConsumedComponents(ValidationState_t& _, const Instruction* type) {
239240
}
240241
break;
241242
case spv::Op::OpTypeVector:
243+
case spv::Op::OpTypeVectorIdEXT:
242244
// Vectors consume components equal to the underlying type's consumption
243245
// times the number of elements in the vector. Note that 3- and 4-element
244246
// vectors cannot have a component decoration (i.e. assumed to be zero).
245247
num_components =
246248
NumConsumedComponents(_, _.FindDef(type->GetOperandAs<uint32_t>(1)));
247-
num_components *= type->GetOperandAs<uint32_t>(2);
249+
num_components *= _.GetDimension(type->id());
248250
break;
249251
case spv::Op::OpTypeArray:
250252
// Skip the array.

test/val/val_interfaces_test.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,65 @@ OpFunctionEnd
20392039
"with a Storage Class of Input or Output.\n"));
20402040
}
20412041

2042+
TEST_F(ValidateInterfacesTest, VectorIdFragmentInputOutputPass) {
2043+
const std::string text = R"(
2044+
OpCapability Shader
2045+
OpCapability LongVectorEXT
2046+
OpExtension "SPV_EXT_long_vector"
2047+
OpMemoryModel Logical GLSL450
2048+
OpEntryPoint Fragment %main "main" %in %out
2049+
OpExecutionMode %main OriginUpperLeft
2050+
OpDecorate %in Location 0
2051+
OpDecorate %out Location 0
2052+
%void = OpTypeVoid
2053+
%f32 = OpTypeFloat 32
2054+
%u32 = OpTypeInt 32 0
2055+
%u4 = OpConstant %u32 4
2056+
%f32vec = OpTypeVectorIdEXT %f32 %u4
2057+
%in_ptr = OpTypePointer Input %f32vec
2058+
%out_ptr = OpTypePointer Output %f32vec
2059+
%in = OpVariable %in_ptr Input
2060+
%out = OpVariable %out_ptr Output
2061+
%void_fn = OpTypeFunction %void
2062+
%main = OpFunction %void None %void_fn
2063+
%entry = OpLabel
2064+
OpReturn
2065+
OpFunctionEnd
2066+
)";
2067+
2068+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
2069+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2070+
}
2071+
2072+
TEST_F(ValidateInterfacesTest, VectorIdVertexInputOutputPass) {
2073+
const std::string text = R"(
2074+
OpCapability Shader
2075+
OpCapability LongVectorEXT
2076+
OpExtension "SPV_EXT_long_vector"
2077+
OpMemoryModel Logical GLSL450
2078+
OpEntryPoint Vertex %main "main" %in %out
2079+
OpDecorate %in Location 0
2080+
OpDecorate %out Location 0
2081+
%void = OpTypeVoid
2082+
%f32 = OpTypeFloat 32
2083+
%u32 = OpTypeInt 32 0
2084+
%u4 = OpConstant %u32 4
2085+
%f32vec = OpTypeVectorIdEXT %f32 %u4
2086+
%in_ptr = OpTypePointer Input %f32vec
2087+
%out_ptr = OpTypePointer Output %f32vec
2088+
%in = OpVariable %in_ptr Input
2089+
%out = OpVariable %out_ptr Output
2090+
%void_fn = OpTypeFunction %void
2091+
%main = OpFunction %void None %void_fn
2092+
%entry = OpLabel
2093+
OpReturn
2094+
OpFunctionEnd
2095+
)";
2096+
2097+
CompileSuccessfully(text, SPV_ENV_VULKAN_1_3);
2098+
ASSERT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_3));
2099+
}
2100+
20422101
} // namespace
20432102
} // namespace val
20442103
} // namespace spvtools

0 commit comments

Comments
 (0)