tint/transform: Don't hoist textures / samplers

in the PromoteSideEffectsToDecl transform

Fixed: tint:1739
Change-Id: Iaa5a6e086708a6bba601c59962042650829795f6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/107683
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2022-10-31 17:33:35 +00:00
committed by Dawn LUCI CQ
parent 22c4850b06
commit be83128031
9 changed files with 713 additions and 2 deletions

View File

@@ -281,11 +281,15 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase {
if (var_user->ConstantValue()) {
return false;
}
// Don't hoist read-only variables as they cannot receive
// side-effects.
// Don't hoist read-only variables as they cannot receive side-effects.
if (var_user->Variable()->Access() == ast::Access::kRead) {
return false;
}
// Don't hoist textures / samplers as they can't be placed into a let, nor
// can they have side effects.
if (var_user->Variable()->Type()->IsAnyOf<sem::Texture, sem::Sampler>()) {
return false;
}
return true;
}
}

View File

@@ -4081,5 +4081,54 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(PromoteSideEffectsToDeclTest, TextureSamplerParameter) {
auto* src = R"(
@group(0) @binding(0) var T : texture_2d<f32>;
@group(0) @binding(1) var S : sampler;
var<private> P : vec2<f32>;
fn side_effects() -> vec2<f32> {
P += vec2(1.0);
return P;
}
fn f(t : texture_2d<f32>, s : sampler) -> vec4<f32> {
return textureSample(t, s, side_effects());
}
fn m() -> vec4<f32>{
return f(T, S);
}
)";
auto* expect = R"(
@group(0) @binding(0) var T : texture_2d<f32>;
@group(0) @binding(1) var S : sampler;
var<private> P : vec2<f32>;
fn side_effects() -> vec2<f32> {
P += vec2(1.0);
return P;
}
fn f(t : texture_2d<f32>, s : sampler) -> vec4<f32> {
let tint_symbol = side_effects();
return textureSample(t, s, tint_symbol);
}
fn m() -> vec4<f32> {
return f(T, S);
}
)";
DataMap data;
auto got = Run<PromoteSideEffectsToDecl>(src, data);
EXPECT_EQ(expect, str(got));
}
} // namespace
} // namespace tint::transform