writer/msl: Handle private and workgroup variables

Add a transform that pushes these into the entry point and then passes
them by pointer to any functions that need them.

Since WGSL does not allow non-function storage class at
function-scope, add a DisableValidation attribute to bypass this
check.

Fixed: tint/726
Change-Id: Ic1f4cd691a54c19e77a60e8ba178508e4249bfd9
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/51962
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
James Price
2021-05-26 15:41:02 +00:00
committed by Tint LUCI CQ
parent 61e573663d
commit 7a47fa8495
45 changed files with 1491 additions and 99 deletions

View File

@@ -1 +0,0 @@
SKIP: TINT_UNIMPLEMENTED crbug.com/tint/726: module-scope private and workgroup variables not yet implemented

View File

@@ -0,0 +1,17 @@
struct S {
};
let bool_let : bool = bool();
let i32_let : i32 = i32();
let u32_let : u32 = u32();
let f32_let : f32 = f32();
let v2i32_let : vec2<i32> = vec2<i32>();
let v3u32_let : vec3<u32> = vec3<u32>();
let v4f32_let : vec4<f32> = vec4<f32>();
let m3x4_let : mat3x4<f32> = mat3x4<f32>();
let arr_let : array<f32, 4> = array<f32, 4>();
let struct_let : S = S();
[[stage(compute)]]
fn main() {
}

View File

@@ -0,0 +1,20 @@
#include <metal_stdlib>
using namespace metal;
struct S {
};
constant bool bool_let = bool();
constant int i32_let = int();
constant uint u32_let = uint();
constant float f32_let = float();
constant int2 v2i32_let = int2();
constant uint3 v3u32_let = uint3();
constant float4 v4f32_let = float4();
constant float3x4 m3x4_let = float3x4();
constant float arr_let[4] = {};
constant S struct_let = {};
kernel void tint_symbol() {
return;
}

View File

@@ -0,0 +1,49 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 26
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %bool_let "bool_let"
OpName %i32_let "i32_let"
OpName %u32_let "u32_let"
OpName %f32_let "f32_let"
OpName %v2i32_let "v2i32_let"
OpName %v3u32_let "v3u32_let"
OpName %v4f32_let "v4f32_let"
OpName %m3x4_let "m3x4_let"
OpName %arr_let "arr_let"
OpName %S "S"
OpName %struct_let "struct_let"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
%bool = OpTypeBool
%bool_let = OpConstantNull %bool
%int = OpTypeInt 32 1
%i32_let = OpConstantNull %int
%uint = OpTypeInt 32 0
%u32_let = OpConstantNull %uint
%float = OpTypeFloat 32
%f32_let = OpConstantNull %float
%v2int = OpTypeVector %int 2
%v2i32_let = OpConstantNull %v2int
%v3uint = OpTypeVector %uint 3
%v3u32_let = OpConstantNull %v3uint
%v4float = OpTypeVector %float 4
%v4f32_let = OpConstantNull %v4float
%mat3v4float = OpTypeMatrix %v4float 3
%m3x4_let = OpConstantNull %mat3v4float
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%arr_let = OpConstantNull %_arr_float_uint_4
%S = OpTypeStruct
%struct_let = OpConstantNull %S
%void = OpTypeVoid
%22 = OpTypeFunction %void
%main = OpFunction %void None %22
%25 = OpLabel
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,26 @@
struct S {
};
let bool_let : bool = bool();
let i32_let : i32 = i32();
let u32_let : u32 = u32();
let f32_let : f32 = f32();
let v2i32_let : vec2<i32> = vec2<i32>();
let v3u32_let : vec3<u32> = vec3<u32>();
let v4f32_let : vec4<f32> = vec4<f32>();
let m3x4_let : mat3x4<f32> = mat3x4<f32>();
let arr_let : array<f32, 4> = array<f32, 4>();
let struct_let : S = S();
[[stage(compute)]]
fn main() {
}

View File

@@ -0,0 +1,28 @@
struct S {
};
var<private> bool_var : bool;
var<private> i32_var : i32;
var<private> u32_var : u32;
var<private> f32_var : f32;
var<private> v2i32_var : vec2<i32>;
var<private> v3u32_var : vec3<u32>;
var<private> v4f32_var : vec4<f32>;
var<private> m2x3_var : mat2x3<f32>;
var<private> arr_var : array<f32, 4>;
var<private> struct_var : S;
[[stage(compute)]]
fn main() {
// Reference the module-scope variables to stop them from being removed.
bool_var = bool();
i32_var = i32();
u32_var = u32();
f32_var = f32();
v2i32_var = vec2<i32>();
v3u32_var = vec3<u32>();
v4f32_var = vec4<f32>();
m2x3_var = mat2x3<f32>();
arr_var = array<f32, 4>();
struct_var = S();
}

