dxcore_interface.h 8.9 KB

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