Skip to content

Commit

Permalink
fix: Experiment with end to end working strategy and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robertleeplummerjr committed Dec 20, 2019
1 parent bcae4ba commit d221e97
Show file tree
Hide file tree
Showing 16 changed files with 984 additions and 603 deletions.
504 changes: 304 additions & 200 deletions dist/gpu-browser-core.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/gpu-browser-core.min.js

Large diffs are not rendered by default.

504 changes: 304 additions & 200 deletions dist/gpu-browser.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/gpu-browser.min.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/backend/gl/kernel-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function toStringWithoutUtils(fn) {

/**
*
* @param {Kernel} Kernel
* @param {GLKernel} Kernel
* @param {KernelVariable[]} args
* @param {Kernel} originKernel
* @param {string} [setupContextString]
Expand Down Expand Up @@ -192,19 +192,19 @@ function glKernelString(Kernel, args, originKernel, setupContextString, destroyC
context.reset();
if (kernel.renderKernels) {
const results = kernel.renderKernels();
const textureName = context.getContextVariableName(kernel.outputTexture);
const textureName = context.getContextVariableName(kernel.texture.texture);
result.push(` return {
result: {
texture: ${ textureName },
type: '${ results.result.type }',
toArray: ${ getToArrayString(results.result, textureName) }
},`);
const { subKernels, subKernelOutputTextures } = kernel;
const { subKernels, mappedTextures } = kernel;
for (let i = 0; i < subKernels.length; i++) {
const texture = subKernelOutputTextures[i];
const texture = mappedTextures[i];
const subKernel = subKernels[i];
const subKernelResult = results[subKernel.property];
const subKernelTextureName = context.getContextVariableName(texture);
const subKernelTextureName = context.getContextVariableName(texture.texture);
result.push(`
${subKernel.property}: {
texture: ${ subKernelTextureName },
Expand All @@ -215,7 +215,7 @@ function glKernelString(Kernel, args, originKernel, setupContextString, destroyC
result.push(` };`);
} else {
const rendered = kernel.renderOutput();
const textureName = context.getContextVariableName(kernel.outputTexture);
const textureName = context.getContextVariableName(kernel.texture.texture);
result.push(` return {
texture: ${ textureName },
type: '${ rendered.type }',
Expand Down
253 changes: 121 additions & 132 deletions src/backend/gl/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ class GLKernel extends Kernel {
super(source, settings);
this.transferValues = null;
this.formatValues = null;
/**
*
* @type {Texture}
*/
this.TextureConstructor = null;
this.renderOutput = null;
this.renderRawOutput = null;
Expand All @@ -314,6 +318,8 @@ class GLKernel extends Kernel {
this.compiledFragmentShader = null;
this.compiledVertexShader = null;
this.switchingKernels = null;
this.prevInput = null;
this.prevMappedInputs = null;
}

checkTextureSize() {
Expand Down Expand Up @@ -483,7 +489,7 @@ class GLKernel extends Kernel {
case 'LiteralInteger':
case 'Float':
case 'Number':
case 'Integer':
case 'Integer': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureMemoryOptimized3D;
this.renderStrategy = renderStrategy.MemoryOptimizedFloatPixelToMemoryOptimized3DFloat;
Expand All @@ -500,64 +506,68 @@ class GLKernel extends Kernel {
this.formatValues = utils.erectMemoryOptimizedFloat;
return null;
}
case 'Array(2)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray2Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
this.formatValues = utils.erect3DArray2;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray2Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
this.formatValues = utils.erect2DArray2;
return null;
} else {
this.TextureConstructor = GLTextureArray2Float;
this.renderStrategy = renderStrategy.FloatPixelToArray2;
this.formatValues = utils.erectArray2;
return null;
}
case 'Array(3)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray3Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
this.formatValues = utils.erect3DArray3;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray3Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
this.formatValues = utils.erect2DArray3;
return null;
} else {
this.TextureConstructor = GLTextureArray3Float;
this.renderStrategy = renderStrategy.FloatPixelToArray3;
this.formatValues = utils.erectArray3;
return null;
}
case 'Array(4)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray4Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
this.formatValues = utils.erect3DArray4;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray4Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
this.formatValues = utils.erect2DArray4;
return null;
} else {
this.TextureConstructor = GLTextureArray4Float;
this.renderStrategy = renderStrategy.FloatPixelToArray4;
this.formatValues = utils.erectArray4;
return null;
}
}
case 'Array(2)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray2Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
this.formatValues = utils.erect3DArray2;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray2Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
this.formatValues = utils.erect2DArray2;
return null;
} else {
this.TextureConstructor = GLTextureArray2Float;
this.renderStrategy = renderStrategy.FloatPixelToArray2;
this.formatValues = utils.erectArray2;
return null;
}
}
case 'Array(3)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray3Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
this.formatValues = utils.erect3DArray3;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray3Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
this.formatValues = utils.erect2DArray3;
return null;
} else {
this.TextureConstructor = GLTextureArray3Float;
this.renderStrategy = renderStrategy.FloatPixelToArray3;
this.formatValues = utils.erectArray3;
return null;
}
}
case 'Array(4)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray4Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
this.formatValues = utils.erect3DArray4;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray4Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
this.formatValues = utils.erect2DArray4;
return null;
} else {
this.TextureConstructor = GLTextureArray4Float;
this.renderStrategy = renderStrategy.FloatPixelToArray4;
this.formatValues = utils.erectArray4;
return null;
}
}
}
} else {
switch (this.returnType) {
case 'LiteralInteger':
case 'Float':
case 'Number':
case 'Integer':
case 'Integer': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureFloat3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DFloat;
Expand All @@ -574,57 +584,61 @@ class GLKernel extends Kernel {
this.formatValues = utils.erectFloat;
return null;
}
case 'Array(2)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray2Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
this.formatValues = utils.erect3DArray2;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray2Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
this.formatValues = utils.erect2DArray2;
return null;
} else {
this.TextureConstructor = GLTextureArray2Float;
this.renderStrategy = renderStrategy.FloatPixelToArray2;
this.formatValues = utils.erectArray2;
return null;
}
case 'Array(3)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray3Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
this.formatValues = utils.erect3DArray3;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray3Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
this.formatValues = utils.erect2DArray3;
return null;
} else {
this.TextureConstructor = GLTextureArray3Float;
this.renderStrategy = renderStrategy.FloatPixelToArray3;
this.formatValues = utils.erectArray3;
return null;
}
case 'Array(4)':
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray4Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
this.formatValues = utils.erect3DArray4;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray4Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
this.formatValues = utils.erect2DArray4;
return null;
} else {
this.TextureConstructor = GLTextureArray4Float;
this.renderStrategy = renderStrategy.FloatPixelToArray4;
this.formatValues = utils.erectArray4;
return null;
}
}
case 'Array(2)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray2Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray2;
this.formatValues = utils.erect3DArray2;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray2Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray2;
this.formatValues = utils.erect2DArray2;
return null;
} else {
this.TextureConstructor = GLTextureArray2Float;
this.renderStrategy = renderStrategy.FloatPixelToArray2;
this.formatValues = utils.erectArray2;
return null;
}
}
case 'Array(3)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray3Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray3;
this.formatValues = utils.erect3DArray3;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray3Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray3;
this.formatValues = utils.erect2DArray3;
return null;
} else {
this.TextureConstructor = GLTextureArray3Float;
this.renderStrategy = renderStrategy.FloatPixelToArray3;
this.formatValues = utils.erectArray3;
return null;
}
}
case 'Array(4)': {
if (this.output[2] > 0) {
this.TextureConstructor = GLTextureArray4Float3D;
this.renderStrategy = renderStrategy.FloatPixelTo3DArray4;
this.formatValues = utils.erect3DArray4;
return null;
} else if (this.output[1] > 0) {
this.TextureConstructor = GLTextureArray4Float2D;
this.renderStrategy = renderStrategy.FloatPixelTo2DArray4;
this.formatValues = utils.erect2DArray4;
return null;
} else {
this.TextureConstructor = GLTextureArray4Float;
this.renderStrategy = renderStrategy.FloatPixelToArray4;
this.formatValues = utils.erectArray4;
return null;
}
}
}
}
} else {
Expand Down Expand Up @@ -801,16 +815,7 @@ class GLKernel extends Kernel {
}

renderTexture() {
return new this.TextureConstructor({
texture: this.outputTexture,
size: this.texSize,
dimensions: this.threadDim,
output: this.output,
context: this.context,
kernel: this,
internalFormat: this.getInternalFormat(),
textureFormat: this.getTextureFormat(),
});
return this.texture.clone();
}
readPackedPixelsToUint8Array() {
if (this.precision !== 'unsigned') throw new Error('Requires this.precision to be "unsigned"');
Expand Down Expand Up @@ -862,15 +867,7 @@ class GLKernel extends Kernel {
result: this.renderOutput(),
};
for (let i = 0; i < this.subKernels.length; i++) {
result[this.subKernels[i].property] = new this.TextureConstructor({
texture: this.subKernelOutputTextures[i],
size: this.texSize,
dimensions: this.threadDim,
output: this.output,
context: this.context,
internalFormat: this.getInternalFormat(),
textureFormat: this.getTextureFormat(),
}).toArray();
result[this.subKernels[i].property] = this.mappedTextures[i].toArray();
}
return result;
}
Expand All @@ -880,15 +877,7 @@ class GLKernel extends Kernel {
result: this.renderOutput(),
};
for (let i = 0; i < this.subKernels.length; i++) {
result[this.subKernels[i].property] = new this.TextureConstructor({
texture: this.subKernelOutputTextures[i],
size: this.texSize,
dimensions: this.threadDim,
output: this.output,
context: this.context,
internalFormat: this.getInternalFormat(),
textureFormat: this.getTextureFormat(),
});
result[this.subKernels[i].property] = this.mappedTextures[i].clone();
}
return result;
}
Expand Down
Loading

0 comments on commit d221e97

Please sign in to comment.