Commit 157f9374 by Geoff Lang

Update the RenderStateCache to use Error objects.

BUG=angle:520 Change-Id: I14e2a84c6d2e6f98a50395b63ac206e32bc10f8b Reviewed-on: https://chromium-review.googlesource.com/216918Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 5b5d1244
...@@ -79,12 +79,12 @@ bool RenderStateCache::compareBlendStates(const BlendStateKey &a, const BlendSta ...@@ -79,12 +79,12 @@ bool RenderStateCache::compareBlendStates(const BlendStateKey &a, const BlendSta
return memcmp(&a, &b, sizeof(BlendStateKey)) == 0; 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) if (!mDevice)
{ {
ERR("RenderStateCache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
return NULL;
} }
bool mrt = false; bool mrt = false;
...@@ -118,7 +118,8 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu ...@@ -118,7 +118,8 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu
{ {
BlendStateCounterPair &state = keyIter->second; BlendStateCounterPair &state = keyIter->second;
state.second = mCounter++; state.second = mCounter++;
return state.first; *outBlendState = state.first;
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
...@@ -170,13 +171,13 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu ...@@ -170,13 +171,13 @@ ID3D11BlendState *RenderStateCache::getBlendState(const gl::Framebuffer *framebu
HRESULT result = mDevice->CreateBlendState(&blendDesc, &dx11BlendState); HRESULT result = mDevice->CreateBlendState(&blendDesc, &dx11BlendState);
if (FAILED(result) || !dx11BlendState) if (FAILED(result) || !dx11BlendState)
{ {
ERR("Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result);
return NULL;
} }
mBlendStateCache.insert(std::make_pair(key, std::make_pair(dx11BlendState, mCounter++))); 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 ...@@ -194,12 +195,12 @@ bool RenderStateCache::compareRasterizerStates(const RasterizerStateKey &a, cons
return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0; 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) if (!mDevice)
{ {
ERR("RenderStateCache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
return NULL;
} }
RasterizerStateKey key = { 0 }; RasterizerStateKey key = { 0 };
...@@ -211,7 +212,8 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer ...@@ -211,7 +212,8 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer
{ {
RasterizerStateCounterPair &state = keyIter->second; RasterizerStateCounterPair &state = keyIter->second;
state.second = mCounter++; state.second = mCounter++;
return state.first; *outRasterizerState = state.first;
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
...@@ -265,13 +267,13 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer ...@@ -265,13 +267,13 @@ ID3D11RasterizerState *RenderStateCache::getRasterizerState(const gl::Rasterizer
HRESULT result = mDevice->CreateRasterizerState(&rasterDesc, &dx11RasterizerState); HRESULT result = mDevice->CreateRasterizerState(&rasterDesc, &dx11RasterizerState);
if (FAILED(result) || !dx11RasterizerState) if (FAILED(result) || !dx11RasterizerState)
{ {
ERR("Unable to create a ID3D11RasterizerState, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11RasterizerState, HRESULT: 0x%X.", result);
return NULL;
} }
mRasterizerStateCache.insert(std::make_pair(key, std::make_pair(dx11RasterizerState, mCounter++))); 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, ...@@ -289,12 +291,11 @@ bool RenderStateCache::compareDepthStencilStates(const gl::DepthStencilState &a,
return memcmp(&a, &b, sizeof(gl::DepthStencilState)) == 0; 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) if (!mDevice)
{ {
ERR("RenderStateCache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
return NULL;
} }
DepthStencilStateMap::iterator keyIter = mDepthStencilStateCache.find(dsState); DepthStencilStateMap::iterator keyIter = mDepthStencilStateCache.find(dsState);
...@@ -302,7 +303,8 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS ...@@ -302,7 +303,8 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS
{ {
DepthStencilStateCounterPair &state = keyIter->second; DepthStencilStateCounterPair &state = keyIter->second;
state.second = mCounter++; state.second = mCounter++;
return state.first; *outDSState = state.first;
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
...@@ -343,13 +345,13 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS ...@@ -343,13 +345,13 @@ ID3D11DepthStencilState *RenderStateCache::getDepthStencilState(const gl::DepthS
HRESULT result = mDevice->CreateDepthStencilState(&dsDesc, &dx11DepthStencilState); HRESULT result = mDevice->CreateDepthStencilState(&dsDesc, &dx11DepthStencilState);
if (FAILED(result) || !dx11DepthStencilState) if (FAILED(result) || !dx11DepthStencilState)
{ {
ERR("Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result);
return NULL;
} }
mDepthStencilStateCache.insert(std::make_pair(dsState, std::make_pair(dx11DepthStencilState, mCounter++))); 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: ...@@ -367,12 +369,11 @@ bool RenderStateCache::compareSamplerStates(const gl::SamplerState &a, const gl:
return memcmp(&a, &b, sizeof(gl::SamplerState)) == 0; 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) if (!mDevice)
{ {
ERR("RenderStateCache is not initialized."); return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
return NULL;
} }
SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState); SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState);
...@@ -380,7 +381,8 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa ...@@ -380,7 +381,8 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa
{ {
SamplerStateCounterPair &state = keyIter->second; SamplerStateCounterPair &state = keyIter->second;
state.second = mCounter++; state.second = mCounter++;
return state.first; *outSamplerState = state.first;
return gl::Error(GL_NO_ERROR);
} }
else else
{ {
...@@ -421,13 +423,13 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa ...@@ -421,13 +423,13 @@ ID3D11SamplerState *RenderStateCache::getSamplerState(const gl::SamplerState &sa
HRESULT result = mDevice->CreateSamplerState(&samplerDesc, &dx11SamplerState); HRESULT result = mDevice->CreateSamplerState(&samplerDesc, &dx11SamplerState);
if (FAILED(result) || !dx11SamplerState) if (FAILED(result) || !dx11SamplerState)
{ {
ERR("Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11SamplerState, HRESULT: 0x%X.", result);
return NULL;
} }
mSamplerStateCache.insert(std::make_pair(samplerState, std::make_pair(dx11SamplerState, mCounter++))); mSamplerStateCache.insert(std::make_pair(samplerState, std::make_pair(dx11SamplerState, mCounter++)));
return dx11SamplerState; *outSamplerState = dx11SamplerState;
return gl::Error(GL_NO_ERROR);
} }
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_ #define LIBGLESV2_RENDERER_RENDERSTATECACHE_H_
#include "libGLESv2/angletypes.h" #include "libGLESv2/angletypes.h"
#include "libGLESv2/Error.h"
#include "common/angleutils.h" #include "common/angleutils.h"
#include <unordered_map> #include <unordered_map>
...@@ -33,10 +34,10 @@ class RenderStateCache ...@@ -33,10 +34,10 @@ class RenderStateCache
void initialize(ID3D11Device *device); void initialize(ID3D11Device *device);
void clear(); void clear();
ID3D11BlendState *getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState); gl::Error getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState, ID3D11BlendState **outBlendState);
ID3D11RasterizerState *getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled); gl::Error getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled, ID3D11RasterizerState **outRasterizerState);
ID3D11DepthStencilState *getDepthStencilState(const gl::DepthStencilState &dsState); gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, ID3D11DepthStencilState **outDSState);
ID3D11SamplerState *getSamplerState(const gl::SamplerState &samplerState); gl::Error getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState);
private: private:
DISALLOW_COPY_AND_ASSIGN(RenderStateCache); DISALLOW_COPY_AND_ASSIGN(RenderStateCache);
......
...@@ -427,12 +427,13 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -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) if (mForceSetPixelSamplerStates[index] || memcmp(&samplerState, &mCurPixelSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{ {
ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); ID3D11SamplerState *dxSamplerState = NULL;
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
if (!dxSamplerState) if (error.isError())
{ {
ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default"
"sampler state for pixel shaders at slot %i.", index); "sampler state for pixel shaders at slot %i.", index);
dxSamplerState = NULL;
} }
mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->PSSetSamplers(index, 1, &dxSamplerState);
...@@ -448,12 +449,13 @@ void Renderer11::setSamplerState(gl::SamplerType type, int index, const gl::Samp ...@@ -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) if (mForceSetVertexSamplerStates[index] || memcmp(&samplerState, &mCurVertexSamplerStates[index], sizeof(gl::SamplerState)) != 0)
{ {
ID3D11SamplerState *dxSamplerState = mStateCache.getSamplerState(samplerState); ID3D11SamplerState *dxSamplerState = NULL;
gl::Error error = mStateCache.getSamplerState(samplerState, &dxSamplerState);
if (!dxSamplerState) if (error.isError())
{ {
ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default" ERR("NULL sampler state returned by RenderStateCache::getSamplerState, setting the default"
"sampler state for vertex shaders at slot %i.", index); "sampler state for vertex shaders at slot %i.", index);
dxSamplerState = NULL;
} }
mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState); mDeviceContext->VSSetSamplers(index, 1, &dxSamplerState);
...@@ -570,11 +572,13 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState) ...@@ -570,11 +572,13 @@ void Renderer11::setRasterizerState(const gl::RasterizerState &rasterState)
{ {
if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0) if (mForceSetRasterState || memcmp(&rasterState, &mCurRasterState, sizeof(gl::RasterizerState)) != 0)
{ {
ID3D11RasterizerState *dxRasterState = mStateCache.getRasterizerState(rasterState, mScissorEnabled); ID3D11RasterizerState *dxRasterState = NULL;
if (!dxRasterState) gl::Error error = mStateCache.getRasterizerState(rasterState, mScissorEnabled, &dxRasterState);
if (error.isError())
{ {
ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default" ERR("NULL rasterizer state returned by RenderStateCache::getRasterizerState, setting the default"
"rasterizer state."); "rasterizer state.");
dxRasterState = NULL;
} }
mDeviceContext->RSSetState(dxRasterState); mDeviceContext->RSSetState(dxRasterState);
...@@ -593,11 +597,13 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat ...@@ -593,11 +597,13 @@ void Renderer11::setBlendState(gl::Framebuffer *framebuffer, const gl::BlendStat
memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 || memcmp(&blendColor, &mCurBlendColor, sizeof(gl::ColorF)) != 0 ||
sampleMask != mCurSampleMask) sampleMask != mCurSampleMask)
{ {
ID3D11BlendState *dxBlendState = mStateCache.getBlendState(framebuffer, blendState); ID3D11BlendState *dxBlendState = NULL;
if (!dxBlendState) gl::Error error = mStateCache.getBlendState(framebuffer, blendState, &dxBlendState);
if (error.isError())
{ {
ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default " ERR("NULL blend state returned by RenderStateCache::getBlendState, setting the default "
"blend state."); "blend state.");
dxBlendState = NULL;
} }
float blendColors[4] = {0.0f}; float blendColors[4] = {0.0f};
...@@ -638,11 +644,13 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS ...@@ -638,11 +644,13 @@ void Renderer11::setDepthStencilState(const gl::DepthStencilState &depthStencilS
ASSERT(stencilRef == stencilBackRef); ASSERT(stencilRef == stencilBackRef);
ASSERT(depthStencilState.stencilMask == depthStencilState.stencilBackMask); ASSERT(depthStencilState.stencilMask == depthStencilState.stencilBackMask);
ID3D11DepthStencilState *dxDepthStencilState = mStateCache.getDepthStencilState(depthStencilState); ID3D11DepthStencilState *dxDepthStencilState = NULL;
if (!dxDepthStencilState) gl::Error error = mStateCache.getDepthStencilState(depthStencilState, &dxDepthStencilState);
if (error.isError())
{ {
ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, " ERR("NULL depth stencil state returned by RenderStateCache::getDepthStencilState, "
"setting the default depth stencil state."); "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 // Max D3D11 stencil reference value is 0xFF, corresponding to the max 8 bits in a stencil buffer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment