diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-01-05 21:26:04 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2020-01-06 22:28:32 +0100 |
commit | 322d6a0311624b8304894baa102ab462ea6cf0ea (patch) | |
tree | e732f9f46a8f15b531a183b787ea20bd1303a26a /src/video_core/renderer_vulkan/vk_update_descriptor.h | |
parent | Merge pull request #3257 from degasus/no_busy_loops (diff) | |
download | yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar.gz yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar.bz2 yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar.lz yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar.xz yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.tar.zst yuzu-322d6a0311624b8304894baa102ab462ea6cf0ea.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_vulkan/vk_update_descriptor.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_update_descriptor.h b/src/video_core/renderer_vulkan/vk_update_descriptor.h new file mode 100644 index 000000000..8c825aa29 --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_update_descriptor.h @@ -0,0 +1,86 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <type_traits> +#include <variant> +#include <boost/container/static_vector.hpp> + +#include "common/common_types.h" +#include "video_core/renderer_vulkan/declarations.h" + +namespace Vulkan { + +class VKDevice; +class VKScheduler; + +class DescriptorUpdateEntry { +public: + explicit DescriptorUpdateEntry() : image{} {} + + DescriptorUpdateEntry(vk::DescriptorImageInfo image) : image{image} {} + + DescriptorUpdateEntry(vk::Buffer buffer, vk::DeviceSize offset, vk::DeviceSize size) + : buffer{buffer, offset, size} {} + + DescriptorUpdateEntry(vk::BufferView texel_buffer) : texel_buffer{texel_buffer} {} + +private: + union { + vk::DescriptorImageInfo image; + vk::DescriptorBufferInfo buffer; + vk::BufferView texel_buffer; + }; +}; + +class VKUpdateDescriptorQueue final { +public: + explicit VKUpdateDescriptorQueue(const VKDevice& device, VKScheduler& scheduler); + ~VKUpdateDescriptorQueue(); + + void TickFrame(); + + void Acquire(); + + void Send(vk::DescriptorUpdateTemplate update_template, vk::DescriptorSet set); + + void AddSampledImage(vk::Sampler sampler, vk::ImageView image_view) { + entries.emplace_back(vk::DescriptorImageInfo{sampler, image_view, {}}); + } + + void AddImage(vk::ImageView image_view) { + entries.emplace_back(vk::DescriptorImageInfo{{}, image_view, {}}); + } + + void AddBuffer(const vk::Buffer* buffer, u64 offset, std::size_t size) { + entries.push_back(Buffer{buffer, offset, size}); + } + + void AddTexelBuffer(vk::BufferView texel_buffer) { + entries.emplace_back(texel_buffer); + } + + vk::ImageLayout* GetLastImageLayout() { + return &std::get<vk::DescriptorImageInfo>(entries.back()).imageLayout; + } + +private: + struct Buffer { + const vk::Buffer* buffer{}; + u64 offset{}; + std::size_t size{}; + }; + using Variant = std::variant<vk::DescriptorImageInfo, Buffer, vk::BufferView>; + // Old gcc versions don't consider this trivially copyable. + // static_assert(std::is_trivially_copyable_v<Variant>); + + const VKDevice& device; + VKScheduler& scheduler; + + boost::container::static_vector<Variant, 0x400> entries; + boost::container::static_vector<DescriptorUpdateEntry, 0x10000> payload; +}; + +} // namespace Vulkan |