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