Commit 3b96fa85 by Alexis Hetu Committed by Nicolas Capens

Fix array texture LOD computation.

2D array textures use 2D LOD calculations, not 3D. Change-Id: I0ce834bc4afb63dfeba3d9662105ffdaa07028da Reviewed-on: https://swiftshader-review.googlesource.com/4716Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent c8b97857
......@@ -62,9 +62,6 @@ namespace sw
}
#endif
bool cubeTexture = state.textureType == TEXTURE_CUBE;
bool volumeTexture = state.textureType == TEXTURE_3D || state.textureType == TEXTURE_2D_ARRAY;
Float4 uuuu = u;
Float4 vvvv = v;
Float4 wwww = w;
......@@ -90,7 +87,7 @@ namespace sw
Float4 lodU;
Float4 lodV;
if(cubeTexture)
if(state.textureType == TEXTURE_CUBE)
{
cubeFace(face, uuuu, vvvv, lodU, lodV, u, v, w);
}
......@@ -100,9 +97,9 @@ namespace sw
Float4 uDelta;
Float4 vDelta;
if(!volumeTexture)
if(state.textureType != TEXTURE_3D)
{
if(!cubeTexture)
if(state.textureType != TEXTURE_CUBE)
{
computeLod(texture, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, q.x, dsx, dsy, bias, gradients, lodProvided);
}
......@@ -116,7 +113,7 @@ namespace sw
computeLod3D(texture, lod, uuuu, vvvv, wwww, q.x, dsx, dsy, bias, gradients, lodProvided);
}
if(cubeTexture)
if(state.textureType == TEXTURE_CUBE)
{
uuuu += Float4(0.5f);
vvvv += Float4(0.5f);
......@@ -301,9 +298,6 @@ namespace sw
}
#endif
bool cubeTexture = state.textureType == TEXTURE_CUBE;
bool volumeTexture = state.textureType == TEXTURE_3D || state.textureType == TEXTURE_2D_ARRAY;
if(state.textureType == TEXTURE_NULL)
{
c.x = Float4(0.0f);
......@@ -323,7 +317,7 @@ namespace sw
Float4 lodU;
Float4 lodV;
if(cubeTexture)
if(state.textureType == TEXTURE_CUBE)
{
cubeFace(face, uuuu, vvvv, lodU, lodV, u, v, w);
}
......@@ -333,9 +327,9 @@ namespace sw
Float4 uDelta;
Float4 vDelta;
if(!volumeTexture)
if(state.textureType != TEXTURE_3D)
{
if(!cubeTexture)
if(state.textureType != TEXTURE_CUBE)
{
computeLod(texture, lod, anisotropy, uDelta, vDelta, uuuu, vvvv, q.x, dsx, dsy, bias, gradients, lodProvided);
}
......@@ -349,7 +343,7 @@ namespace sw
computeLod3D(texture, lod, uuuu, vvvv, wwww, q.x, dsx, dsy, bias, gradients, lodProvided);
}
if(cubeTexture)
if(state.textureType == TEXTURE_CUBE)
{
uuuu += Float4(0.5f);
vvvv += Float4(0.5f);
......@@ -590,8 +584,6 @@ namespace sw
void SamplerCore::sampleFilter(Pointer<Byte> &texture, Vector4s &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool lodProvided)
{
bool volumeTexture = state.textureType == TEXTURE_3D || state.textureType == TEXTURE_2D_ARRAY;
sampleAniso(texture, c, u, v, w, lod, anisotropy, uDelta, vDelta, face, false, lodProvided);
if(state.mipmapFilter > MIPMAP_POINT)
......@@ -617,12 +609,12 @@ namespace sw
if(hasUnsignedTextureComponent(1)) c.y = MulHigh(As<UShort4>(c.y), utri); else c.y = MulHigh(c.y, stri);
if(hasUnsignedTextureComponent(2)) c.z = MulHigh(As<UShort4>(c.z), utri); else c.z = MulHigh(c.z, stri);
if(hasUnsignedTextureComponent(3)) c.w = MulHigh(As<UShort4>(c.w), utri); else c.w = MulHigh(c.w, stri);
c.x += cc.x;
c.y += cc.y;
c.z += cc.z;
c.w += cc.w;
if(!hasUnsignedTextureComponent(0)) c.x += c.x;
if(!hasUnsignedTextureComponent(1)) c.y += c.y;
if(!hasUnsignedTextureComponent(2)) c.z += c.z;
......@@ -634,7 +626,7 @@ namespace sw
if(state.addressingModeU == ADDRESSING_BORDER)
{
Short4 u0;
border(u0, u);
borderMask = u0;
......@@ -643,7 +635,7 @@ namespace sw
if(state.addressingModeV == ADDRESSING_BORDER)
{
Short4 v0;
border(v0, v);
if(state.addressingModeU == ADDRESSING_BORDER)
......@@ -656,7 +648,7 @@ namespace sw
}
}
if(state.addressingModeW == ADDRESSING_BORDER && volumeTexture)
if(state.addressingModeW == ADDRESSING_BORDER && state.textureType == TEXTURE_3D)
{
Short4 s0;
......@@ -675,7 +667,7 @@ namespace sw
if(state.addressingModeU == ADDRESSING_BORDER ||
state.addressingModeV == ADDRESSING_BORDER ||
(state.addressingModeW == ADDRESSING_BORDER && volumeTexture))
(state.addressingModeW == ADDRESSING_BORDER && state.textureType == TEXTURE_3D))
{
Short4 b;
......@@ -799,13 +791,13 @@ namespace sw
sampleTexel(c1, uuuu1, vvvv0, wwww, mipmap, buffer);
sampleTexel(c2, uuuu0, vvvv1, wwww, mipmap, buffer);
sampleTexel(c3, uuuu1, vvvv1, wwww, mipmap, buffer);
if(!gather) // Blend
{
// Fractions
UShort4 f0u = uuuu0;
UShort4 f0v = vvvv0;
if(!state.hasNPOTTexture)
{
f0u = f0u << *Pointer<Long1>(mipmap + OFFSET(Mipmap,uInt)); // .u
......@@ -819,7 +811,7 @@ namespace sw
UShort4 f1u = ~f0u;
UShort4 f1v = ~f0v;
UShort4 f0u0v = MulHigh(f0u, f0v);
UShort4 f1u0v = MulHigh(f1u, f0v);
UShort4 f0u1v = MulHigh(f0u, f1v);
......@@ -977,7 +969,7 @@ namespace sw
Pointer<Byte> mipmap;
Pointer<Byte> buffer[4];
Int face[4];
selectMipmap(texture, buffer, mipmap, lod, face, secondLOD);
Short4 uuuu;
......@@ -1107,8 +1099,6 @@ namespace sw
void SamplerCore::sampleFloatFilter(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Float &anisotropy, Float4 &uDelta, Float4 &vDelta, Int face[4], bool lodProvided)
{
bool volumeTexture = state.textureType == TEXTURE_3D || state.textureType == TEXTURE_2D_ARRAY;
sampleFloatAniso(texture, c, u, v, w, lod, anisotropy, uDelta, vDelta, face, false, lodProvided);
if(state.mipmapFilter > MIPMAP_POINT)
......@@ -1130,7 +1120,7 @@ namespace sw
if(state.addressingModeU == ADDRESSING_BORDER)
{
Int4 u0;
border(u0, u);
borderMask = u0;
......@@ -1139,7 +1129,7 @@ namespace sw
if(state.addressingModeV == ADDRESSING_BORDER)
{
Int4 v0;
border(v0, v);
if(state.addressingModeU == ADDRESSING_BORDER)
......@@ -1152,7 +1142,7 @@ namespace sw
}
}
if(state.addressingModeW == ADDRESSING_BORDER && volumeTexture)
if(state.addressingModeW == ADDRESSING_BORDER && state.textureType == TEXTURE_3D)
{
Int4 s0;
......@@ -1171,7 +1161,7 @@ namespace sw
if(state.addressingModeU == ADDRESSING_BORDER ||
state.addressingModeV == ADDRESSING_BORDER ||
(state.addressingModeW == ADDRESSING_BORDER && volumeTexture))
(state.addressingModeW == ADDRESSING_BORDER && state.textureType == TEXTURE_3D))
{
Int4 b;
......@@ -1247,7 +1237,7 @@ namespace sw
sampleFloat3D(texture, c, u, v, w, lod, secondLOD);
}
}
void SamplerCore::sampleFloat2D(Pointer<Byte> &texture, Vector4f &c, Float4 &u, Float4 &v, Float4 &w, Float &lod, Int face[4], bool secondLOD)
{
int componentCount = textureComponentCount();
......@@ -1255,7 +1245,7 @@ namespace sw
Pointer<Byte> mipmap;
Pointer<Byte> buffer[4];
selectMipmap(texture, buffer, mipmap, lod, face, secondLOD);
Short4 uuuu;
......@@ -1289,7 +1279,7 @@ namespace sw
Short4 uuuu1 = offsetSample(uuuu, mipmap, OFFSET(Mipmap,uHalf), state.addressingModeU == ADDRESSING_WRAP, gather ? 2 : +1);
Short4 vvvv1 = offsetSample(vvvv, mipmap, OFFSET(Mipmap,vHalf), state.addressingModeV == ADDRESSING_WRAP, gather ? 2 : +1);
sampleTexel(c0, uuuu0, vvvv0, wwww, w, mipmap, buffer);
sampleTexel(c0, uuuu0, vvvv0, wwww, w, mipmap, buffer);
sampleTexel(c1, uuuu1, vvvv0, wwww, w, mipmap, buffer);
sampleTexel(c2, uuuu0, vvvv1, wwww, w, mipmap, buffer);
sampleTexel(c3, uuuu1, vvvv1, wwww, w, mipmap, buffer);
......@@ -1433,7 +1423,7 @@ namespace sw
{
Float4 dudxy = Float4(dsx.x.xx, dsy.x.xx);
Float4 dvdxy = Float4(dsx.y.xx, dsy.y.xx);
duvdxy = Float4(dudxy.xz, dvdxy.xz);
}
......@@ -1603,7 +1593,7 @@ namespace sw
// M = xyz * x + yzx * y + zxy * z
Float4 M = As<Float4>((xyz & As<Int4>(x)) | (yzx & As<Int4>(y)) | (zxy & As<Int4>(z)));
M = reciprocal(M);
U *= M * Float4(0.5f);
V *= M * Float4(0.5f);
......@@ -1624,7 +1614,7 @@ namespace sw
// M = xyz * x + yzx * y + zxy * z
Float4 M = As<Float4>((xyz & As<Int4>(x)) | (yzx & As<Int4>(y)) | (zxy & As<Int4>(z)));
M = Rcp_pp(M);
lodU *= M * Float4(0.5f);
lodV *= M * Float4(0.5f);
......@@ -1717,7 +1707,7 @@ namespace sw
Byte8 c3 = *Pointer<Byte8>(buffer[f3] + 4 * index[3]);
c.x = UnpackLow(c0, c1);
c.y = UnpackLow(c2, c3);
switch(state.textureFormat)
{
case FORMAT_A8R8G8B8:
......@@ -2241,7 +2231,7 @@ namespace sw
default:
ASSERT(false);
}
return false;
}
......@@ -2311,7 +2301,7 @@ namespace sw
default:
ASSERT(false);
}
return false;
}
......@@ -2381,7 +2371,7 @@ namespace sw
default:
ASSERT(false);
}
return false;
}
......@@ -2451,7 +2441,7 @@ namespace sw
default:
ASSERT(false);
}
return false;
}
......@@ -2519,7 +2509,7 @@ namespace sw
default:
ASSERT(false);
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment