diff options
| author | DarrelFW321 <60972474+DarrelFW321@users.noreply.github.com> | 2025-03-21 20:11:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-22 00:11:29 +0000 |
| commit | 7f72256bcf3e9a33feec641ce8bc98bc750b6297 (patch) | |
| tree | 118519b804cf1b9b0131f0feffc6dbff5d429a76 | |
| parent | 969d101aff074675de32bdbe6b97baf744634f78 (diff) | |
Add GLSL array length syntax support (#6665)
| -rw-r--r-- | source/slang/glsl.meta.slang | 11 | ||||
| -rw-r--r-- | tests/glsl-intrinsic/array-length.slang | 34 |
2 files changed, 45 insertions, 0 deletions
diff --git a/source/slang/glsl.meta.slang b/source/slang/glsl.meta.slang index 4412ae460..9e6c6c3cc 100644 --- a/source/slang/glsl.meta.slang +++ b/source/slang/glsl.meta.slang @@ -321,6 +321,17 @@ ${{{{ } }}}} +/// Array length +__generic<T, let N : int> +public extension Array<T, N> +{ + [ForceInline] + public int length() + { + return this.getCount(); + } +} + // // Section 8.1. Angle and Trigonometry Functions // diff --git a/tests/glsl-intrinsic/array-length.slang b/tests/glsl-intrinsic/array-length.slang new file mode 100644 index 000000000..e5b96a148 --- /dev/null +++ b/tests/glsl-intrinsic/array-length.slang @@ -0,0 +1,34 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -allow-glsl +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -shaderobj -render-feature hardware-device -allow-glsl +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-metal -compute -shaderobj -allow-glsl +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -shaderobj -allow-glsl +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-wgpu -compute -shaderobj -allow-glsl +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -g0 -allow-glsl + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name outputBuffer +RWStructuredBuffer<int> outputBuffer; + +// +// Tests GLSL array.length() syntax. +// + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain() +{ + int myArray[4] = {4, 3, 2, 1}; + outputBuffer[0] = myArray[0]; + outputBuffer[1] = myArray[1]; + outputBuffer[2] = myArray[2]; + outputBuffer[3] = myArray[3]; + outputBuffer[4] = myArray.length(); + + // BUF: 4 + // BUF-NEXT: 3 + // BUF-NEXT: 2 + // BUF-NEXT: 1 + // BUF-NEXT: 4 +} + + + |
