3
0

AzslCompiler.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <AzslData.h>
  10. #include <AzFramework/FileFunc/FileFunc.h>
  11. #include <Atom/RPI.Reflect/Base.h>
  12. #include <Editor/ShaderBuilderUtility.h>
  13. namespace AZ
  14. {
  15. namespace RPI
  16. {
  17. class ShaderOptionGroupLayout;
  18. }
  19. namespace RHI
  20. {
  21. class ShaderPlatformInterface;
  22. }
  23. namespace ShaderBuilder
  24. {
  25. class AzslCompiler
  26. {
  27. public:
  28. //! AzslCompiler constructor
  29. //! @param inputFilePath The target input file to compile. Should be a valid AZSL file with no preprocessing directives.
  30. AzslCompiler(const AZStd::string& inputFilePath, const AZStd::string& tempFolder);
  31. //! compile with --full and generate all .json files
  32. //! @param outputFile="" will use the input as base path.
  33. Outcome<ShaderBuilderUtility::AzslSubProducts::Paths> EmitFullData(const AZStd::vector<AZStd::string>& azslcArguments,
  34. const AZStd::string& outputFile = "") const;
  35. //! compile to HLSL independently
  36. bool EmitShader(AZ::IO::GenericStream& outputStream,
  37. const AZStd::string& extraCompilerParams) const;
  38. //! compile with --ia independently and populate document @output
  39. bool EmitInputAssembler(rapidjson::Document& output) const;
  40. //! compile with --om independently
  41. bool EmitOutputMerger(rapidjson::Document& output) const;
  42. //! compile with --srg independently
  43. bool EmitSrgData(rapidjson::Document& output, const AZStd::string& extraCompilerParams) const;
  44. //! compile with --option independently
  45. bool EmitOptionsList(rapidjson::Document& output) const;
  46. //! compile with --bindingdep independently
  47. bool EmitBindingDependencies(rapidjson::Document& output) const;
  48. //! make sense of a --ia json document and fill up the function data
  49. bool ParseIaPopulateFunctionData(const rapidjson::Document& input, AzslFunctions& functionData) const;
  50. //! make sense of a --ia json document and fill up the struct data
  51. bool ParseIaPopulateStructData(const rapidjson::Document& input, const AZStd::string& vertexEntryName, StructData& outStructData) const;
  52. //! make sense of a --om json document and fill up the struct data
  53. bool ParseOmPopulateStructData(const rapidjson::Document& input, const AZStd::string& fragmentShaderName, StructData& outStructData) const;
  54. //! make sense of a --srg json document and fill up the srg data container
  55. bool ParseSrgPopulateSrgData(const rapidjson::Document& input, SrgDataContainer& outSrgData) const;
  56. //! make sense of a --option json document and fill up the shader option group layout
  57. bool ParseOptionsPopulateOptionGroupLayout(const rapidjson::Document& input, RPI::Ptr<RPI::ShaderOptionGroupLayout>& shaderOptionGroupLayout, bool& outSpecializationConstants) const;
  58. //! make sense of a --bindingdep json documment and fill up the binding dependencies object
  59. bool ParseBindingdepPopulateBindingDependencies(const rapidjson::Document& input, BindingDependencies& bindingDependencies) const;
  60. //! make sense of a --srg json document and fill up the root constant data
  61. bool ParseSrgPopulateRootConstantData(const rapidjson::Document& input, RootConstantData& rootConstantData) const;
  62. //! retrieve the main input set during construction
  63. const AZStd::string& GetInputFilePath() const;
  64. protected:
  65. bool Compile(const AZStd::string& CompilerParams, const AZStd::string& outputFilePath) const;
  66. enum class AfterRead
  67. {
  68. Delete,
  69. Keep
  70. };
  71. enum class BuildResult
  72. {
  73. Success,
  74. VersionError,
  75. CompilationFailed,
  76. JsonReadbackFailed,
  77. };
  78. BuildResult CompileToFileAndPrepareJsonDocument(
  79. rapidjson::Document& outputJson,
  80. const char* compilerCommandSwitch,
  81. const char* outputExtension,
  82. AfterRead deleteOutputFileAfterReading = AfterRead::Keep) const;
  83. BuildResult PrepareJsonDocument(
  84. rapidjson::Document& outputJson,
  85. const char* outputExtension) const;
  86. AZStd::string m_inputFilePath;
  87. AZStd::string m_tempFolder;
  88. };
  89. }
  90. }