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

Adding layout implementation #18156

Merged
merged 5 commits into from
Jan 13, 2025
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
358 changes: 295 additions & 63 deletions cocos/rendering/custom/layout-graph-editor.ts

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions cocos/rendering/custom/layout-graph-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { assert, error, warn } from '../../core';
import { DescriptorSetInfo, DescriptorSetLayout, DescriptorSetLayoutBinding, DescriptorSetLayoutInfo, DescriptorType, Device, Feature, Format, FormatFeatureBit, GetTypeSize, PipelineLayout, PipelineLayoutInfo, ShaderStageFlagBit, Type, Uniform, UniformBlock } from '../../gfx';
import { UBOForwardLightEnum, UBOSkinning } from '../define';
import type {
DescriptorGroupBlockIndex,
LayoutGraphData,
PipelineLayoutData, RenderPhaseData,
} from './layout-graph';
Expand Down Expand Up @@ -181,6 +182,29 @@ export function sortDescriptorBlocks<T> (lhs: [string, T], rhs: [string, T]): nu
return lhsValue - rhsValue;
}

export function sortDescriptorGroupBlocks<T> (lhs: [string, T], rhs: [string, T]): number {
const lhsIndex: DescriptorGroupBlockIndex = JSON.parse(lhs[0]);
const rhsIndex: DescriptorGroupBlockIndex = JSON.parse(rhs[0]);

const lhsValue = lhsIndex.updateFrequency * 1000000000
+ lhsIndex.parameterType * 100000000
+ lhsIndex.descriptorType * 10000000
+ lhsIndex.visibility * 1000000
+ lhsIndex.accessType * 100000
+ lhsIndex.viewDimension * 10000
+ lhsIndex.sampleType * 1000
+ lhsIndex.format;
const rhsValue = rhsIndex.updateFrequency * 1000000000
+ rhsIndex.parameterType * 100000000
+ rhsIndex.descriptorType * 10000000
+ rhsIndex.visibility * 1000000
+ rhsIndex.accessType * 100000
+ rhsIndex.viewDimension * 10000
+ rhsIndex.sampleType * 1000
+ rhsIndex.format;
return lhsValue - rhsValue;
}

