aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/vk/GrVkTransferBuffer.cpp
blob: 9adfeaf75b5b7bd49622f33f04348487b9e10535 (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
59
60
61
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/

#include "GrVkTransferBuffer.h"
#include "GrVkGpu.h"
#include "SkTraceMemoryDump.h"


GrVkTransferBuffer* GrVkTransferBuffer::Create(GrVkGpu* gpu, size_t size, GrVkBuffer::Type type) {
    GrVkBuffer::Desc desc;
    desc.fDynamic = true;
    SkASSERT(GrVkBuffer::kCopyRead_Type == type || GrVkBuffer::kCopyWrite_Type == type);
    desc.fType = type;
    desc.fSizeInBytes = size;

    const GrVkBuffer::Resource* bufferResource = GrVkBuffer::Create(gpu, desc);
    if (!bufferResource) {
        return nullptr;
    }

    GrVkTransferBuffer* buffer = new GrVkTransferBuffer(gpu, desc, bufferResource);
    if (!buffer) {
        bufferResource->unref(gpu);
    }
    return buffer;
}

GrVkTransferBuffer::GrVkTransferBuffer(GrVkGpu* gpu, const GrVkBuffer::Desc& desc,
                                       const GrVkBuffer::Resource* bufferResource)
    : INHERITED(gpu, desc.fSizeInBytes,
                kCopyRead_Type == desc.fType ?
                    kXferCpuToGpu_GrBufferType : kXferGpuToCpu_GrBufferType,
                kStream_GrAccessPattern)
    , GrVkBuffer(desc, bufferResource) {
    this->registerWithCache(SkBudgeted::kYes);
}

void GrVkTransferBuffer::onRelease() {
    if (!this->wasDestroyed()) {
        this->vkRelease(this->getVkGpu());
    }

    INHERITED::onRelease();
}

void GrVkTransferBuffer::onAbandon() {
    this->vkAbandon();
    INHERITED::onAbandon();
}

void GrVkTransferBuffer::setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
                                          const SkString& dumpName) const {
    SkString buffer_id;
    buffer_id.appendU64((uint64_t)this->buffer());
    traceMemoryDump->setMemoryBacking(dumpName.c_str(), "vk_buffer",
                                      buffer_id.c_str());
}