Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/wgpu/wgpu_image/wgpu_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn create_render_pipeline(
wgpu::RenderPipelineBuilder::from_layout(layout, vs_mod)
.fragment_shader(fs_mod)
.color_format(dst_format)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float2])
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x2])
.sample_count(sample_count)
.primitive_topology(wgpu::PrimitiveTopology::TriangleStrip)
.build(device)
Expand Down
4 changes: 2 additions & 2 deletions examples/wgpu/wgpu_image_sequence/wgpu_image_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn update(app: &App, model: &mut Model, update: Update) {
);

// Update which layer we are viewing based on the playback speed and layer count.
let layer_count = model.texture_array.extent().depth;
let layer_count = model.texture_array.extent().depth_or_array_layers;
model.current_layer = fmod(
model.current_layer + update.since_last.secs() as f32 * fps,
layer_count as f32,
Expand Down Expand Up @@ -250,7 +250,7 @@ fn create_render_pipeline(
wgpu::RenderPipelineBuilder::from_layout(layout, vs_mod)
.fragment_shader(fs_mod)
.color_format(dst_format)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float2])
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x2])
.sample_count(sample_count)
.primitive_topology(wgpu::PrimitiveTopology::TriangleStrip)
.build(device)
Expand Down
Binary file modified examples/wgpu/wgpu_instancing/shaders/frag.spv
Binary file not shown.
36 changes: 34 additions & 2 deletions examples/wgpu/wgpu_instancing/shaders/shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ layout(location = 0) in vec3 position;
layout(location = 1) in vec3 normal;
//locations 3,4,5, are implicitely taken by `instance_transform`
//since one location can contain at max vec4
layout(location = 2) in mat4 instance_transform;
// layout(location = 2) in mat4 instance_transform;
Comment thread
AlexEne marked this conversation as resolved.
Outdated
layout(location = 2) in vec4 model_matrix_0;
layout(location = 3) in vec4 model_matrix_1;
layout(location = 4) in vec4 model_matrix_2;
layout(location = 5) in vec4 model_matrix_3;
layout(location = 6) in vec3 instance_color;

layout(location = 0) out vec3 v_normal;
Expand All @@ -22,9 +26,37 @@ layout(set = 0, binding = 0) uniform Data {
mat4 proj;
} uniforms;

// Temporary manual inverse hack until this is solved
// https://github.com/gfx-rs/naga/issues/893
mat3x3 custom_inverse(mat3x3 m) {
float determinant = determinant(m);

float invdet = 1.0 / determinant;

mat3x3 minv;
minv[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * invdet;
minv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * invdet;
minv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invdet;
minv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) * invdet;
minv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invdet;
minv[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * invdet;
minv[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]) * invdet;
minv[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * invdet;
minv[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * invdet;

return minv;
}

void main() {
mat4 instance_transform = mat4(
model_matrix_0,
model_matrix_1,
model_matrix_2,
model_matrix_3
);

mat4 worldview = uniforms.view * uniforms.world * instance_transform;
v_normal = transpose(inverse(mat3(worldview))) * normal;
v_normal = transpose(custom_inverse(mat3(worldview))) * normal;
v_color = instance_color;
gl_Position = uniforms.proj * worldview * vec4(position, 1.0);
}
Binary file modified examples/wgpu/wgpu_instancing/shaders/vert.spv
Binary file not shown.
18 changes: 9 additions & 9 deletions examples/wgpu/wgpu_instancing/wgpu_instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,35 +428,35 @@ fn create_render_pipeline(
wgpu::RenderPipelineBuilder::from_layout(layout, vs_mod)
.fragment_shader(&fs_mod)
.color_format(dst_format)
.color_blend(wgpu::BlendState::REPLACE)
.alpha_blend(wgpu::BlendState::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float3])
.color_blend(wgpu::BlendComponent::REPLACE)
.alpha_blend(wgpu::BlendComponent::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float32x3])
// TODO: this can use the macro again when https://github.com/gfx-rs/wgpu/issues/836 is fixed
.add_instance_buffer::<Instance>(&[
wgpu::VertexAttribute {
shader_location: 2,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: std::mem::size_of::<[f32; 4]>() as u64 * 0,
},
wgpu::VertexAttribute {
shader_location: 3,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: std::mem::size_of::<[f32; 4]>() as u64 * 1,
},
wgpu::VertexAttribute {
shader_location: 4,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: std::mem::size_of::<[f32; 4]>() as u64 * 2,
},
wgpu::VertexAttribute {
shader_location: 5,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: std::mem::size_of::<[f32; 4]>() as u64 * 3,
},
wgpu::VertexAttribute {
shader_location: 6,
format: wgpu::VertexFormat::Float4,
format: wgpu::VertexFormat::Float32x4,
offset: std::mem::size_of::<[f32; 4]>() as u64 * 4,
},
])
Expand Down
23 changes: 22 additions & 1 deletion examples/wgpu/wgpu_teapot/shaders/shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@ layout(set = 0, binding = 0) uniform Data {
mat4 proj;
} uniforms;

// Temporary manual inverse hack until this is solved
// https://github.com/gfx-rs/naga/issues/893
mat3x3 custom_inverse(mat3x3 m) {
float determinant = determinant(m);

float invdet = 1.0 / determinant;

mat3x3 minv;
minv[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * invdet;
minv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * invdet;
minv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invdet;
minv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) * invdet;
minv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invdet;
minv[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * invdet;
minv[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]) * invdet;
minv[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * invdet;
minv[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * invdet;

return minv;
}

void main() {
mat4 worldview = uniforms.view * uniforms.world;
v_normal = transpose(inverse(mat3(worldview))) * normal;
v_normal = transpose(custom_inverse(mat3(worldview))) * normal;
gl_Position = uniforms.proj * worldview * vec4(position, 1.0);
}
Binary file modified examples/wgpu/wgpu_teapot/shaders/vert.spv
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/wgpu/wgpu_teapot/wgpu_teapot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ fn create_render_pipeline(
wgpu::RenderPipelineBuilder::from_layout(layout, vs_mod)
.fragment_shader(&fs_mod)
.color_format(dst_format)
.color_blend(wgpu::BlendState::REPLACE)
.alpha_blend(wgpu::BlendState::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float3])
.color_blend(wgpu::BlendComponent::REPLACE)
.alpha_blend(wgpu::BlendComponent::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float32x3])
.depth_format(depth_format)
.sample_count(sample_count)
.build(device)
Expand Down
23 changes: 22 additions & 1 deletion examples/wgpu/wgpu_teapot_camera/shaders/shader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,29 @@ layout(set = 0, binding = 0) uniform Data {
mat4 proj;
} uniforms;

// Temporary manual inverse hack until this is solved
// https://github.com/gfx-rs/naga/issues/893
mat3x3 custom_inverse(mat3x3 m) {
float determinant = determinant(m);

float invdet = 1.0 / determinant;

mat3x3 minv;
minv[0][0] = (m[1][1] * m[2][2] - m[2][1] * m[1][2]) * invdet;
minv[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) * invdet;
minv[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) * invdet;
minv[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) * invdet;
minv[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) * invdet;
minv[1][2] = (m[1][0] * m[0][2] - m[0][0] * m[1][2]) * invdet;
minv[2][0] = (m[1][0] * m[2][1] - m[2][0] * m[1][1]) * invdet;
minv[2][1] = (m[2][0] * m[0][1] - m[0][0] * m[2][1]) * invdet;
minv[2][2] = (m[0][0] * m[1][1] - m[1][0] * m[0][1]) * invdet;

return minv;
}

void main() {
mat4 worldview = uniforms.view * uniforms.world;
v_normal = transpose(inverse(mat3(worldview))) * normal;
v_normal = transpose(custom_inverse(mat3(worldview))) * normal;
gl_Position = uniforms.proj * worldview * vec4(position, 1.0);
}
Binary file modified examples/wgpu/wgpu_teapot_camera/shaders/vert.spv
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/wgpu/wgpu_teapot_camera/wgpu_teapot_camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,10 @@ fn create_render_pipeline(
wgpu::RenderPipelineBuilder::from_layout(layout, vs_mod)
.fragment_shader(&fs_mod)
.color_format(dst_format)
.color_blend(wgpu::BlendState::REPLACE)
.alpha_blend(wgpu::BlendState::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float3])
.color_blend(wgpu::BlendComponent::REPLACE)
.alpha_blend(wgpu::BlendComponent::REPLACE)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x3])
.add_vertex_buffer::<Normal>(&wgpu::vertex_attr_array![1 => Float32x3])
.depth_format(depth_format)
.sample_count(sample_count)
.build(device)
Expand Down
2 changes: 1 addition & 1 deletion examples/wgpu/wgpu_triangle/wgpu_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn model(app: &App) -> Model {
let render_pipeline = wgpu::RenderPipelineBuilder::from_layout(&pipeline_layout, &vs_mod)
.fragment_shader(&fs_mod)
.color_format(format)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float2])
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x2])
.sample_count(sample_count)
.build(device);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn model(app: &App) -> Model {
let render_pipeline = wgpu::RenderPipelineBuilder::from_layout(&pipeline_layout, &vs_mod)
.fragment_shader(&fs_mod)
.color_format(format)
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float2])
.add_vertex_buffer::<Vertex>(&wgpu::vertex_attr_array![0 => Float32x2])
.build(device);

