Skip to content

Commit

Permalink
Succesfully create UsdImagingGLEngine in Swift.
Browse files Browse the repository at this point in the history
* Also add Hydra Storm Renderer plugin.

Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Sep 16, 2024
1 parent b48908b commit 2e6bc91
Show file tree
Hide file tree
Showing 23 changed files with 564 additions and 27 deletions.
31 changes: 31 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ let package = Package(
name: "HdSt",
targets: ["HdSt"]
),
.library(
name: "HdStorm",
targets: ["HdStorm"]
),
.library(
name: "Hdx",
targets: ["Hdx"]
Expand Down Expand Up @@ -1209,6 +1213,7 @@ let package = Package(
.target(name: "Tf"),
.target(name: "Trace"),
.target(name: "Hgi"),
.target(name: "Vt"),
],
resources: [
.process("Resources")
Expand Down Expand Up @@ -1432,6 +1437,7 @@ let package = Package(
.target(name: "Hd"),
.target(name: "HdSi"),
.target(name: "HgiGL", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "HgiMetal", condition: .when(platforms: Arch.OS.apple.platform)),
.target(name: "HgiInterop"),
.target(name: "Sdr"),
.target(name: "Arch"),
Expand All @@ -1454,6 +1460,30 @@ let package = Package(
]
),

.target(
name: "HdStorm",
dependencies: [
.target(name: "Arch"),
.target(name: "Tf"),
.target(name: "Plug"),
.target(name: "Trace"),
.target(name: "Vt"),
.target(name: "Work"),
.target(name: "Hd"),
.target(name: "HdSt", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
],
resources: [
.process("Resources")
],
cxxSettings: [
.define("MFB_PACKAGE_NAME", to: "HdStorm"),
.define("MFB_ALT_PACKAGE_NAME", to: "HdStorm"),
.define("MFB_PACKAGE_MODULE", to: "HdStorm"),
.define("HDSTORM_EXPORTS", to: "1"),
.define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows])),
]
),

.target(
name: "Hdx",
dependencies: [
Expand Down Expand Up @@ -1742,6 +1772,7 @@ let package = Package(
.target(name: "HdMtlx"),
.target(name: "HdSi"),
.target(name: "HdSt", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "HdStorm", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "Hdx", condition: .when(platforms: Arch.OS.noembeddedapple.platform)),
.target(name: "Hgi"),
.target(name: "HgiMetal", condition: .when(platforms: Arch.OS.apple.platform)),
Expand Down
4 changes: 2 additions & 2 deletions Sources/HdSt/include/HdSt/basisCurvesComputations.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class HdSt_BasisCurvesPrimvarInterpolaterComputation : public HdComputedBufferSo
<< "(need " << numVertsExpected << ", got " << authoredSize << "), using fallback value "
<< _fallbackValue << " for rendering.";

TF_WARN(s.str());
TF_WARN("%s", s.str().c_str());
}
}
else if (_interpolation == HdInterpolationVarying) {
Expand Down Expand Up @@ -277,7 +277,7 @@ class HdSt_BasisCurvesPrimvarInterpolaterComputation : public HdComputedBufferSo
<< "(need " << numVaryingExpected << ", got " << authoredSize
<< "), using fallback value " << _fallbackValue << " for rendering.";

TF_WARN(s.str());
TF_WARN("%s", s.str().c_str());
}
}

Expand Down
7 changes: 7 additions & 0 deletions Sources/HdSt/include/HdSt/renderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "HdSt/api.h"
#include "pxr/pxrns.h"

#include "Arch/defines.h"

#include <memory>
#include <mutex>

Expand Down Expand Up @@ -46,6 +48,11 @@ class HdStRenderDelegate final : public HdRenderDelegate {
HDST_API
void SetDrivers(HdDriverVector const &drivers) override;

#if defined(ARCH_OS_DARWIN)
HDST_API
bool GetHgiFromMetalDriver(HdDriver *hdDriver);
#endif // defined(ARCH_OS_DARWIN)

HDST_API
HdRenderParam *GetRenderParam() const override;

Expand Down
5 changes: 5 additions & 0 deletions Sources/HdSt/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ void HdStRenderDelegate::SetDrivers(HdDriverVector const &drivers)
_hgi = hdDriver->driver.UncheckedGet<Hgi *>();
break;
}
#if defined(ARCH_OS_DARWIN)
if (GetHgiFromMetalDriver(hdDriver)) {
break;
}
#endif
}

TF_VERIFY(_hgi, "HdSt requires Hgi HdDriver");
Expand Down
23 changes: 23 additions & 0 deletions Sources/HdSt/renderDelegate.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "pxr/pxrns.h"
#include "Arch/defines.h"

#if defined(ARCH_OS_DARWIN)
# include "HdSt/renderDelegate.h"
# include "Hd/driver.h"
# include "HgiMetal/hgi.h"

PXR_NAMESPACE_OPEN_SCOPE

bool HdStRenderDelegate::GetHgiFromMetalDriver(HdDriver *hdDriver)
{
if (hdDriver->name == HgiTokens->renderDriver && hdDriver->driver.IsHolding<HgiMetal *>()) {
_hgi = hdDriver->driver.UncheckedGet<HgiMetal *>();
return true;
}

return false;
}

PXR_NAMESPACE_CLOSE_SCOPE

#endif // defined(ARCH_OS_DARWIN)
22 changes: 22 additions & 0 deletions Sources/HdStorm/Resources/plugInfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"Plugins": [
{
"Info": {
"Types": {
"HdStormRendererPlugin": {
"bases": [
"HdRendererPlugin"
],
"displayName": "GL",
"priority": 0
}
}
},
"LibraryPath": "",
"Name": "HdStorm",
"ResourcePath": "Contents/Resources",
"Root": "../..",
"Type": "library"
}
]
}
6 changes: 6 additions & 0 deletions Sources/HdStorm/include/HdStorm/HdStorm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef __PXR_IMAGING_PLUGIN_HD_STORM_H__
#define __PXR_IMAGING_PLUGIN_HD_STORM_H__

#include <HdStorm/rendererPlugin.h>

#endif // __PXR_IMAGING_PLUGIN_HD_STORM_H__
35 changes: 35 additions & 0 deletions Sources/HdStorm/include/HdStorm/rendererPlugin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Copyright 2017 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#ifndef PXR_IMAGING_PLUGIN_HD_STORM_RENDERER_PLUGIN_H
#define PXR_IMAGING_PLUGIN_HD_STORM_RENDERER_PLUGIN_H

#include "pxr/pxrns.h"
#include "Hd/rendererPlugin.h"

PXR_NAMESPACE_OPEN_SCOPE

class HdStormRendererPlugin final : public HdRendererPlugin
{
public:
HdStormRendererPlugin() = default;
virtual ~HdStormRendererPlugin() = default;

virtual HdRenderDelegate *CreateRenderDelegate() override;
virtual HdRenderDelegate *CreateRenderDelegate(HdRenderSettingsMap const &settingsMap) override;

virtual void DeleteRenderDelegate(HdRenderDelegate *renderDelegate) override;

virtual bool IsSupported(bool gpuEnabled = true) const override;

private:
HdStormRendererPlugin(const HdStormRendererPlugin &) = delete;
HdStormRendererPlugin &operator=(const HdStormRendererPlugin &) = delete;
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif // PXR_IMAGING_PLUGIN_HD_STORM_RENDERER_PLUGIN_H
46 changes: 46 additions & 0 deletions Sources/HdStorm/rendererPlugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Copyright 2017 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "pxr/pxrns.h"
#include "HdStorm/rendererPlugin.h"

#include "HdSt/renderDelegate.h"
#include "Hd/rendererPluginRegistry.h"

PXR_NAMESPACE_OPEN_SCOPE

TF_REGISTRY_FUNCTION(TfType)
{
HdRendererPluginRegistry::Define<HdStormRendererPlugin>();
}

HdRenderDelegate *HdStormRendererPlugin::CreateRenderDelegate()
{
return new HdStRenderDelegate();
}

HdRenderDelegate *HdStormRendererPlugin::CreateRenderDelegate(HdRenderSettingsMap const &settingsMap)
{
return new HdStRenderDelegate(settingsMap);
}

void HdStormRendererPlugin::DeleteRenderDelegate(HdRenderDelegate *renderDelegate)
{
delete renderDelegate;
}

bool HdStormRendererPlugin::IsSupported(bool gpuEnabled) const
{
const bool support = gpuEnabled && HdStRenderDelegate::IsSupported();
if (!support) {
TF_DEBUG(HD_RENDERER_PLUGIN)
.Msg("hdStorm renderer plugin unsupported: %s\n",
gpuEnabled ? "hgi unsupported" : "no gpu");
}
return support;
}

PXR_NAMESPACE_CLOSE_SCOPE
5 changes: 5 additions & 0 deletions Sources/HgiMetal/hgi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ void Drain() {}
return hgi;
}

VtValue HgiMetal::GetValue(HgiMetalPtr ptr) const
{
return VtValue(ptr.get());
}

