From da2caa08816494bcea4473df95edf6d67613133b Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Mon, 14 Mar 2016 19:52:00 +0100 Subject: [PATCH] vulkan: precompute memory type mapping. --- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 2 ++ rpcs3/Emu/RSX/VK/VKGSRender.h | 1 + rpcs3/Emu/RSX/VK/VKHelpers.cpp | 25 +++++++++++++++++++++++++ rpcs3/Emu/RSX/VK/VKHelpers.h | 8 ++++++++ 4 files changed, 36 insertions(+) diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index c2ed6669f0..998597d4e7 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -167,6 +167,8 @@ VKGSRender::VKGSRender() : GSRender(frame_type::Vulkan) m_device = (vk::render_device *)(&m_swap_chain->get_device()); + m_memory_type_mapping = get_memory_mapping(m_device->gpu()); + m_optimal_tiling_supported_formats = vk::get_optimal_tiling_supported_formats(m_device->gpu()); vk::set_current_thread_ctx(m_thread_context); diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.h b/rpcs3/Emu/RSX/VK/VKGSRender.h index a7a30a537f..5ebd6f5f93 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.h +++ b/rpcs3/Emu/RSX/VK/VKGSRender.h @@ -29,6 +29,7 @@ private: rsx::vk_render_targets m_rtts; vk::gpu_formats_support m_optimal_tiling_supported_formats; + vk::memory_type_mapping m_memory_type_mapping; public: //vk::fbo draw_fbo; diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.cpp b/rpcs3/Emu/RSX/VK/VKHelpers.cpp index d8c95bf616..8090a3f5a0 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.cpp +++ b/rpcs3/Emu/RSX/VK/VKHelpers.cpp @@ -35,6 +35,31 @@ namespace vk #endif } + memory_type_mapping get_memory_mapping(VkPhysicalDevice pdev) + { + VkPhysicalDeviceMemoryProperties memory_properties; + vkGetPhysicalDeviceMemoryProperties(pdev, &memory_properties); + + memory_type_mapping result; + result.device_local = VK_MAX_MEMORY_TYPES; + result.host_visible_coherent = VK_MAX_MEMORY_TYPES; + + for (int i = 0; i < VK_MAX_MEMORY_TYPES; i++) + { + bool is_device_local = !!(memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT); + if (is_device_local) + result.device_local = i; + bool is_host_visible = !!(memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT); + bool is_host_coherent = !!(memory_properties.memoryTypes[i].propertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT); + if (is_host_coherent && is_host_visible) + result.host_visible_coherent = i; + } + + if (result.device_local == VK_MAX_MEMORY_TYPES) throw EXCEPTION("GPU doesn't support device local memory"); + if (result.host_visible_coherent == VK_MAX_MEMORY_TYPES) throw EXCEPTION("GPU doesn't support host coherent device local memory"); + return result; + } + VkFormat get_compatible_sampler_format(u32 format, VkComponentMapping& swizzle, u8 swizzle_mask) { u8 remap_a = swizzle_mask & 0x3; diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 1d10e15e85..627aef0c39 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -69,6 +69,14 @@ namespace vk VkFormat get_compatible_sampler_format(u32 format, VkComponentMapping& mapping, u8 swizzle_mask=0); VkFormat get_compatible_surface_format(rsx::surface_color_format color_format); + struct memory_type_mapping + { + uint32_t host_visible_coherent; + uint32_t device_local; + }; + + memory_type_mapping get_memory_mapping(VkPhysicalDevice pdev); + class physical_device { VkPhysicalDevice dev = nullptr;