summaryrefslogtreecommitdiff
path: root/client/src/render/scene
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-01-26 22:22:53 +0100
committermetamuffin <metamuffin@disroot.org>2025-01-26 22:22:53 +0100
commit724e6e4d97f608282e891742565b1036f3e970d5 (patch)
treed75c43703c55ff35a8dd7f01960812f5b147d683 /client/src/render/scene
parentf0b213d51ee7b44362b5618bf5bd1eacf50d2bb8 (diff)
downloadweareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar
weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.bz2
weareserver-724e6e4d97f608282e891742565b1036f3e970d5.tar.zst
graphics config
Diffstat (limited to 'client/src/render/scene')
-rw-r--r--client/src/render/scene/demand_map.rs18
-rw-r--r--client/src/render/scene/mod.rs38
-rw-r--r--client/src/render/scene/pipelines.rs9
-rw-r--r--client/src/render/scene/textures.rs4
4 files changed, 56 insertions, 13 deletions
diff --git a/client/src/render/scene/demand_map.rs b/client/src/render/scene/demand_map.rs
index 16fa181..c27eaac 100644
--- a/client/src/render/scene/demand_map.rs
+++ b/client/src/render/scene/demand_map.rs
@@ -25,7 +25,7 @@ pub struct DemandMap<K, V> {
inner: RwLock<DemandMapState<K, V>>,
}
struct DemandMapState<K, V> {
- values: HashMap<K, V>,
+ values: HashMap<K, (V, usize)>,
needed: HashSet<K>,
size_metric: usize,
}
@@ -46,18 +46,30 @@ impl<K: Hash + Eq + Clone, V: Clone> DemandMap<K, V> {
pub fn insert(&self, key: K, value: V, size: usize) {
let mut s = self.inner.write().unwrap();
s.needed.remove(&key);
- s.values.insert(key, value);
+ if let Some((_, old_size)) = s.values.insert(key, (value, size)) {
+ s.size_metric -= old_size;
+ }
s.size_metric += size;
}
pub fn try_get(&self, key: K) -> Option<V> {
let mut s = self.inner.write().unwrap();
- if let Some(k) = s.values.get(&key) {
+ if let Some((k, _)) = s.values.get(&key) {
Some(k.to_owned())
} else {
s.needed.insert(key);
None
}
}
+ pub fn regenerate_all(&self) {
+ let mut s = self.inner.write().unwrap();
+ let keys = s.values.keys().cloned().collect::<Vec<_>>();
+ s.needed.extend(keys);
+ }
+ pub fn clear(&self) {
+ let mut s = self.inner.write().unwrap();
+ s.values.clear();
+ s.size_metric = 0;
+ }
}
impl<K, V> Widget for &DemandMap<K, V> {
diff --git a/client/src/render/scene/mod.rs b/client/src/render/scene/mod.rs
index ad7e0ce..16eecfc 100644
--- a/client/src/render/scene/mod.rs
+++ b/client/src/render/scene/mod.rs
@@ -21,16 +21,21 @@ pub mod pipelines;
pub mod textures;
pub mod vertex_buffers;
-use super::{shaders::SceneShaders, GraphicsConfig};
+use super::{GraphicsConfig, shaders::SceneShaders};
use crate::{armature::RArmature, download::Downloader};
use anyhow::Result;
use bytemuck::{Pod, Zeroable};
use demand_map::DemandMap;
use egui::{Grid, Widget};
use glam::{UVec3, UVec4, Vec2, Vec3, Vec3A, uvec3, uvec4};
-use log::{debug, trace};
+use log::{debug, info, trace};
use pipelines::SceneBgLayouts;
-use std::{hash::Hash, marker::PhantomData, sync::Arc, time::Instant};
+use std::{
+ hash::Hash,
+ marker::PhantomData,
+ sync::{Arc, RwLock},
+ time::Instant,
+};
use textures::MipGenerationPipeline;
use weareshared::{
Affine3A,
@@ -49,7 +54,7 @@ pub struct ScenePreparer {
layouts: SceneBgLayouts,
shaders: SceneShaders,
render_format: TextureFormat,
- config: GraphicsConfig,
+ config: RwLock<GraphicsConfig>,
downloader: Arc<Downloader>,
textures: DemandMap<TextureSpec, (Arc<Texture>, Arc<BindGroup>)>,
@@ -143,7 +148,7 @@ impl ScenePreparer {
) -> Self {
Self {
render_format,
- config,
+ config: config.into(),
layouts: SceneBgLayouts::load(&device),
shaders: SceneShaders::load(&device),
device,
@@ -163,6 +168,22 @@ impl ScenePreparer {
mip_generation_pipelines: DemandMap::new(),
}
}
+ pub fn reconfigure(&self, config: &GraphicsConfig) {
+ let mut cc = self.config.write().unwrap();
+ if cc.max_anisotropy != config.max_anisotropy || cc.max_mip_count != config.max_mip_count {
+ info!("clear all scene textures");
+ self.textures.clear();
+ self.mesh_parts.clear();
+ self.prefabs.clear();
+ }
+ if cc.sample_count != config.sample_count {
+ info!("clear all scene pipelines");
+ self.pipelines.clear();
+ self.mesh_parts.clear();
+ self.prefabs.clear();
+ }
+ *cc = config.clone();
+ }
pub fn update(&self) -> Result<usize> {
let mut num_done = 0;
@@ -204,7 +225,12 @@ impl ScenePreparer {
for spec in self.pipelines.needed() {
self.pipelines.insert(
spec.clone(),
- Arc::new(spec.create(&self.device, &self.layouts, &self.shaders, &self.config)),
+ Arc::new(spec.create(
+ &self.device,
+ &self.layouts,
+ &self.shaders,
+ &self.config.read().unwrap().clone(),
+ )),
0,
);
}
diff --git a/client/src/render/scene/pipelines.rs b/client/src/render/scene/pipelines.rs
index 53064c9..834d86d 100644
--- a/client/src/render/scene/pipelines.rs
+++ b/client/src/render/scene/pipelines.rs
@@ -16,6 +16,7 @@
*/
use super::{GraphicsConfig, PipelineSpec};
use crate::render::shaders::SceneShaders;
+use log::info;
use wgpu::{
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType, BlendState,
BufferBindingType, ColorTargetState, ColorWrites, CompareFunction, DepthBiasState,
@@ -95,8 +96,12 @@ impl PipelineSpec {
shaders: &SceneShaders,
config: &GraphicsConfig,
) -> RenderPipeline {
+ info!(
+ "creating scene pipeline (format={:?}, skin={}, culling={})",
+ self.format, self.backface_culling, self.skin
+ );
let pipeline_layout = device.create_pipeline_layout(&PipelineLayoutDescriptor {
- label: None,
+ label: Some("scene pipeline layout"),
bind_group_layouts: &[&layouts.texture, &layouts.texture, &layouts.material],
push_constant_ranges: &[PushConstantRange {
// 4x4 model * view * project
@@ -106,7 +111,7 @@ impl PipelineSpec {
}],
});
device.create_render_pipeline(&RenderPipelineDescriptor {
- label: None,
+ label: Some("scene pipeline"),
layout: Some(&pipeline_layout),
fragment: Some(FragmentState {
module: &shaders.fragment_pbr,
diff --git a/client/src/render/scene/textures.rs b/client/src/render/scene/textures.rs
index f85f21f..c385be2 100644
--- a/client/src/render/scene/textures.rs
+++ b/client/src/render/scene/textures.rs
@@ -94,7 +94,7 @@ impl ScenePreparer {
TextureFormat::Rgba8UnormSrgb
},
None,
- &self.config,
+ &self.config.read().unwrap().clone(),
);
self.placeholder_textures.insert(kind, tex_bg, 4);
*num_done += 1;
@@ -122,7 +122,7 @@ impl ScenePreparer {
dims.1,
format,
Some(&mipgen),
- &self.config,
+ &self.config.read().unwrap().clone(),
);
self.textures.insert(spec, tex_bg, image.len());
debug!(