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: Simplify BindGroupLayout creation #20330

Merged
merged 1 commit into from
Sep 13, 2020
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
23 changes: 4 additions & 19 deletions examples/jsm/renderers/webgpu/WebGPUBindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import WebGPUSampledTexture from './WebGPUSampledTexture.js';

class WebGPUBindings {

constructor( device, info, properties, textures ) {
constructor( device, info, properties, textures, pipelines ) {

this.device = device;
this.info = info;
this.properties = properties;
this.textures = textures;
this.pipelines = pipelines;

this.uniformsData = new WeakMap();

Expand All @@ -28,6 +29,7 @@ class WebGPUBindings {

if ( data === undefined ) {

const pipeline = this.pipelines.get( object );
const material = object.material;
let bindings;

Expand All @@ -53,7 +55,7 @@ class WebGPUBindings {

// setup (static) binding layout and (dynamic) binding group

const bindLayout = this._createBindLayout( bindings );
const bindLayout = pipeline.getBindGroupLayout( 0 );
const bindGroup = this._createBindGroup( bindings, bindLayout );

data = {
Expand Down Expand Up @@ -164,23 +166,6 @@ class WebGPUBindings {

}

_createBindLayout( bindings ) {

let bindingPoint = 0;
const entries = [];

for ( const binding of bindings ) {

entries.push( { binding: bindingPoint, visibility: binding.visibility, type: binding.type } );

bindingPoint ++;

}

return this.device.createBindGroupLayout( { entries: entries } );

}

_createBindGroup( bindings, layout ) {

let bindingPoint = 0;
Expand Down
9 changes: 1 addition & 8 deletions examples/jsm/renderers/webgpu/WebGPURenderPipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import {

class WebGPURenderPipelines {

constructor( device, glslang, bindings, sampleCount ) {
constructor( device, glslang, sampleCount ) {

this.device = device;
this.glslang = glslang;
this.bindings = bindings;
this.sampleCount = sampleCount;

this.pipelines = new WeakMap();
Expand Down Expand Up @@ -93,11 +92,6 @@ class WebGPURenderPipelines {

}

// layout

const bindLayout = this.bindings.get( object ).layout;
const layout = device.createPipelineLayout( { bindGroupLayouts: [ bindLayout ] } );

// determine shader attributes

const shaderAttributes = this._parseShaderAttributes( shader.vertexShader );
Expand Down Expand Up @@ -163,7 +157,6 @@ class WebGPURenderPipelines {
const depthCompare = this._getDepthCompare( material );

pipeline = device.createRenderPipeline( {
layout: layout,
vertexStage: moduleVertex,
fragmentStage: moduleFragment,
primitiveTopology: primitiveTopology,
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/renderers/webgpu/WebGPURenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ class WebGPURenderer {
this._attributes = new WebGPUAttributes( device );
this._geometries = new WebGPUGeometries( this._attributes, this._info );
this._textures = new WebGPUTextures( device, this._properties, this._info, compiler );
this._bindings = new WebGPUBindings( device, this._info, this._properties, this._textures );
this._objects = new WebGPUObjects( this._geometries, this._info );
this._renderPipelines = new WebGPURenderPipelines( device, compiler, this._bindings, parameters.sampleCount );
this._renderPipelines = new WebGPURenderPipelines( device, compiler, parameters.sampleCount );
this._bindings = new WebGPUBindings( device, this._info, this._properties, this._textures, this._renderPipelines );
this._renderLists = new WebGPURenderLists();
this._background = new WebGPUBackground( this );

Expand Down