upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 15:16:12 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-22 15:16:12 -0500
commita09d690ca90347aa6e0b47abdc39c8b6cbd6c3bb (patch)
tree77a504edcc65fc00677d0e8b36bf8ae8e37d81ca /runtime
parent94d402f4107dfc7b852fbde03a35acf56da8fb44 (diff)
parent867430739aa82c60a7bedac846810780de5b4953 (diff)
Merge pull request #3252 from Douglas Sposito
Diffstat (limited to 'runtime')
-rw-r--r--runtime/shims/d3d12_vulkan_device.cpp27
-rw-r--r--runtime/test/d3d12_descriptor_test.cpp117
2 files changed, 118 insertions, 26 deletions
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp
index 97222d6a6..888ac5294 100644
--- a/runtime/shims/d3d12_vulkan_device.cpp
+++ b/runtime/shims/d3d12_vulkan_device.cpp
@@ -1475,6 +1475,14 @@ public:
1475 return view_formats_.empty() || format == format_ || 1475 return view_formats_.empty() || format == format_ ||
1476 std::find(view_formats_.begin(), view_formats_.end(), format) != view_formats_.end(); 1476 std::find(view_formats_.begin(), view_formats_.end(), format) != view_formats_.end();
1477 } 1477 }
1478 // The castable-format list in DXGI formats, which the Vulkan list can't tell apart where two families share a
1479 // VkFormat: B8G8R8X8 and B8G8R8A8 are both BGRA8 images.
1480 void keep_castable_formats(UINT32 count, const DXGI_FORMAT* formats) {
1481 if (count && formats) castable_formats_.assign(formats, formats + count);
1482 }
1483 bool lists_castable_format(DXGI_FORMAT format) const {
1484 return std::find(castable_formats_.begin(), castable_formats_.end(), format) != castable_formats_.end();
1485 }
1478 bool r9g9b9e5_as_r32_uint() const { return r9g9b9e5_as_r32_uint_; } 1486 bool r9g9b9e5_as_r32_uint() const { return r9g9b9e5_as_r32_uint_; }
1479 VkImageAspectFlags aspects() const { return aspects_; } 1487 VkImageAspectFlags aspects() const { return aspects_; }
1480 bool rgb96() const { return rgb96_; } // a 96-bit texture in an RGBA32 image 1488 bool rgb96() const { return rgb96_; } // a 96-bit texture in an RGBA32 image
@@ -2057,6 +2065,7 @@ private:
2057 void* mapped_ = nullptr; 2065 void* mapped_ = nullptr;
2058 VkFormat format_ = VK_FORMAT_UNDEFINED; 2066 VkFormat format_ = VK_FORMAT_UNDEFINED;
2059 std::vector<VkFormat> view_formats_; // creation-time castable list; empty means no restriction 2067 std::vector<VkFormat> view_formats_; // creation-time castable list; empty means no restriction
2068 std::vector<DXGI_FORMAT> castable_formats_; // the same list as the application gave it
2060 bool r9g9b9e5_as_r32_uint_ = false; 2069 bool r9g9b9e5_as_r32_uint_ = false;
2061 std::uint64_t image_address_ = 0; // what a T# names the texture by 2070 std::uint64_t image_address_ = 0; // what a T# names the texture by
2062 bool rgb96_ = false; 2071 bool rgb96_ = false;
@@ -3718,7 +3727,9 @@ bool image_descriptor(const Resource& resource, const TextureView& view, leonida
3718 log_once("incompatible typed A8 view format:", int(view.format)); 3727 log_once("incompatible typed A8 view format:", int(view.format));
3719 return false; 3728 return false;
3720 } 3729 }
3721 if (alpha_unused(view.format) != alpha_unused(desc.Format)) { 3730 // Only a castable-format list that names the view's format lets a view cross the two families, as WARP and
3731 // AMD's D3D12 driver accept (relaxed casting).
3732 if (alpha_unused(view.format) != alpha_unused(desc.Format) && !resource.lists_castable_format(view.format)) {
3722 log_once("view format from another typeless family (B8G8R8X8 and B8G8R8A8):", int(view.format)); 3733 log_once("view format from another typeless family (B8G8R8X8 and B8G8R8A8):", int(view.format));
3723 return false; 3734 return false;
3724 } 3735 }
@@ -3793,11 +3804,17 @@ bool image_descriptor(const Resource& resource, const TextureView& view, leonida
3793 // D3D12's component mapping picks, for each of R, G, B, A, a channel of the format or a constant; the T# 3804 // D3D12's component mapping picks, for each of R, G, B, A, a channel of the format or a constant; the T#
3794 // says the same about the hardware's channels, which the format places. 3805 // says the same about the hardware's channels, which the format places.
3795 // A stencil view's format has its eight bits in G and no R, B or A of its own (0, 0, 1 when read). 3806 // A stencil view's format has its eight bits in G and no R, B or A of its own (0, 0, 1 when read).
3796 // B8G8R8X8 has no alpha: it reads 1. 3807 // B8G8R8X8 has no alpha: a view in its family reads 1, and a B8G8R8A8 view of a B8G8R8X8 texture (through a
3797 g::Swizzle channels = g::format_swizzle(view_format); 3808 // castable-format list) the stored byte. The view's format decides, as on WARP and AMD's D3D12 driver.
3809 // The T#'s format code is the same for both channel orders of a colour format (R8G8B8A8 and B8G8R8A8 are one
3810 // 8_8_8_8 code), and the image view keeps the image's format; a castable-format list may still ask for the other
3811 // order, so then the view's own format places the channels. Depth images keep their own format's channels.
3812 const bool other_order = view.format != DXGI_FORMAT_UNKNOWN && !stencil && !depth_plane && !rgb96 &&
3813 named != view_format && !g::is_depth_stencil_format(view_format);
3814 g::Swizzle channels = g::format_swizzle(other_order ? named : view_format);
3798 if (stencil) channels = {g::select_zero, g::select_x, g::select_zero, g::select_one}; 3815 if (stencil) channels = {g::select_zero, g::select_x, g::select_zero, g::select_one};
3799 else if (desc.Format == DXGI_FORMAT_A8_UNORM) channels = {g::select_zero, g::select_zero, g::select_zero, g::select_x}; 3816 else if (desc.Format == DXGI_FORMAT_A8_UNORM) channels = {g::select_zero, g::select_zero, g::select_zero, g::select_x};
3800 else if (alpha_unused(desc.Format)) channels[3] = g::select_one; 3817 else if (alpha_unused(view.format != DXGI_FORMAT_UNKNOWN ? view.format : desc.Format)) channels[3] = g::select_one;
3801 for (UINT i = 0; i < 4; ++i) { 3818 for (UINT i = 0; i < 4; ++i) {
3802 const UINT from = D3D12_DECODE_SHADER_4_COMPONENT_MAPPING(i, view.mapping); 3819 const UINT from = D3D12_DECODE_SHADER_4_COMPONENT_MAPPING(i, view.mapping);
3803 if (msaa && from > D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1) { 3820 if (msaa && from > D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1) {
@@ -5867,6 +5884,7 @@ public:
5867 std::vector<VkFormat> cast_formats; 5884 std::vector<VkFormat> cast_formats;
5868 hr = castable_view_formats(format, castable_count, castable, cast_formats); 5885 hr = castable_view_formats(format, castable_count, castable, cast_formats);
5869 if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats); 5886 if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats);
5887 if (SUCCEEDED(hr)) resource->keep_castable_formats(castable_count, castable);
5870 } 5888 }
5871 } 5889 }
5872 if (FAILED(hr)) { 5890 if (FAILED(hr)) {
@@ -6890,6 +6908,7 @@ private:
6890 std::vector<VkFormat> cast_formats; 6908 std::vector<VkFormat> cast_formats;
6891 hr = castable_view_formats(format, castable_count, castable, cast_formats); 6909 hr = castable_view_formats(format, castable_count, castable, cast_formats);
6892 if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats); 6910 if (SUCCEEDED(hr)) hr = resource->create_texture(format, cast_formats);
6911 if (SUCCEEDED(hr)) resource->keep_castable_formats(castable_count, castable);
6893 } 6912 }
6894 } 6913 }
6895 if (FAILED(hr)) { 6914 if (FAILED(hr)) {
diff --git a/runtime/test/d3d12_descriptor_test.cpp b/runtime/test/d3d12_descriptor_test.cpp
index 19e38a550..8859cd67c 100644
--- a/runtime/test/d3d12_descriptor_test.cpp
+++ b/runtime/test/d3d12_descriptor_test.cpp
@@ -15,7 +15,9 @@
15// at the same S# type, so this also checks that they are two samplers, not one. 15// at the same S# type, so this also checks that they are two samplers, not one.
16// - B8G8R8X8 (D3D-87): a B8G8R8X8_UNORM and a B8G8R8A8_UNORM texture uploaded with the same bytes, the fourth 16// - B8G8R8X8 (D3D-87): a B8G8R8X8_UNORM and a B8G8R8A8_UNORM texture uploaded with the same bytes, the fourth
17// never 255. Their default views read the same red, green and blue; B8G8R8X8 reads alpha 1, B8G8R8A8 the 17// never 255. Their default views read the same red, green and blue; B8G8R8X8 reads alpha 1, B8G8R8A8 the
18// stored byte. Views between the two typeless families give a null descriptor. 18// stored byte. Views between the two typeless families give a null descriptor, unless a castable-format list
19// names the view's format: then a B8G8R8X8 view of a B8G8R8A8 texture reads alpha 1, and a B8G8R8A8 view of a
20// B8G8R8X8 one the stored byte, as on WARP and AMD's D3D12 driver.
19// Multisample SRVs: four masked triangles seed different values per sample and array layer. A compute shader reads 21// Multisample SRVs: four masked triangles seed different values per sample and array layer. A compute shader reads
20// them back using the T#s for the 2D, full-array and sliced-array views. The test builds its pipelines in Vulkan 22// them back using the T#s for the 2D, full-array and sliced-array views. The test builds its pipelines in Vulkan
21// and binds the device's set (rt::d3d12::bindless_set). Without glslangValidator the GPU readbacks are skipped. 23// and binds the device's set (rt::d3d12::bindless_set). Without glslangValidator the GPU readbacks are skipped.
@@ -303,7 +305,7 @@ int main() {
303 if (device_status != vktest::DeviceStatus::ready) return 1; 305 if (device_status != vktest::DeviceStatus::ready) return 1;
304 306
305 constexpr UINT size = 8, texels = size * size, bytes = texels * 4; 307 constexpr UINT size = 8, texels = size * size, bytes = texels * 4;
306 std::vector<std::uint8_t> results(4 * bytes), after_destruction(bytes), borders(3 * bytes), bgr_results(2 * bytes); 308 std::vector<std::uint8_t> results(4 * bytes), after_destruction(bytes), borders(3 * bytes), bgr_results(6 * bytes);
307 bool sampled_through_set = false; 309 bool sampled_through_set = false;
308 UINT lod_mismatches = 0; 310 UINT lod_mismatches = 0;
309 { 311 {
@@ -545,22 +547,49 @@ int main() {
545 for (UINT x = 0; x < fp.Width; ++x) std::memcpy(row + 4 * x, color.data(), 4); 547 for (UINT x = 0; x < fp.Width; ++x) std::memcpy(row + 4 * x, color.data(), 4);
546 } 548 }
547 } 549 }
548 // A B8G8R8X8_UNORM texture and a B8G8R8A8_UNORM one, uploaded with the same bgrx_texel bytes past the cube 550 // Five textures uploaded with the same bgrx_texel bytes past the cube array's footprints: a B8G8R8X8_UNORM and
549 // array's footprints. 551 // a B8G8R8A8_UNORM one for their default views, then a B8G8R8A8_UNORM texture whose castable-format list names
550 constexpr DXGI_FORMAT bgr_formats[2] = {DXGI_FORMAT_B8G8R8X8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM}; 552 // B8G8R8X8_UNORM and a B8G8R8X8_UNORM one whose list names B8G8R8A8_UNORM, each viewed in the other family,
551 Ref<ID3D12Resource> bgr_textures[2]; 553 // and two R8G8B8A8_UNORM ones whose lists name B8G8R8X8_UNORM and B8G8R8A8_UNORM, viewed through them (red
552 D3D12_PLACED_SUBRESOURCE_FOOTPRINT bgr_placed[2]{}; 554 // and blue swap places).
555 constexpr UINT bgr_count = 6;
556 constexpr DXGI_FORMAT bgr_formats[bgr_count] = {DXGI_FORMAT_B8G8R8X8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM,
557 DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B8G8R8X8_UNORM,
558 DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM};
559 constexpr DXGI_FORMAT bgr_casts[bgr_count] = {DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
560 DXGI_FORMAT_B8G8R8X8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM,
561 DXGI_FORMAT_B8G8R8X8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM};
562 Ref<ID3D12Resource> bgr_textures[bgr_count];
563 D3D12_PLACED_SUBRESOURCE_FOOTPRINT bgr_placed[bgr_count]{};
564 Ref<ID3D12Device10> bgr_device10;
565 EXPECT(SUCCEEDED(inner->QueryInterface(IID_PPV_ARGS(&bgr_device10.p))));
553 const auto& last_array = array_levels[std::size(array_levels) - 1]; 566 const auto& last_array = array_levels[std::size(array_levels) - 1];
554 constexpr UINT64 placement = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT; 567 constexpr UINT64 placement = D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT;
555 const UINT64 bgr_start = 568 const UINT64 bgr_start =
556 (last_array.Offset + UINT64(last_array.Footprint.RowPitch) * last_array.Footprint.Height + placement - 1) & 569 (last_array.Offset + UINT64(last_array.Footprint.RowPitch) * last_array.Footprint.Height + placement - 1) &
557 ~(placement - 1); 570 ~(placement - 1);
558 for (UINT f = 0; f < 2; ++f) { 571 for (UINT f = 0; f < bgr_count; ++f) {
559 D3D12_RESOURCE_DESC desc = texture_desc; 572 D3D12_RESOURCE_DESC desc = texture_desc;
560 desc.Format = bgr_formats[f]; 573 desc.Format = bgr_formats[f];
561 EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &desc, 574 if (bgr_casts[f] == DXGI_FORMAT_UNKNOWN) {
562 D3D12_RESOURCE_STATE_COPY_DEST, nullptr, 575 EXPECT(SUCCEEDED(device->CreateCommittedResource(&default_heap, D3D12_HEAP_FLAG_NONE, &desc,
563 IID_PPV_ARGS(&bgr_textures[f].p)))); 576 D3D12_RESOURCE_STATE_COPY_DEST, nullptr,
577 IID_PPV_ARGS(&bgr_textures[f].p))));
578 } else {
579 D3D12_RESOURCE_DESC1 desc1{};
580 desc1.Dimension = desc.Dimension;
581 desc1.Width = desc.Width;
582 desc1.Height = desc.Height;
583 desc1.DepthOrArraySize = desc.DepthOrArraySize;
584 desc1.MipLevels = desc.MipLevels;
585 desc1.Format = desc.Format;
586 desc1.SampleDesc = desc.SampleDesc;
587 desc1.Layout = desc.Layout;
588 desc1.Flags = desc.Flags;
589 EXPECT(SUCCEEDED(bgr_device10->CreateCommittedResource3(
590 &default_heap, D3D12_HEAP_FLAG_NONE, &desc1, D3D12_BARRIER_LAYOUT_COPY_DEST, nullptr, nullptr, 1,
591 &bgr_casts[f], IID_PPV_ARGS(&bgr_textures[f].p))));
592 }
564 device->GetCopyableFootprints(&desc, 0, 1, bgr_start + 8192 * f, &bgr_placed[f], nullptr, nullptr, nullptr); 593 device->GetCopyableFootprints(&desc, 0, 1, bgr_start + 8192 * f, &bgr_placed[f], nullptr, nullptr, nullptr);
565 EXPECT(bgr_placed[f].Footprint.Format == bgr_formats[f]); 594 EXPECT(bgr_placed[f].Footprint.Format == bgr_formats[f]);
566 EXPECT(bgr_placed[f].Offset + UINT64(bgr_placed[f].Footprint.RowPitch) * size <= upload_desc.Width); 595 EXPECT(bgr_placed[f].Offset + UINT64(bgr_placed[f].Footprint.RowPitch) * size <= upload_desc.Width);
@@ -601,7 +630,8 @@ int main() {
601 volume_lod_slot = cube_lod_slot + cube_lod_count, 630 volume_lod_slot = cube_lod_slot + cube_lod_count,
602 ms_slot = volume_lod_slot + volume_lod_count, ms_array_slot, ms_slice_slot, ms_first_layer_slot, 631 ms_slot = volume_lod_slot + volume_lod_count, ms_array_slot, ms_slice_slot, ms_first_layer_slot,
603 ms_uint_slot, ms_uint_array_slot, ms_sint_slot, ms_sint_array_slot, 632 ms_uint_slot, ms_uint_array_slot, ms_sint_slot, ms_sint_array_slot,
604 line_default, line_mip, line_clamped, bgrx_slot, bgra_slot, typed_bgrx_slot, view_slot_count 633 line_default, line_mip, line_clamped, bgrx_slot, bgra_slot, typed_bgrx_slot, cast_bgrx_slot,
634 cast_bgra_slot, cast_rgbx_slot, cast_rgba_slot, view_slot_count
605 }; 635 };
606 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, view_slot_count, 636 D3D12_DESCRIPTOR_HEAP_DESC heap_desc{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, view_slot_count,
607 D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 0}; 637 D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, 0};
@@ -1185,6 +1215,35 @@ int main() {
1185 bgra_image.format == bgrx_image.format); 1215 bgra_image.format == bgrx_image.format);
1186 EXPECT((bgrx_image.swizzle == g::Swizzle{g::select_z, g::select_y, g::select_x, g::select_one})); 1216 EXPECT((bgrx_image.swizzle == g::Swizzle{g::select_z, g::select_y, g::select_x, g::select_one}));
1187 EXPECT((bgra_image.swizzle == g::Swizzle{g::select_z, g::select_y, g::select_x, g::select_w})); 1217 EXPECT((bgra_image.swizzle == g::Swizzle{g::select_z, g::select_y, g::select_x, g::select_w}));
1218 // A castable-format list lets a view cross the two families, and the view's own format decides the alpha:
1219 // WARP and AMD's D3D12 driver read 1 through a B8G8R8X8 view of a B8G8R8A8 texture, and the stored byte
1220 // through a B8G8R8A8 view of a B8G8R8X8 one. A format the list doesn't name stays refused.
1221 {
1222 D3D12_SHADER_RESOURCE_VIEW_DESC cast_view = flat_view;
1223 cast_view.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
1224 device->CreateShaderResourceView(bgr_textures[2].p, &cast_view, view_slot(cast_bgrx_slot));
1225 cast_view.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
1226 device->CreateShaderResourceView(bgr_textures[3].p, &cast_view, view_slot(cast_bgra_slot));
1227 cast_view.Format = DXGI_FORMAT_B8G8R8X8_UNORM;
1228 device->CreateShaderResourceView(bgr_textures[4].p, &cast_view, view_slot(cast_rgbx_slot));
1229 cast_view.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
1230 device->CreateShaderResourceView(bgr_textures[5].p, &cast_view, view_slot(cast_rgba_slot));
1231 g::Image cast_bgrx_image{}, cast_bgra_image{}, cast_rgbx_image{}, cast_rgba_image{};
1232 EXPECT(image_at(cast_bgrx_slot, cast_bgrx_image) && image_at(cast_bgra_slot, cast_bgra_image) &&
1233 image_at(cast_rgbx_slot, cast_rgbx_image) && image_at(cast_rgba_slot, cast_rgba_image));
1234 EXPECT(cast_bgrx_image.format == bgrx_image.format && cast_bgra_image.format == bgrx_image.format &&
1235 cast_rgbx_image.format == bgrx_image.format && cast_rgba_image.format == bgrx_image.format);
1236 // The T#'s format code is the same for both channel orders, so the swizzle carries the view's order.
1237 EXPECT(cast_bgrx_image.swizzle == bgrx_image.swizzle && cast_bgra_image.swizzle == bgra_image.swizzle);
1238 EXPECT(cast_rgba_image.swizzle == bgra_image.swizzle); // B8G8R8A8 view of R8G8B8A8, no B8G8R8X8 involved
1239 EXPECT(cast_rgbx_image.swizzle == bgrx_image.swizzle);
1240 cast_view.Format = DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
1241 for (ID3D12Resource* listed : {bgr_textures[2].p, bgr_textures[3].p, bgr_textures[4].p, bgr_textures[5].p}) {
1242 std::memset(view_bytes(null_slot), 0x77, step);
1243 device->CreateShaderResourceView(listed, &cast_view, view_slot(null_slot));
1244 EXPECT(null_at(null_slot));
1245 }
1246 }
1188 Ref<ID3D12Resource> bgrx_typeless; 1247 Ref<ID3D12Resource> bgrx_typeless;
1189 D3D12_RESOURCE_DESC bgrx_typeless_desc = texture_desc; 1248 D3D12_RESOURCE_DESC bgrx_typeless_desc = texture_desc;
1190 bgrx_typeless_desc.Format = DXGI_FORMAT_B8G8R8X8_TYPELESS; 1249 bgrx_typeless_desc.Format = DXGI_FORMAT_B8G8R8X8_TYPELESS;
@@ -1325,7 +1384,7 @@ int main() {
1325 transition(bc.p, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); 1384 transition(bc.p, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE);
1326 list->ResourceBarrier(1, &barrier); 1385 list->ResourceBarrier(1, &barrier);
1327 } 1386 }
1328 for (UINT f = 0; f < 2; ++f) { 1387 for (UINT f = 0; f < bgr_count; ++f) {
1329 to_texture.pResource = bgr_textures[f].p; 1388 to_texture.pResource = bgr_textures[f].p;
1330 from_upload.PlacedFootprint = bgr_placed[f]; 1389 from_upload.PlacedFootprint = bgr_placed[f];
1331 list->CopyTextureRegion(&to_texture, 0, 0, 0, &from_upload, nullptr); 1390 list->CopyTextureRegion(&to_texture, 0, 0, 0, &from_upload, nullptr);
@@ -1350,6 +1409,14 @@ int main() {
1350 transition(bgr_textures[0].p, D3D12_RESOURCE_STATE_COPY_DEST, 1409 transition(bgr_textures[0].p, D3D12_RESOURCE_STATE_COPY_DEST,
1351 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE), 1410 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
1352 transition(bgr_textures[1].p, D3D12_RESOURCE_STATE_COPY_DEST, 1411 transition(bgr_textures[1].p, D3D12_RESOURCE_STATE_COPY_DEST,
1412 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
1413 transition(bgr_textures[2].p, D3D12_RESOURCE_STATE_COPY_DEST,
1414 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
1415 transition(bgr_textures[3].p, D3D12_RESOURCE_STATE_COPY_DEST,
1416 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
1417 transition(bgr_textures[4].p, D3D12_RESOURCE_STATE_COPY_DEST,
1418 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE),
1419 transition(bgr_textures[5].p, D3D12_RESOURCE_STATE_COPY_DEST,
1353 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE)}; 1420 D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE)};
1354 list->ResourceBarrier(UINT(std::size(sampled)), sampled); 1421 list->ResourceBarrier(UINT(std::size(sampled)), sampled);
1355 to_texture.pResource = array_texture.p; 1422 to_texture.pResource = array_texture.p;
@@ -2081,10 +2148,12 @@ int main() {
2081 } 2148 }
2082 EXPECT(rgb96_differ == 0); 2149 EXPECT(rgb96_differ == 0);
2083 } 2150 }
2084 // The B8G8R8X8 and B8G8R8A8 textures through their default views. 2151 // The B8G8R8X8 and B8G8R8A8 textures through their default views, then the two castable ones through a view
2085 SampleKeys bgr_keys[2] = {}; 2152 // of the other family.
2086 const UINT bgr_slots[2] = {bgrx_slot, bgra_slot}; 2153 SampleKeys bgr_keys[bgr_count] = {};
2087 for (UINT k = 0; k < 2; ++k) { 2154 const UINT bgr_slots[bgr_count] = {bgrx_slot, bgra_slot, cast_bgrx_slot,
2155 cast_bgra_slot, cast_rgbx_slot, cast_rgba_slot};
2156 for (UINT k = 0; k < bgr_count; ++k) {
2088 std::memcpy(bgr_keys[k].tsharp, view_bytes(bgr_slots[k]), sizeof(bgr_keys[k].tsharp)); 2157 std::memcpy(bgr_keys[k].tsharp, view_bytes(bgr_slots[k]), sizeof(bgr_keys[k].tsharp));
2089 std::memcpy(bgr_keys[k].ssharp, sampler_bytes, sizeof(bgr_keys[k].ssharp)); 2158 std::memcpy(bgr_keys[k].ssharp, sampler_bytes, sizeof(bgr_keys[k].ssharp));
2090 bgr_keys[k].first = k * texels; 2159 bgr_keys[k].first = k * texels;
@@ -2691,12 +2760,15 @@ int main() {
2691 } 2760 }
2692 EXPECT(!mismatches); 2761 EXPECT(!mismatches);
2693 EXPECT(lod_mismatches == 0); 2762 EXPECT(lod_mismatches == 0);
2694 // Both read red, green and blue from the same bytes; B8G8R8X8 reads alpha 1, B8G8R8A8 the stored byte. 2763 // All read red, green and blue from the same bytes; a B8G8R8X8 view reads alpha 1, a B8G8R8A8 view the stored
2695 const char* bgr_names[2] = {"B8G8R8X8_UNORM", "B8G8R8A8_UNORM"}; 2764 // byte, whatever the texture's own format (R8G8B8A8 textures read through B8G8R8X8 and B8G8R8A8 views included).
2696 for (UINT k = 0; k < 2; ++k) 2765 const char* bgr_names[] = {"B8G8R8X8_UNORM", "B8G8R8A8_UNORM", "B8G8R8X8_UNORM view of castable B8G8R8A8",
2766 "B8G8R8A8_UNORM view of castable B8G8R8X8", "B8G8R8X8_UNORM view of castable R8G8B8A8",
2767 "B8G8R8A8_UNORM view of castable R8G8B8A8"};
2768 for (UINT k = 0; k < 6; ++k)
2697 for (UINT i = 0; i < texels; ++i) { 2769 for (UINT i = 0; i < texels; ++i) {
2698 auto want = texel(i % size, i / size); 2770 auto want = texel(i % size, i / size);
2699 if (k == 1) want[3] = bgrx_texel(i % size, i / size)[3]; 2771 if (k == 1 || k == 3 || k == 5) want[3] = bgrx_texel(i % size, i / size)[3];
2700 const std::uint8_t* got = bgr_results.data() + k * bytes + i * 4; 2772 const std::uint8_t* got = bgr_results.data() + k * bytes + i * 4;
2701 if (std::memcmp(got, want.data(), 4) != 0 && mismatches++ < 4) 2773 if (std::memcmp(got, want.data(), 4) != 0 && mismatches++ < 4)
2702 std::fprintf(stderr, "%s texel %u: got %u,%u,%u,%u, want %u,%u,%u,%u\n", bgr_names[k], i, 2774 std::fprintf(stderr, "%s texel %u: got %u,%u,%u,%u, want %u,%u,%u,%u\n", bgr_names[k], i,
@@ -2711,7 +2783,8 @@ int main() {
2711 std::printf("descriptors: copies matched; a T# and an S# from CreateShaderResourceView and CreateSampler were " 2783 std::printf("descriptors: copies matched; a T# and an S# from CreateShaderResourceView and CreateSampler were "
2712 "found in the device's bindless set by a shader, %u RGBA8 and RGB9E5 texels matched, and an unknown descriptor " 2784 "found in the device's bindless set by a shader, %u RGBA8 and RGB9E5 texels matched, and an unknown descriptor "
2713 "and a destroyed texture's gave the fallback; UINT black, UINT white and float white borders read " 2785 "and a destroyed texture's gave the fallback; UINT black, UINT white and float white borders read "
2714 "0, 1 and 255; B8G8R8X8 read alpha 1 where B8G8R8A8 read the same bytes' alpha (%u texels each)\n", 2786 "0, 1 and 255; B8G8R8X8 views read alpha 1 where B8G8R8A8 views read the same bytes' alpha, also across "
2787 "a castable-format list (%u texels each)\n",
2715 texels, texels); 2788 texels, texels);
2716 return 0; 2789 return 0;
2717} 2790}