1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-04 16:24:29 +01:00

[dxvk] Add callback to lock submission queue

Can be used to perform additional synchronization as necessary.
This commit is contained in:
Philip Rebohle 2023-03-16 01:32:46 +01:00
parent 56a8fa2e6f
commit 35895ba05b
6 changed files with 31 additions and 9 deletions

View File

@ -543,7 +543,7 @@ namespace dxvk {
queues.transfer = getDeviceQueue(vkd, queueFamilies.transfer, 0);
queues.sparse = getDeviceQueue(vkd, queueFamilies.sparse, 0);
return new DxvkDevice(instance, this, vkd, enabledFeatures, queues);
return new DxvkDevice(instance, this, vkd, enabledFeatures, queues, DxvkQueueCallback());
}
@ -655,7 +655,7 @@ namespace dxvk {
queues.graphics = { args.queue, args.queueFamily };
queues.transfer = queues.graphics;
return new DxvkDevice(instance, this, vkd, enabledFeatures, queues);
return new DxvkDevice(instance, this, vkd, enabledFeatures, queues, args.queueCallback);
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <functional>
#include <optional>
#include "dxvk_device_info.h"
@ -11,7 +12,9 @@ namespace dxvk {
class DxvkDevice;
class DxvkInstance;
using DxvkQueueCallback = std::function<void (bool)>;
/**
* \brief GPU vendors
* Based on PCIe IDs.
@ -65,6 +68,7 @@ namespace dxvk {
uint32_t extensionCount;
const char** extensionNames;
const VkPhysicalDeviceFeatures2* features;
DxvkQueueCallback queueCallback;
};
/**

View File

@ -8,7 +8,8 @@ namespace dxvk {
const Rc<DxvkAdapter>& adapter,
const Rc<vk::DeviceFn>& vkd,
const DxvkDeviceFeatures& features,
const DxvkDeviceQueueSet& queues)
const DxvkDeviceQueueSet& queues,
const DxvkQueueCallback& queueCallback)
: m_options (instance->options()),
m_instance (instance),
m_adapter (adapter),
@ -18,7 +19,7 @@ namespace dxvk {
m_perfHints (getPerfHints()),
m_objects (this),
m_queues (queues),
m_submissionQueue (this) {
m_submissionQueue (this, queueCallback) {
}

View File

@ -87,7 +87,8 @@ namespace dxvk {
const Rc<DxvkAdapter>& adapter,
const Rc<vk::DeviceFn>& vkd,
const DxvkDeviceFeatures& features,
const DxvkDeviceQueueSet& queues);
const DxvkDeviceQueueSet& queues,
const DxvkQueueCallback& queueCallback);
~DxvkDevice();

View File

@ -3,8 +3,8 @@
namespace dxvk {
DxvkSubmissionQueue::DxvkSubmissionQueue(DxvkDevice* device)
: m_device(device),
DxvkSubmissionQueue::DxvkSubmissionQueue(DxvkDevice* device, const DxvkQueueCallback& callback)
: m_device(device), m_callback(callback),
m_submitThread([this] () { submitCmdLists(); }),
m_finishThread([this] () { finishCmdLists(); }) {
@ -75,10 +75,16 @@ namespace dxvk {
void DxvkSubmissionQueue::lockDeviceQueue() {
m_mutexQueue.lock();
if (m_callback)
m_callback(true);
}
void DxvkSubmissionQueue::unlockDeviceQueue() {
if (m_callback)
m_callback(false);
m_mutexQueue.unlock();
}
@ -105,10 +111,16 @@ namespace dxvk {
if (m_lastError != VK_ERROR_DEVICE_LOST) {
std::lock_guard<dxvk::mutex> lock(m_mutexQueue);
if (m_callback)
m_callback(true);
if (entry.submit.cmdList != nullptr)
status = entry.submit.cmdList->submit();
else if (entry.present.presenter != nullptr)
status = entry.present.presenter->presentImage();
if (m_callback)
m_callback(false);
} else {
// Don't submit anything after device loss
// so that drivers get a chance to recover

View File

@ -64,7 +64,10 @@ namespace dxvk {
public:
DxvkSubmissionQueue(DxvkDevice* device);
DxvkSubmissionQueue(
DxvkDevice* device,
const DxvkQueueCallback& callback);
~DxvkSubmissionQueue();
/**
@ -176,6 +179,7 @@ namespace dxvk {
private:
DxvkDevice* m_device;
DxvkQueueCallback m_callback;
std::atomic<VkResult> m_lastError = { VK_SUCCESS };