From 26ff4fd6b7e7085c31681b1a115f92b2cc5e28c2 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Fri, 11 Mar 2016 20:38:30 +0100 Subject: [PATCH 1/2] vulkan: Uses debug output setting to enable debug layers. --- rpcs3/Emu/RSX/VK/VKHelpers.h | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 2842096933..6d27655e5f 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -11,12 +11,10 @@ #include #include +#include "Emu/state.h" #include "VulkanAPI.h" #include "../GCM.h" -//Set to 9 to enable all debug layers. Will cause significant slowdowns. Eventually to be replaced with GUI checkbox -#define VK_ENABLED_LAYER_COUNT 0 - namespace rsx { class texture; @@ -166,22 +164,18 @@ namespace vk "VK_KHR_swapchain" }; - const char *validation_layers[] = - { - "VK_LAYER_LUNARG_threading", "VK_LAYER_LUNARG_mem_tracker", - "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_draw_state", - "VK_LAYER_LUNARG_param_checker", "VK_LAYER_LUNARG_swapchain", - "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_image", - "VK_LAYER_GOOGLE_unique_objects", - }; + std::vector layers; + + if (rpcs3::config.rsx.d3d12.debug_output.value()) + layers.push_back("VK_LAYER_LUNARG_standard_validation"); VkDeviceCreateInfo device; device.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; device.pNext = NULL; device.queueCreateInfoCount = 1; device.pQueueCreateInfos = &queue; - device.enabledLayerCount = VK_ENABLED_LAYER_COUNT; - device.ppEnabledLayerNames = validation_layers; + device.enabledLayerCount = layers.size(); + device.ppEnabledLayerNames = layers.data(); device.enabledExtensionCount = 1; device.ppEnabledExtensionNames = requested_extensions; device.pEnabledFeatures = nullptr; @@ -1011,21 +1005,17 @@ namespace vk "VK_EXT_debug_report", }; - const char *validation_layers[] = - { - "VK_LAYER_LUNARG_threading", "VK_LAYER_LUNARG_mem_tracker", - "VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_draw_state", - "VK_LAYER_LUNARG_param_checker", "VK_LAYER_LUNARG_swapchain", - "VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_image", - "VK_LAYER_GOOGLE_unique_objects", - }; + std::vector layers; + + if (rpcs3::config.rsx.d3d12.debug_output.value()) + layers.push_back("VK_LAYER_LUNARG_standard_validation"); VkInstanceCreateInfo instance_info; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_info.pNext = nullptr; instance_info.pApplicationInfo = &app; - instance_info.enabledLayerCount = VK_ENABLED_LAYER_COUNT; - instance_info.ppEnabledLayerNames = validation_layers; + instance_info.enabledLayerCount = layers.size(); + instance_info.ppEnabledLayerNames = layers.data(); instance_info.enabledExtensionCount = 3; instance_info.ppEnabledExtensionNames = requested_extensions; From 8604f5a02f48f2381743753b33d2b01b23f11ac1 Mon Sep 17 00:00:00 2001 From: Vincent Lejeune Date: Sat, 12 Mar 2016 01:13:30 +0100 Subject: [PATCH 2/2] vulkan: Use d24_u8 or d32_u8 depending on hw support. --- rpcs3/Emu/RSX/VK/VKFormats.cpp | 42 ++++++++++++++++++++++++++++++ rpcs3/Emu/RSX/VK/VKFormats.h | 14 ++++++++++ rpcs3/Emu/RSX/VK/VKGSRender.cpp | 19 +++++--------- rpcs3/Emu/RSX/VK/VKGSRender.h | 3 +++ rpcs3/Emu/RSX/VK/VKHelpers.h | 1 - rpcs3/Emu/RSX/VK/VKRenderTargets.h | 12 +++++---- rpcs3/VKGSRender.vcxproj | 2 ++ rpcs3/VKGSRender.vcxproj.filters | 6 +++++ 8 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 rpcs3/Emu/RSX/VK/VKFormats.cpp create mode 100644 rpcs3/Emu/RSX/VK/VKFormats.h diff --git a/rpcs3/Emu/RSX/VK/VKFormats.cpp b/rpcs3/Emu/RSX/VK/VKFormats.cpp new file mode 100644 index 0000000000..c0b95dd11b --- /dev/null +++ b/rpcs3/Emu/RSX/VK/VKFormats.cpp @@ -0,0 +1,42 @@ +#include "stdafx.h" +#include "VKFormats.h" + +namespace vk +{ + +gpu_formats_support get_optimal_tiling_supported_formats(VkPhysicalDevice physical_device) +{ + gpu_formats_support result = {}; + + VkFormatProperties props; + vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_D24_UNORM_S8_UINT, &props); + + result.d24_unorm_s8 = !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) + && !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + && !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT) + && !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT); + + vkGetPhysicalDeviceFormatProperties(physical_device, VK_FORMAT_D32_SFLOAT_S8_UINT, &props); + result.d32_sfloat_s8 = !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) + && !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT) + && !!(props.optimalTilingFeatures & VK_FORMAT_FEATURE_BLIT_SRC_BIT); + + return result; +} + +VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format format) +{ + switch (format) + { + case rsx::surface_depth_format::z16: return VK_FORMAT_D16_UNORM; + case rsx::surface_depth_format::z24s8: + { + if (support.d24_unorm_s8) return VK_FORMAT_D24_UNORM_S8_UINT; + if (support.d32_sfloat_s8) return VK_FORMAT_D32_SFLOAT_S8_UINT; + throw EXCEPTION("No hardware support for z24s8"); + } + } + throw EXCEPTION("Invalid format (0x%x)", format); +} + +} \ No newline at end of file diff --git a/rpcs3/Emu/RSX/VK/VKFormats.h b/rpcs3/Emu/RSX/VK/VKFormats.h new file mode 100644 index 0000000000..3b69c68316 --- /dev/null +++ b/rpcs3/Emu/RSX/VK/VKFormats.h @@ -0,0 +1,14 @@ +#pragma once +#include "VKHelpers.h" + +namespace vk +{ + struct gpu_formats_support + { + bool d24_unorm_s8 : 1; + bool d32_sfloat_s8 : 1; + }; + + gpu_formats_support get_optimal_tiling_supported_formats(VkPhysicalDevice physical_device); + VkFormat get_compatible_depth_surface_format(const gpu_formats_support &support, rsx::surface_depth_format format); +} \ No newline at end of file diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index cf62146cb5..7443019832 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -6,6 +6,7 @@ #include "VKGSRender.h" #include "../rsx_methods.h" #include "../Common/BufferUtils.h" +#include "VKFormats.h" namespace { @@ -88,16 +89,6 @@ namespace vk } } - VkFormat get_compatible_depth_surface_format(rsx::surface_depth_format format) - { - switch (format) - { - case rsx::surface_depth_format::z16: return VK_FORMAT_D16_UNORM; - case rsx::surface_depth_format::z24s8: return VK_FORMAT_D16_UNORM_S8_UINT; //Cant get D24_S8 to work on AMD (beta 5) - } - throw EXCEPTION("Invalid format (0x%x)", format); - } - std::vector get_draw_buffers(rsx::surface_target fmt) { switch (fmt) @@ -173,7 +164,9 @@ VKGSRender::VKGSRender() : GSRender(frame_type::Vulkan) #endif m_device = (vk::render_device *)(&m_swap_chain->get_device()); - + + m_optimal_tiling_supported_formats = vk::get_optimal_tiling_supported_formats(m_device->gpu()); + vk::set_current_thread_ctx(m_thread_context); vk::set_current_renderer(m_swap_chain->get_device()); @@ -879,7 +872,7 @@ void VKGSRender::prepare_rtts() clip_horizontal, clip_vertical, rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]), get_color_surface_addresses(), get_zeta_surface_address(), - (*m_device), &m_command_buffer); + (*m_device), &m_command_buffer, m_optimal_tiling_supported_formats); //Bind created rtts as current fbo... std::vector draw_buffers = vk::get_draw_buffers(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])); @@ -910,7 +903,7 @@ void VKGSRender::prepare_rtts() destroy_render_pass(); init_render_pass(vk::get_compatible_surface_format(m_surface.color_format), - vk::get_compatible_depth_surface_format(m_surface.depth_format), + vk::get_compatible_depth_surface_format(m_optimal_tiling_supported_formats, m_surface.depth_format), (u8)draw_buffers.size(), draw_buffers.data()); } diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.h b/rpcs3/Emu/RSX/VK/VKGSRender.h index 808283fb7e..a7a30a537f 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.h +++ b/rpcs3/Emu/RSX/VK/VKGSRender.h @@ -3,6 +3,7 @@ #include "VKHelpers.h" #include "VKTextureCache.h" #include "VKRenderTargets.h" +#include "VKFormats.h" #define RSX_DEBUG 1 @@ -27,6 +28,8 @@ private: vk::texture_cache m_texture_cache; rsx::vk_render_targets m_rtts; + vk::gpu_formats_support m_optimal_tiling_supported_formats; + public: //vk::fbo draw_fbo; diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index 6d27655e5f..326233f4f0 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -68,7 +68,6 @@ 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); - VkFormat get_compatible_depth_surface_format(rsx::surface_depth_format depth_format); class physical_device { diff --git a/rpcs3/Emu/RSX/VK/VKRenderTargets.h b/rpcs3/Emu/RSX/VK/VKRenderTargets.h index 4df472990e..ed2ec5d87d 100644 --- a/rpcs3/Emu/RSX/VK/VKRenderTargets.h +++ b/rpcs3/Emu/RSX/VK/VKRenderTargets.h @@ -4,6 +4,7 @@ #include "VKHelpers.h" #include "../GCM.h" #include "../Common/surface_store.h" +#include "VKFormats.h" namespace rsx { @@ -14,7 +15,7 @@ namespace rsx using command_list_type = vk::command_buffer*; using download_buffer_object = void*; - static vk::texture create_new_surface(u32 address, surface_color_format format, size_t width, size_t height, vk::render_device &device, vk::command_buffer *cmd) + static vk::texture create_new_surface(u32 address, surface_color_format format, size_t width, size_t height, vk::render_device &device, vk::command_buffer *cmd, const vk::gpu_formats_support &support) { VkFormat requested_format = vk::get_compatible_surface_format(format); @@ -37,9 +38,9 @@ namespace rsx return rtt; } - static vk::texture create_new_surface(u32 address, surface_depth_format format, size_t width, size_t height, vk::render_device &device, vk::command_buffer *cmd) + static vk::texture create_new_surface(u32 address, surface_depth_format format, size_t width, size_t height, vk::render_device &device, vk::command_buffer *cmd, const vk::gpu_formats_support &support) { - VkFormat requested_format = vk::get_compatible_depth_surface_format(format); + VkFormat requested_format = vk::get_compatible_depth_surface_format(support, format); vk::texture rtt; rtt.create(device, requested_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, width, height, 1, true); @@ -101,10 +102,11 @@ namespace rsx static bool ds_has_format_width_height(const vk::texture &ds, surface_depth_format format, size_t width, size_t height) { - VkFormat fmt = vk::get_compatible_depth_surface_format(format); + // TODO: check format + //VkFormat fmt = vk::get_compatible_depth_surface_format(format); vk::texture &tex = const_cast(ds); - if (tex.get_format() == fmt && + if (//tex.get_format() == fmt && tex.width() == width && tex.height() == height) return true; diff --git a/rpcs3/VKGSRender.vcxproj b/rpcs3/VKGSRender.vcxproj index 5713b9329f..a782cc17c7 100644 --- a/rpcs3/VKGSRender.vcxproj +++ b/rpcs3/VKGSRender.vcxproj @@ -24,6 +24,7 @@ + @@ -35,6 +36,7 @@ + diff --git a/rpcs3/VKGSRender.vcxproj.filters b/rpcs3/VKGSRender.vcxproj.filters index 22eb36cdee..b9a44206f9 100644 --- a/rpcs3/VKGSRender.vcxproj.filters +++ b/rpcs3/VKGSRender.vcxproj.filters @@ -34,6 +34,9 @@ Source Files + + Source Files + @@ -63,5 +66,8 @@ Source Files + + Source Files + \ No newline at end of file