Skip to content

Commit bbca86f

Browse files
committed
Enable experimental Vulkan testing on macOS
1 parent d1ebe6f commit bbca86f

File tree

24 files changed

+631
-384
lines changed

24 files changed

+631
-384
lines changed

build_scripts/build_usd.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,10 +1410,6 @@ def InstallOpenSubdiv(context, force, buildArgs):
14101410
'-DNO_TBB=ON',
14111411
]
14121412

1413-
# Use Metal for macOS and all Apple embedded systems.
1414-
if MacOS():
1415-
extraArgs.append('-DNO_OPENGL=ON')
1416-
14171413
# Add on any user-specified extra arguments.
14181414
extraArgs += buildArgs
14191415

cmake/defaults/Options.cmake

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ option(PXR_BUILD_MAYAPY_TESTS "Build mayapy spline tests" OFF)
3535
option(PXR_BUILD_ANIMX_TESTS "Build AnimX spline tests" OFF)
3636
option(PXR_ENABLE_NAMESPACES "Enable C++ namespaces." ON)
3737
option(PXR_PREFER_SAFETY_OVER_SPEED
38-
"Enable certain checks designed to avoid crashes or out-of-bounds memory reads with malformed input files. These checks may negatively impact performance."
39-
ON)
38+
"Enable certain checks designed to avoid crashes or out-of-bounds memory reads with malformed input files.\
39+
These checks may negatively impact performance." ON)
40+
option(PXR_ENABLE_EXPERIMENTAL_TESTS "Enable experimental tests on macOS.\
41+
These aren't guaranteed to pass." OFF)
4042

4143
if(APPLE)
4244
# Cross Compilation detection as defined in CMake docs
@@ -68,16 +70,17 @@ if(APPLE)
6870
endif ()
6971
endif()
7072

71-
72-
# Determine GFX api
73+
# Determine graphics API
74+
# In the current state of USD, OpenGL support is always required to build.
75+
include(CMakeDependentOption)
76+
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
7377
# Metal only valid on Apple platforms
74-
set(pxr_enable_metal "OFF")
7578
if(APPLE)
76-
set(pxr_enable_metal "ON")
79+
cmake_dependent_option(PXR_ENABLE_METAL_SUPPORT "Enable Metal based components" ON "PXR_ENABLE_GL_SUPPORT" OFF)
80+
else()
81+
set(PXR_ENABLE_METAL_SUPPORT OFF CACHE BOOL "Enable Metal based components" FORCE)
7782
endif()
78-
option(PXR_ENABLE_METAL_SUPPORT "Enable Metal based components" "${pxr_enable_metal}")
79-
option(PXR_ENABLE_VULKAN_SUPPORT "Enable Vulkan based components" OFF)
80-
option(PXR_ENABLE_GL_SUPPORT "Enable OpenGL based components" ON)
83+
cmake_dependent_option(PXR_ENABLE_VULKAN_SUPPORT "Enable Vulkan based components" OFF "PXR_ENABLE_GL_SUPPORT" OFF)
8184

8285
# Precompiled headers are a win on Windows, not on gcc.
8386
set(pxr_enable_pch "OFF")

cmake/defaults/Packages.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ if (PXR_BUILD_IMAGING)
266266
# --X11
267267
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
268268
find_package(X11)
269+
add_definitions(-DPXR_X11_SUPPORT_ENABLED)
269270
endif()
270271
# --Embree
271272
if (PXR_BUILD_EMBREE_PLUGIN)

extras/imaging/examples/hdTiny/CMakeLists.txt

Lines changed: 40 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,47 @@ pxr_plugin(${PXR_PACKAGE}
1818
DISABLE_PRECOMPILED_HEADERS
1919
)
2020

21-
pxr_build_test(testHdTiny
22-
LIBRARIES
23-
hdx
24-
25-
CPPFILES
26-
testenv/testHdTiny.cpp
27-
)
28-
29-
pxr_install_test_dir(
30-
SRC testenv/testHdTiny
31-
DEST testHdTiny
32-
)
21+
if (PXR_ENABLE_GL_SUPPORT)
22+
pxr_build_test(testHdTiny
23+
LIBRARIES
24+
hdx
3325

34-
# This test only runs on MacOS and Linux for now.
35-
if (APPLE)
36-
pxr_register_test(testHdTiny
37-
ENV
38-
DYLD_INSERT_LIBRARIES=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.dylib
39-
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
40-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
41-
STDOUT_REDIRECT output.txt
42-
DIFF_COMPARE output.txt
26+
CPPFILES
27+
testenv/testHdTiny.cpp
4328
)
44-
elseif (UNIX)
45-
pxr_register_test(testHdTiny
46-
ENV
47-
LD_PRELOAD=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.so
48-
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
49-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
50-
STDOUT_REDIRECT output.txt
51-
DIFF_COMPARE output.txt
52-
)
53-
elseif (WIN32)
54-
pxr_register_test(testHdTiny
55-
ENV
56-
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
57-
PRE_PATH
58-
${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny
59-
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
60-
STDOUT_REDIRECT output.txt
61-
DIFF_COMPARE output.txt
29+
30+
pxr_install_test_dir(
31+
SRC testenv/testHdTiny
32+
DEST testHdTiny
6233
)
34+
35+
if (APPLE)
36+
pxr_register_test(testHdTiny
37+
ENV
38+
DYLD_INSERT_LIBRARIES=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.dylib
39+
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
40+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
41+
STDOUT_REDIRECT output.txt
42+
DIFF_COMPARE output.txt
43+
)
44+
elseif (UNIX)
45+
pxr_register_test(testHdTiny
46+
ENV
47+
LD_PRELOAD=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny.so
48+
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
49+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
50+
STDOUT_REDIRECT output.txt
51+
DIFF_COMPARE output.txt
52+
)
53+
elseif (WIN32)
54+
pxr_register_test(testHdTiny
55+
ENV
56+
${PXR_PLUGINPATH_NAME}=${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny/resources
57+
PRE_PATH
58+
${CMAKE_INSTALL_PREFIX}/share/usd/examples/plugin/hdTiny
59+
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdTiny"
60+
STDOUT_REDIRECT output.txt
61+
DIFF_COMPARE output.txt
62+
)
63+
endif()
6364
endif()

pxr/imaging/glf/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ endif()
99

1010
set(optionalPublicClasses "")
1111
if (X11_FOUND)
12-
list(APPEND optionalPublicClasses testGLContext)
12+
list(APPEND optionalPublicClasses testGLXContext)
13+
else()
14+
list(APPEND optionalPublicClasses testGLNullContext)
1315
endif()
1416

1517
pxr_library(glf
@@ -37,6 +39,7 @@ pxr_library(glf
3739
simpleLightingContext
3840
simpleMaterial
3941
simpleShadowArray
42+
testGLContext
4043
texture
4144
uniformBlock
4245
utils

pxr/imaging/glf/testGLContext.cpp

Lines changed: 5 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -8,112 +8,16 @@
88

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

11-
#include <GL/glx.h>
11+
#ifdef PXR_X11_SUPPORT_ENABLED
12+
#include "pxr/imaging/glf/testGLXContext.h"
13+
#else
14+
#include "pxr/imaging/glf/testGLNullContext.h"
15+
#endif
1216

13-
#include <stdio.h>
1417

1518
PXR_NAMESPACE_OPEN_SCOPE
1619

1720

18-
class Glf_TestGLContextPrivate {
19-
public:
20-
Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other=NULL );
21-
22-
void makeCurrent( ) const;
23-
24-
bool isValid();
25-
26-
bool operator==(const Glf_TestGLContextPrivate& rhs) const
27-
{
28-
return _dpy == rhs._dpy && _context == rhs._context;
29-
}
30-
31-
static const Glf_TestGLContextPrivate * currentContext();
32-
33-
static bool areSharing( const Glf_TestGLContextPrivate * context1,
34-
const Glf_TestGLContextPrivate * context2 );
35-
36-
private:
37-
Display * _dpy;
38-
39-
GLXContext _context;
40-
41-
Glf_TestGLContextPrivate const * _sharedContext;
42-
43-
static GLXWindow _win;
44-
45-
static Glf_TestGLContextPrivate const * _currenGLContext;
46-
};
47-
48-
Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext=NULL;
49-
GLXWindow Glf_TestGLContextPrivate::_win=0;
50-
51-
Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other )
52-
: _dpy(NULL), _context(NULL)
53-
{
54-
static int attribs[] = { GLX_DOUBLEBUFFER, GLX_RGBA_BIT,
55-
GLX_RED_SIZE, 8, GLX_GREEN_SIZE, 8, GLX_BLUE_SIZE, 8,
56-
GLX_SAMPLE_BUFFERS, 1, GLX_SAMPLES, 4, None };
57-
58-
_dpy = XOpenDisplay(0);
59-
60-
int n;
61-
GLXFBConfig * fbConfigs = glXChooseFBConfig( _dpy,
62-
DefaultScreen(_dpy), attribs, &n );
63-
64-
GLXContext share = other ? other->_context : 0;
65-
66-
_context = glXCreateNewContext( _dpy,
67-
fbConfigs[0], GLX_RGBA_TYPE, share, true);
68-
69-
_sharedContext=other ? other : this;
70-
71-
if (!_win) {
72-
XVisualInfo * vi = glXGetVisualFromFBConfig( _dpy, fbConfigs[0] );
73-
74-
XSetWindowAttributes swa;
75-
swa.colormap = XCreateColormap(_dpy, RootWindow(_dpy, vi->screen),
76-
vi->visual, AllocNone);
77-
swa.border_pixel = 0;
78-
swa.event_mask = StructureNotifyMask;
79-
80-
Window xwin = XCreateWindow( _dpy, RootWindow(_dpy, vi->screen),
81-
0, 0, 256, 256, 0, vi->depth, InputOutput, vi->visual,
82-
CWBorderPixel|CWColormap|CWEventMask, &swa );
83-
84-
_win = glXCreateWindow( _dpy, fbConfigs[0], xwin, NULL );
85-
}
86-
}
87-
88-
void
89-
Glf_TestGLContextPrivate::makeCurrent( ) const
90-
{
91-
glXMakeContextCurrent(_dpy, _win, _win, _context);
92-
93-
_currenGLContext=this;
94-
}
95-
96-
bool
97-
Glf_TestGLContextPrivate::isValid()
98-
{
99-
return _context!=NULL;
100-
}
101-
102-
const Glf_TestGLContextPrivate *
103-
Glf_TestGLContextPrivate::currentContext()
104-
{
105-
return _currenGLContext;
106-
}
107-
108-
bool
109-
Glf_TestGLContextPrivate::areSharing( const Glf_TestGLContextPrivate * context1, const Glf_TestGLContextPrivate * context2 )
110-
{
111-
if (!context1 || !context2)
112-
return false;
113-
114-
return context1->_sharedContext==context2->_sharedContext;
115-
}
116-
11721
Glf_TestGLContextPrivate *
11822
_GetSharedContext()
11923
{
@@ -217,4 +121,3 @@ GlfTestGLContext::_IsEqual(GlfGLContextSharedPtr const &rhs) const
217121
}
218122

219123
PXR_NAMESPACE_CLOSE_SCOPE
220-
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// Copyright 2024 Pixar
3+
//
4+
// Licensed under the terms set forth in the LICENSE.txt file available at
5+
// https://openusd.org/license.
6+
//
7+
#include "testGLNullContext.h"
8+
9+
PXR_NAMESPACE_OPEN_SCOPE
10+
11+
Glf_TestGLContextPrivate const * Glf_TestGLContextPrivate::_currenGLContext=nullptr;
12+
13+
Glf_TestGLContextPrivate::Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const *)
14+
{
15+
}
16+
17+
void
18+
Glf_TestGLContextPrivate::makeCurrent( ) const
19+
{
20+
_currenGLContext=this;
21+
}
22+
23+
bool
24+
Glf_TestGLContextPrivate::isValid()
25+
{
26+
return true;
27+
}
28+
29+
bool
30+
Glf_TestGLContextPrivate::operator==(const Glf_TestGLContextPrivate& rhs) const
31+
{
32+
return true;
33+
}
34+
35+
const Glf_TestGLContextPrivate *
36+
Glf_TestGLContextPrivate::currentContext()
37+
{
38+
return _currenGLContext;
39+
}
40+
41+
bool
42+
Glf_TestGLContextPrivate::areSharing(
43+
const Glf_TestGLContextPrivate * context1,
44+
const Glf_TestGLContextPrivate * context2)
45+
{
46+
if (!context1 || !context2)
47+
return false;
48+
49+
return context1->_sharedContext==context2->_sharedContext;
50+
}
51+
52+
PXR_NAMESPACE_CLOSE_SCOPE
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// Copyright 2024 Pixar
3+
//
4+
// Licensed under the terms set forth in the LICENSE.txt file available at
5+
// https://openusd.org/license.
6+
//
7+
#ifndef PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H
8+
#define PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H
9+
10+
/// \file glf/testGLNull/Context.h
11+
12+
#include "pxr/pxr.h"
13+
14+
PXR_NAMESPACE_OPEN_SCOPE
15+
16+
class Glf_TestGLContextPrivate {
17+
public:
18+
Glf_TestGLContextPrivate( Glf_TestGLContextPrivate const * other=nullptr );
19+
20+
void makeCurrent( ) const;
21+
22+
bool isValid();
23+
24+
bool operator==(const Glf_TestGLContextPrivate& rhs) const;
25+
26+
static const Glf_TestGLContextPrivate * currentContext();
27+
28+
static bool areSharing( const Glf_TestGLContextPrivate * context1,
29+
const Glf_TestGLContextPrivate * context2 );
30+
31+
private:
32+
Glf_TestGLContextPrivate const * _sharedContext;
33+
34+
static Glf_TestGLContextPrivate const * _currenGLContext;
35+
};
36+
37+
PXR_NAMESPACE_CLOSE_SCOPE
38+
39+
#endif //PXR_IMAGING_GLF_TEST_GLNULLCONTEXT_H

0 commit comments

Comments
 (0)