Commit Graph

2464 Commits

Author SHA1 Message Date
MechaCat02
29efc0381a [GPU] log_draws: also dump vertex positions for file correlation
Extend the RE draw-logger to dump the first few vertex POSITIONS (read
from guest memory) under each draw. The f32 position bytes are identical
between the guest buffer and the on-disc .xpr (only f16 pairs are
rearranged on load), so these values can be grep'd for in a resource file
to locate a mesh whose in-file offset is otherwise unknown.

Validated: world-space stage geometry byte-matches Stage_*.xpr at exact
offsets. (Load-time-transformed meshes like the player ship don't match,
which is itself a useful finding.)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 14:28:47 +02:00
MechaCat02
c6caa9e9c5 [GPU] Add log_draws: dump per-draw vertex declaration for RE
Reverse-engineering aid for decoding game mesh formats against GPU ground
truth. When the `log_draws` cvar is set, each distinct draw's primitive
type, index buffer (guest base / count / format / endianness), and full
per-stream vertex declaration (fetch-constant base + stride, and every
element's format + offset) is written to xenia_re_draws.log.

- command_processor.{h,cc}: CommandProcessor::LogDrawForRE(), no-op unless
  the cvar is set. De-dups by the vertex-declaration fingerprint (shader +
  primitive + element formats/offsets), so animated UI that redraws the
  same format into fresh buffers every frame collapses to one record --
  keeping it near-free (an earlier address-keyed de-dup flooded the log and
  stalled the GPU thread). Capped at 4096 distinct formats.
- pm4_command_processor_implement.h: call it from ExecutePacketType3Draw
  after IssueDraw (so the vertex shader has been analyzed). Backend-agnostic
  base path -- works for the Vulkan build.

Used to confirm Project Sylpheed's XBG7 mesh layout (triangle list, pos
f32x3 / normal f16x4 / uv f16x2, variable stride).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-18 14:28:47 +02:00
goldislead
16e1eb8e28 [GPU] Clarify 64bpp clear register order
This resolves the TODO in GetColorClearShaderConstants about which 32 bit portion is in which register.

For 64bpp formats, RB_COLOR_CLEAR_LO holds the lower 32 bits of the packed clear value, and RB_COLOR_CLEAR holds the upper 32 bits.
2026-07-17 08:18:56 +02:00
SaveEditors
e20f26963f [GPU] Initialize GPU registers to hardware reset defaults
RegisterFile zeroes the whole register file at construction, but a real
console comes up with non-zero values in several of the context
registers. If a game reads one of those before writing it, it gets 0
under emulation and the real default on hardware.

I read the reset values off a retail console (read-only) and checked
them against the AMD R6xx register reference and the r600g defaults in
Mesa, which set the same registers to the same values at context init.
Where the hardware read matches the driver default it's a genuine
power-on default, not leftover runtime state.

Left the tessellation levels out on purpose: they reset to 1.0f too, but
the backends do register + 1.0f, so seeding them here would change the
effective reset factor. That needs its own change.
2026-07-14 21:07:49 +02:00
goldislead
d119505289 [GPU] Texture integer scaling fetches; 8_8_8_8_GAMMA resolve
Integer num_format fetches now get their scale CPU-side instead of trying to guess in the shader. This is authoritative; no cvar. Both translators now use texture_integer_scale_bits after signs/gamma and before exponent bias. This alone fixes black screens and a bunch of rendering bugs across at least several dozen titles.

This new information lives in the updated FormatInfo table, including fixed component widths.

Resolve also has two new fixes.

8_8_8_8_GAMMA EDRAM sources can now decode through the PWL curve while still in linear space, before MSAA resolve or format conversion, then re-encoded for gamma destinations. This is also now default enabled via gamma_decode_pwl_resolve and has improved blowout in at least 4 titles, with no obvious regressions thus far.

