summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/shader_recompiler/frontend/maxwell/translate_program.cpp39
-rw-r--r--src/shader_recompiler/runtime_info.h2
-rw-r--r--src/shader_recompiler/shader_info.h3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_cache.cpp1
-rw-r--r--src/video_core/renderer_vulkan/vk_pipeline_cache.cpp1
5 files changed, 31 insertions, 15 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate_program.cpp b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
index 77efb4f57..3aee33a96 100644
--- a/src/shader_recompiler/frontend/maxwell/translate_program.cpp
+++ b/src/shader_recompiler/frontend/maxwell/translate_program.cpp
@@ -137,28 +137,35 @@ bool IsLegacyAttribute(IR::Attribute attribute) {
137} 137}
138 138
139std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings( 139std::map<IR::Attribute, IR::Attribute> GenerateLegacyToGenericMappings(
140 const VaryingState& state, std::queue<IR::Attribute> ununsed_generics) { 140 const VaryingState& state, std::queue<IR::Attribute> unused_generics,
141 const std::map<IR::Attribute, IR::Attribute>& previous_stage_mapping) {
141 std::map<IR::Attribute, IR::Attribute> mapping; 142 std::map<IR::Attribute, IR::Attribute> mapping;
143 auto update_mapping = [&mapping, &unused_generics, previous_stage_mapping](IR::Attribute attr,
144 size_t count) {
145 if (previous_stage_mapping.find(attr) != previous_stage_mapping.end()) {
146 for (size_t i = 0; i < count; ++i) {
147 mapping.insert({attr + i, previous_stage_mapping.at(attr + i)});
148 }
149 } else {
150 for (size_t i = 0; i < count; ++i) {
151 mapping.insert({attr + i, unused_generics.front() + i});
152 }
153 unused_generics.pop();
154 }
155 };
142 for (size_t index = 0; index < 4; ++index) { 156 for (size_t index = 0; index < 4; ++index) {
143 auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4; 157 auto attr = IR::Attribute::ColorFrontDiffuseR + index * 4;
144 if (state.AnyComponent(attr)) { 158 if (state.AnyComponent(attr)) {
145 for (size_t i = 0; i < 4; ++i) { 159 update_mapping(attr, 4);
146 mapping.insert({attr + i, ununsed_generics.front() + i});
147 }
148 ununsed_generics.pop();
149 } 160 }
150 } 161 }
151 if (state[IR::Attribute::FogCoordinate]) { 162 if (state[IR::Attribute::FogCoordinate]) {
152 mapping.insert({IR::Attribute::FogCoordinate, ununsed_generics.front()}); 163 update_mapping(IR::Attribute::FogCoordinate, 1);
153 ununsed_generics.pop();
154 } 164 }
155 for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) { 165 for (size_t index = 0; index < IR::NUM_FIXEDFNCTEXTURE; ++index) {
156 auto attr = IR::Attribute::FixedFncTexture0S + index * 4; 166 auto attr = IR::Attribute::FixedFncTexture0S + index * 4;
157 if (state.AnyComponent(attr)) { 167 if (state.AnyComponent(attr)) {
158 for (size_t i = 0; i < 4; ++i) { 168 update_mapping(attr, 4);
159 mapping.insert({attr + i, ununsed_generics.front() + i});
160 }
161 ununsed_generics.pop();
162 } 169 }
163 } 170 }
164 return mapping; 171 return mapping;
@@ -271,15 +278,16 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run
271 ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4); 278 ununsed_output_generics.push(IR::Attribute::Generic0X + index * 4);
272 } 279 }
273 } 280 }
274 auto mappings = GenerateLegacyToGenericMappings(stores, ununsed_output_generics); 281 program.info.legacy_stores_mapping =
282 GenerateLegacyToGenericMappings(stores, ununsed_output_generics, {});
275 for (IR::Block* const block : program.post_order_blocks) { 283 for (IR::Block* const block : program.post_order_blocks) {
276 for (IR::Inst& inst : block->Instructions()) { 284 for (IR::Inst& inst : block->Instructions()) {
277 switch (inst.GetOpcode()) { 285 switch (inst.GetOpcode()) {
278 case IR::Opcode::SetAttribute: { 286 case IR::Opcode::SetAttribute: {
279 const auto attr = inst.Arg(0).Attribute(); 287 const auto attr = inst.Arg(0).Attribute();
280 if (IsLegacyAttribute(attr)) { 288 if (IsLegacyAttribute(attr)) {
281 stores.Set(mappings[attr], true); 289 stores.Set(program.info.legacy_stores_mapping[attr], true);
282 inst.SetArg(0, Shader::IR::Value(mappings[attr])); 290 inst.SetArg(0, Shader::IR::Value(program.info.legacy_stores_mapping[attr]));
283 } 291 }
284 break; 292 break;
285 } 293 }
@@ -300,7 +308,8 @@ void ConvertLegacyToGeneric(IR::Program& program, const Shader::RuntimeInfo& run
300 ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4); 308 ununsed_input_generics.push(IR::Attribute::Generic0X + index * 4);
301 } 309 }
302 } 310 }
303 auto mappings = GenerateLegacyToGenericMappings(loads, ununsed_input_generics); 311 auto mappings = GenerateLegacyToGenericMappings(
312 loads, ununsed_input_generics, runtime_info.previous_stage_legacy_stores_mapping);
304 for (IR::Block* const block : program.post_order_blocks) { 313 for (IR::Block* const block : program.post_order_blocks) {
305 for (IR::Inst& inst : block->Instructions()) { 314 for (IR::Inst& inst : block->Instructions()) {
306 switch (inst.GetOpcode()) { 315 switch (inst.GetOpcode()) {
diff --git a/src/shader_recompiler/runtime_info.h b/src/shader_recompiler/runtime_info.h
index dcb5ab158..549b81ef7 100644
--- a/src/shader_recompiler/runtime_info.h
+++ b/src/shader_recompiler/runtime_info.h
@@ -4,6 +4,7 @@
4#pragma once 4#pragma once
5 5
6#include <array> 6#include <array>
7#include <map>
7#include <optional> 8#include <optional>
8#include <vector> 9#include <vector>
9 10
@@ -60,6 +61,7 @@ struct TransformFeedbackVarying {
60struct RuntimeInfo { 61struct RuntimeInfo {
61 std::array<AttributeType, 32> generic_input_types{}; 62 std::array<AttributeType, 32> generic_input_types{};
62 VaryingState previous_stage_stores; 63 VaryingState previous_stage_stores;
64 std::map<IR::Attribute, IR::Attribute> previous_stage_legacy_stores_mapping;
63 65
64 bool convert_depth_mode{}; 66 bool convert_depth_mode{};
65 bool force_early_z{}; 67 bool force_early_z{};
diff --git a/src/shader_recompiler/shader_info.h b/src/shader_recompiler/shader_info.h
index f5690805c..c3c586ada 100644
--- a/src/shader_recompiler/shader_info.h
+++ b/src/shader_recompiler/shader_info.h
@@ -5,6 +5,7 @@
5 5
6#include <array> 6#include <array>
7#include <bitset> 7#include <bitset>
8#include <map>
8 9
9#include "common/common_types.h" 10#include "common/common_types.h"
10#include "shader_recompiler/frontend/ir/type.h" 11#include "shader_recompiler/frontend/ir/type.h"
@@ -123,6 +124,8 @@ struct Info {
123 VaryingState stores; 124 VaryingState stores;
124 VaryingState passthrough; 125 VaryingState passthrough;
125 126
127 std::map<IR::Attribute, IR::Attribute> legacy_stores_mapping;
128
126 bool loads_indexed_attributes{}; 129 bool loads_indexed_attributes{};
127 130
128 std::array<bool, 8> stores_frag_color{}; 131 std::array<bool, 8> stores_frag_color{};
diff --git a/src/video_core/renderer_opengl/gl_shader_cache.cpp b/src/video_core/renderer_opengl/gl_shader_cache.cpp
index ddb70934c..fa05b47ff 100644
--- a/src/video_core/renderer_opengl/gl_shader_cache.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_cache.cpp
@@ -63,6 +63,7 @@ Shader::RuntimeInfo MakeRuntimeInfo(const GraphicsPipelineKey& key,
63 Shader::RuntimeInfo info; 63 Shader::RuntimeInfo info;
64 if (previous_program) { 64 if (previous_program) {
65 info.previous_stage_stores = previous_program->info.stores; 65 info.previous_stage_stores = previous_program->info.stores;
66 info.previous_stage_legacy_stores_mapping = previous_program->info.legacy_stores_mapping;
66 } else { 67 } else {
67 // Mark all stores as available for vertex shaders 68 // Mark all stores as available for vertex shaders
68 info.previous_stage_stores.mask.set(); 69 info.previous_stage_stores.mask.set();
diff --git a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
index 9708dc45e..53dda5048 100644
--- a/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
+++ b/src/video_core/renderer_vulkan/vk_pipeline_cache.cpp
@@ -131,6 +131,7 @@ Shader::RuntimeInfo MakeRuntimeInfo(std::span<const Shader::IR::Program> program
131 Shader::RuntimeInfo info; 131 Shader::RuntimeInfo info;
132 if (previous_program) { 132 if (previous_program) {
133 info.previous_stage_stores = previous_program->info.stores; 133 info.previous_stage_stores = previous_program->info.stores;
134 info.previous_stage_legacy_stores_mapping = previous_program->info.legacy_stores_mapping;
134 if (previous_program->is_geometry_passthrough) { 135 if (previous_program->is_geometry_passthrough) {
135 info.previous_stage_stores.mask |= previous_program->info.passthrough.mask; 136 info.previous_stage_stores.mask |= previous_program->info.passthrough.mask;
136 } 137 }