Skip to content
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

Tweak shader compilation error messages #95495

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Calinou
Copy link
Member

@Calinou Calinou commented Aug 13, 2024

  • Mention the shader type that failed compilation.
  • Mention the most common cause for this error (which are syntax errors).
  • Mention that the shader code is printed nearby for troubleshooting.

Testing project: test_shader_error.zip

Preview

Note

ERROR: not enough arguments for format string is not introduced by this PR; it also occurs in master with the MRP
and is likely due to a script error in that MRP (check line 142 of VSSimplexNoise3D.gd, % arguments are missing).

Forward+

--Main Shader--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp:146)
ERROR: not enough arguments for format string
   at: validated_evaluate (./core/variant/variant_op.h:951)
--res://node_3d.tres--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (res://node_3d.tres:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp:146)
ERROR: Shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: version_get_shader (./servers/rendering/renderer_rd/shader_rd.h:166)

Mobile

--Main Shader--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp:147)
ERROR: not enough arguments for format string
   at: validated_evaluate (./core/variant/variant_op.h:951)
--res://node_3d.tres--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (res://node_3d.tres:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp:147)
ERROR: Shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: version_get_shader (./servers/rendering/renderer_rd/shader_rd.h:166)

Compatibility

--Main Shader--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (drivers/gles3/storage/material_storage.cpp:2972)
ERROR: not enough arguments for format string
   at: validated_evaluate (./core/variant/variant_op.h:951)
--res://node_3d.tres--
    1 | shader_type spatial;
    2 | render_mode blend_mix, depth_draw_opaque, cull_back, diffuse_lambert, specular_schlick_ggx;
    3 |
  ... | [...omitted from this preview to shorten the log...]
  107 |
  108 | }
  109 |
SHADER ERROR: Expected a ';'.
          at: (null) (res://node_3d.tres:101)
ERROR: Spatial shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.
   at: set_code (drivers/gles3/storage/material_storage.cpp:2972)

@Calinou Calinou requested a review from a team as a code owner August 13, 2024 18:11
@Calinou Calinou added this to the 4.4 milestone Aug 13, 2024
@@ -716,7 +716,7 @@ void ShaderGLES3::_initialize_version(Version *p_version) {

void ShaderGLES3::version_set_code(RID p_version, const HashMap<String, String> &p_code, const String &p_uniforms, const String &p_vertex_globals, const String &p_fragment_globals, const Vector<String> &p_custom_defines, const LocalVector<ShaderGLES3::TextureUniformData> &p_texture_uniforms, bool p_initialize) {
Version *version = version_owner.get_or_null(p_version);
ERR_FAIL_NULL(version);
ERR_FAIL_NULL_MSG(version, "Shader compilation failed (most likely due to a syntax error). Shader code has been printed above for troubleshooting.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct. I can't find any code path where this would be reached with a null version due to failing to compile. If compilation fails, the engine won't attempt to set the code on the version.

The error in the bug report comes from version_get_shader()

ERR_FAIL_NULL_V(version, RID());

It happens when you try to use a shader that previously failed compilation

Copy link
Member Author

@Calinou Calinou Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the message accordingly for version_set_code() in all rendering methods. Not sure if we can make it much more specific than what I put:

Can't use a shader that previously failed compilation.

@Calinou Calinou force-pushed the tweak-shader-compilation-error-messages branch from 6c6a7d5 to 7ee15df Compare August 13, 2024 19:11
@Calinou Calinou force-pushed the tweak-shader-compilation-error-messages branch from 7ee15df to 4b6fded Compare January 10, 2025 17:41
@@ -167,7 +167,7 @@ class ShaderRD {
ERR_FAIL_COND_V(!variants_enabled[p_variant], RID());

Version *version = version_owner.get_or_null(p_version);
ERR_FAIL_NULL_V(version, RID());
ERR_FAIL_NULL_V_MSG(version, RID(), "Shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same problem as before. This isn't a shader compilation error.

@@ -651,7 +651,7 @@ void ShaderRD::version_set_compute_code(RID p_version, const HashMap<String, Str
ERR_FAIL_COND(!is_compute);

Version *version = version_owner.get_or_null(p_version);
ERR_FAIL_NULL(version);
ERR_FAIL_NULL_MSG(version, "Compute shader compilation failed (most likely due to a syntax error). Shader code has been printed nearby for troubleshooting.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. This isn't a compilation error

@@ -616,7 +616,7 @@ void ShaderRD::version_set_code(RID p_version, const HashMap<String, String> &p_
ERR_FAIL_COND(is_compute);

Version *version = version_owner.get_or_null(p_version);
ERR_FAIL_NULL(version);
ERR_FAIL_NULL_MSG(version, "Can't use a shader that previously failed compilation.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per my last review, this isn't a compile error. Failing to compile is just one reason why this case may be hit. The message is misleading

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworded all 3 messages somewhat. The concept of "shader version" isn't something that is obvious to most users though (unless you look at the native shader source inspector), so I'm not sure how we could clarify it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this is an error that users would never see. It's meant to be totally internal

@Calinou Calinou force-pushed the tweak-shader-compilation-error-messages branch 2 times, most recently from 7eef8a9 to a3e1672 Compare January 10, 2025 19:20
- Mention the shader type that failed compilation.
- Mention the most common cause for this error (which are syntax errors).
- Mention that the shader code is printed nearby for troubleshooting.
@Calinou Calinou force-pushed the tweak-shader-compilation-error-messages branch from a3e1672 to 90d6b1c Compare January 10, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants