diff --git a/docs/experiments.md b/docs/experiments.md index b50a29d1f0..ea379c6417 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -5782,11 +5782,11 @@ The view must be live and describe format 75 (`BUF_FMT_32_32_32_32_UINT`) with i Run `ctest --preset dev -R '^compute_(heap_store_controls|store_aot_heap_view_store_(warp|hardware))$' --output-on-failure`. The fixture checks all 320 readback words across twelve cases. These include distinct live ranges, one texel ending exactly at the u0 limit, and a partial texel that must leave the sentinel intact. Eight mutations exercise the base, stride, record count, format, lifetime, output extent and slot limit. Removing the per-index extent check lets the next thread write past the last complete texel. -### Packed D16 heap-view stores to FLOAT4 +### Packed D16 heap-view stores to FLOAT4 and FLOAT1 -With the same `--heap-store-view` binding, gfx1013 `buffer_store_format_d16_xyzw` reads X/Y from the low/high halves of the first VGPR and Z/W from the second. A live identity `BUF_FMT_32_32_32_32_FLOAT` view (format 77) receives four binary32 words. Two source VGPRs still require 16 writable bytes in the destination. An ordinary UINT4 record selected by this opcode leaves the sentinel region untouched. [AMD RDNA 2 instruction set](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [HLSL half-to-float conversion](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/f16tof32) +With the same `--heap-store-view` binding, gfx1013 `buffer_store_format_d16_xyzw` reads X/Y from the low/high halves of the first VGPR and Z/W from the second. A live identity `BUF_FMT_32_32_32_32_FLOAT` view (format 77) receives four binary32 words. Two source VGPRs still require 16 writable bytes in the destination. `buffer_store_format_d16_x` takes one source VGPR, converts its low 16 bits (`& 0xffffu`) via `f16tof32`, and writes one 4-byte binary32 word into a live identity `BUF_FMT_32_FLOAT` view (format 22, `0x01016fac`), enforcing 4-byte offset/stride/base alignment and `(bytes - view.x - offset - 4u) / stride` bounds without a raw UAV read-modify-write. Ordinary UINT views or mismatched four-channel/single-channel FLOAT views leave the sentinel region untouched, and `d16_xy` / `d16_xyz` remain refused under `--heap-store-view`. [AMD RDNA 2 instruction set](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [HLSL half-to-float conversion](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/f16tof32) -The heap-store CTest selection above runs both programs. The D16 fixture checks twelve cases with 320 words each. Its reference includes consecutive half values starting at 1, a negative value, the smallest positive half subnormal and negative zero. Eleven compiled shader mutations check addressing, view selection and conversion, including using the low X half for Y, taking W from the wrong VGPR and writing packed values directly. +The heap-store CTest selection above runs all three programs (`UINT4`, `D16-to-FLOAT4`, and `D16_X-to-FLOAT1`). Each D16 fixture checks 320 words across its heap-view cases (with `D16_X` additionally checking four binary16 payload patterns with poisoned high halves: `1.0`..`1.00293`, `-2.0`.., minimum positive subnormal + `+0.0`, and `-0.0` + negative subnormals, plus `UINT1` and `FLOAT4` mismatch rejections and untouched adjacent sentinel dwords). Eleven compiled shader mutations check addressing, view selection, and half-float extraction, including swapping high for low bits, checking the wrong format word, and writing packed values directly. ### Heap-view buffer loads diff --git a/tests/compute_heap_store_check.py b/tests/compute_heap_store_check.py index e3f5080974..e6267494dc 100644 --- a/tests/compute_heap_store_check.py +++ b/tests/compute_heap_store_check.py @@ -11,10 +11,13 @@ GROUP = (4, 1, 1) WORDS = 320 TABLE_BYTE = 256 -UINT4 = 0x0104BFAC # gfx10 format 75, identity XYZW selectors and RESOURCE_LEVEL set +FLOAT1 = 0x01016FAC # gfx10 format 22 (BUF_FMT_32_FLOAT), identity selectors and RESOURCE_LEVEL set +UINT1 = 0x01014FAC # gfx10 format 20 (BUF_FMT_32_UINT) +UINT4 = 0x0104BFAC # gfx10 format 75, identity XYZW selectors and RESOURCE_LEVEL set FLOAT4 = 0x0104DFAC STORE = "buffer_store_format_xyzw v[10:13], v8, s[20:23], 0 idxen offset:4" D16_STORE = "buffer_store_format_d16_xyzw v[10:11], v8, s[20:23], 0 idxen offset:4" +D16_X_STORE = "buffer_store_format_d16_x v10, v8, s[20:23], 0 idxen offset:4" SETUP = [ "s_mov_b32 s12, s7", "s_mov_b32 s13, 0", "s_load_dwordx4 s[20:23], s[12:13], 0x30", "s_load_dwordx4 s[16:19], s[12:13], 0x40", "v_lshl_add_u32 v8, s11, 2, v0", @@ -27,8 +30,18 @@ D16_PROGRAM = SETUP + [ "v_xor_b32_e32 v10, 0xc0003c00, v8", "v_mov_b32_e32 v11, 0x80000001", D16_STORE, "s_endpgm", ] +D16_X_PROGRAM = SETUP + [ + "v_xor_b32_e32 v10, s25, v8", D16_X_STORE, "s_endpgm", +] # 0x3c00..0x3c03 are consecutive binary16 values starting at 1.0. D16_X = (0x3f800000, 0x3f802000, 0x3f804000, 0x3f806000) +# High half 0x4200 poisons each word so leaking high bits or missing & 0xffffu shifts fails readback. +D16_X_PAYLOADS = ( + ("positive 1.0..", 0x42003c00, D16_X), + ("negative -2.0..", 0x4200c000, (0xc0000000, 0xc0002000, 0xc0004000, 0xc0006000)), + ("min positive subnormal and +0", 0x42000001, (0x33800000, 0x00000000, 0x34400000, 0x34000000)), + ("-0 and negative subnormals", 0x42008000, (0x80000000, 0xb3800000, 0xb4000000, 0xb4400000)), +) # V# words 0..3 and live state, then the expected *word addresses* of the four component stores. # The addresses are literal to keep the reference independent of the generated address calculation. CASES = ( @@ -45,6 +58,21 @@ ("base past the declared u0 extent", (640, 24 << 16, 4, UINT4, 1), ()), ("live slot beyond declared count", (12, 24 << 16, 4, UINT4, 1), ()), ) +# 4-byte FLOAT1 records leaving adjacent dwords at SENTINEL so wider writes fail readback. +D16_X_CASES = ( + ("four float1 records", (12, 8 << 16, 4, FLOAT1, 1), (4, 6, 8, 10)), + ("second base and short record count", (116, 12 << 16, 2, FLOAT1, 1), (30, 33)), + ("released view", (12, 8 << 16, 4, FLOAT1, 2), ()), + ("last complete float1 texel in u0", (504, 8 << 16, 4, FLOAT1, 1), (127,)), + ("partial float1 texel at end of u0", (508, 8 << 16, 4, FLOAT1, 1), ()), + ("wrong single-channel UINT1 format", (12, 8 << 16, 4, UINT1, 1), ()), + ("offset plus 4-byte float1 wider than stride", (12, 4 << 16, 4, FLOAT1, 1), ()), + ("misaligned base", (14, 8 << 16, 4, FLOAT1, 1), ()), + ("misaligned stride", (12, 6 << 16, 4, FLOAT1, 1), ()), + ("unsupported high address", (12, (8 << 16) | 1, 4, FLOAT1, 1), ()), + ("base past the declared u0 extent", (640, 8 << 16, 4, FLOAT1, 1), ()), + ("live slot beyond declared count", (12, 8 << 16, 4, FLOAT1, 1), ()), +) VIEW = (0, TABLE_BYTE, len(CASES) - 1, WORDS * 4, 512) BINDING = dict(table_reg=7, descriptor_offset=0x30, constant_descriptor=0x40, source_descriptor=0x50, group_reg=11) @@ -55,30 +83,54 @@ def lower(program=PROGRAM, **options): def controls(): assert base.aot.descriptor_format_word(75) == UINT4 + assert base.aot.descriptor_format_word(22) == FLOAT1 + assert base.aot.descriptor_format_word(20) == UINT1 # Pin the translator call here. draw() exercises the generated guards against actual UAV contents. assert "store_heap_words4(params[0].x, tid.x, 4u, false, uint4(tid.x," in lower() assert "store_heap_words4(params[0].x, tid.x, 4u, true," in lower(D16_PROGRAM) + d16x_hlsl = lower(D16_X_PROGRAM) + assert "store_heap_word_d16(params[0].x, tid.x, 4u, (params[0].y ^ tid.x));" in d16x_hlsl + assert f"{FLOAT1:#x}u" in d16x_hlsl + assert "store_heap_words4(" not in d16x_hlsl and "outputData.Load(" not in d16x_hlsl refuses = base.rejects refuses("Unsupported formatted buffer store target or address mode", lower, heap_store_view=None) - refuses("Invalid heap store view binding", lower, stride=24) - refuses("Invalid heap store view binding", lower, heap_view=VIEW) + refuses("Unsupported formatted buffer store target or address mode", lower, D16_X_PROGRAM, heap_store_view=None) + refuses("Invalid heap store view binding", lower, D16_X_PROGRAM, stride=8) + refuses("Invalid heap store view binding", lower, heap_store_view=VIEW, stride=24) + refuses("Invalid heap store view binding", lower, heap_store_view=VIEW, heap_view=VIEW) refuses("Invalid heap view binding", lower, source_descriptor=None) refuses("Invalid heap view binding", lower, heap_store_view=(0, TABLE_BYTE, 11, TABLE_BYTE + 32, 512)) refuses("Invalid heap store view output size", lower, heap_store_view=(*VIEW[:4], 511)) refuses("Heap store view requires exactly one formatted UAV store", lower, PROGRAM[:-1] + [STORE.replace("offset:4", "offset:24"), "s_endpgm"]) refuses("Heap store view slot constant is not ready", lower, PROGRAM[:7] + PROGRAM[8:]) + refuses("Heap store view slot constant is not ready", lower, + base.variant(D16_X_PROGRAM, ("s_buffer_load_dwordx4 s[24:27], s[16:19], null", + "s_buffer_load_dword s25, s[16:19], 0x4"))) + refuses("Unverified ALU operand", lower, D16_X_PROGRAM[:7] + D16_X_PROGRAM[8:]) refuses("Heap store view requires buffer_store_format_xyzw", lower, base.variant(PROGRAM, (STORE, STORE.replace("xyzw v[10:13]", "xy v[10:11]")))) refuses("Heap store view requires buffer_store_format_xyzw", lower, base.variant(D16_PROGRAM, (D16_STORE, D16_STORE.replace("d16_xyzw", "d16_xyz")))) + refuses("Heap store view requires buffer_store_format_xyzw", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace("d16_x", "d16_xy")))) + refuses("Heap store view requires buffer_store_format_xyzw", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace("d16_x", "x")))) refuses("Unverified raw UAV store", lower, base.variant(D16_PROGRAM, (D16_STORE, D16_STORE.replace("v[10:11]", "v[10:13]")))) + refuses("Unverified raw UAV store", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace("v10", "v[10:11]")))) + refuses("Unverified raw UAV store", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace("offset:4", "offset:2")))) refuses("Unsupported formatted buffer store target or address mode", lower, base.variant(PROGRAM, (STORE, STORE.replace(" idxen", " offen")))) + refuses("Unsupported formatted buffer store target or address mode", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace(" idxen", " offen")))) refuses("Unverified raw UAV store", lower, base.variant(PROGRAM, (STORE, STORE.replace("s[20:23]", "s[16:19]")))) refuses("Heap store view needs a formatted store indexed by dispatch thread ID", lower, base.variant(PROGRAM, (STORE, STORE.replace(", v8,", ", v12,")))) + refuses("Heap store view needs a formatted store indexed by dispatch thread ID", lower, + base.variant(D16_X_PROGRAM, (D16_X_STORE, D16_X_STORE.replace(", v8,", ", v12,")))) def verify_binary(directory, code, library, program=PROGRAM): @@ -92,13 +144,15 @@ def verify_binary(directory, code, library, program=PROGRAM): assert output.read_text(encoding="ascii") == expected -def draw(directory, compiler, renderer, backend, d16): - source = lower(D16_PROGRAM if d16 else PROGRAM) +def draw(directory, compiler, renderer, backend, mode): + program = {"uint4": PROGRAM, "d16_xyzw": D16_PROGRAM, "d16_x": D16_X_PROGRAM}[mode] + cases = D16_X_CASES if mode == "d16_x" else CASES + source = lower(program) table = [0] * WORDS - for slot, (_, record, _) in enumerate(CASES): + for slot, (_, record, _) in enumerate(cases): start = TABLE_BYTE // 4 + slot * 8 table[start:start + 5] = record - if d16: + if mode == "d16_xyzw": table[start + 3] = FLOAT4 if record[3] == UINT4 else UINT4 hlsl, cso = directory / "store.hlsl", directory / "store.cso" @@ -106,46 +160,72 @@ def compile_shader(text): hlsl.write_text(text, encoding="ascii") subprocess.run([compiler, "-T", "cs_6_0", "-E", "main", "-Fo", cso, hlsl], check=True) - def run(slot): + def run(slot, payload=D16_X_PAYLOADS[0][1], expected_x=D16_X, table_words=table): result = [base.SENTINEL] * WORDS - for thread, start in enumerate(CASES[slot][2]): - # D16 y, z, w are -2, the smallest positive binary16 subnormal, and negative zero. - result[start:start + 4] = ([D16_X[thread], 0xc0000000, 0x33800000, 0x80000000] if d16 else - [thread, 0x12345678, 0x80000001, 0x3F800001]) + for thread, start in enumerate(cases[slot][2]): + if mode == "d16_x": + result[start] = expected_x[thread] + elif mode == "d16_xyzw": + # D16 y, z, w are -2, the smallest positive binary16 subnormal, and negative zero. + result[start:start + 4] = [D16_X[thread], 0xc0000000, 0x33800000, 0x80000000] + else: + result[start:start + 4] = [thread, 0x12345678, 0x80000001, 0x3F800001] case = directory / "store.case" - case.write_bytes(struct.pack("<321I", 1, *result) + struct.pack("<16I", slot, *([0] * 15)) - + struct.pack("<320I", *table)) + case.write_bytes(struct.pack("<321I", 1, *result) + struct.pack("<16I", slot, payload, *([0] * 14)) + + struct.pack("<320I", *table_words)) return subprocess.run([renderer, backend, "--compute-store-case", cso, case], capture_output=True, text=True) compile_shader(source) - for slot, (label, _, _) in enumerate(CASES): + for slot, (label, _, _) in enumerate(cases): result = run(slot) if result.returncode == 77 and backend == "hardware": return 77 - assert result.returncode == 0, (label, result.stderr) + assert result.returncode == 0, (mode, label, result.stderr) + extra = 0 + if mode == "d16_x": + for label, payload, want in D16_X_PAYLOADS[1:]: + result = run(0, payload=payload, expected_x=want) + assert result.returncode == 0, (label, result.stderr) + extra += 1 + # A FLOAT4 format word must be refused just like UINT1 by store_heap_word_d16. + wrong_float4 = list(table) + wrong_float4[TABLE_BYTE // 4 + 3] = FLOAT4 + case = directory / "store.case" + case.write_bytes(struct.pack("<321I", 1, *([base.SENTINEL] * WORDS)) + struct.pack("<16I", 0, D16_X_PAYLOADS[0][1], *([0] * 14)) + + struct.pack("<320I", *wrong_float4)) + result = subprocess.run([renderer, backend, "--compute-store-case", cso, case], capture_output=True, text=True) + assert result.returncode == 0, ("wrong FLOAT4 format", result.stderr) + extra += 1 + width_str = "4u" if mode == "d16_x" else "16u" mutations = ( ("view.x + index * stride + offset", "index * stride + offset", 0), (" || index >= view.z", "", 1), - ("uint stride = view.y >> 16u;", "uint stride = 24u;", 1), + ("uint stride = view.y >> 16u;", "uint stride = 8u;" if mode == "d16_x" else "uint stride = 24u;", 1), ("const uint bytes = 512u;", "const uint bytes = 1280u;", 4), - ("if (index > (bytes - view.x - offset - 16u) / stride) return;", "", 3), - ("view.w != formatWord || ", "", 5), + (f"if (index > (bytes - view.x - offset - {width_str}) / stride) return;", "", 3), + (f"view.w != {FLOAT1:#x}u || " if mode == "d16_x" else "view.w != formatWord || ", "", 5), ("!= 1u) return;", "== 0u) return;", 2), (f"slot >= {VIEW[2]}u", f"slot > {VIEW[2]}u", VIEW[2]), ) - if d16: + if mode == "d16_xyzw": mutations += ( ("value.x >> 16u", "value.x", 0), ("value.y >> 16u", "value.x >> 16u", 0), ("if (d16) value =", "if (false) value =", 0), ) + elif mode == "d16_x": + mutations += ( + ("value & 0xffffu", "value >> 16u", 0), + ("asuint(f16tof32(value & 0xffffu))", "value", 0), + (f"{FLOAT1:#x}u", f"{FLOAT4:#x}u", 0), + ) for old, new, slot in mutations: assert source.count(old) == 1, old compile_shader(source.replace(old, new)) result = run(slot) assert result.returncode == 1 and "Compute readback differs" in result.stderr, (old, result.stderr) - kind = "D16-to-FLOAT4" if d16 else "UINT4" - print(f"{backend} {kind}: {len(CASES)} heap-store cases and {len(mutations)} shader mutations checked") + kind = {"uint4": "UINT4", "d16_xyzw": "D16-to-FLOAT4", "d16_x": "D16_X-to-FLOAT1"}[mode] + print(f"{backend} {kind}: {len(cases) + extra} heap-store cases and {len(mutations)} shader mutations checked") return 0 @@ -158,13 +238,13 @@ def run(slot): with tempfile.TemporaryDirectory() as tmp: directory = Path(tmp) if mode == "draw": - for d16 in (False, True): - result = draw(directory, *args, d16) + for kind in ("uint4", "d16_xyzw", "d16_x"): + result = draw(directory, *args, kind) if result: sys.exit(result) sys.exit(0) assembler, objcopy, library = args - for program in (PROGRAM, D16_PROGRAM): + for program in (PROGRAM, D16_PROGRAM, D16_X_PROGRAM): code = base.assemble(directory, assembler, objcopy, program, cpu="gfx1013") verify_binary(directory, code, library, program) else: diff --git a/tools/compute_store_aot.py b/tools/compute_store_aot.py index a5d846d002..fa0ade17ac 100644 --- a/tools/compute_store_aot.py +++ b/tools/compute_store_aot.py @@ -704,24 +704,34 @@ def heap_view_hlsl(table_offset, view_count, buffer_bytes): ) -def heap_store_view_hlsl(table_offset, view_count, output_bytes): - """Store raw UINT4 or four expanded half floats through the live side-table record.""" - return f"""void store_heap_words4(uint slot, uint index, uint offset, bool d16, uint4 value) {{ - if (slot >= {view_count}u) return; - uint record = {table_offset}u + slot * {HEAP_VIEW_RECORD_BYTES}u; - if (inputData.Load(record + 16u) != {HEAP_VIEW_LIVE}u) return; - uint4 view = inputData.Load4(record); - uint formatWord = d16 ? {descriptor_format_word(77):#x}u : {descriptor_format_word(75):#x}u; - if (view.w != formatWord || (view.y & 0xc000ffffu) != 0u) return; - uint stride = view.y >> 16u; - if (((view.x | stride) & 3u) != 0u || stride < offset + 16u || index >= view.z) return; - const uint bytes = {output_bytes}u; - if (view.x > bytes || offset + 16u > bytes - view.x) return; - if (index > (bytes - view.x - offset - 16u) / stride) return; - if (d16) value = asuint(f16tof32(uint4(value.x, value.x >> 16u, value.y, value.y >> 16u))); - outputData.Store4(view.x + index * stride + offset, value); -}} -""" +def heap_store_view_hlsl(table_offset, view_count, output_bytes, *, single_d16=False): + """Store UINT4/FLOAT4 or one expanded half float through a live side-table record.""" + width = 4 if single_d16 else 16 + if single_d16: + sig = "void store_heap_word_d16(uint slot, uint index, uint offset, uint value)" + fmt_check = f" if (view.w != {descriptor_format_word(22):#x}u || (view.y & 0xc000ffffu) != 0u) return;" + write = " outputData.Store(view.x + index * stride + offset, asuint(f16tof32(value & 0xffffu)));" + else: + sig = "void store_heap_words4(uint slot, uint index, uint offset, bool d16, uint4 value)" + fmt_check = (f" uint formatWord = d16 ? {descriptor_format_word(77):#x}u : {descriptor_format_word(75):#x}u;\n" + " if (view.w != formatWord || (view.y & 0xc000ffffu) != 0u) return;") + write = (" if (d16) value = asuint(f16tof32(uint4(value.x, value.x >> 16u, value.y, value.y >> 16u)));\n" + " outputData.Store4(view.x + index * stride + offset, value);") + return ( + f"{sig} {{\n" + f" if (slot >= {view_count}u) return;\n" + f" uint record = {table_offset}u + slot * {HEAP_VIEW_RECORD_BYTES}u;\n" + f" if (inputData.Load(record + 16u) != {HEAP_VIEW_LIVE}u) return;\n" + f" uint4 view = inputData.Load4(record);\n" + f"{fmt_check}\n" + f" uint stride = view.y >> 16u;\n" + f" if (((view.x | stride) & 3u) != 0u || stride < offset + {width}u || index >= view.z) return;\n" + f" const uint bytes = {output_bytes}u;\n" + f" if (view.x > bytes || offset + {width}u > bytes - view.x) return;\n" + f" if (index > (bytes - view.x - offset - {width}u) / stride) return;\n" + f"{write}\n" + f"}}\n" + ) def lower(instructions, group, *, table_reg, descriptor_offset=None, group_reg=None, stride=None, @@ -749,7 +759,8 @@ def lower(instructions, group, *, table_reg, descriptor_offset=None, group_reg=N word index per formatted load, in program order, read by load_descriptor_format (see descriptor_load_hlsl). heap_view=(slot_word, table_offset, view_count, buffer_bytes) makes the same loads take the V# from a run-time view record instead of a constant format word (see heap_view_hlsl). It excludes load_format_constant. - heap_store_view uses the same t0 record layout for one indexed UINT4 or packed D16-to-FLOAT4 store to u0. + heap_store_view uses the same t0 record layout for one indexed UINT4, packed D16-to-FLOAT4, or + packed D16-to-FLOAT1 store to u0. Its fifth argument is the writable byte extent of u0. Root UAV descriptors carry no length. gfx1013 uses RGBA32 FLOAT for full-mask image_store or image_load_mip. When both are used, image_srv_descriptor supplies the separate t0 descriptor. @@ -2721,8 +2732,8 @@ def lower(instructions, group, *, table_reg, descriptor_offset=None, group_reg=N if not idxen or offen: raise ValueError("Unsupported formatted buffer store target or address mode") if heap_store_view is not None: - if channels not in ("xyzw", "d16_xyzw"): - raise ValueError("Heap store view requires buffer_store_format_xyzw or buffer_store_format_d16_xyzw") + if channels not in ("xyzw", "d16_xyzw", "d16_x"): + raise ValueError("Heap store view requires buffer_store_format_xyzw, buffer_store_format_d16_xyzw or buffer_store_format_d16_x") if not any(tag == ("constant_word", heap_slot_word) and reg not in pending for reg, tag in scalar.items()): raise ValueError("Heap store view slot constant is not ready") @@ -2846,16 +2857,19 @@ def lower(instructions, group, *, table_reg, descriptor_offset=None, group_reg=N source_shift = 16 if m["store_hi"] else 0 words[0] = (f"((outputData.Load({address}) & {keep:#x}u) | " f"((({words[0]} >> {source_shift}u) & {mask:#x}u) << {byte_shift}u))") - elif partial and not descriptor_store: + elif partial and not descriptor_store and heap_store_view is None: # Reserve the entire final DWORD, including the untouched high half. The indexed # layout, aligned stride and overlap checks give that word a single writer. final_address = address if count == 1 else f"{address} + 4u" words[-1] = f"((outputData.Load({final_address}) & 0xffff0000u) | ({words[-1]} & 0xffffu))" if heap_store_view is not None: slot = hlsl_word(("constant_word", heap_slot_word)) - supplied = words + ["0u"] * (4 - len(words)) - mode = "true" if packed else "false" - stores.append(f" store_heap_words4({slot}, {address}, {offset}u, {mode}, uint4({', '.join(supplied)}));") + if channels == "d16_x": + stores.append(f" store_heap_word_d16({slot}, {address}, {offset}u, {words[0]});") + else: + supplied = words + ["0u"] * (4 - len(words)) + mode = "true" if packed else "false" + stores.append(f" store_heap_words4({slot}, {address}, {offset}u, {mode}, uint4({', '.join(supplied)}));") elif descriptor_store: supplied = words + ["0u"] * (4 - len(words)) stores.append(" store_descriptor_format(" @@ -2933,7 +2947,9 @@ def lower(instructions, group, *, table_reg, descriptor_offset=None, group_reg=N if heap_view is not None: descriptor_hlsl += heap_view_hlsl(heap_table, heap_count, heap_bytes) if heap_store_view is not None: - descriptor_hlsl += heap_store_view_hlsl(heap_table, heap_count, output_bytes) + descriptor_hlsl += heap_store_view_hlsl( + heap_table, heap_count, output_bytes, single_d16="store_heap_word_d16(" in body + ) # GetDimensions on a raw buffer returns its size in bytes, the value of descriptor word 2. for name, view in (("uav_bytes", "outputData"), ("srv_bytes", "inputData")): if f"{name}(" in body: