-
Notifications
You must be signed in to change notification settings - Fork 42
metal: add support for plane color pipelines #1116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 contains hidden or 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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| clippy::needless_lifetimes | ||
| )] | ||
|
|
||
| pub mod lut; | ||
| pub mod qoi; | ||
| pub mod rect; | ||
| pub mod tf; | ||
|
|
||
This file contains hidden or 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,63 @@ | ||
| pub use generated::*; | ||
|
|
||
| #[rustfmt::skip] | ||
| mod generated; | ||
|
|
||
| #[inline(never)] | ||
| fn fill(res: &mut [f32], mut src_mul: f32, dst_mul: f32, tf: impl Fn(f32) -> f32 + Copy) { | ||
| src_mul /= (res.len() - 1) as f32; | ||
| #[expect(clippy::needless_range_loop)] | ||
| for i in 0..res.len() { | ||
| let v = i as f32 * src_mul; | ||
| let v = tf(v); | ||
| let v = v * dst_mul; | ||
| res[i] = v; | ||
| } | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub fn fill_lut_3d(m: [[f32; 4]; 4], size: usize) -> Vec<[u32; 4]> { | ||
| let mut out = vec![[0u32; 4]; size * size * size]; | ||
| let mul = 1.0 / (size - 1) as f32; | ||
| let idx = 0; | ||
| #[rustfmt::skip] | ||
|
mahkoh marked this conversation as resolved.
|
||
| let v = [ | ||
| m[0][3], | ||
| m[1][3], | ||
| m[2][3], | ||
| ]; | ||
| for b in 0..size { | ||
| let bf = b as f32 * mul; | ||
| let idx = idx * size + b; | ||
| let v = [ | ||
| v[0] + m[0][2] * bf, | ||
| v[1] + m[1][2] * bf, | ||
| v[2] + m[2][2] * bf, | ||
| ]; | ||
| for g in 0..size { | ||
| let gf = g as f32 * mul; | ||
| let idx = idx * size + g; | ||
| let v = [ | ||
| v[0] + m[0][1] * gf, | ||
| v[1] + m[1][1] * gf, | ||
| v[2] + m[2][1] * gf, | ||
| ]; | ||
| for r in 0..size { | ||
| let rf = r as f32 * mul; | ||
| let idx = idx * size + r; | ||
| let v = [ | ||
| v[0] + m[0][0] * rf, | ||
| v[1] + m[1][0] * rf, | ||
| v[2] + m[2][0] * rf, | ||
| ]; | ||
| out[idx] = [ | ||
| (v[0] as f64 * u32::MAX as f64) as u32, | ||
| (v[1] as f64 * u32::MAX as f64) as u32, | ||
| (v[2] as f64 * u32::MAX as f64) as u32, | ||
| 0, | ||
| ]; | ||
| } | ||
| } | ||
| } | ||
| out | ||
| } | ||
This file contains hidden or 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,175 @@ | ||
| use crate::lut::fill; | ||
| use crate::tf::*; | ||
|
|
||
| #[inline(never)] | ||
| pub fn fill_eotf(res: &mut [f32], src_mul: f32, dst_mul: f32, i: AlgoEotf) { | ||
| match i { | ||
| AlgoEotf::Linear => fill(res, src_mul, dst_mul, eotfs::linear::<()>), | ||
| AlgoEotf::St2084Pq => fill(res, src_mul, dst_mul, eotfs::st2084_pq::<()>), | ||
| AlgoEotf::Gamma22 => fill(res, src_mul, dst_mul, eotfs::gamma22::<()>), | ||
| AlgoEotf::Gamma24 => fill(res, src_mul, dst_mul, eotfs::gamma24::<()>), | ||
| AlgoEotf::Gamma28 => fill(res, src_mul, dst_mul, eotfs::gamma28::<()>), | ||
| AlgoEotf::St240 => fill(res, src_mul, dst_mul, eotfs::st240::<()>), | ||
| AlgoEotf::Log100 => fill(res, src_mul, dst_mul, eotfs::log100::<()>), | ||
| AlgoEotf::Log316 => fill(res, src_mul, dst_mul, eotfs::log316::<()>), | ||
| AlgoEotf::St428 => fill(res, src_mul, dst_mul, eotfs::st428::<()>), | ||
| AlgoEotf::CompoundPower24 => fill(res, src_mul, dst_mul, eotfs::compound_power_2_4::<()>), | ||
| AlgoEotf::Bt1886(tp) => { | ||
| let tf = eotfs::bt1886::<()>(tp); | ||
| fill(res, src_mul, dst_mul, tf) | ||
| } | ||
| AlgoEotf::Pow(tp) => { | ||
| let tf = eotfs::pow::<()>(tp); | ||
| fill(res, src_mul, dst_mul, tf) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub fn fill_inv_eotf(res: &mut [f32], src_mul: f32, dst_mul: f32, i: AlgoEotf) { | ||
| match i { | ||
| AlgoEotf::Linear => fill(res, src_mul, dst_mul, inv_eotfs::linear::<()>), | ||
| AlgoEotf::St2084Pq => fill(res, src_mul, dst_mul, inv_eotfs::st2084_pq::<()>), | ||
| AlgoEotf::Gamma22 => fill(res, src_mul, dst_mul, inv_eotfs::gamma22::<()>), | ||
| AlgoEotf::Gamma24 => fill(res, src_mul, dst_mul, inv_eotfs::gamma24::<()>), | ||
| AlgoEotf::Gamma28 => fill(res, src_mul, dst_mul, inv_eotfs::gamma28::<()>), | ||
| AlgoEotf::St240 => fill(res, src_mul, dst_mul, inv_eotfs::st240::<()>), | ||
| AlgoEotf::Log100 => fill(res, src_mul, dst_mul, inv_eotfs::log100::<()>), | ||
| AlgoEotf::Log316 => fill(res, src_mul, dst_mul, inv_eotfs::log316::<()>), | ||
| AlgoEotf::St428 => fill(res, src_mul, dst_mul, inv_eotfs::st428::<()>), | ||
| AlgoEotf::CompoundPower24 => { | ||
| fill(res, src_mul, dst_mul, inv_eotfs::compound_power_2_4::<()>) | ||
| } | ||
| AlgoEotf::Bt1886(tp) => { | ||
| let tf = inv_eotfs::bt1886::<()>(tp); | ||
| fill(res, src_mul, dst_mul, tf) | ||
| } | ||
| AlgoEotf::Pow(tp) => { | ||
| let tf = inv_eotfs::pow::<()>(tp); | ||
| fill(res, src_mul, dst_mul, tf) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[inline(never)] | ||
| pub fn fill_dual(res: &mut [f32], src_mul: f32, dst_mul: f32, i: AlgoEotf, o: AlgoEotf) { | ||
| #[inline(always)] | ||
| fn handle_dst( | ||
| res: &mut [f32], | ||
| src_mul: f32, | ||
| dst_mul: f32, | ||
| o: AlgoEotf, | ||
| sf: impl Fn(f32) -> f32 + Copy, | ||
| ) { | ||
| match o { | ||
| AlgoEotf::Linear => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::linear::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::St2084Pq => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::st2084_pq::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::Gamma22 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::gamma22::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::Gamma24 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::gamma24::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::Gamma28 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::gamma28::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::St240 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::st240::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::Log100 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::log100::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::Log316 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::log316::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::St428 => { | ||
| fill(res, src_mul, dst_mul, |v| inv_eotfs::st428::<()>(sf(v))); | ||
| } | ||
| AlgoEotf::CompoundPower24 => { | ||
| fill(res, src_mul, dst_mul, |v| { | ||
| inv_eotfs::compound_power_2_4::<()>(sf(v)) | ||
| }); | ||
| } | ||
| AlgoEotf::Bt1886(tp) => { | ||
| #[inline(never)] | ||
| fn f( | ||
| res: &mut [f32], | ||
| src_mul: f32, | ||
| dst_mul: f32, | ||
| tp: f32, | ||
| sf: impl Fn(f32) -> f32 + Copy, | ||
| ) { | ||
| let tf = inv_eotfs::bt1886::<()>(tp); | ||
| fill(res, src_mul, dst_mul, |v| tf(sf(v))) | ||
| } | ||
| f(res, src_mul, dst_mul, tp, sf); | ||
| } | ||
| AlgoEotf::Pow(tp) => { | ||
| #[inline(never)] | ||
| fn f( | ||
| res: &mut [f32], | ||
| src_mul: f32, | ||
| dst_mul: f32, | ||
| tp: f32, | ||
| sf: impl Fn(f32) -> f32 + Copy, | ||
| ) { | ||
| let tf = inv_eotfs::pow::<()>(tp); | ||
| fill(res, src_mul, dst_mul, |v| tf(sf(v))) | ||
| } | ||
| f(res, src_mul, dst_mul, tp, sf); | ||
| } | ||
| } | ||
| } | ||
| match i { | ||
| AlgoEotf::Linear => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::linear::<()>); | ||
| } | ||
| AlgoEotf::St2084Pq => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::st2084_pq::<()>); | ||
| } | ||
| AlgoEotf::Gamma22 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::gamma22::<()>); | ||
| } | ||
| AlgoEotf::Gamma24 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::gamma24::<()>); | ||
| } | ||
| AlgoEotf::Gamma28 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::gamma28::<()>); | ||
| } | ||
| AlgoEotf::St240 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::st240::<()>); | ||
| } | ||
| AlgoEotf::Log100 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::log100::<()>); | ||
| } | ||
| AlgoEotf::Log316 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::log316::<()>); | ||
| } | ||
| AlgoEotf::St428 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::st428::<()>); | ||
| } | ||
| AlgoEotf::CompoundPower24 => { | ||
| handle_dst(res, src_mul, dst_mul, o, eotfs::compound_power_2_4::<()>); | ||
| } | ||
| AlgoEotf::Bt1886(sp) => { | ||
| #[inline(never)] | ||
| fn f(res: &mut [f32], src_mul: f32, dst_mul: f32, o: AlgoEotf, sp: f32) { | ||
| let sf = eotfs::bt1886::<()>(sp); | ||
| handle_dst(res, src_mul, dst_mul, o, sf); | ||
| } | ||
| f(res, src_mul, dst_mul, o, sp); | ||
| } | ||
| AlgoEotf::Pow(sp) => { | ||
| #[inline(never)] | ||
| fn f(res: &mut [f32], src_mul: f32, dst_mul: f32, o: AlgoEotf, sp: f32) { | ||
| let sf = eotfs::pow::<()>(sp); | ||
| handle_dst(res, src_mul, dst_mul, o, sf); | ||
| } | ||
| f(res, src_mul, dst_mul, o, sp); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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 contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.