Merge pull request #200 from Richard-Mathie/195-texture-read-error

fixes #195 texture reading in 2d and 3d
This commit is contained in:
Fazli Sapuan 2017-10-07 21:39:41 +08:00 committed by GitHub
commit c6ea5ef4cb
8 changed files with 72 additions and 20 deletions

View File

@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.1
* @date Wed Oct 04 2017 15:27:29 GMT-0400 (EDT)
* @date Sat Oct 07 2017 14:26:08 GMT+0100 (BST)
*
* @license MIT
* The MIT License

2
bin/gpu-core.min.js vendored
View File

@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.1
* @date Wed Oct 04 2017 15:27:29 GMT-0400 (EDT)
* @date Sat Oct 07 2017 14:26:08 GMT+0100 (BST)
*
* @license MIT
* The MIT License

View File

@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 1.0.0-rc.1
* @date Wed Oct 04 2017 15:27:29 GMT-0400 (EDT)
* @date Sat Oct 07 2017 14:26:09 GMT+0100 (BST)
*
* @license MIT
* The MIT License
@ -3219,7 +3219,8 @@ module.exports = function (_KernelBase) {
case 'Texture':
{
var inputTexture = value;
var _dim = utils.getDimensions(inputTexture.output, true);
var _dim = utils.getDimensions(inputTexture, true);
var _size = inputTexture.size;
if (inputTexture.texture === this.outputTexture) {
@ -4597,15 +4598,15 @@ var types = {
eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
prefix: new TokenType("!/~", {beforeExpr: true, prefix: true, startsExpr: true}),
logicalOR: binop("||", 1),
logicalAND: binop("&&", 2),
bitwiseOR: binop("|", 3),
bitwiseXOR: binop("^", 4),
bitwiseAND: binop("&", 5),
equality: binop("==/!=", 6),
relational: binop("</>", 7),
bitShift: binop("<</>>", 8),
equality: binop("==/!=/===/!==", 6),
relational: binop("</>/<=/>=", 7),
bitShift: binop("<</>>/>>>", 8),
plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
modulo: binop("%", 10),
star: binop("*", 10),
@ -4853,7 +4854,7 @@ Parser.prototype.parse = function parse () {
var pp = Parser.prototype;
var literal = /^(?:'((?:[^']|\.)*)'|"((?:[^"]|\.)*)"|;)/;
var literal = /^(?:'((?:\\.|[^'])*?)'|"((?:\\.|[^"])*?)"|;)/;
pp.strictDirective = function(start) {
var this$1 = this;
@ -6425,7 +6426,7 @@ pp$3.parseTemplate = function(ref) {
pp$3.isAsyncProp = function(prop) {
return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
(this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL) &&
(this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL || this.type.keyword) &&
!lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
};
@ -7219,7 +7220,7 @@ pp$8.readToken_caret = function() {
pp$8.readToken_plus_min = function(code) {
var next = this.input.charCodeAt(this.pos + 1);
if (next === code) {
if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
if (next == 45 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 62 &&
(this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
this.skipLineComment(3);
this.skipSpace();
@ -7239,9 +7240,8 @@ pp$8.readToken_lt_gt = function(code) {
if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
return this.finishOp(types.bitShift, size)
}
if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
if (next == 33 && code == 60 && !this.inModule && this.input.charCodeAt(this.pos + 2) == 45 &&
this.input.charCodeAt(this.pos + 3) == 45) {
if (this.inModule) { this.unexpected(); }
this.skipLineComment(4);
this.skipSpace();
return this.nextToken()
@ -7671,7 +7671,7 @@ pp$8.readWord = function() {
};
var version = "5.1.1";
var version = "5.1.2";
function parse(input, options) {

8
bin/gpu.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -650,7 +650,8 @@ module.exports = class WebGLKernel extends KernelBase {
case 'Texture':
{
const inputTexture = value;
const dim = utils.getDimensions(inputTexture.output, true);
const dim = utils.getDimensions(inputTexture, true);
const size = inputTexture.size;
if (inputTexture.texture === this.outputTexture) {
@ -1196,4 +1197,4 @@ module.exports = class WebGLKernel extends KernelBase {
addFunction(fn) {
this.functionBuilder.addFunction(null, fn);
}
};
};

View File

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>GPU.JS : Read from Texture 2D</title>
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../bin/gpu.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../../node_modules/qunit-assert-close/qunit-assert-close.js"></script>
<script src="../../src/issues/195-read-from-texture2d.js"></script>
</body>
</html>

View File

@ -47,5 +47,6 @@
<script src="../src/issues/147-missing-constant.js"></script>
<script src="../src/issues/152-for-vars.js"></script>
<script src="../src/issues/159-3d.js"></script>
<script src="../src/issues/195-read-from-texture2d.js"></script>
</body>
</html>

View File

@ -0,0 +1,32 @@
QUnit.test( "Issue #195 Read from Texture 2D", function() {
var matrixSize = 4;
var A = Array.apply(null, Array(matrixSize*matrixSize)).map(function (_, i) {return i;});
A = splitArray(A, matrixSize)
const gpu = new GPU({ mode: 'gpu' });
function make_kernel(gpu) {
return gpu.createKernel(function(a){
return a[this.thread.y][this.thread.x];
}).setOutput([matrixSize, matrixSize]);
};
const no_texture = make_kernel(gpu);
const texture = make_kernel(gpu).setOutputToTexture(true);
const result = no_texture(A);
const textureResult = texture(A).toArray(gpu);
function splitArray(array, part) {
var result = [];
for(var i = 0; i < array.length; i += part) {
result.push(array.slice(i, i + part));
}
return result;
};
QUnit.assert.deepEqual(result, A);
QUnit.assert.deepEqual(textureResult, A);
QUnit.assert.deepEqual(textureResult, result);
});