gpu, metal: bind TextureCube/CubeArray/3D/2D views with matching MTLTextureType, fix UAV MipSlice in image_words, and decode D3D12 samplers #573

Open
opened 2026-11-28 05:45:43 +00:00 by Sheffy007 · 2 comments
Sheffy007 commented 2026-11-28 05:45:43 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-28T05:45:43Z.


Refs #258, #521

Problem

  1. Cube, cube-array, 3D, and 2D/array texture views are bound with the wrong MTLTextureType or dropped mip/format overrides on Metal:
    • victory-shader lowers GFX10 image_sample ... dim:CUBE to DXIL TextureCube (compiled by Metal Shader Converter to MSL texturecube), while Metal::create_texture allocates 6-face cubemap resources as MTLTextureType::Type2DArray.
    • native::descriptors::decode only routed TEXTURE_2D (4) and TEXTURE_2D_ARRAY (5) through texture_view; TEXTURE_CUBE (9), TEXTURE_CUBE_ARRAY (10), TEXTURE_3D (8), TEXTURE_1D (2), TEXTURE_1D_ARRAY (3), and TEXTURE_2DMS* (6, 7) fell through with mips: None, slices: None (losing MipSlice / mip ranges, cube-array slice ranges, and format casts on RWTexture3D / Texture3D / TextureCube*).
    • Even when create_texture_view ran (e.g. for placed views), Metal::create_texture_view kept let ty = t.tex.textureType(), never creating MTLTextureType::TypeCube, MTLTextureType::TypeCubeArray, MTLTextureType::Type2D (over a Type2DArray slice), or MTLTextureType::Type2DArray (over a 1-slice Type2D), and tex_slices in Metal blits treated TypeCube / TypeCubeArray as 1 slice instead of 6 / 6 * arrayLength.
  2. descriptor::image_words reads d[4] instead of d[2] as MipSlice on UAVs:
    • In D3D12_UNORDERED_ACCESS_VIEW_DESC, MipSlice is at d[2] while d[4] holds ArraySize (Texture2DArray) / WSize (Texture3D, often 0xFFFF_FFFF) / 0 (Texture2D). image_words used (true, _) => (ty, d[4], 1), corrupting descriptor-word size queries on RWTexture2D mips > 0, RWTexture2DArray, and RWTexture3D.
  3. Plain 13-dword D3D12_SAMPLER_DESC (CreateSampler, View::Sampler) is not decoded on the native host:
    • Middleware/title code calling ID3D12Device::CreateSampler instead of CreateSamplerX fails descriptors::decode (a descriptor was not mirrored).

Proposed Fix

  • Add ViewDim (D2, D2Array, D3, Cube, CubeArray) to ViewDesc and carry view dimension, mip ranges, and slice/face ranges through descriptors::decode and NativeHost::mirror into Metal::create_texture_view (and fix MTLTexture slice counting for TypeCube, TypeCubeArray, Type1DArray, and Type2DMultisampleArray).
  • Fix descriptor::image_words to read d[2] (MipSlice) for unordered == true.
  • Decode 13-dword D3D12_SAMPLER_DESC (View::Sampler) in sampler::d3d12_fields and native::descriptors::decode.
  • Add unit tests and an end-to-end Metal GPU shader test sampling all 6 faces of a TextureCube (v_cubeid_f32/v_cubesc_f32/v_cubetc_f32/v_cubema_f32 + image_sample ... dim:CUBE).
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6659916315 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/573). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-28T05:45:43Z. --- Refs #258, #521 ### Problem 1. **Cube, cube-array, 3D, and 2D/array texture views are bound with the wrong `MTLTextureType` or dropped mip/format overrides on Metal:** - `victory-shader` lowers GFX10 `image_sample ... dim:CUBE` to DXIL `TextureCube` (compiled by Metal Shader Converter to MSL `texturecube`), while `Metal::create_texture` allocates 6-face cubemap resources as `MTLTextureType::Type2DArray`. - `native::descriptors::decode` only routed `TEXTURE_2D` (`4`) and `TEXTURE_2D_ARRAY` (`5`) through `texture_view`; `TEXTURE_CUBE` (`9`), `TEXTURE_CUBE_ARRAY` (`10`), `TEXTURE_3D` (`8`), `TEXTURE_1D` (`2`), `TEXTURE_1D_ARRAY` (`3`), and `TEXTURE_2DMS*` (`6`, `7`) fell through with `mips: None, slices: None` (losing `MipSlice` / mip ranges, cube-array slice ranges, and format casts on `RWTexture3D` / `Texture3D` / `TextureCube*`). - Even when `create_texture_view` ran (e.g. for placed views), `Metal::create_texture_view` kept `let ty = t.tex.textureType()`, never creating `MTLTextureType::TypeCube`, `MTLTextureType::TypeCubeArray`, `MTLTextureType::Type2D` (over a `Type2DArray` slice), or `MTLTextureType::Type2DArray` (over a 1-slice `Type2D`), and `tex_slices` in `Metal` blits treated `TypeCube` / `TypeCubeArray` as 1 slice instead of `6` / `6 * arrayLength`. 2. **`descriptor::image_words` reads `d[4]` instead of `d[2]` as `MipSlice` on UAVs:** - In `D3D12_UNORDERED_ACCESS_VIEW_DESC`, `MipSlice` is at `d[2]` while `d[4]` holds `ArraySize` (`Texture2DArray`) / `WSize` (`Texture3D`, often `0xFFFF_FFFF`) / `0` (`Texture2D`). `image_words` used `(true, _) => (ty, d[4], 1)`, corrupting descriptor-word size queries on `RWTexture2D` mips `> 0`, `RWTexture2DArray`, and `RWTexture3D`. 3. **Plain 13-dword `D3D12_SAMPLER_DESC` (`CreateSampler`, `View::Sampler`) is not decoded on the native host:** - Middleware/title code calling `ID3D12Device::CreateSampler` instead of `CreateSamplerX` fails `descriptors::decode` (`a descriptor was not mirrored`). ### Proposed Fix - Add `ViewDim` (`D2`, `D2Array`, `D3`, `Cube`, `CubeArray`) to `ViewDesc` and carry view dimension, mip ranges, and slice/face ranges through `descriptors::decode` and `NativeHost::mirror` into `Metal::create_texture_view` (and fix `MTLTexture` slice counting for `TypeCube`, `TypeCubeArray`, `Type1DArray`, and `Type2DMultisampleArray`). - Fix `descriptor::image_words` to read `d[2]` (`MipSlice`) for `unordered == true`. - Decode 13-dword `D3D12_SAMPLER_DESC` (`View::Sampler`) in `sampler::d3d12_fields` and `native::descriptors::decode`. - Add unit tests and an end-to-end Metal GPU shader test sampling all 6 faces of a `TextureCube` (`v_cubeid_f32`/`v_cubesc_f32`/`v_cubetc_f32`/`v_cubema_f32` + `image_sample ... dim:CUBE`).
Sheffy007 commented 2026-11-28 05:45:44 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Sheffy007 on 2026-11-28T05:45:44Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7234869026 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/573#issuecomment-7234869026). Originally posted by [Sheffy007](https://github.com/Sheffy007) on 2026-11-28T05:45:44Z. --- /claim
github-actions[bot] commented 2026-11-28 05:45:54 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-28T05:45:54Z.


Claimed by @Sheffy007. Open a draft pull request with Refs #573 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7234870792 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/573#issuecomment-7234870792). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T05:45:54Z. --- Claimed by @Sheffy007. Open a draft pull request with `Refs #573` in its description within 24 hours, or the claim expires.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#573
No description provided.