5488 Commits

Author SHA1 Message Date
Jordan Woyak
5140482a6f Merge pull request #15026 from dokslade/ogl-screenshot-offset
VideoCommon: Fix OpenGL screenshots of partial XFB copies
2026-11-16 18:03:02 -06:00
Martino Fontana
14d5fe714d BitSet: Some small additions
Also add requirements for using range functions.
And micro-optimize testing if a bit is set (GCC and MSVC struggle to emit `bt` or `tbz`/`tbnz` with `bs & (1 << n)` compared to `(bs >> n) & 1`).
2026-11-15 22:31:04 +01:00
dok.slade
c6c57d5709 VideoCommon: Fix OpenGL screenshots of partial XFB copies
ScaleTexture flipped its rectangles for backends with a lower-left
origin, but textures are stored top row first and the copy shader
keeps the row order, so the flip is only a no-op for full rectangles.
With a sub-rectangle, OpenGL frame dumps and screenshots read the
bottom of the texture instead of the top, and came out shifted up with
a black band at the bottom.

Pass the rectangles through unchanged. Other backends and callers using
full rectangles are not affected.

Fixes https://bugs.dolphin-emu.org/issues/12286
2026-11-15 14:24:38 +00:00
JosJuice
80a1a25fbc Merge pull request #14966 from SuperSamus/optimize-efb-xfb-uninitialization
TextureCacheBase: Optimize EFB and XFB uninitialization
2026-11-15 12:27:38 +01:00
Jordan Woyak
63557b8a67 PerformanceTracker: Fix broken FPS calculation on Windows after a multi-second delay. 2026-11-13 03:35:41 -06:00
Jordan Woyak
cf21d5dc0b Merge pull request #14877 from SuperSamus/performance-tracker-variance-fixup
PerformanceTracker: Small cleanup, properly use RunningVariance for the standard deviation
2026-11-12 18:07:27 -06:00
iwubcode
b0c7778406 VideoCommon: error if the same asset id is used with a different type 2026-11-05 16:10:41 -06:00
Jordan Woyak
d182533d36 Merge pull request #14916 from iwubcode/vertex_manager_draw_refactor
VideoBackends / VideoCommon: split draw calls into separate commit and render functions
2026-11-01 21:35:00 -06:00
Martino Fontana
c6e63fb3ab PerformanceTracker: Small cleanup, properly use RunningVariance for the standard deviation
UpdateStats() was calculating the standard deviation from the entirety of m_dt_queue, which has a noticeable performance impact when the frame rates are very high.
On a scene so light it runs at 3000 FPS, UpdateStats() was taking around 5% of the profiling (at default 1s sample window). Now it doesn't.
2026-10-31 22:52:44 +01:00
Martino Fontana
d74e757bad TextureCacheBase: Optimize EFB and XFB uninitialization
For EFB, optimize the case where bytes_per_row == stride.

For XFB, do that, and make sure that autovectorization is used without intrinsics. They were only used on x86, so that should improve performance on ARM.
(MSVC ARM specifically will load to register on every iteration, and I give up on this stupid compiler, but it should still be better than before.)
For reference, on x86 with SIMD, on a scene that runs at 3000 FPS, this function takes 1.5% of time according to the profiler.

I spent way too much time making all the compilers cooperate, and I hate it.
2026-10-31 22:44:13 +01:00
iwubcode
4fb368cf36 VideoBackends / VideoCommon: split draw calls into separate commit and render steps 2026-10-31 13:42:20 -05:00
JosJuice
47075151c3 Merge pull request #14943 from Sintendo/vertex-arm64
VertexLoaderARM64: Optimize RGB565 and RGBA6666
2026-10-31 16:13:17 +01:00
JosJuice
97b33a2527 Merge pull request #14928 from JosJuice/neon-texture-decoder
VideoCommon: Add TextureDecoder_ARM64.cpp
2026-10-31 16:12:31 +01:00
iwubcode
1f30867901 Merge pull request #14782 from tygyh/Core/Use-lerp-and-midpoint
Replace manual calculations with std::lerp and std::midpoint
2026-10-31 02:04:42 -05:00
iwubcode
2c6a598fae Merge pull request #14866 from SuperSamus/efb-to-texture-clear-byte
VideoCommon: Option for byte to memset in RAM when `EFBToTextureEnable = True`
2026-10-30 15:14:15 -05:00
Sintendo
f22dd8677f VertexLoaderARM64: Optimize RGBA6666
This commit replaces the old instruction sequence with one that is
considerably shorter. Main ideas are as follows:

 - Use AND with constant mask to isolate the needed bits.
 - Use ORR + LSL/LSR to shirt the bits into position and combine in one
   instruction where possible.
 - Red and alpha are already sequential, so don't need to wait for the
   byteswap.
 - Do the expansion from 6 to 8 bits at the end for all 4 components
   in one step.

