diff --git a/Makefile.am b/Makefile.am index 5e463770..88255a8a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -54,7 +54,8 @@ CLEANFILES = $(spv_shaders) noinst_LTLIBRARIES = libvkd3d-common.la libvkd3d_common_la_SOURCES = \ include/private/vkd3d_debug.h \ - libs/vkd3d-common/debug.c + libs/vkd3d-common/debug.c \ + libs/vkd3d-common/memory.c lib_LTLIBRARIES = libvkd3d-shader.la libvkd3d.la libvkd3d-utils.la diff --git a/include/private/vkd3d_memory.h b/include/private/vkd3d_memory.h index 0a647038..4df92db1 100644 --- a/include/private/vkd3d_memory.h +++ b/include/private/vkd3d_memory.h @@ -20,6 +20,8 @@ #define __VKD3D_MEMORY_H #include +#include + #include "vkd3d_debug.h" static inline void *vkd3d_malloc(size_t size) @@ -51,4 +53,7 @@ static inline void vkd3d_free(void *ptr) free(ptr); } +bool vkd3d_array_reserve(void **elements, size_t *capacity, + size_t element_count, size_t element_size) DECLSPEC_HIDDEN; + #endif /* __VKD3D_MEMORY_H */ diff --git a/libs/vkd3d-common/memory.c b/libs/vkd3d-common/memory.c new file mode 100644 index 00000000..2bf8947e --- /dev/null +++ b/libs/vkd3d-common/memory.c @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Henri Verbeet for CodeWeavers + * Copyright 2017 Józef Kucia for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "vkd3d_memory.h" + +bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size) +{ + size_t new_capacity, max_capacity; + void *new_elements; + + if (element_count <= *capacity) + return true; + + max_capacity = ~(size_t)0 / element_size; + if (max_capacity < element_count) + return false; + + new_capacity = max(*capacity, 4); + while (new_capacity < element_count && new_capacity <= max_capacity / 2) + new_capacity *= 2; + + if (new_capacity < element_count) + new_capacity = element_count; + + if (!(new_elements = vkd3d_realloc(*elements, new_capacity * element_size))) + return false; + + *elements = new_elements; + *capacity = new_capacity; + + return true; +} diff --git a/libs/vkd3d/utils.c b/libs/vkd3d/utils.c index bde9f620..f86eab58 100644 --- a/libs/vkd3d/utils.c +++ b/libs/vkd3d/utils.c @@ -65,34 +65,6 @@ VkFormat vkd3d_get_vk_format(DXGI_FORMAT format) return vkd3d_format->vk_format; } -bool vkd3d_array_reserve(void **elements, size_t *capacity, size_t element_count, size_t element_size) -{ - size_t new_capacity, max_capacity; - void *new_elements; - - if (element_count <= *capacity) - return true; - - max_capacity = ~(size_t)0 / element_size; - if (max_capacity < element_count) - return false; - - new_capacity = max(*capacity, 4); - while (new_capacity < element_count && new_capacity <= max_capacity / 2) - new_capacity *= 2; - - if (new_capacity < element_count) - new_capacity = element_count; - - if (!(new_elements = vkd3d_realloc(*elements, new_capacity * element_size))) - return false; - - *elements = new_elements; - *capacity = new_capacity; - - return true; -} - bool is_valid_feature_level(D3D_FEATURE_LEVEL feature_level) { static const D3D_FEATURE_LEVEL valid_feature_levels[] = diff --git a/libs/vkd3d/vkd3d_private.h b/libs/vkd3d/vkd3d_private.h index 9eb11849..9941b831 100644 --- a/libs/vkd3d/vkd3d_private.h +++ b/libs/vkd3d/vkd3d_private.h @@ -422,9 +422,6 @@ const char *debug_vk_memory_heap_flags(VkMemoryHeapFlags flags) DECLSPEC_HIDDEN; const char *debug_vk_memory_property_flags(VkMemoryPropertyFlags flags) DECLSPEC_HIDDEN; const char *debug_vk_queue_flags(VkQueueFlags flags) DECLSPEC_HIDDEN; -bool vkd3d_array_reserve(void **elements, size_t *capacity, - size_t element_count, size_t element_size) DECLSPEC_HIDDEN; - HRESULT hresult_from_vk_result(VkResult vr) DECLSPEC_HIDDEN; HRESULT vkd3d_load_vk_instance_procs(struct vkd3d_vk_instance_procs *procs,