Skip to content

GPU batching#699

Draft
illarn wants to merge 22 commits intoaui-framework:feat/game-inventoryfrom
illarn:feat/batching
Draft

GPU batching#699
illarn wants to merge 22 commits intoaui-framework:feat/game-inventoryfrom
illarn:feat/batching

Conversation

@illarn
Copy link
Copy Markdown

@illarn illarn commented Feb 12, 2026

Tasks:

  • Render command sorting
  • zIndex in cmds
  • zIndex to z coord transformation
  • Compound meshes in VAO
  • Transform verticies on the CPU
  • Background solid/gradient support
  • Border support
  • Box and inner shadow support
  • z coord support in VS
  • Replace uniforms with vector attributes
  • Texture atlas generation
  • Background image support
  • Border radius support
  • Label support
  • Square sector support
  • Blending support
  • Overflow support
  • Lines and points support
  • Liquid glass (backdrops) support
  • Performance benchmark and comparison

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @illarn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request initiates the GPU batching effort by introducing render command sorting, which groups similar rendering operations to minimize state changes on the GPU and enhance overall rendering efficiency. It also refactors the IBatchingRenderer to streamline the command processing by removing mask and blending operations from the batched command queue. Additionally, a new .editorconfig file has been added to standardize code formatting across the project.

Highlights

  • Render Command Sorting: Implemented sorting of render commands within the OpenGLRenderer based on command type and brush index. This is a foundational step towards GPU batching, aiming to reduce state changes and improve rendering performance.
  • IBatchingRenderer Refactoring: Removed mask and blending related commands (CmdPushMaskBefore, CmdPopMaskBefore, CmdPushMaskAfter, CmdPopMaskAfter, CmdSetBlending) from the IBatchingRenderer's command queue. These operations are no longer treated as batched commands, simplifying the batching logic for other command types.
  • Code Style Consistency: Introduced an .editorconfig file to enforce consistent coding styles, including indentation, line endings, and maximum line length, specifically for C++ source and header files.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .editorconfig
    • Added a new configuration file to define consistent coding styles for C++ files.
  • .gitignore
    • Removed an unnecessary blank line.
    • Added compile_commands.json to the ignore list.
  • CONTRIBUTING.md
    • Updated the link to the contributing guide.
  • aui.views/src/AUI/GL/IBatchingRenderer.cpp
    • Removed enqueueCommand calls for mask and blending operations.
  • aui.views/src/AUI/GL/IBatchingRenderer.h
    • Corrected indentation for CmdRectangle struct.
    • Removed CmdPushMaskBefore, CmdPushMaskAfter, CmdPopMaskBefore, CmdPopMaskAfter, and CmdSetBlending structs.
    • Removed the corresponding command types from the Cmd::Arg variant.
  • aui.views/src/AUI/GL/OpenGLRenderer.cpp
    • Added includes for <algorithm>, <variant>, IBatchingRenderer.h, and ABrush.h.
    • Introduced getBrushIndex static helper function to retrieve the brush index from a command.
    • Implemented command sorting in handleCmds based on command type index and brush index.
    • Removed handling for mask and blending commands from the std::visit call in handleCmds.
  • aui.views/src/AUI/Platform/OpenGLRenderingContext.cpp
    • Removed a trailing newline character.
  • aui.views/src/AUI/Render/ABrush.h
    • Removed a trailing newline character.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces render command sorting as a first step towards GPU batching. The changes primarily involve adding sorting logic in OpenGLRenderer::handleCmds and removing some command types that are likely to be re-implemented later.

My review focuses on improving the new sorting implementation for clarity and maintainability. I've also suggested a small improvement for the newly added .editorconfig file.

The changes look like a good step forward for the batching feature. The sorting logic is sound, and my suggestions aim to make it more idiomatic and easier to read.

.editorconfig Outdated
Comment on lines +5 to +43
[*.cpp]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

[*.hpp]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

[*.h]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

[*.cc]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

[*.cxx]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The configuration for different C++ file extensions is duplicated. You can group them into a single section for better maintainability by using a glob pattern.

[*.{cpp,hpp,h,cc,cxx}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf
max_line_length = 120

Comment on lines +246 to +263
static int getBrushIndex(const IBatchingRenderer::Cmd& cmd) {
int result = -1;

std::visit(aui::lambda_overloaded {
[&](const IBatchingRenderer::CmdRectangle& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdRoundedRectangle& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdRectangleBorder& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdRoundedRectangleBorder& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdLines& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdPoints& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdLinesPairs& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdSquareSector& arg) { result = arg.brush.index(); },
[&](const IBatchingRenderer::CmdSetWindow& arg) { result = -2; },
[&](const auto& arg) { },
}, cmd.arg);

return result;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The getBrushIndex function can be simplified by returning the value from std::visit directly, instead of capturing a local variable. This makes the code more concise and leverages modern C++ features.

static int getBrushIndex(const IBatchingRenderer::Cmd& cmd) {
    return std::visit(aui::lambda_overloaded {
        [](const IBatchingRenderer::CmdRectangle& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdRoundedRectangle& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdRectangleBorder& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdRoundedRectangleBorder& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdLines& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdPoints& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdLinesPairs& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdSquareSector& arg) { return static_cast<int>(arg.brush.index()); },
        [](const IBatchingRenderer::CmdSetWindow&) { return -2; },
        [](const auto&) { return -1; },
    }, cmd.arg);
}

Comment on lines +266 to +272
std::sort(cmds.begin(), cmds.end(), [](const Cmd& cmdA, const Cmd& cmdB) {
if (cmdA.arg.index() != cmdB.arg.index()) {
return cmdA.arg.index() > cmdB.arg.index();
}

return getBrushIndex(cmdA) > getBrushIndex(cmdB);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The sorting logic can be simplified and made more idiomatic by using std::tie to create tuples for comparison. This makes the intent of sorting by multiple criteria clearer and is less error-prone than manual comparison.

    std::sort(cmds.begin(), cmds.end(), [](const Cmd& cmdA, const Cmd& cmdB) {
        return std::tie(cmdA.arg.index(), getBrushIndex(cmdA)) >
               std::tie(cmdB.arg.index(), getBrushIndex(cmdB));
    });

}

void gl::Vao::indices(AArrayView<uint16_t> data) {
static std::vector<unsigned short> generateQuadIndices(const size_t vertexCount) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

TODO REMINDER: replace this with compile time implementation

ABrush brush;
glm::vec2 position;
glm::vec2 size;
int zIndex;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

TODO REMINDER: look into changing this into more suitable data type

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