4
4
*
5
5
* GPU Accelerated JavaScript
6
6
*
7
- * @version 2.4.5
8
- * @date Thu Jan 02 2020 13:02:31 GMT-0500 (Eastern Standard Time)
7
+ * @version 2.4.6
8
+ * @date Thu Jan 02 2020 19:46:21 GMT-0500 (Eastern Standard Time)
9
9
*
10
10
* @license MIT
11
11
* The MIT License
@@ -1406,6 +1406,10 @@ class CPUKernel extends Kernel {
1406
1406
return combinedKernel ;
1407
1407
}
1408
1408
1409
+ static getSignature ( kernel , argumentTypes ) {
1410
+ return 'cpu' + ( argumentTypes . length > 0 ? ':' + argumentTypes . join ( ',' ) : '' ) ;
1411
+ }
1412
+
1409
1413
constructor ( source , settings ) {
1410
1414
super ( source , settings ) ;
1411
1415
this . mergeSettings ( source . settings || settings ) ;
@@ -1518,6 +1522,7 @@ class CPUKernel extends Kernel {
1518
1522
} catch ( e ) {
1519
1523
console . error ( 'An error occurred compiling the javascript: ' , e ) ;
1520
1524
}
1525
+ this . buildSignature ( arguments ) ;
1521
1526
this . built = true ;
1522
1527
}
1523
1528
@@ -4535,6 +4540,10 @@ class GLKernel extends Kernel {
4535
4540
throw new Error ( `"setupFeatureChecks" not defined on ${ this . name } ` ) ;
4536
4541
}
4537
4542
4543
+ static getSignature ( kernel , argumentTypes ) {
4544
+ return kernel . getVariablePrecisionString ( ) + ( argumentTypes . length > 0 ? ':' + argumentTypes . join ( ',' ) : '' ) ;
4545
+ }
4546
+
4538
4547
setFixIntegerDivisionAccuracy ( fix ) {
4539
4548
this . fixIntegerDivisionAccuracy = fix ;
4540
4549
return this ;
@@ -6058,6 +6067,7 @@ class Kernel {
6058
6067
this . onIstanbulCoverageVariable = null ;
6059
6068
this . removeIstanbulCoverage = false ;
6060
6069
this . built = false ;
6070
+ this . signature = null ;
6061
6071
}
6062
6072
6063
6073
mergeSettings ( settings ) {
@@ -6427,6 +6437,39 @@ class Kernel {
6427
6437
}
6428
6438
} ;
6429
6439
}
6440
+
6441
+ buildSignature ( args ) {
6442
+ const Constructor = this . constructor ;
6443
+ this . signature = Constructor . getSignature ( this , Constructor . getArgumentTypes ( this , args ) ) ;
6444
+ }
6445
+
6446
+ static getArgumentTypes ( kernel , args ) {
6447
+ const argumentTypes = new Array ( args . length ) ;
6448
+ for ( let i = 0 ; i < args . length ; i ++ ) {
6449
+ const arg = args [ i ] ;
6450
+ const type = kernel . argumentTypes [ i ] ;
6451
+ if ( arg . type ) {
6452
+ argumentTypes [ i ] = arg . type ;
6453
+ } else {
6454
+ switch ( type ) {
6455
+ case 'Number' :
6456
+ case 'Integer' :
6457
+ case 'Float' :
6458
+ case 'ArrayTexture(1)' :
6459
+ argumentTypes [ i ] = utils . getVariableType ( arg ) ;
6460
+ break ;
6461
+ default :
6462
+ argumentTypes [ i ] = type ;
6463
+ }
6464
+ }
6465
+ }
6466
+ return argumentTypes ;
6467
+ }
6468
+
6469
+ static getSignature ( kernel , argumentTypes ) {
6470
+ throw new Error ( `"getSignature" not implemented on ${ this . name } ` ) ;
6471
+ return argumentTypes . length > 0 ? ':' + argumentTypes . join ( ',' ) : '' ;
6472
+ }
6430
6473
}
6431
6474
6432
6475
module . exports = {
@@ -9102,7 +9145,7 @@ class WebGLKernelValueSingleArray extends WebGLKernelValue {
9102
9145
9103
9146
updateValue ( value ) {
9104
9147
if ( value . constructor !== this . initialValueConstructor ) {
9105
- this . onUpdateValueMismatch ( ) ;
9148
+ this . onUpdateValueMismatch ( value . constructor ) ;
9106
9149
return ;
9107
9150
}
9108
9151
const { context : gl } = this ;
@@ -9333,7 +9376,7 @@ class WebGLKernelValueSingleArray3DI extends WebGLKernelValue {
9333
9376
9334
9377
updateValue ( value ) {
9335
9378
if ( value . constructor !== this . initialValueConstructor ) {
9336
- this . onUpdateValueMismatch ( ) ;
9379
+ this . onUpdateValueMismatch ( value . constructor ) ;
9337
9380
return ;
9338
9381
}
9339
9382
const { context : gl } = this ;
@@ -9416,7 +9459,7 @@ class WebGLKernelValueSingleInput extends WebGLKernelValue {
9416
9459
9417
9460
updateValue ( input ) {
9418
9461
if ( input . constructor !== this . initialValueConstructor ) {
9419
- this . onUpdateValueMismatch ( ) ;
9462
+ this . onUpdateValueMismatch ( input . constructor ) ;
9420
9463
return ;
9421
9464
}
9422
9465
const { context : gl } = this ;
@@ -9471,7 +9514,7 @@ class WebGLKernelValueUnsignedArray extends WebGLKernelValue {
9471
9514
9472
9515
updateValue ( value ) {
9473
9516
if ( value . constructor !== this . initialValueConstructor ) {
9474
- this . onUpdateValueMismatch ( ) ;
9517
+ this . onUpdateValueMismatch ( value . constructor ) ;
9475
9518
return ;
9476
9519
}
9477
9520
const { context : gl } = this ;
@@ -9527,7 +9570,7 @@ class WebGLKernelValueUnsignedInput extends WebGLKernelValue {
9527
9570
9528
9571
updateValue ( input ) {
9529
9572
if ( input . constructor !== this . initialValueConstructor ) {
9530
- this . onUpdateValueMismatch ( ) ;
9573
+ this . onUpdateValueMismatch ( value . constructor ) ;
9531
9574
return ;
9532
9575
}
9533
9576
const { context : gl } = this ;
@@ -10064,6 +10107,7 @@ class WebGLKernel extends GLKernel {
10064
10107
) {
10065
10108
this . _setupSubOutputTextures ( ) ;
10066
10109
}
10110
+ this . buildSignature ( arguments ) ;
10067
10111
this . built = true ;
10068
10112
}
10069
10113
@@ -12004,7 +12048,7 @@ class WebGL2KernelValueSingleArray extends WebGLKernelValueSingleArray {
12004
12048
12005
12049
updateValue ( value ) {
12006
12050
if ( value . constructor !== this . initialValueConstructor ) {
12007
- this . onUpdateValueMismatch ( ) ;
12051
+ this . onUpdateValueMismatch ( value . constructor ) ;
12008
12052
return ;
12009
12053
}
12010
12054
const { context : gl } = this ;
@@ -12030,7 +12074,7 @@ const { WebGLKernelValueSingleArray1DI } = require('../../web-gl/kernel-value/si
12030
12074
class WebGL2KernelValueSingleArray1DI extends WebGLKernelValueSingleArray1DI {
12031
12075
updateValue ( value ) {
12032
12076
if ( value . constructor !== this . initialValueConstructor ) {
12033
- this . onUpdateValueMismatch ( ) ;
12077
+ this . onUpdateValueMismatch ( value . constructor ) ;
12034
12078
return ;
12035
12079
}
12036
12080
const { context : gl } = this ;
@@ -12064,7 +12108,7 @@ const { WebGLKernelValueSingleArray2DI } = require('../../web-gl/kernel-value/si
12064
12108
class WebGL2KernelValueSingleArray2DI extends WebGLKernelValueSingleArray2DI {
12065
12109
updateValue ( value ) {
12066
12110
if ( value . constructor !== this . initialValueConstructor ) {
12067
- this . onUpdateValueMismatch ( ) ;
12111
+ this . onUpdateValueMismatch ( value . constructor ) ;
12068
12112
return ;
12069
12113
}
12070
12114
const { context : gl } = this ;
@@ -12098,7 +12142,7 @@ const { WebGLKernelValueSingleArray3DI } = require('../../web-gl/kernel-value/si
12098
12142
class WebGL2KernelValueSingleArray3DI extends WebGLKernelValueSingleArray3DI {
12099
12143
updateValue ( value ) {
12100
12144
if ( value . constructor !== this . initialValueConstructor ) {
12101
- this . onUpdateValueMismatch ( ) ;
12145
+ this . onUpdateValueMismatch ( value . constructor ) ;
12102
12146
return ;
12103
12147
}
12104
12148
const { context : gl } = this ;
@@ -12795,6 +12839,7 @@ module.exports = lib;
12795
12839
} , { "./index" :107 } ] , 106 :[ function ( require , module , exports ) {
12796
12840
const { gpuMock } = require ( 'gpu-mock.js' ) ;
12797
12841
const { utils } = require ( './utils' ) ;
12842
+ const { Kernel } = require ( './backend/kernel' ) ;
12798
12843
const { CPUKernel } = require ( './backend/cpu/kernel' ) ;
12799
12844
const { HeadlessGLKernel } = require ( './backend/headless-gl/kernel' ) ;
12800
12845
const { WebGL2Kernel } = require ( './backend/web-gl2/kernel' ) ;
@@ -12998,6 +13043,9 @@ class GPU {
12998
13043
console . warn ( 'Switching kernels' ) ;
12999
13044
}
13000
13045
let newOutput = null ;
13046
+ if ( kernel . signature && ! switchableKernels [ kernel . signature ] ) {
13047
+ switchableKernels [ kernel . signature ] = kernel ;
13048
+ }
13001
13049
if ( kernel . dynamicOutput ) {
13002
13050
for ( let i = reasons . length - 1 ; i >= 0 ; i -- ) {
13003
13051
const reason = reasons [ i ] ;
@@ -13006,32 +13054,16 @@ class GPU {
13006
13054
}
13007
13055
}
13008
13056
}
13009
- const argumentTypes = new Array ( args . length ) ;
13010
- for ( let i = 0 ; i < args . length ; i ++ ) {
13011
- const arg = args [ i ] ;
13012
- const type = kernel . argumentTypes [ i ] ;
13013
- if ( arg . type ) {
13014
- argumentTypes [ i ] = arg . type ;
13015
- } else {
13016
- switch ( type ) {
13017
- case 'Number' :
13018
- case 'Integer' :
13019
- case 'Float' :
13020
- case 'ArrayTexture(1)' :
13021
- argumentTypes [ i ] = utils . getVariableType ( arg ) ;
13022
- break ;
13023
- default :
13024
- argumentTypes [ i ] = type ;
13025
- }
13026
- }
13027
- }
13028
- const signature = kernel . getVariablePrecisionString ( ) + ( argumentTypes . length > 0 ? ':' + argumentTypes . join ( ',' ) : '' ) ;
13057
+
13058
+ const Constructor = kernel . constructor ;
13059
+ const argumentTypes = Constructor . getArgumentTypes ( kernel , args ) ;
13060
+ const signature = Constructor . getSignature ( kernel , argumentTypes ) ;
13029
13061
const existingKernel = switchableKernels [ signature ] ;
13030
13062
if ( existingKernel ) {
13031
13063
return existingKernel ;
13032
13064
}
13033
13065
13034
- const newKernel = switchableKernels [ signature ] = new kernel . constructor ( source , {
13066
+ const newKernel = switchableKernels [ signature ] = new Constructor ( source , {
13035
13067
argumentTypes,
13036
13068
constantTypes : kernel . constantTypes ,
13037
13069
graphical : kernel . graphical ,
@@ -13258,7 +13290,7 @@ module.exports = {
13258
13290
kernelOrder,
13259
13291
kernelTypes
13260
13292
} ;
13261
- } , { "./backend/cpu/kernel" :7 , "./backend/headless-gl/kernel" :33 , "./backend/web-gl/kernel" :68 , "./backend/web-gl2/kernel" :103 , "./kernel-run-shortcut" :109 , "./utils" :112 , "gpu-mock.js" :3 } ] , 107 :[ function ( require , module , exports ) {
13293
+ } , { "./backend/cpu/kernel" :7 , "./backend/headless-gl/kernel" :33 , "./backend/kernel" : 35 , "./backend/ web-gl/kernel" :68 , "./backend/web-gl2/kernel" :103 , "./kernel-run-shortcut" :109 , "./utils" :112 , "gpu-mock.js" :3 } ] , 107 :[ function ( require , module , exports ) {
13262
13294
const { GPU } = require ( './gpu' ) ;
13263
13295
const { alias } = require ( './alias' ) ;
13264
13296
const { utils } = require ( './utils' ) ;
@@ -13382,6 +13414,7 @@ function kernelRunShortcut(kernel) {
13382
13414
if ( kernel . switchingKernels ) {
13383
13415
const reasons = kernel . resetSwitchingKernels ( ) ;
13384
13416
const newKernel = kernel . onRequestSwitchKernel ( reasons , arguments , kernel ) ;
13417
+ shortcut . kernel = kernel = newKernel ;
13385
13418
result = newKernel . run . apply ( newKernel , arguments ) ;
13386
13419
}
13387
13420
if ( kernel . renderKernels ) {
@@ -13409,43 +13442,40 @@ function kernelRunShortcut(kernel) {
13409
13442
shortcut . replaceKernel = function ( replacementKernel ) {
13410
13443
kernel = replacementKernel ;
13411
13444
bindKernelToShortcut ( kernel , shortcut ) ;
13412
- shortcut . kernel = kernel ;
13413
13445
} ;
13414
13446
13415
13447
bindKernelToShortcut ( kernel , shortcut ) ;
13416
- shortcut . kernel = kernel ;
13417
13448
return shortcut ;
13418
13449
}
13419
13450
13420
13451
function bindKernelToShortcut ( kernel , shortcut ) {
13452
+ if ( shortcut . kernel ) {
13453
+ shortcut . kernel = kernel ;
13454
+ return ;
13455
+ }
13421
13456
const properties = utils . allPropertiesOf ( kernel ) ;
13422
13457
for ( let i = 0 ; i < properties . length ; i ++ ) {
13423
13458
const property = properties [ i ] ;
13424
13459
if ( property [ 0 ] === '_' && property [ 1 ] === '_' ) continue ;
13425
13460
if ( typeof kernel [ property ] === 'function' ) {
13426
13461
if ( property . substring ( 0 , 3 ) === 'add' || property . substring ( 0 , 3 ) === 'set' ) {
13427
13462
shortcut [ property ] = function ( ) {
13428
- kernel [ property ] . apply ( kernel , arguments ) ;
13463
+ shortcut . kernel [ property ] . apply ( shortcut . kernel , arguments ) ;
13429
13464
return shortcut ;
13430
13465
} ;
13431
13466
} else {
13432
- if ( property === 'toString' ) {
13433
- shortcut . toString = function ( ) {
13434
- return kernel . toString . apply ( kernel , arguments ) ;
13435
- } ;
13436
- } else {
13437
- shortcut [ property ] = kernel [ property ] . bind ( kernel ) ;
13438
- }
13467
+ shortcut [ property ] = function ( ) {
13468
+ return shortcut . kernel [ property ] . apply ( shortcut . kernel , arguments ) ;
13469
+ } ;
13439
13470
}
13440
13471
} else {
13441
- shortcut . __defineGetter__ ( property , ( ) => {
13442
- return kernel [ property ] ;
13443
- } ) ;
13472
+ shortcut . __defineGetter__ ( property , ( ) => shortcut . kernel [ property ] ) ;
13444
13473
shortcut . __defineSetter__ ( property , ( value ) => {
13445
- kernel [ property ] = value ;
13474
+ shortcut . kernel [ property ] = value ;
13446
13475
} ) ;
13447
13476
}
13448
13477
}
13478
+ shortcut . kernel = kernel ;
13449
13479
}
13450
13480
module . exports = {
13451
13481
kernelRunShortcut
0 commit comments