Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Wait for device initialization in hasFeatureAsync() #28218

Merged
merged 1 commit into from
Apr 25, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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