Jelajahi Sumber

WebGPUAttributeUtils: Fix i16a/u16a patch (#30264)

* fix

* Update WebGPUAttributeUtils.js

Add comment.

---------

Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
ycw 1 tahun lalu
induk
melakukan
3212be4f20
1 mengubah file dengan 17 tambahan dan 6 penghapusan
  1. 17 6
      src/renderers/webgpu/utils/WebGPUAttributeUtils.js

+ 17 - 6
src/renderers/webgpu/utils/WebGPUAttributeUtils.js

@@ -69,16 +69,27 @@ class WebGPUAttributeUtils {
 			let array = bufferAttribute.array;
 
 			// patch for INT16 and UINT16
-			if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) {
+			if ( attribute.normalized === false ) {
 
-				const tempArray = new Uint32Array( array.length );
-				for ( let i = 0; i < array.length; i ++ ) {
+				if ( array.constructor === Int16Array ) {
 
-					tempArray[ i ] = array[ i ];
+					array = new Int32Array( array );
 
-				}
+				} else if ( array.constructor === Uint16Array ) {
+
+					array = new Uint32Array( array );
+
+					if ( usage & GPUBufferUsage.INDEX ) {
+
+						for ( let i = 0; i < array.length; i ++ ) {
 
-				array = tempArray;
+							if ( array[ i ] === 0xffff ) array[ i ] = 0xffffffff; // use correct primitive restart index
+
+						}
+
+					}
+
+				}
 
 			}
 

粤ICP备19079148号