From 069c464a6bcac468ef543100828c83821286877f Mon Sep 17 00:00:00 2001 From: jvanverth Date: Wed, 6 Jul 2016 12:56:11 -0700 Subject: [PATCH] Vulkan fixes for TesselatingPathRenderer test - Be sure to release all secondard command buffers on shutdown - Allow mapping of static buffers GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2123323002 Review-Url: https://codereview.chromium.org/2123323002 --- src/gpu/vk/GrVkBuffer.cpp | 28 ++++++++++++++++------------ src/gpu/vk/GrVkBuffer.h | 2 +- src/gpu/vk/GrVkResourceProvider.cpp | 1 + src/gpu/vk/GrVkUniformBuffer.h | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/gpu/vk/GrVkBuffer.cpp b/src/gpu/vk/GrVkBuffer.cpp index d28a8ccbf1..ff809eb50f 100644 --- a/src/gpu/vk/GrVkBuffer.cpp +++ b/src/gpu/vk/GrVkBuffer.cpp @@ -124,33 +124,37 @@ void GrVkBuffer::vkAbandon() { void* GrVkBuffer::vkMap(const GrVkGpu* gpu) { VALIDATE(); SkASSERT(!this->vkIsMapped()); - if (!fDesc.fDynamic) { - return nullptr; - } - if (!fResource->unique()) { // in use by the command buffer, so we need to create a new one fResource->unref(gpu); fResource = Create(gpu, fDesc); } - const GrVkAlloc& alloc = this->alloc(); - VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, alloc.fOffset, - VK_WHOLE_SIZE, 0, &fMapPtr)); - if (err) { - fMapPtr = nullptr; + if (fDesc.fDynamic) { + const GrVkAlloc& alloc = this->alloc(); + VkResult err = VK_CALL(gpu, MapMemory(gpu->device(), alloc.fMemory, alloc.fOffset, + VK_WHOLE_SIZE, 0, &fMapPtr)); + if (err) { + fMapPtr = nullptr; + } + } else { + fMapPtr = new unsigned char[this->size()]; } VALIDATE(); return fMapPtr; } -void GrVkBuffer::vkUnmap(const GrVkGpu* gpu) { +void GrVkBuffer::vkUnmap(GrVkGpu* gpu) { VALIDATE(); SkASSERT(this->vkIsMapped()); - SkASSERT(fDesc.fDynamic); - VK_CALL(gpu, UnmapMemory(gpu->device(), this->alloc().fMemory)); + if (fDesc.fDynamic) { + VK_CALL(gpu, UnmapMemory(gpu->device(), this->alloc().fMemory)); + } else { + gpu->updateBuffer(this, fMapPtr, this->size()); + delete fMapPtr; + } fMapPtr = nullptr; } diff --git a/src/gpu/vk/GrVkBuffer.h b/src/gpu/vk/GrVkBuffer.h index bb053ccce0..3ea9b86929 100644 --- a/src/gpu/vk/GrVkBuffer.h +++ b/src/gpu/vk/GrVkBuffer.h @@ -81,7 +81,7 @@ protected: } void* vkMap(const GrVkGpu* gpu); - void vkUnmap(const GrVkGpu* gpu); + void vkUnmap(GrVkGpu* gpu); // 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, diff --git a/src/gpu/vk/GrVkResourceProvider.cpp b/src/gpu/vk/GrVkResourceProvider.cpp index 7980a2d5f4..c7a66caf4e 100644 --- a/src/gpu/vk/GrVkResourceProvider.cpp +++ b/src/gpu/vk/GrVkResourceProvider.cpp @@ -270,6 +270,7 @@ void GrVkResourceProvider::destroyResources() { for (int i = 0; i < fActiveCommandBuffers.count(); ++i) { SkASSERT(fActiveCommandBuffers[i]->finished(fGpu)); SkASSERT(fActiveCommandBuffers[i]->unique()); + fActiveCommandBuffers[i]->reset(fGpu); fActiveCommandBuffers[i]->unref(fGpu); } fActiveCommandBuffers.reset(); diff --git a/src/gpu/vk/GrVkUniformBuffer.h b/src/gpu/vk/GrVkUniformBuffer.h index bfaf240a65..ed6c8a0aab 100644 --- a/src/gpu/vk/GrVkUniformBuffer.h +++ b/src/gpu/vk/GrVkUniformBuffer.h @@ -20,7 +20,7 @@ public: void* map(const GrVkGpu* gpu) { return this->vkMap(gpu); } - void unmap(const GrVkGpu* gpu) { + void unmap(GrVkGpu* gpu) { this->vkUnmap(gpu); } // The output variable createdNewBuffer must be set to true if a new VkBuffer is created in