Commit f4d693c0 by Jamie Madill Committed by Commit Bot

Vulkan: Cache clear color in ContextVk.

This makes the current clear color a bit more accessible than using the current GL state clear color directly. It is stored in the Context using the Vulkan clear color struct. This also cleans up the attachment clear values in FramebufferVk and paves the way for depth/stencil clear when support for depth/stencil exists. Bug: angleproject:2357 Change-Id: I0553e4447249325115625a44e9f4b1623c7cb0bc Reviewed-on: https://chromium-review.googlesource.com/919550 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent 57fbfd80
......@@ -69,6 +69,8 @@ ContextVk::ContextVk(const gl::ContextState &state, RendererVk *renderer)
mVertexArrayDirty(false),
mTexturesDirty(false)
{
memset(&mClearColorValue, 0, sizeof(mClearColorValue));
memset(&mClearDepthStencilValue, 0, sizeof(mClearDepthStencilValue));
}
ContextVk::~ContextVk()
......@@ -531,13 +533,17 @@ void ContextVk::syncState(const gl::Context *context, const gl::State::DirtyBits
WARN() << "DIRTY_BIT_PRIMITIVE_RESTART_ENABLED unimplemented";
break;
case gl::State::DIRTY_BIT_CLEAR_COLOR:
WARN() << "DIRTY_BIT_CLEAR_COLOR unimplemented";
mClearColorValue.color.float32[0] = glState.getColorClearValue().red;
mClearColorValue.color.float32[1] = glState.getColorClearValue().green;
mClearColorValue.color.float32[2] = glState.getColorClearValue().blue;
mClearColorValue.color.float32[3] = glState.getColorClearValue().alpha;
break;
case gl::State::DIRTY_BIT_CLEAR_DEPTH:
WARN() << "DIRTY_BIT_CLEAR_DEPTH unimplemented";
mClearDepthStencilValue.depthStencil.depth = glState.getDepthClearValue();
break;
case gl::State::DIRTY_BIT_CLEAR_STENCIL:
WARN() << "DIRTY_BIT_CLEAR_STENCIL unimplemented";
mClearDepthStencilValue.depthStencil.stencil =
static_cast<uint32_t>(glState.getStencilClearValue());
break;
case gl::State::DIRTY_BIT_UNPACK_STATE:
WARN() << "DIRTY_BIT_UNPACK_STATE unimplemented";
......@@ -796,4 +802,14 @@ vk::DescriptorPool *ContextVk::getDescriptorPool()
return &mDescriptorPool;
}
const VkClearValue &ContextVk::getClearColorValue() const
{
return mClearColorValue;
}
const VkClearValue &ContextVk::getClearDepthStencilValue() const
{
return mClearDepthStencilValue;
}
} // namespace rx
......@@ -157,6 +157,9 @@ class ContextVk : public ContextImpl
vk::DescriptorPool *getDescriptorPool();
const VkClearValue &getClearColorValue() const;
const VkClearValue &getClearDepthStencilValue() const;
private:
gl::Error initPipeline(const gl::Context *context);
gl::Error setupDraw(const gl::Context *context,
......@@ -179,6 +182,10 @@ class ContextVk : public ContextImpl
// Triggers adding dependencies to the command graph.
bool mVertexArrayDirty;
bool mTexturesDirty;
// Cached clear value for color and depth/stencil.
VkClearValue mClearColorValue;
VkClearValue mClearDepthStencilValue;
};
} // namespace rx
......
......@@ -136,21 +136,14 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
return gl::NoError();
}
const auto &glState = context->getGLState();
const auto &clearColor = glState.getColorClearValue();
VkClearColorValue clearColorValue;
clearColorValue.float32[0] = clearColor.red;
clearColorValue.float32[1] = clearColor.green;
clearColorValue.float32[2] = clearColor.blue;
clearColorValue.float32[3] = clearColor.alpha;
// TODO(jmadill): Scissored clears.
const auto *attachment = mState.getFirstNonNullAttachment();
ASSERT(attachment && attachment->isAttached());
const auto &size = attachment->getSize();
const gl::Rectangle renderArea(0, 0, size.width, size.height);
RendererVk *renderer = vk::GetImpl(context)->getRenderer();
ContextVk *contextVk = vk::GetImpl(context);
RendererVk *renderer = contextVk->getRenderer();
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteOperation(renderer, &commandBuffer));
......@@ -171,7 +164,8 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleColorImage(*renderTarget->image, clearColorValue);
commandBuffer->clearSingleColorImage(*renderTarget->image,
contextVk->getClearColorValue().color);
}
}
......@@ -491,21 +485,7 @@ gl::Error FramebufferVk::getRenderNode(const gl::Context *context, vk::CommandBu
vk::Framebuffer *framebuffer = nullptr;
ANGLE_TRY_RESULT(getFramebuffer(context, renderer), framebuffer);
const gl::State &glState = context->getGLState();
// Hard-code RenderPass to clear the first render target to the current clear value.
// TODO(jmadill): Proper clear value implementation.
VkClearColorValue colorClear;
memset(&colorClear, 0, sizeof(VkClearColorValue));
colorClear.float32[0] = glState.getColorClearValue().red;
colorClear.float32[1] = glState.getColorClearValue().green;
colorClear.float32[2] = glState.getColorClearValue().blue;
colorClear.float32[3] = glState.getColorClearValue().alpha;
std::vector<VkClearValue> attachmentClearValues;
attachmentClearValues.push_back({colorClear});
node->storeRenderPassInfo(*framebuffer, glState.getViewport(), attachmentClearValues);
// Initialize RenderPass info.
// TODO(jmadill): Could cache this info, would require dependent state change messaging.
......@@ -521,6 +501,7 @@ gl::Error FramebufferVk::getRenderNode(const gl::Context *context, vk::CommandBu
// TODO(jmadill): May need layout transition.
renderTarget->image->updateLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
node->appendColorRenderTarget(currentSerial, renderTarget);
attachmentClearValues.emplace_back(contextVk->getClearColorValue());
}
}
......@@ -533,8 +514,13 @@ gl::Error FramebufferVk::getRenderNode(const gl::Context *context, vk::CommandBu
// TODO(jmadill): May need layout transition.
renderTarget->image->updateLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
node->appendDepthStencilRenderTarget(currentSerial, renderTarget);
attachmentClearValues.emplace_back(contextVk->getClearDepthStencilValue());
}
// Hard-code RenderPass to clear the first render target to the current clear value.
// TODO(jmadill): Proper clear value implementation. http://anglebug.com/2361
const gl::State &glState = context->getGLState();
node->storeRenderPassInfo(*framebuffer, glState.getViewport(), attachmentClearValues);
mLastRenderNodeSerial = currentSerial;
*nodeOut = node;
......
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