UNPKG

34.4 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../../src/webgpu/index.ts"],"names":["isSafari","WebGPUConstants","injectable","glslang","WebGPUAttribute","WebGPUBuffer","WebGPUComputeModel","WebGPUElements","WebGPUFramebuffer","WebGPUModel","WebGPUTexture2D","WebGPUEngine","supportWebGPU","useWGSL","options","canvas","context","adapter","device","swapChain","mainPassSampleCount","mainTexture","depthTexture","mainColorAttachments","mainTextureExtends","mainDepthAttachment","uploadEncoder","renderEncoder","computeEncoder","renderTargetEncoder","commandBuffers","Array","fill","undefined","currentRenderPass","mainRenderPass","currentRenderTargetViewDescriptor","currentComputePass","bundleEncoder","tempBuffers","currentRenderTarget","uploadEncoderDescriptor","label","renderEncoderDescriptor","renderTargetEncoderDescriptor","computeEncoderDescriptor","pipelines","computePipelines","defaultSampleCount","clearDepthValue","clearStencilValue","transientViewport","x","Infinity","y","width","height","cachedViewport","clear","framebuffer","color","depth","stencil","supportCompute","startComputePass","endRenderTargetRenderPass","startRenderTargetRenderPass","loadValue","LoadOp","Load","depthLoadValue","stencilLoadValue","endMainRenderPass","startMainRenderPass","createModel","model","init","createAttribute","createBuffer","createElements","createTexture2D","createFramebuffer","useFramebuffer","drawCommands","unbindFramebuffer","dimension","TextureViewDimension","E2d","arrayLayerCount","aspect","TextureAspect","All","createComputeModel","getCanvas","getGLContext","Error","viewport","renderPass","getCurrentRenderPass","setViewport","readPixels","config","antialiasing","initGlslang","initContextAndSwapChain","initMainAttachments","destroy","forEach","buffer","createCommandEncoder","endComputePass","finish","getQueue","submit","filter","defaultQueue","navigator","gpu","requestAdapter","requestDevice","getContext","configureSwapChain","format","swapChainFormat","usage","TextureUsage","OutputAttachment","CopySrc","mainTextureDescriptor","size","mipLevelCount","sampleCount","TextureDimension","TextureFormat","BGRA8Unorm","createTexture","attachment","createDefaultView","createView","storeOp","StoreOp","Store","getCurrentTexture","depthTextureDescriptor","Depth24PlusStencil8","depthStoreOp","stencilStoreOp","beginComputePass","resolveTarget","beginRenderPass","colorAttachments","depthStencilAttachment","renderTarget","clearColor","clearDepth","clearStencil","gpuTexture","get","texture","colorTextureView","depthStencilTexture","depthStencilTextureView","endPass","resetCachedViewport"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,SAgBEA,QAhBF,QAoBO,qBApBP,C,CAqBA;;AACA,OAAO,KAAKC,eAAZ,MAAiC,8BAAjC;AAEA,SAASC,UAAT,QAA2B,WAA3B;AACA,OAAOC,OAAP,MAAoB,WAApB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AACA,OAAOC,kBAAP,MAA+B,sBAA/B;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,iBAAP,MAA8B,qBAA9B;AACA,OAAOC,WAAP,MAAwB,eAAxB;AACA,OAAOC,eAAP,MAA4B,mBAA5B;AASA;AAJA;AACA;AACA;AAEA,IAAaC,YAAb,WADCT,UAAU,EACX;AAAA;AAAA;;AAAA;;AAAA,SACSU,aADT,GACyB,IADzB;AAAA,SAESC,OAFT,GAEmB,KAFnB;AAAA,SAISC,OAJT;AAAA,SAKSC,MALT;AAAA,SAMSC,OANT;AAAA,SAOSb,OAPT;AAAA,SAQSc,OART;AAAA,SASSC,MATT;AAAA,SAUSC,SAVT;AAAA,SAYSC,mBAZT;AAAA,SAcSC,WAdT;AAAA,SAeSC,YAfT;AAAA,SAgBSC,oBAhBT;AAAA,SAiBSC,kBAjBT;AAAA,SAkBSC,mBAlBT;AAAA,SAqBSC,aArBT;AAAA,SAsBSC,aAtBT;AAAA,SAuBSC,cAvBT;AAAA,SAwBSC,mBAxBT;AAAA,SAyBSC,cAzBT,GAyB8C,IAAIC,KAAJ,CAAU,CAAV,EAAaC,IAAb,CAAkBC,SAAlB,CAzB9C;AAAA,SA4BSC,iBA5BT,GA4B0D,IA5B1D;AAAA,SA6BSC,cA7BT,GA6BuD,IA7BvD;AAAA,SA8BSC,iCA9BT;AAAA,SA+BS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3B;AACA,WAAKb,mBAAL,GAA2B,IAA3B,CAVwD,CAYxD;AACA;AACA;;AAEA,WAAKN,iBAAL,GAAyB,KAAKC,cAA9B;AACD;AAxiBH;;AAAA;AAAA","sourcesContent":["/**\n * implements renderService with WebGPU API\n * @see https://webgpu.io/\n * @see https://github.com/BabylonJS/Babylon.js/blob/WebGPU/src/Engines/webgpuEngine.ts\n */\nimport {\n GLSLContext,\n IAttribute,\n IAttributeInitializationOptions,\n IBuffer,\n IBufferInitializationOptions,\n IClearOptions,\n IElements,\n IElementsInitializationOptions,\n IFramebuffer,\n IFramebufferInitializationOptions,\n IModel,\n IModelInitializationOptions,\n IReadPixelsOptions,\n IRendererConfig,\n IRendererService,\n isSafari,\n ITexture2D,\n ITexture2DInitializationOptions,\n IViewport,\n} from '@antv/g-webgpu-core';\n// import { Glslang } from '@webgpu/glslang/dist/web-devel/glslang.onefile';\nimport * as WebGPUConstants from '@webgpu/types/dist/constants';\nimport { vec4 } from 'gl-matrix';\nimport { injectable } from 'inversify';\nimport glslang from './glslang';\nimport WebGPUAttribute from './WebGPUAttribute';\nimport WebGPUBuffer from './WebGPUBuffer';\nimport WebGPUComputeModel from './WebGPUComputeModel';\nimport WebGPUElements from './WebGPUElements';\nimport WebGPUFramebuffer from './WebGPUFramebuffer';\nimport WebGPUModel from './WebGPUModel';\nimport WebGPUTexture2D from './WebGPUTexture2D';\n\ntype Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;\ntype WithOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * regl renderer\n */\n@injectable()\nexport class WebGPUEngine implements IRendererService {\n public supportWebGPU = true;\n public useWGSL = false;\n\n public options: IRendererConfig;\n public canvas: HTMLCanvasElement;\n public context: GPUCanvasContext;\n public glslang: any;\n public adapter: GPUAdapter;\n public device: GPUDevice;\n public swapChain: GPUSwapChain;\n\n public mainPassSampleCount: number;\n\n public mainTexture: GPUTexture;\n public depthTexture: GPUTexture;\n public mainColorAttachments: GPURenderPassColorAttachmentDescriptor[];\n public mainTextureExtends: GPUExtent3D;\n public mainDepthAttachment: GPURenderPassDepthStencilAttachmentDescriptor;\n\n // Frame Life Cycle (recreated each frame)\n public uploadEncoder: GPUCommandEncoder;\n public renderEncoder: GPUCommandEncoder;\n public computeEncoder: GPUCommandEncoder;\n public renderTargetEncoder: GPUCommandEncoder;\n public commandBuffers: GPUCommandBuffer[] = new Array(4).fill(undefined);\n\n // Frame Buffer Life Cycle (recreated for each render target pass)\n public currentRenderPass: GPURenderPassEncoder | null = null;\n public mainRenderPass: GPURenderPassEncoder | null = null;\n public currentRenderTargetViewDescriptor: GPUTextureViewDescriptor;\n public currentComputePass: GPUComputePassEncoder | null = null;\n public bundleEncoder: GPURenderBundleEncoder | null;\n public tempBuffers: GPUBuffer[] = [];\n public currentRenderTarget: WebGPUFramebuffer | null = null;\n\n public readonly uploadEncoderDescriptor = { label: 'upload' };\n public readonly renderEncoderDescriptor = { label: 'render' };\n public readonly renderTargetEncoderDescriptor = { label: 'renderTarget' };\n public readonly computeEncoderDescriptor = { label: 'compute' };\n\n /**\n * 通过名称访问\n */\n private pipelines: {\n [pipelineName: string]: GPURenderPipeline;\n } = {};\n private computePipelines: {\n [pipelineName: string]: GPUComputePipeline;\n } = {};\n\n private readonly defaultSampleCount = 4;\n private readonly clearDepthValue = 1;\n private readonly clearStencilValue = 0;\n private transientViewport: IViewport = {\n x: Infinity,\n y: 0,\n width: 0,\n height: 0,\n };\n private cachedViewport: IViewport = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n };\n\n public isFloatSupported() {\n return true;\n }\n\n public async init(config: IRendererConfig): Promise<void> {\n this.canvas = config.canvas;\n this.options = config;\n this.useWGSL = !!config.useWGSL;\n this.mainPassSampleCount = config.antialiasing\n ? this.defaultSampleCount\n : 1;\n\n await this.initGlslang();\n this.initContextAndSwapChain();\n this.initMainAttachments();\n }\n\n public clear = (options: IClearOptions): void => {\n const { framebuffer, color, depth, stencil } = options;\n\n if (this.options.supportCompute) {\n this.startComputePass();\n }\n\n // We need to recreate the render pass so that the new parameters for clear color / depth / stencil are taken into account\n if (this.currentRenderTarget) {\n if (this.currentRenderPass) {\n this.endRenderTargetRenderPass();\n }\n this.startRenderTargetRenderPass(\n this.currentRenderTarget!,\n color ? color : null,\n !!depth,\n !!stencil,\n );\n } else {\n // if (this.useReverseDepthBuffer) {\n // this._depthCullingState.depthFunc = Constants.GREATER;\n // }\n\n this.mainColorAttachments[0].loadValue = color\n ? color\n : WebGPUConstants.LoadOp.Load;\n\n this.mainDepthAttachment.depthLoadValue = depth\n ? depth\n : WebGPUConstants.LoadOp.Load;\n this.mainDepthAttachment.stencilLoadValue = stencil\n ? this.clearStencilValue\n : WebGPUConstants.LoadOp.Load;\n\n if (this.mainRenderPass) {\n this.endMainRenderPass();\n }\n\n this.startMainRenderPass();\n }\n };\n\n public createModel = async (\n options: IModelInitializationOptions,\n ): Promise<IModel> => {\n const model = new WebGPUModel(this, options);\n await model.init();\n return model;\n };\n\n public createAttribute = (\n options: IAttributeInitializationOptions,\n ): IAttribute => {\n return new WebGPUAttribute(this, options);\n };\n\n public createBuffer = (options: IBufferInitializationOptions): IBuffer => {\n return new WebGPUBuffer(this, options);\n };\n\n public createElements = (\n options: IElementsInitializationOptions,\n ): IElements => {\n return new WebGPUElements(this, options);\n };\n\n public createTexture2D = (\n options: ITexture2DInitializationOptions,\n ): ITexture2D => {\n return new WebGPUTexture2D(this, options);\n };\n\n public createFramebuffer = (\n options: IFramebufferInitializationOptions,\n ): IFramebuffer => {\n return new WebGPUFramebuffer(this, options);\n };\n\n public useFramebuffer = (\n framebuffer: IFramebuffer | null,\n drawCommands: () => void,\n ): void => {\n // bind\n if (this.currentRenderTarget) {\n this.unbindFramebuffer(this.currentRenderTarget);\n }\n this.currentRenderTarget = framebuffer as WebGPUFramebuffer;\n\n // TODO: use mipmap options in framebuffer\n this.currentRenderTargetViewDescriptor = {\n dimension: WebGPUConstants.TextureViewDimension.E2d,\n // mipLevelCount: bindWithMipMaps ? WebGPUTextureHelper.computeNumMipmapLevels(texture.width, texture.height) - lodLevel : 1,\n // baseArrayLayer: faceIndex,\n // baseMipLevel: lodLevel,\n arrayLayerCount: 1,\n aspect: WebGPUConstants.TextureAspect.All,\n };\n\n this.currentRenderPass = null;\n\n drawCommands();\n };\n\n public createComputeModel = async (context: GLSLContext) => {\n const model = new WebGPUComputeModel(this, context);\n await model.init();\n return model;\n };\n\n public getCanvas = (): HTMLCanvasElement => {\n return this.canvas;\n };\n\n public getGLContext = (): WebGLRenderingContext => {\n throw new Error('Method not implemented.');\n };\n\n public viewport = ({\n x,\n y,\n width,\n height,\n }: {\n x: number;\n y: number;\n width: number;\n height: number;\n }): void => {\n if (!this.currentRenderPass) {\n // call viewport() before current render pass created\n this.transientViewport = { x, y, width, height };\n } else if (this.transientViewport.x !== Infinity) {\n const renderPass = this.getCurrentRenderPass();\n // @see https://gpuweb.github.io/gpuweb/#dom-gpurenderpassencoder-setviewport\n renderPass.setViewport(\n this.transientViewport.x,\n this.transientViewport.y,\n this.transientViewport.width,\n this.transientViewport.height,\n 0,\n 1,\n );\n } else if (\n x !== this.cachedViewport.x ||\n y !== this.cachedViewport.y ||\n width !== this.cachedViewport.width ||\n height !== this.cachedViewport.height\n ) {\n this.cachedViewport = { x, y, width, height };\n const renderPass = this.getCurrentRenderPass();\n renderPass.setViewport(x, y, width, height, 0, 1);\n }\n };\n\n public readPixels = (options: IReadPixelsOptions): Uint8Array => {\n throw new Error('Method not implemented.');\n };\n\n public destroy(): void {\n if (this.mainTexture) {\n this.mainTexture.destroy();\n }\n if (this.depthTexture) {\n this.depthTexture.destroy();\n }\n this.tempBuffers.forEach((buffer) => buffer.destroy());\n this.tempBuffers = [];\n }\n\n public beginFrame() {\n this.uploadEncoder = this.device.createCommandEncoder(\n this.uploadEncoderDescriptor,\n );\n this.renderEncoder = this.device.createCommandEncoder(\n this.renderEncoderDescriptor,\n );\n this.renderTargetEncoder = this.device.createCommandEncoder(\n this.renderTargetEncoderDescriptor,\n );\n if (this.options.supportCompute) {\n this.computeEncoder = this.device.createCommandEncoder(\n this.computeEncoderDescriptor,\n );\n }\n }\n\n public endFrame() {\n if (this.options.supportCompute) {\n this.endComputePass();\n }\n\n this.endMainRenderPass();\n\n this.commandBuffers[0] = this.uploadEncoder.finish();\n this.commandBuffers[1] = this.renderEncoder.finish();\n if (this.options.supportCompute) {\n this.commandBuffers[2] = this.computeEncoder.finish();\n }\n this.commandBuffers[3] = this.renderTargetEncoder.finish();\n\n if (isSafari) {\n this.device\n // @ts-ignore\n .getQueue()\n .submit(this.commandBuffers.filter((buffer) => buffer));\n } else {\n this.device.defaultQueue.submit(\n this.commandBuffers.filter((buffer) => buffer),\n );\n }\n }\n\n public getCurrentRenderPass(): GPURenderPassEncoder {\n if (this.currentRenderTarget && !this.currentRenderPass) {\n this.startRenderTargetRenderPass(\n this.currentRenderTarget,\n null,\n false,\n false,\n );\n } else if (!this.currentRenderPass) {\n this.startMainRenderPass();\n }\n\n return this.currentRenderPass!;\n }\n\n private async initGlslang() {\n this.glslang = await glslang();\n this.adapter = (await navigator?.gpu?.requestAdapter()) as GPUAdapter;\n this.device = (await this.adapter.requestDevice()) as GPUDevice;\n }\n\n private initContextAndSwapChain() {\n this.context = (this.canvas.getContext(\n isSafari ? 'gpu' : 'gpupresent',\n ) as unknown) as GPUCanvasContext;\n this.swapChain = this.context.configureSwapChain({\n device: this.device,\n format: this.options.swapChainFormat!,\n usage:\n WebGPUConstants.TextureUsage.OutputAttachment |\n WebGPUConstants.TextureUsage.CopySrc,\n });\n }\n\n private initMainAttachments() {\n this.mainTextureExtends = {\n width: this.canvas.width,\n height: this.canvas.height,\n depth: 1,\n };\n\n if (this.options.antialiasing) {\n const mainTextureDescriptor = {\n size: this.mainTextureExtends,\n // TODO: arrayLayerCount is deprecated: use size.depth\n // arrayLayerCount: 1,\n mipLevelCount: 1,\n sampleCount: this.mainPassSampleCount,\n dimension: WebGPUConstants.TextureDimension.E2d,\n format: WebGPUConstants.TextureFormat.BGRA8Unorm,\n usage: WebGPUConstants.TextureUsage.OutputAttachment,\n };\n\n if (this.mainTexture) {\n this.mainTexture.destroy();\n }\n this.mainTexture = this.device.createTexture(mainTextureDescriptor);\n this.mainColorAttachments = [\n {\n attachment: isSafari\n ? // @ts-ignore\n this.mainTexture.createDefaultView()\n : this.mainTexture.createView(),\n loadValue: [0, 0, 0, 1],\n storeOp: WebGPUConstants.StoreOp.Store,\n },\n ];\n } else {\n this.mainColorAttachments = [\n {\n attachment: isSafari\n ? // @ts-ignore\n this.swapChain.getCurrentTexture().createDefaultView()\n : this.swapChain.getCurrentTexture().createView(),\n loadValue: [0, 0, 0, 1],\n storeOp: WebGPUConstants.StoreOp.Store,\n },\n ];\n }\n\n const depthTextureDescriptor = {\n size: this.mainTextureExtends,\n // arrayLayerCount: 1,\n mipLevelCount: 1,\n sampleCount: this.mainPassSampleCount,\n dimension: WebGPUConstants.TextureDimension.E2d,\n format: isSafari\n ? 'depth32float-stencil8'\n : WebGPUConstants.TextureFormat.Depth24PlusStencil8,\n usage: WebGPUConstants.TextureUsage.OutputAttachment,\n };\n\n if (this.depthTexture) {\n this.depthTexture.destroy();\n }\n\n this.depthTexture = this.device.createTexture(\n // @ts-ignore\n depthTextureDescriptor,\n );\n this.mainDepthAttachment = {\n attachment: isSafari\n ? // @ts-ignore\n this.depthTexture.createDefaultView()\n : this.depthTexture.createView(),\n depthLoadValue: this.clearDepthValue,\n depthStoreOp: WebGPUConstants.StoreOp.Store,\n stencilLoadValue: this.clearStencilValue,\n stencilStoreOp: WebGPUConstants.StoreOp.Store,\n };\n }\n\n private startComputePass() {\n if (this.currentComputePass) {\n this.endComputePass();\n }\n\n this.currentComputePass = this.computeEncoder.beginComputePass();\n }\n\n private startMainRenderPass() {\n if (this.currentRenderPass && !this.currentRenderTarget) {\n this.endMainRenderPass();\n }\n\n // Resolve in case of MSAA\n if (this.options.antialiasing) {\n this.mainColorAttachments[0].resolveTarget = isSafari\n ? // @ts-ignore\n this.swapChain.getCurrentTexture().createDefaultView()\n : this.swapChain.getCurrentTexture().createView();\n } else {\n this.mainColorAttachments[0].attachment = isSafari\n ? // @ts-ignore\n this.swapChain.getCurrentTexture().createDefaultView()\n : this.swapChain.getCurrentTexture().createView();\n }\n\n this.currentRenderPass = this.renderEncoder.beginRenderPass({\n colorAttachments: this.mainColorAttachments,\n depthStencilAttachment: this.mainDepthAttachment, // TODO: use framebuffer's depth & stencil\n });\n\n this.mainRenderPass = this.currentRenderPass;\n\n if (this.cachedViewport) {\n this.viewport(this.cachedViewport);\n }\n }\n\n private startRenderTargetRenderPass(\n renderTarget: WebGPUFramebuffer,\n clearColor: [number, number, number, number] | null,\n clearDepth: boolean,\n clearStencil: boolean = false,\n ) {\n const gpuTexture = renderTarget.get().color?.texture;\n let colorTextureView: GPUTextureView;\n if (gpuTexture) {\n colorTextureView = gpuTexture.createView(\n this.currentRenderTargetViewDescriptor,\n );\n }\n\n const depthStencilTexture = renderTarget.get().depth?.texture;\n let depthStencilTextureView;\n if (depthStencilTexture) {\n depthStencilTextureView = depthStencilTexture.createView();\n }\n\n const renderPass = this.renderTargetEncoder.beginRenderPass({\n colorAttachments: [\n {\n attachment: colorTextureView!,\n loadValue:\n clearColor !== null ? clearColor : WebGPUConstants.LoadOp.Load,\n storeOp: WebGPUConstants.StoreOp.Store,\n },\n ],\n depthStencilAttachment:\n depthStencilTexture && depthStencilTextureView\n ? {\n attachment: depthStencilTextureView,\n depthLoadValue: clearDepth\n ? this.clearDepthValue\n : WebGPUConstants.LoadOp.Load,\n depthStoreOp: WebGPUConstants.StoreOp.Store,\n stencilLoadValue: clearStencil\n ? this.clearStencilValue\n : WebGPUConstants.LoadOp.Load,\n stencilStoreOp: WebGPUConstants.StoreOp.Store,\n }\n : undefined,\n });\n\n this.currentRenderPass = renderPass;\n\n if (this.cachedViewport) {\n this.viewport(this.cachedViewport);\n }\n\n // TODO WEBGPU set the scissor rect and the stencil reference value\n }\n\n private endMainRenderPass() {\n if (\n this.currentRenderPass === this.mainRenderPass &&\n this.currentRenderPass !== null\n ) {\n this.currentRenderPass.endPass();\n this.resetCachedViewport();\n this.currentRenderPass = null;\n this.mainRenderPass = null;\n }\n }\n\n private endComputePass() {\n if (this.currentComputePass) {\n this.currentComputePass.endPass();\n this.currentComputePass = null;\n }\n }\n\n private endRenderTargetRenderPass() {\n if (this.currentRenderPass) {\n this.currentRenderPass.endPass();\n this.resetCachedViewport();\n }\n }\n\n private resetCachedViewport() {\n this.cachedViewport = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n };\n }\n\n private unbindFramebuffer(framebuffer: WebGPUFramebuffer) {\n // unbind\n if (\n this.currentRenderPass &&\n this.currentRenderPass !== this.mainRenderPass\n ) {\n this.endRenderTargetRenderPass();\n }\n\n this.transientViewport.x = Infinity;\n this.currentRenderTarget = null;\n\n // if (texture.generateMipMaps && !disableGenerateMipMaps && !texture.isCube) {\n // this._generateMipmaps(texture);\n // }\n\n this.currentRenderPass = this.mainRenderPass;\n }\n}\n"],"file":"index.js"}
\No newline at end of file