Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/loaders/ObjectLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,17 @@ class ObjectLoader extends Loader {

const text = await loader.loadAsync( url, onProgress );

const json = JSON.parse( text );
let json;

try {

json = JSON.parse( text );

} catch ( e ) {

throw new Error( 'ObjectLoader: Can\'t parse ' + url + '. ' + e.message );

}

const metadata = json.metadata;

Expand Down
6 changes: 2 additions & 4 deletions src/nodes/accessors/InstanceNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,9 @@ class InstanceNode extends Node {

} else {

// WebGPU has a 64kb UBO limit, WebGL 2 ensures only 16KB; fallback to attributes if a certain count is exceeded
const uniformBufferSize = count * 16 * 4; // count * 16 components * 4 bytes (float)

const limit = ( builder.renderer.backend.isWebGPUBackend === true ) ? 1000 : 250;

if ( count <= limit ) {
if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {

instanceMatrixNode = buffer( instanceMatrix.array, 'mat4', Math.max( count, 1 ) ).element( instanceIndex );

Expand Down
11 changes: 11 additions & 0 deletions src/nodes/core/NodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,17 @@ class NodeBuilder {

}

/**
* Returns the maximum number of bytes available for uniform buffers.
*
* @return {number} The maximum number of bytes available for uniform buffers.
*/
getUniformBufferLimit() {

return 16384;

}

/**
* Adds the given node to the internal node chain.
* This is used to check recursive calls in node-graph.
Expand Down
3 changes: 2 additions & 1 deletion src/nodes/geometry/RangeNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ class RangeNode extends Node {
}

const nodeType = this.getNodeType( builder );
const uniformBufferSize = object.count * 4 * 4; // count * 4 components * 4 bytes (float)

if ( object.count <= 4096 ) {
if ( uniformBufferSize <= builder.getUniformBufferLimit() ) {

output = buffer( array, 'vec4', object.count ).element( instanceIndex ).convert( nodeType );

Expand Down
12 changes: 12 additions & 0 deletions src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,18 @@ ${ flowData.code }

}

/**
* Returns the maximum number of bytes available for uniform buffers.
*
* @return {number} The maximum number of bytes available for uniform buffers.
*/
getUniformBufferLimit() {

const gl = this.renderer.backend.gl;
return gl.getParameter( gl.MAX_UNIFORM_BLOCK_SIZE );

}

/**
* Enables hardware clipping.
*
Expand Down
12 changes: 11 additions & 1 deletion src/renderers/webgpu/nodes/WGSLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,7 +2143,6 @@ ${ flowData.code }

}


/**
* Returns the WGSL type of the given node data type.
*
Expand Down Expand Up @@ -2186,6 +2185,17 @@ ${ flowData.code }

}

/**
* Returns the maximum uniform buffer size limit.
*
* @return {number} The maximum uniform buffer size in bytes.
*/
getUniformBufferLimit() {

return this.renderer.backend.device.limits.maxUniformBufferBindingSize;

}

/**
* Returns the native shader method name for a given generic name.
*
Expand Down
Loading