adding pixel put pipeline

This commit is contained in:
2023-03-31 22:16:21 +02:00
parent 3b29305936
commit 88404afb2b
23 changed files with 8443 additions and 165 deletions

View File

@@ -6,7 +6,7 @@
# By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/10/04 16:43:41 by maldavid #+# #+# #
# Updated: 2023/01/23 18:30:59 by maldavid ### ########.fr #
# Updated: 2023/03/31 12:19:47 by maldavid ### ########.fr #
# #
# **************************************************************************** #
@@ -20,8 +20,14 @@ SRCS += $(wildcard $(addsuffix /*.cpp, ./src/renderer/**))
OBJS = $(SRCS:.cpp=.o)
DEBUG ?= false
TOOLCHAIN ?= clang
CXX = clang++
ifeq ($(TOOLCHAIN), gcc)
CXX = g++
endif
CXX = g++
CXXFLAGS = -std=c++17 -O3 -fPIC
INCLUDES = -I./includes -I./src -I./third_party
@@ -32,13 +38,13 @@ endif
RM = rm -f
%.o: %.cpp
@echo "\e[1;32m[compiling... ]\e[1;00m "$<
@echo "\e[1;32m[compiling... "$(CXX)"]\e[1;00m "$<
@$(CXX) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
all: $(NAME)
$(NAME): $(OBJS)
@echo "\e[1;32m[ linking ...]\e[1;00m "$@
@echo "\e[1;32m[linking ...]\e[1;00m "$@
@$(CXX) -shared -o $(NAME) $(OBJS)
@echo "\e[1;32m[build finished]\e[1;00m"

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
/* Updated: 2023/01/24 17:52:21 by maldavid ### ########.fr */
/* Updated: 2023/03/31 12:35:21 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,6 +31,8 @@ int mlx_mouse_get_pos(void* win_ptr, int* x, int* y);
int mlx_pixel_put(void* mlx, void* win_ptr, int x, int y, int color);
void* mlx_png_file_to_image(void* mlx_ptr, char* filename, int* width, int* height);
int mlx_destroy_window(void* mlx, void* win_ptr);
int mlx_destroy_display(void* mlx);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:36:44 by maldavid #+# #+# */
/* Updated: 2023/01/25 16:27:23 by maldavid ### ########.fr */
/* Updated: 2023/03/31 20:30:14 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,21 +28,19 @@ namespace mlx
core::error::report(e_kind::fatal_error, std::string("unable to open a new window, ") + SDL_GetError());
_renderer->setWindow(this);
_renderer->init();
_renderer->getPixelPutPipeline().init(w, h, *_renderer);
std::vector<Vertex> vertexData = {
{{0, 0}, {1.f, 0.f, 0.f}},
{{_width, 0}, {1.f, 0.f, 0.f}},
{{_width, _height}, {1.f, 0.f, 0.f}},
{{0, _height}, {1.f, 0.f, 0.}}
{{0, 0}, {1.f, 0.f, 0.f}, {0.0f, 0.0f}},
{{_width, 0}, {1.f, 0.f, 0.f}, {1.0f, 0.0f}},
{{_width, _height}, {1.f, 0.f, 0.f}, {1.0f, 1.0f}},
{{0, _height}, {1.f, 0.f, 0.}, {0.0f, 1.0f}}
};
std::vector<uint16_t> indexData = { 0, 1, 2, 2, 3, 0 };
_vbo.create(sizeof(Vertex) * vertexData.size(), vertexData.data());
_ibo.create(sizeof(uint16_t) * indexData.size(), indexData.data());
//_vk_image.create(_width, _height);
_staging_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * 4, VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
}
bool MLX_Window::beginFrame()
@@ -51,42 +49,30 @@ namespace mlx
return false;
_proj = glm::ortho<float>(0, _width, 0, _height);
_renderer->getUniformBuffer()->setData(sizeof(_proj), &_proj);
vkCmdBindDescriptorSets(_renderer->getActiveCmdBuffer().get(), VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, 1, &_renderer->getDescriptorSet().get(), 0, nullptr);
return true;
}
void MLX_Window::pixel_put(int x, int y, int color)
{
VkBufferImageCopy region{};
region.bufferOffset = 0;
region.bufferRowLength = 0;
region.bufferImageHeight = 0;
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
region.imageSubresource.mipLevel = 0;
region.imageSubresource.baseArrayLayer = 0;
region.imageSubresource.layerCount = 1;
region.imageOffset = {x, y, 0};
region.imageExtent = {1, 1, 1};
VkClearColorValue vk_color;
vk_color.uint32[0] = (color >> 16) & 0xFF;
vk_color.uint32[1] = (color >> 8) & 0xFF;
vk_color.uint32[2] = color & 0xFF;
vk_color.uint32[3] = 0xFF;
void* map = nullptr;
_staging_buffer.mapMem(&map, sizeof(vk_color));
std::memcpy(map, &vk_color, sizeof(vk_color));
_staging_buffer.unmapMem();
vkCmdCopyBufferToImage(_renderer->getActiveCmdBuffer().get(), _staging_buffer.get(), _vk_image.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
_renderer->getPixelPutPipeline().setPixel(x, y, color);
}
void MLX_Window::endFrame()
{
auto cmd_buff = _renderer->getActiveCmdBuffer().get();
_renderer->getPixelPutPipeline().present();
std::vector<VkDescriptorSet> sets;
sets.push_back(_renderer->getVertDescriptorSet().get());
sets.push_back(_renderer->getPixelPutPipeline().getDescriptorSet());
vkCmdBindDescriptorSets(cmd_buff, VK_PIPELINE_BIND_POINT_GRAPHICS, _renderer->getPipeline().getPipelineLayout(), 0, sets.size(), sets.data(), 0, nullptr);
_vbo.bind(*_renderer);
_ibo.bind(*_renderer);
vkCmdDrawIndexed(_renderer->getActiveCmdBuffer().get(), static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
vkCmdDrawIndexed(cmd_buff, static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
_renderer->endFrame();
}
@@ -94,7 +80,6 @@ namespace mlx
MLX_Window::~MLX_Window()
{
_renderer->destroy();
//_vk_image.destroy();
_staging_buffer.destroy();
_vbo.destroy();
_ibo.destroy();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 21:53:12 by maldavid #+# #+# */
/* Updated: 2023/01/25 15:15:25 by maldavid ### ########.fr */
/* Updated: 2023/03/31 22:16:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -40,8 +40,6 @@ namespace mlx
~MLX_Window();
private:
Image _vk_image;
Buffer _staging_buffer;
C_VBO _vbo;
C_IBO _ibo;
glm::mat4 _proj = glm::mat4(1.0);

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
/* Updated: 2023/01/25 15:36:47 by maldavid ### ########.fr */
/* Updated: 2023/03/31 15:29:01 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -30,8 +30,10 @@ namespace mlx
{
if(vkMapMemory(Render_Core::get().getDevice().get(), _memory, _offset + offset, size, 0, data) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to map a buffer");
_is_mapped = true;
}
inline void unmapMem() noexcept { vkUnmapMemory(Render_Core::get().getDevice().get(), _memory); }
inline bool isMapped() const noexcept { return _is_mapped; }
inline void unmapMem() noexcept { vkUnmapMemory(Render_Core::get().getDevice().get(), _memory); _is_mapped = false; }
void flush(VkDeviceSize size = VK_WHOLE_SIZE, VkDeviceSize offset = 0);
@@ -55,6 +57,7 @@ namespace mlx
VkBufferUsageFlags _usage = 0;
VkMemoryPropertyFlags _flags = 0;
bool _is_mapped = false;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/17 23:33:34 by maldavid #+# #+# */
/* Updated: 2023/01/25 15:24:19 by maldavid ### ########.fr */
/* Updated: 2023/03/31 12:22:34 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -25,6 +25,8 @@
namespace mlx
{
std::mutex mutex;
namespace RCore
{
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties)
@@ -42,6 +44,7 @@ namespace mlx
return -1; // just to avoid warning
}
}
void Render_Core::init()
{
volkInitialize();
@@ -57,7 +60,6 @@ namespace mlx
void Render_Core::destroy()
{
std::mutex mutex;
std::unique_lock<std::mutex> watchdog(mutex, std::try_to_lock);
if(!_is_init)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:54:28 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:54:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -18,25 +18,30 @@
namespace mlx
{
void DescriptorSet::init(Renderer* renderer, UBO* ubo, DescriptorSetLayout& layout, DescriptorPool& pool)
void DescriptorSet::init(Renderer* renderer, DescriptorPool* pool, DescriptorSetLayout* layout)
{
_renderer = renderer;
_layout = layout;
_pool = pool;
auto device = Render_Core::get().getDevice().get();
_pool = pool.get();
std::array<VkDescriptorSetLayout, MAX_FRAMES_IN_FLIGHT> layouts;
layouts.fill(layout.get());
layouts.fill(layout->get());
VkDescriptorSetAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
allocInfo.descriptorPool = _pool;
allocInfo.descriptorSetCount = MAX_FRAMES_IN_FLIGHT;
allocInfo.descriptorPool = _pool->get();
allocInfo.descriptorSetCount = static_cast<uint32_t>(MAX_FRAMES_IN_FLIGHT);
allocInfo.pSetLayouts = layouts.data();
if(vkAllocateDescriptorSets(device, &allocInfo, _desc_set.data()) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to allocate descriptor set");
}
void DescriptorSet::writeDescriptor(int binding, UBO* ubo) noexcept
{
auto device = Render_Core::get().getDevice().get();
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
{
@@ -48,7 +53,7 @@ namespace mlx
VkWriteDescriptorSet descriptorWrite{};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = _desc_set[i];
descriptorWrite.dstBinding = 0;
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = 0;
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
descriptorWrite.descriptorCount = 1;
@@ -58,6 +63,34 @@ namespace mlx
}
}
void DescriptorSet::writeDescriptor(int binding, VkImageView view, VkSampler sampler) noexcept
{
auto device = Render_Core::get().getDevice().get();
VkDescriptorImageInfo imageInfo{};
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
imageInfo.imageView = view;
imageInfo.sampler = sampler;
VkWriteDescriptorSet descriptorWrite{};
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
descriptorWrite.dstSet = _desc_set[_renderer->getActiveImageIndex()];
descriptorWrite.dstBinding = binding;
descriptorWrite.dstArrayElement = 0;
descriptorWrite.descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
descriptorWrite.descriptorCount = 1;
descriptorWrite.pImageInfo = &imageInfo;
vkUpdateDescriptorSets(device, 1, &descriptorWrite, 0, nullptr);
}
DescriptorSet DescriptorSet::duplicate()
{
DescriptorSet set;
set.init(_renderer, _pool, _layout);
return set;
}
VkDescriptorSet& DescriptorSet::operator()() noexcept
{
return _desc_set[_renderer->getActiveImageIndex()];
@@ -66,9 +99,4 @@ namespace mlx
{
return _desc_set[_renderer->getActiveImageIndex()];
}
void DescriptorSet::destroy() noexcept
{
vkFreeDescriptorSets(Render_Core::get().getDevice().get(), _pool, MAX_FRAMES_IN_FLIGHT, _desc_set.data());
}
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:54:22 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:28:36 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,15 +22,22 @@ namespace mlx
class DescriptorSet
{
public:
void init(class Renderer* renderer, class UBO* ubo, class DescriptorSetLayout& layout, class DescriptorPool& pool);
void destroy() noexcept;
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
void writeDescriptor(int binding, class UBO* ubo) noexcept;
void writeDescriptor(int binding, VkImageView view, VkSampler sampler) noexcept;
inline bool isInit() noexcept { return _pool != nullptr && _renderer != nullptr; }
DescriptorSet duplicate();
VkDescriptorSet& operator()() noexcept;
VkDescriptorSet& get() noexcept;
private:
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> _desc_set;
VkDescriptorPool _pool = VK_NULL_HANDLE;
class DescriptorPool* _pool = nullptr;
class DescriptorSetLayout* _layout = nullptr;
class Renderer* _renderer = nullptr;
};
}

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:37:28 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:45:32 by maldavid ### ########.fr */
/* Updated: 2023/03/31 16:37:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,19 +15,24 @@
namespace mlx
{
void DescriptorSetLayout::init(VkDescriptorType t, std::size_t n, int binding, VkShaderStageFlagBits stage)
void DescriptorSetLayout::init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage)
{
VkDescriptorSetLayoutBinding bindings{};
bindings.binding = binding;
bindings.descriptorCount = 1;
bindings.descriptorType = t;
bindings.pImmutableSamplers = nullptr;
bindings.stageFlags = stage;
std::vector<VkDescriptorSetLayoutBinding> bindings(binds.size());
for(int i = 0; i < binds.size(); i++)
{
bindings[i].binding = binds[i].first;
bindings[i].descriptorCount = 1;
bindings[i].descriptorType = binds[i].second;
bindings[i].pImmutableSamplers = nullptr;
bindings[i].stageFlags = stage;
}
_bindings = std::move(binds);
VkDescriptorSetLayoutCreateInfo layoutInfo{};
layoutInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
layoutInfo.bindingCount = n;
layoutInfo.pBindings = &bindings;
layoutInfo.bindingCount = _bindings.size();
layoutInfo.pBindings = bindings.data();
if(vkCreateDescriptorSetLayout(Render_Core::get().getDevice().get(), &layoutInfo, nullptr, &_layout) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create descriptor set layout");

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/23 18:36:22 by maldavid #+# #+# */
/* Updated: 2023/01/23 18:45:44 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:54:03 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -15,20 +15,24 @@
#include <volk.h>
#include <cstddef>
#include <vector>
#include <map>
namespace mlx
{
class DescriptorSetLayout
{
public:
void init(VkDescriptorType t = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, std::size_t n = 1, int binding = 0, VkShaderStageFlagBits stage = VK_SHADER_STAGE_VERTEX_BIT);
void init(std::vector<std::pair<int, VkDescriptorType>> binds, VkShaderStageFlagBits stage);
void destroy() noexcept;
inline VkDescriptorSetLayout& operator()() noexcept { return _layout; }
inline VkDescriptorSetLayout& get() noexcept { return _layout; }
inline const std::vector<std::pair<int, VkDescriptorType>>& getBindings() const noexcept { return _bindings; }
private:
VkDescriptorSetLayout _layout = VK_NULL_HANDLE;
std::vector<std::pair<int, VkDescriptorType>> _bindings;
};
}

35
src/renderer/images/texture.cpp git.filemode.normal_file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* texture.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
/* Updated: 2023/03/31 18:06:26 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <renderer/images/texture.h>
#include <renderer/buffers/vk_buffer.h>
namespace mlx
{
void Texture::create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format)
{
Image::create(width, height, format,
VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
);
Image::createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
Image::createSampler();
Buffer staging_buffer;
std::size_t size = width * height * (format == VK_FORMAT_R32G32B32A32_SFLOAT ? 16 : 4);
staging_buffer.create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, pixels);
Image::copyBuffer(staging_buffer);
staging_buffer.destroy();
}
}

View File

@@ -6,11 +6,24 @@
/* By: maldavid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
/* Updated: 2023/03/08 02:25:18 by maldavid ### ########.fr */
/* Updated: 2023/03/31 18:06:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_TEXTURE__
#define __MLX_TEXTURE__
#include <renderer/images/vk_image.h>
namespace mlx
{
class Texture : public Image
{
public:
Texture() = default;
void create(uint8_t* pixels, uint32_t width, uint32_t height, VkFormat format);
~Texture() = default;
};
}
#endif

View File

@@ -6,12 +6,14 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
/* Updated: 2023/03/08 02:24:10 by maldavid ### ########.fr */
/* Updated: 2023/03/31 12:26:08 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "vk_image.h"
#include <renderer/core/render_core.h>
#include <renderer/buffers/vk_buffer.h>
#include <renderer/command/vk_cmd_pool.h>
namespace mlx
{
@@ -100,7 +102,7 @@ namespace mlx
info.maxAnisotropy = 1.0f;
if(vkCreateSampler(Render_Core::get().getDevice().get(), &info, nullptr, &_sampler) != VK_SUCCESS)
Core::log::report(FATAL_ERROR, "Vulkan : unable to create image sampler");
core::error::report(e_kind::fatal_error, "Vulkan : failed to create an image");
}
void Image::copyBuffer(Buffer& buffer)

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
/* Updated: 2023/03/08 02:15:00 by maldavid ### ########.fr */
/* Updated: 2023/03/31 18:04:35 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -27,6 +27,8 @@ namespace mlx
Image() = default;
void create(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties);
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
void createSampler() noexcept;
void copyBuffer(class Buffer& buffer);
void destroy() noexcept;
@@ -39,10 +41,6 @@ namespace mlx
virtual ~Image() = default;
protected:
void createImageView(VkImageViewType type, VkImageAspectFlags aspectFlags) noexcept;
void createSampler() noexcept;
private:
DescriptorSet _desc;
VkImage _image = VK_NULL_HANDLE;

View File

@@ -6,78 +6,143 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 21:27:38 by maldavid #+# #+# */
/* Updated: 2023/01/25 16:19:33 by maldavid ### ########.fr */
/* Updated: 2023/03/31 18:56:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include "pipeline.h"
#include <renderer/renderer.h>
#include <renderer/core/render_core.h>
#include <renderer/descriptors/vk_descriptor_set_layout.h>
namespace mlx
{
const std::vector<uint32_t> vertex_shader = {
0x07230203,0x00010000,0x0008000a,0x00000029,0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
0x0009000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000d,0x00000019,0x00000025,
0x00000027,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,0x00000000,
0x00060005,0x0000000b,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x0000000b,
0x00000000,0x505f6c67,0x7469736f,0x006e6f69,0x00070006,0x0000000b,0x00000001,0x505f6c67,
0x746e696f,0x657a6953,0x00000000,0x00070006,0x0000000b,0x00000002,0x435f6c67,0x4470696c,
0x61747369,0x0065636e,0x00070006,0x0000000b,0x00000003,0x435f6c67,0x446c6c75,0x61747369,
0x0065636e,0x00030005,0x0000000d,0x00000000,0x00040005,0x00000011,0x7274614d,0x00007869,
0x00050006,0x00000011,0x00000000,0x6a6f7270,0x00000000,0x00040005,0x00000013,0x7274616d,
0x00007869,0x00050005,0x00000019,0x6f506e69,0x69746973,0x00006e6f,0x00050005,0x00000025,
0x67617266,0x6f6c6f43,0x00000072,0x00040005,0x00000027,0x6f436e69,0x00726f6c,0x00050048,
0x0000000b,0x00000000,0x0000000b,0x00000000,0x00050048,0x0000000b,0x00000001,0x0000000b,
0x00000001,0x00050048,0x0000000b,0x00000002,0x0000000b,0x00000003,0x00050048,0x0000000b,
0x00000003,0x0000000b,0x00000004,0x00030047,0x0000000b,0x00000002,0x00040048,0x00000011,
0x00000000,0x00000005,0x00050048,0x00000011,0x00000000,0x00000023,0x00000000,0x00050048,
0x00000011,0x00000000,0x00000007,0x00000010,0x00030047,0x00000011,0x00000002,0x00040047,
0x00000013,0x00000022,0x00000000,0x00040047,0x00000013,0x00000021,0x00000000,0x00040047,
0x00000019,0x0000001e,0x00000000,0x00040047,0x00000025,0x0000001e,0x00000000,0x00040047,
0x00000027,0x0000001e,0x00000001,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040015,
0x00000008,0x00000020,0x00000000,0x0004002b,0x00000008,0x00000009,0x00000001,0x0004001c,
0x0000000a,0x00000006,0x00000009,0x0006001e,0x0000000b,0x00000007,0x00000006,0x0000000a,
0x0000000a,0x00040020,0x0000000c,0x00000003,0x0000000b,0x0004003b,0x0000000c,0x0000000d,
0x00000003,0x00040015,0x0000000e,0x00000020,0x00000001,0x0004002b,0x0000000e,0x0000000f,
0x00000000,0x00040018,0x00000010,0x00000007,0x00000004,0x0003001e,0x00000011,0x00000010,
0x00040020,0x00000012,0x00000002,0x00000011,0x0004003b,0x00000012,0x00000013,0x00000002,
0x00040020,0x00000014,0x00000002,0x00000010,0x00040017,0x00000017,0x00000006,0x00000002,
0x00040020,0x00000018,0x00000001,0x00000017,0x0004003b,0x00000018,0x00000019,0x00000001,
0x0004002b,0x00000006,0x0000001b,0x00000000,0x0004002b,0x00000006,0x0000001c,0x3f800000,
0x00040020,0x00000021,0x00000003,0x00000007,0x00040017,0x00000023,0x00000006,0x00000003,
0x00040020,0x00000024,0x00000003,0x00000023,0x0004003b,0x00000024,0x00000025,0x00000003,
0x00040020,0x00000026,0x00000001,0x00000023,0x0004003b,0x00000026,0x00000027,0x00000001,
0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,
0x00000014,0x00000015,0x00000013,0x0000000f,0x0004003d,0x00000010,0x00000016,0x00000015,
0x0004003d,0x00000017,0x0000001a,0x00000019,0x00050051,0x00000006,0x0000001d,0x0000001a,
0x00000000,0x00050051,0x00000006,0x0000001e,0x0000001a,0x00000001,0x00070050,0x00000007,
0x0000001f,0x0000001d,0x0000001e,0x0000001b,0x0000001c,0x00050091,0x00000007,0x00000020,
0x00000016,0x0000001f,0x00050041,0x00000021,0x00000022,0x0000000d,0x0000000f,0x0003003e,
0x00000022,0x00000020,0x0004003d,0x00000023,0x00000028,0x00000027,0x0003003e,0x00000025,
0x00000028,0x000100fd,0x00010038
/**
#version 450 core
layout(location = 0) in vec2 aPos;
layout(location = 1) in vec3 aColor;
layout(location = 2) in vec2 aUV;
layout(set=0, binding=0) uniform uProjection {
mat4 mat;
} uProj;
out gl_PerVertex {
vec4 gl_Position;
};
const std::vector<uint32_t> fragment_shader = {
0x07230203,0x00010000,0x0008000a,0x00000013,0x00000000,0x00020011,0x00000001,0x0006000b,
layout(location = 0) out struct {
vec3 Color;
vec2 UV;
} Out;
void main()
{
Out.Color = aColor;
Out.UV = aUV;
vec4 position = vec4(aPos.x, aPos.y, 0.0, 1.0) * uProj.mat;
gl_Position = vec4(position.x, position.y, 0.0, 1.0);
}
*/
const std::vector<uint32_t> vertex_shader = {
0x07230203,0x00010000,0x0008000b,0x0000003b,0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000c,0x00030010,
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00090004,0x415f4c47,0x735f4252,
0x72617065,0x5f657461,0x64616873,0x6f5f7265,0x63656a62,0x00007374,0x00040005,0x00000004,
0x6e69616d,0x00000000,0x00050005,0x00000009,0x4374756f,0x726f6c6f,0x00000000,0x00050005,
0x0000000c,0x67617266,0x6f6c6f43,0x00000072,0x00040047,0x00000009,0x0000001e,0x00000000,
0x00040047,0x0000000c,0x0000001e,0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,
0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,
0x00040020,0x00000008,0x00000003,0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,
0x00040017,0x0000000a,0x00000006,0x00000003,0x00040020,0x0000000b,0x00000001,0x0000000a,
0x0004003b,0x0000000b,0x0000000c,0x00000001,0x0004002b,0x00000006,0x0000000e,0x3f800000,
0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003d,
0x0000000a,0x0000000d,0x0000000c,0x00050051,0x00000006,0x0000000f,0x0000000d,0x00000000,
0x00050051,0x00000006,0x00000010,0x0000000d,0x00000001,0x00050051,0x00000006,0x00000011,
0x0000000d,0x00000002,0x00070050,0x00000007,0x00000012,0x0000000f,0x00000010,0x00000011,
0x0000000e,0x0003003e,0x00000009,0x00000012,0x000100fd,0x00010038
0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
0x0000001c,0x00000032,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00050005,
0x0000001b,0x69736f70,0x6e6f6974,0x00000000,0x00040005,0x0000001c,0x736f5061,0x00000000,
0x00050005,0x00000029,0x6f725075,0x7463656a,0x006e6f69,0x00040006,0x00000029,0x00000000,
0x0074616d,0x00040005,0x0000002b,0x6f725075,0x0000006a,0x00060005,0x00000030,0x505f6c67,
0x65567265,0x78657472,0x00000000,0x00060006,0x00000030,0x00000000,0x505f6c67,0x7469736f,
0x006e6f69,0x00030005,0x00000032,0x00000000,0x00040047,0x0000000b,0x0000001e,0x00000000,
0x00040047,0x0000000f,0x0000001e,0x00000001,0x00040047,0x00000015,0x0000001e,0x00000002,
0x00040047,0x0000001c,0x0000001e,0x00000000,0x00040048,0x00000029,0x00000000,0x00000005,
0x00050048,0x00000029,0x00000000,0x00000023,0x00000000,0x00050048,0x00000029,0x00000000,
0x00000007,0x00000010,0x00030047,0x00000029,0x00000002,0x00040047,0x0000002b,0x00000022,
0x00000000,0x00040047,0x0000002b,0x00000021,0x00000000,0x00050048,0x00000030,0x00000000,
0x0000000b,0x00000000,0x00030047,0x00000030,0x00000002,0x00020013,0x00000002,0x00030021,
0x00000003,0x00000002,0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,
0x00000003,0x00040017,0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,
0x00000008,0x00040020,0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,
0x00000003,0x00040015,0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,
0x00000000,0x00040020,0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,
0x00000001,0x00040020,0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,
0x00000001,0x00040020,0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,
0x00000001,0x00040020,0x00000017,0x00000003,0x00000008,0x00040017,0x00000019,0x00000006,
0x00000004,0x00040020,0x0000001a,0x00000007,0x00000019,0x0004003b,0x00000014,0x0000001c,
0x00000001,0x00040015,0x0000001d,0x00000020,0x00000000,0x0004002b,0x0000001d,0x0000001e,
0x00000000,0x00040020,0x0000001f,0x00000001,0x00000006,0x0004002b,0x0000001d,0x00000022,
0x00000001,0x0004002b,0x00000006,0x00000025,0x00000000,0x0004002b,0x00000006,0x00000026,
0x3f800000,0x00040018,0x00000028,0x00000019,0x00000004,0x0003001e,0x00000029,0x00000028,
0x00040020,0x0000002a,0x00000002,0x00000029,0x0004003b,0x0000002a,0x0000002b,0x00000002,
0x00040020,0x0000002c,0x00000002,0x00000028,0x0003001e,0x00000030,0x00000019,0x00040020,
0x00000031,0x00000003,0x00000030,0x0004003b,0x00000031,0x00000032,0x00000003,0x00040020,
0x00000033,0x00000007,0x00000006,0x00040020,0x00000039,0x00000003,0x00000019,0x00050036,
0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,0x00000005,0x0004003b,0x0000001a,
0x0000001b,0x00000007,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,
0x00000012,0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,
0x00000016,0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,
0x00000018,0x00000016,0x00050041,0x0000001f,0x00000020,0x0000001c,0x0000001e,0x0004003d,
0x00000006,0x00000021,0x00000020,0x00050041,0x0000001f,0x00000023,0x0000001c,0x00000022,
0x0004003d,0x00000006,0x00000024,0x00000023,0x00070050,0x00000019,0x00000027,0x00000021,
0x00000024,0x00000025,0x00000026,0x00050041,0x0000002c,0x0000002d,0x0000002b,0x0000000d,
0x0004003d,0x00000028,0x0000002e,0x0000002d,0x00050090,0x00000019,0x0000002f,0x00000027,
0x0000002e,0x0003003e,0x0000001b,0x0000002f,0x00050041,0x00000033,0x00000034,0x0000001b,
0x0000001e,0x0004003d,0x00000006,0x00000035,0x00000034,0x00050041,0x00000033,0x00000036,
0x0000001b,0x00000022,0x0004003d,0x00000006,0x00000037,0x00000036,0x00070050,0x00000019,
0x00000038,0x00000035,0x00000037,0x00000025,0x00000026,0x00050041,0x00000039,0x0000003a,
0x00000032,0x0000000d,0x0003003e,0x0000003a,0x00000038,0x000100fd,0x00010038
};
/**
#version 450 core
layout(location = 0) out vec4 fColor;
layout(set=1, binding=0) uniform sampler2D sTexture;
layout(location = 0) in struct {
vec3 Color;
vec2 UV;
} In;
void main()
{
fColor = vec4(In.Color, 1.0) * texture(sTexture, In.UV.st);
}
*/
const std::vector<uint32_t> fragment_shader = {
0x07230203,0x00010000,0x0008000b,0x00000024,0x00000000,0x00020011,0x00000001,0x0006000b,
0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000e,0x00030010,
0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000c,0x00000000,
0x00050006,0x0000000c,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000c,0x00000001,
0x00005655,0x00030005,0x0000000e,0x00006e49,0x00050005,0x0000001c,0x78655473,0x65727574,
0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000e,0x0000001e,
0x00000000,0x00040047,0x0000001c,0x00000022,0x00000001,0x00040047,0x0000001c,0x00000021,
0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,
0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006,
0x00000003,0x00040017,0x0000000b,0x00000006,0x00000002,0x0004001e,0x0000000c,0x0000000a,
0x0000000b,0x00040020,0x0000000d,0x00000001,0x0000000c,0x0004003b,0x0000000d,0x0000000e,
0x00000001,0x00040015,0x0000000f,0x00000020,0x00000001,0x0004002b,0x0000000f,0x00000010,
0x00000000,0x00040020,0x00000011,0x00000001,0x0000000a,0x0004002b,0x00000006,0x00000014,
0x3f800000,0x00090019,0x00000019,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
0x00000001,0x00000000,0x0003001b,0x0000001a,0x00000019,0x00040020,0x0000001b,0x00000000,
0x0000001a,0x0004003b,0x0000001b,0x0000001c,0x00000000,0x0004002b,0x0000000f,0x0000001e,
0x00000001,0x00040020,0x0000001f,0x00000001,0x0000000b,0x00050036,0x00000002,0x00000004,
0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000011,0x00000012,0x0000000e,
0x00000010,0x0004003d,0x0000000a,0x00000013,0x00000012,0x00050051,0x00000006,0x00000015,
0x00000013,0x00000000,0x00050051,0x00000006,0x00000016,0x00000013,0x00000001,0x00050051,
0x00000006,0x00000017,0x00000013,0x00000002,0x00070050,0x00000007,0x00000018,0x00000015,
0x00000016,0x00000017,0x00000014,0x0004003d,0x0000001a,0x0000001d,0x0000001c,0x00050041,
0x0000001f,0x00000020,0x0000000e,0x0000001e,0x0004003d,0x0000000b,0x00000021,0x00000020,
0x00050057,0x00000007,0x00000022,0x0000001d,0x00000021,0x00050085,0x00000007,0x00000023,
0x00000018,0x00000022,0x0003003e,0x00000009,0x00000023,0x000100fd,0x00010038
};
void GraphicPipeline::init(Renderer& renderer)
@@ -123,7 +188,7 @@ namespace mlx
VkPipelineInputAssemblyStateCreateInfo inputAssembly{};
inputAssembly.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
inputAssembly.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
inputAssembly.primitiveRestartEnable = VK_FALSE;
VkDynamicState states[] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
@@ -183,10 +248,15 @@ namespace mlx
colorBlending.blendConstants[2] = 0.0f;
colorBlending.blendConstants[3] = 0.0f;
VkDescriptorSetLayout layouts[] = {
renderer.getVertDescriptorSetLayout().get(),
renderer.getFragDescriptorSetLayout().get()
};
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.setLayoutCount = 1;
pipelineLayoutInfo.pSetLayouts = &renderer.getDescriptorSetLayout().get();
pipelineLayoutInfo.setLayoutCount = 2;
pipelineLayoutInfo.pSetLayouts = layouts;
if(vkCreatePipelineLayout(Render_Core::get().getDevice().get(), &pipelineLayoutInfo, nullptr, &_pipelineLayout) != VK_SUCCESS)
core::error::report(e_kind::fatal_error, "Vulkan : failed to create a graphics pipeline layout");

56
src/renderer/pixel_put.cpp git.filemode.normal_file
View File

@@ -0,0 +1,56 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pixel_put.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
/* Updated: 2023/03/31 20:30:38 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#include <renderer/pixel_put.h>
#include <renderer/renderer.h>
#include <cstring>
namespace mlx
{
void PixelPutPipeline::init(uint32_t width, uint32_t height, Renderer& renderer) noexcept
{
_image.create(width, height, VK_FORMAT_R8G8B8A8_UNORM, VK_IMAGE_TILING_OPTIMAL,
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
_image.createImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
_image.createSampler();
_buffer.create(Buffer::kind::dynamic, sizeof(uint32_t) * (width * height), VK_BUFFER_USAGE_TRANSFER_SRC_BIT);
_image_set = renderer.getFragDescriptorSet().duplicate();
_width = width;
_height = height;
}
void PixelPutPipeline::setPixel(uint32_t x, uint32_t y, int color) noexcept
{
if(x < 0 || y < 0 || x > _width || y > _height)
return;
if(!_buffer.isMapped())
_buffer.mapMem(&_map);
unsigned char* mem = static_cast<unsigned char*>(_map) + y * _width + x * sizeof(uint32_t);
*reinterpret_cast<uint32_t*>(mem) = color;
}
void PixelPutPipeline::present() noexcept
{
if(_buffer.isMapped())
_buffer.unmapMem();
_image.copyBuffer(_buffer);
_image_set.writeDescriptor(0, _image.getImageView(), _image.getSampler());
}
void PixelPutPipeline::destroy() noexcept
{
_buffer.destroy();
_image.destroy();
}
}

47
src/renderer/pixel_put.h git.filemode.normal_file
View File

@@ -0,0 +1,47 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* pixel_put.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/31 13:18:50 by maldavid #+# #+# */
/* Updated: 2023/03/31 20:30:25 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef __MLX_PIXEL_PUT__
#define __MLX_PIXEL_PUT__
#include <renderer/buffers/vk_buffer.h>
#include <renderer/images/vk_image.h>
#include <renderer/descriptors/vk_descriptor_set.h>
namespace mlx
{
class PixelPutPipeline
{
public:
PixelPutPipeline() = default;
void init(uint32_t width, uint32_t height, class Renderer& renderer) noexcept;
void setPixel(uint32_t x, uint32_t y, int color) noexcept;
void present() noexcept;
inline VkDescriptorSet& getDescriptorSet() noexcept { return _image_set.get(); }
void destroy() noexcept;
~PixelPutPipeline() = default;
private:
Image _image;
Buffer _buffer;
DescriptorSet _image_set;
void* _map = nullptr;
uint32_t _width = 0;
uint32_t _height = 0;
};
}
#endif

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
/* Updated: 2023/01/24 17:02:39 by maldavid ### ########.fr */
/* Updated: 2023/03/31 18:54:23 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,10 +31,24 @@ namespace mlx
_uniform_buffer.reset(new UBO);
_uniform_buffer->create(this, sizeof(glm::mat4));
_layout.init(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
VkDescriptorPoolSize pool_sizes{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, MAX_FRAMES_IN_FLIGHT };
_desc_pool.init(1, &pool_sizes);
_set.init(this, _uniform_buffer.get(), _layout, _desc_pool);
VkDescriptorPoolSize pool_sizes[] = {
{ VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 4096 },
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4096 }
};
_desc_pool.init(2, pool_sizes);
_vert_layout.init({
{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}
}, VK_SHADER_STAGE_VERTEX_BIT);
_frag_layout.init({
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}
}, VK_SHADER_STAGE_FRAGMENT_BIT);
_vert_set.init(this, &_desc_pool, &_vert_layout);
_frag_set.init(this, &_desc_pool, &_frag_layout);
_vert_set.writeDescriptor(0, _uniform_buffer.get());
_pipeline.init(*this);
@@ -134,17 +148,16 @@ namespace mlx
void Renderer::destroy()
{
std::mutex mutex;
std::unique_lock<std::mutex> watchdog(mutex, std::try_to_lock);
vkDeviceWaitIdle(Render_Core::get().getDevice().get());
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
_cmd_buffers[i].destroy();
_pixel_put_pipeline.destroy();
_pipeline.destroy();
_uniform_buffer->destroy();
_layout.destroy();
_vert_layout.destroy();
_frag_layout.destroy();
_desc_pool.destroy();
_swapchain.destroyFB();
_pass.destroy();

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 17:14:45 by maldavid #+# #+# */
/* Updated: 2023/01/25 16:05:05 by maldavid ### ########.fr */
/* Updated: 2023/03/31 17:59:09 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,6 +17,7 @@
#include <vector>
#include <memory>
#include <renderer/pixel_put.h>
#include <renderer/buffers/vk_ubo.h>
#include <renderer/core/vk_surface.h>
#include <renderer/core/render_core.h>
@@ -40,6 +41,7 @@ namespace mlx
{
glm::vec2 pos;
glm::vec3 color;
glm::vec2 uv;
static VkVertexInputBindingDescription getBindingDescription()
{
@@ -51,9 +53,9 @@ namespace mlx
return bindingDescription;
}
static std::array<VkVertexInputAttributeDescription, 2> getAttributeDescriptions()
static std::array<VkVertexInputAttributeDescription, 3> getAttributeDescriptions()
{
std::array<VkVertexInputAttributeDescription, 2> attributeDescriptions;
std::array<VkVertexInputAttributeDescription, 3> attributeDescriptions;
attributeDescriptions[0].binding = 0;
attributeDescriptions[0].location = 0;
@@ -65,6 +67,11 @@ namespace mlx
attributeDescriptions[1].format = VK_FORMAT_R32G32B32_SFLOAT;
attributeDescriptions[1].offset = offsetof(Vertex, color);
attributeDescriptions[2].binding = 0;
attributeDescriptions[2].location = 2;
attributeDescriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
attributeDescriptions[2].offset = offsetof(Vertex, uv);
return attributeDescriptions;
}
};
@@ -93,8 +100,11 @@ namespace mlx
inline CmdBuffer& getCmdBuffer(int i) noexcept { return _cmd_buffers[i]; }
inline GraphicPipeline& getPipeline() noexcept { return _pipeline; }
inline CmdBuffer& getActiveCmdBuffer() noexcept { return _cmd_buffers[_active_image_index]; }
inline DescriptorSet& getDescriptorSet() noexcept { return _set; }
inline DescriptorSetLayout& getDescriptorSetLayout() noexcept { return _layout; }
inline DescriptorSet& getVertDescriptorSet() noexcept { return _vert_set; }
inline DescriptorSet& getFragDescriptorSet() noexcept { return _frag_set; }
inline DescriptorSetLayout& getVertDescriptorSetLayout() noexcept { return _vert_layout; }
inline DescriptorSetLayout& getFragDescriptorSetLayout() noexcept { return _frag_layout; }
inline PixelPutPipeline& getPixelPutPipeline() noexcept { return _pixel_put_pipeline; }
inline uint32_t getActiveImageIndex() noexcept { return _active_image_index; }
inline uint32_t getImageIndex() noexcept { return _image_index; }
@@ -103,19 +113,26 @@ namespace mlx
~Renderer() = default;
private:
PixelPutPipeline _pixel_put_pipeline;
GraphicPipeline _pipeline;
RenderPass _pass;
Surface _surface;
CmdPool _cmd_pool;
SwapChain _swapchain;
Semaphore _semaphore;
DescriptorPool _desc_pool;
DescriptorSet _set;
DescriptorSetLayout _layout;
DescriptorSetLayout _vert_layout;
DescriptorSetLayout _frag_layout;
DescriptorSet _vert_set;
DescriptorSet _frag_set;
std::array<CmdBuffer, MAX_FRAMES_IN_FLIGHT> _cmd_buffers;
std::unique_ptr<UBO> _uniform_buffer = nullptr;
class MLX_Window* _window;
class MLX_Window* _window = nullptr;
uint32_t _active_image_index = 0;
uint32_t _image_index = 0;

BIN
test/42_logo.png git.filemode.normal_file

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -6,7 +6,7 @@
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
/* Updated: 2023/01/25 15:20:35 by maldavid ### ########.fr */
/* Updated: 2023/03/31 20:26:59 by maldavid ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,9 +23,9 @@ int update(t_mlx *mlx)
{
static int i = 0;
printf("%d\n", i);
mlx_pixel_put(mlx->mlx, mlx->win, 100, 0, 0xFFFFFFFF);
i++;
if (i > 20000)
if (i > 10000)
mlx_loop_end(mlx->mlx);
return (0);
}

View File

@@ -1 +1 @@
clear && gcc main.c ../libmlx.so -lSDL2 && ./a.out
clang main.c ../libmlx.so -lSDL2 -g && ./a.out

7987
third_party/stb_image.h vendored git.filemode.normal_file

File diff suppressed because it is too large Load Diff