diff options
author | Branimir Karadžić <branimirkaradzic@gmail.com> | 2017-03-29 17:09:40 +0200 |
---|---|---|
committer | Miodrag Milanovic <mmicko@gmail.com> | 2017-03-29 17:09:40 +0200 |
commit | 49f7c99c7786ce257fae28dfeae2f8ee5810424c (patch) | |
tree | 1bbd30dd4dd48596186846c2fc77a8dc748215d2 /3rdparty/bx | |
parent | 79f22e060b2c012d628d5d1d83288c1bb6e6acef (diff) |
Update BGFX and BX (nw)
Diffstat (limited to '3rdparty/bx')
112 files changed, 4680 insertions, 7081 deletions
diff --git a/3rdparty/bx/3rdparty/CL/cl.h b/3rdparty/bx/3rdparty/CL/cl.h deleted file mode 100644 index 203c65974f2..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl.h +++ /dev/null @@ -1,1214 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_H -#define __OPENCL_CL_H - -#ifdef __APPLE__ -#include <OpenCL/cl_platform.h> -#else -#include <CL/cl_platform.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -typedef cl_bitfield cl_command_queue_properties; -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -typedef cl_bitfield cl_mem_migration_flags; -typedef cl_uint cl_image_info; -typedef cl_uint cl_buffer_create_type; -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -typedef cl_uint cl_program_binary_type; -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -typedef cl_uint cl_kernel_arg_info; -typedef cl_uint cl_kernel_arg_address_qualifier; -typedef cl_uint cl_kernel_arg_access_qualifier; -typedef cl_bitfield cl_kernel_arg_type_qualifier; -typedef cl_uint cl_kernel_work_group_info; -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; - - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; - cl_mem buffer; -} cl_image_desc; - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#define CL_INVALID_PROPERTY -64 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 - -/* OpenCL Version */ -#define CL_VERSION_1_0 1 -#define CL_VERSION_1_1 1 -#define CL_VERSION_1_2 1 - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */ -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#define CL_FP_SOFT_FLOAT (1 << 6) -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#define CL_CONTEXT_NUM_DEVICES 0x1083 - -/* cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 - -/* cl_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -// reserved (1 << 6) -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#define CL_UNORM_INT24 0x10DF - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#define CL_PROGRAM_BINARY_TYPE 0x1184 - -/* cl_program_binary_type */ -#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 -#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 -#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 -#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#define CL_KERNEL_ATTRIBUTES 0x1195 - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -/* cl_kernel_arg_type_qualifer */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#define CL_EVENT_CONTEXT 0x11D4 - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 - -/********************************************************************************************************/ - -/* Platform API */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformIDs(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetPlatformInfo(cl_platform_id /* platform */, - cl_platform_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Device APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceIDs(cl_platform_id /* platform */, - cl_device_type /* device_type */, - cl_uint /* num_entries */, - cl_device_id * /* devices */, - cl_uint * /* num_devices */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceInfo(cl_device_id /* device */, - cl_device_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateSubDevices(cl_device_id /* in_device */, - const cl_device_partition_property * /* properties */, - cl_uint /* num_devices */, - cl_device_id * /* out_devices */, - cl_uint * /* num_devices_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseDevice(cl_device_id /* device */) CL_API_SUFFIX__VERSION_1_2; - -/* Context APIs */ -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContext(const cl_context_properties * /* properties */, - cl_uint /* num_devices */, - const cl_device_id * /* devices */, - void (CL_CALLBACK * /* pfn_notify */)(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_context CL_API_CALL -clCreateContextFromType(const cl_context_properties * /* properties */, - cl_device_type /* device_type */, - void (CL_CALLBACK * /* pfn_notify*/ )(const char *, const void *, size_t, void *), - void * /* user_data */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseContext(cl_context /* context */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetContextInfo(cl_context /* context */, - cl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Command Queue APIs */ -extern CL_API_ENTRY cl_command_queue CL_API_CALL -clCreateCommandQueue(cl_context /* context */, - cl_device_id /* device */, - cl_command_queue_properties /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseCommandQueue(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetCommandQueueInfo(cl_command_queue /* command_queue */, - cl_command_queue_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Memory Object APIs */ -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - size_t /* size */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateSubBuffer(cl_mem /* buffer */, - cl_mem_flags /* flags */, - cl_buffer_create_type /* buffer_create_type */, - const void * /* buffer_create_info */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateImage(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - const cl_image_desc * /* image_desc */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseMemObject(cl_mem /* memobj */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSupportedImageFormats(cl_context /* context */, - cl_mem_flags /* flags */, - cl_mem_object_type /* image_type */, - cl_uint /* num_entries */, - cl_image_format * /* image_formats */, - cl_uint * /* num_image_formats */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetMemObjectInfo(cl_mem /* memobj */, - cl_mem_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetImageInfo(cl_mem /* image */, - cl_image_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetMemObjectDestructorCallback( cl_mem /* memobj */, - void (CL_CALLBACK * /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_API_SUFFIX__VERSION_1_1; - -/* Sampler APIs */ -extern CL_API_ENTRY cl_sampler CL_API_CALL -clCreateSampler(cl_context /* context */, - cl_bool /* normalized_coords */, - cl_addressing_mode /* addressing_mode */, - cl_filter_mode /* filter_mode */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseSampler(cl_sampler /* sampler */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetSamplerInfo(cl_sampler /* sampler */, - cl_sampler_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Program Object APIs */ -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithSource(cl_context /* context */, - cl_uint /* count */, - const char ** /* strings */, - const size_t * /* lengths */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBinary(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const size_t * /* lengths */, - const unsigned char ** /* binaries */, - cl_int * /* binary_status */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_program CL_API_CALL -clCreateProgramWithBuiltInKernels(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* kernel_names */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseProgram(cl_program /* program */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clBuildProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCompileProgram(cl_program /* program */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_headers */, - const cl_program * /* input_headers */, - const char ** /* header_include_names */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_program CL_API_CALL -clLinkProgram(cl_context /* context */, - cl_uint /* num_devices */, - const cl_device_id * /* device_list */, - const char * /* options */, - cl_uint /* num_input_programs */, - const cl_program * /* input_programs */, - void (CL_CALLBACK * /* pfn_notify */)(cl_program /* program */, void * /* user_data */), - void * /* user_data */, - cl_int * /* errcode_ret */ ) CL_API_SUFFIX__VERSION_1_2; - - -extern CL_API_ENTRY cl_int CL_API_CALL -clUnloadPlatformCompiler(cl_platform_id /* platform */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramInfo(cl_program /* program */, - cl_program_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetProgramBuildInfo(cl_program /* program */, - cl_device_id /* device */, - cl_program_build_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Kernel Object APIs */ -extern CL_API_ENTRY cl_kernel CL_API_CALL -clCreateKernel(cl_program /* program */, - const char * /* kernel_name */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clCreateKernelsInProgram(cl_program /* program */, - cl_uint /* num_kernels */, - cl_kernel * /* kernels */, - cl_uint * /* num_kernels_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseKernel(cl_kernel /* kernel */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetKernelArg(cl_kernel /* kernel */, - cl_uint /* arg_index */, - size_t /* arg_size */, - const void * /* arg_value */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelInfo(cl_kernel /* kernel */, - cl_kernel_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelArgInfo(cl_kernel /* kernel */, - cl_uint /* arg_indx */, - cl_kernel_arg_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetKernelWorkGroupInfo(cl_kernel /* kernel */, - cl_device_id /* device */, - cl_kernel_work_group_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Event Object APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clWaitForEvents(cl_uint /* num_events */, - const cl_event * /* event_list */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventInfo(cl_event /* event */, - cl_event_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateUserEvent(cl_context /* context */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clRetainEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clReleaseEvent(cl_event /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetUserEventStatus(cl_event /* event */, - cl_int /* execution_status */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clSetEventCallback( cl_event /* event */, - cl_int /* command_exec_callback_type */, - void (CL_CALLBACK * /* pfn_notify */)(cl_event, cl_int, void *), - void * /* user_data */) CL_API_SUFFIX__VERSION_1_1; - -/* Profiling APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clGetEventProfilingInfo(cl_event /* event */, - cl_profiling_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -/* Flush and Finish APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clFlush(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clFinish(cl_command_queue /* command_queue */) CL_API_SUFFIX__VERSION_1_0; - -/* Enqueued Commands APIs */ -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - size_t /* offset */, - size_t /* size */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_read */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - size_t /* offset */, - size_t /* size */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteBufferRect(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_write */, - const size_t * /* buffer_offset */, - const size_t * /* host_offset */, - const size_t * /* region */, - size_t /* buffer_row_pitch */, - size_t /* buffer_slice_pitch */, - size_t /* host_row_pitch */, - size_t /* host_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - const void * /* pattern */, - size_t /* pattern_size */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - size_t /* src_offset */, - size_t /* dst_offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferRect(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin */, - const size_t * /* dst_origin */, - const size_t * /* region */, - size_t /* src_row_pitch */, - size_t /* src_slice_pitch */, - size_t /* dst_row_pitch */, - size_t /* dst_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_1; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReadImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_read */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* row_pitch */, - size_t /* slice_pitch */, - void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueWriteImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_write */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t /* input_row_pitch */, - size_t /* input_slice_pitch */, - const void * /* ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueFillImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - const void * /* fill_color */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImage(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_image */, - const size_t * /* src_origin[3] */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyImageToBuffer(cl_command_queue /* command_queue */, - cl_mem /* src_image */, - cl_mem /* dst_buffer */, - const size_t * /* src_origin[3] */, - const size_t * /* region[3] */, - size_t /* dst_offset */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueCopyBufferToImage(cl_command_queue /* command_queue */, - cl_mem /* src_buffer */, - cl_mem /* dst_image */, - size_t /* src_offset */, - const size_t * /* dst_origin[3] */, - const size_t * /* region[3] */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapBuffer(cl_command_queue /* command_queue */, - cl_mem /* buffer */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - size_t /* offset */, - size_t /* size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY void * CL_API_CALL -clEnqueueMapImage(cl_command_queue /* command_queue */, - cl_mem /* image */, - cl_bool /* blocking_map */, - cl_map_flags /* map_flags */, - const size_t * /* origin[3] */, - const size_t * /* region[3] */, - size_t * /* image_row_pitch */, - size_t * /* image_slice_pitch */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueUnmapMemObject(cl_command_queue /* command_queue */, - cl_mem /* memobj */, - void * /* mapped_ptr */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMigrateMemObjects(cl_command_queue /* command_queue */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_objects */, - cl_mem_migration_flags /* flags */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNDRangeKernel(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* work_dim */, - const size_t * /* global_work_offset */, - const size_t * /* global_work_size */, - const size_t * /* local_work_size */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueTask(cl_command_queue /* command_queue */, - cl_kernel /* kernel */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueNativeKernel(cl_command_queue /* command_queue */, - void (CL_CALLBACK * /*user_func*/)(void *), - void * /* args */, - size_t /* cb_args */, - cl_uint /* num_mem_objects */, - const cl_mem * /* mem_list */, - const void ** /* args_mem_loc */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueMarkerWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueBarrierWithWaitList(cl_command_queue /* command_queue */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_2; - - -/* Extension function access - * - * Returns the extension function address for the given function name, - * or NULL if a valid function can not be found. The client must - * check to make sure the address is not NULL, before using or - * calling the returned function address. - */ -extern CL_API_ENTRY void * CL_API_CALL -clGetExtensionFunctionAddressForPlatform(cl_platform_id /* platform */, - const char * /* func_name */) CL_API_SUFFIX__VERSION_1_2; - - -// Deprecated OpenCL 1.1 APIs -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage2D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_row_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateImage3D(cl_context /* context */, - cl_mem_flags /* flags */, - const cl_image_format * /* image_format */, - size_t /* image_width */, - size_t /* image_height */, - size_t /* image_depth */, - size_t /* image_row_pitch */, - size_t /* image_slice_pitch */, - void * /* host_ptr */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueMarker(cl_command_queue /* command_queue */, - cl_event * /* event */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueWaitForEvents(cl_command_queue /* command_queue */, - cl_uint /* num_events */, - const cl_event * /* event_list */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clEnqueueBarrier(cl_command_queue /* command_queue */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_int CL_API_CALL -clUnloadCompiler(void) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED void * CL_API_CALL -clGetExtensionFunctionAddress(const char * /* func_name */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_H */ - diff --git a/3rdparty/bx/3rdparty/CL/cl_d3d10.h b/3rdparty/bx/3rdparty/CL/cl_d3d10.h deleted file mode 100644 index 81b0d37214e..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_d3d10.h +++ /dev/null @@ -1,126 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_D3D10_H -#define __OPENCL_CL_D3D10_H - -#include <d3d10.h> -#include <CL/cl.h> -#include <CL/cl_platform.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************** - * cl_khr_d3d10_sharing */ -#define cl_khr_d3d10_sharing 1 - -typedef cl_uint cl_d3d10_device_source_khr; -typedef cl_uint cl_d3d10_device_set_khr; - -/******************************************************************************/ - -// Error Codes -#define CL_INVALID_D3D10_DEVICE_KHR -1002 -#define CL_INVALID_D3D10_RESOURCE_KHR -1003 -#define CL_D3D10_RESOURCE_ALREADY_ACQUIRED_KHR -1004 -#define CL_D3D10_RESOURCE_NOT_ACQUIRED_KHR -1005 - -// cl_d3d10_device_source_nv -#define CL_D3D10_DEVICE_KHR 0x4010 -#define CL_D3D10_DXGI_ADAPTER_KHR 0x4011 - -// cl_d3d10_device_set_nv -#define CL_PREFERRED_DEVICES_FOR_D3D10_KHR 0x4012 -#define CL_ALL_DEVICES_FOR_D3D10_KHR 0x4013 - -// cl_context_info -#define CL_CONTEXT_D3D10_DEVICE_KHR 0x4014 -#define CL_CONTEXT_D3D10_PREFER_SHARED_RESOURCES_KHR 0x402C - -// cl_mem_info -#define CL_MEM_D3D10_RESOURCE_KHR 0x4015 - -// cl_image_info -#define CL_IMAGE_D3D10_SUBRESOURCE_KHR 0x4016 - -// cl_command_type -#define CL_COMMAND_ACQUIRE_D3D10_OBJECTS_KHR 0x4017 -#define CL_COMMAND_RELEASE_D3D10_OBJECTS_KHR 0x4018 - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D10KHR_fn)( - cl_platform_id platform, - cl_d3d10_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d10_device_set_khr d3d_device_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10BufferKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture2DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Texture2D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D10Texture3DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D10Texture3D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D10ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D10ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_0; - -#ifdef __cplusplus -} -#endif - -#endif // __OPENCL_CL_D3D10_H - diff --git a/3rdparty/bx/3rdparty/CL/cl_d3d11.h b/3rdparty/bx/3rdparty/CL/cl_d3d11.h deleted file mode 100644 index d3c8bdc2b1f..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_d3d11.h +++ /dev/null @@ -1,126 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_D3D11_H -#define __OPENCL_CL_D3D11_H - -#include <d3d11.h> -#include <CL/cl.h> -#include <CL/cl_platform.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************** - * cl_khr_d3d11_sharing */ -#define cl_khr_d3d11_sharing 1 - -typedef cl_uint cl_d3d11_device_source_khr; -typedef cl_uint cl_d3d11_device_set_khr; - -/******************************************************************************/ - -// Error Codes -#define CL_INVALID_D3D11_DEVICE_KHR -1006 -#define CL_INVALID_D3D11_RESOURCE_KHR -1007 -#define CL_D3D11_RESOURCE_ALREADY_ACQUIRED_KHR -1008 -#define CL_D3D11_RESOURCE_NOT_ACQUIRED_KHR -1009 - -// cl_d3d11_device_source -#define CL_D3D11_DEVICE_KHR 0x4019 -#define CL_D3D11_DXGI_ADAPTER_KHR 0x401A - -// cl_d3d11_device_set -#define CL_PREFERRED_DEVICES_FOR_D3D11_KHR 0x401B -#define CL_ALL_DEVICES_FOR_D3D11_KHR 0x401C - -// cl_context_info -#define CL_CONTEXT_D3D11_DEVICE_KHR 0x401D -#define CL_CONTEXT_D3D11_PREFER_SHARED_RESOURCES_KHR 0x402D - -// cl_mem_info -#define CL_MEM_D3D11_RESOURCE_KHR 0x401E - -// cl_image_info -#define CL_IMAGE_D3D11_SUBRESOURCE_KHR 0x401F - -// cl_command_type -#define CL_COMMAND_ACQUIRE_D3D11_OBJECTS_KHR 0x4020 -#define CL_COMMAND_RELEASE_D3D11_OBJECTS_KHR 0x4021 - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromD3D11KHR_fn)( - cl_platform_id platform, - cl_d3d11_device_source_khr d3d_device_source, - void * d3d_object, - cl_d3d11_device_set_khr d3d_device_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11BufferKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Buffer * resource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture2DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Texture2D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromD3D11Texture3DKHR_fn)( - cl_context context, - cl_mem_flags flags, - ID3D11Texture3D * resource, - UINT subresource, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireD3D11ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseD3D11ObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#ifdef __cplusplus -} -#endif - -#endif // __OPENCL_CL_D3D11_H - diff --git a/3rdparty/bx/3rdparty/CL/cl_dx9_media_sharing.h b/3rdparty/bx/3rdparty/CL/cl_dx9_media_sharing.h deleted file mode 100644 index 1ef543a5af9..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_dx9_media_sharing.h +++ /dev/null @@ -1,127 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_CL_DX9_MEDIA_SHARING_H -#define __OPENCL_CL_DX9_MEDIA_SHARING_H - -#include <CL/cl.h> -#include <CL/cl_platform.h> - -#ifdef __cplusplus -extern "C" { -#endif - -/****************************************************************************** -/* cl_khr_dx9_media_sharing */ -#define cl_khr_dx9_media_sharing 1 - -typedef cl_uint cl_dx9_media_adapter_type_khr; -typedef cl_uint cl_dx9_media_adapter_set_khr; - -#if defined(_WIN32) -#include <d3d9.h> -typedef struct _cl_dx9_surface_info_khr -{ - IDirect3DSurface9 *resource; - HANDLE shared_handle; -} cl_dx9_surface_info_khr; -#endif - - -/******************************************************************************/ - -// Error Codes -#define CL_INVALID_DX9_MEDIA_ADAPTER_KHR -1010 -#define CL_INVALID_DX9_MEDIA_SURFACE_KHR -1011 -#define CL_DX9_MEDIA_SURFACE_ALREADY_ACQUIRED_KHR -1012 -#define CL_DX9_MEDIA_SURFACE_NOT_ACQUIRED_KHR -1013 - -// cl_media_adapter_type_khr -#define CL_ADAPTER_D3D9_KHR 0x2020 -#define CL_ADAPTER_D3D9EX_KHR 0x2021 -#define CL_ADAPTER_DXVA_KHR 0x2022 - -// cl_media_adapter_set_khr -#define CL_PREFERRED_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2023 -#define CL_ALL_DEVICES_FOR_DX9_MEDIA_ADAPTER_KHR 0x2024 - -// cl_context_info -#define CL_CONTEXT_ADAPTER_D3D9_KHR 0x2025 -#define CL_CONTEXT_ADAPTER_D3D9EX_KHR 0x2026 -#define CL_CONTEXT_ADAPTER_DXVA_KHR 0x2027 - -// cl_mem_info -#define CL_MEM_DX9_MEDIA_ADAPTER_TYPE_KHR 0x2028 -#define CL_MEM_DX9_MEDIA_SURFACE_INFO_KHR 0x2029 - -// cl_image_info -#define CL_IMAGE_DX9_MEDIA_PLANE_KHR 0x202A - -// cl_command_type -#define CL_COMMAND_ACQUIRE_DX9_MEDIA_SURFACES_KHR 0x202B -#define CL_COMMAND_RELEASE_DX9_MEDIA_SURFACES_KHR 0x202C - -/******************************************************************************/ - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetDeviceIDsFromDX9MediaAdapterKHR_fn)( - cl_platform_id platform, - cl_uint num_media_adapters, - cl_dx9_media_adapter_type_khr * media_adapter_type, - void * media_adapters, - cl_dx9_media_adapter_set_khr media_adapter_set, - cl_uint num_entries, - cl_device_id * devices, - cl_uint * num_devices) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromDX9MediaSurfaceKHR_fn)( - cl_context context, - cl_mem_flags flags, - cl_dx9_media_adapter_type_khr adapter_type, - void * surface_info, - cl_uint plane, - cl_int * errcode_ret) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireDX9MediaSurfacesKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseDX9MediaSurfacesKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event) CL_API_SUFFIX__VERSION_1_2; - -#ifdef __cplusplus -} -#endif - -#endif // __OPENCL_CL_DX9_MEDIA_SHARING_H - diff --git a/3rdparty/bx/3rdparty/CL/cl_egl.h b/3rdparty/bx/3rdparty/CL/cl_egl.h deleted file mode 100644 index c1bd4f39423..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_egl.h +++ /dev/null @@ -1,131 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2010 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifndef __OPENCL_CL_EGL_H -#define __OPENCL_CL_EGL_H - -#ifdef __APPLE__ - -#else -#include <CL/cl.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Command type for events created with clEnqueueAcquireEGLObjectsKHR */ -#define CL_COMMAND_EGL_FENCE_SYNC_OBJECT_KHR 0x202F -#define CL_COMMAND_ACQUIRE_EGL_OBJECTS_KHR 0x202D -#define CL_COMMAND_RELEASE_EGL_OBJECTS_KHR 0x202E - -/* Error type for clCreateFromEGLImageKHR */ -#define CL_INVALID_EGL_OBJECT_KHR -1093 -#define CL_EGL_RESOURCE_NOT_ACQUIRED_KHR -1092 - -/* CLeglImageKHR is an opaque handle to an EGLImage */ -typedef void* CLeglImageKHR; - -/* CLeglDisplayKHR is an opaque handle to an EGLDisplay */ -typedef void* CLeglDisplayKHR; - -/* properties passed to clCreateFromEGLImageKHR */ -typedef intptr_t cl_egl_image_properties_khr; - - -#define cl_khr_egl_image 1 - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromEGLImageKHR(cl_context /* context */, - CLeglDisplayKHR /* egldisplay */, - CLeglImageKHR /* eglimage */, - cl_mem_flags /* flags */, - const cl_egl_image_properties_khr * /* properties */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_mem (CL_API_CALL *clCreateFromEGLImageKHR_fn)( - cl_context context, - CLeglDisplayKHR egldisplay, - CLeglImageKHR eglimage, - cl_mem_flags flags, - const cl_egl_image_properties_khr * properties, - cl_int * errcode_ret); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireEGLObjectsKHR(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueAcquireEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseEGLObjectsKHR(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clEnqueueReleaseEGLObjectsKHR_fn)( - cl_command_queue command_queue, - cl_uint num_objects, - const cl_mem * mem_objects, - cl_uint num_events_in_wait_list, - const cl_event * event_wait_list, - cl_event * event); - - -#define cl_khr_egl_event 1 - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromEGLSyncKHR(cl_context /* context */, - EGLSyncKHR /* sync */, - EGLDisplay /* display */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_event (CL_API_CALL *clCreateEventFromEGLSyncKHR_fn)( - cl_context context, - EGLSyncKHR sync, - EGLDisplay display, - cl_int * errcode_ret); - - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_EGL_H */ diff --git a/3rdparty/bx/3rdparty/CL/cl_ext.h b/3rdparty/bx/3rdparty/CL/cl_ext.h deleted file mode 100644 index 6908b7ed6b5..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_ext.h +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2013 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11928 $ on $Date: 2010-07-13 09:04:56 -0700 (Tue, 13 Jul 2010) $ */ - -/* cl_ext.h contains OpenCL extensions which don't have external */ -/* (OpenGL, D3D) dependencies. */ - -#ifndef __CL_EXT_H -#define __CL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include <OpenCL/cl.h> - #include <AvailabilityMacros.h> -#else - #include <CL/cl.h> -#endif - -/* cl_khr_fp16 extension - no extension #define since it has no functions */ -#define CL_DEVICE_HALF_FP_CONFIG 0x1033 - -/* Memory object destruction - * - * Apple extension for use to manage externally allocated buffers used with cl_mem objects with CL_MEM_USE_HOST_PTR - * - * Registers a user callback function that will be called when the memory object is deleted and its resources - * freed. Each call to clSetMemObjectCallbackFn registers the specified user callback function on a callback - * stack associated with memobj. The registered user callback functions are called in the reverse order in - * which they were registered. The user callback functions are called and then the memory object is deleted - * and its resources freed. This provides a mechanism for the application (and libraries) using memobj to be - * notified when the memory referenced by host_ptr, specified when the memory object is created and used as - * the storage bits for the memory object, can be reused or freed. - * - * The application may not call CL api's with the cl_mem object passed to the pfn_notify. - * - * Please check for the "cl_APPLE_SetMemObjectDestructor" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - */ -#define cl_APPLE_SetMemObjectDestructor 1 -cl_int CL_API_ENTRY clSetMemObjectDestructorAPPLE( cl_mem /* memobj */, - void (* /*pfn_notify*/)( cl_mem /* memobj */, void* /*user_data*/), - void * /*user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/* Context Logging Functions - * - * The next three convenience functions are intended to be used as the pfn_notify parameter to clCreateContext(). - * Please check for the "cl_APPLE_ContextLoggingFunctions" extension using clGetDeviceInfo(CL_DEVICE_EXTENSIONS) - * before using. - * - * clLogMessagesToSystemLog fowards on all log messages to the Apple System Logger - */ -#define cl_APPLE_ContextLoggingFunctions 1 -extern void CL_API_ENTRY clLogMessagesToSystemLogAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStdout sends all log messages to the file descriptor stdout */ -extern void CL_API_ENTRY clLogMessagesToStdoutAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - -/* clLogMessagesToStderr sends all log messages to the file descriptor stderr */ -extern void CL_API_ENTRY clLogMessagesToStderrAPPLE( const char * /* errstr */, - const void * /* private_info */, - size_t /* cb */, - void * /* user_data */ ) CL_EXT_SUFFIX__VERSION_1_0; - - -/************************ -* cl_khr_icd extension * -************************/ -#define cl_khr_icd 1 - -/* cl_platform_info */ -#define CL_PLATFORM_ICD_SUFFIX_KHR 0x0920 - -/* Additional Error Codes */ -#define CL_PLATFORM_NOT_FOUND_KHR -1001 - -extern CL_API_ENTRY cl_int CL_API_CALL -clIcdGetPlatformIDsKHR(cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clIcdGetPlatformIDsKHR_fn)( - cl_uint /* num_entries */, - cl_platform_id * /* platforms */, - cl_uint * /* num_platforms */); - - -/* Extension: cl_khr_image2D_buffer - * - * This extension allows a 2D image to be created from a cl_mem buffer without a copy. - * The type associated with a 2D image created from a buffer in an OpenCL program is image2d_t. - * Both the sampler and sampler-less read_image built-in functions are supported for 2D images - * and 2D images created from a buffer. Similarly, the write_image built-ins are also supported - * for 2D images created from a buffer. - * - * When the 2D image from buffer is created, the client must specify the width, - * height, image format (i.e. channel order and channel data type) and optionally the row pitch - * - * The pitch specified must be a multiple of CL_DEVICE_IMAGE_PITCH_ALIGNMENT pixels. - * The base address of the buffer must be aligned to CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT pixels. - */ - -/************************************* - * cl_khr_initalize_memory extension * - *************************************/ - -#define CL_CONTEXT_MEMORY_INITIALIZE_KHR 0x200E - - -/************************************** - * cl_khr_terminate_context extension * - **************************************/ - -#define CL_DEVICE_TERMINATE_CAPABILITY_KHR 0x200F -#define CL_CONTEXT_TERMINATE_KHR 0x2010 - -#define cl_khr_terminate_context 1 -extern CL_API_ENTRY cl_int CL_API_CALL clTerminateContextKHR(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clTerminateContextKHR_fn)(cl_context /* context */) CL_EXT_SUFFIX__VERSION_1_2; - - -/* - * Extension: cl_khr_spir - * - * This extension adds support to create an OpenCL program object from a - * Standard Portable Intermediate Representation (SPIR) instance - */ - -/****************************************** -* cl_nv_device_attribute_query extension * -******************************************/ -/* cl_nv_device_attribute_query extension - no extension #define since it has no functions */ -#define CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV 0x4000 -#define CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV 0x4001 -#define CL_DEVICE_REGISTERS_PER_BLOCK_NV 0x4002 -#define CL_DEVICE_WARP_SIZE_NV 0x4003 -#define CL_DEVICE_GPU_OVERLAP_NV 0x4004 -#define CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV 0x4005 -#define CL_DEVICE_INTEGRATED_MEMORY_NV 0x4006 - -/********************************* -* cl_amd_device_attribute_query * -*********************************/ -#define CL_DEVICE_PROFILING_TIMER_OFFSET_AMD 0x4036 - -#ifdef CL_VERSION_1_1 - /*********************************** - * cl_ext_device_fission extension * - ***********************************/ - #define cl_ext_device_fission 1 - - extern CL_API_ENTRY cl_int CL_API_CALL - clReleaseDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clReleaseDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - extern CL_API_ENTRY cl_int CL_API_CALL - clRetainDeviceEXT( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - (CL_API_CALL *clRetainDeviceEXT_fn)( cl_device_id /*device*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef cl_ulong cl_device_partition_property_ext; - extern CL_API_ENTRY cl_int CL_API_CALL - clCreateSubDevicesEXT( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - typedef CL_API_ENTRY cl_int - ( CL_API_CALL * clCreateSubDevicesEXT_fn)( cl_device_id /*in_device*/, - const cl_device_partition_property_ext * /* properties */, - cl_uint /*num_entries*/, - cl_device_id * /*out_devices*/, - cl_uint * /*num_devices*/ ) CL_EXT_SUFFIX__VERSION_1_1; - - /* cl_device_partition_property_ext */ - #define CL_DEVICE_PARTITION_EQUALLY_EXT 0x4050 - #define CL_DEVICE_PARTITION_BY_COUNTS_EXT 0x4051 - #define CL_DEVICE_PARTITION_BY_NAMES_EXT 0x4052 - #define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN_EXT 0x4053 - - /* clDeviceGetInfo selectors */ - #define CL_DEVICE_PARENT_DEVICE_EXT 0x4054 - #define CL_DEVICE_PARTITION_TYPES_EXT 0x4055 - #define CL_DEVICE_AFFINITY_DOMAINS_EXT 0x4056 - #define CL_DEVICE_REFERENCE_COUNT_EXT 0x4057 - #define CL_DEVICE_PARTITION_STYLE_EXT 0x4058 - - /* error codes */ - #define CL_DEVICE_PARTITION_FAILED_EXT -1057 - #define CL_INVALID_PARTITION_COUNT_EXT -1058 - #define CL_INVALID_PARTITION_NAME_EXT -1059 - - /* CL_AFFINITY_DOMAINs */ - #define CL_AFFINITY_DOMAIN_L1_CACHE_EXT 0x1 - #define CL_AFFINITY_DOMAIN_L2_CACHE_EXT 0x2 - #define CL_AFFINITY_DOMAIN_L3_CACHE_EXT 0x3 - #define CL_AFFINITY_DOMAIN_L4_CACHE_EXT 0x4 - #define CL_AFFINITY_DOMAIN_NUMA_EXT 0x10 - #define CL_AFFINITY_DOMAIN_NEXT_FISSIONABLE_EXT 0x100 - - /* cl_device_partition_property_ext list terminators */ - #define CL_PROPERTIES_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_COUNTS_LIST_END_EXT ((cl_device_partition_property_ext) 0) - #define CL_PARTITION_BY_NAMES_LIST_END_EXT ((cl_device_partition_property_ext) 0 - 1) - -/********************************* -* cl_qcom_ext_host_ptr extension -*********************************/ - -#define CL_MEM_EXT_HOST_PTR_QCOM (1 << 29) - -#define CL_DEVICE_EXT_MEM_PADDING_IN_BYTES_QCOM 0x40A0 -#define CL_DEVICE_PAGE_SIZE_QCOM 0x40A1 -#define CL_IMAGE_ROW_ALIGNMENT_QCOM 0x40A2 -#define CL_IMAGE_SLICE_ALIGNMENT_QCOM 0x40A3 -#define CL_MEM_HOST_UNCACHED_QCOM 0x40A4 -#define CL_MEM_HOST_WRITEBACK_QCOM 0x40A5 -#define CL_MEM_HOST_WRITETHROUGH_QCOM 0x40A6 -#define CL_MEM_HOST_WRITE_COMBINING_QCOM 0x40A7 - -typedef cl_uint cl_image_pitch_info_qcom; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetDeviceImageInfoQCOM(cl_device_id device, - size_t image_width, - size_t image_height, - const cl_image_format *image_format, - cl_image_pitch_info_qcom param_name, - size_t param_value_size, - void *param_value, - size_t *param_value_size_ret); - -typedef struct _cl_mem_ext_host_ptr -{ - // Type of external memory allocation. - // Legal values will be defined in layered extensions. - cl_uint allocation_type; - - // Host cache policy for this external memory allocation. - cl_uint host_cache_policy; - -} cl_mem_ext_host_ptr; - -/********************************* -* cl_qcom_ion_host_ptr extension -*********************************/ - -#define CL_MEM_ION_HOST_PTR_QCOM 0x40A8 - -typedef struct _cl_mem_ion_host_ptr -{ - // Type of external memory allocation. - // Must be CL_MEM_ION_HOST_PTR_QCOM for ION allocations. - cl_mem_ext_host_ptr ext_host_ptr; - - // ION file descriptor - int ion_filedesc; - - // Host pointer to the ION allocated memory - void* ion_hostptr; - -} cl_mem_ion_host_ptr; - -#endif /* CL_VERSION_1_1 */ - -#ifdef __cplusplus -} -#endif - - -#endif /* __CL_EXT_H */ diff --git a/3rdparty/bx/3rdparty/CL/cl_gl.h b/3rdparty/bx/3rdparty/CL/cl_gl.h deleted file mode 100644 index af2036cc997..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_gl.h +++ /dev/null @@ -1,162 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -#ifndef __OPENCL_CL_GL_H -#define __OPENCL_CL_GL_H - -#ifdef __APPLE__ -#include <OpenCL/cl.h> -#else -#include <CL/cl.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -typedef cl_uint cl_gl_object_type; -typedef cl_uint cl_gl_texture_info; -typedef cl_uint cl_gl_platform_info; -typedef struct __GLsync *cl_GLsync; - -/* cl_gl_object_type = 0x2000 - 0x200F enum values are currently taken */ -#define CL_GL_OBJECT_BUFFER 0x2000 -#define CL_GL_OBJECT_TEXTURE2D 0x2001 -#define CL_GL_OBJECT_TEXTURE3D 0x2002 -#define CL_GL_OBJECT_RENDERBUFFER 0x2003 -#define CL_GL_OBJECT_TEXTURE2D_ARRAY 0x200E -#define CL_GL_OBJECT_TEXTURE1D 0x200F -#define CL_GL_OBJECT_TEXTURE1D_ARRAY 0x2010 -#define CL_GL_OBJECT_TEXTURE_BUFFER 0x2011 - -/* cl_gl_texture_info */ -#define CL_GL_TEXTURE_TARGET 0x2004 -#define CL_GL_MIPMAP_LEVEL 0x2005 -#define CL_GL_NUM_SAMPLES 0x2012 - - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLBuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* bufobj */, - int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLTexture(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_2; - -extern CL_API_ENTRY cl_mem CL_API_CALL -clCreateFromGLRenderbuffer(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLuint /* renderbuffer */, - cl_int * /* errcode_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLObjectInfo(cl_mem /* memobj */, - cl_gl_object_type * /* gl_object_type */, - cl_GLuint * /* gl_object_name */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLTextureInfo(cl_mem /* memobj */, - cl_gl_texture_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueAcquireGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - -extern CL_API_ENTRY cl_int CL_API_CALL -clEnqueueReleaseGLObjects(cl_command_queue /* command_queue */, - cl_uint /* num_objects */, - const cl_mem * /* mem_objects */, - cl_uint /* num_events_in_wait_list */, - const cl_event * /* event_wait_list */, - cl_event * /* event */) CL_API_SUFFIX__VERSION_1_0; - - -// Deprecated OpenCL 1.1 APIs -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture2D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -extern CL_API_ENTRY CL_EXT_PREFIX__VERSION_1_1_DEPRECATED cl_mem CL_API_CALL -clCreateFromGLTexture3D(cl_context /* context */, - cl_mem_flags /* flags */, - cl_GLenum /* target */, - cl_GLint /* miplevel */, - cl_GLuint /* texture */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED; - -/* cl_khr_gl_sharing extension */ - -#define cl_khr_gl_sharing 1 - -typedef cl_uint cl_gl_context_info; - -/* Additional Error Codes */ -#define CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR -1000 - -/* cl_gl_context_info */ -#define CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR 0x2006 -#define CL_DEVICES_FOR_GL_CONTEXT_KHR 0x2007 - -/* Additional cl_context_properties */ -#define CL_GL_CONTEXT_KHR 0x2008 -#define CL_EGL_DISPLAY_KHR 0x2009 -#define CL_GLX_DISPLAY_KHR 0x200A -#define CL_WGL_HDC_KHR 0x200B -#define CL_CGL_SHAREGROUP_KHR 0x200C - -extern CL_API_ENTRY cl_int CL_API_CALL -clGetGLContextInfoKHR(const cl_context_properties * /* properties */, - cl_gl_context_info /* param_name */, - size_t /* param_value_size */, - void * /* param_value */, - size_t * /* param_value_size_ret */) CL_API_SUFFIX__VERSION_1_0; - -typedef CL_API_ENTRY cl_int (CL_API_CALL *clGetGLContextInfoKHR_fn)( - const cl_context_properties * properties, - cl_gl_context_info param_name, - size_t param_value_size, - void * param_value, - size_t * param_value_size_ret); - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_H */ diff --git a/3rdparty/bx/3rdparty/CL/cl_gl_ext.h b/3rdparty/bx/3rdparty/CL/cl_gl_ext.h deleted file mode 100644 index 77d53536f62..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_gl_ext.h +++ /dev/null @@ -1,69 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -/* cl_gl_ext.h contains vendor (non-KHR) OpenCL extensions which have */ -/* OpenGL dependencies. */ - -#ifndef __OPENCL_CL_GL_EXT_H -#define __OPENCL_CL_GL_EXT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - #include <OpenCL/cl_gl.h> -#else - #include <CL/cl_gl.h> -#endif - -/* - * For each extension, follow this template - * cl_VEN_extname extension */ -/* #define cl_VEN_extname 1 - * ... define new types, if any - * ... define new tokens, if any - * ... define new APIs, if any - * - * If you need GLtypes here, mirror them with a cl_GLtype, rather than including a GL header - * This allows us to avoid having to decide whether to include GL headers or GLES here. - */ - -/* - * cl_khr_gl_event extension - * See section 9.9 in the OpenCL 1.1 spec for more information - */ -#define CL_COMMAND_GL_FENCE_SYNC_OBJECT_KHR 0x200D - -extern CL_API_ENTRY cl_event CL_API_CALL -clCreateEventFromGLsyncKHR(cl_context /* context */, - cl_GLsync /* cl_GLsync */, - cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1; - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_CL_GL_EXT_H */ diff --git a/3rdparty/bx/3rdparty/CL/cl_platform.h b/3rdparty/bx/3rdparty/CL/cl_platform.h deleted file mode 100644 index cf7b2542d2c..00000000000 --- a/3rdparty/bx/3rdparty/CL/cl_platform.h +++ /dev/null @@ -1,1254 +0,0 @@ -/********************************************************************************** - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - **********************************************************************************/ - -/* $Revision: 11803 $ on $Date: 2010-06-25 10:02:12 -0700 (Fri, 25 Jun 2010) $ */ - -#ifndef __CL_PLATFORM_H -#define __CL_PLATFORM_H - -#ifdef __APPLE__ - /* Contains #defines for AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER below */ - #include <AvailabilityMacros.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_WIN32) - #define CL_API_ENTRY - #define CL_API_CALL __stdcall - #define CL_CALLBACK __stdcall -#else - #define CL_API_ENTRY - #define CL_API_CALL - #define CL_CALLBACK -#endif - -#ifdef __APPLE__ - #define CL_EXTENSION_WEAK_LINK __attribute__((weak_import)) - #define CL_API_SUFFIX__VERSION_1_0 AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER - #define CL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_1 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_7 - - #ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_8 - #else - #warning This path should never happen outside of internal operating system development. AvailabilityMacros do not function correctly here! - #define CL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define GCL_API_SUFFIX__VERSION_1_2 AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_2 CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED CL_EXTENSION_WEAK_LINK AVAILABLE_MAC_OS_X_VERSION_10_7_AND_LATER - #endif -#else - #define CL_EXTENSION_WEAK_LINK - #define CL_API_SUFFIX__VERSION_1_0 - #define CL_EXT_SUFFIX__VERSION_1_0 - #define CL_API_SUFFIX__VERSION_1_1 - #define CL_EXT_SUFFIX__VERSION_1_1 - #define CL_API_SUFFIX__VERSION_1_2 - #define CL_EXT_SUFFIX__VERSION_1_2 - - #ifdef __GNUC__ - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED __attribute__((deprecated)) - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif - #elif defined(_WIN32) - #ifdef CL_USE_DEPRECATED_OPENCL_1_0_APIS - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED __declspec(deprecated) - #endif - - #ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #else - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED __declspec(deprecated) - #endif - #else - #define CL_EXT_SUFFIX__VERSION_1_0_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_0_DEPRECATED - - #define CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED - #define CL_EXT_PREFIX__VERSION_1_1_DEPRECATED - #endif -#endif - -#if (defined (_WIN32) && defined(_MSC_VER)) - -/* scalar types */ -typedef signed __int8 cl_char; -typedef unsigned __int8 cl_uchar; -typedef signed __int16 cl_short; -typedef unsigned __int16 cl_ushort; -typedef signed __int32 cl_int; -typedef unsigned __int32 cl_uint; -typedef signed __int64 cl_long; -typedef unsigned __int64 cl_ulong; - -typedef unsigned __int16 cl_half; -typedef float cl_float; -typedef double cl_double; - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 340282346638528859811704183484516925440.0f -#define CL_FLT_MIN 1.175494350822287507969e-38f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.0 -#define CL_DBL_MIN 2.225073858507201383090e-308 -#define CL_DBL_EPSILON 2.220446049250313080847e-16 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#define CL_NAN (CL_INFINITY - CL_INFINITY) -#define CL_HUGE_VALF ((cl_float) 1e50) -#define CL_HUGE_VAL ((cl_double) 1e500) -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#else - -#include <stdint.h> - -/* scalar types */ -typedef int8_t cl_char; -typedef uint8_t cl_uchar; -typedef int16_t cl_short __attribute__((aligned(2))); -typedef uint16_t cl_ushort __attribute__((aligned(2))); -typedef int32_t cl_int __attribute__((aligned(4))); -typedef uint32_t cl_uint __attribute__((aligned(4))); -typedef int64_t cl_long __attribute__((aligned(8))); -typedef uint64_t cl_ulong __attribute__((aligned(8))); - -typedef uint16_t cl_half __attribute__((aligned(2))); -typedef float cl_float __attribute__((aligned(4))); -typedef double cl_double __attribute__((aligned(8))); - -/* Macro names and corresponding values defined by OpenCL */ -#define CL_CHAR_BIT 8 -#define CL_SCHAR_MAX 127 -#define CL_SCHAR_MIN (-127-1) -#define CL_CHAR_MAX CL_SCHAR_MAX -#define CL_CHAR_MIN CL_SCHAR_MIN -#define CL_UCHAR_MAX 255 -#define CL_SHRT_MAX 32767 -#define CL_SHRT_MIN (-32767-1) -#define CL_USHRT_MAX 65535 -#define CL_INT_MAX 2147483647 -#define CL_INT_MIN (-2147483647-1) -#define CL_UINT_MAX 0xffffffffU -#define CL_LONG_MAX ((cl_long) 0x7FFFFFFFFFFFFFFFLL) -#define CL_LONG_MIN ((cl_long) -0x7FFFFFFFFFFFFFFFLL - 1LL) -#define CL_ULONG_MAX ((cl_ulong) 0xFFFFFFFFFFFFFFFFULL) - -#define CL_FLT_DIG 6 -#define CL_FLT_MANT_DIG 24 -#define CL_FLT_MAX_10_EXP +38 -#define CL_FLT_MAX_EXP +128 -#define CL_FLT_MIN_10_EXP -37 -#define CL_FLT_MIN_EXP -125 -#define CL_FLT_RADIX 2 -#define CL_FLT_MAX 0x1.fffffep127f -#define CL_FLT_MIN 0x1.0p-126f -#define CL_FLT_EPSILON 0x1.0p-23f - -#define CL_DBL_DIG 15 -#define CL_DBL_MANT_DIG 53 -#define CL_DBL_MAX_10_EXP +308 -#define CL_DBL_MAX_EXP +1024 -#define CL_DBL_MIN_10_EXP -307 -#define CL_DBL_MIN_EXP -1021 -#define CL_DBL_RADIX 2 -#define CL_DBL_MAX 0x1.fffffffffffffp1023 -#define CL_DBL_MIN 0x1.0p-1022 -#define CL_DBL_EPSILON 0x1.0p-52 - -#define CL_M_E 2.718281828459045090796 -#define CL_M_LOG2E 1.442695040888963387005 -#define CL_M_LOG10E 0.434294481903251816668 -#define CL_M_LN2 0.693147180559945286227 -#define CL_M_LN10 2.302585092994045901094 -#define CL_M_PI 3.141592653589793115998 -#define CL_M_PI_2 1.570796326794896557999 -#define CL_M_PI_4 0.785398163397448278999 -#define CL_M_1_PI 0.318309886183790691216 -#define CL_M_2_PI 0.636619772367581382433 -#define CL_M_2_SQRTPI 1.128379167095512558561 -#define CL_M_SQRT2 1.414213562373095145475 -#define CL_M_SQRT1_2 0.707106781186547572737 - -#define CL_M_E_F 2.71828174591064f -#define CL_M_LOG2E_F 1.44269502162933f -#define CL_M_LOG10E_F 0.43429449200630f -#define CL_M_LN2_F 0.69314718246460f -#define CL_M_LN10_F 2.30258512496948f -#define CL_M_PI_F 3.14159274101257f -#define CL_M_PI_2_F 1.57079637050629f -#define CL_M_PI_4_F 0.78539818525314f -#define CL_M_1_PI_F 0.31830987334251f -#define CL_M_2_PI_F 0.63661974668503f -#define CL_M_2_SQRTPI_F 1.12837922573090f -#define CL_M_SQRT2_F 1.41421353816986f -#define CL_M_SQRT1_2_F 0.70710676908493f - -#if defined( __GNUC__ ) - #define CL_HUGE_VALF __builtin_huge_valf() - #define CL_HUGE_VAL __builtin_huge_val() - #define CL_NAN __builtin_nanf( "" ) -#else - #define CL_HUGE_VALF ((cl_float) 1e50) - #define CL_HUGE_VAL ((cl_double) 1e500) - float nanf( const char * ); - #define CL_NAN nanf( "" ) -#endif -#define CL_MAXFLOAT CL_FLT_MAX -#define CL_INFINITY CL_HUGE_VALF - -#endif - -#include <stddef.h> - -/* Mirror types to GL types. Mirror types allow us to avoid deciding which 87s to load based on whether we are using GL or GLES here. */ -typedef unsigned int cl_GLuint; -typedef int cl_GLint; -typedef unsigned int cl_GLenum; - -/* - * Vector types - * - * Note: OpenCL requires that all types be naturally aligned. - * This means that vector types must be naturally aligned. - * For example, a vector of four floats must be aligned to - * a 16 byte boundary (calculated as 4 * the natural 4-byte - * alignment of the float). The alignment qualifiers here - * will only function properly if your compiler supports them - * and if you don't actively work to defeat them. For example, - * in order for a cl_float4 to be 16 byte aligned in a struct, - * the start of the struct must itself be 16-byte aligned. - * - * Maintaining proper alignment is the user's responsibility. - */ - -/* Define basic vector types */ -#if defined( __VEC__ ) - #include <altivec.h> /* may be omitted depending on compiler. AltiVec spec provides no way to detect whether the header is required. */ - typedef vector unsigned char __cl_uchar16; - typedef vector signed char __cl_char16; - typedef vector unsigned short __cl_ushort8; - typedef vector signed short __cl_short8; - typedef vector unsigned int __cl_uint4; - typedef vector signed int __cl_int4; - typedef vector float __cl_float4; - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_UINT4__ 1 - #define __CL_INT4__ 1 - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE__ ) - #if defined( __MINGW64__ ) - #include <intrin.h> - #else - #include <xmmintrin.h> - #endif - #if defined( __GNUC__ ) - typedef float __cl_float4 __attribute__((vector_size(16))); - #else - typedef __m128 __cl_float4; - #endif - #define __CL_FLOAT4__ 1 -#endif - -#if defined( __SSE2__ ) - #if defined( __MINGW64__ ) - #include <intrin.h> - #else - #include <emmintrin.h> - #endif - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar16 __attribute__((vector_size(16))); - typedef cl_char __cl_char16 __attribute__((vector_size(16))); - typedef cl_ushort __cl_ushort8 __attribute__((vector_size(16))); - typedef cl_short __cl_short8 __attribute__((vector_size(16))); - typedef cl_uint __cl_uint4 __attribute__((vector_size(16))); - typedef cl_int __cl_int4 __attribute__((vector_size(16))); - typedef cl_ulong __cl_ulong2 __attribute__((vector_size(16))); - typedef cl_long __cl_long2 __attribute__((vector_size(16))); - typedef cl_double __cl_double2 __attribute__((vector_size(16))); - #else - typedef __m128i __cl_uchar16; - typedef __m128i __cl_char16; - typedef __m128i __cl_ushort8; - typedef __m128i __cl_short8; - typedef __m128i __cl_uint4; - typedef __m128i __cl_int4; - typedef __m128i __cl_ulong2; - typedef __m128i __cl_long2; - typedef __m128d __cl_double2; - #endif - #define __CL_UCHAR16__ 1 - #define __CL_CHAR16__ 1 - #define __CL_USHORT8__ 1 - #define __CL_SHORT8__ 1 - #define __CL_INT4__ 1 - #define __CL_UINT4__ 1 - #define __CL_ULONG2__ 1 - #define __CL_LONG2__ 1 - #define __CL_DOUBLE2__ 1 -#endif - -#if defined( __MMX__ ) - #include <mmintrin.h> - #if defined( __GNUC__ ) - typedef cl_uchar __cl_uchar8 __attribute__((vector_size(8))); - typedef cl_char __cl_char8 __attribute__((vector_size(8))); - typedef cl_ushort __cl_ushort4 __attribute__((vector_size(8))); - typedef cl_short __cl_short4 __attribute__((vector_size(8))); - typedef cl_uint __cl_uint2 __attribute__((vector_size(8))); - typedef cl_int __cl_int2 __attribute__((vector_size(8))); - typedef cl_ulong __cl_ulong1 __attribute__((vector_size(8))); - typedef cl_long __cl_long1 __attribute__((vector_size(8))); - typedef cl_float __cl_float2 __attribute__((vector_size(8))); - #else - typedef __m64 __cl_uchar8; - typedef __m64 __cl_char8; - typedef __m64 __cl_ushort4; - typedef __m64 __cl_short4; - typedef __m64 __cl_uint2; - typedef __m64 __cl_int2; - typedef __m64 __cl_ulong1; - typedef __m64 __cl_long1; - typedef __m64 __cl_float2; - #endif - #define __CL_UCHAR8__ 1 - #define __CL_CHAR8__ 1 - #define __CL_USHORT4__ 1 - #define __CL_SHORT4__ 1 - #define __CL_INT2__ 1 - #define __CL_UINT2__ 1 - #define __CL_ULONG1__ 1 - #define __CL_LONG1__ 1 - #define __CL_FLOAT2__ 1 -#endif - -#if defined( __AVX__ ) - #if defined( __MINGW64__ ) - #include <intrin.h> - #else - #include <immintrin.h> - #endif - #if defined( __GNUC__ ) - typedef cl_float __cl_float8 __attribute__((vector_size(32))); - typedef cl_double __cl_double4 __attribute__((vector_size(32))); - #else - typedef __m256 __cl_float8; - typedef __m256d __cl_double4; - #endif - #define __CL_FLOAT8__ 1 - #define __CL_DOUBLE4__ 1 -#endif - -/* Define alignment keys */ -#if defined( __GNUC__ ) - #define CL_ALIGNED(_x) __attribute__ ((aligned(_x))) -#elif defined( _WIN32 ) && defined( _MSC_VER ) - /* Alignment keys neutered on windows because MSVC can't swallow function arguments with alignment requirements */ - /* http://msdn.microsoft.com/en-us/library/373ak2y1%28VS.71%29.aspx */ - /* #include <crtdefs.h> */ - /* #define CL_ALIGNED(_x) _CRT_ALIGN(_x) */ - #define CL_ALIGNED(_x) -#else - #warning Need to implement some method to align data here - #define CL_ALIGNED(_x) -#endif - -/* Indicate whether .xyzw, .s0123 and .hi.lo are supported */ -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - /* .xyzw and .s0123...{f|F} are supported */ - #define CL_HAS_NAMED_VECTOR_FIELDS 1 - /* .hi and .lo are supported */ - #define CL_HAS_HI_LO_VECTOR_FIELDS 1 -#endif - -/* Define cl_vector types */ - -/* ---- cl_charn ---- */ -typedef union -{ - cl_char CL_ALIGNED(2) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y; }; - __extension__ struct{ cl_char s0, s1; }; - __extension__ struct{ cl_char lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2; -#endif -}cl_char2; - -typedef union -{ - cl_char CL_ALIGNED(4) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3; }; - __extension__ struct{ cl_char2 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[2]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4; -#endif -}cl_char4; - -/* cl_char3 is identical in size, alignment and behavior to cl_char4. See section 6.1.5. */ -typedef cl_char4 cl_char3; - -typedef union -{ - cl_char CL_ALIGNED(8) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_char4 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[4]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[2]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8; -#endif -}cl_char8; - -typedef union -{ - cl_char CL_ALIGNED(16) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_char x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_char s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_char8 lo, hi; }; -#endif -#if defined( __CL_CHAR2__) - __cl_char2 v2[8]; -#endif -#if defined( __CL_CHAR4__) - __cl_char4 v4[4]; -#endif -#if defined( __CL_CHAR8__ ) - __cl_char8 v8[2]; -#endif -#if defined( __CL_CHAR16__ ) - __cl_char16 v16; -#endif -}cl_char16; - - -/* ---- cl_ucharn ---- */ -typedef union -{ - cl_uchar CL_ALIGNED(2) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y; }; - __extension__ struct{ cl_uchar s0, s1; }; - __extension__ struct{ cl_uchar lo, hi; }; -#endif -#if defined( __cl_uchar2__) - __cl_uchar2 v2; -#endif -}cl_uchar2; - -typedef union -{ - cl_uchar CL_ALIGNED(4) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3; }; - __extension__ struct{ cl_uchar2 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[2]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4; -#endif -}cl_uchar4; - -/* cl_uchar3 is identical in size, alignment and behavior to cl_uchar4. See section 6.1.5. */ -typedef cl_uchar4 cl_uchar3; - -typedef union -{ - cl_uchar CL_ALIGNED(8) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uchar4 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[4]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[2]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8; -#endif -}cl_uchar8; - -typedef union -{ - cl_uchar CL_ALIGNED(16) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uchar x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uchar s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uchar8 lo, hi; }; -#endif -#if defined( __CL_UCHAR2__) - __cl_uchar2 v2[8]; -#endif -#if defined( __CL_UCHAR4__) - __cl_uchar4 v4[4]; -#endif -#if defined( __CL_UCHAR8__ ) - __cl_uchar8 v8[2]; -#endif -#if defined( __CL_UCHAR16__ ) - __cl_uchar16 v16; -#endif -}cl_uchar16; - - -/* ---- cl_shortn ---- */ -typedef union -{ - cl_short CL_ALIGNED(4) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y; }; - __extension__ struct{ cl_short s0, s1; }; - __extension__ struct{ cl_short lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2; -#endif -}cl_short2; - -typedef union -{ - cl_short CL_ALIGNED(8) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3; }; - __extension__ struct{ cl_short2 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[2]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4; -#endif -}cl_short4; - -/* cl_short3 is identical in size, alignment and behavior to cl_short4. See section 6.1.5. */ -typedef cl_short4 cl_short3; - -typedef union -{ - cl_short CL_ALIGNED(16) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_short4 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[4]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[2]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8; -#endif -}cl_short8; - -typedef union -{ - cl_short CL_ALIGNED(32) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_short x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_short s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_short8 lo, hi; }; -#endif -#if defined( __CL_SHORT2__) - __cl_short2 v2[8]; -#endif -#if defined( __CL_SHORT4__) - __cl_short4 v4[4]; -#endif -#if defined( __CL_SHORT8__ ) - __cl_short8 v8[2]; -#endif -#if defined( __CL_SHORT16__ ) - __cl_short16 v16; -#endif -}cl_short16; - - -/* ---- cl_ushortn ---- */ -typedef union -{ - cl_ushort CL_ALIGNED(4) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y; }; - __extension__ struct{ cl_ushort s0, s1; }; - __extension__ struct{ cl_ushort lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2; -#endif -}cl_ushort2; - -typedef union -{ - cl_ushort CL_ALIGNED(8) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3; }; - __extension__ struct{ cl_ushort2 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[2]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4; -#endif -}cl_ushort4; - -/* cl_ushort3 is identical in size, alignment and behavior to cl_ushort4. See section 6.1.5. */ -typedef cl_ushort4 cl_ushort3; - -typedef union -{ - cl_ushort CL_ALIGNED(16) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ushort4 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[4]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[2]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8; -#endif -}cl_ushort8; - -typedef union -{ - cl_ushort CL_ALIGNED(32) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ushort x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ushort s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ushort8 lo, hi; }; -#endif -#if defined( __CL_USHORT2__) - __cl_ushort2 v2[8]; -#endif -#if defined( __CL_USHORT4__) - __cl_ushort4 v4[4]; -#endif -#if defined( __CL_USHORT8__ ) - __cl_ushort8 v8[2]; -#endif -#if defined( __CL_USHORT16__ ) - __cl_ushort16 v16; -#endif -}cl_ushort16; - -/* ---- cl_intn ---- */ -typedef union -{ - cl_int CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y; }; - __extension__ struct{ cl_int s0, s1; }; - __extension__ struct{ cl_int lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2; -#endif -}cl_int2; - -typedef union -{ - cl_int CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3; }; - __extension__ struct{ cl_int2 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[2]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4; -#endif -}cl_int4; - -/* cl_int3 is identical in size, alignment and behavior to cl_int4. See section 6.1.5. */ -typedef cl_int4 cl_int3; - -typedef union -{ - cl_int CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_int4 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[4]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[2]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8; -#endif -}cl_int8; - -typedef union -{ - cl_int CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_int x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_int8 lo, hi; }; -#endif -#if defined( __CL_INT2__) - __cl_int2 v2[8]; -#endif -#if defined( __CL_INT4__) - __cl_int4 v4[4]; -#endif -#if defined( __CL_INT8__ ) - __cl_int8 v8[2]; -#endif -#if defined( __CL_INT16__ ) - __cl_int16 v16; -#endif -}cl_int16; - - -/* ---- cl_uintn ---- */ -typedef union -{ - cl_uint CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y; }; - __extension__ struct{ cl_uint s0, s1; }; - __extension__ struct{ cl_uint lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2; -#endif -}cl_uint2; - -typedef union -{ - cl_uint CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3; }; - __extension__ struct{ cl_uint2 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[2]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4; -#endif -}cl_uint4; - -/* cl_uint3 is identical in size, alignment and behavior to cl_uint4. See section 6.1.5. */ -typedef cl_uint4 cl_uint3; - -typedef union -{ - cl_uint CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_uint4 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[4]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[2]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8; -#endif -}cl_uint8; - -typedef union -{ - cl_uint CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_uint x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_uint s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_uint8 lo, hi; }; -#endif -#if defined( __CL_UINT2__) - __cl_uint2 v2[8]; -#endif -#if defined( __CL_UINT4__) - __cl_uint4 v4[4]; -#endif -#if defined( __CL_UINT8__ ) - __cl_uint8 v8[2]; -#endif -#if defined( __CL_UINT16__ ) - __cl_uint16 v16; -#endif -}cl_uint16; - -/* ---- cl_longn ---- */ -typedef union -{ - cl_long CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y; }; - __extension__ struct{ cl_long s0, s1; }; - __extension__ struct{ cl_long lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2; -#endif -}cl_long2; - -typedef union -{ - cl_long CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3; }; - __extension__ struct{ cl_long2 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[2]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4; -#endif -}cl_long4; - -/* cl_long3 is identical in size, alignment and behavior to cl_long4. See section 6.1.5. */ -typedef cl_long4 cl_long3; - -typedef union -{ - cl_long CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_long4 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[4]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[2]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8; -#endif -}cl_long8; - -typedef union -{ - cl_long CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_long x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_long s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_long8 lo, hi; }; -#endif -#if defined( __CL_LONG2__) - __cl_long2 v2[8]; -#endif -#if defined( __CL_LONG4__) - __cl_long4 v4[4]; -#endif -#if defined( __CL_LONG8__ ) - __cl_long8 v8[2]; -#endif -#if defined( __CL_LONG16__ ) - __cl_long16 v16; -#endif -}cl_long16; - - -/* ---- cl_ulongn ---- */ -typedef union -{ - cl_ulong CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y; }; - __extension__ struct{ cl_ulong s0, s1; }; - __extension__ struct{ cl_ulong lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2; -#endif -}cl_ulong2; - -typedef union -{ - cl_ulong CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3; }; - __extension__ struct{ cl_ulong2 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[2]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4; -#endif -}cl_ulong4; - -/* cl_ulong3 is identical in size, alignment and behavior to cl_ulong4. See section 6.1.5. */ -typedef cl_ulong4 cl_ulong3; - -typedef union -{ - cl_ulong CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_ulong4 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[4]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[2]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8; -#endif -}cl_ulong8; - -typedef union -{ - cl_ulong CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_ulong x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_ulong s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_ulong8 lo, hi; }; -#endif -#if defined( __CL_ULONG2__) - __cl_ulong2 v2[8]; -#endif -#if defined( __CL_ULONG4__) - __cl_ulong4 v4[4]; -#endif -#if defined( __CL_ULONG8__ ) - __cl_ulong8 v8[2]; -#endif -#if defined( __CL_ULONG16__ ) - __cl_ulong16 v16; -#endif -}cl_ulong16; - - -/* --- cl_floatn ---- */ - -typedef union -{ - cl_float CL_ALIGNED(8) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y; }; - __extension__ struct{ cl_float s0, s1; }; - __extension__ struct{ cl_float lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2; -#endif -}cl_float2; - -typedef union -{ - cl_float CL_ALIGNED(16) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3; }; - __extension__ struct{ cl_float2 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[2]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4; -#endif -}cl_float4; - -/* cl_float3 is identical in size, alignment and behavior to cl_float4. See section 6.1.5. */ -typedef cl_float4 cl_float3; - -typedef union -{ - cl_float CL_ALIGNED(32) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_float4 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[4]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[2]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8; -#endif -}cl_float8; - -typedef union -{ - cl_float CL_ALIGNED(64) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_float x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_float s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_float8 lo, hi; }; -#endif -#if defined( __CL_FLOAT2__) - __cl_float2 v2[8]; -#endif -#if defined( __CL_FLOAT4__) - __cl_float4 v4[4]; -#endif -#if defined( __CL_FLOAT8__ ) - __cl_float8 v8[2]; -#endif -#if defined( __CL_FLOAT16__ ) - __cl_float16 v16; -#endif -}cl_float16; - -/* --- cl_doublen ---- */ - -typedef union -{ - cl_double CL_ALIGNED(16) s[2]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y; }; - __extension__ struct{ cl_double s0, s1; }; - __extension__ struct{ cl_double lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2; -#endif -}cl_double2; - -typedef union -{ - cl_double CL_ALIGNED(32) s[4]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3; }; - __extension__ struct{ cl_double2 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[2]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4; -#endif -}cl_double4; - -/* cl_double3 is identical in size, alignment and behavior to cl_double4. See section 6.1.5. */ -typedef cl_double4 cl_double3; - -typedef union -{ - cl_double CL_ALIGNED(64) s[8]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7; }; - __extension__ struct{ cl_double4 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[4]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[2]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8; -#endif -}cl_double8; - -typedef union -{ - cl_double CL_ALIGNED(128) s[16]; -#if defined( __GNUC__) && ! defined( __STRICT_ANSI__ ) - __extension__ struct{ cl_double x, y, z, w, __spacer4, __spacer5, __spacer6, __spacer7, __spacer8, __spacer9, sa, sb, sc, sd, se, sf; }; - __extension__ struct{ cl_double s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, sA, sB, sC, sD, sE, sF; }; - __extension__ struct{ cl_double8 lo, hi; }; -#endif -#if defined( __CL_DOUBLE2__) - __cl_double2 v2[8]; -#endif -#if defined( __CL_DOUBLE4__) - __cl_double4 v4[4]; -#endif -#if defined( __CL_DOUBLE8__ ) - __cl_double8 v8[2]; -#endif -#if defined( __CL_DOUBLE16__ ) - __cl_double16 v16; -#endif -}cl_double16; - -/* Macro to facilitate debugging - * Usage: - * Place CL_PROGRAM_STRING_DEBUG_INFO on the line before the first line of your source. - * The first line ends with: CL_PROGRAM_STRING_DEBUG_INFO \" - * Each line thereafter of OpenCL C source must end with: \n\ - * The last line ends in "; - * - * Example: - * - * const char *my_program = CL_PROGRAM_STRING_DEBUG_INFO "\ - * kernel void foo( int a, float * b ) \n\ - * { \n\ - * // my comment \n\ - * *b[ get_global_id(0)] = a; \n\ - * } \n\ - * "; - * - * This should correctly set up the line, (column) and file information for your source - * string so you can do source level debugging. - */ -#define __CL_STRINGIFY( _x ) # _x -#define _CL_STRINGIFY( _x ) __CL_STRINGIFY( _x ) -#define CL_PROGRAM_STRING_DEBUG_INFO "#line " _CL_STRINGIFY(__LINE__) " \"" __FILE__ "\" \n\n" - -#ifdef __cplusplus -} -#endif - -#endif /* __CL_PLATFORM_H */ diff --git a/3rdparty/bx/3rdparty/CL/opencl.h b/3rdparty/bx/3rdparty/CL/opencl.h deleted file mode 100644 index 3f00524719b..00000000000 --- a/3rdparty/bx/3rdparty/CL/opencl.h +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008-2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -/* $Revision: 11708 $ on $Date: 2010-06-13 23:36:24 -0700 (Sun, 13 Jun 2010) $ */ - -#ifndef __OPENCL_H -#define __OPENCL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __APPLE__ - -#include <OpenCL/cl.h> -#include <OpenCL/cl_gl.h> -#include <OpenCL/cl_gl_ext.h> -#include <OpenCL/cl_ext.h> - -#else - -#include <CL/cl.h> -#include <CL/cl_gl.h> -#include <CL/cl_gl_ext.h> -#include <CL/cl_ext.h> - -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* __OPENCL_H */ - diff --git a/3rdparty/bx/3rdparty/catch/catch.hpp b/3rdparty/bx/3rdparty/catch/catch.hpp index 7df2fd09c00..2a09fd193a0 100644 --- a/3rdparty/bx/3rdparty/catch/catch.hpp +++ b/3rdparty/bx/3rdparty/catch/catch.hpp @@ -1,6 +1,6 @@ /* - * Catch v1.5.4 - * Generated: 2016-05-12 19:16:01.957320 + * Catch v1.7.2 + * Generated: 2017-02-13 15:57:33.350226 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -60,21 +60,6 @@ // #included from: catch_common.h #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED -#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line -#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) -#ifdef CATCH_CONFIG_COUNTER -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) -#else -# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) -#endif - -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) - -#include <sstream> -#include <stdexcept> -#include <algorithm> - // #included from: catch_compiler_capabilities.h #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED @@ -89,11 +74,14 @@ // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? // CATCH_CONFIG_CPP11_OVERRIDE : is override supported? // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) +// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported? +// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported? // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? // **************** // Note to maintainers: if new toggles are added please document them // in configuration.md, too @@ -106,8 +94,16 @@ // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 -#if defined(__cplusplus) && __cplusplus >= 201103L -# define CATCH_CPP11_OR_GREATER +#ifdef __cplusplus + +# if __cplusplus >= 201103L +# define CATCH_CPP11_OR_GREATER +# endif + +# if __cplusplus >= 201402L +# define CATCH_CPP14_OR_GREATER +# endif + #endif #ifdef __clang__ @@ -165,6 +161,8 @@ // Visual C++ #ifdef _MSC_VER +#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH + #if (_MSC_VER >= 1600) # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR @@ -173,6 +171,8 @@ #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS +#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE +#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS #endif #endif // _MSC_VER @@ -238,6 +238,12 @@ # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR # endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) +# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE +# endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) +# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS +# endif #endif // __cplusplus >= 201103L @@ -260,18 +266,30 @@ #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) # define CATCH_CONFIG_VARIADIC_MACROS #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) +#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) # define CATCH_CONFIG_CPP11_LONG_LONG #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) +#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) # define CATCH_CONFIG_CPP11_OVERRIDE #endif -#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) +#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) # define CATCH_CONFIG_CPP11_UNIQUE_PTR #endif -#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +// Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for +// analytics) because, at time of writing, __COUNTER__ is not properly handled by it. +// This does not affect compilation +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__) # define CATCH_CONFIG_COUNTER #endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_SHUFFLE +#endif +# if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11) +# define CATCH_CONFIG_CPP11_TYPE_TRAITS +# endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS @@ -307,6 +325,20 @@ # define CATCH_AUTO_PTR( T ) std::auto_ptr<T> #endif +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr +#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) + +#include <sstream> +#include <algorithm> + namespace Catch { struct IConfig; @@ -359,7 +391,9 @@ namespace Catch { } bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); bool contains( std::string const& s, std::string const& infix ); void toLowerInPlace( std::string& s ); std::string toLower( std::string const& s ); @@ -379,8 +413,8 @@ namespace Catch { SourceLineInfo(); SourceLineInfo( char const* _file, std::size_t _line ); - SourceLineInfo( SourceLineInfo const& other ); # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS + SourceLineInfo(SourceLineInfo const& other) = default; SourceLineInfo( SourceLineInfo && ) = default; SourceLineInfo& operator = ( SourceLineInfo const& ) = default; SourceLineInfo& operator = ( SourceLineInfo && ) = default; @@ -389,7 +423,7 @@ namespace Catch { bool operator == ( SourceLineInfo const& other ) const; bool operator < ( SourceLineInfo const& other ) const; - std::string file; + char const* file; std::size_t line; }; @@ -423,8 +457,6 @@ namespace Catch { #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); -#include <ostream> - namespace Catch { class NotImplementedException : public std::exception @@ -557,10 +589,6 @@ namespace Catch { #pragma clang diagnostic pop #endif -#include <memory> -#include <vector> -#include <stdlib.h> - namespace Catch { class TestCase; @@ -824,6 +852,27 @@ namespace Catch { namespace Catch { + struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; + + struct DecomposedExpression + { + virtual ~DecomposedExpression() {} + virtual bool isBinaryExpression() const { + return false; + } + virtual void reconstructExpression( std::string& dest ) const = 0; + + // Only simple binary comparisons can be decomposed. + // If more complex check is required then wrap sub-expressions in parentheses. + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& ); + template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& ); + }; + struct AssertionInfo { AssertionInfo() {} @@ -840,11 +889,41 @@ namespace Catch { struct AssertionResultData { - AssertionResultData() : resultType( ResultWas::Unknown ) {} + AssertionResultData() : decomposedExpression( CATCH_NULL ) + , resultType( ResultWas::Unknown ) + , negated( false ) + , parenthesized( false ) {} + + void negate( bool parenthesize ) { + negated = !negated; + parenthesized = parenthesize; + if( resultType == ResultWas::Ok ) + resultType = ResultWas::ExpressionFailed; + else if( resultType == ResultWas::ExpressionFailed ) + resultType = ResultWas::Ok; + } + + std::string const& reconstructExpression() const { + if( decomposedExpression != CATCH_NULL ) { + decomposedExpression->reconstructExpression( reconstructedExpression ); + if( parenthesized ) { + reconstructedExpression.insert( 0, 1, '(' ); + reconstructedExpression.append( 1, ')' ); + } + if( negated ) { + reconstructedExpression.insert( 0, 1, '!' ); + } + decomposedExpression = CATCH_NULL; + } + return reconstructedExpression; + } - std::string reconstructedExpression; + mutable DecomposedExpression const* decomposedExpression; + mutable std::string reconstructedExpression; std::string message; ResultWas::OfType resultType; + bool negated; + bool parenthesized; }; class AssertionResult { @@ -871,6 +950,8 @@ namespace Catch { std::string getMessage() const; SourceLineInfo getSourceInfo() const; std::string getTestMacroName() const; + void discardDecomposedExpression() const; + void expandDecomposedExpression() const; protected: AssertionInfo m_info; @@ -1057,7 +1138,7 @@ namespace Matchers { { return m_caseSensitivity == CaseSensitive::No ? " (case insensitive)" - : ""; + : std::string(); } CaseSensitive::Choice m_caseSensitivity; std::string m_str; @@ -1075,7 +1156,7 @@ namespace Matchers { return m_data.m_str == m_data.adjustString( expr );; } virtual std::string toString() const { - return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); + return "equals: \"" + m_data.m_str + '"' + m_data.toStringSuffix(); } CasedString m_data; @@ -1092,7 +1173,7 @@ namespace Matchers { return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos; } virtual std::string toString() const { - return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); + return "contains: \"" + m_data.m_str + '"' + m_data.toStringSuffix(); } CasedString m_data; @@ -1110,7 +1191,7 @@ namespace Matchers { return startsWith( m_data.adjustString( expr ), m_data.m_str ); } virtual std::string toString() const { - return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); + return "starts with: \"" + m_data.m_str + '"' + m_data.toStringSuffix(); } CasedString m_data; @@ -1127,7 +1208,7 @@ namespace Matchers { return endsWith( m_data.adjustString( expr ), m_data.m_str ); } virtual std::string toString() const { - return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); + return "ends with: \"" + m_data.m_str + '"' + m_data.toStringSuffix(); } CasedString m_data; @@ -1202,22 +1283,20 @@ namespace Catch { template<typename T> class ExpressionLhs; - struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; - struct CopyableStream { CopyableStream() {} CopyableStream( CopyableStream const& other ) { oss << other.oss.str(); } CopyableStream& operator=( CopyableStream const& other ) { - oss.str(""); + oss.str(std::string()); oss << other.oss.str(); return *this; } std::ostringstream oss; }; - class ResultBuilder { + class ResultBuilder : public DecomposedExpression { public: ResultBuilder( char const* macroName, SourceLineInfo const& lineInfo, @@ -1235,19 +1314,15 @@ namespace Catch { return *this; } - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); - ResultBuilder& setResultType( ResultWas::OfType result ); ResultBuilder& setResultType( bool result ); - ResultBuilder& setLhs( std::string const& lhs ); - ResultBuilder& setRhs( std::string const& rhs ); - ResultBuilder& setOp( std::string const& op ); - void endExpression(); + void endExpression( DecomposedExpression const& expr ); + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE; - std::string reconstructExpression() const; AssertionResult build() const; + AssertionResult build( DecomposedExpression const& expr ) const; void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); void captureResult( ResultWas::OfType resultType ); @@ -1259,14 +1334,12 @@ namespace Catch { bool shouldDebugBreak() const; bool allowThrows() const; + template<typename ArgT, typename MatcherT> + void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString ); + private: AssertionInfo m_assertionInfo; AssertionResultData m_data; - struct ExprComponents { - ExprComponents() : testFalse( false ) {} - bool testFalse; - std::string lhs, rhs, op; - } m_exprComponents; CopyableStream m_stream; bool m_shouldDebugBreak; @@ -1788,90 +1861,155 @@ std::string toString( T const& value ) { namespace Catch { -// Wraps the LHS of an expression and captures the operator and RHS (if any) - -// wrapping them all in a ResultBuilder object -template<typename T> -class ExpressionLhs { - ExpressionLhs& operator = ( ExpressionLhs const& ); -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs& operator = ( ExpressionLhs && ) = delete; -# endif +template<typename LhsT, Internal::Operator Op, typename RhsT> +class BinaryExpression; +template<typename ArgT, typename MatcherT> +class MatchExpression; + +// Wraps the LHS of an expression and overloads comparison operators +// for also capturing those and RHS (if any) +template<typename T> +class ExpressionLhs : public DecomposedExpression { public: - ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} -# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS - ExpressionLhs( ExpressionLhs const& ) = default; - ExpressionLhs( ExpressionLhs && ) = default; -# endif + ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {} template<typename RhsT> - ResultBuilder& operator == ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsEqualTo, RhsT const&> + operator == ( RhsT const& rhs ) { return captureExpression<Internal::IsEqualTo>( rhs ); } template<typename RhsT> - ResultBuilder& operator != ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsNotEqualTo, RhsT const&> + operator != ( RhsT const& rhs ) { return captureExpression<Internal::IsNotEqualTo>( rhs ); } template<typename RhsT> - ResultBuilder& operator < ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsLessThan, RhsT const&> + operator < ( RhsT const& rhs ) { return captureExpression<Internal::IsLessThan>( rhs ); } template<typename RhsT> - ResultBuilder& operator > ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsGreaterThan, RhsT const&> + operator > ( RhsT const& rhs ) { return captureExpression<Internal::IsGreaterThan>( rhs ); } template<typename RhsT> - ResultBuilder& operator <= ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsLessThanOrEqualTo, RhsT const&> + operator <= ( RhsT const& rhs ) { return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); } template<typename RhsT> - ResultBuilder& operator >= ( RhsT const& rhs ) { + BinaryExpression<T, Internal::IsGreaterThanOrEqualTo, RhsT const&> + operator >= ( RhsT const& rhs ) { return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); } - ResultBuilder& operator == ( bool rhs ) { + BinaryExpression<T, Internal::IsEqualTo, bool> operator == ( bool rhs ) { return captureExpression<Internal::IsEqualTo>( rhs ); } - ResultBuilder& operator != ( bool rhs ) { + BinaryExpression<T, Internal::IsNotEqualTo, bool> operator != ( bool rhs ) { return captureExpression<Internal::IsNotEqualTo>( rhs ); } void endExpression() { - bool value = m_lhs ? true : false; + m_truthy = m_lhs ? true : false; m_rb - .setLhs( Catch::toString( value ) ) - .setResultType( value ) - .endExpression(); + .setResultType( m_truthy ) + .endExpression( *this ); } - // Only simple binary expressions are allowed on the LHS. - // If more complex compositions are required then place the sub expression in parentheses - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); - template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + dest = Catch::toString( m_truthy ); + } private: template<Internal::Operator Op, typename RhsT> - ResultBuilder& captureExpression( RhsT const& rhs ) { - return m_rb - .setResultType( Internal::compare<Op>( m_lhs, rhs ) ) - .setLhs( Catch::toString( m_lhs ) ) - .setRhs( Catch::toString( rhs ) ) - .setOp( Internal::OperatorTraits<Op>::getName() ); + BinaryExpression<T, Op, RhsT&> captureExpression( RhsT& rhs ) const { + return BinaryExpression<T, Op, RhsT&>( m_rb, m_lhs, rhs ); + } + + template<Internal::Operator Op> + BinaryExpression<T, Op, bool> captureExpression( bool rhs ) const { + return BinaryExpression<T, Op, bool>( m_rb, m_lhs, rhs ); } private: ResultBuilder& m_rb; T m_lhs; + bool m_truthy; +}; + +template<typename LhsT, Internal::Operator Op, typename RhsT> +class BinaryExpression : public DecomposedExpression { +public: + BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs ) + : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {} + + void endExpression() const { + m_rb + .setResultType( Internal::compare<Op>( m_lhs, m_rhs ) ) + .endExpression( *this ); + } + + virtual bool isBinaryExpression() const CATCH_OVERRIDE { + return true; + } + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + std::string lhs = Catch::toString( m_lhs ); + std::string rhs = Catch::toString( m_rhs ); + char delim = lhs.size() + rhs.size() < 40 && + lhs.find('\n') == std::string::npos && + rhs.find('\n') == std::string::npos ? ' ' : '\n'; + dest.reserve( 7 + lhs.size() + rhs.size() ); + // 2 for spaces around operator + // 2 for operator + // 2 for parentheses (conditionally added later) + // 1 for negation (conditionally added later) + dest = lhs; + dest += delim; + dest += Internal::OperatorTraits<Op>::getName(); + dest += delim; + dest += rhs; + } + +private: + ResultBuilder& m_rb; + LhsT m_lhs; + RhsT m_rhs; +}; + +template<typename ArgT, typename MatcherT> +class MatchExpression : public DecomposedExpression { +public: + MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString ) + : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {} + + virtual bool isBinaryExpression() const CATCH_OVERRIDE { + return true; + } + + virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE { + std::string matcherAsString = m_matcher.toString(); + dest = Catch::toString( m_arg ); + dest += ' '; + if( matcherAsString == Detail::unprintableString ) + dest += m_matcherString; + else + dest += matcherAsString; + } + +private: + ArgT m_arg; + MatcherT m_matcher; + char const* m_matcherString; }; } // end namespace Catch @@ -1888,6 +2026,14 @@ namespace Catch { return ExpressionLhs<bool>( *this, value ); } + template<typename ArgT, typename MatcherT> + inline void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher, + char const* matcherString ) { + MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString ); + setResultType( matcher.match( arg ) ); + endExpression( expr ); + } + } // namespace Catch // #included from: catch_message.h @@ -1990,11 +2136,19 @@ namespace Catch { #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_MAC +# define CATCH_PLATFORM_MAC #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) -#define CATCH_PLATFORM_IPHONE +# define CATCH_PLATFORM_IPHONE +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) -#define CATCH_PLATFORM_WINDOWS +# define CATCH_PLATFORM_WINDOWS +# if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINES_NOMINMAX +# endif +# if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# endif #endif #include <string> @@ -2009,27 +2163,36 @@ namespace Catch{ // The following code snippet based on: // http://cocoawithlove.com/2008/03/break-into-debugger.html - #ifdef DEBUG - #if defined(__ppc64__) || defined(__ppc__) - #define CATCH_BREAK_INTO_DEBUGGER() \ - if( Catch::isDebuggerActive() ) { \ - __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ - : : : "memory","r0","r3","r4" ); \ - } - #else - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );} - #endif + #if defined(__ppc64__) || defined(__ppc__) + #define CATCH_TRAP() \ + __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ + : : : "memory","r0","r3","r4" ) + #else + #define CATCH_TRAP() __asm__("int $3\n" : : ) #endif +#elif defined(CATCH_PLATFORM_LINUX) + // If we can use inline assembler, do it because this allows us to break + // directly at the location of the failing check instead of breaking inside + // raise() called from it, i.e. one stack frame below. + #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #define CATCH_TRAP() asm volatile ("int $3") + #else // Fall back to the generic way. + #include <signal.h> + + #define CATCH_TRAP() raise(SIGTRAP) + #endif #elif defined(_MSC_VER) - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); } + #define CATCH_TRAP() __debugbreak() #elif defined(__MINGW32__) extern "C" __declspec(dllimport) void __stdcall DebugBreak(); - #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); } + #define CATCH_TRAP() DebugBreak() #endif -#ifndef CATCH_BREAK_INTO_DEBUGGER -#define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); +#ifdef CATCH_TRAP + #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } +#else + #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); #endif // #included from: catch_interfaces_runner.h @@ -2044,6 +2207,45 @@ namespace Catch { }; } +// #included from: catch_type_traits.hpp +#define TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) +#include <type_traits> +#endif + +namespace Catch { + +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) + + template <typename T> + using add_lvalue_reference = std::add_lvalue_reference<T>; + + template <typename T> + using add_const = std::add_const<T>; + +#else + + template <typename T> + struct add_const { + typedef const T type; + }; + + template <typename T> + struct add_lvalue_reference { + typedef T& type; + }; + template <typename T> + struct add_lvalue_reference<T&> { + typedef T& type; + }; + // No && overload, because that is C++11, in which case we have + // proper type_traits implementation from the standard library + +#endif + +} + /////////////////////////////////////////////////////////////////////////////// // In the event of a failure works out if the debugger needs to be invoked // and/or an exception thrown and takes appropriate action. @@ -2062,10 +2264,11 @@ namespace Catch { ( __catchResult <= expr ).endExpression(); \ } \ catch( ... ) { \ - __catchResult.useActiveException( Catch::ResultDisposition::Normal ); \ + __catchResult.useActiveException( resultDisposition ); \ } \ INTERNAL_CATCH_REACT( __catchResult ) \ - } while( Catch::isTrue( false && !!(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look + } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look + // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&. /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ @@ -2082,7 +2285,7 @@ namespace Catch { do { \ Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ try { \ - expr; \ + static_cast<void>(expr); \ __catchResult.captureResult( Catch::ResultWas::Ok ); \ } \ catch( ... ) { \ @@ -2097,7 +2300,7 @@ namespace Catch { Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \ if( __catchResult.allowThrows() ) \ try { \ - expr; \ + static_cast<void>(expr); \ __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ } \ catch( ... ) { \ @@ -2111,13 +2314,13 @@ namespace Catch { /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \ do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ + Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr ", " #exceptionType, resultDisposition ); \ if( __catchResult.allowThrows() ) \ try { \ - expr; \ + static_cast<void>(expr); \ __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ } \ - catch( exceptionType ) { \ + catch( Catch::add_const<Catch::add_lvalue_reference<exceptionType>::type>::type ) { \ __catchResult.captureResult( Catch::ResultWas::Ok ); \ } \ catch( ... ) { \ @@ -2156,13 +2359,7 @@ namespace Catch { do { \ Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ try { \ - std::string matcherAsString = (matcher).toString(); \ - __catchResult \ - .setLhs( Catch::toString( arg ) ) \ - .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \ - .setOp( "matches" ) \ - .setResultType( (matcher).match( arg ) ); \ - __catchResult.captureExpression(); \ + __catchResult.captureMatch( arg, matcher, #matcher ); \ } catch( ... ) { \ __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ } \ @@ -2245,6 +2442,8 @@ namespace Catch { }; } +#include <string> + namespace Catch { struct SectionInfo { @@ -2615,6 +2814,10 @@ namespace Catch { #include <cmath> #include <limits> +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) +#include <type_traits> +#endif + namespace Catch { namespace Detail { @@ -2643,9 +2846,56 @@ namespace Detail { return approx; } +#if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator == ( const T& lhs, Approx const& rhs ) { + // Thanks to Richard Harris for his help refining this formula + auto lhs_v = double(lhs); + return std::fabs( lhs_v - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs_v), std::fabs(rhs.m_value) ) ); + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator == ( Approx const& lhs, const T& rhs ) { + return operator==( rhs, lhs ); + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator != ( T lhs, Approx const& rhs ) { + return !operator==( lhs, rhs ); + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator != ( Approx const& lhs, T rhs ) { + return !operator==( rhs, lhs ); + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator <= ( T lhs, Approx const& rhs ) + { + return double(lhs) < rhs.m_value || lhs == rhs; + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator <= ( Approx const& lhs, T rhs ) + { + return lhs.m_value < double(rhs) || lhs == rhs; + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator >= ( T lhs, Approx const& rhs ) + { + return double(lhs) > rhs.m_value || lhs == rhs; + } + + template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type> + friend bool operator >= ( Approx const& lhs, T rhs ) + { + return lhs.m_value > double(rhs) || lhs == rhs; + } +#else friend bool operator == ( double lhs, Approx const& rhs ) { // Thanks to Richard Harris for his help refining this formula - return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) ); + return std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) ); } friend bool operator == ( Approx const& lhs, double rhs ) { @@ -2660,6 +2910,27 @@ namespace Detail { return !operator==( rhs, lhs ); } + friend bool operator <= ( double lhs, Approx const& rhs ) + { + return lhs < rhs.m_value || lhs == rhs; + } + + friend bool operator <= ( Approx const& lhs, double rhs ) + { + return lhs.m_value < rhs || lhs == rhs; + } + + friend bool operator >= ( double lhs, Approx const& rhs ) + { + return lhs > rhs.m_value || lhs == rhs; + } + + friend bool operator >= ( Approx const& lhs, double rhs ) + { + return lhs.m_value > rhs || lhs == rhs; + } +#endif + Approx& epsilon( double newEpsilon ) { m_epsilon = newEpsilon; return *this; @@ -2814,7 +3085,8 @@ namespace Catch { IsHidden = 1 << 1, ShouldFail = 1 << 2, MayFail = 1 << 3, - Throws = 1 << 4 + Throws = 1 << 4, + NonPortable = 1 << 5 }; TestCaseInfo( std::string const& _name, @@ -3109,6 +3381,8 @@ return @ desc; \ // #included from: catch_wildcard_pattern.hpp #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED +#include <stdexcept> + namespace Catch { class WildcardPattern { @@ -3126,11 +3400,11 @@ namespace Catch m_wildcard( NoWildcard ), m_pattern( adjustCase( pattern ) ) { - if( startsWith( m_pattern, "*" ) ) { + if( startsWith( m_pattern, '*' ) ) { m_pattern = m_pattern.substr( 1 ); m_wildcard = WildcardAtStart; } - if( endsWith( m_pattern, "*" ) ) { + if( endsWith( m_pattern, '*' ) ) { m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd ); } @@ -3215,10 +3489,11 @@ namespace Catch { bool matches( TestCaseInfo const& testCase ) const { // All patterns in a filter must match for the filter to be a match - for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) + for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) { if( !(*it)->matches( testCase ) ) return false; - return true; + } + return true; } }; @@ -3248,11 +3523,12 @@ namespace Catch { namespace Catch { class TestSpecParser { - enum Mode{ None, Name, QuotedName, Tag }; + enum Mode{ None, Name, QuotedName, Tag, EscapedName }; Mode m_mode; bool m_exclusion; std::size_t m_start, m_pos; std::string m_arg; + std::vector<std::size_t> m_escapeChars; TestSpec::Filter m_currentFilter; TestSpec m_testSpec; ITagAliasRegistry const* m_tagAliases; @@ -3265,6 +3541,7 @@ namespace Catch { m_exclusion = false; m_start = std::string::npos; m_arg = m_tagAliases->expandAliases( arg ); + m_escapeChars.clear(); for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) visitChar( m_arg[m_pos] ); if( m_mode == Name ) @@ -3283,6 +3560,7 @@ namespace Catch { case '~': m_exclusion = true; return; case '[': return startNewMode( Tag, ++m_pos ); case '"': return startNewMode( QuotedName, ++m_pos ); + case '\\': return escape(); default: startNewMode( Name, m_pos ); break; } } @@ -3298,7 +3576,11 @@ namespace Catch { addPattern<TestSpec::NamePattern>(); startNewMode( Tag, ++m_pos ); } + else if( c == '\\' ) + escape(); } + else if( m_mode == EscapedName ) + m_mode = Name; else if( m_mode == QuotedName && c == '"' ) addPattern<TestSpec::NamePattern>(); else if( m_mode == Tag && c == ']' ) @@ -3308,10 +3590,19 @@ namespace Catch { m_mode = mode; m_start = start; } + void escape() { + if( m_mode == None ) + m_start = m_pos; + m_mode = EscapedName; + m_escapeChars.push_back( m_pos ); + } std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } template<typename T> void addPattern() { std::string token = subString(); + for( size_t i = 0; i < m_escapeChars.size(); ++i ) + token = token.substr( 0, m_escapeChars[i]-i ) + token.substr( m_escapeChars[i]+1-i ); + m_escapeChars.clear(); if( startsWith( token, "exclude:" ) ) { m_exclusion = true; token = token.substr( 8 ); @@ -3345,7 +3636,7 @@ namespace Catch { // #included from: catch_interfaces_config.h #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED -#include <iostream> +#include <iosfwd> #include <string> #include <vector> @@ -3397,6 +3688,8 @@ namespace Catch { virtual RunTests::InWhatOrder runOrder() const = 0; virtual unsigned int rngSeed() const = 0; virtual UseColour::YesOrNo useColour() const = 0; + virtual std::vector<std::string> const& getSectionsToRun() const = 0; + }; } @@ -3419,6 +3712,7 @@ namespace Catch { #include <streambuf> #include <ostream> #include <fstream> +#include <memory> namespace Catch { @@ -3450,7 +3744,7 @@ namespace Catch { }; class DebugOutStream : public IStream { - std::auto_ptr<StreamBufBase> m_streamBuf; + CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf; mutable std::ostream m_os; public: DebugOutStream(); @@ -3464,8 +3758,7 @@ namespace Catch { #include <memory> #include <vector> #include <string> -#include <iostream> -#include <ctime> +#include <stdexcept> #ifndef CATCH_CONFIG_CONSOLE_WIDTH #define CATCH_CONFIG_CONSOLE_WIDTH 80 @@ -3522,6 +3815,7 @@ namespace Catch { std::vector<std::string> reporterNames; std::vector<std::string> testsOrTags; + std::vector<std::string> sectionsToRun; }; class Config : public SharedImpl<IConfig> { @@ -3546,8 +3840,7 @@ namespace Catch { } } - virtual ~Config() { - } + virtual ~Config() {} std::string const& getFilename() const { return m_data.outputFilename ; @@ -3560,27 +3853,26 @@ namespace Catch { std::string getProcessName() const { return m_data.processName; } - bool shouldDebugBreak() const { return m_data.shouldDebugBreak; } + std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; } + std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; } - std::vector<std::string> getReporterNames() const { return m_data.reporterNames; } - - int abortAfter() const { return m_data.abortAfter; } - - TestSpec const& testSpec() const { return m_testSpec; } + virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; } bool showHelp() const { return m_data.showHelp; } - bool showInvisibles() const { return m_data.showInvisibles; } // IConfig interface - virtual bool allowThrows() const { return !m_data.noThrow; } - virtual std::ostream& stream() const { return m_stream->stream(); } - virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } - virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; } - virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } - virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; } - virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; } - virtual unsigned int rngSeed() const { return m_data.rngSeed; } - virtual UseColour::YesOrNo useColour() const { return m_data.useColour; } + virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; } + virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); } + virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; } + virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; } + virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; } + virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; } + virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; } + virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; } + virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; } + virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; } + virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; } + virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; } private: @@ -3598,7 +3890,7 @@ namespace Catch { } ConfigData m_data; - std::auto_ptr<IStream const> m_stream; + CATCH_AUTO_PTR( IStream const ) m_stream; TestSpec m_testSpec; }; @@ -3986,9 +4278,12 @@ namespace Clara { inline void convertInto( std::string const& _source, std::string& _dest ) { _dest = _source; } + char toLowerCh(char c) { + return static_cast<char>( ::tolower( c ) ); + } inline void convertInto( std::string const& _source, bool& _dest ) { std::string sourceLC = _source; - std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower ); + std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh ); if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" ) _dest = true; else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" ) @@ -4177,7 +4472,7 @@ namespace Clara { } } Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { - if( std::string( ":=\0", 5 ).find( c ) == std::string::npos ) + if( std::string( ":=\0", 3 ).find( c ) == std::string::npos ) return mode; std::string optName = arg.substr( from, i-from ); @@ -4191,7 +4486,7 @@ namespace Clara { return None; } Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { - if( inQuotes || std::string( "\0", 3 ).find( c ) == std::string::npos ) + if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos ) return mode; std::string data = arg.substr( from, i-from ); @@ -4639,6 +4934,7 @@ STITCH_CLARA_CLOSE_NAMESPACE #endif #include <fstream> +#include <ctime> namespace Catch { @@ -4649,13 +4945,14 @@ namespace Catch { config.abortAfter = x; } inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); } + inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); } inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); } inline void addWarning( ConfigData& config, std::string const& _warning ) { if( _warning == "NoAssertions" ) config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions ); else - throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" ); + throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' ); } inline void setOrder( ConfigData& config, std::string const& order ) { if( startsWith( "declared", order ) ) @@ -4665,7 +4962,7 @@ namespace Catch { else if( startsWith( "random", order ) ) config.runOrder = RunTests::InRandomOrder; else - throw std::runtime_error( "Unrecognised ordering: '" + order + "'" ); + throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' ); } inline void setRngSeed( ConfigData& config, std::string const& seed ) { if( seed == "time" ) { @@ -4676,7 +4973,7 @@ namespace Catch { ss << seed; ss >> config.rngSeed; if( ss.fail() ) - throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" ); + throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" ); } } inline void setVerbosity( ConfigData& config, int level ) { @@ -4711,8 +5008,11 @@ namespace Catch { std::string line; while( std::getline( f, line ) ) { line = trim(line); - if( !line.empty() && !startsWith( line, "#" ) ) - addTestOrTags( config, "\"" + line + "\"," ); + if( !line.empty() && !startsWith( line, '#' ) ) { + if( !startsWith( line, '"' ) ) + line = '"' + line + '"'; + addTestOrTags( config, line + ',' ); + } } } @@ -4799,6 +5099,10 @@ namespace Catch { .describe( "adds a tag for the filename" ) .bind( &ConfigData::filenamesAsTags ); + cli["-c"]["--section"] + .describe( "specify section to run" ) + .bind( &addSectionToRun, "section name" ); + // Less common commands which don't have a short form cli["--list-test-names-only"] .describe( "list all/matching test cases names only" ) @@ -4871,19 +5175,16 @@ namespace Tbc { TextAttributes() : initialIndent( std::string::npos ), indent( 0 ), - width( consoleWidth-1 ), - tabChar( '\t' ) + width( consoleWidth-1 ) {} TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } - TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } std::size_t initialIndent; // indent of first line, or npos std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos std::size_t width; // maximum width of text, including indent. Longer text will wrap - char tabChar; // If this char is seen the indent is changed to current pos }; class Text { @@ -4891,62 +5192,76 @@ namespace Tbc { Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) : attr( _attr ) { - std::string wrappableChars = " [({.,/|\\-"; - std::size_t indent = _attr.initialIndent != std::string::npos - ? _attr.initialIndent - : _attr.indent; - std::string remainder = _str; + const std::string wrappableBeforeChars = "[({<\t"; + const std::string wrappableAfterChars = "])}>-,./|\\"; + const std::string wrappableInsteadOfChars = " \n\r"; + std::string indent = _attr.initialIndent != std::string::npos + ? std::string( _attr.initialIndent, ' ' ) + : std::string( _attr.indent, ' ' ); + + typedef std::string::const_iterator iterator; + iterator it = _str.begin(); + const iterator strEnd = _str.end(); + + while( it != strEnd ) { - while( !remainder.empty() ) { if( lines.size() >= 1000 ) { lines.push_back( "... message truncated due to excessive size" ); return; } - std::size_t tabPos = std::string::npos; - std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); - std::size_t pos = remainder.find_first_of( '\n' ); - if( pos <= width ) { - width = pos; - } - pos = remainder.find_last_of( _attr.tabChar, width ); - if( pos != std::string::npos ) { - tabPos = pos; - if( remainder[width] == '\n' ) - width--; - remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); - } - if( width == remainder.size() ) { - spliceLine( indent, remainder, width ); - } - else if( remainder[width] == '\n' ) { - spliceLine( indent, remainder, width ); - if( width <= 1 || remainder.size() != 1 ) - remainder = remainder.substr( 1 ); - indent = _attr.indent; - } - else { - pos = remainder.find_last_of( wrappableChars, width ); - if( pos != std::string::npos && pos > 0 ) { - spliceLine( indent, remainder, pos ); - if( remainder[0] == ' ' ) - remainder = remainder.substr( 1 ); + std::string suffix; + std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) ); + iterator itEnd = it+width; + iterator itNext = _str.end(); + + iterator itNewLine = std::find( it, itEnd, '\n' ); + if( itNewLine != itEnd ) + itEnd = itNewLine; + + if( itEnd != strEnd ) { + bool foundWrapPoint = false; + iterator findIt = itEnd; + do { + if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) { + itEnd = findIt+1; + itNext = findIt+1; + foundWrapPoint = true; + } + else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) { + itEnd = findIt; + itNext = findIt; + foundWrapPoint = true; + } + else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) { + itNext = findIt+1; + itEnd = findIt; + foundWrapPoint = true; + } + if( findIt == it ) + break; + else + --findIt; + } + while( !foundWrapPoint ); + + if( !foundWrapPoint ) { + // No good wrap char, so we'll break mid word and add a hyphen + --itEnd; + itNext = itEnd; + suffix = "-"; } else { - spliceLine( indent, remainder, width-1 ); - lines.back() += "-"; + while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos ) + --itEnd; } - if( lines.size() == 1 ) - indent = _attr.indent; - if( tabPos != std::string::npos ) - indent += tabPos; } - } - } + lines.push_back( indent + std::string( it, itEnd ) + suffix ); - void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { - lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); - _remainder = _remainder.substr( _pos ); + if( indent.size() != _attr.indent ) + indent = std::string( _attr.indent, ' ' ); + it = itNext; + } } typedef std::vector<std::string>::const_iterator const_iterator; @@ -5055,7 +5370,6 @@ namespace Catch { #include <string> #include <ostream> #include <map> -#include <assert.h> namespace Catch { @@ -5343,9 +5657,9 @@ namespace Catch { } if( !config.testSpec().hasFilters() ) - Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl; + Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl; else - Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl; + Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl; return matchedTests; } @@ -5360,7 +5674,10 @@ namespace Catch { ++it ) { matchedTests++; TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); - Catch::cout() << testCaseInfo.name << std::endl; + if( startsWith( testCaseInfo.name, '#' ) ) + Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl; + else + Catch::cout() << testCaseInfo.name << std::endl; } return matchedTests; } @@ -5421,9 +5738,9 @@ namespace Catch { .setInitialIndent( 0 ) .setIndent( oss.str().size() ) .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); - Catch::cout() << oss.str() << wrapper << "\n"; + Catch::cout() << oss.str() << wrapper << '\n'; } - Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl; + Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl; return tagCounts.size(); } @@ -5442,9 +5759,9 @@ namespace Catch { .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); Catch::cout() << " " << it->first - << ":" + << ':' << std::string( maxNameLen - it->first.size() + 2, ' ' ) - << wrapper << "\n"; + << wrapper << '\n'; } Catch::cout() << std::endl; return factories.size(); @@ -5475,15 +5792,27 @@ namespace Catch { #include <string> #include <assert.h> #include <vector> +#include <iterator> +#include <stdexcept> namespace Catch { namespace TestCaseTracking { + struct NameAndLocation { + std::string name; + SourceLineInfo location; + + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ) + : name( _name ), + location( _location ) + {} + }; + struct ITracker : SharedImpl<> { virtual ~ITracker(); // static queries - virtual std::string name() const = 0; + virtual NameAndLocation const& nameAndLocation() const = 0; // dynamic queries virtual bool isComplete() const = 0; // Successfully completed or failed @@ -5499,7 +5828,7 @@ namespace TestCaseTracking { virtual void markAsNeedingAnotherRun() = 0; virtual void addChild( Ptr<ITracker> const& child ) = 0; - virtual ITracker* findChild( std::string const& name ) = 0; + virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0; virtual void openChild() = 0; // Debug/ checking @@ -5507,7 +5836,7 @@ namespace TestCaseTracking { virtual bool isIndexTracker() const = 0; }; - class TrackerContext { + class TrackerContext { enum RunState { NotStarted, @@ -5569,30 +5898,32 @@ namespace TestCaseTracking { Failed }; class TrackerHasName { - std::string m_name; + NameAndLocation m_nameAndLocation; public: - TrackerHasName( std::string const& name ) : m_name( name ) {} + TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} bool operator ()( Ptr<ITracker> const& tracker ) { - return tracker->name() == m_name; + return + tracker->nameAndLocation().name == m_nameAndLocation.name && + tracker->nameAndLocation().location == m_nameAndLocation.location; } }; typedef std::vector<Ptr<ITracker> > Children; - std::string m_name; + NameAndLocation m_nameAndLocation; TrackerContext& m_ctx; ITracker* m_parent; Children m_children; CycleState m_runState; public: - TrackerBase( std::string const& name, TrackerContext& ctx, ITracker* parent ) - : m_name( name ), + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : m_nameAndLocation( nameAndLocation ), m_ctx( ctx ), m_parent( parent ), m_runState( NotStarted ) {} virtual ~TrackerBase(); - virtual std::string name() const CATCH_OVERRIDE { - return m_name; + virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE { + return m_nameAndLocation; } virtual bool isComplete() const CATCH_OVERRIDE { return m_runState == CompletedSuccessfully || m_runState == Failed; @@ -5611,8 +5942,8 @@ namespace TestCaseTracking { m_children.push_back( child ); } - virtual ITracker* findChild( std::string const& name ) CATCH_OVERRIDE { - Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) ); + virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE { + Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) ); return( it != m_children.end() ) ? it->get() : CATCH_NULL; @@ -5690,32 +6021,56 @@ namespace TestCaseTracking { }; class SectionTracker : public TrackerBase { + std::vector<std::string> m_filters; public: - SectionTracker( std::string const& name, TrackerContext& ctx, ITracker* parent ) - : TrackerBase( name, ctx, parent ) - {} + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) + : TrackerBase( nameAndLocation, ctx, parent ) + { + if( parent ) { + while( !parent->isSectionTracker() ) + parent = &parent->parent(); + + SectionTracker& parentSection = static_cast<SectionTracker&>( *parent ); + addNextFilters( parentSection.m_filters ); + } + } virtual ~SectionTracker(); virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; } - static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) { + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) { SectionTracker* section = CATCH_NULL; ITracker& currentTracker = ctx.currentTracker(); - if( ITracker* childTracker = currentTracker.findChild( name ) ) { + if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) { assert( childTracker ); assert( childTracker->isSectionTracker() ); section = static_cast<SectionTracker*>( childTracker ); } else { - section = new SectionTracker( name, ctx, ¤tTracker ); + section = new SectionTracker( nameAndLocation, ctx, ¤tTracker ); currentTracker.addChild( section ); } - if( !ctx.completedCycle() && !section->isComplete() ) { + if( !ctx.completedCycle() ) + section->tryOpen(); + return *section; + } + + void tryOpen() { + if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) ) + open(); + } - section->open(); + void addInitialFilters( std::vector<std::string> const& filters ) { + if( !filters.empty() ) { + m_filters.push_back(""); // Root - should never be consulted + m_filters.push_back(""); // Test Case - not a section filter + std::copy( filters.begin(), filters.end(), std::back_inserter( m_filters ) ); } - return *section; + } + void addNextFilters( std::vector<std::string> const& filters ) { + if( filters.size() > 1 ) + std::copy( filters.begin()+1, filters.end(), std::back_inserter( m_filters ) ); } }; @@ -5723,8 +6078,8 @@ namespace TestCaseTracking { int m_size; int m_index; public: - IndexTracker( std::string const& name, TrackerContext& ctx, ITracker* parent, int size ) - : TrackerBase( name, ctx, parent ), + IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ) + : TrackerBase( nameAndLocation, ctx, parent ), m_size( size ), m_index( -1 ) {} @@ -5732,17 +6087,17 @@ namespace TestCaseTracking { virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; } - static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) { + static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) { IndexTracker* tracker = CATCH_NULL; ITracker& currentTracker = ctx.currentTracker(); - if( ITracker* childTracker = currentTracker.findChild( name ) ) { + if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) { assert( childTracker ); assert( childTracker->isIndexTracker() ); tracker = static_cast<IndexTracker*>( childTracker ); } else { - tracker = new IndexTracker( name, ctx, ¤tTracker, size ); + tracker = new IndexTracker( nameAndLocation, ctx, ¤tTracker, size ); currentTracker.addChild( tracker ); } @@ -5770,7 +6125,7 @@ namespace TestCaseTracking { }; inline ITracker& TrackerContext::startRun() { - m_rootTracker = new SectionTracker( "{root}", *this, CATCH_NULL ); + m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL ); m_currentTracker = CATCH_NULL; m_runState = Executing; return *m_rootTracker; @@ -5790,35 +6145,128 @@ using TestCaseTracking::IndexTracker; namespace Catch { - // Report the error condition then exit the process - inline void fatal( std::string const& message, int exitCode ) { + // Report the error condition + inline void reportFatal( std::string const& message ) { IContext& context = Catch::getCurrentContext(); IResultCapture* resultCapture = context.getResultCapture(); resultCapture->handleFatalErrorCondition( message ); - - if( Catch::alwaysTrue() ) // avoids "no return" warnings - exit( exitCode ); } } // namespace Catch #if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// +// #included from: catch_windows_h_proxy.h + +#define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED + +#ifdef CATCH_DEFINES_NOMINMAX +# define NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif + +#ifdef __AFXDLL +#include <AfxWin.h> +#else +#include <windows.h> +#endif + +#ifdef CATCH_DEFINES_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + + +# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + +namespace Catch { + struct FatalConditionHandler { + void reset() {} + }; +} + +# else // CATCH_CONFIG_WINDOWS_SEH is defined namespace Catch { + struct SignalDefs { DWORD id; const char* name; }; + extern SignalDefs signalDefs[]; + // There is no 1-1 mapping between signals and windows exceptions. + // Windows can easily distinguish between SO and SigSegV, + // but SigInt, SigTerm, etc are handled differently. + SignalDefs signalDefs[] = { + { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, + { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, + { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, + { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" }, + }; + struct FatalConditionHandler { - void reset() {} - }; + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { + for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) { + reset(); + reportFatal(signalDefs[i].name); + } + } + // If its not an exception we care about, pass it along. + // This stops us from eating debugger breaks etc. + return EXCEPTION_CONTINUE_SEARCH; + } + + FatalConditionHandler() { + isSet = true; + // 32k seems enough for Catch to handle stack overflow, + // but the value was found experimentally, so there is no strong guarantee + guaranteeSize = 32 * 1024; + exceptionHandlerHandle = CATCH_NULL; + // Register as first handler in current chain + exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException); + // Pass in guarantee size to be filled + SetThreadStackGuarantee(&guaranteeSize); + } + + static void reset() { + if (isSet) { + // Unregister handler and restore the old guarantee + RemoveVectoredExceptionHandler(exceptionHandlerHandle); + SetThreadStackGuarantee(&guaranteeSize); + exceptionHandlerHandle = CATCH_NULL; + isSet = false; + } + } + + ~FatalConditionHandler() { + reset(); + } + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; + }; + + bool FatalConditionHandler::isSet = false; + ULONG FatalConditionHandler::guaranteeSize = 0; + PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL; } // namespace Catch +# endif // CATCH_CONFIG_WINDOWS_SEH + #else // Not Windows - assumed to be POSIX compatible ////////////////////////// #include <signal.h> namespace Catch { - struct SignalDefs { int id; const char* name; }; + struct SignalDefs { + int id; + const char* name; + }; extern SignalDefs signalDefs[]; SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, @@ -5827,35 +6275,66 @@ namespace Catch { { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, { SIGTERM, "SIGTERM - Termination request signal" }, { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } - }; + }; struct FatalConditionHandler { + static bool isSet; + static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)]; + static stack_t oldSigStack; + static char altStackMem[SIGSTKSZ]; + static void handleSignal( int sig ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - if( sig == signalDefs[i].id ) - fatal( signalDefs[i].name, -sig ); - fatal( "<unknown signal>", -sig ); + std::string name = "<unknown signal>"; + for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { + SignalDefs &def = signalDefs[i]; + if (sig == def.id) { + name = def.name; + break; + } + } + reset(); + reportFatal(name); + raise( sig ); } - FatalConditionHandler() : m_isSet( true ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, handleSignal ); + FatalConditionHandler() { + isSet = true; + stack_t sigStack; + sigStack.ss_sp = altStackMem; + sigStack.ss_size = SIGSTKSZ; + sigStack.ss_flags = 0; + sigaltstack(&sigStack, &oldSigStack); + struct sigaction sa = { 0 }; + + sa.sa_handler = handleSignal; + sa.sa_flags = SA_ONSTACK; + for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) { + sigaction(signalDefs[i].id, &sa, &oldSigActions[i]); + } } + ~FatalConditionHandler() { reset(); } - void reset() { - if( m_isSet ) { - for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) - signal( signalDefs[i].id, SIG_DFL ); - m_isSet = false; + static void reset() { + if( isSet ) { + // Set signals back to previous values -- hopefully nobody overwrote them in the meantime + for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) { + sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL); + } + // Return the old stack + sigaltstack(&oldSigStack, CATCH_NULL); + isSet = false; } } - - bool m_isSet; }; + bool FatalConditionHandler::isSet = false; + struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {}; + stack_t FatalConditionHandler::oldSigStack = {}; + char FatalConditionHandler::altStackMem[SIGSTKSZ] = {}; + } // namespace Catch #endif // not Windows @@ -5934,10 +6413,12 @@ namespace Catch { m_activeTestCase = &testCase; do { - m_trackerContext.startRun(); + ITracker& rootTracker = m_trackerContext.startRun(); + assert( rootTracker.isSectionTracker() ); + static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() ); do { m_trackerContext.startCycle(); - m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name ); + m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) ); runCurrentTest( redirectedCout, redirectedCerr ); } while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() ); @@ -5982,7 +6463,7 @@ namespace Catch { m_messages.clear(); // Reset working state - m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); + m_lastAssertionInfo = AssertionInfo( std::string(), m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); m_lastResult = result; } @@ -5991,10 +6472,7 @@ namespace Catch { Counts& assertions ) { - std::ostringstream oss; - oss << sectionInfo.name << "@" << sectionInfo.lineInfo; - - ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() ); + ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) ); if( !sectionTracker.isOpen() ) return false; m_activeSections.push_back( §ionTracker ); @@ -6053,7 +6531,7 @@ namespace Catch { virtual std::string getCurrentTestName() const { return m_activeTestCase ? m_activeTestCase->getTestCaseInfo().name - : ""; + : std::string(); } virtual const AssertionResult* getLastResult() const { @@ -6083,11 +6561,11 @@ namespace Catch { deltaTotals.testCases.failed = 1; m_reporter->testCaseEnded( TestCaseStats( testInfo, deltaTotals, - "", - "", + std::string(), + std::string(), false ) ); m_totals.testCases.failed++; - testGroupEnded( "", m_totals, 1, 1 ); + testGroupEnded( std::string(), m_totals, 1, 1 ); m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) ); } @@ -6106,7 +6584,7 @@ namespace Catch { Counts prevAssertions = m_totals.assertions; double duration = 0; try { - m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); + m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, std::string(), ResultDisposition::Normal ); seedRng( *m_config ); @@ -6436,16 +6914,29 @@ namespace Catch { #include <vector> #include <set> #include <sstream> -#include <iostream> #include <algorithm> namespace Catch { - struct LexSort { - bool operator() (TestCase i,TestCase j) const { return (i<j);} - }; struct RandomNumberGenerator { - int operator()( int n ) const { return std::rand() % n; } + typedef std::ptrdiff_t result_type; + + result_type operator()( result_type n ) const { return std::rand() % n; } + +#ifdef CATCH_CONFIG_CPP11_SHUFFLE + static constexpr result_type min() { return 0; } + static constexpr result_type max() { return 1000000; } + result_type operator()() const { return std::rand() % max(); } +#endif + template<typename V> + static void shuffle( V& vector ) { + RandomNumberGenerator rng; +#ifdef CATCH_CONFIG_CPP11_SHUFFLE + std::shuffle( vector.begin(), vector.end(), rng ); +#else + std::random_shuffle( vector.begin(), vector.end(), rng ); +#endif + } }; inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) { @@ -6454,14 +6945,12 @@ namespace Catch { switch( config.runOrder() ) { case RunTests::InLexicographicalOrder: - std::sort( sorted.begin(), sorted.end(), LexSort() ); + std::sort( sorted.begin(), sorted.end() ); break; case RunTests::InRandomOrder: { seedRng( config ); - - RandomNumberGenerator rng; - std::random_shuffle( sorted.begin(), sorted.end(), rng ); + RandomNumberGenerator::shuffle( sorted ); } break; case RunTests::InDeclarationOrder: @@ -6485,7 +6974,7 @@ namespace Catch { ss << Colour( Colour::Red ) << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n" - << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" + << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n' << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl; throw std::runtime_error(ss.str()); @@ -6517,7 +7006,7 @@ namespace Catch { virtual void registerTest( TestCase const& testCase ) { std::string name = testCase.getTestCaseInfo().name; - if( name == "" ) { + if( name.empty() ) { std::ostringstream oss; oss << "Anonymous test case " << ++m_unnamedCount; return registerTest( testCase.withName( oss.str() ) ); @@ -6566,7 +7055,7 @@ namespace Catch { inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) { std::string className = classOrQualifiedMethodName; - if( startsWith( className, "&" ) ) + if( startsWith( className, '&' ) ) { std::size_t lastColons = className.rfind( "::" ); std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); @@ -6784,7 +7273,7 @@ namespace Catch { // #included from: catch_notimplemented_exception.hpp #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED -#include <ostream> +#include <sstream> namespace Catch { @@ -6856,7 +7345,7 @@ namespace Catch { m_ofs.open( filename.c_str() ); if( m_ofs.fail() ) { std::ostringstream oss; - oss << "Unable to open file: '" << filename << "'"; + oss << "Unable to open file: '" << filename << '\''; throw std::domain_error( oss.str() ); } } @@ -6909,6 +7398,11 @@ namespace Catch { Context( Context const& ); void operator=( Context const& ); + public: + virtual ~Context() { + deleteAllValues( m_generatorsByTestName ); + } + public: // IContext virtual IResultCapture* getResultCapture() { return m_resultCapture; @@ -7022,16 +7516,6 @@ namespace Catch { #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// -#ifndef NOMINMAX -#define NOMINMAX -#endif - -#ifdef __AFXDLL -#include <AfxWin.h> -#else -#include <windows.h> -#endif - namespace Catch { namespace { @@ -7112,7 +7596,7 @@ namespace { case Colour::White: return setColour( "[0m" ); case Colour::Red: return setColour( "[0;31m" ); case Colour::Green: return setColour( "[0;32m" ); - case Colour::Blue: return setColour( "[0:34m" ); + case Colour::Blue: return setColour( "[0;34m" ); case Colour::Cyan: return setColour( "[0;36m" ); case Colour::Yellow: return setColour( "[0;33m" ); case Colour::Grey: return setColour( "[1;30m" ); @@ -7298,7 +7782,7 @@ namespace Catch { std::string AssertionResult::getExpression() const { if( isFalseTest( m_info.resultDisposition ) ) - return "!" + m_info.capturedExpression; + return '!' + m_info.capturedExpression; else return m_info.capturedExpression; } @@ -7314,7 +7798,7 @@ namespace Catch { } std::string AssertionResult::getExpandedExpression() const { - return m_resultData.reconstructedExpression; + return m_resultData.reconstructExpression(); } std::string AssertionResult::getMessage() const { @@ -7328,15 +7812,25 @@ namespace Catch { return m_info.macroName; } + void AssertionResult::discardDecomposedExpression() const { + m_resultData.decomposedExpression = CATCH_NULL; + } + + void AssertionResult::expandDecomposedExpression() const { + m_resultData.reconstructExpression(); + } + } // end namespace Catch // #included from: catch_test_case_info.hpp #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED +#include <cctype> + namespace Catch { inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { - if( startsWith( tag, "." ) || + if( startsWith( tag, '.' ) || tag == "hide" || tag == "!hide" ) return TestCaseInfo::IsHidden; @@ -7346,11 +7840,13 @@ namespace Catch { return TestCaseInfo::ShouldFail; else if( tag == "!mayfail" ) return TestCaseInfo::MayFail; + else if( tag == "!nonportable" ) + return TestCaseInfo::NonPortable; else return TestCaseInfo::None; } inline bool isReservedTag( std::string const& tag ) { - return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] ); + return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] ); } inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { if( isReservedTag( tag ) ) { @@ -7420,7 +7916,7 @@ namespace Catch { std::ostringstream oss; for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) { - oss << "[" << *it << "]"; + oss << '[' << *it << ']'; std::string lcaseTag = toLower( *it ); testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); testCaseInfo.lcaseTags.insert( lcaseTag ); @@ -7536,18 +8032,18 @@ namespace Catch { {} std::ostream& operator << ( std::ostream& os, Version const& version ) { - os << version.majorVersion << "." - << version.minorVersion << "." + os << version.majorVersion << '.' + << version.minorVersion << '.' << version.patchNumber; if( !version.branchName.empty() ) { - os << "-" << version.branchName - << "." << version.buildNumber; + os << '-' << version.branchName + << '.' << version.buildNumber; } return os; } - Version libraryVersion( 1, 5, 4, "", 0 ); + Version libraryVersion( 1, 7, 2, "", 0 ); } @@ -7718,7 +8214,6 @@ namespace Catch #endif #ifdef CATCH_PLATFORM_WINDOWS -#include <windows.h> #else #include <sys/time.h> #endif @@ -7767,19 +8262,31 @@ namespace Catch { // #included from: catch_common.hpp #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED +#include <cstring> +#include <cctype> + namespace Catch { bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix; + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; } bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix; + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; } bool contains( std::string const& s, std::string const& infix ) { return s.find( infix ) != std::string::npos; } + char toLowerCh(char c) { + return static_cast<char>( std::tolower( c ) ); + } void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), ::tolower ); + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); } std::string toLower( std::string const& s ) { std::string lc = s; @@ -7791,7 +8298,7 @@ namespace Catch { std::string::size_type start = str.find_first_not_of( whitespaceChars ); std::string::size_type end = str.find_last_not_of( whitespaceChars ); - return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); } bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { @@ -7814,29 +8321,25 @@ namespace Catch { {} std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << " " << pluraliser.m_label; + os << pluraliser.m_count << ' ' << pluraliser.m_label; if( pluraliser.m_count != 1 ) - os << "s"; + os << 's'; return os; } - SourceLineInfo::SourceLineInfo() : line( 0 ){} + SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){} SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) : file( _file ), line( _line ) {} - SourceLineInfo::SourceLineInfo( SourceLineInfo const& other ) - : file( other.file ), - line( other.line ) - {} bool SourceLineInfo::empty() const { - return file.empty(); + return file[0] == '\0'; } bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const { - return line == other.line && file == other.file; + return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0); } bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const { - return line < other.line || ( line == other.line && file < other.file ); + return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); } void seedRng( IConfig const& config ) { @@ -7849,16 +8352,16 @@ namespace Catch { std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { #ifndef __GNUG__ - os << info.file << "(" << info.line << ")"; + os << info.file << '(' << info.line << ')'; #else - os << info.file << ":" << info.line; + os << info.file << ':' << info.line; #endif return os; } void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) { std::ostringstream oss; - oss << locationInfo << ": Internal Catch error: '" << message << "'"; + oss << locationInfo << ": Internal Catch error: '" << message << '\''; if( alwaysTrue() ) throw std::logic_error( oss.str() ); } @@ -7905,8 +8408,6 @@ namespace Catch { // #included from: catch_debugger.hpp #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED -#include <iostream> - #ifdef CATCH_PLATFORM_MAC #include <assert.h> @@ -7955,6 +8456,33 @@ namespace Catch { } } // namespace Catch +#elif defined(CATCH_PLATFORM_LINUX) + #include <fstream> + #include <string> + + namespace Catch{ + // The standard POSIX way of detecting a debugger is to attempt to + // ptrace() the process, but this needs to be done from a child and not + // this process itself to still allow attaching to this process later + // if wanted, so is rather heavy. Under Linux we have the PID of the + // "debugger" (which doesn't need to be gdb, of course, it could also + // be strace, for example) in /proc/$PID/status, so just get it from + // there instead. + bool isDebuggerActive(){ + std::ifstream in("/proc/self/status"); + for( std::string line; std::getline(in, line); ) { + static const int PREFIX_LEN = 11; + if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) { + // We're traced if the PID is not 0 and no other PID starts + // with 0 digit, so it's enough to check for just a single + // character. + return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0'; + } + } + + return false; + } + } // namespace Catch #elif defined(_MSC_VER) extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); namespace Catch { @@ -7976,7 +8504,7 @@ namespace Catch { #endif // Platform #ifdef CATCH_PLATFORM_WINDOWS - extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); + namespace Catch { void writeToDebugConsole( std::string const& text ) { ::OutputDebugStringA( text.c_str() ); @@ -8052,7 +8580,7 @@ std::string toString( std::string const& value ) { } } } - return "\"" + s + "\""; + return '"' + s + '"'; } std::string toString( std::wstring const& value ) { @@ -8073,19 +8601,19 @@ std::string toString( char* const value ) { std::string toString( const wchar_t* const value ) { - return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); + return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); } std::string toString( wchar_t* const value ) { - return Catch::toString( static_cast<const wchar_t*>( value ) ); + return Catch::toString( static_cast<const wchar_t*>( value ) ); } std::string toString( int value ) { std::ostringstream oss; oss << value; if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ")"; + oss << " (0x" << std::hex << value << ')'; return oss.str(); } @@ -8093,7 +8621,7 @@ std::string toString( unsigned long value ) { std::ostringstream oss; oss << value; if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ")"; + oss << " (0x" << std::hex << value << ')'; return oss.str(); } @@ -8121,7 +8649,7 @@ std::string toString( const double value ) { return fpToString( value, 10 ); } std::string toString( const float value ) { - return fpToString( value, 5 ) + "f"; + return fpToString( value, 5 ) + 'f'; } std::string toString( bool value ) { @@ -8129,9 +8657,19 @@ std::string toString( bool value ) { } std::string toString( char value ) { - return value < ' ' - ? toString( static_cast<unsigned int>( value ) ) - : Detail::makeString( value ); + if ( value == '\r' ) + return "'\\r'"; + if ( value == '\f' ) + return "'\\f'"; + if ( value == '\n' ) + return "'\\n'"; + if ( value == '\t' ) + return "'\\t'"; + if ( '\0' <= value && value < ' ' ) + return toString( static_cast<unsigned int>( value ) ); + char chstr[] = "' '"; + chstr[1] = value; + return chstr; } std::string toString( signed char value ) { @@ -8147,14 +8685,14 @@ std::string toString( long long value ) { std::ostringstream oss; oss << value; if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ")"; + oss << " (0x" << std::hex << value << ')'; return oss.str(); } std::string toString( unsigned long long value ) { std::ostringstream oss; oss << value; if( value > Detail::hexThreshold ) - oss << " (0x" << std::hex << value << ")"; + oss << " (0x" << std::hex << value << ')'; return oss.str(); } #endif @@ -8211,22 +8749,10 @@ namespace Catch { m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; return *this; } - ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) { - m_exprComponents.lhs = lhs; - return *this; - } - ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) { - m_exprComponents.rhs = rhs; - return *this; - } - ResultBuilder& ResultBuilder::setOp( std::string const& op ) { - m_exprComponents.op = op; - return *this; - } - void ResultBuilder::endExpression() { - m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition ); - captureExpression(); + void ResultBuilder::endExpression( DecomposedExpression const& expr ) { + AssertionResult result = build( expr ); + handleResult( result ); } void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) { @@ -8239,6 +8765,7 @@ namespace Catch { setResultType( resultType ); captureExpression(); } + void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) { if( expectedMessage.empty() ) captureExpectedException( Matchers::Impl::Generic::AllOf<std::string>() ); @@ -8248,7 +8775,7 @@ namespace Catch { void ResultBuilder::captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ) { - assert( m_exprComponents.testFalse == false ); + assert( !isFalseTest( m_assertionInfo.resultDisposition ) ); AssertionResultData data = m_data; data.resultType = ResultWas::Ok; data.reconstructedExpression = m_assertionInfo.capturedExpression; @@ -8266,6 +8793,7 @@ namespace Catch { AssertionResult result = build(); handleResult( result ); } + void ResultBuilder::handleResult( AssertionResult const& result ) { getResultCapture().assertionEnded( result ); @@ -8277,6 +8805,7 @@ namespace Catch { m_shouldThrow = true; } } + void ResultBuilder::react() { if( m_shouldThrow ) throw Catch::TestFailureException(); @@ -8287,43 +8816,32 @@ namespace Catch { AssertionResult ResultBuilder::build() const { - assert( m_data.resultType != ResultWas::Unknown ); + return build( *this ); + } + // CAVEAT: The returned AssertionResult stores a pointer to the argument expr, + // a temporary DecomposedExpression, which in turn holds references to + // operands, possibly temporary as well. + // It should immediately be passed to handleResult; if the expression + // needs to be reported, its string expansion must be composed before + // the temporaries are destroyed. + AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const + { + assert( m_data.resultType != ResultWas::Unknown ); AssertionResultData data = m_data; - // Flip bool results if testFalse is set - if( m_exprComponents.testFalse ) { - if( data.resultType == ResultWas::Ok ) - data.resultType = ResultWas::ExpressionFailed; - else if( data.resultType == ResultWas::ExpressionFailed ) - data.resultType = ResultWas::Ok; + // Flip bool results if FalseTest flag is set + if( isFalseTest( m_assertionInfo.resultDisposition ) ) { + data.negate( expr.isBinaryExpression() ); } data.message = m_stream.oss.str(); - data.reconstructedExpression = reconstructExpression(); - if( m_exprComponents.testFalse ) { - if( m_exprComponents.op == "" ) - data.reconstructedExpression = "!" + data.reconstructedExpression; - else - data.reconstructedExpression = "!(" + data.reconstructedExpression + ")"; - } + data.decomposedExpression = &expr; // for lazy reconstruction return AssertionResult( m_assertionInfo, data ); } - std::string ResultBuilder::reconstructExpression() const { - if( m_exprComponents.op == "" ) - return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; - else if( m_exprComponents.op == "matches" ) - return m_exprComponents.lhs + " " + m_exprComponents.rhs; - else if( m_exprComponents.op != "!" ) { - if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 && - m_exprComponents.lhs.find("\n") == std::string::npos && - m_exprComponents.rhs.find("\n") == std::string::npos ) - return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs; - else - return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs; - } - else - return "{can't expand - use " + m_assertionInfo.macroName + "_FALSE( " + m_assertionInfo.capturedExpression.substr(1) + " ) instead of " + m_assertionInfo.macroName + "( " + m_assertionInfo.capturedExpression + " ) for better diagnostics}"; + + void ResultBuilder::reconstructExpression( std::string& dest ) const { + dest = m_assertionInfo.capturedExpression; } } // end namespace Catch @@ -8352,9 +8870,6 @@ namespace Catch { } // end namespace Catch -#include <map> -#include <iostream> - namespace Catch { TagAliasRegistry::~TagAliasRegistry() {} @@ -8384,7 +8899,7 @@ namespace Catch { void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { - if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) { + if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) { std::ostringstream oss; oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo; throw std::domain_error( oss.str().c_str() ); @@ -8392,7 +8907,7 @@ namespace Catch { if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) { std::ostringstream oss; oss << "error: tag alias, \"" << alias << "\" already registered.\n" - << "\tFirst seen at " << find(alias)->lineInfo << "\n" + << "\tFirst seen at " << find(alias)->lineInfo << '\n' << "\tRedefined at " << lineInfo; throw std::domain_error( oss.str().c_str() ); } @@ -8660,12 +9175,12 @@ namespace Catch { struct BySectionInfo { BySectionInfo( SectionInfo const& other ) : m_other( other ) {} - BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} + BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} bool operator() ( Ptr<SectionNode> const& node ) const { return node->stats.sectionInfo.lineInfo == m_other.lineInfo; } private: - void operator=( BySectionInfo const& ); + void operator=( BySectionInfo const& ); SectionInfo const& m_other; }; @@ -8721,6 +9236,12 @@ namespace Catch { assert( !m_sectionStack.empty() ); SectionNode& sectionNode = *m_sectionStack.back(); sectionNode.assertions.push_back( assertionStats ); + // AssertionResult holds a pointer to a temporary DecomposedExpression, + // which getExpandedExpression() calls to build the expression string. + // Our section stack copy of the assertionResult will likely outlive the + // temporary, so it must be expanded or discarded now to avoid calling + // a destroyed object later. + prepareExpandedExpression( sectionNode.assertions.back().assertionResult ); return true; } virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { @@ -8755,6 +9276,13 @@ namespace Catch { virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {} + virtual void prepareExpandedExpression( AssertionResult& result ) const { + if( result.isOk() ) + result.discardDecomposedExpression(); + else + result.expandDecomposedExpression(); + } + Ptr<IConfig const> m_config; std::ostream& stream; std::vector<AssertionStats> m_assertions; @@ -8775,7 +9303,7 @@ namespace Catch { char const* getLineOfChars() { static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; if( !*line ) { - memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); + std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; } return line; @@ -8860,7 +9388,7 @@ namespace Catch { return new T( config ); } virtual std::string getDescription() const { - return ""; + return std::string(); } }; @@ -8927,9 +9455,13 @@ namespace Catch { break; default: - // Escape control chars - based on contribution by @espenalb in PR #465 - if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) - os << "&#x" << std::uppercase << std::hex << static_cast<int>( c ); + // Escape control chars - based on contribution by @espenalb in PR #465 and + // by @mrpi PR #588 + if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) { + // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0 + os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) + << static_cast<int>( c ); + } else os << c; } @@ -8983,14 +9515,18 @@ namespace Catch { XmlWriter() : m_tagIsOpen( false ), m_needsNewline( false ), - m_os( &Catch::cout() ) - {} + m_os( Catch::cout() ) + { + writeDeclaration(); + } XmlWriter( std::ostream& os ) : m_tagIsOpen( false ), m_needsNewline( false ), - m_os( &os ) - {} + m_os( os ) + { + writeDeclaration(); + } ~XmlWriter() { while( !m_tags.empty() ) @@ -9000,7 +9536,7 @@ namespace Catch { XmlWriter& startElement( std::string const& name ) { ensureTagClosed(); newlineIfNecessary(); - stream() << m_indent << "<" << name; + m_os << m_indent << '<' << name; m_tags.push_back( name ); m_indent += " "; m_tagIsOpen = true; @@ -9017,24 +9553,25 @@ namespace Catch { newlineIfNecessary(); m_indent = m_indent.substr( 0, m_indent.size()-2 ); if( m_tagIsOpen ) { - stream() << "/>\n"; + m_os << "/>"; m_tagIsOpen = false; } else { - stream() << m_indent << "</" << m_tags.back() << ">\n"; + m_os << m_indent << "</" << m_tags.back() << ">"; } + m_os << std::endl; m_tags.pop_back(); return *this; } XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { if( !name.empty() && !attribute.empty() ) - stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\""; + m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"'; return *this; } XmlWriter& writeAttribute( std::string const& name, bool attribute ) { - stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; + m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"'; return *this; } @@ -9050,8 +9587,8 @@ namespace Catch { bool tagWasOpen = m_tagIsOpen; ensureTagClosed(); if( tagWasOpen && indent ) - stream() << m_indent; - stream() << XmlEncode( text ); + m_os << m_indent; + m_os << XmlEncode( text ); m_needsNewline = true; } return *this; @@ -9059,39 +9596,39 @@ namespace Catch { XmlWriter& writeComment( std::string const& text ) { ensureTagClosed(); - stream() << m_indent << "<!--" << text << "-->"; + m_os << m_indent << "<!--" << text << "-->"; m_needsNewline = true; return *this; } + void writeStylesheetRef( std::string const& url ) { + m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n"; + } + XmlWriter& writeBlankLine() { ensureTagClosed(); - stream() << "\n"; + m_os << '\n'; return *this; } - void setStream( std::ostream& os ) { - m_os = &os; + void ensureTagClosed() { + if( m_tagIsOpen ) { + m_os << ">" << std::endl; + m_tagIsOpen = false; + } } private: XmlWriter( XmlWriter const& ); void operator=( XmlWriter const& ); - std::ostream& stream() { - return *m_os; - } - - void ensureTagClosed() { - if( m_tagIsOpen ) { - stream() << ">\n"; - m_tagIsOpen = false; - } + void writeDeclaration() { + m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; } void newlineIfNecessary() { if( m_needsNewline ) { - stream() << "\n"; + m_os << std::endl; m_needsNewline = false; } } @@ -9100,7 +9637,7 @@ namespace Catch { bool m_needsNewline; std::vector<std::string> m_tags; std::string m_indent; - std::ostream* m_os; + std::ostream& m_os; }; } @@ -9124,6 +9661,7 @@ namespace Catch { public: XmlReporter( ReporterConfig const& _config ) : StreamingReporterBase( _config ), + m_xml(_config.stream()), m_sectionDepth( 0 ) { m_reporterPrefs.shouldRedirectStdOut = true; @@ -9135,6 +9673,10 @@ namespace Catch { return "Reports test results as an XML document"; } + virtual std::string getStylesheetRef() const { + return std::string(); + } + public: // StreamingReporterBase virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE { @@ -9143,7 +9685,9 @@ namespace Catch { virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE { StreamingReporterBase::testRunStarting( testInfo ); - m_xml.setStream( stream ); + std::string stylesheetRef = getStylesheetRef(); + if( !stylesheetRef.empty() ) + m_xml.writeStylesheetRef( stylesheetRef ); m_xml.startElement( "Catch" ); if( !m_config->name().empty() ) m_xml.writeAttribute( "name", m_config->name() ); @@ -9157,10 +9701,14 @@ namespace Catch { virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { StreamingReporterBase::testCaseStarting(testInfo); - m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); + m_xml.startElement( "TestCase" ) + .writeAttribute( "name", trim( testInfo.name ) ) + .writeAttribute( "description", testInfo.description ) + .writeAttribute( "tags", testInfo.tagsAsString ); if ( m_config->showDurations() == ShowDurations::Always ) m_testCaseTimer.start(); + m_xml.ensureTagClosed(); } virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { @@ -9169,6 +9717,7 @@ namespace Catch { m_xml.startElement( "Section" ) .writeAttribute( "name", trim( sectionInfo.name ) ) .writeAttribute( "description", sectionInfo.description ); + m_xml.ensureTagClosed(); } } @@ -9200,7 +9749,7 @@ namespace Catch { if( assertionResult.hasExpression() ) { m_xml.startElement( "Expression" ) .writeAttribute( "success", assertionResult.succeeded() ) - .writeAttribute( "type", assertionResult.getTestMacroName() ) + .writeAttribute( "type", assertionResult.getTestMacroName() ) .writeAttribute( "filename", assertionResult.getSourceInfo().file ) .writeAttribute( "line", assertionResult.getSourceInfo().line ); @@ -9219,7 +9768,7 @@ namespace Catch { .writeText( assertionResult.getMessage() ); break; case ResultWas::FatalErrorCondition: - m_xml.scopedElement( "Fatal Error Condition" ) + m_xml.scopedElement( "FatalErrorCondition" ) .writeAttribute( "filename", assertionResult.getSourceInfo().file ) .writeAttribute( "line", assertionResult.getSourceInfo().line ) .writeText( assertionResult.getMessage() ); @@ -9268,6 +9817,11 @@ namespace Catch { if ( m_config->showDurations() == ShowDurations::Always ) e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); + if( !testCaseStats.stdOut.empty() ) + m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); + if( !testCaseStats.stdErr.empty() ) + m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); + m_xml.endElement(); } @@ -9307,6 +9861,35 @@ namespace Catch { namespace Catch { + namespace { + std::string getCurrentTimestamp() { + // Beware, this is not reentrant because of backward compatibility issues + // Also, UTC only, again because of backward compatibility (%z is C++11) + time_t rawtime; + std::time(&rawtime); + const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z"); + +#ifdef _MSC_VER + std::tm timeInfo = {}; + gmtime_s(&timeInfo, &rawtime); +#else + std::tm* timeInfo; + timeInfo = std::gmtime(&rawtime); +#endif + + char timeStamp[timeStampSize]; + const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + +#ifdef _MSC_VER + std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); +#else + std::strftime(timeStamp, timeStampSize, fmt, timeInfo); +#endif + return std::string(timeStamp); + } + + } + class JunitReporter : public CumulativeReporterBase { public: JunitReporter( ReporterConfig const& _config ) @@ -9371,7 +9954,7 @@ namespace Catch { xml.writeAttribute( "time", "" ); else xml.writeAttribute( "time", suiteTime ); - xml.writeAttribute( "timestamp", "tbd" ); // !TBD + xml.writeAttribute( "timestamp", getCurrentTimestamp() ); // Write test cases for( TestGroupNode::ChildNodes::const_iterator @@ -9406,7 +9989,7 @@ namespace Catch { SectionNode const& sectionNode ) { std::string name = trim( sectionNode.stats.sectionInfo.name ); if( !rootName.empty() ) - name = rootName + "/" + name; + name = rootName + '/' + name; if( !sectionNode.assertions.empty() || !sectionNode.stdOut.empty() || @@ -9484,14 +10067,14 @@ namespace Catch { std::ostringstream oss; if( !result.getMessage().empty() ) - oss << result.getMessage() << "\n"; + oss << result.getMessage() << '\n'; for( std::vector<MessageInfo>::const_iterator it = stats.infoMessages.begin(), itEnd = stats.infoMessages.end(); it != itEnd; ++it ) if( it->type == ResultWas::Info ) - oss << it->message << "\n"; + oss << it->message << '\n'; oss << "at " << result.getSourceInfo(); xml.writeText( oss.str(), false ); @@ -9526,7 +10109,7 @@ namespace Catch { } virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { - stream << "No test cases matched '" << spec << "'" << std::endl; + stream << "No test cases matched '" << spec << '\'' << std::endl; } virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { @@ -9568,12 +10151,12 @@ namespace Catch { } if( m_headerPrinted ) { if( m_config->showDurations() == ShowDurations::Always ) - stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl; + stream << "Completed in " << _sectionStats.durationInSeconds << 's' << std::endl; m_headerPrinted = false; } else { if( m_config->showDurations() == ShowDurations::Always ) - stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl; + stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << 's' << std::endl; } StreamingReporterBase::sectionEnded( _sectionStats ); } @@ -9587,7 +10170,7 @@ namespace Catch { printSummaryDivider(); stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; printTotals( _testGroupStats.totals ); - stream << "\n" << std::endl; + stream << '\n' << std::endl; } StreamingReporterBase::testGroupEnded( _testGroupStats ); } @@ -9679,13 +10262,13 @@ namespace Catch { printSourceInfo(); if( stats.totals.assertions.total() > 0 ) { if( result.isOk() ) - stream << "\n"; + stream << '\n'; printResultType(); printOriginalExpression(); printReconstructedExpression(); } else { - stream << "\n"; + stream << '\n'; } printMessage(); } @@ -9702,25 +10285,25 @@ namespace Catch { Colour colourGuard( Colour::OriginalExpression ); stream << " "; stream << result.getExpressionInMacro(); - stream << "\n"; + stream << '\n'; } } void printReconstructedExpression() const { if( result.hasExpandedExpression() ) { stream << "with expansion:\n"; Colour colourGuard( Colour::ReconstructedExpression ); - stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n"; + stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n'; } } void printMessage() const { if( !messageLabel.empty() ) - stream << messageLabel << ":" << "\n"; + stream << messageLabel << ':' << '\n'; for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end(); it != itEnd; ++it ) { // If this assertion is a warning ignore any INFO messages if( printInfoMessages || it->type != ResultWas::Info ) - stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n"; + stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n'; } } void printSourceInfo() const { @@ -9752,7 +10335,7 @@ namespace Catch { } } void lazyPrintRunInfo() { - stream << "\n" << getLineOfChars<'~'>() << "\n"; + stream << '\n' << getLineOfChars<'~'>() << '\n'; Colour colour( Colour::SecondaryText ); stream << currentTestRunInfo->name << " is a Catch v" << libraryVersion << " host application.\n" @@ -9783,22 +10366,22 @@ namespace Catch { printHeaderString( it->name, 2 ); } - SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; + SourceLineInfo lineInfo = m_sectionStack.back().lineInfo; if( !lineInfo.empty() ){ - stream << getLineOfChars<'-'>() << "\n"; + stream << getLineOfChars<'-'>() << '\n'; Colour colourGuard( Colour::FileName ); - stream << lineInfo << "\n"; + stream << lineInfo << '\n'; } - stream << getLineOfChars<'.'>() << "\n" << std::endl; + stream << getLineOfChars<'.'>() << '\n' << std::endl; } void printClosedHeader( std::string const& _name ) { printOpenHeader( _name ); - stream << getLineOfChars<'.'>() << "\n"; + stream << getLineOfChars<'.'>() << '\n'; } void printOpenHeader( std::string const& _name ) { - stream << getLineOfChars<'-'>() << "\n"; + stream << getLineOfChars<'-'>() << '\n'; { Colour colourGuard( Colour::Headers ); printHeaderString( _name ); @@ -9815,7 +10398,7 @@ namespace Catch { i = 0; stream << Text( _string, TextAttributes() .setIndent( indent+i) - .setInitialIndent( indent ) ) << "\n"; + .setInitialIndent( indent ) ) << '\n'; } struct SummaryColumn { @@ -9830,9 +10413,9 @@ namespace Catch { std::string row = oss.str(); for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) { while( it->size() < row.size() ) - *it = " " + *it; + *it = ' ' + *it; while( it->size() > row.size() ) - row = " " + row; + row = ' ' + row; } rows.push_back( row ); return *this; @@ -9852,8 +10435,8 @@ namespace Catch { stream << Colour( Colour::ResultSuccess ) << "All tests passed"; stream << " (" << pluralise( totals.assertions.passed, "assertion" ) << " in " - << pluralise( totals.testCases.passed, "test case" ) << ")" - << "\n"; + << pluralise( totals.testCases.passed, "test case" ) << ')' + << '\n'; } else { @@ -9888,10 +10471,10 @@ namespace Catch { else if( value != "0" ) { stream << Colour( Colour::LightGrey ) << " | "; stream << Colour( it->colour ) - << value << " " << it->label; + << value << ' ' << it->label; } } - stream << "\n"; + stream << '\n'; } static std::size_t makeRatio( std::size_t number, std::size_t total ) { @@ -9927,10 +10510,10 @@ namespace Catch { else { stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); } - stream << "\n"; + stream << '\n'; } void printSummaryDivider() { - stream << getLineOfChars<'-'>() << "\n"; + stream << getLineOfChars<'-'>() << '\n'; } private: @@ -9965,7 +10548,7 @@ namespace Catch { } virtual void noMatchingTestCases( std::string const& spec ) { - stream << "No test cases matched '" << spec << "'" << std::endl; + stream << "No test cases matched '" << spec << '\'' << std::endl; } virtual void assertionStarting( AssertionInfo const& ) { @@ -9992,7 +10575,7 @@ namespace Catch { virtual void testRunEnded( TestRunStats const& _testRunStats ) { printTotals( _testRunStats.totals ); - stream << "\n" << std::endl; + stream << '\n' << std::endl; StreamingReporterBase::testRunEnded( _testRunStats ); } @@ -10092,26 +10675,26 @@ namespace Catch { void printSourceInfo() const { Colour colourGuard( Colour::FileName ); - stream << result.getSourceInfo() << ":"; + stream << result.getSourceInfo() << ':'; } void printResultType( Colour::Code colour, std::string passOrFail ) const { if( !passOrFail.empty() ) { { Colour colourGuard( colour ); - stream << " " << passOrFail; + stream << ' ' << passOrFail; } - stream << ":"; + stream << ':'; } } void printIssue( std::string issue ) const { - stream << " " << issue; + stream << ' ' << issue; } void printExpressionWas() { if( result.hasExpression() ) { - stream << ";"; + stream << ';'; { Colour colour( dimColour() ); stream << " expression was:"; @@ -10122,7 +10705,7 @@ namespace Catch { void printOriginalExpression() const { if( result.hasExpression() ) { - stream << " " << result.getExpression(); + stream << ' ' << result.getExpression(); } } @@ -10138,7 +10721,7 @@ namespace Catch { void printMessage() { if ( itMessage != messages.end() ) { - stream << " '" << itMessage->message << "'"; + stream << " '" << itMessage->message << '\''; ++itMessage; } } @@ -10153,13 +10736,13 @@ namespace Catch { { Colour colourGuard( colour ); - stream << " with " << pluralise( N, "message" ) << ":"; + stream << " with " << pluralise( N, "message" ) << ':'; } for(; itMessage != itEnd; ) { // If this assertion is a warning ignore any INFO messages if( printInfoMessages || itMessage->type != ResultWas::Info ) { - stream << " '" << itMessage->message << "'"; + stream << " '" << itMessage->message << '\''; if ( ++itMessage != itEnd ) { Colour colourGuard( dimColour() ); stream << " and"; @@ -10185,7 +10768,7 @@ namespace Catch { // - green: Passed [both/all] N tests cases with M assertions. std::string bothOrAll( std::size_t count ) const { - return count == 1 ? "" : count == 2 ? "both " : "all " ; + return count == 1 ? std::string() : count == 2 ? "both " : "all " ; } void printTotals( const Totals& totals ) const { @@ -10196,12 +10779,12 @@ namespace Catch { Colour colour( Colour::ResultError ); const std::string qualify_assertions_failed = totals.assertions.failed == totals.assertions.total() ? - bothOrAll( totals.assertions.failed ) : ""; + bothOrAll( totals.assertions.failed ) : std::string(); stream << "Failed " << bothOrAll( totals.testCases.failed ) << pluralise( totals.testCases.failed, "test case" ) << ", " "failed " << qualify_assertions_failed << - pluralise( totals.assertions.failed, "assertion" ) << "."; + pluralise( totals.assertions.failed, "assertion" ) << '.'; } else if( totals.assertions.total() == 0 ) { stream << @@ -10213,14 +10796,14 @@ namespace Catch { Colour colour( Colour::ResultError ); stream << "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " - "failed " << pluralise( totals.assertions.failed, "assertion" ) << "."; + "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.'; } else { Colour colour( Colour::ResultSuccess ); stream << "Passed " << bothOrAll( totals.testCases.passed ) << pluralise( totals.testCases.passed, "test case" ) << - " with " << pluralise( totals.assertions.passed, "assertion" ) << "."; + " with " << pluralise( totals.assertions.passed, "assertion" ) << '.'; } } }; @@ -10306,7 +10889,8 @@ namespace Catch { // Standard C/C++ main entry point int main (int argc, char * argv[]) { - return Catch::Session().run( argc, argv ); + int result = Catch::Session().run( argc, argv ); + return ( result < 0xff ? result : 0xff ); } #else // __OBJC__ @@ -10324,7 +10908,7 @@ int main (int argc, char * const argv[]) { [pool drain]; #endif - return result; + return ( result < 0xff ? result : 0xff ); } #endif // __OBJC__ @@ -10354,12 +10938,12 @@ int main (int argc, char * const argv[]) { #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" ) #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" ) -#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" ) +#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CATCH_CHECK_THROWS" ) #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" ) #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" ) #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" ) -#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) +#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" ) #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) diff --git a/3rdparty/bx/LICENSE b/3rdparty/bx/LICENSE index f18446330b4..dd17ed45ef3 100644 --- a/3rdparty/bx/LICENSE +++ b/3rdparty/bx/LICENSE @@ -1,7 +1,5 @@ Copyright 2010-2017 Branimir Karadzic. All rights reserved. -https://github.com/bkaradzic/bx - Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: @@ -22,5 +20,3 @@ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -https://github.com/bkaradzic/bx/blob/master/LICENSE diff --git a/3rdparty/bx/include/bx/allocator.h b/3rdparty/bx/include/bx/allocator.h index a1ab3e30826..77646a5b29d 100644 --- a/3rdparty/bx/include/bx/allocator.h +++ b/3rdparty/bx/include/bx/allocator.h @@ -8,7 +8,6 @@ #include "bx.h" -#include <string.h> //::memmove #include <new> #if BX_CONFIG_ALLOCATOR_DEBUG @@ -41,11 +40,14 @@ namespace bx { + /// Abstract allocator interface. + /// struct BX_NO_VTABLE AllocatorI { + /// virtual ~AllocatorI() = 0; - /// Allocated, resizes memory block or frees memory. + /// Allocates, resizes memory block, or frees memory. /// /// @param[in] _ptr If _ptr is NULL new block will be allocated. /// @param[in] _size If _ptr is set, and _size is 0, memory will be freed. @@ -65,7 +67,7 @@ namespace bx , size_t _align = BX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT ); - /// + /// Allocate memory. void* alloc( AllocatorI* _allocator , size_t _size @@ -74,7 +76,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Free memory. void free( AllocatorI* _allocator , void* _ptr @@ -83,7 +85,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Resize memory block. void* realloc( AllocatorI* _allocator , void* _ptr @@ -93,7 +95,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Allocate memory with specific alignment. void* alignedAlloc( AllocatorI* _allocator , size_t _size @@ -102,7 +104,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Free memory that was allocated with aligned allocator. void alignedFree( AllocatorI* _allocator , void* _ptr @@ -111,7 +113,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Resize memory block that was allocated with aligned allocator. void* alignedRealloc( AllocatorI* _allocator , void* _ptr @@ -121,7 +123,7 @@ namespace bx , uint32_t _line = 0 ); - /// + /// Delete object with specific allocator. template <typename ObjectT> void deleteObject( AllocatorI* _allocator @@ -133,6 +135,6 @@ namespace bx } // namespace bx -#include "allocator.inl" +#include "inline/allocator.inl" #endif // BX_ALLOCATOR_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/bx.h b/3rdparty/bx/include/bx/bx.h index 43ccba3cce1..838c429a8f5 100644 --- a/3rdparty/bx/include/bx/bx.h +++ b/3rdparty/bx/include/bx/bx.h @@ -6,47 +6,47 @@ #ifndef BX_H_HEADER_GUARD #define BX_H_HEADER_GUARD +#include <alloca.h> // alloca +#include <stdarg.h> // va_list #include <stdint.h> // uint32_t #include <stdlib.h> // size_t #include <stddef.h> // ptrdiff_t +#include "platform.h" #include "config.h" #include "macros.h" -namespace bx -{ - // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/ - template<typename T, size_t N> char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N]; +/// #define BX_COUNTOF(_x) sizeof(bx::COUNTOF_REQUIRES_ARRAY_ARGUMENT(_x) ) - // Template for avoiding MSVC: C4127: conditional expression is constant - template<bool> - inline bool isEnabled() - { - return true; - } - - template<> - inline bool isEnabled<false>() - { - return false; - } +/// +#define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) ) + +/// #define BX_ENABLED(_x) bx::isEnabled<!!(_x)>() - inline bool ignoreC4127(bool _x) - { - return _x; - } -#define BX_IGNORE_C4127(_x) bx::ignoreC4127(!!(_x) ) +namespace bx +{ + /// Template for avoiding MSVC: C4127: conditional expression is constant + template<bool> + bool isEnabled(); + /// + bool ignoreC4127(bool _x); + + /// template<typename Ty> - inline void xchg(Ty& _a, Ty& _b) - { - Ty tmp = _a; _a = _b; _b = tmp; - } + void xchg(Ty& _a, Ty& _b); + + /// + void xchg(void* _a, void* _b, size_t _numBytes); + + // http://cnicholson.net/2011/01/stupid-c-tricks-a-better-sizeof_array/ + template<typename T, size_t N> + char (&COUNTOF_REQUIRES_ARRAY_ARGUMENT(const T(&)[N]) )[N]; /// - void* memCopy(void* _dst, const void* _src, size_t _numBytes); + void memCopy(void* _dst, const void* _src, size_t _numBytes); /// void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch); @@ -58,11 +58,16 @@ namespace bx void scatter(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _dstPitch); /// - void* memMove(void* _dst, const void* _src, size_t _numBytes); + void memMove(void* _dst, const void* _src, size_t _numBytes); /// - void* memSet(void* _dst, uint8_t _ch, size_t _numBytes); + void memSet(void* _dst, uint8_t _ch, size_t _numBytes); + + /// + int32_t memCmp(const void* _lhs, const void* _rhs, size_t _numBytes); } // namespace bx +#include "inline/bx.inl" + #endif // BX_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/cl.h b/3rdparty/bx/include/bx/cl.h deleted file mode 100644 index f21aa96e734..00000000000 --- a/3rdparty/bx/include/bx/cl.h +++ /dev/null @@ -1,925 +0,0 @@ -/* - * Copyright 2010-2017 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause - */ - -#ifndef BX_CL_H_HEADER_GUARD -#define BX_CL_H_HEADER_GUARD - -/// To implement OpenCL dynamic loading, define BX_CL_IMPLEMENTATION and -/// #include <bx/cl.h> into .cpp file. -/// -/// To use it, just #include <bx/cl.h> without defining BX_CL_IMPLEMENTATION. -/// To load dynamic library call bx::clLoad(), to unload it call bx::clUnload. - -namespace bx -{ - /// Load OpenCL dynamic library. - /// - /// Returns internal reference count. If library is not available - /// returns 0. - /// - int32_t clLoad(); - - /// Unload OpenCL dynamic library. - /// - /// Returns internal reference count. When reference count reaches 0 - /// library is fully unloaded. - /// - int32_t clUnload(); - -} // namespace bx - -#if defined(BX_CL_IMPLEMENTATION) && defined(__OPENCL_CL_H) -# error message("CL/cl.h is already included, it cannot be included before bx/cl.h header when BX_CL_IMPLEMENTATION is defined!") -#endif // defined(BX_CL_IMPLEMENTATION) && defined(__OPENCL_CL_H) - -#ifndef __OPENCL_CL_H -#define __OPENCL_CL_H - -// BK - CL/cl.h header begin ------------------------------------------------->8 - -/******************************************************************************* - * Copyright (c) 2008 - 2012 The Khronos Group Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and/or associated documentation files (the - * "Materials"), to deal in the Materials without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Materials, and to - * permit persons to whom the Materials are furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Materials. - * - * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. - ******************************************************************************/ - -#ifdef __APPLE__ -#include <OpenCL/cl_platform.h> -#else -#include <CL/cl_platform.h> -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/******************************************************************************/ - -typedef struct _cl_platform_id * cl_platform_id; -typedef struct _cl_device_id * cl_device_id; -typedef struct _cl_context * cl_context; -typedef struct _cl_command_queue * cl_command_queue; -typedef struct _cl_mem * cl_mem; -typedef struct _cl_program * cl_program; -typedef struct _cl_kernel * cl_kernel; -typedef struct _cl_event * cl_event; -typedef struct _cl_sampler * cl_sampler; - -typedef cl_uint cl_bool; /* WARNING! Unlike cl_ types in cl_platform.h, cl_bool is not guaranteed to be the same size as the bool in kernels. */ -typedef cl_ulong cl_bitfield; -typedef cl_bitfield cl_device_type; -typedef cl_uint cl_platform_info; -typedef cl_uint cl_device_info; -typedef cl_bitfield cl_device_fp_config; -typedef cl_uint cl_device_mem_cache_type; -typedef cl_uint cl_device_local_mem_type; -typedef cl_bitfield cl_device_exec_capabilities; -typedef cl_bitfield cl_command_queue_properties; -typedef intptr_t cl_device_partition_property; -typedef cl_bitfield cl_device_affinity_domain; - -typedef intptr_t cl_context_properties; -typedef cl_uint cl_context_info; -typedef cl_uint cl_command_queue_info; -typedef cl_uint cl_channel_order; -typedef cl_uint cl_channel_type; -typedef cl_bitfield cl_mem_flags; -typedef cl_uint cl_mem_object_type; -typedef cl_uint cl_mem_info; -typedef cl_bitfield cl_mem_migration_flags; -typedef cl_uint cl_image_info; -typedef cl_uint cl_buffer_create_type; -typedef cl_uint cl_addressing_mode; -typedef cl_uint cl_filter_mode; -typedef cl_uint cl_sampler_info; -typedef cl_bitfield cl_map_flags; -typedef cl_uint cl_program_info; -typedef cl_uint cl_program_build_info; -typedef cl_uint cl_program_binary_type; -typedef cl_int cl_build_status; -typedef cl_uint cl_kernel_info; -typedef cl_uint cl_kernel_arg_info; -typedef cl_uint cl_kernel_arg_address_qualifier; -typedef cl_uint cl_kernel_arg_access_qualifier; -typedef cl_bitfield cl_kernel_arg_type_qualifier; -typedef cl_uint cl_kernel_work_group_info; -typedef cl_uint cl_event_info; -typedef cl_uint cl_command_type; -typedef cl_uint cl_profiling_info; - - -typedef struct _cl_image_format { - cl_channel_order image_channel_order; - cl_channel_type image_channel_data_type; -} cl_image_format; - -typedef struct _cl_image_desc { - cl_mem_object_type image_type; - size_t image_width; - size_t image_height; - size_t image_depth; - size_t image_array_size; - size_t image_row_pitch; - size_t image_slice_pitch; - cl_uint num_mip_levels; - cl_uint num_samples; - cl_mem buffer; -} cl_image_desc; - -typedef struct _cl_buffer_region { - size_t origin; - size_t size; -} cl_buffer_region; - - -/******************************************************************************/ - -/* Error Codes */ -#define CL_SUCCESS 0 -#define CL_DEVICE_NOT_FOUND -1 -#define CL_DEVICE_NOT_AVAILABLE -2 -#define CL_COMPILER_NOT_AVAILABLE -3 -#define CL_MEM_OBJECT_ALLOCATION_FAILURE -4 -#define CL_OUT_OF_RESOURCES -5 -#define CL_OUT_OF_HOST_MEMORY -6 -#define CL_PROFILING_INFO_NOT_AVAILABLE -7 -#define CL_MEM_COPY_OVERLAP -8 -#define CL_IMAGE_FORMAT_MISMATCH -9 -#define CL_IMAGE_FORMAT_NOT_SUPPORTED -10 -#define CL_BUILD_PROGRAM_FAILURE -11 -#define CL_MAP_FAILURE -12 -#define CL_MISALIGNED_SUB_BUFFER_OFFSET -13 -#define CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST -14 -#define CL_COMPILE_PROGRAM_FAILURE -15 -#define CL_LINKER_NOT_AVAILABLE -16 -#define CL_LINK_PROGRAM_FAILURE -17 -#define CL_DEVICE_PARTITION_FAILED -18 -#define CL_KERNEL_ARG_INFO_NOT_AVAILABLE -19 - -#define CL_INVALID_VALUE -30 -#define CL_INVALID_DEVICE_TYPE -31 -#define CL_INVALID_PLATFORM -32 -#define CL_INVALID_DEVICE -33 -#define CL_INVALID_CONTEXT -34 -#define CL_INVALID_QUEUE_PROPERTIES -35 -#define CL_INVALID_COMMAND_QUEUE -36 -#define CL_INVALID_HOST_PTR -37 -#define CL_INVALID_MEM_OBJECT -38 -#define CL_INVALID_IMAGE_FORMAT_DESCRIPTOR -39 -#define CL_INVALID_IMAGE_SIZE -40 -#define CL_INVALID_SAMPLER -41 -#define CL_INVALID_BINARY -42 -#define CL_INVALID_BUILD_OPTIONS -43 -#define CL_INVALID_PROGRAM -44 -#define CL_INVALID_PROGRAM_EXECUTABLE -45 -#define CL_INVALID_KERNEL_NAME -46 -#define CL_INVALID_KERNEL_DEFINITION -47 -#define CL_INVALID_KERNEL -48 -#define CL_INVALID_ARG_INDEX -49 -#define CL_INVALID_ARG_VALUE -50 -#define CL_INVALID_ARG_SIZE -51 -#define CL_INVALID_KERNEL_ARGS -52 -#define CL_INVALID_WORK_DIMENSION -53 -#define CL_INVALID_WORK_GROUP_SIZE -54 -#define CL_INVALID_WORK_ITEM_SIZE -55 -#define CL_INVALID_GLOBAL_OFFSET -56 -#define CL_INVALID_EVENT_WAIT_LIST -57 -#define CL_INVALID_EVENT -58 -#define CL_INVALID_OPERATION -59 -#define CL_INVALID_GL_OBJECT -60 -#define CL_INVALID_BUFFER_SIZE -61 -#define CL_INVALID_MIP_LEVEL -62 -#define CL_INVALID_GLOBAL_WORK_SIZE -63 -#define CL_INVALID_PROPERTY -64 -#define CL_INVALID_IMAGE_DESCRIPTOR -65 -#define CL_INVALID_COMPILER_OPTIONS -66 -#define CL_INVALID_LINKER_OPTIONS -67 -#define CL_INVALID_DEVICE_PARTITION_COUNT -68 - -/* OpenCL Version */ -#define CL_VERSION_1_0 1 -#define CL_VERSION_1_1 1 -#define CL_VERSION_1_2 1 - -/* cl_bool */ -#define CL_FALSE 0 -#define CL_TRUE 1 -#define CL_BLOCKING CL_TRUE -#define CL_NON_BLOCKING CL_FALSE - -/* cl_platform_info */ -#define CL_PLATFORM_PROFILE 0x0900 -#define CL_PLATFORM_VERSION 0x0901 -#define CL_PLATFORM_NAME 0x0902 -#define CL_PLATFORM_VENDOR 0x0903 -#define CL_PLATFORM_EXTENSIONS 0x0904 - -/* cl_device_type - bitfield */ -#define CL_DEVICE_TYPE_DEFAULT (1 << 0) -#define CL_DEVICE_TYPE_CPU (1 << 1) -#define CL_DEVICE_TYPE_GPU (1 << 2) -#define CL_DEVICE_TYPE_ACCELERATOR (1 << 3) -#define CL_DEVICE_TYPE_CUSTOM (1 << 4) -#define CL_DEVICE_TYPE_ALL 0xFFFFFFFF - -/* cl_device_info */ -#define CL_DEVICE_TYPE 0x1000 -#define CL_DEVICE_VENDOR_ID 0x1001 -#define CL_DEVICE_MAX_COMPUTE_UNITS 0x1002 -#define CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS 0x1003 -#define CL_DEVICE_MAX_WORK_GROUP_SIZE 0x1004 -#define CL_DEVICE_MAX_WORK_ITEM_SIZES 0x1005 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR 0x1006 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT 0x1007 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT 0x1008 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG 0x1009 -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT 0x100A -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE 0x100B -#define CL_DEVICE_MAX_CLOCK_FREQUENCY 0x100C -#define CL_DEVICE_ADDRESS_BITS 0x100D -#define CL_DEVICE_MAX_READ_IMAGE_ARGS 0x100E -#define CL_DEVICE_MAX_WRITE_IMAGE_ARGS 0x100F -#define CL_DEVICE_MAX_MEM_ALLOC_SIZE 0x1010 -#define CL_DEVICE_IMAGE2D_MAX_WIDTH 0x1011 -#define CL_DEVICE_IMAGE2D_MAX_HEIGHT 0x1012 -#define CL_DEVICE_IMAGE3D_MAX_WIDTH 0x1013 -#define CL_DEVICE_IMAGE3D_MAX_HEIGHT 0x1014 -#define CL_DEVICE_IMAGE3D_MAX_DEPTH 0x1015 -#define CL_DEVICE_IMAGE_SUPPORT 0x1016 -#define CL_DEVICE_MAX_PARAMETER_SIZE 0x1017 -#define CL_DEVICE_MAX_SAMPLERS 0x1018 -#define CL_DEVICE_MEM_BASE_ADDR_ALIGN 0x1019 -#define CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE 0x101A -#define CL_DEVICE_SINGLE_FP_CONFIG 0x101B -#define CL_DEVICE_GLOBAL_MEM_CACHE_TYPE 0x101C -#define CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE 0x101D -#define CL_DEVICE_GLOBAL_MEM_CACHE_SIZE 0x101E -#define CL_DEVICE_GLOBAL_MEM_SIZE 0x101F -#define CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE 0x1020 -#define CL_DEVICE_MAX_CONSTANT_ARGS 0x1021 -#define CL_DEVICE_LOCAL_MEM_TYPE 0x1022 -#define CL_DEVICE_LOCAL_MEM_SIZE 0x1023 -#define CL_DEVICE_ERROR_CORRECTION_SUPPORT 0x1024 -#define CL_DEVICE_PROFILING_TIMER_RESOLUTION 0x1025 -#define CL_DEVICE_ENDIAN_LITTLE 0x1026 -#define CL_DEVICE_AVAILABLE 0x1027 -#define CL_DEVICE_COMPILER_AVAILABLE 0x1028 -#define CL_DEVICE_EXECUTION_CAPABILITIES 0x1029 -#define CL_DEVICE_QUEUE_PROPERTIES 0x102A -#define CL_DEVICE_NAME 0x102B -#define CL_DEVICE_VENDOR 0x102C -#define CL_DRIVER_VERSION 0x102D -#define CL_DEVICE_PROFILE 0x102E -#define CL_DEVICE_VERSION 0x102F -#define CL_DEVICE_EXTENSIONS 0x1030 -#define CL_DEVICE_PLATFORM 0x1031 -#define CL_DEVICE_DOUBLE_FP_CONFIG 0x1032 -/* 0x1033 reserved for CL_DEVICE_HALF_FP_CONFIG */ -#define CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF 0x1034 -#define CL_DEVICE_HOST_UNIFIED_MEMORY 0x1035 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR 0x1036 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT 0x1037 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_INT 0x1038 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG 0x1039 -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT 0x103A -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE 0x103B -#define CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF 0x103C -#define CL_DEVICE_OPENCL_C_VERSION 0x103D -#define CL_DEVICE_LINKER_AVAILABLE 0x103E -#define CL_DEVICE_BUILT_IN_KERNELS 0x103F -#define CL_DEVICE_IMAGE_MAX_BUFFER_SIZE 0x1040 -#define CL_DEVICE_IMAGE_MAX_ARRAY_SIZE 0x1041 -#define CL_DEVICE_PARENT_DEVICE 0x1042 -#define CL_DEVICE_PARTITION_MAX_SUB_DEVICES 0x1043 -#define CL_DEVICE_PARTITION_PROPERTIES 0x1044 -#define CL_DEVICE_PARTITION_AFFINITY_DOMAIN 0x1045 -#define CL_DEVICE_PARTITION_TYPE 0x1046 -#define CL_DEVICE_REFERENCE_COUNT 0x1047 -#define CL_DEVICE_PREFERRED_INTEROP_USER_SYNC 0x1048 -#define CL_DEVICE_PRINTF_BUFFER_SIZE 0x1049 -#define CL_DEVICE_IMAGE_PITCH_ALIGNMENT 0x104A -#define CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT 0x104B - -/* cl_device_fp_config - bitfield */ -#define CL_FP_DENORM (1 << 0) -#define CL_FP_INF_NAN (1 << 1) -#define CL_FP_ROUND_TO_NEAREST (1 << 2) -#define CL_FP_ROUND_TO_ZERO (1 << 3) -#define CL_FP_ROUND_TO_INF (1 << 4) -#define CL_FP_FMA (1 << 5) -#define CL_FP_SOFT_FLOAT (1 << 6) -#define CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT (1 << 7) - -/* cl_device_mem_cache_type */ -#define CL_NONE 0x0 -#define CL_READ_ONLY_CACHE 0x1 -#define CL_READ_WRITE_CACHE 0x2 - -/* cl_device_local_mem_type */ -#define CL_LOCAL 0x1 -#define CL_GLOBAL 0x2 - -/* cl_device_exec_capabilities - bitfield */ -#define CL_EXEC_KERNEL (1 << 0) -#define CL_EXEC_NATIVE_KERNEL (1 << 1) - -/* cl_command_queue_properties - bitfield */ -#define CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE (1 << 0) -#define CL_QUEUE_PROFILING_ENABLE (1 << 1) - -/* cl_context_info */ -#define CL_CONTEXT_REFERENCE_COUNT 0x1080 -#define CL_CONTEXT_DEVICES 0x1081 -#define CL_CONTEXT_PROPERTIES 0x1082 -#define CL_CONTEXT_NUM_DEVICES 0x1083 - -/* cl_context_properties */ -#define CL_CONTEXT_PLATFORM 0x1084 -#define CL_CONTEXT_INTEROP_USER_SYNC 0x1085 - -/* cl_device_partition_property */ -#define CL_DEVICE_PARTITION_EQUALLY 0x1086 -#define CL_DEVICE_PARTITION_BY_COUNTS 0x1087 -#define CL_DEVICE_PARTITION_BY_COUNTS_LIST_END 0x0 -#define CL_DEVICE_PARTITION_BY_AFFINITY_DOMAIN 0x1088 - -/* cl_device_affinity_domain */ -#define CL_DEVICE_AFFINITY_DOMAIN_NUMA (1 << 0) -#define CL_DEVICE_AFFINITY_DOMAIN_L4_CACHE (1 << 1) -#define CL_DEVICE_AFFINITY_DOMAIN_L3_CACHE (1 << 2) -#define CL_DEVICE_AFFINITY_DOMAIN_L2_CACHE (1 << 3) -#define CL_DEVICE_AFFINITY_DOMAIN_L1_CACHE (1 << 4) -#define CL_DEVICE_AFFINITY_DOMAIN_NEXT_PARTITIONABLE (1 << 5) - -/* cl_command_queue_info */ -#define CL_QUEUE_CONTEXT 0x1090 -#define CL_QUEUE_DEVICE 0x1091 -#define CL_QUEUE_REFERENCE_COUNT 0x1092 -#define CL_QUEUE_PROPERTIES 0x1093 - -/* cl_mem_flags - bitfield */ -#define CL_MEM_READ_WRITE (1 << 0) -#define CL_MEM_WRITE_ONLY (1 << 1) -#define CL_MEM_READ_ONLY (1 << 2) -#define CL_MEM_USE_HOST_PTR (1 << 3) -#define CL_MEM_ALLOC_HOST_PTR (1 << 4) -#define CL_MEM_COPY_HOST_PTR (1 << 5) -// reserved (1 << 6) -#define CL_MEM_HOST_WRITE_ONLY (1 << 7) -#define CL_MEM_HOST_READ_ONLY (1 << 8) -#define CL_MEM_HOST_NO_ACCESS (1 << 9) - -/* cl_mem_migration_flags - bitfield */ -#define CL_MIGRATE_MEM_OBJECT_HOST (1 << 0) -#define CL_MIGRATE_MEM_OBJECT_CONTENT_UNDEFINED (1 << 1) - -/* cl_channel_order */ -#define CL_R 0x10B0 -#define CL_A 0x10B1 -#define CL_RG 0x10B2 -#define CL_RA 0x10B3 -#define CL_RGB 0x10B4 -#define CL_RGBA 0x10B5 -#define CL_BGRA 0x10B6 -#define CL_ARGB 0x10B7 -#define CL_INTENSITY 0x10B8 -#define CL_LUMINANCE 0x10B9 -#define CL_Rx 0x10BA -#define CL_RGx 0x10BB -#define CL_RGBx 0x10BC -#define CL_DEPTH 0x10BD -#define CL_DEPTH_STENCIL 0x10BE - -/* cl_channel_type */ -#define CL_SNORM_INT8 0x10D0 -#define CL_SNORM_INT16 0x10D1 -#define CL_UNORM_INT8 0x10D2 -#define CL_UNORM_INT16 0x10D3 -#define CL_UNORM_SHORT_565 0x10D4 -#define CL_UNORM_SHORT_555 0x10D5 -#define CL_UNORM_INT_101010 0x10D6 -#define CL_SIGNED_INT8 0x10D7 -#define CL_SIGNED_INT16 0x10D8 -#define CL_SIGNED_INT32 0x10D9 -#define CL_UNSIGNED_INT8 0x10DA -#define CL_UNSIGNED_INT16 0x10DB -#define CL_UNSIGNED_INT32 0x10DC -#define CL_HALF_FLOAT 0x10DD -#define CL_FLOAT 0x10DE -#define CL_UNORM_INT24 0x10DF - -/* cl_mem_object_type */ -#define CL_MEM_OBJECT_BUFFER 0x10F0 -#define CL_MEM_OBJECT_IMAGE2D 0x10F1 -#define CL_MEM_OBJECT_IMAGE3D 0x10F2 -#define CL_MEM_OBJECT_IMAGE2D_ARRAY 0x10F3 -#define CL_MEM_OBJECT_IMAGE1D 0x10F4 -#define CL_MEM_OBJECT_IMAGE1D_ARRAY 0x10F5 -#define CL_MEM_OBJECT_IMAGE1D_BUFFER 0x10F6 - -/* cl_mem_info */ -#define CL_MEM_TYPE 0x1100 -#define CL_MEM_FLAGS 0x1101 -#define CL_MEM_SIZE 0x1102 -#define CL_MEM_HOST_PTR 0x1103 -#define CL_MEM_MAP_COUNT 0x1104 -#define CL_MEM_REFERENCE_COUNT 0x1105 -#define CL_MEM_CONTEXT 0x1106 -#define CL_MEM_ASSOCIATED_MEMOBJECT 0x1107 -#define CL_MEM_OFFSET 0x1108 - -/* cl_image_info */ -#define CL_IMAGE_FORMAT 0x1110 -#define CL_IMAGE_ELEMENT_SIZE 0x1111 -#define CL_IMAGE_ROW_PITCH 0x1112 -#define CL_IMAGE_SLICE_PITCH 0x1113 -#define CL_IMAGE_WIDTH 0x1114 -#define CL_IMAGE_HEIGHT 0x1115 -#define CL_IMAGE_DEPTH 0x1116 -#define CL_IMAGE_ARRAY_SIZE 0x1117 -#define CL_IMAGE_BUFFER 0x1118 -#define CL_IMAGE_NUM_MIP_LEVELS 0x1119 -#define CL_IMAGE_NUM_SAMPLES 0x111A - -/* cl_addressing_mode */ -#define CL_ADDRESS_NONE 0x1130 -#define CL_ADDRESS_CLAMP_TO_EDGE 0x1131 -#define CL_ADDRESS_CLAMP 0x1132 -#define CL_ADDRESS_REPEAT 0x1133 -#define CL_ADDRESS_MIRRORED_REPEAT 0x1134 - -/* cl_filter_mode */ -#define CL_FILTER_NEAREST 0x1140 -#define CL_FILTER_LINEAR 0x1141 - -/* cl_sampler_info */ -#define CL_SAMPLER_REFERENCE_COUNT 0x1150 -#define CL_SAMPLER_CONTEXT 0x1151 -#define CL_SAMPLER_NORMALIZED_COORDS 0x1152 -#define CL_SAMPLER_ADDRESSING_MODE 0x1153 -#define CL_SAMPLER_FILTER_MODE 0x1154 - -/* cl_map_flags - bitfield */ -#define CL_MAP_READ (1 << 0) -#define CL_MAP_WRITE (1 << 1) -#define CL_MAP_WRITE_INVALIDATE_REGION (1 << 2) - -/* cl_program_info */ -#define CL_PROGRAM_REFERENCE_COUNT 0x1160 -#define CL_PROGRAM_CONTEXT 0x1161 -#define CL_PROGRAM_NUM_DEVICES 0x1162 -#define CL_PROGRAM_DEVICES 0x1163 -#define CL_PROGRAM_SOURCE 0x1164 -#define CL_PROGRAM_BINARY_SIZES 0x1165 -#define CL_PROGRAM_BINARIES 0x1166 -#define CL_PROGRAM_NUM_KERNELS 0x1167 -#define CL_PROGRAM_KERNEL_NAMES 0x1168 - -/* cl_program_build_info */ -#define CL_PROGRAM_BUILD_STATUS 0x1181 -#define CL_PROGRAM_BUILD_OPTIONS 0x1182 -#define CL_PROGRAM_BUILD_LOG 0x1183 -#define CL_PROGRAM_BINARY_TYPE 0x1184 - -/* cl_program_binary_type */ -#define CL_PROGRAM_BINARY_TYPE_NONE 0x0 -#define CL_PROGRAM_BINARY_TYPE_COMPILED_OBJECT 0x1 -#define CL_PROGRAM_BINARY_TYPE_LIBRARY 0x2 -#define CL_PROGRAM_BINARY_TYPE_EXECUTABLE 0x4 - -/* cl_build_status */ -#define CL_BUILD_SUCCESS 0 -#define CL_BUILD_NONE -1 -#define CL_BUILD_ERROR -2 -#define CL_BUILD_IN_PROGRESS -3 - -/* cl_kernel_info */ -#define CL_KERNEL_FUNCTION_NAME 0x1190 -#define CL_KERNEL_NUM_ARGS 0x1191 -#define CL_KERNEL_REFERENCE_COUNT 0x1192 -#define CL_KERNEL_CONTEXT 0x1193 -#define CL_KERNEL_PROGRAM 0x1194 -#define CL_KERNEL_ATTRIBUTES 0x1195 - -/* cl_kernel_arg_info */ -#define CL_KERNEL_ARG_ADDRESS_QUALIFIER 0x1196 -#define CL_KERNEL_ARG_ACCESS_QUALIFIER 0x1197 -#define CL_KERNEL_ARG_TYPE_NAME 0x1198 -#define CL_KERNEL_ARG_TYPE_QUALIFIER 0x1199 -#define CL_KERNEL_ARG_NAME 0x119A - -/* cl_kernel_arg_address_qualifier */ -#define CL_KERNEL_ARG_ADDRESS_GLOBAL 0x119B -#define CL_KERNEL_ARG_ADDRESS_LOCAL 0x119C -#define CL_KERNEL_ARG_ADDRESS_CONSTANT 0x119D -#define CL_KERNEL_ARG_ADDRESS_PRIVATE 0x119E - -/* cl_kernel_arg_access_qualifier */ -#define CL_KERNEL_ARG_ACCESS_READ_ONLY 0x11A0 -#define CL_KERNEL_ARG_ACCESS_WRITE_ONLY 0x11A1 -#define CL_KERNEL_ARG_ACCESS_READ_WRITE 0x11A2 -#define CL_KERNEL_ARG_ACCESS_NONE 0x11A3 - -/* cl_kernel_arg_type_qualifer */ -#define CL_KERNEL_ARG_TYPE_NONE 0 -#define CL_KERNEL_ARG_TYPE_CONST (1 << 0) -#define CL_KERNEL_ARG_TYPE_RESTRICT (1 << 1) -#define CL_KERNEL_ARG_TYPE_VOLATILE (1 << 2) - -/* cl_kernel_work_group_info */ -#define CL_KERNEL_WORK_GROUP_SIZE 0x11B0 -#define CL_KERNEL_COMPILE_WORK_GROUP_SIZE 0x11B1 -#define CL_KERNEL_LOCAL_MEM_SIZE 0x11B2 -#define CL_KERNEL_PREFERRED_WORK_GROUP_SIZE_MULTIPLE 0x11B3 -#define CL_KERNEL_PRIVATE_MEM_SIZE 0x11B4 -#define CL_KERNEL_GLOBAL_WORK_SIZE 0x11B5 - -/* cl_event_info */ -#define CL_EVENT_COMMAND_QUEUE 0x11D0 -#define CL_EVENT_COMMAND_TYPE 0x11D1 -#define CL_EVENT_REFERENCE_COUNT 0x11D2 -#define CL_EVENT_COMMAND_EXECUTION_STATUS 0x11D3 -#define CL_EVENT_CONTEXT 0x11D4 - -/* cl_command_type */ -#define CL_COMMAND_NDRANGE_KERNEL 0x11F0 -#define CL_COMMAND_TASK 0x11F1 -#define CL_COMMAND_NATIVE_KERNEL 0x11F2 -#define CL_COMMAND_READ_BUFFER 0x11F3 -#define CL_COMMAND_WRITE_BUFFER 0x11F4 -#define CL_COMMAND_COPY_BUFFER 0x11F5 -#define CL_COMMAND_READ_IMAGE 0x11F6 -#define CL_COMMAND_WRITE_IMAGE 0x11F7 -#define CL_COMMAND_COPY_IMAGE 0x11F8 -#define CL_COMMAND_COPY_IMAGE_TO_BUFFER 0x11F9 -#define CL_COMMAND_COPY_BUFFER_TO_IMAGE 0x11FA -#define CL_COMMAND_MAP_BUFFER 0x11FB -#define CL_COMMAND_MAP_IMAGE 0x11FC -#define CL_COMMAND_UNMAP_MEM_OBJECT 0x11FD -#define CL_COMMAND_MARKER 0x11FE -#define CL_COMMAND_ACQUIRE_GL_OBJECTS 0x11FF -#define CL_COMMAND_RELEASE_GL_OBJECTS 0x1200 -#define CL_COMMAND_READ_BUFFER_RECT 0x1201 -#define CL_COMMAND_WRITE_BUFFER_RECT 0x1202 -#define CL_COMMAND_COPY_BUFFER_RECT 0x1203 -#define CL_COMMAND_USER 0x1204 -#define CL_COMMAND_BARRIER 0x1205 -#define CL_COMMAND_MIGRATE_MEM_OBJECTS 0x1206 -#define CL_COMMAND_FILL_BUFFER 0x1207 -#define CL_COMMAND_FILL_IMAGE 0x1208 - -/* command execution status */ -#define CL_COMPLETE 0x0 -#define CL_RUNNING 0x1 -#define CL_SUBMITTED 0x2 -#define CL_QUEUED 0x3 - -/* cl_buffer_create_type */ -#define CL_BUFFER_CREATE_TYPE_REGION 0x1220 - -/* cl_profiling_info */ -#define CL_PROFILING_COMMAND_QUEUED 0x1280 -#define CL_PROFILING_COMMAND_SUBMIT 0x1281 -#define CL_PROFILING_COMMAND_START 0x1282 -#define CL_PROFILING_COMMAND_END 0x1283 - -#ifdef __cplusplus -} //extern "C" -#endif - -// BK - CL/cl.h header end --------------------------------------------------->8 - -// 1.1 -typedef cl_int (CL_API_CALL* PFNCLGETPLATFORMIDSPROC)(cl_uint, cl_platform_id*, cl_uint*); -typedef cl_int (CL_API_CALL* PFNCLGETPLATFORMINFOPROC)(cl_platform_id, cl_platform_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLGETDEVICEINFOPROC)(cl_device_id, cl_device_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLGETDEVICEIDSPROC)(cl_platform_id, cl_device_type, cl_uint, cl_device_id*, cl_uint*); -typedef cl_context (CL_API_CALL* PFNCLCREATECONTEXTPROC)(const cl_context_properties*, cl_uint, const cl_device_id*, void (CL_CALLBACK*)(const char*, const void*, size_t, void*), void*, cl_int*); -typedef cl_context (CL_API_CALL* PFNCLCREATECONTEXTFROMTYPEPROC)(const cl_context_properties *, cl_device_type, void (CL_CALLBACK*)(const char*, const void*, size_t, void*), void*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLRETAINCONTEXTPROC)(cl_context); -typedef cl_int (CL_API_CALL* PFNCLRELEASECONTEXTPROC)(cl_context); -typedef cl_int (CL_API_CALL* PFNCLGETCONTEXTINFOPROC)(cl_context, cl_context_info, size_t, void*, size_t*); -typedef cl_command_queue (CL_API_CALL* PFNCLCREATECOMMANDQUEUEPROC)(cl_context, cl_device_id, cl_command_queue_properties, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLRETAINCOMMANDQUEUEPROC)(cl_command_queue); -typedef cl_int (CL_API_CALL* PFNCLRELEASECOMMANDQUEUEPROC)(cl_command_queue); -typedef cl_int (CL_API_CALL* PFNCLGETCOMMANDQUEUEINFOPROC)(cl_command_queue, cl_command_queue_info, size_t, void*, size_t*); -typedef cl_mem (CL_API_CALL* PFNCLCREATEBUFFERPROC)(cl_context, cl_mem_flags, size_t, void*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLRETAINMEMOBJECTPROC)(cl_mem); -typedef cl_int (CL_API_CALL* PFNCLRELEASEMEMOBJECTPROC)(cl_mem); -typedef cl_int (CL_API_CALL* PFNCLGETSUPPORTEDIMAGEFORMATSPROC)(cl_context, cl_mem_flags, cl_mem_object_type, cl_uint, cl_image_format*, cl_uint*); -typedef cl_int (CL_API_CALL* PFNCLGETMEMOBJECTINFOPROC)(cl_mem, cl_mem_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLGETIMAGEINFOPROC)(cl_mem, cl_image_info, size_t, void*, size_t*); -typedef cl_sampler (CL_API_CALL* PFNCLCREATESAMPLERPROC)(cl_context, cl_bool, cl_addressing_mode, cl_filter_mode, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLRETAINSAMPLERPROC)(cl_sampler); -typedef cl_int (CL_API_CALL* PFNCLRELEASESAMPLERPROC)(cl_sampler); -typedef cl_int (CL_API_CALL* PFNCLGETSAMPLERINFOPROC)(cl_sampler, cl_sampler_info, size_t, void*, size_t*); -typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHSOURCEPROC)(cl_context, cl_uint, const char**, const size_t*, cl_int*); -typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHBINARYPROC)(cl_context, cl_uint, const cl_device_id*, const size_t*, const unsigned char**, cl_int*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLRETAINPROGRAMPROC)(cl_program); -typedef cl_int (CL_API_CALL* PFNCLRELEASEPROGRAMPROC)(cl_program); -typedef cl_int (CL_API_CALL* PFNCLBUILDPROGRAMPROC)(cl_program, cl_uint, const cl_device_id *, const char *, void (CL_CALLBACK*)(cl_program, void*), void*); -typedef cl_int (CL_API_CALL* PFNCLGETPROGRAMINFOPROC)(cl_program, cl_program_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLGETPROGRAMBUILDINFOPROC)(cl_program, cl_device_id, cl_program_build_info, size_t, void*, size_t*); -typedef cl_kernel (CL_API_CALL* PFNCLCREATEKERNELPROC)(cl_program, const char*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLCREATEKERNELSINPROGRAMPROC)(cl_program, cl_uint, cl_kernel*, cl_uint*); -typedef cl_int (CL_API_CALL* PFNCLRETAINKERNELPROC)(cl_kernel); -typedef cl_int (CL_API_CALL* PFNCLRELEASEKERNELPROC)(cl_kernel); -typedef cl_int (CL_API_CALL* PFNCLSETKERNELARGPROC)(cl_kernel, cl_uint, size_t, const void*); -typedef cl_int (CL_API_CALL* PFNCLGETKERNELINFOPROC)(cl_kernel, cl_kernel_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLGETKERNELWORKGROUPINFOPROC)(cl_kernel, cl_device_id, cl_kernel_work_group_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLWAITFOREVENTSPROC)(cl_uint, const cl_event*); -typedef cl_int (CL_API_CALL* PFNCLGETEVENTINFOPROC)(cl_event, cl_event_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLRETAINEVENTPROC)(cl_event); -typedef cl_int (CL_API_CALL* PFNCLRELEASEEVENTPROC)(cl_event); -typedef cl_int (CL_API_CALL* PFNCLGETEVENTPROFILINGINFOPROC)(cl_event, cl_profiling_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLFLUSHPROC)(cl_command_queue); -typedef cl_int (CL_API_CALL* PFNCLFINISHPROC)(cl_command_queue); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERPROC)(cl_command_queue, cl_mem, cl_mem, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, const size_t*, const size_t*, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYIMAGEPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYIMAGETOBUFFERPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, size_t, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERTOIMAGEPROC)(cl_command_queue, cl_mem, cl_mem, size_t, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); -typedef void (CL_API_CALL* PFNCLENQUEUEMAPBUFFERPROC)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, size_t, size_t, cl_uint, const cl_event*, cl_event*, cl_int*); -typedef void (CL_API_CALL* PFNCLENQUEUEMAPIMAGEPROC)(cl_command_queue, cl_mem, cl_bool, cl_map_flags, const size_t *, const size_t *, size_t *, size_t *, cl_uint, const cl_event *, cl_event *, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEUNMAPMEMOBJECTPROC)(cl_command_queue, cl_mem, void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUENDRANGEKERNELPROC)(cl_command_queue, cl_kernel, cl_uint, const size_t*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUETASKPROC)(cl_command_queue, cl_kernel, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUENATIVEKERNELPROC)(cl_command_queue, void (CL_CALLBACK*)(void*), void*, size_t, cl_uint, const cl_mem*, const void**, cl_uint, const cl_event*, cl_event*); - -// 1.1 -typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGE2DPROC)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, void*, cl_int*); -typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGE3DPROC)(cl_context, cl_mem_flags, const cl_image_format*, size_t, size_t, size_t, size_t, size_t, void*, cl_int*); -typedef cl_mem (CL_API_CALL* PFNCLCREATESUBBUFFERPROC)(cl_mem, cl_mem_flags, cl_buffer_create_type, const void*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLSETMEMOBJECTDESTRUCTORCALLBACKPROC)(cl_mem, void (CL_CALLBACK*)(cl_mem, void*), void*); -typedef cl_event (CL_API_CALL* PFNCLCREATEUSEREVENTPROC)(cl_context, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLSETUSEREVENTSTATUSPROC)(cl_event, cl_int); -typedef cl_int (CL_API_CALL* PFNCLSETEVENTCALLBACKPROC)(cl_event, cl_int, void (CL_CALLBACK*)(cl_event, cl_int, void*), void*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEREADBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, size_t, size_t, size_t, size_t, void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEWRITEBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_bool, const size_t *, const size_t *, const size_t *, size_t, size_t, size_t, size_t, const void*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUECOPYBUFFERRECTPROC)(cl_command_queue, cl_mem, cl_mem, const size_t*, const size_t*, const size_t*, size_t, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event*); - -// 1.2 -typedef cl_int (CL_API_CALL* PFNCLCREATESUBDEVICESPROC)(cl_device_id, const cl_device_partition_property*, cl_uint, cl_device_id*, cl_uint*); -typedef cl_int (CL_API_CALL* PFNCLRETAINDEVICEPROC)(cl_device_id); -typedef cl_int (CL_API_CALL* PFNCLRELEASEDEVICEPROC)(cl_device_id); -typedef cl_mem (CL_API_CALL* PFNCLCREATEIMAGEPROC)(cl_context, cl_mem_flags, const cl_image_format*, const cl_image_desc*, void*, cl_int*); -typedef cl_program (CL_API_CALL* PFNCLCREATEPROGRAMWITHBUILTINKERNELSPROC)(cl_context, cl_uint, const cl_device_id*, const char*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLCOMPILEPROGRAMPROC)(cl_program, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, const char**, void (CL_CALLBACK*)(cl_program, void*), void*); -typedef cl_program (CL_API_CALL* PFNCLLINKPROGRAMPROC)(cl_context, cl_uint, const cl_device_id*, const char*, cl_uint, const cl_program*, void (CL_CALLBACK*)(cl_program, void*), void*, cl_int*); -typedef cl_int (CL_API_CALL* PFNCLUNLOADPLATFORMCOMPILERPROC)(cl_platform_id); -typedef cl_int (CL_API_CALL* PFNCLGETKERNELARGINFOPROC)(cl_kernel, cl_uint, cl_kernel_arg_info, size_t, void*, size_t*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEFILLBUFFERPROC)(cl_command_queue, cl_mem, const void*, size_t, size_t, size_t, cl_uint, const cl_event*, cl_event *); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEFILLIMAGEPROC)(cl_command_queue, cl_mem, const void*, const size_t*, const size_t*, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEMIGRATEMEMOBJECTSPROC)(cl_command_queue, cl_uint, const cl_mem*, cl_mem_migration_flags, cl_uint, const cl_event *, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEMARKERWITHWAITLISTPROC)(cl_command_queue, cl_uint, const cl_event*, cl_event*); -typedef cl_int (CL_API_CALL* PFNCLENQUEUEBARRIERWITHWAITLISTPROC)(cl_command_queue, cl_uint, const cl_event *, cl_event*); - -#define BX_CL_IMPORT_ALL_10 \ - /* Platform API */ \ - BX_CL_IMPORT_10(false, PFNCLGETPLATFORMIDSPROC, clGetPlatformIDs); \ - BX_CL_IMPORT_10(false, PFNCLGETPLATFORMINFOPROC, clGetPlatformInfo); \ - /* Device APIs */ \ - BX_CL_IMPORT_10(false, PFNCLGETDEVICEIDSPROC, clGetDeviceIDs); \ - BX_CL_IMPORT_10(false, PFNCLGETDEVICEINFOPROC, clGetDeviceInfo); \ - /* Context APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATECONTEXTPROC, clCreateContext); \ - BX_CL_IMPORT_10(false, PFNCLCREATECONTEXTFROMTYPEPROC, clCreateContextFromType); \ - BX_CL_IMPORT_10(false, PFNCLRETAINCONTEXTPROC, clRetainContext); \ - BX_CL_IMPORT_10(false, PFNCLRELEASECONTEXTPROC, clReleaseContext); \ - BX_CL_IMPORT_10(false, PFNCLGETCONTEXTINFOPROC, clGetContextInfo); \ - /* Command Queue APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATECOMMANDQUEUEPROC, clCreateCommandQueue); \ - BX_CL_IMPORT_10(false, PFNCLRETAINCOMMANDQUEUEPROC, clRetainCommandQueue); \ - BX_CL_IMPORT_10(false, PFNCLRELEASECOMMANDQUEUEPROC, clReleaseCommandQueue); \ - BX_CL_IMPORT_10(false, PFNCLGETCOMMANDQUEUEINFOPROC, clGetCommandQueueInfo); \ - /* Memory Object APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATEBUFFERPROC, clCreateBuffer); \ - BX_CL_IMPORT_10(false, PFNCLRETAINMEMOBJECTPROC, clRetainMemObject); \ - BX_CL_IMPORT_10(false, PFNCLRELEASEMEMOBJECTPROC, clReleaseMemObject); \ - BX_CL_IMPORT_10(false, PFNCLGETSUPPORTEDIMAGEFORMATSPROC, clGetSupportedImageFormats); \ - BX_CL_IMPORT_10(false, PFNCLGETMEMOBJECTINFOPROC, clGetMemObjectInfo); \ - BX_CL_IMPORT_10(false, PFNCLGETIMAGEINFOPROC, clGetImageInfo); \ - /* Sampler APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATESAMPLERPROC, clCreateSampler); \ - BX_CL_IMPORT_10(false, PFNCLRETAINSAMPLERPROC, clRetainSampler); \ - BX_CL_IMPORT_10(false, PFNCLRELEASESAMPLERPROC, clReleaseSampler); \ - BX_CL_IMPORT_10(false, PFNCLGETSAMPLERINFOPROC, clGetSamplerInfo); \ - /* Program Object APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATEPROGRAMWITHSOURCEPROC, clCreateProgramWithSource); \ - BX_CL_IMPORT_10(false, PFNCLCREATEPROGRAMWITHBINARYPROC, clCreateProgramWithBinary); \ - BX_CL_IMPORT_10(false, PFNCLRETAINPROGRAMPROC, clRetainProgram); \ - BX_CL_IMPORT_10(false, PFNCLRELEASEPROGRAMPROC, clReleaseProgram); \ - BX_CL_IMPORT_10(false, PFNCLBUILDPROGRAMPROC, clBuildProgram); \ - BX_CL_IMPORT_10(false, PFNCLGETPROGRAMINFOPROC, clGetProgramInfo); \ - BX_CL_IMPORT_10(false, PFNCLGETPROGRAMBUILDINFOPROC, clGetProgramBuildInfo); \ - /* Kernel Object APIs */ \ - BX_CL_IMPORT_10(false, PFNCLCREATEKERNELPROC, clCreateKernel); \ - BX_CL_IMPORT_10(false, PFNCLCREATEKERNELSINPROGRAMPROC, clCreateKernelsInProgram); \ - BX_CL_IMPORT_10(false, PFNCLRETAINKERNELPROC, clRetainKernel); \ - BX_CL_IMPORT_10(false, PFNCLRELEASEKERNELPROC, clReleaseKernel); \ - BX_CL_IMPORT_10(false, PFNCLSETKERNELARGPROC, clSetKernelArg); \ - BX_CL_IMPORT_10(false, PFNCLGETKERNELINFOPROC, clGetKernelInfo); \ - BX_CL_IMPORT_10(false, PFNCLGETKERNELWORKGROUPINFOPROC, clGetKernelWorkGroupInfo); \ - /* Event Object APIs */ \ - BX_CL_IMPORT_10(false, PFNCLWAITFOREVENTSPROC, clWaitForEvents); \ - BX_CL_IMPORT_10(false, PFNCLGETEVENTINFOPROC, clGetEventInfo); \ - BX_CL_IMPORT_10(false, PFNCLRETAINEVENTPROC, clRetainEvent); \ - BX_CL_IMPORT_10(false, PFNCLRELEASEEVENTPROC, clReleaseEvent); \ - /* Profiling APIs */ \ - BX_CL_IMPORT_10(false, PFNCLGETEVENTPROFILINGINFOPROC, clGetEventProfilingInfo); \ - /* Flush and Finish APIs */ \ - BX_CL_IMPORT_10(false, PFNCLFLUSHPROC, clFlush); \ - BX_CL_IMPORT_10(false, PFNCLFINISHPROC, clFinish); \ - /* Enqueued Commands APIs */ \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEREADBUFFERPROC, clEnqueueReadBuffer); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEWRITEBUFFERPROC, clEnqueueWriteBuffer); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYBUFFERPROC, clEnqueueCopyBuffer); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEREADIMAGEPROC, clEnqueueReadImage); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEWRITEIMAGEPROC, clEnqueueWriteImage); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYIMAGEPROC, clEnqueueCopyImage); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUECOPYIMAGETOBUFFERPROC, clEnqueueCopyImageToBuffer); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEMAPBUFFERPROC, clEnqueueMapBuffer); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEMAPIMAGEPROC, clEnqueueMapImage); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUEUNMAPMEMOBJECTPROC, clEnqueueUnmapMemObject); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUENDRANGEKERNELPROC, clEnqueueNDRangeKernel); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUETASKPROC, clEnqueueTask); \ - BX_CL_IMPORT_10(false, PFNCLENQUEUENATIVEKERNELPROC, clEnqueueNativeKernel); \ - \ - BX_CL_IMPORT_END - -#define BX_CL_IMPORT_ALL_11 \ - /* Memory Object APIs */ \ - BX_CL_IMPORT_11(false, PFNCLCREATEIMAGE2DPROC, clCreateImage2D); \ - BX_CL_IMPORT_11(false, PFNCLCREATEIMAGE3DPROC, clCreateImage3D); \ - BX_CL_IMPORT_11(false, PFNCLCREATESUBBUFFERPROC, clCreateSubBuffer); \ - BX_CL_IMPORT_11(false, PFNCLSETMEMOBJECTDESTRUCTORCALLBACKPROC, clSetMemObjectDestructorCallback); \ - /* Event Object APIs */ \ - BX_CL_IMPORT_11(false, PFNCLCREATEUSEREVENTPROC, clCreateUserEvent); \ - BX_CL_IMPORT_11(false, PFNCLSETUSEREVENTSTATUSPROC, clSetUserEventStatus); \ - BX_CL_IMPORT_11(false, PFNCLSETEVENTCALLBACKPROC, clSetEventCallback); \ - /* Enqueued Commands APIs */ \ - BX_CL_IMPORT_11(false, PFNCLENQUEUEREADBUFFERRECTPROC, clEnqueueReadBufferRect); \ - BX_CL_IMPORT_11(false, PFNCLENQUEUEWRITEBUFFERRECTPROC, clEnqueueWriteBufferRect); \ - BX_CL_IMPORT_11(false, PFNCLENQUEUECOPYBUFFERRECTPROC, clEnqueueCopyBufferRect); \ - \ - BX_CL_IMPORT_END - -#define BX_CL_IMPORT_ALL_12 \ - /* Device APIs */ \ - BX_CL_IMPORT_12(false, PFNCLCREATESUBDEVICESPROC, clCreateSubDevices); \ - BX_CL_IMPORT_12(false, PFNCLRETAINDEVICEPROC, clRetainDevice); \ - BX_CL_IMPORT_12(false, PFNCLRELEASEDEVICEPROC, clReleaseDevice); \ - BX_CL_IMPORT_12(false, PFNCLCREATEIMAGEPROC, clCreateImage); \ - /* Program Object APIs */ \ - BX_CL_IMPORT_12(false, PFNCLCREATEPROGRAMWITHBUILTINKERNELSPROC, clCreateProgramWithBuiltInKernels); \ - BX_CL_IMPORT_12(false, PFNCLCOMPILEPROGRAMPROC, clCompileProgram); \ - BX_CL_IMPORT_12(false, PFNCLLINKPROGRAMPROC, clLinkProgram); \ - BX_CL_IMPORT_12(false, PFNCLUNLOADPLATFORMCOMPILERPROC, clUnloadPlatformCompiler); \ - /* Kernel Object APIs */ \ - BX_CL_IMPORT_12(false, PFNCLGETKERNELARGINFOPROC, clGetKernelArgInfo); \ - /* Enqueued Commands APIs */ \ - BX_CL_IMPORT_12(false, PFNCLENQUEUEFILLBUFFERPROC, clEnqueueFillBuffer); \ - BX_CL_IMPORT_12(false, PFNCLENQUEUEFILLIMAGEPROC, clEnqueueFillImage); \ - BX_CL_IMPORT_12(false, PFNCLENQUEUEMIGRATEMEMOBJECTSPROC, clEnqueueMigrateMemObjects); \ - BX_CL_IMPORT_12(false, PFNCLENQUEUEMARKERWITHWAITLISTPROC, clEnqueueMarkerWithWaitList); \ - BX_CL_IMPORT_12(false, PFNCLENQUEUEBARRIERWITHWAITLISTPROC, clEnqueueBarrierWithWaitList); \ - \ - BX_CL_IMPORT_END - -#define BX_CL_IMPORT_ALL \ - BX_CL_IMPORT_ALL_10 \ - BX_CL_IMPORT_ALL_11 \ - BX_CL_IMPORT_ALL_12 \ - \ - BX_CL_IMPORT_END - -#define BX_CL_IMPORT_10(_optional, _proto, _func) BX_CL_IMPORT(10, _optional, _proto, _func) -#define BX_CL_IMPORT_11(_optional, _proto, _func) BX_CL_IMPORT(11, _optional, _proto, _func) -#define BX_CL_IMPORT_12(_optional, _proto, _func) BX_CL_IMPORT(12, _optional, _proto, _func) -#define BX_CL_IMPORT_END - -#define BX_CL_IMPORT(_version, _optional, _proto, _func) extern "C" _proto _func -BX_CL_IMPORT_ALL -#undef BX_CL_IMPORT - -#if defined(BX_CL_IMPLEMENTATION) -extern "C" -{ -#define BX_CL_IMPORT(_version, _optional, _proto, _func) _proto _func -BX_CL_IMPORT_ALL -#undef BX_CL_IMPORT -}; - -#include "os.h" - -namespace bx -{ - struct OpenCLContext - { - OpenCLContext() - : m_handle(NULL) - , m_refCount(0) - { - } - - int32_t load() - { - if (NULL != m_handle) - { - int32_t ref = ++m_refCount; - return ref; - } - - const char* filePath = -#if BX_PLATFORM_LINUX - "libOpenCL.so" -#elif BX_PLATFORM_OSX - "/Library/Frameworks/OpenCL.framework/OpenCL" -#elif BX_PLATFORM_WINDOWS - "opencl.dll" -#else - "??? unknown OpenCL platform ???" -#endif // BX_PLATFORM_ - ; - - m_handle = bx::dlopen(filePath); - if (NULL == m_handle) - { - BX_TRACE("Unable to find OpenCL '%s' dynamic library.", filePath); - return 0; - } - - m_refCount = 1; - -#define BX_CL_IMPORT(_version, _optional, _proto, _func) _func = (_proto)bx::dlsym(m_handle, #_func) - BX_CL_IMPORT_ALL -#undef BX_CL_IMPORT - - return 1; - } - - int32_t unload() - { - BX_CHECK(m_refCount > 0 && NULL != m_handle, "OpenCL is not loaded."); - - int32_t ref = --m_refCount; - if (0 == ref) - { - dlclose(m_handle); - m_handle = NULL; - } - - return ref; - } - - void* m_handle; - int32_t m_refCount; - }; - - static OpenCLContext s_ctx; - - int32_t clLoad() - { - return s_ctx.load(); - } - - int32_t clUnload() - { - return s_ctx.unload(); - } - -} // namespace bx - -#undef BX_CL_IMPORT_ALL -#undef BX_CL_IMPORT_ALL_10 -#undef BX_CL_IMPORT_ALL_11 -#undef BX_CL_IMPORT_ALL_12 -#undef BX_CL_IMPORT_END - -#endif // defined(BX_CL_IMPLEMENTATION) - -#endif // __OPENCL_CL_H - -#endif // BX_CL_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/config.h b/3rdparty/bx/include/bx/config.h index 86a81521161..2f7264f7c52 100644 --- a/3rdparty/bx/include/bx/config.h +++ b/3rdparty/bx/include/bx/config.h @@ -6,7 +6,7 @@ #ifndef BX_CONFIG_H_HEADER_GUARD #define BX_CONFIG_H_HEADER_GUARD -#include "platform.h" +#include "bx.h" #ifndef BX_CONFIG_ALLOCATOR_DEBUG # define BX_CONFIG_ALLOCATOR_DEBUG 0 @@ -16,30 +16,29 @@ # define BX_CONFIG_ALLOCATOR_CRT 1 #endif // BX_CONFIG_ALLOCATOR_CRT -#ifndef BX_CONFIG_SPSCQUEUE_USE_MUTEX -# define BX_CONFIG_SPSCQUEUE_USE_MUTEX 0 -#endif // BX_CONFIG_SPSCQUEUE_USE_MUTEX - #ifndef BX_CONFIG_CRT_FILE_READER_WRITER -# define BX_CONFIG_CRT_FILE_READER_WRITER !(BX_PLATFORM_NACL) +# define BX_CONFIG_CRT_FILE_READER_WRITER !(0 \ + || BX_PLATFORM_NACL \ + || BX_CRT_NONE \ + ) #endif // BX_CONFIG_CRT_FILE_READER_WRITER #ifndef BX_CONFIG_CRT_PROCESS -# define BX_CONFIG_CRT_PROCESS !(0 \ +# define BX_CONFIG_CRT_PROCESS !(0 \ + || BX_CRT_NONE \ || BX_PLATFORM_EMSCRIPTEN \ - || BX_PLATFORM_NACL \ - || BX_PLATFORM_PS4 \ - || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOXONE \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOXONE \ ) #endif // BX_CONFIG_CRT_PROCESS -#ifndef BX_CONFIG_SEMAPHORE_PTHREAD -# define BX_CONFIG_SEMAPHORE_PTHREAD (BX_PLATFORM_OSX || BX_PLATFORM_IOS) -#endif // BX_CONFIG_SEMAPHORE_PTHREAD - #ifndef BX_CONFIG_SUPPORTS_THREADING -# define BX_CONFIG_SUPPORTS_THREADING !(BX_PLATFORM_EMSCRIPTEN) +# define BX_CONFIG_SUPPORTS_THREADING !(0 \ + || BX_PLATFORM_EMSCRIPTEN \ + || BX_CRT_NONE \ + ) #endif // BX_CONFIG_SUPPORTS_THREADING #endif // BX_CONFIG_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/debug.h b/3rdparty/bx/include/bx/debug.h index 641a0ed82bf..7c2ca8634d0 100644 --- a/3rdparty/bx/include/bx/debug.h +++ b/3rdparty/bx/include/bx/debug.h @@ -7,7 +7,6 @@ #define BX_DEBUG_H_HEADER_GUARD #include "bx.h" -#include <stdarg.h> // va_list namespace bx { diff --git a/3rdparty/bx/include/bx/easing.h b/3rdparty/bx/include/bx/easing.h index 9efbc515378..62131578450 100644 --- a/3rdparty/bx/include/bx/easing.h +++ b/3rdparty/bx/include/bx/easing.h @@ -193,6 +193,6 @@ namespace bx } // namespace bx -#include "easing.inl" +#include "inline/easing.inl" #endif // BX_EASING_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/endian.h b/3rdparty/bx/include/bx/endian.h index c687d4fa0f2..fdc1933e35b 100644 --- a/3rdparty/bx/include/bx/endian.h +++ b/3rdparty/bx/include/bx/endian.h @@ -45,6 +45,6 @@ namespace bx } // namespace bx -#include "endian.inl" +#include "inline/endian.inl" #endif // BX_ENDIAN_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/error.h b/3rdparty/bx/include/bx/error.h index 72a8444342c..47d6d8275a4 100644 --- a/3rdparty/bx/include/bx/error.h +++ b/3rdparty/bx/include/bx/error.h @@ -6,7 +6,6 @@ #ifndef BX_ERROR_H_HEADER_GUARD #define BX_ERROR_H_HEADER_GUARD -#include "bx.h" #include "string.h" #define BX_ERROR_SET(_ptr, _result, _msg) \ @@ -94,6 +93,6 @@ namespace bx } // namespace bx -#include "error.inl" +#include "inline/error.inl" #endif // BX_ERROR_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/float4x4_t.h b/3rdparty/bx/include/bx/float4x4_t.h index e1a5eedfa70..44569b95a76 100644 --- a/3rdparty/bx/include/bx/float4x4_t.h +++ b/3rdparty/bx/include/bx/float4x4_t.h @@ -44,7 +44,7 @@ namespace bx return result; } - BX_SIMD_INLINE void float4x4_mul(float4x4_t* __restrict _result, const float4x4_t* __restrict _a, const float4x4_t* __restrict _b) + BX_SIMD_INLINE void float4x4_mul(float4x4_t* _result, const float4x4_t* _a, const float4x4_t* _b) { _result->col[0] = simd_mul(_a->col[0], _b); _result->col[1] = simd_mul(_a->col[1], _b); @@ -52,7 +52,7 @@ namespace bx _result->col[3] = simd_mul(_a->col[3], _b); } - BX_SIMD_FORCE_INLINE void float4x4_transpose(float4x4_t* __restrict _result, const float4x4_t* __restrict _mtx) + BX_SIMD_FORCE_INLINE void float4x4_transpose(float4x4_t* _result, const float4x4_t* _mtx) { const simd128_t aibj = simd_shuf_xAyB(_mtx->col[0], _mtx->col[2]); // aibj const simd128_t emfn = simd_shuf_xAyB(_mtx->col[1], _mtx->col[3]); // emfn @@ -64,7 +64,7 @@ namespace bx _result->col[3] = simd_shuf_zCwD(ckdl, gohp); // dhlp } - BX_SIMD_INLINE void float4x4_inverse(float4x4_t* __restrict _result, const float4x4_t* __restrict _a) + BX_SIMD_INLINE void float4x4_inverse(float4x4_t* _result, const float4x4_t* _a) { const simd128_t tmp0 = simd_shuf_xAzC(_a->col[0], _a->col[1]); const simd128_t tmp1 = simd_shuf_xAzC(_a->col[2], _a->col[3]); diff --git a/3rdparty/bx/include/bx/fpumath.h b/3rdparty/bx/include/bx/fpumath.h index 4c04eb6dc52..b5b319ce047 100644 --- a/3rdparty/bx/include/bx/fpumath.h +++ b/3rdparty/bx/include/bx/fpumath.h @@ -9,8 +9,6 @@ #define BX_FPU_MATH_H_HEADER_GUARD #include "bx.h" -#include <math.h> -#include <string.h> namespace bx { @@ -125,6 +123,9 @@ namespace bx float fcos(float _a); /// + float ftan(float _a); + + /// float facos(float _a); /// @@ -158,7 +159,7 @@ namespace bx bool fequal(float _a, float _b, float _epsilon); /// - bool fequal(const float* __restrict _a, const float* __restrict _b, uint32_t _num, float _epsilon); + bool fequal(const float* _a, const float* _b, uint32_t _num, float _epsilon); /// float fwrap(float _a, float _wrap); @@ -183,93 +184,93 @@ namespace bx float fgain(float _time, float _gain); /// - void vec3Move(float* __restrict _result, const float* __restrict _a); + void vec3Move(float* _result, const float* _a); /// - void vec3Abs(float* __restrict _result, const float* __restrict _a); + void vec3Abs(float* _result, const float* _a); /// - void vec3Neg(float* __restrict _result, const float* __restrict _a); + void vec3Neg(float* _result, const float* _a); /// - void vec3Add(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Add(float* _result, const float* _a, const float* _b); /// - void vec3Add(float* __restrict _result, const float* __restrict _a, float _b); + void vec3Add(float* _result, const float* _a, float _b); /// - void vec3Sub(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Sub(float* _result, const float* _a, const float* _b); /// - void vec3Sub(float* __restrict _result, const float* __restrict _a, float _b); + void vec3Sub(float* _result, const float* _a, float _b); /// - void vec3Mul(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Mul(float* _result, const float* _a, const float* _b); /// - void vec3Mul(float* __restrict _result, const float* __restrict _a, float _b); + void vec3Mul(float* _result, const float* _a, float _b); /// - float vec3Dot(const float* __restrict _a, const float* __restrict _b); + float vec3Dot(const float* _a, const float* _b); /// - void vec3Cross(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Cross(float* _result, const float* _a, const float* _b); /// float vec3Length(const float* _a); /// - void vec3Lerp(float* __restrict _result, const float* __restrict _a, const float* __restrict _b, float _t); + void vec3Lerp(float* _result, const float* _a, const float* _b, float _t); /// - void vec3Lerp(float* __restrict _result, const float* __restrict _a, const float* __restrict _b, const float* __restrict _c); + void vec3Lerp(float* _result, const float* _a, const float* _b, const float* _c); /// - float vec3Norm(float* __restrict _result, const float* __restrict _a); + float vec3Norm(float* _result, const float* _a); /// - void vec3Min(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Min(float* _result, const float* _a, const float* _b); /// - void vec3Max(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void vec3Max(float* _result, const float* _a, const float* _b); /// - void vec3Rcp(float* __restrict _result, const float* __restrict _a); + void vec3Rcp(float* _result, const float* _a); /// Calculate tangent frame from normal. /// - void vec3TangentFrame(const float* __restrict _n, float* __restrict _t, float* __restrict _b); + void vec3TangentFrame(const float* _n, float* _t, float* _b); /// Calculate tangent frame from normal and angle. /// - void vec3TangentFrame(const float* __restrict _n, float* __restrict _t, float* __restrict _b, float _angle); + void vec3TangentFrame(const float* _n, float* _t, float* _b, float _angle); /// void quatIdentity(float* _result); /// - void quatMove(float* __restrict _result, const float* __restrict _a); + void quatMove(float* _result, const float* _a); /// - void quatMulXYZ(float* __restrict _result, const float* __restrict _qa, const float* __restrict _qb); + void quatMulXYZ(float* _result, const float* _qa, const float* _qb); /// - void quatMul(float* __restrict _result, const float* __restrict _qa, const float* __restrict _qb); + void quatMul(float* _result, const float* _qa, const float* _qb); /// - void quatInvert(float* __restrict _result, const float* __restrict _quat); + void quatInvert(float* _result, const float* _quat); /// - float quatDot(const float* __restrict _a, const float* __restrict _b); + float quatDot(const float* _a, const float* _b); /// - void quatNorm(float* __restrict _result, const float* __restrict _quat); + void quatNorm(float* _result, const float* _quat); /// - void quatToEuler(float* __restrict _result, const float* __restrict _quat); + void quatToEuler(float* _result, const float* _quat); /// - void quatRotateAxis(float* __restrict _result, const float* _axis, float _angle); + void quatRotateAxis(float* _result, const float* _axis, float _angle); /// void quatRotateX(float* _result, float _ax); @@ -281,7 +282,7 @@ namespace bx void quatRotateZ(float* _result, float _az); /// - void vec3MulQuat(float* __restrict _result, const float* __restrict _vec, const float* __restrict _quat); + void vec3MulQuat(float* _result, const float* _vec, const float* _quat); /// void mtxIdentity(float* _result); @@ -296,28 +297,28 @@ namespace bx void mtxScale(float* _result, float _scale); /// - void mtxFromNormal(float* __restrict _result, const float* __restrict _normal, float _scale, const float* __restrict _pos); + void mtxFromNormal(float* _result, const float* _normal, float _scale, const float* _pos); /// - void mtxFromNormal(float* __restrict _result, const float* __restrict _normal, float _scale, const float* __restrict _pos, float _angle); + void mtxFromNormal(float* _result, const float* _normal, float _scale, const float* _pos, float _angle); /// - void mtxQuat(float* __restrict _result, const float* __restrict _quat); + void mtxQuat(float* _result, const float* _quat); /// - void mtxQuatTranslation(float* __restrict _result, const float* __restrict _quat, const float* __restrict _translation); + void mtxQuatTranslation(float* _result, const float* _quat, const float* _translation); /// - void mtxQuatTranslationHMD(float* __restrict _result, const float* __restrict _quat, const float* __restrict _translation); + void mtxQuatTranslationHMD(float* _result, const float* _quat, const float* _translation); /// - void mtxLookAtLh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL);; + void mtxLookAtLh(float* _result, const float* _eye, const float* _at, const float* _up = NULL);; /// - void mtxLookAtRh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL); + void mtxLookAtRh(float* _result, const float* _eye, const float* _at, const float* _up = NULL); /// - void mtxLookAt(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up = NULL); + void mtxLookAt(float* _result, const float* _eye, const float* _at, const float* _up = NULL); /// void mtxProj(float* _result, float _ut, float _dt, float _lt, float _rt, float _near, float _far, bool _oglNdc = false); @@ -422,33 +423,33 @@ namespace bx void mtxSRT(float* _result, float _sx, float _sy, float _sz, float _ax, float _ay, float _az, float _tx, float _ty, float _tz); /// - void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat); + void vec3MulMtx(float* _result, const float* _vec, const float* _mat); /// - void vec3MulMtxH(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat); + void vec3MulMtxH(float* _result, const float* _vec, const float* _mat); /// - void vec4MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat); + void vec4MulMtx(float* _result, const float* _vec, const float* _mat); /// - void mtxMul(float* __restrict _result, const float* __restrict _a, const float* __restrict _b); + void mtxMul(float* _result, const float* _a, const float* _b); /// - void mtxTranspose(float* __restrict _result, const float* __restrict _a); + void mtxTranspose(float* _result, const float* _a); /// - void mtx3Inverse(float* __restrict _result, const float* __restrict _a); + void mtx3Inverse(float* _result, const float* _a); /// - void mtxInverse(float* __restrict _result, const float* __restrict _a); + void mtxInverse(float* _result, const float* _a); /// Convert LH to RH projection matrix and vice versa. /// - void mtxProjFlipHandedness(float* __restrict _dst, const float* __restrict _src); + void mtxProjFlipHandedness(float* _dst, const float* _src); /// Convert LH to RH view matrix and vice versa. /// - void mtxViewFlipHandedness(float* __restrict _dst, const float* __restrict _src); + void mtxViewFlipHandedness(float* _dst, const float* _src); /// void calcNormal(float _result[3], float _va[3], float _vb[3], float _vc[3]); @@ -470,6 +471,6 @@ namespace bx } // namespace bx -#include "fpumath.inl" +#include "inline/fpumath.inl" #endif // BX_FPU_MATH_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/handlealloc.h b/3rdparty/bx/include/bx/handlealloc.h index cf8efc585c5..eb98cac5821 100644 --- a/3rdparty/bx/include/bx/handlealloc.h +++ b/3rdparty/bx/include/bx/handlealloc.h @@ -325,6 +325,6 @@ namespace bx } // namespace bx -#include "handlealloc.inl" +#include "inline/handlealloc.inl" #endif // BX_HANDLE_ALLOC_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/hash.h b/3rdparty/bx/include/bx/hash.h index ec0b8164bd0..feade562a3c 100644 --- a/3rdparty/bx/include/bx/hash.h +++ b/3rdparty/bx/include/bx/hash.h @@ -7,6 +7,7 @@ #define BX_HASH_H_HEADER_GUARD #include "allocator.h" // isAligned +#include "string.h" // StringView namespace bx { @@ -55,8 +56,14 @@ namespace bx template <typename Ty> uint32_t hashMurmur2A(const Ty& _data); + /// + uint32_t hashMurmur2A(const StringView& _data); + + /// + uint32_t hashMurmur2A(const char* _data); + } // namespace bx -#include "hash.inl" +#include "inline/hash.inl" #endif // BX_HASH_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/allocator.inl b/3rdparty/bx/include/bx/inline/allocator.inl index 67a4a5325c5..8a4898d8f60 100644 --- a/3rdparty/bx/include/bx/allocator.inl +++ b/3rdparty/bx/include/bx/inline/allocator.inl @@ -85,7 +85,7 @@ namespace bx } aligned = ptr + offset; - ::memmove(newAligned, aligned, _size); + memMove(newAligned, aligned, _size); uint32_t* header = (uint32_t*)newAligned - 1; *header = uint32_t(newAligned - ptr); return newAligned; diff --git a/3rdparty/bx/include/bx/inline/bx.inl b/3rdparty/bx/include/bx/inline/bx.inl new file mode 100644 index 00000000000..f8e9c6303d4 --- /dev/null +++ b/3rdparty/bx/include/bx/inline/bx.inl @@ -0,0 +1,35 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_H_HEADER_GUARD +# error "Must be included from bx/bx.h!" +#endif // BX_H_HEADER_GUARD + +namespace bx +{ + template<bool> + inline bool isEnabled() + { + return true; + } + + template<> + inline bool isEnabled<false>() + { + return false; + } + + inline bool ignoreC4127(bool _x) + { + return _x; + } + + template<typename Ty> + inline void xchg(Ty& _a, Ty& _b) + { + Ty tmp = _a; _a = _b; _b = tmp; + } + +} // namespace bx diff --git a/3rdparty/bx/include/bx/easing.inl b/3rdparty/bx/include/bx/inline/easing.inl index b23edb1128a..b23edb1128a 100644 --- a/3rdparty/bx/include/bx/easing.inl +++ b/3rdparty/bx/include/bx/inline/easing.inl diff --git a/3rdparty/bx/include/bx/endian.inl b/3rdparty/bx/include/bx/inline/endian.inl index 6ec7572c71c..6ec7572c71c 100644 --- a/3rdparty/bx/include/bx/endian.inl +++ b/3rdparty/bx/include/bx/inline/endian.inl diff --git a/3rdparty/bx/include/bx/error.inl b/3rdparty/bx/include/bx/inline/error.inl index ac16c6f9841..ac16c6f9841 100644 --- a/3rdparty/bx/include/bx/error.inl +++ b/3rdparty/bx/include/bx/inline/error.inl diff --git a/3rdparty/bx/include/bx/fpumath.inl b/3rdparty/bx/include/bx/inline/fpumath.inl index 8a81fc27819..e87b8272b2c 100644 --- a/3rdparty/bx/include/bx/fpumath.inl +++ b/3rdparty/bx/include/bx/inline/fpumath.inl @@ -9,10 +9,6 @@ # error "Must be included from bx/fpumath.h!" #endif // BX_FPU_MATH_H_HEADER_GUARD -#include "bx.h" -#include <math.h> -#include <string.h> - namespace bx { inline float toRad(float _deg) @@ -85,16 +81,6 @@ namespace bx return tmp == UINT64_C(0x7ff0000000000000); } - inline float ffloor(float _f) - { - return floorf(_f); - } - - inline float fceil(float _f) - { - return ceilf(_f); - } - inline float fround(float _f) { return ffloor(_f + 0.5f); @@ -140,66 +126,21 @@ namespace bx return _a < 0.0f ? -1.0f : 1.0f; } - inline float fabsolute(float _a) - { - return fabsf(_a); - } - inline float fsq(float _a) { return _a * _a; } - inline float fsin(float _a) - { - return sinf(_a); - } - - inline float fasin(float _a) - { - return asinf(_a); - } - - inline float fcos(float _a) - { - return cosf(_a); - } - - inline float facos(float _a) - { - return acosf(_a); - } - - inline float fatan2(float _y, float _x) - { - return atan2f(_y, _x); - } - - inline float fpow(float _a, float _b) - { - return powf(_a, _b); - } - inline float fexp2(float _a) { return fpow(2.0f, _a); } - inline float flog(float _a) - { - return logf(_a); - } - inline float flog2(float _a) { return flog(_a) * 1.442695041f; } - inline float fsqrt(float _a) - { - return sqrtf(_a); - } - inline float frsqrt(float _a) { return 1.0f/fsqrt(_a); @@ -207,12 +148,7 @@ namespace bx inline float ffract(float _a) { - return _a - floorf(_a); - } - - inline float fmod(float _a, float _b) - { - return fmodf(_a, _b); + return _a - ffloor(_a); } inline bool fequal(float _a, float _b, float _epsilon) @@ -223,7 +159,7 @@ namespace bx return lhs <= rhs; } - inline bool fequal(const float* __restrict _a, const float* __restrict _b, uint32_t _num, float _epsilon) + inline bool fequal(const float* _a, const float* _b, uint32_t _num, float _epsilon) { bool equal = fequal(_a[0], _b[0], _epsilon); for (uint32_t ii = 1; equal && ii < _num; ++ii) @@ -270,75 +206,75 @@ namespace bx return fbias(_time * 2.0f - 1.0f, 1.0f - _gain) * 0.5f + 0.5f; } - inline void vec3Move(float* __restrict _result, const float* __restrict _a) + inline void vec3Move(float* _result, const float* _a) { _result[0] = _a[0]; _result[1] = _a[1]; _result[2] = _a[2]; } - inline void vec3Abs(float* __restrict _result, const float* __restrict _a) + inline void vec3Abs(float* _result, const float* _a) { _result[0] = fabsolute(_a[0]); _result[1] = fabsolute(_a[1]); _result[2] = fabsolute(_a[2]); } - inline void vec3Neg(float* __restrict _result, const float* __restrict _a) + inline void vec3Neg(float* _result, const float* _a) { _result[0] = -_a[0]; _result[1] = -_a[1]; _result[2] = -_a[2]; } - inline void vec3Add(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Add(float* _result, const float* _a, const float* _b) { _result[0] = _a[0] + _b[0]; _result[1] = _a[1] + _b[1]; _result[2] = _a[2] + _b[2]; } - inline void vec3Add(float* __restrict _result, const float* __restrict _a, float _b) + inline void vec3Add(float* _result, const float* _a, float _b) { _result[0] = _a[0] + _b; _result[1] = _a[1] + _b; _result[2] = _a[2] + _b; } - inline void vec3Sub(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Sub(float* _result, const float* _a, const float* _b) { _result[0] = _a[0] - _b[0]; _result[1] = _a[1] - _b[1]; _result[2] = _a[2] - _b[2]; } - inline void vec3Sub(float* __restrict _result, const float* __restrict _a, float _b) + inline void vec3Sub(float* _result, const float* _a, float _b) { _result[0] = _a[0] - _b; _result[1] = _a[1] - _b; _result[2] = _a[2] - _b; } - inline void vec3Mul(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Mul(float* _result, const float* _a, const float* _b) { _result[0] = _a[0] * _b[0]; _result[1] = _a[1] * _b[1]; _result[2] = _a[2] * _b[2]; } - inline void vec3Mul(float* __restrict _result, const float* __restrict _a, float _b) + inline void vec3Mul(float* _result, const float* _a, float _b) { _result[0] = _a[0] * _b; _result[1] = _a[1] * _b; _result[2] = _a[2] * _b; } - inline float vec3Dot(const float* __restrict _a, const float* __restrict _b) + inline float vec3Dot(const float* _a, const float* _b) { return _a[0]*_b[0] + _a[1]*_b[1] + _a[2]*_b[2]; } - inline void vec3Cross(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Cross(float* _result, const float* _a, const float* _b) { _result[0] = _a[1]*_b[2] - _a[2]*_b[1]; _result[1] = _a[2]*_b[0] - _a[0]*_b[2]; @@ -350,21 +286,21 @@ namespace bx return fsqrt(vec3Dot(_a, _a) ); } - inline void vec3Lerp(float* __restrict _result, const float* __restrict _a, const float* __restrict _b, float _t) + inline void vec3Lerp(float* _result, const float* _a, const float* _b, float _t) { _result[0] = flerp(_a[0], _b[0], _t); _result[1] = flerp(_a[1], _b[1], _t); _result[2] = flerp(_a[2], _b[2], _t); } - inline void vec3Lerp(float* __restrict _result, const float* __restrict _a, const float* __restrict _b, const float* __restrict _c) + inline void vec3Lerp(float* _result, const float* _a, const float* _b, const float* _c) { _result[0] = flerp(_a[0], _b[0], _c[0]); _result[1] = flerp(_a[1], _b[1], _c[1]); _result[2] = flerp(_a[2], _b[2], _c[2]); } - inline float vec3Norm(float* __restrict _result, const float* __restrict _a) + inline float vec3Norm(float* _result, const float* _a) { const float len = vec3Length(_a); const float invLen = 1.0f/len; @@ -374,28 +310,28 @@ namespace bx return len; } - inline void vec3Min(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Min(float* _result, const float* _a, const float* _b) { _result[0] = fmin(_a[0], _b[0]); _result[1] = fmin(_a[1], _b[1]); _result[2] = fmin(_a[2], _b[2]); } - inline void vec3Max(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void vec3Max(float* _result, const float* _a, const float* _b) { _result[0] = fmax(_a[0], _b[0]); _result[1] = fmax(_a[1], _b[1]); _result[2] = fmax(_a[2], _b[2]); } - inline void vec3Rcp(float* __restrict _result, const float* __restrict _a) + inline void vec3Rcp(float* _result, const float* _a) { _result[0] = 1.0f / _a[0]; _result[1] = 1.0f / _a[1]; _result[2] = 1.0f / _a[2]; } - inline void vec3TangentFrame(const float* __restrict _n, float* __restrict _t, float* __restrict _b) + inline void vec3TangentFrame(const float* _n, float* _t, float* _b) { const float nx = _n[0]; const float ny = _n[1]; @@ -419,7 +355,7 @@ namespace bx bx::vec3Cross(_b, _n, _t); } - inline void vec3TangentFrame(const float* __restrict _n, float* __restrict _t, float* __restrict _b, float _angle) + inline void vec3TangentFrame(const float* _n, float* _t, float* _b, float _angle) { vec3TangentFrame(_n, _t, _b); @@ -441,7 +377,7 @@ namespace bx _result[3] = 1.0f; } - inline void quatMove(float* __restrict _result, const float* __restrict _a) + inline void quatMove(float* _result, const float* _a) { _result[0] = _a[0]; _result[1] = _a[1]; @@ -449,7 +385,7 @@ namespace bx _result[3] = _a[3]; } - inline void quatMulXYZ(float* __restrict _result, const float* __restrict _qa, const float* __restrict _qb) + inline void quatMulXYZ(float* _result, const float* _qa, const float* _qb) { const float ax = _qa[0]; const float ay = _qa[1]; @@ -466,7 +402,7 @@ namespace bx _result[2] = aw * bz + ax * by - ay * bx + az * bw; } - inline void quatMul(float* __restrict _result, const float* __restrict _qa, const float* __restrict _qb) + inline void quatMul(float* _result, const float* _qa, const float* _qb) { const float ax = _qa[0]; const float ay = _qa[1]; @@ -484,7 +420,7 @@ namespace bx _result[3] = aw * bw - ax * bx - ay * by - az * bz; } - inline void quatInvert(float* __restrict _result, const float* __restrict _quat) + inline void quatInvert(float* _result, const float* _quat) { _result[0] = -_quat[0]; _result[1] = -_quat[1]; @@ -492,7 +428,7 @@ namespace bx _result[3] = _quat[3]; } - inline float quatDot(const float* __restrict _a, const float* __restrict _b) + inline float quatDot(const float* _a, const float* _b) { return _a[0]*_b[0] + _a[1]*_b[1] @@ -501,7 +437,7 @@ namespace bx ; } - inline void quatNorm(float* __restrict _result, const float* __restrict _quat) + inline void quatNorm(float* _result, const float* _quat) { const float norm = quatDot(_quat, _quat); if (0.0f < norm) @@ -518,7 +454,7 @@ namespace bx } } - inline void quatToEuler(float* __restrict _result, const float* __restrict _quat) + inline void quatToEuler(float* _result, const float* _quat) { const float x = _quat[0]; const float y = _quat[1]; @@ -534,7 +470,7 @@ namespace bx _result[2] = fasin (2.0f * (x * y + z * w) ); } - inline void quatRotateAxis(float* __restrict _result, const float* _axis, float _angle) + inline void quatRotateAxis(float* _result, const float* _axis, float _angle) { const float ha = _angle * 0.5f; const float ca = fcos(ha); @@ -578,7 +514,7 @@ namespace bx _result[3] = cz; } - inline void vec3MulQuat(float* __restrict _result, const float* __restrict _vec, const float* __restrict _quat) + inline void vec3MulQuat(float* _result, const float* _vec, const float* _quat) { float tmp0[4]; quatInvert(tmp0, _quat); @@ -597,7 +533,7 @@ namespace bx inline void mtxIdentity(float* _result) { - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[0] = _result[5] = _result[10] = _result[15] = 1.0f; } @@ -611,7 +547,7 @@ namespace bx inline void mtxScale(float* _result, float _sx, float _sy, float _sz) { - memset(_result, 0, sizeof(float) * 16); + memSet(_result, 0, sizeof(float) * 16); _result[0] = _sx; _result[5] = _sy; _result[10] = _sz; @@ -623,7 +559,7 @@ namespace bx mtxScale(_result, _scale, _scale, _scale); } - inline void mtxFromNormal(float* __restrict _result, const float* __restrict _normal, float _scale, const float* __restrict _pos) + inline void mtxFromNormal(float* _result, const float* _normal, float _scale, const float* _pos) { float tangent[3]; float bitangent[3]; @@ -642,7 +578,7 @@ namespace bx _result[15] = 1.0f; } - inline void mtxFromNormal(float* __restrict _result, const float* __restrict _normal, float _scale, const float* __restrict _pos, float _angle) + inline void mtxFromNormal(float* _result, const float* _normal, float _scale, const float* _pos, float _angle) { float tangent[3]; float bitangent[3]; @@ -661,7 +597,7 @@ namespace bx _result[15] = 1.0f; } - inline void mtxQuat(float* __restrict _result, const float* __restrict _quat) + inline void mtxQuat(float* _result, const float* _quat) { const float x = _quat[0]; const float y = _quat[1]; @@ -702,7 +638,7 @@ namespace bx _result[15] = 1.0f; } - inline void mtxQuatTranslation(float* __restrict _result, const float* __restrict _quat, const float* __restrict _translation) + inline void mtxQuatTranslation(float* _result, const float* _quat, const float* _translation) { mtxQuat(_result, _quat); _result[12] = -(_result[0]*_translation[0] + _result[4]*_translation[1] + _result[ 8]*_translation[2]); @@ -710,7 +646,7 @@ namespace bx _result[14] = -(_result[2]*_translation[0] + _result[6]*_translation[1] + _result[10]*_translation[2]); } - inline void mtxQuatTranslationHMD(float* __restrict _result, const float* __restrict _quat, const float* __restrict _translation) + inline void mtxQuatTranslationHMD(float* _result, const float* _quat, const float* _translation) { float quat[4]; quat[0] = -_quat[0]; @@ -720,7 +656,7 @@ namespace bx mtxQuatTranslation(_result, quat, _translation); } - inline void mtxLookAt_Impl(float* __restrict _result, const float* __restrict _eye, const float* __restrict _view, const float* __restrict _up) + inline void mtxLookAt_Impl(float* _result, const float* _eye, const float* _view, const float* _up) { float up[3] = { 0.0f, 1.0f, 0.0f }; if (NULL != _up) @@ -738,7 +674,7 @@ namespace bx vec3Cross(up, _view, right); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = right[0]; _result[ 1] = up[0]; _result[ 2] = _view[0]; @@ -757,7 +693,7 @@ namespace bx _result[15] = 1.0f; } - inline void mtxLookAtLh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up) + inline void mtxLookAtLh(float* _result, const float* _eye, const float* _at, const float* _up) { float tmp[4]; vec3Sub(tmp, _at, _eye); @@ -768,7 +704,7 @@ namespace bx mtxLookAt_Impl(_result, _eye, view, _up); } - inline void mtxLookAtRh(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up) + inline void mtxLookAtRh(float* _result, const float* _eye, const float* _at, const float* _up) { float tmp[4]; vec3Sub(tmp, _eye, _at); @@ -779,7 +715,7 @@ namespace bx mtxLookAt_Impl(_result, _eye, view, _up); } - inline void mtxLookAt(float* __restrict _result, const float* __restrict _eye, const float* __restrict _at, const float* __restrict _up) + inline void mtxLookAt(float* _result, const float* _eye, const float* _at, const float* _up) { mtxLookAtLh(_result, _eye, _at, _up); } @@ -791,7 +727,7 @@ namespace bx const float aa = _oglNdc ? (_far+_near)/diff : _far/diff; const float bb = _oglNdc ? (2.0f*_far*_near)/diff : _near*aa; - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; _result[ 8] = (Handness::Right == HandnessT) ? _x : -_x; @@ -822,7 +758,7 @@ namespace bx template <Handness::Enum HandnessT> inline void mtxProj_impl(float* _result, float _fovy, float _aspect, float _near, float _far, bool _oglNdc) { - const float height = 1.0f/tanf(toRad(_fovy)*0.5f); + const float height = 1.0f/ftan(toRad(_fovy)*0.5f); const float width = height * 1.0f/_aspect; mtxProjXYWH<HandnessT>(_result, 0.0f, 0.0f, width, height, _near, _far, _oglNdc); } @@ -888,7 +824,7 @@ namespace bx bb = _oglNdc ? 2.0f*_near : _near; } - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = _width; _result[ 5] = _height; _result[ 8] = (Handness::Right == HandnessT) ? _x : -_x; @@ -919,7 +855,7 @@ namespace bx template <NearFar::Enum NearFarT, Handness::Enum HandnessT> inline void mtxProjInf_impl(float* _result, float _fovy, float _aspect, float _near, bool _oglNdc) { - const float height = 1.0f/tanf(toRad(_fovy)*0.5f); + const float height = 1.0f/ftan(toRad(_fovy)*0.5f); const float width = height * 1.0f/_aspect; mtxProjInfXYWH<NearFarT,HandnessT>(_result, 0.0f, 0.0f, width, height, _near, _oglNdc); } @@ -1009,7 +945,7 @@ namespace bx const float ee = (_top + _bottom)/(_bottom - _top); const float ff = _oglNdc ? (_near + _far)/(_near - _far) : _near/(_near - _far); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = aa; _result[ 5] = bb; _result[10] = (Handness::Right == HandnessT) ? -cc : cc; @@ -1039,7 +975,7 @@ namespace bx const float sx = fsin(_ax); const float cx = fcos(_ax); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = 1.0f; _result[ 5] = cx; _result[ 6] = -sx; @@ -1053,7 +989,7 @@ namespace bx const float sy = fsin(_ay); const float cy = fcos(_ay); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = cy; _result[ 2] = sy; _result[ 5] = 1.0f; @@ -1067,7 +1003,7 @@ namespace bx const float sz = fsin(_az); const float cz = fcos(_az); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = cz; _result[ 1] = -sz; _result[ 4] = sz; @@ -1083,7 +1019,7 @@ namespace bx const float sy = fsin(_ay); const float cy = fcos(_ay); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = cy; _result[ 2] = sy; _result[ 4] = sx*sy; @@ -1104,7 +1040,7 @@ namespace bx const float sz = fsin(_az); const float cz = fcos(_az); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = cy*cz; _result[ 1] = -cy*sz; _result[ 2] = sy; @@ -1126,7 +1062,7 @@ namespace bx const float sz = fsin(_az); const float cz = fcos(_az); - memset(_result, 0, sizeof(float)*16); + memSet(_result, 0, sizeof(float)*16); _result[ 0] = cy*cz; _result[ 1] = cz*sx*sy-cx*sz; _result[ 2] = cx*cz*sy+sx*sz; @@ -1172,14 +1108,14 @@ namespace bx _result[15] = 1.0f; } - inline void vec3MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat) + inline void vec3MulMtx(float* _result, const float* _vec, const float* _mat) { _result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12]; _result[1] = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13]; _result[2] = _vec[0] * _mat[ 2] + _vec[1] * _mat[6] + _vec[2] * _mat[10] + _mat[14]; } - inline void vec3MulMtxH(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat) + inline void vec3MulMtxH(float* _result, const float* _vec, const float* _mat) { float xx = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _mat[12]; float yy = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _mat[13]; @@ -1191,7 +1127,7 @@ namespace bx _result[2] = zz*invW; } - inline void vec4MulMtx(float* __restrict _result, const float* __restrict _vec, const float* __restrict _mat) + inline void vec4MulMtx(float* _result, const float* _vec, const float* _mat) { _result[0] = _vec[0] * _mat[ 0] + _vec[1] * _mat[4] + _vec[2] * _mat[ 8] + _vec[3] * _mat[12]; _result[1] = _vec[0] * _mat[ 1] + _vec[1] * _mat[5] + _vec[2] * _mat[ 9] + _vec[3] * _mat[13]; @@ -1199,7 +1135,7 @@ namespace bx _result[3] = _vec[0] * _mat[ 3] + _vec[1] * _mat[7] + _vec[2] * _mat[11] + _vec[3] * _mat[15]; } - inline void mtxMul(float* __restrict _result, const float* __restrict _a, const float* __restrict _b) + inline void mtxMul(float* _result, const float* _a, const float* _b) { vec4MulMtx(&_result[ 0], &_a[ 0], _b); vec4MulMtx(&_result[ 4], &_a[ 4], _b); @@ -1207,7 +1143,7 @@ namespace bx vec4MulMtx(&_result[12], &_a[12], _b); } - inline void mtxTranspose(float* __restrict _result, const float* __restrict _a) + inline void mtxTranspose(float* _result, const float* _a) { _result[ 0] = _a[ 0]; _result[ 4] = _a[ 1]; @@ -1228,7 +1164,7 @@ namespace bx } /// Convert LH to RH projection matrix and vice versa. - inline void mtxProjFlipHandedness(float* __restrict _dst, const float* __restrict _src) + inline void mtxProjFlipHandedness(float* _dst, const float* _src) { _dst[ 0] = -_src[ 0]; _dst[ 1] = -_src[ 1]; @@ -1249,7 +1185,7 @@ namespace bx } /// Convert LH to RH view matrix and vice versa. - inline void mtxViewFlipHandedness(float* __restrict _dst, const float* __restrict _src) + inline void mtxViewFlipHandedness(float* _dst, const float* _src) { _dst[ 0] = -_src[ 0]; _dst[ 1] = _src[ 1]; diff --git a/3rdparty/bx/include/bx/handlealloc.inl b/3rdparty/bx/include/bx/inline/handlealloc.inl index 04369b57d78..8738c3d7038 100644 --- a/3rdparty/bx/include/bx/handlealloc.inl +++ b/3rdparty/bx/include/bx/inline/handlealloc.inl @@ -7,10 +7,6 @@ # error "Must be included from bx/handlealloc.h!" #endif // BX_HANDLE_ALLOC_H_HEADER_GUARD -#include "bx.h" -#include "allocator.h" -#include "uint32_t.h" - namespace bx { inline HandleAlloc::HandleAlloc(uint16_t _maxHandles) @@ -236,7 +232,7 @@ namespace bx template <uint16_t MaxHandlesT> inline void HandleListT<MaxHandlesT>::reset() { - memset(m_links, 0xff, sizeof(m_links) ); + memSet(m_links, 0xff, sizeof(m_links) ); m_front = invalid; m_back = invalid; } @@ -496,7 +492,7 @@ namespace bx template <uint32_t MaxCapacityT, typename KeyT> inline void HandleHashMapT<MaxCapacityT, KeyT>::reset() { - memset(m_handle, 0xff, sizeof(m_handle) ); + memSet(m_handle, 0xff, sizeof(m_handle) ); m_numElements = 0; } diff --git a/3rdparty/bx/include/bx/hash.inl b/3rdparty/bx/include/bx/inline/hash.inl index cfa3eca252c..50da33f0528 100644 --- a/3rdparty/bx/include/bx/hash.inl +++ b/3rdparty/bx/include/bx/inline/hash.inl @@ -151,4 +151,14 @@ namespace bx return hashMurmur2A(&_data, sizeof(Ty) ); } + inline uint32_t hashMurmur2A(const StringView& _data) + { + return hashMurmur2A(_data.getPtr(), _data.getLength() ); + } + + inline uint32_t hashMurmur2A(const char* _data) + { + return hashMurmur2A(StringView(_data) ); + } + } // namespace bx diff --git a/3rdparty/bx/include/bx/inline/mpscqueue.inl b/3rdparty/bx/include/bx/inline/mpscqueue.inl new file mode 100644 index 00000000000..0216b509788 --- /dev/null +++ b/3rdparty/bx/include/bx/inline/mpscqueue.inl @@ -0,0 +1,65 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_MPSCQUEUE_H_HEADER_GUARD +# error "Must be included from bx/mpscqueue.h!" +#endif // BX_MPSCQUEUE_H_HEADER_GUARD + +namespace bx +{ + template <typename Ty> + inline MpScUnboundedQueueT<Ty>::MpScUnboundedQueueT() + { + } + + template <typename Ty> + inline MpScUnboundedQueueT<Ty>::~MpScUnboundedQueueT() + { + } + + template <typename Ty> + inline void MpScUnboundedQueueT<Ty>::push(Ty* _ptr) + { + MutexScope lock(m_write); + m_queue.push(_ptr); + } + + template <typename Ty> + inline Ty* MpScUnboundedQueueT<Ty>::peek() + { + return m_queue.peek(); + } + + template <typename Ty> + inline Ty* MpScUnboundedQueueT<Ty>::pop() + { + return m_queue.pop(); + } + + template <typename Ty> + inline MpScUnboundedBlockingQueue<Ty>::MpScUnboundedBlockingQueue() + { + } + + template <typename Ty> + inline MpScUnboundedBlockingQueue<Ty>::~MpScUnboundedBlockingQueue() + { + } + + template <typename Ty> + inline void MpScUnboundedBlockingQueue<Ty>::push(Ty* _ptr) + { + m_queue.push(_ptr); + m_sem.post(); + } + + template <typename Ty> + inline Ty* MpScUnboundedBlockingQueue<Ty>::pop() + { + m_sem.wait(); + return m_queue.pop(); + } + +} // namespace bx diff --git a/3rdparty/bx/include/bx/mutex.inl b/3rdparty/bx/include/bx/inline/mutex.inl index 0d4140208e1..0d086bdc94c 100644 --- a/3rdparty/bx/include/bx/mutex.inl +++ b/3rdparty/bx/include/bx/inline/mutex.inl @@ -20,15 +20,4 @@ namespace bx m_mutex.unlock(); } - inline LwMutexScope::LwMutexScope(LwMutex& _mutex) - : m_mutex(_mutex) - { - m_mutex.lock(); - } - - inline LwMutexScope::~LwMutexScope() - { - m_mutex.unlock(); - } - } // namespace bx diff --git a/3rdparty/bx/include/bx/pixelformat.inl b/3rdparty/bx/include/bx/inline/pixelformat.inl index be48c85d931..cd4689224be 100644 --- a/3rdparty/bx/include/bx/pixelformat.inl +++ b/3rdparty/bx/include/bx/inline/pixelformat.inl @@ -641,67 +641,67 @@ namespace bx // R32I inline void packR32I(void* _dst, const float* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } inline void unpackR32I(float* _dst, const void* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } // R32U inline void packR32U(void* _dst, const float* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } inline void unpackR32U(float* _dst, const void* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } // R32F inline void packR32F(void* _dst, const float* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } inline void unpackR32F(float* _dst, const void* _src) { - memcpy(_dst, _src, 4); + memCopy(_dst, _src, 4); } // RG32I inline void packRg32I(void* _dst, const float* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } inline void unpackRg32I(float* _dst, const void* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } // RG32U inline void packRg32U(void* _dst, const float* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } inline void unpackRg32U(float* _dst, const void* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } // RG32F inline void packRg32F(void* _dst, const float* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } inline void unpackRg32F(float* _dst, const void* _src) { - memcpy(_dst, _src, 8); + memCopy(_dst, _src, 8); } template<int32_t MantissaBits, int32_t ExpBits> @@ -775,34 +775,34 @@ namespace bx // RGBA32I inline void packRgba32I(void* _dst, const float* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } inline void unpackRgba32I(float* _dst, const void* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } // RGBA32U inline void packRgba32U(void* _dst, const float* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } inline void unpackRgba32U(float* _dst, const void* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } // RGBA32F inline void packRgba32F(void* _dst, const float* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } inline void unpackRgba32F(float* _dst, const void* _src) { - memcpy(_dst, _src, 16); + memCopy(_dst, _src, 16); } // R5G6B5 diff --git a/3rdparty/bx/include/bx/readerwriter.inl b/3rdparty/bx/include/bx/inline/readerwriter.inl index 9ba8517776c..c2eb72a9ed5 100644 --- a/3rdparty/bx/include/bx/readerwriter.inl +++ b/3rdparty/bx/include/bx/inline/readerwriter.inl @@ -170,7 +170,7 @@ namespace bx int64_t remainder = m_top-m_pos; int32_t size = uint32_min(_size, uint32_t(int64_min(remainder, INT32_MAX) ) ); - memcpy(_data, &m_data[m_pos], size); + memCopy(_data, &m_data[m_pos], size); m_pos += size; if (size != _size) { @@ -242,7 +242,7 @@ namespace bx int64_t remainder = m_size-m_pos; int32_t size = uint32_min(_size, uint32_t(int64_min(remainder, INT32_MAX) ) ); - memcpy(&m_data[m_pos], _data, size); + memCopy(&m_data[m_pos], _data, size); m_pos += size; m_top = int64_max(m_top, m_pos); if (size != _size) @@ -301,7 +301,7 @@ namespace bx const uint32_t tmp1 = uint32_sels(256 - _size, 256, tmp0); const uint32_t blockSize = uint32_sels(1024 - _size, 1024, tmp1); uint8_t* temp = (uint8_t*)alloca(blockSize); - memset(temp, _byte, blockSize); + memSet(temp, _byte, blockSize); int32_t size = 0; while (0 < _size) diff --git a/3rdparty/bx/include/bx/inline/ringbuffer.inl b/3rdparty/bx/include/bx/inline/ringbuffer.inl new file mode 100644 index 00000000000..9d8ab942edb --- /dev/null +++ b/3rdparty/bx/include/bx/inline/ringbuffer.inl @@ -0,0 +1,275 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_RINGBUFFER_H_HEADER_GUARD +# error "Must be included from bx/ringbuffer.h!" +#endif // BX_RINGBUFFER_H_HEADER_GUARD + +namespace bx +{ + inline RingBufferControl::RingBufferControl(uint32_t _size) + : m_size(_size) + , m_current(0) + , m_write(0) + , m_read(0) + { + } + + inline RingBufferControl::~RingBufferControl() + { + } + + inline uint32_t RingBufferControl::available() const + { + return distance(m_read, m_current); + } + + inline uint32_t RingBufferControl::consume(uint32_t _size) + { + const uint32_t maxSize = distance(m_read, m_current); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, maxSize); + const uint32_t advance = uint32_add(m_read, size); + const uint32_t read = uint32_mod(advance, m_size); + m_read = read; + return size; + } + + inline uint32_t RingBufferControl::reserve(uint32_t _size, bool _mustSucceed) + { + const uint32_t dist = distance(m_write, m_read)-1; + const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, _mustSucceed ? 0 : maxSize); + const uint32_t advance = uint32_add(m_write, size); + const uint32_t write = uint32_mod(advance, m_size); + m_write = write; + return size; + } + + inline uint32_t RingBufferControl::commit(uint32_t _size) + { + const uint32_t maxSize = distance(m_current, m_write); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, maxSize); + const uint32_t advance = uint32_add(m_current, size); + const uint32_t current = uint32_mod(advance, m_size); + m_current = current; + return size; + } + + inline uint32_t RingBufferControl::distance(uint32_t _from, uint32_t _to) const + { + const uint32_t diff = uint32_sub(_to, _from); + const uint32_t le = uint32_add(m_size, diff); + const uint32_t result = uint32_sels(diff, le, diff); + + return result; + } + + inline void RingBufferControl::reset() + { + m_current = 0; + m_write = 0; + m_read = 0; + } + + inline SpScRingBufferControl::SpScRingBufferControl(uint32_t _size) + : m_size(_size) + , m_current(0) + , m_write(0) + , m_read(0) + { + } + + inline SpScRingBufferControl::~SpScRingBufferControl() + { + } + + inline uint32_t SpScRingBufferControl::available() const + { + return distance(m_read, m_current); + } + + inline uint32_t SpScRingBufferControl::consume(uint32_t _size) + { + const uint32_t maxSize = distance(m_read, m_current); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, maxSize); + const uint32_t advance = uint32_add(m_read, size); + const uint32_t read = uint32_mod(advance, m_size); + m_read = read; + return size; + } + + inline uint32_t SpScRingBufferControl::reserve(uint32_t _size) + { + const uint32_t dist = distance(m_write, m_read)-1; + const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, maxSize); + const uint32_t advance = uint32_add(m_write, size); + const uint32_t write = uint32_mod(advance, m_size); + m_write = write; + return size; + } + + inline uint32_t SpScRingBufferControl::commit(uint32_t _size) + { + const uint32_t maxSize = distance(m_current, m_write); + const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); + const uint32_t test = uint32_sub(sizeNoSign, maxSize); + const uint32_t size = uint32_sels(test, _size, maxSize); + const uint32_t advance = uint32_add(m_current, size); + const uint32_t current = uint32_mod(advance, m_size); + + // must commit all memory writes before moving m_current pointer + // once m_current pointer moves data is used by consumer thread + memoryBarrier(); + m_current = current; + return size; + } + + inline uint32_t SpScRingBufferControl::distance(uint32_t _from, uint32_t _to) const + { + const uint32_t diff = uint32_sub(_to, _from); + const uint32_t le = uint32_add(m_size, diff); + const uint32_t result = uint32_sels(diff, le, diff); + + return result; + } + + inline void SpScRingBufferControl::reset() + { + m_current = 0; + m_write = 0; + m_read = 0; + } + + template <typename ControlT> + inline ReadRingBufferT<ControlT>::ReadRingBufferT(ControlT& _control, const char* _buffer, uint32_t _size) + : m_control(_control) + , m_read(_control.m_read) + , m_end(m_read+_size) + , m_size(_size) + , m_buffer(_buffer) + { + BX_CHECK(_control.available() >= _size, "%d >= %d", _control.available(), _size); + } + + template <typename ControlT> + inline ReadRingBufferT<ControlT>::~ReadRingBufferT() + { + } + + template <typename ControlT> + inline void ReadRingBufferT<ControlT>::end() + { + m_control.consume(m_size); + } + + template <typename ControlT> + inline void ReadRingBufferT<ControlT>::read(char* _data, uint32_t _len) + { + const uint32_t eof = (m_read + _len) % m_control.m_size; + uint32_t wrap = 0; + const char* from = &m_buffer[m_read]; + + if (eof < m_read) + { + wrap = m_control.m_size - m_read; + memCopy(_data, from, wrap); + _data += wrap; + from = (const char*)&m_buffer[0]; + } + + memCopy(_data, from, _len-wrap); + + m_read = eof; + } + + template <typename ControlT> + inline void ReadRingBufferT<ControlT>::skip(uint32_t _len) + { + m_read += _len; + m_read %= m_control.m_size; + } + + template <typename ControlT> + inline WriteRingBufferT<ControlT>::WriteRingBufferT(ControlT& _control, char* _buffer, uint32_t _size) + : m_control(_control) + , m_size(_size) + , m_buffer(_buffer) + { + uint32_t size = m_control.reserve(_size); + BX_UNUSED(size); + BX_CHECK(size == _size, "%d == %d", size, _size); + m_write = m_control.m_current; + m_end = m_write+_size; + } + + template <typename ControlT> + inline WriteRingBufferT<ControlT>::~WriteRingBufferT() + { + } + + template <typename ControlT> + inline void WriteRingBufferT<ControlT>::end() + { + m_control.commit(m_size); + } + + template <typename ControlT> + inline void WriteRingBufferT<ControlT>::write(const char* _data, uint32_t _len) + { + const uint32_t eof = (m_write + _len) % m_control.m_size; + uint32_t wrap = 0; + char* to = &m_buffer[m_write]; + + if (eof < m_write) + { + wrap = m_control.m_size - m_write; + memCopy(to, _data, wrap); + _data += wrap; + to = (char*)&m_buffer[0]; + } + + memCopy(to, _data, _len-wrap); + + m_write = eof; + } + + template <typename ControlT> + inline void WriteRingBufferT<ControlT>::write(ReadRingBufferT<ControlT>& _read, uint32_t _len) + { + const uint32_t eof = (_read.m_read + _len) % _read.m_control.m_size; + uint32_t wrap = 0; + const char* from = &_read.m_buffer[_read.m_read]; + + if (eof < _read.m_read) + { + wrap = _read.m_control.m_size - _read.m_read; + write(from, wrap); + from = (const char*)&_read.m_buffer[0]; + } + + write(from, _len-wrap); + + _read.m_read = eof; + } + + template <typename ControlT> + inline void WriteRingBufferT<ControlT>::skip(uint32_t _len) + { + m_write += _len; + m_write %= m_control.m_size; + } + +} // namespace bx diff --git a/3rdparty/bx/include/bx/rng.inl b/3rdparty/bx/include/bx/inline/rng.inl index 02a4d21e5bc..11b466dadb3 100644 --- a/3rdparty/bx/include/bx/rng.inl +++ b/3rdparty/bx/include/bx/inline/rng.inl @@ -7,10 +7,6 @@ # error "Must be included from bx/rng.h!" #endif // BX_RNG_H_HEADER_GUARD -#include "bx.h" -#include "fpumath.h" -#include "uint32_t.h" - namespace bx { inline RngMwc::RngMwc(uint32_t _z, uint32_t _w) diff --git a/3rdparty/bx/include/bx/simd128_langext.inl b/3rdparty/bx/include/bx/inline/simd128_langext.inl index c89e6123349..c89e6123349 100644 --- a/3rdparty/bx/include/bx/simd128_langext.inl +++ b/3rdparty/bx/include/bx/inline/simd128_langext.inl diff --git a/3rdparty/bx/include/bx/simd128_neon.inl b/3rdparty/bx/include/bx/inline/simd128_neon.inl index 1dd0d1f12b2..1dd0d1f12b2 100644 --- a/3rdparty/bx/include/bx/simd128_neon.inl +++ b/3rdparty/bx/include/bx/inline/simd128_neon.inl diff --git a/3rdparty/bx/include/bx/simd128_ref.inl b/3rdparty/bx/include/bx/inline/simd128_ref.inl index da08f5088b6..e85ae14c979 100644 --- a/3rdparty/bx/include/bx/simd128_ref.inl +++ b/3rdparty/bx/include/bx/inline/simd128_ref.inl @@ -6,8 +6,6 @@ #ifndef BX_SIMD128_REF_H_HEADER_GUARD #define BX_SIMD128_REF_H_HEADER_GUARD -#include <math.h> // sqrtf - #define simd_shuf_xAzC simd_shuf_xAzC_ni #define simd_shuf_yBwD simd_shuf_yBwD_ni #define simd_rcp simd_rcp_ni @@ -396,10 +394,10 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf); BX_SIMD_FORCE_INLINE simd128_ref_t simd_sqrt(simd128_ref_t _a) { simd128_ref_t result; - result.fxyzw[0] = sqrtf(_a.fxyzw[0]); - result.fxyzw[1] = sqrtf(_a.fxyzw[1]); - result.fxyzw[2] = sqrtf(_a.fxyzw[2]); - result.fxyzw[3] = sqrtf(_a.fxyzw[3]); + result.fxyzw[0] = fsqrt(_a.fxyzw[0]); + result.fxyzw[1] = fsqrt(_a.fxyzw[1]); + result.fxyzw[2] = fsqrt(_a.fxyzw[2]); + result.fxyzw[3] = fsqrt(_a.fxyzw[3]); return result; } @@ -407,10 +405,10 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw , 0xf); BX_SIMD_FORCE_INLINE simd128_ref_t simd_rsqrt_est(simd128_ref_t _a) { simd128_ref_t result; - result.fxyzw[0] = 1.0f / sqrtf(_a.fxyzw[0]); - result.fxyzw[1] = 1.0f / sqrtf(_a.fxyzw[1]); - result.fxyzw[2] = 1.0f / sqrtf(_a.fxyzw[2]); - result.fxyzw[3] = 1.0f / sqrtf(_a.fxyzw[3]); + result.fxyzw[0] = 1.0f / fsqrt(_a.fxyzw[0]); + result.fxyzw[1] = 1.0f / fsqrt(_a.fxyzw[1]); + result.fxyzw[2] = 1.0f / fsqrt(_a.fxyzw[2]); + result.fxyzw[3] = 1.0f / fsqrt(_a.fxyzw[3]); return result; } diff --git a/3rdparty/bx/include/bx/simd128_sse.inl b/3rdparty/bx/include/bx/inline/simd128_sse.inl index b0ed8520ab4..b0ed8520ab4 100644 --- a/3rdparty/bx/include/bx/simd128_sse.inl +++ b/3rdparty/bx/include/bx/inline/simd128_sse.inl diff --git a/3rdparty/bx/include/bx/simd128_swizzle.inl b/3rdparty/bx/include/bx/inline/simd128_swizzle.inl index 4185be81b60..4185be81b60 100644 --- a/3rdparty/bx/include/bx/simd128_swizzle.inl +++ b/3rdparty/bx/include/bx/inline/simd128_swizzle.inl diff --git a/3rdparty/bx/include/bx/simd256_avx.inl b/3rdparty/bx/include/bx/inline/simd256_avx.inl index 5eed77ba3af..5eed77ba3af 100644 --- a/3rdparty/bx/include/bx/simd256_avx.inl +++ b/3rdparty/bx/include/bx/inline/simd256_avx.inl diff --git a/3rdparty/bx/include/bx/simd256_ref.inl b/3rdparty/bx/include/bx/inline/simd256_ref.inl index 6d9a5a31ab5..6d9a5a31ab5 100644 --- a/3rdparty/bx/include/bx/simd256_ref.inl +++ b/3rdparty/bx/include/bx/inline/simd256_ref.inl diff --git a/3rdparty/bx/include/bx/simd_ni.inl b/3rdparty/bx/include/bx/inline/simd_ni.inl index 95767f25b95..95767f25b95 100644 --- a/3rdparty/bx/include/bx/simd_ni.inl +++ b/3rdparty/bx/include/bx/inline/simd_ni.inl diff --git a/3rdparty/bx/include/bx/radixsort.inl b/3rdparty/bx/include/bx/inline/sort.inl index 2edc5e40fd3..1f5dcf21690 100644 --- a/3rdparty/bx/include/bx/radixsort.inl +++ b/3rdparty/bx/include/bx/inline/sort.inl @@ -3,9 +3,9 @@ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause */ -#ifndef BX_RADIXSORT_H_HEADER_GUARD -# error "Must be included from bx/radixsort.h!" -#endif // BX_RADIXSORT_H_HEADER_GUARD +#ifndef BX_SORT_H_HEADER_GUARD +# error "Must be included from bx/sort.h!" +#endif // BX_SORT_H_HEADER_GUARD namespace bx { @@ -13,17 +13,17 @@ namespace bx #define BX_RADIXSORT_HISTOGRAM_SIZE (1<<BX_RADIXSORT_BITS) #define BX_RADIXSORT_BIT_MASK (BX_RADIXSORT_HISTOGRAM_SIZE-1) - inline void radixSort(uint32_t* __restrict _keys, uint32_t* __restrict _tempKeys, uint32_t _size) + inline void radixSort(uint32_t* _keys, uint32_t* _tempKeys, uint32_t _size) { - uint32_t* __restrict keys = _keys; - uint32_t* __restrict tempKeys = _tempKeys; + uint32_t* keys = _keys; + uint32_t* tempKeys = _tempKeys; uint32_t histogram[BX_RADIXSORT_HISTOGRAM_SIZE]; uint16_t shift = 0; uint32_t pass = 0; for (; pass < 3; ++pass) { - memset(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); + memSet(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); bool sorted = true; { @@ -70,24 +70,24 @@ done: if (0 != (pass&1) ) { // Odd number of passes needs to do copy to the destination. - memcpy(_keys, _tempKeys, _size*sizeof(uint32_t) ); + memCopy(_keys, _tempKeys, _size*sizeof(uint32_t) ); } } template <typename Ty> - inline void radixSort(uint32_t* __restrict _keys, uint32_t* __restrict _tempKeys, Ty* __restrict _values, Ty* __restrict _tempValues, uint32_t _size) + inline void radixSort(uint32_t* _keys, uint32_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size) { - uint32_t* __restrict keys = _keys; - uint32_t* __restrict tempKeys = _tempKeys; - Ty* __restrict values = _values; - Ty* __restrict tempValues = _tempValues; + uint32_t* keys = _keys; + uint32_t* tempKeys = _tempKeys; + Ty* values = _values; + Ty* tempValues = _tempValues; uint32_t histogram[BX_RADIXSORT_HISTOGRAM_SIZE]; uint16_t shift = 0; uint32_t pass = 0; for (; pass < 3; ++pass) { - memset(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); + memSet(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); bool sorted = true; { @@ -139,7 +139,7 @@ done: if (0 != (pass&1) ) { // Odd number of passes needs to do copy to the destination. - memcpy(_keys, _tempKeys, _size*sizeof(uint32_t) ); + memCopy(_keys, _tempKeys, _size*sizeof(uint32_t) ); for (uint32_t ii = 0; ii < _size; ++ii) { _values[ii] = _tempValues[ii]; @@ -147,17 +147,17 @@ done: } } - inline void radixSort(uint64_t* __restrict _keys, uint64_t* __restrict _tempKeys, uint32_t _size) + inline void radixSort(uint64_t* _keys, uint64_t* _tempKeys, uint32_t _size) { - uint64_t* __restrict keys = _keys; - uint64_t* __restrict tempKeys = _tempKeys; + uint64_t* keys = _keys; + uint64_t* tempKeys = _tempKeys; uint32_t histogram[BX_RADIXSORT_HISTOGRAM_SIZE]; uint16_t shift = 0; uint32_t pass = 0; for (; pass < 6; ++pass) { - memset(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); + memSet(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); bool sorted = true; { @@ -204,24 +204,24 @@ done: if (0 != (pass&1) ) { // Odd number of passes needs to do copy to the destination. - memcpy(_keys, _tempKeys, _size*sizeof(uint64_t) ); + memCopy(_keys, _tempKeys, _size*sizeof(uint64_t) ); } } template <typename Ty> - inline void radixSort(uint64_t* __restrict _keys, uint64_t* __restrict _tempKeys, Ty* __restrict _values, Ty* __restrict _tempValues, uint32_t _size) + inline void radixSort(uint64_t* _keys, uint64_t* _tempKeys, Ty* _values, Ty* _tempValues, uint32_t _size) { - uint64_t* __restrict keys = _keys; - uint64_t* __restrict tempKeys = _tempKeys; - Ty* __restrict values = _values; - Ty* __restrict tempValues = _tempValues; + uint64_t* keys = _keys; + uint64_t* tempKeys = _tempKeys; + Ty* values = _values; + Ty* tempValues = _tempValues; uint32_t histogram[BX_RADIXSORT_HISTOGRAM_SIZE]; uint16_t shift = 0; uint32_t pass = 0; for (; pass < 6; ++pass) { - memset(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); + memSet(histogram, 0, sizeof(uint32_t)*BX_RADIXSORT_HISTOGRAM_SIZE); bool sorted = true; { @@ -273,7 +273,7 @@ done: if (0 != (pass&1) ) { // Odd number of passes needs to do copy to the destination. - memcpy(_keys, _tempKeys, _size*sizeof(uint64_t) ); + memCopy(_keys, _tempKeys, _size*sizeof(uint64_t) ); for (uint32_t ii = 0; ii < _size; ++ii) { _values[ii] = _tempValues[ii]; diff --git a/3rdparty/bx/include/bx/inline/spscqueue.inl b/3rdparty/bx/include/bx/inline/spscqueue.inl new file mode 100644 index 00000000000..7d80f078f2b --- /dev/null +++ b/3rdparty/bx/include/bx/inline/spscqueue.inl @@ -0,0 +1,158 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_SPSCQUEUE_H_HEADER_GUARD +# error "Must be included from bx/spscqueue.h!" +#endif // BX_SPSCQUEUE_H_HEADER_GUARD + +namespace bx +{ + // http://drdobbs.com/article/print?articleId=210604448&siteSectionName= + inline SpScUnboundedQueue::SpScUnboundedQueue() + : m_first(new Node(NULL) ) + , m_divider(m_first) + , m_last(m_first) + { + } + + inline SpScUnboundedQueue::~SpScUnboundedQueue() + { + while (NULL != m_first) + { + Node* node = m_first; + m_first = node->m_next; + delete node; + } + } + + inline void SpScUnboundedQueue::push(void* _ptr) + { + m_last->m_next = new Node( (void*)_ptr); + atomicExchangePtr( (void**)&m_last, m_last->m_next); + while (m_first != m_divider) + { + Node* node = m_first; + m_first = m_first->m_next; + delete node; + } + } + + inline void* SpScUnboundedQueue::peek() + { + if (m_divider != m_last) + { + return m_divider->m_next->m_ptr; + } + + return NULL; + } + + inline void* SpScUnboundedQueue::pop() + { + if (m_divider != m_last) + { + void* ptr = m_divider->m_next->m_ptr; + atomicExchangePtr( (void**)&m_divider, m_divider->m_next); + return ptr; + } + + return NULL; + } + + inline SpScUnboundedQueue::Node::Node(void* _ptr) + : m_ptr(_ptr) + , m_next(NULL) + { + } + + template<typename Ty> + inline SpScUnboundedQueueT<Ty>::SpScUnboundedQueueT() + { + } + + template<typename Ty> + inline SpScUnboundedQueueT<Ty>::~SpScUnboundedQueueT() + { + } + + template<typename Ty> + inline void SpScUnboundedQueueT<Ty>::push(Ty* _ptr) + { + m_queue.push(_ptr); + } + + template<typename Ty> + inline Ty* SpScUnboundedQueueT<Ty>::peek() + { + return (Ty*)m_queue.peek(); + } + + template<typename Ty> + inline Ty* SpScUnboundedQueueT<Ty>::pop() + { + return (Ty*)m_queue.pop(); + } + +#if BX_CONFIG_SUPPORTS_THREADING + inline SpScBlockingUnboundedQueue::SpScBlockingUnboundedQueue() + { + } + + inline SpScBlockingUnboundedQueue::~SpScBlockingUnboundedQueue() + { + } + + inline void SpScBlockingUnboundedQueue::push(void* _ptr) + { + m_queue.push( (void*)_ptr); + m_count.post(); + } + + inline void* SpScBlockingUnboundedQueue::peek() + { + return m_queue.peek(); + } + + inline void* SpScBlockingUnboundedQueue::pop(int32_t _msecs) + { + if (m_count.wait(_msecs) ) + { + return m_queue.pop(); + } + + return NULL; + } + + template<typename Ty> + inline SpScBlockingUnboundedQueueT<Ty>::SpScBlockingUnboundedQueueT() + { + } + + template<typename Ty> + inline SpScBlockingUnboundedQueueT<Ty>::~SpScBlockingUnboundedQueueT() + { + } + + template<typename Ty> + inline void SpScBlockingUnboundedQueueT<Ty>::push(Ty* _ptr) + { + m_queue.push(_ptr); + } + + template<typename Ty> + inline Ty* SpScBlockingUnboundedQueueT<Ty>::peek() + { + return (Ty*)m_queue.peek(); + } + + template<typename Ty> + inline Ty* SpScBlockingUnboundedQueueT<Ty>::pop(int32_t _msecs) + { + return (Ty*)m_queue.pop(_msecs); + } + +#endif // BX_CONFIG_SUPPORTS_THREADING + +} // namespace bx diff --git a/3rdparty/bx/include/bx/string.inl b/3rdparty/bx/include/bx/inline/string.inl index 42f2a6a05b9..7b6f6500b7c 100644 --- a/3rdparty/bx/include/bx/string.inl +++ b/3rdparty/bx/include/bx/inline/string.inl @@ -42,9 +42,9 @@ namespace bx inline Ty replaceAll(const Ty& _str, const char* _from, const char* _to) { Ty str = _str; - size_t startPos = 0; - const size_t fromLen = strlen(_from); - const size_t toLen = strlen(_to); + typename Ty::size_type startPos = 0; + const typename Ty::size_type fromLen = strnlen(_from); + const typename Ty::size_type toLen = strnlen(_to); while ( (startPos = str.find(_from, startPos) ) != Ty::npos) { str.replace(startPos, fromLen, _to); @@ -70,18 +70,18 @@ namespace bx return *this; } - inline StringView::StringView(const char* _ptr, uint32_t _len) + inline StringView::StringView(const char* _ptr, int32_t _len) { set(_ptr, _len); } - inline void StringView::set(const char* _ptr, uint32_t _len) + inline void StringView::set(const char* _ptr, int32_t _len) { clear(); if (NULL != _ptr) { - uint32_t len = uint32_t(strnlen(_ptr, _len) ); + int32_t len = strnlen(_ptr, _len); if (0 != len) { m_len = len; @@ -111,21 +111,11 @@ namespace bx return 0 == m_len; } - inline uint32_t StringView::getLength() const + inline int32_t StringView::getLength() const { return m_len; } - inline uint32_t hashMurmur2A(const StringView& _data) - { - return hashMurmur2A(_data.getPtr(), _data.getLength() ); - } - - inline uint32_t hashMurmur2A(const char* _data) - { - return hashMurmur2A(StringView(_data) ); - } - template<bx::AllocatorI** AllocatorT> inline StringT<AllocatorT>::StringT() : StringView() @@ -147,7 +137,7 @@ namespace bx } template<bx::AllocatorI** AllocatorT> - inline StringT<AllocatorT>::StringT(const char* _ptr, uint32_t _len) + inline StringT<AllocatorT>::StringT(const char* _ptr, int32_t _len) { set(_ptr, _len); } @@ -165,19 +155,19 @@ namespace bx } template<bx::AllocatorI** AllocatorT> - inline void StringT<AllocatorT>::set(const char* _ptr, uint32_t _len) + inline void StringT<AllocatorT>::set(const char* _ptr, int32_t _len) { clear(); append(_ptr, _len); } template<bx::AllocatorI** AllocatorT> - inline void StringT<AllocatorT>::append(const char* _ptr, uint32_t _len) + inline void StringT<AllocatorT>::append(const char* _ptr, int32_t _len) { if (0 != _len) { - uint32_t old = m_len; - uint32_t len = m_len + uint32_t(strnlen(_ptr, _len) ); + int32_t old = m_len; + int32_t len = m_len + strnlen(_ptr, _len); char* ptr = (char*)BX_REALLOC(*AllocatorT, 0 != m_len ? const_cast<char*>(m_ptr) : NULL, len+1); m_len = len; strlncpy(ptr + old, len-old+1, _ptr, _len); diff --git a/3rdparty/bx/include/bx/uint32_t.inl b/3rdparty/bx/include/bx/inline/uint32_t.inl index 8a66a07ca2d..8a66a07ca2d 100644 --- a/3rdparty/bx/include/bx/uint32_t.inl +++ b/3rdparty/bx/include/bx/inline/uint32_t.inl diff --git a/3rdparty/bx/include/bx/macros.h b/3rdparty/bx/include/bx/macros.h index 8dc35fa5865..1358507188d 100644 --- a/3rdparty/bx/include/bx/macros.h +++ b/3rdparty/bx/include/bx/macros.h @@ -101,8 +101,7 @@ # error "Unknown BX_COMPILER_?" #endif -// #define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__) -#define BX_STATIC_ASSERT(_condition, ...) typedef char BX_CONCATENATE(BX_STATIC_ASSERT_, __LINE__)[1][(_condition)] BX_ATTRIBUTE(unused) +#define BX_STATIC_ASSERT(_condition, ...) static_assert(_condition, "" __VA_ARGS__) /// #define BX_ALIGN_DECL_16(_decl) BX_ALIGN_DECL(16, _decl) @@ -225,4 +224,7 @@ # define BX_WARN(_condition, ...) BX_NOOP() #endif // BX_CHECK +// static_assert sometimes causes unused-local-typedef... +BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunused-local-typedef") + #endif // BX_MACROS_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/mpscqueue.h b/3rdparty/bx/include/bx/mpscqueue.h index de4a6646db3..0ac8f82915a 100644 --- a/3rdparty/bx/include/bx/mpscqueue.h +++ b/3rdparty/bx/include/bx/mpscqueue.h @@ -6,48 +6,42 @@ #ifndef BX_MPSCQUEUE_H_HEADER_GUARD #define BX_MPSCQUEUE_H_HEADER_GUARD +#include "mutex.h" #include "spscqueue.h" namespace bx { + /// template <typename Ty> - class MpScUnboundedQueue + class MpScUnboundedQueueT { - BX_CLASS(MpScUnboundedQueue + BX_CLASS(MpScUnboundedQueueT , NO_COPY , NO_ASSIGNMENT ); public: - MpScUnboundedQueue() - { - } - - ~MpScUnboundedQueue() - { - } - - void push(Ty* _ptr) // producer only - { - LwMutexScope lock(m_write); - m_queue.push(_ptr); - } - - Ty* peek() // consumer only - { - return m_queue.peek(); - } - - Ty* pop() // consumer only - { - return m_queue.pop(); - } + /// + MpScUnboundedQueueT(); + + /// + ~MpScUnboundedQueueT(); + + /// + void push(Ty* _ptr); // producer only + + /// + Ty* peek(); // consumer only + + /// + Ty* pop(); // consumer only private: - LwMutex m_write; - SpScUnboundedQueue<Ty> m_queue; + Mutex m_write; + SpScUnboundedQueueT<Ty> m_queue; }; + /// template <typename Ty> class MpScUnboundedBlockingQueue { @@ -57,31 +51,25 @@ namespace bx ); public: - MpScUnboundedBlockingQueue() - { - } - - ~MpScUnboundedBlockingQueue() - { - } - - void push(Ty* _ptr) // producer only - { - m_queue.push(_ptr); - m_sem.post(); - } - - Ty* pop() // consumer only - { - m_sem.wait(); - return m_queue.pop(); - } + /// + MpScUnboundedBlockingQueue(); + + /// + ~MpScUnboundedBlockingQueue(); + + /// + void push(Ty* _ptr); // producer only + + /// + Ty* pop(); // consumer only private: - MpScUnboundedQueue<Ty> m_queue; + MpScUnboundedQueueT<Ty> m_queue; Semaphore m_sem; }; } // namespace bx +#include "inline/mpscqueue.inl" + #endif // BX_MPSCQUEUE_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/mutex.h b/3rdparty/bx/include/bx/mutex.h index 777e577b950..ac8ea7f03de 100644 --- a/3rdparty/bx/include/bx/mutex.h +++ b/3rdparty/bx/include/bx/mutex.h @@ -7,20 +7,6 @@ #define BX_MUTEX_H_HEADER_GUARD #include "bx.h" -#include "cpu.h" -#include "os.h" -#include "sem.h" - -#if BX_CONFIG_SUPPORTS_THREADING - -#if 0 \ - || BX_PLATFORM_ANDROID \ - || BX_PLATFORM_LINUX \ - || BX_PLATFORM_NACL \ - || BX_PLATFORM_IOS \ - || BX_PLATFORM_OSX -# include <pthread.h> -#endif // namespace bx { @@ -46,11 +32,7 @@ namespace bx void unlock(); private: -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - CRITICAL_SECTION m_handle; -#else - pthread_mutex_t m_handle; -#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT + BX_ALIGN_DECL(16, uint8_t) m_internal[64]; }; /// @@ -73,32 +55,8 @@ namespace bx Mutex& m_mutex; }; - typedef Mutex LwMutex; - - /// - class LwMutexScope - { - BX_CLASS(LwMutexScope - , NO_DEFAULT_CTOR - , NO_COPY - , NO_ASSIGNMENT - ); - - public: - /// - LwMutexScope(LwMutex& _mutex); - - /// - ~LwMutexScope(); - - private: - LwMutex& m_mutex; - }; - } // namespace bx -#include "mutex.inl" - -#endif // BX_CONFIG_SUPPORTS_THREADING +#include "inline/mutex.inl" #endif // BX_MUTEX_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/os.h b/3rdparty/bx/include/bx/os.h index d2639756198..56781b25b0e 100644 --- a/3rdparty/bx/include/bx/os.h +++ b/3rdparty/bx/include/bx/os.h @@ -6,9 +6,7 @@ #ifndef BX_OS_H_HEADER_GUARD #define BX_OS_H_HEADER_GUARD -#include "bx.h" #include "debug.h" -#include <sys/stat.h> #if BX_PLATFORM_OSX # define BX_DL_EXT "dylib" diff --git a/3rdparty/bx/include/bx/pixelformat.h b/3rdparty/bx/include/bx/pixelformat.h index 5b2bf565803..78354e48425 100644 --- a/3rdparty/bx/include/bx/pixelformat.h +++ b/3rdparty/bx/include/bx/pixelformat.h @@ -6,8 +6,8 @@ #ifndef BX_PIXEL_FORMAT_H_HEADER_GUARD #define BX_PIXEL_FORMAT_H_HEADER_GUARD -#include <bx/fpumath.h> -#include <bx/uint32_t.h> +#include "fpumath.h" +#include "uint32_t.h" namespace bx { @@ -238,6 +238,6 @@ namespace bx } // namespace bx -#include "pixelformat.inl" +#include "inline/pixelformat.inl" #endif // BX_PIXEL_FORMAT_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/platform.h b/3rdparty/bx/include/bx/platform.h index 99d29a037d9..8d8c340171a 100644 --- a/3rdparty/bx/include/bx/platform.h +++ b/3rdparty/bx/include/bx/platform.h @@ -29,12 +29,20 @@ #define BX_CPU_X86 0 // C Runtime -#define BX_CRT_MSVC 0 +#define BX_CRT_BIONIC 0 #define BX_CRT_GLIBC 0 #define BX_CRT_LIBCXX 0 -#define BX_CRT_NEWLIB 0 #define BX_CRT_MINGW 0 -#define BX_CRT_MUSL 0 +#define BX_CRT_MSVC 0 +#define BX_CRT_NEWLIB 0 + +#ifndef BX_CRT_MUSL +# define BX_CRT_MUSL 0 +#endif // BX_CRT_MUSL + +#ifndef BX_CRT_NONE +# define BX_CRT_NONE 0 +#endif // BX_CRT_NONE // Platform #define BX_PLATFORM_ANDROID 0 @@ -63,34 +71,12 @@ # undef BX_COMPILER_CLANG_ANALYZER # define BX_COMPILER_CLANG_ANALYZER 1 # endif // defined(__clang_analyzer__) -# if defined(_MSC_VER) -# undef BX_CRT_MSVC -# define BX_CRT_MSVC 1 -# elif defined(__GLIBC__) -# undef BX_CRT_GLIBC -# define BX_CRT_GLIBC (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100) -# elif defined(__MINGW32__) || defined(__MINGW64__) -# undef BX_CRT_MINGW -# define BX_CRT_MINGW 1 -# elif defined(__apple_build_version__) || defined(__ANDROID__) -# undef BX_CRT_LIBCXX -# define BX_CRT_LIBCXX 1 -# endif // #elif defined(_MSC_VER) # undef BX_COMPILER_MSVC # define BX_COMPILER_MSVC _MSC_VER -# undef BX_CRT_MSVC -# define BX_CRT_MSVC 1 #elif defined(__GNUC__) # undef BX_COMPILER_GCC # define BX_COMPILER_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) -# if defined(__GLIBC__) -# undef BX_CRT_GLIBC -# define BX_CRT_GLIBC (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100) -# elif defined(__MINGW32__) || defined(__MINGW64__) -# undef BX_CRT_MINGW -# define BX_CRT_MINGW 1 -# endif // #else # error "BX_COMPILER_* is not defined!" #endif // @@ -192,7 +178,7 @@ # endif #elif defined(__ANDROID__) // Android compiler defines __linux__ -# include <android/api-level.h> +# include <sys/cdefs.h> // Defines __BIONIC__ and includes android/api-level.h # undef BX_PLATFORM_ANDROID # define BX_PLATFORM_ANDROID __ANDROID_API__ #elif defined(__native_client__) @@ -217,11 +203,7 @@ # define BX_PLATFORM_IOS 1 #elif defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) # undef BX_PLATFORM_OSX -# if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) -# define BX_PLATFORM_OSX __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ -# else -# define BX_PLATFORM_OSX 1 -# endif // defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) +# define BX_PLATFORM_OSX __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ #elif defined(__EMSCRIPTEN__) # undef BX_PLATFORM_EMSCRIPTEN # define BX_PLATFORM_EMSCRIPTEN 1 @@ -231,7 +213,11 @@ #elif defined(__QNX__) # undef BX_PLATFORM_QNX # define BX_PLATFORM_QNX 1 -#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) +#elif defined(__FreeBSD__) \ + || defined(__FreeBSD_kernel__) \ + || defined(__NetBSD__) \ + || defined(__OpenBSD__) \ + || defined(__DragonFly__) # undef BX_PLATFORM_BSD # define BX_PLATFORM_BSD 1 #elif defined(__GNU__) @@ -239,6 +225,37 @@ # define BX_PLATFORM_HURD 1 #endif // +#if !BX_CRT_NONE +// https://sourceforge.net/p/predef/wiki/Libraries/ +# if defined(__BIONIC__) +# undef BX_CRT_BIONIC +# define BX_CRT_BIONIC 1 +# elif defined(_MSC_VER) +# undef BX_CRT_MSVC +# define BX_CRT_MSVC 1 +# elif defined(__GLIBC__) +# undef BX_CRT_GLIBC +# define BX_CRT_GLIBC (__GLIBC__ * 10000 + __GLIBC_MINOR__ * 100) +# elif defined(__MINGW32__) || defined(__MINGW64__) +# undef BX_CRT_MINGW +# define BX_CRT_MINGW 1 +# elif defined(__apple_build_version__) || defined(__ORBIS__) || defined(__EMSCRIPTEN__) +# undef BX_CRT_LIBCXX +# define BX_CRT_LIBCXX 1 +# endif // + +# if !BX_CRT_BIONIC \ + && !BX_CRT_GLIBC \ + && !BX_CRT_LIBCXX \ + && !BX_CRT_MINGW \ + && !BX_CRT_MSVC \ + && !BX_CRT_MUSL \ + && !BX_CRT_NEWLIB +# undef BX_CRT_NONE +# define BX_CRT_NONE 1 +# endif // BX_CRT_* +#endif // !BX_CRT_NONE + #define BX_PLATFORM_POSIX (0 \ || BX_PLATFORM_ANDROID \ || BX_PLATFORM_EMSCRIPTEN \ @@ -254,19 +271,25 @@ || BX_PLATFORM_RPI \ ) -#define BX_CRT_NONE !(0 \ - || BX_CRT_MSVC \ - || BX_CRT_GLIBC \ - || BX_CRT_LIBCXX \ - || BX_CRT_NEWLIB \ - || BX_CRT_MINGW \ - || BX_CRT_MUSL \ +#define BX_PLATFORM_NONE !(0 \ + || BX_PLATFORM_ANDROID \ + || BX_PLATFORM_EMSCRIPTEN \ + || BX_PLATFORM_BSD \ + || BX_PLATFORM_HURD \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_QNX \ + || BX_PLATFORM_RPI \ + || BX_PLATFORM_STEAMLINK \ + || BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE \ ) -#ifndef BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS -# define BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS 0 -#endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS - #if BX_COMPILER_GCC # define BX_COMPILER_NAME "GCC " \ BX_STRINGIZE(__GNUC__) "." \ @@ -332,8 +355,10 @@ # define BX_PLATFORM_NAME "Xbox 360" #elif BX_PLATFORM_XBOXONE # define BX_PLATFORM_NAME "Xbox One" -#else +#elif BX_PLATFORM_NONE # define BX_PLATFORM_NAME "None" +#else +# error "Unknown BX_PLATFORM!" #endif // BX_PLATFORM_ #if BX_CPU_ARM @@ -350,18 +375,24 @@ # define BX_CPU_NAME "x86" #endif // BX_CPU_ -#if BX_CRT_MSVC -# define BX_CRT_NAME "MSVC C Runtime" +#if BX_CRT_BIONIC +# define BX_CRT_NAME "Bionic libc" #elif BX_CRT_GLIBC # define BX_CRT_NAME "GNU C Library" -#elif BX_CRT_NEWLIB -# define BX_CRT_NAME "Newlib" +#elif BX_CRT_MSVC +# define BX_CRT_NAME "MSVC C Runtime" #elif BX_CRT_MINGW # define BX_CRT_NAME "MinGW C Runtime" +#elif BX_CRT_LIBCXX +# define BX_CRT_NAME "Clang C Library" +#elif BX_CRT_NEWLIB +# define BX_CRT_NAME "Newlib" #elif BX_CRT_MUSL # define BX_CRT_NAME "musl libc" -#else +#elif BX_CRT_NONE # define BX_CRT_NAME "None" +#else +# error "Unknown BX_CRT!" #endif // BX_CRT_ #if BX_ARCH_32BIT @@ -370,25 +401,4 @@ # define BX_ARCH_NAME "64-bit" #endif // BX_ARCH_ -#if BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS && BX_COMPILER_MSVC -# pragma warning(error:4062) // ENABLE warning C4062: enumerator'...' in switch of enum '...' is not handled -# pragma warning(error:4100) // ENABLE warning C4100: '' : unreferenced formal parameter -# pragma warning(error:4189) // ENABLE warning C4189: '' : local variable is initialized but not referenced -# pragma warning(error:4121) // ENABLE warning C4121: 'symbol' : alignment of a member was sensitive to packing -//# pragma warning(error:4127) // ENABLE warning C4127: conditional expression is constant -# pragma warning(error:4130) // ENABLE warning C4130: 'operator' : logical operation on address of string constant -# pragma warning(error:4239) // ENABLE warning C4239: nonstandard extension used : 'argument' : conversion from '*' to '* &' A non-const reference may only be bound to an lvalue -//# pragma warning(error:4244) // ENABLE warning C4244: 'argument' : conversion from 'type1' to 'type2', possible loss of data -# pragma warning(error:4245) // ENABLE warning C4245: 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch -# pragma warning(error:4263) // ENABLE warning C4263: 'function' : member function does not override any base class virtual member function -# pragma warning(error:4265) // ENABLE warning C4265: class has virtual functions, but destructor is not virtual -# pragma warning(error:4431) // ENABLE warning C4431: missing type specifier - int assumed. Note: C no longer supports default-int -# pragma warning(error:4505) // ENABLE warning C4505: '' : unreferenced local function has been removed -# pragma warning(error:4545) // ENABLE warning C4545: expression before comma evaluates to a function which is missing an argument list -# pragma warning(error:4549) // ENABLE warning C4549: 'operator' : operator before comma has no effect; did you intend 'operator'? -# pragma warning(error:4701) // ENABLE warning C4701: potentially uninitialized local variable 'name' used -# pragma warning(error:4706) // ENABLE warning C4706: assignment within conditional expression -# pragma warning(error:4800) // ENABLE warning C4800: '': forcing value to bool 'true' or 'false' (performance warning) -#endif // BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS && BX_COMPILER_MSVC - #endif // BX_PLATFORM_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/radixsort.h b/3rdparty/bx/include/bx/radixsort.h deleted file mode 100644 index 87bd3e310b0..00000000000 --- a/3rdparty/bx/include/bx/radixsort.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2010-2017 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause - */ - -#ifndef BX_RADIXSORT_H_HEADER_GUARD -#define BX_RADIXSORT_H_HEADER_GUARD - -#include "bx.h" - -namespace bx -{ - /// - void radixSort( - uint32_t* __restrict _keys - , uint32_t* __restrict _tempKeys - , uint32_t _size - ); - - /// - template <typename Ty> - void radixSort( - uint32_t* __restrict _keys - , uint32_t* __restrict _tempKeys - , Ty* __restrict _values - , Ty* __restrict _tempValues - , uint32_t _size - ); - - /// - void radixSort( - uint64_t* __restrict _keys - , uint64_t* __restrict _tempKeys - , uint32_t _size - ); - - /// - template <typename Ty> - void radixSort( - uint64_t* __restrict _keys - , uint64_t* __restrict _tempKeys - , Ty* __restrict _values - , Ty* __restrict _tempValues - , uint32_t _size - ); - -} // namespace bx - -#include "radixsort.inl" - -#endif // BX_RADIXSORT_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/readerwriter.h b/3rdparty/bx/include/bx/readerwriter.h index 19411a6adb7..7fda6f08111 100644 --- a/3rdparty/bx/include/bx/readerwriter.h +++ b/3rdparty/bx/include/bx/readerwriter.h @@ -6,12 +6,6 @@ #ifndef BX_READERWRITER_H_HEADER_GUARD #define BX_READERWRITER_H_HEADER_GUARD -#include <alloca.h> -#include <stdarg.h> // va_list -#include <stdio.h> -#include <string.h> - -#include "bx.h" #include "allocator.h" #include "error.h" #include "uint32_t.h" @@ -303,6 +297,6 @@ namespace bx } // namespace bx -#include "readerwriter.inl" +#include "inline/readerwriter.inl" #endif // BX_READERWRITER_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/ringbuffer.h b/3rdparty/bx/include/bx/ringbuffer.h index 28e7731e3d2..fd742503072 100644 --- a/3rdparty/bx/include/bx/ringbuffer.h +++ b/3rdparty/bx/include/bx/ringbuffer.h @@ -12,6 +12,7 @@ namespace bx { + /// class RingBufferControl { BX_CLASS(RingBufferControl @@ -20,75 +21,29 @@ namespace bx ); public: - RingBufferControl(uint32_t _size) - : m_size(_size) - , m_current(0) - , m_write(0) - , m_read(0) - { - } - - ~RingBufferControl() - { - } - - uint32_t available() const - { - return distance(m_read, m_current); - } - - uint32_t consume(uint32_t _size) // consumer only - { - const uint32_t maxSize = distance(m_read, m_current); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_read, size); - const uint32_t read = uint32_mod(advance, m_size); - m_read = read; - return size; - } - - uint32_t reserve(uint32_t _size) // producer only - { - const uint32_t dist = distance(m_write, m_read)-1; - const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_write, size); - const uint32_t write = uint32_mod(advance, m_size); - m_write = write; - return size; - } - - uint32_t commit(uint32_t _size) // producer only - { - const uint32_t maxSize = distance(m_current, m_write); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_current, size); - const uint32_t current = uint32_mod(advance, m_size); - m_current = current; - return size; - } - - uint32_t distance(uint32_t _from, uint32_t _to) const // both - { - const uint32_t diff = uint32_sub(_to, _from); - const uint32_t le = uint32_add(m_size, diff); - const uint32_t result = uint32_sels(diff, le, diff); - - return result; - } - - void reset() - { - m_current = 0; - m_write = 0; - m_read = 0; - } + /// + RingBufferControl(uint32_t _size); + + /// + ~RingBufferControl(); + + /// + uint32_t available() const; + + /// + uint32_t consume(uint32_t _size); // consumer only + + /// + uint32_t reserve(uint32_t _size, bool _mustSucceed = false); // producer only + + /// + uint32_t commit(uint32_t _size); // producer only + + /// + uint32_t distance(uint32_t _from, uint32_t _to) const; // both + + /// + void reset(); const uint32_t m_size; uint32_t m_current; @@ -96,6 +51,7 @@ namespace bx uint32_t m_read; }; + /// class SpScRingBufferControl { BX_CLASS(SpScRingBufferControl @@ -104,79 +60,29 @@ namespace bx ); public: - SpScRingBufferControl(uint32_t _size) - : m_size(_size) - , m_current(0) - , m_write(0) - , m_read(0) - { - } - - ~SpScRingBufferControl() - { - } - - uint32_t available() const - { - return distance(m_read, m_current); - } - - uint32_t consume(uint32_t _size) // consumer only - { - const uint32_t maxSize = distance(m_read, m_current); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_read, size); - const uint32_t read = uint32_mod(advance, m_size); - m_read = read; - return size; - } - - uint32_t reserve(uint32_t _size) // producer only - { - const uint32_t dist = distance(m_write, m_read)-1; - const uint32_t maxSize = uint32_sels(dist, m_size-1, dist); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_write, size); - const uint32_t write = uint32_mod(advance, m_size); - m_write = write; - return size; - } - - uint32_t commit(uint32_t _size) // producer only - { - const uint32_t maxSize = distance(m_current, m_write); - const uint32_t sizeNoSign = uint32_and(_size, 0x7fffffff); - const uint32_t test = uint32_sub(sizeNoSign, maxSize); - const uint32_t size = uint32_sels(test, _size, maxSize); - const uint32_t advance = uint32_add(m_current, size); - const uint32_t current = uint32_mod(advance, m_size); - - // must commit all memory writes before moving m_current pointer - // once m_current pointer moves data is used by consumer thread - memoryBarrier(); - m_current = current; - return size; - } - - uint32_t distance(uint32_t _from, uint32_t _to) const // both - { - const uint32_t diff = uint32_sub(_to, _from); - const uint32_t le = uint32_add(m_size, diff); - const uint32_t result = uint32_sels(diff, le, diff); - - return result; - } - - void reset() - { - m_current = 0; - m_write = 0; - m_read = 0; - } + /// + SpScRingBufferControl(uint32_t _size); + + /// + ~SpScRingBufferControl(); + + /// + uint32_t available() const; + + /// + uint32_t consume(uint32_t _size); // consumer only + + /// + uint32_t reserve(uint32_t _size); // producer only + + /// + uint32_t commit(uint32_t _size); // producer only + + /// + uint32_t distance(uint32_t _from, uint32_t _to) const; // both + + /// + void reset(); const uint32_t m_size; uint32_t m_current; @@ -184,7 +90,8 @@ namespace bx uint32_t m_read; }; - template <typename Control> + /// + template <typename ControlT> class ReadRingBufferT { BX_CLASS(ReadRingBufferT @@ -194,65 +101,40 @@ namespace bx ); public: - ReadRingBufferT(Control& _control, const char* _buffer, uint32_t _size) - : m_control(_control) - , m_read(_control.m_read) - , m_end(m_read+_size) - , m_size(_size) - , m_buffer(_buffer) - { - BX_CHECK(_control.available() >= _size, "%d >= %d", _control.available(), _size); - } - - ~ReadRingBufferT() - { - } - - void end() - { - m_control.consume(m_size); - } - - void read(char* _data, uint32_t _len) - { - const uint32_t eof = (m_read + _len) % m_control.m_size; - uint32_t wrap = 0; - const char* from = &m_buffer[m_read]; - - if (eof < m_read) - { - wrap = m_control.m_size - m_read; - memcpy(_data, from, wrap); - _data += wrap; - from = (const char*)&m_buffer[0]; - } - - memcpy(_data, from, _len-wrap); - - m_read = eof; - } - - void skip(uint32_t _len) - { - m_read += _len; - m_read %= m_control.m_size; - } + /// + ReadRingBufferT(ControlT& _control, const char* _buffer, uint32_t _size); + + /// + ~ReadRingBufferT(); + + /// + void end(); + + /// + void read(char* _data, uint32_t _len); + + /// + void skip(uint32_t _len); private: template <typename Ty> friend class WriteRingBufferT; - Control& m_control; + ControlT& m_control; uint32_t m_read; uint32_t m_end; const uint32_t m_size; const char* m_buffer; }; + /// typedef ReadRingBufferT<RingBufferControl> ReadRingBuffer; + + /// typedef ReadRingBufferT<SpScRingBufferControl> SpScReadRingBuffer; - template <typename Control> + /// + template <typename ControlT> class WriteRingBufferT { BX_CLASS(WriteRingBufferT @@ -262,81 +144,40 @@ namespace bx ); public: - WriteRingBufferT(Control& _control, char* _buffer, uint32_t _size) - : m_control(_control) - , m_size(_size) - , m_buffer(_buffer) - { - uint32_t size = m_control.reserve(_size); - BX_UNUSED(size); - BX_CHECK(size == _size, "%d == %d", size, _size); - m_write = m_control.m_current; - m_end = m_write+_size; - } - - ~WriteRingBufferT() - { - } - - void end() - { - m_control.commit(m_size); - } - - void write(const char* _data, uint32_t _len) - { - const uint32_t eof = (m_write + _len) % m_control.m_size; - uint32_t wrap = 0; - char* to = &m_buffer[m_write]; - - if (eof < m_write) - { - wrap = m_control.m_size - m_write; - memcpy(to, _data, wrap); - _data += wrap; - to = (char*)&m_buffer[0]; - } - - memcpy(to, _data, _len-wrap); - - m_write = eof; - } - - void write(ReadRingBufferT<Control>& _read, uint32_t _len) - { - const uint32_t eof = (_read.m_read + _len) % _read.m_control.m_size; - uint32_t wrap = 0; - const char* from = &_read.m_buffer[_read.m_read]; - - if (eof < _read.m_read) - { - wrap = _read.m_control.m_size - _read.m_read; - write(from, wrap); - from = (const char*)&_read.m_buffer[0]; - } - - write(from, _len-wrap); - - _read.m_read = eof; - } - - void skip(uint32_t _len) - { - m_write += _len; - m_write %= m_control.m_size; - } + /// + WriteRingBufferT(ControlT& _control, char* _buffer, uint32_t _size); + + /// + ~WriteRingBufferT(); + + /// + void end(); + + /// + void write(const char* _data, uint32_t _len); + + /// + void write(ReadRingBufferT<ControlT>& _read, uint32_t _len); + + /// + void skip(uint32_t _len); private: - Control& m_control; + ControlT& m_control; uint32_t m_write; uint32_t m_end; const uint32_t m_size; char* m_buffer; }; + /// typedef WriteRingBufferT<RingBufferControl> WriteRingBuffer; + + /// typedef WriteRingBufferT<SpScRingBufferControl> SpScWriteRingBuffer; } // namespace bx +#include "inline/ringbuffer.inl" + #endif // BX_RINGBUFFER_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/rng.h b/3rdparty/bx/include/bx/rng.h index 91eade62644..56d7674957c 100644 --- a/3rdparty/bx/include/bx/rng.h +++ b/3rdparty/bx/include/bx/rng.h @@ -96,6 +96,6 @@ namespace bx } // namespace bx -#include "rng.inl" +#include "inline/rng.inl" #endif // BX_RNG_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/sem.h b/3rdparty/bx/include/bx/sem.h deleted file mode 100644 index acc2359c363..00000000000 --- a/3rdparty/bx/include/bx/sem.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2010-2017 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause - */ - -#ifndef BX_SEM_H_HEADER_GUARD -#define BX_SEM_H_HEADER_GUARD - -#include "bx.h" - -#if BX_CONFIG_SUPPORTS_THREADING - -#if BX_PLATFORM_POSIX -# include <errno.h> -# include <semaphore.h> -# include <time.h> -# include <pthread.h> -#elif BX_PLATFORM_XBOX360 || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE -# include <windows.h> -# include <limits.h> -# if BX_PLATFORM_XBOXONE -# include <synchapi.h> -# endif // BX_PLATFORM_XBOXONE -#endif // BX_PLATFORM_ - -#include "mutex.h" - -namespace bx -{ - /// - class Semaphore - { - BX_CLASS(Semaphore - , NO_COPY - , NO_ASSIGNMENT - ); - - public: - /// - Semaphore(); - - /// - ~Semaphore(); - - /// - void post(uint32_t _count = 1); - - /// - bool wait(int32_t _msecs = -1); - - private: -#if BX_PLATFORM_POSIX -# if BX_CONFIG_SEMAPHORE_PTHREAD - pthread_mutex_t m_mutex; - pthread_cond_t m_cond; - int32_t m_count; -# else - sem_t m_handle; -# endif // BX_CONFIG_SEMAPHORE_PTHREAD -#elif BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT - HANDLE m_handle; -#endif // BX_PLATFORM_ - }; - -} // namespace bx - -#endif // BX_CONFIG_SUPPORTS_THREADING - -#endif // BX_SEM_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/semaphore.h b/3rdparty/bx/include/bx/semaphore.h new file mode 100644 index 00000000000..867fa9e7cde --- /dev/null +++ b/3rdparty/bx/include/bx/semaphore.h @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_SEM_H_HEADER_GUARD +#define BX_SEM_H_HEADER_GUARD + +#include "bx.h" + +namespace bx +{ + /// + class Semaphore + { + BX_CLASS(Semaphore + , NO_COPY + , NO_ASSIGNMENT + ); + + public: + /// + Semaphore(); + + /// + ~Semaphore(); + + /// + void post(uint32_t _count = 1); + + /// + bool wait(int32_t _msecs = -1); + + private: + BX_ALIGN_DECL(16, uint8_t) m_internal[128]; + }; + +} // namespace bx + +#endif // BX_SEM_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/simd_t.h b/3rdparty/bx/include/bx/simd_t.h index bc1fe6622f8..d3befc44ba0 100644 --- a/3rdparty/bx/include/bx/simd_t.h +++ b/3rdparty/bx/include/bx/simd_t.h @@ -7,6 +7,7 @@ #define BX_SIMD_T_H_HEADER_GUARD #include "bx.h" +#include "fpumath.h" #define BX_SIMD_FORCE_INLINE BX_FORCE_INLINE #define BX_SIMD_INLINE inline @@ -52,7 +53,7 @@ namespace bx #define BX_SIMD128_IMPLEMENT_SWIZZLE(_x, _y, _z, _w) \ template<typename Ty> \ BX_SIMD_FORCE_INLINE Ty simd_swiz_##_x##_y##_z##_w(Ty _a); -#include "simd128_swizzle.inl" +#include "inline/simd128_swizzle.inl" #undef BX_SIMD128_IMPLEMENT_SWIZZLE #undef ELEMw @@ -361,19 +362,19 @@ BX_SIMD128_IMPLEMENT_TEST(xyzw); } // namespace bx #if BX_SIMD_AVX -# include "simd256_avx.inl" +# include "inline/simd256_avx.inl" #endif // BX_SIMD_AVX #if BX_SIMD_LANGEXT -# include "simd128_langext.inl" +# include "inline/simd128_langext.inl" #endif // BX_SIMD_LANGEXT #if BX_SIMD_NEON -# include "simd128_neon.inl" +# include "inline/simd128_neon.inl" #endif // BX_SIMD_NEON #if BX_SIMD_SSE -# include "simd128_sse.inl" +# include "inline/simd128_sse.inl" #endif // BX_SIMD_SSE namespace bx @@ -422,8 +423,8 @@ namespace bx } // namespace bx -#include "simd128_ref.inl" -#include "simd256_ref.inl" +#include "inline/simd128_ref.inl" +#include "inline/simd256_ref.inl" namespace bx { diff --git a/3rdparty/bx/include/bx/sort.h b/3rdparty/bx/include/bx/sort.h new file mode 100644 index 00000000000..2f1511bab5a --- /dev/null +++ b/3rdparty/bx/include/bx/sort.h @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#ifndef BX_SORT_H_HEADER_GUARD +#define BX_SORT_H_HEADER_GUARD + +#include "bx.h" + +namespace bx +{ + /// + typedef int32_t (*ComparisonFn)(const void* _lhs, const void* _rhs); + + /// + void quickSort( + void* _data + , uint32_t _num + , uint32_t _stride + , const ComparisonFn _fn + ); + + /// + void radixSort( + uint32_t* _keys + , uint32_t* _tempKeys + , uint32_t _size + ); + + /// + template <typename Ty> + void radixSort( + uint32_t* _keys + , uint32_t* _tempKeys + , Ty* _values + , Ty* _tempValues + , uint32_t _size + ); + + /// + void radixSort( + uint64_t* _keys + , uint64_t* _tempKeys + , uint32_t _size + ); + + /// + template <typename Ty> + void radixSort( + uint64_t* _keys + , uint64_t* _tempKeys + , Ty* _values + , Ty* _tempValues + , uint32_t _size + ); + +} // namespace bx + +#include "inline/sort.inl" + +#endif // BX_SORT_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/spscqueue.h b/3rdparty/bx/include/bx/spscqueue.h index 3f75496f357..4d37d63b63f 100644 --- a/3rdparty/bx/include/bx/spscqueue.h +++ b/3rdparty/bx/include/bx/spscqueue.h @@ -8,83 +8,39 @@ #include "bx.h" #include "cpu.h" -#include "mutex.h" -#include "uint32_t.h" - -#include <list> +#include "semaphore.h" namespace bx { - // http://drdobbs.com/article/print?articleId=210604448&siteSectionName= - template <typename Ty> - class SpScUnboundedQueueLf + /// + class SpScUnboundedQueue { - BX_CLASS(SpScUnboundedQueueLf + BX_CLASS(SpScUnboundedQueue , NO_COPY , NO_ASSIGNMENT ); public: - SpScUnboundedQueueLf() - : m_first(new Node(NULL) ) - , m_divider(m_first) - , m_last(m_first) - { - } + /// + SpScUnboundedQueue(); - ~SpScUnboundedQueueLf() - { - while (NULL != m_first) - { - Node* node = m_first; - m_first = node->m_next; - delete node; - } - } - - void push(Ty* _ptr) // producer only - { - m_last->m_next = new Node( (void*)_ptr); - atomicExchangePtr( (void**)&m_last, m_last->m_next); - while (m_first != m_divider) - { - Node* node = m_first; - m_first = m_first->m_next; - delete node; - } - } - - Ty* peek() // consumer only - { - if (m_divider != m_last) - { - Ty* ptr = (Ty*)m_divider->m_next->m_ptr; - return ptr; - } + /// + ~SpScUnboundedQueue(); - return NULL; - } + /// + void push(void* _ptr); - Ty* pop() // consumer only - { - if (m_divider != m_last) - { - Ty* ptr = (Ty*)m_divider->m_next->m_ptr; - atomicExchangePtr( (void**)&m_divider, m_divider->m_next); - return ptr; - } + /// + void* peek(); - return NULL; - } + /// + void* pop(); private: struct Node { - Node(void* _ptr) - : m_ptr(_ptr) - , m_next(NULL) - { - } + /// + Node(void* _ptr); void* m_ptr; Node* m_next; @@ -95,69 +51,38 @@ namespace bx Node* m_last; }; -#if BX_CONFIG_SUPPORTS_THREADING + /// template<typename Ty> - class SpScUnboundedQueueMutex + class SpScUnboundedQueueT { - BX_CLASS(SpScUnboundedQueueMutex + BX_CLASS(SpScUnboundedQueueT , NO_COPY , NO_ASSIGNMENT ); public: - SpScUnboundedQueueMutex() - { - } + /// + SpScUnboundedQueueT(); - ~SpScUnboundedQueueMutex() - { - BX_CHECK(m_queue.empty(), "Queue is not empty!"); - } + /// + ~SpScUnboundedQueueT(); - void push(Ty* _item) - { - bx::LwMutexScope lock(m_mutex); - m_queue.push_back(_item); - } + /// + void push(Ty* _ptr); - Ty* peek() - { - bx::LwMutexScope lock(m_mutex); - if (!m_queue.empty() ) - { - return m_queue.front(); - } - - return NULL; - } + /// + Ty* peek(); - Ty* pop() - { - bx::LwMutexScope lock(m_mutex); - if (!m_queue.empty() ) - { - Ty* item = m_queue.front(); - m_queue.pop_front(); - return item; - } - - return NULL; - } + /// + Ty* pop(); private: - bx::LwMutex m_mutex; - std::list<Ty*> m_queue; + SpScUnboundedQueue m_queue; }; -#endif // BX_CONFIG_SUPPORTS_THREADING -#if BX_CONFIG_SPSCQUEUE_USE_MUTEX && BX_CONFIG_SUPPORTS_THREADING -# define SpScUnboundedQueue SpScUnboundedQueueMutex -#else -# define SpScUnboundedQueue SpScUnboundedQueueLf -#endif // BX_CONFIG_SPSCQUEUE_USE_MUTEX #if BX_CONFIG_SUPPORTS_THREADING - template <typename Ty> + /// class SpScBlockingUnboundedQueue { BX_CLASS(SpScBlockingUnboundedQueue @@ -166,41 +91,58 @@ namespace bx ); public: - SpScBlockingUnboundedQueue() - { - } + /// + SpScBlockingUnboundedQueue(); - ~SpScBlockingUnboundedQueue() - { - } + /// + ~SpScBlockingUnboundedQueue(); - void push(Ty* _ptr) // producer only - { - m_queue.push( (void*)_ptr); - m_count.post(); - } + /// + void push(void* _ptr); // producer only - Ty* peek() // consumer only - { - return (Ty*)m_queue.peek(); - } + /// + void* peek(); // consumer only - Ty* pop(int32_t _msecs = -1) // consumer only - { - if (m_count.wait(_msecs) ) - { - return (Ty*)m_queue.pop(); - } - - return NULL; - } + /// + void* pop(int32_t _msecs = -1); // consumer only private: Semaphore m_count; - SpScUnboundedQueue<void> m_queue; + SpScUnboundedQueue m_queue; + }; + + /// + template<typename Ty> + class SpScBlockingUnboundedQueueT + { + BX_CLASS(SpScBlockingUnboundedQueueT + , NO_COPY + , NO_ASSIGNMENT + ); + + public: + /// + SpScBlockingUnboundedQueueT(); + + /// + ~SpScBlockingUnboundedQueueT(); + + /// + void push(Ty* _ptr); // producer only + + /// + Ty* peek(); // consumer only + + /// + Ty* pop(int32_t _msecs = -1); // consumer only + + private: + SpScBlockingUnboundedQueue m_queue; }; #endif // BX_CONFIG_SUPPORTS_THREADING } // namespace bx +#include "inline/spscqueue.inl" + #endif // BX_SPSCQUEUE_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/string.h b/3rdparty/bx/include/bx/string.h index eaf27bc983c..440cbe15f17 100644 --- a/3rdparty/bx/include/bx/string.h +++ b/3rdparty/bx/include/bx/string.h @@ -6,13 +6,9 @@ #ifndef BX_STRING_H_HEADER_GUARD #define BX_STRING_H_HEADER_GUARD -#include "bx.h" -#include <alloca.h> -#include <stdarg.h> // va_list -#include <wchar.h> // wchar_t +#include "allocator.h" -#include <bx/allocator.h> -#include <bx/hash.h> +#include <wchar.h> // wchar_t namespace bx { @@ -30,10 +26,10 @@ namespace bx StringView& operator=(const StringView& _rhs); /// - StringView(const char* _ptr, uint32_t _len = UINT16_MAX); + StringView(const char* _ptr, int32_t _len = INT32_MAX); /// - void set(const char* _ptr, uint32_t _len = UINT16_MAX); + void set(const char* _ptr, int32_t _len = INT32_MAX); /// void clear(); @@ -48,11 +44,11 @@ namespace bx bool isEmpty() const; /// - uint32_t getLength() const; + int32_t getLength() const; protected: const char* m_ptr; - uint32_t m_len; + int32_t m_len; }; /// ASCII string @@ -70,7 +66,7 @@ namespace bx StringT<AllocatorT>& operator=(const StringT<AllocatorT>& _rhs); /// - StringT(const char* _ptr, uint32_t _len = UINT32_MAX); + StringT(const char* _ptr, int32_t _len = INT32_MAX); /// StringT(const StringView& _rhs); @@ -79,10 +75,10 @@ namespace bx ~StringT(); /// - void set(const char* _ptr, uint32_t _len = UINT32_MAX); + void set(const char* _ptr, int32_t _len = INT32_MAX); /// - void append(const char* _ptr, uint32_t _len = UINT32_MAX); + void append(const char* _ptr, int32_t _len = INT32_MAX); /// void clear(); @@ -113,38 +109,50 @@ namespace bx char toLower(char _ch); /// + void toLowerUnsafe(char* _inOutStr, int32_t _len); + + /// + void toLower(char* _inOutStr, int32_t _max = INT32_MAX); + + /// char toUpper(char _ch); /// + void toUpperUnsafe(char* _inOutStr, int32_t _len); + + /// + void toUpper(char* _inOutStr, int32_t _max = INT32_MAX); + + /// bool toBool(const char* _str); /// String compare. - int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max = INT32_MAX); + int32_t strncmp(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX); /// Case insensitive string compare. - int32_t strincmp(const char* _lhs, const char* _rhs, size_t _max = INT32_MAX); + int32_t strincmp(const char* _lhs, const char* _rhs, int32_t _max = INT32_MAX); /// - size_t strnlen(const char* _str, size_t _max = -1); + int32_t strnlen(const char* _str, int32_t _max = INT32_MAX); /// Copy _num characters from string _src to _dst buffer of maximum _dstSize capacity /// including zero terminator. Copy will be terminated with '\0'. - size_t strlncpy(char* _dst, size_t _dstSize, const char* _src, size_t _num = INT32_MAX); + int32_t strlncpy(char* _dst, int32_t _dstSize, const char* _src, int32_t _num = INT32_MAX); /// - size_t strlncat(char* _dst, size_t _dstSize, const char* _src, size_t _num = INT32_MAX); + int32_t strlncat(char* _dst, int32_t _dstSize, const char* _src, int32_t _num = INT32_MAX); /// - const char* strnchr(const char* _str, char _ch, size_t _max = INT32_MAX); + const char* strnchr(const char* _str, char _ch, int32_t _max = INT32_MAX); /// - const char* strnrchr(const char* _str, char _ch, size_t _max = INT32_MAX); + const char* strnrchr(const char* _str, char _ch, int32_t _max = INT32_MAX); /// Find substring in string. Limit search to _size. - const char* strnstr(const char* _str, const char* _find, size_t _max = INT32_MAX); + const char* strnstr(const char* _str, const char* _find, int32_t _max = INT32_MAX); /// Find substring in string. Case insensitive. Limit search to _max. - const char* stristr(const char* _str, const char* _find, size_t _max = INT32_MAX); + const char* stristr(const char* _str, const char* _find, int32_t _max = INT32_MAX); /// Find new line. Returns pointer after new line terminator. const char* strnl(const char* _str); @@ -165,29 +173,29 @@ namespace bx const char* strmb(const char* _str, char _open, char _close); // Normalize string to sane line endings. - void eolLF(char* _out, size_t _size, const char* _str); + void eolLF(char* _out, int32_t _size, const char* _str); // Finds identifier. const char* findIdentifierMatch(const char* _str, const char* _word); - // Finds any identifier from NULL terminated array of identifiers. + /// Finds any identifier from NULL terminated array of identifiers. const char* findIdentifierMatch(const char* _str, const char* _words[]); /// Cross platform implementation of vsnprintf that returns number of /// characters which would have been written to the final string if /// enough space had been available. - int32_t vsnprintf(char* _out, size_t _max, const char* _format, va_list _argList); + int32_t vsnprintf(char* _out, int32_t _max, const char* _format, va_list _argList); /// Cross platform implementation of vsnwprintf that returns number of /// characters which would have been written to the final string if /// enough space had been available. - int32_t vsnwprintf(wchar_t* _out, size_t _max, const wchar_t* _format, va_list _argList); + int32_t vsnwprintf(wchar_t* _out, int32_t _max, const wchar_t* _format, va_list _argList); /// - int32_t snprintf(char* _out, size_t _max, const char* _format, ...); + int32_t snprintf(char* _out, int32_t _max, const char* _format, ...); /// - int32_t swnprintf(wchar_t* _out, size_t _max, const wchar_t* _format, ...); + int32_t swnprintf(wchar_t* _out, int32_t _max, const wchar_t* _format, ...); /// template <typename Ty> @@ -205,37 +213,37 @@ namespace bx const char* baseName(const char* _filePath); /// Convert size in bytes to human readable string. - void prettify(char* _out, size_t _count, uint64_t _size); + void prettify(char* _out, int32_t _count, uint64_t _size); /// Copy src to string dst of size siz. At most siz-1 characters /// will be copied. Always NUL terminates (unless siz == 0). /// Returns strlen(src); if retval >= siz, truncation occurred. - size_t strlcpy(char* _dst, const char* _src, size_t _max); + int32_t strlcpy(char* _dst, const char* _src, int32_t _max); /// Appends src to string dst of size siz (unlike strncat, siz is the /// full size of dst, not space left). At most siz-1 characters /// will be copied. Always NUL terminates (unless siz <= strlen(dst)). /// Returns strlen(src) + MIN(siz, strlen(initial dst)). /// If retval >= siz, truncation occurred. - size_t strlcat(char* _dst, const char* _src, size_t _max); + int32_t strlcat(char* _dst, const char* _src, int32_t _max); /// - int32_t toString(char* _out, size_t _max, double _value); + int32_t toString(char* _out, int32_t _max, double _value); /// - int32_t toString(char* _out, size_t _max, int32_t _value, uint32_t _base = 10); + int32_t toString(char* _out, int32_t _max, int32_t _value, uint32_t _base = 10); /// - int32_t toString(char* _out, size_t _max, uint32_t _value, uint32_t _base = 10); + int32_t toString(char* _out, int32_t _max, int64_t _value, uint32_t _base = 10); /// - uint32_t hashMurmur2A(const StringView& _data); + int32_t toString(char* _out, int32_t _max, uint32_t _value, uint32_t _base = 10); /// - uint32_t hashMurmur2A(const char* _data); + int32_t toString(char* _out, int32_t _max, uint64_t _value, uint32_t _base = 10); } // namespace bx -#include "string.inl" +#include "inline/string.inl" #endif // BX_STRING_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/thread.h b/3rdparty/bx/include/bx/thread.h index 95152367f02..72a072e7d62 100644 --- a/3rdparty/bx/include/bx/thread.h +++ b/3rdparty/bx/include/bx/thread.h @@ -7,24 +7,7 @@ #define BX_THREAD_H_HEADER_GUARD #include "bx.h" - -#if BX_PLATFORM_POSIX -# include <pthread.h> -# if defined(__FreeBSD__) -# include <pthread_np.h> -# endif -# if BX_PLATFORM_LINUX && (BX_CRT_GLIBC < 21200) -# include <sys/prctl.h> -# endif // BX_PLATFORM_ -#elif BX_PLATFORM_WINRT -using namespace Platform; -using namespace Windows::Foundation; -using namespace Windows::System::Threading; -#endif // BX_PLATFORM_ - -#include "sem.h" - -#if BX_CONFIG_SUPPORTS_THREADING +#include "semaphore.h" namespace bx { @@ -62,16 +45,10 @@ namespace bx void setThreadName(const char* _name); private: + friend struct ThreadInternal; int32_t entry(); -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - static DWORD WINAPI threadFunc(LPVOID _arg); - HANDLE m_handle; - DWORD m_threadId; -#elif BX_PLATFORM_POSIX - static void* threadFunc(void* _arg); - pthread_t m_handle; -#endif // BX_PLATFORM_ + BX_ALIGN_DECL(16, uint8_t) m_internal[64]; ThreadFn m_fn; void* m_userData; @@ -98,17 +75,9 @@ namespace bx void set(void* _ptr); private: -#if BX_PLATFORM_WINDOWS - uint32_t m_id; -#elif !(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) - pthread_key_t m_id; -#endif // BX_PLATFORM_* + BX_ALIGN_DECL(16, uint8_t) m_internal[64]; }; } // namespace bx -#endif // BX_CONFIG_SUPPORTS_THREADING - -#include "thread.inl" - #endif // BX_THREAD_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/thread.inl b/3rdparty/bx/include/bx/thread.inl deleted file mode 100644 index 38fc49d0c3a..00000000000 --- a/3rdparty/bx/include/bx/thread.inl +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright 2010-2017 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause - */ - -#ifndef BX_THREAD_H_HEADER_GUARD -# error "Must be included from bx/thread.h!" -#endif // BX_THREAD_H_HEADER_GUARD - -#if BX_CONFIG_SUPPORTS_THREADING - -namespace bx -{ -#if BX_PLATFORM_WINDOWS - inline TlsData::TlsData() - { - m_id = TlsAlloc(); - BX_CHECK(TLS_OUT_OF_INDEXES != m_id, "Failed to allocated TLS index (err: 0x%08x).", GetLastError() ); - } - - inline TlsData::~TlsData() - { - BOOL result = TlsFree(m_id); - BX_CHECK(0 != result, "Failed to free TLS index (err: 0x%08x).", GetLastError() ); BX_UNUSED(result); - } - - inline void* TlsData::get() const - { - return TlsGetValue(m_id); - } - - inline void TlsData::set(void* _ptr) - { - TlsSetValue(m_id, _ptr); - } - -#elif !(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) - - inline TlsData::TlsData() - { - int result = pthread_key_create(&m_id, NULL); - BX_CHECK(0 == result, "pthread_key_create failed %d.", result); BX_UNUSED(result); - } - - inline TlsData::~TlsData() - { - int result = pthread_key_delete(m_id); - BX_CHECK(0 == result, "pthread_key_delete failed %d.", result); BX_UNUSED(result); - } - - inline void* TlsData::get() const - { - return pthread_getspecific(m_id); - } - - inline void TlsData::set(void* _ptr) - { - int result = pthread_setspecific(m_id, _ptr); - BX_CHECK(0 == result, "pthread_setspecific failed %d.", result); BX_UNUSED(result); - } -#endif // BX_PLATFORM_* - -} // namespace bx - -#endif // BX_CONFIG_SUPPORTS_THREADING diff --git a/3rdparty/bx/include/bx/timer.h b/3rdparty/bx/include/bx/timer.h index 7b01e2c9974..31a109614b3 100644 --- a/3rdparty/bx/include/bx/timer.h +++ b/3rdparty/bx/include/bx/timer.h @@ -18,6 +18,4 @@ namespace bx } // namespace bx -#include "timer.inl" - #endif // BX_TIMER_H_HEADER_GUARD diff --git a/3rdparty/bx/include/bx/uint32_t.h b/3rdparty/bx/include/bx/uint32_t.h index d3b3069fe92..622e49ebe58 100644 --- a/3rdparty/bx/include/bx/uint32_t.h +++ b/3rdparty/bx/include/bx/uint32_t.h @@ -285,6 +285,6 @@ namespace bx } // namespace bx -#include "uint32_t.inl" +#include "inline/uint32_t.inl" #endif // BX_UINT32_T_H_HEADER_GUARD diff --git a/3rdparty/bx/scripts/bin2c.lua b/3rdparty/bx/scripts/bin2c.lua index b308b3eb253..daa7b099498 100644 --- a/3rdparty/bx/scripts/bin2c.lua +++ b/3rdparty/bx/scripts/bin2c.lua @@ -4,7 +4,6 @@ -- project "bin2c" - uuid "60eaa654-7d06-11e4-be8e-880965202986" kind "ConsoleApp" includedirs { @@ -23,6 +22,11 @@ project "bin2c" configuration { "mingw-*" } targetextension ".exe" + configuration { "linux-*" } + links { + "pthread", + } + configuration {} strip() diff --git a/3rdparty/bx/scripts/bx.lua b/3rdparty/bx/scripts/bx.lua index b62ee4bae5f..a84eec43b75 100644 --- a/3rdparty/bx/scripts/bx.lua +++ b/3rdparty/bx/scripts/bx.lua @@ -7,13 +7,13 @@ project "bx" kind "StaticLib" includedirs { - "../include", + path.join(BX_DIR, "include"), } files { - "../include/**.h", - "../include/**.inl", - "../src/**.cpp", + path.join(BX_DIR, "include/**.h"), + path.join(BX_DIR, "include/**.inl"), + path.join(BX_DIR, "src/**.cpp"), } configuration { "linux-*" } @@ -22,3 +22,27 @@ project "bx" } configuration {} + + if _OPTIONS["with-amalgamated"] then + excludes { + path.join(BX_DIR, "src/commandline.cpp"), + path.join(BX_DIR, "src/crt.cpp"), + path.join(BX_DIR, "src/crtimpl.cpp"), + path.join(BX_DIR, "src/debug.cpp"), + path.join(BX_DIR, "src/dtoa.cpp"), + path.join(BX_DIR, "src/fpumath.cpp"), + path.join(BX_DIR, "src/mutex.cpp"), + path.join(BX_DIR, "src/os.cpp"), + path.join(BX_DIR, "src/sem.cpp"), + path.join(BX_DIR, "src/sort.cpp"), + path.join(BX_DIR, "src/string.cpp"), + path.join(BX_DIR, "src/thread.cpp"), + path.join(BX_DIR, "src/timer.cpp"), + } + else + excludes { + path.join(BX_DIR, "src/amalgamated.**"), + } + end + + configuration {} diff --git a/3rdparty/bx/scripts/genie.lua b/3rdparty/bx/scripts/genie.lua index e0e634ae716..9919b8c6181 100644 --- a/3rdparty/bx/scripts/genie.lua +++ b/3rdparty/bx/scripts/genie.lua @@ -3,6 +3,16 @@ -- License: https://github.com/bkaradzic/bx#license-bsd-2-clause -- +newoption { + trigger = "with-amalgamated", + description = "Enable amalgamated build.", +} + +newoption { + trigger = "with-crtnone", + description = "Enable build without CRT.", +} + solution "bx" configurations { "Debug", @@ -21,10 +31,6 @@ BX_DIR = path.getabsolute("..") local BX_BUILD_DIR = path.join(BX_DIR, ".build") local BX_THIRD_PARTY_DIR = path.join(BX_DIR, "3rdparty") -defines { - "BX_CONFIG_ENABLE_MSVC_LEVEL4_WARNINGS=1" -} - dofile "toolchain.lua" toolchain(BX_BUILD_DIR, BX_THIRD_PARTY_DIR) @@ -50,7 +56,7 @@ project "bx.test" files { path.join(BX_DIR, "tests/*_test.cpp"), - path.join(BX_DIR, "tests/*_test.H"), + path.join(BX_DIR, "tests/*.h"), path.join(BX_DIR, "tests/dbg.*"), } diff --git a/3rdparty/bx/scripts/toolchain.lua b/3rdparty/bx/scripts/toolchain.lua index 6a01c92422c..0152ce79c32 100644 --- a/3rdparty/bx/scripts/toolchain.lua +++ b/3rdparty/bx/scripts/toolchain.lua @@ -6,6 +6,43 @@ local bxDir = path.getabsolute("..") local naclToolchain = "" +local function crtNone() + + defines { + "BX_CRT_NONE=1", + } + + buildoptions { + "-nostdlib", + "-nodefaultlibs", + "-nostartfiles", + "-Wa,--noexecstack", + "-ffreestanding", + } + + linkoptions { + "-nostdlib", + "-nodefaultlibs", + "-nostartfiles", + "-Wa,--noexecstack", + "-ffreestanding", + } + + configuration { "linux-*" } + + buildoptions { + "-mpreferred-stack-boundary=4", + "-mstackrealign", + } + + linkoptions { + "-mpreferred-stack-boundary=4", + "-mstackrealign", + } + + configuration {} +end + function toolchain(_buildDir, _libDir) newoption { @@ -152,6 +189,10 @@ function toolchain(_buildDir, _libDir) compiler32bit = true end + flags { + "ExtraWarnings", + } + if _ACTION == "gmake" or _ACTION == "ninja" then if nil == _OPTIONS["gcc"] then @@ -159,20 +200,18 @@ function toolchain(_buildDir, _libDir) os.exit(1) end - flags { - "ExtraWarnings", - } - if "android-arm" == _OPTIONS["gcc"] then if not os.getenv("ANDROID_NDK_ARM") or not os.getenv("ANDROID_NDK_CLANG") or not os.getenv("ANDROID_NDK_ROOT") then - print("Set ANDROID_NDK_CLANG and ANDROID_NDK_ROOT envrionment variables.") + print("Set ANDROID_NDK_CLANG, ANDROID_NDK_ARM, and ANDROID_NDK_ROOT envrionment variables.") end premake.gcc.cc = "$(ANDROID_NDK_CLANG)/bin/clang" premake.gcc.cxx = "$(ANDROID_NDK_CLANG)/bin/clang++" + premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar" + premake.gcc.llvm = true location (path.join(_buildDir, "projects", _ACTION .. "-android-arm")) @@ -181,7 +220,7 @@ function toolchain(_buildDir, _libDir) if not os.getenv("ANDROID_NDK_MIPS") or not os.getenv("ANDROID_NDK_CLANG") or not os.getenv("ANDROID_NDK_ROOT") then - print("Set ANDROID_NDK_MIPS and ANDROID_NDK_ROOT envrionment variables.") + print("Set ANDROID_NDK_CLANG, ANDROID_NDK_ARM, and ANDROID_NDK_ROOT envrionment variables.") end premake.gcc.cc = "$(ANDROID_NDK_CLANG)/bin/clang" @@ -194,7 +233,7 @@ function toolchain(_buildDir, _libDir) if not os.getenv("ANDROID_NDK_X86") or not os.getenv("ANDROID_NDK_CLANG") or not os.getenv("ANDROID_NDK_ROOT") then - print("Set ANDROID_NDK_X86 and ANDROID_NDK_ROOT envrionment variables.") + print("Set ANDROID_NDK_CLANG, ANDROID_NDK_ARM, and ANDROID_NDK_ROOT envrionment variables.") end premake.gcc.cc = "$(ANDROID_NDK_CLANG)/bin/clang" @@ -516,6 +555,10 @@ function toolchain(_buildDir, _libDir) flags { "EnableAVX" } end + if _OPTIONS["with-crtnone"] then + crtNone() + end + flags { "NoPCH", "NativeWChar", @@ -1306,6 +1349,7 @@ function toolchain(_buildDir, _libDir) } links { "rt", + "dl", } linkoptions { "-Wl,--gc-sections", @@ -1400,5 +1444,11 @@ function strip() -- .. "--preload-file ../../../examples/runtime@/" } + configuration { "riscv" } + postbuildcommands { + "$(SILENT) echo Stripping symbols.", + "$(SILENT) $(FREEDOM_E_SDK)/toolchain/bin/riscv32-unknown-elf-strip -s \"$(TARGET)\"" + } + configuration {} -- reset configuration end diff --git a/3rdparty/bx/scripts/uncrustify.cfg b/3rdparty/bx/scripts/uncrustify.cfg deleted file mode 100644 index 8f8ec163f21..00000000000 --- a/3rdparty/bx/scripts/uncrustify.cfg +++ /dev/null @@ -1,218 +0,0 @@ -tok_split_gte=false -utf8_byte=false -utf8_force=false -indent_cmt_with_tabs=false -indent_align_string=false -indent_braces=false -indent_braces_no_func=false -indent_braces_no_class=false -indent_braces_no_struct=false -indent_brace_parent=false -indent_namespace=true -indent_extern=false -indent_class=false -indent_class_colon=false -indent_else_if=false -indent_var_def_cont=false -indent_func_call_param=false -indent_func_def_param=false -indent_func_proto_param=false -indent_func_class_param=false -indent_func_ctor_var_param=false -indent_template_param=false -indent_func_param_double=false -indent_relative_single_line_comments=false -indent_col1_comment=false -indent_access_spec_body=false -indent_paren_nl=true -indent_comma_paren=true -indent_bool_paren=true -indent_first_bool_expr=false -indent_square_nl=false -indent_preserve_sql=false -indent_align_assign=true -sp_balance_nested_parens=false -align_keep_tabs=false -align_with_tabs=false -align_on_tabstop=false -align_number_left=true -align_func_params=false -align_same_func_call_params=false -align_var_def_colon=false -align_var_def_attribute=false -align_var_def_inline=false -align_right_cmt_mix=false -align_on_operator=false -align_mix_var_proto=false -align_single_line_func=false -align_single_line_brace=false -align_nl_cont=false -align_left_shift=true -align_oc_decl_colon=false -nl_collapse_empty_body=false -nl_assign_leave_one_liners=true -nl_class_leave_one_liners=false -nl_enum_leave_one_liners=false -nl_getset_leave_one_liners=false -nl_func_leave_one_liners=false -nl_if_leave_one_liners=false -nl_multi_line_cond=false -nl_multi_line_define=false -nl_before_case=true -nl_after_case=false -nl_after_return=false -nl_after_semicolon=false -nl_after_brace_open=false -nl_after_brace_open_cmt=false -nl_after_vbrace_open=false -nl_after_vbrace_open_empty=false -nl_after_brace_close=false -nl_after_vbrace_close=false -nl_define_macro=false -nl_squeeze_ifdef=false -nl_ds_struct_enum_cmt=false -nl_ds_struct_enum_close_brace=false -nl_create_if_one_liner=false -nl_create_for_one_liner=false -nl_create_while_one_liner=false -ls_for_split_full=false -ls_func_split_full=false -nl_after_multiline_comment=false -eat_blanks_after_open_brace=true -eat_blanks_before_close_brace=true -mod_full_brace_if_chain=false -mod_pawn_semicolon=false -mod_full_paren_if_bool=false -mod_remove_extra_semicolon=true -mod_sort_import=false -mod_sort_using=false -mod_sort_include=false -mod_move_case_break=false -mod_remove_empty_return=true -cmt_indent_multi=false -cmt_c_group=false -cmt_c_nl_start=false -cmt_c_nl_end=false -cmt_cpp_group=false -cmt_cpp_nl_start=false -cmt_cpp_nl_end=false -cmt_cpp_to_c=false -cmt_star_cont=false -cmt_multi_check_last=false -cmt_insert_before_preproc=false -pp_indent_at_level=false -pp_region_indent_code=false -pp_if_indent_code=false -pp_define_at_level=false -indent_paren_close=1 -align_struct_init_span=1 -align_pp_define_span=1 -nl_end_of_file_min=1 -nl_max=2 -mod_add_long_ifdef_endif_comment=1 -pp_space_count=3 -newlines=auto -indent_with_tabs=1 -sp_arith=force -sp_assign=force -sp_enum_assign=force -sp_bool=force -sp_compare=force -sp_inside_paren=remove -sp_paren_paren=force -sp_before_ptr_star=remove -sp_before_unnamed_ptr_star=remove -sp_between_ptr_star=remove -sp_after_ptr_star=force -sp_after_ptr_star_func=force -sp_before_ptr_star_func=remove -sp_before_byref=remove -sp_before_unnamed_byref=remove -sp_after_byref=force -sp_after_type=force -sp_template_angle=remove -sp_angle_shift=add -sp_before_sparen=force -sp_inside_sparen=remove -sp_after_sparen=force -sp_special_semi=remove -sp_before_semi=remove -sp_after_semi_for=force -sp_after_semi_for_empty=remove -sp_before_square=remove -sp_before_squares=remove -sp_after_comma=force -sp_before_comma=remove -sp_before_ellipsis=force -sp_after_class_colon=force -sp_before_class_colon=force -sp_before_case_colon=remove -sp_after_operator=remove -sp_after_operator_sym=remove -sp_cpp_cast_paren=remove -sp_sizeof_paren=remove -sp_inside_braces_enum=force -sp_inside_braces_struct=force -sp_inside_braces_empty=remove -sp_type_func=force -sp_func_proto_paren=remove -sp_func_def_paren=remove -sp_inside_fparens=remove -sp_inside_fparen=remove -sp_square_fparen=remove -sp_fparen_brace=force -sp_func_call_paren=remove -sp_func_call_paren_empty=remove -sp_func_call_user_paren=remove -sp_func_class_paren=remove -sp_return_paren=force -sp_attribute_paren=remove -sp_defined_paren=remove -sp_macro=force -sp_macro_func=force -sp_not=remove -sp_inv=remove -sp_addr=remove -sp_member=remove -sp_deref=remove -sp_sign=remove -sp_incdec=remove -sp_before_nl_cont=force -sp_cond_colon=force -sp_cond_question=force -sp_case_label=force -sp_endif_cmt=force -sp_after_new=force -nl_end_of_file=force -nl_assign_brace=force -nl_fcall_brace=force -nl_enum_brace=force -nl_struct_brace=force -nl_union_brace=force -nl_if_brace=force -nl_brace_else=force -nl_elseif_brace=force -nl_else_brace=force -nl_else_if=remove -nl_for_brace=force -nl_while_brace=force -nl_brace_brace=force -nl_do_brace=force -nl_brace_while=force -nl_switch_brace=force -nl_namespace_brace=force -nl_fdef_brace=force -nl_after_if=add -nl_after_for=add -nl_after_while=add -nl_after_switch=add -nl_after_do=add -pos_bool=lead_force -mod_full_brace_do=force -mod_full_brace_for=force -mod_full_brace_function=force -mod_full_brace_if=force -mod_full_brace_while=force -mod_paren_on_return=remove -pp_indent=remove -pp_space=add diff --git a/3rdparty/bx/src/amalgamated.cpp b/3rdparty/bx/src/amalgamated.cpp new file mode 100644 index 00000000000..1aeb2bb906d --- /dev/null +++ b/3rdparty/bx/src/amalgamated.cpp @@ -0,0 +1,19 @@ +/* + * Copyright 2011-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + */ + +#include "bx.cpp" +#include "commandline.cpp" +#include "crtimpl.cpp" +#include "crtnone.cpp" +#include "debug.cpp" +#include "dtoa.cpp" +#include "fpumath.cpp" +#include "mutex.cpp" +#include "os.cpp" +#include "semaphore.cpp" +#include "sort.cpp" +#include "string.cpp" +#include "thread.cpp" +#include "timer.cpp" diff --git a/3rdparty/bx/src/bx.cpp b/3rdparty/bx/src/bx.cpp new file mode 100644 index 00000000000..8a063c56de9 --- /dev/null +++ b/3rdparty/bx/src/bx.cpp @@ -0,0 +1,146 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include <bx/debug.h> +#include <bx/readerwriter.h> + +#if !BX_CRT_NONE +# include <string.h> // memcpy, memmove, memset +#endif // !BX_CRT_NONE + +namespace bx +{ + void xchg(void* _a, void* _b, size_t _numBytes) + { + uint8_t* lhs = (uint8_t*)_a; + uint8_t* rhs = (uint8_t*)_b; + const uint8_t* end = rhs + _numBytes; + while (rhs != end) + { + xchg(*lhs++, *rhs++); + } + } + + void memCopyRef(void* _dst, const void* _src, size_t _numBytes) + { + uint8_t* dst = (uint8_t*)_dst; + const uint8_t* end = dst + _numBytes; + const uint8_t* src = (const uint8_t*)_src; + while (dst != end) + { + *dst++ = *src++; + } + } + + void memCopy(void* _dst, const void* _src, size_t _numBytes) + { +#if BX_CRT_NONE + memCopyRef(_dst, _src, _numBytes); +#else + ::memcpy(_dst, _src, _numBytes); +#endif // BX_CRT_NONE + } + + void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch) + { + const uint8_t* src = (const uint8_t*)_src; + uint8_t* dst = (uint8_t*)_dst; + + for (uint32_t ii = 0; ii < _num; ++ii) + { + memCopy(dst, src, _size); + src += _srcPitch; + dst += _dstPitch; + } + } + + /// + void gather(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch) + { + memCopy(_dst, _src, _size, _num, _srcPitch, _size); + } + + /// + void scatter(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _dstPitch) + { + memCopy(_dst, _src, _size, _num, _size, _dstPitch); + } + + void memMoveRef(void* _dst, const void* _src, size_t _numBytes) + { + uint8_t* dst = (uint8_t*)_dst; + const uint8_t* src = (const uint8_t*)_src; + + if (_numBytes == 0 + || dst == src) + { + return; + } + + // if (src+_numBytes <= dst || end <= src) + if (dst < src) + { + memCopy(_dst, _src, _numBytes); + return; + } + + for (intptr_t ii = _numBytes-1; ii >= 0; --ii) + { + dst[ii] = src[ii]; + } + } + + void memMove(void* _dst, const void* _src, size_t _numBytes) + { +#if BX_CRT_NONE + memMoveRef(_dst, _src, _numBytes); +#else + ::memmove(_dst, _src, _numBytes); +#endif // BX_CRT_NONE + } + + void memSetRef(void* _dst, uint8_t _ch, size_t _numBytes) + { + uint8_t* dst = (uint8_t*)_dst; + const uint8_t* end = dst + _numBytes; + while (dst != end) + { + *dst++ = char(_ch); + } + } + + void memSet(void* _dst, uint8_t _ch, size_t _numBytes) + { +#if BX_CRT_NONE + memSetRef(_dst, _ch, _numBytes); +#else + ::memset(_dst, _ch, _numBytes); +#endif // BX_CRT_NONE + } + + int32_t memCmpRef(const void* _lhs, const void* _rhs, size_t _numBytes) + { + const char* lhs = (const char*)_lhs; + const char* rhs = (const char*)_rhs; + for ( + ; 0 < _numBytes && *lhs == *rhs + ; ++lhs, ++rhs, --_numBytes + ) + { + } + + return 0 == _numBytes ? 0 : *lhs - *rhs; + } + + int32_t memCmp(const void* _lhs, const void* _rhs, size_t _numBytes) + { +#if BX_CRT_NONE + return memCmpRef(_lhs, _rhs, _numBytes); +#else + return ::memcmp(_lhs, _rhs, _numBytes); +#endif // BX_CRT_NONE + } + +} // namespace bx diff --git a/3rdparty/bx/src/commandline.cpp b/3rdparty/bx/src/commandline.cpp index 400e4965a0e..6ec2aadaaaf 100644 --- a/3rdparty/bx/src/commandline.cpp +++ b/3rdparty/bx/src/commandline.cpp @@ -175,13 +175,13 @@ namespace bx bool CommandLine::hasArg(const char _short, const char* _long) const { - const char* arg = findOption(_short, _long, 0); + const char* arg = findOption(_short, _long, int32_t(0) ); return NULL != arg; } bool CommandLine::hasArg(const char* _long) const { - const char* arg = findOption('\0', _long, 0); + const char* arg = findOption('\0', _long, int32_t(0) ); return NULL != arg; } diff --git a/3rdparty/bx/src/crt.cpp b/3rdparty/bx/src/crt.cpp deleted file mode 100644 index 8686f03d267..00000000000 --- a/3rdparty/bx/src/crt.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* - * Copyright 2010-2017 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bx#license-bsd-2-clause - */ - -#include <bx/bx.h> -#include <bx/readerwriter.h> -#include <bx/debug.h> - -namespace bx -{ - void* memCopyRef(void* _dst, const void* _src, size_t _numBytes) - { - uint8_t* dst = (uint8_t*)_dst; - const uint8_t* end = dst + _numBytes; - const uint8_t* src = (const uint8_t*)_src; - while (dst != end) - { - *dst++ = *src++; - } - - return _dst; - } - - void* memCopy(void* _dst, const void* _src, size_t _numBytes) - { -#if BX_CRT_NONE - return memCopyRef(_dst, _src, _numBytes); -#else - return ::memcpy(_dst, _src, _numBytes); -#endif // BX_CRT_NONE - } - - void memCopy(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch, uint32_t _dstPitch) - { - const uint8_t* src = (const uint8_t*)_src; - uint8_t* dst = (uint8_t*)_dst; - - for (uint32_t ii = 0; ii < _num; ++ii) - { - memCopy(dst, src, _size); - src += _srcPitch; - dst += _dstPitch; - } - } - - /// - void gather(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _srcPitch) - { - memCopy(_dst, _src, _size, _num, _srcPitch, _size); - } - - /// - void scatter(void* _dst, const void* _src, uint32_t _size, uint32_t _num, uint32_t _dstPitch) - { - memCopy(_dst, _src, _size, _num, _size, _dstPitch); - } - - void* memMoveRef(void* _dst, const void* _src, size_t _numBytes) - { - uint8_t* dst = (uint8_t*)_dst; - const uint8_t* src = (const uint8_t*)_src; - - if (_numBytes == 0 - || dst == src) - { - return dst; - } - - // if (src+_numBytes <= dst || end <= src) - if (dst < src) - { - return memcpy(_dst, _src, _numBytes); - } - - for (intptr_t ii = _numBytes-1; ii >= 0; --ii) - { - dst[ii] = src[ii]; - } - - return _dst; - } - - void* memMove(void* _dst, const void* _src, size_t _numBytes) - { -#if BX_CRT_NONE - return memMoveRef(_dst, _src, _numBytes); -#else - return ::memmove(_dst, _src, _numBytes); -#endif // BX_CRT_NONE - } - - void* memSetRef(void* _dst, uint8_t _ch, size_t _numBytes) - { - uint8_t* dst = (uint8_t*)_dst; - const uint8_t* end = dst + _numBytes; - while (dst != end) - { - *dst++ = char(_ch); - } - - return _dst; - } - - void* memSet(void* _dst, uint8_t _ch, size_t _numBytes) - { -#if BX_CRT_NONE - return memSetRef(_dst, _ch, _numBytes); -#else - return ::memset(_dst, _ch, _numBytes); -#endif // BX_CRT_NONE - } - - namespace - { - struct Param - { - int32_t width; - uint32_t base; - uint32_t prec; - char fill; - bool left; - }; - - static int32_t write(WriterI* _writer, const char* _str, int32_t _len, const Param& _param, Error* _err) - { - int32_t size = 0; - int32_t len = (int32_t)strnlen(_str, _len); - int32_t padding = _param.width > len ? _param.width - len : 0; - - if (!_param.left) - { - size += writeRep(_writer, _param.fill, padding, _err); - } - - size += write(_writer, _str, len, _err); - - if (_param.left) - { - size += writeRep(_writer, _param.fill, padding, _err); - } - - return size; - } - - static int32_t write(WriterI* _writer, const char* _str, const Param& _param, Error* _err) - { - return write(_writer, _str, INT32_MAX, _param, _err); - } - - static int32_t write(WriterI* _writer, int32_t _i, const Param& _param, Error* _err) - { - char str[33]; - int32_t len = toString(str, sizeof(str), _i, _param.base); - - if (len == 0) - { - return 0; - } - - return write(_writer, str, len, _param, _err); - } - - static int32_t write(WriterI* _writer, uint32_t _i, const Param& _param, Error* _err) - { - char str[33]; - int32_t len = toString(str, sizeof(str), _i, _param.base); - - if (len == 0) - { - return 0; - } - - return write(_writer, str, len, _param, _err); - } - - static int32_t write(WriterI* _writer, double _d, const Param& _param, Error* _err) - { - char str[1024]; - int32_t len = toString(str, sizeof(str), _d); - - if (len == 0) - { - return 0; - } - - const char* dot = strnchr(str, '.'); - const int32_t precLen = int32_t(dot + 1 + _param.prec - str); - if (precLen > len) - { - for (int32_t ii = len; ii < precLen; ++ii) - { - str[ii] = '0'; - } - str[precLen] = '\0'; - } - len = precLen; - - return write(_writer, str, len, _param, _err); - } - - static int32_t write(WriterI* _writer, const void* _ptr, const Param& _param, Error* _err) - { - char str[35] = "0x"; - int32_t len = toString(str + 2, sizeof(str) - 2, uint32_t(uintptr_t(_ptr) ), 16); - - if (len == 0) - { - return 0; - } - - len += 2; - return write(_writer, str, len, _param, _err); - } - } // anonymous namespace - - int32_t write(WriterI* _writer, const char* _format, va_list _argList, Error* _err) - { - MemoryReader reader(_format, strnlen(_format) ); - - int32_t size = 0; - - while (_err->isOk() ) - { - char ch = '\0'; - read(&reader, ch, _err); - - if (!_err->isOk() ) - { - break; - } - else if ('%' == ch) - { - // %[ -0][<width>][.<precision>] - read(&reader, ch); - - Param param; - param.base = 10; - param.prec = 6; - param.left = false; - param.fill = ' '; - param.width = 0; - - while (' ' == ch - || '-' == ch - || '0' == ch) - { - switch (ch) - { - case '-': param.left = true; break; - case ' ': param.fill = ' '; break; - case '0': param.fill = '0'; break; - } - - if (param.left) - { - param.fill = ' '; - } - - read(&reader, ch); - } - - if ('*' == ch) - { - read(&reader, ch); - param.width = va_arg(_argList, int32_t); - - if (0 > param.width) - { - param.left = true; - param.width = -param.width; - } - - } - else - { - while (isNumeric(ch) ) - { - param.width = param.width * 10 + ch - '0'; - read(&reader, ch); - } - } - - if ('.' == ch) - { - read(&reader, ch); - - if ('*' == ch) - { - read(&reader, ch); - param.prec = va_arg(_argList, int32_t); - } - else - { - param.prec = 0; - while (isNumeric(ch) ) - { - param.prec = param.prec * 10 + ch - '0'; - read(&reader, ch); - } - } - } - - switch (toLower(ch) ) - { - case 'c': - size += write(_writer, char(va_arg(_argList, int32_t) ), _err); - break; - - case 's': - size += write(_writer, va_arg(_argList, const char*), param, _err); - break; - - case 'd': - param.base = 10; - size += write(_writer, va_arg(_argList, int32_t), param, _err); - break; - - case 'f': - size += write(_writer, va_arg(_argList, double), param, _err); - break; - - case 'p': - size += write(_writer, va_arg(_argList, void*), param, _err); - break; - - case 'x': - param.base = 16; - size += write(_writer, va_arg(_argList, uint32_t), param, _err); - break; - - case 'u': - param.base = 10; - size += write(_writer, va_arg(_argList, uint32_t), param, _err); - break; - - default: - size += write(_writer, ch, _err); - break; - } - } - else - { - size += write(_writer, ch, _err); - } - } - - size += write(_writer, '\0', _err); - - return size; - } - - int32_t write(WriterI* _writer, Error* _err, const char* _format, ...) - { - va_list argList; - va_start(argList, _format); - int32_t size = write(_writer, _format, argList, _err); - va_end(argList); - return size; - } - -} // namespace bx diff --git a/3rdparty/bx/src/crtimpl.cpp b/3rdparty/bx/src/crtimpl.cpp index 7adb74bb8ee..064b9f6e3ad 100644 --- a/3rdparty/bx/src/crtimpl.cpp +++ b/3rdparty/bx/src/crtimpl.cpp @@ -4,6 +4,7 @@ */ #include <bx/crtimpl.h> +#include <stdio.h> #if BX_CONFIG_ALLOCATOR_CRT # include <malloc.h> diff --git a/3rdparty/bx/src/crtnone.cpp b/3rdparty/bx/src/crtnone.cpp new file mode 100644 index 00000000000..0e88551b6f3 --- /dev/null +++ b/3rdparty/bx/src/crtnone.cpp @@ -0,0 +1,590 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include <bx/debug.h> +#include <bx/sort.h> +#include <bx/readerwriter.h> + +#if BX_CRT_NONE + +extern "C" void* memcpy(void* _dst, const void* _src, size_t _numBytes) +{ + bx::memCopy(_dst, _src, _numBytes); + return _dst; +} + +extern "C" void* memmove(void* _dst, const void* _src, size_t _numBytes) +{ + bx::memMove(_dst, _src, _numBytes); + return _dst; +} + +extern "C" void* memset(void* _dst, int _ch, size_t _numBytes) +{ + bx::memSet(_dst, uint8_t(_ch), _numBytes); + return _dst; +} + +#if !BX_PLATFORM_NONE + +typedef int64_t off64_t; +typedef int32_t pid_t; + +extern "C" int32_t memcmp(const void* _lhs, const void* _rhs, size_t _numBytes) +{ + return bx::memCmp(_lhs, _rhs, _numBytes); +} + +extern "C" size_t strlen(const char* _str) +{ + return bx::strnlen(_str); +} + +extern "C" size_t strnlen(const char* _str, size_t _max) +{ + return bx::strnlen(_str, _max); +} + +extern "C" void* strcpy(char* _dst, const char* _src) +{ + bx::strlncpy(_dst, INT32_MAX, _src, INT32_MAX); + return _dst; +} + +extern "C" void* strncpy(char* _dst, const char* _src, size_t _num) +{ + bx::strlncpy(_dst, INT32_MAX, _src, _num); + return _dst; +} + +extern "C" char* strcat(char* _dst, const char* _src) +{ + bx::strlncat(_dst, INT32_MAX, _src, INT32_MAX); + return _dst; +} + +extern "C" const char* strchr(const char* _str, int _ch) +{ + return bx::strnchr(_str, _ch); +} + +extern "C" int32_t strcmp(const char* _lhs, const char* _rhs) +{ + return bx::strncmp(_lhs, _rhs); +} + +extern "C" int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max) +{ + return bx::strncmp(_lhs, _rhs, _max); +} + +extern "C" const char* strstr(const char* _str, const char* _find) +{ + return bx::strnstr(_str, _find); +} + +extern "C" void qsort(void* _base, size_t _num, size_t _size, bx::ComparisonFn _fn) +{ + BX_CHECK(_num <= UINT32_MAX && _size <= UINT32_MAX, ""); + return bx::quickSort(_base, _num, _size, _fn); +} + +extern "C" int isprint(int _ch) +{ + return bx::isPrint(_ch); +} + +extern "C" int toupper (int _ch) +{ + return bx::toUpper(_ch); +} + +extern "C" size_t mbstowcs(wchar_t* _dst, const char* _src, size_t _max) +{ + BX_UNUSED(_dst, _src, _max); + return 0; +} + +extern "C" char* strdup(const char* _src) +{ + BX_UNUSED(_src); + return NULL; +} + +extern "C" long int strtol(const char* _str, char** _end, int _base) +{ + BX_UNUSED(_str, _end, _base); + return -1; +} + +extern "C" int abs(int _value) +{ + return _value >= 0 ? _value : -_value; +} + +extern "C" float fabsf(float _value) +{ + return _value >= 0.0f ? _value : -_value; +} + +extern "C" double fabs(double _value) +{ + return _value >= 0.0 ? _value : -_value; +} + +extern "C" double ldexp(double _x, int _exp) +{ + BX_UNUSED(_x, _exp); + return 0.0; +} + +extern "C" float expf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float logf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float log10f(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float powf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" double pow(double _x) +{ + BX_UNUSED(_x); + return 0.0; +} + +extern "C" float sinf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float cosf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float tanf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float atan2f(float _y, float _x) +{ + BX_UNUSED(_y, _x); + return 0.0f; +} + +extern "C" float sqrtf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" double sqrt(double _x) +{ + BX_UNUSED(_x); + return 0.0; +} + +extern "C" float ceilf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" double ceil(double _x) +{ + BX_UNUSED(_x); + return 0.0; +} + +extern "C" float floorf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" double floor(double _x) +{ + BX_UNUSED(_x); + return 0.0; +} + +extern "C" float acosf(float _x) +{ + BX_UNUSED(_x); + return 0.0f; +} + +extern "C" float fmodf(float _numer, float _denom) +{ + BX_UNUSED(_numer, _denom); + return 0.0f; +} + +extern "C" int atoi(const char* _str) +{ + BX_UNUSED(_str); + return 0; +} + +extern "C" double atof(const char* _str) +{ + BX_UNUSED(_str); + return 0.0; +} + +extern "C" struct DIR* opendir(const char* dirname) +{ + BX_UNUSED(dirname); + return NULL; +} + +extern "C" struct dirent* readdir(struct DIR* dirp) +{ + BX_UNUSED(dirp); + return NULL; +} + +extern "C" int closedir (struct DIR* dirp) +{ + BX_UNUSED(dirp); + return 0; +} + +extern "C" int vsnprintf(char* _out, size_t _max, const char* _format, va_list _argList) +{ + return bx::vsnprintf(_out, _max, _format, _argList); +} + +extern "C" int sprintf(char* _out, const char* _format, ...) +{ + va_list argList; + va_start(argList, _format); + int32_t len = bx::vsnprintf(_out, INT32_MAX, _format, argList); + va_end(argList); + return len; +} + +extern "C" int snprintf(char* _out, size_t _max, const char* _format, ...) +{ + va_list argList; + va_start(argList, _format); + int32_t len = bx::vsnprintf(_out, _max, _format, argList); + va_end(argList); + return len; +} + +extern "C" int printf(const char* _format, ...) +{ + BX_UNUSED(_format); + return -1; +} + +extern "C" int fprintf(FILE* _stream, const char* _format, ...) +{ + BX_UNUSED(_stream, _format); + return -1; +} + +extern "C" int vfprintf(FILE* _stream, const char* _format, va_list _argList) +{ + BX_UNUSED(_stream, _format, _argList); + return -1; +} + +extern "C" int sscanf(const char* _str, const char* _format, ...) +{ + BX_UNUSED(_str, _format); + return -1; +} + +extern "C" int fscanf(FILE* _stream, const char* _format, ...) +{ + BX_UNUSED(_stream, _format); + return -1; +} + +FILE * stdout; + +extern "C" FILE* fopen(const char* _filename, const char* _mode) +{ + BX_UNUSED(_filename, _mode); + return NULL; +} + +extern "C" int fclose(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" size_t fread(void* _ptr, size_t _size, size_t _count, FILE* _stream) +{ + BX_UNUSED(_ptr, _size, _count, _stream); + return -1; +} + +extern "C" size_t fwrite(const void* _ptr, size_t _size, size_t _count, FILE* _stream) +{ + BX_UNUSED(_ptr, _size, _count, _stream); + return -1; +} + +extern "C" int fseek(FILE* _stream, long int _offset, int _origin) +{ + BX_UNUSED(_stream, _offset, _origin); + return -1; +} + +extern "C" int fseeko64(FILE* _stream, off64_t _offset, int _whence) +{ + BX_UNUSED(_stream, _offset, _whence); + return -1; +} + +extern "C" long int ftell(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" off64_t ftello64(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" int feof(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" int ferror(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" FILE* popen(const char* _command, const char* _type) +{ + BX_UNUSED(_command, _type); + return NULL; +} + +extern "C" int pclose(FILE* _stream) +{ + BX_UNUSED(_stream); + return -1; +} + +extern "C" int execvp(const char* _file, char* const _argv[]) +{ + BX_UNUSED(_file, _argv); + return -1; +} + +extern "C" long syscall(long _num, ...) +{ + BX_UNUSED(_num); + return -1; +} + +extern "C" long sysconf(int name) +{ + BX_UNUSED(name); + return -1; +} + +extern "C" pid_t fork() +{ + return -1; +} + +extern "C" int sched_yield() +{ + return -1; +} + +extern "C" int prctl(int _option, unsigned long _arg2, unsigned long _arg3, unsigned long _arg4, unsigned long _arg5) +{ + BX_UNUSED(_option, _arg2, _arg3, _arg4, _arg5); + return -1; +} + +extern "C" int chdir(const char* _path) +{ + BX_UNUSED(_path); + return -1; +} + +extern "C" char* getcwd(char* _buf, size_t _size) +{ + BX_UNUSED(_buf, _size); + return NULL; +} + +extern "C" char* getenv(const char* _name) +{ + BX_UNUSED(_name); + return NULL; +} + +extern "C" int setenv(const char* _name, const char* _value, int _overwrite) +{ + BX_UNUSED(_name, _value, _overwrite); + return -1; +} + +extern "C" int unsetenv(const char* _name) +{ + BX_UNUSED(_name); + return -1; +} + +extern "C" time_t time(time_t* _arg) +{ + BX_UNUSED(_arg); + return -1; +} + +extern "C" int gettimeofday(struct timeval* _tv, struct timezone* _tz) +{ + BX_UNUSED(_tv, _tz); + return -1; +} + +extern "C" void* realloc(void* _ptr, size_t _size) +{ + BX_UNUSED(_ptr, _size); + return NULL; +} + +extern "C" void* malloc(size_t _size) +{ + return ::realloc(NULL, _size); +} + +extern "C" void free(void* _ptr) +{ + BX_UNUSED(_ptr); +} + +#endif // BX_PLATFORM_* + +extern "C" void abort() +{ + while (true) {}; +} + +extern "C" void __assert_fail(const char* _assertion, const char* _file, uint32_t _line, const char* _function) +{ + BX_UNUSED(_assertion, _file, _line, _function); + abort(); +} + +void* __dso_handle = (void*)&__dso_handle; + +void operator delete(void*) +{ +} + +extern "C" void __cxa_pure_virtual() +{ +} + +extern "C" int __cxa_atexit(void (*_dtorFn)(void*), void* _arg, void* _dsoHandle) +{ + BX_UNUSED(_dtorFn, _arg, _dsoHandle); + return 0; +} + +extern "C" void __gxx_personality_v0() +{ +} + +extern "C" void _Unwind_Resume(void*) +{ +} + +extern "C" int __gcc_personality_v0(int _version, ...) +{ + BX_UNUSED(_version); + return 0; +} + +namespace __cxxabiv1 +{ + class __class_type_info + { + public: + virtual ~__class_type_info(); + + const char* m_name; + }; + + __class_type_info::~__class_type_info() + { + } + + class __si_class_type_info : public __class_type_info + { + public: + virtual ~__si_class_type_info(); + }; + + __si_class_type_info::~__si_class_type_info() + { + } + + class __vmi_class_type_info : public __class_type_info + { + public: + virtual ~__vmi_class_type_info(); + }; + + __vmi_class_type_info::~__vmi_class_type_info() + { + } + + __extension__ typedef int __guard __attribute__( (mode(__DI__) ) ); + + extern "C" int __cxa_guard_acquire (__guard* _g) + { + return !*(char*)(_g); + } + + extern "C" void __cxa_guard_release (__guard* _g) + { + *(char*)_g = 1; + } + + extern "C" void __cxa_guard_abort (__guard* _g) + { + BX_UNUSED(_g); + } + +} // namespace __cxxabiv1 + +#endif // BX_CRT_NONE diff --git a/3rdparty/bx/src/debug.cpp b/3rdparty/bx/src/debug.cpp index 550eef6e5f6..5e52be86e88 100644 --- a/3rdparty/bx/src/debug.cpp +++ b/3rdparty/bx/src/debug.cpp @@ -60,9 +60,11 @@ namespace bx # endif // defined(__OBJC__) #elif 0 // BX_PLATFORM_EMSCRIPTEN emscripten_log(EM_LOG_CONSOLE, "%s", _out); -#else +#elif !BX_CRT_NONE fputs(_out, stdout); fflush(stdout); +#else + BX_UNUSED(_out); #endif // BX_PLATFORM_ } diff --git a/3rdparty/bx/src/dtoa.cpp b/3rdparty/bx/src/dtoa.cpp index 05ac387fec2..98640ede20b 100644 --- a/3rdparty/bx/src/dtoa.cpp +++ b/3rdparty/bx/src/dtoa.cpp @@ -8,6 +8,8 @@ #include <bx/string.h> #include <bx/uint32_t.h> +#include <type_traits> + namespace bx { // https://github.com/miloyip/dtoa-benchmark @@ -384,7 +386,7 @@ namespace bx if (0 < kk && kk <= 21) { // 1234e-2 -> 12.34 - memmove(&buffer[kk + 1], &buffer[kk], length - kk); + memMove(&buffer[kk + 1], &buffer[kk], length - kk); buffer[kk] = '.'; buffer[length + 1] = '\0'; return length + 1; @@ -394,7 +396,7 @@ namespace bx { // 1234e-6 -> 0.001234 const int32_t offset = 2 - kk; - memmove(&buffer[offset], &buffer[0], length); + memMove(&buffer[offset], &buffer[0], length); buffer[0] = '0'; buffer[1] = '.'; for (int32_t i = 2; i < offset; i++) @@ -415,56 +417,57 @@ namespace bx } // 1234e30 -> 1.234e33 - memmove(&buffer[2], &buffer[1], length - 1); + memMove(&buffer[2], &buffer[1], length - 1); buffer[1] = '.'; buffer[length + 1] = 'e'; int32_t exp = WriteExponent(kk - 1, &buffer[length + 2]); return length + 2 + exp; } - int32_t toString(char* _dst, size_t _max, double value) + int32_t toString(char* _dst, int32_t _max, double _value) { - if (isNan(value) ) + int32_t sign = 0 != (doubleToBits(_value) & (UINT64_C(1)<<63) ) ? 1 : 0; + if (1 == sign) { - return (int32_t)strlncpy(_dst, _max, "NaN"); + *_dst++ = '-'; + --_max; + _value = -_value; } - else if (isInfinite(value) ) + + if (isNan(_value) ) { - return (int32_t)strlncpy(_dst, _max, "Inf"); + return (int32_t)strlncpy(_dst, _max, "nan") + sign; } - - int32_t sign = 0.0 > value ? 1 : 0; - if (1 == sign) + else if (isInfinite(_value) ) { - *_dst++ = '-'; - --_max; - value = -value; + return (int32_t)strlncpy(_dst, _max, "inf") + sign; } int32_t len; - if (0.0 == value) + if (0.0 == _value) { len = (int32_t)strlncpy(_dst, _max, "0.0"); } else { int32_t kk; - Grisu2(value, _dst, &len, &kk); + Grisu2(_value, _dst, &len, &kk); len = Prettify(_dst, len, kk); } return len + sign; } - static void reverse(char* _dst, size_t _len) + static void reverse(char* _dst, int32_t _len) { - for (size_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj) + for (int32_t ii = 0, jj = _len - 1; ii < jj; ++ii, --jj) { xchg(_dst[ii], _dst[jj]); } } - int32_t toString(char* _dst, size_t _max, int32_t _value, uint32_t _base) + template<typename Ty> + int32_t toStringSigned(char* _dst, int32_t _max, Ty _value, uint32_t _base) { if (_base == 10 && _value < 0) @@ -474,7 +477,11 @@ namespace bx return 0; } - _max = toString(_dst + 1, _max - 1, uint32_t(-_value), _base); + _max = toString(_dst + 1 + , _max - 1 + , typename std::make_unsigned<Ty>::type(-_value) + , _base + ); if (_max == 0) { return 0; @@ -484,13 +491,28 @@ namespace bx return int32_t(_max + 1); } - return toString(_dst, _max, uint32_t(_value), _base); + return toString(_dst + , _max + , typename std::make_unsigned<Ty>::type(_value) + , _base + ); } - int32_t toString(char* _dst, size_t _max, uint32_t _value, uint32_t _base) + int32_t toString(char* _dst, int32_t _max, int32_t _value, uint32_t _base) + { + return toStringSigned(_dst, _max, _value, _base); + } + + int32_t toString(char* _dst, int32_t _max, int64_t _value, uint32_t _base) + { + return toStringSigned(_dst, _max, _value, _base); + } + + template<typename Ty> + int32_t toStringUnsigned(char* _dst, int32_t _max, Ty _value, uint32_t _base) { char data[32]; - size_t len = 0; + int32_t len = 0; if (_base > 16 || _base < 2) @@ -500,7 +522,7 @@ namespace bx do { - const uint32_t rem = _value % _base; + const Ty rem = _value % _base; _value /= _base; if (rem < 10) { @@ -520,9 +542,19 @@ namespace bx reverse(data, len); - memcpy(_dst, data, len); + memCopy(_dst, data, len); _dst[len] = '\0'; return int32_t(len); } + int32_t toString(char* _dst, int32_t _max, uint32_t _value, uint32_t _base) + { + return toStringUnsigned(_dst, _max, _value, _base); + } + + int32_t toString(char* _dst, int32_t _max, uint64_t _value, uint32_t _base) + { + return toStringUnsigned(_dst, _max, _value, _base); + } + } // namespace bx diff --git a/3rdparty/bx/src/fpumath.cpp b/3rdparty/bx/src/fpumath.cpp index da463e08767..e957ef9e960 100644 --- a/3rdparty/bx/src/fpumath.cpp +++ b/3rdparty/bx/src/fpumath.cpp @@ -4,6 +4,7 @@ */ #include <bx/fpumath.h> +#include <math.h> namespace bx { @@ -17,7 +18,72 @@ namespace bx const float huge = HUGE_VALF; #endif // BX_COMPILER_MSVC - void mtx3Inverse(float* __restrict _result, const float* __restrict _a) + float fabsolute(float _a) + { + return ::fabsf(_a); + } + + float fsin(float _a) + { + return ::sinf(_a); + } + + float fasin(float _a) + { + return ::asinf(_a); + } + + float fcos(float _a) + { + return ::cosf(_a); + } + + float ftan(float _a) + { + return ::tanf(_a); + } + + float facos(float _a) + { + return ::acosf(_a); + } + + float fatan2(float _y, float _x) + { + return ::atan2f(_y, _x); + } + + float fpow(float _a, float _b) + { + return ::powf(_a, _b); + } + + float flog(float _a) + { + return ::logf(_a); + } + + float fsqrt(float _a) + { + return ::sqrtf(_a); + } + + float ffloor(float _f) + { + return ::floorf(_f); + } + + float fceil(float _f) + { + return ::ceilf(_f); + } + + float fmod(float _a, float _b) + { + return ::fmodf(_a, _b); + } + + void mtx3Inverse(float* _result, const float* _a) { float xx = _a[0]; float xy = _a[1]; @@ -49,7 +115,7 @@ namespace bx _result[8] = +(xx*yy - xy*yx) * invDet; } - void mtxInverse(float* __restrict _result, const float* __restrict _a) + void mtxInverse(float* _result, const float* _a) { float xx = _a[ 0]; float xy = _a[ 1]; diff --git a/3rdparty/bx/src/mutex.cpp b/3rdparty/bx/src/mutex.cpp index 00e517684e2..988084bbf0b 100644 --- a/3rdparty/bx/src/mutex.cpp +++ b/3rdparty/bx/src/mutex.cpp @@ -7,17 +7,19 @@ #if BX_CONFIG_SUPPORTS_THREADING -#if 0 \ - || BX_PLATFORM_ANDROID \ - || BX_PLATFORM_LINUX \ - || BX_PLATFORM_NACL \ - || BX_PLATFORM_IOS \ - || BX_PLATFORM_OSX +#if BX_PLATFORM_ANDROID \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_RPI # include <pthread.h> -#elif 0 \ - || BX_PLATFORM_WINDOWS \ - || BX_PLATFORM_WINRT \ - || BX_PLATFORM_XBOX360 +#elif BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE +# include <windows.h> # include <errno.h> #endif // BX_PLATFORM_ @@ -50,7 +52,7 @@ namespace bx InitializeCriticalSectionEx(_mutex, 4000, 0); // docs recommend 4000 spincount as sane default #else InitializeCriticalSection(_mutex); -#endif +#endif // BX_PLATFORM_ return 0; } @@ -63,28 +65,36 @@ namespace bx Mutex::Mutex() { + BX_STATIC_ASSERT(sizeof(pthread_mutex_t) <= sizeof(m_internal) ); + pthread_mutexattr_t attr; + #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT #else pthread_mutexattr_init(&attr); pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); -#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_WINRT - pthread_mutex_init(&m_handle, &attr); +#endif // BX_PLATFORM_ + + pthread_mutex_t* handle = (pthread_mutex_t*)m_internal; + pthread_mutex_init(handle, &attr); } Mutex::~Mutex() { - pthread_mutex_destroy(&m_handle); + pthread_mutex_t* handle = (pthread_mutex_t*)m_internal; + pthread_mutex_destroy(handle); } void Mutex::lock() { - pthread_mutex_lock(&m_handle); + pthread_mutex_t* handle = (pthread_mutex_t*)m_internal; + pthread_mutex_lock(handle); } void Mutex::unlock() { - pthread_mutex_unlock(&m_handle); + pthread_mutex_t* handle = (pthread_mutex_t*)m_internal; + pthread_mutex_unlock(handle); } } // namespace bx diff --git a/3rdparty/bx/src/os.cpp b/3rdparty/bx/src/os.cpp index 5f1d45945b7..0c7e9dc9a8e 100644 --- a/3rdparty/bx/src/os.cpp +++ b/3rdparty/bx/src/os.cpp @@ -7,7 +7,10 @@ #include <bx/uint32_t.h> #include <bx/string.h> +#if !BX_PLATFORM_NONE + #include <stdio.h> +#include <sys/stat.h> #if BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT # include <windows.h> @@ -237,7 +240,7 @@ namespace bx result = len != 0 && len < *_inOutSize; if (len < *_inOutSize) { - strcpy(_out, ptr); + strlncpy(_out, len, ptr); } } @@ -406,11 +409,11 @@ namespace bx return (void*)uintptr_t(pid); #elif BX_PLATFORM_WINDOWS STARTUPINFO si; - memset(&si, 0, sizeof(STARTUPINFO) ); + memSet(&si, 0, sizeof(STARTUPINFO) ); si.cb = sizeof(STARTUPINFO); PROCESS_INFORMATION pi; - memset(&pi, 0, sizeof(PROCESS_INFORMATION) ); + memSet(&pi, 0, sizeof(PROCESS_INFORMATION) ); int32_t total = 0; for (uint32_t ii = 0; NULL != _argv[ii]; ++ii) @@ -452,3 +455,5 @@ namespace bx } } // namespace bx + +#endif // !BX_PLATFORM_NONE diff --git a/3rdparty/bx/src/sem.cpp b/3rdparty/bx/src/semaphore.cpp index 2d3ca1574f8..b4369ff0ce6 100644 --- a/3rdparty/bx/src/sem.cpp +++ b/3rdparty/bx/src/semaphore.cpp @@ -3,35 +3,69 @@ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause */ -#include <bx/sem.h> +#include <bx/semaphore.h> #if BX_CONFIG_SUPPORTS_THREADING #if BX_PLATFORM_POSIX # include <errno.h> +# include <pthread.h> # include <semaphore.h> # include <time.h> -# include <pthread.h> -#elif BX_PLATFORM_XBOXONE -# include <synchapi.h> -#elif BX_PLATFORM_XBOX360 || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#elif BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE # include <windows.h> # include <limits.h> +# if BX_PLATFORM_XBOXONE +# include <synchapi.h> +# endif // BX_PLATFORM_XBOXONE #endif // BX_PLATFORM_ +#ifndef BX_CONFIG_SEMAPHORE_PTHREAD +# define BX_CONFIG_SEMAPHORE_PTHREAD (0 \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_IOS \ + ) +#endif // BX_CONFIG_SEMAPHORE_PTHREAD + namespace bx { + struct SemaphoreInternal + { +#if BX_PLATFORM_POSIX +# if BX_CONFIG_SEMAPHORE_PTHREAD + pthread_mutex_t m_mutex; + pthread_cond_t m_cond; + int32_t m_count; +# else + sem_t m_handle; +# endif // BX_CONFIG_SEMAPHORE_PTHREAD +#elif BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE + HANDLE m_handle; +#endif // BX_PLATFORM_ + }; + #if BX_PLATFORM_POSIX # if BX_CONFIG_SEMAPHORE_PTHREAD Semaphore::Semaphore() - : m_count(0) { + BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); + + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + si->m_count = 0; + int result; - result = pthread_mutex_init(&m_mutex, NULL); + + result = pthread_mutex_init(&si->m_mutex, NULL); BX_CHECK(0 == result, "pthread_mutex_init %d", result); - result = pthread_cond_init(&m_cond, NULL); + result = pthread_cond_init(&si->m_cond, NULL); BX_CHECK(0 == result, "pthread_cond_init %d", result); BX_UNUSED(result); @@ -39,11 +73,13 @@ namespace bx Semaphore::~Semaphore() { + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + int result; - result = pthread_cond_destroy(&m_cond); + result = pthread_cond_destroy(&si->m_cond); BX_CHECK(0 == result, "pthread_cond_destroy %d", result); - result = pthread_mutex_destroy(&m_mutex); + result = pthread_mutex_destroy(&si->m_mutex); BX_CHECK(0 == result, "pthread_mutex_destroy %d", result); BX_UNUSED(result); @@ -51,18 +87,20 @@ namespace bx void Semaphore::post(uint32_t _count) { - int result = pthread_mutex_lock(&m_mutex); + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + int result = pthread_mutex_lock(&si->m_mutex); BX_CHECK(0 == result, "pthread_mutex_lock %d", result); for (uint32_t ii = 0; ii < _count; ++ii) { - result = pthread_cond_signal(&m_cond); + result = pthread_cond_signal(&si->m_cond); BX_CHECK(0 == result, "pthread_cond_signal %d", result); } - m_count += _count; + si->m_count += _count; - result = pthread_mutex_unlock(&m_mutex); + result = pthread_mutex_unlock(&si->m_mutex); BX_CHECK(0 == result, "pthread_mutex_unlock %d", result); BX_UNUSED(result); @@ -70,24 +108,26 @@ namespace bx bool Semaphore::wait(int32_t _msecs) { - int result = pthread_mutex_lock(&m_mutex); + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + int result = pthread_mutex_lock(&si->m_mutex); BX_CHECK(0 == result, "pthread_mutex_lock %d", result); # if BX_PLATFORM_NACL || BX_PLATFORM_OSX BX_UNUSED(_msecs); BX_CHECK(-1 == _msecs, "NaCl and OSX don't support pthread_cond_timedwait at this moment."); while (0 == result - && 0 >= m_count) + && 0 >= si->m_count) { - result = pthread_cond_wait(&m_cond, &m_mutex); + result = pthread_cond_wait(&si->m_cond, &si->m_mutex); } # elif BX_PLATFORM_IOS if (-1 == _msecs) { while (0 == result - && 0 >= m_count) + && 0 >= si->m_count) { - result = pthread_cond_wait(&m_cond, &m_mutex); + result = pthread_cond_wait(&si->m_cond, &si->m_mutex); } } else @@ -97,9 +137,9 @@ namespace bx ts.tv_nsec = (_msecs%1000)*1000; while (0 == result - && 0 >= m_count) + && 0 >= si->m_count) { - result = pthread_cond_timedwait_relative_np(&m_cond, &m_mutex, &ts); + result = pthread_cond_timedwait_relative_np(&si->m_cond, &si->m_mutex, &ts); } } # else @@ -109,19 +149,19 @@ namespace bx ts.tv_nsec += (_msecs%1000)*1000; while (0 == result - && 0 >= m_count) + && 0 >= si->m_count) { - result = pthread_cond_timedwait(&m_cond, &m_mutex, &ts); + result = pthread_cond_timedwait(&si->m_cond, &si->m_mutex, &ts); } -# endif // BX_PLATFORM_NACL || BX_PLATFORM_OSX +# endif // BX_PLATFORM_ bool ok = 0 == result; if (ok) { - --m_count; + --si->m_count; } - result = pthread_mutex_unlock(&m_mutex); + result = pthread_mutex_unlock(&si->m_mutex); BX_CHECK(0 == result, "pthread_mutex_unlock %d", result); BX_UNUSED(result); @@ -133,24 +173,32 @@ namespace bx Semaphore::Semaphore() { - int32_t result = sem_init(&m_handle, 0, 0); + BX_STATIC_ASSERT(sizeof(SemaphoreInternal) <= sizeof(m_internal) ); + + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + int32_t result = sem_init(&si->m_handle, 0, 0); BX_CHECK(0 == result, "sem_init failed. errno %d", errno); BX_UNUSED(result); } Semaphore::~Semaphore() { - int32_t result = sem_destroy(&m_handle); + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + int32_t result = sem_destroy(&si->m_handle); BX_CHECK(0 == result, "sem_destroy failed. errno %d", errno); BX_UNUSED(result); } void Semaphore::post(uint32_t _count) { + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + int32_t result; for (uint32_t ii = 0; ii < _count; ++ii) { - result = sem_post(&m_handle); + result = sem_post(&si->m_handle); BX_CHECK(0 == result, "sem_post failed. errno %d", errno); } BX_UNUSED(result); @@ -158,16 +206,18 @@ namespace bx bool Semaphore::wait(int32_t _msecs) { + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + # if BX_PLATFORM_NACL || BX_PLATFORM_OSX BX_CHECK(-1 == _msecs, "NaCl and OSX don't support sem_timedwait at this moment."); BX_UNUSED(_msecs); - return 0 == sem_wait(&m_handle); + return 0 == sem_wait(&si->m_handle); # else if (0 > _msecs) { int32_t result; do { - result = sem_wait(&m_handle); + result = sem_wait(&si->m_handle); } // keep waiting when interrupted by a signal handler... while (-1 == result && EINTR == errno); BX_CHECK(0 == result, "sem_wait failed. errno %d", errno); @@ -178,40 +228,51 @@ namespace bx clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += _msecs/1000; ts.tv_nsec += (_msecs%1000)*1000; - return 0 == sem_timedwait(&m_handle, &ts); + return 0 == sem_timedwait(&si->m_handle, &ts); # endif // BX_PLATFORM_ } # endif // BX_CONFIG_SEMAPHORE_PTHREAD -#elif BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINDOWS || BX_PLATFORM_WINRT +#elif BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE Semaphore::Semaphore() { + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + #if BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - m_handle = CreateSemaphoreExW(NULL, 0, LONG_MAX, NULL, 0, SEMAPHORE_ALL_ACCESS); + si->m_handle = CreateSemaphoreExW(NULL, 0, LONG_MAX, NULL, 0, SEMAPHORE_ALL_ACCESS); #else - m_handle = CreateSemaphoreA(NULL, 0, LONG_MAX, NULL); + si->m_handle = CreateSemaphoreA(NULL, 0, LONG_MAX, NULL); #endif - BX_CHECK(NULL != m_handle, "Failed to create Semaphore!"); + BX_CHECK(NULL != si->m_handle, "Failed to create Semaphore!"); } Semaphore::~Semaphore() { - CloseHandle(m_handle); + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + CloseHandle(si->m_handle); } void Semaphore::post(uint32_t _count) { - ReleaseSemaphore(m_handle, _count, NULL); + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + + ReleaseSemaphore(si->m_handle, _count, NULL); } bool Semaphore::wait(int32_t _msecs) { + SemaphoreInternal* si = (SemaphoreInternal*)m_internal; + DWORD milliseconds = (0 > _msecs) ? INFINITE : _msecs; #if BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - return WAIT_OBJECT_0 == WaitForSingleObjectEx(m_handle, milliseconds, FALSE); + return WAIT_OBJECT_0 == WaitForSingleObjectEx(si->m_handle, milliseconds, FALSE); #else - return WAIT_OBJECT_0 == WaitForSingleObject(m_handle, milliseconds); + return WAIT_OBJECT_0 == WaitForSingleObject(si->m_handle, milliseconds); #endif } #endif // BX_PLATFORM_ diff --git a/3rdparty/bx/src/sort.cpp b/3rdparty/bx/src/sort.cpp new file mode 100644 index 00000000000..3b7485fe7fe --- /dev/null +++ b/3rdparty/bx/src/sort.cpp @@ -0,0 +1,55 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include <bx/sort.h> + +namespace bx +{ + static void quickSortR(void* _pivot, void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn) + { + if (2 > _num) + { + return; + } + + memCopy(_pivot, _data, _stride); + + uint8_t* data = (uint8_t*)_data; + + uint32_t ll = 0; + uint32_t gg = 1; + + for (uint32_t ii = 1; ii < _num;) + { + int32_t result = _fn(&data[ii*_stride], _pivot); + if (0 > result) + { + xchg(&data[ll*_stride], &data[ii*_stride], _stride); + ++ll; + } + else if (0 == result) + { + xchg(&data[gg*_stride], &data[ii*_stride], _stride); + ++gg; + ++ii; + } + else + { + ++ii; + } + } + + quickSortR(_pivot, &data[0 ], ll, _stride, _fn); + quickSortR(_pivot, &data[gg*_stride], _num-gg, _stride, _fn); + } + + void quickSort(void* _data, uint32_t _num, uint32_t _stride, const ComparisonFn _fn) + { + uint8_t* pivot = (uint8_t*)alloca(_stride); + quickSortR(pivot, _data, _num, _stride, _fn); + } + +} // namespace bx + diff --git a/3rdparty/bx/src/string.cpp b/3rdparty/bx/src/string.cpp index c53a9de1155..dbb59e5090a 100644 --- a/3rdparty/bx/src/string.cpp +++ b/3rdparty/bx/src/string.cpp @@ -60,21 +60,57 @@ namespace bx return _ch + (isUpper(_ch) ? 0x20 : 0); } + void toLowerUnsafe(char* _inOutStr, int32_t _len) + { + for (int32_t ii = 0; ii < _len; ++ii) + { + *_inOutStr = toLower(*_inOutStr); + } + } + + void toLower(char* _inOutStr, int32_t _max) + { + const int32_t len = strnlen(_inOutStr, _max); + toLowerUnsafe(_inOutStr, len); + } + char toUpper(char _ch) { return _ch - (isLower(_ch) ? 0x20 : 0); } + void toUpperUnsafe(char* _inOutStr, int32_t _len) + { + for (int32_t ii = 0; ii < _len; ++ii) + { + *_inOutStr = toUpper(*_inOutStr); + } + } + + void toUpper(char* _inOutStr, int32_t _max) + { + const int32_t len = strnlen(_inOutStr, _max); + toUpperUnsafe(_inOutStr, len); + } + bool toBool(const char* _str) { char ch = toLower(_str[0]); return ch == 't' || ch == '1'; } - int32_t strncmp(const char* _lhs, const char* _rhs, size_t _max) + typedef char (*CharFn)(char _ch); + + inline char toNoop(char _ch) + { + return _ch; + } + + template<CharFn fn> + int32_t strCmp(const char* _lhs, const char* _rhs, int32_t _max) { for ( - ; 0 < _max && *_lhs == *_rhs + ; 0 < _max && fn(*_lhs) == fn(*_rhs) ; ++_lhs, ++_rhs, --_max ) { @@ -85,62 +121,60 @@ namespace bx } } - return 0 == _max ? 0 : *_lhs - *_rhs; + return 0 == _max ? 0 : fn(*_lhs) - fn(*_rhs); } - int32_t strincmp(const char* _lhs, const char* _rhs, size_t _max) + int32_t strncmp(const char* _lhs, const char* _rhs, int32_t _max) { - for ( - ; 0 < _max && toLower(*_lhs) == toLower(*_rhs) - ; ++_lhs, ++_rhs, --_max - ) - { - if (*_lhs == '\0' - || *_rhs == '\0') - { - break; - } - } + return strCmp<toNoop>(_lhs, _rhs, _max); + } - return 0 == _max ? 0 : *_lhs - *_rhs; + int32_t strincmp(const char* _lhs, const char* _rhs, int32_t _max) + { + return strCmp<toLower>(_lhs, _rhs, _max); } - size_t strnlen(const char* _str, size_t _max) + int32_t strnlen(const char* _str, int32_t _max) { - const char* ptr; - for (ptr = _str; 0 < _max && *ptr != '\0'; ++ptr, --_max) {}; - return ptr - _str; + if (NULL == _str) + { + return 0; + } + + const char* ptr = _str; + for (; 0 < _max && *ptr != '\0'; ++ptr, --_max) {}; + return int32_t(ptr - _str); } - size_t strlncpy(char* _dst, size_t _dstSize, const char* _src, size_t _num) + int32_t strlncpy(char* _dst, int32_t _dstSize, const char* _src, int32_t _num) { BX_CHECK(NULL != _dst, "_dst can't be NULL!"); BX_CHECK(NULL != _src, "_src can't be NULL!"); BX_CHECK(0 < _dstSize, "_dstSize can't be 0!"); - const size_t len = strnlen(_src, _num); - const size_t max = _dstSize-1; - const size_t num = (len < max ? len : max); - memcpy(_dst, _src, num); + const int32_t len = strnlen(_src, _num); + const int32_t max = _dstSize-1; + const int32_t num = (len < max ? len : max); + memCopy(_dst, _src, num); _dst[num] = '\0'; return num; } - size_t strlncat(char* _dst, size_t _dstSize, const char* _src, size_t _num) + int32_t strlncat(char* _dst, int32_t _dstSize, const char* _src, int32_t _num) { BX_CHECK(NULL != _dst, "_dst can't be NULL!"); BX_CHECK(NULL != _src, "_src can't be NULL!"); BX_CHECK(0 < _dstSize, "_dstSize can't be 0!"); - const size_t max = _dstSize; - const size_t len = strnlen(_dst, max); + const int32_t max = _dstSize; + const int32_t len = strnlen(_dst, max); return strlncpy(&_dst[len], max-len, _src, _num); } - const char* strnchr(const char* _str, char _ch, size_t _max) + const char* strnchr(const char* _str, char _ch, int32_t _max) { - for (size_t ii = 0, len = strnlen(_str, _max); ii < len; ++ii) + for (int32_t ii = 0, len = strnlen(_str, _max); ii < len; ++ii) { if (_str[ii] == _ch) { @@ -151,9 +185,9 @@ namespace bx return NULL; } - const char* strnrchr(const char* _str, char _ch, size_t _max) + const char* strnrchr(const char* _str, char _ch, int32_t _max) { - for (size_t ii = strnlen(_str, _max); 0 < ii; --ii) + for (int32_t ii = strnlen(_str, _max); 0 < ii; --ii) { if (_str[ii] == _ch) { @@ -164,17 +198,18 @@ namespace bx return NULL; } - const char* strnstr(const char* _str, const char* _find, size_t _max) + template<CharFn fn> + static const char* strStr(const char* _str, int32_t _strMax, const char* _find, int32_t _findMax) { const char* ptr = _str; - size_t stringLen = strnlen(_str, _max); - const size_t findLen = strnlen(_find); + int32_t stringLen = strnlen(_str, _strMax); + const int32_t findLen = strnlen(_find, _findMax); for (; stringLen >= findLen; ++ptr, --stringLen) { // Find start of the string. - while (*ptr != *_find) + while (fn(*ptr) != fn(*_find) ) { ++ptr; --stringLen; @@ -191,7 +226,7 @@ namespace bx const char* search = _find; // Start comparing. - while (*string++ == *search++) + while (fn(*string++) == fn(*search++) ) { // If end of the 'search' string is reached, all characters match. if ('\0' == *search) @@ -204,44 +239,14 @@ namespace bx return NULL; } - const char* stristr(const char* _str, const char* _find, size_t _max) + const char* strnstr(const char* _str, const char* _find, int32_t _max) { - const char* ptr = _str; - - size_t stringLen = strnlen(_str, _max); - const size_t findLen = strnlen(_find); - - for (; stringLen >= findLen; ++ptr, --stringLen) - { - // Find start of the string. - while (toLower(*ptr) != toLower(*_find) ) - { - ++ptr; - --stringLen; - - // Search pattern lenght can't be longer than the string. - if (findLen > stringLen) - { - return NULL; - } - } - - // Set pointers. - const char* string = ptr; - const char* search = _find; - - // Start comparing. - while (toLower(*string++) == toLower(*search++) ) - { - // If end of the 'search' string is reached, all characters match. - if ('\0' == *search) - { - return ptr; - } - } - } + return strStr<toNoop>(_str, _max, _find, INT32_MAX); + } - return NULL; + const char* stristr(const char* _str, const char* _find, int32_t _max) + { + return strStr<toLower>(_str, _max, _find, INT32_MAX); } const char* strnl(const char* _str) @@ -324,7 +329,7 @@ namespace bx return NULL; } - void eolLF(char* _out, size_t _size, const char* _str) + void eolLF(char* _out, int32_t _size, const char* _str) { if (0 < _size) { @@ -343,7 +348,7 @@ namespace bx const char* findIdentifierMatch(const char* _str, const char* _word) { - size_t len = strnlen(_word); + int32_t len = strnlen(_word); const char* ptr = strnstr(_str, _word); for (; NULL != ptr; ptr = strnstr(ptr + len, _word) ) { @@ -382,13 +387,422 @@ namespace bx return NULL; } - int32_t write(WriterI* _writer, const char* _format, va_list _argList, Error* _err); + namespace + { + struct Param + { + Param() + : width(0) + , base(10) + , prec(6) + , fill(' ') + , bits(0) + , left(false) + , upper(false) + , spec(false) + , sign(false) + { + } + + int32_t width; + uint32_t base; + uint32_t prec; + char fill; + uint8_t bits; + bool left; + bool upper; + bool spec; + bool sign; + }; + + static int32_t write(WriterI* _writer, const char* _str, int32_t _len, const Param& _param, Error* _err) + { + int32_t size = 0; + int32_t len = (int32_t)strnlen(_str, _len); + int32_t padding = _param.width > len ? _param.width - len : 0; + bool sign = _param.sign && len > 1 && _str[0] != '-'; + padding = padding > 0 ? padding - sign : 0; + + if (!_param.left) + { + size += writeRep(_writer, _param.fill, padding, _err); + } + + if (NULL == _str) + { + size += write(_writer, "(null)", 6, _err); + } + else if (_param.upper) + { + for (int32_t ii = 0; ii < len; ++ii) + { + size += write(_writer, toUpper(_str[ii]), _err); + } + } + else if (sign) + { + size += write(_writer, '+', _err); + size += write(_writer, _str, len, _err); + } + else + { + size += write(_writer, _str, len, _err); + } + + if (_param.left) + { + size += writeRep(_writer, _param.fill, padding, _err); + } + + return size; + } + + static int32_t write(WriterI* _writer, char _ch, const Param& _param, Error* _err) + { + return write(_writer, &_ch, 1, _param, _err); + } + + static int32_t write(WriterI* _writer, const char* _str, const Param& _param, Error* _err) + { + return write(_writer, _str, INT32_MAX, _param, _err); + } + + static int32_t write(WriterI* _writer, int32_t _i, const Param& _param, Error* _err) + { + char str[33]; + int32_t len = toString(str, sizeof(str), _i, _param.base); + + if (len == 0) + { + return 0; + } + + return write(_writer, str, len, _param, _err); + } + + static int32_t write(WriterI* _writer, int64_t _i, const Param& _param, Error* _err) + { + char str[33]; + int32_t len = toString(str, sizeof(str), _i, _param.base); + + if (len == 0) + { + return 0; + } + + return write(_writer, str, len, _param, _err); + } + + static int32_t write(WriterI* _writer, uint32_t _u, const Param& _param, Error* _err) + { + char str[33]; + int32_t len = toString(str, sizeof(str), _u, _param.base); + + if (len == 0) + { + return 0; + } + + return write(_writer, str, len, _param, _err); + } + + static int32_t write(WriterI* _writer, uint64_t _u, const Param& _param, Error* _err) + { + char str[33]; + int32_t len = toString(str, sizeof(str), _u, _param.base); + + if (len == 0) + { + return 0; + } + + return write(_writer, str, len, _param, _err); + } + + static int32_t write(WriterI* _writer, double _d, const Param& _param, Error* _err) + { + char str[1024]; + int32_t len = toString(str, sizeof(str), _d); + + if (len == 0) + { + return 0; + } + + if (_param.upper) + { + toUpperUnsafe(str, len); + } + + const char* dot = strnchr(str, '.'); + if (NULL != dot) + { + const int32_t precLen = int32_t( + dot + + uint32_min(_param.prec + _param.spec, 1) + + _param.prec + - str + ); + if (precLen > len) + { + for (int32_t ii = len; ii < precLen; ++ii) + { + str[ii] = '0'; + } + str[precLen] = '\0'; + } + len = precLen; + } + + return write(_writer, str, len, _param, _err); + } + + static int32_t write(WriterI* _writer, const void* _ptr, const Param& _param, Error* _err) + { + char str[35] = "0x"; + int32_t len = toString(str + 2, sizeof(str) - 2, uint32_t(uintptr_t(_ptr) ), 16); + + if (len == 0) + { + return 0; + } + + len += 2; + return write(_writer, str, len, _param, _err); + } + } // anonymous namespace + + int32_t write(WriterI* _writer, const char* _format, va_list _argList, Error* _err) + { + MemoryReader reader(_format, uint32_t(strnlen(_format) ) ); + + int32_t size = 0; + + while (_err->isOk() ) + { + char ch = '\0'; + + Error err; + read(&reader, ch, &err); + + if (!_err->isOk() + || !err.isOk() ) + { + break; + } + else if ('%' == ch) + { + // %[flags][width][.precision][length sub-specifier]specifier + read(&reader, ch); + + Param param; + + // flags + while (' ' == ch + || '-' == ch + || '+' == ch + || '0' == ch + || '#' == ch) + { + switch (ch) + { + default: + case ' ': param.fill = ' '; break; + case '-': param.left = true; break; + case '+': param.sign = true; break; + case '0': param.fill = '0'; break; + case '#': param.spec = true; break; + } + + read(&reader, ch); + } + + if (param.left) + { + param.fill = ' '; + } + + // width + if ('*' == ch) + { + read(&reader, ch); + param.width = va_arg(_argList, int32_t); + + if (0 > param.width) + { + param.left = true; + param.width = -param.width; + } + + } + else + { + while (isNumeric(ch) ) + { + param.width = param.width * 10 + ch - '0'; + read(&reader, ch); + } + } + + // .precision + if ('.' == ch) + { + read(&reader, ch); + + if ('*' == ch) + { + read(&reader, ch); + param.prec = va_arg(_argList, int32_t); + } + else + { + param.prec = 0; + while (isNumeric(ch) ) + { + param.prec = param.prec * 10 + ch - '0'; + read(&reader, ch); + } + } + } + + // length sub-specifier + while ('h' == ch + || 'I' == ch + || 'l' == ch + || 'j' == ch + || 't' == ch + || 'z' == ch) + { + switch (ch) + { + default: break; + + case 'j': param.bits = sizeof(intmax_t )*8; break; + case 't': param.bits = sizeof(size_t )*8; break; + case 'z': param.bits = sizeof(ptrdiff_t)*8; break; + + case 'h': case 'I': case 'l': + switch (ch) + { + case 'h': param.bits = sizeof(short int)*8; break; + case 'l': param.bits = sizeof(long int )*8; break; + default: break; + } + + read(&reader, ch); + switch (ch) + { + case 'h': param.bits = sizeof(signed char )*8; break; + case 'l': param.bits = sizeof(long long int)*8; break; + case '3': + case '6': + read(&reader, ch); + switch (ch) + { + case '2': param.bits = sizeof(int32_t)*8; break; + case '4': param.bits = sizeof(int64_t)*8; break; + default: break; + } + break; + + default: seek(&reader, -1); break; + } + break; + } + + read(&reader, ch); + } + + // specifier + switch (toLower(ch) ) + { + case 'c': + size += write(_writer, char(va_arg(_argList, int32_t) ), param, _err); + break; + + case 's': + size += write(_writer, va_arg(_argList, const char*), param, _err); + break; + + case 'o': + param.base = 8; + switch (param.bits) + { + default: size += write(_writer, va_arg(_argList, int32_t), param, _err); break; + case 64: size += write(_writer, va_arg(_argList, int64_t), param, _err); break; + } + break; + + case 'i': + case 'd': + param.base = 10; + switch (param.bits) + { + default: size += write(_writer, va_arg(_argList, int32_t), param, _err); break; + case 64: size += write(_writer, va_arg(_argList, int64_t), param, _err); break; + }; + break; + + case 'e': + case 'f': + case 'g': + param.upper = isUpper(ch); + size += write(_writer, va_arg(_argList, double), param, _err); + break; + + case 'p': + size += write(_writer, va_arg(_argList, void*), param, _err); + break; + + case 'x': + param.base = 16; + param.upper = isUpper(ch); + switch (param.bits) + { + default: size += write(_writer, va_arg(_argList, uint32_t), param, _err); break; + case 64: size += write(_writer, va_arg(_argList, uint64_t), param, _err); break; + } + break; + + case 'u': + param.base = 10; + switch (param.bits) + { + default: size += write(_writer, va_arg(_argList, uint32_t), param, _err); break; + case 64: size += write(_writer, va_arg(_argList, uint64_t), param, _err); break; + } + break; + + default: + size += write(_writer, ch, _err); + break; + } + } + else + { + size += write(_writer, ch, _err); + } + } + + size += write(_writer, '\0', _err); + + return size; + } + + int32_t write(WriterI* _writer, Error* _err, const char* _format, ...) + { + va_list argList; + va_start(argList, _format); + int32_t size = write(_writer, _format, argList, _err); + va_end(argList); + return size; + } - int32_t vsnprintfRef(char* _out, size_t _max, const char* _format, va_list _argList) + int32_t vsnprintfRef(char* _out, int32_t _max, const char* _format, va_list _argList) { if (1 < _max) { - StaticMemoryBlockWriter writer(_out, _max-1); + StaticMemoryBlockWriter writer(_out, uint32_t(_max-1) ); _out[_max-1] = '\0'; Error err; @@ -413,7 +827,7 @@ namespace bx return size - 1 /* size without '\0' terminator */; } - int32_t vsnprintf(char* _out, size_t _max, const char* _format, va_list _argList) + int32_t vsnprintf(char* _out, int32_t _max, const char* _format, va_list _argList) { #if BX_CRT_NONE return vsnprintfRef(_out, _max, _format, _argList); @@ -432,7 +846,7 @@ namespace bx #endif // BX_COMPILER_MSVC } - int32_t snprintf(char* _out, size_t _max, const char* _format, ...) + int32_t snprintf(char* _out, int32_t _max, const char* _format, ...) { va_list argList; va_start(argList, _format); @@ -441,7 +855,7 @@ namespace bx return len; } - int32_t vsnwprintf(wchar_t* _out, size_t _max, const wchar_t* _format, va_list _argList) + int32_t vsnwprintf(wchar_t* _out, int32_t _max, const wchar_t* _format, va_list _argList) { #if BX_CRT_NONE BX_UNUSED(_out, _max, _format, _argList); @@ -463,7 +877,7 @@ namespace bx #endif // BX_COMPILER_MSVC } - int32_t swnprintf(wchar_t* _out, size_t _max, const wchar_t* _format, ...) + int32_t swnprintf(wchar_t* _out, int32_t _max, const wchar_t* _format, ...) { va_list argList; va_start(argList, _format); @@ -487,7 +901,7 @@ namespace bx return _filePath; } - void prettify(char* _out, size_t _count, uint64_t _size) + void prettify(char* _out, int32_t _count, uint64_t _size) { uint8_t idx = 0; double size = double(_size); @@ -502,12 +916,12 @@ namespace bx snprintf(_out, _count, "%0.2f %c%c", size, "BkMGTPEZY"[idx], idx > 0 ? 'B' : '\0'); } - size_t strlcpy(char* _dst, const char* _src, size_t _max) + int32_t strlcpy(char* _dst, const char* _src, int32_t _max) { return strlncpy(_dst, _max, _src); } - size_t strlcat(char* _dst, const char* _src, size_t _max) + int32_t strlcat(char* _dst, const char* _src, int32_t _max) { return strlncat(_dst, _max, _src); } diff --git a/3rdparty/bx/src/thread.cpp b/3rdparty/bx/src/thread.cpp index fea7e8b606c..70ea4a0ecbe 100644 --- a/3rdparty/bx/src/thread.cpp +++ b/3rdparty/bx/src/thread.cpp @@ -5,24 +5,94 @@ #include <bx/thread.h> +#if BX_PLATFORM_ANDROID \ + || BX_PLATFORM_LINUX \ + || BX_PLATFORM_NACL \ + || BX_PLATFORM_IOS \ + || BX_PLATFORM_OSX \ + || BX_PLATFORM_PS4 \ + || BX_PLATFORM_RPI +# include <pthread.h> +# if defined(__FreeBSD__) +# include <pthread_np.h> +# endif +# if BX_PLATFORM_LINUX && (BX_CRT_GLIBC < 21200) +# include <sys/prctl.h> +# endif // BX_PLATFORM_ +#elif BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE +# include <windows.h> +# include <limits.h> +# include <errno.h> +# if BX_PLATFORM_WINRT +using namespace Platform; +using namespace Windows::Foundation; +using namespace Windows::System::Threading; +# endif // BX_PLATFORM_WINRT +#endif // BX_PLATFORM_ + #if BX_CONFIG_SUPPORTS_THREADING namespace bx { - Thread::Thread() -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - : m_handle(INVALID_HANDLE_VALUE) - , m_threadId(UINT32_MAX) + struct ThreadInternal + { +#if BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE + static DWORD WINAPI threadFunc(LPVOID _arg); + HANDLE m_handle; + DWORD m_threadId; #elif BX_PLATFORM_POSIX - : m_handle(0) + static void* threadFunc(void* _arg); + pthread_t m_handle; +#endif // BX_PLATFORM_ + }; + +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT + DWORD WINAPI ThreadInternal::threadFunc(LPVOID _arg) + { + Thread* thread = (Thread*)_arg; + int32_t result = thread->entry(); + return result; + } +#else + void* ThreadInternal::threadFunc(void* _arg) + { + Thread* thread = (Thread*)_arg; + union + { + void* ptr; + int32_t i; + } cast; + cast.i = thread->entry(); + return cast.ptr; + } #endif // BX_PLATFORM_ - , m_fn(NULL) + + Thread::Thread() + : m_fn(NULL) , m_userData(NULL) , m_stackSize(0) , m_exitCode(0 /*EXIT_SUCCESS*/) , m_running(false) - { - } + { + BX_STATIC_ASSERT(sizeof(ThreadInternal) <= sizeof(m_internal) ); + + ThreadInternal* ti = (ThreadInternal*)m_internal; +#if BX_PLATFORM_WINDOWS \ + || BX_PLATFORM_WINRT \ + || BX_PLATFORM_XBOX360 \ + || BX_PLATFORM_XBOXONE + ti->m_handle = INVALID_HANDLE_VALUE; + ti->m_threadId = UINT32_MAX; +#elif BX_PLATFORM_POSIX + ti->m_handle = 0; +#endif // BX_PLATFORM_ + } Thread::~Thread() { @@ -41,21 +111,24 @@ namespace bx m_stackSize = _stackSize; m_running = true; + ThreadInternal* ti = (ThreadInternal*)m_internal; #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE - m_handle = ::CreateThread(NULL + ti->m_handle = ::CreateThread(NULL , m_stackSize - , (LPTHREAD_START_ROUTINE)threadFunc + , (LPTHREAD_START_ROUTINE)ti->threadFunc , this , 0 , NULL ); #elif BX_PLATFORM_WINRT - m_handle = CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS); + ti->m_handle = CreateEventEx(nullptr, nullptr, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS); auto workItemHandler = ref new WorkItemHandler([=](IAsyncAction^) - { - m_exitCode = threadFunc(this); - SetEvent(m_handle); - }, CallbackContext::Any); + { + m_exitCode = ti->threadFunc(this); + SetEvent(ti->m_handle); + } + , CallbackContext::Any + ); ThreadPool::RunAsync(workItemHandler, WorkItemPriority::Normal, WorkItemOptions::TimeSliced); #elif BX_PLATFORM_POSIX @@ -72,12 +145,7 @@ namespace bx BX_CHECK(0 == result, "pthread_attr_setstacksize failed! %d", result); } - // sched_param sched; - // sched.sched_priority = 0; - // result = pthread_attr_setschedparam(&attr, &sched); - // BX_CHECK(0 == result, "pthread_attr_setschedparam failed! %d", result); - - result = pthread_create(&m_handle, &attr, &threadFunc, this); + result = pthread_create(&ti->m_handle, &attr, &ti->threadFunc, this); BX_CHECK(0 == result, "pthread_attr_setschedparam failed! %d", result); #else # error "Not implemented!" @@ -94,25 +162,27 @@ namespace bx void Thread::shutdown() { BX_CHECK(m_running, "Not running!"); + ThreadInternal* ti = (ThreadInternal*)m_internal; #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 - WaitForSingleObject(m_handle, INFINITE); - GetExitCodeThread(m_handle, (DWORD*)&m_exitCode); - CloseHandle(m_handle); - m_handle = INVALID_HANDLE_VALUE; -#elif BX_PLATFORM_WINRT - WaitForSingleObjectEx(m_handle, INFINITE, FALSE); - CloseHandle(m_handle); - m_handle = INVALID_HANDLE_VALUE; + WaitForSingleObject(ti->m_handle, INFINITE); + GetExitCodeThread(ti->m_handle, (DWORD*)&m_exitCode); + CloseHandle(ti->m_handle); + ti->m_handle = INVALID_HANDLE_VALUE; +#elif BX_PLATFORM_WINRT || BX_PLATFORM_XBOXONE + WaitForSingleObjectEx(ti->m_handle, INFINITE, FALSE); + CloseHandle(ti->m_handle); + ti->m_handle = INVALID_HANDLE_VALUE; #elif BX_PLATFORM_POSIX union { void* ptr; int32_t i; } cast; - pthread_join(m_handle, &cast.ptr); + pthread_join(ti->m_handle, &cast.ptr); m_exitCode = cast.i; - m_handle = 0; + ti->m_handle = 0; #endif // BX_PLATFORM_ + m_running = false; } @@ -128,17 +198,19 @@ namespace bx void Thread::setThreadName(const char* _name) { + ThreadInternal* ti = (ThreadInternal*)m_internal; + BX_UNUSED(ti); #if BX_PLATFORM_OSX || BX_PLATFORM_IOS pthread_setname_np(_name); #elif (BX_CRT_GLIBC >= 21200) && ! BX_PLATFORM_HURD - pthread_setname_np(m_handle, _name); + pthread_setname_np(ti->m_handle, _name); #elif BX_PLATFORM_LINUX prctl(PR_SET_NAME,_name, 0, 0, 0); #elif BX_PLATFORM_BSD # ifdef __NetBSD__ - pthread_setname_np(m_handle, "%s", (void*)_name); + pthread_setname_np(ti->m_handle, "%s", (void*)_name); # else - pthread_set_name_np(m_handle, _name); + pthread_set_name_np(ti->m_handle, _name); # endif // __NetBSD__ #elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC # pragma pack(push, 8) @@ -153,7 +225,7 @@ namespace bx ThreadName tn; tn.type = 0x1000; tn.name = _name; - tn.id = m_threadId; + tn.id = ti->m_threadId; tn.flags = 0; __try @@ -175,33 +247,83 @@ namespace bx int32_t Thread::entry() { #if BX_PLATFORM_WINDOWS - m_threadId = ::GetCurrentThreadId(); + ThreadInternal* ti = (ThreadInternal*)m_internal; + ti->m_threadId = ::GetCurrentThreadId(); #endif // BX_PLATFORM_WINDOWS m_sem.post(); return m_fn(m_userData); } -#if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT - DWORD WINAPI Thread::threadFunc(LPVOID _arg) + struct TlsDataInternal { - Thread* thread = (Thread*)_arg; - int32_t result = thread->entry(); - return result; +#if BX_PLATFORM_WINDOWS + uint32_t m_id; +#elif !(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) + pthread_key_t m_id; +#endif // BX_PLATFORM_* + }; + +#if BX_PLATFORM_WINDOWS + TlsData::TlsData() + { + BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) ); + + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + ti->m_id = TlsAlloc(); + BX_CHECK(TLS_OUT_OF_INDEXES != ti->m_id, "Failed to allocated TLS index (err: 0x%08x).", GetLastError() ); } -#else - void* Thread::threadFunc(void* _arg) + + TlsData::~TlsData() { - Thread* thread = (Thread*)_arg; - union - { - void* ptr; - int32_t i; - } cast; - cast.i = thread->entry(); - return cast.ptr; + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + BOOL result = TlsFree(ti->m_id); + BX_CHECK(0 != result, "Failed to free TLS index (err: 0x%08x).", GetLastError() ); BX_UNUSED(result); } -#endif // BX_PLATFORM_ + + void* TlsData::get() const + { + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + return TlsGetValue(ti->m_id); + } + + void TlsData::set(void* _ptr) + { + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + TlsSetValue(ti->m_id, _ptr); + } + +#elif !(BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT) + + TlsData::TlsData() + { + BX_STATIC_ASSERT(sizeof(TlsDataInternal) <= sizeof(m_internal) ); + + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + int result = pthread_key_create(&ti->m_id, NULL); + BX_CHECK(0 == result, "pthread_key_create failed %d.", result); BX_UNUSED(result); + } + + TlsData::~TlsData() + { + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + int result = pthread_key_delete(ti->m_id); + BX_CHECK(0 == result, "pthread_key_delete failed %d.", result); BX_UNUSED(result); + } + + void* TlsData::get() const + { + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + return pthread_getspecific(ti->m_id); + } + + void TlsData::set(void* _ptr) + { + TlsDataInternal* ti = (TlsDataInternal*)m_internal; + int result = pthread_setspecific(ti->m_id, _ptr); + BX_CHECK(0 == result, "pthread_setspecific failed %d.", result); BX_UNUSED(result); + } +#endif // BX_PLATFORM_* } // namespace bx diff --git a/3rdparty/bx/include/bx/timer.inl b/3rdparty/bx/src/timer.cpp index d1c609f571a..7f5403749d9 100644 --- a/3rdparty/bx/include/bx/timer.inl +++ b/3rdparty/bx/src/timer.cpp @@ -3,11 +3,7 @@ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause */ -#ifndef BX_TIMER_H_HEADER_GUARD -# error "Must be included from bx/timer.h!" -#endif // BX_TIMER_H_HEADER_GUARD - -#include "bx.h" +#include <bx/timer.h> #if BX_PLATFORM_ANDROID # include <time.h> // clock, clock_gettime @@ -21,7 +17,7 @@ namespace bx { - inline int64_t getHPCounter() + int64_t getHPCounter() { #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT LARGE_INTEGER li; @@ -35,15 +31,18 @@ namespace bx int64_t i64 = now.tv_sec*INT64_C(1000000000) + now.tv_nsec; #elif BX_PLATFORM_EMSCRIPTEN int64_t i64 = int64_t(1000.0f * emscripten_get_now() ); -#else +#elif !BX_PLATFORM_NONE struct timeval now; gettimeofday(&now, 0); int64_t i64 = now.tv_sec*INT64_C(1000000) + now.tv_usec; +#else + BX_CHECK(false, "Not implemented!"); + int64_t i64 = UINT64_MAX; #endif // BX_PLATFORM_ return i64; } - inline int64_t getHPFrequency() + int64_t getHPFrequency() { #if BX_PLATFORM_WINDOWS || BX_PLATFORM_XBOX360 || BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT LARGE_INTEGER li; diff --git a/3rdparty/bx/tests/crt_test.cpp b/3rdparty/bx/tests/crt_test.cpp new file mode 100644 index 00000000000..6820c0f8a43 --- /dev/null +++ b/3rdparty/bx/tests/crt_test.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include "test.h" + +TEST_CASE("memSet", "") +{ + char temp[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }; + + bx::memSet(temp, 0, 0); + REQUIRE(temp[0] == 1); + + bx::memSet(temp, 0, 5); + REQUIRE(temp[0] == 0); + REQUIRE(temp[1] == 0); + REQUIRE(temp[2] == 0); + REQUIRE(temp[3] == 0); + REQUIRE(temp[4] == 0); + REQUIRE(temp[5] == 6); +} + +TEST_CASE("memMove", "") +{ + const char* orignal = "xxxxabvgd"; + char str[] = { 'x', 'x', 'x', 'x', 'a', 'b', 'v', 'g', 'd' }; + + bx::memMove(&str[4], &str[4], 0); + REQUIRE(0 == bx::memCmp(str, orignal, 9) ); + + bx::memMove(&str[4], &str[4], 5); + REQUIRE(0 == bx::memCmp(str, orignal, 9) ); + + bx::memMove(str, &str[4], 5); + REQUIRE(0 == bx::memCmp(str, "abvgd", 5) ); + + bx::memMove(&str[4], str, 5); + REQUIRE(str[4] == 'a' ); + + bx::memSet(str, 'x', 4); + REQUIRE(0 == bx::memCmp(str, orignal, 9) ); +} diff --git a/3rdparty/bx/tests/handle_bench.cpp b/3rdparty/bx/tests/handle_bench.cpp index 6169bc45c53..e8d8bee11cf 100644 --- a/3rdparty/bx/tests/handle_bench.cpp +++ b/3rdparty/bx/tests/handle_bench.cpp @@ -1,4 +1,8 @@ -#include <bx/bx.h> +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + #include <bx/timer.h> #include <bx/handlealloc.h> #include <bx/maputil.h> @@ -99,5 +103,8 @@ int main() printf("HandleHashMap: %15f\n", double(elapsed) ); } + extern void simd_bench(); + simd_bench(); + return EXIT_SUCCESS; } diff --git a/3rdparty/bx/tests/handle_test.cpp b/3rdparty/bx/tests/handle_test.cpp index 5bcd6f8c89e..b82e1da3174 100644 --- a/3rdparty/bx/tests/handle_test.cpp +++ b/3rdparty/bx/tests/handle_test.cpp @@ -5,7 +5,7 @@ #include "test.h" #include <bx/handlealloc.h> -#include <bx/string.h> +#include <bx/hash.h> TEST_CASE("HandleListT", "") { diff --git a/3rdparty/bx/tests/macros_test.cpp b/3rdparty/bx/tests/macros_test.cpp index 37079de73a4..bae4bb896cf 100644 --- a/3rdparty/bx/tests/macros_test.cpp +++ b/3rdparty/bx/tests/macros_test.cpp @@ -4,8 +4,18 @@ */ #include "test.h" -#include <string.h> #include <bx/bx.h> +#include <bx/string.h> + +BX_STATIC_ASSERT(false + || BX_CRT_BIONIC + || BX_CRT_GLIBC + || BX_CRT_LIBCXX + || BX_CRT_MINGW + || BX_CRT_MSVC + || BX_CRT_MUSL + || BX_CRT_NEWLIB + ); BX_STATIC_ASSERT(1 == BX_VA_ARGS_COUNT(1) ); BX_STATIC_ASSERT(2 == BX_VA_ARGS_COUNT(1, 2) ); @@ -51,5 +61,5 @@ TEST(macros) CHECK_EQUAL(5, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5) ); CHECK_EQUAL(6, BX_VA_ARGS_COUNT(1, 2, 3, 4, 5, 6) ); - CHECK_EQUAL(0, strcmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") ); + CHECK_EQUAL(0, bx::strncmp(BX_STRINGIZE(TEST 1234 %^&*), "TEST 1234 %^&*") ); } diff --git a/3rdparty/bx/tests/main_test.cpp b/3rdparty/bx/tests/main_test.cpp index 47e9bf46155..b9d66db2fd6 100644 --- a/3rdparty/bx/tests/main_test.cpp +++ b/3rdparty/bx/tests/main_test.cpp @@ -3,16 +3,11 @@ * License: https://github.com/bkaradzic/bx#license-bsd-2-clause */ -#define CATCH_CONFIG_RUNNER #include "test.h" static const char* s_argv[] = { "bx.test" }; -int runAllTests(int _argc, const char* _argv[]) -{ - DBG(BX_COMPILER_NAME " / " BX_CPU_NAME " / " BX_ARCH_NAME " / " BX_PLATFORM_NAME); - return Catch::Session().run(_argc, _argv); -} +int runAllTests(int _argc, const char* _argv[]); #if BX_PLATFORM_ANDROID # include <android/native_activity.h> diff --git a/3rdparty/bx/tests/queue_test.cpp b/3rdparty/bx/tests/queue_test.cpp new file mode 100644 index 00000000000..48fd270a274 --- /dev/null +++ b/3rdparty/bx/tests/queue_test.cpp @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include "test.h" +#include <bx/spscqueue.h> +#include <bx/mpscqueue.h> + +void* bitsToPtr(uintptr_t _ui) +{ + union { uintptr_t ui; void* ptr; } cast = { _ui }; + return cast.ptr; +} + +uintptr_t ptrToBits(void* _ptr) +{ + union { void* ptr; uintptr_t ui; } cast = { _ptr }; + return cast.ui; +} + +TEST_CASE("SpSc", "") +{ + bx::SpScUnboundedQueue queue; + queue.push(bitsToPtr(0xdeadbeef) ); + REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) ); +} + +TEST_CASE("MpSc", "") +{ + bx::MpScUnboundedQueueT<void> queue; + queue.push(bitsToPtr(0xdeadbeef) ); + REQUIRE(0xdeadbeef == ptrToBits(queue.pop() ) ); +} diff --git a/3rdparty/bx/tests/ringbuffer_test.cpp b/3rdparty/bx/tests/ringbuffer_test.cpp new file mode 100644 index 00000000000..75d950184da --- /dev/null +++ b/3rdparty/bx/tests/ringbuffer_test.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include "test.h" +#include <bx/ringbuffer.h> + +TEST_CASE("RingBufferControl", "") +{ + bx::RingBufferControl control(16); + + REQUIRE(1 == control.reserve(1) ); + REQUIRE(0 == control.reserve(16, true) ); + REQUIRE(14 == control.reserve(16) ); + REQUIRE(15 == control.commit(15) ); + REQUIRE(15 == control.available() ); + REQUIRE(15 == control.consume(15) ); + REQUIRE(0 == control.available() ); +} diff --git a/3rdparty/bx/tests/run_test.cpp b/3rdparty/bx/tests/run_test.cpp new file mode 100644 index 00000000000..1616fe33c2c --- /dev/null +++ b/3rdparty/bx/tests/run_test.cpp @@ -0,0 +1,20 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#define CATCH_CONFIG_RUNNER +#include "test.h" + +int runAllTests(int _argc, const char* _argv[]) +{ + DBG("Compiler: " BX_COMPILER_NAME + ", CPU: " BX_CPU_NAME + ", Architecture: " BX_ARCH_NAME + ", OS: " BX_PLATFORM_NAME + ", CRT: " BX_CRT_NAME + ", Date: " __DATE__ + ", Time: " __TIME__ + ); + return Catch::Session().run(_argc, _argv); +} diff --git a/3rdparty/bx/tests/simd_bench.cpp b/3rdparty/bx/tests/simd_bench.cpp new file mode 100644 index 00000000000..d8ace20c117 --- /dev/null +++ b/3rdparty/bx/tests/simd_bench.cpp @@ -0,0 +1,133 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include <bx/simd_t.h> +#include <bx/rng.h> +#include <bx/crtimpl.h> +#include <bx/timer.h> + +#include <stdio.h> + +static void flushCache() +{ + static uint32_t length = 1 << 26; + static uint8_t* input = new uint8_t[length]; + static uint8_t* output = new uint8_t[length]; + bx::memCopy(output, input, length); +} + +typedef bx::simd128_t (*SimdRsqrtFn)(bx::simd128_t _a); + +template<SimdRsqrtFn simdRsqrtFn> +void simd_rsqrt_bench(bx::simd128_t* _dst, bx::simd128_t* _src, uint32_t _numVertices) +{ + for (uint32_t ii = 0, num = _numVertices/4; ii < num; ++ii) + { + bx::simd128_t* ptr = &_src[ii*4]; + bx::simd128_t tmp0 = bx::simd_ld(ptr + 0); + bx::simd128_t tmp1 = bx::simd_ld(ptr + 1); + bx::simd128_t tmp2 = bx::simd_ld(ptr + 2); + bx::simd128_t tmp3 = bx::simd_ld(ptr + 3); + bx::simd128_t rsqrt0 = simdRsqrtFn(tmp0); + bx::simd128_t rsqrt1 = simdRsqrtFn(tmp1); + bx::simd128_t rsqrt2 = simdRsqrtFn(tmp2); + bx::simd128_t rsqrt3 = simdRsqrtFn(tmp3); + + ptr = &_dst[ii*4]; + bx::simd_st(ptr + 0, rsqrt0); + bx::simd_st(ptr + 1, rsqrt1); + bx::simd_st(ptr + 2, rsqrt2); + bx::simd_st(ptr + 3, rsqrt3); + } +} + +void simd_bench_pass(bx::simd128_t* _dst, bx::simd128_t* _src, uint32_t _numVertices) +{ + const uint32_t numIterations = 10; + + { + int64_t elapsed = 0; + for (uint32_t test = 0; test < numIterations; ++test) + { + flushCache(); + elapsed += -bx::getHPCounter(); + simd_rsqrt_bench<bx::simd_rsqrt_est>(_dst, _src, _numVertices); + elapsed += bx::getHPCounter(); + } + printf(" simd_rsqrt_est: %15f\n", double(elapsed) ); + } + + { + int64_t elapsed = 0; + for (uint32_t test = 0; test < numIterations; ++test) + { + flushCache(); + elapsed += -bx::getHPCounter(); + simd_rsqrt_bench<bx::simd_rsqrt_nr>(_dst, _src, _numVertices); + elapsed += bx::getHPCounter(); + } + printf(" simd_rsqrt_nr: %15f\n", double(elapsed) ); + } + + { + int64_t elapsed = 0; + for (uint32_t test = 0; test < numIterations; ++test) + { + flushCache(); + elapsed += -bx::getHPCounter(); + simd_rsqrt_bench<bx::simd_rsqrt_carmack>(_dst, _src, _numVertices); + elapsed += bx::getHPCounter(); + } + printf("simd_rsqrt_carmack: %15f\n", double(elapsed) ); + } + + { + int64_t elapsed = 0; + for (uint32_t test = 0; test < numIterations; ++test) + { + flushCache(); + elapsed += -bx::getHPCounter(); + simd_rsqrt_bench<bx::simd_rsqrt>(_dst, _src, _numVertices); + elapsed += bx::getHPCounter(); + } + printf(" simd_rsqrt: %15f\n", double(elapsed) ); + } +} + +void simd_bench() +{ + bx::CrtAllocator allocator; + bx::RngMwc rng; + + const uint32_t numVertices = 1024*1024; + + uint8_t* data = (uint8_t*)BX_ALIGNED_ALLOC(&allocator, 2*numVertices*sizeof(bx::simd128_t), 16); + bx::simd128_t* src = (bx::simd128_t*)data; + bx::simd128_t* dst = &src[numVertices]; + + printf("\n -- positive & negative --\n"); + for (uint32_t ii = 0; ii < numVertices; ++ii) + { + float* ptr = (float*)&src[ii]; + randUnitSphere(ptr, &rng); + ptr[3] = 1.0f; + } + + simd_bench_pass(dst, src, numVertices); + + printf("\n -- positive only --\n"); + for (uint32_t ii = 0; ii < numVertices; ++ii) + { + float* ptr = (float*)&src[ii]; + ptr[0] = bx::fabsolute(ptr[0]); + ptr[1] = bx::fabsolute(ptr[1]); + ptr[2] = bx::fabsolute(ptr[2]); + ptr[3] = bx::fabsolute(ptr[3]); + } + + simd_bench_pass(dst, src, numVertices); + + BX_ALIGNED_FREE(&allocator, data, 16); +} diff --git a/3rdparty/bx/tests/simd_test.cpp b/3rdparty/bx/tests/simd_test.cpp index 0a361f4f7aa..ca46fd00bc3 100644 --- a/3rdparty/bx/tests/simd_test.cpp +++ b/3rdparty/bx/tests/simd_test.cpp @@ -6,7 +6,7 @@ #include "test.h" #include <bx/simd_t.h> #include <bx/fpumath.h> -#include <string.h> +#include <bx/string.h> #if 0 # define SIMD_DBG DBG @@ -206,7 +206,7 @@ void simd_check_string(const char* _str, bx::simd128_t _a) SIMD_DBG("%s %s", _str, test); - CHECK(0 == strcmp(_str, test) ); + CHECK(0 == bx::strncmp(_str, test) ); } TEST_CASE("simd_swizzle", "") @@ -220,7 +220,7 @@ TEST_CASE("simd_swizzle", "") #define BX_SIMD128_IMPLEMENT_SWIZZLE(_x, _y, _z, _w) \ simd_check_string("" #_x #_y #_z #_w "", simd_swiz_##_x##_y##_z##_w(xyzw) ); \ -#include <bx/simd128_swizzle.inl> +#include <bx/inline/simd128_swizzle.inl> #undef BX_SIMD128_IMPLEMENT_SWIZZLE #undef ELEMw diff --git a/3rdparty/bx/tests/sort_test.cpp b/3rdparty/bx/tests/sort_test.cpp new file mode 100644 index 00000000000..d271a3ffa03 --- /dev/null +++ b/3rdparty/bx/tests/sort_test.cpp @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2017 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bx#license-bsd-2-clause + */ + +#include "test.h" +#include <bx/sort.h> +#include <bx/string.h> +#include <bx/rng.h> + +TEST_CASE("quickSort", "") +{ + const char* str[] = + { + "jabuka", + "kruska", + "malina", + "jagoda", + }; + + bx::quickSort(str, BX_COUNTOF(str), sizeof(void*) + , [](const void* _lhs, const void* _rhs) + { + const char* lhs = *(const char**)_lhs; + const char* rhs = *(const char**)_rhs; + return bx::strncmp(lhs, rhs); + }); + + REQUIRE(0 == bx::strncmp(str[0], "jabuka") ); + REQUIRE(0 == bx::strncmp(str[1], "jagoda") ); + REQUIRE(0 == bx::strncmp(str[2], "kruska") ); + REQUIRE(0 == bx::strncmp(str[3], "malina") ); + + int8_t byte[128]; + bx::RngMwc rng; + for (uint32_t ii = 0; ii < BX_COUNTOF(byte); ++ii) + { + byte[ii] = rng.gen()&0xff; + } + + bx::quickSort(byte, BX_COUNTOF(byte), 1 + , [](const void* _lhs, const void* _rhs) + { + int8_t lhs = *(const int8_t*)_lhs; + int8_t rhs = *(const int8_t*)_rhs; + return lhs - rhs; + }); + + for (uint32_t ii = 1; ii < BX_COUNTOF(byte); ++ii) + { + REQUIRE(byte[ii-1] <= byte[ii]); + } +} diff --git a/3rdparty/bx/tests/string_test.cpp b/3rdparty/bx/tests/string_test.cpp index bea72044e54..35e1dac4445 100644 --- a/3rdparty/bx/tests/string_test.cpp +++ b/3rdparty/bx/tests/string_test.cpp @@ -29,7 +29,7 @@ TEST_CASE("strnlen", "") REQUIRE(0 == bx::strnlen(test, 0) ); REQUIRE(2 == bx::strnlen(test, 2) ); - REQUIRE(4 == bx::strnlen(test, UINT32_MAX) ); + REQUIRE(4 == bx::strnlen(test, INT32_MAX) ); } TEST_CASE("strlncpy", "") @@ -41,15 +41,15 @@ TEST_CASE("strlncpy", "") REQUIRE(num == 0); num = bx::strlncpy(dst, 3, "blah", 3); - REQUIRE(0 == strcmp(dst, "bl") ); + REQUIRE(0 == bx::strncmp(dst, "bl") ); REQUIRE(num == 2); num = bx::strlncpy(dst, sizeof(dst), "blah", 3); - REQUIRE(0 == strcmp(dst, "bla") ); + REQUIRE(0 == bx::strncmp(dst, "bla") ); REQUIRE(num == 3); num = bx::strlncpy(dst, sizeof(dst), "blah"); - REQUIRE(0 == strcmp(dst, "blah") ); + REQUIRE(0 == bx::strncmp(dst, "blah") ); REQUIRE(num == 4); } @@ -135,10 +135,14 @@ static bool testToString(Ty _value, const char* _expected) char tmp[1024]; int32_t num = bx::toString(tmp, BX_COUNTOF(tmp), _value); int32_t len = (int32_t)bx::strnlen(_expected); - return true - && 0 == bx::strncmp(tmp, _expected) - && num == len - ; + if (0 == bx::strncmp(tmp, _expected) + && num == len) + { + return true; + } + + printf("result '%s' (%d), expected '%s' (%d)\n", tmp, num, _expected, len); + return false; } TEST_CASE("toString int32_t/uint32_t", "") @@ -152,7 +156,7 @@ TEST_CASE("toString int32_t/uint32_t", "") TEST_CASE("toString double", "") { REQUIRE(testToString(0.0, "0.0") ); - REQUIRE(testToString(-0.0, "0.0") ); + REQUIRE(testToString(-0.0, "-0.0") ); REQUIRE(testToString(1.0, "1.0") ); REQUIRE(testToString(-1.0, "-1.0") ); REQUIRE(testToString(1.2345, "1.2345") ); @@ -195,7 +199,7 @@ TEST_CASE("StringView", "") st.append("test", 2); REQUIRE(10 == st.getLength() ); - REQUIRE(0 == strcmp(st.getPtr(), "testtestte") ); + REQUIRE(0 == bx::strncmp(st.getPtr(), "testtestte") ); st.clear(); REQUIRE(0 == st.getLength() ); diff --git a/3rdparty/bx/tests/test.h b/3rdparty/bx/tests/test.h index db710195023..c4f0dcec320 100644 --- a/3rdparty/bx/tests/test.h +++ b/3rdparty/bx/tests/test.h @@ -7,7 +7,12 @@ #define __TEST_H__ #include <bx/bx.h> + +BX_PRAGMA_DIAGNOSTIC_PUSH(); +BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4312); // warning C4312 : 'reinterpret_cast' : conversion from 'int' to 'const char *' of greater size #include <catch/catch.hpp> +BX_PRAGMA_DIAGNOSTIC_POP(); + #define TEST(_x) TEST_CASE(#_x, "") #define CHECK_EQUAL(_x, _y) REQUIRE(_x == _y) diff --git a/3rdparty/bx/tests/thread_test.cpp b/3rdparty/bx/tests/thread_test.cpp index 54f24f37f20..8d099311835 100644 --- a/3rdparty/bx/tests/thread_test.cpp +++ b/3rdparty/bx/tests/thread_test.cpp @@ -16,23 +16,23 @@ int32_t threadExit1(void*) return 1; } -TEST(thread) +TEST_CASE("thread", "") { bx::Thread th; - CHECK_EQUAL(th.isRunning(), false); + REQUIRE(!th.isRunning() ); th.init(threadExit0); - CHECK_EQUAL(th.isRunning(), true); + REQUIRE(th.isRunning() ); th.shutdown(); - CHECK_EQUAL(th.isRunning(), false); - CHECK_EQUAL(th.getExitCode(), 0); + REQUIRE(!th.isRunning() ); + REQUIRE(th.getExitCode() == 0); th.init(threadExit1); - CHECK_EQUAL(th.isRunning(), true); + REQUIRE(th.isRunning() ); th.shutdown(); - CHECK_EQUAL(th.isRunning(), false); - CHECK_EQUAL(th.getExitCode(), 1); + REQUIRE(!th.isRunning() ); + REQUIRE(th.getExitCode() == 1); } diff --git a/3rdparty/bx/tests/tokenizecmd_test.cpp b/3rdparty/bx/tests/tokenizecmd_test.cpp index 7d35ac7484c..d1495b28796 100644 --- a/3rdparty/bx/tests/tokenizecmd_test.cpp +++ b/3rdparty/bx/tests/tokenizecmd_test.cpp @@ -5,9 +5,9 @@ #include "test.h" #include <bx/commandline.h> -#include <string.h> +#include <bx/string.h> -TEST(commandLine) +TEST_CASE("commandLine", "") { const char* args[] = { @@ -19,76 +19,52 @@ TEST(commandLine) bx::CommandLine cmdLine(BX_COUNTOF(args), args); - CHECK(cmdLine.hasArg("long") ); - CHECK(cmdLine.hasArg('s') ); + REQUIRE(cmdLine.hasArg("long") ); + REQUIRE(cmdLine.hasArg('s') ); // non-existing argument - CHECK(!cmdLine.hasArg('x') ); - CHECK(!cmdLine.hasArg("preprocess") ); + REQUIRE(!cmdLine.hasArg('x') ); + REQUIRE(!cmdLine.hasArg("preprocess") ); } -TEST(tokenizeCommandLine) +static bool test(const char* _input, int32_t _argc, ...) { -#if 0 - const char* input[] = - { - " ", - "\\", -// "\"a b c\" d e", - "\"ab\\\"c\" \"\\\\\" d", - "a\\\\\\b d\"e f\"g h", - "a\\\\\\\"b c d", - "a\\\\\\\\\"b c\" d e", - }; - - const int expected_argc[] = - { - 0, - 0, -// 3, - 3, - 3, - 3, - 3 - }; + char buffer[1024]; + uint32_t len = sizeof(buffer); + char* argv[32]; + int32_t argc; + bx::tokenizeCommandLine(_input, buffer, len, argc, argv, BX_COUNTOF(argv) ); - const char* expected_results[] = + if (_argc != argc) { - "a b c", "d", "e", - "ab\"c", "\\", "d", - "a\\\\\\b", "de fg", "h", - "a\\\"b", "c", "d", - "a\\\\b c", "d", "e", - }; + return false; + } - const char** expected_argv[] = - { - NULL, - NULL, -// &expected_results[0], - &expected_results[3], - &expected_results[6], - &expected_results[9], - &expected_results[12], - }; + va_list argList; + va_start(argList, _argc); - for (uint32_t ii = 0; ii < BX_COUNTOF(exptected_argv); ++ii) + for (int32_t ii = 0; ii < _argc; ++ii) { - printf("x\n"); - char commandLine[1024]; - uint32_t size = BX_COUNTOF(commandLine); - char* argv[50]; - int32_t argc; - bx::tokenizeCommandLine(input[ii], commandLine, size, argc, argv, BX_COUNTOF(argv) ); - printf("\n%d (%d): %s %s\n", ii, argc, input[ii], expected_argc[ii] == argc ? "" : "FAILED!"); - for (uint32_t jj = 0; jj < argc; ++jj) + const char* arg = va_arg(argList, const char*); + if (0 != bx::strncmp(argv[ii], arg) ) { - printf("\t%d: {%s} %s\n" - , jj - , argv[jj] - , jj < argc ? (0==strcmp(argv[jj], expected_argv[ii][jj]) ? "" : "FAILED!") : "FAILED!" - ); + return false; } } -#endif // 0 + + va_end(argList); + + return true; +} + +TEST_CASE("tokenizeCommandLine", "") +{ + REQUIRE(test(" ", 0, NULL) ); + REQUIRE(test("\\", 0, NULL) ); + + REQUIRE(test("a b v g d", 5, "a", "b", "v", "g", "d") ); + + REQUIRE(test("\"ab\\\"v\" \"\\\\\" g", 3, "ab\"v", "\\", "g") ); + REQUIRE(test("a\\\\\\\"b v g", 3, "a\\\"b", "v", "g") ); + REQUIRE(test("a\\\\\\\\\"b v\" g d", 3, "a\\\\b v", "g", "d") ); } diff --git a/3rdparty/bx/tests/vector_complex_test.cpp b/3rdparty/bx/tests/vector_complex_test.cpp index a540ece8a40..17f511989c9 100644 --- a/3rdparty/bx/tests/vector_complex_test.cpp +++ b/3rdparty/bx/tests/vector_complex_test.cpp @@ -37,6 +37,8 @@ # define _strdup strdup #endif // !BX_COMPILER_MSVC +BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4996) // warning C4996: 'strdup': The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name: _strdup. See online help for details. + struct complex { complex() {data = 0;} complex(const char* s) { data = strdup(s); } diff --git a/3rdparty/bx/tests/vsnprintf_test.cpp b/3rdparty/bx/tests/vsnprintf_test.cpp index db1fba6fdad..12aea7bbb25 100644 --- a/3rdparty/bx/tests/vsnprintf_test.cpp +++ b/3rdparty/bx/tests/vsnprintf_test.cpp @@ -5,6 +5,8 @@ #include "test.h" #include <bx/string.h> +#include <limits> +#include <inttypes.h> TEST_CASE("vsnprintf NULL buffer", "No output buffer provided.") { @@ -18,12 +20,12 @@ TEST_CASE("vsnprintf truncated", "Truncated output buffer.") char buffer[7]; REQUIRE(10 == bx::snprintf(buffer, BX_COUNTOF(buffer), "Ten chars!") ); - REQUIRE(0 == strcmp(buffer, "Ten ch") ); + REQUIRE(0 == bx::strncmp(buffer, "Ten ch") ); } static bool test(const char* _expected, const char* _format, ...) { - int32_t max = (int32_t)strlen(_expected) + 1; + int32_t max = (int32_t)bx::strnlen(_expected) + 1; char* temp = (char*)alloca(max); va_list argList; @@ -33,12 +35,12 @@ static bool test(const char* _expected, const char* _format, ...) bool result = true && len == max-1 - && 0 == strcmp(_expected, temp) + && 0 == bx::strncmp(_expected, temp) ; if (!result) { - printf("result (%d) %s, expected (%d) %s\n", len, temp, max-1, _expected); + printf("result (%d) '%s', expected (%d) '%s'\n", len, temp, max-1, _expected); } return result; @@ -46,23 +48,120 @@ static bool test(const char* _expected, const char* _format, ...) TEST_CASE("vsnprintf f", "") { - REQUIRE(test("1.337", "%0.3f", 1.337) ); + REQUIRE(test("1.337", "%0.3f", 1.337) ); REQUIRE(test(" 13.370", "%8.3f", 13.37) ); REQUIRE(test(" 13.370", "%*.*f", 8, 3, 13.37) ); REQUIRE(test("13.370 ", "%-8.3f", 13.37) ); REQUIRE(test("13.370 ", "%*.*f", -8, 3, 13.37) ); + + REQUIRE(test("nan ", "%-8f", std::numeric_limits<double>::quiet_NaN() ) ); + REQUIRE(test(" nan", "%8f", std::numeric_limits<double>::quiet_NaN() ) ); + +#if !BX_CRT_MSVC + // BK - VS2015 CRT vsnprintf returns '-NAN(IND'. +# if BX_CRT_LIBCXX + // BK - Clang LibC vsnprintf returns 'NAN '. + REQUIRE(test("NAN ", "%-8F", -std::numeric_limits<double>::quiet_NaN() ) ); +# else + REQUIRE(test("-NAN ", "%-8F", -std::numeric_limits<double>::quiet_NaN() ) ); +# endif // BX_CRT_LIBCXX +#endif // !BX_CRT_MSVC + + REQUIRE(test(" inf", "%8f", std::numeric_limits<double>::infinity() ) ); + REQUIRE(test("inf ", "%-8f", std::numeric_limits<double>::infinity() ) ); + REQUIRE(test(" -INF", "%8F", -std::numeric_limits<double>::infinity() ) ); } -TEST_CASE("vsnprintf d/u/x", "") +TEST_CASE("vsnprintf d/i/o/u/x", "") { REQUIRE(test("1337", "%d", 1337) ); + REQUIRE(test("1337 ", "%-20d", 1337) ); + REQUIRE(test("-1337 ", "%-20d", -1337) ); + + REQUIRE(test("1337", "%i", 1337) ); + REQUIRE(test("1337 ", "%-20i", 1337) ); + REQUIRE(test("-1337 ", "%-20i", -1337) ); + + REQUIRE(test("1337", "%o", 01337) ); + REQUIRE(test("2471", "%o", 1337) ); + REQUIRE(test("1337 ", "%-20o", 01337) ); + REQUIRE(test("37777776441 ", "%-20o", -01337) ); + + REQUIRE(test("1337", "%u", 1337) ); + REQUIRE(test("1337 ", "%-20u", 1337) ); + REQUIRE(test("4294965959 ", "%-20u", -1337) ); REQUIRE(test("1337", "%x", 0x1337) ); + REQUIRE(test("1234abcd ", "%-20x", 0x1234abcd) ); + REQUIRE(test("1234ABCD ", "%-20X", 0x1234abcd) ); + REQUIRE(test("edcb5433 ", "%-20x", -0x1234abcd) ); + REQUIRE(test("EDCB5433 ", "%-20X", -0x1234abcd) ); + REQUIRE(test("0000000000001234abcd", "%020x", 0x1234abcd) ); + REQUIRE(test("0000000000001234ABCD", "%020X", 0x1234abcd) ); + REQUIRE(test("000000000000edcb5433", "%020x", -0x1234abcd) ); + REQUIRE(test("000000000000EDCB5433", "%020X", -0x1234abcd) ); + +#if !BX_CRT_MSVC + // BK - VS2015 CRT vsnprintf doesn't support 'j' length sub-specifier? + if (BX_ENABLED(BX_ARCH_32BIT) ) + { + REQUIRE(test("2147483647", "%jd", INTMAX_MAX) ); + } + else + { + REQUIRE(test("9223372036854775807", "%jd", INTMAX_MAX) ); + } +#endif // !BX_CRT_MSVC + + REQUIRE(test("18446744073709551615", "%" PRIu64, UINT64_MAX) ); + REQUIRE(test("ffffffffffffffff", "%016" PRIx64, UINT64_MAX) ); +} + +TEST_CASE("vsnprintf modifiers", "") +{ + REQUIRE(test("| 1.000000|", "|%10f|", 1.0f) ); + REQUIRE(test("|1.000000 |", "|%-10f|", 1.0f) ); + REQUIRE(test("|001.000000|", "|%010f|", 1.0f) ); + REQUIRE(test("|0000000001|", "|%010.0f|", 1.0f) ); + REQUIRE(test("|000000001.|", "|%#010.0f|", 1.0f) ); + REQUIRE(test("| 1|", "|%10.0f|", 1.0f) ); + REQUIRE(test("| 1.|", "|%#10.0f|", 1.0f) ); + REQUIRE(test("| +1.|", "|%#+10.0f|", 1.0f) ); + REQUIRE(test("|1 |", "|%-10.0f|", 1.0f) ); + REQUIRE(test("|1. |", "|%#-10.0f|", 1.0f) ); + REQUIRE(test("|+1. |", "|%+#-10.0f|", 1.0f) ); +} + +TEST_CASE("vsnprintf p", "") +{ +#if BX_CRT_MSVC + // BK - VS2015 CRT vsnprintf has different output for 'p' pointer specifier. + REQUIRE(test("0BADC0DE", "%p", (void*)0xbadc0de)); + REQUIRE(test("0BADC0DE ", "%-20p", (void*)0xbadc0de)); +#else + REQUIRE(test("0xbadc0de", "%p", (void*)0xbadc0de) ); + REQUIRE(test("0xbadc0de ", "%-20p", (void*)0xbadc0de) ); +#endif // BX_CRT_MSVC +} + +TEST_CASE("vsnprintf s", "") +{ + REQUIRE(test("(null)", "%s", NULL) ); +} + +TEST_CASE("vsnprintf g", "") +{ + REQUIRE(test(" 0.01", "%7.3g", .01) ); + REQUIRE(test(" 0.0123", "%7.3G", .0123) ); + REQUIRE(test("1.23e+05", "%.3g", 123000.25) ); + REQUIRE(test("1e+05", "%.0g", 123000.25) ); } TEST_CASE("vsnprintf", "") { REQUIRE(test("x", "%c", 'x') ); + REQUIRE(test("x ", "%-20c", 'x') ); + REQUIRE(test("hello ", "%-20s", "hello") ); REQUIRE(test("hello, world!", "%s, %s!", "hello", "world") ); } diff --git a/3rdparty/bx/tools/bin/darwin/genie b/3rdparty/bx/tools/bin/darwin/genie Binary files differindex 97c6f1279b9..48552bab3e7 100755 --- a/3rdparty/bx/tools/bin/darwin/genie +++ b/3rdparty/bx/tools/bin/darwin/genie diff --git a/3rdparty/bx/tools/bin/linux/genie b/3rdparty/bx/tools/bin/linux/genie Binary files differindex 3fa52f00f4f..021bc6ea4d2 100755 --- a/3rdparty/bx/tools/bin/linux/genie +++ b/3rdparty/bx/tools/bin/linux/genie diff --git a/3rdparty/bx/tools/bin/windows/genie.exe b/3rdparty/bx/tools/bin/windows/genie.exe Binary files differindex 19d6f15c6cd..b70a00cb408 100644 --- a/3rdparty/bx/tools/bin/windows/genie.exe +++ b/3rdparty/bx/tools/bin/windows/genie.exe diff --git a/3rdparty/bx/tools/bin2c/bin2c.cpp b/3rdparty/bx/tools/bin2c/bin2c.cpp index 47fc3bc2d22..d33d9204bc9 100644 --- a/3rdparty/bx/tools/bin2c/bin2c.cpp +++ b/3rdparty/bx/tools/bin2c/bin2c.cpp @@ -145,12 +145,12 @@ int main(int _argc, const char* _argv[]) } void* data = NULL; - size_t size = 0; + uint32_t size = 0; bx::CrtFileReader fr; if (bx::open(&fr, filePath) ) { - size = (size_t)bx::getSize(&fr); + size = uint32_t(bx::getSize(&fr) ); data = malloc(size); bx::read(&fr, data, size); |