| ... | @@ -105,6 +105,45 @@ pub struct Engine { | ... | @@ -105,6 +105,45 @@ pub struct Engine { |
| 105 | pub hiq: bool, | 105 | pub hiq: bool, |
| 106 | } | 106 | } |
| 107 | | 107 | |
| | 108 | fn is_video_filename(filename: &str) -> bool { |
| | 109 | let Some(ext) = std::path::Path::new(filename) |
| | 110 | .extension() |
| | 111 | .and_then(|e| e.to_str()) |
| | 112 | else { |
| | 113 | return false; |
| | 114 | }; |
| | 115 | matches!( |
| | 116 | ext.to_ascii_lowercase().as_str(), |
| | 117 | "mov" | "mp4" | "m4v" | "mkv" | "avi" | "webm" | "mxf" |
| | 118 | ) |
| | 119 | } |
| | 120 | |
| | 121 | fn is_static_loader_node(node: &Node) -> bool { |
| | 122 | let Some(clip) = node.clips.first() else { |
| | 123 | return false; |
| | 124 | }; |
| | 125 | if clip.length.unwrap_or(1) > 1 { |
| | 126 | return false; |
| | 127 | } |
| | 128 | if is_video_filename(&clip.filename) { |
| | 129 | return false; |
| | 130 | } |
| | 131 | if clip |
| | 132 | .alternate_filename |
| | 133 | .as_deref() |
| | 134 | .is_some_and(is_video_filename) |
| | 135 | { |
| | 136 | return false; |
| | 137 | } |
| | 138 | if node |
| | 139 | .static_str("ProxyFilename") |
| | 140 | .is_some_and(is_video_filename) |
| | 141 | { |
| | 142 | return false; |
| | 143 | } |
| | 144 | true |
| | 145 | } |
| | 146 | |
| 108 | impl Engine { | 147 | impl Engine { |
| 109 | pub fn new(device: wgpu::Device, queue: wgpu::Queue) -> Self { | 148 | pub fn new(device: wgpu::Device, queue: wgpu::Queue) -> Self { |
| 110 | let supports_f32_filter = device.features().contains(wgpu::Features::FLOAT32_FILTERABLE); | 149 | let supports_f32_filter = device.features().contains(wgpu::Features::FLOAT32_FILTERABLE); |
| ... | @@ -508,13 +547,16 @@ impl Engine { | ... | @@ -508,13 +547,16 @@ impl Engine { |
| 508 | } | 547 | } |
| 509 | let res = self.eval_node_inner(comp, id, time, frame_i, enc, visiting, stats); | 548 | let res = self.eval_node_inner(comp, id, time, frame_i, enc, visiting, stats); |
| 510 | visiting.remove(&(id, time_key)); | 549 | visiting.remove(&(id, time_key)); |
| 511 | if res.content_hash != 0 | 550 | if res.content_hash != 0 { |
| 512 | && matches!( | 551 | let node = comp.node(id); |
| 513 | comp.node(id).kind.as_str(), | 552 | let sticky = match node.kind.as_str() { |
| 514 | "Loader" | "TextPlus" | "Renderer3D" | "pRender" | "PolylineMask" | "WandMask" | 553 | "Loader" => is_static_loader_node(node), |
| 515 | ) | 554 | "TextPlus" | "Renderer3D" | "pRender" | "PolylineMask" | "WandMask" => true, |
| 516 | { | 555 | _ => false, |
| 517 | self.cache.mark_entry_sticky(res.content_hash); | 556 | }; |
| | 557 | if sticky { |
| | 558 | self.cache.mark_entry_sticky(res.content_hash); |
| | 559 | } |
| 518 | } | 560 | } |
| 519 | self.frame_memo.insert((id, time_key, memo_sz), res.clone()); | 561 | self.frame_memo.insert((id, time_key, memo_sz), res.clone()); |
| 520 | res | 562 | res |
| ... | @@ -1590,4 +1632,156 @@ Composition { | ... | @@ -1590,4 +1632,156 @@ Composition { |
| 1590 | assert!(eng.cache.vram_drops() > 0); | 1632 | assert!(eng.cache.vram_drops() > 0); |
| 1591 | assert_eq!(eng.last_bg_vram_drops.get(), eng.cache.vram_drops()); | 1633 | assert_eq!(eng.last_bg_vram_drops.get(), eng.cache.vram_drops()); |
| 1592 | } | 1634 | } |
| | 1635 | |
| | 1636 | #[test] |
| | 1637 | fn static_still_loader_is_sticky_while_video_and_sequence_loaders_are_not() { |
| | 1638 | let dir = std::env::temp_dir().join("fission_sticky_loader_tiering_test"); |
| | 1639 | let _ = std::fs::remove_dir_all(&dir); |
| | 1640 | std::fs::create_dir_all(&dir).unwrap(); |
| | 1641 | |
| | 1642 | let still_path = dir.join("still.png"); |
| | 1643 | image::RgbaImage::from_pixel(32, 32, image::Rgba([200, 100, 50, 255])) |
| | 1644 | .save(&still_path) |
| | 1645 | .unwrap(); |
| | 1646 | |
| | 1647 | for i in 0..3 { |
| | 1648 | let seq_path = dir.join(format!("seq_{i:04}.png")); |
| | 1649 | image::RgbaImage::from_pixel(32, 32, image::Rgba([40 * i as u8, 120, 200, 255])) |
| | 1650 | .save(&seq_path) |
| | 1651 | .unwrap(); |
| | 1652 | } |
| | 1653 | let seq_first = dir.join("seq_0000.png"); |
| | 1654 | |
| | 1655 | let video_path = dir.join("anim.mp4"); |
| | 1656 | let has_video = std::process::Command::new("ffmpeg") |
| | 1657 | .args([ |
| | 1658 | "-y", |
| | 1659 | "-v", |
| | 1660 | "error", |
| | 1661 | "-f", |
| | 1662 | "lavfi", |
| | 1663 | "-i", |
| | 1664 | "testsrc2=size=64x64:rate=24:duration=0.5", |
| | 1665 | "-c:v", |
| | 1666 | "libx264", |
| | 1667 | "-pix_fmt", |
| | 1668 | "yuv420p", |
| | 1669 | ]) |
| | 1670 | .arg(&video_path) |
| | 1671 | .status() |
| | 1672 | .is_ok_and(|s| s.success()); |
| | 1673 | |
| | 1674 | let video_tool = if has_video { |
| | 1675 | format!( |
| | 1676 | r#" |
| | 1677 | VidLoader = Loader {{ |
| | 1678 | Clips = {{ |
| | 1679 | Clip {{ |
| | 1680 | ID = "Clip1", |
| | 1681 | Filename = "{}", |
| | 1682 | FormatID = "QuickTimeMovies", |
| | 1683 | Length = 12, |
| | 1684 | TrimIn = 0, |
| | 1685 | TrimOut = 11, |
| | 1686 | GlobalStart = 0, |
| | 1687 | GlobalEnd = 11, |
| | 1688 | }}, |
| | 1689 | }}, |
| | 1690 | }},"#, |
| | 1691 | video_path.to_string_lossy().replace('\\', "/") |
| | 1692 | ) |
| | 1693 | } else { |
| | 1694 | String::new() |
| | 1695 | }; |
| | 1696 | |
| | 1697 | let src = format!( |
| | 1698 | r#" |
| | 1699 | Composition {{ |
| | 1700 | CurrentTime = 0, |
| | 1701 | RenderRange = {{ 0, 5 }}, |
| | 1702 | GlobalRange = {{ 0, 5 }}, |
| | 1703 | Tools = ordered() {{ |
| | 1704 | StillLoader = Loader {{ |
| | 1705 | Clips = {{ |
| | 1706 | Clip {{ |
| | 1707 | ID = "Clip1", |
| | 1708 | Filename = "{}", |
| | 1709 | FormatID = "PNGFormat", |
| | 1710 | StartFrame = -1, |
| | 1711 | GlobalStart = 0, |
| | 1712 | GlobalEnd = 10, |
| | 1713 | }}, |
| | 1714 | }}, |
| | 1715 | }}, |
| | 1716 | SeqLoader = Loader {{ |
| | 1717 | Clips = {{ |
| | 1718 | Clip {{ |
| | 1719 | ID = "Clip1", |
| | 1720 | Filename = "{}", |
| | 1721 | FormatID = "PNGFormat", |
| | 1722 | StartFrame = 0, |
| | 1723 | Length = 3, |
| | 1724 | TrimIn = 0, |
| | 1725 | TrimOut = 2, |
| | 1726 | GlobalStart = 0, |
| | 1727 | GlobalEnd = 2, |
| | 1728 | }}, |
| | 1729 | }}, |
| | 1730 | }},{video_tool} |
| | 1731 | }}, |
| | 1732 | }} |
| | 1733 | "#, |
| | 1734 | still_path.to_string_lossy().replace('\\', "/"), |
| | 1735 | seq_first.to_string_lossy().replace('\\', "/"), |
| | 1736 | ); |
| | 1737 | |
| | 1738 | let comp = Comp::from_fusion_str(&src).expect("parse loader tiering comp"); |
| | 1739 | let still_id = comp.find_node("StillLoader").unwrap(); |
| | 1740 | let seq_id = comp.find_node("SeqLoader").unwrap(); |
| | 1741 | assert!(is_static_loader_node(comp.node(still_id))); |
| | 1742 | assert!(!is_static_loader_node(comp.node(seq_id))); |
| | 1743 | if has_video { |
| | 1744 | let vid_id = comp.find_node("VidLoader").unwrap(); |
| | 1745 | assert!(!is_static_loader_node(comp.node(vid_id))); |
| | 1746 | } |
| | 1747 | |
| | 1748 | let Ok(mut eng) = Engine::new_headless() else { |
| | 1749 | let _ = std::fs::remove_dir_all(&dir); |
| | 1750 | return; |
| | 1751 | }; |
| | 1752 | |
| | 1753 | let (still_tex, _) = eng.evaluate(&comp, still_id, 0.0); |
| | 1754 | assert_ne!(still_tex.content_hash, 0); |
| | 1755 | assert!( |
| | 1756 | eng.cache.is_entry_sticky(still_tex.content_hash), |
| | 1757 | "static still Loader must be marked sticky" |
| | 1758 | ); |
| | 1759 | |
| | 1760 | let (seq_tex, _) = eng.evaluate(&comp, seq_id, 0.0); |
| | 1761 | assert_ne!(seq_tex.content_hash, 0); |
| | 1762 | assert!( |
| | 1763 | !eng.cache.is_entry_sticky(seq_tex.content_hash), |
| | 1764 | "multi-frame image-sequence Loader must NOT be sticky" |
| | 1765 | ); |
| | 1766 | |
| | 1767 | if has_video { |
| | 1768 | let vid_id = comp.find_node("VidLoader").unwrap(); |
| | 1769 | let (vid_tex, _) = eng.evaluate(&comp, vid_id, 0.0); |
| | 1770 | assert_ne!(vid_tex.content_hash, 0); |
| | 1771 | assert!( |
| | 1772 | !eng.cache.is_entry_sticky(vid_tex.content_hash), |
| | 1773 | "video Loader must NOT be sticky" |
| | 1774 | ); |
| | 1775 | |
| | 1776 | // Also verify lazy EOF frame-hold in video decoder works cleanly past EOF. |
| | 1777 | let mut dec = crate::media::open_video_decoder(&video_path).expect("open video decoder"); |
| | 1778 | let nb = dec.info().nb_frames; |
| | 1779 | assert!(nb >= 6); |
| | 1780 | let near_eof = dec.decode_frame(nb - 2).expect("decode near EOF"); |
| | 1781 | let past_eof = dec.decode_frame(nb + 1).expect("hold frame past EOF"); |
| | 1782 | assert_eq!(near_eof.len(), past_eof.len()); |
| | 1783 | } |
| | 1784 | |
| | 1785 | let _ = std::fs::remove_dir_all(&dir); |
| | 1786 | } |
| 1593 | } | 1787 | } |