Model {
Expand Down
10 changes: 8 additions & 2 deletions guide/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@ back to the origins.

# Unreleased

*No unreleased changes as of yet.

**Upgrade WGPU to 0.8**

Most changes have been about renaming Blend-related data structres and fixing shaders to avoid sampling textures inside of conditionals (wgpu validation layer found this one).
- Item Name changes:
- `BlendState` -> `BlendComponent`
- `wgpu::Extend3d::depth` -> `wgpu::Extend3d::depth_of_array_layers`
- Float tpes are now typed more descripively. E.g., `Float2` -> `Float32x2`

---

# Version 0.16.0 (2021-04-21)
Expand Down
4 changes: 4 additions & 0 deletions guide/src/contributing/pr-checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ landing your changes go smoothly:
last commit. Keep in mind that sometimes warnings already exist due to changes
in the compiler's linter between versions. Try to at least make sure that your
changes do not add any new ones :)
- **Check Examples** - Make sure the examples still work by running
`cargo run --bin run_all_examples`. This executes a script that builds and runs
all the examples in the project. You need to do a manual check to see
if examples have failed to run successfully (e.g. check for wgpu validation errors).
- **Documentation** - If you have made any changes that could benefit from
updating some code documentation, please be sure to do so! Try to put yourself
in the shoes of someone reading your code for the first time.
Expand Down
8 changes: 5 additions & 3 deletions nannou/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ default = ["notosans"]

[dependencies]
cgmath = { version = "0.17", features = ["serde"] }
conrod_core = "0.72"
conrod_wgpu = "0.72"
#conrod_core = "0.72"
# conrod_wgpu = "0.72"
conrod_core = {git = "https://github.com/AlexEne/conrod"}
Comment thread
AlexEne marked this conversation as resolved.
Outdated
conrod_wgpu = {git = "https://github.com/AlexEne/conrod"}
conrod_winit = "0.72"
daggy = "0.6"
find_folder = "0.3"
Expand All @@ -36,5 +38,5 @@ serde_derive = "1"
serde_json = "1"
toml = "0.5"
walkdir = "2"
wgpu_upstream = { version = "0.7.1", package = "wgpu" }
wgpu_upstream = { version = "0.8", package = "wgpu" }
winit = "0.24"
19 changes: 10 additions & 9 deletions nannou/src/draw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ where
#[derive(Clone, Debug, PartialEq)]
pub struct Context<S = geom::scalar::Default> {
pub transform: Matrix4<S>,
pub alpha_blend: wgpu::BlendState,
pub color_blend: wgpu::BlendState,
pub blend: wgpu::BlendState,
pub scissor: Scissor<S>,
// TODO: Consider changing `PolygonMode` (added as of wgpu 0.7) rather than `PrimitiveTopology`
// here.
Expand Down Expand Up @@ -403,21 +402,21 @@ where
}

