Skip to content

Commit 53c0736

Browse files
authored
A fix to support of SPV_QCOM_image_processing2 (KhronosGroup#5646)
Fixing validation of decorations attached to texture/sampler operands of OpImageBlockMatchWindowSSDQCOM and OpImageBlockMatchWindowSADQCOM
1 parent 67a3ed6 commit 53c0736

2 files changed

Lines changed: 60 additions & 21 deletions

File tree

source/val/validate_image.cpp

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,8 @@ spv_result_t ValidateImageProcessingQCOMDecoration(ValidationState_t& _, int id,
21692169
spv::Decoration decor) {
21702170
const Instruction* si_inst = nullptr;
21712171
const Instruction* ld_inst = _.FindDef(id);
2172-
if (ld_inst->opcode() == spv::Op::OpSampledImage) {
2172+
bool is_intf_obj = (ld_inst->opcode() == spv::Op::OpSampledImage);
2173+
if (is_intf_obj == true) {
21732174
si_inst = ld_inst;
21742175
int t_idx = si_inst->GetOperandAs<int>(2); // texture
21752176
ld_inst = _.FindDef(t_idx);
@@ -2186,6 +2187,56 @@ spv_result_t ValidateImageProcessingQCOMDecoration(ValidationState_t& _, int id,
21862187
return SPV_SUCCESS;
21872188
}
21882189

2190+
spv_result_t ValidateImageProcessing2QCOMWindowDecoration(ValidationState_t& _,
2191+
int id) {
2192+
const Instruction* ld_inst = _.FindDef(id);
2193+
bool is_intf_obj = (ld_inst->opcode() != spv::Op::OpSampledImage);
2194+
if (is_intf_obj == true) {
2195+
if (ld_inst->opcode() != spv::Op::OpLoad) {
2196+
return _.diag(SPV_ERROR_INVALID_DATA, ld_inst) << "Expect to see OpLoad";
2197+
}
2198+
int texture_id = ld_inst->GetOperandAs<int>(2); // variable to load
2199+
spv::Decoration decor = spv::Decoration::BlockMatchTextureQCOM;
2200+
if (!_.HasDecoration(texture_id, decor)) {
2201+
return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
2202+
<< "Missing decoration " << _.SpvDecorationString(decor);
2203+
}
2204+
decor = spv::Decoration::BlockMatchSamplerQCOM;
2205+
if (!_.HasDecoration(texture_id, decor)) {
2206+
return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
2207+
<< "Missing decoration " << _.SpvDecorationString(decor);
2208+
}
2209+
} else {
2210+
const Instruction* si_inst = ld_inst;
2211+
int t_idx = si_inst->GetOperandAs<int>(2); // texture
2212+
const Instruction* t_ld_inst = _.FindDef(t_idx);
2213+
if (t_ld_inst->opcode() != spv::Op::OpLoad) {
2214+
return _.diag(SPV_ERROR_INVALID_DATA, t_ld_inst)
2215+
<< "Expect to see OpLoad";
2216+
}
2217+
int texture_id = t_ld_inst->GetOperandAs<int>(2); // variable to load
2218+
spv::Decoration decor = spv::Decoration::BlockMatchTextureQCOM;
2219+
if (!_.HasDecoration(texture_id, decor)) {
2220+
return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
2221+
<< "Missing decoration " << _.SpvDecorationString(decor);
2222+
}
2223+
int s_idx = si_inst->GetOperandAs<int>(3); // sampler
2224+
const Instruction* s_ld_inst = _.FindDef(s_idx);
2225+
if (s_ld_inst->opcode() != spv::Op::OpLoad) {
2226+
return _.diag(SPV_ERROR_INVALID_DATA, s_ld_inst)
2227+
<< "Expect to see OpLoad";
2228+
}
2229+
int sampler_id = s_ld_inst->GetOperandAs<int>(2); // variable to load
2230+
decor = spv::Decoration::BlockMatchSamplerQCOM;
2231+
if (!_.HasDecoration(sampler_id, decor)) {
2232+
return _.diag(SPV_ERROR_INVALID_DATA, ld_inst)
2233+
<< "Missing decoration " << _.SpvDecorationString(decor);
2234+
}
2235+
}
2236+
2237+
return SPV_SUCCESS;
2238+
}
2239+
21892240
spv_result_t ValidateImageProcessingQCOM(ValidationState_t& _,
21902241
const Instruction* inst) {
21912242
spv_result_t res = SPV_SUCCESS;
@@ -2211,18 +2262,10 @@ spv_result_t ValidateImageProcessingQCOM(ValidationState_t& _,
22112262
case spv::Op::OpImageBlockMatchWindowSSDQCOM:
22122263
case spv::Op::OpImageBlockMatchWindowSADQCOM: {
22132264
int tgt_idx = inst->GetOperandAs<int>(2); // target
2214-
res = ValidateImageProcessingQCOMDecoration(
2215-
_, tgt_idx, spv::Decoration::BlockMatchTextureQCOM);
2216-
if (res != SPV_SUCCESS) break;
2217-
res = ValidateImageProcessingQCOMDecoration(
2218-
_, tgt_idx, spv::Decoration::BlockMatchSamplerQCOM);
2265+
res = ValidateImageProcessing2QCOMWindowDecoration(_, tgt_idx);
22192266
if (res != SPV_SUCCESS) break;
22202267
int ref_idx = inst->GetOperandAs<int>(4); // reference
2221-
res = ValidateImageProcessingQCOMDecoration(
2222-
_, ref_idx, spv::Decoration::BlockMatchTextureQCOM);
2223-
if (res != SPV_SUCCESS) break;
2224-
res = ValidateImageProcessingQCOMDecoration(
2225-
_, ref_idx, spv::Decoration::BlockMatchSamplerQCOM);
2268+
res = ValidateImageProcessing2QCOMWindowDecoration(_, ref_idx);
22262269
break;
22272270
}
22282271
case spv::Op::OpImageBlockMatchGatherSSDQCOM:

test/val/val_image_test.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8332,9 +8332,9 @@ TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADNoDecorRefNIT) {
83328332
OpDecorate %4 DescriptorSet 0
83338333
OpDecorate %4 Binding 1
83348334
OpDecorate %4 BlockMatchTextureQCOM
8335-
OpDecorate %4 BlockMatchSamplerQCOM
83368335
OpDecorate %5 DescriptorSet 0
83378336
OpDecorate %5 Binding 3
8337+
OpDecorate %5 BlockMatchSamplerQCOM
83388338
OpDecorate %6 DescriptorSet 0
83398339
OpDecorate %6 Binding 2
83408340
OpDecorate %6 BlockMatchSamplerQCOM
@@ -8816,9 +8816,9 @@ TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDNoDecorRefNIT) {
88168816
OpDecorate %4 DescriptorSet 0
88178817
OpDecorate %4 Binding 1
88188818
OpDecorate %4 BlockMatchTextureQCOM
8819-
OpDecorate %4 BlockMatchSamplerQCOM
88208819
OpDecorate %5 DescriptorSet 0
88218820
OpDecorate %5 Binding 3
8821+
OpDecorate %5 BlockMatchSamplerQCOM
88228822
OpDecorate %6 DescriptorSet 0
88238823
OpDecorate %6 Binding 2
88248824
OpDecorate %6 BlockMatchSamplerQCOM
@@ -9557,9 +9557,8 @@ TEST_F(ValidateImage,
95579557
OpDecorate %104 DescriptorSet 0
95589558
OpDecorate %104 Binding 2
95599559
OpDecorate %102 BlockMatchTextureQCOM
9560-
OpDecorate %102 BlockMatchSamplerQCOM
9560+
OpDecorate %103 BlockMatchSamplerQCOM
95619561
OpDecorate %104 BlockMatchTextureQCOM
9562-
OpDecorate %104 BlockMatchSamplerQCOM
95639562
%void = OpTypeVoid
95649563
%3 = OpTypeFunction %void
95659564
%uint = OpTypeInt 32 0
@@ -9632,9 +9631,8 @@ TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSADInvalidUseRefNI) {
96329631
OpDecorate %104 DescriptorSet 0
96339632
OpDecorate %104 Binding 2
96349633
OpDecorate %102 BlockMatchTextureQCOM
9635-
OpDecorate %102 BlockMatchSamplerQCOM
9634+
OpDecorate %103 BlockMatchSamplerQCOM
96369635
OpDecorate %104 BlockMatchTextureQCOM
9637-
OpDecorate %104 BlockMatchSamplerQCOM
96389636
%void = OpTypeVoid
96399637
%3 = OpTypeFunction %void
96409638
%uint = OpTypeInt 32 0
@@ -9847,9 +9845,8 @@ TEST_F(ValidateImage,
98479845
OpDecorate %104 DescriptorSet 0
98489846
OpDecorate %104 Binding 2
98499847
OpDecorate %102 BlockMatchTextureQCOM
9850-
OpDecorate %102 BlockMatchSamplerQCOM
9848+
OpDecorate %103 BlockMatchSamplerQCOM
98519849
OpDecorate %104 BlockMatchTextureQCOM
9852-
OpDecorate %104 BlockMatchSamplerQCOM
98539850
%void = OpTypeVoid
98549851
%3 = OpTypeFunction %void
98559852
%uint = OpTypeInt 32 0
@@ -9922,9 +9919,8 @@ TEST_F(ValidateImage, QCOMImageProcessing2BlockMatchWindowSSDInvalidUseRefNI) {
99229919
OpDecorate %104 DescriptorSet 0
99239920
OpDecorate %104 Binding 2
99249921
OpDecorate %102 BlockMatchTextureQCOM
9925-
OpDecorate %102 BlockMatchSamplerQCOM
9922+
OpDecorate %103 BlockMatchSamplerQCOM
99269923
OpDecorate %104 BlockMatchTextureQCOM
9927-
OpDecorate %104 BlockMatchSamplerQCOM
99289924
%void = OpTypeVoid
99299925
%3 = OpTypeFunction %void
99309926
%uint = OpTypeInt 32 0

0 commit comments

Comments
 (0)