[perf] SaveFrame readback uses HOST_COHERENT (write-combined) — should be HOST_CACHED #74
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Catcrafts/Crafter.Graphics#74
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Subsystem: Window / frame capture
Location:
implementations/Crafter.Graphics-Window.cpp:1129Impact: Low · Effort: Small · Not hot path (screenshot/debug)
Related: #60 (coherency / invalidate gating), #89 (upload-strategy helper — explicitly NOT for this path, see caveat 4)
Problem
SaveFrameallocates its readback staging bufferHOST_VISIBLE | HOST_COHERENT, copies the frame image into it (TRANSFER_DST), then the CPU reads the whole buffer to write to disk. On most discrete GPUs the firstHOST_VISIBLE|HOST_COHERENTmemory type is write-combined (uncached) — and CPU reads from write-combined memory are pathologically slow (every read is an uncached memory transaction). This is the textbook wrong memory type for a readback path: coherency here buys nothing, and the WC penalty applies to the entire frame.Proposed fix
Allocate readback buffers
HOST_VISIBLE | HOST_CACHED(prefer alsoHOST_COHERENTif a cached-coherent type exists). If the chosen type is not coherent, callvkInvalidateMappedMemoryRangesbefore the CPU read (respectingnonCoherentAtomSize). Cached reads are dramatically faster for the full-frame copy.Correctness caveats
HOST_CACHEDis not spec-guaranteed but is near-universal; fall back toHOST_VISIBLEif absent (the #59 mechanism).DEVICE_LOCAL|HOST_VISIBLE, which on this hardware is coherent-not-cached (write-combined) — the worst type for readback. This path wants the opposite (HOST_CACHED). The two are separate primitives by design.