MCPcopy Index your code
hub / github.com/gpujs/gpu.js / validateSettings

Method validateSettings

src/backend/web-gl2/kernel.js:152–221  ·  view source on GitHub ↗

* @desc Validate settings related to Kernel, such as dimensions size, and auto output support. * @param {IArguments} args

(args)

Source from the content-addressed store, hash-verified

150 * @param {IArguments} args
151 */
152 validateSettings(args) {
153 if (!this.validate) {
154 this.texSize = utils.getKernelTextureSize({
155 optimizeFloatMemory: this.optimizeFloatMemory,
156 precision: this.precision,
157 }, this.output);
158 return;
159 }
160
161 const { features } = this.constructor;
162 if (this.precision === 'single' && !features.isFloatRead) {
163 throw new Error('Float texture outputs are not supported');
164 } else if (!this.graphical && this.precision === null) {
165 this.precision = features.isFloatRead ? 'single' : 'unsigned';
166 }
167
168 if (this.fixIntegerDivisionAccuracy === null) {
169 this.fixIntegerDivisionAccuracy = !features.isIntegerDivisionAccurate;
170 } else if (this.fixIntegerDivisionAccuracy && features.isIntegerDivisionAccurate) {
171 this.fixIntegerDivisionAccuracy = false;
172 }
173
174 this.checkOutput();
175
176 if (!this.output || this.output.length === 0) {
177 if (args.length !== 1) {
178 throw new Error('Auto output only supported for kernels with only one input');
179 }
180
181 const argType = utils.getVariableType(args[0], this.strictIntegers);
182 switch (argType) {
183 case 'Array':
184 this.output = utils.getDimensions(argType);
185 break;
186 case 'NumberTexture':
187 case 'MemoryOptimizedNumberTexture':
188 case 'ArrayTexture(1)':
189 case 'ArrayTexture(2)':
190 case 'ArrayTexture(3)':
191 case 'ArrayTexture(4)':
192 this.output = args[0].output;
193 break;
194 default:
195 throw new Error('Auto output not supported for input type: ' + argType);
196 }
197 }
198
199 if (this.graphical) {
200 if (this.output.length !== 2) {
201 throw new Error('Output must have 2 dimensions on graphical mode');
202 }
203
204 if (this.precision === 'single') {
205 console.warn('Cannot use graphical mode and single precision at the same time');
206 this.precision = 'unsigned';
207 }
208
209 this.texSize = utils.clone(this.output);

Callers

nothing calls this directly

Calls 4

checkOutputMethod · 0.80
getVariableTypeMethod · 0.80
checkTextureSizeMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected