address/remove TODOs, fix comment typos, enable wgpu/trace feature by default (So no recompile is needed to collect an API trace)

This commit is contained in:
Imbris 2021-05-12 23:59:51 -04:00
parent 38d2d46165
commit 8403e4c483
27 changed files with 60 additions and 89 deletions

7
Cargo.lock generated
View File

@ -184,6 +184,9 @@ name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
dependencies = [
"serde",
]
[[package]]
name = "as-slice"
@ -6640,6 +6643,7 @@ dependencies = [
"naga",
"parking_lot 0.11.1",
"raw-window-handle",
"serde",
"smallvec",
"wasm-bindgen",
"wasm-bindgen-futures",
@ -6673,6 +6677,8 @@ dependencies = [
"parking_lot 0.11.1",
"profiling",
"raw-window-handle",
"ron",
"serde",
"smallvec",
"thiserror",
"wgpu-types",
@ -6694,6 +6700,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa248d90c8e6832269b8955bf800e8241f942c25e18a235b7752226804d21556"
dependencies = [
"bitflags",
"serde",
]
[[package]]

View File

@ -27,6 +27,7 @@ void main() {
float(gl_VertexIndex % 2) * 4.0 - 1.0
);
// Flip y and transform into 0.0 to 1.0 range
uv = (v_pos * vec2(1.0, -1.0) + 1.0) * 0.5;
gl_Position = vec4(v_pos, 0.0, 1.0);

View File

@ -24,7 +24,7 @@ layout(std140, set = 0, binding = 0) uniform u_globals {
// 1 - ThirdPerson
uint cam_mode;
float sprite_render_distance;
float gloabls_dummy; // Fix alignment.
float globals_dummy; // Fix alignment.
};
// Specifies the pattern used in the player dithering

View File

@ -45,7 +45,7 @@ i18n = {package = "veloren-i18n", path = "i18n"}
# Graphics
winit = {version = "0.24.0", features = ["serde"]}
wgpu = "0.8.1"
wgpu = { version = "0.8.1", features = ["trace"] }
wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" }
bytemuck = { version="1.4", features=["derive"] }
shaderc = "0.6.2"

View File

@ -2200,7 +2200,7 @@ impl Hud {
let gpu_timings = global_state.window.renderer().timings();
if !gpu_timings.is_empty() {
let num_timings = gpu_timings.len();
// Make sure we have enoung ids
// Make sure we have enough ids
if self.ids.gpu_timings.len() < num_timings {
self.ids
.gpu_timings

View File

@ -11,7 +11,6 @@ pub enum RenderError {
}
use std::fmt;
// TODO: just impl and use Display?
impl fmt::Debug for RenderError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {

View File

@ -9,7 +9,7 @@ pub struct Instances<T: Copy + Pod> {
impl<T: Copy + Pod> Instances<T> {
pub fn new(device: &wgpu::Device, len: usize) -> Self {
Self {
// TODO: examine if we have Intances that are not updated (e.g. sprites) and if there
// TODO: examine if we have Instances that are not updated (e.g. sprites) and if there
// would be any gains from separating those out
buf: DynamicBuffer::new(device, len, wgpu::BufferUsage::VERTEX),
}

View File

@ -33,9 +33,8 @@ pub use self::{
shadow::{Locals as ShadowLocals, PointLightMatrix},
skybox::{create_mesh as create_skybox_mesh, Vertex as SkyboxVertex},
sprite::{
create_verts_buffer as create_sprite_verts_buffer, Instance as SpriteInstance,
SpriteGlobalsBindGroup, Vertex as SpriteVertex,
VERT_PAGE_SIZE as SPRITE_VERT_PAGE_SIZE,
Instance as SpriteInstance, SpriteGlobalsBindGroup, SpriteVerts,
Vertex as SpriteVertex, VERT_PAGE_SIZE as SPRITE_VERT_PAGE_SIZE,
},
terrain::{Locals as TerrainLocals, TerrainLayout, Vertex as TerrainVertex},
ui::{

View File

@ -158,7 +158,6 @@ impl CloudsPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -71,7 +71,6 @@ impl DebugPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -192,7 +192,6 @@ impl FigurePipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -74,7 +74,6 @@ impl FluidPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -163,7 +163,6 @@ impl LodTerrainPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -191,7 +191,6 @@ impl ParticlePipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -147,7 +147,6 @@ impl ShadowFigurePipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,
@ -221,7 +220,6 @@ impl ShadowPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,
@ -297,7 +295,6 @@ impl PointShadowPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -50,7 +50,6 @@ impl SkyboxPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,
@ -111,12 +110,11 @@ impl SkyboxPipeline {
}
}
// TODO: generate mesh in vertex shader
#[rustfmt::skip]
pub fn create_mesh() -> Mesh<Vertex> {
let mut mesh = Mesh::new();
// -x
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [-1.0, -1.0, -1.0] },
Vertex { pos: [-1.0, 1.0, -1.0] },
@ -124,7 +122,6 @@ pub fn create_mesh() -> Mesh<Vertex> {
Vertex { pos: [-1.0, -1.0, 1.0] },
));
// +x
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [ 1.0, -1.0, 1.0] },
Vertex { pos: [ 1.0, 1.0, 1.0] },
@ -132,7 +129,6 @@ pub fn create_mesh() -> Mesh<Vertex> {
Vertex { pos: [ 1.0, -1.0, -1.0] },
));
// -y
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [ 1.0, -1.0, -1.0] },
Vertex { pos: [-1.0, -1.0, -1.0] },
@ -140,7 +136,6 @@ pub fn create_mesh() -> Mesh<Vertex> {
Vertex { pos: [ 1.0, -1.0, 1.0] },
));
// +y
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [ 1.0, 1.0, 1.0] },
Vertex { pos: [-1.0, 1.0, 1.0] },
@ -148,7 +143,6 @@ pub fn create_mesh() -> Mesh<Vertex> {
Vertex { pos: [ 1.0, 1.0, -1.0] },
));
// -z
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [-1.0, -1.0, -1.0] },
Vertex { pos: [ 1.0, -1.0, -1.0] },
@ -156,7 +150,6 @@ pub fn create_mesh() -> Mesh<Vertex> {
Vertex { pos: [-1.0, 1.0, -1.0] },
));
// +z
#[rustfmt::skip]
mesh.push_quad(Quad::new(
Vertex { pos: [-1.0, 1.0, 1.0] },
Vertex { pos: [ 1.0, 1.0, 1.0] },

View File

@ -1,7 +1,6 @@
use super::{
super::{
buffer::Buffer, AaMode, GlobalsLayouts, Mesh, Renderer, TerrainLayout, Texture,
Vertex as VertexTrait,
buffer::Buffer, AaMode, GlobalsLayouts, Mesh, TerrainLayout, Texture, Vertex as VertexTrait,
},
lod_terrain, GlobalModel,
};
@ -77,14 +76,19 @@ impl VertexTrait for Vertex {
const STRIDE: wgpu::BufferAddress = mem::size_of::<Self>() as wgpu::BufferAddress;
}
pub fn create_verts_buffer(renderer: &mut Renderer, mesh: Mesh<Vertex>) -> Buffer<Vertex> {
renderer.ensure_sufficient_index_length::<Vertex>(VERT_PAGE_SIZE as usize);
// TODO: type Buffer by Usage
Buffer::new(
&renderer.device,
pub struct SpriteVerts(Buffer<Vertex>);
//pub struct SpriteVerts(Texture);
pub(in super::super) fn create_verts_buffer(
device: &wgpu::Device,
mesh: Mesh<Vertex>,
) -> SpriteVerts {
// TODO: type Buffer by wgpu::BufferUsage
SpriteVerts(Buffer::new(
&device,
wgpu::BufferUsage::STORAGE,
mesh.vertices(),
)
))
}
#[repr(C)]
@ -203,8 +207,7 @@ impl SpriteLayout {
global_model: &GlobalModel,
lod_data: &lod_terrain::LodData,
noise: &Texture,
//sprite_verts: &Texture,
sprite_verts: &Buffer<Vertex>,
sprite_verts: &SpriteVerts,
) -> wgpu::BindGroup {
let mut entries = GlobalsLayouts::bind_base_globals(global_model, lod_data, noise);
@ -212,7 +215,7 @@ impl SpriteLayout {
// sprite_verts
wgpu::BindGroupEntry {
binding: 12,
resource: sprite_verts.buf.as_entire_binding(),
resource: sprite_verts.0.buf.as_entire_binding(),
},
]);
@ -229,7 +232,7 @@ impl SpriteLayout {
global_model: &GlobalModel,
lod_data: &lod_terrain::LodData,
noise: &Texture,
sprite_verts: &Buffer<Vertex>,
sprite_verts: &SpriteVerts,
) -> SpriteGlobalsBindGroup {
let bind_group =
self.bind_globals_inner(device, global_model, lod_data, noise, sprite_verts);
@ -268,7 +271,6 @@ impl SpritePipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -229,7 +229,6 @@ impl TerrainPipeline {
let samples = match aa_mode {
AaMode::None | AaMode::Fxaa => 1,
// TODO: Ensure sampling in the shader is exactly between the 4 texels
AaMode::MsaaX4 => 4,
AaMode::MsaaX8 => 8,
AaMode::MsaaX16 => 16,

View File

@ -100,8 +100,7 @@ enum State {
/// GPU, along with pipeline state objects (PSOs) needed to renderer different
/// kinds of models to the screen.
pub struct Renderer {
// TODO: remove pub(super)
pub(super) device: Arc<wgpu::Device>,
device: Arc<wgpu::Device>,
queue: wgpu::Queue,
surface: wgpu::Surface,
swap_chain: wgpu::SwapChain,
@ -165,7 +164,7 @@ impl Renderer {
_ => None,
})
.unwrap_or(
wgpu::BackendBit::PRIMARY, /* | wgpu::BackendBit::SECONDARY */
(wgpu::BackendBit::PRIMARY | wgpu::BackendBit::SECONDARY) & !wgpu::BackendBit::GL,
);
let instance = wgpu::Instance::new(backend_bit);
@ -196,12 +195,9 @@ impl Renderer {
// TODO
label: None,
features: wgpu::Features::DEPTH_CLAMPING
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgpu::Features::PUSH_CONSTANTS
// TODO: make optional based on enabling profiling setting?
// woould require recreating the device/queue if this setting changes
// alternatively it could be a compile time feature toggle
| (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES),
| wgpu::Features::ADDRESS_MODE_CLAMP_TO_BORDER
| wgpu::Features::PUSH_CONSTANTS
| (adapter.features() & wgpu_profiler::GpuProfiler::REQUIRED_WGPU_FEATURES),
limits,
},
std::env::var_os("WGPU_TRACE_DIR")
@ -567,8 +563,6 @@ impl Renderer {
.into_tuple();
let (width, height, sample_count) = match mode.aa {
AaMode::None | AaMode::Fxaa => (upscaled.0, upscaled.1, 1),
// TODO: Ensure sampling in the shader is exactly between the 4 texels
// TODO: Figure out how to do upscaling correctly with SSAA
AaMode::MsaaX4 => (upscaled.0, upscaled.1, 4),
AaMode::MsaaX8 => (upscaled.0, upscaled.1, 8),
AaMode::MsaaX16 => (upscaled.0, upscaled.1, 16),
@ -982,6 +976,11 @@ impl Renderer {
}
}
pub fn create_sprite_verts(&mut self, mesh: Mesh<sprite::Vertex>) -> sprite::SpriteVerts {
self.ensure_sufficient_index_length::<sprite::Vertex>(sprite::VERT_PAGE_SIZE as usize);
sprite::create_verts_buffer(&self.device, mesh)
}
/// Create a new model from the provided mesh.
/// If the provided mesh is empty this returns None
pub fn create_model<V: Vertex>(&mut self, mesh: &Mesh<V>) -> Option<Model<V>> {
@ -1125,6 +1124,8 @@ impl Renderer {
}
}
// Consider reenabling at some time
//
// /// Queue the rendering of the player silhouette in the upcoming frame.
// pub fn render_player_shadow(
// &mut self,

View File

@ -1,6 +1,5 @@
use super::{
super::{
buffer::Buffer,
pipelines::{
debug, figure, lod_terrain, shadow, sprite, terrain, ui, ColLights, GlobalModel,
GlobalsBindGroup,
@ -25,7 +24,7 @@ impl Renderer {
&self,
global_model: &GlobalModel,
lod_data: &lod_terrain::LodData,
sprite_verts: &Buffer<sprite::Vertex>,
sprite_verts: &sprite::SpriteVerts,
) -> sprite::SpriteGlobalsBindGroup {
self.layouts.sprite.bind_globals(
&self.device,

View File

@ -49,7 +49,7 @@ impl<'frame> Pipelines<'frame> {
}
// Borrow the fields we need from the renderer so that the GpuProfiler can be
// dijointly borrowed mutably
// disjointly borrowed mutably
struct RendererBorrow<'frame> {
queue: &'frame wgpu::Queue,
device: &'frame wgpu::Device,
@ -405,7 +405,7 @@ impl<'frame> Drop for Drawer<'frame> {
fn drop(&mut self) {
let mut encoder = self.encoder.take().unwrap();
// If taking a screenshota and the blit pipeline is available
// If taking a screenshot and the blit pipeline is available
// NOTE: blit pipeline should always be available for now so we don't report an
// error if it isn't
if let Some((screenshot, blit)) = self

View File

@ -204,7 +204,6 @@ impl ShadowMap {
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::RENDER_ATTACHMENT,
};
//TODO: (0, levels - 1), ?? from master
let point_shadow_view = wgpu::TextureViewDescriptor {
label: None,
format: Some(wgpu::TextureFormat::Depth24Plus),

View File

@ -168,20 +168,9 @@ fn handle_main_events_cleared(
if let Some(last) = states.last_mut() {
span!(guard, "Render");
let renderer = global_state.window.renderer_mut();
// // Clear the shadow maps.
// renderer.clear_shadows();
// // Clear the screen
// renderer.clear();
// Render the screen using the global renderer
last.render(renderer, &global_state.settings);
// Finish the frame.
// TODO: do this as part of dropping rendering thing
//global_state.window.renderer_mut().flush().unwrap();
// // Display the frame on the window.
// global_state
// .window
// .swap_buffers()
// .expect("Failed to swap window buffers!");
drop(guard);
}

View File

@ -77,7 +77,7 @@ fn clamp_and_modulate(ori: Vec3<f32>) -> Vec3<f32> {
/// The only requirements on n and f are: 1/n ≠ 1/f, and 0 ≤ 1/n * 1/f.
///
/// This ensures that the near and far plane are not identical (or else your
/// projection would not covver any distance), and that they have the same sign
/// projection would not cover any distance), and that they have the same sign
/// (or else we cannot rely on clipping to properly fix your scene). This also
/// ensures that at least one of 1/n and 1/f is not 0, and by construction it
/// guarantees that neither n nor f are 0; these are required in order to make

View File

@ -5267,7 +5267,7 @@ impl FigureColLights {
(0, 0),
gfx::format::Swizzle::new(),
gfx::texture::SamplerInfo::new(
gfx::texture::FilterMetho>:Bilinear,
gfx::texture::FilterMethod::Bilinear,
gfx::texture::WrapMode::Clamp,
),
)?;

View File

@ -31,7 +31,8 @@ impl Lod {
client.world_data().lod_alt.raw(),
client.world_data().lod_horizon.raw(),
settings.graphics.lod_detail.max(100).min(2500),
// water_color().into_array().into(),
/* TODO: figure out how we want to do this without color borders?
* water_color().into_array().into(), */
),
}
}

View File

@ -9,10 +9,9 @@ use crate::{
terrain::{generate_mesh, SUNLIGHT},
},
render::{
create_sprite_verts_buffer,
pipelines::{self, ColLights},
Buffer, ColLightInfo, FirstPassDrawer, FluidVertex, GlobalModel, Instances, LodData, Mesh,
Model, RenderError, Renderer, SpriteGlobalsBindGroup, SpriteInstance, SpriteVertex,
ColLightInfo, FirstPassDrawer, FluidVertex, GlobalModel, Instances, LodData, Mesh, Model,
RenderError, Renderer, SpriteGlobalsBindGroup, SpriteInstance, SpriteVertex, SpriteVerts,
TerrainLocals, TerrainShadowDrawer, TerrainVertex, SPRITE_VERT_PAGE_SIZE,
},
};
@ -372,7 +371,7 @@ pub struct SpriteRenderContext {
// Maps sprite kind + variant to data detailing how to render it
sprite_data: Arc<HashMap<(SpriteKind, usize), [SpriteData; SPRITE_LOD_LEVELS]>>,
sprite_col_lights: Arc<ColLights<pipelines::sprite::Locals>>,
sprite_verts_buffer: Arc<Buffer<SpriteVertex>>,
sprite_verts_buffer: Arc<SpriteVerts>,
}
pub type SpriteRenderContextLazy = Box<dyn FnMut(&mut Renderer) -> SpriteRenderContext>;
@ -521,7 +520,7 @@ impl SpriteRenderContext {
let sprite_col_lights = renderer.sprite_bind_col_light(sprite_col_lights);
// Write sprite model to a 1D texture
let sprite_verts_buffer = create_sprite_verts_buffer(renderer, sprite_mesh);
let sprite_verts_buffer = renderer.create_sprite_verts(sprite_mesh);
Self {
// TODO: these are all Arcs, would it makes sense to factor out the Arc?
@ -1069,20 +1068,12 @@ impl<V: RectRasterableVol> Terrain<V> {
// data structure (convert the mesh to a model first of course).
Some(todo) if response.started_tick <= todo.started_tick => {
let started_tick = todo.started_tick;
let sprite_instances = {
let mut iter = response.sprite_instances.iter().map(|instances| {
renderer
.create_instances(instances)
.expect("Failed to upload chunk sprite instances to the GPU!")
});
[
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap(),
]
};
let sprite_instances = response.sprite_instances.map(|instances| {
renderer
.create_instances(&instances)
.expect("Failed to upload chunk sprite instances to the GPU!")
});
if let Some(mesh) = response.mesh {
// Full update, insert the whole chunk.