mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[rs] Another refactor of RenderPassDescriptor API
This commit is contained in:
@@ -263,11 +263,9 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::BLACK,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -86,11 +86,9 @@ async fn run() {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &texture.create_default_view(),
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::RED,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::RED),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -326,16 +326,14 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color {
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
},
|
||||
read_only: false,
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -114,11 +114,9 @@ async fn run(event_loop: EventLoop<()>, window: Window, swapchain_format: wgpu::
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::GREEN,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::GREEN),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -186,11 +186,9 @@ impl Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &views[target_mip],
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::WHITE,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::WHITE),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
@@ -411,20 +409,19 @@ impl framework::Example for Example {
|
||||
let mut encoder =
|
||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
{
|
||||
let clear_color = wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
};
|
||||
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
},
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(clear_color),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -255,23 +255,21 @@ impl framework::Example for Example {
|
||||
let mut encoder =
|
||||
device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
|
||||
{
|
||||
let channel = wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::BLACK,
|
||||
read_only: false,
|
||||
let ops = wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
|
||||
store: true,
|
||||
};
|
||||
let rpass_color_attachment = if self.sample_count == 1 {
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel,
|
||||
ops,
|
||||
}
|
||||
} else {
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &self.multisampled_framebuffer,
|
||||
resolve_target: Some(&frame.view),
|
||||
channel,
|
||||
ops,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -756,18 +756,11 @@ impl framework::Example for Example {
|
||||
color_attachments: &[],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &light.target_view,
|
||||
depth: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 1.0,
|
||||
read_only: false,
|
||||
},
|
||||
stencil: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 0,
|
||||
read_only: false,
|
||||
},
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
});
|
||||
pass.set_pipeline(&self.shadow_pass.pipeline);
|
||||
@@ -787,32 +780,23 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color {
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
},
|
||||
read_only: false,
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.forward_depth,
|
||||
depth: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Clear,
|
||||
clear_value: 1.0,
|
||||
read_only: false,
|
||||
},
|
||||
stencil: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Clear,
|
||||
clear_value: 0,
|
||||
read_only: false,
|
||||
},
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: false,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
});
|
||||
pass.set_pipeline(&self.forward_pass.pipeline);
|
||||
|
||||
@@ -278,16 +278,14 @@ impl framework::Example for Skybox {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color {
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color {
|
||||
r: 0.1,
|
||||
g: 0.2,
|
||||
b: 0.3,
|
||||
a: 1.0,
|
||||
},
|
||||
read_only: false,
|
||||
}),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -371,11 +371,9 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: wgpu::Color::BLACK,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: None,
|
||||
|
||||
@@ -719,29 +719,20 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &self.reflect_view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: back_color,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(back_color),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
// We still need to use the depth buffer here
|
||||
// since the pipeline requires it.
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.depth_buffer,
|
||||
depth: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Clear,
|
||||
clear_value: 1.0,
|
||||
read_only: false,
|
||||
},
|
||||
stencil: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Clear,
|
||||
clear_value: 0,
|
||||
read_only: false,
|
||||
},
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
});
|
||||
rpass.set_pipeline(&self.terrain_pipeline);
|
||||
@@ -756,27 +747,18 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: back_color,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(back_color),
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.depth_buffer,
|
||||
depth: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 1.0,
|
||||
read_only: false,
|
||||
},
|
||||
stencil: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Clear,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 0,
|
||||
read_only: false,
|
||||
},
|
||||
depth_ops: Some(wgpu::Operations {
|
||||
load: wgpu::LoadOp::Clear(1.0),
|
||||
store: true,
|
||||
}),
|
||||
stencil_ops: None,
|
||||
}),
|
||||
});
|
||||
rpass.set_pipeline(&self.terrain_pipeline);
|
||||
@@ -791,27 +773,15 @@ impl framework::Example for Example {
|
||||
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
resolve_target: None,
|
||||
channel: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Load,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: back_color,
|
||||
read_only: false,
|
||||
ops: wgpu::Operations {
|
||||
load: wgpu::LoadOp::Load,
|
||||
store: true,
|
||||
},
|
||||
}],
|
||||
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachmentDescriptor {
|
||||
attachment: &self.depth_buffer,
|
||||
depth: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Load,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 1.0,
|
||||
read_only: true,
|
||||
},
|
||||
stencil: wgpu::PassChannel {
|
||||
load_op: wgpu::LoadOp::Load,
|
||||
store_op: wgpu::StoreOp::Store,
|
||||
clear_value: 0,
|
||||
read_only: false,
|
||||
},
|
||||
depth_ops: None,
|
||||
stencil_ops: None,
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
backend::native_gpu_future, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource,
|
||||
BufferDescriptor, Capabilities, CommandEncoderDescriptor, ComputePipelineDescriptor,
|
||||
Extensions, Limits, MapMode, PipelineLayoutDescriptor, RenderPipelineDescriptor,
|
||||
SamplerDescriptor, ShaderModuleSource, SwapChainStatus, TextureDescriptor,
|
||||
TextureViewDescriptor,
|
||||
Extensions, Limits, LoadOp, MapMode, Operations, PipelineLayoutDescriptor,
|
||||
RenderPipelineDescriptor, SamplerDescriptor, ShaderModuleSource, SwapChainStatus,
|
||||
TextureDescriptor, TextureViewDescriptor,
|
||||
};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
@@ -283,6 +283,43 @@ fn map_texture_copy_view(view: crate::TextureCopyView) -> wgc::command::TextureC
|
||||
}
|
||||
}
|
||||
|
||||
fn map_pass_channel<V: Copy + Default>(ops: Option<&Operations<V>>) -> wgt::PassChannel<V> {
|
||||
match ops {
|
||||
Some(&Operations {
|
||||
load: LoadOp::Clear(clear_value),
|
||||
store,
|
||||
}) => wgt::PassChannel {
|
||||
load_op: wgt::LoadOp::Clear,
|
||||
store_op: if store {
|
||||
wgt::StoreOp::Store
|
||||
} else {
|
||||
wgt::StoreOp::Clear
|
||||
},
|
||||
clear_value,
|
||||
read_only: false,
|
||||
},
|
||||
Some(&Operations {
|
||||
load: LoadOp::Load,
|
||||
store,
|
||||
}) => wgt::PassChannel {
|
||||
load_op: wgt::LoadOp::Load,
|
||||
store_op: if store {
|
||||
wgt::StoreOp::Store
|
||||
} else {
|
||||
wgt::StoreOp::Clear
|
||||
},
|
||||
clear_value: V::default(),
|
||||
read_only: false,
|
||||
},
|
||||
None => wgt::PassChannel {
|
||||
load_op: wgt::LoadOp::Load,
|
||||
store_op: wgt::StoreOp::Store,
|
||||
clear_value: V::default(),
|
||||
read_only: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::Context for Context {
|
||||
type AdapterId = wgc::id::AdapterId;
|
||||
type DeviceId = wgc::id::DeviceId;
|
||||
@@ -453,7 +490,8 @@ impl crate::Context for Context {
|
||||
bindings: &bindings,
|
||||
},
|
||||
PhantomData
|
||||
)).unwrap()
|
||||
))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn device_create_pipeline_layout(
|
||||
@@ -879,15 +917,15 @@ impl crate::Context for Context {
|
||||
.map(|ca| wgc::command::ColorAttachmentDescriptor {
|
||||
attachment: ca.attachment.id,
|
||||
resolve_target: ca.resolve_target.map(|rt| rt.id),
|
||||
channel: ca.channel.clone(),
|
||||
channel: map_pass_channel(Some(&ca.ops)),
|
||||
})
|
||||
.collect::<ArrayVec<[_; wgc::device::MAX_COLOR_TARGETS]>>();
|
||||
|
||||
let depth_stencil = desc.depth_stencil_attachment.as_ref().map(|dsa| {
|
||||
wgc::command::DepthStencilAttachmentDescriptor {
|
||||
attachment: dsa.attachment.id,
|
||||
depth: dsa.depth.clone(),
|
||||
stencil: dsa.stencil.clone(),
|
||||
depth: map_pass_channel(dsa.depth_ops.as_ref()),
|
||||
stencil: map_pass_channel(dsa.stencil_ops.as_ref()),
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BindingType, BufferDescriptor,
|
||||
CommandEncoderDescriptor, ComputePipelineDescriptor, PipelineLayoutDescriptor,
|
||||
CommandEncoderDescriptor, ComputePipelineDescriptor, LoadOp, PipelineLayoutDescriptor,
|
||||
ProgrammableStageDescriptor, RenderPipelineDescriptor, SamplerDescriptor, ShaderModuleSource,
|
||||
SwapChainStatus, TextureDescriptor, TextureViewDescriptor, TextureViewDimension,
|
||||
};
|
||||
@@ -190,11 +190,11 @@ impl crate::RenderPassInner<Context> for RenderPass {
|
||||
self.0.set_stencil_reference(reference);
|
||||
}
|
||||
|
||||
fn insert_debug_marker(&mut self, label: &str) {
|
||||
fn insert_debug_marker(&mut self, _label: &str) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn push_debug_group(&mut self, group_label: &str) {
|
||||
fn push_debug_group(&mut self, _group_label: &str) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ impl crate::RenderPassInner<Context> for RenderPass {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn execute_bundles<'a, I: Iterator<Item = &'a ()>>(&mut self, render_bundles: I) {
|
||||
fn execute_bundles<'a, I: Iterator<Item = &'a ()>>(&mut self, _render_bundles: I) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
@@ -563,10 +563,11 @@ fn map_color(color: wgt::Color) -> web_sys::GpuColorDict {
|
||||
web_sys::GpuColorDict::new(color.a, color.b, color.g, color.r)
|
||||
}
|
||||
|
||||
fn map_store_op(op: wgt::StoreOp) -> web_sys::GpuStoreOp {
|
||||
match op {
|
||||
wgt::StoreOp::Clear => web_sys::GpuStoreOp::Clear,
|
||||
wgt::StoreOp::Store => web_sys::GpuStoreOp::Store,
|
||||
fn map_store_op(store: bool) -> web_sys::GpuStoreOp {
|
||||
if store {
|
||||
web_sys::GpuStoreOp::Store
|
||||
} else {
|
||||
web_sys::GpuStoreOp::Clear
|
||||
}
|
||||
}
|
||||
|
||||
@@ -783,7 +784,7 @@ impl crate::Context for Context {
|
||||
ShaderModuleSource::SpirV(spv) => {
|
||||
web_sys::GpuShaderModuleDescriptor::new(&js_sys::Uint32Array::from(spv))
|
||||
}
|
||||
ShaderModuleSource::Wgsl(code) => {
|
||||
ShaderModuleSource::Wgsl(_code) => {
|
||||
panic!("WGSL is not yet supported by the Web backend")
|
||||
}
|
||||
};
|
||||
@@ -1291,13 +1292,9 @@ impl crate::Context for Context {
|
||||
let mut mapped_color_attachment =
|
||||
web_sys::GpuRenderPassColorAttachmentDescriptor::new(
|
||||
&ca.attachment.id.0,
|
||||
&match ca.channel.load_op {
|
||||
wgt::LoadOp::Clear => {
|
||||
wasm_bindgen::JsValue::from(map_color(ca.channel.clear_value))
|
||||
}
|
||||
wgt::LoadOp::Load => {
|
||||
wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load)
|
||||
}
|
||||
&match ca.ops.load {
|
||||
LoadOp::Clear(color) => wasm_bindgen::JsValue::from(map_color(color)),
|
||||
LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1305,7 +1302,7 @@ impl crate::Context for Context {
|
||||
mapped_color_attachment.resolve_target(&rt.id.0);
|
||||
}
|
||||
|
||||
mapped_color_attachment.store_op(map_store_op(ca.channel.store_op));
|
||||
mapped_color_attachment.store_op(map_store_op(ca.ops.store));
|
||||
|
||||
mapped_color_attachment
|
||||
})
|
||||
@@ -1316,19 +1313,39 @@ impl crate::Context for Context {
|
||||
// TODO: label
|
||||
|
||||
if let Some(dsa) = &desc.depth_stencil_attachment {
|
||||
let (depth_load_op, depth_store_op) = match dsa.depth_ops {
|
||||
Some(ref ops) => {
|
||||
let load_op = match ops.load {
|
||||
LoadOp::Clear(value) => wasm_bindgen::JsValue::from(value),
|
||||
LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
};
|
||||
(load_op, map_store_op(ops.store))
|
||||
}
|
||||
None => (
|
||||
wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
web_sys::GpuStoreOp::Store,
|
||||
),
|
||||
};
|
||||
let (stencil_load_op, stencil_store_op) = match dsa.depth_ops {
|
||||
Some(ref ops) => {
|
||||
let load_op = match ops.load {
|
||||
LoadOp::Clear(value) => wasm_bindgen::JsValue::from(value),
|
||||
LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
};
|
||||
(load_op, map_store_op(ops.store))
|
||||
}
|
||||
None => (
|
||||
wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
web_sys::GpuStoreOp::Store,
|
||||
),
|
||||
};
|
||||
let mapped_depth_stencil_attachment =
|
||||
web_sys::GpuRenderPassDepthStencilAttachmentDescriptor::new(
|
||||
&dsa.attachment.id.0,
|
||||
&match dsa.depth.load_op {
|
||||
wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.depth.clear_value),
|
||||
wgt::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
},
|
||||
map_store_op(dsa.depth.store_op),
|
||||
&match dsa.stencil.load_op {
|
||||
wgt::LoadOp::Clear => wasm_bindgen::JsValue::from(dsa.stencil.clear_value),
|
||||
wgt::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
|
||||
},
|
||||
map_store_op(dsa.stencil.store_op),
|
||||
&depth_load_op,
|
||||
depth_store_op,
|
||||
&stencil_load_op,
|
||||
stencil_store_op,
|
||||
);
|
||||
|
||||
mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment);
|
||||
|
||||
@@ -25,12 +25,12 @@ pub use wgt::{
|
||||
BlendDescriptor, BlendFactor, BlendOperation, BufferAddress, BufferSize, BufferUsage,
|
||||
Capabilities, Color, ColorStateDescriptor, ColorWrite, CommandBufferDescriptor,
|
||||
CompareFunction, CullMode, DepthStencilStateDescriptor, DeviceDescriptor, DynamicOffset,
|
||||
Extensions, Extent3d, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, LoadOp,
|
||||
Origin3d, PassChannel, PowerPreference, PresentMode, PrimitiveTopology,
|
||||
RasterizationStateDescriptor, RenderBundleEncoderDescriptor, ShaderLocation, ShaderStage,
|
||||
StencilOperation, StencilStateFaceDescriptor, StoreOp, SwapChainDescriptor, SwapChainStatus,
|
||||
TextureAspect, TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat,
|
||||
TextureUsage, TextureViewDimension, UnsafeExtensions, VertexAttributeDescriptor, VertexFormat,
|
||||
Extensions, Extent3d, FilterMode, FrontFace, IndexFormat, InputStepMode, Limits, Origin3d,
|
||||
PowerPreference, PresentMode, PrimitiveTopology, RasterizationStateDescriptor,
|
||||
RenderBundleEncoderDescriptor, ShaderLocation, ShaderStage, StencilOperation,
|
||||
StencilStateFaceDescriptor, SwapChainDescriptor, SwapChainStatus, TextureAspect,
|
||||
TextureComponentType, TextureDataLayout, TextureDimension, TextureFormat, TextureUsage,
|
||||
TextureViewDimension, UnsafeExtensions, VertexAttributeDescriptor, VertexFormat,
|
||||
BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT,
|
||||
};
|
||||
|
||||
@@ -892,18 +892,39 @@ pub struct ComputePipelineDescriptor<'a> {
|
||||
pub compute_stage: ProgrammableStageDescriptor<'a>,
|
||||
}
|
||||
|
||||
// The underlying types are also exported so that documentation shows up for them
|
||||
/// 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,
|
||||
}
|
||||
|
||||
/// Pair of load and store operations for an attachment aspect.
|
||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
||||
pub struct Operations<V> {
|
||||
pub load: LoadOp<V>,
|
||||
pub store: bool,
|
||||
}
|
||||
|
||||
pub use wgt::RenderPassColorAttachmentDescriptorBase;
|
||||
/// Describes a color attachment to a [`RenderPass`].
|
||||
pub type RenderPassColorAttachmentDescriptor<'a> =
|
||||
wgt::RenderPassColorAttachmentDescriptorBase<&'a TextureView>;
|
||||
pub use wgt::RenderPassDepthStencilAttachmentDescriptorBase;
|
||||
#[derive(Clone)]
|
||||
pub struct RenderPassColorAttachmentDescriptor<'a> {
|
||||
pub attachment: &'a TextureView,
|
||||
pub resolve_target: Option<&'a TextureView>,
|
||||
pub ops: Operations<Color>,
|
||||
}
|
||||
/// Describes a depth/stencil attachment to a [`RenderPass`].
|
||||
pub type RenderPassDepthStencilAttachmentDescriptor<'a> =
|
||||
wgt::RenderPassDepthStencilAttachmentDescriptorBase<&'a TextureView>;
|
||||
#[derive(Clone)]
|
||||
pub struct RenderPassDepthStencilAttachmentDescriptor<'a> {
|
||||
pub attachment: &'a TextureView,
|
||||
pub depth_ops: Option<Operations<f32>>,
|
||||
pub stencil_ops: Option<Operations<u32>>,
|
||||
}
|
||||
|
||||
/// Describes the attachments of a [`RenderPass`].
|
||||
#[derive(Clone)]
|
||||
pub struct RenderPassDescriptor<'a, 'b> {
|
||||
/// The color attachments of the render pass.
|
||||
pub color_attachments: &'b [RenderPassColorAttachmentDescriptor<'a>],
|
||||
|
||||
Reference in New Issue
Block a user