Skip to content

Commit

Permalink
Wait for device initialization in hasFeatureAsync() (#28218)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunag committed Apr 25, 2024
1 parent 2182dc3 commit 20019c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
14 changes: 12 additions & 2 deletions examples/jsm/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,14 +1054,24 @@ class Renderer {

}

hasFeatureAsync( name ) {
async hasFeatureAsync( name ) {

return this.backend.hasFeatureAsync( name );
if ( this._initialized === false ) await this.init();

return this.backend.hasFeature( name );

}

hasFeature( name ) {

if ( this._initialized === false ) {

console.warn( 'THREE.Renderer: .hasFeature() called before the backend is initialized. Try using .hasFeatureAsync() instead.' );

return false;

}

return this.backend.hasFeature( name );

}
Expand Down
7 changes: 0 additions & 7 deletions examples/jsm/renderers/webgl/WebGLBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,12 +1108,6 @@ class WebGLBackend extends Backend {

}

async hasFeatureAsync( name ) {

return this.hasFeature( name );

}

hasFeature( name ) {

const keysMatching = Object.keys( GLFeatureName ).filter( key => GLFeatureName[ key ] === name );
Expand All @@ -1122,7 +1116,6 @@ class WebGLBackend extends Backend {

for ( let i = 0; i < keysMatching.length; i ++ ) {


if ( extensions.has( keysMatching[ i ] ) ) return true;

}
Expand Down
23 changes: 1 addition & 22 deletions examples/jsm/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import WebGPUAttributeUtils from './utils/WebGPUAttributeUtils.js';
import WebGPUBindingUtils from './utils/WebGPUBindingUtils.js';
import WebGPUPipelineUtils from './utils/WebGPUPipelineUtils.js';
import WebGPUTextureUtils from './utils/WebGPUTextureUtils.js';
import WebGPU from '../../capabilities/WebGPU.js';

//

Expand Down Expand Up @@ -1230,29 +1229,9 @@ class WebGPUBackend extends Backend {

}

async hasFeatureAsync( name ) {

const device = this.device || await WebGPU.getStaticAdapter();

//

return device.features.has( name );

}

hasFeature( name ) {

const device = this.device;

if ( ! device ) {

console.warn( 'WebGPUBackend: WebGPU device has not been initialized yet. Please use hasFeatureAsync() instead.' );

return false;

}

return device.features.has( name );
return this.device.features.has( name );

}

Expand Down

0 comments on commit 20019c3

Please sign in to comment.