BPMemory: Make use of BitField in a number of structures.

This commit is contained in:
Tony Wasserka
2014-03-24 20:21:34 +01:00
parent 8941f19cdb
commit 16105db709
8 changed files with 266 additions and 241 deletions

View File

@ -10,7 +10,6 @@
#include "VideoBackends/D3D/PSTextureEncoder.h"
#include "VideoBackends/D3D/Render.h"
#include "VideoBackends/D3D/TextureCache.h"
#include "VideoCommon/BPMemory.h"
// "Static mode" will compile a new EFB encoder shader for every combination of
// encoding configurations. It's compatible with Shader Model 4.

View File

@ -4,6 +4,7 @@
#pragma once
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/VideoCommon.h"
namespace DX11
@ -111,8 +112,8 @@ public:
virtual void Shutdown() = 0;
// Returns size in bytes of encoded block of memory
virtual size_t Encode(u8* dst, unsigned int dstFormat,
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
bool isIntensity, bool scaleByHalf) = 0;
PEControl::PixelFormat srcFormat, const EFBRectangle& srcRect,
bool isIntensity, bool scaleByHalf) = 0;
};

View File

@ -1279,18 +1279,18 @@ void Renderer::SetBlendMode(bool forceUpdate)
// adjust alpha factors
if (useDualSource)
{
srcidx = GX_BL_ONE;
dstidx = GX_BL_ZERO;
srcidx = BlendMode::ONE;
dstidx = BlendMode::ZERO;
}
else
{
// we can't use GL_DST_COLOR or GL_ONE_MINUS_DST_COLOR for source in alpha channel so use their alpha equivalent instead
if (srcidx == GX_BL_DSTCLR) srcidx = GX_BL_DSTALPHA;
if (srcidx == GX_BL_INVDSTCLR) srcidx = GX_BL_INVDSTALPHA;
if (srcidx == BlendMode::DSTCLR) srcidx = BlendMode::DSTALPHA;
if (srcidx == BlendMode::INVDSTCLR) srcidx = BlendMode::INVDSTALPHA;
// we can't use GL_SRC_COLOR or GL_ONE_MINUS_SRC_COLOR for destination in alpha channel so use their alpha equivalent instead
if (dstidx == GX_BL_SRCCLR) dstidx = GX_BL_SRCALPHA;
if (dstidx == GX_BL_INVSRCCLR) dstidx = GX_BL_INVSRCALPHA;
if (dstidx == BlendMode::SRCCLR) dstidx = BlendMode::SRCALPHA;
if (dstidx == BlendMode::INVSRCCLR) dstidx = BlendMode::INVSRCALPHA;
}
GLenum srcFactorAlpha = glSrcFactors[srcidx];
GLenum dstFactorAlpha = glDestFactors[dstidx];

View File

