// Tests for console descriptor heap T# binding rules and per-reason refusal tracking (RT-UNBOUND-TSHARP-REASONS). // Verifies: // 1. 1D rule: dimension and layer count compatibility ("T# type or samples do not fit the texture"). // 2. Array rule: layer range bounds ("T# names layers the texture lacks"). // 3. Cube rule: minimum layer requirement ("cube T# on fewer than six layers"). // 4. MSAA rule: sample count matching ("T# type or samples do not fit the texture"). // 5. Unbound T# reason tracking: distinct slots and total refusal counts tracked per reason. #include "../shims/d3d12_com.h" #include "../shims/d3d12_xs_device.h" #include "../src/gfx10_descriptors.h" #include #include #include #include namespace { int g_checks = 0; int g_failures = 0; void check(bool condition, const char* what) { ++g_checks; if (!condition) { ++g_failures; std::fprintf(stderr, "FAIL: %s\n", what); } } template struct Ref { T* p = nullptr; ~Ref() { if (p) p->Release(); } T** put() { if (p) { p->Release(); p = nullptr; } return &p; } T* operator->() const { return p; } }; } // namespace int main() { namespace g = leonida::gfx10; // Test 1: Unbound T# statistics and per-reason tracking { rt::d3d12::reset_unbound_tsharp_stats(); std::array dummy_words{}; const char* reason_type = "T# type or samples do not fit the texture"; const char* reason_layers = "T# names layers the texture lacks"; // Slot 0x00 refused for type rt::d3d12::note_refused_tsharp_for_test(0x10000, 0x00, dummy_words, reason_type); // Slot 0x20 refused for type rt::d3d12::note_refused_tsharp_for_test(0x10000, 0x20, dummy_words, reason_type); // Slot 0x00 refused again for type (repeated scan) rt::d3d12::note_refused_tsharp_for_test(0x10000, 0x00, dummy_words, reason_type); // Slot 0x40 refused for layers rt::d3d12::note_refused_tsharp_for_test(0x10000, 0x40, dummy_words, reason_layers); const auto stats = rt::d3d12::unbound_tsharp_stats(); check(stats.total_distinct_slots == 3, "total distinct slots is 3"); check(stats.total_refusals == 4, "total refusals is 4"); const auto it_type = stats.by_reason.find(reason_type); check(it_type != stats.by_reason.end(), "reason_type recorded in stats"); if (it_type != stats.by_reason.end()) { check(it_type->second.distinct_slots == 2, "type reason distinct slots is 2"); check(it_type->second.total_refusals == 3, "type reason total refusals is 3"); } const auto it_layers = stats.by_reason.find(reason_layers); check(it_layers != stats.by_reason.end(), "reason_layers recorded in stats"); if (it_layers != stats.by_reason.end()) { check(it_layers->second.distinct_slots == 1, "layers reason distinct slots is 1"); check(it_layers->second.total_refusals == 1, "layers reason total refusals is 1"); } } // Initialize standalone Vulkan D3D12 device for resource binding rule tests Ref device; if (FAILED(rt::d3d12::create_vulkan_device_standalone(IID_PPV_ARGS(device.put())))) { std::puts("SKIP: no Vulkan D3D12 device"); return 77; } const D3D12_HEAP_PROPERTIES heap_props{ .Type = D3D12_HEAP_TYPE_DEFAULT, .CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN, .MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN, .CreationNodeMask = 1, .VisibleNodeMask = 1, }; // Test 2: 1D Texture binding rules { D3D12_RESOURCE_DESC desc{}; desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE1D; desc.Width = 64; desc.Height = 1; desc.DepthOrArraySize = 1; desc.MipLevels = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; Ref res_1d; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_1d.put()))), "created 1D texture"); const std::uint64_t addr = rt::d3d12::resource_image_address(res_1d.p); check(addr != 0, "1D texture has registered image address"); // Case 2a: T# specifies 2D type for a 1D texture -> refuse type_fits { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 1; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "2D T# on 1D texture refused"); check(why && std::string(why) == "T# type or samples do not fit the texture", "2D T# on 1D texture explains type mismatch"); } // Case 2b: 1D_ARRAY T# with layer_count > 1 on 1-layer 1D texture -> refused with layer mismatch // (Non-array image_1d decodes first_layer=0, layer_count=1 regardless of WORD4 metadata.) { g::Image img{}; img.address = addr; img.type = g::ImageType::image_1d_array; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 1; img.layer_count = 2; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "1D_ARRAY T# with layer_count > 1 on 1D texture refused"); check(why && std::string(why) == "T# names layers the texture lacks", "1D_ARRAY T# with layer_count > 1 explains layer mismatch"); } // Case 2c: T# specifies 1D type and layer_count == 1 -> bound { g::Image img{}; img.address = addr; img.type = g::ImageType::image_1d; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 1; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "matching 1D T# bound successfully"); } } // Test 3: 2D Array and Cube binding rules { D3D12_RESOURCE_DESC desc{}; desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; desc.Width = 64; desc.Height = 64; desc.DepthOrArraySize = 4; // 4 layers desc.MipLevels = 2; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; Ref res_array; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_array.put()))), "created 2D array texture"); const std::uint64_t addr = rt::d3d12::resource_image_address(res_array.p); check(addr != 0, "2D array texture has registered image address"); // Case 3a: T# names layers the texture lacks (first_layer + layer_count > 4) -> refuse layers { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d_array; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.first_layer = 2; img.layer_count = 3; // 2 + 3 = 5 > 4 img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "T# with excessive layers refused"); check(why && std::string(why) == "T# names layers the texture lacks", "excessive layers explains layers mismatch"); } // Case 3b: Cube T# on texture with fewer than six layers (desc.DepthOrArraySize = 4 < 6) -> refuse cube { g::Image img{}; img.address = addr; img.type = g::ImageType::cube; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.first_layer = 0; img.layer_count = 6; // cube needs at least 6 faces, but texture only has 4 layers img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "cube T# on 4 layers refused"); check(why && std::string(why) == "cube T# on fewer than six layers", "cube T# explains fewer than six layers"); } // Case 3c: T# names valid sub-array (first_layer = 1, layer_count = 2 <= 4) -> bound { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d_array; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.first_layer = 1; img.layer_count = 2; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "valid sub-array T# bound successfully"); } // Case 3d: T# names mips the texture lacks (first_mip + mip_count > 2) -> refuse mips { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d_array; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.first_layer = 0; img.layer_count = 1; img.first_mip = 1; img.mip_count = 2; // 1 + 2 = 3 > 2 const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "T# with excessive mips refused"); check(why && std::string(why) == "T# names mips the texture lacks", "excessive mips explains mips mismatch"); } } // Test 4: MSAA Texture binding rules { D3D12_RESOURCE_DESC desc{}; desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; desc.Width = 64; desc.Height = 64; desc.DepthOrArraySize = 1; desc.MipLevels = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 4; // 4x MSAA desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN; Ref res_msaa; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_msaa.put()))), "created 4x MSAA texture"); const std::uint64_t addr = rt::d3d12::resource_image_address(res_msaa.p); check(addr != 0, "MSAA texture has registered image address"); // Case 4a: Non-MSAA T# on MSAA texture -> refuse type_fits { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "non-MSAA T# on MSAA texture refused"); check(why && std::string(why) == "T# type or samples do not fit the texture", "non-MSAA T# explains type or samples mismatch"); } // Case 4b: MSAA T# with mismatched samples (samples = 2 != 4) -> refuse type_fits { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d_msaa; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.samples = 2; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::refused, "mismatched samples T# refused"); check(why && std::string(why) == "T# type or samples do not fit the texture", "mismatched samples explains type or samples mismatch"); } // Case 4c: Matching 4x MSAA T# -> bound { g::Image img{}; img.address = addr; img.type = g::ImageType::image_2d_msaa; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.samples = 4; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "matching 4x MSAA T# bound successfully"); } } // Test 5: Unknown texture address and invalid T# words { // Unknown address { g::Image img{}; img.address = 0xdeadbeef00ull; img.type = g::ImageType::image_2d; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 64; img.height = 64; img.layer_count = 1; img.mip_count = 1; const auto words = g::encode(img); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::unknown, "unknown address returns TitleImage::unknown"); check(why && std::string(why) == "no texture at the T# address: no title memory and no texture of ours", "unknown address explains no texture at the T# address, and what the address is"); } // The classes of an address with no texture: one of ours that is gone, and one whose low 32 bits name one of // ours (of the T#'s shape, of another, or gone) with other high bits. { D3D12_RESOURCE_DESC desc{}; desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; desc.Width = 16; desc.Height = 4; desc.DepthOrArraySize = 1; desc.MipLevels = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; Ref texture; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(texture.put()))), "created a 16x4 texture"); const std::uint64_t addr = rt::d3d12::resource_image_address(texture.p); check(addr >> 32 == 1, "the layer's texture addresses start at 1 << 32"); g::Image img{}; img.address = 0x7f0000000000ull | (addr & 0xffffffffull); img.type = g::ImageType::image_2d; img.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); img.width = 16; img.height = 4; img.layer_count = 1; img.mip_count = 1; const auto reason = [&](const g::Image& image) { const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, g::encode(image), &why); return result == rt::d3d12::TitleImage::unknown && why ? std::string(why) : std::string("?"); }; // The title's 32-bit form of the texture's address (bits 32-39 clear, 0x7f above) with the texture's shape // binds it (tsharp_texture_key); another shape does not. { const char* why = nullptr; check(rt::d3d12::test_bind_title_image(device.p, g::encode(img), &why) == rt::d3d12::TitleImage::bound, "other high bits, same shape: bound to the texture with those low 32 bits"); } g::Image other = img; other.width = 32; check(reason(other) == "no texture at the T# address: its low 32 bits name a texture of ours of another shape", "other high bits, another shape"); texture.put(); // released: its address leaves the device's table check(reason(img) == "no texture at the T# address: its low 32 bits name a texture of ours that is gone", "other high bits, texture gone"); g::Image gone = img; gone.address = addr; check(reason(gone) == "no texture at the T# address: a texture of ours that is gone", "the address of a texture of ours that is gone"); } // Not a valid T# (decode failure) { std::array raw_words{0x1, 0x2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0}; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, raw_words, &why); check(result == rt::d3d12::TitleImage::not_tsharp, "invalid words return TitleImage::not_tsharp"); check(why && std::string(why) == "not a valid T# (swizzle, levels or layers)", "invalid words explains not a valid T#"); } } // Test 6 (Fix T3): WORD4 reserved bits (0x6000C000u), GFX10_FORMAT_INVALID (fmt == 0), and 3D UAV slice check { D3D12_RESOURCE_DESC desc2d{}; desc2d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; desc2d.Width = 32; desc2d.Height = 32; desc2d.DepthOrArraySize = 1; desc2d.MipLevels = 1; desc2d.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc2d.SampleDesc.Count = 1; Ref res_2d; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc2d, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_2d.put()))), "created 2D texture for T3 tests"); const std::uint64_t addr2d = rt::d3d12::resource_image_address(res_2d.p); g::Image base2d{}; base2d.address = addr2d; base2d.type = g::ImageType::image_2d; base2d.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); base2d.width = 32; base2d.height = 32; base2d.layer_count = 1; base2d.mip_count = 1; // Reserved WORD4 bits [30:29] and [15:14] must be rejected as not_tsharp before owner lookup. for (const std::uint32_t bit : {0x40000000u, 0x20000000u, 0x00008000u, 0x00004000u}) { auto words = g::encode(base2d); words[4] |= bit; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::not_tsharp, "WORD4 reserved bit rejected as not_tsharp"); } // format == 0 (GFX10_FORMAT_INVALID) must be rejected as not_tsharp (never refused or bound onto depth). { g::Image fmt0 = base2d; fmt0.format = 0; const auto words = g::encode(fmt0); const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::not_tsharp, "format==0 on color texture rejected as not_tsharp"); } { D3D12_RESOURCE_DESC dsv_desc = desc2d; dsv_desc.Format = DXGI_FORMAT_R32G8X24_TYPELESS; dsv_desc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; Ref res_depth; if (SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &dsv_desc, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_depth.put())))) { g::Image fmt0_depth = base2d; fmt0_depth.address = rt::d3d12::resource_image_address(res_depth.p); fmt0_depth.format = 0; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, g::encode(fmt0_depth), &why); check(result == rt::d3d12::TitleImage::not_tsharp, "format==0 on depth texture rejected as not_tsharp (not wrongly bound)"); } } // 3D UAV slice offset check: must NOT refuse unknown addresses or non-UAV 3D textures, MUST refuse 3D UAVs. { g::Image vol{}; vol.address = 0xdeadbeef00ull; // unknown address vol.type = g::ImageType::image_3d; vol.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); vol.width = 8; vol.height = 8; vol.depth = 8; vol.first_layer = 2; vol.mip_count = 1; auto words = g::encode(vol); words[5] |= 1u; // hardware 3D UAV slice flag WORD5[3:0] == 1 const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::unknown, "3D slice-offset words on unknown address return unknown (not false-positive refused)"); } { D3D12_RESOURCE_DESC desc3d{}; desc3d.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE3D; desc3d.Width = 8; desc3d.Height = 8; desc3d.DepthOrArraySize = 8; desc3d.MipLevels = 1; desc3d.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc3d.SampleDesc.Count = 1; Ref res_3d_ro; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc3d, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_3d_ro.put()))), "created non-UAV 3D texture"); g::Image vol_ro{}; vol_ro.address = rt::d3d12::resource_image_address(res_3d_ro.p); vol_ro.type = g::ImageType::image_3d; vol_ro.format = g::format_from_vulkan(VK_FORMAT_R8G8B8A8_UNORM); vol_ro.width = 8; vol_ro.height = 8; vol_ro.depth = 8; vol_ro.first_layer = 2; vol_ro.mip_count = 1; auto words_ro = g::encode(vol_ro); words_ro[5] |= 1u; const char* why = nullptr; const auto res_ro = rt::d3d12::test_bind_title_image(device.p, words_ro, &why); check(res_ro == rt::d3d12::TitleImage::bound, "non-UAV 3D texture with slice bits binds cleanly"); // Bit 31 (volume_uav_flag) is synthetic and MUST NOT be rejected by the WORD4 reserved-bit check. auto words_flag31 = g::encode(vol_ro); words_flag31[4] |= g::volume_uav_flag; const auto res_flag31 = rt::d3d12::test_bind_title_image(device.p, words_flag31, &why); check(res_flag31 != rt::d3d12::TitleImage::not_tsharp, "WORD4[31] (volume_uav_flag) is not rejected as reserved bit"); desc3d.Flags = D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; Ref res_3d_uav; check(SUCCEEDED(device->CreateCommittedResource(&heap_props, D3D12_HEAP_FLAG_NONE, &desc3d, D3D12_RESOURCE_STATE_COMMON, nullptr, IID_PPV_ARGS(res_3d_uav.put()))), "created UAV 3D texture"); g::Image vol_uav = vol_ro; vol_uav.address = rt::d3d12::resource_image_address(res_3d_uav.p); auto words_uav = g::encode(vol_uav); words_uav[5] |= 1u; why = nullptr; const auto res_uav = rt::d3d12::test_bind_title_image(device.p, words_uav, &why); check(res_uav == rt::d3d12::TitleImage::refused, "UAV 3D texture with slice offset is refused"); check(why && std::string(why) == "a title-written 3D UAV with a slice offset is not supported", "UAV 3D slice offset reports exact refusal reason"); // Fix 4F: 3D extent mismatch (depth differs) is refused with exact reason. g::Image vol_bad_depth = vol_ro; vol_bad_depth.depth = 4; why = nullptr; const auto res_depth = rt::d3d12::test_bind_title_image(device.p, g::encode(vol_bad_depth), &why); check(res_depth == rt::d3d12::TitleImage::refused, "3D T# with mismatched depth is refused"); check(why && std::string(why) == "T# extent does not match the texture", "3D depth mismatch reports exact extent refusal reason"); } // Test 7 (Fix 4F): Half-overwritten Leonida encode() T# guard and mip-0 extent check { // 7a. Half-overwritten 2D (type=9) and 2D-array (type=13) Leonida-encoded T#s with non-zero WORD5[31:8] // or non-zero WORD7 (without volume_uav_flag) must be rejected as not_tsharp. for (const g::ImageType type : {g::ImageType::image_2d, g::ImageType::image_2d_array}) { g::Image img = base2d; img.type = type; { auto words = g::encode(img); words[5] |= 0x0900u; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::not_tsharp, "encoded T# with non-zero WORD5[31:8] rejected as not_tsharp"); } { auto words = g::encode(img); words[7] = 1u; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::not_tsharp, "encoded T# with non-zero WORD7 (no volume_uav_flag) rejected as not_tsharp"); } } // 7b. Positive controls: WORD6 metadata, WORD5 low byte, volume_uav_flag + WORD7, and real hardware T#s // (RESOURCE_LEVEL == 1 or SW_MODE != 0) are never falsely rejected as not_tsharp. { auto words = g::encode(base2d); words[6] = 0x00C0FFEEu; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "encoded T# with WORD6 metadata still binds"); } { auto words = g::encode(base2d); words[4] |= g::volume_uav_flag; words[7] = 0x00010002u; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result != rt::d3d12::TitleImage::not_tsharp, "encoded T# with volume_uav_flag and WORD7 is not rejected as not_tsharp"); } { auto words = g::encode(base2d); words[2] |= (1u << 31); // RESOURCE_LEVEL == 1 (hardware T#) words[5] |= 0x0900u; words[7] = 1u; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "hardware T# (RESOURCE_LEVEL==1) with non-zero WORD5/WORD7 binds cleanly"); } { auto words = g::encode(base2d); words[3] |= (1u << 20); // SW_MODE != 0 (hardware T#) words[5] |= 0x0900u; words[7] = 1u; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, words, &why); check(result == rt::d3d12::TitleImage::bound, "hardware T# (SW_MODE!=0) with non-zero WORD5/WORD7 binds cleanly"); } // 7c. Stale-VA mip-0 extent mismatch (compatible format/mips/layers, wrong width or height) is refused. const std::uint32_t bad_extents[][2] = {{64u, 32u}, {32u, 16u}}; for (const auto& ext : bad_extents) { g::Image bad_extent = base2d; bad_extent.width = ext[0]; bad_extent.height = ext[1]; const char* why = nullptr; const auto result = rt::d3d12::test_bind_title_image(device.p, g::encode(bad_extent), &why); check(result == rt::d3d12::TitleImage::refused, "2D T# with mismatched extent is refused"); check(why && std::string(why) == "T# extent does not match the texture", "2D extent mismatch reports exact refusal reason"); } } } std::printf("d3d12_unbound_tsharp_rules_test: %d checks, %d failures\n", g_checks, g_failures); return g_failures == 0 ? 0 : 1; }