aboutsummaryrefslogtreecommitdiff
path: root/Sources
diff options
context:
space:
mode:
authory-jan137 <yousefjan24000@gmail.com>2026-05-01 17:25:22 +0300
committery-jan137 <yousefjan24000@gmail.com>2026-05-01 17:25:22 +0300
commitde3f8b33f53e72ebda59d1e2aca201eec8bea9e8 (patch)
tree502fbfd658f51a25fb9f2685b5c9b71f778cd1ec /Sources
parent7edac8e1796e9f021c7a990e8efdfe233a8eec69 (diff)
Cache colors in threadgroup memory
Diffstat (limited to 'Sources')
-rw-r--r--Sources/Shaders.metal8
1 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));
}
}