mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
[rs] Fix excessive buffer padding (#795)
* Fix excessive buffer padding * Prettify * cargo fmt * Simplify code * Style
This commit is contained in:
parent
2bda1508f1
commit
aa45e7668b
@ -37,8 +37,12 @@ pub trait DeviceExt {
|
|||||||
impl DeviceExt for crate::Device {
|
impl DeviceExt for crate::Device {
|
||||||
fn create_buffer_init(&self, descriptor: &BufferInitDescriptor<'_>) -> crate::Buffer {
|
fn create_buffer_init(&self, descriptor: &BufferInitDescriptor<'_>) -> crate::Buffer {
|
||||||
let unpadded_size = descriptor.contents.len() as crate::BufferAddress;
|
let unpadded_size = descriptor.contents.len() as crate::BufferAddress;
|
||||||
let padding = crate::COPY_BUFFER_ALIGNMENT - unpadded_size % crate::COPY_BUFFER_ALIGNMENT;
|
// Valid vulkan usage is
|
||||||
let padded_size = padding + unpadded_size;
|
// 1. buffer size must be a multiple of COPY_BUFFER_ALIGNMENT.
|
||||||
|
// 2. buffer size must be greater than 0.
|
||||||
|
// Therefore we round the value up to the nearest multiple, and ensure it's at least COPY_BUFFER_ALIGNMENT.
|
||||||
|
let align_mask = crate::COPY_BUFFER_ALIGNMENT - 1;
|
||||||
|
let padded_size = ((unpadded_size + align_mask) & !align_mask).max(crate::COPY_BUFFER_ALIGNMENT);
|
||||||
|
|
||||||
let wgt_descriptor = crate::BufferDescriptor {
|
let wgt_descriptor = crate::BufferDescriptor {
|
||||||
label: descriptor.label,
|
label: descriptor.label,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user