Commit bd136f9a by Jamie Madill

Reland of "D3D11: Fix draw perf regression with input layouts."

f8dd7b10 fixed unnecessary shader compiles, but introduced a draw call perf regression. Fix the regression robustly by storing a minimal set of input layout elements/vertex attribute info, but also handle the case where the vector sizes mismatch between a cached and new vertex layout. Reland with fix for comparison warning. BUG=510151 Change-Id: I578ddbb5b5bb12e7c1a901f23c7b5fcbd64b5d23 Reviewed-on: https://chromium-review.googlesource.com/292460Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 194814e3
...@@ -59,12 +59,9 @@ GLenum GetTextureType(GLenum samplerType) ...@@ -59,12 +59,9 @@ GLenum GetTextureType(GLenum samplerType)
gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader) gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
{ {
gl::InputLayout defaultLayout(gl::MAX_VERTEX_ATTRIBS, gl::VERTEX_FORMAT_INVALID); gl::InputLayout defaultLayout;
const auto &shaderAttributes = vertexShader->getActiveAttributes(); for (const sh::Attribute &shaderAttr : vertexShader->getActiveAttributes())
size_t layoutIndex = 0;
for (size_t attribIndex = 0; attribIndex < shaderAttributes.size(); ++attribIndex)
{ {
const sh::Attribute &shaderAttr = shaderAttributes[attribIndex];
if (shaderAttr.type != GL_NONE) if (shaderAttr.type != GL_NONE)
{ {
GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type); GLenum transposedType = gl::TransposeMatrixType(shaderAttr.type);
...@@ -79,7 +76,7 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader) ...@@ -79,7 +76,7 @@ gl::InputLayout GetDefaultInputLayoutFromShader(const gl::Shader *vertexShader)
gl::VertexFormatType defaultType = gl::GetVertexFormatType( gl::VertexFormatType defaultType = gl::GetVertexFormatType(
componentType, GL_FALSE, components, pureInt); componentType, GL_FALSE, components, pureInt);
defaultLayout[layoutIndex++] = defaultType; defaultLayout.push_back(defaultType);
} }
} }
} }
...@@ -150,23 +147,36 @@ void ProgramD3D::VertexExecutable::getSignature(RendererD3D *renderer, ...@@ -150,23 +147,36 @@ void ProgramD3D::VertexExecutable::getSignature(RendererD3D *renderer,
const gl::InputLayout &inputLayout, const gl::InputLayout &inputLayout,
Signature *signatureOut) Signature *signatureOut)
{ {
signatureOut->assign(inputLayout.size(), false); signatureOut->resize(inputLayout.size());
for (size_t index = 0; index < inputLayout.size(); ++index) for (size_t index = 0; index < inputLayout.size(); ++index)
{ {
gl::VertexFormatType vertexFormatType = inputLayout[index]; gl::VertexFormatType vertexFormatType = inputLayout[index];
bool converted = false;
if (vertexFormatType != gl::VERTEX_FORMAT_INVALID) if (vertexFormatType != gl::VERTEX_FORMAT_INVALID)
{ {
VertexConversionType conversionType = VertexConversionType conversionType =
renderer->getVertexConversionType(vertexFormatType); renderer->getVertexConversionType(vertexFormatType);
(*signatureOut)[index] = ((conversionType & VERTEX_CONVERT_GPU) != 0); converted = ((conversionType & VERTEX_CONVERT_GPU) != 0);
} }
(*signatureOut)[index] = converted;
} }
} }
bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature) const bool ProgramD3D::VertexExecutable::matchesSignature(const Signature &signature) const
{ {
return mSignature == signature; size_t limit = std::max(mSignature.size(), signature.size());
for (size_t index = 0; index < limit; ++index)
{
// treat undefined indexes as 'not converted'
bool a = index < signature.size() ? signature[index] : false;
bool b = index < mSignature.size() ? mSignature[index] : false;
if (a != b)
return false;
}
return true;
} }
ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature, ProgramD3D::PixelExecutable::PixelExecutable(const std::vector<GLenum> &outputSignature,
...@@ -2060,7 +2070,7 @@ void ProgramD3D::sortAttributesByLayout(const std::vector<TranslatedAttribute> & ...@@ -2060,7 +2070,7 @@ void ProgramD3D::sortAttributesByLayout(const std::vector<TranslatedAttribute> &
void ProgramD3D::updateCachedInputLayout(const gl::Program *program, const gl::State &state) void ProgramD3D::updateCachedInputLayout(const gl::Program *program, const gl::State &state)
{ {
mCachedInputLayout.assign(gl::MAX_VERTEX_ATTRIBS, gl::VERTEX_FORMAT_INVALID); mCachedInputLayout.clear();
const int *semanticIndexes = program->getSemanticIndexes(); const int *semanticIndexes = program->getSemanticIndexes();
const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes(); const auto &vertexAttributes = state.getVertexArray()->getVertexAttributes();
...@@ -2071,6 +2081,10 @@ void ProgramD3D::updateCachedInputLayout(const gl::Program *program, const gl::S ...@@ -2071,6 +2081,10 @@ void ProgramD3D::updateCachedInputLayout(const gl::Program *program, const gl::S
if (semanticIndex != -1) if (semanticIndex != -1)
{ {
if (mCachedInputLayout.size() < static_cast<size_t>(semanticIndex + 1))
{
mCachedInputLayout.resize(semanticIndex + 1, gl::VERTEX_FORMAT_INVALID);
}
mCachedInputLayout[semanticIndex] = mCachedInputLayout[semanticIndex] =
GetVertexFormatType(vertexAttributes[attributeIndex], GetVertexFormatType(vertexAttributes[attributeIndex],
state.getVertexAttribCurrentValue(attributeIndex).Type); state.getVertexAttribCurrentValue(attributeIndex).Type);
......
...@@ -31,17 +31,16 @@ gl::InputLayout GetInputLayout( ...@@ -31,17 +31,16 @@ gl::InputLayout GetInputLayout(
const TranslatedAttribute *translatedAttributes[gl::MAX_VERTEX_ATTRIBS], const TranslatedAttribute *translatedAttributes[gl::MAX_VERTEX_ATTRIBS],
size_t attributeCount) size_t attributeCount)
{ {
gl::InputLayout inputLayout(gl::MAX_VERTEX_ATTRIBS, gl::VERTEX_FORMAT_INVALID); gl::InputLayout inputLayout(attributeCount, gl::VERTEX_FORMAT_INVALID);
for (size_t attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex) for (size_t attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex)
{ {
const TranslatedAttribute *translatedAttribute = translatedAttributes[attributeIndex]; const TranslatedAttribute *translatedAttribute = translatedAttributes[attributeIndex];
if (translatedAttribute->active) if (translatedAttribute->active)
{ {
gl::VertexFormatType vertexFormatType = inputLayout[attributeIndex] = gl::GetVertexFormatType(
gl::GetVertexFormatType(*translatedAttribute->attribute, *translatedAttribute->attribute, translatedAttribute->currentValueType);
translatedAttribute->currentValueType);
inputLayout[attributeIndex] = vertexFormatType;
} }
} }
return inputLayout; return inputLayout;
......
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