MultiThreadComponent.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 <RHI/BasicRHIComponent.h>
  10. #include <Atom/RHI/Buffer.h>
  11. #include <Atom/RHI/BufferPool.h>
  12. #include <Atom/RHI/PipelineState.h>
  13. #include <Atom/RHI.Reflect/InputStreamLayoutBuilder.h>
  14. #include <MultiThreadComponent_Traits_Platform.h>
  15. namespace AtomSampleViewer
  16. {
  17. //! MultiThreadComponent
  18. //! The purpose of this sample is to test support for multithreaded command list and
  19. //! evaluate performance numbers to ensure parallelization by FrameScheduler.
  20. //! There will be one model rendered multiple times over multiple command lists with thousands
  21. //! of draw calls with a total of million plus polygons.
  22. class MultiThreadComponent final
  23. : public BasicRHIComponent
  24. {
  25. public:
  26. AZ_COMPONENT(MultiThreadComponent, "{45950624-28A3-4946-B0FE-E07A640DC6CF}", AZ::Component);
  27. AZ_DISABLE_COPY(MultiThreadComponent);
  28. static void Reflect(AZ::ReflectContext* context);
  29. MultiThreadComponent();
  30. ~MultiThreadComponent() override = default;
  31. // AZ::Component
  32. void Activate() override;
  33. void Deactivate() override;
  34. protected:
  35. // We decrease the number of cubes on mobile due to performance.
  36. static const uint32_t s_cubesPerLine = ATOMSAMPLEVIEWER_TRAIT_MULTITHREAD_SAMPLE_CUBES_PER_LINE;
  37. static const uint32_t s_numberOfCubes = s_cubesPerLine* s_cubesPerLine;
  38. static const uint32_t s_geometryVertexCount = 24;
  39. static const uint32_t s_geometryIndexCount = 36;
  40. struct SingleCubeBufferData
  41. {
  42. AZStd::array<VertexPosition, s_geometryVertexCount> m_positions;
  43. AZStd::array<VertexColor, s_geometryVertexCount> m_colors;
  44. AZStd::array<uint16_t, s_geometryIndexCount> m_indices;
  45. };
  46. struct ScopeData
  47. {
  48. //UserDataParam - Empty for this samples
  49. };
  50. // RHISystemNotificationBus::Handler
  51. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  52. SingleCubeBufferData CreateSingleCubeBufferData(const AZ::Vector4 color);
  53. void CreateInputAssemblyBuffer();
  54. void CreatePipeline();
  55. void CreateScope();
  56. AZ::Matrix4x4 m_viewProjMatrix;
  57. static constexpr float m_zNear = 1.0f;
  58. static constexpr float m_zFar = 1000.0f;
  59. static const AZ::Vector3 m_up;
  60. AZ::Vector3 m_lookAt;
  61. static const uint32_t s_cubeSpacing = 3;
  62. float m_time = 0.0f;
  63. AZStd::array<AZ::Matrix4x4, s_numberOfCubes> m_cubeTransforms;
  64. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  65. AZ::RHI::Ptr<AZ::RHI::Buffer> m_inputAssemblyBuffer;
  66. AZ::RHI::InputStreamLayout m_streamLayoutDescriptor;
  67. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  68. AZStd::array<AZ::Data::Instance<AZ::RPI::ShaderResourceGroup>, s_numberOfCubes> m_shaderResourceGroups;
  69. AZ::RHI::ShaderInputConstantIndex m_shaderIndexWorldMat;
  70. AZ::RHI::ShaderInputConstantIndex m_shaderIndexViewProj;
  71. AZ::RHI::AttachmentId m_depthStencilID;
  72. AZ::RHI::GeometryView m_geometryView;
  73. };
  74. } // namespace AtomSampleViewer