| 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 <stdint.h> |
| 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 |
}; |
| 40 |
|
| 41 |
enum class DXCoreAdapterState : uint32_t |
| 42 |
{ |
| 43 |
IsDriverUpdateInProgress = 0, |
| 44 |
AdapterMemoryBudget = 1 |
| 45 |
}; |
| 46 |
|
| 47 |
enum class DXCoreSegmentGroup : uint32_t |
| 48 |
{ |
| 49 |
Local = 0, |
| 50 |
NonLocal = 1 |
| 51 |
}; |
| 52 |
|
| 53 |
enum class DXCoreNotificationType : uint32_t |
| 54 |
{ |
| 55 |
AdapterListStale = 0, |
| 56 |
AdapterNoLongerValid = 1, |
| 57 |
AdapterBudgetChange = 2, |
| 58 |
AdapterHardwareContentProtectionTeardown = 3 |
| 59 |
}; |
| 60 |
|
| 61 |
enum class DXCoreAdapterPreference : uint32_t |
| 62 |
{ |
| 63 |
Hardware = 0, |
| 64 |
MinimumPower = 1, |
| 65 |
HighPerformance = 2 |
| 66 |
}; |
| 67 |
|
| 68 |
struct DXCoreHardwareID |
| 69 |
{ |
| 70 |
uint32_t vendorID; |
| 71 |
uint32_t deviceID; |
| 72 |
uint32_t subSysID; |
| 73 |
uint32_t revision; |
| 74 |
}; |
| 75 |
|
| 76 |
struct DXCoreHardwareIDParts |
| 77 |
{ |
| 78 |
uint32_t vendorID; |
| 79 |
uint32_t deviceID; |
| 80 |
uint32_t subSystemID; |
| 81 |
uint32_t subVendorID; |
| 82 |
uint32_t revisionID; |
| 83 |
}; |
| 84 |
|
| 85 |
struct DXCoreAdapterMemoryBudgetNodeSegmentGroup |
| 86 |
{ |
| 87 |
uint32_t nodeIndex; |
| 88 |
DXCoreSegmentGroup segmentGroup; |
| 89 |
}; |
| 90 |
|
| 91 |
struct DXCoreAdapterMemoryBudget |
| 92 |
{ |
| 93 |
uint64_t budget; |
| 94 |
uint64_t currentUsage; |
| 95 |
uint64_t availableForReservation; |
| 96 |
uint64_t currentReservation; |
| 97 |
}; |
| 98 |
|
| 99 |
typedef void (STDMETHODCALLTYPE *PFN_DXCORE_NOTIFICATION_CALLBACK)( |
| 100 |
DXCoreNotificationType notificationType, |
| 101 |
_In_ IUnknown *object, |
| 102 |
_In_opt_ void *context); |
| 103 |
|
| 104 |
static_assert(sizeof(bool) == 1, "bool assumed as one byte"); |
| 105 |
|
| 106 |
DEFINE_GUID(IID_IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06); |
| 107 |
DEFINE_GUID(IID_IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28); |
| 108 |
DEFINE_GUID(IID_IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e); |
| 109 |
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D11_GRAPHICS, 0x8c47866b, 0x7583, 0x450d, 0xf0, 0xf0, 0x6b, 0xad, 0xa8, 0x95, 0xaf, 0x4b); |
| 110 |
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS, 0x0c9ece4d, 0x2f6e, 0x4f01, 0x8c, 0x96, 0xe8, 0x9e, 0x33, 0x1b, 0x47, 0xb1); |
| 111 |
DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, 0x248e2800, 0xa793, 0x4724, 0xab, 0xaa, 0x23, 0xa6, 0xde, 0x1b, 0xe0, 0x90); |
| 112 |
|
| 113 |
/* interface IDXCoreAdapter */ |
| 114 |
MIDL_INTERFACE("f0db4c7f-fe5a-42a2-bd62-f2a6cf6fc83e") |
| 115 |
IDXCoreAdapter : public IUnknown |
| 116 |
{ |
| 117 |
public: |
| 118 |
virtual bool STDMETHODCALLTYPE IsValid() = 0; |
| 119 |
|
| 120 |
virtual bool STDMETHODCALLTYPE IsAttributeSupported( |
| 121 |
REFGUID attributeGUID) = 0; |
| 122 |
|
| 123 |
virtual bool STDMETHODCALLTYPE IsPropertySupported( |
| 124 |
DXCoreAdapterProperty property) = 0; |
| 125 |
|
| 126 |
virtual HRESULT STDMETHODCALLTYPE GetProperty( |
| 127 |
DXCoreAdapterProperty property, |
| 128 |
size_t bufferSize, |
| 129 |
_Out_writes_bytes_(bufferSize) void *propertyData) = 0; |
| 130 |
|
| 131 |
template <class T> |
| 132 |
HRESULT GetProperty( |
| 133 |
DXCoreAdapterProperty property, |
| 134 |
_Out_writes_bytes_(sizeof(T)) T *propertyData) |
| 135 |
{ |
| 136 |
return GetProperty(property, |
| 137 |
sizeof(T), |
| 138 |
(void*)propertyData); |
| 139 |
} |
| 140 |
|
| 141 |
virtual HRESULT STDMETHODCALLTYPE GetPropertySize( |
| 142 |
DXCoreAdapterProperty property, |
| 143 |
_Out_ size_t *bufferSize) = 0; |
| 144 |
|
| 145 |
virtual bool STDMETHODCALLTYPE IsQueryStateSupported( |
| 146 |
DXCoreAdapterState property) = 0; |
| 147 |
|
| 148 |
virtual HRESULT STDMETHODCALLTYPE QueryState( |
| 149 |
DXCoreAdapterState state, |
| 150 |
size_t inputStateDetailsSize, |
| 151 |
_In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, |
| 152 |
size_t outputBufferSize, |
| 153 |
_Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0; |
| 154 |
|
| 155 |
template <class T1, class T2> |
| 156 |
HRESULT QueryState( |
| 157 |
DXCoreAdapterState state, |
| 158 |
_In_reads_bytes_opt_(sizeof(T1)) const T1 *inputStateDetails, |
| 159 |
_Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer) |
| 160 |
{ |
| 161 |
return QueryState(state, |
| 162 |
sizeof(T1), |
| 163 |
(const void*)inputStateDetails, |
| 164 |
sizeof(T2), |
| 165 |
(void*)outputBuffer); |
| 166 |
} |
| 167 |
|
| 168 |
template <class T> |
| 169 |
HRESULT QueryState( |
| 170 |
DXCoreAdapterState state, |
| 171 |
_Out_writes_bytes_(sizeof(T)) T *outputBuffer) |
| 172 |
{ |
| 173 |
return QueryState(state, |
| 174 |
0, |
| 175 |
nullptr, |
| 176 |
sizeof(T), |
| 177 |
(void*)outputBuffer); |
| 178 |
} |
| 179 |
|
| 180 |
virtual bool STDMETHODCALLTYPE IsSetStateSupported( |
| 181 |
DXCoreAdapterState property) = 0; |
| 182 |
|
| 183 |
virtual HRESULT STDMETHODCALLTYPE SetState( |
| 184 |
DXCoreAdapterState state, |
| 185 |
size_t inputStateDetailsSize, |
| 186 |
_In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails, |
| 187 |
size_t inputDataSize, |
| 188 |
_In_reads_bytes_(inputDataSize) const void *inputData) = 0; |
| 189 |
|
| 190 |
template <class T1, class T2> |
| 191 |
HRESULT SetState( |
| 192 |
DXCoreAdapterState state, |
| 193 |
const T1 *inputStateDetails, |
| 194 |
const T2 *inputData) |
| 195 |
{ |
| 196 |
return SetState(state, |
| 197 |
sizeof(T1), |
| 198 |
(const void*)inputStateDetails, |
| 199 |
sizeof(T2), |
| 200 |
(const void*)inputData); |
| 201 |
} |
| 202 |
|
| 203 |
virtual HRESULT STDMETHODCALLTYPE GetFactory( |
| 204 |
REFIID riid, |
| 205 |
_COM_Outptr_ void** ppvFactory |
| 206 |
) = 0; |
| 207 |
|
| 208 |
template <class T> |
| 209 |
HRESULT GetFactory( |
| 210 |
_COM_Outptr_ T** ppvFactory |
| 211 |
) |
| 212 |
{ |
| 213 |
return GetFactory(IID_PPV_ARGS(ppvFactory)); |
| 214 |
} |
| 215 |
}; |
| 216 |
|
| 217 |
/* interface IDXCoreAdapterList */ |
| 218 |
MIDL_INTERFACE("526c7776-40e9-459b-b711-f32ad76dfc28") |
| 219 |
IDXCoreAdapterList : public IUnknown |
| 220 |
{ |
| 221 |
public: |
| 222 |
virtual HRESULT STDMETHODCALLTYPE GetAdapter( |
| 223 |
uint32_t index, |
| 224 |
REFIID riid, |
| 225 |
_COM_Outptr_ void **ppvAdapter) = 0; |
| 226 |
|
| 227 |
template<class T> |
| 228 |
HRESULT STDMETHODCALLTYPE GetAdapter( |
| 229 |
uint32_t index, |
| 230 |
_COM_Outptr_ T **ppvAdapter) |
| 231 |
{ |
| 232 |
return GetAdapter(index, |
| 233 |
IID_PPV_ARGS(ppvAdapter)); |
| 234 |
} |
| 235 |
|
| 236 |
virtual uint32_t STDMETHODCALLTYPE GetAdapterCount() = 0; |
| 237 |
|
| 238 |
virtual bool STDMETHODCALLTYPE IsStale() = 0; |
| 239 |
|
| 240 |
virtual HRESULT STDMETHODCALLTYPE GetFactory( |
| 241 |
REFIID riid, |
| 242 |
_COM_Outptr_ void** ppvFactory |
| 243 |
) = 0; |
| 244 |
|
| 245 |
template <class T> |
| 246 |
HRESULT GetFactory( |
| 247 |
_COM_Outptr_ T** ppvFactory |
| 248 |
) |
| 249 |
{ |
| 250 |
return GetFactory(IID_PPV_ARGS(ppvFactory)); |
| 251 |
} |
| 252 |
|
| 253 |
virtual HRESULT STDMETHODCALLTYPE Sort( |
| 254 |
uint32_t numPreferences, |
| 255 |
_In_reads_(numPreferences) const DXCoreAdapterPreference* preferences) = 0; |
| 256 |
|
| 257 |
virtual bool STDMETHODCALLTYPE IsAdapterPreferenceSupported( |
| 258 |
DXCoreAdapterPreference preference) = 0; |
| 259 |
}; |
| 260 |
|
| 261 |
/* interface IDXCoreAdapterFactory */ |
| 262 |
MIDL_INTERFACE("78ee5945-c36e-4b13-a669-005dd11c0f06") |
| 263 |
IDXCoreAdapterFactory : public IUnknown |
| 264 |
{ |
| 265 |
public: |
| 266 |
|
| 267 |
virtual HRESULT STDMETHODCALLTYPE CreateAdapterList( |
| 268 |
uint32_t numAttributes, |
| 269 |
_In_reads_(numAttributes) const GUID *filterAttributes, |
| 270 |
REFIID riid, |
| 271 |
_COM_Outptr_ void **ppvAdapterList) = 0; |
| 272 |
|
| 273 |
template<class T> |
| 274 |
HRESULT STDMETHODCALLTYPE CreateAdapterList( |
| 275 |
uint32_t numAttributes, |
| 276 |
_In_reads_(numAttributes) const GUID *filterAttributes, |
| 277 |
_COM_Outptr_ T **ppvAdapterList) |
| 278 |
{ |
| 279 |
return CreateAdapterList(numAttributes, |
| 280 |
filterAttributes, |
| 281 |
IID_PPV_ARGS(ppvAdapterList)); |
| 282 |
} |
| 283 |
|
| 284 |
virtual HRESULT STDMETHODCALLTYPE GetAdapterByLuid( |
| 285 |
const LUID &adapterLUID, |
| 286 |
REFIID riid, |
| 287 |
_COM_Outptr_ void **ppvAdapter) = 0; |
| 288 |
|
| 289 |
template<class T> |
| 290 |
HRESULT STDMETHODCALLTYPE GetAdapterByLuid( |
| 291 |
const LUID &adapterLUID, |
| 292 |
_COM_Outptr_ T **ppvAdapter) |
| 293 |
{ |
| 294 |
return GetAdapterByLuid(adapterLUID, |
| 295 |
IID_PPV_ARGS(ppvAdapter)); |
| 296 |
} |
| 297 |
|
| 298 |
virtual bool STDMETHODCALLTYPE IsNotificationTypeSupported( |
| 299 |
DXCoreNotificationType notificationType) = 0; |
| 300 |
|
| 301 |
virtual HRESULT STDMETHODCALLTYPE RegisterEventNotification( |
| 302 |
_In_ IUnknown *dxCoreObject, |
| 303 |
DXCoreNotificationType notificationType, |
| 304 |
_In_ PFN_DXCORE_NOTIFICATION_CALLBACK callbackFunction, |
| 305 |
_In_opt_ void *callbackContext, |
| 306 |
_Out_ uint32_t *eventCookie) = 0; |
| 307 |
|
| 308 |
virtual HRESULT STDMETHODCALLTYPE UnregisterEventNotification( |
| 309 |
uint32_t eventCookie) = 0; |
| 310 |
}; |
| 311 |
|
| 312 |
#endif // __cplusplus |
| 313 |
|
| 314 |
#endif // __dxcore_interface_h__ |
| 315 |
|
| 316 |
|