Skip to content

Commit

Permalink
retroarch shaders support
Browse files Browse the repository at this point in the history
  • Loading branch information
igorsaux committed Oct 16, 2024
1 parent 7b0ca29 commit f535d5c
Show file tree
Hide file tree
Showing 12 changed files with 1,089 additions and 54 deletions.
887 changes: 863 additions & 24 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions frontends/rioterm/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,10 @@ impl ApplicationHandler<EventPayload> for Application<'_> {
}
RoutePath::Terminal => {
route.window.screen.render();

if self.config.renderer.continuous_rendering {
route.request_redraw();
}
}
RoutePath::ConfirmQuit => {
route
Expand Down
6 changes: 2 additions & 4 deletions frontends/rioterm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
}
}

id =
id.to_owned() + &(format!("{}{}{};", i, program, terminal_title));
id.push_str(&format!("{}{}{};", i, program, terminal_title));
self.titles.set_key_val(i, program, terminal_title, path);
}
self.titles.set_key(id);
Expand All @@ -563,8 +562,7 @@ impl<T: EventListener + Clone + std::marker::Send + 'static> ContextManager<T> {
let mut id = String::from("");
for (i, _context) in self.contexts.iter().enumerate() {
let program = self.config.shell.program.to_owned();
id = id.to_owned()
+ &(format!("{}{}{};", i, program, String::default()));
id.push_str(&format!("{}{}{};", i, program, String::default()));
self.titles.set_key_val(
i,
program,
Expand Down
4 changes: 4 additions & 0 deletions frontends/rioterm/src/screen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ impl Screen<'_> {
}
};

sugarloaf.update_filters(config.renderer.filters.as_slice());

let renderer = Renderer::new(config, font_library);

let bindings = crate::bindings::default_key_bindings(
Expand Down Expand Up @@ -325,6 +327,8 @@ impl Screen<'_> {
);

self.sugarloaf.layout_mut().update();
self.sugarloaf
.update_filters(config.renderer.filters.as_slice());
self.renderer = Renderer::new(config, font_library);

