diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index f31eecd19fc..d06a4db8b57 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -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 @@ -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 diff --git a/cmake/defaults/Options.cmake b/cmake/defaults/Options.cmake index 6c118a94793..1bdf929d4ae 100644 --- a/cmake/defaults/Options.cmake +++ b/cmake/defaults/Options.cmake @@ -52,10 +52,6 @@ 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 () endif () endif() diff --git a/cmake/defaults/Packages.cmake b/cmake/defaults/Packages.cmake index fe60570b344..cd9c0a54e68 100644 --- a/cmake/defaults/Packages.cmake +++ b/cmake/defaults/Packages.cmake @@ -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) diff --git a/pxr/imaging/garch/CMakeLists.txt b/pxr/imaging/garch/CMakeLists.txt index c7732bc213a..2c86632f79c 100644 --- a/pxr/imaging/garch/CMakeLists.txt +++ b/pxr/imaging/garch/CMakeLists.txt @@ -1,7 +1,7 @@ set(PXR_PREFIX pxr/imaging) set(PXR_PACKAGE garch) -if (NOT ${PXR_ENABLE_GL_SUPPORT}) +if ((NOT ${PXR_ENABLE_GL_SUPPORT}) AND (NOT PXR_APPLE_EMBEDDED)) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF") return() @@ -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) @@ -22,12 +27,16 @@ elseif(WIN32) set(GARCH_SOURCE_EXTENSION cpp) endif() +if (TARGET OpenGL::GL) + list(APPEND optionalLibs OpenGL::GL) +endif() + pxr_library(garch LIBRARIES arch tf ${X11_LIBRARIES} - OpenGL::GL + ${optionalLibs} ${GARCH_PLATFORM_LIBRARIES} INCLUDE_DIRS diff --git a/pxr/imaging/garch/glPlatformContextDarwin.mm b/pxr/imaging/garch/glPlatformContextDarwin.mm index e79b85803c4..e926ade2885 100644 --- a/pxr/imaging/garch/glPlatformContextDarwin.mm +++ b/pxr/imaging/garch/glPlatformContextDarwin.mm @@ -5,15 +5,20 @@ // https://openusd.org/license. // #import -#import #include "pxr/pxr.h" #include "glPlatformContextDarwin.h" -#ifdef ARCH_OS_IPHONE +#if defined(PXR_OPENGL_SUPPORT_ENABLED) +#ifdef ARCH_OS_OSX +#import +typedef NSOpenGLContext NSGLContext; +#elif defined ARCH_OS_IPHONE +#import typedef EAGLContext NSGLContext; +#endif #else -typedef NSOpenGLContext NSGLContext; +typedef void* NSGLContext; #endif PXR_NAMESPACE_OPEN_SCOPE @@ -22,7 +27,11 @@ { public: Detail() { +#if defined(PXR_OPENGL_SUPPORT_ENABLED) context = [NSGLContext currentContext]; +#else + context = nil; +#endif } Detail(NullState) { context = nil; @@ -73,18 +82,26 @@ void GarchNSGLContextState::MakeCurrent() { -#if ARCH_OS_IPHONE +#if defined(PXR_OPENGL_SUPPORT_ENABLED) +#if defined(ARCH_OS_IPHONE) [EAGLContext setCurrentContext:_detail->context]; #else [_detail->context makeCurrentContext]; #endif +#endif } /// Make no context current. void GarchNSGLContextState::DoneCurrent() { +#if defined(PXR_OPENGL_SUPPORT_ENABLED) +#if defined(ARCH_OS_IPHONE) + [EAGLContext setCurrentContext:nil]; +#else [NSGLContext clearCurrentContext]; +#endif +#endif } GarchGLPlatformContextState @@ -96,6 +113,7 @@ void * GarchSelectCoreProfileMacVisual() { +#if defined(ARCH_OS_OSX) NSOpenGLPixelFormatAttribute attribs[10]; int c = 0; @@ -105,6 +123,9 @@ attribs[c++] = 0; return [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs]; +#else // ARCH_OS_MACOS + return NULL; +#endif } PXR_NAMESPACE_CLOSE_SCOPE diff --git a/pxr/imaging/garch/glPlatformDebugWindowDarwin.mm b/pxr/imaging/garch/glPlatformDebugWindowDarwin.mm index ff1d3d22985..2afe5e97974 100644 --- a/pxr/imaging/garch/glPlatformDebugWindowDarwin.mm +++ b/pxr/imaging/garch/glPlatformDebugWindowDarwin.mm @@ -9,12 +9,16 @@ #include "pxr/imaging/garch/glDebugWindow.h" #include "pxr/imaging/garch/glPlatformDebugWindowDarwin.h" +#if defined(ARCH_OS_OSX) #import #import #import +#endif PXR_NAMESPACE_USING_DIRECTIVE +#if defined(ARCH_OS_OSX) + static int Garch_GetModifierKeys(NSUInteger flags) { @@ -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 + diff --git a/pxr/imaging/glf/CMakeLists.txt b/pxr/imaging/glf/CMakeLists.txt index 6a908065498..10f0c3c708c 100644 --- a/pxr/imaging/glf/CMakeLists.txt +++ b/pxr/imaging/glf/CMakeLists.txt @@ -1,10 +1,19 @@ set(PXR_PREFIX pxr/imaging) set(PXR_PACKAGE glf) + if (NOT ${PXR_ENABLE_GL_SUPPORT}) message(STATUS - "Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF") - return() + "Building minimal ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF") + if (NOT PXR_APPLE_EMBEDDED) + list(APPEND optionalLibs ${OPENGL_gl_LIBRARY}) + endif() +else () + list(APPEND optionalLibs ${Boost_PYTHON_LIBRARY}) + list(APPEND optionalLibs ${X11_LIBRARIES}) + if (TARGET OpenGL::GL) + list(APPEND optionalLibs OpenGL::GL) + endif() endif() set(optionalPublicClasses "") @@ -27,9 +36,6 @@ pxr_library(glf tf trace sdf - ${Boost_PYTHON_LIBRARY} - OpenGL::GL - ${X11_LIBRARIES} ${optionalLibs} INCLUDE_DIRS diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index 5f3e459c30a..41e0a51c1e4 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -3,7 +3,7 @@ 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. -if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT}) +if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT (${PXR_ENABLE_GL_SUPPORT} OR PXR_APPLE_EMBEDDED)) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF") return() @@ -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 @@ -41,7 +46,6 @@ pxr_library(hdSt glf hd hdsi - hgiGL hgiInterop sdr tf diff --git a/pxr/imaging/hdx/CMakeLists.txt b/pxr/imaging/hdx/CMakeLists.txt index b544641de5c..c0bd1c521eb 100644 --- a/pxr/imaging/hdx/CMakeLists.txt +++ b/pxr/imaging/hdx/CMakeLists.txt @@ -3,7 +3,7 @@ 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. -if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT}) +if (NOT ${PXR_BUILD_GPU_SUPPORT} OR NOT ${PXR_ENABLE_GL_SUPPORT} AND NOT PXR_APPLE_EMBEDDED) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF") return() diff --git a/pxr/imaging/hgiGL/CMakeLists.txt b/pxr/imaging/hgiGL/CMakeLists.txt index 2a06b7a949f..9b16b630ba7 100644 --- a/pxr/imaging/hgiGL/CMakeLists.txt +++ b/pxr/imaging/hgiGL/CMakeLists.txt @@ -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) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_ENABLE_GL_SUPPORT is OFF") return() diff --git a/pxr/imaging/hgiInterop/CMakeLists.txt b/pxr/imaging/hgiInterop/CMakeLists.txt index 64ebfcb9ed2..5f88d55b8db 100644 --- a/pxr/imaging/hgiInterop/CMakeLists.txt +++ b/pxr/imaging/hgiInterop/CMakeLists.txt @@ -13,6 +13,7 @@ set(optionalPrivateHeaders "") # Destination of hgiInterop is always OpenGL, so always include garch list(APPEND optionalLibraries garch) +list(APPEND optionalLibraries hgiGL) if (PXR_ENABLE_GL_SUPPORT) list(APPEND optionalCppFiles opengl.cpp) @@ -27,7 +28,11 @@ 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 PXR_ENABLE_GL_SUPPORT) + list(APPEND optionalLibraries "-framework CoreVideo") list(APPEND optionalCppFiles metal.mm) list(APPEND optionalPrivateHeaders metal.h) endif() diff --git a/pxr/imaging/hgiInterop/hgiInterop.cpp b/pxr/imaging/hgiInterop/hgiInterop.cpp index 490944a1772..2696a50ec77 100644 --- a/pxr/imaging/hgiInterop/hgiInterop.cpp +++ b/pxr/imaging/hgiInterop/hgiInterop.cpp @@ -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 @@ -32,8 +34,10 @@ struct HgiInteropImpl std::unique_ptr _vulkanToOpenGL; #endif #if defined(PXR_METAL_SUPPORT_ENABLED) +#if !defined(ARCH_OS_IPHONE) std::unique_ptr _metalToOpenGL; #endif +#endif }; HgiInterop::HgiInterop() @@ -58,7 +62,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) { @@ -86,7 +90,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 diff --git a/pxr/imaging/hgiMetal/CMakeLists.txt b/pxr/imaging/hgiMetal/CMakeLists.txt index a8987a3ca71..50591b80834 100644 --- a/pxr/imaging/hgiMetal/CMakeLists.txt +++ b/pxr/imaging/hgiMetal/CMakeLists.txt @@ -7,6 +7,12 @@ 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 @@ -14,7 +20,7 @@ pxr_library(hgiMetal tf trace "-framework Metal" - "-framework AppKit" + "-framework ${APPLE_UI_FRAMEWORK}" PUBLIC_HEADERS api.h diff --git a/pxr/imaging/hgiMetal/blitCmds.h b/pxr/imaging/hgiMetal/blitCmds.h index 7b26fb0831a..04d7cabf5e5 100644 --- a/pxr/imaging/hgiMetal/blitCmds.h +++ b/pxr/imaging/hgiMetal/blitCmds.h @@ -10,6 +10,9 @@ #include "pxr/pxr.h" #include "pxr/imaging/hgiMetal/api.h" #include "pxr/imaging/hgi/blitCmds.h" +#include +#include + PXR_NAMESPACE_OPEN_SCOPE diff --git a/pxr/imaging/hgiMetal/blitCmds.mm b/pxr/imaging/hgiMetal/blitCmds.mm index 04cb0347dd4..3f11faf03e8 100644 --- a/pxr/imaging/hgiMetal/blitCmds.mm +++ b/pxr/imaging/hgiMetal/blitCmds.mm @@ -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; @@ -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) + @@ -462,13 +467,29 @@ return false; } + +static const std::set unfilterableIosFormats = +{ + {MTLPixelFormatRGBA32Float} +}; + +bool +IsFilterable(MTLPixelFormat format) +{ +#if defined(ARCH_OS_IPHONE) + return unfilterableIosFormats.find(format) == unfilterableIosFormats.end(); +#else + return true; +#endif +} + void HgiMetalBlitCmds::GenerateMipMaps(HgiTextureHandle const& texture) { HgiMetalTexture* metalTex = static_cast(texture.Get()); if (metalTex) { - if (_HgiTextureCanBeFiltered(metalTex->GetDescriptor())) { + if (_HgiTextureCanBeFiltered(metalTex->GetDescriptor()) && IsFilterable(metalTex->GetTextureId().pixelFormat)) { _CreateEncoder(); [_blitEncoder generateMipmapsForTexture:metalTex->GetTextureId()]; } diff --git a/pxr/imaging/hgiMetal/capabilities.mm b/pxr/imaging/hgiMetal/capabilities.mm index d6306a3f8d5..785d2b32739 100644 --- a/pxr/imaging/hgiMetal/capabilities.mm +++ b/pxr/imaging/hgiMetal/capabilities.mm @@ -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 hasIPhone = false; if (@available(macOS 100.100, ios 12.0, *)) { unifiedMemory = true; } else if (@available(macOS 10.15, ios 13.0, *)) { @@ -45,10 +48,16 @@ || [device areBarycentricCoordsSupported]) && !hasIntelGPU; +#if defined(ARCH_OS_OSX) hasAppleSilicon = [device hasUnifiedMemory] && ![device isLowPower]; - +#endif } - + + +#if defined(ARCH_OS_IPHONE) + hasIPhone = true; +#endif + if (hasAppleSilicon) { // Indirect command buffers supported only on // Apple Silicon GPUs with macOS 12.3 or later. @@ -60,6 +69,9 @@ // Indirect command buffers not currently supported on Intel GPUs. icbSupported = false; } + if (hasIPhone) { + icbSupported = false; + } if (!TfGetEnvSetting(HGIMETAL_ENABLE_INDIRECT_COMMAND_BUFFER)) { icbSupported = false; @@ -89,7 +101,7 @@ // if we are on MacOS 14 or less //bool isMacOs13OrLess = NSProcessInfo.processInfo.operatingSystemVersion.majorVersion <= 13 //bool requireBasePrimitiveOffset = hasAppleSilicon && isMacOs13OrLess; - bool requiresBasePrimitiveOffset = hasAppleSilicon || hasIntelGPU; + bool requiresBasePrimitiveOffset = hasAppleSilicon || hasIntelGPU || hasIPhone; _SetFlag(HgiDeviceCapabilitiesBitsBasePrimitiveOffset, requiresBasePrimitiveOffset); @@ -97,10 +109,14 @@ if (hasIntelGPU) { _SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true); } - + if (hasIPhone && !barycentrics) { + _SetFlag(HgiDeviceCapabilitiesBitsPrimitiveIdEmulation, true); + } +#if defined(ARCH_OS_OSX) if (!unifiedMemory) { defaultStorageMode = MTLResourceStorageModeManaged; } +#endif _maxUniformBlockSize = 64 * 1024; _maxShaderStorageBlockSize = 1 * 1024 * 1024 * 1024; diff --git a/pxr/imaging/hgiMetal/computeCmds.mm b/pxr/imaging/hgiMetal/computeCmds.mm index d55c05cdc12..1e23be33af9 100644 --- a/pxr/imaging/hgiMetal/computeCmds.mm +++ b/pxr/imaging/hgiMetal/computeCmds.mm @@ -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); @@ -129,6 +130,7 @@ [_argumentBuffer didModifyRange:range]; ARCH_PRAGMA_POP } +#endif [_encoder dispatchThreads:MTLSizeMake(dimX, dimY, 1) threadsPerThreadgroup:MTLSizeMake(MIN(thread_width, dimX), diff --git a/pxr/imaging/hgiMetal/conversions.mm b/pxr/imaging/hgiMetal/conversions.mm index 490d9dc990e..012f528bca2 100644 --- a/pxr/imaging/hgiMetal/conversions.mm +++ b/pxr/imaging/hgiMetal/conversions.mm @@ -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 diff --git a/pxr/imaging/hgiMetal/graphicsCmds.mm b/pxr/imaging/hgiMetal/graphicsCmds.mm index 653c1726676..48a4bc1aae5 100644 --- a/pxr/imaging/hgiMetal/graphicsCmds.mm +++ b/pxr/imaging/hgiMetal/graphicsCmds.mm @@ -392,6 +392,7 @@ HgiMetalGraphicsCmds::_SyncArgumentBuffer() { if (_argumentBuffer) { +#if defined(ARCH_OS_OSX) if (_argumentBuffer.storageMode != MTLStorageModeShared && [_argumentBuffer respondsToSelector:@selector(didModifyRange:)]) { @@ -400,6 +401,7 @@ [_argumentBuffer didModifyRange:{0, _argumentBuffer.length}]; ARCH_PRAGMA_POP } +#endif _argumentBuffer = nil; } } @@ -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; @@ -816,6 +820,7 @@ beforeStages:dstStages]; } } +#endif } static diff --git a/pxr/imaging/hgiMetal/hgi.mm b/pxr/imaging/hgiMetal/hgi.mm index 4ad346f4d1d..066767e0012 100644 --- a/pxr/imaging/hgiMetal/hgi.mm +++ b/pxr/imaging/hgiMetal/hgi.mm @@ -69,6 +69,7 @@ void Drain() {} , _pool(std::make_unique()) { if (!_device) { +#if defined(ARCH_OS_OSX) if( TfGetenvBool("HGIMETAL_USE_INTEGRATED_GPU", false)) { auto devices = MTLCopyAllDevices(); for (id d in devices) { @@ -78,7 +79,7 @@ void Drain() {} } } } - +#endif if (!_device) { _device = MTLCreateSystemDefaultDevice(); } diff --git a/pxr/imaging/hgiMetal/indirectCommandEncoder.h b/pxr/imaging/hgiMetal/indirectCommandEncoder.h index 8a84915c06e..8c62a5d09d6 100644 --- a/pxr/imaging/hgiMetal/indirectCommandEncoder.h +++ b/pxr/imaging/hgiMetal/indirectCommandEncoder.h @@ -37,6 +37,8 @@ class HgiMetalIndirectCommandEncoder final : public HgiIndirectCommandEncoder HGIMETAL_API HgiMetalIndirectCommandEncoder(Hgi *hgi); + HGIMETAL_API ~HgiMetalIndirectCommandEncoder() override; + HGIMETAL_API HgiIndirectCommandsUniquePtr EncodeDraw( HgiComputeCmds * computeCmds, diff --git a/pxr/imaging/hgiMetal/indirectCommandEncoder.mm b/pxr/imaging/hgiMetal/indirectCommandEncoder.mm index 44abcb97075..3eaa8bd5188 100644 --- a/pxr/imaging/hgiMetal/indirectCommandEncoder.mm +++ b/pxr/imaging/hgiMetal/indirectCommandEncoder.mm @@ -89,7 +89,9 @@ options:_bufferStorageMode]; if (_bufferStorageMode != MTLStorageModeShared && [_triangleTessFactors respondsToSelector:@selector(didModifyRange:)]) { +#if defined(ARCH_OS_OSX) [_triangleTessFactors didModifyRange:{0, _triangleTessFactors.length}]; +#endif } MTLQuadTessellationFactorsHalf quadFactors; @@ -106,10 +108,17 @@ options:_bufferStorageMode]; if (_bufferStorageMode != MTLStorageModeShared && [_quadTessFactors respondsToSelector:@selector(didModifyRange:)]) { +#if defined(ARCH_OS_OSX) [_quadTessFactors didModifyRange:{0, _quadTessFactors.length}]; +#endif } } +HgiMetalIndirectCommandEncoder::~HgiMetalIndirectCommandEncoder() { + [_triangleTessFactors release]; + [_quadTessFactors release]; +} + std::string _ArgId(ArgIndex index) { @@ -666,8 +675,10 @@ void _SetArg( if (_bufferStorageMode != MTLStorageModeShared && [commands->indirectArgumentBuffer respondsToSelector:@selector(didModifyRange:)]) { +#if defined(ARCH_OS_OSX) [commands->indirectArgumentBuffer didModifyRange:{0, commands->indirectArgumentBuffer.length}]; +#endif } // Set pipeline state on the encoder and dispatch to populate the ICB @@ -713,8 +724,9 @@ void _SetArg( // Ensure the the main argument buffer is updated on managed hardware. if (mainArgumentBuffer.storageMode != MTLStorageModeShared && [mainArgumentBuffer respondsToSelector:@selector(didModifyRange:)]) { - +#if defined(ARCH_OS_OSX) [mainArgumentBuffer didModifyRange:{0, mainArgumentBuffer.length}]; +#endif } id indirectCommandBuffer = diff --git a/pxr/imaging/hgiMetal/resourceBindings.h b/pxr/imaging/hgiMetal/resourceBindings.h index b03138b031f..abb91e4f24c 100644 --- a/pxr/imaging/hgiMetal/resourceBindings.h +++ b/pxr/imaging/hgiMetal/resourceBindings.h @@ -10,6 +10,8 @@ #include "pxr/pxr.h" #include "pxr/imaging/hgi/resourceBindings.h" #include "pxr/imaging/hgiMetal/api.h" +#include +#include PXR_NAMESPACE_OPEN_SCOPE diff --git a/pxr/imaging/hgiMetal/shaderFunction.mm b/pxr/imaging/hgiMetal/shaderFunction.mm index b472224ee63..8d7ef33a78c 100644 --- a/pxr/imaging/hgiMetal/shaderFunction.mm +++ b/pxr/imaging/hgiMetal/shaderFunction.mm @@ -32,7 +32,7 @@ options.fastMathEnabled = YES; if (@available(macOS 10.15, ios 13.0, *)) { - options.languageVersion = MTLLanguageVersion2_2; + options.languageVersion = MTLLanguageVersion2_3; } else { options.languageVersion = MTLLanguageVersion2_1; } diff --git a/pxr/imaging/hgiMetal/texture.mm b/pxr/imaging/hgiMetal/texture.mm index 342367661d8..ab28806f86f 100644 --- a/pxr/imaging/hgiMetal/texture.mm +++ b/pxr/imaging/hgiMetal/texture.mm @@ -23,6 +23,18 @@ MTLResourceOptions resourceOptions = MTLResourceStorageModePrivate; MTLTextureUsage usage = MTLTextureUsageShaderRead; + if (desc.initialData && desc.pixelsByteSize > 0) { + #if defined(ARCH_OS_OSX) + id device = hgi->GetPrimaryDevice(); + if (![device hasUnifiedMemory]) { + resourceOptions = MTLResourceStorageModeManaged; + } else + #endif + { + resourceOptions = MTLResourceStorageModeShared; + } + } + MTLPixelFormat mtlFormat = HgiMetalConversions::GetPixelFormat( desc.format, desc.usage); @@ -95,7 +107,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; diff --git a/pxr/imaging/hioOpenVDB/CMakeLists.txt b/pxr/imaging/hioOpenVDB/CMakeLists.txt index e32762cea01..1902a8b7c21 100644 --- a/pxr/imaging/hioOpenVDB/CMakeLists.txt +++ b/pxr/imaging/hioOpenVDB/CMakeLists.txt @@ -1,7 +1,7 @@ set(PXR_PREFIX pxr/imaging) set(PXR_PACKAGE hioOpenVDB) -if (NOT ${PXR_BUILD_GPU_SUPPORT}) +if (NOT ${PXR_BUILD_GPU_SUPPORT} AND NOT PXR_APPLE_EMBEDDED) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF") return() diff --git a/pxr/imaging/plugin/hioOiio/CMakeLists.txt b/pxr/imaging/plugin/hioOiio/CMakeLists.txt index 0a055b711d9..e5a68251dd5 100644 --- a/pxr/imaging/plugin/hioOiio/CMakeLists.txt +++ b/pxr/imaging/plugin/hioOiio/CMakeLists.txt @@ -1,7 +1,7 @@ set(PXR_PREFIX pxr/imaging) set(PXR_PACKAGE hioOiio) -if (NOT ${PXR_BUILD_GPU_SUPPORT}) +if (NOT ${PXR_BUILD_GPU_SUPPORT} AND NOT PXR_APPLE_EMBEDDED) message(STATUS "Skipping ${PXR_PACKAGE} because PXR_BUILD_GPU_SUPPORT is OFF") return()