Commit d1249de0 by Jamie Madill Committed by Commit Bot

Vulkan: Optimize ContextVk::setupDraw.

This improves performance significantly in the Vulkan CPU overhead test. Bug: angleproject:2786 Change-Id: I911bc66a6b2d11dd3848ffa90927b314aeadfc24 Reviewed-on: https://chromium-review.googlesource.com/1194301 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 30b5d84c
...@@ -354,6 +354,8 @@ class ProgramState final : angle::NonCopyable ...@@ -354,6 +354,8 @@ class ProgramState final : angle::NonCopyable
bool hasAttachedShader() const; bool hasAttachedShader() const;
const ActiveTextureMask &getActiveSamplersMask() const { return mActiveSamplersMask; }
private: private:
friend class MemoryProgramCache; friend class MemoryProgramCache;
friend class Program; friend class Program;
......
...@@ -257,21 +257,16 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -257,21 +257,16 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
const DirtyBits &dirtyBitsMask, const DirtyBits &dirtyBitsMask,
vk::CommandBuffer **commandBufferOut) vk::CommandBuffer **commandBufferOut)
{ {
// Set any dirty bits that depend on draw call parameters or other objects.
if (drawCallParams.mode() != mCurrentDrawMode) if (drawCallParams.mode() != mCurrentDrawMode)
{ {
invalidateCurrentPipeline(); invalidateCurrentPipeline();
mCurrentDrawMode = drawCallParams.mode(); mCurrentDrawMode = drawCallParams.mode();
} }
const gl::State &state = mState.getState(); if (!mDrawFramebuffer->appendToStartedRenderPass(mRenderer, commandBufferOut))
const gl::Program *programGL = state.getProgram();
vk::RecordingMode mode;
ANGLE_TRY(mDrawFramebuffer->getCommandBufferForDraw(this, commandBufferOut, &mode));
// Set any dirty bits that depend on draw call parameters or other objects.
if (mode == vk::RecordingMode::Start)
{ {
ANGLE_TRY(mDrawFramebuffer->startNewRenderPass(this, commandBufferOut));
mDirtyBits |= mNewCommandBufferDirtyBits; mDirtyBits |= mNewCommandBufferDirtyBits;
} }
...@@ -317,7 +312,7 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -317,7 +312,7 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
// TODO(jmadill): Should probably merge this for loop with programVk's descriptor // TODO(jmadill): Should probably merge this for loop with programVk's descriptor
// update. // update.
for (size_t textureIndex : programGL->getActiveSamplersMask()) for (size_t textureIndex : mProgram->getState().getActiveSamplersMask())
{ {
// Ensure any writes to the textures are flushed before we read from them. // Ensure any writes to the textures are flushed before we read from them.
TextureVk *textureVk = mActiveTextures[textureIndex]; TextureVk *textureVk = mActiveTextures[textureIndex];
...@@ -348,7 +343,7 @@ angle::Result ContextVk::setupDraw(const gl::Context *context, ...@@ -348,7 +343,7 @@ angle::Result ContextVk::setupDraw(const gl::Context *context,
case DIRTY_BIT_VERTEX_BUFFERS: case DIRTY_BIT_VERTEX_BUFFERS:
{ {
BindNonNullVertexBufferRanges(*commandBufferOut, BindNonNullVertexBufferRanges(*commandBufferOut,
programGL->getActiveAttribLocationsMask(), mProgram->getState().getActiveAttribLocationsMask(),
mProgram->getState().getMaxActiveAttribLocation(), mProgram->getState().getMaxActiveAttribLocation(),
mVertexArray->getCurrentArrayBufferHandles(), mVertexArray->getCurrentArrayBufferHandles(),
mVertexArray->getCurrentArrayBufferOffsets()); mVertexArray->getCurrentArrayBufferOffsets());
......
...@@ -1087,6 +1087,12 @@ angle::Result FramebufferVk::getCommandBufferForDraw(ContextVk *contextVk, ...@@ -1087,6 +1087,12 @@ angle::Result FramebufferVk::getCommandBufferForDraw(ContextVk *contextVk,
return angle::Result::Continue(); return angle::Result::Continue();
} }
return startNewRenderPass(contextVk, commandBufferOut);
}
angle::Result FramebufferVk::startNewRenderPass(ContextVk *contextVk,
vk::CommandBuffer **commandBufferOut)
{
vk::Framebuffer *framebuffer = nullptr; vk::Framebuffer *framebuffer = nullptr;
ANGLE_TRY(getFramebuffer(contextVk, &framebuffer)); ANGLE_TRY(getFramebuffer(contextVk, &framebuffer));
...@@ -1120,7 +1126,6 @@ angle::Result FramebufferVk::getCommandBufferForDraw(ContextVk *contextVk, ...@@ -1120,7 +1126,6 @@ angle::Result FramebufferVk::getCommandBufferForDraw(ContextVk *contextVk,
gl::Rectangle renderArea = gl::Rectangle renderArea =
gl::Rectangle(0, 0, mState.getDimensions().width, mState.getDimensions().height); gl::Rectangle(0, 0, mState.getDimensions().width, mState.getDimensions().height);
*modeOut = vk::RecordingMode::Start;
return beginRenderPass(contextVk, *framebuffer, renderArea, mRenderPassDesc.value(), return beginRenderPass(contextVk, *framebuffer, renderArea, mRenderPassDesc.value(),
attachmentClearValues, commandBufferOut); attachmentClearValues, commandBufferOut);
} }
......
...@@ -90,9 +90,6 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource ...@@ -90,9 +90,6 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
GLfloat *xy) const override; GLfloat *xy) const override;
RenderTargetVk *getDepthStencilRenderTarget() const; RenderTargetVk *getDepthStencilRenderTarget() const;
const vk::RenderPassDesc &getRenderPassDesc(); const vk::RenderPassDesc &getRenderPassDesc();
angle::Result getCommandBufferForDraw(ContextVk *contextVk,
vk::CommandBuffer **commandBufferOut,
vk::RecordingMode *modeOut);
// Internal helper function for readPixels operations. // Internal helper function for readPixels operations.
angle::Result readPixelsImpl(ContextVk *contextVk, angle::Result readPixelsImpl(ContextVk *contextVk,
...@@ -107,11 +104,21 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource ...@@ -107,11 +104,21 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
gl::DrawBufferMask getEmulatedAlphaAttachmentMask(); gl::DrawBufferMask getEmulatedAlphaAttachmentMask();
RenderTargetVk *getColorReadRenderTarget() const; RenderTargetVk *getColorReadRenderTarget() const;
// This will clear the current write operation if it is complete.
using CommandGraphResource::appendToStartedRenderPass;
angle::Result startNewRenderPass(ContextVk *context, vk::CommandBuffer **commandBufferOut);
private: private:
FramebufferVk(RendererVk *renderer, FramebufferVk(RendererVk *renderer,
const gl::FramebufferState &state, const gl::FramebufferState &state,
WindowSurfaceVk *backbuffer); WindowSurfaceVk *backbuffer);
// Helper for appendToStarted/else startNewRenderPass.
angle::Result getCommandBufferForDraw(ContextVk *contextVk,
vk::CommandBuffer **commandBufferOut,
vk::RecordingMode *modeOut);
// The 'in' rectangles must be clipped to the scissor and FBO. The clipping is done in 'blit'. // The 'in' rectangles must be clipped to the scissor and FBO. The clipping is done in 'blit'.
void blitWithCommand(vk::CommandBuffer *commandBuffer, void blitWithCommand(vk::CommandBuffer *commandBuffer,
const gl::Rectangle &readRectIn, const gl::Rectangle &readRectIn,
......
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