├── .gitignore ├── 3rdparty ├── gbench │ ├── CMakeLists.txt │ ├── cmake │ │ ├── AddCXXCompilerFlag.cmake │ │ ├── CXXFeatureCheck.cmake │ │ ├── Config.cmake.in │ │ ├── GetGitVersion.cmake │ │ ├── GoogleTest.cmake │ │ ├── GoogleTest.cmake.in │ │ ├── Modules │ │ │ ├── FindLLVMAr.cmake │ │ │ ├── FindLLVMNm.cmake │ │ │ ├── FindLLVMRanLib.cmake │ │ │ └── FindPFM.cmake │ │ ├── benchmark.pc.in │ │ ├── benchmark_main.pc.in │ │ ├── gnu_posix_regex.cpp │ │ ├── llvm-toolchain.cmake │ │ ├── posix_regex.cpp │ │ ├── pthread_affinity.cpp │ │ ├── split_list.cmake │ │ ├── std_regex.cpp │ │ ├── steady_clock.cpp │ │ └── thread_safety_attributes.cpp │ ├── include │ │ └── benchmark │ │ │ ├── benchmark.h │ │ │ └── export.h │ └── src │ │ ├── CMakeLists.txt │ │ ├── arraysize.h │ │ ├── benchmark.cc │ │ ├── benchmark_api_internal.cc │ │ ├── benchmark_api_internal.h │ │ ├── benchmark_main.cc │ │ ├── benchmark_name.cc │ │ ├── benchmark_register.cc │ │ ├── benchmark_register.h │ │ ├── benchmark_runner.cc │ │ ├── benchmark_runner.h │ │ ├── check.cc │ │ ├── check.h │ │ ├── colorprint.cc │ │ ├── colorprint.h │ │ ├── commandlineflags.cc │ │ ├── commandlineflags.h │ │ ├── complexity.cc │ │ ├── complexity.h │ │ ├── console_reporter.cc │ │ ├── counter.cc │ │ ├── counter.h │ │ ├── csv_reporter.cc │ │ ├── cycleclock.h │ │ ├── internal_macros.h │ │ ├── json_reporter.cc │ │ ├── log.h │ │ ├── mutex.h │ │ ├── perf_counters.cc │ │ ├── perf_counters.h │ │ ├── re.h │ │ ├── reporter.cc │ │ ├── statistics.cc │ │ ├── statistics.h │ │ ├── string_util.cc │ │ ├── string_util.h │ │ ├── sysinfo.cc │ │ ├── thread_manager.h │ │ ├── thread_timer.h │ │ ├── timers.cc │ │ └── timers.h ├── gtest │ ├── CMakeLists.txt │ ├── VERSION │ └── googletest │ │ ├── CMakeLists.txt │ │ ├── cmake │ │ ├── Config.cmake.in │ │ ├── gtest.pc.in │ │ ├── gtest_main.pc.in │ │ ├── internal_utils.cmake │ │ └── libgtest.la.in │ │ ├── include │ │ └── gtest │ │ │ ├── gtest-assertion-result.h │ │ │ ├── gtest-death-test.h │ │ │ ├── gtest-matchers.h │ │ │ ├── gtest-message.h │ │ │ ├── gtest-param-test.h │ │ │ ├── gtest-printers.h │ │ │ ├── gtest-spi.h │ │ │ ├── gtest-test-part.h │ │ │ ├── gtest-typed-test.h │ │ │ ├── gtest.h │ │ │ ├── gtest_pred_impl.h │ │ │ ├── gtest_prod.h │ │ │ └── internal │ │ │ ├── custom │ │ │ ├── README.md │ │ │ ├── gtest-port.h │ │ │ ├── gtest-printers.h │ │ │ └── gtest.h │ │ │ ├── gtest-death-test-internal.h │ │ │ ├── gtest-filepath.h │ │ │ ├── gtest-internal.h │ │ │ ├── gtest-param-util.h │ │ │ ├── gtest-port-arch.h │ │ │ ├── gtest-port.h │ │ │ ├── gtest-string.h │ │ │ └── gtest-type-util.h │ │ └── src │ │ ├── gtest-all.cc │ │ ├── gtest-assertion-result.cc │ │ ├── gtest-death-test.cc │ │ ├── gtest-filepath.cc │ │ ├── gtest-internal-inl.h │ │ ├── gtest-matchers.cc │ │ ├── gtest-port.cc │ │ ├── gtest-printers.cc │ │ ├── gtest-test-part.cc │ │ ├── gtest-typed-test.cc │ │ ├── gtest.cc │ │ └── gtest_main.cc ├── vma │ └── include │ │ ├── vk_mem_alloc.cpp │ │ └── vk_mem_alloc.h ├── volk │ ├── VERSION │ └── include │ │ ├── volk.c │ │ └── volk.h └── vulkan │ ├── VERSION │ └── include │ ├── vk_video │ ├── vulkan_video_codec_h264std.h │ ├── vulkan_video_codec_h264std_decode.h │ ├── vulkan_video_codec_h264std_encode.h │ ├── vulkan_video_codec_h265std.h │ ├── vulkan_video_codec_h265std_decode.h │ ├── vulkan_video_codec_h265std_encode.h │ └── vulkan_video_codecs_common.h │ └── vulkan │ ├── vk_icd.h │ ├── vk_layer.h │ ├── vk_platform.h │ ├── vulkan.cppm │ ├── vulkan.h │ ├── vulkan.hpp │ ├── vulkan_android.h │ ├── vulkan_beta.h │ ├── vulkan_core.h │ ├── vulkan_directfb.h │ ├── vulkan_enums.hpp │ ├── vulkan_extension_inspection.hpp │ ├── vulkan_format_traits.hpp │ ├── vulkan_fuchsia.h │ ├── vulkan_funcs.hpp │ ├── vulkan_ggp.h │ ├── vulkan_handles.hpp │ ├── vulkan_hash.hpp │ ├── vulkan_hpp_macros.hpp │ ├── vulkan_ios.h │ ├── vulkan_macos.h │ ├── vulkan_metal.h │ ├── vulkan_raii.hpp │ ├── vulkan_screen.h │ ├── vulkan_shared.hpp │ ├── vulkan_static_assertions.hpp │ ├── vulkan_structs.hpp │ ├── vulkan_to_string.hpp │ ├── vulkan_vi.h │ ├── vulkan_video.hpp │ ├── vulkan_wayland.h │ ├── vulkan_win32.h │ ├── vulkan_xcb.h │ ├── vulkan_xlib.h │ └── vulkan_xlib_xrandr.h ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── benchmarks └── allocator │ ├── CMakeLists.txt │ └── main.cpp ├── docs ├── design_decisions.md └── minspec.md ├── include └── opal.h ├── samples ├── 01_enumerate_devices │ ├── CMakeLists.txt │ └── main.cpp ├── 02_buffers │ ├── CMakeLists.txt │ └── main.cpp ├── 03_textures │ ├── CMakeLists.txt │ └── main.cpp └── 04_triangle │ ├── CMakeLists.txt │ ├── main.cpp │ └── shaders │ ├── directx12 │ ├── main.frag.cso │ ├── main.frag.hlsl │ ├── main.vert.cso │ └── main.vert.hlsl │ ├── vulkan │ ├── main.frag.glsl │ ├── main.frag.spv │ ├── main.vert.glsl │ └── main.vert.spv │ └── webgpu │ ├── main.frag.wgsl │ └── main.vert.wgsl ├── src ├── CMakeLists.txt ├── common │ ├── bump.c │ ├── bump.h │ ├── heap.c │ ├── heap.h │ ├── intrinsics.h │ ├── pool.c │ ├── pool.h │ ├── ring.c │ └── ring.h ├── directx12 │ ├── directx12_allocator.c │ ├── directx12_device.c │ ├── directx12_guids.c │ ├── directx12_instance.c │ ├── directx12_internal.h │ └── directx12_utils.c ├── metal │ ├── metal_device.m │ ├── metal_instance.m │ ├── metal_internal.h │ └── metal_utils.m ├── null │ ├── null_device.c │ ├── null_instance.c │ └── null_internal.h ├── opal.c ├── opal_internal.c ├── opal_internal.h ├── vulkan │ ├── vulkan_allocator.c │ ├── vulkan_device.c │ ├── vulkan_instance.c │ ├── vulkan_internal.h │ ├── vulkan_platform_win32.c │ └── vulkan_utils.c └── webgpu │ ├── webgpu_device.c │ ├── webgpu_instance.c │ ├── webgpu_internal.h │ └── webgpu_utils.c └── tests ├── heap ├── CMakeLists.txt └── main.cpp └── pool ├── CMakeLists.txt └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # CMake specific 2 | [Bb]uild/ 3 | 4 | # VS Code specific 5 | .vscode 6 | 7 | # Mac OS specific 8 | .DS_Store -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/AddCXXCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # - Adds a compiler flag if it is supported by the compiler 2 | # 3 | # This function checks that the supplied compiler flag is supported and then 4 | # adds it to the corresponding compiler flags 5 | # 6 | # add_cxx_compiler_flag( []) 7 | # 8 | # - Example 9 | # 10 | # include(AddCXXCompilerFlag) 11 | # add_cxx_compiler_flag(-Wall) 12 | # add_cxx_compiler_flag(-no-strict-aliasing RELEASE) 13 | # Requires CMake 2.6+ 14 | 15 | if(__add_cxx_compiler_flag) 16 | return() 17 | endif() 18 | set(__add_cxx_compiler_flag INCLUDED) 19 | 20 | include(CheckCXXCompilerFlag) 21 | 22 | function(mangle_compiler_flag FLAG OUTPUT) 23 | string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG) 24 | string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG}) 25 | string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG}) 26 | string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG}) 27 | set(${OUTPUT} "${SANITIZED_FLAG}" PARENT_SCOPE) 28 | endfunction(mangle_compiler_flag) 29 | 30 | function(add_cxx_compiler_flag FLAG) 31 | mangle_compiler_flag("${FLAG}" MANGLED_FLAG) 32 | set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 33 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}") 34 | check_cxx_compiler_flag("${FLAG}" ${MANGLED_FLAG}) 35 | set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") 36 | if(${MANGLED_FLAG}) 37 | if(ARGC GREATER 1) 38 | set(VARIANT ${ARGV1}) 39 | string(TOUPPER "_${VARIANT}" VARIANT) 40 | else() 41 | set(VARIANT "") 42 | endif() 43 | set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${BENCHMARK_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE) 44 | endif() 45 | endfunction() 46 | 47 | function(add_required_cxx_compiler_flag FLAG) 48 | mangle_compiler_flag("${FLAG}" MANGLED_FLAG) 49 | set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 50 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}") 51 | check_cxx_compiler_flag("${FLAG}" ${MANGLED_FLAG}) 52 | set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") 53 | if(${MANGLED_FLAG}) 54 | if(ARGC GREATER 1) 55 | set(VARIANT ${ARGV1}) 56 | string(TOUPPER "_${VARIANT}" VARIANT) 57 | else() 58 | set(VARIANT "") 59 | endif() 60 | set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE) 61 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAG}" PARENT_SCOPE) 62 | set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAG}" PARENT_SCOPE) 63 | set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAG}" PARENT_SCOPE) 64 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}" PARENT_SCOPE) 65 | else() 66 | message(FATAL_ERROR "Required flag '${FLAG}' is not supported by the compiler") 67 | endif() 68 | endfunction() 69 | 70 | function(check_cxx_warning_flag FLAG) 71 | mangle_compiler_flag("${FLAG}" MANGLED_FLAG) 72 | set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 73 | # Add -Werror to ensure the compiler generates an error if the warning flag 74 | # doesn't exist. 75 | set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror ${FLAG}") 76 | check_cxx_compiler_flag("${FLAG}" ${MANGLED_FLAG}) 77 | set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}") 78 | endfunction() 79 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/CXXFeatureCheck.cmake: -------------------------------------------------------------------------------- 1 | # - Compile and run code to check for C++ features 2 | # 3 | # This functions compiles a source file under the `cmake` folder 4 | # and adds the corresponding `HAVE_[FILENAME]` flag to the CMake 5 | # environment 6 | # 7 | # cxx_feature_check( []) 8 | # 9 | # - Example 10 | # 11 | # include(CXXFeatureCheck) 12 | # cxx_feature_check(STD_REGEX) 13 | # Requires CMake 2.8.12+ 14 | 15 | if(__cxx_feature_check) 16 | return() 17 | endif() 18 | set(__cxx_feature_check INCLUDED) 19 | 20 | option(CXXFEATURECHECK_DEBUG OFF) 21 | 22 | function(cxx_feature_check FILE) 23 | string(TOLOWER ${FILE} FILE) 24 | string(TOUPPER ${FILE} VAR) 25 | string(TOUPPER "HAVE_${VAR}" FEATURE) 26 | if (DEFINED HAVE_${VAR}) 27 | set(HAVE_${VAR} 1 PARENT_SCOPE) 28 | add_definitions(-DHAVE_${VAR}) 29 | return() 30 | endif() 31 | 32 | set(FEATURE_CHECK_CMAKE_FLAGS ${BENCHMARK_CXX_LINKER_FLAGS}) 33 | if (ARGC GREATER 1) 34 | message(STATUS "Enabling additional flags: ${ARGV1}") 35 | list(APPEND FEATURE_CHECK_CMAKE_FLAGS ${ARGV1}) 36 | endif() 37 | 38 | if (NOT DEFINED COMPILE_${FEATURE}) 39 | if(CMAKE_CROSSCOMPILING) 40 | message(STATUS "Cross-compiling to test ${FEATURE}") 41 | try_compile(COMPILE_${FEATURE} 42 | ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp 43 | CXX_STANDARD 11 44 | CXX_STANDARD_REQUIRED ON 45 | CMAKE_FLAGS ${FEATURE_CHECK_CMAKE_FLAGS} 46 | LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES} 47 | OUTPUT_VARIABLE COMPILE_OUTPUT_VAR) 48 | if(COMPILE_${FEATURE}) 49 | message(WARNING 50 | "If you see build failures due to cross compilation, try setting HAVE_${VAR} to 0") 51 | set(RUN_${FEATURE} 0 CACHE INTERNAL "") 52 | else() 53 | set(RUN_${FEATURE} 1 CACHE INTERNAL "") 54 | endif() 55 | else() 56 | message(STATUS "Compiling and running to test ${FEATURE}") 57 | try_run(RUN_${FEATURE} COMPILE_${FEATURE} 58 | ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${FILE}.cpp 59 | CXX_STANDARD 11 60 | CXX_STANDARD_REQUIRED ON 61 | CMAKE_FLAGS ${FEATURE_CHECK_CMAKE_FLAGS} 62 | LINK_LIBRARIES ${BENCHMARK_CXX_LIBRARIES} 63 | COMPILE_OUTPUT_VARIABLE COMPILE_OUTPUT_VAR) 64 | endif() 65 | endif() 66 | 67 | if(RUN_${FEATURE} EQUAL 0) 68 | message(STATUS "Performing Test ${FEATURE} -- success") 69 | set(HAVE_${VAR} 1 PARENT_SCOPE) 70 | add_definitions(-DHAVE_${VAR}) 71 | else() 72 | if(NOT COMPILE_${FEATURE}) 73 | if(CXXFEATURECHECK_DEBUG) 74 | message(STATUS "Performing Test ${FEATURE} -- failed to compile: ${COMPILE_OUTPUT_VAR}") 75 | else() 76 | message(STATUS "Performing Test ${FEATURE} -- failed to compile") 77 | endif() 78 | else() 79 | message(STATUS "Performing Test ${FEATURE} -- compiled but failed to run") 80 | endif() 81 | endif() 82 | endfunction() 83 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include (CMakeFindDependencyMacro) 4 | 5 | find_dependency (Threads) 6 | 7 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 8 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/GetGitVersion.cmake: -------------------------------------------------------------------------------- 1 | # - Returns a version string from Git tags 2 | # 3 | # This function inspects the annotated git tags for the project and returns a string 4 | # into a CMake variable 5 | # 6 | # get_git_version() 7 | # 8 | # - Example 9 | # 10 | # include(GetGitVersion) 11 | # get_git_version(GIT_VERSION) 12 | # 13 | # Requires CMake 2.8.11+ 14 | find_package(Git) 15 | 16 | if(__get_git_version) 17 | return() 18 | endif() 19 | set(__get_git_version INCLUDED) 20 | 21 | function(get_git_version var) 22 | if(GIT_EXECUTABLE) 23 | execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --match "v[0-9]*.[0-9]*.[0-9]*" --abbrev=8 --dirty 24 | WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} 25 | RESULT_VARIABLE status 26 | OUTPUT_VARIABLE GIT_VERSION 27 | ERROR_QUIET) 28 | if(status) 29 | set(GIT_VERSION "v0.0.0") 30 | endif() 31 | else() 32 | set(GIT_VERSION "v0.0.0") 33 | endif() 34 | 35 | set(${var} ${GIT_VERSION} PARENT_SCOPE) 36 | endfunction() 37 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/GoogleTest.cmake: -------------------------------------------------------------------------------- 1 | # Download and unpack googletest at configure time 2 | set(GOOGLETEST_PREFIX "${benchmark_BINARY_DIR}/third_party/googletest") 3 | configure_file(${benchmark_SOURCE_DIR}/cmake/GoogleTest.cmake.in ${GOOGLETEST_PREFIX}/CMakeLists.txt @ONLY) 4 | 5 | set(GOOGLETEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/googletest" CACHE PATH "") # Mind the quotes 6 | execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" 7 | -DALLOW_DOWNLOADING_GOOGLETEST=${BENCHMARK_DOWNLOAD_DEPENDENCIES} -DGOOGLETEST_PATH:PATH=${GOOGLETEST_PATH} . 8 | RESULT_VARIABLE result 9 | WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 10 | ) 11 | 12 | if(result) 13 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") 14 | endif() 15 | 16 | execute_process( 17 | COMMAND ${CMAKE_COMMAND} --build . 18 | RESULT_VARIABLE result 19 | WORKING_DIRECTORY ${GOOGLETEST_PREFIX} 20 | ) 21 | 22 | if(result) 23 | message(FATAL_ERROR "Build step for googletest failed: ${result}") 24 | endif() 25 | 26 | # Prevent overriding the parent project's compiler/linker 27 | # settings on Windows 28 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 29 | 30 | include(${GOOGLETEST_PREFIX}/googletest-paths.cmake) 31 | 32 | # Add googletest directly to our build. This defines 33 | # the gtest and gtest_main targets. 34 | add_subdirectory(${GOOGLETEST_SOURCE_DIR} 35 | ${GOOGLETEST_BINARY_DIR} 36 | EXCLUDE_FROM_ALL) 37 | 38 | # googletest doesn't seem to want to stay build warning clean so let's not hurt ourselves. 39 | if (MSVC) 40 | target_compile_options(gtest PRIVATE "/wd4244" "/wd4722") 41 | target_compile_options(gtest_main PRIVATE "/wd4244" "/wd4722") 42 | target_compile_options(gmock PRIVATE "/wd4244" "/wd4722") 43 | target_compile_options(gmock_main PRIVATE "/wd4244" "/wd4722") 44 | else() 45 | target_compile_options(gtest PRIVATE "-w") 46 | target_compile_options(gtest_main PRIVATE "-w") 47 | target_compile_options(gmock PRIVATE "-w") 48 | target_compile_options(gmock_main PRIVATE "-w") 49 | endif() 50 | 51 | if(NOT DEFINED GTEST_COMPILE_COMMANDS) 52 | set(GTEST_COMPILE_COMMANDS ON) 53 | endif() 54 | 55 | set_target_properties(gtest PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $ EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 56 | set_target_properties(gtest_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $ EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 57 | set_target_properties(gmock PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $ EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 58 | set_target_properties(gmock_main PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES $ EXPORT_COMPILE_COMMANDS ${GTEST_COMPILE_COMMANDS}) 59 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/GoogleTest.cmake.in: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.12) 2 | 3 | project(googletest-download NONE) 4 | 5 | # Enable ExternalProject CMake module 6 | include(ExternalProject) 7 | 8 | option(ALLOW_DOWNLOADING_GOOGLETEST "If googletest src tree is not found in location specified by GOOGLETEST_PATH, do fetch the archive from internet" OFF) 9 | set(GOOGLETEST_PATH "/usr/src/googletest" CACHE PATH 10 | "Path to the googletest root tree. Should contain googletest and googlemock subdirs. And CMakeLists.txt in root, and in both of these subdirs") 11 | 12 | # Download and install GoogleTest 13 | 14 | message(STATUS "Looking for Google Test sources") 15 | message(STATUS "Looking for Google Test sources in ${GOOGLETEST_PATH}") 16 | if(EXISTS "${GOOGLETEST_PATH}" AND IS_DIRECTORY "${GOOGLETEST_PATH}" AND EXISTS "${GOOGLETEST_PATH}/CMakeLists.txt" AND 17 | EXISTS "${GOOGLETEST_PATH}/googletest" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googletest" AND EXISTS "${GOOGLETEST_PATH}/googletest/CMakeLists.txt" AND 18 | EXISTS "${GOOGLETEST_PATH}/googlemock" AND IS_DIRECTORY "${GOOGLETEST_PATH}/googlemock" AND EXISTS "${GOOGLETEST_PATH}/googlemock/CMakeLists.txt") 19 | message(STATUS "Found Google Test in ${GOOGLETEST_PATH}") 20 | 21 | ExternalProject_Add( 22 | googletest 23 | PREFIX "${CMAKE_BINARY_DIR}" 24 | DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download" 25 | SOURCE_DIR "${GOOGLETEST_PATH}" # use existing src dir. 26 | BINARY_DIR "${CMAKE_BINARY_DIR}/build" 27 | CONFIGURE_COMMAND "" 28 | BUILD_COMMAND "" 29 | INSTALL_COMMAND "" 30 | TEST_COMMAND "" 31 | ) 32 | else() 33 | if(NOT ALLOW_DOWNLOADING_GOOGLETEST) 34 | message(SEND_ERROR "Did not find Google Test sources! Either pass correct path in GOOGLETEST_PATH, or enable BENCHMARK_DOWNLOAD_DEPENDENCIES, or disable BENCHMARK_USE_BUNDLED_GTEST, or disable BENCHMARK_ENABLE_GTEST_TESTS / BENCHMARK_ENABLE_TESTING.") 35 | return() 36 | else() 37 | message(WARNING "Did not find Google Test sources! Fetching from web...") 38 | ExternalProject_Add( 39 | googletest 40 | GIT_REPOSITORY https://github.com/google/googletest.git 41 | GIT_TAG "release-1.11.0" 42 | PREFIX "${CMAKE_BINARY_DIR}" 43 | STAMP_DIR "${CMAKE_BINARY_DIR}/stamp" 44 | DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/download" 45 | SOURCE_DIR "${CMAKE_BINARY_DIR}/src" 46 | BINARY_DIR "${CMAKE_BINARY_DIR}/build" 47 | CONFIGURE_COMMAND "" 48 | BUILD_COMMAND "" 49 | INSTALL_COMMAND "" 50 | TEST_COMMAND "" 51 | ) 52 | endif() 53 | endif() 54 | 55 | ExternalProject_Get_Property(googletest SOURCE_DIR BINARY_DIR) 56 | file(WRITE googletest-paths.cmake 57 | "set(GOOGLETEST_SOURCE_DIR \"${SOURCE_DIR}\") 58 | set(GOOGLETEST_BINARY_DIR \"${BINARY_DIR}\") 59 | ") 60 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/Modules/FindLLVMAr.cmake: -------------------------------------------------------------------------------- 1 | include(FeatureSummary) 2 | 3 | find_program(LLVMAR_EXECUTABLE 4 | NAMES llvm-ar 5 | DOC "The llvm-ar executable" 6 | ) 7 | 8 | include(FindPackageHandleStandardArgs) 9 | find_package_handle_standard_args(LLVMAr 10 | DEFAULT_MSG 11 | LLVMAR_EXECUTABLE) 12 | 13 | SET_PACKAGE_PROPERTIES(LLVMAr PROPERTIES 14 | URL https://llvm.org/docs/CommandGuide/llvm-ar.html 15 | DESCRIPTION "create, modify, and extract from archives" 16 | ) 17 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/Modules/FindLLVMNm.cmake: -------------------------------------------------------------------------------- 1 | include(FeatureSummary) 2 | 3 | find_program(LLVMNM_EXECUTABLE 4 | NAMES llvm-nm 5 | DOC "The llvm-nm executable" 6 | ) 7 | 8 | include(FindPackageHandleStandardArgs) 9 | find_package_handle_standard_args(LLVMNm 10 | DEFAULT_MSG 11 | LLVMNM_EXECUTABLE) 12 | 13 | SET_PACKAGE_PROPERTIES(LLVMNm PROPERTIES 14 | URL https://llvm.org/docs/CommandGuide/llvm-nm.html 15 | DESCRIPTION "list LLVM bitcode and object file’s symbol table" 16 | ) 17 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/Modules/FindLLVMRanLib.cmake: -------------------------------------------------------------------------------- 1 | include(FeatureSummary) 2 | 3 | find_program(LLVMRANLIB_EXECUTABLE 4 | NAMES llvm-ranlib 5 | DOC "The llvm-ranlib executable" 6 | ) 7 | 8 | include(FindPackageHandleStandardArgs) 9 | find_package_handle_standard_args(LLVMRanLib 10 | DEFAULT_MSG 11 | LLVMRANLIB_EXECUTABLE) 12 | 13 | SET_PACKAGE_PROPERTIES(LLVMRanLib PROPERTIES 14 | DESCRIPTION "generate index for LLVM archive" 15 | ) 16 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/Modules/FindPFM.cmake: -------------------------------------------------------------------------------- 1 | # If successful, the following variables will be defined: 2 | # PFM_FOUND. 3 | # PFM_LIBRARIES 4 | # PFM_INCLUDE_DIRS 5 | # the following target will be defined: 6 | # PFM::libpfm 7 | 8 | include(FeatureSummary) 9 | include(FindPackageHandleStandardArgs) 10 | 11 | set_package_properties(PFM PROPERTIES 12 | URL http://perfmon2.sourceforge.net/ 13 | DESCRIPTION "A helper library to develop monitoring tools" 14 | PURPOSE "Used to program specific performance monitoring events") 15 | 16 | find_library(PFM_LIBRARY NAMES pfm) 17 | find_path(PFM_INCLUDE_DIR NAMES perfmon/pfmlib.h) 18 | 19 | find_package_handle_standard_args(PFM REQUIRED_VARS PFM_LIBRARY PFM_INCLUDE_DIR) 20 | 21 | if (PFM_FOUND AND NOT TARGET PFM::libpfm) 22 | add_library(PFM::libpfm UNKNOWN IMPORTED) 23 | set_target_properties(PFM::libpfm PROPERTIES 24 | IMPORTED_LOCATION "${PFM_LIBRARY}" 25 | INTERFACE_INCLUDE_DIRECTORIES "${PFM_INCLUDE_DIR}") 26 | endif() 27 | 28 | mark_as_advanced(PFM_LIBRARY PFM_INCLUDE_DIR) 29 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/benchmark.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@CMAKE_INSTALL_PREFIX@ 2 | exec_prefix=${prefix} 3 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 4 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 5 | 6 | Name: @PROJECT_NAME@ 7 | Description: Google microbenchmark framework 8 | Version: @VERSION@ 9 | 10 | Libs: -L${libdir} -lbenchmark 11 | Libs.private: -lpthread 12 | Cflags: -I${includedir} 13 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/benchmark_main.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | 3 | Name: @PROJECT_NAME@ 4 | Description: Google microbenchmark framework (with main() function) 5 | Version: @VERSION@ 6 | Requires: benchmark 7 | Libs: -L${libdir} -lbenchmark_main 8 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/gnu_posix_regex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | std::string str = "test0159"; 5 | regex_t re; 6 | int ec = regcomp(&re, "^[a-z]+[0-9]+$", REG_EXTENDED | REG_NOSUB); 7 | if (ec != 0) { 8 | return ec; 9 | } 10 | return regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/llvm-toolchain.cmake: -------------------------------------------------------------------------------- 1 | find_package(LLVMAr REQUIRED) 2 | set(CMAKE_AR "${LLVMAR_EXECUTABLE}" CACHE FILEPATH "" FORCE) 3 | 4 | find_package(LLVMNm REQUIRED) 5 | set(CMAKE_NM "${LLVMNM_EXECUTABLE}" CACHE FILEPATH "" FORCE) 6 | 7 | find_package(LLVMRanLib REQUIRED) 8 | set(CMAKE_RANLIB "${LLVMRANLIB_EXECUTABLE}" CACHE FILEPATH "" FORCE) 9 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/posix_regex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | std::string str = "test0159"; 5 | regex_t re; 6 | int ec = regcomp(&re, "^[a-z]+[0-9]+$", REG_EXTENDED | REG_NOSUB); 7 | if (ec != 0) { 8 | return ec; 9 | } 10 | int ret = regexec(&re, str.c_str(), 0, nullptr, 0) ? -1 : 0; 11 | regfree(&re); 12 | return ret; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/pthread_affinity.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | cpu_set_t set; 4 | CPU_ZERO(&set); 5 | for (int i = 0; i < CPU_SETSIZE; ++i) { 6 | CPU_SET(i, &set); 7 | CPU_CLR(i, &set); 8 | } 9 | pthread_t self = pthread_self(); 10 | int ret; 11 | ret = pthread_getaffinity_np(self, sizeof(set), &set); 12 | if (ret != 0) return ret; 13 | ret = pthread_setaffinity_np(self, sizeof(set), &set); 14 | if (ret != 0) return ret; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/split_list.cmake: -------------------------------------------------------------------------------- 1 | macro(split_list listname) 2 | string(REPLACE ";" " " ${listname} "${${listname}}") 3 | endmacro() 4 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/std_regex.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() { 4 | const std::string str = "test0159"; 5 | std::regex re; 6 | re = std::regex("^[a-z]+[0-9]+$", 7 | std::regex_constants::extended | std::regex_constants::nosubs); 8 | return std::regex_search(str, re) ? 0 : -1; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/steady_clock.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | typedef std::chrono::steady_clock Clock; 5 | Clock::time_point tp = Clock::now(); 6 | ((void)tp); 7 | } 8 | -------------------------------------------------------------------------------- /3rdparty/gbench/cmake/thread_safety_attributes.cpp: -------------------------------------------------------------------------------- 1 | #define HAVE_THREAD_SAFETY_ATTRIBUTES 2 | #include "../src/mutex.h" 3 | 4 | int main() {} 5 | -------------------------------------------------------------------------------- /3rdparty/gbench/include/benchmark/export.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_EXPORT_H 2 | #define BENCHMARK_EXPORT_H 3 | 4 | #if defined(_WIN32) 5 | #define EXPORT_ATTR __declspec(dllexport) 6 | #define IMPORT_ATTR __declspec(dllimport) 7 | #define NO_EXPORT_ATTR 8 | #define DEPRECATED_ATTR __declspec(deprecated) 9 | #else // _WIN32 10 | #define EXPORT_ATTR __attribute__((visibility("default"))) 11 | #define IMPORT_ATTR __attribute__((visibility("default"))) 12 | #define NO_EXPORT_ATTR __attribute__((visibility("hidden"))) 13 | #define DEPRECATE_ATTR __attribute__((__deprecated__)) 14 | #endif // _WIN32 15 | 16 | #ifdef BENCHMARK_STATIC_DEFINE 17 | #define BENCHMARK_EXPORT 18 | #define BENCHMARK_NO_EXPORT 19 | #else // BENCHMARK_STATIC_DEFINE 20 | #ifndef BENCHMARK_EXPORT 21 | #ifdef benchmark_EXPORTS 22 | /* We are building this library */ 23 | #define BENCHMARK_EXPORT EXPORT_ATTR 24 | #else // benchmark_EXPORTS 25 | /* We are using this library */ 26 | #define BENCHMARK_EXPORT IMPORT_ATTR 27 | #endif // benchmark_EXPORTS 28 | #endif // !BENCHMARK_EXPORT 29 | 30 | #ifndef BENCHMARK_NO_EXPORT 31 | #define BENCHMARK_NO_EXPORT NO_EXPORT_ATTR 32 | #endif // !BENCHMARK_NO_EXPORT 33 | #endif // BENCHMARK_STATIC_DEFINE 34 | 35 | #ifndef BENCHMARK_DEPRECATED 36 | #define BENCHMARK_DEPRECATED DEPRECATE_ATTR 37 | #endif // BENCHMARK_DEPRECATED 38 | 39 | #ifndef BENCHMARK_DEPRECATED_EXPORT 40 | #define BENCHMARK_DEPRECATED_EXPORT BENCHMARK_EXPORT BENCHMARK_DEPRECATED 41 | #endif // BENCHMARK_DEPRECATED_EXPORT 42 | 43 | #ifndef BENCHMARK_DEPRECATED_NO_EXPORT 44 | #define BENCHMARK_DEPRECATED_NO_EXPORT BENCHMARK_NO_EXPORT BENCHMARK_DEPRECATED 45 | #endif // BENCHMARK_DEPRECATED_EXPORT 46 | 47 | #endif /* BENCHMARK_EXPORT_H */ 48 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/arraysize.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_ARRAYSIZE_H_ 2 | #define BENCHMARK_ARRAYSIZE_H_ 3 | 4 | #include "internal_macros.h" 5 | 6 | namespace benchmark { 7 | namespace internal { 8 | // The arraysize(arr) macro returns the # of elements in an array arr. 9 | // The expression is a compile-time constant, and therefore can be 10 | // used in defining new arrays, for example. If you use arraysize on 11 | // a pointer by mistake, you will get a compile-time error. 12 | // 13 | 14 | // This template function declaration is used in defining arraysize. 15 | // Note that the function doesn't need an implementation, as we only 16 | // use its type. 17 | template 18 | char (&ArraySizeHelper(T (&array)[N]))[N]; 19 | 20 | // That gcc wants both of these prototypes seems mysterious. VC, for 21 | // its part, can't decide which to use (another mystery). Matching of 22 | // template overloads: the final frontier. 23 | #ifndef COMPILER_MSVC 24 | template 25 | char (&ArraySizeHelper(const T (&array)[N]))[N]; 26 | #endif 27 | 28 | #define arraysize(array) (sizeof(::benchmark::internal::ArraySizeHelper(array))) 29 | 30 | } // end namespace internal 31 | } // end namespace benchmark 32 | 33 | #endif // BENCHMARK_ARRAYSIZE_H_ 34 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_api_internal.cc: -------------------------------------------------------------------------------- 1 | #include "benchmark_api_internal.h" 2 | 3 | #include 4 | 5 | #include "string_util.h" 6 | 7 | namespace benchmark { 8 | namespace internal { 9 | 10 | BenchmarkInstance::BenchmarkInstance(Benchmark* benchmark, int family_idx, 11 | int per_family_instance_idx, 12 | const std::vector& args, 13 | int thread_count) 14 | : benchmark_(*benchmark), 15 | family_index_(family_idx), 16 | per_family_instance_index_(per_family_instance_idx), 17 | aggregation_report_mode_(benchmark_.aggregation_report_mode_), 18 | args_(args), 19 | time_unit_(benchmark_.GetTimeUnit()), 20 | measure_process_cpu_time_(benchmark_.measure_process_cpu_time_), 21 | use_real_time_(benchmark_.use_real_time_), 22 | use_manual_time_(benchmark_.use_manual_time_), 23 | complexity_(benchmark_.complexity_), 24 | complexity_lambda_(benchmark_.complexity_lambda_), 25 | statistics_(benchmark_.statistics_), 26 | repetitions_(benchmark_.repetitions_), 27 | min_time_(benchmark_.min_time_), 28 | min_warmup_time_(benchmark_.min_warmup_time_), 29 | iterations_(benchmark_.iterations_), 30 | threads_(thread_count) { 31 | name_.function_name = benchmark_.name_; 32 | 33 | size_t arg_i = 0; 34 | for (const auto& arg : args) { 35 | if (!name_.args.empty()) { 36 | name_.args += '/'; 37 | } 38 | 39 | if (arg_i < benchmark->arg_names_.size()) { 40 | const auto& arg_name = benchmark_.arg_names_[arg_i]; 41 | if (!arg_name.empty()) { 42 | name_.args += StrFormat("%s:", arg_name.c_str()); 43 | } 44 | } 45 | 46 | name_.args += StrFormat("%" PRId64, arg); 47 | ++arg_i; 48 | } 49 | 50 | if (!IsZero(benchmark->min_time_)) { 51 | name_.min_time = StrFormat("min_time:%0.3f", benchmark_.min_time_); 52 | } 53 | 54 | if (!IsZero(benchmark->min_warmup_time_)) { 55 | name_.min_warmup_time = 56 | StrFormat("min_warmup_time:%0.3f", benchmark_.min_warmup_time_); 57 | } 58 | 59 | if (benchmark_.iterations_ != 0) { 60 | name_.iterations = StrFormat( 61 | "iterations:%lu", static_cast(benchmark_.iterations_)); 62 | } 63 | 64 | if (benchmark_.repetitions_ != 0) { 65 | name_.repetitions = StrFormat("repeats:%d", benchmark_.repetitions_); 66 | } 67 | 68 | if (benchmark_.measure_process_cpu_time_) { 69 | name_.time_type = "process_time"; 70 | } 71 | 72 | if (benchmark_.use_manual_time_) { 73 | if (!name_.time_type.empty()) { 74 | name_.time_type += '/'; 75 | } 76 | name_.time_type += "manual_time"; 77 | } else if (benchmark_.use_real_time_) { 78 | if (!name_.time_type.empty()) { 79 | name_.time_type += '/'; 80 | } 81 | name_.time_type += "real_time"; 82 | } 83 | 84 | if (!benchmark_.thread_counts_.empty()) { 85 | name_.threads = StrFormat("threads:%d", threads_); 86 | } 87 | 88 | setup_ = benchmark_.setup_; 89 | teardown_ = benchmark_.teardown_; 90 | } 91 | 92 | State BenchmarkInstance::Run( 93 | IterationCount iters, int thread_id, internal::ThreadTimer* timer, 94 | internal::ThreadManager* manager, 95 | internal::PerfCountersMeasurement* perf_counters_measurement) const { 96 | State st(name_.function_name, iters, args_, thread_id, threads_, timer, 97 | manager, perf_counters_measurement); 98 | benchmark_.Run(st); 99 | return st; 100 | } 101 | 102 | void BenchmarkInstance::Setup() const { 103 | if (setup_) { 104 | State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_, 105 | nullptr, nullptr, nullptr); 106 | setup_(st); 107 | } 108 | } 109 | 110 | void BenchmarkInstance::Teardown() const { 111 | if (teardown_) { 112 | State st(name_.function_name, /*iters*/ 1, args_, /*thread_id*/ 0, threads_, 113 | nullptr, nullptr, nullptr); 114 | teardown_(st); 115 | } 116 | } 117 | } // namespace internal 118 | } // namespace benchmark 119 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_api_internal.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_API_INTERNAL_H 2 | #define BENCHMARK_API_INTERNAL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "benchmark/benchmark.h" 12 | #include "commandlineflags.h" 13 | 14 | namespace benchmark { 15 | namespace internal { 16 | 17 | // Information kept per benchmark we may want to run 18 | class BenchmarkInstance { 19 | public: 20 | BenchmarkInstance(Benchmark* benchmark, int family_index, 21 | int per_family_instance_index, 22 | const std::vector& args, int threads); 23 | 24 | const BenchmarkName& name() const { return name_; } 25 | int family_index() const { return family_index_; } 26 | int per_family_instance_index() const { return per_family_instance_index_; } 27 | AggregationReportMode aggregation_report_mode() const { 28 | return aggregation_report_mode_; 29 | } 30 | TimeUnit time_unit() const { return time_unit_; } 31 | bool measure_process_cpu_time() const { return measure_process_cpu_time_; } 32 | bool use_real_time() const { return use_real_time_; } 33 | bool use_manual_time() const { return use_manual_time_; } 34 | BigO complexity() const { return complexity_; } 35 | BigOFunc* complexity_lambda() const { return complexity_lambda_; } 36 | const std::vector& statistics() const { return statistics_; } 37 | int repetitions() const { return repetitions_; } 38 | double min_time() const { return min_time_; } 39 | double min_warmup_time() const { return min_warmup_time_; } 40 | IterationCount iterations() const { return iterations_; } 41 | int threads() const { return threads_; } 42 | void Setup() const; 43 | void Teardown() const; 44 | 45 | State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer, 46 | internal::ThreadManager* manager, 47 | internal::PerfCountersMeasurement* perf_counters_measurement) const; 48 | 49 | private: 50 | BenchmarkName name_; 51 | Benchmark& benchmark_; 52 | const int family_index_; 53 | const int per_family_instance_index_; 54 | AggregationReportMode aggregation_report_mode_; 55 | const std::vector& args_; 56 | TimeUnit time_unit_; 57 | bool measure_process_cpu_time_; 58 | bool use_real_time_; 59 | bool use_manual_time_; 60 | BigO complexity_; 61 | BigOFunc* complexity_lambda_; 62 | UserCounters counters_; 63 | const std::vector& statistics_; 64 | int repetitions_; 65 | double min_time_; 66 | double min_warmup_time_; 67 | IterationCount iterations_; 68 | int threads_; // Number of concurrent threads to us 69 | 70 | typedef void (*callback_function)(const benchmark::State&); 71 | callback_function setup_ = nullptr; 72 | callback_function teardown_ = nullptr; 73 | }; 74 | 75 | bool FindBenchmarksInternal(const std::string& re, 76 | std::vector* benchmarks, 77 | std::ostream* Err); 78 | 79 | bool IsZero(double n); 80 | 81 | BENCHMARK_EXPORT 82 | ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false); 83 | 84 | } // end namespace internal 85 | } // end namespace benchmark 86 | 87 | #endif // BENCHMARK_API_INTERNAL_H 88 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2018 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "benchmark/benchmark.h" 16 | 17 | BENCHMARK_EXPORT int main(int, char**); 18 | BENCHMARK_MAIN(); 19 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_name.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | namespace benchmark { 18 | 19 | namespace { 20 | 21 | // Compute the total size of a pack of std::strings 22 | size_t size_impl() { return 0; } 23 | 24 | template 25 | size_t size_impl(const Head& head, const Tail&... tail) { 26 | return head.size() + size_impl(tail...); 27 | } 28 | 29 | // Join a pack of std::strings using a delimiter 30 | // TODO: use absl::StrJoin 31 | void join_impl(std::string&, char) {} 32 | 33 | template 34 | void join_impl(std::string& s, const char delimiter, const Head& head, 35 | const Tail&... tail) { 36 | if (!s.empty() && !head.empty()) { 37 | s += delimiter; 38 | } 39 | 40 | s += head; 41 | 42 | join_impl(s, delimiter, tail...); 43 | } 44 | 45 | template 46 | std::string join(char delimiter, const Ts&... ts) { 47 | std::string s; 48 | s.reserve(sizeof...(Ts) + size_impl(ts...)); 49 | join_impl(s, delimiter, ts...); 50 | return s; 51 | } 52 | } // namespace 53 | 54 | BENCHMARK_EXPORT 55 | std::string BenchmarkName::str() const { 56 | return join('/', function_name, args, min_time, min_warmup_time, iterations, 57 | repetitions, time_type, threads); 58 | } 59 | } // namespace benchmark 60 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_register.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_REGISTER_H 2 | #define BENCHMARK_REGISTER_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "check.h" 9 | 10 | namespace benchmark { 11 | namespace internal { 12 | 13 | // Append the powers of 'mult' in the closed interval [lo, hi]. 14 | // Returns iterator to the start of the inserted range. 15 | template 16 | typename std::vector::iterator AddPowers(std::vector* dst, T lo, T hi, 17 | int mult) { 18 | BM_CHECK_GE(lo, 0); 19 | BM_CHECK_GE(hi, lo); 20 | BM_CHECK_GE(mult, 2); 21 | 22 | const size_t start_offset = dst->size(); 23 | 24 | static const T kmax = std::numeric_limits::max(); 25 | 26 | // Space out the values in multiples of "mult" 27 | for (T i = static_cast(1); i <= hi; i = static_cast(i * mult)) { 28 | if (i >= lo) { 29 | dst->push_back(i); 30 | } 31 | // Break the loop here since multiplying by 32 | // 'mult' would move outside of the range of T 33 | if (i > kmax / mult) break; 34 | } 35 | 36 | return dst->begin() + static_cast(start_offset); 37 | } 38 | 39 | template 40 | void AddNegatedPowers(std::vector* dst, T lo, T hi, int mult) { 41 | // We negate lo and hi so we require that they cannot be equal to 'min'. 42 | BM_CHECK_GT(lo, std::numeric_limits::min()); 43 | BM_CHECK_GT(hi, std::numeric_limits::min()); 44 | BM_CHECK_GE(hi, lo); 45 | BM_CHECK_LE(hi, 0); 46 | 47 | // Add positive powers, then negate and reverse. 48 | // Casts necessary since small integers get promoted 49 | // to 'int' when negating. 50 | const auto lo_complement = static_cast(-lo); 51 | const auto hi_complement = static_cast(-hi); 52 | 53 | const auto it = AddPowers(dst, hi_complement, lo_complement, mult); 54 | 55 | std::for_each(it, dst->end(), [](T& t) { t = static_cast(t * -1); }); 56 | std::reverse(it, dst->end()); 57 | } 58 | 59 | template 60 | void AddRange(std::vector* dst, T lo, T hi, int mult) { 61 | static_assert(std::is_integral::value && std::is_signed::value, 62 | "Args type must be a signed integer"); 63 | 64 | BM_CHECK_GE(hi, lo); 65 | BM_CHECK_GE(mult, 2); 66 | 67 | // Add "lo" 68 | dst->push_back(lo); 69 | 70 | // Handle lo == hi as a special case, so we then know 71 | // lo < hi and so it is safe to add 1 to lo and subtract 1 72 | // from hi without falling outside of the range of T. 73 | if (lo == hi) return; 74 | 75 | // Ensure that lo_inner <= hi_inner below. 76 | if (lo + 1 == hi) { 77 | dst->push_back(hi); 78 | return; 79 | } 80 | 81 | // Add all powers of 'mult' in the range [lo+1, hi-1] (inclusive). 82 | const auto lo_inner = static_cast(lo + 1); 83 | const auto hi_inner = static_cast(hi - 1); 84 | 85 | // Insert negative values 86 | if (lo_inner < 0) { 87 | AddNegatedPowers(dst, lo_inner, std::min(hi_inner, T{-1}), mult); 88 | } 89 | 90 | // Treat 0 as a special case (see discussion on #762). 91 | if (lo < 0 && hi >= 0) { 92 | dst->push_back(0); 93 | } 94 | 95 | // Insert positive values 96 | if (hi_inner > 0) { 97 | AddPowers(dst, std::max(lo_inner, T{1}), hi_inner, mult); 98 | } 99 | 100 | // Add "hi" (if different from last value). 101 | if (hi != dst->back()) { 102 | dst->push_back(hi); 103 | } 104 | } 105 | 106 | } // namespace internal 107 | } // namespace benchmark 108 | 109 | #endif // BENCHMARK_REGISTER_H 110 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/benchmark_runner.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BENCHMARK_RUNNER_H_ 16 | #define BENCHMARK_RUNNER_H_ 17 | 18 | #include 19 | #include 20 | 21 | #include "benchmark_api_internal.h" 22 | #include "internal_macros.h" 23 | #include "perf_counters.h" 24 | #include "thread_manager.h" 25 | 26 | namespace benchmark { 27 | 28 | BM_DECLARE_string(benchmark_min_time); 29 | BM_DECLARE_double(benchmark_min_warmup_time); 30 | BM_DECLARE_int32(benchmark_repetitions); 31 | BM_DECLARE_bool(benchmark_report_aggregates_only); 32 | BM_DECLARE_bool(benchmark_display_aggregates_only); 33 | BM_DECLARE_string(benchmark_perf_counters); 34 | 35 | namespace internal { 36 | 37 | extern MemoryManager* memory_manager; 38 | 39 | struct RunResults { 40 | std::vector non_aggregates; 41 | std::vector aggregates_only; 42 | 43 | bool display_report_aggregates_only = false; 44 | bool file_report_aggregates_only = false; 45 | }; 46 | 47 | struct BENCHMARK_EXPORT BenchTimeType { 48 | enum { ITERS, TIME } tag; 49 | union { 50 | IterationCount iters; 51 | double time; 52 | }; 53 | }; 54 | 55 | BENCHMARK_EXPORT 56 | BenchTimeType ParseBenchMinTime(const std::string& value); 57 | 58 | class BenchmarkRunner { 59 | public: 60 | BenchmarkRunner(const benchmark::internal::BenchmarkInstance& b_, 61 | benchmark::internal::PerfCountersMeasurement* pmc_, 62 | BenchmarkReporter::PerFamilyRunReports* reports_for_family); 63 | 64 | int GetNumRepeats() const { return repeats; } 65 | 66 | bool HasRepeatsRemaining() const { 67 | return GetNumRepeats() != num_repetitions_done; 68 | } 69 | 70 | void DoOneRepetition(); 71 | 72 | RunResults&& GetResults(); 73 | 74 | BenchmarkReporter::PerFamilyRunReports* GetReportsForFamily() const { 75 | return reports_for_family; 76 | } 77 | 78 | double GetMinTime() const { return min_time; } 79 | 80 | bool HasExplicitIters() const { return has_explicit_iteration_count; } 81 | 82 | IterationCount GetIters() const { return iters; } 83 | 84 | private: 85 | RunResults run_results; 86 | 87 | const benchmark::internal::BenchmarkInstance& b; 88 | BenchmarkReporter::PerFamilyRunReports* reports_for_family; 89 | 90 | BenchTimeType parsed_benchtime_flag; 91 | const double min_time; 92 | const double min_warmup_time; 93 | bool warmup_done; 94 | const int repeats; 95 | const bool has_explicit_iteration_count; 96 | 97 | int num_repetitions_done = 0; 98 | 99 | std::vector pool; 100 | 101 | std::vector memory_results; 102 | 103 | IterationCount iters; // preserved between repetitions! 104 | // So only the first repetition has to find/calculate it, 105 | // the other repetitions will just use that precomputed iteration count. 106 | 107 | PerfCountersMeasurement* const perf_counters_measurement_ptr = nullptr; 108 | 109 | struct IterationResults { 110 | internal::ThreadManager::Result results; 111 | IterationCount iters; 112 | double seconds; 113 | }; 114 | IterationResults DoNIterations(); 115 | 116 | IterationCount PredictNumItersNeeded(const IterationResults& i) const; 117 | 118 | bool ShouldReportIterationResults(const IterationResults& i) const; 119 | 120 | double GetMinTimeToApply() const; 121 | 122 | void FinishWarmUp(const IterationCount& i); 123 | 124 | void RunWarmUp(); 125 | }; 126 | 127 | } // namespace internal 128 | 129 | } // end namespace benchmark 130 | 131 | #endif // BENCHMARK_RUNNER_H_ 132 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/check.cc: -------------------------------------------------------------------------------- 1 | #include "check.h" 2 | 3 | namespace benchmark { 4 | namespace internal { 5 | 6 | static AbortHandlerT* handler = &std::abort; 7 | 8 | BENCHMARK_EXPORT AbortHandlerT*& GetAbortHandler() { return handler; } 9 | 10 | } // namespace internal 11 | } // namespace benchmark 12 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/check.h: -------------------------------------------------------------------------------- 1 | #ifndef CHECK_H_ 2 | #define CHECK_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "benchmark/export.h" 9 | #include "internal_macros.h" 10 | #include "log.h" 11 | 12 | #if defined(__GNUC__) || defined(__clang__) 13 | #define BENCHMARK_NOEXCEPT noexcept 14 | #define BENCHMARK_NOEXCEPT_OP(x) noexcept(x) 15 | #elif defined(_MSC_VER) && !defined(__clang__) 16 | #if _MSC_VER >= 1900 17 | #define BENCHMARK_NOEXCEPT noexcept 18 | #define BENCHMARK_NOEXCEPT_OP(x) noexcept(x) 19 | #else 20 | #define BENCHMARK_NOEXCEPT 21 | #define BENCHMARK_NOEXCEPT_OP(x) 22 | #endif 23 | #define __func__ __FUNCTION__ 24 | #else 25 | #define BENCHMARK_NOEXCEPT 26 | #define BENCHMARK_NOEXCEPT_OP(x) 27 | #endif 28 | 29 | namespace benchmark { 30 | namespace internal { 31 | 32 | typedef void(AbortHandlerT)(); 33 | 34 | BENCHMARK_EXPORT 35 | AbortHandlerT*& GetAbortHandler(); 36 | 37 | BENCHMARK_NORETURN inline void CallAbortHandler() { 38 | GetAbortHandler()(); 39 | std::abort(); // fallback to enforce noreturn 40 | } 41 | 42 | // CheckHandler is the class constructed by failing BM_CHECK macros. 43 | // CheckHandler will log information about the failures and abort when it is 44 | // destructed. 45 | class CheckHandler { 46 | public: 47 | CheckHandler(const char* check, const char* file, const char* func, int line) 48 | : log_(GetErrorLogInstance()) { 49 | log_ << file << ":" << line << ": " << func << ": Check `" << check 50 | << "' failed. "; 51 | } 52 | 53 | LogType& GetLog() { return log_; } 54 | 55 | #if defined(COMPILER_MSVC) 56 | #pragma warning(push) 57 | #pragma warning(disable : 4722) 58 | #endif 59 | BENCHMARK_NORETURN ~CheckHandler() BENCHMARK_NOEXCEPT_OP(false) { 60 | log_ << std::endl; 61 | CallAbortHandler(); 62 | } 63 | #if defined(COMPILER_MSVC) 64 | #pragma warning(pop) 65 | #endif 66 | 67 | CheckHandler& operator=(const CheckHandler&) = delete; 68 | CheckHandler(const CheckHandler&) = delete; 69 | CheckHandler() = delete; 70 | 71 | private: 72 | LogType& log_; 73 | }; 74 | 75 | } // end namespace internal 76 | } // end namespace benchmark 77 | 78 | // The BM_CHECK macro returns a std::ostream object that can have extra 79 | // information written to it. 80 | #ifndef NDEBUG 81 | #define BM_CHECK(b) \ 82 | (b ? ::benchmark::internal::GetNullLogInstance() \ 83 | : ::benchmark::internal::CheckHandler(#b, __FILE__, __func__, __LINE__) \ 84 | .GetLog()) 85 | #else 86 | #define BM_CHECK(b) ::benchmark::internal::GetNullLogInstance() 87 | #endif 88 | 89 | // clang-format off 90 | // preserve whitespacing between operators for alignment 91 | #define BM_CHECK_EQ(a, b) BM_CHECK((a) == (b)) 92 | #define BM_CHECK_NE(a, b) BM_CHECK((a) != (b)) 93 | #define BM_CHECK_GE(a, b) BM_CHECK((a) >= (b)) 94 | #define BM_CHECK_LE(a, b) BM_CHECK((a) <= (b)) 95 | #define BM_CHECK_GT(a, b) BM_CHECK((a) > (b)) 96 | #define BM_CHECK_LT(a, b) BM_CHECK((a) < (b)) 97 | 98 | #define BM_CHECK_FLOAT_EQ(a, b, eps) BM_CHECK(std::fabs((a) - (b)) < (eps)) 99 | #define BM_CHECK_FLOAT_NE(a, b, eps) BM_CHECK(std::fabs((a) - (b)) >= (eps)) 100 | #define BM_CHECK_FLOAT_GE(a, b, eps) BM_CHECK((a) - (b) > -(eps)) 101 | #define BM_CHECK_FLOAT_LE(a, b, eps) BM_CHECK((b) - (a) > -(eps)) 102 | #define BM_CHECK_FLOAT_GT(a, b, eps) BM_CHECK((a) - (b) > (eps)) 103 | #define BM_CHECK_FLOAT_LT(a, b, eps) BM_CHECK((b) - (a) > (eps)) 104 | //clang-format on 105 | 106 | #endif // CHECK_H_ 107 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/colorprint.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_COLORPRINT_H_ 2 | #define BENCHMARK_COLORPRINT_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace benchmark { 9 | enum LogColor { 10 | COLOR_DEFAULT, 11 | COLOR_RED, 12 | COLOR_GREEN, 13 | COLOR_YELLOW, 14 | COLOR_BLUE, 15 | COLOR_MAGENTA, 16 | COLOR_CYAN, 17 | COLOR_WHITE 18 | }; 19 | 20 | std::string FormatString(const char* msg, va_list args); 21 | std::string FormatString(const char* msg, ...); 22 | 23 | void ColorPrintf(std::ostream& out, LogColor color, const char* fmt, 24 | va_list args); 25 | void ColorPrintf(std::ostream& out, LogColor color, const char* fmt, ...); 26 | 27 | // Returns true if stdout appears to be a terminal that supports colored 28 | // output, false otherwise. 29 | bool IsColorTerminal(); 30 | 31 | } // end namespace benchmark 32 | 33 | #endif // BENCHMARK_COLORPRINT_H_ 34 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/complexity.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Ismael Jimenez Martinez. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | // Source project : https://github.com/ismaelJimenez/cpp.leastsq 16 | // Adapted to be used with google benchmark 17 | 18 | #ifndef COMPLEXITY_H_ 19 | #define COMPLEXITY_H_ 20 | 21 | #include 22 | #include 23 | 24 | #include "benchmark/benchmark.h" 25 | 26 | namespace benchmark { 27 | 28 | // Return a vector containing the bigO and RMS information for the specified 29 | // list of reports. If 'reports.size() < 2' an empty vector is returned. 30 | std::vector ComputeBigO( 31 | const std::vector& reports); 32 | 33 | // This data structure will contain the result returned by MinimalLeastSq 34 | // - coef : Estimated coefficient for the high-order term as 35 | // interpolated from data. 36 | // - rms : Normalized Root Mean Squared Error. 37 | // - complexity : Scalability form (e.g. oN, oNLogN). In case a scalability 38 | // form has been provided to MinimalLeastSq this will return 39 | // the same value. In case BigO::oAuto has been selected, this 40 | // parameter will return the best fitting curve detected. 41 | 42 | struct LeastSq { 43 | LeastSq() : coef(0.0), rms(0.0), complexity(oNone) {} 44 | 45 | double coef; 46 | double rms; 47 | BigO complexity; 48 | }; 49 | 50 | // Function to return an string for the calculated complexity 51 | std::string GetBigOString(BigO complexity); 52 | 53 | } // end namespace benchmark 54 | 55 | #endif // COMPLEXITY_H_ 56 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/counter.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "counter.h" 16 | 17 | namespace benchmark { 18 | namespace internal { 19 | 20 | double Finish(Counter const& c, IterationCount iterations, double cpu_time, 21 | double num_threads) { 22 | double v = c.value; 23 | if (c.flags & Counter::kIsRate) { 24 | v /= cpu_time; 25 | } 26 | if (c.flags & Counter::kAvgThreads) { 27 | v /= num_threads; 28 | } 29 | if (c.flags & Counter::kIsIterationInvariant) { 30 | v *= static_cast(iterations); 31 | } 32 | if (c.flags & Counter::kAvgIterations) { 33 | v /= static_cast(iterations); 34 | } 35 | 36 | if (c.flags & Counter::kInvert) { // Invert is *always* last. 37 | v = 1.0 / v; 38 | } 39 | return v; 40 | } 41 | 42 | void Finish(UserCounters* l, IterationCount iterations, double cpu_time, 43 | double num_threads) { 44 | for (auto& c : *l) { 45 | c.second.value = Finish(c.second, iterations, cpu_time, num_threads); 46 | } 47 | } 48 | 49 | void Increment(UserCounters* l, UserCounters const& r) { 50 | // add counters present in both or just in *l 51 | for (auto& c : *l) { 52 | auto it = r.find(c.first); 53 | if (it != r.end()) { 54 | c.second.value = c.second + it->second; 55 | } 56 | } 57 | // add counters present in r, but not in *l 58 | for (auto const& tc : r) { 59 | auto it = l->find(tc.first); 60 | if (it == l->end()) { 61 | (*l)[tc.first] = tc.second; 62 | } 63 | } 64 | } 65 | 66 | bool SameNames(UserCounters const& l, UserCounters const& r) { 67 | if (&l == &r) return true; 68 | if (l.size() != r.size()) { 69 | return false; 70 | } 71 | for (auto const& c : l) { 72 | if (r.find(c.first) == r.end()) { 73 | return false; 74 | } 75 | } 76 | return true; 77 | } 78 | 79 | } // end namespace internal 80 | } // end namespace benchmark 81 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/counter.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BENCHMARK_COUNTER_H_ 16 | #define BENCHMARK_COUNTER_H_ 17 | 18 | #include "benchmark/benchmark.h" 19 | 20 | namespace benchmark { 21 | 22 | // these counter-related functions are hidden to reduce API surface. 23 | namespace internal { 24 | void Finish(UserCounters* l, IterationCount iterations, double time, 25 | double num_threads); 26 | void Increment(UserCounters* l, UserCounters const& r); 27 | bool SameNames(UserCounters const& l, UserCounters const& r); 28 | } // end namespace internal 29 | 30 | } // end namespace benchmark 31 | 32 | #endif // BENCHMARK_COUNTER_H_ 33 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/internal_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_INTERNAL_MACROS_H_ 2 | #define BENCHMARK_INTERNAL_MACROS_H_ 3 | 4 | /* Needed to detect STL */ 5 | #include 6 | 7 | // clang-format off 8 | 9 | #ifndef __has_feature 10 | #define __has_feature(x) 0 11 | #endif 12 | 13 | #if defined(__clang__) 14 | #if !defined(COMPILER_CLANG) 15 | #define COMPILER_CLANG 16 | #endif 17 | #elif defined(_MSC_VER) 18 | #if !defined(COMPILER_MSVC) 19 | #define COMPILER_MSVC 20 | #endif 21 | #elif defined(__GNUC__) 22 | #if !defined(COMPILER_GCC) 23 | #define COMPILER_GCC 24 | #endif 25 | #endif 26 | 27 | #if __has_feature(cxx_attributes) 28 | #define BENCHMARK_NORETURN [[noreturn]] 29 | #elif defined(__GNUC__) 30 | #define BENCHMARK_NORETURN __attribute__((noreturn)) 31 | #elif defined(COMPILER_MSVC) 32 | #define BENCHMARK_NORETURN __declspec(noreturn) 33 | #else 34 | #define BENCHMARK_NORETURN 35 | #endif 36 | 37 | #if defined(__CYGWIN__) 38 | #define BENCHMARK_OS_CYGWIN 1 39 | #elif defined(_WIN32) 40 | #define BENCHMARK_OS_WINDOWS 1 41 | // WINAPI_FAMILY_PARTITION is defined in winapifamily.h. 42 | // We include windows.h which implicitly includes winapifamily.h for compatibility. 43 | #ifndef NOMINMAX 44 | #define NOMINMAX 45 | #endif 46 | #include 47 | #if defined(WINAPI_FAMILY_PARTITION) 48 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 49 | #define BENCHMARK_OS_WINDOWS_WIN32 1 50 | #elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 51 | #define BENCHMARK_OS_WINDOWS_RT 1 52 | #endif 53 | #endif 54 | #if defined(__MINGW32__) 55 | #define BENCHMARK_OS_MINGW 1 56 | #endif 57 | #elif defined(__APPLE__) 58 | #define BENCHMARK_OS_APPLE 1 59 | #include "TargetConditionals.h" 60 | #if defined(TARGET_OS_MAC) 61 | #define BENCHMARK_OS_MACOSX 1 62 | #if defined(TARGET_OS_IPHONE) 63 | #define BENCHMARK_OS_IOS 1 64 | #endif 65 | #endif 66 | #elif defined(__FreeBSD__) 67 | #define BENCHMARK_OS_FREEBSD 1 68 | #elif defined(__NetBSD__) 69 | #define BENCHMARK_OS_NETBSD 1 70 | #elif defined(__OpenBSD__) 71 | #define BENCHMARK_OS_OPENBSD 1 72 | #elif defined(__DragonFly__) 73 | #define BENCHMARK_OS_DRAGONFLY 1 74 | #elif defined(__linux__) 75 | #define BENCHMARK_OS_LINUX 1 76 | #elif defined(__native_client__) 77 | #define BENCHMARK_OS_NACL 1 78 | #elif defined(__EMSCRIPTEN__) 79 | #define BENCHMARK_OS_EMSCRIPTEN 1 80 | #elif defined(__rtems__) 81 | #define BENCHMARK_OS_RTEMS 1 82 | #elif defined(__Fuchsia__) 83 | #define BENCHMARK_OS_FUCHSIA 1 84 | #elif defined (__SVR4) && defined (__sun) 85 | #define BENCHMARK_OS_SOLARIS 1 86 | #elif defined(__QNX__) 87 | #define BENCHMARK_OS_QNX 1 88 | #elif defined(__MVS__) 89 | #define BENCHMARK_OS_ZOS 1 90 | #elif defined(__hexagon__) 91 | #define BENCHMARK_OS_QURT 1 92 | #endif 93 | 94 | #if defined(__ANDROID__) && defined(__GLIBCXX__) 95 | #define BENCHMARK_STL_ANDROID_GNUSTL 1 96 | #endif 97 | 98 | #if !__has_feature(cxx_exceptions) && !defined(__cpp_exceptions) \ 99 | && !defined(__EXCEPTIONS) 100 | #define BENCHMARK_HAS_NO_EXCEPTIONS 101 | #endif 102 | 103 | #if defined(COMPILER_CLANG) || defined(COMPILER_GCC) 104 | #define BENCHMARK_MAYBE_UNUSED __attribute__((unused)) 105 | #else 106 | #define BENCHMARK_MAYBE_UNUSED 107 | #endif 108 | 109 | // clang-format on 110 | 111 | #endif // BENCHMARK_INTERNAL_MACROS_H_ 112 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/log.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_LOG_H_ 2 | #define BENCHMARK_LOG_H_ 3 | 4 | #include 5 | #include 6 | 7 | // NOTE: this is also defined in benchmark.h but we're trying to avoid a 8 | // dependency. 9 | // The _MSVC_LANG check should detect Visual Studio 2015 Update 3 and newer. 10 | #if __cplusplus >= 201103L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201103L) 11 | #define BENCHMARK_HAS_CXX11 12 | #endif 13 | 14 | namespace benchmark { 15 | namespace internal { 16 | 17 | typedef std::basic_ostream&(EndLType)(std::basic_ostream&); 18 | 19 | class LogType { 20 | friend LogType& GetNullLogInstance(); 21 | friend LogType& GetErrorLogInstance(); 22 | 23 | // FIXME: Add locking to output. 24 | template 25 | friend LogType& operator<<(LogType&, Tp const&); 26 | friend LogType& operator<<(LogType&, EndLType*); 27 | 28 | private: 29 | LogType(std::ostream* out) : out_(out) {} 30 | std::ostream* out_; 31 | 32 | // NOTE: we could use BENCHMARK_DISALLOW_COPY_AND_ASSIGN but we shouldn't have 33 | // a dependency on benchmark.h from here. 34 | #ifndef BENCHMARK_HAS_CXX11 35 | LogType(const LogType&); 36 | LogType& operator=(const LogType&); 37 | #else 38 | LogType(const LogType&) = delete; 39 | LogType& operator=(const LogType&) = delete; 40 | #endif 41 | }; 42 | 43 | template 44 | LogType& operator<<(LogType& log, Tp const& value) { 45 | if (log.out_) { 46 | *log.out_ << value; 47 | } 48 | return log; 49 | } 50 | 51 | inline LogType& operator<<(LogType& log, EndLType* m) { 52 | if (log.out_) { 53 | *log.out_ << m; 54 | } 55 | return log; 56 | } 57 | 58 | inline int& LogLevel() { 59 | static int log_level = 0; 60 | return log_level; 61 | } 62 | 63 | inline LogType& GetNullLogInstance() { 64 | static LogType null_log(static_cast(nullptr)); 65 | return null_log; 66 | } 67 | 68 | inline LogType& GetErrorLogInstance() { 69 | static LogType error_log(&std::clog); 70 | return error_log; 71 | } 72 | 73 | inline LogType& GetLogInstanceForLevel(int level) { 74 | if (level <= LogLevel()) { 75 | return GetErrorLogInstance(); 76 | } 77 | return GetNullLogInstance(); 78 | } 79 | 80 | } // end namespace internal 81 | } // end namespace benchmark 82 | 83 | // clang-format off 84 | #define BM_VLOG(x) \ 85 | (::benchmark::internal::GetLogInstanceForLevel(x) << "-- LOG(" << x << "):" \ 86 | " ") 87 | // clang-format on 88 | #endif 89 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/re.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef BENCHMARK_RE_H_ 16 | #define BENCHMARK_RE_H_ 17 | 18 | #include "internal_macros.h" 19 | 20 | // clang-format off 21 | 22 | #if !defined(HAVE_STD_REGEX) && \ 23 | !defined(HAVE_GNU_POSIX_REGEX) && \ 24 | !defined(HAVE_POSIX_REGEX) 25 | // No explicit regex selection; detect based on builtin hints. 26 | #if defined(BENCHMARK_OS_LINUX) || defined(BENCHMARK_OS_APPLE) 27 | #define HAVE_POSIX_REGEX 1 28 | #elif __cplusplus >= 199711L 29 | #define HAVE_STD_REGEX 1 30 | #endif 31 | #endif 32 | 33 | // Prefer C regex libraries when compiling w/o exceptions so that we can 34 | // correctly report errors. 35 | #if defined(BENCHMARK_HAS_NO_EXCEPTIONS) && \ 36 | defined(HAVE_STD_REGEX) && \ 37 | (defined(HAVE_GNU_POSIX_REGEX) || defined(HAVE_POSIX_REGEX)) 38 | #undef HAVE_STD_REGEX 39 | #endif 40 | 41 | #if defined(HAVE_STD_REGEX) 42 | #include 43 | #elif defined(HAVE_GNU_POSIX_REGEX) 44 | #include 45 | #elif defined(HAVE_POSIX_REGEX) 46 | #include 47 | #else 48 | #error No regular expression backend was found! 49 | #endif 50 | 51 | // clang-format on 52 | 53 | #include 54 | 55 | #include "check.h" 56 | 57 | namespace benchmark { 58 | 59 | // A wrapper around the POSIX regular expression API that provides automatic 60 | // cleanup 61 | class Regex { 62 | public: 63 | Regex() : init_(false) {} 64 | 65 | ~Regex(); 66 | 67 | // Compile a regular expression matcher from spec. Returns true on success. 68 | // 69 | // On failure (and if error is not nullptr), error is populated with a human 70 | // readable error message if an error occurs. 71 | bool Init(const std::string& spec, std::string* error); 72 | 73 | // Returns whether str matches the compiled regular expression. 74 | bool Match(const std::string& str); 75 | 76 | private: 77 | bool init_; 78 | // Underlying regular expression object 79 | #if defined(HAVE_STD_REGEX) 80 | std::regex re_; 81 | #elif defined(HAVE_POSIX_REGEX) || defined(HAVE_GNU_POSIX_REGEX) 82 | regex_t re_; 83 | #else 84 | #error No regular expression backend implementation available 85 | #endif 86 | }; 87 | 88 | #if defined(HAVE_STD_REGEX) 89 | 90 | inline bool Regex::Init(const std::string& spec, std::string* error) { 91 | #ifdef BENCHMARK_HAS_NO_EXCEPTIONS 92 | ((void)error); // suppress unused warning 93 | #else 94 | try { 95 | #endif 96 | re_ = std::regex(spec, std::regex_constants::extended); 97 | init_ = true; 98 | #ifndef BENCHMARK_HAS_NO_EXCEPTIONS 99 | } 100 | catch (const std::regex_error& e) { 101 | if (error) { 102 | *error = e.what(); 103 | } 104 | } 105 | #endif 106 | return init_; 107 | } 108 | 109 | inline Regex::~Regex() {} 110 | 111 | inline bool Regex::Match(const std::string& str) { 112 | if (!init_) { 113 | return false; 114 | } 115 | return std::regex_search(str, re_); 116 | } 117 | 118 | #else 119 | inline bool Regex::Init(const std::string& spec, std::string* error) { 120 | int ec = regcomp(&re_, spec.c_str(), REG_EXTENDED | REG_NOSUB); 121 | if (ec != 0) { 122 | if (error) { 123 | size_t needed = regerror(ec, &re_, nullptr, 0); 124 | char* errbuf = new char[needed]; 125 | regerror(ec, &re_, errbuf, needed); 126 | 127 | // regerror returns the number of bytes necessary to null terminate 128 | // the string, so we move that when assigning to error. 129 | BM_CHECK_NE(needed, 0); 130 | error->assign(errbuf, needed - 1); 131 | 132 | delete[] errbuf; 133 | } 134 | 135 | return false; 136 | } 137 | 138 | init_ = true; 139 | return true; 140 | } 141 | 142 | inline Regex::~Regex() { 143 | if (init_) { 144 | regfree(&re_); 145 | } 146 | } 147 | 148 | inline bool Regex::Match(const std::string& str) { 149 | if (!init_) { 150 | return false; 151 | } 152 | return regexec(&re_, str.c_str(), 0, nullptr, 0) == 0; 153 | } 154 | #endif 155 | 156 | } // end namespace benchmark 157 | 158 | #endif // BENCHMARK_RE_H_ 159 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/reporter.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google Inc. All rights reserved. 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | #include "benchmark/benchmark.h" 23 | #include "check.h" 24 | #include "string_util.h" 25 | #include "timers.h" 26 | 27 | namespace benchmark { 28 | 29 | BenchmarkReporter::BenchmarkReporter() 30 | : output_stream_(&std::cout), error_stream_(&std::cerr) {} 31 | 32 | BenchmarkReporter::~BenchmarkReporter() {} 33 | 34 | void BenchmarkReporter::PrintBasicContext(std::ostream *out, 35 | Context const &context) { 36 | BM_CHECK(out) << "cannot be null"; 37 | auto &Out = *out; 38 | 39 | #ifndef BENCHMARK_OS_QURT 40 | // Date/time information is not available on QuRT. 41 | // Attempting to get it via this call cause the binary to crash. 42 | Out << LocalDateTimeString() << "\n"; 43 | #endif 44 | 45 | if (context.executable_name) 46 | Out << "Running " << context.executable_name << "\n"; 47 | 48 | const CPUInfo &info = context.cpu_info; 49 | Out << "Run on (" << info.num_cpus << " X " 50 | << (info.cycles_per_second / 1000000.0) << " MHz CPU " 51 | << ((info.num_cpus > 1) ? "s" : "") << ")\n"; 52 | if (info.caches.size() != 0) { 53 | Out << "CPU Caches:\n"; 54 | for (auto &CInfo : info.caches) { 55 | Out << " L" << CInfo.level << " " << CInfo.type << " " 56 | << (CInfo.size / 1024) << " KiB"; 57 | if (CInfo.num_sharing != 0) 58 | Out << " (x" << (info.num_cpus / CInfo.num_sharing) << ")"; 59 | Out << "\n"; 60 | } 61 | } 62 | if (!info.load_avg.empty()) { 63 | Out << "Load Average: "; 64 | for (auto It = info.load_avg.begin(); It != info.load_avg.end();) { 65 | Out << StrFormat("%.2f", *It++); 66 | if (It != info.load_avg.end()) Out << ", "; 67 | } 68 | Out << "\n"; 69 | } 70 | 71 | std::map *global_context = 72 | internal::GetGlobalContext(); 73 | 74 | if (global_context != nullptr) { 75 | for (const auto &kv : *global_context) { 76 | Out << kv.first << ": " << kv.second << "\n"; 77 | } 78 | } 79 | 80 | if (CPUInfo::Scaling::ENABLED == info.scaling) { 81 | Out << "***WARNING*** CPU scaling is enabled, the benchmark " 82 | "real time measurements may be noisy and will incur extra " 83 | "overhead.\n"; 84 | } 85 | 86 | #ifndef NDEBUG 87 | Out << "***WARNING*** Library was built as DEBUG. Timings may be " 88 | "affected.\n"; 89 | #endif 90 | } 91 | 92 | // No initializer because it's already initialized to NULL. 93 | const char *BenchmarkReporter::Context::executable_name; 94 | 95 | BenchmarkReporter::Context::Context() 96 | : cpu_info(CPUInfo::Get()), sys_info(SystemInfo::Get()) {} 97 | 98 | std::string BenchmarkReporter::Run::benchmark_name() const { 99 | std::string name = run_name.str(); 100 | if (run_type == RT_Aggregate) { 101 | name += "_" + aggregate_name; 102 | } 103 | return name; 104 | } 105 | 106 | double BenchmarkReporter::Run::GetAdjustedRealTime() const { 107 | double new_time = real_accumulated_time * GetTimeUnitMultiplier(time_unit); 108 | if (iterations != 0) new_time /= static_cast(iterations); 109 | return new_time; 110 | } 111 | 112 | double BenchmarkReporter::Run::GetAdjustedCPUTime() const { 113 | double new_time = cpu_accumulated_time * GetTimeUnitMultiplier(time_unit); 114 | if (iterations != 0) new_time /= static_cast(iterations); 115 | return new_time; 116 | } 117 | 118 | } // end namespace benchmark 119 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/statistics.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 Ismael Jimenez Martinez. All rights reserved. 2 | // Copyright 2017 Roman Lebedev. All rights reserved. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | #ifndef STATISTICS_H_ 17 | #define STATISTICS_H_ 18 | 19 | #include 20 | 21 | #include "benchmark/benchmark.h" 22 | 23 | namespace benchmark { 24 | 25 | // Return a vector containing the mean, median and standard deviation 26 | // information (and any user-specified info) for the specified list of reports. 27 | // If 'reports' contains less than two non-errored runs an empty vector is 28 | // returned 29 | BENCHMARK_EXPORT 30 | std::vector ComputeStats( 31 | const std::vector& reports); 32 | 33 | BENCHMARK_EXPORT 34 | double StatisticsMean(const std::vector& v); 35 | BENCHMARK_EXPORT 36 | double StatisticsMedian(const std::vector& v); 37 | BENCHMARK_EXPORT 38 | double StatisticsStdDev(const std::vector& v); 39 | BENCHMARK_EXPORT 40 | double StatisticsCV(const std::vector& v); 41 | 42 | } // end namespace benchmark 43 | 44 | #endif // STATISTICS_H_ 45 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/string_util.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_STRING_UTIL_H_ 2 | #define BENCHMARK_STRING_UTIL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "benchmark/benchmark.h" 10 | #include "benchmark/export.h" 11 | #include "check.h" 12 | #include "internal_macros.h" 13 | 14 | namespace benchmark { 15 | 16 | BENCHMARK_EXPORT 17 | std::string HumanReadableNumber(double n, Counter::OneK one_k); 18 | 19 | BENCHMARK_EXPORT 20 | #if defined(__MINGW32__) 21 | __attribute__((format(__MINGW_PRINTF_FORMAT, 1, 2))) 22 | #elif defined(__GNUC__) 23 | __attribute__((format(printf, 1, 2))) 24 | #endif 25 | std::string 26 | StrFormat(const char* format, ...); 27 | 28 | inline std::ostream& StrCatImp(std::ostream& out) BENCHMARK_NOEXCEPT { 29 | return out; 30 | } 31 | 32 | template 33 | inline std::ostream& StrCatImp(std::ostream& out, First&& f, Rest&&... rest) { 34 | out << std::forward(f); 35 | return StrCatImp(out, std::forward(rest)...); 36 | } 37 | 38 | template 39 | inline std::string StrCat(Args&&... args) { 40 | std::ostringstream ss; 41 | StrCatImp(ss, std::forward(args)...); 42 | return ss.str(); 43 | } 44 | 45 | BENCHMARK_EXPORT 46 | std::vector StrSplit(const std::string& str, char delim); 47 | 48 | // Disable lint checking for this block since it re-implements C functions. 49 | // NOLINTBEGIN 50 | #ifdef BENCHMARK_STL_ANDROID_GNUSTL 51 | /* 52 | * GNU STL in Android NDK lacks support for some C++11 functions, including 53 | * stoul, stoi, stod. We reimplement them here using C functions strtoul, 54 | * strtol, strtod. Note that reimplemented functions are in benchmark:: 55 | * namespace, not std:: namespace. 56 | */ 57 | unsigned long stoul(const std::string& str, size_t* pos = nullptr, 58 | int base = 10); 59 | int stoi(const std::string& str, size_t* pos = nullptr, int base = 10); 60 | double stod(const std::string& str, size_t* pos = nullptr); 61 | #else 62 | using std::stod; // NOLINT(misc-unused-using-decls) 63 | using std::stoi; // NOLINT(misc-unused-using-decls) 64 | using std::stoul; // NOLINT(misc-unused-using-decls) 65 | #endif 66 | // NOLINTEND 67 | 68 | } // end namespace benchmark 69 | 70 | #endif // BENCHMARK_STRING_UTIL_H_ 71 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/thread_manager.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_THREAD_MANAGER_H 2 | #define BENCHMARK_THREAD_MANAGER_H 3 | 4 | #include 5 | 6 | #include "benchmark/benchmark.h" 7 | #include "mutex.h" 8 | 9 | namespace benchmark { 10 | namespace internal { 11 | 12 | class ThreadManager { 13 | public: 14 | explicit ThreadManager(int num_threads) 15 | : alive_threads_(num_threads), start_stop_barrier_(num_threads) {} 16 | 17 | Mutex& GetBenchmarkMutex() const RETURN_CAPABILITY(benchmark_mutex_) { 18 | return benchmark_mutex_; 19 | } 20 | 21 | bool StartStopBarrier() EXCLUDES(end_cond_mutex_) { 22 | return start_stop_barrier_.wait(); 23 | } 24 | 25 | void NotifyThreadComplete() EXCLUDES(end_cond_mutex_) { 26 | start_stop_barrier_.removeThread(); 27 | if (--alive_threads_ == 0) { 28 | MutexLock lock(end_cond_mutex_); 29 | end_condition_.notify_all(); 30 | } 31 | } 32 | 33 | void WaitForAllThreads() EXCLUDES(end_cond_mutex_) { 34 | MutexLock lock(end_cond_mutex_); 35 | end_condition_.wait(lock.native_handle(), 36 | [this]() { return alive_threads_ == 0; }); 37 | } 38 | 39 | struct Result { 40 | IterationCount iterations = 0; 41 | double real_time_used = 0; 42 | double cpu_time_used = 0; 43 | double manual_time_used = 0; 44 | int64_t complexity_n = 0; 45 | std::string report_label_; 46 | std::string skip_message_; 47 | internal::Skipped skipped_ = internal::NotSkipped; 48 | UserCounters counters; 49 | }; 50 | GUARDED_BY(GetBenchmarkMutex()) Result results; 51 | 52 | private: 53 | mutable Mutex benchmark_mutex_; 54 | std::atomic alive_threads_; 55 | Barrier start_stop_barrier_; 56 | Mutex end_cond_mutex_; 57 | Condition end_condition_; 58 | }; 59 | 60 | } // namespace internal 61 | } // namespace benchmark 62 | 63 | #endif // BENCHMARK_THREAD_MANAGER_H 64 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/thread_timer.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_THREAD_TIMER_H 2 | #define BENCHMARK_THREAD_TIMER_H 3 | 4 | #include "check.h" 5 | #include "timers.h" 6 | 7 | namespace benchmark { 8 | namespace internal { 9 | 10 | class ThreadTimer { 11 | explicit ThreadTimer(bool measure_process_cpu_time_) 12 | : measure_process_cpu_time(measure_process_cpu_time_) {} 13 | 14 | public: 15 | static ThreadTimer Create() { 16 | return ThreadTimer(/*measure_process_cpu_time_=*/false); 17 | } 18 | static ThreadTimer CreateProcessCpuTime() { 19 | return ThreadTimer(/*measure_process_cpu_time_=*/true); 20 | } 21 | 22 | // Called by each thread 23 | void StartTimer() { 24 | running_ = true; 25 | start_real_time_ = ChronoClockNow(); 26 | start_cpu_time_ = ReadCpuTimerOfChoice(); 27 | } 28 | 29 | // Called by each thread 30 | void StopTimer() { 31 | BM_CHECK(running_); 32 | running_ = false; 33 | real_time_used_ += ChronoClockNow() - start_real_time_; 34 | // Floating point error can result in the subtraction producing a negative 35 | // time. Guard against that. 36 | cpu_time_used_ += 37 | std::max(ReadCpuTimerOfChoice() - start_cpu_time_, 0); 38 | } 39 | 40 | // Called by each thread 41 | void SetIterationTime(double seconds) { manual_time_used_ += seconds; } 42 | 43 | bool running() const { return running_; } 44 | 45 | // REQUIRES: timer is not running 46 | double real_time_used() const { 47 | BM_CHECK(!running_); 48 | return real_time_used_; 49 | } 50 | 51 | // REQUIRES: timer is not running 52 | double cpu_time_used() const { 53 | BM_CHECK(!running_); 54 | return cpu_time_used_; 55 | } 56 | 57 | // REQUIRES: timer is not running 58 | double manual_time_used() const { 59 | BM_CHECK(!running_); 60 | return manual_time_used_; 61 | } 62 | 63 | private: 64 | double ReadCpuTimerOfChoice() const { 65 | if (measure_process_cpu_time) return ProcessCPUUsage(); 66 | return ThreadCPUUsage(); 67 | } 68 | 69 | // should the thread, or the process, time be measured? 70 | const bool measure_process_cpu_time; 71 | 72 | bool running_ = false; // Is the timer running 73 | double start_real_time_ = 0; // If running_ 74 | double start_cpu_time_ = 0; // If running_ 75 | 76 | // Accumulated time so far (does not contain current slice if running_) 77 | double real_time_used_ = 0; 78 | double cpu_time_used_ = 0; 79 | // Manually set iteration time. User sets this with SetIterationTime(seconds). 80 | double manual_time_used_ = 0; 81 | }; 82 | 83 | } // namespace internal 84 | } // namespace benchmark 85 | 86 | #endif // BENCHMARK_THREAD_TIMER_H 87 | -------------------------------------------------------------------------------- /3rdparty/gbench/src/timers.h: -------------------------------------------------------------------------------- 1 | #ifndef BENCHMARK_TIMERS_H 2 | #define BENCHMARK_TIMERS_H 3 | 4 | #include 5 | #include 6 | 7 | namespace benchmark { 8 | 9 | // Return the CPU usage of the current process 10 | double ProcessCPUUsage(); 11 | 12 | // Return the CPU usage of the children of the current process 13 | double ChildrenCPUUsage(); 14 | 15 | // Return the CPU usage of the current thread 16 | double ThreadCPUUsage(); 17 | 18 | #if defined(HAVE_STEADY_CLOCK) 19 | template 20 | struct ChooseSteadyClock { 21 | typedef std::chrono::high_resolution_clock type; 22 | }; 23 | 24 | template <> 25 | struct ChooseSteadyClock { 26 | typedef std::chrono::steady_clock type; 27 | }; 28 | #endif 29 | 30 | struct ChooseClockType { 31 | #if defined(HAVE_STEADY_CLOCK) 32 | typedef ChooseSteadyClock<>::type type; 33 | #else 34 | typedef std::chrono::high_resolution_clock type; 35 | #endif 36 | }; 37 | 38 | inline double ChronoClockNow() { 39 | typedef ChooseClockType::type ClockType; 40 | using FpSeconds = std::chrono::duration; 41 | return FpSeconds(ClockType::now().time_since_epoch()).count(); 42 | } 43 | 44 | std::string LocalDateTimeString(); 45 | 46 | } // end namespace benchmark 47 | 48 | #endif // BENCHMARK_TIMERS_H 49 | -------------------------------------------------------------------------------- /3rdparty/gtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Note: CMake support is community-based. The maintainers do not use CMake 2 | # internally. 3 | 4 | cmake_minimum_required(VERSION 3.13) 5 | 6 | project(googletest-distribution) 7 | set(GOOGLETEST_VERSION 1.14.0) 8 | 9 | if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) 10 | set(CMAKE_CXX_EXTENSIONS OFF) 11 | endif() 12 | 13 | enable_testing() 14 | 15 | include(CMakeDependentOption) 16 | include(GNUInstallDirs) 17 | 18 | #Note that googlemock target already builds googletest 19 | option(BUILD_GMOCK "Builds the googlemock subproject" OFF) 20 | option(INSTALL_GTEST "Enable installation of googletest. (Projects embedding googletest may want to turn this OFF.)" OFF) 21 | option(GTEST_HAS_ABSL "Use Abseil and RE2. Requires Abseil and RE2 to be separately added to the build." OFF) 22 | 23 | if(BUILD_GMOCK) 24 | add_subdirectory( googlemock ) 25 | else() 26 | add_subdirectory( googletest ) 27 | endif() 28 | -------------------------------------------------------------------------------- /3rdparty/gtest/VERSION: -------------------------------------------------------------------------------- 1 | https://github.com/google/googletest/tree/v1.14.0 -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/cmake/Config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | include(CMakeFindDependencyMacro) 3 | if (@GTEST_HAS_PTHREAD@) 4 | set(THREADS_PREFER_PTHREAD_FLAG @THREADS_PREFER_PTHREAD_FLAG@) 5 | find_dependency(Threads) 6 | endif() 7 | 8 | include("${CMAKE_CURRENT_LIST_DIR}/@targets_export_name@.cmake") 9 | check_required_components("@project_name@") 10 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/cmake/gtest.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest 5 | Description: GoogleTest (without main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Libs: -L${libdir} -lgtest @CMAKE_THREAD_LIBS_INIT@ 9 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 10 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/cmake/gtest_main.pc.in: -------------------------------------------------------------------------------- 1 | libdir=@CMAKE_INSTALL_FULL_LIBDIR@ 2 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 3 | 4 | Name: gtest_main 5 | Description: GoogleTest (with main() function) 6 | Version: @PROJECT_VERSION@ 7 | URL: https://github.com/google/googletest 8 | Requires: gtest = @PROJECT_VERSION@ 9 | Libs: -L${libdir} -lgtest_main @CMAKE_THREAD_LIBS_INIT@ 10 | Cflags: -I${includedir} @GTEST_HAS_PTHREAD_MACRO@ 11 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/cmake/libgtest.la.in: -------------------------------------------------------------------------------- 1 | # libgtest.la - a libtool library file 2 | # Generated by libtool (GNU libtool) 2.4.6 3 | 4 | # Please DO NOT delete this file! 5 | # It is necessary for linking the library. 6 | 7 | # Names of this library. 8 | library_names='libgtest.so' 9 | 10 | # Is this an already installed library? 11 | installed=yes 12 | 13 | # Should we warn about portability when linking against -modules? 14 | shouldnotlink=no 15 | 16 | # Files to dlopen/dlpreopen 17 | dlopen='' 18 | dlpreopen='' 19 | 20 | # Directory that this library needs to be installed in: 21 | libdir='@CMAKE_INSTALL_FULL_LIBDIR@' 22 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/include/gtest/gtest_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // Google C++ Testing and Mocking Framework definitions useful in production 31 | // code. 32 | 33 | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 34 | #define GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 35 | 36 | // When you need to test the private or protected members of a class, 37 | // use the FRIEND_TEST macro to declare your tests as friends of the 38 | // class. For example: 39 | // 40 | // class MyClass { 41 | // private: 42 | // void PrivateMethod(); 43 | // FRIEND_TEST(MyClassTest, PrivateMethodWorks); 44 | // }; 45 | // 46 | // class MyClassTest : public testing::Test { 47 | // // ... 48 | // }; 49 | // 50 | // TEST_F(MyClassTest, PrivateMethodWorks) { 51 | // // Can call MyClass::PrivateMethod() here. 52 | // } 53 | // 54 | // Note: The test class must be in the same namespace as the class being tested. 55 | // For example, putting MyClassTest in an anonymous namespace will not work. 56 | 57 | #define FRIEND_TEST(test_case_name, test_name) \ 58 | friend class test_case_name##_##test_name##_Test 59 | 60 | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_PROD_H_ 61 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/include/gtest/internal/custom/README.md: -------------------------------------------------------------------------------- 1 | # Customization Points 2 | 3 | The custom directory is an injection point for custom user configurations. 4 | 5 | ## Header `gtest.h` 6 | 7 | ### The following macros can be defined: 8 | 9 | * `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of 10 | `OsStackTraceGetterInterface`. 11 | * `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See 12 | `testing::TempDir` for semantics and signature. 13 | 14 | ## Header `gtest-port.h` 15 | 16 | The following macros can be defined: 17 | 18 | ### Logging: 19 | 20 | * `GTEST_LOG_(severity)` 21 | * `GTEST_CHECK_(condition)` 22 | * Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. 23 | 24 | ### Threading: 25 | 26 | * `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. 27 | * `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` 28 | are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` 29 | and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` 30 | * `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` 31 | * `GTEST_LOCK_EXCLUDED_(locks)` 32 | 33 | ### Underlying library support features 34 | 35 | * `GTEST_HAS_CXXABI_H_` 36 | 37 | ### Exporting API symbols: 38 | 39 | * `GTEST_API_` - Specifier for exported symbols. 40 | 41 | ## Header `gtest-printers.h` 42 | 43 | * See documentation at `gtest/gtest-printers.h` for details on how to define a 44 | custom printer. 45 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/include/gtest/internal/custom/gtest-port.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ 38 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/include/gtest/internal/custom/gtest-printers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // This file provides an injection point for custom printers in a local 31 | // installation of gTest. 32 | // It will be included from gtest-printers.h and the overrides in this file 33 | // will be visible to everyone. 34 | // 35 | // Injection point for custom user configurations. See README for details 36 | // 37 | // ** Custom implementation starts here ** 38 | 39 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 40 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 41 | 42 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ 43 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/include/gtest/internal/custom/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | // 30 | // Injection point for custom user configurations. See README for details 31 | // 32 | // ** Custom implementation starts here ** 33 | 34 | #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 35 | #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 36 | 37 | #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ 38 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest-all.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // Google C++ Testing and Mocking Framework (Google Test) 32 | // 33 | // Sometimes it's desirable to build Google Test by compiling a single file. 34 | // This file serves this purpose. 35 | 36 | // This line ensures that gtest.h can be compiled on its own, even 37 | // when it's fused. 38 | #include "gtest/gtest.h" 39 | 40 | // The following lines pull in the real gtest *.cc files. 41 | #include "src/gtest-assertion-result.cc" 42 | #include "src/gtest-death-test.cc" 43 | #include "src/gtest-filepath.cc" 44 | #include "src/gtest-matchers.cc" 45 | #include "src/gtest-port.cc" 46 | #include "src/gtest-printers.cc" 47 | #include "src/gtest-test-part.cc" 48 | #include "src/gtest-typed-test.cc" 49 | #include "src/gtest.cc" 50 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest-assertion-result.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2005, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This file defines the AssertionResult type. 33 | 34 | #include "gtest/gtest-assertion-result.h" 35 | 36 | #include 37 | #include 38 | 39 | #include "gtest/gtest-message.h" 40 | 41 | namespace testing { 42 | 43 | // AssertionResult constructors. 44 | // Used in EXPECT_TRUE/FALSE(assertion_result). 45 | AssertionResult::AssertionResult(const AssertionResult& other) 46 | : success_(other.success_), 47 | message_(other.message_ != nullptr 48 | ? new ::std::string(*other.message_) 49 | : static_cast< ::std::string*>(nullptr)) {} 50 | 51 | // Swaps two AssertionResults. 52 | void AssertionResult::swap(AssertionResult& other) { 53 | using std::swap; 54 | swap(success_, other.success_); 55 | swap(message_, other.message_); 56 | } 57 | 58 | // Returns the assertion's negation. Used with EXPECT/ASSERT_FALSE. 59 | AssertionResult AssertionResult::operator!() const { 60 | AssertionResult negation(!success_); 61 | if (message_ != nullptr) negation << *message_; 62 | return negation; 63 | } 64 | 65 | // Makes a successful assertion result. 66 | AssertionResult AssertionSuccess() { return AssertionResult(true); } 67 | 68 | // Makes a failed assertion result. 69 | AssertionResult AssertionFailure() { return AssertionResult(false); } 70 | 71 | // Makes a failed assertion result with the given failure message. 72 | // Deprecated; use AssertionFailure() << message. 73 | AssertionResult AssertionFailure(const Message& message) { 74 | return AssertionFailure() << message; 75 | } 76 | 77 | } // namespace testing 78 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest-matchers.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2007, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // The Google C++ Testing and Mocking Framework (Google Test) 31 | // 32 | // This file implements just enough of the matcher interface to allow 33 | // EXPECT_DEATH and friends to accept a matcher argument. 34 | 35 | #include "gtest/gtest-matchers.h" 36 | 37 | #include 38 | 39 | #include "gtest/internal/gtest-internal.h" 40 | #include "gtest/internal/gtest-port.h" 41 | 42 | namespace testing { 43 | 44 | // Constructs a matcher that matches a const std::string& whose value is 45 | // equal to s. 46 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 47 | 48 | // Constructs a matcher that matches a const std::string& whose value is 49 | // equal to s. 50 | Matcher::Matcher(const char* s) { 51 | *this = Eq(std::string(s)); 52 | } 53 | 54 | // Constructs a matcher that matches a std::string whose value is equal to 55 | // s. 56 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 57 | 58 | // Constructs a matcher that matches a std::string whose value is equal to 59 | // s. 60 | Matcher::Matcher(const char* s) { *this = Eq(std::string(s)); } 61 | 62 | #if GTEST_INTERNAL_HAS_STRING_VIEW 63 | // Constructs a matcher that matches a const StringView& whose value is 64 | // equal to s. 65 | Matcher::Matcher(const std::string& s) { 66 | *this = Eq(s); 67 | } 68 | 69 | // Constructs a matcher that matches a const StringView& whose value is 70 | // equal to s. 71 | Matcher::Matcher(const char* s) { 72 | *this = Eq(std::string(s)); 73 | } 74 | 75 | // Constructs a matcher that matches a const StringView& whose value is 76 | // equal to s. 77 | Matcher::Matcher(internal::StringView s) { 78 | *this = Eq(std::string(s)); 79 | } 80 | 81 | // Constructs a matcher that matches a StringView whose value is equal to 82 | // s. 83 | Matcher::Matcher(const std::string& s) { *this = Eq(s); } 84 | 85 | // Constructs a matcher that matches a StringView whose value is equal to 86 | // s. 87 | Matcher::Matcher(const char* s) { 88 | *this = Eq(std::string(s)); 89 | } 90 | 91 | // Constructs a matcher that matches a StringView whose value is equal to 92 | // s. 93 | Matcher::Matcher(internal::StringView s) { 94 | *this = Eq(std::string(s)); 95 | } 96 | #endif // GTEST_INTERNAL_HAS_STRING_VIEW 97 | 98 | } // namespace testing 99 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest-test-part.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | // 31 | // The Google C++ Testing and Mocking Framework (Google Test) 32 | 33 | #include "gtest/gtest-test-part.h" 34 | 35 | #include 36 | #include 37 | 38 | #include "gtest/internal/gtest-port.h" 39 | #include "src/gtest-internal-inl.h" 40 | 41 | namespace testing { 42 | 43 | // Gets the summary of the failure message by omitting the stack trace 44 | // in it. 45 | std::string TestPartResult::ExtractSummary(const char* message) { 46 | const char* const stack_trace = strstr(message, internal::kStackTraceMarker); 47 | return stack_trace == nullptr ? message : std::string(message, stack_trace); 48 | } 49 | 50 | // Prints a TestPartResult object. 51 | std::ostream& operator<<(std::ostream& os, const TestPartResult& result) { 52 | return os << internal::FormatFileLocation(result.file_name(), 53 | result.line_number()) 54 | << " " 55 | << (result.type() == TestPartResult::kSuccess ? "Success" 56 | : result.type() == TestPartResult::kSkip ? "Skipped" 57 | : result.type() == TestPartResult::kFatalFailure 58 | ? "Fatal failure" 59 | : "Non-fatal failure") 60 | << ":\n" 61 | << result.message() << std::endl; 62 | } 63 | 64 | // Appends a TestPartResult to the array. 65 | void TestPartResultArray::Append(const TestPartResult& result) { 66 | array_.push_back(result); 67 | } 68 | 69 | // Returns the TestPartResult at the given index (0-based). 70 | const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const { 71 | if (index < 0 || index >= size()) { 72 | printf("\nInvalid index (%d) into TestPartResultArray.\n", index); 73 | internal::posix::Abort(); 74 | } 75 | 76 | return array_[static_cast(index)]; 77 | } 78 | 79 | // Returns the number of TestPartResult objects in the array. 80 | int TestPartResultArray::size() const { 81 | return static_cast(array_.size()); 82 | } 83 | 84 | namespace internal { 85 | 86 | HasNewFatalFailureHelper::HasNewFatalFailureHelper() 87 | : has_new_fatal_failure_(false), 88 | original_reporter_( 89 | GetUnitTestImpl()->GetTestPartResultReporterForCurrentThread()) { 90 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread(this); 91 | } 92 | 93 | HasNewFatalFailureHelper::~HasNewFatalFailureHelper() { 94 | GetUnitTestImpl()->SetTestPartResultReporterForCurrentThread( 95 | original_reporter_); 96 | } 97 | 98 | void HasNewFatalFailureHelper::ReportTestPartResult( 99 | const TestPartResult& result) { 100 | if (result.fatally_failed()) has_new_fatal_failure_ = true; 101 | original_reporter_->ReportTestPartResult(result); 102 | } 103 | 104 | } // namespace internal 105 | 106 | } // namespace testing 107 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest-typed-test.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2008 Google Inc. 2 | // All Rights Reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include "gtest/gtest-typed-test.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include "gtest/gtest.h" 37 | 38 | namespace testing { 39 | namespace internal { 40 | 41 | // Skips to the first non-space char in str. Returns an empty string if str 42 | // contains only whitespace characters. 43 | static const char* SkipSpaces(const char* str) { 44 | while (IsSpace(*str)) str++; 45 | return str; 46 | } 47 | 48 | static std::vector SplitIntoTestNames(const char* src) { 49 | std::vector name_vec; 50 | src = SkipSpaces(src); 51 | for (; src != nullptr; src = SkipComma(src)) { 52 | name_vec.push_back(StripTrailingSpaces(GetPrefixUntilComma(src))); 53 | } 54 | return name_vec; 55 | } 56 | 57 | // Verifies that registered_tests match the test names in 58 | // registered_tests_; returns registered_tests if successful, or 59 | // aborts the program otherwise. 60 | const char* TypedTestSuitePState::VerifyRegisteredTestNames( 61 | const char* test_suite_name, const char* file, int line, 62 | const char* registered_tests) { 63 | RegisterTypeParameterizedTestSuite(test_suite_name, CodeLocation(file, line)); 64 | 65 | typedef RegisteredTestsMap::const_iterator RegisteredTestIter; 66 | registered_ = true; 67 | 68 | std::vector name_vec = SplitIntoTestNames(registered_tests); 69 | 70 | Message errors; 71 | 72 | std::set tests; 73 | for (std::vector::const_iterator name_it = name_vec.begin(); 74 | name_it != name_vec.end(); ++name_it) { 75 | const std::string& name = *name_it; 76 | if (tests.count(name) != 0) { 77 | errors << "Test " << name << " is listed more than once.\n"; 78 | continue; 79 | } 80 | 81 | if (registered_tests_.count(name) != 0) { 82 | tests.insert(name); 83 | } else { 84 | errors << "No test named " << name 85 | << " can be found in this test suite.\n"; 86 | } 87 | } 88 | 89 | for (RegisteredTestIter it = registered_tests_.begin(); 90 | it != registered_tests_.end(); ++it) { 91 | if (tests.count(it->first) == 0) { 92 | errors << "You forgot to list test " << it->first << ".\n"; 93 | } 94 | } 95 | 96 | const std::string& errors_str = errors.GetString(); 97 | if (!errors_str.empty()) { 98 | fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), 99 | errors_str.c_str()); 100 | fflush(stderr); 101 | posix::Abort(); 102 | } 103 | 104 | return registered_tests; 105 | } 106 | 107 | } // namespace internal 108 | } // namespace testing 109 | -------------------------------------------------------------------------------- /3rdparty/gtest/googletest/src/gtest_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2006, Google Inc. 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions are 6 | // met: 7 | // 8 | // * Redistributions of source code must retain the above copyright 9 | // notice, this list of conditions and the following disclaimer. 10 | // * Redistributions in binary form must reproduce the above 11 | // copyright notice, this list of conditions and the following disclaimer 12 | // in the documentation and/or other materials provided with the 13 | // distribution. 14 | // * Neither the name of Google Inc. nor the names of its 15 | // contributors may be used to endorse or promote products derived from 16 | // this software without specific prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | #include 31 | 32 | #include "gtest/gtest.h" 33 | 34 | #if defined(GTEST_OS_ESP8266) || defined(GTEST_OS_ESP32) || \ 35 | (defined(GTEST_OS_NRF52) && defined(ARDUINO)) 36 | // Arduino-like platforms: program entry points are setup/loop instead of main. 37 | 38 | #ifdef GTEST_OS_ESP8266 39 | extern "C" { 40 | #endif 41 | 42 | void setup() { testing::InitGoogleTest(); } 43 | 44 | void loop() { RUN_ALL_TESTS(); } 45 | 46 | #ifdef GTEST_OS_ESP8266 47 | } 48 | #endif 49 | 50 | #elif defined(GTEST_OS_QURT) 51 | // QuRT: program entry point is main, but argc/argv are unusable. 52 | 53 | GTEST_API_ int main() { 54 | printf("Running main() from %s\n", __FILE__); 55 | testing::InitGoogleTest(); 56 | return RUN_ALL_TESTS(); 57 | } 58 | #else 59 | // Normal platforms: program entry point is main, argc/argv are initialized. 60 | 61 | GTEST_API_ int main(int argc, char **argv) { 62 | printf("Running main() from %s\n", __FILE__); 63 | testing::InitGoogleTest(&argc, argv); 64 | return RUN_ALL_TESTS(); 65 | } 66 | #endif 67 | -------------------------------------------------------------------------------- /3rdparty/vma/include/vk_mem_alloc.cpp: -------------------------------------------------------------------------------- 1 | #include "volk.h" 2 | 3 | #define VMA_IMPLEMENTATION 4 | #include "vk_mem_alloc.h" 5 | -------------------------------------------------------------------------------- /3rdparty/volk/VERSION: -------------------------------------------------------------------------------- 1 | https://github.com/zeux/volk/tree/1.3.270 -------------------------------------------------------------------------------- /3rdparty/vulkan/VERSION: -------------------------------------------------------------------------------- 1 | https://github.com/KhronosGroup/Vulkan-Headers/tree/v1.3.270 -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vk_video/vulkan_video_codec_h264std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H264STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h264std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h264std_decode 1 24 | #include "vulkan_video_codec_h264std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_decode" 30 | #define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 31 | 32 | typedef enum StdVideoDecodeH264FieldOrderCount { 33 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, 34 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, 35 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, 36 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF 37 | } StdVideoDecodeH264FieldOrderCount; 38 | typedef struct StdVideoDecodeH264PictureInfoFlags { 39 | uint32_t field_pic_flag : 1; 40 | uint32_t is_intra : 1; 41 | uint32_t IdrPicFlag : 1; 42 | uint32_t bottom_field_flag : 1; 43 | uint32_t is_reference : 1; 44 | uint32_t complementary_field_pair : 1; 45 | } StdVideoDecodeH264PictureInfoFlags; 46 | 47 | typedef struct StdVideoDecodeH264PictureInfo { 48 | StdVideoDecodeH264PictureInfoFlags flags; 49 | uint8_t seq_parameter_set_id; 50 | uint8_t pic_parameter_set_id; 51 | uint8_t reserved1; 52 | uint8_t reserved2; 53 | uint16_t frame_num; 54 | uint16_t idr_pic_id; 55 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 56 | } StdVideoDecodeH264PictureInfo; 57 | 58 | typedef struct StdVideoDecodeH264ReferenceInfoFlags { 59 | uint32_t top_field_flag : 1; 60 | uint32_t bottom_field_flag : 1; 61 | uint32_t used_for_long_term_reference : 1; 62 | uint32_t is_non_existing : 1; 63 | } StdVideoDecodeH264ReferenceInfoFlags; 64 | 65 | typedef struct StdVideoDecodeH264ReferenceInfo { 66 | StdVideoDecodeH264ReferenceInfoFlags flags; 67 | uint16_t FrameNum; 68 | uint16_t reserved; 69 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 70 | } StdVideoDecodeH264ReferenceInfo; 71 | 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vk_video/vulkan_video_codec_h265std_decode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H265STD_DECODE_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codec_h265std_decode is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codec_h265std_decode 1 24 | #include "vulkan_video_codec_h265std.h" 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 27 | 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 29 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_decode" 30 | #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 31 | typedef struct StdVideoDecodeH265PictureInfoFlags { 32 | uint32_t IrapPicFlag : 1; 33 | uint32_t IdrPicFlag : 1; 34 | uint32_t IsReference : 1; 35 | uint32_t short_term_ref_pic_set_sps_flag : 1; 36 | } StdVideoDecodeH265PictureInfoFlags; 37 | 38 | typedef struct StdVideoDecodeH265PictureInfo { 39 | StdVideoDecodeH265PictureInfoFlags flags; 40 | uint8_t sps_video_parameter_set_id; 41 | uint8_t pps_seq_parameter_set_id; 42 | uint8_t pps_pic_parameter_set_id; 43 | uint8_t NumDeltaPocsOfRefRpsIdx; 44 | int32_t PicOrderCntVal; 45 | uint16_t NumBitsForSTRefPicSetInSlice; 46 | uint16_t reserved; 47 | uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 48 | uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 49 | uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 50 | } StdVideoDecodeH265PictureInfo; 51 | 52 | typedef struct StdVideoDecodeH265ReferenceInfoFlags { 53 | uint32_t used_for_long_term_reference : 1; 54 | uint32_t unused_for_reference : 1; 55 | } StdVideoDecodeH265ReferenceInfoFlags; 56 | 57 | typedef struct StdVideoDecodeH265ReferenceInfo { 58 | StdVideoDecodeH265ReferenceInfoFlags flags; 59 | int32_t PicOrderCntVal; 60 | } StdVideoDecodeH265ReferenceInfo; 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vk_video/vulkan_video_codecs_common.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODECS_COMMON_H_ 2 | #define VULKAN_VIDEO_CODECS_COMMON_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // vulkan_video_codecs_common is a preprocessor guard. Do not pass it to API calls. 23 | #define vulkan_video_codecs_common 1 24 | #if !defined(VK_NO_STDINT_H) 25 | #include 26 | #endif 27 | 28 | #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ 29 | ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) 30 | 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vk_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // File: vk_platform.h 3 | // 4 | /* 5 | ** Copyright 2014-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | 11 | #ifndef VK_PLATFORM_H_ 12 | #define VK_PLATFORM_H_ 13 | 14 | #ifdef __cplusplus 15 | extern "C" 16 | { 17 | #endif // __cplusplus 18 | 19 | /* 20 | *************************************************************************************************** 21 | * Platform-specific directives and type declarations 22 | *************************************************************************************************** 23 | */ 24 | 25 | /* Platform-specific calling convention macros. 26 | * 27 | * Platforms should define these so that Vulkan clients call Vulkan commands 28 | * with the same calling conventions that the Vulkan implementation expects. 29 | * 30 | * VKAPI_ATTR - Placed before the return type in function declarations. 31 | * Useful for C++11 and GCC/Clang-style function attribute syntax. 32 | * VKAPI_CALL - Placed after the return type in function declarations. 33 | * Useful for MSVC-style calling convention syntax. 34 | * VKAPI_PTR - Placed between the '(' and '*' in function pointer types. 35 | * 36 | * Function declaration: VKAPI_ATTR void VKAPI_CALL vkCommand(void); 37 | * Function pointer type: typedef void (VKAPI_PTR *PFN_vkCommand)(void); 38 | */ 39 | #if defined(_WIN32) 40 | // On Windows, Vulkan commands use the stdcall convention 41 | #define VKAPI_ATTR 42 | #define VKAPI_CALL __stdcall 43 | #define VKAPI_PTR VKAPI_CALL 44 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH < 7 45 | #error "Vulkan is not supported for the 'armeabi' NDK ABI" 46 | #elif defined(__ANDROID__) && defined(__ARM_ARCH) && __ARM_ARCH >= 7 && defined(__ARM_32BIT_STATE) 47 | // On Android 32-bit ARM targets, Vulkan functions use the "hardfloat" 48 | // calling convention, i.e. float parameters are passed in registers. This 49 | // is true even if the rest of the application passes floats on the stack, 50 | // as it does by default when compiling for the armeabi-v7a NDK ABI. 51 | #define VKAPI_ATTR __attribute__((pcs("aapcs-vfp"))) 52 | #define VKAPI_CALL 53 | #define VKAPI_PTR VKAPI_ATTR 54 | #else 55 | // On other platforms, use the default calling convention 56 | #define VKAPI_ATTR 57 | #define VKAPI_CALL 58 | #define VKAPI_PTR 59 | #endif 60 | 61 | #if !defined(VK_NO_STDDEF_H) 62 | #include 63 | #endif // !defined(VK_NO_STDDEF_H) 64 | 65 | #if !defined(VK_NO_STDINT_H) 66 | #if defined(_MSC_VER) && (_MSC_VER < 1600) 67 | typedef signed __int8 int8_t; 68 | typedef unsigned __int8 uint8_t; 69 | typedef signed __int16 int16_t; 70 | typedef unsigned __int16 uint16_t; 71 | typedef signed __int32 int32_t; 72 | typedef unsigned __int32 uint32_t; 73 | typedef signed __int64 int64_t; 74 | typedef unsigned __int64 uint64_t; 75 | #else 76 | #include 77 | #endif 78 | #endif // !defined(VK_NO_STDINT_H) 79 | 80 | #ifdef __cplusplus 81 | } // extern "C" 82 | #endif // __cplusplus 83 | 84 | #endif 85 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_H_ 2 | #define VULKAN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | #include "vk_platform.h" 11 | #include "vulkan_core.h" 12 | 13 | #ifdef VK_USE_PLATFORM_ANDROID_KHR 14 | #include "vulkan_android.h" 15 | #endif 16 | 17 | #ifdef VK_USE_PLATFORM_FUCHSIA 18 | #include 19 | #include "vulkan_fuchsia.h" 20 | #endif 21 | 22 | #ifdef VK_USE_PLATFORM_IOS_MVK 23 | #include "vulkan_ios.h" 24 | #endif 25 | 26 | 27 | #ifdef VK_USE_PLATFORM_MACOS_MVK 28 | #include "vulkan_macos.h" 29 | #endif 30 | 31 | #ifdef VK_USE_PLATFORM_METAL_EXT 32 | #include "vulkan_metal.h" 33 | #endif 34 | 35 | #ifdef VK_USE_PLATFORM_VI_NN 36 | #include "vulkan_vi.h" 37 | #endif 38 | 39 | 40 | #ifdef VK_USE_PLATFORM_WAYLAND_KHR 41 | #include "vulkan_wayland.h" 42 | #endif 43 | 44 | 45 | #ifdef VK_USE_PLATFORM_WIN32_KHR 46 | #include 47 | #include "vulkan_win32.h" 48 | #endif 49 | 50 | 51 | #ifdef VK_USE_PLATFORM_XCB_KHR 52 | #include 53 | #include "vulkan_xcb.h" 54 | #endif 55 | 56 | 57 | #ifdef VK_USE_PLATFORM_XLIB_KHR 58 | #include 59 | #include "vulkan_xlib.h" 60 | #endif 61 | 62 | 63 | #ifdef VK_USE_PLATFORM_DIRECTFB_EXT 64 | #include 65 | #include "vulkan_directfb.h" 66 | #endif 67 | 68 | 69 | #ifdef VK_USE_PLATFORM_XLIB_XRANDR_EXT 70 | #include 71 | #include 72 | #include "vulkan_xlib_xrandr.h" 73 | #endif 74 | 75 | 76 | #ifdef VK_USE_PLATFORM_GGP 77 | #include 78 | #include "vulkan_ggp.h" 79 | #endif 80 | 81 | 82 | #ifdef VK_USE_PLATFORM_SCREEN_QNX 83 | #include 84 | #include "vulkan_screen.h" 85 | #endif 86 | 87 | 88 | #ifdef VK_USE_PLATFORM_SCI 89 | #include 90 | #include 91 | #include "vulkan_sci.h" 92 | #endif 93 | 94 | 95 | #ifdef VK_ENABLE_BETA_EXTENSIONS 96 | #include "vulkan_beta.h" 97 | #endif 98 | 99 | #endif // VULKAN_H_ 100 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_directfb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_DIRECTFB_H_ 2 | #define VULKAN_DIRECTFB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_directfb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_directfb_surface 1 24 | #define VK_EXT_DIRECTFB_SURFACE_SPEC_VERSION 1 25 | #define VK_EXT_DIRECTFB_SURFACE_EXTENSION_NAME "VK_EXT_directfb_surface" 26 | typedef VkFlags VkDirectFBSurfaceCreateFlagsEXT; 27 | typedef struct VkDirectFBSurfaceCreateInfoEXT { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkDirectFBSurfaceCreateFlagsEXT flags; 31 | IDirectFB* dfb; 32 | IDirectFBSurface* surface; 33 | } VkDirectFBSurfaceCreateInfoEXT; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateDirectFBSurfaceEXT)(VkInstance instance, const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceDirectFBPresentationSupportEXT)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, IDirectFB* dfb); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateDirectFBSurfaceEXT( 40 | VkInstance instance, 41 | const VkDirectFBSurfaceCreateInfoEXT* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceDirectFBPresentationSupportEXT( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | IDirectFB* dfb); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_ggp.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_GGP_H_ 2 | #define VULKAN_GGP_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_GGP_stream_descriptor_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_GGP_stream_descriptor_surface 1 24 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_SPEC_VERSION 1 25 | #define VK_GGP_STREAM_DESCRIPTOR_SURFACE_EXTENSION_NAME "VK_GGP_stream_descriptor_surface" 26 | typedef VkFlags VkStreamDescriptorSurfaceCreateFlagsGGP; 27 | typedef struct VkStreamDescriptorSurfaceCreateInfoGGP { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkStreamDescriptorSurfaceCreateFlagsGGP flags; 31 | GgpStreamDescriptor streamDescriptor; 32 | } VkStreamDescriptorSurfaceCreateInfoGGP; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateStreamDescriptorSurfaceGGP)(VkInstance instance, const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateStreamDescriptorSurfaceGGP( 38 | VkInstance instance, 39 | const VkStreamDescriptorSurfaceCreateInfoGGP* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | 45 | // VK_GGP_frame_token is a preprocessor guard. Do not pass it to API calls. 46 | #define VK_GGP_frame_token 1 47 | #define VK_GGP_FRAME_TOKEN_SPEC_VERSION 1 48 | #define VK_GGP_FRAME_TOKEN_EXTENSION_NAME "VK_GGP_frame_token" 49 | typedef struct VkPresentFrameTokenGGP { 50 | VkStructureType sType; 51 | const void* pNext; 52 | GgpFrameToken frameToken; 53 | } VkPresentFrameTokenGGP; 54 | 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_ios.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_IOS_H_ 2 | #define VULKAN_IOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_ios_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_ios_surface 1 24 | #define VK_MVK_IOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_IOS_SURFACE_EXTENSION_NAME "VK_MVK_ios_surface" 26 | typedef VkFlags VkIOSSurfaceCreateFlagsMVK; 27 | typedef struct VkIOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkIOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkIOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateIOSSurfaceMVK)(VkInstance instance, const VkIOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateIOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkIOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_macos.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_MACOS_H_ 2 | #define VULKAN_MACOS_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_MVK_macos_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_MVK_macos_surface 1 24 | #define VK_MVK_MACOS_SURFACE_SPEC_VERSION 3 25 | #define VK_MVK_MACOS_SURFACE_EXTENSION_NAME "VK_MVK_macos_surface" 26 | typedef VkFlags VkMacOSSurfaceCreateFlagsMVK; 27 | typedef struct VkMacOSSurfaceCreateInfoMVK { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkMacOSSurfaceCreateFlagsMVK flags; 31 | const void* pView; 32 | } VkMacOSSurfaceCreateInfoMVK; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateMacOSSurfaceMVK)(VkInstance instance, const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateMacOSSurfaceMVK( 38 | VkInstance instance, 39 | const VkMacOSSurfaceCreateInfoMVK* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_screen.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_SCREEN_H_ 2 | #define VULKAN_SCREEN_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_QNX_screen_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_QNX_screen_surface 1 24 | #define VK_QNX_SCREEN_SURFACE_SPEC_VERSION 1 25 | #define VK_QNX_SCREEN_SURFACE_EXTENSION_NAME "VK_QNX_screen_surface" 26 | typedef VkFlags VkScreenSurfaceCreateFlagsQNX; 27 | typedef struct VkScreenSurfaceCreateInfoQNX { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkScreenSurfaceCreateFlagsQNX flags; 31 | struct _screen_context* context; 32 | struct _screen_window* window; 33 | } VkScreenSurfaceCreateInfoQNX; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateScreenSurfaceQNX)(VkInstance instance, const VkScreenSurfaceCreateInfoQNX* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceScreenPresentationSupportQNX)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct _screen_window* window); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateScreenSurfaceQNX( 40 | VkInstance instance, 41 | const VkScreenSurfaceCreateInfoQNX* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceScreenPresentationSupportQNX( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | struct _screen_window* window); 49 | #endif 50 | 51 | 52 | // VK_QNX_external_memory_screen_buffer is a preprocessor guard. Do not pass it to API calls. 53 | #define VK_QNX_external_memory_screen_buffer 1 54 | #define VK_QNX_EXTERNAL_MEMORY_SCREEN_BUFFER_SPEC_VERSION 1 55 | #define VK_QNX_EXTERNAL_MEMORY_SCREEN_BUFFER_EXTENSION_NAME "VK_QNX_external_memory_screen_buffer" 56 | typedef struct VkScreenBufferPropertiesQNX { 57 | VkStructureType sType; 58 | void* pNext; 59 | VkDeviceSize allocationSize; 60 | uint32_t memoryTypeBits; 61 | } VkScreenBufferPropertiesQNX; 62 | 63 | typedef struct VkScreenBufferFormatPropertiesQNX { 64 | VkStructureType sType; 65 | void* pNext; 66 | VkFormat format; 67 | uint64_t externalFormat; 68 | uint64_t screenUsage; 69 | VkFormatFeatureFlags formatFeatures; 70 | VkComponentMapping samplerYcbcrConversionComponents; 71 | VkSamplerYcbcrModelConversion suggestedYcbcrModel; 72 | VkSamplerYcbcrRange suggestedYcbcrRange; 73 | VkChromaLocation suggestedXChromaOffset; 74 | VkChromaLocation suggestedYChromaOffset; 75 | } VkScreenBufferFormatPropertiesQNX; 76 | 77 | typedef struct VkImportScreenBufferInfoQNX { 78 | VkStructureType sType; 79 | const void* pNext; 80 | struct _screen_buffer* buffer; 81 | } VkImportScreenBufferInfoQNX; 82 | 83 | typedef struct VkExternalFormatQNX { 84 | VkStructureType sType; 85 | void* pNext; 86 | uint64_t externalFormat; 87 | } VkExternalFormatQNX; 88 | 89 | typedef struct VkPhysicalDeviceExternalMemoryScreenBufferFeaturesQNX { 90 | VkStructureType sType; 91 | void* pNext; 92 | VkBool32 screenBufferImport; 93 | } VkPhysicalDeviceExternalMemoryScreenBufferFeaturesQNX; 94 | 95 | typedef VkResult (VKAPI_PTR *PFN_vkGetScreenBufferPropertiesQNX)(VkDevice device, const struct _screen_buffer* buffer, VkScreenBufferPropertiesQNX* pProperties); 96 | 97 | #ifndef VK_NO_PROTOTYPES 98 | VKAPI_ATTR VkResult VKAPI_CALL vkGetScreenBufferPropertiesQNX( 99 | VkDevice device, 100 | const struct _screen_buffer* buffer, 101 | VkScreenBufferPropertiesQNX* pProperties); 102 | #endif 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_vi.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VI_H_ 2 | #define VULKAN_VI_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_NN_vi_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_NN_vi_surface 1 24 | #define VK_NN_VI_SURFACE_SPEC_VERSION 1 25 | #define VK_NN_VI_SURFACE_EXTENSION_NAME "VK_NN_vi_surface" 26 | typedef VkFlags VkViSurfaceCreateFlagsNN; 27 | typedef struct VkViSurfaceCreateInfoNN { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkViSurfaceCreateFlagsNN flags; 31 | void* window; 32 | } VkViSurfaceCreateInfoNN; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateViSurfaceNN)(VkInstance instance, const VkViSurfaceCreateInfoNN* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | 36 | #ifndef VK_NO_PROTOTYPES 37 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateViSurfaceNN( 38 | VkInstance instance, 39 | const VkViSurfaceCreateInfoNN* pCreateInfo, 40 | const VkAllocationCallbacks* pAllocator, 41 | VkSurfaceKHR* pSurface); 42 | #endif 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_wayland.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_WAYLAND_H_ 2 | #define VULKAN_WAYLAND_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_wayland_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_wayland_surface 1 24 | #define VK_KHR_WAYLAND_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME "VK_KHR_wayland_surface" 26 | typedef VkFlags VkWaylandSurfaceCreateFlagsKHR; 27 | typedef struct VkWaylandSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkWaylandSurfaceCreateFlagsKHR flags; 31 | struct wl_display* display; 32 | struct wl_surface* surface; 33 | } VkWaylandSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateWaylandSurfaceKHR)(VkInstance instance, const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, struct wl_display* display); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateWaylandSurfaceKHR( 40 | VkInstance instance, 41 | const VkWaylandSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceWaylandPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | struct wl_display* display); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_xcb.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XCB_H_ 2 | #define VULKAN_XCB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xcb_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xcb_surface 1 24 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 26 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 27 | typedef struct VkXcbSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXcbSurfaceCreateFlagsKHR flags; 31 | xcb_connection_t* connection; 32 | xcb_window_t window; 33 | } VkXcbSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 40 | VkInstance instance, 41 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | xcb_connection_t* connection, 49 | xcb_visualid_t visual_id); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_xlib.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_H_ 2 | #define VULKAN_XLIB_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_KHR_xlib_surface is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_KHR_xlib_surface 1 24 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 25 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 26 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 27 | typedef struct VkXlibSurfaceCreateInfoKHR { 28 | VkStructureType sType; 29 | const void* pNext; 30 | VkXlibSurfaceCreateFlagsKHR flags; 31 | Display* dpy; 32 | Window window; 33 | } VkXlibSurfaceCreateInfoKHR; 34 | 35 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 36 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 37 | 38 | #ifndef VK_NO_PROTOTYPES 39 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 40 | VkInstance instance, 41 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 42 | const VkAllocationCallbacks* pAllocator, 43 | VkSurfaceKHR* pSurface); 44 | 45 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 46 | VkPhysicalDevice physicalDevice, 47 | uint32_t queueFamilyIndex, 48 | Display* dpy, 49 | VisualID visualID); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /3rdparty/vulkan/include/vulkan/vulkan_xlib_xrandr.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_XLIB_XRANDR_H_ 2 | #define VULKAN_XLIB_XRANDR_H_ 1 3 | 4 | /* 5 | ** Copyright 2015-2023 The Khronos Group Inc. 6 | ** 7 | ** SPDX-License-Identifier: Apache-2.0 8 | */ 9 | 10 | /* 11 | ** This header is generated from the Khronos Vulkan XML API Registry. 12 | ** 13 | */ 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | 21 | 22 | // VK_EXT_acquire_xlib_display is a preprocessor guard. Do not pass it to API calls. 23 | #define VK_EXT_acquire_xlib_display 1 24 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_SPEC_VERSION 1 25 | #define VK_EXT_ACQUIRE_XLIB_DISPLAY_EXTENSION_NAME "VK_EXT_acquire_xlib_display" 26 | typedef VkResult (VKAPI_PTR *PFN_vkAcquireXlibDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, VkDisplayKHR display); 27 | typedef VkResult (VKAPI_PTR *PFN_vkGetRandROutputDisplayEXT)(VkPhysicalDevice physicalDevice, Display* dpy, RROutput rrOutput, VkDisplayKHR* pDisplay); 28 | 29 | #ifndef VK_NO_PROTOTYPES 30 | VKAPI_ATTR VkResult VKAPI_CALL vkAcquireXlibDisplayEXT( 31 | VkPhysicalDevice physicalDevice, 32 | Display* dpy, 33 | VkDisplayKHR display); 34 | 35 | VKAPI_ATTR VkResult VKAPI_CALL vkGetRandROutputDisplayEXT( 36 | VkPhysicalDevice physicalDevice, 37 | Display* dpy, 38 | RROutput rrOutput, 39 | VkDisplayKHR* pDisplay); 40 | #endif 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | project(opal VERSION 1.0.0) 3 | 4 | # ================================================================================================== 5 | # Global options 6 | # ================================================================================================== 7 | option(OPAL_BUILD_SAMPLES "Build samples" TRUE) 8 | option(OPAL_BUILD_TESTS "Build tests" FALSE) 9 | option(OPAL_BUILD_BENCHMARKS "Build benchmarks" FALSE) 10 | option(OPAL_BUILD_WITH_DIRECTX12 "Build with DirectX 12 backend" TRUE) 11 | option(OPAL_BUILD_WITH_WEBGPU "Build with WebGPU backend" TRUE) 12 | option(OPAL_BUILD_WITH_VULKAN "Build with Vulkan backend" TRUE) 13 | option(OPAL_BUILD_WITH_METAL "Build with Metal backend" TRUE) 14 | option(OPAL_BUILD_WITH_VALIDATION_LAYERS "Build with Opal validation layers" FALSE) 15 | option(OPAL_BUILD_WITH_VMA "Build with Vulkan Memory Allocator along with built-in memory allocator" FALSE) 16 | 17 | # ================================================================================================== 18 | # Global Variables 19 | # ================================================================================================== 20 | enable_language(C) 21 | if (OPAL_BUILD_WITH_VMA) 22 | enable_language(CXX) 23 | endif() 24 | 25 | set(OPAL_DIR_THIRDPARTY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty) 26 | set(OPAL_DIR_API ${CMAKE_CURRENT_SOURCE_DIR}/include) 27 | set(OPAL_DIR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src) 28 | 29 | set(CMAKE_CXX_STANDARD 17) 30 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 31 | 32 | if (WIN32) 33 | set(OPAL_PLATFORM windows) 34 | set(OPAL_ABI x64) 35 | endif() 36 | 37 | if (APPLE) 38 | set(OPAL_PLATFORM macos) 39 | set(OPAL_ABI x64) # FIXME: Is it always x64? 40 | enable_language(OBJC) 41 | endif() 42 | 43 | if (EMSCRIPTEN) 44 | set(OPAL_PLATFORM emscripten) 45 | set(OPAL_ABI wasm) 46 | set(CMAKE_EXECUTABLE_SUFFIX ".html") 47 | endif() 48 | 49 | message("Platform: ${OPAL_PLATFORM}") 50 | message("ABI: ${OPAL_ABI}") 51 | 52 | # ================================================================================================== 53 | # General compile flags 54 | # ================================================================================================== 55 | if (WIN32) 56 | set(CMAKE_C_FLAGS "/W4 /external:W3 /wd4996 /D_CRT_SECURE_NO_WARNINGS") 57 | set(CMAKE_CXX_FLAGS "/W4 /external:W3 /wd4996 /D_CRT_SECURE_NO_WARNINGS /EHsc /GR-") 58 | endif() 59 | 60 | if (EMSCRIPTEN) 61 | set(CMAKE_C_FLAGS_DEBUG "-g") 62 | set(CMAKE_CXX_FLAGS_DEBUG "-g") 63 | endif() 64 | 65 | # ================================================================================================== 66 | # General includes 67 | # ================================================================================================== 68 | 69 | # ================================================================================================== 70 | # General libraries 71 | # ================================================================================================== 72 | 73 | # ================================================================================================== 74 | # Sub-projects 75 | # ================================================================================================== 76 | add_subdirectory(src) 77 | 78 | if (OPAL_BUILD_TESTS) 79 | set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) 80 | add_subdirectory(3rdparty/gtest) 81 | 82 | add_subdirectory(tests/heap) 83 | add_subdirectory(tests/pool) 84 | endif() 85 | 86 | if (OPAL_BUILD_BENCHMARKS) 87 | set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE) 88 | set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE) 89 | add_subdirectory(3rdparty/gbench) 90 | 91 | add_subdirectory(benchmarks/allocator) 92 | endif() 93 | 94 | if (OPAL_BUILD_SAMPLES) 95 | add_subdirectory(samples/01_enumerate_devices) 96 | add_subdirectory(samples/02_buffers) 97 | add_subdirectory(samples/03_textures) 98 | add_subdirectory(samples/04_triangle) 99 | endif() 100 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 8, 3 | "configurePresets": [ 4 | { 5 | "name": "msvc2022-common", 6 | "hidden": true, 7 | "generator": "Visual Studio 17 2022", 8 | "binaryDir": "${workspaceFolder}/build", 9 | "installDir": "${workspaceFolder}/build" 10 | }, 11 | { 12 | "name": "msvc2022-x64", 13 | "inherits": "msvc2022-common", 14 | "hidden": false, 15 | "architecture": "x64", 16 | "displayName": "Visual Studio 2022 | x64" 17 | }, 18 | { 19 | "name": "emscripten-ninja-common", 20 | "hidden": true, 21 | "generator": "Ninja", 22 | "binaryDir": "${workspaceFolder}/build", 23 | "installDir": "${workspaceFolder}/build", 24 | "toolchainFile": "$penv{EMROOT}/cmake/Modules/Platform/Emscripten.cmake" 25 | }, 26 | { 27 | "name": "emscripten-ninja", 28 | "inherits": "emscripten-ninja-common", 29 | "hidden": false, 30 | "cacheVariables": { 31 | "CMAKE_BUILD_TYPE": "Release" 32 | } 33 | }, 34 | { 35 | "name": "emscripten-ninja-debug", 36 | "inherits": "emscripten-ninja-common", 37 | "hidden": false, 38 | "cacheVariables": { 39 | "CMAKE_BUILD_TYPE": "Debug" 40 | } 41 | } 42 | ], 43 | "buildPresets": [ 44 | { 45 | "name": "build-windows-debug", 46 | "hidden": false, 47 | "configurePreset": "msvc2022-x64", 48 | "configuration": "Debug", 49 | "targets": ["all_build", "install"] 50 | }, 51 | { 52 | "name": "build-windows-release", 53 | "hidden": false, 54 | "configurePreset": "msvc2022-x64", 55 | "configuration": "Release", 56 | "targets": ["all_build", "install"] 57 | }, 58 | { 59 | "name": "build-emscripten-debug", 60 | "hidden": false, 61 | "configurePreset": "emscripten-ninja-debug", 62 | "targets": ["all", "install"] 63 | }, 64 | { 65 | "name": "build-emscripten-release", 66 | "hidden": false, 67 | "configurePreset": "emscripten-ninja", 68 | "targets": ["all", "install"] 69 | } 70 | ] 71 | } 72 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 SEEDØ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # opal 2 | Opal is a low level rendering framework that supports Vulkan / DirectX 12 / Metal / WebGPU 3 | -------------------------------------------------------------------------------- /benchmarks/allocator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET bench_allocator) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ) 14 | 15 | file(GLOB HEADERS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 17 | ) 18 | 19 | # ================================================================================================== 20 | # Target 21 | # ================================================================================================== 22 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 23 | 24 | set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE ${OPAL_DIR_EXPORT}/${OPAL_PLATFORM}/${OPAL_ABI}) 25 | set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${OPAL_DIR_EXPORT}/${OPAL_PLATFORM}/${OPAL_ABI}) 26 | set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${OPAL_DIR_EXPORT}/${OPAL_PLATFORM}/${OPAL_ABI}) 27 | set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG ${OPAL_DIR_EXPORT}/${OPAL_PLATFORM}/${OPAL_ABI}) 28 | 29 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 30 | 31 | # ================================================================================================== 32 | # Includes 33 | # ================================================================================================== 34 | target_include_directories(${TARGET} PUBLIC ${OPAL_API_DIR}) 35 | 36 | # ================================================================================================== 37 | # Preprocessor 38 | # ================================================================================================== 39 | 40 | # ================================================================================================== 41 | # Libraries 42 | # ================================================================================================== 43 | target_link_libraries(${TARGET} PUBLIC opal benchmark::benchmark) 44 | 45 | # ================================================================================================== 46 | # Custom commands 47 | # ================================================================================================== 48 | if (NOT EMSCRIPTEN) 49 | install( 50 | TARGETS ${TARGET} 51 | EXPORT ${TARGET} 52 | RUNTIME DESTINATION bin 53 | LIBRARY DESTINATION lib 54 | ARCHIVE DESTINATION lib 55 | INCLUDES DESTINATION include 56 | PUBLIC_HEADER DESTINATION include 57 | ) 58 | endif() 59 | -------------------------------------------------------------------------------- /benchmarks/allocator/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | template 5 | class AllocatorBench : public benchmark::Fixture 6 | { 7 | public: 8 | void SetUp(benchmark::State &state) 9 | { 10 | static Opal_InstanceDesc instance_desc = 11 | { 12 | "allocator benchmark", 13 | "Opal", 14 | 0, 15 | 0, 16 | OPAL_DEFAULT_HEAP_SIZE, 17 | OPAL_DEFAULT_HEAP_ALLOCATIONS, 18 | OPAL_DEFAULT_HEAPS, 19 | (Opal_InstanceCreationFlags)T 20 | }; 21 | 22 | Opal_Result result = opalCreateInstance(OPAL_API_VULKAN, &instance_desc, &instance); 23 | assert(result == OPAL_SUCCESS); 24 | 25 | result = opalCreateDefaultDevice(instance, OPAL_DEVICE_HINT_DEFAULT, &device); 26 | assert(result == OPAL_SUCCESS); 27 | 28 | textures = (Opal_Texture *)malloc(sizeof(Opal_Texture) * 65536); 29 | buffers = (Opal_Buffer *)malloc(sizeof(Opal_Buffer) * 65536); 30 | 31 | memset(textures, OPAL_NULL_HANDLE, sizeof(Opal_Texture) * 65536); 32 | memset(buffers, OPAL_NULL_HANDLE, sizeof(Opal_Buffer) * 65536); 33 | } 34 | 35 | void TearDown(benchmark::State& state) 36 | { 37 | Opal_Result result = opalDestroyDevice(device); 38 | assert(result == OPAL_SUCCESS); 39 | 40 | result = opalDestroyInstance(instance); 41 | assert(result == OPAL_SUCCESS); 42 | 43 | free(textures); 44 | free(buffers); 45 | } 46 | 47 | void LinearAlloc(benchmark::State &state) 48 | { 49 | static Opal_TextureDesc texture_desc = 50 | { 51 | OPAL_TEXTURE_TYPE_2D, 52 | OPAL_FORMAT_RGBA8_UNORM, 53 | 128, 54 | 128, 55 | 1, 56 | 1, 57 | 1, 58 | OPAL_SAMPLES_1, 59 | (Opal_TextureUsageFlags)OPAL_TEXTURE_USAGE_SHADER_SAMPLED, 60 | OPAL_ALLOCATION_HINT_AUTO, 61 | }; 62 | 63 | for (auto _ : state) 64 | { 65 | for (int64_t i = 0; i < state.range(0); ++i) 66 | { 67 | Opal_Result result = opalCreateTexture(device, &texture_desc, &textures[i]); 68 | assert(result == OPAL_SUCCESS); 69 | } 70 | 71 | for (int64_t i = 0; i < state.range(0); ++i) 72 | { 73 | Opal_Result result = opalDestroyTexture(device, textures[i]); 74 | assert(result == OPAL_SUCCESS); 75 | } 76 | } 77 | } 78 | 79 | void InterleavedAlloc(benchmark::State &state) 80 | { 81 | static Opal_TextureDesc texture_desc = 82 | { 83 | OPAL_TEXTURE_TYPE_2D, 84 | OPAL_FORMAT_RGBA8_UNORM, 85 | 128, 86 | 128, 87 | 1, 88 | 1, 89 | 1, 90 | OPAL_SAMPLES_1, 91 | (Opal_TextureUsageFlags)OPAL_TEXTURE_USAGE_SHADER_SAMPLED, 92 | OPAL_ALLOCATION_HINT_AUTO, 93 | }; 94 | 95 | static Opal_BufferDesc buffer_desc = 96 | { 97 | (Opal_BufferUsageFlags)(OPAL_BUFFER_USAGE_UNIFORM), 98 | 512, 99 | OPAL_ALLOCATION_MEMORY_TYPE_DEVICE_LOCAL, 100 | OPAL_ALLOCATION_HINT_AUTO, 101 | }; 102 | 103 | for (auto _ : state) 104 | { 105 | for (int64_t i = 0; i < state.range(0); ++i) 106 | { 107 | Opal_Result result = opalCreateTexture(device, &texture_desc, &textures[i]); 108 | assert(result == OPAL_SUCCESS); 109 | 110 | result = opalCreateBuffer(device, &buffer_desc, &buffers[i]); 111 | assert(result == OPAL_SUCCESS); 112 | } 113 | 114 | for (int64_t i = 0; i < state.range(0); ++i) 115 | { 116 | Opal_Result result = opalDestroyTexture(device, textures[i]); 117 | assert(result == OPAL_SUCCESS); 118 | 119 | result = opalDestroyBuffer(device, buffers[i]); 120 | assert(result == OPAL_SUCCESS); 121 | } 122 | } 123 | } 124 | 125 | protected: 126 | Opal_Instance instance {OPAL_NULL_HANDLE}; 127 | Opal_Device device {OPAL_NULL_HANDLE}; 128 | 129 | Opal_Texture *textures; 130 | Opal_Buffer *buffers; 131 | }; 132 | 133 | BENCHMARK_TEMPLATE_DEFINE_F(AllocatorBench, LinearAllocVanilla, 0)(benchmark::State& state) { LinearAlloc(state); } 134 | BENCHMARK_TEMPLATE_DEFINE_F(AllocatorBench, LinearAllocVma, 1)(benchmark::State& state) { LinearAlloc(state); } 135 | 136 | BENCHMARK_TEMPLATE_DEFINE_F(AllocatorBench, InterleavedAllocVanilla, 0)(benchmark::State& state) { InterleavedAlloc(state); } 137 | BENCHMARK_TEMPLATE_DEFINE_F(AllocatorBench, InterleavedAllocVma, 1)(benchmark::State& state) { InterleavedAlloc(state); } 138 | 139 | BENCHMARK_REGISTER_F(AllocatorBench, LinearAllocVanilla) 140 | ->Name("LinearAllocVanilla") 141 | ->RangeMultiplier(4)->Range(1, 65536); 142 | 143 | BENCHMARK_REGISTER_F(AllocatorBench, LinearAllocVma) 144 | ->Name("LinearAllocVma") 145 | ->RangeMultiplier(4)->Range(1, 65536); 146 | 147 | BENCHMARK_REGISTER_F(AllocatorBench, InterleavedAllocVanilla) 148 | ->Name("InterleavedAllocVanilla") 149 | ->RangeMultiplier(4)->Range(1, 65536); 150 | 151 | BENCHMARK_REGISTER_F(AllocatorBench, InterleavedAllocVma) 152 | ->Name("InterleavedAllocVma") 153 | ->RangeMultiplier(4)->Range(1, 65536); 154 | 155 | BENCHMARK_MAIN(); 156 | -------------------------------------------------------------------------------- /docs/design_decisions.md: -------------------------------------------------------------------------------- 1 | # Design Decisions 2 | 3 | ## Common 4 | 5 | ### Driver version 6 | 7 | Always uint64_t. Vulkan fills lower 32 bits, DX 12 fills full 64 bits. Other APIs have hardcoded value for lower 32 bits. It's up to the user how to transform this value to string. 8 | 9 | One possible solution might be based on provided vendor ID and device ID. 10 | 11 | ### No support for shader records and parameters both on Vulkan Ray Tracing and DXR 12 | 13 | Intentionally disabled due to different ways to put data in them (LocalRootSignature with 8 byte offset on DXR, Uniform buffer rules for Vulkan). 14 | 15 | ### Artifical queue limits on DirectX 12 and Metal 16 | 17 | Both API allow creating an arbitary number of queues, however, in order to keep the API consistent there are artifical limits for each device engine type. 18 | 19 | - Main (aka direct or graphics) engine will have 16 queues. 20 | - Compute (aka async compute) engine will have 8 queues. 21 | - Copy (aka async transfer) engine will have 2 queues. 22 | 23 | ### No support for acceleration structure serialization / deserialization 24 | 25 | Intentionally removed api as there is no practical use for the end user. 26 | 27 | ### Command buffer memory management 28 | 29 | Opal command buffers will rely on command allocators for memory storage. User is free to create multiple command buffers for a single command allocator but only one command buffer is allowed to be in the recording state (via opalBeginCommandBuffer). Also, opalResetCommandAllocator requires all command buffers to be either in the initial state or executed. This design is similar to DirectX 12. 30 | 31 | ## Vulkan 32 | 33 | ### No support for queue priorities 34 | 35 | Intentionally set to 1.0f for all available queues on physical device. 36 | 37 | ### No support for VK_IMAGE_TILING_LINEAR 38 | 39 | All images will use VK_IMAGE_TILING_OPTIMAL, because there is no practical use case for linear tiled images. 40 | 41 | ### No memory type hint for images 42 | 43 | Images will prefer memory with VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT flag. For transfer & readback it's better to create staging buffer. 44 | 45 | ### Fixed command pools & command buffers flags 46 | 47 | VkCommandPool is always created with VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT so that command buffer can be reset and resubmitted. 48 | 49 | opalBeginCommandBuffer will call vkBeginCommandBuffer with VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT so command buffer must be either reset or recreated after submit. This is done intentionally to match other API designs. 50 | 51 | ## WebGPU 52 | 53 | ### Enumerate devices & create device by index on WebGPU 54 | 55 | Intentionally disabled as WebGPU expects to work with a single device. Use opalCreateDefaultDevice with proper hint. 56 | 57 | ### No map / unmap support for uniform / storage / indirect / vertex / index buffer usages 58 | 59 | WebGPU only allow mapping buffers with WGPUBufferUsage_CopySrc or WGPUBufferUsage_CopyDst usage. This is similar to previous GAPI designs where staging buffer must be created in order to upload data to the GPU memory. 60 | 61 | opalMapBuffer / webgpu_deviceUnmapBuffer will return OPAL_BUFFER_NONMAPPABLE for any combinations of uniform / storage / indirect / vertex / index buffer usages. 62 | 63 | ## DirectX 12 64 | 65 | ### Automatic register space assignment 66 | 67 | To match Vulkan binding model, every descriptor in descriptor set will share the same register space. The value will match the index of corresponding descriptor set layout in pipeline layout. Opal will not allow setting register spaces manually. 68 | 69 | ### Different semantics for binding indices 70 | 71 | DirectX 12 backend will use binding indices as-is. That allows setting the same binding index for different binding types which is not possible in other APIs. 72 | 73 | For example, buffer & texture could have the same binding index, because there're assigned to different register types in HLSL. 74 | 75 | ### Hardcoded input element semantic name 76 | 77 | Intentionally introduced semantic name "LOCATION[n]" for vertex shader input attributes to match other shading language designs. This semantic only required for vertex shader inputs. Other inter-stage semantics could be used as usual. 78 | 79 | ## Metal 80 | -------------------------------------------------------------------------------- /docs/minspec.md: -------------------------------------------------------------------------------- 1 | # Minimum Requirements 2 | 3 | ## Directx 12 4 | 5 | At least Windows 10 is required. 6 | At least D3D_FEATURE_LEVEL_11_0 is required. 7 | 8 | ## Vulkan 9 | 10 | At least Vulkan 1.1 is required. -------------------------------------------------------------------------------- /samples/01_enumerate_devices/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET 01_enumerate_devices) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ) 14 | 15 | file(GLOB HEADERS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 17 | ) 18 | 19 | # ================================================================================================== 20 | # Target 21 | # ================================================================================================== 22 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 23 | 24 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 25 | 26 | # ================================================================================================== 27 | # Includes 28 | # ================================================================================================== 29 | target_include_directories(${TARGET} PUBLIC ${OPAL_API_DIR}) 30 | 31 | # ================================================================================================== 32 | # Preprocessor 33 | # ================================================================================================== 34 | 35 | # ================================================================================================== 36 | # Libraries 37 | # ================================================================================================== 38 | target_link_libraries(${TARGET} PUBLIC opal) 39 | 40 | # ================================================================================================== 41 | # Custom commands 42 | # ================================================================================================== 43 | 44 | # ================================================================================================== 45 | # Installation 46 | # ================================================================================================== 47 | if (EMSCRIPTEN) 48 | install( 49 | FILES 50 | "$/${TARGET}.js" 51 | "$/${TARGET}.wasm" 52 | "$/${TARGET}.html" 53 | DESTINATION bin 54 | ) 55 | else() 56 | install( 57 | TARGETS ${TARGET} 58 | EXPORT ${TARGET} 59 | RUNTIME DESTINATION bin 60 | LIBRARY DESTINATION lib 61 | ARCHIVE DESTINATION lib 62 | INCLUDES DESTINATION include 63 | PUBLIC_HEADER DESTINATION include 64 | ) 65 | endif() 66 | -------------------------------------------------------------------------------- /samples/02_buffers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET 02_buffers) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ) 14 | 15 | file(GLOB HEADERS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 17 | ) 18 | 19 | # ================================================================================================== 20 | # Target 21 | # ================================================================================================== 22 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 23 | 24 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 25 | 26 | # ================================================================================================== 27 | # Includes 28 | # ================================================================================================== 29 | target_include_directories(${TARGET} PUBLIC ${OPAL_API_DIR}) 30 | 31 | # ================================================================================================== 32 | # Preprocessor 33 | # ================================================================================================== 34 | 35 | # ================================================================================================== 36 | # Libraries 37 | # ================================================================================================== 38 | target_link_libraries(${TARGET} PUBLIC opal) 39 | 40 | # ================================================================================================== 41 | # Custom commands 42 | # ================================================================================================== 43 | 44 | # ================================================================================================== 45 | # Installation 46 | # ================================================================================================== 47 | if (EMSCRIPTEN) 48 | install( 49 | FILES 50 | "$/${TARGET}.js" 51 | "$/${TARGET}.wasm" 52 | "$/${TARGET}.html" 53 | DESTINATION bin 54 | ) 55 | else() 56 | install( 57 | TARGETS ${TARGET} 58 | EXPORT ${TARGET} 59 | RUNTIME DESTINATION bin 60 | LIBRARY DESTINATION lib 61 | ARCHIVE DESTINATION lib 62 | INCLUDES DESTINATION include 63 | PUBLIC_HEADER DESTINATION include 64 | ) 65 | endif() 66 | -------------------------------------------------------------------------------- /samples/02_buffers/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void testBuffers(Opal_Device device) 6 | { 7 | Opal_Buffer buffers[2] = {OPAL_NULL_HANDLE, OPAL_NULL_HANDLE}; 8 | void *ptrs[2] = {nullptr, nullptr}; 9 | 10 | Opal_BufferDesc desc = 11 | { 12 | OPAL_BUFFER_USAGE_TRANSFER_SRC, 13 | 16, 14 | OPAL_ALLOCATION_MEMORY_TYPE_UPLOAD, 15 | OPAL_ALLOCATION_HINT_AUTO, 16 | }; 17 | 18 | Opal_Result result = opalCreateBuffer(device, &desc, &buffers[0]); 19 | assert(result == OPAL_SUCCESS); 20 | 21 | result = opalCreateBuffer(device, &desc, &buffers[1]); 22 | assert(result == OPAL_SUCCESS); 23 | 24 | result = opalMapBuffer(device, buffers[0], &ptrs[0]); 25 | assert(result == OPAL_SUCCESS); 26 | 27 | result = opalMapBuffer(device, buffers[1], &ptrs[1]); 28 | assert(result == OPAL_SUCCESS); 29 | 30 | uint32_t data_0 = 42; 31 | uint32_t data_1 = 0xDEADBEEF; 32 | memcpy(ptrs[0], &data_0, sizeof(uint32_t)); 33 | memcpy(ptrs[1], &data_1, sizeof(uint32_t)); 34 | 35 | result = opalDestroyBuffer(device, buffers[0]); 36 | assert(result == OPAL_SUCCESS); 37 | 38 | result = opalDestroyBuffer(device, buffers[1]); 39 | assert(result == OPAL_SUCCESS); 40 | } 41 | 42 | int main() 43 | { 44 | Opal_Instance instance = OPAL_NULL_HANDLE; 45 | 46 | Opal_InstanceDesc instance_desc = 47 | { 48 | "02_buffers", 49 | "Opal", 50 | 0, 51 | 0, 52 | OPAL_DEFAULT_HEAP_SIZE, 53 | OPAL_DEFAULT_HEAP_ALLOCATIONS, 54 | OPAL_DEFAULT_HEAPS, 55 | }; 56 | 57 | Opal_Result result = opalCreateInstance(OPAL_API_AUTO, &instance_desc, &instance); 58 | assert(result == OPAL_SUCCESS); 59 | 60 | Opal_Device device = OPAL_NULL_HANDLE; 61 | result = opalCreateDefaultDevice(instance, OPAL_DEVICE_HINT_DEFAULT, &device); 62 | assert(result == OPAL_SUCCESS); 63 | 64 | testBuffers(device); 65 | 66 | result = opalDestroyDevice(device); 67 | assert(result == OPAL_SUCCESS); 68 | 69 | result = opalDestroyInstance(instance); 70 | assert(result == OPAL_SUCCESS); 71 | 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /samples/03_textures/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET 03_textures) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ) 14 | 15 | file(GLOB HEADERS 16 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 17 | ) 18 | 19 | # ================================================================================================== 20 | # Target 21 | # ================================================================================================== 22 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 23 | 24 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 25 | 26 | # ================================================================================================== 27 | # Includes 28 | # ================================================================================================== 29 | target_include_directories(${TARGET} PUBLIC ${OPAL_API_DIR}) 30 | 31 | # ================================================================================================== 32 | # Preprocessor 33 | # ================================================================================================== 34 | 35 | # ================================================================================================== 36 | # Libraries 37 | # ================================================================================================== 38 | target_link_libraries(${TARGET} PUBLIC opal) 39 | 40 | # ================================================================================================== 41 | # Custom commands 42 | # ================================================================================================== 43 | 44 | # ================================================================================================== 45 | # Installation 46 | # ================================================================================================== 47 | if (EMSCRIPTEN) 48 | install( 49 | FILES 50 | "$/${TARGET}.js" 51 | "$/${TARGET}.wasm" 52 | "$/${TARGET}.html" 53 | DESTINATION bin 54 | ) 55 | else() 56 | install( 57 | TARGETS ${TARGET} 58 | EXPORT ${TARGET} 59 | RUNTIME DESTINATION bin 60 | LIBRARY DESTINATION lib 61 | ARCHIVE DESTINATION lib 62 | INCLUDES DESTINATION include 63 | PUBLIC_HEADER DESTINATION include 64 | ) 65 | endif() 66 | -------------------------------------------------------------------------------- /samples/03_textures/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void testTextures(Opal_Device device) 6 | { 7 | Opal_Texture textures[2] = {OPAL_NULL_HANDLE, OPAL_NULL_HANDLE}; 8 | 9 | Opal_TextureDesc desc = 10 | { 11 | OPAL_TEXTURE_TYPE_2D, 12 | OPAL_TEXTURE_FORMAT_RGBA8_UNORM, 13 | 128, 14 | 128, 15 | 1, 16 | 1, 17 | 1, 18 | OPAL_SAMPLES_1, 19 | (Opal_TextureUsageFlags)(OPAL_TEXTURE_USAGE_SHADER_SAMPLED | OPAL_TEXTURE_USAGE_FRAMEBUFFER_ATTACHMENT), 20 | OPAL_ALLOCATION_HINT_AUTO, 21 | }; 22 | 23 | Opal_Result result = opalCreateTexture(device, &desc, &textures[0]); 24 | assert(result == OPAL_SUCCESS); 25 | 26 | result = opalCreateTexture(device, &desc, &textures[1]); 27 | assert(result == OPAL_SUCCESS); 28 | 29 | result = opalDestroyTexture(device, textures[0]); 30 | assert(result == OPAL_SUCCESS); 31 | 32 | result = opalDestroyTexture(device, textures[1]); 33 | assert(result == OPAL_SUCCESS); 34 | } 35 | 36 | int main() 37 | { 38 | Opal_Instance instance = OPAL_NULL_HANDLE; 39 | 40 | Opal_InstanceDesc instance_desc = 41 | { 42 | "03_textures", 43 | "Opal", 44 | 0, 45 | 0, 46 | OPAL_DEFAULT_HEAP_SIZE, 47 | OPAL_DEFAULT_HEAP_ALLOCATIONS, 48 | OPAL_DEFAULT_HEAPS, 49 | }; 50 | 51 | Opal_Result result = opalCreateInstance(OPAL_API_AUTO, &instance_desc, &instance); 52 | assert(result == OPAL_SUCCESS); 53 | 54 | Opal_Device device = OPAL_NULL_HANDLE; 55 | result = opalCreateDefaultDevice(instance, OPAL_DEVICE_HINT_DEFAULT, &device); 56 | assert(result == OPAL_SUCCESS); 57 | 58 | testTextures(device); 59 | 60 | result = opalDestroyDevice(device); 61 | assert(result == OPAL_SUCCESS); 62 | 63 | result = opalDestroyInstance(instance); 64 | assert(result == OPAL_SUCCESS); 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /samples/04_triangle/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET 04_triangle) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | if (WIN32) 8 | set(OPAL_PLATFORM_DEFINES OPAL_PLATFORM_WINDOWS NOMINMAX) 9 | endif() 10 | 11 | if (APPLE) 12 | set(OPAL_PLATFORM_DEFINES OPAL_PLATFORM_MACOS) 13 | endif() 14 | 15 | if (EMSCRIPTEN) 16 | set(OPAL_PLATFORM_DEFINES OPAL_PLATFORM_WEB) 17 | endif() 18 | 19 | # ================================================================================================== 20 | # Sources 21 | # ================================================================================================== 22 | file(GLOB SOURCES 23 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 24 | ) 25 | 26 | file(GLOB HEADERS 27 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 28 | ) 29 | 30 | # ================================================================================================== 31 | # Target 32 | # ================================================================================================== 33 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 34 | 35 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 36 | 37 | # ================================================================================================== 38 | # Includes 39 | # ================================================================================================== 40 | target_include_directories(${TARGET} PUBLIC ${OPAL_API_DIR}) 41 | 42 | # ================================================================================================== 43 | # Preprocessor 44 | # ================================================================================================== 45 | target_compile_definitions(${TARGET} PRIVATE ${OPAL_PLATFORM_DEFINES}) 46 | 47 | # ================================================================================================== 48 | # Linker 49 | # ================================================================================================== 50 | if (EMSCRIPTEN) 51 | # TODO: could be better 52 | set_target_properties(${TARGET} PROPERTIES LINK_FLAGS " 53 | --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/shaders/webgpu/main.vert.wgsl@samples/04_triangle/shaders/webgpu/main.vert.wgsl 54 | --preload-file ${CMAKE_CURRENT_SOURCE_DIR}/shaders/webgpu/main.frag.wgsl@samples/04_triangle/shaders/webgpu/main.frag.wgsl 55 | ") 56 | endif() 57 | 58 | # ================================================================================================== 59 | # Libraries 60 | # ================================================================================================== 61 | target_link_libraries(${TARGET} PUBLIC opal) 62 | 63 | # ================================================================================================== 64 | # Custom commands 65 | # ================================================================================================== 66 | 67 | # ================================================================================================== 68 | # Installation 69 | # ================================================================================================== 70 | if (EMSCRIPTEN) 71 | install( 72 | FILES 73 | "$/${TARGET}.js" 74 | "$/${TARGET}.wasm" 75 | "$/${TARGET}.html" 76 | "$/${TARGET}.data" 77 | DESTINATION bin 78 | ) 79 | else() 80 | install( 81 | TARGETS ${TARGET} 82 | EXPORT ${TARGET} 83 | RUNTIME DESTINATION bin 84 | LIBRARY DESTINATION lib 85 | ARCHIVE DESTINATION lib 86 | INCLUDES DESTINATION include 87 | PUBLIC_HEADER DESTINATION include 88 | ) 89 | endif() 90 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/directx12/main.frag.cso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seednull/opal/88890c4090226145f4cf8c02a2eb99c86f788528/samples/04_triangle/shaders/directx12/main.frag.cso -------------------------------------------------------------------------------- /samples/04_triangle/shaders/directx12/main.frag.hlsl: -------------------------------------------------------------------------------- 1 | struct VertexOutput 2 | { 3 | float4 position: SV_Position; 4 | float4 color: COLOR0; 5 | }; 6 | 7 | float4 main(VertexOutput input): SV_Target 8 | { 9 | return float4(pow(input.color.rgb, 1.0f / 2.2f), input.color.a); 10 | } 11 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/directx12/main.vert.cso: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seednull/opal/88890c4090226145f4cf8c02a2eb99c86f788528/samples/04_triangle/shaders/directx12/main.vert.cso -------------------------------------------------------------------------------- /samples/04_triangle/shaders/directx12/main.vert.hlsl: -------------------------------------------------------------------------------- 1 | struct VertexInput 2 | { 3 | float4 position: LOCATION0; 4 | float4 color: LOCATION1; 5 | }; 6 | 7 | struct VertexOutput 8 | { 9 | float4 position: SV_Position; 10 | float4 color: COLOR0; 11 | }; 12 | 13 | VertexOutput main(VertexInput input) 14 | { 15 | VertexOutput result; 16 | 17 | result.position = float4(input.position.xyz, 1.0f); 18 | result.color = input.color; 19 | 20 | return result; 21 | } 22 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/vulkan/main.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec4 in_color; 4 | layout(location = 0) out vec4 out_color; 5 | 6 | void main() 7 | { 8 | out_color.rgb = pow(in_color.rgb, vec3(1.0f / 2.2f)); 9 | out_color.a = in_color.a; 10 | } 11 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/vulkan/main.frag.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seednull/opal/88890c4090226145f4cf8c02a2eb99c86f788528/samples/04_triangle/shaders/vulkan/main.frag.spv -------------------------------------------------------------------------------- /samples/04_triangle/shaders/vulkan/main.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 450 2 | 3 | layout(location = 0) in vec4 in_position; 4 | layout(location = 1) in vec4 in_color; 5 | 6 | layout(location = 0) out vec4 out_color; 7 | 8 | void main() 9 | { 10 | gl_Position = vec4(in_position.xyz, 1.0); 11 | out_color = in_color; 12 | } 13 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/vulkan/main.vert.spv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seednull/opal/88890c4090226145f4cf8c02a2eb99c86f788528/samples/04_triangle/shaders/vulkan/main.vert.spv -------------------------------------------------------------------------------- /samples/04_triangle/shaders/webgpu/main.frag.wgsl: -------------------------------------------------------------------------------- 1 | struct VertexOutput 2 | { 3 | @builtin(position) position: vec4f, 4 | @location(0) color: vec4f 5 | }; 6 | 7 | @fragment 8 | fn main(input: VertexOutput) -> @location(0) vec4f 9 | { 10 | return vec4f(pow(input.color.rgb, vec3f(1.0 / 2.2)), input.color.a); 11 | } 12 | -------------------------------------------------------------------------------- /samples/04_triangle/shaders/webgpu/main.vert.wgsl: -------------------------------------------------------------------------------- 1 | struct VertexInput 2 | { 3 | @builtin(vertex_index) index: u32, 4 | @location(0) position: vec4f, 5 | @location(1) color: vec4f 6 | }; 7 | 8 | struct VertexOutput 9 | { 10 | @builtin(position) position: vec4f, 11 | @location(0) color: vec4f 12 | }; 13 | 14 | @vertex 15 | fn main(input: VertexInput) -> VertexOutput 16 | { 17 | var out: VertexOutput; 18 | 19 | out.position = vec4(input.position.xyz, 1.0); 20 | out.color = input.color; 21 | 22 | return out; 23 | } 24 | -------------------------------------------------------------------------------- /src/common/bump.c: -------------------------------------------------------------------------------- 1 | #include "bump.h" 2 | #include "intrinsics.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* 9 | */ 10 | Opal_Result opal_bumpInitialize(Opal_Bump *bump, uint32_t capacity) 11 | { 12 | assert(bump); 13 | assert(capacity > 0); 14 | 15 | memset(bump, 0, sizeof(Opal_Bump)); 16 | 17 | bump->capacity = capacity; 18 | bump->data = (uint8_t *)malloc(capacity); 19 | 20 | return OPAL_SUCCESS; 21 | } 22 | 23 | Opal_Result opal_bumpShutdown(Opal_Bump *bump) 24 | { 25 | assert(bump); 26 | 27 | free(bump->data); 28 | 29 | memset(bump, 0, sizeof(Opal_Bump)); 30 | 31 | return OPAL_SUCCESS; 32 | } 33 | 34 | /* 35 | */ 36 | uint32_t opal_bumpAlloc(Opal_Bump *bump, uint32_t size) 37 | { 38 | assert(bump); 39 | assert(bump->data); 40 | 41 | uint32_t new_capacity = bump->size + size; 42 | 43 | if (bump->capacity < new_capacity) 44 | { 45 | bump->data = (uint8_t *)realloc(bump->data, new_capacity); 46 | bump->capacity = new_capacity; 47 | } 48 | 49 | uint32_t offset = bump->size; 50 | bump->size += size; 51 | 52 | return offset; 53 | } 54 | 55 | Opal_Result opal_bumpReset(Opal_Bump *bump) 56 | { 57 | assert(bump); 58 | assert(bump->data); 59 | 60 | bump->size = 0; 61 | 62 | return OPAL_SUCCESS; 63 | } 64 | -------------------------------------------------------------------------------- /src/common/bump.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | typedef struct Opal_Bump_t 6 | { 7 | uint8_t *data; 8 | uint32_t size; 9 | uint32_t capacity; 10 | } Opal_Bump; 11 | 12 | Opal_Result opal_bumpInitialize(Opal_Bump *bump, uint32_t capacity); 13 | Opal_Result opal_bumpShutdown(Opal_Bump *bump); 14 | 15 | uint32_t opal_bumpAlloc(Opal_Bump *bump, uint32_t size); 16 | Opal_Result opal_bumpReset(Opal_Bump *bump); 17 | -------------------------------------------------------------------------------- /src/common/heap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define OPAL_MANTISSA_BITS 3 6 | #define OPAL_MANTISSA_MAX 0x00000008 7 | #define OPAL_MANTISSA_MASK 0x00000007 8 | 9 | #define OPAL_EXPONENT_BITS 5 10 | #define OPAL_EXPONENT_MAX 0x00000020 11 | 12 | #define OPAL_NUM_SPARSE_BINS OPAL_EXPONENT_MAX 13 | #define OPAL_NUM_LINEAR_BINS OPAL_MANTISSA_MAX 14 | #define OPAL_NUM_BINS OPAL_NUM_SPARSE_BINS * OPAL_NUM_LINEAR_BINS 15 | 16 | #define OPAL_NODE_INDEX_NULL 0xFFFFFFFF 17 | #define OPAL_LINEAR_BIN_INDEX_NULL 0xFF 18 | 19 | typedef uint8_t Opal_BinIndex; 20 | typedef uint32_t Opal_NodeIndex; 21 | 22 | typedef struct Opal_HeapAllocation_t 23 | { 24 | uint32_t offset; 25 | Opal_NodeIndex metadata; 26 | } Opal_HeapAllocation; 27 | 28 | typedef struct Opal_HeapNode_t 29 | { 30 | uint32_t offset; 31 | uint32_t size; 32 | Opal_NodeIndex next_bin; 33 | Opal_NodeIndex prev_bin; 34 | Opal_NodeIndex next_neighbour; 35 | Opal_NodeIndex prev_neighbour; 36 | uint8_t used; 37 | } Opal_HeapNode; 38 | 39 | typedef struct Opal_Heap_t 40 | { 41 | uint32_t used_sparse_bins; 42 | uint8_t used_linear_bins[OPAL_NUM_SPARSE_BINS]; 43 | Opal_NodeIndex bins[OPAL_NUM_BINS]; 44 | Opal_HeapNode *nodes; 45 | Opal_NodeIndex *free_indices; 46 | uint32_t num_nodes; 47 | uint32_t num_free_nodes; 48 | uint32_t size; 49 | } Opal_Heap; 50 | 51 | Opal_Result opal_heapInitialize(Opal_Heap *heap, uint32_t size, uint32_t max_allocations); 52 | Opal_Result opal_heapShutdown(Opal_Heap *heap); 53 | 54 | Opal_Result opal_heapAlloc(Opal_Heap *heap, uint32_t size, Opal_HeapAllocation *allocation); 55 | Opal_Result opal_heapAllocAligned(Opal_Heap *heap, uint32_t size, uint32_t alignment, Opal_HeapAllocation *allocation); 56 | 57 | Opal_Result opal_heapStageAlloc(const Opal_Heap *heap, uint32_t size, Opal_NodeIndex *node_index, uint32_t *offset); 58 | Opal_Result opal_heapStageAllocAligned(const Opal_Heap *heap, uint32_t size, uint32_t alignment, Opal_NodeIndex *node_index, uint32_t *offset); 59 | Opal_Result opal_heapCommitAlloc(Opal_Heap *heap, Opal_NodeIndex node_index, uint32_t offset, uint32_t size); 60 | 61 | Opal_Result opal_heapFree(Opal_Heap *heap, Opal_HeapAllocation allocation); 62 | -------------------------------------------------------------------------------- /src/common/intrinsics.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | // Note: 'static' keyword is intentionally put here to avoid linker errors on emscripten. 7 | // If compiled only with OPAL_INLINE, it searches for symbols and fails to link. 8 | // 9 | // On a side, it's ok to keep these intrinsics statis and have multiple copies in 10 | // translation units. We hope the compiler will inline them anyways. 11 | 12 | /* 13 | */ 14 | static OPAL_INLINE uint32_t lzcnt(uint32_t value) 15 | { 16 | assert(value != 0); 17 | 18 | #ifdef _MSC_VER 19 | unsigned long result = 0; 20 | _BitScanReverse(&result, value); 21 | return 31 - result; 22 | #else 23 | return __builtin_clz(value); 24 | #endif 25 | } 26 | 27 | static OPAL_INLINE uint32_t tzcnt(uint32_t value) 28 | { 29 | assert(value != 0); 30 | 31 | #ifdef _MSC_VER 32 | unsigned long result = 0; 33 | _BitScanForward(&result, value); 34 | return result; 35 | #else 36 | return __builtin_ctz(value); 37 | #endif 38 | } 39 | 40 | static OPAL_INLINE uint32_t popcnt(uint32_t value) 41 | { 42 | #ifdef _MSC_VER 43 | return __popcnt(value); 44 | #else 45 | return __builtin_popcount(value); 46 | #endif 47 | } 48 | 49 | static OPAL_INLINE uint32_t isPow2u(uint32_t value) 50 | { 51 | return (value & (value - 1)) == 0; 52 | } 53 | 54 | static OPAL_INLINE uint64_t isPow2ul(uint64_t value) 55 | { 56 | return (value & (value - 1)) == 0; 57 | } 58 | 59 | static OPAL_INLINE uint32_t isAlignedu(uint32_t value, uint32_t alignment) 60 | { 61 | assert(isPow2u(alignment)); 62 | 63 | uint32_t mask = alignment - 1; 64 | return (value & mask) == 0; 65 | } 66 | 67 | static OPAL_INLINE uint64_t isAlignedul(uint64_t value, uint64_t alignment) 68 | { 69 | assert(isPow2ul(alignment)); 70 | 71 | uint64_t mask = alignment - 1; 72 | return (value & mask) == 0; 73 | } 74 | 75 | static OPAL_INLINE uint32_t alignDown(uint32_t value, uint32_t alignment) 76 | { 77 | assert(isPow2u(alignment)); 78 | 79 | uint32_t mask = alignment - 1; 80 | return value & ~mask; 81 | } 82 | 83 | static OPAL_INLINE uint64_t alignDownul(uint64_t value, uint64_t alignment) 84 | { 85 | assert(isPow2ul(alignment)); 86 | 87 | uint64_t mask = alignment - 1; 88 | return value & ~mask; 89 | } 90 | 91 | static OPAL_INLINE uint32_t alignUp(uint32_t value, uint32_t alignment) 92 | { 93 | assert(isPow2u(alignment)); 94 | 95 | uint32_t mask = alignment - 1; 96 | return (value + mask) & ~mask; 97 | } 98 | 99 | static OPAL_INLINE uint64_t alignUpul(uint64_t value, uint64_t alignment) 100 | { 101 | assert(isPow2ul(alignment)); 102 | 103 | uint64_t mask = alignment - 1; 104 | return (value + mask) & ~mask; 105 | } 106 | 107 | // NOTE: hello, microsoft ucrt 108 | #undef min 109 | #undef max 110 | 111 | static OPAL_INLINE uint32_t min(uint32_t a, uint32_t b) 112 | { 113 | return (a < b) ? a : b; 114 | } 115 | 116 | static OPAL_INLINE uint32_t max(uint32_t a, uint32_t b) 117 | { 118 | return (a < b) ? b : a; 119 | } 120 | -------------------------------------------------------------------------------- /src/common/pool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define OPAL_POOL_MAX_ELEMENTS 0x00FFFFFF 6 | #define OPAL_POOL_MAX_GENERATIONS 0xFF 7 | #define OPAL_POOL_HANDLE_NULL 0xFFFFFFFF 8 | 9 | typedef uint32_t Opal_PoolHandle; 10 | 11 | typedef struct Opal_Pool_t 12 | { 13 | uint8_t *data; 14 | uint8_t *generations; 15 | uint32_t *nexts; 16 | uint32_t *prevs; 17 | uint32_t head; 18 | uint32_t tail; 19 | 20 | uint32_t element_size; 21 | uint32_t size; 22 | uint32_t capacity; 23 | 24 | uint32_t *masks; 25 | uint32_t *indices; 26 | uint32_t num_free_indices; 27 | } Opal_Pool; 28 | 29 | Opal_Result opal_poolInitialize(Opal_Pool *pool, uint32_t element_size, uint32_t capacity); 30 | Opal_Result opal_poolShutdown(Opal_Pool *pool); 31 | 32 | Opal_PoolHandle opal_poolAddElement(Opal_Pool *pool, const void *data); 33 | Opal_Result opal_poolRemoveElement(Opal_Pool *pool, Opal_PoolHandle handle); 34 | void *opal_poolGetElement(const Opal_Pool *pool, Opal_PoolHandle handle); 35 | 36 | void *opal_poolGetElementByIndex(const Opal_Pool *pool, uint32_t index); 37 | uint32_t opal_poolGetHeadIndex(const Opal_Pool *pool); 38 | uint32_t opal_poolGetTailIndex(const Opal_Pool *pool); 39 | uint32_t opal_poolGetNextIndex(const Opal_Pool *pool, uint32_t index); 40 | uint32_t opal_poolGetPrevIndex(const Opal_Pool *pool, uint32_t index); 41 | -------------------------------------------------------------------------------- /src/common/ring.c: -------------------------------------------------------------------------------- 1 | #include "ring.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | Opal_Result opal_ringInitialize(Opal_Ring *ring, uint32_t size) 8 | { 9 | assert(ring); 10 | assert(size > 0); 11 | 12 | ring->data = (uint8_t *)malloc(size); 13 | ring->capacity = size; 14 | ring->size = 0; 15 | ring->read = 0; 16 | ring->write = 0; 17 | 18 | return OPAL_SUCCESS; 19 | } 20 | 21 | Opal_Result opal_ringShutdown(Opal_Ring *ring) 22 | { 23 | assert(ring); 24 | free(ring->data); 25 | 26 | return OPAL_SUCCESS; 27 | } 28 | 29 | uint32_t opal_ringGetSize(const Opal_Ring *ring) 30 | { 31 | assert(ring); 32 | return ring->size; 33 | } 34 | 35 | void opal_ringRead(Opal_Ring *ring, void *data, uint32_t size) 36 | { 37 | assert(ring); 38 | assert(ring->size >= size); 39 | assert(data); 40 | 41 | if (size == 0) 42 | return; 43 | 44 | uint8_t *begin_ptr = ring->data + ring->read; 45 | 46 | ring->read += size; 47 | ring->read %= ring->capacity; 48 | ring->size -= size; 49 | 50 | uint8_t *end_ptr = ring->data + ring->read; 51 | 52 | if (begin_ptr < end_ptr) 53 | memcpy(data, begin_ptr, size); 54 | else 55 | { 56 | uint32_t remainder = size - ring->read; 57 | memcpy(data, begin_ptr, remainder); 58 | 59 | if (ring->read > 0) 60 | memcpy((uint8_t *)data + remainder, ring->data, ring->read); 61 | } 62 | } 63 | 64 | void opal_ringWrite(Opal_Ring *ring, const void *data, uint32_t size) 65 | { 66 | if (size == 0) 67 | return; 68 | 69 | assert(ring); 70 | assert(ring->size + size <= ring->capacity); 71 | assert(data); 72 | 73 | uint8_t *begin_ptr = ring->data + ring->write; 74 | 75 | ring->write += size; 76 | ring->write %= ring->capacity; 77 | ring->size += size; 78 | 79 | uint8_t *end_ptr = ring->data + ring->write; 80 | 81 | if (begin_ptr < end_ptr) 82 | memcpy(begin_ptr, data, size); 83 | else 84 | { 85 | uint32_t remainder = size - ring->write; 86 | memcpy(begin_ptr, data, remainder); 87 | 88 | if (ring->write > 0) 89 | memcpy(ring->data, (uint8_t *)data + remainder, ring->write); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/common/ring.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | typedef struct Opal_Ring_t 6 | { 7 | uint8_t *data; 8 | uint32_t capacity; 9 | uint32_t size; 10 | uint32_t read; 11 | uint32_t write; 12 | } Opal_Ring; 13 | 14 | Opal_Result opal_ringInitialize(Opal_Ring *ring, uint32_t size); 15 | Opal_Result opal_ringShutdown(Opal_Ring *ring); 16 | 17 | uint32_t opal_ringGetSize(const Opal_Ring *ring); 18 | 19 | void opal_ringRead(Opal_Ring *ring, void *data, uint32_t size); 20 | void opal_ringWrite(Opal_Ring *ring, const void *data, uint32_t size); 21 | -------------------------------------------------------------------------------- /src/directx12/directx12_guids.c: -------------------------------------------------------------------------------- 1 | #define INITGUID 2 | #include 3 | #include 4 | -------------------------------------------------------------------------------- /src/metal/metal_instance.m: -------------------------------------------------------------------------------- 1 | #include "metal_internal.h" 2 | 3 | /* 4 | */ 5 | static Opal_Result metal_instanceEnumerateDevices(Opal_Instance this, uint32_t *device_count, Opal_DeviceInfo *infos) 6 | { 7 | assert(this); 8 | assert(device_count); 9 | 10 | NSArray> *devices = MTLCopyAllDevices(); 11 | if (!devices) 12 | return OPAL_METAL_ERROR; 13 | 14 | if (infos) 15 | { 16 | for (uint32_t i = 0; i < devices.count; ++i) 17 | { 18 | id device = devices[i]; 19 | 20 | Opal_Result result = metal_fillDeviceInfo(device, &infos[i]); 21 | if (result != OPAL_SUCCESS) 22 | { 23 | [devices release]; 24 | return result; 25 | } 26 | } 27 | } 28 | 29 | *device_count = devices.count; 30 | 31 | [devices release]; 32 | return OPAL_SUCCESS; 33 | } 34 | 35 | static Opal_Result metal_instanceCreateDefaultDevice(Opal_Instance this, Opal_DeviceHint hint, Opal_Device *device) 36 | { 37 | assert(this); 38 | assert(device); 39 | 40 | NSArray> *metal_devices = MTLCopyAllDevices(); 41 | if (!metal_devices) 42 | return OPAL_METAL_ERROR; 43 | 44 | uint32_t best_score = 0; 45 | id best_metal_device = 0; 46 | 47 | for (uint32_t i = 0; i < metal_devices.count; ++i) 48 | { 49 | id metal_device = metal_devices[i]; 50 | Opal_DeviceInfo info = {0}; 51 | 52 | Opal_Result result = metal_fillDeviceInfo(metal_device, &info); 53 | if (result != OPAL_SUCCESS) 54 | { 55 | [metal_devices release]; 56 | return result; 57 | } 58 | 59 | uint32_t score = opal_evaluateDevice(&info, hint); 60 | if (best_score < score) 61 | { 62 | best_score = score; 63 | best_metal_device = metal_device; 64 | } 65 | } 66 | [metal_devices release]; 67 | 68 | Metal_Instance *instance_ptr = (Metal_Instance *)this; 69 | Metal_Device *device_ptr = (Metal_Device *)malloc(sizeof(Metal_Device)); 70 | assert(device_ptr); 71 | 72 | Opal_Result result = metal_deviceInitialize(device_ptr, instance_ptr, best_metal_device); 73 | if (result != OPAL_SUCCESS) 74 | { 75 | device_ptr->vtbl->destroyDevice((Opal_Device)device_ptr); 76 | return result; 77 | } 78 | 79 | *device = (Opal_Device)device_ptr; 80 | return OPAL_SUCCESS; 81 | } 82 | 83 | static Opal_Result metal_instanceCreateDevice(Opal_Instance this, uint32_t index, Opal_Device *device) 84 | { 85 | assert(this); 86 | assert(device); 87 | 88 | NSArray> *metal_devices = MTLCopyAllDevices(); 89 | if (!metal_devices) 90 | return OPAL_METAL_ERROR; 91 | 92 | if (index >= metal_devices.count) 93 | { 94 | [metal_devices release]; 95 | return OPAL_INVALID_DEVICE_INDEX; 96 | } 97 | 98 | id metal_device = metal_devices[index]; 99 | [metal_devices release]; 100 | 101 | Metal_Instance *instance_ptr = (Metal_Instance *)this; 102 | Metal_Device *device_ptr = (Metal_Device *)malloc(sizeof(Metal_Device)); 103 | assert(device_ptr); 104 | 105 | Opal_Result result = metal_deviceInitialize(device_ptr, instance_ptr, metal_device); 106 | if (result != OPAL_SUCCESS) 107 | { 108 | device_ptr->vtbl->destroyDevice((Opal_Device)device_ptr); 109 | return result; 110 | } 111 | 112 | *device = (Opal_Device)device_ptr; 113 | return OPAL_SUCCESS; 114 | } 115 | 116 | static Opal_Result metal_instanceDestroy(Opal_Instance this) 117 | { 118 | assert(this); 119 | 120 | Metal_Instance *ptr = (Metal_Instance *)this; 121 | 122 | free(ptr->application_name); 123 | free(ptr->engine_name); 124 | 125 | free(ptr); 126 | return OPAL_SUCCESS; 127 | } 128 | 129 | /* 130 | */ 131 | static Opal_InstanceTable instance_vtbl = 132 | { 133 | metal_instanceDestroy, 134 | metal_instanceEnumerateDevices, 135 | metal_instanceCreateDevice, 136 | metal_instanceCreateDefaultDevice, 137 | }; 138 | 139 | /* 140 | */ 141 | Opal_Result metal_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 142 | { 143 | assert(desc); 144 | assert(instance); 145 | 146 | Metal_Instance *ptr = (Metal_Instance *)malloc(sizeof(Metal_Instance)); 147 | assert(ptr); 148 | 149 | // vtable 150 | ptr->vtbl = &instance_vtbl; 151 | 152 | // info 153 | ptr->application_name = strdup(desc->application_name); 154 | ptr->application_version = desc->application_version; 155 | ptr->engine_name = strdup(desc->engine_name); 156 | ptr->engine_version = desc->engine_version; 157 | 158 | *instance = (Opal_Instance)ptr; 159 | return OPAL_SUCCESS; 160 | } 161 | -------------------------------------------------------------------------------- /src/metal/metal_internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "opal_internal.h" 4 | 5 | #import 6 | 7 | typedef struct Metal_Instance_t 8 | { 9 | Opal_InstanceTable *vtbl; 10 | char *application_name; 11 | uint32_t application_version; 12 | char *engine_name; 13 | uint32_t engine_version; 14 | } Metal_Instance; 15 | 16 | typedef struct Metal_Device_t 17 | { 18 | Opal_DeviceTable *vtbl; 19 | id device; 20 | } Metal_Device; 21 | 22 | Opal_Result metal_deviceInitialize(Metal_Device *device_ptr, Metal_Instance *instance_ptr, id device); 23 | Opal_Result metal_fillDeviceInfo(id device, Opal_DeviceInfo *info); 24 | -------------------------------------------------------------------------------- /src/null/null_instance.c: -------------------------------------------------------------------------------- 1 | #include "null_internal.h" 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | /* 8 | */ 9 | static Opal_Result null_instanceEnumerateDevices(Opal_Instance this, uint32_t *device_count, Opal_DeviceInfo *infos) 10 | { 11 | assert(this); 12 | assert(device_count); 13 | 14 | OPAL_UNUSED(this); 15 | 16 | *device_count = 1; 17 | 18 | if (infos) 19 | null_fillDeviceInfo(&infos[0]); 20 | 21 | return OPAL_SUCCESS; 22 | } 23 | 24 | static Opal_Result null_instanceCreateSurface(Opal_Instance this, void *handle, Opal_Surface *surface) 25 | { 26 | OPAL_UNUSED(this); 27 | OPAL_UNUSED(handle); 28 | OPAL_UNUSED(surface); 29 | 30 | return OPAL_NOT_SUPPORTED; 31 | } 32 | 33 | static Opal_Result null_instanceCreateDefaultDevice(Opal_Instance this, Opal_DeviceHint hint, Opal_Device *device) 34 | { 35 | assert(this); 36 | assert(device); 37 | 38 | OPAL_UNUSED(hint); 39 | 40 | Null_Instance *instance_ptr = (Null_Instance *)this; 41 | Null_Device *device_ptr = (Null_Device *)malloc(sizeof(Null_Device)); 42 | assert(device_ptr); 43 | 44 | Opal_Result result = null_deviceInitialize(device_ptr, instance_ptr); 45 | if (result != OPAL_SUCCESS) 46 | { 47 | device_ptr->vtbl->destroyDevice((Opal_Device)device_ptr); 48 | return result; 49 | } 50 | 51 | *device = (Opal_Device)device_ptr; 52 | return OPAL_SUCCESS; 53 | } 54 | 55 | static Opal_Result null_instanceCreateDevice(Opal_Instance this, uint32_t index, Opal_Device *device) 56 | { 57 | assert(this); 58 | assert(device); 59 | 60 | if (index != 0) 61 | return OPAL_INVALID_DEVICE_INDEX; 62 | 63 | Null_Instance *instance_ptr = (Null_Instance *)this; 64 | Null_Device *device_ptr = (Null_Device *)malloc(sizeof(Null_Device)); 65 | assert(device_ptr); 66 | 67 | Opal_Result result = null_deviceInitialize(device_ptr, instance_ptr); 68 | if (result != OPAL_SUCCESS) 69 | { 70 | device_ptr->vtbl->destroyDevice((Opal_Device)device_ptr); 71 | return result; 72 | } 73 | 74 | *device = (Opal_Device)device_ptr; 75 | return OPAL_SUCCESS; 76 | } 77 | 78 | static Opal_Result null_instanceDestroySurface(Opal_Instance this, Opal_Surface surface) 79 | { 80 | OPAL_UNUSED(this); 81 | OPAL_UNUSED(surface); 82 | 83 | return OPAL_NOT_SUPPORTED; 84 | } 85 | 86 | static Opal_Result null_instanceDestroy(Opal_Instance this) 87 | { 88 | assert(this); 89 | 90 | Null_Instance *ptr = (Null_Instance *)this; 91 | 92 | free(ptr->application_name); 93 | free(ptr->engine_name); 94 | 95 | free(ptr); 96 | return OPAL_SUCCESS; 97 | } 98 | 99 | /* 100 | */ 101 | static Opal_InstanceTable instance_vtbl = 102 | { 103 | null_instanceEnumerateDevices, 104 | 105 | null_instanceCreateSurface, 106 | null_instanceCreateDevice, 107 | null_instanceCreateDefaultDevice, 108 | 109 | null_instanceDestroySurface, 110 | null_instanceDestroy, 111 | }; 112 | 113 | /* 114 | */ 115 | Opal_Result null_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 116 | { 117 | assert(desc); 118 | assert(instance); 119 | 120 | Null_Instance *ptr = (Null_Instance *)malloc(sizeof(Null_Instance)); 121 | assert(ptr); 122 | 123 | // vtable 124 | ptr->vtbl = &instance_vtbl; 125 | 126 | // info 127 | ptr->application_name = strdup(desc->application_name); 128 | ptr->application_version = desc->application_version; 129 | ptr->engine_name = strdup(desc->engine_name); 130 | ptr->engine_version = desc->engine_version; 131 | 132 | *instance = (Opal_Instance)ptr; 133 | return OPAL_SUCCESS; 134 | } 135 | -------------------------------------------------------------------------------- /src/null/null_internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "opal_internal.h" 4 | 5 | typedef struct Null_Instance_t 6 | { 7 | Opal_InstanceTable *vtbl; 8 | char *application_name; 9 | uint32_t application_version; 10 | char *engine_name; 11 | uint32_t engine_version; 12 | } Null_Instance; 13 | 14 | typedef struct Null_Device_t 15 | { 16 | Opal_DeviceTable *vtbl; 17 | Opal_DeviceInfo info; 18 | Opal_DeviceLimits limits; 19 | } Null_Device; 20 | 21 | Opal_Result null_fillDeviceInfo(Opal_DeviceInfo *info); 22 | Opal_Result null_deviceInitialize(Null_Device *device_ptr, Null_Instance *instance_ptr); 23 | -------------------------------------------------------------------------------- /src/opal_internal.c: -------------------------------------------------------------------------------- 1 | #include "opal_internal.h" 2 | 3 | #include 4 | 5 | static uint32_t device_type_default_scores[] = 6 | { 7 | 1000, 8 | 100, 9 | 0, 10 | 0, 11 | 0, 12 | }; 13 | 14 | static uint32_t device_type_high_performance_scores[] = 15 | { 16 | 1000, 17 | 100, 18 | 0, 19 | 0, 20 | 0, 21 | }; 22 | 23 | static uint32_t device_type_low_power_scores[] = 24 | { 25 | 100, 26 | 1000, 27 | 0, 28 | 0, 29 | 0, 30 | }; 31 | 32 | /* 33 | */ 34 | uint32_t opal_evaluateDevice(const Opal_DeviceInfo *info, Opal_DeviceHint hint) 35 | { 36 | assert(info); 37 | 38 | uint32_t score = 0; 39 | 40 | switch (hint) 41 | { 42 | case OPAL_DEVICE_HINT_PREFER_HIGH_PERFORMANCE: score += device_type_high_performance_scores[info->device_type]; break; 43 | case OPAL_DEVICE_HINT_PREFER_LOW_POWER: score += device_type_low_power_scores[info->device_type]; break; 44 | default: score += device_type_default_scores[info->device_type]; break; 45 | } 46 | 47 | score += info->features.tessellation_shader; 48 | score += info->features.geometry_shader; 49 | score += info->features.compute_pipeline * 10; 50 | score += info->features.meshlet_pipeline * 10; 51 | score += info->features.raytrace_pipeline * 10; 52 | 53 | return score; 54 | } 55 | 56 | #if !defined(OPAL_BACKEND_DIRECTX12) 57 | 58 | Opal_Result directx12_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 59 | { 60 | assert(desc); 61 | assert(instance); 62 | 63 | OPAL_UNUSED(desc); 64 | OPAL_UNUSED(instance); 65 | 66 | return OPAL_NOT_SUPPORTED; 67 | } 68 | 69 | #endif 70 | 71 | #if !defined(OPAL_BACKEND_WEBGPU) 72 | 73 | Opal_Result webgpu_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 74 | { 75 | assert(desc); 76 | assert(instance); 77 | 78 | OPAL_UNUSED(desc); 79 | OPAL_UNUSED(instance); 80 | 81 | return OPAL_NOT_SUPPORTED; 82 | } 83 | 84 | #endif 85 | 86 | #if !defined(OPAL_BACKEND_VULKAN) 87 | 88 | Opal_Result vulkan_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 89 | { 90 | assert(desc); 91 | assert(instance); 92 | 93 | OPAL_UNUSED(desc); 94 | OPAL_UNUSED(instance); 95 | 96 | return OPAL_NOT_SUPPORTED; 97 | } 98 | 99 | #endif 100 | 101 | #if !defined(OPAL_BACKEND_METAL) 102 | 103 | Opal_Result metal_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance) 104 | { 105 | assert(desc); 106 | assert(instance); 107 | 108 | OPAL_UNUSED(desc); 109 | OPAL_UNUSED(instance); 110 | 111 | return OPAL_NOT_SUPPORTED; 112 | } 113 | 114 | #endif 115 | -------------------------------------------------------------------------------- /src/opal_internal.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define OPAL_UNUSED(x) do { (void)(x); } while(0) 6 | 7 | Opal_Result vulkan_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance); 8 | Opal_Result directx12_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance); 9 | Opal_Result metal_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance); 10 | Opal_Result webgpu_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance); 11 | Opal_Result null_createInstance(const Opal_InstanceDesc *desc, Opal_Instance *instance); 12 | 13 | uint32_t opal_evaluateDevice(const Opal_DeviceInfo *info, Opal_DeviceHint hint); -------------------------------------------------------------------------------- /src/vulkan/vulkan_platform_win32.c: -------------------------------------------------------------------------------- 1 | #include "vulkan_internal.h" 2 | 3 | #define WIN32_LEAN_AND_MEAN 4 | #include 5 | 6 | /* 7 | */ 8 | const char *vulkan_platformGetSurfaceExtension() 9 | { 10 | return VK_KHR_WIN32_SURFACE_EXTENSION_NAME; 11 | } 12 | 13 | Opal_Result vulkan_platformCreateSurface(VkInstance instance, void *handle, VkSurfaceKHR *surface) 14 | { 15 | VkWin32SurfaceCreateInfoKHR surface_info = {0}; 16 | surface_info.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR; 17 | surface_info.hinstance = GetModuleHandle(NULL); 18 | surface_info.hwnd = (HWND)handle; 19 | 20 | VkResult result = vkCreateWin32SurfaceKHR(instance, &surface_info, NULL, surface); 21 | if (result != VK_SUCCESS) 22 | return OPAL_VULKAN_ERROR; 23 | 24 | return OPAL_SUCCESS; 25 | } 26 | -------------------------------------------------------------------------------- /tests/heap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET test_heap) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ${OPAL_DIR_SRC}/common/heap.c 14 | ) 15 | 16 | file(GLOB HEADERS 17 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 18 | ${OPAL_DIR_SRC}/common/*.h 19 | ) 20 | 21 | # ================================================================================================== 22 | # Target 23 | # ================================================================================================== 24 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 25 | 26 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 27 | 28 | # ================================================================================================== 29 | # Includes 30 | # ================================================================================================== 31 | target_include_directories(${TARGET} PUBLIC ${OPAL_DIR_API}) 32 | target_include_directories(${TARGET} PUBLIC ${OPAL_DIR_SRC}/common) 33 | 34 | # ================================================================================================== 35 | # Preprocessor 36 | # ================================================================================================== 37 | 38 | # ================================================================================================== 39 | # Libraries 40 | # ================================================================================================== 41 | target_link_libraries(${TARGET} PUBLIC gtest) 42 | 43 | # ================================================================================================== 44 | # Custom commands 45 | # ================================================================================================== 46 | 47 | # ================================================================================================== 48 | # Installation 49 | # ================================================================================================== 50 | if (NOT EMSCRIPTEN) 51 | install( 52 | TARGETS ${TARGET} 53 | EXPORT ${TARGET} 54 | RUNTIME DESTINATION bin 55 | LIBRARY DESTINATION lib 56 | ARCHIVE DESTINATION lib 57 | INCLUDES DESTINATION include 58 | PUBLIC_HEADER DESTINATION include 59 | ) 60 | endif() 61 | -------------------------------------------------------------------------------- /tests/heap/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern "C" 4 | { 5 | #include "heap.h" 6 | } 7 | 8 | constexpr uint32_t heap_size = 64 * 1024 * 1024; 9 | constexpr uint32_t max_allocations = 1000000; 10 | 11 | class HeapTest : public testing::Test 12 | { 13 | protected: 14 | void SetUp() override 15 | { 16 | Opal_Result result = opal_heapInitialize(&heap, heap_size, max_allocations); 17 | ASSERT_EQ(result, OPAL_SUCCESS); 18 | } 19 | 20 | void TearDown() override 21 | { 22 | Opal_Result result = opal_heapShutdown(&heap); 23 | ASSERT_EQ(result, OPAL_SUCCESS); 24 | } 25 | 26 | Opal_Heap heap; 27 | }; 28 | 29 | TEST_F(HeapTest, AlignedAllocsSameAlignment) 30 | { 31 | constexpr uint32_t alignment = 16; 32 | Opal_HeapAllocation allocs[2]; 33 | 34 | EXPECT_EQ(opal_heapAllocAligned(&heap, 9, alignment, &allocs[0]), OPAL_SUCCESS); 35 | EXPECT_EQ(allocs[0].offset % alignment, 0); 36 | EXPECT_EQ(allocs[0].offset, 0); 37 | 38 | EXPECT_EQ(opal_heapAllocAligned(&heap, 16, alignment, &allocs[1]), OPAL_SUCCESS); 39 | EXPECT_EQ(allocs[1].offset % alignment, 0); 40 | EXPECT_EQ(allocs[1].offset, 16); 41 | 42 | EXPECT_EQ(opal_heapFree(&heap, allocs[0]), OPAL_SUCCESS); 43 | EXPECT_EQ(opal_heapAllocAligned(&heap, 16, alignment, &allocs[0]), OPAL_SUCCESS); 44 | EXPECT_EQ(allocs[0].offset % alignment, 0); 45 | EXPECT_EQ(allocs[0].offset, 0); 46 | 47 | EXPECT_EQ(opal_heapFree(&heap, allocs[0]), OPAL_SUCCESS); 48 | EXPECT_EQ(opal_heapFree(&heap, allocs[1]), OPAL_SUCCESS); 49 | } 50 | 51 | TEST_F(HeapTest, AlignedAllocsDifferentAlignments) 52 | { 53 | constexpr uint32_t alignment1 = 16; 54 | constexpr uint32_t alignment2 = 32; 55 | 56 | Opal_HeapAllocation allocs[3]; 57 | 58 | EXPECT_EQ(opal_heapAllocAligned(&heap, 9, alignment1, &allocs[0]), OPAL_SUCCESS); 59 | EXPECT_EQ(allocs[0].offset % alignment1, 0); 60 | EXPECT_EQ(allocs[0].offset, 0); 61 | 62 | EXPECT_EQ(opal_heapAllocAligned(&heap, 16, alignment1, &allocs[1]), OPAL_SUCCESS); 63 | EXPECT_EQ(allocs[1].offset % alignment1, 0); 64 | EXPECT_EQ(allocs[1].offset, 16); 65 | 66 | EXPECT_EQ(opal_heapAllocAligned(&heap, 32, alignment2, &allocs[2]), OPAL_SUCCESS); 67 | EXPECT_EQ(allocs[2].offset % alignment2, 0); 68 | EXPECT_EQ(allocs[2].offset, 32); 69 | 70 | EXPECT_EQ(opal_heapFree(&heap, allocs[0]), OPAL_SUCCESS); 71 | EXPECT_EQ(opal_heapFree(&heap, allocs[1]), OPAL_SUCCESS); 72 | 73 | EXPECT_EQ(opal_heapAllocAligned(&heap, 32, alignment2, &allocs[1]), OPAL_SUCCESS); 74 | EXPECT_EQ(allocs[1].offset % alignment2, 0); 75 | EXPECT_EQ(allocs[1].offset, 0); 76 | 77 | EXPECT_EQ(opal_heapFree(&heap, allocs[1]), OPAL_SUCCESS); 78 | EXPECT_EQ(opal_heapFree(&heap, allocs[2]), OPAL_SUCCESS); 79 | } 80 | 81 | TEST_F(HeapTest, NonFitAlignedAlloc) 82 | { 83 | constexpr uint32_t alignment = 16; 84 | Opal_HeapAllocation allocs[3]; 85 | 86 | EXPECT_EQ(opal_heapAlloc(&heap, 3, &allocs[0]), OPAL_SUCCESS); 87 | EXPECT_EQ(allocs[0].offset, 0); 88 | 89 | EXPECT_EQ(opal_heapAlloc(&heap, 16, &allocs[1]), OPAL_SUCCESS); 90 | EXPECT_EQ(allocs[1].offset, 3); 91 | 92 | EXPECT_EQ(opal_heapAlloc(&heap, 16, &allocs[2]), OPAL_SUCCESS); 93 | EXPECT_EQ(allocs[2].offset, 19); 94 | 95 | EXPECT_EQ(opal_heapFree(&heap, allocs[1]), OPAL_SUCCESS); 96 | 97 | EXPECT_EQ(opal_heapAllocAligned(&heap, 16, alignment, &allocs[1]), OPAL_SUCCESS); 98 | EXPECT_EQ(allocs[1].offset % alignment, 0); 99 | EXPECT_EQ(allocs[1].offset, 48); 100 | 101 | EXPECT_EQ(opal_heapFree(&heap, allocs[0]), OPAL_SUCCESS); 102 | EXPECT_EQ(opal_heapFree(&heap, allocs[1]), OPAL_SUCCESS); 103 | EXPECT_EQ(opal_heapFree(&heap, allocs[2]), OPAL_SUCCESS); 104 | } 105 | 106 | int main(int argc, char **argv) 107 | { 108 | testing::InitGoogleTest(&argc, argv); 109 | return RUN_ALL_TESTS(); 110 | } 111 | -------------------------------------------------------------------------------- /tests/pool/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(TARGET test_pool) 3 | 4 | # ================================================================================================== 5 | # Variables 6 | # ================================================================================================== 7 | 8 | # ================================================================================================== 9 | # Sources 10 | # ================================================================================================== 11 | file(GLOB SOURCES 12 | ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp 13 | ${OPAL_DIR_SRC}/common/pool.c 14 | ) 15 | 16 | file(GLOB HEADERS 17 | ${CMAKE_CURRENT_SOURCE_DIR}/*.h 18 | ${OPAL_DIR_SRC}/common/*.h 19 | ) 20 | 21 | # ================================================================================================== 22 | # Target 23 | # ================================================================================================== 24 | add_executable(${TARGET} ${SOURCES} ${HEADERS}) 25 | 26 | set_target_properties(${TARGET} PROPERTIES DEBUG_POSTFIX d) 27 | 28 | # ================================================================================================== 29 | # Includes 30 | # ================================================================================================== 31 | target_include_directories(${TARGET} PUBLIC ${OPAL_DIR_API}) 32 | target_include_directories(${TARGET} PUBLIC ${OPAL_DIR_SRC}/common) 33 | 34 | # ================================================================================================== 35 | # Preprocessor 36 | # ================================================================================================== 37 | 38 | # ================================================================================================== 39 | # Libraries 40 | # ================================================================================================== 41 | target_link_libraries(${TARGET} PUBLIC gtest) 42 | 43 | # ================================================================================================== 44 | # Custom commands 45 | # ================================================================================================== 46 | 47 | # ================================================================================================== 48 | # Installation 49 | # ================================================================================================== 50 | if (NOT EMSCRIPTEN) 51 | install( 52 | TARGETS ${TARGET} 53 | EXPORT ${TARGET} 54 | RUNTIME DESTINATION bin 55 | LIBRARY DESTINATION lib 56 | ARCHIVE DESTINATION lib 57 | INCLUDES DESTINATION include 58 | PUBLIC_HEADER DESTINATION include 59 | ) 60 | endif() 61 | --------------------------------------------------------------------------------