summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp')
-rw-r--r--src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp521
1 files changed, 161 insertions, 360 deletions
diff --git a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp
index 2ee25cfb6c..5b85196c2e 100644
--- a/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp
+++ b/src/3rdparty/angle/src/libANGLE/renderer/d3d/d3d11/RenderStateCache.cpp
@@ -17,338 +17,180 @@
#include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
-#include "third_party/murmurhash/MurmurHash3.h"
namespace rx
{
using namespace gl_d3d11;
-template <typename mapType>
-static void ClearStateMap(mapType &map)
-{
- for (typename mapType::iterator i = map.begin(); i != map.end(); i++)
- {
- SafeRelease(i->second.first);
- }
- map.clear();
-}
-
-// MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState,
-// ID3D11Device::CreateDepthStencilState and ID3D11Device::CreateSamplerState claims the maximum
-// number of unique states of each type an application can create is 4096
-const unsigned int RenderStateCache::kMaxBlendStates = 4096;
-const unsigned int RenderStateCache::kMaxRasterizerStates = 4096;
-const unsigned int RenderStateCache::kMaxDepthStencilStates = 4096;
-const unsigned int RenderStateCache::kMaxSamplerStates = 4096;
-
-RenderStateCache::RenderStateCache(Renderer11 *renderer)
- : mRenderer(renderer),
- mCounter(0),
- mBlendStateCache(kMaxBlendStates, hashBlendState, compareBlendStates),
- mRasterizerStateCache(kMaxRasterizerStates, hashRasterizerState, compareRasterizerStates),
- mDepthStencilStateCache(kMaxDepthStencilStates, hashDepthStencilState, compareDepthStencilStates),
- mSamplerStateCache(kMaxSamplerStates, hashSamplerState, compareSamplerStates),
- mDevice(NULL)
+RenderStateCache::RenderStateCache()
+ : mBlendStateCache(kMaxStates),
+ mRasterizerStateCache(kMaxStates),
+ mDepthStencilStateCache(kMaxStates),
+ mSamplerStateCache(kMaxStates)
{
}
RenderStateCache::~RenderStateCache()
{
- clear();
-}
-
-void RenderStateCache::initialize(ID3D11Device *device)
-{
- clear();
- mDevice = device;
}
void RenderStateCache::clear()
{
- ClearStateMap(mBlendStateCache);
- ClearStateMap(mRasterizerStateCache);
- ClearStateMap(mDepthStencilStateCache);
- ClearStateMap(mSamplerStateCache);
+ mBlendStateCache.Clear();
+ mRasterizerStateCache.Clear();
+ mDepthStencilStateCache.Clear();
+ mSamplerStateCache.Clear();
}
-std::size_t RenderStateCache::hashBlendState(const BlendStateKey &blendState)
+// static
+d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *context,
+ const gl::Framebuffer *framebuffer,
+ const gl::BlendState &blendState)
{
- static const unsigned int seed = 0xABCDEF98;
-
- std::size_t hash = 0;
- MurmurHash3_x86_32(&blendState, sizeof(gl::BlendState), seed, &hash);
- return hash;
-}
+ d3d11::BlendStateKey key;
+ FramebufferD3D *framebufferD3D = GetImplAs<FramebufferD3D>(framebuffer);
+ const gl::AttachmentList &colorbuffers = framebufferD3D->getColorAttachmentsForRender(context);
+ const UINT8 blendStateMask =
+ gl_d3d11::ConvertColorMask(blendState.colorMaskRed, blendState.colorMaskGreen,
+ blendState.colorMaskBlue, blendState.colorMaskAlpha);
-bool RenderStateCache::compareBlendStates(const BlendStateKey &a, const BlendStateKey &b)
-{
- return memcmp(&a, &b, sizeof(BlendStateKey)) == 0;
-}
-
-gl::Error RenderStateCache::getBlendState(const gl::Framebuffer *framebuffer, const gl::BlendState &blendState,
- ID3D11BlendState **outBlendState)
-{
- if (!mDevice)
- {
- return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
- }
-
- bool mrt = false;
-
- const FramebufferD3D *framebufferD3D = GetImplAs<FramebufferD3D>(framebuffer);
- const gl::AttachmentList &colorbuffers = framebufferD3D->getColorAttachmentsForRender();
-
- BlendStateKey key = {};
key.blendState = blendState;
- for (size_t colorAttachment = 0; colorAttachment < colorbuffers.size(); ++colorAttachment)
- {
- const gl::FramebufferAttachment *attachment = colorbuffers[colorAttachment];
- auto rtChannels = key.rtChannels[colorAttachment];
+ for (size_t i = 0; i < colorbuffers.size(); i++)
+ {
+ const gl::FramebufferAttachment *attachment = colorbuffers[i];
if (attachment)
{
- if (colorAttachment > 0)
- {
- mrt = true;
- }
-
- rtChannels[0] = attachment->getRedSize() > 0;
- rtChannels[1] = attachment->getGreenSize() > 0;
- rtChannels[2] = attachment->getBlueSize() > 0;
- rtChannels[3] = attachment->getAlphaSize() > 0;
+ key.rtvMax = static_cast<uint32_t>(i) + 1;
+ key.rtvMasks[i] =
+ (gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask;
}
}
- BlendStateMap::iterator keyIter = mBlendStateCache.find(key);
+ return key;
+}
+
+gl::Error RenderStateCache::getBlendState(Renderer11 *renderer,
+ const d3d11::BlendStateKey &key,
+ const d3d11::BlendState **outBlendState)
+{
+ auto keyIter = mBlendStateCache.Get(key);
if (keyIter != mBlendStateCache.end())
{
- BlendStateCounterPair &state = keyIter->second;
- state.second = mCounter++;
- *outBlendState = state.first;
- return gl::Error(GL_NO_ERROR);
+ *outBlendState = &keyIter->second;
+ return gl::NoError();
}
- else
- {
- if (mBlendStateCache.size() >= kMaxBlendStates)
- {
- TRACE("Overflowed the limit of %u blend states, removing the least recently used "
- "to make room.", kMaxBlendStates);
-
- BlendStateMap::iterator leastRecentlyUsed = mBlendStateCache.begin();
- for (BlendStateMap::iterator i = mBlendStateCache.begin(); i != mBlendStateCache.end(); i++)
- {
- if (i->second.second < leastRecentlyUsed->second.second)
- {
- leastRecentlyUsed = i;
- }
- }
- SafeRelease(leastRecentlyUsed->second.first);
- mBlendStateCache.erase(leastRecentlyUsed);
- }
- // Create a new blend state and insert it into the cache
- D3D11_BLEND_DESC blendDesc = { 0 };
- blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage;
- blendDesc.IndependentBlendEnable = mrt ? TRUE : FALSE;
+ TrimCache(kMaxStates, kGCLimit, "blend state", &mBlendStateCache);
- for (unsigned int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
- {
- D3D11_RENDER_TARGET_BLEND_DESC &rtBlend = blendDesc.RenderTarget[i];
-
- rtBlend.BlendEnable = blendState.blend;
- if (blendState.blend)
- {
- rtBlend.SrcBlend = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendRGB, false);
- rtBlend.DestBlend = gl_d3d11::ConvertBlendFunc(blendState.destBlendRGB, false);
- rtBlend.BlendOp = gl_d3d11::ConvertBlendOp(blendState.blendEquationRGB);
-
- rtBlend.SrcBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendAlpha, true);
- rtBlend.DestBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.destBlendAlpha, true);
- rtBlend.BlendOpAlpha = gl_d3d11::ConvertBlendOp(blendState.blendEquationAlpha);
- }
-
- 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);
- }
+ // Create a new blend state and insert it into the cache
+ D3D11_BLEND_DESC blendDesc;
+ D3D11_RENDER_TARGET_BLEND_DESC &rtDesc0 = blendDesc.RenderTarget[0];
+ const gl::BlendState &blendState = key.blendState;
- ID3D11BlendState *dx11BlendState = NULL;
- HRESULT result = mDevice->CreateBlendState(&blendDesc, &dx11BlendState);
- if (FAILED(result) || !dx11BlendState)
- {
- return gl::Error(GL_OUT_OF_MEMORY, "Unable to create a ID3D11BlendState, HRESULT: 0x%X.", result);
- }
+ blendDesc.AlphaToCoverageEnable = blendState.sampleAlphaToCoverage;
+ blendDesc.IndependentBlendEnable = key.rtvMax > 1 ? TRUE : FALSE;
- mBlendStateCache.insert(std::make_pair(key, std::make_pair(dx11BlendState, mCounter++)));
+ rtDesc0 = {};
- *outBlendState = dx11BlendState;
- return gl::Error(GL_NO_ERROR);
+ if (blendState.blend)
+ {
+ rtDesc0.BlendEnable = true;
+ rtDesc0.SrcBlend = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendRGB, false);
+ rtDesc0.DestBlend = gl_d3d11::ConvertBlendFunc(blendState.destBlendRGB, false);
+ rtDesc0.BlendOp = gl_d3d11::ConvertBlendOp(blendState.blendEquationRGB);
+ rtDesc0.SrcBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.sourceBlendAlpha, true);
+ rtDesc0.DestBlendAlpha = gl_d3d11::ConvertBlendFunc(blendState.destBlendAlpha, true);
+ rtDesc0.BlendOpAlpha = gl_d3d11::ConvertBlendOp(blendState.blendEquationAlpha);
}
-}
-std::size_t RenderStateCache::hashRasterizerState(const RasterizerStateKey &rasterState)
-{
- static const unsigned int seed = 0xABCDEF98;
+ rtDesc0.RenderTargetWriteMask = key.rtvMasks[0];
- std::size_t hash = 0;
- MurmurHash3_x86_32(&rasterState, sizeof(RasterizerStateKey), seed, &hash);
- return hash;
-}
+ for (unsigned int i = 1; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
+ {
+ blendDesc.RenderTarget[i] = rtDesc0;
+ blendDesc.RenderTarget[i].RenderTargetWriteMask = key.rtvMasks[i];
+ }
-bool RenderStateCache::compareRasterizerStates(const RasterizerStateKey &a, const RasterizerStateKey &b)
-{
- return memcmp(&a, &b, sizeof(RasterizerStateKey)) == 0;
+ d3d11::BlendState d3dBlendState;
+ ANGLE_TRY(renderer->allocateResource(blendDesc, &d3dBlendState));
+ const auto &iter = mBlendStateCache.Put(key, std::move(d3dBlendState));
+
+ *outBlendState = &iter->second;
+
+ return gl::NoError();
}
-gl::Error RenderStateCache::getRasterizerState(const gl::RasterizerState &rasterState, bool scissorEnabled,
+gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer,
+ const gl::RasterizerState &rasterState,
+ bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{
- if (!mDevice)
- {
- return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
- }
-
- RasterizerStateKey key = {};
+ d3d11::RasterizerStateKey key;
key.rasterizerState = rasterState;
- key.scissorEnabled = scissorEnabled;
+ key.scissorEnabled = scissorEnabled ? 1 : 0;
- RasterizerStateMap::iterator keyIter = mRasterizerStateCache.find(key);
+ auto keyIter = mRasterizerStateCache.Get(key);
if (keyIter != mRasterizerStateCache.end())
{
- RasterizerStateCounterPair &state = keyIter->second;
- state.second = mCounter++;
- *outRasterizerState = state.first;
- return gl::Error(GL_NO_ERROR);
+ *outRasterizerState = keyIter->second.get();
+ return gl::NoError();
}
- else
- {
- if (mRasterizerStateCache.size() >= kMaxRasterizerStates)
- {
- TRACE("Overflowed the limit of %u rasterizer states, removing the least recently used "
- "to make room.", kMaxRasterizerStates);
-
- RasterizerStateMap::iterator leastRecentlyUsed = mRasterizerStateCache.begin();
- for (RasterizerStateMap::iterator i = mRasterizerStateCache.begin(); i != mRasterizerStateCache.end(); i++)
- {
- if (i->second.second < leastRecentlyUsed->second.second)
- {
- leastRecentlyUsed = i;
- }
- }
- SafeRelease(leastRecentlyUsed->second.first);
- mRasterizerStateCache.erase(leastRecentlyUsed);
- }
- D3D11_CULL_MODE cullMode = gl_d3d11::ConvertCullMode(rasterState.cullFace, rasterState.cullMode);
+ TrimCache(kMaxStates, kGCLimit, "rasterizer state", &mRasterizerStateCache);
- // Disable culling if drawing points
- if (rasterState.pointDrawMode)
- {
- cullMode = D3D11_CULL_NONE;
- }
+ D3D11_CULL_MODE cullMode =
+ gl_d3d11::ConvertCullMode(rasterState.cullFace, rasterState.cullMode);
- D3D11_RASTERIZER_DESC rasterDesc;
- rasterDesc.FillMode = D3D11_FILL_SOLID;
- rasterDesc.CullMode = cullMode;
- rasterDesc.FrontCounterClockwise = (rasterState.frontFace == GL_CCW) ? FALSE: TRUE;
- rasterDesc.DepthBiasClamp = 0.0f; // MSDN documentation of DepthBiasClamp implies a value of zero will preform no clamping, must be tested though.
- rasterDesc.DepthClipEnable = TRUE;
- rasterDesc.ScissorEnable = scissorEnabled ? TRUE : FALSE;
- rasterDesc.MultisampleEnable = rasterState.multiSample;
- rasterDesc.AntialiasedLineEnable = FALSE;
-
- if (rasterState.polygonOffsetFill)
- {
- rasterDesc.SlopeScaledDepthBias = rasterState.polygonOffsetFactor;
- rasterDesc.DepthBias = (INT)rasterState.polygonOffsetUnits;
- }
- else
- {
- rasterDesc.SlopeScaledDepthBias = 0.0f;
- rasterDesc.DepthBias = 0;
- }
-
- ID3D11RasterizerState *dx11RasterizerState = NULL;
- HRESULT result = mDevice->CreateRasterizerState(&rasterDesc, &dx11RasterizerState);
- if (FAILED(result) || !dx11RasterizerState)
- {
- 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++)));
-
- *outRasterizerState = dx11RasterizerState;
- return gl::Error(GL_NO_ERROR);
- }
-}
-
-std::size_t RenderStateCache::hashDepthStencilState(const gl::DepthStencilState &dsState)
-{
- static const unsigned int seed = 0xABCDEF98;
-
- std::size_t hash = 0;
- MurmurHash3_x86_32(&dsState, sizeof(gl::DepthStencilState), seed, &hash);
- return hash;
-}
-
-bool RenderStateCache::compareDepthStencilStates(const gl::DepthStencilState &a, const gl::DepthStencilState &b)
-{
- return memcmp(&a, &b, sizeof(gl::DepthStencilState)) == 0;
-}
-
-gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &originalState,
- bool disableDepth,
- bool disableStencil,
- ID3D11DepthStencilState **outDSState)
-{
- if (!mDevice)
+ // Disable culling if drawing points
+ if (rasterState.pointDrawMode)
{
- return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
+ cullMode = D3D11_CULL_NONE;
}
- gl::DepthStencilState glState = originalState;
- if (disableDepth)
+ D3D11_RASTERIZER_DESC rasterDesc;
+ rasterDesc.FillMode = D3D11_FILL_SOLID;
+ rasterDesc.CullMode = cullMode;
+ rasterDesc.FrontCounterClockwise = (rasterState.frontFace == GL_CCW) ? FALSE : TRUE;
+ rasterDesc.DepthBiasClamp = 0.0f; // MSDN documentation of DepthBiasClamp implies a value of
+ // zero will preform no clamping, must be tested though.
+ rasterDesc.DepthClipEnable = TRUE;
+ rasterDesc.ScissorEnable = scissorEnabled ? TRUE : FALSE;
+ rasterDesc.MultisampleEnable = rasterState.multiSample;
+ rasterDesc.AntialiasedLineEnable = FALSE;
+
+ if (rasterState.polygonOffsetFill)
{
- glState.depthTest = false;
- glState.depthMask = false;
+ rasterDesc.SlopeScaledDepthBias = rasterState.polygonOffsetFactor;
+ rasterDesc.DepthBias = (INT)rasterState.polygonOffsetUnits;
}
-
- if (disableStencil)
+ else
{
- glState.stencilWritemask = 0;
- glState.stencilBackWritemask = 0;
- glState.stencilTest = false;
+ rasterDesc.SlopeScaledDepthBias = 0.0f;
+ rasterDesc.DepthBias = 0;
}
- auto keyIter = mDepthStencilStateCache.find(glState);
+ d3d11::RasterizerState dx11RasterizerState;
+ ANGLE_TRY(renderer->allocateResource(rasterDesc, &dx11RasterizerState));
+ *outRasterizerState = dx11RasterizerState.get();
+ mRasterizerStateCache.Put(key, std::move(dx11RasterizerState));
+
+ return gl::NoError();
+}
+
+gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer,
+ const gl::DepthStencilState &glState,
+ const d3d11::DepthStencilState **outDSState)
+{
+ auto keyIter = mDepthStencilStateCache.Get(glState);
if (keyIter != mDepthStencilStateCache.end())
{
- DepthStencilStateCounterPair &state = keyIter->second;
- state.second = mCounter++;
- *outDSState = state.first;
- return gl::Error(GL_NO_ERROR);
+ *outDSState = &keyIter->second;
+ return gl::NoError();
}
- if (mDepthStencilStateCache.size() >= kMaxDepthStencilStates)
- {
- TRACE(
- "Overflowed the limit of %u depth stencil states, removing the least recently used "
- "to make room.",
- kMaxDepthStencilStates);
-
- auto leastRecentlyUsed = mDepthStencilStateCache.begin();
- for (auto i = mDepthStencilStateCache.begin(); i != mDepthStencilStateCache.end(); i++)
- {
- if (i->second.second < leastRecentlyUsed->second.second)
- {
- leastRecentlyUsed = i;
- }
- }
- SafeRelease(leastRecentlyUsed->second.first);
- mDepthStencilStateCache.erase(leastRecentlyUsed);
- }
+ TrimCache(kMaxStates, kGCLimit, "depth stencil state", &mDepthStencilStateCache);
D3D11_DEPTH_STENCIL_DESC dsDesc = {0};
dsDesc.DepthEnable = glState.depthTest ? TRUE : FALSE;
@@ -366,107 +208,66 @@ gl::Error RenderStateCache::getDepthStencilState(const gl::DepthStencilState &or
dsDesc.BackFace.StencilPassOp = ConvertStencilOp(glState.stencilBackPassDepthPass);
dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc);
- ID3D11DepthStencilState *dx11DepthStencilState = NULL;
- HRESULT result = mDevice->CreateDepthStencilState(&dsDesc, &dx11DepthStencilState);
- if (FAILED(result) || !dx11DepthStencilState)
- {
- return gl::Error(GL_OUT_OF_MEMORY,
- "Unable to create a ID3D11DepthStencilState, HRESULT: 0x%X.", result);
- }
+ d3d11::DepthStencilState dx11DepthStencilState;
+ ANGLE_TRY(renderer->allocateResource(dsDesc, &dx11DepthStencilState));
+ const auto &iter = mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState));
- mDepthStencilStateCache.insert(
- std::make_pair(glState, std::make_pair(dx11DepthStencilState, mCounter++)));
+ *outDSState = &iter->second;
- *outDSState = dx11DepthStencilState;
- return gl::Error(GL_NO_ERROR);
+ return gl::NoError();
}
-std::size_t RenderStateCache::hashSamplerState(const gl::SamplerState &samplerState)
+gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer,
+ const gl::SamplerState &samplerState,
+ ID3D11SamplerState **outSamplerState)
{
- static const unsigned int seed = 0xABCDEF98;
-
- std::size_t hash = 0;
- MurmurHash3_x86_32(&samplerState, sizeof(gl::SamplerState), seed, &hash);
- return hash;
-}
-
-bool RenderStateCache::compareSamplerStates(const gl::SamplerState &a, const gl::SamplerState &b)
-{
- return memcmp(&a, &b, sizeof(gl::SamplerState)) == 0;
-}
-
-gl::Error RenderStateCache::getSamplerState(const gl::SamplerState &samplerState, ID3D11SamplerState **outSamplerState)
-{
- if (!mDevice)
+ auto keyIter = mSamplerStateCache.Get(samplerState);
+ if (keyIter != mSamplerStateCache.end())
{
- return gl::Error(GL_OUT_OF_MEMORY, "Internal error, RenderStateCache is not initialized.");
+ *outSamplerState = keyIter->second.get();
+ return gl::NoError();
}
- SamplerStateMap::iterator keyIter = mSamplerStateCache.find(samplerState);
- if (keyIter != mSamplerStateCache.end())
+ TrimCache(kMaxStates, kGCLimit, "sampler state", &mSamplerStateCache);
+
+ const auto &featureLevel = renderer->getRenderer11DeviceCaps().featureLevel;
+
+ D3D11_SAMPLER_DESC samplerDesc;
+ samplerDesc.Filter =
+ gl_d3d11::ConvertFilter(samplerState.minFilter, samplerState.magFilter,
+ samplerState.maxAnisotropy, samplerState.compareMode);
+ samplerDesc.AddressU = gl_d3d11::ConvertTextureWrap(samplerState.wrapS);
+ samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT);
+ samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR);
+ samplerDesc.MipLODBias = 0;
+ samplerDesc.MaxAnisotropy =
+ gl_d3d11::ConvertMaxAnisotropy(samplerState.maxAnisotropy, featureLevel);
+ samplerDesc.ComparisonFunc = gl_d3d11::ConvertComparison(samplerState.compareFunc);
+ samplerDesc.BorderColor[0] = 0.0f;
+ samplerDesc.BorderColor[1] = 0.0f;
+ samplerDesc.BorderColor[2] = 0.0f;
+ samplerDesc.BorderColor[3] = 0.0f;
+ samplerDesc.MinLOD = samplerState.minLod;
+ samplerDesc.MaxLOD = samplerState.maxLod;
+
+ if (featureLevel <= D3D_FEATURE_LEVEL_9_3)
{
- SamplerStateCounterPair &state = keyIter->second;
- state.second = mCounter++;
- *outSamplerState = state.first;
- return gl::Error(GL_NO_ERROR);
+ // Check that maxLOD is nearly FLT_MAX (1000.0f is the default), since 9_3 doesn't support
+ // anything other than FLT_MAX. Note that Feature Level 9_* only supports GL ES 2.0, so the
+ // consumer of ANGLE can't modify the Max LOD themselves.
+ ASSERT(samplerState.maxLod >= 999.9f);
+
+ // Now just set MaxLOD to FLT_MAX. Other parts of the renderer (e.g. the non-zero max LOD
+ // workaround) should take account of this.
+ samplerDesc.MaxLOD = FLT_MAX;
}
- else
- {
- if (mSamplerStateCache.size() >= kMaxSamplerStates)
- {
- TRACE("Overflowed the limit of %u sampler states, removing the least recently used "
- "to make room.", kMaxSamplerStates);
-
- SamplerStateMap::iterator leastRecentlyUsed = mSamplerStateCache.begin();
- for (SamplerStateMap::iterator i = mSamplerStateCache.begin(); i != mSamplerStateCache.end(); i++)
- {
- if (i->second.second < leastRecentlyUsed->second.second)
- {
- leastRecentlyUsed = i;
- }
- }
- SafeRelease(leastRecentlyUsed->second.first);
- mSamplerStateCache.erase(leastRecentlyUsed);
- }
- D3D11_SAMPLER_DESC samplerDesc;
- samplerDesc.Filter = gl_d3d11::ConvertFilter(samplerState.minFilter, samplerState.magFilter,
- samplerState.maxAnisotropy, samplerState.compareMode);
- samplerDesc.AddressU = gl_d3d11::ConvertTextureWrap(samplerState.wrapS);
- samplerDesc.AddressV = gl_d3d11::ConvertTextureWrap(samplerState.wrapT);
- samplerDesc.AddressW = gl_d3d11::ConvertTextureWrap(samplerState.wrapR);
- samplerDesc.MipLODBias = 0;
- samplerDesc.MaxAnisotropy = static_cast<UINT>(samplerState.maxAnisotropy);
- samplerDesc.ComparisonFunc = gl_d3d11::ConvertComparison(samplerState.compareFunc);
- samplerDesc.BorderColor[0] = 0.0f;
- samplerDesc.BorderColor[1] = 0.0f;
- samplerDesc.BorderColor[2] = 0.0f;
- samplerDesc.BorderColor[3] = 0.0f;
- samplerDesc.MinLOD = samplerState.minLod;
- samplerDesc.MaxLOD = samplerState.maxLod;
-
- if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3)
- {
- // Check that maxLOD is nearly FLT_MAX (1000.0f is the default), since 9_3 doesn't support anything other than FLT_MAX.
- // Note that Feature Level 9_* only supports GL ES 2.0, so the consumer of ANGLE can't modify the Max LOD themselves.
- ASSERT(samplerState.maxLod >= 999.9f);
-
- // Now just set MaxLOD to FLT_MAX. Other parts of the renderer (e.g. the non-zero max LOD workaround) should take account of this.
- samplerDesc.MaxLOD = FLT_MAX;
- }
+ d3d11::SamplerState dx11SamplerState;
+ ANGLE_TRY(renderer->allocateResource(samplerDesc, &dx11SamplerState));
+ *outSamplerState = dx11SamplerState.get();
+ mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState));
- ID3D11SamplerState *dx11SamplerState = NULL;
- HRESULT result = mDevice->CreateSamplerState(&samplerDesc, &dx11SamplerState);
- if (FAILED(result) || !dx11SamplerState)
- {
- 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++)));
-
- *outSamplerState = dx11SamplerState;
- return gl::Error(GL_NO_ERROR);
- }
+ return gl::NoError();
}
-}
+} // namespace rx