dxcore_interface.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. //
  2. // DXCore Interface
  3. // Copyright (C) Microsoft Corporation.
  4. // Licensed under the MIT license.
  5. //
  6. #ifndef __dxcore_interface_h__
  7. #define __dxcore_interface_h__
  8. #ifndef COM_NO_WINDOWS_H
  9. #include "windows.h"
  10. #include "ole2.h"
  11. #endif /*COM_NO_WINDOWS_H*/
  12. #include <stdint.h>
  13. #ifdef __cplusplus
  14. #define _FACDXCORE 0x880
  15. #define MAKE_DXCORE_HRESULT( code ) MAKE_HRESULT( 1, _FACDXCORE, code )
  16. enum class DXCoreAdapterProperty : uint32_t
  17. {
  18. InstanceLuid = 0,
  19. DriverVersion = 1,
  20. DriverDescription = 2,
  21. HardwareID = 3, // Use HardwareIDParts instead, if available.
  22. KmdModelVersion = 4,
  23. ComputePreemptionGranularity = 5,
  24. GraphicsPreemptionGranularity = 6,
  25. DedicatedAdapterMemory = 7,
  26. DedicatedSystemMemory = 8,
  27. SharedSystemMemory = 9,
  28. AcgCompatible = 10,
  29. IsHardware = 11,
  30. IsIntegrated = 12,
  31. IsDetachable = 13,
  32. HardwareIDParts = 14,
  33. PhysicalAdapterCount = 15,
  34. AdapterEngineCount = 16,
  35. AdapterEngineName = 17,
  36. };
  37. enum class DXCoreAdapterState : uint32_t
  38. {
  39. IsDriverUpdateInProgress = 0,
  40. AdapterMemoryBudget = 1,
  41. AdapterMemoryUsageBytes = 2,
  42. AdapterMemoryUsageByProcessBytes = 3,
  43. AdapterEngineRunningTimeMicroseconds = 4,
  44. AdapterEngineRunningTimeByProcessMicroseconds = 5,
  45. AdapterTemperatureCelsius = 6,
  46. AdapterInUseProcessCount = 7,
  47. AdapterInUseProcessSet = 8,
  48. AdapterEngineFrequencyHertz = 9,
  49. AdapterMemoryFrequencyHertz = 10
  50. };
  51. enum class DXCoreSegmentGroup : uint32_t
  52. {
  53. Local = 0,
  54. NonLocal = 1
  55. };
  56. enum class DXCoreNotificationType : uint32_t
  57. {
  58. AdapterListStale = 0,
  59. AdapterNoLongerValid = 1,
  60. AdapterBudgetChange = 2,
  61. AdapterHardwareContentProtectionTeardown = 3
  62. };
  63. enum class DXCoreAdapterPreference : uint32_t
  64. {
  65. Hardware = 0,
  66. MinimumPower = 1,
  67. HighPerformance = 2
  68. };
  69. enum class DXCoreWorkload : uint32_t
  70. {
  71. Graphics = 0,
  72. Compute = 1,
  73. Media = 2,
  74. MachineLearning = 3,
  75. };
  76. enum class DXCoreRuntimeFilterFlags : uint32_t
  77. {
  78. None = 0x0,
  79. D3D11 = 0x1,
  80. D3D12 = 0x2
  81. };
  82. DEFINE_ENUM_FLAG_OPERATORS(DXCoreRuntimeFilterFlags)
  83. enum class DXCoreHardwareTypeFilterFlags : uint32_t
  84. {
  85. None = 0x0,
  86. GPU = 0x1,
  87. ComputeAccelerator = 0x2,
  88. NPU = 0x4,
  89. MediaAccelerator = 0x8
  90. };
  91. DEFINE_ENUM_FLAG_OPERATORS(DXCoreHardwareTypeFilterFlags)
  92. struct DXCoreHardwareID
  93. {
  94. uint32_t vendorID;
  95. uint32_t deviceID;
  96. uint32_t subSysID;
  97. uint32_t revision;
  98. };
  99. struct DXCoreHardwareIDParts
  100. {
  101. uint32_t vendorID;
  102. uint32_t deviceID;
  103. uint32_t subSystemID;
  104. uint32_t subVendorID;
  105. uint32_t revisionID;
  106. };
  107. struct DXCoreAdapterMemoryBudgetNodeSegmentGroup
  108. {
  109. uint32_t nodeIndex;
  110. DXCoreSegmentGroup segmentGroup;
  111. };
  112. struct DXCoreAdapterMemoryBudget
  113. {
  114. uint64_t budget;
  115. uint64_t currentUsage;
  116. uint64_t availableForReservation;
  117. uint64_t currentReservation;
  118. };
  119. struct DXCoreAdapterEngineIndex
  120. {
  121. uint32_t physicalAdapterIndex;
  122. uint32_t engineIndex;
  123. };
  124. struct DXCoreEngineQueryInput
  125. {
  126. DXCoreAdapterEngineIndex adapterEngineIndex;
  127. uint32_t processId;
  128. };
  129. struct DXCoreEngineQueryOutput
  130. {
  131. uint64_t runningTime;
  132. bool processQuerySucceeded;
  133. };
  134. enum class DXCoreMemoryType : uint32_t
  135. {
  136. Dedicated = 0,
  137. Shared = 1
  138. };
  139. struct DXCoreMemoryUsage
  140. {
  141. uint64_t committed;
  142. uint64_t resident;
  143. };
  144. struct DXCoreMemoryQueryInput
  145. {
  146. uint32_t physicalAdapterIndex;
  147. DXCoreMemoryType memoryType;
  148. };
  149. struct DXCoreProcessMemoryQueryInput
  150. {
  151. uint32_t physicalAdapterIndex;
  152. DXCoreMemoryType memoryType;
  153. uint32_t processId;
  154. };
  155. struct DXCoreProcessMemoryQueryOutput
  156. {
  157. DXCoreMemoryUsage memoryUsage;
  158. bool processQuerySucceeded;
  159. };
  160. struct DXCoreAdapterProcessSetQueryInput
  161. {
  162. uint32_t arraySize;
  163. _Field_size_(arraySize) uint32_t* processIds;
  164. };
  165. struct DXCoreAdapterProcessSetQueryOutput
  166. {
  167. uint32_t processesWritten;
  168. uint32_t processesTotal;
  169. };
  170. struct DXCoreEngineNamePropertyInput
  171. {
  172. DXCoreAdapterEngineIndex adapterEngineIndex;
  173. uint32_t engineNameLength;
  174. _Field_size_(engineNameLength) wchar_t *engineName;
  175. };
  176. struct DXCoreEngineNamePropertyOutput
  177. {
  178. uint32_t engineNameLength;
  179. };
  180. struct DXCoreFrequencyQueryOutput
  181. {
  182. uint64_t frequency;
  183. uint64_t maxFrequency;
  184. uint64_t maxOverclockedFrequency;
  185. };
  186. typedef void (STDMETHODCALLTYPE *PFN_DXCORE_NOTIFICATION_CALLBACK)(
  187. DXCoreNotificationType notificationType,
  188. _In_ IUnknown *object,
  189. _In_opt_ void *context);
  190. static_assert(sizeof(bool) == 1, "bool assumed as one byte");
  191. DEFINE_GUID(IID_IDXCoreAdapterFactory, 0x78ee5945, 0xc36e, 0x4b13, 0xa6, 0x69, 0x00, 0x5d, 0xd1, 0x1c, 0x0f, 0x06);
  192. DEFINE_GUID(IID_IDXCoreAdapterFactory1, 0xd5682e19, 0x6d21, 0x401c, 0x82, 0x7a, 0x9a, 0x51, 0xa4, 0xea, 0x35, 0xd7);
  193. DEFINE_GUID(IID_IDXCoreAdapterList, 0x526c7776, 0x40e9, 0x459b, 0xb7, 0x11, 0xf3, 0x2a, 0xd7, 0x6d, 0xfc, 0x28);
  194. DEFINE_GUID(IID_IDXCoreAdapter, 0xf0db4c7f, 0xfe5a, 0x42a2, 0xbd, 0x62, 0xf2, 0xa6, 0xcf, 0x6f, 0xc8, 0x3e);
  195. DEFINE_GUID(IID_IDXCoreAdapter1, 0xa0783366, 0xcfa3, 0x43be, 0x9d, 0x79, 0x55, 0xb2, 0xda, 0x97, 0xc6, 0x3c);
  196. DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D11_GRAPHICS, 0x8c47866b, 0x7583, 0x450d, 0xf0, 0xf0, 0x6b, 0xad, 0xa8, 0x95, 0xaf, 0x4b);
  197. DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GRAPHICS, 0x0c9ece4d, 0x2f6e, 0x4f01, 0x8c, 0x96, 0xe8, 0x9e, 0x33, 0x1b, 0x47, 0xb1);
  198. DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_CORE_COMPUTE, 0x248e2800, 0xa793, 0x4724, 0xab, 0xaa, 0x23, 0xa6, 0xde, 0x1b, 0xe0, 0x90);
  199. DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_ML, 0xb71b0d41, 0x1088, 0x422f, 0xa2, 0x7c, 0x2, 0x50, 0xb7, 0xd3, 0xa9, 0x88);
  200. DEFINE_GUID(DXCORE_ADAPTER_ATTRIBUTE_D3D12_GENERIC_MEDIA, 0x8eb2c848, 0x82f6, 0x4b49, 0xaa, 0x87, 0xae, 0xcf, 0xcf, 0x1, 0x74, 0xc6);
  201. DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_GPU, 0xb69eb219, 0x3ded, 0x4464, 0x97, 0x9f, 0xa0, 0xb, 0xd4, 0x68, 0x70, 0x6);
  202. DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_COMPUTE_ACCELERATOR, 0xe0b195da, 0x58ef, 0x4a22, 0x90, 0xf1, 0x1f, 0x28, 0x16, 0x9c, 0xab, 0x8d);
  203. DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_NPU, 0xd46140c4, 0xadd7, 0x451b, 0x9e, 0x56, 0x6, 0xfe, 0x8c, 0x3b, 0x58, 0xed);
  204. DEFINE_GUID(DXCORE_HARDWARE_TYPE_ATTRIBUTE_MEDIA_ACCELERATOR, 0x66bdb96a, 0x50b, 0x44c7, 0xa4, 0xfd, 0xd1, 0x44, 0xce, 0xa, 0xb4, 0x43);
  205. /* interface IDXCoreAdapter */
  206. MIDL_INTERFACE("f0db4c7f-fe5a-42a2-bd62-f2a6cf6fc83e")
  207. IDXCoreAdapter : public IUnknown
  208. {
  209. public:
  210. virtual bool STDMETHODCALLTYPE IsValid() = 0;
  211. virtual bool STDMETHODCALLTYPE IsAttributeSupported(
  212. REFGUID attributeGUID) = 0;
  213. virtual bool STDMETHODCALLTYPE IsPropertySupported(
  214. DXCoreAdapterProperty property) = 0;
  215. virtual HRESULT STDMETHODCALLTYPE GetProperty(
  216. DXCoreAdapterProperty property,
  217. size_t bufferSize,
  218. _Out_writes_bytes_(bufferSize) void *propertyData) = 0;
  219. template <class T>
  220. HRESULT GetProperty(
  221. DXCoreAdapterProperty property,
  222. _Out_writes_bytes_(sizeof(T)) T *propertyData)
  223. {
  224. return GetProperty(property,
  225. sizeof(T),
  226. (void*)propertyData);
  227. }
  228. virtual HRESULT STDMETHODCALLTYPE GetPropertySize(
  229. DXCoreAdapterProperty property,
  230. _Out_ size_t *bufferSize) = 0;
  231. virtual bool STDMETHODCALLTYPE IsQueryStateSupported(
  232. DXCoreAdapterState property) = 0;
  233. virtual HRESULT STDMETHODCALLTYPE QueryState(
  234. DXCoreAdapterState state,
  235. size_t inputStateDetailsSize,
  236. _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails,
  237. size_t outputBufferSize,
  238. _Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0;
  239. template <class T1, class T2>
  240. HRESULT QueryState(
  241. DXCoreAdapterState state,
  242. _In_reads_bytes_opt_(sizeof(T1)) const T1 *inputStateDetails,
  243. _Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer)
  244. {
  245. return QueryState(state,
  246. sizeof(T1),
  247. (const void*)inputStateDetails,
  248. sizeof(T2),
  249. (void*)outputBuffer);
  250. }
  251. template <class T>
  252. HRESULT QueryState(
  253. DXCoreAdapterState state,
  254. _Out_writes_bytes_(sizeof(T)) T *outputBuffer)
  255. {
  256. return QueryState(state,
  257. 0,
  258. nullptr,
  259. sizeof(T),
  260. (void*)outputBuffer);
  261. }
  262. virtual bool STDMETHODCALLTYPE IsSetStateSupported(
  263. DXCoreAdapterState property) = 0;
  264. virtual HRESULT STDMETHODCALLTYPE SetState(
  265. DXCoreAdapterState state,
  266. size_t inputStateDetailsSize,
  267. _In_reads_bytes_opt_(inputStateDetailsSize) const void *inputStateDetails,
  268. size_t inputDataSize,
  269. _In_reads_bytes_(inputDataSize) const void *inputData) = 0;
  270. template <class T1, class T2>
  271. HRESULT SetState(
  272. DXCoreAdapterState state,
  273. const T1 *inputStateDetails,
  274. const T2 *inputData)
  275. {
  276. return SetState(state,
  277. sizeof(T1),
  278. (const void*)inputStateDetails,
  279. sizeof(T2),
  280. (const void*)inputData);
  281. }
  282. virtual HRESULT STDMETHODCALLTYPE GetFactory(
  283. REFIID riid,
  284. _COM_Outptr_ void** ppvFactory
  285. ) = 0;
  286. template <class T>
  287. HRESULT GetFactory(
  288. _COM_Outptr_ T** ppvFactory
  289. )
  290. {
  291. return GetFactory(IID_PPV_ARGS(ppvFactory));
  292. }
  293. };
  294. /* interface IDXCoreAdapter1 */
  295. MIDL_INTERFACE("a0783366-cfa3-43be-9d79-55b2da97c63c")
  296. IDXCoreAdapter1 : public IDXCoreAdapter
  297. {
  298. public:
  299. virtual HRESULT STDMETHODCALLTYPE GetPropertyWithInput(
  300. DXCoreAdapterProperty property,
  301. size_t inputPropertyDetailsSize,
  302. _In_reads_bytes_opt_(inputPropertyDetailsSize) const void *inputPropertyDetails,
  303. size_t outputBufferSize,
  304. _Out_writes_bytes_(outputBufferSize) void *outputBuffer) = 0;
  305. template <class T1, class T2>
  306. HRESULT GetPropertyWithInput(
  307. DXCoreAdapterProperty property,
  308. _In_reads_bytes_opt_(sizeof(T1)) const T1 *inputPropertyDetails,
  309. _Out_writes_bytes_(sizeof(T2)) T2 *outputBuffer)
  310. {
  311. return GetPropertyWithInput(property,
  312. sizeof(T1),
  313. (const void*)inputPropertyDetails,
  314. sizeof(T2),
  315. (void*)outputBuffer);
  316. }
  317. };
  318. /* interface IDXCoreAdapterList */
  319. MIDL_INTERFACE("526c7776-40e9-459b-b711-f32ad76dfc28")
  320. IDXCoreAdapterList : public IUnknown
  321. {
  322. public:
  323. virtual HRESULT STDMETHODCALLTYPE GetAdapter(
  324. uint32_t index,
  325. REFIID riid,
  326. _COM_Outptr_ void **ppvAdapter) = 0;
  327. template<class T>
  328. HRESULT STDMETHODCALLTYPE GetAdapter(
  329. uint32_t index,
  330. _COM_Outptr_ T **ppvAdapter)
  331. {
  332. return GetAdapter(index,
  333. IID_PPV_ARGS(ppvAdapter));
  334. }
  335. virtual uint32_t STDMETHODCALLTYPE GetAdapterCount() = 0;
  336. virtual bool STDMETHODCALLTYPE IsStale() = 0;
  337. virtual HRESULT STDMETHODCALLTYPE GetFactory(
  338. REFIID riid,
  339. _COM_Outptr_ void** ppvFactory
  340. ) = 0;
  341. template <class T>
  342. HRESULT GetFactory(
  343. _COM_Outptr_ T** ppvFactory
  344. )
  345. {
  346. return GetFactory(IID_PPV_ARGS(ppvFactory));
  347. }
  348. virtual HRESULT STDMETHODCALLTYPE Sort(
  349. uint32_t numPreferences,
  350. _In_reads_(numPreferences) const DXCoreAdapterPreference* preferences) = 0;
  351. virtual bool STDMETHODCALLTYPE IsAdapterPreferenceSupported(
  352. DXCoreAdapterPreference preference) = 0;
  353. };
  354. /* interface IDXCoreAdapterFactory */
  355. MIDL_INTERFACE("78ee5945-c36e-4b13-a669-005dd11c0f06")
  356. IDXCoreAdapterFactory : public IUnknown
  357. {
  358. public:
  359. virtual HRESULT STDMETHODCALLTYPE CreateAdapterList(
  360. uint32_t numAttributes,
  361. _In_reads_(numAttributes) const GUID *filterAttributes,
  362. REFIID riid,
  363. _COM_Outptr_ void **ppvAdapterList) = 0;
  364. template<class T>
  365. HRESULT STDMETHODCALLTYPE CreateAdapterList(
  366. uint32_t numAttributes,
  367. _In_reads_(numAttributes) const GUID *filterAttributes,
  368. _COM_Outptr_ T **ppvAdapterList)
  369. {
  370. return CreateAdapterList(numAttributes,
  371. filterAttributes,
  372. IID_PPV_ARGS(ppvAdapterList));
  373. }
  374. virtual HRESULT STDMETHODCALLTYPE GetAdapterByLuid(
  375. const LUID &adapterLUID,
  376. REFIID riid,
  377. _COM_Outptr_ void **ppvAdapter) = 0;
  378. template<class T>
  379. HRESULT STDMETHODCALLTYPE GetAdapterByLuid(
  380. const LUID &adapterLUID,
  381. _COM_Outptr_ T **ppvAdapter)
  382. {
  383. return GetAdapterByLuid(adapterLUID,
  384. IID_PPV_ARGS(ppvAdapter));
  385. }
  386. virtual bool STDMETHODCALLTYPE IsNotificationTypeSupported(
  387. DXCoreNotificationType notificationType) = 0;
  388. virtual HRESULT STDMETHODCALLTYPE RegisterEventNotification(
  389. _In_ IUnknown *dxCoreObject,
  390. DXCoreNotificationType notificationType,
  391. _In_ PFN_DXCORE_NOTIFICATION_CALLBACK callbackFunction,
  392. _In_opt_ void *callbackContext,
  393. _Out_ uint32_t *eventCookie) = 0;
  394. virtual HRESULT STDMETHODCALLTYPE UnregisterEventNotification(
  395. uint32_t eventCookie) = 0;
  396. };
  397. /* interface IDXCoreAdapterFactory1 */
  398. MIDL_INTERFACE("d5682e19-6d21-401c-827a-9a51a4ea35d7")
  399. IDXCoreAdapterFactory1 : public IDXCoreAdapterFactory
  400. {
  401. public:
  402. virtual HRESULT STDMETHODCALLTYPE CreateAdapterListByWorkload(
  403. DXCoreWorkload workload,
  404. DXCoreRuntimeFilterFlags runtimeFilter,
  405. DXCoreHardwareTypeFilterFlags hardwareTypeFilter,
  406. REFIID riid,
  407. _COM_Outptr_ void **ppvAdapterList) = 0;
  408. template<class T>
  409. HRESULT STDMETHODCALLTYPE CreateAdapterListByWorkload(
  410. DXCoreWorkload workload,
  411. DXCoreRuntimeFilterFlags runtimeFilter,
  412. DXCoreHardwareTypeFilterFlags hardwareTypeFilter,
  413. _COM_Outptr_ T **ppvAdapterList)
  414. {
  415. return CreateAdapterListByWorkload(workload,
  416. runtimeFilter,
  417. hardwareTypeFilter,
  418. IID_PPV_ARGS(ppvAdapterList));
  419. }
  420. };
  421. #endif // __cplusplus
  422. #endif // __dxcore_interface_h__