BakedShaderVariantExampleComponent.h 2.7 KB

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