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

Function cpuKernelString

src/backend/cpu/kernel-string.js:29–181  ·  view source on GitHub ↗
(cpuKernel, name)

Source from the content-addressed store, hash-verified

27}
28
29function cpuKernelString(cpuKernel, name) {
30 const header = [];
31 const thisProperties = [];
32 const beforeReturn = [];
33
34 const useFunctionKeyword = !/^function/.test(cpuKernel.color.toString());
35
36 header.push(
37 ' const { context, canvas, constants: incomingConstants } = settings;',
38 ` const output = new Int32Array(${JSON.stringify(Array.from(cpuKernel.output))});`,
39 ` const _constantTypes = ${JSON.stringify(cpuKernel.constantTypes)};`,
40 ` const _constants = ${constantsToString(cpuKernel.constants, cpuKernel.constantTypes)};`
41 );
42
43 thisProperties.push(
44 ' constants: _constants,',
45 ' context,',
46 ' output,',
47 ' thread: {x: 0, y: 0, z: 0},'
48 );
49
50 if (cpuKernel.graphical) {
51 header.push(` const _imageData = context.createImageData(${cpuKernel.output[0]}, ${cpuKernel.output[1]});`);
52 header.push(` const _colorData = new Uint8ClampedArray(${cpuKernel.output[0]} * ${cpuKernel.output[1]} * 4);`);
53
54 const colorFn = utils.flattenFunctionToString((useFunctionKeyword ? 'function ' : '') + cpuKernel.color.toString(), {
55 thisLookup: (propertyName) => {
56 switch (propertyName) {
57 case '_colorData':
58 return '_colorData';
59 case '_imageData':
60 return '_imageData';
61 case 'output':
62 return 'output';
63 case 'thread':
64 return 'this.thread';
65 }
66 return JSON.stringify(cpuKernel[propertyName]);
67 },
68 findDependency: (object, name) => {
69 return null;
70 }
71 });
72
73 const getPixelsFn = utils.flattenFunctionToString((useFunctionKeyword ? 'function ' : '') + cpuKernel.getPixels.toString(), {
74 thisLookup: (propertyName) => {
75 switch (propertyName) {
76 case '_colorData':
77 return '_colorData';
78 case '_imageData':
79 return '_imageData';
80 case 'output':
81 return 'output';
82 case 'thread':
83 return 'this.thread';
84 }
85 return JSON.stringify(cpuKernel[propertyName]);
86 },

Callers 1

toStringMethod · 0.85

Calls 2

constantsToStringFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…