Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Display to set render stage names #32

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions jxl/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub struct RenderPipelineExtendStage<T: ImageDataType> {
}

// TODO(veluca): figure out how to modify the interface for concurrent usage.
pub trait RenderPipelineStage: Any {
pub trait RenderPipelineStage: Any + std::fmt::Display {
type Type: RenderPipelineStageInfo;

/// Which channels are actually used by this stage.
Expand All @@ -97,9 +97,6 @@ pub trait RenderPipelineStage: Any {
fn original_data_origin(&self) -> (usize, usize) {
(0, 0)
}

/// Returns a name for this stage.
fn name(&self) -> String;
}

pub trait RenderPipelineBuilder: Sized {
Expand Down
44 changes: 15 additions & 29 deletions jxl/src/render/simple_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ impl RenderPipelineBuilder for SimpleRenderPipelineBuilder {
fn add_stage<Stage: RenderPipelineStage>(mut self, stage: Stage) -> Result<Self> {
let current_info = self.pipeline.channel_info.last().unwrap().clone();
info!(
"adding stage '{}'. last stage channel info: {:?} can_shift {}",
stage.name(),
current_info,
self.can_shift
last_stage_channel_info = ?current_info,
can_shift = self.can_shift,
"adding stage '{stage}'",
);
let mut after_info = vec![];
for (c, info) in current_info.iter().enumerate() {
Expand All @@ -93,7 +92,7 @@ impl RenderPipelineBuilder for SimpleRenderPipelineBuilder {
if let Some(ty) = info.ty {
if ty != Stage::Type::INPUT_TYPE {
return Err(Error::PipelineChannelTypeMismatch(
stage.name(),
stage.to_string(),
c,
Stage::Type::INPUT_TYPE,
ty,
Expand All @@ -107,16 +106,15 @@ impl RenderPipelineBuilder for SimpleRenderPipelineBuilder {
}
}
if !self.can_shift && Stage::Type::SHIFT != (0, 0) {
return Err(Error::PipelineShiftAfterExpand(stage.name()));
return Err(Error::PipelineShiftAfterExpand(stage.to_string()));
}
if Stage::Type::TYPE == RenderPipelineStageType::Extend {
self.can_shift = false;
}
info!(
"added stage '{}'. new channel info: {:?} can_shift {}",
stage.name(),
after_info,
self.can_shift
new_channel_info = ?after_info,
can_shift = self.can_shift,
"added stage '{stage}'",
);
self.pipeline.channel_info.push(after_info);
self.pipeline.stages.push(Box::new(stage));
Expand Down Expand Up @@ -167,11 +165,7 @@ impl RenderPipelineBuilder for SimpleRenderPipelineBuilder {
.zip(self.pipeline.stages.iter())
.enumerate()
{
info!(
"final channel info before stage {s} '{}': {:?}",
stage.name(),
current_info
);
info!("final channel info before stage {s} '{stage}': {current_info:?}");
}
info!(
"final channel info after all stages {:?}",
Expand Down Expand Up @@ -242,7 +236,7 @@ impl SimpleRenderPipeline {
let mut current_size = self.input_size;

for (i, stage) in self.stages.iter_mut().enumerate() {
info!("running stage {i}: {}", stage.name());
info!("running stage {i}: {stage}");
let mut output_buffers = clone_images(&current_buffers)?;
// Replace buffers of different sizes.
if stage.shift() != (0, 0) || stage.new_size(current_size) != current_size {
Expand Down Expand Up @@ -401,7 +395,7 @@ impl<T: ImageDataType> RenderPipelineRunStage for RenderPipelineInputStage<T> {
input_buffers: &[&Image<f64>],
_output_buffers: &mut [&mut Image<f64>],
) {
info!("running input stage '{}' in simple pipeline", stage.name());
info!("running input stage '{stage}' in simple pipeline");
let numc = input_buffers.len();
if numc == 0 {
return;
Expand Down Expand Up @@ -435,10 +429,7 @@ impl<T: ImageDataType> RenderPipelineRunStage for RenderPipelineInPlaceStage<T>
input_buffers: &[&Image<f64>],
output_buffers: &mut [&mut Image<f64>],
) {
info!(
"running inplace stage '{}' in simple pipeline",
stage.name()
);
info!("running inplace stage '{stage}' in simple pipeline");
let numc = input_buffers.len();
if numc == 0 {
return;
Expand Down Expand Up @@ -490,7 +481,7 @@ impl<
input_buffers: &[&Image<f64>],
output_buffers: &mut [&mut Image<f64>],
) {
info!("running inout stage '{}' in simple pipeline", stage.name());
info!("running inout stage '{stage}' in simple pipeline");
let numc = input_buffers.len();
if numc == 0 {
return;
Expand Down Expand Up @@ -576,7 +567,7 @@ impl<T: ImageDataType> RenderPipelineRunStage for RenderPipelineExtendStage<T> {
input_buffers: &[&Image<f64>],
output_buffers: &mut [&mut Image<f64>],
) {
info!("running extend stage '{}' in simple pipeline", stage.name());
info!("running extend stage '{stage}' in simple pipeline");
let numc = input_buffers.len();
if numc == 0 {
return;
Expand Down Expand Up @@ -639,7 +630,7 @@ impl<T: ImageDataType> RenderPipelineRunStage for RenderPipelineExtendStage<T> {
}
}

trait RunStage: Any {
trait RunStage: Any + std::fmt::Display {
fn run_stage_on(
&mut self,
chunk_size: usize,
Expand All @@ -652,8 +643,6 @@ trait RunStage: Any {
fn as_any(self: Box<Self>) -> Box<dyn Any>;
fn input_type(&self) -> DataTypeTag;
fn output_type(&self) -> DataTypeTag;
#[allow(unused)]
fn name(&self) -> String;
}

impl<T: RenderPipelineStage> RunStage for T {
Expand Down Expand Up @@ -686,7 +675,4 @@ impl<T: RenderPipelineStage> RunStage for T {
fn output_type(&self) -> DataTypeTag {
T::Type::OUTPUT_TYPE.unwrap_or(T::Type::INPUT_TYPE)
}
fn name(&self) -> String {
self.name()
}
}
10 changes: 6 additions & 4 deletions jxl/src/render/stages/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ impl ConvertU8F32Stage {
}
}

impl std::fmt::Display for ConvertU8F32Stage {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "convert U8 data to F32 in channel {}", self.channel)
}
}

impl RenderPipelineStage for ConvertU8F32Stage {
type Type = RenderPipelineInOutStage<u8, f32, 0, 0, 0, 0>;

fn name(&self) -> String {
format!("convert U8 data to F32 in channel {}", self.channel)
}

fn uses_channel(&self, c: usize) -> bool {
c == self.channel
}
Expand Down
15 changes: 11 additions & 4 deletions jxl/src/render/stages/save.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ impl<T: ImageDataType> SaveStage<T> {
}
}

impl<T: ImageDataType> std::fmt::Display for SaveStage<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"save channel {} (type {:?})",
self.channel,
T::DATA_TYPE_ID
)
}
}

impl<T: ImageDataType> RenderPipelineStage for SaveStage<T> {
type Type = RenderPipelineInputStage<T>;

fn name(&self) -> String {
format!("save channel {} (type {:?})", self.channel, T::DATA_TYPE_ID)
}

fn uses_channel(&self, c: usize) -> bool {
c == self.channel
}
Expand Down
14 changes: 10 additions & 4 deletions jxl/src/render/stages/upsample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,19 @@ impl NearestNeighbourUpsample {
}
}

impl std::fmt::Display for NearestNeighbourUpsample {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"2x2 nearest neighbour upsample of channel {}",
self.channel
)
}
}

impl RenderPipelineStage for NearestNeighbourUpsample {
type Type = RenderPipelineInOutStage<u8, u8, 0, 0, 1, 1>;

fn name(&self) -> String {
format!("2x2 nearest neighbour upsample of channel {}", self.channel)
}

fn uses_channel(&self, c: usize) -> bool {
c == self.channel
}
Expand Down