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:
@@ -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; }
|
||||
|
||||
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:
|
||||
SDLManager() = default;
|
||||
~SDLManager() = default;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace mlx
|
||||
public:
|
||||
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 GetY() const noexcept;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_vulkan.h>
|
||||
|
||||
#include <Renderer/Vulkan/VulkanPrototypes.h>
|
||||
#include <kvf.h>
|
||||
|
||||
#include <functional>
|
||||
@@ -71,7 +72,6 @@
|
||||
#include <Core/EventBus.h>
|
||||
#include <Core/Profiler.h>
|
||||
#include <Utils/NonOwningPtr.h>
|
||||
#include <Renderer/Vulkan/VulkanPrototypes.h>
|
||||
|
||||
using Handle = void*;
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ namespace mlx
|
||||
void SetPixel(int x, int y, std::uint32_t color) noexcept;
|
||||
int GetPixel(int x, int y) noexcept;
|
||||
|
||||
void Update(VkCommandBuffer cmd) const;
|
||||
void Update(VkCommandBuffer cmd);
|
||||
|
||||
~Texture() override { Destroy(); }
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace mlx
|
||||
[[nodiscard]] MLX_FORCEINLINE VkPhysicalDevice GetPhysicalDevice() const noexcept { return m_physical_device; }
|
||||
[[nodiscard]] MLX_FORCEINLINE GPUAllocator& GetAllocator() noexcept { return m_allocator; }
|
||||
|
||||
|
||||
inline void WaitDeviceIdle() const noexcept { vkDeviceWaitIdle(m_device); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __SCOP_VK_PROTOTYPES__
|
||||
#define __SCOP_VK_PROTOTYPES__
|
||||
#ifndef __MLX_VK_PROTOTYPES__
|
||||
#define __MLX_VK_PROTOTYPES__
|
||||
|
||||
#if defined(VULKAN_H_) && !defined(VK_NO_PROTOTYPES)
|
||||
#error "define VK_NO_PROTOTYPES needed"
|
||||
|
||||
@@ -16,6 +16,7 @@ namespace mlx
|
||||
NonOwningPtr<T>& NonOwningPtr<T>::operator=(T* ptr)
|
||||
{
|
||||
p_ptr = ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -23,6 +24,7 @@ namespace mlx
|
||||
{
|
||||
p_ptr = ptr.p_ptr;
|
||||
ptr.p_ptr = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -13,9 +13,7 @@ namespace mlx
|
||||
EventBus::RegisterListener({[](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::FatalErrorEventCode)
|
||||
{
|
||||
std::abort();
|
||||
}
|
||||
}, "__MlxApplication" });
|
||||
|
||||
m_fps.Init();
|
||||
|
||||
@@ -38,11 +38,11 @@ namespace mlx
|
||||
|
||||
switch(type)
|
||||
{
|
||||
case LogType::Debug: std::cout << Ansi::blue << "[Akel 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::Warning: std::cout << Ansi::magenta << "[Akel 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::FatalError: std::cerr << Ansi::red << "[Akel Fatal Error] " << 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 << "[MLX Message] " << 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 << "[MLX 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;
|
||||
}
|
||||
|
||||
@@ -56,10 +56,6 @@ namespace mlx
|
||||
{
|
||||
WatcherData* data = static_cast<WatcherData*>(userdata);
|
||||
|
||||
if(event->type == SDL_MOUSEMOTION)
|
||||
{
|
||||
}
|
||||
|
||||
std::uint32_t id = event->window.windowID;
|
||||
switch(event->type)
|
||||
{
|
||||
@@ -102,6 +98,7 @@ namespace mlx
|
||||
|
||||
return 0;
|
||||
}, &watcher_data);
|
||||
DebugLog("SDL Manager initialized");
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
if(m_drop_sdl_responsability)
|
||||
return;
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS);
|
||||
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);
|
||||
}, 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)
|
||||
: 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++)
|
||||
m_set[i] = kvfAllocateDescriptorSet(RenderCore::Get().GetDevice(), layout);
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
#include <Maths/Vec4.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
|
||||
{
|
||||
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.samples = (m_is_multisampled ? VK_SAMPLE_COUNT_4_BIT : VK_SAMPLE_COUNT_1_BIT);
|
||||
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
|
||||
@@ -77,11 +87,11 @@ namespace mlx
|
||||
{
|
||||
VkImageSubresourceRange subresource_range{};
|
||||
subresource_range.baseMipLevel = 0;
|
||||
subresource_range.layerCount = (m_type == ImageType::Cube ? 6 : 1);
|
||||
subresource_range.layerCount = 1;
|
||||
subresource_range.levelCount = 1;
|
||||
subresource_range.baseArrayLayer = 0;
|
||||
|
||||
if(m_type == ImageType::Color || m_type == ImageType::Cube)
|
||||
if(m_type == ImageType::Color)
|
||||
{
|
||||
VkImageLayout old_layout = m_layout;
|
||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
||||
@@ -134,10 +144,10 @@ namespace mlx
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
int GetPixel(int x, int y) noexcept
|
||||
int Texture::GetPixel(int x, int y) noexcept
|
||||
{
|
||||
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;
|
||||
if(!m_staging_buffer.has_value())
|
||||
OpenCPUBuffer();
|
||||
@@ -149,22 +159,16 @@ namespace mlx
|
||||
return *reinterpret_cast<int*>(bytes);
|
||||
}
|
||||
|
||||
void Update(VkCommandBuffer cmd) const
|
||||
void Texture::Update(VkCommandBuffer cmd)
|
||||
{
|
||||
if(!m_has_been_modified)
|
||||
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;
|
||||
VkCommandBuffer cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||
kvfBeginCommandBuffer(cmd, VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT);
|
||||
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);
|
||||
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;
|
||||
}
|
||||
@@ -176,14 +180,14 @@ namespace mlx
|
||||
return;
|
||||
DebugLog("Texture : enabling CPU mapping");
|
||||
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, {});
|
||||
|
||||
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_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);
|
||||
vkEndCommandBuffer(cmd);
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
@@ -191,7 +195,7 @@ namespace mlx
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||
|
||||
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)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <Renderer/Vertex.h>
|
||||
#include <Core/EventBus.h>
|
||||
|
||||
namespace Scop
|
||||
namespace mlx
|
||||
{
|
||||
void GraphicPipeline::Init(const GraphicPipelineDescriptor& descriptor)
|
||||
{
|
||||
@@ -39,7 +39,7 @@ namespace Scop
|
||||
kvfGPipelineBuilderSetCullMode(builder, VK_CULL_MODE_NONE, VK_FRONT_FACE_CLOCKWISE);
|
||||
kvfGPipelineBuilderEnableAlphaBlending(builder);
|
||||
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
|
||||
kvfGPipelineBuilderDisableDepthTest(builder);
|
||||
kvfGPipelineBuilderSetPolygonMode(builder, VK_POLYGON_MODE_FILL, 1.0f);
|
||||
@@ -80,7 +80,7 @@ namespace Scop
|
||||
scissor.extent = fb_extent;
|
||||
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[1] = clear[1];
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
#include <Renderer/Pipelines/Shader.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)
|
||||
{
|
||||
@@ -14,7 +14,7 @@ namespace Scop
|
||||
|
||||
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");
|
||||
|
||||
GeneratePipelineLayout(m_layout);
|
||||
@@ -63,21 +63,4 @@ namespace Scop
|
||||
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
|
||||
{
|
||||
static VulkanLoader loader;
|
||||
static std::unique_ptr<VulkanLoader> loader;
|
||||
|
||||
void ErrorCallback(const char* message) noexcept
|
||||
{
|
||||
FatalError(message);
|
||||
FatalError(message, 0, "", "");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void ValidationErrorCallback(const char* message) noexcept
|
||||
{
|
||||
Error(message);
|
||||
Error(message, 0, "", "");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void ValidationWarningCallback(const char* message) noexcept
|
||||
{
|
||||
Warning(message);
|
||||
Warning(message, 0, "", "");
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
void RenderCore::Init() noexcept
|
||||
{
|
||||
loader = std::make_unique<VulkanLoader>();
|
||||
|
||||
kvfSetErrorCallback(&ErrorCallback);
|
||||
kvfSetValidationErrorCallback(&ValidationErrorCallback);
|
||||
kvfSetValidationWarningCallback(&ValidationWarningCallback);
|
||||
@@ -41,15 +43,15 @@ namespace mlx
|
||||
//kvfAddLayer("VK_LAYER_MESA_overlay");
|
||||
|
||||
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
|
||||
instance_extentions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||
instance_extensions.push_back(VK_KHR_PORTABILITY_ENUMERATION_EXTENSION_NAME);
|
||||
#endif
|
||||
|
||||
m_instance = kvfCreateInstance(instance_extensions.data(), instance_extensions.size());
|
||||
DebugLog("Vulkan : instance created");
|
||||
|
||||
loader.LoadInstance(m_instance);
|
||||
loader->LoadInstance(m_instance);
|
||||
|
||||
VkSurfaceKHR surface = window.CreateVulkanSurface(m_instance);
|
||||
|
||||
@@ -77,5 +79,6 @@ namespace mlx
|
||||
DebugLog("Vulkan : logical device destroyed");
|
||||
kvfDestroyInstance(m_instance);
|
||||
DebugLog("Vulkan : instance destroyed");
|
||||
loader.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace mlx
|
||||
std::vector<std::uint8_t> fragment_shader_code = {
|
||||
#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)
|
||||
{
|
||||
@@ -50,7 +50,7 @@ namespace mlx
|
||||
if(event.What() == Event::DescriptorPoolResetEventCode)
|
||||
{
|
||||
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++)
|
||||
{
|
||||
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_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++)
|
||||
{
|
||||
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.fragment_shader = p_fragment_shader;
|
||||
pipeline_descriptor.color_attachments = { &render_target };
|
||||
pipeline_descriptor.depth = scene.GetDepth();
|
||||
pipeline_descriptor.depth = &scene.GetDepth();
|
||||
pipeline_descriptor.clear_color_attachments = false;
|
||||
m_pipeline.Init(pipeline_descriptor);
|
||||
}
|
||||
@@ -88,8 +88,8 @@ namespace mlx
|
||||
std::uint32_t frame_index = renderer.GetCurrentFrameIndex();
|
||||
|
||||
ViewerData viewer_data;
|
||||
viewer_data.projection = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f);
|
||||
static CPUBuffer buffer(sizeof(ViewerData2D));
|
||||
viewer_data.projection_matrix = Mat4f::Ortho(0.0f, render_target.GetWidth(), render_target.GetHeight(), 0.0f);
|
||||
static CPUBuffer buffer(sizeof(ViewerData));
|
||||
std::memcpy(buffer.GetData(), &viewer_data, buffer.GetSize());
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -36,21 +36,20 @@ namespace mlx
|
||||
|
||||
p_window = window;
|
||||
|
||||
auto& render_core = RenderCore::Get();
|
||||
m_surface = p_window->CreateVulkanSurface(render_core::GetInstance());
|
||||
m_surface = p_window->CreateVulkanSurface(RenderCore::Get().GetInstance());
|
||||
DebugLog("Vulkan : surface created");
|
||||
|
||||
CreateSwapchain();
|
||||
|
||||
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");
|
||||
m_render_finished_semaphores[i] = kvfCreateSemaphore(render_core.GetDevice());
|
||||
m_render_finished_semaphores[i] = kvfCreateSemaphore(RenderCore::Get().GetDevice());
|
||||
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");
|
||||
m_cmd_fences[i] = kvfCreateFence(render_core.GetDevice());
|
||||
m_cmd_fences[i] = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
DebugLog("Vulkan : fence created");
|
||||
}
|
||||
}
|
||||
@@ -124,21 +123,20 @@ namespace mlx
|
||||
|
||||
void Renderer::Destroy() noexcept
|
||||
{
|
||||
auto& render_core = RenderCore::Get();
|
||||
render_core.WaitDeviceIdle();
|
||||
RenderCore::Get().WaitDeviceIdle();
|
||||
|
||||
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");
|
||||
kvfDestroySemaphore(render_core.GetDevice(), m_render_finished_semaphores[i]);
|
||||
kvfDestroySemaphore(RenderCore::Get().GetDevice(), m_render_finished_semaphores[i]);
|
||||
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");
|
||||
}
|
||||
|
||||
DestroySwapchain();
|
||||
vkDestroySurfaceKHR(render_core.GetInstance(), m_surface, nullptr);
|
||||
vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr);
|
||||
DebugLog("Vulkan : surface destroyed");
|
||||
m_surface = VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Graphics/Scene.h>
|
||||
#include <Renderer/ViewerData.h>
|
||||
|
||||
namespacemlx
|
||||
namespace mlx
|
||||
{
|
||||
void SceneRenderer::Init()
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <PreCompiled.h>
|
||||
#include <Renderer/Vulkan/VulkanLoader.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef MLX_PLAT_WINDOWS
|
||||
__declspec(dllimport) HMODULE __stdcall LoadLibraryA(LPCSTR);
|
||||
__declspec(dllimport) FARPROC __stdcall GetProcAddress(HMODULE, LPCSTR);
|
||||
__declspec(dllimport) int __stdcall FreeLibrary(HMODULE);
|
||||
@@ -22,20 +22,20 @@ namespace mlx
|
||||
{
|
||||
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()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if defined(MLX_PLAT_WINDOWS)
|
||||
p_module = LoadLibraryA("vulkan-1.dll");
|
||||
if(!p_module)
|
||||
FatalError("Vulkan loader : failed to load libvulkan");
|
||||
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);
|
||||
if(!p_module)
|
||||
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);
|
||||
if(!p_module)
|
||||
FatalError("Vulkan loader : failed to load libvulkan");
|
||||
|
||||
vkGetInstanceProcAddr = (PFN_vkGetInstanceProcAddr)dlsym(p_module, "vkGetInstanceProcAddr");
|
||||
void* symbol_ptr = dlsym(p_module, "vkGetInstanceProcAddr");
|
||||
*(void**)(&vkGetInstanceProcAddr) = symbol_ptr;
|
||||
#else
|
||||
dlerror();
|
||||
p_module = dlopen("libvulkan.so.1", RTLD_NOW | RTLD_LOCAL);
|
||||
if(!p_module)
|
||||
p_module = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
|
||||
if(!p_module)
|
||||
FatalError("Vulkan loader : failed to load libvulkan");
|
||||
FatalError("Vulkan loader : failed to load libvulkan due to %", dlerror());
|
||||
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
|
||||
#endif
|
||||
DebugLog("Vulkan loader : libvulkan loaded");
|
||||
@@ -251,7 +253,7 @@ namespace mlx
|
||||
|
||||
VulkanLoader::~VulkanLoader()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
#if defined(MLX_PLAT_WINDOWS)
|
||||
FreeLibrary((HMODULE)p_module);
|
||||
#else
|
||||
dlclose(p_module);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#ifndef __MLX_VULKAN_LOADER__
|
||||
#define __MLX_VULKAN_LOADER__
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <mlx_profile.h>
|
||||
|
||||
#ifdef MLX_PLAT_WINDOWS
|
||||
typedef const char* LPCSTR;
|
||||
typedef struct HINSTANCE__* HINSTANCE;
|
||||
typedef HINSTANCE HMODULE;
|
||||
@@ -31,7 +33,7 @@ namespace mlx
|
||||
void LoadDeviceFunctions(void* context, PFN_vkVoidFunction (*load)(void*, const char*)) noexcept;
|
||||
|
||||
private:
|
||||
#ifdef _WIN32
|
||||
#ifdef MLX_PLAT_WINDOWS
|
||||
HMODULE p_module = nullptr;
|
||||
#else
|
||||
Handle p_module = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user