diff options
| author | Ayinaki <ayinakidev@gmail.com> | 2026-11-22 01:59:55 +0000 |
|---|---|---|
| committer | abilliontokens <39147239+abilliontokens@users.noreply.github.com> | 2026-11-21 21:56:17 -0800 |
| commit | 01c0a564855f8082f60577ca41b0971b24be4183 (patch) | |
| tree | 938f9de33acf9b111322b97febb9015ec432a7f1 /runtime/test/d3d12_method_variants_test.cpp | |
| parent | 059b9f325f5c7327725c62689b401afacc8096d4 (diff) | |
d3d12: accept castable formats on committed textures
Keep the creation-time castable list on the resource, reject an SRV format
that is neither the resource format nor listed, and allow listed same-size
cross-family casts such as R8G8B8A8_UINT to R32_UINT.
Diffstat (limited to 'runtime/test/d3d12_method_variants_test.cpp')
| -rw-r--r-- | runtime/test/d3d12_method_variants_test.cpp | 84 |
1 files changed, 81 insertions, 3 deletions
diff --git a/runtime/test/d3d12_method_variants_test.cpp b/runtime/test/d3d12_method_variants_test.cpp index 7bfba2a07..8f84c99cd 100644 --- a/runtime/test/d3d12_method_variants_test.cpp +++ b/runtime/test/d3d12_method_variants_test.cpp | |||
| @@ -321,18 +321,96 @@ int main() { | |||
| 321 | } | 321 | } |
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | // Castable formats: a list is refused, since the layer reports no relaxed format casting (D3D12_OPTIONS12). | 324 | // Castable formats: the layer reports relaxed format casting and passes a real list to |
| 325 | // Not compared with the host, whose answer depends on its GPU's RelaxedFormatCastingSupported. | 325 | // VkImageFormatListCreateInfo. A count with a null list is still no list; a buffer cannot have one. |
| 326 | { | 326 | { |
| 327 | D3D12_FEATURE_DATA_D3D12_OPTIONS12 options12{}; | ||
| 328 | EXPECT(SUCCEEDED(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options12, | ||
| 329 | sizeof(options12)))); | ||
| 330 | EXPECT(options12.RelaxedFormatCastingSupported == TRUE); | ||
| 331 | EXPECT(device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS12, &options12, | ||
| 332 | sizeof(options12) - 1) == E_INVALIDARG); | ||
| 327 | const D3D12_RESOURCE_DESC1 texture = | 333 | const D3D12_RESOURCE_DESC1 texture = |
| 328 | desc1(texture_desc(4, 4, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | 334 | desc1(texture_desc(4, 4, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); |
| 329 | const DXGI_FORMAT own[] = {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}; | 335 | const DXGI_FORMAT own[] = {DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}; |
| 330 | Ref<ID3D12Resource> r; | 336 | Ref<ID3D12Resource> r; |
| 337 | EXPECT(SUCCEEDED(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &texture, | ||
| 338 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 2, own, | ||
| 339 | IID_PPV_ARGS(&r.p)))); | ||
| 340 | EXPECT(rt::d3d12::vulkan_image(r.p)); | ||
| 341 | r.reset(); | ||
| 342 | const D3D12_RESOURCE_DESC1 buffer = desc1(buffer_desc(256)); | ||
| 343 | EXPECT(device->CreateCommittedResource3(&upload_heap, D3D12_HEAP_FLAG_NONE, &buffer, | ||
| 344 | D3D12_BARRIER_LAYOUT_UNDEFINED, nullptr, nullptr, 2, own, | ||
| 345 | IID_PPV_ARGS(&r.p)) == E_INVALIDARG && !r.p); | ||
| 346 | const DXGI_FORMAT unknown[] = {DXGI_FORMAT_UNKNOWN}; | ||
| 331 | EXPECT(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &texture, | 347 | EXPECT(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &texture, |
| 332 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 2, own, | 348 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 1, unknown, |
| 333 | IID_PPV_ARGS(&r.p)) == E_INVALIDARG && !r.p); | 349 | IID_PPV_ARGS(&r.p)) == E_INVALIDARG && !r.p); |
| 334 | } | 350 | } |
| 335 | 351 | ||
| 352 | // The creation-time castable list is also the view allow-list. An unlisted SRGB view leaves the slot null; | ||
| 353 | // a listed same-size cross-family cast writes a descriptor and creates its Vulkan view. | ||
| 354 | { | ||
| 355 | Ref<ID3D12DescriptorHeap> heap; | ||
| 356 | D3D12_DESCRIPTOR_HEAP_DESC heap_desc{}; | ||
| 357 | heap_desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV; | ||
| 358 | heap_desc.NumDescriptors = 3; | ||
| 359 | heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; | ||
| 360 | EXPECT(SUCCEEDED(device->CreateDescriptorHeap(&heap_desc, IID_PPV_ARGS(&heap.p)))); | ||
| 361 | D3D12_CPU_DESCRIPTOR_HANDLE slot = heap->GetCPUDescriptorHandleForHeapStart(); | ||
| 362 | const UINT stride = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); | ||
| 363 | |||
| 364 | const D3D12_RESOURCE_DESC1 unorm_desc = | ||
| 365 | desc1(texture_desc(4, 4, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE)); | ||
| 366 | const DXGI_FORMAT unorm_only[] = {DXGI_FORMAT_R8G8B8A8_UNORM}; | ||
| 367 | Ref<ID3D12Resource> unorm_texture; | ||
| 368 | EXPECT(SUCCEEDED(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &unorm_desc, | ||
| 369 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 1, unorm_only, | ||
| 370 | IID_PPV_ARGS(&unorm_texture.p)))); | ||
| 371 | D3D12_SHADER_RESOURCE_VIEW_DESC srv{}; | ||
| 372 | srv.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; | ||
| 373 | srv.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D; | ||
| 374 | srv.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; | ||
| 375 | srv.Texture2D.MipLevels = 1; | ||
| 376 | device->CreateShaderResourceView(unorm_texture.p, &srv, slot); | ||
| 377 | std::uint32_t words[8]{}; | ||
| 378 | std::memcpy(words, reinterpret_cast<void*>(slot.ptr), sizeof(words)); | ||
| 379 | bool zero = true; | ||
| 380 | for (std::uint32_t word : words) zero = zero && word == 0; | ||
| 381 | EXPECT(zero); | ||
| 382 | |||
| 383 | // The resource's own format is viewable even when the castable list omits it. Vulkan still needs it | ||
| 384 | // in VkImageFormatListCreateInfo, so creation adds it; the default-format SRV must write a descriptor. | ||
| 385 | const DXGI_FORMAT srgb_only[] = {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB}; | ||
| 386 | Ref<ID3D12Resource> self_format_texture; | ||
| 387 | EXPECT(SUCCEEDED(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &unorm_desc, | ||
| 388 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 1, | ||
| 389 | srgb_only, IID_PPV_ARGS(&self_format_texture.p)))); | ||
| 390 | srv.Format = DXGI_FORMAT_R8G8B8A8_UNORM; | ||
| 391 | slot.ptr += stride; | ||
| 392 | device->CreateShaderResourceView(self_format_texture.p, &srv, slot); | ||
| 393 | std::memcpy(words, reinterpret_cast<void*>(slot.ptr), sizeof(words)); | ||
| 394 | bool nonzero = false; | ||
| 395 | for (std::uint32_t word : words) nonzero = nonzero || word != 0; | ||
| 396 | EXPECT(nonzero); | ||
| 397 | |||
| 398 | const D3D12_RESOURCE_DESC1 uint_desc = | ||
| 399 | desc1(texture_desc(4, 4, DXGI_FORMAT_R8G8B8A8_UINT, D3D12_RESOURCE_FLAG_NONE)); | ||
| 400 | const DXGI_FORMAT uint_views[] = {DXGI_FORMAT_R8G8B8A8_UINT, DXGI_FORMAT_R32_UINT}; | ||
| 401 | Ref<ID3D12Resource> uint_texture; | ||
| 402 | EXPECT(SUCCEEDED(device->CreateCommittedResource3(&default_heap, D3D12_HEAP_FLAG_NONE, &uint_desc, | ||
| 403 | D3D12_BARRIER_LAYOUT_COMMON, nullptr, nullptr, 2, uint_views, | ||
| 404 | IID_PPV_ARGS(&uint_texture.p)))); | ||
| 405 | srv.Format = DXGI_FORMAT_R32_UINT; | ||
| 406 | slot.ptr += stride; | ||
| 407 | device->CreateShaderResourceView(uint_texture.p, &srv, slot); | ||
| 408 | std::memcpy(words, reinterpret_cast<void*>(slot.ptr), sizeof(words)); | ||
| 409 | nonzero = false; | ||
| 410 | for (std::uint32_t word : words) nonzero = nonzero || word != 0; | ||
| 411 | EXPECT(nonzero); | ||
| 412 | } | ||
| 413 | |||
| 336 | // A texture from CreateCommittedResource3 (a castable count with a null list, which is no list) is | 414 | // A texture from CreateCommittedResource3 (a castable count with a null list, which is no list) is |
| 337 | // uploaded, copied back and compared on a queue from CreateCommandQueue1. | 415 | // uploaded, copied back and compared on a queue from CreateCommandQueue1. |
| 338 | Ref<ID3D12CommandQueue> queue, queue1; | 416 | Ref<ID3D12CommandQueue> queue, queue1; |