From af6045dffedc9a4511c1d947b4c8a4146f1a13b8 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:24:36 +0200 Subject: [PATCH 1/2] startup: bind constant static samplers on the in-process compute route translate_compute_natively refused every program with a sampler. The C++ compiler already resolves constant sampler words into ComputeSampler entries, so they now fill the route's TranslatedSamplers in register order and the existing root signature code creates the static samplers: a comparison sampler as smpc, any other with explicit_lod as smpl, the choice format_graphics_runtime_manifest makes. A comparison sample's 2D texture (comparison_texture_srv) binds like a plain texture input. A refused native translation clears the samplers so a published manifest read next numbers its sampler lines from 0. A natively bound 2D texture input now sets slot.srv_dimension. The dispatch path treats any other value as a described 1D, 2D-array or 3D view and refused the input as "not 3D". Sampler words that are not constants (a sampler read from memory) are refused by the compiler before this code runs, so the route itself no longer has a sampler refusal; the capacity message drops that clause. startup_compute_dispatch_native_check.py gains step 5: four samples of a two-mip 2x1 R32_FLOAT texture (new consumer mode texture-volume-native-sampled) through four constant samplers: wrap, mirror under a MAX_LOD clamp, clamp under a MIN_LOD clamp, and a LESS comparison. Every stored word is compared with a CPU model of the sampler words. A sampler loaded from the table stays refused with the volume untouched. Refs #3149 AI-assisted. Co-Authored-By: Claude Mythos 5.2 --- src/startup_stubs/d3d12_compute_dispatch.inl | 22 ++- .../startup_compute_dispatch_native_check.py | 132 +++++++++++++++++- tests/startup_stream_consumer.cpp | 28 +++- 3 files changed, 175 insertions(+), 7 deletions(-) diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index ce571a0f8f..16be236063 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -278,7 +278,8 @@ const char* load_compute_translation(ComputeTranslation& tr) // X2W_NATIVE_SHADERS=: the first Dispatch of a slot 67 request translates // it in this process with the C++ compiler (src/gfx1013_compute_native.cpp), before a published .txt is read // and with no offline translator running. The dispatch path below binds the result, so a program is accepted only -// with root constants, raw table buffers and exact-width typed texture outputs. +// with root constants, raw table buffers and exact-width typed texture outputs. The constant sampler words the +// compiler resolved become static samplers. // A refusal is logged and leaves the key to the published translations. draw_lock held. Returns whether tr is ready. bool translate_compute_natively(ComputeTranslation& tr) { @@ -291,6 +292,7 @@ bool translate_compute_natively(ComputeTranslation& tr) tr.uds.clear(); tr.srvs.clear(); tr.uavs.clear(); + tr.samplers = {}; // a published manifest read next numbers its sampler lines from 0 tr.root.Reset(); tr.pipeline.Reset(); static LONG logged; @@ -336,7 +338,10 @@ bool translate_compute_natively(ComputeTranslation& tr) const unsigned channels = x2w::exact_texture_uav_channels(view.kind); const bool packed_x = view.kind == x2w::ComputeViewKind::packed_d16_x_uav; const bool half_typed = packed_x || view.kind == x2w::ComputeViewKind::half_buffer_uav; - const bool texture_input = view.kind == x2w::ComputeViewKind::texture_srv && view.image_dimension == 1; + // A comparison sample reads its 2D texture through the same kind of view as a plain one. + const bool texture_input = (view.kind == x2w::ComputeViewKind::texture_srv || + view.kind == x2w::ComputeViewKind::comparison_texture_srv) && + view.image_dimension == 1; const bool volume = view.kind == x2w::ComputeViewKind::texture_uav && view.image_dimension == 2; const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || volume || channels; auto& slots = output ? tr.uavs : tr.srvs; @@ -346,6 +351,8 @@ bool translate_compute_natively(ComputeTranslation& tr) " is not bound for a natively translated program"); slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset), volume || texture_input}); if (volume) slots.back().uav_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; + // The dispatch path takes an input of any other dimension for a described 1D, 2D-array or 3D view. + if (texture_input) slots.back().srv_dimension = D3D12_SRV_DIMENSION_TEXTURE2D; slots.back().half_typed_bytes = half_typed ? view.required_bytes : 0; slots.back().packed_d16_x = packed_x; if (x2w::accepts_cbv_window(view.kind)) @@ -359,8 +366,15 @@ bool translate_compute_natively(ComputeTranslation& tr) D3D12_UAV_DIMENSION_TEXTURE2D; } } - if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) - throw std::runtime_error("a sampler, or more entry values, inputs or outputs than the dispatch path binds"); + // Static samplers in register order, flagged as the manifest writer names them: smpc, else smpl, else smp. + // The compiler has already refused sampler words that are not constants (a sampler read from memory). + for (const auto& sampler : program.samplers) { + tr.samplers.statics.push_back(sampler.words); + tr.samplers.comparison.push_back(sampler.comparison); + tr.samplers.lod_limits.push_back(sampler.explicit_lod && !sampler.comparison); + } + if (tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) + throw std::runtime_error("more entry values, inputs or outputs than the dispatch path binds"); // A direct module declares wave size 32 (src/dxil_module.h): without it the pipeline cannot be created. D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) || diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 02b5432cf5..19842660f1 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -18,9 +18,17 @@ dispatches case A through the published translation. All 320 words match. 4. Order: the first program runs again, now with a published translation in the cache. The native translation is still the one used, and all 320 words match. +5. Constant samplers (#3149): four samples of a two-mip 2x1 R32_FLOAT texture feed a 3D float image store, each + through its own constant sampler: image_sample_lz (wrap), image_sample_l with LOD 1.25 under a [0, 0] clamp + (mirror), image_sample_l with LOD 0 under a [1, 1] clamp, and image_sample_c_lz (LESS). U and the reference + double with the global X, so the eight threads of a row cover both texels, the three address modes and both + comparison results. Every volume word is compared with a CPU model of the sampler words. Control: with the first + sampler's words loaded from memory (the table) instead, the C++ compiler refuses the program and the volume + keeps its words. -A direct compute module declares wave size 32. On an adapter without 32-lane waves, step 1 instead checks that the -native translation is refused by that name with the output untouched, steps 2 and 3 run as written, step 4 runs the +A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1 and 5 instead check that +the native translation is refused by that name with the output untouched (the memory sampler control runs as +written), steps 2 and 3 run as written, step 4 runs the first program through its published translation, and the check exits 77. Exit 77 also when the adapter is not available. """ @@ -32,13 +40,42 @@ import tempfile import startup_gfx2hlsl_compute_check as C +import startup_compute_dispatch_texture_check as T +import startup_compute_image_store_check as A +import startup_gfx2hlsl_image_store_3d1d_check as V from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_translate_check import state_a from startup_stream_check import gfx2hlsl as G LOAD_X8 = bytes.fromhex('05030cf4' '000000fa') LOADS_X4 = bytes.fromhex('050308f4' '000000fa' '050408f4' '200000fa') RECORD_LOADS = ['s_load_dwordx4 s[12:15], s[10:11], 0x0', 's_load_dwordx4 s[16:19], s[10:11], 0x20'] NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' +# Step 5. Sampler words [address, LOD limits, filter, border] in register order: U address mode in bits 2:0 over +# clamp V, MIN_LOD and MAX_LOD as 4.8 fixed point in bits 11:0 and 23:12 of word 1, point filters. +WRAP, MIRROR, CLAMP, POINT_MIP = 0, 1, 2, 1 << 26 +SAMPLERS = ( + (WRAP | CLAMP << 3, 0xfff << 12, POINT_MIP, 0), # image_sample_lz + (MIRROR | CLAMP << 3, 0, POINT_MIP, 0), # image_sample_l, LOD 1.25: MAX_LOD 0 keeps mip 0 + (CLAMP | CLAMP << 3, 0x100 << 12 | 0x100, POINT_MIP, 0), # image_sample_l, LOD 0: MIN_LOD 1 selects mip 1 + (CLAMP | CLAMP << 3 | 1 << 12 | 1 << 27, 0, 0, 0), # image_sample_c_lz: LESS, point +) +U_BASE, REFERENCE_BASE = 0x3e99999a, 0xbe400000 # 0.3 and -0.1875: adding X << 23 doubles them X times +SAMPLED_PROGRAM = [ + 's_load_dwordx8 s[24:31], s[12:13], 0x20', 's_waitcnt lgkmcnt(0)', + *('s_mov_b32 s%d, 0x%x' % (40 + i, word) for i, word in enumerate(w for words in SAMPLERS for w in words)), + 's_mov_b32 s56, 0x3e99999a', 's_mov_b32 s57, 0xbe400000', + 'v_lshl_add_u32 v12, v2, 23, s56', 'v_mov_b32_e32 v13, 0x3e800000', 'v_mov_b32_e32 v14, 0x3fa00000', + 'image_sample_lz v8, v[12:13], s[24:31], s[40:43] dmask:0x1 dim:SQ_RSRC_IMG_2D', + 'image_sample_l v9, v[12:14], s[24:31], s[44:47] dmask:0x1 dim:SQ_RSRC_IMG_2D', + 'v_mov_b32_e32 v14, 0', + 'image_sample_l v10, v[12:14], s[24:31], s[48:51] dmask:0x1 dim:SQ_RSRC_IMG_2D', + 'v_lshl_add_u32 v15, v2, 23, s57', 'v_mov_b32_e32 v16, v12', 'v_mov_b32_e32 v17, v13', + 'image_sample_c_lz v11, v[15:17], s[24:31], s[52:55] dmask:0x1 dim:SQ_RSRC_IMG_2D', + 's_waitcnt vmcnt(0) lgkmcnt(15)', +] +MEMORY_SAMPLER = 's_load_dwordx4 s[40:43], s[12:13], 0x60' +MEMORY_SAMPLER_REFUSAL = 'nonconstant sampler' def mismatch(got, expected, result): @@ -80,6 +117,96 @@ def scalar_window_case(consumer, dxc_dir, adapter): assert lines(result, 'refused: an input is in title memory outside any placed buffer'), result.stderr[-3000:] +def sampled_program(memory_sampler): + def s_mov(register, word): + return struct.pack('<2I', 0xbe8003ff | register << 16, word) + + def scaled(register, base): # v_lshl_add_u32 v, v2, 23, s + return struct.pack('<2I', 0xd7460000 | register, 0x102 | 151 << 9 | base << 18) + + def image(op, data, address, sampler): + return struct.pack('<2I', 0xf0000108 | op << 18, address | data << 8 | 6 << 16 | sampler // 4 << 21) + + # Keep the volume fixture's table pointer, UAV descriptor, coordinates and final store. + wait = bytes.fromhex('7fc08cbf') + prologue, _, tail = V.program('volume').partition(wait) + words = [word for sampler in SAMPLERS for word in sampler] + body = (bytes.fromhex('06060cf4200000fa') + wait + b''.join(s_mov(40 + i, word) for i, word in enumerate(words)) + + s_mov(56, U_BASE) + s_mov(57, REFERENCE_BASE) + scaled(12, 56) + + struct.pack('<4I', 0x7e1a02ff, 0x3e800000, 0x7e1c02ff, 0x3fa00000) # V 0.25, LOD 1.25 + + image(39, 8, 12, 40) + image(36, 9, 12, 44) + bytes.fromhex('80021c7e') + image(36, 10, 12, 48) + + scaled(15, 57) + bytes.fromhex('0c03207e' '0d03227e') + image(47, 11, 15, 52) + bytes.fromhex('700f8cbf')) + assert [i[3] for i in G.decode(body)] == SAMPLED_PROGRAM, G.decode(body) + if memory_sampler: # after the literal words, so the sample reads the loaded ones + body = body.replace(scaled(12, 56), bytes.fromhex('060a08f4600000fa') + scaled(12, 56)) + assert MEMORY_SAMPLER in [i[3] for i in G.decode(body)] + return prologue + body + tail[32:] # the four samples replace the four literal moves + + +def sampled_reference(x, mips): + """The four words thread x stores: what each sampler's address mode, LOD clamp and comparison select.""" + def f32(bits): + return struct.unpack('> 12 & 0xfff) / 256 + mip = mips[min(int(min(max(lod, low), high) + 0.5), len(mips) - 1)] # point mip filter + u = f32(U_BASE + (x << 23)) + u = u % 1 if address & 7 == WRAP else 1 - abs(u % 2 - 1) if address & 7 == MIRROR else min(max(u, 0), 1) + return mip[min(int(u * len(mip)), len(mip) - 1)] + + assert SAMPLERS[3][0] >> 12 & 7 == 1, 'the model compares with LESS' + passed = f32(REFERENCE_BASE + (x << 23)) < f32(texel(3, 0)) + return texel(0, 0), texel(1, 1.25), texel(2, 0), 0x3f800000 if passed else 0 + + +def sampled_views(directory, consumer, dxc_dir, adapter, no_waves): + cache, env = prepare_case(directory, adapter) + env['X2W_NATIVE_SHADERS'] = dxc_dir + # The guest table: two SRV records (the texture is record 1), then one UAV in record 2. + blob = bytearray(C.root_blob(3, table_range=True)[:-24]) + blob.extend(struct.pack('<12I', 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2)) + payload = 44 # DXBC header, part offset, and RTS0 part header + struct.pack_into(' 2, rows + + for memory_sampler in (False, True): + (directory / 'program').write_bytes(sampled_program(memory_sampler)) + got, result = T.run(directory, consumer, env, 'texture-volume-native-sampled', '<%dI' % len(initial)) + if memory_sampler or no_waves: + reason = lines(result, 'not translated natively: ') + want = MEMORY_SAMPLER_REFUSAL if memory_sampler else NO_WAVES.split(': ')[1] + assert len(reason) == 1 and want in reason[0], result.stderr[-3000:] + assert len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1, result.stderr[-3000:] + assert got == initial, 'a refused Dispatch wrote the volume' + continue + assert len(lines(result, 'translated natively: 3 entry values, 2 inputs, 1 outputs')) == 1, result.stderr[-3000:] + assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] + wrong = [i for i in range(len(got)) if got[i] != expected[i]] + assert not wrong, 'sampled: word %d got=%08x expected=%08x (%d words differ)\n%s' % ( + wrong[0], got[wrong[0]], expected[wrong[0]], len(wrong), result.stderr[-3000:]) + print('constant samplers: all %d volume words match the CPU model (wrap, mirror with MAX_LOD, clamp with ' + 'MIN_LOD, LESS comparison); debug layer: %s' % (len(got), T.clean(result))) + assert all(p.name.startswith('req_') or p.name in ('native', 'revision.txt') for p in cache.iterdir()) + + def main(consumer, dxc_dir, adapter): scalar_window_case(consumer, dxc_dir, adapter) with tempfile.TemporaryDirectory() as temporary: @@ -139,6 +266,7 @@ def main(consumer, dxc_dir, adapter): assert bool(lines(result, f'{key32:016x} translated natively')) != no_waves, result.stderr[-3000:] assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1, result.stderr[-3000:] + sampled_views(directory / 'sampled', consumer, dxc_dir, adapter, no_waves) controls = ('the C++ compiler refuses case A with every word untouched, and a published translation then runs ' 'it') if no_waves: diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 092b6e91e0..79ec23aac8 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -750,7 +750,11 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string { constexpr UINT width = 32; const bool exact = mode.rfind("texture-exact-", 0) == 0; - const bool volume = mode == "texture-volume" || mode == "texture-volume-bad-w" || mode == "texture-exact-volume"; + // texture-volume-native-sampled: the volume store, plus a 2x1 R32_FLOAT texture (a format a comparison sample + // reads) with a 1x1 second mip, whose shader resource view token is copied to table byte 32. + const bool sampled = mode == "texture-volume-native-sampled"; + const bool volume = sampled || mode == "texture-volume" || mode == "texture-volume-bad-w" || + mode == "texture-exact-volume"; const bool line = mode == "texture-line" || mode == "texture-line-bad-mip"; const UINT first_mip = volume || line ? 1 : 0; const UINT height = line ? 1 : 8; @@ -884,6 +888,18 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string 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); + void* input_texture = nullptr; + if (sampled) { + const D3D12_RESOURCE_DESC input_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 2, 1, 1, 2, DXGI_FORMAT_R32_FLOAT, {1, 0}}; + input_texture = make(D3D12_HEAP_TYPE_DEFAULT, input_desc, D3D12_RESOURCE_STATE_COMMON); + if (!input_texture) return 71; + D3D12_SHADER_RESOURCE_VIEW_DESC input_view{DXGI_FORMAT_R32_FLOAT, D3D12_SRV_DIMENSION_TEXTURE2D, + D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + input_view.Texture2D.MipLevels = 2; + // Created at handle 0 and copied to table byte 32, which is not a handle where the increment is above 32. + invoke(device, 18, word(input_texture), word(&input_view), cpu); + std::memcpy(reinterpret_cast(cpu + 32), reinterpret_cast(cpu), 32); + } const auto transfer = [&](void* buffer, bool to_texture) { for (UINT layer = 0; layer < subresources; ++layer) for (UINT mip = 0; mip < mips; ++mip) { @@ -897,6 +913,16 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string const UINT constants[3] = {1, 2, 3}; if (FAILED(static_cast(invoke(list, 139, word(allocator))))) return 74; invoke(list, 32, 1, word(&heap)); + // Mip 0 takes the first two sentinel words of the upload, mip 1 the word at byte 512 (word 128). + for (UINT mip = 0; input_texture && mip < 2; ++mip) { + D3D12_TEXTURE_COPY_LOCATION input_image{static_cast(input_texture), + D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + input_image.SubresourceIndex = mip; + D3D12_TEXTURE_COPY_LOCATION input_source{static_cast(upload), + D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + input_source.PlacedFootprint = {mip * 512u, {DXGI_FORMAT_R32_FLOAT, 2u >> mip, 1, 1, pitch}}; + invoke(list, 16, word(&input_image), 0, 0, 0, word(&input_source), 0); + } transfer(upload, true); invoke(list, 25, word(slot67_pipeline)); invoke(list, 33, word(slot67_root)); From 93582447f0393b10bb3c1f4e91010ca1d21aa073 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 16:30:59 +0200 Subject: [PATCH 2/2] docs: record the constant sampler run on the in-process compute route docs/experiments/startup-compute-native-samplers.md describes what translate_compute_natively binds for a constant sampler, the four-sampler fixture and its memory sampler control, the hardware results on an RTX 4090, the WARP capability skip and six mutations of the change. docs/startup-runtime.md and the route note no longer list every sampler among the refusals. Refs #3149 AI-assisted. Co-Authored-By: Claude Mythos 5.2 --- .../startup-compute-native-dispatch.md | 6 +- .../startup-compute-native-samplers.md | 106 ++++++++++++++++++ docs/startup-runtime.md | 7 +- 3 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 docs/experiments/startup-compute-native-samplers.md diff --git a/docs/experiments/startup-compute-native-dispatch.md b/docs/experiments/startup-compute-native-dispatch.md index 2af49da9b7..c35093e7e0 100644 --- a/docs/experiments/startup-compute-native-dispatch.md +++ b/docs/experiments/startup-compute-native-dispatch.md @@ -15,7 +15,9 @@ cache and no offline translator, and compares all 320 output words with a CPU re dispatch path then resolves the table descriptors, sets the resource states and records the Dispatch. Accepted: root constants, a raw table buffer loaded per lane and a raw table buffer stored to. These are the -bindings the fixture runs. Refused: every other view kind (a scalar buffer load included), a sampler, more than +bindings the fixture runs; a later step samples a 2D texture through constant samplers +([note](startup-compute-native-samplers.md)). Refused: every other view kind (a scalar buffer load included), +a sampler read from memory, more than 32 entry values or inputs or 8 outputs, an adapter without 32-lane waves, and whatever the frontend refuses. The stand-in logs the first 16 refusals of a process with their reason. A refused key is left to a published translation. The in-process translation is tried once per key and before a published `.txt`. @@ -80,7 +82,7 @@ ctest --preset dev --no-tests=error -V -R '^(startup_compute_dispatch(_.*)?|star ## Limits - Compute only. Graphics pipelines are not translated in-process. -- A scalar buffer load, a texture, a sampler and the typed, half and indexed views are refused. This is the +- A scalar buffer load, a sampler read from memory and the typed, half and indexed views are refused. This is the in-process route. The published-manifest route (`.txt` from `compile_dxil --requests`) binds a title's 1D, 2D, 2D-array and 3D texture SRV (`srv N tex1d|tex2d|tex2da|tex3d table R B`). For 1D, 2D-array and 3D the title's view must be described, have the manifest's dimension and fit its texture, otherwise the diff --git a/docs/experiments/startup-compute-native-samplers.md b/docs/experiments/startup-compute-native-samplers.md new file mode 100644 index 0000000000..27cb864337 --- /dev/null +++ b/docs/experiments/startup-compute-native-samplers.md @@ -0,0 +1,106 @@ +# Constant static samplers on the in-process compute route (#3149) + +With `X2W_NATIVE_SHADERS` set, the stand-in translates a slot 67 compute request with the C++ compiler at its +first Dispatch ([route](startup-compute-native-dispatch.md)). Until this change it refused every program that +samples. The compiler already resolves a sampler whose four words are constants into a `ComputeSampler`, and +`translate_compute_natively` (`src/startup_stubs/d3d12_compute_dispatch.inl`) now turns those into the static +samplers of the translated root signature, in register order. + +## What is bound + +- A comparison sampler (`comparison`) is bound as a comparison static sampler, as an `smpc` manifest line is. +- Any other sampler with `explicit_lod` carries the descriptor's MIN_LOD and MAX_LOD, as an `smpl` line does. + The direct compute path sets `explicit_lod` on every sampler it emits (`sample || implicit` in + `src/gfx1013_direct_compute.inl`, and the gathers through `gather_base_level`), so this route produces no + plain `smp` sampler. The conversion keeps that case, but no compute program reaches it. +- The texture of a comparison sample (`comparison_texture_srv`, 2D) is bound like a plain 2D texture input. +- A natively bound 2D texture input sets the slot's input dimension. Without it the dispatch path takes the + input for a described 1D, 2D-array or 3D view and refuses the Dispatch with "an input texture view is not 3D", + so no natively translated program could read a 2D texture. +- A failed native translation clears its samplers, so a published `.txt` read next numbers its sampler + lines from 0. + +The route has no refusal that names a sampler. Sampler words that are neither constants nor one entry of the +sampler heap are refused by the compiler ("nonconstant sampler") before the stand-in binds anything. A +fixed-index sampler of the directly indexed sampler heap (#3140) reaches the route as a `heap_sampler` view, +which is not bound and is refused by the view-kind message ("view kind N is not bound for a natively +translated program"). That is read from the code, not run here; binding that heap is the follow-up of #3076. +The capacity refusal now reads "more entry values, inputs or outputs than the dispatch path binds". + +## Fixture + +Step 5 of [`startup_compute_dispatch_native_check.py`](../../tests/startup_compute_dispatch_native_check.py), +source-built. The consumer mode `texture-volume-native-sampled` is the 3D float store of `texture-volume` plus a +2x1 R32_FLOAT texture with a 1x1 second mip, whose three texels hold different sentinel words. One program samples it four times and +stores the four results as the channels of a 3D float texture: + +| Channel | Instruction | Sampler words | What it selects | +|---|---|---|---| +| 0 | `image_sample_lz` | wrap U, MAX_LOD 15.996 | mip 0, wrapped texel | +| 1 | `image_sample_l`, LOD 1.25 | mirror U, MIN_LOD 0, MAX_LOD 0 | mip 0 (the clamp), mirrored texel | +| 2 | `image_sample_l`, LOD 0 | clamp U, MIN_LOD 1, MAX_LOD 1 | mip 1 (the clamp) | +| 3 | `image_sample_c_lz` | clamp, LESS, point | 1.0 where the reference is below the texel, else 0.0 | + +U is 0.3 and the reference -0.1875, each doubled once per global X. The eight threads of a row therefore read +both texels under wrap and mirror in different threads, and the comparison passes in six threads and fails in +two. All filters are point filters, so the result is exact. Every one of the 6,144 volume words is compared +with a CPU model that decodes the address mode, the LOD limits and the comparison from the sampler words. + +Control: the same program with the first sampler's words loaded from the descriptor table +(`s_load_dwordx4 s[40:43], s[12:13], 0x60`) is refused with "nonconstant sampler", the Dispatch is refused with +"no translation", and every volume word keeps its sentinel. + +## Command and result + +```powershell +.\tools\dev.ps1 +cmake --build --preset dev --target d3d12_xs_shim startup_stream_consumer compile_dxil +ctest --preset dev --no-tests=error -V -R '^(startup_compute_dispatch_native_(hardware|warp)|native_image_store_exact_width_hardware_(r|rg|rgb|array|volume|rgba|sparse)|startup_compute_dispatch_texture_hardware|startup_compute_descriptor_scc_hardware)$' +``` + +Commit `af6045df` on `main` at `f5a6f6ba`, Windows 11 build 26300.9974, Debug build, MSVC 14.44.35207, Windows +SDK 10.0.26100 DXC, D3D12 debug layer enabled. 11 tests selected: 10 passed, 1 capability skip, 0 failed. + +| Test | Adapter, driver | Result | +|---|---|---| +| `startup_compute_dispatch_native_hardware` | NVIDIA GeForce RTX 4090, 32.0.16.1088 | PASS. The four sampled channels match the CPU model in all 6,144 volume words, the memory sampler control leaves the volume untouched, and the other steps of the check pass. No debug-layer error message. | +| `native_image_store_exact_width_hardware_{r,rg,rgb,array,volume,rgba,sparse}` | the same | PASS (7 tests). These dispatch exact-width outputs through the same binding loop. | +| `startup_compute_dispatch_texture_hardware` | the same | PASS. It shares the consumer's texture modes. | +| `startup_compute_descriptor_scc_hardware` | the same | PASS. | + +Capability skip, not a pass: `startup_compute_dispatch_native_warp` exits 77 on the Microsoft Basic Render +Driver 10.0.26100.9818, which reports no 32-lane waves. Before it exits, the check confirms that the sampled +program is refused by that capability reason with the volume untouched, and that the memory sampler control is +refused with "nonconstant sampler". + +Earlier revisions of this change, stacked on #3049, gave the same result for the sampled step on `main` at +`429f11d5`, `7fcde81f` and `ee3347d3`. + +## Mutations + +Each mutation was applied to `src/startup_stubs/d3d12_compute_dispatch.inl` at `af6045df` on its own, the +stand-in rebuilt, `startup_compute_dispatch_native_hardware` run, and the file restored. + +| Mutation | Result | +|---|---| +| The file as on `main` (`f5a6f6ba`) | FAIL at the sampled program: `not translated natively: view kind 11 is not bound for a natively translated program`. The comparison texture view is refused before the sampler check is reached. | +| Only the sampler check restored; the comparison view stays accepted | FAIL at the sampled program: `not translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path binds`. | +| The 2D input dimension left unset | FAIL: the program translates, then `Dispatch(2, 1, 1) refused: an input texture view is not 3D`. | +| `lod_limits` always false | FAIL: `sampled: word 2049 got=bf000080 expected=bf000000 (32 words differ)`. Channels 1 and 2 of all 16 threads read the other mip. | +| `comparison` always false | FAIL: `sampled: word 2051 got=bf000080 expected=00000000 (16 words differ)`. Channel 3 of all 16 threads holds a texel, not a comparison result. | +| Samplers bound in reverse register order | FAIL: `sampled: word 2049 got=bf000080 expected=bf000000 (56 words differ)`. | +| Restored | PASS. | + +The comparison and order mutations were caught by the readback, not by a debug-layer message. + +## Limits + +- Constant sampler words only. A sampler read from memory, including the sampler heap, stays refused (#3076). +- One 2D texture format was sampled (R32_FLOAT), with point filters. Linear and anisotropic filters, border + colors and 3D or array textures were not run on this route. +- A plain sampler without LOD limits was not run: the direct compute path does not emit one. +- A comparison sampler is bound without the LOD limits, as on the published route. The compute path compares at + level zero and the compiler requires MIN_LOD 0, so the limits cannot change the result. +- Clearing the samplers after a failed native translation follows from the code (the manifest reader requires + sampler line `i` to be the next entry). No run exercises it. +- One adapter, in a Debug build. No start-up run used the switch. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 4b1a3e002d..6348cecae3 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -1006,8 +1006,11 @@ against their key, translated and compiled to DXIL in the process. The compiler' The existing dispatch path records the result, and a program is accepted only with the bindings a fixture has run through it: root constants, raw table buffers loaded per lane (`buffer_load_dword`) -and raw table buffers stored to, with their descriptors in 32-byte table records. Anything else (a -scalar buffer load, a texture, a sampler, a typed or indexed view, an instruction the compiler does +and raw table buffers stored to, with their descriptors in 32-byte table records. A 2D texture can be +sampled through samplers whose four words are constants: they become static samplers with the +descriptor's MIN_LOD and MAX_LOD, or comparison samplers +([fixture and results](experiments/startup-compute-native-samplers.md)). Anything else (a +scalar buffer load, a sampler read from memory, a typed or indexed view, an instruction the compiler does not lower) is refused. Programs published as `.txt` also bind 1D, 2D, 2D-array and 3D texture SRVs (`srv N tex1d|tex2d|tex2da|tex3d table R B`) from the title's described view of that dimension, or are refused by name; cube texture SRVs are not published. The first 16 refusals of a process are logged as