Skip to content

Commit

Permalink
Merge 80d1bd7 into b842628
Browse files Browse the repository at this point in the history
  • Loading branch information
1chandu committed Oct 17, 2019
2 parents b842628 + 80d1bd7 commit b773f1b
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/gpu-table/README.md
@@ -0,0 +1,3 @@
# @deck.gl/gpu-table

This is temporary module placed here just for easier development, should be removed before an official release.
12 changes: 12 additions & 0 deletions modules/gpu-table/bundle.js
@@ -0,0 +1,12 @@
const gpuTable = require('./src');

/* global window, global */
const _global = typeof window === 'undefined' ? global : window;
const deck = _global.deck || {};

// Check if peer dependencies are included
if (!deck.Layer) {
throw new Error('@deck.gl/core is not found');
}

module.exports = Object.assign(deck, gpuTable);
35 changes: 35 additions & 0 deletions modules/gpu-table/package.json
@@ -0,0 +1,35 @@
{
"name": "@deck.gl/gpu-table",
"description": "deck.gl gpu-table",
"license": "MIT",
"version": "7.4.0-alpha.2",
"publishConfig": {
"access": "public"
},
"keywords": [
"webgl",
"visualization",
"layer"
],
"repository": {
"type": "git",
"url": "https://github.com/uber/deck.gl.git"
},
"main": "dist/es5/index.js",
"module": "dist/esm/index.js",
"esnext": "dist/es6/index.js",
"files": [
"dist",
"src",
"dist.min.js"
],
"sideEffects": false,
"scripts": {
"build-bundle": "webpack --config ../../scripts/bundle.config.js",
"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
},
"peerDependencies": {
"@deck.gl/core": "^7.3.3",
"@luma.gl/core": "^7.3.2"
}
}
61 changes: 61 additions & 0 deletions modules/gpu-table/src/gpu-table.js
@@ -0,0 +1,61 @@
// Copyright (c) 2015 - 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import {Buffer, _Accessor as Accessor} from '@luma.gl/core';
import {log} from '@deck.gl/core';

export default class GPUTable {
constructor(gl, opts) {
this.gl = gl;
this.accessors = {};
this.buffers = {};
if ('columns' in opts) {
this.addColumns(opts.columns);
}
}

// Takes an object where key is the name of the colum and value is an object {data, type, size, ..}
addColumns(columns) {
for (const name in columns) {
log.assert(!this.buffers[name]);
const {accessor, buffer, data} = columns[name];
log.assert(buffer || data);
this.accessors[name] = accessor || Accessor.resolve(columns[name]);
this.buffers[name] =
buffer ||
new Buffer(this.gl, {
data: columns[name].data,
accessor: this.accessors[name]
});
}
}

// takes one ora array of column names to be deleted
removeColumns(name) {
const names = Array.isArray(name) ? name : [name];
for (const n of names) {
if (n in this.buffers) {
this.buffers[n].delete();
delete this.buffers[n];
delete this.accessors[n];
}
}
}
}
116 changes: 116 additions & 0 deletions modules/gpu-table/src/gpu-transform.js
@@ -0,0 +1,116 @@
// Copyright (c) 2015 - 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

// should create a new column based on mapping and gpuTable.
import {Buffer, Transform, _Accessor as Accessor} from '@luma.gl/core';
import {log} from '@deck.gl/core';
import GL from '@luma.gl/constants';

export default function gpuTransform(gpuTable, mappings) {
// TODO: For now hardcoding everything for position
const longitudeBuffer = gpuTable.buffers.longitude;
const latitudeBuffer = gpuTable.buffers.latitude;

const byteLength = longitudeBuffer.byteLength * 3;
const positionAccessor = Accessor.resolve({size: 3, type: GL.FLOAT});
const positionBuffer = new Buffer(gpuTable.gl, {byteLength, accessor: positionAccessor});
const targetAccessors = {position: positionAccessor};

const {inject, varyings} = getShaderOptions(gpuTable, mappings, targetAccessors);
const transform = new Transform(gpuTable.gl, {
sourceBuffers: {
longitude: longitudeBuffer,
latitude: latitudeBuffer
},
feedbackBuffers: {
position: positionBuffer
},
varyings,
inject,
elementCount: longitudeBuffer.getElementCount(),
vs: 'void main() {}'
});
transform.run();
transform.delete();
gpuTable.addColumns({position: {buffer: positionBuffer, accessor: positionAccessor}});
return;
}

