Skip to content

Commit 32c73af

Browse files
authored
A few small tweaks (#118)
* A few minor fixes * improve some docstrings related to buffer io * fix tests * revert change Co-authored-by: Almar Klein <[email protected]>
1 parent dac017f commit 32c73af

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

tests/test_api.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ def test_base_wgpu_api():
6868

6969
# Fake a device and an adapter
7070
adapter = wgpu.base.GPUAdapter("adapter07", [])
71-
device = wgpu.base.GPUDevice("device08", -1, adapter, [42, 43], {}, None)
71+
queue = wgpu.GPUQueue("", None, None)
72+
device = wgpu.base.GPUDevice("device08", -1, adapter, [42, 43], {}, queue)
73+
74+
assert queue._device is device
7275

7376
assert adapter.name == "adapter07"
7477
assert adapter.extensions == ()

wgpu/backends/rs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def _request_device(self, label, extensions, limits, trace_path):
547547

548548
# Get the queue to which commands can be submitted
549549
queue_id = _lib.wgpu_device_get_default_queue(device_id)
550-
queue = GPUQueue("", queue_id, self)
550+
queue = GPUQueue("", queue_id, None)
551551

552552
return GPUDevice(label, device_id, self, extensions, limits3, queue)
553553

@@ -1206,7 +1206,7 @@ def create_view(
12061206
label=c_label,
12071207
format=format,
12081208
dimension=dimension,
1209-
aspect=aspect,
1209+
aspect=aspect or "all",
12101210
base_mip_level=base_mip_level,
12111211
level_count=mip_level_count,
12121212
base_array_layer=base_array_layer,
@@ -1736,7 +1736,7 @@ def write_buffer(self, buffer, buffer_offset, data, data_offset=0, size=None):
17361736
def write_texture(self, destination, data, data_layout, size):
17371737

17381738
m, address = _get_memoryview_and_address(data)
1739-
# todo: could we not derive the size from trhe shape of m?
1739+
# todo: could we not derive the size from the shape of m?
17401740

17411741
# Checks
17421742
if not m.contiguous: # no-cover

wgpu/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def __init__(self, label, internal, adapter, extensions, limits, default_queue):
171171
self._extensions = tuple(sorted([str(x) for x in extensions]))
172172
self._limits = limits.copy()
173173
self._default_queue = default_queue
174+
default_queue._device = self # because it could not be set earlier
174175

175176
@property
176177
def extensions(self):
@@ -702,6 +703,7 @@ def read_data(self, offset=0, size=0):
702703
""" Read buffer data. Returns the mapped memory as a memoryview,
703704
which can be mapped to e.g. a ctypes array or numpy array.
704705
If size is zero, the remaining size (after offset) is used.
706+
The buffer usage must include MAP_READ.
705707
"""
706708
raise NotImplementedError()
707709

@@ -711,7 +713,10 @@ async def read_data_async(self, offset=0, size=0):
711713

712714
def write_data(self, data, offset=0):
713715
""" Write data to the buffer. The data can be any object
714-
supporting the buffer protocol.
716+
supporting the buffer protocol. The buffer usage must include MAP_WRITE.
717+
718+
Note: this method deviates from the WebGPU spec, and it could be deprecated.
719+
Better use ``device.create_buffer_with_data()`` or ``queue.write_buffer()``.
715720
"""
716721
raise NotImplementedError()
717722

@@ -1441,7 +1446,7 @@ def write_buffer(self, buffer, buffer_offset, data, data_offset=0, size=None):
14411446
Arguments:
14421447
buffer: The :class:`GPUBuffer` object to write to.
14431448
buffer_offset (int): The offset in the buffer to start writing at.
1444-
data: The data to write.
1449+
data: The data to write. Must be contiguous.
14451450
data_offset: The byte offset in the data. Default 0.
14461451
size: The number of bytes to write. Default all minus offset.
14471452
"""

0 commit comments

Comments
 (0)