1
0
Fork 0
forked from wry/wry

all: replace enum-map by linearize

This commit is contained in:
Julian Orth 2025-01-22 14:56:14 +01:00
parent b64bb52051
commit bd303a7ea5
6 changed files with 307 additions and 293 deletions

561
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -57,7 +57,7 @@ gpu-alloc = "0.6.0"
gpu-alloc-ash = "0.7.0" gpu-alloc-ash = "0.7.0"
serde = { version = "1.0.196", features = ["derive"] } serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.128" serde_json = "1.0.128"
enum-map = "2.7.3" linearize = { version = "0.1.3", features = ["derive"] }
png = "0.17.13" png = "0.17.13"
rustc-demangle = { version = "0.1.24", optional = true } rustc-demangle = { version = "0.1.24", optional = true }
tracy-client-sys = { version = "0.24.1", features = ["ondemand", "manual-lifetime", "debuginfod"], optional = true } tracy-client-sys = { version = "0.24.1", features = ["ondemand", "manual-lifetime", "debuginfod"], optional = true }

View file

@ -229,7 +229,7 @@ pub fn buf_to_bytes(
let mut encoder = Encoder::new(&mut out, buf.width as _, buf.height as _); let mut encoder = Encoder::new(&mut out, buf.width as _, buf.height as _);
encoder.set_color(ColorType::Rgba); encoder.set_color(ColorType::Rgba);
encoder.set_depth(BitDepth::Eight); encoder.set_depth(BitDepth::Eight);
encoder.set_srgb(SrgbRenderingIntent::Perceptual); encoder.set_source_srgb(SrgbRenderingIntent::Perceptual);
let mut writer = encoder.write_header().unwrap(); let mut writer = encoder.write_header().unwrap();
writer.write_image_data(&image_data).unwrap(); writer.write_image_data(&image_data).unwrap();
} }

View file

