Commit 43577b8c by Alexis Hetu Committed by Alexis Hétu

Integer types support in Blitter

The blitter now supports integer types. This means: - It supports conversions to/from integer types from/to other already supported types. - It supports integer to integer conversions without going to an intermediate float format. Also added a Blitter::GetScale() function to avoid having 2 instances of the same switch statement in the code and added the read/write utility functions. The final Blitter code is not longer peppered with switch statements and is, hopefully, easier to read that way. Change-Id: I80de519aaaa768f8cedd98f97dc4414dda75bf54 Reviewed-on: https://swiftshader-review.googlesource.com/4113Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent a60d825a
...@@ -216,18 +216,7 @@ namespace D3D9 ...@@ -216,18 +216,7 @@ namespace D3D9
for(int i = 0; i < dWidth; i++) for(int i = 0; i < dWidth; i++)
{ {
sw::Color<float> color; dest->copyInternal(source, i, j, k, x, y, z, filter > D3DTEXF_POINT);
if(filter <= D3DTEXF_POINT)
{
color = source->readInternal((int)x, (int)y, (int)z);
}
else // filter >= D3DTEXF_LINEAR
{
color = source->sampleInternal(x, y, z);
}
dest->writeInternal(i, j, k, color);
x += w; x += w;
} }
......
...@@ -65,6 +65,10 @@ namespace sw ...@@ -65,6 +65,10 @@ namespace sw
private: private:
bool read(Float4 &color, Pointer<Byte> element, Format format); bool read(Float4 &color, Pointer<Byte> element, Format format);
bool write(Float4 &color, Pointer<Byte> element, Format format);
bool read(Int4 &color, Pointer<Byte> element, Format format);
bool write(Int4 &color, Pointer<Byte> element, Format format);
static bool GetScale(float4& scale, Format format);
bool blitReactor(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter); bool blitReactor(Surface *source, const SliceRect &sRect, Surface *dest, const SliceRect &dRect, bool filter);
Routine *generate(BlitState &state); Routine *generate(BlitState &state);
......
...@@ -2290,11 +2290,30 @@ namespace sw ...@@ -2290,11 +2290,30 @@ namespace sw
{ {
case FORMAT_R5G6B5: case FORMAT_R5G6B5:
case FORMAT_X8R8G8B8: case FORMAT_X8R8G8B8:
case FORMAT_X8B8G8R8I:
case FORMAT_X8B8G8R8: case FORMAT_X8B8G8R8:
case FORMAT_A8R8G8B8: case FORMAT_A8R8G8B8:
case FORMAT_A8B8G8R8I:
case FORMAT_R8UI:
case FORMAT_G8R8UI:
case FORMAT_X8B8G8R8UI:
case FORMAT_A8B8G8R8UI:
case FORMAT_A8B8G8R8: case FORMAT_A8B8G8R8:
case FORMAT_G8R8I:
case FORMAT_G8R8: case FORMAT_G8R8:
case FORMAT_R8I_SNORM:
case FORMAT_G8R8I_SNORM:
case FORMAT_X8B8G8R8I_SNORM:
case FORMAT_A8B8G8R8I_SNORM:
case FORMAT_R16I:
case FORMAT_R16UI:
case FORMAT_G16R16I:
case FORMAT_G16R16UI:
case FORMAT_G16R16: case FORMAT_G16R16:
case FORMAT_X16B16G16R16I:
case FORMAT_X16B16G16R16UI:
case FORMAT_A16B16G16R16I:
case FORMAT_A16B16G16R16UI:
case FORMAT_A16B16G16R16: case FORMAT_A16B16G16R16:
case FORMAT_V8U8: case FORMAT_V8U8:
case FORMAT_Q8W8V8U8: case FORMAT_Q8W8V8U8:
...@@ -2303,6 +2322,7 @@ namespace sw ...@@ -2303,6 +2322,7 @@ namespace sw
case FORMAT_A16W16V16U16: case FORMAT_A16W16V16U16:
case FORMAT_Q16W16V16U16: case FORMAT_Q16W16V16U16:
case FORMAT_A8: case FORMAT_A8:
case FORMAT_R8I:
case FORMAT_R8: case FORMAT_R8:
case FORMAT_L8: case FORMAT_L8:
case FORMAT_L16: case FORMAT_L16:
...@@ -2310,6 +2330,14 @@ namespace sw ...@@ -2310,6 +2330,14 @@ namespace sw
case FORMAT_YV12_BT601: case FORMAT_YV12_BT601:
case FORMAT_YV12_BT709: case FORMAT_YV12_BT709:
case FORMAT_YV12_JFIF: case FORMAT_YV12_JFIF:
case FORMAT_R32I:
case FORMAT_R32UI:
case FORMAT_G32R32I:
case FORMAT_G32R32UI:
case FORMAT_X32B32G32R32I:
case FORMAT_X32B32G32R32UI:
case FORMAT_A32B32G32R32I:
case FORMAT_A32B32G32R32UI:
return false; return false;
case FORMAT_R32F: case FORMAT_R32F:
case FORMAT_G32R32F: case FORMAT_G32R32F:
...@@ -2512,6 +2540,40 @@ namespace sw ...@@ -2512,6 +2540,40 @@ namespace sw
} }
} }
bool Surface::isNonNormalizedInteger(Format format)
{
switch(format)
{
case FORMAT_A8B8G8R8I:
case FORMAT_X8B8G8R8I:
case FORMAT_G8R8I:
case FORMAT_R8I:
case FORMAT_A8B8G8R8UI:
case FORMAT_X8B8G8R8UI:
case FORMAT_G8R8UI:
case FORMAT_R8UI:
case FORMAT_A16B16G16R16I:
case FORMAT_X16B16G16R16I:
case FORMAT_G16R16I:
case FORMAT_R16I:
case FORMAT_A16B16G16R16UI:
case FORMAT_X16B16G16R16UI:
case FORMAT_G16R16UI:
case FORMAT_R16UI:
case FORMAT_A32B32G32R32I:
case FORMAT_X32B32G32R32I:
case FORMAT_G32R32I:
case FORMAT_R32I:
case FORMAT_A32B32G32R32UI:
case FORMAT_X32B32G32R32UI:
case FORMAT_G32R32UI:
case FORMAT_R32UI:
return true;
default:
return false;
}
}
int Surface::componentCount(Format format) int Surface::componentCount(Format format)
{ {
switch(format) switch(format)
...@@ -3300,46 +3362,40 @@ namespace sw ...@@ -3300,46 +3362,40 @@ namespace sw
external.write(x, y, color); external.write(x, y, color);
} }
Color<float> Surface::readInternal(int x, int y, int z) const void Surface::copyInternal(const Surface* source, int x, int y, float srcX, float srcY, bool filter)
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); ASSERT(internal.lock != LOCK_UNLOCKED && source && source->internal.lock != LOCK_UNLOCKED);
return internal.read(x, y, z); sw::Color<float> color;
}
Color<float> Surface::readInternal(int x, int y) const if(!filter)
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); color = source->internal.read((int)srcX, (int)srcY);
return internal.read(x, y);
} }
else // Bilinear filtering
Color<float> Surface::sampleInternal(float x, float y, float z) const
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); color = source->internal.sample(srcX, srcY);
}
return internal.sample(x, y, z); internal.write(x, y, color);
} }
Color<float> Surface::sampleInternal(float x, float y) const void Surface::copyInternal(const Surface* source, int x, int y, int z, float srcX, float srcY, float srcZ, bool filter)
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); ASSERT(internal.lock != LOCK_UNLOCKED && source && source->internal.lock != LOCK_UNLOCKED);
return internal.sample(x, y); sw::Color<float> color;
}
void Surface::writeInternal(int x, int y, int z, const Color<float> &color) if(!filter)
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); color = source->internal.read((int)srcX, (int)srcY, int(srcZ));
internal.write(x, y, z, color);
} }
else // Bilinear filtering
void Surface::writeInternal(int x, int y, const Color<float> &color)
{ {
ASSERT(internal.lock != LOCK_UNLOCKED); color = source->internal.sample(srcX, srcY, srcZ);
}
internal.write(x, y, color); internal.write(x, y, z, color);
} }
bool Surface::hasStencil() const bool Surface::hasStencil() const
......
...@@ -294,12 +294,8 @@ namespace sw ...@@ -294,12 +294,8 @@ namespace sw
void writeExternal(int x, int y, int z, const Color<float> &color); void writeExternal(int x, int y, int z, const Color<float> &color);
void writeExternal(int x, int y, const Color<float> &color); void writeExternal(int x, int y, const Color<float> &color);
Color<float> readInternal(int x, int y, int z) const; void copyInternal(const Surface* src, int x, int y, float srcX, float srcY, bool filter);
Color<float> readInternal(int x, int y) const; void copyInternal(const Surface* src, int x, int y, int z, float srcX, float srcY, float srcZ, bool filter);
Color<float> sampleInternal(float x, float y, float z) const;
Color<float> sampleInternal(float x, float y) const;
void writeInternal(int x, int y, int z, const Color<float> &color);
void writeInternal(int x, int y, const Color<float> &color);
bool hasStencil() const; bool hasStencil() const;
bool hasDepth() const; bool hasDepth() const;
...@@ -327,6 +323,7 @@ namespace sw ...@@ -327,6 +323,7 @@ namespace sw
static bool isSRGBreadable(Format format); static bool isSRGBreadable(Format format);
static bool isSRGBwritable(Format format); static bool isSRGBwritable(Format format);
static bool isCompressed(Format format); static bool isCompressed(Format format);
static bool isNonNormalizedInteger(Format format);
static int componentCount(Format format); static int componentCount(Format format);
static void setTexturePalette(unsigned int *palette); static void setTexturePalette(unsigned int *palette);
......
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