mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 14:08:04 +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,8 @@
|
||||
var<private> zero : array<array<i32, 3>, 2>;
|
||||
var<private> init : array<array<i32, 3>, 2> = array<array<i32, 3>, 2>(array<i32, 3>(1, 2, 3), array<i32, 3>(4, 5, 6));
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var v0 = zero;
|
||||
var v1 = init;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#version 310 es
|
||||
|
||||
int zero[2][3] = int[2][3](int[3](0, 0, 0), int[3](0, 0, 0));
|
||||
int init[2][3] = int[2][3](int[3](1, 2, 3), int[3](4, 5, 6));
|
||||
void tint_symbol() {
|
||||
int v0[2][3] = zero;
|
||||
int v1[2][3] = init;
|
||||
}
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
void main() {
|
||||
tint_symbol();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
static int zero[2][3] = (int[2][3])0;
|
||||
static int init[2][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main() {
|
||||
int v0[2][3] = zero;
|
||||
int v1[2][3] = init;
|
||||
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() {
|
||||
thread tint_array<tint_array<int, 3>, 2> tint_symbol_1 = {};
|
||||
thread tint_array<tint_array<int, 3>, 2> tint_symbol_2 = tint_array<tint_array<int, 3>, 2>{tint_array<int, 3>{1, 2, 3}, tint_array<int, 3>{4, 5, 6}};
|
||||
tint_array<tint_array<int, 3>, 2> v0 = tint_symbol_1;
|
||||
tint_array<tint_array<int, 3>, 2> v1 = tint_symbol_2;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 29
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %zero "zero"
|
||||
OpName %init "init"
|
||||
OpName %main "main"
|
||||
OpName %v0 "v0"
|
||||
OpName %v1 "v1"
|
||||
OpDecorate %_arr_int_uint_3 ArrayStride 4
|
||||
OpDecorate %_arr__arr_int_uint_3_uint_2 ArrayStride 12
|
||||
%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_Private__arr__arr_int_uint_3_uint_2 = OpTypePointer Private %_arr__arr_int_uint_3_uint_2
|
||||
%9 = OpConstantNull %_arr__arr_int_uint_3_uint_2
|
||||
%zero = OpVariable %_ptr_Private__arr__arr_int_uint_3_uint_2 Private %9
|
||||
%int_1 = OpConstant %int 1
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_3 = OpConstant %int 3
|
||||
%13 = 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
|
||||
%17 = OpConstantComposite %_arr_int_uint_3 %int_4 %int_5 %int_6
|
||||
%18 = OpConstantComposite %_arr__arr_int_uint_3_uint_2 %13 %17
|
||||
%init = OpVariable %_ptr_Private__arr__arr_int_uint_3_uint_2 Private %18
|
||||
%void = OpTypeVoid
|
||||
%20 = OpTypeFunction %void
|
||||
%_ptr_Function__arr__arr_int_uint_3_uint_2 = OpTypePointer Function %_arr__arr_int_uint_3_uint_2
|
||||
%main = OpFunction %void None %20
|
||||
%23 = OpLabel
|
||||
%v0 = OpVariable %_ptr_Function__arr__arr_int_uint_3_uint_2 Function %9
|
||||
%v1 = OpVariable %_ptr_Function__arr__arr_int_uint_3_uint_2 Function %9
|
||||
%24 = OpLoad %_arr__arr_int_uint_3_uint_2 %zero
|
||||
OpStore %v0 %24
|
||||
%27 = OpLoad %_arr__arr_int_uint_3_uint_2 %init
|
||||
OpStore %v1 %27
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,9 @@
|
||||
var<private> zero : array<array<i32, 3>, 2>;
|
||||
|
||||
var<private> init : array<array<i32, 3>, 2> = array<array<i32, 3>, 2>(array<i32, 3>(1, 2, 3), array<i32, 3>(4, 5, 6));
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var v0 = zero;
|
||||
var v1 = init;
|
||||
}
|
||||
8
test/tint/var/initialization/private/array/i32.wgsl
Normal file
8
test/tint/var/initialization/private/array/i32.wgsl
Normal file
@@ -0,0 +1,8 @@
|
||||
var<private> zero : array<i32, 3>;
|
||||
var<private> init : array<i32, 3> = array<i32, 3>(1, 2, 3);
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var v0 = zero;
|
||||
var v1 = init;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#version 310 es
|
||||
|
||||
int zero[3] = int[3](0, 0, 0);
|
||||
int init[3] = int[3](1, 2, 3);
|
||||
void tint_symbol() {
|
||||
int v0[3] = zero;
|
||||
int v1[3] = init;
|
||||
}
|
||||
|
||||
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
|
||||
void main() {
|
||||
tint_symbol();
|
||||
return;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
static int zero[3] = (int[3])0;
|
||||
static int init[3] = {1, 2, 3};
|
||||
|
||||
[numthreads(1, 1, 1)]
|
||||
void main() {
|
||||
int v0[3] = zero;
|
||||
int v1[3] = init;
|
||||
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() {
|
||||
thread tint_array<int, 3> tint_symbol_1 = {};
|
||||
thread tint_array<int, 3> tint_symbol_2 = tint_array<int, 3>{1, 2, 3};
|
||||
tint_array<int, 3> v0 = tint_symbol_1;
|
||||
tint_array<int, 3> v1 = tint_symbol_2;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 22
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint GLCompute %main "main"
|
||||
OpExecutionMode %main LocalSize 1 1 1
|
||||
OpName %zero "zero"
|
||||
OpName %init "init"
|
||||
OpName %main "main"
|
||||
OpName %v0 "v0"
|
||||
OpName %v1 "v1"
|
||||
OpDecorate %_arr_int_uint_3 ArrayStride 4
|
||||
%int = OpTypeInt 32 1
|
||||
%uint = OpTypeInt 32 0
|
||||
%uint_3 = OpConstant %uint 3
|
||||
%_arr_int_uint_3 = OpTypeArray %int %uint_3
|
||||
%_ptr_Private__arr_int_uint_3 = OpTypePointer Private %_arr_int_uint_3
|
||||
%7 = OpConstantNull %_arr_int_uint_3
|
||||
%zero = OpVariable %_ptr_Private__arr_int_uint_3 Private %7
|
||||
%int_1 = OpConstant %int 1
|
||||
%int_2 = OpConstant %int 2
|
||||
%int_3 = OpConstant %int 3
|
||||
%11 = OpConstantComposite %_arr_int_uint_3 %int_1 %int_2 %int_3
|
||||
%init = OpVariable %_ptr_Private__arr_int_uint_3 Private %11
|
||||
%void = OpTypeVoid
|
||||
%13 = OpTypeFunction %void
|
||||
%_ptr_Function__arr_int_uint_3 = OpTypePointer Function %_arr_int_uint_3
|
||||
%main = OpFunction %void None %13
|
||||
%16 = OpLabel
|
||||
%v0 = OpVariable %_ptr_Function__arr_int_uint_3 Function %7
|
||||
%v1 = OpVariable %_ptr_Function__arr_int_uint_3 Function %7
|
||||
%17 = OpLoad %_arr_int_uint_3 %zero
|
||||
OpStore %v0 %17
|
||||
%20 = OpLoad %_arr_int_uint_3 %init
|
||||
OpStore %v1 %20
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
@@ -0,0 +1,9 @@
|
||||
var<private> zero : array<i32, 3>;
|
||||
|
||||
var<private> init : array<i32, 3> = array<i32, 3>(1, 2, 3);
|
||||
|
||||
@compute @workgroup_size(1)
|
||||
fn main() {
|
||||
var v0 = zero;
|
||||
var v1 = init;
|
||||
}
|
||||
Reference in New Issue
Block a user