Skip to content

Commit afe190f

Browse files
Initial commit
Create deploy.yml Added pages Push Push Fix Update page 01
0 parents  commit afe190f

14 files changed

+854
-0
lines changed

.github/workflows/deploy.yml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Deploy to tutorial.learndaxa.com
2+
on:
3+
push:
4+
branches: ["main"]
5+
workflow_dispatch:
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
12+
concurrency:
13+
group: "pages"
14+
cancel-in-progress: true
15+
16+
jobs:
17+
deploy:
18+
environment:
19+
name: github-pages
20+
url: ${{ steps.deployment.outputs.page_url }}
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
26+
- name: Setup Node.js
27+
uses: actions/setup-node@v2
28+
with:
29+
node-version: "20"
30+
31+
- name: Setup Python
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: "3.11"
35+
36+
- name: Clone Repos
37+
run: |
38+
git clone https://${{ secrets.PRIVATE_REPO_ACCESS_TOKEN }}@github.com/learndaxa/WebsiteTemplate.git ../WebsiteTemplate/
39+
git clone https://${{ secrets.PRIVATE_REPO_ACCESS_TOKEN }}@github.com/learndaxa/WebsiteTheme.git ../WebsiteTemplate/src/lib/theme/
40+
git clone https://${{ secrets.PRIVATE_REPO_ACCESS_TOKEN }}@github.com/learndaxa/WebsiteRenderer.git ../WebsiteRenderer/
41+
42+
- name: Rendering Markdown to Svelte
43+
run: |
44+
python ../WebsiteRenderer/main.py --goal tutorial --source "docs/" --destination "../WebsiteTemplate/"
45+
46+
- name: Building Static Site
47+
run: |
48+
cd ../WebsiteTemplate/
49+
npm install
50+
npm run build
51+
52+
- name: Making static links
53+
run: |
54+
cd ../
55+
python WebsiteRenderer/fix.py --destination "WebsiteTemplate/" --domain "https://tutorial.learndaxa.com"
56+
57+
- name: Upload artifact
58+
uses: actions/upload-pages-artifact@v1
59+
with:
60+
path: "../WebsiteTemplate/build/"
61+
- name: Deploy to GitHub Pages
62+
id: deployment
63+
uses: actions/deploy-pages@v1

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Daxa Tutorial

