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
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const = 0;
void *pixels) = 0;
virtual gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -36,9 +36,8 @@ class MockFramebufferImpl : public rx::FramebufferImpl
MOCK_CONST_METHOD1(getImplementationColorReadFormat, GLenum(const gl::Context *));
MOCK_CONST_METHOD1(getImplementationColorReadType, GLenum(const gl::Context *));
MOCK_CONST_METHOD5(
readPixels,
gl::Error(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *));
MOCK_METHOD5(readPixels,
gl::Error(const gl::Context *, const gl::Rectangle &, GLenum, GLenum, void *));
MOCK_CONST_METHOD2(getSamplePosition, gl::Error(size_t, GLfloat *));
......
......@@ -239,7 +239,7 @@ gl::Error FramebufferD3D::readPixels(const gl::Context *context,
const gl::Rectangle &origArea,
GLenum format,
GLenum type,
void *pixels) const
void *pixels)
{
// Clip read area to framebuffer.
const gl::Extents fbSize = getState().getReadAttachment()->getSize();
......
......@@ -84,7 +84,7 @@ class FramebufferD3D : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const override;
void *pixels) override;
gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea,
......@@ -108,7 +108,7 @@ class FramebufferD3D : public FramebufferImpl
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels) const = 0;
uint8_t *pixels) = 0;
virtual gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -279,7 +279,7 @@ gl::Error Framebuffer11::readPixelsImpl(const gl::Context *context,
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels) const
uint8_t *pixels)
{
const gl::FramebufferAttachment *readAttachment = mState.getReadAttachment();
ASSERT(readAttachment);
......
......@@ -65,7 +65,7 @@ class Framebuffer11 : public FramebufferD3D, public OnRenderTargetDirtyReceiver
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels) const override;
uint8_t *pixels) override;
gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -83,7 +83,7 @@ gl::Error Framebuffer9::readPixelsImpl(const gl::Context *context,
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels) const
uint8_t *pixels)
{
ASSERT(pack.pixelBuffer.get() == nullptr);
......
......@@ -41,7 +41,7 @@ class Framebuffer9 : public FramebufferD3D
GLenum type,
size_t outputPitch,
const gl::PixelPackState &pack,
uint8_t *pixels) const override;
uint8_t *pixels) override;
gl::Error blitImpl(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -417,7 +417,7 @@ Error FramebufferGL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea,
GLenum format,
GLenum type,
void *ptrOrOffset) const
void *ptrOrOffset)
{
// Clip read area to framebuffer.
const gl::Extents fbSize = getState().getReadAttachment()->getSize();
......
......@@ -77,7 +77,7 @@ class FramebufferGL : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const override;
void *pixels) override;
gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -116,7 +116,7 @@ gl::Error FramebufferNULL::readPixels(const gl::Context *context,
const gl::Rectangle &origArea,
GLenum format,
GLenum type,
void *ptrOrOffset) const
void *ptrOrOffset)
{
const gl::PixelPackState &packState = context->getGLState().getPackState();
......
......@@ -55,7 +55,7 @@ class FramebufferNULL : public FramebufferImpl
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const override;
void *pixels) override;
gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea,
......
......@@ -317,14 +317,13 @@ gl::Error ContextVk::drawArrays(const gl::Context *context, GLenum mode, GLint f
vk::CommandBuffer *commandBuffer = nullptr;
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);
// TODO(jmadill): the queue serial should be bound to the pipeline.
setQueueSerial(queueSerial);
commandBuffer->bindVertexBuffers(0, vertexHandles, vertexOffsets);
commandBuffer->draw(count, 1, first, 0);
commandBuffer->endRenderPass();
return gl::NoError();
}
......
......@@ -81,12 +81,20 @@ FramebufferVk *FramebufferVk::CreateDefaultFBO(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)
: FramebufferImpl(state), mBackbuffer(backbuffer), mRenderPass(), mFramebuffer()
: FramebufferImpl(state),
mBackbuffer(backbuffer),
mRenderPass(),
mFramebuffer(),
mInRenderPass(false)
{
}
......@@ -96,6 +104,8 @@ FramebufferVk::~FramebufferVk()
void FramebufferVk::destroy(const gl::Context *context)
{
ASSERT(!mInRenderPass);
VkDevice device = GetImplAs<ContextVk>(context)->getDevice();
mRenderPass.destroy(device);
......@@ -257,7 +267,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const
void *pixels)
{
const auto &glState = context->getGLState();
const auto *readFramebuffer = glState.getReadFramebuffer();
......@@ -278,6 +288,9 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
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,
commandBuffer);
......@@ -543,12 +556,19 @@ gl::Error FramebufferVk::getSamplePosition(size_t index, GLfloat *xy) const
return gl::InternalError() << "getSamplePosition is unimplemented.";
}
gl::Error FramebufferVk::beginRenderPass(const gl::Context *context,
VkDevice device,
vk::CommandBuffer *commandBuffer,
Serial queueSerial,
const gl::State &glState)
gl::Error FramebufferVk::ensureInRenderPass(const gl::Context *context,
VkDevice device,
vk::CommandBuffer *commandBuffer,
Serial queueSerial,
const gl::State &glState)
{
if (mInRenderPass)
{
return gl::NoError();
}
mInRenderPass = true;
// TODO(jmadill): Cache render targets.
for (const auto &colorAttachment : mState.getColorAttachments())
{
......@@ -607,4 +627,13 @@ gl::Error FramebufferVk::beginRenderPass(const gl::Context *context,
return gl::NoError();
}
void FramebufferVk::endRenderPass(vk::CommandBuffer *commandBuffer)
{
if (mInRenderPass)
{
commandBuffer->endRenderPass();
mInRenderPass = false;
}
}
} // namespace rx
......@@ -68,7 +68,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
const gl::Rectangle &area,
GLenum format,
GLenum type,
void *pixels) const override;
void *pixels) override;
gl::Error blit(const gl::Context *context,
const gl::Rectangle &sourceArea,
......@@ -83,11 +83,14 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
gl::Error getSamplePosition(size_t index, GLfloat *xy) const override;
gl::Error beginRenderPass(const gl::Context *context,
VkDevice device,
vk::CommandBuffer *commandBuffer,
Serial queueSerial,
const gl::State &glState);
gl::Error ensureInRenderPass(const gl::Context *context,
VkDevice device,
vk::CommandBuffer *commandBuffer,
Serial queueSerial,
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);
......@@ -102,6 +105,7 @@ class FramebufferVk : public FramebufferImpl, public ResourceVk
vk::RenderPass mRenderPass;
vk::Framebuffer mFramebuffer;
bool mInRenderPass;
};
} // namespace rx
......
......@@ -420,14 +420,15 @@ FramebufferImpl *WindowSurfaceVk::createDefaultFramebuffer(const gl::Framebuffer
egl::Error WindowSurfaceVk::swap(const gl::Context *context)
{
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;
ANGLE_TRY(renderer->getStartedCommandBuffer(&currentCB));
// End render pass
FramebufferVk *framebufferVk = GetImplAs<FramebufferVk>(mState.defaultFramebuffer);
framebufferVk->endRenderPass(currentCB);
auto *image = &mSwapchainImages[mCurrentSwapchainImageIndex];
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