mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 02:48:12 +08:00
Shaders: graster-nodes no-std fixups (#2984)
* wgpu-executor: remove useless features * wgpu-executor: cleanup copy-pasted code * gcore-shaders: no_std fixups
This commit is contained in:
@@ -7,7 +7,7 @@ authors = ["Graphite Authors <contact@graphite.rs>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
|
||||
[features]
|
||||
std = ["dep:dyn-any", "dep:serde", "dep:specta", "dep:log"]
|
||||
std = ["dep:dyn-any", "dep:serde", "dep:specta", "dep:log", "half/std", "half/serde"]
|
||||
|
||||
[dependencies]
|
||||
# Local std dependencies
|
||||
@@ -16,7 +16,7 @@ dyn-any = { workspace = true, optional = true }
|
||||
# Workspace dependencies
|
||||
bytemuck = { workspace = true }
|
||||
glam = { version = "0.29", default-features = false, features = ["nostd-libm", "scalar-math"] }
|
||||
half = { workspace = true }
|
||||
half = { workspace = true, default-features = false }
|
||||
num-derive = { workspace = true }
|
||||
num-traits = { workspace = true }
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use core::fmt::Display;
|
||||
use core::hash::{Hash, Hasher};
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use num_traits::float::Float;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, specta::Type, serde::Serialize, serde::Deserialize))]
|
||||
@@ -24,7 +26,7 @@ impl Hash for AlphaBlending {
|
||||
}
|
||||
}
|
||||
impl Display for AlphaBlending {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
let round = |x: f32| (x * 1e3).round() / 1e3;
|
||||
write!(
|
||||
f,
|
||||
@@ -203,7 +205,7 @@ impl BlendMode {
|
||||
}
|
||||
|
||||
impl Display for BlendMode {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
match self {
|
||||
// Normal group
|
||||
BlendMode::Normal => write!(f, "Normal"),
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
use super::color_traits::{Alpha, AlphaMut, AssociatedAlpha, Luminance, LuminanceMut, Pixel, RGB, RGBMut, Rec709Primaries, SRGB};
|
||||
use super::discrete_srgb::{float_to_srgb_u8, srgb_u8_to_float};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use core::fmt::Debug;
|
||||
use core::hash::Hash;
|
||||
use half::f16;
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::Euclid;
|
||||
use num_traits::Euclid;
|
||||
#[cfg(target_arch = "spirv")]
|
||||
use spirv_std::num_traits::float::Float;
|
||||
use num_traits::float::Float;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Default, Clone, Copy, PartialEq, Pod, Zeroable)]
|
||||
#[derive(Default, Clone, Copy, PartialEq, Pod, Zeroable)]
|
||||
#[cfg_attr(not(target_arch = "spirv"), derive(Debug))]
|
||||
#[cfg_attr(feature = "std", derive(dyn_any::DynAny, serde::Serialize, serde::Deserialize))]
|
||||
pub struct RGBA16F {
|
||||
red: f16,
|
||||
@@ -18,6 +20,14 @@ pub struct RGBA16F {
|
||||
alpha: f16,
|
||||
}
|
||||
|
||||
/// hack around half still masking out impl Debug for f16 on spirv
|
||||
#[cfg(target_arch = "spirv")]
|
||||
impl core::fmt::Debug for RGBA16F {
|
||||
fn fmt(&self, _f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Color> for RGBA16F {
|
||||
#[inline(always)]
|
||||
fn from(c: Color) -> Self {
|
||||
@@ -215,7 +225,7 @@ pub struct Color {
|
||||
|
||||
#[allow(clippy::derived_hash_with_manual_eq)]
|
||||
impl Hash for Color {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
|
||||
self.red.to_bits().hash(state);
|
||||
self.green.to_bits().hash(state);
|
||||
self.blue.to_bits().hash(state);
|
||||
@@ -256,7 +266,7 @@ impl AlphaMut for Color {
|
||||
}
|
||||
|
||||
impl Pixel for Color {
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
#[cfg(feature = "std")]
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
self.to_rgba8_srgb().to_vec()
|
||||
}
|
||||
@@ -793,6 +803,7 @@ impl Color {
|
||||
/// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
|
||||
/// assert_eq!("3240a261", color.to_rgba_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
|
||||
/// ```
|
||||
#[cfg(feature = "std")]
|
||||
pub fn to_rgba_hex_srgb(&self) -> String {
|
||||
let gamma = self.to_gamma_srgb();
|
||||
format!(
|
||||
@@ -810,6 +821,7 @@ impl Color {
|
||||
/// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
|
||||
/// assert_eq!("3240a2", color.to_rgb_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
|
||||
/// ```
|
||||
#[cfg(feature = "std")]
|
||||
pub fn to_rgb_hex_srgb(&self) -> String {
|
||||
self.to_gamma_srgb().to_rgb_hex_srgb_from_gamma()
|
||||
}
|
||||
@@ -820,6 +832,7 @@ impl Color {
|
||||
/// let color = Color::from_rgba8_srgb(0x52, 0x67, 0xFA, 0x61); // Premultiplied alpha
|
||||
/// assert_eq!("3240a2", color.to_rgb_hex_srgb()); // Equivalent hex incorporating premultiplied alpha
|
||||
/// ```
|
||||
#[cfg(feature = "std")]
|
||||
pub fn to_rgb_hex_srgb_from_gamma(&self) -> String {
|
||||
format!("{:02x?}{:02x?}{:02x?}", (self.r() * 255.) as u8, (self.g() * 255.) as u8, (self.b() * 255.) as u8)
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ pub trait Linear {
|
||||
fn lerp(self, other: Self, value: Self) -> Self
|
||||
where
|
||||
Self: Sized + Copy,
|
||||
Self: std::ops::Sub<Self, Output = Self>,
|
||||
Self: std::ops::Mul<Self, Output = Self>,
|
||||
Self: std::ops::Add<Self, Output = Self>,
|
||||
Self: core::ops::Sub<Self, Output = Self>,
|
||||
Self: core::ops::Mul<Self, Output = Self>,
|
||||
Self: core::ops::Add<Self, Output = Self>,
|
||||
{
|
||||
self + (other - self) * value
|
||||
}
|
||||
@@ -97,7 +97,7 @@ pub trait SRGB: Rec709Primaries {}
|
||||
|
||||
// TODO: Come up with a better name for this trait
|
||||
pub trait Pixel: Clone + Pod + Zeroable + Default {
|
||||
#[cfg(not(target_arch = "spirv"))]
|
||||
#[cfg(feature = "std")]
|
||||
fn to_bytes(&self) -> Vec<u8> {
|
||||
bytemuck::bytes_of(self).to_vec()
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ pub fn float_to_srgb_u8(mut f: f32) -> u8 {
|
||||
// We clamped f to [0, 1], and the integer representations
|
||||
// of the positive finite non-NaN floats are monotonic.
|
||||
// This makes the later LUT lookup panicless.
|
||||
unsafe { std::hint::unreachable_unchecked() }
|
||||
unsafe { core::hint::unreachable_unchecked() }
|
||||
}
|
||||
|
||||
// Compute a piecewise linear interpolation that is always
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
pub mod blending;
|
||||
pub mod choice_type;
|
||||
pub mod color;
|
||||
|
||||
@@ -20,5 +20,6 @@ pub mod types {
|
||||
/// DVec2 with px unit
|
||||
pub type PixelSize = glam::DVec2;
|
||||
/// String with one or more than one line
|
||||
#[cfg(feature = "std")]
|
||||
pub type TextArea = String;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user