├── .clang-format
├── .clang-tidy
├── .gitignore
├── .vscode
└── launch.json
├── CMakeLists.txt
├── CMakePresets.json
├── LICENSE
├── README.md
├── cmake
├── modules
│ └── FindWayland.cmake
├── packaging.cmake
├── toolchains
│ ├── cl-x86_64-windows-msvc.cmake
│ ├── clang-x86_64-linux-gnu.cmake
│ ├── clang-x86_64-windows-msvc.cmake
│ ├── gcc-x86_64-linux-gnu.cmake
│ └── vcvars.cmake
├── vcpkg-overlay-ports
│ ├── fsr2
│ │ ├── portfile.cmake
│ │ └── vcpkg.json
│ └── glfw3
│ │ ├── portfile.cmake
│ │ └── vcpkg.json
├── vcpkg.cmake
└── warnings.cmake
├── include
└── daxa
│ ├── c
│ ├── command_recorder.h
│ ├── core.h
│ ├── daxa.h
│ ├── device.h
│ ├── gpu_resources.h
│ ├── instance.h
│ ├── pipeline.h
│ ├── swapchain.h
│ ├── sync.h
│ └── types.h
│ ├── command_recorder.hpp
│ ├── core.hpp
│ ├── daxa.glsl
│ ├── daxa.hpp
│ ├── daxa.inl
│ ├── daxa.slang
│ ├── device.hpp
│ ├── gpu_resources.hpp
│ ├── instance.hpp
│ ├── pipeline.hpp
│ ├── swapchain.hpp
│ ├── sync.hpp
│ ├── types.hpp
│ └── utils
│ ├── fsr2.hpp
│ ├── imgui.hpp
│ ├── mem.hpp
│ ├── pipeline_manager.hpp
│ ├── task_graph.hpp
│ ├── task_graph.inl
│ ├── task_graph_types.hpp
│ └── upscaling_common.hpp
├── misc
└── daxa-logo.png
├── portfile.cmake
├── src
├── cpp_wrapper.cpp
├── impl_command_recorder.cpp
├── impl_command_recorder.hpp
├── impl_core.cpp
├── impl_core.hpp
├── impl_dependencies.cpp
├── impl_device.cpp
├── impl_device.hpp
├── impl_features.cpp
├── impl_features.hpp
├── impl_gpu_resources.cpp
├── impl_gpu_resources.hpp
├── impl_instance.cpp
├── impl_instance.hpp
├── impl_pipeline.cpp
├── impl_pipeline.hpp
├── impl_swapchain.cpp
├── impl_swapchain.hpp
├── impl_sync.cpp
├── impl_sync.hpp
├── impl_timeline_query.cpp
├── impl_timeline_query.hpp
└── utils
│ ├── impl_fsr2.cpp
│ ├── impl_fsr2.hpp
│ ├── impl_imgui.cpp
│ ├── impl_imgui.hpp
│ ├── impl_imgui_spv.hpp
│ ├── impl_mem.cpp
│ ├── impl_pipeline_manager.cpp
│ ├── impl_pipeline_manager.hpp
│ ├── impl_task_graph.cpp
│ ├── impl_task_graph.hpp
│ └── impl_task_graph_debug.hpp
├── tests
├── 0_common
│ ├── base_app.hpp
│ ├── shared.hpp
│ └── window.hpp
├── 1_setup
│ └── 1_window
│ │ └── main.cpp
├── 2_daxa_api
│ ├── 10_raytracing
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── random.glsl
│ │ │ ├── raytracing.glsl
│ │ │ ├── shaders.glsl
│ │ │ └── shared.inl
│ ├── 11_mesh_shader
│ │ ├── draw.slang
│ │ ├── main.cpp
│ │ └── shared.inl
│ ├── 12_async_queues
│ │ ├── draw.slang
│ │ ├── main.cpp
│ │ └── shared.inl
│ ├── 1_instance
│ │ └── main.cpp
│ ├── 2_device
│ │ └── main.cpp
│ ├── 3_command_recorder
│ │ └── main.cpp
│ ├── 4_synchronization
│ │ └── main.cpp
│ ├── 5_swapchain
│ │ └── main.cpp
│ ├── 6_task_graph
│ │ ├── common.hpp
│ │ ├── main.cpp
│ │ ├── mipmapping.hpp
│ │ ├── persistent_resources.hpp
│ │ ├── shaders
│ │ │ ├── draw.glsl
│ │ │ ├── mipmapping.glsl
│ │ │ ├── shader_integration.glsl
│ │ │ ├── shader_integration.inl
│ │ │ ├── shared.inl
│ │ │ ├── transient.glsl
│ │ │ └── transient.inl
│ │ └── transient_overlap.hpp
│ ├── 7_pipeline_manager
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── main.glsl
│ │ │ └── test
│ │ │ ├── tesselation_test.glsl
│ │ │ ├── test0.glsl
│ │ │ └── test1.glsl
│ ├── 8_mem
│ │ └── main.cpp
│ └── 9_shader_integration
│ │ ├── main.cpp
│ │ ├── shaders
│ │ ├── alignment_test.glsl
│ │ ├── bindless_access.glsl
│ │ ├── bindless_access_followup.glsl
│ │ └── shared.inl
│ │ └── shared.hlsl
├── 3_samples
│ ├── 0_rectangle_cutting
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── draw.glsl
│ │ │ └── shared.inl
│ ├── 1_mandelbrot
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── compute.glsl
│ │ │ ├── compute.slang
│ │ │ └── shared.inl
│ ├── 2_mpm_mls
│ │ ├── camera.h
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── compute.glsl
│ │ │ ├── compute.slang
│ │ │ ├── raytracing.glsl
│ │ │ ├── raytracing.slang
│ │ │ └── shared.inl
│ ├── 3_hello_triangle_compute
│ │ ├── main.cpp
│ │ └── shaders
│ │ │ ├── compute.glsl
│ │ │ ├── compute.hlsl
│ │ │ └── shared.inl
│ └── 5_boids
│ │ ├── main.cpp
│ │ ├── shaders
│ │ ├── frag.glsl
│ │ ├── update_boids.glsl
│ │ └── vert.glsl
│ │ └── shared.inl
├── 4_hello_daxa
│ ├── 0_c_api
│ │ └── main.c
│ ├── 1_pink_screen
│ │ └── main.cpp
│ └── 2_triangle
│ │ ├── main.cpp
│ │ ├── main.glsl
│ │ └── shared.inl
└── CMakeLists.txt
└── vcpkg.json
/.clang-format:
--------------------------------------------------------------------------------
1 | Language: Cpp
2 | BasedOnStyle: LLVM
3 |
4 | UseTab: Never
5 | TabWidth: 4
6 | IndentWidth: 4
7 | AccessModifierOffset: -2
8 | IndentCaseLabels: false
9 | ColumnLimit: 0
10 | BreakBeforeBraces: Allman
11 | QualifierAlignment: Right
12 |
13 | SortIncludes: false
14 | SortUsingDeclarations: false
15 |
16 | NamespaceIndentation: All
17 | CompactNamespaces: true
18 |
19 | AllowShortIfStatementsOnASingleLine: false
20 | AllowShortCaseLabelsOnASingleLine: true
21 | AllowShortBlocksOnASingleLine: false
22 |
23 | PointerAlignment: Middle
24 |
--------------------------------------------------------------------------------
/.clang-tidy:
--------------------------------------------------------------------------------
1 | Checks: "*,
2 | -abseil-*,
3 | -altera-*,
4 | -android-*,
5 | -fuchsia-*,
6 | -google-*,
7 | -llvm*,
8 | -zircon-*,
9 | -readability-else-after-return,
10 | -readability-static-accessed-through-instance,
11 | -readability-avoid-const-params-in-decls,
12 | -cppcoreguidelines-non-private-member-variables-in-classes,
13 | -misc-non-private-member-variables-in-classes,
14 | -hicpp-uppercase-literal-suffix,
15 | -readability-uppercase-literal-suffix,
16 | -readability-identifier-length,
17 | -cppcoreguidelines-pro-type-reinterpret-cast,
18 | -performance-no-int-to-ptr,
19 | -bugprone-easily-swappable-parameters,
20 | -readability-simplify-boolean-expr,
21 | -hicpp-signed-bitwise,
22 | -cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers,
23 | -readability-function-cognitive-complexity,
24 | "
25 | WarningsAsErrors: ''
26 | HeaderFilterRegex: ''
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "Launch",
6 | "type": "cppdbg",
7 | "request": "launch",
8 | "program": "${command:cmake.launchTargetPath}",
9 | "args": [],
10 | "stopAtEntry": false,
11 | "cwd": "${workspaceFolder}",
12 | "environment": [],
13 | "linux": {
14 | "type": "lldb"
15 | },
16 | "windows": {
17 | "type": "cppvsdbg",
18 | "console": "externalTerminal"
19 | }
20 | }
21 | ]
22 | }
--------------------------------------------------------------------------------
/CMakePresets.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
3 | "cmakeMinimumRequired": {
4 | "major": 3,
5 | "minor": 21,
6 | "patch": 0
7 | },
8 | "configurePresets": [
9 | {
10 | "name": "defaults",
11 | "hidden": true,
12 | "binaryDir": "${sourceDir}/build/${presetName}",
13 | "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
14 | "generator": "Ninja Multi-Config",
15 | "cacheVariables": {
16 | "CMAKE_MODULE_PATH": "${sourceDir}/cmake/modules",
17 | "DAXA_USE_VCPKG": true,
18 | "DAXA_ENABLE_UTILS_FSR2": false,
19 | "DAXA_ENABLE_UTILS_IMGUI": true,
20 | "DAXA_ENABLE_UTILS_MEM": false,
21 | "DAXA_ENABLE_UTILS_PIPELINE_MANAGER_GLSLANG": true,
22 | "DAXA_ENABLE_UTILS_PIPELINE_MANAGER_SLANG": true,
23 | "DAXA_ENABLE_UTILS_PIPELINE_MANAGER_SPIRV_VALIDATION": false,
24 | "DAXA_ENABLE_UTILS_TASK_GRAPH": true,
25 | "DAXA_ENABLE_TESTS": true,
26 | "DAXA_ENABLE_TOOLS": true,
27 | "DAXA_ENABLE_STATIC_ANALYSIS": false
28 | }
29 | },
30 | {
31 | "name": "defaults-windows",
32 | "hidden": true,
33 | "inherits": [
34 | "defaults"
35 | ],
36 | "condition": {
37 | "type": "equals",
38 | "lhs": "${hostSystemName}",
39 | "rhs": "Windows"
40 | },
41 | "cacheVariables": {
42 | "DAXA_TESTS_DISABLE_WINDOWS_CONSOLE": false
43 | }
44 | },
45 | {
46 | "name": "defaults-linux",
47 | "hidden": true,
48 | "inherits": [
49 | "defaults"
50 | ],
51 | "condition": {
52 | "type": "equals",
53 | "lhs": "${hostSystemName}",
54 | "rhs": "Linux"
55 | }
56 | },
57 | {
58 | "name": "clang-x86_64-windows-msvc",
59 | "displayName": "Clang x86_64 Windows (MSVC ABI)",
60 | "inherits": [
61 | "defaults-windows"
62 | ],
63 | "toolchainFile": "${sourceDir}/cmake/toolchains/clang-x86_64-windows-msvc.cmake"
64 | },
65 | {
66 | "name": "cl-x86_64-windows-msvc",
67 | "displayName": "CL.exe x86_64 Windows (MSVC ABI)",
68 | "inherits": [
69 | "defaults-windows"
70 | ],
71 | "toolchainFile": "${sourceDir}/cmake/toolchains/cl-x86_64-windows-msvc.cmake"
72 | },
73 | {
74 | "name": "gcc-x86_64-linux-gnu",
75 | "displayName": "G++ x86_64 Linux (GNU ABI)",
76 | "inherits": [
77 | "defaults-linux"
78 | ],
79 | "toolchainFile": "${sourceDir}/cmake/toolchains/gcc-x86_64-linux-gnu.cmake"
80 | },
81 | {
82 | "name": "clang-x86_64-linux-gnu",
83 | "displayName": "Clang x86_64 Linux (GNU ABI)",
84 | "inherits": [
85 | "defaults-linux"
86 | ],
87 | "toolchainFile": "${sourceDir}/cmake/toolchains/clang-x86_64-linux-gnu.cmake"
88 | }
89 | ],
90 | "buildPresets": [
91 | {
92 | "name": "clang-x86_64-windows-msvc-debug",
93 | "displayName": "Clang x86_64 Windows (MSVC ABI) Debug",
94 | "configurePreset": "clang-x86_64-windows-msvc",
95 | "configuration": "Debug"
96 | },
97 | {
98 | "name": "clang-x86_64-windows-msvc-relwithdebinfo",
99 | "displayName": "Clang x86_64 Windows (MSVC ABI) RelWithDebInfo",
100 | "configurePreset": "clang-x86_64-windows-msvc",
101 | "configuration": "RelWithDebInfo"
102 | },
103 | {
104 | "name": "clang-x86_64-windows-msvc-release",
105 | "displayName": "Clang x86_64 Windows (MSVC ABI) Release",
106 | "configurePreset": "clang-x86_64-windows-msvc",
107 | "configuration": "Release"
108 | },
109 | {
110 | "name": "cl-x86_64-windows-msvc-debug",
111 | "displayName": "CL.exe x86_64 Windows (MSVC ABI) Debug",
112 | "configurePreset": "cl-x86_64-windows-msvc",
113 | "configuration": "Debug"
114 | },
115 | {
116 | "name": "cl-x86_64-windows-msvc-relwithdebinfo",
117 | "displayName": "CL.exe x86_64 Windows (MSVC ABI) RelWithDebInfo",
118 | "configurePreset": "cl-x86_64-windows-msvc",
119 | "configuration": "RelWithDebInfo"
120 | },
121 | {
122 | "name": "cl-x86_64-windows-msvc-release",
123 | "displayName": "CL.exe x86_64 Windows (MSVC ABI) Release",
124 | "configurePreset": "cl-x86_64-windows-msvc",
125 | "configuration": "Release"
126 | },
127 | {
128 | "name": "gcc-x86_64-linux-gnu-debug",
129 | "displayName": "G++ x86_64 Linux (GNU ABI) Debug",
130 | "configurePreset": "gcc-x86_64-linux-gnu",
131 | "configuration": "Debug"
132 | },
133 | {
134 | "name": "gcc-x86_64-linux-gnu-relwithdebinfo",
135 | "displayName": "G++ x86_64 Linux (GNU ABI) RelWithDebInfo",
136 | "configurePreset": "gcc-x86_64-linux-gnu",
137 | "configuration": "RelWithDebInfo"
138 | },
139 | {
140 | "name": "gcc-x86_64-linux-gnu-release",
141 | "displayName": "G++ x86_64 Linux (GNU ABI) Release",
142 | "configurePreset": "gcc-x86_64-linux-gnu",
143 | "configuration": "Release"
144 | },
145 | {
146 | "name": "clang-x86_64-linux-gnu-debug",
147 | "displayName": "Clang x86_64 Linux (GNU ABI) Debug",
148 | "configurePreset": "clang-x86_64-linux-gnu",
149 | "configuration": "Debug"
150 | },
151 | {
152 | "name": "clang-x86_64-linux-gnu-relwithdebinfo",
153 | "displayName": "Clang x86_64 Linux (GNU ABI) RelWithDebInfo",
154 | "configurePreset": "clang-x86_64-linux-gnu",
155 | "configuration": "RelWithDebInfo"
156 | },
157 | {
158 | "name": "clang-x86_64-linux-gnu-release",
159 | "displayName": "Clang x86_64 Linux (GNU ABI) Release",
160 | "configurePreset": "clang-x86_64-linux-gnu",
161 | "configuration": "Release"
162 | }
163 | ]
164 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Ipotrick (Patrick Ahrens)
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 |
2 |
3 |
4 |
5 |
6 |
7 | # Daxa
8 |
9 | Daxa is my opinionated GPU API abstraction over Vulkan.
10 |
11 | Why would you want to use Daxa? These are some of the aspects of Daxa that set it apart from most other Vulkan abstractions:
12 |
13 | - Specifically designed for GPGPU programming and GPU-driven rendering. Daxa makes writing modern renderers simple and easy. It does not compromise for old hardware or old API concepts. Modern GPUs are the target (for Nvidia this is >=Turing, for AMD this is >= RDNA1).
14 |
15 | - Fully bindless. Buffers, images, samplers, and acceleration structures are all exclusively accessed via a bindless API. The bindless API abstracts descriptors completely. There are no bindings, no descriptor sets, no set layouts, no descriptor pools, and no binding or set indices within shaders.
16 |
17 | - Very high convenience with near zero boilerplate. Daxa makes the simple things as easy as possible. It abstracts over unnecessarily explicit parts of Vulkan. Tons of default values and common abstractions for renderers such as a render-graph and shader build system are provided by Daxa.
18 |
19 | - Shader utilities and shader feature integration. Daxa provides custom GLSL and HLSL headers, host/shader code sharing utilities, and even a shader build system featuring hot reloading and includes management. Especially the shader integration for many features is very convenient.
20 |
21 | - Efficient safety checks. An often neglected part of RHIs and rendering libraries is safety and debugging validation. Daxa performs many validation checks at very low overhead. Especially the render graph has very detailed error messages detailing misuse.
22 |
23 | - Effective abstractions with predictable performance. In contrast to many other abstractions, core Daxa never caches or lazily creates pipelines, layouts, or other objects. It should have performance as predictable as Vulkan. This makes profiling intuitive.
24 |
25 | ## Getting started
26 |
27 | To begin using Daxa, visit [daxa.dev](https://daxa.dev/), where you'll find a comprehensive tutorial and a Wiki containing detailed information about the Daxa API.
28 |
29 | - [Daxa Tutorial](https://tutorial.daxa.dev/)
30 | - [Daxa Wiki](https://wiki.daxa.dev/)
31 |
32 | Additionally, the Daxa repository includes a collection of example projects located in the **tests** folder
33 |
34 | For discussions or support, you can also join the Daxa [Discord server](https://discord.gg/MJPJvZ4FK5) if you prefer interacting there instead of using GitHub issues.
35 |
36 | ## List of biggest features
37 |
38 | - defaulted, named parameters for most functions via c++20 designated struct initialization
39 | - ergonomic, simplified object creation
40 | - easy device selection and properties query
41 | - integrated debug utilities such as debug names and range labels
42 | - feature-rich render-graph, handling automatic synchronization and more
43 | - shader integration for render-graph
44 | - shader/host code shading utilities
45 | - fully abstracted descriptor sets
46 | - automated, deeply integrated bindless system
47 | - shader bindless integration
48 | - a shader build system featuring hot reloading and `#include` handling
49 | - designed for threading, each object has its thread-safety described
50 | - no concept of render-pass or frame-buffer
51 | - typesafe simplified command recording and submission
52 | - automated memory allocation for buffers and images using VMA (manual allocation also possible)
53 | - swapchain that handles frames in flight pacing and WSI problems like resizing
54 | - always enabled dynamic state for any option that is cost-free on target hardware
55 | - simpler pipelines, no pipeline layout, and no descriptor set layouts
56 | - a full C API may be used to create API wrappers for other languages
57 | - extensive low-overhead validation checks
58 | - integrates most commonly used Vulkan extensions
59 | - support for buffer device addresses
60 | - always mapped buffers
61 | - mesh shaders, in core as well as pipeline manager
62 | - raytracing, in core, pipeline manager AND rendergraph
63 | - async compute/ async transfer/ multi-queue support
64 | - ergonomic explicit synchronization (optional, you can also use the render-graph instead)
65 | - stores queriable metadata for all objects, similar to dx11
66 | - simplified, semi-managed resource lifetimes
67 | - resource destruction is deferred until all currently submitted commands finish execution
68 | - unified IDs in host and shader code for buffers, images, etc.
69 | - automatic default image view integrated into all images
70 | - controllable parent-child lifetime semantics
71 | - fully abstracts Vulkan, allows Daxa to have more control and be more convenient
72 | - dearImGui backend
73 | - transient memory pool utility object
74 |
--------------------------------------------------------------------------------
/cmake/modules/FindWayland.cmake:
--------------------------------------------------------------------------------
1 | # temporary fix for wayland
2 |
3 | if(NOT WIN32)
4 | if(Wayland_INCLUDE_DIR AND Wayland_LIBRARIES)
5 | # In the cache already
6 | set(Wayland_FIND_QUIETLY TRUE)
7 | endif()
8 |
9 | # Use pkg-config to get the directories and then use these values
10 | # in the find_path() and find_library() calls
11 | find_package(PkgConfig)
12 | pkg_check_modules(PKG_Wayland QUIET wayland-client wayland-server wayland-egl wayland-cursor)
13 |
14 | set(Wayland_DEFINITIONS ${PKG_Wayland_CFLAGS})
15 |
16 | find_path(Wayland_CLIENT_INCLUDE_DIR NAMES wayland-client.h HINTS ${PKG_Wayland_INCLUDE_DIRS})
17 | find_path(Wayland_SERVER_INCLUDE_DIR NAMES wayland-server.h HINTS ${PKG_Wayland_INCLUDE_DIRS})
18 | find_path(Wayland_EGL_INCLUDE_DIR NAMES wayland-egl.h HINTS ${PKG_Wayland_INCLUDE_DIRS})
19 | find_path(Wayland_CURSOR_INCLUDE_DIR NAMES wayland-cursor.h HINTS ${PKG_Wayland_INCLUDE_DIRS})
20 |
21 | find_library(Wayland_CLIENT_LIBRARIES NAMES wayland-client HINTS ${PKG_Wayland_LIBRARY_DIRS})
22 | find_library(Wayland_SERVER_LIBRARIES NAMES wayland-server HINTS ${PKG_Wayland_LIBRARY_DIRS})
23 | find_library(Wayland_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_Wayland_LIBRARY_DIRS})
24 | find_library(Wayland_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_Wayland_LIBRARY_DIRS})
25 |
26 | set(Wayland_INCLUDE_DIR ${Wayland_CLIENT_INCLUDE_DIR} ${Wayland_SERVER_INCLUDE_DIR} ${Wayland_EGL_INCLUDE_DIR} ${Wayland_CURSOR_INCLUDE_DIR})
27 | set(Wayland_LIBRARIES ${Wayland_CLIENT_LIBRARIES} ${Wayland_SERVER_LIBRARIES} ${Wayland_EGL_LIBRARIES} ${Wayland_CURSOR_LIBRARIES})
28 | list(REMOVE_DUPLICATES Wayland_INCLUDE_DIR)
29 |
30 | include(FindPackageHandleStandardArgs)
31 | find_package_handle_standard_args(Wayland DEFAULT_MSG Wayland_LIBRARIES Wayland_INCLUDE_DIR)
32 |
33 | mark_as_advanced(Wayland_INCLUDE_DIR Wayland_LIBRARIES)
34 | endif()
35 |
--------------------------------------------------------------------------------
/cmake/packaging.cmake:
--------------------------------------------------------------------------------
1 |
2 | include(CMakePackageConfigHelpers)
3 | file(WRITE ${CMAKE_BINARY_DIR}/config.cmake.in [=[
4 | @PACKAGE_INIT@
5 | include(${CMAKE_CURRENT_LIST_DIR}/daxa-targets.cmake)
6 | check_required_components(daxa)
7 |
8 | get_target_property(DAXA_PREV_DEFINITIONS daxa::daxa INTERFACE_COMPILE_DEFINITIONS)
9 | set_target_properties(daxa::daxa PROPERTIES
10 | INTERFACE_COMPILE_DEFINITIONS "${DAXA_PREV_DEFINITIONS};DAXA_SHADER_INCLUDE_DIR=\"${PACKAGE_PREFIX_DIR}/include\""
11 | )
12 | ]=])
13 |
14 | # Re-exporting the find_package is necessary for Linux package management for some reason...
15 | file(APPEND ${CMAKE_BINARY_DIR}/config.cmake.in [=[
16 | find_package(Vulkan REQUIRED)
17 | find_package(VulkanMemoryAllocator CONFIG REQUIRED)
18 | ]=])
19 |
20 | if(DAXA_ENABLE_UTILS_FSR2)
21 | file(APPEND ${CMAKE_BINARY_DIR}/config.cmake.in [=[
22 | find_package(fsr2 CONFIG REQUIRED)
23 | ]=])
24 | endif()
25 | if(DAXA_ENABLE_UTILS_IMGUI)
26 | file(APPEND ${CMAKE_BINARY_DIR}/config.cmake.in [=[
27 | find_package(imgui CONFIG REQUIRED)
28 | ]=])
29 | endif()
30 | if(DAXA_ENABLE_UTILS_MEM)
31 | # No package management work to do
32 | endif()
33 | if(DAXA_ENABLE_UTILS_PIPELINE_MANAGER_GLSLANG)
34 | file(APPEND ${CMAKE_BINARY_DIR}/config.cmake.in [=[
35 | find_package(glslang CONFIG REQUIRED)
36 | find_package(Threads REQUIRED)
37 | ]=])
38 | endif()
39 | if(DAXA_ENABLE_UTILS_PIPELINE_MANAGER_SPIRV_VALIDATION)
40 | file(APPEND ${CMAKE_BINARY_DIR}/config.cmake.in [=[
41 | find_package(SPIRV-Tools CONFIG REQUIRED)
42 | ]=])
43 | endif()
44 | if(DAXA_ENABLE_UTILS_TASK_GRAPH)
45 | # No package management work to do
46 | endif()
47 |
48 | configure_package_config_file(${CMAKE_BINARY_DIR}/config.cmake.in
49 | ${CMAKE_CURRENT_BINARY_DIR}/daxa-config.cmake
50 | INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/daxa
51 | NO_SET_AND_CHECK_MACRO)
52 | write_basic_package_version_file(
53 | ${CMAKE_CURRENT_BINARY_DIR}/daxa-config-version.cmake
54 | VERSION ${PROJECT_VERSION}
55 | COMPATIBILITY SameMajorVersion)
56 | install(
57 | FILES
58 | ${CMAKE_CURRENT_BINARY_DIR}/daxa-config.cmake
59 | ${CMAKE_CURRENT_BINARY_DIR}/daxa-config-version.cmake
60 | DESTINATION
61 | ${CMAKE_INSTALL_DATADIR}/daxa)
62 | install(TARGETS daxa EXPORT daxa-targets)
63 | if(BUILD_SHARED_LIBS AND WIN32)
64 | install(FILES $ DESTINATION bin OPTIONAL)
65 | endif()
66 | install(EXPORT daxa-targets DESTINATION ${CMAKE_INSTALL_DATADIR}/daxa NAMESPACE daxa::)
67 | install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ TYPE INCLUDE)
68 |
--------------------------------------------------------------------------------
/cmake/toolchains/cl-x86_64-windows-msvc.cmake:
--------------------------------------------------------------------------------
1 | # Don't set the MSVC compiler.. This works when opening the folder in Visual Studio
2 | include(${CMAKE_CURRENT_LIST_DIR}/vcvars.cmake)
3 |
4 | find_program(CMAKE_C_COMPILER cl REQUIRED HINTS ${MSVC_ENV_Path})
5 | find_program(CMAKE_CXX_COMPILER cl REQUIRED HINTS ${MSVC_ENV_Path})
6 | find_program(CMAKE_MT mt REQUIRED HINTS ${MSVC_ENV_Path})
7 | find_program(CMAKE_RC_COMPILER rc REQUIRED HINTS ${MSVC_ENV_Path})
8 |
9 | set(CMAKE_CXX_COMPILER_FRONTEND_VARIANT MSVC)
10 | set(CMAKE_C_COMPILER_FRONTEND_VARIANT MSVC)
11 |
12 | list(APPEND CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${MSVC_ENV_INCLUDE})
13 | list(REMOVE_DUPLICATES CMAKE_C_STANDARD_INCLUDE_DIRECTORIES)
14 | set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_C_STANDARD_INCLUDE_DIRECTORIES} CACHE STRING "")
15 |
16 | list(APPEND CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${MSVC_ENV_INCLUDE})
17 | list(REMOVE_DUPLICATES CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES)
18 | set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES} CACHE STRING "")
19 |
20 | list(APPEND CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES ${MSVC_ENV_INCLUDE})
21 | list(REMOVE_DUPLICATES CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES)
22 | set(CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_RC_STANDARD_INCLUDE_DIRECTORIES} CACHE STRING "")
23 |
24 | foreach(libpath ${MSVC_ENV_LIBPATH} ${MSVC_ENV_LIB})
25 | set(CMAKE_SHARED_LINKER_FLAGS_INIT "${CMAKE_SHARED_LINKER_FLAGS_INIT} \"/LIBPATH:${libpath}\"")
26 | set(CMAKE_MODULE_LINKER_FLAGS_INIT "${CMAKE_MODULE_LINKER_FLAGS_INIT} \"/LIBPATH:${libpath}\"")
27 | set(CMAKE_EXE_LINKER_FLAGS_INIT "${CMAKE_EXE_LINKER_FLAGS_INIT} \"/LIBPATH:${libpath}\"")
28 | endforeach()
29 |
30 | list(APPEND LINK_DIRECTORIES $ENV{LIB} $ENV{LIBPATH})
31 | list(REMOVE_DUPLICATES LINK_DIRECTORIES)
32 | set(LINK_DIRECTORIES ${LINK_DIRECTORIES} CACHE STRING "")
33 | link_directories(BEFORE ${LINK_DIRECTORIES})
34 |
35 | list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES
36 | MSVC_ENV_INCLUDE
37 | MSVC_ENV_LIBPATH
38 | MSVC_ENV_VAR_NAMES
39 | MSVC_ENV_Path
40 | MSVC_ENV_LIB
41 | )
42 |
--------------------------------------------------------------------------------
/cmake/toolchains/clang-x86_64-linux-gnu.cmake:
--------------------------------------------------------------------------------
1 |
2 | set(CMAKE_SYSTEM_NAME Linux)
3 | set(CMAKE_SYSTEM_PROCESSOR x86_64)
4 |
5 | set(CMAKE_C_COMPILER_ID Clang)
6 | set(CMAKE_CXX_COMPILER_ID Clang)
7 |
--------------------------------------------------------------------------------
/cmake/toolchains/clang-x86_64-windows-msvc.cmake:
--------------------------------------------------------------------------------
1 |
2 | set(CMAKE_SYSTEM_NAME Windows)
3 | set(CMAKE_SYSTEM_PROCESSOR x86_64)
4 |
5 | set(CMAKE_C_COMPILER_ID Clang)
6 | set(CMAKE_CXX_COMPILER_ID Clang)
7 |
--------------------------------------------------------------------------------
/cmake/toolchains/gcc-x86_64-linux-gnu.cmake:
--------------------------------------------------------------------------------
1 |
2 | set(CMAKE_SYSTEM_NAME Linux)
3 | set(CMAKE_SYSTEM_PROCESSOR x86_64)
4 |
5 | set(CMAKE_C_COMPILER_ID GNU)
6 | set(CMAKE_CXX_COMPILER_ID GNU)
7 |
--------------------------------------------------------------------------------
/cmake/toolchains/vcvars.cmake:
--------------------------------------------------------------------------------
1 | function(msvc_inherit_from_vcvars)
2 | # vcvarsall.bat does not check if the PATH is already populated
3 | # with the necessary directories, and just naively appends them
4 | # to the existing PATH. Because of this, if this function gets
5 | # called more than a few times, it extends the PATH to exceed
6 | # a valid length and fails. Here I'm checking if the DevEnvDir
7 | # environment variable is set, and shortcutting this function
8 | # if so.
9 | # CMake will call the toolchain file multiple times when configuring
10 | # for the first time to do things like check if a compiler works
11 | # for a super simple file. Even though we check if we've set variables
12 | # in the cache to not re-call this function, the cache is NOT
13 | # populated until AFTER all the initial configuration is done,
14 | # therefore we must make sure that it's not a subsequent call from
15 | # checking the actual CMD environment
16 | execute_process(COMMAND cmd /c if defined DevEnvDir (exit 1) RESULT_VARIABLE CMD_RESULT)
17 | if(NOT CMD_RESULT EQUAL 0)
18 | return()
19 | endif()
20 |
21 | # Adapted from Modules/Platform/Windows-GNU.cmake
22 | set(VS_INSTALLER_PATHS "")
23 | set(VS_VERSIONS 17)
24 | foreach(VER ${VS_VERSIONS}) # change the first number to the largest supported version
25 | cmake_host_system_information(RESULT VS_DIR QUERY VS_${VER}_DIR)
26 | if(VS_DIR)
27 | list(APPEND VS_INSTALLER_PATHS "${VS_DIR}/VC/Auxiliary/Build")
28 | endif()
29 | endforeach()
30 |
31 | find_program(VCVARSALL_PATH NAMES vcvars64.bat vcvarsamd64.bat
32 | DOC "Visual Studio vcvarsamd64.bat"
33 | PATHS ${VS_INSTALLER_PATHS}
34 | )
35 |
36 | if(NOT EXISTS "${VCVARSALL_PATH}")
37 | message(FATAL_ERROR "Unknown VS version specified/no vcvarsall.bat detected")
38 | else()
39 | message("vcvars file at ${VCVARSALL_PATH}")
40 | endif()
41 | execute_process(COMMAND cmd /c echo {SET0} && set && echo {/SET0} && "${VCVARSALL_PATH}" x64 && echo {SET1} && set && echo {/SET1} OUTPUT_VARIABLE CMD_OUTPUT RESULT_VARIABLE CMD_RESULT)
42 | if(NOT CMD_RESULT EQUAL 0)
43 | message(FATAL_ERROR "command returned '${CMD_RESULT}'")
44 | endif()
45 |
46 | # Parse the command output
47 | set(REST "${CMD_OUTPUT}")
48 | string(FIND "${REST}" "{SET0}" BEG)
49 | string(SUBSTRING "${REST}" ${BEG} -1 REST)
50 | string(FIND "${REST}" "{/SET0}" END)
51 | string(SUBSTRING "${REST}" 0 ${END} SET0)
52 | string(SUBSTRING "${SET0}" 6 -1 SET0)
53 | string(FIND "${REST}" "{SET1}" BEG)
54 | string(SUBSTRING "${REST}" ${BEG} -1 REST)
55 | string(FIND "${REST}" "{/SET1}" END)
56 | string(SUBSTRING "${REST}" 0 ${END} SET1)
57 | string(SUBSTRING "${SET1}" 6 -1 SET1)
58 | string(REGEX MATCHALL "\n[0-9a-zA-Z_]*" SET0_VARS "${SET0}")
59 | list(TRANSFORM SET0_VARS STRIP)
60 | string(REGEX MATCHALL "\n[0-9a-zA-Z_]*" SET1_VARS "${SET1}")
61 | list(TRANSFORM SET1_VARS STRIP)
62 |
63 | function(_extract_from_set_command INPUT VARNAME OUTVAR_NAME)
64 | set(R "${INPUT}")
65 | string(FIND "${R}" "\n${VARNAME}=" B)
66 | if(B EQUAL -1)
67 | set(${OUTVAR_NAME} "" PARENT_SCOPE)
68 | return()
69 | endif()
70 | string(SUBSTRING "${R}" ${B} -1 R)
71 | string(SUBSTRING "${R}" 1 -1 R)
72 | string(FIND "${R}" "\n" E)
73 | string(SUBSTRING "${R}" 0 ${E} OUT_TEMP)
74 | string(LENGTH "${VARNAME}=" VARNAME_LEN)
75 | string(SUBSTRING "${OUT_TEMP}" ${VARNAME_LEN} -1 OUT_TEMP)
76 | set(${OUTVAR_NAME} "${OUT_TEMP}" PARENT_SCOPE)
77 | endfunction()
78 | set(CHANGED_VARS)
79 | # Run over all the vars in set1 (the set containing all the new environment vars)
80 | # and compare their values to their respective value in set0 (the value before
81 | # running vcvarsall)
82 | foreach(V ${SET1_VARS})
83 | _extract_from_set_command("${SET0}" ${V} V0)
84 | _extract_from_set_command("${SET1}" ${V} V1)
85 | if(NOT ("${V0}" STREQUAL "${V1}"))
86 | # if it is different, then we'll add it to the list
87 | list(APPEND CHANGED_VARS ${V})
88 | # and also we'll cache it as the value from set1.
89 | if(V STREQUAL "Path")
90 | string(REGEX REPLACE "\\\\" "/" V1 "${V1}")
91 | endif()
92 | set(MSVC_ENV_${V} "${V1}" CACHE STRING "")
93 | endif()
94 | endforeach()
95 | set(MSVC_ENV_VAR_NAMES ${CHANGED_VARS} CACHE STRING "")
96 | endfunction()
97 |
98 | if(NOT DEFINED MSVC_ENV_VAR_NAMES)
99 | msvc_inherit_from_vcvars()
100 | endif()
101 |
--------------------------------------------------------------------------------
/cmake/vcpkg-overlay-ports/fsr2/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "fsr2",
3 | "version": "2.2.0",
4 | "description": "Unofficial FSR 2.2 API",
5 | "features": {
6 | "vulkan": {
7 | "description": "Build for Vulkan",
8 | "dependencies": [
9 | "vulkan"
10 | ]
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/cmake/vcpkg-overlay-ports/glfw3/portfile.cmake:
--------------------------------------------------------------------------------
1 | vcpkg_from_git(
2 | OUT_SOURCE_PATH SOURCE_PATH
3 | URL https://github.com/glfw/glfw
4 | REF 8f470597d625ae28758c16b4293dd42d63e8a83a
5 | )
6 |
7 | if(VCPKG_TARGET_IS_LINUX)
8 | message(
9 | "GLFW3 currently requires the following libraries from the system package manager:
10 | xinerama
11 | xcursor
12 | xorg
13 | libglu1-mesa
14 | These can be installed on Ubuntu systems via sudo apt install libxinerama-dev libxcursor-dev xorg-dev libglu1-mesa-dev")
15 | endif()
16 |
17 | vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
18 | FEATURES
19 | xlib WITH_XLIB
20 | wayland WITH_WAYLAND
21 | )
22 | set(GLFW_DEFINES)
23 | if(WITH_XLIB)
24 | list(APPEND GLFW_DEFINES "-DGLFW_BUILD_X11=true")
25 | endif()
26 | if(WITH_WAYLAND)
27 | list(APPEND GLFW_DEFINES "-DGLFW_BUILD_WAYLAND=true")
28 | endif()
29 |
30 | vcpkg_cmake_configure(
31 | SOURCE_PATH "${SOURCE_PATH}"
32 | OPTIONS
33 | -DGLFW_BUILD_EXAMPLES=OFF
34 | -DGLFW_BUILD_TESTS=OFF
35 | -DGLFW_BUILD_DOCS=OFF
36 | ${GLFW_DEFINES}
37 | )
38 |
39 | vcpkg_cmake_install()
40 | vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/glfw3)
41 | vcpkg_fixup_pkgconfig()
42 |
43 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
44 | file(INSTALL "${SOURCE_PATH}/LICENSE.md" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}" RENAME copyright)
45 |
46 | vcpkg_copy_pdbs()
47 |
--------------------------------------------------------------------------------
/cmake/vcpkg-overlay-ports/glfw3/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "glfw3",
3 | "version-string": "custom",
4 | "description": "GLFW is a free, Open Source, multi-platform library for OpenGL, OpenGL ES and Vulkan application development. It provides a simple, platform-independent API for creating windows, contexts and surfaces, reading input, handling events, etc.",
5 | "homepage": "https://github.com/glfw/glfw",
6 | "license": "Zlib",
7 | "dependencies": [
8 | {
9 | "name": "vcpkg-cmake",
10 | "host": true
11 | },
12 | {
13 | "name": "vcpkg-cmake-config",
14 | "host": true
15 | },
16 | {
17 | "name": "wayland",
18 | "default-features": false,
19 | "platform": "linux"
20 | },
21 | {
22 | "name": "wayland-protocols",
23 | "default-features": false,
24 | "platform": "linux"
25 | }
26 | ],
27 | "features": {
28 | "xlib": {
29 | "description": "Build with XLib support"
30 | },
31 | "wayland": {
32 | "description": "Build with Wayland support"
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/cmake/vcpkg.cmake:
--------------------------------------------------------------------------------
1 |
2 | if(NOT (CMAKE_TOOLCHAIN_FILE MATCHES "/scripts/buildsystems/vcpkg.cmake") AND DEFINED CMAKE_TOOLCHAIN_FILE)
3 | set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${CMAKE_TOOLCHAIN_FILE}" CACHE UNINITIALIZED "")
4 | endif()
5 |
6 | if(EXISTS "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
7 | file(TO_CMAKE_PATH $ENV{VCPKG_ROOT} VCPKG_ROOT)
8 | set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
9 | else()
10 | find_package(Git REQUIRED)
11 | if(NOT EXISTS "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
12 | execute_process(COMMAND ${GIT_EXECUTABLE} clone https://github.com/Microsoft/vcpkg
13 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
14 | COMMAND_ERROR_IS_FATAL ANY)
15 | else()
16 | execute_process(COMMAND ${GIT_EXECUTABLE} pull
17 | WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/vcpkg"
18 | COMMAND_ERROR_IS_FATAL ANY)
19 | endif()
20 | set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake")
21 | endif()
22 |
--------------------------------------------------------------------------------
/cmake/warnings.cmake:
--------------------------------------------------------------------------------
1 | function(set_project_warnings project_name)
2 | option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" OFF)
3 |
4 | set(MSVC_WARNINGS
5 | /W4 # Baseline reasonable warnings
6 | /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data
7 | /w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
8 | /w14263 # 'function': member function does not override any base class virtual member function
9 | /w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not
10 | # be destructed correctly
11 | /w14287 # 'operator': unsigned/negative constant mismatch
12 | /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside
13 | # the for-loop scope
14 | /w14296 # 'operator': expression is always 'boolean_value'
15 | /w14311 # 'variable': pointer truncation from 'type1' to 'type2'
16 | /w14545 # expression before comma evaluates to a function which is missing an argument list
17 | /w14546 # function call before comma missing argument list
18 | /w14547 # 'operator': operator before comma has no effect; expected operator with side-effect
19 | /w14549 # 'operator': operator before comma has no effect; did you intend 'operator'?
20 | /w14555 # expression has no effect; expected expression with side- effect
21 | /w14619 # pragma warning: there is no warning number 'number'
22 | /w14640 # Enable warning on thread un-safe static member initialization
23 | /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior.
24 | /w14905 # wide string literal cast to 'LPSTR'
25 | /w14906 # string literal cast to 'LPWSTR'
26 | /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied
27 | /permissive- # standards conformance mode for MSVC compiler.
28 | )
29 |
30 | set(CLANG_WARNINGS
31 | -Wall
32 | -Wextra # reasonable and standard
33 | -Wshadow # warn the user if a variable declaration shadows one from a parent context
34 | -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps
35 | # catch hard to track down memory errors
36 | -Wold-style-cast # warn for c-style casts
37 | -Wcast-align # warn for potential performance problem casts
38 | -Wunused # warn on anything being unused
39 | -Woverloaded-virtual # warn if you overload (not override) a virtual function
40 | -Wpedantic # warn if non-standard C++ is used
41 | -Wconversion # warn on type conversions that may lose data
42 | -Wsign-conversion # warn on sign conversions
43 | -Wnull-dereference # warn if a null dereference is detected
44 | -Wdouble-promotion # warn if float is implicit promoted to double
45 | -Wformat=2 # warn on security issues around functions that format output (ie printf)
46 | -Wimplicit-fallthrough # warn on statements that fallthrough without an explicit annotation
47 | -Wno-language-extension-token # disable this because of DXC code
48 | )
49 |
50 | if(WARNINGS_AS_ERRORS)
51 | set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror)
52 | set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX)
53 | endif()
54 |
55 | set(GCC_WARNINGS
56 | ${CLANG_WARNINGS}
57 | -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist
58 | -Wduplicated-cond # warn if if / else chain has duplicated conditions
59 | -Wduplicated-branches # warn if if / else branches have duplicated code
60 | -Wlogical-op # warn about logical operations being used where bitwise were probably wanted
61 | -Wuseless-cast # warn if you perform a cast to the same type
62 | -Wno-strict-aliasing # DISABLE THIS BOGUS
63 | )
64 |
65 | if(MSVC)
66 | set(PROJECT_WARNINGS ${MSVC_WARNINGS})
67 | elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang")
68 | set(PROJECT_WARNINGS ${CLANG_WARNINGS})
69 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
70 | set(PROJECT_WARNINGS ${GCC_WARNINGS})
71 | else()
72 | message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.")
73 | endif()
74 |
75 | target_compile_options(${project_name} PUBLIC $)
76 |
77 | endfunction()
--------------------------------------------------------------------------------
/include/daxa/c/core.h:
--------------------------------------------------------------------------------
1 | #ifndef __DAXA_CORE_H__
2 | #define __DAXA_CORE_H__
3 |
4 | #include
5 |
6 | #if defined(__cplusplus)
7 | #define DAXA_EXPORT extern "C" DAXA_CMAKE_EXPORT
8 | #if defined(__linux__)
9 | #define DAXA_EXPORT_CXX
10 | #else
11 | #define DAXA_EXPORT_CXX DAXA_CMAKE_EXPORT
12 | #endif
13 | #define DAXA_ZERO_INIT {}
14 | #else
15 | #define DAXA_EXPORT DAXA_CMAKE_EXPORT
16 | #define DAXA_ZERO_INIT {0}
17 | #endif
18 |
19 | #if defined(__cplusplus)
20 | #define DAXA_NO_DISCARD [[nodiscard]]
21 | #else
22 | #define DAXA_NO_DISCARD
23 | #endif
24 |
25 | #define _DAXA_TEST_PRINT(...)
26 |
27 | static uint32_t const DAXA_ID_INDEX_BITS = 20;
28 | static uint32_t const DAXA_ID_INDEX_MASK = (1ull << 20) - 1ull;
29 | static uint32_t const DAXA_ID_INDEX_OFFSET = 0;
30 | static uint32_t const DAXA_ID_VERSION_BITS = 44;
31 | static uint64_t const DAXA_ID_VERSION_MASK = (1ull << 44) - 1ull;
32 | static uint32_t const DAXA_ID_VERSION_OFFSET = 20;
33 |
34 | typedef struct daxa_ImplDevice * daxa_Device;
35 | typedef struct daxa_ImplCommandRecorder * daxa_CommandRecorder;
36 | typedef struct daxa_ImplExecutableCommandList * daxa_ExecutableCommandList;
37 | typedef struct daxa_ImplInstance * daxa_Instance;
38 | typedef struct daxa_ImplRayTracingPipeline * daxa_RayTracingPipeline;
39 | typedef struct daxa_ImplComputePipeline * daxa_ComputePipeline;
40 | typedef struct daxa_ImplRasterPipeline * daxa_RasterPipeline;
41 | typedef struct daxa_ImplSwapchain * daxa_Swapchain;
42 | typedef struct daxa_ImplBinarySemaphore * daxa_BinarySemaphore;
43 | typedef struct daxa_ImplTimelineSemaphore * daxa_TimelineSemaphore;
44 | typedef struct daxa_ImplEvent * daxa_Event;
45 | typedef struct daxa_ImplTimelineQueryPool * daxa_TimelineQueryPool;
46 | typedef struct daxa_ImplMemoryBlock * daxa_MemoryBlock;
47 |
48 | typedef uint64_t daxa_Flags;
49 |
50 | typedef char daxa_Bool8;
51 |
52 | typedef struct
53 | {
54 | uint64_t value;
55 | } daxa_BufferId;
56 |
57 | typedef struct
58 | {
59 | uint64_t value;
60 | } daxa_ImageId;
61 |
62 | typedef struct
63 | {
64 | uint64_t value;
65 | } daxa_ImageViewId;
66 |
67 | typedef struct
68 | {
69 | uint32_t value;
70 | } daxa_ImageViewIndex;
71 |
72 | typedef struct
73 | {
74 | uint64_t value;
75 | } daxa_SamplerId;
76 |
77 | typedef struct
78 | {
79 | uint64_t value;
80 | } daxa_TlasId;
81 |
82 | typedef struct
83 | {
84 | uint64_t value;
85 | } daxa_BlasId;
86 |
87 | #define _DAXA_DECL_VEC2_TYPE(SCALAR_TYPE) \
88 | typedef struct \
89 | { \
90 | SCALAR_TYPE x; \
91 | SCALAR_TYPE y; \
92 | }
93 | typedef uint32_t daxa_b32;
94 | typedef int32_t daxa_i32;
95 | typedef uint32_t daxa_u32;
96 | typedef int64_t daxa_i64;
97 | typedef uint64_t daxa_u64;
98 | typedef float daxa_f32;
99 | typedef double daxa_f64;
100 |
101 | #if defined(__GNUC__) || defined(__clang__)
102 | #pragma GCC diagnostic push
103 | #pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
104 | #elif defined(_MSC_VER)
105 | #pragma warning(push)
106 | #pragma warning(disable : 4201)
107 | #endif
108 |
109 | _DAXA_DECL_VEC2_TYPE(daxa_f32)
110 | daxa_f32vec2;
111 | _DAXA_DECL_VEC2_TYPE(daxa_f64)
112 | daxa_f64vec2;
113 | _DAXA_DECL_VEC2_TYPE(daxa_u32)
114 | daxa_u32vec2;
115 | _DAXA_DECL_VEC2_TYPE(daxa_i32)
116 | daxa_i32vec2;
117 |
118 | #define _DAXA_DECL_VEC3_TYPE(SCALAR_TYPE) \
119 | typedef struct \
120 | { \
121 | SCALAR_TYPE x; \
122 | SCALAR_TYPE y; \
123 | SCALAR_TYPE z; \
124 | }
125 |
126 | _DAXA_DECL_VEC3_TYPE(daxa_f32)
127 | daxa_f32vec3;
128 | _DAXA_DECL_VEC3_TYPE(daxa_f64)
129 | daxa_f64vec3;
130 | _DAXA_DECL_VEC3_TYPE(daxa_u32)
131 | daxa_u32vec3;
132 | _DAXA_DECL_VEC3_TYPE(daxa_i32)
133 | daxa_i32vec3;
134 |
135 | #define _DAXA_DECL_VEC4_TYPE(SCALAR_TYPE) \
136 | typedef struct \
137 | { \
138 | SCALAR_TYPE x; \
139 | SCALAR_TYPE y; \
140 | SCALAR_TYPE z; \
141 | SCALAR_TYPE w; \
142 | }
143 | _DAXA_DECL_VEC4_TYPE(daxa_f32)
144 | daxa_f32vec4;
145 | _DAXA_DECL_VEC4_TYPE(daxa_f64)
146 | daxa_f64vec4;
147 | _DAXA_DECL_VEC4_TYPE(daxa_u32)
148 | daxa_u32vec4;
149 | _DAXA_DECL_VEC4_TYPE(daxa_i32)
150 | daxa_i32vec4;
151 | _DAXA_DECL_VEC2_TYPE(daxa_f32vec2)
152 | daxa_f32mat2x2;
153 | _DAXA_DECL_VEC2_TYPE(daxa_f32vec3)
154 | daxa_f32mat2x3;
155 | _DAXA_DECL_VEC2_TYPE(daxa_f32vec4)
156 | daxa_f32mat2x4;
157 | _DAXA_DECL_VEC2_TYPE(daxa_f64vec2)
158 | daxa_f64mat2x2;
159 | _DAXA_DECL_VEC2_TYPE(daxa_f64vec3)
160 | daxa_f64mat2x3;
161 | _DAXA_DECL_VEC2_TYPE(daxa_f64vec4)
162 | daxa_f64mat2x4;
163 | _DAXA_DECL_VEC3_TYPE(daxa_f32vec2)
164 | daxa_f32mat3x2;
165 | _DAXA_DECL_VEC3_TYPE(daxa_f32vec3)
166 | daxa_f32mat3x3;
167 | _DAXA_DECL_VEC3_TYPE(daxa_f32vec4)
168 | daxa_f32mat3x4;
169 | _DAXA_DECL_VEC3_TYPE(daxa_f64vec2)
170 | daxa_f64mat3x2;
171 | _DAXA_DECL_VEC3_TYPE(daxa_f64vec3)
172 | daxa_f64mat3x3;
173 | _DAXA_DECL_VEC3_TYPE(daxa_f64vec4)
174 | daxa_f64mat3x4;
175 | _DAXA_DECL_VEC4_TYPE(daxa_f32vec2)
176 | daxa_f32mat4x2;
177 | _DAXA_DECL_VEC4_TYPE(daxa_f32vec3)
178 | daxa_f32mat4x3;
179 | _DAXA_DECL_VEC4_TYPE(daxa_f32vec4)
180 | daxa_f32mat4x4;
181 | _DAXA_DECL_VEC4_TYPE(daxa_f64vec2)
182 | daxa_f64mat4x2;
183 | _DAXA_DECL_VEC4_TYPE(daxa_f64vec3)
184 | daxa_f64mat4x3;
185 | _DAXA_DECL_VEC4_TYPE(daxa_f64vec4)
186 | daxa_f64mat4x4;
187 | _DAXA_DECL_VEC2_TYPE(daxa_i32vec2)
188 | daxa_i32mat2x2;
189 | _DAXA_DECL_VEC2_TYPE(daxa_i32vec3)
190 | daxa_i32mat2x3;
191 | _DAXA_DECL_VEC2_TYPE(daxa_i32vec4)
192 | daxa_i32mat2x4;
193 | _DAXA_DECL_VEC2_TYPE(daxa_u32vec2)
194 | daxa_u32mat2x2;
195 | _DAXA_DECL_VEC2_TYPE(daxa_u32vec3)
196 | daxa_u32mat2x3;
197 | _DAXA_DECL_VEC2_TYPE(daxa_u32vec4)
198 | daxa_u32mat2x4;
199 | _DAXA_DECL_VEC3_TYPE(daxa_i32vec2)
200 | daxa_i32mat3x2;
201 | _DAXA_DECL_VEC3_TYPE(daxa_i32vec3)
202 | daxa_i32mat3x3;
203 | _DAXA_DECL_VEC3_TYPE(daxa_i32vec4)
204 | daxa_i32mat3x4;
205 | _DAXA_DECL_VEC3_TYPE(daxa_u32vec2)
206 | daxa_u32mat3x2;
207 | _DAXA_DECL_VEC3_TYPE(daxa_u32vec3)
208 | daxa_u32mat3x3;
209 | _DAXA_DECL_VEC3_TYPE(daxa_u32vec4)
210 | daxa_u32mat3x4;
211 | _DAXA_DECL_VEC4_TYPE(daxa_i32vec2)
212 | daxa_i32mat4x2;
213 | _DAXA_DECL_VEC4_TYPE(daxa_i32vec3)
214 | daxa_i32mat4x3;
215 | _DAXA_DECL_VEC4_TYPE(daxa_i32vec4)
216 | daxa_i32mat4x4;
217 | _DAXA_DECL_VEC4_TYPE(daxa_u32vec2)
218 | daxa_u32mat4x2;
219 | _DAXA_DECL_VEC4_TYPE(daxa_u32vec3)
220 | daxa_u32mat4x3;
221 | _DAXA_DECL_VEC4_TYPE(daxa_u32vec4)
222 | daxa_u32mat4x4;
223 |
224 | #define DAXA_SMALL_STRING_CAPACITY 63
225 |
226 | #if defined(__GNUC__) || defined(__clang__)
227 | #pragma GCC diagnostic pop
228 | #elif defined(_MSC_VER)
229 | #pragma warning(pop)
230 | #endif
231 |
232 | static uint32_t const DAXA_MAX_PUSH_CONSTANT_WORD_SIZE = (32);
233 | static uint32_t const DAXA_MAX_PUSH_CONSTANT_BYTE_SIZE = (DAXA_MAX_PUSH_CONSTANT_WORD_SIZE * 4);
234 | static uint32_t const DAXA_PIPELINE_LAYOUT_COUNT = (DAXA_MAX_PUSH_CONSTANT_WORD_SIZE + 1);
235 |
236 | // TODO(Raytracing): Should this say like this?
237 | static uint32_t const DAXA_GEOMETRY_INSTANCE_TRIANGLE_FACING_CULL_DISABLE = 0x00000001;
238 | static uint32_t const DAXA_GEOMETRY_INSTANCE_TRIANGLE_FLIP_FACING = 0x00000002;
239 | static uint32_t const DAXA_GEOMETRY_INSTANCE_FORCE_OPAQUE = 0x00000004;
240 | static uint32_t const DAXA_GEOMETRY_INSTANCE_FORCE_NO_OPAQUE = 0x00000008;
241 |
242 | /// ABI: Must stay compatible with 'VkAccelerationStructureInstanceKHR'
243 | typedef struct
244 | {
245 | daxa_f32mat3x4 transform;
246 | uint32_t instance_custom_index : 24;
247 | uint32_t mask : 8;
248 | uint32_t instance_shader_binding_table_record_offset : 24;
249 | uint32_t flags : 8;
250 | uint64_t blas_device_address;
251 | } daxa_BlasInstanceData;
252 |
253 | #endif
254 |
--------------------------------------------------------------------------------
/include/daxa/c/daxa.h:
--------------------------------------------------------------------------------
1 | #ifndef __DAXA_H__
2 | #define __DAXA_H__
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #endif // #ifndef __DAXA_H__
12 |
--------------------------------------------------------------------------------
/include/daxa/c/instance.h:
--------------------------------------------------------------------------------
1 | #ifndef __DAXA_INSTANCE_H__
2 | #define __DAXA_INSTANCE_H__
3 |
4 | #include
5 |
6 | typedef daxa_Flags daxa_InstanceFlags;
7 | static const daxa_InstanceFlags DAXA_INSTANCE_FLAG_DEBUG_UTIL = 0x1;
8 | static const daxa_InstanceFlags DAXA_INSTANCE_FLAG_PARENT_MUST_OUTLIVE_CHILD = 0x2;
9 |
10 | typedef struct
11 | {
12 | daxa_InstanceFlags flags;
13 | daxa_SmallString engine_name;
14 | daxa_SmallString app_name;
15 | } daxa_InstanceInfo;
16 |
17 | static const daxa_InstanceInfo DAXA_DEFAULT_INSTANCE_INFO = {
18 | .flags = DAXA_INSTANCE_FLAG_DEBUG_UTIL,
19 | .engine_name = {.data = "daxa", .size = 4},
20 | .app_name = {.data = "daxa app", .size = 8},
21 | };
22 |
23 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
24 | daxa_create_instance(daxa_InstanceInfo const * info, daxa_Instance * out_instance);
25 |
26 | /// WARNING: DEPRECATED, use daxa_instance_create_device_2 instead!
27 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
28 | daxa_instance_create_device(daxa_Instance instance, daxa_DeviceInfo const * info, daxa_Device * out_device);
29 |
30 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
31 | daxa_instance_create_device_2(daxa_Instance instance, daxa_DeviceInfo2 const * info, daxa_Device * out_device);
32 |
33 | // Can be used to autofill the physical_device_index in a partially filled daxa_DeviceInfo2.
34 | DAXA_EXPORT daxa_Result
35 | daxa_instance_choose_device(daxa_Instance instance, daxa_ImplicitFeatureFlags desired_implicit_features, daxa_DeviceInfo2 * info);
36 |
37 | // Returns previous ref count.
38 | DAXA_EXPORT uint64_t
39 | daxa_instance_inc_refcnt(daxa_Instance instance);
40 | // Returns previous ref count.
41 | DAXA_EXPORT uint64_t
42 | daxa_instance_dec_refcnt(daxa_Instance instance);
43 |
44 | DAXA_EXPORT daxa_InstanceInfo const *
45 | daxa_instance_info(daxa_Instance instance);
46 |
47 | DAXA_EXPORT VkInstance
48 | daxa_instance_get_vk_instance(daxa_Instance instance);
49 |
50 | DAXA_EXPORT void
51 | daxa_instance_list_devices_properties(daxa_Instance instance, daxa_DeviceProperties const** properties, daxa_u32 * property_count);
52 |
53 | #endif // #ifndef __DAXA_INSTANCE_H__
54 |
--------------------------------------------------------------------------------
/include/daxa/c/swapchain.h:
--------------------------------------------------------------------------------
1 | #ifndef __DAXA_SWAPCHAIN_H__
2 | #define __DAXA_SWAPCHAIN_H__
3 |
4 | #include
5 | #include
6 |
7 | DAXA_EXPORT int32_t
8 | daxa_default_format_selector(VkFormat format);
9 |
10 | /// @brief A platform-dependent window resource.
11 | /// On Windows, this is an `HWND`
12 | /// On Linux X11, this is a `Window`
13 | /// On Linux Wayland, this is a `wl_surface *`
14 | typedef void * daxa_NativeWindowHandle;
15 |
16 | typedef enum
17 | {
18 | DAXA_NATIVE_WINDOW_PLATFORM_UNKNOWN,
19 | DAXA_NATIVE_WINDOW_PLATFORM_WIN32_API,
20 | DAXA_NATIVE_WINDOW_PLATFORM_XLIB_API,
21 | DAXA_NATIVE_WINDOW_PLATFORM_WAYLAND_API,
22 | DAXA_NATIVE_WINDOW_PLATFORM_MAX_ENUM = 0x7fffffff,
23 | } daxa_NativeWindowPlatform;
24 |
25 | typedef struct
26 | {
27 | daxa_NativeWindowHandle native_window;
28 | daxa_NativeWindowPlatform native_window_platform;
29 | int32_t (*surface_format_selector)(VkFormat);
30 | VkPresentModeKHR present_mode;
31 | VkSurfaceTransformFlagBitsKHR present_operation;
32 | daxa_ImageUsageFlags image_usage;
33 | size_t max_allowed_frames_in_flight;
34 | daxa_QueueFamily queue_family;
35 | daxa_SmallString name;
36 | } daxa_SwapchainInfo;
37 |
38 | DAXA_EXPORT VkExtent2D
39 | daxa_swp_get_surface_extent(daxa_Swapchain swapchain);
40 | DAXA_EXPORT VkFormat
41 | daxa_swp_get_format(daxa_Swapchain swapchain);
42 | DAXA_EXPORT VkColorSpaceKHR
43 | daxa_swp_get_color_space(daxa_Swapchain swapchain);
44 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
45 | daxa_swp_resize(daxa_Swapchain swapchain);
46 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
47 | daxa_swp_set_present_mode(daxa_Swapchain swapchain, VkPresentModeKHR present_mode);
48 |
49 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
50 | daxa_swp_wait_for_next_frame(daxa_Swapchain swapchain);
51 | DAXA_EXPORT DAXA_NO_DISCARD daxa_Result
52 | daxa_swp_acquire_next_image(daxa_Swapchain swapchain, daxa_ImageId * out_image_id);
53 | DAXA_EXPORT daxa_BinarySemaphore *
54 | daxa_swp_current_acquire_semaphore(daxa_Swapchain swapchain);
55 | DAXA_EXPORT daxa_BinarySemaphore *
56 | daxa_swp_current_present_semaphore(daxa_Swapchain swapchain);
57 | DAXA_EXPORT uint64_t
58 | daxa_swp_current_cpu_timeline_value(daxa_Swapchain swapchain);
59 | DAXA_EXPORT daxa_TimelineSemaphore *
60 | daxa_swp_gpu_timeline_semaphore(daxa_Swapchain swapchain);
61 |
62 | DAXA_EXPORT daxa_SwapchainInfo const *
63 | daxa_swp_info(daxa_Swapchain swapchain);
64 |
65 | DAXA_EXPORT VkSwapchainKHR
66 | daxa_swp_get_vk_swapchain(daxa_Swapchain swapchain);
67 | DAXA_EXPORT VkSurfaceKHR
68 | daxa_swp_get_vk_surface(daxa_Swapchain swapchain);
69 | DAXA_EXPORT uint64_t
70 | daxa_swp_inc_refcnt(daxa_Swapchain swapchain);
71 | DAXA_EXPORT uint64_t
72 | daxa_swp_dec_refcnt(daxa_Swapchain swapchain);
73 |
74 | #endif // #ifndef __DAXA_SWAPCHAIN_H__
75 |
--------------------------------------------------------------------------------
/include/daxa/core.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | #if !defined(DAXA_VALIDATION)
8 | #if defined(NDEBUG)
9 | #define DAXA_VALIDATION 0
10 | #else
11 | #define DAXA_VALIDATION 1
12 | #endif
13 | #endif
14 |
15 | #if DAXA_VALIDATION
16 | #include
17 | #include
18 |
19 | #define DAXA_GPU_ID_VALIDATION 1
20 |
21 | #define DAXA_DBG_ASSERT_FAIL_STRING "[[DAXA ASSERT FAILURE]]"
22 |
23 | #define DAXA_DBG_ASSERT_TRUE_M(x, m) \
24 | do \
25 | { \
26 | if (std::is_constant_evaluated()) \
27 | { \
28 | /* how do we check this??? static_assert(x); */ \
29 | } \
30 | else if (!(x)) \
31 | { \
32 | std::cerr << DAXA_DBG_ASSERT_FAIL_STRING << ": " << (m) << std::endl; \
33 | throw std::runtime_error("DAXA DEBUG ASSERTION FAILURE"); \
34 | } \
35 | } while (false)
36 | #define DAXA_DBG_ASSERT_TRUE_MS(x, STREAM) \
37 | do \
38 | { \
39 | if (std::is_constant_evaluated()) \
40 | { \
41 | /* how do we check this??? static_assert(x); */ \
42 | } \
43 | else if (!(x)) \
44 | { \
45 | std::cerr << DAXA_DBG_ASSERT_FAIL_STRING << ": " STREAM << std::endl; \
46 | throw std::runtime_error("DAXA DEBUG ASSERTION FAILURE"); \
47 | } \
48 | } while (false)
49 | #else
50 |
51 | #define DAXA_DBG_ASSERT_TRUE_M(x, m)
52 | #define DAXA_DBG_ASSERT_TRUE_MS(x, m)
53 |
54 | #endif
55 |
56 | #if !defined(DAXA_GPU_ID_VALIDATION)
57 | #define DAXA_GPU_ID_VALIDATION 0
58 | #endif
59 |
60 | #if !defined(DAXA_REMOVE_DEPRECATED)
61 | #define DAXA_REMOVE_DEPRECATED 1
62 | #endif
63 |
64 | namespace daxa
65 | {
66 | /// @brief A platform-dependent window resource.
67 | /// On Windows, this is an `HWND`
68 | /// On Linux X11, this is a `Window`
69 | /// On Linux Wayland, this is a `wl_surface *`
70 | using NativeWindowHandle = void *;
71 |
72 | enum struct NativeWindowPlatform
73 | {
74 | UNKNOWN,
75 | WIN32_API,
76 | XLIB_API,
77 | WAYLAND_API,
78 | MAX_ENUM = 0x7fffffff,
79 | };
80 | } // namespace daxa
81 |
82 | namespace daxa
83 | {
84 | template
85 | struct Result
86 | {
87 | std::optional v = {};
88 | std::string m = {};
89 |
90 | explicit Result(T && value)
91 | : v{std::move(value)}, m{""}
92 | {
93 | }
94 |
95 | explicit Result(T const & value)
96 | : v{value}, m{""}
97 | {
98 | }
99 |
100 | explicit Result(std::optional && opt)
101 | : v{std::move(opt)}, m{opt.has_value() ? "" : "default error message"}
102 | {
103 | }
104 |
105 | explicit Result(std::optional const & opt)
106 | : v{opt}, m{opt.has_value() ? "" : "default error message"}
107 | {
108 | }
109 |
110 | explicit Result(std::string_view message)
111 | : v{std::nullopt}, m{message}
112 | {
113 | }
114 |
115 | bool is_ok() const
116 | {
117 | return v.has_value();
118 | }
119 |
120 | bool is_err() const
121 | {
122 | return !v.has_value();
123 | }
124 |
125 | auto value() const -> T const &
126 | {
127 | return v.value();
128 | }
129 |
130 | auto value() -> T &
131 | {
132 | DAXA_DBG_ASSERT_TRUE_M(v.has_value(), (m != "" ? m : "tried getting value of empty Result"));
133 | return v.value();
134 | }
135 |
136 | auto message() const -> std::string const &
137 | {
138 | return m;
139 | }
140 |
141 | auto to_string() const -> std::string
142 | {
143 | if (v.has_value())
144 | {
145 | return "Result OK";
146 | }
147 | else
148 | {
149 | return std::string("Result Err: ") + m;
150 | }
151 | }
152 |
153 | operator bool() const
154 | {
155 | return v.has_value();
156 | }
157 |
158 | auto operator!() const -> bool
159 | {
160 | return !v.has_value();
161 | }
162 | };
163 |
164 | template <>
165 | struct Result
166 | {
167 | bool v = {};
168 | std::string m = {};
169 |
170 | explicit Result(bool opt)
171 | : v{opt}, m{opt ? "" : "default error message"}
172 | {
173 | }
174 |
175 | explicit Result(std::string_view message)
176 | : v{false}, m{message}
177 | {
178 | }
179 |
180 | bool is_ok() const
181 | {
182 | return v;
183 | }
184 |
185 | bool is_err() const
186 | {
187 | return !v;
188 | }
189 |
190 | auto message() const -> std::string const &
191 | {
192 | return m;
193 | }
194 |
195 | auto to_string() const -> std::string
196 | {
197 | if (v)
198 | {
199 | return "Result OK";
200 | }
201 | else
202 | {
203 | return std::string("Result Err: ") + m;
204 | }
205 | }
206 |
207 | operator bool() const
208 | {
209 | return v;
210 | }
211 |
212 | auto operator!() const -> bool
213 | {
214 | return !v;
215 | }
216 | };
217 | } // namespace daxa
218 |
--------------------------------------------------------------------------------
/include/daxa/daxa.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
--------------------------------------------------------------------------------
/include/daxa/daxa.inl:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define DAXA_GPU_TABLE_SET_BINDING 0
4 | #define DAXA_STORAGE_BUFFER_BINDING 0
5 | #define DAXA_STORAGE_IMAGE_BINDING 1
6 | #define DAXA_SAMPLED_IMAGE_BINDING 2
7 | #define DAXA_SAMPLER_BINDING 3
8 | #define DAXA_BUFFER_DEVICE_ADDRESS_BUFFER_BINDING 4
9 | #define DAXA_ACCELERATION_STRUCTURE_BINDING 5
10 |
11 | #define DAXA_LANGUAGE_C 0
12 | #define DAXA_LANGUAGE_CPP 0
13 | #define DAXA_LANGUAGE_GLSL 2
14 | #define DAXA_LANGUAGE_SLANG 3
15 | #define DAXA_LANGUAGE_HLSL DAXA_LANGUAGE_SLANG
16 |
17 | #if defined(_STDC_) // C
18 |
19 | #define DAXA_SHADER 0
20 | #define DAXA_LANGUAGE DAXA_LANGUAGE_C
21 | #include
22 | /// @brief Buffer ptr enable is ignored in c++.
23 | #define DAXA_DECL_BUFFER_PTR(STRUCT_TYPE)
24 | #define DAXA_DECL_BUFFER_PTR_ALIGN(STRUCT_TYPE, ALIGN)
25 | /// @brief Buffer ptr types map to the buffer device address type in daxa.
26 | #define daxa_RWBufferPtr(x) daxa_DeviceAddress
27 | /// @brief Buffer ptr types map to the buffer device address type in daxa.
28 | #define daxa_BufferPtr(x) daxa_DeviceAddress
29 |
30 | #elif defined(__cplusplus) // C++
31 |
32 | #define DAXA_SHADER 0
33 | #define DAXA_LANGUAGE DAXA_LANGUAGE_CPP
34 | #include
35 | /// @brief Buffer ptr enable is ignored in c++.
36 | #define DAXA_DECL_BUFFER_PTR(STRUCT_TYPE)
37 | #define DAXA_DECL_BUFFER_PTR_ALIGN(STRUCT_TYPE, ALIGN)
38 | /// @brief Buffer ptr types map to the buffer device address type in daxa.
39 | #define daxa_RWBufferPtr(x) daxa::types::DeviceAddress
40 | /// @brief Buffer ptr types map to the buffer device address type in daxa.
41 | #define daxa_BufferPtr(x) daxa::types::DeviceAddress
42 |
43 | #elif defined(GL_core_profile) // GLSL
44 |
45 | #define DAXA_SHADER 1
46 | #define DAXA_LANGUAGE DAXA_LANGUAGE_GLSL
47 | #include
48 |
49 | #else // SLANG
50 |
51 | #define DAXA_SHADER 1
52 | #define DAXA_LANGUAGE DAXA_LANGUAGE_SLANG
53 | #include "daxa/daxa.slang"
54 |
55 | #endif
--------------------------------------------------------------------------------
/include/daxa/instance.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace daxa
7 | {
8 | struct InstanceFlagsProperties
9 | {
10 | using Data = u64;
11 | };
12 | using InstanceFlags = Flags;
13 | struct InstanceFlagBits
14 | {
15 | static inline constexpr InstanceFlags NONE = {0x00000000};
16 | static inline constexpr InstanceFlags DEBUG_UTILS = {0x00000001};
17 | static inline constexpr InstanceFlags PARENT_MUST_OUTLIVE_CHILD = {0x00000002};
18 | };
19 |
20 | struct InstanceInfo
21 | {
22 | InstanceFlags flags =
23 | InstanceFlagBits::DEBUG_UTILS |
24 | InstanceFlagBits::PARENT_MUST_OUTLIVE_CHILD;
25 | SmallString engine_name = "daxa";
26 | SmallString app_name = "daxa app";
27 | };
28 |
29 | struct DAXA_EXPORT_CXX Instance final : ManagedPtr
30 | {
31 | Instance() = default;
32 |
33 | #if !DAXA_REMOVE_DEPRECATED
34 | [[deprecated("Use create_device_2 instead, API:3.0")]] [[nodiscard]] auto create_device(DeviceInfo const & device_info) -> Device;
35 | #endif
36 | [[nodiscard]] auto create_device_2(DeviceInfo2 const & device_info) -> Device;
37 |
38 | /// Convenience function to pick a physical device.
39 | /// Picks first supported device that satisfies the given device info and desired implicit features.
40 | [[nodiscard]] auto choose_device(ImplicitFeatureFlags desired_features, DeviceInfo2 const & base_info) -> DeviceInfo2;
41 |
42 | [[nodiscard]] auto list_devices_properties() -> std::span;
43 |
44 | /// THREADSAFETY:
45 | /// * reference MUST NOT be read after the object is destroyed.
46 | /// @return reference to info of object.
47 | [[nodiscard]] auto info() const -> InstanceInfo const &;
48 |
49 | protected:
50 | template
51 | friend struct ManagedPtr;
52 | static auto inc_refcnt(ImplHandle const * object) -> u64;
53 | static auto dec_refcnt(ImplHandle const * object) -> u64;
54 | };
55 |
56 | [[nodiscard]] DAXA_EXPORT_CXX auto create_instance(InstanceInfo const & info) -> Instance;
57 | } // namespace daxa
58 |
--------------------------------------------------------------------------------
/include/daxa/swapchain.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | #include
6 | #include
7 |
8 | namespace daxa
9 | {
10 | static inline auto default_format_score(Format format) -> i32
11 | {
12 | switch (format)
13 | {
14 | case Format::B8G8R8A8_UNORM: return 90;
15 | case Format::R8G8B8A8_UNORM: return 80;
16 | case Format::B8G8R8A8_SRGB: return 70;
17 | case Format::R8G8B8A8_SRGB: return 60;
18 | default: return 0;
19 | }
20 | }
21 |
22 | struct SwapchainInfo
23 | {
24 | NativeWindowHandle native_window;
25 | NativeWindowPlatform native_window_platform;
26 | i32 (*surface_format_selector)(Format) = default_format_score;
27 | PresentMode present_mode = PresentMode::FIFO;
28 | PresentOp present_operation = PresentOp::IDENTITY;
29 | ImageUsageFlags image_usage = {};
30 | usize max_allowed_frames_in_flight = 2;
31 | QueueFamily queue_family = {};
32 | SmallString name = {};
33 | };
34 |
35 | /**
36 | * @brief Swapchain represents the surface, swapchain and synch primitives regarding acquire and present operations.
37 | * The swapchain has a cpu and gpu timeline in order to ensure proper frames in flight.
38 | *
39 | * NOTE:
40 | * * functions that contain 'current' in their name might return different values between calling acquire_next_image
41 | *
42 | * THREADSAFETY:
43 | * * must be externally synchronized
44 | * * can be passed between different threads
45 | * * may be accessed by only one thread at the same time
46 | */
47 | struct DAXA_EXPORT_CXX Swapchain final : ManagedPtr
48 | {
49 | Swapchain() = default;
50 |
51 | /// @brief Limits Frames In Flight. Blocks until GPU catches up to the max nr of frames in flight.
52 | /// WARNING:
53 | /// * DOES NOT WAIT for the swapchain image to be available, one must STILL use the acquire semaphore!
54 | /// * This function DOES WAIT until there is a FRAME IN FLIGHT available to prepare on the CPU!
55 | /// * Function is entirely optional to call, the function acquire_next_image ALSO calls wait_for_next_frame internally.
56 | void wait_for_next_frame();
57 | /// @brief The ImageId may change between calls. This must be called to obtain a new swapchain image to be used for rendering.
58 | /// WARNING:
59 | /// * ImageIds returned from the swapchain are INVALID after the swapchain is destroyed.
60 | /// * ImageIds returned from the swapchain are INVALID after calling either resize OR set_present_mode!
61 | /// @return A swapchain image, that will be ready to render to when the acquire semaphore is signaled. This may return an empty image id if the swapchain is out of date.
62 | [[nodiscard]] auto acquire_next_image() -> ImageId;
63 | /// The acquire semaphore must be waited on in the first submission that uses the last acquired image.
64 | /// This semaphore may change between acquires, so it needs to be re-queried after every current_acquire_semaphore call.
65 | /// @return The binary semaphore that is signaled when the last acquired image is ready to be used.
66 | [[nodiscard]] auto current_acquire_semaphore() const -> BinarySemaphore const &;
67 | /// @brief The present semaphore must be signaled in the last submission that uses the last acquired swapchain image.
68 | /// The present semaphore must be waited on in the present of the last acquired image.
69 | /// This semaphore may change between acquires, so it needs to be re-queried after every current_acquire_semaphore call.
70 | /// @return The present semaphore that needs to be signaled and waited on for present of the last acquired image.
71 | [[nodiscard]] auto current_present_semaphore() const -> BinarySemaphore const &;
72 | /// @brief The last submission that uses the swapchain image needs to signal the timeline with the cpu value.
73 | /// @return The cpu frame timeline value.
74 | [[nodiscard]] auto current_cpu_timeline_value() const -> u64;
75 | /// @brief The swapchain needs to know when the last use of the swapchain happens to limit the frames in flight.
76 | /// In the last submission that uses the swapchain image, signal this timeline semaphore with the cpu timeline value.
77 | /// @return the gpu timeline semaphore that needs to be signaled.
78 | [[nodiscard]] auto gpu_timeline_semaphore() const -> TimelineSemaphore const &;
79 | /// @brief The swapchain needs to know when the last use of the swapchain happens to limit the frames in flight.
80 | /// In the last submission that uses the swapchain image, signal this timeline semaphore with the cpu timeline value.
81 | /// The cpu value timeline is incremented whenever acquire is called.
82 | /// The gpu timeline must be manually incremented by the user via a submit.
83 | /// The difference between cpu and gpu timeline describes how many frames in flight the gpu is behind the cpu.
84 | /// @return Returns pair of a gpu timeline and cpu timeline value.
85 | [[nodiscard]] auto current_timeline_pair() const -> std::pair;
86 |
87 | /// @brief When the window size changes the swapchain is in an invalid state for new commands.
88 | /// Calling resize will recreate the swapchain with the proper window size.
89 | /// WARNING:
90 | /// * Due to wsi limitations this function will WAIT IDLE THE DEVICE.
91 | /// * If the function throws an error, The swapchain will be invalidated and unusable!
92 | void resize();
93 | /// @brief Recreates swapchain with new present mode.
94 | /// WARNING:
95 | /// * Due to wsi limitations this function will WAIT IDLE THE DEVICE.
96 | /// * If the function throws an error, The swapchain will be invalidated and unusable!
97 | void set_present_mode(PresentMode present_mode);
98 | /// THREADSAFETY:
99 | /// * reference MUST NOT be read after the swapchain is destroyed
100 | /// * reference is INVALIDATED after calling either resize OR set_present_mode
101 | /// @return reference to the objects info
102 | [[nodiscard]] auto info() const -> SwapchainInfo const &;
103 | [[nodiscard]] auto get_surface_extent() const -> Extent2D;
104 | [[nodiscard]] auto get_format() const -> Format;
105 | [[nodiscard]] auto get_color_space() const -> ColorSpace;
106 |
107 | protected:
108 | template
109 | friend struct ManagedPtr;
110 | static auto inc_refcnt(ImplHandle const * object) -> u64;
111 | static auto dec_refcnt(ImplHandle const * object) -> u64;
112 | };
113 | } // namespace daxa
114 |
--------------------------------------------------------------------------------
/include/daxa/sync.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace daxa
7 | {
8 | struct Device;
9 |
10 | struct MemoryBarrierInfo
11 | {
12 | Access src_access = AccessConsts::NONE;
13 | Access dst_access = AccessConsts::NONE;
14 | };
15 |
16 | [[nodiscard]] auto to_string(MemoryBarrierInfo const & info) -> std::string;
17 |
18 | struct ImageMemoryBarrierInfo
19 | {
20 | Access src_access = AccessConsts::NONE;
21 | Access dst_access = AccessConsts::NONE;
22 | ImageLayout src_layout = ImageLayout::UNDEFINED;
23 | ImageLayout dst_layout = ImageLayout::UNDEFINED;
24 | ImageMipArraySlice image_slice = {};
25 | ImageId image_id = {};
26 | };
27 |
28 | [[nodiscard]] DAXA_EXPORT_CXX auto to_string(ImageMemoryBarrierInfo const & info) -> std::string;
29 |
30 | struct BinarySemaphoreInfo
31 | {
32 | SmallString name = {};
33 | };
34 |
35 | struct DAXA_EXPORT_CXX BinarySemaphore final : ManagedPtr
36 | {
37 | BinarySemaphore() = default;
38 |
39 | /// THREADSAFETY:
40 | /// * reference MUST NOT be read after the device is destroyed.
41 | /// @return reference to info of object.
42 | [[nodiscard]] auto info() const -> BinarySemaphoreInfo const &;
43 |
44 | protected:
45 | template
46 | friend struct ManagedPtr;
47 | static auto inc_refcnt(ImplHandle const * object) -> u64;
48 | static auto dec_refcnt(ImplHandle const * object) -> u64;
49 | };
50 |
51 | struct TimelineSemaphoreInfo
52 | {
53 | u64 initial_value = {};
54 | SmallString name = {};
55 | };
56 |
57 | struct DAXA_EXPORT_CXX TimelineSemaphore final : ManagedPtr
58 | {
59 | TimelineSemaphore() = default;
60 |
61 | /// THREADSAFETY:
62 | /// * reference MUST NOT be read after the object is destroyed.
63 | /// @return reference to info of object.
64 | [[nodiscard]] auto info() const -> TimelineSemaphoreInfo const &;
65 |
66 | [[nodiscard]] auto value() const -> u64;
67 | void set_value(u64 value);
68 | [[nodiscard]] auto wait_for_value(u64 value, u64 timeout_nanos = ~0ull) -> bool;
69 |
70 | protected:
71 | template
72 | friend struct ManagedPtr;
73 | static auto inc_refcnt(ImplHandle const * object) -> u64;
74 | static auto dec_refcnt(ImplHandle const * object) -> u64;
75 | };
76 |
77 | struct EventInfo
78 | {
79 | SmallString name = {};
80 | };
81 |
82 | struct DAXA_EXPORT_CXX Event final : ManagedPtr
83 | {
84 | Event() = default;
85 |
86 | /// THREADSAFETY:
87 | /// * reference MUST NOT be read after the object is destroyed.
88 | /// @return reference to info of object.
89 | [[nodiscard]] auto info() const -> EventInfo const &;
90 |
91 | protected:
92 | template
93 | friend struct ManagedPtr;
94 | static auto inc_refcnt(ImplHandle const * object) -> u64;
95 | static auto dec_refcnt(ImplHandle const * object) -> u64;
96 | };
97 |
98 | struct EventSignalInfo
99 | {
100 | daxa::Span memory_barriers = {};
101 | daxa::Span image_barriers = {};
102 | Event & event;
103 | };
104 |
105 | using EventWaitInfo = EventSignalInfo;
106 | } // namespace daxa
--------------------------------------------------------------------------------
/include/daxa/utils/fsr2.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if !DAXA_BUILT_WITH_UTILS_FSR2
4 | #error "[package management error] You must build Daxa with the DAXA_ENABLE_UTILS_FSR2 CMake option enabled, or request the utils-fsr2 feature in vcpkg"
5 | #endif
6 |
7 | #include
8 |
9 | namespace daxa
10 | {
11 | struct ImplFsr2Context;
12 | struct DAXA_EXPORT_CXX Fsr2Context : ManagedPtr
13 | {
14 | Fsr2Context() = default;
15 |
16 | Fsr2Context(UpscaleInstanceInfo const & info);
17 |
18 | void resize(UpscaleSizeInfo const & info);
19 | void upscale(CommandRecorder & command_list, UpscaleInfo const & info);
20 | auto get_jitter(u64 index) const -> daxa_f32vec2;
21 |
22 | protected:
23 | template
24 | friend struct ManagedPtr;
25 | static auto inc_refcnt(ImplHandle const * object) -> u64;
26 | static auto dec_refcnt(ImplHandle const * object) -> u64;
27 | };
28 | } // namespace daxa
29 |
--------------------------------------------------------------------------------
/include/daxa/utils/imgui.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if !DAXA_BUILT_WITH_UTILS_IMGUI
4 | #error "[package management error] You must build Daxa with the DAXA_ENABLE_UTILS_IMGUI CMake option enabled, or request the utils-imgui feature in vcpkg"
5 | #endif
6 |
7 | #include
8 | #include
9 |
10 | #if DAXA_BUILT_WITH_UTILS_TASK_GRAPH
11 | #include
12 | #endif
13 |
14 | #include
15 |
16 | namespace daxa
17 | {
18 | struct ImGuiImageContext
19 | {
20 | ImageViewId image_view_id;
21 | SamplerId sampler_id;
22 | };
23 |
24 | struct ImGuiRendererInfo
25 | {
26 | Device device;
27 | Format format;
28 | ImGuiContext * context = {};
29 | // NOTE: This is for backwards compatibility. Though,
30 | // I'm not sure the ImGui renderer util should set the
31 | // ImGui style. Something to bikeshed.
32 | bool use_custom_config = true;
33 | };
34 |
35 | struct ImplImGuiRenderer;
36 | struct DAXA_EXPORT_CXX ImGuiRenderer : ManagedPtr
37 | {
38 | ImGuiRenderer() = default;
39 |
40 | ImGuiRenderer(ImGuiRendererInfo const & info);
41 |
42 | auto create_texture_id(ImGuiImageContext const & context) -> ImTextureID;
43 |
44 | void record_commands(ImDrawData * draw_data, CommandRecorder & recorder, ImageId target_image, u32 size_x, u32 size_y);
45 | #if DAXA_BUILT_WITH_UTILS_TASK_GRAPH
46 | void record_task(ImDrawData * draw_data, TaskGraph & task_graph, TaskImageView task_swapchain_image, u32 size_x, u32 size_y);
47 | #endif
48 | protected:
49 | template
50 | friend struct ManagedPtr;
51 | static auto inc_refcnt(ImplHandle const * object) -> u64;
52 | static auto dec_refcnt(ImplHandle const * object) -> u64;
53 | };
54 | } // namespace daxa
55 |
--------------------------------------------------------------------------------
/include/daxa/utils/mem.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #if !DAXA_BUILT_WITH_UTILS_MEM
4 | #error "[package management error] You must build Daxa with the DAXA_ENABLE_UTILS_MEM CMake option enabled, or request the utils-mem feature in vcpkg"
5 | #endif
6 |
7 | #include
8 | #include
9 |
10 | #include
11 |
12 | namespace daxa
13 | {
14 | struct TransferMemoryPoolInfo
15 | {
16 | Device device = {};
17 | u32 capacity = 1 << 25;
18 | bool use_bar_memory = {};
19 | std::string name = {};
20 | };
21 |
22 | /// @brief Ring buffer based transfer memory allocator for easy and efficient cpu gpu communication.
23 | struct TransferMemoryPool
24 | {
25 | DAXA_EXPORT_CXX TransferMemoryPool(TransferMemoryPoolInfo a_info);
26 | DAXA_EXPORT_CXX TransferMemoryPool(TransferMemoryPool && other);
27 | DAXA_EXPORT_CXX TransferMemoryPool & operator=(TransferMemoryPool && other);
28 | DAXA_EXPORT_CXX ~TransferMemoryPool();
29 |
30 | struct Allocation
31 | {
32 | daxa::DeviceAddress device_address = {};
33 | void * host_address = {};
34 | u32 buffer_offset = {};
35 | usize size = {};
36 | u64 timeline_index = {};
37 | };
38 | // Returns nullopt if the allocation fails.
39 | DAXA_EXPORT_CXX auto allocate(u32 size, u32 alignment_requirement = 16 /* 16 is a save default for most gpu data*/) -> std::optional;
40 | /// @brief Allocates a section of a buffer with the size of T, writes the given T to the allocation.
41 | /// @return allocation.
42 | template
43 | auto allocate_fill(T const & value, u32 alignment_requirement = alignof(T)) -> std::optional
44 | {
45 | auto allocation_o = allocate(sizeof(T), alignment_requirement);
46 | if (allocation_o.has_value())
47 | {
48 | *reinterpret_cast(allocation_o->host_address) = value;
49 | return allocation_o.value();
50 | }
51 | return std::nullopt;
52 | }
53 | // Returns current timeline index.
54 | DAXA_EXPORT_CXX auto timeline_value() const -> usize;
55 | // Returns and then increments the current timeline index.
56 | // This is useful to ensure that the timeline value used for submits is always increasing.
57 | DAXA_EXPORT_CXX auto inc_timeline_value() -> usize;
58 | // Returns timeline semaphore that needs to be signaled with the latest timeline value,
59 | // on a queue that uses memory from this pool.
60 | DAXA_EXPORT_CXX auto timeline_semaphore() -> TimelineSemaphore const &;
61 | DAXA_EXPORT_CXX auto buffer() const -> daxa::BufferId;
62 | /// THREADSAFETY:
63 | /// * reference MUST NOT be read after the object is destroyed.
64 | /// @return reference to info of object.
65 | DAXA_EXPORT_CXX auto info() const -> TransferMemoryPoolInfo const &;
66 |
67 | private:
68 | // Reclaim expired memory allocations.
69 | DAXA_EXPORT_CXX void reclaim_unused_memory();
70 | struct TrackedAllocation
71 | {
72 | usize timeline_index = {};
73 | u32 offset = {};
74 | u32 size = {};
75 | };
76 |
77 | TransferMemoryPoolInfo m_info = {};
78 | TimelineSemaphore gpu_timeline = {};
79 |
80 | private:
81 | u64 current_timeline_value = {};
82 | std::deque live_allocations = {};
83 | BufferId m_buffer = {};
84 | daxa::DeviceAddress buffer_device_address = {};
85 | void * buffer_host_address = {};
86 | u32 claimed_start = {};
87 | u32 claimed_size = {};
88 | };
89 | } // namespace daxa
90 |
--------------------------------------------------------------------------------
/include/daxa/utils/task_graph.inl:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "../daxa.inl"
3 |
4 | /**
5 | * DAXA_TH_IMAGE:
6 | * Declares an image attachment.
7 | * The attachment is NOT represented at all within the shader blob.
8 | *
9 | * DAXA_TH_IMAGE_ID:
10 | * Declares an image attachment.
11 | * The first runtime image will be represented within the blob.
12 | *
13 | * DAXA_TH_IMAGE_ID_ARRAY:
14 | * Declares an image attachment.
15 | * A partial array of the attachments runtime ids are represented within an id array in the blob.
16 | *
17 | * DAXA_TH_IMAGE_ID_MIP_ARRAY:
18 | * Declares an image attachment.
19 | * A partial array of image views pointing to separate mip levels of the first runtime image are represented within the blob.
20 | *
21 | * DAXA_TH_BUFFER:
22 | * Declares a buffer attachment.
23 | * The attachment is NOT represented at all within the shader blob.
24 | *
25 | * DAXA_TH_BUFFER_ID:
26 | * Declares a buffer attachment.
27 | * The first runtime buffer will be represented within the blob.
28 | *
29 | * DAXA_TH_BUFFER_PTR:
30 | * Declares a buffer attachment.
31 | * The first runtime buffer will be represented with its buffer device address within the blob.
32 | *
33 | * DAXA_TH_BUFFER_ID_ARRAY:
34 | * Declares a buffer attachment.
35 | * A partial array of the attachments runtime buffers are represented within an id array in the blob.
36 | *
37 | * DAXA_TH_BUFFER_PTR_ARRAY:
38 | * Declares a buffer attachment.
39 | * A partial array of the attachments runtime buffers are represented with their buffer device addresses within an id array in the blob.
40 | *
41 | */
42 |
43 | // DAXA 3.0 Task-Head-Shader interface:
44 | #if DAXA_SHADER
45 | #define DAXA_DECL_COMPUTE_TASK_HEAD_BEGIN(HEAD_NAME) DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME)
46 | #define DAXA_DECL_RASTER_TASK_HEAD_BEGIN(HEAD_NAME) DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME)
47 | #define DAXA_DECL_TRANSFER_TASK_HEAD_BEGIN(HEAD_NAME) DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME)
48 | #define DAXA_DECL_RAY_TRACING_TASK_HEAD_BEGIN(HEAD_NAME) DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME)
49 | #if DAXA_LANGUAGE == DAXA_LANGUAGE_SLANG
50 | #define DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME) \
51 | namespace HEAD_NAME \
52 | { \
53 | struct AttachmentShaderBlob \
54 | {
55 | #define DAXA_TH_IMAGE(TASK_ACCESS, VIEW_TYPE, NAME)
56 | #define DAXA_TH_IMAGE_ID(TASK_ACCESS, VIEW_TYPE, NAME) daxa::ImageViewId NAME;
57 | #define DAXA_TH_IMAGE_ID_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa::ImageViewId NAME[SIZE];
58 | #define DAXA_TH_IMAGE_ID_MIP_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa::ImageViewId NAME[SIZE];
59 | #define DAXA_TH_IMAGE_INDEX(TASK_ACCESS, VIEW_TYPE, NAME) daxa::ImageViewIndex NAME;
60 | #define DAXA_TH_IMAGE_INDEX_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa::ImageViewIndex NAME[SIZE];
61 | #define DAXA_TH_IMAGE_INDEX_MIP_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa::ImageViewIndex NAME[SIZE];
62 | #define DAXA_TH_IMAGE_TYPED(TASK_ACCESS, TEX_TYPE, NAME) TEX_TYPE NAME;
63 | #define DAXA_TH_IMAGE_TYPED_ARRAY(TASK_ACCESS, TEX_TYPE, NAME, SIZE) TEX_TYPE NAME[SIZE];
64 | #define DAXA_TH_IMAGE_TYPED_MIP_ARRAY(TASK_ACCESS, TEX_TYPE, NAME, SIZE) TEX_TYPE NAME[SIZE];
65 | #define DAXA_TH_BUFFER(TASK_ACCESS, NAME)
66 | #define DAXA_TH_BUFFER_ID(TASK_ACCESS, NAME) daxa::BufferId NAME;
67 | #define DAXA_TH_BUFFER_PTR(TASK_ACCESS, PTR_TYPE, NAME) PTR_TYPE NAME;
68 | #define DAXA_TH_BUFFER_ID_ARRAY(TASK_ACCESS, NAME, SIZE) daxa::BufferId NAME[SIZE];
69 | #define DAXA_TH_BUFFER_PTR_ARRAY(TASK_ACCESS, PTR_TYPE, NAME, SIZE) PTR_TYPE NAME[SIZE];
70 | #define DAXA_TH_BLAS(TASK_ACCESS, NAME)
71 | #define DAXA_TH_TLAS(TASK_ACCESS, NAME)
72 | #define DAXA_TH_TLAS_PTR(TASK_ACCESS, NAME) daxa::u64 NAME;
73 | #define DAXA_TH_TLAS_ID(TASK_ACCESS, NAME) daxa::TlasId NAME;
74 | #define DAXA_DECL_TASK_HEAD_END \
75 | } \
76 | ; \
77 | } \
78 | ;
79 | #define DAXA_TH_BLOB(HEAD_NAME, field_name) HEAD_NAME::AttachmentShaderBlob field_name;
80 | #else // glsl
81 | #define DAXA_DECL_TASK_HEAD_BEGIN(HEAD_NAME) \
82 | struct HEAD_NAME \
83 | {
84 | #define DAXA_TH_IMAGE(TASK_ACCESS, VIEW_TYPE, NAME)
85 | #define DAXA_TH_IMAGE_ID(TASK_ACCESS, VIEW_TYPE, NAME) daxa_ImageViewId NAME;
86 | #define DAXA_TH_IMAGE_ID_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa_ImageViewId NAME[SIZE];
87 | #define DAXA_TH_IMAGE_ID_MIP_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa_ImageViewId NAME[SIZE];
88 | #define DAXA_TH_IMAGE_INDEX(TASK_ACCESS, VIEW_TYPE, NAME) daxa_ImageViewIndex NAME;
89 | #define DAXA_TH_IMAGE_INDEX_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa_ImageViewIndex NAME[SIZE];
90 | #define DAXA_TH_IMAGE_INDEX_MIP_ARRAY(TASK_ACCESS, VIEW_TYPE, NAME, SIZE) daxa_ImageViewIndex NAME[SIZE];
91 | #define DAXA_TH_IMAGE_TYPED(TASK_ACCESS, TEX_TYPE, NAME) ERROR_TYPED_HANDLES_ARE_SLANG_ONLY
92 | #define DAXA_TH_IMAGE_TYPED_ARRAY(TASK_ACCESS, TEX_TYPE, NAME, SIZE) ERROR_TYPED_HANDLES_ARE_SLANG_ONLY
93 | #define DAXA_TH_IMAGE_TYPED_MIP_ARRAY(TASK_ACCESS, TEX_TYPE, NAME, SIZE) ERROR_TYPED_HANDLES_ARE_SLANG_ONLY
94 | #define DAXA_TH_BUFFER(TASK_ACCESS, NAME)
95 | #define DAXA_TH_BUFFER_ID(TASK_ACCESS, NAME) daxa_BufferId NAME;
96 | #define DAXA_TH_BUFFER_PTR(TASK_ACCESS, PTR_TYPE, NAME) PTR_TYPE NAME;
97 | #define DAXA_TH_BUFFER_ID_ARRAY(TASK_ACCESS, NAME, SIZE) daxa_BufferId NAME[SIZE];
98 | #define DAXA_TH_BUFFER_PTR_ARRAY(TASK_ACCESS, PTR_TYPE, NAME, SIZE) PTR_TYPE NAME[SIZE];
99 | #define DAXA_TH_BLAS(TASK_ACCESS, NAME)
100 | #define DAXA_TH_TLAS(TASK_ACCESS, NAME)
101 | #define DAXA_TH_TLAS_PTR(TASK_ACCESS, NAME) daxa_u64 NAME;
102 | #define DAXA_TH_TLAS_ID(TASK_ACCESS, NAME) daxa_TlasId NAME;
103 | #define DAXA_DECL_TASK_HEAD_END \
104 | } \
105 | ;
106 | #define DAXA_TH_BLOB(HEAD_NAME, field_name) HEAD_NAME field_name;
107 | #endif
108 | #elif __cplusplus
109 | #include "task_graph_types.hpp"
110 | #else // C
111 | #error TASK GRAPH INL ONLY SUPPORTED IN SHADERS AND C++!
112 | #endif
--------------------------------------------------------------------------------
/include/daxa/utils/upscaling_common.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 |
6 | namespace daxa
7 | {
8 | struct UpscaleSizeInfo
9 | {
10 | u32 render_size_x, render_size_y;
11 | u32 display_size_x, display_size_y;
12 | };
13 |
14 | struct UpscaleInstanceInfo
15 | {
16 | Device device;
17 | UpscaleSizeInfo size_info = {};
18 | bool depth_inf = false;
19 | bool depth_inv = false;
20 | bool color_hdr = false;
21 | };
22 |
23 | struct UpscaleInfo
24 | {
25 | ImageId color, depth, motion_vectors;
26 | // ImageId reactive, trans_and_comp;
27 | ImageId output;
28 |
29 | bool should_reset = false;
30 | f32 delta_time;
31 | daxa_f32vec2 jitter;
32 |
33 | bool should_sharpen = false;
34 | f32 sharpening = 0.0f;
35 |
36 | struct CameraInfo
37 | {
38 | f32 near_plane = {};
39 | f32 far_plane = {};
40 | f32 vertical_fov = {};
41 | };
42 | CameraInfo camera_info = {};
43 | };
44 | } // namespace daxa
45 |
--------------------------------------------------------------------------------
/misc/daxa-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ipotrick/Daxa/a18972dcf12efa0b7efb9207cde10cdd251448e4/misc/daxa-logo.png
--------------------------------------------------------------------------------
/portfile.cmake:
--------------------------------------------------------------------------------
1 | # Local-only code
2 |
3 | set(SOURCE_PATH "${CMAKE_CURRENT_LIST_DIR}")
4 |
5 | # Standard vcpkg stuff
6 |
7 | vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS
8 | FEATURES
9 | utils-imgui WITH_UTILS_IMGUI
10 | utils-mem WITH_UTILS_MEM
11 | utils-pipeline-manager-glslang WITH_UTILS_PIPELINE_MANAGER_GLSLANG
12 | utils-pipeline-manager-slang WITH_UTILS_PIPELINE_MANAGER_SLANG
13 | utils-pipeline-manager-spirv-validation WITH_UTILS_PIPELINE_MANAGER_SPIRV_VALIDATION
14 | utils-task-graph WITH_UTILS_TASK_GRAPH
15 | utils-fsr2 WITH_UTILS_FSR2
16 | )
17 | set(DAXA_DEFINES "-DDAXA_INSTALL=true")
18 |
19 | if(WITH_UTILS_IMGUI)
20 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_IMGUI=true")
21 | endif()
22 | if(WITH_UTILS_MEM)
23 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_MEM=true")
24 | endif()
25 | if(WITH_UTILS_PIPELINE_MANAGER_GLSLANG)
26 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_PIPELINE_MANAGER_GLSLANG=true")
27 | endif()
28 | if(WITH_UTILS_PIPELINE_MANAGER_SLANG)
29 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_PIPELINE_MANAGER_SLANG=true")
30 | endif()
31 | if(WITH_UTILS_PIPELINE_MANAGER_SPIRV_VALIDATION)
32 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_PIPELINE_MANAGER_SPIRV_VALIDATION=true")
33 | endif()
34 | if(WITH_UTILS_TASK_GRAPH)
35 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_TASK_GRAPH=true")
36 | endif()
37 | if(WITH_UTILS_FSR2)
38 | list(APPEND DAXA_DEFINES "-DDAXA_ENABLE_UTILS_FSR2=true")
39 | endif()
40 |
41 | vcpkg_configure_cmake(
42 | SOURCE_PATH "${SOURCE_PATH}"
43 | PREFER_NINJA
44 | OPTIONS ${DAXA_DEFINES}
45 | )
46 |
47 | vcpkg_install_cmake()
48 | vcpkg_fixup_cmake_targets()
49 | file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
50 | file(INSTALL "${SOURCE_PATH}/LICENSE"
51 | DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}"
52 | RENAME copyright
53 | )
54 |
--------------------------------------------------------------------------------
/src/impl_command_recorder.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "impl_core.hpp"
4 | #include "impl_sync.hpp"
5 | #include "impl_pipeline.hpp"
6 |
7 | #include
8 | #include
9 |
10 | using namespace daxa;
11 |
12 | struct ImplDevice;
13 |
14 | static inline constexpr u8 DEFERRED_DESTRUCTION_BUFFER_INDEX = 0;
15 | static inline constexpr u8 DEFERRED_DESTRUCTION_IMAGE_INDEX = 1;
16 | static inline constexpr u8 DEFERRED_DESTRUCTION_IMAGE_VIEW_INDEX = 2;
17 | static inline constexpr u8 DEFERRED_DESTRUCTION_SAMPLER_INDEX = 3;
18 | static inline constexpr u8 DEFERRED_DESTRUCTION_TIMELINE_QUERY_POOL_INDEX = 4;
19 | // TODO: maybe reintroduce this in some fashion?
20 | // static inline constexpr usize DEFERRED_DESTRUCTION_COUNT_MAX = 32;
21 |
22 | static inline constexpr usize COMMAND_LIST_BARRIER_MAX_BATCH_SIZE = 16;
23 | static inline constexpr usize COMMAND_LIST_COLOR_ATTACHMENT_MAX = 16;
24 |
25 | struct CommandPoolPool
26 | {
27 | auto get(daxa_Device device) -> VkCommandPool;
28 |
29 | void put_back(VkCommandPool pool_and_buffer);
30 |
31 | void cleanup(daxa_Device device);
32 |
33 | std::vector pools_and_buffers = {};
34 | u32 queue_family_index = {~0u};
35 | std::mutex mtx = {};
36 | };
37 |
38 | struct CommandRecorderZombie
39 | {
40 | daxa_QueueFamily queue_family = {};
41 | VkCommandPool vk_cmd_pool = {};
42 | std::vector allocated_command_buffers = {};
43 | };
44 |
45 | struct ExecutableCommandListData
46 | {
47 | VkCommandBuffer vk_cmd_buffer = {};
48 | std::vector> deferred_destructions = {};
49 | // TODO: These vectors seem to be fast enough. overhead is around 1-4% in cmd recording.
50 | // It might be cool to have some slab allocator for these.
51 | // If there is demand, we could make an instance or cmd list flag to disable the submit checks.
52 | // TODO: Also collect ref counted handles.
53 | std::vector used_buffers = {};
54 | std::vector used_images = {};
55 | std::vector used_image_views = {};
56 | std::vector used_samplers = {};
57 | std::vector used_tlass = {};
58 | std::vector used_blass = {};
59 | };
60 |
61 | struct daxa_ImplCommandRecorder final : ImplHandle
62 | {
63 | daxa_Device device = {};
64 | bool in_renderpass = {};
65 | daxa_CommandRecorderInfo info = {};
66 | VkCommandPool vk_cmd_pool = {};
67 | std::vector allocated_command_buffers = {};
68 | std::array memory_barrier_batch = {};
69 | std::array image_barrier_batch = {};
70 | usize image_barrier_batch_count = {};
71 | usize memory_barrier_batch_count = {};
72 | usize split_barrier_batch_count = {};
73 | struct NoPipeline
74 | {
75 | };
76 | Variant current_pipeline = NoPipeline{};
77 |
78 | ExecutableCommandListData current_command_data = {};
79 |
80 | auto generate_new_current_command_data() -> daxa_Result;
81 |
82 | static void zero_ref_callback(ImplHandle const * handle);
83 | };
84 |
85 | struct daxa_ImplExecutableCommandList final : ImplHandle
86 | {
87 | daxa_CommandRecorder cmd_recorder = {};
88 | ExecutableCommandListData data = {};
89 |
90 | static void zero_ref_callback(ImplHandle const * handle);
91 | };
92 |
93 | void executable_cmd_list_execute_deferred_destructions(daxa_Device device, ExecutableCommandListData & cmd_list);
--------------------------------------------------------------------------------
/src/impl_core.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #ifdef VULKAN_H_
4 | #error MOST NOT INCLUDE VULKAN H BEFORE THIS FILE!
5 | #endif
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include