diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-09 23:32:33 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-09 23:32:33 +1000 |
commit | 3103f383751a12f8a0bdb22309704f1f826d204c (patch) | |
tree | 7da8febddfcc40b15de5d7fc3c9a5215d88c5cab /src/ral | |
parent | d5f22a65ab12b289d80b035e45e6f1e9460b82d1 (diff) |
wip: some cleanup of ral
Diffstat (limited to 'src/ral')
-rw-r--r-- | src/ral/backends/metal/backend_metal.h | 0 | ||||
-rw-r--r-- | src/ral/backends/opengl/backend_opengl.h | 0 | ||||
-rw-r--r-- | src/ral/backends/vulkan/backend_vulkan.h | 0 | ||||
-rw-r--r-- | src/ral/ral.h | 5 | ||||
-rw-r--r-- | src/ral/ral_common.c | 19 | ||||
-rw-r--r-- | src/ral/ral_common.h | 45 | ||||
-rw-r--r-- | src/ral/ral_impl.h | 22 | ||||
-rw-r--r-- | src/ral/ral_types.h | 80 |
8 files changed, 171 insertions, 0 deletions
diff --git a/src/ral/backends/metal/backend_metal.h b/src/ral/backends/metal/backend_metal.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/ral/backends/metal/backend_metal.h diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/ral/backends/opengl/backend_opengl.h diff --git a/src/ral/backends/vulkan/backend_vulkan.h b/src/ral/backends/vulkan/backend_vulkan.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/ral/backends/vulkan/backend_vulkan.h diff --git a/src/ral/ral.h b/src/ral/ral.h new file mode 100644 index 0000000..ce3b27d --- /dev/null +++ b/src/ral/ral.h @@ -0,0 +1,5 @@ +#pragma once + +#include "ral_types.h" +#include "ral_common.h" +#include "ral_impl.h"
\ No newline at end of file diff --git a/src/ral/ral_common.c b/src/ral/ral_common.c new file mode 100644 index 0000000..755b489 --- /dev/null +++ b/src/ral/ral_common.c @@ -0,0 +1,19 @@ +#include "ral_common.h" +#include "ral_impl.h" + +void backend_pools_init(arena* a, gpu_backend_pools* backend_pools) { + pipeline_layout_pool pipeline_layout_pool = + pipeline_layout_pool_create(a, MAX_PIPELINES, sizeof(gpu_pipeline_layout)); + backend_pools->pipeline_layouts = pipeline_layout_pool; + pipeline_pool pipeline_pool = pipeline_pool_create(a, MAX_PIPELINES, sizeof(gpu_pipeline)); + backend_pools->pipelines = pipeline_pool; + renderpass_pool rpass_pool = renderpass_pool_create(a, MAX_RENDERPASSES, sizeof(gpu_renderpass)); + backend_pools->renderpasses = rpass_pool; +} + +void resource_pools_init(arena* a, struct resource_pools* res_pools) { + buffer_pool buf_pool = buffer_pool_create(a, MAX_BUFFERS, sizeof(gpu_buffer)); + res_pools->buffers = buf_pool; + texture_pool tex_pool = texture_pool_create(a, MAX_TEXTURES, sizeof(gpu_texture)); + res_pools->textures = tex_pool; +}
\ No newline at end of file diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h new file mode 100644 index 0000000..bc86945 --- /dev/null +++ b/src/ral/ral_common.h @@ -0,0 +1,45 @@ +#pragma once +#include "defines.h" +#include "mem.h" +#include "ral_types.h" +#include "ral_impl.h" + +CORE_DEFINE_HANDLE(buffer_handle); +CORE_DEFINE_HANDLE(texture_handle); +CORE_DEFINE_HANDLE(sampler_handle); +CORE_DEFINE_HANDLE(shader_handle); +CORE_DEFINE_HANDLE(pipeline_layout_handle); +CORE_DEFINE_HANDLE(pipeline_handle); +CORE_DEFINE_HANDLE(renderpass_handle); + +#define MAX_SHADER_DATA_LAYOUTS 8 +#define MAX_BUFFERS 256 +#define MAX_TEXTURES 256 +#define MAX_PIPELINES 128 +#define MAX_RENDERPASSES 128 + +TYPED_POOL(gpu_buffer, buffer); +TYPED_POOL(gpu_texture, texture); +TYPED_POOL(gpu_pipeline_layout, pipeline_layout); +TYPED_POOL(gpu_pipeline, pipeline); +TYPED_POOL(gpu_renderpass, renderpass); + +// --- Handy macros +#define BUFFER_GET(h) (buffer_pool_get(&context.resource_pools->buffers, h)) +#define TEXTURE_GET(h) (texture_pool_get(&context.resource_pools->textures, h)) + +// --- Pools +typedef struct gpu_backend_pools { + pipeline_pool pipelines; + pipeline_layout_pool pipeline_layouts; + renderpass_pool renderpasses; +} gpu_backend_pools; +void backend_pools_init(arena* a, gpu_backend_pools* backend_pools); + +struct resource_pools { + buffer_pool buffers; + texture_pool textures; +}; +void resource_pools_init(arena* a, struct resource_pools* res_pools); + +// vertex_description static_3d_vertex_description();
\ No newline at end of file diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h new file mode 100644 index 0000000..8edf211 --- /dev/null +++ b/src/ral/ral_impl.h @@ -0,0 +1,22 @@ +#pragma once +#include "defines.h" +#include "ral_types.h" + +struct GLFWwindow; + +bool gpu_backend_init(const char* window_name, struct GLFWwindow* window); +void gpu_backend_shutdown(); + +bool gpu_device_create(gpu_device* out_device); +void gpu_device_destroy(gpu_device* device); + +gpu_pipeline* gpu_graphics_pipeline_create(struct graphics_pipeline_desc description); +void gpu_pipeline_destroy(gpu_pipeline* pipeline); + +// --- Renderpass +gpu_renderpass* gpu_renderpass_create(const gpu_renderpass_desc* description); +void gpu_renderpass_destroy(gpu_renderpass* pass); + +// --- Swapchain +bool gpu_swapchain_create(gpu_swapchain* out_swapchain); +void gpu_swapchain_destroy(gpu_swapchain* swapchain);
\ No newline at end of file diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h new file mode 100644 index 0000000..bc24d7f --- /dev/null +++ b/src/ral/ral_types.h @@ -0,0 +1,80 @@ +#pragma once + +// Forward declare structs - these must be defined in the backend implementation +typedef struct gpu_swapchain gpu_swapchain; +typedef struct gpu_device gpu_device; +typedef struct gpu_pipeline_layout gpu_pipeline_layout; +typedef struct gpu_pipeline gpu_pipeline; +typedef struct gpu_renderpass gpu_renderpass; +typedef struct gpu_cmd_encoder gpu_cmd_encoder; // Recording +typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission +typedef struct gpu_buffer gpu_buffer; +typedef struct gpu_texture gpu_texture; + +typedef enum gpu_primitive_topology { + CEL_PRIMITIVE_TOPOLOGY_POINT, + CEL_PRIMITIVE_TOPOLOGY_LINE, + CEL_PRIMITIVE_TOPOLOGY_LINE_STRIP, + CEL_PRIMITIVE_TOPOLOGY_TRIANGLE, + CEL_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP, + CEL_PRIMITIVE_TOPOLOGY_COUNT +} gpu_primitive_topology; + +typedef enum gpu_texture_type { + CEL_TEXTURE_TYPE_2D, + CEL_TEXTURE_TYPE_3D, + CEL_TEXTURE_TYPE_2D_ARRAY, + CEL_TEXTURE_TYPE_CUBE_MAP, + CEL_TEXTURE_TYPE_COUNT +} gpu_texture_type; + +typedef enum gpu_texture_format { + CEL_TEXTURE_FORMAT_8_8_8_8_RGBA_UNORM, + CEL_TEXTURE_FORMAT_DEPTH_DEFAULT, + CEL_TEXTURE_FORMAT_COUNT +} gpu_texture_format; + +// Vertex attributes +/// @strip_prefix(ATTR_) +typedef enum vertex_attrib_type { + ATTR_F32, + ATTR_F32x2, + ATTR_F32x3, + ATTR_F32x4, + ATTR_U32, + ATTR_U32x2, + ATTR_U32x3, + ATTR_U32x4, + ATTR_I32, + ATTR_I32x2, + ATTR_I32x3, + ATTR_I32x4, +} vertex_attrib_type; + +typedef struct graphics_pipeline_desc { + const char* debug_name; + vertex_description vertex_desc; + shader_desc vs; /** @brief Vertex shader stage */ + shader_desc fs; /** @brief Fragment shader stage */ + + // Roughly equivalent to a descriptor set layout each. each layout can have multiple bindings + // examples: + // - uniform buffer reprensenting view projection matrix + // - texture for shadow map + shader_data data_layouts[MAX_SHADER_DATA_LAYOUTS]; + u32 data_layouts_count; + + // gpu_pipeline_layout* layout; + gpu_renderpass* renderpass; + + bool wireframe; + bool depth_test; +} graphics_pipeline_desc; + +typedef struct gpu_renderpass_desc { + bool default_framebuffer; + bool has_color_target; + texture_handle color_target; // for now only support one + bool has_depth_stencil; + texture_handle depth_stencil; +} gpu_renderpass_desc;
\ No newline at end of file |