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

Shader system improvements and fixes. #2577

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from

Conversation

EliteMasterEric
Copy link

Provides the following changes:

  • Store the original values for the fragment/vertex header such that they can be accessed by child classes.
  • Store the original values for the fragment/vertex body such that they can be accessed by child classes.
  • Store the original values for the fragment/vertex source such that they can be accessed by child classes.
  • Added a configurable glVersion annotation (and corresponding variables) which can be used to modify the GLSL version directive. The default value has been set to 120, which should resolve an issue on some platforms where the uniform type is unavailable.
  • Added checks to __processGLData to ensure a variable exists before it is assigned via Reflection.
    • This resolves an issue caused by custom implementation of variables in child classes.
    • Added caching to the field check to reduce calls to Reflect.fields, improving performance.

These changes were performed to support fixes for FlxRuntimeShader, as part of the pull request HaxeFlixel/flixel-addons#368. Making changes here prevents code duplication in FlxRuntimeShader, improving maintainability.

These changes have been tested on the Windows HXCPP platform.

Copy link

@JonnycatMeow JonnycatMeow left a comment

Choose a reason for hiding this comment

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

PLEASE MERGE THIS!!!

@loudoweb
Copy link
Member

loudoweb commented Aug 14, 2022

Interesting. I was looking for a feature to change a CONST value at runtime. I think storing fragment body and header would be easier for me than parsing, diassembling an reassembling the whole shader. Some shaders need to use CONST in a for loop because non-constant values are forbidden, but different values can provide a better accuracy depending on what has been set in the uniform (e.g: Glow, Outline...). So it's looking great.

That being said, if you have only tested on Windows. This need to be tested in HL, MAC, Android, iOS and HTML5 before being merged.

Also can you provide details on your issue on "some platforms", which platforms are your talking about?

@JonnycatMeow
Copy link

i tested it on mac and i can confirm it works on mac too

@MAJigsaw77
Copy link

@mastereric This pull request makes android to crash, I think is because of glVersion you added, gl version is different in android btw

@JonnycatMeow
Copy link

@mastereric This pull request makes android to crash, I think is because of glVersion you added, gl version is different in android btw

what glversion should be put to use for android?

@MAJigsaw77
Copy link

Idk the exact version

@MAJigsaw77
Copy link

You have to find out, is your pull request anyway

@JonnycatMeow
Copy link

the glsl version for android is #version 300 es how i found out is because of the flxFixedShader https://github.com/YoshiCrafter29/YoshiCrafterEngine/blob/45ddea338a211ff2d05b7d85a3a2c38bb8ab287f/source/FlxFixedShader.hx#L55

@MAJigsaw77
Copy link

That version is wrong

@EliteMasterEric
Copy link
Author

Took a bit of time today to fast forward the branch, as well as implement a couple fixes.

Mainly, glVersion is now a string, and the value defaults to 300 es on Android as suggested.

Hopefully this works for people, I've been having reports that AMD Radeon cards are having issues specifically.

@MAJigsaw77
Copy link

Dude, the default version by openfl is 100

@MAJigsaw77
Copy link

If you put 300 es it will broke everything

@JonnycatMeow
Copy link

JonnycatMeow commented Dec 3, 2022

i get an error trying to build an fnf game for mac and here is the error:
Screen Shot 2022-12-02 at 10 12 12 PM

@JonnycatMeow
Copy link

actually nvm i fixed it

