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
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4781,10 +4781,13 @@ if(EXISTS "${INTAKE_PYTHON}")
add_test(NAME startup_compute_dispatch_entry_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_entry_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
add_test(NAME startup_compute_dispatch_two_mips_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter} two-mips)
set_tests_properties(startup_compute_dispatch_${adapter} startup_compute_dispatch_texture_${adapter}
startup_compute_dispatch_heap_${adapter} startup_compute_dispatch_heap_word_${adapter}
startup_compute_live_retry_${adapter} startup_compute_dispatch_entry_${adapter}
startup_compute_dispatch_input_${adapter}
startup_compute_dispatch_input_${adapter} startup_compute_dispatch_two_mips_${adapter}
PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
endforeach()
add_test(NAME startup_stream_adapter_filter COMMAND "${INTAKE_PYTHON}" -B
Expand Down
4 changes: 3 additions & 1 deletion docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -17053,9 +17053,11 @@ With a device slot 67 placeholder bound, command-list slot 14 looks up the trans

`tests/startup_compute_dispatch_check.py` drives a source-built gfx1013 program through the stand-in's list on WARP and on a physical adapter (exit 77 without one) and reads the 320 output words back from the aliased memory. Controls in the same run: before the offline translation, without a Dispatch, and with the two descriptors exchanged, every output word must keep its sentinel. The two entry values arrive through slot 37 and slot 39, with other values written through slot 40 in between; `dispatch-same-root` must still give the expected words, and five refused modes must log their reason and keep the sentinels: a missing word, another compute root set and the first set again, a list reset, a compute root that is not the pipeline's, and one buffer named as input and output. `tests/startup_compute_dispatch_texture_check.py` does the same for a program that stores to a 32x8 RGBA16_FLOAT texture (1024 halves read back through CopyTextureRegion; controls: before translation, without a Dispatch, a texture without unordered access) and for the raw buffer program with a level-zero sample of a 1x1 texture XORed into each stored word (control: no view at the table entry). The texture output program is also bound under a manifest edited to declare no entry values.

`startup_compute_dispatch_two_mips_` writes two distinct patterns through two UAVs of one RGBA16_FLOAT texture in the same translated Dispatch. The test compares all 1,280 half values in the 32×8 and 16×4 subresources, including the sentinel values outside the written rectangles. Before translation both mips keep their sentinels. Exchanging the two views moves the patterns to opposite mips and changes 64 half values relative to the ordered case.

The log line `x2w-render compute dispatches: translated <n>, refused <n>, no translation <n>, not modelled <n>` follows the render totals; "not modelled" counts calls whose manifest exists but holds a line the runtime does not bind. It is followed by a census: the refused calls per first refusal reason of their key, and every dispatched key by call count, each with its count, the calls recorded and the first refused table descriptor.

Measured on three fixture programs. The sampling fixture uses a 1x1 texture, so it does not tell sampler filter or address modes apart. Programs with other texture kinds, sampler heaps, the same texture as input and output, or buffer outputs in memory that is not aliased are not dispatched.
The sampling fixture uses a 1x1 texture, so it does not tell sampler filter or address modes apart. Programs with other texture kinds, sampler heaps, the same texture as input and output, or buffer outputs in memory that is not aliased are not dispatched.

The `startup_compute_live_retry_warp` and `startup_compute_live_retry_hardware` tests keep the device and
slot 67 pipeline alive across two fenced Dispatch calls. The first observes the missing translation and
Expand Down
100 changes: 91 additions & 9 deletions tests/startup_compute_dispatch_texture_check.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Translated compute programs with 2D texture views, dispatched through the stand-in's command list (slot 14).

usage: startup_compute_dispatch_texture_check.py <startup_stream_consumer> <dxc> <warp|hardware>
usage: startup_compute_dispatch_texture_check.py <startup_stream_consumer> <dxc> <warp|hardware> [two-mips]

Texture output: the consumer creates the image store program of startup_compute_image_store_d16_check.py as a
device slot 67 pipeline, fills a 32x8 RGBA16_FLOAT texture with sentinel halves, creates an unordered access view of
Expand All @@ -24,6 +24,8 @@
Filtered input: the texture input case with a constant wrap, linear sampler that the translator writes as `smpl`
and a 2x1 texture (dispatch-sampled-2x1): red 0.5 at the left edge. The same program with the manifest's sampler
changed to clamp reads red 0 (the control); `smpc` and `smpheap` lines are refused with their reasons.

The two-mips mode writes two different patterns through separate UAVs of the same texture, then swaps the views.
Exit 77 when the adapter is not available.
"""
import os
Expand Down Expand Up @@ -150,6 +152,82 @@ def store(directory, consumer, dxc, env):
f'untouched before translation, without a Dispatch and for a refused view; debug layer: {layer}')


# A second descriptor, at table byte 128, and a different color in v14.
SECOND_STORE = bytes.fromhex(
'06080cf4 800000fa ' # s_load_dwordx8 s[32:39], s[12:13], 0x80
'7fc08cbf ' # s_waitcnt lgkmcnt(0)
'ff021c7e 00bc0044 ' # v_mov_b32_e32 v14, 0x4400bc00
'080f20f0 080e0880' # image_store v[14:15], v[8:9], s[32:39] dmask:0xf dim:SQ_RSRC_IMG_2D d16
)
MIPS = ((32, 8), (16, 4))


def mip_reference(colors):
halves = []
for mip, ((width, height), color) in enumerate(zip(MIPS, colors, strict=True)):
for y in range(height):
for x in range(width):
sentinel = 0x5000 + 0x400 * mip + 4 * (y * width + x)
if color is None or x >= 8 or y >= 2:
halves.extend(range(sentinel, sentinel + 4))
else:
tag = 8 * y + x
rg = (0x3c00 + tag, 0xc000 + tag) if color == 0 else (0xbc00, 0x4400)
halves.extend((*rg, tag, 0x8000 + tag))
return halves


def check_mips(label, got, expected):
start = 0
for mip, (width, height) in enumerate(MIPS):
for index in range(width * height * 4):
actual, wanted = got[start + index], expected[start + index]
pixel, channel = divmod(index, 4)
y, x = divmod(pixel, width)
assert actual == wanted, (f'{label}: mip={mip} x={x} y={y} channel={channel} '
f'expected={wanted:04x} actual={actual:04x}')
start += width * height * 4


def store_two_mips(directory, consumer, dxc, env):
cache, base = prepare(directory)
root = C.root_blob(3, table_range=True)
(directory / 'compute_root').write_bytes(root)
env = dict(base, **env, X2W_TEST_COMPUTE_ROOT=str(directory / 'compute_root'))
code = S.PREFIX + S.STORE + SECOND_STORE + S.END
pipeline = G.ComputePipeline(code, root, S.RSRC2, S.fixture.GROUP)
outputs = [line for line in pipeline.manifest().splitlines() if line.startswith('uav ')]
assert outputs == [
'uav 0 tex2d float table 1 64 channels 4',
'uav 1 tex2d float table 1 128 channels 4',
], outputs
(directory / 'program').write_bytes(code)
(directory / 'data').write_bytes(DATA)
(directory / 'state').write_bytes(state_a(S.fixture.GROUP, S.RSRC2))
untouched = mip_reference((None, None))
layout = '<%dH' % len(untouched)

got, result = run(directory, consumer, env, 'texture-store-mips', layout)
print(result.stdout, end='')
check_mips('missing translation', got, untouched)
assert len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:]
key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16)
translate(cache, dxc, key)

expected = mip_reference((0, 1))
got, result = run(directory, consumer, env, 'texture-store-mips', layout)
check_mips('ordered views', got, expected)
assert len(lines(result, 'translated: 3 entry values, 0 inputs, 2 outputs')) == 1, result.stderr[-3000:]
layer = clean(result)

got, result = run(directory, consumer, env, 'texture-store-mips-swapped', layout)
check_mips('swapped views', got, mip_reference((1, 0)))
clean(result)
changed = sum(a != b for a, b in zip(got, expected, strict=True))
assert changed == 64, changed
print(f'two mip outputs: {len(got)} halves match; swapping views changes {changed} halves; debug layer: {layer}')


def store_3d1d(directory, consumer, dxc, env, form):
cache, base = prepare(directory)
env = dict(base, **env)
Expand Down Expand Up @@ -391,21 +469,25 @@ def uniform_image_load_mip(directory, consumer, dxc, env):
f'x=0 and mip=1 controls each differ at {written} words; debug layer: {layer}')


def main(consumer, dxc, adapter):
def main(consumer, dxc, adapter, mode=None):
env = dict(X2W_D3D12_LIST_NOOP='1', X2W_D3D12_DEBUG='1') # guest lists; debug-layer messages go to the log
if adapter == 'hardware':
env['X2W_TEST_DISPATCH_HARDWARE'] = '1'
with tempfile.TemporaryDirectory() as temporary:
store(Path(temporary) / 'store', consumer, dxc, env)
for form in V.FORMS:
store_3d1d(Path(temporary) / form, consumer, dxc, env, form)
sample(Path(temporary) / 'sample', consumer, dxc, env)
filtered(Path(temporary) / 'filtered', consumer, dxc, env)
uniform_image_load_mip(Path(temporary) / 'uniform_image_load_mip', consumer, dxc, env)
directory = Path(temporary)
if mode == 'two-mips':
store_two_mips(directory / 'mips', consumer, dxc, env)
else:
store(directory / 'store', consumer, dxc, env)
for form in V.FORMS:
store_3d1d(directory / form, consumer, dxc, env, form)
sample(directory / 'sample', consumer, dxc, env)
filtered(directory / 'filtered', consumer, dxc, env)
uniform_image_load_mip(directory / 'uniform_image_load_mip', consumer, dxc, env)
print(f'startup_compute_dispatch_texture: PASS on {adapter}')


if __name__ == '__main__':
if len(sys.argv) != 4 or sys.argv[3] not in ('warp', 'hardware'):
if len(sys.argv) not in (4, 5) or sys.argv[3] not in ('warp', 'hardware') or sys.argv[4:] not in ([], ['two-mips']):
sys.exit(__doc__)
main(*sys.argv[1:])
Loading
Loading