Full resolve can also now pack fixed destinations according to copy_dest_number.
2026-07-06 20:51:02 +02:00
Adrian
2c94e46727 [GPU] Reduce log spam from D3D12 pipeline 2026-07-03 18:24:32 +02:00
Michael Oliver
9781a75a22 [GPU] Avoid stale texture state after invalidation
Check shared memory validity before marking textures up to date and installing watches. If the backing range was invalidated, leave the texture outdated so it can be reloaded later.
2026-06-29 10:16:20 +02:00
bomabomabomaboma
d55670e40b [GPU] Rolls back ZPD cache erasure on guest BEGIN. Only affects kFast. 2026-06-19 08:02:34 +02:00
Gliniak
9478cda5d6 [Kernel] Fixed issue with titles not booting due to lack of title id 2026-06-03 22:45:54 +02:00
bomabomabomaboma
73945c06d7 [GPU] Simplify ZPD cvars 2026-06-02 20:09:50 +02:00
bomabomabomaboma
fbd620c22b [GPU] Implement ZPD occlusion queries
Implements EVENT_WRITE_ZPD handling across shared CommandProcessor, D3D12, and Vulkan backends.

This adds a shared report lifecycle. Reports can span submissions/render passes, split into multiple segments, and asynchronously retire. Reports can also survive same-slot reuse, which is critical for titles that aggressively recycle against a small pool.

RTV/FBO use their respective host occlusion queries, whereas ROV/FSI use counter buffers instead, with shader helpers that are called from the translated PS, accumulating surviving MSAA sample coverage into active slots. Regardless of approach, results are copied to small, dedicated readbacks and fed through shared retirement.

Fast mode writes speculative values and patches in resolved results later. Strict mode waits for real results with a small retire backstop so it doesn't spin forever when a report gets weird. Fake mode's fundamentals are unchanged, it just now uses XenosZPDReport memory helpers like all the modes do.

Also adds optional sample count saturation for instances when attenuation isn't a one-for-one with real hardware, an optional alternate fast behavior that preserves cached zeroes (that can improve flare-heavy titles but might regress occlusion culling), and normalization for upscaling.

QueryBatch is still unsupported other than a fake path that's enabled when a range is set via cvar.
2026-05-30 19:26:25 +02:00
Gliniak
99ea6da18a [XConfig] Implementation of XConfig 2026-05-19 07:50:16 +02:00
Adrian
a261b83def [APP] Flush log & save config on quick exit 2026-05-17 12:05:20 +02:00
oreyg
c2674b19d2 [Vulkan] Drop vertex buffer residency cache, hoist global lock like D3D12 2026-05-15 14:58:51 +02:00
oreyg
b15fcc73e6 [Vulkan] Route guest oDepth through gl_FragDepth in FBO and into FSI depth test 2026-05-15 10:25:54 +02:00
oreyg
562aa0dd91 [Vulkan] Only declare the clip-distance or cull-distance array that is written 2026-05-15 09:00:26 +02:00
oreyg
02a2591295 [Vulkan] Port ac6_ground_fix vertex-fetch nudge to SPIR-V 2026-05-15 08:31:10 +02:00
Gliniak
74f34818e7 [Lint] Added InsertBraces to linter to unify codebase to one standard 2026-05-08 18:54:50 +02:00
Gliniak
9467c77f08 [GPU] Fixed crash related to disassemble_pm4 option.
In case of auto draw there is a chance it will crash due to uninitialized struct
2026-05-02 18:17:01 +02:00
bomabomabomaboma
08c0cf5ad0 [GPU] Improved fake ZPD for QueryBatch titles 2026-05-02 18:00:21 +02:00
goldislead
8a49c0380f [GPU] EVENT_WRITE_ZPD relaxed END detection
Fixes culling flicker in 555307D5.
2026-04-04 22:18:17 +02:00
goldislead
9c00ce9366 [GPU] EVENT_WRITE_ZPD batched sample accumulation cvar 2026-04-04 19:29:52 +02:00
Gliniak
9b1ebffd27 [Memory] GetPhysicalAddress - Added case to assume that input address is already physical
- Restored break on Indirect Buffer failure (Hopefully it won't break anything)
2026-03-28 20:11:43 +01:00
Herman S.
a8ef7faeae [Build/macOS] Exclude empty translation units and Vulkan/SPIR-V targets 2026-03-27 16:12:08 +09:00
Herman S.
57c4051eca [macOS] Build infrastructure and portability fixes
Build system:
- Enable ObjC++, macOS deployment target, framework linking
- Fix AppleClang detection
- macOS platform name for output directories
- Skip Vulkan on macOS, null graphics without Vulkan dependency
- macOS SDL2 framework detection and discord-rpc macOS sources

Portability fixes:
- mach_absolute_time for macOS tick counting
- _NSGetExecutablePath for macOS
- guard MAP_FIXED_NOREPLACE, ftruncate64->ftruncate
- guard Vulkan include/usage, fix data root for all POSIX
2026-03-27 02:44:00 +09:00
Herman S.
1af96481b2 [Build/MacOS] Fix sprintf deprecation warnings
Convert to snprintf in trace_viewer and suppress in 3pp stb header.
2026-03-27 01:24:05 +09:00
Herman S.
883c2030d0 [ARM64] Initial commit for arm64 backend
Based entirely off existing xbyak x86 implementation and available
tests. Still needs a lot of optimization and testing on non-Windows
platforms.

So far passes all tests and boots at least some games on Windows.
2026-03-22 15:57:37 +09:00
Herman S.
1e8f1837cf [Build] Use CMAKE_BINARY_DIR for output paths and version.h include
version.h is now found via CMAKE_BINARY_DIR on the include path instead
of a hardcoded "build/version.h" path. This allows out-of-tree and
multi-config builds to each generate and find their own version header
without colliding.
2026-03-21 01:30:31 +09:00
Herman S.
b581c2d852 [D3D12] Adds scalar fallback for the SSE register-range check 2026-03-17 13:55:38 +09:00
Herman S.
9666ce1115 [Build] Remove stale xenia-hid-skylander references from CMakeLists
d37c22aa replaced skylander with the new portal HID library but
missed updating three CMakeLists.txt files. No replacement needed
since xenia-hid already links xenia-hid-portal transitively.
2026-03-15 17:46:57 +09:00
Herman S.
fdd583eced [GPU/WGF] Fix resolve_fast_32bpp_4xmsaa sample addressing
For 4xMSAA 32bpp, samples 2/3 add a +4 byte horizontal offset to the
EDRAM address. The old typed buffer code (Buffer<uint4>) implicitly
truncated this offset via integer division (>> 2), and the .yw swizzle
compensated by selecting odd elements within the aligned uint4 load.

After the ByteAddressBuffer conversion, Load4 uses the exact byte
address including the +4 offset, shifting the load window by one dword.
The .yw swizzle then picks samples from the wrong pixels, causing
visual artifacts like vertical streaks in Resident Evil 5.

Fix by aligning the load address down to 16 bytes and selecting the
swizzle based on whether the address was offset.
2026-03-15 17:24:16 +09:00
Gliniak
d1ad597939 [GPU] Vulkan: Fixed FSI render target path
AlphaToMask was causing crashes on linux due to missing SelectionMerge
2026-03-09 21:52:00 +01:00
Herman S.
64e51c544e [GPU] Add vulkan shader disk storage / startup loading
Big refactor of the shader storage to allow both backends to share code
2026-03-10 00:49:56 +09:00
Herman S.
5845f3437b [GPU] Async shader compilation for D3D12 and Vulkan
Adds async_shader_compilation cvar (default true) that forces new
pipelines to be created async from the main thread, skips draws entirely
on D3D12 and on vulkan replaces pixel shader with placeholder until the
real one is ready. Causes some visual artifacts on first load but
greatly reduces load times and stutter.
2026-03-10 00:24:26 +09:00
Herman S.
ccf8fb66f5 [Vulkan] Add thread pool for async shader compilation
Uses priority queue with higher priority on shaders with visible
render targets
2026-03-10 00:21:10 +09:00
Herman S.
19c5401eda [GPU] Revert SPIR-V version back to 1.0 for internal shaders 2026-03-09 21:34:22 +09:00
Herman S.
37fabb9346 [GPU] Ensure vsync works correctly on Linux.
Linux scheduler quantum is 4-10ms so requesting 15ms sleep ends
up sleeping 16-19ms and overshoots our target causing games to run
at 57fps
2026-03-09 12:41:53 +09:00
Herman S.
2912da02fe [D3D12] Fix gamma_unorm16 render target transfer shaders
Gamma stored as R16G16B16A16_UNORM is 64bpp in host memory but
represents a single 32bpp pixel, unlike true 64bpp formats which pack
two 32bpp pixels together. Separate dest_is_gamma_unorm16 from
dest_is_64bpp to avoid incorrect coordinate transforms.

Add output paths for gamma_unorm16 destinations:
- gamma→gamma: direct passthrough (already linear in R16G16B16A16)
- k_8_8_8_8→gamma: convert gamma-encoded source to linear
- Cross-format packed EDRAM: midpoint encoding to survive UNORM16
  quantization round-trip through PreSaturatedLinearToPWLGamma

Fixes red bleeding in Halo Reach, image halving in Just Cause 2,
Portal not rendering, and black rock/plant textures in Halo Reach.
2026-03-06 23:05:39 +09:00
Herman S.
65d42843b6 Merge remote-tracking branch 'xenia-master/master' into canary_experimental 2026-03-06 23:05:24 +09:00
Herman S.
16d2cc05c5 [GPU] Use UNorm not signed EDRAM encoding in k_16_16 resolve packing.
The original commit (2eea146b) correctly added kXenosFormat_16_16_EDRAM
case labels and fixed the unpack clamp from -1.0 to -32.0, but
incorrectly changed the resolve pack functions from UNorm to signed EDRAM
encoding. The resolve destination is a regular texture sampled as UNorm
[0,1], not EDRAM. Using EDRAM packing double-encodes the [-32,32]
scaling, crushing all values by ~64x and caused visual issues
particularly in UE3 titles.

The bytecode submitted with the change was actually correct, but the
source had additional incorrect pieces that only manifested when shaders
were rebuilt.
2026-03-05 15:11:22 +09:00
Herman S.
4bd93883ac [Build] Convert buildshaders to custom build rules 2026-03-04 20:57:42 +09:00
Herman S.
71c5702ee8 [Build] Convert build system to raw cmake and remove premake layer 2026-03-04 17:37:36 +09:00
Herman S.
dbfe216754 [Vulkan] Implement extended range for f32 to f16 conversion in memexport 2026-03-03 17:16:37 +09:00
Ylederman153
02c6bc6e61 [D3D12] Implement extended range for f32 to f16 conversion in memexport (#899)
Resolves TODO(Triang3l) by implementing a mathematical workaround to allow exponent 31 for extended float16 range up to +/-131008.0f as expected by the native Xbox 360 hardware, bypassing standard D3D12 f32tof16 boundaries which incorrectly clamp/inf values.
2026-03-03 17:16:05 +09:00
Herman S.
f2ac39cfd9 [Build] Generate shaders on build instead of having them checked in 2026-03-03 16:21:30 +09:00
Ylederman153
2eea146b1b [GPU] Fix k_16_16 and k_16_16_16_16 EDRAM packing clamping (#898)
Replaces the UNorm packing functions with custom Edram functions to preserve the native [-32.0, 32.0] float range and scale mathematically instead of using saturate(). Fixes displaced water meshes in games like Mercenaries 2.
2026-03-03 14:27:04 +09:00
Herman S.
48111e8fba [D3D12] Fix device lost with resolution scaling in 3D-as-2D textures 2026-03-01 16:41:50 +09:00
Herman S.
125b4c8c05 [GPU] Ensure force_special_view checks swizzle signs before using signed
This was causing unnecessary logspam in Blue Dragon due to
incorrectly trying to request signed when the fetch constants are
unsigned
2026-02-26 14:36:08 +09:00
Herman S.
0c8d1b763f [D3D12] Pre-create 3D-as-2D textures before draw setup 2026-02-26 14:22:46 +09:00
Herman S.
0e2967cdb0 [D3D12] Fix 3D-to-2D texture crash under Wine/VKD3D 2026-02-26 14:22:46 +09:00