Commit 7a26a1ad by Geoff Lang

Cache std::vectors in ProgramD3D to avoid allocations during draw calls.

BUG=angleproject:959 Change-Id: Ie08e68ae27372a97bd118e61478201b0d3dad955 Reviewed-on: https://chromium-review.googlesource.com/262337Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarNicolas Capens <capn@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 20d78d24
...@@ -184,6 +184,7 @@ ProgramD3D::ProgramD3D(RendererD3D *renderer) ...@@ -184,6 +184,7 @@ ProgramD3D::ProgramD3D(RendererD3D *renderer)
mUsedVertexSamplerRange(0), mUsedVertexSamplerRange(0),
mUsedPixelSamplerRange(0), mUsedPixelSamplerRange(0),
mDirtySamplerMapping(true), mDirtySamplerMapping(true),
mTextureUnitTypesCache(renderer->getRendererCaps().maxCombinedTextureImageUnits),
mShaderVersion(100), mShaderVersion(100),
mSerial(issueSerial()) mSerial(issueSerial())
{ {
...@@ -340,7 +341,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) ...@@ -340,7 +341,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
// DrawArrays and DrawElements will issue the INVALID_OPERATION error. // DrawArrays and DrawElements will issue the INVALID_OPERATION error.
updateSamplerMapping(); updateSamplerMapping();
std::vector<GLenum> textureUnitTypes(caps.maxCombinedTextureImageUnits, GL_NONE); std::fill(mTextureUnitTypesCache.begin(), mTextureUnitTypesCache.end(), GL_NONE);
for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i) for (unsigned int i = 0; i < mUsedPixelSamplerRange; ++i)
{ {
...@@ -348,19 +349,19 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) ...@@ -348,19 +349,19 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
{ {
unsigned int unit = mSamplersPS[i].logicalTextureUnit; unsigned int unit = mSamplersPS[i].logicalTextureUnit;
if (unit >= textureUnitTypes.size()) if (unit >= caps.maxCombinedTextureImageUnits)
{ {
if (infoLog) if (infoLog)
{ {
infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size()); infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, caps.maxCombinedTextureImageUnits);
} }
return false; return false;
} }
if (textureUnitTypes[unit] != GL_NONE) if (mTextureUnitTypesCache[unit] != GL_NONE)
{ {
if (mSamplersPS[i].textureType != textureUnitTypes[unit]) if (mSamplersPS[i].textureType != mTextureUnitTypesCache[unit])
{ {
if (infoLog) if (infoLog)
{ {
...@@ -372,7 +373,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) ...@@ -372,7 +373,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
} }
else else
{ {
textureUnitTypes[unit] = mSamplersPS[i].textureType; mTextureUnitTypesCache[unit] = mSamplersPS[i].textureType;
} }
} }
} }
...@@ -383,19 +384,19 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) ...@@ -383,19 +384,19 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
{ {
unsigned int unit = mSamplersVS[i].logicalTextureUnit; unsigned int unit = mSamplersVS[i].logicalTextureUnit;
if (unit >= textureUnitTypes.size()) if (unit >= caps.maxCombinedTextureImageUnits)
{ {
if (infoLog) if (infoLog)
{ {
infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, textureUnitTypes.size()); infoLog->append("Sampler uniform (%d) exceeds GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS (%d)", unit, caps.maxCombinedTextureImageUnits);
} }
return false; return false;
} }
if (textureUnitTypes[unit] != GL_NONE) if (mTextureUnitTypesCache[unit] != GL_NONE)
{ {
if (mSamplersVS[i].textureType != textureUnitTypes[unit]) if (mSamplersVS[i].textureType != mTextureUnitTypesCache[unit])
{ {
if (infoLog) if (infoLog)
{ {
...@@ -407,7 +408,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps) ...@@ -407,7 +408,7 @@ bool ProgramD3D::validateSamplers(gl::InfoLog *infoLog, const gl::Caps &caps)
} }
else else
{ {
textureUnitTypes[unit] = mSamplersVS[i].textureType; mTextureUnitTypesCache[unit] = mSamplersVS[i].textureType;
} }
} }
} }
...@@ -838,7 +839,7 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream) ...@@ -838,7 +839,7 @@ gl::Error ProgramD3D::save(gl::BinaryOutputStream *stream)
gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExecutable) gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fbo, ShaderExecutableD3D **outExecutable)
{ {
std::vector<GLenum> outputs; mPixelShaderOutputFormatCache.clear();
const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo); const FramebufferD3D *fboD3D = GetImplAs<FramebufferD3D>(fbo);
const gl::AttachmentList &colorbuffers = fboD3D->getColorAttachmentsForRender(mRenderer->getWorkarounds()); const gl::AttachmentList &colorbuffers = fboD3D->getColorAttachmentsForRender(mRenderer->getWorkarounds());
...@@ -849,15 +850,15 @@ gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fb ...@@ -849,15 +850,15 @@ gl::Error ProgramD3D::getPixelExecutableForFramebuffer(const gl::Framebuffer *fb
if (colorbuffer) if (colorbuffer)
{ {
outputs.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding()); mPixelShaderOutputFormatCache.push_back(colorbuffer->getBinding() == GL_BACK ? GL_COLOR_ATTACHMENT0 : colorbuffer->getBinding());
} }
else else
{ {
outputs.push_back(GL_NONE); mPixelShaderOutputFormatCache.push_back(GL_NONE);
} }
} }
return getPixelExecutableForOutputLayout(outputs, outExecutable, nullptr); return getPixelExecutableForOutputLayout(mPixelShaderOutputFormatCache, outExecutable, nullptr);
} }
gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature, gl::Error ProgramD3D::getPixelExecutableForOutputLayout(const std::vector<GLenum> &outputSignature,
......
...@@ -225,6 +225,12 @@ class ProgramD3D : public ProgramImpl ...@@ -225,6 +225,12 @@ class ProgramD3D : public ProgramImpl
GLuint mUsedPixelSamplerRange; GLuint mUsedPixelSamplerRange;
bool mDirtySamplerMapping; bool mDirtySamplerMapping;
// Cache for validateSamplers
std::vector<GLenum> mTextureUnitTypesCache;
// Cache for getPixelExecutableForFramebuffer
std::vector<GLenum> mPixelShaderOutputFormatCache;
int mShaderVersion; int mShaderVersion;
int mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS]; int mAttributesByLayout[gl::MAX_VERTEX_ATTRIBS];
......
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