Skip to content

Commit

Permalink
Merge pull request #3215 from dgovil/ios-imaging
Browse files Browse the repository at this point in the history
Apple: Enable Imaging support for Embedded Platforms

(Internal change: 2343224)
  • Loading branch information
pixar-oss committed Oct 2, 2024
2 parents edbde59 + bb98ff8 commit 0900db8
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 66 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ to use a monolithic build when embedding USD

These builds do not support Python bindings or command line tools.

Currently, these builds also do not support Imaging or USD Imaging.

For example, the following will download, build, and install USD's dependencies,
then build and install USD for iOS into `/path/to/my_usd_install_dir`.

Expand Down
42 changes: 32 additions & 10 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,23 @@ def InstallMaterialX(context, force, buildArgs):
]

if MacOSTargetEmbedded(context):
# The materialXShaderGen in hdSt assumes the GLSL shadergen is
# available but MaterialX intertwines GLSL shadergen support with
# also requiring rendering support.
cmakeOptions.extend([
'-DMATERIALX_BUILD_GEN_MSL=ON',
'-DMATERIALX_BUILD_GEN_GLSL=OFF',
'-DMATERIALX_BUILD_GEN_GLSL=ON',
'-DMATERIALX_BUILD_IOS=ON'])
PatchFile("CMakeLists.txt",
[(' set(MATERIALX_BUILD_GEN_GLSL OFF)',
' set(MATERIALX_BUILD_GEN_GLSL ON)'),
(' if (MATERIALX_BUILD_GEN_GLSL)\n' +
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
' endif()',
' if (MATERIALX_BUILD_GEN_GLSL AND NOT MATERIALX_BUILD_IOS)\n' +
' add_subdirectory(source/MaterialXRenderGlsl)\n' +
' endif()')
], multiLineMatches=True)

cmakeOptions += buildArgs
RunCMake(context, force, cmakeOptions)
Expand Down Expand Up @@ -1830,8 +1843,8 @@ def InstallUSD(context, force, buildArgs):
- Embedded Build Targets
When cross compiling for an embedded target operating system, e.g. iOS, the
following components are disabled: python, tools, imaging, tests, examples,
tutorials.
following components are disabled: python, tools, tests, examples, tutorials,
opencolorio, openimageio, openvdb.
- Python Versions and DCC Plugins:
Some DCCs may ship with and run using their own version of Python. In that case,
Expand Down Expand Up @@ -2265,9 +2278,11 @@ def __init__(self, args):

# - Imaging
self.buildImaging = (args.build_imaging == IMAGING or
args.build_imaging == USD_IMAGING) and not embedded
args.build_imaging == USD_IMAGING)
self.enablePtex = self.buildImaging and args.enable_ptex
self.enableOpenVDB = self.buildImaging and args.enable_openvdb
self.enableOpenVDB = (self.buildImaging
and args.enable_openvdb
and not embedded)

# - USD Imaging
self.buildUsdImaging = (args.build_imaging == USD_IMAGING)
Expand All @@ -2282,9 +2297,10 @@ def __init__(self, args):
self.buildPrman = self.buildImaging and args.build_prman
self.prmanLocation = (os.path.abspath(args.prman_location)
if args.prman_location else None)
self.buildOIIO = args.build_oiio or (self.buildUsdImaging
and self.buildTests)
self.buildOCIO = args.build_ocio
self.buildOIIO = ((args.build_oiio or (self.buildUsdImaging
and self.buildTests))
and not embedded)
self.buildOCIO = args.build_ocio and not embedded

# - Alembic Plugin
self.buildAlembic = args.build_alembic
Expand Down Expand Up @@ -2421,8 +2437,14 @@ def ForceBuildDependency(self, dep):
if "--tools" in sys.argv:
PrintError("Cannot build tools for embedded build targets")
sys.exit(1)
if "--imaging" in sys.argv:
PrintError("Cannot build imaging for embedded build targets")
if "--openimageio" in sys.argv:
PrintError("Cannot build openimageio for embedded build targets")
sys.exit(1)
if "--opencolorio" in sys.argv:
PrintError("Cannot build opencolorio for embedded build targets")
sys.exit(1)
if "--openvdb" in sys.argv:
PrintError("Cannot build openvdb for embedded build targets")
sys.exit(1)

