Added new UNRESTRICTED_INDEX_BUFFER downlevel flag. (#3157)

Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
This commit is contained in:
Andreas Reich 2022-11-07 21:45:50 +01:00 committed by GitHub
parent db30e3909a
commit b838b0871c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 54 additions and 4 deletions

View File

@ -47,6 +47,7 @@ Bottom level categories:
- Convert all `Default` Implementations on Enums to `derive(Default)` - Convert all `Default` Implementations on Enums to `derive(Default)`
- Implement `Default` for `CompositeAlphaMode` - Implement `Default` for `CompositeAlphaMode`
- Improve compute shader validation error message. By @haraldreingruber in [#3139](https://github.com/gfx-rs/wgpu/pull/3139) - Improve compute shader validation error message. By @haraldreingruber in [#3139](https://github.com/gfx-rs/wgpu/pull/3139)
- New downlevel feature `UNRESTRICTED_INDEX_BUFFER` to indicate support for using `INDEX` together with other non-copy/map usages (unsupported on WebGL). By @Wumpf in [#3157](https://github.com/gfx-rs/wgpu/pull/3157)
#### WebGPU #### WebGPU
- Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098) - Implement `queue_validate_write_buffer` by @jinleili in [#3098](https://github.com/gfx-rs/wgpu/pull/3098)

View File

@ -544,10 +544,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let hub = A::hub(self); let hub = A::hub(self);
let mut token = Token::root(); let mut token = Token::root();
let (device_guard, mut token) = hub.devices.read(&mut token);
let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token); let (mut cmd_buf_guard, mut token) = hub.command_buffers.write(&mut token);
let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, command_encoder_id)?; let cmd_buf = CommandBuffer::get_encoder_mut(&mut *cmd_buf_guard, command_encoder_id)?;
let (buffer_guard, _) = hub.buffers.read(&mut token); let (buffer_guard, _) = hub.buffers.read(&mut token);
let device = &device_guard[cmd_buf.device_id.value];
#[cfg(feature = "trace")] #[cfg(feature = "trace")]
if let Some(ref mut list) = cmd_buf.commands { if let Some(ref mut list) = cmd_buf.commands {
list.push(TraceCommand::CopyBufferToBuffer { list.push(TraceCommand::CopyBufferToBuffer {
@ -597,6 +600,26 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
if destination_offset % wgt::COPY_BUFFER_ALIGNMENT != 0 { if destination_offset % wgt::COPY_BUFFER_ALIGNMENT != 0 {
return Err(TransferError::UnalignedBufferOffset(destination_offset).into()); return Err(TransferError::UnalignedBufferOffset(destination_offset).into());
} }
if !device
.downlevel
.flags
.contains(wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER)
&& (src_buffer.usage.contains(wgt::BufferUsages::INDEX)
|| dst_buffer.usage.contains(wgt::BufferUsages::INDEX))
{
let forbidden_usages = wgt::BufferUsages::VERTEX
| wgt::BufferUsages::UNIFORM
| wgt::BufferUsages::INDIRECT
| wgt::BufferUsages::STORAGE;
if src_buffer.usage.intersects(forbidden_usages)
|| dst_buffer.usage.intersects(forbidden_usages)
{
return Err(TransferError::MissingDownlevelFlags(MissingDownlevelFlags(
wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER,
))
.into());
}
}
let source_end_offset = source_offset + size; let source_end_offset = source_offset + size;
let destination_end_offset = destination_offset + size; let destination_end_offset = destination_offset + size;

View File

@ -590,6 +590,17 @@ impl<A: HalApi> Device<A> {
}); });
} }
if desc.usage.contains(wgt::BufferUsages::INDEX)
&& desc.usage.contains(
wgt::BufferUsages::VERTEX
| wgt::BufferUsages::UNIFORM
| wgt::BufferUsages::INDIRECT
| wgt::BufferUsages::STORAGE,
)
{
self.require_downlevel_flags(wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER)?;
}
let mut usage = conv::map_buffer_usage(desc.usage); let mut usage = conv::map_buffer_usage(desc.usage);
if desc.usage.is_empty() { if desc.usage.is_empty() {

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
device::{DeviceError, HostMap, MissingFeatures}, device::{DeviceError, HostMap, MissingDownlevelFlags, MissingFeatures},
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Resource, Token}, hub::{Global, GlobalIdentityHandlerFactory, HalApi, Resource, Token},
id::{AdapterId, DeviceId, SurfaceId, TextureId, Valid}, id::{AdapterId, DeviceId, SurfaceId, TextureId, Valid},
init_tracker::{BufferInitTracker, TextureInitTracker}, init_tracker::{BufferInitTracker, TextureInitTracker},
@ -248,6 +248,8 @@ pub enum CreateBufferError {
UsageMismatch(wgt::BufferUsages), UsageMismatch(wgt::BufferUsages),
#[error("Buffer size {requested} is greater than the maximum buffer size ({maximum})")] #[error("Buffer size {requested} is greater than the maximum buffer size ({maximum})")]
MaxBufferSize { requested: u64, maximum: u64 }, MaxBufferSize { requested: u64, maximum: u64 },
#[error(transparent)]
MissingDownlevelFlags(#[from] MissingDownlevelFlags),
} }
impl<A: hal::Api> Resource for Buffer<A> { impl<A: hal::Api> Resource for Buffer<A> {

View File

@ -91,8 +91,9 @@ impl super::Adapter {
| wgt::Features::CLEAR_TEXTURE | wgt::Features::CLEAR_TEXTURE
| wgt::Features::TEXTURE_FORMAT_16BIT_NORM | wgt::Features::TEXTURE_FORMAT_16BIT_NORM
| wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO; | wgt::Features::ADDRESS_MODE_CLAMP_TO_ZERO;
let mut downlevel = let mut downlevel = wgt::DownlevelFlags::BASE_VERTEX
wgt::DownlevelFlags::BASE_VERTEX | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL; | wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL
| wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER;
// Features from queries // Features from queries
downlevel.set( downlevel.set(

View File

@ -312,6 +312,11 @@ impl super::Adapter {
wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED, wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED,
!(cfg!(target_arch = "wasm32") || is_angle), !(cfg!(target_arch = "wasm32") || is_angle),
); );
// see https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
downlevel_flags.set(
wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER,
!cfg!(target_arch = "wasm32"),
);
let mut features = wgt::Features::empty() let mut features = wgt::Features::empty()
| wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES | wgt::Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES

View File

@ -1056,7 +1056,7 @@ bitflags::bitflags! {
/// Supports samplers with anisotropic filtering. Note this isn't actually required by /// Supports samplers with anisotropic filtering. Note this isn't actually required by
/// WebGPU, the implementation is allowed to completely ignore aniso clamp. This flag is /// WebGPU, the implementation is allowed to completely ignore aniso clamp. This flag is
/// here for native backends so they can comunicate to the user of aniso is enabled. /// here for native backends so they can communicate to the user of aniso is enabled.
/// ///
/// All backends and all devices support anisotropic filtering. /// All backends and all devices support anisotropic filtering.
const ANISOTROPIC_FILTERING = 1 << 10; const ANISOTROPIC_FILTERING = 1 << 10;
@ -1080,6 +1080,13 @@ bitflags::bitflags! {
/// ///
/// WebGL doesn't support this. /// WebGL doesn't support this.
const BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED = 1 << 15; const BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED = 1 << 15;
/// Supports buffers to combine [`BufferUsages::INDEX`] with usages other than [`BufferUsages::COPY_DST`] and [`BufferUsages::COPY_SRC`].
/// Furthermore, in absence of this feature it is not allowed to copy index buffers from/to buffers with a set of usage flags containing
/// [`BufferUsages::VERTEX`]/[`BufferUsages::UNIFORM`]/[`BufferUsages::STORAGE`] or [`BufferUsages::INDIRECT`].
///
/// WebGL doesn't support this.
const UNRESTRICTED_INDEX_BUFFER = 1 << 16;
} }
} }