View File

@@ -0,0 +1,31 @@
struct S {
};
static bool bool_var;
static int i32_var;
static uint u32_var;
static float f32_var;
static int2 v2i32_var;
static uint3 v3u32_var;
static float4 v4f32_var;
static float2x3 m2x3_var;
static float arr_var[4];
static S struct_var;
[numthreads(1, 1, 1)]
void main() {
bool_var = false;
i32_var = 0;
u32_var = 0u;
f32_var = 0.0f;
v2i32_var = int2(0, 0);
v3u32_var = uint3(0u, 0u, 0u);
v4f32_var = float4(0.0f, 0.0f, 0.0f, 0.0f);
m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
const float tint_symbol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
arr_var = tint_symbol;
const S tint_symbol_1 = {};
struct_var = tint_symbol_1;
return;
}

View File

@@ -0,0 +1 @@
SKIP: crbug.com/tint/814

View File

@@ -0,0 +1,80 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 47
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %bool_var "bool_var"
OpName %i32_var "i32_var"
OpName %u32_var "u32_var"
OpName %f32_var "f32_var"
OpName %v2i32_var "v2i32_var"
OpName %v3u32_var "v3u32_var"
OpName %v4f32_var "v4f32_var"
OpName %m2x3_var "m2x3_var"
OpName %arr_var "arr_var"
OpName %S "S"
OpName %struct_var "struct_var"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
%bool = OpTypeBool
%_ptr_Private_bool = OpTypePointer Private %bool
%4 = OpConstantNull %bool
%bool_var = OpVariable %_ptr_Private_bool Private %4
%int = OpTypeInt 32 1
%_ptr_Private_int = OpTypePointer Private %int
%8 = OpConstantNull %int
%i32_var = OpVariable %_ptr_Private_int Private %8
%uint = OpTypeInt 32 0
%_ptr_Private_uint = OpTypePointer Private %uint
%12 = OpConstantNull %uint
%u32_var = OpVariable %_ptr_Private_uint Private %12
%float = OpTypeFloat 32
%_ptr_Private_float = OpTypePointer Private %float
%16 = OpConstantNull %float
%f32_var = OpVariable %_ptr_Private_float Private %16
%v2int = OpTypeVector %int 2
%_ptr_Private_v2int = OpTypePointer Private %v2int
%20 = OpConstantNull %v2int
%v2i32_var = OpVariable %_ptr_Private_v2int Private %20
%v3uint = OpTypeVector %uint 3
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%24 = OpConstantNull %v3uint
%v3u32_var = OpVariable %_ptr_Private_v3uint Private %24
%v4float = OpTypeVector %float 4
%_ptr_Private_v4float = OpTypePointer Private %v4float
%28 = OpConstantNull %v4float
%v4f32_var = OpVariable %_ptr_Private_v4float Private %28
%v3float = OpTypeVector %float 3
%mat2v3float = OpTypeMatrix %v3float 2
%_ptr_Private_mat2v3float = OpTypePointer Private %mat2v3float
%33 = OpConstantNull %mat2v3float
%m2x3_var = OpVariable %_ptr_Private_mat2v3float Private %33
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%_ptr_Private__arr_float_uint_4 = OpTypePointer Private %_arr_float_uint_4
%38 = OpConstantNull %_arr_float_uint_4
%arr_var = OpVariable %_ptr_Private__arr_float_uint_4 Private %38
%S = OpTypeStruct
%_ptr_Private_S = OpTypePointer Private %S
%42 = OpConstantNull %S
%struct_var = OpVariable %_ptr_Private_S Private %42
%void = OpTypeVoid
%43 = OpTypeFunction %void
%main = OpFunction %void None %43
%46 = OpLabel
OpStore %bool_var %4
OpStore %i32_var %8
OpStore %u32_var %12
OpStore %f32_var %16
OpStore %v2i32_var %20
OpStore %v3u32_var %24
OpStore %v4f32_var %28
OpStore %m2x3_var %33
OpStore %arr_var %38
OpStore %struct_var %42
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,36 @@
struct S {
};
var<private> bool_var : bool;
var<private> i32_var : i32;
var<private> u32_var : u32;
var<private> f32_var : f32;
var<private> v2i32_var : vec2<i32>;
var<private> v3u32_var : vec3<u32>;
var<private> v4f32_var : vec4<f32>;
var<private> m2x3_var : mat2x3<f32>;
var<private> arr_var : array<f32, 4>;
var<private> struct_var : S;
[[stage(compute)]]
fn main() {
bool_var = bool();
i32_var = i32();
u32_var = u32();
f32_var = f32();
v2i32_var = vec2<i32>();
v3u32_var = vec3<u32>();
v4f32_var = vec4<f32>();
m2x3_var = mat2x3<f32>();
arr_var = array<f32, 4>();
struct_var = S();
}

