Skip to content

Commit

Permalink
Fix imaging crash potential, begin UsdView hydra.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Sep 16, 2024
1 parent 42de343 commit b48908b
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* ----------------------------------------------------------------
* :: : 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 . : : : .
* ---------------------------------------------------------------- */

#if canImport(UsdImagingGLEngine)
import UsdImagingGLEngine

public enum UsdImagingGLEngine
{}
#endif // canImport(UsdImagingGLEngine)
3 changes: 1 addition & 2 deletions Sources/UsdImaging/indexProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,10 @@ void UsdImagingIndexProxy::InsertInstancer(SdfPath const &cachePath,
primInfo->dirtyBits = HdChangeTracker::AllDirty;
_delegate->_dirtyCachePaths.insert(cachePath);

auto& adapterType = (*adapter);
TF_DEBUG(USDIMAGING_INSTANCER)
.Msg("[Instancer Inserted] %s, adapter = %s\n",
cachePath.GetText(),
adapter ? TfType::GetCanonicalTypeName(typeid(adapterType)).c_str() : "none");
adapter ? TfType::GetCanonicalTypeName(typeid(*adapter)).c_str() : "none");

_AddTask(cachePath);
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/UsdImaging/instanceAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,13 +335,12 @@ SdfPath UsdImagingInstanceAdapter::_Populate(UsdPrim const &prim,
protoPath = newProtoPath;
}

auto& primAdapterType = (*primAdapter);
TF_DEBUG(USDIMAGING_INSTANCER)
.Msg("[Add Instance NI] <%s> %s (%s), adapter = %s\n",
instancerPath.GetText(),
protoPath.GetText(),
iter->GetName().GetText(),
primAdapter ? TfType::GetCanonicalTypeName(typeid(primAdapterType)).c_str() : "none");
primAdapter ? TfType::GetCanonicalTypeName(typeid(*primAdapter)).c_str() : "none");
}
}

Expand Down
1 change: 1 addition & 0 deletions Sources/UsdImagingGL/include/UsdImagingGL/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ TF_DECLARE_REF_PTRS(HdsiSceneGlobalsSceneIndex);
TF_DECLARE_REF_PTRS(HdSceneIndexBase);

using UsdStageWeakPtr = TfWeakPtr<class UsdStage>;
using UsdImagingGLEngineSharedPtr = std::shared_ptr<class UsdImagingGLEngine>;

namespace UsdImagingGLEngine_Impl {
using _AppSceneIndicesSharedPtr = std::shared_ptr<struct _AppSceneIndices>;
Expand Down
54 changes: 0 additions & 54 deletions Sources/UsdView/HDMTLRenderer.swift

This file was deleted.

71 changes: 71 additions & 0 deletions Sources/UsdView/Hydra+MTLRenderer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* ----------------------------------------------------------------
* :: : 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 Foundation
import PixarUSD
#if canImport(Metal) && !os(visionOS)
import Metal
import MetalKit

public extension Hydra
{
/**
* ``MTLRenderer``
*
* ## Overview
*
* The Hydra Engine (``Hd``) Metal renderer for the ``UsdView``
* application conforms to the ``MTKViewDelegate`` protocol,
* allowing it to be set as a ``MTKView`` object's delegate to
* provide a drawing method to a ``MTKView`` object and respond
* to rendering events. */
class MTLRenderer: NSObject, MTKViewDelegate
{
let hgi: Pixar.HgiMetalPtr
// let engine: UsdImagingGLEngineSharedPtr
// let stage: UsdStageRefPtr

public init?(device _: MTLDevice)
{
hgi = HgiMetal.createHgi()

// let excludedPaths = SdfPathVector()
let driver = HdDriver(name: .renderDriver, driver: VtValue(hgi))

// engine.reset(UsdImagingGLEngineSharedPtr(
// stage.getPseudoRoot().getPath(),
// excludedPaths,
// SdfPathVector(),
// SdfPath.AbsoluteRootPath(),
// driver
// ))

// engine.SetEnablePresentation(false)
// engine.SetRendererAov(false)
}

public func info()
{
Msg.logger.log(level: .info, "Created HGI -> Metal API v\(hgi.apiVersion).")
Msg.logger.log(level: .info, "GPU Architecture -> \(hgi.device.architecture.name)")
}

public func mtkView(_: MTKView, drawableSizeWillChange size: CGSize)
{
print("drawableSizeWillChange", size)
}

public func draw(in _: MTKView)
{}
}
}
#endif // canImport(Metal) && !os(visionOS)
17 changes: 17 additions & 0 deletions Sources/UsdView/Hydra.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* ----------------------------------------------------------------
* :: : 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 Foundation
import PixarUSD

public enum Hydra
{}
4 changes: 2 additions & 2 deletions Sources/UsdView/UsdView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import PixarUSD
struct UsdView: PixarApp
{
#if canImport(Metal) && !os(visionOS)
let hydra: HDMTLRenderer
let hydra: Hydra.MTLRenderer
#endif /* canImport(Metal) && !os(visionOS) */

public init()
Expand All @@ -65,7 +65,7 @@ struct UsdView: PixarApp
#endif /* canImport(PyBundle) */

#if canImport(Metal) && !os(visionOS)
hydra = HDMTLRenderer(device: MTLCreateSystemDefaultDevice()!)!
hydra = Hydra.MTLRenderer(device: MTLCreateSystemDefaultDevice()!)!
#endif /* canImport(Metal) && !os(visionOS) */

#if canImport(SwiftUI)
Expand Down

0 comments on commit b48908b

Please sign in to comment.