GPUShader: Add GLSL source modification pass to support enums
This uses a light parser / string modification pass to convert C++ enum declaration syntax to GLSL compatible one. GLSL having no support for enums, we are forced to convert the enum values to a series of constant uints. The parser (not really one by the way), being stupidly simple, will not change anything to the values and thus make some C++ syntax (like omitting the values) not work. The string replacement happens on all GLSL files on startup. I did not measure significant changes in blender startup speed. There is plans to do all of this at compile time. We limit the scope of the search to `.h` and `.hh` files to prevent confusing syntax in `.glsl` files. There is basic error reporting with file, line and char logging for easy debuggabiliy. The requirements to use this enum sharing system are already listed in `gpu_shader_shared_utils.h` and repeated on top of the preprocessor function.
This commit is contained in:
@@ -27,11 +27,10 @@
|
||||
* Some preprocessing is done by the GPU back-end to make it GLSL compatible.
|
||||
*
|
||||
* IMPORTANT:
|
||||
* - Don't add trailing comma at the end of the enum. Our custom pre-processor will now trim it
|
||||
* for GLSL.
|
||||
* - Always use `u` suffix for enum values. GLSL do not support implicit cast.
|
||||
* - Define all values. This is in order to simplify custom pre-processor code.
|
||||
* - Always use uint32_t as underlying type.
|
||||
* - (C++ only) Always use `uint32_t` as underlying type (`enum eMyEnum : uint32_t`).
|
||||
* - (C only) do NOT use the enum type inside UBO/SSBO structs and use `uint` instead.
|
||||
* - Use float suffix by default for float literals to avoid double promotion in C++.
|
||||
* - Pack one float or int after a vec3/ivec3 to fulfill alignment rules.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user