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