DxilContainerReader.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // DxilContainerReader.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. // Provides support for manipulating DXIL container structures. //
  9. // //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "dxc/Support/Global.h"
  12. #include "dxc/Support/Unicode.h"
  13. #include "dxc/Support/WinIncludes.h"
  14. #include "dxc/DXIL/DxilSubobject.h"
  15. #include "dxc/DxilContainer/DxilContainerReader.h"
  16. #include "dxc/DxilContainer/DxilRuntimeReflection.h"
  17. namespace hlsl {
  18. bool LoadSubobjectsFromRDAT(DxilSubobjects &subobjects, RDAT::SubobjectTableReader *pSubobjectTableReader) {
  19. if (!pSubobjectTableReader)
  20. return false;
  21. bool result = true;
  22. for (unsigned i = 0; i < pSubobjectTableReader->GetCount(); ++i) {
  23. try {
  24. auto reader = pSubobjectTableReader->GetItem(i);
  25. DXIL::SubobjectKind kind = reader.GetKind();
  26. bool bLocalRS = false;
  27. switch (kind) {
  28. case DXIL::SubobjectKind::StateObjectConfig:
  29. subobjects.CreateStateObjectConfig(reader.GetName(),
  30. reader.GetStateObjectConfig_Flags());
  31. break;
  32. case DXIL::SubobjectKind::LocalRootSignature:
  33. bLocalRS = true;
  34. case DXIL::SubobjectKind::GlobalRootSignature: {
  35. const void *pOutBytes;
  36. uint32_t OutSizeInBytes;
  37. if (!reader.GetRootSignature(&pOutBytes, &OutSizeInBytes)) {
  38. result = false;
  39. continue;
  40. }
  41. subobjects.CreateRootSignature(reader.GetName(), bLocalRS, pOutBytes, OutSizeInBytes);
  42. break;
  43. }
  44. case DXIL::SubobjectKind::SubobjectToExportsAssociation: {
  45. uint32_t NumExports = reader.GetSubobjectToExportsAssociation_NumExports();
  46. std::vector<llvm::StringRef> Exports;
  47. Exports.resize(NumExports);
  48. for (unsigned i = 0; i < NumExports; ++i) {
  49. Exports[i] = reader.GetSubobjectToExportsAssociation_Export(i);
  50. }
  51. subobjects.CreateSubobjectToExportsAssociation(reader.GetName(),
  52. reader.GetSubobjectToExportsAssociation_Subobject(),
  53. Exports.data(), NumExports);
  54. break;
  55. }
  56. case DXIL::SubobjectKind::RaytracingShaderConfig:
  57. subobjects.CreateRaytracingShaderConfig(reader.GetName(),
  58. reader.GetRaytracingShaderConfig_MaxPayloadSizeInBytes(),
  59. reader.GetRaytracingShaderConfig_MaxAttributeSizeInBytes());
  60. break;
  61. case DXIL::SubobjectKind::RaytracingPipelineConfig:
  62. subobjects.CreateRaytracingPipelineConfig(reader.GetName(),
  63. reader.GetRaytracingPipelineConfig_MaxTraceRecursionDepth());
  64. break;
  65. case DXIL::SubobjectKind::HitGroup:
  66. subobjects.CreateHitGroup(reader.GetName(),
  67. reader.GetHitGroup_Type(),
  68. reader.GetHitGroup_AnyHit(),
  69. reader.GetHitGroup_ClosestHit(),
  70. reader.GetHitGroup_Intersection());
  71. break;
  72. }
  73. } catch (hlsl::Exception &) {
  74. result = false;
  75. }
  76. }
  77. return result;
  78. }
  79. } // namespace hlsl
  80. // DxilRuntimeReflection implementation
  81. #include "dxc/DxilContainer/DxilRuntimeReflection.inl"