-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WGSL] Generate the correct code for arrayLength
https://bugs.webkit.org/show_bug.cgi?id=262703 rdar://116524838 Reviewed by Mike Wyrzykowski. As of 268884@main, the API now exposes the size of runtime-sized arrays at the end of the argument buffer. This patch updates the compiler to match this argument buffer layout and rewrite calls to arrayLength to read these sizes. * Source/WebGPU/WGSL/GlobalVariableRewriter.cpp: (WGSL::RewriteGlobalVariables::getPacking): (WGSL::RewriteGlobalVariables::collectGlobals): (WGSL::RewriteGlobalVariables::containsRuntimeArray): (WGSL::RewriteGlobalVariables::packArrayType): * Source/WebGPU/WGSL/Metal/MetalFunctionWriter.cpp: (WGSL::Metal::emitArrayLength): (WGSL::Metal::FunctionDefinitionWriter::visit): * Source/WebGPU/WGSL/tests/valid/array-length.wgsl: Added. Canonical link: https://commits.webkit.org/268995@main
- Loading branch information
1 parent
c9c17fb
commit 8f80944
Showing
4 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// RUN: %metal-compile main | ||
|
||
struct S { | ||
x: array<f32>, | ||
} | ||
|
||
struct Packed { | ||
x: vec3<f32> | ||
} | ||
|
||
|
||
struct T { | ||
x: array<Packed>, | ||
} | ||
|
||
@group(0) @binding(0) var<storage, read_write> x: array<f32>; | ||
@group(0) @binding(1) var<storage, read_write> y: S; | ||
@group(0) @binding(2) var<storage, read_write> z: T; | ||
|
||
fn f() -> u32 { | ||
let x1 = arrayLength(&x); | ||
let y1 = arrayLength(&y.x); | ||
let z1 = arrayLength(&z.x); | ||
|
||
let xptr = &x; | ||
let yptr = &y.x; | ||
let zptr = &z.x; | ||
|
||
let x2 = arrayLength(xptr); | ||
let y2 = arrayLength(yptr); | ||
let z2 = arrayLength(zptr); | ||
|
||
return x1 + y1 + z1 + x2 + y2 + z2; | ||
} | ||
|
||
@compute @workgroup_size(1, 1, 1) | ||
fn main() { | ||
let x = f(); | ||
} |