tint/resolver: Fix NPE in CollectTextureSamplerPairs()

Fixed: tint:1715
Change-Id: Ie46d1348e44c4719ef318e7d18393713148338d7
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105620
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2022-10-13 13:45:35 +00:00 committed by Dawn LUCI CQ
parent 4fe330fff4
commit 92264f8bb2
2 changed files with 55 additions and 8 deletions

View File

@ -2091,14 +2091,16 @@ void Resolver::CollectTextureSamplerPairs(const sem::Builtin* builtin,
if (texture_index == -1) { if (texture_index == -1) {
TINT_ICE(Resolver, diagnostics_) << "texture builtin without texture parameter"; TINT_ICE(Resolver, diagnostics_) << "texture builtin without texture parameter";
} }
auto* texture = args[static_cast<size_t>(texture_index)]->As<sem::VariableUser>()->Variable(); if (auto* user = args[static_cast<size_t>(texture_index)]->As<sem::VariableUser>()) {
if (!texture->Type()->UnwrapRef()->Is<sem::StorageTexture>()) { auto* texture = user->Variable();
int sampler_index = signature.IndexOf(sem::ParameterUsage::kSampler); if (!texture->Type()->UnwrapRef()->Is<sem::StorageTexture>()) {
const sem::Variable* sampler = int sampler_index = signature.IndexOf(sem::ParameterUsage::kSampler);
sampler_index != -1 const sem::Variable* sampler =
? args[static_cast<size_t>(sampler_index)]->As<sem::VariableUser>()->Variable() sampler_index != -1
: nullptr; ? args[static_cast<size_t>(sampler_index)]->As<sem::VariableUser>()->Variable()
current_function_->AddTextureSamplerPair(texture, sampler); : nullptr;
current_function_->AddTextureSamplerPair(texture, sampler);
}
} }
} }

View File

@ -2212,6 +2212,51 @@ TEST_F(ResolverTest, TextureSampler_TextureDimensions) {
EXPECT_TRUE(pairs[0].second == nullptr); EXPECT_TRUE(pairs[0].second == nullptr);
} }
TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715
// @binding(0) @group(0) var s: sampler;
// @binding(1) @group(0) var t: texture_2d<f32>;
// @binding(2) @group(0) var<uniform> c: vec2<f32>;
//
// @fragment
// fn main() -> @location(0) vec4<f32> {
// return helper(&s, &t);
// }
//
// fn helper(sl: ptr<function, sampler>, tl: ptr<function, texture_2d<f32>>) -> vec4<f32> {
// return textureSampleLevel(*tl, *sl, c, 0.0);
// }
GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0_a), Binding(0_a));
GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0_a),
Binding(1_a));
GlobalVar("c", ty.vec2<f32>(), ast::AddressSpace::kUniform, Group(0_a), Binding(2_a));
Func("main", utils::Empty, ty.vec4<f32>(),
utils::Vector{
Return(Call("helper", AddressOf("s"), AddressOf("t"))),
},
utils::Vector{
Stage(ast::PipelineStage::kFragment),
},
utils::Vector{
Location(0_u),
});
Func("helper",
utils::Vector{
Param("sl", ty.pointer(ty.sampler(ast::SamplerKind::kSampler),
ast::AddressSpace::kFunction)),
Param("tl", ty.pointer(ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()),
ast::AddressSpace::kFunction)),
},
ty.vec4<f32>(),
utils::Vector{
Return(Call("textureSampleLevel", Deref("tl"), Deref("sl"), "c", 0.0_a)),
});
ASSERT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(), "error: cannot take the address of expression in handle address space");
}
TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) { TEST_F(ResolverTest, ModuleDependencyOrderedDeclarations) {
auto* f0 = Func("f0", utils::Empty, ty.void_(), utils::Empty); auto* f0 = Func("f0", utils::Empty, ty.void_(), utils::Empty);
auto* v0 = GlobalVar("v0", ty.i32(), ast::AddressSpace::kPrivate); auto* v0 = GlobalVar("v0", ty.i32(), ast::AddressSpace::kPrivate);