Skip to content

Commit efd7e99

Browse files
committed
WGSL port complete
"History has to be observed. Otherwise it’s not history. It’s just … well, things happening one after another" I don't really know what happened here, let's just call this things happened, and let's start recording history again.
1 parent 945728e commit efd7e99

File tree

27 files changed

+873
-358
lines changed

27 files changed

+873
-358
lines changed

Cargo.lock

Lines changed: 147 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ members = [
66
"game-client",
77
"atlas",
88
"server",
9-
"mostly-harmless",
109
]
1110

1211
[profile.release]

atlas/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ bytemuck = "1.4"
1414
tracing = "0.1"
1515
bitflags = "1.3"
1616
static_assertions = "1.1.0"
17-
18-
[dependencies.wgpu]
19-
version = "0.14"
20-
features = ["spirv"]

atlas/src/rendering/init/camera.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::*;
21
use crate::rendering::uniforms::CameraUniforms;
32
use pantheon::prelude::*;
3+
use pantheon::wgpu;
44

55
const CAMERA_UNIFORM_BUFFER_SIZE: wgpu::BufferAddress =
66
std::mem::size_of::<CameraUniforms>() as u64;

atlas/src/rendering/init/lights.rs

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::entity::light::infinite::{CASCADE_COUNT, MAP_SIZE};
22

3-
use super::{prelude::*, DEPTH_CLEAR, SHADED};
3+
use super::SHADED_WGSL;
4+
use super::{prelude::*, DEPTH_CLEAR, SHADED, VS_BAKE};
45
use pantheon::graphics::prelude::*;
56
use pantheon::prelude::*;
7+
use pantheon::wgpu;
8+
use pantheon::wgpu::util::DeviceExt;
69
use pantheon::wrangler::PASS_PADDING;
7-
use wgpu::util::DeviceExt;
810

911
/*
1012
const LIGHT_UNIFORM_BUFFER_SIZE: wgpu::BufferAddress = (16 + 3 + 1 + 4) * 4;
@@ -30,7 +32,6 @@ const GLOBAL_LIGHT_SHADOW_SIZE: wgpu::Extent3d = wgpu::Extent3d {
3032

3133
pub const GLOBAL_LIGHT: &'static str = "global_light";
3234
pub const GLOBAL_LIGHT_SHADOW: &'static str = "global_light_shadow";
33-
pub const GLOBAL_LIGHT_SHADOW_COLOR: &'static str = "global_light_shadow_color";
3435
pub const GLOBAL_LIGHT_BAKE_SHADOW: &'static str = "global_light_shadow";
3536
pub const GLOBAL_LIGHT_SHADOW_FMT: &'static str = "global_light_shadow_{}";
3637
pub const GLOBAL_LIGHT_SHADOW_0: &'static str = "global_light_shadow_0";
@@ -80,15 +81,15 @@ pub fn init_global_light(ctx: &mut Context, global_light_uniforms: GlobalLightUn
8081
visibility: wgpu::ShaderStages::FRAGMENT,
8182
ty: wgpu::BindingType::Texture {
8283
multisampled: false,
83-
sample_type: wgpu::TextureSampleType::Float { filterable: true },
84+
sample_type: wgpu::TextureSampleType::Float { filterable: false },
8485
view_dimension: wgpu::TextureViewDimension::D2,
8586
},
8687
count: None,
8788
},
8889
wgpu::BindGroupLayoutEntry {
8990
binding: 3,
9091
visibility: wgpu::ShaderStages::FRAGMENT,
91-
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
92+
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison),
9293
count: None,
9394
},
9495
],
@@ -117,7 +118,6 @@ pub fn init_global_light(ctx: &mut Context, global_light_uniforms: GlobalLightUn
117118
base_array_layer: 0 as u32,
118119
array_layer_count: std::num::NonZeroU32::new(1),
119120
},
120-
Some(wgpu::CompareFunction::GreaterEqual),
121121
GLOBAL_LIGHT_SHADOW,
122122
);
123123
let shadow_uniform_buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
@@ -173,6 +173,8 @@ pub fn init_global_light(ctx: &mut Context, global_light_uniforms: GlobalLightUn
173173
}],
174174
label: Some(GLOBAL_LIGHT_SHADOW),
175175
});
176+
/*
177+
* bad vibes
176178
let texture = Texture::create_surface_texture_size(
177179
&ctx.device,
178180
(
@@ -182,6 +184,7 @@ pub fn init_global_light(ctx: &mut Context, global_light_uniforms: GlobalLightUn
182184
GLOBAL_LIGHT_SHADOW_COLOR,
183185
);
184186
ctx.wrangler.add_texture(texture, GLOBAL_LIGHT_SHADOW_COLOR);
187+
*/
185188

