2020-01-07 01:18:38 +01:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
#include <array>
|
|
|
|
#include <cstddef>
|
2020-01-07 01:55:06 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <utility>
|
2020-01-07 01:18:38 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2020-01-07 01:29:13 +01:00
|
|
|
#include <boost/functional/hash.hpp>
|
|
|
|
|
2020-01-07 01:18:38 +01:00
|
|
|
#include "common/common_types.h"
|
2020-01-07 01:55:06 +01:00
|
|
|
#include "video_core/engines/const_buffer_engine_interface.h"
|
2020-01-07 01:25:14 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2020-01-07 01:29:13 +01:00
|
|
|
#include "video_core/renderer_vulkan/fixed_pipeline_state.h"
|
2020-01-07 01:55:06 +01:00
|
|
|
#include "video_core/renderer_vulkan/vk_graphics_pipeline.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_renderpass_cache.h"
|
2020-01-07 01:18:38 +01:00
|
|
|
#include "video_core/renderer_vulkan/vk_shader_decompiler.h"
|
2020-03-27 05:33:21 +01:00
|
|
|
#include "video_core/renderer_vulkan/wrapper.h"
|
2020-04-24 06:44:14 +02:00
|
|
|
#include "video_core/shader/memory_util.h"
|
2020-02-29 00:53:10 +01:00
|
|
|
#include "video_core/shader/registry.h"
|
2020-01-07 01:18:38 +01:00
|
|
|
#include "video_core/shader/shader_ir.h"
|
2020-05-23 02:01:36 +02:00
|
|
|
#include "video_core/shader_cache.h"
|
2020-01-07 01:55:06 +01:00
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
2020-01-07 01:18:38 +01:00
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-01-07 01:55:06 +01:00
|
|
|
class RasterizerVulkan;
|
|
|
|
class VKComputePipeline;
|
|
|
|
class VKDescriptorPool;
|
2020-01-07 01:18:38 +01:00
|
|
|
class VKDevice;
|
2020-01-07 01:55:06 +01:00
|
|
|
class VKFence;
|
|
|
|
class VKScheduler;
|
|
|
|
class VKUpdateDescriptorQueue;
|
2020-01-07 01:18:38 +01:00
|
|
|
|
2020-01-07 01:29:13 +01:00
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
|
|
|
|
|
|
struct GraphicsPipelineCacheKey {
|
|
|
|
RenderPassParams renderpass_params;
|
2020-06-22 00:30:23 +02:00
|
|
|
u32 padding;
|
2020-04-23 01:52:29 +02:00
|
|
|
std::array<GPUVAddr, Maxwell::MaxShaderProgram> shaders;
|
2020-06-22 00:30:23 +02:00
|
|
|
FixedPipelineState fixed_state;
|
2020-01-07 01:29:13 +01:00
|
|
|
|
2020-04-23 01:52:29 +02:00
|
|
|
std::size_t Hash() const noexcept;
|
|
|
|
|
|
|
|
bool operator==(const GraphicsPipelineCacheKey& rhs) const noexcept;
|
2020-01-07 01:29:13 +01:00
|
|
|
|
2020-04-23 01:52:29 +02:00
|
|
|
bool operator!=(const GraphicsPipelineCacheKey& rhs) const noexcept {
|
|
|
|
return !operator==(rhs);
|
2020-01-07 01:29:13 +01:00
|
|
|
}
|
2020-06-23 00:07:04 +02:00
|
|
|
|
|
|
|
std::size_t Size() const noexcept {
|
|
|
|
return sizeof(renderpass_params) + sizeof(padding) + sizeof(shaders) + fixed_state.Size();
|
|
|
|
}
|
2020-01-07 01:29:13 +01:00
|
|
|
};
|
2020-04-23 01:52:29 +02:00
|
|
|
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>);
|
2020-01-07 01:29:13 +01:00
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
struct ComputePipelineCacheKey {
|
2020-04-23 01:52:29 +02:00
|
|
|
GPUVAddr shader;
|
|
|
|
u32 shared_memory_size;
|
|
|
|
std::array<u32, 3> workgroup_size;
|
|
|
|
|
|
|
|
std::size_t Hash() const noexcept;
|
|
|
|
|
|
|
|
bool operator==(const ComputePipelineCacheKey& rhs) const noexcept;
|
2020-01-07 01:25:14 +01:00
|
|
|
|
2020-04-23 01:52:29 +02:00
|
|
|
bool operator!=(const ComputePipelineCacheKey& rhs) const noexcept {
|
|
|
|
return !operator==(rhs);
|
2020-01-07 01:25:14 +01:00
|
|
|
}
|
|
|
|
};
|
2020-04-23 01:52:29 +02:00
|
|
|
static_assert(std::has_unique_object_representations_v<ComputePipelineCacheKey>);
|
|
|
|
static_assert(std::is_trivially_copyable_v<ComputePipelineCacheKey>);
|
|
|
|
static_assert(std::is_trivially_constructible_v<ComputePipelineCacheKey>);
|
2020-01-07 01:25:14 +01:00
|
|
|
|
|
|
|
} // namespace Vulkan
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
2020-01-07 01:29:13 +01:00
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::GraphicsPipelineCacheKey> {
|
|
|
|
std::size_t operator()(const Vulkan::GraphicsPipelineCacheKey& k) const noexcept {
|
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::ComputePipelineCacheKey> {
|
|
|
|
std::size_t operator()(const Vulkan::ComputePipelineCacheKey& k) const noexcept {
|
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2020-05-23 02:01:36 +02:00
|
|
|
class Shader {
|
2020-01-07 01:55:06 +01:00
|
|
|
public:
|
2020-05-23 02:01:36 +02:00
|
|
|
explicit Shader(Core::System& system, Tegra::Engines::ShaderType stage, GPUVAddr gpu_addr,
|
|
|
|
VideoCommon::Shader::ProgramCode program_code, u32 main_offset);
|
|
|
|
~Shader();
|
2020-01-07 01:55:06 +01:00
|
|
|
|
|
|
|
GPUVAddr GetGpuAddr() const {
|
|
|
|
return gpu_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VideoCommon::Shader::ShaderIR& GetIR() {
|
|
|
|
return shader_ir;
|
|
|
|
}
|
|
|
|
|
2020-03-03 01:36:25 +01:00
|
|
|
const VideoCommon::Shader::Registry& GetRegistry() const {
|
|
|
|
return registry;
|
|
|
|
}
|
|
|
|
|
2020-01-07 01:55:06 +01:00
|
|
|
const VideoCommon::Shader::ShaderIR& GetIR() const {
|
|
|
|
return shader_ir;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ShaderEntries& GetEntries() const {
|
|
|
|
return entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static Tegra::Engines::ConstBufferEngineInterface& GetEngine(Core::System& system,
|
|
|
|
Tegra::Engines::ShaderType stage);
|
|
|
|
|
|
|
|
GPUVAddr gpu_addr{};
|
2020-04-24 06:44:14 +02:00
|
|
|
VideoCommon::Shader::ProgramCode program_code;
|
2020-02-29 00:53:10 +01:00
|
|
|
VideoCommon::Shader::Registry registry;
|
2020-01-07 01:55:06 +01:00
|
|
|
VideoCommon::Shader::ShaderIR shader_ir;
|
|
|
|
ShaderEntries entries;
|
|
|
|
};
|
|
|
|
|
2020-05-23 02:01:36 +02:00
|
|
|
class VKPipelineCache final : public VideoCommon::ShaderCache<Shader> {
|
2020-01-07 01:55:06 +01:00
|
|
|
public:
|
|
|
|
explicit VKPipelineCache(Core::System& system, RasterizerVulkan& rasterizer,
|
|
|
|
const VKDevice& device, VKScheduler& scheduler,
|
|
|
|
VKDescriptorPool& descriptor_pool,
|
2020-02-23 07:51:37 +01:00
|
|
|
VKUpdateDescriptorQueue& update_descriptor_queue,
|
|
|
|
VKRenderPassCache& renderpass_cache);
|
2020-05-23 02:01:36 +02:00
|
|
|
~VKPipelineCache() override;
|
2020-01-07 01:55:06 +01:00
|
|
|
|
2020-05-23 02:01:36 +02:00
|
|
|
std::array<Shader*, Maxwell::MaxShaderProgram> GetShaders();
|
2020-01-07 01:55:06 +01:00
|
|
|
|
|
|
|
VKGraphicsPipeline& GetGraphicsPipeline(const GraphicsPipelineCacheKey& key);
|
|
|
|
|
|
|
|
VKComputePipeline& GetComputePipeline(const ComputePipelineCacheKey& key);
|
|
|
|
|
|
|
|
protected:
|
2020-05-23 02:01:36 +02:00
|
|
|
void OnShaderRemoval(Shader* shader) final;
|
2020-01-07 01:55:06 +01:00
|
|
|
|
|
|
|
private:
|
2020-03-27 05:33:21 +01:00
|
|
|
std::pair<SPIRVProgram, std::vector<VkDescriptorSetLayoutBinding>> DecompileShaders(
|
2020-01-07 01:55:06 +01:00
|
|
|
const GraphicsPipelineCacheKey& key);
|
|
|
|
|
|
|
|
Core::System& system;
|
|
|
|
const VKDevice& device;
|
|
|
|
VKScheduler& scheduler;
|
|
|
|
VKDescriptorPool& descriptor_pool;
|
|
|
|
VKUpdateDescriptorQueue& update_descriptor_queue;
|
2020-02-23 07:51:37 +01:00
|
|
|
VKRenderPassCache& renderpass_cache;
|
2020-01-07 01:55:06 +01:00
|
|
|
|
2020-05-23 02:01:36 +02:00
|
|
|
std::unique_ptr<Shader> null_shader;
|
|
|
|
std::unique_ptr<Shader> null_kernel;
|
2020-04-16 19:50:12 +02:00
|
|
|
|
2020-05-23 02:01:36 +02:00
|
|
|
std::array<Shader*, Maxwell::MaxShaderProgram> last_shaders{};
|
2020-01-07 01:55:06 +01:00
|
|
|
|
|
|
|
GraphicsPipelineCacheKey last_graphics_key;
|
|
|
|
VKGraphicsPipeline* last_graphics_pipeline = nullptr;
|
|
|
|
|
|
|
|
std::unordered_map<GraphicsPipelineCacheKey, std::unique_ptr<VKGraphicsPipeline>>
|
|
|
|
graphics_cache;
|
|
|
|
std::unordered_map<ComputePipelineCacheKey, std::unique_ptr<VKComputePipeline>> compute_cache;
|
|
|
|
};
|
2020-01-07 01:25:14 +01:00
|
|
|
|
2020-01-07 01:18:38 +01:00
|
|
|
void FillDescriptorUpdateTemplateEntries(
|
2020-02-23 06:35:16 +01:00
|
|
|
const ShaderEntries& entries, u32& binding, u32& offset,
|
2020-03-27 05:33:21 +01:00
|
|
|
std::vector<VkDescriptorUpdateTemplateEntryKHR>& template_entries);
|
2020-01-07 01:18:38 +01:00
|
|
|
|
|
|
|
} // namespace Vulkan
|