SBgl 0.1.0
A graphics framework in C99
Loading...
Searching...
No Matches
Changelog

All notable changes to this project will be documented in this file.

[Unreleased] - 2026-05-14

Added

  • sbgl_context_internal.h: New internal header exposing sbgl_GetContextArena() to allow subsystems (e.g., voxel engine) to allocate from the context's persistent arena instead of malloc.
  • Blend State Pipeline Configuration: Added sbgl_BlendMode enum (NONE, ALPHA, ADDITIVE) to sbgl_PipelineConfig. The Vulkan backend now dynamically configures VkPipelineColorBlendAttachmentState based on the selected mode instead of hardcoding blendEnable = VK_FALSE.
  • Instance Count Parameter: Extended sbgl_Draw and sbgl_DrawIndexed to accept an explicit instanceCount parameter, enabling direct instancing without requiring Multi-Draw Indirect.
  • SBGL_VOXEL_CHUNK_SIZE Constant: Replaced the magic number 256.0f and the local CHUNK_SIZE_F variable with a module-level #define in sbgl_voxel.c for maintainability.

Changed

  • Renamed sbgl_Clear to sbgl_SetClearColor: The function name now accurately reflects its behavior (it stores the clear color for the next frame, not the current one). A backward-compatible #define sbgl_Clear sbgl_SetClearColor alias is provided, so existing code compiles without modification.
  • Voxel System Memory Model: sbgl_Voxel_Create and sbgl_Voxel_Destroy now use the context's persistent arena instead of malloc/free, aligning the voxel subsystem with the library's Data-Oriented Design memory model.
  • Voxel AABB Synchronization: Replaced the dual-GPU-buffer mapping strategy with a CPU-side sbgl_AABB mirror (cpuAABB). This eliminates a read-write hazard where the GPU could consume the previous frame's AABB data while the CPU was writing new AABBs.
  • Shader Fallback Path Buffer: Increased the sbgl_LoadShaderFromFile fallback buffer from 256 to 1024 bytes to prevent silent path truncation with deeply nested directory structures.

Fixed

  • Push Constant Size Truncation: Added a runtime guard in sbgl_gfx_PushConstants that rejects sizes exceeding SBGL_VK_PUSH_CONSTANT_SIZE (128 bytes) before the size_t to uint32_t cast, preventing silent truncation on 64-bit builds.
  • Managed Heap Silent Failures: managed_heap_free now emits a stderr warning when the requested offset is not found in any tracked range, aiding detection of double-free or memory corruption.
  • sbl_arena.h Double-Inclusion: Added SBL_ARENA_IMPLEMENTATION_GUARD to prevent the implementation section from being compiled twice when the header is included multiple times with SBL_ARENA_IMPLEMENTATION defined.
  • Removed Dead Code: Removed the four (void) casts suppressing unused-function warnings for static_heap_alloc, dynamic_heap_alloc, managed_heap_alloc, and managed_heap_free in sbgl_backend_vulkan.c, as these functions are actively used by sbgl_gfx_CreateBuffer.

[Unreleased] - 2026-05-12

Changed

  • Memory Expansion: Increased SBGL_MANAGED_HEAP_SIZE from 256MB to 512MB to support high-density 3D voxel environments without buffer overflow.
  • Enhanced Synchronization: Introduced SBGL_BARRIER_HOST_TO_GRAPHICS to the public API and Vulkan backend to ensure host-mapped metadata (like chunk AABBs) is visible to the graphics pipeline.

Fixed

  • Voxel Terrain Randomization: Resolved a critical bug in voxel3D_main where terrain would appear to regenerate or warp during movement.
    • Fixed world-space coordinate scaling in voxel_gen.comp to ensure noise sampling is consistent across chunk boundaries.
    • Corrected the shellPipe compute dispatch dimensions in sbgl_voxel.c to properly iterate over the entire 64x64 voxel column grid.
    • Fixed heuristic material selection in voxel_mesh.comp by utilizing correctly scaled global heights.
  • Voxel Race Conditions: Implemented missing memory barriers in sbgl_Voxel_Update to synchronize GPU-side chunk deactivation with the subsequent culling and rendering passes.
  • Voxel3D Example Optimization: Reduced default max_slots to 256 to improve performance and stability during rapid camera movement.

[Unreleased] - 2026-05-11

Added

  • Hybrid GPU Memory Manager: Implemented a specialized sub-allocation system in the Vulkan backend to eliminate the overhead of individual vkAllocateMemory calls.
    • Static Heap (128MB): Linear arena for permanent resources (vertex/index buffers).
    • Dynamic Heap (128MB): Double-buffered ring buffer for transient per-frame data (storage/uniform buffers).
    • Managed Heap (256MB): Variable-size sub-allocator using a first-fit split/merge strategy for semi-permanent resources (voxel chunks).
  • GPU Memory Unit Tests: Added tests/gpu_memory_test.c to verify the robustness of the managed heap's splitting and coalescing logic.

Changed

  • DOD Resource Tracking (SoA): Transitioned internal resource management from an Array of Structs (AoS) to a Structure of Arrays (SoA).
    • Introduced a contiguous bufferActive array for O(1) cache-efficient resource status checks.
    • Optimized sbgl_gfx_CreateBuffer to perform linear metadata scans, fitting hundreds of checks into a single cache line.
  • Improved Buffer Alignment: Enforced a 256-byte minimum alignment for all sub-allocations to ensure compatibility with minUniformBufferOffsetAlignment across diverse GPU hardware.
  • Enhanced Documentation: Updated docs/manual/memory_management.md and docs/manual/vulkan_backend.md with detailed architectural deep-dives into the new hybrid memory model.

[Unreleased] - 2026-05-10

Added

  • Compute API Support: Implemented a general-purpose compute pipeline system in the Vulkan backend.
    • Added sbgl_CreateComputePipeline, sbgl_DispatchCompute, and sbgl_MemoryBarrier to the public API.
    • Support for SBGL_SHADER_STAGE_COMPUTE in the shader loading system.
    • Memory barriers for synchronizing Compute-to-Graphics and Graphics-to-Compute transitions.
  • Advanced 3D Voxel Engine:
    • High-performance voxel rendering using 3D chunked SSBOs.
    • GPU-Driven Frustum Culling: Implemented via compute shaders to eliminate CPU-side visibility bottlenecks.
    • Multi-Draw Indirect (MDI): Utilizes GPU-populated indirect commands for single-call submission of millions of voxels.
    • New example: examples/voxels/voxel3D_main.c.
  • Compute Documentation: Created docs/COMPUTE.md with technical deep-dives into GPU culling and pipeline synchronization.

Changed

  • Vulkan Meta-loader Integration: Replaced manual Vulkan loading logic with volk (v1.4.350) using CMake FetchContent. This enables device-level function dispatching via VolkDeviceTable, reducing driver overhead for draw calls.
  • Enhanced Test Validation: Refactored the internal test suite (math_test, arena_test, voxel_logic_test, etc.) to replace passive variable usage with explicit runtime validation, ensuring robust testing and resolving compiler warnings in Debug builds.

Fixed

  • Standalone Build Integrity: Resolved linking issues in SBGL_BUILD_STANDALONE mode where volk and platform-specific definitions were not correctly propagated to examples and tests.
  • Compiler Warning Cleanup: Eliminated "unused variable" and "unused function" warnings across the project to maintain a clean -Werror build in both Debug and Release configurations.

[Unreleased] - 2026-05-09

Added

  • Transient GPU Buffer System: Implemented a persistent, per-frame transient buffer pool in the Vulkan backend (16MB per frame in flight). This eliminates per-frame Vulkan buffer allocations, memory mappings, and deallocations for dynamic data like instances and indirect commands.
  • GPU Transient Allocator: Added sbgl_gfx_AllocateTransient to the internal HAL to enable low-overhead, linear sub-allocation from the persistent transient buffers.

Changed

  • Default Build Type: Changed the default CMake build configuration from Debug to Release to prioritize performance.
  • Optimized Radix Sort: Refactored sbgl_radix_sort to use 8-bit passes (256 buckets) instead of 16-bit passes (65,536 buckets). This significantly reduces CPU cache misses and stack zeroing overhead.
  • Allocation-Free Hot Path: Updated sbgl_radix_sort to accept external workspace buffers, eliminating per-frame malloc/free calls in the core batching system.
  • Render Queue Refactor: Updated sbgl_RenderQueuesEx to use the transient GPU allocator and optimized sorter, resolving the CPU bottleneck in the voxel example.
  • Updated HAL Signatures: Modified sbgl_gfx_DrawIndirect to accept a byte offset, supporting multi-draw indirect commands within shared transient buffers.

Fixed

  • Release Mode Segfault: Resolved a critical segmentation fault occurring in Release builds by increasing the default SblArena alignment to 16 bytes. This ensures compatibility with SIMD-optimized instructions generated by the compiler for aligned data types like sbgl_Mat4.
  • Arena Block Alignment: Fixed a bug in sbl_arena_alloc where the first allocation in a new memory block could be misaligned if the block header size was not a multiple of the alignment.
  • Batching Garbage Rendering: Resolved visual artifacts ("exploding" triangles) in the batching and triangle examples by correctly setting the vertex position w component to 1.0.
  • Voxel Example Performance: Resolved the primary CPU bottleneck in voxel_main, reducing CPU frame time from ~11ms to <2ms for standard render distances.

[Unreleased] - 2026-05-08

Added

  • Bit-Field Optimization: Reduced sbgl_DrawPacket from 24 bytes to 16 bytes by packing MeshID, MaterialID, and rendering flags into a 32-bit header. This increases CPU cache density by 50% during sorting and batching.
  • Packed Vertex Format: Transitioned sbgl_Vertex to a 16-byte cache-aligned structure using int16_t[4] for positions (SNORM) and uint32_t for packed RGBA8 colors, reducing GPU vertex bandwidth by over 50%.
  • Transient Arena Management: Introduced a frame-local transientArena in the engine context to handle merge-and-sort operations, eliminating heap allocations in the hot path.
  • Extended Submission API: Updated sbgl_SubmitDraw to expose bit-packed rendering flags (blendMode, sidedness, tags) directly to the public API.
  • Real-time Telemetry: Implemented a high-precision profiling system using Vulkan Timestamp Queries and platform timers to measure independent CPU and GPU execution times.
  • New Verification Test: Added packet_packing_test.c to ensure structural alignment and bit-packing logic integrity.

Fixed

  • Submission API Mismatches: Corrected all demonstration examples and documentation to align with the updated sbgl_SubmitDraw signature.
  • Standalone Build Integrity: Fixed tests/CMakeLists.txt to correctly handle engine test compilation when SBGL_BUILD_STANDALONE is enabled.
  • Internal State Verification: Refactored core_flags_test.c to comply with strict compiler warnings and verified internal state machine transitions.

[Unreleased] - 2026-05-04

Added

  • Vulkan Backend:
    • Implemented dynamic swapchain format selection via vkGetPhysicalDeviceSurfaceFormatsKHR to resolve hardcoded format validation errors.
    • Added support for VK_FORMAT_B8G8R8A8_SRGB and VK_FORMAT_R8G8B8A8_SRGB as preferred swapchain formats.
  • Rendering Pipeline:
    • Implemented a rendering pipeline using Vulkan 1.3 Dynamic Rendering, eliminating RenderPass and Framebuffer management.
    • Resource Management: Introduced a handle-based system (sbgl_Buffer, sbgl_Shader, sbgl_Pipeline) for GPU resources using internal SoA pools for DOD-compliant performance.
    • Shader System: Added SPIR-V shader loading with support for both dynamic file-based loading and hardcoded byte arrays (via xxd).
    • Explicit PSO: Implemented Pipeline State Object (PSO) creation with configurable vertex layouts and shader stages.
    • Interactive Rendering: Added Push Constants support to the public API and Vulkan backend, enabling per-frame data updates (e.g., mouse position).
    • Depth Buffering: Implemented a dedicated depth attachment and enabled depth testing in the graphics pipeline to correct 3D geometry sorting.
    • Synchronization Refactor: Transitioned to a "Frames in Flight" model (2 overlapping frames) to resolve semaphore reuse validation errors and improve GPU utilization.
    • Device Teardown: Introduced sbgl_DeviceWaitIdle() to the public API to ensure the GPU is idle before destroying resources.
    • New Examples:
    • Documentation: Created docs/manual/rendering_pipeline.md covering the architecture and usage workflows.
    • Examples Restructure: Reorganized examples/ directory into topic-based subdirectories (window, input, camera, triangle, batching) and added docs/examples/index.md to catalog them.

