Skip to content

add 2d #18717

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

Merged
merged 5 commits into from
May 21, 2025
Merged

add 2d #18717

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
31 changes: 31 additions & 0 deletions cocos/rendering/custom/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,34 @@ class DeviceRenderScene implements RecordingInterface {
}
}

protected _record3D (): void {
const blit = this._blit!;
const device = context.device;
const cmdBuff = context.commandBuffer;
for (const model of blit.models) {
for (const subModel of model.subModels) {
const inputAssembler = subModel.inputAssembler;
const passCount = subModel.passes.length;
for (let passId = 0; passId < passCount; ++passId) {
const pass = subModel.passes[passId];
const shader = subModel.shaders[passId];
const pso = PipelineStateManager.getOrCreatePipelineState(
device,
pass,
shader,
this._renderPass,
inputAssembler,
);
cmdBuff.bindPipelineState(pso);
cmdBuff.bindDescriptorSet(SetIndex.MATERIAL, pass.descriptorSet);
cmdBuff.bindDescriptorSet(SetIndex.LOCAL, subModel.descriptorSet);
cmdBuff.bindInputAssembler(inputAssembler);
cmdBuff.draw(inputAssembler);
}
}
}
}

protected _recordUI (): void {
const batches = this.camera!.scene!.batches;
for (let i = 0; i < batches.length; i++) {
Expand Down Expand Up @@ -1278,6 +1306,9 @@ class DeviceRenderScene implements RecordingInterface {
case BlitType.DRAW_PROFILE:
this._showProfiler();
break;
case BlitType.DRAW_3D:
this._record3D();
break;
default:
break;
}
Expand Down
15 changes: 15 additions & 0 deletions cocos/rendering/custom/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,21 @@ export interface RenderQueueBuilder extends Setter {
material: Material,
passID: number,
sceneFlags?: SceneFlags): void;
/**
* @beta Feature is under development
*/
addDraw3D (
camera: Camera,
models: Model[],
sceneFlags?: SceneFlags): void;
/**
* @beta Feature is under development
*/
addDraw2D (camera: Camera): void;
/**
* @beta Feature is under development
*/
addProfiler (camera: Camera): void;
/**
* @en Clear current render target.
* @zh 清除当前渲染目标
Expand Down
5 changes: 4 additions & 1 deletion cocos/rendering/custom/render-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { CopyPair, MovePair, ResolvePair, UploadPair } from './types';
import { AccessType, AttachmentType, ClearValueType, LightInfo, QueueHint, ResourceDimension, ResourceFlags, ResourceResidency, SceneFlags, RenderCommonObjectPool } from './types';
import type { RenderScene } from '../../render-scene/core/render-scene';
import type { RenderWindow } from '../../render-scene/core/render-window';
import type { Light } from '../../render-scene/scene';
import type { Light, Model } from '../../render-scene/scene';
import { RecyclePool } from '../../core/memop';

function resetColor (v: Color): void {
Expand Down Expand Up @@ -1084,6 +1084,7 @@ export const enum BlitType {
FULLSCREEN_QUAD,
DRAW_2D,
DRAW_PROFILE,
DRAW_3D,
}

export class Blit {
Expand Down Expand Up @@ -1112,12 +1113,14 @@ export class Blit {
this.sceneFlags = sceneFlags;
this.camera = camera;
this.blitType = blitType;
this.models.length = 0;
}
declare /*refcount*/ material: Material | null;
declare passID: number;
declare sceneFlags: SceneFlags;
declare /*pointer*/ camera: Camera | null;
declare blitType: BlitType;
readonly models: Model[] = [];
}

export class RenderData {
Expand Down
39 changes: 39 additions & 0 deletions cocos/rendering/custom/web-pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,45 @@ export class WebRenderQueueBuilder extends WebSetter implements RenderQueueBuild
setShadowUBOView(this, camera, layoutName);
}
}
addDraw3D (camera: Camera, models: Model[], sceneFlags = SceneFlags.NON_BUILTIN): void {
const blit = renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_3D);
for (const model of models) {
blit.models.push(model);
}
this._renderGraph.addVertex<RenderGraphValue.Blit>(
RenderGraphValue.Blit,
blit,
'Draw3D',
'',
renderGraphPool.createRenderData(),
!DEBUG,
this._vertID,
);
if (!(sceneFlags & SceneFlags.NON_BUILTIN)) {
const layoutName = this.getParentLayout();
setCameraUBOValues(
this,
camera,
this._pipeline,
camera.scene,
layoutName,
);
if (!(sceneFlags & SceneFlags.SHADOW_CASTER)) setShadowUBOView(this, camera, layoutName);
}
}
addDraw2D (camera: Camera): void {
this._renderGraph.addVertex<RenderGraphValue.Blit>(
RenderGraphValue.Blit,
renderGraphPool.createBlit(emptyMaterial, this._renderGraph.N, SceneFlags.NONE, camera, BlitType.DRAW_2D),
'Draw2D',
'',
emptyRenderData,
!DEBUG,
this._vertID,
);
}
addProfiler (camera: Camera): void {
}
clearRenderTarget (name: string, color: Color = new Color()): void {
const clearView = renderGraphPool.createClearView(name, ClearFlagBit.COLOR);
clearView.clearColor.copy(color);
Expand Down
34 changes: 33 additions & 1 deletion native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
const auto& queueDesc = ctx.context.sceneCulling.renderQueueQueryIndex.at(sceneID);
const auto& queue = ctx.context.sceneCulling.renderQueues[queueDesc.renderQueueTarget.value];

queue.recordCommands(ctx.cmdBuff, ctx.currentPass, 0, sceneData.flags);
queue.recordCommands(
ctx.cmdBuff, ctx.currentPass, ctx.subpassIndex, sceneData.flags);

#if CC_USE_GEOMETRY_RENDERER
if (any(sceneData.flags & SceneFlags::GEOMETRY) &&
Expand All @@ -693,6 +694,34 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
}
}

