Skip to content

Commit

Permalink
Merge pull request cocos#13251 from holycanvas/develop
Browse files Browse the repository at this point in the history
Sync v3.6.2 to Develop
  • Loading branch information
SantyWang authored Nov 7, 2022
2 parents 7f7d85c + ddf449b commit 7c886c0
Show file tree
Hide file tree
Showing 32 changed files with 498 additions and 3,806 deletions.
3 changes: 1 addition & 2 deletions cocos/2d/assembler/graphics/webgl/earcut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class Aim {
public next: Aim | null = null;

// z-order curve value
// public z = null;
public z = 0;
public z: number = null as any;

// previous and next nodes in z-order
public prevZ: Aim | null = null;
Expand Down
49 changes: 33 additions & 16 deletions cocos/gfx/webgpu/webgpu-define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
Texture, CommandBuffer, DescriptorSet, Device, InputAssembler, Buffer, Shader
} from './override';
import {
DeviceInfo, BufferTextureCopy, ShaderInfo, ShaderStageFlagBit, TextureViewInfo, TextureInfo, DrawInfo, BufferViewInfo, BufferInfo,
DeviceInfo, BufferTextureCopy, ShaderInfo, ShaderStageFlagBit, TextureViewInfo, TextureInfo, DrawInfo, BufferViewInfo, BufferInfo, BufferUsageBit, IndirectBuffer,
} from '../base/define';

