Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions docs/experiments/native-image-cache-flags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Direct DXIL Read-Only Image Cache Flags (`GLC` / `DLC`)

Experiment for accepting MIMG cache-policy flags `GLC` (word 0 bit 13, `0x2000`) and `DLC` (word 0 bit 7, `0x0080`) on read-only image operations in `DirectCompute::image_io()`, addressing `#3242`, `#3224` (Rank 8), and `#2935`.

## What Changed

- Updated `DirectCompute::image_io()` in [src/gfx1013_direct_compute.inl](../../src/gfx1013_direct_compute.inl) so `(i.a & (store ? 0x3e0c0u : 0x3c040u))` accepts `GLC` (`0x2000`) and `DLC` (`0x0080`) on read-only image instructions (`image_load`, `image_load_mip`, `image_sample*`, `image_gather4*`, `image_getlod`, `image_getresinfo`) while keeping refusals for:
- `image_store` with `GLC` or `DLC` (`0x3e0c0u`)
- `LWE` (`0x20000`), `TFE` (`0x10000`), `R128` (`0x8000`), and reserved word 0 bits (`0x4040`)
- word 1 reserved bits (`0x3c000000u`)
- Added [tests/native_image_cache_flags_check.py](../../tests/native_image_cache_flags_check.py) and registered CTest entries in [tests/cmake/native_image_cache_flags.cmake](../../tests/cmake/native_image_cache_flags.cmake).

## Verification

Host: Windows 10.0.26100, `dev` preset, DXC `10.0.26100.0`.

- `cmake --build --preset dev --target compile_dxil offscreen_check native_compute_ir_dump`: passed.
- `ctest --preset dev --no-tests=error -R '^(native_image_cache_flags_|native_gather_|native_image_atomic_|native_sample_ssamp_)' -V`:
- `native_image_cache_flags_controls`: **passed** (`48` flagged DXIL modules matched plain `flags=0` baselines across Compute and Pixel stages and `GLC`/`DLC`/`SLC`/`GLC|DLC|SLC`; `16` refusals matched across Compute and Pixel).
- `native_image_cache_flags_ps_warp`: **passed** (`12` cached-flag `image_gather4_l` cases matched on Microsoft Basic Render Driver `10.0.26100.9711`).
- `native_image_cache_flags_ps_hardware`: **passed** (`12` cached-flag `image_gather4_l` cases matched on `NVIDIA Quadro M1000M` `32.0.15.7371`; debug layer unavailable).
- `native_image_cache_flags_cs_hardware`: **passed** (`12` cached-flag `image_gather4_l` cases matched on `NVIDIA Quadro M1000M` `32.0.15.7371`; debug layer unavailable).
- `native_image_cache_flags_cs_warp`: **skipped** (`77`, Microsoft Basic Render Driver has 4-lane waves and lacks SM 6.6 wave32).
- Neighbor suites (`native_gather_compare_warp`, `native_gather_lod_controls/ps_warp/ps_hardware/cs_hardware`, `native_image_atomic_controls/hardware`, `native_sample_ssamp_hardware`): passed (with SM 6.6 wave32 WARP tests skipping `77`; `native_image_atomic_runtime_hardware` failed on this dual-GPU host because `startup_stream_consumer` runs on adapter 0 `Intel(R) HD Graphics 530` which lacks SM 6.6 wave32).
- `ctest --preset dev --no-tests=error -R '^native_.*_(controls|ir)$' --output-on-failure`: **67/67 passed** (`0` failures, `0` skips).
- Sensitivity mutants in `src/gfx1013_direct_compute.inl` tested against `native_image_cache_flags_controls`:
- `revert_ro_cache_flags` (`(i.a & 0x3e0c0u)`): failed (`rc=8`, rejected `image_load` with `GLC`).
- `drop_r128_refusal` (`(i.a & (store ? 0x3e0c0u : 0x34040u))`): failed (`rc=8`, accepted `sample_r128`).
- Clean tree restored, rebuilt, and `native_image_cache_flags_controls` passed (`48` modules, `16` refusals).
- `python -B tests/docs_links_check.py`: passed (`131` Markdown files, `631` links).

## Limits

- `native_image_cache_flags_cs_warp` skips (`77`) on WARP because WARP uses 4-lane waves.
- `GLC` and `DLC` remain refused on `image_store*` and explicit/policy-checked on `image_atomic_*` (`image_atomic()`).
- Local `offscreen_check` hardware runs reported `debug_layer=unavailable` on `NVIDIA Quadro M1000M`.
5 changes: 4 additions & 1 deletion src/gfx1013_direct_compute.inl
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,10 @@ struct DirectCompute {
const unsigned coords = coord_count[dim];
const bool exact_store = store && !half && !graphics_input && (dim == 1 || dim == 2 || dim == 5) &&
(mask == 1 || mask == 3 || mask == 7);
if ((i.op != 0 && i.op != 1 && !store && !sample && !gather && !gather_lod && !dimensions) || !mask || (i.a & 0x3e0c0u) ||
// Read-only image ops ignore GLC (bit 13, 0x2000) and DLC (bit 7, 0x0080) cache hints;
// LWE (0x20000), TFE (0x10000), R128 (0x8000), reserved bits (0x4040), and store GLC/DLC stay refused.
if ((i.op != 0 && i.op != 1 && !store && !sample && !gather && !gather_lod && !dimensions) || !mask ||
(i.a & (store ? 0x3e0c0u : 0x3c040u)) ||
(i.b & 0x3c000000u) || (gather && ((mask & (mask - 1)) || (dim != 1 && dim != 3 && dim != 5))) ||
(query && ((dim != 1 && dim != 3) || (mask & ~3u))) ||
(compare && (mask != 1 || (dim != 1 && dim != 3 && dim != 5) || (i.a & 0x1000u))) ||
Expand Down
15 changes: 15 additions & 0 deletions tests/cmake/native_image_cache_flags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if(TARGET compile_dxil AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}" AND
EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll")
add_test(NAME native_image_cache_flags_controls COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_image_cache_flags_check.py" controls
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}")
set_tests_properties(native_image_cache_flags_controls PROPERTIES TIMEOUT 60)
foreach(stage IN ITEMS ps cs)
foreach(adapter IN ITEMS warp hardware)
add_test(NAME native_image_cache_flags_${stage}_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/native_image_cache_flags_check.py" ${stage}
"$<TARGET_FILE:compile_dxil>" "${DXC_BIN_DIR}" "$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(native_image_cache_flags_${stage}_${adapter} PROPERTIES TIMEOUT 90 SKIP_RETURN_CODE 77)
endforeach()
endforeach()
endif()
136 changes: 136 additions & 0 deletions tests/native_image_cache_flags_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
"""Verify GLC and DLC cache-policy flags on direct read-only image ops (#3242)."""
from pathlib import Path
import struct
import subprocess
import sys
import tempfile

from native_direct_container_check import compute, patched_pixel, words
import native_gather_lod_check as G

GLC = 0x2000
DLC = 0x0080
SLC = 0x02000000
ALL_CACHE = GLC | DLC | SLC
REFUSED = 'direct image opcode or descriptor modifiers'


def ro_program(op, stage, *, flags=0, w1_flags=0):
code = [0xBE810380, 0xF40C0200, 0xFA000000] # s[8:15] texture descriptor
if stage == 'cs':
code += [0xF4080800, 0xFA000020, 0x7E060280] # s[32:35] UAV, v3 = 0
for reg, value in enumerate((0x12, 512 << 12, 0x04500000, 0), start=4):
code += [0xBE8003FF | (reg << 16), value]
coords = (0.5, 0.5, 0.0) if op >= 32 else (0, 0, 0)
for reg, value in enumerate(coords):
encoded = struct.unpack('<I', struct.pack('<f', value))[0] if op >= 32 else value
code += [0x7E0002FF | (reg << 17), encoded]
sampler_field = (1 << 21) if op >= 32 else 0
dmask = 1 if op in (68, 71) else 0xF
code += [0xBF8CC07F, 0xF0000008 | (op << 18) | (dmask << 8) | flags, 0x00020400 | sampler_field | w1_flags, 0xBF8C3F70]
if stage == 'cs':
return compute(words(*code, 0xE0781000, 0x80080403, 0xBF810000), threads=1, table=True)
return patched_pixel(len(code), code, table=True, export=(0xF800180F, 0x07060504))


def store_program(stage, *, flags=0):
code = [0xBE810380, 0xF40C0200, 0xFA000000, 0xBF8CC07F,
0x7E000280, 0x7E020280,
0xF0000F08 | (8 << 18) | flags, 0x00020400, 0xBF810000]
if stage == 'cs':
return compute(words(*code), threads=1, table=True)
return patched_pixel(len(code), code, table=True, export=(0xF800180F, 0x07060504))


def compile_bytes(cli, sdk, work, label, stage, blob):
src = work / f'{label}.{stage}'
src.write_bytes(blob)
cso = src.with_suffix('.cso')
run = subprocess.run([cli, sdk, work / 'cache', f'gfx1013-container-{stage}', src, cso],
capture_output=True, text=True, timeout=30)
return cso, run


def controls(cli, sdk, work):
ops = (
('image_load', 0, '@dx.op.textureLoad.f32'),
('image_load_mip', 1, '@dx.op.textureLoad.f32'),
('image_getresinfo', 14, '@dx.op.getDimensions'),
('image_sample_lz', 39, '@dx.op.sampleLevel.f32'),
('image_gather4_lz', 71, '@dx.op.textureGather.f32'),
('image_gather4_l', 68, '@dx.op.textureLoad.f32'),
)
accepted = 0
for stage in ('cs', 'ps'):
for name, op, expected_dxil in ops:
base_cso, base_run = compile_bytes(cli, sdk, work, f'{name}-base', stage, ro_program(op, stage))
assert base_run.returncode == 0 and base_cso.is_file(), (stage, name, base_run.stdout, base_run.stderr)
base_dump = subprocess.run([Path(sdk) / 'dxc.exe', '-dumpbin', base_cso],
capture_output=True, text=True, check=True).stdout
assert expected_dxil in base_dump, (stage, name, expected_dxil, base_dump)
for tag, fl in (('glc', GLC), ('dlc', DLC), ('slc', SLC), ('all', ALL_CACHE)):
cso, run = compile_bytes(cli, sdk, work, f'{name}-{tag}', stage, ro_program(op, stage, flags=fl))
assert run.returncode == 0 and cso.is_file(), (stage, name, tag, run.stdout, run.stderr)
dump = subprocess.run([Path(sdk) / 'dxc.exe', '-dumpbin', cso],
capture_output=True, text=True, check=True).stdout
assert dump == base_dump, (stage, name, tag)
accepted += 1

refusals = (
('store_glc', lambda st: store_program(st, flags=GLC)),
('store_dlc', lambda st: store_program(st, flags=DLC)),
('sample_r128', lambda st: ro_program(39, st, flags=0x8000)),
('sample_tfe', lambda st: ro_program(39, st, flags=0x10000)),
('sample_lwe', lambda st: ro_program(39, st, flags=0x20000)),
('sample_res_bit6', lambda st: ro_program(39, st, flags=0x0040)),
('sample_res_bit14', lambda st: ro_program(39, st, flags=0x4000)),
('sample_res_w1_bit26', lambda st: ro_program(39, st, w1_flags=1 << 26)),
)
refused = 0
for stage in ('cs', 'ps'):
for rname, builder in refusals:
_, run = compile_bytes(cli, sdk, work, f'ref-{rname}', stage, builder(stage))
assert run.returncode != 0 and REFUSED in run.stderr, (stage, rname, run.returncode, run.stderr)
refused += 1

print(f'native_image_cache_flags controls: {accepted} flagged DXIL modules matched plain baselines; {refused} refusals matched')
return 0


def execute(cli, sdk, renderer, adapter, stage, work):
if stage == 'cs':
wave = G.render(renderer, adapter, '--shader-wave32')
assert wave.returncode == 0, wave.stdout + wave.stderr
cases = (G.CASES[0], G.CASES[1], G.CASES[3], G.CASES[7])
flag_sets = (('glc', GLC), ('dlc', DLC), ('glc_dlc_slc', ALL_CACHE))
for case in cases:
for tag, flags in flag_sets:
cso, run = G.compile_shader(cli, sdk, work, case, stage, flags=flags)
assert run.returncode == 0, (stage, case.name, tag, run.stdout, run.stderr)
reference = work / 'expected.bin'
if stage == 'ps':
G.write_case(reference, 3 - case.first, case.first, [G.taps(case)] * (G.SIDE ** 2))
res = G.render(renderer, adapter, '--check-pixel-gather', cso, reference)
assert res.returncode == 0 and 'pixels=64 channels=256 max_absolute_error=0' in res.stdout, (
stage, case.name, tag, res.stdout, res.stderr)
else:
expected = G.compute_reference(case.first + case.relative, case.channel, case.uv)
res = G.render_compute(renderer, adapter, cso, reference, case.first, expected)
assert res.returncode == 0 and 'compared_words=320 mismatches=0' in res.stdout, (
stage, case.name, tag, res.stdout, res.stderr)
if 'debug_layer=enabled' in res.stdout:
assert 'debug_errors=0 debug_warnings=0' in res.stdout, res.stdout
print(f'native_image_cache_flags {stage} ({adapter}): {len(cases) * len(flag_sets)} cached-flag cases matched')
return 0


def main(mode, cli, sdk, *args):
with tempfile.TemporaryDirectory() as tmp:
work = Path(tmp)
if mode == 'controls':
return controls(cli, sdk, work)
return execute(cli, sdk, args[0], args[1], mode, work)


if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))
Loading