Skip to content

Commit b9c276c

Browse files
committed
Initial port of imaging code from Thor LTS branch
1 parent e626f90 commit b9c276c

17 files changed

Lines changed: 127 additions & 20 deletions

cmake/defaults/Packages.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ if (PXR_BUILD_IMAGING)
259259
endif()
260260
endif()
261261
# --Opensubdiv
262-
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT})
262+
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT} OR PXR_APPLE_EMBEDDED)
263263
find_package(OpenSubdiv 3 REQUIRED)
264264
# --Ptex
265265
if (PXR_ENABLE_PTEX_SUPPORT)

pxr/imaging/garch/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ 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+
if(PXR_APPLE_EMBEDDED)
15+
set(GARCH_PLATFORM_LIBRARIES "-framework UIKit")
16+
else()
17+
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
18+
endif()
19+
1520
elseif(X11_FOUND)
1621
set(GARCH_GLPLATFORMCONTEXT glPlatformContextGLX)
1722
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowGLX)

pxr/imaging/garch/glPlatformContextDarwin.mm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
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

1312
#ifdef ARCH_OS_IPHONE
13+
#import <UIKit/UIKit.h>
1414
typedef EAGLContext NSGLContext;
1515
#else
16+
#import <AppKit/NSOpenGL.h>
1617
typedef NSOpenGLContext NSGLContext;
1718
#endif
1819

@@ -84,7 +85,11 @@
8485
void
8586
GarchNSGLContextState::DoneCurrent()
8687
{
87-
[NSGLContext clearCurrentContext];
88+
#if defined(ARCH_OS_IPHONE)
89+
[EAGLContext setCurrentContext:nil];
90+
#else
91+
[NSGLContext clearCurrentContext];
92+
#endif
8893
}
8994

9095
GarchGLPlatformContextState
@@ -96,6 +101,9 @@
96101
void *
97102
GarchSelectCoreProfileMacVisual()
98103
{
104+
#if defined(ARCH_OS_IPHONE)
105+
return NULL
106+
#else
99107
NSOpenGLPixelFormatAttribute attribs[10];
100108
int c = 0;
101109

@@ -105,6 +113,7 @@
105113
attribs[c++] = 0;
106114

107115
return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
116+
#endif
108117
}
109118

110119
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
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/hdSt/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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/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()

pxr/imaging/hgiInterop/hgiInterop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void HgiInterop::TransferToApp(
5858
return;
5959
}
6060

61-
#if defined(PXR_GL_SUPPORT_ENABLED)
61+
#if defined(PXR_GL_SUPPORT_ENABLED) && !defined(ARCH_OS_IPHONE)
6262
if (srcApi == HgiTokens->OpenGL) {
6363
// Transfer OpenGL textures to OpenGL application
6464
if (!_hgiInteropImpl->_openGLToOpenGL) {
@@ -86,7 +86,7 @@ void HgiInterop::TransferToApp(
8686
}
8787
#endif
8888

89-
#if defined(PXR_METAL_SUPPORT_ENABLED)
89+
#if defined(PXR_METAL_SUPPORT_ENABLED) && !defined(ARCH_OS_IPHONE)
9090
if (srcApi == HgiTokens->Metal) {
9191
// Transfer Metal textures to OpenGL application
9292
// XXX: It's possible that if we use the same HgiInterop with a

pxr/imaging/hgiMetal/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_METAL_SUPPORT})
77
return()
88
endif()
99

10+
if (PXR_APPLE_EMBEDDED)
11+
set(APPLE_UI_FRAMEWORK "UIKit")
12+
else()
13+
set(APPLE_UI_FRAMEWORK "AppKit")
14+
endif()
15+
1016
pxr_library(hgiMetal
1117
LIBRARIES
1218
arch
1319
hgi
1420
tf
1521
trace
1622
"-framework Metal"
17-
"-framework AppKit"
23+
"-framework ${APPLE_UI_FRAMEWORK}"
1824

1925
PUBLIC_HEADERS
2026
api.h

pxr/imaging/hgiMetal/blitCmds.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,11 @@
203203

204204
mtlDesc.mipmapLevelCount = dstTexDesc.mipLevels;
205205
mtlDesc.arrayLength = dstTexDesc.layerCount;
206+
#if defined(ARCH_OS_OSX)
206207
mtlDesc.resourceOptions = MTLResourceStorageModeManaged;
208+
#else
209+
mtlDesc.resourceOptions = MTLResourceStorageModeShared;
210+
#endif
207211
mtlDesc.sampleCount = 1;
208212
if (dstTexDesc.type == HgiTextureType3D) {
209213
mtlDesc.depth = depth;
@@ -380,11 +384,12 @@
380384
copyOp.gpuSourceBuffer.Get());
381385

382386
_CreateEncoder();
383-
387+
#if defined(ARCH_OS_OSX)
384388
if ([metalBuffer->GetBufferId() storageMode] == MTLStorageModeManaged) {
385389
[_blitEncoder performSelector:@selector(synchronizeResource:)
386390
withObject:metalBuffer->GetBufferId()];
387391
}
392+
#endif
388393

389394
// Offset into the dst buffer
390395
char* dst = ((char*) copyOp.cpuDestinationBuffer) +

pxr/imaging/hgiMetal/capabilities.mm

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
_SetFlag(HgiDeviceCapabilitiesBitsConcurrentDispatch, true);
2424
}
2525

26-
bool const hasIntelGPU = [device isLowPower];
27-
26+
bool hasIntelGPU = false;
27+
#if defined(ARCH_OS_OSX)
28+
hasIntelGPU = [device isLowPower];
29+
#endif
2830
defaultStorageMode = MTLResourceStorageModeShared;
2931
bool unifiedMemory = false;
3032
bool barycentrics = false;
3133
bool hasAppleSilicon = false;
3234
bool icbSupported = false;
35+
bool hasIos = false;
3336
if (@available(macOS 100.100, ios 12.0, *)) {
3437
unifiedMemory = true;
3538
} else if (@available(macOS 10.15, ios 13.0, *)) {
@@ -45,10 +48,16 @@
4548
|| [device areBarycentricCoordsSupported])
4649
&& !hasIntelGPU;
4750

51+
#if defined(ARCH_OS_OSX)
4852
hasAppleSilicon = [device hasUnifiedMemory] && ![device isLowPower];
49-
53+
#endif
5054
}
51-
55+
56+
57+
#if defined(ARCH_OS_IOS)
58+
hasIos = true;
59+
#endif
60+
5261
if (hasAppleSilicon) {
5362
// Indirect command buffers supported only on
5463
// Apple Silicon GPUs with macOS 12.3 or later.
@@ -97,10 +106,14 @@
97106
if (hasIntelGPU) {
98107
_SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true);
99108
}
100-
109+
if (hasIos && !barycentrics) {
110+
_SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true);
111+
}
112+
#if defined(ARCH_OS_OSX)
101113
if (!unifiedMemory) {
102114
defaultStorageMode = MTLResourceStorageModeManaged;
103115
}
116+
#endif
104117

105118
_maxUniformBlockSize = 64 * 1024;
106119
_maxShaderStorageBlockSize = 1 * 1024 * 1024 * 1024;

0 commit comments

Comments
 (0)