Skip to content

Commit 3e8e68d

Browse files
committed
WIP support for vertex pulling
1 parent c0cfa23 commit 3e8e68d

File tree

5 files changed

+28
-6
lines changed

5 files changed

+28
-6
lines changed

packages/dev/core/src/Engines/WebGPU/webgpuCacheRenderPipeline.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export abstract class WebGPUCacheRenderPipeline {
175175
public readonly mrtTextureArray: InternalTexture[];
176176
public readonly mrtTextureCount: number = 0;
177177

178-
public getRenderPipeline(fillMode: number, effect: Effect, sampleCount: number, textureState = 0): GPURenderPipeline {
178+
public getRenderPipeline(fillMode: number, effect: Effect, sampleCount: number, textureState = 0, useVertexPulling: boolean = false): GPURenderPipeline {
179179
sampleCount = WebGPUTextureHelper.GetSample(sampleCount);
180180

181181
if (this.disabled) {
@@ -196,7 +196,7 @@ export abstract class WebGPUCacheRenderPipeline {
196196
this._setRasterizationState(fillMode, sampleCount);
197197
this._setColorStates();
198198
this._setDepthStencilState();
199-
this._setVertexState(effect);
199+
this._setVertexState(effect, useVertexPulling);
200200
this._setTextureState(textureState);
201201

202202
this.lastStateDirtyLowestIndex = this._stateDirtyLowestIndex;
@@ -777,13 +777,13 @@ export abstract class WebGPUCacheRenderPipeline {
777777
}
778778
}
779779

780-
private _setVertexState(effect: Effect): void {
780+
private _setVertexState(effect: Effect, useVertexPulling: boolean = false): void {
781781
const currStateLen = this._statesLength;
782782
let newNumStates = StatePosition.VertexState;
783783

784784
const webgpuPipelineContext = effect._pipelineContext as WebGPUPipelineContext;
785-
const attributes = webgpuPipelineContext.shaderProcessingContext.attributeNamesFromEffect;
786-
const locations = webgpuPipelineContext.shaderProcessingContext.attributeLocationsFromEffect;
785+
const attributes = useVertexPulling ? [] : webgpuPipelineContext.shaderProcessingContext.attributeNamesFromEffect;
786+
const locations = useVertexPulling ? [] : webgpuPipelineContext.shaderProcessingContext.attributeLocationsFromEffect;
787787

788788
let currentGPUBuffer;
789789
let numVertexBuffers = 0;

packages/dev/core/src/Engines/abstractEngine.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ export abstract class AbstractEngine {
225225
/** @internal */
226226
public _videoTextureSupported: boolean;
227227

228+
/** @internal */
229+
public _useVertexPulling: boolean = false;
230+
228231
protected _compatibilityMode = true;
229232
/** @internal */
230233
public _pointerLockRequested: boolean;

packages/dev/core/src/Engines/webgpuEngine.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ export class WebGPUEngine extends ThinWebGPUEngine {
319319

320320
private _commandBuffers: GPUCommandBuffer[] = [null as any, null as any];
321321

322+
private _dummyVertexBuffer: DataBuffer;
323+
322324
// Frame Buffer Life Cycle (recreated for each render target pass)
323325

324326
private _mainRenderPassWrapper: IWebGPURenderPassWrapper = {
@@ -3690,7 +3692,9 @@ export class WebGPUEngine extends ThinWebGPUEngine {
36903692

36913693
this._currentMaterialContext.textureState = textureState;
36923694

3693-
const pipeline = this._cacheRenderPipeline.getRenderPipeline(fillMode, this._currentEffect!, this.currentSampleCount, textureState);
3695+
// If vertex pulling, get a cached pipeline with empty vertex layout
3696+
// Pass a boolean here to getRenderPipeline that will cause the vertex layout to be empty
3697+
const pipeline = this._cacheRenderPipeline.getRenderPipeline(fillMode, this._currentEffect!, this.currentSampleCount, textureState, this._useVertexPulling);
36943698
const bindGroups = this._cacheBindGroups.getBindGroups(webgpuPipelineContext, this._currentDrawContext, this._currentMaterialContext);
36953699

36963700
if (!this._snapshotRendering.record) {
@@ -3717,6 +3721,13 @@ export class WebGPUEngine extends ThinWebGPUEngine {
37173721
);
37183722
}
37193723

3724+
// If vertex pulling, bind a cached empty vertex buffer
3725+
if (this._useVertexPulling) {
3726+
if (!this._dummyVertexBuffer) {
3727+
this._dummyVertexBuffer = this.createVertexBuffer(new Float32Array(0), false, "DummyVertexPullingBuffer");
3728+
}
3729+
renderPass2.setVertexBuffer(0, this._dummyVertexBuffer.underlyingResource, 0, 0);
3730+
}
37203731
const vertexBuffers = this._cacheRenderPipeline.vertexBuffers;
37213732
for (let index = 0; index < vertexBuffers.length; index++) {
37223733
const vertexBuffer = vertexBuffers[index];

packages/dev/core/src/Meshes/abstractMesh.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,9 @@ export abstract class AbstractMesh extends TransformNode implements IDisposable,
956956
/** @internal */
957957
public _unIndexed = false;
958958

959+
/** @internal */
960+
public _useVertexPulling = false;
961+
959962
/** @internal */
960963
public _lightSources = new Array<Light>();
961964

packages/dev/core/src/Meshes/mesh.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1999,6 +1999,11 @@ export class Mesh extends AbstractMesh implements IGetSetVerticesData {
19991999
} else if (fillMode == Material.WireFrameFillMode) {
20002000
// Triangles as wireframe
20012001
engine.drawElementsType(fillMode, 0, subMesh._linesIndexCount, this.forcedInstanceCount || instancesCount);
2002+
} else if (this._useVertexPulling) {
2003+
// We're rendering the number of indices in the index buffer but the vertex shader is handling the data itself.
2004+
engine._useVertexPulling = true;
2005+
engine.drawArraysType(fillMode, subMesh.indexStart, subMesh.indexCount, this.forcedInstanceCount || instancesCount);
2006+
engine._useVertexPulling = false;
20022007
} else {
20032008
engine.drawElementsType(fillMode, subMesh.indexStart, subMesh.indexCount, this.forcedInstanceCount || instancesCount);
20042009
}

0 commit comments

Comments
 (0)