Skip to content

Commit 3d42ce6

Browse files
Integrate VisionOS platform
1 parent 75a6593 commit 3d42ce6

23 files changed

Lines changed: 511 additions & 54 deletions

BuildTools/CMake/BuildUtils.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ endfunction()
323323
function(get_backend_libraries_type _LIB_TYPE)
324324
if(PLATFORM_WIN32 OR PLATFORM_LINUX OR PLATFORM_ANDROID OR PLATFORM_UNIVERSAL_WINDOWS OR PLATFORM_MACOS)
325325
set(LIB_TYPE "shared")
326-
elseif(PLATFORM_IOS OR PLATFORM_TVOS OR PLATFORM_WEB)
327-
# Statically link with the engine on iOS, tvOS and Emscripten.
326+
elseif(PLATFORM_IOS OR PLATFORM_TVOS OR PLATFORM_VISIONOS OR PLATFORM_WEB)
327+
# Statically link with the engine on iOS, tvOS, visionOS and Emscripten.
328328
# It is also possible to link dynamically by
329329
# putting the library into the framework.
330330
set(LIB_TYPE "static")

CMakeLists.txt

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ set(PLATFORM_LINUX FALSE CACHE INTERNAL "")
4949
set(PLATFORM_MACOS FALSE CACHE INTERNAL "")
5050
set(PLATFORM_IOS FALSE CACHE INTERNAL "")
5151
set(PLATFORM_TVOS FALSE CACHE INTERNAL "")
52+
set(PLATFORM_VISIONOS FALSE CACHE INTERNAL "")
5253
set(PLATFORM_WEB FALSE CACHE INTERNAL "")
5354
set(PLATFORM_EMSCRIPTEN FALSE CACHE INTERNAL "")
5455
set(D3D11_SUPPORTED FALSE CACHE INTERNAL "D3D11 is not supported")
@@ -135,6 +136,9 @@ else()
135136
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "tvOS")
136137
set(PLATFORM_TVOS TRUE CACHE INTERNAL "Target platform: tvOS")
137138
message("Target platform: tvOS " ${ARCH})
139+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "visionOS")
140+
set(PLATFORM_VISIONOS TRUE CACHE INTERNAL "Target platform: visionOS")
141+
message("Target platform: visionOS " ${ARCH})
138142
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten")
139143
set(PLATFORM_WEB TRUE CACHE INTERNAL "Target platform: Web")
140144
set(PLATFORM_EMSCRIPTEN TRUE CACHE INTERNAL "Build with Emscripten")
@@ -144,8 +148,8 @@ else()
144148
endif()
145149
endif(WIN32)
146150

147-
if(PLATFORM_MACOS OR PLATFORM_IOS OR PLATFORM_TVOS)
148-
set(PLATFORM_APPLE TRUE CACHE INTERNAL "Apple platform (macOS, iOS, or tvOS)")
151+
if(PLATFORM_MACOS OR PLATFORM_IOS OR PLATFORM_TVOS OR PLATFORM_VISIONOS)
152+
set(PLATFORM_APPLE TRUE CACHE INTERNAL "Apple platform (macOS, iOS, tvOS, or visionOS)")
149153
endif()
150154

151155
add_library(Diligent-PublicBuildSettings INTERFACE)
@@ -209,6 +213,9 @@ elseif(PLATFORM_IOS)
209213
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_IOS=1 PLATFORM_APPLE=1)
210214
elseif(PLATFORM_TVOS)
211215
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_TVOS=1 PLATFORM_APPLE=1)
216+
elseif(PLATFORM_VISIONOS)
217+
set(ARCHIVER_SUPPORTED TRUE CACHE INTERNAL "Archiver is supported on visionOS platform")
218+
target_compile_definitions(Diligent-PublicBuildSettings INTERFACE PLATFORM_VISIONOS=1 PLATFORM_APPLE=1)
212219
elseif(PLATFORM_WEB)
213220
set(GLES_SUPPORTED TRUE CACHE INTERNAL "OpenGLES is supported on Web platform")
214221
set(WEBGPU_SUPPORTED TRUE CACHE INTERNAL "WebGPU is supported on Web platform")
@@ -298,6 +305,10 @@ option(DILIGENT_NO_DIRECT3D12 "Disable Direct3D12 backend" OFF)
298305
option(DILIGENT_NO_OPENGL "Disable OpenGL/GLES backend" OFF)
299306
option(DILIGENT_NO_VULKAN "Disable Vulkan backend" OFF)
300307
option(DILIGENT_NO_METAL "Disable Metal backend" OFF)
308+
option(DILIGENT_USE_COMPOSITOR_SERVICES "Enable CompositorServices support for visionOS" OFF)
309+
if(PLATFORM_VISIONOS)
310+
set(DILIGENT_USE_COMPOSITOR_SERVICES ON CACHE BOOL "CompositorServices is auto-enabled on visionOS" FORCE)
311+
endif()
301312
if (PLATFORM_WEB)
302313
option(DILIGENT_NO_WEBGPU "Disable WebGPU backend" OFF)
303314
else()
@@ -540,6 +551,16 @@ elseif(PLATFORM_TVOS)
540551
message(FATAL_ERROR "Failed to find CoreFoundation framework")
541552
endif()
542553

