Tint/GLSL: fix null ptr deref in Texture1D -> 2D.

Bug: 1405676
Change-Id: If6edb0ba2b6c1ddd5d75421d234e168297e1b622
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116700
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
senorblanco@chromium.org 2023-01-10 02:13:48 +00:00 committed by Dawn LUCI CQ
parent ab00dd0725
commit 477744b7b5
9 changed files with 119 additions and 1 deletions

View File

@ -126,7 +126,10 @@ struct Texture1DTo2D::State {
return nullptr;
}
const auto& signature = builtin->Signature();
auto texture = signature.Parameter(sem::ParameterUsage::kTexture);
auto* texture = signature.Parameter(sem::ParameterUsage::kTexture);
if (!texture) {
return nullptr;
}
auto* tex = texture->Type()->As<type::Texture>();
if (tex->dim() != ast::TextureDimension::k1d) {
return nullptr;

View File

@ -275,5 +275,30 @@ fn main() {
EXPECT_EQ(expect, str(got));
}
TEST_F(Texture1DTo2DTest, TextureAndNonTextureBuiltin) {
auto* src = R"(
@group(0) @binding(0) var tex : texture_1d<i32>;
fn d() {
textureLoad(tex, 1, 0);
let l = sin(3.0);
}
)";
auto* expect = R"(
@group(0) @binding(0) var tex : texture_2d<i32>;
fn d() {
textureLoad(tex, vec2<i32>(1, 0), 0);
let l = sin(3.0);
}
)";
DataMap data;
auto got = Run<Texture1DTo2D>(src, data);
EXPECT_EQ(expect, str(got));
}
} // namespace
} // namespace tint::transform

View File

@ -0,0 +1,6 @@
@group(0) @binding(0) var arg_0 : texture_1d<i32>;
fn d() {
textureLoad(arg_0, 1, 0);
let l = sin(3.0);
}

View File

@ -0,0 +1,11 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
Texture1D<int4> arg_0 : register(t0, space0);
void d() {
arg_0.Load(int2(1, 0));
const float l = 0.141120002f;
}

View File

@ -0,0 +1,11 @@
[numthreads(1, 1, 1)]
void unused_entry_point() {
return;
}
Texture1D<int4> arg_0 : register(t0, space0);
void d() {
arg_0.Load(int2(1, 0));
const float l = 0.141120002f;
}

View File

@ -0,0 +1,12 @@
#version 310 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
void unused_entry_point() {
return;
}
uniform highp isampler2D arg_0_1;
void d() {
texelFetch(arg_0_1, ivec2(1, 0), 0);
float l = 0.141120002f;
}

View File

@ -0,0 +1,8 @@
#include <metal_stdlib>
using namespace metal;
void d(texture1d<int, access::sample> tint_symbol) {
tint_symbol.read(uint(1), 0);
float const l = 0.141120002f;
}

View File

@ -0,0 +1,36 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 18
; Schema: 0
OpCapability Shader
OpCapability Sampled1D
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
OpExecutionMode %unused_entry_point LocalSize 1 1 1
OpName %arg_0 "arg_0"
OpName %unused_entry_point "unused_entry_point"
OpName %d "d"
OpDecorate %arg_0 DescriptorSet 0
OpDecorate %arg_0 Binding 0
%int = OpTypeInt 32 1
%3 = OpTypeImage %int 1D 0 0 0 1 Unknown
%_ptr_UniformConstant_3 = OpTypePointer UniformConstant %3
%arg_0 = OpVariable %_ptr_UniformConstant_3 UniformConstant
%void = OpTypeVoid
%5 = OpTypeFunction %void
%v4int = OpTypeVector %int 4
%int_1 = OpConstant %int 1
%15 = OpConstantNull %int
%float = OpTypeFloat 32
%float_0_141120002 = OpConstant %float 0.141120002
%unused_entry_point = OpFunction %void None %5
%8 = OpLabel
OpReturn
OpFunctionEnd
%d = OpFunction %void None %5
%10 = OpLabel
%13 = OpLoad %3 %arg_0
%11 = OpImageFetch %v4int %13 %int_1 Lod %15
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,6 @@
@group(0) @binding(0) var arg_0 : texture_1d<i32>;
fn d() {
textureLoad(arg_0, 1, 0);
let l = sin(3.0);
}