mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 02:48:12 +08:00
Restore functionality of GPU infrastructure (#1797)
* Update gpu nodes to compile again Restructure `gpu-executor` and `wgpu-executor` And libssl to nix shell Fix graphene-cli and add half percision color format Fix texture scaling Remove vulkan executor Fix compile errors Improve execution request deduplication * Fix warnings * Fix graph compile issues * Code review * Remove test file * Fix lint * Wip make node futures send * Make futures Send on non wasm targets * Fix warnings * Fix nested use of block_on --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use core::hash::Hash;
|
||||
use half::f16;
|
||||
|
||||
use dyn_any::{DynAny, StaticType};
|
||||
#[cfg(feature = "serde")]
|
||||
@@ -14,6 +15,78 @@ use super::{
|
||||
discrete_srgb::{float_to_srgb_u8, srgb_u8_to_float},
|
||||
Alpha, AssociatedAlpha, Luminance, LuminanceMut, Pixel, RGBMut, Rec709Primaries, RGB, SRGB,
|
||||
};
|
||||
#[repr(C)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, DynAny, Pod, Zeroable)]
|
||||
pub struct RGBA16F {
|
||||
red: f16,
|
||||
green: f16,
|
||||
blue: f16,
|
||||
alpha: f16,
|
||||
}
|
||||
|
||||
impl From<Color> for RGBA16F {
|
||||
#[inline(always)]
|
||||
fn from(c: Color) -> Self {
|
||||
Self {
|
||||
red: f16::from_f32(c.r()),
|
||||
green: f16::from_f32(c.g()),
|
||||
blue: f16::from_f32(c.b()),
|
||||
alpha: f16::from_f32(c.a()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Luminance for RGBA16F {
|
||||
type LuminanceChannel = f32;
|
||||
#[inline(always)]
|
||||
fn luminance(&self) -> f32 {
|
||||
// TODO: verify this is correct for sRGB
|
||||
0.2126 * self.red() + 0.7152 * self.green() + 0.0722 * self.blue()
|
||||
}
|
||||
}
|
||||
|
||||
impl RGB for RGBA16F {
|
||||
type ColorChannel = f32;
|
||||
#[inline(always)]
|
||||
fn red(&self) -> f32 {
|
||||
self.red.to_f32()
|
||||
}
|
||||
#[inline(always)]
|
||||
fn green(&self) -> f32 {
|
||||
self.green.to_f32()
|
||||
}
|
||||
#[inline(always)]
|
||||
fn blue(&self) -> f32 {
|
||||
self.blue.to_f32()
|
||||
}
|
||||
}
|
||||
|
||||
impl Rec709Primaries for RGBA16F {}
|
||||
|
||||
impl Alpha for RGBA16F {
|
||||
type AlphaChannel = f32;
|
||||
#[inline(always)]
|
||||
fn alpha(&self) -> f32 {
|
||||
self.alpha.to_f32() / 255.
|
||||
}
|
||||
|
||||
const TRANSPARENT: Self = RGBA16F {
|
||||
red: f16::from_f32_const(0.),
|
||||
green: f16::from_f32_const(0.),
|
||||
blue: f16::from_f32_const(0.),
|
||||
alpha: f16::from_f32_const(0.),
|
||||
};
|
||||
|
||||
fn multiplied_alpha(&self, alpha: Self::AlphaChannel) -> Self {
|
||||
let alpha = alpha * 255.;
|
||||
let mut result = *self;
|
||||
result.alpha = f16::from_f32(alpha * self.alpha());
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
impl Pixel for RGBA16F {}
|
||||
|
||||
#[repr(C)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
@@ -33,7 +106,7 @@ impl From<Color> for SRGBA8 {
|
||||
red: float_to_srgb_u8(c.r()),
|
||||
green: float_to_srgb_u8(c.g()),
|
||||
blue: float_to_srgb_u8(c.b()),
|
||||
alpha: (c.a() * 255.0) as u8,
|
||||
alpha: (c.a() * 255.) as u8,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -45,7 +118,7 @@ impl From<SRGBA8> for Color {
|
||||
red: srgb_u8_to_float(color.red),
|
||||
green: srgb_u8_to_float(color.green),
|
||||
blue: srgb_u8_to_float(color.blue),
|
||||
alpha: color.alpha as f32 / 255.0,
|
||||
alpha: color.alpha as f32 / 255.,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,15 +136,15 @@ impl RGB for SRGBA8 {
|
||||
type ColorChannel = f32;
|
||||
#[inline(always)]
|
||||
fn red(&self) -> f32 {
|
||||
self.red as f32 / 255.0
|
||||
self.red as f32 / 255.
|
||||
}
|
||||
#[inline(always)]
|
||||
fn green(&self) -> f32 {
|
||||
self.green as f32 / 255.0
|
||||
self.green as f32 / 255.
|
||||
}
|
||||
#[inline(always)]
|
||||
fn blue(&self) -> f32 {
|
||||
self.blue as f32 / 255.0
|
||||
self.blue as f32 / 255.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,13 +155,13 @@ impl Alpha for SRGBA8 {
|
||||
type AlphaChannel = f32;
|
||||
#[inline(always)]
|
||||
fn alpha(&self) -> f32 {
|
||||
self.alpha as f32 / 255.0
|
||||
self.alpha as f32 / 255.
|
||||
}
|
||||
|
||||
const TRANSPARENT: Self = SRGBA8 { red: 0, green: 0, blue: 0, alpha: 0 };
|
||||
|
||||
fn multiplied_alpha(&self, alpha: Self::AlphaChannel) -> Self {
|
||||
let alpha = alpha * 255.0;
|
||||
let alpha = alpha * 255.;
|
||||
let mut result = *self;
|
||||
result.alpha = (alpha * self.alpha()) as u8;
|
||||
result
|
||||
@@ -338,7 +411,7 @@ impl Color {
|
||||
#[inline(always)]
|
||||
pub fn from_rgba8_srgb(red: u8, green: u8, blue: u8, alpha: u8) -> Color {
|
||||
let alpha = alpha as f32 / 255.;
|
||||
let map_range = |int_color| int_color as f32 / 255.0;
|
||||
let map_range = |int_color| int_color as f32 / 255.;
|
||||
Color {
|
||||
red: map_range(red),
|
||||
green: map_range(green),
|
||||
|
||||
Reference in New Issue
Block a user