@@ -500,81 +500,70 @@ impl BufferBuilder {
500500mod tests {
501501 use super :: * ;
502502
503- /// Rejects constructing a buffer with a logical length of zero elements.
503+ /// Rejects CPU-side writes for buffers not created with
504+ /// `Properties::CPU_VISIBLE` (prevents wgpu validation panics).
504505 #[ test]
505- // Ensures callers get a clear engine-level error instead of a wgpu
506- // validation panic when attempting CPU writes to a device-local buffer.
507506 fn validate_cpu_write_supported_rejects_non_cpu_visible ( ) {
508507 let result = validate_cpu_write_supported ( false ) ;
509508 assert ! ( result. is_err( ) ) ;
510509 }
511510
511+ /// Accepts CPU-side writes for buffers created with `Properties::CPU_VISIBLE`.
512512 #[ test]
513- // Verifies CPU-visible buffers are accepted for `write_*` operations.
514513 fn validate_cpu_write_supported_accepts_cpu_visible ( ) {
515514 let result = validate_cpu_write_supported ( true ) ;
516515 assert ! ( result. is_ok( ) ) ;
517516 }
518517
518+ /// Confirms `Properties::default()` is `DEVICE_LOCAL` (not CPU-visible).
519519 #[ test]
520- // Confirms `Properties::default()` is now device-local to avoid placing
521- // static buffers in CPU-visible memory by accident.
522520 fn properties_default_is_device_local ( ) {
523521 assert ! ( !Properties :: default ( ) . cpu_visible( ) ) ;
524522 }
525523
524+ /// Confirms `BufferBuilder::new()` inherits the default properties.
526525 #[ test]
527- // Confirms `BufferBuilder::new()` inherits the default properties so buffer
528- // residency matches `Properties::default()`.
529526 fn buffer_builder_defaults_to_device_local_properties ( ) {
530527 let builder = BufferBuilder :: new ( ) ;
531528 assert ! ( !builder. properties. cpu_visible( ) ) ;
532529 }
533530
531+ /// Validates that size resolution rejects creating a zero-length buffer.
534532 #[ test]
535- // Validates that zero-length buffers are rejected even when size is inferred
536- // from the provided data.
537533 fn resolve_length_rejects_zero ( ) {
538534 let builder = BufferBuilder :: new ( ) ;
539535 let result = builder. resolve_length ( std:: mem:: size_of :: < u32 > ( ) , 0 ) ;
540536 assert ! ( result. is_err( ) ) ;
541537 }
542538
543- /// Ensures builder labels are stored for later propagation/debugging .
539+ /// Ensures `with_label` stores the label on the builder .
544540 #[ test]
545- // Verifies `with_label` stores the label on the builder so it can be applied
546- // to the underlying platform buffer for debugging/profiling.
547541 fn label_is_recorded_on_builder ( ) {
548542 let builder = BufferBuilder :: new ( ) . with_label ( "buffer-test" ) ;
549543 // Indirect check: validate the internal label is stored on the builder.
550544 // Test module is a child of this module and can access private fields.
551545 assert_eq ! ( builder. label. as_deref( ) , Some ( "buffer-test" ) ) ;
552546 }
553547
554- /// Rejects length computations that would overflow `usize`.
548+ /// Rejects length computations that would overflow `usize` when converting
549+ /// element counts/sizes to byte sizes.
555550 #[ test]
556- // Ensures buffer size math guards against integer overflow when resolving
557- // byte lengths from element size and element count.
558551 fn resolve_length_rejects_overflow ( ) {
559552 let builder = BufferBuilder :: new ( ) ;
560553 let result = builder. resolve_length ( usize:: MAX , 2 ) ;
561554 assert ! ( result. is_err( ) ) ;
562555 }
563556
564- /// Confirms `value_as_bytes` uses native-endian byte order and size .
557+ /// Confirms `value_as_bytes` matches the native byte representation .
565558 #[ test]
566- // Confirms `value_as_bytes` produces the same byte representation as the
567- // native `to_ne_bytes` conversion for POD values.
568559 fn value_as_bytes_matches_native_bytes ( ) {
569560 let value: u32 = 0x1122_3344 ;
570561 let expected = value. to_ne_bytes ( ) ;
571562 assert_eq ! ( value_as_bytes( & value) , expected. as_slice( ) ) ;
572563 }
573564
574- /// Confirms `slice_as_bytes` flattens a typed slice to the native bytes.
565+ /// Confirms `slice_as_bytes` matches the expected concatenated native bytes.
575566 #[ test]
576- // Confirms `slice_as_bytes` produces the same byte layout as concatenating
577- // each element's native-endian bytes in order.
578567 fn slice_as_bytes_matches_native_bytes ( ) {
579568 let values: [ u16 ; 3 ] = [ 0x1122 , 0x3344 , 0x5566 ] ;
580569 let mut expected: Vec < u8 > = Vec :: new ( ) ;
@@ -586,16 +575,13 @@ mod tests {
586575
587576 /// Ensures converting an empty slice to bytes yields an empty output slice.
588577 #[ test]
589- // Ensures the empty slice case works and does not error or return junk data.
590578 fn slice_as_bytes_empty_is_empty ( ) {
591579 let values: [ u32 ; 0 ] = [ ] ;
592580 assert_eq ! ( slice_as_bytes( & values) . unwrap( ) , & [ ] ) ;
593581 }
594582
595583 /// Rejects byte length computations that would overflow `usize`.
596584 #[ test]
597- // Ensures the shared byte-length helper rejects overflows rather than
598- // silently wrapping and producing undersized buffers/slices.
599585 fn checked_byte_len_rejects_overflow ( ) {
600586 let result = checked_byte_len ( usize:: MAX , 2 ) ;
601587 assert ! ( result. is_err( ) ) ;
@@ -611,7 +597,7 @@ mod tests {
611597 let combined = Usage :: VERTEX | Usage :: INDEX ;
612598 let _ = combined. to_platform ( ) ;
613599
614- assert ! ( Properties :: default ( ) . cpu_visible( ) ) ;
600+ assert ! ( ! Properties :: default ( ) . cpu_visible( ) ) ;
615601 assert ! ( !Properties :: DEVICE_LOCAL . cpu_visible( ) ) ;
616602 }
617603
0 commit comments