Skip to content

[HIGH] Simplify RHI composite - Split into focused subsystem interfaces #272

@MichaelFisher1997

Description

@MichaelFisher1997

Problem

The RHI struct in src/engine/graphics/rhi.zig (754 lines) is a composite God Object that combines 8+ interface vtables into a single struct:

  • IResourceFactory (buffer/texture/shader creation)
  • IRenderContext (frame/render pass management)
  • IShadowContext (shadow mapping)
  • IUIContext (2D/UI rendering)
  • IGraphicsCommandEncoder (draw commands)
  • IRenderStateContext (uniforms/state)
  • ISSAOContext (SSAO computation)
  • IDeviceQuery/IDeviceTiming (device queries)

This violates SRP and makes the code difficult to maintain and test.

Current State

RHI struct acts as a monolithic facade over many concerns.

Proposed Solution

Keep the segregated interfaces (which are well-designed!) but refactor how they're composed:

  1. Option A: Keep separate interface instances instead of one composite
  2. Option B: Create focused subsystem wrappers:
    • ResourceManager - owns IResourceFactory
    • RenderContext - owns IRenderContext + IGraphicsCommandEncoder
    • ShadowSystem - owns IShadowContext
    • UIRenderer - owns IUIContext

Benefits

  • Clients depend only on interfaces they actually use
  • Easier to mock for unit testing
  • Clearer dependencies between subsystems
  • Reduced cognitive load per module

Acceptance Criteria

  • Split RHI composite into focused subsystems
  • Update all callers to use appropriate subsystem
  • No change to underlying Vulkan implementation
  • All tests pass
  • Document the new architecture

Related Files

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

SOLID Principles

  • Single Responsibility Principle (SRP)
  • Interface Segregation Principle (ISP)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions