| 58 | } |
| 59 | |
| 60 | getUserCode(): string { |
| 61 | let offsetSnippet = '0.0'; |
| 62 | if (this.offsetShape != null) { |
| 63 | offsetSnippet = 'getOffsetByOutputIndex(index)'; |
| 64 | } |
| 65 | |
| 66 | let scaleSnippet = '1.0'; |
| 67 | if (this.scaleShape != null) { |
| 68 | scaleSnippet = 'getScaleByOutputIndex(index)'; |
| 69 | } |
| 70 | |
| 71 | const userCode = ` |
| 72 | ${main('index')} { |
| 73 | if (index < uniforms.size) |
| 74 | { |
| 75 | let xValue = getXByOutputIndex(index); |
| 76 | let meanValue = getMeanByOutputIndex(index); |
| 77 | let varianValue = getVarianceByOutputIndex(index); |
| 78 | let offsetValue = ${offsetSnippet}; |
| 79 | let scaleValue = ${scaleSnippet}; |
| 80 | let inv = scaleValue * inverseSqrt(varianValue + f32(uniforms.varianceEpsilon)); |
| 81 | setOutputAtIndex(index,dot(vec3<f32>(xValue, -meanValue, offsetValue), vec3<f32>(inv, inv, 1.0))); |
| 82 | } |
| 83 | } |
| 84 | `; |
| 85 | return userCode; |
| 86 | } |
| 87 | } |