Sync the device address table's shadows once per guest submission that binds the table, and take out the port of pull request #353.

The author of pull request #353 closed it on 2026-11-11 with the words that they give no permission to use its code. Its port (3134f524) goes: the mark of a pipeline that declares the table (VkPipeInfo.gpa, vk_pipeline.c pipe_add) and of the part that draws with it (vk_mem_gpa_use in vk_exec_draw.c bind_resources and mo_emit), the sync of the table's pools in every such part's prologue (vk_mem_gpa_sync), the submission with a callback in the replay's place as it stood (vk_sync_probe_submit), and --probe-vkmem's read through the table with its shader (test_gpa_read, runtime/shaders/gpa_read.spvasm).

In its place, after pull request #551, which was written without that code: a shadow pool goes into the table and onto a list of the table's shadows (vk_memory.c shadow_table_add); the record of a binding of the table notes the guest submission (vk_exec_draw.c ssbo_info, vk_mem_shadow_table_read); and vk_mem_shadow_sync brings the CPU's writes into every shadow on the list once for that guest submission, before the part is submitted. Once is enough, because the copy-ins read the guest submission's write-watch snapshots, which a second sync would find unchanged. Measured by #551's author on Linux (RTX 4090, Kokiri Forest): 113 and 76 frames over 25 ms in 75 s against 217 and 429 with the port, 43 against 41 fps, the picture complete in both.

What this line had built on the port stays, on the new sync: the test that passes over a pool with nothing written (shadow_pool_clean), the upload of the same pages into a table pool's VRAM mirror, the write-back of stores through the table (NX2NAVI_SHADOW_TABLE_STORES, table_wb_cb, now asked once per guest submission that binds the table) and the counts of NX2NAVI_SHADOW_CHECK. The probes that record their own commands (the lost-device probe, --probe-vkmem's table parts) call vk_sync_submit_own, written anew. vk_mem_shadow_storage stays: one line that returns the mode. Finalized pools in the table were already kept for vk_mem_shutdown here.

--probe-vkmem has a check of its own for the sync (test_table_sync): the shadow of a pool that is never bound keeps its old word through a CPU write and a guest submission that does not bind the table, and holds the new one after a guest submission that does. It passes with NX2NAVI_SHADOW=1 on Windows (RTX 5090), as do the store check with NX2NAVI_SHADOW_TABLE_STORES=1 and the probe without shadow storage; --probe-devlost ends as before. Not run: the game, with or without shadow storage, and anything on Linux.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-11 06:05:07 -05:00
parent 31e0a02901
commit 295922c224
10 changed files with 218 additions and 375 deletions

View File

