libretro/libretro_vulkan.cpp got PPSSPP's libretro core working with
RetroArch's Vulkan integration by globally monkey-patching PPSSPP's Vulkan
loader function pointers (vkCreateInstance, vkCreateDevice,
vkCreateSwapchainKHR, vkAcquireNextImageKHR, vkQueuePresentKHR,
vkQueueSubmit, etc.) so the unmodified VulkanContext class would end up
wrapping RetroArch's already-existing VkInstance/VkDevice instead of
creating its own, and so a fake VkSwapchainKHR (a self-managed array of
images synced against RetroArch's retro_hw_render_interface_vulkan
callbacks) could stand in for the real swapchain that libretro's Vulkan
model doesn't have. Flagged in-code as "a wacky wrapper".
Replaces that with first-class support in VulkanContext for the two things
libretro actually needs:
- Adopting an externally-created instance/device instead of faking
vkCreateInstance/vkCreateDevice: VulkanContext::CreateInstanceExternal()
adopts RetroArch's VkInstance; CreateDevice() gained optional
extraDeviceExtensions/extraRequiredFeatures params so RetroArch's
requirements get merged into a real vkCreateDevice() call;
ownsInstance_/ownsDevice_ flags (the latter set via
SetDeviceExternallyOwned()) mean DestroyInstance()/DestroyDevice() skip
the real vkDestroy* calls when something else owns the object, without
needing to intercept anything. VulkanLoader gained
VulkanLoadFromGetInstanceProcAddr() for bootstrapping from a
host-supplied proc-addr getter instead of dlopen/dlsym-ing the loader
ourselves - vkGetDeviceProcAddr is resolved via the real instance handle
(not NULL), since per the Vulkan spec it's not one of the handful of
commands queryable with a NULL instance.
- A pluggable presentation backend (Common/GPU/Vulkan/VulkanPresentation.h)
for hosts with no real VK_KHR_swapchain, replacing the fake-swapchain-
handle trick. VulkanContext::GetPresentation() is null by default, so
every existing platform's real-swapchain code path is untouched;
libretro/LibretroVulkanPresentation implements this interface directly
against retro_hw_render_interface_vulkan, as real class state instead of
file-scope globals. Several pieces of state that are normally only
populated as a side effect of ReinitSurface()/InitSwapchain() - the
graphics queue/queue family index (ChooseQueue() is entangled with
real-surface presentation-support checks), the swapchain format, and
the available present modes - needed presentation-aware fallbacks since
libretro never calls that real-surface path at all.
libretro/LibretroVulkanContext.cpp now drives VulkanContext's real, public
API directly - no more hijacked function pointers, no more fake surface or
swapchain. libretro/libretro_vulkan.cpp is deleted.
Verified with a full build+run in RetroArch (not just compile-time
checks): the libretro Makefile doesn't track header dependencies
(cl.exe doesn't support -MMD/-MP, and Makefile.common never sets up an
equivalent), so a `make clean` full rebuild is required after any header
change to avoid linking stale object code from before the change - several
of the fixes above were initially masked by exactly that.
When IsFormatSupported returns S_FALSE with a closestMatch format,
evaluate it and use it if it's acceptable (stereo float). This can
improve compatibility with devices that don't support our exact
requested format but have a similar one.
Previously we just discarded closestMatch and forced manual conversion,
which was wasteful when the device provided a perfectly usable
alternative format.
CRITICAL BUG FIX: The previous code assumed incorrect channel ordering
for multichannel audio, breaking 5.1 (6-channel) configurations.
Problem:
- Code assumed channel order: FL, FR, RL, RR, C, LFE
o systems- Actual 5.1 standard order: FL, FR, C, LFE, RL, RR
- This caused center/LFE to receive rear audio and vice versa
- Users had to force stereo mode to get working audio
Solution:
- Parse dwChannelMask from WAVEFORMATEXTENSIBLE to determine actual
channel positions
- Map stereo input to correct output channels based on the mask
- Properly handles 5.1, 7.1, and other multichannel configurations
- Safely handles non-standard channel layouts
The channel mapping now works correctly for all standard speaker
configurations by querying the device's actual channel layout instead
of assuming a fixed order.
Define constants for channel upmixing attenuation factors to improve
code readability and maintainability:
- SURROUND_ATTENUATION (0.7f) for rear/side channels
- CENTER_MIX_ATTENUATION (0.7f) for center channel
- LFE_MIX_ATTENUATION (0.5f) for LFE channel
Store format_->nChannels in atomic curChannels_ member to avoid
unsynchronized access to format_ pointer from the audio thread.
The format_ pointer can be freed/reallocated during Stop() while
the audio thread might still be reading it.
There's no guarantee VK_FULL_SCREEN_EXCLUSIVE_ALLOWED_EXT will enter Fullscreen exclusive (FSE). Under the right conditions, the driver and/or DWM can grant FSE. Adding "allow" to the FSE setting should make this a bit clearer.
Vulkan swapchain now explicitly sets VK_FULL_SCREEN_EXCLUSIVE_DISALLOWED_EXT by default, enabling proper borderless fullscreen behavior with benefits including better Alt+Tab, VRR/G-Sync/FreeSync, and Auto HDR support.