Commit 37386b02 by Jamie Madill Committed by Commit Bot

Vulkan: Cache object pointers in ContextVk.

Small performance optimization. Bug: angleproject:2786 Change-Id: Ib01c1762d438ffb72ec25bf05135a7d3271d6aee Reviewed-on: https://chromium-review.googlesource.com/1188954 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 88fc6da3
...@@ -119,6 +119,9 @@ ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer) ...@@ -119,6 +119,9 @@ ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer)
mVertexBuffersDirty(false), mVertexBuffersDirty(false),
mIndexBufferDirty(false), mIndexBufferDirty(false),
mDescriptorSetsDirty(false), mDescriptorSetsDirty(false),
mVertexArray(nullptr),
mDrawFramebuffer(nullptr),
mProgram(nullptr),
mLastIndexBufferOffset(0), mLastIndexBufferOffset(0),
mCurrentDrawElementsType(GL_NONE), mCurrentDrawElementsType(GL_NONE),
mClearColorMask(kAllColorChannelsMask), mClearColorMask(kAllColorChannelsMask),
...@@ -215,28 +218,24 @@ angle::Result ContextVk::initPipeline(const gl::DrawCallParams &drawCallParams) ...@@ -215,28 +218,24 @@ angle::Result ContextVk::initPipeline(const gl::DrawCallParams &drawCallParams)
{ {
ASSERT(!mCurrentPipeline); ASSERT(!mCurrentPipeline);
const gl::State &state = mState.getState();
VertexArrayVk *vertexArrayVk = vk::GetImpl(state.getVertexArray());
FramebufferVk *framebufferVk = vk::GetImpl(state.getDrawFramebuffer());
ProgramVk *programVk = vk::GetImpl(state.getProgram());
const gl::AttributesMask activeAttribLocationsMask = const gl::AttributesMask activeAttribLocationsMask =
state.getProgram()->getActiveAttribLocationsMask(); mProgram->getState().getActiveAttribLocationsMask();
// Ensure the topology of the pipeline description is updated. // Ensure the topology of the pipeline description is updated.
mPipelineDesc->updateTopology(mCurrentDrawMode); mPipelineDesc->updateTopology(mCurrentDrawMode);
// Copy over the latest attrib and binding descriptions. // Copy over the latest attrib and binding descriptions.
vertexArrayVk->getPackedInputDescriptions(mPipelineDesc.get()); mVertexArray->getPackedInputDescriptions(mPipelineDesc.get());
// Ensure that the RenderPass description is updated. // Ensure that the RenderPass description is updated.
mPipelineDesc->updateRenderPassDesc(framebufferVk->getRenderPassDesc()); mPipelineDesc->updateRenderPassDesc(mDrawFramebuffer->getRenderPassDesc());
// Trigger draw call shader patching and fill out the pipeline desc. // Trigger draw call shader patching and fill out the pipeline desc.
const vk::ShaderAndSerial *vertexShaderAndSerial = nullptr; const vk::ShaderAndSerial *vertexShaderAndSerial = nullptr;
const vk::ShaderAndSerial *fragmentShaderAndSerial = nullptr; const vk::ShaderAndSerial *fragmentShaderAndSerial = nullptr;
const vk::PipelineLayout *pipelineLayout = nullptr; const vk::PipelineLayout *pipelineLayout = nullptr;
ANGLE_TRY(programVk->initShaders(this, drawCallParams, &vertexShaderAndSerial, ANGLE_TRY(mProgram->initShaders(this, drawCallParams, &vertexShaderAndSerial,
&fragmentShaderAndSerial, &pipelineLayout)); &fragmentShaderAndSerial, &pipelineLayout));
mPipelineDesc->updateShaders(vertexShaderAndSerial->getSerial(), mPipelineDesc->updateShaders(vertexShaderAndSerial->getSerial(),
fragmentShaderAndSerial->getSerial()); fragmentShaderAndSerial->getSerial());
...@@ -261,12 +260,9 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -261,12 +260,9 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
const gl::State &state = mState.getState(); const gl::State &state = mState.getState();
const gl::Program *programGL = state.getProgram(); const gl::Program *programGL = state.getProgram();
ProgramVk *programVk = vk::GetImpl(programGL);
FramebufferVk *framebufferVk = vk::GetImpl(state.getDrawFramebuffer());
VertexArrayVk *vertexArrayVk = vk::GetImpl(state.getVertexArray());
vk::RecordingMode mode; vk::RecordingMode mode;
ANGLE_TRY(framebufferVk->getCommandBufferForDraw(this, commandBufferOut, &mode)); ANGLE_TRY(mDrawFramebuffer->getCommandBufferForDraw(this, commandBufferOut, &mode));
// Set any dirty bits that depend on draw call parameters or other objects. // Set any dirty bits that depend on draw call parameters or other objects.
if (mode == vk::RecordingMode::Start) if (mode == vk::RecordingMode::Start)
...@@ -280,13 +276,13 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -280,13 +276,13 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
if (context->getStateCache().hasAnyActiveClientAttrib()) if (context->getStateCache().hasAnyActiveClientAttrib())
{ {
ANGLE_TRY(vertexArrayVk->updateClientAttribs(context, drawCallParams)); ANGLE_TRY(mVertexArray->updateClientAttribs(context, drawCallParams));
mVertexBuffersDirty = true; mVertexBuffersDirty = true;
} }
if (programVk->dirtyUniforms()) if (mProgram->dirtyUniforms())
{ {
ANGLE_TRY(programVk->updateUniforms(this)); ANGLE_TRY(mProgram->updateUniforms(this));
mDescriptorSetsDirty = true; mDescriptorSetsDirty = true;
} }
...@@ -324,12 +320,12 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -324,12 +320,12 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
{ {
TextureVk *textureVk = mActiveTextures[textureIndex]; TextureVk *textureVk = mActiveTextures[textureIndex];
ANGLE_TRY(textureVk->ensureImageInitialized(this)); ANGLE_TRY(textureVk->ensureImageInitialized(this));
textureVk->addReadDependency(framebufferVk); textureVk->addReadDependency(mDrawFramebuffer);
} }
if (programVk->hasTextures()) if (mProgram->hasTextures())
{ {
ANGLE_TRY(programVk->updateTexturesDescriptorSet(this)); ANGLE_TRY(mProgram->updateTexturesDescriptorSet(this));
} }
mDescriptorSetsDirty = true; mDescriptorSetsDirty = true;
...@@ -338,11 +334,11 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -338,11 +334,11 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
if (mDescriptorSetsDirty) if (mDescriptorSetsDirty)
{ {
ANGLE_TRY(programVk->updateDescriptorSets(this, drawCallParams, *commandBufferOut)); ANGLE_TRY(mProgram->updateDescriptorSets(this, drawCallParams, *commandBufferOut));
// Bind the graphics descriptor sets. // Bind the graphics descriptor sets.
(*commandBufferOut) (*commandBufferOut)
->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, programVk->getPipelineLayout(), ->bindDescriptorSets(VK_PIPELINE_BIND_POINT_GRAPHICS, mProgram->getPipelineLayout(),
kDriverUniformsDescriptorSetIndex, 1, kDriverUniformsDescriptorSetIndex, 1,
&mDriverUniformsDescriptorSet, 0, nullptr); &mDriverUniformsDescriptorSet, 0, nullptr);
mDescriptorSetsDirty = false; mDescriptorSetsDirty = false;
...@@ -353,15 +349,15 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -353,15 +349,15 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
{ {
const gl::AttributesMask &programAttribsMask = programGL->getActiveAttribLocationsMask(); const gl::AttributesMask &programAttribsMask = programGL->getActiveAttribLocationsMask();
BindNonNullVertexBufferRanges(*commandBufferOut, programAttribsMask, maxAttrib, BindNonNullVertexBufferRanges(*commandBufferOut, programAttribsMask, maxAttrib,
vertexArrayVk->getCurrentArrayBufferHandles(), mVertexArray->getCurrentArrayBufferHandles(),
vertexArrayVk->getCurrentArrayBufferOffsets()); mVertexArray->getCurrentArrayBufferOffsets());
const auto &arrayBufferResources = vertexArrayVk->getCurrentArrayBufferResources(); const auto &arrayBufferResources = mVertexArray->getCurrentArrayBufferResources();
for (size_t attribIndex : context->getStateCache().getActiveBufferedAttribsMask()) for (size_t attribIndex : context->getStateCache().getActiveBufferedAttribsMask())
{ {
if (arrayBufferResources[attribIndex]) if (arrayBufferResources[attribIndex])
arrayBufferResources[attribIndex]->addReadDependency(framebufferVk); arrayBufferResources[attribIndex]->addReadDependency(mDrawFramebuffer);
} }
mVertexBuffersDirty = false; mVertexBuffersDirty = false;
...@@ -370,15 +366,15 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -370,15 +366,15 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
if (useIndexBuffer && mIndexBufferDirty) if (useIndexBuffer && mIndexBufferDirty)
{ {
(*commandBufferOut) (*commandBufferOut)
->bindIndexBuffer(vertexArrayVk->getCurrentElementArrayBufferHandle(), ->bindIndexBuffer(mVertexArray->getCurrentElementArrayBufferHandle(),
vertexArrayVk->getCurrentElementArrayBufferOffset(), mVertexArray->getCurrentElementArrayBufferOffset(),
gl_vk::GetIndexType(mCurrentDrawElementsType)); gl_vk::GetIndexType(mCurrentDrawElementsType));
vk::CommandGraphResource *elementArrayBufferResource = vk::CommandGraphResource *elementArrayBufferResource =
vertexArrayVk->getCurrentElementArrayBufferResource(); mVertexArray->getCurrentElementArrayBufferResource();
if (elementArrayBufferResource) if (elementArrayBufferResource)
{ {
elementArrayBufferResource->addReadDependency(framebufferVk); elementArrayBufferResource->addReadDependency(mDrawFramebuffer);
} }
mIndexBufferDirty = false; mIndexBufferDirty = false;
...@@ -391,19 +387,17 @@ angle::Result ContextVk::setupIndexedDraw(const gl::Context *context, ...@@ -391,19 +387,17 @@ angle::Result ContextVk::setupIndexedDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
vk::CommandBuffer **commandBufferOut) vk::CommandBuffer **commandBufferOut)
{ {
VertexArrayVk *vertexArrayVk = vk::GetImpl(mState.getState().getVertexArray());
if (drawCallParams.type() != mCurrentDrawElementsType) if (drawCallParams.type() != mCurrentDrawElementsType)
{ {
mIndexBufferDirty = true; mIndexBufferDirty = true;
mCurrentDrawElementsType = drawCallParams.type(); mCurrentDrawElementsType = drawCallParams.type();
} }
const gl::Buffer *elementArrayBuffer = vertexArrayVk->getState().getElementArrayBuffer().get(); const gl::Buffer *elementArrayBuffer = mVertexArray->getState().getElementArrayBuffer().get();
if (!elementArrayBuffer) if (!elementArrayBuffer)
{ {
mIndexBufferDirty = true; mIndexBufferDirty = true;
ANGLE_TRY(vertexArrayVk->updateIndexTranslation(this, drawCallParams)); ANGLE_TRY(mVertexArray->updateIndexTranslation(this, drawCallParams));
} }
else else
{ {
...@@ -411,12 +405,12 @@ angle::Result ContextVk::setupIndexedDraw(const gl::Context *context, ...@@ -411,12 +405,12 @@ angle::Result ContextVk::setupIndexedDraw(const gl::Context *context,
{ {
mIndexBufferDirty = true; mIndexBufferDirty = true;
mLastIndexBufferOffset = drawCallParams.indices(); mLastIndexBufferOffset = drawCallParams.indices();
vertexArrayVk->updateCurrentElementArrayBufferOffset(mLastIndexBufferOffset); mVertexArray->updateCurrentElementArrayBufferOffset(mLastIndexBufferOffset);
} }
if (drawCallParams.type() == GL_UNSIGNED_BYTE && mIndexBufferDirty) if (drawCallParams.type() == GL_UNSIGNED_BYTE && mIndexBufferDirty)
{ {
ANGLE_TRY(vertexArrayVk->updateIndexTranslation(this, drawCallParams)); ANGLE_TRY(mVertexArray->updateIndexTranslation(this, drawCallParams));
} }
} }
...@@ -427,8 +421,7 @@ angle::Result ContextVk::setupLineLoopDraw(const gl::Context *context, ...@@ -427,8 +421,7 @@ angle::Result ContextVk::setupLineLoopDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
vk::CommandBuffer **commandBufferOut) vk::CommandBuffer **commandBufferOut)
{ {
VertexArrayVk *vertexArrayVk = vk::GetImpl(mState.getState().getVertexArray()); ANGLE_TRY(mVertexArray->handleLineLoop(this, drawCallParams));
ANGLE_TRY(vertexArrayVk->handleLineLoop(this, drawCallParams));
mIndexBufferDirty = true; mIndexBufferDirty = true;
mCurrentDrawElementsType = mCurrentDrawElementsType =
drawCallParams.isDrawElements() ? drawCallParams.type() : GL_UNSIGNED_INT; drawCallParams.isDrawElements() ? drawCallParams.type() : GL_UNSIGNED_INT;
...@@ -770,10 +763,10 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt ...@@ -770,10 +763,10 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
break; break;
case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING: case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING:
{ {
mDrawFramebuffer = vk::GetImpl(glState.getDrawFramebuffer());
ANGLE_TRY(updateDriverUniforms(glState)); ANGLE_TRY(updateDriverUniforms(glState));
updateFlipViewportDrawFramebuffer(glState); updateFlipViewportDrawFramebuffer(glState);
FramebufferVk *framebufferVk = vk::GetImpl(glState.getDrawFramebuffer()); mPipelineDesc->updateViewport(mDrawFramebuffer, glState.getViewport(),
mPipelineDesc->updateViewport(framebufferVk, glState.getViewport(),
glState.getNearPlane(), glState.getFarPlane(), glState.getNearPlane(), glState.getFarPlane(),
isViewportFlipEnabledForDrawFBO()); isViewportFlipEnabledForDrawFBO());
updateColorMask(glState.getBlendState()); updateColorMask(glState.getBlendState());
...@@ -795,6 +788,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt ...@@ -795,6 +788,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
break; break;
case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING: case gl::State::DIRTY_BIT_VERTEX_ARRAY_BINDING:
{ {
mVertexArray = vk::GetImpl(glState.getVertexArray());
invalidateDefaultAttributes(context->getStateCache().getActiveDefaultAttribsMask()); invalidateDefaultAttributes(context->getStateCache().getActiveDefaultAttribsMask());
break; break;
} }
...@@ -803,6 +797,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt ...@@ -803,6 +797,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
case gl::State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING: case gl::State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING:
break; break;
case gl::State::DIRTY_BIT_PROGRAM_BINDING: case gl::State::DIRTY_BIT_PROGRAM_BINDING:
mProgram = vk::GetImpl(glState.getProgram());
break; break;
case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE: case gl::State::DIRTY_BIT_PROGRAM_EXECUTABLE:
{ {
...@@ -1207,9 +1202,8 @@ angle::Result ContextVk::updateDefaultAttribute(size_t attribIndex) ...@@ -1207,9 +1202,8 @@ angle::Result ContextVk::updateDefaultAttribute(size_t attribIndex)
ANGLE_TRY(defaultBuffer.flush(this)); ANGLE_TRY(defaultBuffer.flush(this));
VertexArrayVk *vertexArrayVk = vk::GetImpl(glState.getVertexArray()); mVertexArray->updateDefaultAttrib(mRenderer, attribIndex, bufferHandle,
vertexArrayVk->updateDefaultAttrib(mRenderer, attribIndex, bufferHandle, static_cast<uint32_t>(offset));
static_cast<uint32_t>(offset));
return angle::Result::Continue(); return angle::Result::Continue();
} }
} // namespace rx } // namespace rx
...@@ -218,6 +218,11 @@ class ContextVk : public ContextImpl, public vk::Context ...@@ -218,6 +218,11 @@ class ContextVk : public ContextImpl, public vk::Context
bool mIndexBufferDirty; bool mIndexBufferDirty;
bool mDescriptorSetsDirty; bool mDescriptorSetsDirty;
// Cached back-end objects.
VertexArrayVk *mVertexArray;
FramebufferVk *mDrawFramebuffer;
ProgramVk *mProgram;
// The offset we had the last time we bound the index buffer. // The offset we had the last time we bound the index buffer.
const GLvoid *mLastIndexBufferOffset; const GLvoid *mLastIndexBufferOffset;
GLenum mCurrentDrawElementsType; GLenum mCurrentDrawElementsType;
......
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