mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-10 05:57:51 +00:00
Allow array size to be a module-scope constant
Change ast::Array to use an ast::Expression for its `size` field. The WGSL frontend now parses the array size as an `primary_expression`, and the Resolver is responsible for validating the expression is a signed or unsigned integer, and either a literal or a non-overridable module-scope constant. The Resolver evaluates the constant value of the size expression, and so the resolved sem::Array type still has a constant size as before. Fixed: tint:1068 Fixed: tint:1117 Change-Id: Icfa141482ea1e47ea8c21a25e9eb48221f176e9a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/63061 Auto-Submit: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
69ce5f74ed
commit
4cc4315d6c
14
test/array/size.wgsl
Normal file
14
test/array/size.wgsl
Normal file
@@ -0,0 +1,14 @@
|
||||
let slen = 4;
|
||||
let ulen = 4u;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
var signed_literal : array<f32, 4>;
|
||||
var unsigned_literal : array<f32, 4u>;
|
||||
var signed_constant : array<f32, slen>;
|
||||
var unsigned_constant : array<f32, ulen>;
|
||||
|
||||
// Ensure that the types are compatible.
|
||||
signed_literal = unsigned_constant;
|
||||
signed_constant = unsigned_literal;
|
||||
}
|
||||
12
test/array/size.wgsl.expected.hlsl
Normal file
12
test/array/size.wgsl.expected.hlsl
Normal file
@@ -0,0 +1,12 @@
|
||||
static const int slen = 4;
|
||||
static const uint ulen = 4u;
|
||||
|
||||
void main() {
|
||||
float signed_literal[4] = (float[4])0;
|
||||
float unsigned_literal[4] = (float[4])0;
|
||||
float signed_constant[4] = (float[4])0;
|
||||
float unsigned_constant[4] = (float[4])0;
|
||||
signed_literal = unsigned_constant;
|
||||
signed_constant = unsigned_literal;
|
||||
return;
|
||||
}
|
||||
19
test/array/size.wgsl.expected.msl
Normal file
19
test/array/size.wgsl.expected.msl
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <metal_stdlib>
|
||||
|
||||
using namespace metal;
|
||||
struct tint_array_wrapper {
|
||||
float arr[4];
|
||||
};
|
||||
|
||||
constant int slen = 4;
|
||||
constant uint ulen = 4u;
|
||||
fragment void tint_symbol() {
|
||||
tint_array_wrapper signed_literal = {};
|
||||
tint_array_wrapper unsigned_literal = {};
|
||||
tint_array_wrapper signed_constant = {};
|
||||
tint_array_wrapper unsigned_constant = {};
|
||||
signed_literal = unsigned_constant;
|
||||
signed_constant = unsigned_literal;
|
||||
return;
|
||||
}
|
||||
|
||||
39
test/array/size.wgsl.expected.spvasm
Normal file
39
test/array/size.wgsl.expected.spvasm
Normal file
@@ -0,0 +1,39 @@
|
||||
; SPIR-V
|
||||
; Version: 1.3
|
||||
; Generator: Google Tint Compiler; 0
|
||||
; Bound: 19
|
||||
; Schema: 0
|
||||
OpCapability Shader
|
||||
OpMemoryModel Logical GLSL450
|
||||
OpEntryPoint Fragment %main "main"
|
||||
OpExecutionMode %main OriginUpperLeft
|
||||
OpName %slen "slen"
|
||||
OpName %ulen "ulen"
|
||||
OpName %main "main"
|
||||
OpName %signed_literal "signed_literal"
|
||||
OpName %unsigned_literal "unsigned_literal"
|
||||
OpName %signed_constant "signed_constant"
|
||||
OpName %unsigned_constant "unsigned_constant"
|
||||
OpDecorate %_arr_float_ulen ArrayStride 4
|
||||
%int = OpTypeInt 32 1
|
||||
%slen = OpConstant %int 4
|
||||
%uint = OpTypeInt 32 0
|
||||
%ulen = OpConstant %uint 4
|
||||
%void = OpTypeVoid
|
||||
%5 = OpTypeFunction %void
|
||||
%float = OpTypeFloat 32
|
||||
%_arr_float_ulen = OpTypeArray %float %ulen
|
||||
%_ptr_Function__arr_float_ulen = OpTypePointer Function %_arr_float_ulen
|
||||
%13 = OpConstantNull %_arr_float_ulen
|
||||
%main = OpFunction %void None %5
|
||||
%8 = OpLabel
|
||||
%signed_literal = OpVariable %_ptr_Function__arr_float_ulen Function %13
|
||||
%unsigned_literal = OpVariable %_ptr_Function__arr_float_ulen Function %13
|
||||
%signed_constant = OpVariable %_ptr_Function__arr_float_ulen Function %13
|
||||
%unsigned_constant = OpVariable %_ptr_Function__arr_float_ulen Function %13
|
||||
%17 = OpLoad %_arr_float_ulen %unsigned_constant
|
||||
OpStore %signed_literal %17
|
||||
%18 = OpLoad %_arr_float_ulen %unsigned_literal
|
||||
OpStore %signed_constant %18
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
13
test/array/size.wgsl.expected.wgsl
Normal file
13
test/array/size.wgsl.expected.wgsl
Normal file
@@ -0,0 +1,13 @@
|
||||
let slen = 4;
|
||||
|
||||
let ulen = 4u;
|
||||
|
||||
[[stage(fragment)]]
|
||||
fn main() {
|
||||
var signed_literal : array<f32, 4>;
|
||||
var unsigned_literal : array<f32, 4u>;
|
||||
var signed_constant : array<f32, slen>;
|
||||
var unsigned_constant : array<f32, ulen>;
|
||||
signed_literal = unsigned_constant;
|
||||
signed_constant = unsigned_literal;
|
||||
}
|
||||
Reference in New Issue
Block a user