Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "include/gpu/vk/GrVkTypes.h" |
| 12 | #include "src/gpu/vk/GrVkBuffer.h" |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 13 | |
Greg Daniel | a31ab4b | 2020-03-11 13:59:38 -0400 | [diff] [blame] | 14 | class GrVkDescriptorSet; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 15 | class GrVkGpu; |
| 16 | |
| 17 | class GrVkUniformBuffer : public GrVkBuffer { |
| 18 | |
| 19 | public: |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 20 | static GrVkUniformBuffer* Create(GrVkGpu* gpu, size_t size); |
Jim Van Verth | 3e19216 | 2020-03-10 16:23:16 -0400 | [diff] [blame] | 21 | static const GrManagedResource* CreateResource(GrVkGpu* gpu, size_t size); |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 22 | static const size_t kStandardSize = 256; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 23 | |
egdaniel | 927ac9c | 2016-09-19 09:32:09 -0700 | [diff] [blame] | 24 | void* map(GrVkGpu* gpu) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 25 | return this->vkMap(gpu); |
| 26 | } |
jvanverth | 069c464 | 2016-07-06 12:56:11 -0700 | [diff] [blame] | 27 | void unmap(GrVkGpu* gpu) { |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 28 | this->vkUnmap(gpu); |
| 29 | } |
egdaniel | 7cbffda | 2016-04-08 13:27:53 -0700 | [diff] [blame] | 30 | // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in |
| 31 | // order to upload the data |
jvanverth | a584de9 | 2016-06-30 09:10:52 -0700 | [diff] [blame] | 32 | bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes, |
egdaniel | 7cbffda | 2016-04-08 13:27:53 -0700 | [diff] [blame] | 33 | bool* createdNewBuffer) { |
| 34 | return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer); |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 35 | } |
Greg Daniel | 9d02a4c | 2020-07-15 14:26:08 -0400 | [diff] [blame^] | 36 | void release(GrVkGpu* gpu) { this->vkRelease(gpu); } |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 37 | |
Greg Daniel | a31ab4b | 2020-03-11 13:59:38 -0400 | [diff] [blame] | 38 | const VkDescriptorSet* descriptorSet() const { |
| 39 | const Resource* resource = static_cast<const Resource*>(this->resource()); |
| 40 | return resource->descriptorSet(); |
| 41 | } |
| 42 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 43 | private: |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 44 | class Resource : public GrVkBuffer::Resource { |
| 45 | public: |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 46 | Resource(GrVkGpu* gpu, VkBuffer buf, const GrVkAlloc& alloc, |
| 47 | const GrVkDescriptorSet* descSet) |
| 48 | : INHERITED(gpu, buf, alloc, kUniform_Type) |
Greg Daniel | a31ab4b | 2020-03-11 13:59:38 -0400 | [diff] [blame] | 49 | , fDescriptorSet(descSet) {} |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 50 | |
Jim Van Verth | 5082df1 | 2020-03-11 16:14:51 -0400 | [diff] [blame] | 51 | void freeGPUData() const override; |
| 52 | void onRecycle() const override; |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 53 | |
Greg Daniel | a31ab4b | 2020-03-11 13:59:38 -0400 | [diff] [blame] | 54 | const VkDescriptorSet* descriptorSet() const; |
| 55 | |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 56 | typedef GrVkBuffer::Resource INHERITED; |
Greg Daniel | a31ab4b | 2020-03-11 13:59:38 -0400 | [diff] [blame] | 57 | |
| 58 | private: |
| 59 | const GrVkDescriptorSet* fDescriptorSet; |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 60 | }; |
| 61 | |
egdaniel | 31bc7df | 2016-07-29 10:46:06 -0700 | [diff] [blame] | 62 | const GrVkBuffer::Resource* createResource(GrVkGpu* gpu, |
| 63 | const GrVkBuffer::Desc& descriptor) override; |
| 64 | |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 65 | GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc, |
| 66 | const GrVkUniformBuffer::Resource* resource) |
egdaniel | 848904e | 2016-07-29 11:47:58 -0700 | [diff] [blame] | 67 | : INHERITED(desc, resource) {} |
jvanverth | 4c6e47a | 2016-07-22 10:34:52 -0700 | [diff] [blame] | 68 | |
Greg Daniel | 164a9f0 | 2016-02-22 09:56:40 -0500 | [diff] [blame] | 69 | typedef GrVkBuffer INHERITED; |
| 70 | }; |
| 71 | |
| 72 | #endif |