Fixed

  • Vulkan Backend:
    • Resolved vkDestroyPipeline and vkDestroyBuffer validation errors (VUID-vkDestroyPipeline-pipeline-00765, VUID-vkDestroyBuffer-buffer-00922) in examples by adding explicit sbgl_DeviceWaitIdle() calls before resource destruction.
    • Enhanced API documentation in sbgl.h and docs/manual/vulkan_backend.md with critical warnings regarding GPU synchronization and teardown sequences.
    • Resolved vkCreateSwapchainKHR crashes (floating point exception) caused by zero-extent windows (minimized or unmapped) and unsupported image formats.
    • Improved swapchain image count selection logic to respect physical device limits.
    • Fixed validation errors related to imageFormat and imageColorSpace mismatches.
  • Build System:
    • Test Relocation: Decoupled test applications from the examples/ directory. Tests are now located in a top-level tests/ directory.
    • New Build Flag: Introduced SBGL_BUILD_TESTS CMake option to toggle the compilation of internal tests independently of examples.
    • Examples: Refined SBGL_BUILD_EXAMPLES to strictly target demonstration applications.
    • Implemented a default Debug build configuration to ensure development environments have Vulkan validation layers and strict warnings enabled by default.
    • Added strict compiler flags (-Werror, -Wmissing-prototypes, -Wstrict-prototypes on GCC/Clang; /WX on MSVC) specifically for Debug builds to enforce coding standards.
    • Updated all example and test entry points to use int main(void) and ensured all internal functions use explicit (void) parameter lists to satisfy strict prototype requirements.
    • Fixed an issue where .spv shader files were deleted by the CMake build system after header conversion, preventing examples from loading them at runtime.
    • Improved shader conversion using copy_if_different.
    • Resolved unused variable warnings in test files to maintain a clean -Werror build.
  • Documentation System Refinement:
    • Decoupled documentation generation from the source tree by relocating Doxygen output from docs/out to build/docs.
    • Updated CMakeLists.txt to dynamically configure Doxygen output paths, ensuring a cleaner root directory.
    • Image asset synchronization within the build-local documentation site.
  • Structural Cleanup:
    • Moved the shaders/ directory into examples/shaders/ to reduce root directory clutter and better reflect its purpose as example-only assets.
    • Optimized the shader build pipeline to ensure generated assets stay within the build environment.
  • SIMD-Ready Math Library:
    • Implemented a single-header math library (sbgl_math.h) providing Vector (Vec2, Vec3, Vec4), Matrix (Mat4), and Quaternion types.
    • Optimized memory layouts with 16-byte alignment and padding to facilitate efficient SIMD instruction generation and cache line utilization.
    • Implemented an Inverse Square Root (sbgl_InvSqrt) based on the Quake III Arena algorithm using C99-compliant union punning.
    • Provided a set of affine transformations: Translation, Scaling, Rotation (Axis-Angle), Perspective, Orthographic, and LookAt.
    • Added constructor functions (e.g., sbgl_vec3()) for natural initialization syntax.
    • Integrated the math library into the Doxygen documentation system with automatic symbol linking.
    • Created a technical architecture guide (docs/MATH_LIB.md) with usage examples and implementation rationales.

Changed

  • Data-Oriented Input API:
    • Transitioned the input system to a Data-Oriented Design (DOD) model to improve cache utilization and enable batch processing.
    • Removed single-instance query functions: sbgl_IsKeyDown, sbgl_IsKeyPressed, sbgl_IsMouseButtonDown, sbgl_GetMousePos, and sbgl_GetMouseDelta.
    • Introduced sbgl_GetInputState, providing a read-only pointer to the contiguous sbgl_InputState structure for direct array access.
    • Implemented a static, zero-initialized dummy state to handle null-context edge cases without internal branching.

[Unreleased] - 2026-05-02

Added

  • Window Resizing:
    • Implemented automatic swapchain recreation on window resize events across Wayland, X11, and Win32.
    • Added sbgl_GetWindowSize to the public API for context-based dimension queries.
    • Integrated synchronization to handle window minimization (0x0 dimensions).
  • Input System Refactor:
    • Encapsulated all physical input state into a sbgl_InputState structure tied directly to the sbgl_Context.
    • Eliminated global input state in favor of context-local state, enabling zero-overhead real-time input access via "key map" arrays.
    • Added keysPressed tracking for frame-accurate trigger detection.
  • Arena-Based Memory Management:
    • Fully eliminated malloc and free from the platform and Vulkan layers.
    • Implemented a Mark/Rewind pattern for the Vulkan backend to recycle arena memory during swapchain recreation without leaks.

