mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-09-22 11:09:38 +00:00
Improves validation messages in various Vulkan backend files: - vulkan/DeviceVk.cpp - vulkan/ShaderModuleVk.cpp - vulkan/SwapChainVk.cpp - vulkan/TextureVk.cpp - vulkan/external_memory/MemoryServiceDmaBuf.cpp - vulkan/external_memory/MemoryServiceOpaqueFD.cpp - vulkan/external_memory/MemoryServiceZirconHandle.cpp - vulkan/external_semaphore/SemaphoreServiceFD.cpp - vulkan/external_semaphore/SemaphoreServiceZirconHandle.cpp Bug: dawn:563 Change-Id: I521fecc29e7919413aa6210eff050848689296a1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/67122 Commit-Queue: Brandon Jones <bajones@chromium.org> Auto-Submit: Brandon Jones <bajones@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org>
137 lines
5.8 KiB
C++
137 lines
5.8 KiB
C++
// Copyright 2019 The Dawn Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "dawn_native/vulkan/AdapterVk.h"
|
|
#include "dawn_native/vulkan/BackendVk.h"
|
|
#include "dawn_native/vulkan/DeviceVk.h"
|
|
#include "dawn_native/vulkan/VulkanError.h"
|
|
#include "dawn_native/vulkan/external_semaphore/SemaphoreService.h"
|
|
|
|
namespace dawn_native { namespace vulkan { namespace external_semaphore {
|
|
|
|
Service::Service(Device* device)
|
|
: mDevice(device),
|
|
mSupported(CheckSupport(device->GetDeviceInfo(),
|
|
ToBackend(device->GetAdapter())->GetPhysicalDevice(),
|
|
device->fn)) {
|
|
}
|
|
|
|
Service::~Service() = default;
|
|
|
|
// static
|
|
bool Service::CheckSupport(const VulkanDeviceInfo& deviceInfo,
|
|
VkPhysicalDevice physicalDevice,
|
|
const VulkanFunctions& fn) {
|
|
if (!deviceInfo.HasExt(DeviceExt::ExternalSemaphoreZirconHandle)) {
|
|
return false;
|
|
}
|
|
|
|
VkPhysicalDeviceExternalSemaphoreInfoKHR semaphoreInfo;
|
|
semaphoreInfo.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO_KHR;
|
|
semaphoreInfo.pNext = nullptr;
|
|
semaphoreInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TEMP_ZIRCON_EVENT_BIT_FUCHSIA;
|
|
|
|
VkExternalSemaphorePropertiesKHR semaphoreProperties;
|
|
semaphoreProperties.sType = VK_STRUCTURE_TYPE_EXTERNAL_SEMAPHORE_PROPERTIES_KHR;
|
|
semaphoreProperties.pNext = nullptr;
|
|
|
|
fn.GetPhysicalDeviceExternalSemaphoreProperties(physicalDevice, &semaphoreInfo,
|
|
&semaphoreProperties);
|
|
|
|
VkFlags requiredFlags = VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR |
|
|
VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR;
|
|
|
|
return IsSubset(requiredFlags, semaphoreProperties.externalSemaphoreFeatures);
|
|
}
|
|
|
|
bool Service::Supported() {
|
|
return mSupported;
|
|
}
|
|
|
|
ResultOrError<VkSemaphore> Service::ImportSemaphore(ExternalSemaphoreHandle handle) {
|
|
DAWN_INVALID_IF(handle == ZX_HANDLE_INVALID,
|
|
"Importing a semaphore with an invalid handle.");
|
|
|
|
VkSemaphore semaphore = VK_NULL_HANDLE;
|
|
VkSemaphoreCreateInfo info;
|
|
info.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
info.pNext = nullptr;
|
|
info.flags = 0;
|
|
|
|
DAWN_TRY(CheckVkSuccess(
|
|
mDevice->fn.CreateSemaphore(mDevice->GetVkDevice(), &info, nullptr, &*semaphore),
|
|
"vkCreateSemaphore"));
|
|
|
|
VkImportSemaphoreZirconHandleInfoFUCHSIA importSempahoreHandleInfo;
|
|
importSempahoreHandleInfo.sType =
|
|
VK_STRUCTURE_TYPE_TEMP_IMPORT_SEMAPHORE_ZIRCON_HANDLE_INFO_FUCHSIA;
|
|
importSempahoreHandleInfo.pNext = nullptr;
|
|
importSempahoreHandleInfo.semaphore = semaphore;
|
|
importSempahoreHandleInfo.flags = 0;
|
|
importSempahoreHandleInfo.handleType =
|
|
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TEMP_ZIRCON_EVENT_BIT_FUCHSIA;
|
|
importSempahoreHandleInfo.handle = handle;
|
|
|
|
MaybeError status = CheckVkSuccess(mDevice->fn.ImportSemaphoreZirconHandleFUCHSIA(
|
|
mDevice->GetVkDevice(), &importSempahoreHandleInfo),
|
|
"vkImportSemaphoreZirconHandleFUCHSIA");
|
|
|
|
if (status.IsError()) {
|
|
mDevice->fn.DestroySemaphore(mDevice->GetVkDevice(), semaphore, nullptr);
|
|
DAWN_TRY(std::move(status));
|
|
}
|
|
|
|
return semaphore;
|
|
}
|
|
|
|
ResultOrError<VkSemaphore> Service::CreateExportableSemaphore() {
|
|
VkExportSemaphoreCreateInfoKHR exportSemaphoreInfo;
|
|
exportSemaphoreInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR;
|
|
exportSemaphoreInfo.pNext = nullptr;
|
|
exportSemaphoreInfo.handleTypes =
|
|
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TEMP_ZIRCON_EVENT_BIT_FUCHSIA;
|
|
|
|
VkSemaphoreCreateInfo semaphoreCreateInfo;
|
|
semaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
|
|
semaphoreCreateInfo.pNext = &exportSemaphoreInfo;
|
|
semaphoreCreateInfo.flags = 0;
|
|
|
|
VkSemaphore signalSemaphore;
|
|
DAWN_TRY(
|
|
CheckVkSuccess(mDevice->fn.CreateSemaphore(mDevice->GetVkDevice(), &semaphoreCreateInfo,
|
|
nullptr, &*signalSemaphore),
|
|
"vkCreateSemaphore"));
|
|
return signalSemaphore;
|
|
}
|
|
|
|
ResultOrError<ExternalSemaphoreHandle> Service::ExportSemaphore(VkSemaphore semaphore) {
|
|
VkSemaphoreGetZirconHandleInfoFUCHSIA semaphoreGetHandleInfo;
|
|
semaphoreGetHandleInfo.sType =
|
|
VK_STRUCTURE_TYPE_TEMP_SEMAPHORE_GET_ZIRCON_HANDLE_INFO_FUCHSIA;
|
|
semaphoreGetHandleInfo.pNext = nullptr;
|
|
semaphoreGetHandleInfo.semaphore = semaphore;
|
|
semaphoreGetHandleInfo.handleType =
|
|
VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_TEMP_ZIRCON_EVENT_BIT_FUCHSIA;
|
|
|
|
zx_handle_t handle = ZX_HANDLE_INVALID;
|
|
DAWN_TRY(CheckVkSuccess(mDevice->fn.GetSemaphoreZirconHandleFUCHSIA(
|
|
mDevice->GetVkDevice(), &semaphoreGetHandleInfo, &handle),
|
|
"VkSemaphoreGetZirconHandleInfoFUCHSIA"));
|
|
|
|
ASSERT(handle != ZX_HANDLE_INVALID);
|
|
return handle;
|
|
}
|
|
|
|
}}} // namespace dawn_native::vulkan::external_semaphore
|