// get descriptor nameID from name
export function getOrCreateDescriptorID (lg: LayoutGraphData, name: string): number {
const nameID = lg.attributeIndex.get(name);
Expand Down
67 changes: 6 additions & 61 deletions cocos/rendering/custom/layout-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,13 @@ export class DescriptorGroupBlockIndex {
declare format: Format;
}

export class DescriptorGroupBlock {
reset (): void {
this.descriptors.clear();
this.uniformBlocks.clear();
this.capacity = 0;
this.count = 0;
}
readonly descriptors: Map<string, Descriptor> = new Map<string, Descriptor>();
readonly uniformBlocks: Map<string, UniformBlock> = new Map<string, UniformBlock>();
capacity = 0;
count = 0;
}

export class DescriptorDB {
reset (): void {
this.blocks.clear();
this.groupBlocks.clear();
}
readonly blocks: Map<string, DescriptorBlock> = new Map<string, DescriptorBlock>();
readonly groupBlocks: Map<string, DescriptorGroupBlock> = new Map<string, DescriptorGroupBlock>();
readonly groupBlocks: Map<string, DescriptorBlock> = new Map<string, DescriptorBlock>();
}

export class RenderPhase {
Expand Down Expand Up @@ -1013,7 +1000,6 @@ export class LayoutGraphObjectPool {
this.dbf.reset(); // DescriptorBlockFlattened
this.dbi.reset(); // DescriptorBlockIndex
this.dgbi.reset(); // DescriptorGroupBlockIndex
this.dgb.reset(); // DescriptorGroupBlock
this.dd.reset(); // DescriptorDB
this.rp.reset(); // RenderPhase
this.lg.reset(); // LayoutGraph
Expand Down Expand Up @@ -1084,11 +1070,6 @@ export class LayoutGraphObjectPool {
v.format = format;
return v;
}
createDescriptorGroupBlock (): DescriptorGroupBlock {
const v = this.dgb.add(); // DescriptorGroupBlock
v.reset();
return v;
}
createDescriptorDB (): DescriptorDB {
const v = this.dd.add(); // DescriptorDB
v.reset();
Expand Down Expand Up @@ -1207,7 +1188,6 @@ export class LayoutGraphObjectPool {
private readonly dbf: RecyclePool<DescriptorBlockFlattened> = createPool(DescriptorBlockFlattened);
private readonly dbi: RecyclePool<DescriptorBlockIndex> = createPool(DescriptorBlockIndex);
private readonly dgbi: RecyclePool<DescriptorGroupBlockIndex> = createPool(DescriptorGroupBlockIndex);
private readonly dgb: RecyclePool<DescriptorGroupBlock> = createPool(DescriptorGroupBlock);
private readonly dd: RecyclePool<DescriptorDB> = createPool(DescriptorDB);
private readonly rp: RecyclePool<RenderPhase> = createPool(RenderPhase);
private readonly lg: RecyclePool<LayoutGraph> = createPool(LayoutGraph);
Expand Down Expand Up @@ -1360,51 +1340,16 @@ export function loadDescriptorGroupBlockIndex (a: InputArchive, v: DescriptorGro
v.format = a.n();
}

export function saveDescriptorGroupBlock (a: OutputArchive, v: DescriptorGroupBlock): void {
a.n(v.descriptors.size); // Map<string, Descriptor>
for (const [k1, v1] of v.descriptors) {
a.s(k1);
saveDescriptor(a, v1);
}
a.n(v.uniformBlocks.size); // Map<string, UniformBlock>
for (const [k1, v1] of v.uniformBlocks) {
a.s(k1);
saveUniformBlock(a, v1);
}
a.n(v.capacity);
a.n(v.count);
}

export function loadDescriptorGroupBlock (a: InputArchive, v: DescriptorGroupBlock): void {
let sz = 0;
sz = a.n(); // Map<string, Descriptor>
for (let i1 = 0; i1 !== sz; ++i1) {
const k1 = a.s();
const v1 = new Descriptor();
loadDescriptor(a, v1);
v.descriptors.set(k1, v1);
}
sz = a.n(); // Map<string, UniformBlock>
for (let i1 = 0; i1 !== sz; ++i1) {
const k1 = a.s();
const v1 = new UniformBlock();
loadUniformBlock(a, v1);
v.uniformBlocks.set(k1, v1);
}
v.capacity = a.n();
v.count = a.n();
}

export function saveDescriptorDB (a: OutputArchive, v: DescriptorDB): void {
a.n(v.blocks.size); // Map<string, DescriptorBlock>
for (const [k1, v1] of v.blocks) {
saveDescriptorBlockIndex(a, JSON.parse(k1) as DescriptorBlockIndex);
saveDescriptorBlock(a, v1);
}
a.n(v.groupBlocks.size); // Map<string, DescriptorGroupBlock>
a.n(v.groupBlocks.size); // Map<string, DescriptorBlock>
for (const [k1, v1] of v.groupBlocks) {
saveDescriptorGroupBlockIndex(a, JSON.parse(k1) as DescriptorGroupBlockIndex);
saveDescriptorGroupBlock(a, v1);
saveDescriptorBlock(a, v1);
}
}

Expand All @@ -1418,12 +1363,12 @@ export function loadDescriptorDB (a: InputArchive, v: DescriptorDB): void {
loadDescriptorBlock(a, v1);
v.blocks.set(JSON.stringify(k1), v1);
}
sz = a.n(); // Map<string, DescriptorGroupBlock>
sz = a.n(); // Map<string, DescriptorBlock>
for (let i1 = 0; i1 !== sz; ++i1) {
const k1 = new DescriptorGroupBlockIndex();
loadDescriptorGroupBlockIndex(a, k1);
const v1 = new DescriptorGroupBlock();
loadDescriptorGroupBlock(a, v1);
const v1 = new DescriptorBlock();
loadDescriptorBlock(a, v1);
v.groupBlocks.set(JSON.stringify(k1), v1);
}
}
Expand Down
1 change: 0 additions & 1 deletion native/cocos/renderer/pipeline/custom/LayoutGraphFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ struct DescriptorBlock;
struct DescriptorBlockFlattened;
struct DescriptorBlockIndex;
struct DescriptorGroupBlockIndex;
struct DescriptorGroupBlock;
struct DescriptorDB;
struct RenderStageTag;
struct RenderPhaseTag;
Expand Down
1 change: 0 additions & 1 deletion native/cocos/renderer/pipeline/custom/LayoutGraphNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ inline const char* getName(const DescriptorBlock& /*v*/) noexcept { return "Desc
inline const char* getName(const DescriptorBlockFlattened& /*v*/) noexcept { return "DescriptorBlockFlattened"; }
inline const char* getName(const DescriptorBlockIndex& /*v*/) noexcept { return "DescriptorBlockIndex"; }
inline const char* getName(const DescriptorGroupBlockIndex& /*v*/) noexcept { return "DescriptorGroupBlockIndex"; }
inline const char* getName(const DescriptorGroupBlock& /*v*/) noexcept { return "DescriptorGroupBlock"; }
inline const char* getName(const DescriptorDB& /*v*/) noexcept { return "DescriptorDB"; }
inline const char* getName(const RenderStageTag& /*v*/) noexcept { return "RenderStage"; }
inline const char* getName(const RenderPhaseTag& /*v*/) noexcept { return "RenderPhase"; }
Expand Down
14 changes: 0 additions & 14 deletions native/cocos/renderer/pipeline/custom/LayoutGraphSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,6 @@ void load(InputArchive& ar, DescriptorGroupBlockIndex& v) {
load(ar, v.format);
}

void save(OutputArchive& ar, const DescriptorGroupBlock& v) {
save(ar, v.descriptors);
save(ar, v.uniformBlocks);
save(ar, v.capacity);
save(ar, v.count);
}

void load(InputArchive& ar, DescriptorGroupBlock& v) {
load(ar, v.descriptors);
load(ar, v.uniformBlocks);
load(ar, v.capacity);
load(ar, v.count);
}

void save(OutputArchive& ar, const DescriptorDB& v) {
save(ar, v.blocks);
save(ar, v.groupBlocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ void load(InputArchive& ar, DescriptorBlockIndex& v);
void save(OutputArchive& ar, const DescriptorGroupBlockIndex& v);
void load(InputArchive& ar, DescriptorGroupBlockIndex& v);

void save(OutputArchive& ar, const DescriptorGroupBlock& v);
void load(InputArchive& ar, DescriptorGroupBlock& v);

void save(OutputArchive& ar, const DescriptorDB& v);
void load(InputArchive& ar, DescriptorDB& v);

Expand Down
9 changes: 1 addition & 8 deletions native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,6 @@ inline bool operator<(const DescriptorGroupBlockIndex& lhs, const DescriptorGrou
std::forward_as_tuple(rhs.updateFrequency, rhs.parameterType, rhs.descriptorType, rhs.visibility, rhs.accessType, rhs.viewDimension, rhs.sampleType, rhs.format);
}

struct DescriptorGroupBlock {
ccstd::map<ccstd::string, Descriptor> descriptors;
ccstd::map<ccstd::string, gfx::UniformBlock> uniformBlocks;
uint32_t capacity{0};
uint32_t count{0};
};

struct DescriptorDB {
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
allocator_type get_allocator() const noexcept { // NOLINT
Expand All @@ -159,7 +152,7 @@ struct DescriptorDB {
DescriptorDB& operator=(DescriptorDB const& rhs) = default;

ccstd::pmr::map<DescriptorBlockIndex, DescriptorBlock> blocks;
ccstd::pmr::map<DescriptorGroupBlockIndex, DescriptorGroupBlock> groupBlocks;
ccstd::pmr::map<DescriptorGroupBlockIndex, DescriptorBlock> groupBlocks;
};

struct RenderStageTag {};
Expand Down
Loading