Popov72 5 лет назад
Родитель
Сommit
90144d963b

+ 10 - 19
src/Engines/WebGPU/webgpuCacheRenderPipeline.ts

@@ -3,7 +3,6 @@ import * as WebGPUConstants from './webgpuConstants';
 import { Effect } from "../../Materials/effect";
 import { InternalTexture } from "../../Materials/Textures/internalTexture";
 import { VertexBuffer } from "../../Meshes/buffer";
-import { DataBuffer } from "../../Meshes/dataBuffer";
 import { Nullable } from "../../types";
 import { WebGPUHardwareTexture } from "./webgpuHardwareTexture";
 import { WebGPUPipelineContext } from "./webgpuPipelineContext";
@@ -171,7 +170,6 @@ export abstract class WebGPUCacheRenderPipeline {
     private _depthStencilState: number;
     private _vertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>;
     private _overrideVertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>;
-    private _indexBuffer: Nullable<DataBuffer>;
 
     constructor(device: GPUDevice, emptyVertexBuffer: VertexBuffer) {
         this._device = device;
@@ -200,7 +198,7 @@ export abstract class WebGPUCacheRenderPipeline {
         this.setDepthStencilFormat(WebGPUConstants.TextureFormat.Depth24PlusStencil8);
         this.setStencilEnabled(false);
         this.resetStencilState();
-        this.setBuffers(null, null, null);
+        this.setBuffers(null, null);
     }
 
     protected abstract _getRenderPipeline(param: { token: any, pipeline: Nullable<GPURenderPipeline> }): void;
@@ -439,10 +437,9 @@ export abstract class WebGPUCacheRenderPipeline {
         this.setStencilWriteMask(writeMask);
     }
 
-    public setBuffers(vertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>, indexBuffer: Nullable<DataBuffer>, overrideVertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>): void {
+    public setBuffers(vertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>, overrideVertexBuffers: Nullable<{ [key: string]: Nullable<VertexBuffer> }>): void {
         this._vertexBuffers = vertexBuffers;
         this._overrideVertexBuffers = overrideVertexBuffers;
-        this._indexBuffer = indexBuffer;
     }
 
     private static _GetTopology(fillMode: number): GPUPrimitiveTopology {
@@ -854,8 +851,8 @@ export abstract class WebGPUCacheRenderPipeline {
         return this._device.createPipelineLayout({ bindGroupLayouts });
     }
 
-    private _getVertexInputDescriptor(effect: Effect, topology: GPUPrimitiveTopology): GPUVertexStateDescriptor {
-        const descriptors: GPUVertexBufferLayoutDescriptor[] = [];
+    private _getVertexInputDescriptor(effect: Effect): GPUVertexState {
+        const descriptors: GPUVertexBufferLayout[] = [];
         const webgpuPipelineContext = effect._pipelineContext as WebGPUPipelineContext;
         const attributes = webgpuPipelineContext.shaderProcessingContext.attributeNamesFromEffect;
         const locations = webgpuPipelineContext.shaderProcessingContext.attributeLocationsFromEffect;
@@ -868,14 +865,14 @@ export abstract class WebGPUCacheRenderPipeline {
                 vertexBuffer = this._emptyVertexBuffer;
             }
 
-            const attributeDescriptor: GPUVertexAttributeDescriptor = {
+            const attributeDescriptor: GPUVertexAttribute = {
                 shaderLocation: location,
                 offset: 0, // not available in WebGL
                 format: WebGPUCacheRenderPipeline._GetVertexInputDescriptorFormat(vertexBuffer),
             };
 
             // TODO WEBGPU. Factorize the one with the same underlying buffer.
-            const vertexBufferDescriptor: GPUVertexBufferLayoutDescriptor = {
+            const vertexBufferDescriptor: GPUVertexBufferLayout = {
                 arrayStride: vertexBuffer.byteStride,
                 stepMode: vertexBuffer.getIsInstanced() ? WebGPUConstants.InputStepMode.Instance : WebGPUConstants.InputStepMode.Vertex,
                 attributes: [attributeDescriptor]
@@ -884,20 +881,14 @@ export abstract class WebGPUCacheRenderPipeline {
             descriptors.push(vertexBufferDescriptor);
         }
 
-        const inputStateDescriptor: GPUVertexStateDescriptor = {
-            vertexBuffers: descriptors
+        return {
+            buffers: descriptors
         };
-
-        if (topology === WebGPUConstants.PrimitiveTopology.LineStrip || topology === WebGPUConstants.PrimitiveTopology.TriangleStrip) {
-            inputStateDescriptor.indexFormat = !this._indexBuffer || this._indexBuffer.is32Bits ? WebGPUConstants.IndexFormat.Uint32 : WebGPUConstants.IndexFormat.Uint16;
-        }
-
-        return inputStateDescriptor;
     }
 
     private _createRenderPipeline(effect: Effect, topology: GPUPrimitiveTopology, sampleCount: number, createLayout = true): GPURenderPipeline {
         const webgpuPipelineContext = effect._pipelineContext as WebGPUPipelineContext;
-        const inputStateDescriptor = this._getVertexInputDescriptor(effect, topology);
+        const inputStateDescriptor = this._getVertexInputDescriptor(effect);
         const pipelineLayout = createLayout ? this._createPipelineLayout(webgpuPipelineContext) : undefined;
 
         const colorStates: Array<GPUColorStateDescriptor> = [];
@@ -922,7 +913,7 @@ export abstract class WebGPUCacheRenderPipeline {
             });
         }
 
-        const stencilFrontBack: GPUStencilStateFaceDescriptor = {
+        const stencilFrontBack: GPUStencilStateFace = {
             compare: WebGPUCacheRenderPipeline._GetCompareFunction(this._stencilFrontCompare),
             depthFailOp: WebGPUCacheRenderPipeline._GetStencilOpFunction(this._stencilFrontDepthFailOp),
             failOp: WebGPUCacheRenderPipeline._GetStencilOpFunction(this._stencilFrontFailOp),

+ 2 - 2
src/Engines/WebGPU/webgpuPipelineContext.ts

@@ -46,8 +46,8 @@ export interface IWebGPUPipelineContextVertexInputsCache {
 
 /** @hidden */
 export interface IWebGPURenderPipelineStageDescriptor {
-    vertexStage: GPUProgrammableStageDescriptor;
-    fragmentStage?: GPUProgrammableStageDescriptor;
+    vertexStage: GPUProgrammableStage;
+    fragmentStage?: GPUProgrammableStage;
 }
 
 /** @hidden */

+ 0 - 3
src/Engines/WebGPU/webgpuTextureHelper.ts

@@ -201,9 +201,6 @@ export class WebGPUTextureHelper {
                     entryPoint: 'main'
                 },
                 primitiveTopology: WebGPUConstants.PrimitiveTopology.TriangleStrip,
-                vertexState: {
-                    indexFormat: WebGPUConstants.IndexFormat.Uint16
-                },
                 colorStates: [{
                     format,
                 }]

+ 9 - 14
src/Engines/webgpuEngine.ts

@@ -576,9 +576,7 @@ export class WebGPUEngine extends Engine {
         this._mainRenderPassWrapper.colorAttachmentGPUTextures = [new WebGPUHardwareTexture()];
         this._mainRenderPassWrapper.colorAttachmentGPUTextures[0].format = this._colorFormat;
         if (this.dbgGenerateLogs) {
-            this._context.getSwapChainPreferredFormat(this._device).then((format) => {
-                console.log("Swap chain preferred format:", format);
-            });
+            console.log("Swap chain preferred format:", this._context.getSwapChainPreferredFormat(this._adapter));
         }
     }
 
@@ -590,7 +588,7 @@ export class WebGPUEngine extends Engine {
             depth: 1
         };
 
-        let mainColorAttachments: GPURenderPassColorAttachmentDescriptor[];
+        let mainColorAttachments: GPURenderPassColorAttachment[];
 
         if (this._options.antialiasing) {
             const mainTextureDescriptor: GPUTextureDescriptor = {
@@ -637,7 +635,7 @@ export class WebGPUEngine extends Engine {
             this._depthTexture.destroy();
         }
         this._depthTexture = this._device.createTexture(depthTextureDescriptor);
-        const mainDepthAttachment: GPURenderPassDepthStencilAttachmentDescriptor = {
+        const mainDepthAttachment: GPURenderPassDepthStencilAttachment = {
             attachment: this._depthTexture.createView(),
 
             depthLoadValue: this._clearDepthValue,
@@ -712,7 +710,7 @@ export class WebGPUEngine extends Engine {
         this._currentIndexBuffer = null;
         this._currentVertexBuffers = null;
         this._currentOverrideVertexBuffers = null;
-        this._cacheRenderPipeline.setBuffers(null, null, null);
+        this._cacheRenderPipeline.setBuffers(null, null);
 
         if (bruteForce) {
             this._currentProgram = null;
@@ -1075,7 +1073,7 @@ export class WebGPUEngine extends Engine {
         this._currentIndexBuffer = indexBuffer;
         this._currentVertexBuffers = vertexBuffers;
         this._currentOverrideVertexBuffers = overrideVertexBuffers ?? null;
-        this._cacheRenderPipeline.setBuffers(vertexBuffers, indexBuffer, this._currentOverrideVertexBuffers);
+        this._cacheRenderPipeline.setBuffers(vertexBuffers, this._currentOverrideVertexBuffers);
     }
 
     /** @hidden */
@@ -2834,7 +2832,7 @@ export class WebGPUEngine extends Engine {
         const depthTextureView = gpuDepthStencilTexture?.createView(this._rttRenderPassWrapper.depthAttachmentViewDescriptor!);
         const depthMSAATextureView = gpuDepthStencilMSAATexture?.createView(this._rttRenderPassWrapper.depthAttachmentViewDescriptor!);
 
-        const colorAttachments: GPURenderPassColorAttachmentDescriptor[] = [];
+        const colorAttachments: GPURenderPassColorAttachment[] = [];
 
         if (internalTexture._attachments && internalTexture._textureArray) {
             // multi render targets
@@ -2950,7 +2948,7 @@ export class WebGPUEngine extends Engine {
             const depthClearValue = scissorIsActive ? WebGPUConstants.LoadOp.Load : clearDepth ? (this.useReverseDepthBuffer ? this._clearReverseDepthValue : this._clearDepthValue) : WebGPUConstants.LoadOp.Load;
             const stencilClearValue = scissorIsActive ? WebGPUConstants.LoadOp.Load : clearStencil ? this._clearStencilValue : WebGPUConstants.LoadOp.Load;
 
-            (this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments as GPURenderPassColorAttachmentDescriptor[])[0].loadValue = colorClearValue;
+            this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments[0].loadValue = colorClearValue;
             this._mainRenderPassWrapper.renderPassDescriptor!.depthStencilAttachment!.depthLoadValue = depthClearValue;
             this._mainRenderPassWrapper.renderPassDescriptor!.depthStencilAttachment!.stencilLoadValue = stencilClearValue;
         }
@@ -2960,10 +2958,10 @@ export class WebGPUEngine extends Engine {
 
         // Resolve in case of MSAA
         if (this._options.antialiasing) {
-            (this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments as GPURenderPassColorAttachmentDescriptor[])[0].resolveTarget = this._swapChainTexture.createView();
+            this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments[0].resolveTarget = this._swapChainTexture.createView();
         }
         else {
-            (this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments as GPURenderPassColorAttachmentDescriptor[])[0].attachment = this._swapChainTexture.createView();
+            this._mainRenderPassWrapper.renderPassDescriptor!.colorAttachments[0].attachment = this._swapChainTexture.createView();
         }
 
         if (this.dbgVerboseLogsForFirstFrames) {
@@ -2990,9 +2988,6 @@ export class WebGPUEngine extends Engine {
             const pipeline = this._device.createRenderPipeline({
                 sampleCount: this._currentRenderTarget ? this._currentRenderTarget.samples : this._mainPassSampleCount,
                 primitiveTopology: WebGPUConstants.PrimitiveTopology.TriangleStrip,
-                vertexState: {
-                    indexFormat: WebGPUConstants.IndexFormat.Uint16
-                },
 
                 depthStencilState: this._depthTextureFormat === undefined ? undefined : {
                     depthWriteEnabled: clearDepth,

Разница между файлами не показана из-за своего большого размера
+ 803 - 613
src/LibDeclarations/webgpu.d.ts