CopyQueueComponent.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/RPI.Public/Image/StreamingImage.h>
  11. #include <Atom/RPI.Public/Shader/ShaderResourceGroup.h>
  12. #include <Atom/RHI/BufferPool.h>
  13. #include <Atom/RHI/Device.h>
  14. #include <Atom/RHI/DrawItem.h>
  15. #include <Atom/RHI/Factory.h>
  16. #include <Atom/RHI/FrameScheduler.h>
  17. #include <Atom/RHI/PipelineState.h>
  18. #include <RHI/BasicRHIComponent.h>
  19. namespace AtomSampleViewer
  20. {
  21. //! Demonstrates queued uploads of data to the GPU while something is rendering.
  22. //! In effect this tests the AsyncUploadQueue class in the RHI back-end implementations.
  23. //! The expected output is a textured quad where the texture is frequently replaced and the
  24. //! position of the quad frequently changes.
  25. class CopyQueueComponent final
  26. : public BasicRHIComponent
  27. {
  28. public:
  29. AZ_COMPONENT(CopyQueueComponent, "{581AB2F2-C969-4572-9B40-4EE13D862C72}", AZ::Component);
  30. AZ_DISABLE_COPY(CopyQueueComponent);
  31. static void Reflect(AZ::ReflectContext* context);
  32. CopyQueueComponent();
  33. ~CopyQueueComponent() override = default;
  34. protected:
  35. // AZ::Component
  36. void Activate() override;
  37. void Deactivate() override;
  38. // RHISystemNotificationBus::Handler
  39. void OnFramePrepare(AZ::RHI::FrameGraphBuilder& frameGraphBuilder) override;
  40. void UploadTextureAsAsset(const char* filePath, int index);
  41. /// Updates the content of the vertex position buffer to animated based on a time value
  42. void UpdateVertexPositions(float timeValue);
  43. /// Uploads the vertex position buffer to the GPU
  44. void UploadVertexBuffer();
  45. AZ::RHI::ShaderInputImageIndex m_textureInputIndex;
  46. AZ::RHI::Ptr<AZ::RHI::BufferPool> m_bufferPool;
  47. AZ::RHI::Ptr<AZ::RHI::Buffer> m_indexBuffer;
  48. AZ::RHI::Ptr<AZ::RHI::Buffer> m_positionBuffer;
  49. AZ::RHI::Ptr<AZ::RHI::Buffer> m_uvBuffer;
  50. AZ::RHI::ConstPtr<AZ::RHI::PipelineState> m_pipelineState;
  51. AZ::Data::Instance<AZ::RPI::ShaderResourceGroup> m_shaderResourceGroup;
  52. AZ::RHI::ShaderInputConstantIndex m_objectMatrixConstantIndex;
  53. /// Tracks state used for 'animating' the textured quad to adjust its size and the texture in use.
  54. struct ProcessingState
  55. {
  56. static constexpr float ChangeDelay = 0.5f;
  57. static constexpr int TextureCount = 3;
  58. static constexpr float TickAmount = 0.005f;
  59. float m_time = 0.0f;
  60. float m_timeUntilChange = 0.0f;
  61. int m_changeCount = 0;
  62. };
  63. ProcessingState m_processingState;
  64. struct BufferData
  65. {
  66. AZStd::array<VertexPosition, 4> m_positions;
  67. AZStd::array<VertexUV, 4> m_uvs;
  68. AZStd::array<uint16_t, 6> m_indices;
  69. };
  70. BufferData m_bufferData;
  71. AZ::RHI::GeometryView m_geometryView;
  72. static const int numberOfPaths = 3;
  73. const char* m_filePaths[numberOfPaths] = {
  74. "textures/streaming/streaming1.dds.streamingimage",
  75. "textures/streaming/streaming2.dds.streamingimage",
  76. "textures/streaming/streaming3.dds.streamingimage",
  77. };
  78. AZStd::array<AZ::Data::Instance<AZ::RPI::StreamingImage>, 3> m_images;
  79. };
  80. } // namespace AtomSampleViewer
  81. #pragma once