From 549aa897bcfedc28fb2ef8009396f846ea182b72 Mon Sep 17 00:00:00 2001 From: Mukund Keshava Date: Tue, 1 Apr 2025 18:16:17 +0530 Subject: Add GetDimensions support for CUDA (#6718) * Add GetDimensions support for CUDA This CL adds GetDimensions support for cuda by using the PTX instructions. Currently, PTX only supports getting width, height and depth. This CL also adds a new test to test this support. Fixes #5139 * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- tests/compute/texture-get-dimensions-cuda.slang | 86 ++++++++++++++++++++++ .../texture-get-dimensions-cuda.slang.expected.txt | 7 ++ 2 files changed, 93 insertions(+) create mode 100644 tests/compute/texture-get-dimensions-cuda.slang create mode 100644 tests/compute/texture-get-dimensions-cuda.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/texture-get-dimensions-cuda.slang b/tests/compute/texture-get-dimensions-cuda.slang new file mode 100644 index 000000000..43d11a6f8 --- /dev/null +++ b/tests/compute/texture-get-dimensions-cuda.slang @@ -0,0 +1,86 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj + +// Only testing the dimensions available in CUDA via txq: +// - txq.width.b32 +// - txq.height.b32 +// - txq.depth.b32 + +//TEST_INPUT: Texture1D(size=4, content = one):name cudaT1D +Texture1D cudaT1D; +//TEST_INPUT: Texture2D(size=8, content = one):name cudaT2D +Texture2D cudaT2D; +//TEST_INPUT: Texture3D(size=2, content = one):name cudaT3D +Texture3D cudaT3D; +//TEST_INPUT: TextureCube(size=16, content = one):name cudaTCube +TextureCube cudaTCube; +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=3):name cudaT2DArray +Texture2DArray cudaT2DArray; +//TEST_INPUT: TextureCube(size=16, content = one, arrayLength=1):name cudaTCubeArray +TextureCubeArray cudaTCubeArray; + +//TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name cudaOutputBuffer +RWStructuredBuffer cudaOutputBuffer; + +[numthreads(7, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + int idx = dispatchThreadID.x; + + uint width = 0; + uint height = 0; + uint depth = 0; + + switch (idx) + { + case 0: + { + // Test 1D texture width + cudaT1D.GetDimensions(width); + cudaOutputBuffer[idx] = width; + break; + } + case 1: + { + // Test 2D texture width and height + cudaT2D.GetDimensions(width, height); + cudaOutputBuffer[idx] = ((0xff & width) << 8) | (0xff & height); + break; + } + case 2: + { + // Test 3D texture width, height and depth + cudaT3D.GetDimensions(width, height, depth); + cudaOutputBuffer[idx] = ((0xff & width) << 16) | ((0xff & height) << 8) | (0xff & depth); + break; + } + case 3: + { + // Test Cube texture width and height + cudaTCube.GetDimensions(width, height); + cudaOutputBuffer[idx] = ((0xff & width) << 8) | (0xff & height); + break; + } + case 4: + { + // Test 2D array texture width and height + // Note: We don't test array size since txq.array_size is not implemented + cudaT2DArray.GetDimensions(width, height, depth); + cudaOutputBuffer[idx] = ((0xff & width) << 8) | (0xff & height); + break; + } + case 5: + { + // Test Cube array texture width and height + // Note: We don't test array size since txq.array_size is not implemented + cudaTCubeArray.GetDimensions(width, height, depth); + cudaOutputBuffer[idx] = ((0xff & width) << 8) | (0xff & height); + break; + } + case 6: + { + // Reserved for future use + cudaOutputBuffer[idx] = 0; + break; + } + } +} \ No newline at end of file diff --git a/tests/compute/texture-get-dimensions-cuda.slang.expected.txt b/tests/compute/texture-get-dimensions-cuda.slang.expected.txt new file mode 100644 index 000000000..3db0b119a --- /dev/null +++ b/tests/compute/texture-get-dimensions-cuda.slang.expected.txt @@ -0,0 +1,7 @@ +4 +808 +20202 +1010 +404 +1010 +0 \ No newline at end of file -- cgit v1.2.3