[Base/GPU] Cleanup float comparisons and NaN and -0 in clamping

C++ relational operators are supposed to raise FE_INVALID if an argument is
NaN, use std::isless/greater[equal] instead where they were easy to locate
(though there are other places possibly, mostly min/max and clamp usage was
checked).

Also fixes a copy-paste error making the CPU shader interpreter execute
MINs as MAXs instead.
This commit is contained in:
Triang3l
2024-05-12 19:21:37 +03:00
parent f964290ea8
commit a3304d252f
9 changed files with 143 additions and 144 deletions

View File

@@ -12,6 +12,7 @@
#include <algorithm>
#include "xenia/base/assert.h"
#include "xenia/base/math.h"
#include "xenia/ui/graphics_util.h"
#include "xenia/ui/presenter.h"
@@ -67,24 +68,19 @@ bool ImmediateDrawer::ScissorToRenderTarget(const ImmediateDraw& immediate_draw,
}
float render_target_width_float = float(render_target_width);
float render_target_height_float = float(render_target_height);
// Scale to render target coordinates, drop NaNs (by doing
// std::max(0.0f, variable) in this argument order), and clamp to the render
// Scale to render target coordinates, drop NaNs, and clamp to the render
// target size, below which the values are representable as 16p8 fixed-point.
float scale_x = render_target_width / coordinate_space_width();
float scale_y = render_target_height / coordinate_space_height();
float x0_float =
std::min(render_target_width_float,
std::max(0.0f, immediate_draw.scissor_left * scale_x));
float y0_float =
std::min(render_target_height_float,
std::max(0.0f, immediate_draw.scissor_top * scale_y));
float x0_float = xe::clamp_float(immediate_draw.scissor_left * scale_x, 0.0f,
render_target_width_float);
float y0_float = xe::clamp_float(immediate_draw.scissor_top * scale_y, 0.0f,
render_target_height_float);
// Also make sure the size is non-negative.
float x1_float =
std::min(render_target_width_float,
std::max(x0_float, immediate_draw.scissor_right * scale_x));
float y1_float =
std::min(render_target_height_float,
std::max(y0_float, immediate_draw.scissor_bottom * scale_y));
float x1_float = xe::clamp_float(immediate_draw.scissor_right * scale_x,
x0_float, render_target_width_float);
float y1_float = xe::clamp_float(immediate_draw.scissor_bottom * scale_y,
y0_float, render_target_height_float);
// Top-left - include .5 (0.128 treated as 0 covered, 0.129 as 0 not covered).
int32_t x0 = (FloatToD3D11Fixed16p8(x0_float) + 127) >> 8;
int32_t y0 = (FloatToD3D11Fixed16p8(y0_float) + 127) >> 8;