working on texts and fonts

This commit is contained in:
2024-10-27 01:14:07 +02:00
parent 3aaa5df929
commit 028cb57ff4
31 changed files with 414 additions and 187 deletions

View File

@@ -153,8 +153,14 @@ namespace mlx
font = std::make_shared<Font>("default", dogica_ttf, scale); font = std::make_shared<Font>("default", dogica_ttf, scale);
else else
font = std::make_shared<Font>(filepath, scale); font = std::make_shared<Font>(filepath, scale);
if(!m_font_registry.IsFontKnown(font)) for(auto& gs : m_graphics)
{
if(gs)
gs->GetScene().BindFont(font);
}
if(m_font_registry.IsFontKnown(font))
return; return;
font->BuildFont();
m_font_registry.RegisterFont(font); m_font_registry.RegisterFont(font);
} }

View File

@@ -32,6 +32,7 @@ namespace mlx
[[nodiscard]] MLX_FORCEINLINE bool HasWindow() const noexcept { return m_has_window; } [[nodiscard]] MLX_FORCEINLINE bool HasWindow() const noexcept { return m_has_window; }
[[nodiscard]] MLX_FORCEINLINE Renderer& GetRenderer() { return m_renderer; } [[nodiscard]] MLX_FORCEINLINE Renderer& GetRenderer() { return m_renderer; }
[[nodiscard]] MLX_FORCEINLINE Scene& GetScene() { return *p_scene; }
~GraphicsSupport(); ~GraphicsSupport();

View File

@@ -6,7 +6,7 @@ namespace mlx
void GraphicsSupport::ResetRenderData() noexcept void GraphicsSupport::ResetRenderData() noexcept
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
p_scene->ResetSprites(); p_scene->ResetScene();
m_put_pixel_manager.ResetRenderData(); m_put_pixel_manager.ResetRenderData();
m_draw_layer = 0; m_draw_layer = 0;
m_pixelput_called = false; m_pixelput_called = false;
@@ -27,10 +27,30 @@ namespace mlx
void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str) void GraphicsSupport::StringPut(int x, int y, std::uint32_t color, std::string str)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
(void)x; Vec4f vec_color = {
(void)y; static_cast<float>((color & 0x000000FF)) / 255.f,
(void)color; static_cast<float>((color & 0x0000FF00) >> 8) / 255.f,
(void)str; static_cast<float>((color & 0x00FF0000) >> 16) / 255.f,
static_cast<float>((color & 0xFF000000) >> 24) / 255.f
};
NonOwningPtr<Text> text = p_scene->GetTextFromPositionAndColor(str, Vec2f{ static_cast<float>(x), static_cast<float>(y) }, vec_color);
if(!text)
{
Text& new_text = p_scene->CreateText(str);
new_text.SetPosition(Vec2f{ static_cast<float>(x), static_cast<float>(y) });
new_text.SetColor(std::move(vec_color));
if(m_pixelput_called)
{
m_draw_layer++;
m_pixelput_called = false;
}
}
else if(!p_scene->IsTextAtGivenDrawLayer(str, m_draw_layer))
{
p_scene->BringToFront(text.Get());
m_draw_layer++;
}
} }
void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y) void GraphicsSupport::TexturePut(NonOwningPtr<Texture> texture, int x, int y)
@@ -50,7 +70,7 @@ namespace mlx
} }
else if(!p_scene->IsTextureAtGivenDrawLayer(texture, m_draw_layer)) else if(!p_scene->IsTextureAtGivenDrawLayer(texture, m_draw_layer))
{ {
p_scene->BringToFront(std::move(sprite)); p_scene->BringToFront(sprite.Get());
m_draw_layer++; m_draw_layer++;
} }
} }

47
runtime/Includes/Graphics/Drawable.h git.filemode.normal_file
View File

@@ -0,0 +1,47 @@
#ifndef __MLX_DRAWABLE__
#define __MLX_DRAWABLE__
#include <Graphics/Enums.h>
namespace mlx
{
class Drawable
{
friend class Render2DPass;
public:
inline Drawable(DrawableType type) : m_type(type) {}
inline void SetColor(Vec4f color) noexcept { m_color = color; }
inline void SetPosition(Vec2f position) noexcept { m_position = position; }
inline virtual void Update([[maybe_unused]] VkCommandBuffer cmd) {}
[[nodiscard]] MLX_FORCEINLINE const Vec4f& GetColor() const noexcept { return m_color; }
[[nodiscard]] MLX_FORCEINLINE const Vec2f& GetPosition() const noexcept { return m_position; }
[[nodiscard]] MLX_FORCEINLINE std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
[[nodiscard]] MLX_FORCEINLINE DrawableType GetType() const noexcept { return m_type; }
inline virtual ~Drawable() { if(p_set) p_set->ReturnDescriptorSetToPool(); }
protected:
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set ? p_set->GetSet(frame_index) : VK_NULL_HANDLE; }
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
{
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType());
}
virtual void Bind(std::size_t frame_index, VkCommandBuffer cmd) = 0;
protected:
std::shared_ptr<DescriptorSet> p_set;
std::shared_ptr<Mesh> p_mesh;
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
Vec2f m_position = Vec2f{ 0.0f, 0.0f };
DrawableType m_type;
};
}
#endif

13
runtime/Includes/Graphics/Enums.h git.filemode.normal_file
View File

@@ -0,0 +1,13 @@
#ifndef __MLX_GRAPHICS_ENUMS__
#define __MLX_GRAPHICS_ENUMS__
namespace mlx
{
enum class DrawableType
{
Sprite,
Text
};
}
#endif

View File

@@ -15,6 +15,9 @@ namespace mlx
bool FontRegistry::IsFontKnown(std::shared_ptr<Font> font) bool FontRegistry::IsFontKnown(std::shared_ptr<Font> font)
{ {
return m_fonts_registry.find(font) != m_fonts_registry.end(); return std::find_if(m_fonts_registry.begin(), m_fonts_registry.end(), [&font](std::shared_ptr<Font> rhs)
{
return font->GetName() == rhs->GetName() && font->GetScale() == rhs->GetScale();
}) != m_fonts_registry.end();
} }
} }

View File

@@ -2,7 +2,10 @@
#define __MLX_SCENE__ #define __MLX_SCENE__
#include <Renderer/Renderer.h> #include <Renderer/Renderer.h>
#include <Graphics/Text.h>
#include <Graphics/Font.h>
#include <Graphics/Sprite.h> #include <Graphics/Sprite.h>
#include <Graphics/Drawable.h>
#include <Renderer/ViewerData.h> #include <Renderer/ViewerData.h>
namespace mlx namespace mlx
@@ -14,20 +17,28 @@ namespace mlx
Sprite& CreateSprite(NonOwningPtr<class Texture> texture) noexcept; Sprite& CreateSprite(NonOwningPtr<class Texture> texture) noexcept;
NonOwningPtr<Sprite> GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const; NonOwningPtr<Sprite> GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const;
void BringToFront(NonOwningPtr<Sprite> sprite);
void TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture); void TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture);
bool IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const; bool IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const;
inline void ResetSprites() { m_sprites.clear(); } Text& CreateText(const std::string& text) noexcept;
NonOwningPtr<Text> GetTextFromPositionAndColor(const std::string& text, const Vec2f& position, const Vec4f& color) const;
bool IsTextAtGivenDrawLayer(const std::string& text, std::uint64_t draw_layer) const;
[[nodiscard]] MLX_FORCEINLINE const std::vector<std::shared_ptr<Sprite>>& GetSprites() const noexcept { return m_sprites; } inline void BindFont(std::shared_ptr<Font> font) { Verify((bool)font, "invalid fond pointer"); p_bound_font = font; }
void BringToFront(NonOwningPtr<Drawable> drawable);
inline void ResetScene() { m_drawables.clear(); }
[[nodiscard]] MLX_FORCEINLINE const std::vector<std::shared_ptr<Drawable>>& GetDrawables() const noexcept { return m_drawables; }
[[nodiscard]] MLX_FORCEINLINE ViewerData& GetViewerData() noexcept { return m_viewer_data; } [[nodiscard]] MLX_FORCEINLINE ViewerData& GetViewerData() noexcept { return m_viewer_data; }
~Scene() = default; ~Scene() = default;
private: private:
std::vector<std::shared_ptr<Sprite>> m_sprites; std::vector<std::shared_ptr<Drawable>> m_drawables;
ViewerData m_viewer_data; ViewerData m_viewer_data;
std::shared_ptr<Font> p_bound_font;
}; };
} }

View File

