[vk] Fix 20xx flipped screen (#3058)
flip_y means "flip the Y coordinate of the triangles"; however, right now we just update the front face... this "emulates" the raster flip in the viewport itself, not the best solution but it's one solution :) Signed-off-by: lizzie lizzie@eden-emu.dev Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3058 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: Caio Oliveira <caiooliveirafarias0@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
This commit is contained in:
parent
73713737c6
commit
17fe74ef11
|
|
@ -62,41 +62,29 @@ struct DrawParams {
|
||||||
VkViewport GetViewportState(const Device& device, const Maxwell& regs, size_t index, float scale) {
|
VkViewport GetViewportState(const Device& device, const Maxwell& regs, size_t index, float scale) {
|
||||||
const auto& src = regs.viewport_transform[index];
|
const auto& src = regs.viewport_transform[index];
|
||||||
const auto conv = [scale](float value) {
|
const auto conv = [scale](float value) {
|
||||||
float new_value = value * scale;
|
float const new_value = value * scale;
|
||||||
if (scale < 1.0f) {
|
return scale < 1.0f
|
||||||
const bool sign = std::signbit(value);
|
? std::round(std::abs(new_value)) * (std::signbit(new_value) ? -1.f : 1.f)
|
||||||
new_value = std::round(std::abs(new_value));
|
: new_value;
|
||||||
new_value = sign ? -new_value : new_value;
|
|
||||||
}
|
|
||||||
return new_value;
|
|
||||||
};
|
};
|
||||||
const float x = conv(src.translate_x - src.scale_x);
|
float const w = src.scale_x;
|
||||||
const float width = conv(src.scale_x * 2.0f);
|
float h = src.scale_y;
|
||||||
float y = conv(src.translate_y - src.scale_y);
|
if (regs.window_origin.mode == Maxwell::WindowOrigin::Mode::LowerLeft) // Flip by surface clip height
|
||||||
float height = conv(src.scale_y * 2.0f);
|
h = -h;
|
||||||
|
if (!device.IsNvViewportSwizzleSupported() && src.swizzle.y == Maxwell::ViewportSwizzle::NegativeY) // Flip by viewport height
|
||||||
const bool lower_left = regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft;
|
h = -h;
|
||||||
const bool y_negate = !device.IsNvViewportSwizzleSupported() &&
|
// In theory, a raster flip is equivalent to a texture flip for a whole square viewport
|
||||||
src.swizzle.y == Maxwell::ViewportSwizzle::NegativeY;
|
// TODO: one day implement this properly and raster flip the triangles, not the whole viewport... guh
|
||||||
|
if(regs.viewport_transform[1].scale_y == 0 && regs.window_origin.flip_y != 0)
|
||||||
if (lower_left) {
|
h = -h;
|
||||||
// Flip by surface clip height
|
float const x = src.translate_x - w;
|
||||||
y += conv(static_cast<f32>(regs.surface_clip.height));
|
float const y = src.translate_y - h;
|
||||||
height = -height;
|
float const reduce_z = regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1.0f : 0.0f;
|
||||||
}
|
|
||||||
|
|
||||||
if (y_negate) {
|
|
||||||
// Flip by viewport height
|
|
||||||
y += height;
|
|
||||||
height = -height;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float reduce_z = regs.depth_mode == Maxwell::DepthMode::MinusOneToOne ? 1.0f : 0.0f;
|
|
||||||
VkViewport viewport{
|
VkViewport viewport{
|
||||||
.x = x,
|
.x = conv(x),
|
||||||
.y = y,
|
.y = conv(y),
|
||||||
.width = width != 0.0f ? width : 1.0f,
|
.width = w != 0.0f ? conv(w * 2.f) : 1.0f,
|
||||||
.height = height != 0.0f ? height : 1.0f,
|
.height = h != 0.0f ? conv(h * 2.f) : 1.0f,
|
||||||
.minDepth = src.translate_z - src.scale_z * reduce_z,
|
.minDepth = src.translate_z - src.scale_z * reduce_z,
|
||||||
.maxDepth = src.translate_z + src.scale_z,
|
.maxDepth = src.translate_z + src.scale_z,
|
||||||
};
|
};
|
||||||
|
|
@ -1024,10 +1012,10 @@ void RasterizerVulkan::UpdateViewportsState(Tegra::Engines::Maxwell3D::Regs& reg
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!regs.viewport_scale_offset_enabled) {
|
if (!regs.viewport_scale_offset_enabled) {
|
||||||
float x = static_cast<float>(regs.surface_clip.x);
|
float x = float(regs.surface_clip.x);
|
||||||
float y = static_cast<float>(regs.surface_clip.y);
|
float y = float(regs.surface_clip.y);
|
||||||
float width = (std::max)(1.0f, static_cast<float>(regs.surface_clip.width));
|
float width = (std::max)(1.0f, float(regs.surface_clip.width));
|
||||||
float height = (std::max)(1.0f, static_cast<float>(regs.surface_clip.height));
|
float height = (std::max)(1.0f, float(regs.surface_clip.height));
|
||||||
if (regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft) {
|
if (regs.window_origin.mode != Maxwell::WindowOrigin::Mode::UpperLeft) {
|
||||||
y += height;
|
y += height;
|
||||||
height = -height;
|
height = -height;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue