Commit 8f7739a8 by Nicolas Capens Committed by Nicolas Capens

Refactor Blitter state.

Change-Id: Ife3342c64dfc846f8b7722f2e80612fc71f93688 Reviewed-on: https://swiftshader-review.googlesource.com/15128Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 1efac529
...@@ -25,30 +25,45 @@ namespace sw ...@@ -25,30 +25,45 @@ namespace sw
{ {
class Blitter class Blitter
{ {
enum Options : unsigned char struct Options
{ {
FILTER_POINT = 0x00, Options() {}
WRITE_RED = 0x01, Options(bool filter, bool useStencil)
WRITE_GREEN = 0x02, : writeMask(0xF), clearOperation(false), filter(filter), useStencil(useStencil) {}
WRITE_BLUE = 0x04, Options(unsigned int writeMask)
WRITE_ALPHA = 0x08, : writeMask(writeMask), clearOperation(true), filter(false), useStencil(false) {}
WRITE_RGBA = WRITE_RED | WRITE_GREEN | WRITE_BLUE | WRITE_ALPHA,
FILTER_LINEAR = 0x10, union
CLEAR_OPERATION = 0x20, {
USE_STENCIL = 0x40, struct
{
bool writeRed : 1;
bool writeGreen : 1;
bool writeBlue : 1;
bool writeAlpha : 1;
};
unsigned char writeMask;
};
bool clearOperation : 1;
bool filter : 1;
bool useStencil : 1;
}; };
struct BlitState struct State : Options
{ {
bool operator==(const BlitState &state) const State() {}
State(const Options &options) : Options(options) {}
bool operator==(const State &state) const
{ {
return memcmp(this, &state, sizeof(BlitState)) == 0; return memcmp(this, &state, sizeof(State)) == 0;
} }
Format sourceFormat; Format sourceFormat;
Format destFormat; Format destFormat;
int destSamples; int destSamples;
Blitter::Options options;
}; };
struct BlitData struct BlitData
...@@ -78,24 +93,23 @@ namespace sw ...@@ -78,24 +93,23 @@ namespace sw
virtual ~Blitter(); virtual ~Blitter();
void clear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); void clear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil = false); void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Options &options);
void blit3D(Surface *source, Surface *dest); void blit3D(Surface *source, Surface *dest);
private: private:
bool fastClear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask); bool fastClear(void *pixel, sw::Format format, Surface *dest, const SliceRect &dRect, unsigned int rgbaMask);
bool read(Float4 &color, Pointer<Byte> element, Format format); bool read(Float4 &color, Pointer<Byte> element, const State &state);
bool write(Float4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options); bool write(Float4 &color, Pointer<Byte> element, const State &state);
bool read(Int4 &color, Pointer<Byte> element, Format format); bool read(Int4 &color, Pointer<Byte> element, const State &state);
bool write(Int4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options); bool write(Int4 &color, Pointer<Byte> element, const State &state);
static bool GetScale(float4& scale, Format format); static bool GetScale(float4& scale, Format format);
static bool ApplyScaleAndClamp(Float4& value, const BlitState& state); static bool ApplyScaleAndClamp(Float4 &value, const State &state);
static Int ComputeOffset(Int& x, Int& y, Int& pitchB, int bytes, bool quadLayout); static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout);
void blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Blitter::Options& options); bool blitReactor(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Options &options);
bool blitReactor(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Blitter::Options& options); Routine *generate(const State &state);
Routine *generate(BlitState &state);
RoutineCache<BlitState> *blitCache; RoutineCache<State> *blitCache;
MutexLock criticalSection; MutexLock criticalSection;
}; };
} }
......
...@@ -684,7 +684,7 @@ namespace sw ...@@ -684,7 +684,7 @@ namespace sw
void Renderer::blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil) void Renderer::blit(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, bool filter, bool isStencil)
{ {
blitter->blit(source, sRect, dest, dRect, filter, isStencil); blitter->blit(source, sRect, dest, dRect, {filter, isStencil});
} }
void Renderer::blit3D(Surface *source, Surface *dest) void Renderer::blit3D(Surface *source, Surface *dest)
......
...@@ -991,7 +991,7 @@ namespace sw ...@@ -991,7 +991,7 @@ namespace sw
bool PixelRoutine::isSRGB(int index) const bool PixelRoutine::isSRGB(int index) const
{ {
return state.targetFormat[index] == FORMAT_SRGB8_A8 || state.targetFormat[index] == FORMAT_SRGB8_X8; return Surface::isSRGBformat(state.targetFormat[index]);
} }
void PixelRoutine::readPixel(int index, Pointer<Byte> &cBuffer, Int &x, Vector4s &pixel) void PixelRoutine::readPixel(int index, Pointer<Byte> &cBuffer, Int &x, Vector4s &pixel)
...@@ -2653,17 +2653,12 @@ namespace sw ...@@ -2653,17 +2653,12 @@ namespace sw
void PixelRoutine::sRGBtoLinear16_12_16(Vector4s &c) void PixelRoutine::sRGBtoLinear16_12_16(Vector4s &c)
{ {
Pointer<Byte> LUT = constants + OFFSET(Constants,sRGBtoLinear12_16);
c.x = As<UShort4>(c.x) >> 4; c.x = As<UShort4>(c.x) >> 4;
c.y = As<UShort4>(c.y) >> 4; c.y = As<UShort4>(c.y) >> 4;
c.z = As<UShort4>(c.z) >> 4; c.z = As<UShort4>(c.z) >> 4;
sRGBtoLinear12_16(c);
}
void PixelRoutine::sRGBtoLinear12_16(Vector4s &c)
{
Pointer<Byte> LUT = constants + OFFSET(Constants,sRGBtoLinear12_16);
c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0); c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 0))), 0);
c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1); c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 1))), 1);
c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2); c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2);
......
...@@ -83,7 +83,6 @@ namespace sw ...@@ -83,7 +83,6 @@ namespace sw
void writeDepth(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask); void writeDepth(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask);
void sRGBtoLinear16_12_16(Vector4s &c); void sRGBtoLinear16_12_16(Vector4s &c);
void sRGBtoLinear12_16(Vector4s &c);
void linearToSRGB16_12_16(Vector4s &c); void linearToSRGB16_12_16(Vector4s &c);
Float4 sRGBtoLinear(const Float4 &x); Float4 sRGBtoLinear(const Float4 &x);
......
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