Skip to content

Conversation

@Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Apr 17, 2023

Related issue: #25864, #25865

Description

This PR ensures KTX2Loader can also detect support with WebGPURenderer.

There is one issue that needs to be discussed: KTX2Loader.detectSupport() requires the renderer to test for compressed texture formats. This test requires the WebGPU adapter which is only available when the init() routine of WebGPURenderer has been finished. The changes to webgpu_sandbox shows the consequences on app level.

This also means if you would exchange WebGLRenderer with WebGPURenderer in an application that uses KTX2Loader, the app has to use the async/await pattern. I'm not sure right now if there is another way to test GPU features in WebGPU without async code (because you need the adapter for this and you only get it async).

@Mugen87 Mugen87 added this to the r152 milestone Apr 17, 2023
@Mugen87 Mugen87 marked this pull request as ready for review April 17, 2023 17:06

//

renderer = new WebGPURenderer( { requiredFeatures: [ 'texture-compression-bc', 'texture-compression-astc' ] } );
Copy link
Collaborator Author

@Mugen87 Mugen87 Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also something that might cause troubles. You have to specify the required features (e.g. texture compression formats) when WebGPURenderer is created.

That means a viewer application would have to know in advance what type of assets are going to be imported so it can request the respective features (which is of course unrealistic). I wonder now if it's best to always request all supported features (that includes texture compression formats) every time WebGPURenderer is created. Something like the following in WebGPURenderer.init():

const gpuAdapter = await navigator.gpu.requestAdapter();

const features = [];

for ( const name of featureNames ) {

    if ( gpuAdapter.features.has( name ) ) {

        features.push( name );

    }

}

const deviceDescriptor = {
    requiredFeatures: features
};

const device = await adapter.requestDevice( deviceDescriptor );

@Mugen87 Mugen87 merged commit 7359625 into mrdoob:dev Apr 18, 2023
emmanueljl pushed a commit to emmanueljl/three.js that referenced this pull request Apr 28, 2023
* KTX2Loader: Add WebGPU support.

* Examples: Clean up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants