Buffer.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/UnitTest/TestTypes.h>
  10. #include <Atom/RHI/DeviceBufferPool.h>
  11. #include <Atom/RHI/DeviceBufferView.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. namespace UnitTest
  14. {
  15. class BufferView
  16. : public AZ::RHI::DeviceBufferView
  17. {
  18. public:
  19. AZ_CLASS_ALLOCATOR(BufferView, AZ::SystemAllocator);
  20. private:
  21. AZ::RHI::ResultCode InitInternal(AZ::RHI::Device& device, const AZ::RHI::DeviceResource&) override;
  22. AZ::RHI::ResultCode InvalidateInternal() override;
  23. void ShutdownInternal() override;
  24. };
  25. class BufferPool;
  26. class Buffer
  27. : public AZ::RHI::DeviceBuffer
  28. {
  29. friend class BufferPool;
  30. public:
  31. AZ_CLASS_ALLOCATOR(Buffer, AZ::SystemAllocator);
  32. bool IsMapped() const;
  33. void* Map();
  34. void Unmap();
  35. const AZStd::vector<uint8_t>& GetData() const;
  36. private:
  37. bool m_isMapped = false;
  38. AZStd::vector<uint8_t> m_data;
  39. };
  40. class BufferPool
  41. : public AZ::RHI::DeviceBufferPool
  42. {
  43. public:
  44. AZ_CLASS_ALLOCATOR(BufferPool, AZ::SystemAllocator);
  45. private:
  46. AZ::RHI::ResultCode InitInternal(AZ::RHI::Device& device, const AZ::RHI::BufferPoolDescriptor& descriptor) override;
  47. void ShutdownInternal() override;
  48. AZ::RHI::ResultCode InitBufferInternal(AZ::RHI::DeviceBuffer& bufferBase, const AZ::RHI::BufferDescriptor& descriptor) override;
  49. void ShutdownResourceInternal(AZ::RHI::DeviceResource&) override;
  50. AZ::RHI::ResultCode OrphanBufferInternal(AZ::RHI::DeviceBuffer& buffer) override;
  51. AZ::RHI::ResultCode MapBufferInternal(const AZ::RHI::DeviceBufferMapRequest& request, AZ::RHI::DeviceBufferMapResponse& response) override;
  52. void UnmapBufferInternal(AZ::RHI::DeviceBuffer& bufferBase) override;
  53. AZ::RHI::ResultCode StreamBufferInternal(const AZ::RHI::DeviceBufferStreamRequest& request) override;
  54. void ComputeFragmentation() const override {}
  55. };
  56. }