diff options
author | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-02-28 04:49:28 +0100 |
---|---|---|
committer | ReinUsesLisp <reinuseslisp@airmail.cc> | 2019-03-01 21:33:36 +0100 |
commit | 35c105a108d85465046b0f472ef5708b4a143266 (patch) | |
tree | 2ef5080ecd29795b81afb1a5248ee3bdac6b4594 /src/video_core/renderer_vulkan/vk_buffer_cache.h | |
parent | Merge pull request #2174 from lioncash/fwd (diff) | |
download | yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar.gz yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar.bz2 yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar.lz yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar.xz yuzu-35c105a108d85465046b0f472ef5708b4a143266.tar.zst yuzu-35c105a108d85465046b0f472ef5708b4a143266.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_vulkan/vk_buffer_cache.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/video_core/renderer_vulkan/vk_buffer_cache.h b/src/video_core/renderer_vulkan/vk_buffer_cache.h new file mode 100644 index 000000000..6cbe21202 --- /dev/null +++ b/src/video_core/renderer_vulkan/vk_buffer_cache.h @@ -0,0 +1,87 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> +#include <tuple> + +#include "common/common_types.h" +#include "video_core/gpu.h" +#include "video_core/rasterizer_cache.h" +#include "video_core/renderer_vulkan/declarations.h" +#include "video_core/renderer_vulkan/vk_scheduler.h" + +namespace Tegra { +class MemoryManager; +} + +namespace Vulkan { + +class VKDevice; +class VKFence; +class VKMemoryManager; +class VKStreamBuffer; + +struct CachedBufferEntry final : public RasterizerCacheObject { + VAddr GetAddr() const override { + return addr; + } + + std::size_t GetSizeInBytes() const override { + return size; + } + + // We do not have to flush this cache as things in it are never modified by us. + void Flush() override {} + + VAddr addr; + std::size_t size; + u64 offset; + std::size_t alignment; +}; + +class VKBufferCache final : public RasterizerCache<std::shared_ptr<CachedBufferEntry>> { +public: + explicit VKBufferCache(Tegra::MemoryManager& tegra_memory_manager, VideoCore::RasterizerInterface& rasterizer, + const VKDevice& device, VKMemoryManager& memory_manager, + VKScheduler& scheduler, u64 size); + ~VKBufferCache(); + + /// Uploads data from a guest GPU address. Returns host's buffer offset where it's been + /// allocated. + u64 UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, u64 alignment = 4, + bool cache = true); + + /// Uploads from a host memory. Returns host's buffer offset where it's been allocated. + u64 UploadHostMemory(const u8* raw_pointer, std::size_t size, u64 alignment = 4); + + /// Reserves memory to be used by host's CPU. Returns mapped address and offset. + std::tuple<u8*, u64> ReserveMemory(std::size_t size, u64 alignment = 4); + + /// Reserves a region of memory to be used in subsequent upload/reserve operations. + void Reserve(std::size_t max_size); + + /// Ensures that the set data is sent to the device. + [[nodiscard]] VKExecutionContext Send(VKExecutionContext exctx); + + /// Returns the buffer cache handle. + vk::Buffer GetBuffer() const { + return buffer_handle; + } + +private: + void AlignBuffer(std::size_t alignment); + + Tegra::MemoryManager& tegra_memory_manager; + + std::unique_ptr<VKStreamBuffer> stream_buffer; + vk::Buffer buffer_handle; + + u8* buffer_ptr = nullptr; + u64 buffer_offset = 0; + u64 buffer_offset_base = 0; +}; + +} // namespace Vulkan |