Repository navigation
A NaN colour at alpha 0 is returned as 0, as NVIDIA's blender takes a zero factor: Ocarina of Time's white clouds over the ferns are gone - #2030
Conversation
… zero factor (humanperzeus's PR seedds#2030): Ocarina of Time's white clouds over the ferns (PR seedds#2030), with this branch's translator rebuilt from its own source; chain 43821b3e4cba
…ers (chain 402b1a4404e1) blend_zero puts the dm_az guard into main0. For a shader whose main0 already calls dm_body_main0 (it has main0_u, main0_m or main0_d), dmsh_side.unit wrote main0 again as a plain `return dm_body_main0(...)`, and ps_libraries compiled that text, so the guard was gone: 9,265 of Ocarina of Time's 22,352 pixel shaders. unit now keeps such a main0 as it is. Found by a review of play before the build (astra-code-reviewer). The defect is in seedds#2030 as written upstream, not in the merge.
… zero factor: Ocarina of Time's white clouds over the ferns at the camera are gone (chain 4d8f4364df2b) NVIDIA's blender takes a zero factor times anything as 0 (0 x NaN = 0), so a pixel shader may write a NaN colour with alpha 0 under SRC_ALPHA / ONE_MINUS_SRC_ALPHA blending and the target keeps its value. Apple's blender multiplies as IEEE does and stores the NaN; every later pass that reads the target spreads it. Ocarina of Time's half-resolution light shader 5ad65c0eefd09c7f averages hit positions over a fog layer whose density is 0 at the spot (a positive hit count, a weight sum of 0: 1/0 x 0 = NaN; its FMULs carry no .FMZ, so the translation is exact) and writes them with alpha 0. The fog composite 888c1068ac8f7043 carried the NaN into the scene and bloom turned it into white clouds over the ferns at the camera, coming and going as they swayed across the fog volume's surface. dmsh_build.py blend_zero: main0, the entry point a pipeline with float colour targets takes, returns a non-finite rgb as 0 where alpha is exactly 0. A finite output is never changed, nor are the integer entry points (main0_u / main0_m), whose outputs are bits. (cherry picked from seedds/nxnative PR seedds#2030, commit 7d86e5e; issue seedds#1839)
seedds#2030, seedds#2077, seedds#2022, seedds#2075, seedds#2085), last merged at 04811a6, and the Castle Town result on a MacBook Air M4 Castle Town on a 16 GB MacBook Air M4 at 30 fps and full resolution: GPU p50 26-27 ms a frame and 6.9 GB of GPU memory allocated with seedds#2085, against 16.2 GB and about 9 fps before it. Tests: dm/tools/tests/test_docs.py passes.
…0 is returned as 0 (Ocarina of Time's white clouds over the ferns) Conflict with our border-fc branch resolved by hand in dmsh_build.py: border_emu keeps our BORDER_LIVE_FC return line, the PR's BLEND_ZERO / blend_zero block follows it; README keeps both entries; dmsh_chain.h regenerated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s (PR seedds#1833) with the M4 fix, on the synced main The branch is PR seedds#1833 (shader_raw_direct, on for Ocarina of Time) plus one commit that lets raw stores and atomics reach pool buffers above 2^40, which an M4's addresses are. Conflicts resolved by hand: - GlobalToStorage.cs: the PR's structure (TryGenerateRawDirectOp, EmitRawAccess) with main's two changes to the lookup path kept: the 'a miss reads 0 in every word of a vector load' block in TryGenerateRawStorageOp's tail (the direct op has no miss path for loads: the GPU reads 0 at an unmapped address) and the GlobalVectorGroup guard of the follower scan. - nvn_mtl.m (mtl_pool_del): main collects the retired chunks in 'gone' and releases them behind the fence; the PR's whole-pool address buffer (va) joins that batch instead of a separate defer_obj_release. - The translator is rebuilt from the merged sources (dotnet publish; dmsh_xlate.dll, Ryujinx.Graphics.Shader.dll, Ryujinx.Common.dll, Spv.Generator.dll and the pdb replaced, the universal launcher and the other files kept), dmsh_chain.lock updated with tool_lock.py --update-lock (only the four translator fingerprints change), dmsh_chain.h regenerated. tool_lock.py --check-tools passes. - Docs: game-patches.md, symptoms.md and env_switches.tsv regenerated. Checked: test_dmsh_raw_direct, test_xlate_anycpu, test_nsp_chain, the translator tests for border-fc, float-atomic-add, seedds#2081, seedds#2030 and layer_out, docs tests; the host builds for Ocarina of Time. Not run: a game. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
On shaders whose This change in plain = [msl[e['start']:e['end']] + '\n' if shared and e['name'] == 'main0'
else f'{e["attr"]}fragment {e["ret"]} {e["name"]}({", ".join(e["params"])})\n{{\n return dm_body_{e["name"]}({e["args"]});\n}}\n' for e in es]A test that runs A smaller one: the fallback at |
7d86e5e to
a548c50
Compare
…red body too: all 22,296 of Ocarina of Time's pixel shaders with a float colour output (chain 0f5a5ce70b65) Review of seedds#2030: in a pixel shader whose main0 calls the shared body (main0_u / main0_m / main0_d beside it), blend_zero put the guard in main0, and dmsh_side.unit then wrote main0 again as a plain `return dm_body_main0(...)`, which ps_libraries compiles. Ocarina of Time: 9,265 of its 22,352 pixel shaders lost the guard that way. - dmsh_side.unit keeps a shared main0 as it is, with what blend_zero put after its call of the body (the reviewer's change). - The entry points that call the body themselves take the same guard on their result: main0's alpha test and logic operation versions (unit) and main0_f (dmsh_fetch.fold). dmsh_side.az_cols reads the guarded colours from main0, az_after adds them. In a plain shader the guard is in the body, so nothing is added there; the integer entry points stay untouched. - A library that does not build with its extra entry points is built from the plain source with the guard too (dmsh_build.py without_extras; it wrote the source from before blend_zero). Tests: test_dmsh_blend_zero.py 12 (4 new: unit on a shared and on a plain shader, fold's main0_f, without_extras); the 3 new ones about the shared case fail against the old dmsh_side.py / dmsh_fetch.py / dmsh_build.py. test_dmsh_side 6, test_dmsh_fetch 23. Over Ocarina of Time's real 22,352 pixel shaders (blend_zero, unit, fold, on a local build's sources): every float entry point reaches the guard in all 22,296 that have a float colour output (before: 13,031), no integer entry point is touched; the unit and main0_f text of 300 shared-body shaders compiles with Metal's compiler.
|
Thank you, both points were right, and I've pushed a fix (a548c50; the branch is rebased onto 641636e). What changed
Checked
Not yet run: a full Ocarina build on this branch. I'll add the result here once it has run. |
seedds#1901 seedds#1459 seedds#1928 seedds#1942 seedds#1940 seedds#1952 seedds#1611 seedds#2065 seedds#2083 seedds#2008 seedds#2079 seedds#2022 seedds#2075 seedds#2077 seedds#2020 seedds#2021 onto main 04811a6 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014eD437mxrMnW2UwLZhpwc7 Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1459 by PromethOps (open): DM_UPSCALER=metalfx takes agl's agl_ndsr_vr.pck networks too, and a variant with no curve and no power is drawn as one colour space: Ocarina of Time's upscaler is MetalFX's - seedds#1611 by Esteban-V (open): An argument block whose only change is a uniform buffer is patched instead of encoded again - seedds#1774 by uncraftablexd (closed): Compute threads that exit before a barrier keep arriving at it, and every shader loop has a cap (GPU hang defences), chain change - seedds#1824 by cocoman93 (open): Clamp texel fetches past a sampled 2D texture's edge: no hard edge in Ocarina of Time's mist - seedds#1901 by FifteenPen (open): The game's compute dispatches with no game barrier between them run side by side (profile key dispatch_overlap, on for Ocarina of Time): Kokiri Forest GPU p50 15.63 → 14.76 ms - seedds#1928 by FeReuss (open): Ocarina of Time: enc_thread on, the replay encodes on a thread of its own - seedds#1929 by FeReuss (open): Unused border corrections are compiled out of pipelines that bind no sampler with a twin (function constant DMSH_BORDER_FC) - seedds#1930 by FeReuss (open): A float add to storage memory with no result read is one native atomic add instead of a compare-and-swap loop - seedds#1940 by uncraftablexd (open): A prewarm list's lines after its #@after_first_frame line are built after the first frame, in the background, instead of in the prepare step (issue seedds#1747) - seedds#1942 by uncraftablexd (open): Frame step: late frames with the GPU idle do not step up, and a longer hold the GPU does not explain is probed - seedds#1952 by AdyaGMD (open): Compute moves ahead of scene passes past occlusion queries and conditional rendering; clears wait across dispatches - seedds#2008 by bquilty25 (open): nvn: reactive memory watchdog, 16-way view cache, and texture upload batching - seedds#2020 by padsiwono (open): Ocarina of Time v131072: Output Native draws the full output size instead of the game's 80 % frame (`DM_OUTPUT`) - seedds#2021 by padsiwono (open): Ocarina of Time v131072 renders at the launcher's Resolution (`DM_RENDER_SIZE`), docked - seedds#2022 by sleepyeyedjoe (closed): Ocarina of Time: large models no longer go black for one frame twice, 4–5 frames apart, when the game streams new textures into them (a texture ID a shader has read keeps its read mark when it gets another texture) - seedds#2030 by humanperzeus (open): A NaN colour at alpha 0 is returned as 0, as NVIDIA's blender takes a zero factor: Ocarina of Time's white clouds over the ferns are gone - seedds#2035 by Know-It-All-Brother (open): The shader build runs as worker processes, and no shader waits for a batch (Ocarina of Time's cold Mac map: 3,002 s to 1,298 s) - seedds#2065 by Raymon82777 (closed): A vertex library with layer entry points of its own gets bases for its main0 pairs: Ocarina of Time's 230 ms camera-turn hitch in Hyrule Field goes to 39 ms - seedds#2075 by sleepyeyedjoe (closed): Ocarina of Time: a patch of scenery no longer draws dark for one frame when the game gives it a sharper texture (a pool texture the walk does not make holds a stand-in of its own colours until its first read) - seedds#2077 by roandegraaf (closed): Ocarina of Time: fix the "plaid" terrain / missing texture tiles (GPU-drawn textures now reach the storage the game copies) - seedds#2079 by uncraftablexd (open): Render pipelines that share a vertex function are taken from the archive or compiled one at a time: the AGX driver crashes in createVertexProgramVariant's completion block - seedds#2083 by FifteenPen (closed): Ocarina of Time's prewarm list gets 41 more task / mesh pipelines from later play
… zero factor: Ocarina of Time's white clouds over the ferns at the camera are gone (chain ee91be81885f) NVIDIA's blender takes a zero factor times anything as 0 (0 x NaN = 0 x Inf = 0, Direct3D's rule), so a pixel shader may write a NaN colour with alpha 0 under SRC_ALPHA / ONE_MINUS_SRC_ALPHA blending and the target keeps its value. Apple's blender multiplies as IEEE does, stores the NaN, and every later pass that reads the target spreads it. Ocarina of Time's half-resolution light shader 5ad65c0eefd09c7f averages hit positions over a fog layer whose density is 0 there (1/0 x 0); the fog pass carried the NaN into the scene and bloom made white clouds over the ferns at the camera. dmsh_rewrite.py blend_zero, called from dmsh_build.py after the entry points that share main0's body: main0 returns a non-finite rgb as 0 where alpha is exactly 0 (dm_az before each `return out;`). A finite output is never changed, the integer entry points (main0_u / main0_m, whose outputs are bits) are left as they are. The guard reaches the text the library is compiled from: dmsh_side.unit keeps a main0 that calls the shared body as it is, and main0's alpha test and logic operation versions and main0_f (dmsh_fetch.fold), which call the body themselves, take the same guard on their result (dmsh_side.az_cols / az_after). A library built without its extra entry points gets the guard in its plain source too (without_extras). Rebuilt on 80fc2ec, which moved the MSL rewrites into dmsh_rewrite.py; the first version of this PR (review: the guard missed shared-body shaders in unit) is folded in. Tests: test_dmsh_blend_zero.py 12 (the 3 about the shared case fail against the first version), test_dmsh_side 6, test_dmsh_fetch 23, test_dmsh_meshstage 34, test_discard 4, test_dmsh_abi 11, test_dmsh_code_fp 8, test_docs 6, test_nsp_chain 17. Over Ocarina of Time's 22,352 pixel shaders (blend_zero, unit, fold on a full local build's sources): every float entry point reaches the guard in all 22,296 with a float colour output, no integer entry point touched. A full Mac build (42,848 shaders) with this change on 641636e compiles; at the spot, a recorded camera route shows clouds in 4 of 12 frames with the guard taken out of the two shaders and in 0 of 12 with it, the fog equally bright.
a548c50 to
f67642d
Compare
|
The branch had conflicts with main after 80fc2ec, which moved the shader build's MSL rewrites into
Checked again on the rebuilt branch:
|
and seedds#2085 in upstream's versions, the host at -O2, Ocarina of Time's camera-turn hitch in Hyrule Field (230 → 39 ms), 41 more task / mesh pipelines and 4,959 render / compute pipelines in its prewarm list, GPU writes into uploaded textures kept on the GPU, compact NVN recordings; chain 8f2d8a09c3f9 PR seedds#2030 (blend_zero) stays the fork's own: upstream moved the shader build's MSL rewrites into dmsh_rewrite.py (80fc2ec), so blend_zero and BLEND_ZERO move there, dmsh_build.py finish calls dmsh_rewrite.blend_zero, and test_dmsh_blend_zero.py imports it. dmsh_chain.h regenerated (8f2d8a09c3f9). Tests: test_dmsh_*.py 26/26 OK (test_dmsh_pairs with DM_GAME=0400486024DEC000); t_pool_chunks 151/0, t_cpu_storage 135/0, t_readback 218/0, t_pool_seen_replace 44/0, t_pool_standin 31/0, t_pool_notes 81/0, t_mesh_first_use 53/0.
|
A second-machine check on an M2 Pro (macOS 27.2): main
Screenshot and numbers in #2187: #2187 (comment) |
…h_rewrite.py in 10298c1): the pull request's rebuilt version f67642d follows, with its review fix The first version's guard missed every pixel shader whose main0 shares its body with other entry points (dmsh_side.unit wrote main0 again as a plain call of the body): 9,265 of Ocarina of Time's 22,352 pixel shaders. The fern shader 5ad65c0eefd09c7f has no shared body, so the clouds it caused were gone either way.
… zero factor: Ocarina of Time's white clouds over the ferns at the camera are gone (chain 637e72cf3b20) NVIDIA's blender takes a zero factor times anything as 0 (0 x NaN = 0 x Inf = 0, Direct3D's rule), so a pixel shader may write a NaN colour with alpha 0 under SRC_ALPHA / ONE_MINUS_SRC_ALPHA blending and the target keeps its value. Apple's blender multiplies as IEEE does, stores the NaN, and every later pass that reads the target spreads it. Ocarina of Time's half-resolution light shader 5ad65c0eefd09c7f averages hit positions over a fog layer whose density is 0 there (1/0 x 0); the fog pass carried the NaN into the scene and bloom made white clouds over the ferns at the camera. dmsh_rewrite.py blend_zero, called from dmsh_build.py after the entry points that share main0's body: main0 returns a non-finite rgb as 0 where alpha is exactly 0 (dm_az before each `return out;`). A finite output is never changed, the integer entry points (main0_u / main0_m, whose outputs are bits) are left as they are. The guard reaches the text the library is compiled from: dmsh_side.unit keeps a main0 that calls the shared body as it is, and main0's alpha test and logic operation versions and main0_f (dmsh_fetch.fold), which call the body themselves, take the same guard on their result (dmsh_side.az_cols / az_after). A library built without its extra entry points gets the guard in its plain source too (without_extras). Rebuilt on 80fc2ec, which moved the MSL rewrites into dmsh_rewrite.py; the first version of this PR (review: the guard missed shared-body shaders in unit) is folded in. Tests: test_dmsh_blend_zero.py 12 (the 3 about the shared case fail against the first version), test_dmsh_side 6, test_dmsh_fetch 23, test_dmsh_meshstage 34, test_discard 4, test_dmsh_abi 11, test_dmsh_code_fp 8, test_docs 6, test_nsp_chain 17. Over Ocarina of Time's 22,352 pixel shaders (blend_zero, unit, fold on a full local build's sources): every float entry point reaches the guard in all 22,296 with a float colour output, no integer entry point touched. A full Mac build (42,848 shaders) with this change on 641636e compiles; at the spot, a recorded camera route shows clouds in 4 of 12 frames with the guard taken out of the two shaders and in 0 of 12 with it, the fog equally bright. (cherry picked from seedds/nxnative PR seedds#2030, commit f67642d, rebuilt with the review fix a548c50; issue seedds#1839)
…g, as on the console: NVN's driver sets the float blender's "zero times anything is zero" option (the command word for SET_BLEND_FLOAT_OPTION is in the sdk module), while Apple's blender stores NaN for 0 x NaN and 0 x Inf. Every pixel shader with a float4 colour output ends in a guard that reads a word from the host (fragment buffer 28, two bits per colour output), and the host sets an output's bits only where its state can have that weight: blending on, a floating-point target, a sum or difference, a source colour factor of SRC_ALPHA (zero at alpha 0) or ONE_MINUS_SRC_ALPHA (zero at alpha 1) and a destination factor that does not read the source colour. Every other draw returns its colour as it is; a factor of ZERO needs nothing, since Apple's blender leaves that term out. Ocarina of Time's mist shader divides by zero at alpha 0 and blends into an RGBA16F target with SRC_ALPHA / ONE_MINUS_SRC_ALPHA, which the bloom spreads into white clouds; they did not show on the Mac route run here, with the rule on or off, so the game itself awaits a retest. t_blend_zero draws NaN, +Inf, -Inf and 2 at alpha 0 and 1 under seven blend states and reads the target back, with the rule and with DM_NVN_BLEND_ZERO=0 (Apple's blender as it is). Ocarina of Time's 42,848 shaders build; standing in Kokiri Forest GPU p50 10.86 -> 10.95 ms, within the spread between runs, 60 fps both (Apple M6). Open: NaN already in the target under a zero destination weight, a non-finite weight on a colour of 0, the alpha channel's own weights, the Vulkan and OpenGL paths, and the iOS libraries were not run (PR #2030, issue #1839) Co-authored-by: Human Khoobsirat <3029935+humanperzeus@users.noreply.github.com>
|
Thank you: the diagnosis here (the mist shader's NaN at alpha 0, blended with SRC_ALPHA / ONE_MINUS_SRC_ALPHA into the RGBA16F target, where Apple's blender stores 0 x NaN as NaN) is what 0662f9d on main is built on, and you are credited as co-author. The code is a different design, so I am closing this PR in its favour. What changed against the PR:
One thing is open: the white clouds did not show on my Mac route (the Kokiri Forest village from a save), with the rule on or off, so the game itself is not confirmed. If you have a save where they show, a retest on main would settle it; |
|
Retest on an M2 Pro (macOS 27.2), save in Kokiri Forest, same spots at the forest exit and in Hyrule Field near the tree. Main What I ruled out:
Left between the two builds are the translator changes e45694b and 918e9f3 (and 0662f9d itself). A build with the first two reverted is compiling now; I will post the result. 1d090a6 (bound rounded up to 256 bytes) may be related, I have not tested it yet. Screenshots, before and after:
|
…g, as on the console: NVN's driver sets the float blender's "zero times anything is zero" option (the command word for SET_BLEND_FLOAT_OPTION is in the sdk module), while Apple's blender stores NaN for 0 x NaN and 0 x Inf. Every pixel shader with a float4 colour output ends in a guard that reads a word from the host (fragment buffer 28, two bits per colour output), and the host sets an output's bits only where its state can have that weight: blending on, a floating-point target, a sum or difference, a source colour factor of SRC_ALPHA (zero at alpha 0) or ONE_MINUS_SRC_ALPHA (zero at alpha 1) and a destination factor that does not read the source colour. Every other draw returns its colour as it is; a factor of ZERO needs nothing, since Apple's blender leaves that term out. Ocarina of Time's mist shader divides by zero at alpha 0 and blends into an RGBA16F target with SRC_ALPHA / ONE_MINUS_SRC_ALPHA, which the bloom spreads into white clouds; they did not show on the Mac route run here, with the rule on or off, so the game itself awaits a retest. t_blend_zero draws NaN, +Inf, -Inf and 2 at alpha 0 and 1 under seven blend states and reads the target back, with the rule and with DM_NVN_BLEND_ZERO=0 (Apple's blender as it is). Ocarina of Time's 42,848 shaders build; standing in Kokiri Forest GPU p50 10.86 -> 10.95 ms, within the spread between runs, 60 fps both (Apple M6). Open: NaN already in the target under a zero destination weight, a non-finite weight on a colour of 0, the alpha channel's own weights, the Vulkan and OpenGL paths, and the iOS libraries were not run (PR seedds#2030, issue seedds#1839) Co-authored-by: Human Khoobsirat <3029935+humanperzeus@users.noreply.github.com> (cherry picked from commit 0662f9d)
…its outputs are drawn to: bz_word (0662f9d, PR seedds#2030) maps physical attachment i to its logical output through g_pso_lmap, but draw_ sets g_pso_lmap to NULL before it encodes the fragment arguments (encode_args, which calls bz_bind), so in the later pass of a readable-tile merge (DM_NVN_TBDR=1, off by default), when fz_p2_draw moves an output to another attachment, its bits were taken with the format of the attachment that has the output's number, not the one it is drawn to; the deferred pass merge and same-pass tile reads map each output to itself, so no pixel of theirs changes. A later-pass draw whose output 0 blends SRC_ALPHA / ONE_MINUS_SRC_ALPHA into an RGBA16F attachment 1, behind the earlier pass's RGBA8 attachment 0, got the word 0, so a NaN colour at alpha 0 was stored there as Apple's blender stores it. Found reading the code, not seen in a game. draw_ now copies the eight mapping bytes beside raster_mask, before the reset (raster_mask is taken there for the same reason), and hands them to bz_bind through g_bz_lmap for the fragment encode_args call only; bz_word takes the mapping as an argument, and the word bz_bind bound last is kept in g_bz_last for the test. The host alone: no shader or chain change, and DM_NVN_BLEND_ZERO=0 still gives 0 for every draw. t_blend_zero has a new case drawn through draw() with g_pso_lmap set, as defer_replay passes a mapping in: physical attachment 0 RGBA8 with no output, physical 1 RGBA16F holding output 0; the bound word is 1 with the rule (0 with DM_NVN_BLEND_ZERO=0), the mapping is gone after the draw, and the same draw unmapped binds 0. Built with bz_bind reading g_pso_lmap as before, the mapped draw binds 0 and that check fails. make check_t_blend_zero: 165 checks, 0 failed, with the rule and with DM_NVN_BLEND_ZERO=0 (main: 160 and 160). Also checked: test_dmsh_blend_zero.py passes (its compile test for macOS and for iOS 18 too), t_alpha, t_logic, t_defer_chain, t_fuse_check, t_pso_warm and t_image_attachment_store pass as on main, and so does t_feedback but for its check "with nothing running: a commit", which fails in most runs on main too (13 of 15 runs here, 12 of 15 on main), test_docs passes, the Mac host builds with the same 58 warnings as main (M3 Max, macOS 26.7.2, Xcode 27.2, metal 32023.922). Not run: a game, regress.py (the readable-tile merge is off with default settings), lint_c.py (no clang-tidy here), iOS
The blend-zero word (#2030) and the rounding word (#2807) at fragment buffer DMSH_BLEND_BUFFER are computed per physical attachment through the map of a merged pass (g_pso_lmap: physical target i holds output lmap[i]). bz_bind ran inside the fragment encode_args, but draw_ clears g_pso_lmap once it has the pipeline, before that call, so a merged draw got the words of an unmerged pass while its pipeline blended under the map. Output 0 drawn SRC_ALPHA / ONE_MINUS_SRC_ALPHA into an RGBA16F attachment 1 got the zero word 0 and stored the NaN of alpha 0; output 0 drawn unblended into an RGBA8 attachment 1 got the rounding word 0 and stored 66.5 / 255 as 67, not NVIDIA's 66. draw_ now keeps a copy of the map beside raster_mask, before the reset, and binds the fragment state the translated shader reads beside its bindings itself (at_bind, bz_bind, lo_bind), after the fragment arguments and the re-encode check; bz_bind takes the map as an argument and bz_word / rop_word read it. encode_args_ binds only the shader's own resources. g_bz_last keeps the words bound last, for the tests. No game's picture changes on main: the only map draw_ sees now comes from same-pass tile reads (fb_tile_plan), which map each output to its own attachment, so only bits of outputs a shader does not write differ. Checked (M4 Pro, macOS 27.2): t_blend_zero has a merged-pass row through the real replay with readback (from PR #2463) and t_rop_round one for the rounding word. With bz_bind given no map, as on main, they fail (10 and 33 checks); with the fix t_blend_zero 192/0 and t_rop_round 9284/0 in both modes. t_alpha, t_logic, t_feedback, t_pso_warm (MTLDevice and Metal 4), t_image_attachment_store and t_nvn pass; the Mac host builds; test_docs passes; clang-tidy at baseline. Not run: a game, regress.py (no path on main maps an output to another attachment), iOS. Co-authored-by: dean0396 <4335213+dean0396@users.noreply.github.com> Co-authored-by: Lennart Kotzur <74553440+mmkzer0@users.noreply.github.com>




What and why
Fixes #1839 (the same white clouds, reported on the way between Kokiri Forest and Hyrule Field, same shader
5ad65c0eefd09c7f).Symptom. The Legend of Zelda: Ocarina of Time, Kokiri Forest: with the camera low among the ferns, white clouds bloom over the near ferns and come and go as they sway. Dropping the fog composite (
888c1068ac8f7043) removes them.Cause. NVIDIA's blender takes a zero factor times anything as 0 (0 × NaN = 0 × Inf = 0, Direct3D's rule), so a pixel shader may write a NaN colour with alpha 0 under SRC_ALPHA / ONE_MINUS_SRC_ALPHA blending and the target keeps its value. Apple's blender multiplies as IEEE does, stores the NaN, and every later pass reading the target spreads it.
Here the half-resolution light shader
5ad65c0eefd09c7f(a mesh-drawn fog volume) averages hit positions over a fog layer whose density is 0 at that spot: a positive hit count with a weight sum of 0,1/0 × 0. Its FMULs carry no.FMZ, so the translation is exact; the NaN is the game's own arithmetic. It writes the result with alpha 0 into an RGBA16F light target. The fog composite carried the NaN into the R11G11B10F scene and bloom turned each NaN pixel into a white blot. The ferns sway across the fog volume's surface, so those pixels pass and fail its depth test in turn, hence the coming and going.Change.
dmsh_rewrite.pyblend_zero, called fromdmsh_build.pyafter the entry points that sharemain0's body:main0, the entry point a pipeline with float colour targets takes, returns a non-finite rgb as 0 where alpha is exactly 0 (dm_azbefore eachreturn out;). A finite output is never changed; the integer entry points (main0_u/main0_m, which calldm_body_main0) are left as they are, their outputs being bits. Outside SRC_ALPHA blending the rule only touches outputs that were NaN or Inf already.The guard has to reach the text the library is compiled from:
dmsh_side.unitkeeps amain0that calls the shared body as it is.main0's alpha test and logic operation versions, andmain0_f(dmsh_fetch.fold), call the body themselves, so they take the same guard on their result (dmsh_side.az_cols/az_after).without_extras).The branch is rebuilt on 80fc2ec, which moved the MSL rewrites into
dmsh_rewrite.py, as one commit.Reference entry: A NaN colour at alpha 0 under SRC_ALPHA blending; a line under the game note's "Found on this game".
How it was found, in short: per-pass raw floats of one frame (
DM_NVN_TEXSNAP+DM_NVN_SNAPRAW) put the first NaN in the light pass (0 before it, about 18,000 pixels after); that one shader, instrumented and loaded from a folder beside the library (DM_MSL_DIR), put the first NaN at1/w × vwithw = 0; the pass's blend state and the alpha it stores (1 = 1 − srcAlpha, so srcAlpha 0) gave the cause. Ruled out on the way: the fog volumes (finite, increasing slice by slice), FMZ handling (none in the code), stale uniforms (DM_NVN_UB_DEFER=0;DM_NVN_UBP_CHECK: 14,000 shadows equal to GPU memory), the depth test (every shaded pixel legitimately in front of the surface).Checked
python3 dm/gfx/tests/test_dmsh_blend_zero.py(12, new: every return ofmain0guarded, the shared body and the integer entry points untouched, integer outputs never touched, a second pass a no-op; throughdmsh_side.unitanddmsh_fetch.fold, every float entry point of a shared and of a plain shader reaches the guard and the integer ones do not;without_extras; each text compiled by Metal's compiler. The 3 about the shared case fail against the first version of this PR, 3 others withblend_zerodisabled),test_dmsh_side.py(6),test_dmsh_fetch.py(23),test_dmsh_meshstage.py(34),test_discard.py(4),test_dmsh_abi.py(11),test_dmsh_code_fp.py(8),python3 -m unittest dm/tools/tests/test_docs.py(6),python3 -m unittest dm/tools/tests/test_nsp_chain.py(17).blend_zero,unit,foldon a local build's sources): every float entry point reaches it in all 22,296 that have a float colour output; no integer entry point is touched. The first version of this PR reached 13,031: the 9,265 shared-body shaders lost it inunit(found in review). Theunitandmain0_ftext of 300 shared-body shaders compiles with Metal's compiler. A full Mac build (42,848 shaders) with this change on 641636e compiles; at the spot, the same recorded route shows clouds in 4 of 12 frames with the guard taken out of the two shaders and in 0 of 12 with it, the fog equally bright.0400486024DEC000v131072, a full Mac build (42,848 shaders) with this change, on a base before the latest 19 commits ofmain; the PR branch is this change alone on currentmain. A recorded camera route to the spot (DM_KEYSreplay, LoadEnd-synced, 12 shots 0.7 s apart) before and after: frames with a cloud 8 of 12 → 0 of 12; mean picture brightness at the spot 21–25 after, 21–24 in the clean frames before (about 12 with the fog dropped), so the fog is kept; 0 command buffer errors. With the rule's condition marked in the new build (hit count > 0, weight sum 0), it still occurs at 3,056 and 4,913 pixels in two frames, and the light target and the scene hold 0 non-finite values.scripts/regress.py:impactreaches every NVN game through the chain (broad: Breath of the Wild, Pokémon Scarlet, Tears of the Kingdom; Hades not affected).check --gameswas not run: only Ocarina of Time is set up on this Mac, and each other game needs a full shader build of the new chain. By construction the rule changes no finite output.Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas run (the symptom index)dmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change🤖 Generated with Claude Code