Skip to content

Commit 1c462eb

Browse files
committed
Stencil buffer texture sampling
In order to perform a blitFramebuffer operation, ANGLE uses a compute shader which reads the stencil from a depth+stencil image to a buffer, and then copies this buffer to the stencil of the other image. This cl basically treats VK_FORMAT_S8_UINT as VK_FORMAT_R8_UINT with quad layout for the purpose of texture sampling. Fixes the following tests: dEQP-GLES3.functional.fbo.blit.depth_stencil.depth32f_stencil8_basic dEQP-GLES3.functional.fbo.blit.depth_stencil.depth32f_stencil8_stencil_only dEQP-GLES3.functional.fbo.blit.depth_stencil.depth24_stencil8_basic dEQP-GLES3.functional.fbo.blit.depth_stencil.depth24_stencil8_stencil_only Bug: b/142385547 Change-Id: Ib2ea7fa81496ceca1c24ea7f065b1c2cd05596ee Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/37188 Presubmit-Ready: Alexis Hétu <sugoi@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Antonio Maiorano <amaiorano@google.com>
1 parent ae022fa commit 1c462eb

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

src/Device/Blitter.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ namespace sw
10321032
case VK_FORMAT_R8G8_UINT:
10331033
c = Insert(c, Int(*Pointer<Byte>(element + 1)), 1);
10341034
case VK_FORMAT_R8_UINT:
1035+
case VK_FORMAT_S8_UINT:
10351036
c = Insert(c, Int(*Pointer<Byte>(element)), 0);
10361037
break;
10371038
case VK_FORMAT_R16G16B16A16_SINT:
@@ -1090,6 +1091,7 @@ namespace sw
10901091
case VK_FORMAT_R8G8B8_USCALED:
10911092
case VK_FORMAT_R8G8_USCALED:
10921093
case VK_FORMAT_R8_USCALED:
1094+
case VK_FORMAT_S8_UINT:
10931095
c = Min(As<UInt4>(c), UInt4(0xFF));
10941096
break;
10951097
case VK_FORMAT_R16G16B16A16_UINT:
@@ -1215,6 +1217,7 @@ namespace sw
12151217
if(writeG) { *Pointer<Byte>(element + 1) = Byte(Extract(c, 1)); }
12161218
case VK_FORMAT_R8_UINT:
12171219
case VK_FORMAT_R8_USCALED:
1220+
case VK_FORMAT_S8_UINT:
12181221
if(writeR) { *Pointer<Byte>(element) = Byte(Extract(c, 0)); }
12191222
break;
12201223
case VK_FORMAT_R16G16B16A16_SINT:
@@ -1358,7 +1361,7 @@ namespace sw
13581361
{
13591362
// (x & ~1) * 2 + (x & 1) == (x - (x & 1)) * 2 + (x & 1) == x * 2 - (x & 1) * 2 + (x & 1) == x * 2 - (x & 1)
13601363
return (y & Int(~1)) * pitchB +
1361-
((y & Int(1)) * 2 + x * 2 - (x & Int(1))) * bytes;
1364+
((((y & Int(1)) + x) << 1) - (x & Int(1))) * bytes;
13621365
}
13631366
}
13641367

src/Pipeline/SamplerCore.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ namespace
4545
default: ASSERT(false);
4646
}
4747
}
48+
49+
template <typename T>
50+
void applyQuadLayout(T& x, T& y)
51+
{
52+
x = (((y & T(1)) + x) << 1) - (x & T(1));
53+
y &= T(~1);
54+
}
4855
}
4956

5057
namespace sw
@@ -895,6 +902,11 @@ namespace sw
895902
address(v, y0, y1, fv, mipmap, offset.y, filter, OFFSET(Mipmap, height), state.addressingModeV, function);
896903
address(w, z0, z0, fw, mipmap, offset.z, filter, OFFSET(Mipmap, depth), state.addressingModeW, function);
897904

905+
if(hasQuadLayout())
906+
{
907+
::applyQuadLayout(x0, y0);
908+
}
909+
898910
Int4 pitchP = *Pointer<Int4>(mipmap + OFFSET(Mipmap, pitchP), 16);
899911
y0 *= pitchP;
900912
if(state.addressingModeW != ADDRESSING_UNUSED)
@@ -908,6 +920,11 @@ namespace sw
908920
}
909921
else
910922
{
923+
if(hasQuadLayout())
924+
{
925+
::applyQuadLayout(x1, y1);
926+
}
927+
911928
y1 *= pitchP;
912929

913930
Vector4f c00 = sampleTexel(x0, y0, z0, q, mipmap, buffer, function);
@@ -971,6 +988,11 @@ namespace sw
971988
address(v, y0, y1, fv, mipmap, offset.y, filter, OFFSET(Mipmap, height), state.addressingModeV, function);
972989
address(w, z0, z1, fw, mipmap, offset.z, filter, OFFSET(Mipmap, depth), state.addressingModeW, function);
973990

991+
if(hasQuadLayout())
992+
{
993+
::applyQuadLayout(x0, y0);
994+
}
995+
974996
Int4 pitchP = *Pointer<Int4>(mipmap + OFFSET(Mipmap, pitchP), 16);
975997
Int4 sliceP = *Pointer<Int4>(mipmap + OFFSET(Mipmap, sliceP), 16);
976998
y0 *= pitchP;
@@ -982,6 +1004,11 @@ namespace sw
9821004
}
9831005
else
9841006
{
1007+
if(hasQuadLayout())
1008+
{
1009+
::applyQuadLayout(x1, y1);
1010+
}
1011+
9851012
y1 *= pitchP;
9861013
z1 *= sliceP;
9871014

@@ -1280,6 +1307,11 @@ namespace sw
12801307
texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
12811308
}
12821309

1310+
if(hasQuadLayout())
1311+
{
1312+
::applyQuadLayout(uuuu, vvvv);
1313+
}
1314+
12831315
Short4 uuu2 = uuuu;
12841316
uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
12851317
uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
@@ -1491,6 +1523,7 @@ namespace sw
14911523
{
14921524
case VK_FORMAT_R8_SINT:
14931525
case VK_FORMAT_R8_UINT:
1526+
case VK_FORMAT_S8_UINT:
14941527
{
14951528
Int zero(0);
14961529
c.x = Unpack(As<Byte4>(c0), As<Byte4>(zero));
@@ -2386,6 +2419,11 @@ namespace sw
23862419
return state.textureFormat.has32bitIntegerTextureComponents();
23872420
}
23882421

2422+
bool SamplerCore::hasQuadLayout() const
2423+
{
2424+
return state.textureFormat.hasQuadLayout();
2425+
}
2426+
23892427
bool SamplerCore::isYcbcrFormat() const
23902428
{
23912429
return state.textureFormat.isYcbcrFormat();

src/Pipeline/SamplerCore.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ namespace sw
104104
bool has8bitTextureComponents() const;
105105
bool has16bitTextureComponents() const;
106106
bool has32bitIntegerTextureComponents() const;
107+
bool hasQuadLayout() const;
107108
bool isYcbcrFormat() const;
108109
bool isRGBComponent(int component) const;
109110
bool borderModeActive() const;

src/Vulkan/VkFormat.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ bool Format::isUnsignedNonNormalizedInteger() const
127127
case VK_FORMAT_R64G64_UINT:
128128
case VK_FORMAT_R64G64B64_UINT:
129129
case VK_FORMAT_R64G64B64A64_UINT:
130+
case VK_FORMAT_S8_UINT:
130131
return true;
131132
default:
132133
return false;
@@ -1978,6 +1979,7 @@ bool Format::has16bitTextureFormat() const
19781979
case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
19791980
case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
19801981
case VK_FORMAT_D16_UNORM:
1982+
case VK_FORMAT_S8_UINT:
19811983
return false;
19821984
default:
19831985
UNIMPLEMENTED("Format: %d", int(format));
@@ -2009,6 +2011,7 @@ bool Format::has8bitTextureComponents() const
20092011
case VK_FORMAT_R8G8_UINT:
20102012
case VK_FORMAT_R8G8B8A8_SINT:
20112013
case VK_FORMAT_R8G8B8A8_UINT:
2014+
case VK_FORMAT_S8_UINT:
20122015
return true;
20132016
case VK_FORMAT_A1R5G5B5_UNORM_PACK16:
20142017
case VK_FORMAT_B4G4R4A4_UNORM_PACK16:
@@ -2092,6 +2095,7 @@ bool Format::has16bitTextureComponents() const
20922095
case VK_FORMAT_A2B10G10R10_UINT_PACK32:
20932096
case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
20942097
case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
2098+
case VK_FORMAT_S8_UINT:
20952099
return false;
20962100
case VK_FORMAT_R16_UNORM:
20972101
case VK_FORMAT_R16_SNORM:
@@ -2166,6 +2170,7 @@ bool Format::has32bitIntegerTextureComponents() const
21662170
case VK_FORMAT_E5B9G9R9_UFLOAT_PACK32:
21672171
case VK_FORMAT_B10G11R11_UFLOAT_PACK32:
21682172
case VK_FORMAT_D16_UNORM:
2173+
case VK_FORMAT_S8_UINT:
21692174
return false;
21702175
case VK_FORMAT_R32_SINT:
21712176
case VK_FORMAT_R32_UINT:
@@ -2239,6 +2244,7 @@ bool Format::isRGBComponent(int component) const
22392244
return component < 3;
22402245
case VK_FORMAT_D32_SFLOAT:
22412246
case VK_FORMAT_D16_UNORM:
2247+
case VK_FORMAT_S8_UINT:
22422248
return false;
22432249
default:
22442250
UNIMPLEMENTED("Format: %d", int(format));

0 commit comments

Comments
 (0)