(Vulkan) Fix crashes

This commit is contained in:
twinaphex 2022-04-02 19:02:54 +02:00
parent 794900a1ed
commit 65b8ec4cef

View File

@ -896,27 +896,33 @@ static bool vulkan_init_default_filter_chain(vk_t *vk)
#ifdef VULKAN_HDR_SWAPCHAIN
if (vk->context->hdr_enable)
{
struct video_shader* shader_preset = vulkan_filter_chain_get_preset((vulkan_filter_chain_t*)vk->filter_chain);
VkFormat rt_format = vulkan_filter_chain_get_pass_rt_format((vulkan_filter_chain_t*)vk->filter_chain, shader_preset->passes - 1);
struct video_shader* shader_preset = vulkan_filter_chain_get_preset(
vk->filter_chain);
VkFormat rt_format = (shader_preset && shader_preset->passes) ? vulkan_filter_chain_get_pass_rt_format(vk->filter_chain, shader_preset->passes - 1) : VK_FORMAT_UNDEFINED;
if(shader_preset && shader_preset->passes && (rt_format == VK_FORMAT_A2B10G10R10_UNORM_PACK32))
switch (rt_format)
{
/* If the last shader pass uses a RGB10A2 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper and hdr10 conversion */
vulkan_set_hdr_inverse_tonemap(vk, false);
vulkan_set_hdr10(vk, false);
vk->should_resize = true;
}
else if(shader_preset && shader_preset->passes && (rt_format == VK_FORMAT_R16G16B16A16_SFLOAT))
{
/* If the last shader pass uses a RGBA16 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper */
vulkan_set_hdr_inverse_tonemap(vk, false);
vulkan_set_hdr10(vk, true);
vk->should_resize = true;
}
else
{
vulkan_set_hdr_inverse_tonemap(vk, true);
vulkan_set_hdr10(vk, true);
case VK_FORMAT_A2B10G10R10_UNORM_PACK32:
/* If the last shader pass uses a RGB10A2 back buffer
* and HDR has been enabled, assume we want to skip
* the inverse tonemapper and HDR10 conversion */
vulkan_set_hdr_inverse_tonemap(vk, false);
vulkan_set_hdr10(vk, false);
vk->should_resize = true;
break;
case VK_FORMAT_R16G16B16A16_SFLOAT:
/* If the last shader pass uses a RGBA16 backbuffer
* and HDR has been enabled, assume we want to
* skip the inverse tonemapper */
vulkan_set_hdr_inverse_tonemap(vk, false);
vulkan_set_hdr10(vk, true);
vk->should_resize = true;
break;
case VK_FORMAT_UNDEFINED:
default:
vulkan_set_hdr_inverse_tonemap(vk, true);
vulkan_set_hdr10(vk, true);
break;
}
}
#endif /* VULKAN_HDR_SWAPCHAIN */
@ -958,17 +964,16 @@ static bool vulkan_init_filter_chain_preset(vk_t *vk, const char *shader_path)
#ifdef VULKAN_HDR_SWAPCHAIN
if (vk->context->hdr_enable)
{
struct video_shader* shader_preset = vulkan_filter_chain_get_preset((vulkan_filter_chain_t*)vk->filter_chain);
VkFormat rt_format = vulkan_filter_chain_get_pass_rt_format((vulkan_filter_chain_t*)vk->filter_chain, shader_preset->passes - 1);
struct video_shader* shader_preset = vulkan_filter_chain_get_preset(vk->filter_chain);
if(shader_preset && shader_preset->passes && (rt_format == VK_FORMAT_A2B10G10R10_UNORM_PACK32))
if(shader_preset && shader_preset->passes && (vulkan_filter_chain_get_pass_rt_format(vk->filter_chain, shader_preset->passes - 1) == VK_FORMAT_A2B10G10R10_UNORM_PACK32))
{
/* If the last shader pass uses a RGB10A2 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper and hdr10 conversion */
vulkan_set_hdr_inverse_tonemap(vk, false);
vulkan_set_hdr10(vk, false);
vk->should_resize = true;
}
else if(shader_preset && shader_preset->passes && (rt_format == VK_FORMAT_R16G16B16A16_SFLOAT))
else if(shader_preset && shader_preset->passes && (vulkan_filter_chain_get_pass_rt_format(vk->filter_chain, shader_preset->passes - 1) == VK_FORMAT_R16G16B16A16_SFLOAT))
{
/* If the last shader pass uses a RGBA16 back buffer and hdr has been enabled assume we want to skip the inverse tonemapper */
vulkan_set_hdr_inverse_tonemap(vk, false);
@ -1938,8 +1943,8 @@ static bool vulkan_frame(void *data, const void *frame,
bool overlay_behind_menu = video_info->overlay_behind_menu;
#ifdef VULKAN_HDR_SWAPCHAIN
struct video_shader* shader_preset = vulkan_filter_chain_get_preset((vulkan_filter_chain_t*)vk->filter_chain);
VkFormat main_buffer_format = shader_preset && shader_preset->passes ? vulkan_filter_chain_get_pass_rt_format((vulkan_filter_chain_t*)vk->filter_chain, shader_preset->passes - 1) : VK_FORMAT_R8G8B8A8_UNORM;
struct video_shader* shader_preset = vulkan_filter_chain_get_preset(vk->filter_chain);
VkFormat main_buffer_format = shader_preset && shader_preset->passes ? vulkan_filter_chain_get_pass_rt_format(vk->filter_chain, shader_preset->passes - 1) : VK_FORMAT_R8G8B8A8_UNORM;
bool use_main_buffer = main_buffer_format != vk->context->swapchain_format;
#endif /* VULKAN_HDR_SWAPCHAIN */