mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
Add Buffer::size()
and Buffer::usage()
. (#2923)
This commit is contained in:
parent
29f5f8f60e
commit
780209dfb4
@ -56,6 +56,10 @@ the same every time it is rendered, we now warn if it is missing.
|
||||
+fn vert_main(v_in: VertexInput) -> @builtin(position) @invariant vec4<f32> {...}
|
||||
```
|
||||
|
||||
### Added/New Features
|
||||
|
||||
- Add `Buffer::size()` and `Buffer::usage()`; by @kpreid in [#2923](https://github.com/gfx-rs/wgpu/pull/2923)
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
#### General
|
||||
|
@ -659,6 +659,7 @@ pub struct Buffer {
|
||||
context: Arc<C>,
|
||||
id: <C as Context>::BufferId,
|
||||
map_context: Mutex<MapContext>,
|
||||
size: wgt::BufferAddress,
|
||||
usage: BufferUsages,
|
||||
}
|
||||
|
||||
@ -2129,6 +2130,7 @@ impl Device {
|
||||
context: Arc::clone(&self.context),
|
||||
id: Context::device_create_buffer(&*self.context, &self.id, desc),
|
||||
map_context: Mutex::new(map_context),
|
||||
size: desc.size,
|
||||
usage: desc.usage,
|
||||
}
|
||||
}
|
||||
@ -2426,6 +2428,20 @@ impl Buffer {
|
||||
pub fn destroy(&self) {
|
||||
Context::buffer_destroy(&*self.context, &self.id);
|
||||
}
|
||||
|
||||
/// Returns the length of the buffer allocation in bytes.
|
||||
///
|
||||
/// This is always equal to the `size` that was specified when creating the buffer.
|
||||
pub fn size(&self) -> wgt::BufferAddress {
|
||||
self.size
|
||||
}
|
||||
|
||||
/// Returns the allowed usages for this `Buffer`.
|
||||
///
|
||||
/// This is always equal to the `usage` that was specified when creating the buffer.
|
||||
pub fn usage(&self) -> BufferUsages {
|
||||
self.usage
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> BufferSlice<'a> {
|
||||
|
20
wgpu/tests/resource_descriptor_accessor.rs
Normal file
20
wgpu/tests/resource_descriptor_accessor.rs
Normal file
@ -0,0 +1,20 @@
|
||||
use crate::common::{initialize_test, TestParameters};
|
||||
|
||||
/// Buffer's size and usage can be read back.
|
||||
#[test]
|
||||
fn buffer_size_and_usage() {
|
||||
initialize_test(TestParameters::default(), |ctx| {
|
||||
let buffer = ctx.device.create_buffer(&wgpu::BufferDescriptor {
|
||||
label: None,
|
||||
size: 1234,
|
||||
usage: wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::COPY_DST,
|
||||
mapped_at_creation: false,
|
||||
});
|
||||
|
||||
assert_eq!(buffer.size(), 1234);
|
||||
assert_eq!(
|
||||
buffer.usage(),
|
||||
wgpu::BufferUsages::COPY_SRC | wgpu::BufferUsages::COPY_DST
|
||||
);
|
||||
})
|
||||
}
|
@ -6,6 +6,7 @@ mod device;
|
||||
mod example_wgsl;
|
||||
mod instance;
|
||||
mod poll;
|
||||
mod resource_descriptor_accessor;
|
||||
mod shader_primitive_index;
|
||||
mod vertex_indices;
|
||||
mod zero_init_texture_after_discard;
|
||||
|
Loading…
Reference in New Issue
Block a user