mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Update wgpu-rs to reflect latest wgpu API
This commit is contained in:
@@ -23,7 +23,7 @@ vulkan = ["wgn/gfx-backend-vulkan"]
|
||||
|
||||
[dependencies]
|
||||
#TODO: only depend on the published version
|
||||
wgn = { package = "wgpu-native", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "0edf927e5bb13d78d804e5ff58dce952f81e5832" }
|
||||
wgn = { package = "wgpu-native", features = ["local", "window-winit"], git = "https://github.com/gfx-rs/wgpu", rev = "dd61d1220357fc220631854d98f5f05e69623df9" }
|
||||
arrayvec = "0.4"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -115,11 +115,11 @@ impl framework::Example for Example {
|
||||
let vertex_size = mem::size_of::<Vertex>();
|
||||
let (vertex_data, index_data) = create_vertices();
|
||||
let vertex_buf = device
|
||||
.create_buffer_mapped(vertex_data.len(), wgpu::BufferUsageFlags::VERTEX)
|
||||
.create_buffer_mapped(vertex_data.len(), wgpu::BufferUsage::VERTEX)
|
||||
.fill_from_slice(&vertex_data);
|
||||
|
||||
let index_buf = device
|
||||
.create_buffer_mapped(index_data.len(), wgpu::BufferUsageFlags::INDEX)
|
||||
.create_buffer_mapped(index_data.len(), wgpu::BufferUsage::INDEX)
|
||||
.fill_from_slice(&index_data);
|
||||
|
||||
// Create pipeline layout
|
||||
@@ -127,17 +127,17 @@ impl framework::Example for Example {
|
||||
bindings: &[
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStageFlags::VERTEX,
|
||||
visibility: wgpu::ShaderStage::VERTEX,
|
||||
ty: wgpu::BindingType::UniformBuffer,
|
||||
},
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::SampledTexture,
|
||||
},
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 2,
|
||||
visibility: wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler,
|
||||
},
|
||||
],
|
||||
@@ -156,14 +156,16 @@ impl framework::Example for Example {
|
||||
};
|
||||
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
size: texture_extent,
|
||||
array_size: 1,
|
||||
array_layer_count: 1,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: wgpu::TextureFormat::Rgba8Unorm,
|
||||
usage: wgpu::TextureUsageFlags::SAMPLED | wgpu::TextureUsageFlags::TRANSFER_DST,
|
||||
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::TRANSFER_DST,
|
||||
});
|
||||
let texture_view = texture.create_default_view();
|
||||
let temp_buf = device
|
||||
.create_buffer_mapped(texels.len(), wgpu::BufferUsageFlags::TRANSFER_SRC)
|
||||
.create_buffer_mapped(texels.len(), wgpu::BufferUsage::TRANSFER_SRC)
|
||||
.fill_from_slice(&texels);
|
||||
init_encoder.copy_buffer_to_texture(
|
||||
wgpu::BufferCopyView {
|
||||
@@ -174,8 +176,8 @@ impl framework::Example for Example {
|
||||
},
|
||||
wgpu::TextureCopyView {
|
||||
texture: &texture,
|
||||
level: 0,
|
||||
slice: 0,
|
||||
mip_level: 0,
|
||||
array_layer: 0,
|
||||
origin: wgpu::Origin3d {
|
||||
x: 0.0,
|
||||
y: 0.0,
|
||||
@@ -187,24 +189,22 @@ impl framework::Example for Example {
|
||||
|
||||
// Create other resources
|
||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
r_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
s_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
t_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Nearest,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
lod_min_clamp: -100.0,
|
||||
lod_max_clamp: 100.0,
|
||||
max_anisotropy: 0,
|
||||
compare_function: wgpu::CompareFunction::Always,
|
||||
border_color: wgpu::BorderColor::TransparentBlack,
|
||||
});
|
||||
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
|
||||
let mx_ref: &[f32; 16] = mx_total.as_ref();
|
||||
let uniform_buf = device
|
||||
.create_buffer_mapped(
|
||||
16,
|
||||
wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
|
||||
)
|
||||
.fill_from_slice(mx_ref);
|
||||
|
||||
@@ -242,10 +242,10 @@ impl framework::Example for Example {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: wgpu::PipelineStageDescriptor {
|
||||
fragment_stage: Some(wgpu::PipelineStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
}),
|
||||
rasterization_state: wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Cw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
@@ -256,25 +256,25 @@ impl framework::Example for Example {
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
color: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWriteFlags::ALL,
|
||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: None,
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
vertex_buffers: &[wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as u32,
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: &[
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
attribute_index: 0,
|
||||
format: wgpu::VertexFormat::Float4,
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
},
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
attribute_index: 1,
|
||||
format: wgpu::VertexFormat::Float2,
|
||||
offset: 4 * 4,
|
||||
shader_location: 1,
|
||||
},
|
||||
],
|
||||
}],
|
||||
@@ -303,7 +303,7 @@ impl framework::Example for Example {
|
||||
let mx_ref: &[f32; 16] = mx_total.as_ref();
|
||||
|
||||
let temp_buf = device
|
||||
.create_buffer_mapped(16, wgpu::BufferUsageFlags::TRANSFER_SRC)
|
||||
.create_buffer_mapped(16, wgpu::BufferUsage::TRANSFER_SRC)
|
||||
.fill_from_slice(mx_ref);
|
||||
|
||||
let mut encoder =
|
||||
@@ -319,6 +319,7 @@ impl framework::Example for Example {
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_color: wgpu::Color {
|
||||
|
||||
@@ -54,10 +54,11 @@ pub fn run<E: Example>(title: &str) {
|
||||
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
|
||||
power_preference: wgpu::PowerPreference::LowPower,
|
||||
});
|
||||
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
|
||||
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: false,
|
||||
},
|
||||
limits: wgpu::Limits::default(),
|
||||
});
|
||||
|
||||
info!("Initializing the window...");
|
||||
@@ -71,7 +72,7 @@ pub fn run<E: Example>(title: &str) {
|
||||
|
||||
let surface = instance.create_surface(&window);
|
||||
let mut sc_desc = wgpu::SwapChainDescriptor {
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||
format: wgpu::TextureFormat::Bgra8Unorm,
|
||||
width: size.width.round() as u32,
|
||||
height: size.height.round() as u32,
|
||||
|
||||
@@ -12,16 +12,17 @@ fn main() {
|
||||
.map(|s| u32::from_str(&s).expect("You must pass a list of positive integers!"))
|
||||
.collect();
|
||||
|
||||
let size = (numbers.len() * std::mem::size_of::<u32>()) as u32;
|
||||
let size = (numbers.len() * std::mem::size_of::<u32>()) as wgpu::BufferAddress;
|
||||
|
||||
let instance = wgpu::Instance::new();
|
||||
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
});
|
||||
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
|
||||
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: false,
|
||||
},
|
||||
limits: wgpu::Limits::default(),
|
||||
});
|
||||
|
||||
let cs_bytes = include_bytes!("shader.comp.spv");
|
||||
@@ -30,23 +31,23 @@ fn main() {
|
||||
let staging_buffer = device
|
||||
.create_buffer_mapped(
|
||||
numbers.len(),
|
||||
wgpu::BufferUsageFlags::MAP_READ
|
||||
| wgpu::BufferUsageFlags::TRANSFER_DST
|
||||
| wgpu::BufferUsageFlags::TRANSFER_SRC,
|
||||
wgpu::BufferUsage::MAP_READ
|
||||
| wgpu::BufferUsage::TRANSFER_DST
|
||||
| wgpu::BufferUsage::TRANSFER_SRC,
|
||||
)
|
||||
.fill_from_slice(&numbers);
|
||||
|
||||
let storage_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size,
|
||||
usage: wgpu::BufferUsageFlags::STORAGE
|
||||
| wgpu::BufferUsageFlags::TRANSFER_DST
|
||||
| wgpu::BufferUsageFlags::TRANSFER_SRC,
|
||||
usage: wgpu::BufferUsage::STORAGE
|
||||
| wgpu::BufferUsage::TRANSFER_DST
|
||||
| wgpu::BufferUsage::TRANSFER_SRC,
|
||||
});
|
||||
|
||||
let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
bindings: &[wgpu::BindGroupLayoutBinding {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStageFlags::COMPUTE,
|
||||
visibility: wgpu::ShaderStage::COMPUTE,
|
||||
ty: wgpu::BindingType::StorageBuffer,
|
||||
}],
|
||||
});
|
||||
|
||||
@@ -5,10 +5,11 @@ fn main() {
|
||||
let adapter = instance.get_adapter(&wgpu::AdapterDescriptor {
|
||||
power_preference: wgpu::PowerPreference::LowPower,
|
||||
});
|
||||
let mut device = adapter.create_device(&wgpu::DeviceDescriptor {
|
||||
let mut device = adapter.request_device(&wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: false,
|
||||
},
|
||||
limits: wgpu::Limits::default(),
|
||||
});
|
||||
|
||||
let vs_bytes = include_bytes!("shader.vert.spv");
|
||||
@@ -32,10 +33,10 @@ fn main() {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: wgpu::PipelineStageDescriptor {
|
||||
fragment_stage: Some(wgpu::PipelineStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
}),
|
||||
rasterization_state: wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::None,
|
||||
@@ -46,9 +47,9 @@ fn main() {
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: wgpu::TextureFormat::Bgra8Unorm,
|
||||
color: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWriteFlags::ALL,
|
||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: None,
|
||||
index_format: wgpu::IndexFormat::Uint16,
|
||||
@@ -77,7 +78,7 @@ fn main() {
|
||||
let mut swap_chain = device.create_swap_chain(
|
||||
&surface,
|
||||
&wgpu::SwapChainDescriptor {
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||
format: wgpu::TextureFormat::Bgra8Unorm,
|
||||
width: size.width.round() as u32,
|
||||
height: size.height.round() as u32,
|
||||
@@ -112,6 +113,7 @@ fn main() {
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_color: wgpu::Color::GREEN,
|
||||
|
||||
@@ -189,36 +189,36 @@ impl framework::Example for Example {
|
||||
let (cube_vertex_data, cube_index_data) = create_cube();
|
||||
let cube_vertex_buf = Rc::new(
|
||||
device
|
||||
.create_buffer_mapped(cube_vertex_data.len(), wgpu::BufferUsageFlags::VERTEX)
|
||||
.create_buffer_mapped(cube_vertex_data.len(), wgpu::BufferUsage::VERTEX)
|
||||
.fill_from_slice(&cube_vertex_data),
|
||||
);
|
||||
|
||||
let cube_index_buf = Rc::new(
|
||||
device
|
||||
.create_buffer_mapped(cube_index_data.len(), wgpu::BufferUsageFlags::INDEX)
|
||||
.create_buffer_mapped(cube_index_data.len(), wgpu::BufferUsage::INDEX)
|
||||
.fill_from_slice(&cube_index_data),
|
||||
);
|
||||
|
||||
let (plane_vertex_data, plane_index_data) = create_plane(7);
|
||||
let plane_vertex_buf = device
|
||||
.create_buffer_mapped(plane_vertex_data.len(), wgpu::BufferUsageFlags::VERTEX)
|
||||
.create_buffer_mapped(plane_vertex_data.len(), wgpu::BufferUsage::VERTEX)
|
||||
.fill_from_slice(&plane_vertex_data);
|
||||
|
||||
let plane_index_buf = device
|
||||
.create_buffer_mapped(plane_index_data.len(), wgpu::BufferUsageFlags::INDEX)
|
||||
.create_buffer_mapped(plane_index_data.len(), wgpu::BufferUsage::INDEX)
|
||||
.fill_from_slice(&plane_index_data);
|
||||
|
||||
let entity_uniform_size = mem::size_of::<EntityUniforms>() as u32;
|
||||
let entity_uniform_size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
|
||||
let plane_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size: entity_uniform_size,
|
||||
usage: wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
|
||||
});
|
||||
|
||||
let local_bind_group_layout =
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
bindings: &[wgpu::BindGroupLayoutBinding {
|
||||
binding: 0,
|
||||
visibility: wgpu::ShaderStageFlags::VERTEX | wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::UniformBuffer,
|
||||
}],
|
||||
});
|
||||
@@ -291,7 +291,7 @@ impl framework::Example for Example {
|
||||
};
|
||||
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size: entity_uniform_size,
|
||||
usage: wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
|
||||
});
|
||||
entities.push(Entity {
|
||||
mx_world: cgmath::Matrix4::from(transform),
|
||||
@@ -316,25 +316,25 @@ impl framework::Example for Example {
|
||||
|
||||
// Create other resources
|
||||
let shadow_sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||
r_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
s_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
t_address_mode: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||
address_mode_w: wgpu::AddressMode::ClampToEdge,
|
||||
mag_filter: wgpu::FilterMode::Linear,
|
||||
min_filter: wgpu::FilterMode::Linear,
|
||||
mipmap_filter: wgpu::FilterMode::Nearest,
|
||||
lod_min_clamp: -100.0,
|
||||
lod_max_clamp: 100.0,
|
||||
max_anisotropy: 0,
|
||||
compare_function: wgpu::CompareFunction::LessEqual,
|
||||
border_color: wgpu::BorderColor::TransparentBlack,
|
||||
});
|
||||
|
||||
let shadow_texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||
size: Self::SHADOW_SIZE,
|
||||
array_size: Self::MAX_LIGHTS as u32,
|
||||
array_layer_count: Self::MAX_LIGHTS as u32,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: Self::SHADOW_FORMAT,
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT | wgpu::TextureUsageFlags::SAMPLED,
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT | wgpu::TextureUsage::SAMPLED,
|
||||
});
|
||||
let shadow_view = shadow_texture.create_default_view();
|
||||
|
||||
@@ -377,27 +377,27 @@ impl framework::Example for Example {
|
||||
target_view: shadow_target_views[1].take().unwrap(),
|
||||
},
|
||||
];
|
||||
let light_uniform_size = (Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as u32;
|
||||
let light_uniform_size = (Self::MAX_LIGHTS * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
|
||||
let light_uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size: light_uniform_size,
|
||||
usage: wgpu::BufferUsageFlags::UNIFORM
|
||||
| wgpu::BufferUsageFlags::TRANSFER_SRC
|
||||
| wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
usage: wgpu::BufferUsage::UNIFORM
|
||||
| wgpu::BufferUsage::TRANSFER_SRC
|
||||
| wgpu::BufferUsage::TRANSFER_DST,
|
||||
});
|
||||
|
||||
let vb_desc = wgpu::VertexBufferDescriptor {
|
||||
stride: vertex_size as u32,
|
||||
stride: vertex_size as wgpu::BufferAddress,
|
||||
step_mode: wgpu::InputStepMode::Vertex,
|
||||
attributes: &[
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
attribute_index: 0,
|
||||
format: wgpu::VertexFormat::Char4,
|
||||
offset: 0,
|
||||
shader_location: 0,
|
||||
},
|
||||
wgpu::VertexAttributeDescriptor {
|
||||
attribute_index: 1,
|
||||
format: wgpu::VertexFormat::Char4,
|
||||
offset: 4 * 1,
|
||||
shader_location: 1,
|
||||
},
|
||||
],
|
||||
};
|
||||
@@ -408,7 +408,7 @@ impl framework::Example for Example {
|
||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||
bindings: &[wgpu::BindGroupLayoutBinding {
|
||||
binding: 0, // global
|
||||
visibility: wgpu::ShaderStageFlags::VERTEX,
|
||||
visibility: wgpu::ShaderStage::VERTEX,
|
||||
ty: wgpu::BindingType::UniformBuffer,
|
||||
}],
|
||||
});
|
||||
@@ -416,10 +416,10 @@ impl framework::Example for Example {
|
||||
bind_group_layouts: &[&bind_group_layout, &local_bind_group_layout],
|
||||
});
|
||||
|
||||
let uniform_size = mem::size_of::<ShadowUniforms>() as u32;
|
||||
let uniform_size = mem::size_of::<ShadowUniforms>() as wgpu::BufferAddress;
|
||||
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
|
||||
size: uniform_size,
|
||||
usage: wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
usage: wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
|
||||
});
|
||||
|
||||
// Create bind group
|
||||
@@ -452,10 +452,10 @@ impl framework::Example for Example {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: wgpu::PipelineStageDescriptor {
|
||||
fragment_stage: Some(wgpu::PipelineStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
}),
|
||||
rasterization_state: wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Cw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
@@ -493,24 +493,24 @@ impl framework::Example for Example {
|
||||
bindings: &[
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 0, // global
|
||||
visibility: wgpu::ShaderStageFlags::VERTEX
|
||||
| wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::VERTEX
|
||||
| wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::UniformBuffer,
|
||||
},
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 1, // lights
|
||||
visibility: wgpu::ShaderStageFlags::VERTEX
|
||||
| wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::VERTEX
|
||||
| wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::UniformBuffer,
|
||||
},
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 2,
|
||||
visibility: wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::SampledTexture,
|
||||
},
|
||||
wgpu::BindGroupLayoutBinding {
|
||||
binding: 3,
|
||||
visibility: wgpu::ShaderStageFlags::FRAGMENT,
|
||||
visibility: wgpu::ShaderStage::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler,
|
||||
},
|
||||
],
|
||||
@@ -524,11 +524,11 @@ impl framework::Example for Example {
|
||||
proj: *mx_total.as_ref(),
|
||||
num_lights: [lights.len() as u32, 0, 0, 0],
|
||||
};
|
||||
let uniform_size = mem::size_of::<ForwardUniforms>() as u32;
|
||||
let uniform_size = mem::size_of::<ForwardUniforms>() as wgpu::BufferAddress;
|
||||
let uniform_buf = device
|
||||
.create_buffer_mapped(
|
||||
1,
|
||||
wgpu::BufferUsageFlags::UNIFORM | wgpu::BufferUsageFlags::TRANSFER_DST,
|
||||
wgpu::BufferUsage::UNIFORM | wgpu::BufferUsage::TRANSFER_DST,
|
||||
)
|
||||
.fill_from_slice(&[forward_uniforms]);
|
||||
|
||||
@@ -579,10 +579,10 @@ impl framework::Example for Example {
|
||||
module: &vs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
fragment_stage: wgpu::PipelineStageDescriptor {
|
||||
fragment_stage: Some(wgpu::PipelineStageDescriptor {
|
||||
module: &fs_module,
|
||||
entry_point: "main",
|
||||
},
|
||||
}),
|
||||
rasterization_state: wgpu::RasterizationStateDescriptor {
|
||||
front_face: wgpu::FrontFace::Cw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
@@ -593,9 +593,9 @@ impl framework::Example for Example {
|
||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
color_states: &[wgpu::ColorStateDescriptor {
|
||||
format: sc_desc.format,
|
||||
color: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWriteFlags::ALL,
|
||||
color_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
alpha_blend: wgpu::BlendDescriptor::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
depth_stencil_state: Some(wgpu::DepthStencilStateDescriptor {
|
||||
format: Self::DEPTH_FORMAT,
|
||||
@@ -624,10 +624,12 @@ impl framework::Example for Example {
|
||||
height: sc_desc.height,
|
||||
depth: 1,
|
||||
},
|
||||
array_size: 1,
|
||||
array_layer_count: 1,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: Self::DEPTH_FORMAT,
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||
});
|
||||
|
||||
Example {
|
||||
@@ -650,7 +652,7 @@ impl framework::Example for Example {
|
||||
let mx_total = Self::generate_matrix(sc_desc.width as f32 / sc_desc.height as f32);
|
||||
let mx_ref: &[f32; 16] = mx_total.as_ref();
|
||||
let temp_buf = device
|
||||
.create_buffer_mapped(16, wgpu::BufferUsageFlags::TRANSFER_SRC)
|
||||
.create_buffer_mapped(16, wgpu::BufferUsage::TRANSFER_SRC)
|
||||
.fill_from_slice(mx_ref);
|
||||
|
||||
let mut encoder =
|
||||
@@ -665,10 +667,12 @@ impl framework::Example for Example {
|
||||
height: sc_desc.height,
|
||||
depth: 1,
|
||||
},
|
||||
array_size: 1,
|
||||
array_layer_count: 1,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension: wgpu::TextureDimension::D2,
|
||||
format: Self::DEPTH_FORMAT,
|
||||
usage: wgpu::TextureUsageFlags::OUTPUT_ATTACHMENT,
|
||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||
});
|
||||
self.forward_depth = depth_texture.create_default_view();
|
||||
}
|
||||
@@ -678,9 +682,9 @@ impl framework::Example for Example {
|
||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { todo: 0 });
|
||||
|
||||
{
|
||||
let size = mem::size_of::<EntityUniforms>() as u32;
|
||||
let size = mem::size_of::<EntityUniforms>() as wgpu::BufferAddress;
|
||||
let temp_buf_data = device
|
||||
.create_buffer_mapped(self.entities.len(), wgpu::BufferUsageFlags::TRANSFER_SRC);
|
||||
.create_buffer_mapped(self.entities.len(), wgpu::BufferUsage::TRANSFER_SRC);
|
||||
|
||||
for (i, entity) in self.entities.iter_mut().enumerate() {
|
||||
if entity.rotation_speed != 0.0 {
|
||||
@@ -704,7 +708,7 @@ impl framework::Example for Example {
|
||||
for (i, entity) in self.entities.iter().enumerate() {
|
||||
encoder.copy_buffer_to_buffer(
|
||||
&temp_buf,
|
||||
i as u32 * size,
|
||||
i as wgpu::BufferAddress * size,
|
||||
&entity.uniform_buf,
|
||||
0,
|
||||
size,
|
||||
@@ -714,9 +718,9 @@ impl framework::Example for Example {
|
||||
|
||||
if self.lights_are_dirty {
|
||||
self.lights_are_dirty = false;
|
||||
let size = (self.lights.len() * mem::size_of::<LightRaw>()) as u32;
|
||||
let size = (self.lights.len() * mem::size_of::<LightRaw>()) as wgpu::BufferAddress;
|
||||
let temp_buf_data = device
|
||||
.create_buffer_mapped(self.lights.len(), wgpu::BufferUsageFlags::TRANSFER_SRC);
|
||||
.create_buffer_mapped(self.lights.len(), wgpu::BufferUsage::TRANSFER_SRC);
|
||||
for (i, light) in self.lights.iter().enumerate() {
|
||||
temp_buf_data.data[i] = light.to_raw();
|
||||
}
|
||||
@@ -734,7 +738,7 @@ impl framework::Example for Example {
|
||||
// let's just copy it over to the shadow uniform buffer.
|
||||
encoder.copy_buffer_to_buffer(
|
||||
&self.light_uniform_buf,
|
||||
(i * mem::size_of::<LightRaw>()) as u32,
|
||||
(i * mem::size_of::<LightRaw>()) as wgpu::BufferAddress,
|
||||
&self.shadow_pass.uniform_buf,
|
||||
0,
|
||||
64,
|
||||
@@ -768,6 +772,7 @@ impl framework::Example for Example {
|
||||
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_color: wgpu::Color {
|
||||
|
||||
102
wgpu/src/lib.rs
102
wgpu/src/lib.rs
@@ -14,13 +14,13 @@ pub use wgn::{
|
||||
BlendDescriptor,
|
||||
BlendFactor,
|
||||
BlendOperation,
|
||||
BorderColor,
|
||||
BufferAddress,
|
||||
BufferDescriptor,
|
||||
BufferMapAsyncStatus,
|
||||
BufferUsageFlags,
|
||||
BufferUsage,
|
||||
Color,
|
||||
ColorStateDescriptor,
|
||||
ColorWriteFlags,
|
||||
ColorWrite,
|
||||
CommandEncoderDescriptor,
|
||||
CompareFunction,
|
||||
CullMode,
|
||||
@@ -32,17 +32,17 @@ pub use wgn::{
|
||||
FrontFace,
|
||||
IndexFormat,
|
||||
InputStepMode,
|
||||
Limits,
|
||||
LoadOp,
|
||||
Origin3d,
|
||||
PowerPreference,
|
||||
PrimitiveTopology,
|
||||
RasterizationStateDescriptor,
|
||||
RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor,
|
||||
SamplerDescriptor,
|
||||
ShaderAttributeIndex,
|
||||
ShaderLocation,
|
||||
ShaderModuleDescriptor,
|
||||
ShaderStageFlags,
|
||||
ShaderStage,
|
||||
StencilOperation,
|
||||
StencilStateFaceDescriptor,
|
||||
StoreOp,
|
||||
@@ -51,7 +51,7 @@ pub use wgn::{
|
||||
TextureDescriptor,
|
||||
TextureDimension,
|
||||
TextureFormat,
|
||||
TextureUsageFlags,
|
||||
TextureUsage,
|
||||
TextureViewDescriptor,
|
||||
TextureViewDimension,
|
||||
VertexAttributeDescriptor,
|
||||
@@ -161,7 +161,7 @@ pub struct Queue<'a> {
|
||||
pub enum BindingResource<'a> {
|
||||
Buffer {
|
||||
buffer: &'a Buffer,
|
||||
range: Range<u32>,
|
||||
range: Range<BufferAddress>,
|
||||
},
|
||||
Sampler(&'a Sampler),
|
||||
TextureView(&'a TextureView),
|
||||
@@ -192,7 +192,7 @@ pub struct PipelineStageDescriptor<'a> {
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct VertexBufferDescriptor<'a> {
|
||||
pub stride: u32,
|
||||
pub stride: BufferAddress,
|
||||
pub step_mode: InputStepMode,
|
||||
pub attributes: &'a [VertexAttributeDescriptor],
|
||||
}
|
||||
@@ -200,7 +200,7 @@ pub struct VertexBufferDescriptor<'a> {
|
||||
pub struct RenderPipelineDescriptor<'a> {
|
||||
pub layout: &'a PipelineLayout,
|
||||
pub vertex_stage: PipelineStageDescriptor<'a>,
|
||||
pub fragment_stage: PipelineStageDescriptor<'a>,
|
||||
pub fragment_stage: Option<PipelineStageDescriptor<'a>>,
|
||||
pub rasterization_state: RasterizationStateDescriptor,
|
||||
pub primitive_topology: PrimitiveTopology,
|
||||
pub color_states: &'a [ColorStateDescriptor],
|
||||
@@ -216,11 +216,19 @@ pub struct ComputePipelineDescriptor<'a> {
|
||||
}
|
||||
|
||||
pub struct RenderPassDescriptor<'a> {
|
||||
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor<&'a TextureView>],
|
||||
pub color_attachments: &'a [RenderPassColorAttachmentDescriptor<'a>],
|
||||
pub depth_stencil_attachment:
|
||||
Option<RenderPassDepthStencilAttachmentDescriptor<&'a TextureView>>,
|
||||
}
|
||||
|
||||
pub struct RenderPassColorAttachmentDescriptor<'a> {
|
||||
pub attachment: &'a TextureView,
|
||||
pub resolve_target: Option<&'a TextureView>,
|
||||
pub load_op: LoadOp,
|
||||
pub store_op: StoreOp,
|
||||
pub clear_color: Color,
|
||||
}
|
||||
|
||||
pub struct SwapChainOutput<'a> {
|
||||
pub texture: Texture,
|
||||
pub view: TextureView,
|
||||
@@ -229,7 +237,7 @@ pub struct SwapChainOutput<'a> {
|
||||
|
||||
pub struct BufferCopyView<'a> {
|
||||
pub buffer: &'a Buffer,
|
||||
pub offset: u32,
|
||||
pub offset: BufferAddress,
|
||||
pub row_pitch: u32,
|
||||
pub image_height: u32,
|
||||
}
|
||||
@@ -247,8 +255,8 @@ impl<'a> BufferCopyView<'a> {
|
||||
|
||||
pub struct TextureCopyView<'a> {
|
||||
pub texture: &'a Texture,
|
||||
pub level: u32,
|
||||
pub slice: u32,
|
||||
pub mip_level: u32,
|
||||
pub array_layer: u32,
|
||||
pub origin: Origin3d,
|
||||
}
|
||||
|
||||
@@ -256,8 +264,8 @@ impl<'a> TextureCopyView<'a> {
|
||||
fn into_native(self) -> wgn::TextureCopyView {
|
||||
wgn::TextureCopyView {
|
||||
texture: self.texture.id,
|
||||
level: self.level,
|
||||
slice: self.slice,
|
||||
mip_level: self.mip_level,
|
||||
array_layer: self.array_layer,
|
||||
origin: self.origin,
|
||||
}
|
||||
}
|
||||
@@ -311,9 +319,9 @@ impl Instance {
|
||||
}
|
||||
|
||||
impl Adapter {
|
||||
pub fn create_device(&self, desc: &DeviceDescriptor) -> Device {
|
||||
pub fn request_device(&self, desc: &DeviceDescriptor) -> Device {
|
||||
Device {
|
||||
id: wgn::wgpu_adapter_create_device(self.id, desc),
|
||||
id: wgn::wgpu_adapter_request_device(self.id, desc),
|
||||
temp: Temp::default(),
|
||||
}
|
||||
}
|
||||
@@ -354,7 +362,7 @@ impl Device {
|
||||
let bindings = desc
|
||||
.bindings
|
||||
.into_iter()
|
||||
.map(|binding| wgn::Binding {
|
||||
.map(|binding| wgn::BindGroupBinding {
|
||||
binding: binding.binding,
|
||||
resource: match binding.resource {
|
||||
BindingResource::Buffer {
|
||||
@@ -418,7 +426,20 @@ impl Device {
|
||||
|
||||
pub fn create_render_pipeline(&self, desc: &RenderPipelineDescriptor) -> RenderPipeline {
|
||||
let vertex_entry_point = CString::new(desc.vertex_stage.entry_point).unwrap();
|
||||
let fragment_entry_point = CString::new(desc.fragment_stage.entry_point).unwrap();
|
||||
let vertex_stage = wgn::PipelineStageDescriptor {
|
||||
module: desc.vertex_stage.module.id,
|
||||
entry_point: vertex_entry_point.as_ptr(),
|
||||
};
|
||||
let (_fragment_entry_point, fragment_stage) = if let Some(fragment_stage) = &desc.fragment_stage {
|
||||
let fragment_entry_point = CString::new(fragment_stage.entry_point).unwrap();
|
||||
let fragment_stage = wgn::PipelineStageDescriptor {
|
||||
module: fragment_stage.module.id,
|
||||
entry_point: fragment_entry_point.as_ptr(),
|
||||
};
|
||||
(fragment_entry_point, Some(fragment_stage))
|
||||
} else {
|
||||
(CString::default(), None)
|
||||
};
|
||||
|
||||
let temp_color_states = desc.color_states.to_vec();
|
||||
let temp_vertex_buffers = desc
|
||||
@@ -437,14 +458,8 @@ impl Device {
|
||||
self.id,
|
||||
&wgn::RenderPipelineDescriptor {
|
||||
layout: desc.layout.id,
|
||||
vertex_stage: wgn::PipelineStageDescriptor {
|
||||
module: desc.vertex_stage.module.id,
|
||||
entry_point: vertex_entry_point.as_ptr(),
|
||||
},
|
||||
fragment_stage: wgn::PipelineStageDescriptor {
|
||||
module: desc.fragment_stage.module.id,
|
||||
entry_point: fragment_entry_point.as_ptr(),
|
||||
},
|
||||
vertex_stage,
|
||||
fragment_stage: fragment_stage.as_ref().map_or(ptr::null(), |fs| fs as *const _),
|
||||
rasterization_state: desc.rasterization_state.clone(),
|
||||
primitive_topology: desc.primitive_topology,
|
||||
color_states: temp_color_states.as_ptr(),
|
||||
@@ -453,7 +468,7 @@ impl Device {
|
||||
.depth_stencil_state
|
||||
.as_ref()
|
||||
.map_or(ptr::null(), |p| p as *const _),
|
||||
vertex_buffer_state: wgn::VertexBufferStateDescriptor {
|
||||
vertex_input: wgn::VertexInputDescriptor {
|
||||
index_format: desc.index_format,
|
||||
vertex_buffers: temp_vertex_buffers.as_ptr(),
|
||||
vertex_buffers_count: temp_vertex_buffers.len(),
|
||||
@@ -490,16 +505,16 @@ impl Device {
|
||||
pub fn create_buffer_mapped<'a, T>(
|
||||
&self,
|
||||
count: usize,
|
||||
usage: BufferUsageFlags,
|
||||
usage: BufferUsage,
|
||||
) -> CreateBufferMapped<'a, T>
|
||||
where
|
||||
T: 'static + Copy,
|
||||
{
|
||||
let type_size = std::mem::size_of::<T>() as u32;
|
||||
let type_size = std::mem::size_of::<T>() as BufferAddress;
|
||||
assert_ne!(type_size, 0);
|
||||
|
||||
let desc = BufferDescriptor {
|
||||
size: (type_size * count as u32).max(1),
|
||||
size: (type_size * count as BufferAddress).max(1),
|
||||
usage,
|
||||
};
|
||||
let mut ptr: *mut u8 = std::ptr::null_mut();
|
||||
@@ -557,7 +572,7 @@ struct BufferMapReadAsyncUserData<T, F>
|
||||
where
|
||||
F: FnOnce(BufferMapAsyncResult<&[T]>),
|
||||
{
|
||||
size: u32,
|
||||
size: BufferAddress,
|
||||
callback: F,
|
||||
buffer_id: wgn::BufferId,
|
||||
phantom: std::marker::PhantomData<T>,
|
||||
@@ -567,19 +582,19 @@ struct BufferMapWriteAsyncUserData<T, F>
|
||||
where
|
||||
F: FnOnce(BufferMapAsyncResult<&mut [T]>),
|
||||
{
|
||||
size: u32,
|
||||
size: BufferAddress,
|
||||
callback: F,
|
||||
buffer_id: wgn::BufferId,
|
||||
phantom: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
pub fn map_read_async<T, F>(&self, start: u32, size: u32, callback: F)
|
||||
pub fn map_read_async<T, F>(&self, start: BufferAddress, size: BufferAddress, callback: F)
|
||||
where
|
||||
T: 'static + Copy,
|
||||
F: FnOnce(BufferMapAsyncResult<&[T]>) + 'static,
|
||||
{
|
||||
let type_size = std::mem::size_of::<T>() as u32;
|
||||
let type_size = std::mem::size_of::<T>() as BufferAddress;
|
||||
assert_ne!(type_size, 0);
|
||||
assert_eq!(size % type_size, 0);
|
||||
|
||||
@@ -623,12 +638,12 @@ impl Buffer {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn map_write_async<T, F>(&self, start: u32, size: u32, callback: F)
|
||||
pub fn map_write_async<T, F>(&self, start: BufferAddress, size: BufferAddress, callback: F)
|
||||
where
|
||||
T: 'static + Copy,
|
||||
F: FnOnce(BufferMapAsyncResult<&mut [T]>) + 'static,
|
||||
{
|
||||
let type_size = std::mem::size_of::<T>() as u32;
|
||||
let type_size = std::mem::size_of::<T>() as BufferAddress;
|
||||
assert_ne!(type_size, 0);
|
||||
assert_eq!(size % type_size, 0);
|
||||
|
||||
@@ -726,8 +741,9 @@ impl CommandEncoder {
|
||||
let colors = desc
|
||||
.color_attachments
|
||||
.iter()
|
||||
.map(|ca| RenderPassColorAttachmentDescriptor {
|
||||
.map(|ca| wgn::RenderPassColorAttachmentDescriptor {
|
||||
attachment: ca.attachment.id,
|
||||
resolve_target: ca.resolve_target.map_or(ptr::null(), |v| &v.id as *const _),
|
||||
load_op: ca.load_op,
|
||||
store_op: ca.store_op,
|
||||
clear_color: ca.clear_color,
|
||||
@@ -772,10 +788,10 @@ impl CommandEncoder {
|
||||
pub fn copy_buffer_to_buffer(
|
||||
&mut self,
|
||||
source: &Buffer,
|
||||
source_offset: u32,
|
||||
source_offset: BufferAddress,
|
||||
destination: &Buffer,
|
||||
destination_offset: u32,
|
||||
copy_size: u32,
|
||||
destination_offset: BufferAddress,
|
||||
copy_size: BufferAddress,
|
||||
) {
|
||||
wgn::wgpu_command_buffer_copy_buffer_to_buffer(
|
||||
self.id,
|
||||
@@ -849,7 +865,7 @@ impl<'a> RenderPass<'a> {
|
||||
wgn::wgpu_render_pass_set_blend_color(self.id, &color);
|
||||
}
|
||||
|
||||
pub fn set_index_buffer(&mut self, buffer: &Buffer, offset: u32) {
|
||||
pub fn set_index_buffer(&mut self, buffer: &Buffer, offset: BufferAddress) {
|
||||
wgn::wgpu_render_pass_set_index_buffer(self.id, buffer.id, offset);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user