Просмотр исходного кода

WebGPUAttributeUtils: fix updateAttribute() when using range (#29966) (#29967)

* WebGPUAttributeUtils: fix updateAttribute() when using range (#29966)

* WebGPUAttributeUtils: handle ArrayBuffer and DataView

---------

Co-authored-by: Niklas Niehus <nni@demodern.de>
Co-authored-by: Renaud Rohlinger <renaud.rohlinger@gmail.com>
holtsetio 1 год назад
Родитель
Сommit
a0a25ea032
1 измененных файлов с 15 добавлено и 2 удалено
  1. 15 2
      src/renderers/webgpu/utils/WebGPUAttributeUtils.js

+ 15 - 2
src/renderers/webgpu/utils/WebGPUAttributeUtils.js

@@ -108,6 +108,7 @@ class WebGPUAttributeUtils {
 		const buffer = backend.get( bufferAttribute ).buffer;
 
 		const array = bufferAttribute.array;
+		const isTypedArray = this._isTypedArray( array );
 		const updateRanges = bufferAttribute.updateRanges;
 
 		if ( updateRanges.length === 0 ) {
@@ -123,15 +124,21 @@ class WebGPUAttributeUtils {
 
 		} else {
 
+			const byteOffsetFactor = isTypedArray ? 1 : array.BYTES_PER_ELEMENT;
+
 			for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
 
 				const range = updateRanges[ i ];
+
+				const dataOffset = range.start * byteOffsetFactor;
+				const size = range.count * byteOffsetFactor;
+
 				device.queue.writeBuffer(
 					buffer,
 					0,
 					array,
-					range.start * array.BYTES_PER_ELEMENT,
-					range.count * array.BYTES_PER_ELEMENT
+					dataOffset,
+					size
 				);
 
 			}
@@ -299,6 +306,12 @@ class WebGPUAttributeUtils {
 
 	}
 
+	_isTypedArray( array ) {
+
+		return ArrayBuffer.isView( array ) && ! ( array instanceof DataView );
+
+	}
+
 	_getBufferAttribute( attribute ) {
 
 		if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;

粤ICP备19079148号