diff --git a/libs/video/renderer/vulkan/Makefile.am b/libs/video/renderer/vulkan/Makefile.am index e4102ec9d..b134d1f91 100644 --- a/libs/video/renderer/vulkan/Makefile.am +++ b/libs/video/renderer/vulkan/Makefile.am @@ -5,6 +5,7 @@ AM_CPPFLAGS= -I$(top_srcdir)/include -DVK_NO_PROTOTYPES vulkan_src = \ init.c \ + util.c \ vulkan_draw.c \ vulkan_vid_common.c @@ -21,5 +22,5 @@ SUFFICES=.frag .vert .fc .vc .slc .glsl libvulkan_la_SOURCES= $(vulkan_src) -EXTRA_DIST = $(vulkan_src) $(shader_src) namehack.h +EXTRA_DIST = $(vulkan_src) $(shader_src) namehack.h util.h CLEANFILES= *.vc *.fc *.slc diff --git a/libs/video/renderer/vulkan/init.c b/libs/video/renderer/vulkan/init.c index af3f21b4b..7b553d5f6 100644 --- a/libs/video/renderer/vulkan/init.c +++ b/libs/video/renderer/vulkan/init.c @@ -1,5 +1,5 @@ /* - int.c + init.c Copyright (C) 2019 Bill Currie @@ -45,6 +45,8 @@ #include "vid_vulkan.h" +#include "util.h" + cvar_t *vulkan_use_validation; static uint32_t numLayers; @@ -196,53 +198,6 @@ init_physdev (VulkanInstance_t *instance, VkPhysicalDevice dev, VulkanPhysDevice } } -static int -count_strings (const char **str) -{ - int count = 0; - - if (str) { - while (*str++) { - count++; - } - } - return count; -} - -static void -merge_strings (const char **out, const char **in1, const char **in2) -{ - if (in1) { - while (*in1) { - *out++ = *in1++; - } - } - if (in2) { - while (*in2) { - *out++ = *in2++; - } - } -} - -static void -prune_strings (const char * const *reference, const char **strings, - uint32_t *count) -{ - for (int i = *count; i-- > 0; ) { - const char *str = strings[i]; - const char * const *ref; - for (ref = reference; *ref; ref++) { - if (!strcmp (*ref, str)) { - break; - } - } - if (!*ref) { - memmove (strings + i, strings + i + 1, - (--(*count) - i) * sizeof (const char **)); - } - } -} - static int message_severities = VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT | VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT | diff --git a/libs/video/renderer/vulkan/util.c b/libs/video/renderer/vulkan/util.c new file mode 100644 index 000000000..5603bbd5d --- /dev/null +++ b/libs/video/renderer/vulkan/util.c @@ -0,0 +1,83 @@ +/* + util.c + + Copyright (C) 2019 Bill Currie + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to: + + Free Software Foundation, Inc. + 59 Temple Place - Suite 330 + Boston, MA 02111-1307, USA + +*/ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_STRING_H +# include +#endif +#ifdef HAVE_STRINGS_H +# include +#endif + +#include "util.h" + +int +count_strings (const char **str) +{ + int count = 0; + + if (str) { + while (*str++) { + count++; + } + } + return count; +} + +void +merge_strings (const char **out, const char **in1, const char **in2) +{ + if (in1) { + while (*in1) { + *out++ = *in1++; + } + } + if (in2) { + while (*in2) { + *out++ = *in2++; + } + } +} + +void +prune_strings (const char * const *reference, const char **strings, + uint32_t *count) +{ + for (int i = *count; i-- > 0; ) { + const char *str = strings[i]; + const char * const *ref; + for (ref = reference; *ref; ref++) { + if (!strcmp (*ref, str)) { + break; + } + } + if (!*ref) { + memmove (strings + i, strings + i + 1, + (--(*count) - i) * sizeof (const char **)); + } + } +} diff --git a/libs/video/renderer/vulkan/util.h b/libs/video/renderer/vulkan/util.h new file mode 100644 index 000000000..8d1a967a3 --- /dev/null +++ b/libs/video/renderer/vulkan/util.h @@ -0,0 +1,9 @@ +#ifndef __util_h +#define __util_h + +#include +int count_strings (const char **str); +void merge_strings (const char **out, const char **in1, const char **in2); +void prune_strings (const char * const *reference, const char **strings, uint32_t *count); + +#endif//__util_h