mirror of
https://github.com/microsoft/DirectX-Headers.git
synced 2024-11-23 01:46:44 +08:00
Initial commit
This commit is contained in:
commit
1ec6cd7171
58
CMakeLists.txt
Normal file
58
CMakeLists.txt
Normal file
@ -0,0 +1,58 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cmake_minimum_required(VERSION 3.10.2)
|
||||
project(DirectX-Headers
|
||||
LANGUAGES CXX
|
||||
VERSION 1.0)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# Enables consumers to add this library as a link target to automatically add
|
||||
# these include directories, regardless of whether this is referenced via subdirectory
|
||||
# or from an installed location
|
||||
add_library(DirectX-Headers INTERFACE)
|
||||
target_include_directories(DirectX-Headers SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>"
|
||||
)
|
||||
|
||||
# For non-Windows targets, also add the WSL stubs to the include path
|
||||
if (NOT WIN32)
|
||||
target_include_directories(DirectX-Headers SYSTEM INTERFACE
|
||||
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/wsl/stubs>"
|
||||
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/wsl/stubs>"
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(DirectX-Guids STATIC src/dxguids.cpp)
|
||||
target_link_libraries(DirectX-Guids PRIVATE DirectX-Headers)
|
||||
|
||||
# Install the targets
|
||||
install(TARGETS DirectX-Headers DirectX-Guids
|
||||
EXPORT DirectX-Headers-Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
# Create the targets CMake file which contains the above definitions
|
||||
install(EXPORT DirectX-Headers-Targets FILE directx-headers-targets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake)
|
||||
|
||||
# Install the actual includes
|
||||
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
# Create the CMake config files
|
||||
include(CMakePackageConfigHelpers)
|
||||
write_basic_package_version_file("directx-headers-config-version.cmake"
|
||||
VERSION ${PROJECT_VERSION}
|
||||
COMPATIBILITY SameMajorVersion)
|
||||
configure_package_config_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/directx-headers-config.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake"
|
||||
INSTALL_DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake)
|
||||
|
||||
# Install the CMake config files
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/directx-headers-config-version.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/directx-headers/cmake)
|
||||
|
||||
add_subdirectory(test)
|
21
LICENSE
Normal file
21
LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
MIT License
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
45
README.md
Normal file
45
README.md
Normal file
@ -0,0 +1,45 @@
|
||||
# DirectX Headers
|
||||
|
||||
This repository hosts the official Direct3D 12 headers. These headers are made available under the MIT license rather than the traditional Windows SDK license.
|
||||
|
||||
Additionally, this repository hosts several helpers for using these headers.
|
||||
|
||||
## Directory Structure
|
||||
|
||||
* `/`: 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.
|
||||
* `/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.
|
||||
* `/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.
|
||||
* `/include/dxguids`: This header allows an application to use `uuidof<T>()` consistently between Windows and WSL, instead of `__uuidof()`.
|
||||
* `/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.
|
||||
* `/test`: Simple CMake/Meson projects for validating the headers can be included in a given environment
|
||||
|
||||
## Use on Windows
|
||||
|
||||
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.
|
||||
|
||||
## Use on WSL
|
||||
|
||||
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.
|
||||
|
||||
Note: WSL support is only available for 64-bit binaries.
|
||||
|
||||
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:
|
||||
|
||||
|Type|Reason|
|
||||
|---|---|
|
||||
|`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.|
|
||||
|`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.|
|
||||
|
||||
Additionally, APIs taking `HANDLE` (`void*`) for Win32 types should instead use `reinterpret_cast<HANDLE>(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.
|
||||
|
||||
## Ways to consume
|
||||
|
||||
There are various ways to consume the headers in this project:
|
||||
|
||||
* Manually: Just copy the headers somewhere and point your project at them.
|
||||
* 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
|
||||
* 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.
|
||||
* Meson subproject/wrap: Add this entire project as a subproject of your larger project, and use `subproject` or `dependency` to consume it.
|
||||
* Pkg-config: Use Meson to build this project, and the resulting installed package can be found via pkg-config.
|
||||
|
||||
Contributions for new mechanisms are welcome.
|
4
cmake/directx-headers-config.cmake.in
Normal file
4
cmake/directx-headers-config.cmake.in
Normal file
@ -0,0 +1,4 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/directx-headers-targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
23194
include/directx/d3d12.h
Normal file
23194
include/directx/d3d12.h
Normal file
File diff suppressed because it is too large
Load Diff
3654
include/directx/d3d12sdklayers.h
Normal file
3654
include/directx/d3d12sdklayers.h
Normal file
File diff suppressed because it is too large
Load Diff
1061
include/directx/d3dcommon.h
Normal file
1061
include/directx/d3dcommon.h
Normal file
File diff suppressed because it is too large
Load Diff
3905
include/directx/d3dx12.h
Normal file
3905
include/directx/d3dx12.h
Normal file
File diff suppressed because it is too large
Load Diff
40
include/directx/dxcore.h
Normal file
40
include/directx/dxcore.h
Normal file
@ -0,0 +1,40 @@
|
||||
/************************************************************
|
||||
* *
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved. *
|
||||
* *
|
||||
************************************************************/
|
||||
|
||||
#ifndef _DXCOREEXTMODULE_H_
|
||||
#define _DXCOREEXTMODULE_H_
|
||||
|
||||
#include <winapifamily.h>
|
||||
#include "dxcore_interface.h"
|
||||
|
||||
#pragma region Application Family or OneCore Family
|
||||
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM)
|
||||
|
||||
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
|
||||
|
||||
STDAPI
|
||||
DXCoreCreateAdapterFactory(
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void** ppvFactory
|
||||
);
|
||||
|
||||
template <class T>
|
||||
HRESULT
|
||||
DXCoreCreateAdapterFactory(
|
||||
_COM_Outptr_ T** ppvFactory
|
||||
)
|
||||
{
|
||||
return DXCoreCreateAdapterFactory(IID_PPV_ARGS(ppvFactory));
|
||||
}
|
||||
|
||||
#endif // (_WIN32_WINNT >= _WIN32_WINNT_WIN10)
|
||||
|
||||
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP | WINAPI_PARTITION_SYSTEM) */
|
||||
#pragma endregion
|
||||
|
||||
#endif // _DXCOREEXTMODULE_H_
|
||||
|
||||
|
315
include/directx/dxcore_interface.h
Normal file
315
include/directx/dxcore_interface.h
Normal file
@ -0,0 +1,315 @@
|
||||
//
|
||||
// DXCore Interface
|
||||
// Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __dxcore_interface_h__
|
||||
#define __dxcore_interface_h__
|
||||
|
||||
#ifndef COM_NO_WINDOWS_H
|
||||
#include "windows.h"
|
||||
#include "ole2.h"
|
||||
#endif /*COM_NO_WINDOWS_H*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
#define _FACDXCORE 0x880
|
||||
#define MAKE_DXCORE_HRESULT( code ) MAKE_HRESULT( 1, _FACDXCORE, code )
|
||||
|
||||
enum class DXCoreAdapterProperty : uint32_t
|
||||
{
|
||||
InstanceLuid = 0,
|
||||
DriverVersion = 1,
|
||||
DriverDescription = 2,
|
||||
HardwareID = 3, // Use HardwareIDParts instead, if available.
|
||||
KmdModelVersion = 4,
|
||||
ComputePreemptionGranularity = 5,
|
||||
GraphicsPreemptionGranularity = 6,
|
||||
DedicatedAdapterMemory = 7,
|
||||
DedicatedSystemMemory = 8,
|
||||
SharedSystemMemory = 9,
|
||||
AcgCompatible = 10,
|
||||
IsHardware = 11,
|
||||
IsIntegrated = 12,
|
||||
IsDetachable = 13,
|
||||
HardwareIDParts = 14
|
||||
};
|
||||
|
||||
enum class DXCoreAdapterState : uint32_t
|
||||
{
|
||||
IsDriverUpdateInProgress = 0,
|
||||
AdapterMemoryBudget = 1
|
||||
};
|
||||
|
||||
enum class DXCoreSegmentGroup : uint32_t
|
||||
{
|
||||
Local = 0,
|
||||
NonLocal = 1
|
||||
};
|
||||
|
||||
enum class DXCoreNotificationType : uint32_t
|
||||
{
|
||||
AdapterListStale = 0,
|
||||
AdapterNoLongerValid = 1,
|
||||
AdapterBudgetChange = 2,
|
||||
AdapterHardwareContentProtectionTeardown = 3
|
||||
};
|
||||
|
||||
enum class DXCoreAdapterPreference : uint32_t
|
||||
{
|
||||
Hardware = 0,
|
||||
MinimumPower = 1,
|
||||
HighPerformance = 2
|
||||
};
|
||||
|
||||
struct DXCoreHardwareID
|
||||
{
|
||||
uint32_t vendorID;
|
||||
uint32_t deviceID;
|
||||
uint32_t subSysID;
|
||||
uint32_t revision;
|
||||
};
|
||||
|
||||
struct DXCoreHardwareIDParts
|
||||
{
|
||||
uint32_t vendorID;
|
||||
uint32_t deviceID;
|
||||
uint32_t subSystemID;
|
||||
uint32_t subVendorID;
|
||||
uint32_t revisionID;
|
||||
};
|
||||
|
||||
struct DXCoreAdapterMemoryBudgetNodeSegmentGroup
|
||||
{
|
||||
uint32_t nodeIndex;
|
||||
DXCoreSegmentGroup segmentGroup;
|
||||
};
|
||||
|
||||
struct DXCoreAdapterMemoryBudget
|
||||
{
|
||||
uint64_t budget;
|
||||
uint64_t currentUsage;
|
||||
uint64_t availableForReservation;
|
||||
uint64_t currentReservation;
|
||||
};
|
||||
|
||||
typedef void (STDMETHODCALLTYPE *PFN_DXCORE_NOTIFICATION_CALLBACK)(
|
||||
DXCoreNotificationType notificationType,
|
||||
_In_ IUnknown *object,
|
||||
_In_opt_ void *context);
|
||||
|
||||
static_assert(sizeof(bool) == 1, "bool assumed as one byte");
|
||||
|
||||
DEFINE_GUID(IID_IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06);
|
||||
DEFINE_GUID(IID_IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28);
|
||||
DEFINE_GUID(IID_IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e);
|
||||
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D11_GRAPHICS, 0x8c47866b, 0x7583, 0x450d, 0xf0, 0xf0, 0x6b, 0xad, 0xa8, 0x95, 0xaf, 0x4b);
|
||||
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS, 0x0c9ece4d, 0x2f6e, 0x4f01, 0x8c, 0x96, 0xe8, 0x9e, 0x33, 0x1b, 0x47, 0xb1);
|
||||
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, 0x248e2800, 0xa793, 0x4724, 0xab, 0xaa, 0x23, 0xa6, 0xde, 0x1b, 0xe0, 0x90);
|
||||
|
||||
/* interface IDXCoreAdapter */
|
||||
MIDL_INTERFACE("f0db4c7f-fe5a-42a2-bd62-f2a6cf6fc83e")
|
||||
IDXCoreAdapter : public IUnknown
|
||||
{
|
||||
public:
|
||||
virtual bool STDMETHODCALLTYPE IsValid() = 0;
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsAttributeSupported(
|
||||
REFGUID attributeGUID) = 0;
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsPropertySupported(
|
||||
DXCoreAdapterProperty property) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetProperty(
|
||||
DXCoreAdapterProperty property,
|
||||
size_t bufferSize,
|
||||
_Out_writes_bytes_(bufferSize) void *propertyData) = 0;
|
||||
|
||||
template <class T>
|
||||
HRESULT GetProperty(
|
||||
DXCoreAdapterProperty property,
|
||||
_Out_writes_bytes_(sizeof(T)) T *propertyData)
|
||||
{
|
||||
return GetProperty(property,
|
||||
sizeof(T),
|
||||
(void*)propertyData);
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetPropertySize(
|
||||
DXCoreAdapterProperty property,
|
||||
_Out_ size_t *bufferSize) = 0;
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsQueryStateSupported(
|
||||
DXCoreAdapterState property) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryState(
|
||||
DXCoreAdapterState state,
|
||||
size_t inputStateDetailsSize,
|
||||
_In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails,
|
||||
size_t outputBufferSize,
|
||||
_Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0;
|
||||
|
||||
template <class T1, class T2>
|
||||
HRESULT QueryState(
|
||||
DXCoreAdapterState state,
|
||||
_In_reads_bytes_opt_(sizeof(T1)) const T1 *inputStateDetails,
|
||||
_Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer)
|
||||
{
|
||||
return QueryState(state,
|
||||
sizeof(T1),
|
||||
(const void*)inputStateDetails,
|
||||
sizeof(T2),
|
||||
(void*)outputBuffer);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
HRESULT QueryState(
|
||||
DXCoreAdapterState state,
|
||||
_Out_writes_bytes_(sizeof(T)) T *outputBuffer)
|
||||
{
|
||||
return QueryState(state,
|
||||
0,
|
||||
nullptr,
|
||||
sizeof(T),
|
||||
(void*)outputBuffer);
|
||||
}
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsSetStateSupported(
|
||||
DXCoreAdapterState property) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE SetState(
|
||||
DXCoreAdapterState state,
|
||||
size_t inputStateDetailsSize,
|
||||
_In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails,
|
||||
size_t inputDataSize,
|
||||
_In_reads_bytes_(inputDataSize) const void *inputData) = 0;
|
||||
|
||||
template <class T1, class T2>
|
||||
HRESULT SetState(
|
||||
DXCoreAdapterState state,
|
||||
const T1 *inputStateDetails,
|
||||
const T2 *inputData)
|
||||
{
|
||||
return SetState(state,
|
||||
sizeof(T1),
|
||||
(const void*)inputStateDetails,
|
||||
sizeof(T2),
|
||||
(const void*)inputData);
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFactory(
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void** ppvFactory
|
||||
) = 0;
|
||||
|
||||
template <class T>
|
||||
HRESULT GetFactory(
|
||||
_COM_Outptr_ T** ppvFactory
|
||||
)
|
||||
{
|
||||
return GetFactory(IID_PPV_ARGS(ppvFactory));
|
||||
}
|
||||
};
|
||||
|
||||
/* interface IDXCoreAdapterList */
|
||||
MIDL_INTERFACE("526c7776-40e9-459b-b711-f32ad76dfc28")
|
||||
IDXCoreAdapterList : public IUnknown
|
||||
{
|
||||
public:
|
||||
virtual HRESULT STDMETHODCALLTYPE GetAdapter(
|
||||
uint32_t index,
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void **ppvAdapter) = 0;
|
||||
|
||||
template<class T>
|
||||
HRESULT STDMETHODCALLTYPE GetAdapter(
|
||||
uint32_t index,
|
||||
_COM_Outptr_ T **ppvAdapter)
|
||||
{
|
||||
return GetAdapter(index,
|
||||
IID_PPV_ARGS(ppvAdapter));
|
||||
}
|
||||
|
||||
virtual uint32_t STDMETHODCALLTYPE GetAdapterCount() = 0;
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsStale() = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetFactory(
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void** ppvFactory
|
||||
) = 0;
|
||||
|
||||
template <class T>
|
||||
HRESULT GetFactory(
|
||||
_COM_Outptr_ T** ppvFactory
|
||||
)
|
||||
{
|
||||
return GetFactory(IID_PPV_ARGS(ppvFactory));
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE Sort(
|
||||
uint32_t numPreferences,
|
||||
_In_reads_(numPreferences) const DXCoreAdapterPreference* preferences) = 0;
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsAdapterPreferenceSupported(
|
||||
DXCoreAdapterPreference preference) = 0;
|
||||
};
|
||||
|
||||
/* interface IDXCoreAdapterFactory */
|
||||
MIDL_INTERFACE("78ee5945-c36e-4b13-a669-005dd11c0f06")
|
||||
IDXCoreAdapterFactory : public IUnknown
|
||||
{
|
||||
public:
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE CreateAdapterList(
|
||||
uint32_t numAttributes,
|
||||
_In_reads_(numAttributes) const GUID *filterAttributes,
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void **ppvAdapterList) = 0;
|
||||
|
||||
template<class T>
|
||||
HRESULT STDMETHODCALLTYPE CreateAdapterList(
|
||||
uint32_t numAttributes,
|
||||
_In_reads_(numAttributes) const GUID *filterAttributes,
|
||||
_COM_Outptr_ T **ppvAdapterList)
|
||||
{
|
||||
return CreateAdapterList(numAttributes,
|
||||
filterAttributes,
|
||||
IID_PPV_ARGS(ppvAdapterList));
|
||||
}
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE GetAdapterByLuid(
|
||||
const LUID &adapterLUID,
|
||||
REFIID riid,
|
||||
_COM_Outptr_ void **ppvAdapter) = 0;
|
||||
|
||||
template<class T>
|
||||
HRESULT STDMETHODCALLTYPE GetAdapterByLuid(
|
||||
const LUID &adapterLUID,
|
||||
_COM_Outptr_ T **ppvAdapter)
|
||||
{
|
||||
return GetAdapterByLuid(adapterLUID,
|
||||
IID_PPV_ARGS(ppvAdapter));
|
||||
}
|
||||
|
||||
virtual bool STDMETHODCALLTYPE IsNotificationTypeSupported(
|
||||
DXCoreNotificationType notificationType) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE RegisterEventNotification(
|
||||
_In_ IUnknown *dxCoreObject,
|
||||
DXCoreNotificationType notificationType,
|
||||
_In_ PFN_DXCORE_NOTIFICATION_CALLBACK callbackFunction,
|
||||
_In_opt_ void *callbackContext,
|
||||
_Out_ uint32_t *eventCookie) = 0;
|
||||
|
||||
virtual HRESULT STDMETHODCALLTYPE UnregisterEventNotification(
|
||||
uint32_t eventCookie) = 0;
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __dxcore_interface_h__
|
||||
|
||||
|
56
include/directx/dxgicommon.h
Normal file
56
include/directx/dxgicommon.h
Normal file
@ -0,0 +1,56 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __dxgicommon_h__
|
||||
#define __dxgicommon_h__
|
||||
|
||||
|
||||
typedef struct DXGI_RATIONAL
|
||||
{
|
||||
UINT Numerator;
|
||||
UINT Denominator;
|
||||
} DXGI_RATIONAL;
|
||||
|
||||
// The following values are used with DXGI_SAMPLE_DESC::Quality:
|
||||
#define DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN 0xffffffff
|
||||
#define DXGI_CENTER_MULTISAMPLE_QUALITY_PATTERN 0xfffffffe
|
||||
|
||||
typedef struct DXGI_SAMPLE_DESC
|
||||
{
|
||||
UINT Count;
|
||||
UINT Quality;
|
||||
} DXGI_SAMPLE_DESC;
|
||||
|
||||
typedef enum DXGI_COLOR_SPACE_TYPE
|
||||
{
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709 = 0,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 = 1,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709 = 2,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020 = 3,
|
||||
DXGI_COLOR_SPACE_RESERVED = 4,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601 = 5,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601 = 6,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601 = 7,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709 = 8,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709 = 9,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020 = 10,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020 = 11,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 = 12,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020 = 13,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020 = 14,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020 = 15,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020 = 16,
|
||||
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020 = 17,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020 = 18,
|
||||
DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020 = 19,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709 = 20,
|
||||
DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020 = 21,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709 = 22,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020 = 23,
|
||||
DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020 = 24,
|
||||
DXGI_COLOR_SPACE_CUSTOM = 0xFFFFFFFF
|
||||
} DXGI_COLOR_SPACE_TYPE;
|
||||
|
||||
#endif // __dxgicommon_h__
|
||||
|
141
include/directx/dxgiformat.h
Normal file
141
include/directx/dxgiformat.h
Normal file
@ -0,0 +1,141 @@
|
||||
//
|
||||
// Copyright (C) Microsoft. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef __dxgiformat_h__
|
||||
#define __dxgiformat_h__
|
||||
|
||||
#define DXGI_FORMAT_DEFINED 1
|
||||
|
||||
typedef enum DXGI_FORMAT
|
||||
{
|
||||
DXGI_FORMAT_UNKNOWN = 0,
|
||||
DXGI_FORMAT_R32G32B32A32_TYPELESS = 1,
|
||||
DXGI_FORMAT_R32G32B32A32_FLOAT = 2,
|
||||
DXGI_FORMAT_R32G32B32A32_UINT = 3,
|
||||
DXGI_FORMAT_R32G32B32A32_SINT = 4,
|
||||
DXGI_FORMAT_R32G32B32_TYPELESS = 5,
|
||||
DXGI_FORMAT_R32G32B32_FLOAT = 6,
|
||||
DXGI_FORMAT_R32G32B32_UINT = 7,
|
||||
DXGI_FORMAT_R32G32B32_SINT = 8,
|
||||
DXGI_FORMAT_R16G16B16A16_TYPELESS = 9,
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT = 10,
|
||||
DXGI_FORMAT_R16G16B16A16_UNORM = 11,
|
||||
DXGI_FORMAT_R16G16B16A16_UINT = 12,
|
||||
DXGI_FORMAT_R16G16B16A16_SNORM = 13,
|
||||
DXGI_FORMAT_R16G16B16A16_SINT = 14,
|
||||
DXGI_FORMAT_R32G32_TYPELESS = 15,
|
||||
DXGI_FORMAT_R32G32_FLOAT = 16,
|
||||
DXGI_FORMAT_R32G32_UINT = 17,
|
||||
DXGI_FORMAT_R32G32_SINT = 18,
|
||||
DXGI_FORMAT_R32G8X24_TYPELESS = 19,
|
||||
DXGI_FORMAT_D32_FLOAT_S8X24_UINT = 20,
|
||||
DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS = 21,
|
||||
DXGI_FORMAT_X32_TYPELESS_G8X24_UINT = 22,
|
||||
DXGI_FORMAT_R10G10B10A2_TYPELESS = 23,
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM = 24,
|
||||
DXGI_FORMAT_R10G10B10A2_UINT = 25,
|
||||
DXGI_FORMAT_R11G11B10_FLOAT = 26,
|
||||
DXGI_FORMAT_R8G8B8A8_TYPELESS = 27,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM = 28,
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM_SRGB = 29,
|
||||
DXGI_FORMAT_R8G8B8A8_UINT = 30,
|
||||
DXGI_FORMAT_R8G8B8A8_SNORM = 31,
|
||||
DXGI_FORMAT_R8G8B8A8_SINT = 32,
|
||||
DXGI_FORMAT_R16G16_TYPELESS = 33,
|
||||
DXGI_FORMAT_R16G16_FLOAT = 34,
|
||||
DXGI_FORMAT_R16G16_UNORM = 35,
|
||||
DXGI_FORMAT_R16G16_UINT = 36,
|
||||
DXGI_FORMAT_R16G16_SNORM = 37,
|
||||
DXGI_FORMAT_R16G16_SINT = 38,
|
||||
DXGI_FORMAT_R32_TYPELESS = 39,
|
||||
DXGI_FORMAT_D32_FLOAT = 40,
|
||||
DXGI_FORMAT_R32_FLOAT = 41,
|
||||
DXGI_FORMAT_R32_UINT = 42,
|
||||
DXGI_FORMAT_R32_SINT = 43,
|
||||
DXGI_FORMAT_R24G8_TYPELESS = 44,
|
||||
DXGI_FORMAT_D24_UNORM_S8_UINT = 45,
|
||||
DXGI_FORMAT_R24_UNORM_X8_TYPELESS = 46,
|
||||
DXGI_FORMAT_X24_TYPELESS_G8_UINT = 47,
|
||||
DXGI_FORMAT_R8G8_TYPELESS = 48,
|
||||
DXGI_FORMAT_R8G8_UNORM = 49,
|
||||
DXGI_FORMAT_R8G8_UINT = 50,
|
||||
DXGI_FORMAT_R8G8_SNORM = 51,
|
||||
DXGI_FORMAT_R8G8_SINT = 52,
|
||||
DXGI_FORMAT_R16_TYPELESS = 53,
|
||||
DXGI_FORMAT_R16_FLOAT = 54,
|
||||
DXGI_FORMAT_D16_UNORM = 55,
|
||||
DXGI_FORMAT_R16_UNORM = 56,
|
||||
DXGI_FORMAT_R16_UINT = 57,
|
||||
DXGI_FORMAT_R16_SNORM = 58,
|
||||
DXGI_FORMAT_R16_SINT = 59,
|
||||
DXGI_FORMAT_R8_TYPELESS = 60,
|
||||
DXGI_FORMAT_R8_UNORM = 61,
|
||||
DXGI_FORMAT_R8_UINT = 62,
|
||||
DXGI_FORMAT_R8_SNORM = 63,
|
||||
DXGI_FORMAT_R8_SINT = 64,
|
||||
DXGI_FORMAT_A8_UNORM = 65,
|
||||
DXGI_FORMAT_R1_UNORM = 66,
|
||||
DXGI_FORMAT_R9G9B9E5_SHAREDEXP = 67,
|
||||
DXGI_FORMAT_R8G8_B8G8_UNORM = 68,
|
||||
DXGI_FORMAT_G8R8_G8B8_UNORM = 69,
|
||||
DXGI_FORMAT_BC1_TYPELESS = 70,
|
||||
DXGI_FORMAT_BC1_UNORM = 71,
|
||||
DXGI_FORMAT_BC1_UNORM_SRGB = 72,
|
||||
DXGI_FORMAT_BC2_TYPELESS = 73,
|
||||
DXGI_FORMAT_BC2_UNORM = 74,
|
||||
DXGI_FORMAT_BC2_UNORM_SRGB = 75,
|
||||
DXGI_FORMAT_BC3_TYPELESS = 76,
|
||||
DXGI_FORMAT_BC3_UNORM = 77,
|
||||
DXGI_FORMAT_BC3_UNORM_SRGB = 78,
|
||||
DXGI_FORMAT_BC4_TYPELESS = 79,
|
||||
DXGI_FORMAT_BC4_UNORM = 80,
|
||||
DXGI_FORMAT_BC4_SNORM = 81,
|
||||
DXGI_FORMAT_BC5_TYPELESS = 82,
|
||||
DXGI_FORMAT_BC5_UNORM = 83,
|
||||
DXGI_FORMAT_BC5_SNORM = 84,
|
||||
DXGI_FORMAT_B5G6R5_UNORM = 85,
|
||||
DXGI_FORMAT_B5G5R5A1_UNORM = 86,
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM = 87,
|
||||
DXGI_FORMAT_B8G8R8X8_UNORM = 88,
|
||||
DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM = 89,
|
||||
DXGI_FORMAT_B8G8R8A8_TYPELESS = 90,
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM_SRGB = 91,
|
||||
DXGI_FORMAT_B8G8R8X8_TYPELESS = 92,
|
||||
DXGI_FORMAT_B8G8R8X8_UNORM_SRGB = 93,
|
||||
DXGI_FORMAT_BC6H_TYPELESS = 94,
|
||||
DXGI_FORMAT_BC6H_UF16 = 95,
|
||||
DXGI_FORMAT_BC6H_SF16 = 96,
|
||||
DXGI_FORMAT_BC7_TYPELESS = 97,
|
||||
DXGI_FORMAT_BC7_UNORM = 98,
|
||||
DXGI_FORMAT_BC7_UNORM_SRGB = 99,
|
||||
DXGI_FORMAT_AYUV = 100,
|
||||
DXGI_FORMAT_Y410 = 101,
|
||||
DXGI_FORMAT_Y416 = 102,
|
||||
DXGI_FORMAT_NV12 = 103,
|
||||
DXGI_FORMAT_P010 = 104,
|
||||
DXGI_FORMAT_P016 = 105,
|
||||
DXGI_FORMAT_420_OPAQUE = 106,
|
||||
DXGI_FORMAT_YUY2 = 107,
|
||||
DXGI_FORMAT_Y210 = 108,
|
||||
DXGI_FORMAT_Y216 = 109,
|
||||
DXGI_FORMAT_NV11 = 110,
|
||||
DXGI_FORMAT_AI44 = 111,
|
||||
DXGI_FORMAT_IA44 = 112,
|
||||
DXGI_FORMAT_P8 = 113,
|
||||
DXGI_FORMAT_A8P8 = 114,
|
||||
DXGI_FORMAT_B4G4R4A4_UNORM = 115,
|
||||
|
||||
DXGI_FORMAT_P208 = 130,
|
||||
DXGI_FORMAT_V208 = 131,
|
||||
DXGI_FORMAT_V408 = 132,
|
||||
|
||||
|
||||
DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE = 189,
|
||||
DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE = 190,
|
||||
|
||||
|
||||
DXGI_FORMAT_FORCE_UINT = 0xffffffff
|
||||
} DXGI_FORMAT;
|
||||
|
||||
#endif // __dxgiformat_h__
|
126
include/dxguids/dxguids.h
Normal file
126
include/dxguids/dxguids.h
Normal file
@ -0,0 +1,126 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error "This header requires C++"
|
||||
#endif
|
||||
|
||||
constexpr inline bool ConstexprIsEqualGUID(REFGUID a, REFGUID b)
|
||||
{
|
||||
return a.Data1 == b.Data1 &&
|
||||
a.Data2 == b.Data2 &&
|
||||
a.Data3 == b.Data3 &&
|
||||
a.Data4[0] == b.Data4[0] &&
|
||||
a.Data4[1] == b.Data4[1] &&
|
||||
a.Data4[2] == b.Data4[2] &&
|
||||
a.Data4[3] == b.Data4[3] &&
|
||||
a.Data4[4] == b.Data4[4] &&
|
||||
a.Data4[5] == b.Data4[5] &&
|
||||
a.Data4[6] == b.Data4[6] &&
|
||||
a.Data4[7] == b.Data4[7];
|
||||
}
|
||||
|
||||
// Each COM interface (e.g. ID3D12Device) has a unique interface ID (IID) associated with it. With MSVC, the IID is defined
|
||||
// along with the interface declaration using compiler intrinsics (__declspec(uuid(...)); the IID can then be retrieved
|
||||
// using __uuidof. These intrinsics are not supported with all toolchains, so these helpers redefine IID values that can be
|
||||
// used with the various adapter COM helpers (ComPtr, IID_PPV_ARGS, etc.) for Linux. IIDs are stable and cannot change, but as
|
||||
// a precaution we statically assert the values are as expected when compiling for Windows.
|
||||
#ifdef _WIN32
|
||||
// winadapter.h isn't included when building for Windows, so the base function template needs to be declared.
|
||||
template <typename T> GUID uuidof() = delete;
|
||||
#define WINADAPTER_IID(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
template <> constexpr GUID uuidof<InterfaceName>() \
|
||||
{ \
|
||||
return { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \
|
||||
} \
|
||||
static_assert(ConstexprIsEqualGUID(uuidof<InterfaceName>(), __uuidof(InterfaceName)), "GUID definition mismatch: "#InterfaceName);
|
||||
#else
|
||||
#define WINADAPTER_IID(InterfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
|
||||
template <> constexpr GUID uuidof<InterfaceName>() \
|
||||
{ \
|
||||
return { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }; \
|
||||
}
|
||||
#endif
|
||||
|
||||
// Direct3D
|
||||
WINADAPTER_IID(ID3D12Object, 0xc4fec28f, 0x7966, 0x4e95, 0x9f, 0x94, 0xf4, 0x31, 0xcb, 0x56, 0xc3, 0xb8);
|
||||
WINADAPTER_IID(ID3D12DeviceChild, 0x905db94b, 0xa00c, 0x4140, 0x9d, 0xf5, 0x2b, 0x64, 0xca, 0x9e, 0xa3, 0x57);
|
||||
WINADAPTER_IID(ID3D12RootSignature, 0xc54a6b66, 0x72df, 0x4ee8, 0x8b, 0xe5, 0xa9, 0x46, 0xa1, 0x42, 0x92, 0x14);
|
||||
WINADAPTER_IID(ID3D12RootSignatureDeserializer, 0x34AB647B, 0x3CC8, 0x46AC, 0x84, 0x1B, 0xC0, 0x96, 0x56, 0x45, 0xC0, 0x46);
|
||||
WINADAPTER_IID(ID3D12VersionedRootSignatureDeserializer, 0x7F91CE67, 0x090C, 0x4BB7, 0xB7, 0x8E, 0xED, 0x8F, 0xF2, 0xE3, 0x1D, 0xA0);
|
||||
WINADAPTER_IID(ID3D12Pageable, 0x63ee58fb, 0x1268, 0x4835, 0x86, 0xda, 0xf0, 0x08, 0xce, 0x62, 0xf0, 0xd6);
|
||||
WINADAPTER_IID(ID3D12Heap, 0x6b3b2502, 0x6e51, 0x45b3, 0x90, 0xee, 0x98, 0x84, 0x26, 0x5e, 0x8d, 0xf3);
|
||||
WINADAPTER_IID(ID3D12Resource, 0x696442be, 0xa72e, 0x4059, 0xbc, 0x79, 0x5b, 0x5c, 0x98, 0x04, 0x0f, 0xad);
|
||||
WINADAPTER_IID(ID3D12CommandAllocator, 0x6102dee4, 0xaf59, 0x4b09, 0xb9, 0x99, 0xb4, 0x4d, 0x73, 0xf0, 0x9b, 0x24);
|
||||
WINADAPTER_IID(ID3D12Fence, 0x0a753dcf, 0xc4d8, 0x4b91, 0xad, 0xf6, 0xbe, 0x5a, 0x60, 0xd9, 0x5a, 0x76);
|
||||
WINADAPTER_IID(ID3D12Fence1, 0x433685fe, 0xe22b, 0x4ca0, 0xa8, 0xdb, 0xb5, 0xb4, 0xf4, 0xdd, 0x0e, 0x4a);
|
||||
WINADAPTER_IID(ID3D12PipelineState, 0x765a30f3, 0xf624, 0x4c6f, 0xa8, 0x28, 0xac, 0xe9, 0x48, 0x62, 0x24, 0x45);
|
||||
WINADAPTER_IID(ID3D12DescriptorHeap, 0x8efb471d, 0x616c, 0x4f49, 0x90, 0xf7, 0x12, 0x7b, 0xb7, 0x63, 0xfa, 0x51);
|
||||
WINADAPTER_IID(ID3D12QueryHeap, 0x0d9658ae, 0xed45, 0x469e, 0xa6, 0x1d, 0x97, 0x0e, 0xc5, 0x83, 0xca, 0xb4);
|
||||
WINADAPTER_IID(ID3D12CommandSignature, 0xc36a797c, 0xec80, 0x4f0a, 0x89, 0x85, 0xa7, 0xb2, 0x47, 0x50, 0x82, 0xd1);
|
||||
WINADAPTER_IID(ID3D12CommandList, 0x7116d91c, 0xe7e4, 0x47ce, 0xb8, 0xc6, 0xec, 0x81, 0x68, 0xf4, 0x37, 0xe5);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList, 0x5b160d0f, 0xac1b, 0x4185, 0x8b, 0xa8, 0xb3, 0xae, 0x42, 0xa5, 0xa4, 0x55);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList1, 0x553103fb, 0x1fe7, 0x4557, 0xbb, 0x38, 0x94, 0x6d, 0x7d, 0x0e, 0x7c, 0xa7);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList2, 0x38C3E585, 0xFF17, 0x412C, 0x91, 0x50, 0x4F, 0xC6, 0xF9, 0xD7, 0x2A, 0x28);
|
||||
WINADAPTER_IID(ID3D12CommandQueue, 0x0ec870a6, 0x5d7e, 0x4c22, 0x8c, 0xfc, 0x5b, 0xaa, 0xe0, 0x76, 0x16, 0xed);
|
||||
WINADAPTER_IID(ID3D12Device, 0x189819f1, 0x1db6, 0x4b57, 0xbe, 0x54, 0x18, 0x21, 0x33, 0x9b, 0x85, 0xf7);
|
||||
WINADAPTER_IID(ID3D12PipelineLibrary, 0xc64226a8, 0x9201, 0x46af, 0xb4, 0xcc, 0x53, 0xfb, 0x9f, 0xf7, 0x41, 0x4f);
|
||||
WINADAPTER_IID(ID3D12PipelineLibrary1, 0x80eabf42, 0x2568, 0x4e5e, 0xbd, 0x82, 0xc3, 0x7f, 0x86, 0x96, 0x1d, 0xc3);
|
||||
WINADAPTER_IID(ID3D12Device1, 0x77acce80, 0x638e, 0x4e65, 0x88, 0x95, 0xc1, 0xf2, 0x33, 0x86, 0x86, 0x3e);
|
||||
WINADAPTER_IID(ID3D12Device2, 0x30baa41e, 0xb15b, 0x475c, 0xa0, 0xbb, 0x1a, 0xf5, 0xc5, 0xb6, 0x43, 0x28);
|
||||
WINADAPTER_IID(ID3D12Device3, 0x81dadc15, 0x2bad, 0x4392, 0x93, 0xc5, 0x10, 0x13, 0x45, 0xc4, 0xaa, 0x98);
|
||||
WINADAPTER_IID(ID3D12ProtectedSession, 0xA1533D18, 0x0AC1, 0x4084, 0x85, 0xB9, 0x89, 0xA9, 0x61, 0x16, 0x80, 0x6B);
|
||||
WINADAPTER_IID(ID3D12ProtectedResourceSession, 0x6CD696F4, 0xF289, 0x40CC, 0x80, 0x91, 0x5A, 0x6C, 0x0A, 0x09, 0x9C, 0x3D);
|
||||
WINADAPTER_IID(ID3D12Device4, 0xe865df17, 0xa9ee, 0x46f9, 0xa4, 0x63, 0x30, 0x98, 0x31, 0x5a, 0xa2, 0xe5);
|
||||
WINADAPTER_IID(ID3D12LifetimeOwner, 0xe667af9f, 0xcd56, 0x4f46, 0x83, 0xce, 0x03, 0x2e, 0x59, 0x5d, 0x70, 0xa8);
|
||||
WINADAPTER_IID(ID3D12SwapChainAssistant, 0xf1df64b6, 0x57fd, 0x49cd, 0x88, 0x07, 0xc0, 0xeb, 0x88, 0xb4, 0x5c, 0x8f);
|
||||
WINADAPTER_IID(ID3D12LifetimeTracker, 0x3fd03d36, 0x4eb1, 0x424a, 0xa5, 0x82, 0x49, 0x4e, 0xcb, 0x8b, 0xa8, 0x13);
|
||||
WINADAPTER_IID(ID3D12StateObject, 0x47016943, 0xfca8, 0x4594, 0x93, 0xea, 0xaf, 0x25, 0x8b, 0x55, 0x34, 0x6d);
|
||||
WINADAPTER_IID(ID3D12StateObjectProperties, 0xde5fa827, 0x9bf9, 0x4f26, 0x89, 0xff, 0xd7, 0xf5, 0x6f, 0xde, 0x38, 0x60);
|
||||
WINADAPTER_IID(ID3D12Device5, 0x8b4f173b, 0x2fea, 0x4b80, 0x8f, 0x58, 0x43, 0x07, 0x19, 0x1a, 0xb9, 0x5d);
|
||||
WINADAPTER_IID(ID3D12DeviceRemovedExtendedDataSettings, 0x82BC481C, 0x6B9B, 0x4030, 0xAE, 0xDB, 0x7E, 0xE3, 0xD1, 0xDF, 0x1E, 0x63);
|
||||
WINADAPTER_IID(ID3D12DeviceRemovedExtendedDataSettings1, 0xDBD5AE51, 0x3317, 0x4F0A, 0xAD, 0xF9, 0x1D, 0x7C, 0xED, 0xCA, 0xAE, 0x0B);
|
||||
WINADAPTER_IID(ID3D12DeviceRemovedExtendedData, 0x98931D33, 0x5AE8, 0x4791, 0xAA, 0x3C, 0x1A, 0x73, 0xA2, 0x93, 0x4E, 0x71);
|
||||
WINADAPTER_IID(ID3D12DeviceRemovedExtendedData1, 0x9727A022, 0xCF1D, 0x4DDA, 0x9E, 0xBA, 0xEF, 0xFA, 0x65, 0x3F, 0xC5, 0x06);
|
||||
WINADAPTER_IID(ID3D12Device6, 0xc70b221b, 0x40e4, 0x4a17, 0x89, 0xaf, 0x02, 0x5a, 0x07, 0x27, 0xa6, 0xdc);
|
||||
WINADAPTER_IID(ID3D12ProtectedResourceSession1, 0xD6F12DD6, 0x76FB, 0x406E, 0x89, 0x61, 0x42, 0x96, 0xEE, 0xFC, 0x04, 0x09);
|
||||
WINADAPTER_IID(ID3D12Device7, 0x5c014b53, 0x68a1, 0x4b9b, 0x8b, 0xd1, 0xdd, 0x60, 0x46, 0xb9, 0x35, 0x8b);
|
||||
WINADAPTER_IID(ID3D12Device8, 0x9218E6BB, 0xF944, 0x4F7E, 0xA7, 0x5C, 0xB1, 0xB2, 0xC7, 0xB7, 0x01, 0xF3);
|
||||
WINADAPTER_IID(ID3D12Resource1, 0x9D5E227A, 0x4430, 0x4161, 0x88, 0xB3, 0x3E, 0xCA, 0x6B, 0xB1, 0x6E, 0x19);
|
||||
WINADAPTER_IID(ID3D12Resource2, 0xBE36EC3B, 0xEA85, 0x4AEB, 0xA4, 0x5A, 0xE9, 0xD7, 0x64, 0x04, 0xA4, 0x95);
|
||||
WINADAPTER_IID(ID3D12Heap1, 0x572F7389, 0x2168, 0x49E3, 0x96, 0x93, 0xD6, 0xDF, 0x58, 0x71, 0xBF, 0x6D);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList3, 0x6FDA83A7, 0xB84C, 0x4E38, 0x9A, 0xC8, 0xC7, 0xBD, 0x22, 0x01, 0x6B, 0x3D);
|
||||
WINADAPTER_IID(ID3D12MetaCommand, 0xDBB84C27, 0x36CE, 0x4FC9, 0xB8, 0x01, 0xF0, 0x48, 0xC4, 0x6A, 0xC5, 0x70);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList4, 0x8754318e, 0xd3a9, 0x4541, 0x98, 0xcf, 0x64, 0x5b, 0x50, 0xdc, 0x48, 0x74);
|
||||
WINADAPTER_IID(ID3D12ShaderCacheSession, 0x28e2495d, 0x0f64, 0x4ae4, 0xa6, 0xec, 0x12, 0x92, 0x55, 0xdc, 0x49, 0xa8);
|
||||
WINADAPTER_IID(ID3D12Device9, 0x4c80e962, 0xf032, 0x4f60, 0xbc, 0x9e, 0xeb, 0xc2, 0xcf, 0xa1, 0xd8, 0x3c);
|
||||
WINADAPTER_IID(ID3D12Tools, 0x7071e1f0, 0xe84b, 0x4b33, 0x97, 0x4f, 0x12, 0xfa, 0x49, 0xde, 0x65, 0xc5);
|
||||
WINADAPTER_IID(ID3D12SDKConfiguration, 0xe9eb5314, 0x33aa, 0x42b2, 0xa7, 0x18, 0xd7, 0x7f, 0x58, 0xb1, 0xf1, 0xc7);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList5, 0x55050859, 0x4024, 0x474c, 0x87, 0xf5, 0x64, 0x72, 0xea, 0xee, 0x44, 0xea);
|
||||
WINADAPTER_IID(ID3D12GraphicsCommandList6, 0xc3827890, 0xe548, 0x4cfa, 0x96, 0xcf, 0x56, 0x89, 0xa9, 0x37, 0x0f, 0x80);
|
||||
|
||||
#ifdef __d3d12sdklayers_h__
|
||||
WINADAPTER_IID(ID3D12Debug, 0x344488b7, 0x6846, 0x474b, 0xb9, 0x89, 0xf0, 0x27, 0x44, 0x82, 0x45, 0xe0);
|
||||
WINADAPTER_IID(ID3D12Debug1, 0xaffaa4ca, 0x63fe, 0x4d8e, 0xb8, 0xad, 0x15, 0x90, 0x00, 0xaf, 0x43, 0x04);
|
||||
WINADAPTER_IID(ID3D12Debug2, 0x93a665c4, 0xa3b2, 0x4e5d, 0xb6, 0x92, 0xa2, 0x6a, 0xe1, 0x4e, 0x33, 0x74);
|
||||
WINADAPTER_IID(ID3D12Debug3, 0x5cf4e58f, 0xf671, 0x4ff1, 0xa5, 0x42, 0x36, 0x86, 0xe3, 0xd1, 0x53, 0xd1);
|
||||
WINADAPTER_IID(ID3D12Debug4, 0x014b816e, 0x9ec5, 0x4a2f, 0xa8, 0x45, 0xff, 0xbe, 0x44, 0x1c, 0xe1, 0x3a);
|
||||
WINADAPTER_IID(ID3D12DebugDevice1, 0xa9b71770, 0xd099, 0x4a65, 0xa6, 0x98, 0x3d, 0xee, 0x10, 0x02, 0x0f, 0x88);
|
||||
WINADAPTER_IID(ID3D12DebugDevice, 0x3febd6dd, 0x4973, 0x4787, 0x81, 0x94, 0xe4, 0x5f, 0x9e, 0x28, 0x92, 0x3e);
|
||||
WINADAPTER_IID(ID3D12DebugDevice2, 0x60eccbc1, 0x378d, 0x4df1, 0x89, 0x4c, 0xf8, 0xac, 0x5c, 0xe4, 0xd7, 0xdd);
|
||||
WINADAPTER_IID(ID3D12DebugCommandQueue, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3a);
|
||||
WINADAPTER_IID(ID3D12DebugCommandList1, 0x102ca951, 0x311b, 0x4b01, 0xb1, 0x1f, 0xec, 0xb8, 0x3e, 0x06, 0x1b, 0x37);
|
||||
WINADAPTER_IID(ID3D12DebugCommandList, 0x09e0bf36, 0x54ac, 0x484f, 0x88, 0x47, 0x4b, 0xae, 0xea, 0xb6, 0x05, 0x3f);
|
||||
WINADAPTER_IID(ID3D12DebugCommandList2, 0xaeb575cf, 0x4e06, 0x48be, 0xba, 0x3b, 0xc4, 0x50, 0xfc, 0x96, 0x65, 0x2e);
|
||||
WINADAPTER_IID(ID3D12SharingContract, 0x0adf7d52, 0x929c, 0x4e61, 0xad, 0xdb, 0xff, 0xed, 0x30, 0xde, 0x66, 0xef);
|
||||
WINADAPTER_IID(ID3D12InfoQueue, 0x0742a90b, 0xc387, 0x483f, 0xb9, 0x46, 0x30, 0xa7, 0xe4, 0xe6, 0x14, 0x58);
|
||||
#endif
|
||||
|
||||
// DXCore
|
||||
#ifdef __dxcore_interface_h__
|
||||
WINADAPTER_IID(IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06);
|
||||
WINADAPTER_IID(IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28);
|
||||
WINADAPTER_IID(IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e);
|
||||
#endif
|
5
include/wsl/stubs/oaidl.h
Normal file
5
include/wsl/stubs/oaidl.h
Normal file
@ -0,0 +1,5 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub header to satisfy d3d12.h include
|
||||
#pragma once
|
5
include/wsl/stubs/ocidl.h
Normal file
5
include/wsl/stubs/ocidl.h
Normal file
@ -0,0 +1,5 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub header to satisfy d3d12.h include
|
||||
#pragma once
|
5
include/wsl/stubs/rpc.h
Normal file
5
include/wsl/stubs/rpc.h
Normal file
@ -0,0 +1,5 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub header to satisfy d3d12.h include
|
||||
#pragma once
|
6
include/wsl/stubs/rpcndr.h
Normal file
6
include/wsl/stubs/rpcndr.h
Normal file
@ -0,0 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub header to satisfy d3d12.h include
|
||||
#pragma once
|
||||
#define __RPCNDR_H_VERSION__
|
6
include/wsl/stubs/winapifamily.h
Normal file
6
include/wsl/stubs/winapifamily.h
Normal file
@ -0,0 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub header to satisfy d3d12.h include. Unconditionally light up all APIs.
|
||||
#pragma once
|
||||
#define WINAPI_FAMILY_PARTITION(Partitions) 1
|
6
include/wsl/stubs/wrl/client.h
Normal file
6
include/wsl/stubs/wrl/client.h
Normal file
@ -0,0 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub to satisfy d3dx12.h include
|
||||
#pragma once
|
||||
#include "../wrladapter.h"
|
6
include/wsl/stubs/wrl/implements.h
Normal file
6
include/wsl/stubs/wrl/implements.h
Normal file
@ -0,0 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// Stub to satisfy DML TF runtime includes
|
||||
#pragma once
|
||||
#include "wrladapter.h"
|
316
include/wsl/winadapter.h
Normal file
316
include/wsl/winadapter.h
Normal file
@ -0,0 +1,316 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
// These #defines prevent the idl-generated headers from trying to include
|
||||
// Windows.h from the SDK rather than this one.
|
||||
#define RPC_NO_WINDOWS_H
|
||||
#define COM_NO_WINDOWS_H
|
||||
|
||||
// Allcaps type definitions
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
// Note: using fixed-width here to match Windows widths
|
||||
// Specifically this is different for 'long' vs 'LONG'
|
||||
typedef uint8_t UINT8;
|
||||
typedef int8_t INT8;
|
||||
typedef uint16_t UINT16;
|
||||
typedef int16_t INT16;
|
||||
typedef uint32_t UINT32, UINT, ULONG, DWORD, BOOL;
|
||||
typedef int32_t INT32, INT, LONG;
|
||||
typedef uint64_t UINT64;
|
||||
typedef int64_t INT64, LONG_PTR;
|
||||
typedef void VOID, *HANDLE, *RPC_IF_HANDLE, *LPVOID;
|
||||
typedef const void *LPCVOID;
|
||||
typedef size_t SIZE_T;
|
||||
typedef float FLOAT;
|
||||
typedef double DOUBLE;
|
||||
typedef unsigned char BYTE;
|
||||
typedef int HWND;
|
||||
|
||||
// Note: WCHAR is not the same between Windows and Linux, to enable
|
||||
// string manipulation APIs to work with resulting strings.
|
||||
// APIs to D3D/DXCore will work on Linux wchars, but beware with
|
||||
// interactions directly with the Windows kernel.
|
||||
typedef char CHAR, *PSTR, *LPSTR, TCHAR, *PTSTR;
|
||||
typedef const char *LPCSTR, *PCSTR, *LPCTSTR, *PCTSTR;
|
||||
typedef wchar_t WCHAR, *PWSTR, *LPWSTR, *PWCHAR;
|
||||
typedef const wchar_t *LPCWSTR, *PCWSTR;
|
||||
|
||||
#undef LONG_MAX
|
||||
#define LONG_MAX INT_MAX
|
||||
#undef ULONG_MAX
|
||||
#define ULONG_MAX UINT_MAX
|
||||
|
||||
// Misc defines
|
||||
#define interface struct
|
||||
#define MIDL_INTERFACE(x) interface
|
||||
#define __analysis_assume(x)
|
||||
#define TRUE 1u
|
||||
#define FALSE 0u
|
||||
#define DECLARE_INTERFACE(iface) interface iface
|
||||
#define PURE = 0
|
||||
#define THIS_
|
||||
#define DECLSPEC_UUID(x)
|
||||
#define DECLSPEC_NOVTABLE
|
||||
#define DECLSPEC_SELECTANY
|
||||
#define EXTERN_C extern "C"
|
||||
|
||||
typedef struct _GUID {
|
||||
uint32_t Data1;
|
||||
uint16_t Data2;
|
||||
uint16_t Data3;
|
||||
uint8_t Data4[ 8 ];
|
||||
} GUID;
|
||||
|
||||
#ifdef __cplusplus
|
||||
#ifdef INITGUID
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern "C" const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
||||
#else
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern "C" const GUID name
|
||||
#endif
|
||||
|
||||
template <typename T> GUID uuidof() = delete;
|
||||
template <typename T> GUID uuidof(T*) { return uuidof<T>(); }
|
||||
template <typename T> GUID uuidof(T**) { return uuidof<T>(); }
|
||||
template <typename T> GUID uuidof(T&) { return uuidof<T>(); }
|
||||
#define __uuidof(x) uuidof(x)
|
||||
#else
|
||||
#ifdef INITGUID
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) const GUID name = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
|
||||
#else
|
||||
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) extern const GUID name
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef GUID IID;
|
||||
typedef GUID UUID;
|
||||
typedef GUID CLSID;
|
||||
#ifdef __cplusplus
|
||||
#define REFGUID const GUID &
|
||||
#define REFIID const IID &
|
||||
#define REFCLSID const IID &
|
||||
|
||||
__inline int InlineIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
|
||||
{
|
||||
return (
|
||||
((uint32_t *)&rguid1)[0] == ((uint32_t *)&rguid2)[0] &&
|
||||
((uint32_t *)&rguid1)[1] == ((uint32_t *)&rguid2)[1] &&
|
||||
((uint32_t *)&rguid1)[2] == ((uint32_t *)&rguid2)[2] &&
|
||||
((uint32_t *)&rguid1)[3] == ((uint32_t *)&rguid2)[3]);
|
||||
}
|
||||
#else
|
||||
#define REFGUID const GUID *
|
||||
#define REFIID const IID *
|
||||
#define REFCLSID const IID *
|
||||
#endif
|
||||
|
||||
// SAL annotations
|
||||
#define _In_
|
||||
#define _In_z_
|
||||
#define _In_opt_
|
||||
#define _In_opt_z_
|
||||
#define _In_reads_(x)
|
||||
#define _In_reads_opt_(x)
|
||||
#define _In_reads_bytes_(x)
|
||||
#define _In_reads_bytes_opt_(x)
|
||||
#define _In_range_(x, y)
|
||||
#define _In_bytecount_(x)
|
||||
#define _Out_
|
||||
#define _Out_opt_
|
||||
#define _Outptr_
|
||||
#define _Outptr_opt_result_z_
|
||||
#define _Outptr_opt_result_bytebuffer_(x)
|
||||
#define _COM_Outptr_
|
||||
#define _COM_Outptr_result_maybenull_
|
||||
#define _COM_Outptr_opt_
|
||||
#define _COM_Outptr_opt_result_maybenull_
|
||||
#define _Out_writes_(x)
|
||||
#define _Out_writes_z_(x)
|
||||
#define _Out_writes_opt_(x)
|
||||
#define _Out_writes_all_(x)
|
||||
#define _Out_writes_all_opt_(x)
|
||||
#define _Out_writes_to_opt_(x, y)
|
||||
#define _Out_writes_bytes_(x)
|
||||
#define _Out_writes_bytes_all_(x)
|
||||
#define _Out_writes_bytes_all_opt_(x)
|
||||
#define _Out_writes_bytes_opt_(x)
|
||||
#define _Inout_
|
||||
#define _Inout_opt_
|
||||
#define _Inout_updates_(x)
|
||||
#define _Inout_updates_bytes_(x)
|
||||
#define _Field_size_(x)
|
||||
#define _Field_size_opt_(x)
|
||||
#define _Field_size_bytes_(x)
|
||||
#define _Field_size_full_(x)
|
||||
#define _Field_size_bytes_full_(x)
|
||||
#define _Field_size_bytes_full_opt_(x)
|
||||
#define _Field_size_bytes_part_(x, y)
|
||||
#define _Field_range_(x, y)
|
||||
#define _Field_z_
|
||||
#define _Check_return_
|
||||
#define _IRQL_requires_(x)
|
||||
#define _IRQL_requires_min_(x)
|
||||
#define _IRQL_requires_max_(x)
|
||||
#define _At_(x, y)
|
||||
#define _Always_(x)
|
||||
#define _Return_type_success_(x)
|
||||
#define _Translates_Win32_to_HRESULT_(x)
|
||||
#define _Maybenull_
|
||||
#define _Outptr_result_maybenull_
|
||||
#define _Outptr_result_nullonfailure_
|
||||
#define _Analysis_assume_(x)
|
||||
#define _Success_(x)
|
||||
#define _In_count_(x)
|
||||
#define _In_opt_count_(x)
|
||||
|
||||
// Calling conventions
|
||||
#define __stdcall
|
||||
#define STDMETHODCALLTYPE
|
||||
#define STDAPICALLTYPE
|
||||
#define STDAPI extern "C" HRESULT STDAPICALLTYPE
|
||||
#define WINAPI
|
||||
#define STDMETHOD(name) virtual HRESULT name
|
||||
#define STDMETHOD_(type,name) virtual type name
|
||||
#define IFACEMETHOD(method) /*__override*/ STDMETHOD(method)
|
||||
#define IFACEMETHOD_(type, method) /*__override*/ STDMETHOD_(type, method)
|
||||
|
||||
// Error codes
|
||||
typedef LONG HRESULT;
|
||||
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
|
||||
#define FAILED(hr) (((HRESULT)(hr)) < 0)
|
||||
#define S_OK ((HRESULT)0L)
|
||||
#define E_OUTOFMEMORY 0x80000002L
|
||||
#define E_INVALIDARG 0x80000003L
|
||||
#define E_NOINTERFACE 0x80000004L
|
||||
#define DXGI_ERROR_DEVICE_HUNG ((HRESULT)0x887A0006L)
|
||||
#define DXGI_ERROR_DEVICE_REMOVED ((HRESULT)0x887A0005L)
|
||||
#define DXGI_ERROR_DEVICE_RESET ((HRESULT)0x887A0007L)
|
||||
#define DXGI_ERROR_DRIVER_INTERNAL_ERROR ((HRESULT)0x887A0020L)
|
||||
#define DXGI_ERROR_INVALID_CALL ((HRESULT)0x887A0001L)
|
||||
|
||||
struct LUID
|
||||
{
|
||||
ULONG LowPart;
|
||||
LONG HighPart;
|
||||
};
|
||||
|
||||
struct RECT
|
||||
{
|
||||
int left;
|
||||
int top;
|
||||
int right;
|
||||
int bottom;
|
||||
};
|
||||
|
||||
typedef union _LARGE_INTEGER {
|
||||
struct {
|
||||
uint32_t LowPart;
|
||||
uint32_t HighPart;
|
||||
} u;
|
||||
int64_t QuadPart;
|
||||
} LARGE_INTEGER;
|
||||
|
||||
typedef union _ULARGE_INTEGER {
|
||||
struct {
|
||||
uint32_t LowPart;
|
||||
uint32_t HighPart;
|
||||
} u;
|
||||
uint64_t QuadPart;
|
||||
} ULARGE_INTEGER;
|
||||
|
||||
struct SECURITY_ATTRIBUTES;
|
||||
struct STATSTG;
|
||||
|
||||
#ifdef __cplusplus
|
||||
// ENUM_FLAG_OPERATORS
|
||||
// Define operator overloads to enable bit operations on enum values that are
|
||||
// used to define flags. Use DEFINE_ENUM_FLAG_OPERATORS(YOUR_TYPE) to enable these
|
||||
// operators on YOUR_TYPE.
|
||||
extern "C++" {
|
||||
template <size_t S>
|
||||
struct _ENUM_FLAG_INTEGER_FOR_SIZE;
|
||||
|
||||
template <>
|
||||
struct _ENUM_FLAG_INTEGER_FOR_SIZE<1>
|
||||
{
|
||||
typedef int8_t type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct _ENUM_FLAG_INTEGER_FOR_SIZE<2>
|
||||
{
|
||||
typedef int16_t type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct _ENUM_FLAG_INTEGER_FOR_SIZE<4>
|
||||
{
|
||||
typedef int32_t type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct _ENUM_FLAG_INTEGER_FOR_SIZE<8>
|
||||
{
|
||||
typedef int64_t type;
|
||||
};
|
||||
|
||||
// used as an approximation of std::underlying_type<T>
|
||||
template <class T>
|
||||
struct _ENUM_FLAG_SIZED_INTEGER
|
||||
{
|
||||
typedef typename _ENUM_FLAG_INTEGER_FOR_SIZE<sizeof(T)>::type type;
|
||||
};
|
||||
|
||||
}
|
||||
#define DEFINE_ENUM_FLAG_OPERATORS(ENUMTYPE) \
|
||||
extern "C++" { \
|
||||
inline constexpr ENUMTYPE operator | (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) | ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
inline ENUMTYPE &operator |= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) |= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
inline constexpr ENUMTYPE operator & (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) & ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
inline ENUMTYPE &operator &= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) &= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
inline constexpr ENUMTYPE operator ~ (ENUMTYPE a) { return ENUMTYPE(~((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a)); } \
|
||||
inline constexpr ENUMTYPE operator ^ (ENUMTYPE a, ENUMTYPE b) { return ENUMTYPE(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)a) ^ ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
inline ENUMTYPE &operator ^= (ENUMTYPE &a, ENUMTYPE b) { return (ENUMTYPE &)(((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type &)a) ^= ((_ENUM_FLAG_SIZED_INTEGER<ENUMTYPE>::type)b)); } \
|
||||
}
|
||||
#endif
|
||||
|
||||
// D3DX12 uses these
|
||||
#include <stdlib.h>
|
||||
#define HeapAlloc(heap, flags, size) malloc(size)
|
||||
#define HeapFree(heap, flags, ptr) free(ptr)
|
||||
|
||||
#ifdef __cplusplus
|
||||
// IUnknown
|
||||
|
||||
interface DECLSPEC_UUID("00000000-0000-0000-C000-000000000046") DECLSPEC_NOVTABLE IUnknown
|
||||
{
|
||||
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) = 0;
|
||||
virtual ULONG STDMETHODCALLTYPE AddRef() = 0;
|
||||
virtual ULONG STDMETHODCALLTYPE Release() = 0;
|
||||
|
||||
template <class Q> HRESULT STDMETHODCALLTYPE QueryInterface(Q** pp) {
|
||||
return QueryInterface(uuidof<Q>(), (void **)pp);
|
||||
}
|
||||
};
|
||||
|
||||
template <> constexpr GUID uuidof<IUnknown>()
|
||||
{
|
||||
return { 0x00000000, 0x0000, 0x0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
|
||||
}
|
||||
|
||||
extern "C++"
|
||||
{
|
||||
template<typename T> void** IID_PPV_ARGS_Helper(T** pp)
|
||||
{
|
||||
static_cast<IUnknown*>(*pp);
|
||||
return reinterpret_cast<void**>(pp);
|
||||
}
|
||||
}
|
||||
|
||||
#define IID_PPV_ARGS(ppType) __uuidof(**(ppType)), IID_PPV_ARGS_Helper(ppType)
|
||||
#endif
|
805
include/wsl/wrladapter.h
Normal file
805
include/wsl/wrladapter.h
Normal file
@ -0,0 +1,805 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "winadapter.h"
|
||||
|
||||
// defined by winadapter.h and needed by some windows headers, but conflicts
|
||||
// with some libc++ implementation headers
|
||||
#ifdef __out
|
||||
#undef __out
|
||||
#endif
|
||||
|
||||
#include <type_traits>
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
#include <climits>
|
||||
#include <cassert>
|
||||
|
||||
namespace Microsoft
|
||||
{
|
||||
namespace WRL
|
||||
{
|
||||
namespace Details
|
||||
{
|
||||
struct BoolStruct { int Member; };
|
||||
typedef int BoolStruct::* BoolType;
|
||||
|
||||
template <typename T> // T should be the ComPtr<T> or a derived type of it, not just the interface
|
||||
class ComPtrRefBase
|
||||
{
|
||||
public:
|
||||
typedef typename T::InterfaceType InterfaceType;
|
||||
|
||||
operator IUnknown**() const throw()
|
||||
{
|
||||
static_assert(__is_base_of(IUnknown, InterfaceType), "Invalid cast: InterfaceType does not derive from IUnknown");
|
||||
return reinterpret_cast<IUnknown**>(ptr_->ReleaseAndGetAddressOf());
|
||||
}
|
||||
|
||||
protected:
|
||||
T* ptr_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class ComPtrRef : public Details::ComPtrRefBase<T> // T should be the ComPtr<T> or a derived type of it, not just the interface
|
||||
{
|
||||
using Super = Details::ComPtrRefBase<T>;
|
||||
using InterfaceType = typename Super::InterfaceType;
|
||||
public:
|
||||
ComPtrRef(_In_opt_ T* ptr) throw()
|
||||
{
|
||||
this->ptr_ = ptr;
|
||||
}
|
||||
|
||||
// Conversion operators
|
||||
operator void**() const throw()
|
||||
{
|
||||
return reinterpret_cast<void**>(this->ptr_->ReleaseAndGetAddressOf());
|
||||
}
|
||||
|
||||
// This is our operator ComPtr<U> (or the latest derived class from ComPtr (e.g. WeakRef))
|
||||
operator T*() throw()
|
||||
{
|
||||
*this->ptr_ = nullptr;
|
||||
return this->ptr_;
|
||||
}
|
||||
|
||||
// We define operator InterfaceType**() here instead of on ComPtrRefBase<T>, since
|
||||
// if InterfaceType is IUnknown or IInspectable, having it on the base will collide.
|
||||
operator InterfaceType**() throw()
|
||||
{
|
||||
return this->ptr_->ReleaseAndGetAddressOf();
|
||||
}
|
||||
|
||||
// This is used for IID_PPV_ARGS in order to do __uuidof(**(ppType)).
|
||||
// It does not need to clear ptr_ at this point, it is done at IID_PPV_ARGS_Helper(ComPtrRef&) later in this file.
|
||||
InterfaceType* operator *() throw()
|
||||
{
|
||||
return this->ptr_->Get();
|
||||
}
|
||||
|
||||
// Explicit functions
|
||||
InterfaceType* const * GetAddressOf() const throw()
|
||||
{
|
||||
return this->ptr_->GetAddressOf();
|
||||
}
|
||||
|
||||
InterfaceType** ReleaseAndGetAddressOf() throw()
|
||||
{
|
||||
return this->ptr_->ReleaseAndGetAddressOf();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class ComPtr
|
||||
{
|
||||
public:
|
||||
typedef T InterfaceType;
|
||||
|
||||
protected:
|
||||
InterfaceType *ptr_;
|
||||
template<class U> friend class ComPtr;
|
||||
|
||||
void InternalAddRef() const throw()
|
||||
{
|
||||
if (ptr_ != nullptr)
|
||||
{
|
||||
ptr_->AddRef();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long InternalRelease() throw()
|
||||
{
|
||||
unsigned long ref = 0;
|
||||
T* temp = ptr_;
|
||||
|
||||
if (temp != nullptr)
|
||||
{
|
||||
ptr_ = nullptr;
|
||||
ref = temp->Release();
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
public:
|
||||
#pragma region constructors
|
||||
ComPtr() throw() : ptr_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
ComPtr(decltype(nullptr)) throw() : ptr_(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
template<class U>
|
||||
ComPtr(_In_opt_ U *other) throw() : ptr_(other)
|
||||
{
|
||||
InternalAddRef();
|
||||
}
|
||||
|
||||
ComPtr(const ComPtr& other) throw() : ptr_(other.ptr_)
|
||||
{
|
||||
InternalAddRef();
|
||||
}
|
||||
|
||||
// copy constructor that allows to instantiate class when U* is convertible to T*
|
||||
template<class U>
|
||||
ComPtr(const ComPtr<U> &other, typename std::enable_if<std::is_convertible<U*, T*>::value, void *>::type * = 0) throw() :
|
||||
ptr_(other.ptr_)
|
||||
{
|
||||
InternalAddRef();
|
||||
}
|
||||
|
||||
ComPtr(_Inout_ ComPtr &&other) throw() : ptr_(nullptr)
|
||||
{
|
||||
if (this != reinterpret_cast<ComPtr*>(&reinterpret_cast<unsigned char&>(other)))
|
||||
{
|
||||
Swap(other);
|
||||
}
|
||||
}
|
||||
|
||||
// Move constructor that allows instantiation of a class when U* is convertible to T*
|
||||
template<class U>
|
||||
ComPtr(_Inout_ ComPtr<U>&& other, typename std::enable_if<std::is_convertible<U*, T*>::value, void *>::type * = 0) throw() :
|
||||
ptr_(other.ptr_)
|
||||
{
|
||||
other.ptr_ = nullptr;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region destructor
|
||||
~ComPtr() throw()
|
||||
{
|
||||
InternalRelease();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region assignment
|
||||
ComPtr& operator=(decltype(nullptr)) throw()
|
||||
{
|
||||
InternalRelease();
|
||||
return *this;
|
||||
}
|
||||
|
||||
ComPtr& operator=(_In_opt_ T *other) throw()
|
||||
{
|
||||
if (ptr_ != other)
|
||||
{
|
||||
ComPtr(other).Swap(*this);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
ComPtr& operator=(_In_opt_ U *other) throw()
|
||||
{
|
||||
ComPtr(other).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ComPtr& operator=(const ComPtr &other) throw()
|
||||
{
|
||||
if (ptr_ != other.ptr_)
|
||||
{
|
||||
ComPtr(other).Swap(*this);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
ComPtr& operator=(const ComPtr<U>& other) throw()
|
||||
{
|
||||
ComPtr(other).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ComPtr& operator=(_Inout_ ComPtr &&other) throw()
|
||||
{
|
||||
ComPtr(static_cast<ComPtr&&>(other)).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class U>
|
||||
ComPtr& operator=(_Inout_ ComPtr<U>&& other) throw()
|
||||
{
|
||||
ComPtr(static_cast<ComPtr<U>&&>(other)).Swap(*this);
|
||||
return *this;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region modifiers
|
||||
void Swap(_Inout_ ComPtr&& r) throw()
|
||||
{
|
||||
T* tmp = ptr_;
|
||||
ptr_ = r.ptr_;
|
||||
r.ptr_ = tmp;
|
||||
}
|
||||
|
||||
void Swap(_Inout_ ComPtr& r) throw()
|
||||
{
|
||||
T* tmp = ptr_;
|
||||
ptr_ = r.ptr_;
|
||||
r.ptr_ = tmp;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
operator Details::BoolType() const throw()
|
||||
{
|
||||
return Get() != nullptr ? &Details::BoolStruct::Member : nullptr;
|
||||
}
|
||||
|
||||
T* Get() const throw()
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
InterfaceType* operator->() const throw()
|
||||
{
|
||||
return ptr_;
|
||||
}
|
||||
|
||||
Details::ComPtrRef<ComPtr<T>> operator&() throw()
|
||||
{
|
||||
return Details::ComPtrRef<ComPtr<T>>(this);
|
||||
}
|
||||
|
||||
const Details::ComPtrRef<const ComPtr<T>> operator&() const throw()
|
||||
{
|
||||
return Details::ComPtrRef<const ComPtr<T>>(this);
|
||||
}
|
||||
|
||||
T* const* GetAddressOf() const throw()
|
||||
{
|
||||
return &ptr_;
|
||||
}
|
||||
|
||||
T** GetAddressOf() throw()
|
||||
{
|
||||
return &ptr_;
|
||||
}
|
||||
|
||||
T** ReleaseAndGetAddressOf() throw()
|
||||
{
|
||||
InternalRelease();
|
||||
return &ptr_;
|
||||
}
|
||||
|
||||
T* Detach() throw()
|
||||
{
|
||||
T* ptr = ptr_;
|
||||
ptr_ = nullptr;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void Attach(_In_opt_ InterfaceType* other) throw()
|
||||
{
|
||||
if (ptr_ != nullptr)
|
||||
{
|
||||
auto ref = ptr_->Release();
|
||||
// DBG_UNREFERENCED_LOCAL_VARIABLE(ref);
|
||||
// Attaching to the same object only works if duplicate references are being coalesced. Otherwise
|
||||
// re-attaching will cause the pointer to be released and may cause a crash on a subsequent dereference.
|
||||
assert(ref != 0 || ptr_ != other);
|
||||
}
|
||||
|
||||
ptr_ = other;
|
||||
}
|
||||
|
||||
unsigned long Reset()
|
||||
{
|
||||
return InternalRelease();
|
||||
}
|
||||
|
||||
// Previously, unsafe behavior could be triggered when 'this' is ComPtr<IInspectable> or ComPtr<IUnknown> and CopyTo is used to copy to another type U.
|
||||
// The user will use operator& to convert the destination into a ComPtrRef, which can then implicit cast to IInspectable** and IUnknown**.
|
||||
// If this overload of CopyTo is not present, it will implicitly cast to IInspectable or IUnknown and match CopyTo(InterfaceType**) instead.
|
||||
// A valid polymoprhic downcast requires run-time type checking via QueryInterface, so CopyTo(InterfaceType**) will break type safety.
|
||||
// This overload matches ComPtrRef before the implicit cast takes place, preventing the unsafe downcast.
|
||||
template <typename U>
|
||||
HRESULT CopyTo(Details::ComPtrRef<ComPtr<U>> ptr, typename std::enable_if<
|
||||
(std::is_same<T, IUnknown>::value)
|
||||
&& !std::is_same<U*, T*>::value, void *>::type * = 0) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(uuidof<U>(), ptr);
|
||||
}
|
||||
|
||||
HRESULT CopyTo(_Outptr_result_maybenull_ InterfaceType** ptr) const throw()
|
||||
{
|
||||
InternalAddRef();
|
||||
*ptr = ptr_;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CopyTo(REFIID riid, _Outptr_result_nullonfailure_ void** ptr) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(riid, ptr);
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
HRESULT CopyTo(_Outptr_result_nullonfailure_ U** ptr) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(uuidof<U>(), reinterpret_cast<void**>(ptr));
|
||||
}
|
||||
|
||||
// query for U interface
|
||||
template<typename U>
|
||||
HRESULT As(_Inout_ Details::ComPtrRef<ComPtr<U>> p) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(uuidof<U>(), p);
|
||||
}
|
||||
|
||||
// query for U interface
|
||||
template<typename U>
|
||||
HRESULT As(_Out_ ComPtr<U>* p) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(uuidof<U>(), reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
|
||||
}
|
||||
|
||||
// query for riid interface and return as IUnknown
|
||||
HRESULT AsIID(REFIID riid, _Out_ ComPtr<IUnknown>* p) const throw()
|
||||
{
|
||||
return ptr_->QueryInterface(riid, reinterpret_cast<void**>(p->ReleaseAndGetAddressOf()));
|
||||
}
|
||||
|
||||
}; // ComPtr
|
||||
|
||||
|
||||
namespace Details
|
||||
{
|
||||
// Empty struct used as default template parameter
|
||||
class Nil
|
||||
{
|
||||
};
|
||||
|
||||
// Empty struct used for validating template parameter types in Implements
|
||||
struct ImplementsBase
|
||||
{
|
||||
};
|
||||
|
||||
class RuntimeClassBase
|
||||
{
|
||||
protected:
|
||||
template<typename T>
|
||||
static HRESULT AsIID(_In_ T* implements, REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject) noexcept
|
||||
{
|
||||
*ppvObject = nullptr;
|
||||
bool isRefDelegated = false;
|
||||
// Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
|
||||
if (InlineIsEqualGUID(riid, uuidof<IUnknown>()))
|
||||
{
|
||||
*ppvObject = implements->CastToUnknown();
|
||||
static_cast<IUnknown*>(*ppvObject)->AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT hr = implements->CanCastTo(riid, ppvObject, &isRefDelegated);
|
||||
if (SUCCEEDED(hr) && !isRefDelegated)
|
||||
{
|
||||
static_cast<IUnknown*>(*ppvObject)->AddRef();
|
||||
}
|
||||
|
||||
#pragma warning(suppress: 6102) // '*ppvObject' is used but may not be initialized
|
||||
_Analysis_assume_(SUCCEEDED(hr) || (*ppvObject == nullptr));
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
public:
|
||||
HRESULT RuntimeClassInitialize() noexcept
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
};
|
||||
|
||||
// Interface traits provides casting and filling iids methods helpers
|
||||
template<typename I0>
|
||||
struct InterfaceTraits
|
||||
{
|
||||
typedef I0 Base;
|
||||
|
||||
template<typename T>
|
||||
static Base* CastToBase(_In_ T* ptr) noexcept
|
||||
{
|
||||
return static_cast<Base*>(ptr);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static IUnknown* CastToUnknown(_In_ T* ptr) noexcept
|
||||
{
|
||||
return static_cast<IUnknown*>(static_cast<Base*>(ptr));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
_Success_(return == true)
|
||||
static bool CanCastTo(_In_ T* ptr, REFIID riid, _Outptr_ void **ppv) noexcept
|
||||
{
|
||||
// Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
|
||||
if (InlineIsEqualGUID(riid, uuidof<Base>()))
|
||||
{
|
||||
*ppv = static_cast<Base*>(ptr);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for Nil parameter
|
||||
template<>
|
||||
struct InterfaceTraits<Nil>
|
||||
{
|
||||
typedef Nil Base;
|
||||
|
||||
template <typename T>
|
||||
_Success_(return == true)
|
||||
static bool CanCastTo(_In_ T*, REFIID, _Outptr_ void **) noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
// ChainInterfaces - template allows specifying a derived COM interface along with its class hierarchy to allow QI for the base interfaces
|
||||
template <typename I0, typename I1, typename I2 = Nil, typename I3 = Nil,
|
||||
typename I4 = Nil, typename I5 = Nil, typename I6 = Nil,
|
||||
typename I7 = Nil, typename I8 = Nil, typename I9 = Nil>
|
||||
struct ChainInterfaces : I0
|
||||
{
|
||||
protected:
|
||||
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) throw()
|
||||
{
|
||||
typename InterfaceTraits<I0>::Base* ptr = InterfaceTraits<I0>::CastToBase(this);
|
||||
|
||||
return (InterfaceTraits<I0>::CanCastTo(this, riid, ppv) ||
|
||||
InterfaceTraits<I1>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I2>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I3>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I4>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I5>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I6>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I7>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I8>::CanCastTo(ptr, riid, ppv) ||
|
||||
InterfaceTraits<I9>::CanCastTo(ptr, riid, ppv)) ? S_OK : E_NOINTERFACE;
|
||||
}
|
||||
|
||||
IUnknown* CastToUnknown() throw()
|
||||
{
|
||||
return InterfaceTraits<I0>::CastToUnknown(this);
|
||||
}
|
||||
};
|
||||
|
||||
#pragma region Implements helper templates
|
||||
|
||||
// Helper template used by Implements. This template traverses a list of interfaces and adds them as base class and information
|
||||
// to enable QI.
|
||||
template <typename ...TInterfaces>
|
||||
struct ImplementsHelper;
|
||||
|
||||
template <typename T>
|
||||
struct ImplementsMarker
|
||||
{};
|
||||
|
||||
template <typename I0, bool isImplements>
|
||||
struct MarkImplements;
|
||||
|
||||
template <typename I0>
|
||||
struct MarkImplements<I0, false>
|
||||
{
|
||||
typedef I0 Type;
|
||||
};
|
||||
|
||||
template <typename I0>
|
||||
struct MarkImplements<I0, true>
|
||||
{
|
||||
typedef ImplementsMarker<I0> Type;
|
||||
};
|
||||
|
||||
// AdjustImplements pre-processes the type list for more efficient builds.
|
||||
template <typename ...Bases>
|
||||
struct AdjustImplements;
|
||||
|
||||
template <typename I0, typename ...Bases>
|
||||
struct AdjustImplements<I0, Bases...>
|
||||
{
|
||||
typedef ImplementsHelper<typename MarkImplements<I0, std::is_base_of<ImplementsBase, I0>::value>::Type, Bases...> Type;
|
||||
};
|
||||
|
||||
// Use AdjustImplements to remove instances of "Nil" from the type list.
|
||||
template <typename ...Bases>
|
||||
struct AdjustImplements<Nil, Bases...>
|
||||
{
|
||||
typedef typename AdjustImplements<Bases...>::Type Type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct AdjustImplements<>
|
||||
{
|
||||
typedef ImplementsHelper<> Type;
|
||||
};
|
||||
|
||||
// Specialization handles unadorned interfaces
|
||||
template <typename I0, typename ...TInterfaces>
|
||||
struct ImplementsHelper<I0, TInterfaces...> :
|
||||
I0,
|
||||
AdjustImplements<TInterfaces...>::Type
|
||||
{
|
||||
template <typename ...> friend struct ImplementsHelper;
|
||||
friend class RuntimeClassBase;
|
||||
|
||||
protected:
|
||||
|
||||
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
|
||||
{
|
||||
// Prefer InlineIsEqualGUID over other forms since it's better perf on 4-byte aligned data, which is almost always the case.
|
||||
if (InlineIsEqualGUID(riid, uuidof<I0>()))
|
||||
{
|
||||
*ppv = reinterpret_cast<I0*>(reinterpret_cast<void*>(this));
|
||||
return S_OK;
|
||||
}
|
||||
return AdjustImplements<TInterfaces...>::Type::CanCastTo(riid, ppv, pRefDelegated);
|
||||
}
|
||||
|
||||
IUnknown* CastToUnknown() noexcept
|
||||
{
|
||||
return reinterpret_cast<I0*>(reinterpret_cast<void*>(this));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Selector is used to "tag" base interfaces to be used in casting, since a runtime class may indirectly derive from
|
||||
// the same interface or Implements<> template multiple times
|
||||
template <typename base, typename disciminator>
|
||||
struct Selector : public base
|
||||
{
|
||||
};
|
||||
|
||||
// Specialization handles types that derive from ImplementsHelper (e.g. nested Implements).
|
||||
template <typename I0, typename ...TInterfaces>
|
||||
struct ImplementsHelper<ImplementsMarker<I0>, TInterfaces...> :
|
||||
Selector<I0, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>>,
|
||||
Selector<typename AdjustImplements<TInterfaces...>::Type, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>>
|
||||
{
|
||||
template <typename ...> friend struct ImplementsHelper;
|
||||
friend class RuntimeClassBase;
|
||||
|
||||
protected:
|
||||
typedef Selector<I0, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>> CurrentType;
|
||||
typedef Selector<typename AdjustImplements<TInterfaces...>::Type, ImplementsHelper<ImplementsMarker<I0>, TInterfaces...>> BaseType;
|
||||
|
||||
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
|
||||
{
|
||||
HRESULT hr = CurrentType::CanCastTo(riid, ppv);
|
||||
if (hr == E_NOINTERFACE)
|
||||
{
|
||||
hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
|
||||
}
|
||||
return hr;
|
||||
}
|
||||
|
||||
IUnknown* CastToUnknown() noexcept
|
||||
{
|
||||
// First in list wins.
|
||||
return CurrentType::CastToUnknown();
|
||||
}
|
||||
};
|
||||
|
||||
// terminal case specialization.
|
||||
template <>
|
||||
struct ImplementsHelper<>
|
||||
{
|
||||
template <typename ...> friend struct ImplementsHelper;
|
||||
friend class RuntimeClassBase;
|
||||
|
||||
protected:
|
||||
HRESULT CanCastTo(_In_ REFIID /*riid*/, _Outptr_ void ** /*ppv*/, bool * /*pRefDelegated*/ = nullptr) noexcept
|
||||
{
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
// IUnknown* CastToUnknown() noexcept; // not defined for terminal case.
|
||||
};
|
||||
|
||||
// Specialization handles chaining interfaces
|
||||
template <typename C0, typename C1, typename C2, typename C3, typename C4, typename C5, typename C6, typename C7, typename C8, typename C9, typename ...TInterfaces>
|
||||
struct ImplementsHelper<ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>, TInterfaces...> :
|
||||
ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>,
|
||||
AdjustImplements<TInterfaces...>::Type
|
||||
{
|
||||
template <typename ...> friend struct ImplementsHelper;
|
||||
friend class RuntimeClassBase;
|
||||
|
||||
protected:
|
||||
typedef typename AdjustImplements<TInterfaces...>::Type BaseType;
|
||||
|
||||
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv, bool *pRefDelegated = nullptr) noexcept
|
||||
{
|
||||
HRESULT hr = ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::CanCastTo(riid, ppv);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
hr = BaseType::CanCastTo(riid, ppv, pRefDelegated);
|
||||
}
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
IUnknown* CastToUnknown() noexcept
|
||||
{
|
||||
return ChainInterfaces<C0, C1, C2, C3, C4, C5, C6, C7, C8, C9>::CastToUnknown();
|
||||
}
|
||||
};
|
||||
|
||||
#pragma endregion // Implements helper templates
|
||||
|
||||
// Implements - template implementing QI using the information provided through its template parameters
|
||||
// Each template parameter has to be one of the following:
|
||||
// * COM Interface
|
||||
// * A class that implements one or more COM interfaces
|
||||
// * ChainInterfaces template
|
||||
template <typename I0, typename ...TInterfaces>
|
||||
struct Implements :
|
||||
AdjustImplements<I0, TInterfaces...>::Type,
|
||||
ImplementsBase
|
||||
{
|
||||
public:
|
||||
typedef I0 FirstInterface;
|
||||
protected:
|
||||
typedef typename AdjustImplements<I0, TInterfaces...>::Type BaseType;
|
||||
template <typename ...> friend struct ImplementsHelper;
|
||||
friend class RuntimeClassBase;
|
||||
|
||||
HRESULT CanCastTo(REFIID riid, _Outptr_ void **ppv) noexcept
|
||||
{
|
||||
return BaseType::CanCastTo(riid, ppv);
|
||||
}
|
||||
|
||||
IUnknown* CastToUnknown() noexcept
|
||||
{
|
||||
return BaseType::CastToUnknown();
|
||||
}
|
||||
};
|
||||
|
||||
// Used on RuntimeClass to protect it from being constructed with new
|
||||
class DontUseNewUseMake
|
||||
{
|
||||
private:
|
||||
void* operator new(size_t) noexcept
|
||||
{
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
void* operator new(size_t, _In_ void* placement) noexcept
|
||||
{
|
||||
return placement;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ...TInterfaces>
|
||||
class RuntimeClassImpl :
|
||||
public AdjustImplements<TInterfaces...>::Type,
|
||||
public RuntimeClassBase,
|
||||
public DontUseNewUseMake
|
||||
{
|
||||
public:
|
||||
STDMETHOD(QueryInterface)(REFIID riid, _Outptr_result_nullonfailure_ void **ppvObject)
|
||||
{
|
||||
return Super::AsIID(this, riid, ppvObject);
|
||||
}
|
||||
|
||||
STDMETHOD_(ULONG, AddRef)()
|
||||
{
|
||||
return InternalAddRef();
|
||||
}
|
||||
|
||||
STDMETHOD_(ULONG, Release)()
|
||||
{
|
||||
ULONG ref = InternalRelease();
|
||||
if (ref == 0)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
protected:
|
||||
using Super = RuntimeClassBase;
|
||||
static const LONG c_lProtectDestruction = -(LONG_MAX / 2);
|
||||
|
||||
RuntimeClassImpl() noexcept = default;
|
||||
|
||||
virtual ~RuntimeClassImpl() noexcept
|
||||
{
|
||||
// Set refcount_ to -(LONG_MAX/2) to protect destruction and
|
||||
// also catch mismatched Release in debug builds
|
||||
refcount_ = static_cast<ULONG>(c_lProtectDestruction);
|
||||
}
|
||||
|
||||
ULONG InternalAddRef() noexcept
|
||||
{
|
||||
return ++refcount_;
|
||||
}
|
||||
|
||||
ULONG InternalRelease() noexcept
|
||||
{
|
||||
return --refcount_;
|
||||
}
|
||||
|
||||
unsigned long GetRefCount() const noexcept
|
||||
{
|
||||
return refcount_;
|
||||
}
|
||||
|
||||
std::atomic<ULONG> refcount_{1};
|
||||
};
|
||||
}
|
||||
|
||||
template <typename ...TInterfaces>
|
||||
class Base : public Details::RuntimeClassImpl<TInterfaces...>
|
||||
{
|
||||
Base(const Base&) = delete;
|
||||
Base& operator=(const Base&) = delete;
|
||||
|
||||
protected:
|
||||
HRESULT CustomQueryInterface(REFIID /*riid*/, _Outptr_result_nullonfailure_ void** /*ppvObject*/, _Out_ bool *handled)
|
||||
{
|
||||
*handled = false;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
public:
|
||||
Base() throw() = default;
|
||||
typedef Base RuntimeClassT;
|
||||
};
|
||||
|
||||
// Creates a Nano-COM object wrapped in a smart pointer.
|
||||
template <typename T, typename ...TArgs>
|
||||
ComPtr<T> Make(TArgs&&... args)
|
||||
{
|
||||
ComPtr<T> object;
|
||||
|
||||
std::unique_ptr<unsigned char[]> buffer(new unsigned char[sizeof(T)]);
|
||||
if (buffer)
|
||||
{
|
||||
T* ptr = new (buffer.get())T(std::forward<TArgs>(args)...);
|
||||
object.Attach(ptr);
|
||||
buffer.release();
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
using Details::ChainInterfaces;
|
||||
}
|
||||
}
|
||||
|
||||
// Overloaded global function to provide to IID_PPV_ARGS that support Details::ComPtrRef
|
||||
template<typename T>
|
||||
void** IID_PPV_ARGS_Helper(Microsoft::WRL::Details::ComPtrRef<T> pp) throw()
|
||||
{
|
||||
return pp;
|
||||
}
|
28
meson.build
Normal file
28
meson.build
Normal file
@ -0,0 +1,28 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
project('DirectX-Headers', 'cpp', version : '1.0')
|
||||
|
||||
inc_dirs = [include_directories('include', is_system : true)]
|
||||
install_inc_subdirs = ['']
|
||||
|
||||
if host_machine.system() != 'windows'
|
||||
inc_dirs += include_directories('include/wsl/stubs', is_system : true)
|
||||
install_inc_subdirs += ['', 'wsl/stubs', 'directx']
|
||||
endif
|
||||
|
||||
guids_lib = static_library('DirectX-Guids', 'src/dxguids.cpp', include_directories : inc_dirs, install : true)
|
||||
|
||||
dep_dxheaders = declare_dependency(
|
||||
link_with : guids_lib,
|
||||
include_directories : inc_dirs)
|
||||
|
||||
subdir('test')
|
||||
|
||||
pkg = import('pkgconfig')
|
||||
pkg.generate(name : 'DirectX-Headers',
|
||||
description : 'Headers for using D3D12',
|
||||
libraries : [guids_lib],
|
||||
version : meson.project_version(),
|
||||
subdirs : install_inc_subdirs)
|
||||
install_subdir('include', install_dir : '')
|
12
src/dxguids.cpp
Normal file
12
src/dxguids.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// This file's sole purpose is to initialize the GUIDs declared using the DEFINE_GUID macro.
|
||||
#define INITGUID
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <wsl/winadapter.h>
|
||||
#endif
|
||||
|
||||
#include <directx/dxcore.h>
|
||||
#include <directx/d3d12.h>
|
6
test/CMakeLists.txt
Normal file
6
test/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
project(DirectX-Headers-Test CXX)
|
||||
add_executable(DirectX-Headers-Test test.cpp)
|
||||
target_link_libraries(DirectX-Headers-Test DirectX-Headers DirectX-Guids d3d12 dxcore)
|
9
test/meson.build
Normal file
9
test/meson.build
Normal file
@ -0,0 +1,9 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
cpp = meson.get_compiler('cpp')
|
||||
d3d12_lib = cpp.find_library('d3d12')
|
||||
dxcore_lib = cpp.find_library('dxcore')
|
||||
|
||||
headers_test = executable('DirectX-Headers-Test', 'test.cpp',
|
||||
dependencies : [dep_dxheaders, d3d12_lib, dxcore_lib])
|
32
test/test.cpp
Normal file
32
test/test.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <wsl/winadapter.h>
|
||||
#endif
|
||||
|
||||
#include <directx/d3d12.h>
|
||||
#include <directx/dxcore.h>
|
||||
#include <directx/d3dx12.h>
|
||||
#include "dxguids/dxguids.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
IDXCoreAdapter *adapter = nullptr;
|
||||
ID3D12Device *device = nullptr;
|
||||
|
||||
{
|
||||
IDXCoreAdapterFactory *factory = nullptr;
|
||||
if (FAILED(DXCoreCreateAdapterFactory(&factory)))
|
||||
return -1;
|
||||
|
||||
IDXCoreAdapterList *list = nullptr;
|
||||
if (FAILED(factory->CreateAdapterList(1, &DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, &list)))
|
||||
return -1;
|
||||
|
||||
if (FAILED(list->GetAdapter(0, &adapter)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&device));
|
||||
}
|
Loading…
Reference in New Issue
Block a user