Page MenuHome

Fix signed/unsigned mismatches in shader code
ClosedPublic

Authored by Johannes J. (johannesj) on May 22 2022, 10:28 AM.

Details

Summary

Fix the following error messages on Blender startup
since commit 308a12ac647d6f9b4ef2b6c403903e0aeb65a571.

This commit fixes T98194.

ERROR (gpu.shader): overlay_background VertShader:

    |
178 |   SHOW_AXIS_X = (1 << 0),
    |                  ^
    | overlay_shader_shared.h:28:18: Error: initializer of type int cannot be assigned to variable of type uint

[and similar ones]

ERROR (gpu.shader): overlay_grid VertShader:

|

1275 | if (flag_test(grid_flag, PLANE_XY)) {

|       ^
| grid_vert.glsl:15:7: Error: no matching function for call to `flag_test(int, uint)'; candidates are:
| grid_vert.glsl:15:7: Error: bool flag_test(uint, uint)
| grid_vert.glsl:15:7: Error: bool flag_test(int, int)
| grid_vert.glsl:15:7: Error: if-statement condition must be scalar boolean

[and similar ones]

ERROR (gpu.shader): overlay_outline_prepass_gpencil VertShader:

|

1477 | return gpencil_vertex(ma,

|          ^
| common_gpencil_lib.glsl:382:10: Error: no matching function for call to `gpencil_vertex(ivec4, ivec4, ivec4, ivec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, int, vec2, vec3, vec3, vec4, float, vec2, vec4, vec2, vec2, float)'; candidates are:
| common_gpencil_lib.glsl:382:10: Error: vec4 gpencil_vertex(ivec4, ivec4, ivec4, ivec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, uint, vec2, vec3, vec3, vec4, float, vec2, vec4, vec2, vec2, float)
| common_gpencil_lib.glsl:382:10: Error: vec4 gpencil_vertex(ivec4, ivec4, ivec4, ivec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec4, vec3, vec3, vec4, float, vec2, vec4, vec2, vec2, float)
|
|   return gpencil_vertex(ma,
|   ^
| common_gpencil_lib.glsl:382:3: Error: `return' with wrong type error, in function `gpencil_vertex' returning vec4

Diff Detail

Repository
rB Blender

Event Timeline

Johannes J. (johannesj) requested review of this revision.May 22 2022, 10:28 AM
Johannes J. (johannesj) created this revision.
Clément Foucault (fclem) requested changes to this revision.May 22 2022, 6:37 PM

The issue is that this patch works on some implementations but not others.

We don't have a uint uniform function and changing the shader uniform type to uint without using the correct uniform function will produce a GL_ERROR on more pedantic GL implementation.
Adding the uint case for just this usage seemed a bit overkill when I was doing the changes.
So maybe the workaround is to leave the INT in the interface, and implement flag_test(int, uint) as flag_test(uint(a), b).

The GPencil fix is ok to be commited.

source/blender/draw/engines/overlay/overlay_shader_shared.h
27–39

Use same suffix. Some implementation have warning about mixed type shifting.

This revision now requires changes to proceed.May 22 2022, 6:37 PM

Apply changes suggested by Clément Foucault

Thanks for the review and the suggestions.

BTW, if this is accepted, it should also go on the 3.2 release branch if possible. Anything special I need to do here?

Thank you for this patch! Happy that it fixes the issue.

BTW, if this is accepted, it should also go on the 3.2 release branch if possible. Anything special I need to do here?

Nope. I'll just commit this to the release branch.

This revision is now accepted and ready to land.May 23 2022, 4:27 PM