Repository navigation
Conversation
8bdc650 to
d1b09f0
Compare
|
Folks, I'm updating this PR:
Decodes BC6H HDR textures into RGB9E5Float (4 B/px) instead of RGBA16Float (8 B/px), halving their RAM footprint. This UI toggle (DM_BC6H_RGB9E5) is hidden if the device has native BC support.
Removed the per-game profile option (tex_bc_cpu); CPU BC decoding is now automatically active whenever the GPU lacks hardware BC support.
At launch time, the host checks hardware capabilities and user settings, then binds specialized function pointers (g_pkg_upload, g_tex_desc, etc.) to one of 3 paths: Path 1: Direct BC hardware uploads (if supported by GPU). This guarantees zero per-texture branch overhead at runtime—all checks are resolved once at launch. |
d1b09f0 to
2fb9cb3
Compare
|
Thanks for the update and for the long explanation. Two things before I can review it:
|
2fb9cb3 to
e4b0efb
Compare
|
Thanks @v0lumehi! Here is the update addressing both review points: 1. Why this is fork-only and not on nxnativeIn upstream pull request seedds/nxnative#488 ("Decode BC textures on the CPU when the Metal device cannot sample them"), upstream maintainer As documented in matching the status of existing patch 2. Split PR: Pure Bug FixAs requested, the PR has been split:
|
|
Thanks @romulof. I accept the reason: upstream declined CPU BC decoding in seedds/nxnative#488, so this stays here as Two things on my side:
This PR stays in v1.1.2. |
e4b0efb to
fe4b832
Compare
fe4b832 to
e4b0efb
Compare
v0lumehi
left a comment
There was a problem hiding this comment.
Thanks @romulof for the CPU BC decode work. Decoding BC views, uploads and copies on the CPU is a good way to get older iPhones past the crash, and the Upstream-Status: fork-only (declined seedds/nxnative#488) header is correct.
- Rebase on the current main.
patches/seriesconflicts and the numbers 0056 and 0057 are taken. I renumber at merge. - Patch 0057 moves the memory watchdog call from every 300 to every 60 frames for all games. That is unrelated to BC and not in the description. Please remove it or explain it.
front_ios_device_checkno longer stops pre-A17 devices at Play, for every game. That changes what players see on iPhone 14 and older. It needs an issue and a decision first. Please keep the check or open that issue.copy_t2breturns early andmtl_read_texelsreturns zeros for BC textures. Please log a RED line instead of silently giving zeros.- With
g_bc_cpu = !g_bc_gputhe!supportsBC && !g_bc_cpucheck inmtl_initcan never be true. Please remove it, and check that nothing else still uses the oldtex_bc_cpugate. - Please add a result from a device after the fix, for example TotK past frame 153, with the log.
- The claim that function pointers remove per-texture branches does not match the many
g_bc_cpu && nvn_bc_unpacked(...)branches that remain. Please correct the text.
Next: after the rebase and these points I review again. It fits v1.1.2 only if done soon, otherwise v1.1.3.
|
The CPU-decoded BC upload/view portion is now covered by merged #888 (main commit 908e4e8), and the fully overlapping #776 is being closed as superseded. This PR remains open because it also contains distinct work. Please drop the now-landed upload/view changes when refreshing the series and keep the remaining readback/copy behavior, device-gate decision and global watchdog change separate and justified, with the previously requested device validation. The new fix’s historical A15 evidence and synthetic current-pin GPU coverage do not establish those broader behaviors. |
|
I was able to make TOTK run on an iPhone 14 Pro with:
|
e4b0efb to
115fef5
Compare
|
Thanks @thehobbit85 and @v0lumehi for the guidance and reviews. I have rebased the PR onto the current
|
thehobbit85
left a comment
There was a problem hiding this comment.
Reviewed revised head 115fef5c96b69e2fabc3f1314f225fd37dc9cb6e. The narrowed scope addresses the earlier watchdog, device-gate and already-landed upload/view points. The existing GPU test passes all 358 checks under Metal validation, but a new ordering regression blocks merging.
The CPU decode reads sb.contents immediately, even when an earlier GPU buffer copy in the same submission is still writing that source. With unchanged production code on an M2 Max, a BC1 source initially contains red, then mtl_sub_copy queues blue over that source before copy_b2t. After completion the source is blue (1f 00), but the copied texture is red (255,0,0,255). The additional test reports 360 checks, 1 failure, both normally and with DM_NVN_ENC_THREAD=1. Waiting for the source-copy submission before decode produces blue and passes 362 checks.
Please resolve the source range’s pending GPU writes before decoding on the CPU, preserve the compressed guest-memory representation, and add this GPU-copy-to-BC-copy regression. The existing pending-write checks around the guest mirror do not protect this new unconditional CPU read. The relevant production functions are unchanged at the newer engine pin, so refreshing the patch list alone will not fix it.
The reported iPhone 14 Pro result is useful context, but it includes two additional changes. The previously requested device log should identify the complete tested patch set. Patch numbering will be reconciled at merge time after the code is ready.
| + size_t urow = (size_t)c->r.width * (size_t)bc_bpp, uimg = urow * (size_t)c->r.height; | ||
| + id<MTLBuffer> ab; size_t ao = arena_alloc(uimg * (size_t)nz, &ab); | ||
| + for (int z = 0; z < nz; z++) | ||
| + nvn_bc_decode(c->tex->d.format, (const uint8_t *)sb.contents + mo + (size_t)z * img, row, c->r.width, c->r.height, (uint8_t *)ab.contents + ao + (size_t)z * uimg, urow); |
There was a problem hiding this comment.
[P2] Wait for source GPU writes before CPU decoding. A preceding mtl_sub_copy in the same submission can leave this CPU read seeing old BC blocks. The real-GPU reproducer finishes with a blue compressed source but a red destination texture. Resolve the pending source writes first and add a regression for that ordered copy sequence.
Dismissed: the reviewer is no longer a maintainer of this repository. The points of this review stay as comments for the author to judge.
|
@romulof thanks. The patch conflicts with main in @thehobbit85 found a real bug on Nov 7: the CPU decode reads the source buffer before an earlier GPU copy into it has finished. Please wait for the pending GPU writes on the source range before decoding, keep the compressed guest-memory data, and add a regression test for a GPU copy followed by a BC copy. Please also list the complete patch set you tested on the iPhone 14 Pro, with the log. |
115fef5 to
ff17248
Compare
|
Thanks for this. We no longer take submissions for the nxnative engine here. Engine fixes, game profiles and patches go to seedds/nxnative directly. Please open this change there as a pull request: https://github.com/seedds/nxnative (follow their CONTRIBUTING.md). Our CONTRIBUTING.md says the same now (#1433). I am closing this PR. |
|
@v0lumehi Thanks for the note. Just to clarify why this cannot be submitted to Upstream The CPU BC decompression subsystem is an NX2Apple fork-only feature, originally added in patch This PR is not a new engine feature—it is a bugfix for NX2Apple's own downstream
Since upstream does not carry Could you reconsider reopening this as a bugfix for existing fork-only code, or advise how you'd like bugfixes to NX2Apple-specific patches handled under the new policy? |
patches: decode CPU BC buffer-to-texture copies and reject unsupported BC readbacks (#446)
Fix or feature
What and why
Follows up on review feedback from @thehobbit85 and @v0lumehi. Rebased onto
main(v1.4.0-rc2, commit757b2e8d).Since merged #888 (commit
908e4e84, patch0088-nvn-decode-bc-uploads-before-copying-into-unpack.patch) already landed the fix for CPU-decoded BC uploads and format views (tex_view_to_mtl), this PR is strictly scoped to the remaining copy/readback operations on GPUs without native BC support:copy_b2t(buffer to texture copies): Wheng_bc_cpuis active, copies from guest memory buffers carrying compressed BC blocks into unpacked Metal textures (RGBA8Unorm,R8Unorm,RG8Unorm,RGBA16Float) are decoded on the CPU into temporary frame arena memory vianvn_bc_decodebefore blitting, matching the unpacked texture format and byte stride.pend_hits,sbw_hits,gw_live) on the source range before CPU decoding so that earlier GPU copies in the same submission are not read stale, preserving compressed guest memory.copy_t2b(texture to buffer copies): Reading from an unpacked Metal texture back into guest memory expecting compressed BC format cannot be re-encoded without a BC encoder. Logs an explicit[RED]warning (RED_ONCE(101)) and returns early without corrupting buffer memory or triggering GPU assertions.mtl_read_texels(CPU readbacks): CPU readbacks from the GPU for CPU-decoded BC textures log an explicit[RED]warning (RED_ONCE(102)) and return zeroed memory.Changes dropped per review
main).front_ios_device_checkbypass: Dropped (retainedmaincheck honoringdm_profile()->tex_bc_cpuvia merged patch 0079).g_bc_cpuchanges: Dropped (retained existing profile gateg_bc_cpu = !g_bc_gpu && dm_prof()->tex_bc_cpu).DM_BC6H_RGB9E5): Landed separately in patch 0117.Test coverage
dm/gfx/tests/t_bc_cpu.m(copies_and_readback):copy_b2tdecodes BC1 compressed buffer into unpacked RGBA8 texels matching reference colors.mtl_sub_copyfollowed bycopy_b2tproperly resolves writes before decode and preserves compressed blue block in guest memory.copy_t2blogsRED_ONCE(101)and returns safely.mtl_read_texelslogsRED_ONCE(102)and zeroes destination memory.t_bc_cpupass cleanly.