docs/01_Installing_dependencies.md

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Important
2+
3+
This page will explain how to install all the necessary tools to compile the Daxa repository itself, though these things will be necessary for consumers of Daxa as a dependency as well. We'll go over using Daxa as a dependency in the next page. If you have previously worked with Vulkan or C++ before, you can skip some of these steps. Since those steps are different for Windows and Linux, this page is split into multiple parts. Make sure you follow the steps from the correct heading.
4+
5+
## Windows
6+
7+
### Visual Studio
8+
9+
In this tutorial, we will be using Clang as our compiler. Clang relies on the Microsoft STL, which we can get most easily by installing [Visual Studio](https://visualstudio.microsoft.com/de/vs/community/) and selecting the C++ desktop development component during installation
10+
11+
### Clang & Ninja
12+
13+
To install Clang and Ninja, you need to install Chocolatey. To do so, enter this command line into the PowerShell as an administrator:
14+
15+
```ps
16+
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
17+
```
18+
19+
PowerShell might ask you to enable the running of scripts, which can be enabled by running `Set-ExecutionPolicy AllSigned`
20+
21+
You can then go ahead and install clang & ninja:
22+
23+
```batch
24+
choco install llvm
25+
choco install ninja
26+
```
27+
28+
### Misc tools
29+
30+
You also need to install [Git](https://git-scm.com/download/win) and [CMake](https://cmake.org/download/). To do so, simply download & run the installers from their websites.
31+
32+
### Vulkan SDK
33+
34+
The last step is to download the [Vulkan SDK](https://vulkan.lunarg.com/sdk/home#windows). During installation make sure to keep "Debuggable Shader API Libraries" unchecked since they might clash with glslang later on.
35+
36+
## Linux
37+
38+
(Todo)
39+
40+
## Installing VSCode (Windows & Linux)
41+
42+
In this tutorial, we will be using [Visual Studio Code](https://code.visualstudio.com/download) as our code editor. You can also use other IDEs such as [CLion](https://www.jetbrains.com/clion/), but it may be harder to follow the tutorial. We therefore recommend using VSCode with the following extensions:
43+
44+
1. C/C++ Extension Pack (`ms-vscode.cpptools-extension-pack`)
45+
2. GLSL Lint (`dtoplak.vscode-glsllint`)

docs/02_Developement_environment.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Downloading the starting point
2+
3+
Download the starting point [here](https://codeload.github.com/FabulousCodingFox/daxa-app-template/zip/refs/heads/master) or from its [GitHub](https://github.com/FabulousCodingFox/daxa-app-template) and open it with VSCode if prompted select the 'Debug' preset.
4+
5+
To install all needed dependencies and initialize the project you need to run the 'setup' script located in the 'scripts' folder. This will download Vcpkg, Daxa and all dependencies into the 'lib' folder.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
## Disclaimer
2+
3+
In this tutorial, we will be using GLFW to create and manage our window. Since this is not part of the core tutorial, we will only provide a small rundown of the header file without going into further detail. If you are new to GLFW, we recommend you check out [this tutorial on learnopengl.com](https://learnopengl.com/Getting-started/Hello-Window)
4+
5+
The code below will open a small window which we will use in the next sections.
6+
7+
## window.hpp
8+
9+
```cpp
10+
#pragma once
11+
12+
#include <daxa/daxa.hpp>
13+
using namespace daxa::types;
14+
15+
#include <GLFW/glfw3.h>
16+
#if defined(_WIN32)
17+
#define GLFW_EXPOSE_NATIVE_WIN32
18+
#define GLFW_NATIVE_INCLUDE_NONE
19+
using HWND = void *;
20+
#elif defined(__linux__)
21+
#define GLFW_EXPOSE_NATIVE_X11
22+
#define GLFW_EXPOSE_NATIVE_WAYLAND
23+
#endif
24+
#include <GLFW/glfw3native.h>
25+
26+
struct Window{
27+
GLFWwindow * glfw_window_ptr;
28+
u32 width, height;
29+
bool minimized = false;
30+
bool swapchain_out_of_date = false;
31+
32+
explicit Window(char const * window_name, u32 sx = 800, u32 sy = 600) : width{sx}, height{sy} {
33+
// Initialize GLFW
34+
glfwInit();
35+
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
36+
37+
// Tell GLFW to make the window resizable
38+
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
39+
40+
// Create the window
41+
glfw_window_ptr = glfwCreateWindow(static_cast<i32>(width), static_cast<i32>(height), window_name, nullptr, nullptr);
42+
43+
// Set the user pointer to this window
44+
glfwSetWindowUserPointer(glfw_window_ptr, this);
45+
46+
// Enable vsync (To limit the framerate to the refresh rate of the monitor)
47+
glfwSwapInterval(1);
48+
49+
// When the window is resized, update the width and height and mark the swapchain as out of date
50+
glfwSetWindowContentScaleCallback(glfw_window_ptr, [](GLFWwindow* window, float xscale, float yscale){
51+
auto* win = static_cast<Window*>(glfwGetWindowUserPointer(window));
52+
win->width = static_cast<u32>(xscale);
53+
win->height = static_cast<u32>(yscale);
54+
win->swapchain_out_of_date = true;
55+
});
56+
}
57+
58+
~Window() {
59+
glfwDestroyWindow(glfw_window_ptr);
60+
glfwTerminate();
61+
}
62+
63+
auto get_native_handle() const -> daxa::NativeWindowHandle
64+
{
65+
#if defined(_WIN32)
66+
return glfwGetWin32Window(glfw_window_ptr);
67+
#elif defined(__linux__)
68+
switch (get_native_platform())
69+
{
70+
case daxa::NativeWindowPlatform::WAYLAND_API:
71+
return reinterpret_cast<daxa::NativeWindowHandle>(glfwGetWaylandWindow(glfw_window_ptr));
72+
case daxa::NativeWindowPlatform::XLIB_API:
73+
default:
74+
return reinterpret_cast<daxa::NativeWindowHandle>(glfwGetX11Window(glfw_window_ptr));
75+
}
76+
#endif
77+
}
78+
79+
static auto get_native_platform() -> daxa::NativeWindowPlatform
80+
{
81+
switch(glfwGetPlatform())
82+
{
83+
case GLFW_PLATFORM_WIN32: return daxa::NativeWindowPlatform::WIN32_API;
84+
case GLFW_PLATFORM_X11: return daxa::NativeWindowPlatform::XLIB_API;
85+
case GLFW_PLATFORM_WAYLAND: return daxa::NativeWindowPlatform::WAYLAND_API;
86+
default: return daxa::NativeWindowPlatform::UNKNOWN;
87+
}
88+
}
89+
90+
inline void set_mouse_capture(bool should_capture) const
91+
{
92+
glfwSetCursorPos(glfw_window_ptr, static_cast<f64>(width / 2.), static_cast<f64>(height / 2.));
93+
glfwSetInputMode(glfw_window_ptr, GLFW_CURSOR, should_capture ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
94+
glfwSetInputMode(glfw_window_ptr, GLFW_RAW_MOUSE_MOTION, should_capture);
95+
}
96+
97+
inline bool should_close() const
98+
{
99+
return glfwWindowShouldClose(glfw_window_ptr);
100+
}
101+
102+
inline void update() const
103+
{
104+
glfwPollEvents();
105+
glfwSwapBuffers(glfw_window_ptr);
106+
}
107+
108+
inline GLFWwindow* get_glfw_window() const{
109+
return glfw_window_ptr;
110+
}
111+
112+
inline bool should_close() {
113+
return glfwWindowShouldClose(glfw_window_ptr);
114+
}
115+
};
116+
```
117+
118+
## main.cpp
119+
120+
```cpp
121+
#include "window.hpp"
122+
123+
#include <iostream>
124+
125+
#include <daxa/daxa.hpp>
126+
#include <daxa/utils/pipeline_manager.hpp>
127+
#include <daxa/utils/task_graph.hpp>
128+
129+
using namespace daxa::task_resource_uses;
130+
using namespace daxa::types;
131+
132+
int main(int argc, char const *argv[])
133+
{
134+
// Create a window
135+
auto window = Window("Learn Daxa", 860, 640);
136+
137+
// Daxa code goes here...
138+
139+
while (!window.should_close())
140+
{
141+
window.update();
142+
}
143+
144+
return 0;
145+
}
146+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Include the header
2+
3+
Well done! We have now created all the fundamentals and can finally start using Daxa. To use Daxa's C++ API, we need to include the following header:
4+
5+
```cpp
6+
#include <daxa/daxa.hpp>
7+
```
8+
9+
Since this header is already included in the window.hpp header file, we don't need to also include this in our main.cpp
10+
11+
## Create a new instance
12+
13+
Using this header we can now generate a new Daxa instance!
14+
15+
```cpp
16+
daxa::Instance instance = daxa::create_instance({});
17+
```
18+
19+
A curious thing you will notice is that most function calls take a struct as a parameter. This is done to emulate named parameters and also to enable out-of-order default argument values using C++20"s designated initializers.
20+
21+
Daxa is a relatively explicit API but has a lot of defaults via struct default member values. This makes it much nicer to use in many cases.
22+
23+
Nearly all Daxa objects can be assigned a debug name in creation. This name is used in the error messages we emit and is also displayed in tools like RenderDoc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Device selection
2+
3+
A PC can have multiple graphics cards. Unlike OpenGL, you need to manually select which GPU you want to use to perform calculations. Since each GPU is different Daxa provides a simple system to select the GPU best suited for your application. You can choose the considered parameters yourself and change how they are weighed against each other.
4+
5+
Below is a sample code to select a GPU based on location & VRAM.
6+
7+
```cpp
8+
daxa::Device device = instance.create_device({
9+
.selector = [](daxa::DeviceProperties const & device_props) -> daxa::i32
10+
{
11+
daxa::i32 score = 0;
12+
switch (device_props.device_type)
13+
{
14+
case daxa::DeviceType::DISCRETE_GPU: score += 10000; break;
15+
case daxa::DeviceType::VIRTUAL_GPU: score += 1000; break;
16+
case daxa::DeviceType::INTEGRATED_GPU: score += 100; break;
17+
default: break;
18+
}
19+
score += static_cast<daxa::i32>(device_props.limits.max_memory_allocation_count / 100000);
20+
return score;
21+
},
22+
.name = "my device",
23+
});
24+
```
25+
26+
The struct daxa::DeviceProperties has many fields indicating different GPU attributes, such as Vulkan version, device type, ray tracing capabilities, ... ([Code reference](https://github.com/Ipotrick/Daxa/blob/master/include/daxa/device.hpp#L188))

0 commit comments

Comments
 (0)