spirv-reader: Fix texture[Load|Store] with lod
Don't suffix texture intrinsics with `Load` unless it's a `textureSample`.
Discussion:
https://github.com/gpuweb/gpuweb/pull/1261/files/d46b4fa3ca20c4b6e82859391cea8c71009cd220#diff-709b5c343d59ae10cbabe69f9df1eee9e2dbb6e9d848632fa94357083d6e0a34
Bug: tint:109
Bug: dawn:399
Change-Id: Ic42ef9f8681dd04bd8f4c901c6d4cdc5f4166d26
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35423
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index c699115..c8303d5 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -3948,6 +3948,7 @@
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 @@
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 @@
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<ast::type::DepthTexture>()) {
diff --git a/src/reader/spirv/parser_impl_handle_test.cc b/src/reader/spirv/parser_impl_handle_test.cc
index 83055a6..4731bed 100644
--- a/src/reader/spirv/parser_impl_handle_test.cc
+++ b/src/reader/spirv/parser_impl_handle_test.cc
@@ -3134,6 +3134,35 @@
}
}
}
+ })"},
+ // 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(