spirv-reader: Fix texture[Load|Store] with lod

Don't suffix texture intrinsics with `Load` unless it's a `textureSample`.

Discussion:
d46b4fa3ca (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>
This commit is contained in:
Ben Clayton 2020-12-15 12:34:38 +00:00 committed by Commit Bot service account
parent 0b930237ec
commit 11276ef97d
2 changed files with 36 additions and 1 deletions

View File

@ -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<ast::type::DepthTexture>()) {

View File

@ -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(