Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More progress on Vulkan initialization #12

Merged
merged 6 commits into from
Jan 13, 2025
Merged

Conversation

btipling
Copy link
Owner

@btipling btipling commented Jan 13, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced Vulkan descriptor management with new allocator and manager structures.
    • Added support for managing storage images, sampled images, and samplers.
    • Improved graphics device initialization and error handling.
    • Expanded result enum with a new overflow enumerator.
  • Bug Fixes

    • Added null pointer checks during graphics initialization.
  • Chores

    • Updated Vulkan-related dependencies.

Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

The pull request introduces significant enhancements to Vulkan descriptor management in the graphics system. The changes focus on adding a robust descriptor set allocation and management mechanism in the Graphics.cpp file. New structures, descriptor_set_allocator and descriptor_set_manager, are implemented for managing descriptor set lifecycle, including initialization, allocation, and cleanup. The graphics device initialization process is updated with new variables for descriptor pools and layouts, and error handling is improved. Additionally, a new overflow result type is added to the Types.h file, and the VMA.cpp file now includes the Volk library header.

Changes

File Change Summary
src/Engine/Graphics.cpp - Added descriptor_set_allocator and descriptor_set_manager structs
- Updated init_descriptors method for descriptor set managers
- Modified deinit method for cleanup of new descriptor management
- Added variables: present_queue, descriptor set managers, descriptor pool, and layout
src/Engine/Types.h - Added overflow enumerator to result enum class
src/Engine/VMA.cpp - Included "volk/volk.h" header

Possibly related PRs

  • Device initialization #10: Device initialization - Modifies Graphics.cpp and enhances Vulkan device management, closely related to descriptor management changes.

Poem

🐰 Descriptors dance, a Vulkan ballet,
Allocators weave their magical way,
Sets managed with precision and care,
Graphics evolve beyond compare!
A rabbit's code, both nimble and bright 🎨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/Engine/Graphics.cpp (1)

939-939: Remove unused variable device_size

The variable device_size declared at line 939 is unused in the subsequent code. Removing it will clean up the code.

Apply this diff to remove the unused variable:

-			constexpr VkDeviceSize device_size{ 0 };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9131f5b and 660cfd7.

📒 Files selected for processing (3)
  • src/Engine/Graphics.cpp (8 hunks)
  • src/Engine/Types.h (1 hunks)
  • src/Engine/VMA.cpp (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/Engine/VMA.cpp
🔇 Additional comments (5)
src/Engine/Graphics.cpp (4)

11-12: Includes for <queue> and <stack> are necessary

The inclusion of <queue> and <stack> headers is appropriate as they are used in the descriptor_set_allocator implementation.


961-968: Verify the use of vkGetDeviceQueue2

The function vkGetDeviceQueue2 is used to retrieve the presentation queue. Ensure that the Vulkan API version supports this function (it requires Vulkan 1.1 or higher).

If your application needs to support Vulkan versions prior to 1.1, consider using vkGetDeviceQueue instead.


47-48: Proper handling of overflow condition in allocate method

The allocate method correctly checks for the maximum index limit and returns rosy::result::overflow when exceeded. Good job handling potential overflow.


1187-1191: Ensure consistent null checks for initialization parameters

The function checks for new_window and new_log being nullptr before proceeding. This is good practice to prevent null dereferences.

src/Engine/Types.h (1)

13-13: Ensure all code handles the new overflow result

The addition of overflow to the result enum expands the possible return values. Make sure that all switch statements and error handling code that use result are updated to handle this new value appropriately.

Run the following script to find all usages of rosy::result and check for missing cases:

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/Engine/Graphics.cpp (1)

78-84: Improve error handling in descriptor_set_manager::init

The method always returns result::ok without validating inputs. Consider adding checks for:

  • new_max_indexes > 0
  • new_binding validity
 result init(const uint32_t new_max_indexes, const uint32_t new_binding)
 {
+    if (new_max_indexes == 0) {
+        return result::invalid_argument;
+    }
     binding = new_binding;
     allocator = descriptor_set_allocator{};
     allocator.max_indexes = new_max_indexes;
     return result::ok;
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 660cfd7 and c3d804e.

📒 Files selected for processing (1)
  • src/Engine/Graphics.cpp (10 hunks)
🧰 Additional context used
📓 Learnings (1)
src/Engine/Graphics.cpp (1)
Learnt from: btipling
PR: btipling/Rosy#12
File: src/Engine/Graphics.cpp:999-1024
Timestamp: 2025-01-13T00:35:51.032Z
Learning: In the Rosy engine, cleanup of graphics resources (including descriptor managers) is handled through the deinit chain: Engine.cpp calls graphics::deinit() which calls graphics_device::deinit(). This ensures proper cleanup even if initialization fails midway.
🔇 Additional comments (8)
src/Engine/Graphics.cpp (8)

5-6: LGTM! Required includes for descriptor management.

The added STL includes are necessary for the descriptor set allocator implementation.


36-69: Consider thread safety for descriptor_set_allocator

The allocator uses shared resources (std::stack, member variables) without synchronization, which could lead to data races if accessed concurrently.


167-182: LGTM! Well-organized member variables.

The new member variables are properly initialized and logically grouped.


939-954: LGTM! Proper VMA initialization setup.

The VMA allocator is correctly configured with Vulkan 1.3 support and buffer device address capabilities.


962-978: LGTM! Well-structured presentation queue initialization.

Good implementation with proper error handling and debug utils integration.


1055-1057: LGTM! Good validation of binding counts.

Proper validation ensuring consistency between bindings, flags, and pool sizes.


1188-1192: LGTM! Proper input validation.

Good defensive programming with null checks for critical parameters.


999-1024: 🛠️ Refactor suggestion

Handle descriptor manager cleanup on initialization failure

While the deinit chain handles cleanup on normal shutdown, the error paths need proper cleanup to prevent memory leaks during initialization failures.

 if (desc_sampled_images == nullptr)
 {
+    delete desc_storage_images;
+    desc_storage_images = nullptr;
     return VK_ERROR_OUT_OF_HOST_MEMORY;
 }
 if (desc_samples == nullptr)
 {
+    delete desc_storage_images;
+    delete desc_sampled_images;
+    desc_storage_images = nullptr;
+    desc_sampled_images = nullptr;
     return VK_ERROR_OUT_OF_HOST_MEMORY;
 }

Likely invalid or redundant comment.

@btipling btipling merged commit 648ca93 into master Jan 13, 2025
@btipling btipling deleted the bt/init_vk_progress branch January 13, 2025 00:40
@coderabbitai coderabbitai bot mentioned this pull request Jan 18, 2025
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.

1 participant