diff options
| author | y-jan137 <yousefjan24000@gmail.com> | 2026-05-01 17:25:22 +0300 |
|---|---|---|
| committer | y-jan137 <yousefjan24000@gmail.com> | 2026-05-01 17:25:22 +0300 |
| commit | de3f8b33f53e72ebda59d1e2aca201eec8bea9e8 (patch) | |
| tree | 502fbfd658f51a25fb9f2685b5c9b71f778cd1ec | |
| parent | 7edac8e1796e9f021c7a990e8efdfe233a8eec69 (diff) | |
Cache colors in threadgroup memory
| -rw-r--r-- | Sources/Shaders.metal | 8 | ||||
| -rw-r--r-- | examples/output-736x736.png | bin | 1404255 -> 1416867 bytes |
2 files changed, 5 insertions, 3 deletions
diff --git a/Sources/Shaders.metal b/Sources/Shaders.metal index 25f3e64..a525ab3 100644 --- a/Sources/Shaders.metal +++ b/Sources/Shaders.metal @@ -176,6 +176,7 @@ kernel void pixelSortSpan( ) { threadgroup float keys[MAX_SPAN]; threadgroup ushort orig[MAX_SPAN]; + threadgroup half4 colors[MAX_SPAN]; SpanDescriptor span = spanBuffer[tgid]; uint row = span.row; @@ -191,7 +192,9 @@ kernel void pixelSortSpan( for (uint i = tid; i < n; i += TG_SIZE) { if (i < len) { - keys[i] = sortKeyTex.read(uint2(startX + i, row)).x; + uint2 coord = uint2(startX + i, row); + keys[i] = sortKeyTex.read(coord).x; + colors[i] = half4(colorTex.read(coord)); orig[i] = ushort(i); } else { keys[i] = sentinel; @@ -219,8 +222,7 @@ kernel void pixelSortSpan( } for (uint i = tid; i < len; i += TG_SIZE) { - float4 c = colorTex.read(uint2(startX + orig[i], row)); - sortedTex.write(c, uint2(startX + i, row)); + sortedTex.write(float4(colors[orig[i]]), uint2(startX + i, row)); } } diff --git a/examples/output-736x736.png b/examples/output-736x736.png Binary files differindex e2043a7..8e603e5 100644 --- a/examples/output-736x736.png +++ b/examples/output-736x736.png |