tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
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
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 *
 */
 
//
//
//
 
#include <stdlib.h>
#include <stdio.h>
 
//
//
//
 
#include "assert_vk.h"
 
//
//
//
 
#define VK_RESULT_TO_STRING(result) case result: return #result
 
//
// FIXME -- results and errors
//
 
char const *
vk_get_result_string(VkResult const result)
{
  switch (result)
    {
      //
      // Results
      //
      VK_RESULT_TO_STRING(VK_SUCCESS);
      VK_RESULT_TO_STRING(VK_NOT_READY);
      VK_RESULT_TO_STRING(VK_TIMEOUT);
      VK_RESULT_TO_STRING(VK_EVENT_SET);
      VK_RESULT_TO_STRING(VK_EVENT_RESET);
      VK_RESULT_TO_STRING(VK_INCOMPLETE);
      //
      // Errors
      //
      VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_HOST_MEMORY);
      VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DEVICE_MEMORY);
      VK_RESULT_TO_STRING(VK_ERROR_INITIALIZATION_FAILED);
      VK_RESULT_TO_STRING(VK_ERROR_DEVICE_LOST);
      VK_RESULT_TO_STRING(VK_ERROR_MEMORY_MAP_FAILED);
      VK_RESULT_TO_STRING(VK_ERROR_LAYER_NOT_PRESENT);
      VK_RESULT_TO_STRING(VK_ERROR_EXTENSION_NOT_PRESENT);
      VK_RESULT_TO_STRING(VK_ERROR_FEATURE_NOT_PRESENT);
      VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DRIVER);
      VK_RESULT_TO_STRING(VK_ERROR_TOO_MANY_OBJECTS);
      VK_RESULT_TO_STRING(VK_ERROR_FORMAT_NOT_SUPPORTED);
      VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTED_POOL);
      VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_POOL_MEMORY);
      VK_RESULT_TO_STRING(VK_ERROR_INVALID_EXTERNAL_HANDLE);
      VK_RESULT_TO_STRING(VK_ERROR_SURFACE_LOST_KHR);
      VK_RESULT_TO_STRING(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
      VK_RESULT_TO_STRING(VK_SUBOPTIMAL_KHR);
      VK_RESULT_TO_STRING(VK_ERROR_OUT_OF_DATE_KHR);
      VK_RESULT_TO_STRING(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
      VK_RESULT_TO_STRING(VK_ERROR_VALIDATION_FAILED_EXT);
      VK_RESULT_TO_STRING(VK_ERROR_INVALID_SHADER_NV);
      VK_RESULT_TO_STRING(VK_ERROR_FRAGMENTATION_EXT);
      VK_RESULT_TO_STRING(VK_ERROR_NOT_PERMITTED_EXT);
 
      //
      // Extensions: vk_xyz
      //
    default:
      return "UNKNOWN VULKAN RESULT";
    }
}
 
//
//
//
 
VkResult
assert_vk(VkResult const result, char const * const file, int const line, bool const abort)
{
  if (result != VK_SUCCESS)
    {
      char const * const vk_result_str = vk_get_result_string(result);
 
      fprintf(stderr,
              "\"%s\", line %d: assert_vk( %d ) = \"%s\"",
              file,line,result,vk_result_str);
 
      if (abort)
        {
          // stop profiling and reset device here if necessary
          exit(result);
        }
    }
 
  return result;
}
 
//
//
//