Skip to content

[Audit][High] ResourceManager.createShader is stubbed - returns error instead of creating shaders #484

@MichaelFisher1997

Description

@MichaelFisher1997

🔍 Module Scanned

src/engine/graphics/vulkan/ (automated audit scan)

📝 Summary

The ResourceManager.createShader() function is a stub that always returns error.ExtensionNotPresent instead of actually compiling and creating Vulkan shader modules. This means any code path that calls rhi.createShader() will fail, which appears to bypass the actual GLSL→SPIR-V compilation pipeline that should be used for terrain and other shaders.

📍 Location

  • File: src/engine/graphics/vulkan/resource_manager.zig:433-441
  • Function/Scope: createShader

🔴 Severity: High

  • High: Memory leaks, race conditions, incorrect rendering, broken features

💥 Impact

Any code that calls rhi.createShader() or ResourceManager.createShader() will receive an ExtensionNotPresent error. This appears to be dead/stub code, as the actual shader compilation likely happens elsewhere in the pipeline. However, if any production code path relies on this function, shader loading will fail silently. Additionally, the function name ExtensionNotPresent is misleading since shader creation is a core Vulkan feature, not an extension.

🔎 Evidence

pub fn createShader(self: *ResourceManager, vertex_src: [*c]const u8, fragment_src: [*c]const u8) rhi.RhiError!rhi.ShaderHandle {
    _ = self;
    _ = vertex_src;
    _ = fragment_src;
    // TODO: Implement actual shader creation when ready.
    // For now, return error to avoid silent failure.
    // NOTE: If engine code calls this, it will now fail loudly, which is better than silent failure.
    return error.ExtensionNotPresent; // Or proper NotImpl error
}

The function:

  1. Accepts vertex and fragment GLSL source strings but ignores them
  2. Returns a misleading error ExtensionNotPresent instead of a proper error like NotImplemented or ShaderCreationFailed
  3. Has a TODO comment indicating it's incomplete
  4. Has a corresponding destroyShader implementation that does nothing meaningful (_ = self; _ = handle;)

🛠️ Proposed Fix

Either:

  1. Implement full shader creation: Use vkCreateShaderModule with SPIR-V bytecode compiled from GLSL sources via glslangValidator or a Zig-native compiler
  2. Add proper error handling: Change ExtensionNotPresent to NotImplemented or ShaderCreationNotSupported to accurately reflect the state
  3. Wire up destroyShader: The current destroyShader does nothing - if shaders are created elsewhere, this should be wired up to actually destroy them
  4. Document the shader pipeline: If shader creation happens elsewhere (e.g., in a pipeline manager), add a comment explaining where and why

✅ Acceptance Criteria

  • createShader either implements actual shader creation or returns a meaningful error
  • destroyShader properly cleans up shader modules when creation is implemented
  • Error type accurately reflects the failure mode (not ExtensionNotPresent)
  • All callers of createShader handle the error appropriately
  • Shader compilation pipeline is documented if it happens elsewhere

📚 References

  • Vulkan spec: vkCreateShaderModule - core Vulkan feature, not an extension
  • Related: build_options debug flags in rhi_vulkan.zig for shader validation
  • Context: The render pipeline likely depends on external SPIR-V compilation via glslangValidator during build time

Metadata

Metadata

Assignees

No one assigned

    Labels

    automated-auditIssues found by automated opencode audit scansbugSomething isn't workingdocumentationImprovements 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