├── .gitignore ├── .vscode └── launch.json ├── CMakeLists.txt ├── CMakePresets.json ├── LICENSE ├── README.md ├── data └── model │ ├── credits.txt │ ├── diffuse.jpg │ └── mesh.obj ├── src ├── acceleration_structure.cpp ├── acceleration_structure.h ├── demo.cpp ├── demo.h ├── gpu_mesh.h ├── kernels │ ├── copy_to_swapchain.cpp │ ├── copy_to_swapchain.h │ ├── draw_mesh.cpp │ ├── draw_mesh.h │ ├── raytrace_scene.cpp │ └── raytrace_scene.h ├── lib.cpp ├── lib.h ├── main.cpp ├── shaders │ ├── common.glsl │ ├── copy_to_swapchain.comp.glsl │ ├── raster_mesh.frag.glsl │ ├── raster_mesh.vert.glsl │ ├── rt_mesh.rchit.glsl │ ├── rt_mesh.rgen.glsl │ ├── rt_mesh.rmiss.glsl │ └── rt_utils.glsl ├── vk.cpp └── vk.h └── third-party ├── CMakeLists.txt ├── glfw ├── context.c ├── egl_context.c ├── glfw3.h ├── glfw3native.h ├── glx_context.c ├── init.c ├── input.c ├── internal.h ├── linux_joystick.c ├── linux_joystick.h ├── mappings.h ├── monitor.c ├── null_init.c ├── null_joystick.c ├── null_joystick.h ├── null_monitor.c ├── null_platform.h ├── null_window.c ├── osmesa_context.c ├── platform.c ├── platform.h ├── posix_module.c ├── posix_poll.c ├── posix_poll.h ├── posix_thread.c ├── posix_thread.h ├── posix_time.c ├── posix_time.h ├── vulkan.c ├── wgl_context.c ├── win32_init.c ├── win32_joystick.c ├── win32_joystick.h ├── win32_module.c ├── win32_monitor.c ├── win32_platform.h ├── win32_thread.c ├── win32_thread.h ├── win32_time.c ├── win32_time.h ├── win32_window.c ├── window.c ├── x11_init.c ├── x11_monitor.c ├── x11_platform.h ├── x11_window.c ├── xkb_unicode.c └── xkb_unicode.h ├── imgui ├── LICENSE.txt ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_vulkan.cpp ├── imgui_impl_vulkan.h ├── imgui_internal.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h ├── stb_image.h ├── tiny_obj_loader.h ├── vma ├── LICENSE.txt └── vk_mem_alloc.h ├── volk ├── LICENSE.md ├── README.md ├── volk.c └── volk.h └── vulkan ├── vk_enum_string_helper.h ├── vk_platform.h ├── 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.h ├── vulkan_core.h ├── vulkan_win32.h ├── vulkan_xcb.h └── vulkan_xlib.h /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | imgui.ini 3 | data/* 4 | !data/model 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "(Windows) Launch", 6 | "type": "cppvsdbg", 7 | "request": "launch", 8 | "program": "${workspaceFolder}/build/${command:cmake.buildType}/vulkan-ray-tracing.exe", 9 | "args": [], 10 | "stopAtEntry": false, 11 | "cwd": "${workspaceFolder}", 12 | "environment": [], 13 | "console": "integratedTerminal" 14 | }, 15 | { 16 | "name": "(gdb) Launch", 17 | "type": "cppdbg", 18 | "request": "launch", 19 | "program": "${workspaceFolder}/build/${command:cmake.buildType}/vulkan-ray-tracing", 20 | "args": [], 21 | "stopAtEntry": false, 22 | "cwd": "${workspaceFolder}", 23 | "environment": [], 24 | "externalConsole": false, 25 | "MIMode": "gdb", 26 | "setupCommands": [ 27 | { 28 | "description": "Enable pretty-printing for gdb", 29 | "text": "-enable-pretty-printing", 30 | "ignoreFailures": true 31 | }, 32 | { 33 | "description": "Set Disassembly Flavor to Intel", 34 | "text": "-gdb-set disassembly-flavor intel", 35 | "ignoreFailures": true 36 | } 37 | ] 38 | }, 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | set (TARGET_NAME vulkan-ray-tracing) 3 | project(${TARGET_NAME}) 4 | 5 | set(PROGRAM_SOURCE 6 | src/acceleration_structure.cpp 7 | src/acceleration_structure.h 8 | src/demo.cpp 9 | src/demo.h 10 | src/gpu_mesh.h 11 | src/lib.cpp 12 | src/lib.h 13 | src/main.cpp 14 | src/vk.cpp 15 | src/vk.h 16 | src/kernels/copy_to_swapchain.cpp 17 | src/kernels/copy_to_swapchain.h 18 | src/kernels/draw_mesh.cpp 19 | src/kernels/draw_mesh.h 20 | src/kernels/raytrace_scene.cpp 21 | src/kernels/raytrace_scene.h 22 | ) 23 | set(SHADER_ENTRY_POINT_FILES 24 | src/shaders/copy_to_swapchain.comp.glsl 25 | src/shaders/raster_mesh.frag.glsl 26 | src/shaders/raster_mesh.vert.glsl 27 | src/shaders/rt_mesh.rchit.glsl 28 | src/shaders/rt_mesh.rgen.glsl 29 | src/shaders/rt_mesh.rmiss.glsl 30 | ) 31 | set(SHADER_OTHER_FILES 32 | src/shaders/common.glsl 33 | src/shaders/rt_utils.glsl 34 | ) 35 | list(APPEND SHADER_SOURCE ${SHADER_ENTRY_POINT_FILES} ${SHADER_OTHER_FILES}) 36 | 37 | set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) 38 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 39 | source_group(TREE "${CMAKE_SOURCE_DIR}/src" FILES ${PROGRAM_SOURCE}) 40 | source_group(TREE "${CMAKE_SOURCE_DIR}/src/shaders" PREFIX shaders FILES ${SHADER_SOURCE}) 41 | 42 | if (MSVC) 43 | add_compile_definitions(_CRT_SECURE_NO_WARNINGS) 44 | add_compile_options(/MP /W3) 45 | # Match MSVC Release 46 | add_compile_options($<$:/Zi>) 47 | add_compile_options($<$:/GL>) 48 | add_compile_options($<$:/Gy>) 49 | add_link_options($<$:/DEBUG>) 50 | add_link_options($<$:/OPT:REF>) 51 | add_link_options($<$:/OPT:ICF>) 52 | add_link_options($<$:/LTCG>) 53 | else() 54 | add_compile_options(-Wall -Wextra) 55 | endif() 56 | 57 | add_executable(${TARGET_NAME} ${PROGRAM_SOURCE} ${SHADER_SOURCE}) 58 | target_compile_features(${TARGET_NAME} PRIVATE cxx_std_20) 59 | target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_SOURCE_DIR}/src") 60 | add_subdirectory(third-party) 61 | target_link_libraries(${TARGET_NAME} third-party) 62 | 63 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 64 | target_compile_options(${TARGET_NAME} PRIVATE 65 | -Wno-unused-parameter 66 | -Wno-missing-field-initializers 67 | ) 68 | endif() 69 | 70 | set_target_properties(${TARGET_NAME} PROPERTIES 71 | VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" 72 | VS_DPI_AWARE "PerMonitor" 73 | ) 74 | set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${TARGET_NAME}) 75 | 76 | function(add_shader SHADER) 77 | get_filename_component(BASE_NAME ${SHADER} NAME_WLE) 78 | set(SPV_FILE "${CMAKE_SOURCE_DIR}/data/spirv/${BASE_NAME}.spv") 79 | set(SHADER_FILE "${CMAKE_SOURCE_DIR}/${SHADER}") 80 | add_custom_command( 81 | OUTPUT "${SPV_FILE}" 82 | MAIN_DEPENDENCY "${SHADER_FILE}" 83 | DEPENDS "${SHADER_OTHER_FILES}" 84 | COMMAND "$ENV{VULKAN_SDK}/bin/glslangValidator" "${SHADER_FILE}" -V --target-env vulkan1.2 -o "${SPV_FILE}" 85 | COMMAND "$ENV{VULKAN_SDK}/bin/spirv-opt" ${SPV_FILE} -O --strip-debug -o "${SPV_FILE}" 86 | ) 87 | endfunction() 88 | 89 | foreach(SHADER ${SHADER_ENTRY_POINT_FILES}) 90 | add_shader(${SHADER}) 91 | endforeach() 92 | -------------------------------------------------------------------------------- /CMakePresets.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "configurePresets": [ 4 | { 5 | "name": "vs", 6 | "binaryDir": "${sourceDir}/build", 7 | "installDir": "${sourceDir}/install", 8 | "generator": "Visual Studio 17 2022", 9 | "architecture": { 10 | "value": "x64", 11 | "strategy": "external" 12 | }, 13 | "condition": { 14 | "type": "equals", 15 | "lhs": "${hostSystemName}", 16 | "rhs": "Windows" 17 | } 18 | }, 19 | { 20 | "name": "ninja", 21 | "binaryDir": "${sourceDir}/build", 22 | "installDir": "${sourceDir}/install", 23 | "generator": "Ninja Multi-Config", 24 | "condition": { 25 | "type": "equals", 26 | "lhs": "${hostSystemName}", 27 | "rhs": "Linux" 28 | } 29 | } 30 | ], 31 | "buildPresets": [ 32 | { 33 | "name": "vs-debug", 34 | "displayName": "Debug", 35 | "configurePreset": "vs", 36 | "configuration": "Debug" 37 | }, 38 | { 39 | "name": "vs-release", 40 | "displayName": "Release", 41 | "configurePreset": "vs", 42 | "configuration": "Release" 43 | }, 44 | { 45 | "name": "ninja-debug", 46 | "displayName": "Debug", 47 | "configurePreset": "ninja", 48 | "configuration": "Debug" 49 | }, 50 | { 51 | "name": "ninja-release", 52 | "displayName": "Release", 53 | "configurePreset": "ninja", 54 | "configuration": "Release" 55 | } 56 | ] 57 | } 58 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017-2022 Artem Kharytoniuk 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 | # 🌋 vulkan-ray-tracing 🖖 2 | 3 | This is a basic Vulkan ray tracing demo based on __VK_KHR_ray_tracing_pipeline__ + __VK_KHR_acceleration_structure__ extensions. It shows how to setup a ray tracing pipeline and also provides an example of how to use ray differentials for texture filtering. 4 | 5 | Prerequisites: 6 | * CMake 7 | * Vulkan SDK (VULKAN_SDK environment variable should be set) 8 | 9 | Build steps: 10 | 1. `cmake -S . -B build` 11 | 2. `cmake --build build` 12 | 13 | Supported platforms: Windows, Linux. 14 | 15 | In order to enable Vulkan validation layers specify ```--validation-layers``` command line argument. 16 | 17 | ![demo](https://user-images.githubusercontent.com/4964024/48605463-26722a00-e97d-11e8-9548-65de42d50c21.png) 18 | -------------------------------------------------------------------------------- /data/model/credits.txt: -------------------------------------------------------------------------------- 1 | Digimon 3D Craniummon https://sketchfab.com/models/36d1022f74fd40ba8d98972c71174b8a 2 | by Gigano Regulus https://sketchfab.com/Gigano_Regulus 3 | CC BY 4.0 License https://creativecommons.org/licenses/by/4.0/ 4 | -------------------------------------------------------------------------------- /data/model/diffuse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kennyalive/vulkan-ray-tracing/824a61d18dfe405cf95d39f232e5fdc7dc0b2808/data/model/diffuse.jpg -------------------------------------------------------------------------------- /src/acceleration_structure.cpp: -------------------------------------------------------------------------------- 1 | #include "acceleration_structure.h" 2 | #include "gpu_mesh.h" 3 | #include "lib.h" 4 | 5 | static BLAS_Info create_BLAS(const GPU_Mesh& mesh, uint32_t scratch_alignment) { 6 | VkAccelerationStructureGeometryKHR geometry { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR }; 7 | geometry.geometryType = VK_GEOMETRY_TYPE_TRIANGLES_KHR; 8 | 9 | auto& trianglesData = geometry.geometry.triangles; 10 | trianglesData = VkAccelerationStructureGeometryTrianglesDataKHR{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_TRIANGLES_DATA_KHR }; 11 | trianglesData.vertexFormat = VK_FORMAT_R32G32B32_SFLOAT; 12 | trianglesData.vertexData.deviceAddress = mesh.vertex_buffer.device_address; 13 | trianglesData.vertexStride = sizeof(Vertex); 14 | trianglesData.maxVertex = mesh.vertex_count - 1; 15 | trianglesData.indexType = VK_INDEX_TYPE_UINT32; 16 | trianglesData.indexData.deviceAddress = mesh.index_buffer.device_address; 17 | 18 | VkAccelerationStructureBuildGeometryInfoKHR build_info{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR }; 19 | build_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR; 20 | build_info.flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR; 21 | build_info.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR; 22 | build_info.geometryCount = 1; 23 | build_info.pGeometries = &geometry; 24 | 25 | VkAccelerationStructureBuildSizesInfoKHR build_sizes{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR }; 26 | uint32_t triangle_count = mesh.index_count / 3; 27 | vkGetAccelerationStructureBuildSizesKHR(vk.device, VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR, &build_info, &triangle_count, &build_sizes); 28 | 29 | // Create buffer to hold acceleration structure data. 30 | BLAS_Info blas; 31 | blas.buffer = vk_create_buffer(build_sizes.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, nullptr, "blas_buffer"); 32 | 33 | // Create acceleration structure. 34 | VkAccelerationStructureCreateInfoKHR create_info{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR }; 35 | create_info.buffer = blas.buffer.handle; 36 | create_info.offset = 0; 37 | create_info.size = build_sizes.accelerationStructureSize; 38 | create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_BOTTOM_LEVEL_KHR; 39 | VK_CHECK(vkCreateAccelerationStructureKHR(vk.device, &create_info, nullptr, &blas.acceleration_structure)); 40 | vk_set_debug_name(blas.acceleration_structure, "blas"); 41 | 42 | // Get acceleration structure address. 43 | VkAccelerationStructureDeviceAddressInfoKHR device_address_info{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_DEVICE_ADDRESS_INFO_KHR }; 44 | device_address_info.accelerationStructure = blas.acceleration_structure; 45 | blas.device_address = vkGetAccelerationStructureDeviceAddressKHR(vk.device, &device_address_info); 46 | 47 | // Build acceleration structure. 48 | Vk_Buffer scratch_buffer = vk_create_buffer_with_alignment(build_sizes.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, scratch_alignment); 49 | build_info.dstAccelerationStructure = blas.acceleration_structure; 50 | build_info.scratchData.deviceAddress = scratch_buffer.device_address; 51 | 52 | VkAccelerationStructureBuildRangeInfoKHR build_range_info{}; 53 | build_range_info.primitiveCount = mesh.index_count / 3; 54 | const VkAccelerationStructureBuildRangeInfoKHR* p_build_range_infos[1] = { &build_range_info }; 55 | 56 | vk_execute(vk.command_pools[0], vk.queue, [&build_info, p_build_range_infos](VkCommandBuffer command_buffer) 57 | { 58 | vkCmdBuildAccelerationStructuresKHR(command_buffer, 1, &build_info, p_build_range_infos); 59 | }); 60 | scratch_buffer.destroy(); 61 | return blas; 62 | } 63 | 64 | static TLAS_Info create_TLAS(uint32_t instance_count, VkDeviceAddress instances_device_address, uint32_t scratch_alignment) { 65 | VkAccelerationStructureGeometryKHR geometry{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR }; 66 | geometry.geometryType = VK_GEOMETRY_TYPE_INSTANCES_KHR; 67 | geometry.geometry.instances = VkAccelerationStructureGeometryInstancesDataKHR{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR }; 68 | geometry.geometry.instances.arrayOfPointers = VK_FALSE; 69 | geometry.geometry.instances.data.deviceAddress = instances_device_address; 70 | 71 | VkAccelerationStructureBuildGeometryInfoKHR build_info{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR }; 72 | build_info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR; 73 | build_info.flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR; 74 | build_info.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR; 75 | build_info.geometryCount = 1; 76 | build_info.pGeometries = &geometry; 77 | 78 | VkAccelerationStructureBuildSizesInfoKHR build_sizes{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_SIZES_INFO_KHR }; 79 | vkGetAccelerationStructureBuildSizesKHR(vk.device, VK_ACCELERATION_STRUCTURE_BUILD_TYPE_DEVICE_KHR, &build_info, &instance_count, &build_sizes); 80 | 81 | // Create buffer to hold acceleration structure data. 82 | TLAS_Info tlas; 83 | tlas.buffer = vk_create_buffer(build_sizes.accelerationStructureSize, VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_STORAGE_BIT_KHR, nullptr, "tlas_buffer"); 84 | 85 | // Create acceleration structure. 86 | VkAccelerationStructureCreateInfoKHR create_info{ VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_CREATE_INFO_KHR }; 87 | create_info.buffer = tlas.buffer.handle; 88 | create_info.offset = 0; 89 | create_info.size = build_sizes.accelerationStructureSize; 90 | create_info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR; 91 | VK_CHECK(vkCreateAccelerationStructureKHR(vk.device, &create_info, nullptr, &tlas.aceleration_structure)); 92 | vk_set_debug_name(tlas.aceleration_structure, "tlas"); 93 | 94 | // Build acceleration structure. 95 | tlas.scratch_buffer = vk_create_buffer_with_alignment(build_sizes.buildScratchSize, VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, scratch_alignment); 96 | build_info.dstAccelerationStructure = tlas.aceleration_structure; 97 | build_info.scratchData.deviceAddress = tlas.scratch_buffer.device_address; 98 | 99 | VkAccelerationStructureBuildRangeInfoKHR build_range_info{}; 100 | build_range_info.primitiveCount = instance_count; 101 | const VkAccelerationStructureBuildRangeInfoKHR* p_build_range_infos[1] = { &build_range_info }; 102 | 103 | vk_execute(vk.command_pools[0], vk.queue, [&build_info, p_build_range_infos](VkCommandBuffer command_buffer) 104 | { 105 | vkCmdBuildAccelerationStructuresKHR(command_buffer, 1, &build_info, p_build_range_infos); 106 | }); 107 | return tlas; 108 | } 109 | 110 | Vk_Intersection_Accelerator create_intersection_accelerator(const std::vector& gpu_meshes) { 111 | Timestamp t; 112 | Vk_Intersection_Accelerator accelerator; 113 | 114 | auto accel_properties = VkPhysicalDeviceAccelerationStructurePropertiesKHR{ 115 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ACCELERATION_STRUCTURE_PROPERTIES_KHR 116 | }; 117 | VkPhysicalDeviceProperties2 physical_device_properties{ 118 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, 119 | &accel_properties 120 | }; 121 | vkGetPhysicalDeviceProperties2(vk.physical_device, &physical_device_properties); 122 | const uint32_t scratch_alignment = accel_properties.minAccelerationStructureScratchOffsetAlignment; 123 | 124 | // Create BLASes. 125 | accelerator.bottom_level_accels.resize(gpu_meshes.size()); 126 | for (int i = 0; i < (int)gpu_meshes.size(); i++) { 127 | accelerator.bottom_level_accels[i] = create_BLAS(gpu_meshes[i], scratch_alignment); 128 | } 129 | // Create instance buffer. 130 | { 131 | std::vector instances(gpu_meshes.size()); 132 | for (int i = 0; i < (int)instances.size(); i++) { 133 | memcpy(&instances[i].transform.matrix[0][0], &Matrix3x4::identity.a[0][0], 12 * sizeof(float)); 134 | instances[i].instanceCustomIndex = i; 135 | instances[i].mask = 0xff; 136 | instances[i].instanceShaderBindingTableRecordOffset = 0; 137 | instances[i].flags = VK_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE_BIT_KHR; 138 | instances[i].accelerationStructureReference = accelerator.bottom_level_accels[i].device_address; 139 | } 140 | VkDeviceSize instance_buffer_size = instances.size() * sizeof(VkAccelerationStructureInstanceKHR); 141 | accelerator.instance_buffer = vk_create_mapped_buffer(instance_buffer_size, 142 | VK_BUFFER_USAGE_ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_BIT_KHR, 143 | &(void*&)accelerator.mapped_instance_buffer, "instance_buffer"); 144 | } 145 | // Create TLAS. 146 | accelerator.top_level_accel = create_TLAS((uint32_t)gpu_meshes.size(), accelerator.instance_buffer.device_address, scratch_alignment); 147 | 148 | printf("\nAcceleration structures build time = %lld microseconds\n", elapsed_nanoseconds(t) / 1000); 149 | return accelerator; 150 | } 151 | 152 | void Vk_Intersection_Accelerator::rebuild_top_level_accel(VkCommandBuffer command_buffer) { 153 | VkAccelerationStructureGeometryKHR geometry { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_KHR }; 154 | geometry.geometryType = VK_GEOMETRY_TYPE_INSTANCES_KHR; 155 | geometry.geometry.instances = VkAccelerationStructureGeometryInstancesDataKHR { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_GEOMETRY_INSTANCES_DATA_KHR }; 156 | geometry.geometry.instances.arrayOfPointers = VK_FALSE; 157 | geometry.geometry.instances.data.deviceAddress = instance_buffer.device_address; 158 | 159 | VkAccelerationStructureBuildGeometryInfoKHR build_info { VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR }; 160 | build_info.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR; 161 | build_info.flags = VK_BUILD_ACCELERATION_STRUCTURE_PREFER_FAST_TRACE_BIT_KHR; 162 | build_info.mode = VK_BUILD_ACCELERATION_STRUCTURE_MODE_BUILD_KHR; 163 | build_info.dstAccelerationStructure = top_level_accel.aceleration_structure; 164 | build_info.geometryCount = 1; 165 | build_info.pGeometries = &geometry; 166 | build_info.scratchData.deviceAddress = top_level_accel.scratch_buffer.device_address; 167 | 168 | VkAccelerationStructureBuildRangeInfoKHR build_range_info{}; 169 | build_range_info.primitiveCount = (uint32_t)bottom_level_accels.size(); 170 | const VkAccelerationStructureBuildRangeInfoKHR* p_build_range_info[1] = { &build_range_info }; 171 | 172 | vkCmdBuildAccelerationStructuresKHR(command_buffer, 1, &build_info, p_build_range_info); 173 | 174 | VkMemoryBarrier2 barrier{ VK_STRUCTURE_TYPE_MEMORY_BARRIER_2 }; 175 | // Source stages/accesses correspond to AS build operation 176 | // (reads/writes for AS backing buffer and reads for input geometry buffers) 177 | barrier.srcStageMask = VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR; 178 | 179 | barrier.srcAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR | VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR 180 | | VK_ACCESS_SHADER_READ_BIT; 181 | // Destination stage accesses corresponds to: 182 | // - ray tracing shader (RAY_TRACING_SHADER + AS_READ|SHADER_READ) 183 | // - AS rebuild on each frame (AS_BUILD+AS_WRITE|AS_READ|SHADER_READ) 184 | barrier.dstStageMask = VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR 185 | | VK_PIPELINE_STAGE_ACCELERATION_STRUCTURE_BUILD_BIT_KHR; 186 | 187 | barrier.dstAccessMask = VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR | VK_ACCESS_SHADER_READ_BIT 188 | | VK_ACCESS_ACCELERATION_STRUCTURE_WRITE_BIT_KHR; 189 | 190 | VkDependencyInfo dep_info{ VK_STRUCTURE_TYPE_DEPENDENCY_INFO }; 191 | dep_info.memoryBarrierCount = 1; 192 | dep_info.pMemoryBarriers = &barrier; 193 | vkCmdPipelineBarrier2(command_buffer, &dep_info); 194 | } 195 | 196 | void Vk_Intersection_Accelerator::destroy() { 197 | for (auto& blas : bottom_level_accels) { 198 | vkDestroyAccelerationStructureKHR(vk.device, blas.acceleration_structure, nullptr); 199 | blas.buffer.destroy(); 200 | } 201 | vkDestroyAccelerationStructureKHR(vk.device, top_level_accel.aceleration_structure, nullptr); 202 | top_level_accel.buffer.destroy(); 203 | top_level_accel.scratch_buffer.destroy(); 204 | instance_buffer.destroy(); 205 | *this = Vk_Intersection_Accelerator{}; 206 | } 207 | -------------------------------------------------------------------------------- /src/acceleration_structure.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vk.h" 4 | 5 | struct GPU_Mesh; 6 | 7 | struct BLAS_Info { 8 | VkAccelerationStructureKHR acceleration_structure = VK_NULL_HANDLE; 9 | Vk_Buffer buffer; 10 | VkDeviceAddress device_address = 0; 11 | }; 12 | 13 | struct TLAS_Info { 14 | VkAccelerationStructureKHR aceleration_structure = VK_NULL_HANDLE; 15 | Vk_Buffer buffer; 16 | Vk_Buffer scratch_buffer; 17 | }; 18 | 19 | struct Vk_Intersection_Accelerator { 20 | std::vector bottom_level_accels; 21 | TLAS_Info top_level_accel; 22 | Vk_Buffer instance_buffer; 23 | VkAccelerationStructureInstanceKHR* mapped_instance_buffer = nullptr; 24 | 25 | void rebuild_top_level_accel(VkCommandBuffer command_buffer); 26 | void destroy(); 27 | }; 28 | 29 | Vk_Intersection_Accelerator create_intersection_accelerator(const std::vector& gpu_meshes); 30 | -------------------------------------------------------------------------------- /src/demo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "gpu_mesh.h" 4 | #include "lib.h" 5 | 6 | #include "kernels/copy_to_swapchain.h" 7 | #include "kernels/draw_mesh.h" 8 | #include "kernels/raytrace_scene.h" 9 | 10 | #include 11 | 12 | struct GLFWwindow; 13 | 14 | class Vk_Demo { 15 | public: 16 | void initialize(GLFWwindow* glfw_window); 17 | void shutdown(); 18 | 19 | void release_resolution_dependent_resources(); 20 | void restore_resolution_dependent_resources(); 21 | bool vsync_enabled() const { return vsync; } 22 | void run_frame(); 23 | 24 | private: 25 | void draw_frame(); 26 | void render_frame_rasterization(); 27 | void render_frame_ray_tracing(); 28 | void copy_output_image_to_swapchain(); 29 | void do_imgui(); 30 | 31 | private: 32 | using Clock = std::chrono::high_resolution_clock; 33 | using Time = std::chrono::time_point; 34 | 35 | bool show_ui = true; 36 | bool vsync = true; 37 | bool animate = false; 38 | bool ray_tracing_active = true; 39 | bool show_texture_lod = false; 40 | bool spp4 = false; 41 | 42 | Time last_frame_time; 43 | double sim_time; 44 | Vector3 camera_pos = Vector3(0, 0.5, 3.0); 45 | 46 | Vk_GPU_Time_Keeper time_keeper; 47 | struct { 48 | Vk_GPU_Time_Interval* frame; 49 | Vk_GPU_Time_Interval* draw; 50 | Vk_GPU_Time_Interval* compute_copy; 51 | } gpu_times; 52 | 53 | Vk_Image depth_buffer_image; 54 | Vk_Image output_image; 55 | GPU_Mesh gpu_mesh; 56 | Vk_Image texture; 57 | VkSampler sampler; 58 | Copy_To_Swapchain copy_to_swapchain; 59 | Draw_Mesh draw_mesh; 60 | Raytrace_Scene raytrace_scene; 61 | }; 62 | -------------------------------------------------------------------------------- /src/gpu_mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vk.h" 4 | 5 | struct GPU_Mesh { 6 | Vk_Buffer vertex_buffer; 7 | Vk_Buffer index_buffer; 8 | uint32_t vertex_count = 0; 9 | uint32_t index_count = 0; 10 | 11 | void destroy() { 12 | vertex_buffer.destroy(); 13 | index_buffer.destroy(); 14 | vertex_count = 0; 15 | index_count = 0; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /src/kernels/copy_to_swapchain.cpp: -------------------------------------------------------------------------------- 1 | #include "copy_to_swapchain.h" 2 | #include "lib.h" 3 | 4 | void Copy_To_Swapchain::create() 5 | { 6 | set_layout = Vk_Descriptor_Set_Layout() 7 | .sampler(0, VK_SHADER_STAGE_COMPUTE_BIT) 8 | .sampled_image(1, VK_SHADER_STAGE_COMPUTE_BIT) 9 | .storage_image(2, VK_SHADER_STAGE_COMPUTE_BIT) 10 | .create("copy_to_swapchain_set_layout"); 11 | 12 | pipeline_layout = vk_create_pipeline_layout( 13 | { set_layout }, 14 | { VkPushConstantRange{VK_SHADER_STAGE_COMPUTE_BIT, 0, 8 /*uint32 width + uint32 height*/} }, 15 | "copy_to_swapchain_pipeline_layout"); 16 | 17 | Vk_Shader_Module compute_shader(get_resource_path("spirv/copy_to_swapchain.comp.spv")); 18 | 19 | pipeline = vk_create_compute_pipeline(compute_shader.handle, pipeline_layout, "copy_to_swapchain_pipeline"); 20 | 21 | // point sampler 22 | { 23 | VkSamplerCreateInfo create_info { VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO }; 24 | VK_CHECK(vkCreateSampler(vk.device, &create_info, nullptr, &point_sampler)); 25 | vk_set_debug_name(point_sampler, "point_sampler"); 26 | } 27 | } 28 | 29 | void Copy_To_Swapchain::destroy() { 30 | descriptor_buffer.destroy(); 31 | vkDestroyDescriptorSetLayout(vk.device, set_layout, nullptr); 32 | vkDestroyPipelineLayout(vk.device, pipeline_layout, nullptr); 33 | vkDestroyPipeline(vk.device, pipeline, nullptr); 34 | vkDestroySampler(vk.device, point_sampler, nullptr); 35 | } 36 | 37 | void Copy_To_Swapchain::update_resolution_dependent_descriptors(VkImageView output_image_view) { 38 | VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_properties = { 39 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT }; 40 | VkPhysicalDeviceProperties2 physical_device_properties{ 41 | VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 }; 42 | physical_device_properties.pNext = &descriptor_buffer_properties; 43 | vkGetPhysicalDeviceProperties2(vk.physical_device, &physical_device_properties); 44 | 45 | layout_size_in_bytes = 0; 46 | vkGetDescriptorSetLayoutSizeEXT(vk.device, set_layout, &layout_size_in_bytes); 47 | std::vector descriptor_data(layout_size_in_bytes * vk.swapchain_info.images.size()); 48 | 49 | for (size_t i = 0; i < vk.swapchain_info.images.size(); i++) { 50 | // Descriptor 0 (sampler) 51 | { 52 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 53 | descriptor_info.type = VK_DESCRIPTOR_TYPE_SAMPLER; 54 | descriptor_info.data.pSampler = &point_sampler; 55 | 56 | VkDeviceSize offset; 57 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, set_layout, 0, &offset); 58 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.samplerDescriptorSize, 59 | descriptor_data.data() + i * layout_size_in_bytes + offset); 60 | } 61 | // Descriptor 1 (sampled image) 62 | { 63 | VkDescriptorImageInfo image_info; 64 | image_info.imageView = output_image_view; 65 | image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL; 66 | 67 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 68 | descriptor_info.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; 69 | descriptor_info.data.pSampledImage = &image_info; 70 | 71 | VkDeviceSize offset; 72 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, set_layout, 1, &offset); 73 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.sampledImageDescriptorSize, 74 | descriptor_data.data() + i * layout_size_in_bytes + offset); 75 | } 76 | // Descriptor 2 (storage image) 77 | { 78 | VkDescriptorImageInfo image_info; 79 | image_info.imageView = vk.swapchain_info.image_views[i]; 80 | image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL; 81 | 82 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 83 | descriptor_info.type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE; 84 | descriptor_info.data.pStorageImage = &image_info; 85 | 86 | VkDeviceSize offset; 87 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, set_layout, 2, &offset); 88 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.storageImageDescriptorSize, 89 | descriptor_data.data() + i * layout_size_in_bytes + offset); 90 | } 91 | } 92 | 93 | descriptor_buffer.destroy(); 94 | 95 | VkBufferUsageFlags usage = 96 | VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | 97 | VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT | 98 | VK_BUFFER_USAGE_TRANSFER_DST_BIT; 99 | 100 | descriptor_buffer = vk_create_buffer_with_alignment( 101 | layout_size_in_bytes * vk.swapchain_info.images.size(), 102 | usage, 103 | (uint32_t)descriptor_buffer_properties.descriptorBufferOffsetAlignment, 104 | descriptor_data.data(), "copy_to_swapchain_descriptor_buffer"); 105 | } 106 | 107 | void Copy_To_Swapchain::dispatch() { 108 | const uint32_t group_size_x = 32; // according to shader 109 | const uint32_t group_size_y = 32; 110 | 111 | uint32_t group_count_x = (vk.surface_size.width + group_size_x - 1) / group_size_x; 112 | uint32_t group_count_y = (vk.surface_size.height + group_size_y - 1) / group_size_y; 113 | 114 | uint32_t push_constants[] = { vk.surface_size.width, vk.surface_size.height }; 115 | 116 | VkDescriptorBufferBindingInfoEXT descriptor_buffer_binding_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT }; 117 | descriptor_buffer_binding_info.address = descriptor_buffer.device_address; 118 | descriptor_buffer_binding_info.usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT; 119 | vkCmdBindDescriptorBuffersEXT(vk.command_buffer, 1, &descriptor_buffer_binding_info); 120 | 121 | const uint32_t buffer_index = 0; 122 | const VkDeviceSize set_offset = layout_size_in_bytes * vk.swapchain_image_index; 123 | vkCmdSetDescriptorBufferOffsetsEXT(vk.command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline_layout, 0, 1, &buffer_index, &set_offset); 124 | 125 | vkCmdPushConstants(vk.command_buffer, pipeline_layout, VK_SHADER_STAGE_COMPUTE_BIT, 0, sizeof(push_constants), push_constants); 126 | vkCmdBindPipeline(vk.command_buffer, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); 127 | vkCmdDispatch(vk.command_buffer, group_count_x, group_count_y, 1); 128 | } 129 | -------------------------------------------------------------------------------- /src/kernels/copy_to_swapchain.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vk.h" 4 | 5 | struct Copy_To_Swapchain { 6 | VkDescriptorSetLayout set_layout; 7 | VkPipelineLayout pipeline_layout; 8 | VkPipeline pipeline; 9 | VkSampler point_sampler; 10 | Vk_Buffer descriptor_buffer; // contains descriptors per swapchain image 11 | 12 | VkDeviceSize layout_size_in_bytes = 0; 13 | 14 | void create(); 15 | void destroy(); 16 | void update_resolution_dependent_descriptors(VkImageView output_image_view); 17 | void dispatch(); 18 | }; 19 | -------------------------------------------------------------------------------- /src/kernels/draw_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include "draw_mesh.h" 2 | #include "gpu_mesh.h" 3 | #include "lib.h" 4 | 5 | void Draw_Mesh::create(VkFormat color_attachment_format, VkFormat depth_attachment_format, VkImageView texture_view, VkSampler sampler) { 6 | uniform_buffer = vk_create_mapped_buffer(static_cast(sizeof(Matrix4x4)), 7 | VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, &mapped_uniform_buffer, "raster_uniform_buffer"); 8 | 9 | descriptor_set_layout = Vk_Descriptor_Set_Layout() 10 | .uniform_buffer (0, VK_SHADER_STAGE_VERTEX_BIT) 11 | .sampled_image (1, VK_SHADER_STAGE_FRAGMENT_BIT) 12 | .sampler (2, VK_SHADER_STAGE_FRAGMENT_BIT) 13 | .create ("raster_set_layout"); 14 | 15 | pipeline_layout = vk_create_pipeline_layout( 16 | { descriptor_set_layout }, 17 | { VkPushConstantRange{VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4} }, 18 | "raster_pipeline_layout"); 19 | 20 | // pipeline 21 | { 22 | Vk_Shader_Module vertex_shader(get_resource_path("spirv/raster_mesh.vert.spv")); 23 | Vk_Shader_Module fragment_shader(get_resource_path("spirv/raster_mesh.frag.spv")); 24 | 25 | Vk_Graphics_Pipeline_State state = get_default_graphics_pipeline_state(); 26 | 27 | // VkVertexInputBindingDescription 28 | state.vertex_bindings[0].binding = 0; 29 | state.vertex_bindings[0].stride = sizeof(Vertex); 30 | state.vertex_bindings[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX; 31 | state.vertex_binding_count = 1; 32 | 33 | // VkVertexInputAttributeDescription 34 | state.vertex_attributes[0].location = 0; // vertex 35 | state.vertex_attributes[0].binding = 0; 36 | state.vertex_attributes[0].format = VK_FORMAT_R32G32B32_SFLOAT; 37 | state.vertex_attributes[0].offset = 0; 38 | 39 | state.vertex_attributes[1].location = 1; // uv 40 | state.vertex_attributes[1].binding = 0; 41 | state.vertex_attributes[1].format = VK_FORMAT_R32G32_SFLOAT; 42 | state.vertex_attributes[1].offset = 12; 43 | 44 | state.vertex_attribute_count = 2; 45 | 46 | state.color_attachment_formats[0] = color_attachment_format; 47 | state.color_attachment_count = 1; 48 | state.depth_attachment_format = depth_attachment_format; 49 | 50 | pipeline = vk_create_graphics_pipeline(state, vertex_shader.handle, fragment_shader.handle, 51 | pipeline_layout, "draw_mesh_pipeline"); 52 | } 53 | 54 | // Descriptor buffer. 55 | { 56 | VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_properties{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_BUFFER_PROPERTIES_EXT }; 57 | VkPhysicalDeviceProperties2 physical_device_properties{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2 }; 58 | physical_device_properties.pNext = &descriptor_buffer_properties; 59 | vkGetPhysicalDeviceProperties2(vk.physical_device, &physical_device_properties); 60 | 61 | VkDeviceSize layout_size_in_bytes = 0; 62 | vkGetDescriptorSetLayoutSizeEXT(vk.device, descriptor_set_layout, &layout_size_in_bytes); 63 | std::vector descriptor_data(layout_size_in_bytes); 64 | 65 | // Get descriptor 0 (uniform buffer) 66 | { 67 | VkDescriptorAddressInfoEXT address_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_ADDRESS_INFO_EXT }; 68 | address_info.address = uniform_buffer.device_address; 69 | address_info.range = sizeof(Matrix4x4); 70 | 71 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 72 | descriptor_info.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; 73 | descriptor_info.data.pUniformBuffer = &address_info; 74 | 75 | VkDeviceSize offset; 76 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, descriptor_set_layout, 0, &offset); 77 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.uniformBufferDescriptorSize, 78 | descriptor_data.data() + offset); 79 | } 80 | // Get descriptor 1 (sampled image) 81 | { 82 | VkDescriptorImageInfo image_info; 83 | image_info.imageView = texture_view; 84 | image_info.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL; 85 | 86 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 87 | descriptor_info.type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE; 88 | descriptor_info.data.pSampledImage = &image_info; 89 | 90 | VkDeviceSize offset; 91 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, descriptor_set_layout, 1, &offset); 92 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.sampledImageDescriptorSize, 93 | descriptor_data.data() + offset); 94 | } 95 | // Get descriptor 2 (sampler) 96 | { 97 | VkDescriptorGetInfoEXT descriptor_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_GET_INFO_EXT }; 98 | descriptor_info.type = VK_DESCRIPTOR_TYPE_SAMPLER; 99 | descriptor_info.data.pSampler = &sampler; 100 | 101 | VkDeviceSize offset; 102 | vkGetDescriptorSetLayoutBindingOffsetEXT(vk.device, descriptor_set_layout, 2, &offset); 103 | vkGetDescriptorEXT(vk.device, &descriptor_info, descriptor_buffer_properties.samplerDescriptorSize, 104 | descriptor_data.data() + offset); 105 | } 106 | VkBufferUsageFlags usage = 107 | VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | 108 | VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT | 109 | VK_BUFFER_USAGE_TRANSFER_DST_BIT; 110 | descriptor_buffer = vk_create_buffer_with_alignment(layout_size_in_bytes, usage, 111 | (uint32_t)descriptor_buffer_properties.descriptorBufferOffsetAlignment, 112 | descriptor_data.data(), "draw_mesh_descriptor_buffer"); 113 | } 114 | } 115 | 116 | void Draw_Mesh::destroy() { 117 | descriptor_buffer.destroy(); 118 | uniform_buffer.destroy(); 119 | vkDestroyDescriptorSetLayout(vk.device, descriptor_set_layout, nullptr); 120 | vkDestroyPipelineLayout(vk.device, pipeline_layout, nullptr); 121 | vkDestroyPipeline(vk.device, pipeline, nullptr); 122 | *this = Draw_Mesh{}; 123 | } 124 | 125 | void Draw_Mesh::update(const Matrix3x4& object_to_camera_transform) { 126 | float aspect_ratio = (float)vk.surface_size.width / (float)vk.surface_size.height; 127 | Matrix4x4 projection_transform = perspective_transform_opengl_z01(radians(45.0f), aspect_ratio, 0.1f, 50.0f); 128 | Matrix4x4 transform = projection_transform * object_to_camera_transform; 129 | memcpy(mapped_uniform_buffer, &transform, sizeof(transform)); 130 | } 131 | 132 | void Draw_Mesh::dispatch(const GPU_Mesh& mesh, bool show_texture_lod) { 133 | const VkDeviceSize zero_offset = 0; 134 | vkCmdBindVertexBuffers(vk.command_buffer, 0, 1, &mesh.vertex_buffer.handle, &zero_offset); 135 | vkCmdBindIndexBuffer(vk.command_buffer, mesh.index_buffer.handle, 0, VK_INDEX_TYPE_UINT32); 136 | 137 | VkDescriptorBufferBindingInfoEXT descriptor_buffer_binding_info{ VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT }; 138 | descriptor_buffer_binding_info.address = descriptor_buffer.device_address; 139 | descriptor_buffer_binding_info.usage = VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT | VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT; 140 | vkCmdBindDescriptorBuffersEXT(vk.command_buffer, 1, &descriptor_buffer_binding_info); 141 | 142 | const uint32_t buffer_index = 0; 143 | const VkDeviceSize set_offset = 0; 144 | vkCmdSetDescriptorBufferOffsetsEXT(vk.command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline_layout, 0, 1, &buffer_index, &set_offset); 145 | 146 | uint32_t show_texture_lod_uint = show_texture_lod; 147 | vkCmdPushConstants(vk.command_buffer, pipeline_layout, VK_SHADER_STAGE_FRAGMENT_BIT, 0, 4, &show_texture_lod_uint); 148 | vkCmdBindPipeline(vk.command_buffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline); 149 | vkCmdDrawIndexed(vk.command_buffer, mesh.index_count, 1, 0, 0, 0); 150 | } 151 | -------------------------------------------------------------------------------- /src/kernels/draw_mesh.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "vk.h" 4 | 5 | struct Matrix3x4; 6 | struct GPU_Mesh; 7 | 8 | struct Draw_Mesh { 9 | VkDescriptorSetLayout descriptor_set_layout; 10 | VkPipelineLayout pipeline_layout; 11 | VkPipeline pipeline; 12 | Vk_Buffer descriptor_buffer; 13 | Vk_Buffer uniform_buffer; 14 | void* mapped_uniform_buffer; 15 | 16 | void create(VkFormat color_attachment_format, VkFormat depth_attachment_format, VkImageView texture_view, VkSampler sample); 17 | void destroy(); 18 | void update(const Matrix3x4& object_to_camera_transform); 19 | void dispatch(const GPU_Mesh& mesh, bool show_texture_lod); 20 | }; 21 | -------------------------------------------------------------------------------- /src/kernels/raytrace_scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "acceleration_structure.h" 4 | #include "lib.h" 5 | 6 | struct GPU_Mesh; 7 | 8 | struct Raytrace_Scene { 9 | VkPhysicalDeviceRayTracingPipelinePropertiesKHR properties; 10 | Vk_Intersection_Accelerator accelerator; 11 | VkDescriptorSetLayout descriptor_set_layout; 12 | VkPipelineLayout pipeline_layout; 13 | VkPipeline pipeline; 14 | Vk_Buffer descriptor_buffer; 15 | void* mapped_descriptor_buffer_ptr = nullptr; 16 | Vk_Buffer shader_binding_table; 17 | Vk_Buffer uniform_buffer; 18 | void* mapped_uniform_buffer; 19 | 20 | VkPhysicalDeviceDescriptorBufferPropertiesEXT descriptor_buffer_properties{}; 21 | 22 | void create(const GPU_Mesh& gpu_mesh, VkImageView texture_view, VkSampler sampler); 23 | void destroy(); 24 | void update_output_image_descriptor(VkImageView output_image_view); 25 | void update(const Matrix3x4& model_transform, const Matrix3x4& camera_to_world_transform); 26 | void dispatch(bool spp4, bool show_texture_lod); 27 | 28 | private: 29 | void create_pipeline(const GPU_Mesh& gpu_mesh, VkImageView texture_view, VkSampler sampler); 30 | }; 31 | -------------------------------------------------------------------------------- /src/lib.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | constexpr float Pi = 3.14159265f; 12 | constexpr float Infinity = std::numeric_limits::infinity(); 13 | 14 | inline float radians(float degrees) { 15 | constexpr float deg_2_rad = Pi / 180.f; 16 | return degrees * deg_2_rad; 17 | } 18 | 19 | inline float degrees(float radians) { 20 | constexpr float rad_2_deg = 180.f / Pi; 21 | return radians * rad_2_deg; 22 | } 23 | 24 | void error(const std::string& message); 25 | std::string get_resource_path(const std::string& path_relative_data_directory); 26 | std::vector read_binary_file(const std::string& file_name); 27 | 28 | struct Timestamp { 29 | Timestamp() : t(std::chrono::steady_clock::now()) {} 30 | std::chrono::time_point t; 31 | }; 32 | uint64_t elapsed_milliseconds(Timestamp timestamp); 33 | uint64_t elapsed_nanoseconds(Timestamp timestamp); 34 | 35 | // Boost hash combine. 36 | template 37 | inline void hash_combine(std::size_t& seed, T value) { 38 | std::hash hasher; 39 | seed ^= hasher(value) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 40 | } 41 | 42 | inline float srgb_encode(float f) { 43 | if (f <= 0.0031308f) 44 | return 12.92f * f; 45 | else 46 | return 1.055f * std::pow(f, 1.f/2.4f) - 0.055f; 47 | } 48 | 49 | template 50 | inline T round_up(T k, T alignment) { 51 | return (k + alignment - 1) & ~(alignment - 1); 52 | } 53 | 54 | #if 0 55 | #define START_TIMER { Timestamp t; 56 | #define STOP_TIMER(message) \ 57 | auto d = elapsed_nanoseconds(t); \ 58 | static Timestamp t0; \ 59 | if (elapsed_milliseconds(t0) > 1000) { \ 60 | t0 = Timestamp(); \ 61 | printf(message ## " time = %lld microseconds\n", d / 1000); } } 62 | 63 | #else 64 | #define START_TIMER 65 | #define STOP_TIMER(...) 66 | #endif 67 | 68 | struct Vector4; 69 | 70 | struct Vector3 { 71 | float x, y, z; 72 | 73 | Vector3() 74 | : x(0.f), y(0.f), z(0.f) {} 75 | 76 | constexpr explicit Vector3(float v) 77 | : x(v), y(v), z(v) {} 78 | 79 | explicit Vector3(Vector4 v); 80 | 81 | Vector3(float x, float y, float z) 82 | : x(x), y(y), z(z) {} 83 | 84 | bool operator==(Vector3 v) const { 85 | return x == v.x && y == v.y && z == v.z; 86 | } 87 | 88 | bool operator!=(Vector3 v) const { 89 | return !(*this == v); 90 | } 91 | 92 | Vector3 operator-() const { 93 | return Vector3(-x, -y, -z); 94 | } 95 | 96 | float operator[](int index) const { 97 | return (&x)[index]; 98 | } 99 | 100 | float& operator[](int index) { 101 | return (&x)[index]; 102 | } 103 | 104 | Vector3& operator+=(const Vector3& v) { 105 | x += v.x; 106 | y += v.y; 107 | z += v.z; 108 | return *this; 109 | } 110 | 111 | Vector3& operator-=(const Vector3& v) { 112 | x -= v.x; 113 | y -= v.y; 114 | z -= v.z; 115 | return *this; 116 | } 117 | 118 | Vector3& operator*=(const Vector3& v) { 119 | x *= v.x; 120 | y *= v.y; 121 | z *= v.z; 122 | return *this; 123 | } 124 | 125 | Vector3& operator*=(float t) { 126 | x *= t; 127 | y *= t; 128 | z *= t; 129 | return *this; 130 | } 131 | 132 | Vector3& operator/=(float t) { 133 | x /= t; 134 | y /= t; 135 | z /= t; 136 | return *this; 137 | } 138 | 139 | Vector3 operator/(float t) const { 140 | return Vector3(x / t, y / t, z / t); 141 | } 142 | 143 | float length() const { 144 | return std::sqrt(squared_length()); 145 | } 146 | 147 | float squared_length() const { 148 | return x * x + y * y + z * z; 149 | } 150 | 151 | Vector3 normalized() const { 152 | return *this / length(); 153 | } 154 | 155 | void normalize() { 156 | *this /= length(); 157 | } 158 | 159 | bool is_normalized(float epsilon = 1e-3f) const { 160 | return std::abs(length() - 1.f) < epsilon; 161 | } 162 | }; 163 | 164 | struct Vector2 { 165 | float x, y; 166 | 167 | Vector2() 168 | : x(0.f), y(0.f) {} 169 | 170 | constexpr explicit Vector2(float v) 171 | : x(v), y(v) {} 172 | 173 | Vector2(float x, float y) 174 | : x(x), y(y) {} 175 | 176 | bool operator==(Vector2 v) const { 177 | return x == v.x && y == v.y; 178 | } 179 | 180 | bool operator!=(Vector2 v) const { 181 | return !(*this == v); 182 | } 183 | 184 | float operator[](int index) const { 185 | return (&x)[index]; 186 | } 187 | 188 | float& operator[](int index) { 189 | return (&x)[index]; 190 | } 191 | }; 192 | 193 | struct Vector4 { 194 | float x, y, z, w; 195 | 196 | Vector4() 197 | : x(0.f), y(0.f), z(0.f), w(0.f) {} 198 | 199 | constexpr explicit Vector4(float v) 200 | : x(v), y(v), z(v), w(v) {} 201 | 202 | Vector4(float x, float y, float z, float w) 203 | : x(x), y(y), z(z), w(w) {} 204 | 205 | Vector4(Vector3 xyz, float w) 206 | : x(xyz.x), y(xyz.y), z(xyz.z), w(w) {} 207 | 208 | bool operator==(Vector4 v) const { 209 | return x == v.x && y == v.y && z == v.z && w == v.w; 210 | } 211 | 212 | bool operator!=(Vector4 v) const { 213 | return !(*this == v); 214 | } 215 | 216 | float operator[](int index) const { 217 | return (&x)[index]; 218 | } 219 | 220 | float& operator[](int index) { 221 | return (&x)[index]; 222 | } 223 | }; 224 | 225 | inline Vector3::Vector3(Vector4 v) 226 | : x(v.x), y(v.y), z(v.z) 227 | {} 228 | 229 | inline Vector3 operator+(const Vector3& v1, const Vector3& v2) { 230 | return Vector3(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z); 231 | } 232 | 233 | inline Vector3 operator-(const Vector3& v1, const Vector3& v2) { 234 | return Vector3(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z); 235 | } 236 | 237 | inline Vector3 operator*(const Vector3& v1, const Vector3& v2) { 238 | return Vector3(v1.x * v2.x, v1.y * v2.y, v1.z * v2.z); 239 | } 240 | 241 | inline Vector3 operator*(const Vector3& v, float t) { 242 | return Vector3(v.x * t, v.y * t, v.z * t); 243 | } 244 | 245 | inline Vector3 operator*(float t, const Vector3& v) { 246 | return v * t; 247 | } 248 | 249 | inline float dot(const Vector3& v1, const Vector3& v2) { 250 | return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; 251 | } 252 | 253 | inline Vector3 cross(const Vector3& v1, const Vector3& v2) { 254 | return Vector3( 255 | v1.y * v2.z - v1.z * v2.y, 256 | v1.z * v2.x - v1.x * v2.z, 257 | v1.x * v2.y - v1.y * v2.x); 258 | } 259 | 260 | struct Matrix3x4 { 261 | float a[3][4]; 262 | static const Matrix3x4 identity; 263 | 264 | void set_column(int column_index, Vector3 c); 265 | Vector3 get_column(int column) const; 266 | void set_row(int row_index, Vector4 r); 267 | Vector4 get_row(int row) const; 268 | }; 269 | 270 | struct Matrix4x4 { 271 | float a[4][4]; 272 | static const Matrix4x4 identity; 273 | }; 274 | 275 | Matrix3x4 operator*(const Matrix3x4& m1, const Matrix3x4& m2); 276 | Matrix4x4 operator*(const Matrix4x4& m1, const Matrix3x4& m2); 277 | 278 | // assumption is that matrix contains only rotation and translation. 279 | Matrix3x4 get_inverse(const Matrix3x4& m); 280 | 281 | // rotate_[axis] functions premultiply a given matrix by corresponding rotation matrix. 282 | Matrix3x4 rotate_x(const Matrix3x4& m, float angle); 283 | Matrix3x4 rotate_y(const Matrix3x4& m, float angle); 284 | Matrix3x4 rotate_z(const Matrix3x4& m, float angle); 285 | 286 | // Computes world space->eye space transform that positions the camera at point 'from' 287 | // and orients its direction towards the point 'to'. 'up' unit vector specifies reference up direction. 288 | Matrix3x4 look_at_transform(Vector3 from, Vector3 to, Vector3 up); 289 | 290 | // Computes traditional perspective matrix that transforms position vector (x,y,z,1) to 291 | // obtain clip coordinates (xc, yc, zc, wc) that can be transformed to normalized deviced 292 | // coordinates (NDC) by perspective division (xd, yd, zd) = (xc/wc, yc/wc, zc/wc). 293 | // Eye-space z-axis points towards the viewer (OpenGL style), right-handed coordinate system. 294 | // z coordinate is mapped to 0 and 1 for near and far planes correspondingly. y axis in NDC 295 | // space points top-down with regard to eye space vertical direction (to match Vulkan viewport). 296 | Matrix4x4 perspective_transform_opengl_z01(float fovy_radians, float aspect_ratio, float near, float far); 297 | 298 | Vector3 transform_point(const Matrix3x4& m, Vector3 p); 299 | Vector3 transform_vector(const Matrix3x4& m, Vector3 v); 300 | 301 | struct Vertex { 302 | Vector3 pos; 303 | Vector2 uv; 304 | }; 305 | 306 | struct Triangle_Mesh { 307 | std::vector vertices; 308 | std::vector indices; 309 | }; 310 | 311 | Triangle_Mesh load_obj_model(const std::string& path, float additional_scale); 312 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "demo.h" 2 | #include "glfw/glfw3.h" 3 | #include 4 | #include 5 | 6 | static bool parse_command_line(int argc, char** argv) { 7 | bool found_unknown_option = false; 8 | for (int i = 1; i < argc; i++) { 9 | if (strcmp(argv[i], "--data-dir") == 0) { 10 | if (i == argc - 1) { 11 | printf("--data-dir value is missing\n"); 12 | } 13 | else { 14 | extern std::string g_data_dir; 15 | g_data_dir = argv[i + 1]; 16 | i++; 17 | } 18 | } 19 | else if (strcmp(argv[i], "--help") == 0) { 20 | printf("%-25s Path to the data directory. Default is ./data.\n", "--data-dir"); 21 | printf("%-25s Shows this information.\n", "--help"); 22 | return false; 23 | } 24 | else 25 | found_unknown_option = true; 26 | } 27 | if (found_unknown_option) 28 | printf("Use --help to list all options.\n"); 29 | return true; 30 | } 31 | 32 | static int window_width = 720; 33 | static int window_height = 720; 34 | 35 | static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 36 | if (action == GLFW_PRESS) { 37 | if (key == GLFW_KEY_ESCAPE) { 38 | glfwSetWindowShouldClose(window, GLFW_TRUE); 39 | } else if (key == GLFW_KEY_F11 || (key == GLFW_KEY_ENTER && mods == GLFW_MOD_ALT)) { 40 | static int last_window_xpos, last_window_ypos; 41 | static int last_window_width, last_window_height; 42 | 43 | VK_CHECK(vkDeviceWaitIdle(vk.device)); 44 | GLFWmonitor* monitor = glfwGetWindowMonitor(window); 45 | if (monitor == nullptr) { 46 | glfwGetWindowPos(window, &last_window_xpos, &last_window_ypos); 47 | last_window_width = window_width; 48 | last_window_height = window_height; 49 | 50 | monitor = glfwGetPrimaryMonitor(); 51 | const GLFWvidmode* mode = glfwGetVideoMode(monitor); 52 | glfwSetWindowMonitor(window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate); 53 | } else { 54 | glfwSetWindowMonitor(window, nullptr, last_window_xpos, last_window_ypos, last_window_width, last_window_height, 0); 55 | } 56 | } 57 | } 58 | } 59 | 60 | static void glfw_error_callback(int error, const char* description) { 61 | fprintf(stderr, "GLFW error: %s\n", description); 62 | } 63 | 64 | int main(int argc, char** argv) { 65 | if (!parse_command_line(argc, argv)) { 66 | return 0; 67 | } 68 | glfwSetErrorCallback(glfw_error_callback); 69 | if (!glfwInit()) { 70 | error("glfwInit failed"); 71 | } 72 | glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); 73 | GLFWwindow* glfw_window = glfwCreateWindow(window_width, window_height, "Vulkan demo", nullptr, nullptr); 74 | assert(glfw_window != nullptr); 75 | glfwSetKeyCallback(glfw_window, glfw_key_callback); 76 | 77 | Vk_Demo demo{}; 78 | demo.initialize(glfw_window); 79 | 80 | bool prev_vsync = demo.vsync_enabled(); 81 | 82 | bool window_active = true; 83 | 84 | while (!glfwWindowShouldClose(glfw_window)) { 85 | if (window_active) 86 | demo.run_frame(); 87 | 88 | glfwPollEvents(); 89 | 90 | int width, height; 91 | glfwGetWindowSize(glfw_window, &width, &height); 92 | 93 | bool recreate_swapchain = false; 94 | if (prev_vsync != demo.vsync_enabled()) { 95 | prev_vsync = demo.vsync_enabled(); 96 | recreate_swapchain = true; 97 | } else if (width != window_width || height != window_height) { 98 | window_width = width; 99 | window_height = height; 100 | recreate_swapchain = true; 101 | } 102 | 103 | window_active = (width != 0 && height != 0); 104 | 105 | if (!window_active) 106 | continue; 107 | 108 | if (recreate_swapchain) { 109 | VK_CHECK(vkDeviceWaitIdle(vk.device)); 110 | demo.release_resolution_dependent_resources(); 111 | vk_destroy_swapchain(); 112 | vk_create_swapchain(demo.vsync_enabled()); 113 | demo.restore_resolution_dependent_resources(); 114 | recreate_swapchain = false; 115 | } 116 | } 117 | 118 | demo.shutdown(); 119 | glfwTerminate(); 120 | return 0; 121 | } 122 | -------------------------------------------------------------------------------- /src/shaders/common.glsl: -------------------------------------------------------------------------------- 1 | layout(row_major) uniform; 2 | 3 | float srgb_encode(float c) { 4 | if (c <= 0.0031308f) 5 | return 12.92f * c; 6 | else 7 | return 1.055f * pow(c, 1.f/2.4f) - 0.055f; 8 | } 9 | 10 | vec3 srgb_encode(vec3 c) { 11 | return vec3(srgb_encode(c.r), srgb_encode(c.g), srgb_encode(c.b)); 12 | } 13 | 14 | vec3 color_encode_lod(float lod) { 15 | uint color_mask = (uint(floor(lod)) + 1) & 7; 16 | vec3 color0 = vec3(float(color_mask&1), float(color_mask&2), float(color_mask&4)); 17 | vec3 color1 = 0.25 * color0; 18 | return mix(color0, color1, fract(lod)); 19 | } 20 | 21 | float ray_plane_intersection(vec3 ray_o, vec3 ray_d, vec3 plane_n, float plane_d) { 22 | return (-plane_d - dot(plane_n, ray_o)) / dot(plane_n, ray_d); 23 | } 24 | 25 | vec2 barycentric_interpolate(float b1, float b2, vec2 v0, vec2 v1, vec2 v2) { 26 | return (1.0 - b1 - b2)*v0 + b1*v1 + b2*v2; 27 | } 28 | 29 | vec3 barycentric_interpolate(float b1, float b2, vec3 v0, vec3 v1, vec3 v2) { 30 | return (1.0 - b1 - b2)*v0 + b1*v1 + b2*v2; 31 | } 32 | 33 | void coordinate_system_from_vector(vec3 v, out vec3 v1, out vec3 v2) { 34 | v1 = normalize(abs(v.x) > abs(v.y) ? vec3(-v.z, 0, v.x) : vec3(0, -v.z, v.y)); 35 | v2 = cross(v, v1); 36 | } 37 | -------------------------------------------------------------------------------- /src/shaders/copy_to_swapchain.comp.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | 4 | #include "common.glsl" 5 | 6 | layout(local_size_x = 32, local_size_y = 32) in; 7 | 8 | layout(push_constant) uniform Push_Constants { 9 | uvec2 viewport_size; 10 | }; 11 | 12 | layout(binding=0) uniform sampler point_sampler; 13 | layout(binding=1) uniform texture2D output_image; 14 | layout(binding=2, rgba8) uniform writeonly image2D swapchain_image; 15 | 16 | void main() { 17 | ivec2 loc = ivec2(gl_GlobalInvocationID.xy); 18 | 19 | if (loc.x < viewport_size.x && loc.y < viewport_size.y) { 20 | float s = (gl_GlobalInvocationID.x + 0.5) / viewport_size.x; 21 | float t = (gl_GlobalInvocationID.y + 0.5) / viewport_size.y; 22 | vec4 color = textureLod(sampler2D(output_image, point_sampler), vec2(s, t), 0); 23 | imageStore(swapchain_image, loc, color); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/shaders/raster_mesh.frag.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | 4 | #include "common.glsl" 5 | 6 | layout(push_constant) uniform Push_Constants { 7 | uint show_texture_lods; 8 | }; 9 | 10 | layout(location=0) in vec2 frag_uv; 11 | layout(location = 0) out vec4 color_attachment0; 12 | 13 | layout(binding=1) uniform texture2D image; 14 | layout(binding=2) uniform sampler image_sampler; 15 | 16 | void main() { 17 | vec3 color; 18 | 19 | if (show_texture_lods != 0) { 20 | // The commented code below will give result very close to raytracing version. 21 | // The lod calculated by textureQueryLod gives a bit different result and that's 22 | // fine since implementations are not restricted to some fixed algorithm. 23 | // vec2 uvdx = abs(dFdx(frag_in.uv)); 24 | // vec2 uvdy = abs(dFdy(frag_in.uv)); 25 | // float filter_width = max(max(uvdx[0], uvdx[1]), max(uvdy[0], uvdy[1])); 26 | // float lod = textureQueryLevels(sampler2D(image, image_sampler)) - 1 + log2(filter_width); 27 | 28 | float lod = textureQueryLod(sampler2D(image, image_sampler), frag_uv).y; 29 | color = color_encode_lod(lod); 30 | } else { 31 | color = texture(sampler2D(image, image_sampler), frag_uv).xyz; 32 | } 33 | color_attachment0 = vec4(srgb_encode(color), 1); 34 | } 35 | -------------------------------------------------------------------------------- /src/shaders/raster_mesh.vert.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | 4 | #include "common.glsl" 5 | 6 | layout(location=0) in vec4 in_position; 7 | layout(location=1) in vec2 in_uv; 8 | layout(location = 0) out vec2 frag_uv; 9 | 10 | layout(std140, binding=0) uniform Uniform_Block { 11 | mat4x4 model_view_proj; 12 | }; 13 | 14 | void main() { 15 | frag_uv = in_uv; 16 | gl_Position = model_view_proj * in_position; 17 | } 18 | -------------------------------------------------------------------------------- /src/shaders/rt_mesh.rchit.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | #extension GL_EXT_ray_tracing : require 4 | 5 | #include "common.glsl" 6 | 7 | #define HIT_SHADER 8 | #include "rt_utils.glsl" 9 | 10 | hitAttributeEXT vec2 attribs; 11 | 12 | struct Buffer_Vertex { 13 | float x, y, z; 14 | float u, v; 15 | }; 16 | 17 | layout(push_constant) uniform Push_Constants { 18 | layout(offset = 4) uint show_texture_lods; 19 | }; 20 | 21 | layout (location=0) rayPayloadInEXT Ray_Payload payload; 22 | 23 | layout(std430, binding=3) readonly buffer Indices { 24 | uint index_buffer[]; 25 | }; 26 | 27 | layout(std430, binding=4) readonly buffer Vertices { 28 | Buffer_Vertex vertex_buffer[]; 29 | }; 30 | 31 | layout(binding=5) uniform texture2D image; 32 | layout(binding=6) uniform sampler image_sampler; 33 | 34 | Vertex fetch_vertex(int vertex_index) { 35 | uint i = index_buffer[vertex_index]; 36 | Buffer_Vertex bv = vertex_buffer[i]; 37 | 38 | Vertex v; 39 | v.p = vec3(bv.x, bv.y, bv.z); 40 | v.uv = fract(vec2(bv.u, bv.v)); 41 | return v; 42 | } 43 | 44 | void main() { 45 | Vertex v0 = fetch_vertex(gl_PrimitiveID*3 + 0); 46 | Vertex v1 = fetch_vertex(gl_PrimitiveID*3 + 1); 47 | Vertex v2 = fetch_vertex(gl_PrimitiveID*3 + 2); 48 | 49 | v0.p = gl_ObjectToWorldEXT * vec4(v0.p, 1); 50 | v1.p = gl_ObjectToWorldEXT * vec4(v1.p, 1); 51 | v2.p = gl_ObjectToWorldEXT * vec4(v2.p, 1); 52 | 53 | int mip_levels = textureQueryLevels(sampler2D(image, image_sampler)); 54 | float lod = compute_texture_lod(v0, v1, v2, payload.rx_dir, payload.ry_dir, mip_levels); 55 | 56 | vec3 color; 57 | if (show_texture_lods != 0) { 58 | color = color_encode_lod(lod); 59 | } else { 60 | vec2 uv = fract(barycentric_interpolate(attribs.x, attribs.y, v0.uv, v1.uv, v2.uv)); 61 | color = textureLod(sampler2D(image, image_sampler), uv, lod).rgb; 62 | } 63 | 64 | payload.color = srgb_encode(color); 65 | } 66 | -------------------------------------------------------------------------------- /src/shaders/rt_mesh.rgen.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | #extension GL_EXT_ray_tracing : require 4 | 5 | #include "common.glsl" 6 | 7 | #define RGEN_SHADER 8 | #include "rt_utils.glsl" 9 | 10 | layout(push_constant) uniform Push_Constants { 11 | layout(offset = 0) uint spp4; 12 | }; 13 | 14 | layout(binding = 0, rgba8) uniform image2D image; 15 | layout(set=0, binding = 1) uniform accelerationStructureEXT accel; 16 | 17 | layout(std140, binding=2) uniform Uniform_Block { 18 | mat4x3 camera_to_world; 19 | }; 20 | 21 | layout(location = 0) rayPayloadEXT Ray_Payload payload; 22 | 23 | const float tmin = 1e-3f; 24 | const float tmax = 1e+3f; 25 | 26 | vec3 trace_ray(vec2 sample_pos) { 27 | Ray ray = generate_ray(camera_to_world, sample_pos); 28 | payload.rx_dir = ray.rx_dir; 29 | payload.ry_dir = ray.ry_dir; 30 | payload.color = vec3(0); 31 | traceRayEXT(accel, gl_RayFlagsOpaqueEXT, 0xff, 0, 0, 0, ray.origin, tmin, ray.dir, tmax, 0); 32 | return payload.color; 33 | } 34 | 35 | void main() { 36 | const vec2 sample_origin = vec2(gl_LaunchIDEXT.xy); 37 | vec3 color = vec3(0); 38 | 39 | if (spp4 != 0) { 40 | color += trace_ray(sample_origin + vec2(0.125, 0.375)); 41 | color += trace_ray(sample_origin + vec2(0.375, 0.875)); 42 | color += trace_ray(sample_origin + vec2(0.625, 0.125)); 43 | color += trace_ray(sample_origin + vec2(0.875, 0.625)); 44 | color *= 0.25; 45 | } else 46 | color = trace_ray(sample_origin + vec2(0.5)); 47 | 48 | imageStore(image, ivec2(gl_LaunchIDEXT.xy), vec4(color, 1.0)); 49 | } 50 | -------------------------------------------------------------------------------- /src/shaders/rt_mesh.rmiss.glsl: -------------------------------------------------------------------------------- 1 | #version 460 2 | #extension GL_GOOGLE_include_directive : require 3 | #extension GL_EXT_ray_tracing : require 4 | 5 | #include "common.glsl" 6 | #include "rt_utils.glsl" 7 | 8 | layout (location=0) rayPayloadInEXT Ray_Payload payload; 9 | 10 | void main() { 11 | payload.color = srgb_encode(vec3(0.32f, 0.32f, 0.4f)); 12 | } 13 | -------------------------------------------------------------------------------- /src/shaders/rt_utils.glsl: -------------------------------------------------------------------------------- 1 | struct Ray_Payload { 2 | vec3 rx_dir; 3 | vec3 ry_dir; 4 | vec3 color; 5 | }; 6 | 7 | struct Vertex { 8 | vec3 p; 9 | vec2 uv; 10 | }; 11 | 12 | struct Ray { 13 | vec3 origin; 14 | vec3 dir; 15 | vec3 rx_dir; 16 | vec3 ry_dir; 17 | }; 18 | 19 | #ifdef RGEN_SHADER 20 | vec3 get_direction(vec2 film_position) { 21 | const float tan_fovy_over_2 = 0.414; // tan(45/2) 22 | 23 | vec2 uv = 2.0 * (film_position / vec2(gl_LaunchSizeEXT.xy)) - 1.0; 24 | float aspect_ratio = float(gl_LaunchSizeEXT.x) / float(gl_LaunchSizeEXT.y); 25 | 26 | float dir_x = uv.x * aspect_ratio * tan_fovy_over_2; 27 | float dir_y = -uv.y * tan_fovy_over_2; 28 | return normalize(vec3(dir_x, dir_y, -1.f)); 29 | } 30 | 31 | Ray generate_ray(mat4x3 camera_to_world, vec2 film_position) { 32 | Ray ray; 33 | ray.origin = camera_to_world[3]; 34 | ray.dir = camera_to_world * vec4(get_direction(film_position), 0); 35 | ray.rx_dir = camera_to_world * vec4(get_direction(vec2(film_position.x + 1.f, film_position.y)), 0); 36 | ray.ry_dir = camera_to_world * vec4(get_direction(vec2(film_position.x, film_position.y + 1.f)), 0); 37 | return ray; 38 | } 39 | #endif // RGEN_SHADER 40 | 41 | #ifdef HIT_SHADER 42 | float compute_texture_lod(Vertex v0, Vertex v1, Vertex v2, vec3 rx_dir, vec3 ry_dir, int mip_levels) { 43 | vec3 face_normal = normalize(cross(v1.p - v0.p, v2.p - v0.p)); 44 | 45 | // compute dp/du, dp/dv (PBRT, 3.6.2) 46 | vec3 dpdu, dpdv; 47 | { 48 | vec3 p10 = v1.p - v0.p; 49 | vec3 p20 = v2.p - v0.p; 50 | 51 | float a00 = v1.uv.x - v0.uv.x; float a01 = v1.uv.y - v0.uv.y; 52 | float a10 = v2.uv.x - v0.uv.x; float a11 = v2.uv.y - v0.uv.y; 53 | 54 | float det = a00*a11 - a01*a10; 55 | if (abs(det) < 1e-10) { 56 | coordinate_system_from_vector(face_normal, dpdu, dpdv); 57 | } else { 58 | float inv_det = 1.0/det; 59 | dpdu = ( a11*p10 - a01*p20) * inv_det; 60 | dpdv = (-a10*p10 + a00*p20) * inv_det; 61 | } 62 | } 63 | 64 | // compute offsets from main intersection point to approximated intersections of auxilary rays 65 | vec3 dpdx, dpdy; 66 | { 67 | vec3 p = gl_WorldRayOriginEXT + gl_WorldRayDirectionEXT * gl_HitTEXT; 68 | float plane_d = -dot(face_normal, p); 69 | 70 | float tx = ray_plane_intersection(gl_WorldRayOriginEXT, rx_dir, face_normal, plane_d); 71 | float ty = ray_plane_intersection(gl_WorldRayOriginEXT, ry_dir, face_normal, plane_d); 72 | 73 | vec3 px = gl_WorldRayOriginEXT + rx_dir * tx; 74 | vec3 py = gl_WorldRayOriginEXT + ry_dir * ty; 75 | 76 | dpdx = px - p; 77 | dpdy = py - p; 78 | } 79 | 80 | // compute du/dx, dv/dx, du/dy, dv/dy (PBRT, 10.1.1) 81 | float dudx, dvdx, dudy, dvdy; 82 | { 83 | uint dim0 = 0, dim1 = 1; 84 | vec3 a = abs(face_normal); 85 | if (a.x > a.y && a.x > a.z) { 86 | dim0 = 1; 87 | dim1 = 2; 88 | } else if (a.y > a.z) { 89 | dim0 = 0; 90 | dim1 = 2; 91 | } 92 | 93 | float a00 = dpdu[dim0]; float a01 = dpdv[dim0]; 94 | float a10 = dpdu[dim1]; float a11 = dpdv[dim1]; 95 | 96 | float det = a00*a11 - a01*a10; 97 | if (abs(det) < 1e-10) 98 | dudx = dvdx = dudy = dvdy = 0; 99 | else { 100 | float inv_det = 1.0/det; 101 | dudx = ( a11*dpdx[dim0] - a01*dpdx[dim1]) * inv_det; 102 | dvdx = (-a10*dpdx[dim0] - a00*dpdx[dim1]) * inv_det; 103 | 104 | dudy = ( a11*dpdy[dim0] - a01*dpdy[dim1]) * inv_det; 105 | dvdy = (-a10*dpdy[dim0] - a00*dpdy[dim1]) * inv_det; 106 | } 107 | } 108 | 109 | // To satisfy Nyquist limit the filter width should be twice as large as below and it is 110 | // achieved implicitly by using bilinear filtering to sample mip levels. 111 | //float filter_width = max(max(abs(dudx), abs(dvdx)), max(abs(dudy), abs(dvdy))); 112 | float filter_width = max(length(vec2(dudx, dvdx)), length(vec2(dudy, dvdy))); 113 | 114 | return mip_levels - 1 + log2(clamp(filter_width, 1e-6, 1.0)); 115 | } 116 | #endif // HIT_SHADER 117 | -------------------------------------------------------------------------------- /third-party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(THIRD_PARTY_SOURCE 2 | # glfw 3 | glfw/context.c 4 | glfw/egl_context.c 5 | glfw/glx_context.c 6 | glfw/init.c 7 | glfw/input.c 8 | glfw/linux_joystick.c 9 | glfw/monitor.c 10 | glfw/null_init.c 11 | glfw/null_joystick.c 12 | glfw/null_monitor.c 13 | glfw/null_window.c 14 | glfw/osmesa_context.c 15 | glfw/platform.c 16 | glfw/posix_module.c 17 | glfw/posix_poll.c 18 | glfw/posix_thread.c 19 | glfw/posix_time.c 20 | glfw/vulkan.c 21 | glfw/wgl_context.c 22 | glfw/win32_init.c 23 | glfw/win32_joystick.c 24 | glfw/win32_module.c 25 | glfw/win32_monitor.c 26 | glfw/win32_thread.c 27 | glfw/win32_time.c 28 | glfw/win32_window.c 29 | glfw/window.c 30 | glfw/x11_init.c 31 | glfw/x11_monitor.c 32 | glfw/x11_window.c 33 | glfw/xkb_unicode.c 34 | # imgui 35 | imgui/imconfig.h 36 | imgui/imgui.cpp 37 | imgui/imgui.h 38 | imgui/imgui_demo.cpp 39 | imgui/imgui_draw.cpp 40 | imgui/imgui_internal.h 41 | imgui/imgui_tables.cpp 42 | imgui/imgui_widgets.cpp 43 | imgui/imgui_impl_glfw.cpp 44 | imgui/imgui_impl_glfw.h 45 | imgui/imgui_impl_vulkan.cpp 46 | imgui/imgui_impl_vulkan.h 47 | # volk 48 | volk/volk.c 49 | volk/volk.h 50 | ) 51 | source_group(TREE "${CMAKE_SOURCE_DIR}/third-party" FILES ${THIRD_PARTY_SOURCE}) 52 | 53 | add_library(third-party ${THIRD_PARTY_SOURCE}) 54 | target_compile_features(third-party PRIVATE cxx_std_17) 55 | target_include_directories(third-party PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") 56 | 57 | if (CMAKE_SYSTEM_NAME STREQUAL "Windows") 58 | target_compile_definitions(third-party PUBLIC _GLFW_WIN32 VK_USE_PLATFORM_WIN32_KHR IMGUI_IMPL_VULKAN_USE_VOLK) 59 | elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux") 60 | target_compile_definitions(third-party PUBLIC _GLFW_X11 VK_USE_PLATFORM_XCB_KHR IMGUI_IMPL_VULKAN_USE_VOLK) 61 | else() 62 | message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") 63 | endif() 64 | 65 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 66 | target_compile_options(third-party PRIVATE 67 | -Wno-unused-parameter 68 | -Wno-sign-compare 69 | -Wno-missing-field-initializers 70 | ) 71 | target_compile_options(third-party INTERFACE 72 | -Wno-unused-variable 73 | -Wno-parentheses 74 | -Wno-shift-negative-value 75 | -Wno-implicit-fallthrough 76 | ) 77 | endif() 78 | -------------------------------------------------------------------------------- /third-party/glfw/linux_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #define GLFW_LINUX_JOYSTICK_STATE _GLFWjoystickLinux linjs; 32 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE _GLFWlibraryLinux linjs; 33 | 34 | // Linux-specific joystick data 35 | // 36 | typedef struct _GLFWjoystickLinux 37 | { 38 | int fd; 39 | char path[PATH_MAX]; 40 | int keyMap[KEY_CNT - BTN_MISC]; 41 | int absMap[ABS_CNT]; 42 | struct input_absinfo absInfo[ABS_CNT]; 43 | int hats[4][2]; 44 | } _GLFWjoystickLinux; 45 | 46 | // Linux-specific joystick API data 47 | // 48 | typedef struct _GLFWlibraryLinux 49 | { 50 | int inotify; 51 | int watch; 52 | regex_t regex; 53 | GLFWbool dropped; 54 | } _GLFWlibraryLinux; 55 | 56 | void _glfwDetectJoystickConnectionLinux(void); 57 | 58 | GLFWbool _glfwInitJoysticksLinux(void); 59 | void _glfwTerminateJoysticksLinux(void); 60 | GLFWbool _glfwPollJoystickLinux(_GLFWjoystick* js, int mode); 61 | const char* _glfwGetMappingNameLinux(void); 62 | void _glfwUpdateGamepadGUIDLinux(char* guid); 63 | 64 | -------------------------------------------------------------------------------- /third-party/glfw/null_init.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform) 40 | { 41 | const _GLFWplatform null = 42 | { 43 | GLFW_PLATFORM_NULL, 44 | _glfwInitNull, 45 | _glfwTerminateNull, 46 | _glfwGetCursorPosNull, 47 | _glfwSetCursorPosNull, 48 | _glfwSetCursorModeNull, 49 | _glfwSetRawMouseMotionNull, 50 | _glfwRawMouseMotionSupportedNull, 51 | _glfwCreateCursorNull, 52 | _glfwCreateStandardCursorNull, 53 | _glfwDestroyCursorNull, 54 | _glfwSetCursorNull, 55 | _glfwGetScancodeNameNull, 56 | _glfwGetKeyScancodeNull, 57 | _glfwSetClipboardStringNull, 58 | _glfwGetClipboardStringNull, 59 | _glfwInitJoysticksNull, 60 | _glfwTerminateJoysticksNull, 61 | _glfwPollJoystickNull, 62 | _glfwGetMappingNameNull, 63 | _glfwUpdateGamepadGUIDNull, 64 | _glfwFreeMonitorNull, 65 | _glfwGetMonitorPosNull, 66 | _glfwGetMonitorContentScaleNull, 67 | _glfwGetMonitorWorkareaNull, 68 | _glfwGetVideoModesNull, 69 | _glfwGetVideoModeNull, 70 | _glfwGetGammaRampNull, 71 | _glfwSetGammaRampNull, 72 | _glfwCreateWindowNull, 73 | _glfwDestroyWindowNull, 74 | _glfwSetWindowTitleNull, 75 | _glfwSetWindowIconNull, 76 | _glfwGetWindowPosNull, 77 | _glfwSetWindowPosNull, 78 | _glfwGetWindowSizeNull, 79 | _glfwSetWindowSizeNull, 80 | _glfwSetWindowSizeLimitsNull, 81 | _glfwSetWindowAspectRatioNull, 82 | _glfwGetFramebufferSizeNull, 83 | _glfwGetWindowFrameSizeNull, 84 | _glfwGetWindowContentScaleNull, 85 | _glfwIconifyWindowNull, 86 | _glfwRestoreWindowNull, 87 | _glfwMaximizeWindowNull, 88 | _glfwShowWindowNull, 89 | _glfwHideWindowNull, 90 | _glfwRequestWindowAttentionNull, 91 | _glfwFocusWindowNull, 92 | _glfwSetWindowMonitorNull, 93 | _glfwWindowFocusedNull, 94 | _glfwWindowIconifiedNull, 95 | _glfwWindowVisibleNull, 96 | _glfwWindowMaximizedNull, 97 | _glfwWindowHoveredNull, 98 | _glfwFramebufferTransparentNull, 99 | _glfwGetWindowOpacityNull, 100 | _glfwSetWindowResizableNull, 101 | _glfwSetWindowDecoratedNull, 102 | _glfwSetWindowFloatingNull, 103 | _glfwSetWindowOpacityNull, 104 | _glfwSetWindowMousePassthroughNull, 105 | _glfwPollEventsNull, 106 | _glfwWaitEventsNull, 107 | _glfwWaitEventsTimeoutNull, 108 | _glfwPostEmptyEventNull, 109 | _glfwGetEGLPlatformNull, 110 | _glfwGetEGLNativeDisplayNull, 111 | _glfwGetEGLNativeWindowNull, 112 | _glfwGetRequiredInstanceExtensionsNull, 113 | _glfwGetPhysicalDevicePresentationSupportNull, 114 | _glfwCreateWindowSurfaceNull, 115 | }; 116 | 117 | *platform = null; 118 | return GLFW_TRUE; 119 | } 120 | 121 | int _glfwInitNull(void) 122 | { 123 | _glfwPollMonitorsNull(); 124 | return GLFW_TRUE; 125 | } 126 | 127 | void _glfwTerminateNull(void) 128 | { 129 | free(_glfw.null.clipboardString); 130 | _glfwTerminateOSMesa(); 131 | _glfwTerminateEGL(); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /third-party/glfw/null_joystick.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | 32 | ////////////////////////////////////////////////////////////////////////// 33 | ////// GLFW platform API ////// 34 | ////////////////////////////////////////////////////////////////////////// 35 | 36 | GLFWbool _glfwInitJoysticksNull(void) 37 | { 38 | return GLFW_TRUE; 39 | } 40 | 41 | void _glfwTerminateJoysticksNull(void) 42 | { 43 | } 44 | 45 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode) 46 | { 47 | return GLFW_FALSE; 48 | } 49 | 50 | const char* _glfwGetMappingNameNull(void) 51 | { 52 | return ""; 53 | } 54 | 55 | void _glfwUpdateGamepadGUIDNull(char* guid) 56 | { 57 | } 58 | 59 | -------------------------------------------------------------------------------- /third-party/glfw/null_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | GLFWbool _glfwInitJoysticksNull(void); 28 | void _glfwTerminateJoysticksNull(void); 29 | GLFWbool _glfwPollJoystickNull(_GLFWjoystick* js, int mode); 30 | const char* _glfwGetMappingNameNull(void); 31 | void _glfwUpdateGamepadGUIDNull(char* guid); 32 | 33 | -------------------------------------------------------------------------------- /third-party/glfw/null_monitor.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2019 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | // The the sole (fake) video mode of our (sole) fake monitor 37 | // 38 | static GLFWvidmode getVideoMode(void) 39 | { 40 | GLFWvidmode mode; 41 | mode.width = 1920; 42 | mode.height = 1080; 43 | mode.redBits = 8; 44 | mode.greenBits = 8; 45 | mode.blueBits = 8; 46 | mode.refreshRate = 60; 47 | return mode; 48 | } 49 | 50 | ////////////////////////////////////////////////////////////////////////// 51 | ////// GLFW internal API ////// 52 | ////////////////////////////////////////////////////////////////////////// 53 | 54 | void _glfwPollMonitorsNull(void) 55 | { 56 | const float dpi = 141.f; 57 | const GLFWvidmode mode = getVideoMode(); 58 | _GLFWmonitor* monitor = _glfwAllocMonitor("Null SuperNoop 0", 59 | (int) (mode.width * 25.4f / dpi), 60 | (int) (mode.height * 25.4f / dpi)); 61 | _glfwInputMonitor(monitor, GLFW_CONNECTED, _GLFW_INSERT_FIRST); 62 | } 63 | 64 | ////////////////////////////////////////////////////////////////////////// 65 | ////// GLFW platform API ////// 66 | ////////////////////////////////////////////////////////////////////////// 67 | 68 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor) 69 | { 70 | _glfwFreeGammaArrays(&monitor->null.ramp); 71 | } 72 | 73 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos) 74 | { 75 | if (xpos) 76 | *xpos = 0; 77 | if (ypos) 78 | *ypos = 0; 79 | } 80 | 81 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, 82 | float* xscale, float* yscale) 83 | { 84 | if (xscale) 85 | *xscale = 1.f; 86 | if (yscale) 87 | *yscale = 1.f; 88 | } 89 | 90 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, 91 | int* xpos, int* ypos, 92 | int* width, int* height) 93 | { 94 | const GLFWvidmode mode = getVideoMode(); 95 | 96 | if (xpos) 97 | *xpos = 0; 98 | if (ypos) 99 | *ypos = 10; 100 | if (width) 101 | *width = mode.width; 102 | if (height) 103 | *height = mode.height - 10; 104 | } 105 | 106 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found) 107 | { 108 | GLFWvidmode* mode = _glfw_calloc(1, sizeof(GLFWvidmode)); 109 | *mode = getVideoMode(); 110 | *found = 1; 111 | return mode; 112 | } 113 | 114 | void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode) 115 | { 116 | *mode = getVideoMode(); 117 | } 118 | 119 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp) 120 | { 121 | if (!monitor->null.ramp.size) 122 | { 123 | unsigned int i; 124 | 125 | _glfwAllocGammaArrays(&monitor->null.ramp, 256); 126 | 127 | for (i = 0; i < monitor->null.ramp.size; i++) 128 | { 129 | const float gamma = 2.2f; 130 | float value; 131 | value = i / (float) (monitor->null.ramp.size - 1); 132 | value = powf(value, 1.f / gamma) * 65535.f + 0.5f; 133 | value = _glfw_fminf(value, 65535.f); 134 | 135 | monitor->null.ramp.red[i] = (unsigned short) value; 136 | monitor->null.ramp.green[i] = (unsigned short) value; 137 | monitor->null.ramp.blue[i] = (unsigned short) value; 138 | } 139 | } 140 | 141 | _glfwAllocGammaArrays(ramp, monitor->null.ramp.size); 142 | memcpy(ramp->red, monitor->null.ramp.red, sizeof(short) * ramp->size); 143 | memcpy(ramp->green, monitor->null.ramp.green, sizeof(short) * ramp->size); 144 | memcpy(ramp->blue, monitor->null.ramp.blue, sizeof(short) * ramp->size); 145 | return GLFW_TRUE; 146 | } 147 | 148 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp) 149 | { 150 | if (monitor->null.ramp.size != ramp->size) 151 | { 152 | _glfwInputError(GLFW_PLATFORM_ERROR, 153 | "Null: Gamma ramp size must match current ramp size"); 154 | return; 155 | } 156 | 157 | memcpy(monitor->null.ramp.red, ramp->red, sizeof(short) * ramp->size); 158 | memcpy(monitor->null.ramp.green, ramp->green, sizeof(short) * ramp->size); 159 | memcpy(monitor->null.ramp.blue, ramp->blue, sizeof(short) * ramp->size); 160 | } 161 | 162 | -------------------------------------------------------------------------------- /third-party/glfw/null_platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2016 Google Inc. 5 | // Copyright (c) 2016-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLFW_NULL_WINDOW_STATE _GLFWwindowNull null; 29 | #define GLFW_NULL_LIBRARY_WINDOW_STATE _GLFWlibraryNull null; 30 | #define GLFW_NULL_MONITOR_STATE _GLFWmonitorNull null; 31 | 32 | #define GLFW_NULL_CONTEXT_STATE 33 | #define GLFW_NULL_CURSOR_STATE 34 | #define GLFW_NULL_LIBRARY_CONTEXT_STATE 35 | 36 | 37 | // Null-specific per-window data 38 | // 39 | typedef struct _GLFWwindowNull 40 | { 41 | int xpos; 42 | int ypos; 43 | int width; 44 | int height; 45 | char* title; 46 | GLFWbool visible; 47 | GLFWbool iconified; 48 | GLFWbool maximized; 49 | GLFWbool resizable; 50 | GLFWbool decorated; 51 | GLFWbool floating; 52 | GLFWbool transparent; 53 | float opacity; 54 | } _GLFWwindowNull; 55 | 56 | // Null-specific per-monitor data 57 | // 58 | typedef struct _GLFWmonitorNull 59 | { 60 | GLFWgammaramp ramp; 61 | } _GLFWmonitorNull; 62 | 63 | // Null-specific global data 64 | // 65 | typedef struct _GLFWlibraryNull 66 | { 67 | int xcursor; 68 | int ycursor; 69 | char* clipboardString; 70 | _GLFWwindow* focusedWindow; 71 | } _GLFWlibraryNull; 72 | 73 | void _glfwPollMonitorsNull(void); 74 | 75 | GLFWbool _glfwConnectNull(int platformID, _GLFWplatform* platform); 76 | int _glfwInitNull(void); 77 | void _glfwTerminateNull(void); 78 | 79 | void _glfwFreeMonitorNull(_GLFWmonitor* monitor); 80 | void _glfwGetMonitorPosNull(_GLFWmonitor* monitor, int* xpos, int* ypos); 81 | void _glfwGetMonitorContentScaleNull(_GLFWmonitor* monitor, float* xscale, float* yscale); 82 | void _glfwGetMonitorWorkareaNull(_GLFWmonitor* monitor, int* xpos, int* ypos, int* width, int* height); 83 | GLFWvidmode* _glfwGetVideoModesNull(_GLFWmonitor* monitor, int* found); 84 | void _glfwGetVideoModeNull(_GLFWmonitor* monitor, GLFWvidmode* mode); 85 | GLFWbool _glfwGetGammaRampNull(_GLFWmonitor* monitor, GLFWgammaramp* ramp); 86 | void _glfwSetGammaRampNull(_GLFWmonitor* monitor, const GLFWgammaramp* ramp); 87 | 88 | GLFWbool _glfwCreateWindowNull(_GLFWwindow* window, const _GLFWwndconfig* wndconfig, const _GLFWctxconfig* ctxconfig, const _GLFWfbconfig* fbconfig); 89 | void _glfwDestroyWindowNull(_GLFWwindow* window); 90 | void _glfwSetWindowTitleNull(_GLFWwindow* window, const char* title); 91 | void _glfwSetWindowIconNull(_GLFWwindow* window, int count, const GLFWimage* images); 92 | void _glfwSetWindowMonitorNull(_GLFWwindow* window, _GLFWmonitor* monitor, int xpos, int ypos, int width, int height, int refreshRate); 93 | void _glfwGetWindowPosNull(_GLFWwindow* window, int* xpos, int* ypos); 94 | void _glfwSetWindowPosNull(_GLFWwindow* window, int xpos, int ypos); 95 | void _glfwGetWindowSizeNull(_GLFWwindow* window, int* width, int* height); 96 | void _glfwSetWindowSizeNull(_GLFWwindow* window, int width, int height); 97 | void _glfwSetWindowSizeLimitsNull(_GLFWwindow* window, int minwidth, int minheight, int maxwidth, int maxheight); 98 | void _glfwSetWindowAspectRatioNull(_GLFWwindow* window, int n, int d); 99 | void _glfwGetFramebufferSizeNull(_GLFWwindow* window, int* width, int* height); 100 | void _glfwGetWindowFrameSizeNull(_GLFWwindow* window, int* left, int* top, int* right, int* bottom); 101 | void _glfwGetWindowContentScaleNull(_GLFWwindow* window, float* xscale, float* yscale); 102 | void _glfwIconifyWindowNull(_GLFWwindow* window); 103 | void _glfwRestoreWindowNull(_GLFWwindow* window); 104 | void _glfwMaximizeWindowNull(_GLFWwindow* window); 105 | GLFWbool _glfwWindowMaximizedNull(_GLFWwindow* window); 106 | GLFWbool _glfwWindowHoveredNull(_GLFWwindow* window); 107 | GLFWbool _glfwFramebufferTransparentNull(_GLFWwindow* window); 108 | void _glfwSetWindowResizableNull(_GLFWwindow* window, GLFWbool enabled); 109 | void _glfwSetWindowDecoratedNull(_GLFWwindow* window, GLFWbool enabled); 110 | void _glfwSetWindowFloatingNull(_GLFWwindow* window, GLFWbool enabled); 111 | void _glfwSetWindowMousePassthroughNull(_GLFWwindow* window, GLFWbool enabled); 112 | float _glfwGetWindowOpacityNull(_GLFWwindow* window); 113 | void _glfwSetWindowOpacityNull(_GLFWwindow* window, float opacity); 114 | void _glfwSetRawMouseMotionNull(_GLFWwindow *window, GLFWbool enabled); 115 | GLFWbool _glfwRawMouseMotionSupportedNull(void); 116 | void _glfwShowWindowNull(_GLFWwindow* window); 117 | void _glfwRequestWindowAttentionNull(_GLFWwindow* window); 118 | void _glfwRequestWindowAttentionNull(_GLFWwindow* window); 119 | void _glfwHideWindowNull(_GLFWwindow* window); 120 | void _glfwFocusWindowNull(_GLFWwindow* window); 121 | GLFWbool _glfwWindowFocusedNull(_GLFWwindow* window); 122 | GLFWbool _glfwWindowIconifiedNull(_GLFWwindow* window); 123 | GLFWbool _glfwWindowVisibleNull(_GLFWwindow* window); 124 | void _glfwPollEventsNull(void); 125 | void _glfwWaitEventsNull(void); 126 | void _glfwWaitEventsTimeoutNull(double timeout); 127 | void _glfwPostEmptyEventNull(void); 128 | void _glfwGetCursorPosNull(_GLFWwindow* window, double* xpos, double* ypos); 129 | void _glfwSetCursorPosNull(_GLFWwindow* window, double x, double y); 130 | void _glfwSetCursorModeNull(_GLFWwindow* window, int mode); 131 | GLFWbool _glfwCreateCursorNull(_GLFWcursor* cursor, const GLFWimage* image, int xhot, int yhot); 132 | GLFWbool _glfwCreateStandardCursorNull(_GLFWcursor* cursor, int shape); 133 | void _glfwDestroyCursorNull(_GLFWcursor* cursor); 134 | void _glfwSetCursorNull(_GLFWwindow* window, _GLFWcursor* cursor); 135 | void _glfwSetClipboardStringNull(const char* string); 136 | const char* _glfwGetClipboardStringNull(void); 137 | const char* _glfwGetScancodeNameNull(int scancode); 138 | int _glfwGetKeyScancodeNull(int key); 139 | 140 | EGLenum _glfwGetEGLPlatformNull(EGLint** attribs); 141 | EGLNativeDisplayType _glfwGetEGLNativeDisplayNull(void); 142 | EGLNativeWindowType _glfwGetEGLNativeWindowNull(_GLFWwindow* window); 143 | 144 | void _glfwGetRequiredInstanceExtensionsNull(char** extensions); 145 | GLFWbool _glfwGetPhysicalDevicePresentationSupportNull(VkInstance instance, VkPhysicalDevice device, uint32_t queuefamily); 146 | VkResult _glfwCreateWindowSurfaceNull(VkInstance instance, _GLFWwindow* window, const VkAllocationCallbacks* allocator, VkSurfaceKHR* surface); 147 | 148 | void _glfwPollMonitorsNull(void); 149 | 150 | -------------------------------------------------------------------------------- /third-party/glfw/platform.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | // These construct a string literal from individual numeric constants 33 | #define _GLFW_CONCAT_VERSION(m, n, r) #m "." #n "." #r 34 | #define _GLFW_MAKE_VERSION(m, n, r) _GLFW_CONCAT_VERSION(m, n, r) 35 | 36 | ////////////////////////////////////////////////////////////////////////// 37 | ////// GLFW internal API ////// 38 | ////////////////////////////////////////////////////////////////////////// 39 | 40 | static const struct 41 | { 42 | int ID; 43 | GLFWbool (*connect)(int,_GLFWplatform*); 44 | } supportedPlatforms[] = 45 | { 46 | #if defined(_GLFW_WIN32) 47 | { GLFW_PLATFORM_WIN32, _glfwConnectWin32 }, 48 | #endif 49 | #if defined(_GLFW_COCOA) 50 | { GLFW_PLATFORM_COCOA, _glfwConnectCocoa }, 51 | #endif 52 | #if defined(_GLFW_X11) 53 | { GLFW_PLATFORM_X11, _glfwConnectX11 }, 54 | #endif 55 | #if defined(_GLFW_WAYLAND) 56 | { GLFW_PLATFORM_WAYLAND, _glfwConnectWayland }, 57 | #endif 58 | }; 59 | 60 | GLFWbool _glfwSelectPlatform(int desiredID, _GLFWplatform* platform) 61 | { 62 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 63 | size_t i; 64 | 65 | if (desiredID != GLFW_ANY_PLATFORM && 66 | desiredID != GLFW_PLATFORM_WIN32 && 67 | desiredID != GLFW_PLATFORM_COCOA && 68 | desiredID != GLFW_PLATFORM_WAYLAND && 69 | desiredID != GLFW_PLATFORM_X11 && 70 | desiredID != GLFW_PLATFORM_NULL) 71 | { 72 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", desiredID); 73 | return GLFW_FALSE; 74 | } 75 | 76 | // Only allow the Null platform if specifically requested 77 | if (desiredID == GLFW_PLATFORM_NULL) 78 | return _glfwConnectNull(desiredID, platform); 79 | else if (count == 0) 80 | { 81 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "This binary only supports the Null platform"); 82 | return GLFW_FALSE; 83 | } 84 | 85 | if (desiredID == GLFW_ANY_PLATFORM) 86 | { 87 | // If there is exactly one platform available for auto-selection, let it emit the 88 | // error on failure as the platform-specific error description may be more helpful 89 | if (count == 1) 90 | return supportedPlatforms[0].connect(supportedPlatforms[0].ID, platform); 91 | 92 | for (i = 0; i < count; i++) 93 | { 94 | if (supportedPlatforms[i].connect(desiredID, platform)) 95 | return GLFW_TRUE; 96 | } 97 | 98 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "Failed to detect any supported platform"); 99 | } 100 | else 101 | { 102 | for (i = 0; i < count; i++) 103 | { 104 | if (supportedPlatforms[i].ID == desiredID) 105 | return supportedPlatforms[i].connect(desiredID, platform); 106 | } 107 | 108 | _glfwInputError(GLFW_PLATFORM_UNAVAILABLE, "The requested platform is not supported"); 109 | } 110 | 111 | return GLFW_FALSE; 112 | } 113 | 114 | ////////////////////////////////////////////////////////////////////////// 115 | ////// GLFW public API ////// 116 | ////////////////////////////////////////////////////////////////////////// 117 | 118 | GLFWAPI int glfwGetPlatform(void) 119 | { 120 | _GLFW_REQUIRE_INIT_OR_RETURN(0); 121 | return _glfw.platform.platformID; 122 | } 123 | 124 | GLFWAPI int glfwPlatformSupported(int platformID) 125 | { 126 | const size_t count = sizeof(supportedPlatforms) / sizeof(supportedPlatforms[0]); 127 | size_t i; 128 | 129 | if (platformID != GLFW_PLATFORM_WIN32 && 130 | platformID != GLFW_PLATFORM_COCOA && 131 | platformID != GLFW_PLATFORM_WAYLAND && 132 | platformID != GLFW_PLATFORM_X11 && 133 | platformID != GLFW_PLATFORM_NULL) 134 | { 135 | _glfwInputError(GLFW_INVALID_ENUM, "Invalid platform ID 0x%08X", platformID); 136 | return GLFW_FALSE; 137 | } 138 | 139 | if (platformID == GLFW_PLATFORM_NULL) 140 | return GLFW_TRUE; 141 | 142 | for (i = 0; i < count; i++) 143 | { 144 | if (platformID == supportedPlatforms[i].ID) 145 | return GLFW_TRUE; 146 | } 147 | 148 | return GLFW_FALSE; 149 | } 150 | 151 | GLFWAPI const char* glfwGetVersionString(void) 152 | { 153 | return _GLFW_MAKE_VERSION(GLFW_VERSION_MAJOR, 154 | GLFW_VERSION_MINOR, 155 | GLFW_VERSION_REVISION) 156 | #if defined(_GLFW_WIN32) 157 | " Win32 WGL" 158 | #endif 159 | #if defined(_GLFW_COCOA) 160 | " Cocoa NSGL" 161 | #endif 162 | #if defined(_GLFW_WAYLAND) 163 | " Wayland" 164 | #endif 165 | #if defined(_GLFW_X11) 166 | " X11 GLX" 167 | #endif 168 | " Null" 169 | " EGL" 170 | " OSMesa" 171 | #if defined(__MINGW64_VERSION_MAJOR) 172 | " MinGW-w64" 173 | #elif defined(__MINGW32__) 174 | " MinGW" 175 | #elif defined(_MSC_VER) 176 | " VisualC" 177 | #endif 178 | #if defined(_GLFW_USE_HYBRID_HPG) || defined(_GLFW_USE_OPTIMUS_HPG) 179 | " hybrid-GPU" 180 | #endif 181 | #if defined(_POSIX_MONOTONIC_CLOCK) 182 | " monotonic" 183 | #endif 184 | #if defined(_GLFW_BUILD_DLL) 185 | #if defined(_WIN32) 186 | " DLL" 187 | #elif defined(__APPLE__) 188 | " dynamic" 189 | #else 190 | " shared" 191 | #endif 192 | #endif 193 | ; 194 | } 195 | 196 | -------------------------------------------------------------------------------- /third-party/glfw/platform.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #if defined(GLFW_BUILD_WIN32_TIMER) || \ 29 | defined(GLFW_BUILD_WIN32_MODULE) || \ 30 | defined(GLFW_BUILD_WIN32_THREAD) || \ 31 | defined(GLFW_BUILD_COCOA_TIMER) || \ 32 | defined(GLFW_BUILD_POSIX_TIMER) || \ 33 | defined(GLFW_BUILD_POSIX_MODULE) || \ 34 | defined(GLFW_BUILD_POSIX_THREAD) || \ 35 | defined(GLFW_BUILD_POSIX_POLL) || \ 36 | defined(GLFW_BUILD_LINUX_JOYSTICK) 37 | #error "You must not define these; define zero or more _GLFW_ macros instead" 38 | #endif 39 | 40 | #include "null_platform.h" 41 | 42 | #if defined(_GLFW_WIN32) 43 | #include "win32_platform.h" 44 | #else 45 | #define GLFW_WIN32_WINDOW_STATE 46 | #define GLFW_WIN32_MONITOR_STATE 47 | #define GLFW_WIN32_CURSOR_STATE 48 | #define GLFW_WIN32_LIBRARY_WINDOW_STATE 49 | #define GLFW_WGL_CONTEXT_STATE 50 | #define GLFW_WGL_LIBRARY_CONTEXT_STATE 51 | #endif 52 | 53 | #if defined(_GLFW_COCOA) 54 | #include "cocoa_platform.h" 55 | #else 56 | #define GLFW_COCOA_WINDOW_STATE 57 | #define GLFW_COCOA_MONITOR_STATE 58 | #define GLFW_COCOA_CURSOR_STATE 59 | #define GLFW_COCOA_LIBRARY_WINDOW_STATE 60 | #define GLFW_NSGL_CONTEXT_STATE 61 | #define GLFW_NSGL_LIBRARY_CONTEXT_STATE 62 | #endif 63 | 64 | #if defined(_GLFW_WAYLAND) 65 | #include "wl_platform.h" 66 | #else 67 | #define GLFW_WAYLAND_WINDOW_STATE 68 | #define GLFW_WAYLAND_MONITOR_STATE 69 | #define GLFW_WAYLAND_CURSOR_STATE 70 | #define GLFW_WAYLAND_LIBRARY_WINDOW_STATE 71 | #endif 72 | 73 | #if defined(_GLFW_X11) 74 | #include "x11_platform.h" 75 | #else 76 | #define GLFW_X11_WINDOW_STATE 77 | #define GLFW_X11_MONITOR_STATE 78 | #define GLFW_X11_CURSOR_STATE 79 | #define GLFW_X11_LIBRARY_WINDOW_STATE 80 | #define GLFW_GLX_CONTEXT_STATE 81 | #define GLFW_GLX_LIBRARY_CONTEXT_STATE 82 | #endif 83 | 84 | #include "null_joystick.h" 85 | 86 | #if defined(_GLFW_WIN32) 87 | #include "win32_joystick.h" 88 | #else 89 | #define GLFW_WIN32_JOYSTICK_STATE 90 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 91 | #endif 92 | 93 | #if defined(_GLFW_COCOA) 94 | #include "cocoa_joystick.h" 95 | #else 96 | #define GLFW_COCOA_JOYSTICK_STATE 97 | #define GLFW_COCOA_LIBRARY_JOYSTICK_STATE 98 | #endif 99 | 100 | #if (defined(_GLFW_X11) || defined(_GLFW_WAYLAND)) && defined(__linux__) 101 | #define GLFW_BUILD_LINUX_JOYSTICK 102 | #endif 103 | 104 | #if defined(GLFW_BUILD_LINUX_JOYSTICK) 105 | #include "linux_joystick.h" 106 | #else 107 | #define GLFW_LINUX_JOYSTICK_STATE 108 | #define GLFW_LINUX_LIBRARY_JOYSTICK_STATE 109 | #endif 110 | 111 | #define GLFW_PLATFORM_WINDOW_STATE \ 112 | GLFW_WIN32_WINDOW_STATE \ 113 | GLFW_COCOA_WINDOW_STATE \ 114 | GLFW_WAYLAND_WINDOW_STATE \ 115 | GLFW_X11_WINDOW_STATE \ 116 | GLFW_NULL_WINDOW_STATE \ 117 | 118 | #define GLFW_PLATFORM_MONITOR_STATE \ 119 | GLFW_WIN32_MONITOR_STATE \ 120 | GLFW_COCOA_MONITOR_STATE \ 121 | GLFW_WAYLAND_MONITOR_STATE \ 122 | GLFW_X11_MONITOR_STATE \ 123 | GLFW_NULL_MONITOR_STATE \ 124 | 125 | #define GLFW_PLATFORM_CURSOR_STATE \ 126 | GLFW_WIN32_CURSOR_STATE \ 127 | GLFW_COCOA_CURSOR_STATE \ 128 | GLFW_WAYLAND_CURSOR_STATE \ 129 | GLFW_X11_CURSOR_STATE \ 130 | GLFW_NULL_CURSOR_STATE \ 131 | 132 | #define GLFW_PLATFORM_JOYSTICK_STATE \ 133 | GLFW_WIN32_JOYSTICK_STATE \ 134 | GLFW_COCOA_JOYSTICK_STATE \ 135 | GLFW_LINUX_JOYSTICK_STATE 136 | 137 | #define GLFW_PLATFORM_LIBRARY_WINDOW_STATE \ 138 | GLFW_WIN32_LIBRARY_WINDOW_STATE \ 139 | GLFW_COCOA_LIBRARY_WINDOW_STATE \ 140 | GLFW_WAYLAND_LIBRARY_WINDOW_STATE \ 141 | GLFW_X11_LIBRARY_WINDOW_STATE \ 142 | GLFW_NULL_LIBRARY_WINDOW_STATE \ 143 | 144 | #define GLFW_PLATFORM_LIBRARY_JOYSTICK_STATE \ 145 | GLFW_WIN32_LIBRARY_JOYSTICK_STATE \ 146 | GLFW_COCOA_LIBRARY_JOYSTICK_STATE \ 147 | GLFW_LINUX_LIBRARY_JOYSTICK_STATE 148 | 149 | #define GLFW_PLATFORM_CONTEXT_STATE \ 150 | GLFW_WGL_CONTEXT_STATE \ 151 | GLFW_NSGL_CONTEXT_STATE \ 152 | GLFW_GLX_CONTEXT_STATE 153 | 154 | #define GLFW_PLATFORM_LIBRARY_CONTEXT_STATE \ 155 | GLFW_WGL_LIBRARY_CONTEXT_STATE \ 156 | GLFW_NSGL_LIBRARY_CONTEXT_STATE \ 157 | GLFW_GLX_LIBRARY_CONTEXT_STATE 158 | 159 | #if defined(_WIN32) 160 | #define GLFW_BUILD_WIN32_THREAD 161 | #else 162 | #define GLFW_BUILD_POSIX_THREAD 163 | #endif 164 | 165 | #if defined(GLFW_BUILD_WIN32_THREAD) 166 | #include "win32_thread.h" 167 | #define GLFW_PLATFORM_TLS_STATE GLFW_WIN32_TLS_STATE 168 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_WIN32_MUTEX_STATE 169 | #elif defined(GLFW_BUILD_POSIX_THREAD) 170 | #include "posix_thread.h" 171 | #define GLFW_PLATFORM_TLS_STATE GLFW_POSIX_TLS_STATE 172 | #define GLFW_PLATFORM_MUTEX_STATE GLFW_POSIX_MUTEX_STATE 173 | #endif 174 | 175 | #if defined(_WIN32) 176 | #define GLFW_BUILD_WIN32_TIMER 177 | #elif defined(__APPLE__) 178 | #define GLFW_BUILD_COCOA_TIMER 179 | #else 180 | #define GLFW_BUILD_POSIX_TIMER 181 | #endif 182 | 183 | #if defined(GLFW_BUILD_WIN32_TIMER) 184 | #include "win32_time.h" 185 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_WIN32_LIBRARY_TIMER_STATE 186 | #elif defined(GLFW_BUILD_COCOA_TIMER) 187 | #include "cocoa_time.h" 188 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_COCOA_LIBRARY_TIMER_STATE 189 | #elif defined(GLFW_BUILD_POSIX_TIMER) 190 | #include "posix_time.h" 191 | #define GLFW_PLATFORM_LIBRARY_TIMER_STATE GLFW_POSIX_LIBRARY_TIMER_STATE 192 | #endif 193 | 194 | #if defined(_WIN32) 195 | #define GLFW_BUILD_WIN32_MODULE 196 | #else 197 | #define GLFW_BUILD_POSIX_MODULE 198 | #endif 199 | 200 | #if defined(_GLFW_WAYLAND) || defined(_GLFW_X11) 201 | #define GLFW_BUILD_POSIX_POLL 202 | #endif 203 | 204 | -------------------------------------------------------------------------------- /third-party/glfw/posix_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #if defined(GLFW_BUILD_POSIX_MODULE) 32 | 33 | #include 34 | 35 | ////////////////////////////////////////////////////////////////////////// 36 | ////// GLFW platform API ////// 37 | ////////////////////////////////////////////////////////////////////////// 38 | 39 | void* _glfwPlatformLoadModule(const char* path) 40 | { 41 | return dlopen(path, RTLD_LAZY | RTLD_LOCAL); 42 | } 43 | 44 | void _glfwPlatformFreeModule(void* module) 45 | { 46 | dlclose(module); 47 | } 48 | 49 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 50 | { 51 | return dlsym(module, name); 52 | } 53 | 54 | #endif // GLFW_BUILD_POSIX_MODULE 55 | 56 | -------------------------------------------------------------------------------- /third-party/glfw/posix_poll.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #define _GNU_SOURCE 30 | 31 | #include "internal.h" 32 | 33 | #if defined(GLFW_BUILD_POSIX_POLL) 34 | 35 | #include 36 | #include 37 | #include 38 | 39 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout) 40 | { 41 | for (;;) 42 | { 43 | if (timeout) 44 | { 45 | const uint64_t base = _glfwPlatformGetTimerValue(); 46 | 47 | #if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__) 48 | const time_t seconds = (time_t) *timeout; 49 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 50 | const struct timespec ts = { seconds, nanoseconds }; 51 | const int result = ppoll(fds, count, &ts, NULL); 52 | #elif defined(__NetBSD__) 53 | const time_t seconds = (time_t) *timeout; 54 | const long nanoseconds = (long) ((*timeout - seconds) * 1e9); 55 | const struct timespec ts = { seconds, nanoseconds }; 56 | const int result = pollts(fds, count, &ts, NULL); 57 | #else 58 | const int milliseconds = (int) (*timeout * 1e3); 59 | const int result = poll(fds, count, milliseconds); 60 | #endif 61 | const int error = errno; // clock_gettime may overwrite our error 62 | 63 | *timeout -= (_glfwPlatformGetTimerValue() - base) / 64 | (double) _glfwPlatformGetTimerFrequency(); 65 | 66 | if (result > 0) 67 | return GLFW_TRUE; 68 | else if (result == -1 && error != EINTR && error != EAGAIN) 69 | return GLFW_FALSE; 70 | else if (*timeout <= 0.0) 71 | return GLFW_FALSE; 72 | } 73 | else 74 | { 75 | const int result = poll(fds, count, -1); 76 | if (result > 0) 77 | return GLFW_TRUE; 78 | else if (result == -1 && errno != EINTR && errno != EAGAIN) 79 | return GLFW_FALSE; 80 | } 81 | } 82 | } 83 | 84 | #endif // GLFW_BUILD_POSIX_POLL 85 | 86 | -------------------------------------------------------------------------------- /third-party/glfw/posix_poll.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2022 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // It is fine to use C99 in this file because it will not be built with VS 27 | //======================================================================== 28 | 29 | #include 30 | 31 | GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout); 32 | 33 | -------------------------------------------------------------------------------- /third-party/glfw/posix_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_POSIX_THREAD) 33 | 34 | #include 35 | #include 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW platform API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 43 | { 44 | assert(tls->posix.allocated == GLFW_FALSE); 45 | 46 | if (pthread_key_create(&tls->posix.key, NULL) != 0) 47 | { 48 | _glfwInputError(GLFW_PLATFORM_ERROR, 49 | "POSIX: Failed to create context TLS"); 50 | return GLFW_FALSE; 51 | } 52 | 53 | tls->posix.allocated = GLFW_TRUE; 54 | return GLFW_TRUE; 55 | } 56 | 57 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 58 | { 59 | if (tls->posix.allocated) 60 | pthread_key_delete(tls->posix.key); 61 | memset(tls, 0, sizeof(_GLFWtls)); 62 | } 63 | 64 | void* _glfwPlatformGetTls(_GLFWtls* tls) 65 | { 66 | assert(tls->posix.allocated == GLFW_TRUE); 67 | return pthread_getspecific(tls->posix.key); 68 | } 69 | 70 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 71 | { 72 | assert(tls->posix.allocated == GLFW_TRUE); 73 | pthread_setspecific(tls->posix.key, value); 74 | } 75 | 76 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 77 | { 78 | assert(mutex->posix.allocated == GLFW_FALSE); 79 | 80 | if (pthread_mutex_init(&mutex->posix.handle, NULL) != 0) 81 | { 82 | _glfwInputError(GLFW_PLATFORM_ERROR, "POSIX: Failed to create mutex"); 83 | return GLFW_FALSE; 84 | } 85 | 86 | return mutex->posix.allocated = GLFW_TRUE; 87 | } 88 | 89 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 90 | { 91 | if (mutex->posix.allocated) 92 | pthread_mutex_destroy(&mutex->posix.handle); 93 | memset(mutex, 0, sizeof(_GLFWmutex)); 94 | } 95 | 96 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 97 | { 98 | assert(mutex->posix.allocated == GLFW_TRUE); 99 | pthread_mutex_lock(&mutex->posix.handle); 100 | } 101 | 102 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 103 | { 104 | assert(mutex->posix.allocated == GLFW_TRUE); 105 | pthread_mutex_unlock(&mutex->posix.handle); 106 | } 107 | 108 | #endif // GLFW_BUILD_POSIX_THREAD 109 | 110 | -------------------------------------------------------------------------------- /third-party/glfw/posix_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_POSIX_TLS_STATE _GLFWtlsPOSIX posix; 31 | #define GLFW_POSIX_MUTEX_STATE _GLFWmutexPOSIX posix; 32 | 33 | 34 | // POSIX-specific thread local storage data 35 | // 36 | typedef struct _GLFWtlsPOSIX 37 | { 38 | GLFWbool allocated; 39 | pthread_key_t key; 40 | } _GLFWtlsPOSIX; 41 | 42 | // POSIX-specific mutex data 43 | // 44 | typedef struct _GLFWmutexPOSIX 45 | { 46 | GLFWbool allocated; 47 | pthread_mutex_t handle; 48 | } _GLFWmutexPOSIX; 49 | 50 | -------------------------------------------------------------------------------- /third-party/glfw/posix_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // It is fine to use C99 in this file because it will not be built with VS 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_POSIX_TIMER) 33 | 34 | #include 35 | #include 36 | 37 | 38 | ////////////////////////////////////////////////////////////////////////// 39 | ////// GLFW platform API ////// 40 | ////////////////////////////////////////////////////////////////////////// 41 | 42 | void _glfwPlatformInitTimer(void) 43 | { 44 | _glfw.timer.posix.clock = CLOCK_REALTIME; 45 | _glfw.timer.posix.frequency = 1000000000; 46 | 47 | #if defined(_POSIX_MONOTONIC_CLOCK) 48 | struct timespec ts; 49 | if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) 50 | _glfw.timer.posix.clock = CLOCK_MONOTONIC; 51 | #endif 52 | } 53 | 54 | uint64_t _glfwPlatformGetTimerValue(void) 55 | { 56 | struct timespec ts; 57 | clock_gettime(_glfw.timer.posix.clock, &ts); 58 | return (uint64_t) ts.tv_sec * _glfw.timer.posix.frequency + (uint64_t) ts.tv_nsec; 59 | } 60 | 61 | uint64_t _glfwPlatformGetTimerFrequency(void) 62 | { 63 | return _glfw.timer.posix.frequency; 64 | } 65 | 66 | #endif // GLFW_BUILD_POSIX_TIMER 67 | 68 | -------------------------------------------------------------------------------- /third-party/glfw/posix_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 POSIX - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #define GLFW_POSIX_LIBRARY_TIMER_STATE _GLFWtimerPOSIX posix; 29 | 30 | #include 31 | #include 32 | 33 | 34 | // POSIX-specific global timer data 35 | // 36 | typedef struct _GLFWtimerPOSIX 37 | { 38 | clockid_t clock; 39 | uint64_t frequency; 40 | } _GLFWtimerPOSIX; 41 | 42 | -------------------------------------------------------------------------------- /third-party/glfw/vulkan.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2018 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #define _GLFW_FIND_LOADER 1 37 | #define _GLFW_REQUIRE_LOADER 2 38 | 39 | 40 | ////////////////////////////////////////////////////////////////////////// 41 | ////// GLFW internal API ////// 42 | ////////////////////////////////////////////////////////////////////////// 43 | 44 | GLFWbool _glfwInitVulkan(int mode) 45 | { 46 | VkResult err; 47 | VkExtensionProperties* ep; 48 | PFN_vkEnumerateInstanceExtensionProperties vkEnumerateInstanceExtensionProperties; 49 | uint32_t i, count; 50 | 51 | if (_glfw.vk.available) 52 | return GLFW_TRUE; 53 | 54 | if (_glfw.hints.init.vulkanLoader) 55 | _glfw.vk.GetInstanceProcAddr = _glfw.hints.init.vulkanLoader; 56 | else 57 | { 58 | #if defined(_GLFW_VULKAN_LIBRARY) 59 | _glfw.vk.handle = _glfwPlatformLoadModule(_GLFW_VULKAN_LIBRARY); 60 | #elif defined(_GLFW_WIN32) 61 | _glfw.vk.handle = _glfwPlatformLoadModule("vulkan-1.dll"); 62 | #elif defined(_GLFW_COCOA) 63 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.1.dylib"); 64 | if (!_glfw.vk.handle) 65 | _glfw.vk.handle = _glfwLoadLocalVulkanLoaderCocoa(); 66 | #elif defined(__OpenBSD__) || defined(__NetBSD__) 67 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so"); 68 | #else 69 | _glfw.vk.handle = _glfwPlatformLoadModule("libvulkan.so.1"); 70 | #endif 71 | if (!_glfw.vk.handle) 72 | { 73 | if (mode == _GLFW_REQUIRE_LOADER) 74 | _glfwInputError(GLFW_API_UNAVAILABLE, "Vulkan: Loader not found"); 75 | 76 | return GLFW_FALSE; 77 | } 78 | 79 | _glfw.vk.GetInstanceProcAddr = (PFN_vkGetInstanceProcAddr) 80 | _glfwPlatformGetModuleSymbol(_glfw.vk.handle, "vkGetInstanceProcAddr"); 81 | if (!_glfw.vk.GetInstanceProcAddr) 82 | { 83 | _glfwInputError(GLFW_API_UNAVAILABLE, 84 | "Vulkan: Loader does not export vkGetInstanceProcAddr"); 85 | 86 | _glfwTerminateVulkan(); 87 | return GLFW_FALSE; 88 | } 89 | } 90 | 91 | vkEnumerateInstanceExtensionProperties = (PFN_vkEnumerateInstanceExtensionProperties) 92 | vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceExtensionProperties"); 93 | if (!vkEnumerateInstanceExtensionProperties) 94 | { 95 | _glfwInputError(GLFW_API_UNAVAILABLE, 96 | "Vulkan: Failed to retrieve vkEnumerateInstanceExtensionProperties"); 97 | 98 | _glfwTerminateVulkan(); 99 | return GLFW_FALSE; 100 | } 101 | 102 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, NULL); 103 | if (err) 104 | { 105 | // NOTE: This happens on systems with a loader but without any Vulkan ICD 106 | if (mode == _GLFW_REQUIRE_LOADER) 107 | { 108 | _glfwInputError(GLFW_API_UNAVAILABLE, 109 | "Vulkan: Failed to query instance extension count: %s", 110 | _glfwGetVulkanResultString(err)); 111 | } 112 | 113 | _glfwTerminateVulkan(); 114 | return GLFW_FALSE; 115 | } 116 | 117 | ep = _glfw_calloc(count, sizeof(VkExtensionProperties)); 118 | 119 | err = vkEnumerateInstanceExtensionProperties(NULL, &count, ep); 120 | if (err) 121 | { 122 | _glfwInputError(GLFW_API_UNAVAILABLE, 123 | "Vulkan: Failed to query instance extensions: %s", 124 | _glfwGetVulkanResultString(err)); 125 | 126 | _glfw_free(ep); 127 | _glfwTerminateVulkan(); 128 | return GLFW_FALSE; 129 | } 130 | 131 | for (i = 0; i < count; i++) 132 | { 133 | if (strcmp(ep[i].extensionName, "VK_KHR_surface") == 0) 134 | _glfw.vk.KHR_surface = GLFW_TRUE; 135 | else if (strcmp(ep[i].extensionName, "VK_KHR_win32_surface") == 0) 136 | _glfw.vk.KHR_win32_surface = GLFW_TRUE; 137 | else if (strcmp(ep[i].extensionName, "VK_MVK_macos_surface") == 0) 138 | _glfw.vk.MVK_macos_surface = GLFW_TRUE; 139 | else if (strcmp(ep[i].extensionName, "VK_EXT_metal_surface") == 0) 140 | _glfw.vk.EXT_metal_surface = GLFW_TRUE; 141 | else if (strcmp(ep[i].extensionName, "VK_KHR_xlib_surface") == 0) 142 | _glfw.vk.KHR_xlib_surface = GLFW_TRUE; 143 | else if (strcmp(ep[i].extensionName, "VK_KHR_xcb_surface") == 0) 144 | _glfw.vk.KHR_xcb_surface = GLFW_TRUE; 145 | else if (strcmp(ep[i].extensionName, "VK_KHR_wayland_surface") == 0) 146 | _glfw.vk.KHR_wayland_surface = GLFW_TRUE; 147 | } 148 | 149 | _glfw_free(ep); 150 | 151 | _glfw.vk.available = GLFW_TRUE; 152 | 153 | _glfw.platform.getRequiredInstanceExtensions(_glfw.vk.extensions); 154 | 155 | return GLFW_TRUE; 156 | } 157 | 158 | void _glfwTerminateVulkan(void) 159 | { 160 | if (_glfw.vk.handle) 161 | _glfwPlatformFreeModule(_glfw.vk.handle); 162 | } 163 | 164 | const char* _glfwGetVulkanResultString(VkResult result) 165 | { 166 | switch (result) 167 | { 168 | case VK_SUCCESS: 169 | return "Success"; 170 | case VK_NOT_READY: 171 | return "A fence or query has not yet completed"; 172 | case VK_TIMEOUT: 173 | return "A wait operation has not completed in the specified time"; 174 | case VK_EVENT_SET: 175 | return "An event is signaled"; 176 | case VK_EVENT_RESET: 177 | return "An event is unsignaled"; 178 | case VK_INCOMPLETE: 179 | return "A return array was too small for the result"; 180 | case VK_ERROR_OUT_OF_HOST_MEMORY: 181 | return "A host memory allocation has failed"; 182 | case VK_ERROR_OUT_OF_DEVICE_MEMORY: 183 | return "A device memory allocation has failed"; 184 | case VK_ERROR_INITIALIZATION_FAILED: 185 | return "Initialization of an object could not be completed for implementation-specific reasons"; 186 | case VK_ERROR_DEVICE_LOST: 187 | return "The logical or physical device has been lost"; 188 | case VK_ERROR_MEMORY_MAP_FAILED: 189 | return "Mapping of a memory object has failed"; 190 | case VK_ERROR_LAYER_NOT_PRESENT: 191 | return "A requested layer is not present or could not be loaded"; 192 | case VK_ERROR_EXTENSION_NOT_PRESENT: 193 | return "A requested extension is not supported"; 194 | case VK_ERROR_FEATURE_NOT_PRESENT: 195 | return "A requested feature is not supported"; 196 | case VK_ERROR_INCOMPATIBLE_DRIVER: 197 | return "The requested version of Vulkan is not supported by the driver or is otherwise incompatible"; 198 | case VK_ERROR_TOO_MANY_OBJECTS: 199 | return "Too many objects of the type have already been created"; 200 | case VK_ERROR_FORMAT_NOT_SUPPORTED: 201 | return "A requested format is not supported on this device"; 202 | case VK_ERROR_SURFACE_LOST_KHR: 203 | return "A surface is no longer available"; 204 | case VK_SUBOPTIMAL_KHR: 205 | return "A swapchain no longer matches the surface properties exactly, but can still be used"; 206 | case VK_ERROR_OUT_OF_DATE_KHR: 207 | return "A surface has changed in such a way that it is no longer compatible with the swapchain"; 208 | case VK_ERROR_INCOMPATIBLE_DISPLAY_KHR: 209 | return "The display used by a swapchain does not use the same presentable image layout"; 210 | case VK_ERROR_NATIVE_WINDOW_IN_USE_KHR: 211 | return "The requested window is already connected to a VkSurfaceKHR, or to some other non-Vulkan API"; 212 | case VK_ERROR_VALIDATION_FAILED_EXT: 213 | return "A validation layer found an error"; 214 | default: 215 | return "ERROR: UNKNOWN VULKAN ERROR"; 216 | } 217 | } 218 | 219 | 220 | ////////////////////////////////////////////////////////////////////////// 221 | ////// GLFW public API ////// 222 | ////////////////////////////////////////////////////////////////////////// 223 | 224 | GLFWAPI int glfwVulkanSupported(void) 225 | { 226 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 227 | return _glfwInitVulkan(_GLFW_FIND_LOADER); 228 | } 229 | 230 | GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count) 231 | { 232 | assert(count != NULL); 233 | 234 | *count = 0; 235 | 236 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 237 | 238 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 239 | return NULL; 240 | 241 | if (!_glfw.vk.extensions[0]) 242 | return NULL; 243 | 244 | *count = 2; 245 | return (const char**) _glfw.vk.extensions; 246 | } 247 | 248 | GLFWAPI GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, 249 | const char* procname) 250 | { 251 | GLFWvkproc proc; 252 | assert(procname != NULL); 253 | 254 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 255 | 256 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 257 | return NULL; 258 | 259 | // NOTE: Vulkan 1.0 and 1.1 vkGetInstanceProcAddr cannot return itself 260 | if (strcmp(procname, "vkGetInstanceProcAddr") == 0) 261 | return (GLFWvkproc) vkGetInstanceProcAddr; 262 | 263 | proc = (GLFWvkproc) vkGetInstanceProcAddr(instance, procname); 264 | if (!proc) 265 | { 266 | if (_glfw.vk.handle) 267 | proc = (GLFWvkproc) _glfwPlatformGetModuleSymbol(_glfw.vk.handle, procname); 268 | } 269 | 270 | return proc; 271 | } 272 | 273 | GLFWAPI int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, 274 | VkPhysicalDevice device, 275 | uint32_t queuefamily) 276 | { 277 | assert(instance != VK_NULL_HANDLE); 278 | assert(device != VK_NULL_HANDLE); 279 | 280 | _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); 281 | 282 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 283 | return GLFW_FALSE; 284 | 285 | if (!_glfw.vk.extensions[0]) 286 | { 287 | _glfwInputError(GLFW_API_UNAVAILABLE, 288 | "Vulkan: Window surface creation extensions not found"); 289 | return GLFW_FALSE; 290 | } 291 | 292 | return _glfw.platform.getPhysicalDevicePresentationSupport(instance, 293 | device, 294 | queuefamily); 295 | } 296 | 297 | GLFWAPI VkResult glfwCreateWindowSurface(VkInstance instance, 298 | GLFWwindow* handle, 299 | const VkAllocationCallbacks* allocator, 300 | VkSurfaceKHR* surface) 301 | { 302 | _GLFWwindow* window = (_GLFWwindow*) handle; 303 | assert(instance != VK_NULL_HANDLE); 304 | assert(window != NULL); 305 | assert(surface != NULL); 306 | 307 | *surface = VK_NULL_HANDLE; 308 | 309 | _GLFW_REQUIRE_INIT_OR_RETURN(VK_ERROR_INITIALIZATION_FAILED); 310 | 311 | if (!_glfwInitVulkan(_GLFW_REQUIRE_LOADER)) 312 | return VK_ERROR_INITIALIZATION_FAILED; 313 | 314 | if (!_glfw.vk.extensions[0]) 315 | { 316 | _glfwInputError(GLFW_API_UNAVAILABLE, 317 | "Vulkan: Window surface creation extensions not found"); 318 | return VK_ERROR_EXTENSION_NOT_PRESENT; 319 | } 320 | 321 | if (window->context.client != GLFW_NO_API) 322 | { 323 | _glfwInputError(GLFW_INVALID_VALUE, 324 | "Vulkan: Window surface creation requires the window to have the client API set to GLFW_NO_API"); 325 | return VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; 326 | } 327 | 328 | return _glfw.platform.createWindowSurface(instance, window, allocator, surface); 329 | } 330 | 331 | -------------------------------------------------------------------------------- /third-party/glfw/win32_joystick.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2006-2017 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_WIN32_JOYSTICK_STATE _GLFWjoystickWin32 win32; 28 | #define GLFW_WIN32_LIBRARY_JOYSTICK_STATE 29 | 30 | // Joystick element (axis, button or slider) 31 | // 32 | typedef struct _GLFWjoyobjectWin32 33 | { 34 | int offset; 35 | int type; 36 | } _GLFWjoyobjectWin32; 37 | 38 | // Win32-specific per-joystick data 39 | // 40 | typedef struct _GLFWjoystickWin32 41 | { 42 | _GLFWjoyobjectWin32* objects; 43 | int objectCount; 44 | IDirectInputDevice8W* device; 45 | DWORD index; 46 | GUID guid; 47 | } _GLFWjoystickWin32; 48 | 49 | void _glfwDetectJoystickConnectionWin32(void); 50 | void _glfwDetectJoystickDisconnectionWin32(void); 51 | 52 | -------------------------------------------------------------------------------- /third-party/glfw/win32_module.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2021 Camilla Löwy 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // Please use C89 style variable declarations in this file because VS 2010 27 | //======================================================================== 28 | 29 | #include "internal.h" 30 | 31 | #if defined(GLFW_BUILD_WIN32_MODULE) 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW platform API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | void* _glfwPlatformLoadModule(const char* path) 38 | { 39 | return LoadLibraryA(path); 40 | } 41 | 42 | void _glfwPlatformFreeModule(void* module) 43 | { 44 | FreeLibrary((HMODULE) module); 45 | } 46 | 47 | GLFWproc _glfwPlatformGetModuleSymbol(void* module, const char* name) 48 | { 49 | return (GLFWproc) GetProcAddress((HMODULE) module, name); 50 | } 51 | 52 | #endif // GLFW_BUILD_WIN32_MODULE 53 | 54 | -------------------------------------------------------------------------------- /third-party/glfw/win32_thread.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_WIN32_THREAD) 33 | 34 | #include 35 | 36 | 37 | ////////////////////////////////////////////////////////////////////////// 38 | ////// GLFW platform API ////// 39 | ////////////////////////////////////////////////////////////////////////// 40 | 41 | GLFWbool _glfwPlatformCreateTls(_GLFWtls* tls) 42 | { 43 | assert(tls->win32.allocated == GLFW_FALSE); 44 | 45 | tls->win32.index = TlsAlloc(); 46 | if (tls->win32.index == TLS_OUT_OF_INDEXES) 47 | { 48 | _glfwInputError(GLFW_PLATFORM_ERROR, "Win32: Failed to allocate TLS index"); 49 | return GLFW_FALSE; 50 | } 51 | 52 | tls->win32.allocated = GLFW_TRUE; 53 | return GLFW_TRUE; 54 | } 55 | 56 | void _glfwPlatformDestroyTls(_GLFWtls* tls) 57 | { 58 | if (tls->win32.allocated) 59 | TlsFree(tls->win32.index); 60 | memset(tls, 0, sizeof(_GLFWtls)); 61 | } 62 | 63 | void* _glfwPlatformGetTls(_GLFWtls* tls) 64 | { 65 | assert(tls->win32.allocated == GLFW_TRUE); 66 | return TlsGetValue(tls->win32.index); 67 | } 68 | 69 | void _glfwPlatformSetTls(_GLFWtls* tls, void* value) 70 | { 71 | assert(tls->win32.allocated == GLFW_TRUE); 72 | TlsSetValue(tls->win32.index, value); 73 | } 74 | 75 | GLFWbool _glfwPlatformCreateMutex(_GLFWmutex* mutex) 76 | { 77 | assert(mutex->win32.allocated == GLFW_FALSE); 78 | InitializeCriticalSection(&mutex->win32.section); 79 | return mutex->win32.allocated = GLFW_TRUE; 80 | } 81 | 82 | void _glfwPlatformDestroyMutex(_GLFWmutex* mutex) 83 | { 84 | if (mutex->win32.allocated) 85 | DeleteCriticalSection(&mutex->win32.section); 86 | memset(mutex, 0, sizeof(_GLFWmutex)); 87 | } 88 | 89 | void _glfwPlatformLockMutex(_GLFWmutex* mutex) 90 | { 91 | assert(mutex->win32.allocated == GLFW_TRUE); 92 | EnterCriticalSection(&mutex->win32.section); 93 | } 94 | 95 | void _glfwPlatformUnlockMutex(_GLFWmutex* mutex) 96 | { 97 | assert(mutex->win32.allocated == GLFW_TRUE); 98 | LeaveCriticalSection(&mutex->win32.section); 99 | } 100 | 101 | #endif // GLFW_BUILD_WIN32_THREAD 102 | 103 | -------------------------------------------------------------------------------- /third-party/glfw/win32_thread.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_TLS_STATE _GLFWtlsWin32 win32; 31 | #define GLFW_WIN32_MUTEX_STATE _GLFWmutexWin32 win32; 32 | 33 | // Win32-specific thread local storage data 34 | // 35 | typedef struct _GLFWtlsWin32 36 | { 37 | GLFWbool allocated; 38 | DWORD index; 39 | } _GLFWtlsWin32; 40 | 41 | // Win32-specific mutex data 42 | // 43 | typedef struct _GLFWmutexWin32 44 | { 45 | GLFWbool allocated; 46 | CRITICAL_SECTION section; 47 | } _GLFWmutexWin32; 48 | 49 | -------------------------------------------------------------------------------- /third-party/glfw/win32_time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | // Please use C89 style variable declarations in this file because VS 2010 28 | //======================================================================== 29 | 30 | #include "internal.h" 31 | 32 | #if defined(GLFW_BUILD_WIN32_TIMER) 33 | 34 | ////////////////////////////////////////////////////////////////////////// 35 | ////// GLFW platform API ////// 36 | ////////////////////////////////////////////////////////////////////////// 37 | 38 | void _glfwPlatformInitTimer(void) 39 | { 40 | QueryPerformanceFrequency((LARGE_INTEGER*) &_glfw.timer.win32.frequency); 41 | } 42 | 43 | uint64_t _glfwPlatformGetTimerValue(void) 44 | { 45 | uint64_t value; 46 | QueryPerformanceCounter((LARGE_INTEGER*) &value); 47 | return value; 48 | } 49 | 50 | uint64_t _glfwPlatformGetTimerFrequency(void) 51 | { 52 | return _glfw.timer.win32.frequency; 53 | } 54 | 55 | #endif // GLFW_BUILD_WIN32_TIMER 56 | 57 | -------------------------------------------------------------------------------- /third-party/glfw/win32_time.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Win32 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2017 Camilla Löwy 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include 29 | 30 | #define GLFW_WIN32_LIBRARY_TIMER_STATE _GLFWtimerWin32 win32; 31 | 32 | // Win32-specific global timer data 33 | // 34 | typedef struct _GLFWtimerWin32 35 | { 36 | uint64_t frequency; 37 | } _GLFWtimerWin32; 38 | 39 | -------------------------------------------------------------------------------- /third-party/glfw/xkb_unicode.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.4 Linux - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2014 Jonas Ådahl 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #define GLFW_INVALID_CODEPOINT 0xffffffffu 28 | 29 | uint32_t _glfwKeySym2Unicode(unsigned int keysym); 30 | 31 | -------------------------------------------------------------------------------- /third-party/imgui/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2024 Omar Cornut 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 | -------------------------------------------------------------------------------- /third-party/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // DEAR IMGUI COMPILE-TIME OPTIONS 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp file to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to clean your code of obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87+ disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This is automatically done by IMGUI_DISABLE_OBSOLETE_FUNCTIONS. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowIDStackToolWindow() will be empty. 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, IME). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | // May be convenient for some users to only explicitly include vanilla imgui.h and have extra stuff included. 54 | //#define IMGUI_INCLUDE_IMGUI_USER_H 55 | //#define IMGUI_USER_H_FILENAME "my_folder/my_imgui_user.h" 56 | 57 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 58 | //#define IMGUI_USE_BGRA_PACKED_COLOR 59 | 60 | //---- Use 32-bit for ImWchar (default is 16-bit) to support Unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 61 | //#define IMGUI_USE_WCHAR32 62 | 63 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 64 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 65 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 66 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 67 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if IMGUI_USE_STB_SPRINTF is defined. 68 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 69 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 70 | //#define IMGUI_DISABLE_STB_SPRINTF_IMPLEMENTATION // only disabled if IMGUI_USE_STB_SPRINTF is defined. 71 | 72 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 73 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 74 | //#define IMGUI_USE_STB_SPRINTF 75 | 76 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 77 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 78 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 79 | //#define IMGUI_ENABLE_FREETYPE 80 | 81 | //---- Use FreeType+lunasvg library to render OpenType SVG fonts (SVGinOT) 82 | // Requires lunasvg headers to be available in the include path + program to be linked with the lunasvg library (not provided). 83 | // Only works in combination with IMGUI_ENABLE_FREETYPE. 84 | // (implementation is based on Freetype's rsvg-port.c which is licensed under CeCILL-C Free Software License Agreement) 85 | //#define IMGUI_ENABLE_FREETYPE_LUNASVG 86 | 87 | //---- Use stb_truetype to build and rasterize the font atlas (default) 88 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 89 | //#define IMGUI_ENABLE_STB_TRUETYPE 90 | 91 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 92 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 93 | /* 94 | #define IM_VEC2_CLASS_EXTRA \ 95 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 96 | operator MyVec2() const { return MyVec2(x,y); } 97 | 98 | #define IM_VEC4_CLASS_EXTRA \ 99 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 100 | operator MyVec4() const { return MyVec4(x,y,z,w); } 101 | */ 102 | //---- ...Or use Dear ImGui's own very basic math operators. 103 | //#define IMGUI_DEFINE_MATH_OPERATORS 104 | 105 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 106 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 107 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 108 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 109 | //#define ImDrawIdx unsigned int 110 | 111 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 112 | //struct ImDrawList; 113 | //struct ImDrawCmd; 114 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 115 | //#define ImDrawCallback MyImDrawCallback 116 | 117 | //---- Debug Tools: Macro to break in Debugger (we provide a default implementation of this in the codebase) 118 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 119 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 120 | //#define IM_DEBUG_BREAK __debugbreak() 121 | 122 | //---- Debug Tools: Enable slower asserts 123 | //#define IMGUI_DEBUG_PARANOID 124 | 125 | //---- Tip: You can add extra functions within the ImGui:: namespace from anywhere (e.g. your own sources/header files) 126 | /* 127 | namespace ImGui 128 | { 129 | void MyFunction(const char* name, MyMatrix44* mtx); 130 | } 131 | */ 132 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Mouse support. Can discriminate Mouse/TouchScreen/Pen (Windows only). 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 11 | 12 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 13 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 14 | // Learn about Dear ImGui: 15 | // - FAQ https://dearimgui.com/faq 16 | // - Getting Started https://dearimgui.com/getting-started 17 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 18 | // - Introduction, links and more at the top of imgui.cpp 19 | 20 | #pragma once 21 | #include "imgui.h" // IMGUI_IMPL_API 22 | #ifndef IMGUI_DISABLE 23 | 24 | struct GLFWwindow; 25 | struct GLFWmonitor; 26 | 27 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 28 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 29 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 30 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 31 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 32 | 33 | // Emscripten related initialization phase methods 34 | #ifdef __EMSCRIPTEN__ 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback(const char* canvas_selector); 36 | #endif 37 | 38 | // GLFW callbacks install 39 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 40 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 42 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 43 | 44 | // GFLW callbacks options: 45 | // - Set 'chain_for_all_windows=true' to enable chaining callbacks for all windows (including secondary viewports created by backends or by user) 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_SetCallbacksChainForAllWindows(bool chain_for_all_windows); 47 | 48 | // GLFW callbacks (individual callbacks to call yourself if you didn't install callbacks) 49 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 50 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 51 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 52 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 53 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 54 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 55 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 56 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 57 | 58 | #endif // #ifndef IMGUI_DISABLE 59 | -------------------------------------------------------------------------------- /third-party/imgui/imgui_impl_vulkan.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for Vulkan 2 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 3 | 4 | // Implemented features: 5 | // [!] Renderer: User texture binding. Use 'VkDescriptorSet' as ImTextureID. Read the FAQ about ImTextureID! See https://github.com/ocornut/imgui/pull/914 for discussions. 6 | // [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices. 7 | 8 | // Important: on 32-bit systems, user texture binding is only supported if your imconfig file has '#define ImTextureID ImU64'. 9 | // See imgui_impl_vulkan.cpp file for details. 10 | 11 | // The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification. 12 | // IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/ 13 | 14 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 15 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 16 | // Learn about Dear ImGui: 17 | // - FAQ https://dearimgui.com/faq 18 | // - Getting Started https://dearimgui.com/getting-started 19 | // - Documentation https://dearimgui.com/docs (same as your local docs/ folder). 20 | // - Introduction, links and more at the top of imgui.cpp 21 | 22 | // Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app. 23 | // - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h. 24 | // You will use those if you want to use this rendering backend in your engine/app. 25 | // - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by 26 | // the backend itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code. 27 | // Read comments in imgui_impl_vulkan.h. 28 | 29 | #pragma once 30 | #ifndef IMGUI_DISABLE 31 | #include "imgui.h" // IMGUI_IMPL_API 32 | 33 | // [Configuration] in order to use a custom Vulkan function loader: 34 | // (1) You'll need to disable default Vulkan function prototypes. 35 | // We provide a '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' convenience configuration flag. 36 | // In order to make sure this is visible from the imgui_impl_vulkan.cpp compilation unit: 37 | // - Add '#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES' in your imconfig.h file 38 | // - Or as a compilation flag in your build system 39 | // - Or uncomment here (not recommended because you'd be modifying imgui sources!) 40 | // - Do not simply add it in a .cpp file! 41 | // (2) Call ImGui_ImplVulkan_LoadFunctions() before ImGui_ImplVulkan_Init() with your custom function. 42 | // If you have no idea what this is, leave it alone! 43 | //#define IMGUI_IMPL_VULKAN_NO_PROTOTYPES 44 | 45 | // Convenience support for Volk 46 | // (you can also technically use IMGUI_IMPL_VULKAN_NO_PROTOTYPES + wrap Volk via ImGui_ImplVulkan_LoadFunctions().) 47 | //#define IMGUI_IMPL_VULKAN_USE_VOLK 48 | 49 | #if defined(IMGUI_IMPL_VULKAN_NO_PROTOTYPES) && !defined(VK_NO_PROTOTYPES) 50 | #define VK_NO_PROTOTYPES 51 | #endif 52 | #if defined(VK_USE_PLATFORM_WIN32_KHR) && !defined(NOMINMAX) 53 | #define NOMINMAX 54 | #endif 55 | 56 | // Vulkan includes 57 | #ifdef IMGUI_IMPL_VULKAN_USE_VOLK 58 | #include 59 | #else 60 | #include 61 | #endif 62 | #if defined(VK_VERSION_1_3) || defined(VK_KHR_dynamic_rendering) 63 | #define IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING 64 | #endif 65 | 66 | // Initialization data, for ImGui_ImplVulkan_Init() 67 | // - VkDescriptorPool should be created with VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT, 68 | // and must contain a pool size large enough to hold an ImGui VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER descriptor. 69 | // - When using dynamic rendering, set UseDynamicRendering=true and fill PipelineRenderingCreateInfo structure. 70 | // [Please zero-clear before use!] 71 | struct ImGui_ImplVulkan_InitInfo 72 | { 73 | VkInstance Instance; 74 | VkPhysicalDevice PhysicalDevice; 75 | VkDevice Device; 76 | uint32_t QueueFamily; 77 | VkQueue Queue; 78 | VkDescriptorPool DescriptorPool; // See requirements in note above 79 | VkRenderPass RenderPass; // Ignored if using dynamic rendering 80 | uint32_t MinImageCount; // >= 2 81 | uint32_t ImageCount; // >= MinImageCount 82 | VkSampleCountFlagBits MSAASamples; // 0 defaults to VK_SAMPLE_COUNT_1_BIT 83 | 84 | // (Optional) 85 | VkPipelineCache PipelineCache; 86 | uint32_t Subpass; 87 | 88 | // (Optional) Dynamic Rendering 89 | // Need to explicitly enable VK_KHR_dynamic_rendering extension to use this, even for Vulkan 1.3. 90 | bool UseDynamicRendering; 91 | #ifdef IMGUI_IMPL_VULKAN_HAS_DYNAMIC_RENDERING 92 | VkPipelineRenderingCreateInfoKHR PipelineRenderingCreateInfo; 93 | #endif 94 | 95 | // (Optional) Allocation, Debugging 96 | const VkAllocationCallbacks* Allocator; 97 | void (*CheckVkResultFn)(VkResult err); 98 | VkDeviceSize MinAllocationSize; // Minimum allocation size. Set to 1024*1024 to satisfy zealous best practices validation layer and waste a little memory. 99 | }; 100 | 101 | // Called by user code 102 | IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info); 103 | IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown(); 104 | IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame(); 105 | IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE); 106 | IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(); 107 | IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontsTexture(); 108 | IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated) 109 | 110 | // Register a texture (VkDescriptorSet == ImTextureID) 111 | // FIXME: This is experimental in the sense that we are unsure how to best design/tackle this problem 112 | // Please post to https://github.com/ocornut/imgui/pull/914 if you have suggestions. 113 | IMGUI_IMPL_API VkDescriptorSet ImGui_ImplVulkan_AddTexture(VkSampler sampler, VkImageView image_view, VkImageLayout image_layout); 114 | IMGUI_IMPL_API void ImGui_ImplVulkan_RemoveTexture(VkDescriptorSet descriptor_set); 115 | 116 | // Optional: load Vulkan functions with a custom function loader 117 | // This is only useful with IMGUI_IMPL_VULKAN_NO_PROTOTYPES / VK_NO_PROTOTYPES 118 | IMGUI_IMPL_API bool ImGui_ImplVulkan_LoadFunctions(PFN_vkVoidFunction(*loader_func)(const char* function_name, void* user_data), void* user_data = nullptr); 119 | 120 | //------------------------------------------------------------------------- 121 | // Internal / Miscellaneous Vulkan Helpers 122 | // (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.) 123 | //------------------------------------------------------------------------- 124 | // You probably do NOT need to use or care about those functions. 125 | // Those functions only exist because: 126 | // 1) they facilitate the readability and maintenance of the multiple main.cpp examples files. 127 | // 2) the multi-viewport / platform window implementation needs them internally. 128 | // Generally we avoid exposing any kind of superfluous high-level helpers in the bindings, 129 | // but it is too much code to duplicate everywhere so we exceptionally expose them. 130 | // 131 | // Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.). 132 | // You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work. 133 | // (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions) 134 | //------------------------------------------------------------------------- 135 | 136 | struct ImGui_ImplVulkanH_Frame; 137 | struct ImGui_ImplVulkanH_Window; 138 | 139 | // Helpers 140 | IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateOrResizeWindow(VkInstance instance, VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_Window* wnd, uint32_t queue_family, const VkAllocationCallbacks* allocator, int w, int h, uint32_t min_image_count); 141 | IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator); 142 | IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space); 143 | IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count); 144 | IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode); 145 | 146 | // Helper structure to hold the data needed by one rendering frame 147 | // (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) 148 | // [Please zero-clear before use!] 149 | struct ImGui_ImplVulkanH_Frame 150 | { 151 | VkCommandPool CommandPool; 152 | VkCommandBuffer CommandBuffer; 153 | VkFence Fence; 154 | VkImage Backbuffer; 155 | VkImageView BackbufferView; 156 | VkFramebuffer Framebuffer; 157 | }; 158 | 159 | struct ImGui_ImplVulkanH_FrameSemaphores 160 | { 161 | VkSemaphore ImageAcquiredSemaphore; 162 | VkSemaphore RenderCompleteSemaphore; 163 | }; 164 | 165 | // Helper structure to hold the data needed by one rendering context into one OS window 166 | // (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.) 167 | struct ImGui_ImplVulkanH_Window 168 | { 169 | int Width; 170 | int Height; 171 | VkSwapchainKHR Swapchain; 172 | VkSurfaceKHR Surface; 173 | VkSurfaceFormatKHR SurfaceFormat; 174 | VkPresentModeKHR PresentMode; 175 | VkRenderPass RenderPass; 176 | VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo 177 | bool UseDynamicRendering; 178 | bool ClearEnable; 179 | VkClearValue ClearValue; 180 | uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount) 181 | uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count) 182 | uint32_t SemaphoreCount; // Number of simultaneous in-flight frames + 1, to be able to use it in vkAcquireNextImageKHR 183 | uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data) 184 | ImGui_ImplVulkanH_Frame* Frames; 185 | ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores; 186 | 187 | ImGui_ImplVulkanH_Window() 188 | { 189 | memset((void*)this, 0, sizeof(*this)); 190 | PresentMode = (VkPresentModeKHR)~0; // Ensure we get an error if user doesn't set this. 191 | ClearEnable = true; 192 | } 193 | }; 194 | 195 | #endif // #ifndef IMGUI_DISABLE 196 | -------------------------------------------------------------------------------- /third-party/vma/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017-2024 Advanced Micro Devices, Inc. All rights reserved. 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /third-party/volk/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2023 Arseny Kapoulkine 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /third-party/volk/README.md: -------------------------------------------------------------------------------- 1 | # 🐺 volk [![Build Status](https://github.com/zeux/volk/workflows/build/badge.svg)](https://github.com/zeux/volk/actions) 2 | 3 | ## Purpose 4 | 5 | volk is a meta-loader for Vulkan. It allows you to dynamically load entrypoints required to use Vulkan 6 | without linking to vulkan-1.dll or statically linking Vulkan loader. Additionally, volk simplifies the use of Vulkan extensions by automatically loading all associated entrypoints. Finally, volk enables loading 7 | Vulkan entrypoints directly from the driver which can increase performance by skipping loader dispatch overhead. 8 | 9 | volk is written in C89 and supports Windows, Linux, Android and macOS (via MoltenVK). 10 | 11 | ## Building 12 | 13 | There are multiple ways to use volk in your project: 14 | 15 | 1. You can just add `volk.c` to your build system. Note that the usual preprocessor defines that enable Vulkan's platform-specific functions (VK_USE_PLATFORM_WIN32_KHR, VK_USE_PLATFORM_XLIB_KHR, VK_USE_PLATFORM_MACOS_MVK, etc) must be passed as desired to the compiler when building `volk.c`. 16 | 2. You can use volk in header-only fashion. Include `volk.h` wherever you want to use Vulkan functions. In exactly one source file, define `VOLK_IMPLEMENTATION` before including `volk.h`. Do not build `volk.c` at all in this case. This method of integrating volk makes it possible to set the platform defines mentioned above with arbitrary (preprocessor) logic in your code. 17 | 3. You can use provided CMake files, with the usage detailed below. 18 | 19 | ## Basic usage 20 | 21 | To use volk, you have to include `volk.h` instead of `vulkan/vulkan.h`; this is necessary to use function definitions from volk. 22 | 23 | If some files in your application include `vulkan/vulkan.h` and don't include `volk.h`, this can result in symbol conflicts; consider defining `VK_NO_PROTOTYPES` when compiling code that uses Vulkan to make sure this doesn't happen. It's also important to make sure that `vulkan-1` is not linked into the application, as this results in symbol name conflicts as well. 24 | 25 | To initialize volk, call this function first: 26 | 27 | ```c++ 28 | VkResult volkInitialize(); 29 | ``` 30 | 31 | This will attempt to load Vulkan loader from the system; if this function returns `VK_SUCCESS` you can proceed to create Vulkan instance. 32 | If this function fails, this means Vulkan loader isn't installed on your system. 33 | 34 | After creating the Vulkan instance using Vulkan API, call this function: 35 | 36 | ```c++ 37 | void volkLoadInstance(VkInstance instance); 38 | ``` 39 | 40 | This function will load all required Vulkan entrypoints, including all extensions; you can use Vulkan from here on as usual. 41 | 42 | ## Optimizing device calls 43 | 44 | If you use volk as described in the previous section, all device-related function calls, such as `vkCmdDraw`, will go through Vulkan loader dispatch code. 45 | This allows you to transparently support multiple VkDevice objects in the same application, but comes at a price of dispatch overhead which can be as high as 7% depending on the driver and application. 46 | 47 | To avoid this, you have two options: 48 | 49 | 1. For applications that use just one VkDevice object, load device-related Vulkan entrypoints directly from the driver with this function: 50 | 51 | ```c++ 52 | void volkLoadDevice(VkDevice device); 53 | ``` 54 | 55 | 2. For applications that use multiple VkDevice objects, load device-related Vulkan entrypoints into a table: 56 | 57 | ```c++ 58 | void volkLoadDeviceTable(struct VolkDeviceTable* table, VkDevice device); 59 | ``` 60 | 61 | The second option requires you to change the application code to store one `VolkDeviceTable` per `VkDevice` and call functions from this table instead. 62 | 63 | Device entrypoints are loaded using `vkGetDeviceProcAddr`; when no layers are present, this commonly results in most function pointers pointing directly at the driver functions, minimizing the call overhead. When layers are loaded, the entrypoints will point at the implementations in the first applicable layer, so this is compatible with any layers including validation layers. 64 | 65 | Since `volkLoadDevice` overwrites some function pointers with device-specific versions, you can choose to use `volkLoadInstanceOnly` instead of `volkLoadInstance`; when using table-based interface this can also help enforce the usage of the function tables as `volkLoadInstanceOnly` will leave device-specific functions as `NULL`. 66 | 67 | ## CMake support 68 | 69 | If your project uses CMake, volk provides you with targets corresponding to the different use cases: 70 | 71 | 1. Target `volk` is a static library. Any platform defines can be passed to the compiler by setting `VOLK_STATIC_DEFINES`. Example: 72 | ```cmake 73 | if (WIN32) 74 | set(VOLK_STATIC_DEFINES VK_USE_PLATFORM_WIN32_KHR) 75 | elseif() 76 | ... 77 | endif() 78 | add_subdirectory(volk) 79 | target_link_library(my_application PRIVATE volk) 80 | ``` 81 | 2. Target `volk_headers` is an interface target for the header-only style. Example: 82 | ```cmake 83 | add_subdirectory(volk) 84 | target_link_library(my_application PRIVATE volk_headers) 85 | ``` 86 | and in the code: 87 | ```c 88 | /* ...any logic setting VK_USE_PLATFORM_WIN32_KHR and friends... */ 89 | #define VOLK_IMPLEMENTATION 90 | #include "volk.h" 91 | ``` 92 | 93 | The above example use `add_subdirectory` to include volk into CMake's build tree. This is a good choice if you copy the volk files into your project tree or as a git submodule. 94 | 95 | Volk also supports installation and config-file packages. Installation is disabled by default (so as to not pollute user projects with install rules), and can be enabled by passing `-DVOLK_INSTALL=ON` to CMake. Once installed, do something like `find_package(volk CONFIG REQUIRED)` in your project's CMakeLists.txt. The imported volk targets are called `volk::volk` and `volk::volk_headers`. 96 | 97 | ## License 98 | 99 | This library is available to anybody free of charge, under the terms of MIT License (see LICENSE.md). 100 | -------------------------------------------------------------------------------- /third-party/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 | -------------------------------------------------------------------------------- /third-party/vulkan/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 | #define vulkan_video_codec_h264std_decode 1 23 | 24 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 25 | 26 | #define STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE 2 27 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_API_VERSION_1_0_0 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_decode" 29 | 30 | typedef enum StdVideoDecodeH264FieldOrderCount { 31 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_TOP = 0, 32 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_BOTTOM = 1, 33 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_INVALID = 0x7FFFFFFF, 34 | STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_MAX_ENUM = 0x7FFFFFFF 35 | } StdVideoDecodeH264FieldOrderCount; 36 | typedef struct StdVideoDecodeH264PictureInfoFlags { 37 | uint32_t field_pic_flag : 1; 38 | uint32_t is_intra : 1; 39 | uint32_t IdrPicFlag : 1; 40 | uint32_t bottom_field_flag : 1; 41 | uint32_t is_reference : 1; 42 | uint32_t complementary_field_pair : 1; 43 | } StdVideoDecodeH264PictureInfoFlags; 44 | 45 | typedef struct StdVideoDecodeH264PictureInfo { 46 | StdVideoDecodeH264PictureInfoFlags flags; 47 | uint8_t seq_parameter_set_id; 48 | uint8_t pic_parameter_set_id; 49 | uint8_t reserved1; 50 | uint8_t reserved2; 51 | uint16_t frame_num; 52 | uint16_t idr_pic_id; 53 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 54 | } StdVideoDecodeH264PictureInfo; 55 | 56 | typedef struct StdVideoDecodeH264ReferenceInfoFlags { 57 | uint32_t top_field_flag : 1; 58 | uint32_t bottom_field_flag : 1; 59 | uint32_t used_for_long_term_reference : 1; 60 | uint32_t is_non_existing : 1; 61 | } StdVideoDecodeH264ReferenceInfoFlags; 62 | 63 | typedef struct StdVideoDecodeH264ReferenceInfo { 64 | StdVideoDecodeH264ReferenceInfoFlags flags; 65 | uint16_t FrameNum; 66 | uint16_t reserved; 67 | int32_t PicOrderCnt[STD_VIDEO_DECODE_H264_FIELD_ORDER_COUNT_LIST_SIZE]; 68 | } StdVideoDecodeH264ReferenceInfo; 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /third-party/vulkan/vk_video/vulkan_video_codec_h264std_encode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H264STD_ENCODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H264STD_ENCODE_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 | #define vulkan_video_codec_h264std_encode 1 23 | // Vulkan 0.9 provisional Vulkan video H.264 encode std specification version number 24 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_API_VERSION_0_9_9 VK_MAKE_VIDEO_STD_VERSION(0, 9, 9) 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_API_VERSION_0_9_9 27 | #define VK_STD_VULKAN_VIDEO_CODEC_H264_ENCODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h264_encode" 28 | typedef struct StdVideoEncodeH264WeightTableFlags { 29 | uint32_t luma_weight_l0_flag; 30 | uint32_t chroma_weight_l0_flag; 31 | uint32_t luma_weight_l1_flag; 32 | uint32_t chroma_weight_l1_flag; 33 | } StdVideoEncodeH264WeightTableFlags; 34 | 35 | typedef struct StdVideoEncodeH264WeightTable { 36 | StdVideoEncodeH264WeightTableFlags flags; 37 | uint8_t luma_log2_weight_denom; 38 | uint8_t chroma_log2_weight_denom; 39 | int8_t luma_weight_l0[STD_VIDEO_H264_MAX_NUM_LIST_REF]; 40 | int8_t luma_offset_l0[STD_VIDEO_H264_MAX_NUM_LIST_REF]; 41 | int8_t chroma_weight_l0[STD_VIDEO_H264_MAX_NUM_LIST_REF][STD_VIDEO_H264_MAX_CHROMA_PLANES]; 42 | int8_t chroma_offset_l0[STD_VIDEO_H264_MAX_NUM_LIST_REF][STD_VIDEO_H264_MAX_CHROMA_PLANES]; 43 | int8_t luma_weight_l1[STD_VIDEO_H264_MAX_NUM_LIST_REF]; 44 | int8_t luma_offset_l1[STD_VIDEO_H264_MAX_NUM_LIST_REF]; 45 | int8_t chroma_weight_l1[STD_VIDEO_H264_MAX_NUM_LIST_REF][STD_VIDEO_H264_MAX_CHROMA_PLANES]; 46 | int8_t chroma_offset_l1[STD_VIDEO_H264_MAX_NUM_LIST_REF][STD_VIDEO_H264_MAX_CHROMA_PLANES]; 47 | } StdVideoEncodeH264WeightTable; 48 | 49 | typedef struct StdVideoEncodeH264SliceHeaderFlags { 50 | uint32_t direct_spatial_mv_pred_flag : 1; 51 | uint32_t num_ref_idx_active_override_flag : 1; 52 | uint32_t no_output_of_prior_pics_flag : 1; 53 | uint32_t adaptive_ref_pic_marking_mode_flag : 1; 54 | uint32_t no_prior_references_available_flag : 1; 55 | } StdVideoEncodeH264SliceHeaderFlags; 56 | 57 | typedef struct StdVideoEncodeH264PictureInfoFlags { 58 | uint32_t idr_flag : 1; 59 | uint32_t is_reference_flag : 1; 60 | uint32_t used_for_long_term_reference : 1; 61 | } StdVideoEncodeH264PictureInfoFlags; 62 | 63 | typedef struct StdVideoEncodeH264ReferenceInfoFlags { 64 | uint32_t used_for_long_term_reference : 1; 65 | } StdVideoEncodeH264ReferenceInfoFlags; 66 | 67 | typedef struct StdVideoEncodeH264ReferenceListsInfoFlags { 68 | uint32_t ref_pic_list_modification_flag_l0 : 1; 69 | uint32_t ref_pic_list_modification_flag_l1 : 1; 70 | } StdVideoEncodeH264ReferenceListsInfoFlags; 71 | 72 | typedef struct StdVideoEncodeH264RefListModEntry { 73 | StdVideoH264ModificationOfPicNumsIdc modification_of_pic_nums_idc; 74 | uint16_t abs_diff_pic_num_minus1; 75 | uint16_t long_term_pic_num; 76 | } StdVideoEncodeH264RefListModEntry; 77 | 78 | typedef struct StdVideoEncodeH264RefPicMarkingEntry { 79 | StdVideoH264MemMgmtControlOp operation; 80 | uint16_t difference_of_pic_nums_minus1; 81 | uint16_t long_term_pic_num; 82 | uint16_t long_term_frame_idx; 83 | uint16_t max_long_term_frame_idx_plus1; 84 | } StdVideoEncodeH264RefPicMarkingEntry; 85 | 86 | typedef struct StdVideoEncodeH264ReferenceListsInfo { 87 | StdVideoEncodeH264ReferenceListsInfoFlags flags; 88 | uint8_t refPicList0EntryCount; 89 | uint8_t refPicList1EntryCount; 90 | uint8_t refList0ModOpCount; 91 | uint8_t refList1ModOpCount; 92 | uint8_t refPicMarkingOpCount; 93 | uint8_t reserved1[7]; 94 | const uint8_t* pRefPicList0Entries; 95 | const uint8_t* pRefPicList1Entries; 96 | const StdVideoEncodeH264RefListModEntry* pRefList0ModOperations; 97 | const StdVideoEncodeH264RefListModEntry* pRefList1ModOperations; 98 | const StdVideoEncodeH264RefPicMarkingEntry* pRefPicMarkingOperations; 99 | } StdVideoEncodeH264ReferenceListsInfo; 100 | 101 | typedef struct StdVideoEncodeH264PictureInfo { 102 | StdVideoEncodeH264PictureInfoFlags flags; 103 | uint8_t seq_parameter_set_id; 104 | uint8_t pic_parameter_set_id; 105 | uint16_t reserved1; 106 | StdVideoH264PictureType pictureType; 107 | uint32_t frame_num; 108 | int32_t PicOrderCnt; 109 | } StdVideoEncodeH264PictureInfo; 110 | 111 | typedef struct StdVideoEncodeH264ReferenceInfo { 112 | StdVideoEncodeH264ReferenceInfoFlags flags; 113 | StdVideoH264PictureType pictureType; 114 | uint32_t FrameNum; 115 | int32_t PicOrderCnt; 116 | uint16_t long_term_pic_num; 117 | uint16_t long_term_frame_idx; 118 | } StdVideoEncodeH264ReferenceInfo; 119 | 120 | typedef struct StdVideoEncodeH264SliceHeader { 121 | StdVideoEncodeH264SliceHeaderFlags flags; 122 | uint32_t first_mb_in_slice; 123 | StdVideoH264SliceType slice_type; 124 | uint16_t idr_pic_id; 125 | uint8_t num_ref_idx_l0_active_minus1; 126 | uint8_t num_ref_idx_l1_active_minus1; 127 | StdVideoH264CabacInitIdc cabac_init_idc; 128 | StdVideoH264DisableDeblockingFilterIdc disable_deblocking_filter_idc; 129 | int8_t slice_alpha_c0_offset_div2; 130 | int8_t slice_beta_offset_div2; 131 | uint16_t reserved1; 132 | uint32_t reserved2; 133 | const StdVideoEncodeH264WeightTable* pWeightTable; 134 | } StdVideoEncodeH264SliceHeader; 135 | 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /third-party/vulkan/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 | #define vulkan_video_codec_h265std_decode 1 23 | 24 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 VK_MAKE_VIDEO_STD_VERSION(1, 0, 0) 25 | 26 | #define STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE 8 27 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_API_VERSION_1_0_0 28 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_DECODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_decode" 29 | typedef struct StdVideoDecodeH265PictureInfoFlags { 30 | uint32_t IrapPicFlag : 1; 31 | uint32_t IdrPicFlag : 1; 32 | uint32_t IsReference : 1; 33 | uint32_t short_term_ref_pic_set_sps_flag : 1; 34 | } StdVideoDecodeH265PictureInfoFlags; 35 | 36 | typedef struct StdVideoDecodeH265PictureInfo { 37 | StdVideoDecodeH265PictureInfoFlags flags; 38 | uint8_t sps_video_parameter_set_id; 39 | uint8_t pps_seq_parameter_set_id; 40 | uint8_t pps_pic_parameter_set_id; 41 | uint8_t NumDeltaPocsOfRefRpsIdx; 42 | int32_t PicOrderCntVal; 43 | uint16_t NumBitsForSTRefPicSetInSlice; 44 | uint16_t reserved; 45 | uint8_t RefPicSetStCurrBefore[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 46 | uint8_t RefPicSetStCurrAfter[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 47 | uint8_t RefPicSetLtCurr[STD_VIDEO_DECODE_H265_REF_PIC_SET_LIST_SIZE]; 48 | } StdVideoDecodeH265PictureInfo; 49 | 50 | typedef struct StdVideoDecodeH265ReferenceInfoFlags { 51 | uint32_t used_for_long_term_reference : 1; 52 | uint32_t unused_for_reference : 1; 53 | } StdVideoDecodeH265ReferenceInfoFlags; 54 | 55 | typedef struct StdVideoDecodeH265ReferenceInfo { 56 | StdVideoDecodeH265ReferenceInfoFlags flags; 57 | int32_t PicOrderCntVal; 58 | } StdVideoDecodeH265ReferenceInfo; 59 | 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /third-party/vulkan/vk_video/vulkan_video_codec_h265std_encode.h: -------------------------------------------------------------------------------- 1 | #ifndef VULKAN_VIDEO_CODEC_H265STD_ENCODE_H_ 2 | #define VULKAN_VIDEO_CODEC_H265STD_ENCODE_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 | #define vulkan_video_codec_h265std_encode 1 23 | // Vulkan 0.9 provisional Vulkan video H.265 encode std specification version number 24 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_API_VERSION_0_9_10 VK_MAKE_VIDEO_STD_VERSION(0, 9, 10) 25 | 26 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_SPEC_VERSION VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_API_VERSION_0_9_10 27 | #define VK_STD_VULKAN_VIDEO_CODEC_H265_ENCODE_EXTENSION_NAME "VK_STD_vulkan_video_codec_h265_encode" 28 | typedef struct StdVideoEncodeH265WeightTableFlags { 29 | uint16_t luma_weight_l0_flag; 30 | uint16_t chroma_weight_l0_flag; 31 | uint16_t luma_weight_l1_flag; 32 | uint16_t chroma_weight_l1_flag; 33 | } StdVideoEncodeH265WeightTableFlags; 34 | 35 | typedef struct StdVideoEncodeH265WeightTable { 36 | StdVideoEncodeH265WeightTableFlags flags; 37 | uint8_t luma_log2_weight_denom; 38 | int8_t delta_chroma_log2_weight_denom; 39 | int8_t delta_luma_weight_l0[STD_VIDEO_H265_MAX_NUM_LIST_REF]; 40 | int8_t luma_offset_l0[STD_VIDEO_H265_MAX_NUM_LIST_REF]; 41 | int8_t delta_chroma_weight_l0[STD_VIDEO_H265_MAX_NUM_LIST_REF][STD_VIDEO_H265_MAX_CHROMA_PLANES]; 42 | int8_t delta_chroma_offset_l0[STD_VIDEO_H265_MAX_NUM_LIST_REF][STD_VIDEO_H265_MAX_CHROMA_PLANES]; 43 | int8_t delta_luma_weight_l1[STD_VIDEO_H265_MAX_NUM_LIST_REF]; 44 | int8_t luma_offset_l1[STD_VIDEO_H265_MAX_NUM_LIST_REF]; 45 | int8_t delta_chroma_weight_l1[STD_VIDEO_H265_MAX_NUM_LIST_REF][STD_VIDEO_H265_MAX_CHROMA_PLANES]; 46 | int8_t delta_chroma_offset_l1[STD_VIDEO_H265_MAX_NUM_LIST_REF][STD_VIDEO_H265_MAX_CHROMA_PLANES]; 47 | } StdVideoEncodeH265WeightTable; 48 | 49 | typedef struct StdVideoEncodeH265SliceSegmentHeaderFlags { 50 | uint32_t first_slice_segment_in_pic_flag : 1; 51 | uint32_t no_output_of_prior_pics_flag : 1; 52 | uint32_t dependent_slice_segment_flag : 1; 53 | uint32_t pic_output_flag : 1; 54 | uint32_t short_term_ref_pic_set_sps_flag : 1; 55 | uint32_t slice_temporal_mvp_enable_flag : 1; 56 | uint32_t slice_sao_luma_flag : 1; 57 | uint32_t slice_sao_chroma_flag : 1; 58 | uint32_t num_ref_idx_active_override_flag : 1; 59 | uint32_t mvd_l1_zero_flag : 1; 60 | uint32_t cabac_init_flag : 1; 61 | uint32_t cu_chroma_qp_offset_enabled_flag : 1; 62 | uint32_t deblocking_filter_override_flag : 1; 63 | uint32_t slice_deblocking_filter_disabled_flag : 1; 64 | uint32_t collocated_from_l0_flag : 1; 65 | uint32_t slice_loop_filter_across_slices_enabled_flag : 1; 66 | } StdVideoEncodeH265SliceSegmentHeaderFlags; 67 | 68 | typedef struct StdVideoEncodeH265SliceSegmentLongTermRefPics { 69 | uint8_t num_long_term_sps; 70 | uint8_t num_long_term_pics; 71 | uint8_t lt_idx_sps[STD_VIDEO_H265_MAX_LONG_TERM_REF_PICS_SPS]; 72 | uint8_t poc_lsb_lt[STD_VIDEO_H265_MAX_LONG_TERM_PICS]; 73 | uint16_t used_by_curr_pic_lt_flag; 74 | uint8_t delta_poc_msb_present_flag[STD_VIDEO_H265_MAX_DELTA_POC]; 75 | uint8_t delta_poc_msb_cycle_lt[STD_VIDEO_H265_MAX_DELTA_POC]; 76 | } StdVideoEncodeH265SliceSegmentLongTermRefPics; 77 | 78 | typedef struct StdVideoEncodeH265SliceSegmentHeader { 79 | StdVideoEncodeH265SliceSegmentHeaderFlags flags; 80 | StdVideoH265SliceType slice_type; 81 | uint32_t slice_segment_address; 82 | uint8_t short_term_ref_pic_set_idx; 83 | uint8_t collocated_ref_idx; 84 | uint8_t num_ref_idx_l0_active_minus1; 85 | uint8_t num_ref_idx_l1_active_minus1; 86 | uint8_t MaxNumMergeCand; 87 | int8_t slice_cb_qp_offset; 88 | int8_t slice_cr_qp_offset; 89 | int8_t slice_beta_offset_div2; 90 | int8_t slice_tc_offset_div2; 91 | int8_t slice_act_y_qp_offset; 92 | int8_t slice_act_cb_qp_offset; 93 | int8_t slice_act_cr_qp_offset; 94 | const StdVideoH265ShortTermRefPicSet* pShortTermRefPicSet; 95 | const StdVideoEncodeH265SliceSegmentLongTermRefPics* pLongTermRefPics; 96 | const StdVideoEncodeH265WeightTable* pWeightTable; 97 | } StdVideoEncodeH265SliceSegmentHeader; 98 | 99 | typedef struct StdVideoEncodeH265ReferenceListsInfoFlags { 100 | uint32_t ref_pic_list_modification_flag_l0 : 1; 101 | uint32_t ref_pic_list_modification_flag_l1 : 1; 102 | } StdVideoEncodeH265ReferenceListsInfoFlags; 103 | 104 | typedef struct StdVideoEncodeH265ReferenceListsInfo { 105 | StdVideoEncodeH265ReferenceListsInfoFlags flags; 106 | uint8_t num_ref_idx_l0_active_minus1; 107 | uint8_t num_ref_idx_l1_active_minus1; 108 | uint16_t reserved1; 109 | const uint8_t* pRefPicList0Entries; 110 | const uint8_t* pRefPicList1Entries; 111 | const uint8_t* pRefList0Modifications; 112 | const uint8_t* pRefList1Modifications; 113 | } StdVideoEncodeH265ReferenceListsInfo; 114 | 115 | typedef struct StdVideoEncodeH265PictureInfoFlags { 116 | uint32_t is_reference_flag : 1; 117 | uint32_t IrapPicFlag : 1; 118 | uint32_t long_term_flag : 1; 119 | uint32_t discardable_flag : 1; 120 | uint32_t cross_layer_bla_flag : 1; 121 | } StdVideoEncodeH265PictureInfoFlags; 122 | 123 | typedef struct StdVideoEncodeH265PictureInfo { 124 | StdVideoEncodeH265PictureInfoFlags flags; 125 | StdVideoH265PictureType PictureType; 126 | uint8_t sps_video_parameter_set_id; 127 | uint8_t pps_seq_parameter_set_id; 128 | uint8_t pps_pic_parameter_set_id; 129 | uint8_t TemporalId; 130 | int32_t PicOrderCntVal; 131 | } StdVideoEncodeH265PictureInfo; 132 | 133 | typedef struct StdVideoEncodeH265ReferenceInfoFlags { 134 | uint32_t used_for_long_term_reference : 1; 135 | uint32_t unused_for_reference : 1; 136 | } StdVideoEncodeH265ReferenceInfoFlags; 137 | 138 | typedef struct StdVideoEncodeH265ReferenceInfo { 139 | StdVideoEncodeH265ReferenceInfoFlags flags; 140 | StdVideoH265PictureType PictureType; 141 | int32_t PicOrderCntVal; 142 | uint8_t TemporalId; 143 | } StdVideoEncodeH265ReferenceInfo; 144 | 145 | 146 | #ifdef __cplusplus 147 | } 148 | #endif 149 | 150 | #endif 151 | -------------------------------------------------------------------------------- /third-party/vulkan/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 | #define vulkan_video_codecs_common 1 23 | #define VK_MAKE_VIDEO_STD_VERSION(major, minor, patch) \ 24 | ((((uint32_t)(major)) << 22) | (((uint32_t)(minor)) << 12) | ((uint32_t)(patch))) 25 | 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /third-party/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 | -------------------------------------------------------------------------------- /third-party/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 | #define VK_KHR_xcb_surface 1 23 | #define VK_KHR_XCB_SURFACE_SPEC_VERSION 6 24 | #define VK_KHR_XCB_SURFACE_EXTENSION_NAME "VK_KHR_xcb_surface" 25 | typedef VkFlags VkXcbSurfaceCreateFlagsKHR; 26 | typedef struct VkXcbSurfaceCreateInfoKHR { 27 | VkStructureType sType; 28 | const void* pNext; 29 | VkXcbSurfaceCreateFlagsKHR flags; 30 | xcb_connection_t* connection; 31 | xcb_window_t window; 32 | } VkXcbSurfaceCreateInfoKHR; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXcbSurfaceKHR)(VkInstance instance, const VkXcbSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, xcb_connection_t* connection, xcb_visualid_t visual_id); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXcbSurfaceKHR( 39 | VkInstance instance, 40 | const VkXcbSurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | 44 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXcbPresentationSupportKHR( 45 | VkPhysicalDevice physicalDevice, 46 | uint32_t queueFamilyIndex, 47 | xcb_connection_t* connection, 48 | xcb_visualid_t visual_id); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /third-party/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 | #define VK_KHR_xlib_surface 1 23 | #define VK_KHR_XLIB_SURFACE_SPEC_VERSION 6 24 | #define VK_KHR_XLIB_SURFACE_EXTENSION_NAME "VK_KHR_xlib_surface" 25 | typedef VkFlags VkXlibSurfaceCreateFlagsKHR; 26 | typedef struct VkXlibSurfaceCreateInfoKHR { 27 | VkStructureType sType; 28 | const void* pNext; 29 | VkXlibSurfaceCreateFlagsKHR flags; 30 | Display* dpy; 31 | Window window; 32 | } VkXlibSurfaceCreateInfoKHR; 33 | 34 | typedef VkResult (VKAPI_PTR *PFN_vkCreateXlibSurfaceKHR)(VkInstance instance, const VkXlibSurfaceCreateInfoKHR* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface); 35 | typedef VkBool32 (VKAPI_PTR *PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex, Display* dpy, VisualID visualID); 36 | 37 | #ifndef VK_NO_PROTOTYPES 38 | VKAPI_ATTR VkResult VKAPI_CALL vkCreateXlibSurfaceKHR( 39 | VkInstance instance, 40 | const VkXlibSurfaceCreateInfoKHR* pCreateInfo, 41 | const VkAllocationCallbacks* pAllocator, 42 | VkSurfaceKHR* pSurface); 43 | 44 | VKAPI_ATTR VkBool32 VKAPI_CALL vkGetPhysicalDeviceXlibPresentationSupportKHR( 45 | VkPhysicalDevice physicalDevice, 46 | uint32_t queueFamilyIndex, 47 | Display* dpy, 48 | VisualID visualID); 49 | #endif 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | --------------------------------------------------------------------------------