Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(313)

Unified Diff: src/gpu/vk/GrVkMemory.cpp

Issue 2356343003: Some Vulkan memory fixes and cleanup (Closed)
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/vk/GrVkMemory.h ('k') | tests/VkHeapTests.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/vk/GrVkMemory.cpp
diff --git a/src/gpu/vk/GrVkMemory.cpp b/src/gpu/vk/GrVkMemory.cpp
index 98b2f89e243a0964228fd54f3fba9e0f51b6b0cc..24df7d94304d0056fce1cc19faba153f32c747a3 100644
--- a/src/gpu/vk/GrVkMemory.cpp
+++ b/src/gpu/vk/GrVkMemory.cpp
@@ -10,6 +10,12 @@
#include "GrVkGpu.h"
#include "GrVkUtil.h"
+#ifdef SK_DEBUG
+// for simple tracking of how much we're using in each heap
+// last counter is for non-subheap allocations
+VkDeviceSize gHeapUsage[VK_MAX_MEMORY_HEAPS+1] = { 0 };
+#endif
+
static bool get_valid_memory_type_index(const VkPhysicalDeviceMemoryProperties& physDevMemProps,
uint32_t typeBits,
VkMemoryPropertyFlags requestedMemFlags,
@@ -82,12 +88,18 @@ bool GrVkMemory::AllocAndBindBufferMemory(const GrVkGpu* gpu,
&typeIndex));
alloc->fFlags = 0x0;
}
+ uint32_t heapIndex = phDevMemProps.memoryTypes[typeIndex].heapIndex;
GrVkHeap* heap = gpu->getHeap(buffer_type_to_heap(type));
- if (!heap->alloc(memReqs.size, memReqs.alignment, typeIndex, alloc)) {
- SkDebugf("Failed to alloc buffer\n");
- return false;
+ if (!heap->alloc(memReqs.size, memReqs.alignment, typeIndex, heapIndex, alloc)) {
+ // if static, try to allocate from non-host-visible non-device-local memory instead
+ if (dynamic ||
+ !get_valid_memory_type_index(phDevMemProps, memReqs.memoryTypeBits, 0, &typeIndex) ||
+ !heap->alloc(memReqs.size, memReqs.alignment, typeIndex, heapIndex, alloc)) {
egdaniel 2016/09/22 13:25:46 do we need to update heap index between these?
jvanverth1 2016/09/22 14:14:51 Done.
+ SkDebugf("Failed to alloc buffer\n");
+ return false;
+ }
}
// Bind buffer
@@ -163,9 +175,15 @@ bool GrVkMemory::AllocAndBindImageMemory(const GrVkGpu* gpu,
alloc->fFlags = 0x0;
}
- if (!heap->alloc(memReqs.size, memReqs.alignment, typeIndex, alloc)) {
- SkDebugf("Failed to alloc image\n");
- return false;
+ uint32_t heapIndex = phDevMemProps.memoryTypes[typeIndex].heapIndex;
+ if (!heap->alloc(memReqs.size, memReqs.alignment, typeIndex, heapIndex, alloc)) {
+ // if optimal, try to allocate from non-host-visible non-device-local memory instead
+ if (linearTiling ||
+ !get_valid_memory_type_index(phDevMemProps, memReqs.memoryTypeBits, 0, &typeIndex) ||
+ !heap->alloc(memReqs.size, memReqs.alignment, typeIndex, heapIndex, alloc)) {
+ SkDebugf("Failed to alloc image\n");
+ return false;
+ }
}
// Bind image
@@ -431,11 +449,12 @@ void GrVkFreeListAlloc::free(VkDeviceSize allocOffset, VkDeviceSize allocSize) {
#endif
}
-GrVkSubHeap::GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex,
+GrVkSubHeap::GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex, uint32_t heapIndex,
VkDeviceSize size, VkDeviceSize alignment)
: INHERITED(size, alignment)
, fGpu(gpu)
- , fMemoryTypeIndex(memoryTypeIndex) {
+ , fMemoryTypeIndex(memoryTypeIndex)
+ , fHeapIndex(heapIndex) {
VkMemoryAllocateInfo allocInfo = {
VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, // sType
@@ -450,12 +469,20 @@ GrVkSubHeap::GrVkSubHeap(const GrVkGpu* gpu, uint32_t memoryTypeIndex,
&fAlloc));
if (VK_SUCCESS != err) {
this->reset();
+ }
+#ifdef SK_DEBUG
+ else {
+ gHeapUsage[heapIndex] += size;
}
+#endif
}
GrVkSubHeap::~GrVkSubHeap() {
const GrVkInterface* iface = fGpu->vkInterface();
GR_VK_CALL(iface, FreeMemory(fGpu->device(), fAlloc, nullptr));
+#ifdef SK_DEBUG
+ gHeapUsage[fHeapIndex] -= fSize;
+#endif
}
bool GrVkSubHeap::alloc(VkDeviceSize size, GrVkAlloc* alloc) {
@@ -470,7 +497,7 @@ void GrVkSubHeap::free(const GrVkAlloc& alloc) {
}
bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment,
- uint32_t memoryTypeIndex, GrVkAlloc* alloc) {
+ uint32_t memoryTypeIndex, uint32_t heapIndex, GrVkAlloc* alloc) {
VkDeviceSize alignedSize = align_size(size, alignment);
// if requested is larger than our subheap allocation, just alloc directly
@@ -491,6 +518,9 @@ bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment,
}
alloc->fOffset = 0;
alloc->fSize = 0; // hint that this is not a subheap allocation
+#ifdef SK_DEBUG
+ gHeapUsage[VK_MAX_MEMORY_HEAPS] += alignedSize;
+#endif
return true;
}
@@ -520,11 +550,11 @@ bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment,
// need to allocate a new subheap
SkAutoTDelete<GrVkSubHeap>& subHeap = fSubHeaps.push_back();
- subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, fSubHeapSize, alignment));
+ subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, heapIndex, fSubHeapSize, alignment));
// try to recover from failed allocation by only allocating what we need
if (subHeap->size() == 0) {
VkDeviceSize alignedSize = align_size(size, alignment);
- subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, alignedSize, alignment));
+ subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, heapIndex, alignedSize, alignment));
if (subHeap->size() == 0) {
return false;
}
@@ -539,7 +569,7 @@ bool GrVkHeap::subAlloc(VkDeviceSize size, VkDeviceSize alignment,
}
bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment,
- uint32_t memoryTypeIndex, GrVkAlloc* alloc) {
+ uint32_t memoryTypeIndex, uint32_t heapIndex, GrVkAlloc* alloc) {
VkDeviceSize alignedSize = align_size(size, alignment);
// first try to find an unallocated subheap that fits our allocation request
@@ -568,7 +598,7 @@ bool GrVkHeap::singleAlloc(VkDeviceSize size, VkDeviceSize alignment,
// need to allocate a new subheap
SkAutoTDelete<GrVkSubHeap>& subHeap = fSubHeaps.push_back();
- subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, alignedSize, alignment));
+ subHeap.reset(new GrVkSubHeap(fGpu, memoryTypeIndex, heapIndex, alignedSize, alignment));
fAllocSize += alignedSize;
if (subHeap->alloc(size, alloc)) {
fUsedSize += alloc->fSize;
« no previous file with comments | « src/gpu/vk/GrVkMemory.h ('k') | tests/VkHeapTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698