-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Intercept device functions via vkGetInstanceProcAddr() (#22)
Vulkan allows device functions to be (less efficiently) intercepted via vkGetInstanceProcAddr() instead of vkGetDeviceProcAddr(). This PR adds support for intercepting these correctly. This includes a custom vkGetDeviceImageMemoryRequirementsKHR() to skip driver invocations if the driver dispatch pointer is nullptr. This is a workaround for a bug in Unreal Engine which fetches this function using vkGetInstanceProcAddr() with a Vulkan 1.1 instance (when it is available and is therefore non-null) and then tries to use it later with a device created from a Vulkan 1.0 instance (when it is not available because VK_KHR_maintenance4 is a Vulkan 1.1 extension).
- Loading branch information
1 parent
683c74d
commit 783e42e
Showing
7 changed files
with
524 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
generator/vk_codegen/function_vkGetDeviceImageMemoryRequirementsKHR.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Hold the lock to access layer-wide global store | ||
std::unique_lock<std::mutex> lock { g_vulkanLock }; | ||
auto* layer = Device::retrieve(device); | ||
|
||
// Workaround Unreal Engine trying to invoke this via a function pointer | ||
// queried from a Vulkan 1.1 instance with vkInstanceGetProcAddress() with | ||
// device created from a later a Vulkan 1.0 context where the function is | ||
// not available ... | ||
if (!layer->driver.vkGetDeviceImageMemoryRequirementsKHR) | ||
{ | ||
pMemoryRequirements->memoryRequirements.size = 0; | ||
pMemoryRequirements->memoryRequirements.alignment = 0; | ||
pMemoryRequirements->memoryRequirements.memoryTypeBits = 0; | ||
return; | ||
} | ||
|
||
// Release the lock to call into the driver | ||
lock.unlock(); | ||
layer->driver.vkGetDeviceImageMemoryRequirementsKHR(device, pInfo, pMemoryRequirements); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.