blob: db9350ae53bc3716f70a23f685decb3e5671a792 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/vk/GrVkTypes.h"
12#include "src/gpu/vk/GrVkBuffer.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050013
14class GrVkGpu;
15
16class GrVkUniformBuffer : public GrVkBuffer {
17
18public:
jvanverth4c6e47a2016-07-22 10:34:52 -070019 static GrVkUniformBuffer* Create(GrVkGpu* gpu, size_t size);
Jim Van Verth3e192162020-03-10 16:23:16 -040020 static const GrManagedResource* CreateResource(GrVkGpu* gpu, size_t size);
jvanverth4c6e47a2016-07-22 10:34:52 -070021 static const size_t kStandardSize = 256;
Greg Daniel164a9f02016-02-22 09:56:40 -050022
egdaniel927ac9c2016-09-19 09:32:09 -070023 void* map(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050024 return this->vkMap(gpu);
25 }
jvanverth069c4642016-07-06 12:56:11 -070026 void unmap(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050027 this->vkUnmap(gpu);
28 }
egdaniel7cbffda2016-04-08 13:27:53 -070029 // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in
30 // order to upload the data
jvanvertha584de92016-06-30 09:10:52 -070031 bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
egdaniel7cbffda2016-04-08 13:27:53 -070032 bool* createdNewBuffer) {
33 return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer);
Greg Daniel164a9f02016-02-22 09:56:40 -050034 }
jvanverth4c6e47a2016-07-22 10:34:52 -070035 void release(const GrVkGpu* gpu) { this->vkRelease(gpu); }
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
Jim Van Verth3e192162020-03-10 16:23:16 -040043 void onRecycle(GrGpu* gpu) const override;
jvanverth4c6e47a2016-07-22 10:34:52 -070044
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