From a2c75382e9943c5170cab36ab42d3c92683964bf Mon Sep 17 00:00:00 2001 From: Zeqiang Li Date: Fri, 11 Aug 2023 14:43:25 +0800 Subject: [PATCH] Develop move (#14) * subresource move (#157) # Conflicts: # native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp --- .../pipeline/custom/FGDispatcherTypes.h | 15 ++++++++ .../pipeline/custom/FrameGraphDispatcher.cpp | 1 + .../pipeline/custom/NativePipeline.cpp | 36 +++++++++---------- .../pipeline/custom/RenderInterfaceTypes.h | 4 +-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h b/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h index 4f6b586f6f4..4ccbd35bee7 100644 --- a/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h +++ b/native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h @@ -163,6 +163,21 @@ struct ResourceNode { ccstd::vector planes; }; +struct SliceNode { + bool full{false}; + std::vector mips; +}; + +struct TextureNode { + bool full{false}; + std::vector slices; +}; + +struct ResourceNode { + bool full{false}; + std::vector planes; +}; + struct ResourceAccessGraph { using allocator_type = boost::container::pmr::polymorphic_allocator; allocator_type get_allocator() const noexcept { // NOLINT diff --git a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp index c02ba4982fc..297752f6ae2 100644 --- a/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp +++ b/native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp @@ -1483,6 +1483,7 @@ bool moveValidation(const MovePass& pass, ResourceAccessGraph& rag, const Resour fromResDesc.sampleCount == toResDesc.sampleCount, (fromResDesc.depthOrArraySize == toResDesc.depthOrArraySize) || (toResDesc.dimension != ResourceDimension::BUFFER), // full move if resource is buffer }; + auto num = std::min_element(std::begin(validConditions), std::end(validConditions)); bool val = *std::min_element(std::begin(validConditions), std::end(validConditions)); check &= val; } diff --git a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp index 8e5f740ecf0..6781d0a5cd6 100644 --- a/native/cocos/renderer/pipeline/custom/NativePipeline.cpp +++ b/native/cocos/renderer/pipeline/custom/NativePipeline.cpp @@ -1100,6 +1100,9 @@ void NativePipeline::addBuiltinHzbGenerationPass( ccstd::pmr::string currMipName(scratch); currMipName.reserve(targetHzbName.size() + 6); currMipName.append(targetHzbName); + + MovePass move(renderGraph.get_allocator()); + move.movePairs.reserve(targetDesc.mipLevels); // register all mips { CC_EXPECTS(targetDesc.mipLevels && targetDesc.mipLevels != std::numeric_limits::max()); @@ -1107,28 +1110,38 @@ void NativePipeline::addBuiltinHzbGenerationPass( desc.mipLevels = 1; CC_EXPECTS(desc.depthOrArraySize == 1); CC_EXPECTS(desc.sampleCount == gfx::SampleCount::X1); + for (uint32_t k = 0; k != targetDesc.mipLevels; ++k) { currMipName.resize(targetHzbName.size()); CC_ENSURES(currMipName == std::string_view{targetHzbName}); currMipName.append("_Mip"); currMipName.append(std::to_string(k)); + auto resID = findVertex(currMipName, resourceGraph); if (resID == ResourceGraph::null_vertex()) { resID = addVertex( ManagedTextureTag{}, std::forward_as_tuple(currMipName.c_str()), - std::forward_as_tuple(), + std::forward_as_tuple(desc), std::forward_as_tuple(ResourceTraits{ResourceResidency::MANAGED}), std::forward_as_tuple(), std::forward_as_tuple(), std::forward_as_tuple(), resourceGraph); + + MovePair pair(move.get_allocator()); + pair.source = currMipName; + pair.target = targetHzbName; + pair.mipLevels = 1; + pair.numSlices = 1; + pair.targetMostDetailedMip = k; + move.movePairs.emplace_back(std::move(pair)); } else { CC_EXPECTS(holds(resID, resourceGraph)); updateResourceImpl( resourceGraph, currMipName, - gfx::Format::UNKNOWN, + desc.format, desc.width, desc.height, 1, 1, 1, gfx::SampleCount::X1); @@ -1267,24 +1280,7 @@ void NativePipeline::addBuiltinHzbGenerationPass( height = getHalfSize(height); } - // add MovePass - { - MovePass move(renderGraph.get_allocator()); - move.movePairs.reserve(targetDesc.mipLevels); - for (uint32_t k = 0; k != targetDesc.mipLevels; ++k) { - currMipName.resize(targetHzbName.size()); - CC_ENSURES(currMipName == std::string_view{targetHzbName}); - currMipName.append("_Mip"); - currMipName.append(std::to_string(k)); - MovePair pair(move.get_allocator()); - pair.source = currMipName; - pair.target = targetHzbName; - pair.mipLevels = 1; - pair.numSlices = 1; - pair.targetMostDetailedMip = k; - move.movePairs.emplace_back(std::move(pair)); - } - + if (!move.movePairs.empty()) { auto moveID = addVertex2( MoveTag{}, std::forward_as_tuple("HZMove"), diff --git a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h index 9e860d98f8a..95357699920 100644 --- a/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h +++ b/native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h @@ -658,10 +658,10 @@ class BasicRenderPassBuilder : public Setter { addDepthStencil(name, loadOp, storeOp, depth, stencil, gfx::ClearFlagBit::DEPTH_STENCIL); } void addTexture(const ccstd::string &name, const ccstd::string &slotName) { - addTexture(name, slotName, nullptr, 0); + addTexture(name, slotName, nullptr, 0xFFFFFFFF); } void addTexture(const ccstd::string &name, const ccstd::string &slotName, gfx::Sampler *sampler) { - addTexture(name, slotName, sampler, 0); + addTexture(name, slotName, sampler, 0xFFFFFFFF); } RenderQueueBuilder *addQueue() { return addQueue(QueueHint::NONE, "default");