Class: WGPU::BufferMappedRange
- Inherits:
-
Object
- Object
- WGPU::BufferMappedRange
- Defined in:
- lib/wgpu/resources/buffer.rb,
sig/wgpu.rbs
Instance Method Summary collapse
-
#initialize(pointer, size, buffer:, generation:) ⇒ BufferMappedRange
constructor
Wraps a native mapped memory range.
-
#read(type: :f32, count: nil) ⇒ Array
Decodes typed values from the mapped range.
-
#read_bytes ⇒ String
Returns all bytes in the mapped range.
-
#read_float64s(count = nil) ⇒ Array<Float>
Reads 64-bit floating-point values from the mapped range.
-
#read_floats(count = nil) ⇒ Array<Float>
Reads 32-bit floating-point values from the mapped range.
-
#read_int32s(count = nil) ⇒ Array<Integer>
Reads signed 32-bit integers from the mapped range.
-
#read_uint16s(count = nil) ⇒ Array<Integer>
Reads unsigned 16-bit integers from the mapped range.
-
#read_uint32s(count = nil) ⇒ Array<Integer>
Reads unsigned 32-bit integers from the mapped range.
-
#read_uint8s(count = nil) ⇒ Array<Integer>
Reads unsigned 8-bit integers from the mapped range.
-
#write(data, type: :f32) ⇒ void
Encodes typed values into the mapped range.
-
#write_bytes(data) ⇒ void
Writes bytes at the start of the mapped range.
-
#write_float64s(data) ⇒ void
Writes 64-bit floating-point values into the mapped range.
-
#write_floats(data) ⇒ void
Writes 32-bit floating-point values into the mapped range.
-
#write_int32s(data) ⇒ void
Writes signed 32-bit integers into the mapped range.
-
#write_uint16s(data) ⇒ void
Writes unsigned 16-bit integers into the mapped range.
-
#write_uint32s(data) ⇒ void
Writes unsigned 32-bit integers into the mapped range.
-
#write_uint8s(data) ⇒ void
Writes unsigned 8-bit integers into the mapped range.
Constructor Details
#initialize(pointer, size, buffer:, generation:) ⇒ BufferMappedRange
Wraps a native mapped memory range.
420 421 422 423 424 425 |
# File 'lib/wgpu/resources/buffer.rb', line 420 def initialize(pointer, size, buffer:, generation:) @pointer = pointer @size = size @buffer = buffer @generation = generation end |
Instance Method Details
#read(type: :f32, count: nil) ⇒ Array
Decodes typed values from the mapped range.
533 534 535 536 537 538 539 540 541 542 |
# File 'lib/wgpu/resources/buffer.rb', line 533 def read(type: :f32, count: nil) byte_size = DataTypes.byte_size(type) count ||= @size / byte_size count = Integer(count) raise ArgumentError, "count must be non-negative" if count.negative? bytes_to_read = count * byte_size validate_byte_length!(bytes_to_read) DataTypes.unpack(with_valid_mapping { @pointer.read_bytes(bytes_to_read) }, type:) end |
#read_bytes ⇒ String
Returns all bytes in the mapped range.
558 559 560 |
# File 'lib/wgpu/resources/buffer.rb', line 558 def read_bytes with_valid_mapping { @pointer.read_bytes(@size) } end |
#read_float64s(count = nil) ⇒ Array<Float>
Reads 64-bit floating-point values from the mapped range.
482 483 484 |
# File 'lib/wgpu/resources/buffer.rb', line 482 def read_float64s(count = nil) read(type: :f64, count:) end |
#read_floats(count = nil) ⇒ Array<Float>
Reads 32-bit floating-point values from the mapped range.
431 432 433 |
# File 'lib/wgpu/resources/buffer.rb', line 431 def read_floats(count = nil) read(type: :f32, count:) end |
#read_int32s(count = nil) ⇒ Array<Integer>
Reads signed 32-bit integers from the mapped range.
465 466 467 |
# File 'lib/wgpu/resources/buffer.rb', line 465 def read_int32s(count = nil) read(type: :i32, count:) end |
#read_uint16s(count = nil) ⇒ Array<Integer>
Reads unsigned 16-bit integers from the mapped range.
499 500 501 |
# File 'lib/wgpu/resources/buffer.rb', line 499 def read_uint16s(count = nil) read(type: :u16, count:) end |
#read_uint32s(count = nil) ⇒ Array<Integer>
Reads unsigned 32-bit integers from the mapped range.
448 449 450 |
# File 'lib/wgpu/resources/buffer.rb', line 448 def read_uint32s(count = nil) read(type: :u32, count:) end |
#read_uint8s(count = nil) ⇒ Array<Integer>
Reads unsigned 8-bit integers from the mapped range.
516 517 518 |
# File 'lib/wgpu/resources/buffer.rb', line 516 def read_uint8s(count = nil) read(type: :u8, count:) end |
#write(data, type: :f32) ⇒ void
This method returns an undefined value.
Encodes typed values into the mapped range.
549 550 551 552 553 554 |
# File 'lib/wgpu/resources/buffer.rb', line 549 def write(data, type: :f32) bytes = data.is_a?(String) ? data : DataTypes.pack(data, type:) raise ArgumentError, "data exceeds mapped range" if bytes.bytesize > @size with_valid_mapping { @pointer.put_bytes(0, bytes) } end |
#write_bytes(data) ⇒ void
This method returns an undefined value.
Writes bytes at the start of the mapped range.
565 566 567 568 |
# File 'lib/wgpu/resources/buffer.rb', line 565 def write_bytes(data) validate_byte_length!(data.bytesize) with_valid_mapping { @pointer.put_bytes(0, data) } end |
#write_float64s(data) ⇒ void
This method returns an undefined value.
Writes 64-bit floating-point values into the mapped range.
491 492 493 |
# File 'lib/wgpu/resources/buffer.rb', line 491 def write_float64s(data) write(data, type: :f64) end |
#write_floats(data) ⇒ void
This method returns an undefined value.
Writes 32-bit floating-point values into the mapped range.
440 441 442 |
# File 'lib/wgpu/resources/buffer.rb', line 440 def write_floats(data) write(data, type: :f32) end |
#write_int32s(data) ⇒ void
This method returns an undefined value.
Writes signed 32-bit integers into the mapped range.
474 475 476 |
# File 'lib/wgpu/resources/buffer.rb', line 474 def write_int32s(data) write(data, type: :i32) end |
#write_uint16s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 16-bit integers into the mapped range.
508 509 510 |
# File 'lib/wgpu/resources/buffer.rb', line 508 def write_uint16s(data) write(data, type: :u16) end |
#write_uint32s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 32-bit integers into the mapped range.
457 458 459 |
# File 'lib/wgpu/resources/buffer.rb', line 457 def write_uint32s(data) write(data, type: :u32) end |
#write_uint8s(data) ⇒ void
This method returns an undefined value.
Writes unsigned 8-bit integers into the mapped range.
525 526 527 |
# File 'lib/wgpu/resources/buffer.rb', line 525 def write_uint8s(data) write(data, type: :u8) end |