Skip to content

Commit

Permalink
[Libretro] Check for per-pixel compatibility and hide the option if n…
Browse files Browse the repository at this point in the history
…ot supported
  • Loading branch information
bslenul committed Mar 16, 2024
1 parent e27b5dc commit f7c1e10
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/rend/vulkan/vk_context_lr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ bool VkCreateDevice(retro_vulkan_context* context, VkInstance instance, VkPhysic

vk::PhysicalDeviceFeatures supportedFeatures;
physicalDevice.getFeatures(&supportedFeatures);
bool fragmentStoresAndAtomics = supportedFeatures.fragmentStoresAndAtomics;
VulkanContext::Instance()->fragmentStoresAndAtomics = supportedFeatures.fragmentStoresAndAtomics;
VulkanContext::Instance()->samplerAnisotropy = supportedFeatures.samplerAnisotropy;

// Enable VK_KHR_dedicated_allocation if available
Expand Down Expand Up @@ -157,7 +157,7 @@ bool VkCreateDevice(retro_vulkan_context* context, VkInstance instance, VkPhysic
vk::DeviceQueueCreateInfo(vk::DeviceQueueCreateFlags(), context->presentation_queue_family_index, 1, &queuePriority),
};
vk::PhysicalDeviceFeatures features(*required_features);
if (fragmentStoresAndAtomics)
if (VulkanContext::Instance()->fragmentStoresAndAtomics)
features.fragmentStoresAndAtomics = true;
if (VulkanContext::Instance()->samplerAnisotropy)
features.samplerAnisotropy = true;
Expand Down
2 changes: 2 additions & 0 deletions core/rend/vulkan/vk_context_lr.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class VulkanContext : public GraphicsContext, public FlightManager
static VulkanContext *Instance() { return contextInstance; }
bool SupportsSamplerAnisotropy() const { return samplerAnisotropy; }
bool SupportsDedicatedAllocation() const { return dedicatedAllocationSupported; }
bool hasPerPixel() override { return fragmentStoresAndAtomics; }
const VMAllocator& GetAllocator() const { return allocator; }
vk::DeviceSize GetMaxMemoryAllocationSize() const { return maxMemoryAllocationSize; }
f32 GetMaxSamplerAnisotropy() const { return samplerAnisotropy ? maxSamplerAnisotropy : 1.f; }
Expand Down Expand Up @@ -126,6 +127,7 @@ class VulkanContext : public GraphicsContext, public FlightManager
bool samplerAnisotropy = false;
f32 maxSamplerAnisotropy = 0.f;
bool dedicatedAllocationSupported = false;
bool fragmentStoresAndAtomics = false;
private:
u32 vendorID = 0;

Expand Down
47 changes: 47 additions & 0 deletions shell/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ static bool platformIsDreamcast = true;
static bool platformIsArcade = false;
static bool threadedRenderingEnabled = true;
static bool oitEnabled = false;
#if defined(HAVE_OIT) || defined(HAVE_VULKAN) || defined(HAVE_D3D11)
static bool perPixelChecked = false;
#endif
static bool autoSkipFrameEnabled = false;
#ifdef _OPENMP
static bool textureUpscaleEnabled = false;
Expand Down Expand Up @@ -1241,6 +1244,42 @@ void retro_reset()
emu.start();
}

#if defined(HAVE_OIT) || defined(HAVE_VULKAN) || defined(HAVE_D3D11)
void check_per_pixel_opt(void)
{
// Check if per-pixel is supported, if not we hide the option
if (!GraphicsContext::Instance()->hasPerPixel())
{
for (unsigned i = 0; option_defs_us[i].key != NULL; i++)
{
// Looking for the alpha sorting core option...
if (!strcmp(option_defs_us[i].key, CORE_OPTION_NAME "_alpha_sorting"))
{
for (unsigned j = 0; option_defs_us[i].values[j].value != NULL; j++)
{
// ... then for the per-pixel choice...
if (!strcmp(option_defs_us[i].values[j].value, "per-pixel (accurate)"))
{
// ... null it out...
option_defs_us[i].values[j] = { NULL, NULL };

// ... and finally refresh core options.
bool optionCategoriesSupported = false;
libretro_set_core_options(environ_cb, &optionCategoriesSupported);
categoriesSupported |= optionCategoriesSupported;

break;
}
}
break;
}
}
NOTICE_LOG(RENDERER, "Current renderer does not support 'Per-Pixel' Alpha Sorting.");
}
perPixelChecked = true;
}
#endif

#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
static void context_reset()
{
Expand All @@ -1251,6 +1290,10 @@ static void context_reset()
rend_term_renderer();
theGLContext.init();
rend_init_renderer();
#ifdef HAVE_OIT
if (!perPixelChecked)
check_per_pixel_opt();
#endif
}

static void context_destroy()
Expand Down Expand Up @@ -1812,6 +1855,8 @@ static void retro_vk_context_reset()
theVulkanContext.init((retro_hw_render_interface_vulkan *)vulkan);
rend_term_renderer();
rend_init_renderer();
if (!perPixelChecked)
check_per_pixel_opt();
}

static void retro_vk_context_destroy()
Expand Down Expand Up @@ -1946,6 +1991,8 @@ static void dx11_context_reset()
else if (config::RendererType != RenderType::DirectX11_OIT)
config::RendererType = RenderType::DirectX11;
rend_init_renderer();
if (!perPixelChecked)
check_per_pixel_opt();
}

static void dx11_context_destroy()
Expand Down

0 comments on commit f7c1e10

Please sign in to comment.