Skip to content

Commit d8d5879

Browse files
committed
more comments about buffer sizes
1 parent 0210857 commit d8d5879

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

wgpu-core/src/device/resource.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,8 @@ impl Device {
12531253
.map_err(|e| self.handle_hal_error_with_nonfatal_oom(e))?;
12541254

12551255
let timestamp_normalization_bind_group = Snatchable::new(unsafe {
1256-
// SAFETY: The size passed here must not overflow the buffer.
1256+
// SAFETY: The size passed here must be 4B aligned, >= the application size, and
1257+
// <= the buffer size.
12571258
self.timestamp_normalizer
12581259
.get()
12591260
.unwrap()
@@ -1592,7 +1593,8 @@ impl Device {
15921593
/// # Safety
15931594
///
15941595
/// - `hal_buffer` must have been created on this device.
1595-
/// - `hal_buffer` must have been created respecting `desc` (in particular, the size).
1596+
/// - `hal_buffer` must have been created respecting `desc` (in particular, the size,
1597+
/// which must always be a multiple of 4, and may be subject to other requirements).
15961598
/// - `hal_buffer` must be initialized.
15971599
/// - `hal_buffer` must not have zero size.
15981600
pub(crate) unsafe fn create_buffer_from_hal_inner(
@@ -1601,6 +1603,8 @@ impl Device {
16011603
desc: &resource::BufferDescriptor,
16021604
) -> Result<Arc<Buffer>, resource::CreateBufferError> {
16031605
let timestamp_normalization_bind_group = Snatchable::new(unsafe {
1606+
// SAFETY: The size passed here must be 4B aligned, >= the application size, and
1607+
// <= the buffer size.
16041608
self.timestamp_normalizer
16051609
.get()
16061610
.unwrap()
@@ -1650,6 +1654,10 @@ impl Device {
16501654
Ok(buffer)
16511655
}
16521656

1657+
/// If needed, creates the bind groups for indirect validation shaders to read
1658+
/// from `raw_buffer`.
1659+
///
1660+
/// `buffer_size` is the user-requested size of the buffer.
16531661
fn create_indirect_validation_bind_groups(
16541662
&self,
16551663
raw_buffer: &dyn hal::DynBuffer,

wgpu-core/src/indirect_validation/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ pub(crate) struct BindGroups {
7474
}
7575

7676
impl BindGroups {
77+
/// Creates the bind groups for indirect validation shaders to read from `buffer`.
78+
///
79+
/// `buffer_size` is the user-requested size of the buffer.
80+
///
7781
/// `Ok(None)` will only be returned if `buffer_size` is `0`.
7882
pub(crate) fn new(
7983
indirect_validation: &IndirectValidation,

wgpu-core/src/timestamp_normalization/mod.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,16 @@ impl TimestampNormalizer {
253253

254254
/// Create a bind group for normalizing timestamps in `buffer`.
255255
///
256-
/// This function is unsafe because it does not know that `buffer_size` is
257-
/// the true size of the buffer.
256+
/// `buffer_size` must be 4B-aligned, so that it is valid as a storage binding,
257+
/// must be the same or more than the application-visible buffer size, and must
258+
/// not overrun the buffer. This function is unsafe because it does not know and
259+
/// cannot check whether `buffer_size` meets these requirements.
260+
///
261+
/// The buffer size passed here is used to construct a binding that must be
262+
/// able to access the full application-visible range of the buffer. It is
263+
/// not used to check the destination range of query resolution requests. That
264+
/// uses the application-requested buffer size, obtained from the `wgpu_core`
265+
/// `Buffer`.
258266
pub unsafe fn create_normalization_bind_group(
259267
&self,
260268
device: &Device,

0 commit comments

Comments
 (0)