-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandPool.cpp
More file actions
68 lines (53 loc) · 2.13 KB
/
Copy pathCommandPool.cpp
File metadata and controls
68 lines (53 loc) · 2.13 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
68
#include "CommandPool.h"
#include "CommandBuffer.h"
#include <new>
#include "Device.h"
#include "Internal/Error.h"
extern "C" {
GPU_API VkResult GPU_CALL gpuCommandPoolCreate(
GPUDevice device,
const VkCommandPoolCreateInfo* createInfo,
const VkAllocationCallbacks* allocator,
GPUCommandPool* commandPool) {
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || commandPool == nullptr) {
gpu::internal::setLastError("Device, create info, and command pool output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*commandPool = nullptr;
VkCommandPool handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateCommandPool(device->handle, createInfo, allocator, &handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create command pool.");
return result;
}
GPUCommandPool wrapper = new (std::nothrow) GPUCommandPool_T{device, device->handle, handle, allocator, nullptr};
if (wrapper == nullptr) {
gpuDestroyCommandPool(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate CommandPool.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
*commandPool = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuCommandPoolDestroy(GPUCommandPool commandPool) {
if (commandPool == nullptr) {
return;
}
GPUCommandBuffer buffer = commandPool->firstCommandBuffer;
while (buffer != nullptr) {
GPUCommandBuffer next = buffer->next;
gpuFreeCommandBuffers(commandPool->deviceHandle, commandPool->handle, 1, &buffer->handle);
delete buffer;
buffer = next;
}
gpuDestroyCommandPool(commandPool->deviceHandle, commandPool->handle, commandPool->allocator);
delete commandPool;
}
GPU_API VkCommandPool GPU_CALL gpuCommandPoolGetVkHandle(GPUCommandPool commandPool) {
return commandPool != nullptr ? commandPool->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuCommandPoolGetDevice(GPUCommandPool commandPool) {
return commandPool != nullptr ? commandPool->device : nullptr;
}
} // extern "C"