3
0

Utils.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include <Atom/Utils/Utils.h>
  9. namespace AZ
  10. {
  11. namespace Render
  12. {
  13. AZ::Outcome<void> WriteToBuffer(RHI::Ptr<RHI::Buffer> buffer, const void* data, size_t dataSize)
  14. {
  15. // Map the buffer, copy data to the mapped pointer, and unmap it.
  16. RHI::BufferMapRequest mapRequest(*buffer, 0, dataSize);
  17. RHI::BufferMapResponse response;
  18. RHI::BufferPool* bufferPool = static_cast<RHI::BufferPool*>(buffer->GetPool());
  19. RHI::ResultCode resultCode = bufferPool->MapBuffer(mapRequest, response);
  20. if (resultCode != RHI::ResultCode::Success)
  21. {
  22. return AZ::Failure();
  23. }
  24. if (response.m_data)
  25. {
  26. memcpy(response.m_data, data, dataSize);
  27. bufferPool->UnmapBuffer(*buffer);
  28. }
  29. return AZ::Success();
  30. }
  31. } // namespace Render
  32. } // namespace AZ