mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
fixing compilation issues
This commit is contained in:
116
Makefile
116
Makefile
@@ -1,102 +1,120 @@
|
|||||||
NAME = libmlx.so
|
NAME = libmlx.so
|
||||||
|
MAKE = make --no-print-directory
|
||||||
|
|
||||||
SRCS = $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Core))
|
OS ?= $(shell uname -s)
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Platform))
|
|
||||||
SRCS += $(wildcard $(addsuffix /*.cpp, ./runtime/Sources/Graphics))
|
|
||||||
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/makefile
|
|
||||||
OBJS = $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
|
|
||||||
|
|
||||||
PCH = ./runtime/Includes/PreCompiled.h
|
|
||||||
GCH = ./runtime/Includes/PreCompiled.h.gch
|
|
||||||
|
|
||||||
OS = $(shell uname -s)
|
|
||||||
DEBUG ?= false
|
DEBUG ?= false
|
||||||
TOOLCHAIN ?= clang
|
TOOLCHAIN ?= clang
|
||||||
IMAGES_OPTIMIZED ?= true
|
IMAGES_OPTIMIZED ?= true
|
||||||
FORCE_INTEGRATED_GPU ?= false
|
FORCE_INTEGRATED_GPU ?= false
|
||||||
GRAPHICS_MEMORY_DUMP ?= false
|
GRAPHICS_MEMORY_DUMP ?= false
|
||||||
PROFILER ?= false
|
PROFILER ?= false
|
||||||
FORCE_WAYLAND ?= false
|
_ENABLEDFLAGS =
|
||||||
|
|
||||||
MODE = "release"
|
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/**))
|
||||||
|
|
||||||
|
OBJ_DIR = objs/make/$(shell echo $(OS) | tr '[:upper:]' '[:lower:]')
|
||||||
|
OBJS := $(addprefix $(OBJ_DIR)/, $(SRCS:.cpp=.o))
|
||||||
|
|
||||||
CXX = clang++
|
CXX = clang++
|
||||||
|
CXXFLAGS = -std=c++20 -O3 -fPIC -Wall -Wextra -DSDL_MAIN_HANDLED
|
||||||
CXXFLAGS = -std=c++20 -O3 -fPIC -Wall -Wextra -Wno-deprecated -DSDL_MAIN_HANDLED
|
|
||||||
INCLUDES = -I./includes -I./runtime/Includes -I./runtime/Sources -I./third_party
|
INCLUDES = -I./includes -I./runtime/Includes -I./runtime/Sources -I./third_party
|
||||||
|
|
||||||
LDLIBS =
|
|
||||||
|
|
||||||
ifeq ($(TOOLCHAIN), gcc)
|
ifeq ($(TOOLCHAIN), gcc)
|
||||||
CXX = g++
|
CXX = g++
|
||||||
|
CXXFLAGS += -Wno-error=cpp
|
||||||
|
else
|
||||||
|
CXXFLAGS += -Wno-error=#warning
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(OS), Darwin)
|
ifeq ($(OS), Darwin)
|
||||||
LDLIBS += -L /opt/homebrew/lib -lSDL2
|
LDFLAGS += -L /opt/homebrew/lib -lSDL2
|
||||||
CXXFLAGS += -I /opt/homebrew/include
|
CXXFLAGS += -I /opt/homebrew/include
|
||||||
NAME = libmlx.dylib
|
NAME = libmlx.dylib
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(DEBUG), true)
|
ifeq ($(DEBUG), true)
|
||||||
CXXFLAGS += -g -D DEBUG
|
CXXFLAGS += -g3 -D DEBUG
|
||||||
MODE = "debug"
|
LDFLAGS += -rdynamic
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(FORCE_INTEGRATED_GPU), true)
|
ifeq ($(FORCE_INTEGRATED_GPU), true)
|
||||||
CXXFLAGS += -D FORCE_INTEGRATED_GPU
|
_ENABLEDFLAGS += FORCE_INTEGRATED_GPU
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(IMAGES_OPTIMIZED), true)
|
ifeq ($(IMAGES_OPTIMIZED), true)
|
||||||
CXXFLAGS += -D IMAGE_OPTIMIZED
|
_ENABLEDFLAGS += IMAGE_OPTIMIZED
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GRAPHICS_MEMORY_DUMP), true)
|
ifeq ($(GRAPHICS_MEMORY_DUMP), true)
|
||||||
CXXFLAGS += -D GRAPHICS_MEMORY_DUMP
|
_ENABLEDFLAGS += GRAPHICS_MEMORY_DUMP
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(PROFILER), true)
|
ifeq ($(PROFILER), true)
|
||||||
CXXFLAGS += -D PROFILER
|
_ENABLEDFLAGS += PROFILER
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(FORCE_WAYLAND), true)
|
CXXFLAGS += $(addprefix -D, $(_ENABLEDFLAGS))
|
||||||
CXXFLAGS += -D FORCE_WAYLAND
|
|
||||||
endif
|
|
||||||
|
|
||||||
RM = rm -rf
|
RM = rm -rf
|
||||||
|
|
||||||
$(OBJ_DIR)/%.o: %.cpp $(GCH)
|
TPUT = tput -T xterm-256color
|
||||||
@printf "\033[1;32m[compiling... "$(MODE)" "$(CXX)"]\033[1;00m "$<"\n"
|
_RESET := $(shell $(TPUT) sgr0)
|
||||||
|
_BOLD := $(shell $(TPUT) bold)
|
||||||
|
_ITALIC := $(shell $(TPUT) sitm)
|
||||||
|
_UNDER := $(shell $(TPUT) smul)
|
||||||
|
_GREEN := $(shell $(TPUT) setaf 2)
|
||||||
|
_YELLOW := $(shell $(TPUT) setaf 3)
|
||||||
|
_RED := $(shell $(TPUT) setaf 1)
|
||||||
|
_GRAY := $(shell $(TPUT) setaf 8)
|
||||||
|
_PURPLE := $(shell $(TPUT) setaf 5)
|
||||||
|
|
||||||
|
ifeq ($(DEBUG), true)
|
||||||
|
MODE := $(_RESET)$(_PURPLE)$(_BOLD)Debug$(_RESET)$(_PURPLE)
|
||||||
|
COLOR := $(_PURPLE)
|
||||||
|
else
|
||||||
|
MODE := $(_RESET)$(_GREEN)$(_BOLD)Release$(_RESET)$(_GREEN)
|
||||||
|
COLOR := $(_GREEN)
|
||||||
|
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) )))
|
||||||
|
CURR_OBJ = 0
|
||||||
|
|
||||||
|
$(OBJ_DIR)/%.o: %.cpp
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
@$(eval CURR_OBJ=$(shell echo $$(( $(CURR_OBJ) + 1 ))))
|
||||||
|
@$(eval PERCENT=$(shell echo $$(( $(CURR_OBJ) * 100 / $(OBJS_TOTAL) ))))
|
||||||
|
@printf "$(COLOR)($(_BOLD)%3s%%$(_RESET)$(COLOR)) $(_RESET)Compiling $(_BOLD)$<$(_RESET)\n" "$(PERCENT)"
|
||||||
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
|
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
|
||||||
|
|
||||||
all: $(NAME)
|
all: _printbuildinfos
|
||||||
|
@$(MAKE) $(NAME)
|
||||||
|
|
||||||
$(GCH):
|
$(NAME): $(OBJS)
|
||||||
@printf "\033[1;32m[compiling... "$(MODE)" "$(CXX)"]\033[1;00m PreCompiled header\n"
|
@printf "Linking $(_BOLD)$(NAME)$(_RESET)\n"
|
||||||
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $(PCH) -o $(GCH)
|
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDFLAGS)
|
||||||
|
@printf "$(_BOLD)$(NAME)$(_RESET) compiled $(COLOR)$(_BOLD)successfully$(_RESET)\n"
|
||||||
|
|
||||||
$(NAME): $(OBJ_DIR) $(GCH) $(OBJS)
|
_printbuildinfos:
|
||||||
@printf "\033[1;32m[linking ... "$(MODE)"]\033[1;00m "$@"\n"
|
@printf "$(_PURPLE)$(_BOLD)MacroLibX $(_RESET)Compiling in $(_BOLD)$(MODE)$(_RESET) mode on $(_BOLD)$(OS)$(_RESET) | Using $(_BOLD)$(CXX)$(_RESET), flags: $(_BOLD)$(_ENABLEDFLAGS)$(_RESET)\n"
|
||||||
@$(CXX) -shared -o $(NAME) $(OBJS) $(LDLIBS)
|
|
||||||
@printf "\033[1;32m[build finished]\033[1;00m\n"
|
|
||||||
|
|
||||||
$(OBJ_DIR):
|
debug:
|
||||||
@mkdir -p $(sort $(addprefix $(OBJ_DIR)/, $(dir $(SRCS))))
|
@$(MAKE) all DEBUG=true -j$(shell nproc)
|
||||||
@printf "\033[1;32m[created objs directory]\033[1;00m\n"
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@$(RM) $(OBJ_DIR)
|
@$(RM) $(OBJ_DIR)
|
||||||
@printf "\033[1;32m[object files removed]\033[1;00m\n"
|
@printf "Cleaned $(_BOLD)$(OBJ_DIR)$(_RESET)\n"
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
@$(RM) $(NAME)
|
@$(RM) $(NAME)
|
||||||
@$(RM) $(GCH)
|
@printf "Cleaned $(_BOLD)$(NAME)$(_RESET)\n"
|
||||||
@printf "\033[1;32m["$(NAME)" and gch removed]\033[1;00m\n"
|
|
||||||
|
|
||||||
re: fclean all
|
re: fclean _printbuildinfos
|
||||||
|
@$(MAKE) $(NAME)
|
||||||
|
|
||||||
.PHONY: all clean fclean re pch
|
.PHONY: all clean debug fclean re
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -5,8 +5,8 @@ if [ -e a.out ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $(uname -s) = 'Darwin' ]; then
|
if [ $(uname -s) = 'Darwin' ]; then
|
||||||
clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lglfw -g;
|
clang main.c ../libmlx.dylib -L /opt/homebrew/lib -lSDL2 -g;
|
||||||
else
|
else
|
||||||
clang main.c ../libmlx.so -lglfw -g -Wall -Wextra -Werror;
|
clang main.c ../libmlx.so -lSDL2 -g -Wall -Wextra -Werror;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ namespace mlx
|
|||||||
|
|
||||||
inline void SetEventCallback(func::function<void(mlx_event_type, int, int, void*)> functor, void* userdata) { f_callback = std::move(functor); p_callback_data = userdata; }
|
inline void SetEventCallback(func::function<void(mlx_event_type, int, int, void*)> functor, void* userdata) { f_callback = std::move(functor); p_callback_data = userdata; }
|
||||||
|
|
||||||
|
std::int32_t GetX() const noexcept;
|
||||||
|
std::int32_t GetY() const noexcept;
|
||||||
|
std::int32_t GetXRel() const noexcept;
|
||||||
|
std::int32_t GetYRel() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
SDLManager() = default;
|
SDLManager() = default;
|
||||||
~SDLManager() = default;
|
~SDLManager() = default;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace mlx
|
|||||||
public:
|
public:
|
||||||
Inputs();
|
Inputs();
|
||||||
|
|
||||||
void RegisterWindow(std::shared_ptr<Window> window);
|
inline void RegisterWindow(std::shared_ptr<Window> window) { m_windows[window->GetID()] = window; }
|
||||||
|
|
||||||
std::int32_t GetX() const noexcept;
|
std::int32_t GetX() const noexcept;
|
||||||
std::int32_t GetY() const noexcept;
|
std::int32_t GetY() const noexcept;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <SDL2/SDL_vulkan.h>
|
#include <SDL2/SDL_vulkan.h>
|
||||||
|
|
||||||
|
#include <Renderer/Vulkan/VulkanPrototypes.h>
|
||||||
#include <kvf.h>
|
#include <kvf.h>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -71,7 +72,6 @@
|
|||||||
#include <Core/EventBus.h>
|
#include <Core/EventBus.h>
|
||||||
#include <Core/Profiler.h>
|
#include <Core/Profiler.h>
|
||||||
#include <Utils/NonOwningPtr.h>
|
#include <Utils/NonOwningPtr.h>
|
||||||
#include <Renderer/Vulkan/VulkanPrototypes.h>
|
|
||||||
|
|
||||||
using Handle = void*;
|
using Handle = void*;
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ namespace mlx
|
|||||||
void SetPixel(int x, int y, std::uint32_t color) noexcept;
|
void SetPixel(int x, int y, std::uint32_t color) noexcept;
|
||||||
int GetPixel(int x, int y) noexcept;
|
int GetPixel(int x, int y) noexcept;
|
||||||
|
|
||||||
void Update(VkCommandBuffer cmd) const;
|
void Update(VkCommandBuffer cmd);
|
||||||
|
|
||||||
~Texture() override { Destroy(); }
|
~Texture() override { Destroy(); }
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace mlx
|
|||||||
[[nodiscard]] MLX_FORCEINLINE VkPhysicalDevice GetPhysicalDevice() const noexcept { return m_physical_device; }
|
[[nodiscard]] MLX_FORCEINLINE VkPhysicalDevice GetPhysicalDevice() const noexcept { return m_physical_device; }
|
||||||
[[nodiscard]] MLX_FORCEINLINE GPUAllocator& GetAllocator() noexcept { return m_allocator; }
|
[[nodiscard]] MLX_FORCEINLINE GPUAllocator& GetAllocator() noexcept { return m_allocator; }
|
||||||
|
|
||||||
|
|
||||||
inline void WaitDeviceIdle() const noexcept { vkDeviceWaitIdle(m_device); }
|
inline void WaitDeviceIdle() const noexcept { vkDeviceWaitIdle(m_device); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#ifndef __SCOP_VK_PROTOTYPES__
|
#ifndef __MLX_VK_PROTOTYPES__
|
||||||
#define __SCOP_VK_PROTOTYPES__
|
#define __MLX_VK_PROTOTYPES__
|
||||||
|
|
||||||
#if defined(VULKAN_H_) && !defined(VK_NO_PROTOTYPES)
|
#if defined(VULKAN_H_) && !defined(VK_NO_PROTOTYPES)
|
||||||
#error "define VK_NO_PROTOTYPES needed"
|
#error "define VK_NO_PROTOTYPES needed"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace mlx
|
|||||||
NonOwningPtr<T>& NonOwningPtr<T>::operator=(T* ptr)
|
NonOwningPtr<T>& NonOwningPtr<T>::operator=(T* ptr)
|
||||||
{
|
{
|
||||||
p_ptr = ptr;
|
p_ptr = ptr;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -23,6 +24,7 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
p_ptr = ptr.p_ptr;
|
p_ptr = ptr.p_ptr;
|
||||||
ptr.p_ptr = nullptr;
|
ptr.p_ptr = nullptr;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ namespace mlx
|
|||||||
EventBus::RegisterListener({[](const EventBase& event)
|
EventBus::RegisterListener({[](const EventBase& event)
|
||||||
{
|
{
|
||||||
if(event.What() == Event::FatalErrorEventCode)
|
if(event.What() == Event::FatalErrorEventCode)
|
||||||
{
|
|
||||||
std::abort();
|
std::abort();
|
||||||
}
|
|
||||||
}, "__MlxApplication" });
|
}, "__MlxApplication" });
|
||||||
|
|
||||||
m_fps.Init();
|
m_fps.Init();
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ namespace mlx
|
|||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case LogType::Debug: std::cout << Ansi::blue << "[Akel Debug] " << Ansi::def << code_infos << message << '\n'; break;
|
case LogType::Debug: std::cout << Ansi::blue << "[MLX Debug] " << Ansi::def << code_infos << message << '\n'; break;
|
||||||
case LogType::Message: std::cout << Ansi::blue << "[Akel Message] " << Ansi::def << code_infos << message << '\n'; break;
|
case LogType::Message: std::cout << Ansi::blue << "[MLX Message] " << Ansi::def << code_infos << message << '\n'; break;
|
||||||
case LogType::Warning: std::cout << Ansi::magenta << "[Akel Warning] " << Ansi::def << code_infos << message << '\n'; break;
|
case LogType::Warning: std::cout << Ansi::magenta << "[MLX Warning] " << Ansi::def << code_infos << message << '\n'; break;
|
||||||
case LogType::Error: std::cerr << Ansi::red << "[Akel Error] " << Ansi::def << code_infos << message << '\n'; break;
|
case LogType::Error: std::cerr << Ansi::red << "[MLX Error] " << Ansi::def << code_infos << message << '\n'; break;
|
||||||
case LogType::FatalError: std::cerr << Ansi::red << "[Akel Fatal Error] " << Ansi::def << code_infos << message << '\n'; break;
|
case LogType::FatalError: std::cerr << Ansi::red << "[MLX Fatal Error] " << Ansi::def << code_infos << message << '\n'; break;
|
||||||
|
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,10 +56,6 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
WatcherData* data = static_cast<WatcherData*>(userdata);
|
WatcherData* data = static_cast<WatcherData*>(userdata);
|
||||||
|
|
||||||
if(event->type == SDL_MOUSEMOTION)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::uint32_t id = event->window.windowID;
|
std::uint32_t id = event->window.windowID;
|
||||||
switch(event->type)
|
switch(event->type)
|
||||||
{
|
{
|
||||||
@@ -102,6 +98,7 @@ namespace mlx
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}, &watcher_data);
|
}, &watcher_data);
|
||||||
|
DebugLog("SDL Manager initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
void* SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden)
|
void* SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden)
|
||||||
@@ -162,11 +159,44 @@ namespace mlx
|
|||||||
return Vec2ui{ extent };
|
return Vec2ui{ extent };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::int32_t SDLManager::GetX() const noexcept
|
||||||
|
{
|
||||||
|
int dummy;
|
||||||
|
int x;
|
||||||
|
SDL_GetMouseState(&x, &dummy);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t SDLManager::GetY() const noexcept
|
||||||
|
{
|
||||||
|
int dummy;
|
||||||
|
int y;
|
||||||
|
SDL_GetMouseState(&dummy, &y);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t SDLManager::GetXRel() const noexcept
|
||||||
|
{
|
||||||
|
int dummy;
|
||||||
|
int x;
|
||||||
|
SDL_GetRelativeMouseState(&x, &dummy);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t SDLManager::GetYRel() const noexcept
|
||||||
|
{
|
||||||
|
int dummy;
|
||||||
|
int y;
|
||||||
|
SDL_GetRelativeMouseState(&dummy, &y);
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
void SDLManager::Shutdown() noexcept
|
void SDLManager::Shutdown() noexcept
|
||||||
{
|
{
|
||||||
if(m_drop_sdl_responsability)
|
if(m_drop_sdl_responsability)
|
||||||
return;
|
return;
|
||||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
|
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
|
DebugLog("SDL Manager uninitialized");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,24 @@ namespace mlx
|
|||||||
m_events_hooks[window_id][event].hook(code, m_events_hooks[window_id][event].param);
|
m_events_hooks[window_id][event].hook(code, m_events_hooks[window_id][event].param);
|
||||||
}, nullptr);
|
}, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::int32_t Inputs::GetX() const noexcept
|
||||||
|
{
|
||||||
|
return SDLManager::Get().GetX();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t Inputs::GetY() const noexcept
|
||||||
|
{
|
||||||
|
return SDLManager::Get().GetY();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t Inputs::GetXRel() const noexcept
|
||||||
|
{
|
||||||
|
return SDLManager::Get().GetXRel();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::int32_t Inputs::GetYRel() const noexcept
|
||||||
|
{
|
||||||
|
return SDLManager::Get().GetYRel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ namespace mlx
|
|||||||
}
|
}
|
||||||
|
|
||||||
DescriptorSet::DescriptorSet(VkDescriptorSetLayout layout, const std::vector<Descriptor>& descriptors)
|
DescriptorSet::DescriptorSet(VkDescriptorSetLayout layout, const std::vector<Descriptor>& descriptors)
|
||||||
: m_set_layout(layout), m_descriptors(descriptors)
|
: m_descriptors(descriptors), m_set_layout(layout)
|
||||||
{
|
{
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), layout);
|
m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), layout);
|
||||||
|
|||||||
@@ -3,6 +3,16 @@
|
|||||||
#include <Maths/Vec4.h>
|
#include <Maths/Vec4.h>
|
||||||
#include <Renderer/RenderCore.h>
|
#include <Renderer/RenderCore.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#ifdef MLX_COMPILER_GCC
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wstringop-overflow"
|
||||||
|
#include <stb_image.h>
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#else
|
||||||
|
#include <stb_image.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled)
|
void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled)
|
||||||
@@ -31,7 +41,7 @@ namespace mlx
|
|||||||
image_info.usage = usage;
|
image_info.usage = usage;
|
||||||
image_info.samples = (m_is_multisampled ? VK_SAMPLE_COUNT_4_BIT : VK_SAMPLE_COUNT_1_BIT);
|
image_info.samples = (m_is_multisampled ? VK_SAMPLE_COUNT_4_BIT : VK_SAMPLE_COUNT_1_BIT);
|
||||||
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
image_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
|
||||||
m_allocation = RenderCore::Get().GetAllocator().CreateImage(&image_info, alloc_info, &m_image);
|
m_allocation = RenderCore::Get().GetAllocator().CreateImage(&image_info, &alloc_info, m_image);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Image::CreateImageView(VkImageViewType type, VkImageAspectFlags aspect_flags, int layer_count) noexcept
|
void Image::CreateImageView(VkImageViewType type, VkImageAspectFlags aspect_flags, int layer_count) noexcept
|
||||||
@@ -77,11 +87,11 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
VkImageSubresourceRange subresource_range{};
|
VkImageSubresourceRange subresource_range{};
|
||||||
subresource_range.baseMipLevel = 0;
|
subresource_range.baseMipLevel = 0;
|
||||||
subresource_range.layerCount = (m_type == ImageType::Cube ? 6 : 1);
|
subresource_range.layerCount = 1;
|
||||||
subresource_range.levelCount = 1;
|
subresource_range.levelCount = 1;
|
||||||
subresource_range.baseArrayLayer = 0;
|
subresource_range.baseArrayLayer = 0;
|
||||||
|
|
||||||
if(m_type == ImageType::Color || m_type == ImageType::Cube)
|
if(m_type == ImageType::Color)
|
||||||
{
|
{
|
||||||
VkImageLayout old_layout = m_layout;
|
VkImageLayout old_layout = m_layout;
|
||||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
||||||
@@ -134,10 +144,10 @@ namespace mlx
|
|||||||
m_has_been_modified = true;
|
m_has_been_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetPixel(int x, int y) noexcept
|
int Texture::GetPixel(int x, int y) noexcept
|
||||||
{
|
{
|
||||||
MLX_PROFILE_FUNCTION();
|
MLX_PROFILE_FUNCTION();
|
||||||
if(x < 0 || y < 0 || static_cast<std::uint32_t>(x) > getWidth() || static_cast<std::uint32_t>(y) > getHeight())
|
if(x < 0 || y < 0 || static_cast<std::uint32_t>(x) > m_width || static_cast<std::uint32_t>(y) > m_height)
|
||||||
return 0;
|
return 0;
|
||||||
if(!m_staging_buffer.has_value())
|
if(!m_staging_buffer.has_value())
|
||||||
OpenCPUBuffer();
|
OpenCPUBuffer();
|
||||||
@@ -149,22 +159,16 @@ namespace mlx
|
|||||||
return *reinterpret_cast<int*>(bytes);
|
return *reinterpret_cast<int*>(bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Update(VkCommandBuffer cmd) const
|
void Texture::Update(VkCommandBuffer cmd)
|
||||||
{
|
{
|
||||||
if(!m_has_been_modified)
|
if(!m_has_been_modified)
|
||||||
return;
|
return;
|
||||||
std::memcpy(m_staging_buffer.GetMap(), m_cpu_buffer.data(), m_cpu_buffer.size() * kvfGetFormatSize(m_format));
|
std::memcpy(m_staging_buffer->GetMap(), m_cpu_buffer.data(), m_cpu_buffer.size() * kvfFormatSize(m_format));
|
||||||
|
|
||||||
VkImageLayout old_layout = m_layout;
|
VkImageLayout old_layout = m_layout;
|
||||||
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
|
||||||
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
|
||||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
||||||
kvfCopyBufferToImage(cmd, Image::Get(), staging_buffer.Get(), staging_buffer.GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { width, height, 1 });
|
kvfCopyBufferToImage(cmd, Image::Get(), m_staging_buffer->Get(), m_staging_buffer->GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 });
|
||||||
TransitionLayout(old_layout, cmd);
|
TransitionLayout(old_layout, cmd);
|
||||||
vkEndCommandBuffer(cmd);
|
|
||||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
|
||||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
|
||||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
|
||||||
|
|
||||||
m_has_been_modified = false;
|
m_has_been_modified = false;
|
||||||
}
|
}
|
||||||
@@ -176,14 +180,14 @@ namespace mlx
|
|||||||
return;
|
return;
|
||||||
DebugLog("Texture : enabling CPU mapping");
|
DebugLog("Texture : enabling CPU mapping");
|
||||||
m_staging_buffer.emplace();
|
m_staging_buffer.emplace();
|
||||||
std::size_t size = m_width * m_height * kvfGetFormatSize(m_format);
|
std::size_t size = m_width * m_height * kvfFormatSize(m_format);
|
||||||
m_staging_buffer->Init(BufferType::Staging, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, {});
|
m_staging_buffer->Init(BufferType::Staging, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT, {});
|
||||||
|
|
||||||
VkImageLayout old_layout = m_layout;
|
VkImageLayout old_layout = m_layout;
|
||||||
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||||
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cmd);
|
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, cmd);
|
||||||
kvfImageToBuffer(cmd, m_image, m_staging_buffer.Get(), m_staging_buffer.GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 });
|
kvfCopyImageToBuffer(cmd, m_staging_buffer->Get(), m_image, m_staging_buffer->GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 });
|
||||||
TransitionLayout(old_layout, cmd);
|
TransitionLayout(old_layout, cmd);
|
||||||
vkEndCommandBuffer(cmd);
|
vkEndCommandBuffer(cmd);
|
||||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||||
@@ -191,7 +195,7 @@ namespace mlx
|
|||||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||||
|
|
||||||
m_cpu_buffer.resize(m_width * m_height);
|
m_cpu_buffer.resize(m_width * m_height);
|
||||||
std::memcpy(m_cpu_buffer.data(), m_staging_buffer.GetMap(), m_cpu_buffer.size());
|
std::memcpy(m_cpu_buffer.data(), m_staging_buffer->GetMap(), m_cpu_buffer.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture* StbTextureLoad(const std::filesystem::path& file, int* w, int* h)
|
Texture* StbTextureLoad(const std::filesystem::path& file, int* w, int* h)
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
#include <Renderer/Vertex.h>
|
#include <Renderer/Vertex.h>
|
||||||
#include <Core/EventBus.h>
|
#include <Core/EventBus.h>
|
||||||
|
|
||||||
namespace Scop
|
namespace mlx
|
||||||
{
|
{
|
||||||
void GraphicPipeline::Init(const GraphicPipelineDescriptor& descriptor)
|
void GraphicPipeline::Init(const GraphicPipelineDescriptor& descriptor)
|
||||||
{
|
{
|
||||||
@@ -39,7 +39,7 @@ namespace Scop
|
|||||||
kvfGPipelineBuilderSetCullMode(builder, VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE);
|
kvfGPipelineBuilderSetCullMode(builder, VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE);
|
||||||
kvfGPipelineBuilderEnableAlphaBlending(builder);
|
kvfGPipelineBuilderEnableAlphaBlending(builder);
|
||||||
if(p_depth)
|
if(p_depth)
|
||||||
kvfGPipelineBuilderEnableDepthTest(builder, (descriptor.depth_test_equal ? VK_COMPARE_OP_EQUAL : VK_COMPARE_OP_LESS), true);
|
kvfGPipelineBuilderEnableDepthTest(builder, VK_COMPARE_OP_LESS, true);
|
||||||
else
|
else
|
||||||
kvfGPipelineBuilderDisableDepthTest(builder);
|
kvfGPipelineBuilderDisableDepthTest(builder);
|
||||||
kvfGPipelineBuilderSetPolygonMode(builder, VK_POLYGON_MODE_FILL, 1.0f);
|
kvfGPipelineBuilderSetPolygonMode(builder, VK_POLYGON_MODE_FILL, 1.0f);
|
||||||
@@ -80,7 +80,7 @@ namespace Scop
|
|||||||
scissor.extent = fb_extent;
|
scissor.extent = fb_extent;
|
||||||
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
||||||
|
|
||||||
for(int i = 0; i < m_clears.size(); i++)
|
for(std::size_t i = 0; i < m_clears.size(); i++)
|
||||||
{
|
{
|
||||||
m_clears[i].color.float32[0] = clear[0];
|
m_clears[i].color.float32[0] = clear[0];
|
||||||
m_clears[i].color.float32[1] = clear[1];
|
m_clears[i].color.float32[1] = clear[1];
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
#include <Renderer/Pipelines/Shader.h>
|
#include <Renderer/Pipelines/Shader.h>
|
||||||
#include <Renderer/RenderCore.h>
|
#include <Renderer/RenderCore.h>
|
||||||
|
|
||||||
namespace Scop
|
namespace mlx
|
||||||
{
|
{
|
||||||
Shader::Shader(const std::vector<std::uint8_t>& bytecode, ShaderType type, ShaderLayout layout) : m_bytecode(bytecode), m_layout(std::move(layout))
|
Shader::Shader(const std::vector<std::uint8_t>& bytecode, ShaderType type, ShaderLayout layout) : m_layout(std::move(layout)), m_bytecode(bytecode)
|
||||||
{
|
{
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
@@ -14,7 +14,7 @@ namespace Scop
|
|||||||
|
|
||||||
default : FatalError("wtf"); break;
|
default : FatalError("wtf"); break;
|
||||||
}
|
}
|
||||||
m_module = kvfCreateShaderModule(RenderCore::Get().GetDevice(), m_bytecode.data(), m_bytecode.size() * 4);
|
m_module = kvfCreateShaderModule(RenderCore::Get().GetDevice(), reinterpret_cast<std::uint32_t*>(m_bytecode.data()), m_bytecode.size() * 4);
|
||||||
DebugLog("Vulkan : shader module created");
|
DebugLog("Vulkan : shader module created");
|
||||||
|
|
||||||
GeneratePipelineLayout(m_layout);
|
GeneratePipelineLayout(m_layout);
|
||||||
@@ -63,21 +63,4 @@ namespace Scop
|
|||||||
DebugLog("Vulkan : descriptor set layout destroyed");
|
DebugLog("Vulkan : descriptor set layout destroyed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Shader> LoadShaderFromFile(const std::filesystem::path& filepath, ShaderType type, ShaderLayout layout)
|
|
||||||
{
|
|
||||||
std::ifstream stream(filepath, std::ios::binary);
|
|
||||||
if(!stream.is_open())
|
|
||||||
FatalError("Renderer : unable to open a spirv shader file, %", filepath);
|
|
||||||
std::vector<std::uint32_t> data;
|
|
||||||
stream.seekg(0);
|
|
||||||
std::uint32_t part = 0;
|
|
||||||
while(stream.read(reinterpret_cast<char*>(&part), sizeof(part)))
|
|
||||||
data.push_back(part);
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
std::shared_ptr<Shader> shader = std::make_shared<Shader>(data, type, layout);
|
|
||||||
DebugLog("Vulkan : shader loaded %", filepath);
|
|
||||||
return shader;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,28 +12,30 @@
|
|||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
static VulkanLoader loader;
|
static std::unique_ptr<VulkanLoader> loader;
|
||||||
|
|
||||||
void ErrorCallback(const char* message) noexcept
|
void ErrorCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
FatalError(message);
|
FatalError(message, 0, "", "");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationErrorCallback(const char* message) noexcept
|
void ValidationErrorCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
Error(message);
|
Error(message, 0, "", "");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidationWarningCallback(const char* message) noexcept
|
void ValidationWarningCallback(const char* message) noexcept
|
||||||
{
|
{
|
||||||
Warning(message);
|
Warning(message, 0, "", "");
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderCore::Init() noexcept
|
void RenderCore::Init() noexcept
|
||||||
{
|
{
|
||||||
|
loader = std::make_unique<VulkanLoader>();
|
||||||
|
|
||||||
kvfSetErrorCallback(&ErrorCallback);
|
kvfSetErrorCallback(&ErrorCallback);
|
||||||
kvfSetValidationErrorCallback(&ValidationErrorCallback);
|
kvfSetValidationErrorCallback(&ValidationErrorCallback);
|
||||||
kvfSetValidationWarningCallback(&ValidationWarningCallback);
|
kvfSetValidationWarningCallback(&ValidationWarningCallback);
|
||||||
@@ -41,15 +43,15 @@ namespace mlx
|
|||||||
//kvfAddLayer("VK_LAYER_MESA_overlay");
|
//kvfAddLayer("VK_LAYER_MESA_overlay");
|
||||||
|
|
||||||
Window window(1, 1, "", true);
|
Window window(1, 1, "", true);
|
||||||
std::vector<const char*> instance_extentions = window.GetRequiredVulkanInstanceExtentions();
|
std::vector<const char*> instance_extensions = window.GetRequiredVulkanInstanceExtentions();
|
||||||
#ifdef MLX_PLAT_MACOS
|
#ifdef MLX_PLAT_MACOS
|
||||||
instance_extentions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
||||||
DebugLog("Vulkan : instance created");
|
DebugLog("Vulkan : instance created");
|
||||||
|
|
||||||
loader.LoadInstance(m_instance);
|
loader->LoadInstance(m_instance);
|
||||||
|
|
||||||
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
|
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
|
||||||
|
|
||||||
@@ -77,5 +79,6 @@ namespace mlx
|
|||||||
DebugLog("Vulkan : logical device destroyed");
|
DebugLog("Vulkan : logical device destroyed");
|
||||||
kvfDestroyInstance(m_instance);
|
kvfDestroyInstance(m_instance);
|
||||||
DebugLog("Vulkan : instance destroyed");
|
DebugLog("Vulkan : instance destroyed");
|
||||||
|
loader.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace mlx
|
|||||||
std::vector<std::uint8_t> fragment_shader_code = {
|
std::vector<std::uint8_t> fragment_shader_code = {
|
||||||
#include <Embedded/2DFragment.spv.h>
|
#include <Embedded/2DFragment.spv.h>
|
||||||
};
|
};
|
||||||
p_fragment_shader = std::make_shared<Shader>(fragment_shader, ShaderType::Fragment, std::move(fragment_shader_layout));
|
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));
|
||||||
|
|
||||||
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
|
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ namespace mlx
|
|||||||
if(event.What() == Event::DescriptorPoolResetEventCode)
|
if(event.What() == Event::DescriptorPoolResetEventCode)
|
||||||
{
|
{
|
||||||
p_texture_set->Reallocate();
|
p_texture_set->Reallocate();
|
||||||
p_viewer_data_set.Reallocate();
|
p_viewer_data_set->Reallocate();
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
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->SetUniformBuffer(i, 0, p_viewer_data_buffer->Get(i));
|
||||||
@@ -64,7 +64,7 @@ namespace mlx
|
|||||||
p_texture_set = std::make_shared<DescriptorSet>(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
p_texture_set = std::make_shared<DescriptorSet>(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
||||||
|
|
||||||
p_viewer_data_buffer = std::make_shared<UniformBuffer>();
|
p_viewer_data_buffer = std::make_shared<UniformBuffer>();
|
||||||
p_viewer_data_buffer->Init(sizeof(ViewerData2D));
|
p_viewer_data_buffer->Init(sizeof(ViewerData));
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
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->SetUniformBuffer(i, 0, p_viewer_data_buffer->Get(i));
|
||||||
@@ -80,7 +80,7 @@ namespace mlx
|
|||||||
pipeline_descriptor.vertex_shader = p_vertex_shader;
|
pipeline_descriptor.vertex_shader = p_vertex_shader;
|
||||||
pipeline_descriptor.fragment_shader = p_fragment_shader;
|
pipeline_descriptor.fragment_shader = p_fragment_shader;
|
||||||
pipeline_descriptor.color_attachments = { &render_target };
|
pipeline_descriptor.color_attachments = { &render_target };
|
||||||
pipeline_descriptor.depth = scene.GetDepth();
|
pipeline_descriptor.depth = &scene.GetDepth();
|
||||||
pipeline_descriptor.clear_color_attachments = false;
|
pipeline_descriptor.clear_color_attachments = false;
|
||||||
m_pipeline.Init(pipeline_descriptor);
|
m_pipeline.Init(pipeline_descriptor);
|
||||||
}
|
}
|
||||||
@@ -88,8 +88,8 @@ namespace mlx
|
|||||||
std::uint32_t frame_index = renderer.GetCurrentFrameIndex();
|
std::uint32_t frame_index = renderer.GetCurrentFrameIndex();
|
||||||
|
|
||||||
ViewerData viewer_data;
|
ViewerData viewer_data;
|
||||||
viewer_data.projection = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f);
|
viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f);
|
||||||
static CPUBuffer buffer(sizeof(ViewerData2D));
|
static CPUBuffer buffer(sizeof(ViewerData));
|
||||||
std::memcpy(buffer.GetData(), &viewer_data, buffer.GetSize());
|
std::memcpy(buffer.GetData(), &viewer_data, buffer.GetSize());
|
||||||
p_viewer_data_buffer->SetData(buffer, frame_index);
|
p_viewer_data_buffer->SetData(buffer, frame_index);
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace mlx
|
|||||||
p_set = std::make_shared<DescriptorSet>(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
p_set = std::make_shared<DescriptorSet>(p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FinalPass::Pass(Scene& scene, Renderer& renderer, Texture& render_target)
|
void FinalPass::Pass([[maybe_unused]] Scene& scene, Renderer& renderer, Texture& render_target)
|
||||||
{
|
{
|
||||||
if(m_pipeline.GetPipeline() == VK_NULL_HANDLE)
|
if(m_pipeline.GetPipeline() == VK_NULL_HANDLE)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -36,21 +36,20 @@ namespace mlx
|
|||||||
|
|
||||||
p_window = window;
|
p_window = window;
|
||||||
|
|
||||||
auto& render_core = RenderCore::Get();
|
m_surface = p_window->CreateVulkanSurface(RenderCore::Get().GetInstance());
|
||||||
m_surface = p_window->CreateVulkanSurface(render_core::GetInstance());
|
|
||||||
DebugLog("Vulkan : surface created");
|
DebugLog("Vulkan : surface created");
|
||||||
|
|
||||||
CreateSwapchain();
|
CreateSwapchain();
|
||||||
|
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
{
|
{
|
||||||
m_image_available_semaphores[i] = kvfCreateSemaphore(render_core.GetDevice());
|
m_image_available_semaphores[i] = kvfCreateSemaphore(RenderCore::Get().GetDevice());
|
||||||
DebugLog("Vulkan : image available semaphore created");
|
DebugLog("Vulkan : image available semaphore created");
|
||||||
m_render_finished_semaphores[i] = kvfCreateSemaphore(render_core.GetDevice());
|
m_render_finished_semaphores[i] = kvfCreateSemaphore(RenderCore::Get().GetDevice());
|
||||||
DebugLog("Vulkan : render finished semaphore created");
|
DebugLog("Vulkan : render finished semaphore created");
|
||||||
m_cmd_buffers[i] = kvfCreateCommandBuffer(render_core.GetDevice());
|
m_cmd_buffers[i] = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||||
DebugLog("Vulkan : command buffer created");
|
DebugLog("Vulkan : command buffer created");
|
||||||
m_cmd_fences[i] = kvfCreateFence(render_core.GetDevice());
|
m_cmd_fences[i] = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||||
DebugLog("Vulkan : fence created");
|
DebugLog("Vulkan : fence created");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,21 +123,20 @@ namespace mlx
|
|||||||
|
|
||||||
void Renderer::Destroy() noexcept
|
void Renderer::Destroy() noexcept
|
||||||
{
|
{
|
||||||
auto& render_core = RenderCore::Get();
|
RenderCore::Get().WaitDeviceIdle();
|
||||||
render_core.WaitDeviceIdle();
|
|
||||||
|
|
||||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||||
{
|
{
|
||||||
kvfDestroySemaphore(render_core.GetDevice(), m_image_available_semaphores[i]);
|
kvfDestroySemaphore(RenderCore::Get().GetDevice(), m_image_available_semaphores[i]);
|
||||||
DebugLog("Vulkan : image available semaphore destroyed");
|
DebugLog("Vulkan : image available semaphore destroyed");
|
||||||
kvfDestroySemaphore(render_core.GetDevice(), m_render_finished_semaphores[i]);
|
kvfDestroySemaphore(RenderCore::Get().GetDevice(), m_render_finished_semaphores[i]);
|
||||||
DebugLog("Vulkan : render finished semaphore destroyed");
|
DebugLog("Vulkan : render finished semaphore destroyed");
|
||||||
kvfDestroyFence(render_core.GetDevice(), m_cmd_fences[i]);
|
kvfDestroyFence(RenderCore::Get().GetDevice(), m_cmd_fences[i]);
|
||||||
DebugLog("Vulkan : fence destroyed");
|
DebugLog("Vulkan : fence destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
DestroySwapchain();
|
DestroySwapchain();
|
||||||
vkDestroySurfaceKHR(render_core.GetInstance(), m_surface, nullptr);
|
vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr);
|
||||||
DebugLog("Vulkan : surface destroyed");
|
DebugLog("Vulkan : surface destroyed");
|
||||||
m_surface = VK_NULL_HANDLE;
|
m_surface = VK_NULL_HANDLE;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <Graphics/Scene.h>
|
#include <Graphics/Scene.h>
|
||||||
#include <Renderer/ViewerData.h>
|
#include <Renderer/ViewerData.h>
|
||||||
|
|
||||||
namespacemlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
void SceneRenderer::Init()
|
void SceneRenderer::Init()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include <PreCompiled.h>
|
#include <PreCompiled.h>
|
||||||
#include <Renderer/Vulkan/VulkanLoader.h>
|
#include <Renderer/Vulkan/VulkanLoader.h>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef MLX_PLAT_WINDOWS
|
||||||
__declspec(dllimport) HMODULE __stdcall LoadLibraryA(LPCSTR);
|
__declspec(dllimport) HMODULE __stdcall LoadLibraryA(LPCSTR);
|
||||||
__declspec(dllimport) FARPROC __stdcall GetProcAddress(HMODULE, LPCSTR);
|
__declspec(dllimport) FARPROC __stdcall GetProcAddress(HMODULE, LPCSTR);
|
||||||
__declspec(dllimport) int __stdcall FreeLibrary(HMODULE);
|
__declspec(dllimport) int __stdcall FreeLibrary(HMODULE);
|
||||||
@@ -22,20 +22,20 @@ namespace mlx
|
|||||||
{
|
{
|
||||||
namespace Internal
|
namespace Internal
|
||||||
{
|
{
|
||||||
static PFN_vkVoidFunction vkGetInstanceProcAddrStub(Handle context, const char* name)
|
static inline PFN_vkVoidFunction vkGetInstanceProcAddrStub(Handle context, const char* name)
|
||||||
{
|
{
|
||||||
return vkGetInstanceProcAddr((VkInstance)context, name);
|
return vkGetInstanceProcAddr(static_cast<VkInstance>(context), name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanLoader::VulkanLoader()
|
VulkanLoader::VulkanLoader()
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(MLX_PLAT_WINDOWS)
|
||||||
p_module = LoadLibraryA("vulkan-1.dll");
|
p_module = LoadLibraryA("vulkan-1.dll");
|
||||||
if(!p_module)
|
if(!p_module)
|
||||||
FatalError("Vulkan loader : failed to load libvulkan");
|
FatalError("Vulkan loader : failed to load libvulkan");
|
||||||
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)(void(*)(void))GetProcAddress(p_module, "vkGetInstanceProcAddr");
|
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)(void(*)(void))GetProcAddress(p_module, "vkGetInstanceProcAddr");
|
||||||
#elif defined(__APPLE__)
|
#elif defined(MLX_PLAT_MACOS)
|
||||||
p_module = dlopen("libvulkan.dylib", RTLD_NOW | RTLD_LOCAL);
|
p_module = dlopen("libvulkan.dylib", RTLD_NOW | RTLD_LOCAL);
|
||||||
if(!p_module)
|
if(!p_module)
|
||||||
p_module = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL);
|
p_module = dlopen("libvulkan.1.dylib", RTLD_NOW | RTLD_LOCAL);
|
||||||
@@ -55,16 +55,18 @@ namespace mlx
|
|||||||
p_module = dlopen("/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL);
|
p_module = dlopen("/usr/local/lib/libvulkan.dylib", RTLD_NOW | RTLD_LOCAL);
|
||||||
if(!p_module)
|
if(!p_module)
|
||||||
FatalError("Vulkan loader : failed to load libvulkan");
|
FatalError("Vulkan loader : failed to load libvulkan");
|
||||||
|
void* symbol_ptr = dlsym(p_module, "vkGetInstanceProcAddr");
|
||||||
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym(p_module, "vkGetInstanceProcAddr");
|
*(void**)(&vkGetInstanceProcAddr) = symbol_ptr;
|
||||||
#else
|
#else
|
||||||
|
dlerror();
|
||||||
p_module = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL);
|
p_module = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL);
|
||||||
if(!p_module)
|
if(!p_module)
|
||||||
p_module = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
p_module = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||||
if(!p_module)
|
if(!p_module)
|
||||||
FatalError("Vulkan loader : failed to load libvulkan");
|
FatalError("Vulkan loader : failed to load libvulkan due to %", dlerror());
|
||||||
DISABLE_GCC_PEDANTIC_WARNINGS
|
DISABLE_GCC_PEDANTIC_WARNINGS
|
||||||
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym(p_module, "vkGetInstanceProcAddr");
|
void* symbol_ptr = dlsym(p_module, "vkGetInstanceProcAddr");
|
||||||
|
*(void**)(&vkGetInstanceProcAddr) = symbol_ptr;
|
||||||
RESTORE_GCC_PEDANTIC_WARNINGS
|
RESTORE_GCC_PEDANTIC_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
DebugLog("Vulkan loader : libvulkan loaded");
|
DebugLog("Vulkan loader : libvulkan loaded");
|
||||||
@@ -251,7 +253,7 @@ namespace mlx
|
|||||||
|
|
||||||
VulkanLoader::~VulkanLoader()
|
VulkanLoader::~VulkanLoader()
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
#if defined(MLX_PLAT_WINDOWS)
|
||||||
FreeLibrary((HMODULE)p_module);
|
FreeLibrary((HMODULE)p_module);
|
||||||
#else
|
#else
|
||||||
dlclose(p_module);
|
dlclose(p_module);
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef __MLX_VULKAN_LOADER__
|
#ifndef __MLX_VULKAN_LOADER__
|
||||||
#define __MLX_VULKAN_LOADER__
|
#define __MLX_VULKAN_LOADER__
|
||||||
|
|
||||||
#ifdef _WIN32
|
#include <mlx_profile.h>
|
||||||
|
|
||||||
|
#ifdef MLX_PLAT_WINDOWS
|
||||||
typedef const char* LPCSTR;
|
typedef const char* LPCSTR;
|
||||||
typedef struct HINSTANCE__* HINSTANCE;
|
typedef struct HINSTANCE__* HINSTANCE;
|
||||||
typedef HINSTANCE HMODULE;
|
typedef HINSTANCE HMODULE;
|
||||||
@@ -31,7 +33,7 @@ namespace mlx
|
|||||||
void LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept;
|
void LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#ifdef _WIN32
|
#ifdef MLX_PLAT_WINDOWS
|
||||||
HMODULE p_module = nullptr;
|
HMODULE p_module = nullptr;
|
||||||
#else
|
#else
|
||||||
Handle p_module = nullptr;
|
Handle p_module = nullptr;
|
||||||
|
|||||||
27
third_party/kvf.h
vendored
27
third_party/kvf.h
vendored
@@ -134,7 +134,7 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type);
|
VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, KvfImageType type);
|
||||||
void kvfImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent);
|
void kvfCopyImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent);
|
||||||
void kvfDestroyImage(VkDevice device, VkImage image);
|
void kvfDestroyImage(VkDevice device, VkImage image);
|
||||||
VkImageView kvfCreateImageView(VkDevice device, VkImage image, VkFormat format, VkImageViewType type, VkImageAspectFlags aspect, int layer_count);
|
VkImageView kvfCreateImageView(VkDevice device, VkImage image, VkFormat format, VkImageViewType type, VkImageAspectFlags aspect, int layer_count);
|
||||||
void kvfDestroyImageView(VkDevice device, VkImageView image_view);
|
void kvfDestroyImageView(VkDevice device, VkImageView image_view);
|
||||||
@@ -970,6 +970,8 @@ const char* kvfVerbaliseVkResult(VkResult result)
|
|||||||
|
|
||||||
VKAPI_ATTR VkBool32 VKAPI_CALL __kvfDebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData)
|
VKAPI_ATTR VkBool32 VKAPI_CALL __kvfDebugCallback(VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData)
|
||||||
{
|
{
|
||||||
|
(void)messageType;
|
||||||
|
(void)pUserData;
|
||||||
if(messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
if(messageSeverity == VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT)
|
||||||
{
|
{
|
||||||
if(__kvf_validation_error_callback != NULL)
|
if(__kvf_validation_error_callback != NULL)
|
||||||
@@ -1138,7 +1140,7 @@ __KvfQueueFamilies __kvfFindQueueFamilies(VkPhysicalDevice physical, VkSurfaceKH
|
|||||||
VkQueueFamilyProperties* queue_families = (VkQueueFamilyProperties*)KVF_MALLOC(sizeof(VkQueueFamilyProperties) * queue_family_count);
|
VkQueueFamilyProperties* queue_families = (VkQueueFamilyProperties*)KVF_MALLOC(sizeof(VkQueueFamilyProperties) * queue_family_count);
|
||||||
vkGetPhysicalDeviceQueueFamilyProperties(physical, &queue_family_count, queue_families);
|
vkGetPhysicalDeviceQueueFamilyProperties(physical, &queue_family_count, queue_families);
|
||||||
|
|
||||||
for(int i = 0; i < queue_family_count; i++)
|
for(uint32_t i = 0; i < queue_family_count; i++)
|
||||||
{
|
{
|
||||||
// try to find a queue family index that supports compute but not graphics
|
// try to find a queue family index that supports compute but not graphics
|
||||||
if(queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT && (queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)
|
if(queue_families[i].queueFlags & VK_QUEUE_COMPUTE_BIT && (queue_families[i].queueFlags & VK_QUEUE_GRAPHICS_BIT) == 0)
|
||||||
@@ -1201,10 +1203,10 @@ int32_t __kvfScorePhysicalDevice(VkPhysicalDevice device, VkSurfaceKHR surface,
|
|||||||
vkEnumerateDeviceExtensionProperties(device, NULL, &extension_count, props);
|
vkEnumerateDeviceExtensionProperties(device, NULL, &extension_count, props);
|
||||||
|
|
||||||
bool are_there_required_device_extensions = true;
|
bool are_there_required_device_extensions = true;
|
||||||
for(int j = 0; j < device_extensions_count; j++)
|
for(uint32_t j = 0; j < device_extensions_count; j++)
|
||||||
{
|
{
|
||||||
bool is_there_extension = false;
|
bool is_there_extension = false;
|
||||||
for(int k = 0; k < extension_count; k++)
|
for(uint32_t k = 0; k < extension_count; k++)
|
||||||
{
|
{
|
||||||
if(strcmp(device_extensions[j], props[k].extensionName) == 0)
|
if(strcmp(device_extensions[j], props[k].extensionName) == 0)
|
||||||
{
|
{
|
||||||
@@ -1270,7 +1272,7 @@ VkPhysicalDevice kvfPickGoodPhysicalDevice(VkInstance instance, VkSurfaceKHR sur
|
|||||||
devices = (VkPhysicalDevice*)KVF_MALLOC(sizeof(VkPhysicalDevice) * device_count + 1);
|
devices = (VkPhysicalDevice*)KVF_MALLOC(sizeof(VkPhysicalDevice) * device_count + 1);
|
||||||
vkEnumeratePhysicalDevices(instance, &device_count, devices);
|
vkEnumeratePhysicalDevices(instance, &device_count, devices);
|
||||||
|
|
||||||
for(int i = 0; i < device_count; i++)
|
for(uint32_t i = 0; i < device_count; i++)
|
||||||
{
|
{
|
||||||
int32_t current_device_score = __kvfScorePhysicalDevice(devices[i], surface, device_extensions, device_extensions_count);
|
int32_t current_device_score = __kvfScorePhysicalDevice(devices[i], surface, device_extensions, device_extensions_count);
|
||||||
if(current_device_score > best_device_score)
|
if(current_device_score > best_device_score)
|
||||||
@@ -1465,7 +1467,6 @@ uint32_t kvfGetDeviceQueueFamily(VkDevice device, KvfQueueType queue)
|
|||||||
KVF_ASSERT(device != VK_NULL_HANDLE);
|
KVF_ASSERT(device != VK_NULL_HANDLE);
|
||||||
__KvfDevice* kvfdevice = __kvfGetKvfDeviceFromVkDevice(device);
|
__KvfDevice* kvfdevice = __kvfGetKvfDeviceFromVkDevice(device);
|
||||||
KVF_ASSERT(kvfdevice != NULL);
|
KVF_ASSERT(kvfdevice != NULL);
|
||||||
VkQueue vk_queue = VK_NULL_HANDLE;
|
|
||||||
if(queue == KVF_GRAPHICS_QUEUE)
|
if(queue == KVF_GRAPHICS_QUEUE)
|
||||||
return kvfdevice->queues.graphics;
|
return kvfdevice->queues.graphics;
|
||||||
else if(queue == KVF_PRESENT_QUEUE)
|
else if(queue == KVF_PRESENT_QUEUE)
|
||||||
@@ -1508,7 +1509,7 @@ int32_t kvfFindDeviceQueueFamily(VkPhysicalDevice physical, KvfQueueType type)
|
|||||||
|
|
||||||
int32_t queue = -1;
|
int32_t queue = -1;
|
||||||
|
|
||||||
for(int i = 0; i < queue_family_count; i++)
|
for(uint32_t i = 0; i < queue_family_count; i++)
|
||||||
{
|
{
|
||||||
if(type == KVF_COMPUTE_QUEUE)
|
if(type == KVF_COMPUTE_QUEUE)
|
||||||
{
|
{
|
||||||
@@ -1546,7 +1547,7 @@ int32_t kvfFindDeviceQueueFamily(VkPhysicalDevice physical, KvfQueueType type)
|
|||||||
|
|
||||||
int32_t queue = -1;
|
int32_t queue = -1;
|
||||||
|
|
||||||
for(int i = 0; i < queue_family_count; i++)
|
for(uint32_t i = 0; i < queue_family_count; i++)
|
||||||
{
|
{
|
||||||
VkBool32 present_support = false;
|
VkBool32 present_support = false;
|
||||||
vkGetPhysicalDeviceSurfaceSupportKHR(physical, i, surface, &present_support);
|
vkGetPhysicalDeviceSurfaceSupportKHR(physical, i, surface, &present_support);
|
||||||
@@ -1629,7 +1630,7 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore)
|
|||||||
|
|
||||||
VkSurfaceFormatKHR __kvfChooseSwapSurfaceFormat(__KvfSwapchainSupportInternal* support)
|
VkSurfaceFormatKHR __kvfChooseSwapSurfaceFormat(__KvfSwapchainSupportInternal* support)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < support->formats_count; i++)
|
for(uint32_t i = 0; i < support->formats_count; i++)
|
||||||
{
|
{
|
||||||
if(support->formats[i].format == VK_FORMAT_R8G8B8A8_SRGB && support->formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
if(support->formats[i].format == VK_FORMAT_R8G8B8A8_SRGB && support->formats[i].colorSpace == VK_COLOR_SPACE_SRGB_NONLINEAR_KHR)
|
||||||
return support->formats[i];
|
return support->formats[i];
|
||||||
@@ -1641,7 +1642,7 @@ void kvfDestroySemaphore(VkDevice device, VkSemaphore semaphore)
|
|||||||
{
|
{
|
||||||
if(try_vsync == false)
|
if(try_vsync == false)
|
||||||
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
return VK_PRESENT_MODE_IMMEDIATE_KHR;
|
||||||
for(int i = 0; i < support->presentModes_count; i++)
|
for(uint32_t i = 0; i < support->presentModes_count; i++)
|
||||||
{
|
{
|
||||||
if(support->presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
|
if(support->presentModes[i] == VK_PRESENT_MODE_MAILBOX_KHR)
|
||||||
return support->presentModes[i];
|
return support->presentModes[i];
|
||||||
@@ -1781,7 +1782,7 @@ VkImage kvfCreateImage(VkDevice device, uint32_t width, uint32_t height, VkForma
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void kvfImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent)
|
void kvfCopyImageToBuffer(VkCommandBuffer cmd, VkBuffer dst, VkImage src, size_t buffer_offset, VkImageAspectFlagBits aspect, VkExtent3D extent)
|
||||||
{
|
{
|
||||||
KVF_ASSERT(cmd != VK_NULL_HANDLE);
|
KVF_ASSERT(cmd != VK_NULL_HANDLE);
|
||||||
KVF_ASSERT(dst != VK_NULL_HANDLE);
|
KVF_ASSERT(dst != VK_NULL_HANDLE);
|
||||||
@@ -2286,7 +2287,7 @@ VkDescriptorSet kvfAllocateDescriptorSet(VkDevice device, VkDescriptorSetLayout
|
|||||||
__KvfDevice* kvf_device = __kvfGetKvfDeviceFromVkDevice(device);
|
__KvfDevice* kvf_device = __kvfGetKvfDeviceFromVkDevice(device);
|
||||||
KVF_ASSERT(kvf_device != NULL);
|
KVF_ASSERT(kvf_device != NULL);
|
||||||
VkDescriptorPool pool = VK_NULL_HANDLE;
|
VkDescriptorPool pool = VK_NULL_HANDLE;
|
||||||
for(int i = 0; i < kvf_device->sets_pools_size; i++)
|
for(uint32_t i = 0; i < kvf_device->sets_pools_size; i++)
|
||||||
{
|
{
|
||||||
if(kvf_device->sets_pools[i].size < kvf_device->sets_pools[i].capacity)
|
if(kvf_device->sets_pools[i].size < kvf_device->sets_pools[i].capacity)
|
||||||
pool = kvf_device->sets_pools[i].pool;
|
pool = kvf_device->sets_pools[i].pool;
|
||||||
@@ -2397,7 +2398,7 @@ void kvfResetDeviceDescriptorPools(VkDevice device)
|
|||||||
KVF_ASSERT(device != VK_NULL_HANDLE);
|
KVF_ASSERT(device != VK_NULL_HANDLE);
|
||||||
__KvfDevice* kvf_device = __kvfGetKvfDeviceFromVkDevice(device);
|
__KvfDevice* kvf_device = __kvfGetKvfDeviceFromVkDevice(device);
|
||||||
KVF_ASSERT(kvf_device != NULL);
|
KVF_ASSERT(kvf_device != NULL);
|
||||||
for(int i = 0; i < kvf_device->sets_pools_size; i++)
|
for(uint32_t i = 0; i < kvf_device->sets_pools_size; i++)
|
||||||
{
|
{
|
||||||
vkResetDescriptorPool(device, kvf_device->sets_pools[i].pool, 0);
|
vkResetDescriptorPool(device, kvf_device->sets_pools[i].pool, 0);
|
||||||
kvf_device->sets_pools[i].size = 0;
|
kvf_device->sets_pools[i].size = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user