Commit 91d3e94f by Jamie Madill

D3D11: Apply null InputLayout with no attributes.

In some cases in ES3, we can render without vertex attributes. For this, don't bind or create an empty input layout, but instead bind null. This silences a D3D11 warning in Debug, when viewing the system out. BUG=angleproject:667 Change-Id: Ib88dc1177d7f9bb6a5fa15e44c74da022be137f6 Reviewed-on: https://chromium-review.googlesource.com/316612Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent febe45fc
...@@ -317,58 +317,11 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -317,58 +317,11 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
} }
ID3D11InputLayout *inputLayout = nullptr; ID3D11InputLayout *inputLayout = nullptr;
gl::Error error = findInputLayout(layout, inputElementCount, inputElements, programD3D,
auto layoutMapIt = mLayoutMap.find(layout); sortedAttributes, unsortedAttributes.size(), &inputLayout);
if (layoutMapIt != mLayoutMap.end()) if (error.isError())
{ {
inputLayout = layoutMapIt->second; return error;
}
else
{
const gl::InputLayout &shaderInputLayout =
GetInputLayout(sortedAttributes, unsortedAttributes.size());
ShaderExecutableD3D *shader = nullptr;
gl::Error error = programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr);
if (error.isError())
{
return error;
}
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
D3D11_INPUT_ELEMENT_DESC descs[gl::MAX_VERTEX_ATTRIBS];
for (unsigned int j = 0; j < inputElementCount; ++j)
{
descs[j] = inputElements[j];
}
HRESULT result = mDevice->CreateInputLayout(descs, inputElementCount, shader11->getFunction(), shader11->getLength(), &inputLayout);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal input layout, HRESULT: 0x%08x", result);
}
if (mLayoutMap.size() >= mCacheSize)
{
TRACE("Overflowed the limit of %u input layouts, purging half the cache.", mCacheSize);
// Randomly release every second element
auto it = mLayoutMap.begin();
while (it != mLayoutMap.end())
{
it++;
if (it != mLayoutMap.end())
{
// Calling std::map::erase invalidates the current iterator, so make a copy.
auto eraseIt = it++;
SafeRelease(eraseIt->second);
mLayoutMap.erase(eraseIt);
}
}
}
mLayoutMap[layout] = inputLayout;
} }
if (inputLayout != mCurrentIL) if (inputLayout != mCurrentIL)
...@@ -406,7 +359,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -406,7 +359,7 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
if (sourceInfo->srcBuffer != nullptr) if (sourceInfo->srcBuffer != nullptr)
{ {
const uint8_t *bufferData = nullptr; const uint8_t *bufferData = nullptr;
gl::Error error = sourceInfo->srcBuffer->getData(&bufferData); error = sourceInfo->srcBuffer->getData(&bufferData);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -561,4 +514,70 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri ...@@ -561,4 +514,70 @@ gl::Error InputLayoutCache::applyVertexBuffers(const std::vector<TranslatedAttri
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
gl::Error InputLayoutCache::findInputLayout(
const PackedAttributeLayout &layout,
unsigned int inputElementCount,
const D3D11_INPUT_ELEMENT_DESC inputElements[gl::MAX_VERTEX_ATTRIBS],
ProgramD3D *programD3D,
const TranslatedAttribute *sortedAttributes[gl::MAX_VERTEX_ATTRIBS],
size_t attributeCount,
ID3D11InputLayout **inputLayout)
{
if (inputElementCount == 0)
{
*inputLayout = nullptr;
return gl::Error(GL_NO_ERROR);
}
auto layoutMapIt = mLayoutMap.find(layout);
if (layoutMapIt != mLayoutMap.end())
{
*inputLayout = layoutMapIt->second;
return gl::Error(GL_NO_ERROR);
}
const gl::InputLayout &shaderInputLayout = GetInputLayout(sortedAttributes, attributeCount);
ShaderExecutableD3D *shader = nullptr;
gl::Error error =
programD3D->getVertexExecutableForInputLayout(shaderInputLayout, &shader, nullptr);
if (error.isError())
{
return error;
}
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
HRESULT result =
mDevice->CreateInputLayout(inputElements, inputElementCount, shader11->getFunction(),
shader11->getLength(), inputLayout);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create internal input layout, HRESULT: 0x%08x", result);
}
if (mLayoutMap.size() >= mCacheSize)
{
TRACE("Overflowed the limit of %u input layouts, purging half the cache.", mCacheSize);
// Randomly release every second element
auto it = mLayoutMap.begin();
while (it != mLayoutMap.end())
{
it++;
if (it != mLayoutMap.end())
{
// Calling std::map::erase invalidates the current iterator, so make a copy.
auto eraseIt = it++;
SafeRelease(eraseIt->second);
mLayoutMap.erase(eraseIt);
}
}
}
mLayoutMap[layout] = *inputLayout;
return gl::Error(GL_NO_ERROR);
} }
} // namespace rx
...@@ -31,6 +31,7 @@ namespace rx ...@@ -31,6 +31,7 @@ namespace rx
struct TranslatedAttribute; struct TranslatedAttribute;
struct TranslatedIndexData; struct TranslatedIndexData;
struct SourceIndexData; struct SourceIndexData;
class ProgramD3D;
class InputLayoutCache : angle::NonCopyable class InputLayoutCache : angle::NonCopyable
{ {
...@@ -76,6 +77,14 @@ class InputLayoutCache : angle::NonCopyable ...@@ -76,6 +77,14 @@ class InputLayoutCache : angle::NonCopyable
uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS]; uint32_t attributeData[gl::MAX_VERTEX_ATTRIBS];
}; };
gl::Error findInputLayout(const PackedAttributeLayout &layout,
unsigned int inputElementCount,
const D3D11_INPUT_ELEMENT_DESC inputElements[gl::MAX_VERTEX_ATTRIBS],
ProgramD3D *programD3D,
const TranslatedAttribute *sortedAttributes[gl::MAX_VERTEX_ATTRIBS],
size_t attributeCount,
ID3D11InputLayout **inputLayout);
std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap; std::map<PackedAttributeLayout, ID3D11InputLayout *> mLayoutMap;
ID3D11InputLayout *mCurrentIL; ID3D11InputLayout *mCurrentIL;
...@@ -94,6 +103,6 @@ class InputLayoutCache : angle::NonCopyable ...@@ -94,6 +103,6 @@ class InputLayoutCache : angle::NonCopyable
D3D_FEATURE_LEVEL mFeatureLevel; D3D_FEATURE_LEVEL mFeatureLevel;
}; };
} } // namespace rx
#endif // LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_ #endif // LIBANGLE_RENDERER_D3D_D3D11_INPUTLAYOUTCACHE_H_
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