Skip to content

Commit 1369482

Browse files
author
amalxloop
committed
CI pipeline, sc_gfx_resize, Vulkan swapchain resize, WASM fixes
- CI pipeline (.github/workflows/ci.yml): three jobs — software backend test (all 6 suites + stock_dashboard PPM), Vulkan backend (install SDK, compile, headless gfx test), WASM (setup emsdk, build with emcmake) - sc_gfx_resize: new API to handle window resize. Software backend reallocs framebuffer; Vulkan backend recreates swapchain or offscreen resources. Forward declarations + dispatch in sc_gfx.h - sc_vulkan_resize: handles both headless (destroy/recreate offscreen image/view/fbo) and windowed (recreate swapchain via existing _sc_vk_recreate_swapchain) - WASM CMakeLists.fixed: correct unity TU path, added -I tools for stb_truetype, sc_font support; replaced deprecated LINK_FLAGS with target_link_options; exported sc_gfx_resize - silvercore.js: added gfx_resize wrapper
1 parent 8409795 commit 1369482

5 files changed

Lines changed: 124 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: CI
2+
on: [push, pull_request]
3+
4+
jobs:
5+
test-software:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v4
9+
- name: Build & test (software backend)
10+
run: |
11+
for t in test_arena test_math test_layout test_gfx test_runtime test_font; do
12+
clang -I include -I tools -Wall -Wextra -Wpedantic -Wshadow \
13+
tests/${t}.c -lm -o /tmp/$t && /tmp/$t
14+
done
15+
- name: Build stock_dashboard + PPM output
16+
run: |
17+
clang -O3 -DSC_GFX_IMPLEMENTATION -DSC_LAYOUT_IMPLEMENTATION \
18+
-DSC_WIDGET_IMPLEMENTATION -DSC_RUNTIME_IMPLEMENTATION \
19+
-DSC_FONT_IMPLEMENTATION -DSC_GFX_BACKEND_SOFTWARE \
20+
-I include -I tools apps/stock_dashboard/stock_dashboard.c \
21+
-lm -o /tmp/stock_dashboard
22+
/tmp/stock_dashboard
23+
file silvercore.ppm
24+
25+
test-vulkan:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- uses: actions/checkout@v4
29+
- name: Install Vulkan SDK
30+
run: |
31+
sudo apt-get update -qq
32+
sudo apt-get install -y -qq libvulkan-dev mesa-vulkan-drivers
33+
- name: Compile Vulkan backend
34+
run: |
35+
clang -I include -I tools -DSC_GFX_IMPLEMENTATION \
36+
-DSC_GFX_BACKEND_VULKAN -DSC_BACKEND_VULKAN_IMPLEMENTATION \
37+
-DSC_LAYOUT_IMPLEMENTATION -DSC_WIDGET_IMPLEMENTATION \
38+
-DSC_RUNTIME_IMPLEMENTATION -DSC_FONT_IMPLEMENTATION \
39+
-c backends/sc_backend_vulkan.h -o /dev/null -x c \
40+
-Wall -Wextra -Wpedantic -Wshadow
41+
- name: Build and run Vulkan headless test
42+
run: |
43+
clang -I include -I tools -DSC_GFX_IMPLEMENTATION \
44+
-DSC_GFX_BACKEND_VULKAN -DSC_BACKEND_VULKAN_IMPLEMENTATION \
45+
-DSC_LAYOUT_IMPLEMENTATION -DSC_WIDGET_IMPLEMENTATION \
46+
-DSC_RUNTIME_IMPLEMENTATION -DSC_FONT_IMPLEMENTATION \
47+
-Wall -Wextra -Wpedantic -Wshadow \
48+
tests/test_gfx.c -lm -lvulkan -o /tmp/test_vk
49+
/tmp/test_vk
50+
51+
wasm:
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v4
55+
- uses: mymindstorm/setup-emsdk@v14
56+
with:
57+
version: 3.1.64
58+
- name: Build WASM target
59+
run: |
60+
emcmake cmake -S . -B build-wasm -DWASM=ON -DSC_TESTS=OFF
61+
cmake --build build-wasm -j$(nproc)
62+
- name: Verify WASM output
63+
run: |
64+
ls -lh build-wasm/*.wasm build-wasm/*.js

backends/sc_backend_vulkan.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,38 @@ SCGfxTexture sc_vulkan_make_texture(SCGfxContext *ctx, const SCGfxTextureDesc *d
12441244
return h;
12451245
}
12461246

1247+
SCResult sc_vulkan_resize(SCGfxContext *ctx, u32 width, u32 height) {
1248+
if (!ctx || !ctx->backend_data || width == 0 || height == 0)
1249+
return SC_ERR_INVALID_ARG;
1250+
_SCVkState *s = (_SCVkState*)ctx->backend_data;
1251+
1252+
vkDeviceWaitIdle(s->device);
1253+
s->width = width;
1254+
s->height = height;
1255+
ctx->width = width;
1256+
ctx->height = height;
1257+
1258+
if (s->headless) {
1259+
/* Destroy old offscreen resources */
1260+
if (s->os_fbo) vkDestroyFramebuffer(s->device, s->os_fbo, NULL);
1261+
if (s->os_view) vkDestroyImageView(s->device, s->os_view, NULL);
1262+
if (s->os_image) vkDestroyImage(s->device, s->os_image, NULL);
1263+
if (s->os_mem) vkFreeMemory(s->device, s->os_mem, NULL);
1264+
s->os_fbo = s->os_view = VK_NULL_HANDLE;
1265+
s->os_image = VK_NULL_HANDLE;
1266+
s->os_mem = VK_NULL_HANDLE;
1267+
1268+
VkResult r = _sc_vk_create_offscreen(s->device, s->phy_dev, s->gfx_queue,
1269+
s->width, s->height, s->swap_fmt, s->render_pass,
1270+
&s->os_image, &s->os_mem, &s->os_view, &s->os_fbo);
1271+
return (r == VK_SUCCESS) ? SC_OK : SC_ERR_GFX;
1272+
}
1273+
1274+
/* Windowed: recreate swapchain */
1275+
VkResult r = _sc_vk_recreate_swapchain(s);
1276+
return (r == VK_SUCCESS) ? SC_OK : SC_ERR_GFX;
1277+
}
1278+
12471279
void sc_vulkan_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex) {
12481280
if (!ctx || !ctx->backend_data || tex.id == 0 || tex.id >= SC_GFX_MAX_TEXTURES)
12491281
return;

include/sc_gfx.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ SCGfxFrameStats sc_gfx_frame_stats (const SCGfxContext *ctx);
256256
/* Enable or disable software framebuffer rasterization (default: on) */
257257
void sc_gfx_set_rasterize(SCGfxContext *ctx, bool enable);
258258

259+
/* Resize the framebuffer / swapchain (handle window resize) */
260+
SCResult sc_gfx_resize(SCGfxContext *ctx, u32 width, u32 height);
261+
259262
/* Built-in 2-D helpers (sprite / rect / text batch) */
260263
void sc_gfx_draw_rect (SCGfxContext *ctx, SCRect2f rect, SCColor color);
261264
void sc_gfx_draw_sprite(SCGfxContext *ctx, SCRect2f dest, SCGfxTexture tex, SCColor tint);
@@ -303,6 +306,7 @@ void sc_vulkan_end_frame (SCGfxContext *ctx);
303306
SCGfxTexture sc_vulkan_make_texture (SCGfxContext *ctx,
304307
const SCGfxTextureDesc *desc);
305308
void sc_vulkan_destroy_texture(SCGfxContext *ctx, SCGfxTexture tex);
309+
SCResult sc_vulkan_resize (SCGfxContext *ctx, u32 width, u32 height);
306310
#endif
307311

308312
/* ---- Internal context ------------------------------------------------- */
@@ -686,6 +690,24 @@ void sc_gfx_set_rasterize(SCGfxContext *ctx, bool enable) {
686690
if (ctx) ctx->rasterize = enable;
687691
}
688692

693+
SCResult sc_gfx_resize(SCGfxContext *ctx, u32 width, u32 height) {
694+
if (!ctx || width == 0 || height == 0) return SC_ERR_INVALID_ARG;
695+
#ifdef SC_GFX_BACKEND_VULKAN
696+
if (ctx->backend == SC_BACKEND_VULKAN) {
697+
return sc_vulkan_resize(ctx, width, height);
698+
}
699+
#endif
700+
if (ctx->backend == SC_BACKEND_SOFTWARE) {
701+
u8 *fb = (u8*)realloc(ctx->framebuffer, (usize)width * height * 4);
702+
if (!fb) return SC_ERR_OOM;
703+
ctx->framebuffer = fb;
704+
ctx->width = width;
705+
ctx->height = height;
706+
return SC_OK;
707+
}
708+
return SC_ERR_NOT_SUPPORTED;
709+
}
710+
689711
/* ---- 2-D batch helpers ------------------------------------------------ */
690712
static void _sc_gfx_push_quad(SCGfxContext *ctx, SCGfxTexture tex,
691713
f32 x0, f32 y0, f32 x1, f32 y1,

tools/wasm/CMakeLists.wasm.cmake

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(WASM_LINK_FLAGS
3939
"'_sc_gfx_shutdown',"
4040
"'_sc_gfx_begin_frame',"
4141
"'_sc_gfx_end_frame',"
42+
"'_sc_gfx_resize',"
4243
"'_sc_gfx_draw_rect',"
4344
"'_sc_gfx_draw_line',"
4445
"'_sc_gfx_draw_sprite',"
@@ -76,7 +77,7 @@ string(JOIN " " WASM_LINK_FLAGS_STR ${WASM_LINK_FLAGS})
7677
# WASM target
7778
# ---------------------------------------------------------------------------
7879
add_executable(silvercore_wasm
79-
${CMAKE_SOURCE_DIR}/src/sc_kernel.c # implementation TU
80+
${CMAKE_BINARY_DIR}/sc_kernel.c # auto-generated unity build TU
8081
${CMAKE_SOURCE_DIR}/apps/stock_dashboard/stock_dashboard.c
8182
)
8283

@@ -85,19 +86,21 @@ target_compile_definitions(silvercore_wasm PRIVATE
8586
SC_LAYOUT_IMPLEMENTATION
8687
SC_WIDGET_IMPLEMENTATION
8788
SC_RUNTIME_IMPLEMENTATION
89+
SC_FONT_IMPLEMENTATION
8890
SC_GFX_BACKEND_SOFTWARE # WebGPU path TBD
8991
SC_PLATFORM_WASM
9092
)
9193

9294
target_include_directories(silvercore_wasm PRIVATE
9395
${CMAKE_SOURCE_DIR}/include
96+
${CMAKE_SOURCE_DIR}/tools
9497
)
9598

9699
set_target_properties(silvercore_wasm PROPERTIES
97100
OUTPUT_NAME "silvercore"
98101
SUFFIX ".js"
99-
LINK_FLAGS "${WASM_LINK_FLAGS_STR}"
100102
)
103+
target_link_options(silvercore_wasm PRIVATE ${WASM_LINK_FLAGS})
101104

102105
target_compile_options(silvercore_wasm PRIVATE
103106
-O3

tools/wasm/silvercore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class SilverCoreApp {
7777
gfx_shutdown: m.cwrap("sc_gfx_shutdown", null, ["number"]),
7878
gfx_begin_frame: m.cwrap("sc_gfx_begin_frame", null, ["number","number","number","number","number"]),
7979
gfx_end_frame: m.cwrap("sc_gfx_end_frame", null, ["number"]),
80+
gfx_resize: m.cwrap("sc_gfx_resize", "number", ["number","number","number"]),
8081
gfx_draw_rect: m.cwrap("sc_gfx_draw_rect", null, ["number","number","number","number","number","number","number","number","number"]),
8182
gfx_draw_line: m.cwrap("sc_gfx_draw_line", null, ["number","number","number","number","number","number","number","number","number"]),
8283
scene_init: m.cwrap("sc_scene_init", null, ["number","number","number","number"]),

0 commit comments

Comments
 (0)