Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First pass at updating to the future wgpu 0.7 version #1199

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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 crates/bevy_wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bevy_winit = { path = "../bevy_winit", optional = true, version = "0.4.0" }
bevy_utils = { path = "../bevy_utils", version = "0.4.0" }

# other
wgpu = "0.6"
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "3d60546"}
futures-lite = "1.4.0"
crossbeam-channel = "0.4.4"
crossbeam-utils = "0.7.2"
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_wgpu/src/renderer/wgpu_render_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub fn create_render_pass<'a, 'b>(
encoder: &'a mut wgpu::CommandEncoder,
) -> wgpu::RenderPass<'a> {
encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &pass_descriptor
.color_attachments
.iter()
Expand Down
25 changes: 21 additions & 4 deletions crates/bevy_wgpu/src/renderer/wgpu_render_resource_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use bevy_window::{Window, WindowId};
use futures_lite::future;
use std::{borrow::Cow, ops::Range, sync::Arc};
use wgpu::util::DeviceExt;
use wgpu::{ShaderModuleDescriptor, BufferSize};

#[derive(Clone, Debug)]
pub struct WgpuRenderResourceContext {
Expand Down Expand Up @@ -252,9 +253,17 @@ impl RenderResourceContext for WgpuRenderResourceContext {
fn create_shader_module_from_source(&self, shader_handle: &Handle<Shader>, shader: &Shader) {
let mut shader_modules = self.resources.shader_modules.write();
let spirv: Cow<[u32]> = shader.get_spirv(None).unwrap().into();
let source = wgpu::ShaderSource::SpirV(spirv);

let shader_module_descriptor = ShaderModuleDescriptor {
label: None,
source: source,
flags: Default::default()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll probably want the shader validation flag to replicate the old behavior:

Suggested change
flags: Default::default()
flags: wgpu::ShaderFlags::VALIDATION

};

let shader_module = self
.device
.create_shader_module(wgpu::ShaderModuleSource::SpirV(spirv));
.create_shader_module(&shader_module_descriptor);
shader_modules.insert(shader_handle.clone_weak(), shader_module);
}

Expand Down Expand Up @@ -425,7 +434,7 @@ impl RenderResourceContext for WgpuRenderResourceContext {
.as_ref()
.map(|d| d.wgpu_into()),
vertex_state: wgpu::VertexStateDescriptor {
index_format: pipeline_descriptor.index_format.wgpu_into(),
index_format: Some(pipeline_descriptor.index_format.wgpu_into()),
vertex_buffers: &owned_vertex_buffer_descriptors
.iter()
.map(|v| v.into())
Expand Down Expand Up @@ -485,9 +494,17 @@ impl RenderResourceContext for WgpuRenderResourceContext {
let sampler = samplers.get(&resource).unwrap();
wgpu::BindingResource::Sampler(sampler)
}
RenderResourceBinding::Buffer { buffer, range, .. } => {
RenderResourceBinding::Buffer { buffer, range, dynamic_index } => {
let wgpu_buffer = buffers.get(&buffer).unwrap();
wgpu::BindingResource::Buffer(wgpu_buffer.slice(range.clone()))
// let wgpu::BufferSlice { buffer, offset, size } = wgpu_buffer.slice(range.clone());
wgpu::BindingResource::Buffer{
buffer: &wgpu_buffer,
offset: match dynamic_index {
Some(index) => *index as u64,
None => u64::default()
},
size: Some(BufferSize::new(range.end).unwrap())
}
}
};
wgpu::BindGroupEntry {
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_wgpu/src/wgpu_render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use bevy_render::{
};
use bevy_utils::tracing::trace;
use std::ops::Range;
use wgpu::IndexFormat;
use crate::wgpu_type_converter::WgpuInto;

#[derive(Debug)]
pub struct WgpuRenderPass<'a> {
Expand Down Expand Up @@ -42,7 +44,12 @@ impl<'a> RenderPass for WgpuRenderPass<'a> {

fn set_index_buffer(&mut self, buffer_id: BufferId, offset: u64) {
let buffer = self.wgpu_resources.buffers.get(&buffer_id).unwrap();
self.render_pass.set_index_buffer(buffer.slice(offset..));
let index_format = match self.pipeline_descriptor {
Some(pipeline_descriptor) => pipeline_descriptor.index_format.wgpu_into(),
None => IndexFormat::default()
};

self.render_pass.set_index_buffer(buffer.slice(offset..), index_format);
}

fn draw_indexed(&mut self, indices: Range<u32>, base_vertex: i32, instances: Range<u32>) {
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_wgpu/src/wgpu_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl WgpuRenderer {
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: match options.power_pref {
WgpuPowerOptions::HighPerformance => wgpu::PowerPreference::HighPerformance,
WgpuPowerOptions::Adaptive => wgpu::PowerPreference::Default,
WgpuPowerOptions::Adaptive => Default::default(),
WgpuPowerOptions::LowPower => wgpu::PowerPreference::LowPower,
},
compatible_surface: None,
Expand All @@ -53,9 +53,9 @@ impl WgpuRenderer {
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits: wgpu::Limits::default(),
shader_validation: true,
limits: wgpu::Limits::default()
},
trace_path,
)
Expand Down
40 changes: 25 additions & 15 deletions crates/bevy_wgpu/src/wgpu_type_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use bevy_render::{
},
};
use bevy_window::Window;
use wgpu::{BufferBindingType, StorageTextureAccess};

pub trait WgpuFrom<T> {
fn from(val: T) -> Self;
Expand Down Expand Up @@ -181,46 +182,53 @@ where
impl WgpuFrom<&BindType> for wgpu::BindingType {
fn from(bind_type: &BindType) -> Self {
match bind_type {
BindType::Uniform { dynamic, .. } => wgpu::BindingType::UniformBuffer {
dynamic: *dynamic,
BindType::Uniform { dynamic, .. } => wgpu::BindingType::Buffer {
ty: BufferBindingType::Uniform,
has_dynamic_offset: *dynamic,
min_binding_size: bind_type.get_uniform_size().and_then(wgpu::BufferSize::new),
},
BindType::StorageBuffer { dynamic, readonly } => wgpu::BindingType::StorageBuffer {
dynamic: *dynamic,
readonly: *readonly,
BindType::StorageBuffer { dynamic, readonly } => wgpu::BindingType::Buffer {
ty: BufferBindingType::Storage {
read_only: *readonly
},
has_dynamic_offset: *dynamic,
min_binding_size: bind_type.get_uniform_size().and_then(wgpu::BufferSize::new),
},
BindType::SampledTexture {
dimension,
multisampled,
component_type,
} => wgpu::BindingType::SampledTexture {
dimension: (*dimension).wgpu_into(),
} => wgpu::BindingType::Texture {
sample_type: (*component_type).wgpu_into(),
view_dimension: (*dimension).wgpu_into(),
multisampled: *multisampled,
component_type: (*component_type).wgpu_into(),
},
BindType::Sampler { comparison } => wgpu::BindingType::Sampler {
filtering: false,
comparison: *comparison,
},
BindType::StorageTexture {
dimension,
format,
readonly,
} => wgpu::BindingType::StorageTexture {
dimension: (*dimension).wgpu_into(),
view_dimension: (*dimension).wgpu_into(),
format: (*format).wgpu_into(),
readonly: *readonly,
access: match *readonly {
true => StorageTextureAccess::ReadOnly,
false => StorageTextureAccess::WriteOnly
},
},
}
}
}

impl WgpuFrom<TextureComponentType> for wgpu::TextureComponentType {
impl WgpuFrom<TextureComponentType> for wgpu::TextureSampleType {
fn from(texture_component_type: TextureComponentType) -> Self {
match texture_component_type {
TextureComponentType::Float => wgpu::TextureComponentType::Float,
TextureComponentType::Sint => wgpu::TextureComponentType::Sint,
TextureComponentType::Uint => wgpu::TextureComponentType::Uint,
TextureComponentType::Float => wgpu::TextureSampleType::Float { filterable: true },
TextureComponentType::Sint => wgpu::TextureSampleType::Sint,
TextureComponentType::Uint => wgpu::TextureSampleType::Uint,
}
}
}
Expand Down Expand Up @@ -450,6 +458,7 @@ impl WgpuFrom<&RasterizationStateDescriptor> for wgpu::RasterizationStateDescrip
depth_bias_slope_scale: val.depth_bias_slope_scale,
depth_bias_clamp: val.depth_bias_clamp,
clamp_depth: val.clamp_depth,
polygon_mode: Default::default(),
}
}
}
Expand Down Expand Up @@ -536,6 +545,7 @@ impl WgpuFrom<SamplerDescriptor> for wgpu::SamplerDescriptor<'_> {
lod_max_clamp: sampler_descriptor.lod_max_clamp,
compare: sampler_descriptor.compare_function.map(|c| c.wgpu_into()),
anisotropy_clamp: sampler_descriptor.anisotropy_clamp,
border_color: None
}
}
}
Expand All @@ -562,7 +572,7 @@ impl WgpuFrom<FilterMode> for wgpu::FilterMode {
impl WgpuFrom<&Window> for wgpu::SwapChainDescriptor {
fn from(window: &Window) -> Self {
wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format: TextureFormat::default().wgpu_into(),
width: window.physical_width(),
height: window.physical_height(),
Expand Down