Made the layouts more compact

This commit is contained in:
Capucho 2020-09-13 16:05:11 +01:00 committed by Avi Weinstock
parent 8045b98867
commit 7e3971949d
11 changed files with 145 additions and 223 deletions

View File

@ -48,21 +48,6 @@ impl Locals {
flags,
}
}
fn layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
}],
})
}
}
impl Default for Locals {
@ -129,21 +114,38 @@ pub type BoneMeshes = (Mesh<Vertex>, anim::vek::Aabb<f32>);
pub struct FigureLayout {
pub locals: wgpu::BindGroupLayout,
pub bone_data: wgpu::BindGroupLayout,
pub col_lights: wgpu::BindGroupLayout,
}
impl FigureLayout {
pub fn new(device: &wgpu::Device) -> Self {
Self {
locals: Locals::layout(device),
bone_data: BoneData::layout(device),
col_lights: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
locals: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
// locals
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// bone data
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// col lights
wgpu::BindGroupLayoutEntry {
binding: 2,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
@ -152,7 +154,7 @@ impl FigureLayout {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 3,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
@ -181,17 +183,7 @@ impl FigurePipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Figure pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.light,
&global_layout.shadow,
&global_layout.shadow_maps,
&global_layout.light_shadows,
&layout.locals,
&layout.bone_data,
&layout.col_lights,
],
bind_group_layouts: &[&global_layout.globals, &layout.locals],
});
let samples = match aa_mode {

View File

@ -95,15 +95,7 @@ impl FluidPipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Fluid pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.light,
&global_layout.shadow,
&global_layout.shadow_maps,
&global_layout.light_shadows,
&layout.waves,
],
bind_group_layouts: &[&global_layout.globals, &layout.waves],
});
let samples = match aa_mode {

View File

@ -159,11 +159,7 @@ impl LodTerrainPipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Lod terrain pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.lod_map,
],
bind_group_layouts: &[&global_layout.globals],
});
let samples = match aa_mode {

View File

@ -227,12 +227,6 @@ pub struct GlobalModel {
pub struct GlobalsLayouts {
pub globals: wgpu::BindGroupLayout,
pub light: wgpu::BindGroupLayout,
pub shadow: wgpu::BindGroupLayout,
pub alt_horizon: wgpu::BindGroupLayout,
pub shadow_maps: wgpu::BindGroupLayout,
pub light_shadows: wgpu::BindGroupLayout,
pub lod_map: wgpu::BindGroupLayout,
}
impl GlobalsLayouts {
@ -240,6 +234,7 @@ impl GlobalsLayouts {
let globals = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Globals layout"),
entries: &[
// Global uniform
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
@ -249,6 +244,7 @@ impl GlobalsLayouts {
},
count: None,
},
// Noise tex
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
@ -265,76 +261,29 @@ impl GlobalsLayouts {
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
],
});
let light = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Light layout"),
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
}],
});
let shadow = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Shadow layout"),
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
}],
});
let alt_horizon = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("alt/horizon layout"),
entries: &[
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 2,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
// Light uniform
wgpu::BindGroupLayoutEntry {
binding: 3,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
],
});
let shadow_maps = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Shadow maps layout"),
entries: &[
// Shadow uniform
wgpu::BindGroupLayoutEntry {
binding: 0,
binding: 4,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// Alt texture
wgpu::BindGroupLayoutEntry {
binding: 5,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
@ -344,19 +293,14 @@ impl GlobalsLayouts {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 6,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
],
});
let light_shadows = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Light shadows layout"),
entries: &[
// Horizon texture
wgpu::BindGroupLayoutEntry {
binding: 0,
binding: 7,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
@ -366,13 +310,14 @@ impl GlobalsLayouts {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 8,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
// light shadows
wgpu::BindGroupLayoutEntry {
binding: 2,
binding: 9,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
@ -382,19 +327,14 @@ impl GlobalsLayouts {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 3,
binding: 10,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
],
});
let lod_map = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("Lod layout"),
entries: &[
// point shadow_maps
wgpu::BindGroupLayoutEntry {
binding: 0,
binding: 11,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
@ -404,7 +344,41 @@ impl GlobalsLayouts {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 12,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
// directed shadow maps
wgpu::BindGroupLayoutEntry {
binding: 13,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 14,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
},
// lod map (t_map)
wgpu::BindGroupLayoutEntry {
binding: 15,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 16,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
@ -412,14 +386,6 @@ impl GlobalsLayouts {
],
});
Self {
globals,
light,
shadow,
alt_horizon,
shadow_maps,
light_shadows,
lod_map,
}
Self { globals }
}
}

View File

@ -179,14 +179,7 @@ impl ParticlePipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Particle pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.light,
&global_layout.shadow,
&global_layout.shadow_maps,
&global_layout.light_shadows,
],
bind_group_layouts: &[&global_layout.globals],
});
let samples = match aa_mode {

View File

@ -1,5 +1,6 @@
use super::super::{
AaMode, ColLightInfo, FigureLayout, GlobalsLayouts, Renderer, TerrainVertex, Texture,
AaMode, ColLightInfo, FigureLayout, GlobalsLayouts, Renderer, TerrainLayout, TerrainVertex,
Texture,
};
use vek::*;
use zerocopy::AsBytes;
@ -99,7 +100,8 @@ impl ShadowFigurePipeline {
fs_module: &wgpu::ShaderModule,
sc_desc: &wgpu::SwapChainDescriptor,
global_layout: &GlobalsLayouts,
layout: &FigureLayout,
figure_layout: &FigureLayout,
layout: &ShadowLayout,
aa_mode: AaMode,
) -> Self {
let render_pipeline_layout =
@ -108,8 +110,8 @@ impl ShadowFigurePipeline {
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.light_shadows,
&layout.waves,
&figure_layout.locals,
&layout.locals,
],
});
@ -180,6 +182,7 @@ impl ShadowPipeline {
fs_module: &wgpu::ShaderModule,
sc_desc: &wgpu::SwapChainDescriptor,
global_layout: &GlobalsLayouts,
terrain_layout: &TerrainLayout,
layout: &ShadowLayout,
aa_mode: AaMode,
) -> Self {
@ -189,7 +192,7 @@ impl ShadowPipeline {
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.light_shadows,
&terrain_layout.locals,
&layout.locals,
],
});

