Backends: SDL_GPU3: select between metallib and MSL shaders based on availability. (#9076)

Amend fd887f5
This commit is contained in:
ocornut
2025-11-26 15:05:05 +01:00
parent fd887f5241
commit 75db81cf08
2 changed files with 29 additions and 26 deletions

View File

@@ -22,7 +22,7 @@
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info. // Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
// CHANGELOG // CHANGELOG
// 2025-11-26: Use MSL shaders on macOS to support macOS 10.14+ (instead of Metallib shaders requiring macOS 14+). Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL. // 2025-11-26: macOS version can use MSL shaders in order to support macOS 10.14+ (vs Metallib shaders requiring macOS 14+). Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL.
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown. // 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
// 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created. // 2025-08-20: Added ImGui_ImplSDLGPU3_InitInfo::SwapchainComposition and ImGui_ImplSDLGPU3_InitInfo::PresentMode to configure how secondary viewports are created.
// 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988) // 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988)
@@ -453,28 +453,31 @@ static void ImGui_ImplSDLGPU3_CreateShaders()
#ifdef __APPLE__ #ifdef __APPLE__
else else
{ {
#include <TargetConditionals.h> SDL_GPUShaderFormat supported_formats = SDL_GetGPUShaderFormats(v->Device);
#if TARGET_OS_OSX if (supported_formats & SDL_GPU_SHADERFORMAT_METALLIB)
// macOS: using MSL source {
vertex_shader_info.entrypoint = "main0"; // Using metallib blobs (macOS 14+, iOS)
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_MSL; vertex_shader_info.entrypoint = "main0";
vertex_shader_info.code = msl_vertex; vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
vertex_shader_info.code_size = sizeof(msl_vertex); vertex_shader_info.code = metallib_vertex;
fragment_shader_info.entrypoint = "main0"; vertex_shader_info.code_size = sizeof(metallib_vertex);
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_MSL; fragment_shader_info.entrypoint = "main0";
fragment_shader_info.code = msl_fragment; fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
fragment_shader_info.code_size = sizeof(msl_fragment); fragment_shader_info.code = metallib_fragment;
#elif TARGET_OS_IPHONE fragment_shader_info.code_size = sizeof(metallib_fragment);
// iOS device: using metallib blobs }
vertex_shader_info.entrypoint = "main0"; else if (supported_formats & SDL_GPU_SHADERFORMAT_MSL)
vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB; {
vertex_shader_info.code = metallib_vertex; // macOS: using MSL source
vertex_shader_info.code_size = sizeof(metallib_vertex); vertex_shader_info.entrypoint = "main0";
fragment_shader_info.entrypoint = "main0"; vertex_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB; vertex_shader_info.code = msl_vertex;
fragment_shader_info.code = metallib_fragment; vertex_shader_info.code_size = sizeof(msl_vertex);
fragment_shader_info.code_size = sizeof(metallib_fragment); fragment_shader_info.entrypoint = "main0";
#endif fragment_shader_info.format = SDL_GPU_SHADERFORMAT_MSL;
fragment_shader_info.code = msl_fragment;
fragment_shader_info.code_size = sizeof(msl_fragment);
}
} }
#endif #endif
bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info); bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);

View File

@@ -54,9 +54,9 @@ Other Changes:
- Scrollbar: fixed a codepath leading to a divide-by-zero (which would not be - Scrollbar: fixed a codepath leading to a divide-by-zero (which would not be
noticeable by user but detected by sanitizers). (#9089) [@judicaelclair] noticeable by user but detected by sanitizers). (#9089) [@judicaelclair]
- Backends: - Backends:
- SDL_GPU3: on macOS, use MSL shaders in order to support macOS 10.14+ - SDL_GPU3: macOS version can use MSL shaders in order to support macOS 10.14+
(instead of Metallib shaders requiring macOS 14+). (#9076) [@Niminem] (vs Metallib shaders requiring macOS 14+). Requires application calling
Requires calling SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL. SDL_CreateGPUDevice() with SDL_GPU_SHADERFORMAT_MSL. (#9076) [@Niminem]
- Vulkan: helper for creating a swapchain (used by examples and multi-viewports) - Vulkan: helper for creating a swapchain (used by examples and multi-viewports)
selects `VkSwapchainCreateInfoKHR`'s `compositeAlpha` value based on selects `VkSwapchainCreateInfoKHR`'s `compositeAlpha` value based on
`cap.supportedCompositeAlpha`, which seems to be required on some Android `cap.supportedCompositeAlpha`, which seems to be required on some Android