Skip to content

Add ShaderGen module analysis and incremental refactoring plan#40

Draft
Copilot wants to merge 2 commits intodevel_49_ecsfrom
copilot/review-shadergen-module
Draft

Add ShaderGen module analysis and incremental refactoring plan#40
Copilot wants to merge 2 commits intodevel_49_ecsfrom
copilot/review-shadergen-module

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 3, 2025

Analyzed the ShaderGen module (51 files, ~5,800 LOC) and created a structured refactoring plan addressing architectural debt while maintaining continuous buildability.

Analysis

Core Components Identified:

  • ShaderCreateInfo hierarchy - per-stage shader generation (Vertex/Geometry/Fragment)
  • MaterialCreateInfo - multi-stage coordinator
  • MaterialDescriptorInfo / ShaderDescriptorInfo - resource management with auto set/binding allocation
  • GLSLCompiler - SPIR-V compilation via dynamic plugin
  • StdMaterial hierarchy - 2D/3D material framework

Key Strengths:

  • Automated descriptor binding allocation
  • Material instancing for efficient batching
  • Dynamic shader composition from config

Critical Issues:

  • Mixed responsibilities: ShaderCreateInfo handles both generation and compilation
  • String-concatenation-based code generation scattered across classes
  • No shader caching, no parallel compilation
  • Tight coupling prevents testing in isolation
  • Extension requires invasive changes (e.g., Task/Mesh shaders, HLSL support)

Refactoring Plan

25 incremental steps across 8 phases, each step maintains buildability:

Phase 1 (P1) - Foundation: Test harness, structured error reporting, config extraction
Phase 2 (P1) - Generation: ShaderCodeBuilder abstraction, eliminate direct string ops
Phase 3 (P1) - Descriptors: Clarify MDI/SDI split, fluent API, validation
Phase 4 (P1) - Decoupling: IShaderCompiler interface, builder pattern, dependency injection
Phase 5 (P2) - Extension: Template system, shader cache, material variants
Phase 6 (P2) - Performance: Object pooling, parallel compilation, profiling
Phase 7 (P3) - Tooling: API docs, shader visualizer, material editor
Phase 8 (P3) - Advanced: Mesh/Task shaders, HLSL support, SPIRV-Tools integration

Example transformation:

// Current: direct string concatenation
bool ShaderCreateInfo::ProcUBO() {
    final_shader += "\nlayout(set=...";
}

// Target: structured builder
bool ShaderCreateInfo::ProcUBO(ShaderCodeBuilder& builder) {
    for (auto& ubo : ubo_list)
        builder.addUBO(*ubo);
}

Timeline: 3-4 months single-engineer, 1.5-2 months small team

Document: doc/ShaderGen_Refactoring_Plan.md

Original prompt

分析其中的ShaderGen模块,评价其优缺点。并给出详尽可行的重构计划,可以将重构计划切分成十分细的流程,要求是每重构一步都是可以重新编译运行的。也就是不会出现超大规模的一次性重构。将重构计划生成.md文档放在工程中。


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: hyzboy <1788285+hyzboy@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze ShaderGen module and propose refactoring plan Add ShaderGen module analysis and incremental refactoring plan Dec 3, 2025
Copilot AI requested a review from hyzboy December 3, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants