Update for vulkan renderer

- Create staging buffers before starting bg thread
- Remove VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT
This commit is contained in:
Attila Uygun 2023-07-01 23:25:37 +02:00
parent 3dc48ef05e
commit 392c4eaf8f
2 changed files with 30 additions and 31 deletions

View File

@ -974,11 +974,21 @@ bool RendererVulkan::InitializeInternal() {
LOG(0) << " etc1: " << texture_compression_.etc1; LOG(0) << " etc1: " << texture_compression_.etc1;
LOG(0) << " s3tc: " << texture_compression_.s3tc; LOG(0) << " s3tc: " << texture_compression_.s3tc;
current_staging_buffer_ = 0;
staging_buffer_used_ = false;
if (max_staging_buffer_size_ < staging_buffer_size_ * 4)
max_staging_buffer_size_ = staging_buffer_size_ * 4;
for (int i = 0; i < frame_count; i++) {
bool err = InsertStagingBuffer();
LOG_IF(0, !err) << "Failed to create staging buffer.";
}
// Use a background thread for filling up staging buffers and recording setup // Use a background thread for filling up staging buffers and recording setup
// commands. // commands.
quit_.store(false, std::memory_order_relaxed); quit_.store(false, std::memory_order_relaxed);
setup_thread_ = setup_thread_ = std::thread(&RendererVulkan::SetupThreadMain, this);
std::thread(&RendererVulkan::SetupThreadMain, this, frame_count);
// Begin the first command buffer for the first frame. // Begin the first command buffer for the first frame.
BeginFrame(); BeginFrame();
@ -1000,6 +1010,11 @@ void RendererVulkan::Shutdown() {
semaphore_.release(); semaphore_.release();
setup_thread_.join(); setup_thread_.join();
for (size_t i = 0; i < staging_buffers_.size(); i++) {
auto [buffer, allocation] = staging_buffers_[i].buffer;
vmaDestroyBuffer(allocator_, buffer, allocation);
}
DestroyAllResources(); DestroyAllResources();
context_lost_ = true; context_lost_ = true;
@ -1065,7 +1080,8 @@ void RendererVulkan::BeginFrame() {
// Advance current frame. // Advance current frame.
frames_drawn_++; frames_drawn_++;
// Advance staging buffer if used. // Advance staging buffer if used. All tasks in bg thread are complete so this
// is thread safe.
if (staging_buffer_used_) { if (staging_buffer_used_) {
current_staging_buffer_ = current_staging_buffer_ =
(current_staging_buffer_ + 1) % staging_buffers_.size(); (current_staging_buffer_ + 1) % staging_buffers_.size();
@ -1971,11 +1987,10 @@ void RendererVulkan::DrawListEnd() {
#ifdef FORCE_FULL_BARRIER #ifdef FORCE_FULL_BARRIER
FullBarrier(true); FullBarrier(true);
#else #else
MemoryBarrier(VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT | MemoryBarrier(
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT |
VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT, VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT,
VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_VERTEX_INPUT_BIT | VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT |
VK_PIPELINE_STAGE_TRANSFER_BIT,
VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT |
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT | VK_ACCESS_INDEX_READ_BIT | VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT |
@ -2003,18 +2018,7 @@ void RendererVulkan::SwapBuffers() {
BeginFrame(); BeginFrame();
} }
void RendererVulkan::SetupThreadMain(int preallocate) { void RendererVulkan::SetupThreadMain() {
if (max_staging_buffer_size_ < staging_buffer_size_ * 4)
max_staging_buffer_size_ = staging_buffer_size_ * 4;
current_staging_buffer_ = 0;
staging_buffer_used_ = false;
for (int i = 0; i < preallocate; i++) {
bool err = InsertStagingBuffer();
LOG_IF(0, !err) << "Failed to create staging buffer.";
}
for (;;) { for (;;) {
semaphore_.acquire(); semaphore_.acquire();
if (quit_.load(std::memory_order_relaxed)) if (quit_.load(std::memory_order_relaxed))
@ -2022,11 +2026,6 @@ void RendererVulkan::SetupThreadMain(int preallocate) {
task_runner_.RunTasks(); task_runner_.RunTasks();
} }
for (size_t i = 0; i < staging_buffers_.size(); i++) {
auto [buffer, allocation] = staging_buffers_[i].buffer;
vmaDestroyBuffer(allocator_, buffer, allocation);
}
} }
template <typename T> template <typename T>

View File

@ -256,7 +256,7 @@ class RendererVulkan final : public Renderer {
void SwapBuffers(); void SwapBuffers();
void SetupThreadMain(int preallocate); void SetupThreadMain();
template <typename T> template <typename T>
bool SetUniformInternal(ShaderVulkan& shader, const std::string& name, T val); bool SetUniformInternal(ShaderVulkan& shader, const std::string& name, T val);