diff --git a/CMakeLists.txt b/CMakeLists.txt index f9be7c706..d1b0a348a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3570,6 +3570,9 @@ if(EXISTS "${INTAKE_PYTHON}") # A typed buffer load of BUF_FMT_16_16_16_16_FLOAT reads four halves from one 8-byte element (#1695). add_test(NAME startup_gfx2hlsl_tbuffer_16f COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_tbuffer_16f_check.py") + # A typed buffer load of BUF_FMT_2_10_10_10_UNORM reads three 10-bit fields and a 2-bit one from one dword (#1723). + add_test(NAME startup_gfx2hlsl_tbuffer_2101010 COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_tbuffer_2101010_check.py") # The draw's DXGI -> FORMAT table for typed views read by buffer_load_format_* matches the translation's switch. add_test(NAME startup_buffer_format_word3_table COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_buffer_format_word3_table_check.py") diff --git a/docs/experiments.md b/docs/experiments.md index 00b5edb88..7ae776ba1 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -402,6 +402,9 @@ ctest --preset dev --no-tests=error -R '^startup_vertex_fetch_formats_(controls| `BUF_FMT_16_16_SNORM` (format 24, DXGI `R16G16_SNORM` 37) sign-extends each half, divides by 32767 and clamps to -1.0, so -32768 and -32767 both give -1.0 (the Direct3D and Vulkan SNORM rule, as in LLVM 15 and Mesa `ac_formats`). The device run compares `round(v * 32767)` against the same byte decode, with a wrong reference that reads the halves unsigned and a mutated translation that does the same. The pattern the harness writes to t0 holds no 0x8000, so `startup_vertex_fetch_formats_controls` also evaluates the emitted expressions on 0x8000, 0x8001, 0x7fff, 0x0000, 0xffff and 0x4000 in each half, and four wrong forms (unsigned read, no clamp, divisor 32768, one half for both) must fail that check. The D3D12 draw has not been run on Linux. +`BUF_FMT_2_10_10_10_UNORM` (gfx10 format 50, DXGI `R10G10B10A2_UNORM` 24) reads one dword with x, y and z as 10-bit fields in bits 9:0, 19:10 and 29:20 and w as the 2-bit field in bits 31:30, each divided by its maximum (1023, 1023, 1023, 3). This is the 10-bit-x layout that Mesa maps R10G10B10A2 to; `BUF_FMT_10_10_10_2_UNORM` (format 44) has a 2-bit x and is not added here. It is checked on Linux by the Python evaluation `startup_gfx2hlsl_tbuffer_2101010`, which also covers the DXGI table entry; the D3D12 draws `startup_vertex_fetch_formats_warp` and `startup_vertex_fetch_formats_hardware` read it back (stride 6 / offset 2 and through the descriptor path). + + In a graphics shader with only forward branches, a 32-bit root-table pointer can be advanced by a literal byte offset and copied with `s_mov_b32`. At a join the table and its offset must agree on every incoming path. A later @@ -421,7 +424,7 @@ manifest's byte offset changes all 32 pixels and preserves the green values. A typed buffer view that the title creates through the runtime (`CreateShaderResourceView`, `BUFFER`, no flags, no structure stride) leaves no hardware descriptor in the table. For this case the draw builds word 3 the way the console driver builds it from the view, using `view_word3()` in `src/startup_stubs/buffer_format_word3.h`: -- FORMAT is the code of the DXGI format whose typed read gives the same components. The 14 formats in the switch are covered: `R8_UNORM` 1, `R8_UINT` 5, `R8G8_UNORM` 14, `R32_FLOAT` 22, `R16G16_UNORM` 23, `R16G16_SNORM` 24, `R16G16_UINT` 27, `R16G16_FLOAT` 29, `R8G8B8A8_UNORM` 56, `R8G8B8A8_UINT` 60, `R32G32_FLOAT` 64, `R16G16B16A16_FLOAT` 71, `R32G32B32_FLOAT` 74 and `R32G32B32A32_FLOAT` 77. The codes are the LLVM 15 `llvm-mc -mcpu=gfx1013` encodings of the tbuffer `format:` operand. +- FORMAT is the code of the DXGI format whose typed read gives the same components. The 15 formats in the switch are covered: `R8_UNORM` 1, `R8_UINT` 5, `R8G8_UNORM` 14, `R32_FLOAT` 22, `R16G16_UNORM` 23, `R16G16_SNORM` 24, `R16G16_UINT` 27, `R16G16_FLOAT` 29, `R10G10B10A2_UNORM` 50, `R8G8B8A8_UNORM` 56, `R8G8B8A8_UINT` 60, `R32G32_FLOAT` 64, `R16G16B16A16_FLOAT` 71, `R32G32B32_FLOAT` 74 and `R32G32B32A32_FLOAT` 77. The codes are the LLVM 15 `llvm-mc -mcpu=gfx1013` encodings of the tbuffer `format:` operand. - DST_SEL comes from `Shader4ComponentMapping`: a channel becomes 4 to 7, a forced 0 becomes 0 and a forced 1 becomes 1. The draw is refused, not read as zeros, whenever a translated formatted load has no resolved word 3: diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index ac25b37e1..d0f03ec51 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -208,9 +208,9 @@ The translation is refused when: - either header has another size; - the code reads an attribute the table does not list. -The shader cache revision is `x2w-startup-shader-19`. Revision 19 folds `s_mov_b32` from a scalar register that +The shader cache revision is `x2w-startup-shader-20`. Revision 20 decodes MTBUF/MUBUF format 50 (`R10G10B10A2_UNORM`) in the run-time FORMAT switch, so cached shaders from revision 19 are not reused. Revision 19 folds `s_mov_b32` from a scalar register that holds a plain constant, so later reads of the copy use the constant word. The matching compute -(`x2w-startup-shader-19cs`) key advances because that stage uses the shared lowering. The fixed slot 57 mesh +(`x2w-startup-shader-20cs`) key advances because that stage uses the shared lowering. The fixed slot 57 mesh (`x2w-startup-mesh-57-3`) key stays, because that shader is not translated from guest code. Revisions before 19 read a register copied from a constant as a run-time value. Revision 18 preserves the sign of zero in floating-point min, max, min3, max3 and med3. diff --git a/src/startup_stubs/buffer_format_word3.h b/src/startup_stubs/buffer_format_word3.h index 771ec1dd8..072ae1aed 100644 --- a/src/startup_stubs/buffer_format_word3.h +++ b/src/startup_stubs/buffer_format_word3.h @@ -26,6 +26,7 @@ inline std::uint32_t buffer_format_code(DXGI_FORMAT format) case DXGI_FORMAT_R16G16_SNORM: return 24; case DXGI_FORMAT_R16G16_UINT: return 27; case DXGI_FORMAT_R16G16_FLOAT: return 29; + case DXGI_FORMAT_R10G10B10A2_UNORM: return 50; case DXGI_FORMAT_R8G8B8A8_UNORM: return 56; case DXGI_FORMAT_R8G8B8A8_UINT: return 60; case DXGI_FORMAT_R32G32_FLOAT: return 64; diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index e4335cedf..00a7b5e8a 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -353,7 +353,7 @@ Translation* cached_translation(const void* a, std::size_t a_bytes, const void* { // Keep pre-fix desktop bytecode and manifests out of this ABI's cache. // tools/startup/gfx2hlsl.py hashes the same bytes, without a trailing NUL. - constexpr char revision[] = "x2w-startup-shader-19"; + constexpr char revision[] = "x2w-startup-shader-20"; const u64 seed = fnv_bytes(revision, sizeof(revision) - 1); u64 key = fnv_bytes(root_blob.data(), root_blob.size(), fnv_bytes(b, b_bytes, fnv_bytes(a, a_bytes, seed))); // A stream's input layout (stream_input_layout) feeds the vertex fetch, so it is part of the key. @@ -474,7 +474,7 @@ u64 publish_compute_request(const void* desc) std::vector fields(sizeof(words)); words[0] = words[1] = words[3] = words[5] = words[7] = words[9] = words[10] = 0; std::memcpy(fields.data(), words, sizeof(words)); - constexpr char compute_revision[] = "x2w-startup-shader-19cs"; // tools/startup/gfx2hlsl.py compute_key + constexpr char compute_revision[] = "x2w-startup-shader-20cs"; // tools/startup/gfx2hlsl.py compute_key u64 key = fnv_bytes(compute_revision, sizeof(compute_revision) - 1); const std::vector* order[] = {&code, &data, &root_blob, &fields, &state_a, &state_b}; for (const auto* part : order) key = fnv_part(*part, key); diff --git a/src/startup_stubs/formatted_buffer.h b/src/startup_stubs/formatted_buffer.h index 2a216abb0..76ad650eb 100644 --- a/src/startup_stubs/formatted_buffer.h +++ b/src/startup_stubs/formatted_buffer.h @@ -14,7 +14,7 @@ constexpr bool formatted_buffer_supported(std::uint32_t code) { switch (code) { case 1: case 5: case 14: case 22: case 23: case 24: case 27: - case 29: case 56: case 60: case 64: case 71: case 74: case 77: + case 29: case 50: case 56: case 60: case 64: case 71: case 74: case 77: return true; default: return false; diff --git a/tests/startup_buffer_format_word3_check.cpp b/tests/startup_buffer_format_word3_check.cpp index 8df22b7b4..5e245ecd9 100644 --- a/tests/startup_buffer_format_word3_check.cpp +++ b/tests/startup_buffer_format_word3_check.cpp @@ -45,6 +45,8 @@ int main(int argc, char** argv) std::uint32_t word = 0; check("float4 identity", !x2w_startup::view_word3(typed(DXGI_FORMAT_R32G32B32A32_FLOAT), word) && word == (77u << 12 | identity)); + check("R10G10B10A2 unorm identity", !x2w_startup::view_word3(typed(DXGI_FORMAT_R10G10B10A2_UNORM), word) && + word == (50u << 12 | identity)); check("half2 identity", !x2w_startup::view_word3(typed(DXGI_FORMAT_R16G16_FLOAT), word) && word == (29u << 12 | identity)); check("snorm2 identity", !x2w_startup::view_word3(typed(DXGI_FORMAT_R16G16_SNORM), word) && word == (24u << 12 | identity)); check("uint8 identity", !x2w_startup::view_word3(typed(DXGI_FORMAT_R8_UINT), word) && word == (5u << 12 | identity)); @@ -59,7 +61,7 @@ int main(int argc, char** argv) const DXGI_FORMAT decoded[] = {DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_R8_UINT, DXGI_FORMAT_R8G8_UNORM, DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R16G16_UNORM, DXGI_FORMAT_R16G16_SNORM, DXGI_FORMAT_R16G16_FLOAT, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R32G32B32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT, - DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R8G8B8A8_UINT}; + DXGI_FORMAT_R16G16_UINT, DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R10G10B10A2_UNORM}; for (DXGI_FORMAT f : decoded) { const std::uint32_t code = x2w_startup::buffer_format_code(f); if (!code || !x2w_startup::formatted_buffer_supported(code)) { diff --git a/tests/startup_buffer_format_word3_table_check.py b/tests/startup_buffer_format_word3_table_check.py index c89621218..9099c99dc 100644 --- a/tests/startup_buffer_format_word3_table_check.py +++ b/tests/startup_buffer_format_word3_table_check.py @@ -15,7 +15,7 @@ # Public DXGI_FORMAT values (dxgiformat.h) for the names the header uses. DXGI = {'R32G32B32A32_FLOAT': 2, 'R32G32B32_FLOAT': 6, 'R16G16B16A16_FLOAT': 10, 'R32G32_FLOAT': 16, - 'R8G8B8A8_UNORM': 28, 'R16G16_FLOAT': 34, 'R16G16_UNORM': 35, 'R16G16_UINT': 36, 'R16G16_SNORM': 37, 'R8G8B8A8_UINT': 30, 'R32_FLOAT': 41, + 'R8G8B8A8_UNORM': 28, 'R10G10B10A2_UNORM': 24, 'R16G16_FLOAT': 34, 'R16G16_UNORM': 35, 'R16G16_UINT': 36, 'R16G16_SNORM': 37, 'R8G8B8A8_UINT': 30, 'R32_FLOAT': 41, 'R8G8_UNORM': 49, 'R8_UNORM': 61, 'R8_UINT': 62} # The buffer format each DXGI format reads as: FETCH_DXGI, plus the three formats it does not list. EXPECTED = {**{dxgi: name for dxgi, (name, _) in gfx2hlsl.FETCH_DXGI.items()}, diff --git a/tests/startup_compute_request_offline_check.py b/tests/startup_compute_request_offline_check.py index a834a0762..3b6c7fec3 100644 --- a/tests/startup_compute_request_offline_check.py +++ b/tests/startup_compute_request_offline_check.py @@ -25,12 +25,12 @@ DESC = struct.pack('<12Q', 0, 0, 24, 0, 20, 0, len(CODE), 0, len(DATA), 0, 0, 11) STATE_A = struct.pack('<3Q', 1, 0x2c, 0xfff0000000000003) STATE_B = struct.pack('<5I', 0x1234abcd, 0xffff0000, 0, 0, 0) -KEY = 0x63ac0aa21c46da1c # framed key at revision 19cs +KEY = 0x88e751913fcbf7a8 # framed key at revision 20cs def framed_key(): h = 1469598103934665603 - for b in b'x2w-startup-shader-19cs': + for b in b'x2w-startup-shader-20cs': h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B): for b in struct.pack('> 3) & 1) << 21) | (soffset << 24) + return struct.pack(';` lines with `w` bound to the loaded dword; returns {N: value}.""" + out = {} + for line in lines: + m = re.fullmatch(r'v(\d+) = (.*);', line.strip()) + if m: + out[int(m.group(1))] = eval(m.group(2), {'U': lambda x: x, 'ldu': lambda *_: 0}, {'w': word}) + return out + + +def reference(word): + return [(word & 1023) / 1023.0, ((word >> 10) & 1023) / 1023.0, ((word >> 20) & 1023) / 1023.0, (word >> 30) / 3.0] + + +code = encode_mtbuf(MTBUF_LOAD['xyzw'], MTBUF_FORMAT_2_10_10_10_UNORM, vdata=1, vaddr=2, srsrc=4) +asm, lines = translate_bytes(code) +check('decodes the named format', 'BUF_FMT_2_10_10_10_UNORM' in asm[0], repr(asm)) +check('the word is loaded with ldu', any('w = ldu(r0, a)' in l for l in lines), repr(lines)) + +for word in (0x00000000, 0xffffffff, 0x4012a3ff, 0x8007fc01, 0xc0000000, 0x2aaaaaaa, 0x155ff3d1): + got = run_components(lines, word) + want = reference(word) + check('all four components for 0x%08x' % word, [got.get(1 + i) for i in range(4)] == want, + 'got %r want %r' % (got, want)) + +# Fewer components read the same leading fields. +_, lines_xy = translate_bytes(encode_mtbuf(MTBUF_LOAD['xy'], MTBUF_FORMAT_2_10_10_10_UNORM, vdata=1, vaddr=2)) +got = run_components(lines_xy, 0x4012a3ff) +check('the xy form reads two components', sorted(got) == [1, 2] and [got[1], got[2]] == reference(0x4012a3ff)[:2], repr(got)) + +# The input-layout mapping: DXGI_FORMAT_R10G10B10A2_UNORM is 24, one dword per element. +check('DXGI 24 maps to the format', G.FETCH_DXGI.get(24) == ('BUF_FMT_2_10_10_10_UNORM', 4), repr(G.FETCH_DXGI.get(24))) + +# A sibling format stays refused. +try: + translate_bytes(encode_mtbuf(MTBUF_LOAD['xyzw'], MTBUF_FORMAT_2_10_10_10_SNORM, vdata=1, vaddr=2)) + refused = False +except G.Unsupported: + refused = True +check('the SNORM sibling stays refused', refused) + +if failures: + print('FAIL') + for text in failures: + print(' ' + text) + sys.exit(1) +print('PASS') diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 314ef09c8..116968125 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -295,7 +295,7 @@ ComPtr translated_pipeline(ID3D12Device* guest, ID3D12RootSignature* r bool needs_start, bool table_buffer = false, bool indexed = false, bool rect = false) { // The opaque guest programs identify synthetic cache entries. The actual bound shaders are source-built DXBC. - constexpr char revision[] = "x2w-startup-shader-19"; + constexpr char revision[] = "x2w-startup-shader-20"; static std::uint32_t vertex_ids[]{0xe0000101, 0xe0000102, 0xe0000103}; static std::uint32_t pixel_ids[]{0xe0000202, 0xe0000203, 0xe0000204}; auto& vertex_id = vertex_ids[indexed ? 2 : needs_start]; diff --git a/tests/startup_packed_position_provenance_check.py b/tests/startup_packed_position_provenance_check.py index fea8cc816..8620af940 100644 --- a/tests/startup_packed_position_provenance_check.py +++ b/tests/startup_packed_position_provenance_check.py @@ -206,7 +206,7 @@ def refused(label, cache, key, reason): cache = Path(tmp) bare = G.pipeline_key(VS_WORDS, ps_words(4), root_blob()) check('without a description the key is unchanged', - bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-19'))))) + bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-20'))))) keys = [put_request(cache, ps_words(4), masks) for masks in (TARGET, SAME_V4, DECOY)] check('same stages, root and layout with three mask pairs: three request identities', len(set(keys)) == 3 and bare not in keys diff --git a/tests/startup_resource_retire_title.cpp b/tests/startup_resource_retire_title.cpp index 24c80d3b0..b06474077 100644 --- a/tests/startup_resource_retire_title.cpp +++ b/tests/startup_resource_retire_title.cpp @@ -371,7 +371,7 @@ constexpr UINT draw_side = 4; // 4x4 R8G8B8A8_UNORM target constexpr UINT draw_covered = 3; // scissor leaves the last row and column untouched as the sentinel constexpr int draw_seed = 77; constexpr UINT draw_clear_pixel = 0xffff00ffu; // ClearRenderTargetView({1, 0, 1, 1}) in R8G8B8A8_UNORM -constexpr char draw_revision[] = "x2w-startup-shader-19"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-20"; // d3d12_draw.inl cached_translation constexpr char draw_vertex_shader[] = R"( struct Varying { float4 position : SV_Position; }; diff --git a/tests/startup_shader_cache_key_check.py b/tests/startup_shader_cache_key_check.py index a0d27d525..fd44bba11 100644 --- a/tests/startup_shader_cache_key_check.py +++ b/tests/startup_shader_cache_key_check.py @@ -49,10 +49,10 @@ def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): def main(): # Independently executed C++ runtime fnv_bytes/cached_translation known-answer vector. - # Revision x2w-startup-shader-19 excludes NUL. Stored order is a, b, root, then optional input layout. + # Revision x2w-startup-shader-20 excludes NUL. Stored order is a, b, root, then optional input layout. vector = (b"\x00VS\xff", b"PS\x00\x80", b"RTS0\x00") - assert gfx2hlsl.pipeline_key(*vector) == 0xf3444b13fe09b4df - assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x2039e248f9cad09f + assert gfx2hlsl.pipeline_key(*vector) == 0x4564b4bb15aa0b9b + assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x8a4952a88d16d6e3 blobs = (VERTEX, PIXEL, ROOT) canonical = gfx2hlsl.pipeline_key(*blobs) check_request(blobs, canonical) diff --git a/tests/startup_vertex_fetch_formats_check.py b/tests/startup_vertex_fetch_formats_check.py index 52904e985..0dcdc6480 100644 --- a/tests/startup_vertex_fetch_formats_check.py +++ b/tests/startup_vertex_fetch_formats_check.py @@ -54,6 +54,9 @@ def f16(bits): 'BUF_FMT_8_UINT': (5, 3, 1, 8, 'uint', 1), 'BUF_FMT_8_8_UNORM': (14, 3, 2, 8, 'unorm', 2), 'BUF_FMT_16_16_UNORM': (23, 6, 2, 16, 'unorm', 2), + # One dword: x, y, z are 10-bit fields (bits 9:0, 19:10, 29:20) and w the 2-bit field in bits 31:30. The field + # width is listed as 16 only so the stride and offset checks see sub-dword alignment; see PACKED_2101010. + 'BUF_FMT_2_10_10_10_UNORM': (50, 6, 2, 16, 'unorm2101010', 4), 'BUF_FMT_16_16_SNORM': (24, 6, 2, 16, 'snorm', 2), 'BUF_FMT_16_16_UINT': (27, 6, 2, 16, 'uint', 2), 'BUF_FMT_16_16_FLOAT': (29, 10, 10, 16, 'f16', 2), @@ -67,6 +70,9 @@ def f16(bits): } +PACKED_2101010 = ((0, 10), (10, 10), (20, 10), (30, 2)) # (low bit, width) of x, y, z, w + + def snorm_words(fields, unsigned=False, no_clamp=False): """SNORM fields as the compared integers round(v * 32767): two's complement, -32768 clamped to -32767.""" out = [] @@ -80,6 +86,14 @@ def reference(name, vertex, *, offset=None, swap=False, shift=False, w_zero=Fals """The four compared words of one vertex, from the format definition. The keywords give wrong references.""" _, stride, own_offset, bits, kind, count = FORMATS[name] address, size = vertex * stride + (own_offset if offset is None else offset), bits // 8 + if kind == 'unorm2101010': + word = int.from_bytes(DATA[address + (1 if shift else 0):address + (1 if shift else 0) + 4], 'little') + fields = [(word >> low) & ((1 << width) - 1) for low, width in PACKED_2101010] + if swap: + fields[0], fields[1] = fields[1], fields[0] + if unorm_pow2: + fields = [round(f * ((1 << w) - 1) / (1 << w)) for f, (_, w) in zip(fields, PACKED_2101010)] + return fields fields = [int.from_bytes(DATA[address + size * i:address + size * (i + 1)], 'little') for i in range(count)] if shift and bits < 32: # Each field read one field higher, as a wrong shift would; the last reads past the element. @@ -100,6 +114,8 @@ def reference(name, vertex, *, offset=None, swap=False, shift=False, w_zero=Fals def compared(name): """Return the integer readback scale for each normalized component.""" _, _, _, bits, kind, count = FORMATS[name] + if kind == 'unorm2101010': + return [(1 << width) - 1 for _, width in PACKED_2101010] scale = {'unorm': (1 << bits) - 1, 'snorm': (1 << (bits - 1)) - 1}.get(kind) return [scale if i < count else None for i in range(4)] @@ -143,6 +159,9 @@ def wrapper(name): MUTATIONS = ( ('BUF_FMT_8_8_8_8_UNORM', 'second byte from the third', 'U(((w >> 8) & 255) / 255.0)', 'U(((w >> 16) & 255) / 255.0)'), ('BUF_FMT_8_8_8_8_UNORM', 'fourth byte as 255', 'U((w >> 24) / 255.0)', 'U(1.0)'), + ('BUF_FMT_2_10_10_10_UNORM', 'y from the x field', 'v5 = U(((w >> 10) & 1023) / 1023.0);', 'v5 = U((w & 1023) / 1023.0);'), + ('BUF_FMT_2_10_10_10_UNORM', 'z from the y field', 'v6 = U(((w >> 20) & 1023) / 1023.0);', 'v6 = U(((w >> 10) & 1023) / 1023.0);'), + ('BUF_FMT_2_10_10_10_UNORM', 'w over 4', 'v7 = U((w >> 30) / 3.0);', 'v7 = U((w >> 30) / 4.0);'), ('BUF_FMT_8_8_8_8_UINT', 'normalized green byte', 'v5 = (w >> 8) & 255u;', 'v5 = U(((w >> 8) & 255u) / 255.0);'), ('BUF_FMT_8_8_8_8_UINT', 'blue byte from green', 'v6 = (w >> 16) & 255u;', 'v6 = (w >> 8) & 255u;'), ('BUF_FMT_8_8_8_8_UINT', 'alpha byte from blue', 'v7 = w >> 24;', 'v7 = (w >> 16) & 255u;'), @@ -411,8 +430,10 @@ def stage(words): def runtime_gate(source): """Check that both FORMAT metadata and usable backing are required before submission.""" assert 'formatted_buffers_ready(*tr, pass, formatted_buffers)' in source + decoder = source[source.index('const char* formatted_buffer_word3('):source.index('bool formatted_buffers_ready(')] + assert 'formatted_buffer_supported(' in decoder preflight = source[source.index('bool formatted_buffers_ready('):source.index('bool draw_translated(')] - for condition in ('x2w_local::readable(', 'view_token_magic', 'formatted_buffer_supported('): + for condition in ('x2w_local::readable(', 'view_token_magic', 'formatted_buffer_word3('): assert condition in preflight, condition start = source.index('bool draw_translated(') gate = source.index('if (!have && formatted.entry)', start) @@ -424,8 +445,15 @@ def runtime_gate(source): def runtime_gate_controls(): source = RUNTIME.read_text(encoding='utf-8') runtime_gate(source) + decoder = source[source.index('const char* formatted_buffer_word3('):source.index('bool formatted_buffers_ready(')] + try: + runtime_gate(source.replace(decoder, decoder.replace('formatted_buffer_supported(', 'omitted'))) + except AssertionError: + pass + else: + raise AssertionError('descriptor decoder without FORMAT support checking must fail the control') preflight = source[source.index('bool formatted_buffers_ready('):source.index('bool draw_translated(')] - for dropped in ('x2w_local::readable(', 'view_token_magic', 'formatted_buffer_supported('): + for dropped in ('x2w_local::readable(', 'view_token_magic', 'formatted_buffer_word3('): try: runtime_gate(source.replace(preflight, preflight.replace(dropped, 'omitted'))) except AssertionError: diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 348fca197..42a211707 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -128,7 +128,8 @@ def strip_header(code): FETCH_DXGI = {2: ('BUF_FMT_32_32_32_32_FLOAT', 16), 6: ('BUF_FMT_32_32_32_FLOAT', 12), 16: ('BUF_FMT_32_32_FLOAT', 8), 41: ('BUF_FMT_32_FLOAT', 4), 28: ('BUF_FMT_8_8_8_8_UNORM', 4), 49: ('BUF_FMT_8_8_UNORM', 2), 61: ('BUF_FMT_8_UNORM', 1), 34: ('BUF_FMT_16_16_FLOAT', 4), 35: ('BUF_FMT_16_16_UNORM', 4), - 37: ('BUF_FMT_16_16_SNORM', 4), 30: ('BUF_FMT_8_8_8_8_UINT', 4)} + 37: ('BUF_FMT_16_16_SNORM', 4), 30: ('BUF_FMT_8_8_8_8_UINT', 4), + 24: ('BUF_FMT_2_10_10_10_UNORM', 4)} # Typed buffer loads: (word load or None, the four component expressions). Components a format lacks read as # 0, 0, 0, 1 here, as in the existing tbuffer translation; that default is an assumption, not a measurement. FETCH_FORMATS = { @@ -137,6 +138,8 @@ def strip_header(code): 'BUF_FMT_8_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', 'U(((w >> 8) & 255) / 255.0)', '0u', 'U(1.0)']), 'BUF_FMT_8_UNORM': ('ldu({0}, a)', ['U((w & 255) / 255.0)', '0u', '0u', 'U(1.0)']), 'BUF_FMT_8_UINT': ('{0}.Load(a & ~3u) >> ((a & 3u) * 8u)', ['w & 255u', '0u', '0u', '1u']), + # Three 10-bit fields and a 2-bit one in one dword, lowest bits first: x, y, z, then w. + 'BUF_FMT_2_10_10_10_UNORM': ('ldu({0}, a)', ['U((w & 1023) / 1023.0)', 'U(((w >> 10) & 1023) / 1023.0)', 'U(((w >> 20) & 1023) / 1023.0)', 'U((w >> 30) / 3.0)']), 'BUF_FMT_16_16_UNORM': ('ldu({0}, a)', ['U((w & 65535) / 65535.0)', 'U((w >> 16) / 65535.0)', '0u', 'U(1.0)']), # Two unsigned 16-bit fields, x in the low half (LLVM 15: BUF_DATA_FORMAT_16_16 with BUF_NUM_FORMAT_UINT, # gfx10 unified format 27); a missing W of an integer format reads 1. @@ -163,7 +166,7 @@ def strip_header(code): DESC_FORMAT_UNKNOWN = 0x7fc0f0f0 DESC_FORMAT_CODES = { 'BUF_FMT_8_UNORM': 1, 'BUF_FMT_8_UINT': 5, 'BUF_FMT_8_8_UNORM': 14, 'BUF_FMT_32_FLOAT': 22, - 'BUF_FMT_16_16_UNORM': 23, 'BUF_FMT_16_16_SNORM': 24, 'BUF_FMT_16_16_UINT': 27, 'BUF_FMT_16_16_FLOAT': 29, 'BUF_FMT_8_8_8_8_UNORM': 56, 'BUF_FMT_8_8_8_8_UINT': 60, + 'BUF_FMT_2_10_10_10_UNORM': 50, 'BUF_FMT_16_16_UNORM': 23, 'BUF_FMT_16_16_SNORM': 24, 'BUF_FMT_16_16_UINT': 27, 'BUF_FMT_16_16_FLOAT': 29, 'BUF_FMT_8_8_8_8_UNORM': 56, 'BUF_FMT_8_8_8_8_UINT': 60, 'BUF_FMT_32_32_FLOAT': 64, 'BUF_FMT_16_16_16_16_FLOAT': 71, 'BUF_FMT_32_32_32_FLOAT': 74, 'BUF_FMT_32_32_32_32_FLOAT': 77} DESC_FORMAT_SHIFT, DESC_FORMAT_MASK = 12, 127 @@ -9796,7 +9799,7 @@ def pipeline_key(vs_code, ps_code, root_blob, layout=b'', ps_inputs=None): SPI_PS_INPUT_ENA and SPI_PS_INPUT_ADDR as little-endian u32. Two pipelines with the same stages, root signature and input layout but different masks are then two requests with their own results. Without a description the key is unchanged.""" - key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-19')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-20')))) key = fnv(layout, key) if layout else key return key if ps_inputs is None else fnv(b'psin1' + struct.pack('