diff --git a/CMakeLists.txt b/CMakeLists.txt index fef07e4850..31a51f2c82 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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" "$" "${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" "$" + "${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 diff --git a/docs/experiments.md b/docs/experiments.md index 2365cd0c25..e27b255868 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -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 , refused , no translation , not modelled ` 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 diff --git a/tests/startup_compute_dispatch_texture_check.py b/tests/startup_compute_dispatch_texture_check.py index 5f8c8bdbb1..d56ba9ad11 100644 --- a/tests/startup_compute_dispatch_texture_check.py +++ b/tests/startup_compute_dispatch_texture_check.py @@ -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 +usage: startup_compute_dispatch_texture_check.py [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 @@ -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 @@ -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) @@ -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:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index aa7fee7343..5e75f5f394 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -165,7 +165,7 @@ static void* desktop_pipeline(void* device) // stateb-unreadable, desc-unreadable // dispatch, dispatch-swapped, dispatch-none, dispatch-records32, dispatch-sampled, dispatch-sampled-unbound, dispatch-sampled-2x1, dispatch-heap, // dispatch-heap-outside, dispatch-heap-word*, dispatch-input-*: one creation, then dispatch_slot67 below -// texture-store, texture-store-none, texture-store-denied, texture-store-occupied, texture-store-copied: one creation, then texture_slot67 below +// texture-store and texture-array modes: one creation, then texture_slot67 below // The unreadable cases point at a PAGE_NOACCESS page; code-past-end ends the code on the last byte before one. static void* slot67_pipeline; static void* slot67_root; @@ -495,17 +495,23 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin // without unordered access, so the stand-in records its view as not created. texture-store-uint makes the texture // and its view RGBA16_UINT; texture-store-occupied then asks for a view of a texture without unordered access at the same // handle, which keeps the first view; texture-store-self also creates a shader resource view of the texture at table byte 0. +// texture-store-mips adds a second UAV of the same texture. The swapped mode reverses the two mip views. static int texture_slot67(void* device, const std::string& mode) { constexpr UINT width = 32; const bool volume = mode == "texture-volume" || mode == "texture-volume-bad-w"; const bool line = mode == "texture-line" || mode == "texture-line-bad-mip"; - const UINT mip = volume || line ? 1 : 0; + const UINT first_mip = volume || line ? 1 : 0; const UINT height = line ? 1 : 8; const bool fp32 = volume || line || mode == "texture-array" || mode == "texture-array-2d"; const UINT layers = volume || mode == "texture-array" || mode == "texture-array-d16" ? 6 : 1; const UINT subresources = volume ? 1 : layers; - const UINT pitch = width * (fp32 ? 16 : 8), slice_bytes = pitch * height, bytes = slice_bytes * layers; + const bool swapped = mode == "texture-store-mips-swapped"; + const bool dual = swapped || mode == "texture-store-mips"; + const UINT mips = dual ? 2 : 1; + const UINT pixel_bytes = fp32 ? 16 : 8, pitch = width * pixel_bytes; + const UINT slice_bytes = pitch * (height + (dual ? height / 2 : 0)), bytes = slice_bytes * layers; + const auto offset = [&](UINT layer, UINT mip) { return UINT64{layer} * slice_bytes + (mip ? pitch * height : 0); }; const auto word = [](const void* value) { return reinterpret_cast(value); }; const auto make = [&](D3D12_HEAP_TYPE type, const D3D12_RESOURCE_DESC& desc, D3D12_RESOURCE_STATES state) { return make_committed(device, type, desc, state); @@ -514,8 +520,8 @@ static int texture_slot67(void* device, const std::string& mode) mode == "texture-store-uint" ? DXGI_FORMAT_R16G16B16A16_UINT : DXGI_FORMAT_R16G16B16A16_FLOAT; const auto dimension = volume ? D3D12_RESOURCE_DIMENSION_TEXTURE3D : line ? D3D12_RESOURCE_DIMENSION_TEXTURE1D : D3D12_RESOURCE_DIMENSION_TEXTURE2D; - const D3D12_RESOURCE_DESC texture_desc{dimension, 0, width << mip, line ? 1 : height << mip, - static_cast(volume ? layers << mip : layers), static_cast(mip + 1), format, + const D3D12_RESOURCE_DESC texture_desc{dimension, 0, width << first_mip, line ? 1 : height << first_mip, + static_cast(volume ? layers << first_mip : layers), static_cast(first_mip + mips), format, {1, 0}, D3D12_TEXTURE_LAYOUT_UNKNOWN, mode == "texture-store-denied" ? D3D12_RESOURCE_FLAG_NONE : D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS}; const D3D12_RESOURCE_DESC buffer_desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, bytes, 1, 1, 1, DXGI_FORMAT_UNKNOWN, {1, 0}, @@ -529,6 +535,15 @@ static int texture_slot67(void* device, const std::string& mode) for (UINT layer = 0; layer < layers; ++layer) for (UINT i = 0; i < slice_bytes / 4; ++i) static_cast(memory)[layer * slice_bytes / 4 + i] = 0xbf000000u | (layer << 12) | i; + } else if (dual) { + for (UINT mip = 0; mip < mips; ++mip) { + const UINT row_halves = (width >> mip) * (pixel_bytes / sizeof(UINT16)); + auto* start = reinterpret_cast(static_cast(memory) + offset(0, mip)); + for (UINT y = 0; y < (height >> mip); ++y) + for (UINT x = 0; x < row_halves; ++x) + start[y * pitch / sizeof(UINT16) + x] = + static_cast(0x5000 + 0x400 * mip + y * row_halves + x); + } } else { for (UINT i = 0; i < bytes / 2; ++i) static_cast(memory)[i] = static_cast(0x5000 + i); } @@ -536,7 +551,7 @@ static int texture_slot67(void* device, const std::string& mode) const struct { D3D12_DESCRIPTOR_HEAP_DESC desc; UINT64 backing, bytes; - } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 4, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; + } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, dual ? 5u : 4u, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; void *heap = nullptr, *queue = nullptr, *allocator = nullptr, *list = nullptr, *fence = nullptr; const D3D12_COMMAND_QUEUE_DESC queue_desc{}; const UINT list_desc[]{D3D12_COMMAND_LIST_TYPE_DIRECT, 2, 1, 0}; @@ -551,13 +566,15 @@ static int texture_slot67(void* device, const std::string& mode) if (volume) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; // At mip 1 the depth is six. The bad count fits only if the binder uses the base mip's depth. - view.Texture3D = {mip, 1, mode == "texture-volume-bad-w" ? layers : ~0u}; + view.Texture3D = {first_mip, 1, mode == "texture-volume-bad-w" ? layers : ~0u}; } else if (line) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D; - view.Texture1D.MipSlice = mode == "texture-line-bad-mip" ? mip + 1 : mip; // bad-mip: one past the last mip + view.Texture1D.MipSlice = mode == "texture-line-bad-mip" ? first_mip + 1 : first_mip; } else if (layers > 1) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; view.Texture2DArray = {0, 1, 4, 0}; // four selected slices, with untouched neighbors on both sides + } else { + view.Texture2D.MipSlice = swapped ? 1 : 0; } if (mode != "texture-store-copied") invoke(device, 19, word(texture), 0, word(&view), cpu + 64); if (mode == "texture-store-copied") { @@ -578,32 +595,33 @@ static int texture_slot67(void* device, const std::string& mode) if (!other) return 79; invoke(device, 19, word(other), 0, word(&view), cpu + 64); } + if (dual) { + view.Texture2D.MipSlice = swapped ? 0 : 1; + invoke(device, 19, word(texture), 0, word(&view), cpu + 128); + } D3D12_SHADER_RESOURCE_VIEW_DESC read{format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; read.Texture2D.MipLevels = 1; if (mode == "texture-store-self") invoke(device, 18, word(texture), word(&read), cpu); - D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; - D3D12_TEXTURE_COPY_LOCATION source{static_cast(upload), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; - source.PlacedFootprint = {0, {format, width, height, volume ? layers : 1, pitch}}; - D3D12_TEXTURE_COPY_LOCATION result = source; - result.pResource = static_cast(readback); + const auto transfer = [&](void* buffer, bool to_texture) { + for (UINT layer = 0; layer < subresources; ++layer) + for (UINT mip = 0; mip < mips; ++mip) { + D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + image.SubresourceIndex = layer * texture_desc.MipLevels + first_mip + mip; + D3D12_TEXTURE_COPY_LOCATION rows{static_cast(buffer), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + rows.PlacedFootprint = {offset(layer, mip), {format, width >> mip, height >> mip, volume ? layers : 1, pitch}}; + invoke(list, 16, word(to_texture ? &image : &rows), 0, 0, 0, word(to_texture ? &rows : &image), 0); + } + }; const UINT constants[3] = {1, 2, 3}; if (FAILED(static_cast(invoke(list, 139, word(allocator))))) return 74; invoke(list, 32, 1, word(&heap)); - for (UINT subresource = 0; subresource < subresources; ++subresource) { - image.SubresourceIndex = subresource + mip; - source.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; - invoke(list, 16, word(&image), 0, 0, 0, word(&source), 0); - } + transfer(upload, true); invoke(list, 25, word(slot67_pipeline)); invoke(list, 33, word(slot67_root)); invoke(list, 39, 0, 3, word(constants), 0); invoke(list, 35, 1, gpu); if (mode != "texture-store-none") invoke(list, 14, 2, 1, 1); - for (UINT subresource = 0; subresource < subresources; ++subresource) { - image.SubresourceIndex = subresource + mip; - result.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; - invoke(list, 16, word(&result), 0, 0, 0, word(&image), 0); - } + transfer(readback, false); if (FAILED(static_cast(invoke(list, 9)))) return 75; invoke(queue, 10, 1, word(&list)); if (FAILED(static_cast(invoke(queue, 14, word(fence), 1)))) return 76; @@ -616,9 +634,13 @@ static int texture_slot67(void* device, const std::string& mode) const DWORD n = GetEnvironmentVariableA("X2W_TEST_DISPATCH_OUT", path, MAX_PATH); memory = nullptr; if (!n || n >= MAX_PATH || FAILED(static_cast(invoke(readback, 8, 0, 0, word(&memory)))) || !memory) return 2; - std::ofstream(path, std::ios::binary).write(static_cast(memory), bytes); + std::ofstream output(path, std::ios::binary); + for (UINT layer = 0; layer < layers; ++layer) + for (UINT mip = 0; mip < mips; ++mip) + for (UINT y = 0; y < (height >> mip); ++y) + output.write(static_cast(memory) + offset(layer, mip) + y * pitch, (width >> mip) * pixel_bytes); invoke(readback, 9, 0, 0); - return 0; + return output ? 0 : 2; } static bool create_slot67(void* device, const char* code_path, const char* data_path, const char* state_path, const char* mode)