Skip to content

Commit 316fe11

Browse files
author
amalxloop
committed
Implement buffer/shader/pipeline resource management, index buffer support, and CI sanitizer jobs
1 parent c4b44e4 commit 316fe11

6 files changed

Lines changed: 647 additions & 35 deletions

File tree

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,30 @@ jobs:
4949
-lm -lvulkan -o /tmp/test_vk
5050
/tmp/test_vk
5151
52+
test-asan:
53+
runs-on: ubuntu-latest
54+
steps:
55+
- uses: actions/checkout@v4
56+
- name: Build & test with AddressSanitizer
57+
run: |
58+
for t in test_arena test_math test_layout test_gfx test_runtime test_font; do
59+
clang -I include -I tools -Wall -Wextra -Wpedantic -Wshadow \
60+
-fsanitize=address -fno-omit-frame-pointer \
61+
tests/${t}.c -lm -o /tmp/$t && /tmp/$t
62+
done
63+
64+
test-ubsan:
65+
runs-on: ubuntu-latest
66+
steps:
67+
- uses: actions/checkout@v4
68+
- name: Build & test with UndefinedBehaviorSanitizer
69+
run: |
70+
for t in test_arena test_math test_layout test_gfx test_runtime test_font; do
71+
clang -I include -I tools -Wall -Wextra -Wpedantic -Wshadow \
72+
-fsanitize=undefined -fno-sanitize-recover=undefined \
73+
tests/${t}.c -lm -o /tmp/$t && /tmp/$t
74+
done
75+
5276
wasm:
5377
runs-on: ubuntu-latest
5478
steps:

apps/stock_dashboard/stock_dashboard.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,22 @@
3131
* stock_dashboard.c -o stock_dashboard -lm
3232
*/
3333

34-
#ifndef SC_NO_IMPLEMENTATION
34+
#ifndef SC_GFX_IMPLEMENTATION
3535
#define SC_GFX_IMPLEMENTATION
36+
#endif
37+
#ifndef SC_LAYOUT_IMPLEMENTATION
3638
#define SC_LAYOUT_IMPLEMENTATION
39+
#endif
40+
#ifndef SC_WIDGET_IMPLEMENTATION
3741
#define SC_WIDGET_IMPLEMENTATION
42+
#endif
43+
#ifndef SC_RUNTIME_IMPLEMENTATION
3844
#define SC_RUNTIME_IMPLEMENTATION
45+
#endif
46+
#ifndef SC_FONT_IMPLEMENTATION
3947
#define SC_FONT_IMPLEMENTATION
48+
#endif
49+
#ifndef SC_GFX_BACKEND_SOFTWARE
4050
#define SC_GFX_BACKEND_SOFTWARE
4151
#endif
4252

backends/sc_backend_d3d12.h

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,30 @@ typedef struct SCD3D12Desc {
1919
u32 frame_latency; /* swap-chain frame latency (1–3) */
2020
} SCD3D12Desc;
2121

22-
SCResult sc_d3d12_init (SCGfxContext *ctx, const SCGfxDesc *desc,
23-
const SCD3D12Desc *d3d_desc);
24-
void sc_d3d12_shutdown(SCGfxContext *ctx);
25-
void sc_d3d12_begin_frame(SCGfxContext *ctx, SCColor clear);
26-
void sc_d3d12_submit (SCGfxContext *ctx,
22+
SCResult sc_d3d12_init (SCGfxContext *ctx, const SCGfxDesc *desc,
23+
const SCD3D12Desc *d3d_desc);
24+
void sc_d3d12_shutdown (SCGfxContext *ctx);
25+
void sc_d3d12_begin_frame (SCGfxContext *ctx, SCColor clear);
26+
void sc_d3d12_submit (SCGfxContext *ctx,
2727
const SCGfxDrawCmd *cmds, u32 count);
28-
void sc_d3d12_end_frame (SCGfxContext *ctx);
28+
void sc_d3d12_end_frame (SCGfxContext *ctx);
29+
SCGfxBuffer sc_d3d12_make_buffer (SCGfxContext *ctx, const SCGfxBufferDesc *desc);
30+
void sc_d3d12_destroy_buffer(SCGfxContext *ctx, SCGfxBuffer buf);
31+
void sc_d3d12_update_buffer (SCGfxContext *ctx, SCGfxBuffer buf,
32+
const void *data, usize size);
33+
SCGfxTexture sc_d3d12_make_texture (SCGfxContext *ctx, const SCGfxTextureDesc *desc);
34+
void sc_d3d12_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex);
35+
SCGfxShader sc_d3d12_make_shader (SCGfxContext *ctx, const SCGfxShaderDesc *desc);
36+
void sc_d3d12_destroy_shader(SCGfxContext *ctx, SCGfxShader shd);
37+
SCGfxPipeline sc_d3d12_make_pipeline (SCGfxContext *ctx, const SCGfxPipelineDesc *desc);
38+
void sc_d3d12_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip);
2939

