diff options
author | Geoff Lang <geofflang@chromium.org> | 2014-09-08 15:16:28 -0400 |
---|---|---|
committer | Geoff Lang <geofflang@chromium.org> | 2014-09-10 17:57:20 +0000 |
commit | 157f9374e8e2d4b94569a6b2b496faddedca70ed (patch) | |
tree | e5d7c9ae7b7283d880970c4af4d09198ac87c3b5 | |
parent | 5b5d1244d9089bb4a9e74cc34265a524b84ec258 (diff) | |
download | angle-157f9374e8e2d4b94569a6b2b496faddedca70ed.tar.gz |
Update the RenderStateCache to use Error objects.
BUG=angle:520
Change-Id: I14e2a84c6d2e6f98a50395b63ac206e32bc10f8b
Reviewed-on: https://chromium-review.googlesource.com/216918
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
-rw-r--r-- | src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp | 58 | ||||
-rw-r--r-- | src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h | 9 | ||||
-rw-r--r-- | src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp | 32 |
3 files changed, 55 insertions, 44 deletions
diff --git a/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp b/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp index b4a8be23..71b931f2 100644 --- a/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp +++ b/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.cpp @@ -79,12 +79,12 @@ bool RenderStateCache::compareBlendStates(const BlendStateKey &a, const BlendSta return memcmp(&a, &b, sizeof(BlendStateKey)) == 0; } -ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState) +gl::Error RenderStateCache::getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, + ID3D11BlendState **outBlendState) { if (!mDevice) { - ERR("RenderStateCache is not initialized."); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized."); } bool mrt = false; @@ -118,7 +118,8 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu { BlendStateCounterPair &state = keyIter->second; state.second = mCounter++; - return state.first; + *outBlendState = state.first; + return gl::Error(GL_NO_ERROR); } else { @@ -170,13 +171,13 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu HRESULT result = mDevice->CreateBlendState(&blendDesc, &dx11BlendState); if (FAILED(result) || !dx11BlendState) { - ERR("Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result); } mBlendStateCache.insert(std::make_pair(key, std::make_pair(dx11BlendState, mCounter++))); - return dx11BlendState; + *outBlendState = dx11BlendState; + return gl::Error(GL_NO_ERROR); } } @@ -194,12 +195,12 @@ bool RenderStateCache::compareRasterizerStates(const RasterizerStateKey &a, cons return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0; } -ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled) +gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, + ID3D11RasterizerState **outRasterizerState) { if (!mDevice) { - ERR("RenderStateCache is not initialized."); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized."); } RasterizerStateKey key = { 0 }; @@ -211,7 +212,8 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer { RasterizerStateCounterPair &state = keyIter->second; state.second = mCounter++; - return state.first; + *outRasterizerState = state.first; + return gl::Error(GL_NO_ERROR); } else { @@ -265,13 +267,13 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer HRESULT result = mDevice->CreateRasterizerState(&rasterDesc, &dx11RasterizerState); if (FAILED(result) || !dx11RasterizerState) { - ERR("Unable to create a ID3D11RasterizerState, HRESULT: 0x%X.", result); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11RasterizerState, HRESULT: 0x%X.", result); } mRasterizerStateCache.insert(std::make_pair(key, std::make_pair(dx11RasterizerState, mCounter++))); - return dx11RasterizerState; + *outRasterizerState = dx11RasterizerState; + return gl::Error(GL_NO_ERROR); } } @@ -289,12 +291,11 @@ bool RenderStateCache::compareDepthStencilStates(const gl::DepthStencilState &a, return memcmp(&a, &b, sizeof(gl::DepthStencilState)) == 0; } -ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthStencilState &dsState) +gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &dsState, ID3D11DepthStencilState **outDSState) { if (!mDevice) { - ERR("RenderStateCache is not initialized."); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized."); } DepthStencilStateMap::iterator keyIter = mDepthStencilStateCache.find(dsState); @@ -302,7 +303,8 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS { DepthStencilStateCounterPair &state = keyIter->second; state.second = mCounter++; - return state.first; + *outDSState = state.first; + return gl::Error(GL_NO_ERROR); } else { @@ -343,13 +345,13 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS HRESULT result = mDevice->CreateDepthStencilState(&dsDesc, &dx11DepthStencilState); if (FAILED(result) || !dx11DepthStencilState) { - ERR("Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result); } mDepthStencilStateCache.insert(std::make_pair(dsState, std::make_pair(dx11DepthStencilState, mCounter++))); - return dx11DepthStencilState; + *outDSState = dx11DepthStencilState; + return gl::Error(GL_NO_ERROR); } } @@ -367,12 +369,11 @@ bool RenderStateCache::compareSamplerStates(const gl::SamplerState &a, const gl: return memcmp(&a, &b, sizeof(gl::SamplerState)) == 0; } -ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &samplerState) +gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState) { if (!mDevice) { - ERR("RenderStateCache is not initialized."); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized."); } SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState); @@ -380,7 +381,8 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa { SamplerStateCounterPair &state = keyIter->second; state.second = mCounter++; - return state.first; + *outSamplerState = state.first; + return gl::Error(GL_NO_ERROR); } else { @@ -421,13 +423,13 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa HRESULT result = mDevice->CreateSamplerState(&samplerDesc, &dx11SamplerState); if (FAILED(result) || !dx11SamplerState) { - ERR("Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result); - return NULL; + return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11SamplerState, HRESULT: 0x%X.", result); } mSamplerStateCache.insert(std::make_pair(samplerState, std::make_pair(dx11SamplerState, mCounter++))); - return dx11SamplerState; + *outSamplerState = dx11SamplerState; + return gl::Error(GL_NO_ERROR); } } diff --git a/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h b/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h index cc0688e7..d5471a30 100644 --- a/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h +++ b/src/libGLESv2/renderer/d3d/d3d11/RenderStateCache.h @@ -11,6 +11,7 @@ #define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_ #include "libGLESv2/angletypes.h" +#include "libGLESv2/Error.h" #include "common/angleutils.h" #include <unordered_map> @@ -33,10 +34,10 @@ class RenderStateCache void initialize(ID3D11Device *device); void clear(); - ID3D11BlendState *getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState); - ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled); - ID3D11DepthStencilState *getDepthStencilState(const gl::DepthStencilState &dsState); - ID3D11SamplerState *getSamplerState(const gl::SamplerState &samplerState); + gl::Error getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, ID3D11BlendState **outBlendState); + gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState); + gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, ID3D11DepthStencilState **outDSState); + gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState); private: DISALLOW_COPY_AND_ASSIGN(RenderStateCache); diff --git a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp index b9de4caa..9bb2c5c4 100644 --- a/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp +++ b/src/libGLESv2/renderer/d3d/d3d11/Renderer11.cpp @@ -427,12 +427,13 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0) { - ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); - - if (!dxSamplerState) + ID3D11SamplerState *dxSamplerState = NULL; + gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState); + if (error.isError()) { ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" "sampler state for pixel shaders at slot %i.", index); + dxSamplerState = NULL; } mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); @@ -448,12 +449,13 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0) { - ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); - - if (!dxSamplerState) + ID3D11SamplerState *dxSamplerState = NULL; + gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState); + if (error.isError()) { ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" "sampler state for vertex shaders at slot %i.", index); + dxSamplerState = NULL; } mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); @@ -570,11 +572,13 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) { if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) { - ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled); - if (!dxRasterState) + ID3D11RasterizerState *dxRasterState = NULL; + gl::Error error = mStateCache.getRasterizerState(rasterState, mScissorEnabled, &dxRasterState); + if (error.isError()) { ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default" "rasterizer state."); + dxRasterState = NULL; } mDeviceContext->RSSetState(dxRasterState); @@ -593,11 +597,13 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 || sampleMask != mCurSampleMask) { - ID3D11BlendState *dxBlendState = mStateCache.getBlendState(framebuffer, blendState); - if (!dxBlendState) + ID3D11BlendState *dxBlendState = NULL; + gl::Error error = mStateCache.getBlendState(framebuffer, blendState, &dxBlendState); + if (error.isError()) { ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " "blend state."); + dxBlendState = NULL; } float blendColors[4] = {0.0f}; @@ -638,11 +644,13 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS ASSERT(stencilRef == stencilBackRef); ASSERT(depthStencilState.stencilMask == depthStencilState.stencilBackMask); - ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); - if (!dxDepthStencilState) + ID3D11DepthStencilState *dxDepthStencilState = NULL; + gl::Error error = mStateCache.getDepthStencilState(depthStencilState, &dxDepthStencilState); + if (error.isError()) { ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " "setting the default depth stencil state."); + dxDepthStencilState = NULL; } // Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer |