diff --git a/Makefile b/Makefile index 890e9a4..7617caa 100644 --- a/Makefile +++ b/Makefile @@ -16,15 +16,23 @@ SRCS = $(wildcard $(addsuffix /*.cpp, runtime/Sources/Core)) SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Graphics)) SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Platform)) SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer)) -SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/**)) +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Vulkan)) +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/Pipelines)) +SRCS += $(wildcard $(addsuffix /*.cpp, runtime/Sources/Renderer/RenderPasses)) OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]') OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o)) +SHADERS_DIR = runtime/Includes/Embedded +SHADERS_SRCS = $(wildcard $(addsuffix /*.nzsl, $(SHADERS_DIR))) +SPVS = $(SHADERS_SRCS:.nzsl=.spv.h) + CXX = clang++ CXXFLAGS = -std=c++20 -O3 -fPIC -Wall -Wextra -DSDL_MAIN_HANDLED INCLUDES = -I./includes -I./runtime/Includes -I./runtime/Sources -I./third_party +NZSLC = nzslc + ifeq ($(TOOLCHAIN), gcc) CXX = g++ CXXFLAGS += -Wno-error=cpp @@ -93,6 +101,9 @@ endif OBJS_TOTAL = $(words $(OBJS)) N_OBJS := $(shell find $(OBJ_DIR) -type f -name '*.o' 2>/dev/null | wc -l) OBJS_TOTAL := $(shell echo $$(( $(OBJS_TOTAL) - $(N_OBJS) ))) +ifeq ($(OBJS_TOTAL), 0) # To avoid division per 0 + OBJS_TOTAL := 1 +endif CURR_OBJ = 0 $(OBJ_DIR)/%.o: %.cpp @@ -102,6 +113,20 @@ $(OBJ_DIR)/%.o: %.cpp @printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)" @$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@ +SPVS_TOTAL = $(words $(SPVS)) +N_SPVS := $(shell find $(SHADERS_DIR) -type f -name '*.spv.h' 2>/dev/null | wc -l) +SPVS_TOTAL := $(shell echo $$(( $(SPVS_TOTAL) - $(N_SPVS) ))) +ifeq ($(SPVS_TOTAL), 0) # Same + SPVS_TOTAL := 1 +endif +CURR_SPV = 0 + +%.spv.h: %.nzsl + @$(eval CURR_SPV=$(shell echo $$(( $(CURR_SPV) + 1 )))) + @$(eval PERCENT=$(shell echo $$(( $(CURR_SPV) * 100 / $(SPVS_TOTAL) )))) + @printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)" + @$(NZSLC) --compile=spv-header $< -o $(SHADERS_DIR) --optimize + all: _printbuildinfos @$(MAKE) $(NAME) @@ -116,6 +141,11 @@ _printbuildinfos: debug: @$(MAKE) all DEBUG=true -j$(shell nproc) +clean-shaders: + @$(RM) $(SPVS) + +shaders: clean-shaders $(SPVS) + clean: @$(RM) $(OBJ_DIR) @printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n" @@ -127,4 +157,4 @@ fclean: clean re: fclean _printbuildinfos @$(MAKE) $(NAME) -.PHONY: all clean debug fclean re +.PHONY: all clean debug shaders clean-shaders fclean re diff --git a/runtime/Includes/Core/Graphics.inl b/runtime/Includes/Core/Graphics.inl index c0f4c02..33b0df6 100644 --- a/runtime/Includes/Core/Graphics.inl +++ b/runtime/Includes/Core/Graphics.inl @@ -14,12 +14,14 @@ namespace mlx void GraphicsSupport::PixelPut(int x, int y, std::uint32_t color) noexcept { MLX_PROFILE_FUNCTION(); + /* NonOwningPtr texture = m_put_pixel_manager.DrawPixel(x, y, m_current_depth, color); if(texture) { Sprite& new_sprite = p_scene->CreateSprite(texture); new_sprite.SetPosition(Vec3f{ 0.0f, 0.0f, static_cast(m_current_depth) }); } + */ } void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str) @@ -39,10 +41,10 @@ namespace mlx { Sprite& new_sprite = p_scene->CreateSprite(texture); new_sprite.SetPosition(Vec3f{ static_cast(x), static_cast(y), static_cast(m_current_depth) }); + m_current_depth++; } else sprite->SetPosition(Vec3f{ static_cast(x), static_cast(y), static_cast(m_current_depth) }); - m_current_depth++; } void GraphicsSupport::LoadFont(const std::filesystem::path& filepath, float scale) diff --git a/runtime/Includes/Embedded/2DVertex.spv.h b/runtime/Includes/Embedded/2DVertex.spv.h index 5a4f7f8..ac303d2 100644 --- a/runtime/Includes/Embedded/2DVertex.spv.h +++ b/runtime/Includes/Embedded/2DVertex.spv.h @@ -1,77 +1,68 @@ -3,2,35,7,0,0,1,0,39,0,0,0,73,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0, -3,0,0,0,0,0,1,0,0,0,15,0,12,0,0,0,0,0,36,0,0,0,109,97,105,110,0,0,0,0, -13,0,0,0,17,0,0,0,19,0,0,0,23,0,0,0,29,0,0,0,31,0,0,0,32,0,0,0,3,0, -3,0,0,0,0,0,100,0,0,0,5,0,5,0,4,0,0,0,86,105,101,119,101,114,68,97,116,97,0,0, -6,0,8,0,4,0,0,0,0,0,0,0,112,114,111,106,101,99,116,105,111,110,95,109,97,116,114,105,120,0, -0,0,5,0,5,0,7,0,0,0,83,112,114,105,116,101,68,97,116,97,0,0,6,0,5,0,7,0,0,0, -0,0,0,0,99,111,108,111,114,0,0,0,6,0,6,0,7,0,0,0,1,0,0,0,112,111,115,105,116,105, -111,110,0,0,0,0,5,0,4,0,26,0,0,0,86,101,114,116,73,110,0,0,6,0,4,0,26,0,0,0, -0,0,0,0,112,111,115,0,6,0,5,0,26,0,0,0,1,0,0,0,99,111,108,111,114,0,0,0,6,0, -5,0,26,0,0,0,2,0,0,0,110,111,114,109,97,108,0,0,6,0,4,0,26,0,0,0,3,0,0,0, -117,118,0,0,5,0,4,0,33,0,0,0,86,101,114,116,79,117,116,0,6,0,5,0,33,0,0,0,0,0, -0,0,99,111,108,111,114,0,0,0,6,0,4,0,33,0,0,0,1,0,0,0,117,118,0,0,6,0,4,0, -33,0,0,0,2,0,0,0,112,111,115,0,5,0,5,0,6,0,0,0,118,105,101,119,101,114,95,100,97,116, -97,0,5,0,4,0,9,0,0,0,109,111,100,101,108,0,0,0,5,0,3,0,13,0,0,0,112,111,115,0, -5,0,4,0,17,0,0,0,99,111,108,111,114,0,0,0,5,0,4,0,19,0,0,0,110,111,114,109,97,108, -0,0,5,0,3,0,23,0,0,0,117,118,0,0,5,0,4,0,29,0,0,0,99,111,108,111,114,0,0,0, -5,0,3,0,31,0,0,0,117,118,0,0,5,0,5,0,32,0,0,0,112,111,115,105,116,105,111,110,0,0, -0,0,5,0,4,0,36,0,0,0,109,97,105,110,0,0,0,0,71,0,4,0,6,0,0,0,33,0,0,0, -0,0,0,0,71,0,4,0,6,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,32,0,0,0,11,0, -0,0,0,0,0,0,71,0,4,0,13,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,17,0,0,0, -30,0,0,0,1,0,0,0,71,0,4,0,19,0,0,0,30,0,0,0,2,0,0,0,71,0,4,0,23,0, -0,0,30,0,0,0,3,0,0,0,71,0,4,0,29,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0, -31,0,0,0,30,0,0,0,1,0,0,0,71,0,3,0,4,0,0,0,2,0,0,0,72,0,4,0,4,0, -0,0,0,0,0,0,5,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0,7,0,0,0,16,0,0,0, -72,0,5,0,4,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0,3,0,7,0,0,0,2,0, -0,0,72,0,5,0,7,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,7,0,0,0, -1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,26,0,0,0,0,0,0,0,35,0,0,0,0,0, -0,0,72,0,5,0,26,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,26,0,0,0, -2,0,0,0,35,0,0,0,32,0,0,0,72,0,5,0,26,0,0,0,3,0,0,0,35,0,0,0,48,0, -0,0,72,0,5,0,33,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,33,0,0,0, -1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,33,0,0,0,2,0,0,0,35,0,0,0,32,0, -0,0,22,0,3,0,1,0,0,0,32,0,0,0,23,0,4,0,2,0,0,0,1,0,0,0,4,0,0,0, -24,0,4,0,3,0,0,0,2,0,0,0,4,0,0,0,30,0,3,0,4,0,0,0,3,0,0,0,32,0, -4,0,5,0,0,0,2,0,0,0,4,0,0,0,30,0,4,0,7,0,0,0,2,0,0,0,2,0,0,0, -32,0,4,0,8,0,0,0,9,0,0,0,7,0,0,0,19,0,2,0,10,0,0,0,33,0,3,0,11,0, -0,0,10,0,0,0,32,0,4,0,12,0,0,0,1,0,0,0,2,0,0,0,21,0,4,0,14,0,0,0, -32,0,0,0,1,0,0,0,43,0,4,0,14,0,0,0,15,0,0,0,0,0,0,0,32,0,4,0,16,0, -0,0,7,0,0,0,2,0,0,0,43,0,4,0,14,0,0,0,18,0,0,0,1,0,0,0,43,0,4,0, -14,0,0,0,20,0,0,0,2,0,0,0,23,0,4,0,21,0,0,0,1,0,0,0,2,0,0,0,32,0, -4,0,22,0,0,0,1,0,0,0,21,0,0,0,43,0,4,0,14,0,0,0,24,0,0,0,3,0,0,0, -32,0,4,0,25,0,0,0,7,0,0,0,21,0,0,0,30,0,6,0,26,0,0,0,2,0,0,0,2,0, -0,0,2,0,0,0,21,0,0,0,32,0,4,0,27,0,0,0,7,0,0,0,26,0,0,0,32,0,4,0, -28,0,0,0,3,0,0,0,2,0,0,0,32,0,4,0,30,0,0,0,3,0,0,0,21,0,0,0,30,0, -5,0,33,0,0,0,2,0,0,0,21,0,0,0,2,0,0,0,43,0,4,0,1,0,0,0,34,0,0,0, -0,0,128,63,32,0,4,0,35,0,0,0,7,0,0,0,33,0,0,0,32,0,4,0,50,0,0,0,7,0, -0,0,1,0,0,0,32,0,4,0,55,0,0,0,9,0,0,0,2,0,0,0,32,0,4,0,59,0,0,0, -2,0,0,0,3,0,0,0,59,0,4,0,5,0,0,0,6,0,0,0,2,0,0,0,59,0,4,0,8,0, -0,0,9,0,0,0,9,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,1,0,0,0,59,0,4,0, -12,0,0,0,17,0,0,0,1,0,0,0,59,0,4,0,12,0,0,0,19,0,0,0,1,0,0,0,59,0, -4,0,22,0,0,0,23,0,0,0,1,0,0,0,59,0,4,0,28,0,0,0,29,0,0,0,3,0,0,0, -59,0,4,0,30,0,0,0,31,0,0,0,3,0,0,0,59,0,4,0,28,0,0,0,32,0,0,0,3,0, -0,0,54,0,5,0,10,0,0,0,36,0,0,0,0,0,0,0,11,0,0,0,248,0,2,0,37,0,0,0, -59,0,4,0,35,0,0,0,38,0,0,0,7,0,0,0,59,0,4,0,27,0,0,0,39,0,0,0,7,0, -0,0,65,0,5,0,16,0,0,0,40,0,0,0,39,0,0,0,15,0,0,0,63,0,3,0,40,0,0,0, -13,0,0,0,65,0,5,0,16,0,0,0,41,0,0,0,39,0,0,0,18,0,0,0,63,0,3,0,41,0, -0,0,17,0,0,0,65,0,5,0,16,0,0,0,42,0,0,0,39,0,0,0,20,0,0,0,63,0,3,0, -42,0,0,0,19,0,0,0,65,0,5,0,25,0,0,0,43,0,0,0,39,0,0,0,24,0,0,0,63,0, -3,0,43,0,0,0,23,0,0,0,65,0,5,0,25,0,0,0,44,0,0,0,39,0,0,0,24,0,0,0, -61,0,4,0,21,0,0,0,45,0,0,0,44,0,0,0,81,0,5,0,1,0,0,0,46,0,0,0,45,0, -0,0,0,0,0,0,127,0,4,0,1,0,0,0,47,0,0,0,34,0,0,0,133,0,5,0,1,0,0,0, -48,0,0,0,46,0,0,0,47,0,0,0,65,0,5,0,25,0,0,0,49,0,0,0,39,0,0,0,24,0, -0,0,65,0,5,0,50,0,0,0,51,0,0,0,49,0,0,0,15,0,0,0,62,0,3,0,51,0,0,0, -48,0,0,0,65,0,5,0,25,0,0,0,52,0,0,0,39,0,0,0,24,0,0,0,61,0,4,0,21,0, -0,0,53,0,0,0,52,0,0,0,65,0,5,0,25,0,0,0,54,0,0,0,38,0,0,0,18,0,0,0, -62,0,3,0,54,0,0,0,53,0,0,0,65,0,5,0,55,0,0,0,56,0,0,0,9,0,0,0,15,0, -0,0,61,0,4,0,2,0,0,0,57,0,0,0,56,0,0,0,65,0,5,0,16,0,0,0,58,0,0,0, -38,0,0,0,15,0,0,0,62,0,3,0,58,0,0,0,57,0,0,0,65,0,5,0,59,0,0,0,60,0, -0,0,6,0,0,0,15,0,0,0,61,0,4,0,3,0,0,0,61,0,0,0,60,0,0,0,65,0,5,0, -16,0,0,0,62,0,0,0,39,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,63,0,0,0,62,0, -0,0,65,0,5,0,55,0,0,0,64,0,0,0,9,0,0,0,18,0,0,0,61,0,4,0,2,0,0,0, -65,0,0,0,64,0,0,0,129,0,5,0,2,0,0,0,66,0,0,0,63,0,0,0,65,0,0,0,145,0, -5,0,2,0,0,0,67,0,0,0,61,0,0,0,66,0,0,0,65,0,5,0,16,0,0,0,68,0,0,0, -38,0,0,0,20,0,0,0,62,0,3,0,68,0,0,0,67,0,0,0,61,0,4,0,33,0,0,0,69,0, -0,0,38,0,0,0,81,0,5,0,2,0,0,0,70,0,0,0,69,0,0,0,0,0,0,0,62,0,3,0, -29,0,0,0,70,0,0,0,81,0,5,0,21,0,0,0,71,0,0,0,69,0,0,0,1,0,0,0,62,0, -3,0,31,0,0,0,71,0,0,0,81,0,5,0,2,0,0,0,72,0,0,0,69,0,0,0,2,0,0,0, -62,0,3,0,32,0,0,0,72,0,0,0,253,0,1,0,56,0,1,0 +3,2,35,7,0,0,1,0,39,0,0,0,67,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0, +3,0,0,0,0,0,1,0,0,0,15,0,10,0,0,0,0,0,33,0,0,0,109,97,105,110,0,0,0,0, +13,0,0,0,19,0,0,0,25,0,0,0,27,0,0,0,28,0,0,0,3,0,3,0,0,0,0,0,100,0, +0,0,5,0,5,0,4,0,0,0,86,105,101,119,101,114,68,97,116,97,0,0,6,0,8,0,4,0,0,0, +0,0,0,0,112,114,111,106,101,99,116,105,111,110,95,109,97,116,114,105,120,0,0,0,5,0,5,0,7,0, +0,0,83,112,114,105,116,101,68,97,116,97,0,0,6,0,5,0,7,0,0,0,0,0,0,0,99,111,108,111, +114,0,0,0,6,0,6,0,7,0,0,0,1,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0,5,0, +4,0,22,0,0,0,86,101,114,116,73,110,0,0,6,0,4,0,22,0,0,0,0,0,0,0,112,111,115,0, +6,0,4,0,22,0,0,0,1,0,0,0,117,118,0,0,5,0,4,0,29,0,0,0,86,101,114,116,79,117, +116,0,6,0,5,0,29,0,0,0,0,0,0,0,99,111,108,111,114,0,0,0,6,0,4,0,29,0,0,0, +1,0,0,0,117,118,0,0,6,0,4,0,29,0,0,0,2,0,0,0,112,111,115,0,5,0,5,0,6,0, +0,0,118,105,101,119,101,114,95,100,97,116,97,0,5,0,4,0,9,0,0,0,109,111,100,101,108,0,0,0, +5,0,3,0,13,0,0,0,112,111,115,0,5,0,3,0,19,0,0,0,117,118,0,0,5,0,4,0,25,0, +0,0,99,111,108,111,114,0,0,0,5,0,3,0,27,0,0,0,117,118,0,0,5,0,5,0,28,0,0,0, +112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,33,0,0,0,109,97,105,110,0,0,0,0,71,0, +4,0,6,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,6,0,0,0,34,0,0,0,0,0,0,0, +71,0,4,0,28,0,0,0,11,0,0,0,0,0,0,0,71,0,4,0,13,0,0,0,30,0,0,0,0,0, +0,0,71,0,4,0,19,0,0,0,30,0,0,0,1,0,0,0,71,0,4,0,25,0,0,0,30,0,0,0, +0,0,0,0,71,0,4,0,27,0,0,0,30,0,0,0,1,0,0,0,71,0,3,0,4,0,0,0,2,0, +0,0,72,0,4,0,4,0,0,0,0,0,0,0,5,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0, +7,0,0,0,16,0,0,0,72,0,5,0,4,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,71,0, +3,0,7,0,0,0,2,0,0,0,72,0,5,0,7,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0, +72,0,5,0,7,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0,72,0,5,0,22,0,0,0,0,0, +0,0,35,0,0,0,0,0,0,0,72,0,5,0,22,0,0,0,1,0,0,0,35,0,0,0,16,0,0,0, +72,0,5,0,29,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0,29,0,0,0,1,0, +0,0,35,0,0,0,16,0,0,0,72,0,5,0,29,0,0,0,2,0,0,0,35,0,0,0,32,0,0,0, +22,0,3,0,1,0,0,0,32,0,0,0,23,0,4,0,2,0,0,0,1,0,0,0,4,0,0,0,24,0, +4,0,3,0,0,0,2,0,0,0,4,0,0,0,30,0,3,0,4,0,0,0,3,0,0,0,32,0,4,0, +5,0,0,0,2,0,0,0,4,0,0,0,30,0,4,0,7,0,0,0,2,0,0,0,2,0,0,0,32,0, +4,0,8,0,0,0,9,0,0,0,7,0,0,0,19,0,2,0,10,0,0,0,33,0,3,0,11,0,0,0, +10,0,0,0,32,0,4,0,12,0,0,0,1,0,0,0,2,0,0,0,21,0,4,0,14,0,0,0,32,0, +0,0,1,0,0,0,43,0,4,0,14,0,0,0,15,0,0,0,0,0,0,0,32,0,4,0,16,0,0,0, +7,0,0,0,2,0,0,0,23,0,4,0,17,0,0,0,1,0,0,0,2,0,0,0,32,0,4,0,18,0, +0,0,1,0,0,0,17,0,0,0,43,0,4,0,14,0,0,0,20,0,0,0,1,0,0,0,32,0,4,0, +21,0,0,0,7,0,0,0,17,0,0,0,30,0,4,0,22,0,0,0,2,0,0,0,17,0,0,0,32,0, +4,0,23,0,0,0,7,0,0,0,22,0,0,0,32,0,4,0,24,0,0,0,3,0,0,0,2,0,0,0, +32,0,4,0,26,0,0,0,3,0,0,0,17,0,0,0,30,0,5,0,29,0,0,0,2,0,0,0,17,0, +0,0,2,0,0,0,43,0,4,0,1,0,0,0,30,0,0,0,0,0,128,191,32,0,4,0,31,0,0,0, +7,0,0,0,29,0,0,0,43,0,4,0,14,0,0,0,32,0,0,0,2,0,0,0,32,0,4,0,44,0, +0,0,7,0,0,0,1,0,0,0,32,0,4,0,49,0,0,0,9,0,0,0,2,0,0,0,32,0,4,0, +53,0,0,0,2,0,0,0,3,0,0,0,59,0,4,0,5,0,0,0,6,0,0,0,2,0,0,0,59,0, +4,0,8,0,0,0,9,0,0,0,9,0,0,0,59,0,4,0,12,0,0,0,13,0,0,0,1,0,0,0, +59,0,4,0,18,0,0,0,19,0,0,0,1,0,0,0,59,0,4,0,24,0,0,0,25,0,0,0,3,0, +0,0,59,0,4,0,26,0,0,0,27,0,0,0,3,0,0,0,59,0,4,0,24,0,0,0,28,0,0,0, +3,0,0,0,54,0,5,0,10,0,0,0,33,0,0,0,0,0,0,0,11,0,0,0,248,0,2,0,34,0, +0,0,59,0,4,0,31,0,0,0,35,0,0,0,7,0,0,0,59,0,4,0,23,0,0,0,36,0,0,0, +7,0,0,0,65,0,5,0,16,0,0,0,37,0,0,0,36,0,0,0,15,0,0,0,63,0,3,0,37,0, +0,0,13,0,0,0,65,0,5,0,21,0,0,0,38,0,0,0,36,0,0,0,20,0,0,0,63,0,3,0, +38,0,0,0,19,0,0,0,65,0,5,0,21,0,0,0,39,0,0,0,36,0,0,0,20,0,0,0,61,0, +4,0,17,0,0,0,40,0,0,0,39,0,0,0,81,0,5,0,1,0,0,0,41,0,0,0,40,0,0,0, +0,0,0,0,133,0,5,0,1,0,0,0,42,0,0,0,41,0,0,0,30,0,0,0,65,0,5,0,21,0, +0,0,43,0,0,0,36,0,0,0,20,0,0,0,65,0,5,0,44,0,0,0,45,0,0,0,43,0,0,0, +15,0,0,0,62,0,3,0,45,0,0,0,42,0,0,0,65,0,5,0,21,0,0,0,46,0,0,0,36,0, +0,0,20,0,0,0,61,0,4,0,17,0,0,0,47,0,0,0,46,0,0,0,65,0,5,0,21,0,0,0, +48,0,0,0,35,0,0,0,20,0,0,0,62,0,3,0,48,0,0,0,47,0,0,0,65,0,5,0,49,0, +0,0,50,0,0,0,9,0,0,0,15,0,0,0,61,0,4,0,2,0,0,0,51,0,0,0,50,0,0,0, +65,0,5,0,16,0,0,0,52,0,0,0,35,0,0,0,15,0,0,0,62,0,3,0,52,0,0,0,51,0, +0,0,65,0,5,0,53,0,0,0,54,0,0,0,6,0,0,0,15,0,0,0,61,0,4,0,3,0,0,0, +55,0,0,0,54,0,0,0,65,0,5,0,16,0,0,0,56,0,0,0,36,0,0,0,15,0,0,0,61,0, +4,0,2,0,0,0,57,0,0,0,56,0,0,0,65,0,5,0,49,0,0,0,58,0,0,0,9,0,0,0, +20,0,0,0,61,0,4,0,2,0,0,0,59,0,0,0,58,0,0,0,129,0,5,0,2,0,0,0,60,0, +0,0,57,0,0,0,59,0,0,0,145,0,5,0,2,0,0,0,61,0,0,0,55,0,0,0,60,0,0,0, +65,0,5,0,16,0,0,0,62,0,0,0,35,0,0,0,32,0,0,0,62,0,3,0,62,0,0,0,61,0, +0,0,61,0,4,0,29,0,0,0,63,0,0,0,35,0,0,0,81,0,5,0,2,0,0,0,64,0,0,0, +63,0,0,0,0,0,0,0,62,0,3,0,25,0,0,0,64,0,0,0,81,0,5,0,17,0,0,0,65,0, +0,0,63,0,0,0,1,0,0,0,62,0,3,0,27,0,0,0,65,0,0,0,81,0,5,0,2,0,0,0, +66,0,0,0,63,0,0,0,2,0,0,0,62,0,3,0,28,0,0,0,66,0,0,0,253,0,1,0,56,0, +1,0 diff --git a/runtime/Includes/Embedded/ScreenFragment.spv.h b/runtime/Includes/Embedded/ScreenFragment.spv.h index ed5f334..727a9d3 100644 --- a/runtime/Includes/Embedded/ScreenFragment.spv.h +++ b/runtime/Includes/Embedded/ScreenFragment.spv.h @@ -1,49 +1,31 @@ -3,2,35,7,0,0,1,0,39,0,0,0,62,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,11,0, -6,0,32,0,0,0,71,76,83,76,46,115,116,100,46,52,53,48,0,0,0,0,14,0,3,0,0,0,0,0, -1,0,0,0,15,0,7,0,4,0,0,0,34,0,0,0,109,97,105,110,0,0,0,0,23,0,0,0,29,0, -0,0,16,0,3,0,34,0,0,0,7,0,0,0,3,0,3,0,0,0,0,0,100,0,0,0,5,0,4,0, -25,0,0,0,86,101,114,116,79,117,116,0,6,0,4,0,25,0,0,0,0,0,0,0,117,118,0,0,5,0, -4,0,30,0,0,0,70,114,97,103,79,117,116,0,6,0,5,0,30,0,0,0,0,0,0,0,99,111,108,111, -114,0,0,0,5,0,5,0,5,0,0,0,117,95,116,101,120,116,117,114,101,0,0,0,5,0,3,0,23,0, -0,0,117,118,0,0,5,0,4,0,29,0,0,0,99,111,108,111,114,0,0,0,5,0,6,0,33,0,0,0, -76,105,110,101,97,114,84,111,115,82,71,66,0,0,0,0,5,0,4,0,34,0,0,0,109,97,105,110,0,0, -0,0,71,0,4,0,5,0,0,0,33,0,0,0,0,0,0,0,71,0,4,0,5,0,0,0,34,0,0,0, -0,0,0,0,71,0,4,0,23,0,0,0,30,0,0,0,0,0,0,0,71,0,4,0,29,0,0,0,30,0, -0,0,0,0,0,0,72,0,5,0,25,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,72,0,5,0, -30,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,22,0,3,0,1,0,0,0,32,0,0,0,25,0, -9,0,2,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0, -0,0,0,0,27,0,3,0,3,0,0,0,2,0,0,0,32,0,4,0,4,0,0,0,0,0,0,0,3,0, -0,0,23,0,4,0,6,0,0,0,1,0,0,0,3,0,0,0,32,0,4,0,7,0,0,0,7,0,0,0, -6,0,0,0,33,0,4,0,8,0,0,0,6,0,0,0,7,0,0,0,43,0,4,0,1,0,0,0,9,0, -0,0,28,46,77,59,21,0,4,0,10,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,10,0,0,0, -11,0,0,0,0,0,0,0,20,0,2,0,12,0,0,0,23,0,4,0,13,0,0,0,12,0,0,0,3,0, -0,0,43,0,4,0,1,0,0,0,14,0,0,0,61,10,135,63,43,0,4,0,1,0,0,0,15,0,0,0, -0,0,128,63,43,0,4,0,1,0,0,0,16,0,0,0,154,153,25,64,43,0,4,0,1,0,0,0,17,0, -0,0,174,71,97,61,43,0,4,0,1,0,0,0,18,0,0,0,82,184,78,65,19,0,2,0,19,0,0,0, -33,0,3,0,20,0,0,0,19,0,0,0,23,0,4,0,21,0,0,0,1,0,0,0,2,0,0,0,32,0, -4,0,22,0,0,0,1,0,0,0,21,0,0,0,32,0,4,0,24,0,0,0,7,0,0,0,21,0,0,0, -30,0,3,0,25,0,0,0,21,0,0,0,32,0,4,0,26,0,0,0,7,0,0,0,25,0,0,0,23,0, -4,0,27,0,0,0,1,0,0,0,4,0,0,0,32,0,4,0,28,0,0,0,3,0,0,0,27,0,0,0, -30,0,3,0,30,0,0,0,27,0,0,0,32,0,4,0,31,0,0,0,7,0,0,0,30,0,0,0,32,0, -4,0,59,0,0,0,7,0,0,0,27,0,0,0,59,0,4,0,4,0,0,0,5,0,0,0,0,0,0,0, -59,0,4,0,22,0,0,0,23,0,0,0,1,0,0,0,59,0,4,0,28,0,0,0,29,0,0,0,3,0, -0,0,54,0,5,0,6,0,0,0,33,0,0,0,0,0,0,0,8,0,0,0,55,0,3,0,7,0,0,0, -35,0,0,0,248,0,2,0,36,0,0,0,61,0,4,0,6,0,0,0,37,0,0,0,35,0,0,0,80,0, -6,0,6,0,0,0,38,0,0,0,9,0,0,0,9,0,0,0,9,0,0,0,186,0,5,0,13,0,0,0, -39,0,0,0,37,0,0,0,38,0,0,0,61,0,4,0,6,0,0,0,40,0,0,0,35,0,0,0,136,0, -5,0,1,0,0,0,41,0,0,0,15,0,0,0,16,0,0,0,80,0,6,0,6,0,0,0,42,0,0,0, -41,0,0,0,41,0,0,0,41,0,0,0,12,0,7,0,6,0,0,0,43,0,0,0,32,0,0,0,26,0, -0,0,40,0,0,0,42,0,0,0,142,0,5,0,6,0,0,0,44,0,0,0,43,0,0,0,14,0,0,0, -80,0,6,0,6,0,0,0,45,0,0,0,17,0,0,0,17,0,0,0,17,0,0,0,131,0,5,0,6,0, -0,0,46,0,0,0,44,0,0,0,45,0,0,0,61,0,4,0,6,0,0,0,47,0,0,0,35,0,0,0, -142,0,5,0,6,0,0,0,48,0,0,0,47,0,0,0,18,0,0,0,169,0,6,0,6,0,0,0,49,0, -0,0,39,0,0,0,46,0,0,0,48,0,0,0,254,0,2,0,49,0,0,0,56,0,1,0,54,0,5,0, -19,0,0,0,34,0,0,0,0,0,0,0,20,0,0,0,248,0,2,0,50,0,0,0,59,0,4,0,31,0, -0,0,51,0,0,0,7,0,0,0,59,0,4,0,26,0,0,0,52,0,0,0,7,0,0,0,65,0,5,0, -24,0,0,0,53,0,0,0,52,0,0,0,11,0,0,0,63,0,3,0,53,0,0,0,23,0,0,0,61,0, -4,0,3,0,0,0,54,0,0,0,5,0,0,0,65,0,5,0,24,0,0,0,55,0,0,0,52,0,0,0, -11,0,0,0,61,0,4,0,21,0,0,0,56,0,0,0,55,0,0,0,87,0,5,0,27,0,0,0,57,0, -0,0,54,0,0,0,56,0,0,0,65,0,5,0,59,0,0,0,58,0,0,0,51,0,0,0,11,0,0,0, -62,0,3,0,58,0,0,0,57,0,0,0,61,0,4,0,30,0,0,0,60,0,0,0,51,0,0,0,81,0, -5,0,27,0,0,0,61,0,0,0,60,0,0,0,0,0,0,0,62,0,3,0,29,0,0,0,61,0,0,0, +3,2,35,7,0,0,1,0,39,0,0,0,34,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0, +3,0,0,0,0,0,1,0,0,0,15,0,7,0,4,0,0,0,21,0,0,0,109,97,105,110,0,0,0,0, +10,0,0,0,18,0,0,0,16,0,3,0,21,0,0,0,7,0,0,0,3,0,3,0,0,0,0,0,100,0, +0,0,5,0,4,0,14,0,0,0,86,101,114,116,79,117,116,0,6,0,4,0,14,0,0,0,0,0,0,0, +117,118,0,0,5,0,4,0,19,0,0,0,70,114,97,103,79,117,116,0,6,0,5,0,19,0,0,0,0,0, +0,0,99,111,108,111,114,0,0,0,5,0,5,0,5,0,0,0,117,95,116,101,120,116,117,114,101,0,0,0, +5,0,3,0,10,0,0,0,117,118,0,0,5,0,4,0,18,0,0,0,99,111,108,111,114,0,0,0,5,0, +4,0,21,0,0,0,109,97,105,110,0,0,0,0,71,0,4,0,5,0,0,0,33,0,0,0,0,0,0,0, +71,0,4,0,5,0,0,0,34,0,0,0,0,0,0,0,71,0,4,0,10,0,0,0,30,0,0,0,0,0, +0,0,71,0,4,0,18,0,0,0,30,0,0,0,0,0,0,0,72,0,5,0,14,0,0,0,0,0,0,0, +35,0,0,0,0,0,0,0,72,0,5,0,19,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0,22,0, +3,0,1,0,0,0,32,0,0,0,25,0,9,0,2,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0, +0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,27,0,3,0,3,0,0,0,2,0,0,0,32,0, +4,0,4,0,0,0,0,0,0,0,3,0,0,0,19,0,2,0,6,0,0,0,33,0,3,0,7,0,0,0, +6,0,0,0,23,0,4,0,8,0,0,0,1,0,0,0,2,0,0,0,32,0,4,0,9,0,0,0,1,0, +0,0,8,0,0,0,21,0,4,0,11,0,0,0,32,0,0,0,1,0,0,0,43,0,4,0,11,0,0,0, +12,0,0,0,0,0,0,0,32,0,4,0,13,0,0,0,7,0,0,0,8,0,0,0,30,0,3,0,14,0, +0,0,8,0,0,0,32,0,4,0,15,0,0,0,7,0,0,0,14,0,0,0,23,0,4,0,16,0,0,0, +1,0,0,0,4,0,0,0,32,0,4,0,17,0,0,0,3,0,0,0,16,0,0,0,30,0,3,0,19,0, +0,0,16,0,0,0,32,0,4,0,20,0,0,0,7,0,0,0,19,0,0,0,32,0,4,0,31,0,0,0, +7,0,0,0,16,0,0,0,59,0,4,0,4,0,0,0,5,0,0,0,0,0,0,0,59,0,4,0,9,0, +0,0,10,0,0,0,1,0,0,0,59,0,4,0,17,0,0,0,18,0,0,0,3,0,0,0,54,0,5,0, +6,0,0,0,21,0,0,0,0,0,0,0,7,0,0,0,248,0,2,0,22,0,0,0,59,0,4,0,20,0, +0,0,23,0,0,0,7,0,0,0,59,0,4,0,15,0,0,0,24,0,0,0,7,0,0,0,65,0,5,0, +13,0,0,0,25,0,0,0,24,0,0,0,12,0,0,0,63,0,3,0,25,0,0,0,10,0,0,0,61,0, +4,0,3,0,0,0,26,0,0,0,5,0,0,0,65,0,5,0,13,0,0,0,27,0,0,0,24,0,0,0, +12,0,0,0,61,0,4,0,8,0,0,0,28,0,0,0,27,0,0,0,87,0,5,0,16,0,0,0,29,0, +0,0,26,0,0,0,28,0,0,0,65,0,5,0,31,0,0,0,30,0,0,0,23,0,0,0,12,0,0,0, +62,0,3,0,30,0,0,0,29,0,0,0,61,0,4,0,19,0,0,0,32,0,0,0,23,0,0,0,81,0, +5,0,16,0,0,0,33,0,0,0,32,0,0,0,0,0,0,0,62,0,3,0,18,0,0,0,33,0,0,0, 253,0,1,0,56,0,1,0 diff --git a/runtime/Includes/Embedded/ScreenVertex.spv.h b/runtime/Includes/Embedded/ScreenVertex.spv.h index 3ba7900..e4e53d8 100644 --- a/runtime/Includes/Embedded/ScreenVertex.spv.h +++ b/runtime/Includes/Embedded/ScreenVertex.spv.h @@ -1,12 +1,12 @@ 3,2,35,7,0,0,1,0,39,0,0,0,59,0,0,0,0,0,0,0,17,0,2,0,1,0,0,0,14,0, -3,0,0,0,0,0,1,0,0,0,15,0,8,0,0,0,0,0,36,0,0,0,109,97,105,110,0,0,0,0, +3,0,0,0,0,0,1,0,0,0,15,0,8,0,0,0,0,0,37,0,0,0,109,97,105,110,0,0,0,0, 20,0,0,0,26,0,0,0,29,0,0,0,3,0,3,0,0,0,0,0,100,0,0,0,5,0,4,0,23,0, 0,0,86,101,114,116,73,110,0,0,6,0,6,0,23,0,0,0,0,0,0,0,118,101,114,116,95,105,110,100, 101,120,0,0,5,0,4,0,30,0,0,0,86,101,114,116,79,117,116,0,6,0,4,0,30,0,0,0,0,0, 0,0,117,118,0,0,6,0,6,0,30,0,0,0,1,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0, 5,0,5,0,15,0,0,0,118,101,114,116,105,99,101,115,0,0,0,0,5,0,6,0,20,0,0,0,118,101, 114,116,101,120,95,105,110,100,101,120,0,0,0,0,5,0,3,0,26,0,0,0,117,118,0,0,5,0,5,0, -29,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,36,0,0,0,109,97,105,110,0,0, +29,0,0,0,112,111,115,105,116,105,111,110,0,0,0,0,5,0,4,0,37,0,0,0,109,97,105,110,0,0, 0,0,71,0,4,0,20,0,0,0,11,0,0,0,42,0,0,0,71,0,4,0,29,0,0,0,11,0,0,0, 0,0,0,0,71,0,4,0,26,0,0,0,30,0,0,0,0,0,0,0,72,0,5,0,23,0,0,0,0,0, 0,0,35,0,0,0,0,0,0,0,72,0,5,0,30,0,0,0,0,0,0,0,35,0,0,0,0,0,0,0, @@ -27,22 +27,22 @@ 30,0,4,0,30,0,0,0,2,0,0,0,27,0,0,0,32,0,4,0,31,0,0,0,7,0,0,0,2,0, 0,0,32,0,4,0,32,0,0,0,7,0,0,0,30,0,0,0,43,0,4,0,18,0,0,0,33,0,0,0, 1,0,0,0,43,0,4,0,1,0,0,0,34,0,0,0,0,0,0,0,43,0,4,0,1,0,0,0,35,0, -0,0,0,0,0,63,32,0,4,0,44,0,0,0,6,0,0,0,2,0,0,0,32,0,4,0,50,0,0,0, -7,0,0,0,27,0,0,0,59,0,5,0,6,0,0,0,15,0,0,0,6,0,0,0,14,0,0,0,59,0, -4,0,19,0,0,0,20,0,0,0,1,0,0,0,59,0,4,0,25,0,0,0,26,0,0,0,3,0,0,0, -59,0,4,0,28,0,0,0,29,0,0,0,3,0,0,0,54,0,5,0,16,0,0,0,36,0,0,0,0,0, -0,0,17,0,0,0,248,0,2,0,37,0,0,0,59,0,4,0,31,0,0,0,38,0,0,0,7,0,0,0, -59,0,4,0,32,0,0,0,39,0,0,0,7,0,0,0,59,0,4,0,24,0,0,0,40,0,0,0,7,0, -0,0,65,0,5,0,22,0,0,0,41,0,0,0,40,0,0,0,21,0,0,0,63,0,3,0,41,0,0,0, -20,0,0,0,65,0,5,0,22,0,0,0,42,0,0,0,40,0,0,0,21,0,0,0,61,0,4,0,18,0, -0,0,43,0,0,0,42,0,0,0,65,0,5,0,44,0,0,0,45,0,0,0,15,0,0,0,43,0,0,0, -61,0,4,0,2,0,0,0,46,0,0,0,45,0,0,0,62,0,3,0,38,0,0,0,46,0,0,0,61,0, -4,0,2,0,0,0,47,0,0,0,38,0,0,0,80,0,6,0,27,0,0,0,48,0,0,0,47,0,0,0, -34,0,0,0,10,0,0,0,65,0,5,0,50,0,0,0,49,0,0,0,39,0,0,0,33,0,0,0,62,0, -3,0,49,0,0,0,48,0,0,0,61,0,4,0,2,0,0,0,51,0,0,0,38,0,0,0,142,0,5,0, -2,0,0,0,52,0,0,0,51,0,0,0,35,0,0,0,80,0,5,0,2,0,0,0,53,0,0,0,35,0, -0,0,35,0,0,0,129,0,5,0,2,0,0,0,54,0,0,0,52,0,0,0,53,0,0,0,65,0,5,0, -31,0,0,0,55,0,0,0,39,0,0,0,21,0,0,0,62,0,3,0,55,0,0,0,54,0,0,0,61,0, -4,0,30,0,0,0,56,0,0,0,39,0,0,0,81,0,5,0,2,0,0,0,57,0,0,0,56,0,0,0, +0,0,0,0,0,63,44,0,5,0,2,0,0,0,36,0,0,0,35,0,0,0,35,0,0,0,32,0,4,0, +45,0,0,0,6,0,0,0,2,0,0,0,32,0,4,0,51,0,0,0,7,0,0,0,27,0,0,0,59,0, +5,0,6,0,0,0,15,0,0,0,6,0,0,0,14,0,0,0,59,0,4,0,19,0,0,0,20,0,0,0, +1,0,0,0,59,0,4,0,25,0,0,0,26,0,0,0,3,0,0,0,59,0,4,0,28,0,0,0,29,0, +0,0,3,0,0,0,54,0,5,0,16,0,0,0,37,0,0,0,0,0,0,0,17,0,0,0,248,0,2,0, +38,0,0,0,59,0,4,0,31,0,0,0,39,0,0,0,7,0,0,0,59,0,4,0,32,0,0,0,40,0, +0,0,7,0,0,0,59,0,4,0,24,0,0,0,41,0,0,0,7,0,0,0,65,0,5,0,22,0,0,0, +42,0,0,0,41,0,0,0,21,0,0,0,63,0,3,0,42,0,0,0,20,0,0,0,65,0,5,0,22,0, +0,0,43,0,0,0,41,0,0,0,21,0,0,0,61,0,4,0,18,0,0,0,44,0,0,0,43,0,0,0, +65,0,5,0,45,0,0,0,46,0,0,0,15,0,0,0,44,0,0,0,61,0,4,0,2,0,0,0,47,0, +0,0,46,0,0,0,62,0,3,0,39,0,0,0,47,0,0,0,61,0,4,0,2,0,0,0,48,0,0,0, +39,0,0,0,80,0,6,0,27,0,0,0,49,0,0,0,48,0,0,0,34,0,0,0,10,0,0,0,65,0, +5,0,51,0,0,0,50,0,0,0,40,0,0,0,33,0,0,0,62,0,3,0,50,0,0,0,49,0,0,0, +61,0,4,0,2,0,0,0,52,0,0,0,39,0,0,0,142,0,5,0,2,0,0,0,53,0,0,0,52,0, +0,0,35,0,0,0,129,0,5,0,2,0,0,0,54,0,0,0,53,0,0,0,36,0,0,0,65,0,5,0, +31,0,0,0,55,0,0,0,40,0,0,0,21,0,0,0,62,0,3,0,55,0,0,0,54,0,0,0,61,0, +4,0,30,0,0,0,56,0,0,0,40,0,0,0,81,0,5,0,2,0,0,0,57,0,0,0,56,0,0,0, 0,0,0,0,62,0,3,0,26,0,0,0,57,0,0,0,81,0,5,0,27,0,0,0,58,0,0,0,56,0, 0,0,1,0,0,0,62,0,3,0,29,0,0,0,58,0,0,0,253,0,1,0,56,0,1,0 diff --git a/runtime/Includes/Graphics/Sprite.h b/runtime/Includes/Graphics/Sprite.h index 68a1bfb..3221852 100644 --- a/runtime/Includes/Graphics/Sprite.h +++ b/runtime/Includes/Graphics/Sprite.h @@ -14,15 +14,15 @@ namespace mlx friend class Render2DPass; public: - Sprite(NonOwningPtr texture); + Sprite(class Renderer& renderer, NonOwningPtr texture); inline void SetColor(Vec4f color) noexcept { m_color = color; } inline void SetPosition(Vec3f position) noexcept { m_position = position; } - [[nodiscard]] inline const Vec4f& GetColor() const noexcept { return m_color; } - [[nodiscard]] inline const Vec3f& GetPosition() const noexcept { return m_position; } - [[nodiscard]] inline std::shared_ptr GetMesh() const { return p_mesh; } - [[nodiscard]] inline NonOwningPtr GetTexture() const { return p_texture; } + [[nodiscard]] MLX_FORCEINLINE const Vec4f& GetColor() const noexcept { return m_color; } + [[nodiscard]] MLX_FORCEINLINE const Vec3f& GetPosition() const noexcept { return m_position; } + [[nodiscard]] MLX_FORCEINLINE std::shared_ptr GetMesh() const { return p_mesh; } + [[nodiscard]] MLX_FORCEINLINE NonOwningPtr GetTexture() const { return p_texture; } ~Sprite() = default; diff --git a/runtime/Includes/Renderer/Descriptor.h b/runtime/Includes/Renderer/Descriptor.h index ad37ae4..8689d3f 100644 --- a/runtime/Includes/Renderer/Descriptor.h +++ b/runtime/Includes/Renderer/Descriptor.h @@ -17,31 +17,69 @@ namespace mlx std::uint32_t binding; }; + class DescriptorPool + { + public: + DescriptorPool() = default; + + void Init() noexcept; + void Destroy() noexcept; + + VkDescriptorSet AllocateDescriptorSet(std::uint32_t frame_index, VkDescriptorSetLayout layout); + + void ResetPoolFromFrameIndex(std::size_t frame_index); + + [[nodiscard]] inline VkDescriptorPool Get(std::uint32_t index) const noexcept { return m_pools[index]; } + [[nodiscard]] MLX_FORCEINLINE std::size_t GetNumberOfSetsAllocated() const noexcept { return m_allocation_count; } + + ~DescriptorPool() = default; + + private: + std::array m_pools; + std::size_t m_allocation_count = 0; + }; + + class DescriptorPoolManager + { + public: + DescriptorPoolManager() = default; + + void ResetPoolsFromFrameIndex(std::size_t frame_index); + DescriptorPool& GetAvailablePool(); + void Destroy(); + + ~DescriptorPoolManager() = default; + + private: + std::list m_pools; + }; + class DescriptorSet { public: DescriptorSet() { m_set.fill(VK_NULL_HANDLE); } - DescriptorSet(const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type); + DescriptorSet(DescriptorPoolManager& pools_manager, const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type); void SetImage(std::size_t i, std::uint32_t binding, class Image& image); void SetStorageBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer); void SetUniformBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer); void Update(std::size_t i, VkCommandBuffer cmd = VK_NULL_HANDLE) noexcept; - void Reallocate() noexcept; + void Reallocate(std::size_t frame_index) noexcept; [[nodiscard]] inline VkDescriptorSet GetSet(std::size_t i) const noexcept { return m_set[i]; } - [[nodiscard]] inline DescriptorSet Duplicate() const { return DescriptorSet{ m_set_layout, m_descriptors }; } + [[nodiscard]] inline DescriptorSet Duplicate() const { return DescriptorSet{ *p_pools_manager, m_set_layout, m_descriptors }; } [[nodiscard]] inline bool IsInit() const noexcept { return m_set[0] != VK_NULL_HANDLE; } ~DescriptorSet() = default; private: - DescriptorSet(VkDescriptorSetLayout layout, const std::vector& descriptors); + DescriptorSet(DescriptorPoolManager& pools_manager, VkDescriptorSetLayout layout, const std::vector& descriptors); private: std::vector m_descriptors; std::array m_set; VkDescriptorSetLayout m_set_layout; + NonOwningPtr p_pools_manager; }; } diff --git a/runtime/Includes/Renderer/Image.h b/runtime/Includes/Renderer/Image.h index fe4768e..55840ed 100644 --- a/runtime/Includes/Renderer/Image.h +++ b/runtime/Includes/Renderer/Image.h @@ -76,7 +76,7 @@ namespace mlx MLX_PROFILE_FUNCTION(); std::vector candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT }; VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT); - Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, is_multisampled, std::move(debug_name)); + Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT, is_multisampled, std::move(debug_name)); Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT); Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); } diff --git a/runtime/Includes/Renderer/Pipelines/Graphics.h b/runtime/Includes/Renderer/Pipelines/Graphics.h index 46304bf..09aa939 100644 --- a/runtime/Includes/Renderer/Pipelines/Graphics.h +++ b/runtime/Includes/Renderer/Pipelines/Graphics.h @@ -24,7 +24,7 @@ namespace mlx public: GraphicPipeline() = default; - void Init(const GraphicPipelineDescriptor& descriptor); + void Init(const GraphicPipelineDescriptor& descriptor, std::string_view debug_name); bool BindPipeline(VkCommandBuffer command_buffer, std::size_t framebuffer_index, std::array clear) noexcept; void EndPipeline(VkCommandBuffer command_buffer) noexcept override; void Destroy() noexcept; @@ -46,6 +46,9 @@ namespace mlx std::vector> m_attachments; std::vector m_framebuffers; std::vector m_clears; + #ifdef DEBUG + std::string m_debug_name; + #endif std::shared_ptr p_vertex_shader; std::shared_ptr p_fragment_shader; VkRenderPass m_renderpass = VK_NULL_HANDLE; diff --git a/runtime/Includes/Renderer/RenderPasses/2DPass.h b/runtime/Includes/Renderer/RenderPasses/2DPass.h index eef1282..dc78aeb 100644 --- a/runtime/Includes/Renderer/RenderPasses/2DPass.h +++ b/runtime/Includes/Renderer/RenderPasses/2DPass.h @@ -11,7 +11,7 @@ namespace mlx { public: Render2DPass() = default; - void Init(); + void Init(class Renderer& renderer); void Pass(class Scene& scene, class Renderer& renderer, class Texture& render_target); void Destroy(); ~Render2DPass() = default; diff --git a/runtime/Includes/Renderer/RenderPasses/FinalPass.h b/runtime/Includes/Renderer/RenderPasses/FinalPass.h index 93a71cf..fe5571c 100644 --- a/runtime/Includes/Renderer/RenderPasses/FinalPass.h +++ b/runtime/Includes/Renderer/RenderPasses/FinalPass.h @@ -11,7 +11,7 @@ namespace mlx { public: FinalPass() = default; - void Init(); + void Init(class Renderer& renderer); void Pass(class Scene& scene, class Renderer& renderer, class Texture& render_target); void Destroy(); ~FinalPass() = default; diff --git a/runtime/Includes/Renderer/RenderPasses/Passes.h b/runtime/Includes/Renderer/RenderPasses/Passes.h index 7800912..3888a23 100644 --- a/runtime/Includes/Renderer/RenderPasses/Passes.h +++ b/runtime/Includes/Renderer/RenderPasses/Passes.h @@ -11,7 +11,7 @@ namespace mlx { public: RenderPasses() = default; - void Init(); + void Init(class Renderer& renderer); void Pass(class Scene& scene, class Renderer& renderer); void Destroy(); ~RenderPasses() = default; diff --git a/runtime/Includes/Renderer/Renderer.h b/runtime/Includes/Renderer/Renderer.h index a2df8cd..1bcba3a 100644 --- a/runtime/Includes/Renderer/Renderer.h +++ b/runtime/Includes/Renderer/Renderer.h @@ -5,6 +5,7 @@ #include #include #include +#include #include namespace mlx @@ -31,6 +32,7 @@ namespace mlx [[nodiscard]] inline std::size_t GetSwapchainImageIndex() const noexcept { return m_swapchain_image_index; } [[nodiscard]] inline std::size_t GetCurrentFrameIndex() const noexcept { return m_current_frame_index; } [[nodiscard]] inline NonOwningPtr GetWindow() const noexcept { return p_window; } + [[nodiscard]] inline DescriptorPoolManager& GetDescriptorPoolManager() noexcept { return m_descriptor_pool_manager; } MLX_FORCEINLINE constexpr void RequireFramebufferResize() noexcept { m_framebuffers_resize = true; } @@ -43,6 +45,7 @@ namespace mlx void DestroySwapchain(); private: + DescriptorPoolManager m_descriptor_pool_manager; std::array m_image_available_semaphores; std::array m_render_finished_semaphores; std::array m_cmd_buffers; diff --git a/runtime/Includes/Renderer/ScenesRenderer.h b/runtime/Includes/Renderer/ScenesRenderer.h index 03c391e..36dcdad 100644 --- a/runtime/Includes/Renderer/ScenesRenderer.h +++ b/runtime/Includes/Renderer/ScenesRenderer.h @@ -9,7 +9,7 @@ namespace mlx { public: SceneRenderer() = default; - void Init(); + void Init(class Renderer& renderer); void Render(class Scene& scene, class Renderer& renderer); // TODO : add RTT support void Destroy(); ~SceneRenderer() = default; diff --git a/runtime/Sources/Core/Graphics.cpp b/runtime/Sources/Core/Graphics.cpp index 7032816..184831b 100644 --- a/runtime/Sources/Core/Graphics.cpp +++ b/runtime/Sources/Core/Graphics.cpp @@ -12,7 +12,7 @@ namespace mlx MLX_PROFILE_FUNCTION(); // TODO : re-enable render targets m_renderer.Init(nullptr); - m_scene_renderer.Init(); + m_scene_renderer.Init(m_renderer); SceneDescriptor descriptor{}; descriptor.renderer = &m_renderer; @@ -27,7 +27,7 @@ namespace mlx { MLX_PROFILE_FUNCTION(); m_renderer.Init(p_window.get()); - m_scene_renderer.Init(); + m_scene_renderer.Init(m_renderer); SceneDescriptor descriptor{}; descriptor.renderer = &m_renderer; diff --git a/runtime/Sources/Graphics/Scene.cpp b/runtime/Sources/Graphics/Scene.cpp index dd48850..998ed64 100644 --- a/runtime/Sources/Graphics/Scene.cpp +++ b/runtime/Sources/Graphics/Scene.cpp @@ -16,7 +16,7 @@ namespace mlx Sprite& Scene::CreateSprite(NonOwningPtr texture) noexcept { MLX_PROFILE_FUNCTION(); - std::shared_ptr sprite = std::make_shared(texture); + std::shared_ptr sprite = std::make_shared(*m_descriptor.renderer, texture); m_sprites.push_back(sprite); return *sprite; } @@ -24,9 +24,9 @@ namespace mlx NonOwningPtr Scene::GetSpriteFromTextureAndPosition(NonOwningPtr texture, const Vec2f& position) const { MLX_PROFILE_FUNCTION(); - auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [texture, position](std::shared_ptr sprite) + auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture, &position](std::shared_ptr sprite) { - return sprite->GetPosition().x == position.x && sprite->GetPosition().y == position.y && sprite->GetTexture() == texture; + return sprite->GetTexture() == texture && sprite->GetPosition().x == position.x && sprite->GetPosition().y == position.y; }); return (it != m_sprites.end() ? it->get() : nullptr); } @@ -37,7 +37,7 @@ namespace mlx auto it = m_sprites.begin(); do { - it = std::find_if(m_sprites.begin(), m_sprites.end(), [texture](std::shared_ptr sprite) + it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture](std::shared_ptr sprite) { return sprite->GetTexture() == texture; }); diff --git a/runtime/Sources/Graphics/Sprite.cpp b/runtime/Sources/Graphics/Sprite.cpp index 533270b..a57d27a 100644 --- a/runtime/Sources/Graphics/Sprite.cpp +++ b/runtime/Sources/Graphics/Sprite.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace mlx { @@ -36,17 +37,17 @@ namespace mlx return mesh; } - Sprite::Sprite(NonOwningPtr texture) + Sprite::Sprite(Renderer& renderer, NonOwningPtr texture) { MLX_PROFILE_FUNCTION(); Verify((bool)texture, "Sprite: invalid texture"); p_mesh = CreateQuad(0, 0, texture->GetWidth(), texture->GetHeight()); p_texture = texture; - func::function functor = [this](const EventBase& event) + func::function functor = [this, &renderer](const EventBase& event) { if(event.What() == Event::DescriptorPoolResetEventCode) - m_set.Reallocate(); + m_set.Reallocate(renderer.GetCurrentFrameIndex()); }; EventBus::RegisterListener({ functor, "__Sprite" + std::to_string(reinterpret_cast(this)) }); } diff --git a/runtime/Sources/Renderer/Buffer.cpp b/runtime/Sources/Renderer/Buffer.cpp index 250bbd6..3e64d99 100644 --- a/runtime/Sources/Renderer/Buffer.cpp +++ b/runtime/Sources/Renderer/Buffer.cpp @@ -46,6 +46,7 @@ namespace mlx bufferInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE; #ifdef DEBUG + m_debug_name = debug_name; std::string alloc_name{ debug_name }; if(usage & VK_BUFFER_USAGE_INDEX_BUFFER_BIT) alloc_name.append("_index_buffer"); @@ -56,7 +57,6 @@ namespace mlx else alloc_name.append("_buffer"); m_allocation = RenderCore::Get().GetAllocator().CreateBuffer(&bufferInfo, &alloc_info, m_buffer, alloc_name.c_str()); - m_debug_name = std::move(alloc_name); #else m_allocation = RenderCore::Get().GetAllocator().CreateBuffer(&bufferInfo, &alloc_info, m_buffer, nullptr); #endif @@ -85,7 +85,6 @@ namespace mlx kvfEndCommandBuffer(cmd); VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice()); kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence); - kvfWaitForFence(RenderCore::Get().GetDevice(), fence); kvfDestroyFence(RenderCore::Get().GetDevice(), fence); return true; } diff --git a/runtime/Sources/Renderer/Descriptor.cpp b/runtime/Sources/Renderer/Descriptor.cpp index ac3b2ab..4e168a3 100644 --- a/runtime/Sources/Renderer/Descriptor.cpp +++ b/runtime/Sources/Renderer/Descriptor.cpp @@ -5,9 +5,12 @@ #include #include #include +#include namespace mlx { + constexpr std::size_t MAX_SETS_PER_POOL = MAX_FRAMES_IN_FLIGHT * 1024; + void TransitionImageToCorrectLayout(Image& image, VkCommandBuffer cmd) { MLX_PROFILE_FUNCTION(); @@ -19,8 +22,89 @@ namespace mlx Error("Vulkan : cannot transition descriptor image layout, unkown image type"); } - DescriptorSet::DescriptorSet(const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type) - : m_set_layout(vklayout) + void DescriptorPool::Init() noexcept + { + VkDescriptorPoolSize pool_sizes[] = { + { VK_DESCRIPTOR_TYPE_SAMPLER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, MAX_SETS_PER_POOL }, + { VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, MAX_SETS_PER_POOL } + }; + + VkDescriptorPoolCreateInfo poolInfo{}; + poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; + poolInfo.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]); + poolInfo.pPoolSizes = pool_sizes; + poolInfo.maxSets = MAX_SETS_PER_POOL; + poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; + for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) + kvfCheckVk(RenderCore::Get().vkCreateDescriptorPool(RenderCore::Get().GetDevice(), &poolInfo, nullptr, &m_pools[i])); + m_allocation_count = 0; + } + + void DescriptorPool::Destroy() noexcept + { + for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) + { + if(m_pools[i] == VK_NULL_HANDLE) + continue; + RenderCore::Get().vkDestroyDescriptorPool(RenderCore::Get().GetDevice(), m_pools[i], nullptr); + m_pools[i] = VK_NULL_HANDLE; + } + m_allocation_count = 0; + } + + VkDescriptorSet DescriptorPool::AllocateDescriptorSet(std::uint32_t frame_index, VkDescriptorSetLayout layout) + { + VkDescriptorSet set; + VkDescriptorSetAllocateInfo alloc_info = {}; + alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; + alloc_info.descriptorPool = m_pools[frame_index]; + alloc_info.descriptorSetCount = 1; + alloc_info.pSetLayouts = &layout; + kvfCheckVk(RenderCore::Get().vkAllocateDescriptorSets(RenderCore::Get().GetDevice(), &alloc_info, &set)); + m_allocation_count++; + return set; + } + + void DescriptorPool::ResetPoolFromFrameIndex(std::size_t frame_index) + { + Assert(frame_index < MAX_FRAMES_IN_FLIGHT, "invalid frame index"); + RenderCore::Get().vkResetDescriptorPool(RenderCore::Get().GetDevice(), m_pools[frame_index], 0); + } + + void DescriptorPoolManager::ResetPoolsFromFrameIndex(std::size_t frame_index) + { + for(auto& pool : m_pools) + pool.ResetPoolFromFrameIndex(frame_index); + } + + DescriptorPool& DescriptorPoolManager::GetAvailablePool() + { + for(auto& pool : m_pools) + { + if(pool.GetNumberOfSetsAllocated() < MAX_SETS_PER_POOL) + return pool; + } + m_pools.emplace_front().Init(); + return m_pools.front(); + } + + void DescriptorPoolManager::Destroy() + { + for(auto& pool : m_pools) + pool.Destroy(); + } + + DescriptorSet::DescriptorSet(DescriptorPoolManager& pools_manager, const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type) + : m_set_layout(vklayout), p_pools_manager(&pools_manager) { MLX_PROFILE_FUNCTION(); for(auto& [binding, type] : layout.binds) @@ -31,15 +115,15 @@ namespace mlx m_descriptors.back().binding = binding; } for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) - m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), vklayout); + m_set[i] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(i, vklayout); } - DescriptorSet::DescriptorSet(VkDescriptorSetLayout layout, const std::vector& descriptors) - : m_descriptors(descriptors), m_set_layout(layout) + DescriptorSet::DescriptorSet(DescriptorPoolManager& pools_manager, VkDescriptorSetLayout layout, const std::vector& descriptors) + : m_descriptors(descriptors), m_set_layout(layout), p_pools_manager(&pools_manager) { MLX_PROFILE_FUNCTION(); for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) - m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), layout); + m_set[i] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(i, layout); } void DescriptorSet::SetImage(std::size_t i, std::uint32_t binding, class Image& image) @@ -146,10 +230,9 @@ namespace mlx RenderCore::Get().vkUpdateDescriptorSets(RenderCore::Get().GetDevice(), writes.size(), writes.data(), 0, nullptr); } - void DescriptorSet::Reallocate() noexcept + void DescriptorSet::Reallocate(std::size_t frame_index) noexcept { MLX_PROFILE_FUNCTION(); - for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) - m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), m_set_layout); + m_set[frame_index] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(frame_index, m_set_layout); } } diff --git a/runtime/Sources/Renderer/Image.cpp b/runtime/Sources/Renderer/Image.cpp index d74c643..173523a 100644 --- a/runtime/Sources/Renderer/Image.cpp +++ b/runtime/Sources/Renderer/Image.cpp @@ -100,22 +100,21 @@ namespace mlx subresource_range.levelCount = 1; subresource_range.baseArrayLayer = 0; + VkImageLayout old_layout = m_layout; + TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd); if(m_type == ImageType::Color) { - VkImageLayout old_layout = m_layout; - TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd); subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; VkClearColorValue clear_color = VkClearColorValue({ { color.x, color.y, color.z, color.w } }); RenderCore::Get().vkCmdClearColorImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range); - TransitionLayout(old_layout, cmd); } else if(m_type == ImageType::Depth) { VkClearDepthStencilValue clear_depth_stencil = { 1.0f, 1 }; subresource_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; - TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd); RenderCore::Get().vkCmdClearDepthStencilImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_depth_stencil, 1, &subresource_range); } + TransitionLayout(old_layout, cmd); } void Image::DestroySampler() noexcept diff --git a/runtime/Sources/Renderer/Pipelines/Graphics.cpp b/runtime/Sources/Renderer/Pipelines/Graphics.cpp index a466786..267b061 100644 --- a/runtime/Sources/Renderer/Pipelines/Graphics.cpp +++ b/runtime/Sources/Renderer/Pipelines/Graphics.cpp @@ -1,3 +1,4 @@ +#include "vulkan/vulkan_core.h" #include #include #include @@ -7,7 +8,7 @@ namespace mlx { - void GraphicPipeline::Init(const GraphicPipelineDescriptor& descriptor) + void GraphicPipeline::Init(const GraphicPipelineDescriptor& descriptor, std::string_view debug_name) { MLX_PROFILE_FUNCTION(); if(!descriptor.vertex_shader || !descriptor.fragment_shader) @@ -19,6 +20,10 @@ namespace mlx p_renderer = descriptor.renderer; p_depth = descriptor.depth; + #ifdef DEBUG + m_debug_name = debug_name; + #endif + std::vector push_constants; std::vector set_layouts; push_constants.insert(push_constants.end(), p_vertex_shader->GetPipelineLayout().push_constants.begin(), p_vertex_shader->GetPipelineLayout().push_constants.end()); @@ -31,7 +36,7 @@ namespace mlx CreateFramebuffers(m_attachments, descriptor.clear_color_attachments); VkPhysicalDeviceFeatures features{}; - mlx::RenderCore::Get().vkGetPhysicalDeviceFeatures(RenderCore::Get().GetPhysicalDevice(), &features); + RenderCore::Get().vkGetPhysicalDeviceFeatures(RenderCore::Get().GetPhysicalDevice(), &features); KvfGraphicsPipelineBuilder* builder = kvfCreateGPipelineBuilder(); kvfGPipelineBuilderAddShaderStage(builder, p_vertex_shader->GetShaderStage(), p_vertex_shader->GetShaderModule(), "main"); @@ -59,6 +64,33 @@ namespace mlx m_pipeline = kvfCreateGraphicsPipeline(RenderCore::Get().GetDevice(), m_pipeline_layout, builder, m_renderpass); DebugLog("Vulkan : graphics pipeline created"); kvfDestroyGPipelineBuilder(builder); + + #ifdef MLX_HAS_DEBUG_UTILS_FUNCTIONS + VkDebugUtilsObjectNameInfoEXT name_info{}; + name_info.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT; + name_info.objectType = VK_OBJECT_TYPE_PIPELINE; + name_info.objectHandle = reinterpret_cast(m_pipeline); + name_info.pObjectName = m_debug_name.c_str(); + RenderCore::Get().vkSetDebugUtilsObjectNameEXT(RenderCore::Get().GetDevice(), &name_info); + + name_info.objectType = VK_OBJECT_TYPE_RENDER_PASS; + name_info.objectHandle = reinterpret_cast(m_renderpass); + RenderCore::Get().vkSetDebugUtilsObjectNameEXT(RenderCore::Get().GetDevice(), &name_info); + + name_info.objectType = VK_OBJECT_TYPE_SHADER_MODULE; + name_info.objectHandle = reinterpret_cast(p_vertex_shader->GetShaderModule()); + RenderCore::Get().vkSetDebugUtilsObjectNameEXT(RenderCore::Get().GetDevice(), &name_info); + + name_info.objectHandle = reinterpret_cast(p_fragment_shader->GetShaderModule()); + RenderCore::Get().vkSetDebugUtilsObjectNameEXT(RenderCore::Get().GetDevice(), &name_info); + + name_info.objectType = VK_OBJECT_TYPE_FRAMEBUFFER; + for(VkFramebuffer fb : m_framebuffers) + { + name_info.objectHandle = reinterpret_cast(fb); + RenderCore::Get().vkSetDebugUtilsObjectNameEXT(RenderCore::Get().GetDevice(), &name_info); + } + #endif } bool GraphicPipeline::BindPipeline(VkCommandBuffer command_buffer, std::size_t framebuffer_index, std::array clear) noexcept diff --git a/runtime/Sources/Renderer/RenderPasses/2DPass.cpp b/runtime/Sources/Renderer/RenderPasses/2DPass.cpp index a93a2e7..f17b915 100644 --- a/runtime/Sources/Renderer/RenderPasses/2DPass.cpp +++ b/runtime/Sources/Renderer/RenderPasses/2DPass.cpp @@ -14,7 +14,7 @@ namespace mlx Vec4f position; }; - void Render2DPass::Init() + void Render2DPass::Init(Renderer& renderer) { MLX_PROFILE_FUNCTION(); ShaderLayout vertex_shader_layout( @@ -44,25 +44,24 @@ namespace mlx }; p_fragment_shader = std::make_shared(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout)); - func::function functor = [this](const EventBase& event) + + func::function functor = [this, &renderer](const EventBase& event) { if(event.What() == Event::ResizeEventCode) m_pipeline.Destroy(); if(event.What() == Event::DescriptorPoolResetEventCode) { - p_texture_set->Reallocate(); - p_viewer_data_set->Reallocate(); - for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++) - { - p_viewer_data_set->SetUniformBuffer(i, 0, p_viewer_data_buffer->Get(i)); - p_viewer_data_set->Update(i); - } + std::uint32_t frame_index = renderer.GetCurrentFrameIndex(); + p_texture_set->Reallocate(frame_index); + p_viewer_data_set->Reallocate(frame_index); + p_viewer_data_set->SetUniformBuffer(frame_index, 0, p_viewer_data_buffer->Get(frame_index)); + p_viewer_data_set->Update(frame_index); } }; EventBus::RegisterListener({ functor, "__MlxRender2DPass" }); - p_viewer_data_set = std::make_shared(p_vertex_shader->GetShaderLayout().set_layouts[0].second, p_vertex_shader->GetPipelineLayout().set_layouts[0], ShaderType::Vertex); - p_texture_set = std::make_shared(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment); + p_viewer_data_set = std::make_shared(renderer.GetDescriptorPoolManager(), p_vertex_shader->GetShaderLayout().set_layouts[0].second, p_vertex_shader->GetPipelineLayout().set_layouts[0], ShaderType::Vertex); + p_texture_set = std::make_shared(renderer.GetDescriptorPoolManager(), p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment); p_viewer_data_buffer = std::make_shared(); p_viewer_data_buffer->Init(sizeof(ViewerData), "mlx_2d_pass_viewer_data"); @@ -84,13 +83,17 @@ namespace mlx pipeline_descriptor.color_attachments = { &render_target }; pipeline_descriptor.depth = &scene.GetDepth(); pipeline_descriptor.clear_color_attachments = false; - m_pipeline.Init(pipeline_descriptor); + #ifdef DEBUG + m_pipeline.Init(pipeline_descriptor, "mlx_2D_pass"); + #else + m_pipeline.Init(pipeline_descriptor, {}); + #endif } std::uint32_t frame_index = renderer.GetCurrentFrameIndex(); ViewerData viewer_data; - viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f); + viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), 0.0f, render_target.GetHeight(), -1.0f, 100'000.0f); static CPUBuffer buffer(sizeof(ViewerData)); std::memcpy(buffer.GetData(), &viewer_data, buffer.GetSize()); p_viewer_data_buffer->SetData(buffer, frame_index); @@ -108,8 +111,8 @@ namespace mlx sprite->GetTexture()->Update(cmd); sprite->Bind(frame_index, cmd); std::array sets = { p_viewer_data_set->GetSet(frame_index), sprite->GetSet(frame_index) }; - mlx::RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr); - mlx::RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &sprite_data); + RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr); + RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &sprite_data); sprite->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef()); } m_pipeline.EndPipeline(cmd); diff --git a/runtime/Sources/Renderer/RenderPasses/FinalPass.cpp b/runtime/Sources/Renderer/RenderPasses/FinalPass.cpp index b292109..a0b42af 100644 --- a/runtime/Sources/Renderer/RenderPasses/FinalPass.cpp +++ b/runtime/Sources/Renderer/RenderPasses/FinalPass.cpp @@ -7,7 +7,7 @@ namespace mlx { - void FinalPass::Init() + void FinalPass::Init(Renderer& renderer) { MLX_PROFILE_FUNCTION(); ShaderLayout vertex_shader_layout( @@ -31,16 +31,16 @@ namespace mlx }; p_fragment_shader = std::make_shared(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout)); - func::function functor = [this](const EventBase& event) + func::function functor = [this, &renderer](const EventBase& event) { if(event.What() == Event::ResizeEventCode) m_pipeline.Destroy(); if(event.What() == Event::DescriptorPoolResetEventCode) - p_set->Reallocate(); + p_set->Reallocate(renderer.GetCurrentFrameIndex()); }; EventBus::RegisterListener({ functor, "__MlxFinalPass" }); - p_set = std::make_shared(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment); + p_set = std::make_shared(renderer.GetDescriptorPoolManager(), p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment); } void FinalPass::Pass([[maybe_unused]] Scene& scene, Renderer& renderer, Texture& render_target) @@ -53,7 +53,11 @@ namespace mlx pipeline_descriptor.fragment_shader = p_fragment_shader; pipeline_descriptor.renderer = &renderer; pipeline_descriptor.no_vertex_inputs = true; - m_pipeline.Init(pipeline_descriptor); + #ifdef DEBUG + m_pipeline.Init(pipeline_descriptor, "mlx_final_pass"); + #else + m_pipeline.Init(pipeline_descriptor, {}); + #endif } VkCommandBuffer cmd = renderer.GetActiveCommandBuffer(); diff --git a/runtime/Sources/Renderer/RenderPasses/Passes.cpp b/runtime/Sources/Renderer/RenderPasses/Passes.cpp index 0a4b2bc..b23ebc8 100644 --- a/runtime/Sources/Renderer/RenderPasses/Passes.cpp +++ b/runtime/Sources/Renderer/RenderPasses/Passes.cpp @@ -5,39 +5,37 @@ namespace mlx { - void RenderPasses::Init() + void RenderPasses::Init(Renderer& renderer) { - m_2Dpass.Init(); - m_final.Init(); + m_2Dpass.Init(renderer); + m_final.Init(renderer); + func::function functor = [this, renderer](const EventBase& event) + { + if(event.What() == Event::ResizeEventCode) + { + m_main_render_texture.Destroy(); + auto extent = kvfGetSwapchainImagesSize(renderer.GetSwapchain()); + #ifdef DEBUG + m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_renderpasses_target"); + #else + m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, {}); + #endif + m_main_render_texture.TransitionLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + } + }; + EventBus::RegisterListener({ functor, "__MlxRenderPasses" }); + auto extent = kvfGetSwapchainImagesSize(renderer.GetSwapchain()); + + #ifdef DEBUG + m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_renderpasses_target"); + #else + m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, {}); + #endif + m_main_render_texture.TransitionLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); } void RenderPasses::Pass(Scene& scene, Renderer& renderer) { - if(!m_main_render_texture.IsInit()) - { - func::function functor = [this, renderer](const EventBase& event) - { - if(event.What() == Event::ResizeEventCode) - { - m_main_render_texture.Destroy(); - auto extent = kvfGetSwapchainImagesSize(renderer.GetSwapchain()); - #ifdef DEBUG - m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_renderpasses_target"); - #else - m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, {}); - #endif - } - }; - EventBus::RegisterListener({ functor, "__MlxRenderPasses" }); - auto extent = kvfGetSwapchainImagesSize(renderer.GetSwapchain()); - - #ifdef DEBUG - m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, "mlx_renderpasses_target"); - #else - m_main_render_texture.Init({}, extent.width, extent.height, VK_FORMAT_R8G8B8A8_SRGB, false, {}); - #endif - } - m_main_render_texture.Clear(renderer.GetActiveCommandBuffer(), Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f }); scene.GetDepth().Clear(renderer.GetActiveCommandBuffer(), {}); diff --git a/runtime/Sources/Renderer/Renderer.cpp b/runtime/Sources/Renderer/Renderer.cpp index a7f3fcf..d1a4f07 100644 --- a/runtime/Sources/Renderer/Renderer.cpp +++ b/runtime/Sources/Renderer/Renderer.cpp @@ -59,6 +59,13 @@ namespace mlx { MLX_PROFILE_FUNCTION(); kvfWaitForFence(RenderCore::Get().GetDevice(), m_cmd_fences[m_current_frame_index]); + static bool first_run = true; + if(!first_run) + { + m_descriptor_pool_manager.ResetPoolsFromFrameIndex(m_current_frame_index); + EventBus::SendBroadcast(Internal::DescriptorPoolResetEventBroadcast{}); + } + first_run = false; VkResult result = RenderCore::Get().vkAcquireNextImageKHR(RenderCore::Get().GetDevice(), m_swapchain, UINT64_MAX, m_image_available_semaphores[m_current_frame_index], VK_NULL_HANDLE, &m_swapchain_image_index); if(result == VK_ERROR_OUT_OF_DATE_KHR) { @@ -92,8 +99,6 @@ namespace mlx EventBus::SendBroadcast(Internal::ResizeEventBroadcast{}); } m_current_frame_index = (m_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT; - kvfResetDeviceDescriptorPools(RenderCore::Get().GetDevice()); - EventBus::SendBroadcast(Internal::DescriptorPoolResetEventBroadcast{}); } void Renderer::CreateSwapchain() @@ -145,6 +150,7 @@ namespace mlx DebugLog("Vulkan : fence destroyed"); } + m_descriptor_pool_manager.Destroy(); DestroySwapchain(); RenderCore::Get().vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr); DebugLog("Vulkan : surface destroyed"); diff --git a/runtime/Sources/Renderer/SceneRenderer.cpp b/runtime/Sources/Renderer/SceneRenderer.cpp index 09903cb..c1939fd 100644 --- a/runtime/Sources/Renderer/SceneRenderer.cpp +++ b/runtime/Sources/Renderer/SceneRenderer.cpp @@ -6,10 +6,10 @@ namespace mlx { - void SceneRenderer::Init() + void SceneRenderer::Init(Renderer& renderer) { MLX_PROFILE_FUNCTION(); - m_passes.Init(); + m_passes.Init(renderer); } void SceneRenderer::Render(Scene& scene, Renderer& renderer) diff --git a/third_party/kvf.h b/third_party/kvf.h index 164466e..8256b24 100755 --- a/third_party/kvf.h +++ b/third_party/kvf.h @@ -2415,7 +2415,7 @@ void kvfSubmitSingleTimeCommandBuffer(VkDevice device, VkCommandBuffer buffer, K submit_info.pCommandBuffers = &buffer; __kvfCheckVk(KVF_GET_DEVICE_FUNCTION(vkQueueSubmit)(kvfGetDeviceQueue(device, queue), 1, &submit_info, fence)); if(fence != VK_NULL_HANDLE) - KVF_GET_DEVICE_FUNCTION(vkWaitForFences)(device, 1, &fence, VK_TRUE, UINT64_MAX); + kvfWaitForFence(device, fence); } VkAttachmentDescription kvfBuildAttachmentDescription(KvfImageType type, VkFormat format, VkImageLayout initial, VkImageLayout final, bool clear, VkSampleCountFlagBits samples)