Commit 520fe0e3 authored by Sergey Ulanov's avatar Sergey Ulanov Committed by Commit Bot

Add VulkanImplementation::CreateExternalSemaphore()

The new CreateExternalSemaphore() allows to creates semaphore that
can be exported to a platform-specific handle.

Bug: 934526
Change-Id: I0c927e4f505b43f22a393800410b395fdb15265a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1541865
Commit-Queue: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646662}
parent 84710ada
...@@ -45,28 +45,6 @@ ExternalVkImageBacking::~ExternalVkImageBacking() { ...@@ -45,28 +45,6 @@ ExternalVkImageBacking::~ExternalVkImageBacking() {
// Destroy() will do any necessary cleanup. // Destroy() will do any necessary cleanup.
} }
VkSemaphore ExternalVkImageBacking::CreateExternalVkSemaphore() {
VkExportSemaphoreCreateInfo export_info;
export_info.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO;
export_info.pNext = nullptr;
export_info.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT;
VkSemaphoreCreateInfo sem_info;
sem_info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
sem_info.pNext = &export_info;
sem_info.flags = 0;
VkSemaphore semaphore = VK_NULL_HANDLE;
VkResult result = vkCreateSemaphore(device(), &sem_info, nullptr, &semaphore);
if (result != VK_SUCCESS) {
LOG(ERROR) << "Failed to create VkSemaphore: " << result;
return VK_NULL_HANDLE;
}
return semaphore;
}
bool ExternalVkImageBacking::BeginAccess( bool ExternalVkImageBacking::BeginAccess(
bool readonly, bool readonly,
std::vector<SemaphoreHandle>* semaphore_handles) { std::vector<SemaphoreHandle>* semaphore_handles) {
......
...@@ -44,8 +44,6 @@ class ExternalVkImageBacking : public SharedImageBacking { ...@@ -44,8 +44,6 @@ class ExternalVkImageBacking : public SharedImageBacking {
} }
using SharedImageBacking::have_context; using SharedImageBacking::have_context;
VkSemaphore CreateExternalVkSemaphore();
// Notifies the backing that an access will start. Return false if there is // Notifies the backing that an access will start. Return false if there is
// currently any other conflict access in progress. Otherwise, returns true // currently any other conflict access in progress. Otherwise, returns true
// and semaphore handles which will be waited on before accessing. // and semaphore handles which will be waited on before accessing.
......
...@@ -178,9 +178,11 @@ std::unique_ptr<SharedImageBacking> ExternalVkImageFactory::CreateSharedImage( ...@@ -178,9 +178,11 @@ std::unique_ptr<SharedImageBacking> ExternalVkImageFactory::CreateSharedImage(
SkPixmap pixmap(ii, pixel_data.data(), row_bytes); SkPixmap pixmap(ii, pixel_data.data(), row_bytes);
surface->writePixels(pixmap, 0, 0); surface->writePixels(pixmap, 0, 0);
VkSemaphore semaphore = vk_backing->CreateExternalVkSemaphore();
auto* vk_implementation = auto* vk_implementation =
context_state_->vk_context_provider()->GetVulkanImplementation(); context_state_->vk_context_provider()->GetVulkanImplementation();
VkSemaphore semaphore =
vk_implementation->CreateExternalSemaphore(vk_backing->device());
VkDevice device = context_state_->vk_context_provider() VkDevice device = context_state_->vk_context_provider()
->GetDeviceQueue() ->GetDeviceQueue()
->GetVulkanDevice(); ->GetVulkanDevice();
......
...@@ -81,7 +81,8 @@ void ExternalVkImageGlRepresentation::EndAccess() { ...@@ -81,7 +81,8 @@ void ExternalVkImageGlRepresentation::EndAccess() {
(current_access_mode_ == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM); (current_access_mode_ == GL_SHARED_IMAGE_ACCESS_MODE_READ_CHROMIUM);
current_access_mode_ = 0; current_access_mode_ = 0;
VkSemaphore semaphore = backing_impl()->CreateExternalVkSemaphore(); VkSemaphore semaphore =
vk_implementation()->CreateExternalSemaphore(backing_impl()->device());
if (semaphore == VK_NULL_HANDLE) { if (semaphore == VK_NULL_HANDLE) {
// TODO(crbug.com/933452): We should be able to handle this failure more // TODO(crbug.com/933452): We should be able to handle this failure more
// gracefully rather than shutting down the whole process. // gracefully rather than shutting down the whole process.
...@@ -125,6 +126,12 @@ GLuint ExternalVkImageGlRepresentation::ImportVkSemaphoreIntoGL( ...@@ -125,6 +126,12 @@ GLuint ExternalVkImageGlRepresentation::ImportVkSemaphoreIntoGL(
SemaphoreHandle handle) { SemaphoreHandle handle) {
if (!handle.is_valid()) if (!handle.is_valid())
return 0; return 0;
if (handle.vk_handle_type() !=
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT) {
DLOG(ERROR) << "Importing semaphore handle of unexpected type:"
<< handle.vk_handle_type();
return 0;
}
base::ScopedFD fd = handle.TakeHandle(); base::ScopedFD fd = handle.TakeHandle();
gl::GLApi* api = gl::g_current_gl_context; gl::GLApi* api = gl::g_current_gl_context;
GLuint gl_semaphore; GLuint gl_semaphore;
......
...@@ -133,7 +133,8 @@ void ExternalVkImageSkiaRepresentation::EndAccess(bool readonly) { ...@@ -133,7 +133,8 @@ void ExternalVkImageSkiaRepresentation::EndAccess(bool readonly) {
// Cleanup resources for previous accessing. // Cleanup resources for previous accessing.
DestroySemaphore(end_access_semaphore_, end_access_fence_); DestroySemaphore(end_access_semaphore_, end_access_fence_);
end_access_semaphore_ = backing_impl()->CreateExternalVkSemaphore(); end_access_semaphore_ =
vk_implementation()->CreateExternalSemaphore(backing_impl()->device());
// Submit wait semaphore to the queue. Note that Skia uses the same queue // Submit wait semaphore to the queue. Note that Skia uses the same queue
// exposed by vk_queue(), so this will work due to Vulkan queue ordering. // exposed by vk_queue(), so this will work due to Vulkan queue ordering.
if (!vk_implementation()->SubmitSignalSemaphore( if (!vk_implementation()->SubmitSignalSemaphore(
......
...@@ -107,6 +107,12 @@ VulkanImplementationAndroid::ExportVkFenceToGpuFence(VkDevice vk_device, ...@@ -107,6 +107,12 @@ VulkanImplementationAndroid::ExportVkFenceToGpuFence(VkDevice vk_device,
return nullptr; return nullptr;
} }
VkSemaphore VulkanImplementationAndroid::CreateExternalSemaphore(
VkDevice vk_device) {
return VulkanImplementation::CreateExternalSemaphore(
vk_device, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT);
}
VkSemaphore VulkanImplementationAndroid::ImportSemaphoreHandle( VkSemaphore VulkanImplementationAndroid::ImportSemaphoreHandle(
VkDevice vk_device, VkDevice vk_device,
SemaphoreHandle sync_handle) { SemaphoreHandle sync_handle) {
......
...@@ -35,6 +35,7 @@ class COMPONENT_EXPORT(VULKAN_ANDROID) VulkanImplementationAndroid ...@@ -35,6 +35,7 @@ class COMPONENT_EXPORT(VULKAN_ANDROID) VulkanImplementationAndroid
std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence( std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence(
VkDevice vk_device, VkDevice vk_device,
VkFence vk_fence) override; VkFence vk_fence) override;
VkSemaphore CreateExternalSemaphore(VkDevice vk_device) override;
VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
SemaphoreHandle handle) override; SemaphoreHandle handle) override;
SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device, SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device,
......
...@@ -15,25 +15,6 @@ VulkanImplementation::VulkanImplementation() {} ...@@ -15,25 +15,6 @@ VulkanImplementation::VulkanImplementation() {}
VulkanImplementation::~VulkanImplementation() {} VulkanImplementation::~VulkanImplementation() {}
std::unique_ptr<VulkanDeviceQueue> CreateVulkanDeviceQueue(
VulkanImplementation* vulkan_implementation,
uint32_t option) {
auto device_queue = std::make_unique<VulkanDeviceQueue>(
vulkan_implementation->GetVulkanInstance()->vk_instance());
auto callback = base::BindRepeating(
&VulkanImplementation::GetPhysicalDevicePresentationSupport,
base::Unretained(vulkan_implementation));
std::vector<const char*> required_extensions =
vulkan_implementation->GetRequiredDeviceExtensions();
if (!device_queue->Initialize(option, std::move(required_extensions),
callback)) {
device_queue->Destroy();
return nullptr;
}
return device_queue;
}
bool VulkanImplementation::SubmitSignalSemaphore(VkQueue vk_queue, bool VulkanImplementation::SubmitSignalSemaphore(VkQueue vk_queue,
VkSemaphore vk_semaphore, VkSemaphore vk_semaphore,
VkFence vk_fence) { VkFence vk_fence) {
...@@ -66,4 +47,45 @@ bool VulkanImplementation::SubmitWaitSemaphores( ...@@ -66,4 +47,45 @@ bool VulkanImplementation::SubmitWaitSemaphores(
return true; return true;
} }
VkSemaphore VulkanImplementation::CreateExternalSemaphore(
VkDevice vk_device,
VkExternalSemaphoreHandleTypeFlags handle_types) {
VkExportSemaphoreCreateInfo export_info = {
VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO};
export_info.handleTypes = handle_types;
VkSemaphoreCreateInfo sem_info = {VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO,
&export_info};
VkSemaphore semaphore = VK_NULL_HANDLE;
VkResult result =
vkCreateSemaphore(vk_device, &sem_info, nullptr, &semaphore);
if (result != VK_SUCCESS) {
DLOG(ERROR) << "Failed to create VkSemaphore: " << result;
return VK_NULL_HANDLE;
}
return semaphore;
}
std::unique_ptr<VulkanDeviceQueue> CreateVulkanDeviceQueue(
VulkanImplementation* vulkan_implementation,
uint32_t option) {
auto device_queue = std::make_unique<VulkanDeviceQueue>(
vulkan_implementation->GetVulkanInstance()->vk_instance());
auto callback = base::BindRepeating(
&VulkanImplementation::GetPhysicalDevicePresentationSupport,
base::Unretained(vulkan_implementation));
std::vector<const char*> required_extensions =
vulkan_implementation->GetRequiredDeviceExtensions();
if (!device_queue->Initialize(option, std::move(required_extensions),
callback)) {
device_queue->Destroy();
return nullptr;
}
return device_queue;
}
} // namespace gpu } // namespace gpu
...@@ -90,9 +90,18 @@ class VULKAN_EXPORT VulkanImplementation { ...@@ -90,9 +90,18 @@ class VULKAN_EXPORT VulkanImplementation {
return SubmitWaitSemaphores(vk_queue, {vk_semaphore}, vk_fence); return SubmitWaitSemaphores(vk_queue, {vk_semaphore}, vk_fence);
} }
// Creates semaphore that can be exported to external handles of the specified
// |handle_types|.
VkSemaphore CreateExternalSemaphore(
VkDevice vk_device,
VkExternalSemaphoreHandleTypeFlags handle_types);
// Creates a semaphore that can be exported using GetSemaphoreHandle().
virtual VkSemaphore CreateExternalSemaphore(VkDevice vk_device) = 0;
// Import a VkSemaphore from a platform-specific handle. // Import a VkSemaphore from a platform-specific handle.
// Handle types that don't allow permanent import are imported with temporary // Handle types that don't allow permanent import are imported with
// permanence (VK_SEMAPHORE_IMPORT_TEMPORARY_BIT). // temporary permanence (VK_SEMAPHORE_IMPORT_TEMPORARY_BIT).
virtual VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, virtual VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
SemaphoreHandle handle) = 0; SemaphoreHandle handle) = 0;
......
...@@ -105,6 +105,12 @@ VulkanImplementationWin32::ExportVkFenceToGpuFence(VkDevice vk_device, ...@@ -105,6 +105,12 @@ VulkanImplementationWin32::ExportVkFenceToGpuFence(VkDevice vk_device,
return nullptr; return nullptr;
} }
VkSemaphore VulkanImplementationWin32::CreateExternalSemaphore(
VkDevice vk_device) {
NOTIMPLEMENTED();
return VK_NULL_HANDLE;
}
VkSemaphore VulkanImplementationWin32::ImportSemaphoreHandle( VkSemaphore VulkanImplementationWin32::ImportSemaphoreHandle(
VkDevice vk_device, VkDevice vk_device,
SemaphoreHandle handle) { SemaphoreHandle handle) {
......
...@@ -33,6 +33,7 @@ class COMPONENT_EXPORT(VULKAN_WIN32) VulkanImplementationWin32 ...@@ -33,6 +33,7 @@ class COMPONENT_EXPORT(VULKAN_WIN32) VulkanImplementationWin32
std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence( std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence(
VkDevice vk_device, VkDevice vk_device,
VkFence vk_fence) override; VkFence vk_fence) override;
VkSemaphore CreateExternalSemaphore(VkDevice vk_device) override;
VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
SemaphoreHandle handle) override; SemaphoreHandle handle) override;
SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device, SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device,
......
...@@ -147,6 +147,12 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationX11::ExportVkFenceToGpuFence( ...@@ -147,6 +147,12 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationX11::ExportVkFenceToGpuFence(
return nullptr; return nullptr;
} }
VkSemaphore VulkanImplementationX11::CreateExternalSemaphore(
VkDevice vk_device) {
return VulkanImplementation::CreateExternalSemaphore(
vk_device, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT);
}
VkSemaphore VulkanImplementationX11::ImportSemaphoreHandle( VkSemaphore VulkanImplementationX11::ImportSemaphoreHandle(
VkDevice vk_device, VkDevice vk_device,
SemaphoreHandle sync_handle) { SemaphoreHandle sync_handle) {
......
...@@ -35,6 +35,7 @@ class COMPONENT_EXPORT(VULKAN_X11) VulkanImplementationX11 ...@@ -35,6 +35,7 @@ class COMPONENT_EXPORT(VULKAN_X11) VulkanImplementationX11
std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence( std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence(
VkDevice vk_device, VkDevice vk_device,
VkFence vk_fence) override; VkFence vk_fence) override;
VkSemaphore CreateExternalSemaphore(VkDevice vk_device) override;
VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
SemaphoreHandle handle) override; SemaphoreHandle handle) override;
SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device, SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device,
......
...@@ -129,6 +129,12 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationGbm::ExportVkFenceToGpuFence( ...@@ -129,6 +129,12 @@ std::unique_ptr<gfx::GpuFence> VulkanImplementationGbm::ExportVkFenceToGpuFence(
return std::make_unique<gfx::GpuFence>(gpu_fence_handle); return std::make_unique<gfx::GpuFence>(gpu_fence_handle);
} }
VkSemaphore VulkanImplementationGbm::CreateExternalSemaphore(
VkDevice vk_device) {
return VulkanImplementation::CreateExternalSemaphore(
vk_device, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_SYNC_FD_BIT);
}
VkSemaphore VulkanImplementationGbm::ImportSemaphoreHandle( VkSemaphore VulkanImplementationGbm::ImportSemaphoreHandle(
VkDevice vk_device, VkDevice vk_device,
gpu::SemaphoreHandle sync_handle) { gpu::SemaphoreHandle sync_handle) {
......
...@@ -31,6 +31,7 @@ class VulkanImplementationGbm : public gpu::VulkanImplementation { ...@@ -31,6 +31,7 @@ class VulkanImplementationGbm : public gpu::VulkanImplementation {
std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence( std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence(
VkDevice vk_device, VkDevice vk_device,
VkFence vk_fence) override; VkFence vk_fence) override;
VkSemaphore CreateExternalSemaphore(VkDevice vk_device) override;
VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
gpu::SemaphoreHandle handle) override; gpu::SemaphoreHandle handle) override;
gpu::SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device, gpu::SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device,
......
...@@ -126,6 +126,13 @@ VulkanImplementationScenic::ExportVkFenceToGpuFence(VkDevice vk_device, ...@@ -126,6 +126,13 @@ VulkanImplementationScenic::ExportVkFenceToGpuFence(VkDevice vk_device,
return nullptr; return nullptr;
} }
VkSemaphore VulkanImplementationScenic::CreateExternalSemaphore(
VkDevice vk_device) {
return VulkanImplementation::CreateExternalSemaphore(
vk_device,
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TEMP_ZIRCON_EVENT_BIT_FUCHSIA);
}
VkSemaphore VulkanImplementationScenic::ImportSemaphoreHandle( VkSemaphore VulkanImplementationScenic::ImportSemaphoreHandle(
VkDevice vk_device, VkDevice vk_device,
gpu::SemaphoreHandle handle) { gpu::SemaphoreHandle handle) {
......
...@@ -35,6 +35,7 @@ class VulkanImplementationScenic : public gpu::VulkanImplementation { ...@@ -35,6 +35,7 @@ class VulkanImplementationScenic : public gpu::VulkanImplementation {
std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence( std::unique_ptr<gfx::GpuFence> ExportVkFenceToGpuFence(
VkDevice vk_device, VkDevice vk_device,
VkFence vk_fence) override; VkFence vk_fence) override;
VkSemaphore CreateExternalSemaphore(VkDevice vk_device) override;
VkSemaphore ImportSemaphoreHandle(VkDevice vk_device, VkSemaphore ImportSemaphoreHandle(VkDevice vk_device,
gpu::SemaphoreHandle handle) override; gpu::SemaphoreHandle handle) override;
gpu::SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device, gpu::SemaphoreHandle GetSemaphoreHandle(VkDevice vk_device,
......
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