Skip to content

Commit d614c49

Browse files
committed
Fix audio, improve performance (a little) and update vkroots dependency
1 parent 3bbf303 commit d614c49

File tree

12 files changed

+22755
-10738
lines changed

12 files changed

+22755
-10738
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ target_sources(BetterVR_Layer PUBLIC
9494
${CMAKE_CURRENT_SOURCE_DIR}/src/rendering/vulkan.cpp
9595
${CMAKE_CURRENT_SOURCE_DIR}/src/rendering/vulkan.h
9696
${CMAKE_CURRENT_SOURCE_DIR}/src/rendering/vulkan_imgui.cpp
97-
${CMAKE_CURRENT_SOURCE_DIR}/src/hooking/compatibility.cpp
9897
)
9998

10099
# Add graphic pack files to Visual Studio for editing

dependencies/vkroots.h

Lines changed: 22677 additions & 10300 deletions
Large diffs are not rendered by default.

src/hooking/camera.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ void CemuHooks::hook_BeginCameraSide(PPCInterpreter_t* hCPU) {
1111
Log::print<RENDERING>("");
1212
Log::print<RENDERING>("===============================================================================");
1313
Log::print<RENDERING>("{0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0} {0}", side);
14-
15-
RND_Renderer* renderer = VRManager::instance().XR->GetRenderer();
16-
17-
bool layersInitialized = renderer->m_layer3D && renderer->m_layer2D && renderer->m_imguiOverlay;
18-
if (layersInitialized && side == OpenXR::EyeSide::LEFT) {
19-
VRManager::instance().XR->GetRenderer()->StartFrame();
20-
}
2114
}
2215

2316
static std::pair<glm::quat, glm::quat> swingTwistY(const glm::quat& q) {
@@ -403,7 +396,6 @@ void CemuHooks::hook_EndCameraSide(PPCInterpreter_t* hCPU) {
403396

404397
// todo: sometimes this can deadlock apparently?
405398
if (VRManager::instance().XR->GetRenderer()->IsInitialized() && side == OpenXR::EyeSide::RIGHT) {
406-
VRManager::instance().XR->GetRenderer()->EndFrame();
407399
CemuHooks::m_heldWeaponsLastUpdate[0] = CemuHooks::m_heldWeaponsLastUpdate[0]++;
408400
CemuHooks::m_heldWeaponsLastUpdate[1] = CemuHooks::m_heldWeaponsLastUpdate[1]++;
409401
if (CemuHooks::m_heldWeaponsLastUpdate[0] >= 6) {

src/hooking/compatibility.cpp

Lines changed: 0 additions & 245 deletions
This file was deleted.

src/hooking/framebuffer.cpp

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ VkImage s_curr3DDepthImage = VK_NULL_HANDLE;
1515

1616
using 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

Comments
 (0)