Add arrayLength() intrinsic that accepts a pointer argument

The old non-pointer argument overload remains, but is now deprecated.

Bug: tint:806
Change-Id: Ic917ccec0f162414ce1b03df49e332ad84d8060f
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54061
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
Ben Clayton
2021-06-10 18:43:04 +00:00
committed by Tint LUCI CQ
parent 0aa7edbbd5
commit aba42ed362
46 changed files with 2298 additions and 1215 deletions

View File

@@ -1,6 +0,0 @@
[numthreads(1, 1, 1)]
void main() {
return;
}

View File

@@ -1,11 +0,0 @@
#include <metal_stdlib>
using namespace metal;
struct S {
/* 0x0000 */ int a[1];
};
kernel void tint_symbol() {
return;
}

View File

@@ -7,6 +7,7 @@ struct S {
[[stage(compute)]]
fn main() {
// TODO(crbug.com/tint/806): arrayLength signature is currently wrong
// let l : i32 = arrayLength(&G.a);
let p = &G;
let p2 = &((*p).a);
let l1 : u32 = arrayLength(p2);
}

View File

@@ -0,0 +1,12 @@
ByteAddressBuffer G : register(t0, space0);
[numthreads(1, 1, 1)]
void main() {
uint tint_symbol_1 = 0u;
G.GetDimensions(tint_symbol_1);
const uint tint_symbol_2 = ((tint_symbol_1 - 0u) / 4u);
const uint l1 = tint_symbol_2;
return;
}

View File

@@ -0,0 +1,18 @@
SKIP: FAILED
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn tint_symbol() {
let p = &(G);
let p2 = &((*(p)).a);
let l1 : u32 = arrayLength(p2);
}
Failed to generate: error: Unknown import method: arrayLength

View File

@@ -1,7 +1,7 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 10
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
@@ -24,7 +24,9 @@
%G = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%main = OpFunction %void None %6
%9 = OpLabel
%10 = OpArrayLength %uint %G 0
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,13 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let p = &(G);
let p2 = &((*(p)).a);
let l1 : u32 = arrayLength(p2);
}

View File

@@ -0,0 +1,14 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let l1 : u32 = arrayLength(&G.a);
let p = &G.a;
let l2 : u32 = arrayLength(p);
}

View File

@@ -0,0 +1,13 @@
ByteAddressBuffer G : register(t0, space0);
[numthreads(1, 1, 1)]
void main() {
uint tint_symbol_1 = 0u;
G.GetDimensions(tint_symbol_1);
const uint tint_symbol_2 = ((tint_symbol_1 - 0u) / 4u);
const uint l1 = tint_symbol_2;
const uint l2 = tint_symbol_2;
return;
}

View File

@@ -0,0 +1,18 @@
SKIP: FAILED
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn tint_symbol() {
let l1 : u32 = arrayLength(&(G.a));
let p = &(G.a);
let l2 : u32 = arrayLength(p);
}
Failed to generate: error: Unknown import method: arrayLength

View File

@@ -0,0 +1,33 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 13
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %S "S"
OpMemberName %S 0 "a"
OpName %G "G"
OpName %main "main"
OpDecorate %S Block
OpMemberDecorate %S 0 Offset 0
OpDecorate %_runtimearr_int ArrayStride 4
OpDecorate %G NonWritable
OpDecorate %G DescriptorSet 0
OpDecorate %G Binding 0
%int = OpTypeInt 32 1
%_runtimearr_int = OpTypeRuntimeArray %int
%S = OpTypeStruct %_runtimearr_int
%_ptr_StorageBuffer_S = OpTypePointer StorageBuffer %S
%G = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%main = OpFunction %void None %6
%9 = OpLabel
%10 = OpArrayLength %uint %G 0
%12 = OpArrayLength %uint %G 0
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,13 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let l1 : u32 = arrayLength(&(G.a));
let p = &(G.a);
let l2 : u32 = arrayLength(p);
}

View File

@@ -0,0 +1,11 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let l1 : u32 = arrayLength(&G.a);
}

View File

@@ -0,0 +1,12 @@
ByteAddressBuffer G : register(t0, space0);
[numthreads(1, 1, 1)]
void main() {
uint tint_symbol_1 = 0u;
G.GetDimensions(tint_symbol_1);
const uint tint_symbol_2 = ((tint_symbol_1 - 0u) / 4u);
const uint l1 = tint_symbol_2;
return;
}

View File

@@ -0,0 +1,16 @@
SKIP: FAILED
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn tint_symbol() {
let l1 : u32 = arrayLength(&(G.a));
}
Failed to generate: error: Unknown import method: arrayLength

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %S "S"
OpMemberName %S 0 "a"
OpName %G "G"
OpName %main "main"
OpDecorate %S Block
OpMemberDecorate %S 0 Offset 0
OpDecorate %_runtimearr_int ArrayStride 4
OpDecorate %G NonWritable
OpDecorate %G DescriptorSet 0
OpDecorate %G Binding 0
%int = OpTypeInt 32 1
%_runtimearr_int = OpTypeRuntimeArray %int
%S = OpTypeStruct %_runtimearr_int
%_ptr_StorageBuffer_S = OpTypePointer StorageBuffer %S
%G = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%main = OpFunction %void None %6
%9 = OpLabel
%10 = OpArrayLength %uint %G 0
OpReturn
OpFunctionEnd

