Skip to content

Commit

Permalink
Buffer mapping API (#377)
Browse files Browse the repository at this point in the history
* I tried many ways, thought I found one, but did not.

* Remove test file again

* New buffer mapping API

* Allow read_mapped to return mapped data without making a copy

* also release memviews on buffer destroy

* Fix current tests

* more buffer tests, fix buffer read issue

* More tests and fixes

* Tests and fixes for copyless buffer reads

* codegen

* 3.7 compat

* Add changelog

* fix
  • Loading branch information
almarklein authored Oct 17, 2023
1 parent 2ffacd9 commit d7b17e2
Show file tree
Hide file tree
Showing 6 changed files with 676 additions and 161 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,33 @@ Changed:
* Update to wgpu-native 0.17.2.1. No changes are needed in downstream code.


### [v0.11.0] - t.b.d.

We have revised the buffer mapping API, making it more similar to the
WebGPU spec, and providing more flexible and performant ways to set
buffer data.

Added:

* The `GPUBuffer` has new methods `map()`, `map_async()`, `unmap()`. These have been
part of the WebGPU spec for a long time, but we had an alternative API, until now.
* The `GPUBuffer` has new methods `read_mapped()` and `write_mapped()`. These are not
present in the WebGPU spec; they are the Pythonic alternative to `getMappedRange()`.

Changed:

* Can create a buffer that is initially mapped: `device.create_buffer(..., mapped_at_creation=True)` is enabled again.

Removed:

* The `GPUBuffer` methods `map_read()`and `map_write()` are deprecated, in favor of `map()`, `unmap()`, `read_mapped()` and `write_mapped()`.

For the record, these are not changed:

* The convenient `device.create_buffer_with_data()` (not part of the WebGPU spec) is also available.
* The `GPUQueue.read_buffer()` and `GPUQueue.write_buffer()` methods are unchanged.


### [v0.10.0] - 09-10-2023

In this release the API is aligned with the latest webgpu.idl, and
Expand Down
4 changes: 4 additions & 0 deletions codegen/apipatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ def get_method_def(self, classname, methodname):
name_idl = self.name2idl(methodname)
if methodname.endswith("_async") and name_idl not in functions:
name_idl = self.name2idl(methodname.replace("_async", ""))
elif name_idl not in functions and name_idl + "Async" in functions:
name_idl += "Async"
idl_line = functions[name_idl]

# Construct preamble
Expand Down Expand Up @@ -369,6 +371,8 @@ def method_is_known(self, classname, methodname):
name_idl = self.name2idl(methodname)
if "_async" in methodname and name_idl not in functions:
name_idl = self.name2idl(methodname.replace("_async", ""))
elif name_idl not in functions and name_idl + "Async" in functions:
name_idl += "Async"
return name_idl if name_idl in functions else None

def get_class_names(self):
Expand Down
Loading

0 comments on commit d7b17e2

Please sign in to comment.