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
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
33 changes: 23 additions & 10 deletions src/nodes/display/PassNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,22 @@ class PassNode extends TempNode {
*/
this._height = 1;

const depthTexture = new DepthTexture();
depthTexture.isRenderTargetTexture = true;
//depthTexture.type = FloatType;
depthTexture.name = 'depth';

const renderTarget = new RenderTarget( this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType, ...options, } );
renderTarget.texture.name = 'output';
renderTarget.depthTexture = depthTexture;

let depthTexture = null;

if ( this.scope === PassNode.DEPTH || options.depthBuffer !== false ) {

depthTexture = new DepthTexture();
depthTexture.isRenderTargetTexture = true;
//depthTexture.type = FloatType;
depthTexture.name = 'depth';

renderTarget.depthTexture = depthTexture;

}


/**
* The pass's render target.
Expand Down Expand Up @@ -310,13 +318,18 @@ class PassNode extends TempNode {
* A dictionary holding the internal result textures.
*
* @private
* @type {Object<string, Texture>}
* @type {{ output: Texture, depth?: DepthTexture }}
*/
this._textures = {
output: renderTarget.texture,
depth: depthTexture
output: renderTarget.texture
};

if ( depthTexture !== null ) {

this._textures.depth = depthTexture;

}

/**
* A dictionary holding the internal texture nodes.
*
Expand Down Expand Up @@ -757,7 +770,7 @@ class PassNode extends TempNode {

this.renderTarget.texture.type = renderer.getOutputBufferType();

if ( renderer.reversedDepthBuffer === true ) {
if ( renderer.reversedDepthBuffer === true && this.renderTarget.depthTexture !== null ) {

this.renderTarget.depthTexture.type = FloatType;

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
106 changes: 74 additions & 32 deletions src/renderers/common/Bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,39 +77,39 @@ class Bindings extends DataMap {
*/
getForRender( renderObject ) {

const bindings = renderObject.getBindings();
return this._getBindings( renderObject, renderObject.getBindings() );

for ( const bindGroup of bindings ) {
}

const groupData = this.get( bindGroup );
/**
* Returns the bind groups for the given compute node.
*
* @param {Node} computeNode - The compute node.
* @return {Array<BindGroup>} The bind groups.
*/
getForCompute( computeNode ) {

if ( groupData.bindGroup === undefined ) {
return this._getBindings( computeNode, this.nodes.getForCompute( computeNode ).bindings );

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

this._init( bindGroup );
_getBindings( object, bindings ) {

this.backend.createBindings( bindGroup, bindings, 0 );
const data = this.get( object );

groupData.bindGroup = bindGroup;
if ( data.bindings !== bindings ) {

}
if ( data.bindings !== undefined ) {

}
this._updateBindingsUsage( data.bindings, - 1 );

return bindings;
}

}
this._updateBindingsUsage( bindings, 1 );

/**
* Returns the bind groups for the given compute node.
*
* @param {Node} computeNode - The compute node.
* @return {Array<BindGroup>} The bind groups.
*/
getForCompute( computeNode ) {
data.bindings = bindings;

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

for ( const bindGroup of bindings ) {

Expand Down Expand Up @@ -160,14 +160,7 @@ class Bindings extends DataMap {
*/
deleteForCompute( computeNode ) {

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

for ( const bindGroup of bindings ) {

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

}
this._deleteBindings( computeNode );

}

Expand All @@ -178,12 +171,57 @@ class Bindings extends DataMap {
*/
deleteForRender( renderObject ) {

const bindings = renderObject.getBindings();
this._deleteBindings( renderObject );

}

_deleteBindings( object ) {

const data = this.get( object );

if ( data.bindings !== undefined ) {

this._updateBindingsUsage( data.bindings, - 1 );

data.bindings = undefined;

}

}

_updateBindingsUsage( bindings, delta ) {

for ( const bindGroup of bindings ) {

this.backend.deleteBindGroupData( bindGroup );
this.delete( bindGroup );
const groupData = this.get( bindGroup );

groupData.usedTimes = ( groupData.usedTimes || 0 ) + delta;

for ( const binding of bindGroup.bindings ) {

if ( binding.isUniformBuffer ) {

const bindingData = this.get( binding );

bindingData.usedTimes = ( bindingData.usedTimes || 0 ) + delta;

if ( bindingData.usedTimes === 0 ) {

this.backend.destroyUniformBuffer( binding );
this.delete( binding );

}

}

}

if ( groupData.usedTimes === 0 ) {

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

}

}

Expand Down Expand Up @@ -213,7 +251,11 @@ class Bindings extends DataMap {

for ( const binding of bindGroup.bindings ) {

if ( binding.isSampledTexture ) {
if ( binding.isUniformBuffer ) {

this.backend.createUniformBuffer( binding );

} else if ( binding.isSampledTexture ) {

this.textures.updateTexture( binding.texture );

Expand Down
28 changes: 17 additions & 11 deletions src/renderers/common/Textures.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,30 @@ class Textures extends DataMap {
const mipWidth = size.width >> activeMipmapLevel;
const mipHeight = size.height >> activeMipmapLevel;

let depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];
const useDepthTexture = renderTarget.depthBuffer === true || renderTarget.stencilBuffer === true;
let depthTexture = null;

let textureNeedsUpdate = false;

if ( depthTexture === undefined && useDepthTexture ) {
if ( useDepthTexture ) {

depthTexture = new DepthTexture();
depthTexture = renderTarget.depthTexture || depthTextureMips[ activeMipmapLevel ];

depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
depthTexture.image.width = mipWidth;
depthTexture.image.height = mipHeight;
depthTexture.image.depth = size.depth;
depthTexture.renderTarget = renderTarget;
depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;
if ( depthTexture === undefined ) {

depthTextureMips[ activeMipmapLevel ] = depthTexture;
depthTexture = new DepthTexture();

depthTexture.format = renderTarget.stencilBuffer ? DepthStencilFormat : DepthFormat;
depthTexture.type = renderTarget.stencilBuffer ? UnsignedInt248Type : UnsignedIntType; // FloatType
depthTexture.image.width = mipWidth;
depthTexture.image.height = mipHeight;
depthTexture.image.depth = size.depth;
depthTexture.renderTarget = renderTarget;
depthTexture.isArrayTexture = renderTarget.multiview === true && size.depth > 1;

depthTextureMips[ activeMipmapLevel ] = depthTexture;

}

}

Expand Down
59 changes: 40 additions & 19 deletions src/renderers/webgl-fallback/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1834,24 +1834,9 @@ class WebGLBackend extends Backend {
if ( binding.isUniformsGroup || binding.isUniformBuffer ) {

const array = binding.buffer;
let { bufferGPU } = this.get( array );
const bufferGPU = map.bufferGPU;

if ( bufferGPU === undefined ) {

// create

bufferGPU = gl.createBuffer();

gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );
gl.bufferData( gl.UNIFORM_BUFFER, array.byteLength, gl.DYNAMIC_DRAW );

this.set( array, { bufferGPU } );

} else {

gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );

}
gl.bindBuffer( gl.UNIFORM_BUFFER, bufferGPU );

// update

Expand Down Expand Up @@ -1883,8 +1868,6 @@ class WebGLBackend extends Backend {

}

map.bufferGPU = bufferGPU;

this.set( binding, map );

} else if ( binding.isSampledTexture ) {
Expand Down Expand Up @@ -1951,6 +1934,44 @@ class WebGLBackend extends Backend {

// attributes

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

const uniformBufferData = this.get( uniformBuffer );

if ( uniformBufferData.bufferGPU === undefined ) {

const gl = this.gl;
const array = uniformBuffer.buffer;

uniformBufferData.bufferGPU = gl.createBuffer();

gl.bindBuffer( gl.UNIFORM_BUFFER, uniformBufferData.bufferGPU );
gl.bufferData( gl.UNIFORM_BUFFER, array.byteLength, gl.DYNAMIC_DRAW );

}

}

/**
* Destroys the GPU data for the given uniform buffer.
*
* @param {Buffer} uniformBuffer - The uniform buffer.
*/
destroyUniformBuffer( uniformBuffer ) {

const uniformBufferData = this.get( uniformBuffer );

this.gl.deleteBuffer( uniformBufferData.bufferGPU );

this.delete( uniformBuffer );

}

/**
* Creates the GPU buffer of an indexed shader attribute.
*
Expand Down
Loading
Loading