GPU/HW: Use GSVector instead of Rectangle
This commit is contained in:
@ -21,6 +21,7 @@
|
||||
#include "common/align.h"
|
||||
#include "common/error.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/gsvector_formatter.h"
|
||||
#include "common/heap_array.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
@ -351,6 +352,7 @@ bool GPU::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_displ
|
||||
m_draw_mode.texture_page_changed = true;
|
||||
m_draw_mode.texture_window_changed = true;
|
||||
m_drawing_area_changed = true;
|
||||
SetClampedDrawingArea();
|
||||
UpdateDMARequest();
|
||||
}
|
||||
|
||||
@ -1089,12 +1091,11 @@ void GPU::UpdateCommandTickEvent()
|
||||
void GPU::ConvertScreenCoordinatesToDisplayCoordinates(float window_x, float window_y, float* display_x,
|
||||
float* display_y) const
|
||||
{
|
||||
const Common::Rectangle<s32> draw_rc =
|
||||
CalculateDrawRect(g_gpu_device->GetWindowWidth(), g_gpu_device->GetWindowHeight());
|
||||
const GSVector4i draw_rc = CalculateDrawRect(g_gpu_device->GetWindowWidth(), g_gpu_device->GetWindowHeight(), true);
|
||||
|
||||
// convert coordinates to active display region, then to full display region
|
||||
const float scaled_display_x = (window_x - static_cast<float>(draw_rc.left)) / static_cast<float>(draw_rc.GetWidth());
|
||||
const float scaled_display_y = (window_y - static_cast<float>(draw_rc.top)) / static_cast<float>(draw_rc.GetHeight());
|
||||
const float scaled_display_x = (window_x - static_cast<float>(draw_rc.left)) / static_cast<float>(draw_rc.width());
|
||||
const float scaled_display_y = (window_y - static_cast<float>(draw_rc.top)) / static_cast<float>(draw_rc.height());
|
||||
|
||||
// scale back to internal resolution
|
||||
*display_x = scaled_display_x * static_cast<float>(m_crtc_state.display_width);
|
||||
@ -1632,6 +1633,21 @@ void GPU::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 he
|
||||
}
|
||||
}
|
||||
|
||||
void GPU::SetClampedDrawingArea()
|
||||
{
|
||||
if (!IsDrawingAreaIsValid()) [[unlikely]]
|
||||
{
|
||||
m_clamped_drawing_area = GSVector4i::zero();
|
||||
return;
|
||||
}
|
||||
|
||||
const u32 right = std::min(m_drawing_area.right + 1, static_cast<u32>(VRAM_WIDTH));
|
||||
const u32 left = std::min(m_drawing_area.left, std::min(m_drawing_area.right, VRAM_WIDTH - 1));
|
||||
const u32 bottom = std::min(m_drawing_area.bottom + 1, static_cast<u32>(VRAM_HEIGHT));
|
||||
const u32 top = std::min(m_drawing_area.top, std::min(m_drawing_area.bottom, VRAM_HEIGHT - 1));
|
||||
m_clamped_drawing_area = GSVector4i(left, top, right, bottom);
|
||||
}
|
||||
|
||||
void GPU::SetDrawMode(u16 value)
|
||||
{
|
||||
GPUDrawModeReg new_mode_reg{static_cast<u16>(value & GPUDrawModeReg::MASK)};
|
||||
@ -1917,16 +1933,15 @@ bool GPU::PresentDisplay()
|
||||
{
|
||||
FlushRender();
|
||||
|
||||
const Common::Rectangle<s32> draw_rect =
|
||||
m_display_texture ? CalculateDrawRect(g_gpu_device->GetWindowWidth(), g_gpu_device->GetWindowHeight()) :
|
||||
Common::Rectangle<s32>();
|
||||
const GSVector4i draw_rect = m_display_texture ?
|
||||
CalculateDrawRect(g_gpu_device->GetWindowWidth(), g_gpu_device->GetWindowHeight()) :
|
||||
GSVector4i::zero();
|
||||
return RenderDisplay(nullptr, draw_rect, !g_settings.debugging.show_vram);
|
||||
}
|
||||
|
||||
bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_rect, bool postfx)
|
||||
bool GPU::RenderDisplay(GPUTexture* target, const GSVector4i draw_rect, bool postfx)
|
||||
{
|
||||
GL_SCOPE_FMT("RenderDisplay: {}x{} at {},{}", draw_rect.GetWidth(), draw_rect.GetHeight(), draw_rect.left,
|
||||
draw_rect.top);
|
||||
GL_SCOPE_FMT("RenderDisplay: {}", draw_rect);
|
||||
|
||||
if (m_display_texture)
|
||||
m_display_texture->MakeReadyForSampling();
|
||||
@ -1947,8 +1962,8 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_r
|
||||
|
||||
// Now we can apply the post chain.
|
||||
GPUTexture* post_output_texture = PostProcessing::InternalChain.GetOutputTexture();
|
||||
if (PostProcessing::InternalChain.Apply(display_texture, m_display_depth_buffer, post_output_texture, 0, 0,
|
||||
display_texture_view_width, display_texture_view_height,
|
||||
if (PostProcessing::InternalChain.Apply(display_texture, m_display_depth_buffer, post_output_texture,
|
||||
GSVector4i(0, 0, display_texture_view_width, display_texture_view_height),
|
||||
display_texture_view_width, display_texture_view_height,
|
||||
m_crtc_state.display_width, m_crtc_state.display_height))
|
||||
{
|
||||
@ -1966,7 +1981,7 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_r
|
||||
(postfx && PostProcessing::DisplayChain.IsActive() && !g_gpu_device->GetWindowInfo().IsSurfaceless() &&
|
||||
hdformat != GPUTexture::Format::Unknown && target_width > 0 && target_height > 0 &&
|
||||
PostProcessing::DisplayChain.CheckTargets(hdformat, target_width, target_height));
|
||||
const Common::Rectangle<s32> real_draw_rect =
|
||||
const GSVector4i real_draw_rect =
|
||||
g_gpu_device->UsesLowerLeftOrigin() ? GPUDevice::FlipToLowerLeft(draw_rect, target_height) : draw_rect;
|
||||
if (really_postfx)
|
||||
{
|
||||
@ -2009,11 +2024,9 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_r
|
||||
{
|
||||
texture_filter_linear = true;
|
||||
uniforms.params[0] = std::max(
|
||||
std::floor(static_cast<float>(draw_rect.GetWidth()) / static_cast<float>(m_display_texture_view_width)),
|
||||
1.0f);
|
||||
std::floor(static_cast<float>(draw_rect.width()) / static_cast<float>(m_display_texture_view_width)), 1.0f);
|
||||
uniforms.params[1] = std::max(
|
||||
std::floor(static_cast<float>(draw_rect.GetHeight()) / static_cast<float>(m_display_texture_view_height)),
|
||||
1.0f);
|
||||
std::floor(static_cast<float>(draw_rect.height()) / static_cast<float>(m_display_texture_view_height)), 1.0f);
|
||||
uniforms.params[2] = 0.5f - 0.5f / uniforms.params[0];
|
||||
uniforms.params[3] = 0.5f - 0.5f / uniforms.params[1];
|
||||
}
|
||||
@ -2048,8 +2061,7 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_r
|
||||
uniforms.src_size[3] = rcp_height;
|
||||
g_gpu_device->PushUniformBuffer(&uniforms, sizeof(uniforms));
|
||||
|
||||
g_gpu_device->SetViewportAndScissor(real_draw_rect.left, real_draw_rect.top, real_draw_rect.GetWidth(),
|
||||
real_draw_rect.GetHeight());
|
||||
g_gpu_device->SetViewportAndScissor(real_draw_rect);
|
||||
g_gpu_device->Draw(3, 0);
|
||||
}
|
||||
|
||||
@ -2066,14 +2078,11 @@ bool GPU::RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_r
|
||||
const s32 orig_height = static_cast<s32>(std::ceil(static_cast<float>(m_crtc_state.display_height) * upscale_y));
|
||||
|
||||
return PostProcessing::DisplayChain.Apply(PostProcessing::DisplayChain.GetInputTexture(), nullptr, target,
|
||||
real_draw_rect.left, real_draw_rect.top, real_draw_rect.GetWidth(),
|
||||
real_draw_rect.GetHeight(), orig_width, orig_height,
|
||||
m_crtc_state.display_width, m_crtc_state.display_height);
|
||||
real_draw_rect, orig_width, orig_height, m_crtc_state.display_width,
|
||||
m_crtc_state.display_height);
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void GPU::DestroyDeinterlaceTextures()
|
||||
@ -2303,8 +2312,7 @@ bool GPU::ApplyChromaSmoothing()
|
||||
return true;
|
||||
}
|
||||
|
||||
Common::Rectangle<s32> GPU::CalculateDrawRect(s32 window_width, s32 window_height,
|
||||
bool apply_aspect_ratio /* = true */) const
|
||||
GSVector4i GPU::CalculateDrawRect(s32 window_width, s32 window_height, bool apply_aspect_ratio /* = true */) const
|
||||
{
|
||||
const bool integer_scale = (g_settings.display_scaling == DisplayScalingMode::NearestInteger ||
|
||||
g_settings.display_scaling == DisplayScalingMode::BlinearInteger);
|
||||
@ -2401,9 +2409,11 @@ Common::Rectangle<s32> GPU::CalculateDrawRect(s32 window_width, s32 window_heigh
|
||||
}
|
||||
|
||||
// TODO: This should be a float rectangle. But because GL is lame, it only has integer viewports...
|
||||
return Common::Rectangle<s32>::FromExtents(
|
||||
static_cast<s32>(active_left * scale + left_padding), static_cast<s32>(active_top * scale + top_padding),
|
||||
static_cast<s32>(active_width * scale), static_cast<s32>(active_height * scale));
|
||||
const s32 left = static_cast<s32>(active_left * scale + left_padding);
|
||||
const s32 top = static_cast<s32>(active_top * scale + top_padding);
|
||||
const s32 right = left + static_cast<s32>(active_width * scale);
|
||||
const s32 bottom = top + static_cast<s32>(active_height * scale);
|
||||
return GSVector4i(left, top, right, bottom);
|
||||
}
|
||||
|
||||
bool CompressAndWriteTextureToFile(u32 width, u32 height, std::string filename, FileSystem::ManagedCFilePtr fp,
|
||||
@ -2575,7 +2585,7 @@ bool GPU::WriteDisplayTextureToFile(std::string filename, bool compress_on_threa
|
||||
flip_y, std::move(texture_data), texture_data_stride, m_display_texture->GetFormat(), false, compress_on_thread);
|
||||
}
|
||||
|
||||
bool GPU::RenderScreenshotToBuffer(u32 width, u32 height, const Common::Rectangle<s32>& draw_rect, bool postfx,
|
||||
bool GPU::RenderScreenshotToBuffer(u32 width, u32 height, const GSVector4i draw_rect, bool postfx,
|
||||
std::vector<u32>* out_pixels, u32* out_stride, GPUTexture::Format* out_format)
|
||||
{
|
||||
const GPUTexture::Format hdformat =
|
||||
@ -2627,15 +2637,15 @@ bool GPU::RenderScreenshotToFile(std::string filename, DisplayScreenshotMode mod
|
||||
{
|
||||
u32 width = g_gpu_device->GetWindowWidth();
|
||||
u32 height = g_gpu_device->GetWindowHeight();
|
||||
Common::Rectangle<s32> draw_rect = CalculateDrawRect(width, height);
|
||||
GSVector4i draw_rect = CalculateDrawRect(width, height, true);
|
||||
|
||||
const bool internal_resolution = (mode != DisplayScreenshotMode::ScreenResolution || g_settings.debugging.show_vram);
|
||||
if (internal_resolution && m_display_texture_view_width != 0 && m_display_texture_view_height != 0)
|
||||
{
|
||||
if (mode == DisplayScreenshotMode::InternalResolution)
|
||||
{
|
||||
const u32 draw_width = static_cast<u32>(draw_rect.GetWidth());
|
||||
const u32 draw_height = static_cast<u32>(draw_rect.GetHeight());
|
||||
const u32 draw_width = static_cast<u32>(draw_rect.width());
|
||||
const u32 draw_height = static_cast<u32>(draw_rect.height());
|
||||
|
||||
// If internal res, scale the computed draw rectangle to the internal res.
|
||||
// We re-use the draw rect because it's already been AR corrected.
|
||||
@ -2679,7 +2689,7 @@ bool GPU::RenderScreenshotToFile(std::string filename, DisplayScreenshotMode mod
|
||||
}
|
||||
|
||||
// Remove padding, it's not part of the framebuffer.
|
||||
draw_rect.Set(0, 0, static_cast<s32>(width), static_cast<s32>(height));
|
||||
draw_rect = GSVector4i(0, 0, static_cast<s32>(width), static_cast<s32>(height));
|
||||
}
|
||||
if (width == 0 || height == 0)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user