Skip to content

Commit 7fe0672

Browse files
refactor: satisfy clippy::manual_is_multiple_of for transfer alignment checks
1 parent 6c0f5ec commit 7fe0672

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

wgpu-core/src/command/transfer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,10 @@ pub(crate) fn validate_linear_texture_data(
318318
bytes_in_copy,
319319
} = layout.get_buffer_texture_copy_info(format, aspect, copy_size)?;
320320

321-
if copy_width % block_width_texels != 0 {
321+
if !copy_width.is_multiple_of(block_width_texels) {
322322
return Err(TransferError::UnalignedCopyWidth);
323323
}
324-
if copy_height % block_height_texels != 0 {
324+
if !copy_height.is_multiple_of(block_height_texels) {
325325
return Err(TransferError::UnalignedCopyHeight);
326326
}
327327

@@ -986,7 +986,7 @@ pub(super) fn copy_buffer_to_buffer(
986986
None => (src_buffer.size - source_offset, src_buffer.size),
987987
};
988988

989-
if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
989+
if !size.is_multiple_of(wgt::COPY_BUFFER_ALIGNMENT) {
990990
return Err(TransferError::UnalignedCopySize(size).into());
991991
}
992992
if !source_offset.is_multiple_of(wgt::COPY_BUFFER_ALIGNMENT) {

wgpu-core/src/resource.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,15 @@ impl Buffer {
588588
if !offset.is_multiple_of(wgt::MAP_ALIGNMENT) {
589589
return Err((op, BufferAccessError::UnalignedOffset { offset }));
590590
}
591-
if range_size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
591+
if !range_size.is_multiple_of(wgt::COPY_BUFFER_ALIGNMENT) {
592592
return Err((op, BufferAccessError::UnalignedRangeSize { range_size }));
593593
}
594594

595595
let range = offset..(offset + range_size);
596596

597-
if range.start % wgt::MAP_ALIGNMENT != 0 || range.end % wgt::COPY_BUFFER_ALIGNMENT != 0 {
597+
if !range.start.is_multiple_of(wgt::MAP_ALIGNMENT)
598+
|| !range.end.is_multiple_of(wgt::COPY_BUFFER_ALIGNMENT)
599+
{
598600
return Err((op, BufferAccessError::UnalignedRange));
599601
}
600602

@@ -696,7 +698,7 @@ impl Buffer {
696698
if !offset.is_multiple_of(wgt::MAP_ALIGNMENT) {
697699
return Err(BufferAccessError::UnalignedOffset { offset });
698700
}
699-
if range_size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
701+
if range_size.is_multiple_of(wgt::COPY_BUFFER_ALIGNMENT) {
700702
return Err(BufferAccessError::UnalignedRangeSize { range_size });
701703
}
702704
let map_state = &*self.map_state.lock();

0 commit comments

Comments
 (0)