Skip to content

Commit

Permalink
Revert "Implement billinear filtering of textures (#1850)" (#1859)
Browse files Browse the repository at this point in the history
This reverts commit d33dab6.
  • Loading branch information
jleibs authored Apr 14, 2023
1 parent 8d25b9e commit 625d2bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 97 deletions.
66 changes: 6 additions & 60 deletions crates/re_renderer/shader/rectangle.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ const COLOR_MAPPER_OFF = 1u;
const COLOR_MAPPER_FUNCTION = 2u;
const COLOR_MAPPER_TEXTURE = 3u;

const FILTER_NEAREST = 1u;
const FILTER_BILINEAR = 2u;

struct UniformBuffer {
/// Top left corner position in world space.
top_left_corner_position: Vec3,
Expand Down Expand Up @@ -51,9 +48,6 @@ struct UniformBuffer {
/// Exponent to raise the normalized texture value.
/// Inverse brightness.
gamma: f32,

minification_filter: u32,
magnification_filter: u32,
};

@group(1) @binding(0)
Expand Down Expand Up @@ -96,18 +90,6 @@ fn vs_main(@builtin(vertex_index) v_idx: u32) -> VertexOut {
return out;
}

fn is_magnifying(pixel_coord: Vec2) -> bool {
return fwidth(pixel_coord.x) < 1.0;
}

fn tex_filter(pixel_coord: Vec2) -> u32 {
if is_magnifying(pixel_coord) {
return rect_info.magnification_filter;
} else {
return rect_info.minification_filter;
}
}

@fragment
fn fs_main(in: VertexOut) -> @location(0) Vec4 {
// Sample the main texture:
Expand All @@ -116,50 +98,14 @@ fn fs_main(in: VertexOut) -> @location(0) Vec4 {
// TODO(emilk): support mipmaps
sampled_value = textureSampleLevel(texture_float_filterable, texture_sampler, in.texcoord, 0.0);
} else if rect_info.sample_type == SAMPLE_TYPE_FLOAT_NOFILTER {
let coord = in.texcoord * Vec2(textureDimensions(texture_float).xy);
if tex_filter(coord) == FILTER_NEAREST {
// nearest
sampled_value = textureLoad(texture_float, IVec2(coord + vec2(0.5)), 0);
} else {
// bilinear
let v00 = textureLoad(texture_float, IVec2(coord) + IVec2(0, 0), 0);
let v01 = textureLoad(texture_float, IVec2(coord) + IVec2(0, 1), 0);
let v10 = textureLoad(texture_float, IVec2(coord) + IVec2(1, 0), 0);
let v11 = textureLoad(texture_float, IVec2(coord) + IVec2(1, 1), 0);
let top = mix(v00, v10, fract(coord.x));
let bottom = mix(v01, v11, fract(coord.x));
sampled_value = mix(top, bottom, fract(coord.y));
}
let icoords = IVec2(in.texcoord * Vec2(textureDimensions(texture_float).xy));
sampled_value = Vec4(textureLoad(texture_float, icoords, 0));
} else if rect_info.sample_type == SAMPLE_TYPE_SINT_NOFILTER {
let coord = in.texcoord * Vec2(textureDimensions(texture_sint).xy);
if tex_filter(coord) == FILTER_NEAREST {
// nearest
sampled_value = Vec4(textureLoad(texture_sint, IVec2(coord + vec2(0.5)), 0));
} else {
// bilinear
let v00 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(0, 0), 0));
let v01 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(0, 1), 0));
let v10 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(1, 0), 0));
let v11 = Vec4(textureLoad(texture_sint, IVec2(coord) + IVec2(1, 1), 0));
let top = mix(v00, v10, fract(coord.x));
let bottom = mix(v01, v11, fract(coord.x));
sampled_value = mix(top, bottom, fract(coord.y));
}
let icoords = IVec2(in.texcoord * Vec2(textureDimensions(texture_sint).xy));
sampled_value = Vec4(textureLoad(texture_sint, icoords, 0));
} else if rect_info.sample_type == SAMPLE_TYPE_UINT_NOFILTER {
let coord = in.texcoord * Vec2(textureDimensions(texture_uint).xy);
if tex_filter(coord) == FILTER_NEAREST {
// nearest
sampled_value = Vec4(textureLoad(texture_uint, IVec2(coord + vec2(0.5)), 0));
} else {
// bilinear
let v00 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(0, 0), 0));
let v01 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(0, 1), 0));
let v10 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(1, 0), 0));
let v11 = Vec4(textureLoad(texture_uint, IVec2(coord) + IVec2(1, 1), 0));
let top = mix(v00, v10, fract(coord.x));
let bottom = mix(v01, v11, fract(coord.x));
sampled_value = mix(top, bottom, fract(coord.y));
}
let icoords = IVec2(in.texcoord * Vec2(textureDimensions(texture_uint).xy));
sampled_value = Vec4(textureLoad(texture_uint, icoords, 0));
} else {
return ERROR_RGBA; // unknown sample type
}
Expand Down
18 changes: 2 additions & 16 deletions crates/re_renderer/src/renderer/rectangles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ mod gpu_data {
const COLOR_MAPPER_FUNCTION: u32 = 2;
const COLOR_MAPPER_TEXTURE: u32 = 3;

const FILTER_NEAREST: u32 = 1;
const FILTER_BILINEAR: u32 = 2;

#[repr(C, align(256))]
#[derive(Clone, Copy, bytemuck::Pod, bytemuck::Zeroable)]
pub struct UniformBuffer {
Expand All @@ -216,8 +213,7 @@ mod gpu_data {

color_mapper: u32,
gamma: f32,
minification_filter: u32,
magnification_filter: u32,
_row_padding: [u32; 2],

_end_padding: [wgpu_buffer_types::PaddingRow; 16 - 6],
}
Expand Down Expand Up @@ -279,15 +275,6 @@ mod gpu_data {
}
}

let minification_filter = match rectangle.texture_filter_minification {
super::TextureFilterMin::Linear => FILTER_BILINEAR,
super::TextureFilterMin::Nearest => FILTER_NEAREST,
};
let magnification_filter = match rectangle.texture_filter_magnification {
super::TextureFilterMag::Linear => FILTER_BILINEAR,
super::TextureFilterMag::Nearest => FILTER_NEAREST,
};

Ok(Self {
top_left_corner_position: rectangle.top_left_corner_position.into(),
colormap_function,
Expand All @@ -300,8 +287,7 @@ mod gpu_data {
range_min_max: (*range).into(),
color_mapper: color_mapper_int,
gamma: *gamma,
minification_filter,
magnification_filter,
_row_padding: Default::default(),
_end_padding: Default::default(),
})
}
Expand Down
45 changes: 24 additions & 21 deletions crates/re_viewer/src/ui/view_tensor/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,29 +426,32 @@ impl TextureSettings {
});
ui.end_row();

re_ui
.grid_left_hand_label(ui, "Filtering")
.on_hover_text("Filtering to use when magnifying");

fn tf_to_string(tf: egui::TextureFilter) -> &'static str {
match tf {
egui::TextureFilter::Nearest => "Nearest",
egui::TextureFilter::Linear => "Linear",
// TODO(#1612): support texture filtering again
if false {
re_ui
.grid_left_hand_label(ui, "Filtering")
.on_hover_text("Filtering to use when magnifying");

fn tf_to_string(tf: egui::TextureFilter) -> &'static str {
match tf {
egui::TextureFilter::Nearest => "Nearest",
egui::TextureFilter::Linear => "Linear",
}
}
}
egui::ComboBox::from_id_source("texture_filter")
.selected_text(tf_to_string(options.magnification))
.show_ui(ui, |ui| {
ui.style_mut().wrap = Some(false);
ui.set_min_width(64.0);
egui::ComboBox::from_id_source("texture_filter")
.selected_text(tf_to_string(options.magnification))
.show_ui(ui, |ui| {
ui.style_mut().wrap = Some(false);
ui.set_min_width(64.0);

let mut selectable_value = |ui: &mut egui::Ui, e| {
ui.selectable_value(&mut options.magnification, e, tf_to_string(e))
};
selectable_value(ui, egui::TextureFilter::Nearest);
selectable_value(ui, egui::TextureFilter::Linear);
});
ui.end_row();
let mut selectable_value = |ui: &mut egui::Ui, e| {
ui.selectable_value(&mut options.magnification, e, tf_to_string(e))
};
selectable_value(ui, egui::TextureFilter::Linear);
selectable_value(ui, egui::TextureFilter::Nearest);
});
ui.end_row();
}
}
}

Expand Down

1 comment on commit 625d2bd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rust Benchmark

Benchmark suite Current: 625d2bd Previous: 8d25b9e Ratio
datastore/num_rows=1000/num_instances=1000/packed=false/insert/default 2841265 ns/iter (± 68397) 2913868 ns/iter (± 79014) 0.98
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at/default 373 ns/iter (± 2) 372 ns/iter (± 28) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/primary/default 261 ns/iter (± 0) 260 ns/iter (± 0) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/latest_at_missing/secondaries/default 422 ns/iter (± 1) 421 ns/iter (± 0) 1.00
datastore/num_rows=1000/num_instances=1000/packed=false/range/default 2952318 ns/iter (± 69866) 2997422 ns/iter (± 47101) 0.98
datastore/num_rows=1000/num_instances=1000/gc/default 2425312 ns/iter (± 9170) 2430982 ns/iter (± 3903) 1.00
mono_points_arrow/generate_message_bundles 27582815 ns/iter (± 1579541) 27361281 ns/iter (± 1123711) 1.01
mono_points_arrow/generate_messages 126663078 ns/iter (± 1070774) 113812283 ns/iter (± 835795) 1.11
mono_points_arrow/encode_log_msg 156944200 ns/iter (± 1632807) 144690195 ns/iter (± 2233171) 1.08
mono_points_arrow/encode_total 311922547 ns/iter (± 1802501) 285260861 ns/iter (± 1624624) 1.09
mono_points_arrow/decode_log_msg 190679457 ns/iter (± 1204467) 178047417 ns/iter (± 717359) 1.07
mono_points_arrow/decode_message_bundles 70722249 ns/iter (± 1096716) 60299037 ns/iter (± 987875) 1.17
mono_points_arrow/decode_total 259071553 ns/iter (± 1187479) 237797991 ns/iter (± 1261283) 1.09
mono_points_arrow_batched/generate_message_bundles 19762814 ns/iter (± 1609945) 20738420 ns/iter (± 1330384) 0.95
mono_points_arrow_batched/generate_messages 4262898 ns/iter (± 162891) 4249564 ns/iter (± 163095) 1.00
mono_points_arrow_batched/encode_log_msg 1370225 ns/iter (± 8545) 1369393 ns/iter (± 4450) 1.00
mono_points_arrow_batched/encode_total 27498535 ns/iter (± 1745494) 27552349 ns/iter (± 1299622) 1.00
mono_points_arrow_batched/decode_log_msg 780578 ns/iter (± 2916) 777435 ns/iter (± 2279) 1.00
mono_points_arrow_batched/decode_message_bundles 7531005 ns/iter (± 166755) 7613252 ns/iter (± 97516) 0.99
mono_points_arrow_batched/decode_total 8386604 ns/iter (± 365538) 8422214 ns/iter (± 196503) 1.00
batch_points_arrow/generate_message_bundles 198706 ns/iter (± 779) 205340 ns/iter (± 22418) 0.97
batch_points_arrow/generate_messages 5066 ns/iter (± 28) 5047 ns/iter (± 23) 1.00
batch_points_arrow/encode_log_msg 261040 ns/iter (± 1831) 261014 ns/iter (± 1870) 1.00
batch_points_arrow/encode_total 488349 ns/iter (± 2757) 484626 ns/iter (± 2623) 1.01
batch_points_arrow/decode_log_msg 211433 ns/iter (± 796) 210395 ns/iter (± 578) 1.00
batch_points_arrow/decode_message_bundles 1893 ns/iter (± 15) 1882 ns/iter (± 6) 1.01
batch_points_arrow/decode_total 221303 ns/iter (± 1287) 220476 ns/iter (± 1967) 1.00
arrow_mono_points/insert 2529326427 ns/iter (± 5137330) 2290773167 ns/iter (± 6874465) 1.10
arrow_mono_points/query 1181497 ns/iter (± 9495) 1173849 ns/iter (± 6443) 1.01
arrow_batch_points/insert 1157077 ns/iter (± 6316) 1149367 ns/iter (± 2168) 1.01
arrow_batch_points/query 14626 ns/iter (± 170) 14417 ns/iter (± 36) 1.01
arrow_batch_vecs/insert 26424 ns/iter (± 144) 26492 ns/iter (± 45) 1.00
arrow_batch_vecs/query 325239 ns/iter (± 1198) 325760 ns/iter (± 730) 1.00
tuid/Tuid::random 34 ns/iter (± 0) 34 ns/iter (± 0) 1

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.