3
0

AzslData.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Atom/RHI.Reflect/Handle.h>
  10. #include <Atom/RHI.Reflect/ShaderResourceGroupLayoutDescriptor.h>
  11. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  12. #include <AzCore/std/containers/map.h>
  13. #include <AzCore/std/containers/vector.h>
  14. #include <AzCore/std/string/string.h>
  15. #include <CommonFiles/CommonTypes.h>
  16. namespace AZ
  17. {
  18. namespace ShaderBuilder
  19. {
  20. using ConstantBufferContainer = AZStd::vector<ConstantBufferData>;
  21. using StructContainer = AZStd::vector<StructData>;
  22. using SamplerContainer = AZStd::vector<SamplerSrgData>;
  23. using TextureContainer = AZStd::vector<TextureSrgData>;
  24. using BufferContainer = AZStd::vector<BufferSrgData>;
  25. using SrgConstantContainer = AZStd::vector<SrgConstantData>;
  26. struct SrgData
  27. {
  28. //friend bool operator == (const SrgData&, const SrgData&);
  29. AZStd::string m_name;
  30. AZStd::string m_containingFileName;
  31. // One SRG contains the ShaderVariantKey fallback structure
  32. // A size greater than 0 indicates that this SRG data is designated as fallback
  33. Name m_fallbackName;
  34. uint32_t m_fallbackSize = 0;
  35. RHI::Handle<uint32_t> m_bindingSlot;
  36. ConstantBufferContainer m_constantBuffers;
  37. SamplerContainer m_samplers;
  38. StructContainer m_structs;
  39. TextureContainer m_textures;
  40. BufferContainer m_buffers;
  41. SrgConstantContainer m_srgConstantData;
  42. uint32_t m_srgConstantDataRegisterId = RHI::UndefinedRegisterSlot;
  43. uint32_t m_srgConstantDataSpaceId = RHI::UndefinedRegisterSlot;
  44. };
  45. struct FunctionData
  46. {
  47. AZStd::string m_returnType;
  48. AZStd::string m_name;
  49. AZStd::string m_parametersAndContents; // Everything else is lumped together
  50. // Indicates if the function declares any shader stage inputs or outputs by the use of semantics
  51. bool m_hasShaderStageVaryings = false;
  52. RHI::ShaderStageAttributeMap attributesList;
  53. };
  54. typedef AZStd::vector<SrgData> SrgDataContainer;
  55. typedef AZStd::vector<FunctionData> AzslFunctions;
  56. struct RootConstantData
  57. {
  58. RootConstantBinding m_bindingInfo;
  59. SrgConstantContainer m_constants;
  60. };
  61. struct ShaderFiles
  62. {
  63. AZStd::string m_azslSourceFullPath; //!< Full path to the source AZSL file (referred by the "Source" json element in .shader)
  64. AZStd::string m_shaderFileName; //!< Name for the .shader file
  65. AZStd::string m_azslFileName; //!< Name for the source .azsl file
  66. };
  67. //! DEPRECATED [ATOM-15472]
  68. //! This class is used to collect all the json files produced by the compilation
  69. //! of an AZSL file as objects.
  70. struct AzslData
  71. {
  72. AzslData(const AZStd::shared_ptr<ShaderFiles>& a_sources) : m_sources(a_sources) { }
  73. AZStd::shared_ptr<ShaderFiles> m_sources;
  74. AZStd::string m_preprocessedFullPath; // Full path to a preprocessed version of the original AZSL file
  75. AZStd::string m_shaderCodePrefix; // AssetProcessor generated shader code which is added to the
  76. // AZSLc emitted code prior to invoking the native shader compiler
  77. SrgDataContainer m_srgData;
  78. AzslFunctions m_functions;
  79. StructContainer m_structs;
  80. RootConstantData m_rootConstantData;
  81. };
  82. //! This class is used to collect all the json files produced by the compilation
  83. //! of an AZSL file as objects.
  84. struct AzslData2
  85. {
  86. AzslData2(const AZStd::shared_ptr<ShaderFiles>& a_sources)
  87. : m_sources(a_sources)
  88. {
  89. }
  90. AZStd::shared_ptr<ShaderFiles> m_sources;
  91. AZStd::string m_preprocessedFullPath; // Full path to a preprocessed version of the original AZSL file
  92. SrgDataContainer m_srgData;
  93. AzslFunctions m_functions;
  94. StructContainer m_structs;
  95. RootConstantData m_rootConstantData;
  96. };
  97. } // ShaderBuilder
  98. } // AZ