Skip to content

Commit

Permalink
Fix ExportFence Validation Layer
Browse files Browse the repository at this point in the history
Summary:
On the Quest we currently enable fences across the board, and validation layer points out this error:

```
Objects: 1
        [0] 0x9f58380000000064, type: 7, name: NULL
VUID-VkFenceGetFdInfoKHR-handleType-01453(ERROR / SPEC): msgNum: -1005942627 - Validation Error: [ VUID-VkFenceGetFdInfoKHR-handleType-01453 ] Object 0: handle = 0x5684940000000068, type = VK_OBJECT_TYPE_FENCE; | MessageID = 0xc40a889d | vkGetFenceFdKHR: handleType
VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT was not VkExportFenceCreateInfo::handleTypes (Unhandled VkExternalFenceHandleTypeFlagBits)
The Vulkan spec states: handleType must have been included in VkExportFenceCreateInfo::handleTypes when fence's current payload was created (https://www.khronos.org/registry/vulkan/specs/1.3-extensions/html/vkspec.html#VUID-VkFenceGetFdInfoKHR-handleType-01453)
```

We need to create an explicit `VkExportFenceCreateInfo` struct

* Adds a new option `exportableFences` in `VulkanContextConfig`. Disabled by default, if enabled will be piped in through `VulkanImmediateCommands`

Reviewed By: corporateshark

Differential Revision: D49852875

fbshipit-source-id: 0e4194288fb2c0d1d610db530e734b52fee66122
  • Loading branch information
