From 12da498001abe5bf3339dc7710aa8906c1cf1a0d Mon Sep 17 00:00:00 2001 From: kd-11 Date: Wed, 7 Jun 2017 22:45:02 +0300 Subject: [PATCH] vk: API bug fixes - Improve spec conformity explicitly request anisotropic filtering and BC compression clean up a leaking framebuffer handle reference when using debug overlay Wait for device instead of queue to ensure no conflict during renderer shutdown Clip scissor regions when doing surface clears --- rpcs3/Emu/RSX/VK/VKGSRender.cpp | 25 +++++++++++++++++++++++-- rpcs3/Emu/RSX/VK/VKHelpers.h | 12 +++++++++++- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/rpcs3/Emu/RSX/VK/VKGSRender.cpp b/rpcs3/Emu/RSX/VK/VKGSRender.cpp index 9dd2d1807d..5a89b9a5c3 100644 --- a/rpcs3/Emu/RSX/VK/VKGSRender.cpp +++ b/rpcs3/Emu/RSX/VK/VKGSRender.cpp @@ -635,8 +635,8 @@ VKGSRender::~VKGSRender() m_current_command_buffer->reset(); - //Wait for queue - vkQueueWaitIdle(m_swap_chain->get_present_queue()); + //Wait for device to finish up with resources + vkDeviceWaitIdle(*m_device); //Sync objects if (m_present_semaphore) @@ -1048,6 +1048,26 @@ void VKGSRender::clear_surface(u32 mask) u16 scissor_y = rsx::method_registers.scissor_origin_y(); u16 scissor_h = rsx::method_registers.scissor_height(); + const u32 fb_width = m_framebuffer_to_clean.back()->width(); + const u32 fb_height = m_framebuffer_to_clean.back()->height(); + + //clip region + //TODO: Move clipping logic to shared code. Its used in other places as well + if (scissor_x >= fb_width) + scissor_x = 0; + + if (scissor_y >= fb_height) + scissor_y = 0; + + const u32 scissor_limit_x = scissor_x + scissor_w; + const u32 scissor_limit_y = scissor_y + scissor_h; + + if (scissor_limit_x > fb_width) + scissor_w = fb_width - scissor_x; + + if (scissor_limit_y > fb_height) + scissor_h = fb_height - scissor_y; + VkClearRect region = { { { scissor_x, scissor_y },{ scissor_w, scissor_h } }, 0, 1 }; auto targets = vk::get_draw_buffers(rsx::method_registers.surface_color_target()); @@ -1821,6 +1841,7 @@ void VKGSRender::flip(int buffer) vk::change_image_layout(*m_current_command_buffer, target_image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_PRESENT_SRC_KHR, subres); } + m_framebuffer_to_clean.push_back(std::move(direct_fbo)); queue_swap_request(); } else diff --git a/rpcs3/Emu/RSX/VK/VKHelpers.h b/rpcs3/Emu/RSX/VK/VKHelpers.h index c620a8d034..1947fda306 100644 --- a/rpcs3/Emu/RSX/VK/VKHelpers.h +++ b/rpcs3/Emu/RSX/VK/VKHelpers.h @@ -189,6 +189,16 @@ namespace vk if (g_cfg.video.debug_output) layers.push_back("VK_LAYER_LUNARG_standard_validation"); + //Enable hardware features manually + //Currently we require: + //1. Anisotropic sampling + //2. DXT support + VkPhysicalDeviceFeatures available_features; + vkGetPhysicalDeviceFeatures(*pgpu, &available_features); + + available_features.samplerAnisotropy = VK_TRUE; + available_features.textureCompressionBC = VK_TRUE; + VkDeviceCreateInfo device = {}; device.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; device.pNext = NULL; @@ -198,7 +208,7 @@ namespace vk device.ppEnabledLayerNames = layers.data(); device.enabledExtensionCount = 1; device.ppEnabledExtensionNames = requested_extensions; - device.pEnabledFeatures = nullptr; + device.pEnabledFeatures = &available_features; CHECK_RESULT(vkCreateDevice(*pgpu, &device, nullptr, &dev)); }