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

Full shader transpilation #1342

Merged
merged 9 commits into from Jan 27, 2020
Merged

Full shader transpilation #1342

merged 9 commits into from Jan 27, 2020

Conversation

tsherif
Copy link
Contributor

@tsherif tsherif commented Jan 24, 2020

  • Perform transpilation on full shader rather than just shader modules in assembleShaders.
  • Add options to Model, ProgramManager and assembleShaders to force transpilation to GLSL 1.0.
  • Add transpilation rules to fix GLSL version declaration and fragment shader output.

Tested with a simplified version of the deck.gl GLSL 3.0 mesh layer shaders.

@coveralls
Copy link

coveralls commented Jan 24, 2020

Coverage Status

Coverage increased (+0.09%) to 65.832% when pulling 45bbe78 on full-shader-transpile into 566f762 on master.

Copy link
Contributor

@1chandu 1chandu left a comment

Choose a reason for hiding this comment

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

Looks good, but one question:
Before this change, we would force transpile shaderModule's code to actual shader version. Now with the change, we optionally force all the shader code to 100, but if this option , transpileShaders is not set and actual shader and shader module code are different version, its going fail compilation? If so make this option mandatory or make it backward compatible ?

@@ -40,10 +39,10 @@ export default class ShaderModule {
let moduleSource;
switch (type) {
case VERTEX_SHADER:
moduleSource = transpileShader(this.vs || '', targetGLSLVersion, true);
moduleSource = this.vs || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove targetGLSLVersion argument ?

@tsherif
Copy link
Contributor Author

tsherif commented Jan 25, 2020

transpileShaders is not set and actual shader and shader module code are different version, its going fail compilation?

That's handled by the full transpilation here: https://github.com/uber/luma.gl/pull/1342/files#diff-939a698d001db05bb4762bf253428143R144

If transpile isn't set, the entire assembled shader will be transpiled to the version of the base shader source code.

Copy link
Contributor

@1chandu 1chandu left a comment

Choose a reason for hiding this comment

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

Thanks for clarifying , looks good to me.

@tsherif tsherif merged commit 5a7e440 into master Jan 27, 2020
@tsherif tsherif deleted the full-shader-transpile branch January 27, 2020 20:07
* `vs` - (VertexShader|*string*) - A vertex shader object, or source as a string.
* `fs` - (FragmentShader|*string*) - A fragment shader object, or source as a string.
* `varyings` (WebGL 2) - An array of vertex shader output variables, that needs to be recorded (used in TransformFeedback flow).
* `bufferMode` (WebGL 2) - Mode to be used when recording vertex shader outputs (used in TransformFeedback flow). Default value is `gl.SEPARATE_ATTRIBS`.
* `modules` - shader modules to be applied.
* `program` - pre created program to use, when provided, vs, ps and modules are not used.
* `shaderCache` - (ShaderCache) - Compiled shader (Vertex and Fragment) are cached in this object very first time they got compiled and then retrieved when same shader is used. When using multiple Model objects with duplicate shaders, use the same shaderCache object for better performance.
* `programManager` - `ProgramManager` to use for program creation and caching.
* `transpileShaders` - Transpile vertex and fragment shaders to GLSL 1.0.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd call it transpileToGLSL1: true or targetVersion: 100 to remove any ambiguity.

const outputName = outputMatch[1];
source = source
.replace(FS_OUTPUT_REGEX, '')
.replace(new RegExp(`\\b${outputName}\\b`, 'g'), 'gl_FragColor');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason to not use the inline regex syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interpolation of outputName. Is there a way to do that with a literal?

@@ -28,6 +29,117 @@ void main(void) {
}
`;

const VS_GLSL_300_2 = `\
Copy link
Collaborator

Choose a reason for hiding this comment

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

.replace(/texture\(/g, 'texture2D(');
.replace(/^#version\s+300\s+es/, '#version 100')
.replace(/^[ \t]*in[ \t]+/gm, 'attribute ')
.replace(/^[ \t]*out[ \t]+/gm, 'varying ')
Copy link
Collaborator

Choose a reason for hiding this comment

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

No handling for layout yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Saving it for a later iteration.

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

4 participants