@@ -83,6 +83,8 @@ class Shader {
8383 * @param {Map<string, string> } [definition.cincludes] - A map containing key-value pairs
8484 * of include names and their content. These are used for resolving #include directives in the
8585 * compute shader source.
86+ * @param {Map<string, string> } [definition.cdefines] - A map containing key-value pairs of
87+ * define names and their values. These are used for resolving defines in the compute shader.
8688 * @param {boolean } [definition.useTransformFeedback] - Specifies that this shader outputs
8789 * post-VS data to a buffer.
8890 * @param {string | string[] } [definition.fragmentOutputTypes] - Fragment shader output types,
@@ -132,8 +134,17 @@ class Shader {
132134 Debug . assert ( graphicsDevice . supportsCompute , 'Compute shaders are not supported on this device.' ) ;
133135 Debug . assert ( ! definition . vshader && ! definition . fshader , 'Vertex and fragment shaders are not supported when creating a compute shader.' ) ;
134136
137+ // keep reference to unmodified shader in debug mode
138+ Debug . call ( ( ) => {
139+ this . cUnmodified = definition . cshader ;
140+ } ) ;
141+
142+ // Prepend defines to compute shader source
143+ const definesCode = ShaderDefinitionUtils . getDefinesCode ( graphicsDevice , definition . cdefines ) ;
144+ const cshader = definesCode + definition . cshader ;
145+
135146 // pre-process compute shader source
136- definition . cshader = Preprocessor . run ( definition . cshader , definition . cincludes , {
147+ definition . cshader = Preprocessor . run ( cshader , definition . cincludes , {
137148 sourceName : `compute shader for ${ this . label } ` ,
138149 stripDefines : true
139150 } ) ;
0 commit comments