Render fixes (#292)

* Simplify message logging

* Fix setting Z in shaders

* Update debug plugin usage

* Log up to trace messages when run through jetbrains

* Filter duplicate tiles in tile patterns

* Add trace statement
This commit is contained in:
Max Ammann 2023-10-09 13:04:51 +01:00 committed by GitHub
parent 9d075527c6
commit c45cc55bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 43 additions and 46 deletions

View File

@ -2,15 +2,15 @@
<configuration default="false" name="Run demo (debug)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run -p maplibre-demo -- headed" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="false" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs>
<env name="RUST_LOG" value="info" />
<env name="RUST_LOG" value="maplibre=trace" />
</envs>
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />

View File

@ -2,14 +2,16 @@
<configuration default="false" name="Run demo (release)" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run -p maplibre-demo --release -- headed" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<option name="emulateTerminal" value="false" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="emulateTerminal" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<envs />
<envs>
<env name="RUST_LOG" value="maplibre=trace" />
</envs>
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">

View File

@ -14,7 +14,6 @@ use maplibre::{
http_client::ReqwestHttpClient, run_multithreaded, scheduler::TokioScheduler,
ReqwestOffscreenKernelEnvironment,
},
raster::{DefaultRasterTransferables, RasterPlugin},
render::{builder::RendererBuilder, settings::WgpuSettings, RenderPlugin},
style::Style,
window::{MapWindow, MapWindowConfig, WindowSize},
@ -125,8 +124,12 @@ pub fn run_headed_map(
renderer_builder,
vec![
Box::new(RenderPlugin::default()),
//Box::new(VectorPlugin::<DefaultVectorTransferables>::default()),
Box::new(RasterPlugin::<DefaultRasterTransferables>::default()),
Box::new(maplibre::vector::VectorPlugin::<
maplibre::vector::DefaultVectorTransferables,
>::default()),
// Box::new(maplibre::raster::RasterPlugin::<
// maplibre::raster::DefaultRasterTransferables,
// >::default()),
#[cfg(debug_assertions)]
Box::new(maplibre::debug::DebugPlugin::default()),
],

View File

@ -258,7 +258,7 @@ impl Zoom {
/// tiles would be displayed.
pub fn zoom_level(&self, tile_size: f64) -> ZoomLevel {
// TODO: Also support round() instead of floor() here
let z = (self.0 as f64 + (TILE_SIZE / tile_size).ln() / 2.0_f64.ln()).floor() as u8;
let z = (self.0 + (TILE_SIZE / tile_size).ln() / 2.0_f64.ln()).floor() as u8;
return ZoomLevel(z.max(0));
}
}

View File

@ -9,7 +9,6 @@ use geozero::{
error::GeozeroError, geo_types::GeoWriter, ColumnValue, FeatureProcessor, GeomProcessor,
PropertyProcessor,
};
use log::debug;
use rstar::{Envelope, PointDistance, RTree, RTreeObject, AABB};
use crate::{
@ -312,19 +311,19 @@ impl FeatureProcessor for IndexProcessor {
IndexedGeometry::from_linestring(linestring, self.properties.take().unwrap())
.unwrap(),
),
Some(Geometry::Point(_)) => debug!("Unsupported Point geometry in index"),
Some(Geometry::Line(_)) => debug!("Unsupported Line geometry in index"),
Some(Geometry::MultiPoint(_)) => debug!("Unsupported MultiPoint geometry in index"),
Some(Geometry::MultiLineString(_)) => {
debug!("Unsupported MultiLineString geometry in index")
Some(Geometry::Point(_))
| Some(Geometry::Line(_))
| Some(Geometry::MultiPoint(_))
| Some(Geometry::MultiLineString(_))
| Some(Geometry::MultiPolygon(_))
| Some(Geometry::GeometryCollection(_))
| Some(Geometry::Rect(_))
| Some(Geometry::Triangle(_)) => {
log::debug!("Unsupported geometry in index")
}
Some(Geometry::MultiPolygon(_)) => debug!("Unsupported MultiPolygon geometry in index"),
Some(Geometry::GeometryCollection(_)) => {
debug!("Unsupported GeometryCollection geometry in index")
None => {
log::debug!("No geometry in index")
}
Some(Geometry::Rect(_)) => debug!("Unsupported Rect geometry in index"),
Some(Geometry::Triangle(_)) => debug!("Unsupported Triangle geometry in index"),
None => debug!("No geometry in index"),
};
Ok(())

View File

@ -48,7 +48,6 @@ impl<E: Environment, T: RasterTransferables> System for RequestSystem<E, T> {
..
}: &mut MapContext,
) {
let _tiles = &mut world.tiles;
let view_region =
view_state.create_view_region(view_state.zoom().zoom_level(DEFAULT_TILE_SIZE));

View File

@ -2,8 +2,6 @@
use std::ops::Range;
use log::trace;
/// A [`RenderPass`], which tracks the current pipeline state to ensure all draw calls are valid.
/// It is used to set the current [`RenderPipeline`], [`BindGroups`](BindGroup) and buffers.
/// After all requirements are specified, draw calls can be issued.
@ -21,7 +19,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// Subsequent draw calls will exhibit the behavior defined by the `pipeline`.
pub fn set_render_pipeline(&mut self, pipeline: &'a wgpu::RenderPipeline) {
trace!("set pipeline: {pipeline:?}");
self.pass.set_pipeline(pipeline);
}
@ -64,7 +61,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// The active vertex buffer(s) can be set with [`TrackedRenderPass::set_vertex_buffer`].
pub fn draw(&mut self, vertices: Range<u32>, instances: Range<u32>) {
trace!("draw: {vertices:?} {instances:?}");
self.pass.draw(vertices, instances);
}
@ -73,7 +69,6 @@ impl<'a> TrackedRenderPass<'a> {
/// The active index buffer can be set with [`TrackedRenderPass::set_index_buffer`], while the
/// active vertex buffer(s) can be set with [`TrackedRenderPass::set_vertex_buffer`].
pub fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>) {
trace!("draw indexed: {indices:?} {base_vertex} {instances:?}");
self.pass.draw_indexed(indices, base_vertex, instances);
}
@ -94,7 +89,6 @@ impl<'a> TrackedRenderPass<'a> {
/// }
/// ```
pub fn draw_indirect(&mut self, indirect_buffer: &'a wgpu::Buffer, indirect_offset: u64) {
trace!("draw indirect: {indirect_buffer:?} {indirect_offset}");
self.pass.draw_indirect(indirect_buffer, indirect_offset);
}
@ -122,7 +116,6 @@ impl<'a> TrackedRenderPass<'a> {
indirect_buffer: &'a wgpu::Buffer,
indirect_offset: u64,
) {
trace!("draw indexed indirect: {indirect_buffer:?} {indirect_offset}");
self.pass
.draw_indexed_indirect(indirect_buffer, indirect_offset);
}
@ -131,7 +124,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// Subsequent stencil tests will test against this value.
pub fn set_stencil_reference(&mut self, reference: u32) {
trace!("set stencil reference: {reference}");
self.pass.set_stencil_reference(reference);
}
@ -139,7 +131,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// Subsequent draw calls will discard any fragments that fall outside this region.
pub fn set_scissor_rect(&mut self, x: u32, y: u32, width: u32, height: u32) {
trace!("set_scissor_rect: {x} {y} {width} {height}");
self.pass.set_scissor_rect(x, y, width, height);
}
@ -147,10 +138,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// `Features::PUSH_CONSTANTS` must be enabled on the device in order to call these functions.
pub fn set_push_constants(&mut self, stages: wgpu::ShaderStages, offset: u32, data: &[u8]) {
trace!(
"set push constants: {stages:?} offset: {offset} data.len: {}",
data.len()
);
self.pass.set_push_constants(stages, offset, data);
}
@ -166,7 +153,6 @@ impl<'a> TrackedRenderPass<'a> {
min_depth: f32,
max_depth: f32,
) {
trace!("set viewport: {x} {y} {width} {height} {min_depth} {max_depth}");
self.pass
.set_viewport(x, y, width, height, min_depth, max_depth);
}
@ -175,7 +161,6 @@ impl<'a> TrackedRenderPass<'a> {
///
/// This is a GPU debugging feature. This has no effect on the rendering itself.
pub fn insert_debug_marker(&mut self, label: &str) {
trace!("insert debug marker: {label}");
self.pass.insert_debug_marker(label);
}
@ -200,7 +185,6 @@ impl<'a> TrackedRenderPass<'a> {
/// [`push_debug_group`]: TrackedRenderPass::push_debug_group
/// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group
pub fn push_debug_group(&mut self, label: &str) {
trace!("push_debug_group marker: {label}");
self.pass.push_debug_group(label);
}
@ -217,12 +201,10 @@ impl<'a> TrackedRenderPass<'a> {
/// [`push_debug_group`]: TrackedRenderPass::push_debug_group
/// [`pop_debug_group`]: TrackedRenderPass::pop_debug_group
pub fn pop_debug_group(&mut self) {
trace!("pop_debug_group");
self.pass.pop_debug_group();
}
pub fn set_blend_constant(&mut self, color: wgpu::Color) {
trace!("set blend constant: {color:?}");
self.pass.set_blend_constant(color);
}
}

View File

@ -27,7 +27,7 @@ fn main(
@location(10) z_index: f32,
@builtin(instance_index) instance_idx: u32 // instance_index is used when we have multiple instances of the same "object"
) -> VertexOutput {
let z = 0.0;
let z = -z_index;
let width = 3.0 * zoom_factor;
// The following code moves all "invisible" vertices to (0, 0, 0)

View File

@ -71,6 +71,6 @@ fn main(
);
var final_position = mat4x4<f32>(translate1, translate2, translate3, translate4) * vec4<f32>((scaling * vertex), 1.0);
final_position.z = 1.0;
final_position.z = 10.0;
return VertexOutput(DEBUG_COLOR, final_position);
}

View File

@ -38,8 +38,6 @@ fn main(
);
var final_position = mat4x4<f32>(translate1, translate2, translate3, translate4) * vec4<f32>((scaling * vertex), 1.0);
// FIXME: how to fix z-fighting?
final_position.z = 1.0;
final_position.z = 1.0; // TODO: is this correct?
return VertexOutput(DEBUG_COLOR, final_position);
}

View File

@ -42,6 +42,5 @@ fn main(
let tex_coords = TEX_COORDS[vertex_idx];
var final_position = mat4x4<f32>(translate1, translate2, translate3, translate4) * vec4<f32>(vertex, 1.0);
return VertexOutput(tex_coords, final_position);
}

View File

@ -36,6 +36,8 @@ pub fn tile_view_pattern_system(
return;
};
log::trace!("Tiles in view: {}", view_tiles.len());
tile_view_pattern.update_pattern(view_tiles);
}
}

View File

@ -1,4 +1,4 @@
use std::marker::PhantomData;
use std::{collections::HashSet, marker::PhantomData};
use crate::{
coords::{ViewRegion, Zoom},
@ -61,6 +61,7 @@ impl<Q: Queue<B>, B> TileViewPattern<Q, B> {
world: &World,
) -> Vec<ViewTile> {
let mut view_tiles = Vec::with_capacity(self.view_tiles.len());
let mut source_tiles = HashSet::new(); // TODO: Optimization potential: Replace wit a bitmap, that allows false-negative matches
for coords in view_region.iter() {
if coords.build_quad_key().is_none() {
@ -73,6 +74,16 @@ impl<Q: Queue<B>, B> TileViewPattern<Q, B> {
} else if let Some(parent_coords) = container.get_available_parent(coords, world) {
log::debug!("Could not find data at {coords}. Falling back to {parent_coords}");
if source_tiles.contains(&parent_coords) {
// Performance optimization: Suppose the map only offers zoom levels 0-14.
// If we build the pattern for z=18, we won't find tiles. Thus we start
// looking for parents. We might find multiple times the same parent from
// tiles on z=18.
continue;
}
source_tiles.insert(parent_coords);
SourceShapes::Parent(TileShape::new(parent_coords, zoom))
} else if let Some(children_coords) =
container.get_available_children(coords, world, CHILDREN_SEARCH_DEPTH)

View File

@ -121,6 +121,8 @@ pub async fn run_maplibre(new_worker: js_sys::Function) -> Result<(), JSError> {
Box::<maplibre::render::RenderPlugin>::default(),
Box::<maplibre::vector::VectorPlugin<platform::UsedVectorTransferables>>::default(),
// Box::new(RasterPlugin::<platform::UsedRasterTransferables>::default()),
#[cfg(debug_assertions)]
Box::<maplibre::debug::DebugPlugin>::default(),
],
)
.unwrap();