Put infrastructure in place so that other plugins may support dual-source blending.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6296 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Nolan Check
2010-10-21 05:22:18 +00:00
parent 0b7e90f0de
commit 95cfca08e2
14 changed files with 105 additions and 51 deletions

View File

@ -254,37 +254,73 @@ void EmuGfxState::SetRenderTargetWriteMask(UINT8 mask)
void EmuGfxState::SetSrcBlend(D3D11_BLEND val)
{
// TODO: Check whether e.g. the dest color check is needed here
blenddesc.RenderTarget[0].SrcBlend = val;
if (m_useDstAlpha)
{
// Colors should blend against SRC1_ALPHA
if (val == D3D11_BLEND_SRC_ALPHA)
val = D3D11_BLEND_SRC1_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_ALPHA)
val = D3D11_BLEND_INV_SRC1_ALPHA;
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
}
else
{
if (val == D3D11_BLEND_SRC_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
else if (val == D3D11_BLEND_DEST_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
else if (val == D3D11_BLEND_INV_DEST_COLOR) blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
else blenddesc.RenderTarget[0].SrcBlendAlpha = val;
// Colors should blend against SRC_ALPHA
if (val == D3D11_BLEND_SRC1_ALPHA)
val = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC1_ALPHA)
val = D3D11_BLEND_INV_SRC_ALPHA;
if (val == D3D11_BLEND_SRC_COLOR)
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_COLOR)
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
else if (val == D3D11_BLEND_DEST_COLOR)
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_DEST_ALPHA;
else if (val == D3D11_BLEND_INV_DEST_COLOR)
blenddesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
else
blenddesc.RenderTarget[0].SrcBlendAlpha = val;
}
blenddesc.RenderTarget[0].SrcBlend = val;
}
void EmuGfxState::SetDestBlend(D3D11_BLEND val)
{
// TODO: Check whether e.g. the source color check is needed here
blenddesc.RenderTarget[0].DestBlend = val;
if (m_useDstAlpha)
{
// Colors should blend against SRC1_ALPHA
if (val == D3D11_BLEND_SRC_ALPHA)
val = D3D11_BLEND_SRC1_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_ALPHA)
val = D3D11_BLEND_INV_SRC1_ALPHA;
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
}
else
{
if (val == D3D11_BLEND_SRC_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
else if (val == D3D11_BLEND_DEST_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
else if (val == D3D11_BLEND_INV_DEST_COLOR) blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
else blenddesc.RenderTarget[0].DestBlendAlpha = val;
// Colors should blend against SRC_ALPHA
if (val == D3D11_BLEND_SRC1_ALPHA)
val = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC1_ALPHA)
val = D3D11_BLEND_INV_SRC_ALPHA;
if (val == D3D11_BLEND_SRC_COLOR)
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_SRC_ALPHA;
else if (val == D3D11_BLEND_INV_SRC_COLOR)
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA;
else if (val == D3D11_BLEND_DEST_COLOR)
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_DEST_ALPHA;
else if (val == D3D11_BLEND_INV_DEST_COLOR)
blenddesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_INV_DEST_ALPHA;
else
blenddesc.RenderTarget[0].DestBlendAlpha = val;
}
blenddesc.RenderTarget[0].DestBlend = val;
}
void EmuGfxState::SetBlendOp(D3D11_BLEND_OP val)

View File

@ -228,10 +228,10 @@ void PixelShaderCache::Shutdown()
g_ps_disk_cache.Close();
}
bool PixelShaderCache::SetShader(bool dstAlpha,u32 components)
bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components)
{
PIXELSHADERUID uid;
GetPixelShaderId(&uid, dstAlpha);
GetPixelShaderId(&uid, dstAlphaMode);
// Check if the shader is already set
if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount)
@ -256,7 +256,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha,u32 components)
}
// Need to compile a new shader
const char* code = GeneratePixelShaderCode(dstAlpha, API_D3D11,components);
const char* code = GeneratePixelShaderCode(dstAlphaMode, API_D3D11, components);
D3DBlob* pbytecode;
if (!D3D::CompilePixelShader(code, strlen(code), &pbytecode))

View File

@ -32,7 +32,7 @@ public:
static void Init();
static void Clear();
static void Shutdown();
static bool SetShader(bool dstAlpha,u32 components);
static bool SetShader(DSTALPHA_MODE dstAlphaMode, u32 components);
static bool InsertByteCode(const PIXELSHADERUID &uid, void* bytecode, unsigned int bytecodelen);
static ID3D11PixelShader* GetColorMatrixProgram();

View File

@ -90,8 +90,8 @@ static const D3D11_BLEND d3dSrcFactors[8] =
D3D11_BLEND_ONE,
D3D11_BLEND_DEST_COLOR,
D3D11_BLEND_INV_DEST_COLOR,
D3D11_BLEND_SRC1_ALPHA,
D3D11_BLEND_INV_SRC1_ALPHA, // Use dual-source color blending for dst alpha
D3D11_BLEND_SRC_ALPHA,
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
D3D11_BLEND_DEST_ALPHA,
D3D11_BLEND_INV_DEST_ALPHA
};
@ -102,8 +102,8 @@ static const D3D11_BLEND d3dDestFactors[8] =
D3D11_BLEND_ONE,
D3D11_BLEND_SRC_COLOR,
D3D11_BLEND_INV_SRC_COLOR,
D3D11_BLEND_SRC1_ALPHA,
D3D11_BLEND_INV_SRC1_ALPHA, // Use dual-source color blending for dst alpha
D3D11_BLEND_SRC_ALPHA,
D3D11_BLEND_INV_SRC_ALPHA, // NOTE: Use SRC1_ALPHA if dst alpha is enabled!
D3D11_BLEND_DEST_ALPHA,
D3D11_BLEND_INV_DEST_ALPHA
};

View File

@ -223,7 +223,9 @@ void VertexManager::vFlush()
D3D::gfxstate->SetDstAlpha(useDstAlpha);
if (!PixelShaderCache::SetShader(useDstAlpha,g_nativeVertexFmt->m_components))
if (!PixelShaderCache::SetShader(
useDstAlpha ? DSTALPHA_DUAL_SOURCE_BLEND : DSTALPHA_NONE,
g_nativeVertexFmt->m_components))
goto shader_fail;
if (!VertexShaderCache::SetShader(g_nativeVertexFmt->m_components))
goto shader_fail;