summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-08-10 14:59:05 -0700
committerGitHub <noreply@github.com>2023-08-10 14:59:05 -0700
commit756fdb450739c9ac9aaf54a8d7a4def7408975ca (patch)
treecb226dc510584e455430b6e8d2ab791a0e686c07
parent38b0af3537f5d8412f0d69e39e38c5603ff62c15 (diff)
Fix `Texture2D.Load()` with offset. (#3094)
Co-authored-by: Yong He <yhe@nvidia.com>
-rw-r--r--source/slang/core.meta.slang6
-rw-r--r--tests/bugs/gh-3085.slang29
-rw-r--r--tests/bugs/texture-array-samplecmplevelzero.slang23
3 files changed, 56 insertions, 2 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang
index efd0a743c..257d5930b 100644
--- a/source/slang/core.meta.slang
+++ b/source/slang/core.meta.slang
@@ -1641,7 +1641,9 @@ struct TextureTypeInfo
}
sb << ");\n";
+
// GLSL
+ glslFuncName = (access == SLANG_RESOURCE_ACCESS_READ) ? "texelFetchOffset" : "imageLoad";
if (isMultisample)
{
sb << "__glsl_extension(GL_EXT_samplerless_texture_functions)";
@@ -1654,12 +1656,12 @@ struct TextureTypeInfo
if( needsMipLevel )
{
sb << "($1)." << kGLSLLoadCoordsSwizzle[loadCoordCount] << ", ($1)." << kGLSLLoadLODSwizzle[loadCoordCount];
+ sb << ", $2)$z\")\n";
}
else
{
- sb << "$1, 0";
+ sb << "$1, 0, $2)$z\")\n";
}
- sb << ", $2)$z\")\n";
}
if (isReadOnly)
diff --git a/tests/bugs/gh-3085.slang b/tests/bugs/gh-3085.slang
new file mode 100644
index 000000000..9250d501d
--- /dev/null
+++ b/tests/bugs/gh-3085.slang
@@ -0,0 +1,29 @@
+//TEST:SIMPLE(filecheck=CHECK): -entry MainCs -stage compute -profile glsl_450 -target spirv
+//CHECK: EntryPoint
+
+RWTexture2D<float4> g_Test;
+
+Texture2D<float4> g_inoutColorReadonly;
+
+[ForceInline] float3 LoadSourceColor(uint2 pixelPos, constexpr int2 offset, int sampleIndex)
+{
+ float3 color = g_inoutColorReadonly.Load(int3(pixelPos, 0), offset).rgb;
+
+ return color;
+}
+
+[numthreads(16, 16, 1)]
+void MainCs(uint3 groupID: SV_GroupID, uint3 groupThreadID: SV_GroupThreadID)
+{
+
+ uint2 pixelPos = groupID.xy * int2((16 - 2), (16 - 2)) + groupThreadID.xy - int2(1, 1);
+ float3 color = LoadSourceColor(pixelPos, int2(0, 0), 0).rgb;
+
+ // Note this also doesn't work
+ //[unroll]
+ // for ( int i = 0; i < 3; i++ )
+ //{
+ // color+= LoadSourceColor ( pixelPos , int2 ( i%3 , i/3 ) , msaaSampleIndex ) . rgb ;
+ //}
+ g_Test[int2(pixelPos.x / 2, pixelPos.y + 0)] = float4(color, 1.0);
+} \ No newline at end of file
diff --git a/tests/bugs/texture-array-samplecmplevelzero.slang b/tests/bugs/texture-array-samplecmplevelzero.slang
new file mode 100644
index 000000000..6176f74dc
--- /dev/null
+++ b/tests/bugs/texture-array-samplecmplevelzero.slang
@@ -0,0 +1,23 @@
+//TEST_DISABLED:SIMPLE(filecheck=CHECK): -entry MainPs -stage fragment -profile glsl_450 -target spirv
+//CHECK: EntryPoint
+
+SamplerComparisonState g_tSFMShadowDepthTexture_sampler;
+Texture2DArray g_tSFMShadowDepthTexture;
+
+struct PS_INPUT
+{
+ float3 vTexCoord : TEXCOORD0;
+};
+
+struct PS_OUTPUT
+{
+ float4 vColor : SV_Target0;
+};
+
+PS_OUTPUT MainPs ( PS_INPUT i )
+{
+ PS_OUTPUT o;
+ float flDepth = 0.5;
+ o.vColor = g_tSFMShadowDepthTexture.SampleCmpLevelZero ( g_tSFMShadowDepthTexture_sampler, i.vTexCoord.xyz, flDepth ).rrrr;
+ return o;
+} \ No newline at end of file