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

Merge render queue #17622

Merged
merged 4 commits into from
Sep 11, 2024
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
6 changes: 3 additions & 3 deletions native/cocos/renderer/pipeline/custom/LayoutGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@ inline bool operator<(const NameLocalID& lhs, const NameLocalID& rhs) noexcept {

struct DescriptorData {
DescriptorData() = default;
DescriptorData(NameLocalID descriptorIDIn, gfx::Type typeIn, uint32_t countIn) noexcept
DescriptorData(const NameLocalID& descriptorIDIn, gfx::Type typeIn, uint32_t countIn) noexcept
: descriptorID(descriptorIDIn),
type(typeIn),
count(countIn) {}
DescriptorData(NameLocalID descriptorIDIn, gfx::Type typeIn) noexcept
DescriptorData(const NameLocalID& descriptorIDIn, gfx::Type typeIn) noexcept
: descriptorID(descriptorIDIn),
type(typeIn) {}
DescriptorData(NameLocalID descriptorIDIn) noexcept // NOLINT
DescriptorData(const NameLocalID& descriptorIDIn) noexcept // NOLINT
: descriptorID(descriptorIDIn) {}

NameLocalID descriptorID;
Expand Down
4 changes: 2 additions & 2 deletions native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,10 @@ struct RenderGraphVisitor : boost::dfs_visitor<> {
tryBindLeafOverwritePerPassDescriptorSet(sceneID);
}
const auto* scene = camera->getScene();
const auto& queueDesc = ctx.context.sceneCulling.renderQueueIndex.at(sceneID);
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);
queue.recordCommands(ctx.cmdBuff, ctx.currentPass, 0, sceneData.flags);

#if CC_USE_GEOMETRY_RENDERER
if (any(sceneData.flags & SceneFlags::GEOMETRY) &&
Expand Down
13 changes: 12 additions & 1 deletion native/cocos/renderer/pipeline/custom/NativePipelineFwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ struct LightBoundsCullingID;
struct LightBoundsCullingKey;
struct LightBoundsCulling;
struct NativeRenderQueueID;
struct NativeRenderQueueDesc;
struct NativeRenderQueueKey;
struct NativeRenderQueueQuery;
struct LightBoundsCullingResult;
struct SceneCulling;
struct LightResource;
Expand Down Expand Up @@ -123,11 +124,21 @@ struct hash<cc::render::FrustumCullingID> {
hash_t operator()(const cc::render::FrustumCullingID& val) const noexcept;
};

template <>
struct hash<cc::render::LightBoundsCullingID> {
hash_t operator()(const cc::render::LightBoundsCullingID& val) const noexcept;
};

template <>
struct hash<cc::render::LightBoundsCullingKey> {
hash_t operator()(const cc::render::LightBoundsCullingKey& val) const noexcept;
};

template <>
struct hash<cc::render::NativeRenderQueueKey> {
hash_t operator()(const cc::render::NativeRenderQueueKey& val) const noexcept;
};

} // namespace ccstd

// clang-format on
17 changes: 5 additions & 12 deletions native/cocos/renderer/pipeline/custom/NativePipelineTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,14 @@ NativeRenderQueue::NativeRenderQueue(const allocator_type& alloc) noexcept
opaqueInstancingQueue(alloc),
transparentInstancingQueue(alloc) {}

NativeRenderQueue::NativeRenderQueue(SceneFlags sceneFlagsIn, uint32_t subpassOrPassLayoutIDIn, const allocator_type& alloc) noexcept
: opaqueQueue(alloc),
transparentQueue(alloc),
probeQueue(alloc),
opaqueInstancingQueue(alloc),
transparentInstancingQueue(alloc),
sceneFlags(sceneFlagsIn),
subpassOrPassLayoutID(subpassOrPassLayoutIDIn) {}

NativeRenderQueue::NativeRenderQueue(NativeRenderQueue&& rhs, const allocator_type& alloc)
: opaqueQueue(std::move(rhs.opaqueQueue), alloc),
transparentQueue(std::move(rhs.transparentQueue), alloc),
probeQueue(std::move(rhs.probeQueue), alloc),
opaqueInstancingQueue(std::move(rhs.opaqueInstancingQueue), alloc),
transparentInstancingQueue(std::move(rhs.transparentInstancingQueue), alloc),
camera(rhs.camera),
sceneFlags(rhs.sceneFlags),
subpassOrPassLayoutID(rhs.subpassOrPassLayoutID),
lightByteOffset(rhs.lightByteOffset) {}

ResourceGroup::ResourceGroup(const allocator_type& alloc) noexcept
Expand Down Expand Up @@ -195,16 +186,18 @@ SceneCulling::SceneCulling(const allocator_type& alloc) noexcept
frustumCullingResults(alloc),
lightBoundsCullings(alloc),
lightBoundsCullingResults(alloc),
renderQueueIndex(alloc),
renderQueues(alloc),
renderQueueIndex(alloc) {}
renderQueueQueryIndex(alloc) {}

SceneCulling::SceneCulling(SceneCulling&& rhs, const allocator_type& alloc)
: frustumCullings(std::move(rhs.frustumCullings), alloc),
frustumCullingResults(std::move(rhs.frustumCullingResults), alloc),
lightBoundsCullings(std::move(rhs.lightBoundsCullings), alloc),
lightBoundsCullingResults(std::move(rhs.lightBoundsCullingResults), alloc),
renderQueues(std::move(rhs.renderQueues), alloc),
renderQueueIndex(std::move(rhs.renderQueueIndex), alloc),
renderQueues(std::move(rhs.renderQueues), alloc),
renderQueueQueryIndex(std::move(rhs.renderQueueQueryIndex), alloc),
numFrustumCulling(rhs.numFrustumCulling),
numLightBoundsCulling(rhs.numLightBoundsCulling),
numRenderQueues(rhs.numRenderQueues),
Expand Down
56 changes: 47 additions & 9 deletions native/cocos/renderer/pipeline/custom/NativePipelineTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,6 @@ struct NativeRenderQueue {
}

NativeRenderQueue(const allocator_type& alloc) noexcept; // NOLINT
NativeRenderQueue(SceneFlags sceneFlagsIn, uint32_t subpassOrPassLayoutIDIn, const allocator_type& alloc) noexcept;
NativeRenderQueue(NativeRenderQueue&& rhs, const allocator_type& alloc);

NativeRenderQueue(NativeRenderQueue&& rhs) noexcept = default;
Expand All @@ -1095,15 +1094,15 @@ struct NativeRenderQueue {
void clear() noexcept;
bool empty() const noexcept;
void recordCommands(
gfx::CommandBuffer *cmdBuffer, gfx::RenderPass *renderPass, uint32_t subpassIndex) const;
gfx::CommandBuffer *cmdBuffer, gfx::RenderPass *renderPass, uint32_t subpassIndex, SceneFlags sceneFlags) const;

RenderDrawQueue opaqueQueue;
RenderDrawQueue transparentQueue;
ProbeHelperQueue probeQueue;
RenderInstancingQueue opaqueInstancingQueue;
RenderInstancingQueue transparentInstancingQueue;
const scene::Camera* camera{nullptr};
SceneFlags sceneFlags{SceneFlags::NONE};
uint32_t subpassOrPassLayoutID{0xFFFFFFFF};
uint32_t lightByteOffset{0xFFFFFFFF};
};

Expand Down Expand Up @@ -1332,6 +1331,15 @@ struct LightBoundsCullingID {
uint32_t value{0xFFFFFFFF};
};

inline bool operator==(const LightBoundsCullingID& lhs, const LightBoundsCullingID& rhs) noexcept {
return std::forward_as_tuple(lhs.value) ==
std::forward_as_tuple(rhs.value);
}

inline bool operator!=(const LightBoundsCullingID& lhs, const LightBoundsCullingID& rhs) noexcept {
return !(lhs == rhs);
}

struct LightBoundsCullingKey {
FrustumCullingID frustumCullingID;
const scene::Camera* camera{nullptr};
Expand Down Expand Up @@ -1374,11 +1382,25 @@ struct NativeRenderQueueID {
uint32_t value{0xFFFFFFFF};
};

struct NativeRenderQueueDesc {
struct NativeRenderQueueKey {
FrustumCullingID frustumCulledResultID;
LightBoundsCullingID lightBoundsCulledResultID;
uint32_t queueLayoutID{0xFFFFFFFF};
};

inline bool operator==(const NativeRenderQueueKey& lhs, const NativeRenderQueueKey& rhs) noexcept {
return std::forward_as_tuple(lhs.frustumCulledResultID, lhs.lightBoundsCulledResultID, lhs.queueLayoutID) ==
std::forward_as_tuple(rhs.frustumCulledResultID, rhs.lightBoundsCulledResultID, rhs.queueLayoutID);
}

inline bool operator!=(const NativeRenderQueueKey& lhs, const NativeRenderQueueKey& rhs) noexcept {
return !(lhs == rhs);
}

struct NativeRenderQueueQuery {
FrustumCullingID frustumCulledResultID;
LightBoundsCullingID lightBoundsCulledResultID;
NativeRenderQueueID renderQueueTarget;
scene::LightType lightType{scene::LightType::UNKNOWN};
};

struct LightBoundsCullingResult {
Expand All @@ -1405,18 +1427,20 @@ struct SceneCulling {
private:
FrustumCullingID getOrCreateFrustumCulling(const SceneData& sceneData);
LightBoundsCullingID getOrCreateLightBoundsCulling(const SceneData& sceneData, FrustumCullingID frustumCullingID);
NativeRenderQueueID createRenderQueue(SceneFlags sceneFlags, LayoutGraphData::vertex_descriptor subpassOrPassLayoutID);
void collectCullingQueries(const RenderGraph& rg, const LayoutGraphData& lg);
NativeRenderQueueID getOrCreateRenderQueue(
const NativeRenderQueueKey& renderQueueKey, SceneFlags sceneFlags, const scene::Camera* camera);
void collectCullingQueries(const RenderGraph& rg);
void batchFrustumCulling(const NativePipeline& ppl);
void batchLightBoundsCulling();
void fillRenderQueues(const RenderGraph& rg, const pipeline::PipelineSceneData& pplSceneData);
void fillRenderQueues();
public:
ccstd::pmr::unordered_map<const scene::RenderScene*, FrustumCulling> frustumCullings;
ccstd::pmr::vector<ccstd::vector<const scene::Model*>> frustumCullingResults;
ccstd::pmr::unordered_map<const scene::RenderScene*, LightBoundsCulling> lightBoundsCullings;
ccstd::pmr::vector<LightBoundsCullingResult> lightBoundsCullingResults;
ccstd::pmr::unordered_map<NativeRenderQueueKey, NativeRenderQueueID> renderQueueIndex;
ccstd::pmr::vector<NativeRenderQueue> renderQueues;
PmrFlatMap<RenderGraph::vertex_descriptor, NativeRenderQueueDesc> renderQueueIndex;
PmrFlatMap<RenderGraph::vertex_descriptor, NativeRenderQueueQuery> renderQueueQueryIndex;
uint32_t numFrustumCulling{0};
uint32_t numLightBoundsCulling{0};
uint32_t numRenderQueues{0};
Expand Down Expand Up @@ -1754,6 +1778,12 @@ inline hash_t hash<cc::render::FrustumCullingID>::operator()(const cc::render::F
return seed;
}

inline hash_t hash<cc::render::LightBoundsCullingID>::operator()(const cc::render::LightBoundsCullingID& val) const noexcept {
hash_t seed = 0;
hash_combine(seed, val.value);
return seed;
}

inline hash_t hash<cc::render::LightBoundsCullingKey>::operator()(const cc::render::LightBoundsCullingKey& val) const noexcept {
hash_t seed = 0;
hash_combine(seed, val.frustumCullingID);
Expand All @@ -1763,6 +1793,14 @@ inline hash_t hash<cc::render::LightBoundsCullingKey>::operator()(const cc::rend
return seed;
}

inline hash_t hash<cc::render::NativeRenderQueueKey>::operator()(const cc::render::NativeRenderQueueKey& val) const noexcept {
hash_t seed = 0;
hash_combine(seed, val.frustumCulledResultID);
hash_combine(seed, val.lightBoundsCulledResultID);
hash_combine(seed, val.queueLayoutID);
return seed;
}

} // namespace ccstd

// clang-format on
Expand Down
23 changes: 14 additions & 9 deletions native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,20 @@ void NativeRenderQueue::sort() {
void NativeRenderQueue::recordCommands(
gfx::CommandBuffer *cmdBuffer,
gfx::RenderPass *renderPass,
uint32_t subpassIndex) const {
opaqueQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
opaqueInstancingQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
transparentQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
transparentInstancingQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
uint32_t subpassIndex,
SceneFlags sceneFlags) const {
if (any(sceneFlags & (SceneFlags::OPAQUE | SceneFlags::MASK))) {
opaqueQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
opaqueInstancingQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
}
if (any(sceneFlags & SceneFlags::BLEND)) {
transparentQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
transparentInstancingQueue.recordCommandBuffer(
renderPass, subpassIndex, cmdBuffer, lightByteOffset);
}
}

} // namespace render
Expand Down
Loading
Loading