Skip to content

Commit

Permalink
Wgpu 3.6.2 WGPU_CI_ON (cocos#12731)
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice committed Sep 16, 2022
1 parent cab07e9 commit f5c4dee
Show file tree
Hide file tree
Showing 76 changed files with 4,123 additions and 2,148 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
*.jsb.ts
**/*.ems.ts
cocos/core/gfx/webgpu/**/*
cocos/webgpu/**/*
9 changes: 9 additions & 0 deletions @types/url.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare module 'url:native/external/emscripten/webgpu/webgpu_wasm.wasm' {
const url: string;
export default url;
}

declare module 'url:native/external/emscripten/webgpu/glslang.wasm' {
const url: string;
export default url;
}
13 changes: 13 additions & 0 deletions cc.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,13 @@
"cocos/3d/misc/create-mesh.ts":"cocos/3d/misc/create-mesh.jsb.ts"
}
},
{
"test": "context.buildTimeConstants && context.buildTimeConstants.WEBGPU",
"isVirtualModule": false,
"overrides": {
"cocos/core/gfx/index.ts": "cocos/core/gfx/index.ems.ts"
}
},
{
"test": "context.buildTimeConstants && context.buildTimeConstants.HTML5",
"isVirtualModule": true,
Expand Down Expand Up @@ -465,6 +472,12 @@
"type": "number",
"value": 0,
"internal": false
},
"WEBGPU": {
"comment": "Running with webgpu rendering backend.",
"type": "boolean",
"value": false,
"internal": true
}
}
}
8 changes: 4 additions & 4 deletions cocos/core/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
THE SOFTWARE.
*/

import { BUILD, DEBUG, EDITOR, HTML5, JSB, NATIVE, PREVIEW, RUNTIME_BASED, TEST } from 'internal:constants';
import { BUILD, DEBUG, EDITOR, HTML5, JSB, NATIVE, PREVIEW, RUNTIME_BASED, TEST, WEBGPU } from 'internal:constants';
import { systemInfo } from 'pal/system-info';
import { findCanvas, loadJsFile } from 'pal/env';
import { Pacer } from 'pal/pacer';
Expand Down Expand Up @@ -84,7 +84,7 @@ export interface IGameConfig {
* You can pass in parameters in game.init or override them in the [game.onPostBaseInitDelegate] event callback.
* Note: you need to specify this option in the application.js template or add a delegate callback.
*/
overrideSettings : Partial<{ [ k in Settings.Category[keyof Settings.Category] ]: Record<string, any> }>
overrideSettings: Partial<{ [k in Settings.Category[keyof Settings.Category]]: Record<string, any> }>

/**
* @zh
Expand Down Expand Up @@ -602,8 +602,8 @@ export class Game extends EventTarget {
public on (type: string, callback: () => void, target?: any, once?: boolean): any {
// Make sure EVENT_ENGINE_INITED callbacks to be invoked
if ((this._engineInited && type === Game.EVENT_ENGINE_INITED)
|| (this._inited && type === Game.EVENT_GAME_INITED)
|| (this._rendererInitialized && type === Game.EVENT_RENDERER_INITED)) {
|| (this._inited && type === Game.EVENT_GAME_INITED)
|| (this._rendererInitialized && type === Game.EVENT_RENDERER_INITED)) {
callback.call(target);
}
return this.eventTargetOn(type, callback, target, once);
Expand Down
7 changes: 6 additions & 1 deletion cocos/core/gfx/device-manager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-len */
/*
Copyright (c) 2022 Xiamen Yaji Software Co., Ltd.
Expand All @@ -23,7 +24,7 @@
THE SOFTWARE.
*/

import { JSB } from 'internal:constants';
import { JSB, WEBGPU } from 'internal:constants';
import { legacyCC } from '../global-exports';
import { error, getError } from '../platform/debug';
import { sys } from '../platform/sys';
Expand Down Expand Up @@ -88,6 +89,7 @@ export enum RenderType {
/**
* @internal
*/

export class DeviceManager {
private initialized = false;
private _gfxDevice!: Device;
Expand Down Expand Up @@ -127,6 +129,9 @@ export class DeviceManager {
}

const deviceCtors: Constructor<Device>[] = [];
if (WEBGPU) {
deviceCtors.push(legacyCC.WebGPUDevice);
}
if (useWebGL2 && legacyCC.WebGL2Device) {
deviceCtors.push(legacyCC.WebGL2Device);
}
Expand Down
64 changes: 64 additions & 0 deletions cocos/core/gfx/index.ems.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
Copyright (c) 2020 Xiamen Yaji Software Co., Ltd.
https://www.cocos.com/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated engine source code (the "Software"), a limited,
worldwide, royalty-free, non-assignable, revocable and non-exclusive license
to use Cocos Creator solely to develop games on your target platforms. You shall
not use Cocos Creator software for developing other software or tools that's
used for developing games. You are not granted to publish, distribute,
sublicense, and/or sell copies of Cocos Creator.
The software or tools in this License Agreement are licensed, not sold.
Xiamen Yaji Software Co., Ltd. reserves all rights not expressly granted to you.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

/**
* @packageDocumentation
* @module gfx
*/

import { legacyCC } from '../global-exports';
import { gfx, webgpuAdapter } from '../../webgpu/instantiated';

import './deprecated-3.0.0';

export { BlendState, PipelineStateInfo, RasterizerState, DepthStencilState, BlendTarget } from './base/pipeline-state'
export * from './base/define';
export * from './device-manager';


const polyfillCC: Record<string, unknown> = { ...gfx };
polyfillCC.Device = gfx.CCWGPUDevice;
polyfillCC.Swapchain = gfx.CCWGPUSwapchain;
polyfillCC.Buffer = gfx.CCWGPUBuffer;
polyfillCC.Texture = gfx.CCWGPUTexture;
polyfillCC.Sampler = gfx.CCWGPUSampler;
polyfillCC.Shader = gfx.CCWGPUShader;
polyfillCC.InputAssembler = gfx.CCWGPUInputAssembler;
polyfillCC.RenderPass = gfx.CCWGPURenderPass;
polyfillCC.Framebuffer = gfx.CCWGPUFramebuffer;
polyfillCC.DescriptorSet = gfx.CCWGPUDescriptorSet;
polyfillCC.DescriptorSetLayout = gfx.CCWGPUDescriptorSetLayout;
polyfillCC.PipelineLayout = gfx.CCWGPUPipelineLayout;
polyfillCC.PipelineState = gfx.CCWGPUPipelineState;
polyfillCC.CommandBuffer = gfx.CCWGPUCommandBuffer;
polyfillCC.Queue = gfx.CCWGPUQueue;
legacyCC.gfx = polyfillCC;

export * from './webgpu/override';
export * from './webgpu/webgpu-define'

export const WGPU_WASM = true;

console.log(gfx.Device);
56 changes: 56 additions & 0 deletions cocos/core/gfx/webgpu/override.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
/* eslint-disable import/no-mutable-exports */
import { WEBGPU } from 'internal:constants';
import { gfx, promiseForWebGPUInstantiation } from '../../../webgpu/instantiated';

export let Device: any;
export let WebGPUDevice: any;
export let Queue: any;
export let Swapchain: any;
export let Buffer: any;
export let Texture: any;
export let Shader: any;
export let Sampler: any;
export let InputAssembler: any;
export let RenderPass: any;
export let Framebuffer: any;
export let DescriptorSet: any;
export let DescriptorSetLayout: any;
export let PipelineLayout: any;
export let PipelineState: any;
export let CommandBuffer: any;
export let GeneralBarrier: any;
export let TextureBarrier: any;
export let BufferBarrier: any;

WEBGPU && promiseForWebGPUInstantiation.then(() => {
Device = gfx.CCWGPUDevice;
WebGPUDevice = gfx.CCWGPUDevice;
Queue = gfx.CCWGPUQueue;
Swapchain = gfx.CCWGPUSwapchain;
Buffer = gfx.CCWGPUBuffer;
Texture = gfx.CCWGPUTexture;
Shader = gfx.CCWGPUShader;
Sampler = gfx.CCWGPUSampler;
InputAssembler = gfx.CCWGPUInputAssembler;
RenderPass = gfx.CCWGPURenderPass;
Framebuffer = gfx.CCWGPUFramebuffer;
DescriptorSet = gfx.CCWGPUDescriptorSet;
DescriptorSetLayout = gfx.CCWGPUDescriptorSetLayout;
PipelineLayout = gfx.CCWGPUPipelineLayout;
PipelineState = gfx.CCWGPUPipelineState;
CommandBuffer = gfx.CCWGPUCommandBuffer;
GeneralBarrier = gfx.WGPUGeneralBarrier;
TextureBarrier = gfx.WGPUTextureBarrier;
BufferBarrier = gfx.WGPUBufferBarrier;

// immutable excluded
[Device, Queue, Swapchain, Buffer, Texture, Shader, InputAssembler, RenderPass, Framebuffer, DescriptorSet,
DescriptorSetLayout, PipelineState, CommandBuffer].forEach((ele) => {
const oldDestroy = ele.prototype.destroy;
ele.prototype.destroy = function () {
oldDestroy.call(this);
this.delete();
};
});
});
Loading

0 comments on commit f5c4dee

Please sign in to comment.