mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 06:33:35 +00:00
wtf is hapenning
This commit is contained in:
@@ -87,7 +87,6 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
NonOwningPtr<Sprite> sprite = p_scene->GetSpriteFromTexturePositionScaleRotation(texture, Vec2f{ static_cast<float>(x), static_cast<float>(y) }, scale_x, scale_y, angle);
|
||||
std::cout << sprite.Get() << std::endl;
|
||||
if(!sprite)
|
||||
{
|
||||
if(m_pixelput_called)
|
||||
|
||||
@@ -19,7 +19,8 @@ namespace mlx
|
||||
|
||||
void Swap(GPUBuffer& buffer) noexcept;
|
||||
|
||||
[[nodiscard]] MLX_FORCEINLINE void* GetMap() const noexcept { return p_map; }
|
||||
template<typename T = void*>
|
||||
[[nodiscard]] MLX_FORCEINLINE T GetMap() const noexcept { return reinterpret_cast<T>(p_map); }
|
||||
[[nodiscard]] MLX_FORCEINLINE VkBuffer Get() const noexcept { return m_buffer; }
|
||||
[[nodiscard]] MLX_FORCEINLINE VmaAllocation GetAllocation() const noexcept { return m_allocation; }
|
||||
[[nodiscard]] MLX_FORCEINLINE VkDeviceSize GetSize() const noexcept { return m_size; }
|
||||
|
||||
@@ -98,7 +98,6 @@ namespace mlx
|
||||
void OpenCPUBuffer();
|
||||
|
||||
private:
|
||||
std::vector<mlx_color> m_cpu_buffer;
|
||||
std::optional<GPUBuffer> m_staging_buffer;
|
||||
bool m_has_been_modified = false;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
alloc_info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO;
|
||||
|
||||
if(type == BufferType::Constant)
|
||||
@@ -86,6 +86,7 @@ namespace mlx
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,8 @@ namespace mlx
|
||||
if(is_single_time_cmd_buffer)
|
||||
cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||
kvfTransitionImageLayout(RenderCore::Get().GetDevice(), m_image, KVF_IMAGE_COLOR, cmd, m_format, m_layout, new_layout, is_single_time_cmd_buffer);
|
||||
if(is_single_time_cmd_buffer)
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
m_layout = new_layout;
|
||||
}
|
||||
|
||||
@@ -140,6 +142,7 @@ namespace mlx
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,6 +202,7 @@ namespace mlx
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
staging_buffer.Destroy();
|
||||
}
|
||||
TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
@@ -219,9 +223,9 @@ namespace mlx
|
||||
if(!m_staging_buffer.has_value())
|
||||
OpenCPUBuffer();
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
m_cpu_buffer[(y * m_width) + x] = ReverseColor(color);
|
||||
m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x] = ReverseColor(color);
|
||||
else
|
||||
m_cpu_buffer[(y * m_width) + x] = color;
|
||||
m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x] = color;
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
|
||||
@@ -244,9 +248,9 @@ namespace mlx
|
||||
moving_y++;
|
||||
}
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
m_cpu_buffer[(moving_y * m_width) + moving_x] = ReverseColor(pixels[i]);
|
||||
m_staging_buffer->GetMap<mlx_color*>()[(moving_y * m_width) + moving_x] = ReverseColor(pixels[i]);
|
||||
else
|
||||
m_cpu_buffer[(moving_y * m_width) + moving_x] = pixels[i];
|
||||
m_staging_buffer->GetMap<mlx_color*>()[(moving_y * m_width) + moving_x] = pixels[i];
|
||||
}
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
@@ -259,11 +263,13 @@ namespace mlx
|
||||
if(!m_staging_buffer.has_value())
|
||||
OpenCPUBuffer();
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
{
|
||||
for(std::size_t i = 0; i < len; i++)
|
||||
m_cpu_buffer[(y * m_width) + x + i] = ReverseColor(pixels[i]);
|
||||
m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x + i] = ReverseColor(pixels[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::memcpy(&m_cpu_buffer[(y * m_width) + x], pixels, len);
|
||||
std::memcpy(&m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x], pixels, len);
|
||||
}
|
||||
m_has_been_modified = true;
|
||||
}
|
||||
@@ -276,9 +282,9 @@ namespace mlx
|
||||
if(!m_staging_buffer.has_value())
|
||||
OpenCPUBuffer();
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
return ReverseColor(m_cpu_buffer[(y * m_width) + x]);
|
||||
return ReverseColor(m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x]);
|
||||
else
|
||||
return m_cpu_buffer[(y * m_width) + x];
|
||||
return m_staging_buffer->GetMap<mlx_color*>()[(y * m_width) + x];
|
||||
}
|
||||
|
||||
void Texture::GetRegion(int x, int y, int w, int h, mlx_color* dst) noexcept
|
||||
@@ -298,9 +304,9 @@ namespace mlx
|
||||
moving_y++;
|
||||
}
|
||||
if constexpr(std::endian::native == std::endian::little)
|
||||
dst[i] = ReverseColor(m_cpu_buffer[(moving_y * m_width) + moving_x]);
|
||||
dst[i] = ReverseColor(m_staging_buffer->GetMap<mlx_color*>()[(moving_y * m_width) + moving_x]);
|
||||
else
|
||||
dst[i] = m_cpu_buffer[(moving_y * m_width) + moving_x];
|
||||
dst[i] = m_staging_buffer->GetMap<mlx_color*>()[(moving_y * m_width) + moving_x];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,7 +321,16 @@ namespace mlx
|
||||
processed_color.g = static_cast<std::uint8_t>(color.g * 255.f);
|
||||
processed_color.b = static_cast<std::uint8_t>(color.b * 255.f);
|
||||
processed_color.a = static_cast<std::uint8_t>(color.a * 255.f);
|
||||
std::fill(m_cpu_buffer.begin(), m_cpu_buffer.end(), processed_color);
|
||||
if(processed_color.r == 0 && processed_color.g == 0 && processed_color.b == 0)
|
||||
std::memset(m_staging_buffer->GetMap(), processed_color.a, m_staging_buffer->GetSize());
|
||||
else
|
||||
{
|
||||
for(std::size_t y = 0; y < m_height; y++)
|
||||
{
|
||||
for(std::size_t x = 0; x < m_width; x++)
|
||||
m_staging_buffer->GetMap<mlx_color*>()[y * m_width + x] = processed_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,8 +339,6 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(!m_has_been_modified)
|
||||
return;
|
||||
std::memcpy(m_staging_buffer->GetMap(), m_cpu_buffer.data(), m_cpu_buffer.size() * sizeof(mlx_color));
|
||||
|
||||
VkImageLayout old_layout = m_layout;
|
||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
||||
kvfCopyBufferToImage(cmd, Image::Get(), m_staging_buffer->Get(), m_staging_buffer->GetOffset(), VK_IMAGE_ASPECT_COLOR_BIT, { m_width, m_height, 1 });
|
||||
@@ -360,9 +373,7 @@ namespace mlx
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
||||
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() * sizeof(mlx_color));
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
}
|
||||
|
||||
Texture* StbTextureLoad(const std::filesystem::path& file, int* w, int* h)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "vulkan/vulkan_core.h"
|
||||
#include <PreCompiled.h>
|
||||
#define VMA_IMPLEMENTATION
|
||||
#ifdef MLX_COMPILER_CLANG
|
||||
|
||||
@@ -214,6 +214,7 @@ namespace mlx
|
||||
MLX_LOAD_FUNCTION(vkDestroyShaderModule);
|
||||
MLX_LOAD_FUNCTION(vkDeviceWaitIdle);
|
||||
MLX_LOAD_FUNCTION(vkEndCommandBuffer);
|
||||
MLX_LOAD_FUNCTION(vkFreeCommandBuffers);
|
||||
MLX_LOAD_FUNCTION(vkGetDeviceQueue);
|
||||
MLX_LOAD_FUNCTION(vkGetImageSubresourceLayout);
|
||||
MLX_LOAD_FUNCTION(vkQueueSubmit);
|
||||
|
||||
@@ -102,6 +102,7 @@ namespace mlx
|
||||
VkFence fence = kvfCreateFence(RenderCore::Get().GetDevice());
|
||||
kvfSubmitSingleTimeCommandBuffer(RenderCore::Get().GetDevice(), cmd, KVF_GRAPHICS_QUEUE, fence);
|
||||
kvfDestroyFence(RenderCore::Get().GetDevice(), fence);
|
||||
kvfDestroyCommandBuffer(RenderCore::Get().GetDevice(), cmd);
|
||||
m_resize = false;
|
||||
DebugLog("Vulkan: swapchain created");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user