summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2016-12-18 17:25:03 -0800
committerGravatar Yuri Kunde Schlesner2017-01-29 21:31:37 -0800
commit335df895b9f9e9760ed5cd0d6dfaea8befb94dac (patch)
tree6cd8e76d529d5b4af5f87ef63f617941ced77f3e /src
parentVideoCore: Use correct register for immediate mode attribute count (diff)
downloadyuzu-335df895b9f9e9760ed5cd0d6dfaea8befb94dac.tar.gz
yuzu-335df895b9f9e9760ed5cd0d6dfaea8befb94dac.tar.xz
yuzu-335df895b9f9e9760ed5cd0d6dfaea8befb94dac.zip
VideoCore: Consistently use shader configuration to load attributes
Diffstat (limited to 'src')
-rw-r--r--src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp6
-rw-r--r--src/video_core/command_processor.cpp4
-rw-r--r--src/video_core/pica.h39
-rw-r--r--src/video_core/shader/shader.cpp11
-rw-r--r--src/video_core/shader/shader.h6
-rw-r--r--src/video_core/shader/shader_interpreter.cpp4
-rw-r--r--src/video_core/shader/shader_interpreter.h3
7 files changed, 26 insertions, 47 deletions
diff --git a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp
index f37524190..489ec5f21 100644
--- a/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp
+++ b/src/citra_qt/debugger/graphics/graphics_vertex_shader.cpp
@@ -511,7 +511,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
511 auto& shader_config = Pica::g_state.regs.vs; 511 auto& shader_config = Pica::g_state.regs.vs;
512 for (auto instr : shader_setup.program_code) 512 for (auto instr : shader_setup.program_code)
513 info.code.push_back({instr}); 513 info.code.push_back({instr});
514 int num_attributes = Pica::g_state.regs.vertex_attributes.GetNumTotalAttributes(); 514 int num_attributes = shader_config.max_input_attribute_index + 1;
515 515
516 for (auto pattern : shader_setup.swizzle_data) 516 for (auto pattern : shader_setup.swizzle_data)
517 info.swizzle_info.push_back({pattern}); 517 info.swizzle_info.push_back({pattern});
@@ -522,11 +522,11 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
522 // Generate debug information 522 // Generate debug information
523 Pica::Shader::InterpreterEngine shader_engine; 523 Pica::Shader::InterpreterEngine shader_engine;
524 shader_engine.SetupBatch(shader_setup, entry_point); 524 shader_engine.SetupBatch(shader_setup, entry_point);
525 debug_data = shader_engine.ProduceDebugInfo(shader_setup, input_vertex, num_attributes); 525 debug_data = shader_engine.ProduceDebugInfo(shader_setup, input_vertex, shader_config);
526 526
527 // Reload widget state 527 // Reload widget state
528 for (int attr = 0; attr < num_attributes; ++attr) { 528 for (int attr = 0; attr < num_attributes; ++attr) {
529 unsigned source_attr = shader_config.input_register_map.GetRegisterForAttribute(attr); 529 unsigned source_attr = shader_config.GetRegisterForAttribute(attr);
530 input_data_mapping[attr]->setText(QString("-> v%1").arg(source_attr)); 530 input_data_mapping[attr]->setText(QString("-> v%1").arg(source_attr));
531 input_data_container[attr]->setVisible(true); 531 input_data_container[attr]->setVisible(true);
532 } 532 }
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 27b7a023f..fef0b4ceb 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -151,7 +151,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
151 g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, 151 g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation,
152 static_cast<void*>(&immediate_input)); 152 static_cast<void*>(&immediate_input));
153 Shader::UnitState shader_unit; 153 Shader::UnitState shader_unit;
154 shader_unit.LoadInput(immediate_input, regs.vs.max_input_attribute_index + 1); 154 shader_unit.LoadInput(regs.vs, immediate_input);
155 shader_engine->Run(g_state.vs, shader_unit); 155 shader_engine->Run(g_state.vs, shader_unit);
156 auto output_vertex = Shader::OutputVertex::FromRegisters( 156 auto output_vertex = Shader::OutputVertex::FromRegisters(
157 shader_unit.registers.output, regs, regs.vs.output_mask); 157 shader_unit.registers.output, regs, regs.vs.output_mask);
@@ -288,7 +288,7 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
288 if (g_debug_context) 288 if (g_debug_context)
289 g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation, 289 g_debug_context->OnEvent(DebugContext::Event::VertexShaderInvocation,
290 (void*)&input); 290 (void*)&input);
291 shader_unit.LoadInput(input, loader.GetNumTotalAttributes()); 291 shader_unit.LoadInput(regs.vs, input);
292 shader_engine->Run(g_state.vs, shader_unit); 292 shader_engine->Run(g_state.vs, shader_unit);
293 293
294 // Retrieve vertex from register data 294 // Retrieve vertex from register data
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index c772896e0..ac81a3d0f 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -1225,36 +1225,15 @@ struct Regs {
1225 // Offset to shader program entry point (in words) 1225 // Offset to shader program entry point (in words)
1226 BitField<0, 16, u32> main_offset; 1226 BitField<0, 16, u32> main_offset;
1227 1227
1228 union { 1228 /// Maps input attributes to registers. 4-bits per attribute, specifying a register index
1229 BitField<0, 4, u64> attribute0_register; 1229 u32 input_attribute_to_register_map_low;
1230 BitField<4, 4, u64> attribute1_register; 1230 u32 input_attribute_to_register_map_high;
1231 BitField<8, 4, u64> attribute2_register; 1231
1232 BitField<12, 4, u64> attribute3_register; 1232 unsigned int GetRegisterForAttribute(unsigned int attribute_index) const {
1233 BitField<16, 4, u64> attribute4_register; 1233 u64 map = ((u64)input_attribute_to_register_map_high << 32) |
1234 BitField<20, 4, u64> attribute5_register; 1234 (u64)input_attribute_to_register_map_low;
1235 BitField<24, 4, u64> attribute6_register; 1235 return (map >> (attribute_index * 4)) & 0b1111;
1236 BitField<28, 4, u64> attribute7_register; 1236 }
1237 BitField<32, 4, u64> attribute8_register;
1238 BitField<36, 4, u64> attribute9_register;
1239 BitField<40, 4, u64> attribute10_register;
1240 BitField<44, 4, u64> attribute11_register;
1241 BitField<48, 4, u64> attribute12_register;
1242 BitField<52, 4, u64> attribute13_register;
1243 BitField<56, 4, u64> attribute14_register;
1244 BitField<60, 4, u64> attribute15_register;
1245
1246 int GetRegisterForAttribute(int attribute_index) const {
1247 u64 fields[] = {
1248 attribute0_register, attribute1_register, attribute2_register,
1249 attribute3_register, attribute4_register, attribute5_register,
1250 attribute6_register, attribute7_register, attribute8_register,
1251 attribute9_register, attribute10_register, attribute11_register,
1252 attribute12_register, attribute13_register, attribute14_register,
1253 attribute15_register,
1254 };
1255 return (int)fields[attribute_index];
1256 }
1257 } input_register_map;
1258 1237
1259 BitField<0, 16, u32> output_mask; 1238 BitField<0, 16, u32> output_mask;
1260 1239
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp
index 971ce5b7a..dbad167e9 100644
--- a/src/video_core/shader/shader.cpp
+++ b/src/video_core/shader/shader.cpp
@@ -71,12 +71,13 @@ OutputVertex OutputVertex::FromRegisters(Math::Vec4<float24> output_regs[16], co
71 return ret; 71 return ret;
72} 72}
73 73
74void UnitState::LoadInput(const AttributeBuffer& input, int num_attributes) { 74void UnitState::LoadInput(const Regs::ShaderConfig& config, const AttributeBuffer& input) {
75 // Setup input register table 75 const unsigned max_attribute = config.max_input_attribute_index;
76 const auto& attribute_register_map = g_state.regs.vs.input_register_map;
77 76
78 for (int i = 0; i < num_attributes; i++) 77 for (unsigned attr = 0; attr <= max_attribute; ++attr) {
79 registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i]; 78 unsigned reg = config.GetRegisterForAttribute(attr);
79 registers.input[reg] = input.attr[attr];
80 }
80} 81}
81 82
82MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240)); 83MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240));
diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h
index cb38ec0a6..43a8b848c 100644
--- a/src/video_core/shader/shader.h
+++ b/src/video_core/shader/shader.h
@@ -137,10 +137,10 @@ struct UnitState {
137 /** 137 /**
138 * Loads the unit state with an input vertex. 138 * Loads the unit state with an input vertex.
139 * 139 *
140 * @param input Input vertex into the shader 140 * @param config Shader configuration registers corresponding to the unit.
141 * @param num_attributes The number of vertex shader attributes to load 141 * @param input Attribute buffer to load into the input registers.
142 */ 142 */
143 void LoadInput(const AttributeBuffer& input, int num_attributes); 143 void LoadInput(const Regs::ShaderConfig& config, const AttributeBuffer& input);
144}; 144};
145 145
146struct ShaderSetup { 146struct ShaderSetup {
diff --git a/src/video_core/shader/shader_interpreter.cpp b/src/video_core/shader/shader_interpreter.cpp
index d803aebbf..81522b8f5 100644
--- a/src/video_core/shader/shader_interpreter.cpp
+++ b/src/video_core/shader/shader_interpreter.cpp
@@ -669,13 +669,13 @@ void InterpreterEngine::Run(const ShaderSetup& setup, UnitState& state) const {
669 669
670DebugData<true> InterpreterEngine::ProduceDebugInfo(const ShaderSetup& setup, 670DebugData<true> InterpreterEngine::ProduceDebugInfo(const ShaderSetup& setup,
671 const AttributeBuffer& input, 671 const AttributeBuffer& input,
672 int num_attributes) const { 672 const Regs::ShaderConfig& config) const {
673 UnitState state; 673 UnitState state;
674 DebugData<true> debug_data; 674 DebugData<true> debug_data;
675 675
676 // Setup input register table 676 // Setup input register table
677 boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero())); 677 boost::fill(state.registers.input, Math::Vec4<float24>::AssignToAll(float24::Zero()));
678 state.LoadInput(input, num_attributes); 678 state.LoadInput(config, input);
679 RunInterpreter(setup, state, debug_data, setup.engine_data.entry_point); 679 RunInterpreter(setup, state, debug_data, setup.engine_data.entry_point);
680 return debug_data; 680 return debug_data;
681} 681}
diff --git a/src/video_core/shader/shader_interpreter.h b/src/video_core/shader/shader_interpreter.h
index 593e02157..d7a61e122 100644
--- a/src/video_core/shader/shader_interpreter.h
+++ b/src/video_core/shader/shader_interpreter.h
@@ -19,12 +19,11 @@ public:
19 /** 19 /**
20 * Produce debug information based on the given shader and input vertex 20 * Produce debug information based on the given shader and input vertex
21 * @param input Input vertex into the shader 21 * @param input Input vertex into the shader
22 * @param num_attributes The number of vertex shader attributes
23 * @param config Configuration object for the shader pipeline 22 * @param config Configuration object for the shader pipeline
24 * @return Debug information for this shader with regards to the given vertex 23 * @return Debug information for this shader with regards to the given vertex
25 */ 24 */
26 DebugData<true> ProduceDebugInfo(const ShaderSetup& setup, const AttributeBuffer& input, 25 DebugData<true> ProduceDebugInfo(const ShaderSetup& setup, const AttributeBuffer& input,
27 int num_attributes) const; 26 const Regs::ShaderConfig& config) const;
28}; 27};
29 28
30} // namespace 29} // namespace