-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPipeline.cpp
More file actions
108 lines (88 loc) · 3.25 KB
/
Copy pathPipeline.cpp
File metadata and controls
108 lines (88 loc) · 3.25 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "Pipeline.h"
#include <new>
#include "Device.h"
#include "Internal/Error.h"
#include "PipelineCache.h"
extern "C" {
GPU_API VkResult GPU_CALL gpuPipelineCreateGraphics(
GPUDevice device,
GPUPipelineCache pipelineCache,
const VkGraphicsPipelineCreateInfo* createInfo,
const VkAllocationCallbacks* allocator,
GPUPipeline* pipeline) {
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || pipeline == nullptr) {
gpu::internal::setLastError("Device, create info, and pipeline output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*pipeline = nullptr;
VkPipeline handle = VK_NULL_HANDLE;
const VkPipelineCache cacheHandle = pipelineCache != nullptr ? pipelineCache->handle : VK_NULL_HANDLE;
const VkResult result = gpuCreateGraphicsPipelines(
device->handle,
cacheHandle,
1,
createInfo,
allocator,
&handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create graphics pipeline.");
return result;
}
GPUPipeline wrapper = new (std::nothrow) GPUPipeline_T{device, handle, allocator};
if (wrapper == nullptr) {
gpuDestroyPipeline(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate Pipeline.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
*pipeline = wrapper;
return VK_SUCCESS;
}
GPU_API VkResult GPU_CALL gpuPipelineCreateCompute(
GPUDevice device,
GPUPipelineCache pipelineCache,
const VkComputePipelineCreateInfo* createInfo,
const VkAllocationCallbacks* allocator,
GPUPipeline* pipeline) {
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || pipeline == nullptr) {
gpu::internal::setLastError("Device, create info, and pipeline output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*pipeline = nullptr;
VkPipeline handle = VK_NULL_HANDLE;
const VkPipelineCache cacheHandle = pipelineCache != nullptr ? pipelineCache->handle : VK_NULL_HANDLE;
const VkResult result = gpuCreateComputePipelines(
device->handle,
cacheHandle,
1,
createInfo,
allocator,
&handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create compute pipeline.");
return result;
}
GPUPipeline wrapper = new (std::nothrow) GPUPipeline_T{device, handle, allocator};
if (wrapper == nullptr) {
gpuDestroyPipeline(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate Pipeline.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
*pipeline = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuPipelineDestroy(GPUPipeline pipeline) {
if (pipeline == nullptr) {
return;
}
gpuDestroyPipeline(pipeline->device->handle, pipeline->handle, pipeline->allocator);
delete pipeline;
}
GPU_API VkPipeline GPU_CALL gpuPipelineGetVkHandle(GPUPipeline pipeline) {
return pipeline != nullptr ? pipeline->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuPipelineGetDevice(GPUPipeline pipeline) {
return pipeline != nullptr ? pipeline->device : nullptr;
}
} // extern "C"