mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Merge #559
559: Update wgpu with the polygon modes support, use in the cube example r=cwfitzgerald a=kvark Uses https://github.com/gfx-rs/wgpu/pull/921, cc @manuel-woelker Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
This commit is contained in:
@@ -26,14 +26,14 @@ vulkan-portability = ["wgc/gfx-backend-vulkan"]
|
||||
package = "wgpu-core"
|
||||
#version = "0.6"
|
||||
git = "https://github.com/gfx-rs/wgpu"
|
||||
rev = "68bf10a3a5c439728825d4f3bd2d2ec075421edc"
|
||||
rev = "f6f7210b6323e643ff0000f3a4b25b2bb911e848"
|
||||
features = ["raw-window-handle"]
|
||||
|
||||
[dependencies.wgt]
|
||||
package = "wgpu-types"
|
||||
#version = "0.6"
|
||||
git = "https://github.com/gfx-rs/wgpu"
|
||||
rev = "68bf10a3a5c439728825d4f3bd2d2ec075421edc"
|
||||
rev = "f6f7210b6323e643ff0000f3a4b25b2bb911e848"
|
||||
|
||||
[dependencies]
|
||||
arrayvec = "0.5"
|
||||
|
||||
@@ -16,7 +16,7 @@ All framework-based examples render to the window.
|
||||
| instancing | :star: | | | | | | | |
|
||||
| lines and points | | | | :star: | | | | |
|
||||
| dynamic buffer offsets | | | | | :star: | | | |
|
||||
| implicit layout | | | | | | | | |
|
||||
| implicit layout | | | :star: | | | | | |
|
||||
| sampled color textures | :star: | :star: | :star: | | | :star: | :star: | :star: |
|
||||
| storage textures | :star: | | | | | | | |
|
||||
| binding array | | | | | | | :star: | |
|
||||
@@ -29,7 +29,7 @@ All framework-based examples render to the window.
|
||||
| depth testing | | | | | :star: | | | :star: |
|
||||
| depth biasing | | | | | :star: | | | |
|
||||
| read-only depth | | | | | | | | :star: |
|
||||
| blending | | | | | | | | :star: |
|
||||
| blending | | :star: | | | | | | :star: |
|
||||
| render bundles | | | | :star: | | | | :star: |
|
||||
| compute passes | :star: | | | | | | | |
|
||||
| optional extensions | | | | | | | :star: | |
|
||||
@@ -37,6 +37,7 @@ All framework-based examples render to the window.
|
||||
| - push constants | | | | | | | :star: | |
|
||||
| - depth clamping | | | | | :star: | | | |
|
||||
| - BCn compressed textures | | | | | | :star: | | |
|
||||
| - polygon mode | | :star: | | | | | | |
|
||||
| WGSL shaders | | | | | | | | |
|
||||
|
||||
## Hacking
|
||||
|
||||
@@ -94,6 +94,7 @@ struct Example {
|
||||
bind_group: wgpu::BindGroup,
|
||||
uniform_buf: wgpu::Buffer,
|
||||
pipeline: wgpu::RenderPipeline,
|
||||
pipeline_wire: Option<wgpu::RenderPipeline>,
|
||||
}
|
||||
|
||||
impl Example {
|
||||
@@ -110,6 +111,10 @@ impl Example {
|
||||
}
|
||||
|
||||
impl framework::Example for Example {
|
||||
fn optional_features() -> wgt::Features {
|
||||
wgt::Features::NON_FILL_POLYGON_MODE
|
||||
}
|
||||
|
||||
fn init(
|
||||
sc_desc: &wgpu::SwapChainDescriptor,
|
||||
device: &wgpu::Device,
|
||||
@@ -242,6 +247,26 @@ impl framework::Example for Example {
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
let vertex_state = wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: &[
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
format: wgpu::VertexFormat::Float4,
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
},
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
format: wgpu::VertexFormat::Float2,
|
||||
offset: 4 * 4,
|
||||
shader_location: 1,
|
||||
},
|
||||
],
|
||||
}],
|
||||
};
|
||||
|
||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("shader.vert.spv"));
|
||||
let fs_module = device.create_shader_module(wgpu::include_spirv!("shader.frag.spv"));
|
||||
|
||||
@@ -269,30 +294,56 @@ impl framework::Example for Example {
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: None,
|
||||
vertex_state: wgpu::VertexStateDescriptor {
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: &[
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
format: wgpu::VertexFormat::Float4,
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
},
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
format: wgpu::VertexFormat::Float2,
|
||||
offset: 4 * 4,
|
||||
shader_location: 1,
|
||||
},
|
||||
],
|
||||
}],
|
||||
},
|
||||
vertex_state: vertex_state.clone(),
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
});
|
||||
|
||||
let pipeline_wire = if device
|
||||
.features()
|
||||
.contains(wgt::Features::NON_FILL_POLYGON_MODE)
|
||||
{
|
||||
let fs_wire_module = device.create_shader_module(wgpu::include_spirv!("wire.frag.spv"));
|
||||
let pipeline_wire = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: None,
|
||||
layout: Some(&pipeline_layout),
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: Some(wgpu::ProgrammableStageDescriptor {
|
||||
module: &fs_wire_module,
|
||||
entry_point: "main",
|
||||
}),
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
polygon_mode: wgpu::PolygonMode::Line,
|
||||
..Default::default()
|
||||
}),
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
color_blend: wgpu::BlendDescriptor {
|
||||
operation: wgpu::BlendOperation::Add,
|
||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||
},
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: None,
|
||||
vertex_state,
|
||||
sample_count: 1,
|
||||
sample_mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
});
|
||||
Some(pipeline_wire)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Done
|
||||
Example {
|
||||
vertex_buf,
|
||||
@@ -301,6 +352,7 @@ impl framework::Example for Example {
|
||||
bind_group,
|
||||
uniform_buf,
|
||||
pipeline,
|
||||
pipeline_wire,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,6 +405,10 @@ impl framework::Example for Example {
|
||||
rpass.pop_debug_group();
|
||||
rpass.insert_debug_marker("Draw!");
|
||||
rpass.draw_indexed(0..self.index_count as u32, 0, 0..1);
|
||||
if let Some(ref pipe) = self.pipeline_wire {
|
||||
rpass.set_pipeline(pipe);
|
||||
rpass.draw_indexed(0..self.index_count as u32, 0, 0..1);
|
||||
}
|
||||
}
|
||||
|
||||
queue.submit(Some(encoder.finish()));
|
||||
|
||||
7
wgpu/examples/cube/wire.frag
Normal file
7
wgpu/examples/cube/wire.frag
Normal file
@@ -0,0 +1,7 @@
|
||||
#version 450
|
||||
|
||||
layout(location = 0) out vec4 o_Target;
|
||||
|
||||
void main() {
|
||||
o_Target = vec4(0.0, 0.5, 0.0, 0.5);
|
||||
}
|
||||
BIN
wgpu/examples/cube/wire.frag.spv
Normal file
BIN
wgpu/examples/cube/wire.frag.spv
Normal file
Binary file not shown.
@@ -79,39 +79,12 @@ impl Example {
|
||||
texture: &wgpu::Texture,
|
||||
mip_count: u32,
|
||||
) {
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::SampledTexture {
|
||||
multisampled: false,
|
||||
component_type: wgpu::TextureComponentType::Float,
|
||||
dimension: wgpu::TextureViewDimension::D2,
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler { comparison: false },
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("mipmap"),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("blit.vert.spv"));
|
||||
let fs_module = device.create_shader_module(wgpu::include_spirv!("blit.frag.spv"));
|
||||
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("blit"),
|
||||
layout: Some(&pipeline_layout),
|
||||
layout: None,
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
@@ -137,6 +110,8 @@ impl Example {
|
||||
alpha_to_coverage_enabled: false,
|
||||
});
|
||||
|
||||
let bind_group_layout = pipeline.get_bind_group_layout(0);
|
||||
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
label: Some("mip"),
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
@@ -217,43 +192,6 @@ impl framework::Example for Example {
|
||||
usage: wgpu::BufferUsage::VERTEX,
|
||||
});
|
||||
|
||||
// Create pipeline layout
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
entries: &[
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStage::VERTEX,
|
||||
ty: wgpu::BindingType::UniformBuffer {
|
||||
dynamic: false,
|
||||
min_binding_size: wgpu::BufferSize::new(64),
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::SampledTexture {
|
||||
component_type: wgpu::TextureComponentType::Float,
|
||||
multisampled: false,
|
||||
dimension: wgpu::TextureViewDimension::D2,
|
||||
},
|
||||
count: None,
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 2,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler { comparison: false },
|
||||
count: None,
|
||||
},
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("main"),
|
||||
bind_group_layouts: &[&bind_group_layout],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
|
||||
// Create the texture
|
||||
let mip_level_count = 9;
|
||||
let size = 1 << mip_level_count;
|
||||
@@ -318,33 +256,13 @@ impl framework::Example for Example {
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::COPY_DST,
|
||||
});
|
||||
|
||||
// Create bind group
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: uniform_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
// Create the render pipeline
|
||||
let vs_module = device.create_shader_module(wgpu::include_spirv!("draw.vert.spv"));
|
||||
let fs_module = device.create_shader_module(wgpu::include_spirv!("draw.frag.spv"));
|
||||
|
||||
let draw_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("draw"),
|
||||
layout: Some(&pipeline_layout),
|
||||
layout: None,
|
||||
vertex_stage: wgpu::ProgrammableStageDescriptor {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
@@ -374,6 +292,27 @@ impl framework::Example for Example {
|
||||
alpha_to_coverage_enabled: false,
|
||||
});
|
||||
|
||||
// Create bind group
|
||||
let bind_group_layout = draw_pipeline.get_bind_group_layout(0);
|
||||
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
layout: &bind_group_layout,
|
||||
entries: &[
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 0,
|
||||
resource: uniform_buf.as_entire_binding(),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 1,
|
||||
resource: wgpu::BindingResource::TextureView(&texture_view),
|
||||
},
|
||||
wgpu::BindGroupEntry {
|
||||
binding: 2,
|
||||
resource: wgpu::BindingResource::Sampler(&sampler),
|
||||
},
|
||||
],
|
||||
label: None,
|
||||
});
|
||||
|
||||
// Done
|
||||
Self::generate_mipmaps(&mut init_encoder, &device, &texture, mip_level_count);
|
||||
queue.submit(Some(init_encoder.finish()));
|
||||
|
||||
@@ -470,6 +470,7 @@ impl framework::Example for Example {
|
||||
rasterization_state: Some(wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
depth_bias: 2, // corresponds to bilinear filtering
|
||||
depth_bias_slope_scale: 2.0,
|
||||
depth_bias_clamp: 0.0,
|
||||
|
||||
@@ -3,10 +3,10 @@ mod framework;
|
||||
|
||||
mod point_gen;
|
||||
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use cgmath::Point3;
|
||||
use std::{iter, mem};
|
||||
use wgpu::util::DeviceExt;
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
|
||||
///
|
||||
/// Radius of the terrain.
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
//! This module covers generating points in a hexagonal fashion.
|
||||
//!
|
||||
|
||||
use cgmath::{InnerSpace, Point3, Vector3};
|
||||
use bytemuck::{Pod, Zeroable};
|
||||
use cgmath::{InnerSpace, Point3, Vector3};
|
||||
use std::collections::HashMap;
|
||||
|
||||
// The following constants are used in calculations.
|
||||
|
||||
@@ -777,6 +777,14 @@ impl crate::Context for Context {
|
||||
vertex_buffers: Borrowed(&vertex_buffers),
|
||||
};
|
||||
|
||||
let implicit_pipeline_ids = match desc.layout {
|
||||
Some(_) => None,
|
||||
None => Some(wgc::device::ImplicitPipelineIds {
|
||||
root_id: PhantomData,
|
||||
group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS],
|
||||
}),
|
||||
};
|
||||
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(device.id => global.device_create_render_pipeline(
|
||||
device.id,
|
||||
@@ -795,7 +803,7 @@ impl crate::Context for Context {
|
||||
alpha_to_coverage_enabled: desc.alpha_to_coverage_enabled,
|
||||
},
|
||||
PhantomData,
|
||||
None
|
||||
implicit_pipeline_ids
|
||||
))
|
||||
.unwrap_error_sink(&device.error_sink, || {
|
||||
let err = wgc::gfx_select!( device.id => global.render_pipeline_error(PhantomData));
|
||||
@@ -811,6 +819,14 @@ impl crate::Context for Context {
|
||||
) -> Self::ComputePipelineId {
|
||||
use wgc::pipeline as pipe;
|
||||
|
||||
let implicit_pipeline_ids = match desc.layout {
|
||||
Some(_) => None,
|
||||
None => Some(wgc::device::ImplicitPipelineIds {
|
||||
root_id: PhantomData,
|
||||
group_ids: &[PhantomData; wgc::MAX_BIND_GROUPS],
|
||||
}),
|
||||
};
|
||||
|
||||
let global = &self.0;
|
||||
wgc::gfx_select!(device.id => global.device_create_compute_pipeline(
|
||||
device.id,
|
||||
@@ -823,7 +839,7 @@ impl crate::Context for Context {
|
||||
},
|
||||
},
|
||||
PhantomData,
|
||||
None
|
||||
implicit_pipeline_ids
|
||||
))
|
||||
.unwrap_error_sink(&device.error_sink, || {
|
||||
let err = wgc::gfx_select!( device.id => global.compute_pipeline_error(PhantomData));
|
||||
|
||||
@@ -36,9 +36,9 @@ pub use wgt::{
|
||||
BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage, Color,
|
||||
ColorStateDescriptor, ColorWrite, CommandBufferDescriptor, CompareFunction, CullMode,
|
||||
DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset, Extent3d, Features, FilterMode,
|
||||
FrontFace, IndexFormat, InputStepMode, Limits, Origin3d, PowerPreference, PresentMode,
|
||||
PrimitiveTopology, PushConstantRange, RasterizationStateDescriptor, SamplerBorderColor,
|
||||
ShaderLocation, ShaderStage, StencilOperation, StencilStateDescriptor,
|
||||
FrontFace, IndexFormat, InputStepMode, Limits, Origin3d, PolygonMode, PowerPreference,
|
||||
PresentMode, PrimitiveTopology, PushConstantRange, RasterizationStateDescriptor,
|
||||
SamplerBorderColor, ShaderLocation, ShaderStage, StencilOperation, StencilStateDescriptor,
|
||||
StencilStateFaceDescriptor, SwapChainDescriptor, SwapChainStatus, TextureAspect,
|
||||
TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, TextureUsage,
|
||||
TextureViewDimension, VertexAttributeDescriptor, VertexFormat, BIND_BUFFER_ALIGNMENT,
|
||||
|
||||
Reference in New Issue
Block a user