Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance #16650

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 29 additions & 8 deletions cocos/rendering/post-process/utils/pass-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export class PassContext {
forwardPass: any = undefined;
postProcess: PostProcess | undefined;

maxSpotLights = 0xFFFFFFFF;
maxSphereLights = 0xFFFFFFFF;
maxPointLights = 0xFFFFFFFF;
maxRangedDirLights = 0xFFFFFFFF;

setClearFlag (clearFlag: ClearFlagBit): PassContext {
this.clearFlag = clearFlag;
return this;
Expand Down Expand Up @@ -85,9 +90,25 @@ export class PassContext {
}

addSceneLights (queue: RenderQueueBuilder, camera: Camera, flags: SceneFlags = SceneFlags.BLEND): void {
if (this.maxPointLights === 0
&& this.maxSphereLights === 0
&& this.maxSpotLights === 0
&& this.maxRangedDirLights === 0) {
return;
}
const scene = camera.scene!;
for (let i = 0; i < scene.spotLights.length; i++) {
const light = scene.spotLights[i];
const spotLights = scene.spotLights;
const sphereLights = scene.sphereLights;
const pointLights = scene.pointLights;
const rangedDirLights = scene.rangedDirLights;

const numSpotLights = Math.min(spotLights.length, this.maxSpotLights);
const numSphereLights = Math.min(sphereLights.length, this.maxSphereLights);
const numPointLights = Math.min(pointLights.length, this.maxPointLights);
const numRangedDirLights = Math.min(rangedDirLights.length, this.maxRangedDirLights);

for (let i = 0; i < numSpotLights; i++) {
const light = spotLights[i];
if (light.baked) {
continue;
}
Expand All @@ -97,8 +118,8 @@ export class PassContext {
}
}
// sphere lights
for (let i = 0; i < scene.sphereLights.length; i++) {
const light = scene.sphereLights[i];
for (let i = 0; i < numSphereLights; i++) {
const light = sphereLights[i];
if (light.baked) {
continue;
}
Expand All @@ -108,8 +129,8 @@ export class PassContext {
}
}
// point lights
for (let i = 0; i < scene.pointLights.length; i++) {
const light = scene.pointLights[i];
for (let i = 0; i < numPointLights; i++) {
const light = pointLights[i];
if (light.baked) {
continue;
}
Expand All @@ -119,8 +140,8 @@ export class PassContext {
}
}
// ranged dir lights
for (let i = 0; i < scene.rangedDirLights.length; i++) {
const light = scene.rangedDirLights[i];
for (let i = 0; i < numRangedDirLights; i++) {
const light = rangedDirLights[i];
geometry.AABB.transform(boundingBox, rangedDirLightBoundingBox, light.node!.getWorldMatrix());
if (geometry.intersect.aabbFrustum(boundingBox, camera.frustum)) {
queue.addSceneOfCamera(camera, new LightInfo(light), flags);
Expand Down
8 changes: 4 additions & 4 deletions native/cocos/renderer/pipeline/custom/RenderGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -965,10 +965,10 @@ struct RenderData {
RenderData& operator=(RenderData&& rhs) = default;
RenderData& operator=(RenderData const& rhs) = delete;

PmrUnorderedMap<uint32_t, ccstd::pmr::vector<char>> constants;
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Buffer>> buffers;
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Texture>> textures;
PmrUnorderedMap<uint32_t, gfx::Sampler*> samplers;
PmrFlatMap<uint32_t, ccstd::pmr::vector<char>> constants;
PmrFlatMap<uint32_t, IntrusivePtr<gfx::Buffer>> buffers;
PmrFlatMap<uint32_t, IntrusivePtr<gfx::Texture>> textures;
PmrFlatMap<uint32_t, gfx::Sampler*> samplers;
ccstd::pmr::string custom;
};

Expand Down
Loading