Commit e6a40d07 by Luc Ferron Committed by Commit Bot

Vulkan: Depth / stencil attachments bug fixes

I found a couple of bugs trying to enable polygon offset render states. This is just pre-work to get to a better state. Bug:angleproject:2353 Change-Id: If6af949a09af1340e870afb627ae427d01c6e77c Reviewed-on: https://chromium-review.googlesource.com/975631 Commit-Queue: Luc Ferron <lucferron@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9fb23f61
...@@ -143,8 +143,9 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask) ...@@ -143,8 +143,9 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
// We only support packed depth/stencil, not separate. // We only support packed depth/stencil, not separate.
ASSERT(!(clearDepth && clearStencil) || mState.getDepthStencilAttachment()); ASSERT(!(clearDepth && clearStencil) || mState.getDepthStencilAttachment());
const VkImageAspectFlags aspectFlags = (clearDepth ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) | const VkImageAspectFlags aspectFlags =
(clearDepth ? VK_IMAGE_ASPECT_STENCIL_BIT : 0); (depthAttachment ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
(stencilAttachment ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil(); RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil();
renderTarget->resource->onWriteResource(writingNode, currentSerial); renderTarget->resource->onWriteResource(writingNode, currentSerial);
......
...@@ -16,6 +16,13 @@ ...@@ -16,6 +16,13 @@
namespace rx namespace rx
{ {
namespace
{
constexpr VkClearDepthStencilValue kDefaultClearDepthStencilValue = {0.0f, 1};
constexpr VkClearColorValue kBlackClearColorValue = {{0}};
} // anonymous namespace
RenderbufferVk::RenderbufferVk(const gl::RenderbufferState &state) RenderbufferVk::RenderbufferVk(const gl::RenderbufferState &state)
: RenderbufferImpl(state), mAllocatedMemorySize(0) : RenderbufferImpl(state), mAllocatedMemorySize(0)
{ {
...@@ -77,9 +84,13 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context, ...@@ -77,9 +84,13 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
if (!mImage.valid() && (width != 0 || height != 0)) if (!mImage.valid() && (width != 0 || height != 0))
{ {
const angle::Format &textureFormat = vkFormat.textureFormat();
bool isDepthOrStencilFormat = textureFormat.depthBits > 0 || textureFormat.stencilBits > 0;
const VkImageUsageFlags usage = const VkImageUsageFlags usage =
(VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT); VK_IMAGE_USAGE_SAMPLED_BIT |
(textureFormat.redBits > 0 ? VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT : 0) |
(isDepthOrStencilFormat ? VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT : 0);
VkImageCreateInfo imageInfo; VkImageCreateInfo imageInfo;
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO; imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
...@@ -106,7 +117,10 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context, ...@@ -106,7 +117,10 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
ANGLE_TRY(vk::AllocateImageMemory(renderer, flags, &mImage, &mDeviceMemory, ANGLE_TRY(vk::AllocateImageMemory(renderer, flags, &mImage, &mDeviceMemory,
&mAllocatedMemorySize)); &mAllocatedMemorySize));
VkImageAspectFlags aspect = VK_IMAGE_ASPECT_COLOR_BIT; VkImageAspectFlags aspect =
(textureFormat.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
(textureFormat.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0) |
(textureFormat.redBits > 0 ? VK_IMAGE_ASPECT_COLOR_BIT : 0);
// Allocate ImageView. // Allocate ImageView.
VkImageViewCreateInfo viewInfo; VkImageViewCreateInfo viewInfo;
...@@ -131,11 +145,19 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context, ...@@ -131,11 +145,19 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
// TODO(jmadill): Fold this into the RenderPass load/store ops. http://anglebug.com/2361 // TODO(jmadill): Fold this into the RenderPass load/store ops. http://anglebug.com/2361
vk::CommandBuffer *commandBuffer = nullptr; vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer)); ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
VkClearColorValue black = {{0}}; mImage.changeLayoutWithStages(aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
mImage.changeLayoutWithStages( VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleColorImage(mImage, black); if (isDepthOrStencilFormat)
{
commandBuffer->clearSingleDepthStencilImage(mImage, aspect,
kDefaultClearDepthStencilValue);
}
else
{
commandBuffer->clearSingleColorImage(mImage, kBlackClearColorValue);
}
} }
return gl::NoError(); return gl::NoError();
......
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