device layer adapt

This commit is contained in:
Yun Hsiao Wu
2021-01-30 16:53:06 +08:00
parent d9ca07d597
commit 4fd693adf2
93 changed files with 1601 additions and 1963 deletions
+8 -2
View File
@@ -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
+1 -1
View File
@@ -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';
+3 -1
View File
@@ -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
@@ -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<TextureBase>(texName);
if (!dftTex) {
warn(`Illegal texture default value: ${texName}.`);
+3 -3
View File
@@ -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 {
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -223,7 +223,7 @@ export class TextureCube extends SimpleTexture {
this.mipmaps = [];
}
public _serialize (ctxForExporting: any): any {
public _serialize (ctxForExporting: any): Record<string, unknown> | 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;
}
}
+6 -6
View File
@@ -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 {
+1 -1
View File
@@ -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';
+4 -48
View File
@@ -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 缓冲。
+3 -11
View File
@@ -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 命令缓冲。
-117
View File
@@ -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(),
) {}
}
+1042 -349
View File
File diff suppressed because it is too large Load Diff
+11 -171
View File
@@ -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}`;
}
+1 -24
View File
@@ -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.
+1 -14
View File
@@ -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.
+25 -199
View File
@@ -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<string, string> {
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<string, string>();
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 拷贝缓冲到纹理。
-56
View File
@@ -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;
}
+1 -13
View File
@@ -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.
+43 -48
View File
@@ -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<string, unknown> = 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;
+1 -3
View File
@@ -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';
+1 -34
View File
@@ -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.
+1 -9
View File
@@ -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.
+2 -3
View File
@@ -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;
+11 -21
View File
@@ -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,
) {}
}
+21 -62
View File
@@ -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<string, unknown> = {
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;
+2 -11
View File
@@ -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;
}
+9 -69
View File
@@ -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) {
+1 -21
View File
@@ -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.
+1 -80
View File
@@ -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.
+3 -36
View File
@@ -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;
+3 -2
View File
@@ -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,
@@ -39,11 +39,11 @@ export class WebGLCommandPool<T extends WebGLCmdObject> {
private _freeIdx = 0;
private _freeCmds: CachedArray<T>;
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<T extends WebGLCmdObject> {
}
*/
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<T extends WebGLCmdObject> {
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) {
+4 -5
View File
@@ -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';
+31 -35
View File
@@ -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<IWebGLGPUUniformSampler>(gpuShader.samplers.length);
if (gpuShader.samplerTextures.length > 0) {
gpuShader.glSamplerTextures = new Array<IWebGLGPUUniformSamplerTexture>(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;
+1 -1
View File
@@ -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,
@@ -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 {
+2 -1
View File
@@ -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 {
+36 -45
View File
@@ -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)) {
-39
View File
@@ -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 () {}
}
+3 -2
View File
@@ -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) {
+7 -19
View File
@@ -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 {
@@ -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';
@@ -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!; }
@@ -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';
+3 -3
View File
@@ -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++) {
+4 -3
View File
@@ -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 = {
+2 -2
View File
@@ -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[] = [
+4 -3
View File
@@ -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<IWebGLGPUShaderStage>(info.stages.length),
glProgram: null,
glInputs: [],
glUniforms: [],
glBlocks: [],
glSamplers: [],
glSamplerTextures: [],
};
for (let i = 0; i < info.stages.length; ++i) {
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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';
+2 -2
View File
@@ -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,
@@ -39,11 +39,11 @@ export class WebGL2CommandPool<T extends WebGL2CmdObject> {
private _freeIdx = 0;
private _freeCmds: CachedArray<T>;
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<T extends WebGL2CmdObject> {
}
*/
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<T extends WebGL2CmdObject> {
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) {
@@ -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';
+33 -54
View File
@@ -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<IWebGL2GPUUniformSampler>(gpuShader.samplers.length);
if (gpuShader.samplerTextures.length > 0) {
gpuShader.glSamplerTextures = new Array<IWebGL2GPUUniformSamplerTexture>(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;
@@ -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 {
@@ -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 {
+47 -56
View File
@@ -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)) {
-59
View File
@@ -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);
}
}
+3 -2
View File
@@ -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) {
+6 -21
View File
@@ -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 {
@@ -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';
@@ -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!; }
@@ -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';
+3 -7
View File
@@ -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 () {
+4 -3
View File
@@ -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 = {
+2 -1
View File
@@ -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';
+4 -3
View File
@@ -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<IWebGL2GPUShaderStage>(info.stages.length),
glProgram: null,
glInputs: [],
glUniforms: [],
glBlocks: [],
glSamplers: [],
glSamplerTextures: [],
};
for (let i = 0; i < info.stages.length; ++i) {
+1 -1
View File
@@ -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 {
+2 -2
View File
@@ -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';
+15 -13
View File
@@ -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<string, UniformBlock | UniformSampler>;
layouts: Record<string, UniformBlock | UniformSamplerTexture>;
}
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 */
+10 -11
View File
@@ -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<ClearFlag, RenderPass>();
protected _renderPasses = new Map<ClearFlags, RenderPass>();
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);
+2 -2
View File
@@ -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;
+10 -10
View File
@@ -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')
+5 -5
View File
@@ -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
@@ -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(
+1 -5
View File
@@ -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);
+7 -5
View File
@@ -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<typeof BatchView2D> = {
[BatchView2D.COUNT]: BufferDataType.NEVER,
};
export const BatchPool2D = new BufferPool<PoolType.BATCH_2D, typeof BatchView2D, IBatchView2DType>(PoolType.BATCH_2D, batchView2DDataType, BatchView2D);
export const BatchPool2D = new BufferPool<PoolType.BATCH_2D, typeof BatchView2D, IBatchView2DType>(
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<typeof CameraView> {
[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<typeof CameraView> = {
[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,
+2 -2
View File
@@ -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);
+2 -2
View File
@@ -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);
+4 -7
View File
@@ -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++) {
+25 -22
View File
@@ -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);
}
}
+1 -4
View File
@@ -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;
}
/**
+21 -19
View File
@@ -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);
+1 -4
View File
@@ -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);
+2 -2
View File
@@ -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;
@@ -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);
}
+13 -7
View File
@@ -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; // <wireframe debug>
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';
// }
@@ -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);
}
+5 -5
View File
@@ -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;
+3 -3
View File
@@ -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;
+2 -2
View File
@@ -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",