gpu, metal: bind cube/3D views, fix UAV mip words, and wire heap shadow samplers #577
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/577"
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 Sheffy007 on 2026-11-28T06:16:01Z.
Closes #573
Refs #258, #521
cc @Olima34
Summary
Fixes four native GPU/Metal view and sampler bugs affecting world lighting, shadow comparisons, cubemap probes, and UAV size queries:
MTLTextureTypereinterpretation (victory-backend,victory-gpu::native,victory-metal):descriptors::decode/texture_viewnow decodeTEXTURE_1D..TEXTURE_CUBE_ARRAY(2..=10) with explicitViewDim(D2,D2Array,D3,Cube,CubeArray), mip ranges (MostDetailedMip,MipLevels/MipSlice), and face/layer ranges ((0, 6)forTEXTURE_CUBE,(First2DArrayFace, 6 * NumCubes)forTEXTURE_CUBE_ARRAY).Metal::create_texture_viewreinterprets 2D/array backing textures toMTLTextureType::TypeCube,TypeCubeArray,Type2D, orType2DArray(andType3Dmip ranges), while validating dimensions, slice counts, multisampling, and buffer-backed textures before callingnewTextureViewso stale or mismatched descriptors returnErrinstead of tripping Metal ObjC assertions.D3D12_SAMPLER_DESC(victory-gpu::sampler,victory-gpu::native::descriptors,victory-metal):MTLSamplerDescriptordefaultscompareFunctiontoMTLCompareFunction::Never, andSamplerDescpreviously omittedcompare,lod_min,lod_max, andAddress::MirrorOnce. Every heap comparison sampler (CreateSamplerXwithwords[16]inLESS..=ALWAYSorCreateSamplerwithD3D12_FILTER_COMPARISON_*) evaluatedNever(0.0, 100% shadowed) onimage_sample_c*/image_gather4_c*.compare,lod_min,lod_max(includingmip == 0clamping tomin_lod),Address::MirrorOnce(MirrorClampToEdge), and 13-dwordView::Sampler(d3d12_fields) intoSamplerDescanddynamic_sampler_descriptor.MipSliceindescriptor::image_words(victory-gpu::descriptor):D3D12_UNORDERED_ACCESS_VIEW_DESC,MipSliceis atd[2](d[4]holdsArraySize/WSize/0).image_wordspreviously readd[4]on unordered views, corruptingimage_get_resinfodimensions onRWTexture2D(mip > 0),RWTexture2DArray, andRWTexture3D(WSize = u32::MAX).Verification
cargo test -p victory-metal --locked -- --test-threads=1cargo test -p victory-gpu --lib descriptor::tests:: --locked -- --test-threads=1cargo test -p victory-gpu --lib native::descriptors::tests:: --locked -- --test-threads=1cargo test -p victory-gpu --lib native::tests::cube_tests:: --locked -- --test-threads=1(end-to-end GFX10 -> MSC -> Metal GPU tests sampling all 6TextureCubefaces and evaluatingimage_sample_c_lzwith bothConsoleSamplerandD3D12_SAMPLER_DESCcomparison samplers)cargo clippy --workspace --all-targets --locked --target x86_64-pc-windows-gnullvm -- -D warnings(plain and--all-features)cargo xtask policyImported from LakshanSivakumar/Native-Victory-macOS. Originally posted by AnastasisKon on 2026-11-28T18:08:57Z.
Review: APPROVED
Reviewed and verified locally on head
c734a4fd(worktree /private/tmp/review-577):Checked the layouts against the D3D12 structs: UAV MipSlice at word 2 (image_words fix is right — d[4] holds ArraySize/WSize), SRV/UAV dimension decoding for 1D..CubeArray with the correct per-dimension mip/layer words, cube = 6 faces and CubeArray = 6*NumCubes with u32::MAX passthrough, comparison funcs 1..=8 mapped to Never..Always with mode==0 gate, D3D12_SAMPLER_DESC 13-dword filter bit decode (aniso/reduction bits, ComparisonFunc at word 6), Address 5 = MirrorOnce -> MirrorClampToEdge. The Metal side validates buffer-backed, 3D, multisampled, and non-square/short cube backing before newTextureView, so bad descriptors now return Err instead of tripping ObjC assertions, and the dim: None case reinterprets a cube as a 2D array when the view asks for faces individually. Approving — this unblocks #573 and the shadow/cubemap lighting paths behind #258/#521.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.