Check for OOM in GrVkMemory
Change-Id: Ia6bc631596c5de3e8b3f634d5798fd1e76e8ddde Reviewed-on: https://skia-review.googlesource.com/c/skia/+/309438 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
This commit is contained in:
parent
43d8d23693
commit
864562faf4
@ -2515,6 +2515,22 @@ void GrVkGpu::endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin,
|
||||
this->didWriteToSurface(target, origin, &bounds);
|
||||
}
|
||||
|
||||
bool GrVkGpu::checkVkResult(VkResult result) {
|
||||
switch (result) {
|
||||
case VK_SUCCESS:
|
||||
return true;
|
||||
case VK_ERROR_DEVICE_LOST:
|
||||
fDeviceIsLost = true;
|
||||
return false;
|
||||
case VK_ERROR_OUT_OF_DEVICE_MEMORY:
|
||||
case VK_ERROR_OUT_OF_HOST_MEMORY:
|
||||
this->setOOMed();
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void GrVkGpu::submitSecondaryCommandBuffer(std::unique_ptr<GrVkSecondaryCommandBuffer> buffer) {
|
||||
if (!this->currentCommandBuffer()) {
|
||||
return;
|
||||
|
@ -53,7 +53,6 @@ public:
|
||||
void takeOwnershipOfBuffer(sk_sp<GrGpuBuffer>) override;
|
||||
|
||||
bool isDeviceLost() const override { return fDeviceIsLost; }
|
||||
void setDeviceLost() { fDeviceIsLost = true; }
|
||||
|
||||
GrVkMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
|
||||
|
||||
@ -175,7 +174,10 @@ public:
|
||||
const SkIRect& bounds, bool forSecondaryCB);
|
||||
void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin, const SkIRect& bounds);
|
||||
|
||||
using GrGpu::setOOMed;
|
||||
// Returns true if VkResult indicates success and also checks for device lost or OOM. Every
|
||||
// Vulkan call (and GrVkMemoryAllocator call that returns VkResult) made on behalf of the
|
||||
// GrVkGpu should be processed by this function so that we respond to OOMs and lost devices.
|
||||
bool checkVkResult(VkResult);
|
||||
|
||||
private:
|
||||
enum SyncQueue {
|
||||
|
@ -31,16 +31,6 @@ static BufferUsage get_buffer_usage(GrVkBuffer::Type type, bool dynamic) {
|
||||
SK_ABORT("Invalid GrVkBuffer::Type");
|
||||
}
|
||||
|
||||
static bool check_result(GrVkGpu* gpu, VkResult result) {
|
||||
if (result != VK_SUCCESS) {
|
||||
if (result == VK_ERROR_DEVICE_LOST) {
|
||||
gpu->setDeviceLost();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GrVkMemory::AllocAndBindBufferMemory(GrVkGpu* gpu,
|
||||
VkBuffer buffer,
|
||||
GrVkBuffer::Type type,
|
||||
@ -68,7 +58,7 @@ bool GrVkMemory::AllocAndBindBufferMemory(GrVkGpu* gpu,
|
||||
}
|
||||
|
||||
VkResult result = allocator->allocateBufferMemory(buffer, usage, propFlags, &memory);
|
||||
if (!check_result(gpu, result)) {
|
||||
if (!gpu->checkVkResult(result)) {
|
||||
return false;
|
||||
}
|
||||
allocator->getAllocInfo(memory, alloc);
|
||||
@ -118,7 +108,7 @@ bool GrVkMemory::AllocAndBindImageMemory(GrVkGpu* gpu,
|
||||
}
|
||||
|
||||
VkResult result = allocator->allocateImageMemory(image, propFlags, &memory);
|
||||
if (!check_result(gpu, result)) {
|
||||
if (!gpu->checkVkResult(result)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -149,7 +139,7 @@ void* GrVkMemory::MapAlloc(GrVkGpu* gpu, const GrVkAlloc& alloc) {
|
||||
GrVkMemoryAllocator* allocator = gpu->memoryAllocator();
|
||||
void* mapPtr;
|
||||
VkResult result = allocator->mapMemory(alloc.fBackendMemory, &mapPtr);
|
||||
if (!check_result(gpu, result)) {
|
||||
if (!gpu->checkVkResult(result)) {
|
||||
return nullptr;
|
||||
}
|
||||
return mapPtr;
|
||||
@ -192,7 +182,7 @@ void GrVkMemory::FlushMappedAlloc(GrVkGpu* gpu, const GrVkAlloc& alloc, VkDevice
|
||||
SkASSERT(alloc.fBackendMemory);
|
||||
GrVkMemoryAllocator* allocator = gpu->memoryAllocator();
|
||||
VkResult result = allocator->flushMemory(alloc.fBackendMemory, offset, size);
|
||||
check_result(gpu, result);
|
||||
gpu->checkVkResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
@ -204,7 +194,7 @@ void GrVkMemory::InvalidateMappedAlloc(GrVkGpu* gpu, const GrVkAlloc& alloc,
|
||||
SkASSERT(alloc.fBackendMemory);
|
||||
GrVkMemoryAllocator* allocator = gpu->memoryAllocator();
|
||||
VkResult result = allocator->invalidateMemory(alloc.fBackendMemory, offset, size);
|
||||
check_result(gpu, result);
|
||||
gpu->checkVkResult(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,23 +28,13 @@ class GrVkGpu;
|
||||
if (RESULT != VK_SUCCESS && !GPU->isDeviceLost()) { \
|
||||
SkDebugf("Failed vulkan call. Error: %d," #X "\n", RESULT); \
|
||||
} \
|
||||
if (RESULT == VK_ERROR_DEVICE_LOST) { \
|
||||
GPU->setDeviceLost(); \
|
||||
} else if (RESULT == VK_ERROR_OUT_OF_HOST_MEMORY || \
|
||||
RESULT == VK_ERROR_OUT_OF_DEVICE_MEMORY) { \
|
||||
GPU->setOOMed(); \
|
||||
} \
|
||||
GPU->checkVkResult(RESULT); \
|
||||
} while (false)
|
||||
|
||||
#define GR_VK_CALL_RESULT_NOCHECK(GPU, RESULT, X) \
|
||||
do { \
|
||||
(RESULT) = GR_VK_CALL(GPU->vkInterface(), X); \
|
||||
if (RESULT == VK_ERROR_DEVICE_LOST) { \
|
||||
GPU->setDeviceLost(); \
|
||||
} else if (RESULT == VK_ERROR_OUT_OF_HOST_MEMORY || \
|
||||
RESULT == VK_ERROR_OUT_OF_DEVICE_MEMORY) { \
|
||||
GPU->setOOMed(); \
|
||||
} \
|
||||
#define GR_VK_CALL_RESULT_NOCHECK(GPU, RESULT, X) \
|
||||
do { \
|
||||
(RESULT) = GR_VK_CALL(GPU->vkInterface(), X); \
|
||||
GPU->checkVkResult(RESULT); \
|
||||
} while (false)
|
||||
|
||||
// same as GR_VK_CALL but checks for success
|
||||
|
Loading…
Reference in New Issue
Block a user