2019-09-12 12:53:04 +10:00
|
|
|
#include "gpu_hw.h"
|
2019-11-05 22:34:27 +10:00
|
|
|
#include "common/state_wrapper.h"
|
2020-08-02 00:25:07 +10:00
|
|
|
#include "cpu_core.h"
|
2021-05-19 13:43:49 +10:00
|
|
|
#include "gpu_sw_backend.h"
|
2020-08-02 00:25:07 +10:00
|
|
|
#include "pgxp.h"
|
2019-11-02 00:31:25 +10:00
|
|
|
#include "settings.h"
|
|
|
|
|
#include "system.h"
|
2020-08-02 18:04:00 +10:00
|
|
|
#include <cmath>
|
common/types: drop <cstring>, add explicit includes at the 41 callers
types.h carried <cstring> for transitive purposes only - the header
itself never references std::memcpy / std::memset / std::strlen
etc. 41 TUs across the tree used those C-string functions while
relying on types.h to supply the declaration.
Add an explicit '#include <cstring>' to each of those files and
drop it from types.h. The headers that also use cstring functions
(error.h, jit_code_buffer.h are not in the list because they
already include <cstring> directly, or use the C-namespace
<string.h> already in scope) are unaffected.
Files getting an explicit <cstring>:
src/common: cd_image.cpp, cd_image_ecm.cpp, cd_image_mds.cpp,
cd_image_memory.cpp, cd_image_pbp.cpp,
cd_image_ppf.cpp, cd_subchannel_replacement.cpp,
cue_parser.cpp, d3d12/shader_cache.cpp,
d3d12/staging_texture.cpp, d3d12/texture.cpp,
d3d12/util.cpp, iso_reader.cpp, jit_code_buffer.cpp,
md5_digest.cpp, vulkan/shader_cache.cpp,
vulkan/staging_texture.cpp
src/core: bios.cpp, bios.h, bus.cpp, cdrom.cpp, cheats.cpp,
cpu_code_cache.cpp, cpu_recompiler_code_generator.cpp,
cpu_recompiler_register_cache.cpp, dma.cpp, gpu.cpp,
gpu_hw.cpp, gpu_hw.h, gpu_hw_d3d11.cpp,
gpu_hw_d3d12.cpp, gpu_hw_opengl.cpp,
gpu_hw_vulkan.cpp, gpu_sw.cpp, gte.cpp, mdec.cpp,
memory_card_image.cpp, pgxp.cpp, spu.cpp, system.cpp
src/libretro: libretro_host_display.cpp
Most files get one '#include <cstring>' added into the existing
system-include block, sorted alphabetically. A handful of files
(system.cpp, memory_card_image.cpp, d3d12/shader_cache.cpp)
had pre-existing blank-line separations between the stdlib
include block and libretro third-party headers (<compat/strl.h>,
<file/file_path.h>); those separations are preserved.
Build: Makefile.libretro platform=unix - clean, no warnings.
swanstation_libretro.so size unchanged (8026128 bytes).
retro_* exports: 25 (unchanged).
types.h now only includes <cstddef>, <cstdint>, and <type_traits>
- the three headers it actually needs for its own contents.
2026-05-14 12:18:34 +00:00
|
|
|
#include <cstring>
|
2020-08-03 03:06:03 +10:00
|
|
|
#include <sstream>
|
2020-08-02 17:32:43 +10:00
|
|
|
#include <tuple>
|
2022-09-12 01:13:23 +02:00
|
|
|
#define IS_POW2(value) (((value) & ((value) - 1)) == 0)
|
|
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
template<typename T>
|
|
|
|
|
ALWAYS_INLINE static constexpr std::tuple<T, T> MinMax(T v1, T v2)
|
|
|
|
|
{
|
|
|
|
|
if (v1 > v2)
|
|
|
|
|
return std::tie(v2, v1);
|
2022-06-24 07:54:25 +02:00
|
|
|
return std::tie(v1, v2);
|
2020-08-02 17:17:05 +10:00
|
|
|
}
|
|
|
|
|
|
2022-06-24 20:06:14 +02:00
|
|
|
|
2020-08-10 22:37:30 +10:00
|
|
|
ALWAYS_INLINE static bool ShouldUseUVLimits()
|
|
|
|
|
{
|
|
|
|
|
// We only need UV limits if PGXP is enabled, or texture filtering is enabled.
|
2020-09-11 22:20:19 +10:00
|
|
|
return g_settings.gpu_pgxp_enable || g_settings.gpu_texture_filter != GPUTextureFilter::Nearest;
|
2020-08-10 22:37:30 +10:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 14:04:28 +01:00
|
|
|
ALWAYS_INLINE static bool ShouldDisableColorPerspective()
|
|
|
|
|
{
|
|
|
|
|
return g_settings.gpu_pgxp_enable && g_settings.gpu_pgxp_texture_correction && !g_settings.gpu_pgxp_color_correction;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-02 00:25:07 +10:00
|
|
|
GPU_HW::GPU_HW() : GPU()
|
|
|
|
|
{
|
2022-01-21 21:14:41 +01:00
|
|
|
m_vram_ptr = m_vram_shadow.data();
|
2020-08-02 00:25:07 +10:00
|
|
|
}
|
2019-09-12 12:53:04 +10:00
|
|
|
|
2021-05-19 13:43:49 +10:00
|
|
|
GPU_HW::~GPU_HW()
|
|
|
|
|
{
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
m_sw_renderer->Shutdown();
|
|
|
|
|
m_sw_renderer.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-12 12:53:04 +10:00
|
|
|
|
2020-07-31 17:09:18 +10:00
|
|
|
bool GPU_HW::Initialize(HostDisplay* host_display)
|
2019-11-05 22:34:27 +10:00
|
|
|
{
|
2020-07-31 17:09:18 +10:00
|
|
|
if (!GPU::Initialize(host_display))
|
2019-11-05 22:34:27 +10:00
|
|
|
return false;
|
|
|
|
|
|
2020-08-03 03:06:03 +10:00
|
|
|
m_resolution_scale = CalculateResolutionScale();
|
2020-10-31 00:38:06 +10:00
|
|
|
m_multisamples = std::min(g_settings.gpu_multisamples, m_max_multisamples);
|
2020-05-03 17:11:28 +10:00
|
|
|
m_render_api = host_display->GetRenderAPI();
|
2020-10-31 00:38:06 +10:00
|
|
|
m_per_sample_shading = g_settings.gpu_per_sample_shading && m_supports_per_sample_shading;
|
2020-07-31 17:09:18 +10:00
|
|
|
m_true_color = g_settings.gpu_true_color;
|
|
|
|
|
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
2020-09-11 22:20:19 +10:00
|
|
|
m_texture_filtering = g_settings.gpu_texture_filter;
|
2020-08-10 22:37:30 +10:00
|
|
|
m_using_uv_limits = ShouldUseUVLimits();
|
2020-11-03 14:17:51 +10:00
|
|
|
m_chroma_smoothing = g_settings.gpu_24bit_chroma_smoothing;
|
2020-12-30 16:26:20 +10:00
|
|
|
m_downsample_mode = GetDownsampleMode(m_resolution_scale);
|
2023-02-09 14:04:28 +01:00
|
|
|
m_disable_color_perspective = m_supports_disable_color_perspective && ShouldDisableColorPerspective();
|
gpu_hw: trigger shader recompile on runtime swanstation_GPU_ShaderPrecompile change
Reported bug: flipping the swanstation_GPU_ShaderPrecompile core
option between Lazy / Enabled / Disabled at runtime had no
immediate effect. The new mode wouldn't take effect until the
user changed some OTHER shader-affecting setting (texture filter,
resolution scale, multisampling, etc.) that triggered the existing
destroy/recompile path.
Root cause: GPU_HW::UpdateHWSettings's shaders_changed predicate
checked 11 fields (resolution_scale, multisamples, true_color,
per_sample_shading, scaled_dithering, texture_filter, uv_limits,
chroma_smoothing, downsample_mode, pgxp_depth_buffer,
disable_color_perspective) but NOT g_settings.gpu_shader_precompile_mode.
So a pure precompile-mode flip computed shaders_changed = false,
the per-backend UpdateSettings skipped the DestroyPipelines /
CompilePipelines round-trip, and:
- Lazy -> Disabled: the background worker that was already
spawned just kept running until it naturally finished filling
the matrix (~30 seconds on heavy filters). The user-visible
'Disabled' semantics didn't apply until then.
- Disabled -> Lazy: no worker spawn happened. Each draw kept
paying first-use compile cost on the runloop. The user got
Disabled behaviour while the setting said Lazy.
- {Lazy, Disabled} -> Enabled: no synchronous full precompile
happened. The user expected 'block until done' and got
whatever state the matrix was in.
- Enabled -> {Lazy, Disabled}: the matrix was already fully
populated from the Enabled-mode sync pass, so this only had
bearing on FUTURE recompile cycles. Still wrong but the
least-visible case.
Fix: add m_shader_precompile_mode as the cached previous value
(seeded in GPU_HW::Initialize from g_settings.gpu_shader_precompile_mode,
re-stored every UpdateHWSettings call alongside the other field
copies). Include it in the shaders_changed predicate.
After this patch a runtime flip triggers shaders_changed = true,
which calls into the per-backend UpdateSettings's normal
destroy/recompile path:
- Lazy -> Disabled: DestroyPipelines calls StopShaderCompileThread
which joins the worker; CompilePipelines runs in Disabled
mode (skips the precompile matrix, doesn't spawn a worker).
The worker is gone within at most one in-flight cell's
compile worth of latency.
- Disabled -> Lazy: DestroyPipelines is a no-op for the worker
(none running); CompilePipelines runs in Lazy mode (skips
the precompile matrix, spawns a worker that fills the matrix
asynchronously).
- Disabled -> Enabled: full sync precompile on the calling
thread - the documented Enabled-mode behaviour. The frontend
blocks for tens of seconds on cold disk cache; cached, it's
a few seconds.
- Enabled -> Lazy / Disabled: matrix destroyed, recompiled
according to the new mode. Symmetric with the other cases.
- Lazy -> Enabled or vice versa with an in-flight worker:
DestroyPipelines joins the in-flight worker first, then
CompilePipelines starts fresh in the new mode.
Cost is one full destroy/recompile cycle on each precompile-mode
flip - same cost path the existing 11 settings already pay. For
Lazy and Disabled this is roughly 100-300 ms of teardown plus
non-batch shader rebuild. For Enabled it's that plus the actual
sync precompile of the batch matrix, dominated by driver compile
time (10-40s cold, sub-second from disk cache). The cell-fill
work hits the disk shader cache so it's only expensive on the
first time any given (filter, scale, ...) tuple is seen.
We could have written more precise handling - 'on Lazy ->
Disabled just stop the worker, keep the populated matrix' - but
that's a more complex patch and the simple destroy/recompile path
is well-trodden, well-tested, and the user already pays this cost
for any other shader-affecting setting change. Symmetry trumps
the small redundant work in the Lazy <-> Disabled case.
Files touched:
- src/core/gpu_hw.h: m_shader_precompile_mode member added.
- src/core/gpu_hw.cpp: Initialize seeds it from g_settings;
UpdateHWSettings includes it in shaders_changed predicate
and writes the latest value back.
Build verification: linux platform=unix clean, zero warnings,
zero errors. .so size 8040152 unchanged (one u8-sized field and
one extra comparison, well within an existing structure-padding
slot). 25 retro_* exports unchanged.
2026-05-11 18:19:44 +00:00
|
|
|
m_shader_precompile_mode = g_settings.gpu_shader_precompile_mode;
|
2020-10-31 00:38:06 +10:00
|
|
|
|
|
|
|
|
if (m_multisamples != g_settings.gpu_multisamples)
|
|
|
|
|
{
|
|
|
|
|
g_host_interface->AddFormattedOSDMessage(
|
|
|
|
|
20.0f, g_host_interface->TranslateString("OSDMessage", "%ux MSAA is not supported, using %ux instead."),
|
|
|
|
|
g_settings.gpu_multisamples, m_multisamples);
|
|
|
|
|
}
|
|
|
|
|
if (!m_per_sample_shading && g_settings.gpu_per_sample_shading)
|
|
|
|
|
{
|
|
|
|
|
g_host_interface->AddOSDMessage(
|
|
|
|
|
g_host_interface->TranslateStdString("OSDMessage", "SSAA is not supported, using MSAA instead."), 20.0f);
|
|
|
|
|
}
|
2020-11-10 20:55:35 +10:00
|
|
|
if (!m_supports_dual_source_blend && TextureFilterRequiresDualSourceBlend(m_texture_filtering))
|
|
|
|
|
{
|
|
|
|
|
m_texture_filtering = GPUTextureFilter::Nearest;
|
|
|
|
|
}
|
2020-12-30 16:26:20 +10:00
|
|
|
if (!m_supports_adaptive_downsampling && g_settings.gpu_resolution_scale > 1 &&
|
|
|
|
|
g_settings.gpu_downsample_mode == GPUDownsampleMode::Adaptive)
|
|
|
|
|
{
|
|
|
|
|
g_host_interface->AddOSDMessage(
|
|
|
|
|
g_host_interface->TranslateStdString(
|
|
|
|
|
"OSDMessage", "Adaptive downsampling is not supported with the current renderer, using box filter instead."),
|
|
|
|
|
20.0f);
|
|
|
|
|
}
|
2020-10-31 00:38:06 +10:00
|
|
|
|
2021-01-01 17:48:58 +10:00
|
|
|
m_pgxp_depth_buffer = g_settings.UsingPGXPDepthBuffer();
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
UpdateSoftwareRenderer(false);
|
|
|
|
|
|
2019-11-05 22:34:27 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-23 19:00:54 +10:00
|
|
|
void GPU_HW::Reset(bool clear_vram)
|
2019-10-04 20:33:37 +10:00
|
|
|
{
|
2021-01-23 19:00:54 +10:00
|
|
|
GPU::Reset(clear_vram);
|
2019-10-04 20:33:37 +10:00
|
|
|
|
2020-05-03 17:11:28 +10:00
|
|
|
m_batch_current_vertex_ptr = m_batch_start_vertex_ptr;
|
|
|
|
|
|
2019-11-14 16:58:27 +10:00
|
|
|
m_vram_shadow.fill(0);
|
2021-05-19 13:43:49 +10:00
|
|
|
if (m_sw_renderer)
|
|
|
|
|
m_sw_renderer->Reset(clear_vram);
|
2019-11-14 16:58:27 +10:00
|
|
|
|
2019-10-04 20:33:37 +10:00
|
|
|
m_batch = {};
|
2019-11-03 13:15:17 +10:00
|
|
|
m_batch_ubo_data = {};
|
|
|
|
|
m_batch_ubo_dirty = true;
|
2020-06-20 20:21:32 +10:00
|
|
|
m_current_depth = 1;
|
2019-11-05 22:34:27 +10:00
|
|
|
|
|
|
|
|
SetFullVRAMDirtyRectangle();
|
2019-10-04 20:33:37 +10:00
|
|
|
}
|
|
|
|
|
|
2021-01-23 19:00:54 +10:00
|
|
|
bool GPU_HW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
|
2019-11-02 01:32:27 +10:00
|
|
|
{
|
2021-01-23 19:00:54 +10:00
|
|
|
if (!GPU::DoState(sw, host_texture, update_display))
|
2019-11-02 01:32:27 +10:00
|
|
|
return false;
|
|
|
|
|
|
2019-11-05 22:34:27 +10:00
|
|
|
// invalidate the whole VRAM read texture when loading state
|
|
|
|
|
if (sw.IsReading())
|
2020-05-03 17:11:28 +10:00
|
|
|
{
|
|
|
|
|
m_batch_current_vertex_ptr = m_batch_start_vertex_ptr;
|
2019-11-05 22:34:27 +10:00
|
|
|
SetFullVRAMDirtyRectangle();
|
2020-06-20 20:21:32 +10:00
|
|
|
ResetBatchVertexDepth();
|
2020-05-03 17:11:28 +10:00
|
|
|
}
|
2019-11-05 22:34:27 +10:00
|
|
|
|
2019-11-02 01:32:27 +10:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 22:37:30 +10:00
|
|
|
void GPU_HW::UpdateHWSettings(bool* framebuffer_changed, bool* shaders_changed)
|
2019-11-02 00:31:25 +10:00
|
|
|
{
|
2020-08-10 22:37:30 +10:00
|
|
|
const u32 resolution_scale = CalculateResolutionScale();
|
2020-10-31 00:38:06 +10:00
|
|
|
const u32 multisamples = std::min(m_max_multisamples, g_settings.gpu_multisamples);
|
2020-10-31 15:12:12 +10:00
|
|
|
const bool per_sample_shading = g_settings.gpu_per_sample_shading && m_supports_per_sample_shading;
|
2020-12-30 16:26:20 +10:00
|
|
|
const GPUDownsampleMode downsample_mode = GetDownsampleMode(resolution_scale);
|
2020-08-10 22:37:30 +10:00
|
|
|
const bool use_uv_limits = ShouldUseUVLimits();
|
2023-02-09 14:04:28 +01:00
|
|
|
const bool disable_color_perspective = m_supports_disable_color_perspective && ShouldDisableColorPerspective();
|
2019-11-02 00:31:25 +10:00
|
|
|
|
2020-12-30 16:26:20 +10:00
|
|
|
*framebuffer_changed =
|
|
|
|
|
(m_resolution_scale != resolution_scale || m_multisamples != multisamples || m_downsample_mode != downsample_mode);
|
2020-11-03 14:17:51 +10:00
|
|
|
*shaders_changed =
|
|
|
|
|
(m_resolution_scale != resolution_scale || m_multisamples != multisamples ||
|
|
|
|
|
m_true_color != g_settings.gpu_true_color || m_per_sample_shading != per_sample_shading ||
|
|
|
|
|
m_scaled_dithering != g_settings.gpu_scaled_dithering || m_texture_filtering != g_settings.gpu_texture_filter ||
|
2020-12-23 01:10:49 +10:00
|
|
|
m_using_uv_limits != use_uv_limits || m_chroma_smoothing != g_settings.gpu_24bit_chroma_smoothing ||
|
2023-02-09 14:04:28 +01:00
|
|
|
m_downsample_mode != downsample_mode || m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer() ||
|
gpu_hw: trigger shader recompile on runtime swanstation_GPU_ShaderPrecompile change
Reported bug: flipping the swanstation_GPU_ShaderPrecompile core
option between Lazy / Enabled / Disabled at runtime had no
immediate effect. The new mode wouldn't take effect until the
user changed some OTHER shader-affecting setting (texture filter,
resolution scale, multisampling, etc.) that triggered the existing
destroy/recompile path.
Root cause: GPU_HW::UpdateHWSettings's shaders_changed predicate
checked 11 fields (resolution_scale, multisamples, true_color,
per_sample_shading, scaled_dithering, texture_filter, uv_limits,
chroma_smoothing, downsample_mode, pgxp_depth_buffer,
disable_color_perspective) but NOT g_settings.gpu_shader_precompile_mode.
So a pure precompile-mode flip computed shaders_changed = false,
the per-backend UpdateSettings skipped the DestroyPipelines /
CompilePipelines round-trip, and:
- Lazy -> Disabled: the background worker that was already
spawned just kept running until it naturally finished filling
the matrix (~30 seconds on heavy filters). The user-visible
'Disabled' semantics didn't apply until then.
- Disabled -> Lazy: no worker spawn happened. Each draw kept
paying first-use compile cost on the runloop. The user got
Disabled behaviour while the setting said Lazy.
- {Lazy, Disabled} -> Enabled: no synchronous full precompile
happened. The user expected 'block until done' and got
whatever state the matrix was in.
- Enabled -> {Lazy, Disabled}: the matrix was already fully
populated from the Enabled-mode sync pass, so this only had
bearing on FUTURE recompile cycles. Still wrong but the
least-visible case.
Fix: add m_shader_precompile_mode as the cached previous value
(seeded in GPU_HW::Initialize from g_settings.gpu_shader_precompile_mode,
re-stored every UpdateHWSettings call alongside the other field
copies). Include it in the shaders_changed predicate.
After this patch a runtime flip triggers shaders_changed = true,
which calls into the per-backend UpdateSettings's normal
destroy/recompile path:
- Lazy -> Disabled: DestroyPipelines calls StopShaderCompileThread
which joins the worker; CompilePipelines runs in Disabled
mode (skips the precompile matrix, doesn't spawn a worker).
The worker is gone within at most one in-flight cell's
compile worth of latency.
- Disabled -> Lazy: DestroyPipelines is a no-op for the worker
(none running); CompilePipelines runs in Lazy mode (skips
the precompile matrix, spawns a worker that fills the matrix
asynchronously).
- Disabled -> Enabled: full sync precompile on the calling
thread - the documented Enabled-mode behaviour. The frontend
blocks for tens of seconds on cold disk cache; cached, it's
a few seconds.
- Enabled -> Lazy / Disabled: matrix destroyed, recompiled
according to the new mode. Symmetric with the other cases.
- Lazy -> Enabled or vice versa with an in-flight worker:
DestroyPipelines joins the in-flight worker first, then
CompilePipelines starts fresh in the new mode.
Cost is one full destroy/recompile cycle on each precompile-mode
flip - same cost path the existing 11 settings already pay. For
Lazy and Disabled this is roughly 100-300 ms of teardown plus
non-batch shader rebuild. For Enabled it's that plus the actual
sync precompile of the batch matrix, dominated by driver compile
time (10-40s cold, sub-second from disk cache). The cell-fill
work hits the disk shader cache so it's only expensive on the
first time any given (filter, scale, ...) tuple is seen.
We could have written more precise handling - 'on Lazy ->
Disabled just stop the worker, keep the populated matrix' - but
that's a more complex patch and the simple destroy/recompile path
is well-trodden, well-tested, and the user already pays this cost
for any other shader-affecting setting change. Symmetry trumps
the small redundant work in the Lazy <-> Disabled case.
Files touched:
- src/core/gpu_hw.h: m_shader_precompile_mode member added.
- src/core/gpu_hw.cpp: Initialize seeds it from g_settings;
UpdateHWSettings includes it in shaders_changed predicate
and writes the latest value back.
Build verification: linux platform=unix clean, zero warnings,
zero errors. .so size 8040152 unchanged (one u8-sized field and
one extra comparison, well within an existing structure-padding
slot). 25 retro_* exports unchanged.
2026-05-11 18:19:44 +00:00
|
|
|
m_disable_color_perspective != disable_color_perspective ||
|
|
|
|
|
m_shader_precompile_mode != g_settings.gpu_shader_precompile_mode);
|
2020-08-10 22:37:30 +10:00
|
|
|
|
|
|
|
|
m_resolution_scale = resolution_scale;
|
2020-10-31 00:38:06 +10:00
|
|
|
m_multisamples = multisamples;
|
2020-10-31 15:12:12 +10:00
|
|
|
m_per_sample_shading = per_sample_shading;
|
2020-07-31 17:09:18 +10:00
|
|
|
m_true_color = g_settings.gpu_true_color;
|
|
|
|
|
m_scaled_dithering = g_settings.gpu_scaled_dithering;
|
2020-09-11 22:20:19 +10:00
|
|
|
m_texture_filtering = g_settings.gpu_texture_filter;
|
2020-08-10 22:37:30 +10:00
|
|
|
m_using_uv_limits = use_uv_limits;
|
2020-11-03 14:17:51 +10:00
|
|
|
m_chroma_smoothing = g_settings.gpu_24bit_chroma_smoothing;
|
2020-12-30 16:26:20 +10:00
|
|
|
m_downsample_mode = downsample_mode;
|
2023-02-09 14:04:28 +01:00
|
|
|
m_disable_color_perspective = disable_color_perspective;
|
gpu_hw: trigger shader recompile on runtime swanstation_GPU_ShaderPrecompile change
Reported bug: flipping the swanstation_GPU_ShaderPrecompile core
option between Lazy / Enabled / Disabled at runtime had no
immediate effect. The new mode wouldn't take effect until the
user changed some OTHER shader-affecting setting (texture filter,
resolution scale, multisampling, etc.) that triggered the existing
destroy/recompile path.
Root cause: GPU_HW::UpdateHWSettings's shaders_changed predicate
checked 11 fields (resolution_scale, multisamples, true_color,
per_sample_shading, scaled_dithering, texture_filter, uv_limits,
chroma_smoothing, downsample_mode, pgxp_depth_buffer,
disable_color_perspective) but NOT g_settings.gpu_shader_precompile_mode.
So a pure precompile-mode flip computed shaders_changed = false,
the per-backend UpdateSettings skipped the DestroyPipelines /
CompilePipelines round-trip, and:
- Lazy -> Disabled: the background worker that was already
spawned just kept running until it naturally finished filling
the matrix (~30 seconds on heavy filters). The user-visible
'Disabled' semantics didn't apply until then.
- Disabled -> Lazy: no worker spawn happened. Each draw kept
paying first-use compile cost on the runloop. The user got
Disabled behaviour while the setting said Lazy.
- {Lazy, Disabled} -> Enabled: no synchronous full precompile
happened. The user expected 'block until done' and got
whatever state the matrix was in.
- Enabled -> {Lazy, Disabled}: the matrix was already fully
populated from the Enabled-mode sync pass, so this only had
bearing on FUTURE recompile cycles. Still wrong but the
least-visible case.
Fix: add m_shader_precompile_mode as the cached previous value
(seeded in GPU_HW::Initialize from g_settings.gpu_shader_precompile_mode,
re-stored every UpdateHWSettings call alongside the other field
copies). Include it in the shaders_changed predicate.
After this patch a runtime flip triggers shaders_changed = true,
which calls into the per-backend UpdateSettings's normal
destroy/recompile path:
- Lazy -> Disabled: DestroyPipelines calls StopShaderCompileThread
which joins the worker; CompilePipelines runs in Disabled
mode (skips the precompile matrix, doesn't spawn a worker).
The worker is gone within at most one in-flight cell's
compile worth of latency.
- Disabled -> Lazy: DestroyPipelines is a no-op for the worker
(none running); CompilePipelines runs in Lazy mode (skips
the precompile matrix, spawns a worker that fills the matrix
asynchronously).
- Disabled -> Enabled: full sync precompile on the calling
thread - the documented Enabled-mode behaviour. The frontend
blocks for tens of seconds on cold disk cache; cached, it's
a few seconds.
- Enabled -> Lazy / Disabled: matrix destroyed, recompiled
according to the new mode. Symmetric with the other cases.
- Lazy -> Enabled or vice versa with an in-flight worker:
DestroyPipelines joins the in-flight worker first, then
CompilePipelines starts fresh in the new mode.
Cost is one full destroy/recompile cycle on each precompile-mode
flip - same cost path the existing 11 settings already pay. For
Lazy and Disabled this is roughly 100-300 ms of teardown plus
non-batch shader rebuild. For Enabled it's that plus the actual
sync precompile of the batch matrix, dominated by driver compile
time (10-40s cold, sub-second from disk cache). The cell-fill
work hits the disk shader cache so it's only expensive on the
first time any given (filter, scale, ...) tuple is seen.
We could have written more precise handling - 'on Lazy ->
Disabled just stop the worker, keep the populated matrix' - but
that's a more complex patch and the simple destroy/recompile path
is well-trodden, well-tested, and the user already pays this cost
for any other shader-affecting setting change. Symmetry trumps
the small redundant work in the Lazy <-> Disabled case.
Files touched:
- src/core/gpu_hw.h: m_shader_precompile_mode member added.
- src/core/gpu_hw.cpp: Initialize seeds it from g_settings;
UpdateHWSettings includes it in shaders_changed predicate
and writes the latest value back.
Build verification: linux platform=unix clean, zero warnings,
zero errors. .so size 8040152 unchanged (one u8-sized field and
one extra comparison, well within an existing structure-padding
slot). 25 retro_* exports unchanged.
2026-05-11 18:19:44 +00:00
|
|
|
m_shader_precompile_mode = g_settings.gpu_shader_precompile_mode;
|
2020-11-10 20:55:35 +10:00
|
|
|
|
|
|
|
|
if (!m_supports_dual_source_blend && TextureFilterRequiresDualSourceBlend(m_texture_filtering))
|
|
|
|
|
m_texture_filtering = GPUTextureFilter::Nearest;
|
|
|
|
|
|
2020-12-23 01:10:49 +10:00
|
|
|
if (m_pgxp_depth_buffer != g_settings.UsingPGXPDepthBuffer())
|
|
|
|
|
{
|
|
|
|
|
m_pgxp_depth_buffer = g_settings.UsingPGXPDepthBuffer();
|
|
|
|
|
m_batch.use_depth_buffer = false;
|
|
|
|
|
if (m_pgxp_depth_buffer)
|
|
|
|
|
ClearDepthBuffer();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 13:43:49 +10:00
|
|
|
UpdateSoftwareRenderer(true);
|
2020-03-07 12:54:15 +10:00
|
|
|
}
|
|
|
|
|
|
2022-07-22 21:20:00 +02:00
|
|
|
static u32 PreviousPow2(u32 value)
|
|
|
|
|
{
|
|
|
|
|
value |= (value >> 1);
|
|
|
|
|
value |= (value >> 2);
|
|
|
|
|
value |= (value >> 4);
|
|
|
|
|
value |= (value >> 8);
|
|
|
|
|
value |= (value >> 16);
|
|
|
|
|
return value - (value >> 1);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 03:06:03 +10:00
|
|
|
u32 GPU_HW::CalculateResolutionScale() const
|
|
|
|
|
{
|
2020-12-30 16:26:20 +10:00
|
|
|
u32 scale;
|
2020-08-03 03:06:03 +10:00
|
|
|
if (g_settings.gpu_resolution_scale != 0)
|
2020-12-30 16:26:20 +10:00
|
|
|
scale = std::clamp<u32>(g_settings.gpu_resolution_scale, 1, m_max_resolution_scale);
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-05-31 03:48:38 +10:00
|
|
|
// Auto scaling. When the system is starting and all borders crop is enabled, the registers are zero, and
|
|
|
|
|
// display_height therefore is also zero. Use the default size from the region in this case.
|
|
|
|
|
const s32 height = (m_crtc_state.display_height != 0) ?
|
|
|
|
|
static_cast<s32>(m_crtc_state.display_height) :
|
|
|
|
|
(m_console_is_pal ? (PAL_VERTICAL_ACTIVE_END - PAL_VERTICAL_ACTIVE_START) :
|
|
|
|
|
(NTSC_VERTICAL_ACTIVE_END - NTSC_VERTICAL_ACTIVE_START));
|
2020-12-30 16:26:20 +10:00
|
|
|
const s32 preferred_scale =
|
|
|
|
|
static_cast<s32>(std::ceil(static_cast<float>(m_host_display->GetWindowHeight()) / height));
|
|
|
|
|
scale = static_cast<u32>(std::clamp<s32>(preferred_scale, 1, m_max_resolution_scale));
|
|
|
|
|
}
|
|
|
|
|
if (g_settings.gpu_downsample_mode == GPUDownsampleMode::Adaptive && m_supports_adaptive_downsampling && scale > 1 &&
|
2022-06-26 03:03:37 +02:00
|
|
|
!(IS_POW2(scale)))
|
2022-07-22 21:20:00 +02:00
|
|
|
return PreviousPow2(scale);
|
2020-12-30 16:26:20 +10:00
|
|
|
return scale;
|
2020-08-03 03:06:03 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-30 16:26:20 +10:00
|
|
|
GPUDownsampleMode GPU_HW::GetDownsampleMode(u32 resolution_scale) const
|
|
|
|
|
{
|
|
|
|
|
if (resolution_scale == 1)
|
|
|
|
|
return GPUDownsampleMode::Disabled;
|
|
|
|
|
|
|
|
|
|
if (g_settings.gpu_downsample_mode == GPUDownsampleMode::Adaptive)
|
|
|
|
|
return m_supports_adaptive_downsampling ? GPUDownsampleMode::Adaptive : GPUDownsampleMode::Box;
|
|
|
|
|
|
|
|
|
|
return g_settings.gpu_downsample_mode;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-02 21:45:36 +10:00
|
|
|
void GPU_HW::UpdateVRAMReadTexture()
|
|
|
|
|
{
|
|
|
|
|
ClearVRAMDirtyRectangle();
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-28 02:24:22 +10:00
|
|
|
void GPU_HW::HandleFlippedQuadTextureCoordinates(BatchVertex* vertices)
|
|
|
|
|
{
|
|
|
|
|
// Taken from beetle-psx gpu_polygon.cpp
|
|
|
|
|
// For X/Y flipped 2D sprites, PSX games rely on a very specific rasterization behavior. If U or V is decreasing in X
|
|
|
|
|
// or Y, and we use the provided U/V as is, we will sample the wrong texel as interpolation covers an entire pixel,
|
|
|
|
|
// while PSX samples its interpolation essentially in the top-left corner and splats that interpolant across the
|
|
|
|
|
// entire pixel. While we could emulate this reasonably well in native resolution by shifting our vertex coords by
|
|
|
|
|
// 0.5, this breaks in upscaling scenarios, because we have several samples per native sample and we need NN rules to
|
|
|
|
|
// hit the same UV every time. One approach here is to use interpolate at offset or similar tricks to generalize the
|
|
|
|
|
// PSX interpolation patterns, but the problem is that vertices sharing an edge will no longer see the same UV (due to
|
|
|
|
|
// different plane derivatives), we end up sampling outside the intended boundary and artifacts are inevitable, so the
|
|
|
|
|
// only case where we can apply this fixup is for "sprites" or similar which should not share edges, which leads to
|
|
|
|
|
// this unfortunate code below.
|
|
|
|
|
|
|
|
|
|
// It might be faster to do more direct checking here, but the code below handles primitives in any order and
|
|
|
|
|
// orientation, and is far more SIMD-friendly if needed.
|
2020-08-02 00:25:07 +10:00
|
|
|
const float abx = vertices[1].x - vertices[0].x;
|
|
|
|
|
const float aby = vertices[1].y - vertices[0].y;
|
|
|
|
|
const float bcx = vertices[2].x - vertices[1].x;
|
|
|
|
|
const float bcy = vertices[2].y - vertices[1].y;
|
|
|
|
|
const float cax = vertices[0].x - vertices[2].x;
|
|
|
|
|
const float cay = vertices[0].y - vertices[2].y;
|
2020-03-28 02:24:22 +10:00
|
|
|
|
|
|
|
|
// Compute static derivatives, just assume W is uniform across the primitive and that the plane equation remains the
|
|
|
|
|
// same across the quad. (which it is, there is no Z.. yet).
|
2020-08-02 00:25:07 +10:00
|
|
|
const float dudx = -aby * static_cast<float>(vertices[2].u) - bcy * static_cast<float>(vertices[0].u) -
|
|
|
|
|
cay * static_cast<float>(vertices[1].u);
|
|
|
|
|
const float dvdx = -aby * static_cast<float>(vertices[2].v) - bcy * static_cast<float>(vertices[0].v) -
|
|
|
|
|
cay * static_cast<float>(vertices[1].v);
|
|
|
|
|
const float dudy = +abx * static_cast<float>(vertices[2].u) + bcx * static_cast<float>(vertices[0].u) +
|
|
|
|
|
cax * static_cast<float>(vertices[1].u);
|
|
|
|
|
const float dvdy = +abx * static_cast<float>(vertices[2].v) + bcx * static_cast<float>(vertices[0].v) +
|
|
|
|
|
cax * static_cast<float>(vertices[1].v);
|
|
|
|
|
const float area = bcx * cay - bcy * cax;
|
2020-03-28 02:24:22 +10:00
|
|
|
|
|
|
|
|
// Detect and reject any triangles with 0 size texture area
|
|
|
|
|
const s32 texArea = (vertices[1].u - vertices[0].u) * (vertices[2].v - vertices[0].v) -
|
|
|
|
|
(vertices[2].u - vertices[0].u) * (vertices[1].v - vertices[0].v);
|
|
|
|
|
|
2020-08-12 02:27:03 +10:00
|
|
|
// Leverage PGXP to further avoid 3D polygons that just happen to align this way after projection
|
|
|
|
|
const bool is_3d = (vertices[0].w != vertices[1].w || vertices[0].w != vertices[2].w);
|
|
|
|
|
|
2020-03-28 02:24:22 +10:00
|
|
|
// Shouldn't matter as degenerate primitives will be culled anyways.
|
2020-08-12 02:27:03 +10:00
|
|
|
if (area == 0.0f || texArea == 0 || is_3d)
|
2020-03-28 02:24:22 +10:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Use floats here as it'll be faster than integer divides.
|
2020-08-02 00:25:07 +10:00
|
|
|
const float rcp_area = 1.0f / area;
|
|
|
|
|
const float dudx_area = dudx * rcp_area;
|
|
|
|
|
const float dudy_area = dudy * rcp_area;
|
|
|
|
|
const float dvdx_area = dvdx * rcp_area;
|
|
|
|
|
const float dvdy_area = dvdy * rcp_area;
|
2020-03-28 02:24:22 +10:00
|
|
|
const bool neg_dudx = dudx_area < 0.0f;
|
|
|
|
|
const bool neg_dudy = dudy_area < 0.0f;
|
|
|
|
|
const bool neg_dvdx = dvdx_area < 0.0f;
|
|
|
|
|
const bool neg_dvdy = dvdy_area < 0.0f;
|
|
|
|
|
const bool zero_dudx = dudx_area == 0.0f;
|
|
|
|
|
const bool zero_dudy = dudy_area == 0.0f;
|
|
|
|
|
const bool zero_dvdx = dvdx_area == 0.0f;
|
|
|
|
|
const bool zero_dvdy = dvdy_area == 0.0f;
|
|
|
|
|
|
|
|
|
|
// If we have negative dU or dV in any direction, increment the U or V to work properly with nearest-neighbor in
|
|
|
|
|
// this impl. If we don't have 1:1 pixel correspondence, this creates a slight "shift" in the sprite, but we
|
|
|
|
|
// guarantee that we don't sample garbage at least. Overall, this is kinda hacky because there can be legitimate,
|
|
|
|
|
// rare cases where 3D meshes hit this scenario, and a single texel offset can pop in, but this is way better than
|
|
|
|
|
// having borked 2D overall.
|
|
|
|
|
//
|
|
|
|
|
// TODO: If perf becomes an issue, we can probably SIMD the 8 comparisons above,
|
|
|
|
|
// create an 8-bit code, and use a LUT to get the offsets.
|
|
|
|
|
// Case 1: U is decreasing in X, but no change in Y.
|
|
|
|
|
// Case 2: U is decreasing in Y, but no change in X.
|
|
|
|
|
// Case 3: V is decreasing in X, but no change in Y.
|
|
|
|
|
// Case 4: V is decreasing in Y, but no change in X.
|
|
|
|
|
if ((neg_dudx && zero_dudy) || (neg_dudy && zero_dudx))
|
|
|
|
|
{
|
|
|
|
|
vertices[0].u++;
|
|
|
|
|
vertices[1].u++;
|
|
|
|
|
vertices[2].u++;
|
|
|
|
|
vertices[3].u++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((neg_dvdx && zero_dvdy) || (neg_dvdy && zero_dvdx))
|
|
|
|
|
{
|
|
|
|
|
vertices[0].v++;
|
|
|
|
|
vertices[1].v++;
|
|
|
|
|
vertices[2].v++;
|
|
|
|
|
vertices[3].v++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 22:37:07 +10:00
|
|
|
void GPU_HW::ComputePolygonUVLimits(BatchVertex* vertices, u32 num_vertices)
|
|
|
|
|
{
|
|
|
|
|
u16 min_u = vertices[0].u, max_u = vertices[0].u, min_v = vertices[0].v, max_v = vertices[0].v;
|
|
|
|
|
for (u32 i = 1; i < num_vertices; i++)
|
|
|
|
|
{
|
|
|
|
|
min_u = std::min<u16>(min_u, vertices[i].u);
|
|
|
|
|
max_u = std::max<u16>(max_u, vertices[i].u);
|
|
|
|
|
min_v = std::min<u16>(min_v, vertices[i].v);
|
|
|
|
|
max_v = std::max<u16>(max_v, vertices[i].v);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (min_u != max_u)
|
|
|
|
|
max_u--;
|
|
|
|
|
if (min_v != max_v)
|
|
|
|
|
max_v--;
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < num_vertices; i++)
|
2023-03-09 18:32:46 +01:00
|
|
|
vertices[i].uv_limits = BatchVertex::PackUVLimits(min_u, max_u, min_v, max_v);
|
2020-08-10 22:37:07 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-23 01:10:49 +10:00
|
|
|
void GPU_HW::SetBatchDepthBuffer(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
if (GetBatchVertexCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
FlushRender();
|
|
|
|
|
EnsureVertexBufferSpaceForCurrentCommand();
|
|
|
|
|
}
|
|
|
|
|
m_batch.use_depth_buffer = enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::CheckForDepthClear(const BatchVertex* vertices, u32 num_vertices)
|
|
|
|
|
{
|
|
|
|
|
float average_z;
|
|
|
|
|
if (num_vertices == 3)
|
|
|
|
|
average_z = std::min((vertices[0].w + vertices[1].w + vertices[2].w) / 3.0f, 1.0f);
|
|
|
|
|
else
|
|
|
|
|
average_z = std::min((vertices[0].w + vertices[1].w + vertices[2].w + vertices[3].w) / 4.0f, 1.0f);
|
|
|
|
|
|
|
|
|
|
if ((average_z - m_last_depth_z) >= g_settings.gpu_pgxp_depth_clear_threshold)
|
|
|
|
|
{
|
|
|
|
|
if (GetBatchVertexCount() > 0)
|
|
|
|
|
{
|
|
|
|
|
FlushRender();
|
|
|
|
|
EnsureVertexBufferSpaceForCurrentCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClearDepthBuffer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_last_depth_z = average_z;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 16:26:20 +10:00
|
|
|
u32 GPU_HW::GetAdaptiveDownsamplingMipLevels() const
|
|
|
|
|
{
|
|
|
|
|
u32 levels = 0;
|
|
|
|
|
u32 current_width = VRAM_WIDTH * m_resolution_scale;
|
|
|
|
|
while (current_width >= VRAM_WIDTH)
|
|
|
|
|
{
|
|
|
|
|
levels++;
|
|
|
|
|
current_width /= 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return levels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_HW::SmoothingUBOData GPU_HW::GetSmoothingUBO(u32 level, u32 left, u32 top, u32 width, u32 height, u32 tex_width,
|
|
|
|
|
u32 tex_height) const
|
|
|
|
|
{
|
|
|
|
|
const float rcp_width = 1.0f / static_cast<float>(tex_width >> level);
|
|
|
|
|
const float rcp_height = 1.0f / static_cast<float>(tex_height >> level);
|
|
|
|
|
|
|
|
|
|
SmoothingUBOData data;
|
|
|
|
|
data.min_uv[0] = static_cast<float>(left >> level) * rcp_width;
|
|
|
|
|
data.min_uv[1] = static_cast<float>(top >> level) * rcp_height;
|
|
|
|
|
data.max_uv[0] = static_cast<float>((left + width) >> level) * rcp_width;
|
|
|
|
|
data.max_uv[1] = static_cast<float>((top + height) >> level) * rcp_height;
|
|
|
|
|
data.rcp_size[0] = rcp_width;
|
|
|
|
|
data.rcp_size[1] = rcp_height;
|
|
|
|
|
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
void GPU_HW::DrawLine(float x0, float y0, u32 col0, float x1, float y1, u32 col1, float depth)
|
2020-07-25 02:37:00 +10:00
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
const float dx = x1 - x0;
|
|
|
|
|
const float dy = y1 - y0;
|
|
|
|
|
std::array<BatchVertex, 4> output;
|
|
|
|
|
if (dx == 0.0f && dy == 0.0f)
|
2020-07-25 02:37:00 +10:00
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
// Degenerate, render a point.
|
2020-08-10 22:37:07 +10:00
|
|
|
output[0].Set(x0, y0, depth, 1.0f, col0, 0, 0, 0);
|
|
|
|
|
output[1].Set(x0 + 1.0f, y0, depth, 1.0f, col0, 0, 0, 0);
|
|
|
|
|
output[2].Set(x1, y1 + 1.0f, depth, 1.0f, col0, 0, 0, 0);
|
|
|
|
|
output[3].Set(x1 + 1.0f, y1 + 1.0f, depth, 1.0f, col0, 0, 0, 0);
|
2020-07-25 02:37:00 +10:00
|
|
|
}
|
2020-08-02 17:17:05 +10:00
|
|
|
else
|
2020-07-25 02:37:00 +10:00
|
|
|
{
|
2020-08-02 18:04:00 +10:00
|
|
|
const float abs_dx = std::fabs(dx);
|
|
|
|
|
const float abs_dy = std::fabs(dy);
|
2020-08-02 17:17:05 +10:00
|
|
|
float fill_dx, fill_dy;
|
|
|
|
|
float dxdk, dydk;
|
|
|
|
|
float pad_x0 = 0.0f;
|
|
|
|
|
float pad_x1 = 0.0f;
|
|
|
|
|
float pad_y0 = 0.0f;
|
|
|
|
|
float pad_y1 = 0.0f;
|
|
|
|
|
|
|
|
|
|
// Check for vertical or horizontal major lines.
|
|
|
|
|
// When expanding to a rect, do so in the appropriate direction.
|
|
|
|
|
// FIXME: This scheme seems to kinda work, but it seems very hard to find a method
|
|
|
|
|
// that looks perfect on every game.
|
|
|
|
|
// Vagrant Story speech bubbles are a very good test case here!
|
|
|
|
|
if (abs_dx > abs_dy)
|
|
|
|
|
{
|
|
|
|
|
fill_dx = 0.0f;
|
|
|
|
|
fill_dy = 1.0f;
|
|
|
|
|
dxdk = 1.0f;
|
|
|
|
|
dydk = dy / abs_dx;
|
|
|
|
|
|
|
|
|
|
if (dx > 0.0f)
|
|
|
|
|
{
|
|
|
|
|
// Right
|
|
|
|
|
pad_x1 = 1.0f;
|
|
|
|
|
pad_y1 = dydk;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Left
|
|
|
|
|
pad_x0 = 1.0f;
|
|
|
|
|
pad_y0 = -dydk;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-25 02:37:00 +10:00
|
|
|
else
|
2020-08-02 17:17:05 +10:00
|
|
|
{
|
|
|
|
|
fill_dx = 1.0f;
|
|
|
|
|
fill_dy = 0.0f;
|
|
|
|
|
dydk = 1.0f;
|
|
|
|
|
dxdk = dx / abs_dy;
|
|
|
|
|
|
|
|
|
|
if (dy > 0.0f)
|
|
|
|
|
{
|
|
|
|
|
// Down
|
|
|
|
|
pad_y1 = 1.0f;
|
|
|
|
|
pad_x1 = dxdk;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Up
|
|
|
|
|
pad_y0 = 1.0f;
|
|
|
|
|
pad_x0 = -dxdk;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const float ox0 = x0 + pad_x0;
|
|
|
|
|
const float oy0 = y0 + pad_y0;
|
|
|
|
|
const float ox1 = x1 + pad_x1;
|
|
|
|
|
const float oy1 = y1 + pad_y1;
|
|
|
|
|
|
2020-08-10 22:37:07 +10:00
|
|
|
output[0].Set(ox0, oy0, depth, 1.0f, col0, 0, 0, 0);
|
|
|
|
|
output[1].Set(ox0 + fill_dx, oy0 + fill_dy, depth, 1.0f, col0, 0, 0, 0);
|
|
|
|
|
output[2].Set(ox1, oy1, depth, 1.0f, col1, 0, 0, 0);
|
|
|
|
|
output[3].Set(ox1 + fill_dx, oy1 + fill_dy, depth, 1.0f, col1, 0, 0, 0);
|
2020-07-25 02:37:00 +10:00
|
|
|
}
|
2020-08-02 17:17:05 +10:00
|
|
|
|
|
|
|
|
AddVertex(output[0]);
|
|
|
|
|
AddVertex(output[1]);
|
|
|
|
|
AddVertex(output[2]);
|
|
|
|
|
AddVertex(output[3]);
|
|
|
|
|
AddVertex(output[2]);
|
|
|
|
|
AddVertex(output[1]);
|
2020-07-25 02:37:00 +10:00
|
|
|
}
|
|
|
|
|
|
2020-04-19 01:16:58 +10:00
|
|
|
void GPU_HW::LoadVertices()
|
2019-09-12 12:53:04 +10:00
|
|
|
{
|
2020-08-02 13:04:24 +10:00
|
|
|
if (m_GPUSTAT.check_mask_before_draw)
|
|
|
|
|
m_current_depth++;
|
|
|
|
|
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPURenderCommand rc{m_render_command.bits};
|
common: remove SignExtend / ZeroExtend / Truncate helpers in favour of explicit casts
The src/common/types.h helpers SignExtend16/32/64, ZeroExtend16/32/64,
Truncate8/16/32, the generic SignExtend<TR,TV> and ZeroExtend<TR,TV>
templates, and SignExtendN<N,T> were thin wrappers around explicit
static_cast chains. They served a documentation role ("this cast is
intentional, not a typo") in places where the underlying intent was
"narrow this value" or "sign-extend this value", but in practice
they obscured rather than clarified - particularly when several
nested together (SignExtend32(Truncate8(x)) is just (u32)(s8)x).
Tree-wide fold:
Truncate8(x) -> static_cast<u8>(x)
Truncate16(x) -> static_cast<u16>(x)
Truncate32(x) -> static_cast<u32>(x)
ZeroExtendN(u_x) -> static_cast<uN>(u_x)
SignExtendN(u_x) -> static_cast<uN>(static_cast<sM>(u_x)) (M = source width)
SignExtendN(s_x) -> static_cast<uN>(s_x) (relies on int promotion)
SignExtendN<BITS,T>(x) -> static_cast<sN>(static_cast<uN>(x) << S) >> S (S = N*8 - BITS)
SignExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<sM>(x))
ZeroExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<uM>(x))
Mask cleanup applied where the mask matched the truncation width:
Truncate8(x & 0xFFu) -> static_cast<u8>(x)
Truncate8((x & 0xFF00u) >> 8) -> static_cast<u8>(x >> 8)
Truncate16(x & 0xFFFFu) -> static_cast<u16>(x)
Truncate16((x & 0xFFFF0000u) >> 16) -> static_cast<u16>(x >> 16)
The masks were dead-code: a static_cast to uN already keeps exactly
the low N bits.
UB fixes incidental to the fold (visible once the helpers were
unwrapped):
- SignExtendN<NBITS,T> internally did (static_cast<signed_T>(v) << S) >> S.
Signed left shift of a negative value is UB pre-C++20. After the
fold the shift is done in the unsigned domain first:
static_cast<sN>(static_cast<uN>(v) << S) >> S
All five SignExtendN callsite expansions (gpu_commands.cpp x2,
gpu_types.h, gte SignExtendMACResult, mdec.cpp x12) now do the
left shift on uN. Defined behaviour on every C++ standard from
C++98 onward. Right shift of a signed negative value remains
implementation-defined pre-C++20; this is the same as the
original helper and unchanged.
- mdec.cpp:650's SignExtendN<9,s32> took an s64 expression and
forced an implicit s64->int narrowing inside the template, which
-Wconversion flagged. The explicit static_cast<u32>(...) now
makes the narrow visible and the warning goes away. Bit-identical
result.
Sites deliberately not collapsed further, with reasons:
- spu.cpp:1347 (ADPCM pitch modulation): SignExtend32(step) where
step is u16 deliberately produces a u32 with the s16 sign bit
replicated, then multiplies by a u32 factor. Folding it as
static_cast<u32>(static_cast<s16>(step)) preserves the semantics
exactly. The naive 'static_cast<s32>(step) * factor' would not -
it'd evaluate s32 * s32 which is signed and may overflow as UB.
- gte.cpp:297-299 (IRGB conversion): Sign-extension here is observably
equivalent to zero-extension because (value & 0x1F) * 0x80 is
always <= 0xF80, bit 15 always clear. Folded as the literal
static_cast<u32>(static_cast<s16>(static_cast<u16>(...))) rather
than dropping the sign-extend step entirely - that would be a
semantic claim about hardware behaviour beyond the scope of a
helper-removal change.
- GTE TruncateRGB, TruncateAndSetMAC, TruncateAndSetIR,
TruncateAndSetMACAndIR (gte.cpp) and TruncateVertexPosition,
TruncateGPUVertexPosition (pgxp.cpp, gpu_types.h): these are
different functions, not the removed helpers. Left untouched.
bitutils.h's CountLeadingZeros / CountTrailingZeros are template
functions over T. The helper-removal leaves them inline-folding via
std::make_unsigned<T>::type, which is what ZeroExtend was doing
under the hood:
ZeroExtend64(value) ->
static_cast<u64>(static_cast<typename std::make_unsigned<T>::type>(value))
The remaining mechanical changes in cpu_recompiler_register_cache.h's
GetS32ConstantValue / GetS64ConstantValue and in pgxp.cpp's CPU_MULT
fold dropped redundant intermediate u-of-s-of-x casts that became
visible after the SignExtend64 expansion. Same codegen; cleaner.
Files touched: 43.
Helper definitions removed: 13 functions (~60 lines of types.h).
Build verification:
- Makefile.libretro platform=unix: clean build, zero warnings,
.so size 8031016 bytes (unchanged from HEAD).
- 25 retro_* exports unchanged.
- -Wall -Wextra on touched files: same warnings as HEAD (zero
new warnings from the fold, all pre-existing -Wunused-parameter).
- -Wconversion on touched files: one pre-existing warning
eliminated (mdec.cpp:650 SignExtendN<9,s32>(s64_expr) narrowing
is now an explicit static_cast<u32>); zero new warnings.
Codegen equivalence verified by inspection at every transformation
site:
Truncate8(x) = static_cast<u8>(x) ; both emit a movzx/byte-load
Truncate16(x) = static_cast<u16>(x) ; both emit a movzx/halfword-load
ZeroExtend32(u8) = static_cast<u32>(u8) ; both emit a movzx eax,al
ZeroExtend64(u32) = static_cast<u64>(u32); both emit a mov eax,reg (implicit zero-extend on x86-64)
SignExtend32(u8) = static_cast<u32>(static_cast<s8>(x)) ; both emit movsx eax,byte
SignExtend32(u16) = static_cast<u32>(static_cast<s16>(x)) ; both emit movsx eax,word
SignExtend64(u32) = static_cast<u64>(static_cast<s32>(x)) ; both emit movsxd rax,dword
SignExtendN<11,s32> = static_cast<s32>(static_cast<u32>(x) << 21) >> 21
both emit shl ; sar, identical 2-instruction sequence
2026-05-14 03:42:07 +00:00
|
|
|
const u32 texpage = static_cast<u32>(m_draw_mode.mode_reg.bits) | (static_cast<u32>(m_draw_mode.palette_reg) << 16);
|
2020-08-02 00:25:07 +10:00
|
|
|
const float depth = GetCurrentNormalizedVertexDepth();
|
2019-09-27 21:20:35 +10:00
|
|
|
|
2019-09-12 12:53:04 +10:00
|
|
|
switch (rc.primitive)
|
|
|
|
|
{
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Polygon:
|
2019-09-12 12:53:04 +10:00
|
|
|
{
|
2024-04-17 12:39:47 +02:00
|
|
|
u16 native_texcoords[4];
|
2019-09-15 00:17:43 +10:00
|
|
|
const u32 first_color = rc.color_for_first_vertex;
|
|
|
|
|
const bool shaded = rc.shading_enable;
|
|
|
|
|
const bool textured = rc.texture_enable;
|
2020-08-02 00:25:07 +10:00
|
|
|
const bool pgxp = g_settings.gpu_pgxp_enable;
|
2019-09-15 00:17:43 +10:00
|
|
|
|
2020-04-19 01:16:58 +10:00
|
|
|
const u32 num_vertices = rc.quad_polygon ? 4 : 3;
|
2020-02-17 00:09:45 +09:00
|
|
|
std::array<BatchVertex, 4> vertices;
|
2020-08-02 00:25:07 +10:00
|
|
|
std::array<std::array<s32, 2>, 4> native_vertex_positions;
|
|
|
|
|
bool valid_w = g_settings.gpu_pgxp_texture_correction;
|
2020-03-28 02:24:22 +10:00
|
|
|
for (u32 i = 0; i < num_vertices; i++)
|
2019-09-12 12:53:04 +10:00
|
|
|
{
|
2020-08-02 00:25:07 +10:00
|
|
|
const u32 color = (shaded && i > 0) ? (FifoPop() & UINT32_C(0x00FFFFFF)) : first_color;
|
|
|
|
|
const u64 maddr_and_pos = m_fifo.Pop();
|
common: remove SignExtend / ZeroExtend / Truncate helpers in favour of explicit casts
The src/common/types.h helpers SignExtend16/32/64, ZeroExtend16/32/64,
Truncate8/16/32, the generic SignExtend<TR,TV> and ZeroExtend<TR,TV>
templates, and SignExtendN<N,T> were thin wrappers around explicit
static_cast chains. They served a documentation role ("this cast is
intentional, not a typo") in places where the underlying intent was
"narrow this value" or "sign-extend this value", but in practice
they obscured rather than clarified - particularly when several
nested together (SignExtend32(Truncate8(x)) is just (u32)(s8)x).
Tree-wide fold:
Truncate8(x) -> static_cast<u8>(x)
Truncate16(x) -> static_cast<u16>(x)
Truncate32(x) -> static_cast<u32>(x)
ZeroExtendN(u_x) -> static_cast<uN>(u_x)
SignExtendN(u_x) -> static_cast<uN>(static_cast<sM>(u_x)) (M = source width)
SignExtendN(s_x) -> static_cast<uN>(s_x) (relies on int promotion)
SignExtendN<BITS,T>(x) -> static_cast<sN>(static_cast<uN>(x) << S) >> S (S = N*8 - BITS)
SignExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<sM>(x))
ZeroExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<uM>(x))
Mask cleanup applied where the mask matched the truncation width:
Truncate8(x & 0xFFu) -> static_cast<u8>(x)
Truncate8((x & 0xFF00u) >> 8) -> static_cast<u8>(x >> 8)
Truncate16(x & 0xFFFFu) -> static_cast<u16>(x)
Truncate16((x & 0xFFFF0000u) >> 16) -> static_cast<u16>(x >> 16)
The masks were dead-code: a static_cast to uN already keeps exactly
the low N bits.
UB fixes incidental to the fold (visible once the helpers were
unwrapped):
- SignExtendN<NBITS,T> internally did (static_cast<signed_T>(v) << S) >> S.
Signed left shift of a negative value is UB pre-C++20. After the
fold the shift is done in the unsigned domain first:
static_cast<sN>(static_cast<uN>(v) << S) >> S
All five SignExtendN callsite expansions (gpu_commands.cpp x2,
gpu_types.h, gte SignExtendMACResult, mdec.cpp x12) now do the
left shift on uN. Defined behaviour on every C++ standard from
C++98 onward. Right shift of a signed negative value remains
implementation-defined pre-C++20; this is the same as the
original helper and unchanged.
- mdec.cpp:650's SignExtendN<9,s32> took an s64 expression and
forced an implicit s64->int narrowing inside the template, which
-Wconversion flagged. The explicit static_cast<u32>(...) now
makes the narrow visible and the warning goes away. Bit-identical
result.
Sites deliberately not collapsed further, with reasons:
- spu.cpp:1347 (ADPCM pitch modulation): SignExtend32(step) where
step is u16 deliberately produces a u32 with the s16 sign bit
replicated, then multiplies by a u32 factor. Folding it as
static_cast<u32>(static_cast<s16>(step)) preserves the semantics
exactly. The naive 'static_cast<s32>(step) * factor' would not -
it'd evaluate s32 * s32 which is signed and may overflow as UB.
- gte.cpp:297-299 (IRGB conversion): Sign-extension here is observably
equivalent to zero-extension because (value & 0x1F) * 0x80 is
always <= 0xF80, bit 15 always clear. Folded as the literal
static_cast<u32>(static_cast<s16>(static_cast<u16>(...))) rather
than dropping the sign-extend step entirely - that would be a
semantic claim about hardware behaviour beyond the scope of a
helper-removal change.
- GTE TruncateRGB, TruncateAndSetMAC, TruncateAndSetIR,
TruncateAndSetMACAndIR (gte.cpp) and TruncateVertexPosition,
TruncateGPUVertexPosition (pgxp.cpp, gpu_types.h): these are
different functions, not the removed helpers. Left untouched.
bitutils.h's CountLeadingZeros / CountTrailingZeros are template
functions over T. The helper-removal leaves them inline-folding via
std::make_unsigned<T>::type, which is what ZeroExtend was doing
under the hood:
ZeroExtend64(value) ->
static_cast<u64>(static_cast<typename std::make_unsigned<T>::type>(value))
The remaining mechanical changes in cpu_recompiler_register_cache.h's
GetS32ConstantValue / GetS64ConstantValue and in pgxp.cpp's CPU_MULT
fold dropped redundant intermediate u-of-s-of-x casts that became
visible after the SignExtend64 expansion. Same codegen; cleaner.
Files touched: 43.
Helper definitions removed: 13 functions (~60 lines of types.h).
Build verification:
- Makefile.libretro platform=unix: clean build, zero warnings,
.so size 8031016 bytes (unchanged from HEAD).
- 25 retro_* exports unchanged.
- -Wall -Wextra on touched files: same warnings as HEAD (zero
new warnings from the fold, all pre-existing -Wunused-parameter).
- -Wconversion on touched files: one pre-existing warning
eliminated (mdec.cpp:650 SignExtendN<9,s32>(s64_expr) narrowing
is now an explicit static_cast<u32>); zero new warnings.
Codegen equivalence verified by inspection at every transformation
site:
Truncate8(x) = static_cast<u8>(x) ; both emit a movzx/byte-load
Truncate16(x) = static_cast<u16>(x) ; both emit a movzx/halfword-load
ZeroExtend32(u8) = static_cast<u32>(u8) ; both emit a movzx eax,al
ZeroExtend64(u32) = static_cast<u64>(u32); both emit a mov eax,reg (implicit zero-extend on x86-64)
SignExtend32(u8) = static_cast<u32>(static_cast<s8>(x)) ; both emit movsx eax,byte
SignExtend32(u16) = static_cast<u32>(static_cast<s16>(x)) ; both emit movsx eax,word
SignExtend64(u32) = static_cast<u64>(static_cast<s32>(x)) ; both emit movsxd rax,dword
SignExtendN<11,s32> = static_cast<s32>(static_cast<u32>(x) << 21) >> 21
both emit shl ; sar, identical 2-instruction sequence
2026-05-14 03:42:07 +00:00
|
|
|
const GPUVertexPosition vp{static_cast<u32>(maddr_and_pos)};
|
|
|
|
|
const u16 texcoord = textured ? static_cast<u16>(FifoPop()) : 0;
|
2020-08-02 00:25:07 +10:00
|
|
|
const s32 native_x = m_drawing_offset.x + vp.x;
|
|
|
|
|
const s32 native_y = m_drawing_offset.y + vp.y;
|
|
|
|
|
native_vertex_positions[i][0] = native_x;
|
|
|
|
|
native_vertex_positions[i][1] = native_y;
|
2021-05-19 13:43:49 +10:00
|
|
|
native_texcoords[i] = texcoord;
|
2020-08-02 00:25:07 +10:00
|
|
|
vertices[i].Set(static_cast<float>(native_x), static_cast<float>(native_y), depth, 1.0f, color, texpage,
|
2020-08-10 22:37:07 +10:00
|
|
|
texcoord, 0xFFFF0000u);
|
2020-08-02 00:25:07 +10:00
|
|
|
|
|
|
|
|
if (pgxp)
|
|
|
|
|
{
|
|
|
|
|
valid_w &=
|
common: remove SignExtend / ZeroExtend / Truncate helpers in favour of explicit casts
The src/common/types.h helpers SignExtend16/32/64, ZeroExtend16/32/64,
Truncate8/16/32, the generic SignExtend<TR,TV> and ZeroExtend<TR,TV>
templates, and SignExtendN<N,T> were thin wrappers around explicit
static_cast chains. They served a documentation role ("this cast is
intentional, not a typo") in places where the underlying intent was
"narrow this value" or "sign-extend this value", but in practice
they obscured rather than clarified - particularly when several
nested together (SignExtend32(Truncate8(x)) is just (u32)(s8)x).
Tree-wide fold:
Truncate8(x) -> static_cast<u8>(x)
Truncate16(x) -> static_cast<u16>(x)
Truncate32(x) -> static_cast<u32>(x)
ZeroExtendN(u_x) -> static_cast<uN>(u_x)
SignExtendN(u_x) -> static_cast<uN>(static_cast<sM>(u_x)) (M = source width)
SignExtendN(s_x) -> static_cast<uN>(s_x) (relies on int promotion)
SignExtendN<BITS,T>(x) -> static_cast<sN>(static_cast<uN>(x) << S) >> S (S = N*8 - BITS)
SignExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<sM>(x))
ZeroExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<uM>(x))
Mask cleanup applied where the mask matched the truncation width:
Truncate8(x & 0xFFu) -> static_cast<u8>(x)
Truncate8((x & 0xFF00u) >> 8) -> static_cast<u8>(x >> 8)
Truncate16(x & 0xFFFFu) -> static_cast<u16>(x)
Truncate16((x & 0xFFFF0000u) >> 16) -> static_cast<u16>(x >> 16)
The masks were dead-code: a static_cast to uN already keeps exactly
the low N bits.
UB fixes incidental to the fold (visible once the helpers were
unwrapped):
- SignExtendN<NBITS,T> internally did (static_cast<signed_T>(v) << S) >> S.
Signed left shift of a negative value is UB pre-C++20. After the
fold the shift is done in the unsigned domain first:
static_cast<sN>(static_cast<uN>(v) << S) >> S
All five SignExtendN callsite expansions (gpu_commands.cpp x2,
gpu_types.h, gte SignExtendMACResult, mdec.cpp x12) now do the
left shift on uN. Defined behaviour on every C++ standard from
C++98 onward. Right shift of a signed negative value remains
implementation-defined pre-C++20; this is the same as the
original helper and unchanged.
- mdec.cpp:650's SignExtendN<9,s32> took an s64 expression and
forced an implicit s64->int narrowing inside the template, which
-Wconversion flagged. The explicit static_cast<u32>(...) now
makes the narrow visible and the warning goes away. Bit-identical
result.
Sites deliberately not collapsed further, with reasons:
- spu.cpp:1347 (ADPCM pitch modulation): SignExtend32(step) where
step is u16 deliberately produces a u32 with the s16 sign bit
replicated, then multiplies by a u32 factor. Folding it as
static_cast<u32>(static_cast<s16>(step)) preserves the semantics
exactly. The naive 'static_cast<s32>(step) * factor' would not -
it'd evaluate s32 * s32 which is signed and may overflow as UB.
- gte.cpp:297-299 (IRGB conversion): Sign-extension here is observably
equivalent to zero-extension because (value & 0x1F) * 0x80 is
always <= 0xF80, bit 15 always clear. Folded as the literal
static_cast<u32>(static_cast<s16>(static_cast<u16>(...))) rather
than dropping the sign-extend step entirely - that would be a
semantic claim about hardware behaviour beyond the scope of a
helper-removal change.
- GTE TruncateRGB, TruncateAndSetMAC, TruncateAndSetIR,
TruncateAndSetMACAndIR (gte.cpp) and TruncateVertexPosition,
TruncateGPUVertexPosition (pgxp.cpp, gpu_types.h): these are
different functions, not the removed helpers. Left untouched.
bitutils.h's CountLeadingZeros / CountTrailingZeros are template
functions over T. The helper-removal leaves them inline-folding via
std::make_unsigned<T>::type, which is what ZeroExtend was doing
under the hood:
ZeroExtend64(value) ->
static_cast<u64>(static_cast<typename std::make_unsigned<T>::type>(value))
The remaining mechanical changes in cpu_recompiler_register_cache.h's
GetS32ConstantValue / GetS64ConstantValue and in pgxp.cpp's CPU_MULT
fold dropped redundant intermediate u-of-s-of-x casts that became
visible after the SignExtend64 expansion. Same codegen; cleaner.
Files touched: 43.
Helper definitions removed: 13 functions (~60 lines of types.h).
Build verification:
- Makefile.libretro platform=unix: clean build, zero warnings,
.so size 8031016 bytes (unchanged from HEAD).
- 25 retro_* exports unchanged.
- -Wall -Wextra on touched files: same warnings as HEAD (zero
new warnings from the fold, all pre-existing -Wunused-parameter).
- -Wconversion on touched files: one pre-existing warning
eliminated (mdec.cpp:650 SignExtendN<9,s32>(s64_expr) narrowing
is now an explicit static_cast<u32>); zero new warnings.
Codegen equivalence verified by inspection at every transformation
site:
Truncate8(x) = static_cast<u8>(x) ; both emit a movzx/byte-load
Truncate16(x) = static_cast<u16>(x) ; both emit a movzx/halfword-load
ZeroExtend32(u8) = static_cast<u32>(u8) ; both emit a movzx eax,al
ZeroExtend64(u32) = static_cast<u64>(u32); both emit a mov eax,reg (implicit zero-extend on x86-64)
SignExtend32(u8) = static_cast<u32>(static_cast<s8>(x)) ; both emit movsx eax,byte
SignExtend32(u16) = static_cast<u32>(static_cast<s16>(x)) ; both emit movsx eax,word
SignExtend64(u32) = static_cast<u64>(static_cast<s32>(x)) ; both emit movsxd rax,dword
SignExtendN<11,s32> = static_cast<s32>(static_cast<u32>(x) << 21) >> 21
both emit shl ; sar, identical 2-instruction sequence
2026-05-14 03:42:07 +00:00
|
|
|
PGXP::GetPreciseVertex(static_cast<u32>(maddr_and_pos >> 32), vp.bits, native_x, native_y, m_drawing_offset.x,
|
2020-08-02 17:17:05 +10:00
|
|
|
m_drawing_offset.y, &vertices[i].x, &vertices[i].y, &vertices[i].w);
|
2020-08-02 00:25:07 +10:00
|
|
|
}
|
|
|
|
|
}
|
2020-12-23 01:10:49 +10:00
|
|
|
if (pgxp)
|
2020-08-02 00:25:07 +10:00
|
|
|
{
|
2020-12-23 01:10:49 +10:00
|
|
|
if (!valid_w)
|
|
|
|
|
{
|
2022-06-26 03:03:37 +02:00
|
|
|
if (m_batch.use_depth_buffer)
|
|
|
|
|
SetBatchDepthBuffer(false);
|
2020-12-23 01:10:49 +10:00
|
|
|
for (BatchVertex& v : vertices)
|
|
|
|
|
v.w = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
else if (g_settings.gpu_pgxp_depth_buffer)
|
|
|
|
|
{
|
2021-03-30 01:40:04 +10:00
|
|
|
const bool use_depth = (m_batch.transparency_mode == GPUTransparencyMode::Disabled);
|
2022-06-26 03:03:37 +02:00
|
|
|
if (m_batch.use_depth_buffer != use_depth)
|
|
|
|
|
SetBatchDepthBuffer(use_depth);
|
2021-03-30 01:40:04 +10:00
|
|
|
if (use_depth)
|
|
|
|
|
CheckForDepthClear(vertices.data(), num_vertices);
|
2020-12-23 01:10:49 +10:00
|
|
|
}
|
2020-02-17 00:09:45 +09:00
|
|
|
}
|
2019-09-12 12:53:04 +10:00
|
|
|
|
2020-04-21 22:07:53 +10:00
|
|
|
if (rc.quad_polygon && m_resolution_scale > 1)
|
2020-03-28 02:24:22 +10:00
|
|
|
HandleFlippedQuadTextureCoordinates(vertices.data());
|
|
|
|
|
|
2020-08-10 22:37:30 +10:00
|
|
|
if (m_using_uv_limits && textured)
|
2020-08-10 22:37:07 +10:00
|
|
|
ComputePolygonUVLimits(vertices.data(), num_vertices);
|
|
|
|
|
|
2020-06-14 01:01:01 +10:00
|
|
|
if (!IsDrawingAreaIsValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-02-17 00:09:45 +09:00
|
|
|
// Cull polygons which are too large.
|
2020-08-02 17:32:43 +10:00
|
|
|
const auto [min_x_12, max_x_12] = MinMax(native_vertex_positions[1][0], native_vertex_positions[2][0]);
|
|
|
|
|
const auto [min_y_12, max_y_12] = MinMax(native_vertex_positions[1][1], native_vertex_positions[2][1]);
|
2020-08-02 00:25:07 +10:00
|
|
|
const s32 min_x = std::min(min_x_12, native_vertex_positions[0][0]);
|
|
|
|
|
const s32 max_x = std::max(max_x_12, native_vertex_positions[0][0]);
|
|
|
|
|
const s32 min_y = std::min(min_y_12, native_vertex_positions[0][1]);
|
|
|
|
|
const s32 max_y = std::max(max_y_12, native_vertex_positions[0][1]);
|
2020-04-15 23:50:14 +10:00
|
|
|
|
|
|
|
|
if ((max_x - min_x) >= MAX_PRIMITIVE_WIDTH || (max_y - min_y) >= MAX_PRIMITIVE_HEIGHT)
|
2020-02-17 00:09:45 +09:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-15 23:50:14 +10:00
|
|
|
const u32 clip_left = static_cast<u32>(std::clamp<s32>(min_x, m_drawing_area.left, m_drawing_area.right));
|
|
|
|
|
const u32 clip_right = static_cast<u32>(std::clamp<s32>(max_x, m_drawing_area.left, m_drawing_area.right)) + 1u;
|
|
|
|
|
const u32 clip_top = static_cast<u32>(std::clamp<s32>(min_y, m_drawing_area.top, m_drawing_area.bottom));
|
|
|
|
|
const u32 clip_bottom =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_y, m_drawing_area.top, m_drawing_area.bottom)) + 1u;
|
|
|
|
|
|
|
|
|
|
m_vram_dirty_rect.Include(clip_left, clip_right, clip_top, clip_bottom);
|
2020-10-03 14:10:54 +10:00
|
|
|
AddDrawTriangleTicks(native_vertex_positions[0][0], native_vertex_positions[0][1],
|
|
|
|
|
native_vertex_positions[1][0], native_vertex_positions[1][1],
|
|
|
|
|
native_vertex_positions[2][0], native_vertex_positions[2][1], rc.shading_enable,
|
|
|
|
|
rc.texture_enable, rc.transparency_enable);
|
2019-09-14 02:07:31 +10:00
|
|
|
|
2020-02-17 00:09:45 +09:00
|
|
|
std::memcpy(m_batch_current_vertex_ptr, vertices.data(), sizeof(BatchVertex) * 3);
|
|
|
|
|
m_batch_current_vertex_ptr += 3;
|
2019-09-12 12:53:04 +10:00
|
|
|
}
|
2019-11-24 23:46:33 +10:00
|
|
|
|
2020-02-17 00:09:45 +09:00
|
|
|
// quads
|
2020-03-28 02:24:22 +10:00
|
|
|
if (rc.quad_polygon)
|
2020-01-09 08:46:52 +10:00
|
|
|
{
|
2020-08-02 00:25:07 +10:00
|
|
|
const s32 min_x_123 = std::min(min_x_12, native_vertex_positions[3][0]);
|
|
|
|
|
const s32 max_x_123 = std::max(max_x_12, native_vertex_positions[3][0]);
|
|
|
|
|
const s32 min_y_123 = std::min(min_y_12, native_vertex_positions[3][1]);
|
|
|
|
|
const s32 max_y_123 = std::max(max_y_12, native_vertex_positions[3][1]);
|
2020-04-15 23:50:14 +10:00
|
|
|
|
2020-02-17 00:09:45 +09:00
|
|
|
// Cull polygons which are too large.
|
2020-04-15 23:50:14 +10:00
|
|
|
if ((max_x_123 - min_x_123) >= MAX_PRIMITIVE_WIDTH || (max_y_123 - min_y_123) >= MAX_PRIMITIVE_HEIGHT)
|
2020-02-17 00:09:45 +09:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-04-15 23:50:14 +10:00
|
|
|
const u32 clip_left = static_cast<u32>(std::clamp<s32>(min_x_123, m_drawing_area.left, m_drawing_area.right));
|
|
|
|
|
const u32 clip_right =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_x_123, m_drawing_area.left, m_drawing_area.right)) + 1u;
|
|
|
|
|
const u32 clip_top = static_cast<u32>(std::clamp<s32>(min_y_123, m_drawing_area.top, m_drawing_area.bottom));
|
|
|
|
|
const u32 clip_bottom =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_y_123, m_drawing_area.top, m_drawing_area.bottom)) + 1u;
|
|
|
|
|
|
|
|
|
|
m_vram_dirty_rect.Include(clip_left, clip_right, clip_top, clip_bottom);
|
2020-10-03 14:10:54 +10:00
|
|
|
AddDrawTriangleTicks(native_vertex_positions[2][0], native_vertex_positions[2][1],
|
|
|
|
|
native_vertex_positions[1][0], native_vertex_positions[1][1],
|
|
|
|
|
native_vertex_positions[3][0], native_vertex_positions[3][1], rc.shading_enable,
|
|
|
|
|
rc.texture_enable, rc.transparency_enable);
|
2020-02-17 00:09:45 +09:00
|
|
|
|
|
|
|
|
AddVertex(vertices[2]);
|
|
|
|
|
AddVertex(vertices[1]);
|
|
|
|
|
AddVertex(vertices[3]);
|
|
|
|
|
}
|
2020-01-09 08:46:52 +10:00
|
|
|
}
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendDrawPolygonCommand* cmd = m_sw_renderer->NewDrawPolygonCommand(num_vertices);
|
|
|
|
|
FillDrawCommand(cmd, rc);
|
|
|
|
|
|
|
|
|
|
for (u32 i = 0; i < num_vertices; i++)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendDrawPolygonCommand::Vertex* vert = &cmd->vertices[i];
|
|
|
|
|
vert->x = native_vertex_positions[i][0];
|
|
|
|
|
vert->y = native_vertex_positions[i][1];
|
|
|
|
|
vert->texcoord = native_texcoords[i];
|
|
|
|
|
vert->color = vertices[i].color;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
2019-09-12 12:53:04 +10:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Rectangle:
|
2019-09-14 16:27:24 +10:00
|
|
|
{
|
|
|
|
|
const u32 color = rc.color_for_first_vertex;
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPUVertexPosition vp{FifoPop()};
|
|
|
|
|
const s32 pos_x = TruncateGPUVertexPosition(m_drawing_offset.x + vp.x);
|
|
|
|
|
const s32 pos_y = TruncateGPUVertexPosition(m_drawing_offset.y + vp.y);
|
2020-02-09 22:49:50 +09:00
|
|
|
|
common: remove SignExtend / ZeroExtend / Truncate helpers in favour of explicit casts
The src/common/types.h helpers SignExtend16/32/64, ZeroExtend16/32/64,
Truncate8/16/32, the generic SignExtend<TR,TV> and ZeroExtend<TR,TV>
templates, and SignExtendN<N,T> were thin wrappers around explicit
static_cast chains. They served a documentation role ("this cast is
intentional, not a typo") in places where the underlying intent was
"narrow this value" or "sign-extend this value", but in practice
they obscured rather than clarified - particularly when several
nested together (SignExtend32(Truncate8(x)) is just (u32)(s8)x).
Tree-wide fold:
Truncate8(x) -> static_cast<u8>(x)
Truncate16(x) -> static_cast<u16>(x)
Truncate32(x) -> static_cast<u32>(x)
ZeroExtendN(u_x) -> static_cast<uN>(u_x)
SignExtendN(u_x) -> static_cast<uN>(static_cast<sM>(u_x)) (M = source width)
SignExtendN(s_x) -> static_cast<uN>(s_x) (relies on int promotion)
SignExtendN<BITS,T>(x) -> static_cast<sN>(static_cast<uN>(x) << S) >> S (S = N*8 - BITS)
SignExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<sM>(x))
ZeroExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<uM>(x))
Mask cleanup applied where the mask matched the truncation width:
Truncate8(x & 0xFFu) -> static_cast<u8>(x)
Truncate8((x & 0xFF00u) >> 8) -> static_cast<u8>(x >> 8)
Truncate16(x & 0xFFFFu) -> static_cast<u16>(x)
Truncate16((x & 0xFFFF0000u) >> 16) -> static_cast<u16>(x >> 16)
The masks were dead-code: a static_cast to uN already keeps exactly
the low N bits.
UB fixes incidental to the fold (visible once the helpers were
unwrapped):
- SignExtendN<NBITS,T> internally did (static_cast<signed_T>(v) << S) >> S.
Signed left shift of a negative value is UB pre-C++20. After the
fold the shift is done in the unsigned domain first:
static_cast<sN>(static_cast<uN>(v) << S) >> S
All five SignExtendN callsite expansions (gpu_commands.cpp x2,
gpu_types.h, gte SignExtendMACResult, mdec.cpp x12) now do the
left shift on uN. Defined behaviour on every C++ standard from
C++98 onward. Right shift of a signed negative value remains
implementation-defined pre-C++20; this is the same as the
original helper and unchanged.
- mdec.cpp:650's SignExtendN<9,s32> took an s64 expression and
forced an implicit s64->int narrowing inside the template, which
-Wconversion flagged. The explicit static_cast<u32>(...) now
makes the narrow visible and the warning goes away. Bit-identical
result.
Sites deliberately not collapsed further, with reasons:
- spu.cpp:1347 (ADPCM pitch modulation): SignExtend32(step) where
step is u16 deliberately produces a u32 with the s16 sign bit
replicated, then multiplies by a u32 factor. Folding it as
static_cast<u32>(static_cast<s16>(step)) preserves the semantics
exactly. The naive 'static_cast<s32>(step) * factor' would not -
it'd evaluate s32 * s32 which is signed and may overflow as UB.
- gte.cpp:297-299 (IRGB conversion): Sign-extension here is observably
equivalent to zero-extension because (value & 0x1F) * 0x80 is
always <= 0xF80, bit 15 always clear. Folded as the literal
static_cast<u32>(static_cast<s16>(static_cast<u16>(...))) rather
than dropping the sign-extend step entirely - that would be a
semantic claim about hardware behaviour beyond the scope of a
helper-removal change.
- GTE TruncateRGB, TruncateAndSetMAC, TruncateAndSetIR,
TruncateAndSetMACAndIR (gte.cpp) and TruncateVertexPosition,
TruncateGPUVertexPosition (pgxp.cpp, gpu_types.h): these are
different functions, not the removed helpers. Left untouched.
bitutils.h's CountLeadingZeros / CountTrailingZeros are template
functions over T. The helper-removal leaves them inline-folding via
std::make_unsigned<T>::type, which is what ZeroExtend was doing
under the hood:
ZeroExtend64(value) ->
static_cast<u64>(static_cast<typename std::make_unsigned<T>::type>(value))
The remaining mechanical changes in cpu_recompiler_register_cache.h's
GetS32ConstantValue / GetS64ConstantValue and in pgxp.cpp's CPU_MULT
fold dropped redundant intermediate u-of-s-of-x casts that became
visible after the SignExtend64 expansion. Same codegen; cleaner.
Files touched: 43.
Helper definitions removed: 13 functions (~60 lines of types.h).
Build verification:
- Makefile.libretro platform=unix: clean build, zero warnings,
.so size 8031016 bytes (unchanged from HEAD).
- 25 retro_* exports unchanged.
- -Wall -Wextra on touched files: same warnings as HEAD (zero
new warnings from the fold, all pre-existing -Wunused-parameter).
- -Wconversion on touched files: one pre-existing warning
eliminated (mdec.cpp:650 SignExtendN<9,s32>(s64_expr) narrowing
is now an explicit static_cast<u32>); zero new warnings.
Codegen equivalence verified by inspection at every transformation
site:
Truncate8(x) = static_cast<u8>(x) ; both emit a movzx/byte-load
Truncate16(x) = static_cast<u16>(x) ; both emit a movzx/halfword-load
ZeroExtend32(u8) = static_cast<u32>(u8) ; both emit a movzx eax,al
ZeroExtend64(u32) = static_cast<u64>(u32); both emit a mov eax,reg (implicit zero-extend on x86-64)
SignExtend32(u8) = static_cast<u32>(static_cast<s8>(x)) ; both emit movsx eax,byte
SignExtend32(u16) = static_cast<u32>(static_cast<s16>(x)) ; both emit movsx eax,word
SignExtend64(u32) = static_cast<u64>(static_cast<s32>(x)) ; both emit movsxd rax,dword
SignExtendN<11,s32> = static_cast<s32>(static_cast<u32>(x) << 21) >> 21
both emit shl ; sar, identical 2-instruction sequence
2026-05-14 03:42:07 +00:00
|
|
|
const auto [texcoord_x, texcoord_y] = UnpackTexcoord(rc.texture_enable ? static_cast<u16>(FifoPop()) : 0);
|
|
|
|
|
u16 orig_tex_left = static_cast<u16>(texcoord_x);
|
|
|
|
|
u16 orig_tex_top = static_cast<u16>(texcoord_y);
|
2020-02-17 00:09:31 +09:00
|
|
|
s32 rectangle_width;
|
|
|
|
|
s32 rectangle_height;
|
2019-09-14 16:27:24 +10:00
|
|
|
switch (rc.rectangle_size)
|
|
|
|
|
{
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUDrawRectangleSize::R1x1:
|
2019-09-14 16:27:24 +10:00
|
|
|
rectangle_width = 1;
|
|
|
|
|
rectangle_height = 1;
|
|
|
|
|
break;
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUDrawRectangleSize::R8x8:
|
2019-09-14 16:27:24 +10:00
|
|
|
rectangle_width = 8;
|
|
|
|
|
rectangle_height = 8;
|
|
|
|
|
break;
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUDrawRectangleSize::R16x16:
|
2019-09-14 16:27:24 +10:00
|
|
|
rectangle_width = 16;
|
|
|
|
|
rectangle_height = 16;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-04-19 01:16:58 +10:00
|
|
|
{
|
2020-08-02 00:25:07 +10:00
|
|
|
const u32 width_and_height = FifoPop();
|
2020-05-21 12:04:53 +10:00
|
|
|
rectangle_width = static_cast<s32>(width_and_height & VRAM_WIDTH_MASK);
|
|
|
|
|
rectangle_height = static_cast<s32>((width_and_height >> 16) & VRAM_HEIGHT_MASK);
|
|
|
|
|
|
|
|
|
|
if (rectangle_width >= MAX_PRIMITIVE_WIDTH || rectangle_height >= MAX_PRIMITIVE_HEIGHT)
|
|
|
|
|
return;
|
2020-04-19 01:16:58 +10:00
|
|
|
}
|
|
|
|
|
break;
|
2019-09-14 16:27:24 +10:00
|
|
|
}
|
|
|
|
|
|
2020-06-14 01:01:01 +10:00
|
|
|
if (!IsDrawingAreaIsValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-12-23 01:10:49 +10:00
|
|
|
// we can split the rectangle up into potentially 8 quads
|
2022-06-26 03:03:37 +02:00
|
|
|
if (m_batch.use_depth_buffer)
|
|
|
|
|
SetBatchDepthBuffer(false);
|
2020-12-23 01:10:49 +10:00
|
|
|
|
2020-02-17 00:09:31 +09:00
|
|
|
// Split the rectangle into multiple quads if it's greater than 256x256, as the texture page should repeat.
|
|
|
|
|
u16 tex_top = orig_tex_top;
|
|
|
|
|
for (s32 y_offset = 0; y_offset < rectangle_height;)
|
|
|
|
|
{
|
|
|
|
|
const s32 quad_height = std::min<s32>(rectangle_height - y_offset, TEXTURE_PAGE_WIDTH - tex_top);
|
2020-08-02 00:25:07 +10:00
|
|
|
const float quad_start_y = static_cast<float>(pos_y + y_offset);
|
|
|
|
|
const float quad_end_y = quad_start_y + static_cast<float>(quad_height);
|
2020-02-17 00:09:31 +09:00
|
|
|
const u16 tex_bottom = tex_top + static_cast<u16>(quad_height);
|
2019-09-14 16:27:24 +10:00
|
|
|
|
2020-02-17 00:09:31 +09:00
|
|
|
u16 tex_left = orig_tex_left;
|
|
|
|
|
for (s32 x_offset = 0; x_offset < rectangle_width;)
|
|
|
|
|
{
|
|
|
|
|
const s32 quad_width = std::min<s32>(rectangle_width - x_offset, TEXTURE_PAGE_HEIGHT - tex_left);
|
2020-08-02 00:25:07 +10:00
|
|
|
const float quad_start_x = static_cast<float>(pos_x + x_offset);
|
|
|
|
|
const float quad_end_x = quad_start_x + static_cast<float>(quad_width);
|
2020-02-17 00:09:31 +09:00
|
|
|
const u16 tex_right = tex_left + static_cast<u16>(quad_width);
|
2020-08-10 22:37:07 +10:00
|
|
|
const u32 uv_limits = BatchVertex::PackUVLimits(tex_left, tex_right - 1, tex_top, tex_bottom - 1);
|
2020-02-17 00:09:31 +09:00
|
|
|
|
2020-08-10 22:37:07 +10:00
|
|
|
AddNewVertex(quad_start_x, quad_start_y, depth, 1.0f, color, texpage, tex_left, tex_top, uv_limits);
|
|
|
|
|
AddNewVertex(quad_end_x, quad_start_y, depth, 1.0f, color, texpage, tex_right, tex_top, uv_limits);
|
|
|
|
|
AddNewVertex(quad_start_x, quad_end_y, depth, 1.0f, color, texpage, tex_left, tex_bottom, uv_limits);
|
2020-02-17 00:09:31 +09:00
|
|
|
|
2020-08-10 22:37:07 +10:00
|
|
|
AddNewVertex(quad_start_x, quad_end_y, depth, 1.0f, color, texpage, tex_left, tex_bottom, uv_limits);
|
|
|
|
|
AddNewVertex(quad_end_x, quad_start_y, depth, 1.0f, color, texpage, tex_right, tex_top, uv_limits);
|
|
|
|
|
AddNewVertex(quad_end_x, quad_end_y, depth, 1.0f, color, texpage, tex_right, tex_bottom, uv_limits);
|
2020-02-17 00:09:31 +09:00
|
|
|
|
|
|
|
|
x_offset += quad_width;
|
|
|
|
|
tex_left = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
y_offset += quad_height;
|
|
|
|
|
tex_top = 0;
|
|
|
|
|
}
|
2020-04-15 23:50:14 +10:00
|
|
|
|
|
|
|
|
const u32 clip_left = static_cast<u32>(std::clamp<s32>(pos_x, m_drawing_area.left, m_drawing_area.right));
|
|
|
|
|
const u32 clip_right =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(pos_x + rectangle_width, m_drawing_area.left, m_drawing_area.right)) + 1u;
|
|
|
|
|
const u32 clip_top = static_cast<u32>(std::clamp<s32>(pos_y, m_drawing_area.top, m_drawing_area.bottom));
|
|
|
|
|
const u32 clip_bottom =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(pos_y + rectangle_height, m_drawing_area.top, m_drawing_area.bottom)) + 1u;
|
|
|
|
|
|
|
|
|
|
m_vram_dirty_rect.Include(clip_left, clip_right, clip_top, clip_bottom);
|
2020-06-13 01:29:48 +10:00
|
|
|
AddDrawRectangleTicks(clip_right - clip_left, clip_bottom - clip_top, rc.texture_enable, rc.transparency_enable);
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendDrawRectangleCommand* cmd = m_sw_renderer->NewDrawRectangleCommand();
|
|
|
|
|
FillDrawCommand(cmd, rc);
|
|
|
|
|
cmd->color = color;
|
|
|
|
|
cmd->x = pos_x;
|
|
|
|
|
cmd->y = pos_y;
|
|
|
|
|
cmd->width = static_cast<u16>(rectangle_width);
|
|
|
|
|
cmd->height = static_cast<u16>(rectangle_height);
|
|
|
|
|
cmd->texcoord = (static_cast<u16>(texcoord_y) << 8) | static_cast<u16>(texcoord_x);
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
2019-09-14 16:27:24 +10:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Line:
|
2019-09-27 22:45:57 +10:00
|
|
|
{
|
2022-06-26 03:03:37 +02:00
|
|
|
if (m_batch.use_depth_buffer)
|
|
|
|
|
SetBatchDepthBuffer(false);
|
2020-12-23 01:10:49 +10:00
|
|
|
|
2020-04-21 15:45:22 +10:00
|
|
|
if (!rc.polyline)
|
2019-09-27 22:45:57 +10:00
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
u32 start_color, end_color;
|
2020-10-22 19:31:28 +10:00
|
|
|
GPUVertexPosition start_pos, end_pos;
|
2020-04-21 15:45:22 +10:00
|
|
|
if (rc.shading_enable)
|
2020-04-19 01:16:58 +10:00
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
start_color = rc.color_for_first_vertex;
|
|
|
|
|
start_pos.bits = FifoPop();
|
|
|
|
|
end_color = FifoPop() & UINT32_C(0x00FFFFFF);
|
|
|
|
|
end_pos.bits = FifoPop();
|
2020-04-19 01:16:58 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
start_color = end_color = rc.color_for_first_vertex;
|
|
|
|
|
start_pos.bits = FifoPop();
|
|
|
|
|
end_pos.bits = FifoPop();
|
2020-04-19 01:16:58 +10:00
|
|
|
}
|
2019-11-24 23:46:33 +10:00
|
|
|
|
2020-06-14 01:01:01 +10:00
|
|
|
if (!IsDrawingAreaIsValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
s32 start_x = start_pos.x + m_drawing_offset.x;
|
|
|
|
|
s32 start_y = start_pos.y + m_drawing_offset.y;
|
|
|
|
|
s32 end_x = end_pos.x + m_drawing_offset.x;
|
|
|
|
|
s32 end_y = end_pos.y + m_drawing_offset.y;
|
|
|
|
|
const auto [min_x, max_x] = MinMax(start_x, end_x);
|
|
|
|
|
const auto [min_y, max_y] = MinMax(start_y, end_y);
|
|
|
|
|
if ((max_x - min_x) >= MAX_PRIMITIVE_WIDTH || (max_y - min_y) >= MAX_PRIMITIVE_HEIGHT)
|
2020-04-21 15:45:22 +10:00
|
|
|
return;
|
2020-04-15 23:50:14 +10:00
|
|
|
|
2020-12-05 16:47:34 +10:00
|
|
|
const u32 clip_left = static_cast<u32>(std::clamp<s32>(min_x, m_drawing_area.left, m_drawing_area.right));
|
2020-04-21 15:45:22 +10:00
|
|
|
const u32 clip_right = static_cast<u32>(std::clamp<s32>(max_x, m_drawing_area.left, m_drawing_area.right)) + 1u;
|
|
|
|
|
const u32 clip_top = static_cast<u32>(std::clamp<s32>(min_y, m_drawing_area.top, m_drawing_area.bottom));
|
|
|
|
|
const u32 clip_bottom =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_y, m_drawing_area.top, m_drawing_area.bottom)) + 1u;
|
|
|
|
|
|
|
|
|
|
m_vram_dirty_rect.Include(clip_left, clip_right, clip_top, clip_bottom);
|
|
|
|
|
AddDrawLineTicks(clip_right - clip_left, clip_bottom - clip_top, rc.shading_enable);
|
2020-08-02 17:17:05 +10:00
|
|
|
|
|
|
|
|
// TODO: Should we do a PGXP lookup here? Most lines are 2D.
|
|
|
|
|
DrawLine(static_cast<float>(start_x), static_cast<float>(start_y), start_color, static_cast<float>(end_x),
|
|
|
|
|
static_cast<float>(end_y), end_color, depth);
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendDrawLineCommand* cmd = m_sw_renderer->NewDrawLineCommand(2);
|
|
|
|
|
FillDrawCommand(cmd, rc);
|
|
|
|
|
cmd->vertices[0].Set(start_x, start_y, start_color);
|
|
|
|
|
cmd->vertices[1].Set(end_x, end_y, end_color);
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
2020-04-21 15:45:22 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Multiply by two because we don't use line strips.
|
|
|
|
|
const u32 num_vertices = GetPolyLineVertexCount();
|
|
|
|
|
|
2020-06-14 01:01:01 +10:00
|
|
|
if (!IsDrawingAreaIsValid())
|
|
|
|
|
return;
|
|
|
|
|
|
2020-04-21 15:45:22 +10:00
|
|
|
const bool shaded = rc.shading_enable;
|
|
|
|
|
|
|
|
|
|
u32 buffer_pos = 0;
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPUVertexPosition start_vp{m_blit_buffer[buffer_pos++]};
|
2020-08-02 17:17:05 +10:00
|
|
|
s32 start_x = start_vp.x + m_drawing_offset.x;
|
|
|
|
|
s32 start_y = start_vp.y + m_drawing_offset.y;
|
|
|
|
|
u32 start_color = rc.color_for_first_vertex;
|
|
|
|
|
|
2021-05-19 13:43:49 +10:00
|
|
|
GPUBackendDrawLineCommand* cmd;
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
cmd = m_sw_renderer->NewDrawLineCommand(num_vertices);
|
|
|
|
|
FillDrawCommand(cmd, rc);
|
|
|
|
|
cmd->vertices[0].Set(start_x, start_y, start_color);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
cmd = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
for (u32 i = 1; i < num_vertices; i++)
|
2020-04-21 15:45:22 +10:00
|
|
|
{
|
2020-08-02 17:17:05 +10:00
|
|
|
const u32 end_color = shaded ? (m_blit_buffer[buffer_pos++] & UINT32_C(0x00FFFFFF)) : start_color;
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPUVertexPosition vp{m_blit_buffer[buffer_pos++]};
|
2020-08-02 17:17:05 +10:00
|
|
|
const s32 end_x = m_drawing_offset.x + vp.x;
|
|
|
|
|
const s32 end_y = m_drawing_offset.y + vp.y;
|
2020-04-21 15:45:22 +10:00
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
const auto [min_x, max_x] = MinMax(start_x, end_x);
|
|
|
|
|
const auto [min_y, max_y] = MinMax(start_y, end_y);
|
|
|
|
|
if ((max_x - min_x) >= MAX_PRIMITIVE_WIDTH || (max_y - min_y) >= MAX_PRIMITIVE_HEIGHT)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
2020-02-17 00:09:45 +09:00
|
|
|
{
|
2020-12-05 16:47:34 +10:00
|
|
|
const u32 clip_left = static_cast<u32>(std::clamp<s32>(min_x, m_drawing_area.left, m_drawing_area.right));
|
2020-08-02 17:17:05 +10:00
|
|
|
const u32 clip_right =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_x, m_drawing_area.left, m_drawing_area.right)) + 1u;
|
|
|
|
|
const u32 clip_top = static_cast<u32>(std::clamp<s32>(min_y, m_drawing_area.top, m_drawing_area.bottom));
|
|
|
|
|
const u32 clip_bottom =
|
|
|
|
|
static_cast<u32>(std::clamp<s32>(max_y, m_drawing_area.top, m_drawing_area.bottom)) + 1u;
|
|
|
|
|
|
|
|
|
|
m_vram_dirty_rect.Include(clip_left, clip_right, clip_top, clip_bottom);
|
|
|
|
|
AddDrawLineTicks(clip_right - clip_left, clip_bottom - clip_top, rc.shading_enable);
|
|
|
|
|
|
|
|
|
|
// TODO: Should we do a PGXP lookup here? Most lines are 2D.
|
|
|
|
|
DrawLine(static_cast<float>(start_x), static_cast<float>(start_y), start_color, static_cast<float>(end_x),
|
|
|
|
|
static_cast<float>(end_y), end_color, depth);
|
2020-02-17 00:09:45 +09:00
|
|
|
}
|
|
|
|
|
|
2020-08-02 17:17:05 +10:00
|
|
|
start_x = end_x;
|
|
|
|
|
start_y = end_y;
|
|
|
|
|
start_color = end_color;
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (cmd)
|
|
|
|
|
cmd->vertices[i].Set(end_x, end_y, end_color);
|
2020-04-21 15:45:22 +10:00
|
|
|
}
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (cmd)
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
2019-09-27 22:45:57 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2019-09-12 12:53:04 +10:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-11-02 22:21:56 +10:00
|
|
|
}
|
|
|
|
|
|
2019-09-13 00:18:13 +10:00
|
|
|
void GPU_HW::CalcScissorRect(int* left, int* top, int* right, int* bottom)
|
|
|
|
|
{
|
2019-10-05 14:36:48 +10:00
|
|
|
*left = m_drawing_area.left * m_resolution_scale;
|
|
|
|
|
*right = std::max<u32>((m_drawing_area.right + 1) * m_resolution_scale, *left + 1);
|
|
|
|
|
*top = m_drawing_area.top * m_resolution_scale;
|
|
|
|
|
*bottom = std::max<u32>((m_drawing_area.bottom + 1) * m_resolution_scale, *top + 1);
|
2019-09-13 00:18:13 +10:00
|
|
|
}
|
|
|
|
|
|
2020-07-22 14:46:52 +10:00
|
|
|
GPU_HW::VRAMFillUBOData GPU_HW::GetVRAMFillUBOData(u32 x, u32 y, u32 width, u32 height, u32 color) const
|
|
|
|
|
{
|
|
|
|
|
// drop precision unless true colour is enabled
|
|
|
|
|
if (!m_true_color)
|
2021-03-18 12:55:02 +10:00
|
|
|
color = VRAMRGBA5551ToRGBA8888(VRAMRGBA8888ToRGBA5551(color));
|
2020-07-22 14:46:52 +10:00
|
|
|
|
|
|
|
|
VRAMFillUBOData uniforms;
|
2021-07-21 19:22:04 +10:00
|
|
|
uniforms.u_dst_x = (x % VRAM_WIDTH) * m_resolution_scale;
|
|
|
|
|
uniforms.u_dst_y = (y % VRAM_HEIGHT) * m_resolution_scale;
|
|
|
|
|
uniforms.u_end_x = ((x + width) % VRAM_WIDTH) * m_resolution_scale;
|
|
|
|
|
uniforms.u_end_y = ((y + height) % VRAM_HEIGHT) * m_resolution_scale;
|
2020-07-22 14:46:52 +10:00
|
|
|
std::tie(uniforms.u_fill_color[0], uniforms.u_fill_color[1], uniforms.u_fill_color[2], uniforms.u_fill_color[3]) =
|
|
|
|
|
RGBA8ToFloat(color);
|
2020-12-23 01:10:49 +10:00
|
|
|
|
2020-07-22 14:46:52 +10:00
|
|
|
uniforms.u_interlaced_displayed_field = GetActiveLineLSB();
|
|
|
|
|
return uniforms;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 22:30:54 +10:00
|
|
|
Common::Rectangle<u32> GPU_HW::GetVRAMTransferBounds(u32 x, u32 y, u32 width, u32 height) const
|
2019-11-14 16:58:27 +10:00
|
|
|
{
|
2020-07-22 14:46:52 +10:00
|
|
|
Common::Rectangle<u32> out_rc = Common::Rectangle<u32>::FromExtents(x % VRAM_WIDTH, y % VRAM_HEIGHT, width, height);
|
2019-11-14 16:58:27 +10:00
|
|
|
if (out_rc.right > VRAM_WIDTH)
|
|
|
|
|
{
|
|
|
|
|
out_rc.left = 0;
|
|
|
|
|
out_rc.right = VRAM_WIDTH;
|
|
|
|
|
}
|
|
|
|
|
if (out_rc.bottom > VRAM_HEIGHT)
|
|
|
|
|
{
|
|
|
|
|
out_rc.top = 0;
|
|
|
|
|
out_rc.bottom = VRAM_HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
return out_rc;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 02:19:28 +10:00
|
|
|
GPU_HW::VRAMWriteUBOData GPU_HW::GetVRAMWriteUBOData(u32 x, u32 y, u32 width, u32 height, u32 buffer_offset,
|
|
|
|
|
bool set_mask, bool check_mask) const
|
2020-07-11 20:18:07 +10:00
|
|
|
{
|
2020-12-15 02:19:28 +10:00
|
|
|
const VRAMWriteUBOData uniforms = {
|
|
|
|
|
(x % VRAM_WIDTH), (y % VRAM_HEIGHT), ((x + width) % VRAM_WIDTH), ((y + height) % VRAM_HEIGHT), width,
|
|
|
|
|
height, buffer_offset, (set_mask) ? 0x8000u : 0x00, GetCurrentNormalizedVertexDepth()};
|
2020-07-11 20:18:07 +10:00
|
|
|
return uniforms;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-22 14:46:52 +10:00
|
|
|
bool GPU_HW::UseVRAMCopyShader(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) const
|
2020-06-19 00:18:17 +10:00
|
|
|
{
|
2020-07-22 14:46:52 +10:00
|
|
|
// masking enabled, oversized, or overlapping
|
|
|
|
|
return (m_GPUSTAT.IsMaskingEnabled() || ((src_x % VRAM_WIDTH) + width) > VRAM_WIDTH ||
|
|
|
|
|
((src_y % VRAM_HEIGHT) + height) > VRAM_HEIGHT || ((dst_x % VRAM_WIDTH) + width) > VRAM_WIDTH ||
|
|
|
|
|
((dst_y % VRAM_HEIGHT) + height) > VRAM_HEIGHT ||
|
|
|
|
|
Common::Rectangle<u32>::FromExtents(src_x, src_y, width, height)
|
|
|
|
|
.Intersects(Common::Rectangle<u32>::FromExtents(dst_x, dst_y, width, height)));
|
2020-06-19 00:18:17 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GPU_HW::VRAMCopyUBOData GPU_HW::GetVRAMCopyUBOData(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width,
|
|
|
|
|
u32 height) const
|
|
|
|
|
{
|
2020-07-22 14:46:52 +10:00
|
|
|
const VRAMCopyUBOData uniforms = {(src_x % VRAM_WIDTH) * m_resolution_scale,
|
|
|
|
|
(src_y % VRAM_HEIGHT) * m_resolution_scale,
|
|
|
|
|
(dst_x % VRAM_WIDTH) * m_resolution_scale,
|
|
|
|
|
(dst_y % VRAM_HEIGHT) * m_resolution_scale,
|
2020-06-19 00:18:17 +10:00
|
|
|
((dst_x + width) % VRAM_WIDTH) * m_resolution_scale,
|
|
|
|
|
((dst_y + height) % VRAM_HEIGHT) * m_resolution_scale,
|
|
|
|
|
width * m_resolution_scale,
|
|
|
|
|
height * m_resolution_scale,
|
|
|
|
|
m_GPUSTAT.set_mask_while_drawing ? 1u : 0u,
|
2020-06-20 20:21:32 +10:00
|
|
|
GetCurrentNormalizedVertexDepth()};
|
2020-06-19 00:18:17 +10:00
|
|
|
|
|
|
|
|
return uniforms;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-07 20:00:16 +10:00
|
|
|
void GPU_HW::IncludeVRAMDirtyRectangle(const Common::Rectangle<u32>& rect)
|
2020-02-09 22:49:50 +09:00
|
|
|
{
|
|
|
|
|
m_vram_dirty_rect.Include(rect);
|
|
|
|
|
|
|
|
|
|
// the vram area can include the texture page, but the game can leave it as-is. in this case, set it as dirty so the
|
|
|
|
|
// shadow texture is updated
|
2020-02-12 20:58:34 +09:00
|
|
|
if (!m_draw_mode.IsTexturePageChanged() &&
|
2020-10-22 19:31:28 +10:00
|
|
|
(m_draw_mode.mode_reg.GetTexturePageRectangle().Intersects(rect) ||
|
2020-11-22 13:22:20 +10:00
|
|
|
(m_draw_mode.mode_reg.IsUsingPalette() && m_draw_mode.GetTexturePaletteRectangle().Intersects(rect))))
|
2020-02-09 22:49:50 +09:00
|
|
|
{
|
|
|
|
|
m_draw_mode.SetTexturePageChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-28 22:58:31 +10:00
|
|
|
void GPU_HW::EnsureVertexBufferSpace(u32 required_vertices)
|
|
|
|
|
{
|
|
|
|
|
if (m_batch_current_vertex_ptr)
|
|
|
|
|
{
|
|
|
|
|
if (GetBatchVertexSpace() >= required_vertices)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FlushRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MapBatchVertexPointer(required_vertices);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-03 17:11:28 +10:00
|
|
|
void GPU_HW::EnsureVertexBufferSpaceForCurrentCommand()
|
|
|
|
|
{
|
|
|
|
|
u32 required_vertices;
|
|
|
|
|
switch (m_render_command.primitive)
|
|
|
|
|
{
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Polygon:
|
2020-05-03 17:11:28 +10:00
|
|
|
required_vertices = m_render_command.quad_polygon ? 6 : 3;
|
|
|
|
|
break;
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Rectangle:
|
2020-05-03 17:11:28 +10:00
|
|
|
required_vertices = MAX_VERTICES_FOR_RECTANGLE;
|
|
|
|
|
break;
|
2020-10-22 19:31:28 +10:00
|
|
|
case GPUPrimitive::Line:
|
2020-05-03 17:11:28 +10:00
|
|
|
default:
|
2020-08-02 17:17:05 +10:00
|
|
|
required_vertices = m_render_command.polyline ? (GetPolyLineVertexCount() * 6u) : 6u;
|
2020-05-03 17:11:28 +10:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// can we fit these vertices in the current depth buffer range?
|
2020-06-20 20:21:32 +10:00
|
|
|
if ((m_current_depth + required_vertices) > MAX_BATCH_VERTEX_COUNTER_IDS)
|
2020-05-03 17:11:28 +10:00
|
|
|
{
|
|
|
|
|
// implies FlushRender()
|
2020-06-20 20:21:32 +10:00
|
|
|
ResetBatchVertexDepth();
|
2020-05-03 17:11:28 +10:00
|
|
|
}
|
|
|
|
|
else if (m_batch_current_vertex_ptr)
|
|
|
|
|
{
|
|
|
|
|
if (GetBatchVertexSpace() >= required_vertices)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FlushRender();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MapBatchVertexPointer(required_vertices);
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-20 20:21:32 +10:00
|
|
|
void GPU_HW::ResetBatchVertexDepth()
|
2020-05-03 17:11:28 +10:00
|
|
|
{
|
2020-12-23 01:10:49 +10:00
|
|
|
if (m_pgxp_depth_buffer)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-05-03 17:11:28 +10:00
|
|
|
FlushRender();
|
|
|
|
|
UpdateDepthBufferFromMaskBit();
|
|
|
|
|
|
2020-06-20 20:21:32 +10:00
|
|
|
m_current_depth = 1;
|
2020-05-03 17:11:28 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-19 13:43:49 +10:00
|
|
|
void GPU_HW::UpdateSoftwareRenderer(bool copy_vram_from_hw)
|
|
|
|
|
{
|
|
|
|
|
const bool current_enabled = (m_sw_renderer != nullptr);
|
|
|
|
|
const bool new_enabled = g_settings.gpu_use_software_renderer_for_readbacks;
|
|
|
|
|
if (current_enabled == new_enabled)
|
|
|
|
|
return;
|
|
|
|
|
|
2022-01-21 21:14:41 +01:00
|
|
|
m_vram_ptr = m_vram_shadow.data();
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
if (!new_enabled)
|
|
|
|
|
{
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
m_sw_renderer->Shutdown();
|
|
|
|
|
m_sw_renderer.reset();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<GPU_SW_Backend> sw_renderer = std::make_unique<GPU_SW_Backend>();
|
|
|
|
|
if (!sw_renderer->Initialize(true))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// We need to fill in the SW renderer's VRAM with the current state for hot toggles.
|
|
|
|
|
if (copy_vram_from_hw)
|
|
|
|
|
{
|
|
|
|
|
FlushRender();
|
|
|
|
|
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
2022-01-21 21:14:41 +01:00
|
|
|
std::memcpy(sw_renderer->GetVRAM(), m_vram_ptr, sizeof(u16) * VRAM_WIDTH * VRAM_HEIGHT);
|
2021-05-19 13:43:49 +10:00
|
|
|
|
|
|
|
|
// Sync the drawing area.
|
|
|
|
|
GPUBackendSetDrawingAreaCommand* cmd = sw_renderer->NewSetDrawingAreaCommand();
|
|
|
|
|
cmd->new_area = m_drawing_area;
|
|
|
|
|
sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_sw_renderer = std::move(sw_renderer);
|
2022-01-21 21:14:41 +01:00
|
|
|
m_vram_ptr = m_sw_renderer->GetVRAM();
|
2021-05-19 13:43:49 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-20 14:01:47 +10:00
|
|
|
void GPU_HW::FillBackendCommandParameters(GPUBackendCommand* cmd) const
|
|
|
|
|
{
|
|
|
|
|
cmd->params.bits = 0;
|
|
|
|
|
cmd->params.check_mask_before_draw = m_GPUSTAT.check_mask_before_draw;
|
|
|
|
|
cmd->params.set_mask_while_drawing = m_GPUSTAT.set_mask_while_drawing;
|
|
|
|
|
cmd->params.active_line_lsb = m_crtc_state.active_line_lsb;
|
|
|
|
|
cmd->params.interlaced_rendering = m_GPUSTAT.SkipDrawingToActiveField();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::FillDrawCommand(GPUBackendDrawCommand* cmd, GPURenderCommand rc) const
|
|
|
|
|
{
|
|
|
|
|
FillBackendCommandParameters(cmd);
|
|
|
|
|
cmd->rc.bits = rc.bits;
|
|
|
|
|
cmd->draw_mode.bits = m_draw_mode.mode_reg.bits;
|
|
|
|
|
cmd->palette.bits = m_draw_mode.palette_reg;
|
|
|
|
|
cmd->window = m_draw_mode.texture_window;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::ReadSoftwareRendererVRAM(u32 x, u32 y, u32 width, u32 height)
|
|
|
|
|
{
|
|
|
|
|
m_sw_renderer->Sync(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::UpdateSoftwareRendererVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask,
|
|
|
|
|
bool check_mask)
|
|
|
|
|
{
|
|
|
|
|
const u32 num_words = width * height;
|
|
|
|
|
GPUBackendUpdateVRAMCommand* cmd = m_sw_renderer->NewUpdateVRAMCommand(num_words);
|
|
|
|
|
FillBackendCommandParameters(cmd);
|
|
|
|
|
cmd->params.set_mask_while_drawing = set_mask;
|
|
|
|
|
cmd->params.check_mask_before_draw = check_mask;
|
|
|
|
|
cmd->x = static_cast<u16>(x);
|
|
|
|
|
cmd->y = static_cast<u16>(y);
|
|
|
|
|
cmd->width = static_cast<u16>(width);
|
|
|
|
|
cmd->height = static_cast<u16>(height);
|
|
|
|
|
std::memcpy(cmd->data, data, sizeof(u16) * num_words);
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::FillSoftwareRendererVRAM(u32 x, u32 y, u32 width, u32 height, u32 color)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendFillVRAMCommand* cmd = m_sw_renderer->NewFillVRAMCommand();
|
|
|
|
|
FillBackendCommandParameters(cmd);
|
|
|
|
|
cmd->x = static_cast<u16>(x);
|
|
|
|
|
cmd->y = static_cast<u16>(y);
|
|
|
|
|
cmd->width = static_cast<u16>(width);
|
|
|
|
|
cmd->height = static_cast<u16>(height);
|
|
|
|
|
cmd->color = color;
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::CopySoftwareRendererVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendCopyVRAMCommand* cmd = m_sw_renderer->NewCopyVRAMCommand();
|
|
|
|
|
FillBackendCommandParameters(cmd);
|
|
|
|
|
cmd->src_x = static_cast<u16>(src_x);
|
|
|
|
|
cmd->src_y = static_cast<u16>(src_y);
|
|
|
|
|
cmd->dst_x = static_cast<u16>(dst_x);
|
|
|
|
|
cmd->dst_y = static_cast<u16>(dst_y);
|
|
|
|
|
cmd->width = static_cast<u16>(width);
|
|
|
|
|
cmd->height = static_cast<u16>(height);
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-05 22:12:37 +10:00
|
|
|
void GPU_HW::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color)
|
|
|
|
|
{
|
2021-02-07 20:00:16 +10:00
|
|
|
IncludeVRAMDirtyRectangle(
|
2020-02-07 00:10:58 +09:00
|
|
|
Common::Rectangle<u32>::FromExtents(x, y, width, height).Clamped(0, 0, VRAM_WIDTH, VRAM_HEIGHT));
|
2019-11-05 22:12:37 +10:00
|
|
|
}
|
|
|
|
|
|
2020-12-15 02:19:28 +10:00
|
|
|
void GPU_HW::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask, bool check_mask)
|
2019-11-05 22:12:37 +10:00
|
|
|
{
|
2021-02-07 20:00:16 +10:00
|
|
|
IncludeVRAMDirtyRectangle(Common::Rectangle<u32>::FromExtents(x, y, width, height));
|
2020-05-03 17:11:28 +10:00
|
|
|
|
2020-12-15 02:19:28 +10:00
|
|
|
if (check_mask)
|
2020-05-03 17:11:28 +10:00
|
|
|
{
|
|
|
|
|
// set new vertex counter since we want this to take into consideration previous masked pixels
|
2020-06-20 20:21:32 +10:00
|
|
|
m_current_depth++;
|
2020-05-03 17:11:28 +10:00
|
|
|
}
|
2019-11-05 22:12:37 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height)
|
|
|
|
|
{
|
2021-02-07 20:00:16 +10:00
|
|
|
IncludeVRAMDirtyRectangle(
|
2020-02-07 00:10:58 +09:00
|
|
|
Common::Rectangle<u32>::FromExtents(dst_x, dst_y, width, height).Clamped(0, 0, VRAM_WIDTH, VRAM_HEIGHT));
|
2020-05-03 17:11:28 +10:00
|
|
|
|
|
|
|
|
if (m_GPUSTAT.check_mask_before_draw)
|
|
|
|
|
{
|
|
|
|
|
// set new vertex counter since we want this to take into consideration previous masked pixels
|
2020-06-20 20:21:32 +10:00
|
|
|
m_current_depth++;
|
2020-05-03 17:11:28 +10:00
|
|
|
}
|
2019-11-05 22:12:37 +10:00
|
|
|
}
|
|
|
|
|
|
2020-04-19 01:16:58 +10:00
|
|
|
void GPU_HW::DispatchRenderCommand()
|
2019-09-14 02:07:31 +10:00
|
|
|
{
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPURenderCommand rc{m_render_command.bits};
|
2020-04-19 01:16:58 +10:00
|
|
|
|
2020-10-22 19:31:28 +10:00
|
|
|
GPUTextureMode texture_mode;
|
2020-02-07 00:10:36 +09:00
|
|
|
if (rc.IsTexturingEnabled())
|
2019-09-14 02:07:31 +10:00
|
|
|
{
|
2019-11-05 22:12:37 +10:00
|
|
|
// texture page changed - check that the new page doesn't intersect the drawing area
|
2019-12-11 16:35:14 +10:00
|
|
|
if (m_draw_mode.IsTexturePageChanged())
|
2019-11-05 22:12:37 +10:00
|
|
|
{
|
2019-12-11 16:35:14 +10:00
|
|
|
m_draw_mode.ClearTexturePageChangedFlag();
|
2020-11-22 13:22:20 +10:00
|
|
|
if (m_vram_dirty_rect.Valid() && (m_draw_mode.mode_reg.GetTexturePageRectangle().Intersects(m_vram_dirty_rect) ||
|
|
|
|
|
(m_draw_mode.mode_reg.IsUsingPalette() &&
|
|
|
|
|
m_draw_mode.GetTexturePaletteRectangle().Intersects(m_vram_dirty_rect))))
|
2019-11-05 22:12:37 +10:00
|
|
|
{
|
2023-03-09 18:32:46 +01:00
|
|
|
if (m_batch_current_vertex_ptr != m_batch_start_vertex_ptr)
|
2019-11-05 22:12:37 +10:00
|
|
|
FlushRender();
|
|
|
|
|
|
2019-11-05 22:34:27 +10:00
|
|
|
UpdateVRAMReadTexture();
|
2019-11-05 22:12:37 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 19:31:28 +10:00
|
|
|
texture_mode = m_draw_mode.mode_reg.texture_mode;
|
2019-11-01 21:47:45 +10:00
|
|
|
if (rc.raw_texture_enable)
|
2019-11-03 00:01:54 +10:00
|
|
|
{
|
|
|
|
|
texture_mode =
|
2020-10-22 19:31:28 +10:00
|
|
|
static_cast<GPUTextureMode>(static_cast<u8>(texture_mode) | static_cast<u8>(GPUTextureMode::RawTextureBit));
|
2019-11-03 00:01:54 +10:00
|
|
|
}
|
2019-09-14 02:07:31 +10:00
|
|
|
}
|
2019-10-06 00:37:53 +10:00
|
|
|
else
|
|
|
|
|
{
|
2020-10-22 19:31:28 +10:00
|
|
|
texture_mode = GPUTextureMode::Disabled;
|
2019-10-06 00:37:53 +10:00
|
|
|
}
|
2019-09-14 02:07:31 +10:00
|
|
|
|
2019-09-27 16:17:09 +10:00
|
|
|
// has any state changed which requires a new batch?
|
2020-10-22 19:31:28 +10:00
|
|
|
const GPUTransparencyMode transparency_mode =
|
|
|
|
|
rc.transparency_enable ? m_draw_mode.mode_reg.transparency_mode : GPUTransparencyMode::Disabled;
|
2019-11-02 00:31:25 +10:00
|
|
|
const bool dithering_enable = (!m_true_color && rc.IsDitheringEnabled()) ? m_GPUSTAT.dither_enable : false;
|
2021-01-20 01:08:31 +10:00
|
|
|
if (texture_mode != m_batch.texture_mode || transparency_mode != m_batch.transparency_mode ||
|
|
|
|
|
transparency_mode == GPUTransparencyMode::BackgroundMinusForeground || dithering_enable != m_batch.dithering)
|
2019-09-27 16:17:09 +10:00
|
|
|
{
|
2020-04-04 00:10:55 +10:00
|
|
|
FlushRender();
|
2019-09-27 16:17:09 +10:00
|
|
|
}
|
|
|
|
|
|
2020-05-03 17:11:28 +10:00
|
|
|
EnsureVertexBufferSpaceForCurrentCommand();
|
|
|
|
|
|
2019-11-03 13:15:17 +10:00
|
|
|
// transparency mode change
|
2020-10-22 19:31:28 +10:00
|
|
|
if (m_batch.transparency_mode != transparency_mode && transparency_mode != GPUTransparencyMode::Disabled)
|
2019-11-03 13:15:17 +10:00
|
|
|
{
|
|
|
|
|
static constexpr float transparent_alpha[4][2] = {{0.5f, 0.5f}, {1.0f, 1.0f}, {1.0f, 1.0f}, {0.25f, 1.0f}};
|
2021-06-15 23:10:38 +10:00
|
|
|
|
|
|
|
|
const float src_alpha_factor = transparent_alpha[static_cast<u32>(transparency_mode)][0];
|
|
|
|
|
const float dst_alpha_factor = transparent_alpha[static_cast<u32>(transparency_mode)][1];
|
|
|
|
|
m_batch_ubo_dirty |= (m_batch_ubo_data.u_src_alpha_factor != src_alpha_factor ||
|
|
|
|
|
m_batch_ubo_data.u_dst_alpha_factor != dst_alpha_factor);
|
2021-06-17 20:03:18 +10:00
|
|
|
m_batch_ubo_data.u_src_alpha_factor = src_alpha_factor;
|
|
|
|
|
m_batch_ubo_data.u_dst_alpha_factor = dst_alpha_factor;
|
2019-11-03 13:15:17 +10:00
|
|
|
}
|
|
|
|
|
|
2021-06-15 23:10:38 +10:00
|
|
|
const bool check_mask_before_draw = m_GPUSTAT.check_mask_before_draw;
|
|
|
|
|
const bool set_mask_while_drawing = m_GPUSTAT.set_mask_while_drawing;
|
|
|
|
|
if (m_batch.check_mask_before_draw != check_mask_before_draw ||
|
|
|
|
|
m_batch.set_mask_while_drawing != set_mask_while_drawing)
|
2019-11-24 23:30:35 +10:00
|
|
|
{
|
2021-06-15 23:10:38 +10:00
|
|
|
m_batch.check_mask_before_draw = check_mask_before_draw;
|
|
|
|
|
m_batch.set_mask_while_drawing = set_mask_while_drawing;
|
common: remove BoolToUInt8/16/32/64 helpers in favour of explicit casts
The BoolToUInt8/16/32/64 helpers in common/types.h are one-line
wrappers around `static_cast<uN>(bool)`. C++ already guarantees
that converting a bool to an unsigned integer yields exactly 0
(for false) or 1 (for true), so the helpers add nothing beyond a
shorter name - and a less obvious one, since 'BoolToUInt32(x)'
doesn't immediately read as 'cast to u32' the way the static_cast
spelling does.
Mechanical fold across 16 files:
BoolToUInt8(x) -> static_cast<u8>(x)
BoolToUInt32(x) -> static_cast<u32>(x)
(BoolToUInt16 and BoolToUInt64 had no callers in the tree.)
103 callsites rewritten: 82 BoolToUInt8 and 21 BoolToUInt32, spread
across gpu_commands.cpp, pgxp.cpp, gpu.cpp, gpu_hw_d3d11/d3d12/
vulkan/opengl.cpp, gpu_sw.cpp, gpu_hw.cpp, gpu.h, shadergen.cpp,
spu.cpp, analog_controller.cpp, negcon_rumble.cpp,
cpu_recompiler_code_generator.cpp, cpu_core.cpp. Most are array
indices (s_setup_time[BoolToUInt8(...)][...]), bit-packing in
shader-cache lookups, and arithmetic with vertex-count offsets
(words_per_vertex + BoolToUInt32(rc.texture_enable)).
After the rewrite, the four helper definitions are removed from
common/types.h.
Build verification:
Makefile.libretro platform=unix - clean syntax-check on every
touched .cpp that compiles on Linux. d3d11/d3d12 sites are all
simple BoolToUInt8(v) -> static_cast<u8>(v) substitutions on
bitfield values and verified by code review only.
No behaviour change. Codegen is identical at -O2 - both forms
compile to the same setcc/movzx sequence on x86-64.
Same shape of cleanup as the recently-landed SignExtend/Truncate
and ConvertToBoolUnchecked removals: kill a thin readability
wrapper, use the explicit static_cast spelling everywhere.
common/types.h shrinks by another 16 lines.
2026-05-14 04:05:17 +00:00
|
|
|
m_batch_ubo_dirty |= (m_batch_ubo_data.u_set_mask_while_drawing != static_cast<u32>(set_mask_while_drawing));
|
|
|
|
|
m_batch_ubo_data.u_set_mask_while_drawing = static_cast<u32>(set_mask_while_drawing);
|
2019-11-24 23:30:35 +10:00
|
|
|
}
|
|
|
|
|
|
2020-04-04 00:11:39 +10:00
|
|
|
m_batch.interlacing = IsInterlacedRenderingEnabled();
|
2020-04-04 00:11:33 +10:00
|
|
|
if (m_batch.interlacing)
|
|
|
|
|
{
|
2020-05-26 22:57:56 +10:00
|
|
|
const u32 displayed_field = GetActiveLineLSB();
|
2020-04-04 00:11:33 +10:00
|
|
|
m_batch_ubo_dirty |= (m_batch_ubo_data.u_interlaced_displayed_field != displayed_field);
|
|
|
|
|
m_batch_ubo_data.u_interlaced_displayed_field = displayed_field;
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-01 21:47:45 +10:00
|
|
|
// update state
|
|
|
|
|
m_batch.texture_mode = texture_mode;
|
|
|
|
|
m_batch.transparency_mode = transparency_mode;
|
2019-11-01 22:47:32 +10:00
|
|
|
m_batch.dithering = dithering_enable;
|
2019-11-01 21:47:45 +10:00
|
|
|
|
2019-12-11 16:35:14 +10:00
|
|
|
if (m_draw_mode.IsTextureWindowChanged())
|
2019-10-05 23:25:06 +10:00
|
|
|
{
|
2019-12-11 16:35:14 +10:00
|
|
|
m_draw_mode.ClearTextureWindowChangedFlag();
|
2019-11-03 13:15:17 +10:00
|
|
|
|
common: remove SignExtend / ZeroExtend / Truncate helpers in favour of explicit casts
The src/common/types.h helpers SignExtend16/32/64, ZeroExtend16/32/64,
Truncate8/16/32, the generic SignExtend<TR,TV> and ZeroExtend<TR,TV>
templates, and SignExtendN<N,T> were thin wrappers around explicit
static_cast chains. They served a documentation role ("this cast is
intentional, not a typo") in places where the underlying intent was
"narrow this value" or "sign-extend this value", but in practice
they obscured rather than clarified - particularly when several
nested together (SignExtend32(Truncate8(x)) is just (u32)(s8)x).
Tree-wide fold:
Truncate8(x) -> static_cast<u8>(x)
Truncate16(x) -> static_cast<u16>(x)
Truncate32(x) -> static_cast<u32>(x)
ZeroExtendN(u_x) -> static_cast<uN>(u_x)
SignExtendN(u_x) -> static_cast<uN>(static_cast<sM>(u_x)) (M = source width)
SignExtendN(s_x) -> static_cast<uN>(s_x) (relies on int promotion)
SignExtendN<BITS,T>(x) -> static_cast<sN>(static_cast<uN>(x) << S) >> S (S = N*8 - BITS)
SignExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<sM>(x))
ZeroExtendK(TruncateM(x)) -> static_cast<uK>(static_cast<uM>(x))
Mask cleanup applied where the mask matched the truncation width:
Truncate8(x & 0xFFu) -> static_cast<u8>(x)
Truncate8((x & 0xFF00u) >> 8) -> static_cast<u8>(x >> 8)
Truncate16(x & 0xFFFFu) -> static_cast<u16>(x)
Truncate16((x & 0xFFFF0000u) >> 16) -> static_cast<u16>(x >> 16)
The masks were dead-code: a static_cast to uN already keeps exactly
the low N bits.
UB fixes incidental to the fold (visible once the helpers were
unwrapped):
- SignExtendN<NBITS,T> internally did (static_cast<signed_T>(v) << S) >> S.
Signed left shift of a negative value is UB pre-C++20. After the
fold the shift is done in the unsigned domain first:
static_cast<sN>(static_cast<uN>(v) << S) >> S
All five SignExtendN callsite expansions (gpu_commands.cpp x2,
gpu_types.h, gte SignExtendMACResult, mdec.cpp x12) now do the
left shift on uN. Defined behaviour on every C++ standard from
C++98 onward. Right shift of a signed negative value remains
implementation-defined pre-C++20; this is the same as the
original helper and unchanged.
- mdec.cpp:650's SignExtendN<9,s32> took an s64 expression and
forced an implicit s64->int narrowing inside the template, which
-Wconversion flagged. The explicit static_cast<u32>(...) now
makes the narrow visible and the warning goes away. Bit-identical
result.
Sites deliberately not collapsed further, with reasons:
- spu.cpp:1347 (ADPCM pitch modulation): SignExtend32(step) where
step is u16 deliberately produces a u32 with the s16 sign bit
replicated, then multiplies by a u32 factor. Folding it as
static_cast<u32>(static_cast<s16>(step)) preserves the semantics
exactly. The naive 'static_cast<s32>(step) * factor' would not -
it'd evaluate s32 * s32 which is signed and may overflow as UB.
- gte.cpp:297-299 (IRGB conversion): Sign-extension here is observably
equivalent to zero-extension because (value & 0x1F) * 0x80 is
always <= 0xF80, bit 15 always clear. Folded as the literal
static_cast<u32>(static_cast<s16>(static_cast<u16>(...))) rather
than dropping the sign-extend step entirely - that would be a
semantic claim about hardware behaviour beyond the scope of a
helper-removal change.
- GTE TruncateRGB, TruncateAndSetMAC, TruncateAndSetIR,
TruncateAndSetMACAndIR (gte.cpp) and TruncateVertexPosition,
TruncateGPUVertexPosition (pgxp.cpp, gpu_types.h): these are
different functions, not the removed helpers. Left untouched.
bitutils.h's CountLeadingZeros / CountTrailingZeros are template
functions over T. The helper-removal leaves them inline-folding via
std::make_unsigned<T>::type, which is what ZeroExtend was doing
under the hood:
ZeroExtend64(value) ->
static_cast<u64>(static_cast<typename std::make_unsigned<T>::type>(value))
The remaining mechanical changes in cpu_recompiler_register_cache.h's
GetS32ConstantValue / GetS64ConstantValue and in pgxp.cpp's CPU_MULT
fold dropped redundant intermediate u-of-s-of-x casts that became
visible after the SignExtend64 expansion. Same codegen; cleaner.
Files touched: 43.
Helper definitions removed: 13 functions (~60 lines of types.h).
Build verification:
- Makefile.libretro platform=unix: clean build, zero warnings,
.so size 8031016 bytes (unchanged from HEAD).
- 25 retro_* exports unchanged.
- -Wall -Wextra on touched files: same warnings as HEAD (zero
new warnings from the fold, all pre-existing -Wunused-parameter).
- -Wconversion on touched files: one pre-existing warning
eliminated (mdec.cpp:650 SignExtendN<9,s32>(s64_expr) narrowing
is now an explicit static_cast<u32>); zero new warnings.
Codegen equivalence verified by inspection at every transformation
site:
Truncate8(x) = static_cast<u8>(x) ; both emit a movzx/byte-load
Truncate16(x) = static_cast<u16>(x) ; both emit a movzx/halfword-load
ZeroExtend32(u8) = static_cast<u32>(u8) ; both emit a movzx eax,al
ZeroExtend64(u32) = static_cast<u64>(u32); both emit a mov eax,reg (implicit zero-extend on x86-64)
SignExtend32(u8) = static_cast<u32>(static_cast<s8>(x)) ; both emit movsx eax,byte
SignExtend32(u16) = static_cast<u32>(static_cast<s16>(x)) ; both emit movsx eax,word
SignExtend64(u32) = static_cast<u64>(static_cast<s32>(x)) ; both emit movsxd rax,dword
SignExtendN<11,s32> = static_cast<s32>(static_cast<u32>(x) << 21) >> 21
both emit shl ; sar, identical 2-instruction sequence
2026-05-14 03:42:07 +00:00
|
|
|
m_batch_ubo_data.u_texture_window_and[0] = static_cast<u32>(m_draw_mode.texture_window.and_x);
|
|
|
|
|
m_batch_ubo_data.u_texture_window_and[1] = static_cast<u32>(m_draw_mode.texture_window.and_y);
|
|
|
|
|
m_batch_ubo_data.u_texture_window_or[0] = static_cast<u32>(m_draw_mode.texture_window.or_x);
|
|
|
|
|
m_batch_ubo_data.u_texture_window_or[1] = static_cast<u32>(m_draw_mode.texture_window.or_y);
|
2019-11-03 13:15:17 +10:00
|
|
|
m_batch_ubo_dirty = true;
|
2019-10-05 23:25:06 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-19 13:43:49 +10:00
|
|
|
if (m_drawing_area_changed)
|
|
|
|
|
{
|
|
|
|
|
m_drawing_area_changed = false;
|
|
|
|
|
SetScissorFromDrawingArea();
|
|
|
|
|
|
|
|
|
|
if (m_pgxp_depth_buffer && m_last_depth_z < 1.0f)
|
|
|
|
|
ClearDepthBuffer();
|
|
|
|
|
|
|
|
|
|
if (m_sw_renderer)
|
|
|
|
|
{
|
|
|
|
|
GPUBackendSetDrawingAreaCommand* cmd = m_sw_renderer->NewSetDrawingAreaCommand();
|
|
|
|
|
cmd->new_area = m_drawing_area;
|
|
|
|
|
m_sw_renderer->PushCommand(cmd);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-19 01:16:58 +10:00
|
|
|
LoadVertices();
|
2019-09-14 02:07:31 +10:00
|
|
|
}
|
2019-11-05 19:44:17 +10:00
|
|
|
|
2020-04-18 15:30:46 +10:00
|
|
|
void GPU_HW::FlushRender()
|
|
|
|
|
{
|
|
|
|
|
if (!m_batch_current_vertex_ptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const u32 vertex_count = GetBatchVertexCount();
|
|
|
|
|
UnmapBatchVertexPointer(vertex_count);
|
|
|
|
|
|
|
|
|
|
if (vertex_count == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (m_batch_ubo_dirty)
|
|
|
|
|
{
|
|
|
|
|
UploadUniformBuffer(&m_batch_ubo_data, sizeof(m_batch_ubo_data));
|
|
|
|
|
m_batch_ubo_dirty = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-06 20:05:57 +10:00
|
|
|
if (NeedsTwoPassRendering())
|
2020-04-18 15:30:46 +10:00
|
|
|
{
|
|
|
|
|
DrawBatchVertices(BatchRenderMode::OnlyOpaque, m_batch_base_vertex, vertex_count);
|
2020-11-22 13:46:19 +10:00
|
|
|
DrawBatchVertices(BatchRenderMode::OnlyTransparent, m_batch_base_vertex, vertex_count);
|
2020-04-18 15:30:46 +10:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
DrawBatchVertices(m_batch.GetRenderMode(), m_batch_base_vertex, vertex_count);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 13:21:41 +10:00
|
|
|
GPU_HW::ShaderCompileProgressTracker::ShaderCompileProgressTracker(std::string title, u32 total)
|
|
|
|
|
: m_title(std::move(title)), m_min_time(Common::Timer::ConvertSecondsToValue(1.0)),
|
|
|
|
|
m_update_interval(Common::Timer::ConvertSecondsToValue(0.1)), m_start_time(Common::Timer::GetValue()),
|
|
|
|
|
m_last_update_time(0), m_progress(0), m_total(total)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPU_HW::ShaderCompileProgressTracker::Increment()
|
|
|
|
|
{
|
|
|
|
|
m_progress++;
|
|
|
|
|
|
|
|
|
|
const u64 tv = Common::Timer::GetValue();
|
|
|
|
|
if ((tv - m_start_time) >= m_min_time && (tv - m_last_update_time) >= m_update_interval)
|
|
|
|
|
{
|
|
|
|
|
g_host_interface->DisplayLoadingScreen(m_title.c_str(), 0, static_cast<int>(m_total), static_cast<int>(m_progress));
|
|
|
|
|
m_last_update_time = tv;
|
|
|
|
|
}
|
|
|
|
|
}
|