Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support both OpenGL and Vulkan Hgi from single build. #2564

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pxr/imaging/hgiInterop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ else()
list(APPEND optionalPrivateHeaders opengl.h)
endif()

if (PXR_ENABLE_VULKAN_SUPPORT)
list(APPEND optionalCppFiles vulkan.cpp)
list(APPEND optionalPrivateHeaders vulkan.h)
list(APPEND optionalLibraries hgiVulkan)
endif()

pxr_library(hgiInterop
LIBRARIES
gf
Expand Down
48 changes: 26 additions & 22 deletions pxr/imaging/hgiInterop/hgiInterop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
#if defined(PXR_METAL_SUPPORT_ENABLED)
#include "pxr/imaging/hgiMetal/hgi.h"
#include "pxr/imaging/hgiInterop/metal.h"
#elif defined(PXR_VULKAN_SUPPORT_ENABLED)
#include "pxr/imaging/hgiVulkan/hgi.h"
#include "pxr/imaging/hgiInterop/vulkan.h"
#else
#include "pxr/imaging/hgiInterop/opengl.h"
#endif
#if defined(PXR_VULKAN_SUPPORT_ENABLED)
#include "pxr/imaging/hgiVulkan/hgi.h"
#include "pxr/imaging/hgiInterop/vulkan.h"
#endif

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -52,40 +53,43 @@ void HgiInterop::TransferToApp(
{
TfToken const& srcApi = srcHgi->GetAPIName();

if (dstApi != HgiTokens->OpenGL) {
TF_CODING_ERROR("Unsupported destination Hgi backend: %s", dstApi.GetText());
return;
}

#if defined(PXR_METAL_SUPPORT_ENABLED)
if (srcApi==HgiTokens->Metal && dstApi==HgiTokens->OpenGL) {
if (srcApi==HgiTokens->Metal) {
// Transfer Metal textures to OpenGL application
if (!_metalToOpenGL) {
_metalToOpenGL = std::make_unique<HgiInteropMetal>(srcHgi);
}
_metalToOpenGL->CompositeToInterop(
srcColor, srcDepth, dstFramebuffer, dstRegion);
} else {
TF_CODING_ERROR("Unsupported Hgi backend: %s", srcApi.GetText());
}
#elif defined(PXR_VULKAN_SUPPORT_ENABLED)
if (srcApi==HgiTokens->Vulkan && dstApi==HgiTokens->OpenGL) {
// Transfer Vulkan textures to OpenGL application
if (!_vulkanToOpenGL) {
_vulkanToOpenGL = std::make_unique<HgiInteropVulkan>(srcHgi);
}
_vulkanToOpenGL->CompositeToInterop(
return _metalToOpenGL->CompositeToInterop(
srcColor, srcDepth, dstFramebuffer, dstRegion);
} else {
TF_CODING_ERROR("Unsupported Hgi backend: %s", srcApi.GetText());
}
#else
if (srcApi==HgiTokens->OpenGL && dstApi==HgiTokens->OpenGL) {
if (srcApi==HgiTokens->OpenGL) {
// Transfer OpenGL textures to OpenGL application
if (!_openGLToOpenGL) {
_openGLToOpenGL = std::make_unique<HgiInteropOpenGL>();
}
_openGLToOpenGL->CompositeToInterop(
return _openGLToOpenGL->CompositeToInterop(
srcColor, srcDepth, dstFramebuffer, dstRegion);
} else {
TF_CODING_ERROR("Unsupported Hgi backend: %s", srcApi.GetText());
}
#endif

#if defined(PXR_VULKAN_SUPPORT_ENABLED)
if (srcApi==HgiTokens->Vulkan) {
// Transfer Vulkan textures to OpenGL application
if (!_vulkanToOpenGL) {
_vulkanToOpenGL = std::make_unique<HgiInteropVulkan>(srcHgi);
}
return _vulkanToOpenGL->CompositeToInterop(
srcColor, srcDepth, dstFramebuffer, dstRegion);
}
#endif

TF_CODING_ERROR("Unsupported source Hgi backend: %s", srcApi.GetText());
}

PXR_NAMESPACE_CLOSE_SCOPE
5 changes: 3 additions & 2 deletions pxr/imaging/hgiInterop/hgiInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@ class HgiInterop final

#if defined(PXR_METAL_SUPPORT_ENABLED)
std::unique_ptr<HgiInteropMetal> _metalToOpenGL;
#elif defined(PXR_VULKAN_SUPPORT_ENABLED)
std::unique_ptr<HgiInteropVulkan> _vulkanToOpenGL;
#else
std::unique_ptr<HgiInteropOpenGL> _openGLToOpenGL;
#endif
#if defined(PXR_VULKAN_SUPPORT_ENABLED)
std::unique_ptr<HgiInteropVulkan> _vulkanToOpenGL;
#endif
};


Expand Down
Loading