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;
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
|
||||
#include "common/bitfield.h"
|
||||
#include "common/fifo_queue.h"
|
||||
#include "common/rectangle.h"
|
||||
#include "common/types.h"
|
||||
|
||||
#include <algorithm>
|
||||
@ -208,13 +207,13 @@ public:
|
||||
virtual void FlushRender() = 0;
|
||||
|
||||
/// Helper function for computing the draw rectangle in a larger window.
|
||||
Common::Rectangle<s32> CalculateDrawRect(s32 window_width, s32 window_height, bool apply_aspect_ratio = true) const;
|
||||
GSVector4i CalculateDrawRect(s32 window_width, s32 window_height, bool apply_aspect_ratio = true) const;
|
||||
|
||||
/// Helper function to save current display texture to PNG.
|
||||
bool WriteDisplayTextureToFile(std::string filename, bool compress_on_thread = false);
|
||||
|
||||
/// Renders the display, optionally with postprocessing to the specified image.
|
||||
bool RenderScreenshotToBuffer(u32 width, u32 height, const Common::Rectangle<s32>& draw_rect, bool postfx,
|
||||
bool RenderScreenshotToBuffer(u32 width, u32 height, const GSVector4i draw_rect, bool postfx,
|
||||
std::vector<u32>* out_pixels, u32* out_stride, GPUTexture::Format* out_format);
|
||||
|
||||
/// Helper function to save screenshot to PNG.
|
||||
@ -276,6 +275,9 @@ protected:
|
||||
/// Returns 0 if the currently-displayed field is on an even line in VRAM, otherwise 1.
|
||||
ALWAYS_INLINE u32 GetActiveLineLSB() const { return ZeroExtend32(m_crtc_state.active_line_lsb); }
|
||||
|
||||
/// Updates drawing area that's suitablef or clamping.
|
||||
void SetClampedDrawingArea();
|
||||
|
||||
/// Sets/decodes GP0(E1h) (set draw mode).
|
||||
void SetDrawMode(u16 bits);
|
||||
|
||||
@ -323,23 +325,21 @@ protected:
|
||||
virtual void DrawRendererStats();
|
||||
virtual void OnBufferSwapped();
|
||||
|
||||
ALWAYS_INLINE_RELEASE void AddDrawTriangleTicks(s32 x1, s32 y1, s32 x2, s32 y2, s32 x3, s32 y3, bool shaded,
|
||||
ALWAYS_INLINE_RELEASE void AddDrawTriangleTicks(GSVector4i v1, GSVector4i v2, GSVector4i v3, bool shaded,
|
||||
bool textured, bool semitransparent)
|
||||
{
|
||||
// This will not produce the correct results for triangles which are partially outside the clip area.
|
||||
// However, usually it'll undershoot not overshoot. If we wanted to make this more accurate, we'd need to intersect
|
||||
// the edges with the clip rectangle.
|
||||
// TODO: Coordinates are exclusive, so off by one here...
|
||||
const s32 clip_right = static_cast<s32>(m_drawing_area.right) + 1;
|
||||
const s32 clip_bottom = static_cast<s32>(m_drawing_area.bottom) + 1;
|
||||
x1 = std::clamp(x1, static_cast<s32>(m_drawing_area.left), clip_right);
|
||||
x2 = std::clamp(x2, static_cast<s32>(m_drawing_area.left), clip_right);
|
||||
x3 = std::clamp(x3, static_cast<s32>(m_drawing_area.left), clip_right);
|
||||
y1 = std::clamp(y1, static_cast<s32>(m_drawing_area.top), clip_bottom);
|
||||
y2 = std::clamp(y2, static_cast<s32>(m_drawing_area.top), clip_bottom);
|
||||
y3 = std::clamp(y3, static_cast<s32>(m_drawing_area.top), clip_bottom);
|
||||
const GSVector4i clamp_min = m_clamped_drawing_area; // would be xyxy(), but zw isn't used.
|
||||
const GSVector4i clamp_max = m_clamped_drawing_area.zwzw();
|
||||
v1 = v1.sat_i32(clamp_min, clamp_max);
|
||||
v2 = v2.sat_i32(clamp_min, clamp_max);
|
||||
v3 = v3.sat_i32(clamp_min, clamp_max);
|
||||
|
||||
TickCount pixels = std::abs((x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x2 * y1 - x3 * y2) / 2);
|
||||
TickCount pixels =
|
||||
std::abs((v1.x * v2.y + v2.x * v3.y + v3.x * v1.y - v1.x * v3.y - v2.x * v1.y - v3.x * v2.y) / 2);
|
||||
if (textured)
|
||||
pixels += pixels;
|
||||
if (semitransparent || m_GPUSTAT.check_mask_before_draw)
|
||||
@ -479,6 +479,7 @@ protected:
|
||||
|
||||
GPUDrawingArea m_drawing_area = {};
|
||||
GPUDrawingOffset m_drawing_offset = {};
|
||||
GSVector4i m_clamped_drawing_area = {};
|
||||
|
||||
bool m_console_is_pal = false;
|
||||
bool m_set_texture_disable_mask = false;
|
||||
@ -609,7 +610,7 @@ protected:
|
||||
void SetDisplayTexture(GPUTexture* texture, GPUTexture* depth_texture, s32 view_x, s32 view_y, s32 view_width,
|
||||
s32 view_height);
|
||||
|
||||
bool RenderDisplay(GPUTexture* target, const Common::Rectangle<s32>& draw_rect, bool postfx);
|
||||
bool RenderDisplay(GPUTexture* target, const GSVector4i draw_rect, bool postfx);
|
||||
|
||||
bool Deinterlace(u32 field, u32 line_skip);
|
||||
bool DeinterlaceExtractField(u32 dst_bufidx, GPUTexture* src, u32 x, u32 y, u32 width, u32 height, u32 line_skip);
|
||||
|
||||
@ -250,6 +250,7 @@ bool GPU::HandleSetDrawingAreaTopLeftCommand()
|
||||
m_drawing_area.left = left;
|
||||
m_drawing_area.top = top;
|
||||
m_drawing_area_changed = true;
|
||||
SetClampedDrawingArea();
|
||||
}
|
||||
|
||||
AddCommandTicks(1);
|
||||
@ -271,6 +272,7 @@ bool GPU::HandleSetDrawingAreaBottomRightCommand()
|
||||
m_drawing_area.right = right;
|
||||
m_drawing_area.bottom = bottom;
|
||||
m_drawing_area_changed = true;
|
||||
SetClampedDrawingArea();
|
||||
}
|
||||
|
||||
AddCommandTicks(1);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
@ -9,10 +9,10 @@
|
||||
#include "util/gpu_device.h"
|
||||
|
||||
#include "common/dimensional_array.h"
|
||||
#include "common/gsvector.h"
|
||||
#include "common/heap_array.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <limits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@ -122,8 +122,7 @@ private:
|
||||
|
||||
struct BatchUBOData
|
||||
{
|
||||
u32 u_texture_window_and[2];
|
||||
u32 u_texture_window_or[2];
|
||||
u32 u_texture_window[4]; // and_x, and_y, or_x, or_y
|
||||
float u_src_alpha_factor;
|
||||
float u_dst_alpha_factor;
|
||||
u32 u_interlaced_displayed_field;
|
||||
@ -137,6 +136,11 @@ private:
|
||||
u32 num_uniform_buffer_updates;
|
||||
};
|
||||
|
||||
static constexpr GSVector4i VRAM_SIZE_RECT = GSVector4i::cxpr(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
||||
static constexpr GSVector4i INVALID_RECT =
|
||||
GSVector4i::cxpr(std::numeric_limits<s32>::max(), std::numeric_limits<s32>::max(), std::numeric_limits<s32>::min(),
|
||||
std::numeric_limits<s32>::min());
|
||||
|
||||
/// Returns true if a depth buffer should be created.
|
||||
bool NeedsDepthBuffer() const;
|
||||
GPUTexture::Format GetDepthBufferFormat() const;
|
||||
@ -153,7 +157,6 @@ private:
|
||||
void PrintSettingsToLog();
|
||||
void CheckSettings();
|
||||
|
||||
void SetClampedDrawingArea();
|
||||
void UpdateVRAMReadTexture(bool drawn, bool written);
|
||||
void UpdateDepthBufferFromMaskBit();
|
||||
void CopyAndClearDepthBuffer();
|
||||
@ -172,9 +175,9 @@ private:
|
||||
|
||||
void SetFullVRAMDirtyRectangle();
|
||||
void ClearVRAMDirtyRectangle();
|
||||
void IncludeVRAMDirtyRectangle(Common::Rectangle<u32>& rect, const Common::Rectangle<u32>& new_rect);
|
||||
void IncludeDrawnDirtyRectangle(s32 min_x, s32 min_y, s32 max_x, s32 max_y);
|
||||
void CheckForTexPageOverlap(u32 texpage, u32 min_u, u32 min_v, u32 max_u, u32 max_v);
|
||||
void IncludeVRAMDirtyRectangle(GSVector4i& rect, const GSVector4i new_rect);
|
||||
void IncludeDrawnDirtyRectangle(const GSVector4i rect);
|
||||
void CheckForTexPageOverlap(GSVector4i uv_rect);
|
||||
|
||||
bool IsFlushed() const;
|
||||
void EnsureVertexBufferSpace(u32 required_vertices, u32 required_indices);
|
||||
@ -205,7 +208,7 @@ private:
|
||||
void OnBufferSwapped() override;
|
||||
|
||||
void UpdateVRAMOnGPU(u32 x, u32 y, u32 width, u32 height, const void* data, u32 data_pitch, bool set_mask,
|
||||
bool check_mask, const Common::Rectangle<u32>& bounds);
|
||||
bool check_mask, const GSVector4i bounds);
|
||||
bool BlitVRAMReplacementTexture(const TextureReplacementTexture* tex, u32 dst_x, u32 dst_y, u32 width, u32 height);
|
||||
|
||||
/// Expands a line into two triangles.
|
||||
@ -214,10 +217,10 @@ private:
|
||||
/// Handles quads with flipped texture coordinate directions.
|
||||
void HandleFlippedQuadTextureCoordinates(BatchVertex* vertices);
|
||||
bool IsPossibleSpritePolygon(const BatchVertex* vertices) const;
|
||||
void ExpandLineTriangles(BatchVertex* vertices, u32 base_vertex);
|
||||
bool ExpandLineTriangles(BatchVertex* vertices);
|
||||
|
||||
/// Computes polygon U/V boundaries.
|
||||
void ComputePolygonUVLimits(u32 texpage, BatchVertex* vertices, u32 num_vertices);
|
||||
/// Computes polygon U/V boundaries, and for overlap with the current texture page.
|
||||
void ComputePolygonUVLimits(BatchVertex* vertices, u32 num_vertices);
|
||||
|
||||
/// Sets the depth test flag for PGXP depth buffering.
|
||||
void SetBatchDepthBuffer(bool enabled);
|
||||
@ -271,9 +274,10 @@ private:
|
||||
bool m_compute_uv_range : 1 = false;
|
||||
bool m_allow_sprite_mode : 1 = false;
|
||||
bool m_allow_shader_blend : 1 = false;
|
||||
bool m_depth_was_copied : 1 = false;
|
||||
bool m_texture_window_active : 1 = false;
|
||||
|
||||
u8 m_texpage_dirty = 0;
|
||||
bool m_depth_was_copied = false;
|
||||
|
||||
BatchConfig m_batch;
|
||||
|
||||
@ -282,10 +286,10 @@ private:
|
||||
BatchUBOData m_batch_ubo_data = {};
|
||||
|
||||
// Bounding box of VRAM area that the GPU has drawn into.
|
||||
GPUDrawingArea m_clamped_drawing_area = {};
|
||||
Common::Rectangle<u32> m_vram_dirty_draw_rect;
|
||||
Common::Rectangle<u32> m_vram_dirty_write_rect;
|
||||
Common::Rectangle<u32> m_current_uv_range;
|
||||
GSVector4i m_vram_dirty_draw_rect = INVALID_RECT;
|
||||
GSVector4i m_vram_dirty_write_rect = INVALID_RECT;
|
||||
GSVector4i m_current_uv_range = INVALID_RECT;
|
||||
GSVector2i m_current_texture_page_offset = {};
|
||||
|
||||
std::unique_ptr<GPUPipeline> m_wireframe_pipeline;
|
||||
|
||||
|
||||
@ -523,6 +523,7 @@ void GPU_SW::DispatchRenderCommand()
|
||||
GPUBackendDrawPolygonCommand* cmd = m_backend.NewDrawPolygonCommand(num_vertices);
|
||||
FillDrawCommand(cmd, rc);
|
||||
|
||||
std::array<GSVector4i, 4> positions;
|
||||
const u32 first_color = rc.color_for_first_vertex;
|
||||
const bool shaded = rc.shading_enable;
|
||||
const bool textured = rc.texture_enable;
|
||||
@ -535,49 +536,55 @@ void GPU_SW::DispatchRenderCommand()
|
||||
vert->x = m_drawing_offset.x + vp.x;
|
||||
vert->y = m_drawing_offset.y + vp.y;
|
||||
vert->texcoord = textured ? Truncate16(FifoPop()) : 0;
|
||||
positions[i] = GSVector4i::loadl(&vert->x);
|
||||
}
|
||||
|
||||
if (!IsDrawingAreaIsValid())
|
||||
return;
|
||||
|
||||
// Cull polygons which are too large.
|
||||
const auto [min_x_12, max_x_12] = MinMax(cmd->vertices[1].x, cmd->vertices[2].x);
|
||||
const auto [min_y_12, max_y_12] = MinMax(cmd->vertices[1].y, cmd->vertices[2].y);
|
||||
const s32 min_x = std::min(min_x_12, cmd->vertices[0].x);
|
||||
const s32 max_x = std::max(max_x_12, cmd->vertices[0].x);
|
||||
const s32 min_y = std::min(min_y_12, cmd->vertices[0].y);
|
||||
const s32 max_y = std::max(max_y_12, cmd->vertices[0].y);
|
||||
|
||||
if ((max_x - min_x) >= MAX_PRIMITIVE_WIDTH || (max_y - min_y) >= MAX_PRIMITIVE_HEIGHT)
|
||||
const GSVector4i min_pos_12 = positions[1].min_i32(positions[2]);
|
||||
const GSVector4i max_pos_12 = positions[1].max_i32(positions[2]);
|
||||
const GSVector4i draw_rect_012 =
|
||||
min_pos_12.min_i32(positions[0]).upl64(max_pos_12.max_i32(positions[0])).add32(GSVector4i::cxpr(0, 0, 1, 1));
|
||||
const bool first_tri_culled =
|
||||
(draw_rect_012.width() > MAX_PRIMITIVE_WIDTH || draw_rect_012.height() > MAX_PRIMITIVE_HEIGHT ||
|
||||
!m_clamped_drawing_area.rintersects(draw_rect_012));
|
||||
if (first_tri_culled)
|
||||
{
|
||||
DEBUG_LOG("Culling too-large polygon: {},{} {},{} {},{}", cmd->vertices[0].x, cmd->vertices[0].y,
|
||||
DEBUG_LOG("Culling off-screen/too-large polygon: {},{} {},{} {},{}", cmd->vertices[0].x, cmd->vertices[0].y,
|
||||
cmd->vertices[1].x, cmd->vertices[1].y, cmd->vertices[2].x, cmd->vertices[2].y);
|
||||
|
||||
if (!rc.quad_polygon)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddDrawTriangleTicks(cmd->vertices[0].x, cmd->vertices[0].y, cmd->vertices[1].x, cmd->vertices[1].y,
|
||||
cmd->vertices[2].x, cmd->vertices[2].y, rc.shading_enable, rc.texture_enable,
|
||||
AddDrawTriangleTicks(positions[0], positions[1], positions[2], rc.shading_enable, rc.texture_enable,
|
||||
rc.transparency_enable);
|
||||
}
|
||||
|
||||
// quads
|
||||
if (rc.quad_polygon)
|
||||
{
|
||||
const s32 min_x_123 = std::min(min_x_12, cmd->vertices[3].x);
|
||||
const s32 max_x_123 = std::max(max_x_12, cmd->vertices[3].x);
|
||||
const s32 min_y_123 = std::min(min_y_12, cmd->vertices[3].y);
|
||||
const s32 max_y_123 = std::max(max_y_12, cmd->vertices[3].y);
|
||||
const GSVector4i draw_rect_123 =
|
||||
min_pos_12.min_i32(positions[3]).upl64(max_pos_12.max_i32(positions[3])).add32(GSVector4i::cxpr(0, 0, 1, 1));
|
||||
|
||||
// Cull polygons which are too large.
|
||||
if ((max_x_123 - min_x_123) >= MAX_PRIMITIVE_WIDTH || (max_y_123 - min_y_123) >= MAX_PRIMITIVE_HEIGHT)
|
||||
const bool second_tri_culled =
|
||||
(draw_rect_123.width() > MAX_PRIMITIVE_WIDTH || draw_rect_123.height() > MAX_PRIMITIVE_HEIGHT ||
|
||||
!m_clamped_drawing_area.rintersects(draw_rect_123));
|
||||
if (second_tri_culled)
|
||||
{
|
||||
DEBUG_LOG("Culling too-large polygon (quad second half): {},{} {},{} {},{}", cmd->vertices[2].x,
|
||||
cmd->vertices[2].y, cmd->vertices[1].x, cmd->vertices[1].y, cmd->vertices[0].x, cmd->vertices[0].y);
|
||||
|
||||
if (first_tri_culled)
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
AddDrawTriangleTicks(cmd->vertices[2].x, cmd->vertices[2].y, cmd->vertices[1].x, cmd->vertices[1].y,
|
||||
cmd->vertices[3].x, cmd->vertices[3].y, rc.shading_enable, rc.texture_enable,
|
||||
AddDrawTriangleTicks(positions[2], positions[1], positions[3], rc.shading_enable, rc.texture_enable,
|
||||
rc.transparency_enable);
|
||||
}
|
||||
}
|
||||
@ -627,12 +634,6 @@ void GPU_SW::DispatchRenderCommand()
|
||||
const u32 width_and_height = FifoPop();
|
||||
cmd->width = static_cast<u16>(width_and_height & VRAM_WIDTH_MASK);
|
||||
cmd->height = static_cast<u16>((width_and_height >> 16) & VRAM_HEIGHT_MASK);
|
||||
|
||||
if (cmd->width >= MAX_PRIMITIVE_WIDTH || cmd->height >= MAX_PRIMITIVE_HEIGHT)
|
||||
{
|
||||
DEBUG_LOG("Culling too-large rectangle: {},{} {}x{}", cmd->x, cmd->y, cmd->width, cmd->height);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#pragma once
|
||||
#include "common/bitfield.h"
|
||||
#include "common/bitutils.h"
|
||||
#include "common/rectangle.h"
|
||||
#include "common/gsvector.h"
|
||||
#include "types.h"
|
||||
#include <array>
|
||||
|
||||
@ -189,18 +189,19 @@ union GPUDrawModeReg
|
||||
BitField<u16, bool, 12, 1> texture_x_flip;
|
||||
BitField<u16, bool, 13, 1> texture_y_flip;
|
||||
|
||||
ALWAYS_INLINE u16 GetTexturePageBaseX() const { return ZeroExtend16(texture_page_x_base.GetValue()) * 64; }
|
||||
ALWAYS_INLINE u16 GetTexturePageBaseY() const { return ZeroExtend16(texture_page_y_base.GetValue()) * 256; }
|
||||
ALWAYS_INLINE u32 GetTexturePageBaseX() const { return ZeroExtend32(texture_page_x_base.GetValue()) * 64; }
|
||||
ALWAYS_INLINE u32 GetTexturePageBaseY() const { return ZeroExtend32(texture_page_y_base.GetValue()) * 256; }
|
||||
|
||||
/// Returns true if the texture mode requires a palette.
|
||||
ALWAYS_INLINE bool IsUsingPalette() const { return (bits & (2 << 7)) == 0; }
|
||||
|
||||
/// Returns a rectangle comprising the texture page area.
|
||||
ALWAYS_INLINE_RELEASE Common::Rectangle<u32> GetTexturePageRectangle() const
|
||||
ALWAYS_INLINE_RELEASE GSVector4i GetTexturePageRectangle() const
|
||||
{
|
||||
return Common::Rectangle<u32>::FromExtents(GetTexturePageBaseX(), GetTexturePageBaseY(),
|
||||
texture_page_widths[static_cast<u8>(texture_mode.GetValue())],
|
||||
TEXTURE_PAGE_HEIGHT);
|
||||
const u32 base_x = GetTexturePageBaseX();
|
||||
const u32 base_y = GetTexturePageBaseY();
|
||||
return GSVector4i(base_x, base_y, base_x + texture_page_widths[static_cast<u8>(texture_mode.GetValue())],
|
||||
base_y + TEXTURE_PAGE_HEIGHT);
|
||||
}
|
||||
};
|
||||
|
||||
@ -217,10 +218,12 @@ union GPUTexturePaletteReg
|
||||
ALWAYS_INLINE u32 GetYBase() const { return static_cast<u32>(y); }
|
||||
|
||||
/// Returns a rectangle comprising the texture palette area.
|
||||
ALWAYS_INLINE_RELEASE Common::Rectangle<u32> GetRectangle(GPUTextureMode mode) const
|
||||
ALWAYS_INLINE_RELEASE GSVector4i GetRectangle(GPUTextureMode mode) const
|
||||
{
|
||||
static constexpr std::array<u32, 4> palette_widths = {{16, 256, 0, 0}};
|
||||
return Common::Rectangle<u32>::FromExtents(GetXBase(), GetYBase(), palette_widths[static_cast<u8>(mode)], 1);
|
||||
const u32 base_x = GetXBase();
|
||||
const u32 base_y = GetYBase();
|
||||
return GSVector4i(base_x, base_y, base_x + palette_widths[static_cast<u8>(mode)], base_y + 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@ -2727,8 +2727,8 @@ bool System::SaveStateToStream(ByteStream* state, Error* error, u32 screenshot_s
|
||||
u32 screenshot_stride;
|
||||
GPUTexture::Format screenshot_format;
|
||||
if (g_gpu->RenderScreenshotToBuffer(screenshot_width, screenshot_height,
|
||||
Common::Rectangle<s32>::FromExtents(0, 0, screenshot_width, screenshot_height),
|
||||
false, &screenshot_buffer, &screenshot_stride, &screenshot_format) &&
|
||||
GSVector4i(0, 0, screenshot_width, screenshot_height), false,
|
||||
&screenshot_buffer, &screenshot_stride, &screenshot_format) &&
|
||||
GPUTexture::ConvertTextureDataToRGBA8(screenshot_width, screenshot_height, screenshot_buffer, screenshot_stride,
|
||||
screenshot_format))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user