Skip to content

Commit

Permalink
Fix to centralize objc to HgiInterop.
Browse files Browse the repository at this point in the history
* This is so the resources bundle for HdSt doesn't
  get objc import declarations forced into it and break
  everything.

Signed-off-by: furby™ <devs@wabi.foundation>
  • Loading branch information
furby-tm committed Sep 16, 2024
1 parent 94e24b4 commit fa9f292
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 30 deletions.
5 changes: 0 additions & 5 deletions Sources/HdSt/include/HdSt/renderDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ 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
9 changes: 7 additions & 2 deletions Sources/HdSt/renderDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include "Hgi/hgiImpl.h"
#include "Hgi/tokens.h"
#include "HgiInterop/hgiInteropImpl.h"

#include "Glf/diagnostic.h"
#include "Hio/glslfx.h"
Expand Down Expand Up @@ -213,8 +214,12 @@ void HdStRenderDelegate::SetDrivers(HdDriverVector const &drivers)
break;
}
#if defined(ARCH_OS_DARWIN)
if (GetHgiFromMetalDriver(hdDriver)) {
break;
if (hdDriver->name == HgiTokens->renderDriver) {
Hgi *hgiMetal = HgiInterop::GetHgiFromMetalDriver(hdDriver->driver);
if (hgiMetal) {
_hgi = hgiMetal;
break;
}
}
#endif
}
Expand Down
23 changes: 0 additions & 23 deletions Sources/HdSt/renderDelegate.mm

This file was deleted.

12 changes: 12 additions & 0 deletions Sources/HgiInterop/hgiInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ void HgiInterop::TransferToApp(Hgi *srcHgi,
TF_CODING_ERROR("Unsupported source Hgi backend: %s", srcApi.GetText());
}

#if defined(ARCH_OS_DARWIN)
// static.
Hgi* HgiInterop::GetHgiFromMetalDriver(VtValue const &hdDriver)
{
if (hdDriver.IsHolding<HgiMetal *>()) {
return hdDriver.UncheckedGet<HgiMetal *>();
}

return nullptr;
}
#endif // defined(ARCH_OS_DARWIN)

PXR_NAMESPACE_CLOSE_SCOPE

#endif // !defined(__APPLE__)
12 changes: 12 additions & 0 deletions Sources/HgiInterop/hgiInterop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@
TF_CODING_ERROR("Unsupported source Hgi backend: %s", srcApi.GetText());
}

#if defined(ARCH_OS_DARWIN)
// static.
Hgi* HgiInterop::GetHgiFromMetalDriver(VtValue const &hdDriver)
{
if (hdDriver.IsHolding<HgiMetal *>()) {
return hdDriver.UncheckedGet<HgiMetal *>();
}

return nullptr;
}
#endif // defined(ARCH_OS_DARWIN)

PXR_NAMESPACE_CLOSE_SCOPE

#endif // defined(__APPLE__)
5 changes: 5 additions & 0 deletions Sources/HgiInterop/include/HgiInterop/hgiInteropImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class HgiInterop final {
VtValue const &dstFramebuffer,
GfVec4i const &dstRegion);

#if defined(ARCH_OS_DARWIN)
HGIINTEROP_API
static Hgi *GetHgiFromMetalDriver(VtValue const &hdDriver);
#endif // defined(PXR_METAL_SUPPORT_ENABLED) && PXR_METAL_SUPPORT_ENABLED

private:
HgiInterop &operator=(const HgiInterop &) = delete;
HgiInterop(const HgiInterop &) = delete;
Expand Down

0 comments on commit fa9f292

Please sign in to comment.