Repository navigation
Conversation
A device with supportsBCTextureCompression == NO (A15 / A16 and older iPhones and iPads) returns nil for every texture made in a BC pixel format, so each BC texture of a game is missing. The device now decides at start (nvn_bc_cpu_wanted): one that samples BC keeps the BC textures and the GPU deswizzle unchanged; one that cannot makes a BC texture RGBA8 / RGBA8 sRGB / R8 / RG8 / RGBA16F and fills it with texels decoded by bcdec from the deswizzled blocks (pkg_upload_, and buffer-to-texture copies in copy_b2t). Views follow the substituted format; copies out of such a texture and BC render targets are reported red. DM_TEST_NO_BC=1 takes the path on a Mac. Tests: t_bcdec (CPU only, CI and ASan / UBSan), t_bc_cpu (Metal 4, local).
853d76d to
9f2a895
Compare
|
Thank you for this, and for the care that went into it. Doing the check at run time is cleaner than the profile key, the write-up is honest about the history and the limits, and the tests are thorough: I ran Still, I'm going to close it. When I removed this path in In case it helps the NX2Apple fork, which keeps this path, here are a few things I noticed while reading (please correct me if I've misread any):
Thanks again for taking the time on this, and for being so clear about what it is and isn't. |
Upstream-Status: fork-only (declined seedds#488) Reason: Support A15/A16 and older iOS GPUs without hardware BC texture compression including BC6H to RGB9E5 Issue: LNPANDY/NX2Apple#180
What and why
On an Apple GPU that cannot sample BC (
[MTLDevice supportsBCTextureCompression]is NO before the A19: A15 / A16, older iPhones and iPads)newTextureWithDescriptor:returns nil for every texture made in a BC pixel format, so each BC texture of a game is missing. This restores a CPU decode for those devices only. Part of the effort to let forks drop their larger patches (#388).This was in the tree and was removed on purpose.
14fbcf9c("Only GPUs with BC textures are supported: no-BC decompression paths removed") took outnvn_bcdec.c,dm/third_party/bcdec, a GPU kernel for BC1-5 andDM_TEST_NO_BC, because decoded textures do not fit in memory on those phones (Breath of the Wild: 3.9 GB instead of 2.8 GB). I am not trying to overturn that. What differs here:nvn_bc_cpu_wanted): a device that samples BC (every supported one) takes exactly the code it takes now. No profile key, no build switch.DM_TEST_NO_BC=1(the old switch name) takes the path on a Mac, for testing.The downstream fork (NX2Apple) shipped this path in v0.4.5 for A15 / A16 users, behind a per-game profile key (
tex_bc_cpu, on for Tears of the Kingdom). With run-time detection that key is not needed: a device without BC support has no other way to show a BC texture, and a device with it never reaches the path.The change
dm/gfx/tex/nvn_bcdec.{c,h}: the decoded Metal format of each BC format,nvn_bc_decodefor the blocks of one level and layer (BC1-BC7, the sRGB forms, BC4 / BC5 signed and unsigned, BC6H to RGBA16F; partial edge blocks write only the texels inside the level), andnvn_bc_cpu_wanted. Pure C. Decoding isdm/third_party/bcdec(0.985, unmodified, MIT or Unlicense, with its licence and a README; one row indm/third_party/README.md).nvn_mtl.m:mtl_initasks the device.tex_descmakes a BC texture RGBA8 / RGBA8 sRGB / R8 / RG8 / RGBA16F, also for a format-changing view (nvn_fmt_to_mtl_dec, so the sRGB reinterpretation of BC1 is an RGBA8 / RGBA8_sRGB view).pkg_upload_(every CPU-written, packaged and sparse-pool texture) deswizzles on the CPU, decodes per level, array layer, cube face and depth slice into a staging buffer sized per texel, and blits it; the GPU deswizzle writes blocks, so it is skipped for these.copy_b2tinto a BC texture is mirrored into the storage as before, or decoded from the buffer's memory when the CPU holds it (copy_b2t_bc). RGB_DXT1 keeps reading alpha 1 through its view swizzle.[RED]line instead of Metal validation aborts: a copy out of a BC texture (texture→buffer,ReadTexelsof a texture the CPU did not write), a buffer-to-texture copy whose source the GPU writes, and a BC texture as a render target (the shadow ofbcrt_attachcopies blocks, which these textures no longer hold: the attachment is left out, as an unshadowed BC target is on any device).docs/reference/rendering.md(symptom index regenerated),dm/gfx/tex/README.md,docs/env_switches.tsv.Checked
t_bcdec(make -C dm/gfx/tex/tests run, alsoasan; CPU only, added to the CI step "CPU texture layout and deswizzle tests" and so to the sanitizer job): 99 checks. BC1 against a decoder written without bcdec (all palette modes, sRGB the same bytes), hand-made BC2 / BC3 / BC4 (unsigned and signed, both modes) / BC5 / BC6H / BC7 blocks, the format map of all 16 BC formats and the rejection of their neighbours, a 10x6 image with padded source and destination pitches and untouched padding, a mip chain 9x5 down to 1x1, andnvn_bc_cpu_wantedfor a device with and without BC (the mock of "no BC").t_bc_cpu(make -C dm/gfx/tests GAME=010015100B514000 check_t_bc_cpu, Metal 4, so local liket_cpu_tex --metal): 15 checks, withDM_TEST_NO_BC=1and Metal's validation layer on an M2 Max: a CPU-written 2D-array BC1 texture of 18x10, 2 layers, 3 levels is RGBA8 and every level and layer reads back as the decoded texels; a GPU-only texture filled by buffer-to-texture copies reads back the same; with the path off the same kind of texture stays BC1 and holds the blocks as written. It aborts in Metal's validation whentex_descdoes not substitute the format. Existing:t_tex5,334 checks,t_cpu_tex,t_tex_layout,t_cover.make -C dm/host GAME=010015100B514000builds;GAME=010015100B514000 python3 dm/ios/tools/compile_check.py: 179 files, 0 failed;lint_python.py: 0 new;dm/tools/tests/test_docs.py,test_env_switches.py,test_ci_toolchain.pypass.regress.pywas not run. No game was started and nothing was installed on a device. On a device with BC the only changed code that runs is themtl_initquestion andbc_decoded()returning 0.Docs
docs/reference/rendering.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)