Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ 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

Expand All @@ -2272,8 +2272,8 @@ 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.buildOIIO = (args.build_oiio or (self.buildUsdImaging
and self.buildTests))
self.buildOCIO = args.build_ocio

# - Alembic Plugin
Expand Down
2 changes: 1 addition & 1 deletion cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ if (PXR_BUILD_IMAGING)
endif()
endif()
# --Opensubdiv
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT})
set(OPENSUBDIV_USE_GPU ${PXR_ENABLE_GL_SUPPORT} OR PXR_APPLE_EMBEDDED)
find_package(OpenSubdiv 3 REQUIRED)
# --Ptex
if (PXR_ENABLE_PTEX_SUPPORT)
Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/garch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ if(APPLE)
set(GARCH_GLPLATFORMCONTEXT glPlatformContextDarwin)
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowDarwin)
set(GARCH_SOURCE_EXTENSION mm)
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
if(PXR_APPLE_EMBEDDED)
set(GARCH_PLATFORM_LIBRARIES "-framework UIKit")
else()
set(GARCH_PLATFORM_LIBRARIES "-framework AppKit")
endif()

elseif(X11_FOUND)
set(GARCH_GLPLATFORMCONTEXT glPlatformContextGLX)
set(GARCH_GLPLATFORMDEBUGWINDOW glPlatformDebugWindowGLX)
Expand Down
13 changes: 11 additions & 2 deletions pxr/imaging/garch/glPlatformContextDarwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
// https://openusd.org/license.
//
#import <Foundation/Foundation.h>
#import <AppKit/NSOpenGL.h>

#include "pxr/pxr.h"
#include "glPlatformContextDarwin.h"

#ifdef ARCH_OS_IPHONE
#import <UIKit/UIKit.h>
typedef EAGLContext NSGLContext;
#else
#import <AppKit/NSOpenGL.h>
typedef NSOpenGLContext NSGLContext;
#endif

Expand Down Expand Up @@ -84,7 +85,11 @@
void
GarchNSGLContextState::DoneCurrent()
{
[NSGLContext clearCurrentContext];
#if defined(ARCH_OS_IPHONE)
[EAGLContext setCurrentContext:nil];
#else
[NSGLContext clearCurrentContext];
#endif
}

GarchGLPlatformContextState
Expand All @@ -96,6 +101,9 @@
void *
GarchSelectCoreProfileMacVisual()
{
#if defined(ARCH_OS_IPHONE)
return NULL
#else
NSOpenGLPixelFormatAttribute attribs[10];
int c = 0;

Expand All @@ -105,6 +113,7 @@
attribs[c++] = 0;

return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
#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 @@ -222,4 +226,30 @@ - (void)keyDown:(NSEvent *)event
[NSApp stop:nil];
}

#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()
{
}
#endif

PXR_NAMESPACE_CLOSE_SCOPE

6 changes: 5 additions & 1 deletion pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ set(optionalLibs "")
set(optionalIncludeDirs "")
set(optionalPublicClasses "")
set(optionalPrivateClasses "")

if (NOT (PXR_APPLE_EMBEDDED))
list(APPEND optionalLibs hgiGL)
endif()

if (${PXR_ENABLE_MATERIALX_SUPPORT})
list(APPEND optionalLibs
MaterialXGenShader
Expand Down Expand Up @@ -41,7 +46,6 @@ pxr_library(hdSt
glf
hd
hdsi
hgiGL
hgiInterop
sdr
tf
Expand Down
2 changes: 1 addition & 1 deletion pxr/imaging/hgiGL/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(PXR_PREFIX pxr/imaging)
set(PXR_PACKAGE hgiGL)

if (NOT ${PXR_ENABLE_GL_SUPPORT})
if (NOT ${PXR_ENABLE_GL_SUPPORT} AND NOT PXR_APPLE_EMBEDDED)
Comment thread
meshula marked this conversation as resolved.
message(STATUS
"Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF")
return()
Expand Down
4 changes: 2 additions & 2 deletions pxr/imaging/hgiInterop/hgiInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,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 +86,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
8 changes: 7 additions & 1 deletion pxr/imaging/hgiMetal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ 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 Metal"
"-framework AppKit"
"-framework ${APPLE_UI_FRAMEWORK}"

PUBLIC_HEADERS
api.h
Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/hgiMetal/blitCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@

mtlDesc.mipmapLevelCount = dstTexDesc.mipLevels;
mtlDesc.arrayLength = dstTexDesc.layerCount;
#if defined(ARCH_OS_OSX)
mtlDesc.resourceOptions = MTLResourceStorageModeManaged;
#else
mtlDesc.resourceOptions = MTLResourceStorageModeShared;
#endif
mtlDesc.sampleCount = 1;
if (dstTexDesc.type == HgiTextureType3D) {
mtlDesc.depth = depth;
Expand Down Expand Up @@ -380,11 +384,12 @@
copyOp.gpuSourceBuffer.Get());

_CreateEncoder();

#if defined(ARCH_OS_OSX)
if ([metalBuffer->GetBufferId() storageMode] == MTLStorageModeManaged) {
[_blitEncoder performSelector:@selector(synchronizeResource:)
withObject:metalBuffer->GetBufferId()];
}
#endif

// Offset into the dst buffer
char* dst = ((char*) copyOp.cpuDestinationBuffer) +
Expand Down
23 changes: 18 additions & 5 deletions pxr/imaging/hgiMetal/capabilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@
_SetFlag(HgiDeviceCapabilitiesBitsConcurrentDispatch, true);
}

bool const hasIntelGPU = [device isLowPower];

bool hasIntelGPU = false;
#if defined(ARCH_OS_OSX)
hasIntelGPU = [device isLowPower];
#endif
defaultStorageMode = MTLResourceStorageModeShared;
bool unifiedMemory = false;
bool barycentrics = false;
bool hasAppleSilicon = false;
bool icbSupported = false;
bool hasIos = false;
if (@available(macOS 100.100, ios 12.0, *)) {
unifiedMemory = true;
} else if (@available(macOS 10.15, ios 13.0, *)) {
Expand All @@ -45,10 +48,16 @@
|| [device areBarycentricCoordsSupported])
&& !hasIntelGPU;

#if defined(ARCH_OS_OSX)
hasAppleSilicon = [device hasUnifiedMemory] && ![device isLowPower];
#endif
}



#if defined(ARCH_OS_IOS)
hasIos = true;
#endif

if (hasAppleSilicon) {
// Indirect command buffers supported only on
// Apple Silicon GPUs with macOS 12.3 or later.
Expand Down Expand Up @@ -97,10 +106,14 @@
if (hasIntelGPU) {
_SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true);
}

if (hasIos && !barycentrics) {
_SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true);
}
#if defined(ARCH_OS_OSX)
if (!unifiedMemory) {
defaultStorageMode = MTLResourceStorageModeManaged;
}
#endif

_maxUniformBlockSize = 64 * 1024;
_maxShaderStorageBlockSize = 1 * 1024 * 1024 * 1024;
Expand Down
2 changes: 2 additions & 0 deletions pxr/imaging/hgiMetal/computeCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
thread_height = maxTotalThreads / thread_width;
}

#if defined(ARCH_OS_OSX)
if (_argumentBuffer.storageMode != MTLStorageModeShared &&
[_argumentBuffer respondsToSelector:@selector(didModifyRange:)]) {
NSRange range = NSMakeRange(0, _argumentBuffer.length);
Expand All @@ -129,6 +130,7 @@
[_argumentBuffer didModifyRange:range];
ARCH_PRAGMA_POP
}
#endif

[_encoder dispatchThreads:MTLSizeMake(dimX, dimY, 1)
threadsPerThreadgroup:MTLSizeMake(MIN(thread_width, dimX),
Expand Down
10 changes: 9 additions & 1 deletion pxr/imaging/hgiMetal/conversions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,21 @@

//MTLPixelFormatRGB8Unorm_sRGB, // Unsupported by HgiFormat
MTLPixelFormatRGBA8Unorm_sRGB, // HgiFormatUNorm8Vec4srgb,

#if defined(ARCH_OS_IPHONE)
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
MTLPixelFormatInvalid, // Unsupported by iOS Metal
#else
MTLPixelFormatBC6H_RGBFloat, // HgiFormatBC6FloatVec3
MTLPixelFormatBC6H_RGBUfloat, // HgiFormatBC6UFloatVec3
MTLPixelFormatBC7_RGBAUnorm, // HgiFormatBC7UNorm8Vec4
MTLPixelFormatBC7_RGBAUnorm_sRGB, // HgiFormatBC7UNorm8Vec4srgb
MTLPixelFormatBC1_RGBA, // HgiFormatBC1UNorm8Vec4
MTLPixelFormatBC3_RGBA, // HgiFormatBC3UNorm8Vec4
#endif

MTLPixelFormatDepth32Float_Stencil8, // HgiFormatFloat32UInt8

Expand Down
7 changes: 6 additions & 1 deletion pxr/imaging/hgiMetal/graphicsCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@
HgiMetalGraphicsCmds::_SyncArgumentBuffer()
{
if (_argumentBuffer) {
#if defined(ARCH_OS_OSX)
if (_argumentBuffer.storageMode != MTLStorageModeShared &&
[_argumentBuffer respondsToSelector:@selector(didModifyRange:)]) {

Expand All @@ -400,6 +401,7 @@
[_argumentBuffer didModifyRange:{0, _argumentBuffer.length}];
ARCH_PRAGMA_POP
}
#endif
_argumentBuffer = nil;
}
}
Expand Down Expand Up @@ -805,7 +807,9 @@

// Apple Silicon only support memory barriers between vertex stages after
// macOS 12.3.
if (@available(macOS 12.3, *)) {
//For iOS we may want to introduce an alternative path
#if defined(ARCH_OS_OSX)
if (@available(macOS 12.3, ios 16.0, *)) {
MTLBarrierScope scope = MTLBarrierScopeBuffers;
MTLRenderStages srcStages = MTLRenderStageVertex;
MTLRenderStages dstStages = MTLRenderStageVertex;
Expand All @@ -816,6 +820,7 @@
beforeStages:dstStages];
}
}
#endif
}

static
Expand Down
3 changes: 2 additions & 1 deletion pxr/imaging/hgiMetal/hgi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void Drain() {}
, _pool(std::make_unique<AutoReleasePool>())
{
if (!_device) {
#if defined(ARCH_OS_OSX)
if( TfGetenvBool("HGIMETAL_USE_INTEGRATED_GPU", false)) {
auto devices = MTLCopyAllDevices();
for (id<MTLDevice> d in devices) {
Expand All @@ -78,7 +79,7 @@ void Drain() {}
}
}
}

#endif
if (!_device) {
_device = MTLCreateSystemDefaultDevice();
}
Expand Down
Loading