(destSize: number[])
| 29 | customUniforms: Array<{name: string; arrayIndex: number; type: UniformType;}>; |
| 30 | |
| 31 | constructor(destSize: number[]) { |
| 32 | this.outputShape = destSize; |
| 33 | this.rank = destSize.length; |
| 34 | this.customUniforms = [{name: 'start', arrayIndex: this.rank, type: 'int'}]; |
| 35 | const dtype = getCoordsDataType(this.rank); |
| 36 | const coords = getChannels('coords', this.rank); |
| 37 | const sourceLoc = getChannels('sourceLoc', this.rank); |
| 38 | |
| 39 | const innerDims = |
| 40 | this.rank === 1 ? 'sourceLoc' : `vec2(${sourceLoc.slice(-2).join()})`; |
| 41 | const getChannel = |
| 42 | `getChannel(getSource(${sourceLoc.join()}), ${innerDims})`; |
| 43 | const upperRow = ` |
| 44 | result.x = ${getChannel}; |
| 45 | if (++${coords[this.rank - 1]} < ${destSize[this.rank - 1]}) { |
| 46 | ++${sourceLoc[this.rank - 1]}; |
| 47 | result.y = ${getChannel}; |
| 48 | --${sourceLoc[this.rank - 1]}; |
| 49 | } |
| 50 | `; |
| 51 | const lowerRow = this.rank === 1 ? '' : ` |
| 52 | --${coords[this.rank - 1]}; |
| 53 | if (++${coords[this.rank - 2]} < ${destSize[this.rank - 2]}) { |
| 54 | ++${sourceLoc[this.rank - 2]}; |
| 55 | result.z = ${getChannel}; |
| 56 | if (++${coords[this.rank - 1]} < ${destSize[this.rank - 1]}) { |
| 57 | ++${sourceLoc[this.rank - 1]}; |
| 58 | result.w = ${getChannel}; |
| 59 | } |
| 60 | } |
| 61 | `; |
| 62 | |
| 63 | const sourceLocSetup = this.rank <= 4 ? |
| 64 | `sourceLoc = coords + |
| 65 | ${dtype}(${destSize.map((_, i) => `start[${i}]`).join()});` : |
| 66 | destSize.map((_, i) => `${sourceLoc[i]} = ${coords[i]} + start[${i}];`) |
| 67 | .join('\n'); |
| 68 | this.userCode = ` |
| 69 | void main() { |
| 70 | ${dtype} coords = getOutputCoords(); |
| 71 | ${dtype} sourceLoc; |
| 72 | ${sourceLocSetup} |
| 73 | vec4 result = vec4(0.); |
| 74 | ${upperRow} |
| 75 | ${lowerRow} |
| 76 | setOutput(result); |
| 77 | } |
| 78 | `; |
| 79 | } |
| 80 | } |
nothing calls this directly
no test coverage detected