mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-15 03:41:34 +00:00
Vulkan: attempt sub-allocation before direct allocation.
Falling-back to direct allocation ensures allocation failure returns OOM. If no OOM, the resource could be left then used while in an invalid state. BUG=chromium:1045811,chromium:1047220,chromium:1047048 Change-Id: I927962b1dc6a7422a7d6eac114d82f28a42794a2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/15600 Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
97c3be2699
commit
525ef86c2e
@ -112,21 +112,28 @@ namespace dawn_native { namespace vulkan {
|
|||||||
|
|
||||||
VkDeviceSize size = requirements.size;
|
VkDeviceSize size = requirements.size;
|
||||||
|
|
||||||
// If the resource is too big, allocate memory just for it.
|
// Sub-allocate non-mappable resources because at the moment the mapped pointer
|
||||||
// Also allocate mappable resources separately because at the moment the mapped pointer
|
|
||||||
// is part of the resource and not the heap, which doesn't match the Vulkan model.
|
// is part of the resource and not the heap, which doesn't match the Vulkan model.
|
||||||
// TODO(cwallez@chromium.org): allow sub-allocating mappable resources, maybe.
|
// TODO(cwallez@chromium.org): allow sub-allocating mappable resources, maybe.
|
||||||
if (requirements.size >= kMaxSizeForSubAllocation || mappable) {
|
if (requirements.size < kMaxSizeForSubAllocation && !mappable) {
|
||||||
|
ResourceMemoryAllocation subAllocation;
|
||||||
|
DAWN_TRY_ASSIGN(subAllocation,
|
||||||
|
mAllocatorsPerType[memoryType]->AllocateMemory(requirements));
|
||||||
|
if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) {
|
||||||
|
return subAllocation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If sub-allocation failed, allocate memory just for it.
|
||||||
std::unique_ptr<ResourceHeapBase> resourceHeap;
|
std::unique_ptr<ResourceHeapBase> resourceHeap;
|
||||||
DAWN_TRY_ASSIGN(resourceHeap,
|
DAWN_TRY_ASSIGN(resourceHeap, mAllocatorsPerType[memoryType]->AllocateResourceHeap(size));
|
||||||
mAllocatorsPerType[memoryType]->AllocateResourceHeap(size));
|
|
||||||
|
|
||||||
void* mappedPointer = nullptr;
|
void* mappedPointer = nullptr;
|
||||||
if (mappable) {
|
if (mappable) {
|
||||||
DAWN_TRY(
|
DAWN_TRY(
|
||||||
CheckVkSuccess(mDevice->fn.MapMemory(mDevice->GetVkDevice(),
|
CheckVkSuccess(mDevice->fn.MapMemory(mDevice->GetVkDevice(),
|
||||||
ToBackend(resourceHeap.get())->GetMemory(),
|
ToBackend(resourceHeap.get())->GetMemory(), 0,
|
||||||
0, size, 0, &mappedPointer),
|
size, 0, &mappedPointer),
|
||||||
"vkMapMemory"));
|
"vkMapMemory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,9 +141,6 @@ namespace dawn_native { namespace vulkan {
|
|||||||
info.mMethod = AllocationMethod::kDirect;
|
info.mMethod = AllocationMethod::kDirect;
|
||||||
return ResourceMemoryAllocation(info, /*offset*/ 0, resourceHeap.release(),
|
return ResourceMemoryAllocation(info, /*offset*/ 0, resourceHeap.release(),
|
||||||
static_cast<uint8_t*>(mappedPointer));
|
static_cast<uint8_t*>(mappedPointer));
|
||||||
} else {
|
|
||||||
return mAllocatorsPerType[memoryType]->AllocateMemory(requirements);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceMemoryAllocator::Deallocate(ResourceMemoryAllocation* allocation) {
|
void ResourceMemoryAllocator::Deallocate(ResourceMemoryAllocation* allocation) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user