# Error out if user explicitly specified building usdview without required
Expand Down
16 changes: 12 additions & 4 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ if(APPLE)
MESSAGE(STATUS "Setting PXR_BUILD_USD_TOOLS=OFF because they are not supported on Apple embedded platforms")
set(PXR_BUILD_USD_TOOLS OFF)
endif()
if (${PXR_BUILD_IMAGING})
MESSAGE(STATUS "Setting PXR_BUILD_USD_IMAGING=OFF because it is not supported on Apple embedded platforms")
set(PXR_BUILD_IMAGING OFF)
endif ()
if(${PXR_BUILD_OPENCOLORIO_PLUGIN})
MESSAGE(STATUS "Setting PXR_BUILD_OPENCOLORIO_PLUGIN=OFF because it is not supported on Apple embedded platforms")
set(PXR_BUILD_OPENCOLORIO_PLUGIN OFF)
endif()
if(${PXR_BUILD_OPENIMAGEIO_PLUGIN})
MESSAGE(STATUS "Setting PXR_BUILD_OPENIMAGEIO_PLUGIN=OFF because it is not supported on Apple embedded platforms")
set(PXR_BUILD_OPENIMAGEIO_PLUGIN OFF)
endif()
if(${PXR_ENABLE_OPENVDB_SUPPORT})
MESSAGE(STATUS "Setting PXR_ENABLE_OPENVDB_SUPPORT=OFF because it is not supported on Apple embedded platforms")
set(PXR_ENABLE_OPENVDB_SUPPORT OFF)
endif()
endif ()
endif()

Expand Down
4 changes: 2 additions & 2 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ if (PXR_BUILD_IMAGING)
add_definitions(-DPXR_OCIO_PLUGIN_ENABLED)
endif()
# --OpenGL
if (PXR_ENABLE_GL_SUPPORT)
if (PXR_ENABLE_GL_SUPPORT AND NOT PXR_APPLE_EMBEDDED)
# Prefer legacy GL library over GLVND libraries if both
# are installed.
if (POLICY CMP0072)
Expand Down Expand Up @@ -250,7 +250,7 @@ if (PXR_BUILD_IMAGING)
endif()
endif()
# --Opensubdiv
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT})
set(OPENSUBDIV_USE_GPU ${PXR_BUILD_GPU_SUPPORT})
find_package(OpenSubdiv 3 REQUIRED)
# --Ptex
if (PXR_ENABLE_PTEX_SUPPORT)
Expand Down
12 changes: 9 additions & 3 deletions pxr/imaging/garch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@ if(APPLE)
set(GARCH_GLPLATFORMCONTEXT glPlatformContextDarwin)
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowDarwin)
set(GARCH_SOURCE_EXTENSION mm)
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
set(GARCH_PLATFORM_LIBRARIES "-framework Foundation")
if (PXR_APPLE_EMBEDDED)
list(APPEND GARCH_PLATFORM_LIBRARIES "-framework UIKit")
else()
list(APPEND GARCH_PLATFORM_LIBRARIES "-framework AppKit")
list(APPEND GARCH_PLATFORM_LIBRARIES OpenGL::GL)
endif()
elseif(X11_FOUND)
set(GARCH_GLPLATFORMCONTEXT glPlatformContextGLX)
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowGLX)
set(GARCH_SOURCE_EXTENSION cpp)
set(GARCH_PLATFORM_LIBRARIES ${X11_LIBRARIES} OpenGL::GL)
elseif(WIN32)
set(GARCH_GLPLATFORMCONTEXT glPlatformContextWindows)
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowWindows)
set(GARCH_SOURCE_EXTENSION cpp)
set(GARCH_PLATFORM_LIBRARIES OpenGL::GL)
endif()

pxr_library(garch
LIBRARIES
arch
tf
${X11_LIBRARIES}
OpenGL::GL
${GARCH_PLATFORM_LIBRARIES}

PUBLIC_CLASSES
Expand Down
28 changes: 18 additions & 10 deletions pxr/imaging/garch/glPlatformContextDarwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#import <Foundation/Foundation.h>
#import <AppKit/NSOpenGL.h>
#include "pxr/imaging/garch/glPlatformContextDarwin.h"

#include "pxr/pxr.h"
#include "glPlatformContextDarwin.h"
#include "pxr/base/arch/defines.h"

#ifdef ARCH_OS_IPHONE
typedef EAGLContext NSGLContext;
#import <Foundation/Foundation.h>
#if defined(ARCH_OS_OSX)
#import <AppKit/NSOpenGL.h>
using NSGLContext = NSOpenGLContext;
#else
typedef NSOpenGLContext NSGLContext;
using NSGLContext = void;
#endif

PXR_NAMESPACE_OPEN_SCOPE
Expand All @@ -22,7 +22,11 @@
{
public:
Detail() {
#if defined(ARCH_OS_OSX)
context = [NSGLContext currentContext];
#else
context = nil;
#endif
}
Detail(NullState) {
context = nil;
Expand Down Expand Up @@ -73,9 +77,7 @@
void
GarchNSGLContextState::MakeCurrent()
{
#if ARCH_OS_IPHONE
[EAGLContext setCurrentContext:_detail->context];
#else
#if defined(ARCH_OS_OSX)
[_detail->context makeCurrentContext];
#endif
}
Expand All @@ -84,7 +86,9 @@
void
GarchNSGLContextState::DoneCurrent()
{
#if defined(ARCH_OS_OSX)
[NSGLContext clearCurrentContext];
#endif
}

GarchGLPlatformContextState
Expand All @@ -96,6 +100,7 @@
void *
GarchSelectCoreProfileMacVisual()
{
#if defined(ARCH_OS_OSX)
NSOpenGLPixelFormatAttribute attribs[10];
int c = 0;

Expand All @@ -105,6 +110,9 @@
attribs[c++] = 0;

return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
#else // ARCH_OS_MACOS
return nullptr;
#endif
}

PXR_NAMESPACE_CLOSE_SCOPE
30 changes: 30 additions & 0 deletions pxr/imaging/garch/glPlatformDebugWindowDarwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
#include "pxr/imaging/garch/glDebugWindow.h"
#include "pxr/imaging/garch/glPlatformDebugWindowDarwin.h"

#if defined(ARCH_OS_OSX)
#import <Cocoa/Cocoa.h>
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#endif

PXR_NAMESPACE_USING_DIRECTIVE

#if defined(ARCH_OS_OSX)

static int
Garch_GetModifierKeys(NSUInteger flags)
{
Expand Down Expand Up @@ -223,3 +227,29 @@ - (void)keyDown:(NSEvent *)event
}

PXR_NAMESPACE_CLOSE_SCOPE

#else // IPHONE Derivatives

PXR_NAMESPACE_OPEN_SCOPE

Garch_GLPlatformDebugWindow::Garch_GLPlatformDebugWindow(GarchGLDebugWindow *w)
{
}

void Garch_GLPlatformDebugWindow::Init(const char *title, int width, int height, int nSamples)
{
}

void
Garch_GLPlatformDebugWindow::Run()
{
}

void
Garch_GLPlatformDebugWindow::ExitApp()
{
}

PXR_NAMESPACE_CLOSE_SCOPE

#endif
2 changes: 0 additions & 2 deletions pxr/imaging/glf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ pxr_library(glf
tf
trace
sdf
OpenGL::GL
${X11_LIBRARIES}

PUBLIC_CLASSES
bindingMap
Expand Down
4 changes: 2 additions & 2 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(PXR_PREFIX pxr/imaging)
set(PXR_PACKAGE hdSt)

# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Storm currently still only
# runs on OpenGL. Once Storm uses only Hgi, remove GL_SUPPORT check.
# XXX We check for PXR_ENABLE_GL_SUPPORT since Storm currently still uses
# GL via GarchGLApi. Once Storm uses only Hgi, remove GL_SUPPORT check.
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
message(STATUS
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")
Expand Down
4 changes: 2 additions & 2 deletions pxr/imaging/hdx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
set(PXR_PREFIX pxr/imaging)
set(PXR_PACKAGE hdx)

# XXX We tmp check for PXR_ENABLE_GL_SUPPORT since Hdx currently still uses
# OpenGL directly. Once Hdx uses only Hgi, remove GL_SUPPORT check.
# XXX We check for PXR_ENABLE_GL_SUPPORT since Hdx currently still uses
# GL via GarchGLApi. Once Hdx uses only Hgi, remove GL_SUPPORT check.
if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT})
message(STATUS
"Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF")
Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/hgiInterop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ endif()

if (PXR_ENABLE_METAL_SUPPORT)
add_compile_options(-x objective-c++)
list(APPEND optionalLibraries "-framework CoreVideo" hgiMetal)
list(APPEND optionalLibraries hgiMetal)
endif()

if (PXR_ENABLE_METAL_SUPPORT AND NOT PXR_APPLE_EMBEDDED)
list(APPEND optionalLibraries "-framework Foundation")
list(APPEND optionalLibraries "-framework CoreVideo")
list(APPEND optionalCppFiles metal.mm)
list(APPEND optionalPrivateHeaders metal.h)
endif()
Expand Down
8 changes: 5 additions & 3 deletions pxr/imaging/hgiInterop/hgiInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@

#if defined(PXR_METAL_SUPPORT_ENABLED)
#include "pxr/imaging/hgiMetal/hgi.h"
#if defined(ARCH_OS_OSX)
#include "pxr/imaging/hgiInterop/metal.h"
#endif
#endif

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -31,7 +33,7 @@ struct HgiInteropImpl
#if defined(PXR_VULKAN_SUPPORT_ENABLED)
std::unique_ptr<HgiInteropVulkan> _vulkanToOpenGL;
#endif
#if defined(PXR_METAL_SUPPORT_ENABLED)
#if defined(PXR_METAL_SUPPORT_ENABLED) && !defined(ARCH_OS_IPHONE)
std::unique_ptr<HgiInteropMetal> _metalToOpenGL;
#endif
};
Expand All @@ -58,7 +60,7 @@ void HgiInterop::TransferToApp(
return;
}

#if defined(PXR_GL_SUPPORT_ENABLED)
#if defined(PXR_GL_SUPPORT_ENABLED) && !defined(ARCH_OS_IPHONE)
if (srcApi == HgiTokens->OpenGL) {
// Transfer OpenGL textures to OpenGL application
if (!_hgiInteropImpl->_openGLToOpenGL) {
Expand Down Expand Up @@ -86,7 +88,7 @@ void HgiInterop::TransferToApp(
}
#endif

#if defined(PXR_METAL_SUPPORT_ENABLED)
#if defined(PXR_METAL_SUPPORT_ENABLED) && !defined(ARCH_OS_IPHONE)
if (srcApi == HgiTokens->Metal) {
// Transfer Metal textures to OpenGL application
// XXX: It's possible that if we use the same HgiInterop with a
Expand Down
9 changes: 8 additions & 1 deletion pxr/imaging/hgiMetal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_METAL_SUPPORT})
return()
endif()

if (PXR_APPLE_EMBEDDED)
set(APPLE_UI_FRAMEWORK "UIKit")
else()
set(APPLE_UI_FRAMEWORK "AppKit")
endif()

pxr_library(hgiMetal
LIBRARIES
arch
hgi
tf
trace
"-framework Foundation"
"-framework Metal"
"-framework AppKit"
"-framework ${APPLE_UI_FRAMEWORK}"

PUBLIC_HEADERS
api.h
Expand Down
Loading

0 comments on commit 0900db8

Please sign in to comment.