-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBufferView.cpp
More file actions
60 lines (46 loc) · 1.79 KB
/
Copy pathBufferView.cpp
File metadata and controls
60 lines (46 loc) · 1.79 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
#include "BufferView.h"
#include <new>
#include "Buffer.h"
#include "Device.h"
#include "Internal/Error.h"
extern "C" {
GPU_API VkResult GPU_CALL gpuBufferViewCreate(
GPUDevice device,
const VkBufferViewCreateInfo* createInfo,
const VkAllocationCallbacks* allocator,
GPUBufferView* bufferView) {
gpu::internal::clearLastError();
if (device == nullptr || createInfo == nullptr || bufferView == nullptr) {
gpu::internal::setLastError("Device, create info, and buffer view output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*bufferView = nullptr;
VkBufferView handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateBufferView(device->handle, createInfo, allocator, &handle);
if (result != VK_SUCCESS) {
gpu::internal::setLastError("Failed to create buffer view.");
return result;
}
GPUBufferView wrapper = new (std::nothrow) GPUBufferView_T{device, device->handle, handle, allocator};
if (wrapper == nullptr) {
gpuDestroyBufferView(device->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate BufferView.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
*bufferView = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuBufferViewDestroy(GPUBufferView bufferView) {
if (bufferView == nullptr) {
return;
}
gpuDestroyBufferView(bufferView->deviceHandle, bufferView->handle, bufferView->allocator);
delete bufferView;
}
GPU_API VkBufferView GPU_CALL gpuBufferViewGetVkHandle(GPUBufferView bufferView) {
return bufferView != nullptr ? bufferView->handle : VK_NULL_HANDLE;
}
GPU_API GPUDevice GPU_CALL gpuBufferViewGetDevice(GPUBufferView bufferView) {
return bufferView != nullptr ? bufferView->device : nullptr;
}
} // extern "C"