Commit 77980510 by Nicolas Capens

Deprecate handling power-of-two texture sampling separately.

NPOT texture sampling is slightly slower, but with OpenGL we were already treating every mipmapped texture as NPOT due to requiring padding at the 1x1 level for renderability. Seamless cube maps are also NPOT due to the border. Furthermore, the vector shifts by scalar required for POT texel address calculation would require 128-bit values when we deprecate MMX. Change-Id: Ie2e68f632bea7c6f3e599015c14be50392ea7e9a Reviewed-on: https://swiftshader-review.googlesource.com/8248Reviewed-by: 's avatarNicolas Capens <capn@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 84729949
...@@ -48,10 +48,6 @@ namespace sw ...@@ -48,10 +48,6 @@ namespace sw
{ {
mipmap.buffer[face] = &zero; mipmap.buffer[face] = &zero;
} }
mipmap.uFrac = 16;
mipmap.vFrac = 16;
mipmap.wFrac = 16;
} }
externalTextureFormat = FORMAT_NULL; externalTextureFormat = FORMAT_NULL;
...@@ -97,7 +93,6 @@ namespace sw ...@@ -97,7 +93,6 @@ namespace sw
state.addressingModeV = getAddressingModeV(); state.addressingModeV = getAddressingModeV();
state.addressingModeW = getAddressingModeW(); state.addressingModeW = getAddressingModeW();
state.mipmapFilter = mipmapFilter(); state.mipmapFilter = mipmapFilter();
state.hasNPOTTexture = hasNPOTTexture();
state.sRGB = sRGB && Surface::isSRGBreadable(externalTextureFormat); state.sRGB = sRGB && Surface::isSRGBreadable(externalTextureFormat);
state.swizzleR = swizzleR; state.swizzleR = swizzleR;
state.swizzleG = swizzleG; state.swizzleG = swizzleG;
...@@ -158,16 +153,7 @@ namespace sw ...@@ -158,16 +153,7 @@ namespace sw
texture.depthLOD[3] = depth * exp2LOD; texture.depthLOD[3] = depth * exp2LOD;
} }
if(!Surface::isFloatFormat(internalTextureFormat)) if(Surface::isFloatFormat(internalTextureFormat))
{
mipmap.uInt = logWidth;
mipmap.vInt = logHeight;
mipmap.wInt = logDepth;
mipmap.uFrac = 16 - logWidth;
mipmap.vFrac = 16 - logHeight;
mipmap.wFrac = 16 - logDepth;
}
else
{ {
mipmap.fWidth[0] = (float)width / 65536.0f; mipmap.fWidth[0] = (float)width / 65536.0f;
mipmap.fWidth[1] = (float)width / 65536.0f; mipmap.fWidth[1] = (float)width / 65536.0f;
...@@ -239,8 +225,6 @@ namespace sw ...@@ -239,8 +225,6 @@ namespace sw
mipmap.buffer[1] = (byte*)mipmap.buffer[0] + YSize; mipmap.buffer[1] = (byte*)mipmap.buffer[0] + YSize;
mipmap.buffer[2] = (byte*)mipmap.buffer[1] + CSize; mipmap.buffer[2] = (byte*)mipmap.buffer[1] + CSize;
texture.mipmap[1].uFrac = texture.mipmap[0].uFrac + 1;
texture.mipmap[1].vFrac = texture.mipmap[0].vFrac + 1;
texture.mipmap[1].width[0] = width / 2; texture.mipmap[1].width[0] = width / 2;
texture.mipmap[1].width[1] = width / 2; texture.mipmap[1].width[1] = width / 2;
texture.mipmap[1].width[2] = width / 2; texture.mipmap[1].width[2] = width / 2;
...@@ -420,24 +404,6 @@ namespace sw ...@@ -420,24 +404,6 @@ namespace sw
return MIPMAP_NONE; return MIPMAP_NONE;
} }
bool Sampler::hasNPOTTexture() const
{
if(textureType == TEXTURE_NULL)
{
return false;
}
for(int i = 0; i < MIPMAP_LEVELS; i++)
{
if(texture.mipmap[i].width[0] != texture.mipmap[i].onePitchP[1])
{
return true; // Shifting of the texture coordinates doesn't yield the correct address, so using multiply by pitch
}
}
return !isPow2(texture.mipmap[0].width[0]) || !isPow2(texture.mipmap[0].height[0]) || !isPow2(texture.mipmap[0].depth[0]);
}
TextureType Sampler::getTextureType() const TextureType Sampler::getTextureType() const
{ {
return textureType; return textureType;
......
...@@ -24,25 +24,9 @@ namespace sw ...@@ -24,25 +24,9 @@ namespace sw
{ {
const void *buffer[6]; const void *buffer[6];
union float4 fWidth;
{ float4 fHeight;
struct float4 fDepth;
{
int64_t uInt;
int64_t vInt;
int64_t wInt;
int64_t uFrac;
int64_t vFrac;
int64_t wFrac;
};
struct
{
float4 fWidth;
float4 fHeight;
float4 fDepth;
};
};
short uHalf[4]; short uHalf[4];
short vHalf[4]; short vHalf[4];
...@@ -150,7 +134,6 @@ namespace sw ...@@ -150,7 +134,6 @@ namespace sw
AddressingMode addressingModeV : BITS(ADDRESSING_LAST); AddressingMode addressingModeV : BITS(ADDRESSING_LAST);
AddressingMode addressingModeW : BITS(ADDRESSING_LAST); AddressingMode addressingModeW : BITS(ADDRESSING_LAST);
MipmapType mipmapFilter : BITS(FILTER_LAST); MipmapType mipmapFilter : BITS(FILTER_LAST);
bool hasNPOTTexture : 1;
bool sRGB : 1; bool sRGB : 1;
SwizzleType swizzleR : BITS(SWIZZLE_LAST); SwizzleType swizzleR : BITS(SWIZZLE_LAST);
SwizzleType swizzleG : BITS(SWIZZLE_LAST); SwizzleType swizzleG : BITS(SWIZZLE_LAST);
...@@ -201,7 +184,6 @@ namespace sw ...@@ -201,7 +184,6 @@ namespace sw
private: private:
MipmapType mipmapFilter() const; MipmapType mipmapFilter() const;
bool hasNPOTTexture() const;
TextureType getTextureType() const; TextureType getTextureType() const;
FilterType getTextureFilter() const; FilterType getTextureFilter() const;
AddressingMode getAddressingModeU() const; AddressingMode getAddressingModeU() const;
......
...@@ -820,19 +820,8 @@ namespace sw ...@@ -820,19 +820,8 @@ namespace sw
if(!gather) // Blend if(!gather) // Blend
{ {
// Fractions // Fractions
UShort4 f0u = uuuu0; UShort4 f0u = As<UShort4>(uuuu0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
UShort4 f0v = vvvv0; UShort4 f0v = As<UShort4>(vvvv0) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
if(!state.hasNPOTTexture)
{
f0u = f0u << *Pointer<Long1>(mipmap + OFFSET(Mipmap,uInt)); // .u
f0v = f0v << *Pointer<Long1>(mipmap + OFFSET(Mipmap,vInt)); // .v
}
else
{
f0u = f0u * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
f0v = f0v * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
}
UShort4 f1u = ~f0u; UShort4 f1u = ~f0u;
UShort4 f1v = ~f0v; UShort4 f1v = ~f0v;
...@@ -1029,29 +1018,17 @@ namespace sw ...@@ -1029,29 +1018,17 @@ namespace sw
} }
// Fractions // Fractions
UShort4 f[2][2][2]; UShort4 f0u = As<UShort4>(u[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
Short4 fs[2][2][2]; UShort4 f0v = As<UShort4>(v[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
UShort4 f0u; UShort4 f0s = As<UShort4>(s[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,depth));
UShort4 f0v;
UShort4 f0s;
if(!state.hasNPOTTexture)
{
f0u = As<UShort4>(u[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,uInt));
f0v = As<UShort4>(v[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,vInt));
f0s = As<UShort4>(s[0][0][0]) << *Pointer<Long1>(mipmap + OFFSET(Mipmap,wInt));
}
else
{
f0u = As<UShort4>(u[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,width));
f0v = As<UShort4>(v[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,height));
f0s = As<UShort4>(s[0][0][0]) * *Pointer<UShort4>(mipmap + OFFSET(Mipmap,depth));
}
UShort4 f1u = ~f0u; UShort4 f1u = ~f0u;
UShort4 f1v = ~f0v; UShort4 f1v = ~f0v;
UShort4 f1s = ~f0s; UShort4 f1s = ~f0s;
UShort4 f[2][2][2];
Short4 fs[2][2][2];
f[1][1][1] = MulHigh(f1u, f1v); f[1][1][1] = MulHigh(f1u, f1v);
f[0][1][1] = MulHigh(f0u, f1v); f[0][1][1] = MulHigh(f0u, f1v);
f[1][0][1] = MulHigh(f1u, f0v); f[1][0][1] = MulHigh(f1u, f0v);
...@@ -1699,44 +1676,26 @@ namespace sw ...@@ -1699,44 +1676,26 @@ namespace sw
void SamplerCore::computeIndices(Int index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function) void SamplerCore::computeIndices(Int index[4], Short4 uuuu, Short4 vvvv, Short4 wwww, Vector4f &offset, const Pointer<Byte> &mipmap, SamplerFunction function)
{ {
Short4 uuu2;
bool texelFetch = (function == Fetch); bool texelFetch = (function == Fetch);
bool hasOffset = (function.option == Offset); bool hasOffset = (function.option == Offset);
if(!state.hasNPOTTexture && !hasFloatTexture() && !hasOffset) if(!texelFetch)
{ {
if(!texelFetch) uuuu = MulHigh(As<UShort4>(uuuu), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width)));
{ vvvv = MulHigh(As<UShort4>(vvvv), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height)));
vvvv = As<UShort4>(vvvv) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, vFrac));
}
uuu2 = uuuu;
uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
if(!texelFetch)
{
uuuu = As<Short4>(As<UInt2>(uuuu) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, uFrac)));
uuu2 = As<Short4>(As<UInt2>(uuu2) >> *Pointer<Long1>(mipmap + OFFSET(Mipmap, uFrac)));
}
} }
else
if(hasOffset)
{ {
if(!texelFetch) uuuu = applyOffset(uuuu, offset.x, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, width))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
{ vvvv = applyOffset(vvvv, offset.y, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, height))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
uuuu = MulHigh(As<UShort4>(uuuu), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, width)));
vvvv = MulHigh(As<UShort4>(vvvv), *Pointer<UShort4>(mipmap + OFFSET(Mipmap, height)));
}
if(hasOffset)
{
uuuu = applyOffset(uuuu, offset.x, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, width))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeU);
vvvv = applyOffset(vvvv, offset.y, Int4(*Pointer<UShort4>(mipmap + OFFSET(Mipmap, height))), texelFetch ? ADDRESSING_TEXELFETCH : state.addressingModeV);
}
uuu2 = uuuu;
uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
uuuu = As<Short4>(MulAdd(uuuu, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
uuu2 = As<Short4>(MulAdd(uuu2, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
} }
Short4 uuu2 = uuuu;
uuuu = As<Short4>(UnpackLow(uuuu, vvvv));
uuu2 = As<Short4>(UnpackHigh(uuu2, vvvv));
uuuu = As<Short4>(MulAdd(uuuu, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
uuu2 = As<Short4>(MulAdd(uuu2, *Pointer<Short4>(mipmap + OFFSET(Mipmap,onePitchP))));
if((state.textureType == TEXTURE_3D) || (state.textureType == TEXTURE_2D_ARRAY)) if((state.textureType == TEXTURE_3D) || (state.textureType == TEXTURE_2D_ARRAY))
{ {
......
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