diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 69ec724a07..ec990051e7 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -4078,6 +4078,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { std::string builtin_name; bool use_level_of_detail_suffix = true; + bool is_dref = false; switch (opcode) { case SpvOpImageSampleImplicitLod: case SpvOpImageSampleExplicitLod: @@ -4085,6 +4086,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { break; case SpvOpImageSampleDrefImplicitLod: case SpvOpImageSampleDrefExplicitLod: + is_dref = true; builtin_name = "textureSampleCompare"; if (arg_index < num_args) { params.push_back(MakeOperand(inst, arg_index).expr); @@ -4141,6 +4143,11 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { } if (arg_index < num_args && (image_operands_mask & SpvImageOperandsBiasMask)) { + if (is_dref) { + return Fail() << "WGSL does not support depth-reference sampling with " + "level-of-detail bias: " + << inst.PrettyPrint(); + } builtin_name += "Bias"; params.push_back(MakeOperand(inst, arg_index).expr); image_operands_mask ^= SpvImageOperandsBiasMask; @@ -4162,6 +4169,11 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { } if (arg_index + 1 < num_args && (image_operands_mask & SpvImageOperandsGradMask)) { + if (is_dref) { + return Fail() << "WGSL does not support depth-reference sampling with " + "explicit gradient: " + << inst.PrettyPrint(); + } builtin_name += "Grad"; params.push_back(MakeOperand(inst, arg_index).expr); params.push_back(MakeOperand(inst, arg_index + 1).expr); diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 5cccc1a964..619bfe3b38 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -1702,7 +1702,7 @@ INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P( // This test shows the use of a sampled image used with both regular - // sampling and depth-refernce sampling. The texture is a depth-texture, + // sampling and depth-reference sampling. The texture is a depth-texture, // and we use builtins textureSample and textureSampleCompare ImageSampleImplicitLod_BothDrefAndNonDref, SpvParserTest_SampledImageAccessTest, @@ -4428,6 +4428,44 @@ INSTANTIATE_TEST_SUITE_P( "ConstOffset is only permitted for 2D, 2D Arrayed, and 3D textures: ", {}}})); +INSTANTIATE_TEST_SUITE_P( + ImageSampleDref_Bias_IsError, + SpvParserTest_ImageCoordsTest, + ::testing::ValuesIn(std::vector{ + // Implicit Lod + {"%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefImplicitLod %float %sampled_image %vf1234 " + "%depth Bias %float_null", + "WGSL does not support depth-reference sampling with level-of-detail " + "bias: ", + {}}, + // Explicit Lod + {"%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf1234 " + "%depth Lod|Bias %float_null %float_null", + "WGSL does not support depth-reference sampling with level-of-detail " + "bias: ", + {}}})); + +INSTANTIATE_TEST_SUITE_P( + ImageSampleDref_Grad_IsError, + SpvParserTest_ImageCoordsTest, + ::testing::ValuesIn(std::vector{ + // Implicit Lod + {"%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefImplicitLod %float %sampled_image %vf1234 " + "%depth Grad %float_1 %float_2", + "WGSL does not support depth-reference sampling with explicit " + "gradient: ", + {}}, + // Explicit Lod + {"%float 2D 1 0 0 1 Unknown", + "%result = OpImageSampleDrefExplicitLod %float %sampled_image %vf1234 " + "%depth Lod|Grad %float_null %float_1 %float_2", + "WGSL does not support depth-reference sampling with explicit " + "gradient: ", + {}}})); + } // namespace } // namespace spirv } // namespace reader