Skip to content

Commit

Permalink
Develop move (#14)
Browse files Browse the repository at this point in the history
* subresource move (#157)
# Conflicts:
#	native/cocos/renderer/pipeline/custom/FrameGraphDispatcher.cpp
  • Loading branch information
hana-alice authored and stanleyljl committed Aug 14, 2023
1 parent 2188b2d commit a2c7538
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
15 changes: 15 additions & 0 deletions native/cocos/renderer/pipeline/custom/FGDispatcherTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ struct ResourceNode {
ccstd::vector<TextureNode> planes;
};

struct SliceNode {
bool full{false};
std::vector<uint32_t> mips;
};

struct TextureNode {
bool full{false};
std::vector<SliceNode> slices;
};

struct ResourceNode {
bool full{false};
std::vector<TextureNode> planes;
};

struct ResourceAccessGraph {
using allocator_type = boost::container::pmr::polymorphic_allocator<char>;
allocator_type get_allocator() const noexcept { // NOLINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
36 changes: 16 additions & 20 deletions native/cocos/renderer/pipeline/custom/NativePipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,35 +1100,48 @@ 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<decltype(targetDesc.mipLevels)>::max());
auto desc = targetDesc;
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<ManagedTextureTag>(resID, resourceGraph));
updateResourceImpl(
resourceGraph,
currMipName,
gfx::Format::UNKNOWN,
desc.format,
desc.width,
desc.height,
1, 1, 1, gfx::SampleCount::X1);
Expand Down Expand Up @@ -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"),
Expand Down
4 changes: 2 additions & 2 deletions native/cocos/renderer/pipeline/custom/RenderInterfaceTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit a2c7538

Please sign in to comment.