WEBGPU && promiseForWebGPUInstantiation.then(() => {
Expand Down Expand Up @@ -85,22 +85,30 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {

const oldUpdateBuffer = Buffer.prototype.update;
Buffer.prototype.update = function (data: BufferSource, size?: number) {
const updateSize = size === undefined ? data.byteLength : size;
if ('buffer' in data) {
oldUpdateBuffer.call(this, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
if (this.usage & BufferUsageBit.INDIRECT) {
this.updateIndirect(((data as unknown) as IndirectBuffer).drawInfos);
} else {
oldUpdateBuffer.call(this, new Uint8Array(data), updateSize);
const updateSize = size === undefined ? data.byteLength : size;
if ('buffer' in data) {
oldUpdateBuffer.call(this, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
} else {
oldUpdateBuffer.call(this, new Uint8Array(data), updateSize);
}
}

};

const oldCmdUpdateBuffer = CommandBuffer.prototype.updateBuffer;
CommandBuffer.prototype.updateBuffer = function (buffer: typeof Buffer, data: BufferSource, size?: number) {
const updateSize = size === undefined ? data.byteLength : size;

if ('buffer' in data) {
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
if (this.usage & BufferUsageBit.INDIRECT) {
this.updateIndirect(buffer, ((data as unknown) as IndirectBuffer).drawInfos);
} else {
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data), updateSize);
const updateSize = size === undefined ? data.byteLength : size;
if ('buffer' in data) {
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data.buffer, data.byteOffset, data.byteLength), updateSize);
} else {
oldCmdUpdateBuffer.call(this, buffer, new Uint8Array(data), updateSize);
}
}
};

Expand Down Expand Up @@ -196,25 +204,34 @@ WEBGPU && promiseForWebGPUInstantiation.then(() => {
const referredFuncMap = new Map<string, [fnName: string, samplerType: string, samplerName: string]>();
const samplerSet = new Set<string>();
samplerTexturArr?.every((str) => {
let textureName = str.match(/(?<=uniform(.*?)sampler\w* )(\w+)(?=;)/g)!.toString();
// `(?<=)` not compatible with str.match on safari.
// let textureName = str.match(/(?<=uniform(.*?)sampler\w* )(\w+)(?=;)/g)!.toString();
const textureNameRegExpStr = '(?<=uniform(.*?)sampler\\w* )(\\w+)(?=;)';
let textureName = (new RegExp(textureNameRegExpStr, 'g')).exec(str)![0];

let samplerStr = str.replace(textureName, `${textureName}Sampler`);
let samplerFunc = samplerStr.match(/(?<=uniform(.*?))sampler(\w*)/g)!.toString();

// let samplerFunc = samplerStr.match(/(?<=uniform(.*?))sampler(\w*)/g)!.toString();
const samplerRegExpStr = '(?<=uniform(.*?))sampler(\\w*)';
let samplerFunc = (new RegExp(samplerRegExpStr, 'g')).exec(str)![0];
samplerFunc = samplerFunc.replace('sampler', '');
if (samplerFunc === '') {
textureName = textureName.replace('Sampler', '');
} else {
samplerStr = samplerStr.replace(/(?<=uniform(.*?))(sampler\w*)/g, 'sampler');
const samplerReplaceReg = new RegExp('(?<=uniform(.*?))(sampler\\w*)', 'g');
samplerStr = samplerStr.replace(samplerReplaceReg, 'sampler');

// layout (set = a, binding = b) uniform sampler2D cctex;
// to:
// layout (set = a, binding = b) uniform sampler cctexSampler;
// layout (set = a, binding = b + maxTextureNum) uniform texture2D cctex;
const samplerReg = /(?<=binding = )(\d+)(?=\))/g;
const samplerBindingStr = str.match(samplerReg)!.toString();
const samplerReg = new RegExp('(?<=binding = )(\\d+)(?=\\))', 'g');
const samplerBindingStr = samplerReg.exec(str)![0];
const samplerBinding = Number(samplerBindingStr) + 16;
samplerStr = samplerStr.replace(samplerReg, samplerBinding.toString());

const textureStr = str.replace(/(?<=uniform(.*?))(sampler)(?=\w*)/g, 'texture');
const textureReg = new RegExp('(?<=uniform(.*?))(sampler)(?=\\w*)', 'g');
const textureStr = str.replace(textureReg, 'texture');
code = code.replace(str, `${textureStr}\n${samplerStr}`);
}

Expand Down
2 changes: 1 addition & 1 deletion cocos/render-scene/scene/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ export class Model {

this.onMacroPatchesStateChanged();

if (texture === null) {
if (!texture) {
texture = builtinResMgr.get<Texture2D>('empty-texture');
}

Expand Down
8 changes: 7 additions & 1 deletion cocos/render-scene/scene/submodel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,14 @@ export class SubModel {

// update draw info
const drawInfo = this._subMesh.drawInfo;

// to invoke getter/setter function for wasm object
if (this._inputAssembler && drawInfo) {
Object.assign(this._inputAssembler.drawInfo, drawInfo);
const dirtyDrawInfo = this._inputAssembler.drawInfo;
Object.keys(drawInfo).forEach((key) => {
dirtyDrawInfo[key] = drawInfo[key];
});
this._inputAssembler.drawInfo = dirtyDrawInfo;
}
}

Expand Down
5 changes: 3 additions & 2 deletions cocos/rendering/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { SubModel } from '../render-scene/scene/submodel';
import { Layers } from '../scene-graph/layers';
import { cclegacy } from '../core';
import { BindingMappingInfo, DescriptorType, Type, ShaderStageFlagBit, UniformStorageBuffer, DescriptorSetLayoutBinding,
Uniform, UniformBlock, UniformSamplerTexture, UniformStorageImage, Device, FormatFeatureBit, Format,
Uniform, UniformBlock, UniformSamplerTexture, UniformStorageImage, Device, FormatFeatureBit, Format, API,
} from '../gfx';

export const PIPELINE_FLOW_MAIN = 'MainFlow';
Expand Down Expand Up @@ -750,7 +750,8 @@ export function supportsR16HalfFloatTexture (device: Device) {
*/
export function supportsR32FloatTexture (device: Device) {
return (device.getFormatFeatures(Format.R32F) & (FormatFeatureBit.RENDER_TARGET | FormatFeatureBit.SAMPLED_TEXTURE))
=== (FormatFeatureBit.RENDER_TARGET | FormatFeatureBit.SAMPLED_TEXTURE);
=== (FormatFeatureBit.RENDER_TARGET | FormatFeatureBit.SAMPLED_TEXTURE)
&& !(device.gfxAPI === API.WEBGL); // wegl 1 Single-channel float type is not supported under webgl1, so it is excluded
}

/* eslint-enable max-len */
2 changes: 1 addition & 1 deletion cocos/rendering/render-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ export abstract class RenderPipeline extends Asset implements IPipelineEvent, Pi

if (!(clearFlags & ClearFlagBit.COLOR)) {
if (clearFlags & SKYBOX_FLAG) {
colorAttachment.loadOp = LoadOp.DISCARD;
colorAttachment.loadOp = LoadOp.CLEAR;
} else {
colorAttachment.loadOp = LoadOp.LOAD;
colorAttachment.barrier = device.getGeneralBarrier(new GeneralBarrierInfo(
Expand Down
6 changes: 4 additions & 2 deletions cocos/rendering/scene-culling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
import { EDITOR } from 'internal:constants';
import { Model } from '../render-scene/scene/model';
import { Camera, SKYBOX_FLAG } from '../render-scene/scene/camera';
import { Vec3, Pool, warnID, geometry } from '../core';
Expand All @@ -30,6 +31,7 @@ import { IRenderObject, UBOShadow } from './define';
import { ShadowType, CSMOptimizationMode } from '../render-scene/scene/shadows';
import { PipelineSceneData } from './pipeline-scene-data';
import { ShadowLayerVolume } from './shadow/csm-layers';
import { cclegacy } from '../core';
import { ReflectionProbeManager } from './reflection-probe-manager';
import { LODModelsCachedUtils } from './lod-models-utils';

Expand Down Expand Up @@ -147,8 +149,8 @@ export function sceneCulling (pipeline: RenderPipeline, camera: Camera) {
if ((camera.clearFlag & SKYBOX_FLAG)) {
if (skybox.enabled && skybox.model) {
renderObjects.push(getRenderObject(skybox.model, camera));
} else {
warnID(15100, camera.name);
} else if (camera.clearFlag === SKYBOX_FLAG && !EDITOR) {
cclegacy.warnID(15100, camera.name);
}
}

Expand Down
9 changes: 7 additions & 2 deletions cocos/rendering/shadow/shadow-stage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export class ShadowStage extends RenderStage {
const descriptorSet = this._globalDS!;
const cmdBuff = pipeline.commandBuffers[0];
const level = this._level;
const device = pipeline.device;

if (!this._light || !this._shadowFrameBuffer) { return; }
this._pipeline.pipelineUBO.updateShadowUBOLight(descriptorSet, this._light, level);
Expand All @@ -125,8 +126,13 @@ export class ShadowStage extends RenderStage {
this._renderArea.width = shadowMapSize.x;
this._renderArea.height = shadowMapSize.y;
} else {
const screenSpaceSignY = device.capabilities.screenSpaceSignY;
this._renderArea.x = level % 2 * 0.5 * shadowMapSize.x;
this._renderArea.y = (1 - Math.floor(level / 2)) * 0.5 * shadowMapSize.y;
if (screenSpaceSignY > 0.0) {
this._renderArea.y = (1 - Math.floor(level / 2)) * 0.5 * shadowMapSize.y;
} else {
this._renderArea.y = Math.floor(level / 2) * 0.5 * shadowMapSize.y;
}
this._renderArea.width = 0.5 * shadowMapSize.x;
this._renderArea.height = 0.5 * shadowMapSize.y;
}
Expand All @@ -142,7 +148,6 @@ export class ShadowStage extends RenderStage {
default:
}

const device = pipeline.device;
const renderPass = this._shadowFrameBuffer.renderPass;

cmdBuff.beginRenderPass(renderPass, this._shadowFrameBuffer, this._renderArea,
Expand Down
1 change: 1 addition & 0 deletions cocos/spine/assembler/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ function cacheTraverse (worldMat: Mat4 | null) {
let prevDrawIndexOffset = 0;
const rd = _renderData!;
const vbuf = rd.chunk.vb;
_vUintBuf = new Uint32Array(vbuf.buffer, vbuf.byteOffset, vbuf.length);
const ibuf = rd.indices!;
for (let i = 0, n = segments.length; i < n; i++) {
const segInfo = segments[i];
Expand Down
Loading

0 comments on commit 7c886c0

Please sign in to comment.