From f678760750b6d6849d0d6500b5d2c2c66005672f Mon Sep 17 00:00:00 2001 From: zxx43 Date: Fri, 24 Jun 2022 16:05:32 +0800 Subject: [PATCH] add implementation of addUniformBlock --- cocos/core/pipeline/custom/effect.ts | 3 +++ cocos/core/pipeline/custom/web-layout-graph.ts | 15 ++++++++++++++- .../pipeline/custom/NativeLayoutGraphImpl.cpp | 17 ++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/cocos/core/pipeline/custom/effect.ts b/cocos/core/pipeline/custom/effect.ts index 9a748c28a99..f815a33095e 100644 --- a/cocos/core/pipeline/custom/effect.ts +++ b/cocos/core/pipeline/custom/effect.ts @@ -48,6 +48,9 @@ function buildLayoutGraphDataImpl (graph: LayoutGraph, lgData: LayoutGraphBuilde if (block.capacity > 0) { lgData.addDescriptorBlock(vid, index, flattened); } + for (let i = 0; i < flattened.uniformBlockNames.length; ++i) { + lgData.addUniformBlock(vid, index, flattened.uniformBlockNames[i], flattened.uniformBlocks[i]); + } }); } diff --git a/cocos/core/pipeline/custom/web-layout-graph.ts b/cocos/core/pipeline/custom/web-layout-graph.ts index 277731006d1..b1aadb6165c 100644 --- a/cocos/core/pipeline/custom/web-layout-graph.ts +++ b/cocos/core/pipeline/custom/web-layout-graph.ts @@ -182,7 +182,20 @@ export class WebLayoutGraphBuilder extends LayoutGraphBuilder { } public addUniformBlock (nodeID: number, index: DescriptorBlockIndex, name: string, uniformBlock: UniformBlock): void { - // need implementation + const g: LayoutGraphData = this._data; + const ppl: PipelineLayoutData = g.getLayout(nodeID); + const layout: DescriptorSetLayoutData | undefined = ppl.descriptorSets.get(index.updateFrequency)?.descriptorSetLayoutData; + if (layout !== undefined) { + let nameID: number | undefined = g.attributeIndex.get(name); + if (nameID === undefined) { + const id = g.valueNames.length; + g.attributeIndex.set(name, id); + g.valueNames.push(name); + } + + nameID = g.attributeIndex.get(name); + layout.uniformBlocks.set(nameID as number, uniformBlock); + } } public reserveDescriptorBlock (nodeID: number, index: DescriptorBlockIndex, block: DescriptorBlockFlattened): void { diff --git a/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp b/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp index d078b561955..6f83775a2d5 100644 --- a/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp +++ b/native/cocos/renderer/pipeline/custom/NativeLayoutGraphImpl.cpp @@ -104,7 +104,22 @@ void NativeLayoutGraphBuilder::addDescriptorBlock( } void NativeLayoutGraphBuilder::addUniformBlock(uint32_t nodeID, const DescriptorBlockIndex& index, const ccstd::string& name, const gfx::UniformBlock& uniformBlock) { - + auto &g = *data; + auto &ppl = get(LayoutGraphData::Layout, g, nodeID); + auto &layout = ppl.descriptorSets[index.updateFrequency].descriptorSetLayoutData; + auto iter = g.attributeIndex.find(boost::string_view(name)); + if (iter == g.attributeIndex.end()) { + auto attrID = gsl::narrow_cast(g.valueNames.size()); + g.valueNames.emplace_back(name); + bool added = false; + std::tie(iter, added) = g.attributeIndex.emplace( + std::piecewise_construct, + std::forward_as_tuple(name), + std::forward_as_tuple(NameLocalID{attrID})); + CC_ENSURES(added); + } + const auto &nameID = iter->second; + layout.uniformBlocks.emplace(nameID, uniformBlock); } namespace {