diff options
author | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-17 23:12:42 +1000 |
---|---|---|
committer | omnisci3nce <omniscient.oce@gmail.com> | 2024-07-17 23:12:42 +1000 |
commit | c3737fff1be704e14a2bada69bbf8a6709c5f670 (patch) | |
tree | aa2225901f26598b07855a65a944354fbedc40b1 /src/render | |
parent | f8641a5cc4c8baf1f0a7be3685afc219d90143d9 (diff) |
wip shader layouts for common stuff
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/ral.h | 184 | ||||
-rw-r--r-- | src/render/render_types.h | 181 |
2 files changed, 0 insertions, 365 deletions
diff --git a/src/render/ral.h b/src/render/ral.h deleted file mode 100644 index fc3c96c..0000000 --- a/src/render/ral.h +++ /dev/null @@ -1,184 +0,0 @@ -/** - * @file ral.h - * @author your name (you@domain.com) - * @brief Render Abstraction Layer - * @details API that a graphics backend *must* implement - * @version 0.1 - * @date 2024-03-31 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once - -#include "buf.h" -#include "defines.h" -#include "mem.h" -#include "ral_types.h" -#include "str.h" - -// Unrelated forward declares -struct GLFWwindow; - -// 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; - -// #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_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); - -// --- Pipeline description -typedef enum pipeline_kind { - PIPELINE_GRAPHICS, - PIPELINE_COMPUTE, -} pipeline_kind; - -typedef struct shader_desc { - const char* debug_name; - str8 filepath; // Where it came from - str8 code; // Either GLSL or SPIRV bytecode - bool is_spirv; - bool is_combined_vert_frag; // Contains both vertex and fragment stages -} shader_desc; - -shader_desc shader_quick_load(const char* filepath); -/** @brief Hot reloads shaders for the given pipeline. Returns how long it took in milliseconds */ -u64 gpu_pipeline_reload_shaders(gpu_pipeline* pipeline); // TODO - -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; -}; - -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; - -// --- Lifecycle functions -// bool gpu_backend_init(const char* window_name, struct GLFWwindow* window); -// void gpu_backend_shutdown(); -void resource_pools_init(arena* a, struct resource_pools* res_pools); - -// bool gpu_device_create(gpu_device* out_device); -// void gpu_device_destroy(); - -// // --- Render Pipeline -// 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); - -// --- Command buffer -gpu_cmd_encoder gpu_cmd_encoder_create(); -void gpu_cmd_encoder_destroy(gpu_cmd_encoder* encoder); -void gpu_cmd_encoder_begin(gpu_cmd_encoder encoder); -void gpu_cmd_encoder_begin_render(gpu_cmd_encoder* encoder, gpu_renderpass* renderpass); -void gpu_cmd_encoder_end_render(gpu_cmd_encoder* encoder); -void gpu_cmd_encoder_begin_compute(); -gpu_cmd_encoder* gpu_get_default_cmd_encoder(); - -/** @brief Finish recording and return a command buffer that can be submitted to a queue */ -gpu_cmd_buffer gpu_cmd_encoder_finish(gpu_cmd_encoder* encoder); - -void gpu_queue_submit(gpu_cmd_buffer* buffer); - -// --- Data copy commands -/** @brief Copy data from one buffer to another */ -void encode_buffer_copy(gpu_cmd_encoder* encoder, buffer_handle src, u64 src_offset, - buffer_handle dst, u64 dst_offset, u64 copy_size); -/** @brief Upload CPU-side data as array of bytes to a GPU buffer */ -void buffer_upload_bytes(buffer_handle gpu_buf, bytebuffer cpu_buf, u64 offset, u64 size); - -/** @brief Copy data from buffer to buffer using a one time submit command buffer and a wait */ -void copy_buffer_to_buffer_oneshot(buffer_handle src, u64 src_offset, buffer_handle dst, - u64 dst_offset, u64 copy_size); -/** @brief Copy data from buffer to an image using a one time submit command buffer */ -void copy_buffer_to_image_oneshot(buffer_handle src, texture_handle dst); - -// --- Render commands -void encode_bind_pipeline(gpu_cmd_encoder* encoder, pipeline_kind kind, gpu_pipeline* pipeline); -void encode_bind_shader_data(gpu_cmd_encoder* encoder, u32 group, shader_data* data); -void encode_set_default_settings(gpu_cmd_encoder* encoder); -void encode_set_vertex_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); -void encode_set_index_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); -void encode_set_bind_group(); // TODO -void encode_draw(gpu_cmd_encoder* encoder, u64 count); -void encode_draw_indexed(gpu_cmd_encoder* encoder, u64 index_count); -void encode_clear_buffer(gpu_cmd_encoder* encoder, buffer_handle buf); - -// --- Buffers -// --- Vertex formats -bytebuffer vertices_as_bytebuffer(arena* a, vertex_format format, vertex_darray* vertices); - -void vertex_desc_add(vertex_description* builder, const char* name, vertex_attrib_type type); - -// --- TEMP -bool gpu_backend_begin_frame(); -void gpu_backend_end_frame(); -void gpu_temp_draw(size_t n_verts); - -// TODO: --- Compute - -// --- Helpers -vertex_description static_3d_vertex_description(); -size_t vertex_attrib_size(vertex_attrib_type attr); diff --git a/src/render/render_types.h b/src/render/render_types.h deleted file mode 100644 index b25fa14..0000000 --- a/src/render/render_types.h +++ /dev/null @@ -1,181 +0,0 @@ -/** - * @file render_types.h - * @author your name (you@domain.com) - * @brief - * @version 0.1 - * @date 2024-04-27 - * - * @copyright Copyright (c) 2024 - * - */ -#pragma once - -#include "colours.h" -#include "defines.h" -#include "ral.h" -#include "ral_types.h" -#if defined(CEL_PLATFORM_WINDOWS) -// #include "backend_dx11.h" -#endif -#if defined(CEL_REND_BACKEND_VULKAN) -#include "backend_vulkan.h" -#elif defined(CEL_REND_BACKEND_METAL) -#include "backend_metal.h" -#elif defined(CEL_REND_BACKEND_OPENGL) -#include "backend_opengl.h" -#endif - -struct GLFWwindow; - -typedef struct geometry_data { - vertex_format format; - vertex_darray* vertices; // TODO: make it not a pointer - bool has_indices; - u32_darray* indices; - rgba colour; /** Optional: set vertex colours */ -} geometry_data; - -typedef struct u32_opt { - u32 value; - bool has_value; -} u32_opt; - -// 'Upload' a geometry_data (to GPU) -> get back a mesh -typedef struct mesh { - buffer_handle vertex_buffer; - buffer_handle index_buffer; - geometry_data* geometry; // NULL means it has been freed - u32_opt material_index; - bool is_uploaded; - bool is_latent; -} mesh; - -#ifndef TYPED_MESH_ARRAY -KITC_DECL_TYPED_ARRAY(mesh) -#define TYPED_MESH_ARRAY -#endif - -/* Hot reloading: -C side - reload_model(): - - load model from disk using existing loader - - remove from transform graph so it isnt tried to be drawn -*/ - -typedef struct texture { -} texture; - -typedef struct texture_data { - texture_desc description; - void* image_data; -} texture_data; - -typedef enum material_kind { - MAT_BLINN_PHONG, - MAT_PBR, - MAT_PBR_PARAMS, // uses float values to represent a surface uniformly - MAT_COUNT -} material_kind; -static const char* material_kind_names[] = { "Blinn Phong", "PBR (Textures)", "PBR (Params)", - "Count (This should be an error)" }; - -typedef struct blinn_phong_material { - char name[256]; - texture diffuse_texture; - char diffuse_tex_path[256]; - texture specular_texture; - char specular_tex_path[256]; - vec3 ambient_colour; - vec3 diffuse; - vec3 specular; - f32 spec_exponent; - bool is_loaded; - bool is_uploaded; -} blinn_phong_material; -// typedef blinn_phong_material material; - -typedef struct pbr_parameters { - vec3 albedo; - f32 metallic; - f32 roughness; - f32 ao; -} pbr_parameters; - -typedef struct pbr_material { - texture_handle albedo_map; - texture_handle normal_map; - bool metal_roughness_combined; - texture_handle metallic_map; - texture_handle roughness_map; - texture_handle ao_map; -} pbr_material; - -typedef struct material { - material_kind kind; - union { - blinn_phong_material blinn_phong; - pbr_parameters pbr_params; - pbr_material pbr; - } mat_data; - char* name; -} material; - -#ifndef TYPED_MATERIAL_ARRAY -KITC_DECL_TYPED_ARRAY(material) -#define TYPED_MATERIAL_ARRAY -#endif - -CORE_DEFINE_HANDLE(model_handle); - -typedef struct model { - str8 name; - mesh_darray* meshes; - material_darray* materials; -} model; - -TYPED_POOL(model, model) - -// FIXME: the default blinn-phong material. MUST be initialised with the function below -// FIXME: extern material DEFAULT_MATERIAL; -void default_material_init(); - -#ifndef TYPED_MODEL_ARRAY -KITC_DECL_TYPED_ARRAY(model) -#define TYPED_MODEL_ARRAY -#endif - -#ifndef TYPED_ANIMATION_CLIP_ARRAY -#include "animation.h" -KITC_DECL_TYPED_ARRAY(animation_clip) -#define TYPED_ANIMATION_CLIP_ARRAY -#endif - -/** @brief Describes all the data required for the renderer to start executing draws */ -typedef struct render_entity { - /* buffer_handle index_buffer; */ - /* u32 index_count; */ - /* u32 index_offset; */ - /* buffer_handle vertex_buffer; */ - model_handle model; - transform tf; -} render_entity; - -#ifndef TYPED_RENDER_ENTITY_ARRAY -KITC_DECL_TYPED_ARRAY(render_entity) -#define TYPED_RENDER_ENTITY_ARRAY -#endif - -// --- Lights -typedef struct point_light { - vec3 position; - f32 constant, linear, quadratic; - vec3 ambient; - vec3 diffuse; - vec3 specular; -} point_light; - -typedef struct directional_light { - vec3 direction; - vec3 ambient; - vec3 diffuse; - vec3 specular; -} directional_light; |