@ -225,81 +225,83 @@ namespace EfbInterface
return depth;
}
u32 GetSourceFactor(u8 *srcClr, u8 *dstClr, int mode)
u32 GetSourceFactor(u8 *srcClr, u8 *dstClr, BlendMode::BlendFactor mode)
{
switch (mode) {
case 0: // zero
return 0;
case 1: // one
return 0xffffffff;
case 2: // dstclr
return *(u32*)dstClr;
case 3: // invdstclr
return 0xffffffff - *(u32*)dstClr;
case 4: // srcalpha
{
u8 alpha = srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 5: // invsrcalpha
{
u8 alpha = 0xff - srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 6: // dstalpha
{
u8 alpha = dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 7: // invdstalpha
{
u8 alpha = 0xff - dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
switch (mode)
{
case BlendMode::ZERO:
return 0;
case BlendMode::ONE:
return 0xffffffff;
case BlendMode::DSTCLR:
return *(u32*)dstClr;
case BlendMode::INVDSTCLR:
return 0xffffffff - *(u32*)dstClr;
case BlendMode::SRCALPHA:
{
u8 alpha = srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::INVSRCALPHA:
{
u8 alpha = 0xff - srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::DSTALPHA:
{
u8 alpha = dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::INVDSTALPHA:
{
u8 alpha = 0xff - dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
}
return 0;
}
u32 GetDestinationFactor(u8 *srcClr, u8 *dstClr, int mode)
u32 GetDestinationFactor(u8 *srcClr, u8 *dstClr, BlendMode::BlendFactor mode)
{
switch (mode) {
case 0: // zero
return 0;
case 1: // one
return 0xffffffff;
case 2: // srcclr
return *(u32*)srcClr;
case 3: // invsrcclr
return 0xffffffff - *(u32*)srcClr;
case 4: // srcalpha
{
u8 alpha = srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 5: // invsrcalpha
{
u8 alpha = 0xff - srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 6: // dstalpha
{
u8 alpha = dstClr[ALP_C] & 0xff;
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case 7: // invdstalpha
{
u8 alpha = 0xff - dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
switch (mode)
{
case BlendMode::ZERO:
return 0;
case BlendMode::ONE:
return 0xffffffff;
case BlendMode::SRCCLR:
return *(u32*)srcClr;
case BlendMode::INVSRCCLR:
return 0xffffffff - *(u32*)srcClr;
case BlendMode::SRCALPHA:
{
u8 alpha = srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::INVSRCALPHA:
{
u8 alpha = 0xff - srcClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::DSTALPHA:
{
u8 alpha = dstClr[ALP_C] & 0xff;
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
case BlendMode::INVDSTALPHA:
{
u8 alpha = 0xff - dstClr[ALP_C];
u32 factor = alpha << 24 | alpha << 16 | alpha << 8 | alpha;
return factor;
}
}
return 0;
@ -327,58 +329,58 @@ namespace EfbInterface
}
}
void LogicBlend(u32 srcClr, u32 &dstClr, int op)
void LogicBlend(u32 srcClr, u32 &dstClr, BlendMode::LogicOp op)
{
switch (op)
{
case 0: // clear
dstClr = 0;
break;
case 1: // and
dstClr = srcClr & dstClr;
break;
case 2: // revand
dstClr = srcClr & (~dstClr);
break;
case 3: // copy
dstClr = srcClr;
break;
case 4: // invand
dstClr = (~srcClr) & dstClr;
break;
case 5: // noop
// Do nothing
break;
case 6: // xor
dstClr = srcClr ^ dstClr;
break;
case 7: // or
dstClr = srcClr | dstClr;
break;
case 8: // nor
dstClr = ~(srcClr | dstClr);
break;
case 9: // equiv
dstClr = ~(srcClr ^ dstClr);
break;
case 10: // inv
dstClr = ~dstClr;
break;
case 11: // revor
dstClr = srcClr | (~dstClr);
break;
case 12: // invcopy
dstClr = ~srcClr;
break;
case 13: // invor
dstClr = (~srcClr) | dstClr;
break;
case 14: // nand
dstClr = ~(srcClr & dstClr);
break;
case 15: // set
dstClr = 0xffffffff;
break;
case BlendMode::CLEAR:
dstClr = 0;
break;
case BlendMode::AND:
dstClr = srcClr & dstClr;
break;
case BlendMode::AND_REVERSE:
dstClr = srcClr & (~dstClr);
break;
case BlendMode::COPY:
dstClr = srcClr;
break;
case BlendMode::AND_INVERTED:
dstClr = (~srcClr) & dstClr;
break;
case BlendMode::NOOP:
// Do nothing
break;
case BlendMode::XOR:
dstClr = srcClr ^ dstClr;
break;
case BlendMode::OR:
dstClr = srcClr | dstClr;
break;
case BlendMode::NOR:
dstClr = ~(srcClr | dstClr);
break;
case BlendMode::EQUIV:
dstClr = ~(srcClr ^ dstClr);
break;
case BlendMode::INVERT:
dstClr = ~dstClr;
break;
case BlendMode::OR_REVERSE:
dstClr = srcClr | (~dstClr);
break;
case BlendMode::COPY_INVERTED:
dstClr = ~srcClr;
break;
case BlendMode::OR_INVERTED:
dstClr = (~srcClr) | dstClr;
break;
case BlendMode::NAND:
dstClr = ~(srcClr & dstClr);
break;
case BlendMode::SET:
dstClr = 0xffffffff;
break;
}
}
@ -584,33 +586,33 @@ namespace EfbInterface
switch (bpmem.zmode.func)
{
case COMPARE_NEVER:
pass = false;
break;
case COMPARE_LESS:
pass = z < depth;
break;
case COMPARE_EQUAL:
pass = z == depth;
break;
case COMPARE_LEQUAL:
pass = z <= depth;
break;
case COMPARE_GREATER:
pass = z > depth;
break;
case COMPARE_NEQUAL:
pass = z != depth;
break;
case COMPARE_GEQUAL:
pass = z >= depth;
break;
case COMPARE_ALWAYS:
pass = true;
break;
default:
pass = false;
ERROR_LOG(VIDEO, "Bad Z compare mode %i", bpmem.zmode.func);
case ZMode::NEVER:
pass = false;
break;
case ZMode::LESS:
pass = z < depth;
break;
case ZMode::EQUAL:
pass = z == depth;
break;
case ZMode::LEQUAL:
pass = z <= depth;
break;
case ZMode::GREATER:
pass = z > depth;
break;
case ZMode::NEQUAL:
pass = z != depth;
break;
case ZMode::GEQUAL:
pass = z >= depth;
break;
case ZMode::ALWAYS:
pass = true;
break;
default:
pass = false;
ERROR_LOG(VIDEO, "Bad Z compare mode %i", (int)bpmem.zmode.func);
}
if (pass && bpmem.zmode.updateenable)

View File

@ -413,17 +413,17 @@ void Tev::DrawAlphaCompare(TevStageCombiner::AlphaCombiner &ac)
}
}
static bool AlphaCompare(int alpha, int ref, int comp)
static bool AlphaCompare(int alpha, int ref, AlphaTest::CompareMode comp)
{
switch (comp) {
case ALPHACMP_ALWAYS: return true;
case ALPHACMP_NEVER: return false;
case ALPHACMP_LEQUAL: return alpha <= ref;
case ALPHACMP_LESS: return alpha < ref;
case ALPHACMP_GEQUAL: return alpha >= ref;
case ALPHACMP_GREATER: return alpha > ref;
case ALPHACMP_EQUAL: return alpha == ref;
case ALPHACMP_NEQUAL: return alpha != ref;
case AlphaTest::ALWAYS: return true;
case AlphaTest::NEVER: return false;
case AlphaTest::LEQUAL: return alpha <= ref;
case AlphaTest::LESS: return alpha < ref;
case AlphaTest::GEQUAL: return alpha >= ref;
case AlphaTest::GREATER: return alpha > ref;
case AlphaTest::EQUAL: return alpha == ref;
case AlphaTest::NEQUAL: return alpha != ref;
}
return true;
}