3040
#ifdef SC_BACKEND_D3D12_IMPLEMENTATION
3141
#include <stdio.h>
3242

3343
SCResult sc_d3d12_init(SCGfxContext *ctx, const SCGfxDesc *desc,
3444
const SCD3D12Desc *d3d_desc) {
3545
SC_UNUSED(ctx); SC_UNUSED(desc); SC_UNUSED(d3d_desc);
36-
/*
37-
* TODO:
38-
* D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_11_0, ...)
39-
* CreateCommandQueue / CreateSwapChain / CreateDescriptorHeaps
40-
* CreateRootSignature / CompileShader (D3DCompileFromFile)
41-
* CreateGraphicsPipelineState
42-
* CreateCommandAllocator / CreateCommandList
43-
* per-frame fence + event
44-
*/
4546
fprintf(stderr, "[sc_d3d12] stub – link d3d12.lib on Windows\n");
4647
return SC_ERR_NOT_SUPPORTED;
4748
}
@@ -51,5 +52,32 @@ void sc_d3d12_submit(SCGfxContext *ctx, const SCGfxDrawCmd *cmds, u32 n) {
5152
SC_UNUSED(ctx); SC_UNUSED(cmds); SC_UNUSED(n);
5253
}
5354
void sc_d3d12_end_frame(SCGfxContext *ctx) { SC_UNUSED(ctx); }
55+
SCGfxBuffer sc_d3d12_make_buffer(SCGfxContext *ctx, const SCGfxBufferDesc *desc) {
56+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxBuffer h = {0}; return h;
57+
}
58+
void sc_d3d12_destroy_buffer(SCGfxContext *ctx, SCGfxBuffer buf) {
59+
SC_UNUSED(ctx); SC_UNUSED(buf);
60+
}
61+
void sc_d3d12_update_buffer(SCGfxContext *ctx, SCGfxBuffer buf, const void *data, usize size) {
62+
SC_UNUSED(ctx); SC_UNUSED(buf); SC_UNUSED(data); SC_UNUSED(size);
63+
}
64+
SCGfxTexture sc_d3d12_make_texture(SCGfxContext *ctx, const SCGfxTextureDesc *desc) {
65+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxTexture h = {0}; return h;
66+
}
67+
void sc_d3d12_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex) {
68+
SC_UNUSED(ctx); SC_UNUSED(tex);
69+
}
70+
SCGfxShader sc_d3d12_make_shader(SCGfxContext *ctx, const SCGfxShaderDesc *desc) {
71+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxShader h = {0}; return h;
72+
}
73+
void sc_d3d12_destroy_shader(SCGfxContext *ctx, SCGfxShader shd) {
74+
SC_UNUSED(ctx); SC_UNUSED(shd);
75+
}
76+
SCGfxPipeline sc_d3d12_make_pipeline(SCGfxContext *ctx, const SCGfxPipelineDesc *desc) {
77+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxPipeline h = {0}; return h;
78+
}
79+
void sc_d3d12_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip) {
80+
SC_UNUSED(ctx); SC_UNUSED(pip);
81+
}
5482
#endif /* SC_BACKEND_D3D12_IMPLEMENTATION */
5583
#endif /* SC_BACKEND_D3D12_H */

backends/sc_backend_metal.h

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,28 @@
1414
#include "../include/sc_types.h"
1515
#include "../include/sc_gfx.h"
1616

