Skip to content

Commit 4e95cde

Browse files
committed
Padding in buffer_from_array to ensure size is multiple of 4
1 parent 5bfb73c commit 4e95cde

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

webgpu/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,13 @@ def texture_from_data(width, height, data, format, label=""):
447447

448448
def buffer_from_array(array, usage=BufferUsage.STORAGE, label="from_array") -> Buffer:
449449
device = get_device()
450-
buffer = device.createBuffer(
451-
array.size * array.itemsize, usage=usage | BufferUsage.COPY_DST, label=label
452-
)
450+
453451
data = array.tobytes()
452+
if len(data) % 4:
453+
data = data + b"\x00" * (4 - len(data) % 4) # pad to 4 bytes
454+
455+
buffer = device.createBuffer(len(data), usage=usage | BufferUsage.COPY_DST, label=label)
456+
454457
chunk_size = 99 * 1024**2
455458
if len(data) > chunk_size:
456459
for i in range(0, len(data), chunk_size):

0 commit comments

Comments
 (0)