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
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);
}
}
......
......@@ -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);
......
......@@ -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
......
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