Skip to content

NVN: respect primitive restart when expanding indexed fans and quads - #110

Closed
Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/nvn-primitive-restart-polygons
Closed

Jpkovas wants to merge 1 commit into
seedds:mainfrom
Jpkovas:fix/nvn-primitive-restart-polygons

Conversation

@Jpkovas

@Jpkovas Jpkovas commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

The direct indexed fan/quad conversion reads restart markers as ordinary indices and connects polygons across them. In LM3 the first cached shadow-mask draw contains separate triangle fans; the extra triangles zero valid depth regions, producing straight clipped light boundaries on the garage floor.

Expand indices with the configured S.restart.on / S.restart.index. A marker ends the current polygon before base-vertex application. Keep the existing output allocation bound, instance count and base vertex/instance forwarding. This changes direct CPU expansion of fans/quads only; it does not claim to complete every indirect or strip restart path.

The original synthetic GPU test uses two separated polygons, short/empty segments, 8/16/32-bit indices and default/custom markers. It requires literal red pixels in each polygon and untouched gap/outside pixels. On the public base, the polygon assertions fail. With this patch alone all 37 checks pass with Metal API Validation. It needs no game index buffer, translated shader, texture, image or save.

make -C dm/gfx/tests GAME=0100DCA0064A6000 t_primitive_restart
MTL_DEBUG_LAYER=1 dm/gfx/tests/t_primitive_restart

Separately, the local combined Mac game build was visually checked for a soft static light edge and a moving character shadow, at Handheld/30 and Docked/60. That integration observation is not a device visual acceptance or evidence that every shadow issue is resolved. No shadow-comparison override or diagnostic shader modification is included.

Public source base: d979c346b9a188d63ae16ec6f73e099a3c7f5a05. Each patch is independent of the other proposals in this batch.

Fresh negative-control result: primitive restart: 37 checks, 12 failed.

