Skip to content

Feature/add depth texture#10

Merged
kimkulling merged 5 commits into
mainfrom
feature/add_depth_texture
May 21, 2026
Merged

Feature/add depth texture#10
kimkulling merged 5 commits into
mainfrom
feature/add_depth_texture

Conversation

@kimkulling

@kimkulling kimkulling commented May 21, 2026

Copy link
Copy Markdown
Owner
  • Introduce depth texture
  • Introduce doc

Summary by CodeRabbit

  • New Features

    • Added depth rendering support for improved 3D graphics rendering.
    • Updated renderer to handle 3D vertex positions.
  • Bug Fixes

    • Improved error handling during renderer initialization with proper status reporting.
  • Documentation

    • Enhanced API documentation for application lifecycle and renderer classes.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown

Walkthrough

This PR upgrades the Vulkan renderer with 3D vertex position support and depth rendering. Vertex input moves from 2D to 3D; the renderer gains depth image resources, depth format selection, and depth attachment integration into render passes and pipelines. Initialization is wired to create depth resources and command buffers. RHI initialization errors are now propagated to the application. Documentation and code cleanup round out the changes.

Changes

Depth Rendering and 3D Vertex Support

Layer / File(s) Summary
Vertex Position Update to 3D
assets/shaders/default.vert, src/runtime/renderer/RHIVulkan.cpp
Vertex shader input inPosition changes from vec2 to vec3; Vertex::pos struct member changes to glm::vec3; Vulkan vertex attribute format updates to 3-component float; vertex data is updated with 3D coordinates; createImageView() signature is generalized to accept VkImageAspectFlags; all call sites pass the appropriate aspect mask.
Depth Rendering Implementation
src/runtime/renderer/RHIVulkan.cpp
Depth image resources (depthImage, depthImageMemory, depthImageView) are added; helper functions findSupportedFormat() and findDepthFormat() select depth formats; render pass includes depth attachment and subpass dependencies; graphics pipeline adds depth/stencil state with testing and writing; framebuffers bind both color and depth views; command buffer recording clears both color and depth; image layout transitions handle depth-stencil aspect masks and UNDEFINED→DEPTH_STENCIL paths; createDepthResources() manages depth image lifecycle.
RHI Initialization and Error Handling
src/runtime/application/app.cpp, src/runtime/renderer/RHIVulkan.cpp
App::init() captures RHI::init() return value, logs errors on failure, and returns the status; RHIImpl method signatures declare createDepthResources() and rename to createCommandBuffers(); RHI::init() wiring calls createDepthResources(), createFramebuffers(), and createCommandBuffers() in sequence.
Documentation and Code Cleanup
src/runtime/application/app.h, src/runtime/renderer/RHI.h, src/runtime/renderer/rendercore.h, src/runtime/renderer/RHIVulkan.cpp
App and RHI classes gain expanded Doxygen documentation; RHI::mImpl is initialized to nullptr; RenderGraph::~RenderGraph() is explicitly defaulted; commented-out descriptor set code is removed.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • kimkulling/Segfault#2: Modifies the same vertex shader interface and gl_Position computation for 3D vertex handling, with potential overlap in shader input changes.
  • kimkulling/Segfault#7: Updates vertex input pipeline layout and attribute setup alongside texture coordinate addition, directly overlapping with the vertex position attribute changes in this PR.
  • kimkulling/Segfault#3: Contains related RHI lifecycle management and mImpl pointer initialization patterns that intersect with the RHI initialization error handling and documentation changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Feature/add depth texture' accurately describes the main objective of the changeset, which adds depth rendering support including depth image resources, depth attachment integration, and depth/stencil state to the Vulkan renderer.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/add_depth_texture

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/runtime/renderer/RHIVulkan.cpp (1)

1423-1450: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Remove the unconditional pre-initialized vkCmdPipelineBarrier in transitionImageLayout()
RHIImpl::transitionImageLayout() records a first vkCmdPipelineBarrier() before the depth/stencil aspectMask, the layout-specific srcAccessMask/dstAccessMask, and the computed sourceStage/destinationStage are set—using 0 /* TODO */ stage masks and the initial VK_IMAGE_ASPECT_COLOR_BIT aspectMask. For VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, this causes an extra (and potentially invalid) barrier before the correct second depth barrier is submitted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/renderer/RHIVulkan.cpp` around lines 1423 - 1450, The initial
unconditional vkCmdPipelineBarrier call in RHIImpl::transitionImageLayout() is
executed before aspectMask, src/dst access masks and source/destination stages
are computed, causing an extra/invalid barrier (notably for
VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL);
remove that early vkCmdPipelineBarrier and only call vkCmdPipelineBarrier after
you have set barrier.subresourceRange.aspectMask, barrier.srcAccessMask,
barrier.dstAccessMask and computed sourceStage/destinationStage (i.e., move or
defer the pipeline barrier invocation to after the layout-specific if/else
blocks inside transitionImageLayout()) so only the correctly-configured barrier
is recorded.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/application/app.cpp`:
- Around line 107-113: When RHI::init(appName, mSdlWindow) returns false you
must roll back the partial initialization: delete the allocated mRHI, set mRHI
to nullptr and restore mState out of ModuleState::Init (e.g.
ModuleState::Stopped or ModuleState::Uninitialized) so retries can proceed and
no leak remains; perform this cleanup inside the failure branch that currently
only logs the error before returning ret.

