From df94914a63afdfe89cef870caa7d92aca4a57a5a Mon Sep 17 00:00:00 2001 From: Henrik Rydgard Date: Sun, 8 Nov 2015 22:50:16 +0100 Subject: [PATCH] D3D: No need to convert blendcolor to float and back Fix bug with constantAlpha Remove misleading comment, thanks unknown --- GPU/Common/GPUStateUtils.cpp | 17 ++++++++--------- GPU/Common/GPUStateUtils.h | 4 ++-- GPU/Directx9/StateMappingDX9.cpp | 15 +++------------ GPU/Directx9/helper/dx_state.h | 7 +++++++ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/GPU/Common/GPUStateUtils.cpp b/GPU/Common/GPUStateUtils.cpp index 151f97a567..d5fedcd25b 100644 --- a/GPU/Common/GPUStateUtils.cpp +++ b/GPU/Common/GPUStateUtils.cpp @@ -459,7 +459,6 @@ void ConvertViewportAndScissor(bool useBufferedRendering, float renderWidth, flo float offsetY = gstate.getOffsetY(); if (throughmode) { - // No viewport transform here. Let's experiment with using region. out.viewportX = renderX + displayOffsetX; out.viewportY = renderY + displayOffsetY; out.viewportW = curRTWidth * renderWidthFactor; @@ -800,7 +799,7 @@ void ConvertBlendState(GenericBlendState &blendState) { blendState.applyShaderBlending = true; blendState.resetShaderBlending = false; blendState.replaceAlphaWithStencil = replaceAlphaWithStencil; - break; // Surely this should be return?? + break; case REPLACE_BLEND_PRE_SRC: case REPLACE_BLEND_PRE_SRC_2X_ALPHA: @@ -827,22 +826,22 @@ void ConvertBlendState(GenericBlendState &blendState) { if (blendFuncB > GE_DSTBLEND_FIXB) blendFuncB = GE_DSTBLEND_FIXB; - float constantAlpha = 1.0f; + int constantAlpha = 255; BlendFactor constantAlphaGL = BlendFactor::ONE; if (gstate.isStencilTestEnabled() && replaceAlphaWithStencil == REPLACE_ALPHA_NO) { switch (ReplaceAlphaWithStencilType()) { case STENCIL_VALUE_UNIFORM: - constantAlpha = (float)gstate.getStencilTestRef() * (1.0f / 255.0f); + constantAlpha = gstate.getStencilTestRef(); break; case STENCIL_VALUE_INCR_4: case STENCIL_VALUE_DECR_4: - constantAlpha = 1.0f / 15.0f; + constantAlpha = 16; break; case STENCIL_VALUE_INCR_8: case STENCIL_VALUE_DECR_8: - constantAlpha = 1.0f / 255.0f; + constantAlpha = 1; break; default: @@ -850,9 +849,9 @@ void ConvertBlendState(GenericBlendState &blendState) { } // Otherwise it will stay GL_ONE. - if (constantAlpha <= 0.0f) { + if (constantAlpha <= 0) { constantAlphaGL = BlendFactor::ZERO; - } else if (constantAlpha < 1.0f) { + } else if (constantAlpha < 255) { constantAlphaGL = BlendFactor::CONSTANT_ALPHA; } } @@ -945,7 +944,7 @@ void ConvertBlendState(GenericBlendState &blendState) { } } - // Some Android devices (especially Mali, it seems) composite badly if there's alpha in the backbuffer. + // Some Android devices (especially old Mali, it seems) composite badly if there's alpha in the backbuffer. // So in non-buffered rendering, we will simply consider the dest alpha to be zero in blending equations. #ifdef ANDROID if (g_Config.iRenderingMode == FB_NON_BUFFERED_MODE) { diff --git a/GPU/Common/GPUStateUtils.h b/GPU/Common/GPUStateUtils.h index 047fef6387..58eda73d96 100644 --- a/GPU/Common/GPUStateUtils.h +++ b/GPU/Common/GPUStateUtils.h @@ -126,11 +126,11 @@ struct GenericBlendState { eqAlpha = eqA; } void setBlendColor(uint32_t color, uint8_t alpha) { - blendColor = color | (alpha << 24); + blendColor = color | ((uint32_t)alpha << 24); useBlendColor = true; } void defaultBlendColor(uint8_t alpha) { - blendColor = 0xFFFFFF | (alpha << 24); + blendColor = 0xFFFFFF | ((uint32_t)alpha << 24); useBlendColor = true; } }; diff --git a/GPU/Directx9/StateMappingDX9.cpp b/GPU/Directx9/StateMappingDX9.cpp index df901223e0..d55d1e245f 100644 --- a/GPU/Directx9/StateMappingDX9.cpp +++ b/GPU/Directx9/StateMappingDX9.cpp @@ -166,30 +166,21 @@ void TransformDrawEngineDX9::ApplyDrawState(int prim) { shaderManager_->DirtyUniform(DIRTY_SHADERBLEND); } if (blendState.useBlendColor) { - uint32_t color = blendState.blendColor; - const float col[4] = { - (float)((color & 0xFF) >> 0) * (1.0f / 255.0f), - (float)((color & 0xFF00) >> 8) * (1.0f / 255.0f), - (float)((color & 0xFF0000) >> 16) * (1.0f / 255.0f), - (float)((color & 0xFF000000) >> 24) * (1.0f / 255.0f), - }; - dxstate.blendColor.set(col); + dxstate.blendColor.setDWORD(blendState.blendColor); } } else { dxstate.blend.disable(); - dxstate.blendSeparate.disable(); } // Set Dither if (gstate.isDitherEnabled()) { dxstate.dither.enable(); - dxstate.dither.set(true); - } else + } else { dxstate.dither.disable(); + } // Set ColorMask/Stencil/Depth if (gstate.isModeClear()) { - // Set Cull dxstate.cullMode.set(false, false); diff --git a/GPU/Directx9/helper/dx_state.h b/GPU/Directx9/helper/dx_state.h index 3a74f669eb..04a2477228 100644 --- a/GPU/Directx9/helper/dx_state.h +++ b/GPU/Directx9/helper/dx_state.h @@ -269,6 +269,13 @@ private: restore(); } } + void setDWORD(DWORD newc) { + newc = ((newc >> 8) & 0xff) | (newc & 0xff00ff00) | ((newc << 16) & 0xff0000); // ARGB -> ABGR fix + if (c != newc) { + c = newc; + restore(); + } + } void force(const float v[4]) { DWORD old = c; set(v);