PostProcessingShaderOptionBase.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <AzCore/Memory/SystemAllocator.h>
  10. #include <AzCore/std/containers/unordered_map.h>
  11. #include <Atom/RPI.Reflect/Shader/ShaderVariantKey.h>
  12. #include <Atom/RPI.Public/Pass/FullscreenTrianglePass.h>
  13. #include <Atom/RPI.Public/Shader/Shader.h>
  14. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  15. namespace AZ
  16. {
  17. namespace Render
  18. {
  19. //! This class provides common code to use shader option.
  20. class PostProcessingShaderOptionBase
  21. {
  22. public:
  23. PostProcessingShaderOptionBase() = default;
  24. ~PostProcessingShaderOptionBase() = default;
  25. protected:
  26. //! Creates the PSO for ShaderOption and save it as a cache.
  27. void PreloadShaderVariant(
  28. const Data::Instance<AZ::RPI::Shader>& shader,
  29. const RPI::ShaderOptionGroup& shaderOption,
  30. const RHI::RenderAttachmentConfiguration& renderAttachmentConfiguration,
  31. const RHI::MultisampleState& multisampleState);
  32. //! Update shaderVariant. Used when the shader is switched.
  33. void UpdateShaderVariant(const AZ::RPI::ShaderOptionGroup& shaderOption);
  34. //! Set a key in the SRG for dynamic branching for shaders not created in advance.
  35. void CompileShaderVariant(Data::Instance<AZ::RPI::ShaderResourceGroup>& shaderResourceGroup);
  36. //! Get precomputed pipeline.
  37. const AZ::RHI::PipelineState* GetPipelineStateFromShaderVariant() const;
  38. private:
  39. struct ShaderVariantInformation
  40. {
  41. bool m_isFullyBaked = false;
  42. const AZ::RHI::PipelineState* m_pipelineState = nullptr;
  43. };
  44. AZStd::unordered_map<AZ::u64, ShaderVariantInformation> m_shaderVariantTable;
  45. AZ::u64 m_currentShaderVariantKeyValue = 0;
  46. AZ::RPI::ShaderVariantKey m_currentShaderVariantKeyFallbackValue;
  47. const ShaderVariantInformation* GetShaderVariant(AZ::u64 key) const;
  48. };
  49. } // namespace Render
  50. } // namespace AZ