aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkUniformBuffer.h
blob: 2535e0c602d46e7a569ad1194a7e70acb0b2a7a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#ifndef GrVkUniformBuffer_DEFINED
#define GrVkUniformBuffer_DEFINED

#include "GrVkBuffer.h"

class GrVkGpu;

class GrVkUniformBuffer : public GrVkBuffer {

public:
    static GrVkUniformBuffer* Create(GrVkGpu* gpu, size_t size);
    static const GrVkResource* CreateResource(GrVkGpu* gpu, size_t size);
    static const size_t kStandardSize = 256;

    void* map(GrVkGpu* gpu) {
        return this->vkMap(gpu);
    }
    void unmap(GrVkGpu* gpu) {
        this->vkUnmap(gpu);
    }
    // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in
    // order to upload the data
    bool updateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
                    bool* createdNewBuffer) {
        return this->vkUpdateData(gpu, src, srcSizeInBytes, createdNewBuffer);
    }
    void release(const GrVkGpu* gpu) { this->vkRelease(gpu); }
    void abandon() { this->vkAbandon(); }

private:
    class Resource : public GrVkBuffer::Resource {
    public:
        Resource(VkBuffer buf, const GrVkAlloc& alloc)
            : INHERITED(buf, alloc, kUniform_Type) {}

        void onRecycle(GrVkGpu* gpu) const override;

        typedef GrVkBuffer::Resource INHERITED;
    };

    const GrVkBuffer::Resource* createResource(GrVkGpu* gpu,
                                               const GrVkBuffer::Desc& descriptor) override;

    GrVkUniformBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
                      const GrVkUniformBuffer::Resource* resource)
        : INHERITED(desc, resource) {}

    typedef GrVkBuffer INHERITED;
};

#endif