summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-09 23:32:33 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-09 23:32:33 +1000
commit3103f383751a12f8a0bdb22309704f1f826d204c (patch)
tree7da8febddfcc40b15de5d7fc3c9a5215d88c5cab
parentd5f22a65ab12b289d80b035e45e6f1e9460b82d1 (diff)
wip: some cleanup of ral
-rw-r--r--src/ral/backends/metal/backend_metal.h0
-rw-r--r--src/ral/backends/opengl/backend_opengl.h0
-rw-r--r--src/ral/backends/vulkan/backend_vulkan.h0
-rw-r--r--src/ral/ral.h5
-rw-r--r--src/ral/ral_common.c19
-rw-r--r--src/ral/ral_common.h45
-rw-r--r--src/ral/ral_impl.h22
-rw-r--r--src/ral/ral_types.h80
-rw-r--r--src/render/backends/backend_test.c (renamed from src/renderer/backends/backend_test.c)0
-rw-r--r--src/render/backends/metal/README.md (renamed from src/renderer/backends/metal/README.md)0
-rw-r--r--src/render/backends/metal/backend_metal.h (renamed from src/renderer/backends/metal/backend_metal.h)0
-rw-r--r--src/render/backends/metal/backend_metal.m (renamed from src/renderer/backends/metal/backend_metal.m)0
-rw-r--r--src/render/backends/opengl/README.md (renamed from src/renderer/backends/opengl/README.md)0
-rw-r--r--src/render/backends/opengl/backend_opengl.c (renamed from src/renderer/backends/opengl/backend_opengl.c)0
-rw-r--r--src/render/backends/opengl/backend_opengl.h (renamed from src/renderer/backends/opengl/backend_opengl.h)0
-rw-r--r--src/render/backends/opengl/opengl_helpers.h (renamed from src/renderer/backends/opengl/opengl_helpers.h)0
-rw-r--r--src/render/backends/vulkan/README.md (renamed from src/renderer/backends/vulkan/README.md)0
-rw-r--r--src/render/backends/vulkan/backend_vulkan.c (renamed from src/renderer/backends/backend_vulkan.c)0
-rw-r--r--src/render/backends/vulkan/backend_vulkan.h (renamed from src/renderer/backends/backend_vulkan.h)0
-rw-r--r--src/render/backends/vulkan/vulkan_glossary.md (renamed from src/renderer/backends/vulkan/vulkan_glossary.md)0
-rw-r--r--src/render/backends/vulkan_helpers.h (renamed from src/renderer/backends/vulkan_helpers.h)0
-rw-r--r--src/render/bind_group_layouts.h (renamed from src/renderer/bind_group_layouts.h)0
-rw-r--r--src/render/builtin_materials.h (renamed from src/renderer/builtin_materials.h)0
-rw-r--r--src/render/immediate.c (renamed from src/renderer/immediate.c)0
-rw-r--r--src/render/immediate.h (renamed from src/renderer/immediate.h)0
-rw-r--r--src/render/ral.c (renamed from src/renderer/ral.c)0
-rw-r--r--src/render/ral.h (renamed from src/renderer/ral.h)50
-rw-r--r--src/render/ral_types.h (renamed from src/renderer/ral_types.h)11
-rw-r--r--src/render/render.c (renamed from src/renderer/render.c)0
-rw-r--r--src/render/render.h (renamed from src/renderer/render.h)0
-rw-r--r--src/render/render_types.h (renamed from src/renderer/render_types.h)0
-rw-r--r--src/render/renderpasses.c (renamed from src/renderer/renderpasses.c)0
-rw-r--r--src/render/renderpasses.h (renamed from src/renderer/renderpasses.h)0
-rw-r--r--src/render/static_pipeline.h (renamed from src/renderer/static_pipeline.h)0
-rw-r--r--src/renderer/backends/backend_dx11.c5
-rw-r--r--src/renderer/backends/backend_dx11.h29
36 files changed, 196 insertions, 70 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
diff --git a/src/renderer/backends/backend_test.c b/src/render/backends/backend_test.c
index 6347e27..6347e27 100644
--- a/src/renderer/backends/backend_test.c
+++ b/src/render/backends/backend_test.c
diff --git a/src/renderer/backends/metal/README.md b/src/render/backends/metal/README.md
index f87f5c1..f87f5c1 100644
--- a/src/renderer/backends/metal/README.md
+++ b/src/render/backends/metal/README.md
diff --git a/src/renderer/backends/metal/backend_metal.h b/src/render/backends/metal/backend_metal.h
index 9561bb6..9561bb6 100644
--- a/src/renderer/backends/metal/backend_metal.h
+++ b/src/render/backends/metal/backend_metal.h
diff --git a/src/renderer/backends/metal/backend_metal.m b/src/render/backends/metal/backend_metal.m
index 4787755..4787755 100644
--- a/src/renderer/backends/metal/backend_metal.m
+++ b/src/render/backends/metal/backend_metal.m
diff --git a/src/renderer/backends/opengl/README.md b/src/render/backends/opengl/README.md
index f87f5c1..f87f5c1 100644
--- a/src/renderer/backends/opengl/README.md
+++ b/src/render/backends/opengl/README.md
diff --git a/src/renderer/backends/opengl/backend_opengl.c b/src/render/backends/opengl/backend_opengl.c
index 70e10d7..70e10d7 100644
--- a/src/renderer/backends/opengl/backend_opengl.c
+++ b/src/render/backends/opengl/backend_opengl.c
diff --git a/src/renderer/backends/opengl/backend_opengl.h b/src/render/backends/opengl/backend_opengl.h
index 8b88cf8..8b88cf8 100644
--- a/src/renderer/backends/opengl/backend_opengl.h
+++ b/src/render/backends/opengl/backend_opengl.h
diff --git a/src/renderer/backends/opengl/opengl_helpers.h b/src/render/backends/opengl/opengl_helpers.h
index 41018cb..41018cb 100644
--- a/src/renderer/backends/opengl/opengl_helpers.h
+++ b/src/render/backends/opengl/opengl_helpers.h
diff --git a/src/renderer/backends/vulkan/README.md b/src/render/backends/vulkan/README.md
index 220ed64..220ed64 100644
--- a/src/renderer/backends/vulkan/README.md
+++ b/src/render/backends/vulkan/README.md
diff --git a/src/renderer/backends/backend_vulkan.c b/src/render/backends/vulkan/backend_vulkan.c
index 8801230..8801230 100644
--- a/src/renderer/backends/backend_vulkan.c
+++ b/src/render/backends/vulkan/backend_vulkan.c
diff --git a/src/renderer/backends/backend_vulkan.h b/src/render/backends/vulkan/backend_vulkan.h
index 6ca0bb5..6ca0bb5 100644
--- a/src/renderer/backends/backend_vulkan.h
+++ b/src/render/backends/vulkan/backend_vulkan.h
diff --git a/src/renderer/backends/vulkan/vulkan_glossary.md b/src/render/backends/vulkan/vulkan_glossary.md
index 4214f9d..4214f9d 100644
--- a/src/renderer/backends/vulkan/vulkan_glossary.md
+++ b/src/render/backends/vulkan/vulkan_glossary.md
diff --git a/src/renderer/backends/vulkan_helpers.h b/src/render/backends/vulkan_helpers.h
index 23666c6..23666c6 100644
--- a/src/renderer/backends/vulkan_helpers.h
+++ b/src/render/backends/vulkan_helpers.h
diff --git a/src/renderer/bind_group_layouts.h b/src/render/bind_group_layouts.h
index 246d1ef..246d1ef 100644
--- a/src/renderer/bind_group_layouts.h
+++ b/src/render/bind_group_layouts.h
diff --git a/src/renderer/builtin_materials.h b/src/render/builtin_materials.h
index f2db5f4..f2db5f4 100644
--- a/src/renderer/builtin_materials.h
+++ b/src/render/builtin_materials.h
diff --git a/src/renderer/immediate.c b/src/render/immediate.c
index 63a62b8..63a62b8 100644
--- a/src/renderer/immediate.c
+++ b/src/render/immediate.c
diff --git a/src/renderer/immediate.h b/src/render/immediate.h
index f4b1729..f4b1729 100644
--- a/src/renderer/immediate.h
+++ b/src/render/immediate.h
diff --git a/src/renderer/ral.c b/src/render/ral.c
index 9ca99ce..9ca99ce 100644
--- a/src/renderer/ral.c
+++ b/src/render/ral.c
diff --git a/src/renderer/ral.h b/src/render/ral.h
index b76de27..792bb4e 100644
--- a/src/renderer/ral.h
+++ b/src/render/ral.h
@@ -31,36 +31,36 @@ typedef struct gpu_cmd_buffer gpu_cmd_buffer; // Ready for submission
typedef struct gpu_buffer gpu_buffer;
typedef struct gpu_texture gpu_texture;
-#define MAX_SHADER_DATA_LAYOUTS 5
-#define MAX_BUFFERS 256
-#define MAX_TEXTURES 256
-#define MAX_PIPELINES 128
-#define MAX_RENDERPASSES 128
+// #define MAX_SHADER_DATA_LAYOUTS 5
+// #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_buffer, buffer);
+// TYPED_POOL(gpu_texture, texture);
-TYPED_POOL(gpu_pipeline_layout, pipeline_layout);
-TYPED_POOL(gpu_pipeline, pipeline);
-TYPED_POOL(gpu_renderpass, renderpass);
+// 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))
+// // --- 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);
+// 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);
// --- Pipeline description
typedef enum pipeline_kind {
diff --git a/src/renderer/ral_types.h b/src/render/ral_types.h
index f1f261d..5f21846 100644
--- a/src/renderer/ral_types.h
+++ b/src/render/ral_types.h
@@ -26,17 +26,6 @@ CORE_DEFINE_HANDLE(pipeline_handle);
CORE_DEFINE_HANDLE(renderpass_handle);
#define ABSENT_MODEL_HANDLE 999999999
-/* #define RENDERER_TYPED_HANDLES */
-/* #endif */
-
-/* typedef struct gpu_buffer { */
-/* u32 a; */
-/* } gpu_buffer; */
-
-/* #ifndef RAL_TYPED_POOLS */
-/* #define RAL_TYPED_POOLS */
-/* #endif */
-
// gpu types
typedef enum gpu_primitive_topology {
CEL_PRIMITIVE_TOPOLOGY_POINT,
diff --git a/src/renderer/render.c b/src/render/render.c
index f52e2be..f52e2be 100644
--- a/src/renderer/render.c
+++ b/src/render/render.c
diff --git a/src/renderer/render.h b/src/render/render.h
index 19a8d1a..19a8d1a 100644
--- a/src/renderer/render.h
+++ b/src/render/render.h
diff --git a/src/renderer/render_types.h b/src/render/render_types.h
index b25fa14..b25fa14 100644
--- a/src/renderer/render_types.h
+++ b/src/render/render_types.h
diff --git a/src/renderer/renderpasses.c b/src/render/renderpasses.c
index b93d487..b93d487 100644
--- a/src/renderer/renderpasses.c
+++ b/src/render/renderpasses.c
diff --git a/src/renderer/renderpasses.h b/src/render/renderpasses.h
index 5a5ffee..5a5ffee 100644
--- a/src/renderer/renderpasses.h
+++ b/src/render/renderpasses.h
diff --git a/src/renderer/static_pipeline.h b/src/render/static_pipeline.h
index bf5bc42..bf5bc42 100644
--- a/src/renderer/static_pipeline.h
+++ b/src/render/static_pipeline.h
diff --git a/src/renderer/backends/backend_dx11.c b/src/renderer/backends/backend_dx11.c
deleted file mode 100644
index 7e48853..0000000
--- a/src/renderer/backends/backend_dx11.c
+++ /dev/null
@@ -1,5 +0,0 @@
-#if defined(CEL_REND_BACKEND_DX11)
-#include <d3d11.h>
-#include <d3dcompiler.h>
-
-#endif \ No newline at end of file
diff --git a/src/renderer/backends/backend_dx11.h b/src/renderer/backends/backend_dx11.h
deleted file mode 100644
index 53738aa..0000000
--- a/src/renderer/backends/backend_dx11.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#pragma once
-#include <d3d11.h>
-#include <d3dcompiler.h>
-
-#include "ral.h"
-
-#define GPU_SWAPCHAIN_IMG_COUNT 2
-
-// typedef struct gpu_swapchain gpu_swapchain;
-typedef struct gpu_device {
- // VkPhysicalDevice physical_device;
- // VkDevice logical_device;
- // VkPhysicalDeviceProperties properties;
- // VkPhysicalDeviceFeatures features;
- // VkPhysicalDeviceMemoryProperties memory;
- // VkCommandPool pool;
-} gpu_device;
-typedef struct gpu_pipeline {
-} gpu_pipeline;
-
-typedef struct gpu_renderpass {
- // VkRenderPass vk_handle;
- // VkFramebuffer framebuffers[GPU_SWAPCHAIN_IMG_COUNT];
- // u32
-} gpu_renderpass;
-
-typedef struct gpu_cmd_encoder {
- // VkCommandBuffer cmd_buffer;
-} gpu_cmd_encoder; \ No newline at end of file