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`).
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
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.
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.
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]
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]
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>
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.
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)
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.
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.
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.
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.
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.
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.
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.
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.