Before:

ldur   w14, [x0]
rev    w14, w14
ubfx   w15, w14, #0, #6
orr    w15, wzr, w15, lsl #2
orr    w15, w15, w15, lsr #6
orr    w16, wzr, w15, lsl #24
ubfx   w15, w14, #6, #6
orr    w15, wzr, w15, lsl #2
orr    w15, w15, w15, lsr #6
orr    w16, w16, w15, lsl #16
ubfx   w15, w14, #12, #6
orr    w15, wzr, w15, lsl #2
orr    w15, w15, w15, lsr #6
orr    w16, w16, w15, lsl #8
ubfx   w15, w14, #18, #6
orr    w16, w16, w15, lsl #2
orr    w16, w16, w15, lsr #4
str    w16, [x1, #0xc]

After:

ldur   w14, [x0]
rev    w15, w14
and    w16, w14, #0xfc00
and    w14, w14, #0x3f000000
lsr    w16, w16, #8
orr    w16, w16, w14, lsl #2
and    w14, w15, #0xfc0
and    w15, w15, #0x3f000
orr    w15, w15, w14, lsl #14
orr    w16, w16, w15, lsr #2
and    w15, w16, #0xc0c0c0c0
orr    w16, w16, w15, lsr #6
str    w16, [x1, #0xc]
2026-10-24 19:01:59 +02:00
Sintendo
9c60ba938c VertexLoaderARM64: Optimize RGB565
This replaces the old instruction sequence with one that is considerably
shorter. Main ideas are as follows:

 - Use AND with constant mask to isolate the needed bits.
 - Use ORR + LSL/LSR to shift the bits into position and combine in one
   instruction where possible.
 - Red and blue are already sequential, so don't need to wait for the
   byteswap. This is especially handy for red, where the bits are
   already where they need to be.
 - Red and blue can be expanded from 5 to 8 bits together.

Before:

ldurh  w14, [x0, #0x1]
rev16  w14, w14
and    w15, w14, #0x1f
orr    w15, wzr, w15, lsl #3
orr    w15, w15, w15, lsr #5
orr    w16, wzr, w15, lsl #16
ubfx   w15, w14, #5, #6
orr    w15, wzr, w15, lsl #2
orr    w15, w15, w15, lsr #6
orr    w16, w16, w15, lsl #8
ubfx   w15, w14, #11, #5
orr    w16, w16, w15, lsl #3
orr    w16, w16, w15, lsr #2
orr    w16, w16, #0xff000000
str    w16, [x1, #0xc]

After:

ldurh  w14, [x0, #0x1]
rev16  w15, w14
bfi    w14, w14, #11, #13
and    w16, w14, #0xf800f8
and    w14, w14, #0xe000e0
orr    w16, w16, #0xff000000
orr    w16, w16, w14, lsr #5
and    w14, w15, #0x7e0
and    w15, w15, #0x600
orr    w14, w14, w15, lsr #6
orr    w16, w16, w14, lsl #5
str    w16, [x1, #0xc]
2026-10-24 19:00:43 +02:00
Jordan Woyak
1822e3859f Merge pull request #14934 from iwubcode/efb_interface_remove_global
VideoCommon: remove global framebuffer manager from EFBInterface
2026-10-18 13:26:42 -05:00
JosJuice
38d619b076 Merge pull request #14804 from JosJuice/jit-set-lazy-memory-region
Jit: Use LazyMemoryRegion-backed bit sets
2026-10-17 19:14:10 +02:00
iwubcode
f71b0a48b3 VideoCommon: remove global framebuffer manager from EFBInterface and instead pass it in 2026-10-16 01:04:33 -05:00
WalterCool
e951de438f Fix build failure on libc++/clang 23
libc++ 23 enforces the dependency from certain stdlib.

In this case, we need <vector> here or build will fail.

Signed-off-by: WalterCool <waltercool@slash.cl>
2026-10-12 00:25:54 -04:00
JosJuice
178ec51fa6 VideoCommon: Use GPR units more in TexDecoder_DecodeImpl_CMPR
This improves the time reported by the CMPR unit test. The lowest value
is about 14% lower, but there's more variance, with the highest value
being similar to before. The instruction count has increased.

I'm putting this in a separate commit so the older implementation is
available in the commit history for anyone wanting to look at it.
2026-10-11 10:49:58 +02:00
JosJuice
6103e4f5c6 VideoCommon: Add TextureDecoder_ARM64.cpp
We already have x64 SIMD implementations for decoding most texture
formats. This commit adds AArch64 SIMD implementations for all texture
formats except the XFB format. (AArch64 was previously using the
non-SIMD implementations from TextureDecoder_Generic.cpp.)

I left a few TODO comments about things that could be improved using
optional ISA extensions. I don't have any immediate plans to work on
these.

Performance numbers from the unit test are available below. Note that
the unit test fits relatively well in cache, so real workloads might
spend more time waiting on memory, which could lead to smaller
differences between the old and new implementation.

Before:

I4 took 2676 ns on average (36 iterations)
I8 took 3961 ns on average (36 iterations)
IA4 took 7304 ns on average (36 iterations)
IA8 took 4555 ns on average (36 iterations)
RGB565 took 12146 ns on average (36 iterations)
RGB5A3 took 33155 ns on average (36 iterations)
RGBA8 took 3702 ns on average (36 iterations)
C4 (IA8) took 9149 ns on average (36 iterations)
C4 (RGB565) took 19398 ns on average (36 iterations)
C4 (RGB5A3) took 28533 ns on average (36 iterations)
C8 (IA8) took 6766 ns on average (36 iterations)
C8 (RGB565) took 15577 ns on average (36 iterations)
C8 (RGB5A3) took 18906 ns on average (36 iterations)
C14X2 (IA8) took 10603 ns on average (36 iterations)
C14X2 (RGB565) took 20700 ns on average (36 iterations)
C14X2 (RGB5A3) took 38878 ns on average (36 iterations)
CMPR took 6205 ns on average (36 iterations)

After:

I4 took 2086 ns on average (36 iterations)
I8 took 1699 ns on average (36 iterations)
IA4 took 1522 ns on average (36 iterations)
IA8 took 1673 ns on average (36 iterations)
RGB565 took 2443 ns on average (36 iterations)
RGB5A3 took 3922 ns on average (36 iterations)
RGBA8 took 1983 ns on average (36 iterations)
C4 (IA8) took 1646 ns on average (36 iterations)
C4 (RGB565) took 2057 ns on average (36 iterations)
C4 (RGB5A3) took 1670 ns on average (36 iterations)
C8 (IA8) took 3765 ns on average (36 iterations)
C8 (RGB565) took 4275 ns on average (36 iterations)
C8 (RGB5A3) took 5146 ns on average (36 iterations)
C14X2 (IA8) took 5121 ns on average (36 iterations)
C14X2 (RGB565) took 5572 ns on average (36 iterations)
C14X2 (RGB5A3) took 7142 ns on average (36 iterations)
CMPR took 3250 ns on average (36 iterations)
2026-10-11 10:45:11 +02:00
JosJuice
fbab471d1a VideoCommon: Rename TexDecoder_DecodeTexel width parameter
All existing callers pass the width minus one, and passing the width
without subtracting one gives incorrect results. Let's call the
parameter image_width_minus_1, like TextureSampler.cpp already calls it.
2026-10-10 09:57:01 +02:00
JosJuice
9b4d5a5449 Merge pull request #14912 from acts-1631/savestate-fifo-pointer-validation
VideoCommon: validate restored FIFO pointers
2026-10-07 19:48:11 +02:00
JosJuice
370585aa68 Merge pull request #14835 from JoshuaVandaele/vulkan-over-gl
VideoCommon: Prefer Vulkan over OpenGL on Linux
2026-10-07 19:36:04 +02:00
iwubcode
1ab733dd5c Merge pull request #14836 from iwubcode/dolphin_texture_refactor_1
VideoCommon: refactor texture cache frame buffer copies
2026-10-06 15:00:03 -05:00
iwubcode
ad087f3689 Merge pull request #14840 from iwubcode/dolphin_texture_refactor_3
VideoCommon: split partial texture update logic from the actual rendering
2026-10-06 14:56:08 -05:00
iwubcode
68c3fb5351 Merge pull request #14908 from iwubcode/vertex_manager_remove_custom_shaders
VideoCommon: remove remnants of old custom shader feature
2026-10-06 14:55:41 -05:00
iwubcode
0961ec1d87 Merge pull request #14907 from iwubcode/texture_return_shared
VideoCommon: return a RcTcacheEntry (shared_ptr) from TextureCacheBase::Load()
2026-10-04 19:02:07 -05:00
Acts1631
f5438ce0c3 VideoCommon: validate restored FIFO pointers
Save states restored video FIFO pointers from unchecked offsets. A
crafted offset could place a pointer outside its backing allocation and
turn the next gather-pipe copy into an out-of-bounds native write.

Require pointer offsets to stay within their backing array and reject a
state when either offset is invalid or the read pointer follows the write
pointer.
2026-10-04 16:53:57 -04:00
iwubcode
e051e57251 VideoCommon: refactor texture cache frame buffer copies, in preparation for a future enhancement 2026-10-04 01:54:15 -05:00
iwubcode
a0a4e02ebb VideoCommon: remove remnants of old custom shader feature, it will be replaced by Materials in the future 2026-10-04 00:55:03 -05:00
iwubcode
eb236466c4 Merge pull request #14899 from Starlightbotanist/adreno-tev-zero-rewrite
VideoCommon: Work around Adreno TEV zero input miscompilation
2026-10-04 00:19:22 -05:00
Starlightbotanist
4ba37f1dde VideoCommon: Work around Adreno TEV zero input miscompilation
Some Qualcomm Android drivers from version 700 onward miscompile
specialized TEV pixel shaders when color input A or B is TevColorArg::Zero.
Use konstLookup[8].rgb, which PixelShaderManager initializes to zero,
to keep these inputs dependent on a uniform value.

Use the existing driver bug gate for OpenGL and Vulkan. Other inputs and
unaffected drivers retain their original shader expressions.
2026-10-04 00:25:01 -04:00
iwubcode
e6fc6aa1b2 VideoCommon: split partial texture update logic from the actual rendering 2026-10-03 22:53:33 -05:00
iwubcode
93c28ee307 VideoCommon: return a RcTcacheEntry (shared_ptr) from TextureCacheBase::Load()
This allows the texture entry to be stored off or passed around and shared in the future
2026-10-03 22:31:14 -05:00
JosJuice
af1ab20b35 Merge pull request #14812 from JoshuaVandaele/correct-env-locale
Fix crashes when using `std::locale{""}` with an invalid LC_ALL
2026-10-03 09:53:13 +02:00
Martino Fontana
8c1f30bb30 VideoCommon: Option for byte to memset in RAM when EFBToTextureEnable = True
The main use case is for games that in theory should be compatible with `EFBToTextureEnable = True`, as the CPU never reads the EFB texture and only writes to it completely.
However, if what the CPU writes is only zeros, if the texture in RAM was already zeros then Dolphin wouldn't notice the change in RAM and thus wouldn't invalidate the texture in VRAM.
This happens in Rhythm Heaven Fever, and with this change it doesn't require `EFBToTextureEnable = False` anymore.

But there are other use cases, like setting a clear value that is closer to what the EFB copy would be, like in Excite Truck.
(`EFBToTextureEnable` is still `False` by default.)

Other games are more subjective (and not changed here): for instance Mario Kart Wii samples the EFB copy to decide whether to display a sun flare.
Currently with `EFBToTextureEnable = True` (default) it will never be shown, but maybe someone would prefer for the flare to always be shown, even behind walls.

The option currently only supports setting a single byte (that will be memset to the entire texture), as setting a color would be more complex given that a texture can be in multiple formats, and there is no use case (yet) for it.
2026-10-03 09:12:52 +02:00
Martino Fontana
910eeffc08 VideoCommon/Statistics: Use unsigned int where appropriate
Some poorly coded games are able to overflow some statistics (e.g. Jimmy Neutron: Boy Genius's title screen).
While funny, signed integer overflow is undefined behavior, and while in practice here it's extremely unlikely to cause issues, it's still better to avoid it.
2026-09-24 12:05:18 +02:00
Link Mauve
3e95d0fc16 Revert "VideoCommon: Use correct size for PE token"
This reverts commit e4349ae179.

The 0x prefix is included in the characters count (unlike e.g. in Rust
where there is no 0x prefix), so that commit was wrong.  Sorry about
that!

Fixes regression introduced in #14842.
2026-09-06 09:06:48 +02:00
Scott Mansell
debe8e9fd9 Merge pull request #14789 from phire/optimise_vs_uid
Optimize vertex_shader_uid_data down to 28 bytes
2026-09-06 14:37:57 +12:00
Link Mauve
e4349ae179 VideoCommon: Use correct size for PE token
This token is a u16, not a u24, so let’s not display unnecessary 00
padding.
2026-09-03 11:49:13 +02:00
iwubcode
9263f6b7c6 VideoCommon: separate out reinterpret and palette texture creation from rendering 2026-08-31 19:51:30 -05:00
Joshua Vandaële
f708ac2b04 VideoCommon: Prefer Vulkan over OpenGL on Linux 2026-08-31 11:57:23 +02:00
JosJuice
f93a8a995b Common: Add DivideRoundingUp function
Many callers of AlignUp are dividing immediately after aligning. Let's
add a helper function for this so callers don't have to specify the
alignment size twice.
2026-08-22 11:52:22 +02:00
Dr. Dystopia
eb956a158c Replace manual calculations with std::lerp and std::midpoint 2026-08-16 10:28:21 +02:00
Joshua Vandaële
622c711ccf Fix crashes when using std::locale{""} with an invalid LC_ALL 2026-08-12 22:25:11 +02:00
Scott Mansell
e5eabd08f5 Optimize vertex_shader_uid_data down to 28 bytes
This started as a fixing a misalignment issue, but I got carried away.
Was originally 41 bytes (overflowing it's expected 40 bytes by 1 bit).

Now it's 27 bytes plus 8 bits of padding (ready for future expansion).

The savings come from:
 - Removing UV usage from components, it can be reconstructed from
   texcoord_elem_count (saved 8 bits)
 - Removed the 8 unused bits from texMtxInfo_n_projection (saved 8 bits)
 - Removing unused bit from from start of components (saved 1 bit)
 - Removed extra bit from inputform, texgentype and sourcerow
 - packed texMtxInfo_n_projection and texcoord_elem_count back into
   the per texgen info space freed up above. (saved 24 bits)
 - Overlayed postMtx index and Emboss mode shifts into a union based on
   texgentype (saved 56 bits)
 - Move to a single-bit union tag, freeing up an extra bit for regular
   texgens.
 - Move PotMtx normalize into the freed up space (saved 8 bits)

Total savings: 105 bits of data

EDIT: Even worse, MSVC wasn't respecting pack(1) for bitfields at all,
      so on windows this struct was actually quite a bit larger.
      Something like 80 bytes, if not more.

      Fixed this by dropping the size of any enums used in these
      bit structs to u8. Our Common::BitField allows for the underlying
      type to be explicitly specified to something larger.

      msvc's bitfield packing appears to be completely braindead, can't
      mix sizes at all.
2026-08-07 18:42:52 +12:00
JosJuice
f5be1c30e5 VideoCommon: Fix custom texture count in OSD message
83dc468 broke the OSD message that shows the number of custom textures.
If Prefetch Custom Textures was disabled, the number would always be 0.
2026-08-02 10:11:15 +02:00