-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
\#4: port sort to shader preprocessor, remove old odd-even sort
- Loading branch information
1 parent
6612eee
commit 46c950b
Showing
5 changed files
with
63 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {compile, glsl} from '../glslpp'; | ||
import { | ||
compareWidth, | ||
inputSampler, | ||
n, | ||
resolution, | ||
stageWidth, | ||
} from './uniforms'; | ||
|
||
export const sortOddEvenMergeFs = compile(glsl` | ||
out ivec4 outResult; | ||
void main() { | ||
// self index | ||
int i = int(gl_FragCoord.y) * ${resolution}.x + int(gl_FragCoord.x); | ||
// is this the left side of the pair (0) or the right (1)? | ||
bool isLeft; | ||
if (${compareWidth} < ${stageWidth}) { | ||
// this is a merge pass; add an offset | ||
isLeft = (i / ${compareWidth} + 1) % 2 == 0; | ||
} else { | ||
// first pass | ||
isLeft = (i / ${compareWidth}) % 2 == 0; | ||
} | ||
int direction = isLeft ? 1 : -1; | ||
// pair index | ||
int j = i + direction * ${compareWidth}; | ||
// read value of self and pair | ||
ivec2 texCoordi = ivec2(i % ${resolution}.x, i / ${resolution}.x); | ||
ivec2 texCoordj = ivec2(j % ${resolution}.x, j / ${resolution}.x); | ||
// values consist of (key, value) | ||
ivec2 vi = texelFetch(${inputSampler}, texCoordi, 0).rg; | ||
ivec2 vj = texelFetch(${inputSampler}, texCoordj, 0).rg; | ||
ivec2 result; | ||
int sw2 = ${stageWidth} * 2; | ||
int lower = (i / sw2) * sw2; | ||
int upper = lower + sw2; | ||
if (j < lower || j >= upper || j >= ${n}) { | ||
// pair is not in bounds; simply copy own value | ||
result = vi; | ||
} else { | ||
if (isLeft) { | ||
// self is on the left side of the pair; pick < | ||
result = vi.x < vj.x ? vi : vj; | ||
} else { | ||
// self is on the right side of the pair; pick > | ||
result = vi.x > vj.x ? vi : vj; | ||
} | ||
} | ||
outResult = ivec4(result, 0, 0); | ||
} | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.