Make sure VKRRenderThreadTask isn't copied.

This commit is contained in:
Henrik Rydgård
2023-05-17 00:55:04 +02:00
parent ab34d20058
commit 0b9dfac844
4 changed files with 20 additions and 17 deletions
+1 -1
View File
@@ -481,7 +481,7 @@ void VulkanQueueRunner::ApplyMGSHack(std::vector<VKRStep *> &steps) {
last = j - 1;
// should really also check descriptor sets...
if (steps[j]->commands.size()) {
VkRenderData &cmd = steps[j]->commands.back();
const VkRenderData &cmd = steps[j]->commands.back();
if (cmd.cmd == VKRRenderCommand::DRAW_INDEXED && cmd.draw.count != 6)
last = j - 1;
}
+6 -1
View File
@@ -212,9 +212,14 @@ struct VKRStep {
// These are enqueued from the main thread,
// and the render thread pops them off
struct VKRRenderThreadTask {
VKRRenderThreadTask(VKRRunType _runType) : runType(_runType) {}
std::vector<VKRStep *> steps;
int frame;
int frame = -1;
VKRRunType runType;
// Avoid copying these by accident.
VKRRenderThreadTask(VKRRenderThreadTask &) = delete;
VKRRenderThreadTask &operator =(VKRRenderThreadTask &) = delete;
};
class VulkanQueueRunner {
+12 -14
View File
@@ -308,9 +308,8 @@ bool VulkanRenderManager::CreateBackbuffers() {
void VulkanRenderManager::StopThread() {
{
// Tell the render thread to quit when it's done.
VKRRenderThreadTask task;
task.frame = vulkan_->GetCurFrame();
task.runType = VKRRunType::EXIT;
VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::EXIT);
task->frame = vulkan_->GetCurFrame();
std::unique_lock<std::mutex> lock(pushMutex_);
renderThreadQueue_.push(task);
pushCondVar_.notify_one();
@@ -494,7 +493,7 @@ void VulkanRenderManager::ThreadFunc() {
SetCurrentThreadName("RenderMan");
while (true) {
// Pop a task of the queue and execute it.
VKRRenderThreadTask task;
VKRRenderThreadTask *task = nullptr;
{
std::unique_lock<std::mutex> lock(pushMutex_);
while (renderThreadQueue_.empty()) {
@@ -506,12 +505,13 @@ void VulkanRenderManager::ThreadFunc() {
// Oh, we got a task! We can now have pushMutex_ unlocked, allowing the host to
// push more work when it feels like it, and just start working.
if (task.runType == VKRRunType::EXIT) {
if (task->runType == VKRRunType::EXIT) {
// Oh, host wanted out. Let's leave.
break;
}
Run(task);
Run(*task);
delete task;
}
// Wait for the device to be done with everything, before tearing stuff down.
@@ -1266,13 +1266,12 @@ void VulkanRenderManager::Finish() {
FrameData &frameData = frameData_[curFrame];
VLOG("PUSH: Frame[%d]", curFrame);
VKRRenderThreadTask task;
task.frame = curFrame;
task.runType = VKRRunType::PRESENT;
VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::PRESENT);
task->frame = curFrame;
{
std::unique_lock<std::mutex> lock(pushMutex_);
renderThreadQueue_.push(task);
renderThreadQueue_.back().steps = std::move(steps_);
renderThreadQueue_.back()->steps = std::move(steps_);
pushCondVar_.notify_one();
}
@@ -1382,12 +1381,11 @@ void VulkanRenderManager::FlushSync() {
{
VLOG("PUSH: Frame[%d]", curFrame);
VKRRenderThreadTask task;
task.frame = curFrame;
task.runType = VKRRunType::SYNC;
VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::SYNC);
task->frame = curFrame;
std::unique_lock<std::mutex> lock(pushMutex_);
renderThreadQueue_.push(task);
renderThreadQueue_.back().steps = std::move(steps_);
renderThreadQueue_.back()->steps = std::move(steps_);
pushCondVar_.notify_one();
}
+1 -1
View File
@@ -509,7 +509,7 @@ private:
std::mutex pushMutex_;
std::condition_variable pushCondVar_;
std::queue<VKRRenderThreadTask> renderThreadQueue_;
std::queue<VKRRenderThreadTask *> renderThreadQueue_;
// For readbacks and other reasons we need to sync with the render thread.
std::mutex syncMutex_;