graphics: migrate Vulkan backend to Vulkan-Hpp

This commit is contained in:
nmzik committed 2026-07-18 12:33:21 +02:00
1 parent 587cb238f0
commit 7905f2d12f
64 files changed
+4842 -4518

No files matched your search

+39 -40
View File
@@ -251,7 +251,7 @@ VulkanImage* TextureCache::PublishImage(CommandBuffer* command,
image != nullptr ? static_cast<const void*>(image->image) : nullptr,
image != nullptr && image->registered);
}
auto* result = image->image;
auto result = image->image;
command->RetainResourceUntilFence(image);
m_images.push_back(std::move(image));
RegisterImageLocked(*m_images.back());
@@ -397,10 +397,10 @@ struct TextureCache::ReadbackWorker {
size <= info.address + info.size - vaddr;
const bool d16 =
info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm) &&
info.format == VK_FORMAT_D16_UNORM && info.bytes_per_element == 2;
info.format == vk::Format::eD16Unorm && info.bytes_per_element == 2;
const bool d32 =
info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) &&
info.format == VK_FORMAT_D32_SFLOAT && info.bytes_per_element == 4;
info.format == vk::Format::eD32Sfloat && info.bytes_per_element == 4;
TileSizeAlign expected_stencil {};
TileSizeAlign expected_htile {};
TileSizeAlign expected_depth {};
@@ -466,7 +466,7 @@ struct TextureCache::ReadbackWorker {
std::fill(download.begin(), download.end(), 0);
const auto regions =
MakeLayeredImageBufferCopies(info.layers, slice_size, info.pitch, info.width,
info.height, VK_IMAGE_ASPECT_DEPTH_BIT);
info.height, vk::ImageAspectFlagBits::eDepth);
UtilFillBuffer(cached.ctx, download.data(), info.size, regions, cached.image,
cached.image->layout);
guest.resize(info.size);
@@ -820,7 +820,7 @@ bool Equal(const DepthTargetInfo& left, const DepthTargetInfo& right) {
}
void AppendLayerCopies(std::vector<ImageImageCopy>& regions, VulkanImage* source,
VkImageAspectFlags aspect) {
vk::ImageAspectFlags aspect) {
for (uint32_t layer = 0; layer < source->layers; layer++) {
for (uint32_t level = 0; level < source->mip_levels; level++) {
ImageImageCopy region {};
@@ -1060,7 +1060,7 @@ void TextureCache::RetireStorageDepthAliasLocked(GraphicContext* ctx, const Imag
cached.ctx == ctx && cached.gpu_modified && !cached.buffer_modified &&
depth.address == requested.address && depth.size == requested.size &&
depth.stencil_address == 0 && depth.stencil_size == 0 && depth.htile_address == 0 &&
depth.htile_size == 0 && depth.layers == 1 && depth.format == VK_FORMAT_D32_SFLOAT &&
depth.htile_size == 0 && depth.layers == 1 && depth.format == vk::Format::eD32Sfloat &&
depth.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) &&
depth.bytes_per_element == 4 && depth.width == requested.width &&
depth.height == requested.height && depth.pitch == requested.pitch &&
@@ -1265,7 +1265,7 @@ VulkanImage* TextureCache::FindTexture(CommandBuffer* command, GraphicContext* c
cached->kind = CachedImage::Kind::Texture;
cached->info = info;
cached->ctx = ctx;
VkComponentMapping components {};
vk::ComponentMapping components {};
cached->image = ImageOps::CreateTexture(ctx, info, false, &cached->memory, &components);
m_memory_tracker.ForEachUploadRange(
info.address, info.size, false, [](uint64_t, uint64_t) noexcept {},
@@ -1401,7 +1401,7 @@ StorageTextureVulkanImage* TextureCache::FindStorageTexture(CommandBuffer* com
cached->kind = CachedImage::Kind::StorageTexture;
cached->info = info;
cached->ctx = ctx;
VkComponentMapping components {};
vk::ComponentMapping components {};
cached->image = ImageOps::CreateTexture(ctx, info, true, &cached->memory, &components);
m_memory_tracker.ForEachUploadRange(
info.address, info.size, true, [](uint64_t, uint64_t) noexcept {},
@@ -1420,7 +1420,7 @@ RenderTextureVulkanImage* TextureCache::FindRenderTarget(CommandBuffer*
const RenderTargetInfo& info) {
const bool standard64 = IsSupportedStandard64RenderTarget(info);
if (info.address == 0 || info.size == 0 || info.address >= TRACKER_ADDRESS_SIZE ||
info.size > TRACKER_ADDRESS_SIZE - info.address || info.format == VK_FORMAT_UNDEFINED ||
info.size > TRACKER_ADDRESS_SIZE - info.address || info.format == vk::Format::eUndefined ||
info.width == 0 || info.height == 0 || info.pitch < info.width ||
info.bytes_per_element == 0 || info.levels == 0 || info.levels > 16 || info.layers == 0 ||
info.size % info.layers != 0 ||
@@ -1635,9 +1635,8 @@ RenderTextureVulkanImage* TextureCache::FindRenderTarget(CommandBuffer*
std::vector<ImageImageCopy> regions;
regions.reserve(static_cast<size_t>(native_image_source->image->layers) *
native_image_source->image->mip_levels);
AppendLayerCopies(regions, native_image_source->image, VK_IMAGE_ASPECT_COLOR_BIT);
UtilImageToImage(command, regions, cached->image,
static_cast<uint64_t>(RENDER_COLOR_IMAGE_LAYOUT));
AppendLayerCopies(regions, native_image_source->image, vk::ImageAspectFlagBits::eColor);
UtilImageToImage(command, regions, cached->image, RENDER_COLOR_IMAGE_LAYOUT);
} else {
m_memory_tracker.ForEachUploadRange(
info.address, info.size, false, [](uint64_t, uint64_t) noexcept {},
@@ -1935,12 +1934,13 @@ DepthStencilVulkanImage* TextureCache::FindDepthTarget(CommandBuffer* command, G
}
std::vector<ImageImageCopy> regions;
regions.reserve(native_depth_source->image->layers * (has_stencil ? 2u : 1u));
AppendLayerCopies(regions, native_depth_source->image, VK_IMAGE_ASPECT_DEPTH_BIT);
AppendLayerCopies(regions, native_depth_source->image, vk::ImageAspectFlagBits::eDepth);
if (has_stencil) {
AppendLayerCopies(regions, native_depth_source->image, VK_IMAGE_ASPECT_STENCIL_BIT);
AppendLayerCopies(regions, native_depth_source->image,
vk::ImageAspectFlagBits::eStencil);
}
UtilImageToImage(command, regions, cached->image,
static_cast<uint64_t>(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
vk::ImageLayout::eDepthStencilAttachmentOptimal);
cached->gpu_modified = true;
} else {
if (sampled_depth_source != nullptr &&
@@ -1967,11 +1967,11 @@ DepthStencilVulkanImage* TextureCache::FindDepthTarget(CommandBuffer* command, G
break;
case DepthTransitionSource::Native:
command->RetainResourceUntilFence(sampled_depth_source);
UtilCopyImageWithBuffer(
command, ctx, sampled_depth_source->image, VK_IMAGE_ASPECT_COLOR_BIT,
cached->image, VK_IMAGE_ASPECT_DEPTH_BIT, info.bytes_per_element,
static_cast<uint64_t>(
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL));
UtilCopyImageWithBuffer(command, ctx, sampled_depth_source->image,
vk::ImageAspectFlagBits::eColor, cached->image,
vk::ImageAspectFlagBits::eDepth,
info.bytes_per_element,
vk::ImageLayout::eDepthStencilAttachmentOptimal);
break;
}
});
@@ -2269,18 +2269,17 @@ bool TextureCache::ClearImageFromBuffer(CommandBuffer* command, uint64_t vaddr,
image_cpu_modified);
}
auto* vk_buffer = command->GetPool()->buffers[command->GetIndex()];
auto vk_buffer = command->GetPool()->buffers[command->GetIndex()];
if (aspect == ClearAspect::Color) {
VkClearColorValue clear {};
vk::ClearColorValue clear {};
if (!DecodePackedColorClear(match->image->format, packed_clear, &clear)) {
return false;
}
GraphicsRenderColorImageBarrier(vk_buffer, match->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
const VkImageSubresourceRange range {VK_IMAGE_ASPECT_COLOR_BIT, 0, VK_REMAINING_MIP_LEVELS,
0, match->image->layers};
vkCmdClearColorImage(vk_buffer, match->image->image, match->image->layout, &clear, 1,
&range);
vk::ImageLayout::eTransferDstOptimal);
const vk::ImageSubresourceRange range {vk::ImageAspectFlagBits::eColor, 0,
VK_REMAINING_MIP_LEVELS, 0, match->image->layers};
vk_buffer.clearColorImage(match->image->image, match->image->layout, &clear, 1, &range);
GraphicsRenderColorImageBarrier(vk_buffer, match->image, RENDER_COLOR_IMAGE_LAYOUT);
if (!match->gpu_modified) {
m_memory_tracker.MarkRegionAsGpuModified(vaddr, size);
@@ -2290,22 +2289,22 @@ bool TextureCache::ClearImageFromBuffer(CommandBuffer* command, uint64_t vaddr,
return true;
}
if (match->image->layout == VK_IMAGE_LAYOUT_UNDEFINED ||
match->image->layout == VK_IMAGE_LAYOUT_PREINITIALIZED) {
if (match->image->layout == vk::ImageLayout::eUndefined ||
match->image->layout == vk::ImageLayout::ePreinitialized) {
EXIT("TextureCache: compute %s clear has invalid source layout %u\n",
aspect == ClearAspect::Depth ? "depth" : "stencil",
static_cast<uint32_t>(match->image->layout));
}
const auto old_layout = match->image->layout;
GraphicsRenderDepthStencilImageBarrier(vk_buffer, match->image,
VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
const VkClearDepthStencilValue clear {depth_clear, stencil_clear};
const auto clear_aspect = static_cast<VkImageAspectFlags>(
aspect == ClearAspect::Depth ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_STENCIL_BIT);
const VkImageSubresourceRange range {clear_aspect, 0, VK_REMAINING_MIP_LEVELS, 0,
match->image->layers};
vkCmdClearDepthStencilImage(vk_buffer, match->image->image, match->image->layout, &clear, 1,
&range);
vk::ImageLayout::eTransferDstOptimal);
const vk::ClearDepthStencilValue clear {depth_clear, stencil_clear};
const auto clear_aspect = static_cast<vk::ImageAspectFlags>(
aspect == ClearAspect::Depth ? vk::ImageAspectFlagBits::eDepth
: vk::ImageAspectFlagBits::eStencil);
const vk::ImageSubresourceRange range {clear_aspect, 0, VK_REMAINING_MIP_LEVELS, 0,
match->image->layers};
vk_buffer.clearDepthStencilImage(match->image->image, match->image->layout, &clear, 1, &range);
GraphicsRenderDepthStencilImageBarrier(vk_buffer, match->image, old_layout);
if (aspect == ClearAspect::Stencil) {
match->stencil_initialized = true;
@@ -2575,10 +2574,10 @@ void TextureCache::SynchronizeDepthImageToBufferLocked(CachedImage& cached, uint
TileSizeAlign expected_depth {};
const bool d16 =
info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k16UNorm) &&
info.format == VK_FORMAT_D16_UNORM && info.bytes_per_element == 2;
info.format == vk::Format::eD16Unorm && info.bytes_per_element == 2;
const bool d32 =
info.guest_format == Prospero::GpuEnumValue(Prospero::BufferFormat::k32Float) &&
info.format == VK_FORMAT_D32_SFLOAT && info.bytes_per_element == 4;
info.format == vk::Format::eD32Sfloat && info.bytes_per_element == 4;
const bool layout =
(d16 || d32) &&
TileGetDepthSize(info.width, info.height, 0,
@@ -2604,7 +2603,7 @@ void TextureCache::SynchronizeDepthImageToBufferLocked(CachedImage& cached, uint
m_buffer_transition_linear.resize(info.size);
std::fill(m_buffer_transition_linear.begin(), m_buffer_transition_linear.end(), 0);
const auto regions = MakeLayeredImageBufferCopies(1, info.size, info.pitch, info.width,
info.height, VK_IMAGE_ASPECT_DEPTH_BIT);
info.height, vk::ImageAspectFlagBits::eDepth);
UtilFillBuffer(cached.ctx, m_buffer_transition_linear.data(), info.size, regions, cached.image,
cached.image->layout);
m_buffer_transition_guest.resize(info.size);