From 95cfca08e2c3f549613c5ea73836e04ee56a21a1 Mon Sep 17 00:00:00 2001 From: Nolan Check Date: Thu, 21 Oct 2010 05:22:18 +0000 Subject: [PATCH] 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 --- Source/Core/Common/Src/LinearDiskCache.cpp | 2 +- .../Core/VideoCommon/Src/PixelShaderGen.cpp | 36 ++++++----- Source/Core/VideoCommon/Src/PixelShaderGen.h | 12 +++- .../Plugins/Plugin_VideoDX11/Src/GfxState.cpp | 60 +++++++++++++++---- .../Plugin_VideoDX11/Src/PixelShaderCache.cpp | 6 +- .../Plugin_VideoDX11/Src/PixelShaderCache.h | 2 +- .../Plugins/Plugin_VideoDX11/Src/Render.cpp | 8 +-- .../Plugin_VideoDX11/Src/VertexManager.cpp | 4 +- .../Plugin_VideoDX9/Src/PixelShaderCache.cpp | 6 +- .../Plugin_VideoDX9/Src/PixelShaderCache.h | 2 +- .../Plugin_VideoDX9/Src/VertexManager.cpp | 4 +- .../Plugin_VideoOGL/Src/PixelShaderCache.cpp | 6 +- .../Plugin_VideoOGL/Src/PixelShaderCache.h | 2 +- .../Plugin_VideoOGL/Src/VertexManager.cpp | 6 +- 14 files changed, 105 insertions(+), 51 deletions(-) diff --git a/Source/Core/Common/Src/LinearDiskCache.cpp b/Source/Core/Common/Src/LinearDiskCache.cpp index 25665257ab..1df7614b6d 100644 --- a/Source/Core/Common/Src/LinearDiskCache.cpp +++ b/Source/Core/Common/Src/LinearDiskCache.cpp @@ -22,7 +22,7 @@ static const char ID[4] = {'D', 'C', 'A', 'C'}; // Update this to the current SVN revision every time you change shader generation code. // We don't automatically get this from SVN_REV because that would mean regenerating the // shader cache for every revision, graphics-related or not, which is simply annoying. -const int version = 6294; +const int version = 6296; LinearDiskCache::LinearDiskCache() : file_(NULL), num_entries_(0) { diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp index 7b638a1cbd..288af0d386 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.cpp @@ -33,7 +33,7 @@ PIXELSHADERUID last_pixel_shader_uid; // a unique identifier, basically containing all the bits. Yup, it's a lot .... // It would likely be a lot more efficient to build this incrementally as the attributes // are set... -void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable) +void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode) { u32 numstages = bpmem.genMode.numtevstages + 1; u32 projtexcoords = 0; @@ -49,12 +49,11 @@ void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable) uid->values[0] = (u32)bpmem.genMode.numtevstages | ((u32)bpmem.genMode.numindstages << 4) | ((u32)bpmem.genMode.numtexgens << 7) | - ((u32)dstAlphaEnable << 11) | - ((u32)((bpmem.alphaFunc.hex >> 16) & 0xff) << 12) | - (projtexcoords << 20) | - ((u32)bpmem.ztex2.op << 28); + ((u32)dstAlphaMode << 11) | + ((u32)((bpmem.alphaFunc.hex >> 16) & 0xff) << 13) | + (projtexcoords << 21) | + ((u32)bpmem.ztex2.op << 29); - uid->values[0] = (uid->values[0] & ~0x0ff00000) | (projtexcoords << 20); // swap table for (int i = 0; i < 8; i += 2) ((u8*)&uid->values[1])[i / 2] = (bpmem.tevksel[i].hex & 0xf) | ((bpmem.tevksel[i + 1].hex & 0xf) << 4); @@ -443,7 +442,7 @@ char *GeneratePixelLightShader(char *p, int index, const LitChannel& chan, const -const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 components) +const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,u32 components) { setlocale(LC_NUMERIC, "C"); // Reset locale for compilation text[sizeof(text) - 1] = 0x7C; // canary @@ -519,9 +518,18 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 co WRITE(p, "void main(\n"); if(ApiType != API_D3D11) - WRITE(p, " out float4 ocol0 : COLOR0,%s\n in float4 rawpos : %s,\n",DepthTextureEnable ? "\n out float depth : DEPTH," : "", ApiType == API_OPENGL ? "WPOS" : "POSITION"); + { + // TODO: Support DSTALPHA_DUAL_SOURCE_BLEND for non-D3D11 shaders + WRITE(p, " out float4 ocol0 : COLOR0,%s\n in float4 rawpos : %s,\n", + DepthTextureEnable ? "\n out float depth : DEPTH," : "", + ApiType == API_OPENGL ? "WPOS" : "POSITION"); + } else - WRITE(p, " out float4 ocol0 : SV_Target0,\n out float4 ocol1 : SV_Target1,%s\n in float4 rawpos : SV_Position,\n",DepthTextureEnable ? "\n out float depth : SV_Depth," : ""); + { + WRITE(p, " out float4 ocol0 : SV_Target0,%s%s\n in float4 rawpos : SV_Position,\n", + dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND ? "\n out float4 ocol1 : SV_Target1," : "", + DepthTextureEnable ? "\n out float depth : SV_Depth," : ""); + } WRITE(p, " in float4 colors_0 : COLOR0,\n"); WRITE(p, " in float4 colors_1 : COLOR1"); @@ -544,8 +552,7 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 co char* pmainstart = p; int Pretest = AlphaPreTest(); - // TODO: Re-enable the early discard on D3D11 - if (dstAlphaEnable && !DepthTextureEnable && Pretest >= 0 && ApiType != API_D3D11) + if (dstAlphaMode == DSTALPHA_ALPHA_PASS && !DepthTextureEnable && Pretest >= 0) { if (!Pretest) { @@ -807,7 +814,7 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 co WRITE(p, "depth = zCoord;\n"); } - if (dstAlphaEnable && ApiType != API_D3D11) + if (dstAlphaMode == DSTALPHA_ALPHA_PASS) WRITE(p, " ocol0 = float4(prev.rgb, "I_ALPHA"[0].a);\n"); else { @@ -817,13 +824,12 @@ const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 co // On D3D11, use dual-source color blending to perform dst alpha in a // single pass - if (ApiType == API_D3D11) + if (dstAlphaMode == DSTALPHA_DUAL_SOURCE_BLEND) { // Colors will be blended against the alpha from ocol1... WRITE(p, " ocol1 = ocol0;\n"); // ...and the alpha from ocol0 will be written to the framebuffer. - if (dstAlphaEnable) - WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); + WRITE(p, " ocol0.a = "I_ALPHA"[0].a;\n"); } } WRITE(p, "}\n"); diff --git a/Source/Core/VideoCommon/Src/PixelShaderGen.h b/Source/Core/VideoCommon/Src/PixelShaderGen.h index 1552d949fe..baf9db8aa6 100644 --- a/Source/Core/VideoCommon/Src/PixelShaderGen.h +++ b/Source/Core/VideoCommon/Src/PixelShaderGen.h @@ -104,8 +104,16 @@ public: } }; -const char *GeneratePixelShaderCode(bool dstAlphaEnable, API_TYPE ApiType,u32 components); -void GetPixelShaderId(PIXELSHADERUID *uid, u32 dstAlphaEnable); +// Different ways to achieve rendering with destination alpha +enum DSTALPHA_MODE +{ + DSTALPHA_NONE, // Render normally, without destination alpha + DSTALPHA_ALPHA_PASS, // Render normally first, then render again for alpha + DSTALPHA_DUAL_SOURCE_BLEND // Use dual-source blending +}; + +const char *GeneratePixelShaderCode(DSTALPHA_MODE dstAlphaMode, API_TYPE ApiType,u32 components); +void GetPixelShaderId(PIXELSHADERUID *uid, DSTALPHA_MODE dstAlphaMode); extern PIXELSHADERUID last_pixel_shader_uid; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/GfxState.cpp b/Source/Plugins/Plugin_VideoDX11/Src/GfxState.cpp index b9a3ca4b65..1138e10f13 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/GfxState.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/GfxState.cpp @@ -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) diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp index b63319f847..d83fba4dfd 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.cpp @@ -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)) diff --git a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h index bc4691d431..b1d114e3b4 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX11/Src/PixelShaderCache.h @@ -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(); diff --git a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp index 5ab0290b82..4219536a15 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/Render.cpp @@ -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 }; diff --git a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp index 6f9d90feb8..140a0214e6 100644 --- a/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX11/Src/VertexManager.cpp @@ -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; diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp index c5667dacc7..9ddfe06fe2 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.cpp @@ -273,10 +273,10 @@ void PixelShaderCache::Shutdown() unique_shaders.clear(); } -bool PixelShaderCache::SetShader(bool dstAlpha,u32 components) +bool PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) { PIXELSHADERUID uid; - GetPixelShaderId(&uid, dstAlpha ? 1 : 0); + GetPixelShaderId(&uid, dstAlphaMode); // Check if the shader is already set if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) @@ -308,7 +308,7 @@ bool PixelShaderCache::SetShader(bool dstAlpha,u32 components) } // Need to compile a new shader - const char *code = GeneratePixelShaderCode(dstAlpha, API_D3D9,components); + const char *code = GeneratePixelShaderCode(dstAlphaMode, API_D3D9, components); u32 code_hash = HashAdler32((const u8 *)code, strlen(code)); unique_shaders.insert(code_hash); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h index 713fc20557..7291749080 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoDX9/Src/PixelShaderCache.h @@ -60,7 +60,7 @@ private: public: static void Init(); static void Shutdown(); - static bool SetShader(bool dstAlpha, u32 componets); + static bool SetShader(DSTALPHA_MODE dstAlphaMode, u32 componets); static bool InsertByteCode(const PIXELSHADERUID &uid, const u8 *bytecode, int bytecodelen, bool activate); static LPDIRECT3DPIXELSHADER9 GetColorMatrixProgram(int SSAAMode); static LPDIRECT3DPIXELSHADER9 GetColorCopyProgram(int SSAAMode); diff --git a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp index 3153e84d5c..a134e55c41 100644 --- a/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoDX9/Src/VertexManager.cpp @@ -155,7 +155,7 @@ void VertexManager::vFlush() VertexShaderManager::SetConstants(); PixelShaderManager::SetConstants(); - if (!PixelShaderCache::SetShader(false,g_nativeVertexFmt->m_components)) + if (!PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components)) { DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");}); goto shader_fail; @@ -175,7 +175,7 @@ void VertexManager::vFlush() if (bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate) { DWORD write = 0; - if (!PixelShaderCache::SetShader(true, g_nativeVertexFmt->m_components)) + if (!PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS, g_nativeVertexFmt->m_components)) { DEBUGGER_PAUSE_LOG_AT(NEXT_ERROR,true,{printf("Fail to set pixel shader\n");}); goto shader_fail; diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp index 444daa9947..cb92316058 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.cpp @@ -184,11 +184,11 @@ void PixelShaderCache::Shutdown() PixelShaders.clear(); } -FRAGMENTSHADER* PixelShaderCache::SetShader(bool dstAlpha,u32 components) +FRAGMENTSHADER* PixelShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 components) { DVSTARTPROFILE(); PIXELSHADERUID uid; - GetPixelShaderId(&uid, dstAlpha ? 1 : 0); + GetPixelShaderId(&uid, dstAlphaMode); // Check if the shader is already set if (uid == last_pixel_shader_uid && PixelShaders[uid].frameCount == frameCount) @@ -216,7 +216,7 @@ FRAGMENTSHADER* PixelShaderCache::SetShader(bool dstAlpha,u32 components) PSCacheEntry& newentry = PixelShaders[uid]; newentry.frameCount = frameCount; pShaderLast = &newentry.shader; - const char *code = GeneratePixelShaderCode(dstAlpha,API_OPENGL,components); + const char *code = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL, components); #if defined(_DEBUG) || defined(DEBUGFAST) if (g_ActiveConfig.iLog & CONF_SAVESHADERS && code) { diff --git a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h index 0354cf228f..8fd4b63ee6 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h +++ b/Source/Plugins/Plugin_VideoOGL/Src/PixelShaderCache.h @@ -71,7 +71,7 @@ public: static void Init(); static void Shutdown(); - static FRAGMENTSHADER* SetShader(bool dstAlphaEnable,u32 components); + static FRAGMENTSHADER* SetShader(DSTALPHA_MODE dstAlphaMode, u32 components); static bool CompilePixelShader(FRAGMENTSHADER& ps, const char* pstrprogram); static GLuint GetColorMatrixProgram(); diff --git a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp index de6382b213..ef308524d7 100644 --- a/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp +++ b/Source/Plugins/Plugin_VideoOGL/Src/VertexManager.cpp @@ -185,7 +185,7 @@ void VertexManager::vFlush() PixelShaderManager::SetConstants(); // finally bind - FRAGMENTSHADER* ps = PixelShaderCache::SetShader(false,g_nativeVertexFmt->m_components); + FRAGMENTSHADER* ps = PixelShaderCache::SetShader(DSTALPHA_NONE,g_nativeVertexFmt->m_components); VERTEXSHADER* vs = VertexShaderCache::SetShader(g_nativeVertexFmt->m_components); if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // Lego Star Wars crashes here. if (vs) VertexShaderCache::SetCurrentShader(vs->glprogid); @@ -195,7 +195,9 @@ void VertexManager::vFlush() // run through vertex groups again to set alpha if (!g_ActiveConfig.bDstAlphaPass && bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate) { - ps = PixelShaderCache::SetShader(true,g_nativeVertexFmt->m_components); + // TODO: If host supports GL_ARB_blend_func_extended, use + // DSTALPHA_DUAL_SOURCE_BLEND and set blend modes accordingly. + ps = PixelShaderCache::SetShader(DSTALPHA_ALPHA_PASS,g_nativeVertexFmt->m_components); if (ps) PixelShaderCache::SetCurrentShader(ps->glprogid); // only update alpha