-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeferredOperationKHR.cpp
More file actions
67 lines (52 loc) · 2.36 KB
/
Copy pathDeferredOperationKHR.cpp
File metadata and controls
67 lines (52 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "DeferredOperationKHR.h"
#include <new>
#include "Device.h"
#include "Internal/Error.h"
extern "C" {
GPU_API VkResult GPU_CALL gpuDeferredOperationKHRCreate(
GPUDevice device,
const VkAllocationCallbacks* allocator,
GPUDeferredOperationKHR* deferredOperation) {
gpu::internal::clearLastError();
if (device == nullptr || deferredOperation == nullptr) {
gpu::internal::setLastError("Device and deferred operation output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
if (device->destroyRequested) {
gpu::internal::setLastError("Device is being destroyed.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*deferredOperation = nullptr;
VkDeferredOperationKHR handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateDeferredOperationKHR(device->handle, allocator, &handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create deferred operation.");
return result;
}
GPUDeferredOperationKHR wrapper =
new (std::nothrow) GPUDeferredOperationKHR_T{device, handle, allocator, false};
if (wrapper == nullptr) {
gpuDestroyDeferredOperationKHR(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate DeferredOperationKHR.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
gpuDeviceRetain(device);
*deferredOperation = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuDeferredOperationKHRDestroy(GPUDeferredOperationKHR deferredOperation) {
if (deferredOperation == nullptr || deferredOperation->destroyRequested) {
return;
}
deferredOperation->destroyRequested = true;
gpuDestroyDeferredOperationKHR(deferredOperation->device->handle, deferredOperation->handle, deferredOperation->allocator);
gpuDeviceDrop(deferredOperation->device);
delete deferredOperation;
}
GPU_API VkDeferredOperationKHR GPU_CALL gpuDeferredOperationKHRGetVkHandle(GPUDeferredOperationKHR deferredOperation) {
return deferredOperation != nullptr && !deferredOperation->destroyRequested ? deferredOperation->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuDeferredOperationKHRGetDevice(GPUDeferredOperationKHR deferredOperation) {
return deferredOperation != nullptr && !deferredOperation->destroyRequested ? deferredOperation->device : nullptr;
}
} // extern "C"