|
| 1 | +/* |
| 2 | + * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * Copyright (c) 2023, JetBrains s.r.o.. All rights reserved. |
| 4 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | + * |
| 6 | + * This code is free software; you can redistribute it and/or modify it |
| 7 | + * under the terms of the GNU General Public License version 2 only, as |
| 8 | + * published by the Free Software Foundation. Oracle designates this |
| 9 | + * particular file as subject to the "Classpath" exception as provided |
| 10 | + * by Oracle in the LICENSE file that accompanied this code. |
| 11 | + * |
| 12 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 13 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 15 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 16 | + * accompanied this code). |
| 17 | + * |
| 18 | + * You should have received a copy of the GNU General Public License version |
| 19 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 20 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + * |
| 22 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 23 | + * or visit www.oracle.com if you need additional information or have any |
| 24 | + * questions. |
| 25 | + */ |
| 26 | + |
| 27 | +#ifndef VKCapabilityUtil_h_Included |
| 28 | +#define VKCapabilityUtil_h_Included |
| 29 | +#include "VKUtil.h" |
| 30 | + |
| 31 | +#define VK_KHR_VALIDATION_LAYER_NAME "VK_LAYER_KHRONOS_validation" |
| 32 | + |
| 33 | +// Named entries are layers or extensions, arragned into on-stack linked list. |
| 34 | +typedef struct VKNamedEntry { |
| 35 | + pchar name; |
| 36 | + const void* found; // Pointer to the found struct. |
| 37 | + struct VKNamedEntry* next; // Pointer to the next entry. |
| 38 | +} VKNamedEntry; |
| 39 | + |
| 40 | +#define DEF_NAMED_ENTRY(LIST, NAME) VKNamedEntry NAME = { NAME ## _NAME, NULL, (LIST) }; \ |
| 41 | + if (NAME.name != NULL) (LIST) = &(NAME) |
| 42 | + |
| 43 | +static void VKNamedEntry_LogAll(pchar what, pchar all, uint32_t count, size_t stride) { |
| 44 | + J2dRlsTraceLn1(J2D_TRACE_VERBOSE, " Supported %s:", what) |
| 45 | + for (uint32_t i = 0; i < count; i++) { |
| 46 | + if (i == 0) J2dRlsTrace(J2D_TRACE_VERBOSE, " ") |
| 47 | + else J2dRlsTrace(J2D_TRACE_VERBOSE, ", ") |
| 48 | + J2dRlsTrace(J2D_TRACE_VERBOSE, all) |
| 49 | + all += stride; |
| 50 | + } |
| 51 | + J2dRlsTrace(J2D_TRACE_VERBOSE, "\n") |
| 52 | +} |
| 53 | + |
| 54 | +static void VKNamedEntry_LogFound(const VKNamedEntry* list) { |
| 55 | + for (; list != NULL; list = list->next) { |
| 56 | + J2dRlsTraceLn2(J2D_TRACE_INFO, " %s = %s", list->name, list->found ? "true" : "false") |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +static void VKNamedEntry_Match(VKNamedEntry* list, pchar all, uint32_t count, size_t stride) { |
| 61 | + for (; list != NULL; list = list->next) { |
| 62 | + pchar check = all; |
| 63 | + for (uint32_t i = 0; i < count; i++) { |
| 64 | + if (strcmp(list->name, check) == 0) { |
| 65 | + list->found = check; |
| 66 | + break; |
| 67 | + } |
| 68 | + check += stride; |
| 69 | + } |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +static ARRAY(pchar) VKNamedEntry_CollectNames(const VKNamedEntry* list) { |
| 74 | + ARRAY(pchar) result = NULL; |
| 75 | + for (; list != NULL; list = list->next) { |
| 76 | + if (list->found) ARRAY_PUSH_BACK(result) = list->name; |
| 77 | + } |
| 78 | + return result; |
| 79 | +} |
| 80 | + |
| 81 | +static void VKCapabilityUtil_LogErrors(int level, ARRAY(pchar) errors) { |
| 82 | + for (uint32_t i = 0; i < ARRAY_SIZE(errors); i++) { |
| 83 | + J2dRlsTraceLn1(level, " %s", errors[i]) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +#endif //VKCapabilityUtil_h_Included |
0 commit comments