Skip to content

Commit

Permalink
WebGPURenderer: Request all supported features. (#25875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugen87 authored Apr 18, 2023
1 parent 883df2e commit ee2a5f2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
35 changes: 31 additions & 4 deletions examples/jsm/renderers/webgpu/WebGPURenderer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GPUIndexFormat, GPUTextureFormat } from './constants.js';
import { GPUIndexFormat, GPUTextureFormat, GPUFeatureName } from './constants.js';
import WebGPUAnimation from './WebGPUAnimation.js';
import WebGPURenderObjects from './WebGPURenderObjects.js';
import WebGPUAttributes from './WebGPUAttributes.js';
Expand Down Expand Up @@ -167,7 +167,6 @@ class WebGPURenderer {

}

this._parameters.requiredFeatures = ( parameters.requiredFeatures === undefined ) ? [] : parameters.requiredFeatures;
this._parameters.requiredLimits = ( parameters.requiredLimits === undefined ) ? {} : parameters.requiredLimits;

// backwards compatibility
Expand Down Expand Up @@ -200,8 +199,36 @@ class WebGPURenderer {

}

// feature support

const features = [
GPUFeatureName.DepthClipControl,
GPUFeatureName.Depth32FloatStencil8,
GPUFeatureName.TextureCompressionBC,
GPUFeatureName.TextureCompressionETC2,
GPUFeatureName.TextureCompressionASTC,
GPUFeatureName.TimestampQuery,
GPUFeatureName.IndirectFirstInstance,
GPUFeatureName.ShaderF16,
GPUFeatureName.RG11B10UFloat,
GPUFeatureName.BGRA8UNormStorage,
GPUFeatureName.Float32Filterable
];

const supportedFeatures = [];

for ( const name of features ) {

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

supportedFeatures.push( name );

}

}

const deviceDescriptor = {
requiredFeatures: parameters.requiredFeatures,
requiredFeatures: supportedFeatures,
requiredLimits: parameters.requiredLimits
};

Expand Down Expand Up @@ -254,7 +281,7 @@ class WebGPURenderer {

const nodeFrame = this._nodes.nodeFrame;

let previousRenderId = nodeFrame.renderId;
const previousRenderId = nodeFrame.renderId;
nodeFrame.renderId ++;

if ( this._animation.isAnimating === false ) nodeFrame.update();
Expand Down
14 changes: 14 additions & 0 deletions examples/jsm/renderers/webgpu/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,20 @@ export const GPUInputStepMode = {
Instance: 'instance'
};

export const GPUFeatureName = {
DepthClipControl: 'depth-clip-control',
Depth32FloatStencil8: 'depth32float-stencil8',
TextureCompressionBC: 'texture-compression-bc',
TextureCompressionETC2: 'texture-compression-etc2',
TextureCompressionASTC: 'texture-compression-astc',
TimestampQuery: 'timestamp-query',
IndirectFirstInstance: 'indirect-first-instance',
ShaderF16: 'shader-f16',
RG11B10UFloat: 'rg11b10ufloat-renderable',
BGRA8UNormStorage: 'bgra8unorm-storage',
Float32Filterable: 'float32-filterable'
};

export const GPUChunkSize = 16; // size of a chunk in bytes (STD140 layout)

// @TODO: Move to src/constants.js
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_sandbox.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

//

renderer = new WebGPURenderer( { requiredFeatures: [ 'texture-compression-bc', 'texture-compression-astc' ] } );
renderer = new WebGPURenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu_sprites.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@

//

renderer = new WebGPURenderer( { requiredFeatures: [ 'texture-compression-bc' ] } );
renderer = new WebGPURenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( render );
Expand Down

0 comments on commit ee2a5f2

Please sign in to comment.