diff --git a/CLI.md b/CLI.md index 9702dce..ccc3c4d 100644 --- a/CLI.md +++ b/CLI.md @@ -38,11 +38,6 @@ Render a shader preset against an image Usage: librashader-cli render [OPTIONS] --preset --image --out --runtime Options: - -f, --frame - The frame to render - - [default: 60] - -p, --preset The path to the shader preset to load @@ -51,17 +46,44 @@ Options: For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman + -f, --frame + The frame to render. + + The renderer will run up to the number of frames specified here to ensure feedback and history. + + [default: 0] + --params ... Parameters to pass to the shader preset, comma separated with equals signs. For example, crt_gamma=2.5,halation_weight=0.001 - + --passes-enabled Set the number of passes enabled for the preset -i, --image The path to the input image + --frame-direction + The direction of rendering. -1 indicates that the frames are played in reverse order + + [default: 1] + + --rotation + The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg + + [default: 0] + + --total-subframes + The total number of subframes ran. Default is 1 + + [default: 1] + + --current-subframe + The current sub frame. Default is 1 + + [default: 1] + -o, --out The path to the output image @@ -70,11 +92,12 @@ Options: -r, --runtime The runtime to use to render the shader preset - [possible values: opengl3, opengl4, vulkan, wgpu, d3d9, d3d11, d3d12] + [possible values: opengl3, opengl4, vulkan, wgpu, d3d9, d3d11, d3d12, metal] -h, --help Print help (see a summary with '-h') + ``` The `render` command can be used to apply a shader preset to an image. The available runtimes will depend on the platform @@ -99,11 +122,6 @@ Compare two runtimes and get a similarity score between the two runtimes renderi Usage: librashader-cli compare [OPTIONS] --preset --image --left --right Options: - -f, --frame - The frame to render - - [default: 60] - -p, --preset The path to the shader preset to load @@ -112,17 +130,44 @@ Options: For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman + -f, --frame + The frame to render. + + The renderer will run up to the number of frames specified here to ensure feedback and history. + + [default: 0] + --params ... Parameters to pass to the shader preset, comma separated with equals signs. For example, crt_gamma=2.5,halation_weight=0.001 - + --passes-enabled Set the number of passes enabled for the preset - + -i, --image The path to the input image + --frame-direction + The direction of rendering. -1 indicates that the frames are played in reverse order + + [default: 1] + + --rotation + The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg + + [default: 0] + + --total-subframes + The total number of subframes ran. Default is 1 + + [default: 1] + + --current-subframe + The current sub frame. Default is 1 + + [default: 1] + -l, --left The runtime to compare against @@ -140,6 +185,7 @@ Options: -h, --help Print help (see a summary with '-h') + ``` The `compare` command can be used to get the similarity of two different runtimes, returning a similarity score and similarity image. diff --git a/librashader-cli/src/cli/main.rs b/librashader-cli/src/cli/main.rs index 8c8e907..24b86f9 100644 --- a/librashader-cli/src/cli/main.rs +++ b/librashader-cli/src/cli/main.rs @@ -36,7 +36,10 @@ struct PresetArgs { #[derive(clap::Args, Debug)] struct RenderArgs { /// The frame to render. - #[arg(short, long, default_value_t = 60)] + /// + /// The renderer will run up to the number of frames specified here + /// to ensure feedback and history. + #[arg(short, long, default_value_t = 0)] frame: usize, /// Parameters to pass to the shader preset, comma separated with equals signs. /// diff --git a/librashader-cli/src/render/d3d11.rs b/librashader-cli/src/render/d3d11.rs index d7ed57e..a51890e 100644 --- a/librashader-cli/src/render/d3d11.rs +++ b/librashader-cli/src/render/d3d11.rs @@ -36,22 +36,18 @@ impl RenderTest for Direct3D11 { if let Some(setter) = param_setter { setter(filter_chain.parameters()); } + let viewport = Viewport::new_render_target_sized_origin(rtv, None)?; + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); - filter_chain.frame( - None, - &self.image_srv, - &Viewport::new_render_target_sized_origin(rtv, None)?, - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), - )?; + for frame in 0..=frame_count { + filter_chain.frame(None, &self.image_srv, &viewport, frame, options.as_ref())?; + } let mut renderbuffer_desc = Default::default(); renderbuffer.GetDesc(&mut renderbuffer_desc); diff --git a/librashader-cli/src/render/d3d12/mod.rs b/librashader-cli/src/render/d3d12/mod.rs index 0f58f82..cc151b8 100644 --- a/librashader-cli/src/render/d3d12/mod.rs +++ b/librashader-cli/src/render/d3d12/mod.rs @@ -134,29 +134,33 @@ impl RenderTest for Direct3D12 { self.device .CreateRenderTargetView(&output_texture, None, *descriptor.as_ref()); - filter_chain.frame( - &cmd, - self.texture.clone(), - &Viewport::new_render_target_sized_origin( - D3D12OutputView::new_from_raw( - *descriptor.as_ref(), - self.image.size, - DXGI_FORMAT_B8G8R8A8_UNORM, - ), - None, - )?, - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), + let viewport = Viewport::new_render_target_sized_origin( + D3D12OutputView::new_from_raw( + *descriptor.as_ref(), + self.image.size, + DXGI_FORMAT_B8G8R8A8_UNORM, + ), + None, )?; + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); + + for frame in 0..=frame_count { + filter_chain.frame( + &cmd, + self.texture.clone(), + &viewport, + frame, + options.as_ref(), + )?; + } + cmd.Close()?; self.queue.ExecuteCommandLists(&[Some(cmd.cast()?)]); self.queue.Signal(&fence, 1)?; diff --git a/librashader-cli/src/render/d3d9.rs b/librashader-cli/src/render/d3d9.rs index 0ac25a8..cc7e8e7 100644 --- a/librashader-cli/src/render/d3d9.rs +++ b/librashader-cli/src/render/d3d9.rs @@ -84,20 +84,19 @@ impl RenderTest for Direct3D9 { let surface = render_texture.GetSurfaceLevel(0)?; - filter_chain.frame( - &self.texture, - &Viewport::new_render_target_sized_origin(surface.clone(), None)?, - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), - )?; + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); + + let viewport = Viewport::new_render_target_sized_origin(surface.clone(), None)?; + + for frame in 0..=frame_count { + filter_chain.frame(&self.texture, &viewport, frame, options.as_ref())?; + } self.device.GetRenderTargetData(&surface, ©_texture)?; diff --git a/librashader-cli/src/render/gl/mod.rs b/librashader-cli/src/render/gl/mod.rs index 6606a1f..86ed4a2 100644 --- a/librashader-cli/src/render/gl/mod.rs +++ b/librashader-cli/src/render/gl/mod.rs @@ -215,13 +215,11 @@ impl OpenGl { size: self.image_bytes.size, }; - unsafe { - chain.frame( - &self.texture, - &Viewport::new_render_target_sized_origin(&output, None)?, - frame_count, - options, - )?; + let viewport = Viewport::new_render_target_sized_origin(&output, None)?; + for frame in 0..=frame_count { + unsafe { + chain.frame(&self.texture, &viewport, frame, options)?; + } } // should be the same size as the input image diff --git a/librashader-cli/src/render/mtl.rs b/librashader-cli/src/render/mtl.rs index 2cf055b..48f8baf 100644 --- a/librashader-cli/src/render/mtl.rs +++ b/librashader-cli/src/render/mtl.rs @@ -5,7 +5,7 @@ use librashader::presets::ShaderPreset; use librashader::runtime::mtl::{FilterChain, FilterChainOptions, FrameOptions}; use librashader::runtime::Viewport; use librashader::runtime::{FilterChainParameters, RuntimeParameters}; -use librashader_runtime::image::{Image, PixelFormat, UVDirection, BGRA8, RGBA8}; +use librashader_runtime::image::{Image, PixelFormat, UVDirection, BGRA8}; use objc2::ffi::NSUInteger; use objc2::rc::Retained; use objc2::runtime::ProtocolObject; @@ -86,21 +86,24 @@ impl RenderTest for Metal { texture }; - filter_chain.frame( - &self.texture, - &Viewport::new_render_target_sized_origin(render_texture.as_ref(), None)?, - cmd.as_ref(), - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), - )?; + let viewport = Viewport::new_render_target_sized_origin(render_texture.as_ref(), None)?; + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); + + for frame in 0..=frame_count { + filter_chain.frame( + &self.texture, + &viewport, + cmd.as_ref(), + frame, + options.as_ref(), + )?; + } cmd.commit(); unsafe { diff --git a/librashader-cli/src/render/vk/mod.rs b/librashader-cli/src/render/vk/mod.rs index 29939ba..e90e7cc 100644 --- a/librashader-cli/src/render/vk/mod.rs +++ b/librashader-cli/src/render/vk/mod.rs @@ -142,32 +142,36 @@ impl RenderTest for Vulkan { vk::QUEUE_FAMILY_IGNORED, ); - filter_chain.frame( - &VulkanImage { - image: self.image, - size: self.image_bytes.size, + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); + + let viewport = Viewport::new_render_target_sized_origin( + VulkanImage { + image: render_texture, + size: self.image_bytes.size.into(), format: vk::Format::B8G8R8A8_UNORM, }, - &Viewport::new_render_target_sized_origin( - VulkanImage { - image: render_texture, - size: self.image_bytes.size.into(), + None, + )?; + + for frame in 0..=frame_count { + filter_chain.frame( + &VulkanImage { + image: self.image, + size: self.image_bytes.size, format: vk::Format::B8G8R8A8_UNORM, }, - None, - )?, - cmd, - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), - )?; + &viewport, + cmd, + frame, + options.as_ref(), + )?; + } { util::vulkan_image_layout_transition_levels( diff --git a/librashader-cli/src/render/wgpu.rs b/librashader-cli/src/render/wgpu.rs index fd2e9c0..7d8afa7 100644 --- a/librashader-cli/src/render/wgpu.rs +++ b/librashader-cli/src/render/wgpu.rs @@ -108,21 +108,24 @@ impl RenderTest for Wgpu { TextureFormat::Rgba8Unorm, ); - chain.frame( - Arc::clone(&self.texture), - &Viewport::new_render_target_sized_origin(output, None)?, - &mut cmd, - frame_count, - frame_options - .map(|options| FrameOptions { - clear_history: options.clear_history, - frame_direction: options.frame_direction, - rotation: options.rotation, - total_subframes: options.total_subframes, - current_subframe: options.current_subframe, - }) - .as_ref(), - )?; + let viewport = Viewport::new_render_target_sized_origin(output, None)?; + let options = frame_options.map(|options| FrameOptions { + clear_history: options.clear_history, + frame_direction: options.frame_direction, + rotation: options.rotation, + total_subframes: options.total_subframes, + current_subframe: options.current_subframe, + }); + + for frame in 0..=frame_count { + chain.frame( + Arc::clone(&self.texture), + &viewport, + &mut cmd, + frame, + options.as_ref(), + )?; + } cmd.copy_texture_to_buffer( output_tex.as_image_copy(),