mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Make the command_encoder_clear_buffer's size an Option<BufferAddress> (#4737)
* Make the size parameter of command_encoder_clear_buffer an Option<BufferAddress> * Add a changelog entry
This commit is contained in:
parent
dec907a771
commit
7dad106039
@ -74,6 +74,7 @@ By @gents83 in [#3626](https://github.com/gfx-rs/wgpu/pull/3626) and tnx also to
|
||||
- Log vulkan validation layer messages during instance creation and destruction: By @exrook in [#4586](https://github.com/gfx-rs/wgpu/pull/4586)
|
||||
- `TextureFormat::block_size` is deprecated, use `TextureFormat::block_copy_size` instead: By @wumpf in [#4647](https://github.com/gfx-rs/wgpu/pull/4647)
|
||||
- Rename of `DispatchIndirect`, `DrawIndexedIndirect`, and `DrawIndirect` types in the `wgpu::util` module to `DispatchIndirectArgs`, `DrawIndexedIndirectArgs`, and `DrawIndirectArgs`. By @cwfitzgerald in [#4723](https://github.com/gfx-rs/wgpu/pull/4723).
|
||||
- Make the size parameter of `encoder.clear_buffer` an `Option<u64>` instead of `Option<NonZero<u64>>`. By @nical in [#4737](https://github.com/gfx-rs/wgpu/pull/4737)
|
||||
|
||||
#### Safe `Surface` creation
|
||||
|
||||
|
||||
@ -475,7 +475,7 @@ pub fn op_webgpu_command_encoder_clear_buffer(
|
||||
command_encoder,
|
||||
destination_resource.1,
|
||||
offset,
|
||||
std::num::NonZeroU64::new(size)
|
||||
Some(size)
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::{num::NonZeroU64, ops::Range};
|
||||
use std::ops::Range;
|
||||
|
||||
use wgpu_test::{gpu_test, GpuTestConfiguration, TestingContext};
|
||||
|
||||
@ -27,11 +27,7 @@ fn fill_test(ctx: &TestingContext, range: Range<u64>, size: u64) -> bool {
|
||||
label: Some("encoder"),
|
||||
});
|
||||
|
||||
encoder.clear_buffer(
|
||||
&gpu_buffer,
|
||||
range.start,
|
||||
NonZeroU64::new(range.end - range.start),
|
||||
);
|
||||
encoder.clear_buffer(&gpu_buffer, range.start, Some(range.end - range.start));
|
||||
encoder.copy_buffer_to_buffer(&gpu_buffer, 0, &cpu_buffer, 0, size);
|
||||
|
||||
ctx.queue.submit(Some(encoder.finish()));
|
||||
|
||||
@ -16,9 +16,7 @@ use crate::{
|
||||
|
||||
use hal::CommandEncoder as _;
|
||||
use thiserror::Error;
|
||||
use wgt::{
|
||||
math::align_to, BufferAddress, BufferSize, BufferUsages, ImageSubresourceRange, TextureAspect,
|
||||
};
|
||||
use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect};
|
||||
|
||||
/// Error encountered while attempting a clear.
|
||||
#[derive(Clone, Debug, Error)]
|
||||
@ -37,7 +35,7 @@ pub enum ClearError {
|
||||
#[error("Texture {0:?} can not be cleared")]
|
||||
NoValidTextureClearMode(TextureId),
|
||||
#[error("Buffer clear size {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")]
|
||||
UnalignedFillSize(BufferSize),
|
||||
UnalignedFillSize(BufferAddress),
|
||||
#[error("Buffer offset {0:?} is not a multiple of `COPY_BUFFER_ALIGNMENT`")]
|
||||
UnalignedBufferOffset(BufferAddress),
|
||||
#[error("Clear of {start_offset}..{end_offset} would end up overrunning the bounds of the buffer of size {buffer_size}")]
|
||||
@ -75,7 +73,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
command_encoder_id: CommandEncoderId,
|
||||
dst: BufferId,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
size: Option<BufferAddress>,
|
||||
) -> Result<(), ClearError> {
|
||||
profiling::scope!("CommandEncoder::clear_buffer");
|
||||
log::trace!("CommandEncoder::clear_buffer {dst:?}");
|
||||
@ -116,10 +114,10 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
return Err(ClearError::UnalignedBufferOffset(offset));
|
||||
}
|
||||
if let Some(size) = size {
|
||||
if size.get() % wgt::COPY_BUFFER_ALIGNMENT != 0 {
|
||||
if size % wgt::COPY_BUFFER_ALIGNMENT != 0 {
|
||||
return Err(ClearError::UnalignedFillSize(size));
|
||||
}
|
||||
let destination_end_offset = offset + size.get();
|
||||
let destination_end_offset = offset + size;
|
||||
if destination_end_offset > dst_buffer.size {
|
||||
return Err(ClearError::BufferOverrun {
|
||||
start_offset: offset,
|
||||
@ -130,7 +128,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
}
|
||||
|
||||
let end = match size {
|
||||
Some(size) => offset + size.get(),
|
||||
Some(size) => offset + size,
|
||||
None => dst_buffer.size,
|
||||
};
|
||||
if offset == end {
|
||||
|
||||
@ -154,7 +154,7 @@ pub enum Command {
|
||||
ClearBuffer {
|
||||
dst: id::BufferId,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
size: Option<wgt::BufferAddress>,
|
||||
},
|
||||
ClearTexture {
|
||||
dst: id::TextureId,
|
||||
|
||||
@ -2059,7 +2059,7 @@ impl crate::Context for Context {
|
||||
encoder_data: &Self::CommandEncoderData,
|
||||
buffer: &crate::Buffer,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
size: Option<wgt::BufferAddress>,
|
||||
) {
|
||||
let global = &self.0;
|
||||
if let Err(cause) = wgc::gfx_select!(encoder => global.command_encoder_clear_buffer(
|
||||
|
||||
@ -2446,15 +2446,15 @@ impl crate::context::Context for Context {
|
||||
encoder_data: &Self::CommandEncoderData,
|
||||
buffer: &crate::Buffer,
|
||||
offset: wgt::BufferAddress,
|
||||
size: Option<wgt::BufferSize>,
|
||||
size: Option<wgt::BufferAddress>,
|
||||
) {
|
||||
let buffer: &<Context as crate::Context>::BufferData = downcast_ref(buffer.data.as_ref());
|
||||
match size {
|
||||
Some(size) => encoder_data.0.clear_buffer_with_f64_and_f64(
|
||||
&buffer.0,
|
||||
offset as f64,
|
||||
size.get() as f64,
|
||||
),
|
||||
Some(size) => {
|
||||
encoder_data
|
||||
.0
|
||||
.clear_buffer_with_f64_and_f64(&buffer.0, offset as f64, size as f64)
|
||||
}
|
||||
None => encoder_data
|
||||
.0
|
||||
.clear_buffer_with_f64(&buffer.0, offset as f64),
|
||||
|
||||
@ -494,7 +494,7 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
|
||||
encoder_data: &Self::CommandEncoderData,
|
||||
buffer: &Buffer,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
size: Option<BufferAddress>,
|
||||
);
|
||||
|
||||
fn command_encoder_insert_debug_marker(
|
||||
@ -1570,7 +1570,7 @@ pub(crate) trait DynContext: Debug + WasmNotSendSync {
|
||||
encoder_data: &crate::Data,
|
||||
buffer: &Buffer,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
size: Option<BufferAddress>,
|
||||
);
|
||||
|
||||
fn command_encoder_insert_debug_marker(
|
||||
@ -2914,7 +2914,7 @@ where
|
||||
encoder_data: &crate::Data,
|
||||
buffer: &Buffer,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
size: Option<BufferAddress>,
|
||||
) {
|
||||
let encoder = <T::CommandEncoderId>::from(*encoder);
|
||||
let encoder_data = downcast_ref(encoder_data);
|
||||
|
||||
@ -3643,7 +3643,7 @@ impl CommandEncoder {
|
||||
&mut self,
|
||||
buffer: &Buffer,
|
||||
offset: BufferAddress,
|
||||
size: Option<BufferSize>,
|
||||
size: Option<BufferAddress>,
|
||||
) {
|
||||
DynContext::command_encoder_clear_buffer(
|
||||
&*self.context,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user