diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index b1671dc958..975ca26c32 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -3719,6 +3719,14 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { return Fail() << " image gather is not yet supported"; case SpvOpImageQueryLod: return Fail() << " image query Lod is not yet supported"; + case SpvOpImageFetch: + // Read a single texel from a sampled image. + builtin_name = "textureLoad"; + break; + case SpvOpImageRead: + // Read a single texel from a storage image. + builtin_name = "textureLoad"; + break; case SpvOpImageWrite: builtin_name = "textureStore"; if (arg_index < num_args) { diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc index 4f1a61f855..b6ec4978e6 100644 --- a/src/reader/spirv/parser_impl_handle_test.cc +++ b/src/reader/spirv/parser_impl_handle_test.cc @@ -2823,6 +2823,128 @@ INSTANTIATE_TEST_SUITE_P( ) })"}})); +INSTANTIATE_TEST_SUITE_P( + ImageRead_OptionalParams, + SpvParserTest_ImageAccessTest, + ::testing::ValuesIn(std::vector{ + // OpImageRead with no extra params + {"%float 2D 0 0 0 2 Rgba32f", "%99 = OpImageRead %v4float %im %vu12", + R"(DecoratedVariable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __storage_texture_read_only_2d_rgba32float + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + Identifier[not set]{vu12} + ) + } + } + } + })"}, + // OpImageRead with ConstOffset + {"%float 2D 0 0 0 2 Rgba32f", + "%99 = OpImageRead %v4float %im %vu12 ConstOffset %offsets2d", + R"(DecoratedVariable{ + Decorations{ + SetDecoration{2} + BindingDecoration{1} + } + x_20 + uniform_constant + __storage_texture_read_only_2d_rgba32float + })", + R"(VariableDeclStatement{ + VariableConst{ + x_99 + none + __vec_4__f32 + { + Call[not set]{ + Identifier[not set]{textureLoad} + ( + Identifier[not set]{x_20} + Identifier[not set]{vu12} + Identifier[not set]{offsets2d} + ) + } + } + } + })"}})); + +INSTANTIATE_TEST_SUITE_P( + ImageFetch_OptionalParams, + SpvParserTest_ImageAccessTest, + ::testing::ValuesIn(std::vector{ + // OpImageFetch with no extra params + {"%float 2D 0 0 0 1 Rgba32f", "%99 = OpImageFetch %v4float %im %vu12", + R"(DecoratedVariable{ + 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]{vu12} + ) + } + } + } + })"}, + // OpImageFetch with ConstOffset + {"%float 2D 0 0 0 1 Rgba32f", + "%99 = OpImageFetch %v4float %im %vu12 ConstOffset %offsets2d", + R"(DecoratedVariable{ + 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]{vu12} + Identifier[not set]{offsets2d} + ) + } + } + } + })"}})); + INSTANTIATE_TEST_SUITE_P( // The SPIR-V result type could be integral but of different signedness // than the sampled texel type. In these cases the result should be