View File

@@ -7,4 +7,5 @@ struct S {
[[stage(compute)]]
fn main() {
let l1 : u32 = arrayLength(&(G.a));
}

View File

@@ -0,0 +1,13 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let p = &G.a;
let p2 = p;
let l1 : u32 = arrayLength(p2);
}

View File

@@ -0,0 +1,12 @@
ByteAddressBuffer G : register(t0, space0);
[numthreads(1, 1, 1)]
void main() {
uint tint_symbol_1 = 0u;
G.GetDimensions(tint_symbol_1);
const uint tint_symbol_2 = ((tint_symbol_1 - 0u) / 4u);
const uint l1 = tint_symbol_2;
return;
}

View File

@@ -0,0 +1,18 @@
SKIP: FAILED
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn tint_symbol() {
let p = &(G.a);
let p2 = p;
let l1 : u32 = arrayLength(p2);
}
Failed to generate: error: Unknown import method: arrayLength

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %S "S"
OpMemberName %S 0 "a"
OpName %G "G"
OpName %main "main"
OpDecorate %S Block
OpMemberDecorate %S 0 Offset 0
OpDecorate %_runtimearr_int ArrayStride 4
OpDecorate %G NonWritable
OpDecorate %G DescriptorSet 0
OpDecorate %G Binding 0
%int = OpTypeInt 32 1
%_runtimearr_int = OpTypeRuntimeArray %int
%S = OpTypeStruct %_runtimearr_int
%_ptr_StorageBuffer_S = OpTypePointer StorageBuffer %S
%G = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%main = OpFunction %void None %6
%9 = OpLabel
%10 = OpArrayLength %uint %G 0
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,13 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let p = &(G.a);
let p2 = p;
let l1 : u32 = arrayLength(p2);
}

View File

@@ -0,0 +1,14 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let p = &*&G;
let p2 = &*p;
let p3 = &((*p).a);
let l1 : u32 = arrayLength(&*p3);
}

View File

@@ -0,0 +1,12 @@
ByteAddressBuffer G : register(t0, space0);
[numthreads(1, 1, 1)]
void main() {
uint tint_symbol_1 = 0u;
G.GetDimensions(tint_symbol_1);
const uint tint_symbol_2 = ((tint_symbol_1 - 0u) / 4u);
const uint l1 = tint_symbol_2;
return;
}

View File

@@ -0,0 +1,19 @@
SKIP: FAILED
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn tint_symbol() {
let p = &(*(&(G)));
let p2 = &(*(p));
let p3 = &((*(p)).a);
let l1 : u32 = arrayLength(&(*(p3)));
}
Failed to generate: error: Unknown import method: arrayLength

View File

@@ -0,0 +1,32 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 12
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpName %S "S"
OpMemberName %S 0 "a"
OpName %G "G"
OpName %main "main"
OpDecorate %S Block
OpMemberDecorate %S 0 Offset 0
OpDecorate %_runtimearr_int ArrayStride 4
OpDecorate %G NonWritable
OpDecorate %G DescriptorSet 0
OpDecorate %G Binding 0
%int = OpTypeInt 32 1
%_runtimearr_int = OpTypeRuntimeArray %int
%S = OpTypeStruct %_runtimearr_int
%_ptr_StorageBuffer_S = OpTypePointer StorageBuffer %S
%G = OpVariable %_ptr_StorageBuffer_S StorageBuffer
%void = OpTypeVoid
%6 = OpTypeFunction %void
%uint = OpTypeInt 32 0
%main = OpFunction %void None %6
%9 = OpLabel
%10 = OpArrayLength %uint %G 0
OpReturn
OpFunctionEnd

View File

@@ -0,0 +1,14 @@
[[block]]
struct S {
a : array<i32>;
};
[[group(0), binding(0)]] var<storage, read> G : S;
[[stage(compute)]]
fn main() {
let p = &(*(&(G)));
let p2 = &(*(p));
let p3 = &((*(p)).a);
let l1 : u32 = arrayLength(&(*(p3)));
}

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/647a40.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
struct tint_symbol {
float4 value : SV_Position;
};

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/647a40.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/647a40.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
[[block]]
struct SB {
arg_0 : array<u32>;

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/721c9d.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
struct tint_symbol {
float4 value : SV_Position;
};

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/721c9d.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/721c9d.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
[[block]]
struct SB {
arg_0 : array<i32>;

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/b083be.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
struct tint_symbol {
float4 value : SV_Position;
};

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/b083be.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0

View File

@@ -1,3 +1,7 @@
intrinsics/gen/arrayLength/b083be.wgsl:31:18 warning: use of deprecated intrinsic
var res: u32 = arrayLength(sb.arg_0);
^^^^^^^^^^^
[[block]]
struct SB {
arg_0 : array<f32>;