Make {CpuAccessibleBuffer,ImmutableBuffer}::from_data sound (#1517)

from_data needs flat memory structures. Types which implement
Copy (either implicity or explicitly) ensure this property.

This commit adds the Copy trait bound to
{CpuAccessibleBuffer,ImmutableBuffer}::from_data and adapts the unit
tests accordingly.
This commit is contained in:
stephan-cr 2021-03-31 06:51:38 +02:00 committed by GitHub
parent c2d404c669
commit eb21fea03b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 26 deletions

View File

@ -29,6 +29,10 @@
- Implemented synchronization for `SyncCommandBufferBuilder::execute_commands`.
- `AutoCommandBufferBuilder::execute_commands` is now fully safe to use.
- `SyncCommandBufferBuilder` now becomes poisoned when it returns an error, to prevent using the builder in an inconsistent state.
- Fixed missing barriers in dispatch calls
- **Breaking** `shader!` no longer marks descriptor sets as readonly as a fallback when it doesn't know
- **Breaking** The keyword `readonly` might need to be added in front of the `buffer` keyword in GLSL files to get them working again
- **Breaking** structures passed to `ImmutableBuffer::from_data` and `CpuAccessibleBuffer::from_data` must implement [`Copy`](https://doc.rust-lang.org/std/marker/trait.Copy.html) to ensure soundness of these functions
- Added a `dispatch_indirect` command to `AutoCommandBufferBuilder`.
# Version 0.21.0 (2021-03-05)

View File

@ -108,7 +108,7 @@ impl<T> CpuAccessibleBuffer<T> {
data: T,
) -> Result<Arc<CpuAccessibleBuffer<T>>, DeviceMemoryAllocError>
where
T: Content + 'static,
T: Content + Copy + 'static,
{
unsafe {
let uninitialized = CpuAccessibleBuffer::raw(
@ -661,6 +661,7 @@ mod tests {
const EMPTY: [i32; 0] = [];
let _ = CpuAccessibleBuffer::from_data(device, BufferUsage::all(), false, EMPTY.iter());
let _ = CpuAccessibleBuffer::from_data(device.clone(), BufferUsage::all(), false, EMPTY);
let _ = CpuAccessibleBuffer::from_iter(device, BufferUsage::all(), false, EMPTY.iter());
}
}

View File

@ -97,7 +97,7 @@ impl<T: ?Sized> ImmutableBuffer<T> {
queue: Arc<Queue>,
) -> Result<(Arc<ImmutableBuffer<T>>, ImmutableBufferFromBufferFuture), DeviceMemoryAllocError>
where
T: 'static + Send + Sync + Sized,
T: 'static + Copy + Send + Sync + Sized,
{
let source = CpuAccessibleBuffer::from_data(
queue.device().clone(),

View File

@ -368,13 +368,9 @@ mod tests {
let (device, queue) = gfx_dev_and_queue!();
const EMPTY: [i32; 0] = [];
let buf = CpuAccessibleBuffer::from_data(
device,
BufferUsage::vertex_buffer(),
false,
EMPTY.iter(),
)
.unwrap();
let buf =
CpuAccessibleBuffer::from_data(device, BufferUsage::vertex_buffer(), false, EMPTY)
.unwrap();
let mut cacher = StateCacher::new();
@ -396,13 +392,9 @@ mod tests {
let (device, queue) = gfx_dev_and_queue!();
const EMPTY: [i32; 0] = [];
let buf = CpuAccessibleBuffer::from_data(
device,
BufferUsage::vertex_buffer(),
false,
EMPTY.iter(),
)
.unwrap();
let buf =
CpuAccessibleBuffer::from_data(device, BufferUsage::vertex_buffer(), false, EMPTY)
.unwrap();
let mut cacher = StateCacher::new();
@ -436,23 +428,19 @@ mod tests {
device.clone(),
BufferUsage::vertex_buffer(),
false,
EMPTY.iter(),
EMPTY,
)
.unwrap();
let buf2 = CpuAccessibleBuffer::from_data(
device.clone(),
BufferUsage::vertex_buffer(),
false,
EMPTY.iter(),
)
.unwrap();
let buf3 = CpuAccessibleBuffer::from_data(
device,
BufferUsage::vertex_buffer(),
false,
EMPTY.iter(),
EMPTY,
)
.unwrap();
let buf3 =
CpuAccessibleBuffer::from_data(device, BufferUsage::vertex_buffer(), false, EMPTY)
.unwrap();
let mut cacher = StateCacher::new();