diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index c69911512d..c8303d5a41 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -3948,6 +3948,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { const auto num_args = inst.NumInOperands(); std::string builtin_name; + bool use_load_suffix = true; switch (inst.opcode()) { case SpvOpImageSampleImplicitLod: case SpvOpImageSampleExplicitLod: @@ -3973,13 +3974,16 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { case SpvOpImageFetch: // Read a single texel from a sampled image. builtin_name = "textureLoad"; + use_load_suffix = false; break; case SpvOpImageRead: // Read a single texel from a storage image. builtin_name = "textureLoad"; + use_load_suffix = false; break; case SpvOpImageWrite: builtin_name = "textureStore"; + use_load_suffix = false; if (arg_index < num_args) { auto texel = MakeOperand(inst, arg_index); auto* converted_texel = @@ -4014,7 +4018,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { arg_index++; } if (arg_index < num_args && (image_operands_mask & SpvImageOperandsLodMask)) { - builtin_name += "Level"; + if (use_load_suffix) { + builtin_name += "Level"; + } TypedExpression lod = MakeOperand(inst, arg_index); // When sampling from a depth texture, the Lod operand must be an I32. if (texture_type->Is()) { diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 83055a6be6..4731bedc38 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -3134,6 +3134,35 @@ INSTANTIATE_TEST_SUITE_P( } } } + })"}, + // OpImageFetch with explicit level + {"%float 2D 0 0 0 1 Unknown", + "%99 = OpImageFetch %v4float %im %vi12 Lod %int_3", + R"(Variable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __sampled_texture_2d__f32 + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + Identifier[not set]{vi12} + ScalarConstructor[not set]{3} + ) + } + } + } })"}})); INSTANTIATE_TEST_SUITE_P(