mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
tint/writer/msl: Generate an array<T,N> helper
And remove the WrapArraysInStructs transform. Wrapping arrays in structures becomes troublesome for `const` arrays, as currently WGSL does not allow `const` structures. MSL 2.0+ has a builtin array<> helper, but we're targetting MSL 1.2, so we have to emit our own. Fortunately, it can be done with a few lines of templated code. This produces significantly cleaner output. Change-Id: Ifc92ef21e09befa252a07c856c4b5afdc51cc2e4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94540 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
3c054304a8
commit
f47887d207
@@ -0,0 +1,5 @@
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var zero : array<array<i32, 3>, 2>;
|
||||
var init : array<array<i32, 3>, 2> = array<array<i32, 3>, 2>(array<i32, 3>(1, 2, 3), array<i32, 3>(4, 5, 6));
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#version 310 es
|
||||
|
||||
void tint_symbol() {
|
||||
int zero[2][3] = int[2][3](int[3](0, 0, 0), int[3](0, 0, 0));
|
||||
int tint_symbol_1[3] = int[3](1, 2, 3);
|
||||
int tint_symbol_2[3] = int[3](4, 5, 6);
|
||||
int init[2][3] = int[2][3](tint_symbol_1, tint_symbol_2);
|
||||
}
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
void main() {
|
||||
tint_symbol();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
[numthreads(1, 1, 1)]
|
||||
void main() {
|
||||
int zero[2][3] = (int[2][3])0;
|
||||
const int tint_symbol[3] = {1, 2, 3};
|
||||
const int tint_symbol_1[3] = {4, 5, 6};
|
||||
int init[2][3] = {tint_symbol, tint_symbol_1};
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, size_t N>
|
||||
struct tint_array {
|
||||
const constant T& operator[](size_t i) const constant { return elements[i]; }
|
||||
device T& operator[](size_t i) device { return elements[i]; }
|
||||
const device T& operator[](size_t i) const device { return elements[i]; }
|
||||
thread T& operator[](size_t i) thread { return elements[i]; }
|
||||
const thread T& operator[](size_t i) const thread { return elements[i]; }
|
||||
threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
|
||||
const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
kernel void tint_symbol() {
|
||||
tint_array<tint_array<int, 3>, 2> zero = {};
|
||||
tint_array<int, 3> const tint_symbol_1 = tint_array<int, 3>{1, 2, 3};
|
||||
tint_array<int, 3> const tint_symbol_2 = tint_array<int, 3>{4, 5, 6};
|
||||
tint_array<tint_array<int, 3>, 2> init = tint_array<tint_array<int, 3>, 2>{tint_symbol_1, tint_symbol_2};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 24
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %main "main"
|
||||
OpName %zero "zero"
|
||||
OpName %init "init"
|
||||
OpDecorate %_arr_int_uint_3 ArrayStride 4
|
||||
OpDecorate %_arr__arr_int_uint_3_uint_2 ArrayStride 12
|
||||
%void = OpTypeVoid
|
||||
%1 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%_arr_int_uint_3 = OpTypeArray %int %uint_3
|
||||
%uint_2 = OpConstant %uint 2
|
||||
%_arr__arr_int_uint_3_uint_2 = OpTypeArray %_arr_int_uint_3 %uint_2
|
||||
%_ptr_Function__arr__arr_int_uint_3_uint_2 = OpTypePointer Function %_arr__arr_int_uint_3_uint_2
|
||||
%13 = OpConstantNull %_arr__arr_int_uint_3_uint_2
|
||||
%int_1 = OpConstant %int 1
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_3 = OpConstant %int 3
|
||||
%17 = OpConstantComposite %_arr_int_uint_3 %int_1 %int_2 %int_3
|
||||
%int_4 = OpConstant %int 4
|
||||
%int_5 = OpConstant %int 5
|
||||
%int_6 = OpConstant %int 6
|
||||
%21 = OpConstantComposite %_arr_int_uint_3 %int_4 %int_5 %int_6
|
||||
%22 = OpConstantComposite %_arr__arr_int_uint_3_uint_2 %17 %21
|
||||
%main = OpFunction %void None %1
|
||||
%4 = OpLabel
|
||||
%zero = OpVariable %_ptr_Function__arr__arr_int_uint_3_uint_2 Function %13
|
||||
%init = OpVariable %_ptr_Function__arr__arr_int_uint_3_uint_2 Function %13
|
||||
OpStore %init %22
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,5 @@
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var zero : array<array<i32, 3>, 2>;
|
||||
var init : array<array<i32, 3>, 2> = array<array<i32, 3>, 2>(array<i32, 3>(1, 2, 3), array<i32, 3>(4, 5, 6));
|
||||
}
|
||||
5
test/tint/var/initialization/function/array/i32.wgsl
Normal file
5
test/tint/var/initialization/function/array/i32.wgsl
Normal file
@@ -0,0 +1,5 @@
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var zero : array<i32, 3>;
|
||||
var init : array<i32, 3> = array<i32, 3>(1, 2, 3);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#version 310 es
|
||||
|
||||
void tint_symbol() {
|
||||
int zero[3] = int[3](0, 0, 0);
|
||||
int init[3] = int[3](1, 2, 3);
|
||||
}
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
void main() {
|
||||
tint_symbol();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
[numthreads(1, 1, 1)]
|
||||
void main() {
|
||||
int zero[3] = (int[3])0;
|
||||
int init[3] = {1, 2, 3};
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
|
||||
template<typename T, size_t N>
|
||||
struct tint_array {
|
||||
const constant T& operator[](size_t i) const constant { return elements[i]; }
|
||||
device T& operator[](size_t i) device { return elements[i]; }
|
||||
const device T& operator[](size_t i) const device { return elements[i]; }
|
||||
thread T& operator[](size_t i) thread { return elements[i]; }
|
||||
const thread T& operator[](size_t i) const thread { return elements[i]; }
|
||||
threadgroup T& operator[](size_t i) threadgroup { return elements[i]; }
|
||||
const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; }
|
||||
T elements[N];
|
||||
};
|
||||
|
||||
kernel void tint_symbol() {
|
||||
tint_array<int, 3> zero = {};
|
||||
tint_array<int, 3> init = tint_array<int, 3>{1, 2, 3};
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 17
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %main "main"
|
||||
OpName %zero "zero"
|
||||
OpName %init "init"
|
||||
OpDecorate %_arr_int_uint_3 ArrayStride 4
|
||||
%void = OpTypeVoid
|
||||
%1 = OpTypeFunction %void
|
||||
%int = OpTypeInt 32 1
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%_arr_int_uint_3 = OpTypeArray %int %uint_3
|
||||
%_ptr_Function__arr_int_uint_3 = OpTypePointer Function %_arr_int_uint_3
|
||||
%11 = OpConstantNull %_arr_int_uint_3
|
||||
%int_1 = OpConstant %int 1
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_3 = OpConstant %int 3
|
||||
%15 = OpConstantComposite %_arr_int_uint_3 %int_1 %int_2 %int_3
|
||||
%main = OpFunction %void None %1
|
||||
%4 = OpLabel
|
||||
%zero = OpVariable %_ptr_Function__arr_int_uint_3 Function %11
|
||||
%init = OpVariable %_ptr_Function__arr_int_uint_3 Function %11
|
||||
OpStore %init %15
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,5 @@
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var zero : array<i32, 3>;
|
||||
var init : array<i32, 3> = array<i32, 3>(1, 2, 3);
|
||||
}
|
||||
Reference in New Issue
Block a user