DxilContainerReader.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilContainerReader.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. // Helper class for reading from dxil container. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #pragma once
  12. #include "llvm/ADT/STLExtras.h"
  13. #include "dxc/Support/Global.h"
  14. #include "dxc/Support/WinIncludes.h"
  15. #include "dxc/DxilContainer/DxilContainer.h"
  16. namespace hlsl {
  17. #define DXIL_CONTAINER_BLOB_NOT_FOUND -1
  18. struct DxilContainerHeader;
  19. //=================================================================================================================================
  20. // DxilContainerReader
  21. //
  22. // Parse a DXIL or DXBC Container that you provide as input.
  23. //
  24. // Basic usage:
  25. // (1) Call Load()
  26. // (2) Call various Get*() commands to retrieve information about the container such as
  27. // how many blobs are in it, the hash of the container, the version #, and most importantly
  28. // retrieve all of the Blobs. You can retrieve blobs by searching for the FourCC, or
  29. // enumerate through all of them. Multiple blobs can even have the same FourCC, if you choose to
  30. // create the DXBC that way, and this parser will let you discover all of them.
  31. // (3) You can parse a new container by calling Load() again, or just get rid of the class.
  32. //
  33. class DxilContainerReader
  34. {
  35. public:
  36. DxilContainerReader() {}
  37. // Sets the container to be parsed, and does some
  38. // basic integrity checking, making sure the blob FourCCs
  39. // are all from the known list, and ensuring the version is:
  40. // Major = DXBC_MAJOR_VERSION
  41. // Minor = DXBC_MAJOR_VERSION
  42. //
  43. // Returns S_OK or E_FAIL
  44. HRESULT Load(_In_ const void* pContainer, _In_ uint32_t containerSizeInBytes);
  45. HRESULT GetVersion(_Out_ DxilContainerVersion *pResult);
  46. HRESULT GetPartCount(_Out_ uint32_t *pResult);
  47. HRESULT GetPartContent(uint32_t idx, _Outptr_ const void **ppResult, _Out_ uint32_t *pResultSize = nullptr);
  48. HRESULT GetPartFourCC(uint32_t idx, _Out_ uint32_t *pResult);
  49. HRESULT FindFirstPartKind(uint32_t kind, _Out_ uint32_t *pResult);
  50. private:
  51. const void* m_pContainer = nullptr;
  52. uint32_t m_uContainerSize = 0;
  53. const DxilContainerHeader *m_pHeader = nullptr;
  54. bool IsLoaded() const { return m_pHeader != nullptr; }
  55. };
  56. } // namespace hlsl