blob: dc0d6b6891b21f26b89a29b8bc1ce642ac9de316 [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
Greg Daniela31ab4b2020-03-11 13:59:38 -040014class GrVkDescriptorSet;
Greg Daniel164a9f02016-02-22 09:56:40 -050015class GrVkGpu;
16
17class GrVkUniformBuffer : public GrVkBuffer {
18
19public:
jvanverth4c6e47a2016-07-22 10:34:52 -070020 static GrVkUniformBuffer* Create(GrVkGpu* gpu, size_t size);
Jim Van Verth3e192162020-03-10 16:23:16 -040021 static const GrManagedResource* CreateResource(GrVkGpu* gpu, size_t size);
jvanverth4c6e47a2016-07-22 10:34:52 -070022 static const size_t kStandardSize = 256;
Greg Daniel164a9f02016-02-22 09:56:40 -050023
egdaniel927ac9c2016-09-19 09:32:09 -070024 void* map(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050025 return this->vkMap(gpu);
26 }
jvanverth069c4642016-07-06 12:56:11 -070027 void unmap(GrVkGpu* gpu) {
Greg Daniel164a9f02016-02-22 09:56:40 -050028 this->vkUnmap(gpu);
29 }
egdaniel7cbffda2016-04-08 13:27:53 -070030 // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in
31 // order to upload the data
jvanvertha584de92016-06-30 09:10:52 -070032 bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
egdaniel7cbffda2016-04-08 13:27:53 -070033 bool* createdNewBuffer) {
34 return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer);
Greg Daniel164a9f02016-02-22 09:56:40 -050035 }
Greg Daniel9d02a4c2020-07-15 14:26:08 -040036 void release(GrVkGpu* gpu) { this->vkRelease(gpu); }
Greg Daniel164a9f02016-02-22 09:56:40 -050037
Greg Daniela31ab4b2020-03-11 13:59:38 -040038 const VkDescriptorSet* descriptorSet() const {
39 const Resource* resource = static_cast<const Resource*>(this->resource());
40 return resource->descriptorSet();
41 }
42
Greg Daniel164a9f02016-02-22 09:56:40 -050043private:
jvanverth4c6e47a2016-07-22 10:34:52 -070044 class Resource : public GrVkBuffer::Resource {
45 public:
Jim Van Verth5082df12020-03-11 16:14:51 -040046 Resource(GrVkGpu* gpu, VkBuffer buf, const GrVkAlloc& alloc,
47 const GrVkDescriptorSet* descSet)
48 : INHERITED(gpu, buf, alloc, kUniform_Type)
Greg Daniela31ab4b2020-03-11 13:59:38 -040049 , fDescriptorSet(descSet) {}
jvanverth4c6e47a2016-07-22 10:34:52 -070050
Jim Van Verth5082df12020-03-11 16:14:51 -040051 void freeGPUData() const override;
52 void onRecycle() const override;
jvanverth4c6e47a2016-07-22 10:34:52 -070053
Greg Daniela31ab4b2020-03-11 13:59:38 -040054 const VkDescriptorSet* descriptorSet() const;
55
jvanverth4c6e47a2016-07-22 10:34:52 -070056 typedef GrVkBuffer::Resource INHERITED;
Greg Daniela31ab4b2020-03-11 13:59:38 -040057
58 private:
59 const GrVkDescriptorSet* fDescriptorSet;
Greg Daniel164a9f02016-02-22 09:56:40 -050060 };
61
egdaniel31bc7df2016-07-29 10:46:06 -070062 const GrVkBuffer::Resource* createResource(GrVkGpu* gpu,
63 const GrVkBuffer::Desc& descriptor) override;
64
jvanverth4c6e47a2016-07-22 10:34:52 -070065 GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
66 const GrVkUniformBuffer::Resource* resource)
egdaniel848904e2016-07-29 11:47:58 -070067 : INHERITED(desc, resource) {}
jvanverth4c6e47a2016-07-22 10:34:52 -070068
Greg Daniel164a9f02016-02-22 09:56:40 -050069 typedef GrVkBuffer INHERITED;
70};
71
72#endif