mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 06:50:59 +01:00
Enable use of GL_EXT_multisampled_render_to_texture extension for OpenGL backend (#8536)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
This commit is contained in:
1 parent
62c2f5da97
commit
e682ce3f29
5 files changed
+62
-8
No files matched your search
@@ -260,6 +260,11 @@ By @kpreid in [#9042](https://github.com/gfx-rs/wgpu/pull/9042).
|
||||
#### Vulkan
|
||||
|
||||
- Remove incorrect ordered texture uses. By @NiklasEi in [#8924](https://github.com/gfx-rs/wgpu/pull/8924).
|
||||
### Performance
|
||||
|
||||
#### GLES
|
||||
|
||||
- The GL backend would now try to take advantage of `GL_EXT_multisampled_render_to_texture` extension when applicable to skip the multi-sample resolve operation. By @opstic in [#8536](https://github.com/gfx-rs/wgpu/pull/8536).
|
||||
|
||||
### Documentation
|
||||
|
||||
|
||||
@@ -663,6 +663,10 @@ impl super::Adapter {
|
||||
// that's the only way to get gl_InstanceID to work correctly.
|
||||
features.set(wgt::Features::INDIRECT_FIRST_INSTANCE, supported);
|
||||
}
|
||||
private_caps.set(
|
||||
super::PrivateCapabilities::MULTISAMPLED_RENDER_TO_TEXTURE,
|
||||
extensions.contains("GL_EXT_multisampled_render_to_texture"),
|
||||
);
|
||||
|
||||
// GLSL ES 3.10+ / GLSL 4.30+ natively support coherent/volatile qualifiers
|
||||
// on storage buffers. These were introduced alongside storage buffer support.
|
||||
|
||||
@@ -556,10 +556,30 @@ impl crate::CommandEncoder for super::CommandEncoder {
|
||||
for (i, cat) in desc.color_attachments.iter().enumerate() {
|
||||
if let Some(cat) = cat.as_ref() {
|
||||
let attachment = glow::COLOR_ATTACHMENT0 + i as u32;
|
||||
// Try to use the multisampled render-to-texture extension to avoid resolving
|
||||
if let Some(ref rat) = cat.resolve_target {
|
||||
if matches!(rat.view.inner, super::TextureInner::Texture { .. })
|
||||
&& self.private_caps.contains(
|
||||
super::PrivateCapabilities::MULTISAMPLED_RENDER_TO_TEXTURE,
|
||||
)
|
||||
&& !cat.ops.contains(crate::AttachmentOps::STORE)
|
||||
// Extension specifies that only COLOR_ATTACHMENT0 is valid
|
||||
&& i == 0
|
||||
{
|
||||
self.cmd_buffer.commands.push(C::BindAttachment {
|
||||
attachment,
|
||||
view: rat.view.clone(),
|
||||
depth_slice: None,
|
||||
sample_count: desc.sample_count,
|
||||
});
|
||||
continue;
|
||||
}
|
||||
}
|
||||
self.cmd_buffer.commands.push(C::BindAttachment {
|
||||
attachment,
|
||||
view: cat.target.view.clone(),
|
||||
depth_slice: cat.depth_slice,
|
||||
sample_count: 1,
|
||||
});
|
||||
if let Some(ref rat) = cat.resolve_target {
|
||||
self.state
|
||||
@@ -582,6 +602,7 @@ impl crate::CommandEncoder for super::CommandEncoder {
|
||||
attachment,
|
||||
view: dsat.target.view.clone(),
|
||||
depth_slice: None,
|
||||
sample_count: 1,
|
||||
});
|
||||
if aspects.contains(crate::FormatAspects::DEPTH)
|
||||
&& dsat.depth_ops.contains(crate::AttachmentOps::STORE_DISCARD)
|
||||
|
||||
@@ -232,6 +232,8 @@ bitflags::bitflags! {
|
||||
///
|
||||
/// When this is true, instance offset emulation via vertex buffer rebinding and a shader uniform will be disabled.
|
||||
const FULLY_FEATURED_INSTANCING = 1 << 16;
|
||||
/// Supports direct multisampled rendering to a texture without needing a resolve texture.
|
||||
const MULTISAMPLED_RENDER_TO_TEXTURE = 1 << 17;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -922,6 +924,7 @@ enum Command {
|
||||
attachment: u32,
|
||||
view: TextureView,
|
||||
depth_slice: Option<u32>,
|
||||
sample_count: u32,
|
||||
},
|
||||
ResolveAttachment {
|
||||
attachment: u32,
|
||||
|
||||
@@ -111,6 +111,7 @@ impl super::Queue {
|
||||
attachment: u32,
|
||||
view: &super::TextureView,
|
||||
depth_slice: Option<u32>,
|
||||
sample_count: u32,
|
||||
) {
|
||||
match view.inner {
|
||||
super::TextureInner::Renderbuffer { raw } => {
|
||||
@@ -156,13 +157,24 @@ impl super::Queue {
|
||||
} else {
|
||||
unsafe {
|
||||
assert_eq!(view.mip_levels.len(), 1);
|
||||
gl.framebuffer_texture_2d(
|
||||
fbo_target,
|
||||
attachment,
|
||||
get_2d_target(target, view.array_layers.start),
|
||||
Some(raw),
|
||||
view.mip_levels.start as i32,
|
||||
)
|
||||
if sample_count != 1 {
|
||||
gl.framebuffer_texture_2d_multisample(
|
||||
fbo_target,
|
||||
attachment,
|
||||
get_2d_target(target, view.array_layers.start),
|
||||
Some(raw),
|
||||
view.mip_levels.start as i32,
|
||||
sample_count as i32,
|
||||
)
|
||||
} else {
|
||||
gl.framebuffer_texture_2d(
|
||||
fbo_target,
|
||||
attachment,
|
||||
get_2d_target(target, view.array_layers.start),
|
||||
Some(raw),
|
||||
view.mip_levels.start as i32,
|
||||
)
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1119,9 +1131,17 @@ impl super::Queue {
|
||||
attachment,
|
||||
ref view,
|
||||
depth_slice,
|
||||
sample_count,
|
||||
} => {
|
||||
unsafe {
|
||||
self.set_attachment(gl, glow::DRAW_FRAMEBUFFER, attachment, view, depth_slice)
|
||||
self.set_attachment(
|
||||
gl,
|
||||
glow::DRAW_FRAMEBUFFER,
|
||||
attachment,
|
||||
view,
|
||||
depth_slice,
|
||||
sample_count,
|
||||
)
|
||||
};
|
||||
}
|
||||
C::ResolveAttachment {
|
||||
@@ -1139,6 +1159,7 @@ impl super::Queue {
|
||||
glow::COLOR_ATTACHMENT0,
|
||||
dst,
|
||||
None,
|
||||
1,
|
||||
)
|
||||
};
|
||||
unsafe {
|
||||
|
||||
Reference in new issue
Block a user