Skip to content

Remove the need for vkDeviceWaitIdle. #1364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions UnleashedRecomp/gpu/rhi/plume_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2285,6 +2285,9 @@ namespace plume {
}

void D3D12CommandQueue::executeCommandLists(const RenderCommandList **commandLists, uint32_t commandListCount, RenderCommandSemaphore **waitSemaphores, uint32_t waitSemaphoreCount, RenderCommandSemaphore **signalSemaphores, uint32_t signalSemaphoreCount, RenderCommandFence *signalFence) {
assert(commandLists != nullptr);
assert(commandListCount > 0);

for (uint32_t i = 0; i < waitSemaphoreCount; i++) {
D3D12CommandSemaphore *interfaceSemaphore = static_cast<D3D12CommandSemaphore *>(waitSemaphores[i]);
d3d->Wait(interfaceSemaphore->d3d, interfaceSemaphore->semaphoreValue);
Expand All @@ -2297,9 +2300,7 @@ namespace plume {
executionVector.emplace_back(static_cast<ID3D12CommandList *>(interfaceCommandList->d3d));
}

if (!executionVector.empty()) {
d3d->ExecuteCommandLists(UINT(executionVector.size()), executionVector.data());
}
d3d->ExecuteCommandLists(UINT(executionVector.size()), executionVector.data());

for (uint32_t i = 0; i < signalSemaphoreCount; i++) {
D3D12CommandSemaphore *interfaceSemaphore = static_cast<D3D12CommandSemaphore *>(signalSemaphores[i]);
Expand Down Expand Up @@ -3798,10 +3799,6 @@ namespace plume {
return countsSupported;
}

void D3D12Device::waitIdle() const {
assert(false && "Use fences to replicate wait idle behavior on D3D12.");
}

void D3D12Device::release() {
if (d3d != nullptr) {
d3d->Release();
Expand Down
1 change: 0 additions & 1 deletion UnleashedRecomp/gpu/rhi/plume_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,6 @@ namespace plume {
const RenderDeviceCapabilities &getCapabilities() const override;
const RenderDeviceDescription &getDescription() const override;
RenderSampleCounts getSampleCountsSupported(RenderFormat format) const override;
void waitIdle() const override;
void release();
bool isValid() const;
};
Expand Down
3 changes: 1 addition & 2 deletions UnleashedRecomp/gpu/rhi/plume_render_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ namespace plume {

// Concrete implementation shortcuts.
inline void executeCommandLists(const RenderCommandList *commandList, RenderCommandFence *signalFence = nullptr) {
executeCommandLists(commandList != nullptr ? &commandList : nullptr, commandList != nullptr ? 1 : 0, nullptr, 0, nullptr, 0, signalFence);
executeCommandLists(&commandList, 1, nullptr, 0, nullptr, 0, signalFence);
}
};

Expand Down Expand Up @@ -242,7 +242,6 @@ namespace plume {
virtual const RenderDeviceCapabilities &getCapabilities() const = 0;
virtual const RenderDeviceDescription &getDescription() const = 0;
virtual RenderSampleCounts getSampleCountsSupported(RenderFormat format) const = 0;
virtual void waitIdle() const = 0;
};

struct RenderInterface {
Expand Down
4 changes: 0 additions & 4 deletions UnleashedRecomp/gpu/rhi/plume_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4190,10 +4190,6 @@ namespace plume {
}
}

void VulkanDevice::waitIdle() const {
vkDeviceWaitIdle(vk);
}

void VulkanDevice::release() {
if (allocator != VK_NULL_HANDLE) {
vmaDestroyAllocator(allocator);
Expand Down
1 change: 0 additions & 1 deletion UnleashedRecomp/gpu/rhi/plume_vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,6 @@ namespace plume {
const RenderDeviceCapabilities &getCapabilities() const override;
const RenderDeviceDescription &getDescription() const override;
RenderSampleCounts getSampleCountsSupported(RenderFormat format) const override;
void waitIdle() const override;
void release();
bool isValid() const;
};
Expand Down
24 changes: 11 additions & 13 deletions UnleashedRecomp/gpu/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1973,23 +1973,21 @@ void Video::WaitForGPU()
{
g_waitForGPUCount++;

if (g_vulkan)
{
g_device->waitIdle();
}
else
// Wait for all queued frames to finish.
for (size_t i = 0; i < NUM_FRAMES; i++)
{
for (size_t i = 0; i < NUM_FRAMES; i++)
if (g_commandListStates[i])
{
if (g_commandListStates[i])
{
g_queue->waitForCommandFence(g_commandFences[i].get());
g_commandListStates[i] = false;
}
g_queue->waitForCommandFence(g_commandFences[i].get());
g_commandListStates[i] = false;
}
g_queue->executeCommandLists(nullptr, g_commandFences[0].get());
g_queue->waitForCommandFence(g_commandFences[0].get());
}

// Execute an empty command list and wait for it to end to guarantee that any remaining presentation has finished.
g_commandLists[0]->begin();
g_commandLists[0]->end();
g_queue->executeCommandLists(g_commandLists[0].get(), g_commandFences[0].get());
g_queue->waitForCommandFence(g_commandFences[0].get());
}

static uint32_t CreateDevice(uint32_t a1, uint32_t a2, uint32_t a3, uint32_t a4, uint32_t a5, be<uint32_t>* a6)
Expand Down
Loading