In `@src/runtime/renderer/RHIVulkan.cpp`:
- Around line 206-227: Change findSupportedFormat to a non-throwing function
that returns bool and writes the chosen VkFormat via an out-parameter (e.g.,
bool findSupportedFormat(RHIImpl* rhi, const std::vector<VkFormat>& candidates,
VkImageTiling tiling, VkFormatFeatureFlags features, VkFormat& outFormat));
replace the throw with returning false when no candidate matches. Likewise
change findDepthFormat to return bool and call the new findSupportedFormat,
propagating false on failure and only returning true with the depth format set
on success. Update any callers of findDepthFormat/findSupportedFormat to handle
the bool failure result accordingly.
- Around line 1068-1070: In cleanupSwapChain, the code currently destroys
depthImageView/depthImage/depthImageMemory before destroying
swapChainFramebuffers, which is invalid because createFramebuffers uses
depthImageView as an attachment; change cleanupSwapChain so it first iterates
over and destroys all VkFramebuffer objects in swapChainFramebuffers
(vkDestroyFramebuffer) and clears that container, and only after that call
vkDestroyImageView(device, depthImageView, nullptr), vkDestroyImage(device,
depthImage, nullptr) and vkFreeMemory(device, depthImageMemory, nullptr); ensure
references to swapChainFramebuffers, cleanupSwapChain, createFramebuffers,
depthImageView, depthImage, and depthImageMemory are correctly updated.

---

Outside diff comments:
In `@src/runtime/renderer/RHIVulkan.cpp`:
- Around line 1423-1450: The initial unconditional vkCmdPipelineBarrier call in
RHIImpl::transitionImageLayout() is executed before aspectMask, src/dst access
masks and source/destination stages are computed, causing an extra/invalid
barrier (notably for VK_IMAGE_LAYOUT_UNDEFINED ->
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); remove that early
vkCmdPipelineBarrier and only call vkCmdPipelineBarrier after you have set
barrier.subresourceRange.aspectMask, barrier.srcAccessMask,
barrier.dstAccessMask and computed sourceStage/destinationStage (i.e., move or
defer the pipeline barrier invocation to after the layout-specific if/else
blocks inside transitionImageLayout()) so only the correctly-configured barrier
is recorded.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b320271a-821c-42f5-b961-f487c8671b79

📥 Commits

Reviewing files that changed from the base of the PR and between 0d72e96 and 860efcf.

📒 Files selected for processing (6)
  • assets/shaders/default.vert
  • src/runtime/application/app.cpp
  • src/runtime/application/app.h
  • src/runtime/renderer/RHI.h
  • src/runtime/renderer/RHIVulkan.cpp
  • src/runtime/renderer/rendercore.h

Comment thread src/runtime/application/app.cpp
Comment thread src/runtime/renderer/RHIVulkan.cpp
Comment on lines +1068 to +1070
vkDestroyImageView(device, depthImageView, nullptr);
vkDestroyImage(device, depthImage, nullptr);
vkFreeMemory(device, depthImageMemory, nullptr);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
sed -n '841,863p;1067,1080p' src/runtime/renderer/RHIVulkan.cpp

Repository: kimkulling/Segfault

Length of output: 1709


Vulkan lifetime ordering in cleanupSwapChain
createFramebuffers() builds each VkFramebuffer with depthImageView as an attachment, but cleanupSwapChain() destroys depthImageView/depthImage/depthImageMemory before destroying the swapChainFramebuffers. This breaks Vulkan object-lifetime ordering—destroy the framebuffers first, then tear down the shared depth resources.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/renderer/RHIVulkan.cpp` around lines 1068 - 1070, In
cleanupSwapChain, the code currently destroys
depthImageView/depthImage/depthImageMemory before destroying
swapChainFramebuffers, which is invalid because createFramebuffers uses
depthImageView as an attachment; change cleanupSwapChain so it first iterates
over and destroys all VkFramebuffer objects in swapChainFramebuffers
(vkDestroyFramebuffer) and clears that container, and only after that call
vkDestroyImageView(device, depthImageView, nullptr), vkDestroyImage(device,
depthImage, nullptr) and vkFreeMemory(device, depthImageMemory, nullptr); ensure
references to swapChainFramebuffers, cleanupSwapChain, createFramebuffers,
depthImageView, depthImage, and depthImageMemory are correctly updated.

@kimkulling kimkulling merged commit 7e4d6da into main May 21, 2026
5 checks passed
@kimkulling kimkulling deleted the feature/add_depth_texture branch May 21, 2026 21:53
@kimkulling kimkulling self-assigned this May 21, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jun 9, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jun 16, 2026
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