@@ -6,10 +6,11 @@
#include <Graphics/Mesh.h> #include <Graphics/Mesh.h>
#include <Renderer/Descriptor.h> #include <Renderer/Descriptor.h>
#include <Renderer/Image.h> #include <Renderer/Image.h>
#include <Graphics/Drawable.h>
namespace mlx namespace mlx
{ {
class Sprite class Sprite : public Drawable
{ {
friend class Render2DPass; friend class Render2DPass;
@@ -17,26 +18,18 @@ namespace mlx
Sprite(NonOwningPtr<Texture> texture); Sprite(NonOwningPtr<Texture> texture);
Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture); Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture);
inline void SetColor(Vec4f color) noexcept { m_color = color; } MLX_FORCEINLINE void Update(VkCommandBuffer cmd) override
inline void SetPosition(Vec2f position) noexcept { m_position = position; }
[[nodiscard]] MLX_FORCEINLINE const Vec4f& GetColor() const noexcept { return m_color; }
[[nodiscard]] MLX_FORCEINLINE const Vec2f& GetPosition() const noexcept { return m_position; }
[[nodiscard]] MLX_FORCEINLINE std::shared_ptr<Mesh> GetMesh() const { return p_mesh; }
[[nodiscard]] MLX_FORCEINLINE NonOwningPtr<Texture> GetTexture() const { return p_texture; }
inline ~Sprite() { if(p_set) p_set->ReturnDescriptorSetToPool(); }
private:
[[nodiscard]] inline bool IsSetInit() const noexcept { return p_set && p_set->IsInit(); }
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t frame_index) const noexcept { return p_set ? p_set->GetSet(frame_index) : VK_NULL_HANDLE; }
inline void UpdateDescriptorSet(std::shared_ptr<DescriptorSet> set)
{ {
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(set->GetShaderLayout(), set->GetShaderType()); Verify((bool)p_texture, "a sprite has no texture attached (internal mlx issue, please report to the devs)");
p_texture->Update(cmd);
} }
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd) [[nodiscard]] MLX_FORCEINLINE NonOwningPtr<Texture> GetTexture() const { return p_texture; }
inline ~Sprite() = default;
private:
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd) override
{ {
if(!p_set) if(!p_set)
return; return;
@@ -45,11 +38,7 @@ namespace mlx
} }
private: private:
std::shared_ptr<DescriptorSet> p_set;
NonOwningPtr<Texture> p_texture; NonOwningPtr<Texture> p_texture;
std::shared_ptr<Mesh> p_mesh;
Vec4f m_color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
Vec2f m_position = Vec2f{ 0.0f, 0.0f };
}; };
} }

View File

@@ -2,24 +2,38 @@
#define __MLX_TEXT__ #define __MLX_TEXT__
#include <Graphics/Font.h> #include <Graphics/Font.h>
#include <Graphics/Mesh.h>
#include <Graphics/Drawable.h>
namespace mlx namespace mlx
{ {
class Text class Text : public Drawable
{ {
friend class Render2DPass;
public: public:
Text(const std::string& text, std::shared_ptr<Font> font); Text(const std::string& text, std::shared_ptr<Font> font);
inline Text(const std::string& text, std::shared_ptr<Font> font, std::shared_ptr<Mesh> mesh) : Drawable(DrawableType::Text) { Init(text, font, mesh); }
[[nodiscard]] inline const std::string& GetText() const { return m_text; } [[nodiscard]] inline const std::string& GetText() const { return m_text; }
[[nodiscard]] inline std::shared_ptr<Font> GetFont() const { return p_font; } [[nodiscard]] inline std::shared_ptr<Font> GetFont() const { return p_font; }
[[nodiscard]] MLX_FORCEINLINE std::uint32_t GetColor() const noexcept { return m_color; }
~Text(); virtual ~Text() = default;
private:
void Init(const std::string& text, std::shared_ptr<Font> font, std::shared_ptr<Mesh> mesh);
inline void Bind(std::size_t frame_index, VkCommandBuffer cmd) override
{
if(!p_set)
return;
p_set->SetImage(frame_index, 0, const_cast<Texture&>(p_font->GetTexture()));
p_set->Update(frame_index, cmd);
}
private: private:
std::shared_ptr<Font> p_font; std::shared_ptr<Font> p_font;
std::string m_text; std::string m_text;
std::uint32_t m_color;
}; };
} }

View File

@@ -96,6 +96,8 @@
#include <Utils/NonOwningPtr.h> #include <Utils/NonOwningPtr.h>
#include <Utils/NonCopyable.h> #include <Utils/NonCopyable.h>
constexpr const int RANGE = 1024;
using Handle = void*; using Handle = void*;
#endif #endif

View File

@@ -71,7 +71,7 @@ namespace mlx
bool m_is_multisampled = false; bool m_is_multisampled = false;
}; };
class Texture : public Image class Texture: public Image
{ {
public: public:
Texture() = default; Texture() = default;

View File

@@ -24,6 +24,7 @@ namespace mlx
m_fps.Init(); m_fps.Init();
p_render_core = std::make_unique<RenderCore>(); p_render_core = std::make_unique<RenderCore>();
LoadFont("default", 6.0f);
} }
void Application::Run() noexcept void Application::Run() noexcept

View File

@@ -155,13 +155,13 @@ extern "C"
MLX_CHECK_APPLICATION_POINTER(mlx); MLX_CHECK_APPLICATION_POINTER(mlx);
if (filename == nullptr) if (filename == nullptr)
{ {
mlx::Error("PNG loader : filename is NULL"); mlx::Error("PNG loader: filename is NULL");
return nullptr; return nullptr;
} }
std::filesystem::path file(filename); std::filesystem::path file(filename);
if(file.extension() != ".png") if(file.extension() != ".png")
{ {
mlx::Error("PNG loader : not a png file '%'", filename); mlx::Error("PNG loader: not a png file '%'", filename);
return nullptr; return nullptr;
} }
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height); return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
@@ -172,13 +172,13 @@ extern "C"
MLX_CHECK_APPLICATION_POINTER(mlx); MLX_CHECK_APPLICATION_POINTER(mlx);
if (filename == nullptr) if (filename == nullptr)
{ {
mlx::Error("JPG loader : filename is NULL"); mlx::Error("JPG loader: filename is NULL");
return nullptr; return nullptr;
} }
std::filesystem::path file(filename); std::filesystem::path file(filename);
if(file.extension() != ".jpg" && file.extension() != ".jpeg") if(file.extension() != ".jpg" && file.extension() != ".jpeg")
{ {
mlx::Error("JPG loader : not a jpg file '%'", filename); mlx::Error("JPG loader: not a jpg file '%'", filename);
return nullptr; return nullptr;
} }
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height); return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
@@ -189,13 +189,13 @@ extern "C"
MLX_CHECK_APPLICATION_POINTER(mlx); MLX_CHECK_APPLICATION_POINTER(mlx);
if (filename == nullptr) if (filename == nullptr)
{ {
mlx::Error("BMP loader : filename is NULL"); mlx::Error("BMP loader: filename is NULL");
return nullptr; return nullptr;
} }
std::filesystem::path file(filename); std::filesystem::path file(filename);
if(file.extension() != ".bmp" && file.extension() != ".dib") if(file.extension() != ".bmp" && file.extension() != ".dib")
{ {
mlx::Error("BMP loader : not a bmp file '%'", filename); mlx::Error("BMP loader: not a bmp file '%'", filename);
return nullptr; return nullptr;
} }
return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height); return static_cast<mlx::Application*>(mlx)->NewStbTexture(filename, width, height);
@@ -230,13 +230,13 @@ extern "C"
MLX_CHECK_APPLICATION_POINTER(mlx); MLX_CHECK_APPLICATION_POINTER(mlx);
if (filepath == nullptr) if (filepath == nullptr)
{ {
mlx::Error("Font loader : filepath is NULL"); mlx::Error("Font loader: filepath is NULL");
return; return;
} }
std::filesystem::path file(filepath); std::filesystem::path file(filepath);
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte") if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
{ {
mlx::Error("TTF loader : not a truetype font file '%'", filepath); mlx::Error("TTF loader: not a truetype font file '%'", filepath);
return; return;
} }
if(std::strcmp(filepath, "default") == 0) if(std::strcmp(filepath, "default") == 0)
@@ -250,13 +250,13 @@ extern "C"
MLX_CHECK_APPLICATION_POINTER(mlx); MLX_CHECK_APPLICATION_POINTER(mlx);
if (filepath == nullptr) if (filepath == nullptr)
{ {
mlx::Error("Font loader : filepath is NULL"); mlx::Error("Font loader: filepath is NULL");
return; return;
} }
std::filesystem::path file(filepath); std::filesystem::path file(filepath);
if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte") if(std::strcmp(filepath, "default") != 0 && file.extension() != ".ttf" && file.extension() != ".tte")
{ {
mlx::Error("TTF loader : not a truetype font file '%'", filepath); mlx::Error("TTF loader: not a truetype font file '%'", filepath);
return; return;
} }
static_cast<mlx::Application*>(mlx)->LoadFont(file, scale); static_cast<mlx::Application*>(mlx)->LoadFont(file, scale);

View File

@@ -43,7 +43,7 @@ namespace mlx
auto it = std::find(s_blocks.begin(), s_blocks.end(), ptr); auto it = std::find(s_blocks.begin(), s_blocks.end(), ptr);
if(it == s_blocks.end()) if(it == s_blocks.end())
{ {
Error("Memory Manager : trying to free a pointer not allocated by the memory manager"); Error("Memory Manager: trying to free a pointer not allocated by the memory manager");
return; return;
} }
std::free(*it); std::free(*it);

View File

@@ -16,7 +16,7 @@ namespace mlx
if(m_output_stream.is_open()) if(m_output_stream.is_open())
WriteHeader(); WriteHeader();
else else
Error("Profiler : cannot open runtime profile file"); Error("Profiler: cannot open runtime profile file");
m_runtime_session_began = true; m_runtime_session_began = true;
} }

View File

@@ -43,21 +43,21 @@ namespace mlx
#endif #endif
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0) if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_TIMER) != 0)
FatalError("SDL : unable to init all subsystems; %", SDL_GetError()); FatalError("SDL: unable to init all subsystems; %", SDL_GetError());
DebugLog("SDL Manager initialized"); DebugLog("SDL Manager initialized");
} }
Handle SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden, std::int32_t& id) Handle SDLManager::CreateWindow(const std::string& title, std::size_t w, std::size_t h, bool hidden, std::int32_t& id)
{ {
Internal::WindowInfos* infos = new Internal::WindowInfos; Internal::WindowInfos* infos = new Internal::WindowInfos;
Verify(infos != nullptr, "SDL : window allocation failed"); Verify(infos != nullptr, "SDL: window allocation failed");
if(title == "让我们在月光下做爱吧") if(title == "让我们在月光下做爱吧")
infos->window = SDL_CreateWindow(title.c_str(), std::rand() % 512, std::rand() % 512, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN)); infos->window = SDL_CreateWindow(title.c_str(), std::rand() % 512, std::rand() % 512, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN));
else else
infos->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN)); infos->window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_VULKAN | (hidden ? SDL_WINDOW_HIDDEN : SDL_WINDOW_SHOWN));
if(!infos->window) if(!infos->window)
FatalError("SDL : unable to open a new window; %", SDL_GetError()); FatalError("SDL: unable to open a new window; %", SDL_GetError());
infos->icon = SDL_CreateRGBSurfaceFrom(static_cast<void*>(logo_mlx), logo_mlx_width, logo_mlx_height, 32, 4 * logo_mlx_width, rmask, gmask, bmask, amask); infos->icon = SDL_CreateRGBSurfaceFrom(static_cast<void*>(logo_mlx), logo_mlx_width, logo_mlx_height, 32, 4 * logo_mlx_width, rmask, gmask, bmask, amask);
SDL_SetWindowIcon(infos->window, infos->icon); SDL_SetWindowIcon(infos->window, infos->icon);
@@ -70,7 +70,7 @@ namespace mlx
void SDLManager::DestroyWindow(Handle window) noexcept void SDLManager::DestroyWindow(Handle window) noexcept
{ {
Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL : cannot destroy window; unknown window pointer"); Verify(m_windows_registry.find(window) != m_windows_registry.end(), "SDL: cannot destroy window; unknown window pointer");
Internal::WindowInfos* infos = static_cast<Internal::WindowInfos*>(window); Internal::WindowInfos* infos = static_cast<Internal::WindowInfos*>(window);
if(infos->window != nullptr) if(infos->window != nullptr)
@@ -86,7 +86,7 @@ namespace mlx
{ {
VkSurfaceKHR surface; VkSurfaceKHR surface;
if(!SDL_Vulkan_CreateSurface(static_cast<Internal::WindowInfos*>(window)->window, instance, &surface)) if(!SDL_Vulkan_CreateSurface(static_cast<Internal::WindowInfos*>(window)->window, instance, &surface))
FatalError("SDL : could not create a Vulkan surface; %", SDL_GetError()); FatalError("SDL: could not create a Vulkan surface; %", SDL_GetError());
return surface; return surface;
} }
@@ -94,10 +94,10 @@ namespace mlx
{ {
std::uint32_t count; std::uint32_t count;
if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, nullptr)) if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, nullptr))
FatalError("SDL Manager : could not retrieve Vulkan instance extensions"); FatalError("SDL Manager: could not retrieve Vulkan instance extensions");
std::vector<const char*> extensions(count); std::vector<const char*> extensions(count);
if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, extensions.data())) if(!SDL_Vulkan_GetInstanceExtensions(static_cast<Internal::WindowInfos*>(window)->window, &count, extensions.data()))
FatalError("SDL Manager : could not retrieve Vulkan instance extensions"); FatalError("SDL Manager: could not retrieve Vulkan instance extensions");
extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME); extensions.push_back(VK_KHR_SURFACE_EXTENSION_NAME);
return extensions; return extensions;
} }

View File

@@ -10,8 +10,6 @@
namespace mlx namespace mlx
{ {
constexpr const int RANGE = 1024;
void Font::BuildFont() void Font::BuildFont()
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
@@ -21,7 +19,7 @@ namespace mlx
std::ifstream file(std::get<std::filesystem::path>(m_build_data), std::ios::binary); std::ifstream file(std::get<std::filesystem::path>(m_build_data), std::ios::binary);
if(!file.is_open()) if(!file.is_open())
{ {
Error("Font : cannot open font file, %", m_name); Error("Font: cannot open font file, %", m_name);
return; return;
} }
std::ifstream::pos_type file_size = std::filesystem::file_size(std::get<std::filesystem::path>(m_build_data)); std::ifstream::pos_type file_size = std::filesystem::file_size(std::get<std::filesystem::path>(m_build_data));
@@ -56,6 +54,8 @@ namespace mlx
#else #else
m_atlas.Init(vulkan_bitmap, RANGE, RANGE, VK_FORMAT_R8G8B8A8_SRGB, false, {}); m_atlas.Init(vulkan_bitmap, RANGE, RANGE, VK_FORMAT_R8G8B8A8_SRGB, false, {});
#endif #endif
DebugLog("Font: loaded %", m_name);
} }
void Font::Destroy() void Font::Destroy()

View File

