Skip to content

Commit d221e97

Browse files
fix: Experiment with end to end working strategy and unit tests
1 parent bcae4ba commit d221e97

File tree

16 files changed

+984
-603
lines changed

16 files changed

+984
-603
lines changed

dist/gpu-browser-core.js

Lines changed: 304 additions & 200 deletions
Large diffs are not rendered by default.

dist/gpu-browser-core.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser.js

Lines changed: 304 additions & 200 deletions
Large diffs are not rendered by default.

dist/gpu-browser.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/backend/gl/kernel-string.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function toStringWithoutUtils(fn) {
1010

1111
/**
1212
*
13-
* @param {Kernel} Kernel
13+
* @param {GLKernel} Kernel
1414
* @param {KernelVariable[]} args
1515
* @param {Kernel} originKernel
1616
* @param {string} [setupContextString]
@@ -192,19 +192,19 @@ function glKernelString(Kernel, args, originKernel, setupContextString, destroyC
192192
context.reset();
193193
if (kernel.renderKernels) {
194194
const results = kernel.renderKernels();
195-
const textureName = context.getContextVariableName(kernel.outputTexture);
195+
const textureName = context.getContextVariableName(kernel.texture.texture);
196196
result.push(` return {
197197
result: {
198198
texture: ${ textureName },
199199
type: '${ results.result.type }',
200200
toArray: ${ getToArrayString(results.result, textureName) }
201201
},`);
202-
const { subKernels, subKernelOutputTextures } = kernel;
202+
const { subKernels, mappedTextures } = kernel;
203203
for (let i = 0; i < subKernels.length; i++) {
204-
const texture = subKernelOutputTextures[i];
204+
const texture = mappedTextures[i];
205205
const subKernel = subKernels[i];
206206
const subKernelResult = results[subKernel.property];
207-
const subKernelTextureName = context.getContextVariableName(texture);
207+
const subKernelTextureName = context.getContextVariableName(texture.texture);
208208
result.push(`
209209
${subKernel.property}: {
210210
texture: ${ subKernelTextureName },
@@ -215,7 +215,7 @@ function glKernelString(Kernel, args, originKernel, setupContextString, destroyC
215215
result.push(` };`);
216216
} else {
217217
const rendered = kernel.renderOutput();
218-
const textureName = context.getContextVariableName(kernel.outputTexture);
218+
const textureName = context.getContextVariableName(kernel.texture.texture);
219219
result.push(` return {
220220
texture: ${ textureName },
221221
type: '${ rendered.type }',

src/backend/gl/kernel.js

Lines changed: 121 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ class GLKernel extends Kernel {
305305
super(source, settings);
306306
this.transferValues = null;
307307
this.formatValues = null;
308+
/**
309+
*
310+
* @type {Texture}
311+
*/
308312
this.TextureConstructor = null;
309313
this.renderOutput = null;
310314
this.renderRawOutput = null;
@@ -314,6 +318,8 @@ class GLKernel extends Kernel {
314318
this.compiledFragmentShader = null;
315319
this.compiledVertexShader = null;
316320
this.switchingKernels = null;
321+
this.prevInput = null;
322+
this.prevMappedInputs = null;
317323
}
318324

319325
checkTextureSize() {
@@ -483,7 +489,7 @@ class GLKernel extends Kernel {
483489
case 'LiteralInteger':
484490
case 'Float':
485491
case 'Number':
486-
case 'Integer':
492+
case 'Integer': {
487493
if (this.output[2] > 0) {
488494
this.TextureConstructor = GLTextureMemoryOptimized3D;
489495
this.renderStrategy = renderStrategy.MemoryOptimizedFloatPixelToMemoryOptimized3DFloat;
@@ -500,64 +506,68 @@ class GLKernel extends Kernel {
500506
this.formatValues = utils.erectMemoryOptimizedFloat;
501507
return null;
502508
}
503-
case 'Array(2)':
504-
if (this.output[2] > 0) {
505-
this.TextureConstructor = GLTextureArray2Float3D;
506-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
507-
this.formatValues = utils.erect3DArray2;
508-
return null;
509-
} else if (this.output[1] > 0) {
510-
this.TextureConstructor = GLTextureArray2Float2D;
511-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
512-
this.formatValues = utils.erect2DArray2;
513-
return null;
514-
} else {
515-
this.TextureConstructor = GLTextureArray2Float;
516-
this.renderStrategy = renderStrategy.FloatPixelToArray2;
517-
this.formatValues = utils.erectArray2;
518-
return null;
519-
}
520-
case 'Array(3)':
521-
if (this.output[2] > 0) {
522-
this.TextureConstructor = GLTextureArray3Float3D;
523-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
524-
this.formatValues = utils.erect3DArray3;
525-
return null;
526-
} else if (this.output[1] > 0) {
527-
this.TextureConstructor = GLTextureArray3Float2D;
528-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
529-
this.formatValues = utils.erect2DArray3;
530-
return null;
531-
} else {
532-
this.TextureConstructor = GLTextureArray3Float;
533-
this.renderStrategy = renderStrategy.FloatPixelToArray3;
534-
this.formatValues = utils.erectArray3;
535-
return null;
536-
}
537-
case 'Array(4)':
538-
if (this.output[2] > 0) {
539-
this.TextureConstructor = GLTextureArray4Float3D;
540-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
541-
this.formatValues = utils.erect3DArray4;
542-
return null;
543-
} else if (this.output[1] > 0) {
544-
this.TextureConstructor = GLTextureArray4Float2D;
545-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
546-
this.formatValues = utils.erect2DArray4;
547-
return null;
548-
} else {
549-
this.TextureConstructor = GLTextureArray4Float;
550-
this.renderStrategy = renderStrategy.FloatPixelToArray4;
551-
this.formatValues = utils.erectArray4;
552-
return null;
553-
}
509+
}
510+
case 'Array(2)': {
511+
if (this.output[2] > 0) {
512+
this.TextureConstructor = GLTextureArray2Float3D;
513+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
514+
this.formatValues = utils.erect3DArray2;
515+
return null;
516+
} else if (this.output[1] > 0) {
517+
this.TextureConstructor = GLTextureArray2Float2D;
518+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
519+
this.formatValues = utils.erect2DArray2;
520+
return null;
521+
} else {
522+
this.TextureConstructor = GLTextureArray2Float;
523+
this.renderStrategy = renderStrategy.FloatPixelToArray2;
524+
this.formatValues = utils.erectArray2;
525+
return null;
526+
}
527+
}
528+
case 'Array(3)': {
529+
if (this.output[2] > 0) {
530+
this.TextureConstructor = GLTextureArray3Float3D;
531+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
532+
this.formatValues = utils.erect3DArray3;
533+
return null;
534+
} else if (this.output[1] > 0) {
535+
this.TextureConstructor = GLTextureArray3Float2D;
536+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
537+
this.formatValues = utils.erect2DArray3;
538+
return null;
539+
} else {
540+
this.TextureConstructor = GLTextureArray3Float;
541+
this.renderStrategy = renderStrategy.FloatPixelToArray3;
542+
this.formatValues = utils.erectArray3;
543+
return null;
544+
}
545+
}
546+
case 'Array(4)': {
547+
if (this.output[2] > 0) {
548+
this.TextureConstructor = GLTextureArray4Float3D;
549+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
550+
this.formatValues = utils.erect3DArray4;
551+
return null;
552+
} else if (this.output[1] > 0) {
553+
this.TextureConstructor = GLTextureArray4Float2D;
554+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
555+
this.formatValues = utils.erect2DArray4;
556+
return null;
557+
} else {
558+
this.TextureConstructor = GLTextureArray4Float;
559+
this.renderStrategy = renderStrategy.FloatPixelToArray4;
560+
this.formatValues = utils.erectArray4;
561+
return null;
562+
}
563+
}
554564
}
555565
} else {
556566
switch (this.returnType) {
557567
case 'LiteralInteger':
558568
case 'Float':
559569
case 'Number':
560-
case 'Integer':
570+
case 'Integer': {
561571
if (this.output[2] > 0) {
562572
this.TextureConstructor = GLTextureFloat3D;
563573
this.renderStrategy = renderStrategy.FloatPixelTo3DFloat;
@@ -574,57 +584,61 @@ class GLKernel extends Kernel {
574584
this.formatValues = utils.erectFloat;
575585
return null;
576586
}
577-
case 'Array(2)':
578-
if (this.output[2] > 0) {
579-
this.TextureConstructor = GLTextureArray2Float3D;
580-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
581-
this.formatValues = utils.erect3DArray2;
582-
return null;
583-
} else if (this.output[1] > 0) {
584-
this.TextureConstructor = GLTextureArray2Float2D;
585-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
586-
this.formatValues = utils.erect2DArray2;
587-
return null;
588-
} else {
589-
this.TextureConstructor = GLTextureArray2Float;
590-
this.renderStrategy = renderStrategy.FloatPixelToArray2;
591-
this.formatValues = utils.erectArray2;
592-
return null;
593-
}
594-
case 'Array(3)':
595-
if (this.output[2] > 0) {
596-
this.TextureConstructor = GLTextureArray3Float3D;
597-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
598-
this.formatValues = utils.erect3DArray3;
599-
return null;
600-
} else if (this.output[1] > 0) {
601-
this.TextureConstructor = GLTextureArray3Float2D;
602-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
603-
this.formatValues = utils.erect2DArray3;
604-
return null;
605-
} else {
606-
this.TextureConstructor = GLTextureArray3Float;
607-
this.renderStrategy = renderStrategy.FloatPixelToArray3;
608-
this.formatValues = utils.erectArray3;
609-
return null;
610-
}
611-
case 'Array(4)':
612-
if (this.output[2] > 0) {
613-
this.TextureConstructor = GLTextureArray4Float3D;
614-
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
615-
this.formatValues = utils.erect3DArray4;
616-
return null;
617-
} else if (this.output[1] > 0) {
618-
this.TextureConstructor = GLTextureArray4Float2D;
619-
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
620-
this.formatValues = utils.erect2DArray4;
621-
return null;
622-
} else {
623-
this.TextureConstructor = GLTextureArray4Float;
624-
this.renderStrategy = renderStrategy.FloatPixelToArray4;
625-
this.formatValues = utils.erectArray4;
626-
return null;
627-
}
587+
}
588+
case 'Array(2)': {
589+
if (this.output[2] > 0) {
590+
this.TextureConstructor = GLTextureArray2Float3D;
591+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
592+
this.formatValues = utils.erect3DArray2;
593+
return null;
594+
} else if (this.output[1] > 0) {
595+
this.TextureConstructor = GLTextureArray2Float2D;
596+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
597+
this.formatValues = utils.erect2DArray2;
598+
return null;
599+
} else {
600+
this.TextureConstructor = GLTextureArray2Float;
601+
this.renderStrategy = renderStrategy.FloatPixelToArray2;
602+
this.formatValues = utils.erectArray2;
603+
return null;
604+
}
605+
}
606+
case 'Array(3)': {
607+
if (this.output[2] > 0) {
608+
this.TextureConstructor = GLTextureArray3Float3D;
609+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
610+
this.formatValues = utils.erect3DArray3;
611+
return null;
612+
} else if (this.output[1] > 0) {
613+
this.TextureConstructor = GLTextureArray3Float2D;
614+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
615+
this.formatValues = utils.erect2DArray3;
616+
return null;
617+
} else {
618+
this.TextureConstructor = GLTextureArray3Float;
619+
this.renderStrategy = renderStrategy.FloatPixelToArray3;
620+
this.formatValues = utils.erectArray3;
621+
return null;
622+
}
623+
}
624+
case 'Array(4)': {
625+
if (this.output[2] > 0) {
626+
this.TextureConstructor = GLTextureArray4Float3D;
627+
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
628+
this.formatValues = utils.erect3DArray4;
629+
return null;
630+
} else if (this.output[1] > 0) {
631+
this.TextureConstructor = GLTextureArray4Float2D;
632+
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
633+
this.formatValues = utils.erect2DArray4;
634+
return null;
635+
} else {
636+
this.TextureConstructor = GLTextureArray4Float;
637+
this.renderStrategy = renderStrategy.FloatPixelToArray4;
638+
this.formatValues = utils.erectArray4;
639+
return null;
640+
}
641+
}
628642
}
629643
}
630644
} else {
@@ -801,16 +815,7 @@ class GLKernel extends Kernel {
801815
}
802816

803817
renderTexture() {
804-
return new this.TextureConstructor({
805-
texture: this.outputTexture,
806-
size: this.texSize,
807-
dimensions: this.threadDim,
808-
output: this.output,
809-
context: this.context,
810-
kernel: this,
811-
internalFormat: this.getInternalFormat(),
812-
textureFormat: this.getTextureFormat(),
813-
});
818+
return this.texture.clone();
814819
}
815820
readPackedPixelsToUint8Array() {
816821
if (this.precision !== 'unsigned') throw new Error('Requires this.precision to be "unsigned"');
@@ -862,15 +867,7 @@ class GLKernel extends Kernel {
862867
result: this.renderOutput(),
863868
};
864869
for (let i = 0; i < this.subKernels.length; i++) {
865-
result[this.subKernels[i].property] = new this.TextureConstructor({
866-
texture: this.subKernelOutputTextures[i],
867-
size: this.texSize,
868-
dimensions: this.threadDim,
869-
output: this.output,
870-
context: this.context,
871-
internalFormat: this.getInternalFormat(),
872-
textureFormat: this.getTextureFormat(),
873-
}).toArray();
870+
result[this.subKernels[i].property] = this.mappedTextures[i].toArray();
874871
}
875872
return result;
876873
}
@@ -880,15 +877,7 @@ class GLKernel extends Kernel {
880877
result: this.renderOutput(),
881878
};
882879
for (let i = 0; i < this.subKernels.length; i++) {
883-
result[this.subKernels[i].property] = new this.TextureConstructor({
884-
texture: this.subKernelOutputTextures[i],
885-
size: this.texSize,
886-
dimensions: this.threadDim,
887-
output: this.output,
888-
context: this.context,
889-
internalFormat: this.getInternalFormat(),
890-
textureFormat: this.getTextureFormat(),
891-
});
880+
result[this.subKernels[i].property] = this.mappedTextures[i].clone();
892881
}
893882
return result;
894883
}

0 commit comments

Comments
 (0)