3
0

ShaderManagementConsoleDocumentRequestBus.h 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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/RPI.Edit/Shader/ShaderSourceData.h>
  10. #include <Atom/RPI.Edit/Shader/ShaderVariantListSourceData.h>
  11. #include <Atom/RPI.Reflect/Shader/ShaderOptionGroupLayout.h>
  12. #include <AzCore/Asset/AssetCommon.h>
  13. namespace ShaderManagementConsole
  14. {
  15. struct DocumentVerificationResult
  16. {
  17. bool AllGood() const { return !m_hasRedundantVariants && !m_hasRootLike && !m_hasStableIdJump; }
  18. bool m_hasRedundantVariants = false;
  19. bool m_hasRootLike = false;
  20. AZ::u32 m_rootLikeStableId{};
  21. bool m_hasStableIdJump = false;
  22. AZ::u32 faultyId{};
  23. };
  24. class ShaderManagementConsoleDocumentRequests : public AZ::EBusTraits
  25. {
  26. public:
  27. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  28. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  29. typedef AZ::Uuid BusIdType;
  30. //! Add a new shader variant with a unique stable ID to the variant list
  31. virtual void AddOneVariantRow() = 0;
  32. //! Add a batch of variants
  33. //! The variants don't have to be fully enumerated, only some options may participate
  34. //! `optionHeaders` are like a csv file first line, they name the columns.
  35. //! example: o_fog | o_shadow | o_brdfModel
  36. //! --------|------------|--------------
  37. //! 0 | 1 |
  38. //! 1 | 0 |
  39. //! In that case optionHeaders is ["o_fog", "o_shadow"]
  40. //! and matrixOfValues is [ 0,1, 1,0 ] # flattened values-subrect matrix
  41. virtual void AppendSparseVariantSet(AZStd::vector<AZ::Name> optionHeaders, AZStd::vector<AZ::Name> matrixOfValues) = 0;
  42. //! Mix-expand a batch of variants
  43. //! Like the function above the options, the argument and matrix layout work in the same fashion.
  44. //! The difference is that instead of append, this will "multiply" the current variants in the document,
  45. //! with the given new variants (matrix rows).
  46. //! So if you have 10 current variants in your document, and pass a matrix of 4 options x 2 rows,
  47. //! The final document will have 20 variants.
  48. //! If the matrixOfValues specifies option values that are already set by the current variants,
  49. //! the current option values will be overwritten and lost.
  50. //! The matrixOfValues is expected to be a full enumeration in the current usage client: the ExpandOptionsFullCOmbinatorials.py script
  51. //! Therefore losing previous values is not a problem since a full enumeration will necessarily cover the previous values as well.
  52. virtual void MultiplySparseVariantSet(AZStd::vector<AZ::Name> optionHeaders, AZStd::vector<AZ::Name> matrixOfValues) = 0;
  53. //! Uniquifies and recompacts stableID space
  54. virtual void DefragmentVariantList() = 0;
  55. //! Set the shader variant list source data on the document.
  56. //! This function can be used to edit and update the data contained within the document.
  57. //! Functions can be added to this bus for more fine grained editing of shader variant list data.
  58. virtual void SetShaderVariantListSourceData(const AZ::RPI::ShaderVariantListSourceData& shaderVariantListSourceData) = 0;
  59. //! Get the shader variant list source data from the document.
  60. virtual const AZ::RPI::ShaderVariantListSourceData& GetShaderVariantListSourceData() const = 0;
  61. //! Get the number of shader options stored in the shader asset.
  62. //! Note that the shader asset can contain more descriptors than are stored in the shader variant list source data.
  63. virtual size_t GetShaderOptionDescriptorCount() const = 0;
  64. //! Get the shader option descriptor from the shader asset.
  65. //! Note that the shader asset can contain more descriptors than are stored in the shader variant list source data.
  66. virtual const AZ::RPI::ShaderOptionDescriptor& GetShaderOptionDescriptor(size_t index) const = 0;
  67. //! Verify before save that some guarantees are respected (like contiguous stableids)
  68. virtual DocumentVerificationResult Verify() const = 0;
  69. };
  70. using ShaderManagementConsoleDocumentRequestBus = AZ::EBus<ShaderManagementConsoleDocumentRequests>;
  71. } // namespace ShaderManagementConsole