forked from ShuriZma/suyu
1
0
Fork 0

Merge pull request #5924 from ReinUsesLisp/inline-bindings

vk_update_descriptor: Inline and improve code for binding buffers
This commit is contained in:
bunnei 2021-02-19 12:27:10 -08:00 committed by GitHub
commit 728ee181eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 24 deletions

View File

@ -201,10 +201,6 @@ void BufferCacheRuntime::BindTransformFeedbackBuffer(u32 index, VkBuffer buffer,
}); });
} }
void BufferCacheRuntime::BindBuffer(VkBuffer buffer, u32 offset, u32 size) {
update_descriptor_queue.AddBuffer(buffer, offset, size);
}
void BufferCacheRuntime::ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle) { void BufferCacheRuntime::ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle) {
if (num_indices <= current_num_indices) { if (num_indices <= current_num_indices) {
return; return;

View File

@ -8,6 +8,7 @@
#include "video_core/engines/maxwell_3d.h" #include "video_core/engines/maxwell_3d.h"
#include "video_core/renderer_vulkan/vk_compute_pass.h" #include "video_core/renderer_vulkan/vk_compute_pass.h"
#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h" #include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
#include "video_core/vulkan_common/vulkan_memory_allocator.h" #include "video_core/vulkan_common/vulkan_memory_allocator.h"
#include "video_core/vulkan_common/vulkan_wrapper.h" #include "video_core/vulkan_common/vulkan_wrapper.h"
@ -16,7 +17,6 @@ namespace Vulkan {
class Device; class Device;
class VKDescriptorPool; class VKDescriptorPool;
class VKScheduler; class VKScheduler;
class VKUpdateDescriptorQueue;
class BufferCacheRuntime; class BufferCacheRuntime;
@ -86,7 +86,9 @@ public:
} }
private: private:
void BindBuffer(VkBuffer buffer, u32 offset, u32 size); void BindBuffer(VkBuffer buffer, u32 offset, u32 size) {
update_descriptor_queue.AddBuffer(buffer, offset, size);
}
void ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle); void ReserveQuadArrayLUT(u32 num_indices, bool wait_for_idle);

View File

@ -20,20 +20,20 @@ VKUpdateDescriptorQueue::VKUpdateDescriptorQueue(const Device& device_, VKSchedu
VKUpdateDescriptorQueue::~VKUpdateDescriptorQueue() = default; VKUpdateDescriptorQueue::~VKUpdateDescriptorQueue() = default;
void VKUpdateDescriptorQueue::TickFrame() { void VKUpdateDescriptorQueue::TickFrame() {
payload.clear(); payload_cursor = payload.data();
} }
void VKUpdateDescriptorQueue::Acquire() { void VKUpdateDescriptorQueue::Acquire() {
// Minimum number of entries required. // Minimum number of entries required.
// This is the maximum number of entries a single draw call migth use. // This is the maximum number of entries a single draw call migth use.
static constexpr std::size_t MIN_ENTRIES = 0x400; static constexpr size_t MIN_ENTRIES = 0x400;
if (payload.size() + MIN_ENTRIES >= payload.max_size()) { if (std::distance(payload.data(), payload_cursor) + MIN_ENTRIES >= payload.max_size()) {
LOG_WARNING(Render_Vulkan, "Payload overflow, waiting for worker thread"); LOG_WARNING(Render_Vulkan, "Payload overflow, waiting for worker thread");
scheduler.WaitWorker(); scheduler.WaitWorker();
payload.clear(); payload_cursor = payload.data();
} }
upload_start = &*payload.end(); upload_start = payload_cursor;
} }
void VKUpdateDescriptorQueue::Send(VkDescriptorUpdateTemplateKHR update_template, void VKUpdateDescriptorQueue::Send(VkDescriptorUpdateTemplateKHR update_template,

View File

@ -4,8 +4,7 @@
#pragma once #pragma once
#include <variant> #include <array>
#include <boost/container/static_vector.hpp>
#include "common/common_types.h" #include "common/common_types.h"
#include "video_core/vulkan_common/vulkan_wrapper.h" #include "video_core/vulkan_common/vulkan_wrapper.h"
@ -16,13 +15,15 @@ class Device;
class VKScheduler; class VKScheduler;
struct DescriptorUpdateEntry { struct DescriptorUpdateEntry {
struct Empty {};
DescriptorUpdateEntry() = default;
DescriptorUpdateEntry(VkDescriptorImageInfo image_) : image{image_} {} DescriptorUpdateEntry(VkDescriptorImageInfo image_) : image{image_} {}
DescriptorUpdateEntry(VkDescriptorBufferInfo buffer_) : buffer{buffer_} {} DescriptorUpdateEntry(VkDescriptorBufferInfo buffer_) : buffer{buffer_} {}
DescriptorUpdateEntry(VkBufferView texel_buffer_) : texel_buffer{texel_buffer_} {} DescriptorUpdateEntry(VkBufferView texel_buffer_) : texel_buffer{texel_buffer_} {}
union { union {
Empty empty{};
VkDescriptorImageInfo image; VkDescriptorImageInfo image;
VkDescriptorBufferInfo buffer; VkDescriptorBufferInfo buffer;
VkBufferView texel_buffer; VkBufferView texel_buffer;
@ -41,39 +42,40 @@ public:
void Send(VkDescriptorUpdateTemplateKHR update_template, VkDescriptorSet set); void Send(VkDescriptorUpdateTemplateKHR update_template, VkDescriptorSet set);
void AddSampledImage(VkImageView image_view, VkSampler sampler) { void AddSampledImage(VkImageView image_view, VkSampler sampler) {
payload.emplace_back(VkDescriptorImageInfo{ *(payload_cursor++) = VkDescriptorImageInfo{
.sampler = sampler, .sampler = sampler,
.imageView = image_view, .imageView = image_view,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL, .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
}); };
} }
void AddImage(VkImageView image_view) { void AddImage(VkImageView image_view) {
payload.emplace_back(VkDescriptorImageInfo{ *(payload_cursor++) = VkDescriptorImageInfo{
.sampler = VK_NULL_HANDLE, .sampler = VK_NULL_HANDLE,
.imageView = image_view, .imageView = image_view,
.imageLayout = VK_IMAGE_LAYOUT_GENERAL, .imageLayout = VK_IMAGE_LAYOUT_GENERAL,
}); };
} }
void AddBuffer(VkBuffer buffer, u64 offset, size_t size) { void AddBuffer(VkBuffer buffer, VkDeviceSize offset, VkDeviceSize size) {
payload.emplace_back(VkDescriptorBufferInfo{ *(payload_cursor++) = VkDescriptorBufferInfo{
.buffer = buffer, .buffer = buffer,
.offset = offset, .offset = offset,
.range = size, .range = size,
}); };
} }
void AddTexelBuffer(VkBufferView texel_buffer) { void AddTexelBuffer(VkBufferView texel_buffer) {
payload.emplace_back(texel_buffer); *(payload_cursor++) = texel_buffer;
} }
private: private:
const Device& device; const Device& device;
VKScheduler& scheduler; VKScheduler& scheduler;
DescriptorUpdateEntry* payload_cursor = nullptr;
const DescriptorUpdateEntry* upload_start = nullptr; const DescriptorUpdateEntry* upload_start = nullptr;
boost::container::static_vector<DescriptorUpdateEntry, 0x10000> payload; std::array<DescriptorUpdateEntry, 0x10000> payload;
}; };
} // namespace Vulkan } // namespace Vulkan