Skip to content

Commit 710fcd5

Browse files
committed
Support for large textures
Texture dimensions larger than SHRT_MAX (32767) were not supported by SwiftShader. Used integers instead of shorts to store texture sizes to increase the maximum texture size to INT_MAX (2147483647). Tests: dEQP-VK.memory.pipeline_barrier.host_write_uniform_texel_buffer.* Tests: dEQP-VK.memory.pipeline_barrier.transfer_dst_uniform_texel_buffer.* Bug b/133429305 Change-Id: I7913f5f4c1f933889e74c57851a837ad7982f87a Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/31989 Reviewed-by: Nicolas Capens <[email protected]> Tested-by: Alexis Hétu <[email protected]> Kokoro-Presubmit: kokoro <[email protected]>
1 parent 42232ab commit 710fcd5

File tree

4 files changed

+29
-45
lines changed

4 files changed

+29
-45
lines changed

src/Device/Sampler.hpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,12 @@ namespace sw
3131
{
3232
const void *buffer[6];
3333

34-
float4 fWidth;
35-
float4 fHeight;
36-
float4 fDepth;
37-
3834
short uHalf[4];
3935
short vHalf[4];
4036
short wHalf[4];
41-
short width[4];
42-
short height[4];
43-
short depth[4];
37+
int4 width;
38+
int4 height;
39+
int4 depth;
4440
short onePitchP[4];
4541
int4 pitchP;
4642
int4 sliceP;
@@ -154,6 +150,7 @@ namespace sw
154150
VkCompareOp compareOp;
155151
VkBorderColor border;
156152
bool unnormalizedCoordinates;
153+
bool largeTexture;
157154

158155
#if PERF_PROFILE
159156
bool compressedFormat;

src/Pipeline/SamplerCore.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ namespace sw
150150
bool force32BitFiltering = state.highPrecisionFiltering && !hasYuvFormat() && (state.textureFilter != FILTER_POINT);
151151
bool seamlessCube = (state.addressingModeU == ADDRESSING_SEAMLESS);
152152
bool use32BitFiltering = hasFloatTexture() || hasUnnormalizedIntegerTexture() || force32BitFiltering ||
153-
seamlessCube || state.unnormalizedCoordinates || state.compareEnable || borderModeActive();
153+
seamlessCube || state.unnormalizedCoordinates || state.compareEnable || state.largeTexture ||
154+
borderModeActive();
154155

155156
if(use32BitFiltering)
156157
{
@@ -448,8 +449,8 @@ namespace sw
448449
if(!gather) // Blend
449450
{
450451
// Fractions
451-
UShort4 f0u = As<UShort4>(uuuu0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
452-
UShort4 f0v = As<UShort4>(vvvv0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
452+
UShort4 f0u = As<UShort4>(uuuu0) * UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap,width)));
453+
UShort4 f0v = As<UShort4>(vvvv0) * UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap,height)));
453454

454455
UShort4 f1u = ~f0u;
455456
UShort4 f1v = ~f0v;
@@ -650,9 +651,9 @@ namespace sw
650651
}
651652

652653
// Fractions
653-
UShort4 f0u = As<UShort4>(u[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
654-
UShort4 f0v = As<UShort4>(v[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
655-
UShort4 f0s = As<UShort4>(s[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,depth));
654+
UShort4 f0u = As<UShort4>(u[0][0][0]) * UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap,width)));
655+
UShort4 f0v = As<UShort4>(v[0][0][0]) * UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap,height)));
656+
UShort4 f0s = As<UShort4>(s[0][0][0]) * UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap,depth)));
656657

657658
UShort4 f1u = ~f0u;
658659
UShort4 f1v = ~f0v;
@@ -1203,16 +1204,16 @@ namespace sw
12031204

12041205
if(!texelFetch)
12051206
{
1206-
uuuu = MulHigh(As<UShort4>(uuuu), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width)));
1207-
vvvv = MulHigh(As<UShort4>(vvvv), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height)));
1207+
uuuu = MulHigh(As<UShort4>(uuuu), UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap, width))));
1208+
vvvv = MulHigh(As<UShort4>(vvvv), UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap, height))));
12081209
}
12091210

12101211
if(hasOffset)
12111212
{
1212-
UShort4 w = *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width));
1213-
uuuu = applyOffset(uuuu, offset.x, Int4(w), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
1214-
UShort4 h = *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height));
1215-
vvvv = applyOffset(vvvv, offset.y, Int4(h), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
1213+
uuuu = applyOffset(uuuu, offset.x, *Pointer<Int4>(mipmap + OFFSET(Mipmap, width)),
1214+
texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
1215+
vvvv = applyOffset(vvvv, offset.y, *Pointer<Int4>(mipmap + OFFSET(Mipmap, height)),
1216+
texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
12161217
}
12171218

12181219
Short4 uuu2 = uuuu;
@@ -1227,13 +1228,13 @@ namespace sw
12271228
{
12281229
if(!texelFetch)
12291230
{
1230-
wwww = MulHigh(As<UShort4>(wwww), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth)));
1231+
wwww = MulHigh(As<UShort4>(wwww), UShort4(*Pointer<Int4>(mipmap + OFFSET(Mipmap, depth))));
12311232
}
12321233

12331234
if(hasOffset)
12341235
{
1235-
UShort4 d = *Pointer<UShort4>(mipmap + OFFSET(Mipmap, depth));
1236-
wwww = applyOffset(wwww, offset.z, Int4(d), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeW);
1236+
wwww = applyOffset(wwww, offset.z, *Pointer<Int4>(mipmap + OFFSET(Mipmap, depth)),
1237+
texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeW);
12371238
}
12381239
}
12391240

