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: Follow the latest GPURenderPipelineDescriptor format #21472

Merged
merged 2 commits into from
Mar 16, 2021
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
67 changes: 31 additions & 36 deletions examples/jsm/renderers/webgpu/WebGPURenderPipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,6 @@ class WebGPURenderPipelines {

//

let indexFormat;

if ( object.isLine === true && object.isLineSegments !== true ) {

const count = ( geometry.index ) ? geometry.index.count : geometry.attributes.position.count;

indexFormat = ( count > 65535 ) ? GPUIndexFormat.Uint32 : GPUIndexFormat.Uint16; // define data type for primitive restart value

}

//

let alphaBlend = {};
let colorBlend = {};

Expand Down Expand Up @@ -170,25 +158,24 @@ class WebGPURenderPipelines {

// pipeline

const primitiveTopology = this._getPrimitiveTopology( object );
const rasterizationState = this._getRasterizationStateDescriptor( material );
const primitiveState = this._getPrimitiveState( object, material );
const colorWriteMask = this._getColorWriteMask( material );
const depthCompare = this._getDepthCompare( material );
const colorFormat = this._getColorFormat( this.renderer );
const depthStencilFormat = this._getDepthStencilFormat( this.renderer );

pipeline = device.createRenderPipeline( {
vertexStage: moduleVertex,
fragmentStage: moduleFragment,
primitiveTopology: primitiveTopology,
rasterizationState: rasterizationState,
colorStates: [ {
vertex: Object.assign( {}, moduleVertex, { buffers: vertexBuffers } ),
fragment: Object.assign( {}, moduleFragment, { targets: [ {
format: colorFormat,
alphaBlend: alphaBlend,
colorBlend: colorBlend,
blend: {
alpha: alphaBlend,
color: colorBlend
},
writeMask: colorWriteMask
} ],
depthStencilState: {
} ] } ),
primitive: primitiveState,
depthStencil: {
format: depthStencilFormat,
depthWriteEnabled: material.depthWrite,
depthCompare: depthCompare,
Expand All @@ -197,11 +184,9 @@ class WebGPURenderPipelines {
stencilReadMask: material.stencilFuncMask,
stencilWriteMask: material.stencilWriteMask
},
vertexState: {
indexFormat: indexFormat,
vertexBuffers: vertexBuffers
},
sampleCount: this.sampleCount
multisample: {
count: this.sampleCount
}
} );

this.pipelines.set( object, pipeline );
Expand Down Expand Up @@ -594,18 +579,19 @@ class WebGPURenderPipelines {

}

_getPrimitiveTopology( object ) {
_getPrimitiveState( object, material ) {

if ( object.isMesh ) return GPUPrimitiveTopology.TriangleList;
else if ( object.isPoints ) return GPUPrimitiveTopology.PointList;
else if ( object.isLineSegments ) return GPUPrimitiveTopology.LineList;
else if ( object.isLine ) return GPUPrimitiveTopology.LineStrip;
const descriptor = {};

}
descriptor.topology = this._getPrimitiveTopology( object );

_getRasterizationStateDescriptor( material ) {
if ( object.isLine === true && object.isLineSegments !== true ) {

const descriptor = {};
const geometry = object.geometry;
const count = ( geometry.index ) ? geometry.index.count : geometry.attributes.position.count;
descriptor.stripIndexFormat = ( count > 65535 ) ? GPUIndexFormat.Uint32 : GPUIndexFormat.Uint16; // define data type for primitive restart value

}

switch ( material.side ) {

Expand Down Expand Up @@ -634,6 +620,15 @@ class WebGPURenderPipelines {

}

_getPrimitiveTopology( object ) {

if ( object.isMesh ) return GPUPrimitiveTopology.TriangleList;
else if ( object.isPoints ) return GPUPrimitiveTopology.PointList;
else if ( object.isLineSegments ) return GPUPrimitiveTopology.LineList;
else if ( object.isLine ) return GPUPrimitiveTopology.LineStrip;

}

_getStencilCompare( material ) {

let stencilCompare;
Expand Down
24 changes: 12 additions & 12 deletions examples/jsm/renderers/webgpu/WebGPUTextureUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class WebGPUTextureUtils {
this.pipelines = {};

this.mipmapVertexShaderModule = device.createShaderModule( {
code: glslang.compileGLSL( mipmapVertexSource, 'vertex' ),
} );
this.mipmapFragmentShaderModule = device.createShaderModule( {
code: glslang.compileGLSL( mipmapFragmentSource, 'fragment' ),
} );
code: glslang.compileGLSL( mipmapVertexSource, 'vertex' ),
} );
this.mipmapFragmentShaderModule = device.createShaderModule( {
code: glslang.compileGLSL( mipmapFragmentSource, 'fragment' ),
} );

}

Expand All @@ -68,19 +68,19 @@ class WebGPUTextureUtils {
if ( pipeline === undefined ) {

pipeline = this.device.createRenderPipeline( {
vertexStage: {
vertex: {
module: this.mipmapVertexShaderModule,
entryPoint: 'main',
},
fragmentStage: {
fragment: {
module: this.mipmapFragmentShaderModule,
entryPoint: 'main',
targets: [ { format } ],
},
primitiveTopology: GPUPrimitiveTopology.TriangleStrip,
vertexState: {
indexFormat: GPUIndexFormat.Uint32
},
colorStates: [ { format } ],
primitive: {
topology: GPUPrimitiveTopology.TriangleStrip,
stripIndexFormat: GPUIndexFormat.Uint32
}
} );
this.pipelines[ format ] = pipeline;

Expand Down