diff options
-rw-r--r-- | assets/shaders/triangle.frag | 4 | ||||
-rw-r--r-- | src/renderer/backends/backend_vulkan.c | 14 | ||||
-rw-r--r-- | src/renderer/ral.h | 5 | ||||
-rw-r--r-- | src/std/mem.c | 21 | ||||
-rw-r--r-- | src/std/mem.h | 28 |
5 files changed, 61 insertions, 11 deletions
diff --git a/assets/shaders/triangle.frag b/assets/shaders/triangle.frag index a8c6e69..c3ff328 100644 --- a/assets/shaders/triangle.frag +++ b/assets/shaders/triangle.frag @@ -3,6 +3,4 @@ layout(location = 0) in vec3 fragColor; layout(location = 0) out vec4 outColor; -void main() { - outColor = vec4(fragColor, 0.0); -} +void main() { outColor = vec4(fragColor, 0.0); } diff --git a/src/renderer/backends/backend_vulkan.c b/src/renderer/backends/backend_vulkan.c index 3a9c4e1..1db9803 100644 --- a/src/renderer/backends/backend_vulkan.c +++ b/src/renderer/backends/backend_vulkan.c @@ -411,12 +411,13 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip frag_shader_stage_info }; // TODO: Attributes - VkVertexInputAttributeDescription attribute_descs[2] = {0}; + VkVertexInputAttributeDescription attribute_descs[2] = { 0 }; /* u32 offset = 0; */ /* for (u32 i = 0; i < description.vertex_desc.attributes_count; i++) { */ /* attribute_descs[i].binding = 0; */ /* attribute_descs[i].location = i; */ - /* attribute_descs[i].format = format_from_vertex_attr(description.vertex_desc.attributes[i]); */ + /* attribute_descs[i].format = format_from_vertex_attr(description.vertex_desc.attributes[i]); + */ /* attribute_descs[i].offset = offset; */ /* size_t this_offset = vertex_attrib_size(description.vertex_desc.attributes[i]); */ /* printf("offset total %d this attr %ld\n", offset, this_offset); */ @@ -428,12 +429,12 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip attribute_descs[0].binding = 0; attribute_descs[0].location = 0; attribute_descs[0].format = VK_FORMAT_R32G32B32_SFLOAT; - attribute_descs[0].offset = 0; // offsetof(custom_vertex, pos); + attribute_descs[0].offset = 0; // offsetof(custom_vertex, pos); attribute_descs[1].binding = 0; attribute_descs[1].location = 1; attribute_descs[1].format = VK_FORMAT_R32G32B32_SFLOAT; - attribute_descs[1].offset = 12; // offsetof(custom_vertex, color); + attribute_descs[1].offset = 12; // offsetof(custom_vertex, color); // Vertex input // TODO: Generate this from descroiption now @@ -447,7 +448,8 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip }; vertex_input_info.vertexBindingDescriptionCount = 1; vertex_input_info.pVertexBindingDescriptions = &binding_desc; - vertex_input_info.vertexAttributeDescriptionCount = 2; // description.vertex_desc.attributes_count; + vertex_input_info.vertexAttributeDescriptionCount = + 2; // description.vertex_desc.attributes_count; vertex_input_info.pVertexAttributeDescriptions = attribute_descs; // Input Assembly @@ -628,7 +630,7 @@ gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc descrip VK_CHECK(vkCreateDescriptorSetLayout(context.device->logical_device, &desc_set_layout_info, context.allocator, &desc_set_layouts[i])); } - printf("Descriptor set layouts\n"); + printf("Descriptor set layouts\n"); // Layout VkPipelineLayoutCreateInfo pipeline_layout_create_info = { diff --git a/src/renderer/ral.h b/src/renderer/ral.h index 30d5413..ee65233 100644 --- a/src/renderer/ral.h +++ b/src/renderer/ral.h @@ -78,6 +78,11 @@ struct graphics_pipeline_desc { typedef struct gpu_renderpass_desc { } gpu_renderpass_desc; +typedef struct resource_pools { + // TODO: buffer pool + // TODO: texture pool +} resource_pools; + // --- Lifecycle functions bool gpu_backend_init(const char* window_name, struct GLFWwindow* window); diff --git a/src/std/mem.c b/src/std/mem.c index 4886d72..7d768c9 100644 --- a/src/std/mem.c +++ b/src/std/mem.c @@ -8,6 +8,8 @@ #define DEFAULT_ALIGNMENT (2 * sizeof(void*)) #endif +// --- Arena + void* arena_alloc_align(arena* a, size_t size, size_t align) { ptrdiff_t padding = -(uintptr_t)a->curr & (align - 1); ptrdiff_t available = a->end - a->curr - padding; @@ -38,4 +40,21 @@ arena_save arena_savepoint(arena* a) { return savept; } -void arena_rewind(arena_save savepoint) { savepoint.arena->curr = savepoint.savepoint; }
\ No newline at end of file +void arena_rewind(arena_save savepoint) { savepoint.arena->curr = savepoint.savepoint; } + +// --- Pool + +void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size) { + size_t memory_requirements = capacity * entry_size; + void* backing_buf = arena_alloc(a, memory_requirements); + + void_pool pool = { .capacity = capacity, + .entry_size = entry_size, + .count = 0, + .backing_buffer = backing_buf, + .free_list_head = NULL }; + + void_pool_free_all(&pool); + + return pool; +} diff --git a/src/std/mem.h b/src/std/mem.h index bbfb852..eef97a0 100644 --- a/src/std/mem.h +++ b/src/std/mem.h @@ -10,6 +10,9 @@ #pragma once #include <stddef.h> +#include "defines.h" + +// --- Arena // Inspired by https://nullprogram.com/blog/2023/09/27/ typedef struct arena { @@ -30,4 +33,27 @@ void arena_free_all(arena* a); void arena_free_storage(arena* a); arena_save arena_savepoint(arena* a); void arena_rewind(arena_save savepoint); -// TODO: arena_resize
\ No newline at end of file +// TODO: arena_resize + +// --- Pool + +typedef struct void_pool_header void_pool_header; +struct void_pool_header { + void_pool_header* next; +}; + +typedef struct void_pool { + u64 capacity; + u64 entry_size; + u64 count; + void* backing_buffer; + void_pool_header* free_list_head; +} void_pool; + +void_pool void_pool_create(arena* a, u64 capacity, u64 entry_size); +void void_pool_free_all(void_pool* pool); +bool void_pool_is_empty(void_pool* pool); +bool void_pool_is_full(void_pool* pool); +void* void_pool_get(u32 raw_handle); + +// TODO: macro that lets us specialise |