vkback: fix viewdesc CUBE_ARRAY/ArraySize clamping, SRV PlaneSlice stencil, and X8 default format #196
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/vktory6--VKtory!196
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-196"
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?
@Mhyster on GitHub · 2026-12-02 07:11 UTC · original
Mhyster:fix/tex-viewdesc-cube-stencil-x8→main· +52 −23 · 2 files · 1 commits · openWhat
Fixes four D3D12-to-Vulkan texture view decoding bugs in
greenfield/vkback/src/viewdesc.rs(range,components):CUBE_ARRAYNumCubesand handle0/u32::MAX(viewdesc.rsrange): previously computedb.saturating_mul(6)unclamped, yieldinglayerCount = 0whenNumCubes == 0(VUID-VkImageSubresourceRange-layerCount-01721),u32::MAXwhenNumCubes == u32::MAX(VUID-VkImageViewCreateInfo-subresourceRange-01483), or exceedinglayers - first. Now clamps to whole cubes(layers - first) / 6 * 6and treats0/u32::MAXas the remaining whole cubes.ArraySize == 0/u32::MAXas remaining layers (viewdesc.rsrange): previouslyspan(first, 0)returned0(layerCount = 0). Now matchesrestandtargetby resolving0oru32::MAXtolayers.saturating_sub(first).PlaneSlice == 1for stencil aspect (viewdesc.rscomponents): previously only checked stencil view formats (22 | 47 | 120), so single-channel stencil SRVs (e.g.R8_UINTwithPlaneSlice == 1) boundDEPTH_BITinstead ofSTENCIL_BIT. Now selectsSTENCIL_ASPECTviaoffset_of!(Tex2dSrv, plane)/offset_of!(Tex2dArraySrv, plane)while keeping identity swizzle (stencil in R) for non-X*_G8formats, and(ZERO, R, ZERO, ZERO)for22 | 47 | 120.Format == 0(DXGI_FORMAT_UNKNOWN) (viewdesc.rscomponents,slotwrite.rswrite_view): passesimg.desc.formatas fallback so default-format SRVs ofB8G8R8X8_UNORM(88) /B8G8R8X8_UNORM_SRGB(93) still forcealpha = ONE.Reproduces D3D12 texture SRV/UAV subresource ranges, stencil plane selection, and
X8alpha semantics.The reference
vkd3d-protonlibs/vkd3d/resource.c:vkd3d_setup_texture_srv_view(resource.c:7098, 7107, 7131-7140): setsaspect_mask = vk_image_aspect_flags_from_d3d12(resource->format, desc->Texture2D[Array].PlaneSlice)and handlesVK_REMAINING_ARRAY_LAYERSbefore multiplyingNumCubes * 6.vk_image_aspect_flags_from_d3d12(resource.c:2948-2967): mapsPlaneSlice == 1on a depth-stencil image toVK_IMAGE_ASPECT_STENCIL_BIT.init_default_texture_view_desc(resource.c:5722-5732): resolvesview_format == 0fromresource->desc.Format.vkd3d_set_view_swizzle_for_format(resource.c:5583-5637): applies(ZERO, R, ZERO, ZERO)only forvk_aspect_mask == VK_IMAGE_ASPECT_STENCIL_BITformats and forcesa = ONEforB8G8R8X8_UNORM[_SRGB].allowed_swizzle == false);PlaneSlice == 1without a stencil-swizzle format selectsSTENCIL_ASPECTwithout overriding the R channel.Evidence
greenfield/vkback/src/viewdesc.rs(components_follow_vkd3d,array_and_multisampled_dimensions_decode): coverCUBE_ARRAYclamping and0/u32::MAX,ArraySize0/u32::MAX, 2D and 2D-arrayPlaneSlice == 1(R8_UINTkeeps identity swizzle withSTENCIL_ASPECT;X32_TYPELESS_G8X24_UINTkeeps(ZERO, R, ZERO, ZERO)), andd[0] == 0inheritingB8G8R8X8_UNORM/B8G8R8X8_UNORM_SRGBalphaONE.cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)(168 passed, 3 ignored; 6/6 policy tests)cargo clippy --all-targets --locked -- -D warningson root native crates,greenfield,greenfield/wine, andgreenfield/vkback/translate.frames.py) could not be run in this session (no live game run performed);cargo xwin clippyruns in GitHub Actions CI.Checklist (docs/AGENTS.md)
docs/TASKS.mdnot edited, the fixed item named above (rule 29)unsafeblock has a// SAFETY:comment; no raw pointer around the borrow checker (rule 36)TRANSLATOR_VERSIONbumped if the translator's output changes (rule 27)@vktory6 on GitHub · 2026-12-02 15:28 UTC · original
Thanks. This bundles four fixes (rule 31), so please split it. What to keep and what to change:
PlaneSlice == 1selecting the stencil aspect (vkd3dvk_image_aspect_flags_from_d3d12), and view format 0 inheriting the resource format for the X8 alpha swizzle (vkd3dinit_default_texture_view_desc).UINT_MAXshould mean "the rest", as in vkd3d (resource.c7113 and 7144–7146).ArraySize == 0as "the rest" has no console source, so it should fail loudly (rules 6 and 9b).View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.