Commit d43f4cec by Nicolas Capens

Add utility function for 16-bit texture formats.

Bug 20891368 Change-Id: I6fb0ed00b903fe86c3b5c730842d28e9c212e04e Reviewed-on: https://swiftshader-review.googlesource.com/3100Reviewed-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 e1a50af5
...@@ -626,7 +626,7 @@ namespace sw ...@@ -626,7 +626,7 @@ namespace sw
// Bilinear interpolation // Bilinear interpolation
if(componentCount >= 1) if(componentCount >= 1)
{ {
if(has16bitTexture() && hasUnsignedTextureComponent(0)) if(has16bitTextureComponents() && hasUnsignedTextureComponent(0))
{ {
c0.x = As<UShort4>(c0.x) - MulHigh(As<UShort4>(c0.x), f0u) + MulHigh(As<UShort4>(c1.x), f0u); c0.x = As<UShort4>(c0.x) - MulHigh(As<UShort4>(c0.x), f0u) + MulHigh(As<UShort4>(c1.x), f0u);
c2.x = As<UShort4>(c2.x) - MulHigh(As<UShort4>(c2.x), f0u) + MulHigh(As<UShort4>(c3.x), f0u); c2.x = As<UShort4>(c2.x) - MulHigh(As<UShort4>(c2.x), f0u) + MulHigh(As<UShort4>(c3.x), f0u);
...@@ -656,7 +656,7 @@ namespace sw ...@@ -656,7 +656,7 @@ namespace sw
if(componentCount >= 2) if(componentCount >= 2)
{ {
if(has16bitTexture() && hasUnsignedTextureComponent(1)) if(has16bitTextureComponents() && hasUnsignedTextureComponent(1))
{ {
c0.y = As<UShort4>(c0.y) - MulHigh(As<UShort4>(c0.y), f0u) + MulHigh(As<UShort4>(c1.y), f0u); c0.y = As<UShort4>(c0.y) - MulHigh(As<UShort4>(c0.y), f0u) + MulHigh(As<UShort4>(c1.y), f0u);
c2.y = As<UShort4>(c2.y) - MulHigh(As<UShort4>(c2.y), f0u) + MulHigh(As<UShort4>(c3.y), f0u); c2.y = As<UShort4>(c2.y) - MulHigh(As<UShort4>(c2.y), f0u) + MulHigh(As<UShort4>(c3.y), f0u);
...@@ -686,7 +686,7 @@ namespace sw ...@@ -686,7 +686,7 @@ namespace sw
if(componentCount >= 3) if(componentCount >= 3)
{ {
if(has16bitTexture() && hasUnsignedTextureComponent(2)) if(has16bitTextureComponents() && hasUnsignedTextureComponent(2))
{ {
c0.z = As<UShort4>(c0.z) - MulHigh(As<UShort4>(c0.z), f0u) + MulHigh(As<UShort4>(c1.z), f0u); c0.z = As<UShort4>(c0.z) - MulHigh(As<UShort4>(c0.z), f0u) + MulHigh(As<UShort4>(c1.z), f0u);
c2.z = As<UShort4>(c2.z) - MulHigh(As<UShort4>(c2.z), f0u) + MulHigh(As<UShort4>(c3.z), f0u); c2.z = As<UShort4>(c2.z) - MulHigh(As<UShort4>(c2.z), f0u) + MulHigh(As<UShort4>(c3.z), f0u);
...@@ -716,7 +716,7 @@ namespace sw ...@@ -716,7 +716,7 @@ namespace sw
if(componentCount >= 4) if(componentCount >= 4)
{ {
if(has16bitTexture() && hasUnsignedTextureComponent(3)) if(has16bitTextureComponents() && hasUnsignedTextureComponent(3))
{ {
c0.w = As<UShort4>(c0.w) - MulHigh(As<UShort4>(c0.w), f0u) + MulHigh(As<UShort4>(c1.w), f0u); c0.w = As<UShort4>(c0.w) - MulHigh(As<UShort4>(c0.w), f0u) + MulHigh(As<UShort4>(c1.w), f0u);
c2.w = As<UShort4>(c2.w) - MulHigh(As<UShort4>(c2.w), f0u) + MulHigh(As<UShort4>(c3.w), f0u); c2.w = As<UShort4>(c2.w) - MulHigh(As<UShort4>(c2.w), f0u) + MulHigh(As<UShort4>(c3.w), f0u);
...@@ -1475,13 +1475,12 @@ namespace sw ...@@ -1475,13 +1475,12 @@ namespace sw
int f2 = state.textureType == TEXTURE_CUBE ? 2 : 0; int f2 = state.textureType == TEXTURE_CUBE ? 2 : 0;
int f3 = state.textureType == TEXTURE_CUBE ? 3 : 0; int f3 = state.textureType == TEXTURE_CUBE ? 3 : 0;
if(!has16bitTexture()) if(has16bitTextureFormat())
{
UNIMPLEMENTED();
}
else if(!has16bitTextureComponents()) // 8-bit components
{ {
Int c0;
Int c1;
Int c2;
Int c3;
switch(textureComponentCount()) switch(textureComponentCount())
{ {
case 4: case 4:
...@@ -1577,18 +1576,20 @@ namespace sw ...@@ -1577,18 +1576,20 @@ namespace sw
} }
break; break;
case 1: case 1:
c0 = Int(*Pointer<Byte>(buffer[f0] + index[0])); {
c1 = Int(*Pointer<Byte>(buffer[f1] + index[1])); Int c0 = Int(*Pointer<Byte>(buffer[f0] + index[0]));
c2 = Int(*Pointer<Byte>(buffer[f2] + index[2])); Int c1 = Int(*Pointer<Byte>(buffer[f1] + index[1]));
c3 = Int(*Pointer<Byte>(buffer[f3] + index[3])); Int c2 = Int(*Pointer<Byte>(buffer[f2] + index[2]));
c0 = c0 | (c1 << 8) | (c2 << 16) | (c3 << 24); Int c3 = Int(*Pointer<Byte>(buffer[f3] + index[3]));
c.x = Unpack(As<Byte4>(c0)); c0 = c0 | (c1 << 8) | (c2 << 16) | (c3 << 24);
c.x = Unpack(As<Byte4>(c0));
}
break; break;
default: default:
ASSERT(false); ASSERT(false);
} }
} }
else else // 16-bit components
{ {
switch(textureComponentCount()) switch(textureComponentCount())
{ {
...@@ -1826,10 +1827,49 @@ namespace sw ...@@ -1826,10 +1827,49 @@ namespace sw
return Surface::componentCount(state.textureFormat); return Surface::componentCount(state.textureFormat);
} }
bool SamplerCore::has16bitTexture() const bool SamplerCore::has16bitTextureFormat() const
{
switch(state.textureFormat)
{
case FORMAT_R5G6B5:
return true;
case FORMAT_G8R8:
case FORMAT_X8R8G8B8:
case FORMAT_X8B8G8R8:
case FORMAT_A8R8G8B8:
case FORMAT_A8B8G8R8:
case FORMAT_V8U8:
case FORMAT_Q8W8V8U8:
case FORMAT_X8L8V8U8:
case FORMAT_R32F:
case FORMAT_G32R32F:
case FORMAT_A32B32G32R32F:
case FORMAT_A8:
case FORMAT_R8:
case FORMAT_L8:
case FORMAT_A8L8:
case FORMAT_D32F_LOCKABLE:
case FORMAT_D32FS8_TEXTURE:
case FORMAT_D32FS8_SHADOW:
case FORMAT_L16:
case FORMAT_G16R16:
case FORMAT_A16B16G16R16:
case FORMAT_V16U16:
case FORMAT_A16W16V16U16:
case FORMAT_Q16W16V16U16:
return false;
default:
ASSERT(false);
}
return false;
}
bool SamplerCore::has16bitTextureComponents() const
{ {
switch(state.textureFormat) switch(state.textureFormat)
{ {
case FORMAT_R5G6B5:
case FORMAT_G8R8: case FORMAT_G8R8:
case FORMAT_X8R8G8B8: case FORMAT_X8R8G8B8:
case FORMAT_X8B8G8R8: case FORMAT_X8B8G8R8:
...@@ -1867,6 +1907,7 @@ namespace sw ...@@ -1867,6 +1907,7 @@ namespace sw
{ {
switch(state.textureFormat) switch(state.textureFormat)
{ {
case FORMAT_R5G6B5: return component < 3;
case FORMAT_G8R8: return component < 2; case FORMAT_G8R8: return component < 2;
case FORMAT_X8R8G8B8: return component < 3; case FORMAT_X8R8G8B8: return component < 3;
case FORMAT_X8B8G8R8: return component < 3; case FORMAT_X8B8G8R8: return component < 3;
......
...@@ -60,7 +60,8 @@ namespace sw ...@@ -60,7 +60,8 @@ namespace sw
bool hasFloatTexture() const; bool hasFloatTexture() const;
bool hasUnsignedTextureComponent(int component) const; bool hasUnsignedTextureComponent(int component) const;
int textureComponentCount() const; int textureComponentCount() const;
bool has16bitTexture() const; bool has16bitTextureFormat() const;
bool has16bitTextureComponents() const;
bool isRGBComponent(int component) const; bool isRGBComponent(int component) const;
Pointer<Byte> &constants; Pointer<Byte> &constants;
......
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