Refactor vulkan buffer mapping and unmapping
A lot of this is so we don't have duplicated code in both the map/unmap and
updateData functions of GrVkBuffer. Also there were slightly differences in
how we handled various things in the two cases that this now unifies.
Also I added a barrier after the vkUpdateBuffer call which I believe was
missing.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2344323002
Review-Url: https://codereview.chromium.org/2344323002
diff --git a/src/gpu/vk/GrVkBuffer.h b/src/gpu/vk/GrVkBuffer.h
index 473a837..e58d5e4 100644
--- a/src/gpu/vk/GrVkBuffer.h
+++ b/src/gpu/vk/GrVkBuffer.h
@@ -23,6 +23,7 @@
virtual ~GrVkBuffer() {
// either release or abandon should have been called by the owner of this object.
SkASSERT(!fResource);
+ delete [] (unsigned char*)fMapPtr;
}
VkBuffer buffer() const { return fResource->fBuffer; }
@@ -83,8 +84,12 @@
: fDesc(desc), fResource(resource), fOffset(0), fMapPtr(nullptr) {
}
- void* vkMap(const GrVkGpu* gpu);
- void vkUnmap(GrVkGpu* gpu);
+ void* vkMap(GrVkGpu* gpu) {
+ this->internalMap(gpu, fDesc.fSizeInBytes);
+ return fMapPtr;
+ }
+ void vkUnmap(GrVkGpu* gpu) { this->internalUnmap(gpu, this->size()); }
+
// If the caller passes in a non null createdNewBuffer, this function will set the bool to true
// if it creates a new VkBuffer to upload the data to.
bool vkUpdateData(GrVkGpu* gpu, const void* src, size_t srcSizeInBytes,
@@ -99,6 +104,9 @@
return Create(gpu, descriptor);
}
+ void internalMap(GrVkGpu* gpu, size_t size, bool* createdNewBuffer = nullptr);
+ void internalUnmap(GrVkGpu* gpu, size_t size);
+
void validate() const;
bool vkIsMapped() const;