mirror of
https://git.h3cjp.net/H3cJP/yuzu.git
synced 2024-12-15 15:25:31 +00:00
Merge pull request #963 from yuriks/gpu-fixes
Misc. GPU vertex loading fixes
This commit is contained in:
commit
31c1bb901b
|
@ -221,20 +221,14 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
// Initialize data for the current vertex
|
// Initialize data for the current vertex
|
||||||
VertexShader::InputVertex input;
|
VertexShader::InputVertex input;
|
||||||
|
|
||||||
// Load a debugging token to check whether this gets loaded by the running
|
|
||||||
// application or not.
|
|
||||||
static const float24 debug_token = float24::FromRawFloat24(0x00abcdef);
|
|
||||||
input.attr[0].w = debug_token;
|
|
||||||
|
|
||||||
for (int i = 0; i < attribute_config.GetNumTotalAttributes(); ++i) {
|
for (int i = 0; i < attribute_config.GetNumTotalAttributes(); ++i) {
|
||||||
// Load the default attribute if we're configured to do so, this data will be overwritten by the loader data if it's set
|
if (vertex_attribute_elements[i] != 0) {
|
||||||
if (attribute_config.IsDefaultAttribute(i)) {
|
// Default attribute values set if array elements have < 4 components. This
|
||||||
input.attr[i] = g_state.vs.default_attributes[i];
|
// is *not* carried over from the default attribute settings even if they're
|
||||||
LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
|
// enabled for this attribute.
|
||||||
i, vertex, index,
|
static const float24 zero = float24::FromFloat32(0.0f);
|
||||||
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
|
static const float24 one = float24::FromFloat32(1.0f);
|
||||||
input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
|
input.attr[i] = Math::Vec4<float24>(zero, zero, zero, one);
|
||||||
}
|
|
||||||
|
|
||||||
// Load per-vertex data from the loader arrays
|
// Load per-vertex data from the loader arrays
|
||||||
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
|
for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
|
||||||
|
@ -260,17 +254,19 @@ static inline void WritePicaReg(u32 id, u32 value, u32 mask) {
|
||||||
vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i],
|
vertex_attribute_strides[i] * vertex + comp * vertex_attribute_element_size[i],
|
||||||
input.attr[i][comp].ToFloat32());
|
input.attr[i][comp].ToFloat32());
|
||||||
}
|
}
|
||||||
|
} else if (attribute_config.IsDefaultAttribute(i)) {
|
||||||
|
// Load the default attribute if we're configured to do so
|
||||||
|
input.attr[i] = g_state.vs.default_attributes[i];
|
||||||
|
LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)",
|
||||||
|
i, vertex, index,
|
||||||
|
input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
|
||||||
|
input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
|
||||||
|
} else {
|
||||||
|
// TODO(yuriks): In this case, no data gets loaded and the vertex remains
|
||||||
|
// with the last value it had. This isn't currently maintained
|
||||||
|
// as global state, however, and so won't work in Cita yet.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HACK: Some games do not initialize the vertex position's w component. This leads
|
|
||||||
// to critical issues since it messes up perspective division. As a
|
|
||||||
// workaround, we force the fourth component to 1.0 if we find this to be the
|
|
||||||
// case.
|
|
||||||
// To do this, we additionally have to assume that the first input attribute
|
|
||||||
// is the vertex position, since there's no information about this other than
|
|
||||||
// the empiric observation that this is usually the case.
|
|
||||||
if (input.attr[0].w == debug_token)
|
|
||||||
input.attr[0].w = float24::FromFloat32(1.0);
|
|
||||||
|
|
||||||
if (g_debug_context)
|
if (g_debug_context)
|
||||||
g_debug_context->OnEvent(DebugContext::Event::VertexLoaded, (void*)&input);
|
g_debug_context->OnEvent(DebugContext::Event::VertexLoaded, (void*)&input);
|
||||||
|
|
|
@ -609,6 +609,12 @@ OutputVertex RunShader(const InputVertex& input, int num_attributes, const Regs:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The hardware takes the absolute and saturates vertex colors like this, *before* doing interpolation
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
ret.color[i] = float24::FromFloat32(
|
||||||
|
std::fmin(std::fabs(ret.color[i].ToFloat32()), 1.0f));
|
||||||
|
}
|
||||||
|
|
||||||
LOG_TRACE(Render_Software, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)",
|
LOG_TRACE(Render_Software, "Output vertex: pos (%.2f, %.2f, %.2f, %.2f), col(%.2f, %.2f, %.2f, %.2f), tc0(%.2f, %.2f)",
|
||||||
ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),
|
ret.pos.x.ToFloat32(), ret.pos.y.ToFloat32(), ret.pos.z.ToFloat32(), ret.pos.w.ToFloat32(),
|
||||||
ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(),
|
ret.color.x.ToFloat32(), ret.color.y.ToFloat32(), ret.color.z.ToFloat32(), ret.color.w.ToFloat32(),
|
||||||
|
|
Loading…
Reference in a new issue