adding depth buffer, ci skip

This commit is contained in:
Kbz-8
2024-09-02 13:02:32 +02:00
parent d5eeef9559
commit b7d554553b
26 changed files with 217 additions and 192 deletions

View File

@@ -28,6 +28,7 @@ namespace mlx
void SetStorageBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
void SetUniformBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer);
void Update(std::size_t i, VkCommandBuffer cmd = VK_NULL_HANDLE) noexcept;
void Reallocate() noexcept;
[[nodiscard]] inline VkDescriptorSet GetSet(std::size_t i) const noexcept { return m_set[i]; }
[[nodiscard]] inline DescriptorSet Duplicate() const { return DescriptorSet{ m_set_layout, m_descriptors }; }

View File

@@ -17,6 +17,7 @@ namespace mlx
enum class ImageType
{
Color = 0,
Depth,
EndEnum
};

View File

@@ -23,7 +23,7 @@ namespace mlx
m_layout = layout;
}
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, bool is_multisampled = false);
void Init(ImageType type, std::uint32_t width, std::uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, bool is_multisampled = false);
void CreateImageView(VkImageViewType type, VkImageAspectFlags aspectFlags, int layer_count = 1) noexcept;
void CreateSampler() noexcept;
void TransitionLayout(VkImageLayout new_layout, VkCommandBuffer cmd = VK_NULL_HANDLE);
@@ -34,7 +34,6 @@ namespace mlx
virtual void Destroy() noexcept;
[[nodiscard]] MLX_FORCEINLINE VkImage Get() const noexcept { return m_image; }
[[nodiscard]] MLX_FORCEINLINE VkImage operator()() const noexcept { return m_image; }
[[nodiscard]] MLX_FORCEINLINE VkDeviceMemory GetDeviceMemory() const noexcept { return m_memory.memory; }
[[nodiscard]] MLX_FORCEINLINE VkImageView GetImageView() const noexcept { return m_image_view; }
[[nodiscard]] MLX_FORCEINLINE VkFormat GetFormat() const noexcept { return m_format; }
@@ -62,6 +61,21 @@ namespace mlx
bool m_is_multisampled = false;
};
class DepthImage : public Image
{
public:
DepthImage() = default;
inline void Init(std::uint32_t width, std::uint32_t height, bool is_multisampled = false)
{
std::vector<VkFormat> candidates = { VK_FORMAT_D32_SFLOAT, VK_FORMAT_D32_SFLOAT_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT };
VkFormat format = kvfFindSupportFormatInCandidates(RenderCore::Get().GetDevice(), candidates.data(), candidates.size(), VK_IMAGE_TILING_OPTIMAL, VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT);
Image::Init(ImageType::Depth, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, is_multisampled);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_DEPTH_BIT);
Image::TransitionLayout(VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
}
~DepthImage() = default;
};
class Texture : public Image
{
public:
@@ -72,7 +86,7 @@ namespace mlx
}
inline void Init(CPUBuffer pixels, std::uint32_t width, std::uint32_t height, VkFormat format = VK_FORMAT_R8G8B8A8_SRGB, bool is_multisampled = false)
{
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, is_multisampled);
Image::Init(ImageType::Color, width, height, format, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, is_multisampled);
Image::CreateImageView(VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT);
Image::CreateSampler();
if(pixels)

View File

@@ -14,6 +14,7 @@ namespace mlx
std::shared_ptr<Shader> fragment_shader;
std::vector<NonOwningPtr<Texture>> color_attachments;
NonOwningPtr<class Renderer> renderer = nullptr;
NonOwningPtr<DepthImage> depth = nullptr;
bool clear_color_attachments = true;
bool no_vertex_inputs = false;
};
@@ -51,6 +52,7 @@ namespace mlx
VkPipeline m_pipeline = VK_NULL_HANDLE;
VkPipelineLayout m_pipeline_layout = VK_NULL_HANDLE;
NonOwningPtr<class Renderer> p_renderer;
NonOwningPtr<DepthImage> p_depth;
};
}

View File

@@ -8,15 +8,14 @@ namespace mlx
{
struct Vertex
{
alignas(16) Vec2f position = Vec4f{ 0.0f, 0.0f };
alignas(16) Vec4f color = Vec4f{ 1.0f, 1.0f, 1.0f, 1.0f };
alignas(16) Vec4f position = Vec4f{ 0.0f, 0.0f, 0.0f, 1.0f };
alignas(16) Vec2f uv = Vec2f{ 0.0f, 0.0f };
Vertex() = default;
Vertex(Vec2f p, Vec4f c, Vec2f u) : position(std::move(p)), color(std::move(c)), uv(std::move(u)) {}
Vertex(Vec4f p, Vec2f u) : position(std::move(p)), uv(std::move(u)) {}
[[nodiscard]] inline static VkVertexInputBindingDescription GetBindingDescription();
[[nodiscard]] inline static std::array<VkVertexInputAttributeDescription, 3> GetAttributeDescriptions();
[[nodiscard]] inline static std::array<VkVertexInputAttributeDescription, 2> GetAttributeDescriptions();
};
}

View File

@@ -12,24 +12,19 @@ namespace mlx
return binding_description;
}
std::array<VkVertexInputAttributeDescription, 3> Vertex::GetAttributeDescriptions()
std::array<VkVertexInputAttributeDescription, 2> Vertex::GetAttributeDescriptions()
{
std::array<VkVertexInputAttributeDescription, 3> attribute_descriptions;
attribute_descriptions[0].binding = 0;
attribute_descriptions[0].location = 0;
attribute_descriptions[0].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[0].format = VK_FORMAT_R32G32B32A32_SFLOAT;
attribute_descriptions[0].offset = offsetof(Vertex, position);
attribute_descriptions[1].binding = 0;
attribute_descriptions[1].location = 1;
attribute_descriptions[1].format = VK_FORMAT_R32G32B32A32_SFLOAT;
attribute_descriptions[1].offset = offsetof(Vertex, color);
attribute_descriptions[2].binding = 0;
attribute_descriptions[2].location = 2;
attribute_descriptions[2].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[2].offset = offsetof(Vertex, uv);
attribute_descriptions[1].format = VK_FORMAT_R32G32_SFLOAT;
attribute_descriptions[1].offset = offsetof(Vertex, uv);
return attribute_descriptions;
}