diff options
| -rw-r--r-- | source/slang/slang-core-module-textures.cpp | 43 | ||||
| -rw-r--r-- | tests/compute/texture-get-dimensions-cuda.slang | 86 | ||||
| -rw-r--r-- | tests/compute/texture-get-dimensions-cuda.slang.expected.txt | 7 |
3 files changed, 135 insertions, 1 deletions
diff --git a/source/slang/slang-core-module-textures.cpp b/source/slang/slang-core-module-textures.cpp index f703a8a3b..ed34ed388 100644 --- a/source/slang/slang-core-module-textures.cpp +++ b/source/slang/slang-core-module-textures.cpp @@ -258,6 +258,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() StringBuilder metal; const char* metalMipLevel = "0"; + StringBuilder cuda; + cuda << "{"; + StringBuilder wgsl; wgsl << "{"; @@ -277,6 +280,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "width"; metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),"; + cuda << "uint32_t width; asm(\\\"txq.width.b32 %0, [%1];\\\" : \\\"=r\\\"(width) : " + "\\\"l\\\"($0)); *($" + << String(paramCount) << ") = width;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion( dimType, @@ -292,6 +298,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "width,"; metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),"; + cuda << "uint32_t w, h; asm(\\\"txq.width.b32 %0, [%2]; txq.height.b32 %1, " + "[%2];\\\" : \\\"=r\\\"(w), \\\"=r\\\"(h) : \\\"l\\\"($0)); *($" + << String(paramCount) << ") = w;"; wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";"; @@ -300,6 +309,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "height"; metal << "(*($" << String(paramCount) << ") = $0.get_height(" << String(metalMipLevel) << ")),"; + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "*($" << String(paramCount) << ") = h;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";"; @@ -311,6 +323,10 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "width,"; metal << "(*($" << String(paramCount) << ") = $0.get_width(" << String(metalMipLevel) << ")),"; + cuda << "uint32_t w, h, d; asm(\\\"txq.width.b32 %0, [%3]; txq.height.b32 %1, " + "[%3]; txq.depth.b32 %2, [%3];\\\" : \\\"=r\\\"(w), \\\"=r\\\"(h), " + "\\\"=r\\\"(d) : \\\"l\\\"($0)); *($" + << String(paramCount) << ") = w;"; wgsl << "var dim = textureDimensions($0" << (includeMipInfo ? ", $1" : "") << ");"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.x") << ";"; @@ -319,6 +335,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "height,"; metal << "(*($" << String(paramCount) << ") = $0.get_height(" << String(metalMipLevel) << ")),"; + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "*($" << String(paramCount) << ") = h;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.y") << ";"; @@ -326,6 +345,9 @@ void TextureTypeInfo::writeGetDimensionFunctions() params << t << "depth"; metal << "(*($" << String(paramCount) << ") = $0.get_depth(" << String(metalMipLevel) << ")),"; + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "*($" << String(paramCount) << ") = d;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "dim.z") << ";"; @@ -343,6 +365,14 @@ void TextureTypeInfo::writeGetDimensionFunctions() ++paramCount; params << ", " << t << "elements"; metal << "(*($" << String(paramCount) << ") = $0.get_array_size()),"; + + // For cube map arrays, CUDA should include all 6 faces in the array size count + // but we can't currently implement this as txq.array_size isn't supported + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "/* txq.array_size not available in CUDA */ *($" << String(paramCount) + << ") = 0;"; + wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumLayers($0)") << ";"; @@ -353,6 +383,10 @@ void TextureTypeInfo::writeGetDimensionFunctions() ++paramCount; params << ", " << t << "sampleCount"; metal << "(*($" << String(paramCount) << ") = $0.get_num_samples()),"; + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "/* txq.samples not available in CUDA */ *($" << String(paramCount) + << ") = 0;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumSamples($0)") << ";"; @@ -363,12 +397,17 @@ void TextureTypeInfo::writeGetDimensionFunctions() ++paramCount; params << ", " << t << "numberOfLevels"; metal << "(*($" << String(paramCount) << ") = $0.get_num_mip_levels()),"; + if (cuda.getLength() > 1 && cuda[cuda.getLength() - 1] != ';') + cuda << "; "; + cuda << "/* txq.num_mipmap_levels not available in CUDA */ *($" + << String(paramCount) << ") = 0;"; wgsl << "($" << String(paramCount) << ") = " << wgslTextureAttributeConversion(dimType, "textureNumLevels($0)") << ";"; } metal.reduceLength(metal.getLength() - 1); // drop the last comma + cuda << "}"; wgsl << "}"; StringBuilder glsl; @@ -559,6 +598,8 @@ void TextureTypeInfo::writeGetDimensionFunctions() sb << " __glsl_version(450)\n"; sb << " [require(cpp"; + if (cuda.getLength()) + sb << "_cuda"; if (glsl.getLength()) sb << "_glsl"; sb << "_hlsl"; @@ -578,7 +619,7 @@ void TextureTypeInfo::writeGetDimensionFunctions() spirvDefault, spirvRWDefault, spirvCombined, - "", + cuda.produceString(), metal, wgsl, ReadNoneMode::Always); 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<float> cudaT1D; +//TEST_INPUT: Texture2D(size=8, content = one):name cudaT2D +Texture2D<float> cudaT2D; +//TEST_INPUT: Texture3D(size=2, content = one):name cudaT3D +Texture3D<float> cudaT3D; +//TEST_INPUT: TextureCube(size=16, content = one):name cudaTCube +TextureCube<float> cudaTCube; +//TEST_INPUT: Texture2D(size=4, content = one, arrayLength=3):name cudaT2DArray +Texture2DArray<float> cudaT2DArray; +//TEST_INPUT: TextureCube(size=16, content = one, arrayLength=1):name cudaTCubeArray +TextureCubeArray<float> cudaTCubeArray; + +//TEST_INPUT: ubuffer(data=[0 0 0 0 0 0 0], stride=4):out,name cudaOutputBuffer +RWStructuredBuffer<uint> 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 |
