(
outShape: number[], outBufferType: DataType, component: number)
| 789 | } |
| 790 | |
| 791 | function setOutputSnippet( |
| 792 | outShape: number[], outBufferType: DataType, component: number): string { |
| 793 | const outRank = outShape.length; |
| 794 | const gpuType = dataTypeToGPUType(outBufferType, component); |
| 795 | let snippet = |
| 796 | `fn setOutputAtIndex(flatIndex : i32, value : ${typeSnippet(component)}) { |
| 797 | result[flatIndex] = ${gpuType}(value); |
| 798 | } |
| 799 | |
| 800 | fn setOutputAtIndexI32(flatIndex : i32, value : ${ |
| 801 | typeSnippet(component, 'i32')}) { |
| 802 | result[flatIndex] = ${gpuType}(value); |
| 803 | } |
| 804 | `; |
| 805 | if (outRank >= 2) { |
| 806 | const dims = ['d0', 'd1', 'd2', 'd3', 'd4', 'd5'].slice(0, outRank); |
| 807 | const type = getCoordsDataType(outRank); |
| 808 | |
| 809 | snippet += ` |
| 810 | fn setOutputAtCoords(${dims.map(d => `${d} : i32`).join(', ')}, value : ${ |
| 811 | typeSnippet(component)}) { |
| 812 | let flatIndex = getOutputIndexFromCoords(${type}(${dims.join(', ')})); |
| 813 | setOutputAtIndex(flatIndex${ |
| 814 | component === 1 ? '' : ` / ${component}`}, value); |
| 815 | } |
| 816 | fn setOutputAtCoordsI32(${ |
| 817 | dims.map(d => `${d} : i32`).join(', ')}, value : ${ |
| 818 | typeSnippet(component, 'i32')}) { |
| 819 | let flatIndex = getOutputIndexFromCoords(${type}(${dims.join(', ')})); |
| 820 | setOutputAtIndexI32(flatIndex${ |
| 821 | component === 1 ? '' : ` / ${component}`}, value); |
| 822 | } |
| 823 | `; |
| 824 | } |
| 825 | |
| 826 | return snippet; |
| 827 | } |
| 828 | |
| 829 | function insertAlignment(uniformShader: string) { |
| 830 | // insert alignment when current pattern is vec5 or vec6 |
no test coverage detected
searching dependent graphs…