mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
upgrade wgpu
This commit is contained in:
parent
fd219660d3
commit
2ca6de2b81
12 changed files with 114 additions and 113 deletions
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
pass::{
|
||||
LoadOp, PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, StoreOp, TextureAttachment,
|
||||
LoadOp, Operations, PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, TextureAttachment,
|
||||
},
|
||||
render_graph::{
|
||||
nodes::{
|
||||
|
@ -96,20 +96,18 @@ impl BaseRenderGraphBuilder for RenderGraph {
|
|||
color_attachments: vec![RenderPassColorAttachmentDescriptor {
|
||||
attachment: TextureAttachment::Input("color".to_string()),
|
||||
resolve_target: None,
|
||||
load_op: LoadOp::Clear,
|
||||
store_op: StoreOp::Store,
|
||||
clear_color: Color::rgb(0.1, 0.1, 0.1),
|
||||
ops: Operations {
|
||||
load: LoadOp::Clear(Color::rgb(0.1, 0.1, 0.1)),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: TextureAttachment::Input("depth".to_string()),
|
||||
depth_load_op: LoadOp::Clear,
|
||||
depth_store_op: StoreOp::Store,
|
||||
stencil_load_op: LoadOp::Clear,
|
||||
stencil_store_op: StoreOp::Store,
|
||||
stencil_read_only: false,
|
||||
depth_read_only: false,
|
||||
clear_depth: 1.0,
|
||||
clear_stencil: 0,
|
||||
depth_ops: Some(Operations {
|
||||
load: LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
sample_count: 1,
|
||||
});
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum LoadOp {
|
||||
Clear = 0,
|
||||
Load = 1,
|
||||
/// Operation to perform to the output attachment at the start of a renderpass.
|
||||
#[derive(Clone, Copy, Debug, Hash, PartialEq)]
|
||||
pub enum LoadOp<V> {
|
||||
/// Clear with a specified value.
|
||||
Clear(V),
|
||||
/// Load from memory.
|
||||
Load,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
pub enum StoreOp {
|
||||
Clear = 0,
|
||||
Store = 1,
|
||||
}
|
||||
/// Pair of load and store operations for an attachment aspect.
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub struct Operations<V> {
|
||||
/// How data should be read through this attachment.
|
||||
pub load: LoadOp<V>,
|
||||
/// Whether data will be written to through this attachment.
|
||||
pub store: bool,
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use super::{LoadOp, StoreOp};
|
||||
use super::Operations;
|
||||
use crate::{render_resource::TextureId, Color};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -35,27 +35,17 @@ pub struct RenderPassColorAttachmentDescriptor {
|
|||
/// The resolve target for this color attachment, if any.
|
||||
pub resolve_target: Option<TextureAttachment>,
|
||||
|
||||
/// The beginning-of-pass load operation for this color attachment.
|
||||
pub load_op: LoadOp,
|
||||
|
||||
/// The end-of-pass store operation for this color attachment.
|
||||
pub store_op: StoreOp,
|
||||
|
||||
/// The color that will be assigned to every pixel of this attachment when cleared.
|
||||
pub clear_color: Color,
|
||||
/// What operations will be performed on this color attachment.
|
||||
pub ops: Operations<Color>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RenderPassDepthStencilAttachmentDescriptor {
|
||||
pub attachment: TextureAttachment,
|
||||
pub depth_load_op: LoadOp,
|
||||
pub depth_store_op: StoreOp,
|
||||
pub clear_depth: f32,
|
||||
pub stencil_load_op: LoadOp,
|
||||
pub stencil_store_op: StoreOp,
|
||||
pub depth_read_only: bool,
|
||||
pub stencil_read_only: bool,
|
||||
pub clear_stencil: u32,
|
||||
/// What operations will be performed on the depth part of the attachment.
|
||||
pub depth_ops: Option<Operations<f32>>,
|
||||
/// What operations will be performed on the stencil part of the attachment.
|
||||
pub stencil_ops: Option<Operations<u32>>,
|
||||
}
|
||||
|
||||
// A set of pipeline bindings and draw calls with color and depth outputs
|
||||
|
|
|
@ -29,7 +29,6 @@ pub enum BindType {
|
|||
},
|
||||
StorageTexture {
|
||||
dimension: TextureViewDimension,
|
||||
component_type: TextureComponentType,
|
||||
format: TextureFormat,
|
||||
readonly: bool,
|
||||
},
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
draw::{Draw, RenderCommand},
|
||||
pass::{ClearColor, PassDescriptor, TextureAttachment},
|
||||
pass::{ClearColor, PassDescriptor, TextureAttachment, LoadOp},
|
||||
pipeline::{
|
||||
BindGroupDescriptor, BindType, BindingDescriptor, PipelineDescriptor, UniformProperty,
|
||||
},
|
||||
|
@ -111,7 +111,7 @@ impl Node for PassNode {
|
|||
for (i, color_attachment) in self.descriptor.color_attachments.iter_mut().enumerate() {
|
||||
if self.default_clear_color_inputs.contains(&i) {
|
||||
if let Ok(default_clear_color) = resources.get::<ClearColor>() {
|
||||
color_attachment.clear_color = default_clear_color.0;
|
||||
color_attachment.ops.load = LoadOp::Clear(default_clear_color.0);
|
||||
}
|
||||
}
|
||||
if let Some(input_index) = self.color_attachment_input_indices[i] {
|
||||
|
|
|
@ -24,9 +24,9 @@ impl Default for SamplerDescriptor {
|
|||
mag_filter: FilterMode::Nearest,
|
||||
min_filter: FilterMode::Linear,
|
||||
mipmap_filter: FilterMode::Nearest,
|
||||
lod_min_clamp: -100.0,
|
||||
lod_max_clamp: 100.0,
|
||||
compare_function: Some(CompareFunction::Always),
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: std::f32::MAX,
|
||||
compare_function: None,
|
||||
anisotropy_clamp: None,
|
||||
}
|
||||
}
|
||||
|
@ -41,9 +41,9 @@ impl From<&Texture> for SamplerDescriptor {
|
|||
mag_filter: FilterMode::Nearest,
|
||||
min_filter: FilterMode::Linear,
|
||||
mipmap_filter: FilterMode::Nearest,
|
||||
lod_min_clamp: -100.0,
|
||||
lod_max_clamp: 100.0,
|
||||
compare_function: Some(CompareFunction::Always),
|
||||
lod_min_clamp: 0.0,
|
||||
lod_max_clamp: std::f32::MAX,
|
||||
compare_function: None,
|
||||
anisotropy_clamp: None,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ bevy_window = { path = "../bevy_window" }
|
|||
bevy_winit = { path = "../bevy_winit", optional = true }
|
||||
|
||||
# render
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "7b866b1a1b72d4ecb7a63e11fbc8f521fe9eb363" }
|
||||
wgpu = { git = "https://github.com/gfx-rs/wgpu-rs.git", rev = "344161feae78b077dc28089cf8daa8ce80277eb9" }
|
||||
# wgpu = { version = "0.5.0" }
|
||||
|
||||
pollster = "0.2.0"
|
||||
|
|
|
@ -209,9 +209,7 @@ fn create_wgpu_color_attachment_descriptor<'a>(
|
|||
.map(|target| get_texture_view(global_render_resource_bindings, refs, &target));
|
||||
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
store_op: color_attachment_descriptor.store_op.wgpu_into(),
|
||||
load_op: color_attachment_descriptor.load_op.wgpu_into(),
|
||||
clear_color: color_attachment_descriptor.clear_color.wgpu_into(),
|
||||
ops: (&color_attachment_descriptor.ops).wgpu_into(),
|
||||
attachment,
|
||||
resolve_target,
|
||||
}
|
||||
|
@ -230,21 +228,7 @@ fn create_wgpu_depth_stencil_attachment_descriptor<'a>(
|
|||
|
||||
wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment,
|
||||
clear_depth: depth_stencil_attachment_descriptor.clear_depth,
|
||||
clear_stencil: depth_stencil_attachment_descriptor.clear_stencil,
|
||||
depth_load_op: depth_stencil_attachment_descriptor
|
||||
.depth_load_op
|
||||
.wgpu_into(),
|
||||
depth_store_op: depth_stencil_attachment_descriptor
|
||||
.depth_store_op
|
||||
.wgpu_into(),
|
||||
stencil_load_op: depth_stencil_attachment_descriptor
|
||||
.stencil_load_op
|
||||
.wgpu_into(),
|
||||
stencil_store_op: depth_stencil_attachment_descriptor
|
||||
.stencil_store_op
|
||||
.wgpu_into(),
|
||||
depth_read_only: depth_stencil_attachment_descriptor.depth_read_only,
|
||||
stencil_read_only: depth_stencil_attachment_descriptor.stencil_read_only,
|
||||
depth_ops: depth_stencil_attachment_descriptor.depth_ops.as_ref().map(|ops| ops.wgpu_into()),
|
||||
stencil_ops: depth_stencil_attachment_descriptor.stencil_ops.as_ref().map(|ops| ops.wgpu_into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,10 +113,12 @@ impl WgpuRenderResourceContext {
|
|||
let bind_group_layout_binding = descriptor
|
||||
.bindings
|
||||
.iter()
|
||||
.map(|binding| wgpu::BindGroupLayoutEntry {
|
||||
binding: binding.index,
|
||||
visibility: wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
ty: (&binding.bind_type).wgpu_into(),
|
||||
.map(|binding| {
|
||||
wgpu::BindGroupLayoutEntry::new(
|
||||
binding.index,
|
||||
wgpu::ShaderStage::VERTEX | wgpu::ShaderStage::FRAGMENT,
|
||||
(&binding.bind_type).wgpu_into(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<wgpu::BindGroupLayoutEntry>>();
|
||||
let wgpu_descriptor = wgpu::BindGroupLayoutDescriptor {
|
||||
|
@ -186,12 +188,12 @@ impl RenderResourceContext for WgpuRenderResourceContext {
|
|||
label: None,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
let data = buffer.map_async(wgpu::MapMode::Write, 0, wgpu::BufferSize::WHOLE);
|
||||
let buffer_slice = buffer.slice(..);
|
||||
let data = buffer_slice.map_async(wgpu::MapMode::Write);
|
||||
self.device.poll(wgpu::Maintain::Wait);
|
||||
if let Ok(()) = pollster::block_on(data) {
|
||||
let data = buffer.get_mapped_range_mut(0, wgpu::BufferSize::WHOLE);
|
||||
setup_data(data, self);
|
||||
let mut data = buffer_slice.get_mapped_range_mut();
|
||||
setup_data(&mut data, self);
|
||||
} else {
|
||||
panic!("failed to map buffer to host");
|
||||
}
|
||||
|
@ -246,7 +248,9 @@ 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().unwrap();
|
||||
let shader_module = self.device.create_shader_module(&shader.get_spirv(None));
|
||||
let shader_module = self
|
||||
.device
|
||||
.create_shader_module(wgpu::ShaderModuleSource::SpirV(&shader.get_spirv(None)));
|
||||
shader_modules.insert(shader_handle, shader_module);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,23 +18,19 @@ pub struct WgpuRenderer {
|
|||
|
||||
impl WgpuRenderer {
|
||||
pub async fn new() -> Self {
|
||||
let instance = wgpu::Instance::new();
|
||||
let instance = wgpu::Instance::new(wgpu::BackendBit::PRIMARY);
|
||||
let adapter = instance
|
||||
.request_adapter(
|
||||
&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
compatible_surface: None,
|
||||
},
|
||||
wgpu::UnsafeExtensions::disallow(),
|
||||
wgpu::BackendBit::PRIMARY,
|
||||
)
|
||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||
power_preference: wgpu::PowerPreference::Default,
|
||||
compatible_surface: None,
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let (device, queue) = adapter
|
||||
.request_device(
|
||||
&wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions::empty(),
|
||||
features: wgpu::Features::empty(),
|
||||
limits: wgpu::Limits::default(),
|
||||
shader_validation: true,
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use bevy_render::{
|
||||
pass::{LoadOp, StoreOp},
|
||||
pass::{LoadOp, Operations},
|
||||
pipeline::{
|
||||
state_descriptors::{
|
||||
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
||||
|
@ -140,20 +140,41 @@ impl WgpuFrom<BufferUsage> for wgpu::BufferUsage {
|
|||
}
|
||||
}
|
||||
|
||||
impl WgpuFrom<LoadOp> for wgpu::LoadOp {
|
||||
fn from(val: LoadOp) -> Self {
|
||||
impl WgpuFrom<&LoadOp<Color>> for wgpu::LoadOp<wgpu::Color> {
|
||||
fn from(val: &LoadOp<Color>) -> Self {
|
||||
match val {
|
||||
LoadOp::Clear => wgpu::LoadOp::Clear,
|
||||
LoadOp::Clear(value) => wgpu::LoadOp::Clear(value.clone().wgpu_into()),
|
||||
LoadOp::Load => wgpu::LoadOp::Load,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WgpuFrom<StoreOp> for wgpu::StoreOp {
|
||||
fn from(val: StoreOp) -> Self {
|
||||
impl WgpuFrom<&LoadOp<f32>> for wgpu::LoadOp<f32> {
|
||||
fn from(val: &LoadOp<f32>) -> Self {
|
||||
match val {
|
||||
StoreOp::Clear => wgpu::StoreOp::Clear,
|
||||
StoreOp::Store => wgpu::StoreOp::Store,
|
||||
LoadOp::Clear(value) => wgpu::LoadOp::Clear(*value),
|
||||
LoadOp::Load => wgpu::LoadOp::Load,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl WgpuFrom<&LoadOp<u32>> for wgpu::LoadOp<u32> {
|
||||
fn from(val: &LoadOp<u32>) -> Self {
|
||||
match val {
|
||||
LoadOp::Clear(value) => wgpu::LoadOp::Clear(*value),
|
||||
LoadOp::Load => wgpu::LoadOp::Load,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T, U> WgpuFrom<&'a Operations<T>> for wgpu::Operations<U>
|
||||
where
|
||||
wgpu::LoadOp<U>: WgpuFrom<&'a LoadOp<T>>,
|
||||
{
|
||||
fn from(val: &'a Operations<T>) -> Self {
|
||||
Self {
|
||||
load: (&val.load).wgpu_into(),
|
||||
store: val.store,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -163,11 +184,19 @@ impl WgpuFrom<&BindType> for wgpu::BindingType {
|
|||
match bind_type {
|
||||
BindType::Uniform {
|
||||
dynamic,
|
||||
properties: _,
|
||||
} => wgpu::BindingType::UniformBuffer { dynamic: *dynamic },
|
||||
properties: _properties,
|
||||
} => wgpu::BindingType::UniformBuffer {
|
||||
dynamic: *dynamic,
|
||||
min_binding_size: bind_type
|
||||
.get_uniform_size()
|
||||
.and_then(|size| wgpu::BufferSize::new(size)),
|
||||
},
|
||||
BindType::StorageBuffer { dynamic, readonly } => wgpu::BindingType::StorageBuffer {
|
||||
dynamic: *dynamic,
|
||||
readonly: *readonly,
|
||||
min_binding_size: bind_type
|
||||
.get_uniform_size()
|
||||
.and_then(|size| wgpu::BufferSize::new(size)),
|
||||
},
|
||||
BindType::SampledTexture {
|
||||
dimension,
|
||||
|
@ -183,12 +212,10 @@ impl WgpuFrom<&BindType> for wgpu::BindingType {
|
|||
},
|
||||
BindType::StorageTexture {
|
||||
dimension,
|
||||
component_type,
|
||||
format,
|
||||
readonly,
|
||||
} => wgpu::BindingType::StorageTexture {
|
||||
dimension: (*dimension).wgpu_into(),
|
||||
component_type: (*component_type).wgpu_into(),
|
||||
format: (*format).wgpu_into(),
|
||||
readonly: *readonly,
|
||||
},
|
||||
|
|
|
@ -3,13 +3,14 @@ use bevy::{
|
|||
render::{
|
||||
pass::{
|
||||
LoadOp, PassDescriptor, RenderPassColorAttachmentDescriptor,
|
||||
RenderPassDepthStencilAttachmentDescriptor, StoreOp, TextureAttachment,
|
||||
RenderPassDepthStencilAttachmentDescriptor, TextureAttachment,
|
||||
},
|
||||
texture::{TextureDescriptor, TextureFormat, TextureUsage},
|
||||
ActiveCameras,
|
||||
},
|
||||
window::{CreateWindow, WindowId, WindowReference},
|
||||
};
|
||||
use bevy_render::pass::Operations;
|
||||
|
||||
fn main() {
|
||||
App::build()
|
||||
|
@ -68,20 +69,18 @@ fn setup(
|
|||
color_attachments: vec![RenderPassColorAttachmentDescriptor {
|
||||
attachment: TextureAttachment::Input("color".to_string()),
|
||||
resolve_target: None,
|
||||
load_op: LoadOp::Clear,
|
||||
store_op: StoreOp::Store,
|
||||
clear_color: Color::rgb(0.1, 0.1, 0.1),
|
||||
ops: Operations {
|
||||
load: LoadOp::Clear(Color::rgb(0.1, 0.1, 0.1)),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: TextureAttachment::Input("depth".to_string()),
|
||||
depth_load_op: LoadOp::Clear,
|
||||
depth_store_op: StoreOp::Store,
|
||||
stencil_load_op: LoadOp::Clear,
|
||||
stencil_store_op: StoreOp::Store,
|
||||
stencil_read_only: false,
|
||||
depth_read_only: false,
|
||||
clear_depth: 1.0,
|
||||
clear_stencil: 0,
|
||||
depth_ops: Some(Operations {
|
||||
load: LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
sample_count: 1,
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue