mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 13:59:56 -04:00
With shadow storage (Linux, and Windows builds under Wine) a CPU-visible pool is a host-visible copy with no memory object of its own, and only pools that owned one went into the device address table: pointers the game's shaders read from memory reached nothing. Shadow copies are now in the table. A shader that reads through the table resolves no pool, so nothing queued the pool it reaches for the copy-in: the part is marked where its pipeline is drawn or dispatched (VkPipeInfo.gpa, vk_mem_gpa_use), and its prologue brings the shadow of every pool in the table up to date with the CPU's writes and queues the same pages for those pools' VRAM mirrors (vk_memory.c vk_mem_gpa_sync). --probe-vkmem reads a word through the table from a pool that is never bound, before and after a plain CPU write. Pull request #353 by TophC7, ported onto the base copies of the black-world fix: - taken as it is: the table registration, the mark in vk_exec_draw.c and vk_pipeline.c, the prologue call and vk_sync_probe_submit in vk_sync.c (two hunks merged by hand), the probe's test; - written again: vk_mem_gpa_sync, on top of the snapshot-based shadow_sync_pool; a lookup no longer queues a pool for being in the table, which every shadow pool now is; - narrowed: the sync runs only with shadow storage. Without it (Windows) a mirrored pool stays unsynced for the table's readers as before, so the frame there is unchanged, and the probe makes the source's mirror only with shadow storage and skips when the device has no address table; - the probe's shader was an array of SPIR-V words in tex_probe.c; it is now the source runtime/shaders/gpa_read.spvasm, built like the other runtime shaders; - the exact re-upload count in the texture probe stays checked on Windows. Files other sessions are changing: runtime/vk_memory.c (vk_pool_init's registration, mem_resolve's touch, the new section before vk_mem_use). The Windows files compile and the shader assembles and validates; no probe was run, and nothing was run on Linux here. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
107 lines
5.2 KiB
Plaintext
107 lines
5.2 KiB
Plaintext
; --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
|