Commit d4826159 by Jamie Madill Committed by Commit Bot

Vulkan: Only init RenderPass once per frame.

This saves some time spent in the driver, by making multiple draw calls happen inside a single RenderPass. This also makes the ReadPixels impl method non-const. I think in the future we should avoid making const Impl methods unless they're totally trivial. BUG=angleproject:1898 Change-Id: I39172270a2f7dc5c1c2e3d4cc50af3bac8a29fa1 Reviewed-on: https://chromium-review.googlesource.com/672148Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 1f9d6843
...@@ -70,7 +70,7 @@ class FramebufferImpl : angle::NonCopyable ...@@ -70,7 +70,7 @@ class FramebufferImpl : angle::NonCopyable
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const = 0; void *pixels) = 0;
virtual gl::Error blit(const gl::Context *context, virtual gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -36,9 +36,8 @@ class MockFramebufferImpl : public rx::FramebufferImpl ...@@ -36,9 +36,8 @@ class MockFramebufferImpl : public rx::FramebufferImpl
MOCK_CONST_METHOD1(getImplementationColorReadFormat, GLenum(const gl::Context *)); MOCK_CONST_METHOD1(getImplementationColorReadFormat, GLenum(const gl::Context *));
MOCK_CONST_METHOD1(getImplementationColorReadType, GLenum(const gl::Context *)); MOCK_CONST_METHOD1(getImplementationColorReadType, GLenum(const gl::Context *));
MOCK_CONST_METHOD5( MOCK_METHOD5(readPixels,
readPixels, gl::Error(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *));
gl::Error(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *));
MOCK_CONST_METHOD2(getSamplePosition, gl::Error(size_t, GLfloat *)); MOCK_CONST_METHOD2(getSamplePosition, gl::Error(size_t, GLfloat *));
......
...@@ -239,7 +239,7 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context, ...@@ -239,7 +239,7 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context,
const gl::Rectangle &origArea, const gl::Rectangle &origArea,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const void *pixels)
{ {
// Clip read area to framebuffer. // Clip read area to framebuffer.
const gl::Extents fbSize = getState().getReadAttachment()->getSize(); const gl::Extents fbSize = getState().getReadAttachment()->getSize();
......
...@@ -84,7 +84,7 @@ class FramebufferD3D : public FramebufferImpl ...@@ -84,7 +84,7 @@ class FramebufferD3D : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const override; void *pixels) override;
gl::Error blit(const gl::Context *context, gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
...@@ -108,7 +108,7 @@ class FramebufferD3D : public FramebufferImpl ...@@ -108,7 +108,7 @@ class FramebufferD3D : public FramebufferImpl
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const = 0; uint8_t *pixels) = 0;
virtual gl::Error blitImpl(const gl::Context *context, virtual gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -279,7 +279,7 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Context *context, ...@@ -279,7 +279,7 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Context *context,
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const uint8_t *pixels)
{ {
const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment(); const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment();
ASSERT(readAttachment); ASSERT(readAttachment);
......
...@@ -65,7 +65,7 @@ class Framebuffer11 : public FramebufferD3D, public OnRenderTargetDirtyReceiver ...@@ -65,7 +65,7 @@ class Framebuffer11 : public FramebufferD3D, public OnRenderTargetDirtyReceiver
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const override; uint8_t *pixels) override;
gl::Error blitImpl(const gl::Context *context, gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -83,7 +83,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Context *context, ...@@ -83,7 +83,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Context *context,
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const uint8_t *pixels)
{ {
ASSERT(pack.pixelBuffer.get() == nullptr); ASSERT(pack.pixelBuffer.get() == nullptr);
......
...@@ -41,7 +41,7 @@ class Framebuffer9 : public FramebufferD3D ...@@ -41,7 +41,7 @@ class Framebuffer9 : public FramebufferD3D
GLenum type, GLenum type,
size_t outputPitch, size_t outputPitch,
const gl::PixelPackState &pack, const gl::PixelPackState &pack,
uint8_t *pixels) const override; uint8_t *pixels) override;
gl::Error blitImpl(const gl::Context *context, gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -417,7 +417,7 @@ Error FramebufferGL::readPixels(const gl::Context *context, ...@@ -417,7 +417,7 @@ Error FramebufferGL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea, const gl::Rectangle &origArea,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *ptrOrOffset) const void *ptrOrOffset)
{ {
// Clip read area to framebuffer. // Clip read area to framebuffer.
const gl::Extents fbSize = getState().getReadAttachment()->getSize(); const gl::Extents fbSize = getState().getReadAttachment()->getSize();
......
...@@ -77,7 +77,7 @@ class FramebufferGL : public FramebufferImpl ...@@ -77,7 +77,7 @@ class FramebufferGL : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const override; void *pixels) override;
gl::Error blit(const gl::Context *context, gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -116,7 +116,7 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context, ...@@ -116,7 +116,7 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea, const gl::Rectangle &origArea,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *ptrOrOffset) const void *ptrOrOffset)
{ {
const gl::PixelPackState &packState = context->getGLState().getPackState(); const gl::PixelPackState &packState = context->getGLState().getPackState();
......
...@@ -55,7 +55,7 @@ class FramebufferNULL : public FramebufferImpl ...@@ -55,7 +55,7 @@ class FramebufferNULL : public FramebufferImpl
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const override; void *pixels) override;
gl::Error blit(const gl::Context *context, gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
......
...@@ -317,14 +317,13 @@ gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint f ...@@ -317,14 +317,13 @@ gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint f
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer)); ANGLE_TRY(mRenderer->getStartedCommandBuffer(&commandBuffer));
ANGLE_TRY(vkFBO->beginRenderPass(context, device, commandBuffer, queueSerial, state)); ANGLE_TRY(vkFBO->ensureInRenderPass(context, device, commandBuffer, queueSerial, state));
commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline); commandBuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, mCurrentPipeline);
// TODO(jmadill): the queue serial should be bound to the pipeline. // TODO(jmadill): the queue serial should be bound to the pipeline.
setQueueSerial(queueSerial); setQueueSerial(queueSerial);
commandBuffer->bindVertexBuffers(0, vertexHandles, vertexOffsets); commandBuffer->bindVertexBuffers(0, vertexHandles, vertexOffsets);
commandBuffer->draw(count, 1, first, 0); commandBuffer->draw(count, 1, first, 0);
commandBuffer->endRenderPass();
return gl::NoError(); return gl::NoError();
} }
......
...@@ -81,12 +81,20 @@ FramebufferVk *FramebufferVk::CreateDefaultFBO(const gl::FramebufferState &state ...@@ -81,12 +81,20 @@ FramebufferVk *FramebufferVk::CreateDefaultFBO(const gl::FramebufferState &state
} }
FramebufferVk::FramebufferVk(const gl::FramebufferState &state) FramebufferVk::FramebufferVk(const gl::FramebufferState &state)
: FramebufferImpl(state), mBackbuffer(nullptr), mRenderPass(), mFramebuffer() : FramebufferImpl(state),
mBackbuffer(nullptr),
mRenderPass(),
mFramebuffer(),
mInRenderPass(false)
{ {
} }
FramebufferVk::FramebufferVk(const gl::FramebufferState &state, WindowSurfaceVk *backbuffer) FramebufferVk::FramebufferVk(const gl::FramebufferState &state, WindowSurfaceVk *backbuffer)
: FramebufferImpl(state), mBackbuffer(backbuffer), mRenderPass(), mFramebuffer() : FramebufferImpl(state),
mBackbuffer(backbuffer),
mRenderPass(),
mFramebuffer(),
mInRenderPass(false)
{ {
} }
...@@ -96,6 +104,8 @@ FramebufferVk::~FramebufferVk() ...@@ -96,6 +104,8 @@ FramebufferVk::~FramebufferVk()
void FramebufferVk::destroy(const gl::Context *context) void FramebufferVk::destroy(const gl::Context *context)
{ {
ASSERT(!mInRenderPass);
VkDevice device = GetImplAs<ContextVk>(context)->getDevice(); VkDevice device = GetImplAs<ContextVk>(context)->getDevice();
mRenderPass.destroy(device); mRenderPass.destroy(device);
...@@ -257,7 +267,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -257,7 +267,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const void *pixels)
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
const auto *readFramebuffer = glState.getReadFramebuffer(); const auto *readFramebuffer = glState.getReadFramebuffer();
...@@ -278,6 +288,9 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context, ...@@ -278,6 +288,9 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer)); ANGLE_TRY(contextVk->getStartedCommandBuffer(&commandBuffer));
// End render pass if we're in one.
endRenderPass(commandBuffer);
stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL, stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
commandBuffer); commandBuffer);
...@@ -543,12 +556,19 @@ gl::Error FramebufferVk::getSamplePosition(size_t index, GLfloat *xy) const ...@@ -543,12 +556,19 @@ gl::Error FramebufferVk::getSamplePosition(size_t index, GLfloat *xy) const
return gl::InternalError() << "getSamplePosition is unimplemented."; return gl::InternalError() << "getSamplePosition is unimplemented.";
} }
gl::Error FramebufferVk::beginRenderPass(const gl::Context *context, gl::Error FramebufferVk::ensureInRenderPass(const gl::Context *context,
VkDevice device, VkDevice device,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
Serial queueSerial, Serial queueSerial,
const gl::State &glState) const gl::State &glState)
{ {
if (mInRenderPass)
{
return gl::NoError();
}
mInRenderPass = true;
// TODO(jmadill): Cache render targets. // TODO(jmadill): Cache render targets.
for (const auto &colorAttachment : mState.getColorAttachments()) for (const auto &colorAttachment : mState.getColorAttachments())
{ {
...@@ -607,4 +627,13 @@ gl::Error FramebufferVk::beginRenderPass(const gl::Context *context, ...@@ -607,4 +627,13 @@ gl::Error FramebufferVk::beginRenderPass(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
void FramebufferVk::endRenderPass(vk::CommandBuffer *commandBuffer)
{
if (mInRenderPass)
{
commandBuffer->endRenderPass();
mInRenderPass = false;
}
}
} // namespace rx } // namespace rx
...@@ -68,7 +68,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk ...@@ -68,7 +68,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
const gl::Rectangle &area, const gl::Rectangle &area,
GLenum format, GLenum format,
GLenum type, GLenum type,
void *pixels) const override; void *pixels) override;
gl::Error blit(const gl::Context *context, gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
...@@ -83,11 +83,14 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk ...@@ -83,11 +83,14 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
gl::Error getSamplePosition(size_t index, GLfloat *xy) const override; gl::Error getSamplePosition(size_t index, GLfloat *xy) const override;
gl::Error beginRenderPass(const gl::Context *context, gl::Error ensureInRenderPass(const gl::Context *context,
VkDevice device, VkDevice device,
vk::CommandBuffer *commandBuffer, vk::CommandBuffer *commandBuffer,
Serial queueSerial, Serial queueSerial,
const gl::State &glState); const gl::State &glState);
void endRenderPass(vk::CommandBuffer *commandBuffer);
bool isInRenderPass() const { return mInRenderPass; }
gl::ErrorOrResult<vk::RenderPass *> getRenderPass(const gl::Context *context, VkDevice device); gl::ErrorOrResult<vk::RenderPass *> getRenderPass(const gl::Context *context, VkDevice device);
...@@ -102,6 +105,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk ...@@ -102,6 +105,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
vk::RenderPass mRenderPass; vk::RenderPass mRenderPass;
vk::Framebuffer mFramebuffer; vk::Framebuffer mFramebuffer;
bool mInRenderPass;
}; };
} // namespace rx } // namespace rx
......
...@@ -420,14 +420,15 @@ FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Framebuffer ...@@ -420,14 +420,15 @@ FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Framebuffer
egl::Error WindowSurfaceVk::swap(const gl::Context *context) egl::Error WindowSurfaceVk::swap(const gl::Context *context)
{ {
const DisplayVk *displayVk = GetImplAs<DisplayVk>(context->getCurrentDisplay()); const DisplayVk *displayVk = GetImplAs<DisplayVk>(context->getCurrentDisplay());
return swapImpl(displayVk->getRenderer()).toEGL(EGL_BAD_ALLOC); RendererVk *renderer = displayVk->getRenderer();
}
vk::Error WindowSurfaceVk::swapImpl(RendererVk *renderer)
{
vk::CommandBuffer *currentCB = nullptr; vk::CommandBuffer *currentCB = nullptr;
ANGLE_TRY(renderer->getStartedCommandBuffer(&currentCB)); ANGLE_TRY(renderer->getStartedCommandBuffer(&currentCB));
// End render pass
FramebufferVk *framebufferVk = GetImplAs<FramebufferVk>(mState.defaultFramebuffer);
framebufferVk->endRenderPass(currentCB);
auto *image = &mSwapchainImages[mCurrentSwapchainImageIndex]; auto *image = &mSwapchainImages[mCurrentSwapchainImageIndex];
image->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, image->changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
......
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