summaryrefslogtreecommitdiff
path: root/src/video_core/vertex_shader.cpp
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-08-14 14:30:38 +0200
committerGravatar Tony Wasserka2014-08-25 22:03:18 +0200
commitf37e39deb9abe88b4874ebc2889ed52e02ed9c13 (patch)
treebbced32a26ee671ffb69de1c42492fc13b8f6724 /src/video_core/vertex_shader.cpp
parentPica: Add debug utility functions for dumping geometry data. (diff)
downloadyuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.tar.gz
yuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.tar.xz
yuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.zip
Pica: Add debug utilities for dumping shaders.
Diffstat (limited to 'src/video_core/vertex_shader.cpp')
-rw-r--r--src/video_core/vertex_shader.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/video_core/vertex_shader.cpp b/src/video_core/vertex_shader.cpp
index 93830a96a..8df14b51f 100644
--- a/src/video_core/vertex_shader.cpp
+++ b/src/video_core/vertex_shader.cpp
@@ -4,6 +4,7 @@
4 4
5#include "pica.h" 5#include "pica.h"
6#include "vertex_shader.h" 6#include "vertex_shader.h"
7#include "debug_utils/debug_utils.h"
7#include <core/mem_map.h> 8#include <core/mem_map.h>
8#include <common/file_util.h> 9#include <common/file_util.h>
9 10
@@ -50,6 +51,11 @@ struct VertexShaderState {
50 }; 51 };
51 u32 call_stack[8]; // TODO: What is the maximal call stack depth? 52 u32 call_stack[8]; // TODO: What is the maximal call stack depth?
52 u32* call_stack_pointer; 53 u32* call_stack_pointer;
54
55 struct {
56 u32 max_offset; // maximum program counter ever reached
57 u32 max_opdesc_id; // maximum swizzle pattern index ever used
58 } debug;
53}; 59};
54 60
55static void ProcessShaderCode(VertexShaderState& state) { 61static void ProcessShaderCode(VertexShaderState& state) {
@@ -57,6 +63,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
57 bool increment_pc = true; 63 bool increment_pc = true;
58 bool exit_loop = false; 64 bool exit_loop = false;
59 const Instruction& instr = *(const Instruction*)state.program_counter; 65 const Instruction& instr = *(const Instruction*)state.program_counter;
66 state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + (state.program_counter - shader_memory));
60 67
61 const float24* src1_ = (instr.common.src1 < 0x10) ? state.input_register_table[instr.common.src1] 68 const float24* src1_ = (instr.common.src1 < 0x10) ? state.input_register_table[instr.common.src1]
62 : (instr.common.src1 < 0x20) ? &state.temporary_registers[instr.common.src1-0x10].x 69 : (instr.common.src1 < 0x20) ? &state.temporary_registers[instr.common.src1-0x10].x
@@ -88,6 +95,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
88 switch (instr.opcode) { 95 switch (instr.opcode) {
89 case Instruction::OpCode::ADD: 96 case Instruction::OpCode::ADD:
90 { 97 {
98 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
91 for (int i = 0; i < 4; ++i) { 99 for (int i = 0; i < 4; ++i) {
92 if (!swizzle.DestComponentEnabled(i)) 100 if (!swizzle.DestComponentEnabled(i))
93 continue; 101 continue;
@@ -100,6 +108,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
100 108
101 case Instruction::OpCode::MUL: 109 case Instruction::OpCode::MUL:
102 { 110 {
111 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
103 for (int i = 0; i < 4; ++i) { 112 for (int i = 0; i < 4; ++i) {
104 if (!swizzle.DestComponentEnabled(i)) 113 if (!swizzle.DestComponentEnabled(i))
105 continue; 114 continue;
@@ -113,6 +122,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
113 case Instruction::OpCode::DP3: 122 case Instruction::OpCode::DP3:
114 case Instruction::OpCode::DP4: 123 case Instruction::OpCode::DP4:
115 { 124 {
125 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
116 float24 dot = float24::FromFloat32(0.f); 126 float24 dot = float24::FromFloat32(0.f);
117 int num_components = (instr.opcode == Instruction::OpCode::DP3) ? 3 : 4; 127 int num_components = (instr.opcode == Instruction::OpCode::DP3) ? 3 : 4;
118 for (int i = 0; i < num_components; ++i) 128 for (int i = 0; i < num_components; ++i)
@@ -130,6 +140,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
130 // Reciprocal 140 // Reciprocal
131 case Instruction::OpCode::RCP: 141 case Instruction::OpCode::RCP:
132 { 142 {
143 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
133 for (int i = 0; i < 4; ++i) { 144 for (int i = 0; i < 4; ++i) {
134 if (!swizzle.DestComponentEnabled(i)) 145 if (!swizzle.DestComponentEnabled(i))
135 continue; 146 continue;
@@ -145,6 +156,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
145 // Reciprocal Square Root 156 // Reciprocal Square Root
146 case Instruction::OpCode::RSQ: 157 case Instruction::OpCode::RSQ:
147 { 158 {
159 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
148 for (int i = 0; i < 4; ++i) { 160 for (int i = 0; i < 4; ++i) {
149 if (!swizzle.DestComponentEnabled(i)) 161 if (!swizzle.DestComponentEnabled(i))
150 continue; 162 continue;
@@ -159,6 +171,7 @@ static void ProcessShaderCode(VertexShaderState& state) {
159 171
160 case Instruction::OpCode::MOV: 172 case Instruction::OpCode::MOV:
161 { 173 {
174 state.debug.max_opdesc_id = std::max<u32>(state.debug.max_opdesc_id, 1+instr.common.operand_desc_id);
162 for (int i = 0; i < 4; ++i) { 175 for (int i = 0; i < 4; ++i) {
163 if (!swizzle.DestComponentEnabled(i)) 176 if (!swizzle.DestComponentEnabled(i))
164 continue; 177 continue;
@@ -212,6 +225,8 @@ OutputVertex RunShader(const InputVertex& input, int num_attributes)
212 225
213 const u32* main = &shader_memory[registers.vs_main_offset]; 226 const u32* main = &shader_memory[registers.vs_main_offset];
214 state.program_counter = (u32*)main; 227 state.program_counter = (u32*)main;
228 state.debug.max_offset = 0;
229 state.debug.max_opdesc_id = 0;
215 230
216 // Setup input register table 231 // Setup input register table
217 const auto& attribute_register_map = registers.vs_input_register_map; 232 const auto& attribute_register_map = registers.vs_input_register_map;
@@ -255,6 +270,9 @@ OutputVertex RunShader(const InputVertex& input, int num_attributes)
255 state.call_stack_pointer = &state.call_stack[0]; 270 state.call_stack_pointer = &state.call_stack[0];
256 271
257 ProcessShaderCode(state); 272 ProcessShaderCode(state);
273 DebugUtils::DumpShader(shader_memory, state.debug.max_offset, swizzle_data,
274 state.debug.max_opdesc_id, registers.vs_main_offset,
275 registers.vs_output_attributes);
258 276
259 DEBUG_LOG(GPU, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)", 277 DEBUG_LOG(GPU, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)",
260 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(), 278 ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),