diff options
Diffstat (limited to 'src/video_core/shader/registry.cpp')
| -rw-r--r-- | src/video_core/shader/registry.cpp | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/src/video_core/shader/registry.cpp b/src/video_core/shader/registry.cpp deleted file mode 100644 index 148d91fcb..000000000 --- a/src/video_core/shader/registry.cpp +++ /dev/null | |||
| @@ -1,181 +0,0 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <algorithm> | ||
| 6 | #include <tuple> | ||
| 7 | |||
| 8 | #include "common/assert.h" | ||
| 9 | #include "common/common_types.h" | ||
| 10 | #include "video_core/engines/kepler_compute.h" | ||
| 11 | #include "video_core/engines/maxwell_3d.h" | ||
| 12 | #include "video_core/engines/shader_type.h" | ||
| 13 | #include "video_core/shader/registry.h" | ||
| 14 | |||
| 15 | namespace VideoCommon::Shader { | ||
| 16 | |||
| 17 | using Tegra::Engines::ConstBufferEngineInterface; | ||
| 18 | using Tegra::Engines::SamplerDescriptor; | ||
| 19 | using Tegra::Engines::ShaderType; | ||
| 20 | |||
| 21 | namespace { | ||
| 22 | |||
| 23 | GraphicsInfo MakeGraphicsInfo(ShaderType shader_stage, ConstBufferEngineInterface& engine) { | ||
| 24 | if (shader_stage == ShaderType::Compute) { | ||
| 25 | return {}; | ||
| 26 | } | ||
| 27 | |||
| 28 | auto& graphics = dynamic_cast<Tegra::Engines::Maxwell3D&>(engine); | ||
| 29 | |||
| 30 | return { | ||
| 31 | .tfb_layouts = graphics.regs.tfb_layouts, | ||
| 32 | .tfb_varying_locs = graphics.regs.tfb_varying_locs, | ||
| 33 | .primitive_topology = graphics.regs.draw.topology, | ||
| 34 | .tessellation_primitive = graphics.regs.tess_mode.prim, | ||
| 35 | .tessellation_spacing = graphics.regs.tess_mode.spacing, | ||
| 36 | .tfb_enabled = graphics.regs.tfb_enabled != 0, | ||
| 37 | .tessellation_clockwise = graphics.regs.tess_mode.cw.Value() != 0, | ||
| 38 | }; | ||
| 39 | } | ||
| 40 | |||
| 41 | ComputeInfo MakeComputeInfo(ShaderType shader_stage, ConstBufferEngineInterface& engine) { | ||
| 42 | if (shader_stage != ShaderType::Compute) { | ||
| 43 | return {}; | ||
| 44 | } | ||
| 45 | |||
| 46 | auto& compute = dynamic_cast<Tegra::Engines::KeplerCompute&>(engine); | ||
| 47 | const auto& launch = compute.launch_description; | ||
| 48 | |||
| 49 | return { | ||
| 50 | .workgroup_size = {launch.block_dim_x, launch.block_dim_y, launch.block_dim_z}, | ||
| 51 | .shared_memory_size_in_words = launch.shared_alloc, | ||
| 52 | .local_memory_size_in_words = launch.local_pos_alloc, | ||
| 53 | }; | ||
| 54 | } | ||
| 55 | |||
| 56 | } // Anonymous namespace | ||
| 57 | |||
| 58 | Registry::Registry(ShaderType shader_stage, const SerializedRegistryInfo& info) | ||
| 59 | : stage{shader_stage}, stored_guest_driver_profile{info.guest_driver_profile}, | ||
| 60 | bound_buffer{info.bound_buffer}, graphics_info{info.graphics}, compute_info{info.compute} {} | ||
| 61 | |||
| 62 | Registry::Registry(ShaderType shader_stage, ConstBufferEngineInterface& engine_) | ||
| 63 | : stage{shader_stage}, engine{&engine_}, bound_buffer{engine_.GetBoundBuffer()}, | ||
| 64 | graphics_info{MakeGraphicsInfo(shader_stage, engine_)}, compute_info{MakeComputeInfo( | ||
| 65 | shader_stage, engine_)} {} | ||
| 66 | |||
| 67 | Registry::~Registry() = default; | ||
| 68 | |||
| 69 | std::optional<u32> Registry::ObtainKey(u32 buffer, u32 offset) { | ||
| 70 | const std::pair<u32, u32> key = {buffer, offset}; | ||
| 71 | const auto iter = keys.find(key); | ||
| 72 | if (iter != keys.end()) { | ||
| 73 | return iter->second; | ||
| 74 | } | ||
| 75 | if (!engine) { | ||
| 76 | return std::nullopt; | ||
| 77 | } | ||
| 78 | const u32 value = engine->AccessConstBuffer32(stage, buffer, offset); | ||
| 79 | keys.emplace(key, value); | ||
| 80 | return value; | ||
| 81 | } | ||
| 82 | |||
| 83 | std::optional<SamplerDescriptor> Registry::ObtainBoundSampler(u32 offset) { | ||
| 84 | const u32 key = offset; | ||
| 85 | const auto iter = bound_samplers.find(key); | ||
| 86 | if (iter != bound_samplers.end()) { | ||
| 87 | return iter->second; | ||
| 88 | } | ||
| 89 | if (!engine) { | ||
| 90 | return std::nullopt; | ||
| 91 | } | ||
| 92 | const SamplerDescriptor value = engine->AccessBoundSampler(stage, offset); | ||
| 93 | bound_samplers.emplace(key, value); | ||
| 94 | return value; | ||
| 95 | } | ||
| 96 | |||
| 97 | std::optional<Tegra::Engines::SamplerDescriptor> Registry::ObtainSeparateSampler( | ||
| 98 | std::pair<u32, u32> buffers, std::pair<u32, u32> offsets) { | ||
| 99 | SeparateSamplerKey key; | ||
| 100 | key.buffers = buffers; | ||
| 101 | key.offsets = offsets; | ||
| 102 | const auto iter = separate_samplers.find(key); | ||
| 103 | if (iter != separate_samplers.end()) { | ||
| 104 | return iter->second; | ||
| 105 | } | ||
| 106 | if (!engine) { | ||
| 107 | return std::nullopt; | ||
| 108 | } | ||
| 109 | |||
| 110 | const u32 handle_1 = engine->AccessConstBuffer32(stage, key.buffers.first, key.offsets.first); | ||
| 111 | const u32 handle_2 = engine->AccessConstBuffer32(stage, key.buffers.second, key.offsets.second); | ||
| 112 | const SamplerDescriptor value = engine->AccessSampler(handle_1 | handle_2); | ||
| 113 | separate_samplers.emplace(key, value); | ||
| 114 | return value; | ||
| 115 | } | ||
| 116 | |||
| 117 | std::optional<SamplerDescriptor> Registry::ObtainBindlessSampler(u32 buffer, u32 offset) { | ||
| 118 | const std::pair key = {buffer, offset}; | ||
| 119 | const auto iter = bindless_samplers.find(key); | ||
| 120 | if (iter != bindless_samplers.end()) { | ||
| 121 | return iter->second; | ||
| 122 | } | ||
| 123 | if (!engine) { | ||
| 124 | return std::nullopt; | ||
| 125 | } | ||
| 126 | const SamplerDescriptor value = engine->AccessBindlessSampler(stage, buffer, offset); | ||
| 127 | bindless_samplers.emplace(key, value); | ||
| 128 | return value; | ||
| 129 | } | ||
| 130 | |||
| 131 | void Registry::InsertKey(u32 buffer, u32 offset, u32 value) { | ||
| 132 | keys.insert_or_assign({buffer, offset}, value); | ||
| 133 | } | ||
| 134 | |||
| 135 | void Registry::InsertBoundSampler(u32 offset, SamplerDescriptor sampler) { | ||
| 136 | bound_samplers.insert_or_assign(offset, sampler); | ||
| 137 | } | ||
| 138 | |||
| 139 | void Registry::InsertBindlessSampler(u32 buffer, u32 offset, SamplerDescriptor sampler) { | ||
| 140 | bindless_samplers.insert_or_assign({buffer, offset}, sampler); | ||
| 141 | } | ||
| 142 | |||
| 143 | bool Registry::IsConsistent() const { | ||
| 144 | if (!engine) { | ||
| 145 | return true; | ||
| 146 | } | ||
| 147 | return std::all_of(keys.begin(), keys.end(), | ||
| 148 | [this](const auto& pair) { | ||
| 149 | const auto [cbuf, offset] = pair.first; | ||
| 150 | const auto value = pair.second; | ||
| 151 | return value == engine->AccessConstBuffer32(stage, cbuf, offset); | ||
| 152 | }) && | ||
| 153 | std::all_of(bound_samplers.begin(), bound_samplers.end(), | ||
| 154 | [this](const auto& sampler) { | ||
| 155 | const auto [key, value] = sampler; | ||
| 156 | return value == engine->AccessBoundSampler(stage, key); | ||
| 157 | }) && | ||
| 158 | std::all_of(bindless_samplers.begin(), bindless_samplers.end(), | ||
| 159 | [this](const auto& sampler) { | ||
| 160 | const auto [cbuf, offset] = sampler.first; | ||
| 161 | const auto value = sampler.second; | ||
| 162 | return value == engine->AccessBindlessSampler(stage, cbuf, offset); | ||
| 163 | }); | ||
| 164 | } | ||
| 165 | |||
| 166 | bool Registry::HasEqualKeys(const Registry& rhs) const { | ||
| 167 | return std::tie(keys, bound_samplers, bindless_samplers) == | ||
| 168 | std::tie(rhs.keys, rhs.bound_samplers, rhs.bindless_samplers); | ||
| 169 | } | ||
| 170 | |||
| 171 | const GraphicsInfo& Registry::GetGraphicsInfo() const { | ||
| 172 | ASSERT(stage != Tegra::Engines::ShaderType::Compute); | ||
| 173 | return graphics_info; | ||
| 174 | } | ||
| 175 | |||
| 176 | const ComputeInfo& Registry::GetComputeInfo() const { | ||
| 177 | ASSERT(stage == Tegra::Engines::ShaderType::Compute); | ||
| 178 | return compute_info; | ||
| 179 | } | ||
| 180 | |||
| 181 | } // namespace VideoCommon::Shader | ||