Skip to content

Commit 986e66b

Browse files
committed
GPU: Use vectors in draw rect calculation
1 parent 97582bc commit 986e66b

File tree

1 file changed

+29
-40
lines changed

1 file changed

+29
-40
lines changed

src/core/gpu.cpp

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,115 +1806,104 @@ void GPU::CalculateDrawRect(const GSVector2i& window_size, const GSVector2i& vid
18061806
bool integer_scale, GSVector4i* out_source_rect, GSVector4i* out_display_rect,
18071807
GSVector4i* out_draw_rect)
18081808
{
1809-
const float fwindow_width = static_cast<float>(window_size.x);
1810-
const float fwindow_height = static_cast<float>(window_size.y);
1811-
float display_width = static_cast<float>(video_size.x);
1812-
float display_height = static_cast<float>(video_size.y);
1813-
float active_left = static_cast<float>(video_active_rect.x);
1814-
float active_top = static_cast<float>(video_active_rect.y);
1815-
float active_width = static_cast<float>(video_active_rect.width());
1816-
float active_height = static_cast<float>(video_active_rect.height());
1809+
GSVector2 fwindow_size = GSVector2(window_size);
1810+
GSVector2 fvideo_size = GSVector2(video_size);
1811+
GSVector4 fvideo_active_rect = GSVector4(video_active_rect);
18171812

18181813
// for integer scale, use whichever gets us a greater effective display size
18191814
// this is needed for games like crash where the framebuffer is wide to not lose detail
18201815
if (integer_scale ?
1821-
IntegerScalePreferWidth(display_width, display_height, pixel_aspect_ratio, fwindow_width, fwindow_height) :
1816+
IntegerScalePreferWidth(fvideo_size.x, fvideo_size.y, pixel_aspect_ratio, fwindow_size.x, fwindow_size.y) :
18221817
(pixel_aspect_ratio >= 1.0f))
18231818
{
1824-
display_width *= pixel_aspect_ratio;
1825-
active_left *= pixel_aspect_ratio;
1826-
active_width *= pixel_aspect_ratio;
1819+
fvideo_size.x *= pixel_aspect_ratio;
1820+
fvideo_active_rect = fvideo_active_rect.blend32<5>(fvideo_active_rect * pixel_aspect_ratio);
18271821
}
18281822
else
18291823
{
1830-
display_height /= pixel_aspect_ratio;
1831-
active_top /= pixel_aspect_ratio;
1832-
active_height /= pixel_aspect_ratio;
1824+
fvideo_size.y /= pixel_aspect_ratio;
1825+
fvideo_active_rect = fvideo_active_rect.blend32<10>(fvideo_active_rect / pixel_aspect_ratio);
18331826
}
18341827

18351828
// swap width/height when rotated, the flipping of padding is taken care of in the shader with the rotation matrix
18361829
if (rotation == DisplayRotation::Rotate90 || rotation == DisplayRotation::Rotate270)
18371830
{
1838-
std::swap(display_width, display_height);
1839-
std::swap(active_width, active_height);
1840-
std::swap(active_top, active_left);
1831+
fvideo_size = fvideo_size.yx();
1832+
fvideo_active_rect = fvideo_active_rect.yxwz();
18411833
}
18421834

18431835
// now fit it within the window
18441836
float scale;
1845-
float left_padding, top_padding;
1846-
if ((display_width / display_height) >= (fwindow_width / fwindow_height))
1837+
GSVector2 padding;
1838+
if ((fvideo_size.x / fvideo_size.y) >= (fwindow_size.x / fwindow_size.y))
18471839
{
18481840
// align in middle vertically
1849-
scale = fwindow_width / display_width;
1841+
scale = fwindow_size.x / fvideo_size.x;
18501842
if (integer_scale)
18511843
{
18521844
// skip integer scaling if we cannot fit in the window at all
18531845
scale = (scale >= 1.0f) ? std::floor(scale) : scale;
1854-
left_padding = std::max<float>((fwindow_width - display_width * scale) / 2.0f, 0.0f);
1846+
padding.x = std::max<float>((fwindow_size.x - fvideo_size.x * scale) / 2.0f, 0.0f);
18551847
}
18561848
else
18571849
{
1858-
left_padding = 0.0f;
1850+
padding.x = 0.0f;
18591851
}
18601852

18611853
switch (alignment)
18621854
{
18631855
case DisplayAlignment::RightOrBottom:
1864-
top_padding = std::max<float>(fwindow_height - (display_height * scale), 0.0f);
1856+
padding.y = std::max<float>(fwindow_size.y - (fvideo_size.y * scale), 0.0f);
18651857
break;
18661858

18671859
case DisplayAlignment::Center:
1868-
top_padding = std::max<float>((fwindow_height - (display_height * scale)) / 2.0f, 0.0f);
1860+
padding.y = std::max<float>((fwindow_size.y - (fvideo_size.y * scale)) / 2.0f, 0.0f);
18691861
break;
18701862

18711863
case DisplayAlignment::LeftOrTop:
18721864
default:
1873-
top_padding = 0.0f;
1865+
padding.y = 0.0f;
18741866
break;
18751867
}
18761868
}
18771869
else
18781870
{
18791871
// align in middle horizontally
1880-
scale = fwindow_height / display_height;
1872+
scale = fwindow_size.y / fvideo_size.y;
18811873
if (integer_scale)
18821874
{
18831875
// skip integer scaling if we cannot fit in the window at all
18841876
scale = (scale >= 1.0f) ? std::floor(scale) : scale;
1885-
top_padding = std::max<float>((fwindow_height - (display_height * scale)) / 2.0f, 0.0f);
1877+
padding.y = std::max<float>((fwindow_size.y - (fvideo_size.y * scale)) / 2.0f, 0.0f);
18861878
}
18871879
else
18881880
{
1889-
top_padding = 0.0f;
1881+
padding.y = 0.0f;
18901882
}
18911883

18921884
switch (alignment)
18931885
{
18941886
case DisplayAlignment::RightOrBottom:
1895-
left_padding = std::max<float>(fwindow_width - (display_width * scale), 0.0f);
1887+
padding.x = std::max<float>(fwindow_size.x - (fvideo_size.x * scale), 0.0f);
18961888
break;
18971889

18981890
case DisplayAlignment::Center:
1899-
left_padding = std::max<float>((fwindow_width - (display_width * scale)) / 2.0f, 0.0f);
1891+
padding.x = std::max<float>((fwindow_size.x - (fvideo_size.x * scale)) / 2.0f, 0.0f);
19001892
break;
19011893

19021894
case DisplayAlignment::LeftOrTop:
19031895
default:
1904-
left_padding = 0.0f;
1896+
padding.x = 0.0f;
19051897
break;
19061898
}
19071899
}
19081900

1909-
// TODO: This should be a float rectangle. But because GL is lame, it only has integer viewports...
1910-
const s32 left = static_cast<s32>(active_left * scale + left_padding);
1911-
const s32 top = static_cast<s32>(active_top * scale + top_padding);
1912-
const s32 right = left + static_cast<s32>(active_width * scale);
1913-
const s32 bottom = top + static_cast<s32>(active_height * scale);
1901+
const GSVector4 padding4 = GSVector4::xyxy(padding);
1902+
fvideo_size *= scale;
1903+
fvideo_active_rect *= scale;
19141904
*out_source_rect = source_rect;
1915-
*out_draw_rect = GSVector4i(left, top, right, bottom);
1916-
*out_display_rect = GSVector4i(
1917-
GSVector4(left_padding, top_padding, left_padding + display_width * scale, top_padding + display_height * scale));
1905+
*out_draw_rect = GSVector4i(fvideo_active_rect + padding4);
1906+
*out_display_rect = GSVector4i(GSVector4::loadh(fvideo_size) + padding4);
19181907
}
19191908

19201909
void GPU::ReadVRAM(u16 x, u16 y, u16 width, u16 height)

0 commit comments

Comments
 (0)