Skip to content

Commit 6083bc2

Browse files
committed
Apple: Enable Imaging support for Embedded Platforms
This PR ports Thor's Imaging work onto the latest USD dev branch. It also includes some patches from Maddy Adams and me to suit the current state of USD and its dependencies. There is a single patch to MaterialX to enable support with USD not using OpenGL builds. Additionally, as requested by Nick Porcino, I have added support for shared memory texture handling on the Mac as well where applicable. I've tested this on macOS with Apple Silicon but do not have Intel macs to test with. I've also tested building this for both iOS and visionOS.
1 parent d476c31 commit 6083bc2

27 files changed

Lines changed: 238 additions & 42 deletions

build_scripts/build_usd.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,10 +1534,22 @@ def InstallMaterialX(context, force, buildArgs):
15341534
]
15351535

15361536
if MacOSTargetEmbedded(context):
1537+
# The materialXShaderGen in hdSt assumes the GLSL shadergen is available
1538+
# but MaterialX intertwines GLSL shadergen support with also requiring rendering support.
15371539
cmakeOptions.extend([
15381540
'-DMATERIALX_BUILD_GEN_MSL=ON',
1539-
'-DMATERIALX_BUILD_GEN_GLSL=OFF',
1541+
'-DMATERIALX_BUILD_GEN_GLSL=ON',
15401542
'-DMATERIALX_BUILD_IOS=ON'])
1543+
PatchFile("CMakeLists.txt",
1544+
[(' set(MATERIALX_BUILD_GEN_GLSL OFF)',
1545+
' set(MATERIALX_BUILD_GEN_GLSL ON)'),
1546+
(' if (MATERIALX_BUILD_GEN_GLSL)\n' +
1547+
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
1548+
' endif()',
1549+
' if (MATERIALX_BUILD_GEN_GLSL AND NOT MATERIALX_BUILD_IOS)\n' +
1550+
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
1551+
' endif()')
1552+
], multiLineMatches=True)
15411553

15421554
cmakeOptions += buildArgs
15431555
RunCMake(context, force, cmakeOptions)
@@ -2255,7 +2267,7 @@ def __init__(self, args):
22552267

22562268
# - Imaging
22572269
self.buildImaging = (args.build_imaging == IMAGING or
2258-
args.build_imaging == USD_IMAGING) and not embedded
2270+
args.build_imaging == USD_IMAGING)
22592271
self.enablePtex = self.buildImaging and args.enable_ptex
22602272
self.enableOpenVDB = self.buildImaging and args.enable_openvdb
22612273

cmake/defaults/Options.cmake

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ if(APPLE)
5353
MESSAGE(STATUS "Setting PXR_BUILD_USD_TOOLS=OFF because they are not supported on Apple embedded platforms")
5454
set(PXR_BUILD_USD_TOOLS OFF)
5555
endif()
56-
if (${PXR_BUILD_IMAGING})
57-
MESSAGE(STATUS "Setting PXR_BUILD_USD_IMAGING=OFF because it is not supported on Apple embedded platforms")
58-
set(PXR_BUILD_IMAGING OFF)
59-
endif ()
56+
set(PXR_ENABLE_GL_SUPPORT OFF)
6057
endif ()
6158
endif()
6259

cmake/defaults/Packages.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ if (PXR_BUILD_IMAGING)
254254
endif()
255255
endif()
256256
# --Opensubdiv
257-
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT})
257+
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT} OR PXR_APPLE_EMBEDDED)
258258
find_package(OpenSubdiv 3 REQUIRED)
259259
# --Ptex
260260
if (PXR_ENABLE_PTEX_SUPPORT)

pxr/imaging/garch/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE garch)
33

4-
if (NOT ${PXR_ENABLE_GL_SUPPORT})
4+
if ((NOT ${PXR_ENABLE_GL_SUPPORT}) AND (NOT PXR_APPLE_EMBEDDED))
55
message(STATUS
66
"Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF")
77
return()
@@ -11,7 +11,13 @@ if(APPLE)
1111
set(GARCH_GLPLATFORMCONTEXT glPlatformContextDarwin)
1212
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowDarwin)
1313
set(GARCH_SOURCE_EXTENSION mm)
14-
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
14+
list(APPEND optionalLibs "-framework Foundation")
15+
if(PXR_APPLE_EMBEDDED)
16+
list(APPEND optionalLibs "-framework UIKit")
17+
else()
18+
list(APPEND optionalLibs "-framework AppKit")
19+
endif()
20+
1521
elseif(X11_FOUND)
1622
set(GARCH_GLPLATFORMCONTEXT glPlatformContextGLX)
1723
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowGLX)
@@ -22,13 +28,16 @@ elseif(WIN32)
2228
set(GARCH_SOURCE_EXTENSION cpp)
2329
endif()
2430

