Conversation
waruqi
commented
Dec 7, 2025
- Before adding new features and new modules, please go to issues to submit the relevant feature description first.
- Write good commit messages and use the same coding conventions as the rest of the project.
- Please commit code to dev branch and we will merge into master branch in feature
- Ensure your edited codes with four spaces instead of TAB.
- 增加新特性和新模块之前,请先到issues提交相关特性说明,经过讨论评估确认后,再进行相应的代码提交,避免做无用工作。
- 编写友好可读的提交信息,并使用与工程代码相同的代码规范,代码请用4个空格字符代替tab缩进。
- 请提交代码到dev分支,如果通过,我们会在特定时间合并到master分支上。
- 为了规范化提交日志的格式,commit消息,不要用中文,请用英文描述。
Summary of ChangesHello @waruqi, 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 introduces a new Highlights
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 bin2obj support for glsl2spv and hlsl2spv rules, which is a valuable addition for embedding shaders. The implementation is well-structured, including a new reusable bin2obj utility and corresponding test cases. My review focuses on a few areas for improvement:
- A correctness issue where a null terminator is incorrectly added to SPIR-V binary data.
- Opportunities to refactor the new C test code for better readability, correctness, and maintainability.
- Minor code redundancy and style improvements in the Lua scripts.
| local objectfile = bin2obj_utils.generate_objectfile(target, batchcmds, spvfilepath, { | ||
| progress = opt.progress, | ||
| zeroend = true -- default enable zeroend for shader data | ||
| }) |
There was a problem hiding this comment.
Setting zeroend = true for SPIR-V binary data is incorrect. SPIR-V is a binary format with a specific structure, not a null-terminated string. Appending a null byte will alter the content and size, which can cause issues with SPIR-V parsers. The bin2c path correctly disables the null terminator. For consistency and correctness, zeroend should be false. Since false is the default, you can simply omit this option.
local objectfile = bin2obj_utils.generate_objectfile(target, batchcmds, spvfilepath, {
progress = opt.progress
})
| #include <stdio.h> | ||
| #include <stdint.h> | ||
|
|
||
| extern const uint8_t _binary_test_vert_spv_start[]; | ||
| extern const uint8_t _binary_test_vert_spv_end[]; | ||
|
|
||
| extern const uint8_t _binary_test_frag_spv_start[]; | ||
| extern const uint8_t _binary_test_frag_spv_end[]; | ||
|
|
||
| int main(int argc, char** argv) { | ||
| const uint32_t vert_size = (uint32_t)(_binary_test_vert_spv_end - _binary_test_vert_spv_start); | ||
| const uint32_t frag_size = (uint32_t)(_binary_test_frag_spv_end - _binary_test_frag_spv_start); | ||
|
|
||
| printf("test.vert.spv: size: %u bytes\n", vert_size); | ||
| printf("test.frag.spv: size: %u bytes\n", frag_size); | ||
|
|
||
| // Print first few bytes | ||
| if (vert_size > 0) { | ||
| printf("test.vert.spv first 4 bytes: "); | ||
| for (uint32_t i = 0; i < 4 && i < vert_size; i++) { | ||
| printf("%02x ", _binary_test_vert_spv_start[i]); | ||
| } | ||
| printf("\n"); | ||
| } | ||
|
|
||
| if (frag_size > 0) { | ||
| printf("test.frag.spv first 4 bytes: "); | ||
| for (uint32_t i = 0; i < 4 && i < frag_size; i++) { | ||
| printf("%02x ", _binary_test_frag_spv_start[i]); | ||
| } | ||
| printf("\n"); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
This test program can be improved for correctness, readability and maintainability:
- The
mainfunction signature should beint main(void)asargcandargvare unused. - For portability and correctness,
size_t(from<stddef.h>) should be used for sizes, along with the%zuformat specifier inprintf. - The code for printing vertex and fragment shader information is duplicated. Extracting it into a helper function would reduce redundancy.
Here is a suggested refactoring that addresses these points:
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
extern const uint8_t _binary_test_vert_spv_start[];
extern const uint8_t _binary_test_vert_spv_end[];
extern const uint8_t _binary_test_frag_spv_start[];
extern const uint8_t _binary_test_frag_spv_end[];
static void print_shader_info(const char* name, const uint8_t* start, const uint8_t* end) {
const size_t size = (size_t)(end - start);
printf("%s: size: %zu bytes\n", name, size);
if (size > 0) {
printf("%s first 4 bytes: ", name);
const size_t print_count = size < 4 ? size : 4;
for (size_t i = 0; i < print_count; i++) {
printf("%02x ", start[i]);
}
printf("\n");
}
}
int main(void) {
print_shader_info("test.vert.spv", _binary_test_vert_spv_start, _binary_test_vert_spv_end);
print_shader_info("test.frag.spv", _binary_test_frag_spv_start, _binary_test_frag_spv_end);
return 0;
}| #include <stdio.h> | ||
| #include <stdint.h> | ||
|
|
||
| extern const uint8_t _binary_test_vs_spv_start[]; | ||
| extern const uint8_t _binary_test_vs_spv_end[]; | ||
|
|
||
| extern const uint8_t _binary_test_ps_spv_start[]; | ||
| extern const uint8_t _binary_test_ps_spv_end[]; | ||
|
|
||
| int main(int argc, char** argv) { | ||
| const uint32_t vs_size = (uint32_t)(_binary_test_vs_spv_end - _binary_test_vs_spv_start); | ||
| const uint32_t ps_size = (uint32_t)(_binary_test_ps_spv_end - _binary_test_ps_spv_start); | ||
|
|
||
| printf("test.vs.spv: size: %u bytes\n", vs_size); | ||
| printf("test.ps.spv: size: %u bytes\n", ps_size); | ||
|
|
||
| // Print first few bytes | ||
| if (vs_size > 0) { | ||
| printf("test.vs.spv first 4 bytes: "); | ||
| for (uint32_t i = 0; i < 4 && i < vs_size; i++) { | ||
| printf("%02x ", _binary_test_vs_spv_start[i]); | ||
| } | ||
| printf("\n"); | ||
| } | ||
|
|
||
| if (ps_size > 0) { | ||
| printf("test.ps.spv first 4 bytes: "); | ||
| for (uint32_t i = 0; i < 4 && i < ps_size; i++) { | ||
| printf("%02x ", _binary_test_ps_spv_start[i]); | ||
| } | ||
| printf("\n"); | ||
| } | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
This test program can be improved for correctness, readability and maintainability:
- The
mainfunction signature should beint main(void)asargcandargvare unused. - For portability and correctness,
size_t(from<stddef.h>) should be used for sizes, along with the%zuformat specifier inprintf. - The code for printing vertex and pixel shader information is duplicated. Extracting it into a helper function would reduce redundancy.
Here is a suggested refactoring that addresses these points:
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
extern const uint8_t _binary_test_vs_spv_start[];
extern const uint8_t _binary_test_vs_spv_end[];
extern const uint8_t _binary_test_ps_spv_start[];
extern const uint8_t _binary_test_ps_spv_end[];
static void print_shader_info(const char* name, const uint8_t* start, const uint8_t* end) {
const size_t size = (size_t)(end - start);
printf("%s: size: %zu bytes\n", name, size);
if (size > 0) {
printf("%s first 4 bytes: ", name);
const size_t print_count = size < 4 ? size : 4;
for (size_t i = 0; i < print_count; i++) {
printf("%02x ", start[i]);
}
printf("\n");
}
}
int main(void) {
print_shader_info("test.vs.spv", _binary_test_vs_spv_start, _binary_test_vs_spv_end);
print_shader_info("test.ps.spv", _binary_test_ps_spv_start, _binary_test_ps_spv_end);
return 0;
}| objectfile = target:objectfile(binaryfile) | ||
| -- adjust extension based on format (use .obj for COFF, .o for others) | ||
| local objext = (format == "coff") and ".obj" or ".o" | ||
| objectfile = objectfile:gsub("%.o$", objext):gsub("%.obj$", objext) |