{
// Specify the default glVersion.
// We can use compile defines to guess the value that prevents crashes in the majority of cases.
return #if (android) "100" #elseif (web) "100" #else "100" #end;

Choose a reason for hiding this comment

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

added another #elseif for mac and make it 120 because that the only version that is supported and then put else 100

Choose a reason for hiding this comment

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

make sure to do it for everyone of the code that says 100 even the extension

Copy link

Choose a reason for hiding this comment

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

it will look like this
Screen Shot 2022-12-02 at 10 23 01 PM
Sc Screen Shot 2022-12-02 at 10 23 35 PM reen Shot 2022-12-02 at 10 23 21 PM
Screen Shot 2022-12-02 at 10 24 46 PM

Screen Shot 2022-12-02 at 10 23 50 PM

Copy link
Author

Choose a reason for hiding this comment

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

Wrapping the 100 makes no sense, if you force 100 on a platform that doesn't support it you should obviously get an error.

Thanks for letting me know the correct default version for Mac though.

@EliteMasterEric EliteMasterEric marked this pull request as ready for review December 4, 2022 02:47
@EliteMasterEric
Copy link
Author

EliteMasterEric commented Dec 4, 2022

This PR is now ready and fully tested on a variety of platforms.

See more at my test workbench here: https://github.com/MasterEric/Flixel-GalaxyShaderWorkbench

EDIT: Make sure to use the build instructions to ensure the correct library versions are installed before testing.

@EliteMasterEric
Copy link
Author

With help from @JonnycatMeow I was able to test the workbench on their Mac platform. Notably, their version of OpenGL ONLY supports 110 and 120. This may be significant for those looking to resolve compatibility issues.

@JonnycatMeow
Copy link

bro can someone merge this please!!!!

@Raltyro
Copy link

Raltyro commented Feb 26, 2023

The Sound modification seems pretty handy for streaming
although is it on purpose that the samplerate is locked at 44100?

@EliteMasterEric
Copy link
Author

The Sound modification seems pretty handy for streaming although is it on purpose that the samplerate is locked at 44100?

This pull request is not related to sound.

@joshtynjala
Copy link
Member

This pull request is not related to sound.

Look on the Commits tab of this PR. You merged in a SampleDataEvent commit, and maybe some other stuff. I mentioned this to you on Discord, but you never responded.

@EliteMasterEric
Copy link
Author

This pull request is not related to sound.

Look on the Commits tab of this PR. You merged in a SampleDataEvent commit, and maybe some other stuff. I mentioned this to you on Discord, but you never responded.

Thank you for informing me of this. I will re-review my branch, make appropriate fixes, and merge them ASAP so that review can continue.

@EliteMasterEric
Copy link
Author

It appears that changes related to other pull requests (#2534 and #2515) accidentally got included in the working branch for this PR. Those changes have now been removed, and the PR has additionally been fast-forwarded to match the target branch.

Please inform me here of any additional review changes.

Comment on lines +623 to +684
default:
return glExtensions;

case "100":
return glExtensions;
case "110":
return glExtensions;
case "120":
return glExtensions;
case "130":
return glExtensions;
case "140":
return glExtensions;
case "150":
return glExtensions;

case "300 es":
var hasSeparateShaderObjects = false;
for (extension in glExtensions)
{
if (extension.name == "GL_ARB_separate_shader_objects") hasSeparateShaderObjects = true;
if (extension.name == "GL_EXT_separate_shader_objects") hasSeparateShaderObjects = true;
}

#if desktop
if (!hasSeparateShaderObjects)
{
#if linux
return glExtensions.concat([{name: "GL_EXT_separate_shader_objects", behavior: "require"}]);
#else
return glExtensions.concat([{name: "GL_ARB_separate_shader_objects", behavior: "require"}]);
#end
}
#end
return glExtensions;

case "310 es":
var result = buildGLSLExtensions(glExtensions, "300 es", isFragment);
return result;

case "320 es":
var result = buildGLSLExtensions(glExtensions, "310 es", isFragment);
return result;

case "330":
var result = buildGLSLExtensions(glExtensions, "320 es", isFragment);
return result;

case "400":
return glExtensions;
case "410":
return glExtensions;
case "420":
return glExtensions;
case "430":
return glExtensions;
case "440":
return glExtensions;
case "450":
return glExtensions;
case "460":
return glExtensions;
Copy link
Contributor

@Geokureli Geokureli Apr 27, 2023

Choose a reason for hiding this comment

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

I don't get why this switch seems so needlessly convoluted.

  • Why have a bunch of cases that behave exactly like the default case?
  • why not group similar results using case "400" | "410":?
  • why "310 es" pass "300 es" into buildGLSLExtensions and so on for "320 es" and "330"?
  • why store a result var just to return it

Comment on lines +478 to +479
// We don't know this GLSL version, so don't do anything.
return source;
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe show an explicit warning like "OpenFl doesn't know glsl version ${glVersion}, no conversion will happen" ?

Choose a reason for hiding this comment

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

So then how do we use a certain glsl version in the project.xml or could it only be used in .hx code?

Copy link
Author

Choose a reason for hiding this comment

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

You don't specify GLSL version in the project.xml you specify it when you construct the shader

Choose a reason for hiding this comment

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

oh ok so then the default whould be 120 for desktops and for web it whould be 300?

Copy link
Author

Choose a reason for hiding this comment

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

oh ok so then the default whould be 120 for desktops and for web it whould be 300?

The default would be the result of getDefaultGLSLVersion

Choose a reason for hiding this comment

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

ohhh ok

Choose a reason for hiding this comment

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

then how whould i use a certain glsl version?

Copy link
Author

Choose a reason for hiding this comment

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

then how whould i use a certain glsl version?

You can use @:glVersion("120") the same way you use @:glFragmentBody("...").

As a note there is an FlxRuntimeShader in flixel-addons. It was originally built by me and ran on this, but it was modified to not use this code so it could be merged. When this is merged it will get changed back and then it will support setting the glVersion among other things.

@Raltyro
Copy link

Raltyro commented Dec 17, 2023

The Sound modification seems pretty handy for streaming
although is it on purpose that the samplerate is locked at 44100?

When did i said this what

@EliteMasterEric
Copy link
Author

The Sound modification seems pretty handy for streaming
although is it on purpose that the samplerate is locked at 44100?

When did i said this what

I accidentally included another PR in this one by mistake.

@JonnycatMeow
Copy link

there should be core and compatibility support for macOS
https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.1.50.pdf
this shader version only uses core for macOS because compatibility craps its self

@JonnycatMeow
Copy link

Screen Shot 2024-02-21 at 12 46 24 AM

@JonnycatMeow
Copy link

Screen Shot 2024-02-21 at 12 46 36 AM

@JonnycatMeow
Copy link

Screen Shot 2024-02-21 at 1 19 20 AM

@JonnycatMeow
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet