diff --git a/src/tint/transform/texture_1d_to_2d.cc b/src/tint/transform/texture_1d_to_2d.cc index 0e19d02601..85cd512aa9 100644 --- a/src/tint/transform/texture_1d_to_2d.cc +++ b/src/tint/transform/texture_1d_to_2d.cc @@ -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(); if (tex->dim() != ast::TextureDimension::k1d) { return nullptr; diff --git a/src/tint/transform/texture_1d_to_2d_test.cc b/src/tint/transform/texture_1d_to_2d_test.cc index 83a12bd3a1..687988cf25 100644 --- a/src/tint/transform/texture_1d_to_2d_test.cc +++ b/src/tint/transform/texture_1d_to_2d_test.cc @@ -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; + +fn d() { + textureLoad(tex, 1, 0); + let l = sin(3.0); +} +)"; + + auto* expect = R"( +@group(0) @binding(0) var tex : texture_2d; + +fn d() { + textureLoad(tex, vec2(1, 0), 0); + let l = sin(3.0); +} +)"; + + DataMap data; + auto got = Run(src, data); + + EXPECT_EQ(expect, str(got)); +} + } // namespace } // namespace tint::transform diff --git a/test/tint/bug/chromium/1405676.wgsl b/test/tint/bug/chromium/1405676.wgsl new file mode 100644 index 0000000000..38f66a418f --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl @@ -0,0 +1,6 @@ +@group(0) @binding(0) var arg_0 : texture_1d; + +fn d() { + textureLoad(arg_0, 1, 0); + let l = sin(3.0); +} diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.dxc.hlsl b/test/tint/bug/chromium/1405676.wgsl.expected.dxc.hlsl new file mode 100644 index 0000000000..4b4cf12827 --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.dxc.hlsl @@ -0,0 +1,11 @@ +[numthreads(1, 1, 1)] +void unused_entry_point() { + return; +} + +Texture1D arg_0 : register(t0, space0); + +void d() { + arg_0.Load(int2(1, 0)); + const float l = 0.141120002f; +} diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.fxc.hlsl b/test/tint/bug/chromium/1405676.wgsl.expected.fxc.hlsl new file mode 100644 index 0000000000..4b4cf12827 --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.fxc.hlsl @@ -0,0 +1,11 @@ +[numthreads(1, 1, 1)] +void unused_entry_point() { + return; +} + +Texture1D arg_0 : register(t0, space0); + +void d() { + arg_0.Load(int2(1, 0)); + const float l = 0.141120002f; +} diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.glsl b/test/tint/bug/chromium/1405676.wgsl.expected.glsl new file mode 100644 index 0000000000..6a46c61912 --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.glsl @@ -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; +} + diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.msl b/test/tint/bug/chromium/1405676.wgsl.expected.msl new file mode 100644 index 0000000000..b32437b52a --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.msl @@ -0,0 +1,8 @@ +#include + +using namespace metal; +void d(texture1d tint_symbol) { + tint_symbol.read(uint(1), 0); + float const l = 0.141120002f; +} + diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.spvasm b/test/tint/bug/chromium/1405676.wgsl.expected.spvasm new file mode 100644 index 0000000000..9394063ea6 --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.spvasm @@ -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 diff --git a/test/tint/bug/chromium/1405676.wgsl.expected.wgsl b/test/tint/bug/chromium/1405676.wgsl.expected.wgsl new file mode 100644 index 0000000000..38f66a418f --- /dev/null +++ b/test/tint/bug/chromium/1405676.wgsl.expected.wgsl @@ -0,0 +1,6 @@ +@group(0) @binding(0) var arg_0 : texture_1d; + +fn d() { + textureLoad(arg_0, 1, 0); + let l = sin(3.0); +}