bool
HgiMetal::IsBackendSupported() const
{
Expand Down
4 changes: 4 additions & 0 deletions Sources/HgiMetal/include/HgiMetal/hgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "HgiMetal/api.h"
#include "HgiMetal/capabilities.h"
#include "HgiMetal/indirectCommandEncoder.h"
#include "Vt/value.h"
#include "pxr/pxrns.h"

#import <Metal/Metal.h>
Expand Down Expand Up @@ -46,6 +47,9 @@ class HgiMetal final : public Hgi {
HGIMETAL_API
static HgiMetalPtr CreateHgi();

HGIMETAL_API
VtValue GetValue(HgiMetalPtr ptr) const;

HGIMETAL_API
bool IsBackendSupported() const override;

Expand Down
6 changes: 6 additions & 0 deletions Sources/PixarUSD/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ public extension Bundle
* Where ``HdSt`` application bundle resources are located. */
static let hdSt = Bundle(path: "\(pxrRoot)/SwiftUSD_HdSt\(ext)")

/**
* Where ``HdStorm`` application bundle resources are located. */
static let hdStorm = Bundle(path: "\(pxrRoot)/SwiftUSD_HdStorm\(ext)")

/**
* Where ``Hdx`` application bundle resources are located. */
static let hdx = Bundle(path: "\(pxrRoot)/SwiftUSD_Hdx\(ext)")
Expand Down Expand Up @@ -441,6 +445,7 @@ public enum BundleFramework: CaseIterable
case hgiVulkan
case hgiGL
case hdSt
case hdStorm
case hdx
case hio
case glf
Expand Down Expand Up @@ -477,6 +482,7 @@ public enum BundleFramework: CaseIterable
case .hgiVulkan: Bundle.hgiVulkan?.resourcePath
case .hgiGL: Bundle.hgiGL?.resourcePath
case .hdSt: Bundle.hdSt?.resourcePath
case .hdStorm: Bundle.hdStorm?.resourcePath
case .hdx: Bundle.hdx?.resourcePath
case .hio: Bundle.hio?.resourcePath
case .glf: Bundle.glf?.resourcePath
Expand Down
83 changes: 83 additions & 0 deletions Sources/PixarUSD/Imaging/Hd/AovTokens.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/* ----------------------------------------------------------------
* :: : M E T A V E R S E : ::
* ----------------------------------------------------------------
* Licensed under the terms set forth in the LICENSE.txt file, this
* file is available at https://openusd.org/license.
*
* Copyright (C) 2016 Pixar.
* Copyright (C) 2024 Wabi Foundation. All Rights Reserved.
* ----------------------------------------------------------------
* . x x x . o o o . x x x . : : : . o x o . : : : .
* ---------------------------------------------------------------- */

import Hd

private extension Hd
{
/**
* Private struct to hold the static
* data for the Hd library's AOV tokens. */
struct AovStaticData
{
static let shared = AovStaticData()
private init()
{}

let tokens = Pixar.HdAovTokens_StaticTokenType()
}
}

public extension Hd
{
/**
* # Hd.AovTokens
*
* ## Overview
*
* Public, client facing api to access
* the static Hd AOV tokens. */
enum AovTokens: String, CaseIterable
{
case color
case depth
case depthStencil
case cameraDepth
case primId
case instanceId
case elementId
case edgeId
case pointId
case pEye
case nEye
case patchCoord
case primitiveParam
case normal
case primvars = "primvars:"
case lpe = "lpe:"
case shader = "shader:"

public var token: Tf.Token
{
switch self
{
case .color: AovStaticData.shared.tokens.color
case .depth: AovStaticData.shared.tokens.depth
case .depthStencil: AovStaticData.shared.tokens.depthStencil
case .cameraDepth: AovStaticData.shared.tokens.cameraDepth
case .primId: AovStaticData.shared.tokens.primId
case .instanceId: AovStaticData.shared.tokens.instanceId
case .elementId: AovStaticData.shared.tokens.elementId
case .edgeId: AovStaticData.shared.tokens.edgeId
case .pointId: AovStaticData.shared.tokens.pointId
case .pEye: AovStaticData.shared.tokens.Peye
case .nEye: AovStaticData.shared.tokens.Neye
case .patchCoord: AovStaticData.shared.tokens.patchCoord
case .primitiveParam: AovStaticData.shared.tokens.primitiveParam
case .normal: AovStaticData.shared.tokens.normal
case .primvars: AovStaticData.shared.tokens.primvars
case .lpe: AovStaticData.shared.tokens.lpe
case .shader: AovStaticData.shared.tokens.shader
}
}
}
}
Loading

0 comments on commit 2e6bc91

Please sign in to comment.