BufferImpl.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Gr/Buffer.h>
  7. #include <AnKi/Gr/Vulkan/VulkanObject.h>
  8. #include <AnKi/Gr/Vulkan/GpuMemoryManager.h>
  9. namespace anki
  10. {
  11. /// @addtogroup vulkan
  12. /// @{
  13. /// Buffer implementation
  14. class BufferImpl final : public Buffer, public VulkanObject<Buffer, BufferImpl>
  15. {
  16. public:
  17. BufferImpl(GrManager* manager, CString name)
  18. : Buffer(manager, name)
  19. {
  20. }
  21. ~BufferImpl();
  22. ANKI_USE_RESULT Error init(const BufferInitInfo& inf);
  23. ANKI_USE_RESULT void* map(PtrSize offset, PtrSize range, BufferMapAccessBit access);
  24. void unmap()
  25. {
  26. ANKI_ASSERT(isCreated());
  27. ANKI_ASSERT(m_mapped);
  28. #if ANKI_EXTRA_CHECKS
  29. m_mapped = false;
  30. #endif
  31. // TODO Flush or invalidate caches
  32. }
  33. VkBuffer getHandle() const
  34. {
  35. ANKI_ASSERT(isCreated());
  36. return m_handle;
  37. }
  38. Bool usageValid(BufferUsageBit usage) const
  39. {
  40. return (m_usage & usage) == usage;
  41. }
  42. PtrSize getActualSize() const
  43. {
  44. ANKI_ASSERT(m_actualSize > 0);
  45. return m_actualSize;
  46. }
  47. void computeBarrierInfo(BufferUsageBit before, BufferUsageBit after, VkPipelineStageFlags& srcStages,
  48. VkAccessFlags& srcAccesses, VkPipelineStageFlags& dstStages,
  49. VkAccessFlags& dstAccesses) const;
  50. private:
  51. VkBuffer m_handle = VK_NULL_HANDLE;
  52. GpuMemoryHandle m_memHandle;
  53. VkMemoryPropertyFlags m_memoryFlags = 0;
  54. PtrSize m_actualSize = 0;
  55. #if ANKI_EXTRA_CHECKS
  56. Bool m_mapped = false;
  57. #endif
  58. Bool isCreated() const
  59. {
  60. return m_handle != VK_NULL_HANDLE;
  61. }
  62. static VkPipelineStageFlags computePplineStage(BufferUsageBit usage);
  63. static VkAccessFlags computeAccessMask(BufferUsageBit usage);
  64. };
  65. /// @}
  66. } // end namespace anki