2019-09-23 20:02:02 +02:00
|
|
|
// Copyright 2019 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-02-29 07:49:51 +01:00
|
|
|
#include <array>
|
2019-11-27 11:51:13 +01:00
|
|
|
#include <optional>
|
2020-02-29 07:49:51 +01:00
|
|
|
#include <type_traits>
|
2019-09-23 20:02:02 +02:00
|
|
|
#include <unordered_map>
|
2020-02-29 07:49:51 +01:00
|
|
|
#include <utility>
|
|
|
|
|
2019-09-23 20:02:02 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/hash.h"
|
|
|
|
#include "video_core/engines/const_buffer_engine_interface.h"
|
2020-02-29 07:49:51 +01:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-11-18 22:35:21 +01:00
|
|
|
#include "video_core/engines/shader_type.h"
|
2020-01-03 21:16:29 +01:00
|
|
|
#include "video_core/guest_driver.h"
|
2019-09-23 20:02:02 +02:00
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
2020-06-05 04:03:49 +02:00
|
|
|
struct SeparateSamplerKey {
|
|
|
|
std::pair<u32, u32> buffers;
|
|
|
|
std::pair<u32, u32> offsets;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace VideoCommon::Shader
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct hash<VideoCommon::Shader::SeparateSamplerKey> {
|
|
|
|
std::size_t operator()(const VideoCommon::Shader::SeparateSamplerKey& key) const noexcept {
|
|
|
|
return std::hash<u32>{}(key.buffers.first ^ key.buffers.second ^ key.offsets.first ^
|
|
|
|
key.offsets.second);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
|
|
|
struct equal_to<VideoCommon::Shader::SeparateSamplerKey> {
|
|
|
|
bool operator()(const VideoCommon::Shader::SeparateSamplerKey& lhs,
|
|
|
|
const VideoCommon::Shader::SeparateSamplerKey& rhs) const noexcept {
|
|
|
|
return lhs.buffers == rhs.buffers && lhs.offsets == rhs.offsets;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace VideoCommon::Shader {
|
|
|
|
|
2019-09-25 15:53:18 +02:00
|
|
|
using KeyMap = std::unordered_map<std::pair<u32, u32>, u32, Common::PairHash>;
|
|
|
|
using BoundSamplerMap = std::unordered_map<u32, Tegra::Engines::SamplerDescriptor>;
|
2020-06-05 04:03:49 +02:00
|
|
|
using SeparateSamplerMap =
|
|
|
|
std::unordered_map<SeparateSamplerKey, Tegra::Engines::SamplerDescriptor>;
|
2019-09-25 15:53:18 +02:00
|
|
|
using BindlessSamplerMap =
|
|
|
|
std::unordered_map<std::pair<u32, u32>, Tegra::Engines::SamplerDescriptor, Common::PairHash>;
|
|
|
|
|
2020-02-29 07:49:51 +01:00
|
|
|
struct GraphicsInfo {
|
2020-03-02 05:54:00 +01:00
|
|
|
using Maxwell = Tegra::Engines::Maxwell3D::Regs;
|
|
|
|
|
|
|
|
std::array<Maxwell::TransformFeedbackLayout, Maxwell::NumTransformFeedbackBuffers>
|
|
|
|
tfb_layouts{};
|
|
|
|
std::array<std::array<u8, 128>, Maxwell::NumTransformFeedbackBuffers> tfb_varying_locs{};
|
|
|
|
Maxwell::PrimitiveTopology primitive_topology{};
|
|
|
|
Maxwell::TessellationPrimitive tessellation_primitive{};
|
|
|
|
Maxwell::TessellationSpacing tessellation_spacing{};
|
|
|
|
bool tfb_enabled = false;
|
2020-02-29 08:03:22 +01:00
|
|
|
bool tessellation_clockwise = false;
|
2020-02-29 07:49:51 +01:00
|
|
|
};
|
2020-02-29 08:03:22 +01:00
|
|
|
static_assert(std::is_trivially_copyable_v<GraphicsInfo> &&
|
|
|
|
std::is_standard_layout_v<GraphicsInfo>);
|
2020-02-29 07:49:51 +01:00
|
|
|
|
|
|
|
struct ComputeInfo {
|
|
|
|
std::array<u32, 3> workgroup_size{};
|
|
|
|
u32 shared_memory_size_in_words = 0;
|
|
|
|
u32 local_memory_size_in_words = 0;
|
|
|
|
};
|
2020-02-29 08:03:22 +01:00
|
|
|
static_assert(std::is_trivially_copyable_v<ComputeInfo> && std::is_standard_layout_v<ComputeInfo>);
|
2020-02-29 07:49:51 +01:00
|
|
|
|
|
|
|
struct SerializedRegistryInfo {
|
|
|
|
VideoCore::GuestDriverProfile guest_driver_profile;
|
|
|
|
u32 bound_buffer = 0;
|
|
|
|
GraphicsInfo graphics;
|
|
|
|
ComputeInfo compute;
|
|
|
|
};
|
|
|
|
|
2019-10-17 16:35:16 +02:00
|
|
|
/**
|
2020-02-29 00:53:10 +01:00
|
|
|
* The Registry is a class use to interface the 3D and compute engines with the shader compiler.
|
|
|
|
* With it, the shader can obtain required data from GPU state and store it for disk shader
|
|
|
|
* compilation.
|
2019-11-18 22:35:21 +01:00
|
|
|
*/
|
2020-02-29 00:53:10 +01:00
|
|
|
class Registry {
|
2019-09-23 20:02:02 +02:00
|
|
|
public:
|
2020-02-29 07:49:51 +01:00
|
|
|
explicit Registry(Tegra::Engines::ShaderType shader_stage, const SerializedRegistryInfo& info);
|
2019-09-23 20:02:02 +02:00
|
|
|
|
2020-02-29 00:53:10 +01:00
|
|
|
explicit Registry(Tegra::Engines::ShaderType shader_stage,
|
2020-09-23 21:10:25 +02:00
|
|
|
Tegra::Engines::ConstBufferEngineInterface& engine_);
|
2019-09-23 20:02:02 +02:00
|
|
|
|
2020-02-29 00:53:10 +01:00
|
|
|
~Registry();
|
2019-10-17 16:35:16 +02:00
|
|
|
|
2020-02-29 00:53:10 +01:00
|
|
|
/// Retrieves a key from the registry, if it's registered, it will give the registered value, if
|
2019-09-26 00:19:41 +02:00
|
|
|
/// not it will obtain it from maxwell3d and register it.
|
2019-09-23 20:02:02 +02:00
|
|
|
std::optional<u32> ObtainKey(u32 buffer, u32 offset);
|
|
|
|
|
2019-09-25 15:53:18 +02:00
|
|
|
std::optional<Tegra::Engines::SamplerDescriptor> ObtainBoundSampler(u32 offset);
|
|
|
|
|
2020-06-05 04:03:49 +02:00
|
|
|
std::optional<Tegra::Engines::SamplerDescriptor> ObtainSeparateSampler(
|
|
|
|
std::pair<u32, u32> buffers, std::pair<u32, u32> offsets);
|
|
|
|
|
2019-09-25 15:53:18 +02:00
|
|
|
std::optional<Tegra::Engines::SamplerDescriptor> ObtainBindlessSampler(u32 buffer, u32 offset);
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Inserts a key.
|
2019-09-23 20:02:02 +02:00
|
|
|
void InsertKey(u32 buffer, u32 offset, u32 value);
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Inserts a bound sampler key.
|
2019-09-25 15:53:18 +02:00
|
|
|
void InsertBoundSampler(u32 offset, Tegra::Engines::SamplerDescriptor sampler);
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Inserts a bindless sampler key.
|
2019-09-25 15:53:18 +02:00
|
|
|
void InsertBindlessSampler(u32 buffer, u32 offset, Tegra::Engines::SamplerDescriptor sampler);
|
|
|
|
|
2020-02-29 00:53:10 +01:00
|
|
|
/// Checks keys and samplers against engine's current const buffers.
|
|
|
|
/// Returns true if they are the same value, false otherwise.
|
2019-09-26 00:19:41 +02:00
|
|
|
bool IsConsistent() const;
|
2019-09-23 20:02:02 +02:00
|
|
|
|
2020-02-29 00:53:10 +01:00
|
|
|
/// Returns true if the keys are equal to the other ones in the registry.
|
|
|
|
bool HasEqualKeys(const Registry& rhs) const;
|
2019-09-26 05:23:08 +02:00
|
|
|
|
2020-03-02 05:08:10 +01:00
|
|
|
/// Returns graphics information from this shader
|
|
|
|
const GraphicsInfo& GetGraphicsInfo() const;
|
|
|
|
|
|
|
|
/// Returns compute information from this shader
|
|
|
|
const ComputeInfo& GetComputeInfo() const;
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Gives an getter to the const buffer keys in the database.
|
|
|
|
const KeyMap& GetKeys() const {
|
|
|
|
return keys;
|
2019-09-25 15:53:18 +02:00
|
|
|
}
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Gets samplers database.
|
|
|
|
const BoundSamplerMap& GetBoundSamplers() const {
|
|
|
|
return bound_samplers;
|
2019-09-25 15:53:18 +02:00
|
|
|
}
|
|
|
|
|
2019-09-26 00:19:41 +02:00
|
|
|
/// Gets bindless samplers database.
|
|
|
|
const BindlessSamplerMap& GetBindlessSamplers() const {
|
|
|
|
return bindless_samplers;
|
2019-09-25 15:53:18 +02:00
|
|
|
}
|
2019-09-23 20:02:02 +02:00
|
|
|
|
2020-01-24 15:44:34 +01:00
|
|
|
/// Gets bound buffer used on this shader
|
2020-01-03 23:15:24 +01:00
|
|
|
u32 GetBoundBuffer() const {
|
|
|
|
return bound_buffer;
|
|
|
|
}
|
|
|
|
|
2020-01-24 15:44:34 +01:00
|
|
|
/// Obtains access to the guest driver's profile.
|
2020-02-26 20:13:47 +01:00
|
|
|
VideoCore::GuestDriverProfile& AccessGuestDriverProfile() {
|
|
|
|
return engine ? engine->AccessGuestDriverProfile() : stored_guest_driver_profile;
|
2020-01-03 21:16:29 +01:00
|
|
|
}
|
|
|
|
|
2019-09-23 20:02:02 +02:00
|
|
|
private:
|
2019-09-26 00:19:41 +02:00
|
|
|
const Tegra::Engines::ShaderType stage;
|
2020-02-26 20:13:47 +01:00
|
|
|
VideoCore::GuestDriverProfile stored_guest_driver_profile;
|
2019-09-26 00:19:41 +02:00
|
|
|
Tegra::Engines::ConstBufferEngineInterface* engine = nullptr;
|
|
|
|
KeyMap keys;
|
|
|
|
BoundSamplerMap bound_samplers;
|
2020-06-05 04:03:49 +02:00
|
|
|
SeparateSamplerMap separate_samplers;
|
2019-09-26 00:19:41 +02:00
|
|
|
BindlessSamplerMap bindless_samplers;
|
2020-02-29 07:49:51 +01:00
|
|
|
u32 bound_buffer;
|
|
|
|
GraphicsInfo graphics_info;
|
|
|
|
ComputeInfo compute_info;
|
2019-09-23 20:02:02 +02:00
|
|
|
};
|
2019-09-26 00:19:41 +02:00
|
|
|
|
2019-09-23 20:02:02 +02:00
|
|
|
} // namespace VideoCommon::Shader
|