Skip to content

Commit

Permalink
Enable experimental Vulkan testing on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
DDoS committed Nov 4, 2024
1 parent d1ebe6f commit f52a686
Show file tree
Hide file tree
Showing 24 changed files with 631 additions and 384 deletions.
4 changes: 0 additions & 4 deletions build_scripts/build_usd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,6 @@ def InstallOpenSubdiv(context, force, buildArgs):
'-DNO_TBB=ON',
]

# Use Metal for macOS and all Apple embedded systems.
if MacOS():
extraArgs.append('-DNO_OPENGL=ON')

# Add on any user-specified extra arguments.
extraArgs += buildArgs

Expand Down
21 changes: 12 additions & 9 deletions cmake/defaults/Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ option(PXR_BUILD_MAYAPY_TESTS "Build mayapy spline tests" OFF)
option(PXR_BUILD_ANIMX_TESTS "Build AnimX spline tests" OFF)
option(PXR_ENABLE_NAMESPACES "Enable C++ namespaces." ON)
option(PXR_PREFER_SAFETY_OVER_SPEED
"Enable certain checks designed to avoid crashes or out-of-bounds memory reads with malformed input files. These checks may negatively impact performance."
ON)
"Enable certain checks designed to avoid crashes or out-of-bounds memory reads with malformed input files.\
These checks may negatively impact performance." ON)
option(PXR_ENABLE_EXPERIMENTAL_TESTS "Enable experimental tests on macOS.\
These aren't guaranteed to pass." OFF)

if(APPLE)
# Cross Compilation detection as defined in CMake docs
Expand Down Expand Up @@ -68,16 +70,17 @@ if(APPLE)
endif ()
endif()


# Determine GFX api
# Determine graphics API
# In the current state of USD, OpenGL support is always required to build.
include(CMakeDependentOption)
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
# Metal only valid on Apple platforms
set(pxr_enable_metal "OFF")
if(APPLE)
set(pxr_enable_metal "ON")
cmake_dependent_option(PXR_ENABLE_METAL_SUPPORT "Enable Metal based components" ON "PXR_ENABLE_GL_SUPPORT" OFF)
else()
set(PXR_ENABLE_METAL_SUPPORT OFF CACHE BOOL "Enable Metal based components" FORCE)
endif()
option(PXR_ENABLE_METAL_SUPPORT "Enable Metal based components" "${pxr_enable_metal}")
option(PXR_ENABLE_VULKAN_SUPPORT "Enable Vulkan based components" OFF)
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
cmake_dependent_option(PXR_ENABLE_VULKAN_SUPPORT "Enable Vulkan based components" OFF "PXR_ENABLE_GL_SUPPORT" OFF)

# Precompiled headers are a win on Windows, not on gcc.
set(pxr_enable_pch "OFF")
Expand Down
1 change: 1 addition & 0 deletions cmake/defaults/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ if (PXR_BUILD_IMAGING)
# --X11
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
find_package(X11)
add_definitions(-DPXR_X11_SUPPORT_ENABLED)
endif()
# --Embree
if (PXR_BUILD_EMBREE_PLUGIN)
Expand Down
79 changes: 40 additions & 39 deletions extras/imaging/examples/hdTiny/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,47 @@ pxr_plugin(${PXR_PACKAGE}
DISABLE_PRECOMPILED_HEADERS
)

pxr_build_test(testHdTiny
LIBRARIES
hdx

CPPFILES
testenv/testHdTiny.cpp
)

