Skip to content

Commit

Permalink
Support pulling D3D12TranslationLayer with FetchContent (#15)
Browse files Browse the repository at this point in the history
Thanks to FetchContent, it's now easier than ever to contribute to
D3D11On12! Even if you only clone the 11on12 project it will
automatically download the dependencies for you and add them to the
solution.
  • Loading branch information
vdwtanner authored May 27, 2021
1 parent 9e805c7 commit b8873b2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.14)
project(d3d11on12)

set(CMAKE_CXX_STANDARD 17)
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@ The device object internally uses an instance of the D3D12TranslationLayer immed

## Building

This project is expected to be included in a CMake build environment where the D3D12TranslationLayer project is also included. Additionally, the [WDK](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) (Windows Driver Kit) must be installed, in order to provide `d3d10umddi.h` to D3D11On12, and in order to generate the D3D12TranslationLayer_WDK project, which hosts some code required to parse DXBC shaders and containers.
In order to build D3D11On12, the [WDK](https://docs.microsoft.com/en-us/windows-hardware/drivers/download-the-wdk) (Windows Driver Kit) must be installed, in order to provide `d3d10umddi.h` to D3D11On12, and in order to generate the D3D12TranslationLayer_WDK project, which hosts some code required to parse DXBC shaders and containers. The D3D12TranslationLayer and its subprojects, D3D12TranslationLayer_WDK and DXBCParser, will be fetched from GitHub when building with CMake if D3D12TranslationLayer_WDK isn't already included, such as by a parent CMakeLists.txt that has already entered that project. Assuming there was a top level `CMakeLists.txt` in a directory that included both D3D11On12 and D3D12TranslationLayer, you could achieve that like this:

At the time of publishing, the D3D11On12 and D3D12TranslationLayer require **insider** versions of the SDK and WDK. Those can be found [here](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewWDK).
```CMake
cmake_minimum_required(VERSION 3.14)
include(FetchContent)
An example CMakeLists.txt for building D3D11On12 would be:
FetchContent_Declare(
d3d12translationlayer
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/D3D12TranslationLayer
)
FetchContent_MakeAvailable(d3d12translationlayer)
```
cmake_minimum_required(VERSION 3.13)
add_subdirectory(D3D12TranslationLayer)
add_subdirectory(D3D11On12)
```

At the time of publishing, the D3D11On12 and D3D12TranslationLayer require **insider** versions of the SDK and WDK. Those can be found [here](https://www.microsoft.com/en-us/software-download/windowsinsiderpreviewWDK).

D3D11On12 requires C++17, and only supports building with MSVC at the moment.

## Why open source?
Expand Down
11 changes: 10 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
cmake_minimum_required(VERSION 3.13)
cmake_minimum_required(VERSION 3.14)
include(FetchContent)

file(GLOB SRC CONFIGURE_DEPENDS *.cpp)
file(GLOB INC ../include/*.h ../include/*.hpp ../interface/*.h *.h *.hpp)
Expand All @@ -9,6 +10,14 @@ file(GLOB INL ../include/*.inl *.inl)
file(GLOB_RECURSE EXTERNAL_INC ../external/*.h ../external/*.hpp)

add_library(d3d11on12 SHARED ${SRC} ${INC} ${INL} ${EXTERNAL_INC} d3d11on12.rc d3d11on12.def)

FetchContent_Declare(
d3d12translationlayer
GIT_REPOSITORY https://github.com/microsoft/D3D12TranslationLayer.git
GIT_TAG 6ba530c050d781d82289d26f04db1119861bb521
)
FetchContent_MakeAvailable(d3d12translationlayer)

target_link_libraries(d3d11on12 d3d12translationlayer_wdk)
target_include_directories(d3d11on12
PRIVATE ../include
Expand Down

0 comments on commit b8873b2

Please sign in to comment.