function getShaderOptions(gpuTable, mappings, targetAccessors) {
let columns = [];
let glslCode = '';
let declarations = '';
const varyings = [];
for (const target in mappings) {
if (mappings[target].sourceColumns) {
columns = columns.concat(mappings[target].sourceColumns);
}
glslCode = `${glslCode}${mappings[target].glslCode}\n`;
const accessor = targetAccessors[target];
const type = getType(accessor);
declarations = `${declarations}varying ${type} ${target};\n`;
varyings.push(target);
}

// filter out duplicates
columns = new Set(columns);
columns.forEach(column => {
const accessor = gpuTable.accessors[column];
const type = getType(accessor);
declarations = `${declarations}attribute ${type} ${column};\n`;
});
return {
inject: {
'vs:#decl': declarations,
'vs:#main-start': glslCode
},
varyings
};
}

// TODO
// Utility methods that can be moved to some global scope
// or just any existing luma.gl shadertools methods

function getType(accessor) {
switch (accessor.type) {
case GL.FLOAT:
switch (accessor.size) {
case 1:
return 'float';
case 2:
return 'vec2';
case 3:
return 'vec3';
case 4:
return 'vec4';
default:
// invalid size
log.assert(false);
break;
}
break;
default:
// TODO: add other cases
log.assert(false);
break;
}
return null;
}
1 change: 1 addition & 0 deletions modules/gpu-table/src/index.js
@@ -0,0 +1 @@
export {default as GPUTable} from './gpu-table';
1 change: 1 addition & 0 deletions test/browser.js
Expand Up @@ -51,6 +51,7 @@ test('deck.gl', t => {
require('./modules/aggregation-layers/utils/grid-aggregation-utils.spec');
require('./modules/aggregation-layers/heatmap-layer/heatmap-layer.spec');
require('./modules/core/lib/pick-layers.spec');
require('./modules/gpu-table/gpu-transform.spec');

require('./render');
require('./interaction');
Expand Down
101 changes: 101 additions & 0 deletions test/modules/gpu-table/gpu-table.spec.js
@@ -0,0 +1,101 @@
// Copyright (c) 2015 - 2019 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import test from 'tape-catch';

// import GPUTable from '@deck.gl/gpu-table';
// TODO: fix import path
import GPUTable from '../../../modules/gpu-table/src/gpu-table';

import {isWebGL2} from '@luma.gl/core';
import {gl} from '@deck.gl/test-utils';

test('GPUTable#imports', t => {
t.equals(typeof GPUTable, 'function', 'GPUTable import successful');
t.end();
});

test('GPUTable#addColumns', t => {
const LONGITUDES = [1.0, 2.0, 3.0];
const LATITUDES = [11.0, 12.0, 13.0];
const RADIUS = [10, 20, 30];
const gpuTable = new GPUTable(gl, {
columns: {
longitude: {data: new Float32Array(LONGITUDES)},
latitude: {data: new Float32Array(LATITUDES)}
}
});
gpuTable.addColumns({
radius: {data: new Float32Array(RADIUS)}
});

t.ok(gpuTable.buffers.longitude, 'should create longitude Buffer');
t.ok(gpuTable.buffers.latitude, 'should create latitude Buffer');
t.ok(gpuTable.buffers.radius, 'should create radius Buffer');
t.ok(gpuTable.accessors.longitude, 'should create longitude Accessor');
t.ok(gpuTable.accessors.latitude, 'should create latitude Accessor');
t.ok(gpuTable.accessors.radius, 'should create radius Accessor');

// Buffer.getData() is WebGL2 only
if (isWebGL2(gl)) {
t.deepEqual(
gpuTable.buffers.longitude.getData(),
LONGITUDES,
'should setup correct data for longitude Buffer'
);
t.deepEqual(
gpuTable.buffers.latitude.getData(),
LATITUDES,
'should setup correct data for longitude Buffer'
);
t.deepEqual(
gpuTable.buffers.radius.getData(),
RADIUS,
'should setup correct data for longitude Buffer'
);
}
t.end();
});

test('GPUTable#removeColumns', t => {
const LONGITUDES = [1.0, 2.0, 3.0];
const LATITUDES = [11.0, 12.0, 13.0];
const RADIUS = [10, 20, 30];
const gpuTable = new GPUTable(gl, {
columns: {
longitude: {data: new Float32Array(LONGITUDES)},
latitude: {data: new Float32Array(LATITUDES)}
}
});
gpuTable.addColumns({
radius: {data: new Float32Array(RADIUS)}
});

gpuTable.removeColumns(['longitude', 'radius']);

t.notOk(gpuTable.buffers.longitude, 'should have deleted longitude Buffer');
t.ok(gpuTable.buffers.latitude, "shouldn't delete latitude Buffer");
t.notOk(gpuTable.buffers.radius, 'should have deleted radius Buffer');

gpuTable.removeColumns('latitude');
t.notOk(gpuTable.buffers.latitude, 'should have deleted latitude Buffer');

t.end();
});

0 comments on commit b773f1b

Please sign in to comment.