Repository navigation
Conversation
…age (fxgl#51) On Apple10 (M5 Pro, macOS 27.2) a placement sparse depth texture with MTLTextureUsageShaderWrite drops render pass stores to its mapped tiles, so sparse.c's two D32 sparse depth cases read the bound tile as unbound and run.sh stopped build.sh before installing. KosmicKrisp only set the usage for TRANSFER_DST, and nothing writes depth/stencil images from shaders. Full KosmicKrisp repro suite green on an M5 Pro. The patch's commit message is a placeholder for Joey to write. Investigated and drafted with the help of Claude (AI). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fxgl
reviewed
Nov 1, 2026
fxgl
left a comment
Owner
There was a problem hiding this comment.
Thanks for the thorough probe. The fix itself is right. I traced every path in the patched tree (main's 0001-0074 plus #47's 0064), and nothing in KosmicKrisp writes a depth image from a shader:
- depth formats have no storage feature in
kk_format.c; - clears render with STORE;
- all
kk_cmd_copy.cpaths are blit commands; - vk_meta blit and resolve are graphics;
- host image copy runs on the CPU.
So dropping MTLTextureUsageShaderWrite for sparse depth is safe on every GPU, and only sparse images are affected.
Before it can land:
- Number. main now has 0065-0069 and 0071-0074, and #47 takes 0064. Please rename the patch to
0075-…, move the build.sh entry after 0074 and update the subject. It applies cleanly as 0075 on top of everything. - Commit message. The patch subject and body are still the
TODO(Joey)placeholder, and the steamac commit says so too. Mesa's AGENTS.md asks for published text to be written by a person, so please write the subject (kk: …, no em dash) and the body yourself: the cause (Apple10 drops render-pass stores to mapped tiles of placement-sparse depth textures with ShaderWrite), why it's safe, and the repro. Pick the trailer that matches how it was written (Assisted-by:vsGenerated-by:, see main's 0065/0069). - A code comment in
kk_image_layout.cwhere the flag is cleared: 2-3 lines on why. Otherwise it looks accidental on the next rebase; the neighbouring steamac workarounds are all commented. - The KOSMICKRISP.txt line in build.sh, like 0065-0074:
echo " 0075 = steamac: sparse depth images without MTLTextureUsageShaderWrite (Apple10 drops render-pass stores)".
Could you also check on the M5:
- Sparse D32 with
VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT.kk_image_layout.c:68-69adds PixelFormatView there. Your table says using PixelFormatView instead of ShaderWrite "made no difference". If that means stores are lost with RT+Read+PixelFormatView too, sparse depth-only images should drop PixelFormatView as well; a depth view's format always equals the image's. - A
vkCmdCopyBufferToImageinto a bound tile of the sparse D32 image, with read-back, ideally underMTL_DEBUG_LAYER=1. Thesparse.cD32 case never writes by copy, and that is what TRANSFER_DST is for.
Nits:
- Sparse stencil formats are rejected by
kk_sparse.c, so the entry could say "sparse depth images (D16/D32)". Repro: host/moltenvk/repro sparse.cis missing a/.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #51.
Cause
KosmicKrisp gives images with
TRANSFER_DSTusageMTLTextureUsageShaderWrite. On Apple10 (M5 Pro, macOS 27.2), a placement sparse depth texture with that usage drops render pass stores to its mapped tiles: the depth clear (load clear + store) and draw depth writes never reach the heap, while blits read the heap. The bound tile ofsparse.c's D32 cases therefore read 0, like an unbound one.A plain Metal 4 probe (no Vulkan): 256x256 placement sparse texture, 64 KiB pages, tile (0,0) mapped to a placement heap shaped like KosmicKrisp's, render pass clearing it, blit to a buffer:
PixelFormatView usage instead of ShaderWrite, the heap's storage mode, a CPU buffer over the heap and the heap size make no difference.
Fix
Patch 0065: sparse images with a depth or stencil format are created without
MTLTextureUsageShaderWrite. Nothing in KosmicKrisp writes depth/stencil images from shaders (depth formats have no storage image feature; clears render, copies blit). The patch applies on 0001-0063 and on 0001-0064 (#47) alike; itsbuild.shentry will need a one-line rebase against #47's 0064 entry, whichever merges second.Testing (Mac17,16, M5 Pro, macOS 27.2)
sparse—FAIL D32 sparse depth test/writein one and in two render passes (16384 wrong colours and depths: the bound tile), also with the depth case run alone and with only the clear and the copy.sparse: 0 failure(s);REPRO_DRIVER=kosmickrisp host/moltenvk/repro/run.shexits 0 with no failures.sparse.ctests D32 only).Draft: the Mesa patch's commit message is still a placeholder; I'll replace it before marking this ready.
Investigated and written with the help of Claude (AI).
🤖 Generated with Claude Code