View File

@@ -2,26 +2,27 @@ struct S {
};
var<private> bool_var : bool = bool();
let bool_let : bool = bool();
var<private> i32_var : i32 = i32();
let i32_let : i32 = i32();
var<private> u32_var : u32 = u32();
let u32_let : u32 = u32();
var<private> f32_var : f32 = f32();
let f32_let : f32 = f32();
var<private> v2i32_var : vec2<i32> = vec2<i32>();
let v2i32_let : vec2<i32> = vec2<i32>();
var<private> v3u32_var : vec3<u32> = vec3<u32>();
let v3u32_let : vec3<u32> = vec3<u32>();
var<private> v4f32_var : vec4<f32> = vec4<f32>();
let v4f32_let : vec4<f32> = vec4<f32>();
var<private> m2x3_var : mat2x3<f32> = mat2x3<f32>();
let m3x4_let : mat3x4<f32> = mat3x4<f32>();
var<private> arr_var : array<f32, 4> = array<f32, 4>();
let arr_let : array<f32, 4> = array<f32, 4>();
var<private> struct_var : S = S();
let struct_let : S = S();
[[stage(compute)]]
fn main() {
// Reference the module-scope variables to stop them from being removed.
bool_var = bool();
i32_var = i32();
u32_var = u32();
f32_var = f32();
v2i32_var = vec2<i32>();
v3u32_var = vec3<u32>();
v4f32_var = vec4<f32>();
m2x3_var = mat2x3<f32>();
arr_var = array<f32, 4>();
struct_var = S();
}

View File

@@ -0,0 +1,31 @@
struct S {
};
static bool bool_var = false;
static int i32_var = 0;
static uint u32_var = 0u;
static float f32_var = 0.0f;
static int2 v2i32_var = int2(0, 0);
static uint3 v3u32_var = uint3(0u, 0u, 0u);
static float4 v4f32_var = float4(0.0f, 0.0f, 0.0f, 0.0f);
static float2x3 m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
static float arr_var[4] = {0.0f, 0.0f, 0.0f, 0.0f};
static S struct_var = {};
[numthreads(1, 1, 1)]
void main() {
bool_var = false;
i32_var = 0;
u32_var = 0u;
f32_var = 0.0f;
v2i32_var = int2(0, 0);
v3u32_var = uint3(0u, 0u, 0u);
v4f32_var = float4(0.0f, 0.0f, 0.0f, 0.0f);
m2x3_var = float2x3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
const float tint_symbol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
arr_var = tint_symbol;
const S tint_symbol_1 = {};
struct_var = tint_symbol_1;
return;
}

View File

@@ -0,0 +1 @@
SKIP: crbug.com/tint/814

View File

@@ -1,82 +1,80 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 49
; Bound: 47
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %bool_var "bool_var"
OpName %bool_let "bool_let"
OpName %i32_var "i32_var"
OpName %i32_let "i32_let"
OpName %u32_var "u32_var"
OpName %u32_let "u32_let"
OpName %f32_var "f32_var"
OpName %f32_let "f32_let"
OpName %v2i32_var "v2i32_var"
OpName %v2i32_let "v2i32_let"
OpName %v3u32_var "v3u32_var"
OpName %v3u32_let "v3u32_let"
OpName %v4f32_var "v4f32_var"
OpName %v4f32_let "v4f32_let"
OpName %m2x3_var "m2x3_var"
OpName %m3x4_let "m3x4_let"
OpName %arr_var "arr_var"
OpName %arr_let "arr_let"
OpName %S "S"
OpName %struct_var "struct_var"
OpName %struct_let "struct_let"
OpName %main "main"
OpDecorate %_arr_float_uint_4 ArrayStride 4
%bool = OpTypeBool
%bool_let = OpConstantNull %bool
%2 = OpConstantNull %bool
%_ptr_Private_bool = OpTypePointer Private %bool
%bool_var = OpVariable %_ptr_Private_bool Private %bool_let
%bool_var = OpVariable %_ptr_Private_bool Private %2
%int = OpTypeInt 32 1
%i32_let = OpConstantNull %int
%6 = OpConstantNull %int
%_ptr_Private_int = OpTypePointer Private %int
%i32_var = OpVariable %_ptr_Private_int Private %i32_let
%i32_var = OpVariable %_ptr_Private_int Private %6
%uint = OpTypeInt 32 0
%u32_let = OpConstantNull %uint
%10 = OpConstantNull %uint
%_ptr_Private_uint = OpTypePointer Private %uint
%u32_var = OpVariable %_ptr_Private_uint Private %u32_let
%u32_var = OpVariable %_ptr_Private_uint Private %10
%float = OpTypeFloat 32
%f32_let = OpConstantNull %float
%14 = OpConstantNull %float
%_ptr_Private_float = OpTypePointer Private %float
%f32_var = OpVariable %_ptr_Private_float Private %f32_let
%f32_var = OpVariable %_ptr_Private_float Private %14
%v2int = OpTypeVector %int 2
%v2i32_let = OpConstantNull %v2int
%18 = OpConstantNull %v2int
%_ptr_Private_v2int = OpTypePointer Private %v2int
%v2i32_var = OpVariable %_ptr_Private_v2int Private %v2i32_let
%v2i32_var = OpVariable %_ptr_Private_v2int Private %18
%v3uint = OpTypeVector %uint 3
%v3u32_let = OpConstantNull %v3uint
%22 = OpConstantNull %v3uint
%_ptr_Private_v3uint = OpTypePointer Private %v3uint
%v3u32_var = OpVariable %_ptr_Private_v3uint Private %v3u32_let
%v3u32_var = OpVariable %_ptr_Private_v3uint Private %22
%v4float = OpTypeVector %float 4
%v4f32_let = OpConstantNull %v4float
%26 = OpConstantNull %v4float
%_ptr_Private_v4float = OpTypePointer Private %v4float
%v4f32_var = OpVariable %_ptr_Private_v4float Private %v4f32_let
%v4f32_var = OpVariable %_ptr_Private_v4float Private %26
%v3float = OpTypeVector %float 3
%mat2v3float = OpTypeMatrix %v3float 2
%31 = OpConstantNull %mat2v3float
%_ptr_Private_mat2v3float = OpTypePointer Private %mat2v3float
%m2x3_var = OpVariable %_ptr_Private_mat2v3float Private %31
%mat3v4float = OpTypeMatrix %v4float 3
%m3x4_let = OpConstantNull %mat3v4float
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%arr_let = OpConstantNull %_arr_float_uint_4
%36 = OpConstantNull %_arr_float_uint_4
%_ptr_Private__arr_float_uint_4 = OpTypePointer Private %_arr_float_uint_4
%arr_var = OpVariable %_ptr_Private__arr_float_uint_4 Private %arr_let
%arr_var = OpVariable %_ptr_Private__arr_float_uint_4 Private %36
%S = OpTypeStruct
%struct_let = OpConstantNull %S
%40 = OpConstantNull %S
%_ptr_Private_S = OpTypePointer Private %S
%struct_var = OpVariable %_ptr_Private_S Private %struct_let
%struct_var = OpVariable %_ptr_Private_S Private %40
%void = OpTypeVoid
%45 = OpTypeFunction %void
%main = OpFunction %void None %45
%48 = OpLabel
%43 = OpTypeFunction %void
%main = OpFunction %void None %43
%46 = OpLabel
OpStore %bool_var %2
OpStore %i32_var %6
OpStore %u32_var %10
OpStore %f32_var %14
OpStore %v2i32_var %18
OpStore %v3u32_var %22
OpStore %v4f32_var %26
OpStore %m2x3_var %31
OpStore %arr_var %36
OpStore %struct_var %40
OpReturn
OpFunctionEnd

View File

@@ -3,44 +3,34 @@ struct S {
var<private> bool_var : bool = bool();
let bool_let : bool = bool();
var<private> i32_var : i32 = i32();
let i32_let : i32 = i32();
var<private> u32_var : u32 = u32();
let u32_let : u32 = u32();
var<private> f32_var : f32 = f32();
let f32_let : f32 = f32();
var<private> v2i32_var : vec2<i32> = vec2<i32>();
let v2i32_let : vec2<i32> = vec2<i32>();
var<private> v3u32_var : vec3<u32> = vec3<u32>();
let v3u32_let : vec3<u32> = vec3<u32>();
var<private> v4f32_var : vec4<f32> = vec4<f32>();
let v4f32_let : vec4<f32> = vec4<f32>();
var<private> m2x3_var : mat2x3<f32> = mat2x3<f32>();
let m3x4_let : mat3x4<f32> = mat3x4<f32>();
var<private> arr_var : array<f32, 4> = array<f32, 4>();
let arr_let : array<f32, 4> = array<f32, 4>();
var<private> struct_var : S = S();
let struct_let : S = S();
[[stage(compute)]]
fn main() {
bool_var = bool();
i32_var = i32();
u32_var = u32();
f32_var = f32();
v2i32_var = vec2<i32>();
v3u32_var = vec3<u32>();
v4f32_var = vec4<f32>();
m2x3_var = mat2x3<f32>();
arr_var = array<f32, 4>();
struct_var = S();
}