BsVulkanHardwareBuffer.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsVulkanPrerequisites.h"
  5. #include "BsVulkanResource.h"
  6. #include "BsHardwareBuffer.h"
  7. namespace BansheeEngine
  8. {
  9. /** @addtogroup Vulkan
  10. * @{
  11. */
  12. /** Wrapper around a Vulkan buffer object that manages its usage and lifetime. */
  13. class VulkanBuffer : public VulkanResource
  14. {
  15. public:
  16. VulkanBuffer(VulkanResourceManager* owner, VkBuffer buffer, VkBufferView view, VkDeviceMemory memory);
  17. ~VulkanBuffer();
  18. /** Returns the internal handle to the Vulkan object. */
  19. VkBuffer getHandle() const { return mBuffer; }
  20. /** Returns a buffer view that covers the entire buffer. */
  21. VkBufferView getView() const { return mView; }
  22. private:
  23. VkBuffer mBuffer;
  24. VkBufferView mView;
  25. VkDeviceMemory mMemory;
  26. };
  27. /** Class containing common functionality for all Vulkan hardware buffers. */
  28. class VulkanHardwareBuffer : public HardwareBuffer
  29. {
  30. public:
  31. /** Available types of Vulkan buffers. */
  32. enum BufferType
  33. {
  34. /** Contains geometry vertices and their properties. */
  35. BT_VERTEX = 0x1,
  36. /** Contains triangle to vertex mapping. */
  37. BT_INDEX = 0x2,
  38. /** Contains GPU program parameters. */
  39. BT_UNIFORM = 0x4,
  40. /** Generic read-only GPU buffer containing formatted data. */
  41. BT_GENERIC = 0x8,
  42. /** Generic read/write GPU buffer containing formatted data. */
  43. BT_STORAGE = 0x10,
  44. /** Helper buffer that can be written to on the CPU. Used for copy operations. */
  45. BT_STAGING = 0x20,
  46. };
  47. VulkanHardwareBuffer(BufferType type, GpuBufferFormat format, GpuBufferUsage usage, UINT32 size,
  48. GpuDeviceFlags deviceMask = GDF_DEFAULT);
  49. ~VulkanHardwareBuffer();
  50. /** @copydoc HardwareBuffer::readData */
  51. void readData(UINT32 offset, UINT32 length, void* dest, UINT32 syncMask = 0x00000001) override;
  52. /** @copydoc HardwareBuffer::writeData */
  53. void writeData(UINT32 offset, UINT32 length, const void* source,
  54. BufferWriteType writeFlags = BWT_NORMAL, UINT32 syncMask = 0x00000001) override;
  55. /** @copydoc HardwareBuffer::copyData */
  56. void copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset,
  57. UINT32 length, bool discardWholeBuffer = false, UINT32 syncMask = 0x00000001) override;
  58. /**
  59. * Gets the resource wrapping the buffer object, on the specified device. If hardware buffer device mask doesn't
  60. * include the provided device, null is returned.
  61. */
  62. VulkanBuffer* getResource(UINT32 deviceIdx) const { return mBuffers[deviceIdx]; }
  63. protected:
  64. /** @copydoc HardwareBuffer::map */
  65. void* map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 syncMask) override;
  66. /** @copydoc HardwareBuffer::unmap */
  67. void unmap() override;
  68. VulkanBuffer* mBuffers[BS_MAX_DEVICES];
  69. };
  70. /** @} */
  71. }