diff options
| author | 2014-12-16 00:32:49 +0100 | |
|---|---|---|
| committer | 2014-12-20 18:06:55 +0100 | |
| commit | 8ce1d324602001e1102648319a9281ee08a1af95 (patch) | |
| tree | acabdc7c8614235b283e6e48e13dc17a0a1a85dd /src/video_core/vertex_shader.cpp | |
| parent | Add nihstro (a 3DS shader tools suite) as a submodule. (diff) | |
| download | yuzu-8ce1d324602001e1102648319a9281ee08a1af95.tar.gz yuzu-8ce1d324602001e1102648319a9281ee08a1af95.tar.xz yuzu-8ce1d324602001e1102648319a9281ee08a1af95.zip | |
Pica/VertexShader: Remove (now) duplicated shader bytecode definitions in favor of nihstro's ones.
Diffstat (limited to 'src/video_core/vertex_shader.cpp')
| -rw-r--r-- | src/video_core/vertex_shader.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/video_core/vertex_shader.cpp b/src/video_core/vertex_shader.cpp index 477e78cfe..064a703eb 100644 --- a/src/video_core/vertex_shader.cpp +++ b/src/video_core/vertex_shader.cpp | |||
| @@ -8,11 +8,18 @@ | |||
| 8 | 8 | ||
| 9 | #include <core/mem_map.h> | 9 | #include <core/mem_map.h> |
| 10 | 10 | ||
| 11 | #include <nihstro/shader_bytecode.h> | ||
| 12 | |||
| 11 | #include "debug_utils/debug_utils.h" | 13 | #include "debug_utils/debug_utils.h" |
| 12 | 14 | ||
| 13 | #include "pica.h" | 15 | #include "pica.h" |
| 14 | #include "vertex_shader.h" | 16 | #include "vertex_shader.h" |
| 15 | 17 | ||
| 18 | using nihstro::Instruction; | ||
| 19 | using nihstro::RegisterType; | ||
| 20 | using nihstro::SourceRegister; | ||
| 21 | using nihstro::SwizzlePattern; | ||
| 22 | |||
| 16 | namespace Pica { | 23 | namespace Pica { |
| 17 | 24 | ||
| 18 | namespace VertexShader { | 25 | namespace VertexShader { |
| @@ -70,19 +77,28 @@ static void ProcessShaderCode(VertexShaderState& state) { | |||
| 70 | const Instruction& instr = *(const Instruction*)state.program_counter; | 77 | const Instruction& instr = *(const Instruction*)state.program_counter; |
| 71 | state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + (state.program_counter - shader_memory)); | 78 | state.debug.max_offset = std::max<u32>(state.debug.max_offset, 1 + (state.program_counter - shader_memory)); |
| 72 | 79 | ||
| 73 | const float24* src1_ = (instr.common.src1 < 0x10) ? state.input_register_table[instr.common.src1.GetIndex()] | 80 | auto LookupSourceRegister = [&](const SourceRegister& source_reg) -> const float24* { |
| 74 | : (instr.common.src1 < 0x20) ? &state.temporary_registers[instr.common.src1.GetIndex()].x | 81 | switch (source_reg.GetRegisterType()) { |
| 75 | : (instr.common.src1 < 0x80) ? &shader_uniforms.f[instr.common.src1.GetIndex()].x | 82 | case RegisterType::Input: |
| 76 | : nullptr; | 83 | return state.input_register_table[source_reg.GetIndex()]; |
| 77 | const float24* src2_ = (instr.common.src2 < 0x10) ? state.input_register_table[instr.common.src2.GetIndex()] | 84 | |
| 78 | : &state.temporary_registers[instr.common.src2.GetIndex()].x; | 85 | case RegisterType::Temporary: |
| 86 | return &state.temporary_registers[source_reg.GetIndex()].x; | ||
| 87 | |||
| 88 | case RegisterType::FloatUniform: | ||
| 89 | return &shader_uniforms.f[source_reg.GetIndex()].x; | ||
| 90 | } | ||
| 91 | }; | ||
| 92 | bool is_inverted = 0 != (instr.opcode.GetInfo().subtype & Instruction::OpCodeInfo::SrcInversed); | ||
| 93 | const float24* src1_ = LookupSourceRegister(instr.common.GetSrc1(is_inverted)); | ||
| 94 | const float24* src2_ = LookupSourceRegister(instr.common.GetSrc2(is_inverted)); | ||
| 79 | float24* dest = (instr.common.dest < 0x08) ? state.output_register_table[4*instr.common.dest.GetIndex()] | 95 | float24* dest = (instr.common.dest < 0x08) ? state.output_register_table[4*instr.common.dest.GetIndex()] |
| 80 | : (instr.common.dest < 0x10) ? nullptr | 96 | : (instr.common.dest < 0x10) ? nullptr |
| 81 | : (instr.common.dest < 0x20) ? &state.temporary_registers[instr.common.dest.GetIndex()][0] | 97 | : (instr.common.dest < 0x20) ? &state.temporary_registers[instr.common.dest.GetIndex()][0] |
| 82 | : nullptr; | 98 | : nullptr; |
| 83 | 99 | ||
| 84 | const SwizzlePattern& swizzle = *(SwizzlePattern*)&swizzle_data[instr.common.operand_desc_id]; | 100 | const SwizzlePattern& swizzle = *(SwizzlePattern*)&swizzle_data[instr.common.operand_desc_id]; |
| 85 | const bool negate_src1 = (swizzle.negate != 0); | 101 | const bool negate_src1 = (swizzle.negate_src1 != 0); |
| 86 | 102 | ||
| 87 | float24 src1[4] = { | 103 | float24 src1[4] = { |
| 88 | src1_[(int)swizzle.GetSelectorSrc1(0)], | 104 | src1_[(int)swizzle.GetSelectorSrc1(0)], |
| @@ -192,7 +208,9 @@ static void ProcessShaderCode(VertexShaderState& state) { | |||
| 192 | break; | 208 | break; |
| 193 | } | 209 | } |
| 194 | 210 | ||
| 195 | case Instruction::OpCode::RET: | 211 | // NOP is currently used as a heuristic for leaving from a function. |
| 212 | // TODO: This is completely incorrect. | ||
| 213 | case Instruction::OpCode::NOP: | ||
| 196 | if (*state.call_stack_pointer == VertexShaderState::INVALID_ADDRESS) { | 214 | if (*state.call_stack_pointer == VertexShaderState::INVALID_ADDRESS) { |
| 197 | exit_loop = true; | 215 | exit_loop = true; |
| 198 | } else { | 216 | } else { |
| @@ -209,17 +227,16 @@ static void ProcessShaderCode(VertexShaderState& state) { | |||
| 209 | _dbg_assert_(HW_GPU, state.call_stack_pointer - state.call_stack < sizeof(state.call_stack)); | 227 | _dbg_assert_(HW_GPU, state.call_stack_pointer - state.call_stack < sizeof(state.call_stack)); |
| 210 | 228 | ||
| 211 | *++state.call_stack_pointer = state.program_counter - shader_memory; | 229 | *++state.call_stack_pointer = state.program_counter - shader_memory; |
| 212 | // TODO: Does this offset refer to the beginning of shader memory? | 230 | state.program_counter = &shader_memory[instr.flow_control.dest_offset]; |
| 213 | state.program_counter = &shader_memory[instr.flow_control.offset_words]; | ||
| 214 | break; | 231 | break; |
| 215 | 232 | ||
| 216 | case Instruction::OpCode::FLS: | 233 | case Instruction::OpCode::END: |
| 217 | // TODO: Do whatever needs to be done here? | 234 | // TODO |
| 218 | break; | 235 | break; |
| 219 | 236 | ||
| 220 | default: | 237 | default: |
| 221 | LOG_ERROR(HW_GPU, "Unhandled instruction: 0x%02x (%s): 0x%08x", | 238 | LOG_ERROR(HW_GPU, "Unhandled instruction: 0x%02x (%s): 0x%08x", |
| 222 | (int)instr.opcode.Value(), instr.GetOpCodeName().c_str(), instr.hex); | 239 | (int)instr.opcode.Value(), instr.opcode.GetInfo().name, instr.hex); |
| 223 | break; | 240 | break; |
| 224 | } | 241 | } |
| 225 | 242 | ||