diff options
| author | requiemsnkrp <317543573 +requiemsnkrp@users.noreply.github.com> | 2026-11-22 16:48:45 +0100 |
|---|---|---|
| committer | requiemsnkrp <317543573 +requiemsnkrp@users.noreply.github.com> | 2026-11-22 16:48:45 +0100 |
| commit | c48a39d2d07f26ae95ed1fd84594f4cfbd2a987d (patch) | |
| tree | 4bfab96aaa38af4501a6adb1e5b7ddeee815e080 /runtime/src | |
| parent | 4eb6155d3ac4f9d3fadb0d095c4ce13e76783615 (diff) | |
D3D-275: typed RTVs of every typeless color family
- ColorViewFormat now holds the view's VkFormat number (the RGBA8 names keep their values), and
CreateRenderTargetView accepts any typed format of a TYPELESS color texture's family (B8G8R8A8 and
B8G8R8X8 kept apart), not only RGBA8.
- ResourceBinding::rgba8_typeless becomes typeless (any TYPELESS color resource); color_view_format accepts a
format of the resource's family (typeless_view_family, R8 included for when it is mapped), so clears go
through a view in the RTV's format. Attachment views of every typeless image ask for color-attachment usage
only.
- d3d12_typeless_families_test: every typed RTV format of each family, two clear values, bytes compared with
the host D3D12 on the same adapter (LUID) and reported against WARP.
- docs/d3d12_vulkan.md: the typeless RTV section.
AI-assisted.
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/command_list.h | 7 | ||||
| -rw-r--r-- | runtime/src/vulkan_backend.h | 4 | ||||
| -rw-r--r-- | runtime/src/vulkan_replay.h | 52 |
3 files changed, 42 insertions, 21 deletions
diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index 07520c2e3..fce4ab9f0 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h | |||
| @@ -150,8 +150,11 @@ inline constexpr std::uint32_t clear_depth = 0x1; | |||
| 150 | inline constexpr std::uint32_t clear_stencil = 0x2; | 150 | inline constexpr std::uint32_t clear_stencil = 0x2; |
| 151 | inline constexpr std::uint32_t texture_barrier_discard = 0x1; | 151 | inline constexpr std::uint32_t texture_barrier_discard = 0x1; |
| 152 | 152 | ||
| 153 | // Portable color-view interpretation. Other views inherit their resource format as before. | 153 | // The format a color view names, as a VkFormat number (0, `resource`, is the resource's own). The named values are |
| 154 | enum class ColorViewFormat : std::uint32_t { resource, rgba8_unorm, rgba8_srgb, rgba8_uint, rgba8_sint, rgba8_snorm }; | 154 | // the RGBA8 family's; a typeless resource of any other family stores its view's VkFormat the same way (D3D-275). |
| 155 | enum class ColorViewFormat : std::uint32_t { | ||
| 156 | resource = 0, rgba8_unorm = 37, rgba8_snorm = 38, rgba8_uint = 41, rgba8_sint = 42, rgba8_srgb = 43 | ||
| 157 | }; | ||
| 155 | 158 | ||
| 156 | // D3D12_QUERY_HEAP_TYPE and D3D12_QUERY_TYPE. | 159 | // D3D12_QUERY_HEAP_TYPE and D3D12_QUERY_TYPE. |
| 157 | namespace d3d12_query_heap { | 160 | namespace d3d12_query_heap { |
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 8683ae2de..79be8805c 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -1113,10 +1113,10 @@ private: | |||
| 1113 | info.format = r.format; | 1113 | info.format = r.format; |
| 1114 | info.subresourceRange = range; | 1114 | info.subresourceRange = range; |
| 1115 | // Attachment views need only color-attachment usage. Inheriting STORAGE usage from a mutable/extended | 1115 | // Attachment views need only color-attachment usage. Inheriting STORAGE usage from a mutable/extended |
| 1116 | // resource (typeless RGBA8 sRGB views, or R32_UINT-backed R9G9B9E5 UAV images) would require unrelated usages. | 1116 | // resource (typeless views such as RGBA8 sRGB, or R32_UINT-backed R9G9B9E5 UAV images) would require unrelated usages. |
| 1117 | VkImageViewUsageCreateInfo usage{VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO}; | 1117 | VkImageViewUsageCreateInfo usage{VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO}; |
| 1118 | usage.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; | 1118 | usage.usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; |
| 1119 | if (r.rgba8_typeless || (range.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT && r.color_attachment)) | 1119 | if (r.typeless || (range.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT && r.color_attachment)) |
| 1120 | info.pNext = &usage; | 1120 | info.pNext = &usage; |
| 1121 | VkImageView view = VK_NULL_HANDLE; | 1121 | VkImageView view = VK_NULL_HANDLE; |
| 1122 | if (vk.vkCreateImageView(device_, &info, nullptr, &view) != VK_SUCCESS) return VK_NULL_HANDLE; | 1122 | if (vk.vkCreateImageView(device_, &info, nullptr, &view) != VK_SUCCESS) return VK_NULL_HANDLE; |
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 2a37f58f5..b85140b04 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h | |||
| @@ -74,7 +74,7 @@ struct ResourceBinding { | |||
| 74 | std::uint32_t depth = 1; | 74 | std::uint32_t depth = 1; |
| 75 | bool volume = false; // one array layer, including at mips with a single slice | 75 | bool volume = false; // one array layer, including at mips with a single slice |
| 76 | std::uint32_t samples = 1; // more than one: a multisampled 2D texture | 76 | std::uint32_t samples = 1; // more than one: a multisampled 2D texture |
| 77 | bool rgba8_typeless = false; // Original resource was R8G8B8A8_TYPELESS; views may reinterpret it. | 77 | bool typeless = false; // A TYPELESS color resource: views name a format of its family (D3D-275). |
| 78 | bool castable_view_formats = false; // A creation-time castable list made the image mutable (D3D-85/D3D-90), | 78 | bool castable_view_formats = false; // A creation-time castable list made the image mutable (D3D-85/D3D-90), |
| 79 | // so views may reinterpret it as typeless resources do. | 79 | // so views may reinterpret it as typeless resources do. |
| 80 | // D24_UNORM_S8_UINT stored as D32_SFLOAT_S8_UINT (the GPU has no D24): footprint copies of the depth plane convert | 80 | // D24_UNORM_S8_UINT stored as D32_SFLOAT_S8_UINT (the GPU has no D24): footprint copies of the depth plane convert |
| @@ -960,24 +960,42 @@ inline VkClearColorValue render_target_clear_color(VkFormat format, const ClearC | |||
| 960 | return value; | 960 | return value; |
| 961 | } | 961 | } |
| 962 | 962 | ||
| 963 | // Only the RGBA8 family is explicitly reinterpreted here. Legacy views retain their resource format. A typeless | 963 | // The DXGI typeless family a color view format belongs to, by the Vulkan formats the layer maps its members to: the |
| 964 | // resource or one created with a castable-format list (its image is mutable and lists the view formats) may be | 964 | // same nonzero number for formats one typeless resource can be viewed as, 0 for a format of no such family. |
| 965 | // reinterpreted; the reinterpretation itself is the UNORM image's. | 965 | inline int typeless_view_family(VkFormat format) { |
| 966 | switch (format) { | ||
| 967 | case VK_FORMAT_R8G8B8A8_UNORM: case VK_FORMAT_R8G8B8A8_SRGB: case VK_FORMAT_R8G8B8A8_SNORM: | ||
| 968 | case VK_FORMAT_R8G8B8A8_UINT: case VK_FORMAT_R8G8B8A8_SINT: return 1; | ||
| 969 | case VK_FORMAT_B8G8R8A8_UNORM: case VK_FORMAT_B8G8R8A8_SRGB: return 2; | ||
| 970 | case VK_FORMAT_R16G16B16A16_SFLOAT: case VK_FORMAT_R16G16B16A16_UNORM: case VK_FORMAT_R16G16B16A16_SNORM: | ||
| 971 | case VK_FORMAT_R16G16B16A16_UINT: case VK_FORMAT_R16G16B16A16_SINT: return 3; | ||
| 972 | case VK_FORMAT_R32G32B32A32_SFLOAT: case VK_FORMAT_R32G32B32A32_UINT: case VK_FORMAT_R32G32B32A32_SINT: return 4; | ||
| 973 | case VK_FORMAT_R32G32_SFLOAT: case VK_FORMAT_R32G32_UINT: case VK_FORMAT_R32G32_SINT: return 5; | ||
| 974 | case VK_FORMAT_R16G16_SFLOAT: case VK_FORMAT_R16G16_UNORM: case VK_FORMAT_R16G16_SNORM: | ||
| 975 | case VK_FORMAT_R16G16_UINT: case VK_FORMAT_R16G16_SINT: return 6; | ||
| 976 | case VK_FORMAT_A2B10G10R10_UNORM_PACK32: case VK_FORMAT_A2B10G10R10_UINT_PACK32: return 7; | ||
| 977 | case VK_FORMAT_R8G8_UNORM: case VK_FORMAT_R8G8_SNORM: case VK_FORMAT_R8G8_UINT: case VK_FORMAT_R8G8_SINT: return 8; | ||
| 978 | case VK_FORMAT_R32_SFLOAT: case VK_FORMAT_R32_UINT: case VK_FORMAT_R32_SINT: return 9; | ||
| 979 | case VK_FORMAT_R16_SFLOAT: case VK_FORMAT_R16_UNORM: case VK_FORMAT_R16_SNORM: case VK_FORMAT_R16_UINT: | ||
| 980 | case VK_FORMAT_R16_SINT: return 10; | ||
| 981 | case VK_FORMAT_R8_UNORM: case VK_FORMAT_R8_SNORM: case VK_FORMAT_R8_UINT: case VK_FORMAT_R8_SINT: return 11; | ||
| 982 | default: return 0; | ||
| 983 | } | ||
| 984 | } | ||
| 985 | |||
| 986 | // The format a color view clears or renders in. A view of the resource's own format keeps it (a typeless resource | ||
| 987 | // has none, so it needs an explicit one). A typeless resource, or one created with a castable-format list (its image | ||
| 988 | // is mutable and lists the view formats), may be viewed in another format of its family: the image is mutable, so | ||
| 989 | // the view reinterprets its bits (D3D-275; before it only the RGBA8 family was). A volume keeps its own format. | ||
| 966 | inline VkFormat color_view_format(const ResourceBinding& resource, const TargetView& target) { | 990 | inline VkFormat color_view_format(const ResourceBinding& resource, const TargetView& target) { |
| 967 | if (target.format == ColorViewFormat::resource) | 991 | if (target.format == ColorViewFormat::resource) |
| 968 | return resource.rgba8_typeless ? VK_FORMAT_UNDEFINED : resource.format; | 992 | return resource.typeless ? VK_FORMAT_UNDEFINED : resource.format; |
| 969 | VkFormat format = VK_FORMAT_UNDEFINED; | 993 | const auto format = static_cast<VkFormat>(target.format); |
| 970 | switch (target.format) { | 994 | const int family = typeless_view_family(format); |
| 971 | case ColorViewFormat::rgba8_unorm: format = VK_FORMAT_R8G8B8A8_UNORM; break; | 995 | if (!family) return VK_FORMAT_UNDEFINED; |
| 972 | case ColorViewFormat::rgba8_srgb: format = VK_FORMAT_R8G8B8A8_SRGB; break; | 996 | if (!resource.typeless && !resource.castable_view_formats) |
| 973 | case ColorViewFormat::rgba8_uint: format = VK_FORMAT_R8G8B8A8_UINT; break; | ||
| 974 | case ColorViewFormat::rgba8_sint: format = VK_FORMAT_R8G8B8A8_SINT; break; | ||
| 975 | case ColorViewFormat::rgba8_snorm: format = VK_FORMAT_R8G8B8A8_SNORM; break; | ||
| 976 | default: return VK_FORMAT_UNDEFINED; | ||
| 977 | } | ||
| 978 | if (!resource.rgba8_typeless && !resource.castable_view_formats) | ||
| 979 | return format == resource.format ? format : VK_FORMAT_UNDEFINED; | 997 | return format == resource.format ? format : VK_FORMAT_UNDEFINED; |
| 980 | if (resource.format != VK_FORMAT_R8G8B8A8_UNORM || resource.volume || resource.depth != 1) | 998 | if (family != typeless_view_family(resource.format) || resource.volume || resource.depth != 1) |
| 981 | return VK_FORMAT_UNDEFINED; | 999 | return VK_FORMAT_UNDEFINED; |
| 982 | return format; | 1000 | return format; |
| 983 | } | 1001 | } |
| @@ -2081,7 +2099,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2081 | // Older ownerless replay callers omit the resource format for float-only clears. Preserve | 2099 | // Older ownerless replay callers omit the resource format for float-only clears. Preserve |
| 2082 | // that path; an explicit format or a typeless resource must still resolve a concrete RTV. | 2100 | // that path; an explicit format or a typeless resource must still resolve a concrete RTV. |
| 2083 | if (p.clear_format == VK_FORMAT_UNDEFINED && | 2101 | if (p.clear_format == VK_FORMAT_UNDEFINED && |
| 2084 | (p.binding.rgba8_typeless || color_clear->target.format != ColorViewFormat::resource)) | 2102 | (p.binding.typeless || color_clear->target.format != ColorViewFormat::resource)) |
| 2085 | return ReplayResult::invalid_clear; | 2103 | return ReplayResult::invalid_clear; |
| 2086 | const bool partial_volume = p.binding.volume && | 2104 | const bool partial_volume = p.binding.volume && |
| 2087 | color_clear->target.layer_count != std::max(1u, p.binding.depth >> color_clear->target.mip); | 2105 | color_clear->target.layer_count != std::max(1u, p.binding.depth >> color_clear->target.mip); |