BsVulkanHardwareBuffer.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsVulkanHardwareBuffer.h"
  4. #include "BsVulkanRenderAPI.h"
  5. #include "BsVulkanDevice.h"
  6. #include "BsException.h"
  7. namespace BansheeEngine
  8. {
  9. VulkanHardwareBuffer::VulkanHardwareBuffer(GpuBufferUsage usage, const VkMemoryRequirements& reqs, bool useSystemMem,
  10. GpuDeviceFlags deviceMask)
  11. : HardwareBuffer(usage, useSystemMem), mAllocations{}
  12. {
  13. VulkanRenderAPI& rapi = static_cast<VulkanRenderAPI&>(RenderAPICore::instance());
  14. UINT32 deviceIdx = 0;
  15. if(deviceMask == GDF_DEFAULT)
  16. {
  17. const Vector<SPtr<VulkanDevice>>& devices = rapi._getPrimaryDevices();
  18. for (auto& device : devices)
  19. mAllocations[deviceIdx++].device = device;
  20. }
  21. else
  22. {
  23. for(UINT32 i = 0; i < BS_MAX_DEVICES; i++)
  24. {
  25. if ((1 << i) & deviceMask)
  26. mAllocations[deviceIdx++].device = rapi._getDevice(i);
  27. }
  28. }
  29. VkMemoryPropertyFlags flags = useSystemMem ?
  30. (VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) : // Note: Try using cached uncoherent memory
  31. VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
  32. for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
  33. {
  34. if (mAllocations[i].device == nullptr)
  35. break;
  36. mAllocations[i].memory = mAllocations[i].device->allocateMemory(reqs, flags);
  37. }
  38. mSizeInBytes = reqs.size;
  39. }
  40. VulkanHardwareBuffer::~VulkanHardwareBuffer()
  41. {
  42. for(auto& alloc : mAllocations)
  43. alloc.device->freeMemory(alloc.memory);
  44. }
  45. void* VulkanHardwareBuffer::map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 syncMask)
  46. {
  47. if ((offset + length) > mSizeInBytes)
  48. BS_EXCEPT(RenderingAPIException, "Provided offset(" + toString(offset) + ") + length(" + toString(length) + ") "
  49. "is larger than the buffer " + toString(mSizeInBytes) + ".");
  50. switch (options)
  51. {
  52. case GBL_WRITE_ONLY_DISCARD:
  53. break;
  54. case GBL_WRITE_ONLY_NO_OVERWRITE:
  55. break;
  56. case GBL_WRITE_ONLY:
  57. break;
  58. case GBL_READ_WRITE:
  59. break;
  60. case GBL_READ_ONLY:
  61. break;
  62. }
  63. return nullptr;
  64. }
  65. void VulkanHardwareBuffer::unmap()
  66. {
  67. }
  68. void VulkanHardwareBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset,
  69. UINT32 dstOffset, UINT32 length, bool discardWholeBuffer, UINT32 syncMask)
  70. {
  71. }
  72. void VulkanHardwareBuffer::readData(UINT32 offset, UINT32 length, void* pDest, UINT32 syncMask)
  73. {
  74. }
  75. void VulkanHardwareBuffer::writeData(UINT32 offset, UINT32 length, const void* pSource, BufferWriteType writeFlags, UINT32 syncMask)
  76. {
  77. }
  78. }