Add end-of-init barrier

This commit is contained in:
Henrik Rydgård 2023-05-31 07:48:51 +02:00
parent a9456824aa
commit 484fbeb4cb
3 changed files with 26 additions and 6 deletions

View File

@ -16,6 +16,8 @@ class VulkanBarrier {
public:
VulkanBarrier() : imageBarriers_(4) {}
bool empty() const { return imageBarriers_.empty(); }
void TransitionImage(
VkImage image, int baseMip, int numMipLevels, int numLayers, VkImageAspectFlags aspectMask,
VkImageLayout oldImageLayout, VkImageLayout newImageLayout,

View File

@ -1411,6 +1411,11 @@ void VulkanRenderManager::Finish() {
int curFrame = vulkan_->GetCurFrame();
FrameData &frameData = frameData_[curFrame];
if (!postInitBarrier_.empty()) {
VkCommandBuffer buffer = frameData.GetInitCmd(vulkan_);
postInitBarrier_.Flush(buffer);
}
VLOG("PUSH: Frame[%d]", curFrame);
VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::SUBMIT);
task->frame = curFrame;
@ -1561,7 +1566,12 @@ void VulkanRenderManager::FlushSync() {
int curFrame = vulkan_->GetCurFrame();
FrameData &frameData = frameData_[curFrame];
if (!postInitBarrier_.empty()) {
VkCommandBuffer buffer = frameData.GetInitCmd(vulkan_);
postInitBarrier_.Flush(buffer);
}
if (useRenderThread_) {
{
VLOG("PUSH: Frame[%d]", curFrame);
@ -1584,11 +1594,10 @@ void VulkanRenderManager::FlushSync() {
frameData.syncDone = false;
}
} else {
VKRRenderThreadTask *task = new VKRRenderThreadTask(VKRRunType::SYNC);
task->frame = curFrame;
task->steps = std::move(steps_);
Run(*task);
delete task;
VKRRenderThreadTask task(VKRRunType::SYNC);
task.frame = curFrame;
task.steps = std::move(steps_);
Run(task);
steps_.clear();
}
}

View File

@ -16,6 +16,7 @@
#include "Common/Thread/Promise.h"
#include "Common/System/Display.h"
#include "Common/GPU/Vulkan/VulkanContext.h"
#include "Common/GPU/Vulkan/VulkanBarrier.h"
#include "Common/Data/Convert/SmallDataConvert.h"
#include "Common/Data/Collections/FastVec.h"
#include "Common/Math/math_util.h"
@ -535,6 +536,12 @@ public:
return outOfDateFrames_ > VulkanContext::MAX_INFLIGHT_FRAMES;
}
void Invalidate(InvalidationFlags flags);
VulkanBarrier &PostInitBarrier() {
return postInitBarrier_;
}
void ResetStats();
void DrainAndBlockCompileQueue();
void ReleaseCompileQueue();
@ -626,6 +633,8 @@ private:
SimpleStat renderCPUTimeMs_;
SimpleStat descUpdateTimeMs_;
VulkanBarrier postInitBarrier_;
std::function<void(InvalidationCallbackFlags)> invalidationCallback_;
uint64_t frameIdGen_ = FRAME_TIME_HISTORY_LENGTH;