From 40be61a890cd9799fad476d086b8196945db799c Mon Sep 17 00:00:00 2001 From: Roland Edi Date: Tue, 1 Dec 2026 16:37:59 +0000 Subject: [PATCH] shader: combine mesh f16 mixlo/mixhi halves --- src/gfx1013_direct_mesh.inl | 5 ++++- tests/native_direct_mesh_check.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/gfx1013_direct_mesh.inl b/src/gfx1013_direct_mesh.inl index abc97056b8..575612d031 100644 --- a/src/gfx1013_direct_mesh.inl +++ b/src/gfx1013_direct_mesh.inl @@ -18,7 +18,10 @@ NativeComputeShader lower_mesh(const string &code, const MeshStageLayout &layout DirectCompute alu{emitter}; // A container stage reflects its table records; an IDXEN raw load takes its record stride from them. alu.graphics_interface=reflected; - alu.graphics_half_writes=layout.texture_heap_slot_map; + // The mesh tracks which half of a VGPR a 16-bit write defined: a mixed + // f16 fma writes one half, and a later read may consume the whole word + // only when both halves have been written. + alu.graphics_half_writes=true; GuestShaderStage fixed_outputs{}; fixed_outputs.output_signature.push_back({"SV_Position",0,1,3,0,15,15}); GraphicsStage graphics{reflected ? *reflected : fixed_outputs,alu,false}; diff --git a/tests/native_direct_mesh_check.py b/tests/native_direct_mesh_check.py index 0816a19356..7fa7767e90 100644 --- a/tests/native_direct_mesh_check.py +++ b/tests/native_direct_mesh_check.py @@ -37,6 +37,19 @@ def _sop1(op, dst, src): return 0xBE800000 | ((dst & 0x7F) << 16) | ((op & 0xFF) << 8) | (src & 0xFF) +def assert_export_column(text, value, column): + """A 32-bit SSA value reaches one POS0 column through uitofp and bitcasts.""" + value_re = r"%[\w.]+" + as_float = re.search(rf"(?P{value_re}) = uitofp i32 {re.escape(value)} to float\n", text) + assert as_float, text + bits = re.search(rf"(?P{value_re}) = bitcast float {re.escape(as_float['float'])} to i32\n", text) + assert bits, text + back = re.search(rf"(?P{value_re}) = bitcast i32 {re.escape(bits['bits'])} to float\n", text) + assert back, text + assert re.search(rf"call void @dx\.op\.storeVertexOutput\.f32\(i32 171, i32 \d+, i32 0, i8 {column}, " + rf"float {re.escape(back['back'])},", text), text + + def _inline_u32(value): if 0 <= value <= 64: return 128 + value @@ -741,6 +754,18 @@ def skip_load(body, seed=True): 'graphics register read includes undefined bits: 276') run('mesh-full-read-of-partial-half',half_frontend+[0x7e340314]+program, 'graphics register read includes undefined bits: 276') + # A mixed f16 pair writes the low and high halves of one VGPR; only + # both together make the whole word readable. + half_pair = [0xcc210014, 242 | (242 << 9) | (242 << 18), # v_fma_mixlo_f16 v20, 1, 1, 1 + 0xcc220014, 242 | (242 << 9) | (242 << 18)] # v_fma_mixhi_f16 v20, 1, 1, 1 + layout.write_text('mesh1 128 3 1 2 128 64') + text = run('mesh-mixed-half-pair', program[:5] + half_pair + [0x7e020314] + program[6:]) + assert 'legacyF32ToF16' in text + packed = re.findall(r'(%[\w.]+) = or i32 ', text) + assert len(packed) >= 2, text + assert_export_column(text, packed[-1], 0) + run('mesh-mixed-half-single', program[:5] + half_frontend + [0x7e020314] + program[6:], + 'graphics register read includes undefined bits: 276') # GPU-selected slot through a view token: the heap byte offset is a dword read from a root-table buffer SRV, # times 32. The token at that address names the view; the shader checks it before reading the heap. select_word = [0xbe910380, # s_mov_b32 s17, 0 (table high word)