cli(render): make frame inclusive to ensure correct feedback and history behaviour

This commit is contained in:
chyyran 2024-09-26 23:49:56 -04:00 committed by Ronny Chan
parent 84e78f4e48
commit da53c3df59
9 changed files with 181 additions and 125 deletions

68
CLI.md
View file

@ -38,11 +38,6 @@ Render a shader preset against an image
Usage: librashader-cli render [OPTIONS] --preset <PRESET> --image <IMAGE> --out <OUT> --runtime <RUNTIME>
Options:
-f, --frame <FRAME>
The frame to render
[default: 60]
-p, --preset <PRESET>
The path to the shader preset to load
@ -51,6 +46,13 @@ Options:
For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman
-f, --frame <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 <PARAMS>...
Parameters to pass to the shader preset, comma separated with equals signs.
@ -62,6 +64,26 @@ Options:
-i, --image <IMAGE>
The path to the input image
--frame-direction <FRAME_DIRECTION>
The direction of rendering. -1 indicates that the frames are played in reverse order
[default: 1]
--rotation <ROTATION>
The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg
[default: 0]
--total-subframes <TOTAL_SUBFRAMES>
The total number of subframes ran. Default is 1
[default: 1]
--current-subframe <CURRENT_SUBFRAME>
The current sub frame. Default is 1
[default: 1]
-o, --out <OUT>
The path to the output image
@ -70,11 +92,12 @@ Options:
-r, --runtime <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 <PRESET> --image <IMAGE> --left <LEFT> --right <RIGHT>
Options:
-f, --frame <FRAME>
The frame to render
[default: 60]
-p, --preset <PRESET>
The path to the shader preset to load
@ -112,6 +130,13 @@ Options:
For example, CONTENT-DIR=MyVerticalGames,GAME=mspacman
-f, --frame <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 <PARAMS>...
Parameters to pass to the shader preset, comma separated with equals signs.
@ -123,6 +148,26 @@ Options:
-i, --image <IMAGE>
The path to the input image
--frame-direction <FRAME_DIRECTION>
The direction of rendering. -1 indicates that the frames are played in reverse order
[default: 1]
--rotation <ROTATION>
The rotation of the output. 0 = 0deg, 1 = 90deg, 2 = 180deg, 3 = 270deg
[default: 0]
--total-subframes <TOTAL_SUBFRAMES>
The total number of subframes ran. Default is 1
[default: 1]
--current-subframe <CURRENT_SUBFRAME>
The current sub frame. Default is 1
[default: 1]
-l, --left <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.

View file

@ -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.
///

View file

@ -36,22 +36,18 @@ impl RenderTest for Direct3D11 {
if let Some(setter) = param_setter {
setter(filter_chain.parameters());
}
filter_chain.frame(
None,
&self.image_srv,
&Viewport::new_render_target_sized_origin(rtv, None)?,
frame_count,
frame_options
.map(|options| FrameOptions {
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,
})
.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);

View file

@ -134,28 +134,32 @@ 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(
let viewport = 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 {
)?;
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,
})
.as_ref(),
});
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()?)]);

View file

@ -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 {
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,
})
.as_ref(),
)?;
});
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, &copy_texture)?;

View file

@ -215,13 +215,11 @@ impl OpenGl {
size: self.image_bytes.size,
};
let viewport = Viewport::new_render_target_sized_origin(&output, None)?;
for frame in 0..=frame_count {
unsafe {
chain.frame(
&self.texture,
&Viewport::new_render_target_sized_origin(&output, None)?,
frame_count,
options,
)?;
chain.frame(&self.texture, &viewport, frame, options)?;
}
}
// should be the same size as the input image

View file

@ -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 {
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,
})
.as_ref(),
});
for frame in 0..=frame_count {
filter_chain.frame(
&self.texture,
&viewport,
cmd.as_ref(),
frame,
options.as_ref(),
)?;
}
cmd.commit();
unsafe {

View file

@ -142,33 +142,37 @@ impl RenderTest for Vulkan {
vk::QUEUE_FAMILY_IGNORED,
);
filter_chain.frame(
&VulkanImage {
image: self.image,
size: self.image_bytes.size,
format: vk::Format::B8G8R8A8_UNORM,
},
&Viewport::new_render_target_sized_origin(
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,
},
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(),
)?;
for frame in 0..=frame_count {
filter_chain.frame(
&VulkanImage {
image: self.image,
size: self.image_bytes.size,
format: vk::Format::B8G8R8A8_UNORM,
},
&viewport,
cmd,
frame,
options.as_ref(),
)?;
}
{
util::vulkan_image_layout_transition_levels(
&self.vk.device(),

View file

@ -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 {
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,
})
.as_ref(),
});
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(),