-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Shader parse error on working shaders #187
Comments
Hi! Thanks for reaching out to report your issue 😄 As it happens with JSON files, the GLSL parser used by PackSquash is more strict than Minecraft. However, unlike with JSON files, I did not intend the GLSL parser to be that way, so I agree that PackSquash should improve in this regard, and understand why it may be seen as a "bug". (There is a point in enforcing strict JSON syntax, because JSON is meant to be a data exchange format, and Minecraft accepts deviations that other commonly used programs do not. However, GLSL is rather application-specific, especially when considering the fact that Mojang extended it with preprocessor directives such as The errors you experience are caused by two known limitations, described in this issue comment:
Luckily, these limitations can be worked around with no functional differences (i.e., without affecting how the shaders work):
I reckon that applying these workarounds at scale can be tedious, but they should be enough to get your pack to compile for now. Sadly, I don't expect them to be fixed soon, due to current technical constraints caused by how PackSquash is designed, which will be addressed for v0.4.0. Please let me know if this comment was helpful to you. |
Hi Alex, Thank you for your quick reply, we'll give the workarounds a try and I'll let you know if we need anything else. Thank you, Callum |
Some preprocessor directives cannot simply be moved to the top of files, such as Although without the use of |
Right, I wasn't thinking on those! Indeed, they are part of the specification. And, while the specification is not crystal-clear about it, I think that PackSquash is wrong here, because the specification makes several statements that equate the GLSL preprocessor with the one you'd find on C. The only reason for this particular limitation to exist is that the fork of the third-party GLSL parser PackSquash uses has it. Upstream has been unresponsive for quite some time now and AFAIK there are no better GLSL parsers PackSquash could use, so any fix will likely be made by me or other PackSquash contributor on that fork. Sadly, time is finite for me now, and I'm prioritizing getting v0.4.0 released, but PRs are welcome 😄 |
That's understandable, and it is possible to work around the limitation so it is not a big deal. I believe it can be resolved by keeping the newlines around any line starting with |
Is there a way to turn off the parsing of .glsl files or exempt specific files from processing? |
I'm afraid that PackSquash does not provide any options to do that, sorry. Would you mind elaborating on why are you interested in disabling such parsing? Are the discussed workarounds impractical in your scenario? Ideally, I would like to address this issue by fixing the PackSquash GLSL parser rather than letting people sweep its problems under the rug. |
I am currently in your # | packsquash support channel in discord, but we're hoping to get the minify-shaders option to work to skip trying to parse glsl files. I sent the example of how we tried to use it, but it didn't seem to work. |
Note to self (and potentially other interested parties): the |
I recently wrote some shaders and was very disappointed to realize I can't release an update because of this. Definitely is "at scale" enough for the level of frustration to workaround is too high. I support an option to skip shader validation. No reason not to throw in a skip if the validator currently has known issues validating the base OpenGL Specifications, at least until it's actually accurate. |
I am aware of the disappointing reality that some shaders can't be used as-is with the current PackSquash release. I am also aware that it a fix for the situation is warranted and necessary, especially in situations where refactoring shaders is not a viable option. I'm sorry for the inconvenience it causes to some users. However, I won't add an option to skip parsing GLSL files. I don't believe that is the proper way to approach this issue for several reasons:
That being said, while I appreciate feedback and understand that the problem can be frustrating, I'd like to kindly ask further commentors to avoid further "I'm affected by this too" comments, unless they add something new and constructive to the topic. I want to make PackSquash as good as it can be 😄 |
Well I can respect having a vison and wanting things to align to it, my vision as an end-user is to compress a valid resource pack. All the reasoning in the world can't work around that fact that I have a valid formatted resource pack with GLSL spec compliant shaders and can no longer use this project to compress it. Even if only a "subset of shaders" are affected at the end of the day preventing a project from failing to perform it's core purpose over the prospect of a temporary config boolean seems a bit silly. |
This comment was marked as off-topic.
This comment was marked as off-topic.
As described in issue #187, PackSquash does not support shaders that use preprocessor directives in external declaration position. To properly address this issue, it is necessary to equip PackSquash with a GLSL preprocessor that runs before parsing the source GLSL, as the GLSL specification mandates for proper GLSL compilation. (Building a GLSL parser that accepts preprocessor directives anywhere, even in the middle of tokens, is, if not impossible, an exceedingly complex task.) This commit improves on the situation by adding such preprocessing capabilities to PackSquash, so that the preprocessing step accepts directives anywhere that are not seen by the downstream parser. However, if they appear in external declaration position, it is possible to inject them back into the AST, in order to preserve them in the transformed GLSL source. Only directives that are needed by Minecraft are injected; others are resolved and removed by PackSquash. In addition, include shaders now need not be full translation units: they might be standalone statements or expressions, too. Functionality to prettify shaders was also added, revamping the `minify_shader` option to a more powerful `shader_source_transformation_strategy`. These changes allow PackSquash to deal properly with a wider variety of shaders. The only ones that still trigger failure modes are: - Shaders which depend on `#moj_import`ed preprocessor variables to be syntactically correct. - Shaders which depend on `#moj_import`ed preprocessor variables to build the expected source code, but are syntactically correct otherwise. (This can be worked around by setting `source_transformation_strategy = 'keep_as_is'` for the affected shaders.) - Shaders that include vertex or fragment shaders, relying on their preprocessor variables or syntax to be valid. (This can be partially worked around by setting `is_top_level_shader = false` for the included shaders, although including vertex or fragment shaders is an extreme edge case that we never saw before, and arguably a bad idea.) The first two kinds of shaders should be able to be properly parsed for PackSquash v0.4.0, because its design allows pack files to resolve references to other files.
I'm pleased to announce that I've just pushed a commit that allows PackSquash to support a wider variety of shaders, without resorting to changing options or throwing minification out of the window in the supported cases! 🎉 The technical details of how this was accomplished can be read at the commit description. In summary:
For now, I hope that these changes help at least some of you. You can try them out on the latest unstable builds. If you are using the PackSquash GitHub Action, you'll have to bring your own options file. For those that were eager for an improvement in the situation, this represents my first concrete step forward 😉 |
As announced on Discord, the roadmap for v0.4.0 has changed, and it will be released soon with the partial fix for this issue described above. This does not affect my plans to release a better fix in the future, once the necessary redesign originally planned for v0.4.0 lands in a future version, such as v0.5.0. With the more complete fix is in place, I'd feel comfortable adding a last-resort option to skip parsing to handle use cases that might not be feasible to support. Thank you all for your patience ❤️ |
…s involved As highlighted in issue #187, a significant number of practical shaders use `#moj_import`s in ways that are tricky for PackSquash to handle without import expansion capabilities. The necessary redesign to achieve expansion will ikely take some time, but there is stakeholder pressure to get better (and more correct) solutions working now: PackSquash has arguably been incorrect in how it processes shaders for months, and justifying the status quo with upcoming plans to tackle the problems at their source is no longer a tenable proposition, leading to relatively frequent uncomfortable situations for both me and users. Therefore, let's play the cards very close to our chest when it comes to transforming GLSL sources: don't do it unless we can be certain that we have a full AST and all the preprocessor state is known. This entails significant optimization regressions for any shader that uses `#moj_import`, as not expanding that directive is the root of all evil, but PackSquash will at least just work in much more cases. In particular, these changes were tested with FancyPants, TextEffects v2.1 and objmc, which are interesting shaders from a parsing standpoint due to their popularity and intensive usage of GLSL language features.
Due to the fact that the redesign required for proper Since the latest commits, PackSquash is now very conservative about which shaders it is willing to minify or prettify, in order to avoid unwanted parsing errors or surprises when loading the pack in-game as much as possible. This means that any shader that uses I'll continue to work on better expansion and transformation capabilities, but I'd rather track them as separate enhancements and issues, since the shaders should at least "just work" now. In any case, please feel free to give feedback on the latest changes! It's very welcome 😄 |
Saw this was back on the next release backlog, just as a note, v0.4.0 seems to now get tripped up on my tooltip shader, as well as some other random one that worked with the old Tooltip shader:
Snippet from the text_effects.config.glsl shader:
|
Hi @UltraFaceguy, did you try the latest unstable builds? They should be more lenient when it comes to handling shader parsing errors. The issue was closed because the user-visible errors were fixed in such builds. |
Distribution
Linux x64 APT package
Bug description
When compiling a pack that contains Shaders from objmc (https://github.com/Godlander/objmc), I've been getting errors from Shaders that work correctly within Minecraft. Seems like they cannot be parsed but are correctly formatted.
Output:
Reproduction steps
Expected behavior
The pack should compile normally
Attached files
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: