From 15f1cb4c9899db05cbcc82b3234dcca7dc30083f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 29 Sep 2025 13:24:00 -0700 Subject: [PATCH] Added GPU API support on visionOS You must set SDL_PROP_GPU_DEVICE_CREATE_FEATURE_DEPTH_CLAMPING_BOOLEAN to false on this platform, since setDepthClipMode is not supported on Apple headsets (as of visionOS 2.3) and clipping is the default. --- src/gpu/metal/SDL_gpu_metal.m | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/gpu/metal/SDL_gpu_metal.m b/src/gpu/metal/SDL_gpu_metal.m index 8ceb2b3250..fd6c399d9a 100644 --- a/src/gpu/metal/SDL_gpu_metal.m +++ b/src/gpu/metal/SDL_gpu_metal.m @@ -1116,6 +1116,13 @@ static SDL_GPUGraphicsPipeline *METAL_CreateGraphicsPipeline( SDL_assert_release(!"CreateGraphicsPipeline was passed a vertex shader for the fragment stage"); } } +#ifdef SDL_PLATFORM_VISIONOS + // The default is depth clipping enabled and it can't be changed + if (!createinfo->rasterizer_state.enable_depth_clip) { + SDL_assert_release(!"Rasterizer state enable_depth_clip must be true on this platform"); + } +#endif + pipelineDescriptor = [MTLRenderPipelineDescriptor new]; // Blend @@ -2414,7 +2421,9 @@ static void METAL_BindGraphicsPipeline( [metalCommandBuffer->renderEncoder setTriangleFillMode:SDLToMetal_PolygonMode[pipeline->rasterizerState.fill_mode]]; [metalCommandBuffer->renderEncoder setCullMode:SDLToMetal_CullMode[pipeline->rasterizerState.cull_mode]]; [metalCommandBuffer->renderEncoder setFrontFacingWinding:SDLToMetal_FrontFace[pipeline->rasterizerState.front_face]]; +#ifndef SDL_PLATFORM_VISIONOS [metalCommandBuffer->renderEncoder setDepthClipMode:SDLToMetal_DepthClipMode(pipeline->rasterizerState.enable_depth_clip)]; +#endif [metalCommandBuffer->renderEncoder setDepthBias:((rast->enable_depth_bias) ? rast->depth_bias_constant_factor : 0) slopeScale:((rast->enable_depth_bias) ? rast->depth_bias_slope_factor : 0) @@ -4511,6 +4520,8 @@ static SDL_GPUDevice *METAL_CreateDevice(bool debugMode, bool preferLowPower, SD } else if (@available(macOS 10.14, *)) { hasHardwareSupport = [device supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily2_v1]; } +#elif defined(SDL_PLATFORM_VISIONOS) + hasHardwareSupport = true; #else if (@available(iOS 13.0, tvOS 13.0, *)) { hasHardwareSupport = [device supportsFamily:MTLGPUFamilyApple3];