blob: 2535e0c602d46e7a569ad1194a7e70acb0b2a7a8 [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
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"
Greg Daniel164a9f02016-02-22 09:56:40 -050012
13class GrVkGpu;
14
15class GrVkUniformBuffer : public GrVkBuffer {
16
17public:
jvanverth4c6e47a2016-07-22 10:34:52 -070018 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;
Greg Daniel164a9f02016-02-22 09:56:40 -050021
egdaniel927ac9c2016-09-19 09:32:09 -070022 void* map(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050023 return this->vkMap(gpu);
24 }
jvanverth069c4642016-07-06 12:56:11 -070025 void unmap(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050026 this->vkUnmap(gpu);
27 }
egdaniel7cbffda2016-04-08 13:27:53 -070028 // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in
29 // order to upload the data
jvanvertha584de92016-06-30 09:10:52 -070030 bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
egdaniel7cbffda2016-04-08 13:27:53 -070031 bool* createdNewBuffer) {
32 return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer);
Greg Daniel164a9f02016-02-22 09:56:40 -050033 }
jvanverth4c6e47a2016-07-22 10:34:52 -070034 void release(const GrVkGpu* gpu) { this->vkRelease(gpu); }
35 void abandon() { this->vkAbandon(); }
Greg Daniel164a9f02016-02-22 09:56:40 -050036
37private:
jvanverth4c6e47a2016-07-22 10:34:52 -070038 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;
Greg Daniel164a9f02016-02-22 09:56:40 -050046 };
47
egdaniel31bc7df2016-07-29 10:46:06 -070048 const GrVkBuffer::Resource* createResource(GrVkGpu* gpu,
49 const GrVkBuffer::Desc& descriptor) override;
50
jvanverth4c6e47a2016-07-22 10:34:52 -070051 GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
52 const GrVkUniformBuffer::Resource* resource)
egdaniel848904e2016-07-29 11:47:58 -070053 : INHERITED(desc, resource) {}
jvanverth4c6e47a2016-07-22 10:34:52 -070054
Greg Daniel164a9f02016-02-22 09:56:40 -050055 typedef GrVkBuffer INHERITED;
56};
57
58#endif