├── .github ├── dependabot.yml └── workflows │ ├── codeql.yml │ ├── main.yml │ ├── msvc.yml │ ├── uwp.yml │ └── wsl.yml ├── .gitignore ├── Android.bp ├── CMakeLists.txt ├── CMakePresets.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── cmake ├── DirectX-Headers.pc.in ├── JoinPaths.cmake └── directx-headers-config.cmake.in ├── googletest ├── CMakeLists.txt ├── MockDevice.hpp ├── feature_support_test.cpp └── meson.build ├── include ├── directx │ ├── D3D12TokenizedProgramFormat.hpp │ ├── DirectML.h │ ├── d3d12.h │ ├── d3d12.idl │ ├── d3d12compatibility.h │ ├── d3d12compatibility.idl │ ├── d3d12sdklayers.h │ ├── d3d12sdklayers.idl │ ├── d3d12shader.h │ ├── d3d12video.h │ ├── d3d12video.idl │ ├── d3dcommon.h │ ├── d3dcommon.idl │ ├── d3dx12.h │ ├── d3dx12_barriers.h │ ├── d3dx12_check_feature_support.h │ ├── d3dx12_core.h │ ├── d3dx12_default.h │ ├── d3dx12_pipeline_state_stream.h │ ├── d3dx12_property_format_table.h │ ├── d3dx12_render_pass.h │ ├── d3dx12_resource_helpers.h │ ├── d3dx12_root_signature.h │ ├── d3dx12_state_object.h │ ├── dxcore.h │ ├── dxcore_interface.h │ ├── dxgicommon.h │ ├── dxgicommon.idl │ ├── dxgiformat.h │ └── dxgiformat.idl ├── dxguids │ └── dxguids.h └── wsl │ ├── stubs │ ├── basetsd.h │ ├── oaidl.h │ ├── ocidl.h │ ├── rpc.h │ ├── rpcndr.h │ ├── unknwn.h │ ├── unknwnbase.h │ ├── winapifamily.h │ └── wrl │ │ ├── client.h │ │ └── implements.h │ ├── winadapter.h │ └── wrladapter.h ├── meson.build ├── meson_options.txt ├── src ├── d3dx12_property_format_table.cpp └── dxguids.cpp └── test ├── CMakeLists.txt ├── feature_check_test.cpp ├── meson.build └── test.cpp /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: weekly 7 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: "CodeQL" 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | schedule: 15 | - cron: '15 2 * * 4' 16 | 17 | permissions: 18 | contents: read 19 | 20 | jobs: 21 | analyze: 22 | name: Analyze (C/C++) 23 | runs-on: windows-latest 24 | timeout-minutes: 360 25 | permissions: 26 | actions: read # for github/codeql-action/init to get workflow details 27 | contents: read # for actions/checkout to fetch code 28 | security-events: write # for github/codeql-action/autobuild to send a status report 29 | packages: read 30 | 31 | steps: 32 | - name: Checkout repository 33 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 34 | 35 | - name: 'Install Ninja' 36 | run: choco install ninja 37 | 38 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 39 | 40 | - name: Initialize CodeQL 41 | uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 42 | with: 43 | languages: c-cpp 44 | build-mode: manual 45 | 46 | - name: 'Configure CMake' 47 | working-directory: ${{ github.workspace }} 48 | run: cmake --preset=x64-Debug 49 | 50 | - name: 'Build' 51 | working-directory: ${{ github.workspace }} 52 | run: cmake --build out\build\x64-Debug 53 | 54 | - name: Perform CodeQL Analysis 55 | uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 56 | with: 57 | category: "/language:c-cpp" 58 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (Windows)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | build: 20 | runs-on: ${{ matrix.os }} 21 | 22 | strategy: 23 | fail-fast: false 24 | 25 | matrix: 26 | os: [windows-2019, windows-2022] 27 | build_type: [x64-Debug, x64-Release] 28 | arch: [amd64] 29 | include: 30 | - os: windows-2019 31 | build_type: x86-Debug 32 | arch: amd64_x86 33 | - os: windows-2019 34 | build_type: x86-Release 35 | arch: amd64_x86 36 | - os: windows-2022 37 | build_type: x86-Debug 38 | arch: amd64_x86 39 | - os: windows-2022 40 | build_type: x86-Release 41 | arch: amd64_x86 42 | - os: windows-2022 43 | build_type: arm64-Debug 44 | arch: amd64_arm64 45 | - os: windows-2022 46 | build_type: arm64-Release 47 | arch: amd64_arm64 48 | - os: windows-2022 49 | build_type: arm64ec-Debug 50 | arch: amd64_arm64 51 | - os: windows-2022 52 | build_type: arm64ec-Release 53 | arch: amd64_arm64 54 | - os: windows-2022 55 | build_type: x64-Debug-Clang 56 | arch: amd64 57 | - os: windows-2022 58 | build_type: x64-Release-Clang 59 | arch: amd64 60 | - os: windows-2022 61 | build_type: x86-Debug-Clang 62 | arch: amd64_x86 63 | - os: windows-2022 64 | build_type: x86-Release-Clang 65 | arch: amd64_x86 66 | - os: windows-2022 67 | build_type: arm64-Debug-Clang 68 | arch: amd64_arm64 69 | - os: windows-2022 70 | build_type: arm64-Release-Clang 71 | arch: amd64_arm64 72 | - os: windows-2022 73 | build_type: x64-Debug-MinGW 74 | arch: amd64 75 | - os: windows-2022 76 | build_type: x64-Release-MinGW 77 | arch: amd64 78 | 79 | steps: 80 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 81 | 82 | - name: 'Install Ninja' 83 | run: choco install ninja 84 | 85 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 86 | with: 87 | arch: ${{ matrix.arch }} 88 | 89 | - name: 'Configure CMake' 90 | working-directory: ${{ github.workspace }} 91 | run: cmake --preset=${{ matrix.build_type }} 92 | 93 | - name: 'Build' 94 | working-directory: ${{ github.workspace }} 95 | run: cmake --build out\build\${{ matrix.build_type }} 96 | -------------------------------------------------------------------------------- /.github/workflows/msvc.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: Microsoft C++ Code Analysis 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | schedule: 15 | - cron: '24 13 * * 4' 16 | 17 | permissions: 18 | contents: read 19 | 20 | jobs: 21 | analyze: 22 | permissions: 23 | contents: read 24 | security-events: write 25 | actions: read 26 | name: Analyze 27 | runs-on: windows-latest 28 | 29 | steps: 30 | - name: Checkout repository 31 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 32 | 33 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 34 | with: 35 | arch: amd64 36 | 37 | - name: Configure CMake 38 | working-directory: ${{ github.workspace }} 39 | run: cmake -B out 40 | 41 | - name: Initialize MSVC Code Analysis 42 | uses: microsoft/msvc-code-analysis-action@24c285ab36952c9e9182f4b78dfafbac38a7e5ee # v0.1.1 43 | id: run-analysis 44 | with: 45 | cmakeBuildDirectory: ./out 46 | buildConfiguration: Debug 47 | ruleset: NativeRecommendedRules.ruleset 48 | 49 | # Upload SARIF file to GitHub Code Scanning Alerts 50 | - name: Upload SARIF to GitHub 51 | uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18 52 | with: 53 | sarif_file: ${{ steps.run-analysis.outputs.sarif }} 54 | -------------------------------------------------------------------------------- /.github/workflows/uwp.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (UWP)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | 15 | permissions: 16 | contents: read 17 | 18 | jobs: 19 | build: 20 | runs-on: windows-2022 21 | 22 | strategy: 23 | fail-fast: false 24 | 25 | matrix: 26 | build_type: [x64-Debug-UWP, x64-Release-UWP, x64-Debug-UWP-Clang, x64-Release-UWP-Clang] 27 | arch: [amd64] 28 | include: 29 | - build_type: x86-Debug-UWP 30 | arch: amd64_x86 31 | - build_type: x86-Release-UWP 32 | arch: amd64_x86 33 | - build_type: x86-Debug-UWP-Clang 34 | arch: amd64_x86 35 | - build_type: x86-Release-UWP-Clang 36 | arch: amd64_x86 37 | - build_type: arm64-Debug-UWP 38 | arch: amd64_arm64 39 | - build_type: arm64-Release-UWP 40 | arch: amd64_arm64 41 | - build_type: arm64-Debug-UWP-Clang 42 | arch: amd64_arm64 43 | - build_type: arm64-Release-UWP-Clang 44 | arch: amd64_arm64 45 | 46 | steps: 47 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 48 | 49 | - name: 'Install Ninja' 50 | run: choco install ninja 51 | 52 | - uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0 53 | with: 54 | arch: ${{ matrix.arch }} 55 | uwp: true 56 | 57 | - name: 'Configure CMake' 58 | working-directory: ${{ github.workspace }} 59 | run: cmake --preset=${{ matrix.build_type }} 60 | 61 | - name: 'Build' 62 | working-directory: ${{ github.workspace }} 63 | run: cmake --build out\build\${{ matrix.build_type }} 64 | -------------------------------------------------------------------------------- /.github/workflows/wsl.yml: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | name: 'CMake (WSL)' 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | paths-ignore: 12 | - '*.md' 13 | - LICENSE 14 | 15 | jobs: 16 | build: 17 | runs-on: ubuntu-latest 18 | 19 | strategy: 20 | fail-fast: false 21 | 22 | matrix: 23 | build_type: [x64-Debug-Linux, x64-Release-Linux] 24 | gcc: [12, 13, 14] 25 | 26 | steps: 27 | - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 28 | 29 | - uses: seanmiddleditch/gha-setup-ninja@3b1f8f94a2f8254bd26914c4ab9474d4f0015f67 # v6 30 | 31 | - name: 'Configure CMake' 32 | working-directory: ${{ github.workspace }} 33 | run: > 34 | cmake --preset=${{ matrix.build_type }} 35 | 36 | env: 37 | CC: gcc-${{ matrix.gcc }} 38 | CXX: g++-${{ matrix.gcc }} 39 | 40 | - name: 'Build' 41 | working-directory: ${{ github.workspace }} 42 | run: cmake --build out/build/${{ matrix.build_type }} 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.psess 2 | *.vsp 3 | *.log 4 | *.err 5 | *.wrn 6 | *.suo 7 | *.sdf 8 | *.user 9 | *.i 10 | *.vspscc 11 | *.opensdf 12 | *.opendb 13 | *.ipch 14 | *.cache 15 | *.tlog 16 | *.lastbuildstate 17 | *.ilk 18 | *.VC.db 19 | *.nupkg 20 | .vs 21 | /out 22 | /CMakeUserPresets.json 23 | /build* 24 | -------------------------------------------------------------------------------- /Android.bp: -------------------------------------------------------------------------------- 1 | cc_library_headers { 2 | name: "DirectX-Headers", 3 | export_include_dirs: ["include", "include/wsl/stubs"], 4 | vendor_available: true, 5 | } 6 | 7 | cc_library_static { 8 | name: "DirectX-Guids", 9 | header_libs: ["DirectX-Headers"], 10 | local_include_dirs: ["include/dxguids"], 11 | srcs: ["src/dxguids.cpp"], 12 | cppflags: ["-Wno-non-virtual-dtor", "-Wno-unused-value"], 13 | vendor_available: true, 14 | } 15 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | cmake_minimum_required(VERSION 3.10.2) 4 | project(DirectX-Headers 5 | LANGUAGES CXX 6 | VERSION 1.616.0 7 | ) 8 | include(CTest) 9 | set(CMAKE_CXX_STANDARD 14) 10 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 11 | set(CMAKE_CXX_EXTENSIONS OFF) 12 | enable_testing() 13 | 14 | # It's useful to know if you are a top level project or not, if your project is 15 | # being consumed via add_subdirectory 16 | if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) 17 | set(IS_TOPLEVEL_PROJECT TRUE) 18 | else() 19 | set(IS_TOPLEVEL_PROJECT FALSE) 20 | endif() 21 | 22 | # Use DXHEADERS_* prefix to avoid potential name conflicts in cmake-gui, and allow 23 | # grouping by prefix if more options are added 24 | # 25 | # Testing should only be enabled by default if we are top level. Otherwise clients can set it 26 | # either via cmake or cmake-gui 27 | option(DXHEADERS_BUILD_TEST "Build the test" ${IS_TOPLEVEL_PROJECT}) 28 | option(DXHEADERS_INSTALL "Installation logic" ${IS_TOPLEVEL_PROJECT}) 29 | option(DXHEADERS_BUILD_GOOGLE_TEST "Build the google test suite" ${IS_TOPLEVEL_PROJECT}) 30 | 31 | include(GNUInstallDirs) 32 | 33 | # Enables consumers to add this library as a link target to automatically add 34 | # these include directories, regardless of whether this is referenced via subdirectory 35 | # or from an installed location 36 | add_library(DirectX-Headers STATIC src/d3dx12_property_format_table.cpp) 37 | target_include_directories(DirectX-Headers SYSTEM PUBLIC 38 | "$" 39 | "$" 40 | ) 41 | target_include_directories(DirectX-Headers PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include/directx) 42 | 43 | add_library(Microsoft::DirectX-Headers ALIAS DirectX-Headers) 44 | 45 | add_library(DirectX-Guids STATIC src/dxguids.cpp) 46 | target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers) 47 | 48 | add_library(Microsoft::DirectX-Guids ALIAS DirectX-Guids) 49 | 50 | # For non-Windows targets, also add the WSL stubs to the include path 51 | if (NOT WIN32) 52 | target_include_directories(DirectX-Headers SYSTEM PUBLIC 53 | "$" 54 | "$" 55 | ) 56 | elseif((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")) 57 | # MinGW has RPC headers which define old versions, and complain if D3D 58 | # headers are included before the RPC headers, since D3D headers were 59 | # generated with new MIDL and "require" new RPC headers. 60 | target_compile_definitions(DirectX-Headers PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") 61 | target_compile_definitions(DirectX-Guids PRIVATE "__REQUIRED_RPCNDR_H_VERSION__=475") 62 | endif() 63 | 64 | if (DXHEADERS_INSTALL) 65 | # Install the targets 66 | install(TARGETS DirectX-Headers DirectX-Guids 67 | EXPORT DirectX-Headers-Targets 68 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) 69 | # Create the targets CMake file which contains the above definitions 70 | install(EXPORT DirectX-Headers-Targets FILE directx-headers-targets.cmake 71 | NAMESPACE Microsoft:: 72 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) 73 | 74 | # Install the actual includes 75 | install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/" 76 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) 77 | 78 | # Create the CMake config files 79 | include(CMakePackageConfigHelpers) 80 | write_basic_package_version_file("directx-headers-config-version.cmake" 81 | VERSION ${PROJECT_VERSION} 82 | COMPATIBILITY SameMajorVersion) 83 | configure_package_config_file( 84 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/directx-headers-config.cmake.in" 85 | "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" 86 | INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) 87 | 88 | # Install the CMake config files 89 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake" 90 | "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config-version.cmake" 91 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake) 92 | 93 | # Create pkg-config file 94 | include(cmake/JoinPaths.cmake) 95 | # from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files 96 | join_paths(DIRECTX_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") 97 | join_paths(DIRECTX_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") 98 | configure_file( 99 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/DirectX-Headers.pc.in" 100 | "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" @ONLY) 101 | 102 | # Install the pkg-config file 103 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectX-Headers.pc" 104 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 105 | 106 | endif() 107 | 108 | if (BUILD_TESTING) 109 | if (DXHEADERS_BUILD_TEST) 110 | add_subdirectory(test) 111 | endif() 112 | 113 | if (DXHEADERS_BUILD_GOOGLE_TEST) 114 | # We do not want to install GoogleTest when packaging DirectX-Headers. 115 | set(INSTALL_GTEST OFF) 116 | add_subdirectory(googletest) 117 | endif() 118 | endif() 119 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "configurePresets": [ 4 | { 5 | "name": "base", 6 | "displayName": "Basic Config", 7 | "description": "Basic build using Ninja generator", 8 | "generator": "Ninja", 9 | "hidden": true, 10 | "binaryDir": "${sourceDir}/out/build/${presetName}", 11 | "cacheVariables": { "CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}" } 12 | }, 13 | 14 | { 15 | "name": "x64", 16 | "architecture": { 17 | "value": "x64", 18 | "strategy": "external" 19 | }, 20 | "hidden": true 21 | }, 22 | { 23 | "name": "x86", 24 | "architecture": { 25 | "value": "x86", 26 | "strategy": "external" 27 | }, 28 | "hidden": true 29 | }, 30 | { 31 | "name": "ARM64", 32 | "architecture": { 33 | "value": "arm64", 34 | "strategy": "external" 35 | }, 36 | "hidden": true 37 | }, 38 | { 39 | "name": "ARM64EC", 40 | "architecture": { 41 | "value": "arm64ec", 42 | "strategy": "external" 43 | }, 44 | "environment": { 45 | "CFLAGS": "/arm64EC", 46 | "CXXFLAGS": "/arm64EC" 47 | }, 48 | "hidden": true 49 | }, 50 | 51 | { 52 | "name": "Debug", 53 | "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" }, 54 | "hidden": true 55 | }, 56 | { 57 | "name": "Release", 58 | "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" }, 59 | "hidden": true 60 | }, 61 | 62 | { 63 | "name": "MSVC", 64 | "hidden": true, 65 | "cacheVariables": { 66 | "CMAKE_CXX_COMPILER": "cl.exe", 67 | "CMAKE_C_COMPILER": "cl.exe" 68 | }, 69 | "toolset": { 70 | "value": "host=x64", 71 | "strategy": "external" 72 | } 73 | }, 74 | { 75 | "name": "Clang", 76 | "hidden": true, 77 | "cacheVariables": { 78 | "CMAKE_CXX_COMPILER": "clang-cl.exe", 79 | "CMAKE_C_COMPILER": "clang-cl.exe" 80 | }, 81 | "toolset": { 82 | "value": "host=x64", 83 | "strategy": "external" 84 | } 85 | }, 86 | { 87 | "name": "Clang-X86", 88 | "environment": { 89 | "CFLAGS": "-m32", 90 | "CXXFLAGS": "-m32" 91 | }, 92 | "hidden": true 93 | }, 94 | { 95 | "name": "Clang-AArch64", 96 | "environment": { 97 | "CFLAGS": "--target=arm64-pc-windows-msvc", 98 | "CXXFLAGS": "--target=arm64-pc-windows-msvc" 99 | }, 100 | "hidden": true 101 | }, 102 | { 103 | "name": "GNUC", 104 | "hidden": true, 105 | "cacheVariables": { 106 | "CMAKE_CXX_COMPILER": "g++.exe", 107 | "CMAKE_C_COMPILER": "gcc.exe", 108 | "DXHEADERS_BUILD_TEST": false 109 | }, 110 | "toolset": { 111 | "value": "host=x64", 112 | "strategy": "external" 113 | } 114 | }, 115 | { 116 | "name": "Intel", 117 | "hidden": true, 118 | "cacheVariables": { 119 | "CMAKE_CXX_COMPILER": "icl.exe", 120 | "DXHEADERS_BUILD_GOOGLE_TEST": false, 121 | "DXHEADERS_BUILD_TEST": false 122 | }, 123 | "toolset": { 124 | "value": "host=x64", 125 | "strategy": "external" 126 | } 127 | }, 128 | { 129 | "name": "IntelLLVM", 130 | "hidden": true, 131 | "cacheVariables": { 132 | "CMAKE_CXX_COMPILER": "icx.exe", 133 | "DXHEADERS_BUILD_GOOGLE_TEST": false 134 | }, 135 | "toolset": { 136 | "value": "host=x64", 137 | "strategy": "external" 138 | } 139 | }, 140 | 141 | { 142 | "name": "UWP", 143 | "cacheVariables": { 144 | "CMAKE_SYSTEM_NAME": "WindowsStore", 145 | "CMAKE_SYSTEM_VERSION": "10.0" 146 | }, 147 | "hidden": true 148 | }, 149 | { 150 | "name": "NoTests", 151 | "hidden": true, 152 | "cacheVariables": { 153 | "DXHEADERS_BUILD_TEST": false, 154 | "DXHEADERS_BUILD_GOOGLE_TEST": false 155 | } 156 | }, 157 | 158 | { "name": "x64-Debug" , "description": "MSVC for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "MSVC" ] }, 159 | { "name": "x64-Release" , "description": "MSVC for x64 (Release)", "inherits": [ "base", "x64", "Release", "MSVC" ] }, 160 | { "name": "x86-Debug" , "description": "MSVC for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "MSVC" ] }, 161 | { "name": "x86-Release" , "description": "MSVC for x86 (Release)", "inherits": [ "base", "x86", "Release", "MSVC" ] }, 162 | { "name": "arm64-Debug" , "description": "MSVC for ARM64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "MSVC" ] }, 163 | { "name": "arm64-Release" , "description": "MSVC for ARM64 (Release)", "inherits": [ "base", "ARM64", "Release", "MSVC" ] }, 164 | { "name": "arm64ec-Debug" , "description": "MSVC for ARM64EC (Debug)", "inherits": [ "base", "ARM64EC", "Debug", "MSVC" ] }, 165 | { "name": "arm64ec-Release" , "description": "MSVC for ARM64EC (Release)", "inherits": [ "base", "ARM64EC", "Release", "MSVC" ] }, 166 | 167 | { "name": "x64-Debug-UWP" , "description": "MSVC for x64 (Debug) for UWP", "inherits": [ "base", "x64", "Debug", "MSVC", "UWP" ] }, 168 | { "name": "x64-Release-UWP" , "description": "MSVC for x64 (Release) for UWP", "inherits": [ "base", "x64", "Release", "MSVC", "UWP" ] }, 169 | { "name": "x86-Debug-UWP" , "description": "MSVC for x86 (Debug) for UWP", "inherits": [ "base", "x86", "Debug", "MSVC", "UWP" ] }, 170 | { "name": "x86-Release-UWP" , "description": "MSVC for x86 (Release) for UWP", "inherits": [ "base", "x86", "Release", "MSVC", "UWP" ] }, 171 | { "name": "arm64-Debug-UWP" , "description": "MSVC for ARM64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "MSVC", "UWP" ] }, 172 | { "name": "arm64-Release-UWP", "description": "MSVC for ARM64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "MSVC", "UWP" ] }, 173 | 174 | { "name": "x64-Debug-Clang" , "description": "Clang/LLVM for x64 (Debug)", "inherits": [ "base", "x64", "Debug", "Clang" ] }, 175 | { "name": "x64-Release-Clang" , "description": "Clang/LLVM for x64 (Release)", "inherits": [ "base", "x64", "Release", "Clang" ] }, 176 | { "name": "x86-Debug-Clang" , "description": "Clang/LLVM for x86 (Debug)", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86" ] }, 177 | { "name": "x86-Release-Clang" , "description": "Clang/LLVM for x86 (Release)", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86" ] }, 178 | { "name": "arm64-Debug-Clang" , "description": "Clang/LLVM for AArch64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "Clang", "Clang-AArch64" ] }, 179 | { "name": "arm64-Release-Clang", "description": "Clang/LLVM for AArch64 (Release)", "inherits": [ "base", "ARM64", "Release", "Clang", "Clang-AArch64" ] }, 180 | 181 | { "name": "x64-Debug-UWP-Clang" , "description": "Clang/LLVM for x64 (Debug) for UWP", "inherits": [ "base", "x64", "Debug", "Clang", "UWP" ] }, 182 | { "name": "x64-Release-UWP-Clang" , "description": "Clang/LLVM for x64 (Release) for UWP", "inherits": [ "base", "x64", "Release", "Clang", "UWP" ] }, 183 | { "name": "x86-Debug-UWP-Clang" , "description": "Clang/LLVM for x86 (Debug) for UWP", "inherits": [ "base", "x86", "Debug", "Clang", "Clang-X86", "UWP" ] }, 184 | { "name": "x86-Release-UWP-Clang" , "description": "Clang/LLVM for x86 (Release) for UWP", "inherits": [ "base", "x86", "Release", "Clang", "Clang-X86", "UWP" ] }, 185 | { "name": "arm64-Debug-UWP-Clang" , "description": "Clang/LLVM for AArch64 (Debug) for UWP", "inherits": [ "base", "ARM64", "Debug", "Clang", "Clang-AArch64", "UWP" ] }, 186 | { "name": "arm64-Release-UWP-Clang", "description": "Clang/LLVM for AArch64 (Release) for UWP", "inherits": [ "base", "ARM64", "Release", "Clang", "Clang-AArch64", "UWP" ] }, 187 | 188 | { "name": "x64-Debug-ICC" , "description": "Intel Classic Compiler (Debug)", "inherits": [ "base", "x64", "Debug", "Intel" ] }, 189 | { "name": "x64-Release-ICC" , "description": "Intel Classic Compiler (Release)", "inherits": [ "base", "x64", "Release", "Intel" ] }, 190 | { "name": "x86-Debug-ICC" , "description": "Intel Classic Compiler (Debug)", "inherits": [ "base", "x86", "Debug", "Intel" ] }, 191 | { "name": "x86-Release-ICC" , "description": "Intel Classic Compiler (Release)", "inherits": [ "base", "x86", "Release", "Intel" ] }, 192 | 193 | { "name": "x64-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug)", "inherits": [ "base", "x64", "Debug", "IntelLLVM" ] }, 194 | { "name": "x64-Release-ICX" , "description": "Intel oneAPI Compiler (Release)", "inherits": [ "base", "x64", "Release", "IntelLLVM" ] }, 195 | { "name": "x86-Debug-ICX" , "description": "Intel oneAPI Compiler (Debug)", "inherits": [ "base", "x86", "Debug", "IntelLLVM" ] }, 196 | { "name": "x86-Release-ICX" , "description": "Intel oneAPI Compiler (Release)", "inherits": [ "base", "x86", "Release", "IntelLLVM" ] }, 197 | 198 | { "name": "x64-Debug-MinGW" , "description": "MinG-W64 (Debug)", "inherits": [ "base", "x64", "Debug", "GNUC" ], "environment": { "PATH": "$penv{PATH};c:/mingw64/bin" } }, 199 | { "name": "x64-Release-MinGW", "description": "MinG-W64 (Release)", "inherits": [ "base", "x64", "Release", "GNUC" ], "environment": { "PATH": "$penv{PATH};c:/mingw64/bin" } }, 200 | { "name": "x86-Debug-MinGW" , "description": "MinG-W32 (Debug)", "inherits": [ "base", "x86", "Debug", "GNUC" ], "environment": { "PATH": "$penv{PATH};c:/mingw32/bin" } }, 201 | { "name": "x86-Release-MinGW", "description": "MinG-W32 (Release)", "inherits": [ "base", "x86", "Release", "GNUC" ], "environment": { "PATH": "$penv{PATH};c:/mingw32/bin" } }, 202 | 203 | { "name": "x64-Debug-WSL" , "description": "WSL x64 (Debug) for Windows 11", "inherits": [ "base", "x64", "Debug" ] }, 204 | { "name": "x64-Release-WSL" , "description": "WSL x64 (Release) for Windows 11", "inherits": [ "base", "x64", "Release" ] }, 205 | { "name": "arm64-Debug-WSL" , "description": "WSL AArch64 (Debug) for Windows 11", "inherits": [ "base", "ARM64", "Debug" ] }, 206 | { "name": "arm64-Release-WSL", "description": "WSL AArch64 (Release) for Windows 11", "inherits": [ "base", "ARM64", "Release" ] }, 207 | 208 | { "name": "x64-Debug-Linux" , "description": "Linux x64 (Debug)", "inherits": [ "base", "x64", "Debug", "NoTests" ] }, 209 | { "name": "x64-Release-Linux" , "description": "Linux x64 (Release)", "inherits": [ "base", "x64", "Release", "NoTests" ] }, 210 | { "name": "arm64-Debug-Linux" , "description": "Linux AArch64 (Debug)", "inherits": [ "base", "ARM64", "Debug", "NoTests" ] }, 211 | { "name": "arm64-Release-Linux", "description": "Linux AArch64 (Release)", "inherits": [ "base", "ARM64", "Release", "NoTests" ] } 212 | ], 213 | "testPresets": [ 214 | { "name": "x64-Debug" , "configurePreset": "x64-Debug" }, 215 | { "name": "x64-Release" , "configurePreset": "x64-Release" }, 216 | { "name": "x86-Debug" , "configurePreset": "x86-Debug" }, 217 | { "name": "x86-Release" , "configurePreset": "x86-Release" }, 218 | 219 | { "name": "arm64-Debug" , "configurePreset": "arm64-Debug" }, 220 | { "name": "arm64-Release" , "configurePreset": "arm64-Release" }, 221 | { "name": "arm64ec-Debug" , "configurePreset": "arm64ec-Debug" }, 222 | { "name": "arm64ec-Release", "configurePreset": "arm64ec-Release" } 223 | ] 224 | } 225 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | - Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support) 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) Microsoft Corporation. 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DirectX Headers 2 | 3 | This repository hosts the official Direct3D 12 headers. These headers are made available under the MIT license rather than the traditional Windows SDK license. 4 | 5 | Additionally, this repository hosts several helpers for using these headers. 6 | 7 | Make sure that you visit the [DirectX Landing Page](https://devblogs.microsoft.com/directx/landing-page/) for more resources for DirectX developers. 8 | 9 | ## Directory Structure 10 | 11 | * `/`: Build files are available here for quick integration. CMake is provided, and can be referenced either via `subdirectory()` or after installation to a system location. Meson is also available for inclusion as a subproject/wrap. 12 | * `/include/directx`: These files are the core headers for using D3D12, plus d3dx12.h, which is a helper and does not cross the boundaries of the D3D12 API. 13 | * `/include/wsl`: These files are provided as a shim to be able to include the D3D12 headers from a Linux build environment, without requiring the rest of the Windows SDK. 14 | * `/include/dxguids`: This header allows an application to use `uuidof()` consistently between Windows and WSL, instead of `__uuidof()`. 15 | * `/src/dxguids.cpp`: This cpp file can be used as a replacement for linking against `dxguid.lib` on Windows, and as a convenient translation unit to define GUIDs without multiple definitions for WSL. 16 | * `/test`: Simple CMake/Meson projects for validating the headers can be included in a given environment 17 | 18 | ## Use on Windows 19 | 20 | Note that these headers may conflict with the headers from the Windows SDK, depending on include ordering. These headers should be added to the include directory list before the SDK, and should be included before other graphics headers (e.g. `d3d11.h`) from the Windows SDK. Otherwise, the corresponding header from the Windows SDK may be included first, and will define the include guards which prevents these headers from being used. 21 | 22 | ## Use on WSL 23 | 24 | Note: WSL support is not intended for general purpose application development. At this time, the only recommended usage is for frameworks wishing to provide hardware acceleration for a Linux graphics/compute API in a WSL2 virtualization environment. 25 | 26 | Note: WSL support is only available for 64-bit binaries. 27 | 28 | The headers in the `/include/wsl` directory provide alternative definitions to macros and typedefs normally found in the Windows SDK. For the most part, they should be straightforward, but there are a couple to call attention to: 29 | 30 | |Type|Reason| 31 | |---|---| 32 | |`LONG`/`ULONG`|On 64-bit Windows, a `long` is 4 bytes, but on Linux it is typically 8 bytes. The D3D12 ABI for WSL uses `long` and therefore these should be 8 bytes.| 33 | |`WCHAR`/`WCSTR`|On Windows, a `wchar_t` is 2 bytes, but on Linux it is typically 4 bytes. The D3D12 ABI for WSL uses the native 4-byte `wchar_t`, to enable applications and the runtime to use the system C library to perform string manipulation.| 34 | 35 | Additionally, APIs taking `HANDLE` (`void*`) for Win32 types should instead use `reinterpret_cast(fd)` for an appropriate type of file descriptor. For `ID3D12Fence::SetEventOnCompletion` this should be an `eventfd`, and for shared resources will be an opaque fd. 36 | 37 | ## Ways to consume 38 | 39 | There are various ways to consume the headers in this project: 40 | 41 | * Manually: Just copy the headers somewhere and point your project at them. 42 | * CMake subproject: Add this entire project as a subdirectory of your larger project, e.g. as a git submodule, and `add_subdirectory` into it. Use the resulting `DirectX-Headers` and/or `DirectX-Guids` targets as a link dependency 43 | * Installed CMake: After building/installing this project, it can be found through CMake's `find_package` functionality and will expose the same `DirectX-Headers` and `DirectX-Guids` targets. 44 | * FetchContent CMake (3.11+): Fetch this library using Git and easily add it to your project. 45 | * Meson subproject/wrap: Add this entire project as a subproject of your larger project, and use `subproject` or `dependency` to consume it. 46 | * Pkg-config: Use Meson to build this project, and the resulting installed package can be found via pkg-config. 47 | * vcpkg: A vcpkg port has [been added](https://github.com/microsoft/vcpkg/tree/master/ports/directx-headers). 48 | * NuGet: Download the [DirectX 12 Agility SDK](https://devblogs.microsoft.com/directx/announcing-dx12agility/) from [NuGet.org](https://www.nuget.org/packages/Microsoft.Direct3D.D3D12) 49 | * For more info about the Agility SDK, see the [getting started guide](https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/) 50 | 51 | Contributions for new mechanisms are welcome. 52 | 53 | ## Contributing 54 | 55 | This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. 56 | 57 | When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. 58 | 59 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 60 | 61 | ## Trademarks 62 | 63 | This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party's policies. 64 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd). 40 | 41 | 42 | -------------------------------------------------------------------------------- /cmake/DirectX-Headers.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | libdir=@DIRECTX_LIBDIR_FOR_PKG_CONFIG@ 3 | includedir=@DIRECTX_INCLUDEDIR_FOR_PKG_CONFIG@ 4 | 5 | Name: @PROJECT_NAME@ 6 | Description: Headers for using D3D12 7 | URL: https://github.com/microsoft/DirectX-Headers 8 | Version: @PROJECT_VERSION@ 9 | Cflags: -I${includedir} 10 | Libs: -lDirectX-Headers -lDirectX-Guids 11 | -------------------------------------------------------------------------------- /cmake/JoinPaths.cmake: -------------------------------------------------------------------------------- 1 | # This module provides function for joining paths 2 | # known from most languages 3 | # 4 | # SPDX-License-Identifier: (MIT OR CC0-1.0) 5 | # Copyright 2020 Jan Tojnar 6 | # https://github.com/jtojnar/cmake-snips 7 | # 8 | # Modelled after Python’s os.path.join 9 | # https://docs.python.org/3.7/library/os.path.html#os.path.join 10 | # Windows not supported 11 | function(join_paths joined_path first_path_segment) 12 | set(temp_path "${first_path_segment}") 13 | foreach(current_segment IN LISTS ARGN) 14 | if(NOT ("${current_segment}" STREQUAL "")) 15 | if(IS_ABSOLUTE "${current_segment}") 16 | set(temp_path "${current_segment}") 17 | else() 18 | set(temp_path "${temp_path}/${current_segment}") 19 | endif() 20 | endif() 21 | endforeach() 22 | set(${joined_path} "${temp_path}" PARENT_SCOPE) 23 | endfunction() 24 | -------------------------------------------------------------------------------- /cmake/directx-headers-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/directx-headers-targets.cmake") 4 | check_required_components("@PROJECT_NAME@") -------------------------------------------------------------------------------- /googletest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | include(FetchContent) 4 | 5 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 6 | FetchContent_Declare( 7 | googletest 8 | GIT_REPOSITORY https://github.com/google/googletest.git 9 | GIT_TAG main # Live at head 10 | ) 11 | FetchContent_MakeAvailable(googletest) 12 | 13 | list(APPEND dxlibs "") 14 | if(EXISTS "/usr/lib/wsl/lib/") 15 | find_library(libd3d12 d3d12 HINTS /usr/lib/wsl/lib) 16 | list(APPEND dxlibs ${libd3d12}) 17 | else() 18 | # Fallback to default: let CMake look for libs 19 | list(APPEND dxlibs d3d12) 20 | endif() 21 | 22 | project(DirectX-Headers-GoogleTest-Suite 23 | DESCRIPTION "DirectX-Header tests using GooleTest" 24 | HOMEPAGE_URL "https://github.com/microsoft/DirectX-Headers/" 25 | LANGUAGES CXX) 26 | 27 | set(CMAKE_CXX_STANDARD 17) 28 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 29 | set(CMAKE_CXX_EXTENSIONS OFF) 30 | 31 | add_executable(Feature-Support-Test feature_support_test.cpp) 32 | target_link_libraries(Feature-Support-Test DirectX-Headers DirectX-Guids ${dxlibs} gtest_main) 33 | add_test(Feature-Support-Test Feature-Support-Test) 34 | 35 | if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) 36 | target_compile_options(Feature-Support-Test PRIVATE -Wno-unused-variable) 37 | endif() 38 | 39 | if(WIN32) 40 | target_compile_definitions(Feature-Support-Test PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0A00) 41 | 42 | if(WINDOWS_STORE) 43 | target_compile_definitions(Feature-Support-Test PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_APP) 44 | endif() 45 | endif() 46 | -------------------------------------------------------------------------------- /googletest/meson.build: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | gtest = cpp.find_library('gtest', required: false) 5 | gtest_main = cpp.find_library('gtest_main', required: false) 6 | 7 | if gtest.found() and gtest_main.found() 8 | feature_support_test = executable('Feature-Support-Test', 'feature_support_test.cpp', 9 | dependencies : [gtest, gtest_main, dep_dxheaders, d3d12_lib, dxcore_lib], 10 | cpp_args : test_compile_opts, 11 | c_args : test_compile_opts) 12 | test('Feature-Support-Test', feature_support_test) 13 | endif 14 | -------------------------------------------------------------------------------- /include/directx/d3d12compatibility.idl: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------- 2 | * 3 | * Copyright (c) Microsoft Corporation 4 | * Licensed under the MIT license 5 | * 6 | *-------------------------------------------------------------------------------------*/ 7 | import "oaidl.idl"; 8 | import "ocidl.idl"; 9 | 10 | import "d3d11on12.idl"; 11 | 12 | cpp_quote("#include ") 13 | 14 | #pragma region Desktop Family 15 | cpp_quote("#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES)") 16 | 17 | typedef enum D3D12_COMPATIBILITY_SHARED_FLAGS 18 | { 19 | D3D12_COMPATIBILITY_SHARED_FLAG_NONE = 0, 20 | D3D12_COMPATIBILITY_SHARED_FLAG_NON_NT_HANDLE = 0x1, 21 | D3D12_COMPATIBILITY_SHARED_FLAG_KEYED_MUTEX = 0x2, 22 | D3D12_COMPATIBILITY_SHARED_FLAG_9_ON_12 = 0x4, 23 | 24 | } D3D12_COMPATIBILITY_SHARED_FLAGS; 25 | cpp_quote( "DEFINE_ENUM_FLAG_OPERATORS( D3D12_COMPATIBILITY_SHARED_FLAGS )" ) 26 | 27 | typedef enum D3D12_REFLECT_SHARED_PROPERTY 28 | { 29 | D3D12_REFLECT_SHARED_PROPERTY_D3D11_RESOURCE_FLAGS, // D3D11_RESOURCE_FLAGS 30 | D3D12_REFELCT_SHARED_PROPERTY_COMPATIBILITY_SHARED_FLAGS, // D3D12_COMPATIBILITY_SHARED_FLAGS 31 | D3D12_REFLECT_SHARED_PROPERTY_NON_NT_SHARED_HANDLE, // HANDLE 32 | } D3D12_REFLECT_SHARED_PROPERTY; 33 | 34 | [ uuid( 8f1c0e3c-fae3-4a82-b098-bfe1708207ff ), object, local, pointer_default( unique ) ] 35 | interface ID3D12CompatibilityDevice 36 | : IUnknown 37 | { 38 | HRESULT CreateSharedResource( 39 | [annotation("_In_")] const D3D12_HEAP_PROPERTIES* pHeapProperties, 40 | D3D12_HEAP_FLAGS HeapFlags, 41 | [annotation("_In_")] const D3D12_RESOURCE_DESC* pDesc, 42 | D3D12_RESOURCE_STATES InitialResourceState, 43 | [annotation("_In_opt_")] const D3D12_CLEAR_VALUE* pOptimizedClearValue, 44 | [annotation("_In_opt_")] const D3D11_RESOURCE_FLAGS* pFlags11, 45 | D3D12_COMPATIBILITY_SHARED_FLAGS CompatibilityFlags, 46 | [annotation("_In_opt_")] ID3D12LifetimeTracker* pLifetimeTracker, 47 | [annotation("_In_opt_")] ID3D12SwapChainAssistant* pOwningSwapchain, 48 | REFIID riid, 49 | [out, iid_is(riid), annotation("_COM_Outptr_opt_")] void** ppResource); 50 | 51 | HRESULT CreateSharedHeap( 52 | [annotation("_In_")] const D3D12_HEAP_DESC* pHeapDesc, 53 | D3D12_COMPATIBILITY_SHARED_FLAGS CompatibilityFlags, 54 | REFIID riid, 55 | [out, iid_is(riid), annotation("_COM_Outptr_opt_")] void** ppHeap); 56 | 57 | HRESULT ReflectSharedProperties( 58 | [annotation("_In_")] ID3D12Object* pHeapOrResource, 59 | D3D12_REFLECT_SHARED_PROPERTY ReflectType, 60 | [annotation("_Out_writes_bytes_(DataSize)")] void* pData, 61 | UINT DataSize); 62 | } 63 | 64 | [uuid(edbf5678-2960-4e81-8429-99d4b2630c4e), object, local, pointer_default(unique)] 65 | interface D3D11On12CreatorID : IUnknown { }; 66 | 67 | [uuid(fffcbb7f-15d3-42a2-841e-9d8d32f37ddd), object, local, pointer_default(unique)] 68 | interface D3D9On12CreatorID : IUnknown { }; 69 | 70 | [uuid(6bb3cd34-0d19-45ab-97ed-d720ba3dfc80), object, local, pointer_default(unique)] 71 | interface OpenGLOn12CreatorID : IUnknown { }; 72 | 73 | [uuid(3f76bb74-91b5-4a88-b126-20ca0331cd60), object, local, pointer_default(unique)] 74 | interface OpenCLOn12CreatorID : IUnknown { }; 75 | 76 | [uuid(bc806e01-3052-406c-a3e8-9fc07f048f98), object, local, pointer_default(unique)] 77 | interface VulkanOn12CreatorID : IUnknown { }; 78 | 79 | [uuid(cb7490ac-8a0f-44ec-9b7b-6f4cafe8e9ab), object, local, pointer_default(unique)] 80 | interface DirectMLTensorFlowCreatorID : IUnknown { }; 81 | 82 | [uuid(af029192-fba1-4b05-9116-235e06560354), object, local, pointer_default(unique)] 83 | interface DirectMLPyTorchCreatorID : IUnknown { }; 84 | 85 | [uuid(fdf01a76-1e11-450f-902b-74f04ea08094), object, local, pointer_default(unique)] 86 | interface DirectMLWebNNCreatorID : IUnknown { }; 87 | 88 | 89 | cpp_quote("#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_GAMES) */") 90 | #pragma endregion 91 | 92 | cpp_quote( "DEFINE_GUID(IID_ID3D12CompatibilityDevice,0x8f1c0e3c,0xfae3,0x4a82,0xb0,0x98,0xbf,0xe1,0x70,0x82,0x07,0xff);" ) 93 | cpp_quote( "DEFINE_GUID(IID_D3D11On12CreatorID,0xedbf5678,0x2960,0x4e81,0x84,0x29,0x99,0xd4,0xb2,0x63,0x0c,0x4e);" ) 94 | cpp_quote( "DEFINE_GUID(IID_D3D9On12CreatorID,0xfffcbb7f,0x15d3,0x42a2,0x84,0x1e,0x9d,0x8d,0x32,0xf3,0x7d,0xdd);" ) 95 | cpp_quote( "DEFINE_GUID(IID_OpenGLOn12CreatorID,0x6bb3cd34,0x0d19,0x45ab,0x97,0xed,0xd7,0x20,0xba,0x3d,0xfc,0x80);" ) 96 | cpp_quote( "DEFINE_GUID(IID_OpenCLOn12CreatorID,0x3f76bb74,0x91b5,0x4a88,0xb1,0x26,0x20,0xca,0x03,0x31,0xcd,0x60);" ) 97 | cpp_quote( "DEFINE_GUID(IID_VulkanOn12CreatorID,0xbc806e01,0x3052,0x406c,0xa3,0xe8,0x9f,0xc0,0x7f,0x04,0x8f,0x98);" ) 98 | cpp_quote( "DEFINE_GUID(IID_DirectMLTensorFlowCreatorID,0xcb7490ac,0x8a0f,0x44ec,0x9b,0x7b,0x6f,0x4c,0xaf,0xe8,0xe9,0xab);" ) 99 | cpp_quote( "DEFINE_GUID(IID_DirectMLPyTorchCreatorID,0xaf029192,0xfba1,0x4b05,0x91,0x16,0x23,0x5e,0x06,0x56,0x03,0x54);" ) 100 | cpp_quote( "DEFINE_GUID(IID_DirectMLWebNNCreatorID,0xfdf01a76,0x1e11,0x450f,0x90,0x2b,0x74,0xf0,0x4e,0xa0,0x80,0x94);" ) 101 | -------------------------------------------------------------------------------- /include/directx/d3dx12.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | 8 | #ifndef __D3DX12_H__ 9 | #define __D3DX12_H__ 10 | 11 | #include "d3d12.h" 12 | 13 | #if defined( __cplusplus ) 14 | 15 | #include "d3dx12_barriers.h" 16 | #include "d3dx12_core.h" 17 | #include "d3dx12_default.h" 18 | #include "d3dx12_pipeline_state_stream.h" 19 | #include "d3dx12_render_pass.h" 20 | #include "d3dx12_resource_helpers.h" 21 | #include "d3dx12_root_signature.h" 22 | #include "d3dx12_property_format_table.h" 23 | 24 | #ifndef D3DX12_NO_STATE_OBJECT_HELPERS 25 | #include "d3dx12_state_object.h" 26 | #endif // !D3DX12_NO_STATE_OBJECT_HELPERS 27 | 28 | #ifndef D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS 29 | #include "d3dx12_check_feature_support.h" 30 | #endif // !D3DX12_NO_CHECK_FEATURE_SUPPORT_CLASS 31 | 32 | #endif // defined( __cplusplus ) 33 | 34 | #endif //__D3DX12_H__ 35 | 36 | -------------------------------------------------------------------------------- /include/directx/d3dx12_barriers.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | 8 | #ifndef __D3DX12_BARRIERS_H__ 9 | #define __D3DX12_BARRIERS_H__ 10 | 11 | #if defined( __cplusplus ) 12 | 13 | #include "d3d12.h" 14 | 15 | //------------------------------------------------------------------------------------------------ 16 | struct CD3DX12_RESOURCE_BARRIER : public D3D12_RESOURCE_BARRIER 17 | { 18 | CD3DX12_RESOURCE_BARRIER() = default; 19 | explicit CD3DX12_RESOURCE_BARRIER(const D3D12_RESOURCE_BARRIER &o) noexcept : 20 | D3D12_RESOURCE_BARRIER(o) 21 | {} 22 | static inline CD3DX12_RESOURCE_BARRIER Transition( 23 | _In_ ID3D12Resource* pResource, 24 | D3D12_RESOURCE_STATES stateBefore, 25 | D3D12_RESOURCE_STATES stateAfter, 26 | UINT subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, 27 | D3D12_RESOURCE_BARRIER_FLAGS flags = D3D12_RESOURCE_BARRIER_FLAG_NONE) noexcept 28 | { 29 | CD3DX12_RESOURCE_BARRIER result = {}; 30 | D3D12_RESOURCE_BARRIER &barrier = result; 31 | result.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; 32 | result.Flags = flags; 33 | barrier.Transition.pResource = pResource; 34 | barrier.Transition.StateBefore = stateBefore; 35 | barrier.Transition.StateAfter = stateAfter; 36 | barrier.Transition.Subresource = subresource; 37 | return result; 38 | } 39 | static inline CD3DX12_RESOURCE_BARRIER Aliasing( 40 | _In_opt_ ID3D12Resource* pResourceBefore, 41 | _In_opt_ ID3D12Resource* pResourceAfter) noexcept 42 | { 43 | CD3DX12_RESOURCE_BARRIER result = {}; 44 | D3D12_RESOURCE_BARRIER &barrier = result; 45 | result.Type = D3D12_RESOURCE_BARRIER_TYPE_ALIASING; 46 | barrier.Aliasing.pResourceBefore = pResourceBefore; 47 | barrier.Aliasing.pResourceAfter = pResourceAfter; 48 | return result; 49 | } 50 | static inline CD3DX12_RESOURCE_BARRIER UAV( 51 | _In_opt_ ID3D12Resource* pResource) noexcept 52 | { 53 | CD3DX12_RESOURCE_BARRIER result = {}; 54 | D3D12_RESOURCE_BARRIER &barrier = result; 55 | result.Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; 56 | barrier.UAV.pResource = pResource; 57 | return result; 58 | } 59 | }; 60 | 61 | #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 608) 62 | 63 | //================================================================================================ 64 | // D3DX12 Enhanced Barrier Helpers 65 | //================================================================================================ 66 | 67 | class CD3DX12_BARRIER_SUBRESOURCE_RANGE : public D3D12_BARRIER_SUBRESOURCE_RANGE 68 | { 69 | public: 70 | CD3DX12_BARRIER_SUBRESOURCE_RANGE() = default; 71 | CD3DX12_BARRIER_SUBRESOURCE_RANGE(const D3D12_BARRIER_SUBRESOURCE_RANGE &o) noexcept : 72 | D3D12_BARRIER_SUBRESOURCE_RANGE(o) 73 | {} 74 | explicit CD3DX12_BARRIER_SUBRESOURCE_RANGE(UINT Subresource) noexcept : 75 | D3D12_BARRIER_SUBRESOURCE_RANGE{ Subresource, 0, 0, 0, 0, 0 } 76 | {} 77 | CD3DX12_BARRIER_SUBRESOURCE_RANGE( 78 | UINT firstMipLevel, 79 | UINT numMips, 80 | UINT firstArraySlice, 81 | UINT numArraySlices, 82 | UINT firstPlane = 0, 83 | UINT numPlanes = 1) noexcept : 84 | D3D12_BARRIER_SUBRESOURCE_RANGE 85 | { 86 | firstMipLevel, 87 | numMips, 88 | firstArraySlice, 89 | numArraySlices, 90 | firstPlane, 91 | numPlanes 92 | } 93 | {} 94 | }; 95 | 96 | class CD3DX12_GLOBAL_BARRIER : public D3D12_GLOBAL_BARRIER 97 | { 98 | public: 99 | CD3DX12_GLOBAL_BARRIER() = default; 100 | CD3DX12_GLOBAL_BARRIER(const D3D12_GLOBAL_BARRIER &o) noexcept : D3D12_GLOBAL_BARRIER(o){} 101 | CD3DX12_GLOBAL_BARRIER( 102 | D3D12_BARRIER_SYNC syncBefore, 103 | D3D12_BARRIER_SYNC syncAfter, 104 | D3D12_BARRIER_ACCESS accessBefore, 105 | D3D12_BARRIER_ACCESS accessAfter) noexcept : D3D12_GLOBAL_BARRIER { 106 | syncBefore, 107 | syncAfter, 108 | accessBefore, 109 | accessAfter 110 | } 111 | {} 112 | }; 113 | 114 | class CD3DX12_BUFFER_BARRIER : public D3D12_BUFFER_BARRIER 115 | { 116 | public: 117 | CD3DX12_BUFFER_BARRIER() = default; 118 | CD3DX12_BUFFER_BARRIER(const D3D12_BUFFER_BARRIER &o) noexcept : D3D12_BUFFER_BARRIER(o){} 119 | CD3DX12_BUFFER_BARRIER( 120 | D3D12_BARRIER_SYNC syncBefore, 121 | D3D12_BARRIER_SYNC syncAfter, 122 | D3D12_BARRIER_ACCESS accessBefore, 123 | D3D12_BARRIER_ACCESS accessAfter, 124 | ID3D12Resource *pRes) noexcept : D3D12_BUFFER_BARRIER { 125 | syncBefore, 126 | syncAfter, 127 | accessBefore, 128 | accessAfter, 129 | pRes, 130 | 0, ULLONG_MAX 131 | } 132 | {} 133 | }; 134 | 135 | class CD3DX12_TEXTURE_BARRIER : public D3D12_TEXTURE_BARRIER 136 | { 137 | public: 138 | CD3DX12_TEXTURE_BARRIER() = default; 139 | CD3DX12_TEXTURE_BARRIER(const D3D12_TEXTURE_BARRIER &o) noexcept : D3D12_TEXTURE_BARRIER(o){} 140 | CD3DX12_TEXTURE_BARRIER( 141 | D3D12_BARRIER_SYNC syncBefore, 142 | D3D12_BARRIER_SYNC syncAfter, 143 | D3D12_BARRIER_ACCESS accessBefore, 144 | D3D12_BARRIER_ACCESS accessAfter, 145 | D3D12_BARRIER_LAYOUT layoutBefore, 146 | D3D12_BARRIER_LAYOUT layoutAfter, 147 | ID3D12Resource *pRes, 148 | const D3D12_BARRIER_SUBRESOURCE_RANGE &subresources, 149 | D3D12_TEXTURE_BARRIER_FLAGS flag = D3D12_TEXTURE_BARRIER_FLAG_NONE) noexcept : D3D12_TEXTURE_BARRIER { 150 | syncBefore, 151 | syncAfter, 152 | accessBefore, 153 | accessAfter, 154 | layoutBefore, 155 | layoutAfter, 156 | pRes, 157 | subresources, 158 | flag 159 | } 160 | {} 161 | }; 162 | 163 | class CD3DX12_BARRIER_GROUP : public D3D12_BARRIER_GROUP 164 | { 165 | public: 166 | CD3DX12_BARRIER_GROUP() = default; 167 | CD3DX12_BARRIER_GROUP(const D3D12_BARRIER_GROUP &o) noexcept : D3D12_BARRIER_GROUP(o){} 168 | CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_BUFFER_BARRIER *pBarriers) noexcept 169 | { 170 | Type = D3D12_BARRIER_TYPE_BUFFER; 171 | NumBarriers = numBarriers; 172 | pBufferBarriers = pBarriers; 173 | } 174 | CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_TEXTURE_BARRIER *pBarriers) noexcept 175 | { 176 | Type = D3D12_BARRIER_TYPE_TEXTURE; 177 | NumBarriers = numBarriers; 178 | pTextureBarriers = pBarriers; 179 | } 180 | CD3DX12_BARRIER_GROUP(UINT32 numBarriers, const D3D12_GLOBAL_BARRIER *pBarriers) noexcept 181 | { 182 | Type = D3D12_BARRIER_TYPE_GLOBAL; 183 | NumBarriers = numBarriers; 184 | pGlobalBarriers = pBarriers; 185 | } 186 | }; 187 | #endif // D3D12_SDK_VERSION >= 608 188 | 189 | 190 | #endif // defined( __cplusplus ) 191 | 192 | #endif // __D3DX12_BARRIERS_H__ 193 | -------------------------------------------------------------------------------- /include/directx/d3dx12_default.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | 8 | #pragma once 9 | 10 | struct CD3DX12_DEFAULT {}; 11 | extern const DECLSPEC_SELECTANY CD3DX12_DEFAULT D3D12_DEFAULT; 12 | 13 | -------------------------------------------------------------------------------- /include/directx/d3dx12_property_format_table.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | #ifndef __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__ 8 | #define __D3D12_PROPERTY_LAYOUT_FORMAT_TABLE_H__ 9 | #include "d3d12.h" 10 | #define MAP_ALIGN_REQUIREMENT 16 // Map is required to return 16-byte aligned addresses 11 | 12 | struct D3D12_PROPERTY_LAYOUT_FORMAT_TABLE 13 | { 14 | public: 15 | // ---------------------------------------------------------------------------- 16 | // Information describing everything about a D3D Resource Format 17 | // ---------------------------------------------------------------------------- 18 | typedef struct FORMAT_DETAIL 19 | { 20 | DXGI_FORMAT DXGIFormat; 21 | DXGI_FORMAT ParentFormat; 22 | const DXGI_FORMAT* pDefaultFormatCastSet; // This is dependent on FL/driver version, but is here to save a lot of space 23 | UINT8 BitsPerComponent[4]; // only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE 24 | UINT8 BitsPerUnit; 25 | BYTE SRGBFormat : 1; 26 | UINT WidthAlignment : 4; // number of texels to align to in a mip level. 27 | UINT HeightAlignment : 4; // Top level dimensions must be a multiple of these 28 | UINT DepthAlignment : 1; // values. 29 | D3D_FORMAT_LAYOUT Layout : 1; 30 | D3D_FORMAT_TYPE_LEVEL TypeLevel : 2; 31 | D3D_FORMAT_COMPONENT_NAME ComponentName0 : 3; // RED ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE 32 | D3D_FORMAT_COMPONENT_NAME ComponentName1 : 3; // GREEN ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE 33 | D3D_FORMAT_COMPONENT_NAME ComponentName2 : 3; // BLUE ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE 34 | D3D_FORMAT_COMPONENT_NAME ComponentName3 : 3; // ALPHA ... only used for D3DFTL_PARTIAL_TYPE or FULL_TYPE 35 | D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation0 : 3; // only used for D3DFTL_FULL_TYPE 36 | D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation1 : 3; // only used for D3DFTL_FULL_TYPE 37 | D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation2 : 3; // only used for D3DFTL_FULL_TYPE 38 | D3D_FORMAT_COMPONENT_INTERPRETATION ComponentInterpretation3 : 3; // only used for D3DFTL_FULL_TYPE 39 | bool bDX9VertexOrIndexFormat : 1; 40 | bool bDX9TextureFormat : 1; 41 | bool bFloatNormFormat : 1; 42 | bool bPlanar : 1; 43 | bool bYUV : 1; 44 | bool bDependantFormatCastSet : 1; // This indicates that the format cast set is dependent on FL/driver version 45 | bool bInternal : 1; 46 | } FORMAT_DETAIL; 47 | 48 | private: 49 | static const FORMAT_DETAIL s_FormatDetail[]; 50 | static const UINT s_NumFormats; 51 | static const LPCSTR s_FormatNames[]; // separate from above structure so it can be compiled out of runtime. 52 | public: 53 | static UINT GetNumFormats(); 54 | static const FORMAT_DETAIL* GetFormatTable(); 55 | static D3D_FEATURE_LEVEL GetHighestDefinedFeatureLevel(); 56 | 57 | static DXGI_FORMAT GetFormat (SIZE_T Index); 58 | static bool FormatExists (DXGI_FORMAT Format); 59 | static bool FormatExistsInHeader (DXGI_FORMAT Format, bool bExternalHeader = true); 60 | static UINT GetByteAlignment (DXGI_FORMAT Format); 61 | static bool IsBlockCompressFormat (DXGI_FORMAT Format); 62 | static LPCSTR GetName (DXGI_FORMAT Format, bool bHideInternalFormats = true); 63 | static bool IsSRGBFormat (DXGI_FORMAT Format); 64 | static UINT GetBitsPerStencil (DXGI_FORMAT Format); 65 | static UINT GetBitsPerDepth (DXGI_FORMAT Format); 66 | static void GetFormatReturnTypes (DXGI_FORMAT Format, D3D_FORMAT_COMPONENT_INTERPRETATION* pInterpretations); // return array of 4 components 67 | static UINT GetNumComponentsInFormat(DXGI_FORMAT Format); 68 | static UINT GetMinNumComponentsInFormats(DXGI_FORMAT FormatA, DXGI_FORMAT FormatB); 69 | 70 | // Converts the sequential component index (range from 0 to GetNumComponentsInFormat()) to 71 | // the absolute component index (range 0 to 3). 72 | static UINT Sequential2AbsoluteComponentIndex (DXGI_FORMAT Format, UINT SequentialComponentIndex); 73 | static bool CanBeCastEvenFullyTyped (DXGI_FORMAT Format, D3D_FEATURE_LEVEL fl); 74 | static UINT8 GetAddressingBitsPerAlignedSize (DXGI_FORMAT Format); 75 | static DXGI_FORMAT GetParentFormat (DXGI_FORMAT Format); 76 | static const DXGI_FORMAT* GetFormatCastSet (DXGI_FORMAT Format); 77 | static D3D_FORMAT_LAYOUT GetLayout (DXGI_FORMAT Format); 78 | static D3D_FORMAT_TYPE_LEVEL GetTypeLevel (DXGI_FORMAT Format); 79 | static UINT GetBitsPerUnit (DXGI_FORMAT Format); 80 | static UINT GetBitsPerUnitThrow (DXGI_FORMAT Format); 81 | static UINT GetBitsPerElement (DXGI_FORMAT Format); // Legacy function used to support D3D10on9 only. Do not use. 82 | static UINT GetWidthAlignment (DXGI_FORMAT Format); 83 | static UINT GetHeightAlignment (DXGI_FORMAT Format); 84 | static UINT GetDepthAlignment (DXGI_FORMAT Format); 85 | static BOOL Planar (DXGI_FORMAT Format); 86 | static BOOL NonOpaquePlanar (DXGI_FORMAT Format); 87 | static BOOL YUV (DXGI_FORMAT Format); 88 | static BOOL Opaque (DXGI_FORMAT Format); 89 | static bool FamilySupportsStencil (DXGI_FORMAT Format); 90 | static UINT NonOpaquePlaneCount (DXGI_FORMAT Format); 91 | static BOOL DX9VertexOrIndexFormat (DXGI_FORMAT Format); 92 | static BOOL DX9TextureFormat (DXGI_FORMAT Format); 93 | static BOOL FloatNormTextureFormat (DXGI_FORMAT Format); 94 | static bool DepthOnlyFormat (DXGI_FORMAT format); 95 | static UINT8 GetPlaneCount (DXGI_FORMAT Format); 96 | static bool MotionEstimatorAllowedInputFormat (DXGI_FORMAT Format); 97 | static bool SupportsSamplerFeedback (DXGI_FORMAT Format); 98 | static bool DecodeHistogramAllowedForOutputFormatSupport(DXGI_FORMAT Format); 99 | static UINT8 GetPlaneSliceFromViewFormat (DXGI_FORMAT ResourceFormat, DXGI_FORMAT ViewFormat); 100 | static bool FloatAndNotFloatFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB); 101 | static bool SNORMAndUNORMFormats (DXGI_FORMAT FormatA, DXGI_FORMAT FormatB); 102 | static bool ValidCastToR32UAV (DXGI_FORMAT from, DXGI_FORMAT to); 103 | static bool IsSupportedTextureDisplayableFormat (DXGI_FORMAT, bool bMediaFormatOnly); 104 | static D3D_FORMAT_COMPONENT_INTERPRETATION GetFormatComponentInterpretation (DXGI_FORMAT Format, UINT AbsoluteComponentIndex); 105 | static UINT GetBitsPerComponent (DXGI_FORMAT Format, UINT AbsoluteComponentIndex); 106 | static D3D_FORMAT_COMPONENT_NAME GetComponentName (DXGI_FORMAT Format, UINT AbsoluteComponentIndex); 107 | static HRESULT CalculateExtraPlanarRows (DXGI_FORMAT format, UINT plane0Height, _Out_ UINT& totalHeight); 108 | static HRESULT CalculateMinimumRowMajorRowPitch (DXGI_FORMAT Format, UINT Width, _Out_ UINT& RowPitch); 109 | static HRESULT CalculateMinimumRowMajorSlicePitch (DXGI_FORMAT Format, UINT ContextBasedRowPitch, UINT Height, _Out_ UINT& SlicePitch); 110 | static void GetYCbCrChromaSubsampling (DXGI_FORMAT Format, _Out_ UINT& HorizontalSubsampling, _Out_ UINT& VerticalSubsampling); 111 | 112 | static HRESULT CalculateResourceSize (UINT width, UINT height, UINT depth, DXGI_FORMAT format, UINT mipLevels, UINT subresources, _Out_ SIZE_T& totalByteSize, _Out_writes_opt_(subresources) D3D12_MEMCPY_DEST* pDst = nullptr); 113 | static void GetTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount); 114 | static void Get4KTileShape (D3D12_TILE_SHAPE* pTileShape, DXGI_FORMAT Format, D3D12_RESOURCE_DIMENSION Dimension, UINT SampleCount); 115 | static void GetMipDimensions (UINT8 mipSlice, _Inout_ UINT64* pWidth, _Inout_opt_ UINT64* pHeight = nullptr, _Inout_opt_ UINT64* pDepth = nullptr); 116 | static void GetPlaneSubsampledSizeAndFormatForCopyableLayout(UINT PlaneSlice, DXGI_FORMAT Format, UINT Width, UINT Height, _Out_ DXGI_FORMAT& PlaneFormat, _Out_ UINT& MinPlanePitchWidth, _Out_ UINT& PlaneWidth, _Out_ UINT& PlaneHeight); 117 | 118 | static UINT GetDetailTableIndex (DXGI_FORMAT Format); 119 | static UINT GetDetailTableIndexNoThrow (DXGI_FORMAT Format); 120 | static UINT GetDetailTableIndexThrow (DXGI_FORMAT Format); 121 | static bool SupportsDepth (DXGI_FORMAT Format); 122 | static bool SupportsStencil (DXGI_FORMAT Format); 123 | private: 124 | static const FORMAT_DETAIL* GetFormatDetail (DXGI_FORMAT Format); 125 | 126 | }; 127 | 128 | #endif -------------------------------------------------------------------------------- /include/directx/d3dx12_render_pass.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | 8 | #pragma once 9 | 10 | #ifndef __cplusplus 11 | #error D3DX12 requires C++ 12 | #endif 13 | 14 | #include "d3d12.h" 15 | #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) 16 | inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept 17 | { 18 | return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight)); 19 | } 20 | 21 | inline bool operator==(const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_BEGINNING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept 22 | { 23 | return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight)); 24 | } 25 | 26 | inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& a, const D3D12_RENDER_PASS_ENDING_ACCESS_PRESERVE_LOCAL_PARAMETERS& b) noexcept 27 | { 28 | return ((a.AdditionalWidth == b.AdditionalWidth) && (a.AdditionalHeight == b.AdditionalHeight)); 29 | } 30 | #endif 31 | 32 | inline bool operator==( const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &a, const D3D12_RENDER_PASS_BEGINNING_ACCESS_CLEAR_PARAMETERS &b) noexcept 33 | { 34 | return a.ClearValue == b.ClearValue; 35 | } 36 | 37 | inline bool operator==( const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &a, const D3D12_RENDER_PASS_ENDING_ACCESS_RESOLVE_PARAMETERS &b) noexcept 38 | { 39 | if (a.pSrcResource != b.pSrcResource) return false; 40 | if (a.pDstResource != b.pDstResource) return false; 41 | if (a.SubresourceCount != b.SubresourceCount) return false; 42 | if (a.Format != b.Format) return false; 43 | if (a.ResolveMode != b.ResolveMode) return false; 44 | if (a.PreserveResolveSource != b.PreserveResolveSource) return false; 45 | return true; 46 | } 47 | 48 | inline bool operator==( const D3D12_RENDER_PASS_BEGINNING_ACCESS &a, const D3D12_RENDER_PASS_BEGINNING_ACCESS &b) noexcept 49 | { 50 | if (a.Type != b.Type) return false; 51 | switch (a.Type) 52 | { 53 | case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_CLEAR: 54 | if (!(a.Clear == b.Clear)) return false; 55 | break; 56 | #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) 57 | case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_RENDER: 58 | case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_SRV: 59 | case D3D12_RENDER_PASS_BEGINNING_ACCESS_TYPE_PRESERVE_LOCAL_UAV: 60 | if (!(a.PreserveLocal == b.PreserveLocal)) return false; 61 | break; 62 | #endif 63 | default: 64 | break; 65 | } 66 | return true; 67 | } 68 | 69 | inline bool operator==(const D3D12_RENDER_PASS_ENDING_ACCESS& a, const D3D12_RENDER_PASS_ENDING_ACCESS& b) noexcept 70 | { 71 | if (a.Type != b.Type) return false; 72 | switch (a.Type) 73 | { 74 | case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_RESOLVE: 75 | if (!(a.Resolve == b.Resolve)) return false; 76 | break; 77 | #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 609) 78 | case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_RENDER: 79 | case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_SRV: 80 | case D3D12_RENDER_PASS_ENDING_ACCESS_TYPE_PRESERVE_LOCAL_UAV: 81 | if (!(a.PreserveLocal == b.PreserveLocal)) return false; 82 | break; 83 | #endif 84 | default: 85 | break; 86 | } 87 | return true; 88 | } 89 | 90 | inline bool operator==( const D3D12_RENDER_PASS_RENDER_TARGET_DESC &a, const D3D12_RENDER_PASS_RENDER_TARGET_DESC &b) noexcept 91 | { 92 | if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false; 93 | if (!(a.BeginningAccess == b.BeginningAccess)) return false; 94 | if (!(a.EndingAccess == b.EndingAccess)) return false; 95 | return true; 96 | } 97 | inline bool operator==( const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &a, const D3D12_RENDER_PASS_DEPTH_STENCIL_DESC &b) noexcept 98 | { 99 | if (a.cpuDescriptor.ptr != b.cpuDescriptor.ptr) return false; 100 | if (!(a.DepthBeginningAccess == b.DepthBeginningAccess)) return false; 101 | if (!(a.StencilBeginningAccess == b.StencilBeginningAccess)) return false; 102 | if (!(a.DepthEndingAccess == b.DepthEndingAccess)) return false; 103 | if (!(a.StencilEndingAccess == b.StencilEndingAccess)) return false; 104 | return true; 105 | } 106 | -------------------------------------------------------------------------------- /include/directx/d3dx12_resource_helpers.h: -------------------------------------------------------------------------------- 1 | //********************************************************* 2 | // 3 | // Copyright (c) Microsoft Corporation. 4 | // Licensed under the MIT License (MIT). 5 | // 6 | //********************************************************* 7 | 8 | #pragma once 9 | 10 | #ifndef __cplusplus 11 | #error D3DX12 requires C++ 12 | #endif 13 | 14 | #include "d3dx12_property_format_table.h" 15 | #include "d3d12.h" 16 | #include "d3dx12_core.h" 17 | //------------------------------------------------------------------------------------------------ 18 | template 19 | inline void D3D12DecomposeSubresource( UINT Subresource, UINT MipLevels, UINT ArraySize, _Out_ T& MipSlice, _Out_ U& ArraySlice, _Out_ V& PlaneSlice ) noexcept 20 | { 21 | MipSlice = static_cast(Subresource % MipLevels); 22 | ArraySlice = static_cast((Subresource / MipLevels) % ArraySize); 23 | PlaneSlice = static_cast(Subresource / (MipLevels * ArraySize)); 24 | } 25 | 26 | //------------------------------------------------------------------------------------------------ 27 | // Row-by-row memcpy 28 | inline void MemcpySubresource( 29 | _In_ const D3D12_MEMCPY_DEST* pDest, 30 | _In_ const D3D12_SUBRESOURCE_DATA* pSrc, 31 | SIZE_T RowSizeInBytes, 32 | UINT NumRows, 33 | UINT NumSlices) noexcept 34 | { 35 | for (UINT z = 0; z < NumSlices; ++z) 36 | { 37 | auto pDestSlice = static_cast(pDest->pData) + pDest->SlicePitch * z; 38 | auto pSrcSlice = static_cast(pSrc->pData) + pSrc->SlicePitch * LONG_PTR(z); 39 | for (UINT y = 0; y < NumRows; ++y) 40 | { 41 | memcpy(pDestSlice + pDest->RowPitch * y, 42 | pSrcSlice + pSrc->RowPitch * LONG_PTR(y), 43 | RowSizeInBytes); 44 | } 45 | } 46 | } 47 | 48 | //------------------------------------------------------------------------------------------------ 49 | // Row-by-row memcpy 50 | inline void MemcpySubresource( 51 | _In_ const D3D12_MEMCPY_DEST* pDest, 52 | _In_ const void* pResourceData, 53 | _In_ const D3D12_SUBRESOURCE_INFO* pSrc, 54 | SIZE_T RowSizeInBytes, 55 | UINT NumRows, 56 | UINT NumSlices) noexcept 57 | { 58 | for (UINT z = 0; z < NumSlices; ++z) 59 | { 60 | auto pDestSlice = static_cast(pDest->pData) + pDest->SlicePitch * z; 61 | auto pSrcSlice = (static_cast(pResourceData) + pSrc->Offset) + pSrc->DepthPitch * ULONG_PTR(z); 62 | for (UINT y = 0; y < NumRows; ++y) 63 | { 64 | memcpy(pDestSlice + pDest->RowPitch * y, 65 | pSrcSlice + pSrc->RowPitch * ULONG_PTR(y), 66 | RowSizeInBytes); 67 | } 68 | } 69 | } 70 | 71 | //------------------------------------------------------------------------------------------------ 72 | // Returns required size of a buffer to be used for data upload 73 | inline UINT64 GetRequiredIntermediateSize( 74 | _In_ ID3D12Resource* pDestinationResource, 75 | _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 76 | _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources) noexcept 77 | { 78 | #if defined(_MSC_VER) || !defined(_WIN32) 79 | const auto Desc = pDestinationResource->GetDesc(); 80 | #else 81 | D3D12_RESOURCE_DESC tmpDesc; 82 | const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc); 83 | #endif 84 | UINT64 RequiredSize = 0; 85 | 86 | ID3D12Device* pDevice = nullptr; 87 | pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast(&pDevice)); 88 | pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, nullptr, nullptr, nullptr, &RequiredSize); 89 | pDevice->Release(); 90 | 91 | return RequiredSize; 92 | } 93 | 94 | //------------------------------------------------------------------------------------------------ 95 | // All arrays must be populated (e.g. by calling GetCopyableFootprints) 96 | inline UINT64 UpdateSubresources( 97 | _In_ ID3D12GraphicsCommandList* pCmdList, 98 | _In_ ID3D12Resource* pDestinationResource, 99 | _In_ ID3D12Resource* pIntermediate, 100 | _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 101 | _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources, 102 | UINT64 RequiredSize, 103 | _In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, 104 | _In_reads_(NumSubresources) const UINT* pNumRows, 105 | _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes, 106 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept 107 | { 108 | // Minor validation 109 | #if defined(_MSC_VER) || !defined(_WIN32) 110 | const auto IntermediateDesc = pIntermediate->GetDesc(); 111 | const auto DestinationDesc = pDestinationResource->GetDesc(); 112 | #else 113 | D3D12_RESOURCE_DESC tmpDesc1, tmpDesc2; 114 | const auto& IntermediateDesc = *pIntermediate->GetDesc(&tmpDesc1); 115 | const auto& DestinationDesc = *pDestinationResource->GetDesc(&tmpDesc2); 116 | #endif 117 | if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || 118 | IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset || 119 | RequiredSize > SIZE_T(-1) || 120 | (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && 121 | (FirstSubresource != 0 || NumSubresources != 1))) 122 | { 123 | return 0; 124 | } 125 | 126 | BYTE* pData; 127 | HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast(&pData)); 128 | if (FAILED(hr)) 129 | { 130 | return 0; 131 | } 132 | 133 | for (UINT i = 0; i < NumSubresources; ++i) 134 | { 135 | if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0; 136 | D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) }; 137 | MemcpySubresource(&DestData, &pSrcData[i], static_cast(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth); 138 | } 139 | pIntermediate->Unmap(0, nullptr); 140 | 141 | if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) 142 | { 143 | pCmdList->CopyBufferRegion( 144 | pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width); 145 | } 146 | else 147 | { 148 | for (UINT i = 0; i < NumSubresources; ++i) 149 | { 150 | const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); 151 | const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); 152 | pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr); 153 | } 154 | } 155 | return RequiredSize; 156 | } 157 | 158 | //------------------------------------------------------------------------------------------------ 159 | // All arrays must be populated (e.g. by calling GetCopyableFootprints) 160 | inline UINT64 UpdateSubresources( 161 | _In_ ID3D12GraphicsCommandList* pCmdList, 162 | _In_ ID3D12Resource* pDestinationResource, 163 | _In_ ID3D12Resource* pIntermediate, 164 | _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 165 | _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources, 166 | UINT64 RequiredSize, 167 | _In_reads_(NumSubresources) const D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, 168 | _In_reads_(NumSubresources) const UINT* pNumRows, 169 | _In_reads_(NumSubresources) const UINT64* pRowSizesInBytes, 170 | _In_ const void* pResourceData, 171 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept 172 | { 173 | // Minor validation 174 | #if defined(_MSC_VER) || !defined(_WIN32) 175 | const auto IntermediateDesc = pIntermediate->GetDesc(); 176 | const auto DestinationDesc = pDestinationResource->GetDesc(); 177 | #else 178 | D3D12_RESOURCE_DESC tmpDesc1, tmpDesc2; 179 | const auto& IntermediateDesc = *pIntermediate->GetDesc(&tmpDesc1); 180 | const auto& DestinationDesc = *pDestinationResource->GetDesc(&tmpDesc2); 181 | #endif 182 | if (IntermediateDesc.Dimension != D3D12_RESOURCE_DIMENSION_BUFFER || 183 | IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset || 184 | RequiredSize > SIZE_T(-1) || 185 | (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && 186 | (FirstSubresource != 0 || NumSubresources != 1))) 187 | { 188 | return 0; 189 | } 190 | 191 | BYTE* pData; 192 | HRESULT hr = pIntermediate->Map(0, nullptr, reinterpret_cast(&pData)); 193 | if (FAILED(hr)) 194 | { 195 | return 0; 196 | } 197 | 198 | for (UINT i = 0; i < NumSubresources; ++i) 199 | { 200 | if (pRowSizesInBytes[i] > SIZE_T(-1)) return 0; 201 | D3D12_MEMCPY_DEST DestData = { pData + pLayouts[i].Offset, pLayouts[i].Footprint.RowPitch, SIZE_T(pLayouts[i].Footprint.RowPitch) * SIZE_T(pNumRows[i]) }; 202 | MemcpySubresource(&DestData, pResourceData, &pSrcData[i], static_cast(pRowSizesInBytes[i]), pNumRows[i], pLayouts[i].Footprint.Depth); 203 | } 204 | pIntermediate->Unmap(0, nullptr); 205 | 206 | if (DestinationDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER) 207 | { 208 | pCmdList->CopyBufferRegion( 209 | pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width); 210 | } 211 | else 212 | { 213 | for (UINT i = 0; i < NumSubresources; ++i) 214 | { 215 | const CD3DX12_TEXTURE_COPY_LOCATION Dst(pDestinationResource, i + FirstSubresource); 216 | const CD3DX12_TEXTURE_COPY_LOCATION Src(pIntermediate, pLayouts[i]); 217 | pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, nullptr); 218 | } 219 | } 220 | return RequiredSize; 221 | } 222 | 223 | //------------------------------------------------------------------------------------------------ 224 | // Heap-allocating UpdateSubresources implementation 225 | inline UINT64 UpdateSubresources( 226 | _In_ ID3D12GraphicsCommandList* pCmdList, 227 | _In_ ID3D12Resource* pDestinationResource, 228 | _In_ ID3D12Resource* pIntermediate, 229 | UINT64 IntermediateOffset, 230 | _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 231 | _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources, 232 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept 233 | { 234 | UINT64 RequiredSize = 0; 235 | const auto MemToAlloc = static_cast(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources; 236 | if (MemToAlloc > SIZE_MAX) 237 | { 238 | return 0; 239 | } 240 | void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast(MemToAlloc)); 241 | if (pMem == nullptr) 242 | { 243 | return 0; 244 | } 245 | auto pLayouts = static_cast(pMem); 246 | auto pRowSizesInBytes = reinterpret_cast(pLayouts + NumSubresources); 247 | auto pNumRows = reinterpret_cast(pRowSizesInBytes + NumSubresources); 248 | 249 | #if defined(_MSC_VER) || !defined(_WIN32) 250 | const auto Desc = pDestinationResource->GetDesc(); 251 | #else 252 | D3D12_RESOURCE_DESC tmpDesc; 253 | const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc); 254 | #endif 255 | ID3D12Device* pDevice = nullptr; 256 | pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast(&pDevice)); 257 | pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize); 258 | pDevice->Release(); 259 | 260 | const UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData); 261 | HeapFree(GetProcessHeap(), 0, pMem); 262 | return Result; 263 | } 264 | 265 | //------------------------------------------------------------------------------------------------ 266 | // Heap-allocating UpdateSubresources implementation 267 | inline UINT64 UpdateSubresources( 268 | _In_ ID3D12GraphicsCommandList* pCmdList, 269 | _In_ ID3D12Resource* pDestinationResource, 270 | _In_ ID3D12Resource* pIntermediate, 271 | UINT64 IntermediateOffset, 272 | _In_range_(0,D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 273 | _In_range_(0,D3D12_REQ_SUBRESOURCES-FirstSubresource) UINT NumSubresources, 274 | _In_ const void* pResourceData, 275 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept 276 | { 277 | UINT64 RequiredSize = 0; 278 | const auto MemToAlloc = static_cast(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(UINT) + sizeof(UINT64)) * NumSubresources; 279 | if (MemToAlloc > SIZE_MAX) 280 | { 281 | return 0; 282 | } 283 | void* pMem = HeapAlloc(GetProcessHeap(), 0, static_cast(MemToAlloc)); 284 | if (pMem == nullptr) 285 | { 286 | return 0; 287 | } 288 | auto pLayouts = static_cast(pMem); 289 | auto pRowSizesInBytes = reinterpret_cast(pLayouts + NumSubresources); 290 | auto pNumRows = reinterpret_cast(pRowSizesInBytes + NumSubresources); 291 | 292 | #if defined(_MSC_VER) || !defined(_WIN32) 293 | const auto Desc = pDestinationResource->GetDesc(); 294 | #else 295 | D3D12_RESOURCE_DESC tmpDesc; 296 | const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc); 297 | #endif 298 | ID3D12Device* pDevice = nullptr; 299 | pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast(&pDevice)); 300 | pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize); 301 | pDevice->Release(); 302 | 303 | const UINT64 Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pResourceData, pSrcData); 304 | HeapFree(GetProcessHeap(), 0, pMem); 305 | return Result; 306 | } 307 | 308 | //------------------------------------------------------------------------------------------------ 309 | // Stack-allocating UpdateSubresources implementation 310 | template 311 | inline UINT64 UpdateSubresources( 312 | _In_ ID3D12GraphicsCommandList* pCmdList, 313 | _In_ ID3D12Resource* pDestinationResource, 314 | _In_ ID3D12Resource* pIntermediate, 315 | UINT64 IntermediateOffset, 316 | _In_range_(0,MaxSubresources) UINT FirstSubresource, 317 | _In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources, 318 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_DATA* pSrcData) noexcept 319 | { 320 | UINT64 RequiredSize = 0; 321 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources]; 322 | UINT NumRows[MaxSubresources]; 323 | UINT64 RowSizesInBytes[MaxSubresources]; 324 | 325 | #if defined(_MSC_VER) || !defined(_WIN32) 326 | const auto Desc = pDestinationResource->GetDesc(); 327 | #else 328 | D3D12_RESOURCE_DESC tmpDesc; 329 | const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc); 330 | #endif 331 | ID3D12Device* pDevice = nullptr; 332 | pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast(&pDevice)); 333 | pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize); 334 | pDevice->Release(); 335 | 336 | return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData); 337 | } 338 | 339 | //------------------------------------------------------------------------------------------------ 340 | // Stack-allocating UpdateSubresources implementation 341 | template 342 | inline UINT64 UpdateSubresources( 343 | _In_ ID3D12GraphicsCommandList* pCmdList, 344 | _In_ ID3D12Resource* pDestinationResource, 345 | _In_ ID3D12Resource* pIntermediate, 346 | UINT64 IntermediateOffset, 347 | _In_range_(0,MaxSubresources) UINT FirstSubresource, 348 | _In_range_(1,MaxSubresources-FirstSubresource) UINT NumSubresources, 349 | _In_ const void* pResourceData, 350 | _In_reads_(NumSubresources) const D3D12_SUBRESOURCE_INFO* pSrcData) noexcept 351 | { 352 | UINT64 RequiredSize = 0; 353 | D3D12_PLACED_SUBRESOURCE_FOOTPRINT Layouts[MaxSubresources]; 354 | UINT NumRows[MaxSubresources]; 355 | UINT64 RowSizesInBytes[MaxSubresources]; 356 | 357 | #if defined(_MSC_VER) || !defined(_WIN32) 358 | const auto Desc = pDestinationResource->GetDesc(); 359 | #else 360 | D3D12_RESOURCE_DESC tmpDesc; 361 | const auto& Desc = *pDestinationResource->GetDesc(&tmpDesc); 362 | #endif 363 | ID3D12Device* pDevice = nullptr; 364 | pDestinationResource->GetDevice(IID_ID3D12Device, reinterpret_cast(&pDevice)); 365 | pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize); 366 | pDevice->Release(); 367 | 368 | return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pResourceData, pSrcData); 369 | } 370 | 371 | //------------------------------------------------------------------------------------------------ 372 | constexpr bool D3D12IsLayoutOpaque( D3D12_TEXTURE_LAYOUT Layout ) noexcept 373 | { return Layout == D3D12_TEXTURE_LAYOUT_UNKNOWN || Layout == D3D12_TEXTURE_LAYOUT_64KB_UNDEFINED_SWIZZLE; } 374 | 375 | //------------------------------------------------------------------------------------------------ 376 | template< typename T > 377 | inline T D3DX12Align(T uValue, T uAlign) 378 | { 379 | // Assert power of 2 alignment 380 | D3DX12_ASSERT(0 == (uAlign & (uAlign - 1))); 381 | T uMask = uAlign - 1; 382 | T uResult = (uValue + uMask) & ~uMask; 383 | D3DX12_ASSERT(uResult >= uValue); 384 | D3DX12_ASSERT(0 == (uResult % uAlign)); 385 | return uResult; 386 | } 387 | 388 | //------------------------------------------------------------------------------------------------ 389 | template< typename T > 390 | inline T D3DX12AlignAtLeast(T uValue, T uAlign) 391 | { 392 | T aligned = D3DX12Align(uValue, uAlign); 393 | return aligned > uAlign ? aligned : uAlign; 394 | } 395 | 396 | inline const CD3DX12_RESOURCE_DESC1* D3DX12ConditionallyExpandAPIDesc( 397 | D3D12_RESOURCE_DESC1& LclDesc, 398 | const D3D12_RESOURCE_DESC1* pDesc) 399 | { 400 | return D3DX12ConditionallyExpandAPIDesc(static_cast(LclDesc), static_cast(pDesc)); 401 | } 402 | 403 | #if defined(D3D12_SDK_VERSION) && (D3D12_SDK_VERSION >= 606) 404 | //------------------------------------------------------------------------------------------------ 405 | // The difference between D3DX12GetCopyableFootprints and ID3D12Device::GetCopyableFootprints 406 | // is that this one loses a lot of error checking by assuming the arguments are correct 407 | inline bool D3DX12GetCopyableFootprints( 408 | _In_ const D3D12_RESOURCE_DESC1& ResourceDesc, 409 | _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 410 | _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources, 411 | UINT64 BaseOffset, 412 | _Out_writes_opt_(NumSubresources) D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, 413 | _Out_writes_opt_(NumSubresources) UINT* pNumRows, 414 | _Out_writes_opt_(NumSubresources) UINT64* pRowSizeInBytes, 415 | _Out_opt_ UINT64* pTotalBytes) 416 | { 417 | constexpr UINT64 uint64_max = ~0ull; 418 | UINT64 TotalBytes = uint64_max; 419 | UINT uSubRes = 0; 420 | 421 | bool bResourceOverflow = false; 422 | TotalBytes = 0; 423 | 424 | const DXGI_FORMAT Format = ResourceDesc.Format; 425 | 426 | CD3DX12_RESOURCE_DESC1 LresourceDesc; 427 | const CD3DX12_RESOURCE_DESC1& resourceDesc = *D3DX12ConditionallyExpandAPIDesc(LresourceDesc, &ResourceDesc); 428 | 429 | // Check if its a valid format 430 | D3DX12_ASSERT(D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::FormatExists(Format)); 431 | 432 | // D3DX12GetCopyableFootprints does not support buffers with width larger than UINT_MAX. 433 | if (ResourceDesc.Dimension == D3D12_RESOURCE_DIMENSION_BUFFER && ResourceDesc.Width >= UINT_MAX) 434 | { 435 | return false; 436 | } 437 | 438 | const UINT WidthAlignment = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetWidthAlignment( Format ); 439 | const UINT HeightAlignment = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetHeightAlignment( Format ); 440 | const UINT16 DepthAlignment = UINT16( D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetDepthAlignment( Format ) ); 441 | 442 | for (; uSubRes < NumSubresources; ++uSubRes) 443 | { 444 | bool bOverflow = false; 445 | UINT Subresource = FirstSubresource + uSubRes; 446 | 447 | D3DX12_ASSERT(resourceDesc.MipLevels != 0); 448 | UINT subresourceCount = resourceDesc.MipLevels * resourceDesc.ArraySize() * D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetPlaneCount(resourceDesc.Format); 449 | 450 | if (Subresource > subresourceCount) 451 | { 452 | break; 453 | } 454 | 455 | TotalBytes = D3DX12Align< UINT64 >( TotalBytes, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT ); 456 | 457 | UINT MipLevel, ArraySlice, PlaneSlice; 458 | D3D12DecomposeSubresource(Subresource, resourceDesc.MipLevels, resourceDesc.ArraySize(), /*_Out_*/MipLevel, /*_Out_*/ArraySlice, /*_Out_*/PlaneSlice); 459 | 460 | const UINT64 Width = D3DX12AlignAtLeast(resourceDesc.Width >> MipLevel, WidthAlignment); 461 | const UINT Height = D3DX12AlignAtLeast(resourceDesc.Height >> MipLevel, HeightAlignment); 462 | const UINT16 Depth = D3DX12AlignAtLeast(resourceDesc.Depth() >> MipLevel, DepthAlignment); 463 | 464 | // Adjust for the current PlaneSlice. Most formats have only one plane. 465 | DXGI_FORMAT PlaneFormat; 466 | UINT32 MinPlanePitchWidth, PlaneWidth, PlaneHeight; 467 | D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::GetPlaneSubsampledSizeAndFormatForCopyableLayout(PlaneSlice, Format, (UINT)Width, Height, /*_Out_*/ PlaneFormat, /*_Out_*/ MinPlanePitchWidth, /* _Out_ */ PlaneWidth, /*_Out_*/ PlaneHeight); 468 | 469 | D3D12_SUBRESOURCE_FOOTPRINT LocalPlacement = {}; 470 | auto& Placement = pLayouts ? pLayouts[uSubRes].Footprint : LocalPlacement; 471 | Placement.Format = PlaneFormat; 472 | Placement.Width = PlaneWidth; 473 | Placement.Height = PlaneHeight; 474 | Placement.Depth = Depth; 475 | 476 | // Calculate row pitch 477 | UINT MinPlaneRowPitch = 0; 478 | D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch(PlaneFormat, MinPlanePitchWidth, MinPlaneRowPitch); 479 | 480 | // Formats with more than one plane choose a larger pitch alignment to ensure that each plane begins on the row 481 | // immediately following the previous plane while still adhering to subresource alignment restrictions. 482 | static_assert( D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT >= D3D12_TEXTURE_DATA_PITCH_ALIGNMENT 483 | && ((D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT % D3D12_TEXTURE_DATA_PITCH_ALIGNMENT) == 0), 484 | "D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT must be >= and evenly divisible by D3D12_TEXTURE_DATA_PITCH_ALIGNMENT." ); 485 | 486 | Placement.RowPitch = D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::Planar(Format) 487 | ? D3DX12Align< UINT >( MinPlaneRowPitch, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT ) 488 | : D3DX12Align< UINT >( MinPlaneRowPitch, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT ); 489 | 490 | if (pRowSizeInBytes) 491 | { 492 | UINT PlaneRowSize = 0; 493 | D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::CalculateMinimumRowMajorRowPitch(PlaneFormat, PlaneWidth, PlaneRowSize); 494 | 495 | pRowSizeInBytes[uSubRes] = PlaneRowSize; 496 | } 497 | 498 | // Number of rows (accounting for block compression and additional planes) 499 | UINT NumRows = 0; 500 | if (D3D12_PROPERTY_LAYOUT_FORMAT_TABLE::Planar(Format)) 501 | { 502 | NumRows = PlaneHeight; 503 | } 504 | else 505 | { 506 | D3DX12_ASSERT(Height % HeightAlignment == 0); 507 | NumRows = Height / HeightAlignment; 508 | } 509 | 510 | if (pNumRows) 511 | { 512 | pNumRows[uSubRes] = NumRows; 513 | } 514 | 515 | // Offsetting 516 | if (pLayouts) 517 | { 518 | pLayouts[uSubRes].Offset = (bOverflow ? uint64_max : TotalBytes + BaseOffset); 519 | } 520 | 521 | const UINT16 NumSlices = Depth; 522 | const UINT64 SubresourceSize = (NumRows * NumSlices - 1) * Placement.RowPitch + MinPlaneRowPitch; 523 | 524 | // uint64 addition with overflow checking 525 | TotalBytes = TotalBytes + SubresourceSize; 526 | if(TotalBytes < SubresourceSize) 527 | { 528 | TotalBytes = uint64_max; 529 | } 530 | bResourceOverflow = bResourceOverflow || bOverflow; 531 | } 532 | 533 | // Overflow error 534 | if (bResourceOverflow) 535 | { 536 | TotalBytes = uint64_max; 537 | } 538 | 539 | 540 | if (pLayouts) 541 | { 542 | memset( pLayouts + uSubRes, -1, sizeof( *pLayouts ) * (NumSubresources - uSubRes) ); 543 | } 544 | if (pNumRows) 545 | { 546 | memset(pNumRows + uSubRes, -1, sizeof(*pNumRows) * (NumSubresources - uSubRes)); 547 | } 548 | if (pRowSizeInBytes) 549 | { 550 | memset(pRowSizeInBytes + uSubRes, -1, sizeof(*pRowSizeInBytes) * (NumSubresources - uSubRes)); 551 | } 552 | if (pTotalBytes) 553 | { 554 | *pTotalBytes = TotalBytes; 555 | } 556 | if(TotalBytes == uint64_max) 557 | { 558 | return false; 559 | } 560 | return true; 561 | } 562 | 563 | //------------------------------------------------------------------------------------------------ 564 | inline D3D12_RESOURCE_DESC1 D3DX12ResourceDesc0ToDesc1(D3D12_RESOURCE_DESC const& desc0) 565 | { 566 | D3D12_RESOURCE_DESC1 desc1; 567 | desc1.Dimension = desc0.Dimension; 568 | desc1.Alignment = desc0.Alignment; 569 | desc1.Width = desc0.Width; 570 | desc1.Height = desc0.Height; 571 | desc1.DepthOrArraySize = desc0.DepthOrArraySize; 572 | desc1.MipLevels = desc0.MipLevels; 573 | desc1.Format = desc0.Format; 574 | desc1.SampleDesc.Count = desc0.SampleDesc.Count; 575 | desc1.SampleDesc.Quality = desc0.SampleDesc.Quality; 576 | desc1.Layout = desc0.Layout; 577 | desc1.Flags = desc0.Flags; 578 | desc1.SamplerFeedbackMipRegion.Width = 0; 579 | desc1.SamplerFeedbackMipRegion.Height = 0; 580 | desc1.SamplerFeedbackMipRegion.Depth = 0; 581 | return desc1; 582 | } 583 | 584 | //------------------------------------------------------------------------------------------------ 585 | inline bool D3DX12GetCopyableFootprints( 586 | _In_ const D3D12_RESOURCE_DESC& pResourceDesc, 587 | _In_range_(0, D3D12_REQ_SUBRESOURCES) UINT FirstSubresource, 588 | _In_range_(0, D3D12_REQ_SUBRESOURCES - FirstSubresource) UINT NumSubresources, 589 | UINT64 BaseOffset, 590 | _Out_writes_opt_(NumSubresources) D3D12_PLACED_SUBRESOURCE_FOOTPRINT* pLayouts, 591 | _Out_writes_opt_(NumSubresources) UINT* pNumRows, 592 | _Out_writes_opt_(NumSubresources) UINT64* pRowSizeInBytes, 593 | _Out_opt_ UINT64* pTotalBytes) 594 | { 595 | // From D3D12_RESOURCE_DESC to D3D12_RESOURCE_DESC1 596 | D3D12_RESOURCE_DESC1 desc = D3DX12ResourceDesc0ToDesc1(pResourceDesc); 597 | return D3DX12GetCopyableFootprints( 598 | *static_cast(&desc),// From D3D12_RESOURCE_DESC1 to CD3DX12_RESOURCE_DESC1 599 | FirstSubresource, 600 | NumSubresources, 601 | BaseOffset, 602 | pLayouts, 603 | pNumRows, 604 | pRowSizeInBytes, 605 | pTotalBytes); 606 | } 607 | 608 | #endif // D3D12_SDK_VERSION >= 606 609 | 610 | -------------------------------------------------------------------------------- /include/directx/dxcore.h: -------------------------------------------------------------------------------- 1 | /************************************************************ 2 | * * 3 | * Copyright (c) Microsoft Corporation. * 4 | * Licensed under the MIT license. * 5 | * * 6 | ************************************************************/ 7 | 8 | #ifndef _DXCOREEXTMODULE_H_ 9 | #define _DXCOREEXTMODULE_H_ 10 | 11 | #include 12 | #include "dxcore_interface.h" 13 | 14 | #pragma region Application Family or OneCore Family 15 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) 16 | 17 | #if (_WIN32_WINNT >= _WIN32_WINNT_WIN10) 18 | 19 | STDAPI 20 | DXCoreCreateAdapterFactory( 21 | REFIID riid, 22 | _COM_Outptr_ void** ppvFactory 23 | ); 24 | 25 | template 26 | HRESULT 27 | DXCoreCreateAdapterFactory( 28 | _COM_Outptr_ T** ppvFactory 29 | ) 30 | { 31 | return DXCoreCreateAdapterFactory(IID_PPV_ARGS(ppvFactory)); 32 | } 33 | 34 | #endif // (_WIN32_WINNT >= _WIN32_WINNT_WIN10) 35 | 36 | #endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */ 37 | #pragma endregion 38 | 39 | #endif // _DXCOREEXTMODULE_H_ 40 | 41 | 42 | -------------------------------------------------------------------------------- /include/directx/dxcore_interface.h: -------------------------------------------------------------------------------- 1 | // 2 | // DXCore Interface 3 | // Copyright (C) Microsoft Corporation. 4 | // Licensed under the MIT license. 5 | // 6 | 7 | #ifndef __dxcore_interface_h__ 8 | #define __dxcore_interface_h__ 9 | 10 | #ifndef COM_NO_WINDOWS_H 11 | #include "windows.h" 12 | #include "ole2.h" 13 | #endif /*COM_NO_WINDOWS_H*/ 14 | 15 | #include 16 | 17 | #ifdef __cplusplus 18 | 19 | #define _FACDXCORE 0x880 20 | #define MAKE_DXCORE_HRESULT( code ) MAKE_HRESULT( 1, _FACDXCORE, code ) 21 | 22 | enum class DXCoreAdapterProperty : uint32_t 23 | { 24 | InstanceLuid = 0, 25 | DriverVersion = 1, 26 | DriverDescription = 2, 27 | HardwareID = 3, // Use HardwareIDParts instead, if available. 28 | KmdModelVersion = 4, 29 | ComputePreemptionGranularity = 5, 30 | GraphicsPreemptionGranularity = 6, 31 | DedicatedAdapterMemory = 7, 32 | DedicatedSystemMemory = 8, 33 | SharedSystemMemory = 9, 34 | AcgCompatible = 10, 35 | IsHardware = 11, 36 | IsIntegrated = 12, 37 | IsDetachable = 13, 38 | HardwareIDParts = 14, 39 | PhysicalAdapterCount = 15, 40 | AdapterEngineCount = 16, 41 | AdapterEngineName = 17, 42 | }; 43 | 44 | enum class DXCoreAdapterState : uint32_t 45 | { 46 | IsDriverUpdateInProgress = 0, 47 | AdapterMemoryBudget = 1, 48 | AdapterMemoryUsageBytes = 2, 49 | AdapterMemoryUsageByProcessBytes = 3, 50 | AdapterEngineRunningTimeMicroseconds = 4, 51 | AdapterEngineRunningTimeByProcessMicroseconds = 5, 52 | AdapterTemperatureCelsius = 6, 53 | AdapterInUseProcessCount = 7, 54 | AdapterInUseProcessSet = 8, 55 | AdapterEngineFrequencyHertz = 9, 56 | AdapterMemoryFrequencyHertz = 10 57 | }; 58 | 59 | enum class DXCoreSegmentGroup : uint32_t 60 | { 61 | Local = 0, 62 | NonLocal = 1 63 | }; 64 | 65 | enum class DXCoreNotificationType : uint32_t 66 | { 67 | AdapterListStale = 0, 68 | AdapterNoLongerValid = 1, 69 | AdapterBudgetChange = 2, 70 | AdapterHardwareContentProtectionTeardown = 3 71 | }; 72 | 73 | enum class DXCoreAdapterPreference : uint32_t 74 | { 75 | Hardware = 0, 76 | MinimumPower = 1, 77 | HighPerformance = 2 78 | }; 79 | 80 | enum class DXCoreWorkload : uint32_t 81 | { 82 | Graphics = 0, 83 | Compute = 1, 84 | Media = 2, 85 | MachineLearning = 3, 86 | }; 87 | 88 | enum class DXCoreRuntimeFilterFlags : uint32_t 89 | { 90 | None = 0x0, 91 | D3D11 = 0x1, 92 | D3D12 = 0x2 93 | }; 94 | 95 | DEFINE_ENUM_FLAG_OPERATORS(DXCoreRuntimeFilterFlags) 96 | 97 | enum class DXCoreHardwareTypeFilterFlags : uint32_t 98 | { 99 | None = 0x0, 100 | GPU = 0x1, 101 | ComputeAccelerator = 0x2, 102 | NPU = 0x4, 103 | MediaAccelerator = 0x8 104 | }; 105 | 106 | DEFINE_ENUM_FLAG_OPERATORS(DXCoreHardwareTypeFilterFlags) 107 | 108 | struct DXCoreHardwareID 109 | { 110 | uint32_t vendorID; 111 | uint32_t deviceID; 112 | uint32_t subSysID; 113 | uint32_t revision; 114 | }; 115 | 116 | struct DXCoreHardwareIDParts 117 | { 118 | uint32_t vendorID; 119 | uint32_t deviceID; 120 | uint32_t subSystemID; 121 | uint32_t subVendorID; 122 | uint32_t revisionID; 123 | }; 124 | 125 | struct DXCoreAdapterMemoryBudgetNodeSegmentGroup 126 | { 127 | uint32_t nodeIndex; 128 | DXCoreSegmentGroup segmentGroup; 129 | }; 130 | 131 | struct DXCoreAdapterMemoryBudget 132 | { 133 | uint64_t budget; 134 | uint64_t currentUsage; 135 | uint64_t availableForReservation; 136 | uint64_t currentReservation; 137 | }; 138 | 139 | struct DXCoreAdapterEngineIndex 140 | { 141 | uint32_t physicalAdapterIndex; 142 | uint32_t engineIndex; 143 | }; 144 | 145 | struct DXCoreEngineQueryInput 146 | { 147 | DXCoreAdapterEngineIndex adapterEngineIndex; 148 | uint32_t processId; 149 | }; 150 | 151 | struct DXCoreEngineQueryOutput 152 | { 153 | uint64_t runningTime; 154 | bool processQuerySucceeded; 155 | }; 156 | 157 | enum class DXCoreMemoryType : uint32_t 158 | { 159 | Dedicated = 0, 160 | Shared = 1 161 | }; 162 | 163 | struct DXCoreMemoryUsage 164 | { 165 | uint64_t committed; 166 | uint64_t resident; 167 | }; 168 | 169 | struct DXCoreMemoryQueryInput 170 | { 171 | uint32_t physicalAdapterIndex; 172 | DXCoreMemoryType memoryType; 173 | }; 174 | 175 | struct DXCoreProcessMemoryQueryInput 176 | { 177 | uint32_t physicalAdapterIndex; 178 | DXCoreMemoryType memoryType; 179 | uint32_t processId; 180 | }; 181 | 182 | struct DXCoreProcessMemoryQueryOutput 183 | { 184 | DXCoreMemoryUsage memoryUsage; 185 | bool processQuerySucceeded; 186 | }; 187 | 188 | struct DXCoreAdapterProcessSetQueryInput 189 | { 190 | uint32_t arraySize; 191 | _Field_size_(arraySize) uint32_t* processIds; 192 | }; 193 | 194 | struct DXCoreAdapterProcessSetQueryOutput 195 | { 196 | uint32_t processesWritten; 197 | uint32_t processesTotal; 198 | }; 199 | 200 | struct DXCoreEngineNamePropertyInput 201 | { 202 | DXCoreAdapterEngineIndex adapterEngineIndex; 203 | uint32_t engineNameLength; 204 | _Field_size_(engineNameLength) wchar_t *engineName; 205 | }; 206 | 207 | struct DXCoreEngineNamePropertyOutput 208 | { 209 | uint32_t engineNameLength; 210 | }; 211 | 212 | struct DXCoreFrequencyQueryOutput 213 | { 214 | uint64_t frequency; 215 | uint64_t maxFrequency; 216 | uint64_t maxOverclockedFrequency; 217 | }; 218 | 219 | typedef void (STDMETHODCALLTYPE *PFN_DXCORE_NOTIFICATION_CALLBACK)( 220 | DXCoreNotificationType notificationType, 221 | _In_ IUnknown *object, 222 | _In_opt_ void *context); 223 | 224 | static_assert(sizeof(bool) == 1, "bool assumed as one byte"); 225 | 226 | DEFINE_GUID(IID_IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06); 227 | DEFINE_GUID(IID_IDXCoreAdapterFactory1, 0xd5682e19, 0x6d21, 0x401c, 0x82, 0x7a, 0x9a, 0x51, 0xa4, 0xea, 0x35, 0xd7); 228 | DEFINE_GUID(IID_IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28); 229 | DEFINE_GUID(IID_IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e); 230 | DEFINE_GUID(IID_IDXCoreAdapter1, 0xa0783366, 0xcfa3, 0x43be, 0x9d, 0x79, 0x55, 0xb2, 0xda, 0x97, 0xc6, 0x3c); 231 | 232 | DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D11_GRAPHICS, 0x8c47866b, 0x7583, 0x450d, 0xf0, 0xf0, 0x6b, 0xad, 0xa8, 0x95, 0xaf, 0x4b); 233 | DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS, 0x0c9ece4d, 0x2f6e, 0x4f01, 0x8c, 0x96, 0xe8, 0x9e, 0x33, 0x1b, 0x47, 0xb1); 234 | DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, 0x248e2800, 0xa793, 0x4724, 0xab, 0xaa, 0x23, 0xa6, 0xde, 0x1b, 0xe0, 0x90); 235 | DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_ML, 0xb71b0d41, 0x1088, 0x422f, 0xa2, 0x7c, 0x2, 0x50, 0xb7, 0xd3, 0xa9, 0x88); 236 | DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_MEDIA, 0x8eb2c848, 0x82f6, 0x4b49, 0xaa, 0x87, 0xae, 0xcf, 0xcf, 0x1, 0x74, 0xc6); 237 | 238 | DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_GPU, 0xb69eb219, 0x3ded, 0x4464, 0x97, 0x9f, 0xa0, 0xb, 0xd4, 0x68, 0x70, 0x6); 239 | DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_COMPUTE_ACCELERATOR, 0xe0b195da, 0x58ef, 0x4a22, 0x90, 0xf1, 0x1f, 0x28, 0x16, 0x9c, 0xab, 0x8d); 240 | DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_NPU, 0xd46140c4, 0xadd7, 0x451b, 0x9e, 0x56, 0x6, 0xfe, 0x8c, 0x3b, 0x58, 0xed); 241 | DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_MEDIA_ACCELERATOR, 0x66bdb96a, 0x50b, 0x44c7, 0xa4, 0xfd, 0xd1, 0x44, 0xce, 0xa, 0xb4, 0x43); 242 | 243 | /* interface IDXCoreAdapter */ 244 | MIDL_INTERFACE("f0db4c7f-fe5a-42a2-bd62-f2a6cf6fc83e") 245 | IDXCoreAdapter : public IUnknown 246 | { 247 | public: 248 | virtual bool STDMETHODCALLTYPE IsValid() = 0; 249 | 250 | virtual bool STDMETHODCALLTYPE IsAttributeSupported( 251 | REFGUID attributeGUID) = 0; 252 | 253 | virtual bool STDMETHODCALLTYPE IsPropertySupported( 254 | DXCoreAdapterProperty property) = 0; 255 | 256 | virtual HRESULT STDMETHODCALLTYPE GetProperty( 257 | DXCoreAdapterProperty property, 258 | size_t bufferSize, 259 | _Out_writes_bytes_(bufferSize) void *propertyData) = 0; 260 | 261 | template 262 | HRESULT GetProperty( 263 | DXCoreAdapterProperty property, 264 | _Out_writes_bytes_(sizeof(T)) T *propertyData) 265 | { 266 | return GetProperty(property, 267 | sizeof(T), 268 | (void*)propertyData); 269 | } 270 | 271 | virtual HRESULT STDMETHODCALLTYPE GetPropertySize( 272 | DXCoreAdapterProperty property, 273 | _Out_ size_t *bufferSize) = 0; 274 | 275 | virtual bool STDMETHODCALLTYPE IsQueryStateSupported( 276 | DXCoreAdapterState property) = 0; 277 | 278 | virtual HRESULT STDMETHODCALLTYPE QueryState( 279 | DXCoreAdapterState state, 280 | size_t inputStateDetailsSize, 281 | _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, 282 | size_t outputBufferSize, 283 | _Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0; 284 | 285 | template 286 | HRESULT QueryState( 287 | DXCoreAdapterState state, 288 | _In_reads_bytes_opt_(sizeof(T1)) const T1 *inputStateDetails, 289 | _Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer) 290 | { 291 | return QueryState(state, 292 | sizeof(T1), 293 | (const void*)inputStateDetails, 294 | sizeof(T2), 295 | (void*)outputBuffer); 296 | } 297 | 298 | template 299 | HRESULT QueryState( 300 | DXCoreAdapterState state, 301 | _Out_writes_bytes_(sizeof(T)) T *outputBuffer) 302 | { 303 | return QueryState(state, 304 | 0, 305 | nullptr, 306 | sizeof(T), 307 | (void*)outputBuffer); 308 | } 309 | 310 | virtual bool STDMETHODCALLTYPE IsSetStateSupported( 311 | DXCoreAdapterState property) = 0; 312 | 313 | virtual HRESULT STDMETHODCALLTYPE SetState( 314 | DXCoreAdapterState state, 315 | size_t inputStateDetailsSize, 316 | _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, 317 | size_t inputDataSize, 318 | _In_reads_bytes_(inputDataSize) const void *inputData) = 0; 319 | 320 | template 321 | HRESULT SetState( 322 | DXCoreAdapterState state, 323 | const T1 *inputStateDetails, 324 | const T2 *inputData) 325 | { 326 | return SetState(state, 327 | sizeof(T1), 328 | (const void*)inputStateDetails, 329 | sizeof(T2), 330 | (const void*)inputData); 331 | } 332 | 333 | virtual HRESULT STDMETHODCALLTYPE GetFactory( 334 | REFIID riid, 335 | _COM_Outptr_ void** ppvFactory 336 | ) = 0; 337 | 338 | template 339 | HRESULT GetFactory( 340 | _COM_Outptr_ T** ppvFactory 341 | ) 342 | { 343 | return GetFactory(IID_PPV_ARGS(ppvFactory)); 344 | } 345 | }; 346 | 347 | /* interface IDXCoreAdapter1 */ 348 | MIDL_INTERFACE("a0783366-cfa3-43be-9d79-55b2da97c63c") 349 | IDXCoreAdapter1 : public IDXCoreAdapter 350 | { 351 | public: 352 | virtual HRESULT STDMETHODCALLTYPE GetPropertyWithInput( 353 | DXCoreAdapterProperty property, 354 | size_t inputPropertyDetailsSize, 355 | _In_reads_bytes_opt_(inputPropertyDetailsSize) const void *inputPropertyDetails, 356 | size_t outputBufferSize, 357 | _Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0; 358 | 359 | template 360 | HRESULT GetPropertyWithInput( 361 | DXCoreAdapterProperty property, 362 | _In_reads_bytes_opt_(sizeof(T1)) const T1 *inputPropertyDetails, 363 | _Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer) 364 | { 365 | return GetPropertyWithInput(property, 366 | sizeof(T1), 367 | (const void*)inputPropertyDetails, 368 | sizeof(T2), 369 | (void*)outputBuffer); 370 | } 371 | }; 372 | 373 | /* interface IDXCoreAdapterList */ 374 | MIDL_INTERFACE("526c7776-40e9-459b-b711-f32ad76dfc28") 375 | IDXCoreAdapterList : public IUnknown 376 | { 377 | public: 378 | virtual HRESULT STDMETHODCALLTYPE GetAdapter( 379 | uint32_t index, 380 | REFIID riid, 381 | _COM_Outptr_ void **ppvAdapter) = 0; 382 | 383 | template 384 | HRESULT STDMETHODCALLTYPE GetAdapter( 385 | uint32_t index, 386 | _COM_Outptr_ T **ppvAdapter) 387 | { 388 | return GetAdapter(index, 389 | IID_PPV_ARGS(ppvAdapter)); 390 | } 391 | 392 | virtual uint32_t STDMETHODCALLTYPE GetAdapterCount() = 0; 393 | 394 | virtual bool STDMETHODCALLTYPE IsStale() = 0; 395 | 396 | virtual HRESULT STDMETHODCALLTYPE GetFactory( 397 | REFIID riid, 398 | _COM_Outptr_ void** ppvFactory 399 | ) = 0; 400 | 401 | template 402 | HRESULT GetFactory( 403 | _COM_Outptr_ T** ppvFactory 404 | ) 405 | { 406 | return GetFactory(IID_PPV_ARGS(ppvFactory)); 407 | } 408 | 409 | virtual HRESULT STDMETHODCALLTYPE Sort( 410 | uint32_t numPreferences, 411 | _In_reads_(numPreferences) const DXCoreAdapterPreference* preferences) = 0; 412 | 413 | virtual bool STDMETHODCALLTYPE IsAdapterPreferenceSupported( 414 | DXCoreAdapterPreference preference) = 0; 415 | }; 416 | 417 | /* interface IDXCoreAdapterFactory */ 418 | MIDL_INTERFACE("78ee5945-c36e-4b13-a669-005dd11c0f06") 419 | IDXCoreAdapterFactory : public IUnknown 420 | { 421 | public: 422 | 423 | virtual HRESULT STDMETHODCALLTYPE CreateAdapterList( 424 | uint32_t numAttributes, 425 | _In_reads_(numAttributes) const GUID *filterAttributes, 426 | REFIID riid, 427 | _COM_Outptr_ void **ppvAdapterList) = 0; 428 | 429 | template 430 | HRESULT STDMETHODCALLTYPE CreateAdapterList( 431 | uint32_t numAttributes, 432 | _In_reads_(numAttributes) const GUID *filterAttributes, 433 | _COM_Outptr_ T **ppvAdapterList) 434 | { 435 | return CreateAdapterList(numAttributes, 436 | filterAttributes, 437 | IID_PPV_ARGS(ppvAdapterList)); 438 | } 439 | 440 | virtual HRESULT STDMETHODCALLTYPE GetAdapterByLuid( 441 | const LUID &adapterLUID, 442 | REFIID riid, 443 | _COM_Outptr_ void **ppvAdapter) = 0; 444 | 445 | template 446 | HRESULT STDMETHODCALLTYPE GetAdapterByLuid( 447 | const LUID &adapterLUID, 448 | _COM_Outptr_ T **ppvAdapter) 449 | { 450 | return GetAdapterByLuid(adapterLUID, 451 | IID_PPV_ARGS(ppvAdapter)); 452 | } 453 | 454 | virtual bool STDMETHODCALLTYPE IsNotificationTypeSupported( 455 | DXCoreNotificationType notificationType) = 0; 456 | 457 | virtual HRESULT STDMETHODCALLTYPE RegisterEventNotification( 458 | _In_ IUnknown *dxCoreObject, 459 | DXCoreNotificationType notificationType, 460 | _In_ PFN_DXCORE_NOTIFICATION_CALLBACK callbackFunction, 461 | _In_opt_ void *callbackContext, 462 | _Out_ uint32_t *eventCookie) = 0; 463 | 464 | virtual HRESULT STDMETHODCALLTYPE UnregisterEventNotification( 465 | uint32_t eventCookie) = 0; 466 | }; 467 | 468 | /* interface IDXCoreAdapterFactory1 */ 469 | MIDL_INTERFACE("d5682e19-6d21-401c-827a-9a51a4ea35d7") 470 | IDXCoreAdapterFactory1 : public IDXCoreAdapterFactory 471 | { 472 | public: 473 | virtual HRESULT STDMETHODCALLTYPE CreateAdapterListByWorkload( 474 | DXCoreWorkload workload, 475 | DXCoreRuntimeFilterFlags runtimeFilter, 476 | DXCoreHardwareTypeFilterFlags hardwareTypeFilter, 477 | REFIID riid, 478 | _COM_Outptr_ void **ppvAdapterList) = 0; 479 | 480 | template 481 | HRESULT STDMETHODCALLTYPE CreateAdapterListByWorkload( 482 | DXCoreWorkload workload, 483 | DXCoreRuntimeFilterFlags runtimeFilter, 484 | DXCoreHardwareTypeFilterFlags hardwareTypeFilter, 485 | _COM_Outptr_ T **ppvAdapterList) 486 | { 487 | return CreateAdapterListByWorkload(workload, 488 | runtimeFilter, 489 | hardwareTypeFilter, 490 | IID_PPV_ARGS(ppvAdapterList)); 491 | } 492 | }; 493 | 494 | #endif // __cplusplus 495 | 496 | #endif // __dxcore_interface_h__ 497 | 498 | -------------------------------------------------------------------------------- /include/directx/dxgicommon.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) Microsoft Corporation. 3 | // Licensed under the MIT license 4 | // 5 | 6 | #ifndef __dxgicommon_h__ 7 | #define __dxgicommon_h__ 8 | 9 | 10 | typedef struct DXGI_RATIONAL 11 | { 12 | UINT Numerator; 13 | UINT Denominator; 14 | } DXGI_RATIONAL; 15 | 16 | // The following values are used with DXGI_SAMPLE_DESC::Quality: 17 | #define DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN 0xffffffff 18 | #define DXGI_CENTER_MULTISAMPLE_QUALITY_PATTERN 0xfffffffe 19 | 20 | typedef struct DXGI_SAMPLE_DESC 21 | { 22 | UINT Count; 23 | UINT Quality; 24 | } DXGI_SAMPLE_DESC; 25 | 26 | typedef enum DXGI_COLOR_SPACE_TYPE 27 | { 28 | DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0, 29 | DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1, 30 | DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709 = 2, 31 | DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020 = 3, 32 | DXGI_COLOR_SPACE_RESERVED = 4, 33 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 = 5, 34 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 = 6, 35 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601 = 7, 36 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 = 8, 37 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709 = 9, 38 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 = 10, 39 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 = 11, 40 | DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 = 12, 41 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020 = 13, 42 | DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020 = 14, 43 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15, 44 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16, 45 | DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 = 17, 46 | DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18, 47 | DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19, 48 | DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 = 20, 49 | DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 = 21, 50 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 = 22, 51 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 = 23, 52 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24, 53 | DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF 54 | } DXGI_COLOR_SPACE_TYPE; 55 | 56 | #endif // __dxgicommon_h__ 57 | 58 | -------------------------------------------------------------------------------- /include/directx/dxgicommon.idl: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) Microsoft Corporation. 3 | // Licensed under the MIT license 4 | // 5 | 6 | import "ocidl.idl"; 7 | 8 | typedef struct DXGI_RATIONAL 9 | { 10 | UINT Numerator; 11 | UINT Denominator; 12 | } DXGI_RATIONAL; 13 | 14 | // The following values are used with DXGI_SAMPLE_DESC::Quality: 15 | #define DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN 0xffffffff 16 | #define DXGI_CENTER_MULTISAMPLE_QUALITY_PATTERN 0xfffffffe 17 | 18 | typedef struct DXGI_SAMPLE_DESC 19 | { 20 | UINT Count; 21 | UINT Quality; 22 | } DXGI_SAMPLE_DESC; 23 | 24 | typedef enum DXGI_COLOR_SPACE_TYPE 25 | { 26 | DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0, 27 | DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1, 28 | DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709 = 2, 29 | DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020 = 3, 30 | DXGI_COLOR_SPACE_RESERVED = 4, 31 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 = 5, 32 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 = 6, 33 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601 = 7, 34 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 = 8, 35 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709 = 9, 36 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 = 10, 37 | DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 = 11, 38 | DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 = 12, 39 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020 = 13, 40 | DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020 = 14, 41 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15, 42 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16, 43 | DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 = 17, 44 | DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18, 45 | DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19, 46 | DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 = 20, 47 | DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 = 21, 48 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 = 22, 49 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 = 23, 50 | DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24, 51 | DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF 52 | } DXGI_COLOR_SPACE_TYPE; 53 | 54 | -------------------------------------------------------------------------------- /include/directx/dxgiformat.h: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) Microsoft Corporation. 3 | // Licensed under the MIT license 4 | // 5 | 6 | #ifndef __dxgiformat_h__ 7 | #define __dxgiformat_h__ 8 | 9 | #define DXGI_FORMAT_DEFINED 1 10 | 11 | typedef enum DXGI_FORMAT 12 | { 13 | DXGI_FORMAT_UNKNOWN = 0, 14 | DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, 15 | DXGI_FORMAT_R32G32B32A32_FLOAT = 2, 16 | DXGI_FORMAT_R32G32B32A32_UINT = 3, 17 | DXGI_FORMAT_R32G32B32A32_SINT = 4, 18 | DXGI_FORMAT_R32G32B32_TYPELESS = 5, 19 | DXGI_FORMAT_R32G32B32_FLOAT = 6, 20 | DXGI_FORMAT_R32G32B32_UINT = 7, 21 | DXGI_FORMAT_R32G32B32_SINT = 8, 22 | DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, 23 | DXGI_FORMAT_R16G16B16A16_FLOAT = 10, 24 | DXGI_FORMAT_R16G16B16A16_UNORM = 11, 25 | DXGI_FORMAT_R16G16B16A16_UINT = 12, 26 | DXGI_FORMAT_R16G16B16A16_SNORM = 13, 27 | DXGI_FORMAT_R16G16B16A16_SINT = 14, 28 | DXGI_FORMAT_R32G32_TYPELESS = 15, 29 | DXGI_FORMAT_R32G32_FLOAT = 16, 30 | DXGI_FORMAT_R32G32_UINT = 17, 31 | DXGI_FORMAT_R32G32_SINT = 18, 32 | DXGI_FORMAT_R32G8X24_TYPELESS = 19, 33 | DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, 34 | DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, 35 | DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, 36 | DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, 37 | DXGI_FORMAT_R10G10B10A2_UNORM = 24, 38 | DXGI_FORMAT_R10G10B10A2_UINT = 25, 39 | DXGI_FORMAT_R11G11B10_FLOAT = 26, 40 | DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, 41 | DXGI_FORMAT_R8G8B8A8_UNORM = 28, 42 | DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, 43 | DXGI_FORMAT_R8G8B8A8_UINT = 30, 44 | DXGI_FORMAT_R8G8B8A8_SNORM = 31, 45 | DXGI_FORMAT_R8G8B8A8_SINT = 32, 46 | DXGI_FORMAT_R16G16_TYPELESS = 33, 47 | DXGI_FORMAT_R16G16_FLOAT = 34, 48 | DXGI_FORMAT_R16G16_UNORM = 35, 49 | DXGI_FORMAT_R16G16_UINT = 36, 50 | DXGI_FORMAT_R16G16_SNORM = 37, 51 | DXGI_FORMAT_R16G16_SINT = 38, 52 | DXGI_FORMAT_R32_TYPELESS = 39, 53 | DXGI_FORMAT_D32_FLOAT = 40, 54 | DXGI_FORMAT_R32_FLOAT = 41, 55 | DXGI_FORMAT_R32_UINT = 42, 56 | DXGI_FORMAT_R32_SINT = 43, 57 | DXGI_FORMAT_R24G8_TYPELESS = 44, 58 | DXGI_FORMAT_D24_UNORM_S8_UINT = 45, 59 | DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, 60 | DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, 61 | DXGI_FORMAT_R8G8_TYPELESS = 48, 62 | DXGI_FORMAT_R8G8_UNORM = 49, 63 | DXGI_FORMAT_R8G8_UINT = 50, 64 | DXGI_FORMAT_R8G8_SNORM = 51, 65 | DXGI_FORMAT_R8G8_SINT = 52, 66 | DXGI_FORMAT_R16_TYPELESS = 53, 67 | DXGI_FORMAT_R16_FLOAT = 54, 68 | DXGI_FORMAT_D16_UNORM = 55, 69 | DXGI_FORMAT_R16_UNORM = 56, 70 | DXGI_FORMAT_R16_UINT = 57, 71 | DXGI_FORMAT_R16_SNORM = 58, 72 | DXGI_FORMAT_R16_SINT = 59, 73 | DXGI_FORMAT_R8_TYPELESS = 60, 74 | DXGI_FORMAT_R8_UNORM = 61, 75 | DXGI_FORMAT_R8_UINT = 62, 76 | DXGI_FORMAT_R8_SNORM = 63, 77 | DXGI_FORMAT_R8_SINT = 64, 78 | DXGI_FORMAT_A8_UNORM = 65, 79 | DXGI_FORMAT_R1_UNORM = 66, 80 | DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, 81 | DXGI_FORMAT_R8G8_B8G8_UNORM = 68, 82 | DXGI_FORMAT_G8R8_G8B8_UNORM = 69, 83 | DXGI_FORMAT_BC1_TYPELESS = 70, 84 | DXGI_FORMAT_BC1_UNORM = 71, 85 | DXGI_FORMAT_BC1_UNORM_SRGB = 72, 86 | DXGI_FORMAT_BC2_TYPELESS = 73, 87 | DXGI_FORMAT_BC2_UNORM = 74, 88 | DXGI_FORMAT_BC2_UNORM_SRGB = 75, 89 | DXGI_FORMAT_BC3_TYPELESS = 76, 90 | DXGI_FORMAT_BC3_UNORM = 77, 91 | DXGI_FORMAT_BC3_UNORM_SRGB = 78, 92 | DXGI_FORMAT_BC4_TYPELESS = 79, 93 | DXGI_FORMAT_BC4_UNORM = 80, 94 | DXGI_FORMAT_BC4_SNORM = 81, 95 | DXGI_FORMAT_BC5_TYPELESS = 82, 96 | DXGI_FORMAT_BC5_UNORM = 83, 97 | DXGI_FORMAT_BC5_SNORM = 84, 98 | DXGI_FORMAT_B5G6R5_UNORM = 85, 99 | DXGI_FORMAT_B5G5R5A1_UNORM = 86, 100 | DXGI_FORMAT_B8G8R8A8_UNORM = 87, 101 | DXGI_FORMAT_B8G8R8X8_UNORM = 88, 102 | DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, 103 | DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, 104 | DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, 105 | DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, 106 | DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, 107 | DXGI_FORMAT_BC6H_TYPELESS = 94, 108 | DXGI_FORMAT_BC6H_UF16 = 95, 109 | DXGI_FORMAT_BC6H_SF16 = 96, 110 | DXGI_FORMAT_BC7_TYPELESS = 97, 111 | DXGI_FORMAT_BC7_UNORM = 98, 112 | DXGI_FORMAT_BC7_UNORM_SRGB = 99, 113 | DXGI_FORMAT_AYUV = 100, 114 | DXGI_FORMAT_Y410 = 101, 115 | DXGI_FORMAT_Y416 = 102, 116 | DXGI_FORMAT_NV12 = 103, 117 | DXGI_FORMAT_P010 = 104, 118 | DXGI_FORMAT_P016 = 105, 119 | DXGI_FORMAT_420_OPAQUE = 106, 120 | DXGI_FORMAT_YUY2 = 107, 121 | DXGI_FORMAT_Y210 = 108, 122 | DXGI_FORMAT_Y216 = 109, 123 | DXGI_FORMAT_NV11 = 110, 124 | DXGI_FORMAT_AI44 = 111, 125 | DXGI_FORMAT_IA44 = 112, 126 | DXGI_FORMAT_P8 = 113, 127 | DXGI_FORMAT_A8P8 = 114, 128 | DXGI_FORMAT_B4G4R4A4_UNORM = 115, 129 | 130 | DXGI_FORMAT_P208 = 130, 131 | DXGI_FORMAT_V208 = 131, 132 | DXGI_FORMAT_V408 = 132, 133 | 134 | 135 | DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189, 136 | DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190, 137 | 138 | DXGI_FORMAT_A4B4G4R4_UNORM = 191, 139 | 140 | 141 | DXGI_FORMAT_FORCE_UINT = 0xffffffff 142 | } DXGI_FORMAT; 143 | 144 | #endif // __dxgiformat_h__ 145 | -------------------------------------------------------------------------------- /include/directx/dxgiformat.idl: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) Microsoft Corporation. 3 | // Licensed under the MIT license 4 | // 5 | 6 | 7 | typedef enum DXGI_FORMAT 8 | { 9 | DXGI_FORMAT_UNKNOWN = 0, 10 | DXGI_FORMAT_R32G32B32A32_TYPELESS = 1, 11 | DXGI_FORMAT_R32G32B32A32_FLOAT = 2, 12 | DXGI_FORMAT_R32G32B32A32_UINT = 3, 13 | DXGI_FORMAT_R32G32B32A32_SINT = 4, 14 | DXGI_FORMAT_R32G32B32_TYPELESS = 5, 15 | DXGI_FORMAT_R32G32B32_FLOAT = 6, 16 | DXGI_FORMAT_R32G32B32_UINT = 7, 17 | DXGI_FORMAT_R32G32B32_SINT = 8, 18 | DXGI_FORMAT_R16G16B16A16_TYPELESS = 9, 19 | DXGI_FORMAT_R16G16B16A16_FLOAT = 10, 20 | DXGI_FORMAT_R16G16B16A16_UNORM = 11, 21 | DXGI_FORMAT_R16G16B16A16_UINT = 12, 22 | DXGI_FORMAT_R16G16B16A16_SNORM = 13, 23 | DXGI_FORMAT_R16G16B16A16_SINT = 14, 24 | DXGI_FORMAT_R32G32_TYPELESS = 15, 25 | DXGI_FORMAT_R32G32_FLOAT = 16, 26 | DXGI_FORMAT_R32G32_UINT = 17, 27 | DXGI_FORMAT_R32G32_SINT = 18, 28 | DXGI_FORMAT_R32G8X24_TYPELESS = 19, 29 | DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20, 30 | DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21, 31 | DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22, 32 | DXGI_FORMAT_R10G10B10A2_TYPELESS = 23, 33 | DXGI_FORMAT_R10G10B10A2_UNORM = 24, 34 | DXGI_FORMAT_R10G10B10A2_UINT = 25, 35 | DXGI_FORMAT_R11G11B10_FLOAT = 26, 36 | DXGI_FORMAT_R8G8B8A8_TYPELESS = 27, 37 | DXGI_FORMAT_R8G8B8A8_UNORM = 28, 38 | DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29, 39 | DXGI_FORMAT_R8G8B8A8_UINT = 30, 40 | DXGI_FORMAT_R8G8B8A8_SNORM = 31, 41 | DXGI_FORMAT_R8G8B8A8_SINT = 32, 42 | DXGI_FORMAT_R16G16_TYPELESS = 33, 43 | DXGI_FORMAT_R16G16_FLOAT = 34, 44 | DXGI_FORMAT_R16G16_UNORM = 35, 45 | DXGI_FORMAT_R16G16_UINT = 36, 46 | DXGI_FORMAT_R16G16_SNORM = 37, 47 | DXGI_FORMAT_R16G16_SINT = 38, 48 | DXGI_FORMAT_R32_TYPELESS = 39, 49 | DXGI_FORMAT_D32_FLOAT = 40, 50 | DXGI_FORMAT_R32_FLOAT = 41, 51 | DXGI_FORMAT_R32_UINT = 42, 52 | DXGI_FORMAT_R32_SINT = 43, 53 | DXGI_FORMAT_R24G8_TYPELESS = 44, 54 | DXGI_FORMAT_D24_UNORM_S8_UINT = 45, 55 | DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46, 56 | DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47, 57 | DXGI_FORMAT_R8G8_TYPELESS = 48, 58 | DXGI_FORMAT_R8G8_UNORM = 49, 59 | DXGI_FORMAT_R8G8_UINT = 50, 60 | DXGI_FORMAT_R8G8_SNORM = 51, 61 | DXGI_FORMAT_R8G8_SINT = 52, 62 | DXGI_FORMAT_R16_TYPELESS = 53, 63 | DXGI_FORMAT_R16_FLOAT = 54, 64 | DXGI_FORMAT_D16_UNORM = 55, 65 | DXGI_FORMAT_R16_UNORM = 56, 66 | DXGI_FORMAT_R16_UINT = 57, 67 | DXGI_FORMAT_R16_SNORM = 58, 68 | DXGI_FORMAT_R16_SINT = 59, 69 | DXGI_FORMAT_R8_TYPELESS = 60, 70 | DXGI_FORMAT_R8_UNORM = 61, 71 | DXGI_FORMAT_R8_UINT = 62, 72 | DXGI_FORMAT_R8_SNORM = 63, 73 | DXGI_FORMAT_R8_SINT = 64, 74 | DXGI_FORMAT_A8_UNORM = 65, 75 | DXGI_FORMAT_R1_UNORM = 66, 76 | DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67, 77 | DXGI_FORMAT_R8G8_B8G8_UNORM = 68, 78 | DXGI_FORMAT_G8R8_G8B8_UNORM = 69, 79 | DXGI_FORMAT_BC1_TYPELESS = 70, 80 | DXGI_FORMAT_BC1_UNORM = 71, 81 | DXGI_FORMAT_BC1_UNORM_SRGB = 72, 82 | DXGI_FORMAT_BC2_TYPELESS = 73, 83 | DXGI_FORMAT_BC2_UNORM = 74, 84 | DXGI_FORMAT_BC2_UNORM_SRGB = 75, 85 | DXGI_FORMAT_BC3_TYPELESS = 76, 86 | DXGI_FORMAT_BC3_UNORM = 77, 87 | DXGI_FORMAT_BC3_UNORM_SRGB = 78, 88 | DXGI_FORMAT_BC4_TYPELESS = 79, 89 | DXGI_FORMAT_BC4_UNORM = 80, 90 | DXGI_FORMAT_BC4_SNORM = 81, 91 | DXGI_FORMAT_BC5_TYPELESS = 82, 92 | DXGI_FORMAT_BC5_UNORM = 83, 93 | DXGI_FORMAT_BC5_SNORM = 84, 94 | DXGI_FORMAT_B5G6R5_UNORM = 85, 95 | DXGI_FORMAT_B5G5R5A1_UNORM = 86, 96 | DXGI_FORMAT_B8G8R8A8_UNORM = 87, 97 | DXGI_FORMAT_B8G8R8X8_UNORM = 88, 98 | DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89, 99 | DXGI_FORMAT_B8G8R8A8_TYPELESS = 90, 100 | DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91, 101 | DXGI_FORMAT_B8G8R8X8_TYPELESS = 92, 102 | DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93, 103 | DXGI_FORMAT_BC6H_TYPELESS = 94, 104 | DXGI_FORMAT_BC6H_UF16 = 95, 105 | DXGI_FORMAT_BC6H_SF16 = 96, 106 | DXGI_FORMAT_BC7_TYPELESS = 97, 107 | DXGI_FORMAT_BC7_UNORM = 98, 108 | DXGI_FORMAT_BC7_UNORM_SRGB = 99, 109 | DXGI_FORMAT_AYUV = 100, 110 | DXGI_FORMAT_Y410 = 101, 111 | DXGI_FORMAT_Y416 = 102, 112 | DXGI_FORMAT_NV12 = 103, 113 | DXGI_FORMAT_P010 = 104, 114 | DXGI_FORMAT_P016 = 105, 115 | DXGI_FORMAT_420_OPAQUE = 106, 116 | DXGI_FORMAT_YUY2 = 107, 117 | DXGI_FORMAT_Y210 = 108, 118 | DXGI_FORMAT_Y216 = 109, 119 | DXGI_FORMAT_NV11 = 110, 120 | DXGI_FORMAT_AI44 = 111, 121 | DXGI_FORMAT_IA44 = 112, 122 | DXGI_FORMAT_P8 = 113, 123 | DXGI_FORMAT_A8P8 = 114, 124 | DXGI_FORMAT_B4G4R4A4_UNORM = 115, 125 | 126 | DXGI_FORMAT_P208 = 130, 127 | DXGI_FORMAT_V208 = 131, 128 | DXGI_FORMAT_V408 = 132, 129 | 130 | 131 | DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189, 132 | DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190, 133 | 134 | DXGI_FORMAT_A4B4G4R4_UNORM = 191, 135 | 136 | 137 | DXGI_FORMAT_FORCE_UINT = 0xffffffff 138 | } DXGI_FORMAT; 139 | 140 | -------------------------------------------------------------------------------- /include/dxguids/dxguids.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #ifndef __cplusplus 7 | #error "This header requires C++" 8 | #endif 9 | 10 | constexpr inline bool ConstexprIsEqualGUID(REFGUID a, REFGUID b) 11 | { 12 | return a.Data1 == b.Data1 && 13 | a.Data2 == b.Data2 && 14 | a.Data3 == b.Data3 && 15 | a.Data4[0] == b.Data4[0] && 16 | a.Data4[1] == b.Data4[1] && 17 | a.Data4[2] == b.Data4[2] && 18 | a.Data4[3] == b.Data4[3] && 19 | a.Data4[4] == b.Data4[4] && 20 | a.Data4[5] == b.Data4[5] && 21 | a.Data4[6] == b.Data4[6] && 22 | a.Data4[7] == b.Data4[7]; 23 | } 24 | 25 | template GUID uuidof() = delete; 26 | template GUID uuidof(T*) { return uuidof(); } 27 | template GUID uuidof(T**) { return uuidof(); } 28 | template GUID uuidof(T&) { return uuidof(); } 29 | 30 | // Each COM interface (e.g. ID3D12Device) has a unique interface ID (IID) associated with it. With MSVC, the IID is defined 31 | // along with the interface declaration using compiler intrinsics (__declspec(uuid(...)); the IID can then be retrieved 32 | // using __uuidof. These intrinsics are not supported with all toolchains, so these helpers redefine IID values that can be 33 | // used with the various adapter COM helpers (ComPtr, IID_PPV_ARGS, etc.) for Linux. IIDs are stable and cannot change, but as 34 | // a precaution we statically assert the values are as expected when compiling for Windows. 35 | #if defined(_MSC_VER) 36 | #define _DXGUIDS_SUPPORT_STATIC_ASSERT_IID 37 | #elif defined(__CRT_UUID_DECL) 38 | /* match _mingw.h */ 39 | #if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L 40 | #define _DXGUIDS_SUPPORT_STATIC_ASSERT_IID 41 | #endif /* __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L */ 42 | #endif /* _MSC_VER */ 43 | 44 | #ifdef _DXGUIDS_SUPPORT_STATIC_ASSERT_IID 45 | #define _WINADAPTER_ASSERT_IID(InterfaceName) \ 46 | static_assert(ConstexprIsEqualGUID(uuidof(), __uuidof(InterfaceName)), "GUID definition mismatch: "#InterfaceName); 47 | #else 48 | #define _WINADAPTER_ASSERT_IID(InterfaceName) 49 | #endif 50 | 51 | #ifdef __CRT_UUID_DECL 52 | #define WINADAPTER_IID(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 53 | template <> constexpr GUID uuidof() \ 54 | { \ 55 | return { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \ 56 | } \ 57 | __CRT_UUID_DECL(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 58 | _WINADAPTER_ASSERT_IID(InterfaceName) 59 | #else 60 | #define WINADAPTER_IID(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 61 | template <> constexpr GUID uuidof() \ 62 | { \ 63 | return { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \ 64 | } \ 65 | _WINADAPTER_ASSERT_IID(InterfaceName) 66 | #endif /* defined(_WIN32) && defined(__MINGW32__) */ 67 | 68 | // Direct3D 69 | #ifdef __d3d12_h__ 70 | WINADAPTER_IID(ID3D12Object, 0xc4fec28f, 0x7966, 0x4e95, 0x9f, 0x94, 0xf4, 0x31, 0xcb, 0x56, 0xc3, 0xb8); 71 | WINADAPTER_IID(ID3D12DeviceChild, 0x905db94b, 0xa00c, 0x4140, 0x9d, 0xf5, 0x2b, 0x64, 0xca, 0x9e, 0xa3, 0x57); 72 | WINADAPTER_IID(ID3D12RootSignature, 0xc54a6b66, 0x72df, 0x4ee8, 0x8b, 0xe5, 0xa9, 0x46, 0xa1, 0x42, 0x92, 0x14); 73 | WINADAPTER_IID(ID3D12RootSignatureDeserializer, 0x34AB647B, 0x3CC8, 0x46AC, 0x84, 0x1B, 0xC0, 0x96, 0x56, 0x45, 0xC0, 0x46); 74 | WINADAPTER_IID(ID3D12VersionedRootSignatureDeserializer, 0x7F91CE67, 0x090C, 0x4BB7, 0xB7, 0x8E, 0xED, 0x8F, 0xF2, 0xE3, 0x1D, 0xA0); 75 | WINADAPTER_IID(ID3D12Pageable, 0x63ee58fb, 0x1268, 0x4835, 0x86, 0xda, 0xf0, 0x08, 0xce, 0x62, 0xf0, 0xd6); 76 | WINADAPTER_IID(ID3D12Heap, 0x6b3b2502, 0x6e51, 0x45b3, 0x90, 0xee, 0x98, 0x84, 0x26, 0x5e, 0x8d, 0xf3); 77 | WINADAPTER_IID(ID3D12Resource, 0x696442be, 0xa72e, 0x4059, 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad); 78 | WINADAPTER_IID(ID3D12CommandAllocator, 0x6102dee4, 0xaf59, 0x4b09, 0xb9, 0x99, 0xb4, 0x4d, 0x73, 0xf0, 0x9b, 0x24); 79 | WINADAPTER_IID(ID3D12Fence, 0x0a753dcf, 0xc4d8, 0x4b91, 0xad, 0xf6, 0xbe, 0x5a, 0x60, 0xd9, 0x5a, 0x76); 80 | WINADAPTER_IID(ID3D12Fence1, 0x433685fe, 0xe22b, 0x4ca0, 0xa8, 0xdb, 0xb5, 0xb4, 0xf4, 0xdd, 0x0e, 0x4a); 81 | WINADAPTER_IID(ID3D12PipelineState, 0x765a30f3, 0xf624, 0x4c6f, 0xa8, 0x28, 0xac, 0xe9, 0x48, 0x62, 0x24, 0x45); 82 | WINADAPTER_IID(ID3D12DescriptorHeap, 0x8efb471d, 0x616c, 0x4f49, 0x90, 0xf7, 0x12, 0x7b, 0xb7, 0x63, 0xfa, 0x51); 83 | WINADAPTER_IID(ID3D12QueryHeap, 0x0d9658ae, 0xed45, 0x469e, 0xa6, 0x1d, 0x97, 0x0e, 0xc5, 0x83, 0xca, 0xb4); 84 | WINADAPTER_IID(ID3D12CommandSignature, 0xc36a797c, 0xec80, 0x4f0a, 0x89, 0x85, 0xa7, 0xb2, 0x47, 0x50, 0x82, 0xd1); 85 | WINADAPTER_IID(ID3D12CommandList, 0x7116d91c, 0xe7e4, 0x47ce, 0xb8, 0xc6, 0xec, 0x81, 0x68, 0xf4, 0x37, 0xe5); 86 | WINADAPTER_IID(ID3D12GraphicsCommandList, 0x5b160d0f, 0xac1b, 0x4185, 0x8b, 0xa8, 0xb3, 0xae, 0x42, 0xa5, 0xa4, 0x55); 87 | WINADAPTER_IID(ID3D12GraphicsCommandList1, 0x553103fb, 0x1fe7, 0x4557, 0xbb, 0x38, 0x94, 0x6d, 0x7d, 0x0e, 0x7c, 0xa7); 88 | WINADAPTER_IID(ID3D12GraphicsCommandList2, 0x38C3E585, 0xFF17, 0x412C, 0x91, 0x50, 0x4F, 0xC6, 0xF9, 0xD7, 0x2A, 0x28); 89 | WINADAPTER_IID(ID3D12CommandQueue, 0x0ec870a6, 0x5d7e, 0x4c22, 0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed); 90 | WINADAPTER_IID(ID3D12Device, 0x189819f1, 0x1db6, 0x4b57, 0xbe, 0x54, 0x18, 0x21, 0x33, 0x9b, 0x85, 0xf7); 91 | WINADAPTER_IID(ID3D12PipelineLibrary, 0xc64226a8, 0x9201, 0x46af, 0xb4, 0xcc, 0x53, 0xfb, 0x9f, 0xf7, 0x41, 0x4f); 92 | WINADAPTER_IID(ID3D12PipelineLibrary1, 0x80eabf42, 0x2568, 0x4e5e, 0xbd, 0x82, 0xc3, 0x7f, 0x86, 0x96, 0x1d, 0xc3); 93 | WINADAPTER_IID(ID3D12Device1, 0x77acce80, 0x638e, 0x4e65, 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e); 94 | WINADAPTER_IID(ID3D12Device2, 0x30baa41e, 0xb15b, 0x475c, 0xa0, 0xbb, 0x1a, 0xf5, 0xc5, 0xb6, 0x43, 0x28); 95 | WINADAPTER_IID(ID3D12Device3, 0x81dadc15, 0x2bad, 0x4392, 0x93, 0xc5, 0x10, 0x13, 0x45, 0xc4, 0xaa, 0x98); 96 | WINADAPTER_IID(ID3D12ProtectedSession, 0xA1533D18, 0x0AC1, 0x4084, 0x85, 0xB9, 0x89, 0xA9, 0x61, 0x16, 0x80, 0x6B); 97 | WINADAPTER_IID(ID3D12ProtectedResourceSession, 0x6CD696F4, 0xF289, 0x40CC, 0x80, 0x91, 0x5A, 0x6C, 0x0A, 0x09, 0x9C, 0x3D); 98 | WINADAPTER_IID(ID3D12Device4, 0xe865df17, 0xa9ee, 0x46f9, 0xa4, 0x63, 0x30, 0x98, 0x31, 0x5a, 0xa2, 0xe5); 99 | WINADAPTER_IID(ID3D12LifetimeOwner, 0xe667af9f, 0xcd56, 0x4f46, 0x83, 0xce, 0x03, 0x2e, 0x59, 0x5d, 0x70, 0xa8); 100 | WINADAPTER_IID(ID3D12SwapChainAssistant, 0xf1df64b6, 0x57fd, 0x49cd, 0x88, 0x07, 0xc0, 0xeb, 0x88, 0xb4, 0x5c, 0x8f); 101 | WINADAPTER_IID(ID3D12LifetimeTracker, 0x3fd03d36, 0x4eb1, 0x424a, 0xa5, 0x82, 0x49, 0x4e, 0xcb, 0x8b, 0xa8, 0x13); 102 | WINADAPTER_IID(ID3D12StateObject, 0x47016943, 0xfca8, 0x4594, 0x93, 0xea, 0xaf, 0x25, 0x8b, 0x55, 0x34, 0x6d); 103 | WINADAPTER_IID(ID3D12StateObjectProperties, 0xde5fa827, 0x9bf9, 0x4f26, 0x89, 0xff, 0xd7, 0xf5, 0x6f, 0xde, 0x38, 0x60); 104 | WINADAPTER_IID(ID3D12Device5, 0x8b4f173b, 0x2fea, 0x4b80, 0x8f, 0x58, 0x43, 0x07, 0x19, 0x1a, 0xb9, 0x5d); 105 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedDataSettings, 0x82BC481C, 0x6B9B, 0x4030, 0xAE, 0xDB, 0x7E, 0xE3, 0xD1, 0xDF, 0x1E, 0x63); 106 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedDataSettings1, 0xDBD5AE51, 0x3317, 0x4F0A, 0xAD, 0xF9, 0x1D, 0x7C, 0xED, 0xCA, 0xAE, 0x0B); 107 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedDataSettings2, 0x61552388, 0x01ab, 0x4008, 0xa4, 0x36, 0x83, 0xdb, 0x18, 0x95, 0x66, 0xea); 108 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedData, 0x98931D33, 0x5AE8, 0x4791, 0xAA, 0x3C, 0x1A, 0x73, 0xA2, 0x93, 0x4E, 0x71); 109 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedData1, 0x9727A022, 0xCF1D, 0x4DDA, 0x9E, 0xBA, 0xEF, 0xFA, 0x65, 0x3F, 0xC5, 0x06); 110 | WINADAPTER_IID(ID3D12DeviceRemovedExtendedData2, 0x67FC5816, 0xE4CA, 0x4915, 0xBF, 0x18, 0x42, 0x54, 0x12, 0x72, 0xDA, 0x54); 111 | WINADAPTER_IID(ID3D12Device6, 0xc70b221b, 0x40e4, 0x4a17, 0x89, 0xaf, 0x02, 0x5a, 0x07, 0x27, 0xa6, 0xdc); 112 | WINADAPTER_IID(ID3D12ProtectedResourceSession1, 0xD6F12DD6, 0x76FB, 0x406E, 0x89, 0x61, 0x42, 0x96, 0xEE, 0xFC, 0x04, 0x09); 113 | WINADAPTER_IID(ID3D12Device7, 0x5c014b53, 0x68a1, 0x4b9b, 0x8b, 0xd1, 0xdd, 0x60, 0x46, 0xb9, 0x35, 0x8b); 114 | WINADAPTER_IID(ID3D12Device8, 0x9218E6BB, 0xF944, 0x4F7E, 0xA7, 0x5C, 0xB1, 0xB2, 0xC7, 0xB7, 0x01, 0xF3); 115 | WINADAPTER_IID(ID3D12Resource1, 0x9D5E227A, 0x4430, 0x4161, 0x88, 0xB3, 0x3E, 0xCA, 0x6B, 0xB1, 0x6E, 0x19); 116 | WINADAPTER_IID(ID3D12Resource2, 0xBE36EC3B, 0xEA85, 0x4AEB, 0xA4, 0x5A, 0xE9, 0xD7, 0x64, 0x04, 0xA4, 0x95); 117 | WINADAPTER_IID(ID3D12Heap1, 0x572F7389, 0x2168, 0x49E3, 0x96, 0x93, 0xD6, 0xDF, 0x58, 0x71, 0xBF, 0x6D); 118 | WINADAPTER_IID(ID3D12GraphicsCommandList3, 0x6FDA83A7, 0xB84C, 0x4E38, 0x9A, 0xC8, 0xC7, 0xBD, 0x22, 0x01, 0x6B, 0x3D); 119 | WINADAPTER_IID(ID3D12MetaCommand, 0xDBB84C27, 0x36CE, 0x4FC9, 0xB8, 0x01, 0xF0, 0x48, 0xC4, 0x6A, 0xC5, 0x70); 120 | WINADAPTER_IID(ID3D12GraphicsCommandList4, 0x8754318e, 0xd3a9, 0x4541, 0x98, 0xcf, 0x64, 0x5b, 0x50, 0xdc, 0x48, 0x74); 121 | WINADAPTER_IID(ID3D12ShaderCacheSession, 0x28e2495d, 0x0f64, 0x4ae4, 0xa6, 0xec, 0x12, 0x92, 0x55, 0xdc, 0x49, 0xa8); 122 | WINADAPTER_IID(ID3D12Device9, 0x4c80e962, 0xf032, 0x4f60, 0xbc, 0x9e, 0xeb, 0xc2, 0xcf, 0xa1, 0xd8, 0x3c); 123 | WINADAPTER_IID(ID3D12Device10, 0x517f8718, 0xaa66, 0x49f9, 0xb0, 0x2b, 0xa7, 0xab, 0x89, 0xc0, 0x60, 0x31); 124 | WINADAPTER_IID(ID3D12Device11, 0x5405c344, 0xd457, 0x444e, 0xb4, 0xdd, 0x23, 0x66, 0xe4, 0x5a, 0xee, 0x39); 125 | WINADAPTER_IID(ID3D12VirtualizationGuestDevice, 0xbc66d368, 0x7373, 0x4943, 0x87, 0x57, 0xfc, 0x87, 0xdc, 0x79, 0xe4, 0x76); 126 | WINADAPTER_IID(ID3D12Tools, 0x7071e1f0, 0xe84b, 0x4b33, 0x97, 0x4f, 0x12, 0xfa, 0x49, 0xde, 0x65, 0xc5); 127 | WINADAPTER_IID(ID3D12SDKConfiguration, 0xe9eb5314, 0x33aa, 0x42b2, 0xa7, 0x18, 0xd7, 0x7f, 0x58, 0xb1, 0xf1, 0xc7); 128 | WINADAPTER_IID(ID3D12SDKConfiguration1, 0x8aaf9303, 0xad25, 0x48b9, 0x9a, 0x57, 0xd9, 0xc3, 0x7e, 0x00, 0x9d, 0x9f); 129 | WINADAPTER_IID(ID3D12DeviceFactory, 0x61f307d3, 0xd34e, 0x4e7c, 0x83, 0x74, 0x3b, 0xa4, 0xde, 0x23, 0xcc, 0xcb); 130 | WINADAPTER_IID(ID3D12DeviceConfiguration, 0x78dbf87b, 0xf766, 0x422b, 0xa6, 0x1c, 0xc8, 0xc4, 0x46, 0xbd, 0xb9, 0xad); 131 | WINADAPTER_IID(ID3D12GraphicsCommandList5, 0x55050859, 0x4024, 0x474c, 0x87, 0xf5, 0x64, 0x72, 0xea, 0xee, 0x44, 0xea); 132 | WINADAPTER_IID(ID3D12GraphicsCommandList6, 0xc3827890, 0xe548, 0x4cfa, 0x96, 0xcf, 0x56, 0x89, 0xa9, 0x37, 0x0f, 0x80); 133 | WINADAPTER_IID(ID3D12GraphicsCommandList7, 0xdd171223, 0x8b61, 0x4769, 0x90, 0xe3, 0x16, 0x0c, 0xcd, 0xe4, 0xe2, 0xc1); 134 | WINADAPTER_IID(ID3D12GraphicsCommandList8, 0xee936ef9, 0x599d, 0x4d28, 0x93, 0x8e, 0x23, 0xc4, 0xad, 0x05, 0xce, 0x51); 135 | #endif 136 | 137 | // Direct3D Video 138 | #ifdef __d3d12video_h__ 139 | WINADAPTER_IID(ID3D12VideoDecoderHeap,0x0946B7C9,0xEBF6,0x4047,0xBB,0x73,0x86,0x83,0xE2,0x7D,0xBB,0x1F); 140 | WINADAPTER_IID(ID3D12VideoDevice,0x1F052807,0x0B46,0x4ACC,0x8A,0x89,0x36,0x4F,0x79,0x37,0x18,0xA4); 141 | WINADAPTER_IID(ID3D12VideoDecoder,0xC59B6BDC,0x7720,0x4074,0xA1,0x36,0x17,0xA1,0x56,0x03,0x74,0x70); 142 | WINADAPTER_IID(ID3D12VideoProcessor,0x304FDB32,0xBEDE,0x410A,0x85,0x45,0x94,0x3A,0xC6,0xA4,0x61,0x38); 143 | WINADAPTER_IID(ID3D12VideoDecodeCommandList,0x3B60536E,0xAD29,0x4E64,0xA2,0x69,0xF8,0x53,0x83,0x7E,0x5E,0x53); 144 | WINADAPTER_IID(ID3D12VideoProcessCommandList,0xAEB2543A,0x167F,0x4682,0xAC,0xC8,0xD1,0x59,0xED,0x4A,0x62,0x09); 145 | WINADAPTER_IID(ID3D12VideoDecodeCommandList1,0xD52F011B,0xB56E,0x453C,0xA0,0x5A,0xA7,0xF3,0x11,0xC8,0xF4,0x72); 146 | WINADAPTER_IID(ID3D12VideoProcessCommandList1,0x542C5C4D,0x7596,0x434F,0x8C,0x93,0x4E,0xFA,0x67,0x66,0xF2,0x67); 147 | WINADAPTER_IID(ID3D12VideoMotionEstimator,0x33FDAE0E,0x098B,0x428F,0x87,0xBB,0x34,0xB6,0x95,0xDE,0x08,0xF8); 148 | WINADAPTER_IID(ID3D12VideoMotionVectorHeap,0x5BE17987,0x743A,0x4061,0x83,0x4B,0x23,0xD2,0x2D,0xAE,0xA5,0x05); 149 | WINADAPTER_IID(ID3D12VideoDevice1,0x981611AD,0xA144,0x4C83,0x98,0x90,0xF3,0x0E,0x26,0xD6,0x58,0xAB); 150 | WINADAPTER_IID(ID3D12VideoEncodeCommandList,0x8455293A,0x0CBD,0x4831,0x9B,0x39,0xFB,0xDB,0xAB,0x72,0x47,0x23); 151 | WINADAPTER_IID(ID3D12VideoDecoder1,0x79A2E5FB,0xCCD2,0x469A,0x9F,0xDE,0x19,0x5D,0x10,0x95,0x1F,0x7E); 152 | WINADAPTER_IID(ID3D12VideoDecoderHeap1,0xDA1D98C5,0x539F,0x41B2,0xBF,0x6B,0x11,0x98,0xA0,0x3B,0x6D,0x26); 153 | WINADAPTER_IID(ID3D12VideoProcessor1,0xF3CFE615,0x553F,0x425C,0x86,0xD8,0xEE,0x8C,0x1B,0x1F,0xB0,0x1C); 154 | WINADAPTER_IID(ID3D12VideoExtensionCommand,0x554E41E8,0xAE8E,0x4A8C,0xB7,0xD2,0x5B,0x4F,0x27,0x4A,0x30,0xE4); 155 | WINADAPTER_IID(ID3D12VideoDevice2,0xF019AC49,0xF838,0x4A95,0x9B,0x17,0x57,0x94,0x37,0xC8,0xF5,0x13); 156 | WINADAPTER_IID(ID3D12VideoDecodeCommandList2,0x6e120880,0xc114,0x4153,0x80,0x36,0xd2,0x47,0x05,0x1e,0x17,0x29); 157 | WINADAPTER_IID(ID3D12VideoDecodeCommandList3,0x2aee8c37,0x9562,0x42da,0x8a,0xbf,0x61,0xef,0xeb,0x2e,0x45,0x13); 158 | WINADAPTER_IID(ID3D12VideoProcessCommandList2,0xdb525ae4,0x6ad6,0x473c,0xba,0xa7,0x59,0xb2,0xe3,0x70,0x82,0xe4); 159 | WINADAPTER_IID(ID3D12VideoProcessCommandList3,0x1a0a4ca4,0x9f08,0x40ce,0x95,0x58,0xb4,0x11,0xfd,0x26,0x66,0xff); 160 | WINADAPTER_IID(ID3D12VideoEncodeCommandList1,0x94971eca,0x2bdb,0x4769,0x88,0xcf,0x36,0x75,0xea,0x75,0x7e,0xbc); 161 | WINADAPTER_IID(ID3D12VideoEncoder,0x2E0D212D,0x8DF9,0x44A6,0xA7,0x70,0xBB,0x28,0x9B,0x18,0x27,0x37); 162 | WINADAPTER_IID(ID3D12VideoEncoderHeap,0x22B35D96,0x876A,0x44C0,0xB2,0x5E,0xFB,0x8C,0x9C,0x7F,0x1C,0x4A); 163 | WINADAPTER_IID(ID3D12VideoDevice3,0x4243ADB4,0x3A32,0x4666,0x97,0x3C,0x0C,0xCC,0x56,0x25,0xDC,0x44); 164 | WINADAPTER_IID(ID3D12VideoEncodeCommandList2,0x895491e2,0xe701,0x46a9,0x9a,0x1f,0x8d,0x34,0x80,0xed,0x86,0x7a); 165 | WINADAPTER_IID(ID3D12VideoEncodeCommandList3,0x7f027b22,0x1515,0x4e85,0xaa,0x0d,0x02,0x64,0x86,0x58,0x05,0x76); 166 | #endif 167 | 168 | #ifdef __d3d12sdklayers_h__ 169 | WINADAPTER_IID(ID3D12Debug, 0x344488b7, 0x6846, 0x474b, 0xb9, 0x89, 0xf0, 0x27, 0x44, 0x82, 0x45, 0xe0); 170 | WINADAPTER_IID(ID3D12Debug1, 0xaffaa4ca, 0x63fe, 0x4d8e, 0xb8, 0xad, 0x15, 0x90, 0x00, 0xaf, 0x43, 0x04); 171 | WINADAPTER_IID(ID3D12Debug2, 0x93a665c4, 0xa3b2, 0x4e5d, 0xb6, 0x92, 0xa2, 0x6a, 0xe1, 0x4e, 0x33, 0x74); 172 | WINADAPTER_IID(ID3D12Debug3, 0x5cf4e58f, 0xf671, 0x4ff1, 0xa5, 0x42, 0x36, 0x86, 0xe3, 0xd1, 0x53, 0xd1); 173 | WINADAPTER_IID(ID3D12Debug4, 0x014b816e, 0x9ec5, 0x4a2f, 0xa8, 0x45, 0xff, 0xbe, 0x44, 0x1c, 0xe1, 0x3a); 174 | WINADAPTER_IID(ID3D12Debug5, 0x548d6b12, 0x09fa, 0x40e0, 0x90, 0x69, 0x5d, 0xcd, 0x58, 0x9a, 0x52, 0xc9); 175 | WINADAPTER_IID(ID3D12Debug6, 0x82a816d6, 0x5d01, 0x4157, 0x97, 0xd0, 0x49, 0x75, 0x46, 0x3f, 0xd1, 0xed); 176 | WINADAPTER_IID(ID3D12DebugDevice1, 0xa9b71770, 0xd099, 0x4a65, 0xa6, 0x98, 0x3d, 0xee, 0x10, 0x02, 0x0f, 0x88); 177 | WINADAPTER_IID(ID3D12DebugDevice, 0x3febd6dd, 0x4973, 0x4787, 0x81, 0x94, 0xe4, 0x5f, 0x9e, 0x28, 0x92, 0x3e); 178 | WINADAPTER_IID(ID3D12DebugDevice2, 0x60eccbc1, 0x378d, 0x4df1, 0x89, 0x4c, 0xf8, 0xac, 0x5c, 0xe4, 0xd7, 0xdd); 179 | WINADAPTER_IID(ID3D12DebugCommandQueue, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3a); 180 | WINADAPTER_IID(ID3D12DebugCommandQueue1, 0x16be35a2, 0xbfd6, 0x49f2, 0xbc, 0xae, 0xea, 0xae, 0x4a, 0xff, 0x86, 0x2d); 181 | WINADAPTER_IID(ID3D12DebugCommandList1, 0x102ca951, 0x311b, 0x4b01, 0xb1, 0x1f, 0xec, 0xb8, 0x3e, 0x06, 0x1b, 0x37); 182 | WINADAPTER_IID(ID3D12DebugCommandList, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3f); 183 | WINADAPTER_IID(ID3D12DebugCommandList2, 0xaeb575cf, 0x4e06, 0x48be, 0xba, 0x3b, 0xc4, 0x50, 0xfc, 0x96, 0x65, 0x2e); 184 | WINADAPTER_IID(ID3D12DebugCommandList3, 0x197d5e15, 0x4d37, 0x4d34, 0xaf, 0x78, 0x72, 0x4c, 0xd7, 0x0f, 0xdb, 0x1f); 185 | WINADAPTER_IID(ID3D12SharingContract, 0x0adf7d52, 0x929c, 0x4e61, 0xad, 0xdb, 0xff, 0xed, 0x30, 0xde, 0x66, 0xef); 186 | WINADAPTER_IID(ID3D12InfoQueue, 0x0742a90b, 0xc387, 0x483f, 0xb9, 0x46, 0x30, 0xa7, 0xe4, 0xe6, 0x14, 0x58); 187 | WINADAPTER_IID(ID3D12InfoQueue1, 0x2852dd88, 0xb484, 0x4c0c, 0xb6, 0xb1, 0x67, 0x16, 0x85, 0x00, 0xe6, 0x00); 188 | #endif 189 | 190 | // DXCore 191 | #ifdef __dxcore_interface_h__ 192 | WINADAPTER_IID(IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06); 193 | WINADAPTER_IID(IDXCoreAdapterFactory1, 0xd5682e19, 0x6d21, 0x401c, 0x82, 0x7a, 0x9a, 0x51, 0xa4, 0xea, 0x35, 0xd7); 194 | WINADAPTER_IID(IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28); 195 | WINADAPTER_IID(IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e); 196 | WINADAPTER_IID(IDXCoreAdapter1, 0xa0783366, 0xcfa3, 0x43be, 0x9d, 0x79, 0x55, 0xb2, 0xda, 0x97, 0xc6, 0x3c); 197 | #endif 198 | -------------------------------------------------------------------------------- /include/wsl/stubs/basetsd.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | // These #defines prevent the idl-generated headers from trying to include 7 | // Windows.h from the SDK rather than this one. 8 | #define RPC_NO_WINDOWS_H 9 | #define COM_NO_WINDOWS_H 10 | 11 | // Allcaps type definitions 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | // Note: using fixed-width here to match Windows widths 18 | // Specifically this is different for 'long' vs 'LONG' 19 | typedef uint8_t UINT8; 20 | typedef int8_t INT8; 21 | typedef uint16_t UINT16; 22 | typedef int16_t INT16; 23 | typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL, WINBOOL; 24 | typedef int32_t INT32, INT, LONG; 25 | typedef uint64_t UINT64, ULONG_PTR; 26 | typedef int64_t INT64, LONG_PTR; 27 | typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID; 28 | typedef const void *LPCVOID; 29 | typedef size_t SIZE_T; 30 | typedef float FLOAT; 31 | typedef double DOUBLE; 32 | typedef unsigned char BYTE; 33 | typedef int HWND; 34 | typedef int PALETTEENTRY; 35 | typedef int HDC; 36 | typedef uint16_t WORD; 37 | typedef void* PVOID; 38 | typedef char BOOLEAN; 39 | typedef uint64_t ULONGLONG; 40 | typedef uint16_t USHORT, *PUSHORT; 41 | typedef int64_t LONGLONG, *PLONGLONG; 42 | typedef int64_t LONG_PTR, *PLONG_PTR; 43 | typedef int64_t LONG64, *PLONG64; 44 | typedef uint64_t ULONG64, *PULONG64; 45 | typedef wchar_t WCHAR, *PWSTR; 46 | typedef uint8_t UCHAR, *PUCHAR; 47 | typedef uint64_t ULONG_PTR, *PULONG_PTR; 48 | typedef uint64_t UINT_PTR, *PUINT_PTR; 49 | typedef int64_t INT_PTR, *PINT_PTR; 50 | 51 | // Note: WCHAR is not the same between Windows and Linux, to enable 52 | // string manipulation APIs to work with resulting strings. 53 | // APIs to D3D/DXCore will work on Linux wchars, but beware with 54 | // interactions directly with the Windows kernel. 55 | typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR; 56 | typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR; 57 | typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR; 58 | typedef const wchar_t *LPCWSTR, *PCWSTR; 59 | 60 | #undef LONG_MAX 61 | #define LONG_MAX INT_MAX 62 | #undef ULONG_MAX 63 | #define ULONG_MAX UINT_MAX 64 | 65 | // Misc defines 66 | #define MIDL_INTERFACE(x) interface 67 | #define __analysis_assume(x) 68 | #define TRUE 1u 69 | #define FALSE 0u 70 | #define DECLSPEC_UUID(x) 71 | #define DECLSPEC_NOVTABLE 72 | #define DECLSPEC_SELECTANY 73 | #ifdef __cplusplus 74 | #define EXTERN_C extern "C" 75 | #else 76 | #define EXTERN_C extern 77 | #endif 78 | #define APIENTRY 79 | #define OUT 80 | #define IN 81 | #define CONST const 82 | #define MAX_PATH 260 83 | #define GENERIC_ALL 0x10000000L 84 | #define C_ASSERT(expr) static_assert((expr)) 85 | #define _countof(a) (sizeof(a) / sizeof(*(a))) 86 | 87 | typedef struct tagRECTL 88 | { 89 | LONG left; 90 | LONG top; 91 | LONG right; 92 | LONG bottom; 93 | } RECTL; 94 | 95 | typedef struct tagPOINT 96 | { 97 | int x; 98 | int y; 99 | } POINT; 100 | 101 | typedef struct _GUID { 102 | uint32_t Data1; 103 | uint16_t Data2; 104 | uint16_t Data3; 105 | uint8_t Data4[ 8 ]; 106 | } GUID; 107 | 108 | #ifdef INITGUID 109 | #ifdef __cplusplus 110 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 111 | #else 112 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID DECLSPEC_SELECTANY name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } } 113 | #endif 114 | #else 115 | #define DEFINE_GUID(name,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) EXTERN_C const GUID name 116 | #endif 117 | 118 | typedef GUID IID; 119 | typedef GUID UUID; 120 | typedef GUID CLSID; 121 | #ifdef __cplusplus 122 | #define REFGUID const GUID & 123 | #define REFIID const IID & 124 | #define REFCLSID const IID & 125 | 126 | __inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2) 127 | { 128 | return ( 129 | ((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] && 130 | ((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] && 131 | ((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] && 132 | ((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]); 133 | } 134 | 135 | inline bool operator==(REFGUID guidOne, REFGUID guidOther) 136 | { 137 | return !!InlineIsEqualGUID(guidOne, guidOther); 138 | } 139 | 140 | inline bool operator!=(REFGUID guidOne, REFGUID guidOther) 141 | { 142 | return !(guidOne == guidOther); 143 | } 144 | 145 | #else 146 | #define REFGUID const GUID * 147 | #define REFIID const IID * 148 | #define REFCLSID const IID * 149 | #endif 150 | 151 | // SAL annotations 152 | #define _In_ 153 | #define _In_z_ 154 | #define _In_opt_ 155 | #define _In_opt_z_ 156 | #define _In_reads_(x) 157 | #define _In_reads_opt_(x) 158 | #define _In_reads_bytes_(x) 159 | #define _In_reads_bytes_opt_(x) 160 | #define _In_range_(x, y) 161 | #define _In_bytecount_(x) 162 | #define _Out_ 163 | #define _Out_opt_ 164 | #define _Outptr_ 165 | #define _Outptr_opt_result_z_ 166 | #define _Outptr_opt_result_bytebuffer_(x) 167 | #define _COM_Outptr_ 168 | #define _COM_Outptr_result_maybenull_ 169 | #define _COM_Outptr_opt_ 170 | #define _COM_Outptr_opt_result_maybenull_ 171 | #define _Out_writes_(x) 172 | #define _Out_writes_z_(x) 173 | #define _Out_writes_opt_(x) 174 | #define _Out_writes_all_(x) 175 | #define _Out_writes_all_opt_(x) 176 | #define _Out_writes_to_opt_(x, y) 177 | #define _Out_writes_bytes_(x) 178 | #define _Out_writes_bytes_all_(x) 179 | #define _Out_writes_bytes_all_opt_(x) 180 | #define _Out_writes_bytes_opt_(x) 181 | #define _Inout_ 182 | #define _Inout_opt_ 183 | #define _Inout_updates_(x) 184 | #define _Inout_updates_bytes_(x) 185 | #define _Field_size_(x) 186 | #define _Field_size_opt_(x) 187 | #define _Field_size_bytes_(x) 188 | #define _Field_size_full_(x) 189 | #define _Field_size_full_opt_(x) 190 | #define _Field_size_bytes_full_(x) 191 | #define _Field_size_bytes_full_opt_(x) 192 | #define _Field_size_bytes_part_(x, y) 193 | #define _Field_range_(x, y) 194 | #define _Field_z_ 195 | #define _Check_return_ 196 | #define _IRQL_requires_(x) 197 | #define _IRQL_requires_min_(x) 198 | #define _IRQL_requires_max_(x) 199 | #define _At_(x, y) 200 | #define _Always_(x) 201 | #define _Return_type_success_(x) 202 | #define _Translates_Win32_to_HRESULT_(x) 203 | #define _Maybenull_ 204 | #define _Outptr_result_maybenull_ 205 | #define _Outptr_result_nullonfailure_ 206 | #define _Analysis_assume_(x) 207 | #define _Success_(x) 208 | #define _In_count_(x) 209 | #define _In_opt_count_(x) 210 | #define _Use_decl_annotations_ 211 | #define _Null_terminated_ 212 | 213 | // Calling conventions 214 | #define __cdecl 215 | #define __stdcall 216 | #define STDMETHODCALLTYPE 217 | #define STDAPICALLTYPE 218 | #define STDAPI EXTERN_C HRESULT STDAPICALLTYPE 219 | #define WINAPI 220 | 221 | #define interface struct 222 | #if defined (__cplusplus) && !defined (CINTERFACE) 223 | #define STDMETHOD(method) virtual HRESULT STDMETHODCALLTYPE method 224 | #define STDMETHOD_(type, method) virtual type STDMETHODCALLTYPE method 225 | #define PURE = 0 226 | #define THIS_ 227 | #define THIS void 228 | #define DECLARE_INTERFACE(iface) interface DECLSPEC_NOVTABLE iface 229 | #define DECLARE_INTERFACE_(iface, baseiface) interface DECLSPEC_NOVTABLE iface : public baseiface 230 | 231 | interface IUnknown; 232 | extern "C++" 233 | { 234 | template void** IID_PPV_ARGS_Helper(T** pp) 235 | { 236 | (void)static_cast(*pp); 237 | return reinterpret_cast(pp); 238 | } 239 | } 240 | #define IID_PPV_ARGS(ppType) __uuidof (**(ppType)), IID_PPV_ARGS_Helper (ppType) 241 | #else 242 | #define STDMETHOD(method) HRESULT (STDMETHODCALLTYPE *method) 243 | #define STDMETHOD_(type, method) type (STDMETHODCALLTYPE *method) 244 | #define PURE 245 | #define THIS_ INTERFACE *This, 246 | #define THIS INTERFACE *This 247 | #ifdef CONST_VTABLE 248 | #define DECLARE_INTERFACE(iface) typedef interface iface { const struct iface##Vtbl *lpVtbl; } iface; typedef const struct iface##Vtbl iface##Vtbl; const struct iface##Vtbl 249 | #else 250 | #define DECLARE_INTERFACE(iface) typedef interface iface { struct iface##Vtbl *lpVtbl; } iface; typedef struct iface##Vtbl iface##Vtbl; struct iface##Vtbl 251 | #endif 252 | #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE (iface) 253 | #endif 254 | 255 | #define IFACEMETHOD(method) /*override*/ STDMETHOD (method) 256 | #define IFACEMETHOD_(type, method) /*override*/ STDMETHOD_(type, method) 257 | #ifndef BEGIN_INTERFACE 258 | #define BEGIN_INTERFACE 259 | #define END_INTERFACE 260 | #endif 261 | 262 | // Error codes 263 | typedef LONG HRESULT; 264 | #define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) 265 | #define FAILED(hr) (((HRESULT)(hr)) < 0) 266 | #define S_OK ((HRESULT)0L) 267 | #define S_FALSE ((HRESULT)1L) 268 | #define E_NOTIMPL ((HRESULT)0x80004001L) 269 | #define E_OUTOFMEMORY ((HRESULT)0x8007000EL) 270 | #define E_INVALIDARG ((HRESULT)0x80070057L) 271 | #define E_NOINTERFACE ((HRESULT)0x80004002L) 272 | #define E_POINTER ((HRESULT)0x80004003L) 273 | #define E_HANDLE ((HRESULT)0x80070006L) 274 | #define E_ABORT ((HRESULT)0x80004004L) 275 | #define E_FAIL ((HRESULT)0x80004005L) 276 | #define E_ACCESSDENIED ((HRESULT)0x80070005L) 277 | #define E_UNEXPECTED ((HRESULT)0x8000FFFFL) 278 | #define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L) 279 | #define DXGI_ERROR_NOT_FOUND ((HRESULT)0x887A0002L) 280 | #define DXGI_ERROR_MORE_DATA ((HRESULT)0x887A0003L) 281 | #define DXGI_ERROR_UNSUPPORTED ((HRESULT)0x887A0004L) 282 | #define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L) 283 | #define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L) 284 | #define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L) 285 | #define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L) 286 | #define DXGI_ERROR_SDK_COMPONENT_MISSING ((HRESULT)0x887A002DL) 287 | 288 | typedef struct _LUID 289 | { 290 | ULONG LowPart; 291 | LONG HighPart; 292 | } LUID; 293 | 294 | typedef struct _RECT 295 | { 296 | int left; 297 | int top; 298 | int right; 299 | int bottom; 300 | } RECT; 301 | 302 | typedef union _LARGE_INTEGER { 303 | struct { 304 | uint32_t LowPart; 305 | uint32_t HighPart; 306 | } u; 307 | int64_t QuadPart; 308 | } LARGE_INTEGER; 309 | typedef LARGE_INTEGER *PLARGE_INTEGER; 310 | 311 | typedef union _ULARGE_INTEGER { 312 | struct { 313 | uint32_t LowPart; 314 | uint32_t HighPart; 315 | } u; 316 | uint64_t QuadPart; 317 | } ULARGE_INTEGER; 318 | typedef ULARGE_INTEGER *PULARGE_INTEGER; 319 | 320 | #define DECLARE_HANDLE(name) \ 321 | struct name##__ { \ 322 | int unused; \ 323 | }; \ 324 | typedef struct name##__ *name 325 | 326 | typedef struct _SECURITY_ATTRIBUTES { 327 | DWORD nLength; 328 | LPVOID lpSecurityDescriptor; 329 | WINBOOL bInheritHandle; 330 | } SECURITY_ATTRIBUTES; 331 | 332 | struct STATSTG; 333 | 334 | #ifdef __cplusplus 335 | // ENUM_FLAG_OPERATORS 336 | // Define operator overloads to enable bit operations on enum values that are 337 | // used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these 338 | // operators on YOUR_TYPE. 339 | extern "C++" { 340 | template 341 | struct _ENUM_FLAG_INTEGER_FOR_SIZE; 342 | 343 | template <> 344 | struct _ENUM_FLAG_INTEGER_FOR_SIZE<1> 345 | { 346 | typedef int8_t type; 347 | }; 348 | 349 | template <> 350 | struct _ENUM_FLAG_INTEGER_FOR_SIZE<2> 351 | { 352 | typedef int16_t type; 353 | }; 354 | 355 | template <> 356 | struct _ENUM_FLAG_INTEGER_FOR_SIZE<4> 357 | { 358 | typedef int32_t type; 359 | }; 360 | 361 | template <> 362 | struct _ENUM_FLAG_INTEGER_FOR_SIZE<8> 363 | { 364 | typedef int64_t type; 365 | }; 366 | 367 | // used as an approximation of std::underlying_type 368 | template 369 | struct _ENUM_FLAG_SIZED_INTEGER 370 | { 371 | typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE::type type; 372 | }; 373 | 374 | } 375 | #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \ 376 | extern "C++" { \ 377 | inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) | ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 378 | inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 379 | inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) & ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 380 | inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 381 | inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER::type)a)); } \ 382 | inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 383 | inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER::type)b)); } \ 384 | } 385 | #else 386 | #define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) /* */ 387 | #endif 388 | 389 | // D3DX12 uses these 390 | #include 391 | #define HeapAlloc(heap, flags, size) malloc(size) 392 | #define HeapFree(heap, flags, ptr) free(ptr) 393 | 394 | #if defined(lint) 395 | // Note: lint -e530 says don't complain about uninitialized variables for 396 | // this variable. Error 527 has to do with unreachable code. 397 | // -restore restores checking to the -save state 398 | #define UNREFERENCED_PARAMETER(P) \ 399 | /*lint -save -e527 -e530 */ \ 400 | { \ 401 | (P) = (P); \ 402 | } \ 403 | /*lint -restore */ 404 | #else 405 | #define UNREFERENCED_PARAMETER(P) (P) 406 | #endif 407 | -------------------------------------------------------------------------------- /include/wsl/stubs/oaidl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub header to satisfy d3d12.h include 5 | #pragma once -------------------------------------------------------------------------------- /include/wsl/stubs/ocidl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub header to satisfy d3d12.h include 5 | #pragma once -------------------------------------------------------------------------------- /include/wsl/stubs/rpc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub header to satisfy d3d12.h include 5 | #pragma once -------------------------------------------------------------------------------- /include/wsl/stubs/rpcndr.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub header to satisfy d3d12.h include 5 | #pragma once 6 | 7 | #include "basetsd.h" 8 | 9 | #define __RPCNDR_H_VERSION__ 10 | 11 | #ifdef CONST_VTABLE 12 | #define CONST_VTBL const 13 | #else 14 | #define CONST_VTBL 15 | #endif 16 | 17 | /* Macros for __uuidof template-based emulation */ 18 | #if defined(__cplusplus) 19 | #if __cpp_constexpr >= 200704l && __cpp_inline_variables >= 201606L 20 | #define __wsl_stub_uuidof_use_constexpr 1 21 | #else 22 | #define __wsl_stub_uuidof_use_constexpr 0 23 | #endif 24 | #ifndef __GNUC__ 25 | #error "Only support for compilers that support for `GNU C++ extension`" 26 | #endif 27 | extern "C++" { 28 | #if __wsl_stub_uuidof_use_constexpr 29 | __extension__ template struct __wsl_stub_uuidof_s; 30 | __extension__ template constexpr const GUID &__wsl_stub_uuidof(); 31 | #else 32 | __extension__ template const GUID &__wsl_stub_uuidof(); 33 | #endif 34 | } 35 | 36 | #if __wsl_stub_uuidof_use_constexpr 37 | #define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 38 | extern "C++" \ 39 | { \ 40 | template <> \ 41 | struct __wsl_stub_uuidof_s \ 42 | { \ 43 | static constexpr IID __uuid_inst = { \ 44 | l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \ 45 | }; \ 46 | template <> \ 47 | constexpr const GUID &__wsl_stub_uuidof() \ 48 | { \ 49 | return __wsl_stub_uuidof_s::__uuid_inst; \ 50 | } \ 51 | template <> \ 52 | constexpr const GUID &__wsl_stub_uuidof() \ 53 | { \ 54 | return __wsl_stub_uuidof_s::__uuid_inst; \ 55 | } \ 56 | } 57 | #else 58 | #define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \ 59 | extern "C++" \ 60 | { \ 61 | template <> \ 62 | inline const GUID &__wsl_stub_uuidof() \ 63 | { \ 64 | static const IID __uuid_inst = { \ 65 | l, w1, w2, {b1, b2, b3, b4, b5, b6, b7, b8}}; \ 66 | return __uuid_inst; \ 67 | } \ 68 | template <> \ 69 | inline const GUID &__wsl_stub_uuidof() \ 70 | { \ 71 | return __wsl_stub_uuidof(); \ 72 | } \ 73 | } 74 | #endif 75 | #define __uuidof(type) __wsl_stub_uuidof<__typeof(type)>() 76 | #else 77 | #define __CRT_UUID_DECL(type, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) 78 | #endif 79 | -------------------------------------------------------------------------------- /include/wsl/stubs/unknwn.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "unknwnbase.h" 4 | -------------------------------------------------------------------------------- /include/wsl/stubs/unknwnbase.h: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------------------- 2 | * 3 | * Copyright (c) Microsoft Corporation 4 | * Licensed under the MIT license 5 | * 6 | *-------------------------------------------------------------------------------------*/ 7 | 8 | /* this ALWAYS GENERATED file contains the definitions for the interfaces */ 9 | 10 | /* File created by MIDL compiler version 8.01.0627 */ 11 | 12 | /* verify that the version is high enough to compile this file*/ 13 | #ifndef __REQUIRED_RPCNDR_H_VERSION__ 14 | #define __REQUIRED_RPCNDR_H_VERSION__ 500 15 | #endif 16 | 17 | /* verify that the version is high enough to compile this file*/ 18 | #ifndef __REQUIRED_RPCSAL_H_VERSION__ 19 | #define __REQUIRED_RPCSAL_H_VERSION__ 100 20 | #endif 21 | 22 | #include "rpc.h" 23 | #include "rpcndr.h" 24 | 25 | #ifndef __RPCNDR_H_VERSION__ 26 | #error this stub requires an updated version of 27 | #endif /* __RPCNDR_H_VERSION__ */ 28 | 29 | #ifndef COM_NO_WINDOWS_H 30 | #include "windows.h" 31 | #include "ole2.h" 32 | #endif /*COM_NO_WINDOWS_H*/ 33 | 34 | #ifndef __unknwnbase_h__ 35 | #define __unknwnbase_h__ 36 | 37 | #if defined(_MSC_VER) && (_MSC_VER >= 1020) 38 | #pragma once 39 | #endif 40 | 41 | /* Forward Declarations */ 42 | 43 | #ifndef __IUnknown_FWD_DEFINED__ 44 | #define __IUnknown_FWD_DEFINED__ 45 | typedef interface IUnknown IUnknown; 46 | 47 | #endif /* __IUnknown_FWD_DEFINED__ */ 48 | 49 | #ifndef __IUnknown_INTERFACE_DEFINED__ 50 | #define __IUnknown_INTERFACE_DEFINED__ 51 | 52 | /* interface IUnknown */ 53 | /* [unique][uuid][object][local] */ 54 | 55 | typedef /* [unique] */ IUnknown *LPUNKNOWN; 56 | 57 | EXTERN_C const IID IID_IUnknown; 58 | 59 | #if defined(__cplusplus) && !defined(CINTERFACE) 60 | extern "C++" 61 | { 62 | MIDL_INTERFACE("00000000-0000-0000-c000-000000000046") 63 | IUnknown 64 | { 65 | BEGIN_INTERFACE 66 | 67 | virtual HRESULT STDMETHODCALLTYPE QueryInterface( 68 | REFIID riid, 69 | void **ppvObject) = 0; 70 | 71 | virtual ULONG STDMETHODCALLTYPE AddRef() = 0; 72 | 73 | virtual ULONG STDMETHODCALLTYPE Release() = 0; 74 | 75 | template 76 | HRESULT 77 | STDMETHODCALLTYPE 78 | QueryInterface(_COM_Outptr_ Q * *pp) 79 | { 80 | return QueryInterface(__uuidof(Q), (void **)pp); 81 | } 82 | END_INTERFACE 83 | }; 84 | } 85 | #ifdef __CRT_UUID_DECL 86 | __CRT_UUID_DECL(IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46) 87 | #endif 88 | #else 89 | typedef struct IUnknownVtbl { 90 | BEGIN_INTERFACE 91 | 92 | /*** IUnknown methods ***/ 93 | HRESULT (STDMETHODCALLTYPE *QueryInterface)( 94 | IUnknown *This, 95 | REFIID riid, 96 | void **ppvObject); 97 | 98 | ULONG (STDMETHODCALLTYPE *AddRef)( 99 | IUnknown *This); 100 | 101 | ULONG (STDMETHODCALLTYPE *Release)( 102 | IUnknown *This); 103 | 104 | END_INTERFACE 105 | } IUnknownVtbl; 106 | 107 | interface IUnknown { 108 | CONST_VTBL IUnknownVtbl* lpVtbl; 109 | }; 110 | 111 | #ifdef COBJMACROS 112 | /*** IUnknown methods ***/ 113 | #define IUnknown_QueryInterface(This,riid,ppvObject) (This)->lpVtbl->QueryInterface(This,riid,ppvObject) 114 | #define IUnknown_AddRef(This) (This)->lpVtbl->AddRef(This) 115 | #define IUnknown_Release(This) (This)->lpVtbl->Release(This) 116 | #endif 117 | 118 | #endif 119 | 120 | #endif /* __IUnknown_INTERFACE_DEFINED__ */ 121 | 122 | DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xc0,0x00, 0x00,0x00,0x00,0x00,0x00,0x46); 123 | 124 | #endif /* __unknwnbase_h__ */ 125 | -------------------------------------------------------------------------------- /include/wsl/stubs/winapifamily.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub header to satisfy d3d12.h include. Unconditionally light up all APIs. 5 | #pragma once 6 | #define WINAPI_FAMILY_PARTITION(Partitions) 1 -------------------------------------------------------------------------------- /include/wsl/stubs/wrl/client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub to satisfy d3dx12.h include 5 | #pragma once 6 | #include -------------------------------------------------------------------------------- /include/wsl/stubs/wrl/implements.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // Stub to satisfy DML TF runtime includes 5 | #pragma once 6 | #include -------------------------------------------------------------------------------- /include/wsl/winadapter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /include/wsl/wrladapter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #pragma once 5 | 6 | #include "winadapter.h" 7 | 8 | // defined by winadapter.h and needed by some windows headers, but conflicts 9 | // with some libc++ implementation headers 10 | #ifdef __in 11 | #undef __in 12 | #endif 13 | #ifdef __out 14 | #undef __out 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | namespace Microsoft 25 | { 26 | namespace WRL 27 | { 28 | namespace Details 29 | { 30 | struct BoolStruct { int Member; }; 31 | typedef int BoolStruct::* BoolType; 32 | 33 | template // T should be the ComPtr or a derived type of it, not just the interface 34 | class ComPtrRefBase 35 | { 36 | public: 37 | typedef typename T::InterfaceType InterfaceType; 38 | 39 | operator IUnknown**() const throw() 40 | { 41 | static_assert(__is_base_of(IUnknown, InterfaceType), "Invalid cast: InterfaceType does not derive from IUnknown"); 42 | return reinterpret_cast(ptr_->ReleaseAndGetAddressOf()); 43 | } 44 | 45 | protected: 46 | T* ptr_; 47 | }; 48 | 49 | template 50 | class ComPtrRef : public Details::ComPtrRefBase // T should be the ComPtr or a derived type of it, not just the interface 51 | { 52 | using Super = Details::ComPtrRefBase; 53 | using InterfaceType = typename Super::InterfaceType; 54 | public: 55 | ComPtrRef(_In_opt_ T* ptr) throw() 56 | { 57 | this->ptr_ = ptr; 58 | } 59 | 60 | // Conversion operators 61 | operator void**() const throw() 62 | { 63 | return reinterpret_cast(this->ptr_->ReleaseAndGetAddressOf()); 64 | } 65 | 66 | // This is our operator ComPtr (or the latest derived class from ComPtr (e.g. WeakRef)) 67 | operator T*() throw() 68 | { 69 | *this->ptr_ = nullptr; 70 | return this->ptr_; 71 | } 72 | 73 | // We define operator InterfaceType**() here instead of on ComPtrRefBase, since 74 | // if InterfaceType is IUnknown or IInspectable, having it on the base will collide. 75 | operator InterfaceType**() throw() 76 | { 77 | return this->ptr_->ReleaseAndGetAddressOf(); 78 | } 79 | 80 | // This is used for IID_PPV_ARGS in order to do __uuidof(**(ppType)). 81 | // It does not need to clear ptr_ at this point, it is done at IID_PPV_ARGS_Helper(ComPtrRef&) later in this file. 82 | InterfaceType* operator *() throw() 83 | { 84 | return this->ptr_->Get(); 85 | } 86 | 87 | // Explicit functions 88 | InterfaceType* const * GetAddressOf() const throw() 89 | { 90 | return this->ptr_->GetAddressOf(); 91 | } 92 | 93 | InterfaceType** ReleaseAndGetAddressOf() throw() 94 | { 95 | return this->ptr_->ReleaseAndGetAddressOf(); 96 | } 97 | }; 98 | } 99 | 100 | template 101 | class ComPtr 102 | { 103 | public: 104 | typedef T InterfaceType; 105 | 106 | protected: 107 | InterfaceType *ptr_; 108 | template friend class ComPtr; 109 | 110 | void InternalAddRef() const throw() 111 | { 112 | if (ptr_ != nullptr) 113 | { 114 | ptr_->AddRef(); 115 | } 116 | } 117 | 118 | unsigned long InternalRelease() throw() 119 | { 120 | unsigned long ref = 0; 121 | T* temp = ptr_; 122 | 123 | if (temp != nullptr) 124 | { 125 | ptr_ = nullptr; 126 | ref = temp->Release(); 127 | } 128 | 129 | return ref; 130 | } 131 | 132 | public: 133 | ComPtr() throw() : ptr_(nullptr) 134 | { 135 | } 136 | 137 | ComPtr(decltype(nullptr)) throw() : ptr_(nullptr) 138 | { 139 | } 140 | 141 | template 142 | ComPtr(_In_opt_ U *other) throw() : ptr_(other) 143 | { 144 | InternalAddRef(); 145 | } 146 | 147 | ComPtr(const ComPtr& other) throw() : ptr_(other.ptr_) 148 | { 149 | InternalAddRef(); 150 | } 151 | 152 | // copy constructor that allows to instantiate class when U* is convertible to T* 153 | template 154 | ComPtr(const ComPtr &other, typename std::enable_if::value, void *>::type * = 0) throw() : 155 | ptr_(other.ptr_) 156 | { 157 | InternalAddRef(); 158 | } 159 | 160 | ComPtr(_Inout_ ComPtr &&other) throw() : ptr_(nullptr) 161 | { 162 | if (this != reinterpret_cast(&reinterpret_cast(other))) 163 | { 164 | Swap(other); 165 | } 166 | } 167 | 168 | // Move constructor that allows instantiation of a class when U* is convertible to T* 169 | template 170 | ComPtr(_Inout_ ComPtr&& other, typename std::enable_if::value, void *>::type * = 0) throw() : 171 | ptr_(other.ptr_) 172 | { 173 | other.ptr_ = nullptr; 174 | } 175 | 176 | ~ComPtr() throw() 177 | { 178 | InternalRelease(); 179 | } 180 | 181 | ComPtr& operator=(decltype(nullptr)) throw() 182 | { 183 | InternalRelease(); 184 | return *this; 185 | } 186 | 187 | ComPtr& operator=(_In_opt_ T *other) throw() 188 | { 189 | if (ptr_ != other) 190 | { 191 | ComPtr(other).Swap(*this); 192 | } 193 | return *this; 194 | } 195 | 196 | template 197 | ComPtr& operator=(_In_opt_ U *other) throw() 198 | { 199 | ComPtr(other).Swap(*this); 200 | return *this; 201 | } 202 | 203 | ComPtr& operator=(const ComPtr &other) throw() 204 | { 205 | if (ptr_ != other.ptr_) 206 | { 207 | ComPtr(other).Swap(*this); 208 | } 209 | return *this; 210 | } 211 | 212 | template 213 | ComPtr& operator=(const ComPtr& other) throw() 214 | { 215 | ComPtr(other).Swap(*this); 216 | return *this; 217 | } 218 | 219 | ComPtr& operator=(_Inout_ ComPtr &&other) throw() 220 | { 221 | ComPtr(static_cast(other)).Swap(*this); 222 | return *this; 223 | } 224 | 225 | template 226 | ComPtr& operator=(_Inout_ ComPtr&& other) throw() 227 | { 228 | ComPtr(static_cast&&>(other)).Swap(*this); 229 | return *this; 230 | } 231 | 232 | void Swap(_Inout_ ComPtr&& r) throw() 233 | { 234 | T* tmp = ptr_; 235 | ptr_ = r.ptr_; 236 | r.ptr_ = tmp; 237 | } 238 | 239 | void Swap(_Inout_ ComPtr& r) throw() 240 | { 241 | T* tmp = ptr_; 242 | ptr_ = r.ptr_; 243 | r.ptr_ = tmp; 244 | } 245 | 246 | operator Details::BoolType() const throw() 247 | { 248 | return Get() != nullptr ? &Details::BoolStruct::Member : nullptr; 249 | } 250 | 251 | T* Get() const throw() 252 | { 253 | return ptr_; 254 | } 255 | 256 | InterfaceType* operator->() const throw() 257 | { 258 | return ptr_; 259 | } 260 | 261 | Details::ComPtrRef> operator&() throw() 262 | { 263 | return Details::ComPtrRef>(this); 264 | } 265 | 266 | const Details::ComPtrRef> operator&() const throw() 267 | { 268 | return Details::ComPtrRef>(this); 269 | } 270 | 271 | T* const* GetAddressOf() const throw() 272 | { 273 | return &ptr_; 274 | } 275 | 276 | T** GetAddressOf() throw() 277 | { 278 | return &ptr_; 279 | } 280 | 281 | T** ReleaseAndGetAddressOf() throw() 282 | { 283 | InternalRelease(); 284 | return &ptr_; 285 | } 286 | 287 | T* Detach() throw() 288 | { 289 | T* ptr = ptr_; 290 | ptr_ = nullptr; 291 | return ptr; 292 | } 293 | 294 | void Attach(_In_opt_ InterfaceType* other) throw() 295 | { 296 | if (ptr_ != nullptr) 297 | { 298 | auto ref = ptr_->Release(); 299 | // DBG_UNREFERENCED_LOCAL_VARIABLE(ref); 300 | // Attaching to the same object only works if duplicate references are being coalesced. Otherwise 301 | // re-attaching will cause the pointer to be released and may cause a crash on a subsequent dereference. 302 | assert(ref != 0 || ptr_ != other); 303 | } 304 | 305 | ptr_ = other; 306 | } 307 | 308 | unsigned long Reset() 309 | { 310 | return InternalRelease(); 311 | } 312 | 313 | // Previously, unsafe behavior could be triggered when 'this' is ComPtr or ComPtr and CopyTo is used to copy to another type U. 314 | // The user will use operator& to convert the destination into a ComPtrRef, which can then implicit cast to IInspectable** and IUnknown**. 315 | // If this overload of CopyTo is not present, it will implicitly cast to IInspectable or IUnknown and match CopyTo(InterfaceType**) instead. 316 | // A valid polymoprhic downcast requires run-time type checking via QueryInterface, so CopyTo(InterfaceType**) will break type safety. 317 | // This overload matches ComPtrRef before the implicit cast takes place, preventing the unsafe downcast. 318 | template 319 | HRESULT CopyTo(Details::ComPtrRef> ptr, typename std::enable_if< 320 | (std::is_same::value) 321 | && !std::is_same::value, void *>::type * = 0) const throw() 322 | { 323 | return ptr_->QueryInterface(__uuidof(U), ptr); 324 | } 325 | 326 | HRESULT CopyTo(_Outptr_result_maybenull_ InterfaceType** ptr) const throw() 327 | { 328 | InternalAddRef(); 329 | *ptr = ptr_; 330 | return S_OK; 331 | } 332 | 333 | HRESULT CopyTo(REFIID riid, _Outptr_result_nullonfailure_ void** ptr) const throw() 334 | { 335 | return ptr_->QueryInterface(riid, ptr); 336 | } 337 | 338 | template 339 | HRESULT CopyTo(_Outptr_result_nullonfailure_ U** ptr) const throw() 340 | { 341 | return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(ptr)); 342 | } 343 | 344 | // query for U interface 345 | template 346 | HRESULT As(_Inout_ Details::ComPtrRef> p) const throw() 347 | { 348 | return ptr_->QueryInterface(__uuidof(U), p); 349 | } 350 | 351 | // query for U interface 352 | template 353 | HRESULT As(_Out_ ComPtr* p) const throw() 354 | { 355 | return ptr_->QueryInterface(__uuidof(U), reinterpret_cast(p->ReleaseAndGetAddressOf())); 356 | } 357 | 358 | // query for riid interface and return as IUnknown 359 | HRESULT AsIID(REFIID riid, _Out_ ComPtr* p) const throw() 360 | { 361 | return ptr_->QueryInterface(riid, reinterpret_cast(p->ReleaseAndGetAddressOf())); 362 | } 363 | 364 | }; // ComPtr 365 | 366 | 367 | namespace Details 368 | { 369 | // Empty struct used as default template parameter 370 | class Nil 371 | { 372 | }; 373 | 374 | // Empty struct used for validating template parameter types in Implements 375 | struct ImplementsBase 376 | { 377 | }; 378 | 379 | class RuntimeClassBase 380 | { 381 | protected: 382 | template 383 | static HRESULT AsIID(_In_ T* implements, REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject) noexcept 384 | { 385 | *ppvObject = nullptr; 386 | bool isRefDelegated = false; 387 | // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. 388 | if (InlineIsEqualGUID(riid, __uuidof(IUnknown))) 389 | { 390 | *ppvObject = implements->CastToUnknown(); 391 | static_cast(*ppvObject)->AddRef(); 392 | return S_OK; 393 | } 394 | 395 | HRESULT hr = implements->CanCastTo(riid, ppvObject, &isRefDelegated); 396 | if (SUCCEEDED(hr) && !isRefDelegated) 397 | { 398 | static_cast(*ppvObject)->AddRef(); 399 | } 400 | 401 | #ifdef _MSC_VER 402 | #pragma warning(push) 403 | #pragma warning(disable: 6102) // '*ppvObject' is used but may not be initialized 404 | #endif 405 | _Analysis_assume_(SUCCEEDED(hr) || (*ppvObject == nullptr)); 406 | #ifdef _MSC_VER 407 | #pragma warning(pop) 408 | #endif 409 | return hr; 410 | } 411 | 412 | public: 413 | HRESULT RuntimeClassInitialize() noexcept 414 | { 415 | return S_OK; 416 | } 417 | }; 418 | 419 | // Interface traits provides casting and filling iids methods helpers 420 | template 421 | struct InterfaceTraits 422 | { 423 | typedef I0 Base; 424 | 425 | template 426 | static Base* CastToBase(_In_ T* ptr) noexcept 427 | { 428 | return static_cast(ptr); 429 | } 430 | 431 | template 432 | static IUnknown* CastToUnknown(_In_ T* ptr) noexcept 433 | { 434 | return static_cast(static_cast(ptr)); 435 | } 436 | 437 | template 438 | _Success_(return == true) 439 | static bool CanCastTo(_In_ T* ptr, REFIID riid, _Outptr_ void **ppv) noexcept 440 | { 441 | // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. 442 | if (InlineIsEqualGUID(riid, __uuidof(Base))) 443 | { 444 | *ppv = static_cast(ptr); 445 | return true; 446 | } 447 | 448 | return false; 449 | } 450 | }; 451 | 452 | // Specialization for Nil parameter 453 | template<> 454 | struct InterfaceTraits 455 | { 456 | typedef Nil Base; 457 | 458 | template 459 | _Success_(return == true) 460 | static bool CanCastTo(_In_ T*, REFIID, _Outptr_ void **) noexcept 461 | { 462 | return false; 463 | } 464 | }; 465 | 466 | // ChainInterfaces - template allows specifying a derived COM interface along with its class hierarchy to allow QI for the base interfaces 467 | template 470 | struct ChainInterfaces : I0 471 | { 472 | protected: 473 | HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) throw() 474 | { 475 | typename InterfaceTraits::Base* ptr = InterfaceTraits::CastToBase(this); 476 | 477 | return (InterfaceTraits::CanCastTo(this, riid, ppv) || 478 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 479 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 480 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 481 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 482 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 483 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 484 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 485 | InterfaceTraits::CanCastTo(ptr, riid, ppv) || 486 | InterfaceTraits::CanCastTo(ptr, riid, ppv)) ? S_OK : E_NOINTERFACE; 487 | } 488 | 489 | IUnknown* CastToUnknown() throw() 490 | { 491 | return InterfaceTraits::CastToUnknown(this); 492 | } 493 | }; 494 | 495 | // Helper template used by Implements. This template traverses a list of interfaces and adds them as base class and information 496 | // to enable QI. 497 | template 498 | struct ImplementsHelper; 499 | 500 | template 501 | struct ImplementsMarker 502 | {}; 503 | 504 | template 505 | struct MarkImplements; 506 | 507 | template 508 | struct MarkImplements 509 | { 510 | typedef I0 Type; 511 | }; 512 | 513 | template 514 | struct MarkImplements 515 | { 516 | typedef ImplementsMarker Type; 517 | }; 518 | 519 | // AdjustImplements pre-processes the type list for more efficient builds. 520 | template 521 | struct AdjustImplements; 522 | 523 | template 524 | struct AdjustImplements 525 | { 526 | typedef ImplementsHelper::value>::Type, Bases...> Type; 527 | }; 528 | 529 | // Use AdjustImplements to remove instances of "Nil" from the type list. 530 | template 531 | struct AdjustImplements 532 | { 533 | typedef typename AdjustImplements::Type Type; 534 | }; 535 | 536 | template <> 537 | struct AdjustImplements<> 538 | { 539 | typedef ImplementsHelper<> Type; 540 | }; 541 | 542 | // Specialization handles unadorned interfaces 543 | template 544 | struct ImplementsHelper : 545 | I0, 546 | AdjustImplements::Type 547 | { 548 | template friend struct ImplementsHelper; 549 | friend class RuntimeClassBase; 550 | 551 | protected: 552 | 553 | HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept 554 | { 555 | // Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case. 556 | if (InlineIsEqualGUID(riid, __uuidof(I0))) 557 | { 558 | *ppv = reinterpret_cast(reinterpret_cast(this)); 559 | return S_OK; 560 | } 561 | return AdjustImplements::Type::CanCastTo(riid, ppv, pRefDelegated); 562 | } 563 | 564 | IUnknown* CastToUnknown() noexcept 565 | { 566 | return reinterpret_cast(reinterpret_cast(this)); 567 | } 568 | }; 569 | 570 | 571 | // Selector is used to "tag" base interfaces to be used in casting, since a runtime class may indirectly derive from 572 | // the same interface or Implements<> template multiple times 573 | template 574 | struct Selector : public base 575 | { 576 | }; 577 | 578 | // Specialization handles types that derive from ImplementsHelper (e.g. nested Implements). 579 | template 580 | struct ImplementsHelper, TInterfaces...> : 581 | Selector, TInterfaces...>>, 582 | Selector::Type, ImplementsHelper, TInterfaces...>> 583 | { 584 | template friend struct ImplementsHelper; 585 | friend class RuntimeClassBase; 586 | 587 | protected: 588 | typedef Selector, TInterfaces...>> CurrentType; 589 | typedef Selector::Type, ImplementsHelper, TInterfaces...>> BaseType; 590 | 591 | HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept 592 | { 593 | HRESULT hr = CurrentType::CanCastTo(riid, ppv); 594 | if (hr == E_NOINTERFACE) 595 | { 596 | hr = BaseType::CanCastTo(riid, ppv, pRefDelegated); 597 | } 598 | return hr; 599 | } 600 | 601 | IUnknown* CastToUnknown() noexcept 602 | { 603 | // First in list wins. 604 | return CurrentType::CastToUnknown(); 605 | } 606 | }; 607 | 608 | // terminal case specialization. 609 | template <> 610 | struct ImplementsHelper<> 611 | { 612 | template friend struct ImplementsHelper; 613 | friend class RuntimeClassBase; 614 | 615 | protected: 616 | HRESULT CanCastTo(_In_ REFIID /*riid*/, _Outptr_ void ** /*ppv*/, bool * /*pRefDelegated*/ = nullptr) noexcept 617 | { 618 | return E_NOINTERFACE; 619 | } 620 | 621 | // IUnknown* CastToUnknown() noexcept; // not defined for terminal case. 622 | }; 623 | 624 | // Specialization handles chaining interfaces 625 | template 626 | struct ImplementsHelper, TInterfaces...> : 627 | ChainInterfaces, 628 | AdjustImplements::Type 629 | { 630 | template friend struct ImplementsHelper; 631 | friend class RuntimeClassBase; 632 | 633 | protected: 634 | typedef typename AdjustImplements::Type BaseType; 635 | 636 | HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept 637 | { 638 | HRESULT hr = ChainInterfaces::CanCastTo(riid, ppv); 639 | if (FAILED(hr)) 640 | { 641 | hr = BaseType::CanCastTo(riid, ppv, pRefDelegated); 642 | } 643 | 644 | return hr; 645 | } 646 | 647 | IUnknown* CastToUnknown() noexcept 648 | { 649 | return ChainInterfaces::CastToUnknown(); 650 | } 651 | }; 652 | 653 | // Implements - template implementing QI using the information provided through its template parameters 654 | // Each template parameter has to be one of the following: 655 | // * COM Interface 656 | // * A class that implements one or more COM interfaces 657 | // * ChainInterfaces template 658 | template 659 | struct Implements : 660 | AdjustImplements::Type, 661 | ImplementsBase 662 | { 663 | public: 664 | typedef I0 FirstInterface; 665 | protected: 666 | typedef typename AdjustImplements::Type BaseType; 667 | template friend struct ImplementsHelper; 668 | friend class RuntimeClassBase; 669 | 670 | HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) noexcept 671 | { 672 | return BaseType::CanCastTo(riid, ppv); 673 | } 674 | 675 | IUnknown* CastToUnknown() noexcept 676 | { 677 | return BaseType::CastToUnknown(); 678 | } 679 | }; 680 | 681 | // Used on RuntimeClass to protect it from being constructed with new 682 | class DontUseNewUseMake 683 | { 684 | private: 685 | void* operator new(size_t) noexcept 686 | { 687 | assert(false); 688 | return 0; 689 | } 690 | 691 | public: 692 | void* operator new(size_t, _In_ void* placement) noexcept 693 | { 694 | return placement; 695 | } 696 | }; 697 | 698 | template 699 | class RuntimeClassImpl : 700 | public AdjustImplements::Type, 701 | public RuntimeClassBase, 702 | public DontUseNewUseMake 703 | { 704 | public: 705 | STDMETHOD(QueryInterface)(REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject) 706 | { 707 | return Super::AsIID(this, riid, ppvObject); 708 | } 709 | 710 | STDMETHOD_(ULONG, AddRef)() 711 | { 712 | return InternalAddRef(); 713 | } 714 | 715 | STDMETHOD_(ULONG, Release)() 716 | { 717 | ULONG ref = InternalRelease(); 718 | if (ref == 0) 719 | { 720 | this->~RuntimeClassImpl(); 721 | delete[] reinterpret_cast(this); 722 | } 723 | 724 | return ref; 725 | } 726 | 727 | protected: 728 | using Super = RuntimeClassBase; 729 | static const LONG c_lProtectDestruction = -(LONG_MAX / 2); 730 | 731 | RuntimeClassImpl() noexcept = default; 732 | 733 | virtual ~RuntimeClassImpl() noexcept 734 | { 735 | // Set refcount_ to -(LONG_MAX/2) to protect destruction and 736 | // also catch mismatched Release in debug builds 737 | refcount_ = static_cast(c_lProtectDestruction); 738 | } 739 | 740 | ULONG InternalAddRef() noexcept 741 | { 742 | return ++refcount_; 743 | } 744 | 745 | ULONG InternalRelease() noexcept 746 | { 747 | return --refcount_; 748 | } 749 | 750 | unsigned long GetRefCount() const noexcept 751 | { 752 | return refcount_; 753 | } 754 | 755 | std::atomic refcount_{1}; 756 | }; 757 | } 758 | 759 | template 760 | class Base : public Details::RuntimeClassImpl 761 | { 762 | Base(const Base&) = delete; 763 | Base& operator=(const Base&) = delete; 764 | 765 | protected: 766 | HRESULT CustomQueryInterface(REFIID /*riid*/, _Outptr_result_nullonfailure_ void** /*ppvObject*/, _Out_ bool *handled) 767 | { 768 | *handled = false; 769 | return S_OK; 770 | } 771 | 772 | public: 773 | Base() throw() = default; 774 | typedef Base RuntimeClassT; 775 | }; 776 | 777 | // Creates a Nano-COM object wrapped in a smart pointer. 778 | template 779 | ComPtr Make(TArgs&&... args) 780 | { 781 | std::unique_ptr buffer(new(std::nothrow) char[sizeof(T)]); 782 | ComPtr object; 783 | 784 | if (buffer) 785 | { 786 | T* ptr = new (buffer.get())T(std::forward(args)...); 787 | object.Attach(ptr); 788 | buffer.release(); 789 | } 790 | 791 | return object; 792 | } 793 | 794 | using Details::ChainInterfaces; 795 | } 796 | } 797 | 798 | // Overloaded global function to provide to IID_PPV_ARGS that support Details::ComPtrRef 799 | template 800 | void** IID_PPV_ARGS_Helper(Microsoft::WRL::Details::ComPtrRef pp) throw() 801 | { 802 | return pp; 803 | } 804 | -------------------------------------------------------------------------------- /meson.build: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | project('DirectX-Headers', 'cpp', version : '1.616.0', 5 | default_options : ['cpp_std=c++14']) 6 | 7 | cpp = meson.get_compiler('cpp') 8 | compiler_id = cpp.get_id() 9 | #d3d12_lib is not available in linux 10 | d3d12_lib = cpp.find_library('d3d12', required : host_machine.system() == 'windows') 11 | #dxcore is not available in Mingw-w64 12 | dxcore_lib = cpp.find_library('dxcore', required: compiler_id == 'msvc') 13 | test_compile_opts = [] 14 | if host_machine.system() == 'windows' 15 | test_compile_opts = ['-DUNICODE', '-D_WIN32_WINNT=0x0A00'] 16 | endif 17 | if (compiler_id == 'gcc') or (compiler_id == 'clang') 18 | test_compile_opts += ['-Wno-unused-variable'] 19 | endif 20 | 21 | inc_dirs = [include_directories('include', is_system : true)] 22 | install_inc_subdirs = [''] 23 | compile_options = [] 24 | 25 | if host_machine.system() != 'windows' 26 | inc_dirs += include_directories('include/wsl/stubs', is_system : true) 27 | install_inc_subdirs += ['', 'wsl/stubs', 'directx'] 28 | elif meson.get_compiler('cpp').get_id() != 'msvc' and meson.get_compiler('cpp').get_id() != 'clang-cl' 29 | # MinGW has RPC headers which define old versions, and complain if D3D 30 | # headers are included before the RPC headers, since D3D headers were 31 | # generated with new MIDL and "require" new RPC headers. 32 | compile_options = ['-D__REQUIRED_RPCNDR_H_VERSION__=475'] 33 | endif 34 | 35 | format_properties_lib = static_library( 36 | 'd3dx12-format-properties', 37 | 'src/d3dx12_property_format_table.cpp', 38 | include_directories : [inc_dirs, 'include/directx'], 39 | cpp_args : compile_options, 40 | install : true) 41 | guids_lib = static_library('DirectX-Guids', 'src/dxguids.cpp', include_directories : inc_dirs, install : true) 42 | 43 | dep_dxheaders = declare_dependency( 44 | link_with : [format_properties_lib, guids_lib], 45 | include_directories : inc_dirs, 46 | compile_args : compile_options) 47 | 48 | if meson.version().version_compare('>=0.54.0') 49 | meson.override_dependency('DirectX-Headers', dep_dxheaders) 50 | endif 51 | 52 | if not meson.is_subproject() and get_option('build-test') 53 | subdir('googletest') 54 | subdir('test') 55 | endif 56 | 57 | pkg = import('pkgconfig') 58 | pkg.generate(name : 'DirectX-Headers', 59 | description : 'Headers for using D3D12', 60 | url: 'https://github.com/microsoft/DirectX-Headers', 61 | libraries : [format_properties_lib, guids_lib], 62 | version : meson.project_version(), 63 | subdirs : install_inc_subdirs) 64 | install_subdir('include', install_dir : '') 65 | -------------------------------------------------------------------------------- /meson_options.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | option('build-test', 5 | type : 'boolean', 6 | value : true, 7 | description : 'Build the test') 8 | -------------------------------------------------------------------------------- /src/dxguids.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | // This file's sole purpose is to initialize the GUIDs declared using the DEFINE_GUID macro. 5 | #define INITGUID 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | list(APPEND dxlibs "") 5 | # Check if in WSL and if has DirectX driver and runtime 6 | if(EXISTS "/usr/lib/wsl/lib/") 7 | find_library(libd3d12 d3d12 HINTS /usr/lib/wsl/lib) 8 | find_library(libdxcore dxcore HINTS /usr/lib/wsl/lib) 9 | list(APPEND dxlibs ${libd3d12} ${libdxcore}) 10 | else() 11 | # Fallback to default: let CMake look for libs 12 | list(APPEND dxlibs d3d12) 13 | if (MSVC) 14 | # MINGW doesn't have dxcore yet 15 | list(APPEND dxlibs dxcore) 16 | endif() 17 | endif() 18 | 19 | project(DirectX-Headers-Test 20 | DESCRIPTION "DirectX-Header test" 21 | HOMEPAGE_URL "https://github.com/microsoft/DirectX-Headers/" 22 | LANGUAGES CXX) 23 | 24 | set(CMAKE_CXX_STANDARD 17) 25 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 26 | set(CMAKE_CXX_EXTENSIONS OFF) 27 | 28 | option(DXHEADERS_BUILD_COM_ATL "Build using ATL CComPtr" OFF) 29 | 30 | set(TEST_EXES DirectX-Headers-Test DirectX-Headers-Check-Feature-Support-Test) 31 | 32 | add_executable(DirectX-Headers-Test test.cpp) 33 | add_test(NAME DirectX-Headers-Test COMMAND DirectX-Headers-Test) 34 | add_executable(DirectX-Headers-Check-Feature-Support-Test feature_check_test.cpp) 35 | add_test(NAME DirectX-Headers-Check-Feature-Support-Test COMMAND DirectX-Headers-Check-Feature-Support-Test) 36 | 37 | foreach(t IN LISTS TEST_EXES) 38 | target_link_libraries(${t} DirectX-Headers DirectX-Guids ${dxlibs}) 39 | endforeach() 40 | 41 | if(DXHEADERS_BUILD_COM_ATL) 42 | foreach(t IN LISTS TEST_EXES) 43 | target_compile_definitions(${t} PRIVATE D3DX12_USE_ATL) 44 | endforeach() 45 | endif() 46 | 47 | if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM" ) 48 | target_compile_options(DirectX-Headers-Check-Feature-Support-Test PRIVATE -Wno-unused-variable) 49 | endif() 50 | 51 | if(WIN32) 52 | foreach(t IN LISTS TEST_EXES) 53 | target_compile_definitions(${t} PRIVATE _UNICODE UNICODE _WIN32_WINNT=0x0A00) 54 | endforeach() 55 | 56 | if(WINDOWS_STORE) 57 | foreach(t IN LISTS TEST_EXES) 58 | target_compile_definitions(${t} PRIVATE WINAPI_FAMILY=WINAPI_FAMILY_APP) 59 | endforeach() 60 | endif() 61 | endif() 62 | -------------------------------------------------------------------------------- /test/meson.build: -------------------------------------------------------------------------------- 1 | # Copyright (c) Microsoft Corporation. 2 | # Licensed under the MIT License. 3 | 4 | headers_test = executable('DirectX-Headers-Test', 'test.cpp', 5 | dependencies : [dep_dxheaders, d3d12_lib, dxcore_lib], 6 | cpp_args : test_compile_opts, 7 | c_args : test_compile_opts) 8 | test('DirectX-Headers-Test', headers_test) 9 | 10 | headers_features_test = executable('DirectX-Headers-Check-Feature-Support-Test', 'feature_check_test.cpp', 11 | dependencies : [dep_dxheaders, d3d12_lib, dxcore_lib], 12 | cpp_args : test_compile_opts, 13 | c_args : test_compile_opts) 14 | test('DirectX-Headers-Check-Feature-Support-Test', headers_features_test) 15 | 16 | -------------------------------------------------------------------------------- /test/test.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft Corporation. 2 | // Licensed under the MIT License. 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "dxguids/dxguids.h" 11 | 12 | #ifdef __MINGW32__ 13 | STDAPI 14 | DXCoreCreateAdapterFactory( 15 | REFIID riid, 16 | _COM_Outptr_ void** ppvFactory 17 | ) { 18 | return 0; 19 | } 20 | #endif 21 | 22 | int check_uuid_linkage() { 23 | auto uuid_i_unknown = IID_IUnknown; 24 | return sizeof(uuid_i_unknown); 25 | } 26 | 27 | int main() 28 | { 29 | IDXCoreAdapter *adapter = nullptr; 30 | ID3D12Device *device = nullptr; 31 | check_uuid_linkage(); 32 | { 33 | IDXCoreAdapterFactory *factory = nullptr; 34 | if (FAILED(DXCoreCreateAdapterFactory(&factory))) 35 | return -1; 36 | 37 | IDXCoreAdapterList *list = nullptr; 38 | if (FAILED(factory->CreateAdapterList(1, &DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, &list))) 39 | return -1; 40 | 41 | if (FAILED(list->GetAdapter(0, &adapter))) 42 | return -1; 43 | } 44 | 45 | return D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device)); 46 | } 47 | --------------------------------------------------------------------------------