BakedShaderVariantExampleComponent.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * 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.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0 OR MIT
  5. *
  6. */
  7. #pragma once
  8. #include <Atom/RPI.Reflect/Material/MaterialAsset.h>
  9. #include <Atom/RPI.Reflect/Model/ModelAsset.h>
  10. #include <AzCore/Component/TickBus.h>
  11. #include <AzFramework/Asset/AssetSystemTypes.h>
  12. #include <CommonSampleComponentBase.h>
  13. #include <Utils/ImGuiSidebar.h>
  14. #include <Utils/ImGuiAssetBrowser.h>
  15. #include <Utils/ImGuiMaterialDetails.h>
  16. #include <Utils/ImGuiHistogramQueue.h>
  17. namespace AtomSampleViewer
  18. {
  19. //! This test is for collecting metrics on the shader variant system by allowing users to switch from using
  20. //! root shader variant to the optimized variant. To generate shader variants, use the Shader Management Console.
  21. //! The shader options used by the material can be verified using the Material Details button in the sidebar.
  22. //! FPS and root pass metrics are shown on the sidebar as well. To view metrics for specific passes, use the GPU
  23. //! profiler.
  24. class BakedShaderVariantExampleComponent final
  25. : public CommonSampleComponentBase
  26. , public AZ::TickBus::Handler
  27. , public AZ::Data::AssetBus::Handler
  28. {
  29. public:
  30. AZ_COMPONENT(BakedShaderVariantExampleComponent, "{4986DD5D-347E-4E11-BBD5-E364061666A1}", CommonSampleComponentBase);
  31. BakedShaderVariantExampleComponent();
  32. static void Reflect(AZ::ReflectContext* context);
  33. // AZ::Component overrides...
  34. void Activate() override;
  35. void Deactivate() override;
  36. private:
  37. AZ_DISABLE_COPY_MOVE(BakedShaderVariantExampleComponent);
  38. // AZ::TickBus::Handler overrides...
  39. void OnTick(float deltaTime, AZ::ScriptTimePoint scriptTime) override;
  40. void MaterialChange();
  41. void SetRootVariantUsage(bool enabled);
  42. static constexpr uint32_t FrameTimeLogSize = 50;
  43. static constexpr uint32_t PassTimeLogSize = 50;
  44. ImGuiSidebar m_imguiSidebar;
  45. ImGuiMaterialDetails m_imguiMaterialDetails;
  46. ImGuiAssetBrowser m_materialBrowser;
  47. ImGuiHistogramQueue m_imGuiFrameTimer;
  48. ImGuiHistogramQueue m_imGuiForwardPassTimer;
  49. AZ::Render::MeshFeatureProcessorInterface* m_meshFeatureProcessor = nullptr;
  50. AZ::Data::Asset<AZ::RPI::MaterialAsset> m_materialAsset;
  51. AZ::Data::Instance<AZ::RPI::Material> m_material;
  52. AZ::Data::Asset<AZ::RPI::ModelAsset> m_modelAsset;
  53. AZ::Render::MeshFeatureProcessorInterface::MeshHandle m_meshHandle;
  54. AZ::RHI::Ptr<AZ::RPI::Pass> m_forwardPass;
  55. size_t m_selectedShaderIndex = 0;
  56. };
  57. } // namespace AtomSampleViewer