native: depth textures compute writes get colour twins, copied where the use changes (#258) #371
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/371"
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?
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Tarraga on 2026-11-27T14:28:50Z.
Refs #258. This covers only the piece I claimed there: depth textures that compute writes.
Problem
The tiled light draws test equal against a 1280x720 depth target of DXGI format 118, the console's
D16_UNORM_S8_UINT. The host keeps it as 32-bit float depth with stencil. Compute writes it through unordered views:R16_UNORMviews of the depth plane, andR8_UINTviews of the stencil plane. OurVICTORY_TRACE_TARGETS=1run lists it among the UAVs off0c91b4d2578f5bf(160x90 groups),570f1473f4641b30andbad01f53f53248e5.On main, a colour view of a depth texture is the depth texture itself, because
create_texture_viewkeeps the depth format. So compute writes the depth texture directly. Metal does not support shader writes to a depth texture. On an M4 Pro, a blit copy of the depth plane reads what compute wrote, but a later render pass's depth test does not see it.Fix
NativeHost::depth_twin):R16Unormfor a 16-bit depth texture (the shadow maps);R32Floatfor a 32-bit one. AnR16_UNORMview of a 32-bit plane writes the twin as 32-bit floats.NativeHost::twin_copies), as VIctory'stwin.rsdoes on the D3D12 path:DepthFromDepthStencil).VICTORY_DEPTH_TWINS=0turns it off.Guesses, also in
docs/native-host.md:k / 65535through anR16_UNORMview of the 32-bit plane, the very float its draws rasterise. VIctory's D3D12 path convertsktok * 0x37800080; the host keeps the float the shader stores.R8_UINTviews still reach nothing.Why the default is on
I know you prefer defaults that don't change behaviour for others until more Macs have run them. Here is why I think on is right for this one, and I'll switch it off if you disagree:
VICTORY_PASSES_PER_BUFFER. The cost is copies of the twinned textures only. I have no clean before-and-after frame rate: the run with twins both ways (r164) ran 1.8 to 1.9 world frames a second, and the closest run without twins (r159, before the alias) ran 2.0 to 2.1, with other changes in between.VICTORY_DEPTH_TWINS=1to turn it on.Evidence
One Mac (M4 Pro, 48 GB, Series S, warm cache). The game runs were on our working branch, not on this main: main of 27 November morning, plus a placed-view alias like the one main now has, and other changes of ours.
Tests
native::tests::a_draw_tests_against_the_depth_compute_wrote_through_an_unordered_viewneeds the Shader Converter. In one list, aD32_FLOATtexture gets:tex_filldispatch that writes x / 255 through anR32_FLOATunordered view;LessEqual.728845d1, with only this test added, it fails: the draw lands nowhere (green row[0; 16]).texture_tests::an_unordered_view_of_a_depth_texture_writes_a_colour_twin: the twin is made at the unordered view, not at a colour read before it, and the newer side moves as described.texture_tests::a_depth_twin_and_its_depth_plane_hold_the_same_texels: for DXGI 118 and a 16-bit depth texture, what the twin holds goes into the depth plane and back on the GPU, bit for bit.VICTORY_MSC_DYLIB): the texture tests andnative::tests::a_*, 49 of 49 pass.described_rectangle_list_draw_uses_supplied_triangles,an_indirect_dispatch_mesh_x_draws_the_groups_its_record_holdsanda_drawn_target_is_not_filled_from_title_memory_again. This Mac has no arm64 converter, so their pipelines are not made. All three pass on x86_64 with the converter.cargo xtask policypasses.How to check that the switch takes the old path
With
VICTORY_DEPTH_TWINS=0,depth_twinreturnsNonebefore anything else. No twin is ever made, the twin map stays empty, andtwin_copies/twin_usesreturn at once. The views and passes are exactly main's.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T16:15:23Z.
Merged in
4cf84c83. It was still a draft; I merged it because the change looks complete and is off with VICTORY_DEPTH_TWINS=0. Before pushing I ran the tests (native arm64), Windows clippy, the policy check, a release build, and one headless game run of the exact tree (170 s, Series S): menus at 30 fps, the world entered at about 81 s and kept presenting to the end at about 1 frame a second, 0 GPU errors, no crash. I did not check the lighting result itself. Thanks.