Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.DS_Store
.AppleDouble

_build
10 changes: 10 additions & 0 deletions build_ios.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

# Generates and builds USD for iOS using Xcode as the generator.
# To get the values for 'CMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM' and 'CMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY' open already signed Xcode project's 'project.pbxproj; using text editor and look for those.

set -e

clear
rm -rf _build
python3 ./build_scripts/build_usd.py --build-target "iOS" --generator "Xcode" --cmake-build-args "\-DXCODE_ATTRIBUTE_CODE_SIGN_STYLE=\"Automatic\" \-DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM=\"M369BC24W9\" \-DCMAKE_XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY=\"Apple Development\"" --verbose --build-monolithic --usd-imaging --no-materialx --no-usdview --no-examples --no-tutorials --no-tools --no-python _build
11 changes: 9 additions & 2 deletions build_scripts/apple_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@
TARGET_UNIVERSAL = "universal"
TARGET_IOS = "iOS"
TARGET_VISIONOS = "visionOS"
TARGET_IPHONE_SIMULATOR= "iPhoneSimulator"

EMBEDDED_PLATFORMS = [TARGET_IOS, TARGET_VISIONOS]
EMBEDDED_PLATFORMS = [TARGET_IOS, TARGET_VISIONOS, TARGET_IPHONE_SIMULATOR]

def GetBuildTargets():
return [TARGET_NATIVE,
TARGET_X86,
TARGET_ARM64,
TARGET_UNIVERSAL,
TARGET_IOS,
TARGET_VISIONOS]
TARGET_VISIONOS,
TARGET_IPHONE_SIMULATOR]

def GetBuildTargetDefault():
return TARGET_NATIVE
Expand Down Expand Up @@ -126,6 +128,8 @@ def GetSDKRoot(context) -> Optional[str]:
sdk = "iphoneos"
elif context.buildTarget == TARGET_VISIONOS:
sdk = "xros"
elif context.buildTarget == TARGET_IPHONE_SIMULATOR:
sdk = "iphonesimulator"

for arg in (context.cmakeBuildArgs or '').split():
if "CMAKE_OSX_SYSROOT" in arg:
Expand All @@ -141,6 +145,7 @@ def SetTarget(context, targetName):
context.targetUniversal = (targetName == TARGET_UNIVERSAL)
context.targetIOS = (targetName == TARGET_IOS)
context.targetVisionOS = (targetName == TARGET_VISIONOS)
context.targetIPhoneSimulator = (targetName == TARGET_IPHONE_SIMULATOR)
if context.targetUniversal and not SupportsMacOSUniversalBinaries():
context.targetUniversal = False
raise ValueError(
Expand Down Expand Up @@ -235,6 +240,8 @@ def ConfigureCMakeExtraArgs(context, args:List[str]) -> List[str]:
system_name = None
if TargetEmbeddedOS(context):
system_name = context.buildTarget
if system_name == TARGET_IPHONE_SIMULATOR:
system_name = TARGET_IOS

if system_name:
args.append(f"-DCMAKE_SYSTEM_NAME={system_name}")
Expand Down
31 changes: 27 additions & 4 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,32 @@ def InstallTBB_MacOS(context, force, buildArgs):
("iPhone", "XR"),
("IPHONEOS","XROS")])

if context.buildTarget == apple_utils.TARGET_IPHONE_SIMULATOR:
# Create iPhoneSimulator config from iOS config
shutil.copy(
src="build/ios.macos.inc",
dst="build/iphonesimulator.macos.inc")

PatchFile("build/iphonesimulator.macos.inc",
[("ios","iphonesimulator"),
("iOS", "iPhoneSimulator"),
("iPhoneOS", "iPhoneSimulator"),
("?= 8.0", "?= 8.0")])

# iOS clang just reuses the macOS one,
# so it's easier to copy it directly.
shutil.copy(src="build/macos.clang.inc",
dst="build/iphonesimulator.clang.inc")

# arm64-apple-iphonesimulator
# ios-arm64-simulator
PatchFile("build/iphonesimulator.clang.inc",
[("ios","iphonesimulator"),
("-miphoneos-version-min=", "-target arm64-apple-ios17.5-simulator"),
("iOS", "iPhoneSimulator"),
("iPhone", "iPhoneSimulator"),
("$(IPHONEOS_DEPLOYMENT_TARGET)", "")])

(primaryArch, secondaryArch) = apple_utils.GetTargetArchPair(context)

# tbb uses different arch names
Expand Down Expand Up @@ -2255,7 +2281,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 Down Expand Up @@ -2411,9 +2437,6 @@ 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")
sys.exit(1)

# Error out if user explicitly specified building usdview without required
# components. Otherwise, usdview will be silently disabled. This lets users
Expand Down
4 changes: 2 additions & 2 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if(APPLE)
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)
# set(PXR_BUILD_IMAGING OFF)
endif ()
endif ()
endif()
Expand All @@ -68,7 +68,7 @@ if(APPLE)
endif()
option(PXR_ENABLE_METAL_SUPPORT "Enable Metal based components" "${pxr_enable_metal}")
option(PXR_ENABLE_VULKAN_SUPPORT "Enable Vulkan based components" OFF)
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" OFF)

# Precompiled headers are a win on Windows, not on gcc.
set(pxr_enable_pch "OFF")
Expand Down
6 changes: 6 additions & 0 deletions 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 @@ -381,10 +385,12 @@

_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
10 changes: 9 additions & 1 deletion pxr/imaging/hgiMetal/capabilities.mm
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
_SetFlag(HgiDeviceCapabilitiesBitsConcurrentDispatch, true);
}

#if defined(ARCH_OS_OSX)
bool const hasIntelGPU = [device isLowPower];
#else
bool const hasIntelGPU = false;
#endif

defaultStorageMode = MTLResourceStorageModeShared;
bool unifiedMemory = false;
Expand All @@ -45,7 +49,7 @@
|| [device areBarycentricCoordsSupported])
&& !hasIntelGPU;

hasAppleSilicon = [device hasUnifiedMemory] && ![device isLowPower];
hasAppleSilicon = [device hasUnifiedMemory] && !hasIntelGPU;

}

Expand Down Expand Up @@ -98,16 +102,20 @@
_SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true);
}

#if defined(ARCH_OS_OSX)
if (!unifiedMemory) {
defaultStorageMode = MTLResourceStorageModeManaged;
}
#endif

_maxUniformBlockSize = 64 * 1024;
_maxShaderStorageBlockSize = 1 * 1024 * 1024 * 1024;
_uniformBufferOffsetAlignment = 16;
_maxClipDistances = 8;
_pageSizeAlignment = 4096;

// TODO: [VG]

// Apple Silicon only support memory barriers between vertex stages after
// macOS 12.3.
hasVertexMemoryBarrier = !hasAppleSilicon;
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 @@ -124,10 +124,12 @@
[_argumentBuffer respondsToSelector:@selector(didModifyRange:)]) {
NSRange range = NSMakeRange(0, _argumentBuffer.length);

#if defined(ARCH_OS_OSX)
ARCH_PRAGMA_PUSH
ARCH_PRAGMA_INSTANCE_METHOD_NOT_FOUND
[_argumentBuffer didModifyRange:range];
ARCH_PRAGMA_POP
#endif
}

[_encoder dispatchThreads:MTLSizeMake(dimX, dimY, 1)
Expand Down
2 changes: 2 additions & 0 deletions 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
2 changes: 2 additions & 0 deletions 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,6 +79,7 @@ void Drain() {}
}
}
}
#endif

if (!_device) {
_device = MTLCreateSystemDefaultDevice();
Expand Down
8 changes: 8 additions & 0 deletions pxr/imaging/hgiMetal/indirectCommandEncoder.mm
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@
newBufferWithBytes:&triangleFactors
length:sizeof(triangleFactors)
options:_bufferStorageMode];
#if defined(ARCH_OS_OSX)
if (_bufferStorageMode != MTLStorageModeShared &&
[_triangleTessFactors respondsToSelector:@selector(didModifyRange:)]) {
[_triangleTessFactors didModifyRange:{0, _triangleTessFactors.length}];
}
#endif

MTLQuadTessellationFactorsHalf quadFactors;
quadFactors.insideTessellationFactor[0] = factorZero;
Expand All @@ -104,10 +106,12 @@
newBufferWithBytes:&quadFactors
length:sizeof(quadFactors)
options:_bufferStorageMode];
#if defined(ARCH_OS_OSX)
if (_bufferStorageMode != MTLStorageModeShared &&
[_quadTessFactors respondsToSelector:@selector(didModifyRange:)]) {
[_quadTessFactors didModifyRange:{0, _quadTessFactors.length}];
}
#endif
}

std::string
Expand Down Expand Up @@ -663,12 +667,14 @@ void _SetArg(
index++;
}

#if defined(ARCH_OS_OSX)
if (_bufferStorageMode != MTLStorageModeShared &&
[commands->indirectArgumentBuffer
respondsToSelector:@selector(didModifyRange:)]) {
[commands->indirectArgumentBuffer
didModifyRange:{0, commands->indirectArgumentBuffer.length}];
}
#endif

// Set pipeline state on the encoder and dispatch to populate the ICB
[encoder setComputePipelineState:function.pipelineState];
Expand Down Expand Up @@ -710,12 +716,14 @@ void _SetArg(
encoder,
mainArgumentBuffer);

#if defined(ARCH_OS_OSX)
// Ensure the the main argument buffer is updated on managed hardware.
if (mainArgumentBuffer.storageMode != MTLStorageModeShared &&
[mainArgumentBuffer respondsToSelector:@selector(didModifyRange:)]) {

[mainArgumentBuffer didModifyRange:{0, mainArgumentBuffer.length}];
}
#endif

id<MTLIndirectCommandBuffer> indirectCommandBuffer =
metalCommands->indirectCommandBuffer;
Expand Down
4 changes: 4 additions & 0 deletions pxr/imaging/hgiMetal/texture.mm
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@
// to our original, private texture.

// Modify texture descriptor to describe the temp texture.
#if defined(ARCH_OS_OSX)
texDesc.resourceOptions = MTLResourceStorageModeManaged;
#else
texDesc.resourceOptions = MTLResourceStorageModeShared;
#endif
texDesc.sampleCount = 1;
if (desc.type == HgiTextureType3D) {
texDesc.textureType = MTLTextureType3D;
Expand Down