vulkan: precompute memory type mapping.

This commit is contained in:
Vincent Lejeune 2016-03-14 19:52:00 +01:00
parent 93b06f2a39
commit da2caa0881
4 changed files with 36 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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