summaryrefslogtreecommitdiff
path: root/src/ral
diff options
context:
space:
mode:
authoromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-19 14:33:34 +1000
committeromniscient <17525998+omnisci3nce@users.noreply.github.com>2024-07-19 14:33:34 +1000
commit82515f9d90ac149984013f0d64c1cab37b349b29 (patch)
tree6da445874d055e3e66ab1825d4aa3bb784955fc9 /src/ral
parent5359c011a08ef2e06ed54104cc16c32868ca88ff (diff)
chore clang format + tidy
Diffstat (limited to 'src/ral')
-rw-r--r--src/ral/backends/opengl/backend_opengl.h18
-rw-r--r--src/ral/backends/opengl/opengl_helpers.h2
-rw-r--r--src/ral/backends/vulkan/backend_vulkan.h42
-rw-r--r--src/ral/ral.h4
-rw-r--r--src/ral/ral_common.h8
-rw-r--r--src/ral/ral_impl.h15
-rw-r--r--src/ral/ral_types.h75
7 files changed, 87 insertions, 77 deletions
diff --git a/src/ral/backends/opengl/backend_opengl.h b/src/ral/backends/opengl/backend_opengl.h
index f5ab9c8..fd50830 100644
--- a/src/ral/backends/opengl/backend_opengl.h
+++ b/src/ral/backends/opengl/backend_opengl.h
@@ -11,20 +11,20 @@
#define OPENGL_DEFAULT_FRAMEBUFFER 0
-typedef struct GPU_Swapchain{
+typedef struct GPU_Swapchain {
u32x2 dimensions;
-}GPU_Swapchain;
+} GPU_Swapchain;
typedef struct GPU_Device {
} GPU_Device;
-typedef struct GPU_PipelineLayout{
+typedef struct GPU_PipelineLayout {
void *pad;
-}GPU_PipelineLayout;
+} GPU_PipelineLayout;
typedef struct GPU_Pipeline {
u32 shader_id;
- GPU_Renderpass* renderpass;
+ GPU_Renderpass *renderpass;
VertexDescription vertex_desc;
BufferHandle uniform_bindings[MAX_PIPELINE_UNIFORM_BUFFERS];
u32 uniform_count;
@@ -38,7 +38,7 @@ typedef struct GPU_Renderpass {
typedef struct GPU_CmdEncoder {
GPU_Pipeline *pipeline;
-} GPU_CmdEncoder; // Recording
+} GPU_CmdEncoder; // Recording
typedef struct GPU_CmdBuffer {
void *pad;
@@ -53,14 +53,14 @@ typedef struct GPU_Buffer {
union {
u32 vao;
u32 ubo_binding_point
- }; // Optional
- char* name;
+ }; // Optional
+ char *name;
u64 size;
} GPU_Buffer;
typedef struct GPU_Texture {
u32 id;
- void* pad;
+ void *pad;
} GPU_Texture;
typedef struct opengl_support {
diff --git a/src/ral/backends/opengl/opengl_helpers.h b/src/ral/backends/opengl/opengl_helpers.h
index f40bbca..f3059ac 100644
--- a/src/ral/backends/opengl/opengl_helpers.h
+++ b/src/ral/backends/opengl/opengl_helpers.h
@@ -4,8 +4,8 @@
#include "ral_impl.h"
#if defined(CEL_REND_BACKEND_OPENGL)
#include "backend_opengl.h"
-#include "log.h"
#include "file.h"
+#include "log.h"
#include "ral_types.h"
#include <glad/glad.h>
diff --git a/src/ral/backends/vulkan/backend_vulkan.h b/src/ral/backends/vulkan/backend_vulkan.h
index 790344b..f31bed2 100644
--- a/src/ral/backends/vulkan/backend_vulkan.h
+++ b/src/ral/backends/vulkan/backend_vulkan.h
@@ -1,10 +1,10 @@
#pragma once
#ifdef CEL_REND_BACKEND_VULKAN
-#include "ral_impl.h"
#include "defines.h"
#include "maths_types.h"
#include "ral.h"
+#include "ral_impl.h"
#include "ral_types.h"
#include <vulkan/vk_platform.h>
@@ -14,31 +14,31 @@
// Provide definitions for RAL structs
struct GPU_Swapchain {
- VkSwapchainKHR handle;
+ VkSwapchainKHR handle;
};
struct GPU_Device {
- VkPhysicalDevice physical_device;
- VkDevice logical_device;
+ VkPhysicalDevice physical_device;
+ VkDevice logical_device;
};
struct GPU_PipelineLayout {};
- struct GPU_Pipeline {};
- struct GPU_Renderpass {};
- struct GPU_CmdEncoder {};
- struct GPU_CmdBuffer {};
- struct GPU_Buffer {
- VkBuffer handle;
- VkDeviceMemory memory;
- u64 size;
- };
- struct GPU_Texture {
- VkImage handle;
- VkDeviceMemory memory;
- u64 size;
- VkImageView view;
- VkSampler sampler;
- char* debug_label;
- };
+struct GPU_Pipeline {};
+struct GPU_Renderpass {};
+struct GPU_CmdEncoder {};
+struct GPU_CmdBuffer {};
+struct GPU_Buffer {
+ VkBuffer handle;
+ VkDeviceMemory memory;
+ u64 size;
+};
+struct GPU_Texture {
+ VkImage handle;
+ VkDeviceMemory memory;
+ u64 size;
+ VkImageView view;
+ VkSampler sampler;
+ char* debug_label;
+};
#endif
diff --git a/src/ral/ral.h b/src/ral/ral.h
index ce3b27d..fdbadd3 100644
--- a/src/ral/ral.h
+++ b/src/ral/ral.h
@@ -1,5 +1,5 @@
#pragma once
-#include "ral_types.h"
#include "ral_common.h"
-#include "ral_impl.h" \ No newline at end of file
+#include "ral_impl.h"
+#include "ral_types.h" \ No newline at end of file
diff --git a/src/ral/ral_common.h b/src/ral/ral_common.h
index 98f54ed..63816b1 100644
--- a/src/ral/ral_common.h
+++ b/src/ral/ral_common.h
@@ -1,9 +1,9 @@
/**
* @brief Common functions that don't actually depend on the specific backend
-*/
+ */
#pragma once
-#include "defines.h"
#include "buf.h"
+#include "defines.h"
#include "mem.h"
#include "ral_types.h"
// #include "ral_impl.h"
@@ -13,7 +13,6 @@
#include "backend_opengl.h"
#endif
-
TYPED_POOL(GPU_Buffer, Buffer);
TYPED_POOL(GPU_Texture, Texture);
TYPED_POOL(GPU_PipelineLayout, PipelineLayout);
@@ -39,7 +38,8 @@ struct ResourcePools {
typedef struct ResourcePools ResourcePools;
void ResourcePools_Init(arena* a, struct ResourcePools* res_pools);
-PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to default framebuffer with default depth
+PUB GPU_Renderpass* GPU_GetDefaultRenderpass(); // returns a renderpass that draws directly to
+ // default framebuffer with default depth
// --- Vertex formats
VertexDescription static_3d_vertex_description();
diff --git a/src/ral/ral_impl.h b/src/ral/ral_impl.h
index 7b40f28..6676b6c 100644
--- a/src/ral/ral_impl.h
+++ b/src/ral/ral_impl.h
@@ -1,6 +1,6 @@
/**
* @brief
-*/
+ */
#pragma once
#include "buf.h"
#include "defines.h"
@@ -20,7 +20,8 @@ typedef struct GPU_CmdBuffer GPU_CmdBuffer; // Ready for submission
typedef struct GPU_Buffer GPU_Buffer;
typedef struct GPU_Texture GPU_Texture;
-bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window, struct ResourcePools* res_pools);
+bool GPU_Backend_Init(const char* window_name, struct GLFWwindow* window,
+ struct ResourcePools* res_pools);
void GPU_Backend_Shutdown();
bool GPU_Device_Create(GPU_Device* out_device);
@@ -32,7 +33,8 @@ void GPU_Swapchain_Destroy(GPU_Swapchain* swapchain);
PUB GPU_Renderpass* GPU_Renderpass_Create(GPU_RenderpassDesc description);
PUB void GPU_Renderpass_Destroy(GPU_Renderpass* pass);
-PUB GPU_Pipeline* GPU_GraphicsPipeline_Create(GraphicsPipelineDesc description, GPU_Renderpass* renderpass);
+PUB GPU_Pipeline* GPU_GraphicsPipeline_Create(GraphicsPipelineDesc description,
+ GPU_Renderpass* renderpass);
PUB void GraphicsPipeline_Destroy(GPU_Pipeline* pipeline);
// --- Command buffer
@@ -46,7 +48,8 @@ PUB GPU_CmdEncoder* GPU_GetDefaultEncoder();
PUB void GPU_QueueSubmit(GPU_CmdBuffer* cmd_buffer);
// --- Buffers
-PUB BufferHandle GPU_BufferCreate(u64 size, GPU_BufferType buf_type, GPU_BufferFlags flags, const void* data);
+PUB BufferHandle GPU_BufferCreate(u64 size, GPU_BufferType buf_type, GPU_BufferFlags flags,
+ const void* data);
PUB void GPU_BufferDestroy(BufferHandle handle);
PUB void GPU_BufferUpload(BufferHandle buffer, size_t n_bytes, const void* data);
@@ -58,8 +61,8 @@ PUB void GPU_TextureUpload(TextureHandle handle, size_t n_bytes, const void* dat
// --- Data copy commands
// TODO: Rename these to reflect current coding style
-void encode_buffer_copy(GPU_CmdEncoder* encoder, BufferHandle src, u64 src_offset,
- BufferHandle dst, u64 dst_offset, u64 copy_size);
+void encode_buffer_copy(GPU_CmdEncoder* encoder, BufferHandle src, u64 src_offset, BufferHandle dst,
+ u64 dst_offset, u64 copy_size);
void buffer_upload_bytes(BufferHandle gpu_buf, bytebuffer cpu_buf, u64 offset, u64 size);
void copy_buffer_to_buffer_oneshot(BufferHandle src, u64 src_offset, BufferHandle dst,
diff --git a/src/ral/ral_types.h b/src/ral/ral_types.h
index bb15d2a..a41cf28 100644
--- a/src/ral/ral_types.h
+++ b/src/ral/ral_types.h
@@ -1,6 +1,6 @@
#pragma once
-#include "defines.h"
#include "darray.h"
+#include "defines.h"
#include "maths_types.h"
#include "str.h"
@@ -21,10 +21,10 @@ CORE_DEFINE_HANDLE(ShaderHandle);
CORE_DEFINE_HANDLE(PipelineLayoutHandle);
CORE_DEFINE_HANDLE(PipelineHandle);
CORE_DEFINE_HANDLE(RenderpassHandle);
-#define INVALID_TEX_HANDLE ((TextureHandle){.raw = 9999999 })
+#define INVALID_TEX_HANDLE ((TextureHandle){ .raw = 9999999 })
// --- Buffers
-typedef enum GPU_BufferType{
+typedef enum GPU_BufferType {
BUFFER_DEFAULT, // on Vulkan this would be a storage buffer?
BUFFER_VERTEX,
BUFFER_INDEX,
@@ -142,12 +142,12 @@ typedef enum VertexAttribType {
} VertexAttribType;
typedef struct VertexDescription {
- char* debug_label;
- const char* attr_names[MAX_VERTEX_ATTRIBUTES];
- VertexAttribType attributes[MAX_VERTEX_ATTRIBUTES];
- u32 attributes_count;
- size_t stride;
- bool use_full_vertex_size;
+ char* debug_label;
+ const char* attr_names[MAX_VERTEX_ATTRIBUTES];
+ VertexAttribType attributes[MAX_VERTEX_ATTRIBUTES];
+ u32 attributes_count;
+ size_t stride;
+ bool use_full_vertex_size;
} VertexDescription;
// --- Shaders
@@ -157,10 +157,10 @@ typedef enum PipelineKind {
} PipelineKind;
typedef enum ShaderVisibility {
- VISIBILITY_VERTEX = 1 << 0,
- VISIBILITY_FRAGMENT = 1 << 1,
- VISIBILITY_COMPUTE = 1 << 2,
-} ShaderVisibility ;
+ VISIBILITY_VERTEX = 1 << 0,
+ VISIBILITY_FRAGMENT = 1 << 1,
+ VISIBILITY_COMPUTE = 1 << 2,
+} ShaderVisibility;
typedef struct ShaderDesc {
const char* debug_name;
@@ -171,36 +171,43 @@ typedef struct ShaderDesc {
} ShaderDesc;
typedef enum ShaderBindingKind {
- BINDING_BYTES,
- BINDING_BUFFER,
- BINDING_BUFFER_ARRAY,
- BINDING_TEXTURE,
- BINDING_TEXTURE_ARRAY,
- BINDING_SAMPLER,
- BINDING_COUNT
+ BINDING_BYTES,
+ BINDING_BUFFER,
+ BINDING_BUFFER_ARRAY,
+ BINDING_TEXTURE,
+ BINDING_TEXTURE_ARRAY,
+ BINDING_SAMPLER,
+ BINDING_COUNT
} ShaderBindingKind;
typedef struct ShaderBinding {
- const char* label;
- ShaderBindingKind kind;
- ShaderVisibility vis;
- union {
- struct { u32 size; void* data; } bytes;
- struct { BufferHandle handle; } buffer;
- struct { TextureHandle handle; } texture;
- } data;
+ const char* label;
+ ShaderBindingKind kind;
+ ShaderVisibility vis;
+ union {
+ struct {
+ u32 size;
+ void* data;
+ } bytes;
+ struct {
+ BufferHandle handle;
+ } buffer;
+ struct {
+ TextureHandle handle;
+ } texture;
+ } data;
} ShaderBinding;
typedef struct ShaderDataLayout {
- ShaderBinding bindings[MAX_SHADER_BINDINGS];
- size_t binding_count;
+ ShaderBinding bindings[MAX_SHADER_BINDINGS];
+ size_t binding_count;
} ShaderDataLayout;
typedef ShaderDataLayout (*FN_GetBindingLayout)(void* data);
typedef struct ShaderData {
- FN_GetBindingLayout get_layout;
- void* data;
+ FN_GetBindingLayout get_layout;
+ void* data;
} ShaderData;
// --- Miscellaneous
@@ -236,7 +243,7 @@ typedef struct GraphicsPipelineDesc {
typedef struct GPU_RenderpassDesc {
bool default_framebuffer;
bool has_color_target;
- TextureHandle color_target; // for now only support one
+ TextureHandle color_target; // for now only support one
bool has_depth_stencil;
- TextureHandle depth_stencil;
+ TextureHandle depth_stencil;
} GPU_RenderpassDesc;