BsVulkanIndexBuffer.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsVulkanIndexBuffer.h"
  4. #include "BsVulkanHardwareBuffer.h"
  5. #include "Profiling/BsRenderStats.h"
  6. namespace bs { namespace ct
  7. {
  8. VulkanIndexBuffer::VulkanIndexBuffer(const INDEX_BUFFER_DESC& desc, GpuDeviceFlags deviceMask)
  9. :IndexBuffer(desc, deviceMask), mBuffer(nullptr), mUsage(desc.usage), mDeviceMask(deviceMask)
  10. { }
  11. VulkanIndexBuffer::~VulkanIndexBuffer()
  12. {
  13. if (mBuffer != nullptr)
  14. bs_delete(mBuffer);
  15. BS_INC_RENDER_STAT_CAT(ResDestroyed, RenderStatObject_IndexBuffer);
  16. }
  17. void VulkanIndexBuffer::initialize()
  18. {
  19. mBuffer = bs_new<VulkanHardwareBuffer>(VulkanHardwareBuffer::BT_INDEX, BF_UNKNOWN, mUsage, mSize, mDeviceMask);
  20. BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_IndexBuffer);
  21. IndexBuffer::initialize();
  22. }
  23. void* VulkanIndexBuffer::map(UINT32 offset, UINT32 length, GpuLockOptions options, UINT32 deviceIdx, UINT32 queueIdx)
  24. {
  25. #if BS_PROFILING_ENABLED
  26. if (options == GBL_READ_ONLY || options == GBL_READ_WRITE)
  27. {
  28. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  29. }
  30. if (options == GBL_READ_WRITE || options == GBL_WRITE_ONLY || options == GBL_WRITE_ONLY_DISCARD || options == GBL_WRITE_ONLY_NO_OVERWRITE)
  31. {
  32. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  33. }
  34. #endif
  35. return mBuffer->lock(offset, length, options, deviceIdx, queueIdx);
  36. }
  37. void VulkanIndexBuffer::unmap()
  38. {
  39. mBuffer->unlock();
  40. }
  41. void VulkanIndexBuffer::readData(UINT32 offset, UINT32 length, void* dest, UINT32 deviceIdx, UINT32 queueIdx)
  42. {
  43. mBuffer->readData(offset, length, dest, deviceIdx, queueIdx);
  44. BS_INC_RENDER_STAT_CAT(ResRead, RenderStatObject_IndexBuffer);
  45. }
  46. void VulkanIndexBuffer::writeData(UINT32 offset, UINT32 length, const void* source, BufferWriteType writeFlags, UINT32 queueIdx)
  47. {
  48. mBuffer->writeData(offset, length, source, writeFlags, queueIdx);
  49. BS_INC_RENDER_STAT_CAT(ResWrite, RenderStatObject_IndexBuffer);
  50. }
  51. void VulkanIndexBuffer::copyData(HardwareBuffer& srcBuffer, UINT32 srcOffset, UINT32 dstOffset, UINT32 length,
  52. bool discardWholeBuffer, const SPtr<CommandBuffer>& commandBuffer)
  53. {
  54. mBuffer->copyData(srcBuffer, srcOffset, dstOffset, length, discardWholeBuffer, commandBuffer);
  55. }
  56. VulkanBuffer* VulkanIndexBuffer::getResource(UINT32 deviceIdx) const
  57. {
  58. return mBuffer->getResource(deviceIdx);
  59. }
  60. }}