/// Produce a new **Draw** instance that will draw with the given alpha blend descriptor.
pub fn alpha_blend(&self, blend_descriptor: wgpu::BlendState) -> Self {
pub fn alpha_blend(&self, blend_descriptor: wgpu::BlendComponent) -> Self {
let mut context = self.context.clone();
context.alpha_blend = blend_descriptor;
context.blend.alpha = blend_descriptor;
self.context(context)
}

/// Produce a new **Draw** instance that will draw with the given color blend descriptor.
pub fn color_blend(&self, blend_descriptor: wgpu::BlendState) -> Self {
pub fn color_blend(&self, blend_descriptor: wgpu::BlendComponent) -> Self {
let mut context = self.context.clone();
context.color_blend = blend_descriptor;
context.blend.color = blend_descriptor;
self.context(context)
}

/// Short-hand for `color_blend`, the common use-case.
pub fn blend(&self, blend_descriptor: wgpu::BlendState) -> Self {
pub fn blend(&self, blend_descriptor: wgpu::BlendComponent) -> Self {
self.color_blend(blend_descriptor)
}

Expand Down Expand Up @@ -672,8 +671,10 @@ where
fn default() -> Self {
Self {
transform: Matrix4::identity(),
alpha_blend: wgpu::RenderPipelineBuilder::DEFAULT_ALPHA_BLEND,
color_blend: wgpu::RenderPipelineBuilder::DEFAULT_COLOR_BLEND,
blend: wgpu::BlendState {
color: wgpu::RenderPipelineBuilder::DEFAULT_COLOR_BLEND,
alpha: wgpu::RenderPipelineBuilder::DEFAULT_ALPHA_BLEND,
},
scissor: Scissor::Full,
topology: wgpu::RenderPipelineBuilder::DEFAULT_PRIMITIVE_TOPOLOGY,
sampler: wgpu::SamplerBuilder::new().into_descriptor(),
Expand Down
24 changes: 13 additions & 11 deletions nannou/src/draw/renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,8 @@ impl Renderer {
// Determine the new current bind group layout ID, pipeline ID, bind group ID
// and scissor required for drawing this primitive.
let new_pipeline_id = {
let color_id = blend_state_hash(&curr_ctxt.color_blend);
let alpha_id = blend_state_hash(&curr_ctxt.alpha_blend);
let color_id = blend_component_hash(&curr_ctxt.blend.color);
let alpha_id = blend_component_hash(&curr_ctxt.blend.alpha);
let topology = curr_ctxt.topology;
PipelineId {
color_id,
Expand Down Expand Up @@ -645,8 +645,8 @@ impl Renderer {
// If necessary, push a new pipeline command.
if pipeline_changed {
curr_pipeline_id = Some(new_pipeline_id);
let color_blend = curr_ctxt.color_blend.clone();
let alpha_blend = curr_ctxt.alpha_blend.clone();
let color_blend = curr_ctxt.blend.color.clone();
let alpha_blend = curr_ctxt.blend.alpha.clone();
let sampler_filtering = wgpu::sampler_filtering(&curr_ctxt.sampler);
new_pipeline_ids.insert(
new_pipeline_id,
Expand Down Expand Up @@ -1117,18 +1117,20 @@ fn create_render_pipeline(
dst_format: wgpu::TextureFormat,
depth_format: wgpu::TextureFormat,
sample_count: u32,
color_blend: wgpu::BlendState,
alpha_blend: wgpu::BlendState,
color_blend: wgpu::BlendComponent,
alpha_blend: wgpu::BlendComponent,
topology: wgpu::PrimitiveTopology,
) -> wgpu::RenderPipeline {
let bind_group_layouts = &[uniform_layout, text_layout, texture_layout];
wgpu::RenderPipelineBuilder::from_layout_descriptor(&bind_group_layouts[..], vs_mod)
.fragment_shader(fs_mod)
.color_format(dst_format)
.add_vertex_buffer::<draw::mesh::vertex::Point>(&wgpu::vertex_attr_array![0 => Float3])
.add_vertex_buffer::<draw::mesh::vertex::Color>(&wgpu::vertex_attr_array![1 => Float4])
.add_vertex_buffer::<draw::mesh::vertex::TexCoords>(&wgpu::vertex_attr_array![2 => Float2])
.add_vertex_buffer::<VertexMode>(&wgpu::vertex_attr_array![3 => Uint])
.add_vertex_buffer::<draw::mesh::vertex::Point>(&wgpu::vertex_attr_array![0 => Float32x3])
.add_vertex_buffer::<draw::mesh::vertex::Color>(&wgpu::vertex_attr_array![1 => Float32x4])
.add_vertex_buffer::<draw::mesh::vertex::TexCoords>(
&wgpu::vertex_attr_array![2 => Float32x2],
)
.add_vertex_buffer::<VertexMode>(&wgpu::vertex_attr_array![3 => Uint32])
.depth_format(depth_format)
.sample_count(sample_count)
.color_blend(color_blend)
Expand All @@ -1153,7 +1155,7 @@ fn sampler_descriptor_hash(desc: &wgpu::SamplerDescriptor) -> SamplerId {
s.finish()
}

fn blend_state_hash(desc: &wgpu::BlendState) -> BlendId {
fn blend_component_hash(desc: &wgpu::BlendComponent) -> BlendId {
let mut s = std::collections::hash_map::DefaultHasher::new();
desc.src_factor.hash(&mut s);
desc.dst_factor.hash(&mut s);
Expand Down
Binary file modified nannou/src/draw/renderer/shaders/frag.spv
Binary file not shown.
Loading