Fix #134234: GPU: Shader Compile Error on with gpu.types.GPUShader

The removal of the loose uniform made the shader not compile.
This patch adds a new define for these type of shaders and add
back the loose uniform.

Note that these shaders might no longer work on Metal as
the source is not parsed anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/134341
This commit is contained in:
Clément Foucault
2025-02-10 14:06:47 +01:00
committed by Clément Foucault
parent acfc8f2cc6
commit 34216a2b7b
2 changed files with 17 additions and 1 deletions

View File

@@ -331,9 +331,18 @@ GPUShader *GPU_shader_create_from_python(std::optional<StringRefNull> vertcode,
std::optional<StringRefNull> fragcode,
std::optional<StringRefNull> geomcode,
std::optional<StringRefNull> libcode,
const std::optional<StringRefNull> defines,
std::optional<StringRefNull> defines,
const std::optional<StringRefNull> name)
{
std::string defines_cat = "#define GPU_RAW_PYTHON_SHADER\n";
if (defines) {
defines_cat += defines.value();
defines = defines_cat;
}
else {
defines = defines_cat;
}
std::string libcodecat;
if (!libcode) {

View File

@@ -11,6 +11,13 @@ SHADER_LIBRARY_CREATE_INFO(gpu_srgb_to_framebuffer_space)
/* Undefine the macro that avoids compilation errors. */
#undef blender_srgb_to_framebuffer_space
/* Raw python shaders don't have create infos and thus don't generate the needed `srgbTarget`
* uniform automatically. For API compatibility, we sill define this loose uniform, but it will
* not be parsed by the Metal or Vulkan backend. */
#ifdef GPU_RAW_PYTHON_SHADER
uniform bool srgbTarget = false;
#endif
vec4 blender_srgb_to_framebuffer_space(vec4 in_color)
{
if (srgbTarget) {