2019-02-24 08:22:33 +01:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
2020-12-30 06:25:23 +01:00
|
|
|
#include <utility>
|
2019-02-24 08:22:33 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2019-02-24 08:22:33 +01:00
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
class Device;
|
2019-02-24 08:22:33 +01:00
|
|
|
class VKFenceWatch;
|
|
|
|
class VKScheduler;
|
|
|
|
|
2020-01-06 21:59:20 +01:00
|
|
|
class VKStreamBuffer final {
|
2019-02-24 08:22:33 +01:00
|
|
|
public:
|
2020-12-26 05:10:53 +01:00
|
|
|
explicit VKStreamBuffer(const Device& device, VKScheduler& scheduler);
|
2019-02-24 08:22:33 +01:00
|
|
|
~VKStreamBuffer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reserves a region of memory from the stream buffer.
|
|
|
|
* @param size Size to reserve.
|
2020-12-30 06:25:23 +01:00
|
|
|
* @returns A pair of a raw memory pointer (with offset added), and the buffer offset
|
2019-02-24 08:22:33 +01:00
|
|
|
*/
|
2020-12-30 06:25:23 +01:00
|
|
|
std::pair<u8*, u64> Map(u64 size, u64 alignment);
|
2019-02-24 08:22:33 +01:00
|
|
|
|
|
|
|
/// Ensures that "size" bytes of memory are available to the GPU, potentially recording a copy.
|
2020-01-06 21:59:20 +01:00
|
|
|
void Unmap(u64 size);
|
2019-02-24 08:22:33 +01:00
|
|
|
|
2020-05-11 21:35:04 +02:00
|
|
|
VkBuffer Handle() const noexcept {
|
2019-02-26 06:09:43 +01:00
|
|
|
return *buffer;
|
|
|
|
}
|
|
|
|
|
2020-05-11 21:35:04 +02:00
|
|
|
u64 Address() const noexcept {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-02-24 08:22:33 +01:00
|
|
|
private:
|
2020-09-10 08:43:30 +02:00
|
|
|
struct Watch {
|
|
|
|
u64 tick{};
|
2020-01-06 21:59:20 +01:00
|
|
|
u64 upper_bound{};
|
|
|
|
};
|
|
|
|
|
2019-02-24 08:22:33 +01:00
|
|
|
/// Creates Vulkan buffer handles committing the required the required memory.
|
2020-12-30 06:25:23 +01:00
|
|
|
void CreateBuffers();
|
2019-02-24 08:22:33 +01:00
|
|
|
|
|
|
|
/// Increases the amount of watches available.
|
2020-01-06 21:59:20 +01:00
|
|
|
void ReserveWatches(std::vector<Watch>& watches, std::size_t grow_size);
|
|
|
|
|
|
|
|
void WaitPendingOperations(u64 requested_upper_bound);
|
2019-02-24 08:22:33 +01:00
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device& device; ///< Vulkan device manager.
|
2020-03-27 05:33:21 +01:00
|
|
|
VKScheduler& scheduler; ///< Command scheduler.
|
2019-02-24 08:22:33 +01:00
|
|
|
|
2020-04-17 10:13:35 +02:00
|
|
|
vk::Buffer buffer; ///< Mapped buffer.
|
|
|
|
vk::DeviceMemory memory; ///< Memory allocation.
|
|
|
|
u64 stream_buffer_size{}; ///< Stream buffer size.
|
2019-02-24 08:22:33 +01:00
|
|
|
|
|
|
|
u64 offset{}; ///< Buffer iterator.
|
|
|
|
u64 mapped_size{}; ///< Size reserved for the current copy.
|
|
|
|
|
2020-01-06 21:59:20 +01:00
|
|
|
std::vector<Watch> current_watches; ///< Watches recorded in the current iteration.
|
|
|
|
std::size_t current_watch_cursor{}; ///< Count of watches, reset on invalidation.
|
|
|
|
std::optional<std::size_t> invalidation_mark; ///< Number of watches used in the previous cycle.
|
|
|
|
|
|
|
|
std::vector<Watch> previous_watches; ///< Watches used in the previous iteration.
|
|
|
|
std::size_t wait_cursor{}; ///< Last watch being waited for completion.
|
|
|
|
u64 wait_bound{}; ///< Highest offset being watched for completion.
|
2019-02-24 08:22:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|