Shayan Javed authored and facebook-github-bot committed Oct 7, 2023
1 parent e3437b8 commit 613b8e4
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/igl/vulkan/VulkanContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,12 @@ igl::Result VulkanContext::initContext(const HWDeviceDesc& desc,

device_ =
std::make_unique<igl::vulkan::VulkanDevice>(vf_, device, "Device: VulkanContext::device_");
immediate_ = std::make_unique<igl::vulkan::VulkanImmediateCommands>(
vf_, device, deviceQueues_.graphicsQueueFamilyIndex, "VulkanContext::immediate_");
immediate_ =
std::make_unique<igl::vulkan::VulkanImmediateCommands>(vf_,
device,
deviceQueues_.graphicsQueueFamilyIndex,
config_.exportableFences,
"VulkanContext::immediate_");
syncManager_ = std::make_unique<SyncManager>(*this, config_.maxResourceCount);

// create Vulkan pipeline cache
Expand Down
4 changes: 4 additions & 0 deletions src/igl/vulkan/VulkanContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ struct VulkanContextConfig {
// owned by the application - should be alive until initContext() returns
const void* pipelineCacheData = nullptr;
size_t pipelineCacheDataSize = 0;

// This enables fences generated at the end of submission to be exported to the client.
// The client can then use the SubmitHandle to wait for the completion of the GPU work.
bool exportableFences = false;
};

class VulkanContext final {
Expand Down
7 changes: 5 additions & 2 deletions src/igl/vulkan/VulkanFence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ namespace vulkan {
VulkanFence::VulkanFence(const VulkanFunctionTable& vf,
VkDevice device,
VkFlags flags,
bool exportable,
const char* debugName) :
vf_(&vf), device_(device) {
vf_(&vf), device_(device), exportable_(exportable) {
IGL_PROFILER_FUNCTION_COLOR(IGL_PROFILER_COLOR_CREATE);

VK_ASSERT(ivkCreateFence(vf_, device_, flags, &vkFence_));
VK_ASSERT(ivkCreateFence(vf_, device_, flags, exportable, &vkFence_));
VK_ASSERT(
ivkSetDebugObjectName(vf_, device_, VK_OBJECT_TYPE_FENCE, (uint64_t)vkFence_, debugName));
}
Expand All @@ -39,13 +40,15 @@ VulkanFence::VulkanFence(VulkanFence&& other) noexcept {
std::swap(vf_, other.vf_);
std::swap(device_, other.device_);
std::swap(vkFence_, other.vkFence_);
std::swap(exportable_, other.exportable_);
}

VulkanFence& VulkanFence::operator=(VulkanFence&& other) noexcept {
VulkanFence tmp(std::move(other));
std::swap(vf_, tmp.vf_);
std::swap(device_, tmp.device_);
std::swap(vkFence_, tmp.vkFence_);
std::swap(exportable_, tmp.exportable_);
return *this;
}

Expand Down
2 changes: 2 additions & 0 deletions src/igl/vulkan/VulkanFence.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class VulkanFence final {
VulkanFence(const VulkanFunctionTable& vf,
VkDevice device,
VkFlags flags,
bool exportable = false,
const char* debugName = nullptr);
~VulkanFence();

Expand All @@ -39,6 +40,7 @@ class VulkanFence final {
const VulkanFunctionTable* vf_{};
VkDevice device_ = VK_NULL_HANDLE;
VkFence vkFence_ = VK_NULL_HANDLE;
bool exportable_ = false;
};

} // namespace vulkan
Expand Down
8 changes: 7 additions & 1 deletion src/igl/vulkan/VulkanHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,16 @@ VkResult ivkCreateSemaphore(const struct VulkanFunctionTable* vt,
VkResult ivkCreateFence(const struct VulkanFunctionTable* vt,
VkDevice device,
VkFlags flags,
const bool exportable,
VkFence* outFence) {
const VkExportFenceCreateInfo exportInfo = {
.sType = VK_STRUCTURE_TYPE_EXPORT_FENCE_CREATE_INFO,
.handleTypes = VK_EXTERNAL_FENCE_HANDLE_TYPE_SYNC_FD_BIT,
};

const VkFenceCreateInfo ci = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
.pNext = exportable ? &exportInfo : NULL,
.flags = flags,
};
return vt->vkCreateFence(device, &ci, NULL, outFence);
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/VulkanHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ VkResult ivkCreateSemaphore(const struct VulkanFunctionTable* vt,
VkResult ivkCreateFence(const struct VulkanFunctionTable* vt,
VkDevice device,
VkFlags flags,
bool exportable,
VkFence* outFence);

VkResult ivkCreateSurface(const struct VulkanFunctionTable* vt,
Expand Down
2 changes: 2 additions & 0 deletions src/igl/vulkan/VulkanImmediateCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace vulkan {
VulkanImmediateCommands::VulkanImmediateCommands(const VulkanFunctionTable& vf,
VkDevice device,
uint32_t queueFamilyIndex,
bool exportableFences,
const char* debugName) :
vf_(vf),
device_(device),
Expand All @@ -37,6 +38,7 @@ VulkanImmediateCommands::VulkanImmediateCommands(const VulkanFunctionTable& vf,
VulkanFence(vf_,
device_,
VkFenceCreateFlagBits{},
exportableFences,
IGL_FORMAT("Fence: commandBuffer #{}", i).c_str()),
VulkanSemaphore(vf_, device, IGL_FORMAT("Semaphore: {} ({})", debugName, i).c_str()));
VK_ASSERT(ivkAllocateCommandBuffer(
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/VulkanImmediateCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class VulkanImmediateCommands final {
VulkanImmediateCommands(const VulkanFunctionTable& vf,
VkDevice device,
uint32_t queueFamilyIndex,
bool exportableFences,
const char* debugName);
~VulkanImmediateCommands();
VulkanImmediateCommands(const VulkanImmediateCommands&) = delete;
Expand Down
1 change: 1 addition & 0 deletions src/igl/vulkan/VulkanStagingDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ VulkanStagingDevice::VulkanStagingDevice(VulkanContext& ctx) : ctx_(ctx) {
ctx_.vf_,
ctx_.device_->getVkDevice(),
ctx_.deviceQueues_.graphicsQueueFamilyIndex,
ctx_.config_.exportableFences,
"VulkanStagingDevice::immediate_");
IGL_ASSERT(immediate_.get());
}
Expand Down

0 comments on commit 613b8e4

Please sign in to comment.