4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.0.0-rc.19
8
- * @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
7
+ * @version 2.0.0-rc.20
8
+ * @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
@@ -717,7 +717,7 @@ class CPUFunctionNode extends FunctionNode {
717
717
}
718
718
719
719
astVariableDeclaration ( varDecNode , retArr ) {
720
- if ( varDecNode . kind === 'var' ) {
720
+ if ( varDecNode . kind === 'var' && this . warnVarUsage ) {
721
721
this . varWarn ( ) ;
722
722
}
723
723
retArr . push ( `${ varDecNode . kind } ` ) ;
@@ -900,9 +900,9 @@ class CPUFunctionNode extends FunctionNode {
900
900
if ( isInput ) {
901
901
retArr . push ( '[(' ) ;
902
902
this . astGeneric ( zProperty , retArr ) ;
903
- retArr . push ( `*${ size [ 1 ] * size [ 0 ] } )+(` ) ;
903
+ retArr . push ( `*${ this . dynamicArguments ? '(outputY * outputX)' : size [ 1 ] * size [ 0 ] } )+(` ) ;
904
904
this . astGeneric ( yProperty , retArr ) ;
905
- retArr . push ( `*${ size [ 0 ] } )+` ) ;
905
+ retArr . push ( `*${ this . dynamicArguments ? 'outputX' : size [ 0 ] } )+` ) ;
906
906
this . astGeneric ( xProperty , retArr ) ;
907
907
retArr . push ( ']' ) ;
908
908
} else {
@@ -920,7 +920,7 @@ class CPUFunctionNode extends FunctionNode {
920
920
if ( isInput ) {
921
921
retArr . push ( '[(' ) ;
922
922
this . astGeneric ( yProperty , retArr ) ;
923
- retArr . push ( `*${ size [ 0 ] } )+` ) ;
923
+ retArr . push ( `*${ this . dynamicArguments ? 'outputX' : size [ 0 ] } )+` ) ;
924
924
this . astGeneric ( xProperty , retArr ) ;
925
925
retArr . push ( ']' ) ;
926
926
} else {
@@ -1674,7 +1674,9 @@ class FunctionBuilder {
1674
1674
functions,
1675
1675
leadingReturnStatement,
1676
1676
followingReturnStatement,
1677
+ dynamicArguments,
1677
1678
dynamicOutput,
1679
+ warnVarUsage,
1678
1680
} = kernel ;
1679
1681
1680
1682
const needsArgumentType = ( functionName , index ) => {
@@ -1736,7 +1738,8 @@ class FunctionBuilder {
1736
1738
triggerImplyArgumentType,
1737
1739
triggerTrackArgumentSynonym,
1738
1740
lookupArgumentSynonym,
1739
- onFunctionCall
1741
+ onFunctionCall,
1742
+ warnVarUsage,
1740
1743
} ) ) ;
1741
1744
nestedFunction . traceFunctionAST ( ast ) ;
1742
1745
functionBuilder . addFunctionNode ( nestedFunction ) ;
@@ -1764,6 +1767,7 @@ class FunctionBuilder {
1764
1767
loopMaxIterations,
1765
1768
output,
1766
1769
plugins,
1770
+ dynamicArguments,
1767
1771
dynamicOutput,
1768
1772
} , extraNodeOptions || { } ) ;
1769
1773
@@ -2234,8 +2238,10 @@ class FunctionNode {
2234
2238
this . leadingReturnStatement = null ;
2235
2239
this . followingReturnStatement = null ;
2236
2240
this . dynamicOutput = null ;
2241
+ this . dynamicArguments = null ;
2237
2242
this . strictTypingChecking = false ;
2238
2243
this . fixIntegerDivisionAccuracy = null ;
2244
+ this . warnVarUsage = true ;
2239
2245
2240
2246
if ( settings ) {
2241
2247
for ( const p in settings ) {
@@ -5465,6 +5471,7 @@ class Kernel {
5465
5471
this . optimizeFloatMemory = null ;
5466
5472
this . strictIntegers = false ;
5467
5473
this . fixIntegerDivisionAccuracy = null ;
5474
+ this . warnVarUsage = true ;
5468
5475
}
5469
5476
5470
5477
mergeSettings ( settings ) {
@@ -5660,6 +5667,11 @@ class Kernel {
5660
5667
return this ;
5661
5668
}
5662
5669
5670
+ setWarnVarUsage ( flag ) {
5671
+ this . warnVarUsage = flag ;
5672
+ return this ;
5673
+ }
5674
+
5663
5675
getCanvas ( ) {
5664
5676
utils . warnDeprecated ( 'method' , 'getCanvas' ) ;
5665
5677
return this . canvas ;
@@ -6784,7 +6796,7 @@ class WebGLFunctionNode extends FunctionNode {
6784
6796
}
6785
6797
6786
6798
astVariableDeclaration ( varDecNode , retArr ) {
6787
- if ( varDecNode . kind === 'var' ) {
6799
+ if ( varDecNode . kind === 'var' && this . warnVarUsage ) {
6788
6800
this . varWarn ( ) ;
6789
6801
}
6790
6802
const declarations = varDecNode . declarations ;
@@ -7569,7 +7581,7 @@ module.exports = {
7569
7581
const { utils } = require ( '../../../utils' ) ;
7570
7582
const { WebGLKernelValueHTMLImage } = require ( './html-image' ) ;
7571
7583
7572
- class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
7584
+ class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
7573
7585
getSource ( ) {
7574
7586
return utils . linesToString ( [
7575
7587
`uniform sampler2D ${ this . id } ` ,
@@ -7589,7 +7601,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
7589
7601
}
7590
7602
7591
7603
module . exports = {
7592
- WebGLKernelValueDynamicInput
7604
+ WebGLKernelValueDynamicHTMLImage
7593
7605
} ;
7594
7606
} , { "../../../utils" :89 , "./html-image" :47 } ] , 40 :[ function ( require , module , exports ) {
7595
7607
const { utils } = require ( '../../../utils' ) ;
@@ -7630,8 +7642,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
7630
7642
}
7631
7643
7632
7644
updateValue ( value ) {
7633
- this . dimensions = inputTexture . dimensions ;
7634
- this . textureSize = inputTexture . size ;
7645
+ this . dimensions = value . dimensions ;
7646
+ this . textureSize = value . size ;
7635
7647
this . kernel . setUniform3iv ( this . dimensionsId , this . dimensions ) ;
7636
7648
this . kernel . setUniform2iv ( this . sizeId , this . textureSize ) ;
7637
7649
super . updateValue ( value ) ;
@@ -7684,7 +7696,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
7684
7696
updateValue ( value ) {
7685
7697
this . dimensions = value . size ;
7686
7698
this . textureSize = utils . getMemoryOptimizedFloatTextureSize ( this . dimensions , this . bitRatio ) ;
7687
- this . uploadArrayLength = this . textureSize [ 0 ] * this . textureSize [ 1 ] * ( 4 / this . bitRatio ) ;
7699
+ this . uploadArrayLength = this . textureSize [ 0 ] * this . textureSize [ 1 ] * this . bitRatio ;
7688
7700
this . uploadValue = new Float32Array ( this . uploadArrayLength ) ;
7689
7701
this . kernel . setUniform3iv ( this . dimensionsId , this . dimensions ) ;
7690
7702
this . kernel . setUniform2iv ( this . sizeId , this . textureSize ) ;
@@ -9957,6 +9969,7 @@ void main(void) {
9957
9969
module . exports = {
9958
9970
fragmentShader
9959
9971
} ;
9972
+
9960
9973
} , { } ] , 59 :[ function ( require , module , exports ) {
9961
9974
const { WebGLFunctionNode } = require ( '../web-gl/function-node' ) ;
9962
9975
@@ -10148,9 +10161,9 @@ module.exports = {
10148
10161
} ;
10149
10162
} , { "./html-image-array" :71 } ] , 63 :[ function ( require , module , exports ) {
10150
10163
const { utils } = require ( '../../../utils' ) ;
10151
- const { WebGLKernelValueDynamicInput } = require ( '../../web-gl/kernel-value/dynamic-html-image' ) ;
10164
+ const { WebGLKernelValueDynamicHTMLImage } = require ( '../../web-gl/kernel-value/dynamic-html-image' ) ;
10152
10165
10153
- class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
10166
+ class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
10154
10167
getSource ( ) {
10155
10168
return utils . linesToString ( [
10156
10169
`uniform highp sampler2D ${ this . id } ` ,
@@ -10161,7 +10174,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
10161
10174
}
10162
10175
10163
10176
module . exports = {
10164
- WebGL2KernelValueDynamicInput
10177
+ WebGL2KernelValueDynamicHTMLImage
10165
10178
} ;
10166
10179
} , { "../../../utils" :89 , "../../web-gl/kernel-value/dynamic-html-image" :39 } ] , 64 :[ function ( require , module , exports ) {
10167
10180
const { utils } = require ( '../../../utils' ) ;
@@ -10199,39 +10212,59 @@ module.exports = {
10199
10212
} ;
10200
10213
} , { "../../../utils" :89 , "../../web-gl/kernel-value/dynamic-number-texture" :41 } ] , 66 :[ function ( require , module , exports ) {
10201
10214
const { utils } = require ( '../../../utils' ) ;
10202
- const { WebGLKernelValueDynamicSingleArray } = require ( '../../web-gl /kernel-value/dynamic- single-array' ) ;
10215
+ const { WebGL2KernelValueSingleArray } = require ( '../../web-gl2 /kernel-value/single-array' ) ;
10203
10216
10204
- class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
10217
+ class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
10205
10218
getSource ( ) {
10206
10219
return utils . linesToString ( [
10207
10220
`uniform highp sampler2D ${ this . id } ` ,
10208
10221
`uniform highp ivec2 ${ this . sizeId } ` ,
10209
10222
`uniform highp ivec3 ${ this . dimensionsId } ` ,
10210
10223
] ) ;
10211
10224
}
10225
+
10226
+ updateValue ( value ) {
10227
+ this . dimensions = utils . getDimensions ( value , true ) ;
10228
+ this . textureSize = utils . getMemoryOptimizedFloatTextureSize ( this . dimensions , this . bitRatio ) ;
10229
+ this . uploadArrayLength = this . textureSize [ 0 ] * this . textureSize [ 1 ] * this . bitRatio ;
10230
+ this . uploadValue = new Float32Array ( this . uploadArrayLength ) ;
10231
+ this . kernel . setUniform3iv ( this . dimensionsId , this . dimensions ) ;
10232
+ this . kernel . setUniform2iv ( this . sizeId , this . textureSize ) ;
10233
+ super . updateValue ( value ) ;
10234
+ }
10212
10235
}
10213
10236
10214
10237
module . exports = {
10215
10238
WebGL2KernelValueDynamicSingleArray
10216
10239
} ;
10217
- } , { "../../../utils" :89 , "../../web-gl /kernel-value/dynamic- single-array" :42 } ] , 67 :[ function ( require , module , exports ) {
10240
+ } , { "../../../utils" :89 , "../../web-gl2 /kernel-value/single-array" :76 } ] , 67 :[ function ( require , module , exports ) {
10218
10241
const { utils } = require ( '../../../utils' ) ;
10219
- const { WebGLKernelValueDynamicSingleInput } = require ( '../../web-gl /kernel-value/dynamic- single-input' ) ;
10242
+ const { WebGL2KernelValueSingleInput } = require ( '../../web-gl2 /kernel-value/single-input' ) ;
10220
10243
10221
- class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
10244
+ class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
10222
10245
getSource ( ) {
10223
10246
return utils . linesToString ( [
10224
10247
`uniform highp sampler2D ${ this . id } ` ,
10225
10248
`uniform highp ivec2 ${ this . sizeId } ` ,
10226
10249
`uniform highp ivec3 ${ this . dimensionsId } ` ,
10227
10250
] ) ;
10228
10251
}
10252
+
10253
+ updateValue ( value ) {
10254
+ this . dimensions = value . size ;
10255
+ this . textureSize = utils . getMemoryOptimizedFloatTextureSize ( this . dimensions , this . bitRatio ) ;
10256
+ this . uploadArrayLength = this . textureSize [ 0 ] * this . textureSize [ 1 ] * this . bitRatio ;
10257
+ this . uploadValue = new Float32Array ( this . uploadArrayLength ) ;
10258
+ this . kernel . setUniform3iv ( this . dimensionsId , this . dimensions ) ;
10259
+ this . kernel . setUniform2iv ( this . sizeId , this . textureSize ) ;
10260
+ super . updateValue ( value ) ;
10261
+ }
10229
10262
}
10230
10263
10231
10264
module . exports = {
10232
10265
WebGL2KernelValueDynamicSingleInput
10233
10266
} ;
10234
- } , { "../../../utils" :89 , "../../web-gl /kernel-value/dynamic- single-input" :43 } ] , 68 :[ function ( require , module , exports ) {
10267
+ } , { "../../../utils" :89 , "../../web-gl2 /kernel-value/single-input" :77 } ] , 68 :[ function ( require , module , exports ) {
10235
10268
const { utils } = require ( '../../../utils' ) ;
10236
10269
const { WebGLKernelValueDynamicUnsignedArray } = require ( '../../web-gl/kernel-value/dynamic-unsigned-array' ) ;
10237
10270
@@ -10523,6 +10556,7 @@ let isSupported = null;
10523
10556
let testCanvas = null ;
10524
10557
let testContext = null ;
10525
10558
let testExtensions = null ;
10559
+
10526
10560
let features = null ;
10527
10561
10528
10562
class WebGL2Kernel extends WebGLKernel {
@@ -11338,7 +11372,25 @@ class GPU {
11338
11372
gpu : this ,
11339
11373
validate,
11340
11374
onRequestFallback : ( args ) => {
11341
- const fallbackKernel = new CPUKernel ( source , mergedSettings ) ;
11375
+ const fallbackKernel = new CPUKernel ( source , {
11376
+ graphical : kernel . graphical ,
11377
+ loopMaxIterations : kernel . loopMaxIterations ,
11378
+ constants : kernel . constants ,
11379
+ dynamicOutput : kernel . dynamicOutput ,
11380
+ dynamicArgument : kernel . dynamicArguments ,
11381
+ output : kernel . output ,
11382
+ precision : kernel . precision ,
11383
+ pipeline : kernel . pipeline ,
11384
+ immutable : kernel . immutable ,
11385
+ optimizeFloatMemory : kernel . optimizeFloatMemory ,
11386
+ fixIntegerDivisionAccuracy : kernel . fixIntegerDivisionAccuracy ,
11387
+ functions : kernel . functions ,
11388
+ nativeFunctions : kernel . nativeFunctions ,
11389
+ subKernels : kernel . subKernels ,
11390
+ strictIntegers : kernel . strictIntegers ,
11391
+ debug : kernel . debug ,
11392
+ warnVarUsage : kernel . warnVarUsage ,
11393
+ } ) ;
11342
11394
fallbackKernel . build . apply ( fallbackKernel , args ) ;
11343
11395
const result = fallbackKernel . run . apply ( fallbackKernel , args ) ;
11344
11396
kernel . replaceKernel ( fallbackKernel ) ;
@@ -11361,7 +11413,10 @@ class GPU {
11361
11413
}
11362
11414
const newKernel = switchableKernels [ signature ] = new this . Kernel ( source , {
11363
11415
graphical : kernel . graphical ,
11416
+ loopMaxIterations : kernel . loopMaxIterations ,
11364
11417
constants : kernel . constants ,
11418
+ dynamicOutput : kernel . dynamicOutput ,
11419
+ dynamicArgument : kernel . dynamicArguments ,
11365
11420
context : kernel . context ,
11366
11421
canvas : kernel . canvas ,
11367
11422
output : kernel . output ,
@@ -11377,6 +11432,7 @@ class GPU {
11377
11432
debug : kernel . debug ,
11378
11433
gpu : this ,
11379
11434
validate,
11435
+ warnVarUsage : kernel . warnVarUsage ,
11380
11436
} ) ;
11381
11437
newKernel . build . apply ( newKernel , args ) ;
11382
11438
newKernel . run . apply ( newKernel , args ) ;
0 commit comments