GrVkUniformBuffer.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 GrVkUniformBuffer_DEFINED
  8. #define GrVkUniformBuffer_DEFINED
  9. #include "include/gpu/vk/GrVkTypes.h"
  10. #include "src/gpu/vk/GrVkBuffer.h"
  11. class GrVkGpu;
  12. class GrVkUniformBuffer : public GrVkBuffer {
  13. public:
  14. static GrVkUniformBuffer* Create(GrVkGpu* gpu, size_t size);
  15. static const GrVkResource* CreateResource(GrVkGpu* gpu, size_t size);
  16. static const size_t kStandardSize = 256;
  17. void* map(GrVkGpu* gpu) {
  18. return this->vkMap(gpu);
  19. }
  20. void unmap(GrVkGpu* gpu) {
  21. this->vkUnmap(gpu);
  22. }
  23. // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in
  24. // order to upload the data
  25. bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
  26. bool* createdNewBuffer) {
  27. return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer);
  28. }
  29. void release(const GrVkGpu* gpu) { this->vkRelease(gpu); }
  30. void abandon() { this->vkAbandon(); }
  31. private:
  32. class Resource : public GrVkBuffer::Resource {
  33. public:
  34. Resource(VkBuffer buf, const GrVkAlloc& alloc)
  35. : INHERITED(buf, alloc, kUniform_Type) {}
  36. void onRecycle(GrVkGpu* gpu) const override;
  37. typedef GrVkBuffer::Resource INHERITED;
  38. };
  39. const GrVkBuffer::Resource* createResource(GrVkGpu* gpu,
  40. const GrVkBuffer::Desc& descriptor) override;
  41. GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
  42. const GrVkUniformBuffer::Resource* resource)
  43. : INHERITED(desc, resource) {}
  44. typedef GrVkBuffer INHERITED;
  45. };
  46. #endif