summaryrefslogtreecommitdiff
path: root/src/video_core/shader/shader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/shader/shader.cpp')
-rw-r--r--src/video_core/shader/shader.cpp49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp
index 2692b91e4..4e9836c80 100644
--- a/src/video_core/shader/shader.cpp
+++ b/src/video_core/shader/shader.cpp
@@ -5,6 +5,8 @@
5#include <memory> 5#include <memory>
6#include <unordered_map> 6#include <unordered_map>
7 7
8#include <boost/range/algorithm/fill.hpp>
9
8#include "common/hash.h" 10#include "common/hash.h"
9#include "common/make_unique.h" 11#include "common/make_unique.h"
10#include "common/profiler.h" 12#include "common/profiler.h"
@@ -30,7 +32,7 @@ static JitCompiler jit;
30static CompiledShader* jit_shader; 32static CompiledShader* jit_shader;
31#endif // ARCHITECTURE_x86_64 33#endif // ARCHITECTURE_x86_64
32 34
33void Setup(UnitState& state) { 35void Setup(UnitState<false>& state) {
34#ifdef ARCHITECTURE_x86_64 36#ifdef ARCHITECTURE_x86_64
35 if (VideoCore::g_shader_jit_enabled) { 37 if (VideoCore::g_shader_jit_enabled) {
36 u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ 38 u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^
@@ -54,9 +56,8 @@ void Shutdown() {
54 56
55static Common::Profiling::TimingCategory shader_category("Vertex Shader"); 57static Common::Profiling::TimingCategory shader_category("Vertex Shader");
56 58
57OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes) { 59OutputVertex Run(UnitState<false>& state, const InputVertex& input, int num_attributes) {
58 auto& config = g_state.regs.vs; 60 auto& config = g_state.regs.vs;
59 auto& setup = g_state.vs;
60 61
61 Common::Profiling::ScopeTimer timer(shader_category); 62 Common::Profiling::ScopeTimer timer(shader_category);
62 63
@@ -67,6 +68,8 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes)
67 // Setup input register table 68 // Setup input register table
68 const auto& attribute_register_map = config.input_register_map; 69 const auto& attribute_register_map = config.input_register_map;
69 70
71 // TODO: Instead of this cumbersome logic, just load the input data directly like
72 // for (int attr = 0; attr < num_attributes; ++attr) { input_attr[0] = state.registers.input[attribute_register_map.attribute0_register]; }
70 if (num_attributes > 0) state.registers.input[attribute_register_map.attribute0_register] = input.attr[0]; 73 if (num_attributes > 0) state.registers.input[attribute_register_map.attribute0_register] = input.attr[0];
71 if (num_attributes > 1) state.registers.input[attribute_register_map.attribute1_register] = input.attr[1]; 74 if (num_attributes > 1) state.registers.input[attribute_register_map.attribute1_register] = input.attr[1];
72 if (num_attributes > 2) state.registers.input[attribute_register_map.attribute2_register] = input.attr[2]; 75 if (num_attributes > 2) state.registers.input[attribute_register_map.attribute2_register] = input.attr[2];
@@ -126,14 +129,52 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes)
126 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f)); 129 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f));
127 } 130 }
128 131
129 LOG_TRACE(Render_Software, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)", 132 LOG_TRACE(Render_Software, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), quat (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)",
130 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(), 133 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),
134 ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(), ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(),
131 ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(), 135 ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(),
132 ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32()); 136 ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32());
133 137
134 return ret; 138 return ret;
135} 139}
136 140
141DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const State::ShaderSetup& setup) {
142 UnitState<true> state;
143
144 const auto& shader_memory = setup.program_code;
145 state.program_counter = config.main_offset;
146 state.debug.max_offset = 0;
147 state.debug.max_opdesc_id = 0;
148
149 // Setup input register table
150 const auto& attribute_register_map = config.input_register_map;
151 float24 dummy_register;
152 boost::fill(state.registers.input, &dummy_register);
153
154 if (num_attributes > 0) state.registers.input[attribute_register_map.attribute0_register] = &input.attr[0].x;
155 if (num_attributes > 1) state.registers.input[attribute_register_map.attribute1_register] = &input.attr[1].x;
156 if (num_attributes > 2) state.registers.input[attribute_register_map.attribute2_register] = &input.attr[2].x;
157 if (num_attributes > 3) state.registers.input[attribute_register_map.attribute3_register] = &input.attr[3].x;
158 if (num_attributes > 4) state.registers.input[attribute_register_map.attribute4_register] = &input.attr[4].x;
159 if (num_attributes > 5) state.registers.input[attribute_register_map.attribute5_register] = &input.attr[5].x;
160 if (num_attributes > 6) state.registers.input[attribute_register_map.attribute6_register] = &input.attr[6].x;
161 if (num_attributes > 7) state.registers.input[attribute_register_map.attribute7_register] = &input.attr[7].x;
162 if (num_attributes > 8) state.registers.input[attribute_register_map.attribute8_register] = &input.attr[8].x;
163 if (num_attributes > 9) state.registers.input[attribute_register_map.attribute9_register] = &input.attr[9].x;
164 if (num_attributes > 10) state.registers.input[attribute_register_map.attribute10_register] = &input.attr[10].x;
165 if (num_attributes > 11) state.registers.input[attribute_register_map.attribute11_register] = &input.attr[11].x;
166 if (num_attributes > 12) state.registers.input[attribute_register_map.attribute12_register] = &input.attr[12].x;
167 if (num_attributes > 13) state.registers.input[attribute_register_map.attribute13_register] = &input.attr[13].x;
168 if (num_attributes > 14) state.registers.input[attribute_register_map.attribute14_register] = &input.attr[14].x;
169 if (num_attributes > 15) state.registers.input[attribute_register_map.attribute15_register] = &input.attr[15].x;
170
171 state.conditional_code[0] = false;
172 state.conditional_code[1] = false;
173
174 RunInterpreter(state);
175 return state.debug;
176}
177
137} // namespace Shader 178} // namespace Shader
138 179
139} // namespace Pica 180} // namespace Pica