TextureVk: Replace swapchain specific layout getter with general one
The swapchain needs to get the current layout of the only subresource of
some textures when it needs to do a blit. This helper isn't just useful
for swapchains so make it more general to get the layout of any specific
subresource.
Change-Id: I7ddd019e1cc7c44f9394d9c75336206aebdbce94
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/207674
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Loko Kung <lokokung@google.com>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/dawn/native/vulkan/SwapChainVk.cpp b/src/dawn/native/vulkan/SwapChainVk.cpp
index 19a7ddc..5e52789 100644
--- a/src/dawn/native/vulkan/SwapChainVk.cpp
+++ b/src/dawn/native/vulkan/SwapChainVk.cpp
@@ -411,9 +411,9 @@
static_cast<int32_t>(mTexture->GetHeight(Aspect::Color)), 1};
device->fn.CmdBlitImage(recordingContext->commandBuffer, mBlitTexture->GetHandle(),
- mBlitTexture->GetCurrentLayoutForSwapChain(), mTexture->GetHandle(),
- mTexture->GetCurrentLayoutForSwapChain(), 1, ®ion,
- VK_FILTER_LINEAR);
+ mBlitTexture->GetCurrentLayout(Aspect::Color),
+ mTexture->GetHandle(), mTexture->GetCurrentLayout(Aspect::Color), 1,
+ ®ion, VK_FILTER_LINEAR);
// TODO(crbug.com/dawn/269): Find a way to reuse the blit texture between frames
// instead of creating a new one every time. This will involve "un-destroying" the
diff --git a/src/dawn/native/vulkan/TextureVk.cpp b/src/dawn/native/vulkan/TextureVk.cpp
index 81f5a9d..99d0223 100644
--- a/src/dawn/native/vulkan/TextureVk.cpp
+++ b/src/dawn/native/vulkan/TextureVk.cpp
@@ -1241,9 +1241,12 @@
return {};
}
-VkImageLayout Texture::GetCurrentLayoutForSwapChain() const {
+VkImageLayout Texture::GetCurrentLayout(Aspect aspect,
+ uint32_t arrayLayer,
+ uint32_t mipLevel) const {
DAWN_ASSERT(GetFormat().aspects == Aspect::Color);
- return VulkanImageLayout(GetFormat(), mSubresourceLastSyncInfos.Get(Aspect::Color, 0, 0).usage);
+ return VulkanImageLayout(GetFormat(),
+ mSubresourceLastSyncInfos.Get(aspect, arrayLayer, mipLevel).usage);
}
bool Texture::UseCombinedAspects() const {
@@ -1607,18 +1610,16 @@
MaybeError ImportedTextureBase::EndAccess(ExternalSemaphoreHandle* handle,
VkImageLayout* releasedOldLayout,
VkImageLayout* releasedNewLayout) {
+ DAWN_ASSERT(GetNumMipLevels() == 1 && GetArrayLayers() == 1);
+
// Release the texture
mExternalState = ExternalState::Released;
- DAWN_ASSERT(GetNumMipLevels() == 1 && GetArrayLayers() == 1);
- wgpu::TextureUsage usage =
- mSubresourceLastSyncInfos.Get(GetDisjointVulkanAspects(), 0, 0).usage;
-
// Compute the layouts for the queue transition for export. desiredLayout == UNDEFINED is a tag
// value used to export with whatever the current layout is. However queue transitioning to the
// UNDEFINED layout is disallowed so we handle the case where currentLayout is UNDEFINED by
// promoting to GENERAL.
- VkImageLayout currentLayout = VulkanImageLayout(GetFormat(), usage);
+ VkImageLayout currentLayout = GetCurrentLayout(GetDisjointVulkanAspects());
VkImageLayout targetLayout;
if (currentLayout != VK_IMAGE_LAYOUT_UNDEFINED) {
targetLayout = currentLayout;
diff --git a/src/dawn/native/vulkan/TextureVk.h b/src/dawn/native/vulkan/TextureVk.h
index 93edce0..fd39adb 100644
--- a/src/dawn/native/vulkan/TextureVk.h
+++ b/src/dawn/native/vulkan/TextureVk.h
@@ -75,7 +75,9 @@
// Returns the aspects used for tracking of Vulkan state. These can be the combined aspects.
Aspect GetDisjointVulkanAspects() const;
- VkImageLayout GetCurrentLayoutForSwapChain() const;
+ VkImageLayout GetCurrentLayout(Aspect aspect,
+ uint32_t arrayLayer = 0,
+ uint32_t mipLevel = 0) const;
// Transitions the texture to be used as `usage`, recording any necessary barrier in
// `commands`.