Skip to content

Commit

Permalink
Only non-hole attachments is supported on wasm target and gl backend
Browse files Browse the repository at this point in the history
  • Loading branch information
jinleili committed Jun 25, 2022
1 parent cf66739 commit 00a5912
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 42 deletions.
36 changes: 22 additions & 14 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,8 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
match desc
.color_attachments
.first()
.map(|at| &at.target.view.inner)
.filter(|at| at.is_some())
.map(|at| &at.as_ref().unwrap().target.view.inner)
{
// default framebuffer (provided externally)
Some(&super::TextureInner::DefaultRenderbuffer) => {
Expand All @@ -444,18 +445,20 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
.push(C::ResetFramebuffer { is_default: false });

for (i, cat) in desc.color_attachments.iter().enumerate() {
let attachment = glow::COLOR_ATTACHMENT0 + i as u32;
self.cmd_buffer.commands.push(C::BindAttachment {
attachment,
view: cat.target.view.clone(),
});
if let Some(ref rat) = cat.resolve_target {
self.state
.resolve_attachments
.push((attachment, rat.view.clone()));
}
if !cat.ops.contains(crate::AttachmentOps::STORE) {
self.state.invalidate_attachments.push(attachment);
if let Some(cat) = cat.as_ref() {
let attachment = glow::COLOR_ATTACHMENT0 + i as u32;
self.cmd_buffer.commands.push(C::BindAttachment {
attachment,
view: cat.target.view.clone(),
});
if let Some(ref rat) = cat.resolve_target {
self.state
.resolve_attachments
.push((attachment, rat.view.clone()));
}
if !cat.ops.contains(crate::AttachmentOps::STORE) {
self.state.invalidate_attachments.push(attachment);
}
}
}
if let Some(ref dsat) = desc.depth_stencil_attachment {
Expand Down Expand Up @@ -505,7 +508,12 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
});

// issue the clears
for (i, cat) in desc.color_attachments.iter().enumerate() {
for (i, cat) in desc
.color_attachments
.iter()
.filter_map(|at| at.as_ref())
.enumerate()
{
if !cat.ops.contains(crate::AttachmentOps::LOAD) {
let c = &cat.clear_value;
self.cmd_buffer
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/gles/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ impl crate::Device<super::Api> for super::Device {

let color_targets = {
let mut targets = Vec::new();
for ct in desc.color_targets.iter() {
for ct in desc.color_targets.iter().filter_map(|at| at.as_ref()) {
targets.push(super::ColorTargetDesc {
mask: ct.write_mask,
blend: ct.blend.as_ref().map(conv::map_blend),
Expand Down
66 changes: 39 additions & 27 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,17 +1498,20 @@ impl crate::Context for Context {
let targets = frag
.targets
.iter()
.map(|target| {
let mapped_format = map_texture_format(target.format);
let mut mapped_color_state = web_sys::GpuColorTargetState::new(mapped_format);
if let Some(ref bs) = target.blend {
let alpha = map_blend_component(&bs.alpha);
let color = map_blend_component(&bs.color);
let mapped_blend_state = web_sys::GpuBlendState::new(&alpha, &color);
mapped_color_state.blend(&mapped_blend_state);
}
mapped_color_state.write_mask(target.write_mask.bits());
mapped_color_state
.filter_map(|t| {
t.as_ref().map(|target| {
let mapped_format = map_texture_format(target.format);
let mut mapped_color_state =
web_sys::GpuColorTargetState::new(mapped_format);
if let Some(ref bs) = target.blend {
let alpha = map_blend_component(&bs.alpha);
let color = map_blend_component(&bs.color);
let mapped_blend_state = web_sys::GpuBlendState::new(&alpha, &color);
mapped_color_state.blend(&mapped_blend_state);
}
mapped_color_state.write_mask(target.write_mask.bits());
mapped_color_state
})
})
.collect::<js_sys::Array>();
let mapped_fragment_desc =
Expand Down Expand Up @@ -1632,7 +1635,10 @@ impl crate::Context for Context {
let mapped_color_formats = desc
.color_formats
.iter()
.map(|cf| wasm_bindgen::JsValue::from(map_texture_format(*cf)))
.filter_map(|cf| {
cf.as_ref()
.map(|format| wasm_bindgen::JsValue::from(map_texture_format(*format)))
})
.collect::<js_sys::Array>();
let mut mapped_desc = web_sys::GpuRenderBundleEncoderDescriptor::new(&mapped_color_formats);
if let Some(label) = desc.label {
Expand Down Expand Up @@ -1940,25 +1946,31 @@ impl crate::Context for Context {
let mapped_color_attachments = desc
.color_attachments
.iter()
.map(|ca| {
let load_value = match ca.ops.load {
crate::LoadOp::Clear(color) => wasm_bindgen::JsValue::from(map_color(color)),
crate::LoadOp::Load => wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load),
};
.filter_map(|attachment| {
attachment.as_ref().map(|ca| {
let load_value = match ca.ops.load {
crate::LoadOp::Clear(color) => {
wasm_bindgen::JsValue::from(map_color(color))
}
crate::LoadOp::Load => {
wasm_bindgen::JsValue::from(web_sys::GpuLoadOp::Load)
}
};

let mut mapped_color_attachment = web_sys::GpuRenderPassColorAttachment::new(
&load_value,
map_store_op(ca.ops.store),
&ca.view.id.0,
);
let mut mapped_color_attachment = web_sys::GpuRenderPassColorAttachment::new(
&load_value,
map_store_op(ca.ops.store),
&ca.view.id.0,
);

if let Some(rt) = ca.resolve_target {
mapped_color_attachment.resolve_target(&rt.id.0);
}
if let Some(rt) = ca.resolve_target {
mapped_color_attachment.resolve_target(&rt.id.0);
}

mapped_color_attachment.store_op(map_store_op(ca.ops.store));
mapped_color_attachment.store_op(map_store_op(ca.ops.store));

mapped_color_attachment
mapped_color_attachment
})
})
.collect::<js_sys::Array>();

Expand Down

0 comments on commit 00a5912

Please sign in to comment.