diff options
Diffstat (limited to 'src/video_core/shader/shader.cpp')
| -rw-r--r-- | src/video_core/shader/shader.cpp | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/video_core/shader/shader.cpp b/src/video_core/shader/shader.cpp index f565e2c91..272f3ffe1 100644 --- a/src/video_core/shader/shader.cpp +++ b/src/video_core/shader/shader.cpp | |||
| @@ -7,23 +7,18 @@ | |||
| 7 | #include <cstring> | 7 | #include <cstring> |
| 8 | #include <unordered_map> | 8 | #include <unordered_map> |
| 9 | #include <utility> | 9 | #include <utility> |
| 10 | |||
| 11 | #include <boost/range/algorithm/fill.hpp> | 10 | #include <boost/range/algorithm/fill.hpp> |
| 12 | |||
| 13 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 14 | #include "common/hash.h" | 12 | #include "common/hash.h" |
| 15 | #include "common/logging/log.h" | 13 | #include "common/logging/log.h" |
| 16 | #include "common/microprofile.h" | 14 | #include "common/microprofile.h" |
| 17 | |||
| 18 | #include "video_core/pica.h" | 15 | #include "video_core/pica.h" |
| 19 | #include "video_core/pica_state.h" | 16 | #include "video_core/pica_state.h" |
| 20 | #include "video_core/shader/shader.h" | 17 | #include "video_core/shader/shader.h" |
| 21 | #include "video_core/shader/shader_interpreter.h" | 18 | #include "video_core/shader/shader_interpreter.h" |
| 22 | |||
| 23 | #ifdef ARCHITECTURE_x86_64 | 19 | #ifdef ARCHITECTURE_x86_64 |
| 24 | #include "video_core/shader/shader_jit_x64.h" | 20 | #include "video_core/shader/shader_jit_x64.h" |
| 25 | #endif // ARCHITECTURE_x86_64 | 21 | #endif // ARCHITECTURE_x86_64 |
| 26 | |||
| 27 | #include "video_core/video_core.h" | 22 | #include "video_core/video_core.h" |
| 28 | 23 | ||
| 29 | namespace Pica { | 24 | namespace Pica { |
| @@ -46,10 +41,8 @@ OutputVertex OutputRegisters::ToVertex(const Regs::ShaderConfig& config) { | |||
| 46 | 41 | ||
| 47 | const auto& output_register_map = g_state.regs.vs_output_attributes[index]; | 42 | const auto& output_register_map = g_state.regs.vs_output_attributes[index]; |
| 48 | 43 | ||
| 49 | u32 semantics[4] = { | 44 | u32 semantics[4] = {output_register_map.map_x, output_register_map.map_y, |
| 50 | output_register_map.map_x, output_register_map.map_y, | 45 | output_register_map.map_z, output_register_map.map_w}; |
| 51 | output_register_map.map_z, output_register_map.map_w | ||
| 52 | }; | ||
| 53 | 46 | ||
| 54 | for (unsigned comp = 0; comp < 4; ++comp) { | 47 | for (unsigned comp = 0; comp < 4; ++comp) { |
| 55 | float24* out = ((float24*)&ret) + semantics[comp]; | 48 | float24* out = ((float24*)&ret) + semantics[comp]; |
| @@ -65,19 +58,20 @@ OutputVertex OutputRegisters::ToVertex(const Regs::ShaderConfig& config) { | |||
| 65 | index++; | 58 | index++; |
| 66 | } | 59 | } |
| 67 | 60 | ||
| 68 | // The hardware takes the absolute and saturates vertex colors like this, *before* doing interpolation | 61 | // The hardware takes the absolute and saturates vertex colors like this, *before* doing |
| 62 | // interpolation | ||
| 69 | for (unsigned i = 0; i < 4; ++i) { | 63 | for (unsigned i = 0; i < 4; ++i) { |
| 70 | ret.color[i] = float24::FromFloat32( | 64 | ret.color[i] = float24::FromFloat32(std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f)); |
| 71 | std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f)); | ||
| 72 | } | 65 | } |
| 73 | 66 | ||
| 74 | LOG_TRACE(HW_GPU, "Output vertex: pos(%.2f, %.2f, %.2f, %.2f), quat(%.2f, %.2f, %.2f, %.2f), " | 67 | LOG_TRACE(HW_GPU, "Output vertex: pos(%.2f, %.2f, %.2f, %.2f), quat(%.2f, %.2f, %.2f, %.2f), " |
| 75 | "col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f), view(%.2f, %.2f, %.2f)", | 68 | "col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f), view(%.2f, %.2f, %.2f)", |
| 76 | ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(), | 69 | ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), |
| 77 | ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(), ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(), | 70 | ret.pos.w.ToFloat32(), ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(), |
| 78 | ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(), | 71 | ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(), ret.color.x.ToFloat32(), |
| 79 | ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32(), | 72 | ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(), |
| 80 | ret.view.x.ToFloat32(), ret.view.y.ToFloat32(), ret.view.z.ToFloat32()); | 73 | ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32(), ret.view.x.ToFloat32(), |
| 74 | ret.view.y.ToFloat32(), ret.view.z.ToFloat32()); | ||
| 81 | 75 | ||
| 82 | return ret; | 76 | return ret; |
| 83 | } | 77 | } |
| @@ -96,8 +90,9 @@ void ClearCache() { | |||
| 96 | void ShaderSetup::Setup() { | 90 | void ShaderSetup::Setup() { |
| 97 | #ifdef ARCHITECTURE_x86_64 | 91 | #ifdef ARCHITECTURE_x86_64 |
| 98 | if (VideoCore::g_shader_jit_enabled) { | 92 | if (VideoCore::g_shader_jit_enabled) { |
| 99 | u64 cache_key = (Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ | 93 | u64 cache_key = |
| 100 | Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data))); | 94 | Common::ComputeHash64(&g_state.vs.program_code, sizeof(g_state.vs.program_code)) ^ |
| 95 | Common::ComputeHash64(&g_state.vs.swizzle_data, sizeof(g_state.vs.swizzle_data)); | ||
| 101 | 96 | ||
| 102 | auto iter = shader_map.find(cache_key); | 97 | auto iter = shader_map.find(cache_key); |
| 103 | if (iter != shader_map.end()) { | 98 | if (iter != shader_map.end()) { |
| @@ -127,7 +122,7 @@ void ShaderSetup::Run(UnitState<false>& state, const InputVertex& input, int num | |||
| 127 | const auto& attribute_register_map = config.input_register_map; | 122 | const auto& attribute_register_map = config.input_register_map; |
| 128 | 123 | ||
| 129 | for (unsigned i = 0; i < num_attributes; i++) | 124 | for (unsigned i = 0; i < num_attributes; i++) |
| 130 | state.registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i]; | 125 | state.registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i]; |
| 131 | 126 | ||
| 132 | state.conditional_code[0] = false; | 127 | state.conditional_code[0] = false; |
| 133 | state.conditional_code[1] = false; | 128 | state.conditional_code[1] = false; |
| @@ -140,10 +135,11 @@ void ShaderSetup::Run(UnitState<false>& state, const InputVertex& input, int num | |||
| 140 | #else | 135 | #else |
| 141 | RunInterpreter(setup, state, config.main_offset); | 136 | RunInterpreter(setup, state, config.main_offset); |
| 142 | #endif // ARCHITECTURE_x86_64 | 137 | #endif // ARCHITECTURE_x86_64 |
| 143 | |||
| 144 | } | 138 | } |
| 145 | 139 | ||
| 146 | DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, const Regs::ShaderConfig& config, const ShaderSetup& setup) { | 140 | DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_attributes, |
| 141 | const Regs::ShaderConfig& config, | ||
| 142 | const ShaderSetup& setup) { | ||
| 147 | UnitState<true> state; | 143 | UnitState<true> state; |
| 148 | 144 | ||
| 149 | state.debug.max_offset = 0; | 145 | state.debug.max_offset = 0; |
| @@ -155,7 +151,7 @@ DebugData<true> ShaderSetup::ProduceDebugInfo(const InputVertex& input, int num_ | |||
| 155 | boost::fill(state.registers.input, &dummy_register); | 151 | boost::fill(state.registers.input, &dummy_register); |
| 156 | 152 | ||
| 157 | for (unsigned i = 0; i < num_attributes; i++) | 153 | for (unsigned i = 0; i < num_attributes; i++) |
| 158 | state.registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i]; | 154 | state.registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i]; |
| 159 | 155 | ||
| 160 | state.conditional_code[0] = false; | 156 | state.conditional_code[0] = false; |
| 161 | state.conditional_code[1] = false; | 157 | state.conditional_code[1] = false; |