Commit 82eda93f by Luc Ferron Committed by Commit Bot

Vulkan: Fix for framebuffer blit and Y flip

- The depth/stencil related tests are now disabled since I found out that the tests are too simple to find issues if there is a flip since they use only a single color and no gradient / checked board. This is left to implement in the Vulkan backend later on. Bug: angleproject:2673 Change-Id: I8f7091d4b9c8c3bec0353ebab28304b6209ea350 Reviewed-on: https://chromium-review.googlesource.com/1129629Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Luc Ferron <lucferron@chromium.org>
parent 853f8255
......@@ -387,10 +387,14 @@ void ContextVk::popDebugGroup()
UNIMPLEMENTED();
}
bool ContextVk::isViewportFlipEnabled() const
bool ContextVk::isViewportFlipEnabledForDrawFBO() const
{
gl::Framebuffer *framebuffer = mState.getState().getDrawFramebuffer();
return framebuffer->isDefault() && mFlipYForCurrentSurface;
return mFlipViewportForDrawFramebuffer && mFlipYForCurrentSurface;
}
bool ContextVk::isViewportFlipEnabledForReadFBO() const
{
return mFlipViewportForReadFramebuffer;
}
void ContextVk::updateColorMask(const gl::BlendState &blendState)
......@@ -412,14 +416,16 @@ void ContextVk::updateScissor(const gl::State &glState)
if (glState.isScissorTestEnabled())
{
mPipelineDesc->updateScissor(glState.getScissor(), isViewportFlipEnabled(), renderArea);
mPipelineDesc->updateScissor(glState.getScissor(), isViewportFlipEnabledForDrawFBO(),
renderArea);
}
else
{
// If the scissor test isn't enabled, we can simply use a really big scissor that's
// certainly larger than the current surface using the maximum size of a 2D texture
// for the width and height.
mPipelineDesc->updateScissor(kMaxSizedScissor, isViewportFlipEnabled(), renderArea);
mPipelineDesc->updateScissor(kMaxSizedScissor, isViewportFlipEnabledForDrawFBO(),
renderArea);
}
}
......@@ -448,7 +454,7 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
FramebufferVk *framebufferVk = vk::GetImpl(glState.getDrawFramebuffer());
mPipelineDesc->updateViewport(framebufferVk, glState.getViewport(),
glState.getNearPlane(), glState.getFarPlane(),
isViewportFlipEnabled());
isViewportFlipEnabledForDrawFBO());
ANGLE_TRY(updateDriverUniforms());
break;
}
......@@ -519,9 +525,11 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
break;
case gl::State::DIRTY_BIT_CULL_FACE_ENABLED:
case gl::State::DIRTY_BIT_CULL_FACE:
{
mPipelineDesc->updateCullMode(glState.getRasterizerState(),
isViewportFlipEnabled());
isViewportFlipEnabledForDrawFBO());
break;
}
case gl::State::DIRTY_BIT_FRONT_FACE:
mPipelineDesc->updateFrontFace(glState.getRasterizerState());
break;
......@@ -577,17 +585,18 @@ gl::Error ContextVk::syncState(const gl::Context *context, const gl::State::Dirt
WARN() << "DIRTY_BIT_SHADER_DERIVATIVE_HINT unimplemented";
break;
case gl::State::DIRTY_BIT_READ_FRAMEBUFFER_BINDING:
WARN() << "DIRTY_BIT_READ_FRAMEBUFFER_BINDING unimplemented";
updateFlipViewportReadFramebuffer(context->getGLState());
break;
case gl::State::DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING:
{
updateFlipViewportDrawFramebuffer(context->getGLState());
FramebufferVk *framebufferVk = vk::GetImpl(glState.getDrawFramebuffer());
mPipelineDesc->updateViewport(framebufferVk, glState.getViewport(),
glState.getNearPlane(), glState.getFarPlane(),
isViewportFlipEnabled());
isViewportFlipEnabledForDrawFBO());
updateColorMask(glState.getBlendState());
mPipelineDesc->updateCullMode(glState.getRasterizerState(),
isViewportFlipEnabled());
isViewportFlipEnabledForDrawFBO());
updateScissor(glState);
break;
}
......@@ -689,6 +698,24 @@ void ContextVk::onMakeCurrent(const gl::Context *context)
mFlipYForCurrentSurface =
drawSurface != nullptr && mRenderer->getFeatures().flipViewportY &&
!IsMaskFlagSet(drawSurface->getOrientation(), EGL_SURFACE_ORIENTATION_INVERT_Y_ANGLE);
const gl::State &glState = context->getGLState();
updateFlipViewportDrawFramebuffer(glState);
updateFlipViewportReadFramebuffer(glState);
}
void ContextVk::updateFlipViewportDrawFramebuffer(const gl::State &glState)
{
gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer();
mFlipViewportForDrawFramebuffer =
drawFramebuffer->isDefault() && mRenderer->getFeatures().flipViewportY;
}
void ContextVk::updateFlipViewportReadFramebuffer(const gl::State &glState)
{
gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer();
mFlipViewportForReadFramebuffer =
readFramebuffer->isDefault() && mRenderer->getFeatures().flipViewportY;
}
gl::Caps ContextVk::getNativeCaps() const
......
......@@ -87,7 +87,8 @@ class ContextVk : public ContextImpl
void pushDebugGroup(GLenum source, GLuint id, GLsizei length, const char *message) override;
void popDebugGroup() override;
bool isViewportFlipEnabled() const;
bool isViewportFlipEnabledForDrawFBO() const;
bool isViewportFlipEnabledForReadFBO() const;
// State sync with dirty bits.
gl::Error syncState(const gl::Context *context, const gl::State::DirtyBits &dirtyBits) override;
......@@ -177,6 +178,8 @@ class ContextVk : public ContextImpl
bool *shouldApplyVertexArrayOut);
void updateScissor(const gl::State &glState);
void updateFlipViewportDrawFramebuffer(const gl::State &glState);
void updateFlipViewportReadFramebuffer(const gl::State &glState);
vk::Error updateDriverUniforms();
......@@ -206,6 +209,8 @@ class ContextVk : public ContextImpl
// If the current surface bound to this context wants to have all rendering flipped vertically.
// Updated on calls to onMakeCurrent.
bool mFlipYForCurrentSurface;
bool mFlipViewportForDrawFramebuffer;
bool mFlipViewportForReadFramebuffer;
// For shader uniforms such as gl_DepthRange and the viewport size.
struct DriverUniforms
......
......@@ -306,7 +306,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
return gl::NoError();
}
gl::Rectangle flippedArea = clippedArea;
if (contextVk->isViewportFlipEnabled())
if (contextVk->isViewportFlipEnabledForDrawFBO())
{
flippedArea.y = fbRect.height - flippedArea.y - flippedArea.height;
}
......@@ -317,7 +317,7 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
gl::PixelPackState packState(glState.getPackState());
if (contextVk->isViewportFlipEnabled())
if (contextVk->isViewportFlipEnabledForDrawFBO())
{
packState.reverseRowOrder = !packState.reverseRowOrder;
}
......@@ -448,6 +448,9 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
FramebufferVk *sourceFramebufferVk = vk::GetImpl(sourceFramebuffer);
bool flipSource = contextVk->isViewportFlipEnabledForReadFBO();
bool flipDest = contextVk->isViewportFlipEnabledForDrawFBO();
if (blitColorBuffer)
{
RenderTargetVk *readRenderTarget = sourceFramebufferVk->getColorReadRenderTarget();
......@@ -458,8 +461,9 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
ASSERT(drawRenderTarget);
ASSERT(HasSrcAndDstBlitProperties(renderer->getPhysicalDevice(), readRenderTarget,
drawRenderTarget));
ANGLE_TRY(blitImpl(commandBuffer, sourceArea, destArea, readRenderTarget,
drawRenderTarget, filter, scissor, true, false, false));
ANGLE_TRY(blitImpl(contextVk, commandBuffer, sourceArea, destArea, readRenderTarget,
drawRenderTarget, filter, scissor, true, false, false, flipSource,
flipDest));
}
}
......@@ -473,12 +477,22 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
if (HasSrcAndDstBlitProperties(renderer->getPhysicalDevice(), readRenderTarget,
drawRenderTarget))
{
ANGLE_TRY(blitImpl(commandBuffer, sourceArea, destArea, readRenderTarget,
ANGLE_TRY(blitImpl(contextVk, commandBuffer, sourceArea, destArea, readRenderTarget,
drawRenderTarget, filter, scissor, false, blitDepthBuffer,
blitStencilBuffer));
blitStencilBuffer, flipSource, flipDest));
}
else
{
if (flipSource || contextVk->isViewportFlipEnabledForReadFBO())
{
// The tests in BlitFramebufferANGLETest are passing, but they are wrong since they
// use a single color for the depth / stencil buffers, it looks like its working,
// but if it was a gradient or a checked board, you would realize the flip isn't
// happening with this copy.
UNIMPLEMENTED();
return gl::InternalError();
}
ASSERT(filter == GL_NEAREST);
ANGLE_TRY(blitUsingCopy(renderer, commandBuffer, sourceArea, destArea, readRenderTarget,
drawRenderTarget, scissor, blitDepthBuffer, blitStencilBuffer));
......@@ -488,7 +502,8 @@ gl::Error FramebufferVk::blit(const gl::Context *context,
return gl::NoError();
}
gl::Error FramebufferVk::blitImpl(vk::CommandBuffer *commandBuffer,
gl::Error FramebufferVk::blitImpl(ContextVk *contextVk,
vk::CommandBuffer *commandBuffer,
const gl::Rectangle &readRectIn,
const gl::Rectangle &drawRectIn,
RenderTargetVk *readRenderTarget,
......@@ -497,7 +512,9 @@ gl::Error FramebufferVk::blitImpl(vk::CommandBuffer *commandBuffer,
const gl::Rectangle *scissor,
bool colorBlit,
bool depthBlit,
bool stencilBlit)
bool stencilBlit,
bool flipSource,
bool flipDest)
{
// Since blitRenderbufferRect is called for each render buffer that needs to be blitted,
// it should never be the case that both color and depth/stencil need to be blitted at
......@@ -537,9 +554,17 @@ gl::Error FramebufferVk::blitImpl(vk::CommandBuffer *commandBuffer,
vk::ImageHelper *srcImage = readRenderTarget->getImageForRead(
this, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, aspectMask, commandBuffer);
if (flipSource)
{
scissoredReadRect.y =
sourceFrameBufferExtents.height - scissoredReadRect.y - scissoredReadRect.height;
}
VkImageBlit blit = {};
blit.srcOffsets[0] = {scissoredReadRect.x0(), scissoredReadRect.y0(), 0};
blit.srcOffsets[1] = {scissoredReadRect.x1(), scissoredReadRect.y1(), 1};
blit.srcOffsets[0] = {scissoredReadRect.x0(),
flipSource ? scissoredReadRect.y1() : scissoredReadRect.y0(), 0};
blit.srcOffsets[1] = {scissoredReadRect.x1(),
flipSource ? scissoredReadRect.y0() : scissoredReadRect.y1(), 1};
blit.srcSubresource.aspectMask = aspectMask;
blit.srcSubresource.mipLevel = 0;
blit.srcSubresource.baseArrayLayer = 0;
......@@ -557,8 +582,16 @@ gl::Error FramebufferVk::blitImpl(vk::CommandBuffer *commandBuffer,
return gl::NoError();
}
blit.dstOffsets[0] = {scissoredDrawRect.x0(), scissoredDrawRect.y0(), 0};
blit.dstOffsets[1] = {scissoredDrawRect.x1(), scissoredDrawRect.y1(), 1};
if (flipDest)
{
scissoredDrawRect.y =
drawFrameBufferBounds.height - scissoredDrawRect.y - scissoredDrawRect.height;
}
blit.dstOffsets[0] = {scissoredDrawRect.x0(),
flipDest ? scissoredDrawRect.y1() : scissoredDrawRect.y0(), 0};
blit.dstOffsets[1] = {scissoredDrawRect.x1(),
flipDest ? scissoredDrawRect.y0() : scissoredDrawRect.y1(), 1};
vk::ImageHelper *dstImage = drawRenderTarget->getImageForWrite(this);
......@@ -785,7 +818,7 @@ gl::Error FramebufferVk::clearWithClearAttachments(ContextVk *contextVk,
clearRect.rect = gl_vk::GetRect(intersection);
if (contextVk->isViewportFlipEnabled())
if (contextVk->isViewportFlipEnabledForDrawFBO())
{
clearRect.rect.offset.y = getRenderPassRenderArea().height - clearRect.rect.offset.y -
clearRect.rect.extent.height;
......@@ -896,7 +929,9 @@ gl::Error FramebufferVk::clearWithDraw(const gl::Context *context,
pipelineDesc.updateColorWriteMask(colorMaskFlags, getEmulatedAlphaAttachmentMask());
pipelineDesc.updateRenderPassDesc(getRenderPassDesc());
pipelineDesc.updateShaders(fullScreenQuad->queueSerial(), pushConstantColor->queueSerial());
pipelineDesc.updateViewport(this, renderArea, 0.0f, 1.0f, contextVk->isViewportFlipEnabled());
bool invertViewport = contextVk->isViewportFlipEnabledForDrawFBO();
pipelineDesc.updateViewport(this, renderArea, 0.0f, 1.0f, invertViewport);
const gl::State &glState = contextVk->getGLState();
if (glState.isScissorTestEnabled())
......@@ -907,11 +942,11 @@ gl::Error FramebufferVk::clearWithDraw(const gl::Context *context,
return gl::NoError();
}
pipelineDesc.updateScissor(intersection, contextVk->isViewportFlipEnabled(), renderArea);
pipelineDesc.updateScissor(intersection, invertViewport, renderArea);
}
else
{
pipelineDesc.updateScissor(renderArea, contextVk->isViewportFlipEnabled(), renderArea);
pipelineDesc.updateScissor(renderArea, invertViewport, renderArea);
}
vk::PipelineAndSerial *pipeline = nullptr;
......
......@@ -126,7 +126,8 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
gl::Error clearWithDraw(const gl::Context *context, VkColorComponentFlags colorMaskFlags);
void updateActiveColorMasks(size_t colorIndex, bool r, bool g, bool b, bool a);
gl::Error blitImpl(vk::CommandBuffer *commandBuffer,
gl::Error blitImpl(ContextVk *contextVk,
vk::CommandBuffer *commandBuffer,
const gl::Rectangle &readRectIn,
const gl::Rectangle &drawRectIn,
RenderTargetVk *readRenderTarget,
......@@ -135,7 +136,9 @@ class FramebufferVk : public FramebufferImpl, public vk::CommandGraphResource
const gl::Rectangle *scissor,
bool colorBlit,
bool depthBlit,
bool stencilBlit);
bool stencilBlit,
bool flipSource,
bool flipDest);
RenderTargetVk *getColorReadRenderTarget() const;
......
......@@ -570,6 +570,10 @@ TEST_P(BlitFramebufferANGLETest, ReverseOversizedBlit)
// blit from user-created FBO to system framebuffer, with depth buffer.
TEST_P(BlitFramebufferANGLETest, BlitWithDepth)
{
// TODO(lucferron): Fix this test and the implementation.
// http://anglebug.com/2673
ANGLE_SKIP_TEST_IF(IsVulkan());
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
......@@ -609,6 +613,10 @@ TEST_P(BlitFramebufferANGLETest, BlitWithDepth)
// blit from system FBO to user-created framebuffer, with depth buffer.
TEST_P(BlitFramebufferANGLETest, ReverseBlitWithDepth)
{
// TODO(lucferron): Fix this test and the implementation.
// http://anglebug.com/2673
ANGLE_SKIP_TEST_IF(IsVulkan());
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
glBindFramebuffer(GL_FRAMEBUFFER, mOriginalFBO);
......@@ -781,6 +789,10 @@ TEST_P(BlitFramebufferANGLETest, BlitWithMissingAttachments)
TEST_P(BlitFramebufferANGLETest, BlitStencil)
{
// TODO(lucferron): Fix this test and the implementation.
// http://anglebug.com/2673
ANGLE_SKIP_TEST_IF(IsVulkan());
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
// TODO(jmadill): Figure out if we can fix this on D3D9.
......@@ -833,6 +845,10 @@ TEST_P(BlitFramebufferANGLETest, BlitStencil)
// make sure that attempting to blit a partial depth buffer issues an error
TEST_P(BlitFramebufferANGLETest, BlitPartialDepthStencil)
{
// TODO(lucferron): Fix this test and the implementation.
// http://anglebug.com/2673
ANGLE_SKIP_TEST_IF(IsVulkan());
ANGLE_SKIP_TEST_IF(!extensionEnabled("GL_ANGLE_framebuffer_blit"));
glBindFramebuffer(GL_FRAMEBUFFER, mUserFBO);
......
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