31+
if (TARGET OpenGL::GL)
32+
list(APPEND optionalLibs OpenGL::GL)
33+
endif()
34+
2535
pxr_library(garch
2636
LIBRARIES
2737
arch
2838
tf
2939
${X11_LIBRARIES}
30-
OpenGL::GL
31-
${GARCH_PLATFORM_LIBRARIES}
40+
${optionalLibs}
3241

3342
PUBLIC_CLASSES
3443
glApi

pxr/imaging/garch/glPlatformContextDarwin.mm

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,20 @@
55
// https://openusd.org/license.
66
//
77
#import <Foundation/Foundation.h>
8-
#import <AppKit/NSOpenGL.h>
98

109
#include "pxr/pxr.h"
1110
#include "glPlatformContextDarwin.h"
1211

13-
#ifdef ARCH_OS_IPHONE
12+
#if defined(PXR_OPENGL_SUPPORT_ENABLED)
13+
#ifdef ARCH_OS_OSX
14+
#import <AppKit/NSOpenGL.h>
15+
typedef NSOpenGLContext NSGLContext;
16+
#elif defined ARCH_OS_IPHONE
17+
#import <UIKit/UIKit.h>
1418
typedef EAGLContext NSGLContext;
19+
#endif
1520
#else
16-
typedef NSOpenGLContext NSGLContext;
21+
typedef void* NSGLContext;
1722
#endif
1823

1924
PXR_NAMESPACE_OPEN_SCOPE
@@ -22,7 +27,11 @@
2227
{
2328
public:
2429
Detail() {
30+
#if defined(PXR_OPENGL_SUPPORT_ENABLED)
2531
context = [NSGLContext currentContext];
32+
#else
33+
context = nil;
34+
#endif
2635
}
2736
Detail(NullState) {
2837
context = nil;
@@ -73,18 +82,26 @@
7382
void
7483
GarchNSGLContextState::MakeCurrent()
7584
{
76-
#if ARCH_OS_IPHONE
85+
#if defined(PXR_OPENGL_SUPPORT_ENABLED)
86+
#if defined(ARCH_OS_IPHONE)
7787
[EAGLContext setCurrentContext:_detail->context];
7888
#else
7989
[_detail->context makeCurrentContext];
8090
#endif
91+
#endif
8192
}
8293

8394
/// Make no context current.
8495
void
8596
GarchNSGLContextState::DoneCurrent()
8697
{
98+
#if defined(PXR_OPENGL_SUPPORT_ENABLED)
99+
#if defined(ARCH_OS_IPHONE)
100+
[EAGLContext setCurrentContext:nil];
101+
#else
87102
[NSGLContext clearCurrentContext];
103+
#endif
104+
#endif
88105
}
89106

90107
GarchGLPlatformContextState
@@ -96,6 +113,7 @@
96113
void *
97114
GarchSelectCoreProfileMacVisual()
98115
{
116+
#if defined(ARCH_OS_OSX)
99117
NSOpenGLPixelFormatAttribute attribs[10];
100118
int c = 0;
101119

@@ -105,6 +123,9 @@
105123
attribs[c++] = 0;
106124

107125
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
126+
#else // ARCH_OS_MACOS
127+
return NULL;
128+
#endif
108129
}
109130

110131
PXR_NAMESPACE_CLOSE_SCOPE

pxr/imaging/garch/glPlatformDebugWindowDarwin.mm

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@
99
#include "pxr/imaging/garch/glDebugWindow.h"
1010
#include "pxr/imaging/garch/glPlatformDebugWindowDarwin.h"
1111

12+
#if defined(ARCH_OS_OSX)
1213
#import <Cocoa/Cocoa.h>
1314
#import <OpenGL/OpenGL.h>
1415
#import <OpenGL/gl.h>
16+
#endif
1517

1618
PXR_NAMESPACE_USING_DIRECTIVE
1719

20+
#if defined(ARCH_OS_OSX)
21+
1822
static int
1923
Garch_GetModifierKeys(NSUInteger flags)
2024
{
@@ -222,4 +226,30 @@ - (void)keyDown:(NSEvent *)event
222226
[NSApp stop:nil];
223227
}
224228

229+
#else // IPHONE Derivatives
230+
231+
PXR_NAMESPACE_OPEN_SCOPE
232+
233+
Garch_GLPlatformDebugWindow::Garch_GLPlatformDebugWindow(GarchGLDebugWindow *w)
234+
{
235+
236+
}
237+
238+
void Garch_GLPlatformDebugWindow::Init(const char *title, int width, int height, int nSamples)
239+
{
240+
241+
}
242+
243+
void
244+
Garch_GLPlatformDebugWindow::Run()
245+
{
246+
}
247+
248+
void
249+
Garch_GLPlatformDebugWindow::ExitApp()
250+
{
251+
}
252+
#endif
253+
225254
PXR_NAMESPACE_CLOSE_SCOPE
255+

pxr/imaging/glf/CMakeLists.txt

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,29 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE glf)
33

4+
45
if (NOT ${PXR_ENABLE_GL_SUPPORT})
56
message(STATUS
6-
"Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF")
7-
return()
7+
"Building minimal ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF")
8+
if (NOT PXR_APPLE_EMBEDDED)
9+
list(APPEND optionalLibs ${OPENGL_gl_LIBRARY})
10+
endif()
11+
else ()
12+
list(APPEND optionalLibs ${Boost_PYTHON_LIBRARY})
13+
list(APPEND optionalLibs ${X11_LIBRARIES})
14+
if (TARGET OpenGL::GL)
15+
list(APPEND optionalLibs OpenGL::GL)
16+
endif()
817
endif()
918

1019
set(optionalPublicClasses "")
1120
if (X11_FOUND)
1221
list(APPEND optionalPublicClasses testGLContext)
1322
endif()
1423

24+
set(optionalLibs "")
25+
set(optionalIncludeDirs "")
26+
1527
pxr_library(glf
1628
LIBRARIES
1729
ar
@@ -24,8 +36,11 @@ pxr_library(glf
2436
tf
2537
trace
2638
sdf
27-
OpenGL::GL
28-
${X11_LIBRARIES}
39+
${optionalLibs}
40+
41+
INCLUDE_DIRS
42+
${Boost_INCLUDE_DIRS}
43+
${optionalIncludeDirs}
2944

3045
PUBLIC_CLASSES
3146
bindingMap
@@ -51,6 +66,9 @@ pxr_library(glf
5166
PUBLIC_HEADERS
5267
api.h
5368

69+
CPPFILES
70+
${optionalCppFiles}
71+
5472
PYTHON_CPPFILES
5573
moduleDeps.cpp
5674

pxr/imaging/hdSt/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(PXR_PACKAGE hdSt)
33

44
# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Storm currently still only
55
# runs on OpenGL. Once Storm uses only Hgi, remove GL_SUPPORT check.
6-
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
6+
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT (${PXR_ENABLE_GL_SUPPORT} OR PXR_APPLE_EMBEDDED))
77
message(STATUS
88
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")
99
return()
@@ -13,6 +13,11 @@ set(optionalLibs "")
1313
set(optionalIncludeDirs "")
1414
set(optionalPublicClasses "")
1515
set(optionalPrivateClasses "")
16+
17+
if (NOT (PXR_APPLE_EMBEDDED))
18+
list(APPEND optionalLibs hgiGL)
19+
endif()
20+
1621
if (${PXR_ENABLE_MATERIALX_SUPPORT})
1722
list(APPEND optionalLibs
1823
MaterialXGenShader
@@ -41,7 +46,6 @@ pxr_library(hdSt
4146
glf
4247
hd
4348
hdsi
44-
hgiGL
4549
hgiInterop
4650
sdr
4751
tf

pxr/imaging/hdx/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set(PXR_PACKAGE hdx)
33

44
# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Hdx currently still uses
55
# OpenGL directly. Once Hdx uses only Hgi, remove GL_SUPPORT check.
6-
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
6+
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT} AND NOT PXR_APPLE_EMBEDDED)
77
message(STATUS
88
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")
99
return()

pxr/imaging/hgiGL/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(PXR_PREFIX pxr/imaging)
22
set(PXR_PACKAGE hgiGL)
33

4-
if (NOT ${PXR_ENABLE_GL_SUPPORT})
4+
if (NOT ${PXR_ENABLE_GL_SUPPORT} AND NOT PXR_APPLE_EMBEDDED)
55
message(STATUS
66
"Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF")
77
return()

0 commit comments

Comments
 (0)