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
{
class Blitter
{
enum Options : unsigned char
struct Options
{
FILTER_POINT = 0x00,
WRITE_RED = 0x01,
WRITE_GREEN = 0x02,
WRITE_BLUE = 0x04,
WRITE_ALPHA = 0x08,
WRITE_RGBA = WRITE_RED | WRITE_GREEN | WRITE_BLUE | WRITE_ALPHA,
FILTER_LINEAR = 0x10,
CLEAR_OPERATION = 0x20,
USE_STENCIL = 0x40,
Options() {}
Options(bool filter, bool useStencil)
: writeMask(0xF), clearOperation(false), filter(filter), useStencil(useStencil) {}
Options(unsigned int writeMask)
: writeMask(writeMask), clearOperation(true), filter(false), useStencil(false) {}
union
{
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 destFormat;
int destSamples;
Blitter::Options options;
};
struct BlitData
......@@ -78,24 +93,23 @@ namespace sw
virtual ~Blitter();
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);
private:
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 write(Float4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options);
bool read(Int4 &color, Pointer<Byte> element, Format format);
bool write(Int4 &color, Pointer<Byte> element, Format format, const Blitter::Options& options);
bool read(Float4 &color, Pointer<Byte> element, const State &state);
bool write(Float4 &color, Pointer<Byte> element, const State &state);
bool read(Int4 &color, Pointer<Byte> element, const State &state);
bool write(Int4 &color, Pointer<Byte> element, const State &state);
static bool GetScale(float4& scale, Format format);
static bool ApplyScaleAndClamp(Float4& value, const BlitState& state);
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 Blitter::Options& options);
Routine *generate(BlitState &state);
static bool ApplyScaleAndClamp(Float4 &value, const State &state);
static Int ComputeOffset(Int &x, Int &y, Int &pitchB, int bytes, bool quadLayout);
bool blitReactor(Surface *source, const SliceRectF &sRect, Surface *dest, const SliceRect &dRect, const Options &options);
Routine *generate(const State &state);
RoutineCache<BlitState> *blitCache;
RoutineCache<State> *blitCache;
MutexLock criticalSection;
};
}
......
......@@ -684,7 +684,7 @@ namespace sw
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)
......
......@@ -991,7 +991,7 @@ namespace sw
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)
......@@ -2653,17 +2653,12 @@ namespace sw
void PixelRoutine::sRGBtoLinear16_12_16(Vector4s &c)
{
Pointer<Byte> LUT = constants + OFFSET(Constants,sRGBtoLinear12_16);
c.x = As<UShort4>(c.x) >> 4;
c.y = As<UShort4>(c.y) >> 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, 1))), 1);
c.x = Insert(c.x, *Pointer<Short>(LUT + 2 * Int(Extract(c.x, 2))), 2);
......
......@@ -83,7 +83,6 @@ namespace sw
void writeDepth(Pointer<Byte> &zBuffer, int q, Int &x, Float4 &z, Int &zMask);
void sRGBtoLinear16_12_16(Vector4s &c);
void sRGBtoLinear12_16(Vector4s &c);
void linearToSRGB16_12_16(Vector4s &c);
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