Skip to content

[Medium] Decouple RHI (God Object) into Subsystems #190

Description

@MichaelFisher1997

Problem

The RHI struct in src/engine/graphics/rhi.zig violates the Single Responsibility Principle (SRP). It acts as a monolithic facade ("God Object") that handles widely divergent responsibilities:

  • Resource Management (Buffers, Textures, Shaders)
  • Command Recording & Submission
  • UI Rendering
  • Device Queries & Synchronization
  • Presentation & VSync

This centralization makes the graphics subsystem rigid and difficult to unit test or refactor.

Impacted Files

  • src/engine/graphics/rhi.zig
  • src/engine/graphics/rhi_vulkan.zig

Action Plan

  1. Define Subsystems:
    • ResourceManager: Dedicated to createBuffer, createTexture, destroy*.
    • RenderCommandQueue: Handles beginFrame, endFrame, and submission logic.
    • SwapchainPresenter: Handles surface, vsync, and presentation.
  2. Refactor RHI: Change RHI to be a container that holds references to these subsystems, rather than implementing the methods directly via a giant VTable.
  3. Update Implementation: Split VulkanContext to align with these new boundaries.

Acceptance Criteria

  • RHI struct is significantly smaller or acts only as a composition root.
  • Resource creation and command submission are distinct logical paths.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions