fix(gpu): preserve CSP shaper channels on software Vulkan

This commit is contained in:
Dylan M. Taylor
2026-11-15 23:56:13 -05:00
parent 3678cc9bec
commit f0a5783a82
2 changed files with 37 additions and 14 deletions
+23 -14
View File
@@ -130,12 +130,15 @@ fn fxl_shape(at: u32, n: u32, x: f32, flip: bool) -> f32 {
// partition_point(|p| p.x < x).
var lo = 0u;
var hi = n;
while (lo < hi) {
let mid = (lo + hi) / 2u;
if (data[at + mid * 2u + kx] < x) {
lo = mid + 1u;
} else {
hi = mid;
// Bound the partition search as for inverse 1D LUTs below.
for (var step = 0u; step < 32u; step++) {
if (lo < hi) {
let mid = lo + (hi - lo) / 2u;
if (data[at + mid * 2u + kx] < x) {
lo = mid + 1u;
} else {
hi = mid;
}
}
}
let i = clamp(lo, 1u, n - 1u);
@@ -156,13 +159,22 @@ fn fxl_shaper_at(s: u32, k: u32) -> vec2<u32> {
return vec2<u32>(at, u32(data[s + k]));
}
// Evaluate independent shaper channels without dynamically writing vector lanes.
fn fxl_shaper_apply(sh: u32, c: vec3<f32>, flip: bool) -> vec3<f32> {
let r = fxl_shaper_at(sh, 0u);
let g = fxl_shaper_at(sh, 1u);
let b = fxl_shaper_at(sh, 2u);
return vec3<f32>(
fxl_shape(r.x, r.y, c.x, flip),
fxl_shape(g.x, g.y, c.y, flip),
fxl_shape(b.x, b.y, c.z, flip)
);
}
fn fxl_file_fwd(o: u32, sh: i32, c0: vec3<f32>, interp: u32) -> vec3<f32> {
var c = c0;
if (sh >= 0) {
for (var k = 0u; k < 3u; k++) {
let a = fxl_shaper_at(u32(sh), k);
c[k] = fxl_shape(a.x, a.y, c[k], false);
}
c = fxl_shaper_apply(u32(sh), c, false);
}
return fxl_lut_apply(o, c, interp);
}
@@ -209,10 +221,7 @@ fn fxl_file(o: u32, sh: i32, c: vec3<f32>, interp: u32, inverse: bool) -> vec3<f
x = vec3<f32>(fxl_inv_1d(o, 0u, c.x), fxl_inv_1d(o, 1u, c.y), fxl_inv_1d(o, 2u, c.z));
}
if (sh >= 0) {
for (var k = 0u; k < 3u; k++) {
let a = fxl_shaper_at(u32(sh), k);
x[k] = fxl_shape(a.x, a.y, x[k], true);
}
x = fxl_shaper_apply(u32(sh), x, true);
}
return x;
}
+14
View File
@@ -112,6 +112,20 @@ fn profile_conversion_on_a_fresh_device_matches_cpu() {
effect_direct("ec.utility.colorprofileconverter", &[("inputProfile", e(1)), ("outputProfile", e(3)), ("intent", e(0))], false);
}
// Unequal CSP channel point counts exercise shaper offsets on a fresh device.
#[test]
fn csp_shaper_on_a_fresh_device_matches_cpu() {
effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("interpolation", e(1))], false);
effect_direct("ec.color.ociofile", &[("file", s(&csp())), ("direction", e(1))], false);
}
// A 1D CSP takes the direct inverse-shaper path (flip=true), unlike a 3D CSP.
#[test]
fn inverse_1d_csp_shaper_on_a_fresh_device_matches_cpu() {
let lut = "CSPLUTV100\n1D\n3\n0 0.5 1\n0 0.3 1\n2\n0 1\n0 1\n4\n0 0.2 0.6 1\n0 0.4 0.7 1\n2\n0 0 0\n1 1 1\n";
effect_direct("ec.color.ociofile", &[("file", s(lut)), ("direction", e(1))], false);
}
#[test]
fn ocio_file_transform() {
for interp in 1..4 {