View File

@ -39,7 +39,7 @@ impl SkyboxPipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Skybox pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[&layouts.globals, &layouts.alt_horizon],
bind_group_layouts: &[&layouts.globals],
});
let samples = match aa_mode {

View File

@ -163,19 +163,28 @@ impl Locals {
pub struct SpriteLayout {
pub locals: wgpu::BindGroupLayout,
pub col_lights: wgpu::BindGroupLayout,
}
impl SpriteLayout {
pub fn new(device: &wgpu::Device) -> Self {
Self {
locals: Locals::layout(device),
col_lights: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
locals: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
// locals
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// col lights
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
@ -184,7 +193,7 @@ impl SpriteLayout {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 2,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
@ -216,14 +225,8 @@ impl SpritePipeline {
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.light,
&global_layout.shadow,
&global_layout.shadow_maps,
&global_layout.light_shadows,
&layout.col_lights,
&layout.locals,
&terrain_layout.locals,
&layout.locals,
],
});

View File

@ -144,38 +144,32 @@ impl Locals {
atlas_offs: [0; 4],
}
}
fn layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
}],
})
}
}
pub struct TerrainLayout {
pub locals: wgpu::BindGroupLayout,
pub col_lights: wgpu::BindGroupLayout,
}
impl TerrainLayout {
pub fn new(device: &wgpu::Device) -> Self {
Self {
locals: Locals::layout(device),
col_lights: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
locals: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
// locals
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// col lights
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
@ -184,7 +178,7 @@ impl TerrainLayout {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 2,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
@ -213,16 +207,7 @@ impl TerrainPipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("Terrain pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[
&global_layout.globals,
&global_layout.alt_horizon,
&global_layout.light,
&global_layout.shadow,
&global_layout.shadow_maps,
&global_layout.light_shadows,
&layout.locals,
&layout.col_lights,
],
bind_group_layouts: &[&global_layout.globals, &layout.locals],
});
let samples = match aa_mode {

View File

@ -29,23 +29,6 @@ pub struct Locals {
pos: [f32; 4],
}
impl Locals {
fn layout(device: &wgpu::Device) -> wgpu::BindGroupLayout {
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
}],
})
}
}
impl From<Vec4<f32>> for Locals {
fn from(pos: Vec4<f32>) -> Self {
Self {
@ -97,19 +80,28 @@ impl Mode {
pub struct UILayout {
pub locals: wgpu::BindGroupLayout,
pub tex: wgpu::BindGroupLayout,
}
impl UILayout {
pub fn new(device: &wgpu::Device) -> Self {
Self {
locals: Locals::layout(device),
tex: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
locals: device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None,
entries: &[
// locals
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::UniformBuffer {
dynamic: false,
min_binding_size: None,
},
count: None,
},
// texture
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::SampledTexture {
component_type: wgpu::TextureComponentType::Float,
dimension: wgpu::TextureViewDimension::D2,
@ -118,7 +110,7 @@ impl UILayout {
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
binding: 2,
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
ty: wgpu::BindingType::Sampler { comparison: false },
count: None,
@ -147,7 +139,7 @@ impl UIPipeline {
device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: Some("UI pipeline layout"),
push_constant_ranges: &[],
bind_group_layouts: &[&global_layout.globals, &layout.locals, &layout.tex],
bind_group_layouts: &[&global_layout.globals, &layout.locals],
});
let samples = match aa_mode {

View File

@ -1647,7 +1647,7 @@ impl Renderer {
// // NOTE: It would be nice if this wasn't needed and we could use
// a constant buffer // offset into the sprite data. Hopefully,
// when we switch to wgpu we can do this, // as it offers the
// exact API we want (the equivalent can be done in OpenGL using
// exact API we want (the equivalent can be done in OpenGL using
// // glBindBufferOffset). locals: locals.buf.clone(),
// globals: global.globals.buf.clone(),
// lights: global.lights.buf.clone(),
@ -1816,7 +1816,7 @@ impl Renderer {
// color_sampler: (self.tgt_color_res.clone(),
// self.sampler.clone()), depth_sampler:
// (self.tgt_depth_res.clone(), self.sampler.clone()), noise:
// (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
// (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
// tgt_color: self.tgt_color_pp_view.clone(), },
// )
// }
@ -1847,7 +1847,7 @@ impl Renderer {
// color_sampler: (self.tgt_color_res_pp.clone(),
// self.sampler.clone()), depth_sampler:
// (self.tgt_depth_res.clone(), self.sampler.clone()), noise:
// (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
// (self.noise_tex.srv.clone(), self.noise_tex.sampler.clone()),
// tgt_color: self.win_color_view.clone(), },
// )
// }