Skip to content

Commit 7e62639

Browse files
fix: #585 check for inaccurate results for very small kernel
fix: #585 add features.isSpeedTacticSupported and tests
1 parent 1955ad3 commit 7e62639

File tree

12 files changed

+159
-24
lines changed

12 files changed

+159
-24
lines changed

dist/gpu-browser-core.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.9.1
8-
* @date Tue Mar 24 2020 07:52:55 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.9.2
8+
* @date Mon Mar 30 2020 08:17:24 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -4615,6 +4615,29 @@ class GLKernel extends Kernel {
46154615
return result[0] === 2 && result[1] === 1511;
46164616
}
46174617

4618+
static getIsSpeedTacticSupported() {
4619+
function kernelFunction(value) {
4620+
return value[this.thread.x];
4621+
}
4622+
const kernel = new this(kernelFunction.toString(), {
4623+
context: this.testContext,
4624+
canvas: this.testCanvas,
4625+
validate: false,
4626+
output: [4],
4627+
returnType: 'Number',
4628+
precision: 'unsigned',
4629+
tactic: 'speed',
4630+
});
4631+
const args = [
4632+
[0, 1, 2, 3]
4633+
];
4634+
kernel.build.apply(kernel, args);
4635+
kernel.run.apply(kernel, args);
4636+
const result = kernel.renderOutput();
4637+
kernel.destroy(true);
4638+
return Math.round(result[0]) === 0 && Math.round(result[1]) === 1 && Math.round(result[2]) === 2 && Math.round(result[3]) === 3;
4639+
}
4640+
46184641
static get testCanvas() {
46194642
throw new Error(`"testCanvas" not defined on ${ this.name }`);
46204643
}
@@ -4629,6 +4652,7 @@ class GLKernel extends Kernel {
46294652
return Object.freeze({
46304653
isFloatRead: this.getIsFloatRead(),
46314654
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
4655+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
46324656
isTextureFloat: this.getIsTextureFloat(),
46334657
isDrawBuffers,
46344658
kernelMap: isDrawBuffers,
@@ -5371,6 +5395,7 @@ class GLKernel extends Kernel {
53715395
}
53725396
getVariablePrecisionString(textureSize = this.texSize, tactic = this.tactic, isInt = false) {
53735397
if (!tactic) {
5398+
if (!this.constructor.features.isSpeedTacticSupported) return 'highp';
53745399
const low = this.constructor.features[isInt ? 'lowIntPrecision' : 'lowFloatPrecision'];
53755400
const medium = this.constructor.features[isInt ? 'mediumIntPrecision' : 'mediumFloatPrecision'];
53765401
const high = this.constructor.features[isInt ? 'highIntPrecision' : 'highFloatPrecision'];
@@ -12749,6 +12774,7 @@ class WebGL2Kernel extends WebGLKernel {
1274912774
return Object.freeze({
1275012775
isFloatRead: this.getIsFloatRead(),
1275112776
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
12777+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
1275212778
kernelMap: true,
1275312779
isTextureFloat: true,
1275412780
isDrawBuffers: true,
@@ -12767,10 +12793,6 @@ class WebGL2Kernel extends WebGLKernel {
1276712793
return true;
1276812794
}
1276912795

12770-
static getIsIntegerDivisionAccurate() {
12771-
return super.getIsIntegerDivisionAccurate();
12772-
}
12773-
1277412796
static getChannelCount() {
1277512797
return testContext.getParameter(testContext.MAX_DRAW_BUFFERS);
1277612798
}

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 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: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.9.1
8-
* @date Tue Mar 24 2020 07:52:55 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.9.2
8+
* @date Mon Mar 30 2020 08:17:24 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -9068,6 +9068,29 @@ class GLKernel extends Kernel {
90689068
return result[0] === 2 && result[1] === 1511;
90699069
}
90709070

9071+
static getIsSpeedTacticSupported() {
9072+
function kernelFunction(value) {
9073+
return value[this.thread.x];
9074+
}
9075+
const kernel = new this(kernelFunction.toString(), {
9076+
context: this.testContext,
9077+
canvas: this.testCanvas,
9078+
validate: false,
9079+
output: [4],
9080+
returnType: 'Number',
9081+
precision: 'unsigned',
9082+
tactic: 'speed',
9083+
});
9084+
const args = [
9085+
[0, 1, 2, 3]
9086+
];
9087+
kernel.build.apply(kernel, args);
9088+
kernel.run.apply(kernel, args);
9089+
const result = kernel.renderOutput();
9090+
kernel.destroy(true);
9091+
return Math.round(result[0]) === 0 && Math.round(result[1]) === 1 && Math.round(result[2]) === 2 && Math.round(result[3]) === 3;
9092+
}
9093+
90719094
static get testCanvas() {
90729095
throw new Error(`"testCanvas" not defined on ${ this.name }`);
90739096
}
@@ -9082,6 +9105,7 @@ class GLKernel extends Kernel {
90829105
return Object.freeze({
90839106
isFloatRead: this.getIsFloatRead(),
90849107
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
9108+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
90859109
isTextureFloat: this.getIsTextureFloat(),
90869110
isDrawBuffers,
90879111
kernelMap: isDrawBuffers,
@@ -9824,6 +9848,7 @@ class GLKernel extends Kernel {
98249848
}
98259849
getVariablePrecisionString(textureSize = this.texSize, tactic = this.tactic, isInt = false) {
98269850
if (!tactic) {
9851+
if (!this.constructor.features.isSpeedTacticSupported) return 'highp';
98279852
const low = this.constructor.features[isInt ? 'lowIntPrecision' : 'lowFloatPrecision'];
98289853
const medium = this.constructor.features[isInt ? 'mediumIntPrecision' : 'mediumFloatPrecision'];
98299854
const high = this.constructor.features[isInt ? 'highIntPrecision' : 'highFloatPrecision'];
@@ -17202,6 +17227,7 @@ class WebGL2Kernel extends WebGLKernel {
1720217227
return Object.freeze({
1720317228
isFloatRead: this.getIsFloatRead(),
1720417229
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
17230+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
1720517231
kernelMap: true,
1720617232
isTextureFloat: true,
1720717233
isDrawBuffers: true,
@@ -17220,10 +17246,6 @@ class WebGL2Kernel extends WebGLKernel {
1722017246
return true;
1722117247
}
1722217248

17223-
static getIsIntegerDivisionAccurate() {
17224-
return super.getIsIntegerDivisionAccurate();
17225-
}
17226-
1722717249
static getChannelCount() {
1722817250
return testContext.getParameter(testContext.MAX_DRAW_BUFFERS);
1722917251
}

dist/gpu-browser.min.js

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

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.9.1",
3+
"version": "2.9.2",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=8.0.0"

src/backend/gl/kernel.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,29 @@ class GLKernel extends Kernel {
7575
return result[0] === 2 && result[1] === 1511;
7676
}
7777

78+
static getIsSpeedTacticSupported() {
79+
function kernelFunction(value) {
80+
return value[this.thread.x];
81+
}
82+
const kernel = new this(kernelFunction.toString(), {
83+
context: this.testContext,
84+
canvas: this.testCanvas,
85+
validate: false,
86+
output: [4],
87+
returnType: 'Number',
88+
precision: 'unsigned',
89+
tactic: 'speed',
90+
});
91+
const args = [
92+
[0, 1, 2, 3]
93+
];
94+
kernel.build.apply(kernel, args);
95+
kernel.run.apply(kernel, args);
96+
const result = kernel.renderOutput();
97+
kernel.destroy(true);
98+
return Math.round(result[0]) === 0 && Math.round(result[1]) === 1 && Math.round(result[2]) === 2 && Math.round(result[3]) === 3;
99+
}
100+
78101
/**
79102
* @abstract
80103
*/
@@ -95,6 +118,7 @@ class GLKernel extends Kernel {
95118
return Object.freeze({
96119
isFloatRead: this.getIsFloatRead(),
97120
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
121+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
98122
isTextureFloat: this.getIsTextureFloat(),
99123
isDrawBuffers,
100124
kernelMap: isDrawBuffers,
@@ -942,6 +966,7 @@ class GLKernel extends Kernel {
942966
}
943967
getVariablePrecisionString(textureSize = this.texSize, tactic = this.tactic, isInt = false) {
944968
if (!tactic) {
969+
if (!this.constructor.features.isSpeedTacticSupported) return 'highp';
945970
const low = this.constructor.features[isInt ? 'lowIntPrecision' : 'lowFloatPrecision'];
946971
const medium = this.constructor.features[isInt ? 'mediumIntPrecision' : 'mediumFloatPrecision'];
947972
const high = this.constructor.features[isInt ? 'highIntPrecision' : 'highFloatPrecision'];

src/backend/web-gl2/kernel.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class WebGL2Kernel extends WebGLKernel {
7171
return Object.freeze({
7272
isFloatRead: this.getIsFloatRead(),
7373
isIntegerDivisionAccurate: this.getIsIntegerDivisionAccurate(),
74+
isSpeedTacticSupported: this.getIsSpeedTacticSupported(),
7475
kernelMap: true,
7576
isTextureFloat: true,
7677
isDrawBuffers: true,
@@ -89,10 +90,6 @@ class WebGL2Kernel extends WebGLKernel {
8990
return true;
9091
}
9192

92-
static getIsIntegerDivisionAccurate() {
93-
return super.getIsIntegerDivisionAccurate();
94-
}
95-
9693
static getChannelCount() {
9794
return testContext.getParameter(testContext.MAX_DRAW_BUFFERS);
9895
}

src/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ export interface IKernelFeatures {
373373
isFloatRead: boolean;
374374
kernelMap: boolean;
375375
isIntegerDivisionAccurate: boolean;
376+
isSpeedTacticSupported: boolean;
376377
isTextureFloat: boolean;
377378
isDrawBuffers: boolean;
378379
channelCount: number;

test/all.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
<script type="module" src="issues/560-minification-madness.js"></script>
178178
<script type="module" src="issues/564-boolean.js"></script>
179179
<script type="module" src="issues/567-wrong-modulus.js"></script>
180+
<script type="module" src="issues/585-inaccurate-lookups.js"></script>
180181
<script type="module" src="issues/586-unable-to-resize.js"></script>
181182
<script type="module" src="issues/91-create-kernel-map-array.js"></script>
182183
<script type="module" src="issues/96-param-names.js"></script>

0 commit comments

Comments
 (0)