Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / libGLESv2 / renderer / d3d11 / RenderStateCache.cpp
index ad24d5e..0047e04 100644 (file)
@@ -11,6 +11,9 @@
 #include "libGLESv2/renderer/d3d11/RenderStateCache.h"
 #include "libGLESv2/renderer/d3d11/renderer11_utils.h"
 
+#include "libGLESv2/Framebuffer.h"
+#include "libGLESv2/Renderbuffer.h"
+#include "libGLESv2/utilities.h"
 #include "common/debug.h"
 #include "third_party/murmurhash/MurmurHash3.h"
 
@@ -71,21 +74,21 @@ void RenderStateCache::clear()
     mSamplerStateCache.clear();
 }
 
-std::size_t RenderStateCache::hashBlendState(const gl::BlendState &blendState)
+std::size_t RenderStateCache::hashBlendState(const BlendStateKey &blendState)
 {
     static const unsigned int seed = 0xABCDEF98;
 
     std::size_t hash = 0;
-    MurmurHash3_x86_32(&blendState, sizeof(gl::BlendState), seed, &hash);
+    MurmurHash3_x86_32(&blendState, sizeof(BlendStateKey), seed, &hash);
     return hash;
 }
 
-bool RenderStateCache::compareBlendStates(const gl::BlendState &a, const gl::BlendState &b)
+bool RenderStateCache::compareBlendStates(const BlendStateKey &a, const BlendStateKey &b)
 {
     return memcmp(&a, &b, sizeof(gl::BlendState)) == 0;
 }
 
-ID3D11BlendState *RenderStateCache::getBlendState(const gl::BlendState &blendState)
+ID3D11BlendState *RenderStateCache::getBlendState(gl::Framebuffer *framebuffer, const gl::BlendState &blendState)
 {
     if (!mDevice)
     {
@@ -93,7 +96,36 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::BlendState &blendSta
         return NULL;
     }
 
-    BlendStateMap::iterator i = mBlendStateCache.find(blendState);
+    bool mrt = false;
+
+    BlendStateKey key = { 0 };
+    key.blendState = blendState;
+    for (unsigned int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
+    {
+        gl::Renderbuffer *renderBuffer = framebuffer->getColorbuffer(i);
+        if (renderBuffer)
+        {
+            if (i > 0)
+            {
+                mrt = true;
+            }
+
+            GLenum internalFormat = renderBuffer->getInternalFormat();
+            key.rtChannels[i][0] = gl::GetRedSize(internalFormat) > 0;
+            key.rtChannels[i][1] = gl::GetGreenSize(internalFormat) > 0;
+            key.rtChannels[i][2] = gl::GetBlueSize(internalFormat) > 0;;
+            key.rtChannels[i][3] = gl::GetAlphaSize(internalFormat) > 0;
+        }
+        else
+        {
+            key.rtChannels[i][0] = false;
+            key.rtChannels[i][1] = false;
+            key.rtChannels[i][2] = false;
+            key.rtChannels[i][3] = false;
+        }
+    }
+
+    BlendStateMap::iterator i = mBlendStateCache.find(key);
     if (i != mBlendStateCache.end())
     {
         BlendStateCounterPair &state = i->second;
@@ -122,7 +154,7 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::BlendState &blendSta
         // Create a new blend state and insert it into the cache
         D3D11_BLEND_DESC blendDesc = { 0 };
         blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage;
-        blendDesc.IndependentBlendEnable = FALSE;
+        blendDesc.IndependentBlendEnable = mrt ? TRUE : FALSE;
 
         for (unsigned int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
         {
@@ -140,10 +172,10 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::BlendState &blendSta
                 rtBlend.BlendOpAlpha = gl_d3d11::ConvertBlendOp(blendState.blendEquationAlpha);
             }
 
-            rtBlend.RenderTargetWriteMask = gl_d3d11::ConvertColorMask(blendState.colorMaskRed,
-                                                                       blendState.colorMaskGreen,
-                                                                       blendState.colorMaskBlue,
-                                                                       blendState.colorMaskAlpha);
+            rtBlend.RenderTargetWriteMask = gl_d3d11::ConvertColorMask(key.rtChannels[i][0] && blendState.colorMaskRed,
+                                                                       key.rtChannels[i][1] && blendState.colorMaskGreen,
+                                                                       key.rtChannels[i][2] && blendState.colorMaskBlue,
+                                                                       key.rtChannels[i][3] && blendState.colorMaskAlpha);
         }
 
         ID3D11BlendState *dx11BlendState = NULL;
@@ -154,7 +186,7 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::BlendState &blendSta
             return NULL;
         }
 
-        mBlendStateCache.insert(std::make_pair(blendState, std::make_pair(dx11BlendState, mCounter++)));
+        mBlendStateCache.insert(std::make_pair(key, std::make_pair(dx11BlendState, mCounter++)));
 
         return dx11BlendState;
     }