upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/present_compose.comp
diff options
context:
space:
mode:
authorAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 17:34:38 +0100
committerAlxcBTW <187763517+AlxcBTW@users.noreply.github.com>2026-11-22 17:34:38 +0100
commit0a3bf1ed91a529cb0ad093262d8b9d5250102763 (patch)
tree538c7204bae449d5cea0fe17b1f08ead3f2921a7 /runtime/src/present_compose.comp
parent9bf0794813c98a6ac45a6b9963456deb1a806956 (diff)
PresentX planes: enable swapchain_colorspace on the real instance, premultiply before filtering
- create_vulkan_device_standalone now enables VK_EXT_swapchain_colorspace when the loader has it (only the test device did), so the HDR10 surface formats can be listed in the real runtime; xbox_present_test checks the standalone path (device_has_swapchain_colorspace). - Straight-alpha planes are bilinearly filtered on premultiplied colour and un-premultiplied after, so a transparent texel adds no colour; the CPU model does it independently, plus a transparent-edge case. Both found in review by Flyander. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/present_compose.comp')
-rw-r--r--runtime/src/present_compose.comp16
1 files changed, 11 insertions, 5 deletions
diff --git a/runtime/src/present_compose.comp b/runtime/src/present_compose.comp
index 303730cef..b557a6444 100644
--- a/runtime/src/present_compose.comp
+++ b/runtime/src/present_compose.comp
@@ -44,22 +44,28 @@ vec3 srgb_encode(vec3 c) {
44 return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, greaterThan(c, vec3(0.0031308))); 44 return mix(c * 12.92, 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055, greaterThan(c, vec3(0.0031308)));
45} 45}
46 46
47vec4 fetch_texel(texture2D t, ivec2 i) { return texelFetch(t, i, 0); } 47// `pre`: straight-alpha data is filtered premultiplied (colour * alpha), else a transparent texel would drag the colour of its neighbours down.
48vec4 fetch_texel(texture2D t, ivec2 i, bool pre) {
49 vec4 c = texelFetch(t, i, 0);
50 return pre ? vec4(c.rgb * c.a, c.a) : c;
51}
48 52
49// The plane's value at output pixel `pixel` (its centre), in the plane's own encoding. 53// The plane's value at output pixel `pixel` (its centre), in the plane's own encoding.
50vec4 fetch_plane(texture2D t, vec4 dest, vec4 src, uint flags, ivec2 pixel) { 54vec4 fetch_plane(texture2D t, vec4 dest, vec4 src, uint flags, ivec2 pixel) {
51 vec2 p = (vec2(pixel) + 0.5 - dest.xy) / (dest.zw - dest.xy); // 0..1 across the destination rectangle 55 vec2 p = (vec2(pixel) + 0.5 - dest.xy) / (dest.zw - dest.xy); // 0..1 across the destination rectangle
52 vec2 s = src.xy + p * (src.zw - src.xy); // continuous texel coordinates 56 vec2 s = src.xy + p * (src.zw - src.xy); // continuous texel coordinates
53 vec2 lo = src.xy, hi = src.zw - 1.0; 57 vec2 lo = src.xy, hi = src.zw - 1.0;
58 bool pre = (flags & flag_straight_alpha) != 0u;
54 vec4 c; 59 vec4 c;
55 if ((flags & flag_point) != 0u) { 60 if ((flags & flag_point) != 0u) {
56 c = fetch_texel(t, ivec2(clamp(floor(s), lo, hi))); 61 c = fetch_texel(t, ivec2(clamp(floor(s), lo, hi)), false);
57 } else { 62 } else {
58 vec2 f = clamp(s - 0.5, lo, hi); // the texel whose centre is at or before the sample, clamped inside the rectangle 63 vec2 f = clamp(s - 0.5, lo, hi); // the texel whose centre is at or before the sample, clamped inside the rectangle
59 vec2 base = floor(f), w = f - base; 64 vec2 base = floor(f), w = f - base;
60 ivec2 i0 = ivec2(base), i1 = ivec2(min(base + 1.0, hi)); 65 ivec2 i0 = ivec2(base), i1 = ivec2(min(base + 1.0, hi));
61 c = mix(mix(fetch_texel(t, ivec2(i0.x, i0.y)), fetch_texel(t, ivec2(i1.x, i0.y)), w.x), 66 c = mix(mix(fetch_texel(t, ivec2(i0.x, i0.y), pre), fetch_texel(t, ivec2(i1.x, i0.y), pre), w.x),
62 mix(fetch_texel(t, ivec2(i0.x, i1.y)), fetch_texel(t, ivec2(i1.x, i1.y)), w.x), w.y); 67 mix(fetch_texel(t, ivec2(i0.x, i1.y), pre), fetch_texel(t, ivec2(i1.x, i1.y), pre), w.x), w.y);
68 if (pre) c.rgb = c.a > 0.0 ? c.rgb / c.a : vec3(0.0); // back to unassociated colour
63 } 69 }
64 if ((flags & flag_srgb_source) != 0u) c.rgb = srgb_encode(c.rgb); 70 if ((flags & flag_srgb_source) != 0u) c.rgb = srgb_encode(c.rgb);
65 return c; 71 return c;
@@ -102,7 +108,7 @@ void main() {
102 108
103 vec3 base = vec3(0.0); // outside plane 0's rectangle: black 109 vec3 base = vec3(0.0); // outside plane 0's rectangle: black
104 if (all(greaterThanEqual(centre, pc.dest0.xy)) && all(lessThan(centre, pc.dest0.zw))) { 110 if (all(greaterThanEqual(centre, pc.dest0.xy)) && all(lessThan(centre, pc.dest0.zw))) {
105 vec4 c = fetch_plane(plane0, pc.dest0, pc.src0, pc.flags0, pixel); 111 vec4 c = fetch_plane(plane0, pc.dest0, pc.src0, pc.flags0 & ~flag_straight_alpha, pixel);
106 base = to_output(c.rgb, (pc.flags0 & flag_hdr10) != 0u); 112 base = to_output(c.rgb, (pc.flags0 & flag_hdr10) != 0u);
107 } 113 }
108 if (pc.plane_count > 1u && all(greaterThanEqual(centre, pc.dest1.xy)) && all(lessThan(centre, pc.dest1.zw))) { 114 if (pc.plane_count > 1u && all(greaterThanEqual(centre, pc.dest1.xy)) && all(lessThan(centre, pc.dest1.zw))) {