Conversation
Summary of ChangesHello @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 Highlights
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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
| [*.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 |
There was a problem hiding this comment.
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
| 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; | ||
| } |
There was a problem hiding this comment.
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);
}| 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); | ||
| }); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
TODO REMINDER: replace this with compile time implementation
| ABrush brush; | ||
| glm::vec2 position; | ||
| glm::vec2 size; | ||
| int zIndex; |
There was a problem hiding this comment.
TODO REMINDER: look into changing this into more suitable data type
Tasks: