(
gpgpu: GPGPUContext, binary: GPGPUBinary, inputs: TensorData[],
output: TensorData, customUniformValues?: number[][])
| 237 | } |
| 238 | |
| 239 | export function runProgram<T extends Tensor, K extends Tensor>( |
| 240 | gpgpu: GPGPUContext, binary: GPGPUBinary, inputs: TensorData[], |
| 241 | output: TensorData, customUniformValues?: number[][]): void { |
| 242 | if (!binary.program.enableShapeUniforms) { |
| 243 | validateBinaryAndProgram(binary.inShapeInfos, inputs); |
| 244 | validateBinaryAndProgram([binary.outShapeInfo], [output]); |
| 245 | } |
| 246 | |
| 247 | const outTex = output.texData.texture; |
| 248 | const outTexShape = output.texData.texShape; |
| 249 | if (output.texData.isPacked) { |
| 250 | gpgpu.setOutputPackedMatrixTexture( |
| 251 | outTex.texture, outTexShape[0], outTexShape[1]); |
| 252 | } else { |
| 253 | gpgpu.setOutputMatrixTexture( |
| 254 | outTex.texture, outTexShape[0], outTexShape[1]); |
| 255 | } |
| 256 | gpgpu.setProgram(binary.webGLProgram); |
| 257 | gpgpu.bindVertexArray(binary.webGLProgram.vao); |
| 258 | |
| 259 | // Set special uniforms (NAN, INFINITY) |
| 260 | if (env().getNumber('WEBGL_VERSION') === 1) { |
| 261 | if (binary.infLoc !== null) { |
| 262 | gpgpu.gl.uniform1f(binary.infLoc, Infinity); |
| 263 | } |
| 264 | } |
| 265 | if (binary.nanLoc !== null) { |
| 266 | gpgpu.gl.uniform1f(binary.nanLoc, NaN); |
| 267 | } |
| 268 | |
| 269 | // Set user-defined inputs |
| 270 | for (let i = 0; i < inputs.length; ++i) { |
| 271 | const input = inputs[i]; |
| 272 | const { |
| 273 | uniform: varLoc, |
| 274 | offset: varOffsetLoc, |
| 275 | shape: varShapeLoc, |
| 276 | texShape: varTexShapeLoc, |
| 277 | } = binary.variablesLocations[i]; |
| 278 | |
| 279 | if (varShapeLoc) { |
| 280 | const {uniformShape} = shader_compiler.getUniformInfoFromShape( |
| 281 | binary.program.packedInputs, input.shape, input.texData.texShape); |
| 282 | switch (uniformShape.length) { |
| 283 | case 1: |
| 284 | gpgpu.gl.uniform1iv(varShapeLoc, new Int32Array(uniformShape)); |
| 285 | break; |
| 286 | case 2: |
| 287 | gpgpu.gl.uniform2iv(varShapeLoc, new Int32Array(uniformShape)); |
| 288 | break; |
| 289 | case 3: |
| 290 | gpgpu.gl.uniform3iv(varShapeLoc, new Int32Array(uniformShape)); |
| 291 | break; |
| 292 | case 4: |
| 293 | gpgpu.gl.uniform4iv(varShapeLoc, new Int32Array(uniformShape)); |
| 294 | break; |
| 295 | default: |
| 296 | break; |
nothing calls this directly
no test coverage detected
searching dependent graphs…