@@ -15,8 +15,8 @@ VkImage s_curr3DDepthImage = VK_NULL_HANDLE;
1515
1616using namespace VRLayer ;
1717
18- VkResult VkDeviceOverrides::CreateImage (const vkroots::VkDeviceDispatch* pDispatch, VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage) {
19- VkResult res = pDispatch-> CreateImage (device, pCreateInfo, pAllocator, pImage);
18+ VkResult VkDeviceOverrides::CreateImage (const vkroots::VkDeviceDispatch& pDispatch, VkDevice device, const VkImageCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkImage* pImage) {
19+ VkResult res = pDispatch. CreateImage (device, pCreateInfo, pAllocator, pImage);
2020
2121 if (pCreateInfo->extent .width >= 1280 && pCreateInfo->extent .height >= 720 ) {
2222 lockImageResolutions.lock ();
@@ -26,7 +26,7 @@ VkResult VkDeviceOverrides::CreateImage(const vkroots::VkDeviceDispatch* pDispat
2626 return res;
2727}
2828
29- void VkDeviceOverrides::DestroyImage (const vkroots::VkDeviceDispatch* pDispatch, VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator) {
29+ void VkDeviceOverrides::DestroyImage (const vkroots::VkDeviceDispatch& pDispatch, VkDevice device, VkImage image, const VkAllocationCallbacks* pAllocator) {
3030 lockImageResolutions.lock ();
3131 imageResolutions.erase (image);
3232 if (s_curr3DColorImage == image) {
@@ -37,10 +37,10 @@ void VkDeviceOverrides::DestroyImage(const vkroots::VkDeviceDispatch* pDispatch,
3737 }
3838 lockImageResolutions.unlock ();
3939
40- pDispatch-> DestroyImage (device, image, pAllocator);
40+ pDispatch. DestroyImage (device, image, pAllocator);
4141}
4242
43- void VkDeviceOverrides::CmdClearColorImage (const vkroots::VkDeviceDispatch* pDispatch, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges) {
43+ void VkDeviceOverrides::CmdClearColorImage (const vkroots::VkCommandBufferDispatch& pDispatch, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearColorValue* pColor, uint32_t rangeCount, const VkImageSubresourceRange* pRanges) {
4444 // check whether the magic values are there, and which order they are in to determine which eye
4545 OpenXR::EyeSide side = (OpenXR::EyeSide)-1 ;
4646 if (pColor->float32 [1 ] >= 0.12 && pColor->float32 [1 ] <= 0.13 && pColor->float32 [2 ] >= 0.97 && pColor->float32 [2 ] <= 0.99 ) {
@@ -51,7 +51,8 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
5151 }
5252
5353 if (!VRManager::instance ().VK ) {
54- VRManager::instance ().Init (pDispatch->pPhysicalDeviceDispatch ->Instance , pDispatch->PhysicalDevice , pDispatch->Device );
54+ auto * dispatch = pDispatch.pDeviceDispatch ;
55+ VRManager::instance ().Init (dispatch->pPhysicalDeviceDispatch ->pInstanceDispatch ->Instance , dispatch->PhysicalDevice , dispatch->Device );
5556 VRManager::instance ().InitSession ();
5657 }
5758
@@ -66,7 +67,7 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
6667 auto * renderer = VRManager::instance ().XR ->GetRenderer ();
6768 if (!renderer) {
6869 Log::print<RENDERING>(" Renderer is not initialized yet!" );
69- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
70+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
7071 }
7172 auto & layer3D = renderer->m_layer3D ;
7273 auto & layer2D = renderer->m_layer2D ;
@@ -143,7 +144,7 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
143144 clearColor = {{ 0 .0f , 0 .0f , 0 .0f , 1 .0f }};
144145 }
145146 returnToLayout ();
146- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
147+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
147148 }
148149
149150 if (renderer->GetFrame (frameIdx).copiedColor [side]) {
@@ -152,7 +153,7 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
152153
153154 VkClearColorValue clearColor = {{ 0 .0f , 0 .0f , 0 .0f , 0 .0f }};
154155 returnToLayout ();
155- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
156+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
156157 }
157158
158159 // note: This uses vkCmdCopyImage to copy the image to the D3D12-created interop texture. s_activeCopyOperations queues a semaphore for the D3D12 side to wait on.
@@ -174,7 +175,7 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
174175 // clear the image to be transparent to allow for the HUD to be rendered on top of it which results in a transparent HUD layer
175176 VkClearColorValue clearColor = {{ 0 .0f , 0 .0f , 0 .0f , 0 .0f }};
176177 returnToLayout ();
177- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
178+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
178179 }
179180
180181 // 2D layer - color texture for HUD rendering
@@ -188,7 +189,7 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
188189
189190 VkClearColorValue clearColor = {{ 0 .0f , 0 .0f , 0 .0f , 0 .0f }};
190191 returnToLayout ();
191- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
192+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
192193 }
193194 else {
194195 // provide the HUD texture to the imgui overlay we'll use to recomposite Cemu's original flatscreen rendering
@@ -231,18 +232,18 @@ void VkDeviceOverrides::CmdClearColorImage(const vkroots::VkDeviceDispatch* pDis
231232 if (hudCopied) {
232233 // AMD GPU FIX: Use local VkClearColorValue instead of const_cast to avoid UB
233234 VkClearColorValue clearColor = {{ 0 .0f , 0 .0f , 0 .0f , 0 .0f }};
234- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
235+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, &clearColor, rangeCount, pRanges);
235236 }
236237 }
237238 }
238239 return ;
239240 }
240241 else {
241- return pDispatch-> CmdClearColorImage (commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
242+ return pDispatch. CmdClearColorImage (commandBuffer, image, imageLayout, pColor, rangeCount, pRanges);
242243 }
243244}
244245
245- void VkDeviceOverrides::CmdClearDepthStencilImage (const vkroots::VkDeviceDispatch* pDispatch, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges) {
246+ void VkDeviceOverrides::CmdClearDepthStencilImage (const vkroots::VkCommandBufferDispatch& pDispatch, VkCommandBuffer commandBuffer, VkImage image, VkImageLayout imageLayout, const VkClearDepthStencilValue* pDepthStencil, uint32_t rangeCount, const VkImageSubresourceRange* pRanges) {
246247 // check for magical clear values
247248 // check order and whether there's a match with the magical clear value
248249 OpenXR::EyeSide side = (OpenXR::EyeSide)-1 ;
@@ -323,31 +324,11 @@ void VkDeviceOverrides::CmdClearDepthStencilImage(const vkroots::VkDeviceDispatc
323324 }
324325 }
325326 else {
326- return pDispatch-> CmdClearDepthStencilImage (commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
327+ return pDispatch. CmdClearDepthStencilImage (commandBuffer, image, imageLayout, pDepthStencil, rangeCount, pRanges);
327328 }
328329}
329330
330- static std::unordered_set<VkSemaphore> s_isTimeline;
331-
332- VkResult VkDeviceOverrides::CreateSemaphore (const vkroots::VkDeviceDispatch* pDispatch, VkDevice device, const VkSemaphoreCreateInfo* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSemaphore* pSemaphore) {
333- VkResult res = pDispatch->CreateSemaphore (device, pCreateInfo, pAllocator, pSemaphore);
334- if (res == VK_SUCCESS && vkroots::FindInChain<VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO, const VkSemaphoreCreateInfo>(pCreateInfo->pNext )) {
335- s_isTimeline.emplace (*pSemaphore);
336- }
337- return res;
338- }
339-
340- void VkDeviceOverrides::DestroySemaphore (const vkroots::VkDeviceDispatch* pDispatch, VkDevice device, VkSemaphore semaphore, const VkAllocationCallbacks* pAllocator) {
341- s_isTimeline.erase (semaphore);
342- return pDispatch->DestroySemaphore (device, semaphore, pAllocator);
343- }
344-
345- inline bool IsTimeline (const VkSemaphore semaphore) {
346- auto it = s_isTimeline.find (semaphore);
347- return it != s_isTimeline.end ();
348- }
349-
350- VkResult VkDeviceOverrides::QueueSubmit (const vkroots::VkDeviceDispatch* pDispatch, VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) {
331+ VkResult VkDeviceOverrides::QueueSubmit (const vkroots::VkQueueDispatch& pDispatch, VkQueue queue, uint32_t submitCount, const VkSubmitInfo* pSubmits, VkFence fence) {
351332 VkResult result = VK_SUCCESS;
352333
353334 size_t activeCopyCount;
@@ -357,7 +338,7 @@ VkResult VkDeviceOverrides::QueueSubmit(const vkroots::VkDeviceDispatch* pDispat
357338 }
358339
359340 if (activeCopyCount == 0 ) {
360- result = pDispatch-> QueueSubmit (queue, submitCount, pSubmits, fence);
341+ result = pDispatch. QueueSubmit (queue, submitCount, pSubmits, fence);
361342 }
362343 else {
363344 struct ModifiedSubmitInfo_t {
@@ -454,7 +435,7 @@ VkResult VkDeviceOverrides::QueueSubmit(const vkroots::VkDeviceDispatch* pDispat
454435
455436 shadowSubmits[i] = modifiedSubmitInfo.submitInfoCopy ;
456437 }
457- result = pDispatch-> QueueSubmit (queue, submitCount, shadowSubmits.data (), fence);
438+ result = pDispatch. QueueSubmit (queue, submitCount, shadowSubmits.data (), fence);
458439 }
459440
460441 if (result != VK_SUCCESS) {
@@ -464,8 +445,16 @@ VkResult VkDeviceOverrides::QueueSubmit(const vkroots::VkDeviceDispatch* pDispat
464445 return result;
465446}
466447
467- VkResult VkDeviceOverrides::QueuePresentKHR (const vkroots::VkDeviceDispatch* pDispatch, VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
448+ VkResult VkDeviceOverrides::QueuePresentKHR (const vkroots::VkQueueDispatch& pDispatch, VkQueue queue, const VkPresentInfoKHR* pPresentInfo) {
468449 VRManager::instance ().XR ->ProcessEvents ();
469450
470- return pDispatch->QueuePresentKHR (queue, pPresentInfo);
451+ auto * renderer = VRManager::instance ().XR ->GetRenderer ();
452+ if (renderer && renderer->m_layer3D && renderer->m_layer2D && renderer->m_imguiOverlay ) {
453+ if (renderer->IsInitialized ()) {
454+ renderer->EndFrame ();
455+ }
456+ renderer->StartFrame ();
457+ }
458+
459+ return pDispatch.QueuePresentKHR (queue, pPresentInfo);
471460}
0 commit comments