17-
SCResult sc_metal_init (SCGfxContext *ctx, const SCGfxDesc *desc);
18-
void sc_metal_shutdown(SCGfxContext *ctx);
19-
void sc_metal_begin_frame(SCGfxContext *ctx, SCColor clear);
20-
void sc_metal_submit (SCGfxContext *ctx,
17+
SCResult sc_metal_init (SCGfxContext *ctx, const SCGfxDesc *desc);
18+
void sc_metal_shutdown (SCGfxContext *ctx);
19+
void sc_metal_begin_frame (SCGfxContext *ctx, SCColor clear);
20+
void sc_metal_submit (SCGfxContext *ctx,
2121
const SCGfxDrawCmd *cmds, u32 count);
22-
void sc_metal_end_frame (SCGfxContext *ctx);
22+
void sc_metal_end_frame (SCGfxContext *ctx);
23+
SCGfxBuffer sc_metal_make_buffer (SCGfxContext *ctx, const SCGfxBufferDesc *desc);
24+
void sc_metal_destroy_buffer(SCGfxContext *ctx, SCGfxBuffer buf);
25+
void sc_metal_update_buffer (SCGfxContext *ctx, SCGfxBuffer buf,
26+
const void *data, usize size);
27+
SCGfxTexture sc_metal_make_texture (SCGfxContext *ctx, const SCGfxTextureDesc *desc);
28+
void sc_metal_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex);
29+
SCGfxShader sc_metal_make_shader (SCGfxContext *ctx, const SCGfxShaderDesc *desc);
30+
void sc_metal_destroy_shader(SCGfxContext *ctx, SCGfxShader shd);
31+
SCGfxPipeline sc_metal_make_pipeline (SCGfxContext *ctx, const SCGfxPipelineDesc *desc);
32+
void sc_metal_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip);
2333

2434
#ifdef SC_BACKEND_METAL_IMPLEMENTATION
2535
#include <stdio.h>
2636

2737
SCResult sc_metal_init(SCGfxContext *ctx, const SCGfxDesc *desc) {
2838
SC_UNUSED(ctx); SC_UNUSED(desc);
29-
/*
30-
* TODO (ObjC/Swift):
31-
* id<MTLDevice> device = MTLCreateSystemDefaultDevice();
32-
* id<MTLCommandQueue> queue = [device newCommandQueue];
33-
* CAMetalLayer *layer = [CAMetalLayer layer];
34-
* layer.device = device; layer.pixelFormat = MTLPixelFormatBGRA8Unorm;
35-
* MTLRenderPipelineDescriptor *pd = ...
36-
*/
3739
fprintf(stderr, "[sc_metal] stub – compile as Obj-C and link Metal\n");
3840
return SC_ERR_NOT_SUPPORTED;
3941
}
@@ -43,5 +45,32 @@ void sc_metal_submit(SCGfxContext *ctx, const SCGfxDrawCmd *cmds, u32 n) {
4345
SC_UNUSED(ctx); SC_UNUSED(cmds); SC_UNUSED(n);
4446
}
4547
void sc_metal_end_frame(SCGfxContext *ctx) { SC_UNUSED(ctx); }
48+
SCGfxBuffer sc_metal_make_buffer(SCGfxContext *ctx, const SCGfxBufferDesc *desc) {
49+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxBuffer h = {0}; return h;
50+
}
51+
void sc_metal_destroy_buffer(SCGfxContext *ctx, SCGfxBuffer buf) {
52+
SC_UNUSED(ctx); SC_UNUSED(buf);
53+
}
54+
void sc_metal_update_buffer(SCGfxContext *ctx, SCGfxBuffer buf, const void *data, usize size) {
55+
SC_UNUSED(ctx); SC_UNUSED(buf); SC_UNUSED(data); SC_UNUSED(size);
56+
}
57+
SCGfxTexture sc_metal_make_texture(SCGfxContext *ctx, const SCGfxTextureDesc *desc) {
58+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxTexture h = {0}; return h;
59+
}
60+
void sc_metal_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex) {
61+
SC_UNUSED(ctx); SC_UNUSED(tex);
62+
}
63+
SCGfxShader sc_metal_make_shader(SCGfxContext *ctx, const SCGfxShaderDesc *desc) {
64+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxShader h = {0}; return h;
65+
}
66+
void sc_metal_destroy_shader(SCGfxContext *ctx, SCGfxShader shd) {
67+
SC_UNUSED(ctx); SC_UNUSED(shd);
68+
}
69+
SCGfxPipeline sc_metal_make_pipeline(SCGfxContext *ctx, const SCGfxPipelineDesc *desc) {
70+
SC_UNUSED(ctx); SC_UNUSED(desc); SCGfxPipeline h = {0}; return h;
71+
}
72+
void sc_metal_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip) {
73+
SC_UNUSED(ctx); SC_UNUSED(pip);
74+
}
4675
#endif /* SC_BACKEND_METAL_IMPLEMENTATION */
4776
#endif /* SC_BACKEND_METAL_H */

0 commit comments

Comments
 (0)