GrVkMemory.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2015 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef GrVkMemory_DEFINED
  8. #define GrVkMemory_DEFINED
  9. #include "include/gpu/vk/GrVkTypes.h"
  10. #include "include/private/SkTArray.h"
  11. #include "src/gpu/vk/GrVkBuffer.h"
  12. class GrVkGpu;
  13. namespace GrVkMemory {
  14. /**
  15. * Allocates vulkan device memory and binds it to the gpu's device for the given object.
  16. * Returns true if allocation succeeded.
  17. */
  18. bool AllocAndBindBufferMemory(const GrVkGpu* gpu,
  19. VkBuffer buffer,
  20. GrVkBuffer::Type type,
  21. bool dynamic,
  22. GrVkAlloc* alloc);
  23. void FreeBufferMemory(const GrVkGpu* gpu, GrVkBuffer::Type type, const GrVkAlloc& alloc);
  24. bool AllocAndBindImageMemory(const GrVkGpu* gpu,
  25. VkImage image,
  26. bool linearTiling,
  27. GrVkAlloc* alloc);
  28. void FreeImageMemory(const GrVkGpu* gpu, bool linearTiling, const GrVkAlloc& alloc);
  29. // Maps the entire GrVkAlloc and returns a pointer to the start of the allocation. Underneath
  30. // the hood, we may map more than the range of the GrVkAlloc (e.g. the entire VkDeviceMemory),
  31. // but the pointer returned will always be to the start of the GrVkAlloc. The caller should also
  32. // never assume more than the GrVkAlloc block has been mapped.
  33. void* MapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc);
  34. void UnmapAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc);
  35. // For the Flush and Invalidate calls, the offset should be relative to the GrVkAlloc. Thus this
  36. // will often be 0. The client does not need to make sure the offset and size are aligned to the
  37. // nonCoherentAtomSize, the internal calls will handle that.
  38. void FlushMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset,
  39. VkDeviceSize size);
  40. void InvalidateMappedAlloc(const GrVkGpu* gpu, const GrVkAlloc& alloc, VkDeviceSize offset,
  41. VkDeviceSize size);
  42. // Helper for aligning and setting VkMappedMemoryRange for flushing/invalidating noncoherent
  43. // memory.
  44. void GetNonCoherentMappedMemoryRange(const GrVkAlloc&, VkDeviceSize offset, VkDeviceSize size,
  45. VkDeviceSize alignment, VkMappedMemoryRange*);
  46. }
  47. #endif