@@ -1,3 +1,4 @@
#include "Graphics/Enums.h"
#include <PreCompiled.h> #include <PreCompiled.h>
#include <Graphics/Scene.h> #include <Graphics/Scene.h>
#include <Renderer/Renderer.h> #include <Renderer/Renderer.h>
@@ -10,64 +11,117 @@ namespace mlx
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
Verify((bool)texture, "Scene: invalid texture (internal mlx issue, please report to devs)"); Verify((bool)texture, "Scene: invalid texture (internal mlx issue, please report to devs)");
#pragma omp parallel for for(auto& drawable : m_drawables)
for(auto& sprite : m_sprites)
{ {
if(texture->GetWidth() == sprite->GetTexture()->GetWidth() && texture->GetHeight() == sprite->GetTexture()->GetHeight()) if(!drawable || drawable->GetType() != DrawableType::Sprite)
continue;
if(texture->GetWidth() == static_cast<Sprite*>(drawable.get())->GetTexture()->GetWidth() && texture->GetHeight() == static_cast<Sprite*>(drawable.get())->GetTexture()->GetHeight())
{ {
std::shared_ptr<Sprite> new_sprite = std::make_shared<Sprite>(sprite->GetMesh(), texture); std::shared_ptr<Sprite> new_sprite = std::make_shared<Sprite>(drawable->GetMesh(), texture);
m_sprites.push_back(new_sprite); m_drawables.push_back(new_sprite);
return *new_sprite; return *new_sprite;
} }
} }
std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture); std::shared_ptr<Sprite> sprite = std::make_shared<Sprite>(texture);
m_sprites.push_back(sprite); m_drawables.push_back(sprite);
return *sprite; return *sprite;
} }
NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const NonOwningPtr<Sprite> Scene::GetSpriteFromTextureAndPosition(NonOwningPtr<Texture> texture, const Vec2f& position) const
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture, &position](std::shared_ptr<Sprite> sprite) auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture, &position](std::shared_ptr<Drawable> drawable)
{ {
return sprite->GetTexture() == texture && sprite->GetPosition().x == position.x && sprite->GetPosition().y == position.y; if(!drawable || drawable->GetType() != DrawableType::Sprite)
return false;
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture && drawable->GetPosition() == position;
}); });
return (it != m_sprites.end() ? it->get() : nullptr); return static_cast<Sprite*>(it != m_drawables.end() ? it->get() : nullptr);
}
void Scene::BringToFront(NonOwningPtr<Sprite> sprite)
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_sprites.begin(), m_sprites.end(), [&sprite](std::shared_ptr<Sprite> sprite_ptr)
{
return sprite_ptr.get() == sprite.Get();
});
if(it == m_sprites.end())
return;
std::rotate(it, it + 1, m_sprites.end());
} }
void Scene::TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture) void Scene::TryEraseSpriteFromTexture(NonOwningPtr<Texture> texture)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
auto it = m_sprites.begin(); auto it = m_drawables.begin();
do do
{ {
it = std::find_if(m_sprites.begin(), m_sprites.end(), [&texture](std::shared_ptr<Sprite> sprite) it = std::find_if(m_drawables.begin(), m_drawables.end(), [&texture](std::shared_ptr<Drawable> drawable)
{ {
return sprite->GetTexture() == texture; if(!drawable || drawable->GetType() != DrawableType::Sprite)
return false;
return static_cast<Sprite*>(drawable.get())->GetTexture() == texture;
}); });
if(it != m_sprites.end()) if(it != m_drawables.end())
m_sprites.erase(it); m_drawables.erase(it);
} while(it != m_sprites.end()); } while(it != m_drawables.end());
} }
bool Scene::IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const bool Scene::IsTextureAtGivenDrawLayer(NonOwningPtr<Texture> texture, std::uint64_t draw_layer) const
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(draw_layer >= m_sprites.size()) if(draw_layer >= m_drawables.size())
return false; return false;
return m_sprites[draw_layer]->GetTexture() == texture; if(!m_drawables[draw_layer] || m_drawables[draw_layer]->GetType() != DrawableType::Sprite)
return false;
return static_cast<Sprite*>(m_drawables[draw_layer].get())->GetTexture() == texture;
}
Text& Scene::CreateText(const std::string& text) noexcept
{
MLX_PROFILE_FUNCTION();
Assert((bool)p_bound_font, "no font bound");
for(auto& drawable : m_drawables)
{
if(!drawable || drawable->GetType() != DrawableType::Text)
continue;
if(text == static_cast<Text*>(drawable.get())->GetText() && p_bound_font == static_cast<Text*>(drawable.get())->GetFont())
{
std::shared_ptr<Text> new_text = std::make_shared<Text>(text, p_bound_font, drawable->GetMesh());
m_drawables.push_back(new_text);
return *new_text;
}
}
std::shared_ptr<Text> new_text = std::make_shared<Text>(text, p_bound_font);
m_drawables.push_back(new_text);
return *new_text;
}
NonOwningPtr<Text> Scene::GetTextFromPositionAndColor(const std::string& text, const Vec2f& position, const Vec4f& color) const
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&text, &position, &color](std::shared_ptr<Drawable> drawable)
{
if(!drawable || drawable->GetType() != DrawableType::Text)
return false;
return static_cast<Text*>(drawable.get())->GetText() == text && drawable->GetPosition() == position && drawable->GetColor() == color;
});
return static_cast<Text*>(it != m_drawables.end() ? it->get() : nullptr);
}
bool Scene::IsTextAtGivenDrawLayer(const std::string& text, std::uint64_t draw_layer) const
{
MLX_PROFILE_FUNCTION();
if(draw_layer >= m_drawables.size())
return false;
if(!m_drawables[draw_layer] || m_drawables[draw_layer]->GetType() != DrawableType::Text)
return false;
Text* ptr = static_cast<Text*>(m_drawables[draw_layer].get());
return ptr->GetText() == text && ptr->GetFont() == p_bound_font;
}
void Scene::BringToFront(NonOwningPtr<Drawable> drawable)
{
MLX_PROFILE_FUNCTION();
auto it = std::find_if(m_drawables.begin(), m_drawables.end(), [&drawable](std::shared_ptr<Drawable> drawable_ptr)
{
return drawable_ptr.get() == drawable.Get();
});
if(it == m_drawables.end())
return;
std::rotate(it, it + 1, m_drawables.end());
} }
} }

View File

@@ -37,7 +37,7 @@ namespace mlx
return mesh; return mesh;
} }
Sprite::Sprite(NonOwningPtr<Texture> texture) Sprite::Sprite(NonOwningPtr<Texture> texture) : Drawable(DrawableType::Sprite)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)"); Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)");
@@ -45,7 +45,7 @@ namespace mlx
p_texture = texture; p_texture = texture;
} }
Sprite::Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture) Sprite::Sprite(std::shared_ptr<Mesh> mesh, NonOwningPtr<Texture> texture) : Drawable(DrawableType::Sprite)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)"); Verify((bool)texture, "Sprite: invalid texture (internal mlx issue, please report to devs)");

61
runtime/Sources/Graphics/Text.cpp git.filemode.normal_file
View File

@@ -0,0 +1,61 @@
#include <PreCompiled.h>
#include <Graphics/Text.h>
#define STB_RECT_PACK_IMPLEMENTATION
#include <stb_rect_pack.h>
namespace mlx
{
Text::Text(const std::string& text, std::shared_ptr<Font> font) : Drawable(DrawableType::Text)
{
MLX_PROFILE_FUNCTION();
Assert(font != nullptr, "invalid font");
std::vector<Vertex> vertex_data;
std::vector<std::uint32_t> index_data;
float stb_x = 0.0f;
float stb_y = 0.0f;
for(char c : text)
{
if(c < 32)
continue;
stbtt_aligned_quad q;
stbtt_GetPackedQuad(font->GetCharData().data(), RANGE, RANGE, c - 32, &stb_x, &stb_y, &q, 1);
std::size_t index = vertex_data.size();
vertex_data.emplace_back(Vec4f{ q.x0, q.y0, 0.0f, 0.0f }, Vec2f{ q.s0, q.t0 });
vertex_data.emplace_back(Vec4f{ q.x1, q.y0, 0.0f, 0.0f }, Vec2f{ q.s1, q.t0 });
vertex_data.emplace_back(Vec4f{ q.x1, q.y1, 0.0f, 0.0f }, Vec2f{ q.s1, q.t1 });
vertex_data.emplace_back(Vec4f{ q.x0, q.y1, 0.0f, 0.0f }, Vec2f{ q.s0, q.t1 });
index_data.emplace_back(index + 0);
index_data.emplace_back(index + 1);
index_data.emplace_back(index + 2);
index_data.emplace_back(index + 2);
index_data.emplace_back(index + 3);
index_data.emplace_back(index + 0);
}
std::shared_ptr<Mesh> mesh = std::make_shared<Mesh>();
mesh->AddSubMesh({ std::move(vertex_data), std::move(index_data) });
Init(text, font, mesh);
}
void Text::Init(const std::string& text, std::shared_ptr<Font> font, std::shared_ptr<Mesh> mesh)
{
MLX_PROFILE_FUNCTION();
Assert(font != nullptr, "invalid font");
Assert(mesh != nullptr, "invalid mesh");
p_mesh = mesh;
p_font = font;
m_text = text;
}
}

View File

@@ -15,7 +15,7 @@ namespace mlx
{ {
if(data.Empty()) if(data.Empty())
{ {
Warning("Vulkan : trying to create constant buffer without data (constant buffers cannot be modified after creation)"); Warning("Vulkan: trying to create constant buffer without data (constant buffers cannot be modified after creation)");
return; return;
} }
m_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT; m_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
@@ -70,12 +70,12 @@ namespace mlx
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(!(m_usage & VK_BUFFER_USAGE_TRANSFER_DST_BIT)) if(!(m_usage & VK_BUFFER_USAGE_TRANSFER_DST_BIT))
{ {
Error("Vulkan : buffer cannot be the destination of a copy because it does not have the correct usage flag"); Error("Vulkan: buffer cannot be the destination of a copy because it does not have the correct usage flag");
return false; return false;
} }
if(!(buffer.m_usage & VK_BUFFER_USAGE_TRANSFER_SRC_BIT)) if(!(buffer.m_usage & VK_BUFFER_USAGE_TRANSFER_SRC_BIT))
{ {
Error("Vulkan : buffer cannot be the source of a copy because it does not have the correct usage flag"); Error("Vulkan: buffer cannot be the source of a copy because it does not have the correct usage flag");
return false; return false;
} }
@@ -108,7 +108,7 @@ namespace mlx
if(new_buffer.CopyFrom(*this)) if(new_buffer.CopyFrom(*this))
Swap(new_buffer); Swap(new_buffer);
new_buffer.Destroy(); new_buffer.Destroy();
DebugLog("Vulkan : pushed buffer to GPU memory"); DebugLog("Vulkan: pushed buffer to GPU memory");
} }
void GPUBuffer::Destroy() noexcept void GPUBuffer::Destroy() noexcept
@@ -141,12 +141,12 @@ namespace mlx
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(data.GetSize() > m_size) if(data.GetSize() > m_size)
{ {
Error("Vulkan : trying to store to much data in a vertex buffer (% bytes in % bytes)", data.GetSize(), m_size); Error("Vulkan: trying to store to much data in a vertex buffer (% bytes in % bytes)", data.GetSize(), m_size);
return; return;
} }
if(data.Empty()) if(data.Empty())
{ {
Warning("Vulkan : cannot set empty data in a vertex buffer"); Warning("Vulkan: cannot set empty data in a vertex buffer");
return; return;
} }
GPUBuffer staging; GPUBuffer staging;
@@ -164,12 +164,12 @@ namespace mlx
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(data.GetSize() > m_size) if(data.GetSize() > m_size)
{ {
Error("Vulkan : trying to store to much data in an index buffer (% bytes in % bytes)", data.GetSize(), m_size); Error("Vulkan: trying to store to much data in an index buffer (% bytes in % bytes)", data.GetSize(), m_size);
return; return;
} }
if(data.Empty()) if(data.Empty())
{ {
Warning("Vulkan : cannot set empty data in an index buffer"); Warning("Vulkan: cannot set empty data in an index buffer");
return; return;
} }
GPUBuffer staging; GPUBuffer staging;
@@ -194,7 +194,7 @@ namespace mlx
#endif #endif
m_maps[i] = m_buffers[i].GetMap(); m_maps[i] = m_buffers[i].GetMap();
if(m_maps[i] == nullptr) if(m_maps[i] == nullptr)
FatalError("Vulkan : unable to map a uniform buffer"); FatalError("Vulkan: unable to map a uniform buffer");
} }
} }
@@ -203,7 +203,7 @@ namespace mlx
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(data.GetSize() != m_buffers[frame_index].GetSize()) if(data.GetSize() != m_buffers[frame_index].GetSize())
{ {
Error("Vulkan : invalid data size to update to a uniform buffer, % != %", data.GetSize(), m_buffers[frame_index].GetSize()); Error("Vulkan: invalid data size to update to a uniform buffer, % != %", data.GetSize(), m_buffers[frame_index].GetSize());
return; return;
} }
if(m_maps[frame_index] != nullptr) if(m_maps[frame_index] != nullptr)

View File

@@ -19,7 +19,7 @@ namespace mlx
if(image.GetType() == ImageType::Color) if(image.GetType() == ImageType::Color)
image.TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, cmd); image.TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, cmd);
else else
Error("Vulkan : cannot transition descriptor image layout, unkown image type"); Error("Vulkan: cannot transition descriptor image layout, unkown image type");
} }
void DescriptorPool::Init() noexcept void DescriptorPool::Init() noexcept
@@ -128,7 +128,7 @@ namespace mlx
}); });
if(it == m_used_sets.end()) if(it == m_used_sets.end())
{ {
Error("Vulkan : cannot return descriptor set to pool, invalid pool"); Error("Vulkan: cannot return descriptor set to pool, invalid pool");
return; return;
} }
m_used_sets.erase(it); m_used_sets.erase(it);
@@ -182,12 +182,12 @@ namespace mlx
}); });
if(it == m_descriptors.end()) if(it == m_descriptors.end())
{ {
Warning("Vulkan : cannot update descriptor set image; invalid binding"); Warning("Vulkan: cannot update descriptor set image; invalid binding");
return; return;
} }
if(it->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) if(it->type != VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
{ {
Error("Vulkan : trying to bind an image to the wrong descriptor"); Error("Vulkan: trying to bind an image to the wrong descriptor");
return; return;
} }
it->image_ptr = &image; it->image_ptr = &image;
@@ -203,12 +203,12 @@ namespace mlx
}); });
if(it == m_descriptors.end()) if(it == m_descriptors.end())
{ {
Warning("Vulkan : cannot update descriptor set buffer; invalid binding"); Warning("Vulkan: cannot update descriptor set buffer; invalid binding");
return; return;
} }
if(it->type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER) if(it->type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER)
{ {
Error("Vulkan : trying to bind a buffer to the wrong descriptor"); Error("Vulkan: trying to bind a buffer to the wrong descriptor");
return; return;
} }
it->storage_buffer_ptr = &buffer; it->storage_buffer_ptr = &buffer;
@@ -224,12 +224,12 @@ namespace mlx
}); });
if(it == m_descriptors.end()) if(it == m_descriptors.end())
{ {
Warning("Vulkan : cannot update descriptor set buffer; invalid binding"); Warning("Vulkan: cannot update descriptor set buffer; invalid binding");
return; return;
} }
if(it->type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER) if(it->type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
{ {
Error("Vulkan : trying to bind a buffer to the wrong descriptor"); Error("Vulkan: trying to bind a buffer to the wrong descriptor");
return; return;
} }
it->uniform_buffer_ptr = &buffer; it->uniform_buffer_ptr = &buffer;

View File

@@ -14,6 +14,12 @@
#include <stb_image.h> #include <stb_image.h>
#endif #endif
#ifdef IMAGE_OPTIMIZED
#define TILING VK_IMAGE_TILING_OPTIMAL
#else
#define TILING VK_IMAGE_TILING_LINEAR
#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, [[maybe_unused]] std::string_view debug_name) void Image::Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled, [[maybe_unused]] std::string_view debug_name)
@@ -153,7 +159,7 @@ namespace mlx
void Texture::Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, [[maybe_unused]] std::string_view debug_name) void Texture::Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format, bool is_multisampled, [[maybe_unused]] std::string_view debug_name)
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled, std::move(debug_name)); Image::Init(ImageType::Color, width, height, format, TILING, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled, std::move(debug_name));
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT); Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
Image::CreateSampler(); Image::CreateSampler();
if(pixels) if(pixels)
@@ -228,7 +234,7 @@ namespace mlx
if(m_staging_buffer.has_value()) if(m_staging_buffer.has_value())
return; return;
#ifdef DEBUG #ifdef DEBUG
DebugLog("Texture : enabling CPU mapping for '%'", m_debug_name); DebugLog("Texture: enabling CPU mapping for '%'", m_debug_name);
#endif #endif
m_staging_buffer.emplace(); m_staging_buffer.emplace();
std::size_t size = m_width * m_height * kvfFormatSize(m_format); std::size_t size = m_width * m_height * kvfFormatSize(m_format);
@@ -263,12 +269,12 @@ namespace mlx
if(!std::filesystem::exists(file)) if(!std::filesystem::exists(file))
{ {
Error("Image : file not found %", file); Error("Image: file not found %", file);
return nullptr; return nullptr;
} }
if(stbi_is_hdr(filename.c_str())) if(stbi_is_hdr(filename.c_str()))
{ {
Error("Texture : unsupported image format % (HDR image)", file); Error("Texture: unsupported image format % (HDR image)", file);
return nullptr; return nullptr;
} }
int dummy_w; int dummy_w;

View File

@@ -54,7 +54,7 @@ namespace mlx
allocator_create_info.pVulkanFunctions = &vma_vulkan_func; allocator_create_info.pVulkanFunctions = &vma_vulkan_func;
kvfCheckVk(vmaCreateAllocator(&allocator_create_info, &m_allocator)); kvfCheckVk(vmaCreateAllocator(&allocator_create_info, &m_allocator));
DebugLog("Graphics allocator : created new allocator"); DebugLog("Graphics Allocator: created new allocator");
} }
VmaAllocation GPUAllocator::CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) noexcept VmaAllocation GPUAllocator::CreateBuffer(const VkBufferCreateInfo* binfo, const VmaAllocationCreateInfo* vinfo, VkBuffer& buffer, const char* name) noexcept
@@ -74,7 +74,7 @@ namespace mlx
#endif #endif
vmaSetAllocationName(m_allocator, allocation, name); vmaSetAllocationName(m_allocator, allocation, name);
} }
DebugLog("Graphics Allocator : created new buffer '%'", name); DebugLog("Graphics Allocator: created new buffer '%'", name);
m_active_buffers_allocations++; m_active_buffers_allocations++;
return allocation; return allocation;
} }
@@ -85,9 +85,9 @@ namespace mlx
RenderCore::Get().WaitDeviceIdle(); RenderCore::Get().WaitDeviceIdle();
vmaDestroyBuffer(m_allocator, buffer, allocation); vmaDestroyBuffer(m_allocator, buffer, allocation);
if(name != nullptr) if(name != nullptr)
DebugLog("Graphics Allocator : destroyed buffer '%'", name); DebugLog("Graphics Allocator: destroyed buffer '%'", name);
else else
DebugLog("Graphics Allocator : destroyed buffer"); DebugLog("Graphics Allocator: destroyed buffer");
m_active_buffers_allocations--; m_active_buffers_allocations--;
} }
@@ -108,7 +108,7 @@ namespace mlx
#endif #endif
vmaSetAllocationName(m_allocator, allocation, name); vmaSetAllocationName(m_allocator, allocation, name);
} }
DebugLog("Graphics Allocator : created new image '%'", name); DebugLog("Graphics Allocator: created new image '%'", name);
m_active_images_allocations++; m_active_images_allocations++;
return allocation; return allocation;
} }
@@ -119,9 +119,9 @@ namespace mlx
RenderCore::Get().WaitDeviceIdle(); RenderCore::Get().WaitDeviceIdle();
vmaDestroyImage(m_allocator, image, allocation); vmaDestroyImage(m_allocator, image, allocation);
if(name != nullptr) if(name != nullptr)
DebugLog("Graphics Allocator : destroyed image '%'", name); DebugLog("Graphics Allocator: destroyed image '%'", name);
else else
DebugLog("Graphics Allocator : destroyed image"); DebugLog("Graphics Allocator: destroyed image");
m_active_images_allocations--; m_active_images_allocations--;
} }
@@ -145,7 +145,7 @@ namespace mlx
std::ofstream file(name); std::ofstream file(name);
if(!file.is_open()) if(!file.is_open())
{ {
Error("Graphics allocator : unable to dump memory to a json file"); Error("Graphics Allocator: unable to dump memory to a json file");
return; return;
} }
char* str = nullptr; char* str = nullptr;
@@ -166,14 +166,14 @@ namespace mlx
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(m_active_images_allocations != 0) if(m_active_images_allocations != 0)
Error("Graphics allocator : some user-dependant allocations were not freed before destroying the display (% active allocations). You may have not destroyed all the MLX resources you've created", m_active_images_allocations); Error("Graphics Allocator: some user-dependant allocations were not freed before destroying the display (% active allocations). You may have not destroyed all the MLX resources you've created", m_active_images_allocations);
else if(m_active_buffers_allocations != 0) else if(m_active_buffers_allocations != 0)
Error("Graphics allocator : some MLX-dependant allocations were not freed before destroying the display (% active allocations). This is an error in the MLX, please report this should not happen", m_active_buffers_allocations); Error("Graphics Allocator: some MLX-dependant allocations were not freed before destroying the display (% active allocations). This is an error in the MLX, please report this should not happen", m_active_buffers_allocations);
if(m_active_images_allocations < 0 || m_active_buffers_allocations < 0) if(m_active_images_allocations < 0 || m_active_buffers_allocations < 0)
Warning("Graphics allocator : the impossible happened, the MLX has freed more allocations than it has made (wtf)"); Warning("Graphics Allocator: the impossible happened, the MLX has freed more allocations than it has made (wtf)");
vmaDestroyAllocator(m_allocator); vmaDestroyAllocator(m_allocator);
m_active_buffers_allocations = 0; m_active_buffers_allocations = 0;
m_active_images_allocations = 0; m_active_images_allocations = 0;
DebugLog("Vulkan : destroyed a graphics allocator"); DebugLog("Vulkan: destroyed a graphics allocator");
} }
} }

View File

@@ -11,7 +11,7 @@ namespace mlx
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
if(!descriptor.vertex_shader || !descriptor.fragment_shader) if(!descriptor.vertex_shader || !descriptor.fragment_shader)
FatalError("Vulkan : invalid shaders"); FatalError("Vulkan: invalid shaders");
m_attachments = descriptor.color_attachments; m_attachments = descriptor.color_attachments;
p_vertex_shader = descriptor.vertex_shader; p_vertex_shader = descriptor.vertex_shader;
@@ -51,7 +51,7 @@ namespace mlx
} }
m_pipeline = kvfCreateGraphicsPipeline(RenderCore::Get().GetDevice(), m_pipeline_layout, builder, m_renderpass); m_pipeline = kvfCreateGraphicsPipeline(RenderCore::Get().GetDevice(), m_pipeline_layout, builder, m_renderpass);
DebugLog("Vulkan : graphics pipeline created"); DebugLog("Vulkan: graphics pipeline created");
kvfDestroyGPipelineBuilder(builder); kvfDestroyGPipelineBuilder(builder);
#ifdef MLX_HAS_DEBUG_UTILS_FUNCTIONS #ifdef MLX_HAS_DEBUG_UTILS_FUNCTIONS
@@ -132,18 +132,18 @@ namespace mlx
for(auto& fb : m_framebuffers) for(auto& fb : m_framebuffers)
{ {
kvfDestroyFramebuffer(RenderCore::Get().GetDevice(), fb); kvfDestroyFramebuffer(RenderCore::Get().GetDevice(), fb);
DebugLog("Vulkan : framebuffer destroyed"); DebugLog("Vulkan: framebuffer destroyed");
} }
m_framebuffers.clear(); m_framebuffers.clear();
kvfDestroyPipelineLayout(RenderCore::Get().GetDevice(), m_pipeline_layout); kvfDestroyPipelineLayout(RenderCore::Get().GetDevice(), m_pipeline_layout);
m_pipeline_layout = VK_NULL_HANDLE; m_pipeline_layout = VK_NULL_HANDLE;
DebugLog("Vulkan : graphics pipeline layout destroyed"); DebugLog("Vulkan: graphics pipeline layout destroyed");
kvfDestroyRenderPass(RenderCore::Get().GetDevice(), m_renderpass); kvfDestroyRenderPass(RenderCore::Get().GetDevice(), m_renderpass);
m_renderpass = VK_NULL_HANDLE; m_renderpass = VK_NULL_HANDLE;
DebugLog("Vulkan : renderpass destroyed"); DebugLog("Vulkan: renderpass destroyed");
kvfDestroyPipeline(RenderCore::Get().GetDevice(), m_pipeline); kvfDestroyPipeline(RenderCore::Get().GetDevice(), m_pipeline);
m_pipeline = VK_NULL_HANDLE; m_pipeline = VK_NULL_HANDLE;
DebugLog("Vulkan : graphics pipeline destroyed"); DebugLog("Vulkan: graphics pipeline destroyed");
} }
void GraphicPipeline::CreateFramebuffers(const std::vector<NonOwningPtr<Texture>>& render_targets, bool clear_attachments) void GraphicPipeline::CreateFramebuffers(const std::vector<NonOwningPtr<Texture>>& render_targets, bool clear_attachments)
@@ -167,7 +167,7 @@ namespace mlx
m_renderpass = kvfCreateRenderPass(RenderCore::Get().GetDevice(), attachments.data(), attachments.size(), GetPipelineBindPoint()); m_renderpass = kvfCreateRenderPass(RenderCore::Get().GetDevice(), attachments.data(), attachments.size(), GetPipelineBindPoint());
m_clears.clear(); m_clears.clear();
m_clears.resize(attachments.size()); m_clears.resize(attachments.size());
DebugLog("Vulkan : renderpass created"); DebugLog("Vulkan: renderpass created");
if(p_renderer) if(p_renderer)
{ {
@@ -175,14 +175,14 @@ namespace mlx
{ {
attachment_views[0] = image.GetImageView(); attachment_views[0] = image.GetImageView();
m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image.GetWidth(), .height = image.GetHeight() })); m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image.GetWidth(), .height = image.GetHeight() }));
DebugLog("Vulkan : framebuffer created"); DebugLog("Vulkan: framebuffer created");
} }
} }
#pragma omp parallel for #pragma omp parallel for
for(NonOwningPtr<Texture> image : render_targets) for(NonOwningPtr<Texture> image : render_targets)
{ {
m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image->GetWidth(), .height = image->GetHeight() })); m_framebuffers.push_back(kvfCreateFramebuffer(RenderCore::Get().GetDevice(), m_renderpass, attachment_views.data(), attachment_views.size(), { .width = image->GetWidth(), .height = image->GetHeight() }));
DebugLog("Vulkan : framebuffer created"); DebugLog("Vulkan: framebuffer created");
} }
} }

View File

@@ -15,7 +15,7 @@ namespace mlx
default : FatalError("wtf"); break; default : FatalError("wtf"); break;
} }
m_module = kvfCreateShaderModule(RenderCore::Get().GetDevice(), reinterpret_cast<std::uint32_t*>(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);
} }
@@ -35,7 +35,7 @@ namespace mlx
bindings[i].stageFlags = m_stage; bindings[i].stageFlags = m_stage;
} }
m_set_layouts.emplace_back(kvfCreateDescriptorSetLayout(RenderCore::Get().GetDevice(), bindings.data(), bindings.size())); m_set_layouts.emplace_back(kvfCreateDescriptorSetLayout(RenderCore::Get().GetDevice(), bindings.data(), bindings.size()));
DebugLog("Vulkan : descriptor set layout created"); DebugLog("Vulkan: descriptor set layout created");
m_pipeline_layout_part.set_layouts.push_back(m_set_layouts.back()); m_pipeline_layout_part.set_layouts.push_back(m_set_layouts.back());
} }
@@ -56,11 +56,11 @@ namespace mlx
{ {
MLX_PROFILE_FUNCTION(); MLX_PROFILE_FUNCTION();
kvfDestroyShaderModule(RenderCore::Get().GetDevice(), m_module); kvfDestroyShaderModule(RenderCore::Get().GetDevice(), m_module);
DebugLog("Vulkan : shader module destroyed"); DebugLog("Vulkan: shader module destroyed");
for(auto& layout : m_set_layouts) for(auto& layout : m_set_layouts)
{ {
kvfDestroyDescriptorSetLayout(RenderCore::Get().GetDevice(), layout); kvfDestroyDescriptorSetLayout(RenderCore::Get().GetDevice(), layout);
DebugLog("Vulkan : descriptor set layout destroyed"); DebugLog("Vulkan: descriptor set layout destroyed");
} }
} }
} }

View File

@@ -69,7 +69,7 @@ namespace mlx
#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);
LoadKVFInstanceVulkanFunctionPointers(); LoadKVFInstanceVulkanFunctionPointers();
@@ -81,13 +81,13 @@ namespace mlx
// just for style // just for style
VkPhysicalDeviceProperties props; VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(m_physical_device, &props); vkGetPhysicalDeviceProperties(m_physical_device, &props);
DebugLog("Vulkan : physical device picked '%'", props.deviceName); DebugLog("Vulkan: physical device picked '%'", props.deviceName);
const char* device_extensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; const char* device_extensions[] = { VK_KHR_SWAPCHAIN_EXTENSION_NAME };
VkPhysicalDeviceFeatures features{}; VkPhysicalDeviceFeatures features{};
vkGetPhysicalDeviceFeatures(m_physical_device, &features); vkGetPhysicalDeviceFeatures(m_physical_device, &features);
m_device = kvfCreateDevice(m_physical_device, device_extensions, sizeof(device_extensions) / sizeof(device_extensions[0]), &features); m_device = kvfCreateDevice(m_physical_device, device_extensions, sizeof(device_extensions) / sizeof(device_extensions[0]), &features);
DebugLog("Vulkan : logical device created"); DebugLog("Vulkan: logical device created");
loader->LoadDevice(m_device); loader->LoadDevice(m_device);
LoadKVFDeviceVulkanFunctionPointers(); LoadKVFDeviceVulkanFunctionPointers();
@@ -201,9 +201,9 @@ namespace mlx
m_descriptor_pool_manager.Destroy(); m_descriptor_pool_manager.Destroy();
m_allocator.Destroy(); m_allocator.Destroy();
kvfDestroyDevice(m_device); kvfDestroyDevice(m_device);
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(); loader.reset();
s_instance = nullptr; s_instance = nullptr;

View File

@@ -92,32 +92,31 @@ namespace mlx
VkCommandBuffer cmd = renderer.GetActiveCommandBuffer(); VkCommandBuffer cmd = renderer.GetActiveCommandBuffer();
const auto& sprites = scene.GetSprites(); const auto& drawables = scene.GetDrawables();
for(auto sprite : sprites) for(auto drawable : drawables)
{ {
// Check every textures and update modified ones to GPU before starting the render pass // Check every textures and update modified ones to GPU before starting the render pass
if(!sprite->IsSetInit()) if(!drawable->IsSetInit())
sprite->UpdateDescriptorSet(p_texture_set); drawable->UpdateDescriptorSet(p_texture_set);
Verify((bool)sprite->GetTexture(), "a sprite has no texture attached (internal mlx issue, please report to the devs)"); drawable->Update(cmd);
sprite->GetTexture()->Update(cmd);
} }
m_pipeline.BindPipeline(cmd, 0, {}); m_pipeline.BindPipeline(cmd, 0, {});
for(auto sprite : sprites) for(auto drawable : drawables)
{ {
SpriteData sprite_data; SpriteData drawable_data;
sprite_data.position = Vec4f{ sprite->GetPosition(), 0.0f, 1.0f }; drawable_data.position = Vec4f{ drawable->GetPosition(), 0.0f, 1.0f };
sprite_data.color = sprite->GetColor(); drawable_data.color = drawable->GetColor();
sprite->Bind(frame_index, cmd); drawable->Bind(frame_index, cmd);
std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), sprite->GetSet(frame_index) }; std::array<VkDescriptorSet, 2> sets = { p_viewer_data_set->GetSet(frame_index), drawable->GetSet(frame_index) };
RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &sprite_data); RenderCore::Get().vkCmdPushConstants(cmd, m_pipeline.GetPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(SpriteData), &drawable_data);
RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr); RenderCore::Get().vkCmdBindDescriptorSets(cmd, m_pipeline.GetPipelineBindPoint(), m_pipeline.GetPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
sprite->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef()); drawable->GetMesh()->Draw(cmd, renderer.GetDrawCallsCounterRef(), renderer.GetPolygonDrawnCounterRef());
} }
m_pipeline.EndPipeline(cmd); m_pipeline.EndPipeline(cmd);
} }

View File

@@ -33,20 +33,20 @@ namespace mlx
p_window = window; p_window = window;
m_surface = p_window->CreateVulkanSurface(RenderCore::Get().GetInstance()); m_surface = p_window->CreateVulkanSurface(RenderCore::Get().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(RenderCore::Get().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(RenderCore::Get().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(RenderCore::Get().GetDevice()); m_cmd_buffers[i] = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
DebugLog("Vulkan : command buffer created"); DebugLog("Vulkan: command buffer created");
m_cmd_fences[i] = kvfCreateFence(RenderCore::Get().GetDevice()); m_cmd_fences[i] = kvfCreateFence(RenderCore::Get().GetDevice());
DebugLog("Vulkan : fence created"); DebugLog("Vulkan: fence created");
} }
} }
@@ -63,7 +63,7 @@ namespace mlx
//return false; //return false;
} }
else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) else if(result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR)
FatalError("Vulkan error : failed to acquire swapchain image, %", kvfVerbaliseVkResult(result)); FatalError("Vulkan error: failed to acquire swapchain image, %", kvfVerbaliseVkResult(result));
RenderCore::Get().vkResetCommandBuffer(m_cmd_buffers[m_current_frame_index], 0); RenderCore::Get().vkResetCommandBuffer(m_cmd_buffers[m_current_frame_index], 0);
kvfBeginCommandBuffer(m_cmd_buffers[m_current_frame_index], 0); kvfBeginCommandBuffer(m_cmd_buffers[m_current_frame_index], 0);
@@ -110,7 +110,7 @@ namespace mlx
m_swapchain_images[i].TransitionLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR); m_swapchain_images[i].TransitionLayout(VK_IMAGE_LAYOUT_PRESENT_SRC_KHR);
m_swapchain_images[i].CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT); m_swapchain_images[i].CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
} }
DebugLog("Vulkan : swapchain created"); DebugLog("Vulkan: swapchain created");
} }
void Renderer::DestroySwapchain() void Renderer::DestroySwapchain()
@@ -120,7 +120,7 @@ namespace mlx
for(Image& img : m_swapchain_images) for(Image& img : m_swapchain_images)
img.DestroyImageView(); img.DestroyImageView();
kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), m_swapchain); kvfDestroySwapchainKHR(RenderCore::Get().GetDevice(), m_swapchain);
DebugLog("Vulkan : swapchain destroyed"); DebugLog("Vulkan: swapchain destroyed");
} }
void Renderer::Destroy() noexcept void Renderer::Destroy() noexcept
@@ -131,16 +131,16 @@ namespace mlx
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(RenderCore::Get().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(RenderCore::Get().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(RenderCore::Get().GetDevice(), m_cmd_fences[i]); kvfDestroyFence(RenderCore::Get().GetDevice(), m_cmd_fences[i]);
DebugLog("Vulkan : fence destroyed"); DebugLog("Vulkan: fence destroyed");
} }
DestroySwapchain(); DestroySwapchain();
RenderCore::Get().vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr); RenderCore::Get().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;
} }
} }

