AzslcPlatformEmitter.h 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 <string>
  10. #include "AzslcBackend.h"
  11. namespace AZ::ShaderCompiler
  12. {
  13. struct CodeEmitter;
  14. // PlatformEmitter is not a Backend by design. It's a supplement to CodeEmitter, not a replacement.
  15. struct PlatformEmitter
  16. {
  17. using SrgParamDesc = RootSigDesc::SrgParamDesc;
  18. //! Returns the default platform emitter. It's always guaranteed to exist.
  19. static const PlatformEmitter* GetDefaultEmitter() noexcept(true);
  20. //! Returns a platform emitter registered with the specified key.
  21. //! If no such key is registered, returns nullptr instead.
  22. //! It never returns the default platform emitter.
  23. //! @param key The key used to search the platform emitter
  24. static const PlatformEmitter* GetEmitter(const string& key) noexcept(true);
  25. PlatformEmitter(PlatformEmitter const&) = delete;
  26. void operator=(PlatformEmitter const&) = delete;
  27. void operator=(PlatformEmitter const&& other)
  28. {
  29. return *this = std::move(other);
  30. }
  31. protected:
  32. PlatformEmitter() {};
  33. virtual ~PlatformEmitter() {}
  34. //! Registers a new platform emitter with the specified name.
  35. //! In order to provide robust assertion it throws an exception if more than one emitters try to use the same key.
  36. //! The only intended use of this method is by the platform emitter itself. No other entity should register emitters.
  37. //! @param key The key used to search. The platform emitter will be registered under this key.
  38. //! @param platformEmitter An emitter to register, which must be of a class derived from this PlatformEmitter
  39. static void SetEmitter(const string& key, const PlatformEmitter* const platformEmitter) noexcept(false);
  40. public:
  41. //! Gets the string emission for the root signature for this platform
  42. //! @param codeEmitter Reference to the calling code emitter
  43. //! @param rootSig Root signature description which should be emitted as shader code
  44. //! @param options Emission options
  45. [[nodiscard]]
  46. virtual string GetRootSig(const CodeEmitter& codeEmitter, const RootSigDesc& rootSig, const Options& options, BindingPair::Set signatureQuery) const;
  47. //! Gets the string emission for the data view containing the root constants
  48. //! @param codeEmitter Reference to the calling code emitter
  49. //! @param rootSig Root signature description which should be emitted as shader code
  50. //! @param options Emission options
  51. [[nodiscard]]
  52. virtual string GetRootConstantsView(const CodeEmitter& codeEmitter, const RootSigDesc& rootSig, const Options& options, BindingPair::Set signatureQuery) const;
  53. //! Gets the string emission for the surroundings of an extern data view variable
  54. //! @param codeEmitter Reference to the calling code emitter
  55. //! @param symbol The symbol path of the original variable we are emitting as an extern data view
  56. //! @param bindInfoRegisterIndex Register index of the resource
  57. //! @param stringifiedLogicalSpace Optional register space
  58. //! \return first: header to emit before the dataview declaration. second: footer to emit after the dataview declaration
  59. [[nodiscard]]
  60. virtual std::pair<string, string> GetDataViewHeaderFooter(const CodeEmitter& codeEmitter, const IdentifierUID& symbol, uint32_t bindInfoRegisterIndex, string_view registerTypeLetter, optional<string> stringifiedLogicalSpace) const;
  61. //! Aligns the size for the data containing the root constants.
  62. //! @param size The size of stride
  63. virtual uint32_t AlignRootConstants(uint32_t size) const;
  64. virtual bool RequiresUniqueSpaceForUnboundedArrays() const {return false;}
  65. [[nodiscard]]
  66. virtual string GetSpecializationConstant(const CodeEmitter& codeEmitter, const IdentifierUID& symbol, const Options& options) const;
  67. };
  68. }