summaryrefslogtreecommitdiff
path: root/src/video_core/shader/shader.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2015-08-16 13:18:56 +0200
committerGravatar Tony Wasserka2015-08-16 13:18:56 +0200
commit7312894a6a1a1600629f2eaec8843508a2fd3578 (patch)
tree4f67fb221da50ada7a62efc45788d16950ef16f6 /src/video_core/shader/shader.cpp
parentMerge pull request #1033 from bbarenblat/master (diff)
parentcitra-qt/VertexShader: Minor UI improvements. (diff)
downloadyuzu-7312894a6a1a1600629f2eaec8843508a2fd3578.tar.gz
yuzu-7312894a6a1a1600629f2eaec8843508a2fd3578.tar.xz
yuzu-7312894a6a1a1600629f2eaec8843508a2fd3578.zip
Merge pull request #933 from neobrain/shader_debugger
Shader debugger improvements
Diffstat (limited to 'src/video_core/shader/shader.cpp')
-rw-r--r--src/video_core/shader/shader.cpp55
1 files changed, 45 insertions, 10 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp
index 6a27a8015..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];
@@ -96,12 +99,6 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes)
96 RunInterpreter(state); 99 RunInterpreter(state);
97#endif // ARCHITECTURE_x86_64 100#endif // ARCHITECTURE_x86_64
98 101
99#if PICA_DUMP_SHADERS
100 DebugUtils::DumpShader(setup.program_code.data(), state.debug.max_offset, setup.swizzle_data.data(),
101 state.debug.max_opdesc_id, config.main_offset,
102 g_state.regs.vs_output_attributes); // TODO: Don't hardcode VS here
103#endif
104
105 // Setup output data 102 // Setup output data
106 OutputVertex ret; 103 OutputVertex ret;
107 // TODO(neobrain): Under some circumstances, up to 16 attributes may be output. We need to 104 // TODO(neobrain): Under some circumstances, up to 16 attributes may be output. We need to
@@ -132,14 +129,52 @@ OutputVertex Run(UnitState& state, const InputVertex& input, int num_attributes)
132 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f)); 129 std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f));
133 } 130 }
134 131
135 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)",
136 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(),
137 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(),
138 ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32()); 136 ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32());
139 137
140 return ret; 138 return ret;
141} 139}
142 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
143} // namespace Shader 178} // namespace Shader
144 179
145} // namespace Pica 180} // namespace Pica