Skip to content

Commit 539a11d

Browse files
spirv-val: Validate ImageQuerySizeLod is 32-bit (#6479)
similar to #6477 but this one was used the Kernel code in the tests so could separate it as a new PR
1 parent 149ec16 commit 539a11d

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

source/val/validate_image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,9 +1943,9 @@ spv_result_t ValidateImageQuerySizeLod(ValidationState_t& _,
19431943
}
19441944

19451945
const uint32_t lod_type = _.GetOperandTypeId(inst, 3);
1946-
if (!_.IsIntScalarType(lod_type)) {
1946+
if (!_.IsIntScalarType(lod_type, 32)) {
19471947
return _.diag(SPV_ERROR_INVALID_DATA, inst)
1948-
<< "Expected Level of Detail to be int scalar";
1948+
<< "Expected Level of Detail to be a 32-bit int scalar";
19491949
}
19501950
return SPV_SUCCESS;
19511951
}

test/val/val_image_test.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ OpCapability ImageQuery
385385
OpCapability ImageGatherExtended
386386
OpCapability InputAttachment
387387
OpCapability SampledRect
388+
OpCapability Int16
388389
)";
389390

390391
ss << capabilities_and_extensions;
@@ -394,6 +395,7 @@ OpMemoryModel Physical32 OpenCL
394395
%func = OpTypeFunction %void
395396
%bool = OpTypeBool
396397
%f32 = OpTypeFloat 32
398+
%u16 = OpTypeInt 16 0
397399
%u32 = OpTypeInt 32 0
398400
%u32vec2 = OpTypeVector %u32 2
399401
%f32vec2 = OpTypeVector %f32 2
@@ -408,6 +410,8 @@ OpMemoryModel Physical32 OpenCL
408410
%f32_0_25 = OpConstant %f32 0.25
409411
%f32_0_75 = OpConstant %f32 0.75
410412
413+
%u16_0 = OpConstant %u16 0
414+
411415
%u32_0 = OpConstant %u32 0
412416
%u32_1 = OpConstant %u32 1
413417
%u32_2 = OpConstant %u32 2
@@ -4618,7 +4622,19 @@ TEST_F(ValidateImage, QuerySizeLodWrongLodType) {
46184622
CompileSuccessfully(GenerateKernelCode(body).c_str());
46194623
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
46204624
EXPECT_THAT(getDiagnosticString(),
4621-
HasSubstr("Expected Level of Detail to be int scalar"));
4625+
HasSubstr("Expected Level of Detail to be a 32-bit int scalar"));
4626+
}
4627+
4628+
TEST_F(ValidateImage, QuerySizeLodWrong16Bit) {
4629+
const std::string body = R"(
4630+
%img = OpLoad %type_image_f32_2d_0001 %uniform_image_f32_2d_0001
4631+
%res1 = OpImageQuerySizeLod %u32vec2 %img %u16_0
4632+
)";
4633+
4634+
CompileSuccessfully(GenerateKernelCode(body).c_str());
4635+
ASSERT_EQ(SPV_ERROR_INVALID_DATA, ValidateInstructions());
4636+
EXPECT_THAT(getDiagnosticString(),
4637+
HasSubstr("Expected Level of Detail to be a 32-bit int scalar"));
46224638
}
46234639

46244640
TEST_F(ValidateImage, QuerySizeSuccess) {

0 commit comments

Comments
 (0)