DxcContainerBuilder.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxcContainerBuilder.h //
  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. // Implements the Dxil Container Builder //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "dxc/dxcapi.h"
  13. #include "dxc/Support/Global.h"
  14. #include "dxc/Support/WinIncludes.h"
  15. #include "dxc/DxilContainer/DxilContainer.h"
  16. #include "dxc/Support/microcom.h"
  17. #include "llvm/ADT/SmallVector.h"
  18. using namespace hlsl;
  19. namespace hlsl {
  20. class AbstractMemoryStream;
  21. }
  22. class DxcContainerBuilder : public IDxcContainerBuilder {
  23. public:
  24. HRESULT STDMETHODCALLTYPE Load(_In_ IDxcBlob *pDxilContainerHeader) override; // Loads DxilContainer to the builder
  25. HRESULT STDMETHODCALLTYPE AddPart(_In_ UINT32 fourCC, _In_ IDxcBlob *pSource) override; // Add the given part with fourCC
  26. HRESULT STDMETHODCALLTYPE RemovePart(_In_ UINT32 fourCC) override; // Remove the part with fourCC
  27. HRESULT STDMETHODCALLTYPE SerializeContainer(_Out_ IDxcOperationResult **ppResult) override; // Builds a container of the given container builder state
  28. DXC_MICROCOM_TM_ADDREF_RELEASE_IMPL()
  29. DXC_MICROCOM_TM_CTOR(DxcContainerBuilder)
  30. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void **ppvObject) override {
  31. return DoBasicQueryInterface<IDxcContainerBuilder>(this, riid, ppvObject);
  32. }
  33. void Init(const char *warning = nullptr) {
  34. m_warning = warning;
  35. m_RequireValidation = false;
  36. }
  37. protected:
  38. DXC_MICROCOM_TM_REF_FIELDS()
  39. private:
  40. class DxilPart {
  41. public:
  42. UINT32 m_fourCC;
  43. CComPtr<IDxcBlob> m_Blob;
  44. DxilPart(UINT32 fourCC, IDxcBlob *pSource) : m_fourCC(fourCC), m_Blob(pSource) {}
  45. };
  46. typedef llvm::SmallVector<DxilPart, 8> PartList;
  47. PartList m_parts;
  48. CComPtr<IDxcBlob> m_pContainer;
  49. const char *m_warning;
  50. bool m_RequireValidation;
  51. UINT32 ComputeContainerSize();
  52. HRESULT UpdateContainerHeader(AbstractMemoryStream *pStream, uint32_t containerSize);
  53. HRESULT UpdateOffsetTable(AbstractMemoryStream *pStream);
  54. HRESULT UpdateParts(AbstractMemoryStream *pStream);
  55. };