From 64eda770fbedd56c88f00419221c76a828205b2c Mon Sep 17 00:00:00 2001 From: Isse Date: Sun, 28 Jan 2024 16:08:07 +0100 Subject: [PATCH] cache max texture size --- voxygen/src/render/renderer.rs | 36 ++++++++++++------- .../src/render/renderer/rain_occlusion_map.rs | 7 ++-- voxygen/src/render/renderer/shadow_map.rs | 7 ++-- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/voxygen/src/render/renderer.rs b/voxygen/src/render/renderer.rs index e07d5157c8..98ba157c64 100644 --- a/voxygen/src/render/renderer.rs +++ b/voxygen/src/render/renderer.rs @@ -187,6 +187,8 @@ pub struct Renderer { /// Supported present modes. present_modes: Vec, + /// Cached max texture size. + max_texture_size: u32, } impl Renderer { @@ -349,6 +351,8 @@ impl Renderer { ); } + let max_texture_size = device.limits().max_texture_dimension_2d; + let surface_capabilities = surface.get_capabilities(&adapter); let format = surface_capabilities.formats[0]; info!("Using {:?} as the surface format", format); @@ -409,18 +413,22 @@ impl Renderer { &device, (dims.width, dims.height), &ShadowMapMode::try_from(pipeline_modes.shadow).unwrap_or_default(), + max_texture_size, ) .map_err(|err| { warn!("Could not create shadow map views: {:?}", err); }) .ok(); - let rain_occlusion_view = - RainOcclusionMap::create_view(&device, &pipeline_modes.rain_occlusion) - .map_err(|err| { - warn!("Could not create rain occlusion map views: {:?}", err); - }) - .ok(); + let rain_occlusion_view = RainOcclusionMap::create_view( + &device, + &pipeline_modes.rain_occlusion, + max_texture_size, + ) + .map_err(|err| { + warn!("Could not create rain occlusion map views: {:?}", err); + }) + .ok(); let shaders = Shaders::load_expect(""); let shaders_watcher = shaders.reload_watcher(); @@ -614,7 +622,9 @@ impl Renderer { graphics_backend, intermediate_format, + present_modes, + max_texture_size, }) } @@ -808,7 +818,12 @@ impl Renderer { if let (Some((point_depth, directed_depth)), ShadowMode::Map(mode)) = (shadow_views, self.pipeline_modes.shadow) { - match ShadowMap::create_shadow_views(&self.device, (dims.x, dims.y), &mode) { + match ShadowMap::create_shadow_views( + &self.device, + (dims.x, dims.y), + &mode, + self.max_texture_size, + ) { Ok((new_point_depth, new_directed_depth)) => { *point_depth = new_point_depth; *directed_depth = new_directed_depth; @@ -824,6 +839,7 @@ impl Renderer { match RainOcclusionMap::create_view( &self.device, &self.pipeline_modes.rain_occlusion, + self.max_texture_size, ) { Ok(new_rain_depth) => { *rain_depth = new_rain_depth; @@ -1420,11 +1436,7 @@ impl Renderer { } /// Return the maximum supported texture size. - pub fn max_texture_size(&self) -> u32 { Self::max_texture_size_raw(&self.device) } - - fn max_texture_size_raw(device: &wgpu::Device) -> u32 { - device.limits().max_texture_dimension_2d - } + pub fn max_texture_size(&self) -> u32 { self.max_texture_size } /// Create a new immutable texture from the provided image. /// # Panics diff --git a/voxygen/src/render/renderer/rain_occlusion_map.rs b/voxygen/src/render/renderer/rain_occlusion_map.rs index 720c821377..bdc44f9861 100644 --- a/voxygen/src/render/renderer/rain_occlusion_map.rs +++ b/voxygen/src/render/renderer/rain_occlusion_map.rs @@ -1,9 +1,6 @@ use crate::{render::pipelines::rain_occlusion, scene::terrain::RAIN_OCCLUSION_CHUNKS}; -use super::{ - super::{texture::Texture, RenderError, ShadowMapMode}, - Renderer, -}; +use super::super::{texture::Texture, RenderError, ShadowMapMode}; use common::{terrain::TerrainChunkSize, vol::RectVolSize}; use vek::*; @@ -121,11 +118,11 @@ impl RainOcclusionMap { pub(super) fn create_view( device: &wgpu::Device, mode: &ShadowMapMode, + max_texture_size: u32, ) -> Result { // (Attempt to) apply resolution factor to rain occlusion map resolution. let resolution_factor = mode.resolution.clamped(0.25, 4.0); - let max_texture_size = Renderer::max_texture_size_raw(device); let size = (RAIN_OCCLUSION_CHUNKS as f32).sqrt().ceil() as u32 * TerrainChunkSize::RECT_SIZE * 2; diff --git a/voxygen/src/render/renderer/shadow_map.rs b/voxygen/src/render/renderer/shadow_map.rs index ef9b363932..7b5ab16e0f 100644 --- a/voxygen/src/render/renderer/shadow_map.rs +++ b/voxygen/src/render/renderer/shadow_map.rs @@ -1,7 +1,4 @@ -use super::{ - super::{pipelines::shadow, texture::Texture, RenderError, ShadowMapMode}, - Renderer, -}; +use super::super::{pipelines::shadow, texture::Texture, RenderError, ShadowMapMode}; use vek::*; /// A type that holds shadow map data. Since shadow mapping may not be @@ -150,11 +147,11 @@ impl ShadowMap { device: &wgpu::Device, size: (u32, u32), mode: &ShadowMapMode, + max_texture_size: u32, ) -> Result<(Texture, Texture), RenderError> { // (Attempt to) apply resolution factor to shadow map resolution. let resolution_factor = mode.resolution.clamped(0.25, 4.0); - let max_texture_size = Renderer::max_texture_size_raw(device); // Limit to max texture size, rather than erroring. let size = Vec2::new(size.0, size.1).map(|e| { let size = e as f32 * resolution_factor;