Abstract renderer away
This commit is contained in:
parent
7f5b4b22c6
commit
02735e5014
@ -40,7 +40,9 @@ add_compile_options(
|
|||||||
-Wall -Wextra -Wpedantic
|
-Wall -Wextra -Wpedantic
|
||||||
-Wno-nested-anon-types -Wno-keyword-macro -Wno-gnu-auto-type -Wno-auto-decl-extensions -Wno-gnu-empty-initializer -Wno-fixed-enum-extension -Wno-gnu-binary-literal
|
-Wno-nested-anon-types -Wno-keyword-macro -Wno-gnu-auto-type -Wno-auto-decl-extensions -Wno-gnu-empty-initializer -Wno-fixed-enum-extension -Wno-gnu-binary-literal
|
||||||
-fno-exceptions -fno-stack-protector
|
-fno-exceptions -fno-stack-protector
|
||||||
-fdiagnostics-color=always -ferror-limit=1
|
-fdiagnostics-color=always
|
||||||
|
-fansi-escape-codes
|
||||||
|
-ferror-limit=1
|
||||||
-march=native
|
-march=native
|
||||||
${BB_IS_CI_C_FLAG} -DCOMPILER_NAME=\"${COMPILER_NAME}\" -DBUILD_DIR=\"${CMAKE_BINARY_DIR}\" -DBB_DIR=\"${BB_DIR}\"
|
${BB_IS_CI_C_FLAG} -DCOMPILER_NAME=\"${COMPILER_NAME}\" -DBUILD_DIR=\"${CMAKE_BINARY_DIR}\" -DBB_DIR=\"${BB_DIR}\"
|
||||||
)
|
)
|
||||||
@ -210,8 +212,8 @@ if (NOT BB_IS_CI)
|
|||||||
add_subdirectory(dependencies/volk-1.3.301 volk)
|
add_subdirectory(dependencies/volk-1.3.301 volk)
|
||||||
target_link_libraries(${COMPILER_NAME} PRIVATE volk)
|
target_link_libraries(${COMPILER_NAME} PRIVATE volk)
|
||||||
target_sources(${COMPILER_NAME} PRIVATE
|
target_sources(${COMPILER_NAME} PRIVATE
|
||||||
"bootstrap/bloat-buster/shader_compilation.c"
|
"bootstrap/std/image_loader.c"
|
||||||
"bootstrap/bloat-buster/image_loader.c"
|
"bootstrap/std/shader_compilation.c"
|
||||||
"bootstrap/std/font_cache.c"
|
"bootstrap/std/font_cache.c"
|
||||||
"bootstrap/std/font_provider.c"
|
"bootstrap/std/font_provider.c"
|
||||||
"bootstrap/std/graphics.c"
|
"bootstrap/std/graphics.c"
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -77,6 +77,7 @@ declare_slice(s32);
|
|||||||
declare_slice(s64);
|
declare_slice(s64);
|
||||||
|
|
||||||
declare_slice_p(char);
|
declare_slice_p(char);
|
||||||
|
declare_slice_p(void);
|
||||||
|
|
||||||
typedef Slice(u8) String;
|
typedef Slice(u8) String;
|
||||||
declare_slice(String);
|
declare_slice(String);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <std/base.h>
|
#include <std/base.h>
|
||||||
#include <std/os.h>
|
#include <std/os.h>
|
||||||
|
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <std/base.h>
|
#include <std/base.h>
|
||||||
#include <std/os.h>
|
#include <std/os.h>
|
||||||
|
#include <std/render.h>
|
||||||
STRUCT(TextureMemory)
|
|
||||||
{
|
|
||||||
u8* pointer;
|
|
||||||
u32 width;
|
|
||||||
u32 height;
|
|
||||||
u32 channel_count;
|
|
||||||
u32 depth;
|
|
||||||
};
|
|
||||||
|
|
||||||
EXPORT TextureMemory texture_load_from_file(Arena* arena, String path);
|
EXPORT TextureMemory texture_load_from_file(Arena* arena, String path);
|
@ -0,0 +1,183 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <std/base.h>
|
||||||
|
|
||||||
|
#include <std/graphics.h>
|
||||||
|
|
||||||
|
#define frame_overlap (2)
|
||||||
|
|
||||||
|
typedef struct Renderer Renderer;
|
||||||
|
typedef struct RenderWindow RenderWindow;
|
||||||
|
typedef struct Pipeline Pipeline;
|
||||||
|
|
||||||
|
typedef enum IndexType : u8
|
||||||
|
{
|
||||||
|
INDEX_TYPE_U16,
|
||||||
|
INDEX_TYPE_U32,
|
||||||
|
} IndexType;
|
||||||
|
|
||||||
|
typedef enum TextureFormat : u8
|
||||||
|
{
|
||||||
|
R8_UNORM,
|
||||||
|
R8G8B8A8_SRGB,
|
||||||
|
} TextureFormat;
|
||||||
|
|
||||||
|
STRUCT(TextureMemory)
|
||||||
|
{
|
||||||
|
u8* pointer;
|
||||||
|
u32 width;
|
||||||
|
u32 height;
|
||||||
|
u32 depth;
|
||||||
|
TextureFormat format;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef enum ShaderStage : u8
|
||||||
|
{
|
||||||
|
SHADER_STAGE_VERTEX,
|
||||||
|
SHADER_STAGE_FRAGMENT,
|
||||||
|
} ShaderStage;
|
||||||
|
|
||||||
|
STRUCT(PipelineCreate)
|
||||||
|
{
|
||||||
|
Slice(u16) shader_source_indices;
|
||||||
|
u16 layout_index;
|
||||||
|
};
|
||||||
|
declare_slice(PipelineCreate);
|
||||||
|
|
||||||
|
STRUCT(PushConstantRange)
|
||||||
|
{
|
||||||
|
u16 offset;
|
||||||
|
u16 size;
|
||||||
|
ShaderStage stage;
|
||||||
|
};
|
||||||
|
declare_slice(PushConstantRange);
|
||||||
|
|
||||||
|
typedef enum DescriptorType : u8
|
||||||
|
{
|
||||||
|
DESCRIPTOR_TYPE_IMAGE_PLUS_SAMPLER,
|
||||||
|
DESCRIPTOR_TYPE_COUNT,
|
||||||
|
} DescriptorType;
|
||||||
|
|
||||||
|
STRUCT(DescriptorSetLayoutBinding)
|
||||||
|
{
|
||||||
|
u8 binding;
|
||||||
|
DescriptorType type;
|
||||||
|
ShaderStage stage;
|
||||||
|
u8 count;
|
||||||
|
};
|
||||||
|
declare_slice(DescriptorSetLayoutBinding);
|
||||||
|
|
||||||
|
STRUCT(DescriptorSetLayout)
|
||||||
|
{
|
||||||
|
Slice(DescriptorSetLayoutBinding) bindings;
|
||||||
|
};
|
||||||
|
declare_slice(DescriptorSetLayout);
|
||||||
|
|
||||||
|
STRUCT(PipelineLayoutCreate)
|
||||||
|
{
|
||||||
|
Slice(PushConstantRange) push_constant_ranges;
|
||||||
|
Slice(DescriptorSetLayout) descriptor_set_layouts;
|
||||||
|
};
|
||||||
|
declare_slice(PipelineLayoutCreate);
|
||||||
|
|
||||||
|
STRUCT(GraphicsPipelinesCreate)
|
||||||
|
{
|
||||||
|
Slice(String) shader_sources;
|
||||||
|
Slice(PipelineLayoutCreate) layouts;
|
||||||
|
Slice(PipelineCreate) pipelines;
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(TextureIndex)
|
||||||
|
{
|
||||||
|
u32 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(PipelineIndex)
|
||||||
|
{
|
||||||
|
u32 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(PipelineLayoutIndex)
|
||||||
|
{
|
||||||
|
u32 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(DescriptorSetIndex)
|
||||||
|
{
|
||||||
|
u32 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MAX_TEXTURE_UPDATE_COUNT (32)
|
||||||
|
#define MAX_DESCRIPTOR_SET_UPDATE_COUNT (16)
|
||||||
|
STRUCT(DescriptorSetUpdate)
|
||||||
|
{
|
||||||
|
DescriptorSetIndex set;
|
||||||
|
DescriptorType type;
|
||||||
|
u32 binding;
|
||||||
|
u32 descriptor_count;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
TextureIndex textures[MAX_TEXTURE_UPDATE_COUNT];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
declare_slice(DescriptorSetUpdate);
|
||||||
|
|
||||||
|
typedef enum BufferType : u8
|
||||||
|
{
|
||||||
|
BUFFER_TYPE_VERTEX,
|
||||||
|
BUFFER_TYPE_INDEX,
|
||||||
|
BUFFER_TYPE_STAGING,
|
||||||
|
} BufferType;
|
||||||
|
|
||||||
|
STRUCT(BufferIndex)
|
||||||
|
{
|
||||||
|
u32 value;
|
||||||
|
};
|
||||||
|
|
||||||
|
STRUCT(HostBufferCopy)
|
||||||
|
{
|
||||||
|
String source;
|
||||||
|
u64 destination_offset;
|
||||||
|
};
|
||||||
|
declare_slice(HostBufferCopy);
|
||||||
|
|
||||||
|
STRUCT(LocalBufferCopyRegion)
|
||||||
|
{
|
||||||
|
u64 source_offset;
|
||||||
|
u64 destination_offset;
|
||||||
|
u64 size;
|
||||||
|
};
|
||||||
|
declare_slice(LocalBufferCopyRegion);
|
||||||
|
|
||||||
|
STRUCT(LocalBufferCopy)
|
||||||
|
{
|
||||||
|
BufferIndex destination;
|
||||||
|
BufferIndex source;
|
||||||
|
Slice(LocalBufferCopyRegion) regions;
|
||||||
|
};
|
||||||
|
declare_slice(LocalBufferCopy);
|
||||||
|
|
||||||
|
#define MAX_LOCAL_BUFFER_COPY_COUNT (16)
|
||||||
|
|
||||||
|
EXPORT Renderer* renderer_initialize();
|
||||||
|
EXPORT RenderWindow* renderer_window_initialize(Renderer* renderer, GraphicsWindow* window);
|
||||||
|
EXPORT PipelineIndex renderer_graphics_pipelines_create(Renderer* renderer, Arena* arena, GraphicsPipelinesCreate create_data);
|
||||||
|
EXPORT PipelineLayoutIndex renderer_pipeline_get_layout(PipelineIndex pipeline);
|
||||||
|
EXPORT GraphicsWindowSize renderer_window_frame_begin(Renderer* renderer, RenderWindow* window);
|
||||||
|
EXPORT void renderer_window_frame_end(Renderer* renderer, RenderWindow* window);
|
||||||
|
EXPORT TextureIndex renderer_texture_create(Renderer* renderer, TextureMemory texture_memory);
|
||||||
|
EXPORT BufferIndex renderer_buffer_create(Renderer* renderer, u64 size, BufferType type);
|
||||||
|
EXPORT void renderer_update_pipeline_resources(Renderer* renderer, PipelineIndex pipeline_index, Slice(DescriptorSetUpdate) descriptor_updates);
|
||||||
|
EXPORT void renderer_copy_to_host(BufferIndex buffer_index, Slice(HostBufferCopy) regions);
|
||||||
|
EXPORT void renderer_copy_to_local(Renderer* renderer, Slice(LocalBufferCopy) copies);
|
||||||
|
EXPORT void window_command_begin(RenderWindow* window);
|
||||||
|
EXPORT void window_command_end(RenderWindow* window);
|
||||||
|
EXPORT void window_render_begin(RenderWindow* window);
|
||||||
|
EXPORT void window_render_end(RenderWindow* window);
|
||||||
|
|
||||||
|
EXPORT void window_bind_pipeline(RenderWindow* window, PipelineIndex pipeline_index);
|
||||||
|
EXPORT void window_bind_pipeline_descriptor_sets(RenderWindow* window, PipelineIndex pipeline_index);
|
||||||
|
EXPORT void window_bind_index_buffer(RenderWindow* window, BufferIndex index_buffer, u64 offset, IndexType index_type);
|
||||||
|
EXPORT void window_push_constants(RenderWindow* window, PipelineIndex pipeline_index, SliceP(void) memories);
|
||||||
|
EXPORT u64 buffer_address(BufferIndex buffer_index);
|
||||||
|
EXPORT void window_draw_indexed(RenderWindow* window, u32 index_count, u32 instance_count, u32 first_index, s32 vertex_offset, u32 first_instance);
|
@ -1,10 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <std/base.h>
|
#include <std/base.h>
|
||||||
#include <std/os.h>
|
#include <std/os.h>
|
||||||
|
|
||||||
typedef enum ShaderStage : u8
|
#include <std/render.h>
|
||||||
{
|
|
||||||
SHADER_STAGE_VERTEX,
|
|
||||||
SHADER_STAGE_FRAGMENT,
|
|
||||||
} ShaderStage;
|
|
||||||
|
|
||||||
EXPORT String compile_shader(Arena* arena, String path, ShaderStage shader_stage);
|
EXPORT String compile_shader(Arena* arena, String path, ShaderStage shader_stage);
|
@ -104,6 +104,7 @@ fn void run_tests(Arena* arena, String compiler_path, TestOptions const * const
|
|||||||
|
|
||||||
run_command(arena, (CStringSlice) array_to_slice(arguments), envp);
|
run_command(arena, (CStringSlice) array_to_slice(arguments), envp);
|
||||||
|
|
||||||
|
#if BB_CI
|
||||||
// if (compiler_backend != COMPILER_BACKEND_INTERPRETER)
|
// if (compiler_backend != COMPILER_BACKEND_INTERPRETER)
|
||||||
{
|
{
|
||||||
auto executable = binary_path_from_options(arena, (BinaryPathOptions) {
|
auto executable = binary_path_from_options(arena, (BinaryPathOptions) {
|
||||||
@ -119,6 +120,7 @@ fn void run_tests(Arena* arena, String compiler_path, TestOptions const * const
|
|||||||
};
|
};
|
||||||
run_command(arena, (CStringSlice) array_to_slice(run_arguments), envp);
|
run_command(arena, (CStringSlice) array_to_slice(run_arguments), envp);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
#include <bloat-buster/font.h>
|
#include <std/font_provider.h>
|
||||||
|
|
||||||
#define STBTT_STATIC
|
#define STBTT_STATIC
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#include <stb_truetype.h>
|
#include <stb_truetype.h>
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
|
TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
|
||||||
{
|
{
|
||||||
@ -75,7 +78,7 @@ TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
|
|||||||
character->width = width;
|
character->width = width;
|
||||||
character->height = height;
|
character->height = height;
|
||||||
|
|
||||||
print("Drawing codepoint '{c}' ({u32}x{u32}) at ({u32}, {u32}). Offsets: ({s32}, {s32})\n", ch, width, height, x, y, character->x_offset, character->y_offset);
|
// print("Drawing codepoint '{c}' ({u32}x{u32}) at ({u32}, {u32}). Offsets: ({s32}, {s32})\n", ch, width, height, x, y, character->x_offset, character->y_offset);
|
||||||
|
|
||||||
auto* source = bitmap;
|
auto* source = bitmap;
|
||||||
auto* destination = result.pointer;
|
auto* destination = result.pointer;
|
||||||
@ -89,23 +92,23 @@ TextureAtlas font_create_texture_atlas(Arena* arena, TextureAtlasCreate create)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (u32 bitmap_y = y; bitmap_y < y + height; bitmap_y += 1)
|
// for (u32 bitmap_y = y; bitmap_y < y + height; bitmap_y += 1)
|
||||||
{
|
// {
|
||||||
for (u32 bitmap_x = x; bitmap_x < x + width; bitmap_x += 1)
|
// for (u32 bitmap_x = x; bitmap_x < x + width; bitmap_x += 1)
|
||||||
{
|
// {
|
||||||
auto x = result.pointer[bitmap_y * result.width + bitmap_x];
|
// auto x = result.pointer[bitmap_y * result.width + bitmap_x];
|
||||||
if (x)
|
// if (x)
|
||||||
{
|
// {
|
||||||
print("[x]");
|
// print("[x]");
|
||||||
}
|
// }
|
||||||
else
|
// else
|
||||||
{
|
// {
|
||||||
print("[ ]");
|
// print("[ ]");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
print("\n");
|
// print("\n");
|
||||||
}
|
// }
|
||||||
|
|
||||||
x += width;
|
x += width;
|
||||||
|
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
#include <bloat-buster/image_loader.h>
|
#include <std/image_loader.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_STATIC
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-function"
|
||||||
#include <stb_image.h>
|
#include <stb_image.h>
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
EXPORT TextureMemory texture_load_from_file(Arena* arena, String path)
|
EXPORT TextureMemory texture_load_from_file(Arena* arena, String path)
|
||||||
{
|
{
|
||||||
@ -16,7 +21,7 @@ EXPORT TextureMemory texture_load_from_file(Arena* arena, String path)
|
|||||||
.pointer = buffer,
|
.pointer = buffer,
|
||||||
.width = width,
|
.width = width,
|
||||||
.height = height,
|
.height = height,
|
||||||
.channel_count = channels,
|
.format = R8G8B8A8_SRGB,
|
||||||
.depth = 1,
|
.depth = 1,
|
||||||
};
|
};
|
||||||
}
|
}
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
|||||||
#include <bloat-buster/shader_compilation.h>
|
#include <std/shader_compilation.h>
|
||||||
#include <glslang/Include/glslang_c_interface.h>
|
#include <glslang/Include/glslang_c_interface.h>
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user