2015-07-21 19:38:59 -04:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2016-04-30 11:34:51 -04:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstring>
|
|
|
|
#include "common/logging/log.h"
|
2015-08-17 17:25:21 -04:00
|
|
|
#include "common/microprofile.h"
|
2015-07-21 19:38:59 -04:00
|
|
|
#include "video_core/pica.h"
|
2016-03-02 22:16:38 -05:00
|
|
|
#include "video_core/pica_state.h"
|
2016-09-21 02:52:38 -04:00
|
|
|
#include "video_core/shader/shader.h"
|
2016-04-30 11:34:51 -04:00
|
|
|
#include "video_core/shader/shader_interpreter.h"
|
2015-08-14 22:29:08 -04:00
|
|
|
#ifdef ARCHITECTURE_x86_64
|
2016-12-17 04:21:16 -05:00
|
|
|
#include "video_core/shader/shader_jit_x64.h"
|
2015-08-14 22:29:08 -04:00
|
|
|
#endif // ARCHITECTURE_x86_64
|
2016-04-30 11:34:51 -04:00
|
|
|
#include "video_core/video_core.h"
|
|
|
|
|
2015-07-21 19:38:59 -04:00
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
namespace Shader {
|
|
|
|
|
2016-12-17 17:38:03 -05:00
|
|
|
OutputVertex OutputVertex::FromRegisters(Math::Vec4<float24> output_regs[16], const Regs& regs,
|
|
|
|
u32 output_mask) {
|
2016-05-13 02:49:20 -04:00
|
|
|
// Setup output data
|
|
|
|
OutputVertex ret;
|
|
|
|
// TODO(neobrain): Under some circumstances, up to 16 attributes may be output. We need to
|
|
|
|
// figure out what those circumstances are and enable the remaining outputs then.
|
|
|
|
unsigned index = 0;
|
|
|
|
for (unsigned i = 0; i < 7; ++i) {
|
|
|
|
|
2016-12-17 17:38:03 -05:00
|
|
|
if (index >= regs.vs_output_total)
|
2016-05-13 02:49:20 -04:00
|
|
|
break;
|
|
|
|
|
2016-12-17 17:38:03 -05:00
|
|
|
if ((output_mask & (1 << i)) == 0)
|
2016-05-13 02:49:20 -04:00
|
|
|
continue;
|
|
|
|
|
2016-12-17 17:38:03 -05:00
|
|
|
const auto& output_register_map = regs.vs_output_attributes[index];
|
2016-05-13 02:49:20 -04:00
|
|
|
|
2016-09-17 20:38:01 -04:00
|
|
|
u32 semantics[4] = {output_register_map.map_x, output_register_map.map_y,
|
|
|
|
output_register_map.map_z, output_register_map.map_w};
|
2016-05-13 02:49:20 -04:00
|
|
|
|
|
|
|
for (unsigned comp = 0; comp < 4; ++comp) {
|
|
|
|
float24* out = ((float24*)&ret) + semantics[comp];
|
|
|
|
if (semantics[comp] != Regs::VSOutputAttributes::INVALID) {
|
2016-12-17 17:38:03 -05:00
|
|
|
*out = output_regs[i][comp];
|
2016-05-13 02:49:20 -04:00
|
|
|
} else {
|
|
|
|
// Zero output so that attributes which aren't output won't have denormals in them,
|
|
|
|
// which would slow us down later.
|
|
|
|
memset(out, 0, sizeof(*out));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
2016-09-17 20:38:01 -04:00
|
|
|
// The hardware takes the absolute and saturates vertex colors like this, *before* doing
|
|
|
|
// interpolation
|
2016-05-13 02:49:20 -04:00
|
|
|
for (unsigned i = 0; i < 4; ++i) {
|
2016-09-17 20:38:01 -04:00
|
|
|
ret.color[i] = float24::FromFloat32(std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f));
|
2016-05-13 02:49:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG_TRACE(HW_GPU, "Output vertex: pos(%.2f, %.2f, %.2f, %.2f), quat(%.2f, %.2f, %.2f, %.2f), "
|
2016-09-17 20:38:01 -04:00
|
|
|
"col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f), view(%.2f, %.2f, %.2f)",
|
|
|
|
ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(),
|
|
|
|
ret.pos.w.ToFloat32(), ret.quat.x.ToFloat32(), ret.quat.y.ToFloat32(),
|
|
|
|
ret.quat.z.ToFloat32(), ret.quat.w.ToFloat32(), ret.color.x.ToFloat32(),
|
|
|
|
ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(),
|
|
|
|
ret.tc0.u().ToFloat32(), ret.tc0.v().ToFloat32(), ret.view.x.ToFloat32(),
|
|
|
|
ret.view.y.ToFloat32(), ret.view.z.ToFloat32());
|
2016-05-13 02:49:20 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-12-18 19:42:19 -05:00
|
|
|
void UnitState::LoadInput(const AttributeBuffer& input, int num_attributes) {
|
2016-12-17 00:41:38 -05:00
|
|
|
// Setup input register table
|
|
|
|
const auto& attribute_register_map = g_state.regs.vs.input_register_map;
|
|
|
|
|
|
|
|
for (int i = 0; i < num_attributes; i++)
|
|
|
|
registers.input[attribute_register_map.GetRegisterForAttribute(i)] = input.attr[i];
|
|
|
|
}
|
|
|
|
|
2016-12-17 04:21:16 -05:00
|
|
|
MICROPROFILE_DEFINE(GPU_Shader, "GPU", "Shader", MP_RGB(50, 50, 240));
|
2015-07-22 23:25:30 -04:00
|
|
|
|
2016-03-29 20:45:18 -04:00
|
|
|
#ifdef ARCHITECTURE_x86_64
|
2016-12-17 04:21:16 -05:00
|
|
|
static std::unique_ptr<JitX64Engine> jit_engine;
|
2016-03-29 20:45:18 -04:00
|
|
|
#endif // ARCHITECTURE_x86_64
|
2016-12-17 04:21:16 -05:00
|
|
|
static InterpreterEngine interpreter_engine;
|
2016-12-17 02:21:26 -05:00
|
|
|
|
2016-12-17 04:21:16 -05:00
|
|
|
ShaderEngine* GetEngine() {
|
2015-07-22 23:25:30 -04:00
|
|
|
#ifdef ARCHITECTURE_x86_64
|
2016-12-17 04:21:16 -05:00
|
|
|
// TODO(yuriks): Re-initialize on each change rather than being persistent
|
2015-07-22 23:25:30 -04:00
|
|
|
if (VideoCore::g_shader_jit_enabled) {
|
2016-12-17 04:21:16 -05:00
|
|
|
if (jit_engine == nullptr) {
|
|
|
|
jit_engine = std::make_unique<JitX64Engine>();
|
2015-07-22 23:25:30 -04:00
|
|
|
}
|
2016-12-17 04:21:16 -05:00
|
|
|
return jit_engine.get();
|
2015-08-14 22:29:08 -04:00
|
|
|
}
|
|
|
|
#endif // ARCHITECTURE_x86_64
|
2015-07-21 19:38:59 -04:00
|
|
|
|
2016-12-17 04:21:16 -05:00
|
|
|
return &interpreter_engine;
|
|
|
|
}
|
2015-07-21 19:38:59 -04:00
|
|
|
|
2016-12-17 04:21:16 -05:00
|
|
|
void Shutdown() {
|
2015-07-22 23:25:30 -04:00
|
|
|
#ifdef ARCHITECTURE_x86_64
|
2016-12-17 04:21:16 -05:00
|
|
|
jit_engine = nullptr;
|
2015-08-14 22:29:08 -04:00
|
|
|
#endif // ARCHITECTURE_x86_64
|
2015-07-21 19:38:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Shader
|
|
|
|
|
|
|
|
} // namespace Pica
|