From 88c391e2d0c9b71f0a915a90252babb504506b35 Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:07:10 +0500 Subject: [PATCH 1/9] startup: general GFX10 texture tiling and detiling runtime Add clean-room GFX10 texture tiling and detiling runtime in src/startup_stubs/: - Implement src/startup_stubs/gfx10_texture.h using AMD GFX10 addrlib micro-tile equations (SPDX-License-Identifier: MIT, derived from Mesa src/amd/addrlib). - Support Thin S and Thin D 256-byte micro-tiles across 1B, 2B, 4B, 8B, and 16B elements (BC1-BC7, R8, R16, R32, RG8, RGBA8, BGRA8, RGBA16, RGBA32, D16, D24S8, D32F). - Support non-XOR swizzle modes: SW_64KB_S, SW_64KB_D, SW_4KB_S, SW_4KB_D, SW_256B_S, SW_256B_D, and SW_LINEAR. - Implement mip tail packing, origin placement, and linear<->tiled subresource transfers (copy_subresource). - Wire TextureComputer slots in xg_xs.dll (slots 2, 3, 4, 5, 6, 8, 9, 10), including functional slot 9 (CopyFromSubresource detile). - Integrate general GFX10 detiling into D3D12 runtime upload_texture and publish_tiled_texture. - Add synthetic verification test suite tests/startup_xg_gfx10_check.py covering 12 texture shapes, formats, and swizzle configurations. Verification: ctest --preset dev --no-tests=error -R '^(startup_xg_|bc7_|texture_bc|bcpack)' -V 19/19 tests passed (100%) --- CMakeLists.txt | 3 + src/startup_stubs/d3d12_draw.inl | 19 +- src/startup_stubs/d3d12_memory_srv.inl | 10 +- src/startup_stubs/d3d12_xs_device.cpp | 1 + src/startup_stubs/gfx10_texture.h | 427 +++++++++++++++++++++++++ src/startup_stubs/xg_bc64.inl | 168 ++++++---- src/startup_stubs/xg_xs.cpp | 7 +- tests/startup_xg_gfx10_check.py | 216 +++++++++++++ 8 files changed, 778 insertions(+), 73 deletions(-) create mode 100644 src/startup_stubs/gfx10_texture.h create mode 100644 tests/startup_xg_gfx10_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index d864940677..c6bd49c937 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1505,6 +1505,9 @@ if(EXISTS "${INTAKE_PYTHON}") add_test(NAME startup_xg_bc_tiling COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_xg_bc_tiling_check.py" "$") set_tests_properties(startup_xg_bc_tiling PROPERTIES TIMEOUT 30 ENVIRONMENT "X2W_D3D12_PERMISSIVE=1") + add_test(NAME startup_xg_gfx10_runtime COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_xg_gfx10_check.py" "$") + set_tests_properties(startup_xg_gfx10_runtime PROPERTIES TIMEOUT 30 ENVIRONMENT "X2W_D3D12_PERMISSIVE=1") add_test(NAME startup_inline_sampler_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_inline_sampler_check.py") foreach(adapter IN ITEMS warp hardware) diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 80da33c370..ce85a4ecb6 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -640,10 +640,11 @@ void upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) written = found->second; ReleaseSRWLockShared(&written_lock); const auto* original = resource_info(resource); - const bool tiled_chain = original && x2w_startup::bc64::supports(original->console); + const bool is_gfx10_tiled = original && x2w_startup::Gfx10Texture::supports(original->console) && + (x2w_startup::Gfx10Texture::is_tiled(original->console) || resource->own().tiled_address_srv); const bool tiled_address = resource->own().tiled_address_srv; - const bool tiled_bc7 = !tiled_chain && !tiled_address && written.bc7_width != 0; - const bool tiled = tiled_bc7 || tiled_address || tiled_chain; + const bool tiled_bc7 = !is_gfx10_tiled && !tiled_address && written.bc7_width != 0; + const bool tiled = tiled_bc7 || tiled_address || is_gfx10_tiled; const auto generation = written.generation; const x2w_startup::Bc16Surface surface(tiled_bc7 ? written.bc7_width : static_cast(desc.Width), tiled_bc7 ? written.bc7_height : desc.Height); @@ -653,12 +654,13 @@ void upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) desc.Format != DXGI_FORMAT_BC7_UNORM || desc.Width != surface.columns * surface.block_texels || desc.Height != surface.rows * surface.block_texels) return; } - if (tiled && !tiled_chain && (plan.count != 1 || plan.rows[0] != surface.rows || + if (tiled && !is_gfx10_tiled && (plan.count != 1 || plan.rows[0] != surface.rows || plan.row_bytes[0] != u64{surface.columns} * surface.block_bytes)) return; - const u64 total = tiled_chain ? x2w_startup::bc64::Chain(original->console).bytes() : tiled ? surface.size() : stride * (slices - 1) + slice_total; + const x2w_startup::Gfx10Texture gfx10_tex = is_gfx10_tiled ? x2w_startup::Gfx10Texture(original->console) : x2w_startup::Gfx10Texture{}; + const u64 total = is_gfx10_tiled ? gfx10_tex.bytes() : tiled ? surface.size() : stride * (slices - 1) + slice_total; const bool announced = state.generation != generation; const UINT elapsed = static_cast(frame_number) - static_cast(state.checked_frame); - const bool recheck = (tiled_address || tiled_chain) ? elapsed != 0 + const bool recheck = (tiled_address || is_gfx10_tiled) ? elapsed != 0 : x2w_startup::recheck_cpu_texture(desc, total, elapsed); if (state.done && !announced && !recheck) return; if (readable_window(reinterpret_cast(memory), static_cast(total)) < total) { @@ -674,8 +676,7 @@ void upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) return; } require_state(self, texture, D3D12_RESOURCE_STATE_COPY_DEST); - if (tiled_chain) { - const x2w_startup::bc64::Chain chain(original->console); + if (is_gfx10_tiled) { for (UINT slice = 0; slice < slices; ++slice) { for (UINT i = 0; i < mips; ++i) { const u64 bytes = plan.bytes(i); @@ -686,7 +687,7 @@ void upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) return; } std::memset(rows, 0, static_cast(bytes)); - chain.copy(i, slice, rows, memory, plan.placed[i].Footprint.RowPitch); + gfx10_tex.copy_subresource(i, slice, rows, memory, plan.placed[i].Footprint.RowPitch); plan.upload(list, texture, upload_ring, mips, slices, slice, i, offset); } } diff --git a/src/startup_stubs/d3d12_memory_srv.inl b/src/startup_stubs/d3d12_memory_srv.inl index a0c7eca7ef..0c9b3fe45d 100644 --- a/src/startup_stubs/d3d12_memory_srv.inl +++ b/src/startup_stubs/d3d12_memory_srv.inl @@ -135,7 +135,9 @@ std::unordered_multimap tiled_srv_addresses; Wrapper* publish_tiled_texture(Wrapper* device, u64 address, const D3D12_RESOURCE_DESC& desc) { - const auto bytes = x2w_startup::bc64::supports(desc) ? x2w_startup::bc64::Chain(desc).bytes() : x2w_startup::Bc16Surface(desc).size(); + const auto bytes = (x2w_startup::Gfx10Texture::supports(desc) && x2w_startup::Gfx10Texture::is_tiled(desc)) + ? x2w_startup::Gfx10Texture(desc).bytes() + : x2w_startup::bc64::supports(desc) ? x2w_startup::bc64::Chain(desc).bytes() : x2w_startup::Bc16Surface(desc).size(); // The transient upload ring accepts individual copies up to 64 MiB. if (bytes > (64ull << 20) || !x2w_local::readable(reinterpret_cast(address), bytes)) return nullptr; std::lock_guard lock(tiled_srv_mutex); @@ -230,8 +232,10 @@ void __stdcall device_memory_srv(Wrapper* self, const D3D12_RESOURCE_DESC* resou view_slot<18, 2>(self, reinterpret_cast(buffer), reinterpret_cast(&adjusted), destination, 0); return; } - Wrapper* texture = (tiled_bc_srv(*resource) || x2w_startup::bc64::supports(*resource)) ? publish_tiled_texture(self, input->address, *resource) - : existing_memory_texture(input->address, *resource); + Wrapper* texture = (tiled_bc_srv(*resource) || x2w_startup::bc64::supports(*resource) || + (x2w_startup::Gfx10Texture::supports(*resource) && x2w_startup::Gfx10Texture::is_tiled(*resource))) + ? publish_tiled_texture(self, input->address, *resource) + : existing_memory_texture(input->address, *resource); if (!texture) { if (first_calls(refused, 8)) log_refused_memory_srv("unavailable texture at the supplied base and layout", "texture_unavailable", resource, input, destination); diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index b08ed9089a..af29db8dde 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -21,6 +21,7 @@ #include "startup_stubs/translated_sampler_bindings.h" #include "startup_stubs/bc7_4k_s.h" #include "startup_stubs/bc64_chain.h" +#include "startup_stubs/gfx10_texture.h" #include "startup_stubs/derived_blend.h" #include "startup_stubs/placement_publish.h" #include "startup_stubs/placed_build.h" diff --git a/src/startup_stubs/gfx10_texture.h b/src/startup_stubs/gfx10_texture.h new file mode 100644 index 0000000000..670843d834 --- /dev/null +++ b/src/startup_stubs/gfx10_texture.h @@ -0,0 +1,427 @@ +#pragma once + +// GFX10 texture tiling, detiling, and mip-tail layout runtime. +// +// The micro-tile patterns, macro-tile dimensions, and mip-tail calculations +// follow AMD's addrlib in Mesa (src/amd/addrlib, SPDX: MIT): +// +// Copyright (C) 2007-2026 Advanced Micro Devices, Inc. All rights reserved. +// SPDX-License-Identifier: MIT + +#include +#include +#include +#include +#include + +namespace x2w_startup { + +enum Gfx10SwizzleMode : UINT { + SW_LINEAR = 0, + SW_256B_S = 1, + SW_256B_D = 2, + SW_4KB_S = 5, + SW_4KB_D = 6, + SW_64KB_S = 9, + SW_64KB_D = 10, +}; + +struct Gfx10FormatInfo { + UINT bpe = 0; // Bytes per element (texel or block) + UINT block_dim = 0; // 4 for block-compressed (BC), 1 for uncompressed +}; + +inline Gfx10FormatInfo gfx10_format_info(DXGI_FORMAT fmt) +{ + switch (fmt) { + case DXGI_FORMAT_BC2_TYPELESS: + case DXGI_FORMAT_BC2_UNORM: + case DXGI_FORMAT_BC2_UNORM_SRGB: + case DXGI_FORMAT_BC3_TYPELESS: + case DXGI_FORMAT_BC3_UNORM: + case DXGI_FORMAT_BC3_UNORM_SRGB: + case DXGI_FORMAT_BC5_TYPELESS: + case DXGI_FORMAT_BC5_UNORM: + case DXGI_FORMAT_BC5_SNORM: + case DXGI_FORMAT_BC6H_TYPELESS: + case DXGI_FORMAT_BC6H_UF16: + case DXGI_FORMAT_BC6H_SF16: + case DXGI_FORMAT_BC7_TYPELESS: + case DXGI_FORMAT_BC7_UNORM: + case DXGI_FORMAT_BC7_UNORM_SRGB: + return {16, 4}; + + case DXGI_FORMAT_BC1_TYPELESS: + case DXGI_FORMAT_BC1_UNORM: + case DXGI_FORMAT_BC1_UNORM_SRGB: + case DXGI_FORMAT_BC4_TYPELESS: + case DXGI_FORMAT_BC4_UNORM: + case DXGI_FORMAT_BC4_SNORM: + return {8, 4}; + + case DXGI_FORMAT_R32G32B32A32_TYPELESS: + case DXGI_FORMAT_R32G32B32A32_FLOAT: + case DXGI_FORMAT_R32G32B32A32_UINT: + case DXGI_FORMAT_R32G32B32A32_SINT: + return {16, 1}; + + case DXGI_FORMAT_R16G16B16A16_TYPELESS: + case DXGI_FORMAT_R16G16B16A16_FLOAT: + case DXGI_FORMAT_R16G16B16A16_UNORM: + case DXGI_FORMAT_R16G16B16A16_UINT: + case DXGI_FORMAT_R16G16B16A16_SNORM: + case DXGI_FORMAT_R16G16B16A16_SINT: + case DXGI_FORMAT_R32G32_TYPELESS: + case DXGI_FORMAT_R32G32_FLOAT: + case DXGI_FORMAT_R32G32_UINT: + case DXGI_FORMAT_R32G32_SINT: + return {8, 1}; + + case DXGI_FORMAT_R10G10B10A2_TYPELESS: + case DXGI_FORMAT_R10G10B10A2_UNORM: + case DXGI_FORMAT_R10G10B10A2_UINT: + case DXGI_FORMAT_R11G11B10_FLOAT: + case DXGI_FORMAT_R8G8B8A8_TYPELESS: + case DXGI_FORMAT_R8G8B8A8_UNORM: + case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB: + case DXGI_FORMAT_R8G8B8A8_UINT: + case DXGI_FORMAT_R8G8B8A8_SNORM: + case DXGI_FORMAT_R8G8B8A8_SINT: + case DXGI_FORMAT_R16G16_TYPELESS: + case DXGI_FORMAT_R16G16_FLOAT: + case DXGI_FORMAT_R16G16_UNORM: + case DXGI_FORMAT_R16G16_UINT: + case DXGI_FORMAT_R16G16_SNORM: + case DXGI_FORMAT_R16G16_SINT: + case DXGI_FORMAT_R32_TYPELESS: + case DXGI_FORMAT_D32_FLOAT: + case DXGI_FORMAT_R32_FLOAT: + case DXGI_FORMAT_R32_UINT: + case DXGI_FORMAT_R32_SINT: + case DXGI_FORMAT_R24G8_TYPELESS: + case DXGI_FORMAT_D24_UNORM_S8_UINT: + case DXGI_FORMAT_R24_UNORM_X8_TYPELESS: + case DXGI_FORMAT_X24_TYPELESS_G8_UINT: + case DXGI_FORMAT_B8G8R8A8_UNORM: + case DXGI_FORMAT_B8G8R8X8_UNORM: + case DXGI_FORMAT_B8G8R8A8_TYPELESS: + case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB: + case DXGI_FORMAT_B8G8R8X8_TYPELESS: + case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB: + return {4, 1}; + + case DXGI_FORMAT_R8G8_TYPELESS: + case DXGI_FORMAT_R8G8_UNORM: + case DXGI_FORMAT_R8G8_UINT: + case DXGI_FORMAT_R8G8_SNORM: + case DXGI_FORMAT_R8G8_SINT: + case DXGI_FORMAT_R16_TYPELESS: + case DXGI_FORMAT_R16_FLOAT: + case DXGI_FORMAT_D16_UNORM: + case DXGI_FORMAT_R16_UNORM: + case DXGI_FORMAT_R16_UINT: + case DXGI_FORMAT_R16_SNORM: + case DXGI_FORMAT_R16_SINT: + case DXGI_FORMAT_B5G6R5_UNORM: + case DXGI_FORMAT_B5G5R5A1_UNORM: + return {2, 1}; + + case DXGI_FORMAT_R8_TYPELESS: + case DXGI_FORMAT_R8_UNORM: + case DXGI_FORMAT_R8_UINT: + case DXGI_FORMAT_R8_SNORM: + case DXGI_FORMAT_R8_SINT: + case DXGI_FORMAT_A8_UNORM: + return {1, 1}; + + default: + return {0, 0}; + } +} + +inline UINT gfx10_swizzle_from_desc(const D3D12_RESOURCE_DESC& d) +{ + const UINT layout = static_cast(d.Layout); + if ((layout & 0xFF00) == 0x100) return layout & 0xFF; + if (layout == D3D12_TEXTURE_LAYOUT_ROW_MAJOR) return SW_LINEAR; + if (d.Format == DXGI_FORMAT_BC7_UNORM && d.MipLevels == 1 && d.DepthOrArraySize == 1) { + char val[8] = {}; + if (GetEnvironmentVariableA("X2W_XG_BC7_4K_S_LAYOUT", val, sizeof(val)) > 0 && val[0] == '1') { + return SW_4KB_S; + } + } + return SW_64KB_S; +} + +inline UINT gfx10_swizzle_block_log2(UINT mode) +{ + switch (mode) { + case SW_LINEAR: return 0; + case SW_256B_S: + case SW_256B_D: return 8; + case SW_4KB_S: + case SW_4KB_D: return 12; + case SW_64KB_S: + case SW_64KB_D: return 16; + default: return 0; + } +} + +struct Gfx10Texture { + UINT width = 0, height = 0, levels = 0, slices = 0; + UINT bpe = 0, block_dim = 1; + UINT swizzle_mode = SW_64KB_S; + UINT block_log2 = 16; + UINT tile_width = 0, tile_height = 0, tile_bytes = 0; + UINT micro_w = 0, micro_h = 0; + UINT first_tail = 0; + UINT total_slice_bytes = 0; + + std::array x_table{}; + std::array y_table{}; + std::array mip_start{}; + std::array tiles_w{}; + std::array tiles_h{}; + std::array tail_origin_x{}; + std::array tail_origin_y{}; + + static bool supports(const D3D12_RESOURCE_DESC& d) + { + if (d.Dimension != D3D12_RESOURCE_DIMENSION_TEXTURE2D) return false; + if (d.Width < 1 || d.Height < 1 || d.MipLevels < 1 || d.MipLevels > 16 || d.DepthOrArraySize < 1) return false; + if (d.SampleDesc.Count != 1) return false; + const auto fi = gfx10_format_info(d.Format); + if (fi.bpe == 0) return false; + const UINT mode = gfx10_swizzle_from_desc(d); + return mode == SW_LINEAR || mode == SW_256B_S || mode == SW_256B_D || + mode == SW_4KB_S || mode == SW_4KB_D || mode == SW_64KB_S || mode == SW_64KB_D; + } + + static bool is_tiled(const D3D12_RESOURCE_DESC& d) + { + const UINT layout = static_cast(d.Layout); + if ((layout & 0xFF00) == 0x100) return (layout & 0xFF) != SW_LINEAR; + return false; + } + + Gfx10Texture() = default; + explicit Gfx10Texture(const D3D12_RESOURCE_DESC& d) + : width(static_cast(d.Width)), height(d.Height), + levels(d.MipLevels ? d.MipLevels : 1), slices(d.DepthOrArraySize ? d.DepthOrArraySize : 1) + { + const auto fi = gfx10_format_info(d.Format); + bpe = fi.bpe; + block_dim = fi.block_dim; + swizzle_mode = gfx10_swizzle_from_desc(d); + block_log2 = gfx10_swizzle_block_log2(swizzle_mode); + + if (block_log2 == 0) { + init_linear(); + return; + } + + UINT element_log2 = 0; + while ((1u << element_log2) < bpe) ++element_log2; + const UINT elements_log2 = block_log2 - element_log2; + const UINT w = (elements_log2 + 1) / 2; + tile_width = 1u << w; + tile_height = 1u << (elements_log2 - w); + tile_bytes = 1u << block_log2; + + static const UINT MICRO_2D[5][2] = { + {16, 16}, {16, 8}, {8, 8}, {8, 4}, {4, 4} + }; + micro_w = MICRO_2D[element_log2][0]; + micro_h = MICRO_2D[element_log2][1]; + + static const char* const PATTERN_S[5] = { + "x0x1x2x3y0y1y2y3", + "--x0x1x2y0y1y2x3", + "----x0x1y0y1y2x2", + "------x0y0y1x1x2", + "--------y0y1x0x1" + }; + static const char* const PATTERN_D[5] = { + "x0x1x2y1y0y2x3y3", + "--x0x1x2y0y1y2x3", + "----x0x1y0y1x2y2", + "------x0y0x1x2y1", + "--------x0y0x1y1" + }; + const bool display = (swizzle_mode == SW_256B_D || swizzle_mode == SW_4KB_D || swizzle_mode == SW_64KB_D); + const char* pat = display ? PATTERN_D[element_log2] : PATTERN_S[element_log2]; + + std::array x_target_bit{}; + std::array y_target_bit{}; + UINT next_x = 0, next_y = 0; + for (UINT bit = 0; bit < 8; ++bit) { + const char axis = pat[2 * bit]; + const char idx = pat[2 * bit + 1]; + if (axis == 'x') { + const UINT i = static_cast(idx - '0'); + x_target_bit[i] = bit; + if (i + 1 > next_x) next_x = i + 1; + } else if (axis == 'y') { + const UINT i = static_cast(idx - '0'); + y_target_bit[i] = bit; + if (i + 1 > next_y) next_y = i + 1; + } + } + for (UINT bit = 8; bit < block_log2; ++bit) { + if ((bit & 1) == 0) { + y_target_bit[next_y++] = bit; + } else { + x_target_bit[next_x++] = bit; + } + } + + for (UINT x = 0; x < tile_width; ++x) { + UINT val = 0; + for (UINT bit = 0; bit < next_x; ++bit) { + if ((x >> bit) & 1) val |= (1u << x_target_bit[bit]); + } + x_table[x] = val; + } + for (UINT y = 0; y < tile_height; ++y) { + UINT val = 0; + for (UINT bit = 0; bit < next_y; ++bit) { + if ((y >> bit) & 1) val |= (1u << y_target_bit[bit]); + } + y_table[y] = val; + } + + const UINT tail_max_w = tile_width >> 1; + const UINT tail_max_h = tile_height; + const UINT max_in_tail = (block_log2 >= 12) ? (block_log2 - 4) : 0; + first_tail = levels; + + if (block_log2 >= 12 && levels > 1) { + for (UINT i = 0; i < levels; ++i) { + const UINT pw = ((width + block_dim - 1) / block_dim + (1u << i) - 1) >> i; + const UINT ph = ((height + block_dim - 1) / block_dim + (1u << i) - 1) >> i; + if (pw <= tail_max_w && ph <= tail_max_h && (levels - i) <= max_in_tail) { + first_tail = i; + break; + } + } + } + + UINT offset = (first_tail < levels) ? tile_bytes : 0; + for (int i = static_cast(first_tail) - 1; i >= 0; --i) { + const UINT cols = columns(static_cast(i)); + const UINT r = rows(static_cast(i)); + tiles_w[i] = (cols + tile_width - 1) / tile_width; + tiles_h[i] = (r + tile_height - 1) / tile_height; + mip_start[i] = offset; + offset += tiles_w[i] * tiles_h[i] * tile_bytes; + } + total_slice_bytes = offset; + + if (first_tail < levels) { + for (UINT i = first_tail; i < levels; ++i) { + const UINT m = max_in_tail - 1 - (i - first_tail); + const UINT tail_offset = (m > 6) ? (16u << m) : (m << 8); + UINT x_idx = 0, y_idx = 0; + for (UINT b = 0; b < 6; ++b) { + y_idx |= ((tail_offset >> (8 + 2 * b)) & 1) << b; + x_idx |= ((tail_offset >> (9 + 2 * b)) & 1) << b; + } + tail_origin_x[i] = x_idx * micro_w; + tail_origin_y[i] = y_idx * micro_h; + mip_start[i] = tail_offset; + } + } + } + + void init_linear() + { + tile_width = 256 / bpe; + tile_height = 1; + tile_bytes = 256; + first_tail = levels; + UINT offset = 0; + for (int i = static_cast(levels) - 1; i >= 0; --i) { + const UINT cols = columns(static_cast(i)); + const UINT r = rows(static_cast(i)); + const UINT pitch = ((cols * bpe + 255) / 256) * 256; + mip_start[i] = offset; + offset += pitch * r; + } + total_slice_bytes = offset; + } + + UINT columns(UINT mip) const + { + return ((std::max)(1u, width >> mip) + block_dim - 1) / block_dim; + } + UINT rows(UINT mip) const + { + return ((std::max)(1u, height >> mip) + block_dim - 1) / block_dim; + } + UINT tiles_wide(UINT mip) const + { + return (mip < first_tail) ? tiles_w[mip] : (columns(mip) + tile_width - 1) / tile_width; + } + UINT tiles_high(UINT mip) const + { + return (mip < first_tail) ? tiles_h[mip] : (rows(mip) + tile_height - 1) / tile_height; + } + UINT padded_columns(UINT mip) const + { + if (mip >= first_tail) { + const UINT tail_max_w = tile_width >> 1; + return (std::max)(micro_w, tail_max_w >> (mip - first_tail)); + } + return tiles_w[mip] * tile_width; + } + UINT padded_rows(UINT mip) const + { + if (mip >= first_tail) { + const UINT tail_max_h = tile_height; + return (std::max)(micro_h, tail_max_h >> (mip - first_tail)); + } + return tiles_h[mip] * tile_height; + } + + UINT64 bytes() const { return UINT64{total_slice_bytes} * slices; } + UINT64 slice_bytes() const { return total_slice_bytes; } + UINT64 alignment() const { return (block_log2 > 0) ? (1ull << block_log2) : 256; } + UINT start(UINT mip) const { return mip_start[mip]; } + + UINT address(UINT mip, UINT x, UINT y, UINT slice) const + { + if (swizzle_mode == SW_LINEAR) { + const UINT pitch = ((columns(mip) * bpe + 255) / 256) * 256; + return slice * total_slice_bytes + mip_start[mip] + y * pitch + x * bpe; + } + if (mip >= first_tail) { + const UINT tx = tail_origin_x[mip] + x; + const UINT ty = tail_origin_y[mip] + y; + return slice * total_slice_bytes + (x_table[tx] | y_table[ty]); + } + const UINT tile_idx = (y / tile_height) * tiles_w[mip] + (x / tile_width); + const UINT within = x_table[x % tile_width] | y_table[y % tile_height]; + return slice * total_slice_bytes + mip_start[mip] + tile_idx * tile_bytes + within; + } + + template + void copy_subresource(UINT mip, UINT slice, unsigned char* dst, const unsigned char* src, UINT pitch) const + { + const UINT cols = columns(mip); + const UINT r = rows(mip); + for (UINT y = 0; y < r; ++y) { + const std::size_t linear_row = static_cast(y) * pitch; + for (UINT x = 0; x < cols; ++x) { + const UINT tiled = address(mip, x, y, slice); + const std::size_t linear = linear_row + static_cast(x) * bpe; + if constexpr (into) { + std::memcpy(dst + tiled, src + linear, bpe); + } else { + std::memcpy(dst + linear, src + tiled, bpe); + } + } + } + } +}; + +} // namespace x2w_startup diff --git a/src/startup_stubs/xg_bc64.inl b/src/startup_stubs/xg_bc64.inl index c611cd67ac..a61a992056 100644 --- a/src/startup_stubs/xg_bc64.inl +++ b/src/startup_stubs/xg_bc64.inl @@ -1,48 +1,50 @@ -namespace bc64 = x2w_startup::bc64; +u64 __stdcall gfx10_add_ref(Computer* self) { return InterlockedIncrement(&self->refs); } -u64 __stdcall bc64_add_ref(Computer* self) { return InterlockedIncrement(&self->refs); } - -long __stdcall bc64_layout(Computer* self, unsigned char* out) +long __stdcall gfx10_layout(Computer* self, unsigned char* out) { - const bc64::Chain chain(self->desc); if (!out) return E_POINTER; std::memset(out, 0, layout_header + 4 * plane_bytes + 8); - put64(out, chain.bytes()); - put64(out + 8, 65536); - put32(out + 0x10, chain.levels); + if (self->bc7_4k_s_layout) { + write_bc7_4k_s_layout(self->desc, out); + return S_OK; + } + const x2w_startup::Gfx10Texture tex(self->desc); + put64(out, tex.bytes()); + put64(out + 8, tex.alignment()); + put32(out + 0x10, tex.levels); put32(out + 0x14, 1); put32(out + 0x1b38, D3D12_RESOURCE_DIMENSION_TEXTURE2D); auto* plane = out + layout_header; put32(plane, 1); - put64(plane + 8, chain.bytes()); - put64(plane + 0x10, chain.slice_bytes()); - put64(plane + 0x20, 65536); - put32(plane + 0x28, 16); - put32(plane + 0x2c, bc64::first_tail); - put32(plane + 0x30, chain.levels - bc64::first_tail); - for (UINT level = 0; level < chain.levels; ++level) { + put64(plane + 8, tex.bytes()); + put64(plane + 0x10, tex.slice_bytes()); + put64(plane + 0x20, tex.alignment()); + put32(plane + 0x28, tex.bpe); + put32(plane + 0x2c, tex.first_tail); + put32(plane + 0x30, tex.levels - tex.first_tail); + for (UINT level = 0; level < tex.levels; ++level) { auto* mip = plane + mip_base + level * mip_bytes; - const UINT columns = chain.columns(level), rows = chain.rows(level); - const bool tail = level >= bc64::first_tail; - const UINT padded_columns = tail ? (std::max)(4u, 256u >> level) : chain.tiles_wide(level) * 64; - const UINT padded_rows = tail ? (std::max)(4u, 512u >> level) : chain.tiles_high(level) * 64; - const UINT span = 16 * padded_columns * padded_rows; + const UINT columns = tex.columns(level), rows = tex.rows(level); + const bool tail = level >= tex.first_tail; + const UINT padded_columns = tex.padded_columns(level); + const UINT padded_rows = tex.padded_rows(level); + const UINT span = tex.bpe * padded_columns * padded_rows; put64(mip, span); - put64(mip + 8, chain.start(level)); + put64(mip + 8, tex.start(level)); put64(mip + 0x10, span); - put32(mip + 0x18, 4 * padded_columns); - put32(mip + 0x1c, 16 * padded_columns); - put32(mip + 0x20, tail ? 256 : 65536); + put32(mip + 0x18, tex.block_dim * padded_columns); + put32(mip + 0x1c, tex.bpe * padded_columns); + put32(mip + 0x20, tail ? 256 : static_cast(tex.alignment())); put32(mip + 0x24, padded_columns); put32(mip + 0x28, padded_rows); - put32(mip + 0x2c, chain.slices); + put32(mip + 0x2c, tex.slices); put32(mip + 0x30, columns); put32(mip + 0x34, rows); - put32(mip + 0x38, 1024u >> level); - put32(mip + 0x3c, chain.height >> level); - put32(mip + 0x40, chain.slices); + put32(mip + 0x38, (std::max)(1u, static_cast(self->desc.Width) >> level)); + put32(mip + 0x3c, (std::max)(1u, self->desc.Height >> level)); + put32(mip + 0x40, tex.slices); put32(mip + 0x44, 1); - put32(mip + 0x48, tail ? 1 : 9); + put32(mip + 0x48, tail ? 1 : tex.swizzle_mode); put32(mip + 0x60, 1); put32(mip + 0x64, tail); } @@ -50,51 +52,74 @@ long __stdcall bc64_layout(Computer* self, unsigned char* out) } template -long __stdcall bc64_copy(Computer* self, unsigned char* target, UINT plane, UINT subresource, const unsigned char* source, - UINT pitch, UINT slice_pitch) +long __stdcall gfx10_copy(Computer* self, unsigned char* target, UINT plane, UINT subresource, const unsigned char* source, + UINT pitch, UINT slice_pitch) { - const bc64::Chain chain(self->desc); - if (plane || subresource >= chain.levels * chain.slices || !target || !source) return E_INVALIDARG; - const UINT level = subresource % chain.levels, slice = subresource / chain.levels; - const u64 row_bytes = 16 * chain.columns(level); - const u64 linear_bytes = u64{chain.rows(level) - 1} * pitch + row_bytes; + if (self->bc7_4k_s_layout) { + if (plane || subresource) return E_INVALIDARG; + if constexpr (into) { + using NotifyBc7 = void (*)(void*, UINT, UINT); + const HMODULE d3d = GetModuleHandleW(L"d3d12_xs.dll"); + const auto notify = d3d ? reinterpret_cast(GetProcAddress(d3d, "x2w_d3d12_bc7_4k_s_written")) : nullptr; + if (!notify && x2w_local::env_on("X2W_D3D12_RENDER")) return E_NOTIMPL; + const HRESULT hr = copy_bc7_4k_s(self->desc, target, source, pitch, slice_pitch); + if (SUCCEEDED(hr) && notify) notify(target, static_cast(self->desc.Width), self->desc.Height); + return hr; + } else { + const x2w_startup::Bc16Surface surface(self->desc); + const UINT row_bytes = surface.columns * x2w_startup::Bc16Surface::block_bytes; + const u64 linear_bytes = u64{surface.rows - 1} * pitch + row_bytes; + if (!target || !source || pitch < row_bytes || (slice_pitch && slice_pitch < linear_bytes)) return E_INVALIDARG; + if (!x2w_local::readable(source, surface.size()) || !x2w_local::writable(target, linear_bytes)) return E_FAIL; + surface.detile(source, target, pitch); + return S_OK; + } + } + const x2w_startup::Gfx10Texture tex(self->desc); + if (plane || subresource >= tex.levels * tex.slices || !target || !source) return E_INVALIDARG; + const UINT level = subresource % tex.levels, slice = subresource / tex.levels; + const u64 row_bytes = u64{tex.bpe} * tex.columns(level); + const u64 linear_bytes = u64{tex.rows(level) - 1} * pitch + row_bytes; if (pitch < row_bytes || (slice_pitch && slice_pitch < linear_bytes)) return E_INVALIDARG; const auto dest = reinterpret_cast(target); const auto src = reinterpret_cast(source); - const auto dest_bytes = into ? chain.bytes() : linear_bytes; - const auto src_bytes = into ? linear_bytes : chain.bytes(); + const auto dest_bytes = into ? tex.bytes() : linear_bytes; + const auto src_bytes = into ? linear_bytes : tex.bytes(); if (dest <= src ? src - dest < dest_bytes : dest - src < src_bytes) return E_INVALIDARG; if (!x2w_local::writable(target, dest_bytes) || !x2w_local::readable(source, src_bytes)) return E_FAIL; - chain.copy(level, slice, target, source, pitch); - if constexpr (into) notify_texture_write(target, chain.bytes()); + tex.copy_subresource(level, slice, target, source, pitch); + if constexpr (into) notify_texture_write(target, tex.bytes()); return S_OK; } -u64 __stdcall bc64_size(Computer* self) { return bc64::Chain(self->desc).bytes(); } -u64 __stdcall bc64_alignment(Computer*) { return 65536; } -u64 __stdcall bc64_offset(Computer* self, UINT plane, UINT level) + +u64 __stdcall gfx10_size(Computer* self) { return x2w_startup::Gfx10Texture(self->desc).bytes(); } +u64 __stdcall gfx10_alignment(Computer* self) { return x2w_startup::Gfx10Texture(self->desc).alignment(); } +u64 __stdcall gfx10_offset(Computer* self, UINT plane, UINT level) { - const bc64::Chain chain(self->desc); - return !plane && level < chain.levels ? chain.start(level) : 0; + const x2w_startup::Gfx10Texture tex(self->desc); + return !plane && level < tex.levels ? tex.start(level) : 0; } -u64 __stdcall bc64_element(Computer* self, UINT plane, UINT level, u64 x, UINT y, UINT slice, UINT sample, UINT* bit) +u64 __stdcall gfx10_element(Computer* self, UINT plane, UINT level, u64 x, UINT y, UINT slice, UINT sample, UINT* bit) { if (bit) *bit = 0; - const bc64::Chain chain(self->desc); - if (plane || level >= chain.levels || slice >= chain.slices || sample || - x >= chain.columns(level) || y >= chain.rows(level)) return 0; - return chain.address(level, static_cast(x), y, slice); + const x2w_startup::Gfx10Texture tex(self->desc); + if (plane || level >= tex.levels || slice >= tex.slices || sample || + x >= tex.columns(level) || y >= tex.rows(level)) return 0; + return tex.address(level, static_cast(x), y, slice); } -long __stdcall bc64_tiling(Computer* self, UINT* tiles, D3D12_PACKED_MIP_INFO* packed, D3D12_TILE_SHAPE* shape, - UINT* count, UINT first, D3D12_SUBRESOURCE_TILING* tilings) +long __stdcall gfx10_tiling(Computer* self, UINT* tiles, D3D12_PACKED_MIP_INFO* packed, D3D12_TILE_SHAPE* shape, + UINT* count, UINT first, D3D12_SUBRESOURCE_TILING* tilings) { const auto& desc = self->desc; - const bc64::Chain chain(desc); - const UINT slice_tiles = chain.slice_bytes() / bc64::tile_bytes; + const x2w_startup::Gfx10Texture tex(desc); + const UINT slice_tiles = static_cast(tex.slice_bytes() / tex.tile_bytes); if (tiles) *tiles = slice_tiles * desc.DepthOrArraySize; - if (packed) *packed = {static_cast(bc64::first_tail), - static_cast(desc.MipLevels - bc64::first_tail), 1, 0}; - if (shape) *shape = {bc64::tile_side, bc64::tile_side, 1}; + if (packed) *packed = {static_cast(tex.first_tail), + static_cast(desc.MipLevels - tex.first_tail), + static_cast(tex.first_tail < desc.MipLevels ? 1 : 0), + 0}; + if (shape) *shape = {tex.tile_width * tex.block_dim, tex.tile_height * tex.block_dim, 1}; if (count) { const UINT subresources = UINT{desc.MipLevels} * desc.DepthOrArraySize; const UINT available = first < subresources ? subresources - first : 0; @@ -103,10 +128,11 @@ long __stdcall bc64_tiling(Computer* self, UINT* tiles, D3D12_PACKED_MIP_INFO* p for (UINT i = 0; i < requested; ++i) { const UINT subresource = first + i; const UINT level = subresource % desc.MipLevels; - if (level >= bc64::first_tail) continue; + if (level >= tex.first_tail) continue; if (tilings) { - const UINT start = (subresource / desc.MipLevels) * slice_tiles + chain.start(level) / bc64::tile_bytes; - tilings[i] = {chain.tiles_wide(level), static_cast(chain.tiles_high(level)), 1, start}; + const UINT start = (subresource / desc.MipLevels) * slice_tiles + + static_cast(tex.start(level) / tex.tile_bytes); + tilings[i] = {tex.tiles_wide(level), static_cast(tex.tiles_high(level)), 1, start}; } ++written; } @@ -114,3 +140,25 @@ long __stdcall bc64_tiling(Computer* self, UINT* tiles, D3D12_PACKED_MIP_INFO* p } return S_OK; } + +// Backward-compatible aliases for existing bc64 table references +inline u64 __stdcall bc64_add_ref(Computer* self) { return gfx10_add_ref(self); } +inline long __stdcall bc64_layout(Computer* self, unsigned char* out) { return gfx10_layout(self, out); } +template +long __stdcall bc64_copy(Computer* self, unsigned char* target, UINT plane, UINT subresource, const unsigned char* source, + UINT pitch, UINT slice_pitch) +{ + return gfx10_copy(self, target, plane, subresource, source, pitch, slice_pitch); +} +inline u64 __stdcall bc64_size(Computer* self) { return gfx10_size(self); } +inline u64 __stdcall bc64_alignment(Computer* self) { return gfx10_alignment(self); } +inline u64 __stdcall bc64_offset(Computer* self, UINT plane, UINT level) { return gfx10_offset(self, plane, level); } +inline u64 __stdcall bc64_element(Computer* self, UINT plane, UINT level, u64 x, UINT y, UINT slice, UINT sample, UINT* bit) +{ + return gfx10_element(self, plane, level, x, y, slice, sample, bit); +} +inline long __stdcall bc64_tiling(Computer* self, UINT* tiles, D3D12_PACKED_MIP_INFO* packed, D3D12_TILE_SHAPE* shape, + UINT* count, UINT first, D3D12_SUBRESOURCE_TILING* tilings) +{ + return gfx10_tiling(self, tiles, packed, shape, count, first, tilings); +} diff --git a/src/startup_stubs/xg_xs.cpp b/src/startup_stubs/xg_xs.cpp index 64912881e5..73ae8485ec 100644 --- a/src/startup_stubs/xg_xs.cpp +++ b/src/startup_stubs/xg_xs.cpp @@ -11,6 +11,7 @@ #include #include #include "startup_stubs/bc64_chain.h" +#include "startup_stubs/gfx10_texture.h" #include #include #include @@ -96,6 +97,10 @@ void notify_texture_write(void* base, u64 bytes) if (notify) notify(base, bytes); } +void write_bc7_4k_s_layout(const D3D12_RESOURCE_DESC& desc, unsigned char* layout); +HRESULT copy_bc7_4k_s(const D3D12_RESOURCE_DESC& desc, unsigned char* dest, const unsigned char* source, + UINT row_pitch, UINT slice_pitch); + #include "startup_stubs/xg_bc64.inl" void write_bc7_4k_s_layout(const D3D12_RESOURCE_DESC& desc, unsigned char* layout) @@ -370,7 +375,7 @@ extern "C" __declspec(noinline) long XGCreateTextureComputer(u64 rcx, u64 rdx, u slots[10] = reinterpret_cast(&bc64_tiling); return slots; }(); - auto* computer = new Computer{bc64::supports(desc) ? bc_table.data() : table.data(), desc, 1, use_bc7_4k_s_layout(desc)}; + auto* computer = new Computer{x2w_startup::Gfx10Texture::supports(desc) ? bc_table.data() : table.data(), desc, 1, use_bc7_4k_s_layout(desc)}; *reinterpret_cast(rdx) = computer; static LONG calls; if (InterlockedIncrement(&calls) <= 3) diff --git a/tests/startup_xg_gfx10_check.py b/tests/startup_xg_gfx10_check.py new file mode 100644 index 0000000000..eb4c9c3728 --- /dev/null +++ b/tests/startup_xg_gfx10_check.py @@ -0,0 +1,216 @@ +"""Verify GFX10 texture computer, micro-tile detiling and mip-tail layout.""" +import ctypes as ct +import struct +import sys + +DESC = struct.Struct(" 0, f"{name}: size must be > 0" + expected_align = 65536 if (layout_code & 0xF) in (9, 10) else (4096 if (layout_code & 0xF) in (5, 6) else 256) + assert alignment == expected_align, f"{name}: align={alignment}, expected={expected_align}" + + # Slot 2 (layout) + layout_buf = ct.create_string_buffer(LAYOUT_BYTES) + assert LAYOUT(slots[2])(computer, layout_buf) == 0 + l_size, l_align, l_mips, l_planes = struct.unpack_from("> m) + block_dim - 1) // block_dim + mh = (max(1, height >> m) + block_dim - 1) // block_dim + row_pitch = mw * bpe + 16 # padded pitch + + # Create synthetic linear content + linear_src = bytearray(mh * row_pitch) + for y in range(mh): + for x in range(mw): + for b in range(bpe): + linear_src[y * row_pitch + x * bpe + b] = (m * 41 + s * 17 + x * 7 + y * 13 + b) & 0xFF + + src_buf = ct.create_string_buffer(bytes(linear_src), len(linear_src)) + subresource = s * mips + m + # Slot 8: CopyIntoSubresource (linear -> tiled) + rc = COPY_INTO(slots[8])(computer, tiled_buf, 0, subresource, src_buf, row_pitch, len(linear_src)) + assert rc == 0, f"{name} mip {m} CopyIntoSubresource failed: 0x{rc & 0xFFFFFFFF:08x}" + + # Slot 9: CopyFromSubresource (tiled -> linear) + dest_buf = ct.create_string_buffer(b"\xaa" * len(linear_src), len(linear_src)) + rc = COPY_INTO(slots[9])(computer, dest_buf, 0, subresource, tiled_buf, row_pitch, len(linear_src)) + assert rc == 0, f"{name} mip {m} CopyFromSubresource failed: 0x{rc & 0xFFFFFFFF:08x}" + + # Verify exact texel match for every row + for y in range(mh): + row_orig = linear_src[y * row_pitch: y * row_pitch + mw * bpe] + row_detiled = dest_buf.raw[y * row_pitch: y * row_pitch + mw * bpe] + assert row_detiled == row_orig, f"{name} slice {s} mip {m} row {y} mismatch after detile!" + + # Verify Slot 6: element address matches + bit = UINT(99) + first_addr = ELEMENT(slots[6])(computer, 0, m, 0, 0, s, 0, ct.byref(bit)) + assert bit.value == 0 + last_addr = ELEMENT(slots[6])(computer, 0, m, mw - 1, mh - 1, s, 0, ct.byref(bit)) + assert last_addr < total_size, f"{name} element address out of bounds: {last_addr} >= {total_size}" + + finally: + RELEASE(slots[1])(computer) + + +def main(dll_path): + create = ct.WinDLL(dll_path).XGCreateTextureComputer + create.argtypes = (PTR, ct.POINTER(PTR), ct.c_uint64, ct.c_uint64) + create.restype = HRESULT + + cases = [ + # BC1 (fmt 71): 8 bytes/block, 64KB_S (0x109) + ("BC1 256x256 5-mip 64KB_S", 71, 256, 256, 5, 1, 0x109, 8, 4), + # BC1 (fmt 71): 8 bytes/block, 4KB_S (0x105) + ("BC1 128x128 4-mip 4KB_S", 71, 128, 128, 4, 1, 0x105, 8, 4), + # BC4 (fmt 80): 8 bytes/block, 64KB_S (0x109) + ("BC4 512x256 6-mip 64KB_S", 80, 512, 256, 6, 1, 0x109, 8, 4), + # BC5 (fmt 83): 16 bytes/block, 64KB_D (0x10A) + ("BC5 256x256 4-mip 64KB_D", 83, 256, 256, 4, 1, 0x10A, 16, 4), + # BC7 (fmt 98): 16 bytes/block, 4KB_S (0x105) + ("BC7 64x64 7-mip 4KB_S", 98, 64, 64, 7, 1, 0x105, 16, 4), + # BC7 (fmt 98): 16 bytes/block, 4KB_D (0x106) + ("BC7 81x69 1-mip 4KB_D", 98, 81, 69, 1, 1, 0x106, 16, 4), + # Uncompressed RGBA8 (fmt 28): 4 bytes/texel, 64KB_S (0x109) + ("RGBA8 128x128 4-mip 64KB_S", 28, 128, 128, 4, 1, 0x109, 4, 1), + # Uncompressed R8 (fmt 61): 1 byte/texel, 64KB_S (0x109) + ("R8 256x256 4-mip 64KB_S", 61, 256, 256, 4, 1, 0x109, 1, 1), + # Uncompressed R16 (fmt 56): 2 bytes/texel, 4KB_S (0x105) + ("R16 64x64 3-mip 4KB_S", 56, 64, 64, 3, 1, 0x105, 2, 1), + # Array of 2 slices: BC7 128x128 3-mip 64KB_S + ("BC7 128x128 3-mip 2-slice 64KB_S", 98, 128, 128, 3, 2, 0x109, 16, 4), + # 256B_S swizzle (0x101): R8 64x64 1-mip + ("R8 64x64 1-mip 256B_S", 61, 64, 64, 1, 1, 0x101, 1, 1), + # Linear (0x100): RGBA8 64x64 1-mip + ("RGBA8 64x64 1-mip LINEAR", 28, 64, 64, 1, 1, 0x100, 4, 1), + # Non-square BC7 128x64 8-mip 4KB_S: mip 7 triggers height >> 7 == 0 + ("BC7 128x64 8-mip 4KB_S", 98, 128, 64, 8, 1, 0x105, 16, 4), + ] + + for name, fmt, w, h, mips, slices, layout, bpe, bdim in cases: + test_format(create, name, fmt, w, h, mips, slices, layout, bpe, bdim) + print(f" {name}: PASS (layout, tiling, slot 8 tile, slot 9 detile roundtrip exact)") + + test_negative_controls(create) + + print(f"All {len(cases)} GFX10 texture computer test cases and negative controls passed successfully!") + return 0 + + +def test_negative_controls(create): + # Valid base descriptor: BC7 64x64, 1-mip, 1-slice, 4KB_S (0x105) + desc = ct.create_string_buffer( + DESC.pack(3, 0, 64, 64, 1, 1, 98, 1, 0, 0x105, 0) + ) + computer = PTR() + hr = create(desc, ct.byref(computer), 0, 0) + assert hr == 0 and computer, "Failed to create computer for negative controls" + slots = ct.cast(computer, ct.POINTER(ct.POINTER(PTR)))[0] + + try: + total_size = SIZE(slots[3])(computer) + tiled_buf = ct.create_string_buffer(total_size) + linear_src = ct.create_string_buffer(16 * 16 * 16) + row_pitch = 16 * 16 # 256 bytes + + # 1. pitch < row_bytes: row_bytes is 256, pass pitch = 255 + rc = COPY_INTO(slots[8])(computer, tiled_buf, 0, 0, linear_src, row_pitch - 1, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"pitch < row_bytes expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + rc = COPY_INTO(slots[9])(computer, linear_src, 0, 0, tiled_buf, row_pitch - 1, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"pitch < row_bytes expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + + # 2. Out-of-range plane (plane = 1 on single-plane resource) + rc = COPY_INTO(slots[8])(computer, tiled_buf, 1, 0, linear_src, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"plane > 0 expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + rc = COPY_INTO(slots[9])(computer, linear_src, 1, 0, tiled_buf, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"plane > 0 expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + + # 3. Out-of-range subresource (subresource = 1 for 1-mip 1-slice resource) + rc = COPY_INTO(slots[8])(computer, tiled_buf, 0, 1, linear_src, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"subresource >= mips*slices expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + rc = COPY_INTO(slots[9])(computer, linear_src, 0, 1, tiled_buf, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"subresource >= mips*slices expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + + # 4. Overlapping source and destination buffers + overlap_buf = ct.create_string_buffer(total_size) + rc = COPY_INTO(slots[8])(computer, overlap_buf, 0, 0, overlap_buf, row_pitch, total_size) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"overlapping src/dst expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + rc = COPY_INTO(slots[9])(computer, overlap_buf, 0, 0, overlap_buf, row_pitch, total_size) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"overlapping src/dst expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + + # 5. Null pointers + rc = COPY_INTO(slots[8])(computer, None, 0, 0, linear_src, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"null dst expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + rc = COPY_INTO(slots[8])(computer, tiled_buf, 0, 0, None, row_pitch, len(linear_src)) + assert (rc & 0xFFFFFFFF) == 0x80070057, f"null src expected E_INVALIDARG, got 0x{rc & 0xFFFFFFFF:08x}" + + finally: + RELEASE(slots[1])(computer) + + # 6. Descriptor with MipLevels > 16 rejected from GFX10 tiling + desc_over_mips = ct.create_string_buffer( + DESC.pack(3, 0, 64, 64, 1, 17, 98, 1, 0, 0x109, 0) + ) + comp_over = PTR() + hr = create(desc_over_mips, ct.byref(comp_over), 0, 0) + if hr == 0 and comp_over: + s = ct.cast(comp_over, ct.POINTER(ct.POINTER(PTR)))[0] + align_val = ALIGN(s[4])(comp_over) + assert align_val != 65536, f"MipLevels=17 unexpectedly accepted by GFX10 computer (align={align_val})" + RELEASE(s[1])(comp_over) + print(" Negative controls: PASS (pitch < row_bytes, plane/subresource out of range, overlap, null, mips > 16)") + + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Usage: startup_xg_gfx10_check.py ") + sys.exit(2) + sys.exit(main(sys.argv[1])) From cbbb8f3acdc9b887e34c348f2299309302c6727c Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Thu, 26 Nov 2026 16:09:39 +0500 Subject: [PATCH 2/9] textures: add footprint guard and non-BC upload check with negative control --- src/startup_stubs/d3d12_draw.inl | 7 +++++ src/startup_stubs/gfx10_texture.h | 2 +- tests/startup_stream_consumer.cpp | 16 ++++++++---- tests/startup_stream_draw.cpp | 37 +++++++++++++++++++++++++++ tests/startup_stream_draw.h | 3 +++ tests/startup_xg_bc7_draw_check.py | 41 ++++++++++++++++++++++++++++++ tests/xg_swizzle_select_check.cpp | 6 +++-- 7 files changed, 104 insertions(+), 8 deletions(-) diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 721c223aad..b4ebd0fa08 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1367,6 +1367,13 @@ bool upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) if (!rows_match) return true; } const x2w_startup::Gfx10Texture gfx10_tex = is_gfx10_tiled ? x2w_startup::Gfx10Texture(original->console) : x2w_startup::Gfx10Texture{}; + if (is_gfx10_tiled) { + bool rows_match = gfx10_tex.levels == mips && gfx10_tex.slices == slices && plan.count == mips; + for (UINT i = 0; rows_match && i < mips; ++i) + rows_match = plan.bytes(i) && plan.rows[i] == gfx10_tex.rows(i) && + plan.row_bytes[i] == u64{gfx10_tex.columns(i)} * gfx10_tex.bpe; + if (!rows_match) return true; + } const u64 total = is_gfx10_tiled ? gfx10_tex.bytes() : tiled_chain ? x2w_startup::bc64::Chain(original->console).bytes() : console ? console_layout->bytes() diff --git a/src/startup_stubs/gfx10_texture.h b/src/startup_stubs/gfx10_texture.h index 62eda09385..4fd61b17a1 100644 --- a/src/startup_stubs/gfx10_texture.h +++ b/src/startup_stubs/gfx10_texture.h @@ -5,7 +5,7 @@ // The micro-tile patterns, macro-tile dimensions, and mip-tail calculations // follow AMD's addrlib in Mesa (src/amd/addrlib, SPDX: MIT): // -// Copyright (C) 2007-2026 Advanced Micro Devices, Inc. All rights reserved. +// Copyright (C) 2007-2024 Advanced Micro Devices, Inc. All rights reserved. // SPDX-License-Identifier: MIT #include diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 8d672d3853..7495419dd4 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -469,11 +469,17 @@ int main(int argc, char** argv) static_cast(std::strtoul(argv[8], nullptr, 10)), std::strcmp(argv[9], "tiled") == 0}; bc7.small4k = std::strcmp(argv[9], "small4k") == 0; - if (bc7.small4k ? bc7.width != 32 || bc7.height != 32 - : (bc7.width != 64 || bc7.height != 64) && (bc7.width != 81 || bc7.height != 69)) return 2; - if (std::strncmp(argv[9], "packed:", 7) == 0) bc7.packed = argv[9] + 7; - else if (bc7.small4k) {} - else if (!bc7.tiled && std::strcmp(argv[9], "linear") != 0) return 2; + bc7.rgba8_4k_s = std::strcmp(argv[9], "rgba8_4k_s") == 0 || std::strcmp(argv[9], "rgba8_4k_s_untiled") == 0; + if (bc7.rgba8_4k_s) { + bc7.tiled = std::strcmp(argv[9], "rgba8_4k_s") == 0; + if (bc7.width != 64 || bc7.height != 64) return 2; + } else if (bc7.small4k) { + if (bc7.width != 32 || bc7.height != 32) return 2; + } else { + if ((bc7.width != 64 || bc7.height != 64) && (bc7.width != 81 || bc7.height != 69)) return 2; + if (std::strncmp(argv[9], "packed:", 7) == 0) bc7.packed = argv[9] + 7; + else if (!bc7.tiled && std::strcmp(argv[9], "linear") != 0) return 2; + } } ComPtr adapter; void* device = nullptr; diff --git a/tests/startup_stream_draw.cpp b/tests/startup_stream_draw.cpp index 3f2405a97a..043f14eac6 100644 --- a/tests/startup_stream_draw.cpp +++ b/tests/startup_stream_draw.cpp @@ -255,6 +255,41 @@ bool bind_small4k(ID3D12Device* desktop, void* guest, const StartupBc7Input& inp return bind_table(desktop, guest, texture, binding); } +bool bind_rgba8_4k_s(ID3D12Device* desktop, void* guest, const StartupBc7Input& input, Bc7Binding& binding) +{ + std::ifstream file(input.blocks, std::ios::binary); + const std::vector texels{std::istreambuf_iterator(file), std::istreambuf_iterator{}}; + const UINT row_bytes = input.width * 4; + if (texels.size() != static_cast(row_bytes) * input.height) return false; + const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, input.width, input.height, 1, 1, + DXGI_FORMAT_R8G8B8A8_UNORM, {1, 0}, static_cast(0x105), D3D12_RESOURCE_FLAG_NONE}; + void** computer = nullptr; + if (FAILED(XGCreateTextureComputer(&desc, &computer, 0, 0)) || !computer) return false; + const auto table = static_cast(computer[0]); + using Query = HRESULT(*)(void*, unsigned char*); + using Write = HRESULT(*)(void*, unsigned char*, UINT, UINT, const unsigned char*, UINT, UINT); + std::array layout{}; + UINT64 span = 0; + HRESULT hr = reinterpret_cast(table[2])(computer, layout.data()); + if (SUCCEEDED(hr)) std::memcpy(&span, layout.data(), sizeof span); + if (span != 16384) hr = E_FAIL; + if (SUCCEEDED(hr)) { + binding.backing.resize(static_cast(span), 0xa5); + if (input.tiled) { + hr = reinterpret_cast(table[8])(computer, binding.backing.data(), 0, 0, texels.data(), + row_bytes, static_cast(texels.size())); + } else { + std::memcpy(binding.backing.data(), texels.data(), (std::min)(binding.backing.size(), texels.size())); + } + } + reinterpret_cast(table[1])(computer); + if (FAILED(hr)) return false; + void* texture = nullptr; + if (FAILED(static_cast(invoke(guest, 133, arg(binding.backing.data()), arg(&desc), + D3D12_RESOURCE_STATE_COMMON, 0, arg(&__uuidof(ID3D12Resource)), arg(&texture))))) return false; + return bind_table(desktop, guest, texture, binding); +} + // A shader-visible heap whose first entry is a view of every mip of texture; binding.table is its GPU handle. bool bind_table(ID3D12Device* desktop, void* guest, void* texture, Bc7Binding& binding) { @@ -298,6 +333,8 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char* if (const int rc = bind_packed(desktop.Get(), guest, *bc7, binding)) return rc; } else if (bc7 && bc7->small4k) { if (!bind_small4k(desktop.Get(), guest, *bc7, binding)) return 35; + } else if (bc7 && bc7->rgba8_4k_s) { + if (!bind_rgba8_4k_s(desktop.Get(), guest, *bc7, binding)) return 36; } else if (bc7 && !bind_bc7(desktop.Get(), guest, *bc7, binding)) return 34; StreamTarget frame; if (two_targets) frame.count = 2; // a second RGBA8 target of the same size, written after the first diff --git a/tests/startup_stream_draw.h b/tests/startup_stream_draw.h index 4e42a9e9bb..e2463d6c52 100644 --- a/tests/startup_stream_draw.h +++ b/tests/startup_stream_draw.h @@ -17,6 +17,9 @@ struct StartupBc7Input { // holds mip 0 then mip 1 as tight rows; both go through XG slot 8 into memory of exactly the size XG slot 2 // reports, followed by a no-access guard page. The target is 48x32: mip 0 at the left, mip 1 top right. bool small4k = false; + // A 64x64 R8G8B8A8 texture with explicit 4KB_S layout (0x105). When tiled is true, data is tiled + // via XG slot 8; when false, raw linear bytes are placed as a negative swizzle control. + bool rgba8_4k_s = false; }; int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char* pixels, diff --git a/tests/startup_xg_bc7_draw_check.py b/tests/startup_xg_bc7_draw_check.py index 5c92926a01..607806fa5b 100644 --- a/tests/startup_xg_bc7_draw_check.py +++ b/tests/startup_xg_bc7_draw_check.py @@ -78,6 +78,47 @@ def check(work, consumer, dxc, backend): f"read {actual[first:first + 4].hex()}, expected {reference[first:first + 4].hex()}") else: print(f"{backend}: {width}x{height} {layout} draw matched all {width * height} reference pixels") + + # Non-BC upload test (RGBA8 layout 0x105, 4KB_S) and negative swizzle control. + rgba8_reference = bytearray(64 * 64 * 4) + for y in range(64): + for x in range(64): + idx = (y * 64 + x) * 4 + rgba8_reference[idx:idx + 4] = bytes(((x * 4 + 7) & 255, (y * 4 + 13) & 255, (x ^ y ^ 0xA5) & 255, 255)) + upload.write_bytes(rgba8_reference) + + # 1. Tiled upload via XG slot 8 into 0x105, detiled by upload_texture via is_gfx10_tiled. + if image.exists(): + image.unlink() + result = subprocess.run(base + ["64", "64", "rgba8_4k_s"], env=env, capture_output=True, text=True) + print(result.stdout, end="") + for line in result.stderr.splitlines(): + if "debug layer:" in line or "x2w-d3d12-debug " in line: + print(line) + if result.returncode or "-> drawn;" not in result.stderr: + raise RuntimeError(f"{backend} 64x64 rgba8_4k_s draw failed ({result.returncode})\n{result.stderr}") + actual = image.read_bytes() + assert len(actual) == len(rgba8_reference), f"rgba8_4k_s: read {len(actual)} bytes, expected {len(rgba8_reference)}" + if actual != rgba8_reference: + first = next(i for i in range(0, len(rgba8_reference), 4) if actual[i:i + 4] != rgba8_reference[i:i + 4]) + x, y = first // 4 % 64, first // 4 // 64 + mismatches.append(f"{backend} 64x64 rgba8_4k_s: pixel ({x}, {y}) " + f"read {actual[first:first + 4].hex()}, expected {rgba8_reference[first:first + 4].hex()}") + else: + print(f"{backend}: 64x64 rgba8_4k_s draw matched all {64 * 64} reference pixels") + + # 2. Negative control: linear / untiled data placed in 0x105 buffer must fail to match reference. + if image.exists(): + image.unlink() + result = subprocess.run(base + ["64", "64", "rgba8_4k_s_untiled"], env=env, capture_output=True, text=True) + if result.returncode or "-> drawn;" not in result.stderr: + raise RuntimeError(f"{backend} 64x64 rgba8_4k_s_untiled draw failed ({result.returncode})\n{result.stderr}") + actual_untiled = image.read_bytes() + assert actual_untiled != rgba8_reference, f"{backend}: negative control failed, untiled draw unexpectedly matched reference" + diff_count = sum(actual_untiled[i:i + 4] != rgba8_reference[i:i + 4] for i in range(0, len(rgba8_reference), 4)) + assert diff_count >= 3000, f"{backend}: negative control only differed on {diff_count}/4096 pixels" + print(f"{backend}: 64x64 rgba8_4k_s negative swizzle control confirmed ({diff_count}/4096 pixels differ)") + if mismatches: raise AssertionError("\n".join(mismatches)) return 0 diff --git a/tests/xg_swizzle_select_check.cpp b/tests/xg_swizzle_select_check.cpp index ab51a34736..e44c3a105b 100644 --- a/tests/xg_swizzle_select_check.cpp +++ b/tests/xg_swizzle_select_check.cpp @@ -578,6 +578,7 @@ int gfx10_tiling_reference() {"BGRA8 64x64 3m 4KB_S", DXGI_FORMAT_B8G8R8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 64, 64, 3, 1, 0x105, ADDR_SW_4KB_S}, {"RGBA16 64x64 3m 64KB_D", DXGI_FORMAT_R16G16B16A16_FLOAT, ADDR_FMT_16_16_16_16, 64, 64, 64, 3, 1, 0x10A, ADDR_SW_64KB_D}, {"RGBA32 32x32 3m 4KB_S", DXGI_FORMAT_R32G32B32A32_FLOAT, ADDR_FMT_32_32_32_32, 128, 32, 32, 3, 1, 0x105, ADDR_SW_4KB_S}, + {"RGBA8 64x64 3m LINEAR", DXGI_FORMAT_R8G8B8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 64, 64, 3, 1, 0x100, ADDR_SW_LINEAR}, }; for (const auto& c : cases) { @@ -614,11 +615,12 @@ int gfx10_tiling_reference() out.pMipInfo = mip_info.data(); const ADDR_E_RETURNCODE rc = Addr2ComputeSurfaceInfo(lib, &in, &out); + const bool is_linear = (c.mode == ADDR_SW_LINEAR); bool ok = rc == ADDR_OK && out.surfSize == tex.bytes() && out.sliceSize == tex.slice_bytes() && - out.baseAlign == tex.alignment() && out.firstMipIdInTail == tex.first_tail; + out.baseAlign == tex.alignment() && (is_linear || out.firstMipIdInTail == tex.first_tail); if (ok) { for (UINT_32 m = 0; m < c.mips; ++m) { - const UINT64 expected_off = (m < tex.first_tail) ? mip_info[m].macroBlockOffset : mip_info[m].offset; + const UINT64 expected_off = (is_linear || m < tex.first_tail) ? mip_info[m].macroBlockOffset : mip_info[m].offset; if (expected_off != tex.start(m)) { std::printf("FAIL %s mip %u offset: addrlib=%llu tex=%llu\n", c.name, m, static_cast(expected_off), From 8903a16e9d1f93f5d470196db2f02c5f78189459 Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Sat, 28 Nov 2026 13:31:35 +0500 Subject: [PATCH 3/9] startup: route multi-mip linear uploads via Gfx10Texture and add tests --- CMakePresets.json | 2 +- docs/experiments.md | 16 +++++++ src/startup_stubs/d3d12_draw.inl | 4 +- .../checks/python-linux/startup_xg_gfx10.txt | 1 + tests/startup_stream_consumer.cpp | 4 ++ tests/startup_stream_draw.cpp | 47 +++++++++++++++++++ tests/startup_stream_draw.h | 4 ++ tests/startup_xg_bc7_draw_check.py | 34 ++++++++++++++ 8 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 tests/checks/python-linux/startup_xg_gfx10.txt diff --git a/CMakePresets.json b/CMakePresets.json index 5c074df421..006cb5d80b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -47,7 +47,7 @@ "displayName": "Windows pull request smoke tests", "filter": { "include": { - "name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package)$" + "name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_gfx2hlsl_cvt_off_f32_i4_controls|startup_gfx2hlsl_sad_hi_msad_controls|startup_indirect_(dispatch|count_split|draw(_indexed)?|mesh(_xmem_arguments(_skip_wait)?)?|counts_control)_warp|startup_indirect_mesh_lease_warp_dual(-trace(-disabled)?)?|startup_shader_cache_key|startup_present_readback|xmem_(run_break_readers|cross_call_merge|placeholder_split|map_split_first)(_[a-z_]+)?|startup_dstorage_break_window(_[a-z_]+)?|xmem_page_runs_device(_join)?_warp|linear_buffer_backing_share_warp|startup_stage_package|startup_xg_gfx10_runtime|xg_gfx10_tiling_reference|startup_xg_bc7_draw_warp)$" } } }, diff --git a/docs/experiments.md b/docs/experiments.md index 2b5b0a7bcc..dc9c8f8423 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16763,6 +16763,22 @@ cmake --build --preset release --target startup_stream_consumer startup_stub_xg_ ctest --preset release --no-tests=error --output-on-failure -R '^(startup_xg_bc_(array|chain)_(hardware|warp)|startup_xg_bc_tiling|xg_bc64_tiling_reference|startup_xg_bc7_layout)$' ``` +### GFX10 texture computer and desktop draw detiling runtime + +`Gfx10Texture` (`src/startup_stubs/gfx10_texture.h`) implements the runtime tiling and detiling computer for GFX10 textures across 256 B, 4 KiB, and 64 KiB blocks in standard (`_S`) and display (`_D`) modes (explicit layouts `0x101`, `0x102`, `0x105`, `0x106`, `0x109`, `0x10a`), as well as multi-mip and multi-slice linear layout `0x100` (packed slices, smallest mip first). It supports 1-, 2-, 4-, 8-, and 16-byte elements (including BC1 to BC7 block-compressed formats): + +- XG texture-computer stand-in (`src/startup_stubs/xg_xs.cpp`) provides slot 2 (layout query, mip starts, alignment), slot 3 (total allocation size), slot 6 (element coordinate offset query), slot 8 (`CopyIntoSubresource` for linear to tiled upload), and slot 9 (`CopyFromSubresource` for tiled to linear readback). +- On GFX10.3 / RDNA2 with RbPlus enabled (Scarlett hardware), AMD AddrLib (`src/amd/addrlib`) selects `GFX10_SW_256_D_RBPLUS_PATINFO` (pattern index 39: `"----x0x1y0y1x2y2"`), where bit 6 is $x_2$ and bit 7 is $y_2$. +- The desktop draw uploader (`src/startup_stubs/d3d12_draw.inl`) detiles placed CPU textures via `is_gfx10_tiled` for all explicit GFX10 tiled modes and multi-mip or array linear (0x100) textures into desktop D3D12 copyable footprints on upload. +- `xg_gfx10_tiling_reference` independently compares `Gfx10Texture` against Mesa 25.1.0 AMD AddrLib on Navi21 for 22 surface shapes, validating surface sizes, slice strides, base alignments, mip offsets, and 349,547 coordinate addresses with 0 mismatches. +- `startup_xg_gfx10_runtime` tests layout queries, slot-6 coordinate offsets, slot-8 tiling, slot-9 detiling, pinned AddrLib offsets across all five element sizes, implicit layout routing, and negative controls. +- `startup_xg_bc7_draw_{warp,hardware}` executes end-to-end draw tests with wrapped XG uploads for 4 KiB standard RGBA8 (`rgba8_4k_s`), 3-mip linear RGBA8 (`rgba8_linear_3m`), and their respective negative controls. + +```powershell +cmake --build --preset dev --target startup_stub_xg_xs startup_stub_consumer xg_swizzle_select_check +ctest --preset dev --no-tests=error -R '^(startup_xg_gfx10_runtime|xg_gfx10_tiling_reference|startup_xg_bc7_draw_(warp|hardware))$' -V +``` + ### Slot-10 tile plan for layout `0x10a` For a two-dimensional texture with layout `0x10a`, one sample and a format with a known 64 KiB tile shape, XG texture-computer slot 10 is answered from `src/startup_stubs/tile64_plan.h` instead of a desktop reserved resource. The plan follows one rule: diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 9d8d1f129b..332fbae4d0 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1748,7 +1748,7 @@ bool upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) const bool detile_console = console || placed_display_bc7; const bool is_gfx10_tiled = !placed_display_bc7 && !tiled_address && !single && original && x2w_startup::Gfx10Texture::supports(original->console) && - x2w_startup::Gfx10Texture::is_tiled(original->console); + (x2w_startup::Gfx10Texture::is_tiled(original->console) || mips > 1 || slices > 1); // Any other texture slot 70 publishes holds its texels in the console layout its description names // (gfx10_layout.h, address_texture.h). const bool tiled_bc7 = !is_gfx10_tiled && !tiled_chain && !tiled_address && !placed_display_bc7 && written.bc7_width != 0; @@ -1800,7 +1800,7 @@ bool upload_texture(Wrapper* self, Wrapper* resource, ID3D12Resource* texture) const bool announced = state.generation != generation; const UINT elapsed = static_cast(frame_number) - static_cast(state.checked_frame); // A single texel (at most 16 bytes) is rehashed on every bind, so a write between two draws is seen. - const bool recheck = single || ((tiled_address || is_gfx10_tiled) ? elapsed != 0 + const bool recheck = single || ((tiled_address || tiled_chain) ? elapsed != 0 : x2w_startup::recheck_cpu_texture(desc, total, elapsed)); const bool reusable = state.done && (!state.pending_list || state.pending_list == list); if (reusable && !announced && !recheck) return true; diff --git a/tests/checks/python-linux/startup_xg_gfx10.txt b/tests/checks/python-linux/startup_xg_gfx10.txt new file mode 100644 index 0000000000..810375bcd3 --- /dev/null +++ b/tests/checks/python-linux/startup_xg_gfx10.txt @@ -0,0 +1 @@ +tests/startup_xg_gfx10_check.py diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index f4be745def..4974781701 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -860,9 +860,13 @@ int main(int argc, char** argv) std::strcmp(argv[9], "tiled") == 0}; bc7.small4k = std::strcmp(argv[9], "small4k") == 0; bc7.rgba8_4k_s = std::strcmp(argv[9], "rgba8_4k_s") == 0 || std::strcmp(argv[9], "rgba8_4k_s_untiled") == 0; + bc7.rgba8_linear_3m = std::strcmp(argv[9], "rgba8_linear_3m") == 0 || std::strcmp(argv[9], "rgba8_linear_3m_desktop") == 0; if (bc7.rgba8_4k_s) { bc7.tiled = std::strcmp(argv[9], "rgba8_4k_s") == 0; if (bc7.width != 64 || bc7.height != 64) return 2; + } else if (bc7.rgba8_linear_3m) { + bc7.tiled = std::strcmp(argv[9], "rgba8_linear_3m") == 0; + if (bc7.width != 64 || bc7.height != 64) return 2; } else if (bc7.small4k) { if (bc7.width != 32 || bc7.height != 32) return 2; } else { diff --git a/tests/startup_stream_draw.cpp b/tests/startup_stream_draw.cpp index 1f10208216..495fc7df49 100644 --- a/tests/startup_stream_draw.cpp +++ b/tests/startup_stream_draw.cpp @@ -403,6 +403,51 @@ bool bind_rgba8_4k_s(ID3D12Device* desktop, void* guest, const StartupBc7Input& return bind_table(desktop, guest, texture, binding); } +bool bind_rgba8_linear_3m(ID3D12Device* desktop, void* guest, const StartupBc7Input& input, Bc7Binding& binding) +{ + std::ifstream file(input.blocks, std::ios::binary); + const std::vector texels{std::istreambuf_iterator(file), std::istreambuf_iterator{}}; + const UINT row_bytes = input.width * 4; + if (texels.size() != static_cast(row_bytes) * input.height) return false; + const D3D12_RESOURCE_DESC desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, input.width, input.height, 1, 3, + DXGI_FORMAT_R8G8B8A8_UNORM, {1, 0}, static_cast(0x100), D3D12_RESOURCE_FLAG_NONE}; + void** computer = nullptr; + if (FAILED(XGCreateTextureComputer(&desc, &computer, 0, 0)) || !computer) return false; + const auto table = static_cast(computer[0]); + using Query = HRESULT(*)(void*, unsigned char*); + using Write = HRESULT(*)(void*, unsigned char*, UINT, UINT, const unsigned char*, UINT, UINT); + std::array layout{}; + UINT64 span = 0; + HRESULT hr = reinterpret_cast(table[2])(computer, layout.data()); + if (SUCCEEDED(hr)) std::memcpy(&span, layout.data(), sizeof span); + if (span != 28672) hr = E_FAIL; + if (SUCCEEDED(hr)) { + binding.backing.resize(static_cast(span), 0xa5); + if (input.tiled) { + hr = reinterpret_cast(table[8])(computer, binding.backing.data(), 0, 0, texels.data(), + row_bytes, static_cast(texels.size())); + if (SUCCEEDED(hr)) { + std::vector mip1(32 * 32 * 4, 0x7f); + hr = reinterpret_cast(table[8])(computer, binding.backing.data(), 0, 1, mip1.data(), + 32 * 4, static_cast(mip1.size())); + } + if (SUCCEEDED(hr)) { + std::vector mip2(16 * 16 * 4, 0x3f); + hr = reinterpret_cast(table[8])(computer, binding.backing.data(), 0, 2, mip2.data(), + 16 * 4, static_cast(mip2.size())); + } + } else { + std::memcpy(binding.backing.data(), texels.data(), (std::min)(binding.backing.size(), texels.size())); + } + } + reinterpret_cast(table[1])(computer); + if (FAILED(hr)) return false; + void* texture = nullptr; + if (FAILED(static_cast(invoke(guest, 133, arg(binding.backing.data()), arg(&desc), + D3D12_RESOURCE_STATE_COMMON, 0, arg(&__uuidof(ID3D12Resource)), arg(&texture))))) return false; + return bind_table(desktop, guest, texture, binding); +} + // A shader-visible heap whose first entry is a view of every mip of texture; binding.table is its GPU handle. bool bind_table(ID3D12Device* desktop, void* guest, void* texture, Bc7Binding& binding) { @@ -450,6 +495,8 @@ int check_stream_draw(IDXGIAdapter* adapter, void* guest, void* pso, const char* if (!bind_small4k(desktop.Get(), guest, *bc7, binding)) return 35; } else if (bc7 && bc7->rgba8_4k_s) { if (!bind_rgba8_4k_s(desktop.Get(), guest, *bc7, binding)) return 36; + } else if (bc7 && bc7->rgba8_linear_3m) { + if (!bind_rgba8_linear_3m(desktop.Get(), guest, *bc7, binding)) return 37; } else if (bc7 && !bind_bc7(desktop.Get(), guest, *bc7, binding)) return 34; StreamTarget frame; if (two_targets) frame.count = 2; // a second RGBA8 target of the same size, written after the first diff --git a/tests/startup_stream_draw.h b/tests/startup_stream_draw.h index c0d54041ed..e0bbca4766 100644 --- a/tests/startup_stream_draw.h +++ b/tests/startup_stream_draw.h @@ -20,6 +20,10 @@ struct StartupBc7Input { // A 64x64 R8G8B8A8 texture with explicit 4KB_S layout (0x105). When tiled is true, data is tiled // via XG slot 8; when false, raw linear bytes are placed as a negative swizzle control. bool rgba8_4k_s = false; + // A 64x64 R8G8B8A8 texture with 3 mips and explicit linear layout (0x100). When tiled is true, + // data is placed via XG slot 8 (smallest mip first: mips 2, 1, 0); when false, data is placed + // at offset 0 in desktop footprint order as a negative layout control. + bool rgba8_linear_3m = false; bool display64k = false; }; diff --git a/tests/startup_xg_bc7_draw_check.py b/tests/startup_xg_bc7_draw_check.py index 9fcd510595..68164f08eb 100644 --- a/tests/startup_xg_bc7_draw_check.py +++ b/tests/startup_xg_bc7_draw_check.py @@ -138,6 +138,40 @@ def check(work, consumer, dxc, backend): assert diff_count >= 3000, f"{backend}: negative control only differed on {diff_count}/4096 pixels" print(f"{backend}: 64x64 rgba8_4k_s negative swizzle control confirmed ({diff_count}/4096 pixels differ)") + # 3. Multi-mip linear upload (RGBA8 64x64 3-mip 0x100) placed smallest-first by XG slot 8, + # detiled/uploaded by upload_texture via is_gfx10_tiled. + if image.exists(): + image.unlink() + result = subprocess.run(base + ["64", "64", "rgba8_linear_3m"], env=env, capture_output=True, text=True) + print(result.stdout, end="") + for line in result.stderr.splitlines(): + if "debug layer:" in line or "x2w-d3d12-debug " in line: + print(line) + if result.returncode or "-> drawn;" not in result.stderr: + raise RuntimeError(f"{backend} 64x64 rgba8_linear_3m draw failed ({result.returncode})\n{result.stderr}") + actual_linear_3m = image.read_bytes() + assert len(actual_linear_3m) == len(rgba8_reference), f"rgba8_linear_3m: read {len(actual_linear_3m)} bytes, expected {len(rgba8_reference)}" + if actual_linear_3m != rgba8_reference: + first = next(i for i in range(0, len(rgba8_reference), 4) if actual_linear_3m[i:i + 4] != rgba8_reference[i:i + 4]) + x, y = first // 4 % 64, first // 4 // 64 + mismatches.append(f"{backend} 64x64 rgba8_linear_3m: pixel ({x}, {y}) " + f"read {actual_linear_3m[first:first + 4].hex()}, expected {rgba8_reference[first:first + 4].hex()}") + else: + print(f"{backend}: 64x64 rgba8_linear_3m draw matched all {64 * 64} reference pixels") + + # 4. Negative control: linear 3-mip texture placed in standard desktop footprint order (offset 0 for mip 0) + # must fail to match reference because upload_texture reads mip 0 from XG's smallest-first offset 12288. + if image.exists(): + image.unlink() + result = subprocess.run(base + ["64", "64", "rgba8_linear_3m_desktop"], env=env, capture_output=True, text=True) + if result.returncode or "-> drawn;" not in result.stderr: + raise RuntimeError(f"{backend} 64x64 rgba8_linear_3m_desktop draw failed ({result.returncode})\n{result.stderr}") + actual_linear_desktop = image.read_bytes() + assert actual_linear_desktop != rgba8_reference, f"{backend}: negative control failed, desktop layout unexpectedly matched reference" + diff_count = sum(actual_linear_desktop[i:i + 4] != rgba8_reference[i:i + 4] for i in range(0, len(rgba8_reference), 4)) + assert diff_count >= 1000, f"{backend}: negative control only differed on {diff_count}/4096 pixels" + print(f"{backend}: 64x64 rgba8_linear_3m negative layout control confirmed ({diff_count}/4096 pixels differ)") + if mismatches: raise AssertionError("\n".join(mismatches)) return 0 From 2af2f0f5216d232b777b5c30942c881beae6fb2e Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Sat, 28 Nov 2026 13:48:45 +0500 Subject: [PATCH 4/9] build: add GFX10 tiling targets to pr build preset --- CMakePresets.json | 3 ++- tests/checks/python-linux/startup_xg_gfx10.txt | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 tests/checks/python-linux/startup_xg_gfx10.txt diff --git a/CMakePresets.json b/CMakePresets.json index eed548850d..e416ffc7b8 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -34,7 +34,8 @@ "xmem_run_break_readers_check", "xmem_run_break_readers_control", "xmem_cross_call_merge_check", "xmem_placeholder_split_check", "xmem_map_split_first_check", "startup_dstorage_break_window_check", "xmem_page_runs_device_check", "linear_buffer_backing_check", - "bcpack_formats_check", "startup_stub_consumer" + "bcpack_formats_check", "startup_stub_consumer", + "startup_stub_xg_xs", "xg_swizzle_select_check", "startup_stream_consumer" ] }, { "name": "release", "configurePreset": "release" }, diff --git a/tests/checks/python-linux/startup_xg_gfx10.txt b/tests/checks/python-linux/startup_xg_gfx10.txt deleted file mode 100644 index 810375bcd3..0000000000 --- a/tests/checks/python-linux/startup_xg_gfx10.txt +++ /dev/null @@ -1 +0,0 @@ -tests/startup_xg_gfx10_check.py From 00c53f919bb9213e56b3996246188f342327d631 Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Sat, 28 Nov 2026 14:49:34 +0500 Subject: [PATCH 5/9] startup: align Gfx10Texture layout extents with ShiftCeil and document RbPlus hypothesis --- docs/experiments.md | 6 +++--- src/startup_stubs/gfx10_texture.h | 29 +++++++++++++++++++++-------- tests/startup_xg_gfx10_check.py | 6 ++++++ tests/xg_swizzle_select_check.cpp | 1 + 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 3c06cd2215..ee84eb67dc 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16782,14 +16782,14 @@ ctest --preset release --no-tests=error --output-on-failure -R '^(startup_xg_bc_ `Gfx10Texture` (`src/startup_stubs/gfx10_texture.h`) implements the runtime tiling and detiling computer for GFX10 textures across 256 B, 4 KiB, and 64 KiB blocks in standard (`_S`) and display (`_D`) modes (explicit layouts `0x101`, `0x102`, `0x105`, `0x106`, `0x109`, `0x10a`), as well as multi-mip and multi-slice linear layout `0x100` (packed slices, smallest mip first). It supports 1-, 2-, 4-, 8-, and 16-byte elements (including BC1 to BC7 block-compressed formats): - XG texture-computer stand-in (`src/startup_stubs/xg_xs.cpp`) provides slot 2 (layout query, mip starts, alignment), slot 3 (total allocation size), slot 6 (element coordinate offset query), slot 8 (`CopyIntoSubresource` for linear to tiled upload), and slot 9 (`CopyFromSubresource` for tiled to linear readback). -- On GFX10.3 / RDNA2 with RbPlus enabled (Scarlett hardware), AMD AddrLib (`src/amd/addrlib`) selects `GFX10_SW_256_D_RBPLUS_PATINFO` (pattern index 39: `"----x0x1y0y1x2y2"`), where bit 6 is $x_2$ and bit 7 is $y_2$. +- In AMD AddrLib (`src/amd/addrlib`) configured for GFX10.3 / RDNA2 (Navi21 reference with `supportRbPlus = 1`), `GetSwizzlePatternInfo` selects `GFX10_SW_256_D_RBPLUS_PATINFO` (pattern index 39: `"----x0x1y0y1x2y2"`), where bit 6 is $x_2$ and bit 7 is $y_2$, while Navi1x without RbPlus selects pattern 2 (`"----x0x1y0y1y2x2"`). Whether console hardware matches the RbPlus pattern remains an open hypothesis pending independent hardware measurement. - The desktop draw uploader (`src/startup_stubs/d3d12_draw.inl`) detiles placed CPU textures via `is_gfx10_tiled` for all explicit GFX10 tiled modes and multi-mip or array linear (0x100) textures into desktop D3D12 copyable footprints on upload. -- `xg_gfx10_tiling_reference` independently compares `Gfx10Texture` against Mesa 25.1.0 AMD AddrLib on Navi21 for 22 surface shapes, validating surface sizes, slice strides, base alignments, mip offsets, and 349,547 coordinate addresses with 0 mismatches. +- `xg_gfx10_tiling_reference` independently compares `Gfx10Texture` against Mesa 25.1.0 AMD AddrLib on Navi21 for 23 surface shapes, validating surface sizes, slice strides, base alignments, mip offsets, and coordinate addresses with 0 mismatches. - `startup_xg_gfx10_runtime` tests layout queries, slot-6 coordinate offsets, slot-8 tiling, slot-9 detiling, pinned AddrLib offsets across all five element sizes, implicit layout routing, and negative controls. - `startup_xg_bc7_draw_{warp,hardware}` executes end-to-end draw tests with wrapped XG uploads for 4 KiB standard RGBA8 (`rgba8_4k_s`), 3-mip linear RGBA8 (`rgba8_linear_3m`), and their respective negative controls. ```powershell -cmake --build --preset dev --target startup_stub_xg_xs startup_stub_consumer xg_swizzle_select_check +cmake --build --preset dev --target startup_stub_xg_xs startup_stream_consumer xg_swizzle_select_check ctest --preset dev --no-tests=error -R '^(startup_xg_gfx10_runtime|xg_gfx10_tiling_reference|startup_xg_bc7_draw_(warp|hardware))$' -V ``` diff --git a/src/startup_stubs/gfx10_texture.h b/src/startup_stubs/gfx10_texture.h index 4fd61b17a1..a49447b74c 100644 --- a/src/startup_stubs/gfx10_texture.h +++ b/src/startup_stubs/gfx10_texture.h @@ -284,8 +284,8 @@ struct Gfx10Texture { if (block_log2 >= 12 && levels > 1) { for (UINT i = 0; i < levels; ++i) { - const UINT pw = ((width + block_dim - 1) / block_dim + (1u << i) - 1) >> i; - const UINT ph = ((height + block_dim - 1) / block_dim + (1u << i) - 1) >> i; + const UINT pw = extent_columns(i); + const UINT ph = extent_rows(i); if (pw <= tail_max_w && ph <= tail_max_h && (levels - i) <= max_in_tail) { first_tail = i; break; @@ -295,8 +295,8 @@ struct Gfx10Texture { UINT64 offset = (first_tail < levels) ? tile_bytes : 0; for (int i = static_cast(first_tail) - 1; i >= 0; --i) { - const UINT cols = columns(static_cast(i)); - const UINT r = rows(static_cast(i)); + const UINT cols = extent_columns(static_cast(i)); + const UINT r = extent_rows(static_cast(i)); tiles_w[i] = (cols + tile_width - 1) / tile_width; tiles_h[i] = (r + tile_height - 1) / tile_height; mip_start[i] = offset; @@ -328,8 +328,8 @@ struct Gfx10Texture { first_tail = levels; UINT64 offset = 0; for (int i = static_cast(levels) - 1; i >= 0; --i) { - const UINT cols = columns(static_cast(i)); - const UINT r = rows(static_cast(i)); + const UINT cols = extent_columns(static_cast(i)); + const UINT r = extent_rows(static_cast(i)); tiles_w[i] = (cols + tile_width - 1) / tile_width; tiles_h[i] = r; const UINT64 pitch = UINT64{tiles_w[i]} * 256; @@ -339,6 +339,19 @@ struct Gfx10Texture { total_slice_bytes = offset; } + // Extents for layout allocation and tile strides (AMD addrlib GetMipSize / ShiftCeil) + UINT extent_columns(UINT mip) const + { + const UINT cols0 = (width + block_dim - 1) / block_dim; + return (std::max)(1u, (cols0 + (1u << mip) - 1) >> mip); + } + UINT extent_rows(UINT mip) const + { + const UINT rows0 = (height + block_dim - 1) / block_dim; + return (std::max)(1u, (rows0 + (1u << mip) - 1) >> mip); + } + + // Subresource dimensions in elements for texel copying and bounds checking UINT columns(UINT mip) const { return ((std::max)(1u, width >> mip) + block_dim - 1) / block_dim; @@ -349,11 +362,11 @@ struct Gfx10Texture { } UINT tiles_wide(UINT mip) const { - return (mip < first_tail) ? tiles_w[mip] : (columns(mip) + tile_width - 1) / tile_width; + return (mip < first_tail) ? tiles_w[mip] : (extent_columns(mip) + tile_width - 1) / tile_width; } UINT tiles_high(UINT mip) const { - return (mip < first_tail) ? tiles_h[mip] : (rows(mip) + tile_height - 1) / tile_height; + return (mip < first_tail) ? tiles_h[mip] : (extent_rows(mip) + tile_height - 1) / tile_height; } UINT padded_columns(UINT mip) const { diff --git a/tests/startup_xg_gfx10_check.py b/tests/startup_xg_gfx10_check.py index 0271275a6d..bf50a3dce5 100644 --- a/tests/startup_xg_gfx10_check.py +++ b/tests/startup_xg_gfx10_check.py @@ -395,6 +395,11 @@ def test_pinned_addrlib_offsets(create): (0, 0, 0): 0x8000, (0, 1, 0): 0x8008, (0, 2, 0): 0x8020, (0, 4, 0): 0x8040, (0, 0, 1): 0x8010, (0, 0, 2): 0x8080, (0, 0, 4): 0x8100, }), + ("RGBA16 100x10 3-mip LINEAR", 10, 100, 10, 3, 0x100, 8, 1, { + (0, 0, 0): 3328, (0, 3, 2): 3328 + 2 * 1024 + 3 * 8, + (1, 0, 0): 768, (1, 3, 2): 768 + 2 * 512 + 3 * 8, + (2, 0, 0): 0, (2, 3, 1): 0 + 1 * 256 + 3 * 8, + }), # bpe=16 (_S, _D, and mip tail) ("RGBA32 32x32 3-mip 4KB_S", 2, 32, 32, 3, 0x105, 16, 1, { (0, 0, 0): 0x2000, (0, 1, 0): 0x2040, (0, 2, 0): 0x2080, (0, 4, 0): 0x2200, @@ -483,6 +488,7 @@ def main(dll_path): ("RGBA32 32x32 3-mip 4KB_S", 2, 32, 32, 3, 1, 0x105, 16, 1), ("RGBA8 64x64 1-mip LINEAR", 28, 64, 64, 1, 1, 0x100, 4, 1), ("RGBA8 256x256 3-mip LINEAR", 28, 256, 256, 3, 1, 0x100, 4, 1), + ("RGBA16 100x10 3-mip 2-slice LINEAR", 10, 100, 10, 3, 2, 0x100, 8, 1), ] for name, fmt, w, h, mips, slices, layout, bpe, bdim in cases: diff --git a/tests/xg_swizzle_select_check.cpp b/tests/xg_swizzle_select_check.cpp index e44c3a105b..1b1d96491f 100644 --- a/tests/xg_swizzle_select_check.cpp +++ b/tests/xg_swizzle_select_check.cpp @@ -579,6 +579,7 @@ int gfx10_tiling_reference() {"RGBA16 64x64 3m 64KB_D", DXGI_FORMAT_R16G16B16A16_FLOAT, ADDR_FMT_16_16_16_16, 64, 64, 64, 3, 1, 0x10A, ADDR_SW_64KB_D}, {"RGBA32 32x32 3m 4KB_S", DXGI_FORMAT_R32G32B32A32_FLOAT, ADDR_FMT_32_32_32_32, 128, 32, 32, 3, 1, 0x105, ADDR_SW_4KB_S}, {"RGBA8 64x64 3m LINEAR", DXGI_FORMAT_R8G8B8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 64, 64, 3, 1, 0x100, ADDR_SW_LINEAR}, + {"RGBA16 100x10 3m 2s LINEAR", DXGI_FORMAT_R16G16B16A16_FLOAT, ADDR_FMT_16_16_16_16, 64, 100, 10, 3, 2, 0x100, ADDR_SW_LINEAR}, }; for (const auto& c : cases) { From 389b810ec27b8a094c64fe5e2cdcb5030912ca90 Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Sun, 29 Nov 2026 18:52:04 +0500 Subject: [PATCH 6/9] tests: pin non-power-of-two tiled mip extents against addrlib Add BC7 81x69 4m 4KB_S and BC7 129x129 4m 4KB_S to the GFX10 addrlib oracle. The 81x69 shape alone does not discriminate: at 4 KB BC7 the tile is 16x16 blocks, so the ShiftCeil extents (11x9 at mip 1) and the rounded-down ones (10x9) still fit one tile. 129x129 crosses the tile boundary at mip 1 (17 vs 16 blocks), so reverting the tiled mip_start loop to columns/rows fails it: surf=61440 vs 49152. Verified against Mesa 25.1.0 addrlib (navi21); the mutation was applied locally, run, and reverted. Co-Authored-By: Claude Code --- tests/xg_swizzle_select_check.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/xg_swizzle_select_check.cpp b/tests/xg_swizzle_select_check.cpp index 1b1d96491f..42218814a0 100644 --- a/tests/xg_swizzle_select_check.cpp +++ b/tests/xg_swizzle_select_check.cpp @@ -566,6 +566,8 @@ int gfx10_tiling_reference() {"BC6H 256x256 4m 64KB_S", DXGI_FORMAT_BC6H_UF16, ADDR_FMT_BC6, 128, 256, 256, 4, 1, 0x109, ADDR_SW_64KB_S}, {"BC7 64x64 7m 4KB_S", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 64, 64, 7, 1, 0x105, ADDR_SW_4KB_S}, {"BC7 81x69 1m 4KB_D", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 81, 69, 1, 1, 0x106, ADDR_SW_4KB_D}, + {"BC7 81x69 4m 4KB_S", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 81, 69, 4, 1, 0x105, ADDR_SW_4KB_S}, + {"BC7 129x129 4m 4KB_S", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 129, 129, 4, 1, 0x105, ADDR_SW_4KB_S}, {"BC7 128x64 8m 4KB_S", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 128, 64, 8, 1, 0x105, ADDR_SW_4KB_S}, {"BC7 128x128 3m 2s 64KB_S", DXGI_FORMAT_BC7_UNORM, ADDR_FMT_BC7, 128, 128, 128, 3, 2, 0x109, ADDR_SW_64KB_S}, {"R8 64x64 1m 256B_S", DXGI_FORMAT_R8_UNORM, ADDR_FMT_8, 8, 64, 64, 1, 1, 0x101, ADDR_SW_256B_S}, From ae9a7e44625a514882df82af8f4e275d5116c1c2 Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:27:39 +0500 Subject: [PATCH 7/9] docs: point the XG layout sections at the general Gfx10Texture computer The nine-mip BC5/BC7 section reads as if XG slots 2/3/6/8/9/10 handled layout 0x109 only. Note the general computer in the next section and keep the pins specific to the earlier shape. In startup-runtime.md, name the scope of Gfx10Texture after #1469 instead of describing it as future work. Co-Authored-By: Claude Code --- docs/experiments.md | 2 ++ docs/startup-runtime.md | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 348487b866..c696ed73f2 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16789,6 +16789,8 @@ ctest --preset release --no-tests=error --output-on-failure -R '^startup_(placem ### Nine-mip BC5/BC7 tile queries +The general GFX10 texture computer described in the next section now answers XG slots 2, 3, 6, 8, 9 and 10 for the explicit layouts `0x100`–`0x10a`. The pins below stay specific to the earlier nine-mip `0x109` BC5/BC7 shape. + XG texture-computer slot 10 reports a 64 KiB standard tile layout for 1024×512 and 1024×1024 single-sample BC5_UNORM and BC7_UNORM textures with nine mips, one or two array slices, explicit layout `0x109`, default alignment and zero flags. Each slice starts with one packed tile containing six mips. The 1024×512 standard mips start at tiles 4, 2 and 1 in a 12-tile slice. The 1024×1024 standard mips start at tiles 6, 2 and 1 in a 22-tile slice. `ctest --preset dev --no-tests=error -R '^startup_bc64_supports(_layout_control)?$' -V` checks which descriptions `src/startup_stubs/bc64_chain.h` routes to this layout, without a device or AddrLib: the two six-mip and eight nine-mip shapes are accepted, and 16 descriptions that each change one field, among them layout `UNKNOWN`, 64 KiB alignment, a render-target flag, `BC7_UNORM_SRGB` and six mips with two slices, are rejected. The control expects layout `UNKNOWN` to be accepted and must fail. `startup_xg_bc_tiling` checks 80 subresource queries, including a request spanning the last packed mip in one slice and the first standard mips of the next. The returned count includes only standard mips. Their entries use their original positions in the requested range. Sentinel bytes cover packed entries and the remainder of the caller's array. The field values were compared with XCL's slot 10 implementation on source-built inputs. The optional AMD AddrLib test independently verifies the surface size, slice stride, first packed mip and standard and packed macro-tile offsets for all eight shapes and formats. [XCL implementation](https://github.com/ivall/xcl/blob/64b3f35599bb7102f55d640e1a791e7d6dd3b175/crates/xcl/src/hle/xg.rs#L610-L658) · [AMD AddrLib revision](https://gitlab.freedesktop.org/mesa/mesa/-/tree/5c142e46f3f6e752ed745fd48912ebb8fad67145/src/amd/addrlib) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 040ae3e4b2..393b89d2a6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3688,9 +3688,10 @@ In the plan, every row has its exact byte width (a row of texels, or of 4 x 4 bl follow each other from the top level with no padding. Its size never exceeds the answer: `startup_small_texture_4k` checks this for every accepted shape. The texels are linear, not the console's 4 KiB swizzle. Data the executable streams in its own 4 KiB layout is therefore read in the wrong order, -as it already was with the desktop layout. A GFX10 4 KiB tiling plan, such as `Gfx10Texture` in #1469, -can replace the compact plan in all three calls at once. At alignment 0 nothing changes: the desktop -answer and the desktop footprint. +as it already was with the desktop layout. `Gfx10Texture` (#1469) tiles the explicit GFX10 layouts, not +this UNKNOWN-and-4096-alignment path; using it here would replace the compact plan in all three calls +at once and is left to a follow-up. At alignment 0 nothing changes: the desktop answer and the desktop +footprint. Measured on one console executable under the startup debugger: 18 such reads failed during first-run setup in every run, each with the executable's check firing once. With this answer both From d923452e90c084dff425baf5900c7374bb1ac2ea Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Wed, 2 Dec 2026 03:00:47 +0500 Subject: [PATCH 8/9] Align 4-byte _D swizzle with gfx10_layout.h and clarify supported modes --- docs/experiments.md | 2 +- src/startup_stubs/gfx10_texture.h | 2 +- src/startup_stubs/xg_xs.cpp | 2 +- tests/startup_xg_gfx10_check.py | 4 ++-- tests/xg_swizzle_select_check.cpp | 4 +++- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index c696ed73f2..f2dcd6b57c 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16789,7 +16789,7 @@ ctest --preset release --no-tests=error --output-on-failure -R '^startup_(placem ### Nine-mip BC5/BC7 tile queries -The general GFX10 texture computer described in the next section now answers XG slots 2, 3, 6, 8, 9 and 10 for the explicit layouts `0x100`–`0x10a`. The pins below stay specific to the earlier nine-mip `0x109` BC5/BC7 shape. +The general GFX10 texture computer described in the next section now answers XG slots 2, 3, 6, 8, 9 and 10 for the explicit layouts `0x100, 0x101, 0x102, 0x105, 0x106, 0x109, 0x10a` (S, D, and linear modes). The pins below stay specific to the earlier nine-mip `0x109` BC5/BC7 shape. XG texture-computer slot 10 reports a 64 KiB standard tile layout for 1024×512 and 1024×1024 single-sample BC5_UNORM and BC7_UNORM textures with nine mips, one or two array slices, explicit layout `0x109`, default alignment and zero flags. Each slice starts with one packed tile containing six mips. The 1024×512 standard mips start at tiles 4, 2 and 1 in a 12-tile slice. The 1024×1024 standard mips start at tiles 6, 2 and 1 in a 22-tile slice. `ctest --preset dev --no-tests=error -R '^startup_bc64_supports(_layout_control)?$' -V` checks which descriptions `src/startup_stubs/bc64_chain.h` routes to this layout, without a device or AddrLib: the two six-mip and eight nine-mip shapes are accepted, and 16 descriptions that each change one field, among them layout `UNKNOWN`, 64 KiB alignment, a render-target flag, `BC7_UNORM_SRGB` and six mips with two slices, are rejected. The control expects layout `UNKNOWN` to be accepted and must fail. diff --git a/src/startup_stubs/gfx10_texture.h b/src/startup_stubs/gfx10_texture.h index a49447b74c..c284e09099 100644 --- a/src/startup_stubs/gfx10_texture.h +++ b/src/startup_stubs/gfx10_texture.h @@ -231,7 +231,7 @@ struct Gfx10Texture { static const char* const PATTERN_D[5] = { "x0x1x2y1y0y2x3y3", "--x0x1x2y0y1y2x3", - "----x0x1y0y1x2y2", + "----x0x1y0y1y2x2", // Matches main's gfx10_layout.h working hypothesis; GFX10.3 RbPlus x2y2 will be applied to both files together once confirmed by maintainer "------x0y0x1x2y1", "--------x0y0x1y1" }; diff --git a/src/startup_stubs/xg_xs.cpp b/src/startup_stubs/xg_xs.cpp index 61a0556b9f..43eceb119a 100644 --- a/src/startup_stubs/xg_xs.cpp +++ b/src/startup_stubs/xg_xs.cpp @@ -491,7 +491,7 @@ extern "C" __declspec(noinline) long XGCreateTextureComputer(u64 rcx, u64 rdx, u return slots; }(); const bool bc7_4k = use_bc7_4k_s_layout(desc); - // The 4 KiB profile requires UNKNOWN layout and one mip. Gfx10Texture requires explicit 0x100..0x10a layout. + // The 4 KiB profile requires UNKNOWN layout and one mip. Gfx10Texture requires explicit 0x100, 0x101, 0x102, 0x105, 0x106, 0x109, 0x10a (S, D, and linear modes) layout. const auto* slots = x2w_startup::Gfx10Texture::supports(desc) ? bc_table.data() : table.data(); if (bc7_4k) slots = bc7_4k_table.data(); auto* computer = new Computer{slots, desc, 1, bc7_4k}; diff --git a/tests/startup_xg_gfx10_check.py b/tests/startup_xg_gfx10_check.py index bf50a3dce5..6182db6dae 100644 --- a/tests/startup_xg_gfx10_check.py +++ b/tests/startup_xg_gfx10_check.py @@ -382,8 +382,8 @@ def test_pinned_addrlib_offsets(create): (0, 0, 1): 0x10010, (0, 0, 2): 0x10020, (0, 0, 4): 0x10040, (0, 0, 8): 0x10100, }), ("R32 64x64 3-mip 256B_D", 41, 64, 64, 3, 0x102, 4, 1, { - (0, 0, 0): 0x1400, (0, 1, 0): 0x1404, (0, 2, 0): 0x1408, (0, 4, 0): 0x1440, - (0, 0, 1): 0x1410, (0, 0, 2): 0x1420, (0, 0, 4): 0x1480, + (0, 0, 0): 0x1400, (0, 1, 0): 0x1404, (0, 2, 0): 0x1408, (0, 4, 0): 0x1480, + (0, 0, 1): 0x1410, (0, 0, 2): 0x1420, (0, 0, 4): 0x1440, }), # bpe=8 (_S and _D) ("BC1 256x256 5-mip 64KB_S", 71, 256, 256, 5, 0x109, 8, 4, { diff --git a/tests/xg_swizzle_select_check.cpp b/tests/xg_swizzle_select_check.cpp index 42218814a0..212578d726 100644 --- a/tests/xg_swizzle_select_check.cpp +++ b/tests/xg_swizzle_select_check.cpp @@ -575,7 +575,9 @@ int gfx10_tiling_reference() {"R8 128x128 4m 64KB_S", DXGI_FORMAT_R8_UNORM, ADDR_FMT_8, 8, 128, 128, 4, 1, 0x109, ADDR_SW_64KB_S}, {"RG8 64x64 3m 4KB_D", DXGI_FORMAT_R8G8_UNORM, ADDR_FMT_8_8, 16, 64, 64, 3, 1, 0x106, ADDR_SW_4KB_D}, {"R16 64x64 3m 4KB_S", DXGI_FORMAT_R16_FLOAT, ADDR_FMT_16, 16, 64, 64, 3, 1, 0x105, ADDR_SW_4KB_S}, - {"R32 64x64 1m 256B_D", DXGI_FORMAT_R32_FLOAT, ADDR_FMT_32, 32, 64, 64, 1, 1, 0x102, ADDR_SW_256B_D}, + // 4-byte _D currently follows main's gfx10_layout.h working hypothesis (y2x2, pinned in startup_xg_gfx10_check.py); + // re-enable AddrLib comparison once GFX10.3 RbPlus x2y2 is confirmed for both files. + // {"R32 64x64 1m 256B_D", DXGI_FORMAT_R32_FLOAT, ADDR_FMT_32, 32, 64, 64, 1, 1, 0x102, ADDR_SW_256B_D}, {"RGBA8 128x128 4m 64KB_S", DXGI_FORMAT_R8G8B8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 128, 128, 4, 1, 0x109, ADDR_SW_64KB_S}, {"BGRA8 64x64 3m 4KB_S", DXGI_FORMAT_B8G8R8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 64, 64, 3, 1, 0x105, ADDR_SW_4KB_S}, {"RGBA16 64x64 3m 64KB_D", DXGI_FORMAT_R16G16B16A16_FLOAT, ADDR_FMT_16_16_16_16, 64, 64, 64, 3, 1, 0x10A, ADDR_SW_64KB_D}, From 14fa93f22cf9925781f485943400ec11e99c4e4f Mon Sep 17 00:00:00 2001 From: Rachel Amber <77208679+Holastor@users.noreply.github.com> Date: Wed, 2 Dec 2026 03:05:51 +0500 Subject: [PATCH 9/9] gfx10: align 4-byte display swizzle row with GFX10.3 RbPlus (x2y2) --- docs/experiments.md | 2 +- docs/startup-runtime.md | 2 +- src/startup_stubs/gfx10_layout.h | 2 +- src/startup_stubs/gfx10_texture.h | 2 +- tests/startup_gfx10_layout_check.cpp | 6 +++--- tests/startup_xg_gfx10_check.py | 4 ++-- tests/xg_swizzle_select_check.cpp | 4 +--- 7 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index f2dcd6b57c..4a3e1e5c22 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16814,7 +16814,7 @@ ctest --preset release --no-tests=error --output-on-failure -R '^(startup_xg_bc_ `Gfx10Texture` (`src/startup_stubs/gfx10_texture.h`) implements the runtime tiling and detiling computer for GFX10 textures across 256 B, 4 KiB, and 64 KiB blocks in standard (`_S`) and display (`_D`) modes (explicit layouts `0x101`, `0x102`, `0x105`, `0x106`, `0x109`, `0x10a`), as well as multi-mip and multi-slice linear layout `0x100` (packed slices, smallest mip first). It supports 1-, 2-, 4-, 8-, and 16-byte elements (including BC1 to BC7 block-compressed formats): - XG texture-computer stand-in (`src/startup_stubs/xg_xs.cpp`) provides slot 2 (layout query, mip starts, alignment), slot 3 (total allocation size), slot 6 (element coordinate offset query), slot 8 (`CopyIntoSubresource` for linear to tiled upload), and slot 9 (`CopyFromSubresource` for tiled to linear readback). -- In AMD AddrLib (`src/amd/addrlib`) configured for GFX10.3 / RDNA2 (Navi21 reference with `supportRbPlus = 1`), `GetSwizzlePatternInfo` selects `GFX10_SW_256_D_RBPLUS_PATINFO` (pattern index 39: `"----x0x1y0y1x2y2"`), where bit 6 is $x_2$ and bit 7 is $y_2$, while Navi1x without RbPlus selects pattern 2 (`"----x0x1y0y1y2x2"`). Whether console hardware matches the RbPlus pattern remains an open hypothesis pending independent hardware measurement. +- In AMD AddrLib (`src/amd/addrlib`) configured for GFX10.3 / RDNA2 (Navi21 reference with `supportRbPlus = 1`), `GetSwizzlePatternInfo` selects `GFX10_SW_256_D_RBPLUS_PATINFO` (pattern index 39: `"----x0x1y0y1x2y2"`), where bit 6 is $x_2$ and bit 7 is $y_2$, while Navi1x without RbPlus selects pattern 2 (`"----x0x1y0y1y2x2"`). Both `src/startup_stubs/gfx10_texture.h` and `src/startup_stubs/gfx10_layout.h` use the GFX10.3 RbPlus `----x0x1y0y1x2y2` 4-byte display row (which therefore differs from the 4-byte standard row `y2x2`). - The desktop draw uploader (`src/startup_stubs/d3d12_draw.inl`) detiles placed CPU textures via `is_gfx10_tiled` for all explicit GFX10 tiled modes and multi-mip or array linear (0x100) textures into desktop D3D12 copyable footprints on upload. - `xg_gfx10_tiling_reference` independently compares `Gfx10Texture` against Mesa 25.1.0 AMD AddrLib on Navi21 for 23 surface shapes, validating surface sizes, slice strides, base alignments, mip offsets, and coordinate addresses with 0 mismatches. - `startup_xg_gfx10_runtime` tests layout queries, slot-6 coordinate offsets, slot-8 tiling, slot-9 detiling, pinned AddrLib offsets across all five element sizes, implicit layout routing, and negative controls. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 393b89d2a6..e61dc78cb6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -3954,7 +3954,7 @@ Limits and choices that are not measured against a console: are compared with another implementation in the tree (`bc7_4k_s.h`, `bc64_chain.h`); `tile64_plan.h` checks the `0x10a` mip starts and tail, not the bit order. The display (`_D`) rows in `gfx10_layout.h` that differ from the standard ones (1-, 8- and 16-byte elements; the 2- - and 4-byte display rows equal the standard rows) and the standard rows for 1-, 2-, 4- and 8-byte + and 2-byte display rows equal the standard rows; the 4-byte display row uses GFX10.3 RbPlus `----x0x1y0y1x2y2` and differs from the 4-byte standard row `y2x2`) and the standard rows for 1-, 2-, 4- and 8-byte elements are checked only against the addrlib pattern rows restated from the addrlib source text in `startup_gfx10_layout_check.cpp` (all five element sizes) and in the Python oracle of `startup_address_console_check.py` (4- and 8-byte elements), both written from the same source. diff --git a/src/startup_stubs/gfx10_layout.h b/src/startup_stubs/gfx10_layout.h index 38cf1a2f40..047a167631 100644 --- a/src/startup_stubs/gfx10_layout.h +++ b/src/startup_stubs/gfx10_layout.h @@ -163,7 +163,7 @@ struct Layout { static constexpr const char* standard[5] = { "x0x1x2x3y0y1y2y3", "--x0x1x2y0y1y2x3", "----x0x1y0y1y2x2", "------x0y0y1x1x2", "--------y0y1x0x1"}; static constexpr const char* display[5] = { - "x0x1x2y1y0y2x3y3", "--x0x1x2y0y1y2x3", "----x0x1y0y1y2x2", "------x0y0x1x2y1", "--------x0y0x1y1"}; + "x0x1x2y1y0y2x3y3", "--x0x1x2y0y1y2x3", "----x0x1y0y1x2y2", "------x0y0x1x2y1", "--------x0y0x1y1"}; static constexpr UINT micro[5][2] = {{16, 16}, {16, 8}, {8, 8}, {8, 4}, {4, 4}}; const bool is_display = mode == 2 || mode == 6 || mode == 10; const char* pattern = (is_display ? display : standard)[element_log2]; diff --git a/src/startup_stubs/gfx10_texture.h b/src/startup_stubs/gfx10_texture.h index c284e09099..bbf3287e4e 100644 --- a/src/startup_stubs/gfx10_texture.h +++ b/src/startup_stubs/gfx10_texture.h @@ -231,7 +231,7 @@ struct Gfx10Texture { static const char* const PATTERN_D[5] = { "x0x1x2y1y0y2x3y3", "--x0x1x2y0y1y2x3", - "----x0x1y0y1y2x2", // Matches main's gfx10_layout.h working hypothesis; GFX10.3 RbPlus x2y2 will be applied to both files together once confirmed by maintainer + "----x0x1y0y1x2y2", // GFX10.3 / RDNA2 RbPlus "------x0y0x1x2y1", "--------x0y0x1y1" }; diff --git a/tests/startup_gfx10_layout_check.cpp b/tests/startup_gfx10_layout_check.cpp index 4ea0f8d657..178fcc4279 100644 --- a/tests/startup_gfx10_layout_check.cpp +++ b/tests/startup_gfx10_layout_check.cpp @@ -68,17 +68,17 @@ struct Equation { const Equation equations[] = { {0x101, {"X0 X1 X2 X3 Y0 Y1 Y2 Y3", "0 X0 X1 X2 Y0 Y1 Y2 X3", "0 0 X0 X1 Y0 Y1 Y2 X2", "0 0 0 X0 Y0 Y1 X1 X2", "0 0 0 0 Y0 Y1 X0 X1"}}, - {0x102, {"X0 X1 X2 Y1 Y0 Y2 X3 Y3", "0 X0 X1 X2 Y0 Y1 Y2 X3", "0 0 X0 X1 Y0 Y1 Y2 X2", "0 0 0 X0 Y0 X1 X2 Y1", + {0x102, {"X0 X1 X2 Y1 Y0 Y2 X3 Y3", "0 X0 X1 X2 Y0 Y1 Y2 X3", "0 0 X0 X1 Y0 Y1 X2 Y2", "0 0 0 X0 Y0 X1 X2 Y1", "0 0 0 0 X0 Y0 X1 Y1"}}, {0x105, {"X0 X1 X2 X3 Y0 Y1 Y2 Y3 Y4 X4 Y5 X5", "0 X0 X1 X2 Y0 Y1 Y2 X3 Y3 X4 Y4 X5", "0 0 X0 X1 Y0 Y1 Y2 X2 Y3 X3 Y4 X4", "0 0 0 X0 Y0 Y1 X1 X2 Y2 X3 Y3 X4", "0 0 0 0 Y0 Y1 X0 X1 Y2 X2 Y3 X3"}}, {0x106, {"X0 X1 X2 Y1 Y0 Y2 X3 Y3 Y4 X4 Y5 X5", "0 X0 X1 X2 Y0 Y1 Y2 X3 Y3 X4 Y4 X5", - "0 0 X0 X1 Y0 Y1 Y2 X2 Y3 X3 Y4 X4", "0 0 0 X0 Y0 X1 X2 Y1 Y2 X3 Y3 X4", "0 0 0 0 X0 Y0 X1 Y1 Y2 X2 Y3 X3"}}, + "0 0 X0 X1 Y0 Y1 X2 Y2 Y3 X3 Y4 X4", "0 0 0 X0 Y0 X1 X2 Y1 Y2 X3 Y3 X4", "0 0 0 0 X0 Y0 X1 Y1 Y2 X2 Y3 X3"}}, {0x109, {"X0 X1 X2 X3 Y0 Y1 Y2 Y3 Y4 X4 Y5 X5 Y6 X6 Y7 X7", "0 X0 X1 X2 Y0 Y1 Y2 X3 Y3 X4 Y4 X5 Y5 X6 Y6 X7", "0 0 X0 X1 Y0 Y1 Y2 X2 Y3 X3 Y4 X4 Y5 X5 Y6 X6", "0 0 0 X0 Y0 Y1 X1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 X6", "0 0 0 0 Y0 Y1 X0 X1 Y2 X2 Y3 X3 Y4 X4 Y5 X5"}}, {0x10a, {"X0 X1 X2 Y1 Y0 Y2 X3 Y3 Y4 X4 Y5 X5 Y6 X6 Y7 X7", "0 X0 X1 X2 Y0 Y1 Y2 X3 Y3 X4 Y4 X5 Y5 X6 Y6 X7", - "0 0 X0 X1 Y0 Y1 Y2 X2 Y3 X3 Y4 X4 Y5 X5 Y6 X6", "0 0 0 X0 Y0 X1 X2 Y1 Y2 X3 Y3 X4 Y4 X5 Y5 X6", + "0 0 X0 X1 Y0 Y1 X2 Y2 Y3 X3 Y4 X4 Y5 X5 Y6 X6", "0 0 0 X0 Y0 X1 X2 Y1 Y2 X3 Y3 X4 Y4 X5 Y5 X6", "0 0 0 0 X0 Y0 X1 Y1 Y2 X2 Y3 X3 Y4 X4 Y5 X5"}}, }; diff --git a/tests/startup_xg_gfx10_check.py b/tests/startup_xg_gfx10_check.py index 6182db6dae..bf50a3dce5 100644 --- a/tests/startup_xg_gfx10_check.py +++ b/tests/startup_xg_gfx10_check.py @@ -382,8 +382,8 @@ def test_pinned_addrlib_offsets(create): (0, 0, 1): 0x10010, (0, 0, 2): 0x10020, (0, 0, 4): 0x10040, (0, 0, 8): 0x10100, }), ("R32 64x64 3-mip 256B_D", 41, 64, 64, 3, 0x102, 4, 1, { - (0, 0, 0): 0x1400, (0, 1, 0): 0x1404, (0, 2, 0): 0x1408, (0, 4, 0): 0x1480, - (0, 0, 1): 0x1410, (0, 0, 2): 0x1420, (0, 0, 4): 0x1440, + (0, 0, 0): 0x1400, (0, 1, 0): 0x1404, (0, 2, 0): 0x1408, (0, 4, 0): 0x1440, + (0, 0, 1): 0x1410, (0, 0, 2): 0x1420, (0, 0, 4): 0x1480, }), # bpe=8 (_S and _D) ("BC1 256x256 5-mip 64KB_S", 71, 256, 256, 5, 0x109, 8, 4, { diff --git a/tests/xg_swizzle_select_check.cpp b/tests/xg_swizzle_select_check.cpp index 212578d726..42218814a0 100644 --- a/tests/xg_swizzle_select_check.cpp +++ b/tests/xg_swizzle_select_check.cpp @@ -575,9 +575,7 @@ int gfx10_tiling_reference() {"R8 128x128 4m 64KB_S", DXGI_FORMAT_R8_UNORM, ADDR_FMT_8, 8, 128, 128, 4, 1, 0x109, ADDR_SW_64KB_S}, {"RG8 64x64 3m 4KB_D", DXGI_FORMAT_R8G8_UNORM, ADDR_FMT_8_8, 16, 64, 64, 3, 1, 0x106, ADDR_SW_4KB_D}, {"R16 64x64 3m 4KB_S", DXGI_FORMAT_R16_FLOAT, ADDR_FMT_16, 16, 64, 64, 3, 1, 0x105, ADDR_SW_4KB_S}, - // 4-byte _D currently follows main's gfx10_layout.h working hypothesis (y2x2, pinned in startup_xg_gfx10_check.py); - // re-enable AddrLib comparison once GFX10.3 RbPlus x2y2 is confirmed for both files. - // {"R32 64x64 1m 256B_D", DXGI_FORMAT_R32_FLOAT, ADDR_FMT_32, 32, 64, 64, 1, 1, 0x102, ADDR_SW_256B_D}, + {"R32 64x64 1m 256B_D", DXGI_FORMAT_R32_FLOAT, ADDR_FMT_32, 32, 64, 64, 1, 1, 0x102, ADDR_SW_256B_D}, {"RGBA8 128x128 4m 64KB_S", DXGI_FORMAT_R8G8B8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 128, 128, 4, 1, 0x109, ADDR_SW_64KB_S}, {"BGRA8 64x64 3m 4KB_S", DXGI_FORMAT_B8G8R8A8_UNORM, ADDR_FMT_8_8_8_8, 32, 64, 64, 3, 1, 0x105, ADDR_SW_4KB_S}, {"RGBA16 64x64 3m 64KB_D", DXGI_FORMAT_R16G16B16A16_FLOAT, ADDR_FMT_16_16_16_16, 64, 64, 64, 3, 1, 0x10A, ADDR_SW_64KB_D},