2021-03-19 23:28:31 +01:00
|
|
|
// Copyright 2021 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-04-24 23:27:25 +02:00
|
|
|
#include <algorithm>
|
2021-03-19 23:28:31 +01:00
|
|
|
#include <array>
|
2021-04-01 06:36:22 +02:00
|
|
|
#include <atomic>
|
2021-04-04 02:41:49 +02:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
2021-04-24 23:27:25 +02:00
|
|
|
#include <type_traits>
|
2021-03-19 23:28:31 +01:00
|
|
|
|
2021-04-01 06:36:22 +02:00
|
|
|
#include "common/thread_worker.h"
|
2021-03-19 23:28:31 +01:00
|
|
|
#include "shader_recompiler/shader_info.h"
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
|
|
|
#include "video_core/renderer_vulkan/fixed_pipeline_state.h"
|
2021-04-01 06:36:22 +02:00
|
|
|
#include "video_core/renderer_vulkan/vk_buffer_cache.h"
|
2021-03-19 23:28:31 +01:00
|
|
|
#include "video_core/renderer_vulkan/vk_descriptor_pool.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
|
|
|
|
2021-06-06 05:11:36 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
class ShaderNotify;
|
|
|
|
}
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
namespace Vulkan {
|
|
|
|
|
2021-04-24 23:27:25 +02:00
|
|
|
struct GraphicsPipelineCacheKey {
|
2021-04-26 08:53:26 +02:00
|
|
|
std::array<u64, 6> unique_hashes;
|
2021-04-24 23:27:25 +02:00
|
|
|
FixedPipelineState state;
|
|
|
|
|
|
|
|
size_t Hash() const noexcept;
|
|
|
|
|
|
|
|
bool operator==(const GraphicsPipelineCacheKey& rhs) const noexcept;
|
|
|
|
|
|
|
|
bool operator!=(const GraphicsPipelineCacheKey& rhs) const noexcept {
|
|
|
|
return !operator==(rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Size() const noexcept {
|
|
|
|
return sizeof(unique_hashes) + state.Size();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
static_assert(std::has_unique_object_representations_v<GraphicsPipelineCacheKey>);
|
|
|
|
static_assert(std::is_trivially_copyable_v<GraphicsPipelineCacheKey>);
|
|
|
|
static_assert(std::is_trivially_constructible_v<GraphicsPipelineCacheKey>);
|
|
|
|
|
|
|
|
} // namespace Vulkan
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::GraphicsPipelineCacheKey> {
|
|
|
|
size_t operator()(const Vulkan::GraphicsPipelineCacheKey& k) const noexcept {
|
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
class Device;
|
|
|
|
class RenderPassCache;
|
|
|
|
class VKScheduler;
|
|
|
|
class VKUpdateDescriptorQueue;
|
|
|
|
|
|
|
|
class GraphicsPipeline {
|
|
|
|
static constexpr size_t NUM_STAGES = Tegra::Engines::Maxwell3D::Regs::MaxShaderStage;
|
|
|
|
|
|
|
|
public:
|
2021-06-06 05:11:36 +02:00
|
|
|
explicit GraphicsPipeline(
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d, Tegra::MemoryManager& gpu_memory,
|
|
|
|
VKScheduler& scheduler, BufferCache& buffer_cache, TextureCache& texture_cache,
|
|
|
|
VideoCore::ShaderNotify* shader_notify, const Device& device,
|
|
|
|
DescriptorPool& descriptor_pool, VKUpdateDescriptorQueue& update_descriptor_queue,
|
|
|
|
Common::ThreadWorker* worker_thread, RenderPassCache& render_pass_cache,
|
|
|
|
const GraphicsPipelineCacheKey& key, std::array<vk::ShaderModule, NUM_STAGES> stages,
|
|
|
|
const std::array<const Shader::Info*, NUM_STAGES>& infos);
|
2021-03-19 23:28:31 +01:00
|
|
|
|
2021-04-01 06:36:22 +02:00
|
|
|
GraphicsPipeline& operator=(GraphicsPipeline&&) noexcept = delete;
|
|
|
|
GraphicsPipeline(GraphicsPipeline&&) noexcept = delete;
|
2021-03-19 23:28:31 +01:00
|
|
|
|
|
|
|
GraphicsPipeline& operator=(const GraphicsPipeline&) = delete;
|
|
|
|
GraphicsPipeline(const GraphicsPipeline&) = delete;
|
|
|
|
|
2021-04-24 23:27:25 +02:00
|
|
|
void AddTransition(GraphicsPipeline* transition);
|
|
|
|
|
2021-04-24 23:28:02 +02:00
|
|
|
void Configure(bool is_indexed) {
|
|
|
|
configure_func(this, is_indexed);
|
|
|
|
}
|
|
|
|
|
2021-06-06 03:10:02 +02:00
|
|
|
[[nodiscard]] GraphicsPipeline* Next(const GraphicsPipelineCacheKey& current_key) noexcept {
|
2021-04-24 23:27:25 +02:00
|
|
|
if (key == current_key) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
const auto it{std::find(transition_keys.begin(), transition_keys.end(), current_key)};
|
|
|
|
return it != transition_keys.end() ? transitions[std::distance(transition_keys.begin(), it)]
|
|
|
|
: nullptr;
|
|
|
|
}
|
|
|
|
|
2021-06-06 03:10:02 +02:00
|
|
|
[[nodiscard]] bool IsBuilt() const noexcept {
|
|
|
|
return is_built.load(std::memory_order::relaxed);
|
|
|
|
}
|
|
|
|
|
2021-04-24 23:28:02 +02:00
|
|
|
template <typename Spec>
|
|
|
|
static auto MakeConfigureSpecFunc() {
|
2021-07-12 04:10:38 +02:00
|
|
|
return [](GraphicsPipeline* pl, bool is_indexed) { pl->ConfigureImpl<Spec>(is_indexed); };
|
2021-04-24 23:28:02 +02:00
|
|
|
}
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
private:
|
2021-04-24 23:28:02 +02:00
|
|
|
template <typename Spec>
|
|
|
|
void ConfigureImpl(bool is_indexed);
|
|
|
|
|
|
|
|
void ConfigureDraw();
|
|
|
|
|
2021-04-25 06:04:49 +02:00
|
|
|
void MakePipeline(VkRenderPass render_pass);
|
2021-03-19 23:28:31 +01:00
|
|
|
|
2021-04-24 23:28:02 +02:00
|
|
|
void Validate();
|
|
|
|
|
2021-04-24 23:27:25 +02:00
|
|
|
const GraphicsPipelineCacheKey key;
|
2021-04-01 06:36:22 +02:00
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d;
|
|
|
|
Tegra::MemoryManager& gpu_memory;
|
2021-04-25 06:04:49 +02:00
|
|
|
const Device& device;
|
2021-04-01 06:36:22 +02:00
|
|
|
TextureCache& texture_cache;
|
|
|
|
BufferCache& buffer_cache;
|
|
|
|
VKScheduler& scheduler;
|
|
|
|
VKUpdateDescriptorQueue& update_descriptor_queue;
|
2021-04-24 23:27:25 +02:00
|
|
|
|
2021-04-25 06:04:49 +02:00
|
|
|
void (*configure_func)(GraphicsPipeline*, bool){};
|
2021-04-24 23:28:02 +02:00
|
|
|
|
2021-04-24 23:27:25 +02:00
|
|
|
std::vector<GraphicsPipelineCacheKey> transition_keys;
|
|
|
|
std::vector<GraphicsPipeline*> transitions;
|
2021-03-19 23:28:31 +01:00
|
|
|
|
|
|
|
std::array<vk::ShaderModule, NUM_STAGES> spv_modules;
|
2021-05-30 07:57:42 +02:00
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
std::array<Shader::Info, NUM_STAGES> stage_infos;
|
2021-06-02 07:15:07 +02:00
|
|
|
std::array<u32, 5> enabled_uniform_buffer_masks{};
|
|
|
|
VideoCommon::UniformBufferSizes uniform_buffer_sizes{};
|
2021-05-30 07:57:42 +02:00
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
vk::DescriptorSetLayout descriptor_set_layout;
|
|
|
|
DescriptorAllocator descriptor_allocator;
|
|
|
|
vk::PipelineLayout pipeline_layout;
|
|
|
|
vk::DescriptorUpdateTemplateKHR descriptor_update_template;
|
|
|
|
vk::Pipeline pipeline;
|
2021-04-04 02:41:49 +02:00
|
|
|
|
|
|
|
std::condition_variable build_condvar;
|
|
|
|
std::mutex build_mutex;
|
|
|
|
std::atomic_bool is_built{false};
|
2021-06-17 02:14:57 +02:00
|
|
|
bool uses_push_descriptor{false};
|
2021-03-19 23:28:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Vulkan
|