Commit 98bbe148 authored by Austin Eng's avatar Austin Eng Committed by Commit Bot

Update to use Dawn's dawn_native::vulkan::ExportVulkanImage API

The new API allows passing/getting the old/new image layouts to
do proper image layout transitions. ExportSignalSemaphoreOpaqueFD
is deprecated.

Bug: dawn:200, 976495
Change-Id: Icbdd354bf5d8231c16b1bbc64317bcd158e0c135
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2451710Reviewed-by: default avatarCorentin Wallez <cwallez@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814221}
parent f85138bc
......@@ -57,7 +57,7 @@ WGPUTexture ExternalVkImageDawnRepresentation::BeginAccess(
dawn_native::vulkan::ExternalImageDescriptorOpaqueFD descriptor = {};
descriptor.cTextureDescriptor = &texture_descriptor;
descriptor.isCleared = IsCleared();
descriptor.isInitialized = IsCleared();
descriptor.allocationSize = backing_impl()->image()->device_size();
descriptor.memoryTypeIndex = backing_impl()->image()->memory_type_index();
descriptor.memoryFD = dup(memory_fd_.get());
......@@ -80,22 +80,28 @@ void ExternalVkImageDawnRepresentation::EndAccess() {
}
// Grab the signal semaphore from dawn
int signal_semaphore_fd =
dawn_native::vulkan::ExportSignalSemaphoreOpaqueFD(device_, texture_);
if (dawn_native::IsTextureSubresourceInitialized(texture_, 0, 1, 0, 1)) {
SetCleared();
dawn_native::vulkan::ExternalImageExportInfoOpaqueFD export_info;
if (!dawn_native::vulkan::ExportVulkanImage(
texture_, VK_IMAGE_LAYOUT_UNDEFINED, &export_info)) {
DLOG(ERROR) << "Failed to export Dawn Vulkan image.";
} else {
if (export_info.isInitialized) {
SetCleared();
}
// TODO(enga): Handle waiting on multiple semaphores from dawn
DCHECK(export_info.semaphoreHandles.size() == 1);
// Wrap file descriptor in a handle
SemaphoreHandle handle(VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
base::ScopedFD(export_info.semaphoreHandles[0]));
auto semaphore = ExternalSemaphore::CreateFromHandle(
backing_impl()->context_provider(), std::move(handle));
backing_impl()->EndAccess(false, std::move(semaphore), false /* is_gl */);
}
// Wrap file descriptor in a handle
SemaphoreHandle handle(VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR,
base::ScopedFD(signal_semaphore_fd));
auto semaphore = ExternalSemaphore::CreateFromHandle(
backing_impl()->context_provider(), std::move(handle));
backing_impl()->EndAccess(false, std::move(semaphore), false /* is_gl */);
// Destroy the texture, signaling the semaphore in dawn
dawn_procs_.textureDestroy(texture_);
dawn_procs_.textureRelease(texture_);
......
......@@ -122,7 +122,7 @@ class SharedImageRepresentationDawnIOSurface
dawn_native::metal::ExternalImageDescriptorIOSurface descriptor;
descriptor.cTextureDescriptor = &texture_descriptor;
descriptor.isCleared = IsCleared();
descriptor.isInitialized = IsCleared();
descriptor.ioSurface = io_surface_.get();
descriptor.plane = 0;
......
......@@ -90,7 +90,7 @@ WGPUTexture SharedImageRepresentationDawnD3D::BeginAccess(
dawn_native::d3d12::ExternalImageDescriptorDXGISharedHandle descriptor;
descriptor.cTextureDescriptor = &texture_descriptor;
descriptor.isCleared = IsCleared();
descriptor.isInitialized = IsCleared();
descriptor.sharedHandle = shared_handle;
descriptor.acquireMutexKey = shared_mutex_acquire_key;
descriptor.isSwapChainTexture =
......
......@@ -7,6 +7,7 @@
#include <dawn_native/VulkanBackend.h>
#include <vulkan/vulkan.h>
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "gpu/command_buffer/service/memory_tracking.h"
......@@ -69,7 +70,7 @@ WGPUTexture SharedImageRepresentationDawnOzone::BeginAccess(
dawn_native::vulkan::ExternalImageDescriptorDmaBuf descriptor = {};
descriptor.cTextureDescriptor = &texture_descriptor;
descriptor.isCleared = IsCleared();
descriptor.isInitialized = IsCleared();
// Import the dma-buf into Dawn via the Vulkan backend. As per the Vulkan
// documentation, importing memory from a file descriptor transfers
// ownership of the fd from the application to the Vulkan implementation.
......@@ -94,12 +95,19 @@ void SharedImageRepresentationDawnOzone::EndAccess() {
return;
}
if (dawn_native::IsTextureSubresourceInitialized(texture_, 0, 1, 0, 1)) {
SetCleared();
}
// Grab the signal semaphore from dawn
dawn_native::vulkan::ExternalImageExportInfoOpaqueFD export_info;
if (!dawn_native::vulkan::ExportVulkanImage(
texture_, VK_IMAGE_LAYOUT_UNDEFINED, &export_info)) {
DLOG(ERROR) << "Failed to export Dawn Vulkan image.";
} else {
if (export_info.isInitialized) {
SetCleared();
}
// TODO(hob): Synchronize access to the dma-buf by exporting the VkSemaphore
// from the WebGPU texture.
// TODO(hob): Synchronize access to the dma-buf by waiting on
// |export_info.semaphoreHandles|
}
dawn_procs_->data.textureDestroy(texture_);
dawn_procs_->data.textureRelease(texture_);
texture_ = nullptr;
......
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