-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDebugReportCallbackEXT.cpp
More file actions
80 lines (65 loc) · 2.6 KB
/
Copy pathDebugReportCallbackEXT.cpp
File metadata and controls
80 lines (65 loc) · 2.6 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
#ifndef NDEBUG
#include "DebugReportCallbackEXT.h"
#include <new>
#include "Instance.h"
#include "Internal/Error.h"
extern "C"
{
GPU_API VkResult GPU_CALL gpuDebugReportCallbackEXTCreate(
GPUInstance instance,
const VkDebugReportCallbackCreateInfoEXT *createInfo,
const VkAllocationCallbacks *allocator,
GPUDebugReportCallbackEXT *callback)
{
gpu::internal::clearLastError();
if (instance == nullptr || createInfo == nullptr || callback == nullptr)
{
gpu::internal::setLastError("Instance, create info, and callback output must not be null.");
return VK_ERROR_INITIALIZATION_FAILED;
}
if (instance->destroyRequested)
{
gpu::internal::setLastError("Instance is being destroyed.");
return VK_ERROR_INITIALIZATION_FAILED;
}
*callback = nullptr;
VkDebugReportCallbackEXT handle = VK_NULL_HANDLE;
const VkResult result = gpuCreateDebugReportCallbackEXT(instance->handle, createInfo, allocator, &handle);
if (result != VK_SUCCESS)
{
gpu::internal::setLastError("Failed to create debug report callback.");
return result;
}
GPUDebugReportCallbackEXT wrapper =
new (std::nothrow) GPUDebugReportCallbackEXT_T{instance, handle, allocator, false};
if (wrapper == nullptr)
{
gpuDestroyDebugReportCallbackEXT(instance->handle, handle, allocator);
gpu::internal::setLastError("Failed to allocate DebugReportCallbackEXT.");
return VK_ERROR_OUT_OF_HOST_MEMORY;
}
gpuInstanceRetain(instance);
*callback = wrapper;
return VK_SUCCESS;
}
GPU_API void GPU_CALL gpuDebugReportCallbackEXTDestroy(GPUDebugReportCallbackEXT callback)
{
if (callback == nullptr || callback->destroyRequested)
{
return;
}
callback->destroyRequested = true;
gpuDestroyDebugReportCallbackEXT(callback->instance->handle, callback->handle, callback->allocator);
gpuInstanceDrop(callback->instance);
delete callback;
}
GPU_API VkDebugReportCallbackEXT GPU_CALL gpuDebugReportCallbackEXTGetVkHandle(GPUDebugReportCallbackEXT callback)
{
return callback != nullptr && !callback->destroyRequested ? callback->handle : VK_NULL_HANDLE;
}
GPU_API GPUInstance GPU_CALL gpuDebugReportCallbackEXTGetInstance(GPUDebugReportCallbackEXT callback)
{
return callback != nullptr && !callback->destroyRequested ? callback->instance : nullptr;
}
} // extern "C"
#endif