From 5a91ed01eb94bb73fabfc7eb7b4a7795c44413f0 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Fri, 17 Oct 2025 02:54:34 +0300 Subject: [PATCH] vk: Rework the unique resource id system and apply it to buffer views --- rpcs3/Emu/CMakeLists.txt | 1 + rpcs3/Emu/RSX/VK/vkutils/buffer_object.h | 3 ++- rpcs3/Emu/RSX/VK/vkutils/ex.cpp | 14 +++++++++---- rpcs3/Emu/RSX/VK/vkutils/ex.h | 13 ++++++++++++ rpcs3/Emu/RSX/VK/vkutils/image.cpp | 4 ---- rpcs3/Emu/RSX/VK/vkutils/image.h | 5 ++--- rpcs3/Emu/RSX/VK/vkutils/unique_resource.cpp | 11 ++++++++++ rpcs3/Emu/RSX/VK/vkutils/unique_resource.h | 22 ++++++++++++++++++++ rpcs3/VKGSRender.vcxproj | 2 ++ rpcs3/VKGSRender.vcxproj.filters | 6 ++++++ 10 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 rpcs3/Emu/RSX/VK/vkutils/unique_resource.cpp create mode 100644 rpcs3/Emu/RSX/VK/vkutils/unique_resource.h diff --git a/rpcs3/Emu/CMakeLists.txt b/rpcs3/Emu/CMakeLists.txt index 82613c12ff..2fcaf4361f 100644 --- a/rpcs3/Emu/CMakeLists.txt +++ b/rpcs3/Emu/CMakeLists.txt @@ -590,6 +590,7 @@ if(TARGET 3rdparty_vulkan) RSX/VK/vkutils/device.cpp RSX/VK/vkutils/sampler.cpp RSX/VK/vkutils/shared.cpp + RSX/VK/vkutils/unique_resource.cpp RSX/VK/VKAsyncScheduler.cpp RSX/VK/VKCommandStream.cpp RSX/VK/VKCommonDecompiler.cpp diff --git a/rpcs3/Emu/RSX/VK/vkutils/buffer_object.h b/rpcs3/Emu/RSX/VK/vkutils/buffer_object.h index 03f5659e49..3289a3391a 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/buffer_object.h +++ b/rpcs3/Emu/RSX/VK/vkutils/buffer_object.h @@ -3,10 +3,11 @@ #include "../VulkanAPI.h" #include "device.h" #include "memory.h" +#include "unique_resource.h" namespace vk { - struct buffer_view + struct buffer_view : public unique_resource { VkBufferView value; VkBufferViewCreateInfo info = {}; diff --git a/rpcs3/Emu/RSX/VK/vkutils/ex.cpp b/rpcs3/Emu/RSX/VK/vkutils/ex.cpp index 1e4b68c904..45b9fa9acf 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/ex.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/ex.cpp @@ -1,4 +1,5 @@ #include "ex.h" +#include "buffer_object.h" #include "image.h" #include "sampler.h" @@ -6,21 +7,26 @@ namespace vk { VkDescriptorImageInfoEx::VkDescriptorImageInfoEx(const vk::image_view& view, const vk::sampler& sampler, VkImageLayout layout) : VkDescriptorImageInfo(sampler.value, view.value, layout) - , resourceId(view.image()->id()) + , resourceId(view.image()->uid()) {} VkDescriptorImageInfoEx::VkDescriptorImageInfoEx(const vk::image_view& view, const vk::sampler& sampler) : VkDescriptorImageInfo(sampler.value, view.value, view.image()->current_layout) - , resourceId(view.image()->id()) + , resourceId(view.image()->uid()) {} VkDescriptorImageInfoEx::VkDescriptorImageInfoEx(const vk::image_view& view, VkSampler sampler) : VkDescriptorImageInfo(sampler, view.value, view.image()->current_layout) - , resourceId(view.image()->id()) + , resourceId(view.image()->uid()) {} VkDescriptorImageInfoEx::VkDescriptorImageInfoEx(const vk::image_view& view) : VkDescriptorImageInfo(VK_NULL_HANDLE, view.value, view.image()->current_layout) - , resourceId(view.image()->id()) + , resourceId(view.image()->uid()) + {} + + VkDescriptorBufferViewEx::VkDescriptorBufferViewEx(const vk::buffer_view& view) + : resourceId(view.uid()) + , view(view.value) {} } diff --git a/rpcs3/Emu/RSX/VK/vkutils/ex.h b/rpcs3/Emu/RSX/VK/vkutils/ex.h index ee49e7bc55..ed3066718b 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/ex.h +++ b/rpcs3/Emu/RSX/VK/vkutils/ex.h @@ -5,6 +5,7 @@ // Custom extensions to vulkan core namespace vk { + struct buffer_view; struct image_view; struct sampler; @@ -20,8 +21,20 @@ namespace vk VkDescriptorImageInfoEx(const vk::image_view& view, VkSampler sampler); VkDescriptorImageInfoEx(const vk::image_view& view); }; + + struct VkDescriptorBufferViewEx { + u64 resourceId = 0ull; + VkBufferView view = VK_NULL_HANDLE; + + VkDescriptorBufferViewEx() = default; + VkDescriptorBufferViewEx(u64 uid, VkBufferView view) + : resourceId(uid), view(view) + {} + VkDescriptorBufferViewEx(const vk::buffer_view& view); + }; } // Re-export using VkDescriptorImageInfoEx = vk::VkDescriptorImageInfoEx; +using VkDescriptorBufferViewEx = vk::VkDescriptorBufferViewEx; diff --git a/rpcs3/Emu/RSX/VK/vkutils/image.cpp b/rpcs3/Emu/RSX/VK/vkutils/image.cpp index 65ab7f9f16..31499b0ce1 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/image.cpp +++ b/rpcs3/Emu/RSX/VK/vkutils/image.cpp @@ -10,8 +10,6 @@ namespace vk { - static atomic_t s_image_uid_counter = 0; - void image::validate(const vk::render_device& dev, const VkImageCreateInfo& info) const { const auto& gpu_limits = dev.gpu().get_limits(); @@ -121,8 +119,6 @@ namespace vk CHECK_RESULT(vkCreateImage(m_device, &info, nullptr, &value)); - m_uid = s_image_uid_counter++; - VkMemoryRequirements memory_req; vkGetImageMemoryRequirements(m_device, value, &memory_req); diff --git a/rpcs3/Emu/RSX/VK/vkutils/image.h b/rpcs3/Emu/RSX/VK/vkutils/image.h index d7ec263f17..91ebf5616e 100644 --- a/rpcs3/Emu/RSX/VK/vkutils/image.h +++ b/rpcs3/Emu/RSX/VK/vkutils/image.h @@ -6,6 +6,7 @@ #include "commands.h" #include "device.h" #include "memory.h" +#include "unique_resource.h" #include @@ -26,7 +27,7 @@ namespace vk VK_IMAGE_CREATE_SPECIAL_FLAGS_RPCS3 = (VK_IMAGE_CREATE_ALLOW_NULL_RPCS3 | VK_IMAGE_CREATE_SHAREABLE_RPCS3) }; - class image + class image : public unique_resource { std::stack m_layout_stack; VkImageAspectFlags m_storage_aspect = 0; @@ -68,7 +69,6 @@ namespace vk image(image&&) = delete; // Identifiers - u64 id() const { return m_uid; } VkImage handle() const { return value; } // Properties @@ -99,7 +99,6 @@ namespace vk protected: VkDevice m_device = VK_NULL_HANDLE; - u64 m_uid = 0ull; }; struct image_view diff --git a/rpcs3/Emu/RSX/VK/vkutils/unique_resource.cpp b/rpcs3/Emu/RSX/VK/vkutils/unique_resource.cpp new file mode 100644 index 0000000000..2bd60a4a02 --- /dev/null +++ b/rpcs3/Emu/RSX/VK/vkutils/unique_resource.cpp @@ -0,0 +1,11 @@ +#include "unique_resource.h" +#include + +namespace vk +{ + static atomic_t s_resource_uid; + + u64 gen_uid() { + return s_resource_uid++; + } +} diff --git a/rpcs3/Emu/RSX/VK/vkutils/unique_resource.h b/rpcs3/Emu/RSX/VK/vkutils/unique_resource.h new file mode 100644 index 0000000000..6a201cbd2e --- /dev/null +++ b/rpcs3/Emu/RSX/VK/vkutils/unique_resource.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace vk +{ + u64 gen_uid(); + + class unique_resource + { + public: + unique_resource() + : m_uid(gen_uid()) + {} + + u64 uid() const { return m_uid; } + bool operator == (const unique_resource& other) const { return m_uid == other.m_uid; } + + private: + u64 m_uid = 0ull; + }; +} diff --git a/rpcs3/VKGSRender.vcxproj b/rpcs3/VKGSRender.vcxproj index b964e282c1..2b02e062fb 100644 --- a/rpcs3/VKGSRender.vcxproj +++ b/rpcs3/VKGSRender.vcxproj @@ -67,6 +67,7 @@ + @@ -113,6 +114,7 @@ + diff --git a/rpcs3/VKGSRender.vcxproj.filters b/rpcs3/VKGSRender.vcxproj.filters index 143da9a07b..de87d27733 100644 --- a/rpcs3/VKGSRender.vcxproj.filters +++ b/rpcs3/VKGSRender.vcxproj.filters @@ -84,6 +84,9 @@ vkutils + + vkutils + @@ -206,6 +209,9 @@ vkutils + + vkutils +