-
Notifications
You must be signed in to change notification settings - Fork 909
Fix to allow using the glslang_shader_parse from C API without preprocess #3803
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to add this fragment shader as a test case?
I will try to look into it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this fix does what you meant. If the code is not pre-processed, we still fail to parse with:
ERROR: 0:4: 'gl_GlobalInvocationID' : undeclared identifier
ERROR: 0:4: '' : compilation terminated
ERROR: 2 compilation errors. No code generated.
Which I guess it's expected because gl_GlobalInvocationID is not expanded properly.
@antaalt are you still working on this PR? Thanks. |
Sorry, did not had the time to look into it, it compile fine for me if i specify the compute shader stage as gl_GlobalInvocationID is a compute only variable. For me the issue is mostly due to the C API that requires to call preprocess before calling parse (it will crash if you dont), while with the C++ API, simply calling parse is enough. It looks like parse is doing the preprocessing steps aswell. Calling preprocess before calling parse will preprocess the code twice, which is the reason of the bug in this changelist. Ideally, we should avoid preprocessing twice, this is a small fix to just allow us to run parse without calling preprocess before. I will try to look to add some test for this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the new test. Would you consider adding a couple more tests that check for other escape sequences and macro expansion?
Also, if pre-processing has occurred, we should now just use the pre-processed string, right? Perhaps a test that validates this makes sense?
Thanks.
); | ||
// Seems glslang is preprocessing files twice if we call preprocess then parse on the preprocessed string. | ||
// As we are forcing the use of preprocess before parse, this could lead to some issues with line return being preprocessed twice for example. | ||
// Should avoid preprocessing twice in this case ideally, but just allow using C Api without preprocess for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/C Api/C API/
const int shaderLengths = static_cast<int>(source.size()); | ||
|
||
// Done by framework | ||
//glslang_initialize_process(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have this commented-out code here.
const std::string logs = std::string(glslang_shader_get_info_log(shader)); | ||
glslang_shader_delete(shader); | ||
return std::make_tuple(false, logs); | ||
}*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yes, but why have it here commented out?
Hello,
I went into problem with the C API of glslang. Here is a small repro sample of the issue:
This will produce an
End of line in string
error for\n
within string, but glslangValidator does not produce this error. After digging into it, it seems calling preprocess will replace\n
string by a newline feed character (Code atMachineIndependant/preprocessor/PpScanner.cpp:1136
), which will then be used by parse & produce this error.With this CL, I try to fix this by not forcing the parse function to have preprocess executed before. Right now the C API dont allow parsing without preprocessing while the C++ API allow it. This issue should probably be solved more deeply to allow preprocess & parsing aswell but as its a very minor issue, I dont think it should really be a problem.