Skip to content

Commit

Permalink
Add @dgovil support for iOS and visionOS imaging.
Browse files Browse the repository at this point in the history
* Also setup CI workflows to build and bundle on iOS and visionOS.

Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Sep 9, 2024
1 parent e6bacc7 commit fc09bc2
Show file tree
Hide file tree
Showing 19 changed files with 215 additions and 59 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/swift-ios.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Swift (iOS 18)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on iOS
strategy:
matrix:
os: [self-hosted]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: 📦 Build
run: swift bundler bundle -c release -p iOSSimulator UsdView
16 changes: 16 additions & 0 deletions .github/workflows/swift-visionos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Swift (visionOS 2)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on visionOS
strategy:
matrix:
os: [self-hosted]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: 📦 Build
run: swift bundler bundle -c release -p visionOSSimulator UsdView
20 changes: 17 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1158,6 +1158,7 @@ let package = Package(
.target(name: "Tf"),
],
cxxSettings: [
.define("PXR_GL_SUPPORT_ENABLED", .when(platforms: Arch.OS.noembeddedapple.platform)),
.define("MFB_PACKAGE_NAME", to: "Garch"),
.define("MFB_ALT_PACKAGE_NAME", to: "Garch"),
.define("MFB_PACKAGE_MODULE", to: "Garch"),
Expand All @@ -1166,6 +1167,7 @@ let package = Package(
],
linkerSettings: [
.linkedFramework("OpenGL", .when(platforms: [.macOS])),
.linkedFramework("UIKit", .when(platforms: Arch.OS.embeddedapple.platform)),
.linkedLibrary("glut", .when(platforms: Arch.OS.linux.platform)),
.linkedLibrary("GL", .when(platforms: Arch.OS.linux.platform)),
.linkedLibrary("GLU", .when(platforms: Arch.OS.linux.platform)),
Expand Down Expand Up @@ -1221,8 +1223,10 @@ let package = Package(
.define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
],
linkerSettings: [
.linkedFramework("Foundation", .when(platforms: Arch.OS.apple.platform)),
.linkedFramework("Metal", .when(platforms: Arch.OS.apple.platform)),
.linkedFramework("AppKit", .when(platforms: [.macOS])),
.linkedFramework("UIKit", .when(platforms: Arch.OS.embeddedapple.platform)),
]
),

Expand Down Expand Up @@ -1280,7 +1284,7 @@ let package = Package(
.target(name: "Hgi"),
.target(name: "HgiMetal", condition: .when(platforms: Arch.OS.apple.platform)),
// .target(name: "HgiVulkan", condition: .when(platforms: Arch.OS.linux.platform)),
.target(name: "HgiGL"),
.target(name: "HgiGL", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
],
cxxSettings: [
.define("MFB_PACKAGE_NAME", to: "HgiInterop"),
Expand All @@ -1293,6 +1297,7 @@ let package = Package(
.define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
],
linkerSettings: [
.linkedFramework("Foundation", .when(platforms: Arch.OS.apple.platform)),
.linkedFramework("CoreVideo", .when(platforms: Arch.OS.apple.platform))
]
),
Expand Down Expand Up @@ -1345,6 +1350,9 @@ let package = Package(
.define("MFB_PACKAGE_MODULE", to: "Glf"),
.define("GLF_EXPORTS", to: "1"),
.define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
],
linkerSettings: [
.linkedFramework("OpenGL", .when(platforms: [.macOS])),
]
),

Expand Down Expand Up @@ -1421,7 +1429,7 @@ let package = Package(
.target(name: "Glf"),
.target(name: "Hd"),
.target(name: "HdSi"),
.target(name: "HgiGL"),
.target(name: "HgiGL", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "HgiInterop"),
.target(name: "Sdr"),
.target(name: "Arch"),
Expand Down Expand Up @@ -1736,7 +1744,7 @@ let package = Package(
.target(name: "Hgi"),
.target(name: "HgiMetal", condition: .when(platforms: Arch.OS.apple.platform)),
// .target(name: "HgiVulkan", condition: .when(platforms: Arch.OS.linux.platform)),
.target(name: "HgiGL"),
.target(name: "HgiGL", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "HgiInterop"),
.target(name: "Hio"),
.target(name: "PxOsd"),
Expand Down Expand Up @@ -1810,6 +1818,10 @@ enum Arch
case applewindows
/// everything not apple (linux + windows).
case linwin
/// only embedded apple devices.
case embeddedapple
/// everything not embedded apple devices.
case noembeddedapple

public var platform: [Platform]
{
Expand All @@ -1822,6 +1834,8 @@ enum Arch
case .nix: [.macOS, .iOS, .visionOS, .tvOS, .watchOS, .linux, .android, .openbsd]
case .applewindows: [.macOS, .iOS, .visionOS, .tvOS, .watchOS, .windows]
case .linwin: [.linux, .android, .openbsd, .windows]
case .embeddedapple: [.iOS, .visionOS, .tvOS, .watchOS]
case .noembeddedapple: [.macOS, .linux, .android, .openbsd, .windows]
}
}

Expand Down
45 changes: 30 additions & 15 deletions Sources/Garch/glPlatformContextDarwin.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,32 @@
#include "Arch/defines.h"

#if defined(__APPLE__)
# import <Foundation/Foundation.h>
# if defined(ARCH_OS_IPHONE)
# import <GLKit/GLKit.h>
# else // !defined(ARCH_OS_IPHONE)
# import <AppKit/NSOpenGL.h>
# endif // defined(ARCH_OS_IPHONE)

# include "pxr/pxrns.h"
# include "Garch/GarchDarwin/glPlatformContextDarwin.h"

# ifdef ARCH_OS_IPHONE
typedef EAGLContext NSGLContext;
# else
# import <Foundation/Foundation.h>
# if defined(PXR_GL_SUPPORT_ENABLED)
# if defined(ARCH_OS_OSX)
# import <AppKit/NSOpenGL.h>
typedef NSOpenGLContext NSGLContext;
# endif
# elif defined(ARCH_OS_IPHONE)
# import <UIKit/UIKit.h>
typedef EAGLContext NSGLContext;
# endif // defined(ARCH_OS_IPHONE)
# else // !defined(PXR_GL_SUPPORT_ENABLED)
typedef void* NSGLContext;
# endif // defined(PXR_GL_SUPPORT_ENABLED)

PXR_NAMESPACE_OPEN_SCOPE

class GarchNSGLContextState::Detail
{
public:
Detail() {
#if defined(PXR_GL_SUPPORT_ENABLED)
context = [NSGLContext currentContext];
#else
context = nil;
#endif
}
Detail(NullState) {
context = nil;
Expand Down Expand Up @@ -80,18 +83,26 @@
void
GarchNSGLContextState::MakeCurrent()
{
#if ARCH_OS_IPHONE
#if defined(PXR_GL_SUPPORT_ENABLED)
# if defined(ARCH_OS_IPHONE)
[EAGLContext setCurrentContext:_detail->context];
#else
# else // !defined(ARCH_OS_IPHONE)
[_detail->context makeCurrentContext];
#endif
# endif // defined(ARCH_OS_IPHONE)
#endif // defined(PXR_GL_SUPPORT_ENABLED)
}

/// Make no context current.
void
GarchNSGLContextState::DoneCurrent()
{
#if defined(PXR_GL_SUPPORT_ENABLED)
# if defined(ARCH_OS_IPHONE)
[EAGLContext setCurrentContext:nil];
# else // !defined(ARCH_OS_IPHONE)
[NSGLContext clearCurrentContext];
# endif // defined(ARCH_OS_IPHONE)
#endif
}

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

Expand All @@ -112,6 +124,9 @@
attribs[c++] = 0;

return (__bridge void*)[[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
#else // !defined(ARCH_OS_OSX)
return NULL;
#endif // defined(ARCH_OS_OSX)
}

PXR_NAMESPACE_CLOSE_SCOPE
Expand Down
52 changes: 29 additions & 23 deletions Sources/Garch/glPlatformDebugWindowDarwin.mm
Original file line number Diff line number Diff line change
@@ -1,29 +1,12 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "Arch/defines.h"

#if defined(__APPLE__) && defined(ARCH_OS_OSX)
#if defined(__APPLE__)
/* -----------------------------------------------------------------
* to reduce the need to explicitly exclude platform specific source
* from SwiftPM, we will just guard the compilation by its platform,
Expand All @@ -34,12 +17,16 @@
# include "Garch/glDebugWindow.h"
# include <pxr/pxrns.h>

# import <Cocoa/Cocoa.h>
# import <OpenGL/OpenGL.h>
# import <OpenGL/gl.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 @@ -249,6 +236,25 @@ - (void)keyDown:(NSEvent *)event
[NSApp stop:nil];
}

#else // !defined(ARCH_OS_OSX)

PXR_NAMESPACE_OPEN_SCOPE

Garch_GLPlatformDebugWindow::Garch_GLPlatformDebugWindow(GarchGLDebugWindow *w)

Check failure on line 243 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on visionOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 243 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on visionOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 243 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on iOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 243 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on iOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier
{}

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

Check failure on line 246 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on visionOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 246 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on iOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier
{}

void
Garch_GLPlatformDebugWindow::Run()

Check failure on line 250 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on visionOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 250 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on iOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier
{}

void
Garch_GLPlatformDebugWindow::ExitApp()

Check failure on line 254 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on visionOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier

Check failure on line 254 in Sources/Garch/glPlatformDebugWindowDarwin.mm

View workflow job for this annotation

GitHub Actions / Swift 5.10 on iOS

incomplete type 'Pixar::Garch_GLPlatformDebugWindow' named in nested name specifier
{}
#endif // defined(ARCH_OS_OSX)

PXR_NAMESPACE_CLOSE_SCOPE

#endif /* defined(__APPLE__) && defined(ARCH_OS_OSX) */
18 changes: 11 additions & 7 deletions Sources/HgiInterop/hgiInterop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,26 @@
#endif

#if defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED
# include "HgiInterop/metal.h"
# include "HgiMetal/hgi.h"
#endif
# if defined(ARCH_OS_OSX)
# include "HgiInterop/metal.h"
# endif // defined(ARCH_OS_OSX)
#endif // defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED

PXR_NAMESPACE_OPEN_SCOPE

struct HgiInteropImpl {
#if defined(PXR_GL_SUPPORT_ENABLED)
std::unique_ptr<HgiInteropOpenGL> _openGLToOpenGL;
#endif
#endif // defined(PXR_GL_SUPPORT_ENABLED)
#if defined(PXR_VULKAN_SUPPORT_ENABLED) && PXR_VULKAN_SUPPORT_ENABLED
std::unique_ptr<HgiInteropVulkan> _vulkanToOpenGL;
#endif
#endif // defined(PXR_VULKAN_SUPPORT_ENABLED) && PXR_VULKAN_SUPPORT_ENABLED
#if defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED
# if !defined(ARCH_OS_IPHONE)
std::unique_ptr<HgiInteropMetal> _metalToOpenGL;
#endif
# endif // !defined(ARCH_OS_IPHONE)
#endif // defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED
};

HgiInterop::HgiInterop() : _hgiInteropImpl(std::make_unique<HgiInteropImpl>()) {}
Expand All @@ -60,7 +64,7 @@
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 All @@ -86,7 +90,7 @@
}
#endif

#if defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED
#if (defined(PXR_METAL_SUPPORT_ENABLED) && 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
21 changes: 19 additions & 2 deletions Sources/HgiMetal/blitCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@

mtlDesc.mipmapLevelCount = dstTexDesc.mipLevels;
mtlDesc.arrayLength = dstTexDesc.layerCount;
mtlDesc.resourceOptions = MTLResourceStorageModeManaged;
mtlDesc.resourceOptions = _hgi->GetCapabilities()->preferredStorageMode;
mtlDesc.sampleCount = 1;
if (dstTexDesc.type == HgiTextureType3D) {
mtlDesc.depth = depth;
Expand Down Expand Up @@ -389,10 +389,12 @@

_CreateEncoder();

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

// Offset into the dst buffer
char* dst = ((char*) copyOp.cpuDestinationBuffer) +
Expand Down Expand Up @@ -470,13 +472,28 @@
return false;
}

static const std::set<MTLPixelFormat> unfilterableIosFormats =
{
{MTLPixelFormatRGBA32Float}
};

bool
IsFilterable(MTLPixelFormat format)
{
#if defined(ARCH_OS_IPHONE)
return unfilterableIosFormats.find(format) == unfilterableIosFormats.end();
#else // !defined(ARCH_OS_IPHONE)
return true;
#endif // defined(ARCH_OS_IPHONE)
}

void
HgiMetalBlitCmds::GenerateMipMaps(HgiTextureHandle const& texture)
{
HgiMetalTexture* metalTex = static_cast<HgiMetalTexture*>(texture.Get());

if (metalTex) {
if (_HgiTextureCanBeFiltered(metalTex->GetDescriptor())) {
if (_HgiTextureCanBeFiltered(metalTex->GetDescriptor()) && IsFilterable(metalTex->GetTextureId().pixelFormat)) {
_CreateEncoder();
[_blitEncoder generateMipmapsForTexture:metalTex->GetTextureId()];
}
Expand Down
Loading

0 comments on commit fc09bc2

Please sign in to comment.