@@ -1255,10 +1256,10 @@ namespace sw
12551256

12561257
if(texelFetch)
12571258
{
1258-
Int size = Int(*Pointer<Int>(mipmap + OFFSET(Mipmap, sliceP)));
1259+
Int size = *Pointer<Int>(mipmap + OFFSET(Mipmap, sliceP));
12591260
if(hasThirdCoordinate())
12601261
{
1261-
size *= Int(*Pointer<Short>(mipmap + OFFSET(Mipmap, depth)));
1262+
size *= *Pointer<Int>(mipmap + OFFSET(Mipmap, depth));
12621263
}
12631264
UInt min = 0;
12641265
UInt max = size - 1;
@@ -1989,7 +1990,7 @@ namespace sw
19891990
}
19901991
else if(addressingMode == ADDRESSING_LAYER)
19911992
{
1992-
return Min(Max(Short4(RoundInt(uw)), Short4(0)), *Pointer<Short4>(mipmap + OFFSET(Mipmap, depth)) - Short4(1));
1993+
return Short4(Min(Max(RoundInt(uw), Int4(0)), *Pointer<Int4>(mipmap + OFFSET(Mipmap, depth)) - Int4(1)));
19931994
}
19941995
else if(addressingMode == ADDRESSING_CLAMP || addressingMode == ADDRESSING_BORDER)
19951996
{
@@ -2030,7 +2031,7 @@ namespace sw
20302031
return;
20312032
}
20322033

2033-
Int4 dim = Int4(*Pointer<Short4>(mipmap + whd, 16));
2034+
Int4 dim = *Pointer<Int4>(mipmap + whd, 16);
20342035
Int4 maxXYZ = dim - Int4(1);
20352036

20362037
if(function == Fetch)

src/Pipeline/SpirvShaderSampling.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <spirv/unified1/spirv.hpp>
2929
#include <spirv/unified1/GLSL.std.450.h>
3030

31+
#include <climits>
3132
#include <mutex>
3233

3334
namespace sw {
@@ -66,6 +67,9 @@ SpirvShader::ImageSampler *SpirvShader::getImageSampler(uint32_t inst, vk::Sampl
6667
samplerState.compareEnable = (sampler->compareEnable == VK_TRUE);
6768
samplerState.compareOp = sampler->compareOp;
6869
samplerState.unnormalizedCoordinates = (sampler->unnormalizedCoordinates == VK_TRUE);
70+
samplerState.largeTexture = (imageDescriptor->extent.width > SHRT_MAX) ||
71+
(imageDescriptor->extent.height > SHRT_MAX) ||
72+
(imageDescriptor->extent.depth > SHRT_MAX);
6973

7074
if(sampler->anisotropyEnable != VK_FALSE)
7175
{

src/Vulkan/VkDescriptorSetLayout.cpp

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
323323

324324
sw::Mipmap &mipmap = imageSampler[i].texture.mipmap[0];
325325
mipmap.buffer[0] = bufferView->getPointer();
326-
mipmap.width[0] = mipmap.width[1] = mipmap.width[2] = mipmap.width[3] = static_cast<short>(numElements);
326+
mipmap.width[0] = mipmap.width[1] = mipmap.width[2] = mipmap.width[3] = numElements;
327327
mipmap.height[0] = mipmap.height[1] = mipmap.height[2] = mipmap.height[3] = 1;
328328
mipmap.depth[0] = mipmap.depth[1] = mipmap.depth[2] = mipmap.depth[3] = 1;
329329
mipmap.pitchP.x = mipmap.pitchP.y = mipmap.pitchP.z = mipmap.pitchP.w = numElements;
@@ -419,24 +419,6 @@ void DescriptorSetLayout::WriteDescriptorSet(DescriptorSet *dstSet, VkDescriptor
419419
texture->depth[3] = depth;
420420
}
421421

422-
if(format.isFloatFormat())
423-
{
424-
mipmap.fWidth[0] = (float)width / 65536.0f;
425-
mipmap.fWidth[1] = (float)width / 65536.0f;
426-
mipmap.fWidth[2] = (float)width / 65536.0f;
427-
mipmap.fWidth[3] = (float)width / 65536.0f;
428-
429-
mipmap.fHeight[0] = (float)height / 65536.0f;
430-
mipmap.fHeight[1] = (float)height / 65536.0f;
431-
mipmap.fHeight[2] = (float)height / 65536.0f;
432-
mipmap.fHeight[3] = (float)height / 65536.0f;
433-
434-
mipmap.fDepth[0] = (float)depth / 65536.0f;
435-
mipmap.fDepth[1] = (float)depth / 65536.0f;
436-
mipmap.fDepth[2] = (float)depth / 65536.0f;
437-
mipmap.fDepth[3] = (float)depth / 65536.0f;
438-
}
439-
440422
short halfTexelU = 0x8000 / width;
441423
short halfTexelV = 0x8000 / height;
442424
short halfTexelW = 0x8000 / depth;

0 commit comments

Comments
 (0)