Merge pull request #1860 from lixonik/fix/title-3d-view-array-range

D3D-3D-VIEW-ARRAY-RANGE: use the single array layer for Vulkan 3D views
This commit is contained in:
aslan2142
2026-11-25 23:02:37 +01:00
committed by GitHub
3 changed files with 35 additions and 6 deletions

View File

@ -4722,12 +4722,10 @@ struct DeviceState {
}
}
view_info.components = g::vulkan_swizzle(swizzle, channels_format);
// The cast: MSVC's enums are ints, and it rejects int to VkImageAspectFlags in braces as narrowing.
view_info.subresourceRange = {
VkImageAspectFlags(stencil ? VK_IMAGE_ASPECT_STENCIL_BIT
: (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) ? VK_IMAGE_ASPECT_DEPTH_BIT
: VK_IMAGE_ASPECT_COLOR_BIT),
image.first_mip, image.mip_count, image.first_layer, image.layer_count};
view_info.subresourceRange = g::vulkan_subresource_range(
image, stencil ? VK_IMAGE_ASPECT_STENCIL_BIT
: (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) ? VK_IMAGE_ASPECT_DEPTH_BIT
: VK_IMAGE_ASPECT_COLOR_BIT);
ImageEntry entry{dimension, 0, VK_NULL_HANDLE, VK_NULL_HANDLE, image.address};
if (sampled) {
const VkResult result = vk.vkCreateImageView(info.device, &view_info, nullptr, &entry.sampled);
@ -10377,6 +10375,8 @@ TitleImage bind_title_image(DeviceState& device, const leonida::gfx10::ImageWord
std::lock_guard lock(device.descriptor_mutex);
if (!device.bindless) return refuse("no bindless set");
if (device.image_entries.count(words)) return TitleImage::known;
if (g::has_hardware_volume_uav_slice_offset(words, image))
return refuse("a title-written 3D UAV with a slice offset is not supported");
auto found = device.images_by_address.find(image.address);
// Memory of the texture stream pool has two addresses, the CPU view's and the GPU-only alias the title hands
// to the GPU (title_gpu_views): a T# naming either finds a texture registered under the other.

View File

@ -236,6 +236,16 @@ inline constexpr VkImageViewType vulkan_view_type(ImageType type) {
}
}
inline constexpr VkImageSubresourceRange vulkan_subresource_range(const Image& image, VkImageAspectFlags aspects) {
const bool volume = image.type == ImageType::image_3d;
return {aspects, image.first_mip, image.mip_count, volume ? 0u : image.first_layer,
volume ? 1u : image.layer_count};
}
inline constexpr bool has_hardware_volume_uav_slice_offset(const ImageWords& words, const Image& image) {
return image.type == ImageType::image_3d && image.first_layer != 0 && detail::get(words[5], 0, 4) == 1;
}
// ---- formats ----
// One row for each Vulkan format: its GFX10_FORMAT code, and the DST_SEL that reads its channels as R, G, B, A

View File

@ -114,6 +114,25 @@ int main() {
CHECK(is_image(words) && decode(words, out) && out == in);
}
ImageWords volume_words = encode(Image{.type = ImageType::image_3d, .depth = 16,
.first_mip = 1, .mip_count = 2, .resource_mips = 4});
volume_words[4] |= 37u << 16;
CHECK(decode(volume_words, image) && image.first_layer == 37 && image.depth == 16);
CHECK(!has_hardware_volume_uav_slice_offset(volume_words, image));
const auto volume_range = vulkan_subresource_range(image, VK_IMAGE_ASPECT_COLOR_BIT);
CHECK(volume_range.aspectMask == VK_IMAGE_ASPECT_COLOR_BIT);
CHECK(volume_range.baseMipLevel == 1 && volume_range.levelCount == 2);
CHECK(volume_range.baseArrayLayer == 0 && volume_range.layerCount == 1);
volume_words = encode(Image{.type = ImageType::image_3d, .depth = 7, .first_mip = 1, .resource_mips = 4});
volume_words[4] |= 2u << 16;
volume_words[5] |= 1u;
CHECK(decode(volume_words, image) && has_hardware_volume_uav_slice_offset(volume_words, image));
volume_words[4] &= 0xffffu;
CHECK(decode(volume_words, image) && !has_hardware_volume_uav_slice_offset(volume_words, image));
const auto array_range = vulkan_subresource_range(images[2], VK_IMAGE_ASPECT_COLOR_BIT);
CHECK(array_range.baseArrayLayer == 3 && array_range.layerCount == 7);
// Bits this header does not encode are ignored: SW_MODE and BC_SWIZZLE (word 3), PITCH_MSB (word 4), PERF_MOD
// and the rest of word 5, the compression and metadata fields of words 6 and 7, RESOURCE_LEVEL (word 2 bit 31).
ImageWords busy = encode(images[3]);