Merge pull request #1566 from vlj/vulkan

Vulkan: Uses d24_s8 or d32_s8 depending on availability.
This commit is contained in:
vlj 2016-03-12 19:39:46 +01:00
commit c8cc681591
8 changed files with 93 additions and 42 deletions

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -6,6 +6,7 @@
#include "VKGSRender.h" #include "VKGSRender.h"
#include "../rsx_methods.h" #include "../rsx_methods.h"
#include "../Common/BufferUtils.h" #include "../Common/BufferUtils.h"
#include "VKFormats.h"
namespace 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<u8> get_draw_buffers(rsx::surface_target fmt) std::vector<u8> get_draw_buffers(rsx::surface_target fmt)
{ {
switch (fmt) switch (fmt)
@ -174,6 +165,8 @@ VKGSRender::VKGSRender() : GSRender(frame_type::Vulkan)
m_device = (vk::render_device *)(&m_swap_chain->get_device()); 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_thread_ctx(m_thread_context);
vk::set_current_renderer(m_swap_chain->get_device()); vk::set_current_renderer(m_swap_chain->get_device());
@ -879,7 +872,7 @@ void VKGSRender::prepare_rtts()
clip_horizontal, clip_vertical, clip_horizontal, clip_vertical,
rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]), rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET]),
get_color_surface_addresses(), get_zeta_surface_address(), 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... //Bind created rtts as current fbo...
std::vector<u8> draw_buffers = vk::get_draw_buffers(rsx::to_surface_target(rsx::method_registers[NV4097_SET_SURFACE_COLOR_TARGET])); std::vector<u8> 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(); destroy_render_pass();
init_render_pass(vk::get_compatible_surface_format(m_surface.color_format), 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(), (u8)draw_buffers.size(),
draw_buffers.data()); draw_buffers.data());
} }

View file

@ -3,6 +3,7 @@
#include "VKHelpers.h" #include "VKHelpers.h"
#include "VKTextureCache.h" #include "VKTextureCache.h"
#include "VKRenderTargets.h" #include "VKRenderTargets.h"
#include "VKFormats.h"
#define RSX_DEBUG 1 #define RSX_DEBUG 1
@ -27,6 +28,8 @@ private:
vk::texture_cache m_texture_cache; vk::texture_cache m_texture_cache;
rsx::vk_render_targets m_rtts; rsx::vk_render_targets m_rtts;
vk::gpu_formats_support m_optimal_tiling_supported_formats;
public: public:
//vk::fbo draw_fbo; //vk::fbo draw_fbo;

View file

@ -11,12 +11,10 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp> #include <glm/gtc/type_ptr.hpp>
#include "Emu/state.h"
#include "VulkanAPI.h" #include "VulkanAPI.h"
#include "../GCM.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 namespace rsx
{ {
class texture; class texture;
@ -70,7 +68,6 @@ namespace vk
VkFormat get_compatible_sampler_format(u32 format, VkComponentMapping& mapping, u8 swizzle_mask=0); 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_surface_format(rsx::surface_color_format color_format);
VkFormat get_compatible_depth_surface_format(rsx::surface_depth_format depth_format);
class physical_device class physical_device
{ {
@ -166,22 +163,18 @@ namespace vk
"VK_KHR_swapchain" "VK_KHR_swapchain"
}; };
const char *validation_layers[] = std::vector<const char *> layers;
{
"VK_LAYER_LUNARG_threading", "VK_LAYER_LUNARG_mem_tracker", if (rpcs3::config.rsx.d3d12.debug_output.value())
"VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_draw_state", layers.push_back("VK_LAYER_LUNARG_standard_validation");
"VK_LAYER_LUNARG_param_checker", "VK_LAYER_LUNARG_swapchain",
"VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_image",
"VK_LAYER_GOOGLE_unique_objects",
};
VkDeviceCreateInfo device; VkDeviceCreateInfo device;
device.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO; device.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
device.pNext = NULL; device.pNext = NULL;
device.queueCreateInfoCount = 1; device.queueCreateInfoCount = 1;
device.pQueueCreateInfos = &queue; device.pQueueCreateInfos = &queue;
device.enabledLayerCount = VK_ENABLED_LAYER_COUNT; device.enabledLayerCount = layers.size();
device.ppEnabledLayerNames = validation_layers; device.ppEnabledLayerNames = layers.data();
device.enabledExtensionCount = 1; device.enabledExtensionCount = 1;
device.ppEnabledExtensionNames = requested_extensions; device.ppEnabledExtensionNames = requested_extensions;
device.pEnabledFeatures = nullptr; device.pEnabledFeatures = nullptr;
@ -1011,21 +1004,17 @@ namespace vk
"VK_EXT_debug_report", "VK_EXT_debug_report",
}; };
const char *validation_layers[] = std::vector<const char *> layers;
{
"VK_LAYER_LUNARG_threading", "VK_LAYER_LUNARG_mem_tracker", if (rpcs3::config.rsx.d3d12.debug_output.value())
"VK_LAYER_LUNARG_object_tracker", "VK_LAYER_LUNARG_draw_state", layers.push_back("VK_LAYER_LUNARG_standard_validation");
"VK_LAYER_LUNARG_param_checker", "VK_LAYER_LUNARG_swapchain",
"VK_LAYER_LUNARG_device_limits", "VK_LAYER_LUNARG_image",
"VK_LAYER_GOOGLE_unique_objects",
};
VkInstanceCreateInfo instance_info; VkInstanceCreateInfo instance_info;
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
instance_info.pNext = nullptr; instance_info.pNext = nullptr;
instance_info.pApplicationInfo = &app; instance_info.pApplicationInfo = &app;
instance_info.enabledLayerCount = VK_ENABLED_LAYER_COUNT; instance_info.enabledLayerCount = layers.size();
instance_info.ppEnabledLayerNames = validation_layers; instance_info.ppEnabledLayerNames = layers.data();
instance_info.enabledExtensionCount = 3; instance_info.enabledExtensionCount = 3;
instance_info.ppEnabledExtensionNames = requested_extensions; instance_info.ppEnabledExtensionNames = requested_extensions;

