Skip to content

feat(shader,gpu): move 16-bit typed buffer channels bit-exactly through unsigned twin views - #407

Open
gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:feat/macos-half-views-mouths
Open

gdemontalivet wants to merge 1 commit into
pragyaangaur:mainfrom
gdemontalivet:feat/macos-half-views-mouths

Conversation

@gdemontalivet

Copy link
Copy Markdown
Contributor

On the console GPU, a typed buffer descriptor carries NUM_FORMAT (FLOAT, UINT, SINT, …) in the descriptor itself rather than in the shader instruction, and deformation/morph shaders (such as facial and mouth blendshape passes) move 16-bit channel patterns bit-exactly through two idioms:

  1. buffer_load_format_d16_* / buffer_store_format_d16_* instructions, or
  2. Whole-dword buffer_load_format_{x,xy,xyz,xyzw} / tbuffer_load_format_* loads whose destination registers are consumed exclusively as 16-bit half-floats (v_cvt_f32_f16 or v_fma_mix* with op_sel_hi set)—expecting the console's UINT view to return zero-extended 16-bit bit patterns in the low half of each VGPR.

When the host binds a 16-bit FLOAT or SINT typed buffer view (R16_FLOAT, R16G16_FLOAT, R16G16B16A16_FLOAT, or _SINT) to a DXIL Buffer<uint4> (VIEW_INTEGER) or Buffer<float4> handle, D3D12 / Metal either converts float values to integer, canonicalizes/flushes subnormal and signaling-NaN payload bits, or mismatches the view's return type—corrupting packed 16-bit vertex deltas and blendshape weights.

What changed

  • Static identification of bit-exact 16-bit buffer descriptor slots (victory-shader/src/emit/half_views.rs, lower.rs, ir.rs, mod.rs, shader_cache.rs):
    • Extract 16-bit view analysis and lowering helpers into emit/half_views.rs (keeping crates/victory-shader/src/emit/lower.rs trimmed to 514,608 B—9,680 B below the 524,288 B policy cap) and add Lower::places_read_as_halves to find (root_slot, table_dword_offset) descriptor places where every static access is either a _format_d16_ buffer op or a whole-dword format load whose results are read exclusively as 16-bit halves (read_only_as_halves, following phis and ignoring lane-preserving partial-EXEC register reads via ir::operand_reads), excluding any place also accessed as plain floats/raw words or any table dynamically indexed at run time.
    • Lower loads/stores on those half_views places through VIEW_INTEGER (Buffer<uint4> / RWBuffer<uint4>) so 16-bit channel bits travel unconverted, and serialize HostShader::half_views in the shader cache (VSH3).
  • Unsigned 16-bit twin buffer views at table binding time (victory-gpu/src/descriptor/host.rs, descriptor.rs, draw.rs):
    • Map 16-bit FLOAT and SINT buffer SRVs/UAVs (placed and unplaced: formats 10/14 -> 12 R16G16B16A16_UINT, 34/38 -> 36 R16G16_UINT, 54/59 -> 57 R16_UINT) to unsigned integer twin views via descriptor::host::half_view when building fresh dynamic descriptor tables for shaders with non-empty half_views, sizing the dynamic table allocation to cover half_views slots past UsedResource range starts and logging any format whose console conversion is non-identity (half_inexact).

How it was tested

  • Apple M5 Max, CrossOver Preview with D3DMetal (wave32=true), isolated test bottle:
    • cargo test --workspace (native macOS): all passed (0 failed).
    • Windows + D3DMetal (--test-threads=1):
      • victory-shader: all passed (0 failed), including hardware/WARP execution tests verifying bit-exact preservation of subnormals, negative zero, NaN payloads, and signed 16-bit patterns across d16 and whole-dword half-float loads/stores, mixed-access exclusion, and dynamic-table exclusion.
      • victory-gpu: 77 descriptor & draw D3DMetal tests passed (0 failed), including only_16_bit_float_and_signed_buffer_views_get_an_unsigned_twin and a_fresh_table_holds_the_half_views_past_its_range_starts.
    • cargo xtask policy (260 files ok, lower.rs at 514,608 B with 9,680 B headroom below 524,288 B), git diff --check, and cargo clippy --workspace --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings (with and without --features diagnostics, 0 warnings): clean. All test inputs are synthetic.

Live M5 Max Verification (Combined Build on CrossOver Preview + D3DMetal)

  • In a combined warm-cache 720p opening-sequence run on Apple M5 Max (CrossOver Preview + D3DMetal, wave32=true), the runtime reached and sustained the 3D world through +8, +24, +48, +90 at 1.5–1.8 FPS (549.7–672.1 ms/frame on 1,021–1,258 draws/frame, 1.275 FPS overall across +8..+90) with 0 2.48 s allocation stalls, 7.2–9.0 ms/frame GUARDS lock hold time (down from 4,887 ms/frame before unlocking GUARDS), 149–154 MB/frame buffer copy volume, 0 DirectStorage decompression or access-violation failures, and 38/38 over-32 KiB aligned mesh/pixel pairs linked with 0 host mesh refusals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant