Commit 858c1ccc by Jamie Madill Committed by Commit Bot

Vulkan: Move image layout into helper.

Now that we're using the helper everywhere, we can clean up the vk::Image class and move the layout tracking into ImageHelper. Bug: angleproject:2318 Change-Id: I9636835a2a3a76f181dac629bd4182bc5815cdee Reviewed-on: https://chromium-review.googlesource.com/980774 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent 24a3137a
......@@ -161,12 +161,7 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
RenderTargetVk *renderTarget = mRenderTargetCache.getDepthStencil();
renderTarget->resource->onWriteResource(writingNode, currentSerial);
renderTarget->image->getImage().changeLayoutWithStages(
aspectFlags, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleDepthStencilImage(renderTarget->image->getImage(), aspectFlags,
clearDepthStencilValue);
renderTarget->image->clearDepthStencil(aspectFlags, clearDepthStencilValue, commandBuffer);
if (!clearColor)
{
......@@ -191,13 +186,7 @@ gl::Error FramebufferVk::clear(const gl::Context *context, GLbitfield mask)
RenderTargetVk *colorRenderTarget = colorRenderTargets[colorIndex];
ASSERT(colorRenderTarget);
colorRenderTarget->resource->onWriteResource(writingNode, currentSerial);
colorRenderTarget->image->getImage().changeLayoutWithStages(
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(colorRenderTarget->image->getImage(),
contextVk->getClearColorValue().color);
colorRenderTarget->image->clearColor(contextVk->getClearColorValue().color, commandBuffer);
}
return gl::NoError();
......@@ -264,7 +253,6 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
RenderTargetVk *renderTarget = mRenderTargetCache.getColorRead(mState);
ASSERT(renderTarget);
vk::Image &readImage = renderTarget->image->getImage();
vk::ImageHelper stagingImage;
ANGLE_TRY(stagingImage.init2DStaging(
device, renderer->getMemoryProperties(), renderTarget->image->getFormat(),
......@@ -273,33 +261,13 @@ gl::Error FramebufferVk::readPixels(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
stagingImage.getImage().changeLayoutTop(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
commandBuffer);
readImage.changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
VkImageCopy region;
region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.srcSubresource.mipLevel = 0;
region.srcSubresource.baseArrayLayer = 0;
region.srcSubresource.layerCount = 1;
region.srcOffset.x = area.x;
region.srcOffset.y = area.y;
region.srcOffset.z = 0;
region.dstSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.dstSubresource.mipLevel = 0;
region.dstSubresource.baseArrayLayer = 0;
region.dstSubresource.layerCount = 1;
region.dstOffset.x = 0;
region.dstOffset.y = 0;
region.dstOffset.z = 0;
region.extent.width = area.width;
region.extent.height = area.height;
region.extent.depth = 1;
commandBuffer->copyImage(readImage, stagingImage.getImage(), 1, &region);
stagingImage.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_GENERAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, commandBuffer);
vk::ImageHelper::Copy(renderTarget->image, &stagingImage, gl::Offset(area.x, area.y, 0),
gl::Offset(), gl::Extents(area.width, area.height, 1),
VK_IMAGE_ASPECT_COLOR_BIT, commandBuffer);
// Triggers a full finish.
// TODO(jmadill): Don't block on asynchronous readback.
......@@ -590,7 +558,7 @@ gl::Error FramebufferVk::getCommandGraphNodeForDraw(const gl::Context *context,
ASSERT(colorRenderTarget);
// TODO(jmadill): Use automatic layout transition. http://anglebug.com/2361
colorRenderTarget->image->getImage().changeLayoutWithStages(
colorRenderTarget->image->changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
commandBuffer);
......@@ -606,7 +574,7 @@ gl::Error FramebufferVk::getCommandGraphNodeForDraw(const gl::Context *context,
VkImageAspectFlags aspectFlags = (format.depthBits > 0 ? VK_IMAGE_ASPECT_DEPTH_BIT : 0) |
(format.stencilBits > 0 ? VK_IMAGE_ASPECT_STENCIL_BIT : 0);
depthStencilRenderTarget->image->getImage().changeLayoutWithStages(
depthStencilRenderTarget->image->changeLayoutWithStages(
aspectFlags, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
commandBuffer);
......
......@@ -870,7 +870,7 @@ vk::Error ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
const gl::State &glState = contextVk->getGLState();
const auto &completeTextures = glState.getCompleteTextureCache();
for (const auto &samplerBinding : mState.getSamplerBindings())
for (const gl::SamplerBinding &samplerBinding : mState.getSamplerBindings())
{
ASSERT(!samplerBinding.unreferenced);
......@@ -884,7 +884,7 @@ vk::Error ProgramVk::updateTexturesDescriptorSet(ContextVk *contextVk)
ASSERT(texture);
TextureVk *textureVk = vk::GetImpl(texture);
const vk::Image &image = textureVk->getImage();
const vk::ImageHelper &image = textureVk->getImage();
VkDescriptorImageInfo &imageInfo = descriptorImageInfo[imageCount];
......
......@@ -97,18 +97,13 @@ gl::Error RenderbufferVk::setStorage(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
mImage.getImage().changeLayoutWithStages(aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
if (isDepthOrStencilFormat)
{
commandBuffer->clearSingleDepthStencilImage(mImage.getImage(), aspect,
kDefaultClearDepthStencilValue);
mImage.clearDepthStencil(aspect, kDefaultClearDepthStencilValue, commandBuffer);
}
else
{
commandBuffer->clearSingleColorImage(mImage.getImage(), kBlackClearColorValue);
mImage.clearColor(kBlackClearColorValue, commandBuffer);
}
}
......
......@@ -203,7 +203,7 @@ void WindowSurfaceVk::destroy(const egl::Display *display)
for (SwapchainImage &swapchainImage : mSwapchainImages)
{
// Although we don't own the swapchain image handles, we need to keep our shutdown clean.
swapchainImage.image.getImage().reset();
swapchainImage.image.resetImageWeakReference();
swapchainImage.image.destroy(device);
swapchainImage.imageView.destroy(device);
swapchainImage.framebuffer.destroy(device);
......@@ -400,10 +400,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
&member.imageView);
// Set transfer dest layout, and clear the image to black.
member.image.getImage().changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleColorImage(member.image.getImage(), transparentBlack);
member.image.clearColor(transparentBlack, commandBuffer);
ANGLE_TRY(member.imageAcquiredSemaphore.init(device));
ANGLE_TRY(member.commandsCompleteSemaphore.init(device));
......@@ -432,11 +429,7 @@ vk::Error WindowSurfaceVk::initializeImpl(RendererVk *renderer)
VkClearDepthStencilValue depthStencilClearValue = {1.0f, 0};
// Set transfer dest layout, and clear the image.
mDepthStencilImage.getImage().changeLayoutWithStages(
aspect, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_ALL_GRAPHICS_BIT,
VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
commandBuffer->clearSingleDepthStencilImage(mDepthStencilImage.getImage(), aspect,
depthStencilClearValue);
mDepthStencilImage.clearDepthStencil(aspect, depthStencilClearValue, commandBuffer);
ANGLE_TRY(mDepthStencilImage.initImageView(device, aspect, gl::SwizzleState(),
&mDepthStencilImageView));
......@@ -466,9 +459,9 @@ egl::Error WindowSurfaceVk::swap(const gl::Context *context)
SwapchainImage &image = mSwapchainImages[mCurrentSwapchainImageIndex];
image.image.getImage().changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, swapCommands);
image.image.changeLayoutWithStages(VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT,
VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, swapCommands);
ANGLE_TRY(
renderer->flush(context, image.imageAcquiredSemaphore, image.commandsCompleteSemaphore));
......
......@@ -141,10 +141,7 @@ gl::Error TextureVk::setImage(const gl::Context *context,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
VkClearColorValue black = {{0}};
mImage.getImage().changeLayoutWithStages(
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(mImage.getImage(), black);
mImage.clearColor(black, commandBuffer);
}
if (!mSampler.valid())
......@@ -253,16 +250,8 @@ gl::Error TextureVk::setSubImageImpl(ContextVk *contextVk,
vk::CommandBuffer *commandBuffer = nullptr;
ANGLE_TRY(beginWriteResource(renderer, &commandBuffer));
stagingImage.getImage().changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
mImage.getImage().changeLayoutWithStages(
VK_IMAGE_ASPECT_COLOR_BIT, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, commandBuffer);
gl::Box wholeRegion(0, 0, 0, size.width, size.height, size.depth);
commandBuffer->copySingleImage(stagingImage.getImage(), mImage.getImage(), wholeRegion,
VK_IMAGE_ASPECT_COLOR_BIT);
vk::ImageHelper::Copy(&stagingImage, &mImage, gl::Offset(), gl::Offset(), size,
VK_IMAGE_ASPECT_COLOR_BIT, commandBuffer);
// Immediately release staging image.
// TODO(jmadill): Staging image re-use.
......@@ -403,10 +392,10 @@ gl::Error TextureVk::initializeContents(const gl::Context *context,
return gl::NoError();
}
const vk::Image &TextureVk::getImage() const
const vk::ImageHelper &TextureVk::getImage() const
{
ASSERT(mImage.valid());
return mImage.getImage();
return mImage;
}
const vk::ImageView &TextureVk::getImageView() const
......
......@@ -111,7 +111,7 @@ class TextureVk : public TextureImpl, public ResourceVk
gl::Error initializeContents(const gl::Context *context,
const gl::ImageIndex &imageIndex) override;
const vk::Image &getImage() const;
const vk::ImageHelper &getImage() const;
const vk::ImageView &getImageView() const;
const vk::Sampler &getSampler() const;
......
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