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>
|
2021-03-23 01:03:20 +01:00
|
|
|
#include <iosfwd>
|
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>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
2021-03-19 23:28:31 +01:00
|
|
|
#include "shader_recompiler/frontend/ir/basic_block.h"
|
|
|
|
#include "shader_recompiler/frontend/ir/microinstruction.h"
|
|
|
|
#include "shader_recompiler/frontend/maxwell/control_flow.h"
|
|
|
|
#include "shader_recompiler/object_pool.h"
|
|
|
|
#include "shader_recompiler/profile.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"
|
2021-03-19 23:28:31 +01:00
|
|
|
#include "video_core/renderer_vulkan/vk_buffer_cache.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_compute_pipeline.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_graphics_pipeline.h"
|
|
|
|
#include "video_core/renderer_vulkan/vk_texture_cache.h"
|
2020-05-23 02:01:36 +02:00
|
|
|
#include "video_core/shader_cache.h"
|
2020-12-25 01:30:11 +01:00
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.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:29:13 +01:00
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
struct ComputePipelineCacheKey {
|
2021-02-17 04:59:28 +01:00
|
|
|
u128 unique_hash;
|
2020-04-23 01:52:29 +02:00
|
|
|
u32 shared_memory_size;
|
|
|
|
std::array<u32, 3> workgroup_size;
|
|
|
|
|
2021-02-17 00:52:12 +01:00
|
|
|
size_t Hash() const noexcept;
|
2020-04-23 01:52:29 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
struct GraphicsPipelineCacheKey {
|
|
|
|
std::array<u128, 6> unique_hashes;
|
|
|
|
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>);
|
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
} // namespace Vulkan
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::ComputePipelineCacheKey> {
|
2021-02-17 00:52:12 +01:00
|
|
|
size_t operator()(const Vulkan::ComputePipelineCacheKey& k) const noexcept {
|
2020-01-07 01:25:14 +01:00
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
template <>
|
|
|
|
struct hash<Vulkan::GraphicsPipelineCacheKey> {
|
|
|
|
size_t operator()(const Vulkan::GraphicsPipelineCacheKey& k) const noexcept {
|
|
|
|
return k.Hash();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-07 01:25:14 +01:00
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace Vulkan {
|
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
class ComputePipeline;
|
|
|
|
class Device;
|
2021-03-23 01:03:20 +01:00
|
|
|
class GenericEnvironment;
|
2021-03-19 23:28:31 +01:00
|
|
|
class RasterizerVulkan;
|
|
|
|
class RenderPassCache;
|
|
|
|
class VKDescriptorPool;
|
|
|
|
class VKScheduler;
|
|
|
|
class VKUpdateDescriptorQueue;
|
|
|
|
|
2021-02-17 04:59:28 +01:00
|
|
|
struct ShaderInfo {
|
|
|
|
u128 unique_hash{};
|
|
|
|
size_t size_bytes{};
|
2020-01-07 01:55:06 +01:00
|
|
|
};
|
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
struct ShaderPools {
|
|
|
|
void ReleaseContents() {
|
|
|
|
inst.ReleaseContents();
|
|
|
|
block.ReleaseContents();
|
|
|
|
flow_block.ReleaseContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
Shader::ObjectPool<Shader::IR::Inst> inst;
|
|
|
|
Shader::ObjectPool<Shader::IR::Block> block;
|
|
|
|
Shader::ObjectPool<Shader::Maxwell::Flow::Block> flow_block;
|
|
|
|
};
|
|
|
|
|
2021-02-17 04:59:28 +01:00
|
|
|
class PipelineCache final : public VideoCommon::ShaderCache<ShaderInfo> {
|
2020-01-07 01:55:06 +01:00
|
|
|
public:
|
2021-02-17 00:52:12 +01:00
|
|
|
explicit PipelineCache(RasterizerVulkan& rasterizer, Tegra::GPU& gpu,
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d,
|
|
|
|
Tegra::Engines::KeplerCompute& kepler_compute,
|
|
|
|
Tegra::MemoryManager& gpu_memory, const Device& device,
|
|
|
|
VKScheduler& scheduler, VKDescriptorPool& descriptor_pool,
|
2021-03-19 23:28:31 +01:00
|
|
|
VKUpdateDescriptorQueue& update_descriptor_queue,
|
|
|
|
RenderPassCache& render_pass_cache, BufferCache& buffer_cache,
|
|
|
|
TextureCache& texture_cache);
|
2021-02-17 00:52:12 +01:00
|
|
|
~PipelineCache() override;
|
2020-01-07 01:55:06 +01:00
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
[[nodiscard]] GraphicsPipeline* CurrentGraphicsPipeline();
|
2020-07-31 23:30:05 +02:00
|
|
|
|
2021-03-19 23:28:31 +01:00
|
|
|
[[nodiscard]] ComputePipeline* CurrentComputePipeline();
|
2020-01-07 01:55:06 +01:00
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
|
|
|
const VideoCore::DiskResourceLoadCallback& callback);
|
|
|
|
|
2020-01-07 01:55:06 +01:00
|
|
|
private:
|
2021-03-19 23:28:31 +01:00
|
|
|
bool RefreshStages();
|
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
const ShaderInfo* MakeShaderInfo(GenericEnvironment& env, VAddr cpu_addr);
|
2021-03-19 23:28:31 +01:00
|
|
|
|
|
|
|
GraphicsPipeline CreateGraphicsPipeline();
|
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
GraphicsPipeline CreateGraphicsPipeline(ShaderPools& pools, const GraphicsPipelineCacheKey& key,
|
|
|
|
std::span<Shader::Environment* const> envs);
|
2021-02-17 04:59:28 +01:00
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
ComputePipeline CreateComputePipeline(const ComputePipelineCacheKey& key,
|
|
|
|
const ShaderInfo* shader);
|
2021-02-17 04:59:28 +01:00
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
ComputePipeline CreateComputePipeline(ShaderPools& pools, const ComputePipelineCacheKey& key,
|
|
|
|
Shader::Environment& env) const;
|
2021-02-17 04:59:28 +01:00
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
Tegra::GPU& gpu;
|
|
|
|
Tegra::Engines::Maxwell3D& maxwell3d;
|
|
|
|
Tegra::Engines::KeplerCompute& kepler_compute;
|
|
|
|
Tegra::MemoryManager& gpu_memory;
|
|
|
|
|
2020-12-26 05:10:53 +01:00
|
|
|
const Device& device;
|
2020-01-07 01:55:06 +01:00
|
|
|
VKScheduler& scheduler;
|
|
|
|
VKDescriptorPool& descriptor_pool;
|
|
|
|
VKUpdateDescriptorQueue& update_descriptor_queue;
|
2021-03-19 23:28:31 +01:00
|
|
|
RenderPassCache& render_pass_cache;
|
|
|
|
BufferCache& buffer_cache;
|
|
|
|
TextureCache& texture_cache;
|
|
|
|
|
|
|
|
GraphicsPipelineCacheKey graphics_key{};
|
2020-01-07 01:55:06 +01:00
|
|
|
|
2021-02-17 04:59:28 +01:00
|
|
|
std::unordered_map<ComputePipelineCacheKey, ComputePipeline> compute_cache;
|
2021-03-19 23:28:31 +01:00
|
|
|
std::unordered_map<GraphicsPipelineCacheKey, GraphicsPipeline> graphics_cache;
|
|
|
|
|
2021-03-23 01:03:20 +01:00
|
|
|
ShaderPools main_pools;
|
2021-03-19 23:28:31 +01:00
|
|
|
|
|
|
|
Shader::Profile profile;
|
2021-03-23 01:03:20 +01:00
|
|
|
std::string pipeline_cache_filename;
|
2020-01-07 01:55:06 +01:00
|
|
|
};
|
2020-01-07 01:25:14 +01:00
|
|
|
|
2020-01-07 01:18:38 +01:00
|
|
|
} // namespace Vulkan
|