AzslShaderBuilderSystemComponent.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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/Component/Component.h>
  10. #include <Atom/RHI.Edit/ShaderPlatformInterfaceBus.h>
  11. #include <Atom/RPI.Reflect/Shader/ShaderAsset.h>
  12. #include "ShaderAssetBuilder.h"
  13. #include "ShaderVariantAssetBuilder.h"
  14. #include "PrecompiledShaderBuilder.h"
  15. #include "ShaderPlatformInterfaceRequest.h"
  16. #include "ShaderVariantListBuilder.h"
  17. namespace AZ
  18. {
  19. namespace ShaderBuilder
  20. {
  21. class AzslShaderBuilderSystemComponent
  22. : public Component
  23. , public RHI::ShaderPlatformInterfaceRegisterBus::Handler
  24. , public ShaderPlatformInterfaceRequestBus::Handler
  25. {
  26. public:
  27. AZ_COMPONENT(AzslShaderBuilderSystemComponent, "{56B5B944-8AF4-4478-A047-8DFDE38DA681}");
  28. static void Reflect(ReflectContext* context);
  29. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  30. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  31. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  32. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  33. protected:
  34. ////////////////////////////////////////////////////////////////////////
  35. // AzslShaderBuilderRequestBus interface implementation
  36. ////////////////////////////////////////////////////////////////////////
  37. ////////////////////////////////////////////////////////////////////////
  38. // AZ::Component interface implementation
  39. void Init() override;
  40. void Activate() override;
  41. void Deactivate() override;
  42. ////////////////////////////////////////////////////////////////////////
  43. // ShaderPlatformInterfaceRegisterBus interface overrides ...
  44. void RegisterShaderPlatformHandler(RHI::ShaderPlatformInterface* shaderPlatformInterface) override;
  45. void UnregisterShaderPlatformHandler(RHI::ShaderPlatformInterface* shaderPlatformInterface) override;
  46. // ShaderPlatformInterfaceRequestBus interface overrides ...
  47. AZStd::vector<RHI::ShaderPlatformInterface*> GetShaderPlatformInterface(const AssetBuilderSDK::PlatformInfo& platformInfo) override;
  48. private:
  49. ShaderAssetBuilder m_shaderAssetBuilder;
  50. // The ShaderVariantAssetBuilder can be disabled with this registry key.
  51. // By default it is enabled. A user might want to disable it when doing look development
  52. // work with shaders or doing lots of iterative changes to shaders. In these cases
  53. // GPU performance doesn't matter at all so it is important to not waste time
  54. // building ShaderVariantAssets (Other than the Root ShaderVariantAsset, of course.).
  55. static constexpr char EnableShaderVariantAssetBuilderRegistryKey[] = "/O3DE/Atom/Shaders/BuildVariants";
  56. bool m_enableShaderVariantAssetBuilder = true;
  57. ShaderVariantAssetBuilder m_shaderVariantAssetBuilder;
  58. PrecompiledShaderBuilder m_precompiledShaderBuilder;
  59. ShaderVariantListBuilder m_shaderVariantListBuilder;
  60. /// Contains the ShaderPlatformInterface for all registered RHIs
  61. AZStd::unordered_map<RHI::APIType, RHI::ShaderPlatformInterface*> m_shaderPlatformInterfaces;
  62. };
  63. } // ShaderBuilder
  64. } //AZ