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

Refactor 2d render pipeline #1708

Open
wants to merge 90 commits into
base: dev/1.3
Choose a base branch
from

Conversation

singlecoder
Copy link
Member

@singlecoder singlecoder commented Aug 22, 2023

for (let i = 0; i < charCount; ++i) {
const charRenderData = charRenderDatas[i];
const spriteRenderData = spriteRenderDataPool.getFromPool();
spriteRenderData.set(this, material, charRenderData.renderData, charRenderData.texture, i);
charsData[i] = spriteRenderData;
spriteRenderData.set(this, material, charRenderData.renderData, charRenderData.texture);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charRenderData.usage = RenderDataUsage.Sprite;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -70,6 +71,9 @@ export class Camera extends Component {
_renderPipeline: BasicRenderPipeline;
/** @internal */
@ignoreClone
_batcherManager: BatcherManager;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not in BasicRenderPipeline.

}

commitRenderData(context: RenderContext, data: RenderData | Array<RenderData>): void {
if (!data) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be deleted.

/** @internal */
_meshCount: number = 1;
/** @internal */
_subMeshPool: ClassPool<SubMesh> = new ClassPool(SubMesh);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a static variable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be a static variable.

has deleted


commitRenderData(context: RenderContext, data: SpriteRenderData): void {
if (this._preSpriteRenderData) {
if (this._vertexCount + data.verticesData.vertexCount > Batcher2D.MAX_VERTEX_COUNT) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to judge index

@cptbtptpbcptdtptp
Copy link
Collaborator

cptbtptpbcptdtptp commented Aug 28, 2023

There is a doubt that the current BatchManager is subordinate to the Camera. When the number of cameras increases, the memory occupied by Batch2D will also increase multiple times.
image
The same is true for SpriteMaskBatcher

this._cascadedShadowCaster = new CascadedShadowCasterPass(camera);
this._depthOnlyPass = new DepthOnlyPass(engine);
this._spriteMaskManager = new SpriteMaskManager(camera.engine);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to put SpriteMaskManager in Scene? Because :

  1. Mask does not depend on rendering timing.
  2. More memory efficient.

@singlecoder singlecoder changed the base branch from dev/1.1 to main September 13, 2023 09:46
/** @internal */
_componentInstanceId: number;
/** @internal */
_distanceForSort: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a internal class, why use internal property?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change


/**
* Render queue.
*/
export class RenderQueue {
private static _textureProperty: ShaderProperty = ShaderProperty.getByName("renderer_SpriteTexture");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you define a render property in Renderqueue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for text that with multi-texture, i do not have any good idea now

} else {
return distanceDiff;
}
return dataA._distanceForSort - dataB._distanceForSort || instanceIdDiff;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not OK?

 return (
      dataA._priority - dataB._priority ||
      dataA._distanceForSort - dataB._distanceForSort ||
      dataA._componentInstanceId - dataB._componentInstanceId ||
      dataA._materialPriority - dataB._materialPriority
    );

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, in some case, the same renderer wo want control the sort just for material priority, link lottie or spine

// TextRenderer may be has multi-texture.
const isText = usage === RenderDataUsage.Text;
// @ts-ignore
isText && rendererData.setTexture(RenderQueue._textureProperty, data.texture);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No!!!!! This configuration should be done at the upper level

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't has a good idea how to handle a text renderer with multi-texture right now

const { usage } = data;
const needMask = usage === RenderDataUsage.Sprite || usage === RenderDataUsage.Text;
const renderer = data.component;
needMask && spriteMaskManager.preRender(camera, <SpriteRenderer>renderer);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Type is not write

compileMacros
);
const { usage } = data;
const needMask = usage === RenderDataUsage.Sprite || usage === RenderDataUsage.Text;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SpriteMask is still very specialized!

import { SpriteMaskBatcher } from "./SpriteMaskBatcher";
import { SpriteMaskRenderData } from "./SpriteMaskRenderData";
import { StencilOperation } from "../shader";
import { SpriteMaskBatcher } from "./batcher/SpriteMaskBatcher";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to discuss!!!

}

set(
override set(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Further abstraction is needed. In addition, this is a common class between text and elves. The current definition is unreasonable.

import { RenderDataUsage } from "../enums/RenderDataUsage";
import { Batcher2D } from "./Batcher2D";

export class BatcherManager {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the value of this class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

future, i want handle all batch logic in batch function

/**
* @internal
*/
export class MeshBuffer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vague definition, and needs to be redesigned!!!!!!!!!

import { SpriteRenderData } from "../SpriteRenderData";
import { Batcher2D } from "./Batcher2D";

export class SpriteMaskBatcher extends Batcher2D {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically no design, may need to be rewritten

*/
export class MeshBuffer {
/** @internal */
_mesh: BufferMesh;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Primitive

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Primitive

done

* @internal
*/
protected _canBatch(elementA: RenderElement, elementB: RenderElement): boolean {
return false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use RenderData, RenderElement is specific to RenderQueue

* @internal
*/
protected _batchRenderElement(elementA: RenderElement, elementB?: RenderElement): void {}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to use RenderData, RenderElement is specific to RenderQueue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

Optimize 2D rendering pipeline
3 participants