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

Method validateSettings

src/backend/web-gl/kernel.js:252–328  ·  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

250 * @param {IArguments} args
251 */
252 validateSettings(args) {
253 if (!this.validate) {
254 this.texSize = utils.getKernelTextureSize({
255 optimizeFloatMemory: this.optimizeFloatMemory,
256 precision: this.precision,
257 }, this.output);
258 return;
259 }
260
261 const { features } = this.constructor;
262
263 if (this.optimizeFloatMemory === true && !features.isTextureFloat) {
264 throw new Error('Float textures are not supported');
265 } else if (this.precision === 'single' && !features.isFloatRead) {
266 throw new Error('Single precision not supported');
267 } else if (!this.graphical && this.precision === null && features.isTextureFloat) {
268 this.precision = features.isFloatRead ? 'single' : 'unsigned';
269 }
270
271 if (this.subKernels && this.subKernels.length > 0 && !this.extensions.WEBGL_draw_buffers) {
272 throw new Error('could not instantiate draw buffers extension');
273 }
274
275 if (this.fixIntegerDivisionAccuracy === null) {
276 this.fixIntegerDivisionAccuracy = !features.isIntegerDivisionAccurate;
277 } else if (this.fixIntegerDivisionAccuracy && features.isIntegerDivisionAccurate) {
278 this.fixIntegerDivisionAccuracy = false;
279 }
280
281 this.checkOutput();
282
283 if (!this.output || this.output.length === 0) {
284 if (args.length !== 1) {
285 throw new Error('Auto output only supported for kernels with only one input');
286 }
287
288 const argType = utils.getVariableType(args[0], this.strictIntegers);
289 switch (argType) {
290 case 'Array':
291 this.output = utils.getDimensions(argType);
292 break;
293 case 'NumberTexture':
294 case 'MemoryOptimizedNumberTexture':
295 case 'ArrayTexture(1)':
296 case 'ArrayTexture(2)':
297 case 'ArrayTexture(3)':
298 case 'ArrayTexture(4)':
299 this.output = args[0].output;
300 break;
301 default:
302 throw new Error('Auto output not supported for input type: ' + argType);
303 }
304 }
305
306 if (this.graphical) {
307 if (this.output.length !== 2) {
308 throw new Error('Output must have 2 dimensions on graphical mode');
309 }

Callers 1

buildMethod · 0.95

Calls 4

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

Tested by

no test coverage detected