Skip to content

Instantly share code, notes, and snippets.

View vjt's full-sized avatar
💭
looking at the stars

Marcello Barnaba vjt

💭
looking at the stars
View GitHub Profile
@vjt
vjt / 1-gow-hang.txt
Created December 4, 2026 00:43
shadPS4 SxLock lost wakeup: God of War hang, stress test before/after
God of War (CUSA07410), deer hunt after the funeral pyre: picture freezes, audio goes on.
Build: vjt/shadPS4 fork main 938230ca (upstream e771049b + fork fixes; sx_lock.cpp identical to upstream main).
Process left alive, read with gdb and /proc/<pid>/mem.
Threads
Game:Main R 100% user, guest loop waiting on a job group: +0x10 = 0 queued, +0x20 = 1 in flight
TaskManager03 S FUTEX_WAIT, running that job: guest sceKernelBatchMap -> ... -> Rasterizer::MapMemory
-> std::scoped_lock{mapped_ranges_mutex} -> SxLock::xlock_hard -> atomic wait
TaskManager0-2 S idle on their semaphore
GpuComm S idle (nothing submitted)
@vjt
vjt / README.md
Created December 3, 2026 02:32
shadPS4: page watchers left on unmapped memory, runs and detector lines

Page watchers left on unmapped memory: Days Gone (CUSA09175), God of War (CUSA07410)

Two paths track memory after the guest has unmapped it; the watcher stays when the range is mapped again, so the new mapping is not write-protected.

  1. Rasterizer::UnmapMemory untracks the range in the buffer cache, then the GPU thread's ObtainBuffer tracks it again before it leaves mapped_ranges. Caught in race-wo1.txt: unmap of 0x2a3160000+0x240000 by RenderThread_1, invalidate at seq 3228041, GpuComm ObtainBuffer Upload at 3228061, mapped_ranges erase at 3228210, re-map 3 ms later with w=1.
  2. BufferCache::SynchronizeDmaBuffers syncs every resident range, unmapped ones included: the unmap left their pages CPU-modified, so a DMA draw uploads them (zeros) and tracks them again (gow-dma.txt).
@vjt
vjt / README.md
Created December 3, 2026 01:15
shadPS4: Days Gone mip levels hidden by min_lod, runs and detector lines

Days Gone (CUSA09175): mip levels hidden by min_lod

The game samples many textures with min_lod 1 to 4 and does not commit the levels it hides; their memory holds other allocations of the same block pool, or nothing. The texture cache tracks the whole mip chain, so the page watchers count pages the image does not own. With the change the image starts at level floor(min_lod).

Intro cutscene, 200 s per run, Radeon 780M, RADV. Detector = extra stderr lines (STALETRACK: a texture cache Track of a range not fully GPU-mapped).

| Run | Build | not fully GPU mapped | STALETRACK | FPS |

@vjt
vjt / README.md
Created December 1, 2026 08:49
shadPS4: a sample offset that is not a bitcast (God of War, Skills tab)

shadPS4: a sample offset that is not a bitcast (God of War, Skills tab)

God of War (CUSA07410) asserts in PatchImageSampleArgs when the menu shows the Skills tab: the texel offset of one sample is a SelectF32 of two immediates. With the change the tab is drawn.

file build what it shows
without-fork-main-46d5a0b1.log fork main 46d5a0b1 (upstream 8317cf44 plus the fixes its README lists), log filter *:error by hand: touchpad, then L1. The assert is the last line
diag-5eca9d74.log the same, the assert replaced by a message (test/diag-offset), log off the opcode of the offset: SelectF32 args [IEqual32 imm imm], pc 0x1818
with-c7399287.log fork main with the change (test/sample-offset-main), log off touchpad, L1 x7, R1 x2: nothing printed
runs.txt the script's lines for the two scripted runs: EXIT@166 and the trap int3, then ALIVE
@vjt
vjt / README.md
Last active November 30, 2026 23:22
shadPS4: Days Gone, LDS in fragment shaders

Days Gone (CUSA09175): LDS in fragment shaders

Upstream main (8317cf44) exits 26 to 40 s after boot:

data_share.cpp:235 DS_WRITE: Assertion Failed!
Unexpected shared memory offset alignment: 256

41 fragment shaders of the intro use LDS (303 accesses in one run, all 32 bit). 21 use DS_WRITE_B32 / DS_READ_B32 at offsets 0, 256 ... 1280 with the address lane_id &lt;&lt; 2: one dword per lane, what the existing lowering covers. 20 use DS_WRITE2_B32 (offsets 0, 1) + DS_WRITE_B32 (offset 8), then DS_READ2_B32 + DS_READ_B32, with the address (lane_id &gt;&gt; 2) * 12: one vec3 per quad. These assert.