554+
find_library(FOUNDATION Foundation)
555+
if(NOT FOUNDATION)
556+
message(FATAL_ERROR "Failed to find Foundation framework")
557+
endif()
558+
elseif(PLATFORM_VISIONOS)
559+
find_library(CORE_FOUNDATION CoreFoundation)
560+
if(NOT CORE_FOUNDATION)
561+
message(FATAL_ERROR "Failed to find CoreFoundation framework")
562+
endif()
563+
543564
find_library(FOUNDATION Foundation)
544565
if(NOT FOUNDATION)
545566
message(FATAL_ERROR "Failed to find Foundation framework")

Common/interface/StringTools.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -95,7 +95,7 @@ inline std::wstring WidenString(const std::string& Str)
9595

9696
inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
9797
{
98-
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_WEB
98+
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS || PLATFORM_WEB
9999
# define _strnicmp strncasecmp
100100
#endif
101101

@@ -104,7 +104,7 @@ inline int StrCmpNoCase(const char* Str1, const char* Str2, size_t NumChars)
104104

105105
inline int StrCmpNoCase(const char* Str1, const char* Str2)
106106
{
107-
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_WEB
107+
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS || PLATFORM_WEB
108108
# define _stricmp strcasecmp
109109
#endif
110110

Graphics/Archiver/interface/ArchiverFactoryLoader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828

2929
#include "ArchiverFactory.h"
3030

31-
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_WEB || (PLATFORM_WIN32 && !defined(_MSC_VER))
31+
#if PLATFORM_ANDROID || PLATFORM_LINUX || PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS || PLATFORM_WEB || (PLATFORM_WIN32 && !defined(_MSC_VER))
3232
// https://gcc.gnu.org/wiki/Visibility
3333
# define API_QUALIFIER __attribute__((visibility("default")))
3434
#elif PLATFORM_WIN32 || PLATFORM_UNIVERSAL_WINDOWS

Graphics/GraphicsEngine/src/DeviceObjectArchive.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ DeviceObjectArchive::DeviceType RenderDeviceTypeToArchiveDeviceType(RENDER_DEVIC
5050
case RENDER_DEVICE_TYPE_VULKAN: return DeviceObjectArchive::DeviceType::Vulkan;
5151
#if PLATFORM_MACOS
5252
case RENDER_DEVICE_TYPE_METAL: return DeviceObjectArchive::DeviceType::Metal_MacOS;
53-
#elif PLATFORM_IOS || PLATFORM_TVOS
53+
#elif PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS
5454
case RENDER_DEVICE_TYPE_METAL: return DeviceObjectArchive::DeviceType::Metal_iOS;
5555
#endif
5656
case RENDER_DEVICE_TYPE_WEBGPU:

Graphics/GraphicsEngine/src/FramebufferBase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2025 Diligent Graphics LLC
2+
* Copyright 2019-2026 Diligent Graphics LLC
33
* Copyright 2015-2019 Egor Yusov
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -125,7 +125,7 @@ void ValidateFramebufferDesc(const FramebufferDesc& Desc, IRenderDevice* pDevice
125125
LOG_FRAMEBUFFER_ERROR_AND_THROW("memoryless attachment ", i, " is not compatible with ATTACHMENT_STORE_OP_STORE");
126126
}
127127

128-
#if PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS
128+
#if PLATFORM_MACOS || PLATFORM_IOS || PLATFORM_TVOS || PLATFORM_VISIONOS
129129
{
130130
Uint32 NumSubpasses = 0;
131131
for (Uint32 s = 0; s < RPDesc.SubpassCount; ++s)

Graphics/GraphicsTools/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ if(DILIGENT_USE_OPENXR)
7777
list(APPEND INTERFACE interface/OpenXRUtilities.h)
7878
endif()
7979

80+
if(DILIGENT_USE_COMPOSITOR_SERVICES)
81+
list(APPEND SOURCE src/CompositorServicesUtilitiesMtl.mm)
82+
list(APPEND INTERFACE interface/CompositorServicesUtilities.h)
83+
endif()
84+
8085
set(DEPENDENCIES)
8186

8287
if(D3D11_SUPPORTED)
@@ -164,6 +169,15 @@ if(DILIGENT_USE_OPENXR)
164169
target_compile_definitions(Diligent-GraphicsTools PUBLIC DILIGENT_USE_OPENXR=1)
165170
endif()
166171

172+
if(DILIGENT_USE_COMPOSITOR_SERVICES)
173+
find_library(COMPOSITOR_SERVICES_FRAMEWORK CompositorServices)
174+
find_library(SPATIAL_FRAMEWORK Spatial)
175+
if(COMPOSITOR_SERVICES_FRAMEWORK AND SPATIAL_FRAMEWORK)
176+
target_link_libraries(Diligent-GraphicsTools PRIVATE ${COMPOSITOR_SERVICES_FRAMEWORK} ${SPATIAL_FRAMEWORK})
177+
endif()
178+
target_compile_definitions(Diligent-GraphicsTools PUBLIC DILIGENT_USE_COMPOSITOR_SERVICES=1)
179+
endif()
180+
167181
if(D3D11_SUPPORTED OR D3D12_SUPPORTED)
168182
target_link_libraries(Diligent-GraphicsTools
169183
PRIVATE
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright 2026 Diligent Graphics LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* In no event and under no legal theory, whether in tort (including negligence),
17+
* contract, or otherwise, unless required by applicable law (such as deliberate
18+
* and grossly negligent acts) or agreed to in writing, shall any Contributor be
19+
* liable for any damages, including any direct, indirect, special, incidental,
20+
* or consequential damages of any character arising as a result of this License or
21+
* out of the use or inability to use the software (including but not limited to damages
22+
* for loss of goodwill, work stoppage, computer failure or malfunction, or any and
23+
* all other commercial damages or losses), even if such Contributor has been advised
24+
* of the possibility of such damages.
25+
*/
26+
27+
#pragma once
28+
29+
/// \file
30+
/// CompositorServices utilities for visionOS
31+
32+
#include "../../GraphicsEngine/interface/RenderDevice.h"
33+
#include "../../GraphicsEngine/interface/DeviceContext.h"
34+
#include "../../../Primitives/interface/BasicTypes.h"
35+
#include "../../../Common/interface/BasicMath.hpp"
36+
37+
#include <CompositorServices/CompositorServices.h>
38+
39+
DILIGENT_BEGIN_NAMESPACE(Diligent)
40+
41+
#include "../../../Primitives/interface/DefineRefMacro.h"
42+
43+
/// Type of texture to retrieve from a CompositorServices drawable.
44+
DILIGENT_TYPED_ENUM(COMPOSITOR_SERVICES_TEXTURE_TYPE, Uint8){
45+
/// Color texture (render target).
46+
COMPOSITOR_SERVICES_TEXTURE_TYPE_COLOR = 0,
47+
48+
/// Depth texture.
49+
COMPOSITOR_SERVICES_TEXTURE_TYPE_DEPTH};
50+
51+
/// Returns the number of views (eyes) in a CompositorServices drawable.
52+
///
53+
/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t).
54+
/// \return Number of views (typically 2 for stereo rendering).
55+
Uint32 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesViewCount)(cp_drawable_t Drawable);
56+
57+
/// Returns a Diligent ITexture wrapping the Metal texture from a CompositorServices drawable.
58+
///
59+
/// \param [in] pDevice - Pointer to the render device.
60+
/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t).
61+
/// \param [in] ViewIndex - Index of the view (eye) to get the texture for.
62+
/// \param [in] TexType - Type of texture to retrieve (color or depth).
63+
/// \param [out] ppTexture - Address of the memory location where the pointer to the
64+
/// texture object will be stored.
65+
void DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesSwapchainImage)(IRenderDevice* pDevice,
66+
cp_drawable_t Drawable,
67+
Uint32 ViewIndex,
68+
COMPOSITOR_SERVICES_TEXTURE_TYPE TexType,
69+
ITexture** ppTexture);
70+
71+
/// Returns the projection matrix for a specific view in a CompositorServices drawable.
72+
///
73+
/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t).
74+
/// \param [in] ViewIndex - Index of the view (eye).
75+
/// \param [in] NearZ - Near clipping plane distance.
76+
/// \param [in] FarZ - Far clipping plane distance.
77+
/// \return The 4x4 projection matrix for the specified view.
78+
float4x4 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesProjectionMatrix)(cp_drawable_t Drawable,
79+
Uint32 ViewIndex,
80+
float NearZ,
81+
float FarZ);
82+
83+
/// Returns the view transform matrix for a specific view in a CompositorServices drawable.
84+
///
85+
/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t).
86+
/// \param [in] ViewIndex - Index of the view (eye).
87+
/// \return The 4x4 view transform matrix for the specified view.
88+
float4x4 DILIGENT_GLOBAL_FUNCTION(GetCompositorServicesViewTransform)(cp_drawable_t Drawable,
89+
Uint32 ViewIndex);
90+
91+
/// Presents the CompositorServices drawable by encoding a present command into the
92+
/// Metal command buffer obtained from the device context.
93+
///
94+
/// \param [in] pContext - Pointer to the device context.
95+
/// \param [in] Drawable - CompositorServices drawable (cp_drawable_t) to present.
96+
///
97+
/// This function hides all ObjC++/Metal details from the caller,
98+
/// allowing tutorials to be pure C++.
99+
void DILIGENT_GLOBAL_FUNCTION(PresentCompositorServicesDrawable)(IDeviceContext* pContext,
100+
cp_drawable_t Drawable);
101+
102+
#include "../../../Primitives/interface/UndefRefMacro.h"
103+
104+
DILIGENT_END_NAMESPACE // namespace Diligent

0 commit comments

Comments
 (0)