Changed

  • Core Architecture:
    • Updated internal HAL signatures to pass the engine context or specialized state pointers instead of relying on globals.
    • Updated sbgl_gfx_Init to accept the context's SblArena for graphics-layer allocations.
  • Public API:
    • Updated input helpers (sbgl_IsKeyDown, etc.) to perform validation checks and read directly from the context's internal state.

Added

  • Core Architecture: Implemented a modular HAL (Hardware Abstraction Layer) separating Core, Platform, and Graphics Backend.
  • Build System:
    • Created a CMakeLists.txt with automatic backend detection and protocol generation.
    • Added SBGL_BUILD_EXAMPLES option (defaults to OFF for a minimal core build).
    • Added SBGL_BUILD_STANDALONE option for compiling library sources directly into executables (Unity-style build).
    • Enabled CMAKE_EXPORT_COMPILE_COMMANDS for LSP context support.
    • Added docs-clean target to manage documentation artifacts.
  • Platform HAL: Defined sbgl_platform.h for OS-agnostic windowing, timing, and native integration.
  • Multi-Platform Support:
    • Fully implemented the Win32 Platform Layer (window.c, input.c) with virtual key mapping.
    • Fully implemented the X11 Platform Layer (window_x11.c, input_x11.c).
    • Implemented a native Wayland Platform Layer using XDG-Shell protocols (window_wayland.c, input_wayland.c).
    • Reorganized Linux implementations into a modular, decoupled structure using a shared linux_internal.h.
    • Added build-time switching between backends via the SBGL_USE_WAYLAND CMake option.
  • Vulkan Backend:
    • Implemented Dynamic Vulkan Loading: The engine now loads libvulkan.so or vulkan-1.dll at runtime, eliminating build-time link dependencies.
    • Vulkan 1.3 Instance and Surface creation for Wayland, X11, and Win32.
    • Automatic Physical Device selection (preferring discrete GPUs).
    • Logical Device creation with Dynamic Rendering enabled.
    • Swapchain management with image view generation.
    • Clear Screen: Implemented BeginFrame and EndFrame to clear the screen to a color using dynamic rendering.
  • Public API: Defined sbgl.h with an explicit Context management and physical scancode definitions.
  • Memory Management: Integrated sbl_arena.h for zero-isolated-malloc window state allocation.
  • Opaque Types: Created sbgl_types.h to centralize forward declarations and resolve C99 typedef redefinition warnings.
  • Input Refinement:
    • Decoupled the input system into a dedicated HAL (sbgl_input.h) and platform-specific implementations.
    • Replaced raw memcpy for keyboard states with Struct Assignment.
    • Added support for one-shot key triggers (sbgl_IsKeyPressed).
    • Implemented native pointer support (position, delta, buttons) for Wayland, X11, and Win32.
  • Git Integration: Initialized git repository and added a .gitignore.
  • Documentation:
    • Integrated Doxygen for API documentation generation.
    • Added a docs target to CMake (cmake --build build --target docs).
    • Added docs/manual/vulkan_backend.md with a detailed explanation of the engine's graphics architecture.
  • Examples: Added hello_window.c and input_test.c (interactive color switching) to verify the entire stack.

Fixed

  • Compiler Warnings:
    • Silenced ISO C99 pedantic warnings regarding anonymous structs in sbgl_math.h using the __extension__ keyword.
    • Eliminated unused parameter warnings in Wayland platform callbacks by implementing explicit (void) casts, ensuring a clean build with -Wall -Wextra -Wpedantic.
  • Memory: Resolved a segmentation fault in sbl_arena_free caused by a Use-After-Free when the arena structure was self-contained within its own memory blocks.
  • GPU Synchronization: Fixed a Vulkan driver crash during rapid window resizing by implementing internal frame lifecycle tracking (isDrawing flag), preventing out-of-order command submissions.
  • Wayland Protocol Crashes: Resolved "listener function is NULL" errors by providing callback implementations for wl_keyboard and wl_pointer.
  • Wayland Window Visibility: Resolved the issue where windows remained invisible until a valid Vulkan buffer was attached and submitted.
  • Wayland ANR: Fixed "Application Not Responding" dialogs by restoring the XDG-Shell ping/pong heartbeat.
  • GPU Synchronization: Fixed a potential hang in the frame lifecycle by adopting an explicit BeginDrawing/EndDrawing pattern.
  • C99 Compatibility: Fixed header redefinition errors by refactoring forward declarations into a dedicated types header.