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