|
@@ -163,6 +163,8 @@ class WGSLNodeBuilder extends NodeBuilder {
|
|
|
|
|
|
this.builtins = {};
|
|
|
|
|
|
+ this.directives = {};
|
|
|
+
|
|
|
}
|
|
|
|
|
|
needsColorSpaceToLinear( texture ) {
|
|
@@ -655,6 +657,50 @@ ${ flowData.code }
|
|
|
|
|
|
}
|
|
|
|
|
|
+ enableDirective( name, shaderStage = this.shaderStage ) {
|
|
|
+
|
|
|
+ const stage = this.directives[ shaderStage ] || ( this.directives[ shaderStage ] = [] );
|
|
|
+ stage.push( name );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ getDirectives( shaderStage ) {
|
|
|
+
|
|
|
+ const snippets = [];
|
|
|
+ const directives = this.directives[ shaderStage ];
|
|
|
+
|
|
|
+ if ( directives !== undefined ) {
|
|
|
+
|
|
|
+ for ( const directive of directives ) {
|
|
|
+
|
|
|
+ snippets.push( `enable ${directive}` );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return snippets.join( '\n' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ enableClipDistances() {
|
|
|
+
|
|
|
+ this.enableDirective( 'clip_distances' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ enableShaderF16() {
|
|
|
+
|
|
|
+ this.enableDirective( 'f16' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ enableDualSourceBlending() {
|
|
|
+
|
|
|
+ this.enableDirective( 'dual_source_blending' );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
getBuiltins( shaderStage ) {
|
|
|
|
|
|
const snippets = [];
|
|
@@ -970,6 +1016,7 @@ ${ flowData.code }
|
|
|
stageData.structs = this.getStructs( shaderStage );
|
|
|
stageData.vars = this.getVars( shaderStage );
|
|
|
stageData.codes = this.getCodes( shaderStage );
|
|
|
+ stageData.directives = this.getDirectives( shaderStage );
|
|
|
|
|
|
//
|
|
|
|
|
@@ -1129,6 +1176,8 @@ ${ flowData.code }
|
|
|
_getWGSLVertexCode( shaderData ) {
|
|
|
|
|
|
return `${ this.getSignature() }
|
|
|
+// directives
|
|
|
+${shaderData.directives};
|
|
|
|
|
|
// uniforms
|
|
|
${shaderData.uniforms}
|
|
@@ -1188,6 +1237,9 @@ fn main( ${shaderData.varyings} ) -> ${shaderData.returnType} {
|
|
|
_getWGSLComputeCode( shaderData, workgroupSize ) {
|
|
|
|
|
|
return `${ this.getSignature() }
|
|
|
+// directives
|
|
|
+${shaderData.directives}
|
|
|
+
|
|
|
// system
|
|
|
var<private> instanceIndex : u32;
|
|
|
|