View File

@@ -30,8 +30,8 @@ namespace mlx
{ {
PFN_vkVoidFunction function = RenderCore::Get().vkGetInstanceProcAddr(static_cast<VkInstance>(context), name); PFN_vkVoidFunction function = RenderCore::Get().vkGetInstanceProcAddr(static_cast<VkInstance>(context), name);
if(!function) if(!function)
FatalError("Vulkan loader : could not load '%'", name); FatalError("Vulkan Loader: could not load '%'", name);
//DebugLog("Vulkan loader : loaded %", name); //DebugLog("Vulkan Loader: loaded %", name);
return function; return function;
} }
@@ -39,8 +39,8 @@ namespace mlx
{ {
PFN_vkVoidFunction function = RenderCore::Get().vkGetDeviceProcAddr(static_cast<VkDevice>(context), name); PFN_vkVoidFunction function = RenderCore::Get().vkGetDeviceProcAddr(static_cast<VkDevice>(context), name);
if(!function) if(!function)
FatalError("Vulkan loader : could not load '%'", name); FatalError("Vulkan Loader: could not load '%'", name);
//DebugLog("Vulkan loader : loaded %", name); //DebugLog("Vulkan Loader: loaded %", name);
return function; return function;
} }
@@ -95,13 +95,13 @@ namespace mlx
RESTORE_GCC_PEDANTIC_WARNINGS RESTORE_GCC_PEDANTIC_WARNINGS
if(RenderCore::Get().vkGetInstanceProcAddr) if(RenderCore::Get().vkGetInstanceProcAddr)
{ {
DebugLog("Vulkan loader : libvulkan loaded using '%'", libname); DebugLog("Vulkan Loader: libvulkan loaded using '%'", libname);
break; break;
} }
} }
} }
if(!p_module || !RenderCore::Get().vkGetInstanceProcAddr) if(!p_module || !RenderCore::Get().vkGetInstanceProcAddr)
FatalError("Vulkan loader : failed to load libvulkan"); FatalError("Vulkan Loader: failed to load libvulkan");
LoadGlobalFunctions(nullptr, Internal::vkGetInstanceProcAddrStub); LoadGlobalFunctions(nullptr, Internal::vkGetInstanceProcAddrStub);
} }
@@ -120,7 +120,7 @@ namespace mlx
#define MLX_VULKAN_GLOBAL_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn)); #define MLX_VULKAN_GLOBAL_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
#include <Renderer/Vulkan/VulkanDefs.h> #include <Renderer/Vulkan/VulkanDefs.h>
#undef MLX_VULKAN_GLOBAL_FUNCTION #undef MLX_VULKAN_GLOBAL_FUNCTION
DebugLog("Vulkan loader : global functions loaded"); DebugLog("Vulkan Loader: global functions loaded");
} }
void VulkanLoader::LoadInstanceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept void VulkanLoader::LoadInstanceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept
@@ -128,7 +128,7 @@ namespace mlx
#define MLX_VULKAN_INSTANCE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn)); #define MLX_VULKAN_INSTANCE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
#include <Renderer/Vulkan/VulkanDefs.h> #include <Renderer/Vulkan/VulkanDefs.h>
#undef MLX_VULKAN_INSTANCE_FUNCTION #undef MLX_VULKAN_INSTANCE_FUNCTION
DebugLog("Vulkan loader : instance functions loaded"); DebugLog("Vulkan Loader: instance functions loaded");
} }
void VulkanLoader::LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept void VulkanLoader::LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept
@@ -136,7 +136,7 @@ namespace mlx
#define MLX_VULKAN_DEVICE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn)); #define MLX_VULKAN_DEVICE_FUNCTION(fn) RenderCore::Get().fn = reinterpret_cast<PFN_##fn>(load(context, #fn));
#include <Renderer/Vulkan/VulkanDefs.h> #include <Renderer/Vulkan/VulkanDefs.h>
#undef MLX_VULKAN_DEVICE_FUNCTION #undef MLX_VULKAN_DEVICE_FUNCTION
DebugLog("Vulkan loader : device functions loaded"); DebugLog("Vulkan Loader: device functions loaded");
} }
VulkanLoader::~VulkanLoader() VulkanLoader::~VulkanLoader()
@@ -147,6 +147,6 @@ namespace mlx
dlclose(p_module); dlclose(p_module);
#endif #endif
p_module = nullptr; p_module = nullptr;
DebugLog("Vulkan loader : libvulkan unloaded"); DebugLog("Vulkan Loader: libvulkan unloaded");
} }
} }

12
third_party/kvf.h vendored
View File

@@ -894,7 +894,7 @@ VkPipelineStageFlags kvfLayoutToAccessMask(VkImageLayout layout, bool is_destina
{ {
case VK_IMAGE_LAYOUT_UNDEFINED: case VK_IMAGE_LAYOUT_UNDEFINED:
if(is_destination) if(is_destination)
KVF_ASSERT(false && "Vulkan : the new layout used in a transition must not be VK_IMAGE_LAYOUT_UNDEFINED"); KVF_ASSERT(false && "Vulkan: the new layout used in a transition must not be VK_IMAGE_LAYOUT_UNDEFINED");
break; break;
case VK_IMAGE_LAYOUT_GENERAL: access_mask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; break; case VK_IMAGE_LAYOUT_GENERAL: access_mask = VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT; break;
case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: access_mask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break; case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: access_mask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break;
@@ -909,13 +909,13 @@ VkPipelineStageFlags kvfLayoutToAccessMask(VkImageLayout layout, bool is_destina
if(!is_destination) if(!is_destination)
access_mask = VK_ACCESS_HOST_WRITE_BIT; access_mask = VK_ACCESS_HOST_WRITE_BIT;
else else
KVF_ASSERT(false && "Vulkan : the new layout used in a transition must not be VK_IMAGE_LAYOUT_PREINITIALIZED"); KVF_ASSERT(false && "Vulkan: the new layout used in a transition must not be VK_IMAGE_LAYOUT_PREINITIALIZED");
break; break;
case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: access_mask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL: access_mask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: access_mask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break; case VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL: access_mask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: access_mask = VK_ACCESS_MEMORY_READ_BIT; break; case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR: access_mask = VK_ACCESS_MEMORY_READ_BIT; break;
default: KVF_ASSERT(false && "Vulkan : unexpected image layout"); break; default: KVF_ASSERT(false && "Vulkan: unexpected image layout"); break;
} }
return access_mask; return access_mask;
@@ -929,7 +929,7 @@ VkPipelineStageFlags kvfAccessFlagsToPipelineStage(VkAccessFlags access_flags, V
{ {
VkAccessFlagBits _access_flag = (VkAccessFlagBits)(access_flags & (~(access_flags - 1))); VkAccessFlagBits _access_flag = (VkAccessFlagBits)(access_flags & (~(access_flags - 1)));
if(_access_flag == 0 || (_access_flag & (_access_flag - 1)) != 0) if(_access_flag == 0 || (_access_flag & (_access_flag - 1)) != 0)
KVF_ASSERT(false && "Vulkan : an error has been caught during access flag to pipeline stage operation"); KVF_ASSERT(false && "Vulkan: an error has been caught during access flag to pipeline stage operation");
access_flags &= ~_access_flag; access_flags &= ~_access_flag;
switch(_access_flag) switch(_access_flag)
@@ -952,7 +952,7 @@ VkPipelineStageFlags kvfAccessFlagsToPipelineStage(VkAccessFlags access_flags, V
case VK_ACCESS_MEMORY_READ_BIT: break; case VK_ACCESS_MEMORY_READ_BIT: break;
case VK_ACCESS_MEMORY_WRITE_BIT: break; case VK_ACCESS_MEMORY_WRITE_BIT: break;
default: KVF_ASSERT(false && "Vulkan : unknown access flag"); break; default: KVF_ASSERT(false && "Vulkan: unknown access flag"); break;
} }
} }
return stages; return stages;
@@ -973,7 +973,7 @@ VkFormat kvfFindSupportFormatInCandidates(VkDevice device, VkFormat* candidates,
return candidates[i]; return candidates[i];
} }
KVF_ASSERT(false && "Vulkan : failed to find image format"); KVF_ASSERT(false && "Vulkan: failed to find image format");
return VK_FORMAT_R8G8B8A8_SRGB; // just to avoir warning return VK_FORMAT_R8G8B8A8_SRGB; // just to avoir warning
} }