-
Notifications
You must be signed in to change notification settings - Fork 490
Add DirectX 12 GPU backend for automated unit testing on Windows #2271
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
base: main
Are you sure you want to change the base?
Changes from all commits
d328a19
c8deabb
015da53
85d007f
6419c94
fb53430
a9e069a
c1aaf9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -287,6 +287,8 @@ Here are the most common OCIO-specific CMake options (the default values are sho | |
| - ``-DOCIO_BUILD_TESTS=ON`` (Set to OFF to not build the unit tests) | ||
| - ``-DOCIO_BUILD_GPU_TESTS=ON`` (Set to OFF to not build the GPU unit tests) | ||
| - ``-DOCIO_USE_HEADLESS=OFF`` (Set to ON to do headless GPU rendering) | ||
| - ``-DOCIO_DIRECTX_ENABLED=ON`` (Windows only; set to OFF to disable the DirectX 12 GPU rendering backend used by ``test_dx``. Forced OFF on non-Windows platforms.) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default-enabled for windows platforms, but let me know if you prefer leaving it off by default for now. |
||
| - ``-DOCIO_VULKAN_ENABLED=OFF`` (Set to ON to enable the Vulkan GPU rendering backend used by ``test_vulkan``. Requires the Vulkan SDK to be installed and findable by CMake.) | ||
| - ``-DOCIO_WARNING_AS_ERROR=ON`` (Set to OFF to turn off warnings as errors) | ||
| - ``-DOCIO_BUILD_DOCS=OFF`` (Set to ON to build the documentation) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright Contributors to the OpenColorIO Project. | ||
| # | ||
| # Locate DirectX-Headers (header-only, Windows only) | ||
| # | ||
| # Variables defined by this module: | ||
| # DirectX-Headers_FOUND - Indicate whether the package was found or not | ||
| # DirectX-Headers_INCLUDE_DIR - Location of the header files | ||
| # DirectX-Headers_VERSION - Package version | ||
| # | ||
| # Global targets defined by this module: | ||
| # Microsoft::DirectX-Headers | ||
| # | ||
| # DirectX-Headers can be supplied by the caller through any of the standard | ||
| # CMake mechanisms: | ||
| # -- Set -DDirectX-Headers_DIR to the directory containing directx-headers-config.cmake | ||
| # -- Set -DDirectX-Headers_ROOT to the install prefix (with include/directx/ underneath) | ||
| # -- Set -DDirectX-Headers_INCLUDE_DIR to the directory containing directx/d3d12.h | ||
| # | ||
| # When OCIO_INSTALL_EXT_PACKAGES is not ALL, this module first tries to locate | ||
| # an existing install via the upstream CMake config, then falls back to a | ||
| # manual header search. If still not found and OCIO_INSTALL_EXT_PACKAGES is | ||
| # MISSING (the default), OCIO's ocio_install_dependency() pathway will invoke | ||
| # InstallDirectX-Headers.cmake to build it via FetchContent. | ||
| # | ||
|
|
||
| if(NOT OCIO_INSTALL_EXT_PACKAGES STREQUAL ALL) | ||
| # Prefer the upstream CMake config (installed as lower-case). | ||
| find_package(directx-headers ${DirectX-Headers_FIND_VERSION} CONFIG QUIET) | ||
|
|
||
| if(directx-headers_FOUND) | ||
| set(DirectX-Headers_FOUND TRUE) | ||
| if(directx-headers_VERSION) | ||
| set(DirectX-Headers_VERSION ${directx-headers_VERSION}) | ||
| endif() | ||
| else() | ||
| # Fall back to locating the public header directly (e.g. when the | ||
| # headers were installed without the CMake config, or are provided | ||
| # by a vendored copy). | ||
| find_path(DirectX-Headers_INCLUDE_DIR | ||
| NAMES | ||
| directx/d3d12.h | ||
| HINTS | ||
| ${DirectX-Headers_ROOT} | ||
| PATH_SUFFIXES | ||
| include | ||
| ) | ||
| endif() | ||
|
|
||
| # If OCIO can install the package itself, demote REQUIRED so a missing | ||
| # dependency here does not abort configuration before the install step. | ||
| if(OCIO_INSTALL_EXT_PACKAGES STREQUAL MISSING) | ||
| set(DirectX-Headers_FIND_REQUIRED FALSE) | ||
| endif() | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(DirectX-Headers | ||
| REQUIRED_VARS | ||
| DirectX-Headers_INCLUDE_DIR | ||
| VERSION_VAR | ||
| DirectX-Headers_VERSION | ||
| ) | ||
| endif() | ||
|
|
||
| ############################################################################### | ||
| ### Create target (only needed for the manual-header-search fallback; the | ||
| ### upstream CMake config already defines Microsoft::DirectX-Headers). | ||
|
|
||
| if(DirectX-Headers_FOUND AND NOT TARGET Microsoft::DirectX-Headers AND DirectX-Headers_INCLUDE_DIR) | ||
| add_library(Microsoft::DirectX-Headers INTERFACE IMPORTED GLOBAL) | ||
| set_target_properties(Microsoft::DirectX-Headers PROPERTIES | ||
| INTERFACE_INCLUDE_DIRECTORIES "${DirectX-Headers_INCLUDE_DIR}" | ||
| ) | ||
|
|
||
| mark_as_advanced(DirectX-Headers_INCLUDE_DIR DirectX-Headers_VERSION) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright Contributors to the OpenColorIO Project. | ||
| # | ||
| # Install DirectX-Headers (header-only, Windows only) | ||
| # https://github.com/microsoft/DirectX-Headers | ||
| # | ||
| ############################################################################### | ||
|
|
||
| include(FetchContent) | ||
|
|
||
| set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/ext/build/DirectX-Headers") | ||
| set(DIRECTX_HEADERS_BUILD_TEST OFF CACHE BOOL "" FORCE) | ||
|
|
||
| FetchContent_Declare(DirectX-Headers | ||
| GIT_REPOSITORY https://github.com/microsoft/DirectX-Headers.git | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a blocker I think but may be nice to offer a way to specify a path manually for Windows systems without internet access (unless you already did and I missed it in the PR). |
||
| GIT_TAG v1.619.1 | ||
| ) | ||
|
|
||
| FetchContent_MakeAvailable(DirectX-Headers) | ||
|
|
||
| # Signal success to ocio_install_dependency so ocio_handle_dependency does not | ||
| # abort at the next required-check. FetchContent_MakeAvailable has just created | ||
| # the Microsoft::DirectX-Headers target via the upstream CMakeLists. | ||
| if(TARGET Microsoft::DirectX-Headers) | ||
| set(DirectX-Headers_FOUND TRUE) | ||
| set(DirectX-Headers_VERSION "1.619.1") | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # Copyright Contributors to the OpenColorIO Project. | ||
| # | ||
| # Locate the dxcompiler.dll + dxil.dll runtime pair needed to run D3D12 shader | ||
| # compilation at test time, and surface their file version. | ||
| # | ||
| # Inputs: | ||
| # OCIO_DXCOMPILER_DLL - Optional user-supplied path to dxcompiler.dll. | ||
| # When set, overrides the Windows SDK Redist/D3D | ||
| # search. Useful when the SDK-bundled DLL is too old. | ||
| # | ||
| # Outputs: | ||
| # DXCOMPILER_DLL - Path to dxcompiler.dll (cache variable). | ||
| # DXIL_DLL - Path to the adjacent dxil.dll (cache variable, may | ||
| # be left unset if not found next to dxcompiler.dll). | ||
|
|
||
| set(OCIO_DXCOMPILER_DLL "" CACHE FILEPATH | ||
| "Optional explicit path to dxcompiler.dll (e.g. from a newer DirectX Shader Compiler release). \ | ||
| Overrides the automatic Windows SDK Redist/D3D search." | ||
| ) | ||
|
|
||
| if(OCIO_DXCOMPILER_DLL) | ||
| if(NOT EXISTS "${OCIO_DXCOMPILER_DLL}") | ||
| message(FATAL_ERROR "OCIO_DXCOMPILER_DLL=${OCIO_DXCOMPILER_DLL} does not exist.") | ||
| endif() | ||
| set(DXCOMPILER_DLL "${OCIO_DXCOMPILER_DLL}" CACHE FILEPATH | ||
| "Path to dxcompiler.dll (user-supplied via OCIO_DXCOMPILER_DLL)" FORCE) | ||
| else() | ||
| find_file(DXCOMPILER_DLL | ||
| NAMES dxcompiler.dll | ||
| PATHS | ||
| # Note: x64 hardcoded; update if ARM64 Windows support is needed. | ||
| "$ENV{WindowsSdkDir}Redist/D3D/x64" | ||
| "C:/Program Files (x86)/Windows Kits/10/Redist/D3D/x64" | ||
| NO_DEFAULT_PATH | ||
| DOC "Path to dxcompiler.dll from Windows SDK" | ||
| ) | ||
| endif() | ||
|
|
||
| if(DXCOMPILER_DLL) | ||
| get_filename_component(_dxc_dll_dir "${DXCOMPILER_DLL}" DIRECTORY) | ||
| find_file(DXIL_DLL | ||
| NAMES dxil.dll | ||
| HINTS "${_dxc_dll_dir}" | ||
| NO_DEFAULT_PATH | ||
| ) | ||
|
|
||
| # Report the found dxcompiler.dll version so crash reports can identify | ||
| # mismatched or outdated DXC builds without re-running diagnostics. | ||
| string(REPLACE "'" "''" _dxc_dll_ps "${DXCOMPILER_DLL}") | ||
| execute_process( | ||
| COMMAND powershell -NoProfile -Command | ||
| "(Get-Item -LiteralPath '${_dxc_dll_ps}').VersionInfo.FileVersion" | ||
| OUTPUT_VARIABLE _dxc_version | ||
| OUTPUT_STRIP_TRAILING_WHITESPACE | ||
| ERROR_QUIET | ||
| ) | ||
| if(_dxc_version) | ||
| message(STATUS "Found dxcompiler.dll (version ${_dxc_version}): ${DXCOMPILER_DLL}") | ||
| else() | ||
| message(STATUS "Found dxcompiler.dll (version unknown): ${DXCOMPILER_DLL}") | ||
| endif() | ||
| message(STATUS | ||
| "If test_dx crashes during shader compilation, the Windows SDK's dxcompiler.dll " | ||
| "may be too old to produce signed DXIL on this system. Replace it with a newer " | ||
| "build from https://github.com/microsoft/DirectXShaderCompiler/releases, or set " | ||
| "-DOCIO_DXCOMPILER_DLL=<path> to point at a specific dxcompiler.dll." | ||
| ) | ||
| else() | ||
| message(WARNING | ||
| "OCIO_DIRECTX_ENABLED is ON but dxcompiler.dll was not found in the " | ||
| "Windows SDK Redist/D3D path. test_dx will fail at runtime unless " | ||
| "dxcompiler.dll and dxil.dll are on PATH. Install the Windows SDK " | ||
| "redistributable components, set -DOCIO_DXCOMPILER_DLL=<path> to supply " | ||
| "a specific dxcompiler.dll, or set -DOCIO_DIRECTX_ENABLED=OFF to " | ||
| "disable the DirectX 12 backend." | ||
| ) | ||
| endif() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not from this PR but maybe we should use this opportunity to also add the same option for
OCIO_VULKAN_ENABLED.