summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/slang/hlsl.meta.slang71
-rw-r--r--tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang23
-rw-r--r--tests/hlsl-intrinsic/texture/partial-resident-texture.slang4
3 files changed, 94 insertions, 4 deletions
diff --git a/source/slang/hlsl.meta.slang b/source/slang/hlsl.meta.slang
index 558ac6301..5f0edb3f9 100644
--- a/source/slang/hlsl.meta.slang
+++ b/source/slang/hlsl.meta.slang
@@ -3772,12 +3772,47 @@ extension _Texture<T,Shape,isArray,0,sampleCount,0,isShadow,isCombined,format>
[__readNone]
[ForceInline]
- [require(hlsl, texture_sm_4_1_samplerless)]
+ [require(hlsl_spirv, texture_sm_4_1_samplerless)]
T Load(vector<int, Shape.dimensions+isArray+1> location, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
{
__target_switch
{
case hlsl: __intrinsic_asm ".Load";
+ case spirv:
+ const int lodLoc = Shape.dimensions+isArray;
+ let coord = __vectorReshape<Shape.dimensions+isArray>(location);
+ let lod = location[lodLoc];
+ if (isCombined != 0)
+ {
+ return spirv_asm
+ {
+ OpCapability SparseResidency;
+ %sparseResultType = OpTypeStruct $$uint __sampledType(T);
+ %image:__imageType(this) = OpImage $this;
+
+ %sparseResult:%sparseResultType = OpImageSparseFetch %image $coord Lod|ConstOffset $lod $offset;
+ %residentCode:$$uint = OpCompositeExtract %sparseResult 0;
+ %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;
+
+ OpStore &status %residentCode;
+ __truncate $$T result __sampledType(T) %sampled;
+ };
+ }
+ else
+ {
+ return spirv_asm
+ {
+ OpCapability SparseResidency;
+ %sparseResultType = OpTypeStruct $$uint __sampledType(T);
+
+ %sparseResult:%sparseResultType = OpImageSparseFetch $this $coord Lod|ConstOffset $lod $offset;
+ %residentCode:$$uint = OpCompositeExtract %sparseResult 0;
+ %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;
+
+ OpStore &status %residentCode;
+ __truncate $$T result __sampledType(T) %sampled;
+ };
+ }
default:
status = 0;
return Load(location, offset);
@@ -3952,12 +3987,44 @@ extension _Texture<T,Shape,isArray,1,sampleCount,0,isShadow,isCombined,format>
[__readNone]
[ForceInline]
- [require(hlsl, texture_sm_4_1_samplerless)]
+ [require(hlsl_spirv, texture_sm_4_1_samplerless)]
T Load(vector<int, Shape.dimensions+isArray> location, int sampleIndex, constexpr vector<int, Shape.planeDimensions> offset, out uint status)
{
__target_switch
{
case hlsl: __intrinsic_asm ".Load";
+ case spirv:
+ if (isCombined != 0)
+ {
+ return spirv_asm
+ {
+ OpCapability SparseResidency;
+ %sparseResultType = OpTypeStruct $$uint __sampledType(T);
+ %image:__imageType(this) = OpImage $this;
+
+ %sparseResult:%sparseResultType = OpImageSparseFetch %image $location ConstOffset|Sample $offset $sampleIndex;
+ %residentCode:$$uint = OpCompositeExtract %sparseResult 0;
+ %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;
+
+ OpStore &status %residentCode;
+ __truncate $$T result __sampledType(T) %sampled;
+ };
+ }
+ else
+ {
+ return spirv_asm
+ {
+ OpCapability SparseResidency;
+ %sparseResultType = OpTypeStruct $$uint __sampledType(T);
+
+ %sparseResult:%sparseResultType = OpImageSparseFetch $this $location ConstOffset|Sample $offset $sampleIndex;
+ %residentCode:$$uint = OpCompositeExtract %sparseResult 0;
+ %sampled:__sampledType(T) = OpCompositeExtract %sparseResult 1;
+
+ OpStore &status %residentCode;
+ __truncate $$T result __sampledType(T) %sampled;
+ };
+ }
default:
status = 0;
return Load(location, sampleIndex, offset);
diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang
index 21b16eba8..3deddb504 100644
--- a/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang
+++ b/tests/hlsl-intrinsic/texture/partial-resident-texture-combined.slang
@@ -37,6 +37,9 @@ Sampler1DArray<float4> st1DArray_f32v4;
//TEST_INPUT: TextureSampler2D(size=4, content = one, arrayLength=2):name st2DArray_f32v4
Sampler2DArray<float4> st2DArray_f32v4;
+//TEST_INPUT: TextureSampler2D(size=4, content = one):name st2DMS_f32v4
+ Sampler2DMS<float4> st2DMS_f32v4;
+
//
// Combined depth texture samplers.
//
@@ -177,6 +180,25 @@ bool TEST_sampler<T>(
;
}
+bool TEST_sparse<T>(
+ Sampler2D<T> s2D,
+ Sampler2DMS<T> s2DMS)
+ where T : ITexelElement, IArithmetic
+ {
+ typealias TN = T;
+ constexpr const int2 offset = int2(0, 0);
+ uint status;
+
+ int sampleIndex = 0;
+ int2 iuv = int2(1, 1);
+ int3 iuvs = int3(iuv, sampleIndex);
+
+ return true
+ && (status = getNotMapped(), all(TN(T(1)) == s2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status)
+ && (status = getNotMapped(), all(TN(T(1)) == s2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status)
+ ;
+ }
+
[numthreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
{
@@ -198,6 +220,7 @@ void computeMain(int3 dispatchThreadID: SV_DispatchThreadID)
st2DArray_f32v4,
)
&& TEST_combinedDepth()
+ && TEST_sparse(st2D_f32v4, st2DMS_f32v4)
;
//CHK:1
diff --git a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang
index ee2c21225..edf67ddc1 100644
--- a/tests/hlsl-intrinsic/texture/partial-resident-texture.slang
+++ b/tests/hlsl-intrinsic/texture/partial-resident-texture.slang
@@ -235,10 +235,10 @@ bool TEST_load<T>(
int3 iuvs = int3(iuv, sampleIndex);
return true
- // Currently not supported by Slang on VK.
-#if !defined(VK)
&& (status = getNotMapped(), all(TN(T(1)) == t2DMS.Load(iuv, sampleIndex, offset, status))) && CheckAccessFullyMapped(status)
&& (status = getNotMapped(), all(TN(T(1)) == t2D.Load(iuvs, offset, status))) && CheckAccessFullyMapped(status)
+ // SPIRV does not support sparse buffer loads.
+#if !defined(VK)
&& (status = getNotMapped(), 2 == outputBuffer.Load(0, status)) && CheckAccessFullyMapped(status)
&& (status = getNotMapped(), 1 == iBuf.Load(0, status)) && CheckAccessFullyMapped(status)
&& (status = getNotMapped(), all(int2(1) == iBuf.Load2(0, status))) && CheckAccessFullyMapped(status)