From 5dd27a26da9b6b6191f3b1eba0f38f85714c1ae3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 17 Apr 2024 22:14:34 -0700 Subject: Support combined texture sampler when targeting HLSL. (#3963) * Support combined texture sampler when targeting HLSL. * Fix glsl intrinsics. * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Update source/slang/slang-ir-lower-combined-texture-sampler.cpp Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> * Fix., * Enhance test. * Remove unused field. * Fix indentation --------- Co-authored-by: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> --- tests/glsl-intrinsic/intrinsic-texture.slang | 104 ++++++++++++++++++++++++++- tests/hlsl/combined-texture-sampler.slang | 25 +++++++ 2 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 tests/hlsl/combined-texture-sampler.slang (limited to 'tests') diff --git a/tests/glsl-intrinsic/intrinsic-texture.slang b/tests/glsl-intrinsic/intrinsic-texture.slang index 591ced099..4cf50abe1 100644 --- a/tests/glsl-intrinsic/intrinsic-texture.slang +++ b/tests/glsl-intrinsic/intrinsic-texture.slang @@ -72,7 +72,7 @@ uniform usampler2DMS uniform_usampler2DMS; uniform usampler2DMSArray uniform_usampler2DMSArray; #endif // #if defined(TEST_when_multisampling_works) -__generic +__generic bool textureFuncs( Sampler1D> gsampler1D , Sampler2D> gsampler2D , Sampler2DRect> gsampler2DRect @@ -400,6 +400,104 @@ bool textureFuncs( Sampler1D> gsampler1D ; } +__generic +bool itextureFuncs(Sampler1D> gsampler1D + , Sampler2D> gsampler2D + , Sampler2DRect> gsampler2DRect + , Sampler3D> gsampler3D + , SamplerCube> gsamplerCube + , Sampler1DArray> gsampler1DArray + , Sampler2DArray> gsampler2DArray + , SamplerCubeArray> gsamplerCubeArray + , SamplerBuffer> gsamplerBuffer +#if defined(TEST_when_multisampling_works) + , Sampler2DMS> gsampler2DMS + , Sampler2DMSArray> gsampler2DMSArray +#endif // #if defined(TEST_when_multisampling_works) +) +{ + typealias gvec4 = vector; + + constexpr ivec2 ivec2_0 = ivec2(0); + + return true + // 8.9.1. Texture Query Functions + && int(0) == textureSize(gsampler1D, int(0)) + && ivec2(0) == textureSize(gsampler2D, int(0)) + && ivec3(0) == textureSize(gsampler3D, int(0)) + && ivec2(0) == textureSize(gsamplerCube, int(0)) + && int(0) == textureSize(uniform_sampler1DShadow, int(0)) + && ivec2(0) == textureSize(uniform_sampler2DShadow, int(0)) + && ivec2(0) == textureSize(uniform_samplerCubeShadow, int(0)) + && ivec3(0) == textureSize(gsamplerCubeArray, int(0)) + && ivec3(0) == textureSize(uniform_samplerCubeArrayShadow, int(0)) + && ivec2(0) == textureSize(gsampler2DRect) + && ivec2(0) == textureSize(uniform_sampler2DRectShadow) + && ivec2(0) == textureSize(gsampler1DArray, int(0)) + && ivec2(0) == textureSize(uniform_sampler1DArrayShadow, int(0)) + && ivec3(0) == textureSize(gsampler2DArray, int(0)) + && ivec3(0) == textureSize(uniform_sampler2DArrayShadow, int(0)) + && int(0) == textureSize(gsamplerBuffer) +#if defined(TEST_when_multisampling_works) + && ivec2(0) == textureSize(gsampler2DMS) + && ivec3(0) == textureSize(gsampler2DMSArray) +#endif + && gvec4(T(0)) == texelFetch(gsampler1D, int(0), int(0)) + && gvec4(T(0)) == texelFetch(gsampler2D, ivec2(0), int(0)) + && gvec4(T(0)) == texelFetch(gsampler3D, ivec3(0), int(0)) + && gvec4(T(0)) == texelFetch(gsampler2DRect, ivec2(0)) + && gvec4(T(0)) == texelFetch(gsampler1DArray, ivec2(0), int(0)) + && gvec4(T(0)) == texelFetch(gsampler2DArray, ivec3(0), int(0)) + && gvec4(T(0)) == texelFetch(gsamplerBuffer, int(0)) +#if defined(TEST_when_multisampling_works) + && gvec4(T(0)) == texelFetch(gsampler2DMS, ivec2(0), int(0)) + && gvec4(T(0)) == texelFetch(gsampler2DMSArray, ivec3(0), int(0)) +#endif // #if defined(TEST_when_multisampling_works) + && gvec4(T(0)) == texelFetchOffset(gsampler1D, int(0), int(0), __LINE__) + && gvec4(T(0)) == texelFetchOffset(gsampler2D, ivec2(0), int(0), { __LINE__ }) + && gvec4(T(0)) == texelFetchOffset(gsampler3D, ivec3(0), int(0), { __LINE__ }) + && gvec4(T(0)) == texelFetchOffset(gsampler2DRect, ivec2(0), { __LINE__ }) + && gvec4(T(0)) == texelFetchOffset(gsampler1DArray, ivec2(0), int(0), __LINE__) + && gvec4(T(0)) == texelFetchOffset(gsampler2DArray, ivec3(0), int(0), { __LINE__ }) + // 8.9.4. Texture Gather Functions + && gvec4(T(0)) == textureGather(gsampler2D, vec2(0)) + && gvec4(T(0)) == textureGather(gsampler2D, vec2(0), int(0)) + && gvec4(T(0)) == textureGather(gsampler2DArray, vec3(0)) + && gvec4(T(0)) == textureGather(gsampler2DArray, vec3(0), int(0)) + && gvec4(T(0)) == textureGather(gsamplerCube, vec3(0)) + && gvec4(T(0)) == textureGather(gsamplerCube, vec3(0), int(0)) + && gvec4(T(0)) == textureGather(gsamplerCubeArray, vec4(0)) + && gvec4(T(0)) == textureGather(gsamplerCubeArray, vec4(0), int(0)) + && gvec4(T(0)) == textureGather(gsampler2DRect, vec2(0)) + && gvec4(T(0)) == textureGather(gsampler2DRect, vec2(0), int(0)) + && vec4(0) == textureGather(uniform_sampler2DShadow, vec2(0), float(0)) + && vec4(0) == textureGather(uniform_sampler2DArrayShadow, vec3(0), float(0)) + && vec4(0) == textureGather(uniform_samplerCubeShadow, vec3(0), float(0)) + && vec4(0) == textureGather(uniform_samplerCubeArrayShadow, vec4(0), float(0)) + && vec4(0) == textureGather(uniform_sampler2DRectShadow, vec2(0), float(0)) + && gvec4(T(0)) == textureGatherOffset(gsampler2D, vec2(0), { __LINE__ }) + && gvec4(T(0)) == textureGatherOffset(gsampler2D, vec2(0), { __LINE__ }, int(0)) + && gvec4(T(0)) == textureGatherOffset(gsampler2DArray, vec3(0), { __LINE__ }) + && gvec4(T(0)) == textureGatherOffset(gsampler2DArray, vec3(0), { __LINE__ }, int(0)) + && vec4(0) == textureGatherOffset(uniform_sampler2DShadow, vec2(0), float(0), { __LINE__ }) + && vec4(0) == textureGatherOffset(uniform_sampler2DArrayShadow, vec3(0), float(0), { __LINE__ }) + && gvec4(T(0)) == textureGatherOffset(gsampler2DRect, vec2(0), { __LINE__ }) + && gvec4(T(0)) == textureGatherOffset(gsampler2DRect, vec2(0), { __LINE__ }, int(0)) + && vec4(0) == textureGatherOffset(uniform_sampler2DRectShadow, vec2(0), float(0), { __LINE__ }) +#if defined(TEST_when_constexpr_works) + && gvec4(T(0)) == textureGatherOffsets(gsampler2D, vec2(0), { __LINE__ }) // constexpr not working + && gvec4(T(0)) == textureGatherOffsets(gsampler2D, vec2(0), { __LINE__ }, int(0)) // constexpr not working + && gvec4(T(0)) == textureGatherOffsets(gsampler2DArray, vec3(0), { __LINE__ }) // constexpr not working + && gvec4(T(0)) == textureGatherOffsets(gsampler2DArray, vec3(0), { __LINE__ }, int(0)) // constexpr not working + && vec4(0) == textureGatherOffsets(uniform_sampler2DShadow, vec2(0), float(0), { __LINE__ }) // constexpr not working + && vec4(0) == textureGatherOffsets(uniform_sampler2DArrayShadow, vec3(0), float(0), { __LINE__ }) // constexpr not working + && gvec4(T(0)) == textureGatherOffsets(gsampler2DRect, vec2(0), { __LINE__ }) // constexpr not working + && gvec4(T(0)) == textureGatherOffsets(gsampler2DRect, vec2(0), { __LINE__ }, int(0)) // constexpr not working + && vec4(0) == textureGatherOffsets(uniform_sampler2DRectShadow, vec2(0), float(0), { __LINE__ }) // constexpr not working +#endif // #if defined(TEST_when_constexpr_works) + ; +} + [numthreads(4, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { @@ -425,7 +523,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) , uniform_sampler2DMSArray #endif // #if defined(TEST_when_multisampling_works) ) - && textureFuncs( + && itextureFuncs( uniform_isampler1D , uniform_isampler2D , uniform_isampler2DRect @@ -440,7 +538,7 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) , uniform_isampler2DMSArray #endif // #if defined(TEST_when_multisampling_works) ) - && textureFuncs( + && itextureFuncs( uniform_usampler1D , uniform_usampler2D , uniform_usampler2DRect diff --git a/tests/hlsl/combined-texture-sampler.slang b/tests/hlsl/combined-texture-sampler.slang new file mode 100644 index 000000000..986ac3468 --- /dev/null +++ b/tests/hlsl/combined-texture-sampler.slang @@ -0,0 +1,25 @@ +//TEST:SIMPLE(filecheck=CHECK): -target hlsl -entry fragMain -profile ps_6_0 +//TEST:SIMPLE(filecheck=DXIL): -target dxil -entry fragMain -profile ps_6_0 + +// Check that we can correctly cross compile combined texture samplers to HLSL. + +// DXIL: define void @fragMain() + +// CHECK-DAG: Texture2D sampler_texture{{.*}} : register(t0); +// CHECK-DAG: SamplerState sampler_sampler{{.*}} : register(s0); +Sampler2D sampler; + +// CHECK-DAG: Texture2D followingTexture{{.*}} : register(t1); +Texture2D followingTexture; + +// CHECK-DAG: SamplerState followingSamplerState{{.*}} : register(s1); +SamplerState followingSamplerState; + +// CHECK-DAG: Texture2D explicitBindingSampler_texture{{.*}} : register(t4); +// CHECK-DAG: SamplerState explicitBindingSampler_sampler{{.*}} : register(s3); +Sampler2D explicitBindingSampler : register(t4): register(s3); + +float4 fragMain() : SV_Target +{ + return sampler.Sample(float2(0, 0)) + explicitBindingSampler.Sample(float2(0, 0)) + followingTexture.Sample(followingSamplerState, float2(0,0)); +} \ No newline at end of file -- cgit v1.2.3