Skip to content

Commit a21ab81

Browse files
author
amalxloop
committed
Unify backend dispatch, add thread safety, depth testing, and API docs
- Add missing Metal dispatch for begin/end frame, destroy_texture, shader/pipeline lifecycle, and resize in sc_gfx.h - Wire D3D12 and WebGPU stubs into sc_gfx.h dispatch for all 14 backend-routed functions with CMake backend options - Add sc_metal_resize implementation, sc_d3d12_resize/sc_wgpu_resize stubs - Implement depth/stencil pipeline state, depth buffer, depth testing and depth write in software rasterizer - Add sc_gfx_lock/unlock with platform mutex (POSIX/Windows/WASM) and thread_safe option in SCGfxDesc - Add Doxygen API docs on all 19 public functions - Add depth, thread-safety, and resize test cases (26 total) - Update Python bindings for resize, lock, unlock - Add Vulkan pipeline cache with desc hashing - Update sc_kernel.c unity build for D3D12/WGPU backends
1 parent 03e54ea commit a21ab81

9 files changed

Lines changed: 1402 additions & 72 deletions

File tree

CMakeLists.txt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ option(SC_TESTS "Build test suite" ON)
1111
option(SC_SHARED "Build shared library (libsc_kernel.so)" ON)
1212

1313
# Graphics backend selection
14-
set(SC_GFX_BACKEND "SOFTWARE" CACHE STRING "Graphics backend: SOFTWARE, VULKAN")
15-
set_property(CACHE SC_GFX_BACKEND PROPERTY STRINGS SOFTWARE VULKAN)
14+
set(SC_GFX_BACKEND "SOFTWARE" CACHE STRING "Graphics backend: SOFTWARE, VULKAN, METAL, D3D12, WGPU")
15+
set_property(CACHE SC_GFX_BACKEND PROPERTY STRINGS SOFTWARE VULKAN METAL D3D12 WGPU)
1616

1717
# ---------------------------------------------------------------------------
1818
# Global compile settings
@@ -52,6 +52,21 @@ if(SC_GFX_BACKEND STREQUAL "VULKAN")
5252
if(NOT XCB_FOUND AND NOT WAYLAND_FOUND)
5353
message(WARNING "No window system found; windowed Vulkan mode disabled, headless only")
5454
endif()
55+
elseif(SC_GFX_BACKEND STREQUAL "METAL")
56+
set(SC_GFX_BACKEND_DEF "SC_GFX_BACKEND_METAL")
57+
set(SC_GFX_LIBS "")
58+
set(SC_GFX_INCLUDES "")
59+
message(STATUS "Metal backend selected (compile .mm files with -fobjc-arc)")
60+
elseif(SC_GFX_BACKEND STREQUAL "D3D12")
61+
set(SC_GFX_BACKEND_DEF "SC_GFX_BACKEND_D3D12")
62+
set(SC_GFX_LIBS "")
63+
set(SC_GFX_INCLUDES "")
64+
message(STATUS "D3D12 backend selected (stub — link d3d12.lib on Windows)")
65+
elseif(SC_GFX_BACKEND STREQUAL "WGPU")
66+
set(SC_GFX_BACKEND_DEF "SC_GFX_BACKEND_WGPU")
67+
set(SC_GFX_LIBS "")
68+
set(SC_GFX_INCLUDES "")
69+
message(STATUS "WebGPU backend selected (stub — link wgpu-native or Dawn)")
5570
else()
5671
set(SC_GFX_BACKEND_DEF "SC_GFX_BACKEND_SOFTWARE")
5772
set(SC_GFX_LIBS "")

backends/sc_backend_d3d12.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ SCGfxShader sc_d3d12_make_shader (SCGfxContext *ctx, const SCGfxShaderDesc *
3636
void sc_d3d12_destroy_shader(SCGfxContext *ctx, SCGfxShader shd);
3737
SCGfxPipeline sc_d3d12_make_pipeline (SCGfxContext *ctx, const SCGfxPipelineDesc *desc);
3838
void sc_d3d12_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip);
39+
SCResult sc_d3d12_resize (SCGfxContext *ctx, u32 width, u32 height);
3940

4041
#ifdef SC_BACKEND_D3D12_IMPLEMENTATION
4142
#include <stdio.h>
@@ -79,5 +80,9 @@ SCGfxPipeline sc_d3d12_make_pipeline(SCGfxContext *ctx, const SCGfxPipelineDesc
7980
void sc_d3d12_destroy_pipeline(SCGfxContext *ctx, SCGfxPipeline pip) {
8081
SC_UNUSED(ctx); SC_UNUSED(pip);
8182
}
83+
SCResult sc_d3d12_resize(SCGfxContext *ctx, u32 width, u32 height) {
84+
SC_UNUSED(ctx); SC_UNUSED(width); SC_UNUSED(height);
85+
return SC_ERR_NOT_SUPPORTED;
86+
}
8287
#endif /* SC_BACKEND_D3D12_IMPLEMENTATION */
8388
#endif /* SC_BACKEND_D3D12_H */

0 commit comments

Comments
 (0)