View file

@ -4,6 +4,7 @@
#include "VKHelpers.h" #include "VKHelpers.h"
#include "../GCM.h" #include "../GCM.h"
#include "../Common/surface_store.h" #include "../Common/surface_store.h"
#include "VKFormats.h"
namespace rsx namespace rsx
{ {
@ -14,7 +15,7 @@ namespace rsx
using command_list_type = vk::command_buffer*; using command_list_type = vk::command_buffer*;
using download_buffer_object = void*; 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); VkFormat requested_format = vk::get_compatible_surface_format(format);
@ -37,9 +38,9 @@ namespace rsx
return rtt; 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; vk::texture rtt;
rtt.create(device, requested_format, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT|VK_IMAGE_USAGE_SAMPLED_BIT, width, height, 1, true); 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) 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<vk::texture&>(ds); vk::texture &tex = const_cast<vk::texture&>(ds);
if (tex.get_format() == fmt && if (//tex.get_format() == fmt &&
tex.width() == width && tex.width() == width &&
tex.height() == height) tex.height() == height)
return true; return true;

View file

@ -24,6 +24,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Emu\RSX\VK\VKCommonDecompiler.h" /> <ClInclude Include="Emu\RSX\VK\VKCommonDecompiler.h" />
<ClInclude Include="Emu\RSX\VK\VKFormats.h" />
<ClInclude Include="Emu\RSX\VK\VKFragmentProgram.h" /> <ClInclude Include="Emu\RSX\VK\VKFragmentProgram.h" />
<ClInclude Include="Emu\RSX\VK\VKGSRender.h" /> <ClInclude Include="Emu\RSX\VK\VKGSRender.h" />
<ClInclude Include="Emu\RSX\VK\VKHelpers.h" /> <ClInclude Include="Emu\RSX\VK\VKHelpers.h" />
@ -35,6 +36,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Emu\RSX\VK\VKCommonDecompiler.cpp" /> <ClCompile Include="Emu\RSX\VK\VKCommonDecompiler.cpp" />
<ClCompile Include="Emu\RSX\VK\VKFormats.cpp" />
<ClCompile Include="Emu\RSX\VK\VKFragmentProgram.cpp" /> <ClCompile Include="Emu\RSX\VK\VKFragmentProgram.cpp" />
<ClCompile Include="Emu\RSX\VK\VKGSRender.cpp" /> <ClCompile Include="Emu\RSX\VK\VKGSRender.cpp" />
<ClCompile Include="Emu\RSX\VK\VKHelpers.cpp" /> <ClCompile Include="Emu\RSX\VK\VKHelpers.cpp" />

View file

@ -34,6 +34,9 @@
<ClInclude Include="Emu\RSX\VK\VulkanAPI.h"> <ClInclude Include="Emu\RSX\VK\VulkanAPI.h">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Emu\RSX\VK\VKFormats.h">
<Filter>Source Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Emu\RSX\VK\VKGSRender.cpp"> <ClCompile Include="Emu\RSX\VK\VKGSRender.cpp">
@ -63,5 +66,8 @@
<ClCompile Include="Emu\RSX\VK\VKVertexBuffers.cpp"> <ClCompile Include="Emu\RSX\VK\VKVertexBuffers.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Emu\RSX\VK\VKFormats.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
</Project> </Project>