From 4fd693adf2b40c8e79609df06c7f7501d2b355d8 Mon Sep 17 00:00:00 2001 From: Yun Hsiao Wu Date: Sat, 30 Jan 2021 16:53:06 +0800 Subject: [PATCH] device layer adapt --- .eslintrc.yaml | 10 +- cocos/2d/utils/dynamic-atlas/atlas.ts | 2 +- cocos/3d/framework/mesh-renderer.ts | 4 +- .../value-proxy-factories/uniform.ts | 8 +- cocos/core/assets/effect-asset.ts | 6 +- cocos/core/assets/material.ts | 4 +- cocos/core/assets/render-texture.ts | 4 +- cocos/core/assets/texture-cube.ts | 4 +- cocos/core/components/camera-component.ts | 12 +- cocos/core/game.ts | 2 +- cocos/core/gfx/buffer.ts | 52 +- cocos/core/gfx/command-buffer.ts | 14 +- cocos/core/gfx/define-class.ts | 117 -- cocos/core/gfx/define.ts | 1391 ++++++++++++----- cocos/core/gfx/deprecated-3.0.0.ts | 182 +-- cocos/core/gfx/descriptor-set-layout.ts | 25 +- cocos/core/gfx/descriptor-set.ts | 15 +- cocos/core/gfx/device.ts | 224 +-- cocos/core/gfx/fence.ts | 56 - cocos/core/gfx/framebuffer.ts | 14 +- cocos/core/gfx/index.jsb.ts | 91 +- cocos/core/gfx/index.ts | 4 +- cocos/core/gfx/input-assembler.ts | 35 +- cocos/core/gfx/pipeline-layout.ts | 10 +- cocos/core/gfx/pipeline-state.jsb.ts | 5 +- cocos/core/gfx/pipeline-state.ts | 32 +- cocos/core/gfx/polyfill-legacy-cc.ts | 83 +- cocos/core/gfx/queue.ts | 13 +- cocos/core/gfx/render-pass.ts | 78 +- cocos/core/gfx/sampler.ts | 22 +- cocos/core/gfx/shader.ts | 81 +- cocos/core/gfx/texture.ts | 39 +- cocos/core/gfx/webgl/webgl-buffer.ts | 5 +- .../core/gfx/webgl/webgl-command-allocator.ts | 8 +- cocos/core/gfx/webgl/webgl-command-buffer.ts | 9 +- cocos/core/gfx/webgl/webgl-commands.ts | 66 +- cocos/core/gfx/webgl/webgl-define.ts | 2 +- .../gfx/webgl/webgl-descriptor-set-layout.ts | 3 +- cocos/core/gfx/webgl/webgl-descriptor-set.ts | 3 +- cocos/core/gfx/webgl/webgl-device.ts | 81 +- cocos/core/gfx/webgl/webgl-fence.ts | 39 - cocos/core/gfx/webgl/webgl-framebuffer.ts | 5 +- cocos/core/gfx/webgl/webgl-gpu-objects.ts | 26 +- cocos/core/gfx/webgl/webgl-input-assembler.ts | 3 +- cocos/core/gfx/webgl/webgl-pipeline-layout.ts | 3 +- .../gfx/webgl/webgl-primary-command-buffer.ts | 5 +- cocos/core/gfx/webgl/webgl-queue.ts | 6 +- cocos/core/gfx/webgl/webgl-render-pass.ts | 7 +- cocos/core/gfx/webgl/webgl-sampler.ts | 4 +- cocos/core/gfx/webgl/webgl-shader.ts | 7 +- cocos/core/gfx/webgl/webgl-state-cache.ts | 2 +- cocos/core/gfx/webgl/webgl-texture.ts | 4 +- cocos/core/gfx/webgl2/webgl2-buffer.ts | 4 +- .../gfx/webgl2/webgl2-command-allocator.ts | 8 +- .../core/gfx/webgl2/webgl2-command-buffer.ts | 7 +- cocos/core/gfx/webgl2/webgl2-commands.ts | 87 +- .../webgl2/webgl2-descriptor-set-layout.ts | 3 +- .../core/gfx/webgl2/webgl2-descriptor-set.ts | 3 +- cocos/core/gfx/webgl2/webgl2-device.ts | 103 +- cocos/core/gfx/webgl2/webgl2-fence.ts | 59 - cocos/core/gfx/webgl2/webgl2-framebuffer.ts | 5 +- cocos/core/gfx/webgl2/webgl2-gpu-objects.ts | 27 +- .../core/gfx/webgl2/webgl2-input-assembler.ts | 3 +- .../core/gfx/webgl2/webgl2-pipeline-layout.ts | 3 +- .../webgl2/webgl2-primary-command-buffer.ts | 5 +- cocos/core/gfx/webgl2/webgl2-queue.ts | 10 +- cocos/core/gfx/webgl2/webgl2-render-pass.ts | 7 +- cocos/core/gfx/webgl2/webgl2-sampler.ts | 3 +- cocos/core/gfx/webgl2/webgl2-shader.ts | 7 +- cocos/core/gfx/webgl2/webgl2-state-cache.ts | 2 +- cocos/core/gfx/webgl2/webgl2-texture.ts | 4 +- cocos/core/pipeline/define.ts | 28 +- .../core/pipeline/forward/forward-pipeline.ts | 21 +- cocos/core/pipeline/forward/forward-stage.ts | 4 +- cocos/core/pipeline/pipeline-serialization.ts | 20 +- cocos/core/pipeline/pipeline-ubo.ts | 10 +- .../pipeline/render-additive-light-queue.ts | 8 +- cocos/core/pipeline/shadow/shadow-flow.ts | 6 +- cocos/core/renderer/core/memory-pools.ts | 12 +- cocos/core/renderer/core/pass-instance.ts | 4 +- cocos/core/renderer/core/pass-utils.ts | 4 +- cocos/core/renderer/core/pass.ts | 11 +- cocos/core/renderer/core/program-lib.ts | 47 +- cocos/core/renderer/core/render-window.ts | 5 +- cocos/core/renderer/scene/camera.ts | 40 +- cocos/core/root.ts | 5 +- cocos/core/splash-screen.ts | 4 +- .../renderer/particle-system-renderer-data.ts | 10 +- cocos/particle/renderer/trail.ts | 20 +- .../physx/shapes/physx-trimesh-shape.ts | 8 +- cocos/profiler/profiler.ts | 10 +- cocos/video/video-player-impl-web.ts | 6 +- package.json | 4 +- 93 files changed, 1601 insertions(+), 1963 deletions(-) delete mode 100644 cocos/core/gfx/define-class.ts delete mode 100644 cocos/core/gfx/fence.ts delete mode 100644 cocos/core/gfx/webgl/webgl-fence.ts delete mode 100644 cocos/core/gfx/webgl2/webgl2-fence.ts diff --git a/.eslintrc.yaml b/.eslintrc.yaml index cd58d2c3ed..1f44686c58 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -42,6 +42,10 @@ rules: # https://eslint.org/docs/rules/ # https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin + # !!!!!!!!!!!!!!!!!!!!!!!!! + # BEFORE ADDING ANY RULES + # PLEASE EXPLAIN THE REASON IN THE COMMENT. + ##### RECOMMENDED RULE OVERRIDES ##### camelcase: off # underscores may come in handy in some cases @@ -54,7 +58,7 @@ rules: radix: off # we sometimes do not need to pass a second parameter # allow underscores, we still widely use pre-dangle naming in our naming convention # e.g. private properties, private functions, module scope shared variables etc. - no-underscore-dangle: off + no-underscore-dangle: off quotes: [warn, single, { allowTemplateLiterals: true }] # force single, but allow template literal no-else-return: off # else-return is a common pattern which clearly expresses the control flow @@ -70,6 +74,7 @@ rules: lines-between-class-members: off # be more lenient on member declarations max-classes-per-file: off # helper classes are common max-len: [warn, 150] # more lenient on max length per line + no-console: off # this is just too much work, cc.warn is still too much pain to use no-plusplus: off # allow increment/decrement operators no-continue: off # allow unlabeled continues no-mixed-operators: off # this is just cumbersome @@ -86,7 +91,8 @@ rules: object-curly-newline: off # we want manual control over this one-var-declaration-per-line: off # auto-fix has order issues with `one-var` prefer-destructuring: off # auto-fix is not smart enough to merge different instances - linebreak-style: off + linebreak-style: off # we don't enforce this on everyone's dev environment for now + ##### TYPESCRIPT-SPECIFIC RULE OVERRIDES ##### # TODO: this is just too much work diff --git a/cocos/2d/utils/dynamic-atlas/atlas.ts b/cocos/2d/utils/dynamic-atlas/atlas.ts index 5dbe5006d2..5f54291ae1 100644 --- a/cocos/2d/utils/dynamic-atlas/atlas.ts +++ b/cocos/2d/utils/dynamic-atlas/atlas.ts @@ -6,7 +6,7 @@ import { PixelFormat } from '../../../core/assets/asset-enum'; import { ImageAsset } from '../../../core/assets/image-asset'; import { Texture2D } from '../../../core/assets/texture-2d'; -import { BufferTextureCopy } from '../../../core/gfx/define-class'; +import { BufferTextureCopy } from '../../../core/gfx/define'; import { legacyCC } from '../../../core/global-exports'; import { SpriteFrame } from '../../assets/sprite-frame'; diff --git a/cocos/3d/framework/mesh-renderer.ts b/cocos/3d/framework/mesh-renderer.ts index 778c14eedd..6485ca8b45 100644 --- a/cocos/3d/framework/mesh-renderer.ts +++ b/cocos/3d/framework/mesh-renderer.ts @@ -28,7 +28,8 @@ * @module model */ -import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, visible, type, formerlySerializedAs, serializable, editable, disallowAnimation } from 'cc.decorator'; +import { ccclass, help, executeInEditMode, executionOrder, menu, tooltip, visible, type, + formerlySerializedAs, serializable, editable, disallowAnimation } from 'cc.decorator'; import { Texture2D } from '../../core/assets'; import { Material } from '../../core/assets/material'; import { Mesh } from '../assets/mesh'; @@ -237,6 +238,7 @@ export class MeshRenderer extends RenderableComponent { return this._model; } + // eslint-disable-next-line func-names @visible(function (this: MeshRenderer) { return !!( this.mesh diff --git a/cocos/core/animation/value-proxy-factories/uniform.ts b/cocos/core/animation/value-proxy-factories/uniform.ts index 7337e4130f..1103c35db7 100644 --- a/cocos/core/animation/value-proxy-factories/uniform.ts +++ b/cocos/core/animation/value-proxy-factories/uniform.ts @@ -88,10 +88,10 @@ export class UniformProxyFactory implements IValueProxyFactory { throw new Error(`Material "${target.name}" has no uniform "${this.uniformName}"`); } const propertyType = Pass.getPropertyTypeFromHandle(handle); - if (propertyType === PropertyType.UBO) { + if (propertyType === PropertyType.BUFFER) { const realHandle = this.channelIndex === undefined ? handle : pass.getHandle(this.uniformName, this.channelIndex, Type.FLOAT); if (!realHandle) { - throw new Error(`Uniform "${this.uniformName} (in material ${target.name}) has no channel ${this.channelIndex}"`); + throw new Error(`Uniform "${this.uniformName} (in material ${target.name}) has no channel ${this.channelIndex!}"`); } if (isUniformArray(pass, this.uniformName)) { return { @@ -105,10 +105,10 @@ export class UniformProxyFactory implements IValueProxyFactory { pass.setUniform(realHandle, value); }, }; - } if (propertyType === PropertyType.SAMPLER) { + } if (propertyType === PropertyType.TEXTURE) { const binding = Pass.getBindingFromHandle(handle); const prop = pass.properties[this.uniformName]; - const texName = prop && prop.value ? `${prop.value}-texture` : getDefaultFromType(prop.type) as string; + const texName = prop && prop.value ? `${prop.value as string}-texture` : getDefaultFromType(prop.type) as string; let dftTex = builtinResMgr.get(texName); if (!dftTex) { warn(`Illegal texture default value: ${texName}.`); diff --git a/cocos/core/assets/effect-asset.ts b/cocos/core/assets/effect-asset.ts index d45dd9b895..b9baa06b6e 100644 --- a/cocos/core/assets/effect-asset.ts +++ b/cocos/core/assets/effect-asset.ts @@ -77,7 +77,7 @@ export interface IBlockInfo { stageFlags: ShaderStageFlags; descriptorType?: DescriptorType; } -export interface ISamplerInfo { +export interface ISamplerTextureInfo { binding: number; name: string; type: Type; @@ -101,7 +101,7 @@ export interface IBuiltin { } export interface IBuiltinInfo { blocks: IBuiltin[]; - samplers: IBuiltin[]; + samplerTextures: IBuiltin[]; } export interface IShaderInfo { name: string; @@ -112,7 +112,7 @@ export interface IShaderInfo { builtins: { globals: IBuiltinInfo, locals: IBuiltinInfo }; defines: IDefineInfo[]; blocks: IBlockInfo[]; - samplers: ISamplerInfo[]; + samplerTextures: ISamplerTextureInfo[]; attributes: IAttributeInfo[]; } export interface IPreCompileInfo { diff --git a/cocos/core/assets/material.ts b/cocos/core/assets/material.ts index 15b0734586..64b81b5673 100644 --- a/cocos/core/assets/material.ts +++ b/cocos/core/assets/material.ts @@ -425,7 +425,7 @@ export class Material extends Asset { const handle = pass.getHandle(name); if (!handle) { return false; } const propertyType = Pass.getPropertyTypeFromHandle(handle); - if (propertyType === PropertyType.UBO) { + if (propertyType === PropertyType.BUFFER) { if (Array.isArray(val)) { pass.setUniformArray(handle, val as MaterialProperty[]); } else if (val !== null) { @@ -433,7 +433,7 @@ export class Material extends Asset { } else { pass.resetUniform(name); } - } else if (propertyType === PropertyType.SAMPLER) { + } else if (propertyType === PropertyType.TEXTURE) { if (Array.isArray(val)) { for (let i = 0; i < val.length; i++) { this._bindTexture(pass, handle, val[i], i); diff --git a/cocos/core/assets/render-texture.ts b/cocos/core/assets/render-texture.ts index a3a046ba8a..a8a808a1cc 100644 --- a/cocos/core/assets/render-texture.ts +++ b/cocos/core/assets/render-texture.ts @@ -29,7 +29,7 @@ */ import { ccclass, rangeMin, rangeMax, serializable } from 'cc.decorator'; -import { Texture, Sampler, ColorAttachment, DepthStencilAttachment, TextureLayout, RenderPassInfo } from '../gfx'; +import { Texture, Sampler, ColorAttachment, DepthStencilAttachment, AccessType, RenderPassInfo } from '../gfx'; import { legacyCC } from '../global-exports'; import { RenderWindow, IRenderWindowInfo } from '../renderer/core/render-window'; @@ -49,7 +49,7 @@ export interface IRenderTextureCreateInfo { } const _colorAttachment = new ColorAttachment(); -_colorAttachment.endLayout = TextureLayout.SHADER_READONLY_OPTIMAL; +_colorAttachment.endAccesses = [AccessType.FRAGMENT_SHADER_READ_TEXTURE]; const _depthStencilAttachment = new DepthStencilAttachment(); const passInfo = new RenderPassInfo([_colorAttachment], _depthStencilAttachment); diff --git a/cocos/core/assets/texture-cube.ts b/cocos/core/assets/texture-cube.ts index 21a0b0d45a..7ddd769865 100644 --- a/cocos/core/assets/texture-cube.ts +++ b/cocos/core/assets/texture-cube.ts @@ -223,7 +223,7 @@ export class TextureCube extends SimpleTexture { this.mipmaps = []; } - public _serialize (ctxForExporting: any): any { + public _serialize (ctxForExporting: any): Record | null { if (EDITOR || TEST) { return { base: super._serialize(ctxForExporting), @@ -244,6 +244,7 @@ export class TextureCube extends SimpleTexture { })), }; } + return null; } public _deserialize (serializedData: ITextureCubeSerializeData, handle: any) { @@ -277,7 +278,6 @@ export class TextureCube extends SimpleTexture { texInfo.height = this._height; texInfo.layerCount = 6; Object.assign(texInfo, presumed); - texInfo.flags |= TextureFlagBit.CUBEMAP; return texInfo; } } diff --git a/cocos/core/components/camera-component.ts b/cocos/core/components/camera-component.ts index a457c638ba..33716f9e97 100644 --- a/cocos/core/components/camera-component.ts +++ b/cocos/core/components/camera-component.ts @@ -34,7 +34,6 @@ import { RenderTexture } from '../assets/render-texture'; import { UITransform } from '../../2d/framework'; import { Component } from './component'; import { Ray } from '../geometry'; -import { ClearFlag as GFXClearFlag } from '../gfx/define'; import { Color, Rect, toRadian, Vec3 } from '../math'; import { CAMERA_DEFAULT_MASK } from '../pipeline/define'; import { view } from '../platform/view'; @@ -47,6 +46,7 @@ import { Enum } from '../value-types'; import { TransformBit } from '../scene-graph/node-enum'; import { legacyCC } from '../global-exports'; import { RenderWindow } from '../renderer/core/render-window'; +import { ClearFlagBit } from '../gfx/define'; const _temp_vec3_1 = new Vec3(); @@ -60,11 +60,11 @@ const Aperture = Enum(CameraAperture); const Shutter = Enum(CameraShutter); const ISO = Enum(CameraISO); -const ClearFlag = Enum({ - SKYBOX: SKYBOX_FLAG | GFXClearFlag.DEPTH_STENCIL, - SOLID_COLOR: GFXClearFlag.ALL, - DEPTH_ONLY: GFXClearFlag.DEPTH_STENCIL, - DONT_CLEAR: GFXClearFlag.NONE, +export const ClearFlag = Enum({ + SKYBOX: SKYBOX_FLAG | ClearFlagBit.DEPTH_STENCIL, + SOLID_COLOR: ClearFlagBit.ALL, + DEPTH_ONLY: ClearFlagBit.DEPTH_STENCIL, + DONT_CLEAR: ClearFlagBit.NONE, }); export declare namespace Camera { diff --git a/cocos/core/game.ts b/cocos/core/game.ts index 45f6a67c90..2584186a2e 100644 --- a/cocos/core/game.ts +++ b/cocos/core/game.ts @@ -28,7 +28,7 @@ * @module core */ -import { ALIPAY, EDITOR, JSB, PREVIEW, RUNTIME_BASED } from 'internal:constants'; +import { EDITOR, JSB, PREVIEW, RUNTIME_BASED } from 'internal:constants'; import { IAssetManagerOptions } from './asset-manager/asset-manager'; import { EventTarget } from './event/event-target'; import * as debug from './platform/debug'; diff --git a/cocos/core/gfx/buffer.ts b/cocos/core/gfx/buffer.ts index 2c8d744a99..6d6fcc9666 100644 --- a/cocos/core/gfx/buffer.ts +++ b/cocos/core/gfx/buffer.ts @@ -38,56 +38,12 @@ import { MemoryUsageBit, Obj, ObjectType, + IndirectBuffer, + BufferInfo, + BufferViewInfo, + BufferSource, } from './define'; -export class DrawInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public vertexCount: number = 0, - public firstVertex: number = 0, - public indexCount: number = 0, - public firstIndex: number = 0, - public vertexOffset: number = 0, - public instanceCount: number = 0, - public firstInstance: number = 0, - ) {} -} - -export const DRAW_INFO_SIZE = 28; - -export class IndirectBuffer { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public drawInfos: DrawInfo[] = [], - ) {} -} - -export type BufferSource = ArrayBuffer | IndirectBuffer; - -export class BufferInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public usage: BufferUsage, - public memUsage: MemoryUsage, - public size: number = 0, - public stride: number = 0, // in bytes - public flags: BufferFlags = BufferFlagBit.NONE, - ) {} -} - -export class BufferViewInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public buffer: Buffer, - public offset: number = 0, - public range: number = 0, - ) {} -} - /** * @en GFX buffer. * @zh GFX 缓冲。 diff --git a/cocos/core/gfx/command-buffer.ts b/cocos/core/gfx/command-buffer.ts index a691b1bd03..bffdff0eba 100644 --- a/cocos/core/gfx/command-buffer.ts +++ b/cocos/core/gfx/command-buffer.ts @@ -37,23 +37,15 @@ import { PipelineState } from './pipeline-state'; import { Queue } from './queue'; import { RenderPass } from './render-pass'; import { Texture } from './texture'; -import { BufferTextureCopy, Color, Rect, Viewport } from './define-class'; import { - CommandBufferType, Obj, ObjectType, StencilFace, + CommandBufferType, + CommandBufferInfo, + BufferTextureCopy, Color, Rect, Viewport, } from './define'; -export class CommandBufferInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public queue: Queue, - public type: CommandBufferType = CommandBufferType.PRIMARY, - ) {} -} - /** * @en GFX command buffer. * @zh GFX 命令缓冲。 diff --git a/cocos/core/gfx/define-class.ts b/cocos/core/gfx/define-class.ts deleted file mode 100644 index e01db4bb4c..0000000000 --- a/cocos/core/gfx/define-class.ts +++ /dev/null @@ -1,117 +0,0 @@ -/* - 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. - */ - -/** - * Define gfx global classes here. - */ - -export class Rect { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public x: number = 0, - public y: number = 0, - public width: number = 1, - public height: number = 1, - ) {} -} - -export class Viewport { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public left: number = 0, - public top: number = 0, - public width: number = 0, - public height: number = 0, - public minDepth: number = 0, - public maxDepth: number = 1, - ) {} -} - -export class Color { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public x: number = 0, - public y: number = 0, - public z: number = 0, - public w: number = 0, - ) {} -} - -export class Offset { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public x: number = 0, - public y: number = 0, - public z: number = 0, - ) {} -} - -export class Extent { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public width: number = 0, - public height: number = 0, - public depth: number = 1, - ) {} -} - -export class TextureSubres { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public mipLevel: number = 0, - public baseArrayLayer: number = 0, - public layerCount: number = 1, - ) {} -} - -export class TextureCopy { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public srcSubres = new TextureSubres(), - public srcOffset = new Offset(), - public dstSubres = new TextureSubres(), - public dstOffset = new Offset(), - public extent = new Extent(), - ) {} -} - -export class BufferTextureCopy { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public buffStride: number = 0, - public buffTexHeight: number = 0, - public texOffset = new Offset(), - public texExtent = new Extent(), - public texSubres = new TextureSubres(), - ) {} -} diff --git a/cocos/core/gfx/define.ts b/cocos/core/gfx/define.ts index 0741ac2240..0c62e9b301 100644 --- a/cocos/core/gfx/define.ts +++ b/cocos/core/gfx/define.ts @@ -28,7 +28,20 @@ * @module gfx */ -export const MAX_ATTACHMENTS = 4; +import { Buffer } from './buffer'; +import { DescriptorSetLayout } from './descriptor-set-layout'; +import { Queue } from './queue'; +import { RenderPass } from './render-pass'; +import { Sampler } from './sampler'; +import { Texture } from './texture'; + +/** + * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= + * The following section is auto-generated from engine-native/cocos/renderer/core/gfx/GFXDef-common.h + * by the script engine-native/tools/gfx-define-generator/generate.js. + * Changes to these public interfaces should be made there first and synced back. + * ========================= !DO NOT CHANGE THE FOLLOWING SECTION MANUALLY! ========================= + */ export enum ObjectType { UNKNOWN, @@ -44,93 +57,67 @@ export enum ObjectType { DESCRIPTOR_SET, INPUT_ASSEMBLER, COMMAND_BUFFER, - FENCE, QUEUE, - WINDOW, + GLOBAL_BARRIER, + TEXTURE_BARRIER, + BUFFER_BARRIER, } -/** - * @en GFX base object. - * @zh GFX 基类对象。 - */ -export class Obj { - public get gfxType (): ObjectType { - return this._gfxType; - } - - protected _gfxType = ObjectType.UNKNOWN; - - constructor (gfxType: ObjectType) { - this._gfxType = gfxType; - } +export enum Status { + UNREADY, + FAILED, + SUCCESS, } -export enum AttributeName { - ATTR_POSITION = 'a_position', - ATTR_NORMAL = 'a_normal', - ATTR_TANGENT = 'a_tangent', - ATTR_BITANGENT = 'a_bitangent', - ATTR_WEIGHTS = 'a_weights', - ATTR_JOINTS = 'a_joints', - ATTR_COLOR = 'a_color', - ATTR_COLOR1 = 'a_color1', - ATTR_COLOR2 = 'a_color2', - ATTR_TEX_COORD = 'a_texCoord', - ATTR_TEX_COORD1 = 'a_texCoord1', - ATTR_TEX_COORD2 = 'a_texCoord2', - ATTR_TEX_COORD3 = 'a_texCoord3', - ATTR_TEX_COORD4 = 'a_texCoord4', - ATTR_TEX_COORD5 = 'a_texCoord5', - ATTR_TEX_COORD6 = 'a_texCoord6', - ATTR_TEX_COORD7 = 'a_texCoord7', - ATTR_TEX_COORD8 = 'a_texCoord8', - ATTR_BATCH_ID = 'a_batch_id', - ATTR_BATCH_UV = 'a_batch_uv', -} - -export enum Type { - // assumptions about the order of this enum: (exploited by other parts of the engine) - // * vectors always come before samplers - // * vectors with the same data type are always consecutive, in an component-wise ascending order - // * unknown is always zero +export enum API { UNKNOWN, - // vectors - BOOL, - BOOL2, - BOOL3, - BOOL4, + GLES2, + GLES3, + METAL, + VULKAN, + WEBGL, + WEBGL2, + WEBGPU, +} - INT, - INT2, - INT3, - INT4, +export enum SurfaceTransform { + IDENTITY, + ROTATE_90, + ROTATE_180, + ROTATE_270, +} - UINT, - UINT2, - UINT3, - UINT4, - - FLOAT, - FLOAT2, - FLOAT3, - FLOAT4, - - MAT2, - MAT2X3, - MAT2X4, - MAT3X2, - MAT3, - MAT3X4, - MAT4X2, - MAT4X3, - MAT4, - // samplers - SAMPLER1D, - SAMPLER1D_ARRAY, - SAMPLER2D, - SAMPLER2D_ARRAY, - SAMPLER3D, - SAMPLER_CUBE, +export enum Feature { + COLOR_FLOAT, + COLOR_HALF_FLOAT, + TEXTURE_FLOAT, + TEXTURE_HALF_FLOAT, + TEXTURE_FLOAT_LINEAR, + TEXTURE_HALF_FLOAT_LINEAR, + FORMAT_R11G11B10F, + FORMAT_D16, + FORMAT_D16S8, + FORMAT_D24, + FORMAT_D24S8, + FORMAT_D32F, + FORMAT_D32FS8, + FORMAT_ETC1, + FORMAT_ETC2, + FORMAT_DXT, + FORMAT_PVRTC, + FORMAT_ASTC, + FORMAT_RGB8, + MSAA, + ELEMENT_INDEX_UINT, + INSTANCED_ARRAYS, + MULTIPLE_RENDER_TARGETS, + BLEND_MINMAX, + DEPTH_BOUNDS, + LINE_WIDTH, + STENCIL_WRITE_MASK, + STENCIL_COMPARE_MASK, + MULTITHREADED_SUBMISSION, + COMPUTE_SHADER, COUNT, } @@ -287,43 +274,276 @@ export enum Format { ASTC_SRGBA_10x10, ASTC_SRGBA_12x10, ASTC_SRGBA_12x12, + + // Total count + COUNT, +} + +export enum FormatType { + NONE, + UNORM, + SNORM, + UINT, + INT, + UFLOAT, + FLOAT, +} + +export enum Type { + UNKNOWN, + BOOL, + BOOL2, + BOOL3, + BOOL4, + INT, + INT2, + INT3, + INT4, + UINT, + UINT2, + UINT3, + UINT4, + FLOAT, + FLOAT2, + FLOAT3, + FLOAT4, + MAT2, + MAT2X3, + MAT2X4, + MAT3X2, + MAT3, + MAT3X4, + MAT4X2, + MAT4X3, + MAT4, + // combined image samplers + SAMPLER1D, + SAMPLER1D_ARRAY, + SAMPLER2D, + SAMPLER2D_ARRAY, + SAMPLER3D, + SAMPLER_CUBE, + // sampler + SAMPLER, + // sampled textures + TEXTURE1D, + TEXTURE1D_ARRAY, + TEXTURE2D, + TEXTURE2D_ARRAY, + TEXTURE3D, + TEXTURE_CUBE, + // storage images + IMAGE1D, + IMAGE1D_ARRAY, + IMAGE2D, + IMAGE2D_ARRAY, + IMAGE3D, + IMAGE_CUBE, + // input attachment + SUBPASS_INPUT, + COUNT, } export enum BufferUsageBit { - NONE = 0, + NONE = 0, TRANSFER_SRC = 0x1, TRANSFER_DST = 0x2, - INDEX = 0x4, - VERTEX = 0x8, - UNIFORM = 0x10, - STORAGE = 0x20, - INDIRECT = 0x40, + INDEX = 0x4, + VERTEX = 0x8, + UNIFORM = 0x10, + STORAGE = 0x20, + INDIRECT = 0x40, } -export type BufferUsage = BufferUsageBit; - -export enum MemoryUsageBit { - NONE = 0, - DEVICE = 0x1, - HOST = 0x2, -} - -export type MemoryUsage = MemoryUsageBit; - export enum BufferFlagBit { - NONE = 0, + NONE = 0, BAKUP_BUFFER = 0x4, } -export type BufferFlags = BufferFlagBit; - -export enum BufferAccessBit { - NONE = 0, - READ = 0x1, - WRITE = 0x2, +export enum MemoryAccessBit { + NONE = 0, + READ_ONLY = 0x1, + WRITE_ONLY = 0x2, + READ_WRITE = READ_ONLY | WRITE_ONLY, } -export type BufferAccess = BufferAccessBit; +export enum MemoryUsageBit { + NONE = 0, + DEVICE = 0x1, + HOST = 0x2, +} + +export enum TextureType { + TEX1D, + TEX2D, + TEX3D, + CUBE, + TEX1D_ARRAY, + TEX2D_ARRAY, +} + +export enum TextureUsageBit { + NONE = 0, + TRANSFER_SRC = 0x1, + TRANSFER_DST = 0x2, + SAMPLED = 0x4, + STORAGE = 0x8, + COLOR_ATTACHMENT = 0x10, + DEPTH_STENCIL_ATTACHMENT = 0x20, + TRANSIENT_ATTACHMENT = 0x40, + INPUT_ATTACHMENT = 0x80, +} + +export enum TextureFlagBit { + NONE = 0, + GEN_MIPMAP = 0x1, + BAKUP_BUFFER = 0x2, + IMMUTABLE = 0x4, +} + +export enum SampleCount { + X1, + X2, + X4, + X8, + X16, + X32, + X64, +} + +export enum Filter { + NONE, + POINT, + LINEAR, + ANISOTROPIC, +} + +export enum Address { + WRAP, + MIRROR, + CLAMP, + BORDER, +} + +export enum ComparisonFunc { + NEVER, + LESS, + EQUAL, + LESS_EQUAL, + GREATER, + NOT_EQUAL, + GREATER_EQUAL, + ALWAYS, +} + +export enum StencilOp { + ZERO, + KEEP, + REPLACE, + INCR, + DECR, + INVERT, + INCR_WRAP, + DECR_WRAP, +} + +export enum BlendFactor { + ZERO, + ONE, + SRC_ALPHA, + DST_ALPHA, + ONE_MINUS_SRC_ALPHA, + ONE_MINUS_DST_ALPHA, + SRC_COLOR, + DST_COLOR, + ONE_MINUS_SRC_COLOR, + ONE_MINUS_DST_COLOR, + SRC_ALPHA_SATURATE, + CONSTANT_COLOR, + ONE_MINUS_CONSTANT_COLOR, + CONSTANT_ALPHA, + ONE_MINUS_CONSTANT_ALPHA, +} + +export enum BlendOp { + ADD, + SUB, + REV_SUB, + MIN, + MAX, +} + +export enum ColorMask { + NONE = 0x0, + R = 0x1, + G = 0x2, + B = 0x4, + A = 0x8, + ALL = R | G | B | A, +} + +export enum ShaderStageFlagBit { + NONE = 0x0, + VERTEX = 0x1, + CONTROL = 0x2, + EVALUATION = 0x4, + GEOMETRY = 0x8, + FRAGMENT = 0x10, + COMPUTE = 0x20, + ALL = 0x3f, +} + +export enum LoadOp { + LOAD, // Load the contents from the fbo from previous + CLEAR, // Clear the fbo + DISCARD, // Ignore writing to the fbo and keep old data +} + +export enum StoreOp { + STORE, // Write the source to the destination + DISCARD, // Don't write the source to the destination +} + +export enum AccessType { + NONE, + + // Read access + INDIRECT_BUFFER, // Read as an indirect buffer for drawing or dispatch + INDEX_BUFFER, // Read as an index buffer for drawing + VERTEX_BUFFER, // Read as a vertex buffer for drawing + VERTEX_SHADER_READ_UNIFORM_BUFFER, // Read as a uniform buffer in a vertex shader + VERTEX_SHADER_READ_TEXTURE, // Read as a sampled image/uniform texel buffer in a vertex shader + VERTEX_SHADER_READ_OTHER, // Read as any other resource in a vertex shader + FRAGMENT_SHADER_READ_UNIFORM_BUFFER, // Read as a uniform buffer in a fragment shader + FRAGMENT_SHADER_READ_TEXTURE, // Read as a sampled image/uniform texel buffer in a fragment shader + FRAGMENT_SHADER_READ_COLOR_INPUT_ATTACHMENT, // Read as an input attachment with a color format in a fragment shader + FRAGMENT_SHADER_READ_DEPTH_STENCIL_INPUT_ATTACHMENT, // Read as an input attachment with a depth/stencil format in a fragment shader + FRAGMENT_SHADER_READ_OTHER, // Read as any other resource in a fragment shader + COLOR_ATTACHMENT_READ, // Read by standard blending/logic operations or subpass load operations + DEPTH_STENCIL_ATTACHMENT_READ, // Read by depth/stencil tests or subpass load operations + COMPUTE_SHADER_READ_UNIFORM_BUFFER, // Read as a uniform buffer in a compute shader + COMPUTE_SHADER_READ_TEXTURE, // Read as a sampled image/uniform texel buffer in a compute shader + COMPUTE_SHADER_READ_OTHER, // Read as any other resource in a compute shader + TRANSFER_READ, // Read as the source of a transfer operation + HOST_READ, // Read on the host + PRESENT, // Read by the presentation engine + + // Write access + VERTEX_SHADER_WRITE, // Written as any resource in a vertex shader + FRAGMENT_SHADER_WRITE, // Written as any resource in a fragment shader + COLOR_ATTACHMENT_WRITE, // Written as a color attachment during rendering, or via a subpass store op + DEPTH_STENCIL_ATTACHMENT_WRITE, // Written as a depth/stencil attachment during rendering, or via a subpass store op + COMPUTE_SHADER_WRITE, // Written as any resource in a compute shader + TRANSFER_WRITE, // Written as the destination of a transfer operation + HOST_PREINITIALIZED, // Data pre-filled by host before device access starts + HOST_WRITE, // Written on the host +} + +export enum PipelineBindPoint { + GRAPHICS, + COMPUTE, + RAY_TRACING, +} export enum PrimitiveMode { POINT_LIST, @@ -360,282 +580,644 @@ export enum CullMode { BACK, } -export enum ComparisonFunc { - NEVER, - LESS, - EQUAL, - LESS_EQUAL, - GREATER, - NOT_EQUAL, - GREATER_EQUAL, - ALWAYS, -} - -export enum StencilOp { - ZERO, - KEEP, - REPLACE, - INCR, - DECR, - INVERT, - INCR_WRAP, - DECR_WRAP, -} - -export enum BlendOp { - ADD, - SUB, - REV_SUB, - MIN, - MAX, -} - -export enum BlendFactor { - ZERO, - ONE, - SRC_ALPHA, - DST_ALPHA, - ONE_MINUS_SRC_ALPHA, - ONE_MINUS_DST_ALPHA, - SRC_COLOR, - DST_COLOR, - ONE_MINUS_SRC_COLOR, - ONE_MINUS_DST_COLOR, - SRC_ALPHA_SATURATE, - CONSTANT_COLOR, - ONE_MINUS_CONSTANT_COLOR, - CONSTANT_ALPHA, - ONE_MINUS_CONSTANT_ALPHA, -} - -export enum ColorMask { - NONE = 0x0, - R = 0x1, - G = 0x2, - B = 0x4, - A = 0x8, - ALL = R | G | B | A, -} - -export enum Filter { - NONE, - POINT, - LINEAR, - ANISOTROPIC, -} - -export enum Address { - WRAP, - MIRROR, - CLAMP, - BORDER, -} - -export enum TextureType { - TEX1D, - TEX2D, - TEX3D, - CUBE, - TEX1D_ARRAY, - TEX2D_ARRAY, -} - -export enum TextureUsageBit { - NONE = 0, - TRANSFER_SRC = 0x1, - TRANSFER_DST = 0x2, - SAMPLED = 0x4, - STORAGE = 0x8, - COLOR_ATTACHMENT = 0x10, - DEPTH_STENCIL_ATTACHMENT = 0x20, - TRANSIENT_ATTACHMENT = 0x40, - INPUT_ATTACHMENT = 0x80, -} - -export type TextureUsage = TextureUsageBit; - -export enum SampleCount { - X1, - X2, - X4, - X8, - X16, - X32, - X64, -} - -export enum TextureFlagBit { - NONE = 0, - GEN_MIPMAP = 0x1, - CUBEMAP = 0x2, - BAKUP_BUFFER = 0x4, - IMMUTABLE = 0x8, -} -export type TextureFlags = TextureFlagBit; - -export enum ShaderStageFlagBit { - NONE = 0, - VERTEX = 0x1, - CONTROL = 0x2, - EVALUATION = 0x4, - GEOMETRY = 0x8, - FRAGMENT = 0x10, - COMPUTE = 0x20, - ALL = 0x3f, -} -export type ShaderStageFlags = ShaderStageFlagBit; - -export enum DescriptorType { - UNKNOWN = 0, - UNIFORM_BUFFER = 0x1, - DYNAMIC_UNIFORM_BUFFER = 0x2, - STORAGE_BUFFER = 0x4, - DYNAMIC_STORAGE_BUFFER = 0x8, - SAMPLER = 0x10, -} - -export enum CommandBufferType { - PRIMARY, - SECONDARY, -} - -export enum LoadOp { - LOAD, // Load the previous data - CLEAR, // Clear the fbo - DISCARD, // Ignore the previous data -} - -export enum StoreOp { - STORE, // Write the source to the destination - DISCARD, // Don't write the source to the destination -} - -export enum TextureLayout { - UNDEFINED, - GENERAL, - COLOR_ATTACHMENT_OPTIMAL, - DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - DEPTH_STENCIL_READONLY_OPTIMAL, - SHADER_READONLY_OPTIMAL, - TRANSFER_SRC_OPTIMAL, - TRANSFER_DST_OPTIMAL, - PREINITIALIZED, - PRESENT_SRC, -} - -export enum PipelineBindPoint { - GRAPHICS, - COMPUTE, - RAY_TRACING, -} - export enum DynamicStateFlagBit { - NONE = 0x0, - VIEWPORT = 0x1, - SCISSOR = 0x2, - LINE_WIDTH = 0x4, - DEPTH_BIAS = 0x8, - BLEND_CONSTANTS = 0x10, - DEPTH_BOUNDS = 0x20, - STENCIL_WRITE_MASK = 0x40, + NONE = 0x0, + VIEWPORT = 0x1, + SCISSOR = 0x2, + LINE_WIDTH = 0x4, + DEPTH_BIAS = 0x8, + BLEND_CONSTANTS = 0x10, + DEPTH_BOUNDS = 0x20, + STENCIL_WRITE_MASK = 0x40, STENCIL_COMPARE_MASK = 0x80, } -export type DynamicStateFlags = DynamicStateFlagBit; - export enum StencilFace { FRONT, BACK, ALL, } +export enum DescriptorType { + UNKNOWN = 0, + UNIFORM_BUFFER = 0x1, + DYNAMIC_UNIFORM_BUFFER = 0x2, + STORAGE_BUFFER = 0x4, + DYNAMIC_STORAGE_BUFFER = 0x8, + SAMPLER_TEXTURE = 0x10, + SAMPLER = 0x20, + TEXTURE = 0x40, + STORAGE_IMAGE = 0x80, + INPUT_ATTACHMENT = 0x100, +} + export enum QueueType { GRAPHICS, COMPUTE, TRANSFER, } -export enum ClearFlag { - NONE = 0, - COLOR = 1, - DEPTH = 2, - STENCIL = 4, +export enum CommandBufferType { + PRIMARY, + SECONDARY, +} + +export enum ClearFlagBit { + NONE = 0, + COLOR = 0x1, + DEPTH = 0x2, + STENCIL = 0x4, DEPTH_STENCIL = DEPTH | STENCIL, - ALL = COLOR | DEPTH | STENCIL, + ALL = COLOR | DEPTH | STENCIL, } -export enum FormatType { - NONE, - UNORM, - SNORM, - UINT, - INT, - UFLOAT, - FLOAT, +export type BufferUsage = BufferUsageBit; +export type BufferFlags = BufferFlagBit; +export type MemoryAccess = MemoryAccessBit; +export type MemoryUsage = MemoryUsageBit; +export type TextureUsage = TextureUsageBit; +export type TextureFlags = TextureFlagBit; +export type ShaderStageFlags = ShaderStageFlagBit; +export type DynamicStateFlags = DynamicStateFlagBit; +export type ClearFlags = ClearFlagBit; + +export class Size { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public x: number = 0, + public y: number = 0, + public z: number = 0, + ) {} } -export enum API { - UNKNOWN, - GLES2, - GLES3, - METAL, - VULKAN, - WEBGL, - WEBGL2, - WEBGPU, +export class DeviceCaps { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public maxVertexAttributes: number = 0, + public maxVertexUniformVectors: number = 0, + public maxFragmentUniformVectors: number = 0, + public maxTextureUnits: number = 0, + public maxImageUnits: number = 0, + public maxVertexTextureUnits: number = 0, + public maxColorRenderTargets: number = 0, + public maxShaderStorageBufferBindings: number = 0, + public maxShaderStorageBlockSize: number = 0, + public maxUniformBufferBindings: number = 0, + public maxUniformBlockSize: number = 0, + public maxTextureSize: number = 0, + public maxCubeMapTextureSize: number = 0, + public uboOffsetAlignment: number = 0, + public depthBits: number = 0, + public stencilBits: number = 0, + public maxComputeSharedMemorySize: number = 0, + public maxComputeWorkGroupInvocations: number = 0, + public maxComputeWorkGroupSize: Size = new Size(), + public maxComputeWorkGroupCount: Size = new Size(), + public clipSpaceMinZ: number = -1, + public screenSpaceSignY: number = 1, + public UVSpaceSignY: number = -1, + ) {} } -export enum SurfaceTransform { - IDENTITY, - ROTATE_90, - ROTATE_180, - ROTATE_270, +export class Offset { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public x: number = 0, + public y: number = 0, + public z: number = 0, + ) {} } -export enum Feature { - COLOR_FLOAT, - COLOR_HALF_FLOAT, - TEXTURE_FLOAT, - TEXTURE_HALF_FLOAT, - TEXTURE_FLOAT_LINEAR, - TEXTURE_HALF_FLOAT_LINEAR, - FORMAT_R11G11B10F, - FORMAT_D16, - FORMAT_D16S8, - FORMAT_D24, - FORMAT_D24S8, - FORMAT_D32F, - FORMAT_D32FS8, - FORMAT_ETC1, - FORMAT_ETC2, - FORMAT_DXT, - FORMAT_PVRTC, - FORMAT_ASTC, - FORMAT_RGB8, - MSAA, - ELEMENT_INDEX_UINT, - INSTANCED_ARRAYS, - MULTIPLE_RENDER_TARGETS, - BLEND_MINMAX, - DEPTH_BOUNDS, - LINE_WIDTH, - STENCIL_WRITE_MASK, - STENCIL_COMPARE_MASK, - COUNT, +export class Rect { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public x: number = 0, + public y: number = 0, + public width: number = 1, + public height: number = 1, + ) {} +} + +export class Extent { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public width: number = 0, + public height: number = 0, + public depth: number = 1, + ) {} +} + +export class TextureSubresLayers { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public mipLevel: number = 0, + public baseArrayLayer: number = 0, + public layerCount: number = 1, + ) {} +} + +export class TextureSubresRange { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public baseMipLevel: number = 0, + public levelCount: number = 1, + public baseArrayLayer: number = 0, + public layerCount: number = 1, + ) {} +} + +export class TextureCopy { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public srcSubres: TextureSubresLayers = new TextureSubresLayers(), + public srcOffset: Offset = new Offset(), + public dstSubres: TextureSubresLayers = new TextureSubresLayers(), + public dstOffset: Offset = new Offset(), + public extent: Extent = new Extent(), + ) {} +} + +export class TextureBlit { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public srcSubres: TextureSubresLayers = new TextureSubresLayers(), + public srcOffset: Offset = new Offset(), + public srcExtent: Extent = new Extent(), + public dstSubres: TextureSubresLayers = new TextureSubresLayers(), + public dstOffset: Offset = new Offset(), + public dstExtent: Extent = new Extent(), + ) {} +} + +export class BufferTextureCopy { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public buffStride: number = 0, + public buffTexHeight: number = 0, + public texOffset: Offset = new Offset(), + public texExtent: Extent = new Extent(), + public texSubres: TextureSubresLayers = new TextureSubresLayers(), + ) {} +} + +export class Viewport { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public left: number = 0, + public top: number = 0, + public width: number = 0, + public height: number = 0, + public minDepth: number = 0, + public maxDepth: number = 1, + ) {} +} + +export class Color { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public x: number = 0, + public y: number = 0, + public z: number = 0, + public w: number = 0, + ) {} +} + +export class BindingMappingInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public bufferOffsets: number[] = [], + public samplerOffsets: number[] = [], + public flexibleSet: number = 0, + ) {} +} + +export class BufferInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public usage: BufferUsage = BufferUsageBit.NONE, + public memUsage: MemoryUsage = MemoryUsageBit.NONE, + public size: number = 0, + public stride: number = 0, + public flags: BufferFlags = BufferFlagBit.NONE, + ) {} +} + +export class BufferViewInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public buffer: Buffer = null!, + public offset: number = 0, + public range: number = 0, + ) {} +} + +export class DrawInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public vertexCount: number = 0, + public firstVertex: number = 0, + public indexCount: number = 0, + public firstIndex: number = 0, + public vertexOffset: number = 0, + public instanceCount: number = 0, + public firstInstance: number = 0, + ) {} +} + +export class DispatchInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public groupCountX: number = 0, + public groupCountY: number = 0, + public groupCountZ: number = 0, + public indirectBuffer: Buffer | null = null, + public indirectOffset: number = 0, + ) {} +} + +export class IndirectBuffer { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public drawInfos: DrawInfo[] = [], + ) {} +} + +export class TextureInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public type: TextureType = TextureType.TEX2D, + public usage: TextureUsage = TextureUsageBit.NONE, + public format: Format = Format.UNKNOWN, + public width: number = 0, + public height: number = 0, + public flags: TextureFlags = TextureFlagBit.NONE, + public layerCount: number = 1, + public levelCount: number = 1, + public samples: SampleCount = SampleCount.X1, + public depth: number = 1, + ) {} +} + +export class TextureViewInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public texture: Texture = null!, + public type: TextureType = TextureType.TEX2D, + public format: Format = Format.UNKNOWN, + public baseLevel: number = 0, + public levelCount: number = 1, + public baseLayer: number = 0, + public layerCount: number = 1, + ) {} +} + +export class SamplerInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public minFilter: Filter = Filter.LINEAR, + public magFilter: Filter = Filter.LINEAR, + public mipFilter: Filter = Filter.NONE, + public addressU: Address = Address.WRAP, + public addressV: Address = Address.WRAP, + public addressW: Address = Address.WRAP, + public maxAnisotropy: number = 0, + public cmpFunc: ComparisonFunc = ComparisonFunc.NEVER, + public borderColor: Color = new Color(), + public minLOD: number = 0, + public maxLOD: number = 1000, + public mipLODBias: number = 0, + ) {} +} + +export class ShaderMacro { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public macro: string = '', + public value: string = '', + ) {} +} + +export class Uniform { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public name: string = '', + public type: Type = Type.UNKNOWN, + public count: number = 0, + ) {} +} + +export class UniformBlock { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public members: Uniform[] = [], + public count: number = 0, + ) {} +} + +export class UniformSamplerTexture { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public type: Type = Type.UNKNOWN, + public count: number = 0, + ) {} +} + +export class UniformSampler { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public count: number = 0, + ) {} +} + +export class UniformTexture { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public type: Type = Type.UNKNOWN, + public count: number = 0, + ) {} +} + +export class UniformStorageImage { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public type: Type = Type.UNKNOWN, + public count: number = 0, + public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE, + ) {} +} + +export class UniformStorageBuffer { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public count: number = 0, + public memoryAccess: MemoryAccess = MemoryAccessBit.READ_WRITE, + ) {} +} + +export class UniformInputAttachment { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public set: number = 0, + public binding: number = 0, + public name: string = '', + public count: number = 0, + ) {} +} + +export class ShaderStage { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public stage: ShaderStageFlagBit = ShaderStageFlagBit.NONE, + public source: string = '', + ) {} +} + +export class Attribute { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public name: string = '', + public format: Format = Format.UNKNOWN, + public isNormalized: boolean = false, + public stream: number = 0, + public isInstanced: boolean = false, + public location: number = 0, + ) {} +} + +export class ShaderInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public name: string = '', + public stages: ShaderStage[] = [], + public attributes: Attribute[] = [], + public blocks: UniformBlock[] = [], + public buffers: UniformStorageBuffer[] = [], + public samplerTextures: UniformSamplerTexture[] = [], + public samplers: UniformSampler[] = [], + public textures: UniformTexture[] = [], + public images: UniformStorageImage[] = [], + public subpassInputs: UniformInputAttachment[] = [], + ) {} +} + +export class InputAssemblerInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public attributes: Attribute[] = [], + public vertexBuffers: Buffer[] = [], + public indexBuffer: Buffer | null = null, + public indirectBuffer: Buffer | null = null, + ) {} +} + +export class ColorAttachment { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public format: Format = Format.UNKNOWN, + public sampleCount: SampleCount = SampleCount.X1, + public loadOp: LoadOp = LoadOp.CLEAR, + public storeOp: StoreOp = StoreOp.STORE, + public beginAccesses: AccessType[] = [], + public endAccesses: AccessType[] = [AccessType.PRESENT], + ) {} +} + +export class DepthStencilAttachment { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public format: Format = Format.UNKNOWN, + public sampleCount: SampleCount = SampleCount.X1, + public depthLoadOp: LoadOp = LoadOp.CLEAR, + public depthStoreOp: StoreOp = StoreOp.STORE, + public stencilLoadOp: LoadOp = LoadOp.CLEAR, + public stencilStoreOp: StoreOp = StoreOp.STORE, + public beginAccesses: AccessType[] = [], + public endAccesses: AccessType[] = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE], + ) {} +} + +export class SubpassInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public inputs: number[] = [], + public colors: number[] = [], + public resolves: number[] = [], + public preserves: number[] = [], + public depthStencil: number = -1, + ) {} +} + +export class RenderPassInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public colorAttachments: ColorAttachment[] = [], + public depthStencilAttachment: DepthStencilAttachment = new DepthStencilAttachment(), + public subpasses: SubpassInfo[] = [], + ) {} +} + +export class GlobalBarrierInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public prevAccesses: AccessType[] = [], + public nextAccesses: AccessType[] = [], + ) {} +} + +export class TextureBarrierInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public prevAccesses: AccessType[] = [], + public nextAccesses: AccessType[] = [], + public discardContents: boolean = false, + public srcQueue: Queue | null = null, + public dstQueue: Queue | null = null, + ) {} +} + +export class FramebufferInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public renderPass: RenderPass = null!, + public colorTextures: (Texture | null)[] = [], + public depthStencilTexture: Texture | null = null, + public colorMipmapLevels: number[] = [], + public depthStencilMipmapLevel: number = 0, + ) {} +} + +export class DescriptorSetLayoutBinding { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public binding: number = -1, + public descriptorType: DescriptorType = DescriptorType.UNKNOWN, + public count: number = 0, + public stageFlags: ShaderStageFlags = ShaderStageFlagBit.NONE, + public immutableSamplers: Sampler[] = [], + ) {} +} + +export class DescriptorSetLayoutInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public bindings: DescriptorSetLayoutBinding[] = [], + ) {} +} + +export class DescriptorSetInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public layout: DescriptorSetLayout = null!, + ) {} +} + +export class PipelineLayoutInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public setLayouts: DescriptorSetLayout[] = [], + ) {} +} + +export class InputState { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public attributes: Attribute[] = [], + ) {} +} + +export class CommandBufferInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public queue: Queue = null!, + public type: CommandBufferType = CommandBufferType.PRIMARY, + ) {} +} + +export class QueueInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public type: QueueType = QueueType.GRAPHICS, + ) {} } export class FormatInfo { declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object constructor ( - public readonly name: string, - public readonly size: number, - public readonly count: number, - public readonly type: FormatType, - public readonly hasAlpha: boolean, - public readonly hasDepth: boolean, - public readonly hasStencil: boolean, - public readonly isCompressed: boolean, + public readonly name: string = '', + public readonly size: number = 0, + public readonly count: number = 0, + public readonly type: FormatType = FormatType.NONE, + public readonly hasAlpha: boolean = false, + public readonly hasDepth: boolean = false, + public readonly hasStencil: boolean = false, + public readonly isCompressed: boolean = false, ) {} } @@ -648,6 +1230,98 @@ export class MemoryStatus { ) {} } +/** + * ========================= !DO NOT CHANGE THE ABOVE SECTION MANUALLY! ========================= + * The above section is auto-generated from engine-native/cocos/renderer/core/gfx/GFXDef-common.h + * by the script engine-native/tools/gfx-define-generator/generate.js. + * Changes to these public interfaces should be made there first and synced back. + * ========================= !DO NOT CHANGE THE ABOVE SECTION MANUALLY! ========================= + */ + +/** + * @en GFX base object. + * @zh GFX 基类对象。 + */ +export class Obj { + public get gfxType (): ObjectType { + return this._gfxType; + } + + protected _gfxType = ObjectType.UNKNOWN; + + constructor (gfxType: ObjectType) { + this._gfxType = gfxType; + } +} + +export class DeviceInfo { + declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object + + constructor ( + public canvasElm: HTMLElement, + public isAntialias: boolean = true, + public isPremultipliedAlpha: boolean = true, + public devicePixelRatio: number = 1, + public nativeWidth: number = 1, + public nativeHeight: number = 1, + /** + * For non-vulkan backends, to maintain compatibility and maximize + * descriptor cache-locality, descriptor-set-based binding numbers need + * to be mapped to backend-specific bindings based on the maximum limit + * of available descriptor slots in each set. + * + * The GFX layer assumes the binding numbers for each descriptor type inside each set + * are guaranteed to be consecutive, so the mapping procedure is reduced + * to a simple shifting operation. This data structure specifies the + * offsets for each descriptor type in each set. + */ + public bindingMappingInfo = new BindingMappingInfo(), + ) {} +} + +export interface IUniform { + name: string; + type: Type; + count: number; +} + +export interface IShaderStage { + stage: ShaderStageFlagBit; + source: string; +} + +export interface IAttribute { + name: string; + format: Format; + isNormalized: boolean; + stream: number; + isInstanced: boolean; + location: number; +} + +export enum AttributeName { + ATTR_POSITION = 'a_position', + ATTR_NORMAL = 'a_normal', + ATTR_TANGENT = 'a_tangent', + ATTR_BITANGENT = 'a_bitangent', + ATTR_WEIGHTS = 'a_weights', + ATTR_JOINTS = 'a_joints', + ATTR_COLOR = 'a_color', + ATTR_COLOR1 = 'a_color1', + ATTR_COLOR2 = 'a_color2', + ATTR_TEX_COORD = 'a_texCoord', + ATTR_TEX_COORD1 = 'a_texCoord1', + ATTR_TEX_COORD2 = 'a_texCoord2', + ATTR_TEX_COORD3 = 'a_texCoord3', + ATTR_TEX_COORD4 = 'a_texCoord4', + ATTR_TEX_COORD5 = 'a_texCoord5', + ATTR_TEX_COORD6 = 'a_texCoord6', + ATTR_TEX_COORD7 = 'a_texCoord7', + ATTR_TEX_COORD8 = 'a_texCoord8', + ATTR_BATCH_ID = 'a_batch_id', + ATTR_BATCH_UV = 'a_batch_uv', +} + export const FormatInfos = Object.freeze([ new FormatInfo('UNKNOWN', 0, 0, FormatType.NONE, false, false, false, false), @@ -785,6 +1459,22 @@ export const FormatInfos = Object.freeze([ new FormatInfo('ASTC_SRGBA_12x12', 1, 4, FormatType.UNORM, true, false, false, true), ]); +export const DESCRIPTOR_BUFFER_TYPE = DescriptorType.UNIFORM_BUFFER | DescriptorType.DYNAMIC_UNIFORM_BUFFER + | DescriptorType.STORAGE_BUFFER | DescriptorType.DYNAMIC_STORAGE_BUFFER; + +export const DESCRIPTOR_SAMPLER_TYPE = DescriptorType.SAMPLER_TEXTURE | DescriptorType.SAMPLER | DescriptorType.TEXTURE + | DescriptorType.STORAGE_IMAGE | DescriptorType.INPUT_ATTACHMENT; + +export const DESCRIPTOR_DYNAMIC_TYPE = DescriptorType.DYNAMIC_STORAGE_BUFFER | DescriptorType.DYNAMIC_UNIFORM_BUFFER; + +export const DRAW_INFO_SIZE = 28; + +export type BufferSource = ArrayBuffer | IndirectBuffer; + +export function IsPowerOf2 (x: number): boolean { + return x > 0 && (x & (x - 1)) === 0; +} + /** * @en Get memory size of the specified fomat. * @zh 获取指定格式对应的内存大小。 @@ -967,6 +1657,7 @@ export function getTypedArrayConstructor (info: FormatInfo): TypedArrayConstruct case 1: return Uint8Array; case 2: return Uint16Array; case 4: return Uint32Array; + default: } break; } @@ -976,12 +1667,14 @@ export function getTypedArrayConstructor (info: FormatInfo): TypedArrayConstruct case 1: return Int8Array; case 2: return Int16Array; case 4: return Int32Array; + default: } break; } case FormatType.FLOAT: { return Float32Array; } + default: } return Float32Array; } diff --git a/cocos/core/gfx/deprecated-3.0.0.ts b/cocos/core/gfx/deprecated-3.0.0.ts index c056d81e21..af93d770b9 100644 --- a/cocos/core/gfx/deprecated-3.0.0.ts +++ b/cocos/core/gfx/deprecated-3.0.0.ts @@ -30,194 +30,34 @@ import { polyfillCC } from './polyfill-legacy-cc'; import { removeProperty, replaceProperty } from '../utils/x-deprecated'; import { legacyCC } from '../global-exports'; - -import { DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, DescriptorSetInfo, DescriptorSet } from './descriptor-set'; -import { DrawInfo, DRAW_INFO_SIZE, IndirectBuffer, BufferSource, BufferInfo, BufferViewInfo, Buffer } from './buffer'; -import { CommandBufferInfo, CommandBuffer } from './command-buffer'; -import { MAX_ATTACHMENTS, ObjectType, Obj, AttributeName, Type, Format, BufferUsageBit, BufferUsage, MemoryUsageBit, - MemoryUsage, BufferFlagBit, BufferFlags, BufferAccessBit, BufferAccess, PrimitiveMode, PolygonMode, ShadeModel, - CullMode, ComparisonFunc, StencilOp, BlendOp, BlendFactor, ColorMask, Filter, Address, TextureType, TextureUsageBit, - TextureUsage, SampleCount, TextureFlagBit, TextureFlags, ShaderStageFlagBit, ShaderStageFlags, DescriptorType, - CommandBufferType, LoadOp, StoreOp, TextureLayout, PipelineBindPoint, DynamicStateFlagBit, DynamicStateFlags, - StencilFace, QueueType, ClearFlag, FormatType, API, SurfaceTransform, Feature, FormatInfo, MemoryStatus, - FormatInfos, FormatSize, FormatSurfaceSize } from './define'; -import { Rect, Viewport, Color, Offset, Extent, TextureSubres, TextureCopy, BufferTextureCopy } from './define-class'; -import { BindingMappingInfo, DeviceInfo, Device } from './device'; -import { FramebufferInfo, Framebuffer } from './framebuffer'; -import { IAttribute, Attribute, InputAssemblerInfo, InputAssembler } from './input-assembler'; -import { DescriptorSetLayoutBinding, DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE, DescriptorSetLayout } from './descriptor-set-layout'; -import { PipelineLayoutInfo, PipelineLayout } from './pipeline-layout'; -import { RasterizerState, DepthStencilState, BlendTarget, BlendState, InputState, PipelineStateInfo, PipelineState } from './pipeline-state'; -import { FenceInfo, Fence } from './fence'; -import { QueueInfo, Queue } from './queue'; -import { ColorAttachment, DepthStencilAttachment, SubPassInfo, RenderPassInfo, RenderPass } from './render-pass'; -import { SamplerInfo, Sampler } from './sampler'; -import { IShaderStage, ShaderStage, IUniform, Uniform, UniformBlock, UniformSampler, ShaderInfo, Shader } from './shader'; -import { TextureInfo, TextureViewInfo, Texture } from './texture'; +import { CommandBuffer } from './command-buffer'; replaceProperty(legacyCC, 'cc', [ - { - name: 'GFXDynamicState', - newName: 'DynamicStateFlagBit', - }, - { - name: 'GFXBindingType', - newName: 'DescriptorType', - }, - { - name: 'GFXBindingLayout', - newName: 'DescriptorSet', - }, + { name: 'GFXDynamicState', newName: 'DynamicStateFlagBit' }, + { name: 'GFXBindingType', newName: 'DescriptorType' }, + { name: 'GFXBindingLayout', newName: 'DescriptorSet' }, ]); removeProperty(CommandBuffer.prototype, 'CommandBuffer.prototype', [ - { - name: 'bindBindingLayout', - suggest: 'Use `bindDescriptorSet` instead', - }, + { name: 'bindBindingLayout', suggest: 'Use `bindDescriptorSet` instead' }, ]); -// Deprecate GFX prefix APIs - -export type GFXBufferSource = BufferSource; -export type GFXBufferUsage = BufferUsage; -export type GFXMemoryUsage = MemoryUsage; -export type GFXBufferFlags = BufferFlags; -export type GFXBufferAccess = BufferAccess; -export type GFXTextureUsage = TextureUsage; -export type GFXTextureFlags = TextureFlags; -export type GFXShaderStageFlags = ShaderStageFlags; -export type GFXDynamicStateFlags = DynamicStateFlags; -export type IGFXAttribute = IAttribute; -export type IGFXShaderStage = IShaderStage; -export type IGFXUniform = IUniform; - -export { DESCRIPTOR_BUFFER_TYPE as GFX_DESCRIPTOR_BUFFER_TYPE }; -export { DESCRIPTOR_SAMPLER_TYPE as GFX_DESCRIPTOR_SAMPLER_TYPE }; -export { DescriptorSetInfo as GFXDescriptorSetInfo }; -export { DescriptorSet as GFXDescriptorSet }; -export { DrawInfo as GFXDrawInfo }; -export { DRAW_INFO_SIZE as GFX_DRAW_INFO_SIZE }; -export { IndirectBuffer as GFXIndirectBuffer }; -export { BufferInfo as GFXBufferInfo }; -export { BufferViewInfo as GFXBufferViewInfo }; -export { Buffer as GFXBuffer }; -export { CommandBufferInfo as GFXCommandBufferInfo }; -export { CommandBuffer as GFXCommandBuffer }; -export { MAX_ATTACHMENTS as GFX_MAX_ATTACHMENTS }; -export { ObjectType as GFXObjectType }; -export { Obj as GFXObject }; -export { AttributeName as GFXAttributeName }; -export { Type as GFXType }; -export { Format as GFXFormat }; -export { BufferUsageBit as GFXBufferUsageBit }; -export { MemoryUsageBit as GFXMemoryUsageBit }; -export { BufferFlagBit as GFXBufferFlagBit }; -export { BufferAccessBit as GFXBufferAccessBit }; -export { PrimitiveMode as GFXPrimitiveMode }; -export { PolygonMode as GFXPolygonMode }; -export { ShadeModel as GFXShadeModel }; -export { CullMode as GFXCullMode }; -export { ComparisonFunc as GFXComparisonFunc }; -export { StencilOp as GFXStencilOp }; -export { BlendOp as GFXBlendOp }; -export { BlendFactor as GFXBlendFactor }; -export { ColorMask as GFXColorMask }; -export { Filter as GFXFilter }; -export { Address as GFXAddress }; -export { TextureType as GFXTextureType }; -export { TextureUsageBit as GFXTextureUsageBit }; -export { SampleCount as GFXSampleCount }; -export { TextureFlagBit as GFXTextureFlagBit }; -export { ShaderStageFlagBit as GFXShaderStageFlagBit }; -export { DescriptorType as GFXDescriptorType }; -export { CommandBufferType as GFXCommandBufferType }; -export { LoadOp as GFXLoadOp }; -export { StoreOp as GFXStoreOp }; -export { TextureLayout as GFXTextureLayout }; -export { PipelineBindPoint as GFXPipelineBindPoint }; -export { DynamicStateFlagBit as GFXDynamicStateFlagBit }; -export { StencilFace as GFXStencilFace }; -export { QueueType as GFXQueueType }; -export { ClearFlag as GFXClearFlag }; -export { FormatType as GFXFormatType }; -export { API as GFXAPI }; -export { SurfaceTransform as GFXSurfaceTransform }; -export { Feature as GFXFeature }; -export { FormatInfo as GFXFormatInfo }; -export { MemoryStatus as GFXMemoryStatus }; -export { FormatInfos as GFXFormatInfos }; -export { FormatSize as GFXFormatSize }; -export { FormatSurfaceSize as GFXFormatSurfaceSize }; -export { Rect as GFXRect }; -export { Viewport as GFXViewport }; -export { Color as GFXColor }; -export { Offset as GFXOffset }; -export { Extent as GFXExtent }; -export { TextureSubres as GFXTextureSubres }; -export { TextureCopy as GFXTextureCopy }; -export { BufferTextureCopy as GFXBufferTextureCopy }; -export { BindingMappingInfo as GFXBindingMappingInfo }; -export { DeviceInfo as GFXDeviceInfo }; -export { Device as GFXDevice }; -export { FramebufferInfo as GFXFramebufferInfo }; -export { Framebuffer as GFXFramebuffer }; -export { Attribute as GFXAttribute }; -export { InputAssemblerInfo as GFXInputAssemblerInfo }; -export { InputAssembler as GFXInputAssembler }; -export { DescriptorSetLayoutBinding as GFXDescriptorSetLayoutBinding }; -export { DescriptorSetLayoutInfo as GFXDescriptorSetLayoutInfo }; -export { DESCRIPTOR_DYNAMIC_TYPE as GFX_DESCRIPTOR_DYNAMIC_TYPE }; -export { DescriptorSetLayout as GFXDescriptorSetLayout }; -export { PipelineLayoutInfo as GFXPipelineLayoutInfo }; -export { PipelineLayout as GFXPipelineLayout }; -export { RasterizerState as GFXRasterizerState }; -export { DepthStencilState as GFXDepthStencilState }; -export { BlendTarget as GFXBlendTarget }; -export { BlendState as GFXBlendState }; -export { InputState as GFXInputState }; -export { PipelineStateInfo as GFXPipelineStateInfo }; -export { PipelineState as GFXPipelineState }; -export { FenceInfo as GFXFenceInfo }; -export { Fence as GFXFence }; -export { QueueInfo as GFXQueueInfo }; -export { Queue as GFXQueue }; -export { ColorAttachment as GFXColorAttachment }; -export { DepthStencilAttachment as GFXDepthStencilAttachment }; -export { SubPassInfo as GFXSubPassInfo }; -export { RenderPassInfo as GFXRenderPassInfo }; -export { RenderPass as GFXRenderPass }; -export { SamplerInfo as GFXSamplerInfo }; -export { Sampler as GFXSampler }; -export { ShaderStage as GFXShaderStage }; -export { Uniform as GFXUniform }; -export { UniformBlock as GFXUniformBlock }; -export { UniformSampler as GFXUniformSampler }; -export { ShaderInfo as GFXShaderInfo }; -export { Shader as GFXShader }; -export { TextureInfo as GFXTextureInfo }; -export { TextureViewInfo as GFXTextureViewInfo }; -export { Texture as GFXTexture }; - // Deprecated CC polyfill -const special = { - // Special replacement +const customMappings = { // DRAW_INFO_SIZE: 'GFX_DRAW_INFO_SIZE', - MAX_ATTACHMENTS: 'GFX_MAX_ATTACHMENTS', - Obj: 'GFXObject', - - // Unchanged + // MAX_ATTACHMENTS: 'GFX_MAX_ATTACHMENTS', + // Obj: 'GFXObject', // DESCRIPTOR_BUFFER_TYPE: '', // DESCRIPTOR_SAMPLER_TYPE: '', - getTypedArrayConstructor: '', + // getTypedArrayConstructor: '', // GFXFormatToWebGLType: '', // GFXFormatToWebGLInternalFormat: '', // GFXFormatToWebGLFormat: '', }; for (const api in polyfillCC) { - let deprecated = special[api]; + let deprecated = customMappings[api]; if (deprecated === '') { - continue; + deprecated = api; } else if (deprecated === undefined) { deprecated = `GFX${api}`; } diff --git a/cocos/core/gfx/descriptor-set-layout.ts b/cocos/core/gfx/descriptor-set-layout.ts index add0c45225..da585b606f 100644 --- a/cocos/core/gfx/descriptor-set-layout.ts +++ b/cocos/core/gfx/descriptor-set-layout.ts @@ -29,30 +29,7 @@ */ import { Device } from './device'; -import { Sampler } from './sampler'; -import { DescriptorType, Obj, ObjectType, ShaderStageFlagBit, ShaderStageFlags } from './define'; - -export class DescriptorSetLayoutBinding { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public binding: number = -1, - public descriptorType: DescriptorType = DescriptorType.UNKNOWN, - public count: number = 0, - public stageFlags: ShaderStageFlags = ShaderStageFlagBit.NONE, - public immutableSamplers: Sampler[] = [], - ) {} -} - -export class DescriptorSetLayoutInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public bindings: DescriptorSetLayoutBinding[] = [], - ) {} -} - -export const DESCRIPTOR_DYNAMIC_TYPE = DescriptorType.DYNAMIC_STORAGE_BUFFER | DescriptorType.DYNAMIC_UNIFORM_BUFFER; +import { Obj, ObjectType, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo } from './define'; /** * @en GFX descriptor sets layout. diff --git a/cocos/core/gfx/descriptor-set.ts b/cocos/core/gfx/descriptor-set.ts index 61eb8fea16..2e40c97e81 100644 --- a/cocos/core/gfx/descriptor-set.ts +++ b/cocos/core/gfx/descriptor-set.ts @@ -33,20 +33,7 @@ import { DescriptorSetLayout } from './descriptor-set-layout'; import { Device } from './device'; import { Sampler } from './sampler'; import { Texture } from './texture'; -import { DescriptorType, Obj, ObjectType } from './define'; - -export const DESCRIPTOR_BUFFER_TYPE = DescriptorType.UNIFORM_BUFFER | DescriptorType.DYNAMIC_UNIFORM_BUFFER - | DescriptorType.STORAGE_BUFFER | DescriptorType.DYNAMIC_STORAGE_BUFFER; - -export const DESCRIPTOR_SAMPLER_TYPE = DescriptorType.SAMPLER; - -export class DescriptorSetInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public layout: DescriptorSetLayout, - ) {} -} +import { Obj, ObjectType, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from './define'; /** * @en GFX descriptor sets. diff --git a/cocos/core/gfx/device.ts b/cocos/core/gfx/device.ts index 8320e19ca7..c796c58be6 100644 --- a/cocos/core/gfx/device.ts +++ b/cocos/core/gfx/device.ts @@ -28,61 +28,29 @@ * @module gfx */ -import { Command } from 'commander'; import { ccenum } from '../value-types/enum'; -import { gfx } from '../../../exports/base'; -import { API, Feature, Filter, Format, MemoryStatus, SurfaceTransform } from './define'; -import { Buffer, BufferInfo, BufferViewInfo } from './buffer'; -import { BufferTextureCopy, Rect } from './define-class'; -import { CommandBuffer, CommandBufferInfo } from './command-buffer'; -import { DescriptorSet, DescriptorSetInfo } from './descriptor-set'; -import { Fence, FenceInfo } from './fence'; -import { Framebuffer, FramebufferInfo } from './framebuffer'; -import { InputAssembler, InputAssemblerInfo } from './input-assembler'; +import { + API, Feature, Filter, Format, MemoryStatus, SurfaceTransform, Rect, + CommandBufferInfo, BufferInfo, BufferViewInfo, TextureInfo, TextureViewInfo, SamplerInfo, DescriptorSetInfo, + ShaderInfo, InputAssemblerInfo, RenderPassInfo, FramebufferInfo, DescriptorSetLayoutInfo, PipelineLayoutInfo, + QueueInfo, BufferTextureCopy, DeviceInfo, DeviceCaps, +} from './define'; +import { Buffer } from './buffer'; +import { CommandBuffer } from './command-buffer'; +import { DescriptorSet } from './descriptor-set'; +import { DescriptorSetLayout } from './descriptor-set-layout'; +import { PipelineLayout } from './pipeline-layout'; +import { Framebuffer } from './framebuffer'; +import { InputAssembler } from './input-assembler'; import { PipelineState, PipelineStateInfo } from './pipeline-state'; -import { Queue, QueueInfo } from './queue'; -import { RenderPass, RenderPassInfo } from './render-pass'; -import { Sampler, SamplerInfo } from './sampler'; -import { Shader, ShaderInfo } from './shader'; -import { Texture, TextureInfo, TextureViewInfo } from './texture'; +import { Queue } from './queue'; +import { RenderPass } from './render-pass'; +import { Sampler } from './sampler'; +import { Shader } from './shader'; +import { Texture } from './texture'; ccenum(Format); -export class BindingMappingInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public bufferOffsets: number[] = [], - public samplerOffsets: number[] = [], - public flexibleSet: number = 0, - ) {} -} - -export class DeviceInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public canvasElm: HTMLElement, - public isAntialias: boolean = true, - public isPremultipliedAlpha: boolean = true, - public devicePixelRatio: number = 1, - public nativeWidth: number = 1, - public nativeHeight: number = 1, - /** - * For non-vulkan backends, to maintain compatibility and maximize - * descriptor cache-locality, descriptor-set-based binding numbers need - * to be mapped to backend-specific bindings based on the maximum limit - * of available descriptor slots in each set. - * - * The GFX layer assumes the binding numbers for each descriptor type inside each set - * are guaranteed to be consecutive, so the mapping procedure is reduced - * to a simple shifting operation. This data structure specifies the - * offsets for each descriptor type in each set. - */ - public bindingMappingInfo = new BindingMappingInfo(), - ) {} -} - /** * @en GFX Device. * @zh GFX 设备。 @@ -184,102 +152,6 @@ export abstract class Device { return this._vendor; } - /** - * @en Max vertex attributes supported. - * @zh 最大顶点属性数量。 - */ - get maxVertexAttributes (): number { - return this._maxVertexAttributes; - } - - /** - * @en Max vertex uniform vectors supported. - * @zh 最大顶点Uniform向量数。 - */ - get maxVertexUniformVectors (): number { - return this._maxVertexUniformVectors; - } - - /** - * @en Max fragment uniform vectors supported. - * @zh 最大片段Uniform向量数。 - */ - get maxFragmentUniformVectors (): number { - return this._maxFragmentUniformVectors; - } - - /** - * @en Max texture units supported. - * @zh 最大纹理单元数量。 - */ - get maxTextureUnits (): number { - return this._maxTextureUnits; - } - - /** - * @en Max vertex texture units supported. - * @zh 最大顶点纹理单元数量。 - */ - get maxVertexTextureUnits (): number { - return this._maxVertexTextureUnits; - } - - /** - * @en Max uniform buffer bindings supported. - * @zh 最大 uniform 缓冲绑定数量。 - */ - get maxUniformBufferBindings (): number { - return this._maxUniformBufferBindings; - } - - /** - * @en Max uniform block size supported. - * @zh 最大 uniform 缓冲大小。 - */ - get maxUniformBlockSize (): number { - return this._maxUniformBlockSize; - } - - /** - * @en Max texture size supported. - * @zh 最大贴图尺寸。 - */ - get maxTextureSize (): number { - return this._maxTextureSize; - } - - /** - * @en Max cube map texture size supported. - * @zh 最大立方贴图尺寸。 - */ - get maxCubeMapTextureSize (): number { - return this._maxCubeMapTextureSize; - } - - /** - * @en Uniform buffer offset alignment. - * @zh Uniform 缓冲偏移量的对齐单位。 - */ - get uboOffsetAlignment (): number { - return this._uboOffsetAlignment; - } - - /** - * @en Device depth bits. - * @zh 深度位数。 - */ - get depthBits (): number { - return this._depthBits; - } - - /** - * @en Device stencil bits. - * @zh 模板位数。 - */ - get stencilBits (): number { - return this._stencilBits; - } - /** * @en Device color format. * @zh 颜色格式。 @@ -296,14 +168,6 @@ export abstract class Device { return this._depthStencilFmt; } - /** - * @en Device built-in macros. - * @zh 系统宏定义。 - */ - get macros (): Map { - return this._macros; - } - /** * @en Number of draw calls currently recorded. * @zh 绘制调用次数。 @@ -337,27 +201,11 @@ export abstract class Device { } /** - * @en The minimum Z value in clip space for the device. - * @zh 裁剪空间的最小 z 值。 + * @en Current device capabilities. + * @zh 当前设备能立数据。 */ - get clipSpaceMinZ () { - return this._clipSpaceMinZ; - } - - /** - * @en The sign of the screen space Y axis, positive if origin at lower-left. - * @zh 屏幕空间的 y 轴符号,原点在左下角时为正。 - */ - get screenSpaceSignY () { - return this._screenSpaceSignY; - } - - /** - * @en The sign of the UV space Y axis, positive if origin at upper-left. - * @zh UV 空间的 y 轴符号,原点在左上角时为正。 - */ - get UVSpaceSignY () { - return this._UVSpaceSignY; + get capabilities (): DeviceCaps { + return this._caps; } /** @@ -384,28 +232,13 @@ export abstract class Device { protected _height = 0; protected _nativeWidth = 0; protected _nativeHeight = 0; - protected _maxVertexAttributes = 0; - protected _maxVertexUniformVectors = 0; - protected _maxFragmentUniformVectors = 0; - protected _maxTextureUnits = 0; - protected _maxVertexTextureUnits = 0; - protected _maxUniformBufferBindings = 0; - protected _maxUniformBlockSize = 0; - protected _maxTextureSize = 0; - protected _maxCubeMapTextureSize = 0; - protected _uboOffsetAlignment = 1; - protected _depthBits = 0; - protected _stencilBits = 0; protected _colorFmt = Format.UNKNOWN; protected _depthStencilFmt = Format.UNKNOWN; - protected _macros = new Map(); protected _numDrawCalls = 0; protected _numInstances = 0; protected _numTris = 0; protected _memoryStatus = new MemoryStatus(); - protected _clipSpaceMinZ = -1; - protected _screenSpaceSignY = 1; - protected _UVSpaceSignY = -1; + protected _caps = new DeviceCaps(); public abstract initialize (info: DeviceInfo): boolean; @@ -505,14 +338,14 @@ export abstract class Device { * @zh 创建描述符集布局。 * @param info GFX descriptor set layout description info. */ - public abstract createDescriptorSetLayout (info: gfx.DescriptorSetLayoutInfo): gfx.DescriptorSetLayout; + public abstract createDescriptorSetLayout (info: DescriptorSetLayoutInfo): DescriptorSetLayout; /** * @en Create pipeline layout. * @zh 创建管线布局。 * @param info GFX pipeline layout description info. */ - public abstract createPipelineLayout (info: gfx.PipelineLayoutInfo): gfx.PipelineLayout; + public abstract createPipelineLayout (info: PipelineLayoutInfo): PipelineLayout; /** * @en Create pipeline state. @@ -528,13 +361,6 @@ export abstract class Device { */ public abstract createQueue (info: QueueInfo): Queue; - /** - * @en Create fence. - * @zh 创建同步信号。 - * @param info GFX fence description info. - */ - public abstract createFence (info: FenceInfo): Fence; - /** * @en Copy buffers to texture. * @zh 拷贝缓冲到纹理。 diff --git a/cocos/core/gfx/fence.ts b/cocos/core/gfx/fence.ts deleted file mode 100644 index eaea95c2b0..0000000000 --- a/cocos/core/gfx/fence.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* - 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 { Device } from './device'; -import { Obj, ObjectType } from './define'; - -export class FenceInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - ) {} -} - -/** - * @en GFX Fence. - * @zh GFX 同步信号。 - */ -export abstract class Fence extends Obj { - protected _device: Device; - - constructor (device: Device) { - super(ObjectType.FENCE); - this._device = device; - } - - public abstract initialize (info: FenceInfo): boolean; - - public abstract destroy (): void; -} diff --git a/cocos/core/gfx/framebuffer.ts b/cocos/core/gfx/framebuffer.ts index fc87e7c2b9..f39dcbf978 100644 --- a/cocos/core/gfx/framebuffer.ts +++ b/cocos/core/gfx/framebuffer.ts @@ -31,19 +31,7 @@ import { Device } from './device'; import { RenderPass } from './render-pass'; import { Texture } from './texture'; -import { Obj, ObjectType } from './define'; - -export class FramebufferInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public renderPass: RenderPass, - public colorTextures: (Texture | null)[] = [], // pass null to use swapchain buffers - public depthStencilTexture: Texture | null = null, - public colorMipmapLevels: number[] = [], - public depStencilMipmapLevel: number = 0, - ) {} -} +import { Obj, ObjectType, FramebufferInfo } from './define'; /** * @en GFX frame buffer. diff --git a/cocos/core/gfx/index.jsb.ts b/cocos/core/gfx/index.jsb.ts index 012226c44f..67af0a08db 100644 --- a/cocos/core/gfx/index.jsb.ts +++ b/cocos/core/gfx/index.jsb.ts @@ -25,57 +25,52 @@ declare const gfx: any; -import * as Defines from './define'; import { legacyCC } from '../global-exports'; -import { PipelineState } from './pipeline-state.jsb'; +import * as defines from './define'; +import * as pso from './pipeline-state.jsb'; +export * from './descriptor-set'; +export * from './buffer'; +export * from './command-buffer'; export * from './define'; -export * from './define-class'; -export * from './pipeline-state.jsb'; -export { DeviceInfo, BindingMappingInfo } from './device'; -export {TextureInfo } from './texture'; -export { ShaderStage, UniformSampler, UniformBlock, Uniform, ShaderInfo } from './shader'; -export { DRAW_INFO_SIZE, BufferInfo, BufferViewInfo, DrawInfo, IndirectBuffer } from './buffer'; -export { ColorAttachment, DepthStencilAttachment, SubPassInfo, RenderPassInfo } from './render-pass'; -export { SamplerInfo } from './sampler'; -export { DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE, DescriptorSetInfo } from './descriptor-set'; -export { DescriptorSetLayoutInfo, DescriptorSetLayoutBinding } from './descriptor-set-layout'; -export { CommandBufferInfo } from './command-buffer'; -export { FramebufferInfo } from './framebuffer'; -export { PipelineLayoutInfo } from './pipeline-layout'; -export { FenceInfo } from './fence'; -export { QueueInfo } from './queue'; -export { InputAssemblerInfo } from './input-assembler'; +export * from './device'; +export * from './framebuffer'; +export * from './input-assembler'; +export * from './descriptor-set-layout'; +export * from './pipeline-layout'; +export * from './queue'; +export * from './render-pass'; +export * from './sampler'; +export * from './shader'; +export * from './texture'; -export const TextureViewInfo = gfx.TextureViewInfo; -export const Texture = gfx.Texture; -export const Device = gfx.Device; -export const Shader = gfx.Shader; -export const Attribute = gfx.Attribute; -export const InputAssembler = gfx.InputAssembler; -export const Buffer = gfx.Buffer; -export const Sampler = gfx.Sampler; -export const Fence = gfx.Fence -export const RenderPass = gfx.RenderPass -export const Queue = gfx.Queue; -export const PipelineLayout = gfx.PipelineLayout; -export const DescriptorSetLayout = gfx.DescriptorSetLayout; -export const Framebuffer = gfx.Framebuffer; -export const CommandBuffer = gfx.CommandBuffer; +const polyfillCC: Record = Object.assign({}, defines); +polyfillCC.Device = gfx.Device; +polyfillCC.Buffer = gfx.Buffer; +polyfillCC.Texture = gfx.Texture; +polyfillCC.Sampler = gfx.Sampler; +polyfillCC.Shader = gfx.Shader; +polyfillCC.InputAssembler = gfx.InputAssembler; +polyfillCC.RenderPass = gfx.RenderPass; +polyfillCC.Framebuffer = gfx.Framebuffer; +polyfillCC.DescriptorSet = gfx.DescriptorSet; +polyfillCC.DescriptorSetLayout = gfx.DescriptorSetLayout; +polyfillCC.PipelineLayout = gfx.PipelineLayout; +polyfillCC.PipelineState = gfx.PipelineState; +polyfillCC.CommandBuffer = gfx.CommandBuffer; +polyfillCC.Queue = gfx.Queue; +legacyCC.gfx = polyfillCC; +// TODO: remove these after state info refactor +export const BlendTarget = pso.BlendTarget; +export const BlendState = pso.BlendState; +export const RasterizerState = pso.RasterizerState; +export const DepthStencilState = pso.DepthStencilState; +export const PipelineState = pso.PipelineState; +export const PipelineStateInfo = pso.PipelineStateInfo; -legacyCC.Device = Device; -legacyCC.Buffer = Buffer; -legacyCC.Texture = Texture; -legacyCC.Sampler = Sampler; -legacyCC.Shader = Shader; -legacyCC.InputAssembler = InputAssembler; -legacyCC.RenderPass = RenderPass; -legacyCC.Framebuffer = Framebuffer; -legacyCC.PipelineState = PipelineState; -legacyCC.CommandBuffer = CommandBuffer; -legacyCC.Queue = Queue; - -Object.assign(legacyCC, Defines); - -export * from './deprecated-3.0.0'; +polyfillCC.BlendTarget = pso.BlendTarget; +polyfillCC.BlendState = pso.BlendState; +polyfillCC.RasterizerState = pso.RasterizerState; +polyfillCC.DepthStencilState = pso.DepthStencilState; +polyfillCC.PipelineStateInfo = pso.PipelineStateInfo; diff --git a/cocos/core/gfx/index.ts b/cocos/core/gfx/index.ts index ccc7ceec46..c1ed47f5c5 100644 --- a/cocos/core/gfx/index.ts +++ b/cocos/core/gfx/index.ts @@ -29,21 +29,19 @@ */ import { legacyCC } from '../global-exports'; -import { polyfillCC } from './polyfill-legacy-cc'; import './deprecated-3.0.0'; +import { polyfillCC } from './polyfill-legacy-cc'; export * from './descriptor-set'; export * from './buffer'; export * from './command-buffer'; export * from './define'; -export * from './define-class'; export * from './device'; export * from './framebuffer'; export * from './input-assembler'; export * from './descriptor-set-layout'; export * from './pipeline-layout'; export * from './pipeline-state'; -export * from './fence'; export * from './queue'; export * from './render-pass'; export * from './sampler'; diff --git a/cocos/core/gfx/input-assembler.ts b/cocos/core/gfx/input-assembler.ts index ca6816c3bd..d1bddf1e5b 100644 --- a/cocos/core/gfx/input-assembler.ts +++ b/cocos/core/gfx/input-assembler.ts @@ -31,40 +31,7 @@ import { Buffer } from './buffer'; import { Device } from './device'; import { murmurhash2_32_gc } from '../utils/murmurhash2_gc'; -import { Format, Obj, ObjectType } from './define'; - -export interface IAttribute { - name: string; - format: Format; - isNormalized: boolean; - tream: number; - isInstanced: boolean; - location: number; -} - -export class Attribute { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public name: string = '', - public format: Format = Format.UNKNOWN, - public isNormalized: boolean = false, - public stream: number = 0, - public isInstanced: boolean = false, - public location: number = 0, - ) {} -} - -export class InputAssemblerInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public attributes: Attribute[] = [], - public vertexBuffers: Buffer[] = [], - public indexBuffer: Buffer | null = null, - public indirectBuffer: Buffer | null = null, - ) {} -} +import { Attribute, Obj, ObjectType, InputAssemblerInfo } from './define'; /** * @en GFX input assembler. diff --git a/cocos/core/gfx/pipeline-layout.ts b/cocos/core/gfx/pipeline-layout.ts index c0f520f63d..87e814dde6 100644 --- a/cocos/core/gfx/pipeline-layout.ts +++ b/cocos/core/gfx/pipeline-layout.ts @@ -30,15 +30,7 @@ import { DescriptorSetLayout } from './descriptor-set-layout'; import { Device } from './device'; -import { Obj, ObjectType } from './define'; - -export class PipelineLayoutInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public setLayouts: DescriptorSetLayout[] = [], - ) {} -} +import { Obj, ObjectType, PipelineLayoutInfo } from './define'; /** * @en GFX pipeline layout. diff --git a/cocos/core/gfx/pipeline-state.jsb.ts b/cocos/core/gfx/pipeline-state.jsb.ts index 0861143a50..dd8afac3ad 100644 --- a/cocos/core/gfx/pipeline-state.jsb.ts +++ b/cocos/core/gfx/pipeline-state.jsb.ts @@ -41,8 +41,8 @@ import { PolygonMode, ShadeModel, StencilOp, + Color, } from './define'; -import { Color } from './define-class'; import { BlendTargetArrayPool, NULL_HANDLE, BlendTargetArrayHandle, RasterizerStateHandle, RasterizerStatePool, RasterizerStateView, DepthStencilStateHandle, DepthStencilStatePool, DepthStencilStateView, BlendTargetHandle, BlendTargetPool, BlendTargetView, BlendStateHandle, BlendStatePool, BlendStateView } from '../renderer/core/memory-pools'; @@ -474,6 +474,5 @@ export class BlendState { } } -export const PipelineStateInfo = gfx.PipelineStateInfo; -export const InputState = gfx.InputState; export const PipelineState = gfx.PipelineState; +export const PipelineStateInfo = gfx.PipelineStateInfo; diff --git a/cocos/core/gfx/pipeline-state.ts b/cocos/core/gfx/pipeline-state.ts index 5a1637fa75..21bb5c80b3 100644 --- a/cocos/core/gfx/pipeline-state.ts +++ b/cocos/core/gfx/pipeline-state.ts @@ -28,8 +28,6 @@ * @module gfx */ -import { Attribute } from './input-assembler'; -import { Color } from './define-class'; import { Device } from './device'; import { PipelineLayout } from './pipeline-layout'; import { RenderPass } from './render-pass'; @@ -48,6 +46,9 @@ import { PrimitiveMode, ShadeModel, StencilOp, + InputState, + Color, + PipelineBindPoint, } from './define'; import { NULL_HANDLE, RawBufferHandle } from '../renderer/core/memory-pools'; @@ -241,31 +242,20 @@ export class BlendState { public destroy () {} } -/** - * @en GFX input state. - * @zh GFX 输入状态。 - */ -export class InputState { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public attributes: Attribute[] = [], - ) {} -} - export class PipelineStateInfo { declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object constructor ( - public shader: Shader, - public pipelineLayout: PipelineLayout, - public renderPass: RenderPass, - public inputState: InputState, - public rasterizerState: RasterizerState, - public depthStencilState: DepthStencilState, - public blendState: BlendState, + public shader: Shader = null!, + public pipelineLayout: PipelineLayout = null!, + public renderPass: RenderPass = null!, + public inputState: InputState = new InputState(), + public rasterizerState: RasterizerState = new RasterizerState(), + public depthStencilState: DepthStencilState = new DepthStencilState(), + public blendState: BlendState = new BlendState(), public primitive: PrimitiveMode = PrimitiveMode.TRIANGLE_LIST, public dynamicStates: DynamicStateFlags = DynamicStateFlagBit.NONE, + public bindPoint: PipelineBindPoint = PipelineBindPoint.GRAPHICS, ) {} } diff --git a/cocos/core/gfx/polyfill-legacy-cc.ts b/cocos/core/gfx/polyfill-legacy-cc.ts index 0897b917b2..7f89708621 100644 --- a/cocos/core/gfx/polyfill-legacy-cc.ts +++ b/cocos/core/gfx/polyfill-legacy-cc.ts @@ -32,22 +32,19 @@ import { CommandBuffer } from './command-buffer'; import { Device } from './device'; import { Framebuffer } from './framebuffer'; import { InputAssembler } from './input-assembler'; -import { PipelineState } from './pipeline-state'; +import { DescriptorSet } from './descriptor-set'; +import { DescriptorSetLayout } from './descriptor-set-layout'; +import { PipelineLayout } from './pipeline-layout'; +import { PipelineState, PipelineStateInfo, RasterizerState, BlendState, BlendTarget, DepthStencilState } from './pipeline-state'; import { Queue } from './queue'; import { RenderPass } from './render-pass'; import { Sampler } from './sampler'; import { Shader } from './shader'; import { Texture } from './texture'; -import { Address, AttributeName, BlendFactor, BlendOp, BufferAccessBit, - BufferFlagBit, BufferUsageBit, ClearFlag, ColorMask, CommandBufferType, ComparisonFunc, CullMode, DescriptorType, - DynamicStateFlagBit, Filter, Format, FormatInfo, FormatInfos, FormatSize, FormatSurfaceSize, FormatType, - GetTypeSize, LoadOp, MAX_ATTACHMENTS, MemoryStatus, MemoryUsageBit, Obj, ObjectType, PipelineBindPoint, PolygonMode, - PrimitiveMode, QueueType, SampleCount, ShadeModel, ShaderStageFlagBit, StencilFace, StencilOp, StoreOp, - TextureFlagBit, TextureLayout, TextureType, - TextureUsageBit, Type, getTypedArrayConstructor } from './define'; -import { BufferTextureCopy, Color, Extent, Offset, Rect, TextureCopy, TextureSubres, Viewport } from './define-class'; +import * as defines from './define'; -export const polyfillCC = { Device, +const polyfills: Record = { + Device, Buffer, Texture, Sampler, @@ -55,58 +52,20 @@ export const polyfillCC = { Device, InputAssembler, RenderPass, Framebuffer, + DescriptorSet, + DescriptorSetLayout, + PipelineLayout, PipelineState, CommandBuffer, Queue, - FormatSize, - FormatSurfaceSize, - GetTypeSize, - getTypedArrayConstructor, - MAX_ATTACHMENTS, - ObjectType, - Obj, - AttributeName, - Type, - Format, - BufferUsageBit, - MemoryUsageBit, - BufferFlagBit, - BufferAccessBit, - PrimitiveMode, - PolygonMode, - ShadeModel, - CullMode, - ComparisonFunc, - StencilOp, - BlendOp, - BlendFactor, - ColorMask, - Filter, - Address, - TextureType, - TextureUsageBit, - SampleCount, - TextureFlagBit, - ShaderStageFlagBit, - DescriptorType, - CommandBufferType, - LoadOp, - StoreOp, - TextureLayout, - PipelineBindPoint, - DynamicStateFlagBit, - StencilFace, - QueueType, - Rect, - Viewport, - Color, - ClearFlag, - Offset, - Extent, - TextureSubres, - TextureCopy, - BufferTextureCopy, - FormatType, - FormatInfo, - MemoryStatus, - FormatInfos }; + + RasterizerState, + BlendState, + BlendTarget, + DepthStencilState, + PipelineStateInfo, +}; + +Object.assign(polyfills, defines); + +export const polyfillCC = polyfills; diff --git a/cocos/core/gfx/queue.ts b/cocos/core/gfx/queue.ts index 65df98c537..56a0113e2e 100644 --- a/cocos/core/gfx/queue.ts +++ b/cocos/core/gfx/queue.ts @@ -30,16 +30,7 @@ import { CommandBuffer } from './command-buffer'; import { Device } from './device'; -import { Fence } from './fence'; -import { Obj, ObjectType, QueueType } from './define'; - -export class QueueInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public type: QueueType = QueueType.GRAPHICS, - ) {} -} +import { Obj, ObjectType, QueueType, QueueInfo } from './define'; /** * @en GFX Queue. @@ -77,5 +68,5 @@ export abstract class Queue extends Obj { * @param cmdBuffs The command buffers to be submitted. * @param fence The syncing fence. */ - public abstract submit (cmdBuffs: CommandBuffer[], fence?: Fence): void; + public abstract submit (cmdBuffs: CommandBuffer[]): void; } diff --git a/cocos/core/gfx/render-pass.ts b/cocos/core/gfx/render-pass.ts index b3980cb6fc..acf3d03392 100644 --- a/cocos/core/gfx/render-pass.ts +++ b/cocos/core/gfx/render-pass.ts @@ -31,74 +31,14 @@ import { Device } from './device'; import { murmurhash2_32_gc } from '../utils/murmurhash2_gc'; import { - Format, - LoadOp, Obj, ObjectType, - PipelineBindPoint, - StoreOp, - TextureLayout, + ColorAttachment, + DepthStencilAttachment, + SubpassInfo, + RenderPassInfo, } from './define'; -/** - * @en Color attachment. - * @zh GFX 颜色附件。 - */ -export class ColorAttachment { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public format: Format = Format.UNKNOWN, - public sampleCount: number = 1, - public loadOp: LoadOp = LoadOp.CLEAR, - public storeOp: StoreOp = StoreOp.STORE, - public beginLayout: TextureLayout = TextureLayout.UNDEFINED, - public endLayout: TextureLayout = TextureLayout.PRESENT_SRC, - ) {} -} - -/** - * @en Depth stencil attachment. - * @zh GFX 深度模板附件。 - */ -export class DepthStencilAttachment { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public format: Format = Format.UNKNOWN, - public sampleCount: number = 1, - public depthLoadOp: LoadOp = LoadOp.CLEAR, - public depthStoreOp: StoreOp = StoreOp.STORE, - public stencilLoadOp: LoadOp = LoadOp.CLEAR, - public stencilStoreOp: StoreOp = StoreOp.STORE, - public beginLayout: TextureLayout = TextureLayout.UNDEFINED, - public endLayout: TextureLayout = TextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, - ) {} -} - -export class SubPassInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public bindPoint: PipelineBindPoint = PipelineBindPoint.GRAPHICS, - public inputs: number[] = [], - public colors: number[] = [], - public resolves: number[] = [], - public depthStencil: number = -1, - public preserves: number[] = [], - ) {} -} - -export class RenderPassInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public colorAttachments: ColorAttachment[] = [], - public depthStencilAttachment: DepthStencilAttachment | null = null, - public subPasses: SubPassInfo[] = [], - ) {} -} - /** * @en GFX render pass. * @zh GFX 渲染过程。 @@ -110,13 +50,13 @@ export abstract class RenderPass extends Obj { protected _depthStencilInfo: DepthStencilAttachment | null = null; - protected _subPasses: SubPassInfo[] = []; + protected _subpasses: SubpassInfo[] = []; protected _hash = 0; get colorAttachments () { return this._colorInfos; } get depthStencilAttachment () { return this._depthStencilInfo; } - get subPasses () { return this._subPasses; } + get subPasses () { return this._subpasses; } get hash () { return this._hash; } constructor (device: Device) { @@ -127,9 +67,9 @@ export abstract class RenderPass extends Obj { // Based on render pass compatibility protected computeHash (): number { let res = ''; - if (this._subPasses.length) { - for (let i = 0; i < this._subPasses.length; ++i) { - const subpass = this._subPasses[i]; + if (this._subpasses.length) { + for (let i = 0; i < this._subpasses.length; ++i) { + const subpass = this._subpasses[i]; if (subpass.inputs.length) { res += 'ia'; for (let j = 0; j < subpass.inputs.length; ++j) { diff --git a/cocos/core/gfx/sampler.ts b/cocos/core/gfx/sampler.ts index 5096c61724..830ab98fa1 100644 --- a/cocos/core/gfx/sampler.ts +++ b/cocos/core/gfx/sampler.ts @@ -28,28 +28,8 @@ * @module gfx */ -import { Color } from './define-class'; import { Device } from './device'; -import { Address, ComparisonFunc, Filter, Obj, ObjectType } from './define'; - -export class SamplerInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public minFilter: Filter = Filter.LINEAR, - public magFilter: Filter = Filter.LINEAR, - public mipFilter: Filter = Filter.NONE, - public addressU: Address = Address.WRAP, - public addressV: Address = Address.WRAP, - public addressW: Address = Address.WRAP, - public maxAnisotropy: number = 16, - public cmpFunc: ComparisonFunc = ComparisonFunc.NEVER, - public borderColor: Color = new Color(), - public minLOD: number = 0, - public maxLOD: number = 0, - public mipLODBias: number = 0.0, - ) {} -} +import { Color, Address, ComparisonFunc, Filter, Obj, ObjectType, SamplerInfo } from './define'; /** * @en GFX sampler. diff --git a/cocos/core/gfx/shader.ts b/cocos/core/gfx/shader.ts index e5fc3b7e2f..c0bb63d7ed 100644 --- a/cocos/core/gfx/shader.ts +++ b/cocos/core/gfx/shader.ts @@ -28,87 +28,8 @@ * @module gfx */ -import { Attribute } from './input-assembler'; import { Device } from './device'; -import { Obj, ObjectType, ShaderStageFlagBit, Type } from './define'; - -export interface IShaderStage { - stage: ShaderStageFlagBit; - source: string; -} - -export class ShaderStage implements IShaderStage { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public stage: ShaderStageFlagBit = ShaderStageFlagBit.NONE, - public source: string = '', - ) {} -} - -export interface IUniform { - name: string; - type: Type; - count: number; -} - -/** - * @en GFX uniform. - * @zh GFX uniform。 - */ -export class Uniform implements IUniform { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public name: string = '', - public type: Type = Type.UNKNOWN, - public count: number = 1, - ) {} -} - -/** - * @en GFX uniform block. - * @zh GFX uniform 块。 - */ -export class UniformBlock { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public set: number = -1, - public binding: number = -1, - public name: string = '', - public members: Uniform[] = [], - public count: number = 1, - ) {} -} - -/** - * @en GFX uniform sampler. - * @zh GFX Uniform 采样器。 - */ -export class UniformSampler { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public set: number = -1, - public binding: number = -1, - public name: string = '', - public type: Type = Type.UNKNOWN, - public count: number = 1, - ) {} -} - -export class ShaderInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public name: string = '', - public stages: ShaderStage[] = [], - public attributes: Attribute[] = [], - public blocks: UniformBlock[] = [], - public samplers: UniformSampler[] = [], - ) {} -} +import { Obj, ObjectType, ShaderInfo, ShaderStage, UniformBlock, UniformSampler, Attribute } from './define'; /** * @en GFX shader. diff --git a/cocos/core/gfx/texture.ts b/cocos/core/gfx/texture.ts index d5f244f2fa..2a86084fba 100644 --- a/cocos/core/gfx/texture.ts +++ b/cocos/core/gfx/texture.ts @@ -39,43 +39,10 @@ import { TextureType, TextureUsage, TextureUsageBit, + TextureInfo, + TextureViewInfo, } from './define'; -export class TextureInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public type: TextureType, - public usage: TextureUsage = TextureUsageBit.NONE, - public format: Format = Format.UNKNOWN, - public width: number = 0, - public height: number = 0, - public flags: TextureFlags = TextureFlagBit.NONE, - public layerCount: number = 1, - public levelCount: number = 1, - public samples: SampleCount = SampleCount.X1, - public depth: number = 1, - ) {} -} - -export class TextureViewInfo { - declare private _token: never; // to make sure all usages must be an instance of this exact class, not assembled from plain object - - constructor ( - public texture: Texture, - public type: TextureType = TextureType.TEX2D, - public format: Format = Format.UNKNOWN, - public baseLevel: number = 0, - public levelCount: number = 1, - public baseLayer: number = 0, - public layerCount: number = 1, - ) {} -} - -export function IsPowerOf2 (x: number): boolean { - return x > 0 && (x & (x - 1)) === 0; -} - /** * @en GFX texture. * @zh GFX 纹理。 @@ -198,7 +165,7 @@ export abstract class Texture extends Obj { this._device = device; } - public abstract initialize (info: TextureInfo): boolean; + public abstract initialize (info: TextureInfo | TextureViewInfo): boolean; public abstract destroy (): void; diff --git a/cocos/core/gfx/webgl/webgl-buffer.ts b/cocos/core/gfx/webgl/webgl-buffer.ts index 5128f9c683..f2896f2064 100644 --- a/cocos/core/gfx/webgl/webgl-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-buffer.ts @@ -23,8 +23,9 @@ THE SOFTWARE. */ -import { Buffer, BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer } from '../buffer'; -import { BufferUsageBit, BufferFlagBit } from '../define'; +import { BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer, BufferUsageBit, BufferFlagBit } from '../define'; +import { Buffer } from '../buffer'; + import { WebGLCmdFuncCreateBuffer, WebGLCmdFuncDestroyBuffer, diff --git a/cocos/core/gfx/webgl/webgl-command-allocator.ts b/cocos/core/gfx/webgl/webgl-command-allocator.ts index ac67b8f323..dedd71f2e2 100644 --- a/cocos/core/gfx/webgl/webgl-command-allocator.ts +++ b/cocos/core/gfx/webgl/webgl-command-allocator.ts @@ -39,11 +39,11 @@ export class WebGLCommandPool { private _freeIdx = 0; private _freeCmds: CachedArray; - constructor (clazz: new() => T, count: number) { + constructor (Clazz: new() => T, count: number) { this._frees = new Array(count); this._freeCmds = new CachedArray(count); for (let i = 0; i < count; ++i) { - this._frees[i] = new clazz(); + this._frees[i] = new Clazz(); } this._freeIdx = count - 1; } @@ -54,7 +54,7 @@ export class WebGLCommandPool { } */ - public alloc (clazz: new() => T): T { + public alloc (Clazz: new() => T): T { if (this._freeIdx < 0) { const size = this._frees.length * 2; const temp = this._frees; @@ -62,7 +62,7 @@ export class WebGLCommandPool { const increase = size - temp.length; for (let i = 0; i < increase; ++i) { - this._frees[i] = new clazz(); + this._frees[i] = new Clazz(); } for (let i = increase, j = 0; i < size; ++i, ++j) { diff --git a/cocos/core/gfx/webgl/webgl-command-buffer.ts b/cocos/core/gfx/webgl/webgl-command-buffer.ts index e1365c260e..467de2e2b2 100644 --- a/cocos/core/gfx/webgl/webgl-command-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-command-buffer.ts @@ -24,8 +24,8 @@ */ import { DescriptorSet } from '../descriptor-set'; -import { Buffer, BufferSource } from '../buffer'; -import { CommandBuffer, CommandBufferInfo } from '../command-buffer'; +import { Buffer } from '../buffer'; +import { CommandBuffer } from '../command-buffer'; import { Framebuffer } from '../framebuffer'; import { InputAssembler } from '../input-assembler'; import { PipelineState } from '../pipeline-state'; @@ -41,9 +41,8 @@ import { WebGLPipelineState } from './webgl-pipeline-state'; import { WebGLTexture } from './webgl-texture'; import { RenderPass } from '../render-pass'; import { WebGLRenderPass } from './webgl-render-pass'; -import { BufferUsageBit, CommandBufferType, - StencilFace } from '../define'; -import { BufferTextureCopy, Color, Rect, Viewport } from '../define-class'; +import { BufferUsageBit, CommandBufferType, StencilFace, BufferSource, + CommandBufferInfo, BufferTextureCopy, Color, Rect, Viewport } from '../define'; import { WebGLCmd, WebGLCmdBeginRenderPass, WebGLCmdBindStates, WebGLCmdCopyBufferToTexture, WebGLCmdDraw, WebGLCmdPackage, WebGLCmdUpdateBuffer } from './webgl-commands'; diff --git a/cocos/core/gfx/webgl/webgl-commands.ts b/cocos/core/gfx/webgl/webgl-commands.ts index b27011a1b1..2eb0ffaf6c 100644 --- a/cocos/core/gfx/webgl/webgl-commands.ts +++ b/cocos/core/gfx/webgl/webgl-commands.ts @@ -25,7 +25,6 @@ import { CachedArray } from '../../memop/cached-array'; import { error, errorID } from '../../platform/debug'; -import { BufferSource, DrawInfo, IndirectBuffer } from '../buffer'; import { WebGLCommandAllocator } from './webgl-command-allocator'; import { IWebGLDepthBias, IWebGLDepthBounds, IWebGLStencilCompareMask, IWebGLStencilWriteMask, @@ -34,16 +33,13 @@ import { WebGLEXT } from './webgl-define'; import { WebGLDevice } from './webgl-device'; import { IWebGLGPUInputAssembler, IWebGLGPUUniform, IWebGLAttrib, IWebGLGPUDescriptorSet, IWebGLGPUBuffer, IWebGLGPUFramebuffer, IWebGLGPUInput, - IWebGLGPUPipelineState, IWebGLGPUShader, IWebGLGPUTexture, IWebGLGPUUniformBlock, IWebGLGPUUniformSampler, IWebGLGPURenderPass, + IWebGLGPUPipelineState, IWebGLGPUShader, IWebGLGPUTexture, IWebGLGPUUniformBlock, IWebGLGPUUniformSamplerTexture, IWebGLGPURenderPass, } from './webgl-gpu-objects'; import { - BufferUsageBit, ClearFlag, ColorMask, CullMode, Format, + BufferUsageBit, ClearFlagBit, ClearFlags, ColorMask, CullMode, Format, BufferTextureCopy, Color, Rect, Viewport, FormatInfos, FormatSize, LoadOp, MemoryUsageBit, SampleCount, ShaderStageFlagBit, StencilFace, - TextureFlagBit, TextureType, Type, FormatInfo, DynamicStateFlagBit, + TextureFlagBit, TextureType, Type, FormatInfo, DynamicStateFlagBit, BufferSource, DrawInfo, IndirectBuffer, } from '../define'; -import { - BufferTextureCopy, Color, Rect, Viewport, -} from '../define-class'; export function GFXFormatToWebGLType (format: Format, gl: WebGLRenderingContext): GLenum { switch (format) { @@ -543,7 +539,7 @@ export class WebGLCmdBeginRenderPass extends WebGLCmdObject { public renderArea = new Rect(); - public clearFlag: ClearFlag = ClearFlag.NONE; + public clearFlag: ClearFlags = ClearFlagBit.NONE; public clearColors: Color[] = []; @@ -906,8 +902,8 @@ export function WebGLCmdFuncCreateTexture (device: WebGLDevice, gpuTexture: IWeb gpuTexture.glTarget = gl.TEXTURE_2D; const maxSize = Math.max(w, h); - if (maxSize > device.maxTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } if (!device.WEBGL_depth_texture && FormatInfos[gpuTexture.format].hasDepth) { @@ -982,8 +978,8 @@ export function WebGLCmdFuncCreateTexture (device: WebGLDevice, gpuTexture: IWeb gpuTexture.glTarget = gl.TEXTURE_CUBE_MAP; const maxSize = Math.max(w, h); - if (maxSize > device.maxCubeMapTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxCubeMapTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } const glTexture = gl.createTexture(); @@ -1080,8 +1076,8 @@ export function WebGLCmdFuncResizeTexture (device: WebGLDevice, gpuTexture: IWeb gpuTexture.glTarget = gl.TEXTURE_2D; const maxSize = Math.max(w, h); - if (maxSize > device.maxTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } if (gpuTexture.glRenderbuffer) { @@ -1120,8 +1116,8 @@ export function WebGLCmdFuncResizeTexture (device: WebGLDevice, gpuTexture: IWeb gpuTexture.glTarget = gl.TEXTURE_CUBE_MAP; const maxSize = Math.max(w, h); - if (maxSize > device.maxCubeMapTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxCubeMapTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } const glTexUnit = device.stateCache.glTexUnits[device.stateCache.texUnit]; @@ -1402,12 +1398,12 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL for (let u = 0; u < block.members.length; ++u) { const uniform = block.members[u]; const glType = GFXTypeToWebGLType(uniform.type, gl); - const ctor = GFXTypeToTypedArrayCtor(uniform.type); + const Ctor = GFXTypeToTypedArrayCtor(uniform.type); const stride = WebGLGetTypeSize(glType, gl); const size = stride * uniform.count; const begin = glBlock.size / 4; const count = size / 4; - const array = new ctor(count); + const array = new Ctor(count); glBlock.glUniforms[u] = { binding: -1, @@ -1456,12 +1452,12 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL } // create uniform samplers - if (gpuShader.samplers.length > 0) { - gpuShader.glSamplers = new Array(gpuShader.samplers.length); + if (gpuShader.samplerTextures.length > 0) { + gpuShader.glSamplerTextures = new Array(gpuShader.samplerTextures.length); - for (let i = 0; i < gpuShader.samplers.length; ++i) { - const sampler = gpuShader.samplers[i]; - gpuShader.glSamplers[i] = { + for (let i = 0; i < gpuShader.samplerTextures.length; ++i) { + const sampler = gpuShader.samplerTextures[i]; + gpuShader.glSamplerTextures[i] = { set: sampler.set, binding: sampler.binding, name: sampler.name, @@ -1520,7 +1516,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL } // for // texture unit index mapping optimization - const glActiveSamplers: IWebGLGPUUniformSampler[] = []; + const glActiveSamplers: IWebGLGPUUniformSamplerTexture[] = []; const glActiveSamplerLocations: WebGLUniformLocation[] = []; const { bindingMappingInfo } = device; const { texUnitCacheMap } = device.stateCache; @@ -1533,18 +1529,18 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL } let arrayOffset = 0; - for (let i = 0; i < gpuShader.samplers.length; ++i) { - const sampler = gpuShader.samplers[i]; + for (let i = 0; i < gpuShader.samplerTextures.length; ++i) { + const sampler = gpuShader.samplerTextures[i]; const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name); // Note: getUniformLocation return Object on wechat platform. if (glLoc !== null && (typeof glLoc === 'number' || (glLoc as any).id !== -1)) { - glActiveSamplers.push(gpuShader.glSamplers[i]); + glActiveSamplers.push(gpuShader.glSamplerTextures[i]); glActiveSamplerLocations.push(glLoc); } if (texUnitCacheMap[sampler.name] === undefined) { let binding = sampler.binding + bindingMappingInfo.samplerOffsets[sampler.set] + arrayOffset; if (sampler.set === bindingMappingInfo.flexibleSet) { binding -= flexibleSetBaseOffset; } - texUnitCacheMap[sampler.name] = binding % device.maxTextureUnits; + texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits; arrayOffset += sampler.count - 1; } } @@ -1560,7 +1556,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL glSampler.glLoc = glActiveSamplerLocations[i]; for (let t = 0; t < glSampler.count; ++t) { while (usedTexUnits[cachedUnit]) { - cachedUnit = (cachedUnit + 1) % device.maxTextureUnits; + cachedUnit = (cachedUnit + 1) % device.capabilities.maxTextureUnits; } glSampler.units.push(cachedUnit); usedTexUnits[cachedUnit] = true; @@ -1576,7 +1572,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL glSampler.glLoc = glActiveSamplerLocations[i]; for (let t = 0; t < glSampler.count; ++t) { while (usedTexUnits[unitIdx]) { - unitIdx = (unitIdx + 1) % device.maxTextureUnits; + unitIdx = (unitIdx + 1) % device.capabilities.maxTextureUnits; } if (texUnitCacheMap[glSampler.name] === undefined) { texUnitCacheMap[glSampler.name] = unitIdx; @@ -1612,7 +1608,7 @@ export function WebGLCmdFuncCreateShader (device: WebGLDevice, gpuShader: IWebGL } } - gpuShader.glSamplers = glActiveSamplers; + gpuShader.glSamplerTextures = glActiveSamplers; } export function WebGLCmdFuncDestroyShader (device: WebGLDevice, gpuShader: IWebGLGPUShader) { @@ -2312,9 +2308,9 @@ export function WebGLCmdFuncBindStates ( continue; } - const samplerLen = gpuShader.glSamplers.length; + const samplerLen = gpuShader.glSamplerTextures.length; for (let i = 0; i < samplerLen; i++) { - const glSampler = gpuShader.glSamplers[i]; + const glSampler = gpuShader.glSamplerTextures[i]; const gpuDescriptorSet = gpuDescriptorSets[glSampler.set]; let descriptorIndex = gpuDescriptorSet && gpuDescriptorSet.descriptorIndices[glSampler.binding]; let gpuDescriptor = descriptorIndex >= 0 && gpuDescriptorSet.gpuDescriptors[descriptorIndex]; @@ -2485,7 +2481,7 @@ export function WebGLCmdFuncBindStates ( cache.glVAO = glVAO; } } else { - for (let a = 0; a < device.maxVertexAttributes; ++a) { + for (let a = 0; a < device.capabilities.maxVertexAttributes; ++a) { cache.glCurrentAttribLocs[a] = false; } @@ -2533,7 +2529,7 @@ export function WebGLCmdFuncBindStates ( } } - for (let a = 0; a < device.maxVertexAttributes; ++a) { + for (let a = 0; a < device.capabilities.maxVertexAttributes; ++a) { if (cache.glEnabledAttribLocs[a] !== cache.glCurrentAttribLocs[a]) { gl.disableVertexAttribArray(a); cache.glEnabledAttribLocs[a] = false; diff --git a/cocos/core/gfx/webgl/webgl-define.ts b/cocos/core/gfx/webgl/webgl-define.ts index c6eacd1505..c6aa3f5d77 100644 --- a/cocos/core/gfx/webgl/webgl-define.ts +++ b/cocos/core/gfx/webgl/webgl-define.ts @@ -30,7 +30,7 @@ export enum WebGLEXT { RGBA32F_EXT = 0x8814, FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT = 0x8211, UNSIGNED_NORMALIZED_EXT = 0x8C17, - UNSIGNED_INT_24_8_WEBGL = 0x84FA, + UNSIGNED_INT_24_8_WEBGL = 0x84FA, HALF_FLOAT_OES = 0x8D61, COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0, diff --git a/cocos/core/gfx/webgl/webgl-descriptor-set-layout.ts b/cocos/core/gfx/webgl/webgl-descriptor-set-layout.ts index 92a1b3bdc8..a983a67427 100644 --- a/cocos/core/gfx/webgl/webgl-descriptor-set-layout.ts +++ b/cocos/core/gfx/webgl/webgl-descriptor-set-layout.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { DescriptorSetLayout, DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE } from '../descriptor-set-layout'; +import { DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE } from '../define'; +import { DescriptorSetLayout } from '../descriptor-set-layout'; import { IWebGLGPUDescriptorSetLayout } from './webgl-gpu-objects'; export class WebGLDescriptorSetLayout extends DescriptorSetLayout { diff --git a/cocos/core/gfx/webgl/webgl-descriptor-set.ts b/cocos/core/gfx/webgl/webgl-descriptor-set.ts index 9f0bac6f95..b51ea4aa42 100644 --- a/cocos/core/gfx/webgl/webgl-descriptor-set.ts +++ b/cocos/core/gfx/webgl/webgl-descriptor-set.ts @@ -23,12 +23,13 @@ THE SOFTWARE. */ -import { DescriptorSet, DescriptorSetInfo, DESCRIPTOR_SAMPLER_TYPE, DESCRIPTOR_BUFFER_TYPE } from '../descriptor-set'; +import { DescriptorSet } from '../descriptor-set'; import { WebGLBuffer } from './webgl-buffer'; import { IWebGLGPUDescriptorSet, IWebGLGPUDescriptor } from './webgl-gpu-objects'; import { WebGLSampler } from './webgl-sampler'; import { WebGLTexture } from './webgl-texture'; import { WebGLDescriptorSetLayout } from './webgl-descriptor-set-layout'; +import { DescriptorSetInfo, DESCRIPTOR_SAMPLER_TYPE, DESCRIPTOR_BUFFER_TYPE } from '../define'; export class WebGLDescriptorSet extends DescriptorSet { get gpuDescriptorSet (): IWebGLGPUDescriptorSet { diff --git a/cocos/core/gfx/webgl/webgl-device.ts b/cocos/core/gfx/webgl/webgl-device.ts index 3ed6369818..02e1060157 100644 --- a/cocos/core/gfx/webgl/webgl-device.ts +++ b/cocos/core/gfx/webgl/webgl-device.ts @@ -26,26 +26,24 @@ import { ALIPAY, RUNTIME_BASED, BYTEDANCE, WECHAT, LINKSURE, QTT, COCOSPLAY, HUAWEI } from 'internal:constants'; import { macro, warnID, warn } from '../../platform'; import { sys } from '../../platform/sys'; -import { DescriptorSet, DescriptorSetInfo } from '../descriptor-set'; -import { DescriptorSetLayoutInfo, DescriptorSetLayout } from '../descriptor-set-layout'; -import { PipelineLayoutInfo, PipelineLayout } from '../pipeline-layout'; -import { Buffer, BufferInfo, BufferViewInfo } from '../buffer'; -import { CommandBuffer, CommandBufferInfo } from '../command-buffer'; -import { Device, DeviceInfo, BindingMappingInfo } from '../device'; -import { Fence, FenceInfo } from '../fence'; -import { Framebuffer, FramebufferInfo } from '../framebuffer'; -import { InputAssembler, InputAssemblerInfo } from '../input-assembler'; +import { DescriptorSet } from '../descriptor-set'; +import { DescriptorSetLayout } from '../descriptor-set-layout'; +import { PipelineLayout } from '../pipeline-layout'; +import { Buffer } from '../buffer'; +import { CommandBuffer } from '../command-buffer'; +import { Device } from '../device'; +import { Framebuffer } from '../framebuffer'; +import { InputAssembler } from '../input-assembler'; import { PipelineState, PipelineStateInfo } from '../pipeline-state'; -import { Queue, QueueInfo } from '../queue'; -import { RenderPass, RenderPassInfo } from '../render-pass'; -import { Sampler, SamplerInfo } from '../sampler'; -import { Shader, ShaderInfo } from '../shader'; -import { Texture, TextureInfo, TextureViewInfo } from '../texture'; +import { Queue } from '../queue'; +import { RenderPass } from '../render-pass'; +import { Sampler } from '../sampler'; +import { Shader } from '../shader'; +import { Texture } from '../texture'; import { WebGLDescriptorSet } from './webgl-descriptor-set'; import { WebGLBuffer } from './webgl-buffer'; import { WebGLCommandAllocator } from './webgl-command-allocator'; import { WebGLCommandBuffer } from './webgl-command-buffer'; -import { WebGLFence } from './webgl-fence'; import { WebGLFramebuffer } from './webgl-framebuffer'; import { WebGLInputAssembler } from './webgl-input-assembler'; import { WebGLDescriptorSetLayout } from './webgl-descriptor-set-layout'; @@ -58,9 +56,10 @@ import { WebGLSampler } from './webgl-sampler'; import { WebGLShader } from './webgl-shader'; import { WebGLStateCache } from './webgl-state-cache'; import { WebGLTexture } from './webgl-texture'; -import { getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, - QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature } from '../define'; -import { BufferTextureCopy, Rect } from '../define-class'; +import { getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, BindingMappingInfo, ShaderInfo, + QueueInfo, CommandBufferInfo, DescriptorSetInfo, DescriptorSetLayoutInfo, FramebufferInfo, InputAssemblerInfo, PipelineLayoutInfo, + RenderPassInfo, SamplerInfo, TextureInfo, TextureViewInfo, BufferInfo, BufferViewInfo, DeviceInfo, + QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature, BufferTextureCopy, Rect } from '../define'; import { GFXFormatToWebGLFormat, GFXFormatToWebGLType, WebGLCmdFuncCopyBuffersToTexture, WebGLCmdFuncCopyTexImagesToTexture } from './webgl-commands'; @@ -290,20 +289,20 @@ export class WebGLDevice extends Device { } this._version = gl.getParameter(gl.VERSION); - this._maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - this._maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); - this._maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); - this._maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); - this._maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); - this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); - this._maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); - this._depthBits = gl.getParameter(gl.DEPTH_BITS); - this._stencilBits = gl.getParameter(gl.STENCIL_BITS); + this._caps.maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this._caps.maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); + this._caps.maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); + this._caps.maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); + this._caps.maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); + this._caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); + this._caps.maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); + this._caps.depthBits = gl.getParameter(gl.DEPTH_BITS); + this._caps.stencilBits = gl.getParameter(gl.STENCIL_BITS); - this.stateCache.initialize(this._maxTextureUnits, this._maxVertexAttributes); + this.stateCache.initialize(this._caps.maxTextureUnits, this._caps.maxVertexAttributes); if (ALIPAY) { - this._depthBits = 24; + this._caps.depthBits = 24; } this._devicePixelRatio = info.devicePixelRatio || 1.0; @@ -314,13 +313,13 @@ export class WebGLDevice extends Device { this._colorFmt = Format.RGBA8; - if (this._depthBits === 24) { - if (this._stencilBits === 8) { + if (this._caps.depthBits === 24) { + if (this._caps.stencilBits === 8) { this._depthStencilFmt = Format.D24S8; } else { this._depthStencilFmt = Format.D24; } - } else if (this._stencilBits === 8) { + } else if (this._caps.stencilBits === 8) { this._depthStencilFmt = Format.D16S8; } else { this._depthStencilFmt = Format.D16; @@ -488,12 +487,12 @@ export class WebGLDevice extends Device { // console.info('COLOR_FORMAT: ' + FormatInfos[this._colorFmt].name); // console.info('DEPTH_STENCIL_FORMAT: ' + FormatInfos[this._depthStencilFmt].name); // console.info('MAX_VERTEX_ATTRIBS: ' + this._maxVertexAttributes); - console.info(`MAX_VERTEX_UNIFORM_VECTORS: ${this._maxVertexUniformVectors}`); + console.info(`MAX_VERTEX_UNIFORM_VECTORS: ${this._caps.maxVertexUniformVectors}`); // console.info('MAX_FRAGMENT_UNIFORM_VECTORS: ' + this._maxFragmentUniformVectors); // console.info('MAX_TEXTURE_IMAGE_UNITS: ' + this._maxTextureUnits); // console.info('MAX_VERTEX_TEXTURE_IMAGE_UNITS: ' + this._maxVertexTextureUnits); - console.info(`DEPTH_BITS: ${this._depthBits}`); - console.info(`STENCIL_BITS: ${this._stencilBits}`); + console.info(`DEPTH_BITS: ${this._caps.depthBits}`); + console.info(`STENCIL_BITS: ${this._caps.stencilBits}`); if (this._EXT_texture_filter_anisotropic) { console.info(`MAX_TEXTURE_MAX_ANISOTROPY_EXT: ${this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT}`); } @@ -518,12 +517,12 @@ export class WebGLDevice extends Device { )) as WebGLTexture; this.nullTexCube = this.createTexture(new TextureInfo( - TextureType.TEX2D, + TextureType.CUBE, TextureUsageBit.SAMPLED, Format.RGBA8, 2, 2, - TextureFlagBit.CUBEMAP | TextureFlagBit.GEN_MIPMAP, + TextureFlagBit.GEN_MIPMAP, 6, )) as WebGLTexture; @@ -695,14 +694,6 @@ export class WebGLDevice extends Device { return null!; } - public createFence (info: FenceInfo): Fence { - const fence = new WebGLFence(this); - if (fence.initialize(info)) { - return fence; - } - return null!; - } - public createQueue (info: QueueInfo): Queue { const queue = new WebGLQueue(this); if (queue.initialize(info)) { diff --git a/cocos/core/gfx/webgl/webgl-fence.ts b/cocos/core/gfx/webgl/webgl-fence.ts deleted file mode 100644 index 41d9dbde85..0000000000 --- a/cocos/core/gfx/webgl/webgl-fence.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - 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. - */ - -import { Fence, FenceInfo } from '../fence'; - -export class WebGLFence extends Fence { - public initialize (info: FenceInfo): boolean { - return true; - } - - public destroy () { - } - - // WebGL 1 doesn't have any syncing mechanism - public wait () {} - public reset () {} -} diff --git a/cocos/core/gfx/webgl/webgl-framebuffer.ts b/cocos/core/gfx/webgl/webgl-framebuffer.ts index 474b246e2f..56959c3dc3 100644 --- a/cocos/core/gfx/webgl/webgl-framebuffer.ts +++ b/cocos/core/gfx/webgl/webgl-framebuffer.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { Framebuffer, FramebufferInfo } from '../framebuffer'; +import { FramebufferInfo } from '../define'; +import { Framebuffer } from '../framebuffer'; import { WebGLCmdFuncCreateFramebuffer, WebGLCmdFuncDestroyFramebuffer } from './webgl-commands'; import { WebGLDevice } from './webgl-device'; import { IWebGLGPUFramebuffer, IWebGLGPUTexture } from './webgl-gpu-objects'; @@ -43,7 +44,7 @@ export class WebGLFramebuffer extends Framebuffer { this._colorTextures = info.colorTextures || []; this._depthStencilTexture = info.depthStencilTexture || null; - if (info.depStencilMipmapLevel !== 0) { + if (info.depthStencilMipmapLevel !== 0) { console.warn('The mipmap level of th texture image to be attached of depth stencil attachment should be 0. Convert to 0.'); } for (let i = 0; i < info.colorMipmapLevels.length; ++i) { diff --git a/cocos/core/gfx/webgl/webgl-gpu-objects.ts b/cocos/core/gfx/webgl/webgl-gpu-objects.ts index 3a4e5600ea..1622d36e2d 100644 --- a/cocos/core/gfx/webgl/webgl-gpu-objects.ts +++ b/cocos/core/gfx/webgl/webgl-gpu-objects.ts @@ -23,25 +23,13 @@ THE SOFTWARE. */ -import { DrawInfo } from '../buffer'; import { - DescriptorType, - BufferUsage, - Format, - MemoryUsage, - SampleCount, - ShaderStageFlagBit, - TextureFlags, - TextureType, - TextureUsage, - Type, - DynamicStateFlagBit, + DescriptorType, BufferUsage, Format, MemoryUsage, SampleCount, DynamicStateFlagBit, + ShaderStageFlagBit, TextureFlags, TextureType, TextureUsage, Type, + DrawInfo, Attribute, ColorAttachment, DepthStencilAttachment, + UniformBlock, UniformSamplerTexture, DescriptorSetLayoutBinding, } from '../define'; -import { Attribute } from '../input-assembler'; import { BlendState, DepthStencilState, RasterizerState } from '../pipeline-state'; -import { ColorAttachment, DepthStencilAttachment } from '../render-pass'; -import { UniformBlock, UniformSampler } from '../shader'; -import { DescriptorSetLayoutBinding } from '../descriptor-set-layout'; export interface IWebGLGPUUniformInfo { name: string; @@ -155,7 +143,7 @@ export interface IWebGLGPUUniformBlock { glActiveUniforms: IWebGLGPUUniform[]; } -export interface IWebGLGPUUniformSampler { +export interface IWebGLGPUUniformSamplerTexture { set: number; binding: number; name: string; @@ -177,14 +165,14 @@ export interface IWebGLGPUShaderStage { export interface IWebGLGPUShader { name: string; blocks: UniformBlock[]; - samplers: UniformSampler[]; + samplerTextures: UniformSamplerTexture[]; gpuStages: IWebGLGPUShaderStage[]; glProgram: WebGLProgram | null; glInputs: IWebGLGPUInput[]; glUniforms: IWebGLGPUUniform[]; glBlocks: IWebGLGPUUniformBlock[]; - glSamplers: IWebGLGPUUniformSampler[]; + glSamplerTextures: IWebGLGPUUniformSamplerTexture[]; } export interface IWebGLGPUDescriptorSetLayout { diff --git a/cocos/core/gfx/webgl/webgl-input-assembler.ts b/cocos/core/gfx/webgl/webgl-input-assembler.ts index e8b691a209..7558d3d82d 100644 --- a/cocos/core/gfx/webgl/webgl-input-assembler.ts +++ b/cocos/core/gfx/webgl/webgl-input-assembler.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { InputAssembler, InputAssemblerInfo } from '../input-assembler'; +import { InputAssemblerInfo } from '../define'; +import { InputAssembler } from '../input-assembler'; import { WebGLBuffer } from './webgl-buffer'; import { WebGLCmdFuncCreateInputAssember, WebGLCmdFuncDestroyInputAssembler } from './webgl-commands'; import { WebGLDevice } from './webgl-device'; diff --git a/cocos/core/gfx/webgl/webgl-pipeline-layout.ts b/cocos/core/gfx/webgl/webgl-pipeline-layout.ts index 49a68958e3..626744039d 100644 --- a/cocos/core/gfx/webgl/webgl-pipeline-layout.ts +++ b/cocos/core/gfx/webgl/webgl-pipeline-layout.ts @@ -23,9 +23,10 @@ THE SOFTWARE. */ -import { PipelineLayout, PipelineLayoutInfo } from '../pipeline-layout'; +import { PipelineLayout } from '../pipeline-layout'; import { IWebGLGPUPipelineLayout, IWebGLGPUDescriptorSetLayout } from './webgl-gpu-objects'; import { WebGLDescriptorSetLayout } from './webgl-descriptor-set-layout'; +import { PipelineLayoutInfo } from '../define'; export class WebGLPipelineLayout extends PipelineLayout { get gpuPipelineLayout () { return this._gpuPipelineLayout!; } diff --git a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts index 85eb765d00..2d83e3325c 100644 --- a/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl/webgl-primary-command-buffer.ts @@ -23,10 +23,9 @@ THE SOFTWARE. */ -import { Buffer, BufferSource, DrawInfo } from '../buffer'; +import { Buffer } from '../buffer'; import { CommandBuffer } from '../command-buffer'; -import { BufferUsageBit } from '../define'; -import { BufferTextureCopy, Color, Rect } from '../define-class'; +import { BufferSource, DrawInfo, BufferTextureCopy, Color, Rect, BufferUsageBit } from '../define'; import { Framebuffer } from '../framebuffer'; import { InputAssembler } from '../input-assembler'; import { Texture } from '../texture'; diff --git a/cocos/core/gfx/webgl/webgl-queue.ts b/cocos/core/gfx/webgl/webgl-queue.ts index 5bcb153f94..94ff8b2bdc 100644 --- a/cocos/core/gfx/webgl/webgl-queue.ts +++ b/cocos/core/gfx/webgl/webgl-queue.ts @@ -23,9 +23,9 @@ THE SOFTWARE. */ +import { QueueInfo } from '../define'; import { CommandBuffer } from '../command-buffer'; -import { Queue, QueueInfo } from '../queue'; -import { Fence } from '../fence'; +import { Queue } from '../queue'; export class WebGLQueue extends Queue { public numDrawCalls = 0; @@ -41,7 +41,7 @@ export class WebGLQueue extends Queue { public destroy () { } - public submit (cmdBuffs: CommandBuffer[], fence?: Fence) { + public submit (cmdBuffs: CommandBuffer[]) { if (!this._isAsync) { const len = cmdBuffs.length; for (let i = 0; i < len; i++) { diff --git a/cocos/core/gfx/webgl/webgl-render-pass.ts b/cocos/core/gfx/webgl/webgl-render-pass.ts index 998472cff1..38910d9332 100644 --- a/cocos/core/gfx/webgl/webgl-render-pass.ts +++ b/cocos/core/gfx/webgl/webgl-render-pass.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { RenderPass, RenderPassInfo } from '../render-pass'; +import { RenderPassInfo } from '../define'; +import { RenderPass } from '../render-pass'; import { IWebGLGPURenderPass } from './webgl-gpu-objects'; export class WebGLRenderPass extends RenderPass { @@ -36,8 +37,8 @@ export class WebGLRenderPass extends RenderPass { public initialize (info: RenderPassInfo): boolean { this._colorInfos = info.colorAttachments; this._depthStencilInfo = info.depthStencilAttachment; - if (info.subPasses) { - this._subPasses = info.subPasses; + if (info.subpasses) { + this._subpasses = info.subpasses; } this._gpuRenderPass = { diff --git a/cocos/core/gfx/webgl/webgl-sampler.ts b/cocos/core/gfx/webgl/webgl-sampler.ts index f92562c0c2..ff0275ece7 100644 --- a/cocos/core/gfx/webgl/webgl-sampler.ts +++ b/cocos/core/gfx/webgl/webgl-sampler.ts @@ -23,8 +23,8 @@ THE SOFTWARE. */ -import { Filter } from '../define'; -import { Sampler, SamplerInfo } from '../sampler'; +import { Filter, SamplerInfo } from '../define'; +import { Sampler } from '../sampler'; import { IWebGLGPUSampler } from './webgl-gpu-objects'; const WebGLWraps: GLenum[] = [ diff --git a/cocos/core/gfx/webgl/webgl-shader.ts b/cocos/core/gfx/webgl/webgl-shader.ts index 66c09d54b8..857747eb9e 100644 --- a/cocos/core/gfx/webgl/webgl-shader.ts +++ b/cocos/core/gfx/webgl/webgl-shader.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { Shader, ShaderInfo } from '../shader'; +import { ShaderInfo } from '../define'; +import { Shader } from '../shader'; import { WebGLCmdFuncCreateShader, WebGLCmdFuncDestroyShader } from './webgl-commands'; import { WebGLDevice } from './webgl-device'; import { IWebGLGPUShader, IWebGLGPUShaderStage } from './webgl-gpu-objects'; @@ -45,14 +46,14 @@ export class WebGLShader extends Shader { this._gpuShader = { name: info.name, blocks: info.blocks, - samplers: info.samplers, + samplerTextures: info.samplerTextures, gpuStages: new Array(info.stages.length), glProgram: null, glInputs: [], glUniforms: [], glBlocks: [], - glSamplers: [], + glSamplerTextures: [], }; for (let i = 0; i < info.stages.length; ++i) { diff --git a/cocos/core/gfx/webgl/webgl-state-cache.ts b/cocos/core/gfx/webgl/webgl-state-cache.ts index 783ef162fe..9d9c838204 100644 --- a/cocos/core/gfx/webgl/webgl-state-cache.ts +++ b/cocos/core/gfx/webgl/webgl-state-cache.ts @@ -23,7 +23,7 @@ THE SOFTWARE. */ -import { Rect, Viewport } from '../define-class'; +import { Rect, Viewport } from '../define'; import { BlendState, DepthStencilState, RasterizerState } from '../pipeline-state'; export interface IWebGLTexUnit { diff --git a/cocos/core/gfx/webgl/webgl-texture.ts b/cocos/core/gfx/webgl/webgl-texture.ts index 94660a4f08..8cada6e246 100644 --- a/cocos/core/gfx/webgl/webgl-texture.ts +++ b/cocos/core/gfx/webgl/webgl-texture.ts @@ -23,8 +23,8 @@ THE SOFTWARE. */ -import { TextureFlagBit, FormatSurfaceSize } from '../define'; -import { Texture, TextureInfo, TextureViewInfo, IsPowerOf2 } from '../texture'; +import { TextureFlagBit, FormatSurfaceSize, TextureInfo, TextureViewInfo, IsPowerOf2 } from '../define'; +import { Texture } from '../texture'; import { WebGLCmdFuncCreateTexture, WebGLCmdFuncDestroyTexture, WebGLCmdFuncResizeTexture } from './webgl-commands'; import { WebGLDevice } from './webgl-device'; import { IWebGLGPUTexture } from './webgl-gpu-objects'; diff --git a/cocos/core/gfx/webgl2/webgl2-buffer.ts b/cocos/core/gfx/webgl2/webgl2-buffer.ts index 4a41f20c35..aaead9f255 100644 --- a/cocos/core/gfx/webgl2/webgl2-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-buffer.ts @@ -23,8 +23,8 @@ THE SOFTWARE. */ -import { Buffer, BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer } from '../buffer'; -import { BufferFlagBit, BufferUsageBit } from '../define'; +import { Buffer } from '../buffer'; +import { BufferFlagBit, BufferUsageBit, BufferSource, BufferInfo, BufferViewInfo, IndirectBuffer } from '../define'; import { WebGL2CmdFuncCreateBuffer, WebGL2CmdFuncDestroyBuffer, diff --git a/cocos/core/gfx/webgl2/webgl2-command-allocator.ts b/cocos/core/gfx/webgl2/webgl2-command-allocator.ts index 350a4fe500..9a3ad4451a 100644 --- a/cocos/core/gfx/webgl2/webgl2-command-allocator.ts +++ b/cocos/core/gfx/webgl2/webgl2-command-allocator.ts @@ -39,11 +39,11 @@ export class WebGL2CommandPool { private _freeIdx = 0; private _freeCmds: CachedArray; - constructor (clazz: new() => T, count: number) { + constructor (Clazz: new() => T, count: number) { this._frees = new Array(count); this._freeCmds = new CachedArray(count); for (let i = 0; i < count; ++i) { - this._frees[i] = new clazz(); + this._frees[i] = new Clazz(); } this._freeIdx = count - 1; } @@ -54,7 +54,7 @@ export class WebGL2CommandPool { } */ - public alloc (clazz: new() => T): T { + public alloc (Clazz: new() => T): T { if (this._freeIdx < 0) { const size = this._frees.length * 2; const temp = this._frees; @@ -62,7 +62,7 @@ export class WebGL2CommandPool { const increase = size - temp.length; for (let i = 0; i < increase; ++i) { - this._frees[i] = new clazz(); + this._frees[i] = new Clazz(); } for (let i = increase, j = 0; i < size; ++i, ++j) { diff --git a/cocos/core/gfx/webgl2/webgl2-command-buffer.ts b/cocos/core/gfx/webgl2/webgl2-command-buffer.ts index a8a559844c..3bc8ed8a63 100644 --- a/cocos/core/gfx/webgl2/webgl2-command-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-command-buffer.ts @@ -24,14 +24,15 @@ */ import { DescriptorSet } from '../descriptor-set'; -import { Buffer, BufferSource } from '../buffer'; -import { CommandBuffer, CommandBufferInfo } from '../command-buffer'; +import { Buffer } from '../buffer'; +import { CommandBuffer } from '../command-buffer'; import { BufferUsageBit, CommandBufferType, StencilFace, + BufferSource, CommandBufferInfo, + BufferTextureCopy, Color, Rect, Viewport, } from '../define'; -import { BufferTextureCopy, Color, Rect, Viewport } from '../define-class'; import { Framebuffer } from '../framebuffer'; import { InputAssembler } from '../input-assembler'; import { PipelineState } from '../pipeline-state'; diff --git a/cocos/core/gfx/webgl2/webgl2-commands.ts b/cocos/core/gfx/webgl2/webgl2-commands.ts index 3d0217cb2c..d0719af138 100644 --- a/cocos/core/gfx/webgl2/webgl2-commands.ts +++ b/cocos/core/gfx/webgl2/webgl2-commands.ts @@ -25,29 +25,11 @@ import { CachedArray } from '../../memop/cached-array'; import { error, errorID } from '../../platform'; -import { BufferSource, DrawInfo, IndirectBuffer } from '../buffer'; import { - BufferUsageBit, - ColorMask, - CullMode, - DynamicStateFlagBit, - Filter, - Format, - FormatInfos, - FormatSize, - LoadOp, - MemoryUsageBit, - SampleCount, - ShaderStageFlagBit, - StencilFace, - TextureFlagBit, - TextureType, - Type, - FormatInfo, + BufferUsageBit, ColorMask, CullMode, DynamicStateFlagBit, Filter, Format, TextureType, Type, FormatInfo, + FormatInfos, FormatSize, LoadOp, MemoryUsageBit, SampleCount, ShaderStageFlagBit, StencilFace, TextureFlagBit, + Color, Rect, Viewport, BufferTextureCopy, BufferSource, DrawInfo, IndirectBuffer, UniformBlock, } from '../define'; -import { - Color, Rect, Viewport, BufferTextureCopy, -} from '../define-class'; import { WebGLEXT } from '../webgl/webgl-define'; import { WebGL2CommandAllocator } from './webgl2-command-allocator'; import { @@ -59,7 +41,6 @@ import { import { WebGL2Device } from './webgl2-device'; import { IWebGL2GPUInputAssembler, - IWebGL2GPUUniform, IWebGL2Attrib, IWebGL2GPUDescriptorSet, IWebGL2GPUBuffer, @@ -70,10 +51,9 @@ import { IWebGL2GPUShader, IWebGL2GPUTexture, IWebGL2GPUUniformBlock, - IWebGL2GPUUniformSampler, + IWebGL2GPUUniformSamplerTexture, IWebGL2GPURenderPass, } from './webgl2-gpu-objects'; -import { UniformBlock } from '../shader'; const WebGLWraps: GLenum[] = [ 0x2901, // WebGLRenderingContext.REPEAT @@ -1097,8 +1077,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW gpuTexture.glTarget = gl.TEXTURE_2D; const maxSize = Math.max(w, h); - if (maxSize > device.maxTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } if (gpuTexture.samples === SampleCount.X1) { @@ -1171,8 +1151,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW gpuTexture.glTarget = gl.TEXTURE_CUBE_MAP; const maxSize = Math.max(w, h); - if (maxSize > device.maxCubeMapTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxCubeMapTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } const glTexture = gl.createTexture(); @@ -1268,8 +1248,8 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2Device, gpuTexture: IW gpuTexture.glTarget = gl.TEXTURE_2D; const maxSize = Math.max(w, h); - if (maxSize > device.maxTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } if (gpuTexture.samples === SampleCount.X1) { @@ -1315,8 +1295,8 @@ export function WebGL2CmdFuncResizeTexture (device: WebGL2Device, gpuTexture: IW gpuTexture.glTarget = gl.TEXTURE_CUBE_MAP; const maxSize = Math.max(w, h); - if (maxSize > device.maxCubeMapTextureSize) { - errorID(9100, maxSize, device.maxTextureSize); + if (maxSize > device.capabilities.maxCubeMapTextureSize) { + errorID(9100, maxSize, device.capabilities.maxTextureSize); } const glTexUnit = device.stateCache.glTexUnits[device.stateCache.texUnit]; @@ -1669,12 +1649,12 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb } // create uniform samplers - if (gpuShader.samplers.length > 0) { - gpuShader.glSamplers = new Array(gpuShader.samplers.length); + if (gpuShader.samplerTextures.length > 0) { + gpuShader.glSamplerTextures = new Array(gpuShader.samplerTextures.length); - for (let i = 0; i < gpuShader.samplers.length; ++i) { - const sampler = gpuShader.samplers[i]; - gpuShader.glSamplers[i] = { + for (let i = 0; i < gpuShader.samplerTextures.length; ++i) { + const sampler = gpuShader.samplerTextures[i]; + gpuShader.glSamplerTextures[i] = { set: sampler.set, binding: sampler.binding, name: sampler.name, @@ -1689,31 +1669,30 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb } // texture unit index mapping optimization - const glActiveSamplers: IWebGL2GPUUniformSampler[] = []; + const glActiveSamplers: IWebGL2GPUUniformSamplerTexture[] = []; const glActiveSamplerLocations: WebGLUniformLocation[] = []; - const { bindingMappingInfo } = device; - const { texUnitCacheMap } = device.stateCache; + const texUnitCacheMap = device.stateCache.texUnitCacheMap; let flexibleSetBaseOffset = 0; for (let i = 0; i < gpuShader.blocks.length; ++i) { - if (gpuShader.blocks[i].set === bindingMappingInfo.flexibleSet) { + if (gpuShader.blocks[i].set === device.bindingMappingInfo.flexibleSet) { flexibleSetBaseOffset++; } } let arrayOffset = 0; - for (let i = 0; i < gpuShader.samplers.length; ++i) { - const sampler = gpuShader.samplers[i]; + for (let i = 0; i < gpuShader.samplerTextures.length; ++i) { + const sampler = gpuShader.samplerTextures[i]; const glLoc = gl.getUniformLocation(gpuShader.glProgram, sampler.name); // Note: getUniformLocation return Object on wechat platform. if (glLoc !== null && (typeof glLoc === 'number' || (glLoc as any).id !== -1)) { - glActiveSamplers.push(gpuShader.glSamplers[i]); + glActiveSamplers.push(gpuShader.glSamplerTextures[i]); glActiveSamplerLocations.push(glLoc); } if (texUnitCacheMap[sampler.name] === undefined) { - let binding = sampler.binding + bindingMappingInfo.samplerOffsets[sampler.set] + arrayOffset; - if (sampler.set === bindingMappingInfo.flexibleSet) { binding -= flexibleSetBaseOffset; } - texUnitCacheMap[sampler.name] = binding % device.maxTextureUnits; + let binding = sampler.binding + device.bindingMappingInfo.samplerOffsets[sampler.set] + arrayOffset; + if (sampler.set === device.bindingMappingInfo.flexibleSet) { binding -= flexibleSetBaseOffset; } + texUnitCacheMap[sampler.name] = binding % device.capabilities.maxTextureUnits; arrayOffset += sampler.count - 1; } } @@ -1729,7 +1708,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb glSampler.glLoc = glActiveSamplerLocations[i]; for (let t = 0; t < glSampler.count; ++t) { while (usedTexUnits[cachedUnit]) { - cachedUnit = (cachedUnit + 1) % device.maxTextureUnits; + cachedUnit = (cachedUnit + 1) % device.capabilities.maxTextureUnits; } glSampler.units.push(cachedUnit); usedTexUnits[cachedUnit] = true; @@ -1746,7 +1725,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb while (usedTexUnits[unitIdx]) { unitIdx++; } for (let t = 0; t < glSampler.count; ++t) { while (usedTexUnits[unitIdx]) { - unitIdx = (unitIdx + 1) % device.maxTextureUnits; + unitIdx = (unitIdx + 1) % device.capabilities.maxTextureUnits; } if (texUnitCacheMap[glSampler.name] === undefined) { texUnitCacheMap[glSampler.name] = unitIdx; @@ -1772,7 +1751,7 @@ export function WebGL2CmdFuncCreateShader (device: WebGL2Device, gpuShader: IWeb } } - gpuShader.glSamplers = glActiveSamplers; + gpuShader.glSamplerTextures = glActiveSamplers; } export function WebGL2CmdFuncDestroyShader (device: WebGL2Device, gpuShader: IWebGL2GPUShader) { @@ -2308,9 +2287,9 @@ export function WebGL2CmdFuncBindStates ( } } - const samplerLen = gpuShader.glSamplers.length; + const samplerLen = gpuShader.glSamplerTextures.length; for (let i = 0; i < samplerLen; i++) { - const glSampler = gpuShader.glSamplers[i]; + const glSampler = gpuShader.glSamplerTextures[i]; const gpuDescriptorSet = gpuDescriptorSets[glSampler.set]; let descriptorIndex = gpuDescriptorSet && gpuDescriptorSet.descriptorIndices[glSampler.binding]; let gpuDescriptor = descriptorIndex >= 0 && gpuDescriptorSet.gpuDescriptors[descriptorIndex]; @@ -2420,7 +2399,7 @@ export function WebGL2CmdFuncBindStates ( cache.glVAO = glVAO; } } else { - for (let a = 0; a < device.maxVertexAttributes; ++a) { + for (let a = 0; a < device.capabilities.maxVertexAttributes; ++a) { cache.glCurrentAttribLocs[a] = false; } @@ -2466,7 +2445,7 @@ export function WebGL2CmdFuncBindStates ( } } - for (let a = 0; a < device.maxVertexAttributes; ++a) { + for (let a = 0; a < device.capabilities.maxVertexAttributes; ++a) { if (cache.glEnabledAttribLocs[a] !== cache.glCurrentAttribLocs[a]) { gl.disableVertexAttribArray(a); cache.glEnabledAttribLocs[a] = false; diff --git a/cocos/core/gfx/webgl2/webgl2-descriptor-set-layout.ts b/cocos/core/gfx/webgl2/webgl2-descriptor-set-layout.ts index 8f958fb12c..0f4430c292 100644 --- a/cocos/core/gfx/webgl2/webgl2-descriptor-set-layout.ts +++ b/cocos/core/gfx/webgl2/webgl2-descriptor-set-layout.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { DescriptorSetLayout, DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE } from '../descriptor-set-layout'; +import { DescriptorSetLayoutInfo, DESCRIPTOR_DYNAMIC_TYPE } from '../define'; +import { DescriptorSetLayout } from '../descriptor-set-layout'; import { IWebGL2GPUDescriptorSetLayout } from './webgl2-gpu-objects'; export class WebGL2DescriptorSetLayout extends DescriptorSetLayout { diff --git a/cocos/core/gfx/webgl2/webgl2-descriptor-set.ts b/cocos/core/gfx/webgl2/webgl2-descriptor-set.ts index 5df60e5cb8..03f4146f9e 100644 --- a/cocos/core/gfx/webgl2/webgl2-descriptor-set.ts +++ b/cocos/core/gfx/webgl2/webgl2-descriptor-set.ts @@ -23,12 +23,13 @@ THE SOFTWARE. */ -import { DescriptorSet, DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from '../descriptor-set'; +import { DescriptorSet } from '../descriptor-set'; import { WebGL2Buffer } from './webgl2-buffer'; import { IWebGL2GPUDescriptorSet, IWebGL2GPUDescriptor } from './webgl2-gpu-objects'; import { WebGL2Sampler } from './webgl2-sampler'; import { WebGL2Texture } from './webgl2-texture'; import { WebGL2DescriptorSetLayout } from './webgl2-descriptor-set-layout'; +import { DescriptorSetInfo, DESCRIPTOR_BUFFER_TYPE, DESCRIPTOR_SAMPLER_TYPE } from '../define'; export class WebGL2DescriptorSet extends DescriptorSet { get gpuDescriptorSet (): IWebGL2GPUDescriptorSet { diff --git a/cocos/core/gfx/webgl2/webgl2-device.ts b/cocos/core/gfx/webgl2/webgl2-device.ts index bb2cba3335..74b5a23fb6 100644 --- a/cocos/core/gfx/webgl2/webgl2-device.ts +++ b/cocos/core/gfx/webgl2/webgl2-device.ts @@ -24,26 +24,24 @@ */ import { macro, warnID, warn } from '../../platform'; -import { DescriptorSet, DescriptorSetInfo } from '../descriptor-set'; -import { DescriptorSetLayout, DescriptorSetLayoutInfo } from '../descriptor-set-layout'; -import { PipelineLayout, PipelineLayoutInfo } from '../pipeline-layout'; -import { Buffer, BufferInfo, BufferViewInfo } from '../buffer'; -import { CommandBuffer, CommandBufferInfo } from '../command-buffer'; -import { Device, DeviceInfo, BindingMappingInfo } from '../device'; -import { Fence, FenceInfo } from '../fence'; -import { Framebuffer, FramebufferInfo } from '../framebuffer'; -import { InputAssembler, InputAssemblerInfo } from '../input-assembler'; +import { DescriptorSet } from '../descriptor-set'; +import { DescriptorSetLayout } from '../descriptor-set-layout'; +import { PipelineLayout } from '../pipeline-layout'; +import { Buffer } from '../buffer'; +import { CommandBuffer } from '../command-buffer'; +import { Device } from '../device'; +import { Framebuffer } from '../framebuffer'; +import { InputAssembler } from '../input-assembler'; import { PipelineState, PipelineStateInfo } from '../pipeline-state'; -import { Queue, QueueInfo } from '../queue'; -import { RenderPass, RenderPassInfo } from '../render-pass'; -import { Sampler, SamplerInfo } from '../sampler'; -import { Shader, ShaderInfo } from '../shader'; -import { Texture, TextureInfo, TextureViewInfo } from '../texture'; +import { Queue } from '../queue'; +import { RenderPass } from '../render-pass'; +import { Sampler } from '../sampler'; +import { Shader } from '../shader'; +import { Texture } from '../texture'; import { WebGL2DescriptorSet } from './webgl2-descriptor-set'; import { WebGL2Buffer } from './webgl2-buffer'; import { WebGL2CommandAllocator } from './webgl2-command-allocator'; import { WebGL2CommandBuffer } from './webgl2-command-buffer'; -import { WebGL2Fence } from './webgl2-fence'; import { WebGL2Framebuffer } from './webgl2-framebuffer'; import { WebGL2InputAssembler } from './webgl2-input-assembler'; import { WebGL2DescriptorSetLayout } from './webgl2-descriptor-set-layout'; @@ -56,9 +54,10 @@ import { WebGL2Sampler } from './webgl2-sampler'; import { WebGL2Shader } from './webgl2-shader'; import { WebGL2StateCache } from './webgl2-state-cache'; import { WebGL2Texture } from './webgl2-texture'; -import { getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, - QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature } from '../define'; -import { BufferTextureCopy, Rect } from '../define-class'; +import { getTypedArrayConstructor, CommandBufferType, Filter, Format, FormatInfos, DescriptorSetLayoutInfo, DescriptorSetInfo, + PipelineLayoutInfo, BufferViewInfo, CommandBufferInfo, BufferInfo, BindingMappingInfo, FramebufferInfo, InputAssemblerInfo, + QueueInfo, RenderPassInfo, SamplerInfo, ShaderInfo, TextureInfo, TextureViewInfo, DeviceInfo, + QueueType, TextureFlagBit, TextureType, TextureUsageBit, API, Feature, BufferTextureCopy, Rect } from '../define'; import { GFXFormatToWebGLFormat, GFXFormatToWebGLType, WebGL2CmdFuncBlitFramebuffer, WebGL2CmdFuncCopyBuffersToTexture, WebGL2CmdFuncCopyTexImagesToTexture } from './webgl2-commands'; @@ -214,22 +213,22 @@ export class WebGL2Device extends Device { } this._version = gl.getParameter(gl.VERSION); - this._maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); - this._maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); - this._maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); - this._maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); - this._maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); - this._maxUniformBufferBindings = gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS); - this._maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE); - this._maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); - this._maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); - this._uboOffsetAlignment = gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT); - this._depthBits = gl.getParameter(gl.DEPTH_BITS); - this._stencilBits = gl.getParameter(gl.STENCIL_BITS); + this._caps.maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); + this._caps.maxVertexUniformVectors = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); + this._caps.maxFragmentUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); + this._caps.maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); + this._caps.maxVertexTextureUnits = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); + this._caps.maxUniformBufferBindings = gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS); + this._caps.maxUniformBlockSize = gl.getParameter(gl.MAX_UNIFORM_BLOCK_SIZE); + this._caps.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); + this._caps.maxCubeMapTextureSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); + this._caps.uboOffsetAlignment = gl.getParameter(gl.UNIFORM_BUFFER_OFFSET_ALIGNMENT); + this._caps.depthBits = gl.getParameter(gl.DEPTH_BITS); + this._caps.stencilBits = gl.getParameter(gl.STENCIL_BITS); // let maxVertexUniformBlocks = gl.getParameter(gl.MAX_VERTEX_UNIFORM_BLOCKS); // let maxFragmentUniformBlocks = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_BLOCKS); - this.stateCache.initialize(this._maxTextureUnits, this._maxUniformBufferBindings, this._maxVertexAttributes); + this.stateCache.initialize(this._caps.maxTextureUnits, this._caps.maxUniformBufferBindings, this._caps.maxVertexAttributes); this._devicePixelRatio = info.devicePixelRatio || 1.0; this._width = this._canvas.width; @@ -239,19 +238,19 @@ export class WebGL2Device extends Device { this._colorFmt = Format.RGBA8; - if (this._depthBits === 32) { - if (this._stencilBits === 8) { + if (this._caps.depthBits === 32) { + if (this._caps.stencilBits === 8) { this._depthStencilFmt = Format.D32F_S8; } else { this._depthStencilFmt = Format.D32F; } - } else if (this._depthBits === 24) { - if (this._stencilBits === 8) { + } else if (this._caps.depthBits === 24) { + if (this._caps.stencilBits === 8) { this._depthStencilFmt = Format.D24S8; } else { this._depthStencilFmt = Format.D24; } - } else if (this._stencilBits === 8) { + } else if (this._caps.stencilBits === 8) { this._depthStencilFmt = Format.D16S8; } else { this._depthStencilFmt = Format.D16; @@ -344,16 +343,16 @@ export class WebGL2Device extends Device { console.info(`DPR: ${this._devicePixelRatio}`); console.info(`SCREEN_SIZE: ${this._width} x ${this._height}`); console.info(`NATIVE_SIZE: ${this._nativeWidth} x ${this._nativeHeight}`); - console.info(`MAX_VERTEX_ATTRIBS: ${this._maxVertexAttributes}`); - console.info(`MAX_VERTEX_UNIFORM_VECTORS: ${this._maxVertexUniformVectors}`); - console.info(`MAX_FRAGMENT_UNIFORM_VECTORS: ${this._maxFragmentUniformVectors}`); - console.info(`MAX_TEXTURE_IMAGE_UNITS: ${this._maxTextureUnits}`); - console.info(`MAX_VERTEX_TEXTURE_IMAGE_UNITS: ${this._maxVertexTextureUnits}`); - console.info(`MAX_UNIFORM_BUFFER_BINDINGS: ${this._maxUniformBufferBindings}`); - console.info(`MAX_UNIFORM_BLOCK_SIZE: ${this._maxUniformBlockSize}`); - console.info(`DEPTH_BITS: ${this._depthBits}`); - console.info(`STENCIL_BITS: ${this._stencilBits}`); - console.info(`UNIFORM_BUFFER_OFFSET_ALIGNMENT: ${this._uboOffsetAlignment}`); + console.info(`MAX_VERTEX_ATTRIBS: ${this._caps.maxVertexAttributes}`); + console.info(`MAX_VERTEX_UNIFORM_VECTORS: ${this._caps.maxVertexUniformVectors}`); + console.info(`MAX_FRAGMENT_UNIFORM_VECTORS: ${this._caps.maxFragmentUniformVectors}`); + console.info(`MAX_TEXTURE_IMAGE_UNITS: ${this._caps.maxTextureUnits}`); + console.info(`MAX_VERTEX_TEXTURE_IMAGE_UNITS: ${this._caps.maxVertexTextureUnits}`); + console.info(`MAX_UNIFORM_BUFFER_BINDINGS: ${this._caps.maxUniformBufferBindings}`); + console.info(`MAX_UNIFORM_BLOCK_SIZE: ${this._caps.maxUniformBlockSize}`); + console.info(`DEPTH_BITS: ${this._caps.depthBits}`); + console.info(`STENCIL_BITS: ${this._caps.stencilBits}`); + console.info(`UNIFORM_BUFFER_OFFSET_ALIGNMENT: ${this._caps.uboOffsetAlignment}`); if (this._EXT_texture_filter_anisotropic) { console.info(`MAX_TEXTURE_MAX_ANISOTROPY_EXT: ${this._EXT_texture_filter_anisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT}`); } @@ -379,12 +378,12 @@ export class WebGL2Device extends Device { this.nullTexCube = new WebGL2Texture(this); this.nullTexCube.initialize(new TextureInfo( - TextureType.TEX2D, + TextureType.CUBE, TextureUsageBit.SAMPLED, Format.RGBA8, 2, 2, - TextureFlagBit.CUBEMAP | TextureFlagBit.GEN_MIPMAP, + TextureFlagBit.GEN_MIPMAP, 6, )); @@ -568,14 +567,6 @@ export class WebGL2Device extends Device { return null!; } - public createFence (info: FenceInfo): Fence { - const fence = new WebGL2Fence(this); - if (fence.initialize(info)) { - return fence; - } - return null!; - } - public createQueue (info: QueueInfo): Queue { const queue = new WebGL2Queue(this); if (queue.initialize(info)) { diff --git a/cocos/core/gfx/webgl2/webgl2-fence.ts b/cocos/core/gfx/webgl2/webgl2-fence.ts deleted file mode 100644 index 39555ef6df..0000000000 --- a/cocos/core/gfx/webgl2/webgl2-fence.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - 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. - */ - -import { Fence, FenceInfo } from '../fence'; -import { WebGL2Device } from './webgl2-device'; - -export class WebGL2Fence extends Fence { - private _sync: WebGLSync | null = null; - - public initialize (info: FenceInfo): boolean { - return true; - } - - public destroy () { - } - - public wait () { - if (this._sync) { - const gl = (this._device as WebGL2Device).gl; - gl.clientWaitSync(this._sync, 0, gl.TIMEOUT_IGNORED); - } - } - - public reset () { - if (this._sync) { - const gl = (this._device as WebGL2Device).gl; - gl.deleteSync(this._sync); - this._sync = null; - } - } - - public insert () { - const gl = (this._device as WebGL2Device).gl; - if (this._sync) { gl.deleteSync(this._sync); } - this._sync = gl.fenceSync(gl.SYNC_GPU_COMMANDS_COMPLETE, 0); - } -} diff --git a/cocos/core/gfx/webgl2/webgl2-framebuffer.ts b/cocos/core/gfx/webgl2/webgl2-framebuffer.ts index b4b270cd27..680ac67142 100644 --- a/cocos/core/gfx/webgl2/webgl2-framebuffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-framebuffer.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { Framebuffer, FramebufferInfo } from '../framebuffer'; +import { FramebufferInfo } from '../define'; +import { Framebuffer } from '../framebuffer'; import { WebGL2CmdFuncCreateFramebuffer, WebGL2CmdFuncDestroyFramebuffer } from './webgl2-commands'; import { WebGL2Device } from './webgl2-device'; import { IWebGL2GPUFramebuffer, IWebGL2GPUTexture } from './webgl2-gpu-objects'; @@ -42,7 +43,7 @@ export class WebGL2Framebuffer extends Framebuffer { this._colorTextures = info.colorTextures || []; this._depthStencilTexture = info.depthStencilTexture || null; - if (info.depStencilMipmapLevel !== 0) { + if (info.depthStencilMipmapLevel !== 0) { console.warn('The mipmap level of th texture image to be attached of depth stencil attachment should be 0. Convert to 0.'); } for (let i = 0; i < info.colorMipmapLevels.length; ++i) { diff --git a/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts b/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts index d0eb975391..0a86e4f0ee 100644 --- a/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts +++ b/cocos/core/gfx/webgl2/webgl2-gpu-objects.ts @@ -23,27 +23,12 @@ THE SOFTWARE. */ -import { DrawInfo } from '../buffer'; import { - Address, - DescriptorType, - BufferUsage, - Filter, - Format, - MemoryUsage, - SampleCount, - ShaderStageFlagBit, - TextureFlags, - TextureType, - TextureUsage, - Type, - DynamicStateFlagBit, + Address, DescriptorType, BufferUsage, Filter, Format, MemoryUsage, SampleCount, + ShaderStageFlagBit, TextureFlags, TextureType, TextureUsage, Type, DynamicStateFlagBit, DrawInfo, Attribute, + ColorAttachment, DepthStencilAttachment, UniformBlock, UniformSamplerTexture, DescriptorSetLayoutBinding, } from '../define'; -import { Attribute } from '../input-assembler'; import { BlendState, DepthStencilState, RasterizerState } from '../pipeline-state'; -import { ColorAttachment, DepthStencilAttachment } from '../render-pass'; -import { UniformBlock, UniformSampler } from '../shader'; -import { DescriptorSetLayout, DescriptorSetLayoutBinding } from '../descriptor-set-layout'; export interface IWebGL2GPUUniformInfo { name: string; @@ -162,7 +147,7 @@ export interface IWebGL2GPUUniformBlock { glBinding: number; } -export interface IWebGL2GPUUniformSampler { +export interface IWebGL2GPUUniformSamplerTexture { set: number; binding: number; name: string; @@ -184,14 +169,14 @@ export interface IWebGL2GPUShaderStage { export interface IWebGL2GPUShader { name: string; blocks: UniformBlock[]; - samplers: UniformSampler[]; + samplerTextures: UniformSamplerTexture[]; gpuStages: IWebGL2GPUShaderStage[]; glProgram: WebGLProgram | null; glInputs: IWebGL2GPUInput[]; glUniforms: IWebGL2GPUUniform[]; glBlocks: IWebGL2GPUUniformBlock[]; - glSamplers: IWebGL2GPUUniformSampler[]; + glSamplerTextures: IWebGL2GPUUniformSamplerTexture[]; } export interface IWebGL2GPUDescriptorSetLayout { diff --git a/cocos/core/gfx/webgl2/webgl2-input-assembler.ts b/cocos/core/gfx/webgl2/webgl2-input-assembler.ts index 1796ff401f..88174b1e7c 100644 --- a/cocos/core/gfx/webgl2/webgl2-input-assembler.ts +++ b/cocos/core/gfx/webgl2/webgl2-input-assembler.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { InputAssembler, InputAssemblerInfo } from '../input-assembler'; +import { InputAssemblerInfo } from '../define'; +import { InputAssembler } from '../input-assembler'; import { WebGL2Buffer } from './webgl2-buffer'; import { WebGL2CmdFuncCreateInputAssember, WebGL2CmdFuncDestroyInputAssembler } from './webgl2-commands'; import { WebGL2Device } from './webgl2-device'; diff --git a/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts b/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts index e79ebfe77c..590a78d094 100644 --- a/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts +++ b/cocos/core/gfx/webgl2/webgl2-pipeline-layout.ts @@ -23,9 +23,10 @@ THE SOFTWARE. */ -import { PipelineLayout, PipelineLayoutInfo } from '../pipeline-layout'; +import { PipelineLayout } from '../pipeline-layout'; import { IWebGL2GPUPipelineLayout, IWebGL2GPUDescriptorSetLayout } from './webgl2-gpu-objects'; import { WebGL2DescriptorSetLayout } from './webgl2-descriptor-set-layout'; +import { PipelineLayoutInfo } from '../define'; export class WebGL2PipelineLayout extends PipelineLayout { get gpuPipelineLayout () { return this._gpuPipelineLayout!; } diff --git a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts index 572cfeb344..a9fdd7d7c7 100644 --- a/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts +++ b/cocos/core/gfx/webgl2/webgl2-primary-command-buffer.ts @@ -23,10 +23,9 @@ THE SOFTWARE. */ -import { Buffer, BufferSource, DrawInfo } from '../buffer'; +import { Buffer } from '../buffer'; import { CommandBuffer } from '../command-buffer'; -import { BufferUsageBit } from '../define'; -import { BufferTextureCopy, Color, Rect } from '../define-class'; +import { BufferUsageBit, BufferTextureCopy, Color, Rect, BufferSource, DrawInfo } from '../define'; import { Framebuffer } from '../framebuffer'; import { InputAssembler } from '../input-assembler'; import { Texture } from '../texture'; diff --git a/cocos/core/gfx/webgl2/webgl2-queue.ts b/cocos/core/gfx/webgl2/webgl2-queue.ts index 89b401c12c..9a3f043b70 100644 --- a/cocos/core/gfx/webgl2/webgl2-queue.ts +++ b/cocos/core/gfx/webgl2/webgl2-queue.ts @@ -23,11 +23,10 @@ THE SOFTWARE. */ +import { QueueInfo } from '../define'; import { CommandBuffer } from '../command-buffer'; -import { Queue, QueueInfo } from '../queue'; +import { Queue } from '../queue'; import { WebGL2CommandBuffer } from './webgl2-command-buffer'; -import { Fence } from '../fence'; -import { WebGL2Fence } from './webgl2-fence'; export class WebGL2Queue extends Queue { public numDrawCalls = 0; @@ -43,7 +42,7 @@ export class WebGL2Queue extends Queue { public destroy () { } - public submit (cmdBuffs: CommandBuffer[], fence?: Fence) { + public submit (cmdBuffs: CommandBuffer[]) { // TODO: Async if (!this._isAsync) { for (let i = 0; i < cmdBuffs.length; i++) { @@ -54,9 +53,6 @@ export class WebGL2Queue extends Queue { this.numTris += cmdBuff.numTris; } } - if (fence) { - (fence as WebGL2Fence).insert(); - } } public clear () { diff --git a/cocos/core/gfx/webgl2/webgl2-render-pass.ts b/cocos/core/gfx/webgl2/webgl2-render-pass.ts index c7cfb64290..845370e63b 100644 --- a/cocos/core/gfx/webgl2/webgl2-render-pass.ts +++ b/cocos/core/gfx/webgl2/webgl2-render-pass.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { RenderPass, RenderPassInfo } from '../render-pass'; +import { RenderPassInfo } from '../define'; +import { RenderPass } from '../render-pass'; import { IWebGL2GPURenderPass } from './webgl2-gpu-objects'; export class WebGL2RenderPass extends RenderPass { @@ -36,8 +37,8 @@ export class WebGL2RenderPass extends RenderPass { public initialize (info: RenderPassInfo): boolean { this._colorInfos = info.colorAttachments; this._depthStencilInfo = info.depthStencilAttachment; - if (info.subPasses) { - this._subPasses = info.subPasses; + if (info.subpasses) { + this._subpasses = info.subpasses; } this._gpuRenderPass = { diff --git a/cocos/core/gfx/webgl2/webgl2-sampler.ts b/cocos/core/gfx/webgl2/webgl2-sampler.ts index f101a4d843..0aaf988e8d 100644 --- a/cocos/core/gfx/webgl2/webgl2-sampler.ts +++ b/cocos/core/gfx/webgl2/webgl2-sampler.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { Sampler, SamplerInfo } from '../sampler'; +import { SamplerInfo } from '../define'; +import { Sampler } from '../sampler'; import { WebGL2CmdFuncCreateSampler, WebGL2CmdFuncDestroySampler } from './webgl2-commands'; import { WebGL2Device } from './webgl2-device'; import { IWebGL2GPUSampler } from './webgl2-gpu-objects'; diff --git a/cocos/core/gfx/webgl2/webgl2-shader.ts b/cocos/core/gfx/webgl2/webgl2-shader.ts index f6716f5103..5683fadbfe 100644 --- a/cocos/core/gfx/webgl2/webgl2-shader.ts +++ b/cocos/core/gfx/webgl2/webgl2-shader.ts @@ -23,7 +23,8 @@ THE SOFTWARE. */ -import { Shader, ShaderInfo } from '../shader'; +import { ShaderInfo } from '../define'; +import { Shader } from '../shader'; import { WebGL2CmdFuncCreateShader, WebGL2CmdFuncDestroyShader } from './webgl2-commands'; import { WebGL2Device } from './webgl2-device'; import { IWebGL2GPUShader, IWebGL2GPUShaderStage } from './webgl2-gpu-objects'; @@ -45,14 +46,14 @@ export class WebGL2Shader extends Shader { this._gpuShader = { name: info.name, blocks: info.blocks, - samplers: info.samplers, + samplerTextures: info.samplerTextures, gpuStages: new Array(info.stages.length), glProgram: null, glInputs: [], glUniforms: [], glBlocks: [], - glSamplers: [], + glSamplerTextures: [], }; for (let i = 0; i < info.stages.length; ++i) { diff --git a/cocos/core/gfx/webgl2/webgl2-state-cache.ts b/cocos/core/gfx/webgl2/webgl2-state-cache.ts index 3ece077a40..805a98c826 100644 --- a/cocos/core/gfx/webgl2/webgl2-state-cache.ts +++ b/cocos/core/gfx/webgl2/webgl2-state-cache.ts @@ -23,7 +23,7 @@ THE SOFTWARE. */ -import { Rect, Viewport } from '../define-class'; +import { Rect, Viewport } from '../define'; import { BlendState, DepthStencilState, RasterizerState } from '../pipeline-state'; export interface IWebGL2TexUnit { diff --git a/cocos/core/gfx/webgl2/webgl2-texture.ts b/cocos/core/gfx/webgl2/webgl2-texture.ts index 162938e433..259e2661ad 100644 --- a/cocos/core/gfx/webgl2/webgl2-texture.ts +++ b/cocos/core/gfx/webgl2/webgl2-texture.ts @@ -23,8 +23,8 @@ THE SOFTWARE. */ -import { TextureFlagBit, FormatSurfaceSize } from '../define'; -import { Texture, TextureInfo, IsPowerOf2, TextureViewInfo } from '../texture'; +import { TextureFlagBit, FormatSurfaceSize, TextureInfo, IsPowerOf2, TextureViewInfo } from '../define'; +import { Texture } from '../texture'; import { WebGL2CmdFuncCreateTexture, WebGL2CmdFuncDestroyTexture, WebGL2CmdFuncResizeTexture } from './webgl2-commands'; import { WebGL2Device } from './webgl2-device'; import { IWebGL2GPUTexture } from './webgl2-gpu-objects'; diff --git a/cocos/core/pipeline/define.ts b/cocos/core/pipeline/define.ts index 1097caee58..d40382714a 100644 --- a/cocos/core/pipeline/define.ts +++ b/cocos/core/pipeline/define.ts @@ -34,9 +34,7 @@ import { SubModel } from '../renderer/scene/submodel'; import { Layers } from '../scene-graph/layers'; import { legacyCC } from '../global-exports'; import { BindingMappingInfo, DescriptorType, Type, ShaderStageFlagBit, - DescriptorSetLayoutBinding, Uniform, UniformBlock, UniformSampler } from '../gfx'; -import { Camera } from '../renderer/scene'; -import { DescriptorSetHandle, InputAssemblerHandle } from '../renderer/core/memory-pools'; + DescriptorSetLayoutBinding, Uniform, UniformBlock, UniformSamplerTexture } from '../gfx'; export const PIPELINE_FLOW_GBUFFER = 'GbufferFlow'; export const PIPELINE_FLOW_LIGHTING = 'LightingFlow'; @@ -106,7 +104,7 @@ export interface IRenderQueueDesc { export interface IDescriptorSetLayoutInfo { bindings: DescriptorSetLayoutBinding[]; - layouts: Record; + layouts: Record; } export const globalDescriptorSetLayout: IDescriptorSetLayoutInfo = { bindings: [], layouts: {} }; @@ -261,6 +259,8 @@ export class UBOShadow { globalDescriptorSetLayout.layouts[UBOShadow.NAME] = UBOShadow.LAYOUT; globalDescriptorSetLayout.bindings[UBOShadow.BINDING] = UBOShadow.DESCRIPTOR; +/* eslint-disable max-len */ + /** * @en The sampler for Main light shadow map * @zn 主光源阴影纹理采样器 @@ -268,7 +268,7 @@ globalDescriptorSetLayout.bindings[UBOShadow.BINDING] = UBOShadow.DESCRIPTOR; const UNIFORM_SHADOWMAP_NAME = 'cc_shadowMap'; export const UNIFORM_SHADOWMAP_BINDING = PipelineGlobalBindings.SAMPLER_SHADOWMAP; const UNIFORM_SHADOWMAP_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_SHADOWMAP_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT); -const UNIFORM_SHADOWMAP_LAYOUT = new UniformSampler(SetIndex.GLOBAL, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SHADOWMAP_NAME, Type.SAMPLER2D, 1); +const UNIFORM_SHADOWMAP_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SHADOWMAP_NAME, Type.SAMPLER2D, 1); globalDescriptorSetLayout.layouts[UNIFORM_SHADOWMAP_NAME] = UNIFORM_SHADOWMAP_LAYOUT; globalDescriptorSetLayout.bindings[UNIFORM_SHADOWMAP_BINDING] = UNIFORM_SHADOWMAP_DESCRIPTOR; @@ -310,7 +310,7 @@ globalDescriptorSetLayout.bindings[UNIFORM_GBUFFER_EMISSIVEMAP_BINDING] = UNIFOR const UNIFORM_ENVIRONMENT_NAME = 'cc_environment'; export const UNIFORM_ENVIRONMENT_BINDING = PipelineGlobalBindings.SAMPLER_ENVIRONMENT; const UNIFORM_ENVIRONMENT_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_ENVIRONMENT_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT); -const UNIFORM_ENVIRONMENT_LAYOUT = new UniformSampler(SetIndex.GLOBAL, UNIFORM_ENVIRONMENT_BINDING, UNIFORM_ENVIRONMENT_NAME, Type.SAMPLER_CUBE, 1); +const UNIFORM_ENVIRONMENT_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_ENVIRONMENT_BINDING, UNIFORM_ENVIRONMENT_NAME, Type.SAMPLER_CUBE, 1); globalDescriptorSetLayout.layouts[UNIFORM_ENVIRONMENT_NAME] = UNIFORM_ENVIRONMENT_LAYOUT; globalDescriptorSetLayout.bindings[UNIFORM_ENVIRONMENT_BINDING] = UNIFORM_ENVIRONMENT_DESCRIPTOR; @@ -321,7 +321,7 @@ globalDescriptorSetLayout.bindings[UNIFORM_ENVIRONMENT_BINDING] = UNIFORM_ENVIRO const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME = 'cc_spotLightingMap'; export const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING = PipelineGlobalBindings.SAMPLER_SPOT_LIGHTING_MAP; const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT); -const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_LAYOUT = new UniformSampler(SetIndex.GLOBAL, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME, Type.SAMPLER2D, 1); +const UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.GLOBAL, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME, Type.SAMPLER2D, 1); globalDescriptorSetLayout.layouts[UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_NAME] = UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_LAYOUT; globalDescriptorSetLayout.bindings[UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING] = UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_DESCRIPTOR; @@ -480,7 +480,7 @@ localDescriptorSetLayout.bindings[UBOMorph.BINDING] = UBOMorph.DESCRIPTOR; const UNIFORM_JOINT_TEXTURE_NAME = 'cc_jointTexture'; export const UNIFORM_JOINT_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_JOINTS; const UNIFORM_JOINT_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_JOINT_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.VERTEX); -const UNIFORM_JOINT_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_JOINT_TEXTURE_BINDING, UNIFORM_JOINT_TEXTURE_NAME, Type.SAMPLER2D, 1); +const UNIFORM_JOINT_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_JOINT_TEXTURE_BINDING, UNIFORM_JOINT_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_JOINT_TEXTURE_NAME] = UNIFORM_JOINT_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_JOINT_TEXTURE_BINDING] = UNIFORM_JOINT_TEXTURE_DESCRIPTOR; @@ -491,7 +491,7 @@ localDescriptorSetLayout.bindings[UNIFORM_JOINT_TEXTURE_BINDING] = UNIFORM_JOINT const UNIFORM_POSITION_MORPH_TEXTURE_NAME = 'cc_PositionDisplacements'; export const UNIFORM_POSITION_MORPH_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_MORPH_POSITION; const UNIFORM_POSITION_MORPH_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_POSITION_MORPH_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.VERTEX); -const UNIFORM_POSITION_MORPH_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_POSITION_MORPH_TEXTURE_BINDING, UNIFORM_POSITION_MORPH_TEXTURE_NAME, Type.SAMPLER2D, 1); +const UNIFORM_POSITION_MORPH_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_POSITION_MORPH_TEXTURE_BINDING, UNIFORM_POSITION_MORPH_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_POSITION_MORPH_TEXTURE_NAME] = UNIFORM_POSITION_MORPH_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_POSITION_MORPH_TEXTURE_BINDING] = UNIFORM_POSITION_MORPH_TEXTURE_DESCRIPTOR; @@ -502,7 +502,7 @@ localDescriptorSetLayout.bindings[UNIFORM_POSITION_MORPH_TEXTURE_BINDING] = UNIF const UNIFORM_NORMAL_MORPH_TEXTURE_NAME = 'cc_NormalDisplacements'; export const UNIFORM_NORMAL_MORPH_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_MORPH_NORMAL; const UNIFORM_NORMAL_MORPH_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_NORMAL_MORPH_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.VERTEX); -const UNIFORM_NORMAL_MORPH_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_NORMAL_MORPH_TEXTURE_BINDING, +const UNIFORM_NORMAL_MORPH_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_NORMAL_MORPH_TEXTURE_BINDING, UNIFORM_NORMAL_MORPH_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_NORMAL_MORPH_TEXTURE_NAME] = UNIFORM_NORMAL_MORPH_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_NORMAL_MORPH_TEXTURE_BINDING] = UNIFORM_NORMAL_MORPH_TEXTURE_DESCRIPTOR; @@ -514,7 +514,7 @@ localDescriptorSetLayout.bindings[UNIFORM_NORMAL_MORPH_TEXTURE_BINDING] = UNIFOR const UNIFORM_TANGENT_MORPH_TEXTURE_NAME = 'cc_TangentDisplacements'; export const UNIFORM_TANGENT_MORPH_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_MORPH_TANGENT; const UNIFORM_TANGENT_MORPH_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_TANGENT_MORPH_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.VERTEX); -const UNIFORM_TANGENT_MORPH_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_TANGENT_MORPH_TEXTURE_BINDING, +const UNIFORM_TANGENT_MORPH_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_TANGENT_MORPH_TEXTURE_BINDING, UNIFORM_TANGENT_MORPH_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_TANGENT_MORPH_TEXTURE_NAME] = UNIFORM_TANGENT_MORPH_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_TANGENT_MORPH_TEXTURE_BINDING] = UNIFORM_TANGENT_MORPH_TEXTURE_DESCRIPTOR; @@ -526,7 +526,7 @@ localDescriptorSetLayout.bindings[UNIFORM_TANGENT_MORPH_TEXTURE_BINDING] = UNIFO const UNIFORM_LIGHTMAP_TEXTURE_NAME = 'cc_lightingMap'; export const UNIFORM_LIGHTMAP_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_LIGHTMAP; const UNIFORM_LIGHTMAP_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_LIGHTMAP_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT); -const UNIFORM_LIGHTMAP_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_LIGHTMAP_TEXTURE_BINDING, +const UNIFORM_LIGHTMAP_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_LIGHTMAP_TEXTURE_BINDING, UNIFORM_LIGHTMAP_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_LIGHTMAP_TEXTURE_NAME] = UNIFORM_LIGHTMAP_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_LIGHTMAP_TEXTURE_BINDING] = UNIFORM_LIGHTMAP_TEXTURE_DESCRIPTOR; @@ -538,7 +538,7 @@ localDescriptorSetLayout.bindings[UNIFORM_LIGHTMAP_TEXTURE_BINDING] = UNIFORM_LI const UNIFORM_SPRITE_TEXTURE_NAME = 'cc_spriteTexture'; export const UNIFORM_SPRITE_TEXTURE_BINDING = ModelLocalBindings.SAMPLER_SPRITE; const UNIFORM_SPRITE_TEXTURE_DESCRIPTOR = new DescriptorSetLayoutBinding(UNIFORM_SPRITE_TEXTURE_BINDING, DescriptorType.SAMPLER, 1, ShaderStageFlagBit.FRAGMENT); -const UNIFORM_SPRITE_TEXTURE_LAYOUT = new UniformSampler(SetIndex.LOCAL, UNIFORM_SPRITE_TEXTURE_BINDING, UNIFORM_SPRITE_TEXTURE_NAME, Type.SAMPLER2D, 1); +const UNIFORM_SPRITE_TEXTURE_LAYOUT = new UniformSamplerTexture(SetIndex.LOCAL, UNIFORM_SPRITE_TEXTURE_BINDING, UNIFORM_SPRITE_TEXTURE_NAME, Type.SAMPLER2D, 1); localDescriptorSetLayout.layouts[UNIFORM_SPRITE_TEXTURE_NAME] = UNIFORM_SPRITE_TEXTURE_LAYOUT; localDescriptorSetLayout.bindings[UNIFORM_SPRITE_TEXTURE_BINDING] = UNIFORM_SPRITE_TEXTURE_DESCRIPTOR; @@ -548,3 +548,5 @@ export const CAMERA_DEFAULT_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, export const CAMERA_EDITOR_MASK = Layers.makeMaskExclude([Layers.BitMask.UI_2D, Layers.BitMask.PROFILER]); export const MODEL_ALWAYS_MASK = Layers.Enum.ALL; + +/* eslint-enable max-len */ diff --git a/cocos/core/pipeline/forward/forward-pipeline.ts b/cocos/core/pipeline/forward/forward-pipeline.ts index 2b72eddd7a..605e8d12a0 100644 --- a/cocos/core/pipeline/forward/forward-pipeline.ts +++ b/cocos/core/pipeline/forward/forward-pipeline.ts @@ -34,9 +34,8 @@ import { ForwardFlow } from './forward-flow'; import { RenderTextureConfig, MaterialConfig } from '../pipeline-serialization'; import { ShadowFlow } from '../shadow/shadow-flow'; import { UBOGlobal, UBOShadow, UBOCamera, UNIFORM_SHADOWMAP_BINDING, UNIFORM_SPOT_LIGHTING_MAP_TEXTURE_BINDING } from '../define'; -import { ClearFlag, Filter, Address, StoreOp } from '../../gfx/define'; -import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, TextureLayout, - RenderPassInfo, Feature } from '../../gfx'; +import { ColorAttachment, DepthStencilAttachment, RenderPass, LoadOp, + RenderPassInfo, Feature, ClearFlagBit, ClearFlags, Filter, Address, StoreOp, AccessType } from '../../gfx'; import { SKYBOX_FLAG } from '../../renderer/scene/camera'; import { genSamplerHash, samplerLib } from '../../renderer/core/sampler-lib'; import { builtinResMgr } from '../../builtin'; @@ -68,7 +67,7 @@ export class ForwardPipeline extends RenderPipeline { @serializable @displayOrder(3) protected materials: MaterialConfig[] = []; - protected _renderPasses = new Map(); + protected _renderPasses = new Map(); public initialize (info: IRenderPipelineInfo): boolean { super.initialize(info); @@ -118,7 +117,7 @@ export class ForwardPipeline extends RenderPipeline { this._device.queue.submit(this._commandBuffers); } - public getRenderPass (clearFlags: ClearFlag): RenderPass { + public getRenderPass (clearFlags: ClearFlags): RenderPass { let renderPass = this._renderPasses.get(clearFlags); if (renderPass) { return renderPass; } @@ -130,19 +129,19 @@ export class ForwardPipeline extends RenderPipeline { depthStencilAttachment.stencilStoreOp = StoreOp.DISCARD; depthStencilAttachment.depthStoreOp = StoreOp.DISCARD; - if (!(clearFlags & ClearFlag.COLOR)) { + if (!(clearFlags & ClearFlagBit.COLOR)) { if (clearFlags & SKYBOX_FLAG) { colorAttachment.loadOp = LoadOp.DISCARD; } else { colorAttachment.loadOp = LoadOp.LOAD; - colorAttachment.beginLayout = TextureLayout.PRESENT_SRC; + colorAttachment.beginAccesses = [AccessType.PRESENT]; } } - if ((clearFlags & ClearFlag.DEPTH_STENCIL) !== ClearFlag.DEPTH_STENCIL) { - if (!(clearFlags & ClearFlag.DEPTH)) depthStencilAttachment.depthLoadOp = LoadOp.LOAD; - if (!(clearFlags & ClearFlag.STENCIL)) depthStencilAttachment.stencilLoadOp = LoadOp.LOAD; - depthStencilAttachment.beginLayout = TextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + if ((clearFlags & ClearFlagBit.DEPTH_STENCIL) !== ClearFlagBit.DEPTH_STENCIL) { + if (!(clearFlags & ClearFlagBit.DEPTH)) depthStencilAttachment.depthLoadOp = LoadOp.LOAD; + if (!(clearFlags & ClearFlagBit.STENCIL)) depthStencilAttachment.stencilLoadOp = LoadOp.LOAD; + depthStencilAttachment.beginAccesses = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE]; } const renderPassInfo = new RenderPassInfo([colorAttachment], depthStencilAttachment); diff --git a/cocos/core/pipeline/forward/forward-stage.ts b/cocos/core/pipeline/forward/forward-stage.ts index 99ee1bfc4d..795565cbf1 100644 --- a/cocos/core/pipeline/forward/forward-stage.ts +++ b/cocos/core/pipeline/forward/forward-stage.ts @@ -32,7 +32,7 @@ import { ccclass, displayOrder, type, serializable } from 'cc.decorator'; import { IRenderPass, SetIndex } from '../define'; import { getPhaseID } from '../pass-phase'; import { opaqueCompareFn, RenderQueue, transparentCompareFn } from '../render-queue'; -import { ClearFlag } from '../../gfx/define'; +import { ClearFlagBit } from '../../gfx/define'; import { Color, Rect } from '../../gfx'; import { SRGBToLinear } from '../pipeline-funcs'; import { RenderBatchedQueue } from '../render-batched-queue'; @@ -195,7 +195,7 @@ export class ForwardStage extends RenderStage { this._renderArea.width = vp.width * w * sceneData.shadingScale; this._renderArea.height = vp.height * h * sceneData.shadingScale; - if (camera.clearFlag & ClearFlag.COLOR) { + if (camera.clearFlag & ClearFlagBit.COLOR) { if (sceneData.isHDR) { SRGBToLinear(colors[0], camera.clearColor); const scale = sceneData.fpScale / camera.exposure; diff --git a/cocos/core/pipeline/pipeline-serialization.ts b/cocos/core/pipeline/pipeline-serialization.ts index b337516350..e33ae792c9 100644 --- a/cocos/core/pipeline/pipeline-serialization.ts +++ b/cocos/core/pipeline/pipeline-serialization.ts @@ -30,7 +30,7 @@ import { ccclass, type, serializable, editable } from 'cc.decorator'; import { CCString } from '../data/utils/attribute'; -import { Format, LoadOp, StoreOp, TextureLayout, TextureType, TextureUsageBit } from '../gfx/define'; +import { AccessType, Format, LoadOp, StoreOp, TextureType, TextureUsageBit } from '../gfx/define'; import { ccenum } from '../value-types/enum'; import { RenderTexture } from '../assets/render-texture'; import { Material } from '../assets/material'; @@ -39,7 +39,7 @@ ccenum(TextureType); ccenum(TextureUsageBit); ccenum(StoreOp); ccenum(LoadOp); -ccenum(TextureLayout); +ccenum(AccessType); /** * @en The tag of the render flow, including SCENE, POSTPROCESS and UI. @@ -118,10 +118,10 @@ export class ColorDesc { @serializable @editable public sampleCount = 1; - @type(TextureLayout) - public beginLayout: TextureLayout = TextureLayout.UNDEFINED; - @type(TextureLayout) - public endLayout: TextureLayout = TextureLayout.PRESENT_SRC; + @type([AccessType]) + public beginAccesses: AccessType[] = []; + @type([AccessType]) + public endAccesses: AccessType[] = [AccessType.PRESENT]; } @ccclass('DepthStencilDesc') @@ -139,10 +139,10 @@ export class DepthStencilDesc { @serializable @editable public sampleCount = 1; - @type(TextureLayout) - public beginLayout: TextureLayout = TextureLayout.UNDEFINED; - @type(TextureLayout) - public endLayout: TextureLayout = TextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; + @type([AccessType]) + public beginAccesses: AccessType[] = []; + @type([AccessType]) + public endAccesses: AccessType[] = [AccessType.DEPTH_STENCIL_ATTACHMENT_WRITE]; } @ccclass('RenderPassDesc') diff --git a/cocos/core/pipeline/pipeline-ubo.ts b/cocos/core/pipeline/pipeline-ubo.ts index 36c5848c27..5180771912 100644 --- a/cocos/core/pipeline/pipeline-ubo.ts +++ b/cocos/core/pipeline/pipeline-ubo.ts @@ -130,13 +130,13 @@ export class PipelineUBO { Mat4.toArray(cv, camera.matProjInvOffscreen, UBOCamera.MAT_PROJ_INV_OFFSET); Mat4.toArray(cv, camera.matViewProjOffscreen, UBOCamera.MAT_VIEW_PROJ_OFFSET); Mat4.toArray(cv, camera.matViewProjInvOffscreen, UBOCamera.MAT_VIEW_PROJ_INV_OFFSET); - cv[UBOCamera.CAMERA_POS_OFFSET + 3] = device.screenSpaceSignY * device.UVSpaceSignY; + cv[UBOCamera.CAMERA_POS_OFFSET + 3] = device.capabilities.screenSpaceSignY * device.capabilities.UVSpaceSignY; } else { Mat4.toArray(cv, camera.matProj, UBOCamera.MAT_PROJ_OFFSET); Mat4.toArray(cv, camera.matProjInv, UBOCamera.MAT_PROJ_INV_OFFSET); Mat4.toArray(cv, camera.matViewProj, UBOCamera.MAT_VIEW_PROJ_OFFSET); Mat4.toArray(cv, camera.matViewProjInv, UBOCamera.MAT_VIEW_PROJ_INV_OFFSET); - cv[UBOCamera.CAMERA_POS_OFFSET + 3] = device.screenSpaceSignY; + cv[UBOCamera.CAMERA_POS_OFFSET + 3] = device.capabilities.screenSpaceSignY; } if (fog.enabled) { @@ -188,9 +188,9 @@ export class PipelineUBO { Mat4.invert(matShadowView, shadowCameraView!); - const projectionSignY = device.screenSpaceSignY * device.UVSpaceSignY; // always offscreen + const projectionSignY = device.capabilities.screenSpaceSignY * device.capabilities.UVSpaceSignY; // always offscreen Mat4.ortho(matShadowViewProj, -x, x, -y, y, shadowInfo.near, far, - device.clipSpaceMinZ, projectionSignY); + device.capabilities.clipSpaceMinZ, projectionSignY); Mat4.multiply(matShadowViewProj, matShadowViewProj, matShadowView); Mat4.toArray(sv, matShadowViewProj, UBOShadow.MAT_LIGHT_VIEW_PROJ_OFFSET); @@ -241,7 +241,7 @@ export class PipelineUBO { Mat4.invert(matShadowView, _shadowCameraView); Mat4.ortho(matShadowViewProj, -_x, _x, -_y, _y, shadowInfo.near, _far, - device.clipSpaceMinZ, device.screenSpaceSignY * device.UVSpaceSignY); + device.capabilities.clipSpaceMinZ, device.capabilities.screenSpaceSignY * device.capabilities.UVSpaceSignY); break; case LightType.SPOT: // light view diff --git a/cocos/core/pipeline/render-additive-light-queue.ts b/cocos/core/pipeline/render-additive-light-queue.ts index c6d358f40e..80be720860 100644 --- a/cocos/core/pipeline/render-additive-light-queue.ts +++ b/cocos/core/pipeline/render-additive-light-queue.ts @@ -35,10 +35,10 @@ import { Model } from '../renderer/scene/model'; import { PipelineStateManager } from './pipeline-state-manager'; import { DSPool, ShaderPool, PassView, PassPool, SubModelPool, SubModelView, ShaderHandle } from '../renderer/core/memory-pools'; -import { Vec3, nextPow2, Mat4, Vec4, Color } from '../math'; +import { Vec3, nextPow2, Mat4, Color } from '../math'; import { Sphere, intersect } from '../geometry'; import { Device, RenderPass, Buffer, BufferUsageBit, MemoryUsageBit, - BufferInfo, BufferViewInfo, CommandBuffer, Filter, Address, Sampler, DescriptorSet, Texture, DescriptorSetInfo } from '../gfx'; + BufferInfo, BufferViewInfo, CommandBuffer, Filter, Address, Sampler, DescriptorSet, DescriptorSetInfo } from '../gfx'; import { Pool } from '../memop'; import { RenderBatchedQueue } from './render-batched-queue'; import { RenderInstancedQueue } from './render-instanced-queue'; @@ -54,7 +54,6 @@ import { builtinResMgr } from '../builtin/builtin-res-mgr'; import { Texture2D } from '../assets/texture-2d'; import { updatePlanarPROJ } from './scene-culling'; import { Camera } from '../renderer/scene'; -import { view } from '../platform'; import { PipelineUBO } from './pipeline-ubo'; const _samplerInfo = [ @@ -141,7 +140,8 @@ export class RenderAdditiveLightQueue { this._instancedQueue = new RenderInstancedQueue(); this._batchedQueue = new RenderBatchedQueue(); - this._lightBufferStride = Math.ceil(UBOForwardLight.SIZE / this._device.uboOffsetAlignment) * this._device.uboOffsetAlignment; + const alignment = this._device.capabilities.uboOffsetAlignment; + this._lightBufferStride = Math.ceil(UBOForwardLight.SIZE / alignment) * alignment; this._lightBufferElementCount = this._lightBufferStride / Float32Array.BYTES_PER_ELEMENT; this._lightBuffer = this._device.createBuffer(new BufferInfo( diff --git a/cocos/core/pipeline/shadow/shadow-flow.ts b/cocos/core/pipeline/shadow/shadow-flow.ts index aa4dd5134f..7faf58e6e7 100644 --- a/cocos/core/pipeline/shadow/shadow-flow.ts +++ b/cocos/core/pipeline/shadow/shadow-flow.ts @@ -34,7 +34,7 @@ import { IRenderFlowInfo, RenderFlow } from '../render-flow'; import { ForwardFlowPriority } from '../forward/enum'; import { ShadowStage } from './shadow-stage'; import { RenderPass, LoadOp, StoreOp, - TextureLayout, Format, Texture, TextureType, TextureUsageBit, ColorAttachment, + Format, Texture, TextureType, TextureUsageBit, ColorAttachment, DepthStencilAttachment, RenderPassInfo, TextureInfo, FramebufferInfo } from '../../gfx'; import { RenderFlowTag } from '../pipeline-serialization'; import { ForwardPipeline } from '../forward/forward-pipeline'; @@ -146,8 +146,6 @@ export class ShadowFlow extends RenderFlow { colorAttachment.loadOp = LoadOp.CLEAR; // should clear color attachment colorAttachment.storeOp = StoreOp.STORE; colorAttachment.sampleCount = 1; - colorAttachment.beginLayout = TextureLayout.UNDEFINED; - colorAttachment.endLayout = TextureLayout.PRESENT_SRC; const depthStencilAttachment = new DepthStencilAttachment(); depthStencilAttachment.format = device.depthStencilFormat; @@ -156,8 +154,6 @@ export class ShadowFlow extends RenderFlow { depthStencilAttachment.stencilLoadOp = LoadOp.CLEAR; depthStencilAttachment.stencilStoreOp = StoreOp.DISCARD; depthStencilAttachment.sampleCount = 1; - depthStencilAttachment.beginLayout = TextureLayout.UNDEFINED; - depthStencilAttachment.endLayout = TextureLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL; const renderPassInfo = new RenderPassInfo([colorAttachment], depthStencilAttachment); this._shadowRenderPass = device.createRenderPass(renderPassInfo); diff --git a/cocos/core/renderer/core/memory-pools.ts b/cocos/core/renderer/core/memory-pools.ts index 188355b019..6a074673ad 100644 --- a/cocos/core/renderer/core/memory-pools.ts +++ b/cocos/core/renderer/core/memory-pools.ts @@ -34,7 +34,7 @@ import { DescriptorSetInfo, Device, DescriptorSet, ShaderInfo, Shader, InputAssemblerInfo, InputAssembler, PipelineLayoutInfo, PipelineLayout, Framebuffer, FramebufferInfo, PrimitiveMode, - DynamicStateFlags, ClearFlag, Color as GFXColor, + DynamicStateFlags, Color as GFXColor, ClearFlags, } from '../../gfx'; import { RenderPassStage } from '../../pipeline/define'; import { BatchingSchemes } from './pass'; @@ -836,7 +836,9 @@ const batchView2DDataType: BufferDataTypeManifest = { [BatchView2D.COUNT]: BufferDataType.NEVER, }; -export const BatchPool2D = new BufferPool(PoolType.BATCH_2D, batchView2DDataType, BatchView2D); +export const BatchPool2D = new BufferPool( + PoolType.BATCH_2D, batchView2DDataType, BatchView2D, +); export enum AABBView { CENTER, // Vec3 @@ -891,7 +893,7 @@ export enum CameraView { WIDTH, HEIGHT, EXPOSURE, - CLEAR_FLAG, + CLEAR_FLAGS, CLEAR_DEPTH, CLEAR_STENCIL, VISIBILITY, @@ -918,7 +920,7 @@ interface ICameraViewType extends BufferTypeManifest { [CameraView.WIDTH]: number; [CameraView.HEIGHT]: number; [CameraView.EXPOSURE]: number; - [CameraView.CLEAR_FLAG]: ClearFlag; + [CameraView.CLEAR_FLAGS]: ClearFlags; [CameraView.CLEAR_DEPTH]: number; [CameraView.CLEAR_STENCIL]: number; [CameraView.VISIBILITY]: number, @@ -945,7 +947,7 @@ const cameraViewDataType: BufferDataTypeManifest = { [CameraView.WIDTH]: BufferDataType.UINT32, [CameraView.HEIGHT]: BufferDataType.UINT32, [CameraView.EXPOSURE]: BufferDataType.FLOAT32, - [CameraView.CLEAR_FLAG]: BufferDataType.UINT32, + [CameraView.CLEAR_FLAGS]: BufferDataType.UINT32, [CameraView.CLEAR_DEPTH]: BufferDataType.FLOAT32, [CameraView.CLEAR_STENCIL]: BufferDataType.UINT32, [CameraView.VISIBILITY]: BufferDataType.UINT32, diff --git a/cocos/core/renderer/core/pass-instance.ts b/cocos/core/renderer/core/pass-instance.ts index 9e53014647..e22a9a74cb 100644 --- a/cocos/core/renderer/core/pass-instance.ts +++ b/cocos/core/renderer/core/pass-instance.ts @@ -64,8 +64,8 @@ export class PassInstance extends Pass { } this._rootBufferDirty = true; const paren = this._parent as PassInstance; - for (let i = 0; i < this._shaderInfo.samplers.length; i++) { - const u = this._shaderInfo.samplers[i]; + for (let i = 0; i < this._shaderInfo.samplerTextures.length; i++) { + const u = this._shaderInfo.samplerTextures[i]; for (let j = 0; j < u.count; j++) { const sampler = paren._descriptorSet.getSampler(u.binding, j); const texture = paren._descriptorSet.getTexture(u.binding, j); diff --git a/cocos/core/renderer/core/pass-utils.ts b/cocos/core/renderer/core/pass-utils.ts index 5c37bb81ef..9a381c237a 100644 --- a/cocos/core/renderer/core/pass-utils.ts +++ b/cocos/core/renderer/core/pass-utils.ts @@ -45,11 +45,11 @@ export enum PropertyType { /** * Uniform buffer object */ - UBO, + BUFFER, /** * Texture sampler */ - SAMPLER, + TEXTURE, } export const genHandle = (pt: PropertyType, set: number, binding: number, type: Type, offset = 0): number => ((pt << 28) & dtMask) | ((type << 22) & typeMask) | ((set << 20) & setMask) | ((binding << 14) & bindingMask) | (offset & offsetMask); diff --git a/cocos/core/renderer/core/pass.ts b/cocos/core/renderer/core/pass.ts index 3f3dbc5eea..c6a0e643a9 100644 --- a/cocos/core/renderer/core/pass.ts +++ b/cocos/core/renderer/core/pass.ts @@ -29,7 +29,6 @@ */ import { EDITOR } from 'internal:constants'; -import { Color } from '../../gfx/define-class'; import { Root } from '../../root'; import { TextureBase } from '../../assets/texture-base'; import { builtinResMgr } from '../../builtin/builtin-res-mgr'; @@ -37,12 +36,10 @@ import { getPhaseID } from '../../pipeline/pass-phase'; import { murmurhash2_32_gc } from '../../utils/murmurhash2_gc'; import { samplerLib } from './sampler-lib'; import { + BufferUsageBit, DynamicStateFlagBit, DynamicStateFlags, Feature, GetTypeSize, MemoryUsageBit, PrimitiveMode, Type, Color, BlendState, BlendTarget, Buffer, BufferInfo, BufferViewInfo, DepthStencilState, DescriptorSet, DescriptorSetInfo, DescriptorSetLayout, Device, RasterizerState, Sampler, Texture, } from '../../gfx'; -import { - BufferUsageBit, DynamicStateFlagBit, DynamicStateFlags, Feature, GetTypeSize, MemoryUsageBit, PrimitiveMode, Type, -} from '../../gfx/define'; import { DSPool, NULL_HANDLE, PassHandle, PassPool, PassView, ShaderHandle, } from './memory-pools'; @@ -473,8 +470,8 @@ export class Pass { * @zh 重置所有 texture 和 sampler 为初始默认值。 */ public resetTextures (): void { - for (let i = 0; i < this._shaderInfo.samplers.length; i++) { - const u = this._shaderInfo.samplers[i]; + for (let i = 0; i < this._shaderInfo.samplerTextures.length; i++) { + const u = this._shaderInfo.samplerTextures[i]; for (let j = 0; j < u.count; j++) { this.resetTexture(u.name, j); } @@ -577,7 +574,7 @@ export class Pass { const blocks = this._shaderInfo.blocks; const tmplInfo = programLib.getTemplateInfo(info.program); const { blockSizes, handleMap } = tmplInfo; - const alignment = device.uboOffsetAlignment; + const alignment = device.capabilities.uboOffsetAlignment; const startOffsets: number[] = []; let lastSize = 0; let lastOffset = 0; for (let i = 0; i < blocks.length; i++) { diff --git a/cocos/core/renderer/core/program-lib.ts b/cocos/core/renderer/core/program-lib.ts index 6549ca56d8..7393603a69 100644 --- a/cocos/core/renderer/core/program-lib.ts +++ b/cocos/core/renderer/core/program-lib.ts @@ -34,10 +34,10 @@ import { RenderPipeline } from '../../pipeline/render-pipeline'; import { genHandle, MacroRecord, PropertyType } from './pass-utils'; import { legacyCC } from '../../global-exports'; import { ShaderPool, ShaderHandle, PipelineLayoutHandle, PipelineLayoutPool, NULL_HANDLE } from './memory-pools'; -import { PipelineLayoutInfo, Device, Attribute, UniformBlock, ShaderInfo, UniformSampler, +import { PipelineLayoutInfo, Device, Attribute, UniformBlock, ShaderInfo, Uniform, ShaderStage, DESCRIPTOR_SAMPLER_TYPE, DESCRIPTOR_BUFFER_TYPE, DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo, - DescriptorType, GetTypeSize, ShaderStageFlagBit, API } from '../../gfx'; + DescriptorType, GetTypeSize, ShaderStageFlagBit, API, UniformSamplerTexture } from '../../gfx'; const _dsLayoutInfo = new DescriptorSetLayoutInfo(); @@ -48,7 +48,7 @@ interface IDefineRecord extends IDefineInfo { export interface ITemplateInfo { gfxBlocks: UniformBlock[]; - gfxSamplers: UniformSampler[]; + gfxSamplerTextures: UniformSamplerTexture[]; gfxAttributes: Attribute[]; blockSizes: number[]; gfxStages: ShaderStage[]; @@ -121,19 +121,19 @@ function insertBuiltinBindings ( if (outBindings && !outBindings.includes(binding)) outBindings.push(binding); } Array.prototype.unshift.apply(tmplInfo.gfxBlocks, tempBlocks); - const tempSamplers: UniformSampler[] = []; - for (let i = 0; i < target.samplers.length; i++) { - const s = target.samplers[i]; - const info = source.layouts[s.name] as UniformSampler; + const tempSamplerTextures: UniformSamplerTexture[] = []; + for (let i = 0; i < target.samplerTextures.length; i++) { + const s = target.samplerTextures[i]; + const info = source.layouts[s.name] as UniformSamplerTexture; const binding = info && source.bindings.find((bd) => bd.binding === info.binding); if (!info || !binding || !(binding.descriptorType & DESCRIPTOR_SAMPLER_TYPE)) { - console.warn(`builtin sampler '${s.name}' not available!`); + console.warn(`builtin samplerTexture '${s.name}' not available!`); continue; } - tempSamplers.push(info); + tempSamplerTextures.push(info); if (outBindings && !outBindings.includes(binding)) outBindings.push(binding); } - Array.prototype.unshift.apply(tmplInfo.gfxSamplers, tempSamplers); + Array.prototype.unshift.apply(tmplInfo.gfxSamplerTextures, tempSamplerTextures); if (outBindings) outBindings.sort((a, b) => a.binding - b.binding); } @@ -150,14 +150,14 @@ function genHandles (tmpl: IProgramInfo) { let offset = 0; for (let j = 0; j < members.length; j++) { const uniform = members[j]; - handleMap[uniform.name] = genHandle(PropertyType.UBO, SetIndex.MATERIAL, block.binding, uniform.type, offset); + handleMap[uniform.name] = genHandle(PropertyType.BUFFER, SetIndex.MATERIAL, block.binding, uniform.type, offset); offset += (GetTypeSize(uniform.type) >> 2) * uniform.count; } } - // sampler handles - for (let i = 0; i < tmpl.samplers.length; i++) { - const sampler = tmpl.samplers[i]; - handleMap[sampler.name] = genHandle(PropertyType.SAMPLER, SetIndex.MATERIAL, sampler.binding, sampler.type); + // samplerTexture handles + for (let i = 0; i < tmpl.samplerTextures.length; i++) { + const samplerTexture = tmpl.samplerTextures[i]; + handleMap[samplerTexture.name] = genHandle(PropertyType.TEXTURE, SetIndex.MATERIAL, samplerTexture.binding, samplerTexture.type); } return handleMap; } @@ -233,7 +233,7 @@ class ProgramLib { const tmplInfo = {} as ITemplateInfo; // cache material-specific descriptor set layout tmplInfo.samplerStartBinding = tmpl.blocks.length; - tmplInfo.gfxBlocks = []; tmplInfo.gfxSamplers = []; + tmplInfo.gfxBlocks = []; tmplInfo.gfxSamplerTextures = []; tmplInfo.bindings = []; tmplInfo.blockSizes = []; for (let i = 0; i < tmpl.blocks.length; i++) { const block = tmpl.blocks[i]; @@ -243,11 +243,13 @@ class ProgramLib { tmplInfo.gfxBlocks.push(new UniformBlock(SetIndex.MATERIAL, block.binding, block.name, block.members.map((m) => new Uniform(m.name, m.type, m.count)), 1)); // effect compiler guarantees block count = 1 } - for (let i = 0; i < tmpl.samplers.length; i++) { - const sampler = tmpl.samplers[i]; - tmplInfo.bindings.push(new DescriptorSetLayoutBinding(sampler.binding, sampler.descriptorType || DescriptorType.SAMPLER, - sampler.count, sampler.stageFlags)); - tmplInfo.gfxSamplers.push(new UniformSampler(SetIndex.MATERIAL, sampler.binding, sampler.name, sampler.type, sampler.count)); + for (let i = 0; i < tmpl.samplerTextures.length; i++) { + const samplerTexture = tmpl.samplerTextures[i]; + tmplInfo.bindings.push(new DescriptorSetLayoutBinding(samplerTexture.binding, + samplerTexture.descriptorType || DescriptorType.SAMPLER_TEXTURE, samplerTexture.count, samplerTexture.stageFlags)); + tmplInfo.gfxSamplerTextures.push(new UniformSamplerTexture( + SetIndex.MATERIAL, samplerTexture.binding, samplerTexture.name, samplerTexture.type, samplerTexture.count, + )); } tmplInfo.gfxAttributes = []; for (let i = 0; i < tmpl.attributes.length; i++) { @@ -415,7 +417,8 @@ class ProgramLib { const attributes = getActiveAttributes(tmpl, tmplInfo, defines); const instanceName = getShaderInstanceName(name, macroArray); - const shaderInfo = new ShaderInfo(instanceName, tmplInfo.gfxStages, attributes, tmplInfo.gfxBlocks, tmplInfo.gfxSamplers); + const shaderInfo = new ShaderInfo(instanceName, tmplInfo.gfxStages, attributes, tmplInfo.gfxBlocks); + shaderInfo.samplerTextures = tmplInfo.gfxSamplerTextures; return this._cache[key] = ShaderPool.alloc(device, shaderInfo); } } diff --git a/cocos/core/renderer/core/render-window.ts b/cocos/core/renderer/core/render-window.ts index 6c090e463a..43da2d32ed 100644 --- a/cocos/core/renderer/core/render-window.ts +++ b/cocos/core/renderer/core/render-window.ts @@ -266,8 +266,7 @@ export class RenderWindow { } } - public extractRenderCameras () { - const cameras: Camera[] = []; + public extractRenderCameras (cameras: Camera[]) { for (let j = 0; j < this._cameras.length; j++) { const camera = this._cameras[j]; if (camera.enabled) { @@ -275,8 +274,6 @@ export class RenderWindow { cameras.push(camera); } } - - return cameras; } /** diff --git a/cocos/core/renderer/scene/camera.ts b/cocos/core/renderer/scene/camera.ts index f46eb76b42..27ec2a7466 100644 --- a/cocos/core/renderer/scene/camera.ts +++ b/cocos/core/renderer/scene/camera.ts @@ -25,18 +25,18 @@ import { JSB } from 'internal:constants'; import { Frustum, Ray } from '../../geometry'; -import { ClearFlag, SurfaceTransform } from '../../gfx/define'; +import { SurfaceTransform, ClearFlagBit } from '../../gfx/define'; import { lerp, Mat4, Rect, toRadian, Vec3, IVec4Like, } from '../../math'; import { CAMERA_DEFAULT_MASK } from '../../pipeline/define'; import { Node } from '../../scene-graph'; import { RenderScene } from './render-scene'; -import { Device, Color } from '../../gfx'; +import { Device, Color, ClearFlags } from '../../gfx'; import { legacyCC } from '../../global-exports'; import { RenderWindow } from '../core/render-window'; import { - CameraHandle, CameraPool, CameraView, FrustumHandle, FrustumPool, NULL_HANDLE, SceneHandle, RenderWindowHandle, + CameraHandle, CameraPool, CameraView, FrustumHandle, FrustumPool, NULL_HANDLE, SceneHandle, } from '../core/memory-pools'; import { recordFrustumToSharedMemory } from '../../geometry/frustum'; import { preTransforms } from '../../math/mat4'; @@ -120,7 +120,7 @@ const v_a = new Vec3(); const v_b = new Vec3(); const _tempMat1 = new Mat4(); -export const SKYBOX_FLAG = ClearFlag.STENCIL << 1; +export const SKYBOX_FLAG = ClearFlagBit.STENCIL << 1; const correctionMatrices: Mat4[] = []; @@ -178,7 +178,7 @@ export class Camera { this._aspect = this.screenScale = 1; if (!correctionMatrices.length) { - const ySign = device.screenSpaceSignY; + const ySign = device.capabilities.screenSpaceSignY; correctionMatrices[SurfaceTransform.IDENTITY] = new Mat4(1, 0, 0, 0, 0, ySign); correctionMatrices[SurfaceTransform.ROTATE_90] = new Mat4(0, 1, 0, 0, -ySign, 0); correctionMatrices[SurfaceTransform.ROTATE_180] = new Mat4(-1, 0, 0, 0, 0, -ySign); @@ -196,7 +196,7 @@ export class Camera { const handle = this._poolHandle = CameraPool.alloc(); CameraPool.set(handle, CameraView.WIDTH, 1); CameraPool.set(handle, CameraView.HEIGHT, 1); - CameraPool.set(handle, CameraView.CLEAR_FLAG, ClearFlag.NONE); + CameraPool.set(handle, CameraView.CLEAR_FLAGS, ClearFlagBit.NONE); CameraPool.set(handle, CameraView.CLEAR_DEPTH, 1.0); CameraPool.set(handle, CameraView.NODE, this._node.handle); CameraPool.set(handle, CameraView.VISIBILITY, CAMERA_DEFAULT_MASK); @@ -278,22 +278,24 @@ export class Camera { const orientation = this._device.surfaceTransform; if (this._isProjDirty || this._curTransform !== orientation) { this._curTransform = orientation; - const projectionSignY = this._device.screenSpaceSignY; + const projectionSignY = this._device.capabilities.screenSpaceSignY; if (this._proj === CameraProjection.PERSPECTIVE) { Mat4.perspective(this._matProj, this._fov, this._aspect, this._nearClip, this._farClip, - this._fovAxis === CameraFOVAxis.VERTICAL, this._device.clipSpaceMinZ, projectionSignY, orientation); + this._fovAxis === CameraFOVAxis.VERTICAL, this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation); Mat4.perspective(this._matProjOffscreen, this._fov, this._aspect, this._nearClip, this._farClip, - this._fovAxis === CameraFOVAxis.VERTICAL, this._device.clipSpaceMinZ, projectionSignY * this._device.UVSpaceSignY, + this._fovAxis === CameraFOVAxis.VERTICAL, + this._device.capabilities.clipSpaceMinZ, + projectionSignY * this._device.capabilities.UVSpaceSignY, SurfaceTransform.IDENTITY); } else { const x = this._orthoHeight * this._aspect; // aspect is already oriented const y = this._orthoHeight; Mat4.ortho(this._matProj, -x, x, -y, y, this._nearClip, this._farClip, - this._device.clipSpaceMinZ, projectionSignY, orientation); + this._device.capabilities.clipSpaceMinZ, projectionSignY, orientation); Mat4.ortho(this._matProjOffscreen, -x, x, -y, y, this._nearClip, this._farClip, - this._device.clipSpaceMinZ, projectionSignY * this._device.UVSpaceSignY, SurfaceTransform.IDENTITY); + this._device.capabilities.clipSpaceMinZ, projectionSignY * this._device.capabilities.UVSpaceSignY, SurfaceTransform.IDENTITY); } Mat4.invert(this._matProjInv, this._matProj); Mat4.invert(this._matProjInvOffscreen, this._matProjOffscreen); @@ -409,7 +411,7 @@ export class Camera { set viewport (val) { const { x, width, height } = val; - const y = this._device.screenSpaceSignY < 0 ? 1 - val.y - height : val.y; + const y = this._device.capabilities.screenSpaceSignY < 0 ? 1 - val.y - height : val.y; switch (this._device.surfaceTransform) { case SurfaceTransform.ROTATE_90: @@ -637,12 +639,12 @@ export class Camera { return CameraPool.get(this._poolHandle, CameraView.EXPOSURE); } - get clearFlag () : ClearFlag { - return CameraPool.get(this._poolHandle, CameraView.CLEAR_FLAG); + get clearFlag () : ClearFlags { + return CameraPool.get(this._poolHandle, CameraView.CLEAR_FLAGS); } - set clearFlag (flag: ClearFlag) { - CameraPool.set(this._poolHandle, CameraView.CLEAR_FLAG, flag); + set clearFlag (flag: ClearFlags) { + CameraPool.set(this._poolHandle, CameraView.CLEAR_FLAGS, flag); } get clearDepth () : number { @@ -698,7 +700,7 @@ export class Camera { const cw = this._viewport.width * width; const ch = this._viewport.height * height; const isProj = this._proj === CameraProjection.PERSPECTIVE; - const ySign = this._device.screenSpaceSignY; + const ySign = this._device.capabilities.screenSpaceSignY; const preTransform = preTransforms[this._curTransform]; Vec3.set(v_a, (x - cx) / cw * 2 - 1, (y - cy) / ch * 2 - 1, isProj ? 1 : -1); @@ -731,7 +733,7 @@ export class Camera { const cy = this._viewport.y * height; const cw = this._viewport.width * width; const ch = this._viewport.height * height; - const ySign = this._device.screenSpaceSignY; + const ySign = this._device.capabilities.screenSpaceSignY; const preTransform = preTransforms[this._curTransform]; if (this._proj === CameraProjection.PERSPECTIVE) { @@ -778,7 +780,7 @@ export class Camera { const cy = this._viewport.y * height; const cw = this._viewport.width * width; const ch = this._viewport.height * height; - const ySign = this._device.screenSpaceSignY; + const ySign = this._device.capabilities.screenSpaceSignY; const preTransform = preTransforms[this._curTransform]; Vec3.transformMat4(out, worldPos, this._matViewProj); diff --git a/cocos/core/root.ts b/cocos/core/root.ts index 26ac84fea9..eb0fab8cac 100644 --- a/cocos/core/root.ts +++ b/cocos/core/root.ts @@ -414,10 +414,7 @@ export class Root { const cameraList: Camera[] = []; for (let i = 0; i < windows.length; i++) { const window = windows[i]; - const cameras = window.extractRenderCameras(); - cameras.forEach((camera) => { - cameraList.push(camera); - }); + window.extractRenderCameras(cameraList); } cameraList.sort((a: Camera, b: Camera) => a.priority - b.priority); this._pipeline.render(cameraList); diff --git a/cocos/core/splash-screen.ts b/cocos/core/splash-screen.ts index a795bef19e..48b0390d55 100644 --- a/cocos/core/splash-screen.ts +++ b/cocos/core/splash-screen.ts @@ -399,7 +399,7 @@ export class SplashScreen { } // doing the screen adaptation here will not support dynamic screen orientation changes - const ySign = this.device.screenSpaceSignY; + const ySign = this.device.capabilities.screenSpaceSignY; const preTransform = preTransforms[this.device.surfaceTransform]; for (let i = 0; i < verts.length; i += 4) { const x = verts[i] / this.screenWidth * 2 - 1; @@ -483,7 +483,7 @@ export class SplashScreen { } // doing the screen adaptation here will not support dynamic screen orientation changes - const ySign = this.device.screenSpaceSignY; + const ySign = this.device.capabilities.screenSpaceSignY; const preTransform = preTransforms[this.device.surfaceTransform]; for (let i = 0; i < verts.length; i += 4) { const x = verts[i] / this.screenWidth * 2 - 1; diff --git a/cocos/particle/renderer/particle-system-renderer-data.ts b/cocos/particle/renderer/particle-system-renderer-data.ts index 112b086cf5..91ee85e068 100644 --- a/cocos/particle/renderer/particle-system-renderer-data.ts +++ b/cocos/particle/renderer/particle-system-renderer-data.ts @@ -35,7 +35,7 @@ import { legacyCC } from '../../core/global-exports'; function isSupportGPUParticle () { const device: Device = director.root!.device; - if (device.maxVertexTextureUnits >= 8 && device.hasFeature(Feature.TEXTURE_FLOAT)) { + if (device.capabilities.maxVertexTextureUnits >= 8 && device.hasFeature(Feature.TEXTURE_FLOAT)) { return true; } @@ -131,10 +131,10 @@ export default class ParticleSystemRenderer { if (!this._particleSystem) { return null; } - return this._particleSystem.getMaterial(0); + return this._particleSystem.getMaterial(0) as Material; } - public set particleMaterial (val) { + public set particleMaterial (val: Material | null) { this._particleSystem.setMaterial(val, 0); } @@ -148,10 +148,10 @@ export default class ParticleSystemRenderer { if (!this._particleSystem) { return null; } - return this._particleSystem.getMaterial(1)!; + return this._particleSystem.getMaterial(1) as Material; } - public set trailMaterial (val) { + public set trailMaterial (val: Material | null) { this._particleSystem.setMaterial(val, 1); } diff --git a/cocos/particle/renderer/trail.ts b/cocos/particle/renderer/trail.ts index fd5d4a30d7..c4f4f34596 100644 --- a/cocos/particle/renderer/trail.ts +++ b/cocos/particle/renderer/trail.ts @@ -104,7 +104,7 @@ class TrailSegment { public addElement (): ITrailElement { if (this.trailElements.length === 0) { - return null as any; + return null!; } if (this.start === -1) { this.start = 0; @@ -159,7 +159,8 @@ class TrailSegment { // public _print () { // let msg = String(); // this.iterateElement(this, (target: object, e: ITrailElement, p: Particle, dt: number) => { - // msg += 'pos:' + e.position.toString() + ' lifetime:' + e.lifetime + ' dir:' + e.direction + ' velocity:' + e.velocity.toString() + '\n'; + // msg += 'pos:' + e.position.toString() + ' lifetime:' + e.lifetime + ' dir:' + e.direction + + // ' velocity:' + e.velocity.toString() + '\n'; // return false; // }, null, 0); // console.log(msg); @@ -193,7 +194,8 @@ export default class TrailModule { this._trailModel.enabled = val; } - val ? this.onEnable() : this.onDisable(); + if (val) this.onEnable(); + else this.onDisable(); } @serializable @@ -511,7 +513,8 @@ export default class TrailModule { for (let i = trailSeg.start + 1; i < end; i++) { const segEle = trailSeg.trailElements[i % trailSeg.trailElements.length]; const j = i - trailSeg.start; - this._fillVertexBuffer(segEle, this.colorOverTrail.evaluate(1 - j / trailNum, 1), indexOffset, 1 - j * textCoordSeg, j, PRE_TRIANGLE_INDEX | NEXT_TRIANGLE_INDEX); + this._fillVertexBuffer(segEle, this.colorOverTrail.evaluate(1 - j / trailNum, 1), + indexOffset, 1 - j * textCoordSeg, j, PRE_TRIANGLE_INDEX | NEXT_TRIANGLE_INDEX); } if (this._needTransform) { Vec3.transformMat4(_temp_trailEle.position, p.position, _temp_xform); @@ -543,7 +546,8 @@ export default class TrailModule { this.vbOffset -= this._vertSize / 4 * 2; this.ibOffset -= 6; // _bcIdx = (_bcIdx - 6 + 9) % 9; // - this._fillVertexBuffer(lastSecondTrail, this.colorOverTrail.evaluate(textCoordSeg, 1), indexOffset, textCoordSeg, trailNum - 1, PRE_TRIANGLE_INDEX | NEXT_TRIANGLE_INDEX); + this._fillVertexBuffer(lastSecondTrail, this.colorOverTrail.evaluate(textCoordSeg, 1), indexOffset, + textCoordSeg, trailNum - 1, PRE_TRIANGLE_INDEX | NEXT_TRIANGLE_INDEX); Vec3.subtract(_temp_trailEle.velocity, _temp_trailEle.position, lastSecondTrail.position); Vec3.normalize(_temp_trailEle.velocity, _temp_trailEle.velocity); this._checkDirectionReverse(_temp_trailEle, lastSecondTrail); @@ -646,7 +650,8 @@ export default class TrailModule { return trailEle.lifetime > module._trailLifetime; } - private _fillVertexBuffer (trailSeg: ITrailElement, colorModifer: Color, indexOffset: number, xTexCoord: number, trailEleIdx: number, indexSet: number) { + private _fillVertexBuffer (trailSeg: ITrailElement, colorModifer: Color, indexOffset: number, + xTexCoord: number, trailEleIdx: number, indexSet: number) { this._vbF32![this.vbOffset++] = trailSeg.position.x; this._vbF32![this.vbOffset++] = trailSeg.position.y; this._vbF32![this.vbOffset++] = trailSeg.position.z; @@ -710,7 +715,8 @@ export default class TrailModule { // private _printVB() { // let log = new String(); // for (let i = 0; i < this.vbOffset; i++) { - // log += 'pos:' + this._vbF32![i++].toFixed(2) + ',' + this._vbF32![i++].toFixed(2) + ',' + this._vbF32![i++].toFixed(2) + ' dir:' + this._vbF32![i++].toFixed(0) + ' '; + // log += 'pos:' + this._vbF32![i++].toFixed(2) + ',' + this._vbF32![i++].toFixed(2) + ',' + + // this._vbF32![i++].toFixed(2) + ' dir:' + this._vbF32![i++].toFixed(0) + ' '; // i += 6; // log += 'vel:' + this._vbF32![i++].toFixed(2) + ',' + this._vbF32![i++].toFixed(2) + ',' + this._vbF32![i++].toFixed(2) + '\n'; // } diff --git a/cocos/physics/physx/shapes/physx-trimesh-shape.ts b/cocos/physics/physx/shapes/physx-trimesh-shape.ts index a22330abb2..bd944e2aae 100644 --- a/cocos/physics/physx/shapes/physx-trimesh-shape.ts +++ b/cocos/physics/physx/shapes/physx-trimesh-shape.ts @@ -28,12 +28,14 @@ * @hidden */ -import { GFXAttributeName, Quat, Vec3 } from '../../../core'; +import { Quat, Vec3 } from '../../../core'; + import { Mesh } from '../../../3d/assets'; import { MeshCollider } from '../../framework'; import { ITrimeshShape } from '../../spec/i-physics-shape'; import { createConvexMesh, createMeshGeometryFlags, createTriangleMesh, PX, _trans } from '../export-physx'; import { EPhysXShapeType, PhysXShape } from './physx-shape'; +import { AttributeName } from '../../../core/gfx'; export class PhysXTrimeshShape extends PhysXShape implements ITrimeshShape { geometry: any; @@ -54,7 +56,7 @@ export class PhysXTrimeshShape extends PhysXShape implements ITrimeshShape { if (collider.convex) { if (PX.MESH_CONVEX[v._uuid] == null) { const cooking = wrappedWorld.cooking; - const posBuf = v.readAttribute(0, GFXAttributeName.ATTR_POSITION)! as unknown as Float32Array; + const posBuf = v.readAttribute(0, AttributeName.ATTR_POSITION)! as unknown as Float32Array; PX.MESH_CONVEX[v._uuid] = createConvexMesh(posBuf, cooking, physics); } const convexMesh = PX.MESH_CONVEX[v._uuid]; @@ -62,7 +64,7 @@ export class PhysXTrimeshShape extends PhysXShape implements ITrimeshShape { } else { if (PX.MESH_STATIC[v._uuid] == null) { const cooking = wrappedWorld.cooking; - const posBuf = v.readAttribute(0, GFXAttributeName.ATTR_POSITION)! as unknown as Float32Array; + const posBuf = v.readAttribute(0, AttributeName.ATTR_POSITION)! as unknown as Float32Array; const indBuf = v.readIndices(0)! as unknown as Uint32Array; // Uint16Array ? PX.MESH_STATIC[v._uuid] = createTriangleMesh(posBuf, indBuf, cooking, physics); } diff --git a/cocos/profiler/profiler.ts b/cocos/profiler/profiler.ts index 3156bd1097..27c4041c0b 100644 --- a/cocos/profiler/profiler.ts +++ b/cocos/profiler/profiler.ts @@ -29,9 +29,8 @@ import { MeshRenderer } from '../3d/framework/mesh-renderer'; import { Camera } from '../core/components/camera-component'; import { createMesh } from '../3d/misc'; import { Material } from '../core/assets/material'; -import { ClearFlag, Format, TextureType, TextureUsageBit } from '../core/gfx/define'; -import { Texture, TextureInfo, Device, BufferTextureCopy } from '../core/gfx'; -import { toRadian, Vec4 } from '../core/math'; +import { } from '../core/gfx/define'; +import { ClearFlagBit, Format, TextureType, TextureUsageBit, Texture, TextureInfo, Device, BufferTextureCopy } from '../core/gfx'; import { Layers } from '../core/scene-graph'; import { Node } from '../core/scene-graph/node'; import { ICounterOption } from './counter'; @@ -261,7 +260,7 @@ export class Profiler { camera.near = 1; camera.far = 2; camera.visibility = Layers.BitMask.PROFILER; - camera.clearFlags = ClearFlag.NONE; + camera.clearFlags = ClearFlagBit.NONE; camera.priority = 0xffffffff; // after everything else const managerNode = new Node('Profiler_Root'); @@ -379,7 +378,8 @@ export class Profiler { } if (!EDITOR) { - const { screenSpaceSignY, surfaceTransform } = this._device!; + const surfaceTransform = this._device!.surfaceTransform; + const screenSpaceSignY = this._device!.capabilities.screenSpaceSignY; if (surfaceTransform !== this.offsetData[3]) { const preTransform = preTransforms[surfaceTransform]; const x = -0.9; const y = -0.9 * screenSpaceSignY; diff --git a/cocos/video/video-player-impl-web.ts b/cocos/video/video-player-impl-web.ts index edfa3357ee..1fdfa1c09d 100644 --- a/cocos/video/video-player-impl-web.ts +++ b/cocos/video/video-player-impl-web.ts @@ -24,12 +24,12 @@ */ import { mat4 } from '../core/math'; -import { error, sys, view, screen, warn } from '../core/platform'; +import { sys, view, screen, warn } from '../core/platform'; import { game } from '../core'; import { contains } from '../core/utils/misc'; import { EventType, READY_STATE } from './video-player-enums'; import { VideoPlayerImpl } from './video-player-impl'; -import { ClearFlag } from '../core/gfx'; +import { ClearFlagBit } from '../core/gfx'; import visibleRect from '../core/platform/visible-rect'; const MIN_ZINDEX = -(2 ** 15); @@ -344,7 +344,7 @@ export class VideoPlayerImplWeb extends VideoPlayerImpl { this._clearColorA = camera.clearColor.w; this._clearFlag = camera.clearFlag; camera.clearColor.w = 0; - camera.clearFlag = ClearFlag.ALL; + camera.clearFlag = ClearFlagBit.ALL; } else if (this._clearFlag) { camera.clearColor.w = this._clearColorA; camera.clearFlag = this._clearFlag; diff --git a/package.json b/package.json index 44cbe50127..f1f350dd5c 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "scripts": { "server": "http-server . -p 8002 -o http://127.0.0.1:8002/playground/index.html", "build": "gulp build", - "build:dev": "gulp build-code", - "build:min": "gulp build-code-minified", + "build:dev": "gulp build-h5-source", + "build:min": "gulp build-h5-minified", "build-declaration": "gulp build-declarations", "build-api-json": "gulp build-api-json -i index.ts -o ./3d-api-docs/tempJson", "build-api": "npm run build-api-json && gulp build-3d-api -i index.ts -o ./3d-api-docs -j ./3d-api-docs/tempJson",