/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include namespace AZ { namespace Render { //! This class provides common code to use shader option. class PostProcessingShaderOptionBase { public: PostProcessingShaderOptionBase() = default; ~PostProcessingShaderOptionBase() = default; protected: //! Creates the PSO for ShaderOption and save it as a cache. void PreloadShaderVariant( const Data::Instance& shader, const RPI::ShaderOptionGroup& shaderOption, const RHI::RenderAttachmentConfiguration& renderAttachmentConfiguration, const RHI::MultisampleState& multisampleState); //! Update shaderVariant. Used when the shader is switched. void UpdateShaderVariant(const AZ::RPI::ShaderOptionGroup& shaderOption); //! Set a key in the SRG for dynamic branching for shaders not created in advance. void CompileShaderVariant(Data::Instance& shaderResourceGroup); //! Get precomputed pipeline. const AZ::RHI::PipelineState* GetPipelineStateFromShaderVariant() const; private: struct ShaderVariantInformation { bool m_isFullyBaked = false; const AZ::RHI::PipelineState* m_pipelineState = nullptr; }; AZStd::unordered_map m_shaderVariantTable; AZ::u64 m_currentShaderVariantKeyValue = 0; AZ::RPI::ShaderVariantKey m_currentShaderVariantKeyFallbackValue; const ShaderVariantInformation* GetShaderVariant(AZ::u64 key) const; }; } // namespace Render } // namespace AZ