mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f6201014aa | ||
|
|
c583f1abc8 | ||
|
|
f7cf64cbb9 | ||
|
|
b882771a18 | ||
|
|
39aa8009a4 | ||
|
|
5dce6a2c8e | ||
|
|
52929e215c | ||
|
|
ad60a17da9 | ||
|
|
d29cd56044 | ||
|
|
d6795f97ef | ||
|
|
2fa7e2d4a9 | ||
|
|
85c43dabf4 | ||
|
|
e6ed390e84 | ||
|
|
6cd3422337 | ||
|
|
c0f539b57f | ||
|
|
497879a0bc | ||
|
|
5b43b47f90 | ||
|
|
ab4ebc34d5 | ||
|
|
587e71b940 | ||
|
|
11073a2cbc | ||
|
|
c1898fb8dd | ||
|
|
453ee0850b | ||
|
|
3dd055b406 | ||
|
|
08cbbfa836 | ||
|
|
ce7e3ac88d | ||
|
|
cc810368aa | ||
|
|
ec757ab292 | ||
|
|
fc9fa1a980 | ||
|
|
469716e72b | ||
|
|
254f80b442 | ||
|
|
4d19598ac2 | ||
|
|
774f7c41b0 | ||
|
|
4f8dbc794c | ||
|
|
281bf2dcd2 |
42
.github/workflows/linux_clang.yml
vendored
git.filemode.normal_file
42
.github/workflows/linux_clang.yml
vendored
git.filemode.normal_file
@@ -0,0 +1,42 @@
|
||||
name: Linux (clang)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install mesa-common-dev clang libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && clang main.c ../libmlx.so -lSDL2
|
||||
43
.github/workflows/linux_gcc.yml
vendored
git.filemode.normal_file
43
.github/workflows/linux_gcc.yml
vendored
git.filemode.normal_file
@@ -0,0 +1,43 @@
|
||||
name: Linux (gcc)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install system dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install mesa-common-dev libsdl2-2.0-0 libsdl2-dev build-essential libvulkan-dev
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make TOOLCHAIN=gcc -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && gcc main.c ../libmlx.so -lSDL2
|
||||
|
||||
49
.github/workflows/macos_x86.yml
vendored
git.filemode.normal_file
49
.github/workflows/macos_x86.yml
vendored
git.filemode.normal_file
@@ -0,0 +1,49 @@
|
||||
name: macOS
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
push:
|
||||
paths-ignore:
|
||||
- '.gitignore'
|
||||
- 'LICENSE'
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [macOS-latest]
|
||||
arch: [x86_64]
|
||||
mode: [release]
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
if: "!contains(github.event.head_commit.message, 'ci skip')"
|
||||
|
||||
steps:
|
||||
- name: Get current date as package key
|
||||
id: cache_key
|
||||
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Install system dependencies
|
||||
- name: Install Vulkan SDK
|
||||
uses: humbletim/install-vulkan-sdk@v1.1.1
|
||||
with:
|
||||
version: 1.3.204.1
|
||||
cache: true
|
||||
|
||||
- name: Install Dependancies
|
||||
run: |
|
||||
brew install SDL2
|
||||
|
||||
# Build the lib
|
||||
- name: Build MacroLibX
|
||||
run: make -j
|
||||
|
||||
# Build the test
|
||||
- name: Build Test
|
||||
run: cd test && clang main.c ../libmlx.so -lSDL2
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
||||
*.a
|
||||
*.so
|
||||
*.out
|
||||
.cache/
|
||||
|
||||
23
Makefile
23
Makefile
@@ -3,10 +3,10 @@
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: vvaas <vvaas@student.42.fr> +#+ +:+ +#+ #
|
||||
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
|
||||
# Updated: 2023/08/09 13:51:08 by maldavid ### ########.fr #
|
||||
# Updated: 2023/11/13 06:08:16 by maldavid ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@@ -19,9 +19,12 @@ SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
|
||||
|
||||
OBJS = $(SRCS:.cpp=.o)
|
||||
|
||||
OS = $(shell uname -s)
|
||||
DEBUG ?= false
|
||||
TOOLCHAIN ?= clang
|
||||
IMAGES_OPTIMIZED ?= true
|
||||
FORCE_INTEGRATED_GPU ?= false
|
||||
GRAPHICS_MEMORY_DUMP ?= false
|
||||
|
||||
CXX = clang++
|
||||
|
||||
@@ -32,14 +35,28 @@ endif
|
||||
CXXFLAGS = -std=c++17 -O3 -fPIC
|
||||
INCLUDES = -I./includes -I./src -I./third_party
|
||||
|
||||
LDLIBS =
|
||||
|
||||
ifeq ($(OS), Darwin)
|
||||
LDLIBS += -lSDL2
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG), true)
|
||||
CXXFLAGS += -g -D DEBUG
|
||||
endif
|
||||
|
||||
ifeq ($(FORCE_INTEGRATED_GPU), true)
|
||||
CXXFLAGS += -D FORCE_INTEGRATED_GPU
|
||||
endif
|
||||
|
||||
ifeq ($(IMAGES_OPTIMIZED), true)
|
||||
CXXFLAGS += -D IMAGE_OPTIMIZED
|
||||
endif
|
||||
|
||||
ifeq ($(GRAPHICS_MEMORY_DUMP), true)
|
||||
CXXFLAGS += -D GRAPHICS_MEMORY_DUMP
|
||||
endif
|
||||
|
||||
RM = rm -f
|
||||
|
||||
%.o: %.cpp
|
||||
@@ -50,7 +67,7 @@ all: $(NAME)
|
||||
|
||||
$(NAME): $(OBJS)
|
||||
@echo "\e[1;32m[linking ...]\e[1;00m "$@
|
||||
@$(CXX) -shared -o $(NAME) $(OBJS)
|
||||
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDLIBS)
|
||||
@echo "\e[1;32m[build finished]\e[1;00m"
|
||||
|
||||
clean:
|
||||
|
||||
97
README.md
97
README.md
@@ -1,48 +1,85 @@
|
||||
# MacroLibX
|
||||
# MacroLibX [![linux clang workflow][linux-clang_badge]][linux-clang_wf] [![linux gcc workflow][linux-gcc_badge]][linux-gcc_wf] [![macos workflow][macos_badge]][macos_wf]
|
||||
###### A rewrite of 42 School's MiniLibX using SDL2 and Vulkan.
|
||||
|
||||
A rewrite of School 42's MiniLibX using SDL2 and Vulkan. The goal of this version is to give a light, fast and modern graphical tool while keeping the same API as the version currently used at 42.
|
||||
The goal of this version is to provide a light, fast, and modern graphical tool while keeping the same API.
|
||||
|
||||
# Installation
|
||||
## 🖥️ Installation
|
||||
|
||||
## Linux
|
||||
Dependances :
|
||||
### Dependencies
|
||||
|
||||
For Ubuntu/Debian
|
||||
```bash
|
||||
~ sudo apt update
|
||||
~ sudo apt install libsdl2-2.0-0 libsdl2-dev build-essential
|
||||
You first need to install the proper dependencies for your operating-system.
|
||||
|
||||
#### 🐧 Linux
|
||||
|
||||
Here are a few common cases for different Linux distributions:
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
For <a href="https://ubuntu.com">Ubuntu</a>/<a href="https://debian.org">Debian</a>-based distros:
|
||||
</summary>
|
||||
<pre><code><!--
|
||||
-->sudo apt update
|
||||
sudo apt install libsdl2-2.0-0 libsdl2-dev build-essential
|
||||
</code></pre>
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
For <a href="https://archlinux.org">ArchLinux</a>-based distros:
|
||||
</summary>
|
||||
<pre><code>sudo pacman -S sdl2</code></pre>
|
||||
</details>
|
||||
|
||||
#### 🍎 macOS
|
||||
|
||||
[MacroLibX](#) on macOS requires [SDL2](#) and [MoltenVK](https://github.com/KhronosGroup/MoltenVK). You can install both using the [Homebrew](https://brew.sh) package manager:
|
||||
```sh
|
||||
brew install molten-vk
|
||||
brew install SDL2
|
||||
```
|
||||
|
||||
For Arch based distros
|
||||
### Clone and Build
|
||||
|
||||
Finally, you can clone the Git repository. When inside it, run the GNU `make` command to compile MacroLibX.
|
||||
```bash
|
||||
~ sudo pacman -S sdl2
|
||||
git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
cd MacroLibX
|
||||
make
|
||||
```
|
||||
|
||||
### MacOS
|
||||
Dependances :
|
||||
* [MoltenVK](https://github.com/KhronosGroup/MoltenVK/)
|
||||
* SDL2 `brew install SDL2`
|
||||
|
||||
# Get MacroLibX
|
||||
|
||||
If you want to build using GCC you can add `TOOLCHAIN=gcc` to your `make` command
|
||||
```bash
|
||||
~ git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
~ cd MacroLibX
|
||||
~ make
|
||||
make TOOLCHAIN=gcc
|
||||
```
|
||||
|
||||
# Compile your project
|
||||
## 🔨 Compile your project
|
||||
|
||||
```bash
|
||||
clang myApp.c MacroLibX/libmlx.so -lSDL2
|
||||
To compile your project with MacroLibX, you just provide the shared library path in your compilation/linking command:
|
||||
|
||||
```sh
|
||||
clang myApp.c /path/to/MacroLibX/libmlx.so -lSDL2
|
||||
```
|
||||
|
||||
## /!\ If you run into glitches when writing or reading pixels from images /!\
|
||||
### ⚠️ Troubleshooting
|
||||
|
||||
You need to add `IMAGES_OPTIMIZED=false` to your make mlx command
|
||||
#### If you run into glitches when writing or reading pixels from images
|
||||
|
||||
```bash
|
||||
~ git clone https://github.com/420verfl0w/MacroLibX.git
|
||||
~ cd MacroLibX
|
||||
~ make IMAGES_OPTIMIZED=false
|
||||
You need to add `IMAGES_OPTIMIZED=false` to your `make` command:
|
||||
|
||||
```sh
|
||||
# In your cloned environment, inside the MacroLibX folder
|
||||
make IMAGES_OPTIMIZED=false
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
This project and all its files, except the [`third_party`](./third_party) directory or unless otherwise mentionned, are licenced under the [GNU GPL v2.0](./LICENSE).
|
||||
|
||||
<!-- Links -->
|
||||
|
||||
[linux-clang_badge]: https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_clang.yml/badge.svg
|
||||
[linux-gcc_badge]: https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_gcc.yml/badge.svg
|
||||
[macos_badge]: https://github.com/420verfl0w/MacroLibX/actions/workflows/macos_x86.yml/badge.svg
|
||||
[linux-clang_wf]: https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_clang.yml
|
||||
[linux-gcc_wf]: https://github.com/420verfl0w/MacroLibX/actions/workflows/linux_gcc.yml
|
||||
[macos_wf]: https://github.com/420verfl0w/MacroLibX/actions/workflows/macos_x86.yml
|
||||
|
||||
642
compile_commands.json
git.filemode.normal_file
642
compile_commands.json
git.filemode.normal_file
@@ -0,0 +1,642 @@
|
||||
[
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/text_pipeline.o",
|
||||
"src/renderer/text_pipeline.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/text_pipeline.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/text_pipeline.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/buffers/vk_vbo.o",
|
||||
"src/renderer/buffers/vk_vbo.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_vbo.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_vbo.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/pixel_put.o",
|
||||
"src/renderer/pixel_put.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/pixel_put.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/pixel_put.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/core/graphics.o",
|
||||
"src/core/graphics.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/core/graphics.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/core/graphics.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/buffers/vk_ubo.o",
|
||||
"src/renderer/buffers/vk_ubo.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_ubo.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_ubo.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/platform/inputs.o",
|
||||
"src/platform/inputs.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/platform/inputs.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/platform/inputs.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/renderer.o",
|
||||
"src/renderer/renderer.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/renderer.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/renderer.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/text_library.o",
|
||||
"src/renderer/text_library.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/text_library.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/text_library.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/buffers/vk_buffer.o",
|
||||
"src/renderer/buffers/vk_buffer.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_buffer.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/buffers/vk_buffer.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/command/cmd_manager.o",
|
||||
"src/renderer/command/cmd_manager.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/cmd_manager.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/cmd_manager.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_device.o",
|
||||
"src/renderer/core/vk_device.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_device.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_device.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/command/vk_cmd_buffer.o",
|
||||
"src/renderer/command/vk_cmd_buffer.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/vk_cmd_buffer.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/vk_cmd_buffer.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/render_core.o",
|
||||
"src/renderer/core/render_core.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/render_core.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/render_core.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/command/vk_cmd_pool.o",
|
||||
"src/renderer/command/vk_cmd_pool.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/vk_cmd_pool.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/command/vk_cmd_pool.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_instance.o",
|
||||
"src/renderer/core/vk_instance.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_instance.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_instance.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_semaphore.o",
|
||||
"src/renderer/core/vk_semaphore.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_semaphore.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_semaphore.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_queues.o",
|
||||
"src/renderer/core/vk_queues.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_queues.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_queues.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_validation_layers.o",
|
||||
"src/renderer/core/vk_validation_layers.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_validation_layers.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_validation_layers.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_surface.o",
|
||||
"src/renderer/core/vk_surface.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_surface.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_surface.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/core/vk_fence.o",
|
||||
"src/renderer/core/vk_fence.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_fence.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/core/vk_fence.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/descriptors/vk_descriptor_pool.o",
|
||||
"src/renderer/descriptors/vk_descriptor_pool.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_pool.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_pool.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/images/texture_atlas.o",
|
||||
"src/renderer/images/texture_atlas.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/texture_atlas.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/texture_atlas.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/descriptors/vk_descriptor_set.o",
|
||||
"src/renderer/descriptors/vk_descriptor_set.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_set.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_set.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/swapchain/vk_framebuffer.o",
|
||||
"src/renderer/swapchain/vk_framebuffer.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_framebuffer.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_framebuffer.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/pipeline/pipeline.o",
|
||||
"src/renderer/pipeline/pipeline.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/pipeline/pipeline.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/pipeline/pipeline.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/images/vk_image.o",
|
||||
"src/renderer/images/vk_image.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/vk_image.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/vk_image.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/descriptors/vk_descriptor_set_layout.o",
|
||||
"src/renderer/descriptors/vk_descriptor_set_layout.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_set_layout.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/descriptors/vk_descriptor_set_layout.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/swapchain/vk_imageview.o",
|
||||
"src/renderer/swapchain/vk_imageview.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_imageview.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_imageview.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/swapchain/vk_swapchain.o",
|
||||
"src/renderer/swapchain/vk_swapchain.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_swapchain.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_swapchain.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/swapchain/vk_render_pass.o",
|
||||
"src/renderer/swapchain/vk_render_pass.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_render_pass.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/swapchain/vk_render_pass.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/platform/window.o",
|
||||
"src/platform/window.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/platform/window.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/platform/window.o"
|
||||
},
|
||||
{
|
||||
"arguments": [
|
||||
"/usr/bin/clang++",
|
||||
"-std=c++17",
|
||||
"-O3",
|
||||
"-fPIC",
|
||||
"-D",
|
||||
"IMAGE_OPTIMIZED",
|
||||
"-I./includes",
|
||||
"-I./src",
|
||||
"-I./third_party",
|
||||
"-c",
|
||||
"-o",
|
||||
"src/renderer/images/texture.o",
|
||||
"src/renderer/images/texture.cpp"
|
||||
],
|
||||
"directory": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX",
|
||||
"file": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/texture.cpp",
|
||||
"output": "/home/kbz_8/Documents/Programmation/42/other/MacroLibX/src/renderer/images/texture.o"
|
||||
}
|
||||
]
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 22:10:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/28 10:19:53 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:47:50 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <array>
|
||||
#include <core/errors.h>
|
||||
#include <utils/endian.h>
|
||||
#include <core/profile.h>
|
||||
|
||||
namespace mlx::core
|
||||
{
|
||||
@@ -43,7 +44,11 @@ namespace mlx::core
|
||||
|
||||
void* Application::newTexture(int w, int h)
|
||||
{
|
||||
_textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
#ifdef DEBUG
|
||||
_textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_unamed_user_texture");
|
||||
#else
|
||||
_textures.emplace_front().create(nullptr, w, h, VK_FORMAT_R8G8B8A8_UNORM, nullptr);
|
||||
#endif
|
||||
return &_textures.front();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:49:46 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/28 10:19:35 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/17 11:57:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace mlx::core
|
||||
|
||||
inline void loopHook(int (*f)(void*), void* param);
|
||||
inline void loopEnd() noexcept;
|
||||
|
||||
|
||||
void run() noexcept;
|
||||
|
||||
~Application();
|
||||
|
||||
@@ -42,7 +42,7 @@ namespace mlx::core
|
||||
|
||||
void* Application::newGraphicsSuport(std::size_t w, std::size_t h, std::string title)
|
||||
{
|
||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, std::move(title), _graphics.size()));
|
||||
_graphics.emplace_back(std::make_unique<GraphicsSupport>(w, h, title, _graphics.size()));
|
||||
_in->addWindow(_graphics.back()->getWindow());
|
||||
return static_cast<void*>(&_graphics.back()->getID());
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:35:20 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/25 15:23:05 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 11:43:30 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,7 +20,14 @@ extern "C"
|
||||
{
|
||||
void* mlx_init()
|
||||
{
|
||||
static bool init = false;
|
||||
if(init)
|
||||
{
|
||||
mlx::core::error::report(e_kind::error, "MLX cannot be initialized multiple times");
|
||||
return NULL;
|
||||
}
|
||||
mlx::Render_Core::get().init();
|
||||
init = true;
|
||||
return new mlx::core::Application();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:48:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 13:07:56 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 07:14:57 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,15 +17,17 @@
|
||||
|
||||
#include "errors.h"
|
||||
|
||||
constexpr const int BUFFER_SIZE = 4096;
|
||||
|
||||
namespace mlx::core::error
|
||||
{
|
||||
void report(e_kind kind, std::string msg, ...)
|
||||
{
|
||||
char buffer[4096];
|
||||
char buffer[BUFFER_SIZE];
|
||||
|
||||
va_list al;
|
||||
va_start(al, msg);
|
||||
std::vsprintf(buffer, msg.c_str(), al);
|
||||
std::vsnprintf(buffer, BUFFER_SIZE, msg.c_str(), al);
|
||||
va_end(al);
|
||||
|
||||
switch(kind)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 15:13:55 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/08 00:19:18 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 06:59:12 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id) :
|
||||
_window(std::make_shared<MLX_Window>(w, h, std::move(title))),
|
||||
GraphicsSupport::GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id) :
|
||||
_window(std::make_shared<MLX_Window>(w, h, title)),
|
||||
_renderer(std::make_unique<Renderer>()), _text_put_pipeline(std::make_unique<TextPutPipeline>()),
|
||||
_id(id)
|
||||
{
|
||||
@@ -29,8 +29,10 @@ namespace mlx
|
||||
{
|
||||
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
|
||||
|
||||
std::vector<VkDescriptorSet> sets;
|
||||
sets.push_back(_renderer->getVertDescriptorSet().get());
|
||||
static std::array<VkDescriptorSet, 2> sets = {
|
||||
_renderer->getVertDescriptorSet().get(),
|
||||
VK_NULL_HANDLE
|
||||
};
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
{
|
||||
@@ -38,27 +40,35 @@ namespace mlx
|
||||
data.texture->setDescriptor(_renderer->getFragDescriptorSet().duplicate());
|
||||
if(!data.texture->hasBeenUpdated())
|
||||
data.texture->updateSet(0);
|
||||
sets.push_back(data.texture->getSet());
|
||||
sets[1] = data.texture->getSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
data.texture->render(*_renderer, data.x, data.y);
|
||||
sets.pop_back();
|
||||
}
|
||||
|
||||
_pixel_put_pipeline.present();
|
||||
|
||||
sets.push_back(_pixel_put_pipeline.getDescriptorSet());
|
||||
sets[1] = _pixel_put_pipeline.getDescriptorSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
_pixel_put_pipeline.render(*_renderer);
|
||||
sets.pop_back();
|
||||
|
||||
sets.push_back(_text_put_pipeline->getDescriptorSet());
|
||||
sets[1] = _text_put_pipeline->getDescriptorSet();
|
||||
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
|
||||
_text_put_pipeline->render();
|
||||
|
||||
|
||||
_renderer->endFrame();
|
||||
|
||||
for(auto& data : _textures_to_render)
|
||||
data.texture->resetUpdate();
|
||||
|
||||
#ifdef GRAPHICS_MEMORY_DUMP
|
||||
// dump memory to file every two seconds
|
||||
static uint64_t timer = SDL_GetTicks64();
|
||||
if(SDL_GetTicks64() - timer > 2000)
|
||||
{
|
||||
Render_Core::get().getAllocator().dumpMemoryToJson();
|
||||
timer += 2000;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
GraphicsSupport::~GraphicsSupport()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 14:49:49 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/21 18:43:38 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 11:39:55 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -32,19 +32,18 @@ namespace mlx
|
||||
class GraphicsSupport : public non_copyable
|
||||
{
|
||||
public:
|
||||
GraphicsSupport(std::size_t w, std::size_t h, std::string title, int id);
|
||||
GraphicsSupport(std::size_t w, std::size_t h, const std::string& title, int id);
|
||||
|
||||
inline int& getID() noexcept;
|
||||
inline std::shared_ptr<MLX_Window> getWindow();
|
||||
|
||||
inline void beginRender() noexcept;
|
||||
void endRender() noexcept;
|
||||
|
||||
inline void clearRenderData() noexcept;
|
||||
inline void pixelPut(int x, int y, uint32_t color) noexcept;
|
||||
inline void stringPut(int x, int y, int color, std::string str);
|
||||
inline void texturePut(Texture* texture, int x, int y);
|
||||
|
||||
void endRender() noexcept;
|
||||
|
||||
~GraphicsSupport();
|
||||
|
||||
|
||||
60
src/core/profile.h
git.filemode.normal_file
60
src/core/profile.h
git.filemode.normal_file
@@ -0,0 +1,60 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* profile.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/10 08:49:17 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/10 09:05:56 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_PROFILE__
|
||||
#define __MLX_PROFILE__
|
||||
|
||||
// Try to identify the compiler
|
||||
#if defined(__BORLANDC__)
|
||||
#define MLX_COMPILER_BORDLAND
|
||||
#elif defined(__clang__)
|
||||
#define MLX_COMPILER_CLANG
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__GNUC__) || defined(__MINGW32__)
|
||||
#define MLX_COMPILER_GCC
|
||||
#ifdef __MINGW32__
|
||||
#define MLX_COMPILER_MINGW
|
||||
#ifdef __MINGW64_VERSION_MAJOR
|
||||
#define MLX_COMPILER_MINGW_W64
|
||||
#endif
|
||||
#endif
|
||||
#elif defined(__INTEL_COMPILER) || defined(__ICL)
|
||||
#define MLX_COMPILER_INTEL
|
||||
#elif defined(_MSC_VER)
|
||||
#define MLX_COMPILER_MSVC
|
||||
#else
|
||||
#define MLX_COMPILER_UNKNOWN
|
||||
#warning "This compiler is not fully supported"
|
||||
#endif
|
||||
|
||||
// Checking common assumptions
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
|
||||
static_assert(CHAR_BIT == 8, "CHAR_BIT is expected to be 8");
|
||||
|
||||
static_assert(sizeof(int8_t) == 1, "int8_t is not of the correct size" );
|
||||
static_assert(sizeof(int16_t) == 2, "int16_t is not of the correct size");
|
||||
static_assert(sizeof(int32_t) == 4, "int32_t is not of the correct size");
|
||||
static_assert(sizeof(int64_t) == 8, "int64_t is not of the correct size");
|
||||
|
||||
static_assert(sizeof(uint8_t) == 1, "uint8_t is not of the correct size" );
|
||||
static_assert(sizeof(uint16_t) == 2, "uint16_t is not of the correct size");
|
||||
static_assert(sizeof(uint32_t) == 4, "uint32_t is not of the correct size");
|
||||
static_assert(sizeof(uint64_t) == 8, "uint64_t is not of the correct size");
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/12 18:45:05 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:24:38 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
MLX_Window::MLX_Window(std::size_t w, std::size_t h, std::string title) : _width(w), _height(h)
|
||||
MLX_Window::MLX_Window(std::size_t w, std::size_t h, const std::string& title) : _width(w), _height(h)
|
||||
{
|
||||
_win = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN);
|
||||
if(!_win)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/12 19:06:24 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:24:46 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace mlx
|
||||
class MLX_Window
|
||||
{
|
||||
public:
|
||||
MLX_Window(std::size_t w, std::size_t h, std::string title);
|
||||
MLX_Window(std::size_t w, std::size_t h, const std::string& title);
|
||||
|
||||
inline SDL_Window* getNativeWindow() const noexcept { return _win; }
|
||||
inline int getWidth() const noexcept { return _width; }
|
||||
|
||||
@@ -6,19 +6,23 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 12:37:32 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:54:25 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "vk_buffer.h"
|
||||
#include <renderer/command/vk_cmd_pool.h>
|
||||
#include <renderer/command/vk_cmd_buffer.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <vma.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Buffer::create(Buffer::kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data)
|
||||
void Buffer::create(Buffer::kind type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data)
|
||||
{
|
||||
_usage = usage;
|
||||
if(type == Buffer::kind::constant)
|
||||
{
|
||||
if(data == nullptr)
|
||||
@@ -26,31 +30,21 @@ namespace mlx
|
||||
core::error::report(e_kind::warning, "Vulkan : trying to create constant buffer without data (constant buffers cannot be modified after creation)");
|
||||
return;
|
||||
}
|
||||
_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
}
|
||||
else if(type == Buffer::kind::uniform)
|
||||
{
|
||||
_usage = usage;
|
||||
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
_usage = usage;
|
||||
_flags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
_usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
}
|
||||
|
||||
_size = size;
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO;
|
||||
|
||||
createBuffer(_usage, _flags);
|
||||
createBuffer(_usage, alloc_info, size, name);
|
||||
|
||||
if(type == Buffer::kind::constant || data != nullptr)
|
||||
if(data != nullptr)
|
||||
{
|
||||
void* mapped = nullptr;
|
||||
mapMem(&mapped);
|
||||
std::memcpy(mapped, data, _size);
|
||||
std::memcpy(mapped, data, size);
|
||||
unmapMem();
|
||||
|
||||
if(type == Buffer::kind::constant)
|
||||
pushToGPU();
|
||||
}
|
||||
@@ -58,80 +52,66 @@ namespace mlx
|
||||
|
||||
void Buffer::destroy() noexcept
|
||||
{
|
||||
vkDestroyBuffer(Render_Core::get().getDevice().get(), _buffer, nullptr);
|
||||
vkFreeMemory(Render_Core::get().getDevice().get(), _memory, nullptr);
|
||||
if(_is_mapped)
|
||||
unmapMem();
|
||||
if(_buffer != VK_NULL_HANDLE)
|
||||
Render_Core::get().getAllocator().destroyBuffer(_allocation, _buffer);
|
||||
_buffer = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
void Buffer::createBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties)
|
||||
void Buffer::createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, const char* name)
|
||||
{
|
||||
VkBufferCreateInfo bufferInfo{};
|
||||
bufferInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
bufferInfo.size = _size;
|
||||
bufferInfo.size = size;
|
||||
bufferInfo.usage = usage;
|
||||
bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
|
||||
auto device = Render_Core::get().getDevice().get();
|
||||
|
||||
if(vkCreateBuffer(device, &bufferInfo, nullptr, &_buffer) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create buffer");
|
||||
|
||||
VkMemoryRequirements memRequirements;
|
||||
vkGetBufferMemoryRequirements(device, _buffer, &memRequirements);
|
||||
|
||||
VkMemoryAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
allocInfo.allocationSize = memRequirements.size;
|
||||
allocInfo.memoryTypeIndex = *RCore::findMemoryType(memRequirements.memoryTypeBits, properties);
|
||||
|
||||
if(vkAllocateMemory(device, &allocInfo, nullptr, &_memory) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate buffer memory");
|
||||
if(vkBindBufferMemory(device, _buffer, _memory, _offset) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : unable to bind device memory to a buffer object");
|
||||
#ifdef DEBUG
|
||||
_name = name;
|
||||
std::string alloc_name = _name;
|
||||
if(usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT)
|
||||
alloc_name.append("_index_buffer");
|
||||
else if(usage & VK_BUFFER_USAGE_VERTEX_BUFFER_BIT)
|
||||
alloc_name.append("_vertex_buffer");
|
||||
else if((usage & VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT) != 1)
|
||||
alloc_name.append("_buffer");
|
||||
_allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, alloc_name.c_str());
|
||||
#else
|
||||
_allocation = Render_Core::get().getAllocator().createBuffer(&bufferInfo, &info, _buffer, nullptr);
|
||||
#endif
|
||||
_size = size;
|
||||
}
|
||||
|
||||
void Buffer::pushToGPU() noexcept
|
||||
{
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||
|
||||
Buffer newBuffer;
|
||||
newBuffer._size = _size;
|
||||
newBuffer._usage = (this->_usage & 0xFFFFFFFC) | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
newBuffer._flags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||
newBuffer.createBuffer(newBuffer._usage, newBuffer._flags);
|
||||
newBuffer._usage = (_usage & 0xFFFFFFFC) | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
#ifdef DEBUG
|
||||
std::string new_name = _name + "_GPU";
|
||||
newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, new_name.c_str());
|
||||
#else
|
||||
newBuffer.createBuffer(newBuffer._usage, alloc_info, _size, nullptr);
|
||||
#endif
|
||||
|
||||
CmdPool cmdpool;
|
||||
cmdpool.init();
|
||||
auto device = Render_Core::get().getDevice().get();
|
||||
CmdBuffer cmdBuffer;
|
||||
cmdBuffer.init(&cmdpool);
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandPool = cmdpool.get();
|
||||
allocInfo.commandBufferCount = 1;
|
||||
|
||||
VkCommandBuffer commandBuffer;
|
||||
vkAllocateCommandBuffers(device, &allocInfo, &commandBuffer);
|
||||
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
|
||||
|
||||
vkBeginCommandBuffer(commandBuffer, &beginInfo);
|
||||
cmdBuffer.beginRecord(VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||
|
||||
VkBufferCopy copyRegion{};
|
||||
copyRegion.size = _size;
|
||||
vkCmdCopyBuffer(commandBuffer, _buffer, newBuffer._buffer, 1, ©Region);
|
||||
vkCmdCopyBuffer(cmdBuffer.get(), _buffer, newBuffer._buffer, 1, ©Region);
|
||||
|
||||
vkEndCommandBuffer(commandBuffer);
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
||||
submitInfo.commandBufferCount = 1;
|
||||
submitInfo.pCommandBuffers = &commandBuffer;
|
||||
|
||||
auto graphicsQueue = Render_Core::get().getQueue().getGraphic();
|
||||
|
||||
vkQueueSubmit(graphicsQueue, 1, &submitInfo, VK_NULL_HANDLE);
|
||||
vkQueueWaitIdle(graphicsQueue);
|
||||
cmdBuffer.endRecord();
|
||||
cmdBuffer.submitIdle();
|
||||
|
||||
cmdBuffer.destroy();
|
||||
cmdpool.destroy();
|
||||
|
||||
this->swap(newBuffer);
|
||||
@@ -145,6 +125,10 @@ namespace mlx
|
||||
_buffer = buffer._buffer;
|
||||
buffer._buffer = temp_b;
|
||||
|
||||
VmaAllocation temp_a = buffer._allocation;
|
||||
buffer._allocation = _allocation;
|
||||
_allocation = temp_a;
|
||||
|
||||
VkDeviceSize temp_size = buffer._size;
|
||||
buffer._size = _size;
|
||||
_size = temp_size;
|
||||
@@ -153,26 +137,13 @@ namespace mlx
|
||||
buffer._offset = _offset;
|
||||
_offset = temp_offset;
|
||||
|
||||
VkDeviceMemory temp_memory = buffer._memory;
|
||||
buffer._memory = _memory;
|
||||
_memory = temp_memory;
|
||||
|
||||
VkBufferUsageFlags temp_u = _usage;
|
||||
_usage = buffer._usage;
|
||||
buffer._usage = temp_u;
|
||||
|
||||
VkMemoryPropertyFlags temp_f = _flags;
|
||||
_flags = buffer._flags;
|
||||
buffer._flags = temp_f;
|
||||
}
|
||||
|
||||
void Buffer::flush(VkDeviceSize size, VkDeviceSize offset)
|
||||
{
|
||||
VkMappedMemoryRange mappedRange{};
|
||||
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
|
||||
mappedRange.memory = _memory;
|
||||
mappedRange.offset = offset;
|
||||
mappedRange.size = size;
|
||||
vkFlushMappedMemoryRanges(Render_Core::get().getDevice().get(), 1, &mappedRange);
|
||||
Render_Core::get().getAllocator().flush(_allocation, size, offset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:51:47 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:56:19 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,40 +23,38 @@ namespace mlx
|
||||
public:
|
||||
enum class kind { dynamic, uniform, constant };
|
||||
|
||||
void create(kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data = nullptr);
|
||||
void create(kind type, VkDeviceSize size, VkBufferUsageFlags usage, const char* name, const void* data = nullptr);
|
||||
void destroy() noexcept;
|
||||
|
||||
inline void mapMem(void** data = nullptr, VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0) noexcept
|
||||
{
|
||||
if(vkMapMemory(Render_Core::get().getDevice().get(), _memory, _offset + offset, size, 0, data) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to map a buffer");
|
||||
_is_mapped = true;
|
||||
}
|
||||
inline void mapMem(void** data) noexcept { Render_Core::get().getAllocator().mapMemory(_allocation, data); _is_mapped = true; }
|
||||
inline bool isMapped() const noexcept { return _is_mapped; }
|
||||
inline void unmapMem() noexcept { vkUnmapMemory(Render_Core::get().getDevice().get(), _memory); _is_mapped = false; }
|
||||
inline void unmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(_allocation); _is_mapped = false; }
|
||||
|
||||
void flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
|
||||
|
||||
inline unsigned int getSize() noexcept { return _size; }
|
||||
inline unsigned int getOffset() noexcept { return _offset; }
|
||||
inline VkDeviceMemory getDeviceMemory() noexcept { return _memory; }
|
||||
inline VkBuffer& operator()() noexcept { return _buffer; }
|
||||
inline VkBuffer& get() noexcept { return _buffer; }
|
||||
inline VkDeviceSize getSize() const noexcept { return _size; }
|
||||
inline VkDeviceSize getOffset() const noexcept { return _offset; }
|
||||
|
||||
protected:
|
||||
void pushToGPU() noexcept;
|
||||
void swap(Buffer& buffer) noexcept;
|
||||
|
||||
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
||||
VkDeviceSize _offset = 0;
|
||||
VkDeviceSize _size = 0;
|
||||
protected:
|
||||
VmaAllocation _allocation;
|
||||
VkBuffer _buffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize _offset = 0;
|
||||
VkDeviceSize _size = 0;
|
||||
|
||||
private:
|
||||
void createBuffer(VkBufferUsageFlags usage, VkMemoryPropertyFlags properties);
|
||||
void createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size, const char* name);
|
||||
|
||||
private:
|
||||
#ifdef DEBUG
|
||||
std::string _name;
|
||||
#endif
|
||||
VkBufferUsageFlags _usage = 0;
|
||||
VkMemoryPropertyFlags _flags = 0;
|
||||
bool _is_mapped = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:51:54 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 03:25:59 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mlx
|
||||
class C_IBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const uint16_t* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, data); }
|
||||
inline void create(uint32_t size, const uint16_t* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, name, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindIndexBuffer(renderer.getActiveCmdBuffer().get(), _buffer, _offset, VK_INDEX_TYPE_UINT16); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:45:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:51:56 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:57:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,13 +16,19 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void UBO::create(Renderer* renderer, uint32_t size)
|
||||
void UBO::create(Renderer* renderer, uint32_t size, const char* name)
|
||||
{
|
||||
_renderer = renderer;
|
||||
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
_buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT);
|
||||
#ifdef DEBUG
|
||||
std::string name_frame = name;
|
||||
name_frame.append(std::to_string(i));
|
||||
_buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, name_frame.c_str());
|
||||
#else
|
||||
_buffers[i].create(Buffer::kind::uniform, size, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, nullptr);
|
||||
#endif
|
||||
_buffers[i].mapMem(&_maps[i]);
|
||||
if(_maps[i] == nullptr)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : unable to map a uniform buffer");
|
||||
@@ -50,11 +56,6 @@ namespace mlx
|
||||
return _buffers[_renderer->getActiveImageIndex()].getOffset();
|
||||
}
|
||||
|
||||
VkDeviceMemory UBO::getDeviceMemory() noexcept
|
||||
{
|
||||
return _buffers[_renderer->getActiveImageIndex()].getDeviceMemory();
|
||||
}
|
||||
|
||||
VkBuffer& UBO::operator()() noexcept
|
||||
{
|
||||
return _buffers[_renderer->getActiveImageIndex()].get();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:45:29 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:51:59 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 03:26:10 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,7 +22,7 @@ namespace mlx
|
||||
class UBO
|
||||
{
|
||||
public:
|
||||
void create(class Renderer* renderer, uint32_t size);
|
||||
void create(class Renderer* renderer, uint32_t size, const char* name);
|
||||
|
||||
void setData(uint32_t size, const void* data);
|
||||
void setDynamicData(uint32_t size, const void* data);
|
||||
@@ -37,7 +37,6 @@ namespace mlx
|
||||
|
||||
inline unsigned int getSize(int i) noexcept { return _buffers[i].getSize(); }
|
||||
inline unsigned int getOffset(int i) noexcept { return _buffers[i].getOffset(); }
|
||||
inline VkDeviceMemory getDeviceMemory(int i) noexcept { return _buffers[i].getDeviceMemory(); }
|
||||
inline VkBuffer& operator()(int i) noexcept { return _buffers[i].get(); }
|
||||
inline VkBuffer& get(int i) noexcept { return _buffers[i].get(); }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:28:08 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/19 15:38:45 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/10 08:33:52 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,8 +17,8 @@ namespace mlx
|
||||
{
|
||||
void VBO::setData(uint32_t size, const void* data)
|
||||
{
|
||||
if(size > _size)
|
||||
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, _size);
|
||||
if(size > getSize())
|
||||
core::error::report(e_kind::error, "Vulkan : trying to store to much data in a vertex buffer (%d bytes in %d bytes)", size, getSize());
|
||||
|
||||
if(data == nullptr)
|
||||
core::error::report(e_kind::warning, "Vulkan : mapping null data in a vertex buffer");
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:52:05 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 04:53:36 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -21,17 +21,15 @@ namespace mlx
|
||||
class VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); }
|
||||
|
||||
inline void create(uint32_t size, const char* name) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name); }
|
||||
void setData(uint32_t size, const void* data);
|
||||
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
|
||||
class C_VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, data); }
|
||||
inline void create(uint32_t size, const void* data, const char* name) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, name, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 15:19:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:17:49 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -34,6 +34,9 @@ namespace mlx
|
||||
|
||||
if(vkAllocateCommandBuffers(Render_Core::get().getDevice().get(), &allocInfo, &_cmd_buffer) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate command buffer");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new command buffer");
|
||||
#endif
|
||||
|
||||
_fence.init();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:24:33 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:56:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:23:38 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -29,5 +29,6 @@ namespace mlx
|
||||
void CmdPool::destroy() noexcept
|
||||
{
|
||||
vkDestroyCommandPool(Render_Core::get().getDevice().get(), _cmd_pool, nullptr);
|
||||
_cmd_pool = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
160
src/renderer/core/memory.cpp
git.filemode.normal_file
160
src/renderer/core/memory.cpp
git.filemode.normal_file
@@ -0,0 +1,160 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memory.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: kbz_8 <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/20 22:02:37 by kbz_8 #+# #+# */
|
||||
/* Updated: 2023/11/14 12:45:29 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <core/profile.h>
|
||||
#include <core/errors.h>
|
||||
#include <cstdio>
|
||||
|
||||
#define VMA_STATIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0
|
||||
#define VMA_VULKAN_VERSION 1002000
|
||||
#define VMA_ASSERT(expr) (static_cast<bool>(expr) ? void(0) : mlx::core::error::report(e_kind::fatal_error, "Graphics allocator : an assertion has been catched : '%s'", #expr))
|
||||
#define VMA_IMPLEMENTATION
|
||||
|
||||
#ifdef MLX_COMPILER_CLANG
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wnullability-completeness"
|
||||
#include <renderer/core/memory.h>
|
||||
#pragma clang diagnostic pop
|
||||
#else
|
||||
#include <renderer/core/memory.h>
|
||||
#endif
|
||||
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void GPUallocator::init() noexcept
|
||||
{
|
||||
VmaVulkanFunctions vma_vulkan_func{};
|
||||
vma_vulkan_func.vkAllocateMemory = vkAllocateMemory;
|
||||
vma_vulkan_func.vkBindBufferMemory = vkBindBufferMemory;
|
||||
vma_vulkan_func.vkBindImageMemory = vkBindImageMemory;
|
||||
vma_vulkan_func.vkCreateBuffer = vkCreateBuffer;
|
||||
vma_vulkan_func.vkCreateImage = vkCreateImage;
|
||||
vma_vulkan_func.vkDestroyBuffer = vkDestroyBuffer;
|
||||
vma_vulkan_func.vkDestroyImage = vkDestroyImage;
|
||||
vma_vulkan_func.vkFlushMappedMemoryRanges = vkFlushMappedMemoryRanges;
|
||||
vma_vulkan_func.vkFreeMemory = vkFreeMemory;
|
||||
vma_vulkan_func.vkGetBufferMemoryRequirements = vkGetBufferMemoryRequirements;
|
||||
vma_vulkan_func.vkGetImageMemoryRequirements = vkGetImageMemoryRequirements;
|
||||
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties = vkGetPhysicalDeviceMemoryProperties;
|
||||
vma_vulkan_func.vkGetPhysicalDeviceProperties = vkGetPhysicalDeviceProperties;
|
||||
vma_vulkan_func.vkInvalidateMappedMemoryRanges = vkInvalidateMappedMemoryRanges;
|
||||
vma_vulkan_func.vkMapMemory = vkMapMemory;
|
||||
vma_vulkan_func.vkUnmapMemory = vkUnmapMemory;
|
||||
vma_vulkan_func.vkCmdCopyBuffer = vkCmdCopyBuffer;
|
||||
vma_vulkan_func.vkGetBufferMemoryRequirements2KHR = vkGetBufferMemoryRequirements2;
|
||||
vma_vulkan_func.vkGetImageMemoryRequirements2KHR = vkGetImageMemoryRequirements2;
|
||||
vma_vulkan_func.vkBindBufferMemory2KHR = vkBindBufferMemory2;
|
||||
vma_vulkan_func.vkBindImageMemory2KHR = vkBindImageMemory2;
|
||||
vma_vulkan_func.vkGetPhysicalDeviceMemoryProperties2KHR = vkGetPhysicalDeviceMemoryProperties2;
|
||||
|
||||
VmaAllocatorCreateInfo allocatorCreateInfo{};
|
||||
allocatorCreateInfo.vulkanApiVersion = VK_API_VERSION_1_2;
|
||||
allocatorCreateInfo.physicalDevice = Render_Core::get().getDevice().getPhysicalDevice();
|
||||
allocatorCreateInfo.device = Render_Core::get().getDevice().get();
|
||||
allocatorCreateInfo.instance = Render_Core::get().getInstance().get();
|
||||
allocatorCreateInfo.pVulkanFunctions = &vma_vulkan_func;
|
||||
|
||||
if(vmaCreateAllocator(&allocatorCreateInfo, &_allocator) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create graphics memory allocator");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new allocator");
|
||||
#endif
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
if(vmaCreateBuffer(_allocator, binfo, vinfo, &buffer, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate a buffer");
|
||||
if(name != nullptr)
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new buffer");
|
||||
#endif
|
||||
return allocation;
|
||||
}
|
||||
|
||||
void GPUallocator::destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
vmaDestroyBuffer(_allocator, buffer, allocation);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : destroyed buffer");
|
||||
#endif
|
||||
}
|
||||
|
||||
VmaAllocation GPUallocator::createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name) noexcept
|
||||
{
|
||||
VmaAllocation allocation;
|
||||
if(vmaCreateImage(_allocator, iminfo, vinfo, &image, &allocation, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate an image");
|
||||
if(name != nullptr)
|
||||
vmaSetAllocationName(_allocator, allocation, name);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : created new image");
|
||||
#endif
|
||||
return allocation;
|
||||
}
|
||||
|
||||
void GPUallocator::destroyImage(VmaAllocation allocation, VkImage image) noexcept
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
vmaDestroyImage(_allocator, image, allocation);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Graphics Allocator : destroyed image");
|
||||
#endif
|
||||
}
|
||||
|
||||
void GPUallocator::mapMemory(VmaAllocation allocation, void** data) noexcept
|
||||
{
|
||||
if(vmaMapMemory(_allocator, allocation, data) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Graphics allocator : unable to map GPU memory to CPU memory");
|
||||
}
|
||||
|
||||
void GPUallocator::unmapMemory(VmaAllocation allocation) noexcept
|
||||
{
|
||||
vmaUnmapMemory(_allocator, allocation);
|
||||
}
|
||||
|
||||
void GPUallocator::dumpMemoryToJson()
|
||||
{
|
||||
static uint32_t id = 0;
|
||||
std::string name("memory_dump");
|
||||
name.append(std::to_string(id) + ".json");
|
||||
std::ofstream file(name);
|
||||
if(!file.is_open())
|
||||
{
|
||||
core::error::report(e_kind::error, "Graphics allocator : unable to dump memory to a json file");
|
||||
return;
|
||||
}
|
||||
char* str = nullptr;
|
||||
vmaBuildStatsString(_allocator, &str, true);
|
||||
file << str;
|
||||
vmaFreeStatsString(_allocator, str);
|
||||
file.close();
|
||||
id++;
|
||||
}
|
||||
|
||||
void GPUallocator::flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept
|
||||
{
|
||||
vmaFlushAllocation(_allocator, allocation, offset, size);
|
||||
}
|
||||
|
||||
void GPUallocator::destroy() noexcept
|
||||
{
|
||||
vmaDestroyAllocator(_allocator);
|
||||
}
|
||||
}
|
||||
49
src/renderer/core/memory.h
git.filemode.normal_file
49
src/renderer/core/memory.h
git.filemode.normal_file
@@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* memory.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/20 02:13:03 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/14 09:46:32 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_MEMORY__
|
||||
#define __MLX_VK_MEMORY__
|
||||
|
||||
#include <volk.h>
|
||||
#include <vma.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class GPUallocator
|
||||
{
|
||||
public:
|
||||
GPUallocator() = default;
|
||||
|
||||
void init() noexcept;
|
||||
void destroy() noexcept;
|
||||
|
||||
VmaAllocation createBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name = nullptr) noexcept;
|
||||
void destroyBuffer(VmaAllocation allocation, VkBuffer buffer) noexcept;
|
||||
|
||||
VmaAllocation createImage(const VkImageCreateInfo* iminfo, const VmaAllocationCreateInfo* vinfo, VkImage& image, const char* name = nullptr) noexcept;
|
||||
void destroyImage(VmaAllocation allocation, VkImage image) noexcept;
|
||||
|
||||
void mapMemory(VmaAllocation allocation, void** data) noexcept;
|
||||
void unmapMemory(VmaAllocation allocation) noexcept;
|
||||
|
||||
void dumpMemoryToJson();
|
||||
|
||||
void flush(VmaAllocation allocation, VkDeviceSize size, VkDeviceSize offset) noexcept;
|
||||
|
||||
~GPUallocator() = default;
|
||||
|
||||
private:
|
||||
VmaAllocator _allocator;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 19:09:21 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 14:06:46 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <mutex>
|
||||
|
||||
#ifdef DEBUG
|
||||
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages and may impact rendering performances"
|
||||
#warning "MLX is being compiled in debug mode, this activates Vulkan's validation layers and debug messages which may impact rendering performances"
|
||||
#endif
|
||||
|
||||
namespace mlx
|
||||
@@ -57,6 +57,7 @@ namespace mlx
|
||||
_device.init();
|
||||
volkLoadDevice(_device.get());
|
||||
_queues.init();
|
||||
_allocator.init();
|
||||
_is_init = true;
|
||||
}
|
||||
|
||||
@@ -67,6 +68,7 @@ namespace mlx
|
||||
|
||||
vkDeviceWaitIdle(_device());
|
||||
|
||||
_allocator.destroy();
|
||||
_device.destroy();
|
||||
_layers.destroy();
|
||||
_instance.destroy();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:16:32 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 12:31:42 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 05:00:44 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "vk_device.h"
|
||||
#include "vk_instance.h"
|
||||
#include "vk_validation_layers.h"
|
||||
#include "memory.h"
|
||||
|
||||
#include <utils/singleton.h>
|
||||
#include <core/errors.h>
|
||||
@@ -39,7 +40,7 @@ namespace mlx
|
||||
|
||||
const std::vector<const char*> validationLayers = { "VK_LAYER_KHRONOS_validation" };
|
||||
|
||||
constexpr const int MAX_FRAMES_IN_FLIGHT = 2;
|
||||
constexpr const int MAX_FRAMES_IN_FLIGHT = 3;
|
||||
|
||||
class Render_Core : public Singleton<Render_Core>
|
||||
{
|
||||
@@ -52,6 +53,7 @@ namespace mlx
|
||||
inline Instance& getInstance() noexcept { return _instance; }
|
||||
inline Device& getDevice() noexcept { return _device; }
|
||||
inline Queues& getQueue() noexcept { return _queues; }
|
||||
inline GPUallocator& getAllocator() noexcept { return _allocator; }
|
||||
inline ValidationLayers& getLayers() noexcept { return _layers; }
|
||||
|
||||
~Render_Core() = default;
|
||||
@@ -61,6 +63,7 @@ namespace mlx
|
||||
Queues _queues;
|
||||
Device _device;
|
||||
Instance _instance;
|
||||
GPUallocator _allocator;
|
||||
bool _is_init = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:14:29 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:56:47 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:02 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -57,6 +58,9 @@ namespace mlx
|
||||
|
||||
if(vkCreateDevice(_physicalDevice, &createInfo, nullptr, &_device) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create logcal device");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new logical device");
|
||||
#endif
|
||||
}
|
||||
|
||||
void Device::pickPhysicalDevice()
|
||||
@@ -78,32 +82,57 @@ namespace mlx
|
||||
if(SDL_Vulkan_CreateSurface(window, Render_Core::get().getInstance().get(), &surface) != SDL_TRUE)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface to pick physical device");
|
||||
|
||||
std::vector<std::pair<int, VkPhysicalDevice>> devices_score;
|
||||
|
||||
for(const auto& device : devices)
|
||||
{
|
||||
if(isDeviceSuitable(device, surface))
|
||||
{
|
||||
_physicalDevice = device;
|
||||
break;
|
||||
}
|
||||
}
|
||||
devices_score.emplace_back(deviceScore(device, surface), device);
|
||||
|
||||
vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), surface, nullptr);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
using device_pair = std::pair<int, VkPhysicalDevice>;
|
||||
std::sort(devices_score.begin(), devices_score.end(), [](const device_pair& a, const device_pair& b)
|
||||
{
|
||||
return a.first > b.first;
|
||||
});
|
||||
|
||||
if(devices_score.front().first > 0)
|
||||
_physicalDevice = devices_score.front().second;
|
||||
|
||||
if(_physicalDevice == VK_NULL_HANDLE)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to find a suitable GPU");
|
||||
#ifdef DEBUG
|
||||
VkPhysicalDeviceProperties props;
|
||||
vkGetPhysicalDeviceProperties(_physicalDevice, &props);
|
||||
core::error::report(e_kind::message, "Vulkan : picked a physical device, %s", props.deviceName);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool Device::isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface)
|
||||
|
||||
int Device::deviceScore(VkPhysicalDevice device, VkSurfaceKHR surface)
|
||||
{
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(device, surface);
|
||||
|
||||
bool extensionsSupported = checkDeviceExtensionSupport(device);
|
||||
|
||||
uint32_t formatCount = 0;
|
||||
if(extensionsSupported)
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
return indices.isComplete() && extensionsSupported && formatCount != 0;
|
||||
|
||||
VkPhysicalDeviceProperties props;
|
||||
vkGetPhysicalDeviceProperties(device, &props);
|
||||
if(!indices.isComplete() || !extensionsSupported || formatCount == 0)
|
||||
return -1;
|
||||
|
||||
int score = 0;
|
||||
#ifndef FORCE_INTEGRATED_GPU
|
||||
if(props.deviceType == VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU)
|
||||
score += 1000;
|
||||
#else
|
||||
if(props.deviceType != VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
|
||||
return -1;
|
||||
#endif
|
||||
score += props.limits.maxImageDimension2D;
|
||||
score += props.limits.maxBoundDescriptorSets;
|
||||
return score;
|
||||
}
|
||||
|
||||
bool Device::checkDeviceExtensionSupport(VkPhysicalDevice device)
|
||||
@@ -125,5 +154,6 @@ namespace mlx
|
||||
void Device::destroy() noexcept
|
||||
{
|
||||
vkDestroyDevice(_device, nullptr);
|
||||
_device = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:13:42 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:55:30 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/11 01:51:26 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -28,12 +28,13 @@ namespace mlx
|
||||
inline VkDevice& get() noexcept { return _device; }
|
||||
|
||||
inline VkPhysicalDevice& getPhysicalDevice() noexcept { return _physicalDevice; }
|
||||
|
||||
|
||||
private:
|
||||
void pickPhysicalDevice();
|
||||
bool isDeviceSuitable(VkPhysicalDevice device, VkSurfaceKHR surface);
|
||||
bool checkDeviceExtensionSupport(VkPhysicalDevice device);
|
||||
int deviceScore(VkPhysicalDevice device, VkSurfaceKHR surface);
|
||||
|
||||
private:
|
||||
VkPhysicalDevice _physicalDevice = VK_NULL_HANDLE;
|
||||
VkDevice _device = VK_NULL_HANDLE;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/02 17:53:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 17:54:14 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:07:21 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace mlx
|
||||
|
||||
if(vkCreateFence(Render_Core::get().getDevice().get(), &fenceInfo, nullptr, &_fence) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create CPU synchronization object");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new fence");
|
||||
#endif
|
||||
}
|
||||
|
||||
void Fence::wait() noexcept
|
||||
@@ -39,6 +42,8 @@ namespace mlx
|
||||
|
||||
void Fence::destroy() noexcept
|
||||
{
|
||||
vkDestroyFence(Render_Core::get().getDevice().get(), _fence, nullptr);
|
||||
if(_fence != VK_NULL_HANDLE)
|
||||
vkDestroyFence(Render_Core::get().getDevice().get(), _fence, nullptr);
|
||||
_fence = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:04:21 by maldavid #+# #+# */
|
||||
/* Updated: 2023/01/25 15:28:18 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:21:42 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,25 +19,25 @@ namespace mlx
|
||||
{
|
||||
void Instance::init()
|
||||
{
|
||||
VkApplicationInfo appInfo{};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "MacroLibX";
|
||||
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.pEngineName = "MacroLibX";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(0, 0, 1);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_2;
|
||||
VkApplicationInfo appInfo{};
|
||||
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||
appInfo.pApplicationName = "MacroLibX";
|
||||
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.pEngineName = "MacroLibX";
|
||||
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
appInfo.apiVersion = VK_API_VERSION_1_2;
|
||||
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
VkInstanceCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||
createInfo.pApplicationInfo = &appInfo;
|
||||
|
||||
auto extensions = getRequiredExtensions();
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
createInfo.ppEnabledExtensionNames = extensions.data();
|
||||
auto extensions = getRequiredExtensions();
|
||||
createInfo.enabledExtensionCount = static_cast<uint32_t>(extensions.size());
|
||||
createInfo.ppEnabledExtensionNames = extensions.data();
|
||||
|
||||
VkDebugUtilsMessengerCreateInfoEXT debugCreateInfo;
|
||||
if constexpr(enableValidationLayers)
|
||||
{
|
||||
{
|
||||
if(Render_Core::get().getLayers().checkValidationLayerSupport())
|
||||
{
|
||||
createInfo.enabledLayerCount = static_cast<uint32_t>(validationLayers.size());
|
||||
@@ -45,45 +45,49 @@ namespace mlx
|
||||
Render_Core::get().getLayers().populateDebugMessengerCreateInfo(debugCreateInfo);
|
||||
createInfo.pNext = (VkDebugUtilsMessengerCreateInfoEXT*) &debugCreateInfo;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
createInfo.enabledLayerCount = 0;
|
||||
createInfo.pNext = nullptr;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
createInfo.enabledLayerCount = 0;
|
||||
createInfo.pNext = nullptr;
|
||||
}
|
||||
|
||||
VkResult res;
|
||||
if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS)
|
||||
if((res = vkCreateInstance(&createInfo, nullptr, &_instance)) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create Vulkan instance");
|
||||
volkLoadInstance(_instance);
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new instance");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<const char*> Instance::getRequiredExtensions()
|
||||
{
|
||||
unsigned int count = 0;
|
||||
{
|
||||
unsigned int count = 0;
|
||||
SDL_Window* window = SDL_CreateWindow("", 0, 0, 1, 1, SDL_WINDOW_VULKAN | SDL_WINDOW_HIDDEN);
|
||||
if(!window)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
|
||||
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr))
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, nullptr))
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
|
||||
|
||||
std::vector<const char*> extensions = { VK_EXT_DEBUG_REPORT_EXTENSION_NAME };
|
||||
size_t additional_extension_count = extensions.size();
|
||||
extensions.resize(additional_extension_count + count);
|
||||
std::vector<const char*> extensions = { VK_EXT_DEBUG_REPORT_EXTENSION_NAME };
|
||||
size_t additional_extension_count = extensions.size();
|
||||
extensions.resize(additional_extension_count + count);
|
||||
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data() + additional_extension_count))
|
||||
if(!SDL_Vulkan_GetInstanceExtensions(window, &count, extensions.data() + additional_extension_count))
|
||||
core::error::report(e_kind::error, "Vulkan : cannot get instance extentions from window : %s", SDL_GetError());
|
||||
|
||||
if constexpr(enableValidationLayers)
|
||||
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
|
||||
|
||||
SDL_DestroyWindow(window);
|
||||
return extensions;
|
||||
}
|
||||
return extensions;
|
||||
}
|
||||
|
||||
void Instance::destroy() noexcept
|
||||
{
|
||||
vkDestroyInstance(_instance, nullptr);
|
||||
}
|
||||
void Instance::destroy() noexcept
|
||||
{
|
||||
vkDestroyInstance(_instance, nullptr);
|
||||
_instance = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 19:01:08 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/02 17:55:58 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:29 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,11 +24,16 @@ namespace mlx
|
||||
if( vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_imageAvailableSemaphores) != VK_SUCCESS ||
|
||||
vkCreateSemaphore(Render_Core::get().getDevice().get(), &semaphoreInfo, nullptr, &_renderFinishedSemaphores) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create GPU synchronization object");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new semaphore");
|
||||
#endif
|
||||
}
|
||||
|
||||
void Semaphore::destroy() noexcept
|
||||
{
|
||||
vkDestroySemaphore(Render_Core::get().getDevice().get(), _renderFinishedSemaphores, nullptr);
|
||||
_renderFinishedSemaphores = VK_NULL_HANDLE;
|
||||
vkDestroySemaphore(Render_Core::get().getDevice().get(), _imageAvailableSemaphores, nullptr);
|
||||
_imageAvailableSemaphores = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:58:49 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:20:57 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:22:38 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace mlx
|
||||
{
|
||||
if(SDL_Vulkan_CreateSurface(renderer.getWindow()->getNativeWindow(), Render_Core::get().getInstance().get(), &_surface) != SDL_TRUE)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a surface : %s", SDL_GetError());
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new surface");
|
||||
#endif
|
||||
}
|
||||
|
||||
VkSurfaceFormatKHR Surface::chooseSwapSurfaceFormat(const std::vector<VkSurfaceFormatKHR>& availableFormats)
|
||||
@@ -38,5 +41,6 @@ namespace mlx
|
||||
void Surface::destroy() noexcept
|
||||
{
|
||||
vkDestroySurfaceKHR(Render_Core::get().getInstance().get(), _surface, nullptr);
|
||||
_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/19 14:05:25 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/19 14:11:12 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:15:36 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -28,6 +28,10 @@ namespace mlx
|
||||
populateDebugMessengerCreateInfo(createInfo);
|
||||
if(createDebugUtilsMessengerEXT(&createInfo, nullptr) != VK_SUCCESS)
|
||||
core::error::report(e_kind::error, "Vulkan : failed to set up debug messenger");
|
||||
#ifdef DEBUG
|
||||
else
|
||||
core::error::report(e_kind::message, "Vulkan : enabled validation layers");
|
||||
#endif
|
||||
}
|
||||
|
||||
bool ValidationLayers::checkValidationLayerSupport()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:34:23 by maldavid #+# #+# */
|
||||
/* Updated: 2023/01/23 18:44:51 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:23:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -30,5 +30,6 @@ namespace mlx
|
||||
void DescriptorPool::destroy() noexcept
|
||||
{
|
||||
vkDestroyDescriptorPool(Render_Core::get().getDevice().get(), _pool, nullptr);
|
||||
_pool = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/22 19:52:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/12 01:14:52 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -37,6 +37,9 @@ namespace mlx
|
||||
|
||||
if(vkAllocateDescriptorSets(device, &allocInfo, _desc_set.data()) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate descriptor set");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new descriptor set");
|
||||
#endif
|
||||
}
|
||||
|
||||
void DescriptorSet::writeDescriptor(int binding, UBO* ubo) noexcept
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:37:28 by maldavid #+# #+# */
|
||||
/* Updated: 2023/03/31 16:37:09 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:23:16 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -41,5 +41,6 @@ namespace mlx
|
||||
void DescriptorSetLayout::destroy() noexcept
|
||||
{
|
||||
vkDestroyDescriptorSetLayout(Render_Core::get().getDevice().get(), _layout, nullptr);
|
||||
_layout = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/09 13:51:35 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 14:01:47 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -29,13 +29,9 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format)
|
||||
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
{
|
||||
Image::create(width, height, format, TILING,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
{ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT }
|
||||
);
|
||||
|
||||
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
Image::createSampler();
|
||||
|
||||
@@ -48,14 +44,24 @@ namespace mlx
|
||||
|
||||
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
|
||||
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data());
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
|
||||
#ifdef DEBUG
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), name);
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), name);
|
||||
_name = name;
|
||||
#else
|
||||
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data(), nullptr);
|
||||
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data(), nullptr);
|
||||
#endif
|
||||
|
||||
if(pixels != nullptr)
|
||||
{
|
||||
Buffer staging_buffer;
|
||||
std::size_t size = width * height * formatSize(format);
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
|
||||
#ifdef DEBUG
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, name, pixels);
|
||||
#else
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, nullptr, pixels);
|
||||
#endif
|
||||
Image::copyFromBuffer(staging_buffer);
|
||||
staging_buffer.destroy();
|
||||
}
|
||||
@@ -89,10 +95,13 @@ namespace mlx
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Texture : enabling CPU mapping");
|
||||
#endif
|
||||
|
||||
std::size_t size = getWidth() * getHeight() * formatSize(getFormat());
|
||||
_buf_map.emplace();
|
||||
_buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT);
|
||||
#ifdef DEBUG
|
||||
_buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, _name.c_str());
|
||||
#else
|
||||
_buf_map->create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, nullptr);
|
||||
#endif
|
||||
Image::copyToBuffer(*_buf_map);
|
||||
_buf_map->mapMem(&_map);
|
||||
_cpu_map = std::vector<uint32_t>(getWidth() * getHeight(), 0);
|
||||
@@ -139,7 +148,11 @@ namespace mlx
|
||||
if(stbi_is_hdr(filename.c_str()))
|
||||
core::error::report(e_kind::fatal_error, "Texture : unsupported image format '%s'", filename.c_str());
|
||||
data = stbi_load(filename.c_str(), w, h, &channels, 4);
|
||||
texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
#ifdef DEBUG
|
||||
texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM, filename.c_str());
|
||||
#else
|
||||
texture.create(data, *w, *h, VK_FORMAT_R8G8B8A8_UNORM, nullptr);
|
||||
#endif
|
||||
stbi_image_free(data);
|
||||
return texture;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/02 12:32:27 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 14:01:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace mlx
|
||||
public:
|
||||
Texture() = default;
|
||||
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void render(class Renderer& renderer, int x, int y);
|
||||
void destroy() noexcept override;
|
||||
|
||||
@@ -50,6 +50,9 @@ namespace mlx
|
||||
private:
|
||||
C_VBO _vbo;
|
||||
C_IBO _ibo;
|
||||
#ifdef DEBUG
|
||||
std::string _name;
|
||||
#endif
|
||||
DescriptorSet _set;
|
||||
std::vector<uint32_t> _cpu_map;
|
||||
std::optional<Buffer> _buf_map = std::nullopt;
|
||||
|
||||
@@ -6,22 +6,23 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/07 16:40:09 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 12:55:22 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 05:36:46 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <renderer/images/texture_atlas.h>
|
||||
|
||||
#ifdef IMAGE_OPTIMIZED
|
||||
#define TILING VK_IMAGE_TILING_OPTIMAL
|
||||
#else
|
||||
#define TILING VK_IMAGE_TILING_LINEAR
|
||||
#endif
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void TextureAtlas::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format)
|
||||
void TextureAtlas::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory)
|
||||
{
|
||||
Image::create(width, height, format,
|
||||
VK_IMAGE_TILING_OPTIMAL,
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
{ VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT }
|
||||
);
|
||||
|
||||
Image::create(width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, name, dedicated_memory);
|
||||
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
Image::createSampler();
|
||||
|
||||
@@ -29,7 +30,7 @@ namespace mlx
|
||||
{
|
||||
Buffer staging_buffer;
|
||||
std::size_t size = width * height * formatSize(format);
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
|
||||
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, name, pixels);
|
||||
Image::copyFromBuffer(staging_buffer);
|
||||
staging_buffer.destroy();
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 12:04:16 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 05:36:30 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace mlx
|
||||
public:
|
||||
TextureAtlas() = default;
|
||||
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
|
||||
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format, const char* name, bool dedicated_memory = false);
|
||||
void render(class Renderer& renderer, int x, int y, uint32_t ibo_size);
|
||||
void destroy() noexcept override;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 14:59:41 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:21:14 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,7 +18,125 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Image::create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, std::vector<VkMemoryPropertyFlags> properties)
|
||||
bool isStencilFormat(VkFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case VK_FORMAT_D32_SFLOAT_S8_UINT:
|
||||
case VK_FORMAT_D24_UNORM_S8_UINT:
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDepthFormat(VkFormat format)
|
||||
{
|
||||
switch(format)
|
||||
{
|
||||
case VK_FORMAT_D16_UNORM:
|
||||
case VK_FORMAT_D32_SFLOAT:
|
||||
case VK_FORMAT_D32_SFLOAT_S8_UINT:
|
||||
case VK_FORMAT_D24_UNORM_S8_UINT:
|
||||
case VK_FORMAT_D16_UNORM_S8_UINT:
|
||||
return true;
|
||||
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
||||
VkFormat bitsToFormat(uint32_t bits)
|
||||
{
|
||||
switch(bits)
|
||||
{
|
||||
case 8: return VK_FORMAT_R8_UNORM;
|
||||
case 16: return VK_FORMAT_R8G8_UNORM;
|
||||
case 24: return VK_FORMAT_R8G8B8_UNORM;
|
||||
case 32: return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
case 48: return VK_FORMAT_R16G16B16_SFLOAT;
|
||||
case 64: return VK_FORMAT_R16G16B16A16_SFLOAT;
|
||||
case 96: return VK_FORMAT_R32G32B32_SFLOAT;
|
||||
case 128: return VK_FORMAT_R32G32B32A32_SFLOAT;
|
||||
|
||||
default:
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : unsupported image bit-depth");
|
||||
return VK_FORMAT_R8G8B8A8_UNORM;
|
||||
}
|
||||
}
|
||||
|
||||
VkPipelineStageFlags layoutToAccessMask(VkImageLayout layout, bool isDestination)
|
||||
{
|
||||
VkPipelineStageFlags accessMask = 0;
|
||||
|
||||
switch(layout)
|
||||
{
|
||||
case VK_IMAGE_LAYOUT_UNDEFINED:
|
||||
if(isDestination)
|
||||
core::error::report(e_kind::error, "Vulkan : the new layout used in a transition must not be VK_IMAGE_LAYOUT_UNDEFINED");
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_GENERAL: accessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: accessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: accessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL:
|
||||
accessMask = VK_ACCESS_SHADER_READ_BIT; // VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: accessMask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_INPUT_ATTACHMENT_READ_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL: accessMask = VK_ACCESS_TRANSFER_READ_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: accessMask = VK_ACCESS_TRANSFER_WRITE_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_PREINITIALIZED:
|
||||
if(!isDestination)
|
||||
accessMask = VK_ACCESS_HOST_WRITE_BIT;
|
||||
else
|
||||
core::error::report(e_kind::error, "Vulkan : the new layout used in a transition must not be VK_IMAGE_LAYOUT_PREINITIALIZED");
|
||||
break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: accessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: accessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
|
||||
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: accessMask = VK_ACCESS_MEMORY_READ_BIT; break;
|
||||
|
||||
default: core::error::report(e_kind::error, "Vulkan : unexpected image layout"); break;
|
||||
}
|
||||
|
||||
return accessMask;
|
||||
}
|
||||
|
||||
VkPipelineStageFlags accessFlagsToPipelineStage(VkAccessFlags accessFlags, VkPipelineStageFlags stageFlags)
|
||||
{
|
||||
VkPipelineStageFlags stages = 0;
|
||||
|
||||
while(accessFlags != 0)
|
||||
{
|
||||
VkAccessFlagBits AccessFlag = static_cast<VkAccessFlagBits>(accessFlags & (~(accessFlags - 1)));
|
||||
if(AccessFlag == 0 || (AccessFlag & (AccessFlag - 1)) != 0)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : an error has been caught during access flag to pipeline stage operation");
|
||||
accessFlags &= ~AccessFlag;
|
||||
|
||||
switch(AccessFlag)
|
||||
{
|
||||
case VK_ACCESS_INDIRECT_COMMAND_READ_BIT: stages |= VK_PIPELINE_STAGE_DRAW_INDIRECT_BIT; break;
|
||||
case VK_ACCESS_INDEX_READ_BIT: stages |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; break;
|
||||
case VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT: stages |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT; break;
|
||||
case VK_ACCESS_UNIFORM_READ_BIT: stages |= stageFlags | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; break;
|
||||
case VK_ACCESS_INPUT_ATTACHMENT_READ_BIT: stages |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT; break;
|
||||
case VK_ACCESS_SHADER_READ_BIT: stages |= stageFlags | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; break;
|
||||
case VK_ACCESS_SHADER_WRITE_BIT: stages |= stageFlags | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT; break;
|
||||
case VK_ACCESS_COLOR_ATTACHMENT_READ_BIT: stages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; break;
|
||||
case VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT: stages |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; break;
|
||||
case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT: stages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; break;
|
||||
case VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT: stages |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT; break;
|
||||
case VK_ACCESS_TRANSFER_READ_BIT: stages |= VK_PIPELINE_STAGE_TRANSFER_BIT; break;
|
||||
case VK_ACCESS_TRANSFER_WRITE_BIT: stages |= VK_PIPELINE_STAGE_TRANSFER_BIT; break;
|
||||
case VK_ACCESS_HOST_READ_BIT: stages |= VK_PIPELINE_STAGE_HOST_BIT; break;
|
||||
case VK_ACCESS_HOST_WRITE_BIT: stages |= VK_PIPELINE_STAGE_HOST_BIT; break;
|
||||
case VK_ACCESS_MEMORY_READ_BIT: break;
|
||||
case VK_ACCESS_MEMORY_WRITE_BIT: break;
|
||||
|
||||
default: core::error::report(e_kind::error, "Vulkan : unknown access flag"); break;
|
||||
}
|
||||
}
|
||||
return stages;
|
||||
}
|
||||
|
||||
void Image::create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool dedicated_memory)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
@@ -40,30 +158,15 @@ namespace mlx
|
||||
imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
|
||||
if(vkCreateImage(Render_Core::get().getDevice().get(), &imageInfo, nullptr, &_image) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image");
|
||||
|
||||
VkMemoryRequirements memRequirements;
|
||||
vkGetImageMemoryRequirements(Render_Core::get().getDevice().get(), _image, &memRequirements);
|
||||
|
||||
std::optional<uint32_t> memTypeIndex;
|
||||
for(auto prop : properties)
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||
if(dedicated_memory)
|
||||
{
|
||||
memTypeIndex = RCore::findMemoryType(memRequirements.memoryTypeBits, prop, false);
|
||||
if(memTypeIndex.has_value())
|
||||
break;
|
||||
alloc_info.flags = VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT;
|
||||
alloc_info.priority = 1.0f;
|
||||
}
|
||||
if(!memTypeIndex.has_value())
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to find suitable memory type for an image");
|
||||
VkMemoryAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
|
||||
allocInfo.allocationSize = memRequirements.size;
|
||||
allocInfo.memoryTypeIndex = *memTypeIndex;
|
||||
|
||||
if(vkAllocateMemory(Render_Core::get().getDevice().get(), &allocInfo, nullptr, &_memory) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate memory for an image");
|
||||
|
||||
vkBindImageMemory(Render_Core::get().getDevice().get(), _image, _memory, 0);
|
||||
_allocation = Render_Core::get().getAllocator().createImage(&imageInfo, &alloc_info, _image, name);
|
||||
|
||||
_pool.init();
|
||||
}
|
||||
@@ -87,7 +190,7 @@ namespace mlx
|
||||
|
||||
void Image::createSampler() noexcept
|
||||
{
|
||||
VkSamplerCreateInfo info = {};
|
||||
VkSamplerCreateInfo info{};
|
||||
info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
info.magFilter = VK_FILTER_NEAREST;
|
||||
info.minFilter = VK_FILTER_NEAREST;
|
||||
@@ -112,7 +215,7 @@ namespace mlx
|
||||
_transfer_cmd.reset();
|
||||
_transfer_cmd.beginRecord();
|
||||
|
||||
VkImageMemoryBarrier copy_barrier = {};
|
||||
VkImageMemoryBarrier copy_barrier{};
|
||||
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
copy_barrier.dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
copy_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
@@ -125,7 +228,7 @@ namespace mlx
|
||||
copy_barrier.subresourceRange.layerCount = 1;
|
||||
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
||||
|
||||
VkBufferImageCopy region = {};
|
||||
VkBufferImageCopy region{};
|
||||
region.bufferOffset = 0;
|
||||
region.bufferRowLength = 0;
|
||||
region.bufferImageHeight = 0;
|
||||
@@ -138,7 +241,7 @@ namespace mlx
|
||||
|
||||
vkCmdCopyBufferToImage(_transfer_cmd.get(), buffer.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||
|
||||
VkImageMemoryBarrier use_barrier = {};
|
||||
VkImageMemoryBarrier use_barrier{};
|
||||
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
use_barrier.srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
use_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
@@ -164,7 +267,7 @@ namespace mlx
|
||||
_transfer_cmd.reset();
|
||||
_transfer_cmd.beginRecord();
|
||||
|
||||
VkImageMemoryBarrier copy_barrier = {};
|
||||
VkImageMemoryBarrier copy_barrier{};
|
||||
copy_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
copy_barrier.dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
copy_barrier.oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
@@ -177,7 +280,7 @@ namespace mlx
|
||||
copy_barrier.subresourceRange.layerCount = 1;
|
||||
vkCmdPipelineBarrier(_transfer_cmd.get(), VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, nullptr, 0, nullptr, 1, ©_barrier);
|
||||
|
||||
VkBufferImageCopy region = {};
|
||||
VkBufferImageCopy region{};
|
||||
region.bufferOffset = 0;
|
||||
region.bufferRowLength = 0;
|
||||
region.bufferImageHeight = 0;
|
||||
@@ -190,7 +293,7 @@ namespace mlx
|
||||
|
||||
vkCmdCopyImageToBuffer(_transfer_cmd.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.get(), 1, ®ion);
|
||||
|
||||
VkImageMemoryBarrier use_barrier = {};
|
||||
VkImageMemoryBarrier use_barrier{};
|
||||
use_barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
use_barrier.srcAccessMask = VK_ACCESS_TRANSFER_READ_BIT;
|
||||
use_barrier.dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
|
||||
@@ -208,18 +311,79 @@ namespace mlx
|
||||
_transfer_cmd.submitIdle();
|
||||
}
|
||||
|
||||
void Image::destroy() noexcept
|
||||
void Image::transitionLayout(VkImageLayout new_layout)
|
||||
{
|
||||
if(new_layout == _layout)
|
||||
return;
|
||||
|
||||
if(!_transfer_cmd.isInit())
|
||||
_transfer_cmd.init(&_pool);
|
||||
_transfer_cmd.reset();
|
||||
_transfer_cmd.beginRecord();
|
||||
|
||||
VkImageMemoryBarrier barrier{};
|
||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||
barrier.oldLayout = _layout;
|
||||
barrier.newLayout = new_layout;
|
||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
barrier.image = _image;
|
||||
barrier.subresourceRange.aspectMask = isDepthFormat(_format) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
barrier.subresourceRange.baseMipLevel = 0;
|
||||
barrier.subresourceRange.levelCount = 1;
|
||||
barrier.subresourceRange.baseArrayLayer = 0;
|
||||
barrier.subresourceRange.layerCount = 1;
|
||||
barrier.srcAccessMask = layoutToAccessMask(_layout, false);
|
||||
barrier.dstAccessMask = layoutToAccessMask(new_layout, true);
|
||||
if(isStencilFormat(_format))
|
||||
barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||
|
||||
VkPipelineStageFlags sourceStage = 0;
|
||||
if(barrier.oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
||||
sourceStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
else if(barrier.srcAccessMask != 0)
|
||||
sourceStage = accessFlagsToPipelineStage(barrier.srcAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
else
|
||||
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
|
||||
VkPipelineStageFlags destinationStage = 0;
|
||||
if(barrier.newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
||||
destinationStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
else if(barrier.dstAccessMask != 0)
|
||||
destinationStage = accessFlagsToPipelineStage(barrier.dstAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
else
|
||||
destinationStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
|
||||
vkCmdPipelineBarrier(_transfer_cmd.get(), sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||
|
||||
_transfer_cmd.endRecord();
|
||||
_transfer_cmd.submitIdle();
|
||||
_layout = new_layout;
|
||||
}
|
||||
|
||||
void Image::destroySampler() noexcept
|
||||
{
|
||||
if(_sampler != VK_NULL_HANDLE)
|
||||
vkDestroySampler(Render_Core::get().getDevice().get(), _sampler, nullptr);
|
||||
_sampler = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
void Image::destroyImageView() noexcept
|
||||
{
|
||||
if(_image_view != VK_NULL_HANDLE)
|
||||
vkDestroyImageView(Render_Core::get().getDevice().get(), _image_view, nullptr);
|
||||
_image_view = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
vkFreeMemory(Render_Core::get().getDevice().get(), _memory, nullptr);
|
||||
vkDestroyImage(Render_Core::get().getDevice().get(), _image, nullptr);
|
||||
if(_transfer_cmd.isInit())
|
||||
_transfer_cmd.destroy();
|
||||
_pool.destroy();
|
||||
void Image::destroy() noexcept
|
||||
{
|
||||
destroySampler();
|
||||
destroyImageView();
|
||||
destroyCmdPool();
|
||||
|
||||
if(_image != VK_NULL_HANDLE)
|
||||
Render_Core::get().getAllocator().destroyImage(_allocation, _image);
|
||||
_image = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
uint32_t formatSize(VkFormat format)
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/23 14:17:11 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:10:05 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __VK_IMAGE__
|
||||
#define __VK_IMAGE__
|
||||
#ifndef __MLX_VK_IMAGE__
|
||||
#define __MLX_VK_IMAGE__
|
||||
|
||||
#include <volk.h>
|
||||
#include <cstddef>
|
||||
@@ -25,19 +25,30 @@ namespace mlx
|
||||
|
||||
class Image
|
||||
{
|
||||
friend class SwapChain;
|
||||
|
||||
public:
|
||||
Image() = default;
|
||||
|
||||
void create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, std::vector<VkMemoryPropertyFlags> properties);
|
||||
inline void create(VkImage image, VkFormat format, uint32_t width, uint32_t height, VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED) noexcept
|
||||
{
|
||||
_image = image;
|
||||
_format = format;
|
||||
_width = width;
|
||||
_height = height;
|
||||
_layout = layout;
|
||||
_pool.init();
|
||||
}
|
||||
void create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, const char* name, bool decated_memory = false);
|
||||
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
|
||||
void createSampler() noexcept;
|
||||
void copyFromBuffer(class Buffer& buffer);
|
||||
void copyToBuffer(class Buffer& buffer);
|
||||
void transitionLayout(VkImageLayout new_layout);
|
||||
virtual void destroy() noexcept;
|
||||
|
||||
inline VkImage get() noexcept { return _image; }
|
||||
inline VkImage operator()() noexcept { return _image; }
|
||||
inline VkDeviceMemory getDeviceMemory() noexcept { return _memory; }
|
||||
inline VkImageView getImageView() noexcept { return _image_view; }
|
||||
inline VkFormat getFormat() noexcept { return _format; }
|
||||
inline VkImageTiling getTiling() noexcept { return _tiling; }
|
||||
@@ -47,15 +58,21 @@ namespace mlx
|
||||
|
||||
virtual ~Image() = default;
|
||||
|
||||
private:
|
||||
void destroySampler() noexcept;
|
||||
void destroyImageView() noexcept;
|
||||
inline void destroyCmdPool() noexcept { _transfer_cmd.destroy(); _pool.destroy(); }
|
||||
|
||||
private:
|
||||
CmdBuffer _transfer_cmd;
|
||||
CmdPool _pool;
|
||||
VmaAllocation _allocation;
|
||||
VkImage _image = VK_NULL_HANDLE;
|
||||
VkDeviceMemory _memory = VK_NULL_HANDLE;
|
||||
VkImageView _image_view = VK_NULL_HANDLE;
|
||||
VkSampler _sampler = VK_NULL_HANDLE;
|
||||
VkFormat _format;
|
||||
VkImageTiling _tiling;
|
||||
VkImageLayout _layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
||||
uint32_t _width = 0;
|
||||
uint32_t _height = 0;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/13 14:52:57 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 16:57:57 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -222,14 +222,14 @@ namespace mlx
|
||||
VkViewport viewport{};
|
||||
viewport.x = 0.0f;
|
||||
viewport.y = 0.0f;
|
||||
viewport.width = (float)renderer.getSwapChain()._swapChainExtent.width;
|
||||
viewport.height = (float)renderer.getSwapChain()._swapChainExtent.height;
|
||||
viewport.width = (float)renderer.getSwapChain().getExtent().width;
|
||||
viewport.height = (float)renderer.getSwapChain().getExtent().height;
|
||||
viewport.minDepth = 0.0f;
|
||||
viewport.maxDepth = 1.0f;
|
||||
|
||||
VkRect2D scissor{};
|
||||
scissor.offset = { 0, 0 };
|
||||
scissor.extent = renderer.getSwapChain()._swapChainExtent;
|
||||
scissor.extent = renderer.getSwapChain().getExtent();
|
||||
|
||||
VkPipelineViewportStateCreateInfo viewportState{};
|
||||
viewportState.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
|
||||
@@ -301,6 +301,9 @@ namespace mlx
|
||||
|
||||
if(vkCreateGraphicsPipelines(Render_Core::get().getDevice().get(), VK_NULL_HANDLE, 1, &pipelineInfo, nullptr, &_graphicsPipeline) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new graphic pipeline");
|
||||
#endif
|
||||
|
||||
vkDestroyShaderModule(Render_Core::get().getDevice().get(), fshader, nullptr);
|
||||
vkDestroyShaderModule(Render_Core::get().getDevice().get(), vshader, nullptr);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/02 05:28:49 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:44:58 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,10 +17,10 @@ namespace mlx
|
||||
{
|
||||
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
|
||||
{
|
||||
_texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
_texture.create(nullptr, width, height, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_pixel_put_pipeline_texture", true);
|
||||
_texture.setDescriptor(renderer.getFragDescriptorSet().duplicate());
|
||||
|
||||
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
|
||||
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT, "__mlx_pixel_put_pipeline_texture");
|
||||
_buffer.mapMem(&_buffer_map);
|
||||
_cpu_map = std::vector<uint32_t>(height * width, 0);
|
||||
_width = width;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/21 20:56:51 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:08:19 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,14 +20,20 @@ namespace mlx
|
||||
{
|
||||
_surface.create(*this);
|
||||
_swapchain.init(this);
|
||||
_pass.init(this);
|
||||
_swapchain.initFB();
|
||||
_pass.init(_swapchain.getImagesFormat());
|
||||
_cmd.init();
|
||||
|
||||
for(int i = 0; i < _swapchain.getImagesNumber(); i++)
|
||||
_framebuffers.emplace_back().init(_pass, _swapchain.getImage(i));
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_semaphores[i].init();
|
||||
|
||||
_uniform_buffer.reset(new UBO);
|
||||
_uniform_buffer->create(this, sizeof(glm::mat4));
|
||||
#ifdef DEBUG
|
||||
_uniform_buffer->create(this, sizeof(glm::mat4), "__mlx_matrices_uniform_buffer_");
|
||||
#else
|
||||
_uniform_buffer->create(this, sizeof(glm::mat4), nullptr);
|
||||
#endif
|
||||
|
||||
VkDescriptorPoolSize pool_sizes[] = {
|
||||
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4096 },
|
||||
@@ -51,15 +57,15 @@ namespace mlx
|
||||
|
||||
_framebufferResized = false;
|
||||
}
|
||||
|
||||
|
||||
bool Renderer::beginFrame()
|
||||
{
|
||||
auto device = Render_Core::get().getDevice().get();
|
||||
|
||||
_cmd.getCmdBuffer(_active_image_index).waitForExecution();
|
||||
_cmd.getCmdBuffer(_active_image_index).reset();
|
||||
_cmd.getCmdBuffer(_current_frame_index).waitForExecution();
|
||||
_cmd.getCmdBuffer(_current_frame_index).reset();
|
||||
|
||||
VkResult result = vkAcquireNextImageKHR(device, _swapchain(), UINT64_MAX, _semaphores[_active_image_index].getImageSemaphore(), VK_NULL_HANDLE, &_image_index);
|
||||
VkResult result = vkAcquireNextImageKHR(device, _swapchain(), UINT64_MAX, _semaphores[_current_frame_index].getImageSemaphore(), VK_NULL_HANDLE, &_image_index);
|
||||
|
||||
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
{
|
||||
@@ -69,36 +75,37 @@ namespace mlx
|
||||
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to acquire swapchain image");
|
||||
|
||||
_cmd.getCmdBuffer(_active_image_index).beginRecord();
|
||||
_pass.begin();
|
||||
_cmd.getCmdBuffer(_current_frame_index).beginRecord();
|
||||
auto& fb = _framebuffers[_image_index];
|
||||
_pass.begin(getActiveCmdBuffer(), fb);
|
||||
|
||||
_pipeline.bindPipeline(_cmd.getCmdBuffer(_active_image_index));
|
||||
_pipeline.bindPipeline(_cmd.getCmdBuffer(_current_frame_index));
|
||||
|
||||
VkViewport viewport{};
|
||||
viewport.x = 0.0f;
|
||||
viewport.y = 0.0f;
|
||||
viewport.width = (float)_swapchain._swapChainExtent.width;
|
||||
viewport.height = (float)_swapchain._swapChainExtent.height;
|
||||
viewport.width = static_cast<float>(fb.getWidth());
|
||||
viewport.height = static_cast<float>(fb.getHeight());
|
||||
viewport.minDepth = 0.0f;
|
||||
viewport.maxDepth = 1.0f;
|
||||
vkCmdSetViewport(_cmd.getCmdBuffer(_active_image_index).get(), 0, 1, &viewport);
|
||||
vkCmdSetViewport(_cmd.getCmdBuffer(_current_frame_index).get(), 0, 1, &viewport);
|
||||
|
||||
VkRect2D scissor{};
|
||||
scissor.offset = { 0, 0 };
|
||||
scissor.extent = _swapchain._swapChainExtent;
|
||||
vkCmdSetScissor(_cmd.getCmdBuffer(_active_image_index).get(), 0, 1, &scissor);
|
||||
scissor.extent = _swapchain.getExtent();
|
||||
vkCmdSetScissor(_cmd.getCmdBuffer(_current_frame_index).get(), 0, 1, &scissor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Renderer::endFrame()
|
||||
{
|
||||
_pass.end();
|
||||
_cmd.getCmdBuffer(_active_image_index).endRecord();
|
||||
_cmd.getCmdBuffer(_active_image_index).submit(_semaphores[_active_image_index]);
|
||||
_pass.end(getActiveCmdBuffer());
|
||||
_cmd.getCmdBuffer(_current_frame_index).endRecord();
|
||||
_cmd.getCmdBuffer(_current_frame_index).submit(_semaphores[_current_frame_index]);
|
||||
|
||||
VkSwapchainKHR swapchain = _swapchain();
|
||||
VkSemaphore signalSemaphores[] = { _semaphores[_active_image_index].getRenderImageSemaphore() };
|
||||
VkSemaphore signalSemaphores[] = { _semaphores[_current_frame_index].getRenderImageSemaphore() };
|
||||
|
||||
VkPresentInfoKHR presentInfo{};
|
||||
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
@@ -118,7 +125,7 @@ namespace mlx
|
||||
else if(result != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to present swap chain image");
|
||||
|
||||
_active_image_index = (_active_image_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
_current_frame_index = (_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
}
|
||||
|
||||
void Renderer::destroy()
|
||||
@@ -131,9 +138,10 @@ namespace mlx
|
||||
_frag_layout.destroy();
|
||||
_cmd.destroy();
|
||||
_desc_pool.destroy();
|
||||
_swapchain.destroyFB();
|
||||
_pass.destroy();
|
||||
_swapchain.destroy();
|
||||
for(auto& fb : _framebuffers)
|
||||
fb.destroy();
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_semaphores[i].destroy();
|
||||
_surface.destroy();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 12:33:33 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 16:56:09 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -24,7 +24,8 @@
|
||||
#include <renderer/pipeline/pipeline.h>
|
||||
#include <renderer/command/cmd_manager.h>
|
||||
#include <renderer/swapchain/vk_swapchain.h>
|
||||
#include <renderer/swapchain/vk_render_pass.h>
|
||||
#include <renderer/renderpass/vk_render_pass.h>
|
||||
#include <renderer/renderpass/vk_framebuffer.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set.h>
|
||||
#include <renderer/descriptors/vk_descriptor_pool.h>
|
||||
#include <renderer/descriptors/vk_descriptor_set_layout.h>
|
||||
@@ -99,12 +100,12 @@ namespace mlx
|
||||
inline RenderPass& getRenderPass() noexcept { return _pass; }
|
||||
inline GraphicPipeline& getPipeline() noexcept { return _pipeline; }
|
||||
inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd.getCmdBuffer(i); }
|
||||
inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd.getCmdBuffer(_active_image_index); }
|
||||
inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd.getCmdBuffer(_current_frame_index); }
|
||||
inline DescriptorSet& getVertDescriptorSet() noexcept { return _vert_set; }
|
||||
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
|
||||
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
|
||||
inline DescriptorSetLayout& getFragDescriptorSetLayout() noexcept { return _frag_layout; }
|
||||
inline uint32_t getActiveImageIndex() noexcept { return _active_image_index; }
|
||||
inline uint32_t getActiveImageIndex() noexcept { return _current_frame_index; }
|
||||
inline uint32_t getImageIndex() noexcept { return _image_index; }
|
||||
|
||||
constexpr inline void requireFrameBufferResize(int index) noexcept { _framebufferResized = true; }
|
||||
@@ -118,6 +119,7 @@ namespace mlx
|
||||
Surface _surface;
|
||||
SwapChain _swapchain;
|
||||
std::array<Semaphore, MAX_FRAMES_IN_FLIGHT> _semaphores;
|
||||
std::vector<FrameBuffer> _framebuffers;
|
||||
|
||||
DescriptorPool _desc_pool;
|
||||
|
||||
@@ -131,7 +133,7 @@ namespace mlx
|
||||
|
||||
class MLX_Window* _window = nullptr;
|
||||
|
||||
uint32_t _active_image_index = 0;
|
||||
uint32_t _current_frame_index = 0;
|
||||
uint32_t _image_index = 0;
|
||||
bool _framebufferResized = false;
|
||||
};
|
||||
|
||||
@@ -6,35 +6,43 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:18:06 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 20:01:51 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:20:23 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <volk.h>
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/images/vk_image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void FrameBuffer::init(Renderer& renderer, ImageView& image)
|
||||
void FrameBuffer::init(RenderPass& renderpass, Image& image)
|
||||
{
|
||||
VkImageView attachments[] = { image() };
|
||||
VkImageView attachments[] = { image.getImageView() };
|
||||
|
||||
_width = image.getWidth();
|
||||
_height = image.getHeight();
|
||||
|
||||
VkFramebufferCreateInfo framebufferInfo{};
|
||||
framebufferInfo.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||
framebufferInfo.renderPass = renderer.getRenderPass().get();
|
||||
framebufferInfo.renderPass = renderpass.get();
|
||||
framebufferInfo.attachmentCount = 1;
|
||||
framebufferInfo.pAttachments = attachments;
|
||||
framebufferInfo.width = renderer.getSwapChain()._swapChainExtent.width;
|
||||
framebufferInfo.height = renderer.getSwapChain()._swapChainExtent.height;
|
||||
framebufferInfo.width = _width;
|
||||
framebufferInfo.height = _height;
|
||||
framebufferInfo.layers = 1;
|
||||
|
||||
if(vkCreateFramebuffer(Render_Core::get().getDevice().get(), &framebufferInfo, nullptr, &_framebuffer) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a framebuffer");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new framebuffer");
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrameBuffer::destroy() noexcept
|
||||
{
|
||||
vkDestroyFramebuffer(Render_Core::get().getDevice().get(), _framebuffer, nullptr);
|
||||
_framebuffer = VK_NULL_HANDLE;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:19:44 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 19:53:00 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 16:44:16 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -17,18 +17,22 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class FrameBuffer
|
||||
{
|
||||
public:
|
||||
void init(class Renderer& renderer, class ImageView& image);
|
||||
void destroy() noexcept;
|
||||
class FrameBuffer
|
||||
{
|
||||
public:
|
||||
void init(class RenderPass& renderpass, class Image& image);
|
||||
void destroy() noexcept;
|
||||
|
||||
inline VkFramebuffer& operator()() noexcept { return _framebuffer; }
|
||||
inline VkFramebuffer& get() noexcept { return _framebuffer; }
|
||||
inline VkFramebuffer& operator()() noexcept { return _framebuffer; }
|
||||
inline VkFramebuffer& get() noexcept { return _framebuffer; }
|
||||
inline uint32_t getWidth() const noexcept { return _width; }
|
||||
inline uint32_t getHeight() const noexcept { return _height; }
|
||||
|
||||
private:
|
||||
VkFramebuffer _framebuffer = VK_NULL_HANDLE;
|
||||
};
|
||||
private:
|
||||
VkFramebuffer _framebuffer = VK_NULL_HANDLE;
|
||||
uint32_t _width = 0;
|
||||
uint32_t _height = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __MLX_VK_FRAMEBUFFER__
|
||||
@@ -6,24 +6,23 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/19 00:06:34 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 15:58:26 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "vk_render_pass.h"
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/renderpass/vk_framebuffer.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
static const VkClearValue clearColor = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
|
||||
void RenderPass::init(Renderer* renderer)
|
||||
void RenderPass::init(VkFormat attachement_format)
|
||||
{
|
||||
_renderer = renderer;
|
||||
|
||||
VkAttachmentDescription colorAttachment{};
|
||||
colorAttachment.format = renderer->getSwapChain()._swapChainImageFormat;
|
||||
colorAttachment.format = attachement_format;
|
||||
colorAttachment.samples = VK_SAMPLE_COUNT_1_BIT;
|
||||
colorAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
|
||||
colorAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
|
||||
@@ -50,9 +49,12 @@ namespace mlx
|
||||
|
||||
if(vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_renderPass) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create render pass");
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new render pass");
|
||||
#endif
|
||||
}
|
||||
|
||||
void RenderPass::begin()
|
||||
void RenderPass::begin(class CmdBuffer& cmd, class FrameBuffer& fb)
|
||||
{
|
||||
if(_is_running)
|
||||
return;
|
||||
@@ -60,23 +62,23 @@ namespace mlx
|
||||
VkRenderPassBeginInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
renderPassInfo.renderPass = _renderPass;
|
||||
renderPassInfo.framebuffer = _renderer->getSwapChain()._framebuffers[_renderer->getImageIndex()].get();
|
||||
renderPassInfo.framebuffer = fb.get();
|
||||
renderPassInfo.renderArea.offset = { 0, 0 };
|
||||
renderPassInfo.renderArea.extent = _renderer->getSwapChain()._swapChainExtent;
|
||||
renderPassInfo.renderArea.extent = { fb.getWidth(), fb.getHeight() };
|
||||
renderPassInfo.clearValueCount = 1;
|
||||
renderPassInfo.pClearValues = &clearColor;
|
||||
|
||||
vkCmdBeginRenderPass(_renderer->getActiveCmdBuffer().get(), &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
vkCmdBeginRenderPass(cmd.get(), &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
_is_running = true;
|
||||
}
|
||||
|
||||
void RenderPass::end()
|
||||
void RenderPass::end(class CmdBuffer& cmd)
|
||||
{
|
||||
if(!_is_running)
|
||||
return;
|
||||
|
||||
vkCmdEndRenderPass(_renderer->getActiveCmdBuffer().get());
|
||||
vkCmdEndRenderPass(cmd.get());
|
||||
_is_running = false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 20:33:28 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 15:58:12 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,18 +20,17 @@ namespace mlx
|
||||
class RenderPass
|
||||
{
|
||||
public:
|
||||
void init(class Renderer* renderer);
|
||||
void init(VkFormat attachement_format);
|
||||
void destroy() noexcept;
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
void begin(class CmdBuffer& cmd, class FrameBuffer& fb);
|
||||
void end(class CmdBuffer& cmd);
|
||||
|
||||
inline VkRenderPass& operator()() noexcept { return _renderPass; }
|
||||
inline VkRenderPass& get() noexcept { return _renderPass; }
|
||||
|
||||
private:
|
||||
VkRenderPass _renderPass = VK_NULL_HANDLE;
|
||||
class Renderer* _renderer = nullptr;
|
||||
bool _is_running = false;
|
||||
};
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_imageview.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:20:49 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 19:55:03 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "vk_swapchain.h"
|
||||
#include "vk_imageview.h"
|
||||
#include <renderer/core/render_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void ImageView::init(SwapChain& swapchain, VkImage& image)
|
||||
{
|
||||
VkImageViewCreateInfo createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||
createInfo.image = image;
|
||||
createInfo.viewType = VK_IMAGE_VIEW_TYPE_2D;
|
||||
createInfo.format = swapchain._swapChainImageFormat;
|
||||
createInfo.components.r = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
createInfo.components.g = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
createInfo.components.b = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
createInfo.components.a = VK_COMPONENT_SWIZZLE_IDENTITY;
|
||||
createInfo.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
createInfo.subresourceRange.baseMipLevel = 0;
|
||||
createInfo.subresourceRange.levelCount = 1;
|
||||
createInfo.subresourceRange.baseArrayLayer = 0;
|
||||
createInfo.subresourceRange.layerCount = 1;
|
||||
|
||||
if(vkCreateImageView(Render_Core::get().getDevice().get(), &createInfo, nullptr, &_image) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image view");
|
||||
}
|
||||
|
||||
void ImageView::destroy() noexcept
|
||||
{
|
||||
vkDestroyImageView(Render_Core::get().getDevice().get(), _image, nullptr);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* vk_imageview.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:20:19 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 19:54:44 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_VK_IMAGE_VIEW__
|
||||
#define __MLX_VK_IMAGE_VIEW__
|
||||
|
||||
#include <volk.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class ImageView
|
||||
{
|
||||
public:
|
||||
void init(class SwapChain& swapchain, VkImage& image);
|
||||
void destroy() noexcept;
|
||||
|
||||
inline VkImageView& operator()() noexcept { return _image; }
|
||||
inline VkImageView& get() noexcept { return _image; }
|
||||
|
||||
private:
|
||||
VkImageView _image = VK_NULL_HANDLE;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // __MLX_VK_IMAGE_VIEW__
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:22:28 by maldavid #+# #+# */
|
||||
/* Updated: 2023/01/25 11:39:01 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:15:10 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -18,138 +18,137 @@
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void SwapChain::init(Renderer* renderer)
|
||||
{
|
||||
void SwapChain::init(Renderer* renderer)
|
||||
{
|
||||
VkDevice device = Render_Core::get().getDevice().get();
|
||||
|
||||
_renderer = renderer;
|
||||
_swapChainSupport = querySwapChainSupport(Render_Core::get().getDevice().getPhysicalDevice());
|
||||
|
||||
_swapChainSupport = querySwapChainSupport(Render_Core::get().getDevice().getPhysicalDevice());
|
||||
VkSurfaceFormatKHR surfaceFormat = renderer->getSurface().chooseSwapSurfaceFormat(_swapChainSupport.formats);
|
||||
VkPresentModeKHR presentMode = chooseSwapPresentMode(_swapChainSupport.presentModes);
|
||||
_extent = chooseSwapExtent(_swapChainSupport.capabilities);
|
||||
|
||||
VkSurfaceFormatKHR surfaceFormat = renderer->getSurface().chooseSwapSurfaceFormat(_swapChainSupport.formats);
|
||||
VkPresentModeKHR presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; // change this to set vsync (if the driver supports it)
|
||||
VkExtent2D extent = chooseSwapExtent(_swapChainSupport.capabilities);
|
||||
uint32_t imageCount = _swapChainSupport.capabilities.minImageCount + 1;
|
||||
if(_swapChainSupport.capabilities.maxImageCount > 0 && imageCount > _swapChainSupport.capabilities.maxImageCount)
|
||||
imageCount = _swapChainSupport.capabilities.maxImageCount;
|
||||
|
||||
uint32_t imageCount = _swapChainSupport.capabilities.minImageCount + 1;
|
||||
if(_swapChainSupport.capabilities.maxImageCount > 0 && imageCount > _swapChainSupport.capabilities.maxImageCount)
|
||||
imageCount = _swapChainSupport.capabilities.maxImageCount;
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), renderer->getSurface().get());
|
||||
uint32_t queueFamilyIndices[] = { indices.graphicsFamily.value(), indices.presentFamily.value() };
|
||||
|
||||
VkSwapchainCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
createInfo.surface = renderer->getSurface().get();
|
||||
|
||||
createInfo.minImageCount = imageCount;
|
||||
createInfo.imageFormat = surfaceFormat.format;
|
||||
createInfo.imageColorSpace = surfaceFormat.colorSpace;
|
||||
createInfo.imageExtent = extent;
|
||||
createInfo.imageArrayLayers = 1;
|
||||
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
|
||||
Queues::QueueFamilyIndices indices = Render_Core::get().getQueue().findQueueFamilies(Render_Core::get().getDevice().getPhysicalDevice(), renderer->getSurface().get());
|
||||
uint32_t queueFamilyIndices[] = {indices.graphicsFamily.value(), indices.presentFamily.value()};
|
||||
|
||||
if(indices.graphicsFamily != indices.presentFamily)
|
||||
VkSwapchainCreateInfoKHR createInfo{};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
|
||||
createInfo.surface = renderer->getSurface().get();
|
||||
createInfo.minImageCount = imageCount;
|
||||
createInfo.imageFormat = surfaceFormat.format;
|
||||
createInfo.imageColorSpace = surfaceFormat.colorSpace;
|
||||
createInfo.imageExtent = _extent;
|
||||
createInfo.imageArrayLayers = 1;
|
||||
createInfo.imageUsage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
|
||||
createInfo.preTransform = _swapChainSupport.capabilities.currentTransform;
|
||||
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
createInfo.presentMode = presentMode;
|
||||
createInfo.clipped = VK_TRUE;
|
||||
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||
if(indices.graphicsFamily != indices.presentFamily)
|
||||
{
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||
createInfo.queueFamilyIndexCount = 2;
|
||||
createInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||
}
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_CONCURRENT;
|
||||
createInfo.queueFamilyIndexCount = 2;
|
||||
createInfo.pQueueFamilyIndices = queueFamilyIndices;
|
||||
}
|
||||
else
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
createInfo.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||
|
||||
createInfo.preTransform = _swapChainSupport.capabilities.currentTransform;
|
||||
createInfo.compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
createInfo.presentMode = presentMode;
|
||||
createInfo.clipped = VK_TRUE;
|
||||
if(vkCreateSwapchainKHR(device, &createInfo, nullptr, &_swapChain) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create the swapchain");
|
||||
|
||||
createInfo.oldSwapchain = VK_NULL_HANDLE;
|
||||
std::vector<VkImage> tmp;
|
||||
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, nullptr);
|
||||
_images.resize(imageCount);
|
||||
tmp.resize(imageCount);
|
||||
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, tmp.data());
|
||||
|
||||
VkDevice device = Render_Core::get().getDevice().get();
|
||||
for(int i = 0; i < imageCount; i++)
|
||||
{
|
||||
_images[i].create(tmp[i], surfaceFormat.format, _extent.width, _extent.height);
|
||||
_images[i].transitionLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
|
||||
_images[i].createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
|
||||
}
|
||||
|
||||
if(vkCreateSwapchainKHR(device, &createInfo, nullptr, &_swapChain) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create swapchain");
|
||||
_swapChainImageFormat = surfaceFormat.format;
|
||||
#ifdef DEBUG
|
||||
core::error::report(e_kind::message, "Vulkan : created new swapchain");
|
||||
#endif
|
||||
}
|
||||
|
||||
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, nullptr);
|
||||
_swapChainImages.resize(imageCount);
|
||||
vkGetSwapchainImagesKHR(device, _swapChain, &imageCount, _swapChainImages.data());
|
||||
SwapChain::SwapChainSupportDetails SwapChain::querySwapChainSupport(VkPhysicalDevice device)
|
||||
{
|
||||
SwapChain::SwapChainSupportDetails details;
|
||||
VkSurfaceKHR surface = _renderer->getSurface().get();
|
||||
|
||||
_swapChainImageFormat = surfaceFormat.format;
|
||||
_swapChainExtent = extent;
|
||||
if(vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : unable to retrieve surface capabilities");
|
||||
|
||||
_imageViews.resize(_swapChainImages.size());
|
||||
uint32_t formatCount = 0;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
|
||||
for(size_t i = 0; i < _swapChainImages.size(); i++)
|
||||
_imageViews[i].init(*this, _swapChainImages[i]);
|
||||
}
|
||||
if(formatCount != 0)
|
||||
{
|
||||
details.formats.resize(formatCount);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
|
||||
}
|
||||
|
||||
void SwapChain::initFB()
|
||||
{
|
||||
_framebuffers.resize(_imageViews.size());
|
||||
uint32_t presentModeCount;
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, nullptr);
|
||||
|
||||
for(size_t i = 0; i < _imageViews.size(); i++)
|
||||
_framebuffers[i].init(*_renderer, _imageViews[i]);
|
||||
}
|
||||
if(presentModeCount != 0)
|
||||
{
|
||||
details.presentModes.resize(presentModeCount);
|
||||
vkGetPhysicalDeviceSurfacePresentModesKHR(device, surface, &presentModeCount, details.presentModes.data());
|
||||
}
|
||||
|
||||
SwapChain::SwapChainSupportDetails SwapChain::querySwapChainSupport(VkPhysicalDevice device)
|
||||
{
|
||||
SwapChain::SwapChainSupportDetails details;
|
||||
VkSurfaceKHR surface = _renderer->getSurface().get();
|
||||
return details;
|
||||
}
|
||||
|
||||
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(device, surface, &details.capabilities);
|
||||
VkPresentModeKHR SwapChain::chooseSwapPresentMode([[maybe_unused]] const std::vector<VkPresentModeKHR>& availablePresentModes)
|
||||
{
|
||||
// in the future, you may choose to activate vsync or not
|
||||
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||
}
|
||||
|
||||
uint32_t formatCount = 0;
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, nullptr);
|
||||
VkExtent2D SwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities)
|
||||
{
|
||||
if(capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
||||
return capabilities.currentExtent;
|
||||
|
||||
if(formatCount != 0)
|
||||
{
|
||||
details.formats.resize(formatCount);
|
||||
vkGetPhysicalDeviceSurfaceFormatsKHR(device, surface, &formatCount, details.formats.data());
|
||||
}
|
||||
return details;
|
||||
}
|
||||
int width, height;
|
||||
SDL_Vulkan_GetDrawableSize(_renderer->getWindow()->getNativeWindow(), &width, &height);
|
||||
|
||||
VkExtent2D SwapChain::chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities)
|
||||
{
|
||||
if(capabilities.currentExtent.width != std::numeric_limits<uint32_t>::max())
|
||||
return capabilities.currentExtent;
|
||||
VkExtent2D actualExtent = { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
|
||||
|
||||
int width, height;
|
||||
SDL_Vulkan_GetDrawableSize(_renderer->getWindow()->getNativeWindow(), &width, &height);
|
||||
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||
|
||||
VkExtent2D actualExtent = { static_cast<uint32_t>(width), static_cast<uint32_t>(height) };
|
||||
return actualExtent;
|
||||
}
|
||||
|
||||
actualExtent.width = std::clamp(actualExtent.width, capabilities.minImageExtent.width, capabilities.maxImageExtent.width);
|
||||
actualExtent.height = std::clamp(actualExtent.height, capabilities.minImageExtent.height, capabilities.maxImageExtent.height);
|
||||
void SwapChain::recreate()
|
||||
{
|
||||
destroy();
|
||||
init(_renderer);
|
||||
}
|
||||
|
||||
return actualExtent;
|
||||
}
|
||||
|
||||
void SwapChain::recreate()
|
||||
{
|
||||
destroyFB();
|
||||
destroy();
|
||||
_renderer->getRenderPass().destroy();
|
||||
|
||||
init(_renderer);
|
||||
_renderer->getRenderPass().init(_renderer);
|
||||
initFB();
|
||||
}
|
||||
|
||||
void SwapChain::destroyFB() noexcept
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
|
||||
for(size_t i = 0; i < _framebuffers.size(); i++)
|
||||
_framebuffers[i].destroy();
|
||||
}
|
||||
|
||||
void SwapChain::destroy() noexcept
|
||||
{
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
|
||||
for(size_t i = 0; i < _imageViews.size(); i++)
|
||||
_imageViews[i].destroy();
|
||||
|
||||
if(_swapChain != VK_NULL_HANDLE)
|
||||
vkDestroySwapchainKHR(Render_Core::get().getDevice().get(), _swapChain, nullptr);
|
||||
_swapChain = VK_NULL_HANDLE;
|
||||
}
|
||||
void SwapChain::destroy() noexcept
|
||||
{
|
||||
if(_swapChain == VK_NULL_HANDLE)
|
||||
return;
|
||||
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
|
||||
vkDestroySwapchainKHR(Render_Core::get().getDevice().get(), _swapChain, nullptr);
|
||||
_swapChain = VK_NULL_HANDLE;
|
||||
for(Image& img : _images)
|
||||
{
|
||||
img.destroyImageView();
|
||||
img.destroyCmdPool();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:23:27 by maldavid #+# #+# */
|
||||
/* Updated: 2022/12/18 22:08:36 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/18 17:15:18 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -15,15 +15,12 @@
|
||||
|
||||
#include <vector>
|
||||
#include <volk.h>
|
||||
#include "vk_imageview.h"
|
||||
#include "vk_framebuffer.h"
|
||||
#include <renderer/images/vk_image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
class SwapChain
|
||||
{
|
||||
friend class FrameBuffer;
|
||||
friend class ImageView;
|
||||
friend class GraphicPipeline;
|
||||
friend class RenderPass;
|
||||
friend class Renderer;
|
||||
@@ -33,32 +30,36 @@ namespace mlx
|
||||
{
|
||||
VkSurfaceCapabilitiesKHR capabilities;
|
||||
std::vector<VkSurfaceFormatKHR> formats;
|
||||
std::vector<VkPresentModeKHR> presentModes;
|
||||
};
|
||||
|
||||
public:
|
||||
SwapChain() = default;
|
||||
|
||||
void init(class Renderer* renderer);
|
||||
void initFB();
|
||||
void destroy() noexcept;
|
||||
void destroyFB() noexcept;
|
||||
|
||||
void recreate();
|
||||
void destroy() noexcept;
|
||||
|
||||
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device);
|
||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||
SwapChainSupportDetails querySwapChainSupport(VkPhysicalDevice device);
|
||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR& capabilities);
|
||||
VkPresentModeKHR chooseSwapPresentMode([[maybe_unused]] const std::vector<VkPresentModeKHR> &availablePresentModes);
|
||||
|
||||
inline SwapChainSupportDetails getSupport() noexcept { return _swapChainSupport; }
|
||||
inline VkSwapchainKHR& operator()() noexcept { return _swapChain; }
|
||||
inline VkSwapchainKHR& get() noexcept { return _swapChain; }
|
||||
inline FrameBuffer& getFrameBuffer(int i) { return _framebuffers[i]; }
|
||||
inline size_t getImagesNumber() const noexcept { return _swapChainImages.size(); }
|
||||
inline VkSwapchainKHR get() noexcept { return _swapChain; }
|
||||
inline VkSwapchainKHR operator()() noexcept { return _swapChain; }
|
||||
inline size_t getImagesNumber() const noexcept { return _images.size(); }
|
||||
inline Image& getImage(std::size_t i) noexcept { return _images[i]; }
|
||||
inline SwapChainSupportDetails getSupport() noexcept { return _swapChainSupport; }
|
||||
inline VkExtent2D getExtent() noexcept { return _extent; }
|
||||
inline VkFormat getImagesFormat() const noexcept { return _swapChainImageFormat; }
|
||||
|
||||
~SwapChain() = default;
|
||||
|
||||
private:
|
||||
SwapChainSupportDetails _swapChainSupport;
|
||||
std::vector<VkImage> _swapChainImages;
|
||||
std::vector<FrameBuffer> _framebuffers;
|
||||
std::vector<ImageView> _imageViews;
|
||||
VkSwapchainKHR _swapChain;
|
||||
VkFormat _swapChainImageFormat;
|
||||
VkExtent2D _swapChainExtent;
|
||||
SwapChainSupportDetails _swapChainSupport;
|
||||
VkSwapchainKHR _swapChain;
|
||||
std::vector<Image> _images;
|
||||
VkFormat _swapChainImageFormat;
|
||||
VkExtent2D _extent;
|
||||
class Renderer* _renderer = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/10 11:59:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/19 13:43:43 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/16 13:45:31 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -20,8 +20,13 @@ namespace mlx
|
||||
void TextData::init(std::string text, std::vector<Vertex> vbo_data, std::vector<uint16_t> ibo_data)
|
||||
{
|
||||
_text = std::move(text);
|
||||
_vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data());
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data());
|
||||
#ifdef DEBUG
|
||||
_vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data(), _text.c_str());
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), _text.c_str());
|
||||
#else
|
||||
_vbo.create(sizeof(Vertex) * vbo_data.size(), vbo_data.data(), nullptr);
|
||||
_ibo.create(sizeof(uint16_t) * ibo_data.size(), ibo_data.data(), nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
void TextData::bind(Renderer& renderer) noexcept
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:41:13 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/19 13:43:49 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 05:36:09 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace mlx
|
||||
vulkan_bitmap[j + 2] = tmp_bitmap[i];
|
||||
vulkan_bitmap[j + 3] = tmp_bitmap[i];
|
||||
}
|
||||
_atlas.create(vulkan_bitmap, 512, 512, VK_FORMAT_R8G8B8A8_UNORM);
|
||||
_atlas.create(vulkan_bitmap, 512, 512, VK_FORMAT_R8G8B8A8_UNORM, "__mlx_texts_pipeline_texture_atlas", true);
|
||||
_atlas.setDescriptor(renderer->getFragDescriptorSet().duplicate());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/06 16:24:11 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/12 13:25:33 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/14 12:43:45 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace mlx
|
||||
void init(Renderer* renderer) noexcept;
|
||||
void put(int x, int y, int color, std::string str);
|
||||
inline VkDescriptorSet getDescriptorSet() noexcept { return _atlas.getSet(); }
|
||||
inline void clear() { _drawlist.clear(); }
|
||||
inline void clear() { _drawlist.clear(); _library.clearLibrary(); }
|
||||
void render();
|
||||
void destroy() noexcept;
|
||||
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/11 16:20:25 by maldavid #+# #+# */
|
||||
/* Updated: 2023/04/11 16:20:27 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/08 20:23:23 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef __MLX_DOGICA_TTF__
|
||||
#define __MLX_DOGICA_TTF__
|
||||
|
||||
unsigned int dogica_ttf_len = 33860;
|
||||
inline unsigned int dogica_ttf_len = 33860;
|
||||
|
||||
unsigned char dogica_ttf[] = {
|
||||
inline unsigned char dogica_ttf[] = {
|
||||
0x00, 0x01, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x80, 0x00, 0x03, 0x00, 0x60,
|
||||
0x46, 0x46, 0x54, 0x4d, 0x8f, 0xe1, 0x5b, 0x60, 0x00, 0x00, 0x84, 0x28,
|
||||
0x00, 0x00, 0x00, 0x1c, 0x47, 0x44, 0x45, 0x46, 0x00, 0x15, 0x00, 0x14,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
||||
/* Updated: 2023/08/28 10:52:33 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/17 09:08:51 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,6 +19,7 @@ typedef struct s_mlx
|
||||
void *mlx;
|
||||
void *win;
|
||||
void *logo;
|
||||
void *img;
|
||||
} t_mlx;
|
||||
|
||||
int update(t_mlx *mlx)
|
||||
@@ -28,6 +29,7 @@ int update(t_mlx *mlx)
|
||||
int k;
|
||||
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->logo, 100, 100);
|
||||
mlx_put_image_to_window(mlx->mlx, mlx->win, mlx->img, 220, 20);
|
||||
mlx_string_put(mlx->mlx, mlx->win, 20, 50, 0xFFFFFFFF, "that's a text");
|
||||
j = 0;
|
||||
k = 0;
|
||||
@@ -102,13 +104,12 @@ int main(void)
|
||||
mlx.logo = mlx_png_file_to_image(mlx.mlx, "42_logo.png", &w, &h);
|
||||
mlx_pixel_put(mlx.mlx, mlx.win, 200, 10, 0xFFFF00FF);
|
||||
mlx_put_image_to_window(mlx.mlx, mlx.win, mlx.logo, 200, 200);
|
||||
img = create_image(&mlx);
|
||||
mlx.img = create_image(&mlx);
|
||||
mlx_string_put(mlx.mlx, mlx.win, 20, 20, 0xFFFF2000, \
|
||||
"that text will disappear");
|
||||
mlx_put_image_to_window(mlx.mlx, mlx.win, img, 200, 20);
|
||||
mlx_loop_hook(mlx.mlx, update, &mlx);
|
||||
mlx_loop(mlx.mlx);
|
||||
mlx_destroy_image(mlx.mlx, img);
|
||||
mlx_destroy_image(mlx.mlx, mlx.img);
|
||||
mlx_destroy_image(mlx.mlx, mlx.logo);
|
||||
mlx_destroy_window(mlx.mlx, mlx.win);
|
||||
mlx_destroy_display(mlx.mlx);
|
||||
|
||||
19558
third_party/vma.h
vendored
git.filemode.normal_file
19558
third_party/vma.h
vendored
git.filemode.normal_file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user