3Dickulus / FragM

Derived from https://github.com/Syntopia/Fragmentarium/
GNU General Public License v3.0
344 stars 30 forks source link

frag/vert compatibility patches should handle `#extension` #185

Closed claudeha closed 1 year ago

claudeha commented 1 year ago

Is your feature request related to a problem? Please describe.

At the top of my shader I want to add

#version 330 core
#extension GL_ARB_array_of_array : enable

the compatibility patches mess this up giving an error about extension not allowed in middle of shader.

Describe the solution you'd like enabling compatibility patches should move extensions along with version

Describe alternatives you've considered adapt every frag to do the compatibility patches manually and disable fragm's additions

Additional context trying to implement multiwave colouring

3Dickulus commented 1 year ago

version 330 works here

version 330 core works here

version 330 compatibility works here

using #version 330 with #extension GL_ARB_array_of_array : enable shows this warning but renders ok

...Mandelbulb.frag (3) : warning C7508: extension ARB_array_of_array not supported

are you using MESA? are you using the most recent version of FragM?

starting at #version 440 core I see this error... ...Mandelbulb.frag (2) : error C7621: #extension directive must occur before any non-preprocessor token

note: #include "MathUtils.frag" uses #extension (x4) when #define WANG_HASH, also throws error starting at v440

ATM can't do much, will look into it over this weekend. will investigate #extension position in shader debug output, will try relocating all parsed #extension occurrences to immediately after #version directive.

3Dickulus commented 1 year ago

debug output looks like...

#version 440 core
#line 2 0
#extension GL_ARB_array_of_array : enable

// #info Mandelbulb Distance Estimator
#define providesInit
#define WANG_HASH
// #donotrun
#line 2 1

// #if __VERSION__ >= 300
// #extension GL_NV_gpu_shader5 : enable
// #endif

#ifdef WANG_HASH
// required for Wang hash, placing this here means this file must be the first #included file
#extension GL_ARB_shader_bit_encoding : enable
#extension GL_EXT_gpu_shader4 : enable
#extension GL_ARB_gpu_shader5 : enable
#extension GL_ARB_gpu_shader_int64 : enable
// #extension GL_NV_shader_buffer_load : enable // nVidia only
#endif

extension already does occur before any non-preprocessor tokens so not sure what's going on there ??? investigating...

3Dickulus commented 1 year ago

note: #extension is not presented in blue in the text editor so is not getting parsed properly by the highlighter code as well.

3Dickulus commented 1 year ago

try... Menu->Edit->Preferences->Apply compatibility patches = OFF ...when using #version 440 compatibility

seems like possible conflict between auto-compat and explicit compat ??? use one or the other but not both ???

claudeha commented 1 year ago

Sorry for typo in extension name...

Menu->Edit->Preferences->Apply compatibility patches = OFF

That's what I meant by

adapt every frag to do the compatibility patches manually and disable fragm's additions

3Dickulus commented 1 year ago

version 330 core

extension GL_ARB_arrays_of_arrays : enable

works when Edit->Preferences->Apply compatibility patches is enabled

just prepping a push....

3Dickulus commented 1 year ago

when compatibility patches are OFF nothing will compile/link cleanly because it's all legacy code.

claudeha commented 1 year ago

when compatibility patches are OFF nothing will compile/link cleanly because it's all legacy code.

Right. Changing frag/vert is necessary, but possible (I did it for one of mine so far, didn't attempt the rest).

3Dickulus commented 1 year ago

auto patch fixed to insert after all existing pre-processor directives. next push...

3Dickulus commented 1 year ago

extension GL_ARB_arrays_of_arrays ... this doesn't cover uniform arrays does it? ie: #146

3Dickulus commented 1 year ago

Current behaviour as of aec0270

when preferences->patch is dis-abled and #version > 120 seeing lots of : warning C7555: 'varying' is deprecated, use 'in/out' instead etc. preferences->patch fixes this successfully.

#version 330 core
#extension GL_ARB_arrays_of_arrays : enable

tested up to #version 460 core

synopsis: when #version < 130 no patch required, when #version > 120 < 330 patch is required, when #version > 320 es the preprocessor option is available ie: #version 330 compatibility this will allow nVidia cards to run frags with warnings when not patched, MESA may present these warnings as errors so requires patch.

have not tested MESA extensively.