DxcPixEntrypoints.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxcPixEntrypoints.cpp //
  4. // Copyright (C) Microsoft Corporation. All rights reserved. //
  5. // This file is distributed under the University of Illinois Open Source //
  6. // License. See LICENSE.TXT for details. //
  7. // //
  8. // Defines all of the entrypoints for DXC's PIX interfaces for dealing with //
  9. // debug info. These entrypoints are responsible for setting up a common, //
  10. // sane environment -- e.g., exceptions are caught and returned as an //
  11. // HRESULT -- deferring to the real implementations defined elsewhere in //
  12. // this library. //
  13. // //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. #include "dxc/Support/WinIncludes.h"
  16. #include "dxc/dxcapi.h"
  17. #include "dxc/dxcpix.h"
  18. #include "DxilDiaSession.h"
  19. #include "dxc/Support/Global.h"
  20. #include "dxc/Support/microcom.h"
  21. #include "dxc/Support/FileIOHelper.h"
  22. #include "llvm/Support/MSFileSystem.h"
  23. #include "llvm/Support/FileSystem.h"
  24. #include "DxcPixBase.h"
  25. #include "DxcPixDxilDebugInfo.h"
  26. #include "DxcPixCompilationInfo.h"
  27. #include <functional>
  28. namespace dxil_debug_info
  29. {
  30. namespace entrypoints
  31. {
  32. // OutParam/OutParamImpl provides a mechanism that entrypoints
  33. // use to tag method arguments as OutParams. OutParams are
  34. // automatically zero-initialized.
  35. template <typename T>
  36. class OutParamImpl
  37. {
  38. public:
  39. OutParamImpl(T *V) : m_V(V)
  40. {
  41. if (m_V != nullptr)
  42. {
  43. *m_V = T();
  44. }
  45. }
  46. operator T *() const
  47. {
  48. return m_V;
  49. }
  50. private:
  51. T *m_V;
  52. };
  53. template <typename T>
  54. OutParamImpl<T> OutParam(T *V)
  55. {
  56. return OutParamImpl<T>(V);
  57. }
  58. // InParam/InParamImpl provides a mechanism that entrypoints
  59. // use to tag method arguments as InParams. InParams are
  60. // not zero-initialized.
  61. template <typename T>
  62. struct InParamImpl
  63. {
  64. public:
  65. InParamImpl(const T *V) : m_V(V)
  66. {
  67. }
  68. operator const T *() const
  69. {
  70. return m_V;
  71. }
  72. private:
  73. const T *m_V;
  74. };
  75. template <typename T>
  76. InParamImpl<T> InParam(T *V)
  77. {
  78. return InParamImpl<T>(V);
  79. }
  80. // ThisPtr/ThisPtrImpl provides a mechanism that entrypoints
  81. // use to tag method arguments as c++'s this. This values
  82. // are not checked/initialized.
  83. template <typename T>
  84. struct ThisPtrImpl
  85. {
  86. public:
  87. ThisPtrImpl(T *V) : m_V(V)
  88. {
  89. }
  90. operator T *() const
  91. {
  92. return m_V;
  93. }
  94. private:
  95. T *m_V;
  96. };
  97. template <typename T>
  98. ThisPtrImpl<T> ThisPtr(T *V)
  99. {
  100. return ThisPtrImpl<T>(V);
  101. }
  102. // CheckNotNull/CheckNotNullImpl provide a mechanism that entrypoints
  103. // can use for automatic parameter validation. They will throw an
  104. // exception if the given parameter is null.
  105. template <typename T>
  106. class CheckNotNullImpl;
  107. template <typename T>
  108. class CheckNotNullImpl<OutParamImpl<T>>
  109. {
  110. public:
  111. explicit CheckNotNullImpl(OutParamImpl<T> V) : m_V(V)
  112. {
  113. }
  114. operator T *() const
  115. {
  116. if (m_V == nullptr)
  117. {
  118. throw hlsl::Exception(E_POINTER);
  119. }
  120. return m_V;
  121. }
  122. private:
  123. T *m_V;
  124. };
  125. template <typename T>
  126. class CheckNotNullImpl<InParamImpl<T>>
  127. {
  128. public:
  129. explicit CheckNotNullImpl(InParamImpl<T> V) : m_V(V)
  130. {
  131. }
  132. operator T *() const
  133. {
  134. if (m_V == nullptr)
  135. {
  136. throw hlsl::Exception(E_POINTER);
  137. }
  138. return m_V;
  139. }
  140. private:
  141. T *m_V;
  142. };
  143. template <typename T>
  144. CheckNotNullImpl<T> CheckNotNull(T V)
  145. {
  146. return CheckNotNullImpl<T>(V);
  147. }
  148. // WrapOutParams will wrap any OutParams<T> that the
  149. // entrypoints provide to SetupAndRun -- which is essentially
  150. // the method that runs the actual methods.
  151. void WrapOutParams(IMalloc *)
  152. {
  153. }
  154. template <typename T> struct EntrypointWrapper;
  155. // WrapOutParams' specialization that detects OutParams that
  156. // inherit from IUnknown. Any OutParams inheriting from IUnknown
  157. // should be wrapped by one of the classes in this file so that
  158. // user calls will be safely run.
  159. template <
  160. typename T,
  161. typename =
  162. typename std::enable_if<std::is_base_of<IUnknown, T>::value>::type,
  163. typename... O>
  164. void WrapOutParams(
  165. IMalloc* M,
  166. CheckNotNullImpl<OutParamImpl<T *>> ppOut,
  167. O... Others
  168. )
  169. {
  170. if (*ppOut)
  171. {
  172. NewDxcPixDxilDebugInfoObjectOrThrow<typename EntrypointWrapper<T*>::type>(
  173. (T**)ppOut,
  174. M,
  175. *ppOut);
  176. }
  177. WrapOutParams(M, Others...);
  178. }
  179. template <typename T, typename... O>
  180. void WrapOutParams(IMalloc *M, T, O... Others)
  181. {
  182. WrapOutParams(M, Others...);
  183. }
  184. // DEFINE_ENTRYPOINT_WRAPPER_TRAIT is a helper macro that every entrypoint
  185. // should use in order to define the EntrypointWrapper traits class for
  186. // the interface it implements.
  187. #define DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IInterface) \
  188. template <> struct EntrypointWrapper<IInterface *> \
  189. { \
  190. using type = IInterface ## Entrypoint; \
  191. };
  192. // IsValidArgType exposes a static method named check(), which returns
  193. // true if <T> is a valid type for a method argument, and false otherwise.
  194. // This is trying to ensure all pointers are checked, and all out params
  195. // are default-initialized.
  196. template <typename T>
  197. struct IsValidArgType
  198. {
  199. static void check() {}
  200. };
  201. template <typename T>
  202. struct IsValidArgType<T *>
  203. {
  204. static void check()
  205. {
  206. static_assert(
  207. false,
  208. "Pointer arguments should be checked and wrapped"
  209. " with InParam/OutParam, or marked with ThisPtr()");
  210. }
  211. };
  212. template <typename T>
  213. struct IsValidArgType<InParamImpl<T>>
  214. {
  215. static void check()
  216. {
  217. static_assert(
  218. false,
  219. "InParams should be checked for nullptrs");
  220. }
  221. };
  222. template <typename T>
  223. struct IsValidArgType<OutParamImpl<T>>
  224. {
  225. static void check()
  226. {
  227. static_assert(
  228. false,
  229. "InParams should be checked for nullptrs");
  230. }
  231. };
  232. void EnsureAllPointersAreChecked()
  233. {
  234. }
  235. template <typename T, typename... O>
  236. void EnsureAllPointersAreChecked(T, O... o)
  237. {
  238. IsValidArgType<T>::check();
  239. EnsureAllPointersAreChecked(o...);
  240. }
  241. // SetupAndRun is the function that sets up the environment
  242. // in which all of the user requests to the DxcPix library
  243. // run under.
  244. template<typename H, typename... A>
  245. HRESULT SetupAndRun(
  246. IMalloc* M,
  247. H Handler,
  248. A... Args
  249. )
  250. {
  251. DxcThreadMalloc TM(M);
  252. HRESULT hr = E_FAIL;
  253. try
  254. {
  255. ::llvm::sys::fs::MSFileSystem* msfPtr;
  256. IFT(CreateMSFileSystemForDisk(&msfPtr));
  257. std::unique_ptr<::llvm::sys::fs::MSFileSystem> msf(msfPtr);
  258. ::llvm::sys::fs::AutoPerThreadSystem pts(msf.get());
  259. IFTLLVM(pts.error_code());
  260. EnsureAllPointersAreChecked(Args...);
  261. hr = Handler(Args...);
  262. WrapOutParams(M, Args...);
  263. }
  264. catch (const hlsl::Exception &e)
  265. {
  266. hr = e.hr;
  267. }
  268. catch (const std::bad_alloc &)
  269. {
  270. hr = E_OUTOFMEMORY;
  271. }
  272. catch (const std::exception &)
  273. {
  274. hr = E_FAIL;
  275. }
  276. return hr;
  277. }
  278. HRESULT CreateEntrypointWrapper(
  279. IMalloc *pMalloc,
  280. IUnknown *pReal,
  281. REFIID iid,
  282. void **ppvObject);
  283. // Entrypoint is the base class for all entrypoints, providing
  284. // the default QueryInterface implementation, as well as a
  285. // more convenient way of calling SetupAndRun.
  286. template <typename I>
  287. class Entrypoint : public I
  288. {
  289. protected:
  290. using IInterface = I;
  291. Entrypoint(
  292. IMalloc *pMalloc,
  293. IInterface *pI
  294. ) : m_pMalloc(pMalloc)
  295. , m_pReal(pI)
  296. {
  297. }
  298. DXC_MICROCOM_TM_REF_FIELDS();
  299. CComPtr<IInterface> m_pReal;
  300. template <typename F, typename... A>
  301. HRESULT InvokeOnReal(F pFn, A... Args)
  302. {
  303. return ::SetupAndRun(m_pMalloc, std::mem_fn(pFn), m_pReal, Args...);
  304. }
  305. public:
  306. DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL();
  307. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void** ppvObject) override final
  308. {
  309. return ::SetupAndRun(
  310. m_pMalloc,
  311. std::mem_fn(&Entrypoint<IInterface>::QueryInterfaceImpl),
  312. ThisPtr(this),
  313. iid,
  314. CheckNotNull(OutParam(ppvObject)));
  315. }
  316. HRESULT STDMETHODCALLTYPE QueryInterfaceImpl(REFIID iid, void** ppvObject)
  317. {
  318. // Special-casing so we don't need to create a new wrapper.
  319. if (iid == __uuidof(IInterface) ||
  320. iid == __uuidof(IUnknown) ||
  321. iid == __uuidof(INoMarshal))
  322. {
  323. this->AddRef();
  324. *ppvObject = this;
  325. return S_OK;
  326. }
  327. CComPtr<IUnknown> RealQI;
  328. IFR(m_pReal->QueryInterface(iid, (void**)&RealQI));
  329. return CreateEntrypointWrapper(m_pMalloc, RealQI, iid, ppvObject);
  330. }
  331. };
  332. #define DEFINE_ENTRYPOINT_BOILERPLATE(Name) \
  333. Name(IMalloc *M, IInterface *pI) : Entrypoint<IInterface>(M, pI){} \
  334. DXC_MICROCOM_TM_ALLOC(Name)
  335. struct IUnknownEntrypoint : public Entrypoint<IUnknown>
  336. {
  337. DEFINE_ENTRYPOINT_BOILERPLATE(IUnknownEntrypoint);
  338. };
  339. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IUnknown);
  340. struct IDxcPixTypeEntrypoint : public Entrypoint<IDxcPixType>
  341. {
  342. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixTypeEntrypoint);
  343. STDMETHODIMP GetName(
  344. _Outptr_result_z_ BSTR *Name) override
  345. {
  346. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  347. }
  348. STDMETHODIMP GetSizeInBits(
  349. _Outptr_result_z_ DWORD *SizeInBits) override
  350. {
  351. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  352. }
  353. STDMETHODIMP UnAlias(
  354. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  355. {
  356. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  357. }
  358. };
  359. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixType);
  360. struct IDxcPixConstTypeEntrypoint : public Entrypoint<IDxcPixConstType>
  361. {
  362. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixConstTypeEntrypoint);
  363. STDMETHODIMP GetName(
  364. _Outptr_result_z_ BSTR *Name) override
  365. {
  366. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  367. }
  368. STDMETHODIMP GetSizeInBits(
  369. _Outptr_result_z_ DWORD *SizeInBits) override
  370. {
  371. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  372. }
  373. STDMETHODIMP UnAlias(
  374. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  375. {
  376. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  377. }
  378. };
  379. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixConstType);
  380. struct IDxcPixTypedefTypeEntrypoint : public Entrypoint<IDxcPixTypedefType>
  381. {
  382. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixTypedefTypeEntrypoint);
  383. STDMETHODIMP GetName(
  384. _Outptr_result_z_ BSTR *Name) override
  385. {
  386. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  387. }
  388. STDMETHODIMP GetSizeInBits(
  389. _Outptr_result_z_ DWORD *SizeInBits) override
  390. {
  391. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  392. }
  393. STDMETHODIMP UnAlias(
  394. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  395. {
  396. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  397. }
  398. };
  399. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixTypedefType);
  400. struct IDxcPixScalarTypeEntrypoint : public Entrypoint<IDxcPixScalarType>
  401. {
  402. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixScalarTypeEntrypoint);
  403. STDMETHODIMP GetName(
  404. _Outptr_result_z_ BSTR *Name) override
  405. {
  406. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  407. }
  408. STDMETHODIMP GetSizeInBits(
  409. _Outptr_result_z_ DWORD *SizeInBits) override
  410. {
  411. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  412. }
  413. STDMETHODIMP UnAlias(
  414. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  415. {
  416. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  417. }
  418. };
  419. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixScalarType);
  420. struct IDxcPixArrayTypeEntrypoint : public Entrypoint<IDxcPixArrayType>
  421. {
  422. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixArrayTypeEntrypoint);
  423. STDMETHODIMP GetName(
  424. _Outptr_result_z_ BSTR *Name) override
  425. {
  426. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  427. }
  428. STDMETHODIMP GetSizeInBits(
  429. _Outptr_result_z_ DWORD *SizeInBits) override
  430. {
  431. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  432. }
  433. STDMETHODIMP UnAlias(
  434. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  435. {
  436. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  437. }
  438. STDMETHODIMP GetNumElements(
  439. _Outptr_result_z_ DWORD *ppNumElements) override
  440. {
  441. return InvokeOnReal(&IInterface::GetNumElements, CheckNotNull(OutParam(ppNumElements)));
  442. }
  443. STDMETHODIMP GetIndexedType(
  444. _Outptr_result_z_ IDxcPixType **ppElementType) override
  445. {
  446. return InvokeOnReal(&IInterface::GetIndexedType, CheckNotNull(OutParam(ppElementType)));
  447. }
  448. STDMETHODIMP GetElementType(
  449. _Outptr_result_z_ IDxcPixType** ppElementType) override
  450. {
  451. return InvokeOnReal(&IInterface::GetElementType, CheckNotNull(OutParam(ppElementType)));
  452. }
  453. };
  454. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixArrayType);
  455. struct IDxcPixStructFieldEntrypoint : public Entrypoint<IDxcPixStructField>
  456. {
  457. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixStructFieldEntrypoint);
  458. STDMETHODIMP GetName(
  459. _Outptr_result_z_ BSTR *Name) override
  460. {
  461. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  462. }
  463. STDMETHODIMP GetType(
  464. _Outptr_result_z_ IDxcPixType** ppType) override
  465. {
  466. return InvokeOnReal(&IInterface::GetType, CheckNotNull(OutParam(ppType)));
  467. }
  468. STDMETHODIMP GetOffsetInBits(
  469. _Outptr_result_z_ DWORD *pOffsetInBits) override
  470. {
  471. return InvokeOnReal(&IInterface::GetOffsetInBits, CheckNotNull(OutParam(pOffsetInBits)));
  472. }
  473. };
  474. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixStructField);
  475. struct IDxcPixStructTypeEntrypoint : public Entrypoint<IDxcPixStructType>
  476. {
  477. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixStructTypeEntrypoint);
  478. STDMETHODIMP GetName(
  479. _Outptr_result_z_ BSTR *Name) override
  480. {
  481. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  482. }
  483. STDMETHODIMP GetSizeInBits(
  484. _Outptr_result_z_ DWORD *SizeInBits) override
  485. {
  486. return InvokeOnReal(&IInterface::GetSizeInBits, CheckNotNull(OutParam(SizeInBits)));
  487. }
  488. STDMETHODIMP UnAlias(
  489. _Outptr_result_z_ IDxcPixType** ppBaseType) override
  490. {
  491. return InvokeOnReal(&IInterface::UnAlias, CheckNotNull(OutParam(ppBaseType)));
  492. }
  493. STDMETHODIMP GetNumFields(
  494. _Outptr_result_z_ DWORD* ppNumFields) override
  495. {
  496. return InvokeOnReal(&IInterface::GetNumFields, CheckNotNull(OutParam(ppNumFields)));
  497. }
  498. STDMETHODIMP GetFieldByIndex(
  499. DWORD dwIndex,
  500. _Outptr_result_z_ IDxcPixStructField **ppField) override
  501. {
  502. return InvokeOnReal(&IInterface::GetFieldByIndex, dwIndex, CheckNotNull(OutParam(ppField)));
  503. }
  504. STDMETHODIMP GetFieldByName(
  505. _In_ LPCWSTR lpName,
  506. _Outptr_result_z_ IDxcPixStructField** ppField) override
  507. {
  508. return InvokeOnReal(&IInterface::GetFieldByName, CheckNotNull(InParam(lpName)), CheckNotNull(OutParam(ppField)));
  509. }
  510. };
  511. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixStructType);
  512. struct IDxcPixDxilStorageEntrypoint : public Entrypoint<IDxcPixDxilStorage>
  513. {
  514. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilStorageEntrypoint);
  515. STDMETHODIMP AccessField(
  516. _In_ LPCWSTR Name,
  517. _COM_Outptr_ IDxcPixDxilStorage** ppResult) override
  518. {
  519. return InvokeOnReal(&IInterface::AccessField, CheckNotNull(InParam(Name)), CheckNotNull(OutParam(ppResult)));
  520. }
  521. STDMETHODIMP Index(
  522. _In_ DWORD Index,
  523. _COM_Outptr_ IDxcPixDxilStorage** ppResult) override
  524. {
  525. return InvokeOnReal(&IInterface::Index, Index, CheckNotNull(OutParam(ppResult)));
  526. }
  527. STDMETHODIMP GetRegisterNumber(
  528. _Outptr_result_z_ DWORD *pRegNum) override
  529. {
  530. return InvokeOnReal(&IInterface::GetRegisterNumber, CheckNotNull(OutParam(pRegNum)));
  531. }
  532. STDMETHODIMP GetIsAlive() override
  533. {
  534. return InvokeOnReal(&IInterface::GetIsAlive);
  535. }
  536. STDMETHODIMP GetType(
  537. _Outptr_result_z_ IDxcPixType** ppType) override
  538. {
  539. return InvokeOnReal(&IInterface::GetType, CheckNotNull(OutParam(ppType)));
  540. }
  541. };
  542. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilStorage);
  543. struct IDxcPixVariableEntrypoint : public Entrypoint<IDxcPixVariable>
  544. {
  545. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixVariableEntrypoint);
  546. STDMETHODIMP GetName(
  547. _Outptr_result_z_ BSTR *Name) override
  548. {
  549. return InvokeOnReal(&IInterface::GetName, CheckNotNull(OutParam(Name)));
  550. }
  551. STDMETHODIMP GetType(
  552. _Outptr_result_z_ IDxcPixType **ppType) override
  553. {
  554. return InvokeOnReal(&IInterface::GetType, CheckNotNull(OutParam(ppType)));
  555. }
  556. STDMETHODIMP GetStorage(
  557. _COM_Outptr_ IDxcPixDxilStorage **ppStorage) override
  558. {
  559. return InvokeOnReal(&IInterface::GetStorage, CheckNotNull(OutParam(ppStorage)));
  560. }
  561. };
  562. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixVariable);
  563. struct IDxcPixDxilLiveVariablesEntrypoint : public Entrypoint<IDxcPixDxilLiveVariables>
  564. {
  565. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilLiveVariablesEntrypoint);
  566. STDMETHODIMP GetCount(
  567. _Outptr_ DWORD *dwSize) override
  568. {
  569. return InvokeOnReal(&IInterface::GetCount, CheckNotNull(OutParam(dwSize)));
  570. }
  571. STDMETHODIMP GetVariableByIndex(
  572. _In_ DWORD Index,
  573. _Outptr_result_z_ IDxcPixVariable ** ppVariable) override
  574. {
  575. return InvokeOnReal(&IInterface::GetVariableByIndex, Index, CheckNotNull(OutParam(ppVariable)));
  576. }
  577. STDMETHODIMP GetVariableByName(
  578. _In_ LPCWSTR Name,
  579. _Outptr_result_z_ IDxcPixVariable** ppVariable) override
  580. {
  581. return InvokeOnReal(&IInterface::GetVariableByName, CheckNotNull(InParam(Name)), CheckNotNull(OutParam(ppVariable)));
  582. }
  583. };
  584. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilLiveVariables);
  585. struct IDxcPixDxilDebugInfoEntrypoint : public Entrypoint<IDxcPixDxilDebugInfo>
  586. {
  587. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilDebugInfoEntrypoint);
  588. STDMETHODIMP GetLiveVariablesAt(
  589. _In_ DWORD InstructionOffset,
  590. _COM_Outptr_ IDxcPixDxilLiveVariables **ppLiveVariables) override
  591. {
  592. return InvokeOnReal(&IInterface::GetLiveVariablesAt, InstructionOffset, CheckNotNull(OutParam(ppLiveVariables)));
  593. }
  594. STDMETHODIMP IsVariableInRegister(
  595. _In_ DWORD InstructionOffset,
  596. _In_ const wchar_t *VariableName) override
  597. {
  598. return InvokeOnReal(&IInterface::IsVariableInRegister, InstructionOffset, CheckNotNull(InParam(VariableName)));
  599. }
  600. STDMETHODIMP GetFunctionName(
  601. _In_ DWORD InstructionOffset,
  602. _Outptr_result_z_ BSTR *ppFunctionName) override
  603. {
  604. return InvokeOnReal(&IInterface::GetFunctionName, InstructionOffset, CheckNotNull(OutParam(ppFunctionName)));
  605. }
  606. STDMETHODIMP GetStackDepth(
  607. _In_ DWORD InstructionOffset,
  608. _Outptr_ DWORD *StackDepth) override
  609. {
  610. return InvokeOnReal(&IInterface::GetStackDepth, InstructionOffset, CheckNotNull(OutParam(StackDepth)));
  611. }
  612. STDMETHODIMP InstructionOffsetsFromSourceLocation(
  613. _In_ const wchar_t* FileName,
  614. _In_ DWORD SourceLine,
  615. _In_ DWORD SourceColumn,
  616. _COM_Outptr_ IDxcPixDxilInstructionOffsets** ppOffsets) override
  617. {
  618. return InvokeOnReal(&IInterface::InstructionOffsetsFromSourceLocation, CheckNotNull(InParam(FileName)), SourceLine, SourceColumn, CheckNotNull(OutParam(ppOffsets)));
  619. }
  620. };
  621. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilDebugInfo);
  622. struct IDxcPixDxilInstructionOffsetsEntrypoint : public Entrypoint<IDxcPixDxilInstructionOffsets>
  623. {
  624. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixDxilInstructionOffsetsEntrypoint);
  625. STDMETHODIMP_(DWORD) GetCount() override
  626. {
  627. return InvokeOnReal(&IInterface::GetCount);
  628. }
  629. STDMETHODIMP_(DWORD) GetOffsetByIndex(_In_ DWORD Index) override
  630. {
  631. return InvokeOnReal(&IInterface::GetOffsetByIndex, Index);
  632. }
  633. };
  634. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixDxilInstructionOffsets);
  635. struct IDxcPixCompilationInfoEntrypoint
  636. : public Entrypoint<IDxcPixCompilationInfo>
  637. {
  638. DEFINE_ENTRYPOINT_BOILERPLATE(IDxcPixCompilationInfoEntrypoint);
  639. virtual STDMETHODIMP
  640. GetSourceFile(_In_ DWORD SourceFileOrdinal,
  641. _Outptr_result_z_ BSTR *pSourceName,
  642. _Outptr_result_z_ BSTR *pSourceContents) override {
  643. return InvokeOnReal(&IInterface::GetSourceFile, SourceFileOrdinal,
  644. CheckNotNull(OutParam(pSourceName)),
  645. CheckNotNull(OutParam(pSourceContents))
  646. );
  647. }
  648. virtual STDMETHODIMP GetArguments(_Outptr_result_z_ BSTR* pArguments) override
  649. {
  650. return InvokeOnReal(&IInterface::GetArguments, CheckNotNull(OutParam(pArguments)));
  651. }
  652. virtual STDMETHODIMP
  653. GetMacroDefinitions(_Outptr_result_z_ BSTR* pMacroDefinitions) override
  654. {
  655. return InvokeOnReal(&IInterface::GetMacroDefinitions,
  656. CheckNotNull(OutParam(pMacroDefinitions)));
  657. }
  658. virtual STDMETHODIMP
  659. GetEntryPointFile(_Outptr_result_z_ BSTR* pEntryPointFile) override {
  660. return InvokeOnReal(&IInterface::GetEntryPointFile,
  661. CheckNotNull(OutParam(pEntryPointFile)));
  662. }
  663. virtual STDMETHODIMP
  664. GetHlslTarget(_Outptr_result_z_ BSTR* pHlslTarget) override {
  665. return InvokeOnReal(&IInterface::GetHlslTarget,
  666. CheckNotNull(OutParam(pHlslTarget)));
  667. }
  668. virtual STDMETHODIMP
  669. GetEntryPoint(_Outptr_result_z_ BSTR* pEntryPoint) override
  670. {
  671. return InvokeOnReal(&IInterface::GetEntryPoint,
  672. CheckNotNull(OutParam(pEntryPoint)));
  673. }
  674. };
  675. DEFINE_ENTRYPOINT_WRAPPER_TRAIT(IDxcPixCompilationInfo);
  676. HRESULT CreateEntrypointWrapper(
  677. IMalloc* pMalloc,
  678. IUnknown* pReal,
  679. REFIID riid,
  680. void** ppvObject)
  681. {
  682. #define HANDLE_INTERFACE(IInterface) \
  683. if (__uuidof(IInterface) == riid) \
  684. { \
  685. return NewDxcPixDxilDebugInfoObjectOrThrow<IInterface##Entrypoint>( \
  686. (IInterface **) ppvObject, \
  687. pMalloc, \
  688. (IInterface *) pReal); \
  689. } (void)0
  690. HANDLE_INTERFACE(IUnknown);
  691. HANDLE_INTERFACE(IDxcPixType);
  692. HANDLE_INTERFACE(IDxcPixConstType);
  693. HANDLE_INTERFACE(IDxcPixTypedefType);
  694. HANDLE_INTERFACE(IDxcPixScalarType);
  695. HANDLE_INTERFACE(IDxcPixArrayType);
  696. HANDLE_INTERFACE(IDxcPixStructField);
  697. HANDLE_INTERFACE(IDxcPixStructType);
  698. HANDLE_INTERFACE(IDxcPixDxilStorage);
  699. HANDLE_INTERFACE(IDxcPixVariable);
  700. HANDLE_INTERFACE(IDxcPixDxilLiveVariables);
  701. HANDLE_INTERFACE(IDxcPixDxilDebugInfo);
  702. HANDLE_INTERFACE(IDxcPixCompilationInfo);
  703. return E_FAIL;
  704. }
  705. } // namespace entrypoints
  706. } // namespace dxil_debug_info
  707. #include "DxilDiaSession.h"
  708. using namespace dxil_debug_info::entrypoints;
  709. static STDMETHODIMP NewDxcPixDxilDebugInfoImpl(
  710. IMalloc *pMalloc,
  711. dxil_dia::Session *pSession,
  712. IDxcPixDxilDebugInfo** ppDxilDebugInfo
  713. )
  714. {
  715. return dxil_debug_info::NewDxcPixDxilDebugInfoObjectOrThrow<dxil_debug_info::DxcPixDxilDebugInfo>(
  716. ppDxilDebugInfo,
  717. pMalloc,
  718. pSession);
  719. }
  720. STDMETHODIMP dxil_dia::Session::NewDxcPixDxilDebugInfo(
  721. _COM_Outptr_ IDxcPixDxilDebugInfo** ppDxilDebugInfo)
  722. {
  723. return SetupAndRun(
  724. m_pMalloc,
  725. &NewDxcPixDxilDebugInfoImpl,
  726. m_pMalloc,
  727. ThisPtr(this),
  728. CheckNotNull(OutParam(ppDxilDebugInfo)));
  729. }
  730. static STDMETHODIMP NewDxcPixCompilationInfoImpl(
  731. IMalloc *pMalloc,
  732. dxil_dia::Session *pSession,
  733. IDxcPixCompilationInfo** ppCompilationInfo
  734. )
  735. {
  736. return dxil_debug_info::CreateDxilCompilationInfo(
  737. pMalloc,
  738. pSession,
  739. ppCompilationInfo);
  740. }
  741. STDMETHODIMP dxil_dia::Session::NewDxcPixCompilationInfo(
  742. _COM_Outptr_ IDxcPixCompilationInfo **ppCompilationInfo)
  743. {
  744. return SetupAndRun(
  745. m_pMalloc,
  746. &NewDxcPixCompilationInfoImpl,
  747. m_pMalloc,
  748. ThisPtr(this),
  749. CheckNotNull(OutParam(ppCompilationInfo)));
  750. }