Skip to content

Commit 9ef6bdc

Browse files
spirv-val: Check for image declaration with TileImageEXT storage class
Change-Id: I9d97fb16af9848b3a3871f5f6a8043b859415fa3
1 parent 2ec8457 commit 9ef6bdc

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

source/val/validate_memory.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,32 @@ spv_result_t ValidateVariableTileShadingQCOM(ValidationState_t& _,
11241124
return SPV_SUCCESS;
11251125
}
11261126

1127+
spv_result_t ValidateVariableTileImageEXT(ValidationState_t& _,
1128+
const Instruction* inst) {
1129+
bool is_valid_decl = true;
1130+
1131+
auto result_type = _.FindDef(inst->type_id());
1132+
if (result_type->opcode() == spv::Op::OpTypePointer) {
1133+
const auto pointee_type = _.FindDef(result_type->GetOperandAs<uint32_t>(2));
1134+
if (pointee_type && pointee_type->opcode() == spv::Op::OpTypeImage) {
1135+
spv::Dim dim = static_cast<spv::Dim>(pointee_type->word(3));
1136+
if (dim != spv::Dim::TileImageDataEXT) {
1137+
is_valid_decl = false;
1138+
}
1139+
} else {
1140+
is_valid_decl = false;
1141+
}
1142+
}
1143+
1144+
if (!is_valid_decl) {
1145+
return _.diag(SPV_ERROR_INVALID_DATA, inst)
1146+
<< "The TileImageEXT Storage Class must only be used for declaring "
1147+
"tile image variables";
1148+
} else {
1149+
return SPV_SUCCESS;
1150+
}
1151+
}
1152+
11271153
spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
11281154
const bool untyped_pointer = inst->opcode() == spv::Op::OpUntypedVariableKHR;
11291155

@@ -1242,6 +1268,11 @@ spv_result_t ValidateVariable(ValidationState_t& _, const Instruction* inst) {
12421268
if (auto error = ValidateVariableTileShadingQCOM(_, inst)) return error;
12431269
}
12441270

1271+
if (_.HasCapability(spv::Capability::TileImageColorReadAccessEXT) &&
1272+
storage_class == spv::StorageClass::TileImageEXT) {
1273+
if (auto error = ValidateVariableTileImageEXT(_, inst)) return error;
1274+
}
1275+
12451276
return SPV_SUCCESS;
12461277
}
12471278

test/val/val_storage_test.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,38 @@ TEST_F(ValidateStorage, TileAttachmentQCOMBad6) {
437437
HasSubstr("requires one of these capabilities: TileShadingQCOM"));
438438
}
439439

440+
TEST_F(ValidateStorage, WrongDimTileImageEXT) {
441+
const std::string spirv = R"(
442+
OpCapability Shader
443+
OpCapability Sampled1D
444+
OpCapability TileImageColorReadAccessEXT
445+
OpExtension "SPV_EXT_shader_tile_image"
446+
OpMemoryModel Logical GLSL450
447+
OpEntryPoint Fragment %main "main"
448+
OpExecutionMode %main OriginUpperLeft
449+
OpSource GLSL 450
450+
%void = OpTypeVoid
451+
%int = OpTypeInt 32 1
452+
%img = OpTypeImage %int 1D 0 0 0 2 Rgba32i
453+
%ptr_img = OpTypePointer TileImageEXT %img
454+
%color1 = OpVariable %ptr_img TileImageEXT
455+
%3 = OpTypeFunction %void
456+
%main = OpFunction %void None %3
457+
%5 = OpLabel
458+
OpReturn
459+
OpFunctionEnd
460+
)";
461+
462+
spv_target_env env = SPV_ENV_VULKAN_1_4;
463+
CompileSuccessfully(spirv, env);
464+
EXPECT_THAT(SPV_ERROR_INVALID_DATA, ValidateInstructions(env));
465+
EXPECT_THAT(
466+
getDiagnosticString(),
467+
HasSubstr(
468+
"The TileImageEXT Storage Class must only be used for declaring "
469+
"tile image variables"));
470+
}
471+
440472
std::string GenerateExecutionModelCode(const std::string& execution_model,
441473
const std::string& storage_class,
442474
bool store) {

0 commit comments

Comments
 (0)