186189
for i in 0..CASCADE_COUNT {
187190
let s = int_to_cascade(i);
@@ -233,22 +236,9 @@ pub fn init_global_bake_shadow_pass<'a>(ctx: &mut Context<'a>) {
233236

234237
let pass_bind_group_handle = Some(bind_group);
235238

236-
let color_attachment_ops = if i == 0 {
237-
Some(wgpu::Operations {
238-
load: wgpu::LoadOp::Clear(ctx.gfx_context.clear_color),
239-
store: true,
240-
})
241-
} else {
242-
Some(wgpu::Operations {
243-
load: wgpu::LoadOp::Load,
244-
store: true,
245-
})
246-
};
247-
let color_attachment_view_handle = Some(
248-
ctx.wrangler
249-
.handle_to_texture(GLOBAL_LIGHT_SHADOW_COLOR)
250-
.unwrap(),
251-
);
239+
// Bad vibes
240+
let color_attachment_ops = None;
241+
let color_attachment_view_handle = None;
252242

253243
let depth_ops = if i == 0 {
254244
Some(wgpu::Operations {
@@ -300,8 +290,10 @@ pub fn init_global_bake_shadow_pass<'a>(ctx: &mut Context<'a>) {
300290
frame_bind_group_layout_handle_override,
301291

302292
push_constant_ranges,
303-
vs_path: Some("bake_shadow.vert.spv"),
304-
fs_path: Some("basic.frag.spv"),
293+
vs_module_name: Some(SHADED_WGSL),
294+
vs_entry_point: Some(VS_BAKE),
295+
fs_module_name: None,
296+
fs_entry_point: None,
305297
vert_desc: crate::vertex::ShadedVertex::desc,
306298
label: Some(pass_label),
307299
fragment_targets: Some(vec![ColorTarget {

atlas/src/rendering/init/mod.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use self::prelude::GlobalLightUniforms;
99
pub use super::*;
1010
pub use camera::*;
1111
pub use lights::*;
12+
use pantheon::context::Context;
1213
use pantheon::wrangler::PASS_PADDING;
1314
pub use shaded::*;
1415
pub use texture::*;
@@ -25,6 +26,25 @@ pub const UNIFORM_BUFFER_VERTEX: &'static str = "uniform_buffer_vertex";
2526
pub const UNIFORM_BUFFER_FRAGMENT: &'static str = "uniform_buffer_fragment";
2627
pub const UNIFORM_BUFFER_VERTEX_FRAGMENT: &'static str = "uniform_buffer_vertex_fragment";
2728

29+
pub const BASIC_WGSL: &'static str = "basic.wgsl";
30+
pub const BASIC_TEXTURED_WGSL: &'static str = "basic_textured.wgsl";
31+
pub const SHADED_WGSL: &'static str = "shaded.wgsl";
32+
pub const WATER_WGSL: &'static str = "water.wgsl";
33+
34+
pub const VS_MAIN: &'static str = "vs_main";
35+
pub const FS_MAIN: &'static str = "fs_main";
36+
pub const VS_BAKE: &'static str = "vs_bake";
37+
38+
pub const DEPTH: &'static str = "depth";
39+
40+
fn init_shaders(ctx: &mut Context) {
41+
ctx.shader_context.register_module(&ctx.device, BASIC_WGSL);
42+
ctx.shader_context
43+
.register_module(&ctx.device, BASIC_TEXTURED_WGSL);
44+
ctx.shader_context.register_module(&ctx.device, SHADED_WGSL);
45+
ctx.shader_context.register_module(&ctx.device, WATER_WGSL);
46+
}
47+
2848
pub fn init_shared(ctx: &mut Context) {
2949
let padding_bgl = ctx
3050
.device
@@ -105,9 +125,9 @@ pub fn init_shared(ctx: &mut Context) {
105125
}
106126

107127
pub fn init_entity_resources(ctx: &mut Context) {
108-
let depth_texture = Texture::create_depth_texture(&ctx.device, &ctx.surface_config, "depth");
128+
let depth_texture = Texture::create_depth_texture(&ctx.device, &ctx.surface_config, DEPTH);
109129

110-
let _depth_texture_handle = ctx.wrangler.add_texture(depth_texture, "depth");
130+
let _depth_texture_handle = ctx.wrangler.add_texture(depth_texture, DEPTH);
111131
}
112132

113133
fn init_vert_index_buffers<'a>(ctx: &mut Context<'a>, label: &'a str) {
@@ -136,6 +156,7 @@ pub struct InitParams {
136156
}
137157

138158
pub fn init<'a>(ctx: &mut Context<'a>, params: InitParams) {
159+
init::init_shaders(ctx);
139160
init::init_shared(ctx);
140161
init::init_global_light(ctx, params.global_light_uniforms);
141162
init::init_camera_resources(ctx);

atlas/src/rendering/init/shaded.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use crate::vertex;
33
use pantheon::graphics::prelude::*;
44
use pantheon::math::prelude::*;
55
use pantheon::prelude::*;
6-
use wgpu::util::DeviceExt;
6+
use pantheon::wgpu;
7+
use pantheon::wgpu::util::DeviceExt;
78

89
pub const SHADED: &'static str = "shaded";
910

@@ -65,7 +66,7 @@ pub fn init_shaded_resources<'a>(
6566
},
6667
wgpu::BindGroupLayoutEntry {
6768
binding: 1,
68-
visibility: wgpu::ShaderStages::VERTEX,
69+
visibility: wgpu::ShaderStages::FRAGMENT,
6970
ty: wgpu::BindingType::Buffer {
7071
ty: wgpu::BufferBindingType::Uniform,
7172
has_dynamic_offset: false,
@@ -152,11 +153,11 @@ pub fn init_shaded_resources<'a>(
152153

153154
pub fn init_shaded_pass<'a>(ctx: &'a mut Context) -> PassHandle<'a> {
154155
let pass_label = "shaded";
155-
let depth_texture_handle = match ctx.wrangler.handle_to_texture("depth") {
156+
let depth_texture_handle = match ctx.wrangler.handle_to_texture(DEPTH) {
156157
Some(handle) => handle,
157158
None => {
158159
init_entity_resources(ctx);
159-
ctx.wrangler.handle_to_texture("depth").unwrap()
160+
ctx.wrangler.handle_to_texture(DEPTH).unwrap()
160161
}
161162
};
162163

@@ -189,8 +190,10 @@ pub fn init_shaded_pass<'a>(ctx: &'a mut Context) -> PassHandle<'a> {
189190
draw_call_bind_group_layout_handle: None,
190191
frame_bind_group_layout_handle_override: None,
191192
push_constant_ranges,
192-
vs_path: Some("shaded.vert.spv"),
193-
fs_path: Some("shaded.frag.spv"),
193+
vs_module_name: Some(SHADED_WGSL),
194+
vs_entry_point: Some(VS_MAIN),
195+
fs_module_name: Some(SHADED_WGSL),
196+
fs_entry_point: Some(FS_MAIN),
194197
vert_desc: vertex::ShadedVertex::desc,
195198
label: Some(pass_label),
196199
fragment_targets: Some(vec![ColorTarget {

atlas/src/rendering/init/texture.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
use super::*;
22
use pantheon::graphics::prelude::*;
33
use pantheon::prelude::*;
4+
use pantheon::wgpu;
5+
6+
pub const BASIC_TEXTURED: &str = "basic_textured";
7+
pub const DEPTH: &str = "depth";
48

59
/// @NOTE @DEBUG are you trying to reverse engineer how the textures are sampled because the
610
/// texture you are trying to sample is outputting garbage? Have you remembered to recreate the
@@ -41,7 +45,7 @@ pub fn init_textured_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
4145
visibility: wgpu::ShaderStages::FRAGMENT,
4246
ty: wgpu::BindingType::Texture {
4347
multisampled: false,
44-
sample_type: wgpu::TextureSampleType::Float { filterable: true },
48+
sample_type: wgpu::TextureSampleType::Depth,
4549
view_dimension: wgpu::TextureViewDimension::D2,
4650
},
4751
count: None,
@@ -70,21 +74,21 @@ pub fn init_textured_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
7074
);
7175
init_bind_group_for_textured_pass(
7276
ctx,
73-
&basic_textured_bind_group_layout,
74-
"refraction_depth",
75-
Some(&Texture::surface_texture_sampler(&ctx.device)),
77+
&depth_texture_bind_group_layout,
78+
REFRACTION_DEPTH,
79+
None,
7680
);
7781

7882
let _basic_texured_bgl_handle = ctx
7983
.wrangler
80-
.add_bind_group_layout(basic_textured_bind_group_layout, label);
84+
.add_bind_group_layout(basic_textured_bind_group_layout, BASIC_TEXTURED);
8185
let _handle = ctx
8286
.wrangler
83-
.add_bind_group_layout(depth_texture_bind_group_layout, "depth_sampler");
87+
.add_bind_group_layout(depth_texture_bind_group_layout, DEPTH);
8488
}
8589

8690
pub fn init_basic_textured_pass<'a>(ctx: &'a mut Context) {
87-
let pass_label = "basic_textured";
91+
let pass_label = BASIC_TEXTURED;
8892
init_textured_resources(ctx, pass_label);
8993
let bglh_basic_textured = ctx
9094
.wrangler
@@ -99,8 +103,10 @@ pub fn init_basic_textured_pass<'a>(ctx: &'a mut Context) {
99103
draw_call_bind_group_layout_handle: Some(bglh_basic_textured),
100104
push_constant_ranges,
101105
frame_bind_group_layout_handle_override: None,
102-
vs_path: Some("basic_textured.vert.spv"),
103-
fs_path: Some("basic_textured.frag.spv"),
106+
vs_module_name: Some(BASIC_TEXTURED_WGSL),
107+
vs_entry_point: Some(VS_MAIN),
108+
fs_module_name: Some(BASIC_TEXTURED_WGSL),
109+
fs_entry_point: Some(FS_MAIN),
104110
vert_desc: crate::vertex::BasicTexturedVertex::desc,
105111
label: Some(pass_label),
106112
fragment_targets: Some(vec![ColorTarget {

atlas/src/rendering/init/water.rs

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use super::*;
22
use crate::vertex;
33
use pantheon::graphics::prelude::*;
44
use pantheon::prelude::*;
5+
use pantheon::wgpu;
56

67
pub const WATER: &'static str = "water";
78
pub const REFRACTION_DEPTH: &'static str = "refraction_depth";
@@ -57,8 +58,10 @@ pub fn init_refraction_pass<'a>(ctx: &'a mut Context) {
5758
draw_call_bind_group_layout_handle: None,
5859

5960
push_constant_ranges,
60-
vs_path: Some("shaded.vert.spv"),
61-
fs_path: Some("shaded.frag.spv"),
61+
vs_module_name: Some(SHADED_WGSL),
62+
vs_entry_point: Some(VS_MAIN),
63+
fs_module_name: Some(SHADED_WGSL),
64+
fs_entry_point: Some(FS_MAIN),
6265
frame_bind_group_layout_handle_override: None,
6366
vert_desc: crate::vertex::ShadedVertex::desc,
6467
label: Some(pass_label),
@@ -130,11 +133,11 @@ pub fn init_reflection_resources<'a>(ctx: &mut Context<'a>) {
130133
pub fn init_reflection_pass<'a>(ctx: &'a mut Context) {
131134
let pass_label = "reflection";
132135
let shaded_label = "shaded";
133-
let depth_texture_handle = match ctx.wrangler.handle_to_texture("depth") {
136+
let depth_texture_handle = match ctx.wrangler.handle_to_texture(DEPTH) {
134137
Some(handle) => handle,
135138
None => {
136139
init_entity_resources(ctx);
137-
ctx.wrangler.handle_to_texture("depth").unwrap()
140+
ctx.wrangler.handle_to_texture(DEPTH).unwrap()
138141
}
139142
};
140143

@@ -172,8 +175,10 @@ pub fn init_reflection_pass<'a>(ctx: &'a mut Context) {
172175
draw_call_bind_group_layout_handle: None,
173176

174177
push_constant_ranges,
175-
vs_path: Some("shaded.vert.spv"),
176-
fs_path: Some("shaded.frag.spv"),
178+
vs_module_name: Some(SHADED_WGSL),
179+
vs_entry_point: Some(VS_MAIN),
180+
fs_module_name: Some(SHADED_WGSL),
181+
fs_entry_point: Some(FS_MAIN),
177182
frame_bind_group_layout_handle_override: None,
178183
vert_desc: vertex::ShadedVertex::desc,
179184
label: Some(pass_label),
@@ -275,7 +280,7 @@ pub fn init_water_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
275280
visibility: wgpu::ShaderStages::FRAGMENT,
276281
ty: wgpu::BindingType::Texture {
277282
multisampled: false,
278-
sample_type: wgpu::TextureSampleType::Float { filterable: true },
283+
sample_type: wgpu::TextureSampleType::Float { filterable: false },
279284
view_dimension: wgpu::TextureViewDimension::D2,
280285
},
281286
count: None,
@@ -286,6 +291,12 @@ pub fn init_water_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
286291
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
287292
count: None,
288293
},
294+
wgpu::BindGroupLayoutEntry {
295+
binding: 5,
296+
visibility: wgpu::ShaderStages::FRAGMENT,
297+
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Comparison),
298+
count: None,
299+
},
289300
],
290301
label: Some(WATER),
291302
});
@@ -320,6 +331,10 @@ pub fn init_water_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
320331
&ctx.device,
321332
)),
322333
},
334+
wgpu::BindGroupEntry {
335+
binding: 5,
336+
resource: wgpu::BindingResource::Sampler(&refraction_depth.sampler),
337+
},
323338
],
324339
label: Some(WATER),
325340
});
@@ -334,11 +349,11 @@ pub fn init_water_resources<'a>(ctx: &mut Context<'a>, label: &'a str) {
334349

335350
pub fn init_water_pass<'a>(ctx: &mut Context<'a>) -> PassHandle<'a> {
336351
let pass_label = "water";
337-
let depth_texture_handle = match ctx.wrangler.handle_to_texture("depth") {
352+
let depth_texture_handle = match ctx.wrangler.handle_to_texture(DEPTH) {
338353
Some(handle) => handle,
339354
None => {
340355
init_entity_resources(ctx);
341-
ctx.wrangler.handle_to_texture("depth").unwrap()
356+
ctx.wrangler.handle_to_texture(DEPTH).unwrap()
342357
}
343358
};
344359

@@ -376,8 +391,10 @@ pub fn init_water_pass<'a>(ctx: &mut Context<'a>) -> PassHandle<'a> {
376391
draw_call_bind_group_layout_handle: Some(static_entity_bind_group_layout_handle),
377392
push_constant_ranges,
378393
frame_bind_group_layout_handle_override: None,
379-
vs_path: Some("water.vert.spv"),
380-
fs_path: Some("water.frag.spv"),
394+
vs_module_name: Some(WATER_WGSL),
395+
vs_entry_point: Some(VS_MAIN),
396+
fs_module_name: Some(WATER_WGSL),
397+
fs_entry_point: Some(FS_MAIN),
381398
vert_desc: crate::vertex::WaterVertex::desc,
382399
label: Some(pass_label),
383400
fragment_targets: Some(vec![ColorTarget {

0 commit comments

Comments
 (0)