@vjt
vjt / README.md
Last active November 30, 2026 14:28
shadPS4: God of War, the main depth target loses its clear on the river

God of War (CUSA07410): the world stops being drawn on the river

On the river the main depth target is not cleared: with reverse Z the depth of older frames rejects the new geometry. With readbacks_mode 1 from the boat up to the landing; with readbacks_mode 2 for a few seconds under the ice, until the texture cache makes a new image for the main target.

The game renders a 1024x1024 D32Sfloat target at the address of the main 1920x1080 depth target (0x20b0a0000), with the same HTILE (0x20bbe0000), before the main prepass, and clears HTILE with a compute fill (0x3961879c) before each of the two. TextureCache::RegisterMeta replaces the HTILE entry when the image that owns it changes, clear mask included, so the clear IsComputeMetaClear has just recorded is dropped.

main HTILE fills main depth clears
without, before the second target appears 5958 5839
without, from then on 2194 0
@vjt
vjt / README.md
Last active November 30, 2026 14:13
shadPS4: God of War stencil plane cleared through a buffer

God of War (CUSA07410): stencil cleared through a buffer never reaches the depth image

The game clears each stencil plane once per frame with a compute fill (shader 0x3961879c, value 0), binding the plane as a plain buffer. shadPS4 runs the fill into the buffer cache and never uploads it into the D32S8 image, so the stencil of earlier frames stays. The sky dome draws only where (stencil & 7) != 5 and skips every pixel that geometry covered before: the old picture stays there.

New Game, the tree at the start (R1 from 115 s), then the river after it. Ryzen 7 PRO 8845HS, Radeon 780M (RADV), Batocera 44. The m2- pictures are with readbacks_mode 2 (the game needs it to draw the whole world); the others and the log counts with readbacks_mode 1. Branches are on vjt/shadPS4.

@vjt
vjt / 1-main-lds-diag.log
Created November 29, 2026 22:18
shadPS4: Days Gone, Not enough watchers since #5781 (block pool reservation mapped to the GPU)
[Kernel.Vmm] <Info> (Game:Main) memory.cpp:626 sceKernelMemoryPoolReserve: addr_in = 0x0, size = 0x400000000, alignment = 0x0, flags = 0x0
[Render] <Info> (Game:Main) vk_rasterizer.cpp:1400 MapMemory: DIAG5780 gpu map 0x200000000-0x600000000
[Kernel.Vmm] <Info> (Game:Main) memory.cpp:646 sceKernelMemoryPoolReserve: out_addr = 0x200000000, ret = 0x0
[...]
[Render] <Info> (shadPS4:GpuComm) buffer_cache.cpp:423 EnsureResident: Making range start=171283, end=234752 resident
[Render] <Warning> (shadPS4:GpuComm) page_manager.cpp:286 UpdatePageWatchersForRegion: DIAG5780 no state: op=1 pages 0x29f000000-0x2a0000000 n=4096 region 0x29f000000 mapped first=true all=true
[Render] <Warning> (shadPS4:GpuComm) page_manager.cpp:286 UpdatePageWatchersForRegion: DIAG5780 no state: op=1 pages 0x2a0000000-0x2a1000000 n=4096 region 0x2a0000000 mapped first=true all=true
[Render] <Warning> (shadPS4:GpuComm) page_manager.cpp:286 UpdatePageWatchersForRegion: DIAG5780 no state: op=1 pages 0x2a1000000-0x2a2000000 n=4096 region 0x2a10
@vjt
vjt / 1-before.perf-dso.txt
Last active November 29, 2026 17:48
shadPS4 #5781: Assassin's Creed Valhalla frame rate, runs and perf tables
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 58K of event 'cycles:P'
# Event count (approx.): 243564993652
#
# Overhead Shared Object
# ........ ...........................
@vjt
vjt / README.md
Last active November 26, 2026 21:08
shadPS4: Assassin's Creed Valhalla, Not enough watchers

Assassin's Creed Valhalla (CUSA18522): Not enough watchers

PageManager::UpdatePageWatchersForRegion updates page states it never reserved, so the watcher count of a fresh page underflows. Calling EnsurePages on the region first, as UpdatePageWatchers does, removes the assert.

New Game, 212 s in game per run, same sources with and without the two lines (runs.tsv):

build runs Not enough watchers
without the change 3 3, while New Game loads, on Loading Thread or TaskThread02
with the change 3 0