BufferVK.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
  2. // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
  3. // SPDX-License-Identifier: MIT
  4. #pragma once
  5. #include <Jolt/Compute/VK/IncludeVK.h>
  6. #include <Jolt/Core/Reference.h>
  7. #include <Jolt/Core/NonCopyable.h>
  8. JPH_NAMESPACE_BEGIN
  9. /// Simple wrapper class to manage a Vulkan memory block
  10. class MemoryVK : public RefTarget<MemoryVK>, public NonCopyable
  11. {
  12. public:
  13. ~MemoryVK()
  14. {
  15. // We should have unmapped and freed the block before destruction
  16. JPH_ASSERT(mMappedCount == 0);
  17. JPH_ASSERT(mMemory == VK_NULL_HANDLE);
  18. }
  19. VkDeviceMemory mMemory = VK_NULL_HANDLE; ///< The Vulkan memory handle
  20. VkDeviceSize mSize = 0; ///< Size of the memory block
  21. VkDeviceSize mBufferSize = 0; ///< Size of each of the buffers that this memory block has been divided into
  22. VkMemoryPropertyFlags mProperties = 0; ///< Vulkan memory properties used to allocate this block
  23. int mMappedCount = 0; ///< How often buffers using this memory block were mapped
  24. void * mMappedPtr = nullptr; ///< The CPU address of the memory block when mapped
  25. };
  26. /// Simple wrapper class to manage a Vulkan buffer
  27. class BufferVK
  28. {
  29. public:
  30. Ref<MemoryVK> mMemory; ///< The memory block that contains the buffer (note that filling this in is optional if you do your own buffer allocation)
  31. VkBuffer mBuffer = VK_NULL_HANDLE; ///< The Vulkan buffer handle
  32. VkDeviceSize mOffset = 0; ///< Offset in the memory block where the buffer starts
  33. VkDeviceSize mSize = 0; ///< Real size of the buffer
  34. };
  35. JPH_NAMESPACE_END