seedds added a commit that referenced this pull request Oct 24, 2026
…ral, found on Luigi's Mansion 3): no blending on integer targets, primitive restart in fan and quad expansion, partial depth-stencil clears, every name of an upgraded texture, the SDK's AudioOut fields. nvn_mtl.m pso_desc (#105): an integer colour target took the game's blend enable, and Metal refuses such a pipeline with an assertion even without the API validation layer (checked on this Mac); Maxwell ignores blending on integer targets, so it is off for them. draw (#110): indexed triangle fans and quads expanded on the CPU read the restart index as a vertex and joined the polygons across it, and the extra triangles cleared parts of Luigi's Mansion 3's cached shadow depth; nvn_primitive.h ends a polygon at the restart index (compared before the base vertex), at most as many triangles as before. OP_CLEAR_DS (#108): a depth-stencil clear whose scissor does not cover the target, or whose stencil mask is partial, cleared the whole target before the first draw, and a partial stencil mask did so in a pass too; both are drawn as a triangle now (clear_ds_tri), full clears stay load actions. Logs on the T7 show who takes the new path: Tears of the Kingdom clears 8x8 tiles of a 64x64 depth target (each clear wiped the whole target), AI: THE SOMNIUM FILES clears 1280x720 of a 1920x1080 one. tex_upgrade (#107): a texture recreated to add a usage replaced only the asking serial and one sharing-table entry, so other serials on the same storage read the old copy; every entry in g_by_serial, g_ghost and g_alias now moves to the new texture in place, g_alias_set follows, and the old one is retired after the submissions that used it. hle_audio.c (#109, reworked): the host left the guest AudioOut zero, and middleware that checks its first word before Stop / Close skipped the close, freed its PCM and the host's consumer read freed memory (SIGBUS on resume in Luigi's Mansion 3). The PR wrote 1 and cleared it on close; the SDK's OpenAudioOut (SDK 8, 12, 18 and 20 checked) writes sample rate, channel count, sample format and state at +0 / +4 / +8 / +0xc, its getters load from there, and CloseAudioOut only sets the state to stopped, so the host now writes the same (au_info). New tests t_integer_blend (63 checks), t_primitive_restart (37), t_clear_ds (43), t_upgrade_alias (10) in the gfx run list, and an AudioOut fields and lifetime case in t_audio (12 guarded open / close / unmap / resume cycles, silent sink and real output). Checked: the four new tests pass under Metal validation; every other gfx test gives the same result as on main (t_fuse_check, t_reorder_chain, t_defer_chain, t_mip_extent, t_rt_range_ro and t_rt_range fail the same cases on both; t_refl finds no reflection samples in this checkout's shader cache); the host unit tests pass; on the Mac host for 90 s from boot, against main built the same way: Breath of the Wild over the title, 60 fps and the same red lines; AI: THE SOMNIUM FILES (shaders built by the NSP script on this chain), whose 1280x720 depth clears at the start of a pass now take the triangle path too (from pass 119), 60 fps, no red line, 5 long frames against 12. Not taken from this batch: #106 (the stencil-only view of a depth-stencil texture works without format-view usage; only the validation layer asks for it, and the PR would put that usage on every depth-stencil buffer), #111 (an opt-in draft with no memory saving shown), #104 (Mac app bundle)

Co-authored-by: João Karalkovas <[email protected]>
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Ported in bc5ba1b, thanks. The test now runs in the main run list.

@seedds seedds closed this Oct 24, 2026
arielherself added a commit to arielherself/nxnative that referenced this pull request Oct 24, 2026
…seedds#110, run-time shader captures on a Mac without Metal 4, embedded modules with an empty patch area)

Conflict: nvn_mtl.m includes both mtl_srclib.h and upstream's nvn_primitive.h. The chain version is unchanged (070d11b1b3f8); the GL and Vulkan layers still take their libraries through dm_srclib_open / dm_srclib_function. The merged host builds for iOS with build_app_linux.py; the tool and workflow tests pass (8 files).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…eedds#109 and seedds#110 (general, found on Luigi's Mansion 3): no blending on integer targets, primitive restart in fan and quad expansion, partial depth-stencil clears, every name of an upgraded texture, the SDK's AudioOut fields. nvn_mtl.m pso_desc (seedds#105): an integer colour target took the game's blend enable, and Metal refuses such a pipeline with an assertion even without the API validation layer (checked on this Mac); Maxwell ignores blending on integer targets, so it is off for them. draw (seedds#110): indexed triangle fans and quads expanded on the CPU read the restart index as a vertex and joined the polygons across it, and the extra triangles cleared parts of Luigi's Mansion 3's cached shadow depth; nvn_primitive.h ends a polygon at the restart index (compared before the base vertex), at most as many triangles as before. OP_CLEAR_DS (seedds#108): a depth-stencil clear whose scissor does not cover the target, or whose stencil mask is partial, cleared the whole target before the first draw, and a partial stencil mask did so in a pass too; both are drawn as a triangle now (clear_ds_tri), full clears stay load actions. Logs on the T7 show who takes the new path: Tears of the Kingdom clears 8x8 tiles of a 64x64 depth target (each clear wiped the whole target), AI: THE SOMNIUM FILES clears 1280x720 of a 1920x1080 one. tex_upgrade (seedds#107): a texture recreated to add a usage replaced only the asking serial and one sharing-table entry, so other serials on the same storage read the old copy; every entry in g_by_serial, g_ghost and g_alias now moves to the new texture in place, g_alias_set follows, and the old one is retired after the submissions that used it. hle_audio.c (seedds#109, reworked): the host left the guest AudioOut zero, and middleware that checks its first word before Stop / Close skipped the close, freed its PCM and the host's consumer read freed memory (SIGBUS on resume in Luigi's Mansion 3). The PR wrote 1 and cleared it on close; the SDK's OpenAudioOut (SDK 8, 12, 18 and 20 checked) writes sample rate, channel count, sample format and state at +0 / +4 / +8 / +0xc, its getters load from there, and CloseAudioOut only sets the state to stopped, so the host now writes the same (au_info). New tests t_integer_blend (63 checks), t_primitive_restart (37), t_clear_ds (43), t_upgrade_alias (10) in the gfx run list, and an AudioOut fields and lifetime case in t_audio (12 guarded open / close / unmap / resume cycles, silent sink and real output). Checked: the four new tests pass under Metal validation; every other gfx test gives the same result as on main (t_fuse_check, t_reorder_chain, t_defer_chain, t_mip_extent, t_rt_range_ro and t_rt_range fail the same cases on both; t_refl finds no reflection samples in this checkout's shader cache); the host unit tests pass; on the Mac host for 90 s from boot, against main built the same way: Breath of the Wild over the title, 60 fps and the same red lines; AI: THE SOMNIUM FILES (shaders built by the NSP script on this chain), whose 1280x720 depth clears at the start of a pass now take the triangle path too (from pass 119), 60 fps, no red line, 5 long frames against 12. Not taken from this batch: seedds#106 (the stencil-only view of a depth-stencil texture works without format-view usage; only the validation layer asks for it, and the PR would put that usage on every depth-stencil buffer), seedds#111 (an opt-in draft with no memory saving shown), seedds#104 (Mac app bundle)

Co-authored-by: João Karalkovas <[email protected]>
ltrdpper pushed a commit to ltrdpper/BananaNative that referenced this pull request Nov 11, 2026
…ix, 12 GB memory, foldable inner screen, Pokopia frame cap

Memory maps (seedds#127, seedds#132): background pipeline compiles on Turnip are serialized (vk-psoasync / vk-psopt through the heavy-compile hold), contiguous placed segments are joined across pools at submission start, unplace copies through sw_mmap_fixed instead of mremap so the kernel merges anonymous VMAs again, and past 2,000 split anonymous maps the dirty tracker releases its protections once (one re-upload) so guest VMAs merge.
Launcher: android:appCategory="game" (seedds#110); the game fills a foldable's near-square inner screen (GameOrientation.fixedLandscape from the maximum window metrics); overlay blocks inset from rounded corners and cutouts (seedds#105, OverlayInset); Prepare texts say whether the code rewrite or a shader translation runs and that shaders are kept; no "Ready, with limits" dialog at start.
Frame rate: Ocarina of Time (`0400486024DEC000`) fps_limit 60 (was 30). Pokémon Pokopia (`0400A3A01EE4C000`) fps_limit 60 with the new launcher key fps_limit_present: the host limiter's caps are offered with a note that they pace the presents only (seedds#143).
Skipped work: the Vulkan replay counts draws and dispatches skipped for causes of the device (no mesh shading, refused shaders or pipelines, missing features) and warns once per run past DM_VK_SKIP_WARN percent (default 5) in two 300-frame windows in a row; the launcher shows a small notice.
Textures: the pool-read line counts images made again for an ID made before (diagnostic, seedds#131).
Docs: Fire Emblem Fortune's Weave's note links only existing reference entries; docs_patches classifies av1_decoder.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants