Skip to content

Commit

Permalink
Merge branch 'v3.8.4' into v3.8.4-performance
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Sep 12, 2024
2 parents cd640ec + 6434f14 commit 0cd7eb7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 61 deletions.
76 changes: 37 additions & 39 deletions cocos/rendering/custom/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,53 +34,51 @@ import {
RenderGraphValue,
} from './render-graph';
import { AccessType, ResourceResidency, SceneFlags } from './types';
import { hashCombineNum, hashCombineStr } from './define';
import { hashCombineKey, hashCombineStr } from './define';

function genHashValue (pass: RasterPass): void {
let hashCode = 0;
let hashCode = '';
for (const [name, raster] of pass.rasterViews) {
hashCode = hashCombineStr('raster', hashCode);
hashCode = hashCombineStr(name, hashCode);
hashCode = hashCombineStr(raster.slotName, hashCode);
hashCode = hashCombineNum(raster.accessType, hashCode);
hashCode = hashCombineNum(raster.attachmentType, hashCode);
hashCode = hashCombineNum(raster.loadOp, hashCode);
hashCode = hashCombineNum(raster.storeOp, hashCode);
hashCode = hashCombineNum(raster.clearFlags, hashCode);
hashCode = hashCombineNum(raster.clearColor.x, hashCode);
hashCode = hashCombineNum(raster.clearColor.y, hashCode);
hashCode = hashCombineNum(raster.clearColor.z, hashCode);
hashCode = hashCombineNum(raster.clearColor.w, hashCode);
hashCode = hashCombineNum(raster.slotID, hashCode);
hashCode = hashCombineNum(raster.shaderStageFlags, hashCode);
hashCode += hashCombineKey(name);
hashCode += hashCombineKey(raster.slotName);
hashCode += hashCombineKey(raster.accessType);
hashCode += hashCombineKey(raster.attachmentType);
hashCode += hashCombineKey(raster.loadOp);
hashCode += hashCombineKey(raster.storeOp);
hashCode += hashCombineKey(raster.clearFlags);
hashCode += hashCombineKey(raster.clearColor.x);
hashCode += hashCombineKey(raster.clearColor.y);
hashCode += hashCombineKey(raster.clearColor.z);
hashCode += hashCombineKey(raster.clearColor.w);
hashCode += hashCombineKey(raster.slotID);
hashCode += hashCombineKey(raster.shaderStageFlags);
}
for (const [name, computes] of pass.computeViews) {
hashCode = hashCombineStr(name, hashCode);
hashCode += hashCombineKey(name);
for (const compute of computes) {
hashCode = hashCombineStr('compute', hashCode);
hashCode = hashCombineStr(compute.name, hashCode);
hashCode = hashCombineNum(compute.accessType, hashCode);
hashCode = hashCombineNum(compute.clearFlags, hashCode);
hashCode = hashCombineNum(compute.clearValueType, hashCode);
hashCode = hashCombineNum(compute.clearValue.x, hashCode);
hashCode = hashCombineNum(compute.clearValue.y, hashCode);
hashCode = hashCombineNum(compute.clearValue.z, hashCode);
hashCode = hashCombineNum(compute.clearValue.w, hashCode);
hashCode = hashCombineNum(compute.shaderStageFlags, hashCode);
hashCode += hashCombineKey(compute.name);
hashCode += hashCombineKey(compute.accessType);
hashCode += hashCombineKey(compute.clearFlags);
hashCode += hashCombineKey(compute.clearValueType);
hashCode += hashCombineKey(compute.clearValue.x);
hashCode += hashCombineKey(compute.clearValue.y);
hashCode += hashCombineKey(compute.clearValue.z);
hashCode += hashCombineKey(compute.clearValue.w);
hashCode += hashCombineKey(compute.shaderStageFlags);
}
}
hashCode = hashCombineNum(pass.width, hashCode);
hashCode = hashCombineNum(pass.height, hashCode);
hashCode = hashCombineNum(pass.viewport.left, hashCode);
hashCode = hashCombineNum(pass.viewport.top, hashCode);
hashCode = hashCombineNum(pass.viewport.width, hashCode);
hashCode = hashCombineNum(pass.viewport.height, hashCode);
hashCode = hashCombineNum(pass.viewport.minDepth, hashCode);
hashCode = hashCombineNum(pass.viewport.maxDepth, hashCode);
hashCode = hashCombineNum(pass.showStatistics ? 1 : 0, hashCode);
pass.hashValue = hashCode;
hashCode += hashCombineKey(pass.width);
hashCode += hashCombineKey(pass.height);
hashCode += hashCombineKey(pass.viewport.left);
hashCode += hashCombineKey(pass.viewport.top);
hashCode += hashCombineKey(pass.viewport.width);
hashCode += hashCombineKey(pass.viewport.height);
hashCode += hashCombineKey(pass.viewport.minDepth);
hashCode += hashCombineKey(pass.viewport.maxDepth);
hashCode += hashCombineKey(pass.showStatistics ? 1 : 0);
pass.hashValue = hashCombineStr(hashCode);
}

const readViews: Map<string, RasterView> = new Map();
class PassVisitor implements RenderGraphVisitor {
public queueID = 0xFFFFFFFF;
public sceneID = 0xFFFFFFFF;
Expand Down Expand Up @@ -182,7 +180,7 @@ class PassVisitor implements RenderGraphVisitor {
}
const outputId = this.resID;
const outputName = this.context.resourceGraph.vertexName(outputId);
const readViews: Map<string, RasterView> = new Map();
readViews.clear();
const pass = this._currPass! as RasterPass;
const validPass = rg.getValid(this.passID);
for (const [readName, raster] of pass.rasterViews) {
Expand Down
18 changes: 7 additions & 11 deletions cocos/rendering/custom/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -685,22 +685,18 @@ export function updatePerPassUBO (layout: string, sceneId: number, idxRD: number
descriptorSet.update();
}

function hashCombine (hash, currHash: number): number {
return currHash ^= (hash >>> 0) + 0x9e3779b9 + (currHash << 6) + (currHash >> 2);
export function hashCombineKey (val): string {
return `${val}-`;
}

export function hashCombineNum (val: number, currHash: number): number {
const hash = 5381;
return hashCombine((hash * 33) ^ val, currHash);
}

export function hashCombineStr (str: string, currHash: number): number {
export function hashCombineStr (str: string): number {
// DJB2 HASH
let hash = 5381;
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash * 33) ^ str.charCodeAt(i);
hash = ((hash << 5) - hash) + str.charCodeAt(i);
hash |= 0;// Convert to 32bit integer
}
return hashCombine(hash, currHash);
return hash;
}

export function bool (val): boolean {
Expand Down
7 changes: 4 additions & 3 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ class DeviceRenderPass implements RecordingInterface {
}
if (!swapchain) swapchain = resTex.swapchain;
if (!framebuffer) framebuffer = resTex.framebuffer;
const clearFlag = rasterV.clearFlags & 0xffffffff;
switch (rasterV.attachmentType) {
case AttachmentType.RENDER_TARGET:
{
Expand All @@ -809,7 +808,9 @@ class DeviceRenderPass implements RecordingInterface {
rasterV.loadOp === LoadOp.LOAD ? AccessFlagBit.COLOR_ATTACHMENT_WRITE : AccessFlagBit.NONE,
rasterV.storeOp === StoreOp.STORE ? AccessFlagBit.COLOR_ATTACHMENT_WRITE : AccessFlagBit.NONE,
));
this._clearColor.push(rasterV.clearColor);
const currCol = new Color();
currCol.copy(rasterV.clearColor);
this._clearColor.push(currCol);
colors.push(colorAttachment);
}
break;
Expand Down Expand Up @@ -1033,7 +1034,7 @@ class DeviceRenderPass implements RecordingInterface {
if (currFBDepthTex && !isInsideTexDestroy) {
isInsideTexDestroy = currFBDepthTex.getTextureHandle() === 0;
}
const needRebuild = (width !== currentWidth) || (height !== currentHeight) || currFramebuffer.needRebuild || isInsideTexDestroy;
const needRebuild = width !== currentWidth || height !== currentHeight || currFramebuffer.needRebuild || isInsideTexDestroy;
for (const [resName, rasterV] of pass.rasterViews) {
let deviceTex = context.deviceTextures.get(resName)!;
const currTex = deviceTex;
Expand Down
16 changes: 8 additions & 8 deletions cocos/rendering/custom/scene-culling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CSMLevel, Camera, DirectionalLight, Light, LightType, Model, PointLight
ReflectionProbe, SKYBOX_FLAG, ShadowType, Shadows, SphereLight, SpotLight } from '../../render-scene/scene';
import { Layers, Node } from '../../scene-graph';
import { PipelineSceneData } from '../pipeline-scene-data';
import { bool, AlignUp, SetLightUBO } from './define';
import { bool, AlignUp, SetLightUBO, hashCombineKey } from './define';
import { LayoutGraphData } from './layout-graph';
import { CullingFlags, RenderGraph, RenderGraphValue, SceneData, RenderQueue as RenderQueue0 } from './render-graph';
import { SceneFlags } from './types';
Expand Down Expand Up @@ -48,13 +48,13 @@ function computeCullingKey (
const lightLevel = sceneData.light.level;
const reflectProbe = sceneData.light.probe!;
const shadeLight = sceneData.shadingLight;
cullingKeys += `${camera ? objectID(camera) : 0}-`;
cullingKeys += `${reflectProbe ? objectID(reflectProbe) : 0}-`;
cullingKeys += `${(refId === -1 && light) ? objectID(light) : 0}-`;
cullingKeys += `${(refId !== -1 && shadeLight) ? objectID(shadeLight) : 0}-`;
cullingKeys += `${refId === -1 ? lightLevel : 0}-`;
cullingKeys += `${castShadows ? 1 : 0}-`;
cullingKeys += `${refId}`;
cullingKeys += hashCombineKey(camera ? objectID(camera) : 0);
cullingKeys += hashCombineKey(reflectProbe ? objectID(reflectProbe) : 0);
cullingKeys += hashCombineKey((refId === -1 && light) ? objectID(light) : 0);
cullingKeys += hashCombineKey((refId !== -1 && shadeLight) ? objectID(shadeLight) : 0);
cullingKeys += hashCombineKey(refId === -1 ? lightLevel : 0);
cullingKeys += hashCombineKey(castShadows ? 1 : 0);
cullingKeys += hashCombineKey(refId);
return cullingKeys;
}

Expand Down

0 comments on commit 0cd7eb7

Please sign in to comment.