@ -24,8 +24,8 @@ use {
}, },
}, },
ahash::AHashMap, ahash::AHashMap,
enum_map::{enum_map, Enum, EnumMap},
jay_config::video::GfxApi, jay_config::video::GfxApi,
linearize::{static_map, Linearize, StaticMap},
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
ffi::CString, ffi::CString,
@ -60,13 +60,13 @@ impl TexProg {
} }
} }
#[derive(Copy, Clone, PartialEq, Enum)] #[derive(Copy, Clone, PartialEq, Linearize)]
pub(in crate::gfx_apis::gl) enum TexCopyType { pub(in crate::gfx_apis::gl) enum TexCopyType {
Identity, Identity,
Multiply, Multiply,
} }
#[derive(Copy, Clone, PartialEq, Enum)] #[derive(Copy, Clone, PartialEq, Linearize)]
pub(in crate::gfx_apis::gl) enum TexSourceType { pub(in crate::gfx_apis::gl) enum TexSourceType {
Opaque, Opaque,
HasAlpha, HasAlpha,
@ -79,8 +79,8 @@ pub(in crate::gfx_apis::gl) struct GlRenderContext {
pub(crate) render_node: Rc<CString>, pub(crate) render_node: Rc<CString>,
pub(crate) tex_internal: EnumMap<TexCopyType, EnumMap<TexSourceType, TexProg>>, pub(crate) tex_internal: StaticMap<TexCopyType, StaticMap<TexSourceType, TexProg>>,
pub(crate) tex_external: Option<EnumMap<TexCopyType, EnumMap<TexSourceType, TexProg>>>, pub(crate) tex_external: Option<StaticMap<TexCopyType, StaticMap<TexSourceType, TexProg>>>,
pub(crate) fill_prog: GlProgram, pub(crate) fill_prog: GlProgram,
pub(crate) fill_prog_pos: GLint, pub(crate) fill_prog_pos: GLint,
@ -136,12 +136,12 @@ impl GlRenderContext {
Ok::<_, RenderError>(TexProg::from(prog, alpha_multiplier)) Ok::<_, RenderError>(TexProg::from(prog, alpha_multiplier))
} }
}; };
Ok::<_, RenderError>(enum_map! { Ok::<_, RenderError>(static_map! {
TexCopyType::Identity => enum_map! { TexCopyType::Identity => static_map! {
TexSourceType::Opaque => create_program(false, false)?, TexSourceType::Opaque => create_program(false, false)?,
TexSourceType::HasAlpha => create_program(false, true)?, TexSourceType::HasAlpha => create_program(false, true)?,
}, },
TexCopyType::Multiply => enum_map! { TexCopyType::Multiply => static_map! {
TexSourceType::Opaque => create_program(true, false)?, TexSourceType::Opaque => create_program(true, false)?,
TexSourceType::HasAlpha => create_program(true, true)?, TexSourceType::HasAlpha => create_program(true, true)?,
}, },

View file

@ -43,8 +43,8 @@ use {
}, },
Device, Device,
}, },
enum_map::{enum_map, Enum, EnumMap},
isnt::std_1::collections::IsntHashMapExt, isnt::std_1::collections::IsntHashMapExt,
linearize::{static_map, Linearize, StaticMap},
std::{ std::{
cell::{Cell, RefCell}, cell::{Cell, RefCell},
fmt::{Debug, Formatter}, fmt::{Debug, Formatter},
@ -109,13 +109,13 @@ pub(super) struct UsedTexture {
release_sync: ReleaseSync, release_sync: ReleaseSync,
} }
#[derive(Enum)] #[derive(Linearize)]
pub(super) enum TexCopyType { pub(super) enum TexCopyType {
Identity, Identity,
Multiply, Multiply,
} }
#[derive(Enum)] #[derive(Linearize)]
pub(super) enum TexSourceType { pub(super) enum TexSourceType {
Opaque, Opaque,
HasAlpha, HasAlpha,
@ -145,7 +145,7 @@ pub(super) struct PendingFrame {
pub(super) struct VulkanFormatPipelines { pub(super) struct VulkanFormatPipelines {
pub(super) fill: Rc<VulkanPipeline>, pub(super) fill: Rc<VulkanPipeline>,
pub(super) tex: EnumMap<TexCopyType, EnumMap<TexSourceType, Rc<VulkanPipeline>>>, pub(super) tex: StaticMap<TexCopyType, StaticMap<TexSourceType, Rc<VulkanPipeline>>>,
} }
impl VulkanDevice { impl VulkanDevice {
@ -276,12 +276,12 @@ impl VulkanRenderer {
let tex_mult_alpha = create_tex_mult_pipeline(&self.tex_frag_mult_alpha_shader)?; let tex_mult_alpha = create_tex_mult_pipeline(&self.tex_frag_mult_alpha_shader)?;
let pipelines = Rc::new(VulkanFormatPipelines { let pipelines = Rc::new(VulkanFormatPipelines {
fill, fill,
tex: enum_map! { tex: static_map! {
TexCopyType::Identity => enum_map! { TexCopyType::Identity => static_map! {
TexSourceType::HasAlpha => tex_alpha.clone(), TexSourceType::HasAlpha => tex_alpha.clone(),
TexSourceType::Opaque => tex_opaque.clone(), TexSourceType::Opaque => tex_opaque.clone(),
}, },
TexCopyType::Multiply => enum_map! { TexCopyType::Multiply => static_map! {
TexSourceType::HasAlpha => tex_mult_alpha.clone(), TexSourceType::HasAlpha => tex_mult_alpha.clone(),
TexSourceType::Opaque => tex_mult_opaque.clone(), TexSourceType::Opaque => tex_mult_opaque.clone(),
}, },

View file

@ -165,8 +165,9 @@ mod leaks {
objs.sort_by_key(|o| o.0); objs.sort_by_key(|o| o.0);
log::info!("Client {} leaked {} objects", objs[0].1.client, objs.len()); log::info!("Client {} leaked {} objects", objs[0].1.client, objs.len());
for (_, obj) in objs { for (_, obj) in objs {
let time = let time = chrono::DateTime::from_timestamp(obj.time.0, obj.time.1)
chrono::NaiveDateTime::from_timestamp_opt(obj.time.0, obj.time.1).unwrap(); .unwrap()
.naive_utc();
log::info!(" [{}] {}", time.format("%H:%M:%S%.3f"), obj.ty,); log::info!(" [{}] {}", time.format("%H:%M:%S%.3f"), obj.ty,);
match find_allocation_containing(obj.addr) { match find_allocation_containing(obj.addr) {
Some(mut alloc) => { Some(mut alloc) => {