Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

benchmark.gl-benchmarks

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

benchmark.gl-benchmarks - npm Package Compare versions

Comparing version 0.1.7 to 1.0.0

31

benchmark/frameBuffer.js
var createFBO = require("gl-fbo");
var createShader = require("gl-shader");
var fillScreen = require("a-big-triangle");
var ndarray = require("ndarray");
var fill = require("ndarray-fill");
var createBuffer = require("gl-buffer");
var createVAO = require("gl-vao");

@@ -89,4 +90,14 @@ module.exports.loadFrameBuffer = function(gl){

opts.updateShader.uniforms.dims = prevState.shape;
fillScreen(gl)
var buf = createBuffer(gl, new Float32Array([-1, -1, -1, 4, 4, -1]));
triangleVAO = createVAO(gl, [
{ buffer: buf,
type: gl.FLOAT,
size: 2
}
]);
triangleVAO.bind();
gl.drawArrays(gl.TRIANGLES, 0, 3);
triangleVAO.unbind();
return opts;

@@ -97,5 +108,15 @@ }

//Render contents of buffer to screen
opts.drawShader.bind()
opts.drawShader.uniforms.buffer = opts.state[opts.currentFrame].color[0].bind()
fillScreen(gl)
opts.drawShader.bind();
opts.drawShader.uniforms.buffer = opts.state[opts.currentFrame].color[0].bind();
var buf = createBuffer(gl, new Float32Array([-1, -1, -1, 4, 4, -1]));
triangleVAO = createVAO(gl, [
{ buffer: buf,
type: gl.FLOAT,
size: 2
}
]);
triangleVAO.bind();
gl.drawArrays(gl.TRIANGLES, 0, 3);
triangleVAO.unbind();
}

1

benchmark/shader.js
var createShader = require("gl-shader");
var fillScreen = require("a-big-triangle");
var raymarchShader = require("../shader/raymarchShader.js");

@@ -4,0 +3,0 @@ var glMatrix = require("gl-matrix");

var createTexture = require("gl-texture2d");
var createShader = require("gl-shader");
var fillScreen = require("a-big-triangle");
var baboon = require("baboon-image");
var ndarray = require("ndarray")
var ndarray = require("ndarray");
var createBuffer = require("gl-buffer");
var createVAO = require("gl-vao");

@@ -10,6 +11,4 @@

//flips the textures
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
//Create texture
texture = createTexture(gl, baboon);

@@ -28,6 +27,6 @@ //Create shader

precision highp float;\
uniform sampler2D baboonTexture;\
uniform sampler2D tex;\
varying vec2 texCoord;\
void main() {\
gl_FragColor = texture2D(baboonTexture, texCoord);\
gl_FragColor = texture2D(tex, texCoord);\
}"

@@ -37,5 +36,10 @@ );

//Create texture
texture = createTexture(gl, baboon);
buffer = createBuffer(gl, [-1, -1, -1, 4, 4, -1]);
var options = {
shader: shader,
texture: texture
texture: texture,
buffer: buffer
};

@@ -48,8 +52,5 @@ return Object.assign({}, options);

//flips the textures
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
// gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true);
//Create texture
texture = createTexture(gl, texture);
//Create shader

@@ -67,6 +68,6 @@ shader = createShader(gl,

precision highp float;\
uniform sampler2D baboonTexture;\
uniform sampler2D tex;\
varying vec2 texCoord;\
void main() {\
gl_FragColor = texture2D(baboonTexture, texCoord);\
gl_FragColor = texture2D(tex, texCoord);\
}"

@@ -76,5 +77,9 @@ );

//Create texture
texture = createTexture(gl, texture);
var options = {
shader: shader,
texture: texture
texture: texture,
buffer: buffer
};

@@ -84,2 +89,18 @@ return Object.assign({}, options);

module.exports.renderTexture = function(gl, opts){
opts.shader.bind();
opts.shader.uniforms.tex = opts.texture.bind();
var buf = createBuffer(gl, new Float32Array([-1, -1, -1, 4, 4, -1]));
triangleVAO = createVAO(gl, [
{ buffer: buf,
type: gl.FLOAT,
size: 2
}
]);
triangleVAO.bind();
gl.drawArrays(gl.TRIANGLES, 0, 3);
triangleVAO.unbind();
}
module.exports.generateTexture = function(opts){

@@ -104,13 +125,2 @@ opts = opts || {};

return ndarray(new Uint8Array(data), [ width, height, channels ], [ channels, channels * width, 1 ], 0);
}
module.exports.renderTexture = function(gl, opts){
opts.shader.bind();
opts.shader.uniforms.baboonTexture = opts.texture.bind();
fillScreen(gl);
}

@@ -9,5 +9,5 @@ global.contextBench = require("./benchmark/context.js");

global.Benchmark = require("benchmark");
var gpuReport = require("./gpuReport.js");
module.exports.run = function(cb){

@@ -18,3 +18,3 @@ var suite = new Benchmark.Suite;

completedBenchmarks: 0,
remainingBenchmarks: 7,
remainingBenchmarks: 13,
gpu: gpuReport.collectGPUInfo(),

@@ -26,21 +26,15 @@ benchmarks: [],

var settings = {
"async": false,
"onStart": function(e) {
e.currentTarget.canvas = document.createElement("canvas");
e.currentTarget.canvas.width = 100;
e.currentTarget.canvas.height = 100;
async: false,
maxTime: 1,
onStart: function(e) {
e.currentTarget.canvas = setup();
},
"onCycle": function(e) {
e.currentTarget.canvas.remove();
resetGL(e.currentTarget.gl);
var ext = e.currentTarget.gl.getExtension("WEBGL_lose_context");
ext.loseContext();
e.currentTarget.canvas = document.createElement("canvas");
e.currentTarget.canvas.width = 100;
e.currentTarget.canvas.height = 100;
onCycle: function(e) {
teardown(e.currentTarget.canvas, e.currentTarget.gl);
e.currentTarget.canvas = setup();
}
};
// add tests
suite.add("shader", function() {
//Shader
suite.add("shader-init", function() {
this.gl = createContext(this.canvas, shaderBench.renderShader);

@@ -50,4 +44,20 @@ var renderOpts = shaderBench.loadShader(this.gl);

}, settings)
suite.add("shaderRayMarch", function() {
}, settings);
suite.add("shader-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, shaderBench.renderShader);
e.currentTarget.renderOpts = shaderBench.loadShader(e.currentTarget.gl);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
// Shader-RayMarch
suite.add("shaderRayMarch-init", function() {
this.gl = createContext(this.canvas, shaderBench.renderShaderRayMarch);

@@ -57,4 +67,20 @@ var renderOpts = shaderBench.loadShaderRayMarch(this.gl);

}, settings)
.add("geometry", function() {
}, settings);
suite.add("shaderRayMarch-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, shaderBench.renderShaderRayMarch);
e.currentTarget.renderOpts = shaderBench.loadShaderRayMarch(e.currentTarget.gl);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
//Geometry
suite.add("geometry-init", function() {
this.gl = createContext(this.canvas, geometryBench.renderGeometry);

@@ -64,4 +90,23 @@ var renderOpts = geometryBench.loadGeometry(this.gl, this.canvas.width, this.canvas.height);

}, settings)
.add("vertexArray", function() {
}, settings);
suite.add("geometry-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, geometryBench.renderGeometry);
e.currentTarget.renderOpts = geometryBench.loadGeometry(
e.currentTarget.gl,
e.currentTarget.canvas.width,
e.currentTarget.canvas.height);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
//Vertex Array
suite.add("vertexArray-init", function() {
this.gl = createContext(this.canvas, vertexArrayBench.renderVertexArray);

@@ -71,4 +116,20 @@ var renderOpts = vertexArrayBench.loadVertexArray(this.gl);

}, settings)
.add("texture", function() {
}, settings);
suite.add("vertexArray-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, vertexArrayBench.renderVertexArray);
e.currentTarget.renderOpts = vertexArrayBench.loadVertexArray(e.currentTarget.gl);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
//Texture
suite.add("texture-init", function() {
this.gl = createContext(this.canvas, textureBench.renderTexture);

@@ -78,4 +139,41 @@ var renderOpts = textureBench.loadBaboonTexture(this.gl);

}, settings)
.add("loadTextureSizes", function() {
}, settings);
suite.add("texture-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, textureBench.renderTexture);
e.currentTarget.renderOpts = textureBench.loadBaboonTexture(e.currentTarget.gl);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
//FrameBuffer
suite.add("frameBuffer-init", function() {
this.gl = createContext(this.canvas, frameBufferBench.renderFrameBuffer);
var renderOpts = frameBufferBench.loadFrameBuffer(this.gl);
this.gl.tick(renderOpts);
}, settings);
suite.add("frameBuffer-render", function() {
this.gl.tick(this.renderOpts);
}, {
async: false,
maxTime: 2,
onStart: function(e) {
e.currentTarget.canvas = setup();
e.currentTarget.gl = createContext(e.currentTarget.canvas, frameBufferBench.renderFrameBuffer);
e.currentTarget.renderOpts = frameBufferBench.loadFrameBuffer(e.currentTarget.gl);
},
onComplete: function(e){
teardown(e.currentTarget.canvas, e.currentTarget.gl);
}
});
// textureSizes
suite.add("loadTextureSizes", function() {
this.gl = createContext(this.canvas, textureBench.renderTexture);

@@ -93,11 +191,5 @@ var size = 8;

}
}, settings);
}, settings)
.add("frameBuffer", function() {
this.gl = createContext(this.canvas, frameBufferBench.renderFrameBuffer);
var renderOpts = frameBufferBench.loadFrameBuffer(this.gl);
this.gl.tick(renderOpts);
}, settings)
.on("cycle", function(e) {
suite.on("cycle", function(e) {
results.completedBenchmarks++;

@@ -115,17 +207,18 @@ results.remainingBenchmarks--;

cb(results);
})
.on("error", function(e) {
});
suite.on("error", function(e) {
console.error("error", e.target.error);
})
.run({
"async": false,
"maxTime": 3,
});
suite.run({
async: true,
maxTime: 2,
delay: 0.5,
});
}
function setup(){
var canvas = document.body.appendChild(document.createElement("canvas"));
canvas.width = 100;
canvas.height = 100;
function setup(opts){
opts = opts || {};
var canvas = document.createElement("canvas");
canvas.width = opts.width || 1;
canvas.height = opts.height || 1;
return canvas;

@@ -156,3 +249,3 @@ }

if (!gl) {
throw new Error("Unable to initialize headless-gl");
throw new Error("Unable to initialize gl");
}

@@ -159,0 +252,0 @@

{
"name": "benchmark.gl-benchmarks",
"version": "0.1.7",
"version": "1.0.0",
"description": "benchmarks used for generating benchmark.gl calibration library",

@@ -34,3 +34,2 @@ "keywords": [

"dependencies": {
"a-big-triangle": "^1.0.2",
"baboon-image": "^2.0.0",

@@ -37,0 +36,0 @@ "benchmark": "^2.1.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc