[tint][msl] Handle binding_array in the printer.
Bug: 393558555
Change-Id: I21ab0d5f1fcc02995ad11c1f9c358e2d8d79735e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/229235
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/tint/lang/glsl/writer/writer.cc b/src/tint/lang/glsl/writer/writer.cc
index aa1a088..353b47d 100644
--- a/src/tint/lang/glsl/writer/writer.cc
+++ b/src/tint/lang/glsl/writer/writer.cc
@@ -30,6 +30,7 @@
#include "src/tint/lang/core/ir/core_builtin_call.h"
#include "src/tint/lang/core/ir/module.h"
#include "src/tint/lang/core/ir/var.h"
+#include "src/tint/lang/core/type/binding_array.h"
#include "src/tint/lang/core/type/pointer.h"
#include "src/tint/lang/core/type/storage_texture.h"
#include "src/tint/lang/glsl/writer/printer/printer.h"
@@ -43,6 +44,9 @@
if (ty->Is<core::type::SubgroupMatrix>()) {
return Failure("subgroup matrices are not supported by the GLSL backend");
}
+ if (ty->Is<core::type::BindingArray>()) {
+ return Failure("binding_array are not supported by the GLSL backend");
+ }
}
// Make sure that every texture variable is in the texture_builtins_from_uniform binding list,
diff --git a/src/tint/lang/hlsl/writer/writer.cc b/src/tint/lang/hlsl/writer/writer.cc
index a18e546..cefb6f9 100644
--- a/src/tint/lang/hlsl/writer/writer.cc
+++ b/src/tint/lang/hlsl/writer/writer.cc
@@ -33,6 +33,7 @@
#include "src/tint/lang/core/ir/function.h"
#include "src/tint/lang/core/ir/module.h"
#include "src/tint/lang/core/ir/var.h"
+#include "src/tint/lang/core/type/binding_array.h"
#include "src/tint/lang/core/type/input_attachment.h"
#include "src/tint/lang/hlsl/writer/ast_printer/ast_printer.h"
#include "src/tint/lang/hlsl/writer/printer/printer.h"
@@ -47,6 +48,9 @@
if (ty->Is<core::type::SubgroupMatrix>()) {
return Failure("subgroup matrices are not supported by the HLSL backend");
}
+ if (ty->Is<core::type::BindingArray>()) {
+ return Failure("binding_array are not supported by the HLSL backend");
+ }
}
// Check for unsupported module-scope variable address spaces and types.
diff --git a/src/tint/lang/msl/writer/printer/printer.cc b/src/tint/lang/msl/writer/printer/printer.cc
index 51f2aec..da02455 100644
--- a/src/tint/lang/msl/writer/printer/printer.cc
+++ b/src/tint/lang/msl/writer/printer/printer.cc
@@ -70,6 +70,7 @@
#include "src/tint/lang/core/ir/var.h"
#include "src/tint/lang/core/type/array.h"
#include "src/tint/lang/core/type/atomic.h"
+#include "src/tint/lang/core/type/binding_array.h"
#include "src/tint/lang/core/type/bool.h"
#include "src/tint/lang/core/type/depth_multisampled_texture.h"
#include "src/tint/lang/core/type/depth_texture.h"
@@ -399,8 +400,15 @@
}
} else {
// Handle types are declared by value instead of by pointer.
+ // In MSL the attribute for BindingArray is the same as the attribute for
+ // the first element.
+ auto* handle_type = param->Type();
+ if (handle_type->Is<core::type::BindingArray>()) {
+ handle_type = handle_type->As<core::type::BindingArray>()->ElemType();
+ }
+
Switch(
- param->Type(),
+ handle_type,
[&](const core::type::Texture*) {
out << " [[texture(" << binding_point->binding << ")]]";
},
@@ -1303,6 +1311,7 @@
[&](const core::type::Pointer* ptr) { EmitPointerType(out, ptr); },
[&](const core::type::Sampler*) { out << "sampler"; }, //
[&](const core::type::Texture* tex) { EmitTextureType(out, tex); },
+ [&](const core::type::BindingArray* arr) { EmitBindingArrayType(out, arr); },
[&](const core::type::Struct* str) {
out << StructName(str);
@@ -1406,6 +1415,17 @@
out << mat->Columns() << "x" << mat->Rows();
}
+ /// Handles generating a binding_array declaration
+ /// @param out the output stream
+ /// @param arr the array to emit
+ void EmitBindingArrayType(StringStream& out, const core::type::BindingArray* arr) {
+ out << "array<";
+ EmitType(out, arr->ElemType());
+ out << ", ";
+ out << arr->Count()->As<core::type::ConstantArrayCount>()->value;
+ out << ">";
+ }
+
/// Handles generating a texture declaration
/// @param out the output stream
/// @param tex the texture to emit
diff --git a/src/tint/lang/msl/writer/type_test.cc b/src/tint/lang/msl/writer/type_test.cc
index ef96b19..04571a0 100644
--- a/src/tint/lang/msl/writer/type_test.cc
+++ b/src/tint/lang/msl/writer/type_test.cc
@@ -28,6 +28,7 @@
#include "gmock/gmock.h"
#include "src/tint/lang/core/type/array.h"
+#include "src/tint/lang/core/type/binding_array.h"
#include "src/tint/lang/core/type/depth_multisampled_texture.h"
#include "src/tint/lang/core/type/depth_texture.h"
#include "src/tint/lang/core/type/matrix.h"
@@ -991,6 +992,22 @@
)");
}
+TEST_F(MslWriterTest, EmitType_BindingArraySampledTexture) {
+ auto* func = b.Function("foo", ty.void_());
+ auto* sampled_texture = ty.sampled_texture(core::type::TextureDimension::k2d, ty.f32());
+ auto* param = b.FunctionParam("a", ty.binding_array(sampled_texture, 4_u));
+ func->SetParams({param});
+ b.Append(func->Block(), [&] { //
+ b.Return(func);
+ });
+
+ ASSERT_TRUE(Generate()) << err_ << output_.msl;
+ EXPECT_EQ(output_.msl, MetalHeader() + R"(
+void foo(array<texture2d<float, access::sample>, 4> a) {
+}
+)");
+}
+
struct MslDepthTextureData {
core::type::TextureDimension dim;
std::string result;
diff --git a/src/tint/lang/spirv/writer/writer.cc b/src/tint/lang/spirv/writer/writer.cc
index c6d43e3..bfcca93 100644
--- a/src/tint/lang/spirv/writer/writer.cc
+++ b/src/tint/lang/spirv/writer/writer.cc
@@ -31,6 +31,7 @@
#include <utility>
#include "src/tint/lang/core/ir/var.h"
+#include "src/tint/lang/core/type/binding_array.h"
#include "src/tint/lang/core/type/pointer.h"
#include "src/tint/lang/spirv/writer/common/option_helpers.h"
#include "src/tint/lang/spirv/writer/printer/printer.h"
@@ -49,6 +50,9 @@
return Failure("using subgroup matrices requires the Vulkan Memory Model");
}
}
+ if (ty->Is<core::type::BindingArray>()) {
+ return Failure("binding_array are not supported by the SPIR-V backend");
+ }
}
// If a remapped entry point name is provided, it must not be empty, and must not contain
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl b/test/tint/binding_array/access_as_function_argument.wgsl
new file mode 100644
index 0000000..77dd4d2
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl
@@ -0,0 +1,9 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment fn fs() {
+ do_texture_load(sampled_textures[0]);
+}
+
+fn do_texture_load(t : texture_2d<f32>) {
+ let texture_load = textureLoad(t, vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.dxc.hlsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.fxc.hlsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.glsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.glsl
new file mode 100644
index 0000000..82220c4
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.glsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/glsl/writer/raise/texture_builtins_from_uniform.cc:137 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.dxc.hlsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.dxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.fxc.hlsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.fxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.ir.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.msl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.msl
new file mode 100644
index 0000000..5100a0a
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.msl
@@ -0,0 +1,17 @@
+#include <metal_stdlib>
+using namespace metal;
+
+struct tint_module_vars_struct {
+ array<texture2d<float, access::sample>, 4> sampled_textures;
+};
+
+void do_texture_load(texture2d<float, access::sample> t) {
+ uint const v = min(uint(0), (t.get_num_mip_levels() - 1u));
+ uint2 const v_1 = (uint2(t.get_width(v), t.get_height(v)) - uint2(1u));
+ float4 const texture_load = t.read(min(uint2(int2(0)), v_1), v);
+}
+
+fragment void fs(array<texture2d<float, access::sample>, 4> sampled_textures [[texture(0)]]) {
+ tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sampled_textures=sampled_textures};
+ do_texture_load(tint_module_vars.sampled_textures[0]);
+}
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.spvasm b/test/tint/binding_array/access_as_function_argument.wgsl.expected.spvasm
new file mode 100644
index 0000000..3220aa1
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.spvasm
@@ -0,0 +1,53 @@
+SKIP: FAILED
+
+
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ do_texture_load(sampled_textures[0]);
+}
+
+fn do_texture_load(t : texture_2d<f32>) {
+ let texture_load = textureLoad(t, vec2(0, 0), 0);
+}
+
+Failed to generate SPIR-V: :22:135 error: access: result of access chain is type 'ptr<handle, texture_2d<f32>, read>' but instruction type is 'ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read>'
+ %15:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, 0i
+ ^^^^^^
+
+:21:3 note: in block
+ $B3: {
+ ^^^
+
+note: # Disassembly
+$B1: { # root
+ %sampled_textures:ptr<handle, binding_array<texture_2d<f32>, 4>, read> = var undef @binding_point(0, 0)
+}
+
+%do_texture_load = func(%t:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>):void {
+ $B2: {
+ %4:u32 = spirv.image_query_levels<u32> %t
+ %5:u32 = sub %4, 1u
+ %6:u32 = convert 0i
+ %7:u32 = min %6, %5
+ %8:vec2<u32> = spirv.image_query_size_lod %t, %7
+ %9:vec2<u32> = sub %8, vec2<u32>(1u)
+ %10:vec2<u32> = convert vec2<i32>(0i)
+ %11:vec2<u32> = min %10, %9
+ %12:vec4<f32> = spirv.image_fetch %t, %11, 2u, %7
+ %texture_load:vec4<f32> = let %12
+ ret
+ }
+}
+%fs = @fragment func():void {
+ $B3: {
+ %15:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, 0i
+ %16:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write> = load %15
+ %17:void = call %do_texture_load, %16
+ ret
+ }
+}
+
+
+tint executable returned error: exit status 1
diff --git a/test/tint/binding_array/access_as_function_argument.wgsl.expected.wgsl b/test/tint/binding_array/access_as_function_argument.wgsl.expected.wgsl
new file mode 100644
index 0000000..8abf789
--- /dev/null
+++ b/test/tint/binding_array/access_as_function_argument.wgsl.expected.wgsl
@@ -0,0 +1,10 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ do_texture_load(sampled_textures[0]);
+}
+
+fn do_texture_load(t : texture_2d<f32>) {
+ let texture_load = textureLoad(t, vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/access_constant.wgsl b/test/tint/binding_array/access_constant.wgsl
new file mode 100644
index 0000000..2869558
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl
@@ -0,0 +1,5 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment fn fs() {
+ let texture_load = textureLoad(sampled_textures[0], vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.dxc.hlsl b/test/tint/binding_array/access_constant.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.fxc.hlsl b/test/tint/binding_array/access_constant.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.glsl b/test/tint/binding_array/access_constant.wgsl.expected.glsl
new file mode 100644
index 0000000..82220c4
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.glsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/glsl/writer/raise/texture_builtins_from_uniform.cc:137 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.ir.dxc.hlsl b/test/tint/binding_array/access_constant.wgsl.expected.ir.dxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.ir.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.ir.fxc.hlsl b/test/tint/binding_array/access_constant.wgsl.expected.ir.fxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.ir.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.msl b/test/tint/binding_array/access_constant.wgsl.expected.msl
new file mode 100644
index 0000000..5322abe
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.msl
@@ -0,0 +1,13 @@
+#include <metal_stdlib>
+using namespace metal;
+
+struct tint_module_vars_struct {
+ array<texture2d<float, access::sample>, 4> sampled_textures;
+};
+
+fragment void fs(array<texture2d<float, access::sample>, 4> sampled_textures [[texture(0)]]) {
+ tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sampled_textures=sampled_textures};
+ uint const v = min(uint(0), (tint_module_vars.sampled_textures[0].get_num_mip_levels() - 1u));
+ uint2 const v_1 = (uint2(tint_module_vars.sampled_textures[0].get_width(v), tint_module_vars.sampled_textures[0].get_height(v)) - uint2(1u));
+ float4 const texture_load = tint_module_vars.sampled_textures[0].read(min(uint2(int2(0)), v_1), v);
+}
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.spvasm b/test/tint/binding_array/access_constant.wgsl.expected.spvasm
new file mode 100644
index 0000000..7baf484
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.spvasm
@@ -0,0 +1,43 @@
+SKIP: FAILED
+
+
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ let texture_load = textureLoad(sampled_textures[0], vec2(0, 0), 0);
+}
+
+Failed to generate SPIR-V: :7:134 error: access: result of access chain is type 'ptr<handle, texture_2d<f32>, read>' but instruction type is 'ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read>'
+ %3:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, 0i
+ ^^^^^^
+
+:6:3 note: in block
+ $B2: {
+ ^^^
+
+note: # Disassembly
+$B1: { # root
+ %sampled_textures:ptr<handle, binding_array<texture_2d<f32>, 4>, read> = var undef @binding_point(0, 0)
+}
+
+%fs = @fragment func():void {
+ $B2: {
+ %3:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, 0i
+ %4:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write> = load %3
+ %5:u32 = spirv.image_query_levels<u32> %4
+ %6:u32 = sub %5, 1u
+ %7:u32 = convert 0i
+ %8:u32 = min %7, %6
+ %9:vec2<u32> = spirv.image_query_size_lod %4, %8
+ %10:vec2<u32> = sub %9, vec2<u32>(1u)
+ %11:vec2<u32> = convert vec2<i32>(0i)
+ %12:vec2<u32> = min %11, %10
+ %13:vec4<f32> = spirv.image_fetch %4, %12, 2u, %8
+ %texture_load:vec4<f32> = let %13
+ ret
+ }
+}
+
+
+tint executable returned error: exit status 1
diff --git a/test/tint/binding_array/access_constant.wgsl.expected.wgsl b/test/tint/binding_array/access_constant.wgsl.expected.wgsl
new file mode 100644
index 0000000..81cd8b1
--- /dev/null
+++ b/test/tint/binding_array/access_constant.wgsl.expected.wgsl
@@ -0,0 +1,6 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ let texture_load = textureLoad(sampled_textures[0], vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/access_uniform.wgsl b/test/tint/binding_array/access_uniform.wgsl
new file mode 100644
index 0000000..fe0922f
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl
@@ -0,0 +1,6 @@
+@group(1) @binding(0) var<uniform> index : u32;
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment fn fs() {
+ let texture_load = textureLoad(sampled_textures[index], vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.dxc.hlsl b/test/tint/binding_array/access_uniform.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.fxc.hlsl b/test/tint/binding_array/access_uniform.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..0fec7c1
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:4795 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.glsl b/test/tint/binding_array/access_uniform.wgsl.expected.glsl
new file mode 100644
index 0000000..82220c4
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.glsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/glsl/writer/raise/texture_builtins_from_uniform.cc:137 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.ir.dxc.hlsl b/test/tint/binding_array/access_uniform.wgsl.expected.ir.dxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.ir.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.ir.fxc.hlsl b/test/tint/binding_array/access_uniform.wgsl.expected.ir.fxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.ir.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.msl b/test/tint/binding_array/access_uniform.wgsl.expected.msl
new file mode 100644
index 0000000..c451173
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.msl
@@ -0,0 +1,15 @@
+#include <metal_stdlib>
+using namespace metal;
+
+struct tint_module_vars_struct {
+ const constant uint* index;
+ array<texture2d<float, access::sample>, 4> sampled_textures;
+};
+
+fragment void fs(const constant uint* index [[buffer(0)]], array<texture2d<float, access::sample>, 4> sampled_textures [[texture(0)]]) {
+ tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.index=index, .sampled_textures=sampled_textures};
+ texture2d<float, access::sample> const v = tint_module_vars.sampled_textures[(*tint_module_vars.index)];
+ uint const v_1 = min(uint(0), (v.get_num_mip_levels() - 1u));
+ uint2 const v_2 = (uint2(v.get_width(v_1), v.get_height(v_1)) - uint2(1u));
+ float4 const texture_load = v.read(min(uint2(int2(0)), v_2), v_1);
+}
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.spvasm b/test/tint/binding_array/access_uniform.wgsl.expected.spvasm
new file mode 100644
index 0000000..a93b2df
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.spvasm
@@ -0,0 +1,52 @@
+SKIP: FAILED
+
+
+@group(1) @binding(0) var<uniform> index : u32;
+
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ let texture_load = textureLoad(sampled_textures[index], vec2(0, 0), 0);
+}
+
+Failed to generate SPIR-V: :14:134 error: access: result of access chain is type 'ptr<handle, texture_2d<f32>, read>' but instruction type is 'ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read>'
+ %6:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, %5
+ ^^^^^^
+
+:11:3 note: in block
+ $B2: {
+ ^^^
+
+note: # Disassembly
+index_block = struct @align(4), @block {
+ inner:u32 @offset(0)
+}
+
+$B1: { # root
+ %1:ptr<uniform, index_block, read> = var undef @binding_point(1, 0)
+ %sampled_textures:ptr<handle, binding_array<texture_2d<f32>, 4>, read> = var undef @binding_point(0, 0)
+}
+
+%fs = @fragment func():void {
+ $B2: {
+ %4:ptr<uniform, u32, read> = access %1, 0u
+ %5:u32 = load %4
+ %6:ptr<handle, spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>, read> = access %sampled_textures, %5
+ %7:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write> = load %6
+ %8:u32 = spirv.image_query_levels<u32> %7
+ %9:u32 = sub %8, 1u
+ %10:u32 = convert 0i
+ %11:u32 = min %10, %9
+ %12:vec2<u32> = spirv.image_query_size_lod %7, %11
+ %13:vec2<u32> = sub %12, vec2<u32>(1u)
+ %14:vec2<u32> = convert vec2<i32>(0i)
+ %15:vec2<u32> = min %14, %13
+ %16:vec4<f32> = spirv.image_fetch %7, %15, 2u, %11
+ %texture_load:vec4<f32> = let %16
+ ret
+ }
+}
+
+
+tint executable returned error: exit status 1
diff --git a/test/tint/binding_array/access_uniform.wgsl.expected.wgsl b/test/tint/binding_array/access_uniform.wgsl.expected.wgsl
new file mode 100644
index 0000000..184f867
--- /dev/null
+++ b/test/tint/binding_array/access_uniform.wgsl.expected.wgsl
@@ -0,0 +1,8 @@
+@group(1) @binding(0) var<uniform> index : u32;
+
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ let texture_load = textureLoad(sampled_textures[index], vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/as_function_parameter.wgsl b/test/tint/binding_array/as_function_parameter.wgsl
new file mode 100644
index 0000000..27234b7
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl
@@ -0,0 +1,9 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment fn fs() {
+ do_texture_load(sampled_textures);
+}
+
+fn do_texture_load(ts : binding_array<texture_2d<f32>, 4>) {
+ let texture_load = textureLoad(ts[0], vec2(0, 0), 0);
+}
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.dxc.hlsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..221fe66
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/wgsl/ast/transform/robustness.cc:278 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.fxc.hlsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..221fe66
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/wgsl/ast/transform/robustness.cc:278 internal compiler error: Switch() matched no cases. Type: tint::core::type::BindingArray
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.glsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.glsl
new file mode 100644
index 0000000..82220c4
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.glsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/glsl/writer/raise/texture_builtins_from_uniform.cc:137 internal compiler error: Switch() matched no cases. Type: tint::core::ir::Access
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.dxc.hlsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.dxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.dxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.fxc.hlsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.fxc.hlsl
new file mode 100644
index 0000000..4f6e83d
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.ir.fxc.hlsl
@@ -0,0 +1,12 @@
+SKIP: FAILED
+
+../../src/tint/lang/hlsl/writer/printer/printer.cc:636 internal compiler error: TINT_ASSERT(register_space != ' ')
+
+********************************************************************
+* The tint shader compiler has encountered an unexpected error. *
+* *
+* Please help us fix this issue by submitting a bug report at *
+* crbug.com/tint with the source program that triggered the bug. *
+********************************************************************
+
+tint executable returned error: signal: trace/BPT trap
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.msl b/test/tint/binding_array/as_function_parameter.wgsl.expected.msl
new file mode 100644
index 0000000..c69e498
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.msl
@@ -0,0 +1,17 @@
+#include <metal_stdlib>
+using namespace metal;
+
+struct tint_module_vars_struct {
+ array<texture2d<float, access::sample>, 4> sampled_textures;
+};
+
+void do_texture_load(array<texture2d<float, access::sample>, 4> ts) {
+ uint const v = min(uint(0), (ts[0].get_num_mip_levels() - 1u));
+ uint2 const v_1 = (uint2(ts[0].get_width(v), ts[0].get_height(v)) - uint2(1u));
+ float4 const texture_load = ts[0].read(min(uint2(int2(0)), v_1), v);
+}
+
+fragment void fs(array<texture2d<float, access::sample>, 4> sampled_textures [[texture(0)]]) {
+ tint_module_vars_struct const tint_module_vars = tint_module_vars_struct{.sampled_textures=sampled_textures};
+ do_texture_load(tint_module_vars.sampled_textures);
+}
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.spvasm b/test/tint/binding_array/as_function_parameter.wgsl.expected.spvasm
new file mode 100644
index 0000000..bc9d02d
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.spvasm
@@ -0,0 +1,53 @@
+SKIP: FAILED
+
+
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ do_texture_load(sampled_textures);
+}
+
+fn do_texture_load(ts : binding_array<texture_2d<f32>, 4>) {
+ let texture_load = textureLoad(ts[0], vec2(0, 0), 0);
+}
+
+Failed to generate SPIR-V: :7:115 error: access: result of access chain is type 'texture_2d<f32>' but instruction type is 'spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write>'
+ %4:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write> = access %ts, 0i
+ ^^^^^^
+
+:6:3 note: in block
+ $B2: {
+ ^^^
+
+note: # Disassembly
+$B1: { # root
+ %sampled_textures:ptr<handle, binding_array<texture_2d<f32>, 4>, read> = var undef @binding_point(0, 0)
+}
+
+%do_texture_load = func(%ts:binding_array<texture_2d<f32>, 4>):void {
+ $B2: {
+ %4:spirv.image<f32, 2d, not_depth, non_arrayed, single_sampled, sampling_compatible, undefined, read_write> = access %ts, 0i
+ %5:u32 = spirv.image_query_levels<u32> %4
+ %6:u32 = sub %5, 1u
+ %7:u32 = convert 0i
+ %8:u32 = min %7, %6
+ %9:vec2<u32> = spirv.image_query_size_lod %4, %8
+ %10:vec2<u32> = sub %9, vec2<u32>(1u)
+ %11:vec2<u32> = convert vec2<i32>(0i)
+ %12:vec2<u32> = min %11, %10
+ %13:vec4<f32> = spirv.image_fetch %4, %12, 2u, %8
+ %texture_load:vec4<f32> = let %13
+ ret
+ }
+}
+%fs = @fragment func():void {
+ $B3: {
+ %16:binding_array<texture_2d<f32>, 4> = load %sampled_textures
+ %17:void = call %do_texture_load, %16
+ ret
+ }
+}
+
+
+tint executable returned error: exit status 1
diff --git a/test/tint/binding_array/as_function_parameter.wgsl.expected.wgsl b/test/tint/binding_array/as_function_parameter.wgsl.expected.wgsl
new file mode 100644
index 0000000..33398ec0
--- /dev/null
+++ b/test/tint/binding_array/as_function_parameter.wgsl.expected.wgsl
@@ -0,0 +1,10 @@
+@group(0) @binding(0) var sampled_textures : binding_array<texture_2d<f32>, 4>;
+
+@fragment
+fn fs() {
+ do_texture_load(sampled_textures);
+}
+
+fn do_texture_load(ts : binding_array<texture_2d<f32>, 4>) {
+ let texture_load = textureLoad(ts[0], vec2(0, 0), 0);
+}