Fix handling of S8 multisampled textures. Closes #2883

This commit is contained in:
baldurk
2023-03-14 16:32:06 +00:00
parent 31d5fa9eb3
commit 38afb7c8ad
10 changed files with 295 additions and 71 deletions
+1
View File
@@ -108,6 +108,7 @@ precision highp int;
#define SHADER_D24_UNORM_S8_UINT 3
#define SHADER_D32_SFLOAT 4
#define SHADER_D32_SFLOAT_S8_UINT 5
#define SHADER_S8_UINT 6
// divide MS<->buffer workgroups by 64
#define MS_DISPATCH_LOCAL_SIZE 64
+20
View File
@@ -102,6 +102,26 @@ void main()
uint stencilData = srcData[idx * 2 + 1];
stencil = stencilData & 0xFF;
}
else if(format == SHADER_S8_UINT)
{
uint stencilData = srcData[idx / 4];
if((idx % 4) == 0)
{
stencil = stencilData & 0x000000FF;
}
else if((idx % 4) == 1)
{
stencil = (stencilData & 0x0000FF00) >> 8;
}
else if((idx % 4) == 2)
{
stencil = (stencilData & 0x00FF0000) >> 16;
}
else
{
stencil = (stencilData & 0xFF000000) >> 24;
}
}
if(currentStencil < 256u)
{
@@ -115,4 +115,24 @@ void main()
result[dispatchOffset + (idx * 2 + 0)] = floatBitsToUint(depth);
result[dispatchOffset + (idx * 2 + 1)] = stencil;
}
// For S8, we need to sample 4 pixels at a time
else if(format == SHADER_S8_UINT)
{
int pxIdx = int(idx * 4);
int x0 = (pxIdx + 0) % textureWidth;
int y0 = (pxIdx + 0) / textureWidth;
int x1 = (pxIdx + 1) % textureWidth;
int y1 = (pxIdx + 1) / textureWidth;
int x2 = (pxIdx + 2) % textureWidth;
int y2 = (pxIdx + 2) / textureWidth;
int x3 = (pxIdx + 3) % textureWidth;
int y3 = (pxIdx + 3) / textureWidth;
uvec4 stencil = uvec4(texelFetch(srcStencilMS, ivec3(x0, y0, slice), sampleIdx).x,
texelFetch(srcStencilMS, ivec3(x1, y1, slice), sampleIdx).x,
texelFetch(srcStencilMS, ivec3(x2, y2, slice), sampleIdx).x,
texelFetch(srcStencilMS, ivec3(x3, y3, slice), sampleIdx).x);
result[dispatchOffset + idx] = ((stencil.x & 0xFF) << 0) | ((stencil.y & 0xFF) << 8) |
((stencil.z & 0xFF) << 16) | ((stencil.w & 0xFF) << 24);
}
}