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