pxr_install_test_dir(
SRC testenv/testHdTiny
DEST testHdTiny
)
if (PXR_ENABLE_GL_SUPPORT)
pxr_build_test(testHdTiny
LIBRARIES
hdx

# This test only runs on MacOS and Linux for now.
if (APPLE)
pxr_register_test(testHdTiny
ENV
DYLD_INSERT_LIBRARIES=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.dylib
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt
CPPFILES
testenv/testHdTiny.cpp
)
elseif (UNIX)
pxr_register_test(testHdTiny
ENV
LD_PRELOAD=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.so
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt
)
elseif (WIN32)
pxr_register_test(testHdTiny
ENV
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
PRE_PATH
${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt

pxr_install_test_dir(
SRC testenv/testHdTiny
DEST testHdTiny
)

if (APPLE)
pxr_register_test(testHdTiny
ENV
DYLD_INSERT_LIBRARIES=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.dylib
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt
)
elseif (UNIX)
pxr_register_test(testHdTiny
ENV
LD_PRELOAD=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.so
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt
)
elseif (WIN32)
pxr_register_test(testHdTiny
ENV
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
PRE_PATH
${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
STDOUT_REDIRECT output.txt
DIFF_COMPARE output.txt
)
endif()
endif()
5 changes: 4 additions & 1 deletion pxr/imaging/glf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ endif()

set(optionalPublicClasses "")
if (X11_FOUND)
list(APPEND optionalPublicClasses testGLContext)
list(APPEND optionalPublicClasses testGLXContext)
else()
list(APPEND optionalPublicClasses testGLNullContext)
endif()

pxr_library(glf
Expand Down Expand Up @@ -37,6 +39,7 @@ pxr_library(glf
simpleLightingContext
simpleMaterial
simpleShadowArray
testGLContext
texture
uniformBlock
utils
Expand Down
107 changes: 5 additions & 102 deletions pxr/imaging/glf/testGLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,112 +8,16 @@

#include "pxr/base/tf/diagnostic.h"

#include <GL/glx.h>
#ifdef PXR_X11_SUPPORT_ENABLED
#include "pxr/imaging/glf/testGLXContext.h"
#else
#include "pxr/imaging/glf/testGLNullContext.h"
#endif

#include <stdio.h>

PXR_NAMESPACE_OPEN_SCOPE


class Glf_TestGLContextPrivate {
public:
Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other=NULL );

void makeCurrent( ) const;

bool isValid();

bool operator==(const Glf_TestGLContextPrivate& rhs) const
{
return _dpy == rhs._dpy && _context == rhs._context;
}

static const Glf_TestGLContextPrivate * currentContext();

static bool areSharing( const Glf_TestGLContextPrivate * context1,
const Glf_TestGLContextPrivate * context2 );

private:
Display * _dpy;

GLXContext _context;

Glf_TestGLContextPrivate const * _sharedContext;

static GLXWindow _win;

static Glf_TestGLContextPrivate const * _currenGLContext;
};

Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext=NULL;
GLXWindow Glf_TestGLContextPrivate::_win=0;

Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other )
: _dpy(NULL), _context(NULL)
{
static int attribs[] = { GLX_DOUBLEBUFFER, GLX_RGBA_BIT,
GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
GLX_SAMPLE_BUFFERS, 1, GLX_SAMPLES, 4, None };

_dpy = XOpenDisplay(0);

int n;
GLXFBConfig * fbConfigs = glXChooseFBConfig( _dpy,
DefaultScreen(_dpy), attribs, &n );

GLXContext share = other ? other->_context : 0;

_context = glXCreateNewContext( _dpy,
fbConfigs[0], GLX_RGBA_TYPE, share, true);

_sharedContext=other ? other : this;

if (!_win) {
XVisualInfo * vi = glXGetVisualFromFBConfig( _dpy, fbConfigs[0] );

XSetWindowAttributes swa;
swa.colormap = XCreateColormap(_dpy, RootWindow(_dpy, vi->screen),
vi->visual, AllocNone);
swa.border_pixel = 0;
swa.event_mask = StructureNotifyMask;

Window xwin = XCreateWindow( _dpy, RootWindow(_dpy, vi->screen),
0, 0, 256, 256, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel|CWColormap|CWEventMask, &swa );

_win = glXCreateWindow( _dpy, fbConfigs[0], xwin, NULL );
}
}

void
Glf_TestGLContextPrivate::makeCurrent( ) const
{
glXMakeContextCurrent(_dpy, _win, _win, _context);

_currenGLContext=this;
}

bool
Glf_TestGLContextPrivate::isValid()
{
return _context!=NULL;
}

const Glf_TestGLContextPrivate *
Glf_TestGLContextPrivate::currentContext()
{
return _currenGLContext;
}

bool
Glf_TestGLContextPrivate::areSharing( const Glf_TestGLContextPrivate * context1, const Glf_TestGLContextPrivate * context2 )
{
if (!context1 || !context2)
return false;

return context1->_sharedContext==context2->_sharedContext;
}

Glf_TestGLContextPrivate *
_GetSharedContext()
{
Expand Down Expand Up @@ -217,4 +121,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const
}

PXR_NAMESPACE_CLOSE_SCOPE

52 changes: 52 additions & 0 deletions pxr/imaging/glf/testGLNullContext.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// Copyright 2024 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#include "testGLNullContext.h"

PXR_NAMESPACE_OPEN_SCOPE

Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext=nullptr;

Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const *)
{
}

void
Glf_TestGLContextPrivate::makeCurrent( ) const
{
_currenGLContext=this;
}

bool
Glf_TestGLContextPrivate::isValid()
{
return true;
}

bool
Glf_TestGLContextPrivate::operator==(const Glf_TestGLContextPrivate& rhs) const
{
return true;
}

const Glf_TestGLContextPrivate *
Glf_TestGLContextPrivate::currentContext()
{
return _currenGLContext;
}

bool
Glf_TestGLContextPrivate::areSharing(
const Glf_TestGLContextPrivate * context1,
const Glf_TestGLContextPrivate * context2)
{
if (!context1 || !context2)
return false;

return context1->_sharedContext==context2->_sharedContext;
}

PXR_NAMESPACE_CLOSE_SCOPE
39 changes: 39 additions & 0 deletions pxr/imaging/glf/testGLNullContext.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Copyright 2024 Pixar
//
// Licensed under the terms set forth in the LICENSE.txt file available at
// https://openusd.org/license.
//
#ifndef PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H
#define PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H

/// \file glf/testGLNull/Context.h

#include "pxr/pxr.h"

PXR_NAMESPACE_OPEN_SCOPE

class Glf_TestGLContextPrivate {
public:
Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other=nullptr );

void makeCurrent( ) const;

bool isValid();

bool operator==(const Glf_TestGLContextPrivate& rhs) const;

static const Glf_TestGLContextPrivate * currentContext();

static bool areSharing( const Glf_TestGLContextPrivate * context1,
const Glf_TestGLContextPrivate * context2 );

private:
Glf_TestGLContextPrivate const * _sharedContext;

static Glf_TestGLContextPrivate const * _currenGLContext;
};

PXR_NAMESPACE_CLOSE_SCOPE

#endif //PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H
Loading

0 comments on commit f52a686

Please sign in to comment.