From 4b3fd0a4536f873649e6fcdefbaf2f8b6f0897e0 Mon Sep 17 00:00:00 2001 From: Simon Kallweit <64953474+skallweitNV@users.noreply.github.com> Date: Wed, 8 Oct 2025 20:18:23 +0200 Subject: Improve texture loads and stores on CUDA (#8644) - fix handling layer and mip level - add support for 1D layered textures - reduce code by using macros - assert when trying to emit unsupported intrinsics There is a new set of unit tests in slang-rhi for exhaustive testing of shader loads/stores on textures. These fixes allow to enable most of these tests. Formatted loads/stores on surfaces are not supported in PTX ISA, so this would require codegen for the conversion which in theory should be possible but not as part of the CUDA prelude. --- source/slang/hlsl.meta.slang | 41 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 22 deletions(-) (limited to 'source') diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang index ff2762b23..26c2a43cb 100644 --- a/source/slang/hlsl.meta.slang +++ b/source/slang/hlsl.meta.slang @@ -3654,32 +3654,29 @@ extension _Texture __intrinsic_asm ".Load"; case cuda: if (isArray != 0) + { + switch(Shape.flavor) { - static_assert(Shape.flavor == $(SLANG_TEXTURE_2D) || Shape.flavor == $(SLANG_TEXTURE_3D), - "Integer coordinates are supported for texture reads only for 2D and 3D textures and 2D array textures."); - - if (Shape.flavor == $(SLANG_TEXTURE_2D)) - { - __intrinsic_asm "tex2DArrayfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)"; - } - else - { - __intrinsic_asm ""; - } + case $(SLANG_TEXTURE_1D): + __intrinsic_asm "tex1DArrayfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)"; + case $(SLANG_TEXTURE_2D): + __intrinsic_asm "tex2DArrayfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z, ($1).w)"; } - else + } + else + { + switch(Shape.flavor) { - switch(Shape.flavor) - { - case $(SLANG_TEXTURE_2D): - __intrinsic_asm "tex2Dfetch_int<$T0>($0, ($1).x, ($1).y)"; - case $(SLANG_TEXTURE_3D): - __intrinsic_asm "tex3Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)"; - case $(SLANG_TEXTURE_CUBE): - default: - __intrinsic_asm ""; - } + case $(SLANG_TEXTURE_1D): + __intrinsic_asm "tex1Dfetch_int<$T0>($0, ($1).x, ($1).y)"; + case $(SLANG_TEXTURE_2D): + __intrinsic_asm "tex2Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z)"; + case $(SLANG_TEXTURE_3D): + __intrinsic_asm "tex3Dfetch_int<$T0>($0, ($1).x, ($1).y, ($1).z, ($1).w)"; } + } + static_assert(false, "Unsupported 'Load' of 'texture' for 'cuda' target"); + __intrinsic_asm ""; case metal: switch (Shape.flavor) { -- cgit v1.2.3