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
6 changes: 3 additions & 3 deletions .github/workflows/codeql-code-scanning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@c10b8064de6f491fea524254123dbe5e09572f13 # v4
uses: github/codeql-action/init@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4
with:
languages: ${{ matrix.language }}
config-file: ./.github/codeql-config.yml
queries: security-and-quality

- name: Autobuild
uses: github/codeql-action/autobuild@c10b8064de6f491fea524254123dbe5e09572f13 # v4
uses: github/codeql-action/autobuild@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@c10b8064de6f491fea524254123dbe5e09572f13 # v4
uses: github/codeql-action/analyze@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4
with:
category: "/language:${{matrix.language}}"
8 changes: 8 additions & 0 deletions examples/jsm/inspector/tabs/Memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class Memory extends Tab {
this.textures = new Item( 'Textures', createValueSpan(), createValueSpan() );
this.memoryStats.add( this.textures );

this.uniformBuffers = new Item( 'Uniform Buffers', createValueSpan(), createValueSpan() );
this.memoryStats.add( this.uniformBuffers );

this.graph = graph;

}
Expand Down Expand Up @@ -100,6 +103,7 @@ class Memory extends Tab {

setText( this.attributes.data[ 1 ], memory.attributes.toString() );
setText( this.attributes.data[ 2 ], formatBytes( memory.attributesSize ) );

setText( this.geometries.data[ 1 ], memory.geometries.toString() );

setText( this.indexAttributes.data[ 1 ], memory.indexAttributes.toString() );
Expand All @@ -118,9 +122,13 @@ class Memory extends Tab {

setText( this.storageAttributes.data[ 1 ], memory.storageAttributes.toString() );
setText( this.storageAttributes.data[ 2 ], formatBytes( memory.storageAttributesSize ) );

setText( this.textures.data[ 1 ], memory.textures.toString() );
setText( this.textures.data[ 2 ], formatBytes( memory.texturesSize ) );

setText( this.uniformBuffers.data[ 1 ], memory.uniformBuffers.toString() );
setText( this.uniformBuffers.data[ 2 ], formatBytes( memory.uniformBuffersSize ) );

}

}
Expand Down
24 changes: 21 additions & 3 deletions examples/jsm/inspector/tabs/Timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,11 +1044,29 @@ class Timeline extends Tab {
case 'updateBindings': {

const bindGroup = args[ 0 ];
const details = { group: bindGroup.name || 'unknown' };

if ( bindGroup.bindings ) {
const details = {
group: bindGroup.name || 'unknown',
count: bindGroup.bindings.length
};

return details;

}

case 'createUniformBuffer':
case 'destroyUniformBuffer': {

const binding = args[ 0 ];

const details = {
group: binding.groupNode.name || 'unknown',
size: binding.byteLength + ' bytes'
};

if ( binding.name !== details.group ) {

details.count = bindGroup.bindings.length;
details.name = binding.name;

}

Expand Down
3 changes: 3 additions & 0 deletions examples/jsm/lighting/LightProbeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const ATLAS_PADDING = 1;
* A 3D grid of L2 Spherical Harmonic irradiance probes that provides
* position-dependent diffuse global illumination.
*
* Note that this class can only be used with {@link WebGLRenderer}.
* A version for {@link WebGPURenderer} will be added at a later point.
*
* All seven packed SH sub-volumes are stored in a **single** RGBA
* `WebGL3DRenderTarget` using a texture-atlas layout along the Z axis.
* Each sub-volume occupies `( nz + 2 )` atlas slices: one padding slice at
Expand Down
26 changes: 14 additions & 12 deletions src/materials/nodes/manager/NodeMaterialObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ class NodeMaterialObserver {

}

data.lights = this.getLightsData( renderObject.lightsNode.getLights() );
data.lights = this.getLightsData( renderObject.lightsNode.getLights(), [] );

this.renderObjects.set( renderObject, data );

Expand Down Expand Up @@ -629,9 +629,9 @@ class NodeMaterialObserver {
* @param {Array<Light>} materialLights - The material lights.
* @return {Array<Object>} The lights data for the given material lights.
*/
getLightsData( materialLights ) {
getLightsData( materialLights, lights ) {

const lights = [];
lights.length = 0;

for ( const light of materialLights ) {

Expand All @@ -658,23 +658,25 @@ class NodeMaterialObserver {
*/
getLights( lightsNode, renderId ) {

if ( _lightsCache.has( lightsNode ) ) {
let cached = _lightsCache.get( lightsNode );

const cached = _lightsCache.get( lightsNode );
if ( cached === undefined ) {

if ( cached.renderId === renderId ) {
cached = { renderId: - 1, lightsData: [] };
_lightsCache.set( lightsNode, cached );

return cached.lightsData;
}

}
if ( cached.renderId === renderId ) {

}
return cached.lightsData;

const lightsData = this.getLightsData( lightsNode.getLights() );
}

_lightsCache.set( lightsNode, { renderId, lightsData } );
cached.renderId = renderId;
this.getLightsData( lightsNode.getLights(), cached.lightsData );

return lightsData;
return cached.lightsData;

}

Expand Down
16 changes: 16 additions & 0 deletions src/renderers/common/Backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,22 @@ class Backend {
*/
createStorageAttribute( /*attribute*/ ) { }

/**
* Creates a uniform buffer.
*
* @abstract
* @param {Buffer} uniformBuffer - The uniform buffer.
*/
createUniformBuffer( /*uniformBuffer*/ ) { }

/**
* Destroys a uniform buffer.
*
* @abstract
* @param {Buffer} uniformBuffer - The uniform buffer.
*/
destroyUniformBuffer( /*uniformBuffer*/ ) { }

/**
* Updates the GPU buffer of a shader attribute.
*
Expand Down
143 changes: 97 additions & 46 deletions src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,15 @@ class Bindings extends DataMap {

const bindings = renderObject.getBindings();

for ( const bindGroup of bindings ) {

const groupData = this.get( bindGroup );
const renderObjectData = this.get( renderObject );

if ( groupData.bindGroup === undefined ) {
if ( renderObjectData.initialized !== true ) {

// each object defines an array of bindings (ubos, textures, samplers etc.)
// bind groups are created once per object

this._init( bindGroup );
this._createBindings( bindings );

this.backend.createBindings( bindGroup, bindings, 0 );

groupData.bindGroup = bindGroup;

}
renderObjectData.initialized = true;

}

Expand All @@ -110,20 +104,15 @@ class Bindings extends DataMap {
getForCompute( computeNode ) {

const bindings = this.nodes.getForCompute( computeNode ).bindings;
const computeNodeData = this.get( computeNode );

for ( const bindGroup of bindings ) {

const groupData = this.get( bindGroup );

if ( groupData.bindGroup === undefined ) {
if ( computeNodeData.initialized !== true ) {

this._init( bindGroup );
// bind groups are created once per object

this.backend.createBindings( bindGroup, bindings, 0 );
this._createBindings( bindings );

groupData.bindGroup = bindGroup;

}
computeNodeData.initialized = true;

}

Expand Down Expand Up @@ -162,12 +151,9 @@ class Bindings extends DataMap {

const bindings = this.nodes.getForCompute( computeNode ).bindings;

for ( const bindGroup of bindings ) {
this._destroyBindings( bindings );

this.backend.deleteBindGroupData( bindGroup );
this.delete( bindGroup );

}
this.delete( computeNode );

}

Expand All @@ -180,60 +166,125 @@ class Bindings extends DataMap {

const bindings = renderObject.getBindings();

for ( const bindGroup of bindings ) {

this.backend.deleteBindGroupData( bindGroup );
this.delete( bindGroup );
this._destroyBindings( bindings );

}
this.delete( renderObject );

}

/**
* Updates the given array of bindings.
* Creates the bindings for the given array of bindings.
*
* @param {Array<BindGroup>} bindings - The bind groups.
*/
_updateBindings( bindings ) {
_createBindings( bindings ) {

for ( const bindGroup of bindings ) {

this._update( bindGroup, bindings );
// binding group

const groupData = this.get( bindGroup );

if ( groupData.bindGroup === undefined ) {

// initialize

for ( const binding of bindGroup.bindings ) {

if ( binding.isUniformBuffer ) {

this.backend.createUniformBuffer( binding );
this.info.createUniformBuffer( binding );

} else if ( binding.isSampledTexture ) {

this.textures.updateTexture( binding.texture );

} else if ( binding.isSampler ) {

this.textures.updateSampler( binding.texture );

} else if ( binding.isStorageBuffer ) {

const attribute = binding.attribute;
const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;

this.attributes.update( attribute, attributeType );

}

}

// each object defines an array of bindings (ubos, textures, samplers etc.)

this.backend.createBindings( bindGroup, bindings, 0 );

groupData.bindGroup = bindGroup;
groupData.usedTimes = 1;

} else {

groupData.usedTimes ++;

}

}

}

/**
* Initializes the given bind group.
* Deletes the given array of bindings.
*
* @param {BindGroup} bindGroup - The bind group to initialize.
* @param {Array<BindGroup>} bindings - The bind groups.
*/
_init( bindGroup ) {
_destroyBindings( bindings ) {

for ( const binding of bindGroup.bindings ) {
for ( const bindGroup of bindings ) {

if ( binding.isSampledTexture ) {
const groupData = this.get( bindGroup );
groupData.usedTimes --;

this.textures.updateTexture( binding.texture );
if ( groupData.usedTimes === 0 ) {

} else if ( binding.isSampler ) {
for ( const binding of bindGroup.bindings ) {

this.textures.updateSampler( binding.texture );
if ( binding.isUniformBuffer ) {

} else if ( binding.isStorageBuffer ) {
this.backend.destroyUniformBuffer( binding );
this.info.destroyUniformBuffer( binding );

const attribute = binding.attribute;
const attributeType = attribute.isIndirectStorageBufferAttribute ? AttributeType.INDIRECT : AttributeType.STORAGE;
// release arrays

this.attributes.update( attribute, attributeType );
binding.release();

}

}

this.backend.deleteBindGroupData( bindGroup );
this.delete( bindGroup );

}

}

}

/**
* Updates the given array of bindings.
*
* @param {Array<BindGroup>} bindings - The bind groups.
*/
_updateBindings( bindings ) {

for ( const bindGroup of bindings ) {

this._update( bindGroup, bindings );

}

}

/**
* Updates the given bind group.
*
Expand Down
Loading
Loading