@@ -1,106 +0,0 @@
; --probe-vkmem (runtime/tex_probe.c test_gpa_read): one invocation reads a 32-bit word of guest memory through the
; device address table as the game's translated shaders do, by the table's layout (runtime/vk_gpa.c): L1 at word 16,
; one entry per 16 MiB; L2 blocks of 4096 page entries from word 65552; word 2 holds the word index of the records,
; four words each, the first two the buffer's device address minus the guest address of its byte 0. The pool that
; holds the word is never a descriptor of the shader: only the table (binding 0) and a result word (binding 1) are.
; An address no page maps gives 0. Written in SPIR-V assembly (spirv-as; no GLSL compiler in the build). As GLSL:
; #extension GL_EXT_buffer_reference : require
; layout(local_size_x = 1) in;
; layout(std430, binding = 0) readonly buffer Table { uint t[]; };
; layout(std430, binding = 1) buffer Result { uint r[]; };
; layout(push_constant) uniform Push { uint64_t guest; } pc;
; layout(buffer_reference, std430, buffer_reference_align = 4) readonly buffer Word { uint v; };
; void main() {
; uint rec = t[65552u + (t[16u + uint(pc.guest >> 24)] << 12) + (uint(pc.guest >> 12) & 4095u)];
; if (rec == 0u) { r[0] = 0u; return; }
; uint at = t[2] + (rec << 2);
; r[0] = Word(pc.guest + (uint64_t(t[at]) | uint64_t(t[at + 1u]) << 32)).v;
; }
OpCapability Shader
OpCapability Int64
OpCapability PhysicalStorageBufferAddresses
OpExtension "SPV_KHR_physical_storage_buffer"
OpMemoryModel PhysicalStorageBuffer64 GLSL450
OpEntryPoint GLCompute %main "main" %table %result %push
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %_runtimearr_uint ArrayStride 4
OpDecorate %Words Block
OpMemberDecorate %Words 0 Offset 0
OpDecorate %table DescriptorSet 0
OpDecorate %table Binding 0
OpDecorate %result DescriptorSet 0
OpDecorate %result Binding 1
OpDecorate %Push Block
OpMemberDecorate %Push 0 Offset 0
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%ulong = OpTypeInt 64 0
%bool = OpTypeBool
%fn = OpTypeFunction %void
%_runtimearr_uint = OpTypeRuntimeArray %uint
%Words = OpTypeStruct %_runtimearr_uint
%ptr_words = OpTypePointer StorageBuffer %Words
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%table = OpVariable %ptr_words StorageBuffer
%result = OpVariable %ptr_words StorageBuffer
%Push = OpTypeStruct %ulong
%ptr_push = OpTypePointer PushConstant %Push
%push = OpVariable %ptr_push PushConstant
%_ptr_PushConstant_ulong = OpTypePointer PushConstant %ulong
%_ptr_PhysicalStorageBuffer_uint = OpTypePointer PhysicalStorageBuffer %uint
%uint_0 = OpConstant %uint 0
%uint_1 = OpConstant %uint 1
%uint_2 = OpConstant %uint 2
%uint_4 = OpConstant %uint 4
%uint_12 = OpConstant %uint 12
%uint_16 = OpConstant %uint 16
%uint_24 = OpConstant %uint 24
%uint_32 = OpConstant %uint 32
%uint_4095 = OpConstant %uint 4095
%uint_65552 = OpConstant %uint 65552
%main = OpFunction %void None %fn
%entry = OpLabel
%28 = OpAccessChain %_ptr_PushConstant_ulong %push %uint_0
%guest = OpLoad %ulong %28
%30 = OpShiftRightLogical %ulong %guest %uint_24
%31 = OpUConvert %uint %30
%59 = OpIAdd %uint %31 %uint_16
%32 = OpAccessChain %_ptr_StorageBuffer_uint %table %uint_0 %59
%block = OpLoad %uint %32
%34 = OpShiftRightLogical %ulong %guest %uint_12
%35 = OpUConvert %uint %34
%page = OpBitwiseAnd %uint %35 %uint_4095
%62 = OpShiftLeftLogical %uint %block %uint_12
%63 = OpIAdd %uint %uint_65552 %62
%42 = OpIAdd %uint %63 %page
%37 = OpAccessChain %_ptr_StorageBuffer_uint %table %uint_0 %42
%rec = OpLoad %uint %37
%out = OpAccessChain %_ptr_StorageBuffer_uint %result %uint_0 %uint_0
%mapped = OpINotEqual %bool %rec %uint_0
OpSelectionMerge %done None
OpBranchConditional %mapped %is_mapped %not_mapped
%is_mapped = OpLabel
%43 = OpAccessChain %_ptr_StorageBuffer_uint %table %uint_0 %uint_2
%recs = OpLoad %uint %43
%45 = OpShiftLeftLogical %uint %rec %uint_2
%at = OpIAdd %uint %recs %45
%47 = OpAccessChain %_ptr_StorageBuffer_uint %table %uint_0 %at
%48 = OpLoad %uint %47
%49 = OpIAdd %uint %at %uint_1
%50 = OpAccessChain %_ptr_StorageBuffer_uint %table %uint_0 %49
%51 = OpLoad %uint %50
%52 = OpUConvert %ulong %48
%53 = OpUConvert %ulong %51
%54 = OpShiftLeftLogical %ulong %53 %uint_32
%delta = OpBitwiseOr %ulong %52 %54
%56 = OpIAdd %ulong %guest %delta
%ptr = OpConvertUToPtr %_ptr_PhysicalStorageBuffer_uint %56
%value = OpLoad %uint %ptr Aligned 4
OpStore %out %value
OpBranch %done
%not_mapped = OpLabel
OpStore %out %uint_0
OpBranch %done
%done = OpLabel
OpReturn
OpFunctionEnd