for context in self.ctx().contexts() {
Expand Down
9 changes: 9 additions & 0 deletions rio-backend/src/config/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,21 @@ pub fn default_config_file_content() -> String {
# will be done like enable font ligatures or emoji support.
# For more information please check the docs.
#
# • filters: A list of paths to RetroArch slang shaders
#
# • continuous-rendering: Configure continuous rendering
# - Available options: true and false.
# When set to true, the renderer will continuously render.
# When set to false, the renderer will render as rare as possible.
#
# Example:
# [renderer]
# performance = "high"
# backend = "automatic"
# disable-unfocused-render = false
# level = 1
# filters = []
# continuous-rendering = false
# Keyboard
#
Expand Down
6 changes: 6 additions & 0 deletions rio-backend/src/config/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct Renderer {
pub disable_unfocused_render: bool,
#[serde(default = "Option::default", rename = "target-fps")]
pub target_fps: Option<u64>,
#[serde(default = "Vec::default")]
pub filters: Vec<String>,
#[serde(default = "bool::default", rename = "continuous-rendering")]
pub continuous_rendering: bool,
}

#[allow(clippy::derivable_impls)]
Expand All @@ -21,6 +25,8 @@ impl Default for Renderer {
backend: Backend::default(),
disable_unfocused_render: false,
target_fps: None,
filters: Vec::default(),
continuous_rendering: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions sugarloaf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ skrifa = "0.22.3"
yazi = { version = "0.1.6", optional = true }
zeno = { version = "0.2.2", optional = true, default-features = false }
futures = { workspace = true }
librashader = { version = "0.5.1", features = ["preprocess", "runtime-wgpu", "stable"], default-features = false }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
crossbeam-channel = "0.5.13"
Expand Down
14 changes: 7 additions & 7 deletions sugarloaf/src/components/text/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use glyph::{
use crate::components::core::orthographic_projection;
use ab_glyph::{Font, Rect};
use core::hash::BuildHasher;
use std::borrow::Cow;
use std::{borrow::Cow, sync::Arc};

use glyph::{BrushAction, BrushError, DefaultSectionHasher};

Expand Down Expand Up @@ -87,7 +87,7 @@ where
F: Font + Sync,
H: BuildHasher,
{
fn process_queued(&mut self, device: &wgpu::Device, queue: &mut wgpu::Queue) {
fn process_queued(&mut self, device: &wgpu::Device, queue: &wgpu::Queue) {
let pipeline = &mut self.pipeline;

let mut brush_action;
Expand All @@ -98,7 +98,7 @@ where
let offset = [rect.min[0] as u16, rect.min[1] as u16];
let size = [rect.width() as u16, rect.height() as u16];

pipeline.update_cache(queue, offset, size, tex_data);
pipeline.update_cache(&queue, offset, size, tex_data);
},
Instance::from_vertex,
);
Expand Down Expand Up @@ -130,7 +130,7 @@ where

match brush_action.unwrap() {
BrushAction::Draw(mut verts) => {
self.pipeline.upload(device, queue, &mut verts);
self.pipeline.upload(device, &queue, &mut verts);
}
BrushAction::ReDraw => {}
};
Expand Down Expand Up @@ -177,7 +177,7 @@ impl<F: Font + Sync, H: BuildHasher> GlyphBrush<(), F, H> {
rpass: &mut wgpu::RenderPass<'pass>,
) {
let device = &context.device;
let queue = &mut context.queue;
let queue = &context.queue;
self.draw_queued_with_transform(
device,
queue,
Expand All @@ -200,8 +200,8 @@ impl<F: Font + Sync, H: BuildHasher> GlyphBrush<(), F, H> {
#[inline]
pub fn draw_queued_with_transform<'pass>(
&'pass mut self,
device: &wgpu::Device,
queue: &mut wgpu::Queue,
device: &Arc<wgpu::Device>,
queue: &wgpu::Queue,
rpass: &mut wgpu::RenderPass<'pass>,
transform: [f32; 16],
) {
Expand Down
10 changes: 5 additions & 5 deletions sugarloaf/src/components/text/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Pipeline<()> {

pub fn draw<'pass>(
&'pass mut self,
queue: &mut wgpu::Queue,
queue: &wgpu::Queue,
rpass: &mut wgpu::RenderPass<'pass>,
transform: [f32; 16],
region: Option<Region>,
Expand Down Expand Up @@ -100,12 +100,12 @@ impl Pipeline<wgpu::DepthStencilState> {
impl<Depth> Pipeline<Depth> {
pub fn update_cache(
&mut self,
queue: &mut wgpu::Queue,
queue: &wgpu::Queue,
offset: [u16; 2],
size: [u16; 2],
data: &[u8],
) {
self.cache.update(queue, offset, size, data);
self.cache.update(&queue, offset, size, data);
}

pub fn increase_cache_size(
Expand All @@ -128,7 +128,7 @@ impl<Depth> Pipeline<Depth> {
pub fn upload(
&mut self,
device: &wgpu::Device,
queue: &mut wgpu::Queue,
queue: &wgpu::Queue,
instances: &mut [Instance],
) {
if instances.is_empty() {
Expand Down Expand Up @@ -315,7 +315,7 @@ fn build<D>(

fn draw<'pass, D>(
pipeline: &'pass mut Pipeline<D>,
config: (&mut wgpu::Queue, &mut wgpu::RenderPass<'pass>),
config: (&wgpu::Queue, &mut wgpu::RenderPass<'pass>),
transform: [f32; 16],
region: Option<Region>,
) {
Expand Down
2 changes: 1 addition & 1 deletion sugarloaf/src/components/text/pipeline/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Cache {

pub fn update(
&mut self,
queue: &mut wgpu::Queue,
queue: &wgpu::Queue,
offset: [u16; 2],
size: [u16; 2],
data: &[u8],
Expand Down
29 changes: 20 additions & 9 deletions sugarloaf/src/context/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use crate::sugarloaf::{SugarloafWindow, SugarloafWindowSize};
use crate::SugarloafRenderer;
use std::sync::Arc;

pub struct Context<'a> {
pub device: wgpu::Device,
pub device: Arc<wgpu::Device>,
pub surface: wgpu::Surface<'a>,
pub queue: wgpu::Queue,
pub queue: Arc<wgpu::Queue>,
pub format: wgpu::TextureFormat,
pub size: SugarloafWindowSize,
pub scale: f32,
Expand Down Expand Up @@ -111,9 +112,15 @@ impl Context<'_> {

let (device, queue) = {
{
if let Ok(result) = futures::executor::block_on(
adapter.request_device(&wgpu::DeviceDescriptor::default(), None),
) {
if let Ok(result) = futures::executor::block_on(adapter.request_device(
// ADDRESS_MODE_CLAMP_TO_BORDER is required for librashader
&wgpu::DeviceDescriptor {
required_features: wgpu::Features::empty()
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER,
..Default::default()
},
None,
)) {
result
} else {
// These downlevel limits will allow the code to run on all possible hardware
Expand Down Expand Up @@ -148,7 +155,9 @@ impl Context<'_> {
surface.configure(
&device,
&wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
// COPY_DST is required for rendering filter chains
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::COPY_DST,
format,
width: size.width as u32,
height: size.height as u32,
Expand All @@ -160,8 +169,8 @@ impl Context<'_> {
);

Context {
device,
queue,
device: Arc::new(device),
queue: Arc::new(queue),
surface,
format,
alpha_mode,
Expand All @@ -180,7 +189,9 @@ impl Context<'_> {
self.surface.configure(
&self.device,
&wgpu::SurfaceConfiguration {
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
// COPY_DST is required for rendering filter chains
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::COPY_DST,
format: self.format,
width,
height,
Expand Down
Loading

0 comments on commit f535d5c

Please sign in to comment.