Skip to content

Commit

Permalink
fix gpu driven shadow bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stanleyljl committed Oct 8, 2023
1 parent 2e1f639 commit feb3c36
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
13 changes: 11 additions & 2 deletions native/cocos/renderer/pipeline/custom/NativeExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ gfx::DescriptorSet* initDescriptorSet(

gfx::DescriptorSet* updatePerPassDescriptorSet(
gfx::CommandBuffer* cmdBuff,
ResourceGraph& resg,
const LayoutGraphData& lg,
const DescriptorSetData& set,
const RenderData& user,
Expand Down Expand Up @@ -677,7 +678,15 @@ gfx::DescriptorSet* updatePerPassDescriptorSet(
for (const auto& d : block.descriptors) {
bool found = false;
CC_EXPECTS(d.count == 1);
if (auto iter = user.buffers.find(d.descriptorID.value);
if (auto iter = user.bufferNames.find(d.descriptorID.value);
iter != user.bufferNames.end()) {
const auto resID = findVertex(iter->second, resg);
CC_ENSURES(resID != ResourceGraph::null_vertex());
auto* buffer = resg.getBuffer(resID);
CC_ENSURES(buffer);
newSet->bindBuffer(bindID, buffer);
found = true;
} else if (auto iter = user.buffers.find(d.descriptorID.value);
iter != user.buffers.end()) {
newSet->bindBuffer(bindID, iter->second.get());
found = true;
Expand Down Expand Up @@ -732,7 +741,7 @@ gfx::DescriptorSet* updateCameraUniformBufferAndDescriptorSet(
auto& set = iter->second;
auto& node = ctx.context.layoutGraphResources.at(passLayoutID);
const auto& user = get(RenderGraph::DataTag{}, ctx.g, sceneID); // notice: sceneID
perPassSet = updatePerPassDescriptorSet(ctx.cmdBuff, ctx.lg, set, user, node);
perPassSet = updatePerPassDescriptorSet(ctx.cmdBuff, ctx.resourceGraph, ctx.lg, set, user, node);
}
return perPassSet;
}
Expand Down
7 changes: 7 additions & 0 deletions native/cocos/renderer/pipeline/custom/NativeRenderGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ void NativeRenderQueueBuilder::addGpuDrivenResource(const scene::Camera *camera,
}

if (any(sceneFlags & SceneFlags::GPU_DRIVEN)) {
auto &data = get(RenderGraph::DataTag{}, *renderGraph, rgSceneID);
const auto passID = renderGraph->getPassID(nodeID);
const auto &sceneCulling = dynamic_cast<const NativePipeline *>(pipelineRuntime)->nativeContext.sceneCulling;
const auto sceneID = sceneCulling.sceneIDs.at(scene);
Expand All @@ -772,6 +773,12 @@ void NativeRenderQueueBuilder::addGpuDrivenResource(const scene::Camera *camera,
ccstd::pmr::string drawInstanceBuffer("CCDrawInstanceBuffer");
drawInstanceBuffer.append(std::to_string(cullingID));

const auto objectNameID = layoutGraph->attributeIndex.at("CCObjectBuffer");
data.bufferNames[objectNameID.value] = objectBuffer;

const auto instanceNameID = layoutGraph->attributeIndex.at("CCDrawInstanceBuffer");
data.bufferNames[instanceNameID.value] = drawInstanceBuffer;

auto &rasterPass = get(RasterPassTag{}, passID, *renderGraph);
if (rasterPass.computeViews.find(objectBuffer) == rasterPass.computeViews.end()) {
auto res = rasterPass.computeViews.emplace(
Expand Down
5 changes: 0 additions & 5 deletions native/cocos/renderer/pipeline/custom/NativeRenderQueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,6 @@ void GPUDrivenQueue::recordCommandBuffer(
auto indirectResID = findVertex(indirectName, resg);
const auto &indirectBuffer = get(ManagedBufferTag{}, indirectResID, resg).buffer.get();

ccstd::pmr::string instanceName("CCDrawInstanceBuffer", get_allocator());
instanceName.append(std::to_string(cullingID));
auto instanceResID = findVertex(instanceName, resg);
const auto &instanceBuffer = get(ManagedBufferTag{}, instanceResID, resg).buffer.get();

// Draw visible instances
const auto supportFirstInstance = device->getCapabilities().supportFirstInstance;
auto *batchPool = gpuScene->getBatchPool();
Expand Down
2 changes: 2 additions & 0 deletions native/cocos/renderer/pipeline/custom/RenderGraphTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,15 @@ RenderData::RenderData(const allocator_type& alloc) noexcept
buffers(alloc),
textures(alloc),
samplers(alloc),
bufferNames(alloc),
custom(alloc) {}

RenderData::RenderData(RenderData&& rhs, const allocator_type& alloc)
: constants(std::move(rhs.constants), alloc),
buffers(std::move(rhs.buffers), alloc),
textures(std::move(rhs.textures), alloc),
samplers(std::move(rhs.samplers), alloc),
bufferNames(std::move(rhs.bufferNames), alloc),
custom(std::move(rhs.custom), alloc) {}

RenderGraph::RenderGraph(const allocator_type& alloc) noexcept
Expand Down
1 change: 1 addition & 0 deletions native/cocos/renderer/pipeline/custom/RenderGraphTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ struct RenderData {
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Buffer>> buffers;
PmrUnorderedMap<uint32_t, IntrusivePtr<gfx::Texture>> textures;
PmrUnorderedMap<uint32_t, gfx::Sampler*> samplers;
PmrUnorderedMap<uint32_t, ccstd::pmr::string> bufferNames;
ccstd::pmr::string custom;
};

Expand Down

0 comments on commit feb3c36

Please sign in to comment.