Skip to content

Commit f8dc961

Browse files
authored
release 2.0 (#110)
2 parents 4448479 + 07f521d commit f8dc961

File tree

648 files changed

+81061
-130111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

648 files changed

+81061
-130111
lines changed

.github/workflows/linux_clang.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [ubuntu-latest]
16+
os: [ubuntu-24.04]
1717
arch: [x86_64]
1818
mode: [release]
1919

2020
runs-on: ${{ matrix.os }}
2121
if: "!contains(github.event.head_commit.message, 'ci skip')"
2222

2323
steps:
24-
- name: Get current date as package key
25-
id: cache_key
26-
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
27-
2824
- name: Checkout repository
2925
uses: actions/checkout@v4
3026

.github/workflows/linux_gcc.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ jobs:
1313
strategy:
1414
fail-fast: false
1515
matrix:
16-
os: [ubuntu-latest]
16+
os: [ubuntu-24.04]
1717
arch: [x86_64]
1818
mode: [release]
1919

2020
runs-on: ${{ matrix.os }}
2121
if: "!contains(github.event.head_commit.message, 'ci skip')"
2222

2323
steps:
24-
- name: Get current date as package key
25-
id: cache_key
26-
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
27-
2824
- name: Checkout repository
2925
uses: actions/checkout@v4
3026

.github/workflows/macos_x86.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ jobs:
2121
if: "!contains(github.event.head_commit.message, 'ci skip')"
2222

2323
steps:
24-
- name: Get current date as package key
25-
id: cache_key
26-
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
27-
2824
- name: Checkout repository
2925
uses: actions/checkout@v4
3026

.github/workflows/windows.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,3 @@ jobs:
5050
# Build the mlx
5151
- name: Build MacroLibX
5252
run: xmake --yes
53-
54-
# Build the example
55-
- name: Build Example
56-
run: xmake build --yes Test

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
*.tmp
1212
*.ilk
1313
*.pdb
14+
*.gch
15+
*.pch
16+
*.sym
1417
*.exe
15-
*vgcore
18+
*vgcore.*
1619
*.gdb_history
1720
.vs/
1821
.xmake/

Makefile

Lines changed: 120 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,178 @@
1-
# **************************************************************************** #
2-
# #
3-
# ::: :::::::: #
4-
# Makefile :+: :+: :+: #
5-
# +:+ +:+ +:+ #
6-
# By: kiroussa <oss@xtrm.me> +#+ +:+ +#+ #
7-
# +#+#+#+#+#+ +#+ #
8-
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
9-
# Updated: 2024/04/24 14:59:23 by kiroussa ### ########.fr #
10-
# #
11-
# **************************************************************************** #
12-
13-
NAME = libmlx.so
14-
MAKE = make --no-print-directory
15-
16-
OS ?= $(shell uname -s)
17-
DEBUG ?= false
18-
TOOLCHAIN ?= clang
19-
IMAGES_OPTIMIZED ?= true
20-
FORCE_INTEGRATED_GPU ?= false
21-
GRAPHICS_MEMORY_DUMP ?= false
22-
PROFILER ?= false
23-
_ENABLEDFLAGS =
24-
25-
SRCS = $(wildcard $(addsuffix /*.cpp, src/core))
26-
SRCS += $(wildcard $(addsuffix /*.cpp, src/platform))
27-
SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer))
28-
SRCS += $(wildcard $(addsuffix /*.cpp, src/renderer/**))
29-
30-
OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
31-
OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
32-
33-
CXX = clang++
34-
CXXFLAGS = -std=c++17 -O3 -fPIC -Wall -Wextra -Werror -DSDL_MAIN_HANDLED
35-
INCLUDES = -I./includes -I./src -I./third_party
1+
NAME = libmlx.so
2+
MAKE = make --no-print-directory
3+
4+
OS ?= $(shell uname -s)
5+
DEBUG ?= false
6+
TOOLCHAIN ?= clang
7+
IMAGES_OPTIMIZED ?= true
8+
FORCE_INTEGRATED_GPU ?= false
9+
GRAPHICS_MEMORY_DUMP ?= false
10+
PROFILER ?= false
11+
FORCE_WAYLAND ?= false
12+
DISABLE_ALL_SAFETIES ?= false
13+
_ENABLEDFLAGS =
14+
15+
SRCS = $(wildcard $(addsuffix /*.cpp, runtime/Sources/Core))
16+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Graphics))
17+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Platform))
18+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer))
19+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Vulkan))
20+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Pipelines))
21+
SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/RenderPasses))
22+
23+
OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
24+
OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
25+
26+
SHADERS_DIR = runtime/Includes/Embedded
27+
SHADERS_SRCS = $(wildcard $(addsuffix /*.nzsl, $(SHADERS_DIR)))
28+
SPVS = $(SHADERS_SRCS:.nzsl=.spv.h)
29+
30+
CXX = clang++
31+
CXXFLAGS = -std=c++20 -fPIC -Wall -Wextra -DSDL_MAIN_HANDLED
32+
INCLUDES = -I./includes -I./runtime/Includes -I./runtime/Sources -I./third_party
33+
34+
CXXPCHFLAGS = -xc++-header -std=c++20 -Wall -Wextra
35+
36+
PCH_SOURCE = runtime/Includes/PreCompiled.h
37+
GCH = runtime/Includes/PreCompiled.h.gch
38+
CCH = runtime/Includes/PreCompiled.h.pch
39+
PCH =
40+
41+
NZSLC ?= nzslc
3642

3743
ifeq ($(TOOLCHAIN), gcc)
38-
CXX = g++
39-
CXXFLAGS += -Wno-error=cpp
44+
CXX = g++
45+
PCH = $(GCH)
46+
CXXFLAGS += -Wno-error=cpp
4047
else
41-
CXXFLAGS += -Wno-error=#warning
48+
PCH = $(CCH)
49+
CXXFLAGS += -Wno-error=#warning -include-pch $(PCH)
4250
endif
4351

4452
ifeq ($(OS), Darwin)
45-
LDFLAGS += -L /opt/homebrew/lib -lSDL2
46-
CXXFLAGS += -I /opt/homebrew/include
47-
NAME = libmlx.dylib
53+
LDFLAGS += -L /opt/homebrew/Cellar/lib -L /usr/local/Cellar -L /opt/homebrew/lib -lSDL2
54+
INCLUDES += -I /opt/homebrew/Cellar/include -I /usr/local/Cellar/include -I /opt/homebrew/include
55+
NAME = libmlx.dylib
4856
endif
4957

5058
ifeq ($(DEBUG), true)
51-
CXXFLAGS += -g3 -D DEBUG
52-
LDFLAGS += -rdynamic
59+
CXXFLAGS += -g3 -O0 -D DEBUG
60+
LDFLAGS += -rdynamic
61+
else
62+
CXXFLAGS += -O3
5363
endif
5464

5565
ifeq ($(FORCE_INTEGRATED_GPU), true)
56-
_ENABLEDFLAGS += FORCE_INTEGRATED_GPU
66+
_ENABLEDFLAGS += FORCE_INTEGRATED_GPU
5767
endif
5868

5969
ifeq ($(IMAGES_OPTIMIZED), true)
60-
_ENABLEDFLAGS += IMAGE_OPTIMIZED
70+
_ENABLEDFLAGS += IMAGE_OPTIMIZED
6171
endif
6272

6373
ifeq ($(GRAPHICS_MEMORY_DUMP), true)
64-
_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP
74+
_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP
6575
endif
6676

6777
ifeq ($(PROFILER), true)
68-
_ENABLEDFLAGS += PROFILER
78+
_ENABLEDFLAGS += PROFILER
79+
endif
80+
81+
ifeq ($(FORCE_WAYLAND), true)
82+
_ENABLEDFLAGS += FORCE_WAYLAND
6983
endif
7084

71-
CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))
85+
ifeq ($(DISABLE_ALL_SAFETIES), true)
86+
_ENABLEDFLAGS += DISABLE_ALL_SAFETIES
87+
endif
88+
89+
CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))
7290

7391
RM = rm -rf
7492

75-
TPUT = tput -T xterm-256color
76-
_RESET := $(shell $(TPUT) sgr0)
77-
_BOLD := $(shell $(TPUT) bold)
78-
_ITALIC := $(shell $(TPUT) sitm)
79-
_UNDER := $(shell $(TPUT) smul)
80-
_GREEN := $(shell $(TPUT) setaf 2)
81-
_YELLOW := $(shell $(TPUT) setaf 3)
82-
_RED := $(shell $(TPUT) setaf 1)
83-
_GRAY := $(shell $(TPUT) setaf 8)
84-
_PURPLE := $(shell $(TPUT) setaf 5)
93+
TPUT = tput -T xterm-256color
94+
_RESET := $(shell $(TPUT) sgr0)
95+
_BOLD := $(shell $(TPUT) bold)
96+
_ITALIC := $(shell $(TPUT) sitm)
97+
_UNDER := $(shell $(TPUT) smul)
98+
_GREEN := $(shell $(TPUT) setaf 2)
99+
_YELLOW := $(shell $(TPUT) setaf 3)
100+
_RED := $(shell $(TPUT) setaf 1)
101+
_GRAY := $(shell $(TPUT) setaf 8)
102+
_PURPLE := $(shell $(TPUT) setaf 5)
85103

86104
ifeq ($(DEBUG), true)
87-
MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE)
88-
COLOR := $(_PURPLE)
105+
MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE)
106+
COLOR := $(_PURPLE)
89107
else
90-
MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN)
91-
COLOR := $(_GREEN)
108+
MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN)
109+
COLOR := $(_GREEN)
92110
endif
93111

94-
OBJS_TOTAL = $(words $(OBJS))
95-
N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l)
96-
OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) )))
97-
CURR_OBJ = 0
112+
OBJS_TOTAL = $(words $(OBJS))
113+
N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l)
114+
OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) )))
115+
ifeq ($(OBJS_TOTAL), 0) # To avoid division per 0
116+
OBJS_TOTAL := 1
117+
endif
118+
CURR_OBJ = 0
98119

99-
$(OBJ_DIR)/%.o: %.cpp
120+
$(OBJ_DIR)/%.o: %.cpp $(PCH)
100121
@mkdir -p $(dir $@)
101122
@$(eval CURR_OBJ=$(shell echo $$(( $(CURR_OBJ) + 1 ))))
102123
@$(eval PERCENT=$(shell echo $$(( $(CURR_OBJ) * 100 / $(OBJS_TOTAL) ))))
103124
@printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)"
104125
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
105126

106-
all: _printbuildinfos
127+
SPVS_TOTAL = $(words $(SPVS))
128+
N_SPVS := $(shell find $(SHADERS_DIR) -type f -name '*.spv.h' 2>/dev/null | wc -l)
129+
SPVS_TOTAL := $(shell echo $$(( $(SPVS_TOTAL) - $(N_SPVS) )))
130+
ifeq ($(SPVS_TOTAL), 0) # Same
131+
SPVS_TOTAL := 1
132+
endif
133+
CURR_SPV = 0
134+
135+
%.spv.h: %.nzsl
136+
@$(eval CURR_SPV=$(shell echo $$(( $(CURR_SPV) + 1 ))))
137+
@$(eval PERCENT=$(shell echo $$(( $(CURR_SPV) * 100 / $(SPVS_TOTAL) ))))
138+
@printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)"
139+
@$(NZSLC) --compile=spv-header $< -o $(SHADERS_DIR) --optimize
140+
141+
all: _printbuildinfos
107142
@$(MAKE) $(NAME)
108143

109-
$(NAME): $(OBJS)
144+
$(PCH):
145+
@printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)PreCompiled header$(_RESET)\n" "0"
146+
@$(CXX) $(CXXPCHFLAGS) $(INCLUDES) $(PCH_SOURCE) -o $(PCH)
147+
148+
$(NAME): $(OBJS)
110149
@printf "Linking $(_BOLD)$(NAME)$(_RESET)\n"
111150
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS)
112151
@printf "$(_BOLD)$(NAME)$(_RESET) compiled $(COLOR)$(_BOLD)successfully$(_RESET)\n"
113152

114153
_printbuildinfos:
115-
@printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX)$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n"
154+
@printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX) ($(shell $(CXX) --version | head -n 1))$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n"
116155

117156
debug:
118157
@$(MAKE) all DEBUG=true -j$(shell nproc)
119158

159+
clean-shaders:
160+
@$(RM) $(SPVS)
161+
162+
shaders: clean-shaders $(SPVS)
163+
120164
clean:
121165
@$(RM) $(OBJ_DIR)
122166
@printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n"
167+
@$(RM) $(GCH)
168+
@$(RM) $(CCH)
169+
@printf "Cleaned pre compiled header\n"
123170

124-
fclean: clean
171+
fclean: clean
125172
@$(RM) $(NAME)
126173
@printf "Cleaned $(_BOLD)$(NAME)$(_RESET)\n"
127174

128-
re: fclean _printbuildinfos
175+
re: fclean _printbuildinfos
129176
@$(MAKE) $(NAME)
130177

131-
.PHONY: all clean debug fclean re
178+
.PHONY: all clean debug shaders clean-shaders fclean re

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ And you can enjoy your project
9797
### 📦 Compile mode
9898
By default the mlx is built in release mode but you can switch to debug by using `make DEBUG=true`.
9999

100+
### 🦺 Safety
101+
MacroLibX has a strong safety support, mainly by checking every pointer that you pass to it. But this safety has a cost that can be avoided by enabling `DISABLE_ALL_SAFETIES=true` before compiling but don't be afraid to recieve segmentation faults from the mlx.
102+
100103
### 🛠️ Set the toolchain
101104
If you want to use `GCC` to build the mlx you can use `make TOOLCHAIN=gcc`
102105

XMAKE_BUILD.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Just as the Makfile build system, you can configure how xmake should build the M
1010
### 📦 Compile mode
1111
You can configure xmake to build the mlx in debug mode or in release mode (release mode is enabled by default). To do so you can use `xmake config --mode=debug` or `xmake config --mode=release`.
1212

13+
### 🦺 Safety
14+
MacroLibX has a strong safety support, mainly by checking every pointer that you pass to it. But this safety has a cost that can be avoided by enabling `xmake config --disable_all_safeties=y` before compiling but don't be afraid to recieve segmentation faults from the mlx.
15+
1316
### 🛠️ Set the toolchain
1417
To change the compilation toolchain you can use `xmake config --toolchain=[gcc|clang|...]`
1518

0 commit comments

Comments
 (0)