void draw3D(const Blit& blit) const {
if (blit.models.empty()) {
return;
}
auto* cmdBuff = ctx.cmdBuff;
auto* renderPass = ctx.currentPass;
const auto subpassIndex = ctx.subpassIndex;

for (const auto& model : blit.models) {
for (const auto& subModel : model->getSubModels()) {
auto* inputAssembler = subModel->getInputAssembler();
const auto& passes = *(subModel->getPasses());
for (uint32_t passIdx = 0; passIdx < passes.size(); ++passIdx) {
const auto& pass = passes[passIdx];
auto* shader = subModel->getShader(passIdx);
auto* pso = pipeline::PipelineStateManager::getOrCreatePipelineState(
pass, shader, inputAssembler, renderPass, subpassIndex);

cmdBuff->bindPipelineState(pso);
cmdBuff->bindDescriptorSet(pipeline::materialSet, pass->getDescriptorSet());
cmdBuff->bindDescriptorSet(pipeline::localSet, subModel->getDescriptorSet());
cmdBuff->bindInputAssembler(inputAssembler);
cmdBuff->draw(inputAssembler);
}
}
}
}

void draw2D(const Blit& blit, RenderGraph::vertex_descriptor sceneID) const {
const auto queueID = parent(sceneID, ctx.g);
CC_EXPECTS(queueID != RenderGraph::null_vertex());
Expand Down Expand Up @@ -758,6 +787,9 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
case BlitType::DRAW_PROFILE:
submitProfilerCommands(ctx, vertID);
break;
case BlitType::DRAW_3D:
draw3D(blit);
break;
default:
CC_EXPECTS(false);
}
Expand Down
3 changes: 3 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativePipelineTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ class NativeRenderQueueBuilder final : public RenderQueueBuilder, public NativeS
SceneBuilder *addScene(const scene::Camera *camera, SceneFlags sceneFlags, scene::Light *light, scene::RenderScene *scene) override;
void addFullscreenQuad(Material *material, uint32_t passID, SceneFlags sceneFlags) override;
void addCameraQuad(scene::Camera *camera, Material *material, uint32_t passID, SceneFlags sceneFlags) override;
void addDraw3D(const scene::Camera *camera, const std::vector<scene::Model*> &models, SceneFlags sceneFlags) override;
void addDraw2D(const scene::Camera *camera) override;
void addProfiler(const scene::Camera *camera) override;
void clearRenderTarget(const ccstd::string &name, const gfx::Color &color) override;
void setViewport(const gfx::Viewport &viewport) override;
void addCustomCommand(std::string_view customBehavior) override;
Expand Down
Loading
Loading