From 03c22974b459721a1601d34ff1047ba179adcaf3 Mon Sep 17 00:00:00 2001 From: JB2WIN Date: Sat, 28 Nov 2026 05:22:53 +0100 Subject: [PATCH] runtime: bind 1D, 2D-array and 3D texture SRVs for published native compute The published compute manifest now carries `srv N tex1d|tex3d|tex2da table R B` for texture SRVs of those dimensions (cube and multisampled ones keep their named refusal). The Dispatch reader takes the name as the slot's dimension; for 1D, 2D-array and 3D it needs the title's described view of that dimension that fits its texture (address_view_fits: same or typeless-family format, mips and slices inside, no LOD clamp), otherwise the Dispatch is refused by name. An accepted tex2d line binds as before. The refusal text for an srv line that is not read now names the new dimensions. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EF3hKGcUDvQ6pxjDDMrvbn --- .../native-compile-dxil-refusals.md | 3 +- .../startup-compute-native-dispatch.md | 8 +- docs/startup-runtime.md | 4 +- src/direct_compute_cache.cpp | 12 +- src/startup_stubs/d3d12_compute_dispatch.inl | 32 +++- ...tartup_compute_dispatch_texture_dims.cmake | 8 + tests/native_compute_manifest_reasons.cpp | 31 +++- ...tup_compute_dispatch_texture_dims_check.py | 167 ++++++++++++++++++ ...startup_compute_root_srv_dispatch_check.py | 6 +- tests/startup_stream_consumer.cpp | 59 +++++++ 10 files changed, 315 insertions(+), 15 deletions(-) create mode 100644 tests/cmake/startup_compute_dispatch_texture_dims.cmake create mode 100644 tests/startup_compute_dispatch_texture_dims_check.py diff --git a/docs/experiments/native-compile-dxil-refusals.md b/docs/experiments/native-compile-dxil-refusals.md index 2f5133d110..090ad0bf15 100644 --- a/docs/experiments/native-compile-dxil-refusals.md +++ b/docs/experiments/native-compile-dxil-refusals.md @@ -25,7 +25,8 @@ exit: a zero group dimension, root constants above parameter 15 or more than 8 in one parameter, more than 32 user data words, a resource or sampler heap view, a view above root parameter 15, non-contiguous SRV or UAV registers, an SRV or UAV kind with no manifest line (the kind, and for - images the dimension and `array`), more than 32 SRVs or 8 UAVs, a comparison sampler, and stride + images the dimension and `array`; a texture SRV of dimension 1D, 2D, 3D or 2D array has a line, a + cube or multisampled one does not), more than 32 SRVs or 8 UAVs, a comparison sampler, and stride words from a view that is not one raw vector SRV. No register numbers, offsets or keys. - `--requests` still publishes `.cs.cso` and no `.txt`, still counts the request as compiled and still removes `.fail`. It prints the reason in that job's report as diff --git a/docs/experiments/startup-compute-native-dispatch.md b/docs/experiments/startup-compute-native-dispatch.md index bafceee393..2af49da9b7 100644 --- a/docs/experiments/startup-compute-native-dispatch.md +++ b/docs/experiments/startup-compute-native-dispatch.md @@ -80,7 +80,13 @@ 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. +- A scalar buffer load, a texture, a sampler 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 + Dispatch is refused (on a dimension mismatch the draw path binds a null view instead). "Fits" is + `address_view_fits`: the view format is the storage format or a member of its typeless family, the mip and + slice range lie inside the texture, and ResourceMinLODClamp is 0. Cube texture SRVs are not published. - One descriptor shape was dispatched: stride 4 and 320 records, for the input and for the output. - An indirect Dispatch of a natively translated program was not run. - A captured request starts with a 36-byte prefix of `v_nop` words before `s_inst_prefetch`. The route passes diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 9a423e7125..b404470135 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -1010,7 +1010,9 @@ The existing dispatch path records the result, and a program is accepted only wi 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 -not lower) is refused. The first 16 refusals of a process are logged as +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 `compute pipeline not translated natively: `. A refused key is left to the published translations, so `-Translate` can run beside it for those pipelines. A direct module declares wave size 32, so an adapter without 32-lane waves refuses every program by that name. The in-process diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 2c4ad29e47..e926ea1893 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -797,9 +797,15 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh b.kind == ComputeViewKind::byte_window_srv) { srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset << '\n'; - } else if (b.kind == ComputeViewKind::texture_srv && b.image_dimension == 1 && b.array_count == 1) { - srv_lines << "srv " << b.shader_register << " tex2d table " << b.root_parameter << ' ' << b.byte_offset - << '\n'; + } else if (b.kind == ComputeViewKind::texture_srv && b.array_count == 1 && + (b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 || + b.image_dimension == 5)) { + const char *tex = b.image_dimension == 0 ? "tex1d" + : b.image_dimension == 1 ? "tex2d" + : b.image_dimension == 2 ? "tex3d" + : "tex2da"; + srv_lines << "srv " << b.shader_register << ' ' << tex << " table " << b.root_parameter << ' ' + << b.byte_offset << '\n'; } else { return refuse(view_shape("SRV", b)); } diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index e0cb2a5a3c..b05bcf9fea 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -3,7 +3,7 @@ // .cs.cso. Bound from the compute tables recorded by slot 35 and compute root SRVs recorded by slot 43: raw // buffers (`srv buf table ` and `srv buf root ` inputs, `uav table ` // outputs) named by hardware buffer descriptors or 64-bit root SRV addresses, and textures -// (`srv tex2d table ` inputs, `uav tex1d/tex2d/tex2da/tex3d float table channels ` outputs) named +// (`srv tex1d|tex2d|tex2da|tex3d table ` inputs, `uav tex1d/tex2d/tex2da/tex3d float table channels ` outputs) named // by the token of a view the title created (device slots 18 and 19). `smp`, `smpl` and `smpc` lines become static samplers. Entry // values come from the compute root constants of slots 37 and 39, or from the descriptor a buffer input or output is // bound from: its stride and word 3 (`stride`, `descword3`), and word 3, the upper half of word 1 and the record @@ -37,6 +37,7 @@ struct ComputeTranslation { bool root = false; bool atomic_uint_texture = false; unsigned channels = 4; + D3D12_SRV_DIMENSION srv_dimension = D3D12_SRV_DIMENSION_UNKNOWN; }; u64 key = 0; int state = 0; // 0 not loaded, 1 ready, 2 unavailable @@ -163,6 +164,13 @@ const char* load_compute_translation(ComputeTranslation& tr) if (!std::strcmp(name, "tex3d")) return D3D12_UAV_DIMENSION_TEXTURE3D; return D3D12_UAV_DIMENSION_UNKNOWN; }; + const auto srv_dimension = [&] { + if (!std::strcmp(name, "tex1d")) return D3D12_SRV_DIMENSION_TEXTURE1D; + if (!std::strcmp(name, "tex2d")) return D3D12_SRV_DIMENSION_TEXTURE2D; + if (!std::strcmp(name, "tex2da")) return D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + if (!std::strcmp(name, "tex3d")) return D3D12_SRV_DIMENSION_TEXTURE3D; + return D3D12_SRV_DIMENSION_UNKNOWN; + }; if (line.empty() || (std::sscanf(line.c_str(), "group %u %u %u%n", &x, &y, &z, &used) == 3 && whole())) continue; if (std::sscanf(line.c_str(), "ud %u%n", &declared_uds, &used) == 1 && whole()) continue; if (std::sscanf(line.c_str(), "udsrc %u rootconst %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uds.size()) @@ -201,8 +209,11 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.uavs.back().uav_dimension = uav_dimension(); tr.uavs.back().channels = x; } - else if (std::sscanf(line.c_str(), "srv %u tex2d table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size()) + else if (std::sscanf(line.c_str(), "srv %u %15s table %d %d%n", &i, name, &a, &b, &used) == 4 && whole() && + i == tr.srvs.size() && srv_dimension() != D3D12_SRV_DIMENSION_UNKNOWN) { tr.srvs.push_back({a, b, true}); + tr.srvs.back().srv_dimension = srv_dimension(); + } // A static sampler, decoded as the draw path does: plain (smp), with the descriptor's LOD clamp (smpl) or a // comparison one (smpc). Not modelled here: the run-time sampler heap table (smpheap). else if (line.rfind("smpheap", 0) == 0) return "a sampler from the sampler heap"; @@ -211,7 +222,7 @@ const char* load_compute_translation(ComputeTranslation& tr) std::sscanf(line.c_str(), "smpc %u %x %x %x %x%n", &i, &x, &y, &z, &w, &used) == 5) && whole() && i == tr.samplers.statics.size()) tr.samplers.read_manifest_line(line.c_str()); - else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 2D texture" + else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 1D/2D/2D-array/3D texture" : line.rfind("uav", 0) == 0 ? "an output that is not a raw table buffer or a 1D/2D/2D-array/3D float texture" : line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant or a buffer descriptor word" : line.rfind("smp", 0) == 0 ? "a sampler that is not a plain static one" : "an unknown manifest line"; @@ -515,6 +526,21 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& if (!known || record.slot != 18) reason = "an input texture entry is not the token of a shader resource view"; else if (!texture || (resource.Flags & D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE)) reason = "an input texture has no desktop texture to sample"; + else if (slot.srv_dimension != D3D12_SRV_DIMENSION_TEXTURE2D) { + // 1D, 2D array and 3D: only the title's own described view of that dimension, inside its texture. + const bool one = slot.srv_dimension == D3D12_SRV_DIMENSION_TEXTURE1D; + const bool array = slot.srv_dimension == D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + if (!described) + reason = one ? "an input 1D texture has no recorded view description" + : array ? "an input 2D array texture has no recorded view description" + : "an input 3D texture has no recorded view description"; + else if (desc.ViewDimension != slot.srv_dimension) + reason = one ? "an input texture view is not 1D" : array ? "an input texture view is not 2D array" + : "an input texture view is not 3D"; + else if (!x2w_startup::address_view_fits(resource, desc)) + reason = "an input texture view does not fit its texture"; + else if (x2w_startup::packed_target_format(desc.Format)) reason = "an input texture view has a packed format"; + } else if (described ? desc.ViewDimension != D3D12_SRV_DIMENSION_TEXTURE2D : resource.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D || resource.DepthOrArraySize != 1) reason = "an input texture view is not 2D"; diff --git a/tests/cmake/startup_compute_dispatch_texture_dims.cmake b/tests/cmake/startup_compute_dispatch_texture_dims.cmake new file mode 100644 index 0000000000..e90a58bce4 --- /dev/null +++ b/tests/cmake/startup_compute_dispatch_texture_dims.cmake @@ -0,0 +1,8 @@ +if(EXISTS "${INTAKE_PYTHON}" AND TARGET startup_stream_consumer) + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_dispatch_texture_dims_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_dims_check.py" "$" + "${DXC_EXECUTABLE}" ${adapter}) + set_tests_properties(startup_compute_dispatch_texture_dims_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/native_compute_manifest_reasons.cpp b/tests/native_compute_manifest_reasons.cpp index 95576a8ef9..92d7147f14 100644 --- a/tests/native_compute_manifest_reasons.cpp +++ b/tests/native_compute_manifest_reasons.cpp @@ -3,6 +3,7 @@ #include "native_compute_output.h" #include +#include #include #include @@ -58,9 +59,9 @@ int main() { {"SRV registers not contiguous", [](auto &p) { p.bindings[0].shader_register = 1; }}, {"UAV registers not contiguous", [](auto &p) { p.bindings[1].shader_register = 1; }}, {"SRV kind root_buffer_srv", [](auto &p) { p.bindings[0].kind = K::root_buffer_srv; }}, - {"SRV kind texture_srv 3d", [](auto &p) { + {"SRV kind texture_srv cube", [](auto &p) { p.bindings[0].kind = K::texture_srv; - p.bindings[0].image_dimension = 2; + p.bindings[0].image_dimension = 3; }}, {"SRV kind texture_srv 2d array", [](auto &p) { p.bindings[0].kind = K::texture_srv; @@ -92,6 +93,30 @@ int main() { ok ? "" : manifest ? "a manifest" : reason.c_str()); failures += !ok; } - std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + 1); + // A texture SRV is published under the name of its dimension: the line the runtime's reader takes. + const struct { + unsigned image_dimension; + const char *line; + } published[] = { + {0, "srv 0 tex1d table 1 64\n"}, + {1, "srv 0 tex2d table 1 64\n"}, + {2, "srv 0 tex3d table 1 64\n"}, + {5, "srv 0 tex2da table 1 64\n"}, + }; + for (const auto &c : published) { + auto program = base(); + program.bindings[0].kind = K::texture_srv; + program.bindings[0].image_dimension = c.image_dimension; + reason = "unset"; + const auto manifest = format_compute_runtime_manifest(program, &reason); + std::string wanted = expected; + wanted.replace(wanted.find("srv 0 buf table 1 64\n"), std::strlen("srv 0 buf table 1 64\n"), c.line); + const bool ok = manifest && *manifest == wanted && reason == "unset"; + std::printf("%s publishes %s", ok ? "ok " : "FAIL", c.line); + if (!ok) + std::printf(" | got: %s\n", manifest ? manifest->c_str() : reason.c_str()); + failures += !ok; + } + std::printf("%d of %zu manifest reasons wrong\n", failures, std::size(cases) + std::size(published) + 1); return failures ? 1 : 0; } diff --git a/tests/startup_compute_dispatch_texture_dims_check.py b/tests/startup_compute_dispatch_texture_dims_check.py new file mode 100644 index 0000000000..2081ea54f2 --- /dev/null +++ b/tests/startup_compute_dispatch_texture_dims_check.py @@ -0,0 +1,167 @@ +"""Translated compute programs reading 1D, 2D-array and 3D texture views through the stand-in's Dispatch (slot 14). + +usage: startup_compute_dispatch_texture_dims_check.py + +Case A of startup_gfx2hlsl_compute_check.py with one image_load (for 1D an image_sample_lz at the texel's +center, because gfx2hlsl lowers no 1D image_load) spliced before its store: the texel read is XORed into every +stored word. The program's manifest names the dimension of its texture input (`srv 1 tex1d`, +`tex2da` or `tex3d`, table byte 64). The consumer (dispatch-texdim-<1d|2da|3d>) uploads a described R32_FLOAT +texture, texel (x + 4 y + 16 slice) = 0.25 * (index + 1), subresource by subresource, and creates its view at table byte 64 +(device slot 18): + +- 1d: eight texels, the program reads x = 5 (1.5); +- 2da: 4x4 with six slices, the view starts at slice 1, the program reads x = 1, y = 2, relative slice 2, which + is slice 3 of the texture (14.5); +- 3d: 4x4x4, the program reads x = 3, y = 1, z = 2 (10.0). + +Per dimension: before translation the dispatch is refused with "no translation" and writes nothing; after +gfx2hlsl.py --pending with DXC all 320 words equal case A's words XORed with the texel's bits on the 288 written +words (the rest keep the sentinel). Controls, each refused with one logged reason and an untouched output: +the title's view is a 2D view of a 2D texture (-mismatch), the view has no description (-undescribed), the view +has a ResourceMinLODClamp of 1.0, which does not fit as address_view_fits reads views (-clamped; a view outside the +texture would remove the device when the title creates it), and the published manifest line rewritten to tex2d (and, for +a second mutant, to another non-2D dimension): the runtime must read the manifest's dimension, not the title's. +Exit 77 when the adapter is not available. +""" +from pathlib import Path +import struct +import sys +import tempfile + +import startup_compute_dispatch_texture_check as T +import startup_gfx2hlsl_compute_check as C +from startup_compute_dispatch_check import lines +from startup_compute_request_check import DATA, prepare +from startup_compute_translate_check import state_a +from startup_stream_check import gfx2hlsl as G + +LOAD = 'image_load v12, %s, s[24:31] dmask:0x1 dim:SQ_RSRC_IMG_%s' +# MIMG: dword 0 is 0xf0000000 | dmask << 8 | dim << 3 (1D 0, 3D 2, 2D array 5); dword 1 holds vaddr 8, vdata 12 and +# srsrc 24 / 4 in its three low bytes. The decoder below must read each word back as the text of its dictionary key. +DIM_FIELD = {'1D': 0, '3D': 2, '2D_ARRAY': 5} + +# name: (manifest word, image dim, texel coordinates, expected texel value, refusal word for the view, manifest line) +KINDS = { + '1d': ('tex1d', '1D', (5,), 1.5, '1D', 'srv 1 tex1d table 1 64'), + '2da': ('tex2da', '2D_ARRAY', (1, 2, 2), 14.5, '2D array', 'srv 1 tex2da table 1 64'), + '3d': ('tex3d', '3D', (3, 1, 2), 10.0, '3D', 'srv 1 tex3d table 1 64'), +} +# What the consumer holds: texel (x, y, slice) is 0.25 * (x + 4 y + 16 slice + 1); the 2D-array view starts at slice 1. +FIRST_SLICE = {'1d': 0, '2da': 1, '3d': 0} + + +def texel(kind, coordinates): + x, y, z = (*coordinates, 0, 0)[:3] + return 0.25 * (x + 4 * y + 16 * (z + FIRST_SLICE[kind]) + 1) + + +def vmov(register, value): + return bytes([0x80 + value, 0x02, register * 2, 0x7e]).hex() # v_mov_b32_e32 v, + + +def program(kind): + _, dim, coordinates, _, _, _ = KINDS[kind] + C.SPLICE.update({T.XOR: '05190a3a', 's_waitcnt vmcnt(0)': '703f8cbf'}) + if dim == '1D': + # gfx2hlsl lowers a 1D image only as image_sample, _lz or _l (no image_load), so the texel is read by a + # level-zero sample at its center under the all-zero (wrap, point) sampler of the sample test. + center = struct.unpack('= C.STORE_A][:len(steps)] + assert decoded == [step.replace('_e32', '') for step in steps], decoded + return code + + +def check(directory, consumer, dxc, kind, adapter): + name, dim, coordinates, value, refusal, line = KINDS[kind] + assert texel(kind, coordinates) == value, (kind, texel(kind, coordinates)) + cache, base = prepare(directory) + env = dict(base, X2W_D3D12_LIST_NOOP='1', X2W_D3D12_DEBUG='1') + if adapter == 'hardware': + env['X2W_TEST_DISPATCH_HARDWARE'] = '1' + (directory / 'compute_root').write_bytes(C.root_blob(table_range=True)) + env['X2W_TEST_COMPUTE_ROOT'] = str(directory / 'compute_root') + _, _, rsrc2, group, groups = C.CASES['A'] + assert groups == (3, 2, 2) and (C.KEY, C.STRIDE) == (0x01234567, 0x9e3779b9), 'the consumer hard-codes case A' + code = program(kind) + (directory / 'program').write_bytes(code) + (directory / 'data').write_bytes(DATA) + (directory / 'state').write_bytes(state_a(group, rsrc2)) + bits = struct.unpack('(cpu + 16), reinterpret_cast(cpu + 64), 16); } + if (mode.rfind("dispatch-texdim-", 0) == 0) { + // dispatch-texdim-<1d|2da|3d>[-mismatch|-undescribed|-clamped]: the sampled input is a described R32_FLOAT texture + // of that dimension in the SRV at table byte 64, texel (x + y * 4 + slice * 16) holding 0.25 * (index + 1): + // 1d is 8 texels wide, 2da is 4x4 with six slices (the view starts at slice 1 and spans four), 3d is 4x4x4. + // Each subresource is uploaded by its own copy. -mismatch views a plain 2D texture instead (a view dimension + // that is not the manifest's), -undescribed creates the view without a description, -clamped sets + // ResourceMinLODClamp 1.0 (a valid desktop view that is not a view of the texels as stored; a view outside the + // texture would remove the device when it is created). + const std::string rest = mode.substr(16); + const std::string kind = rest.substr(0, rest.find('-')); + const std::string control = rest.find('-') == std::string::npos ? "" : rest.substr(rest.find('-') + 1); + const bool one = kind == "1d", array = kind == "2da", volume = kind == "3d"; + if (!one && !array && !volume) return 2; + const bool plain = control == "mismatch"; + constexpr DXGI_FORMAT format = DXGI_FORMAT_R32_FLOAT; + const UINT width = one && !plain ? 8 : 4, height = one && !plain ? 1 : 4; + const UINT depth = plain || one ? 1 : array ? 6 : 4; + const D3D12_RESOURCE_DIMENSION dimension = plain || array ? D3D12_RESOURCE_DIMENSION_TEXTURE2D : + one ? D3D12_RESOURCE_DIMENSION_TEXTURE1D : D3D12_RESOURCE_DIMENSION_TEXTURE3D; + const D3D12_RESOURCE_DESC texture_desc{dimension, 0, width, height, static_cast(depth), 1, format, {1, 0}}; + constexpr UINT pitch = D3D12_TEXTURE_DATA_PITCH_ALIGNMENT, slice_bytes = pitch * 4; + const D3D12_RESOURCE_DESC upload_desc{D3D12_RESOURCE_DIMENSION_BUFFER, 0, 8192, 1, 1, 1, DXGI_FORMAT_UNKNOWN, {1, 0}, + D3D12_TEXTURE_LAYOUT_ROW_MAJOR}; + void* const texture = make_committed(device, D3D12_HEAP_TYPE_DEFAULT, texture_desc, D3D12_RESOURCE_STATE_COMMON); + void* const upload = make_committed(device, D3D12_HEAP_TYPE_UPLOAD, upload_desc, D3D12_RESOURCE_STATE_GENERIC_READ); + void* texel = nullptr; + if (!texture || !upload || FAILED(static_cast(invoke(upload, 8, 0, 0, word(&texel)))) || !texel) return 80; + std::memset(texel, 0, 8192); + for (UINT z = 0; z < depth; ++z) + for (UINT y = 0; y < height; ++y) + for (UINT x = 0; x < width; ++x) { + const float value = 0.25f * static_cast(x + y * 4 + z * 16 + 1); + std::memcpy(static_cast(texel) + z * slice_bytes + y * pitch + x * 4, &value, sizeof(value)); + } + invoke(upload, 9, 0, 0); + // A 3D texture is one subresource whose footprint spans its depth; a 2D one has a subresource per slice. + const UINT copies = volume ? 1 : depth; + for (UINT i = 0; i < copies; ++i) { + D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + image.SubresourceIndex = i; + D3D12_TEXTURE_COPY_LOCATION source{static_cast(upload), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + source.PlacedFootprint = {UINT64{i} * slice_bytes, {format, width, height, volume ? depth : 1, pitch}}; + invoke(list, 16, word(&image), 0, 0, 0, word(&source), 0); + } + D3D12_SHADER_RESOURCE_VIEW_DESC view{format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + const float clamp = control == "clamped" ? 1.0f : 0.0f; + if (plain) view.Texture2D.MipLevels = 1; + else if (one) { + view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE1D; + view.Texture1D = {0, 1, clamp}; + } else if (array) { + view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2DARRAY; + view.Texture2DArray = {0, 1, 1, 4, 0, clamp}; + } else { + view.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE3D; + view.Texture3D = {0, 1, clamp}; + } + invoke(device, 18, word(texture), control == "undescribed" ? 0 : word(&view), cpu + 64); + } if (mode == "dispatch-input-memory-view") { // The input is a buffer view (device slot 70) of memory no buffer is placed over, 16 bytes in; its token // replaces the input descriptor and the words are written after the view exists.