Skip to content

Commit

Permalink
relax stalls, in case of indirect buffer update
Browse files Browse the repository at this point in the history
  • Loading branch information
Try committed Oct 9, 2024
1 parent 8ceb66d commit 0db60b0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
22 changes: 17 additions & 5 deletions game/graphics/drawcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void DrawCommands::addClusters(uint16_t cmdId, uint32_t meshletCount) {
cmd[cmdId].maxPayload += meshletCount;
}

bool DrawCommands::commit() {
bool DrawCommands::commit(Encoder<CommandBuffer>& enc, uint8_t fId) {
if(!cmdDurtyBit)
return false;
cmdDurtyBit = false;
Expand All @@ -154,13 +154,13 @@ bool DrawCommands::commit() {
const size_t visClustersSz = totalPayload*sizeof(uint32_t)*4;

auto& v = views[0];
bool cmdChg = true; //v.indirectCmd.byteSize()!=sizeof(IndirectCmd)*cmd.size();
bool cmdChg = v.indirectCmd.byteSize()!=sizeof(IndirectCmd)*cmd.size();
bool visChg = v.visClusters.byteSize()!=visClustersSz;
if(!layChg && !visChg) {
//return false;
}

std::vector<IndirectCmd> cx(cmd.size()+1);
std::vector<IndirectCmd> cx(cmd.size());
for(size_t i=0; i<cmd.size(); ++i) {
auto mesh = cmd[i].isMeshShader();

Expand All @@ -169,7 +169,6 @@ bool DrawCommands::commit() {
cx[i].firstVertex = mesh ? 1 : 0;
cx[i].firstInstance = mesh ? 1 : 0;
}
cx.back().writeOffset = uint32_t(totalPayload);

ord.resize(cmd.size());
for(size_t i=0; i<cmd.size(); ++i)
Expand All @@ -196,7 +195,20 @@ bool DrawCommands::commit() {
if(cmdChg) {
Resources::recycle(std::move(v.indirectCmd));
v.indirectCmd = device.ssbo(cx.data(), sizeof(IndirectCmd)*cx.size());
visChg |= (v.viewport==SceneGlobals::V_Vsm); //FIXME
visChg |= (v.viewport==SceneGlobals::V_Vsm);
}
else if(layChg) {
auto staging = device.ssbo(BufferHeap::Upload, cx.data(), sizeof(IndirectCmd)*cx.size());

auto& sh = Shaders::inst().copyBuf;
auto desc = device.descriptors(sh);
desc.set(0, v.indirectCmd);
desc.set(1, staging);
enc.setUniforms(sh, desc);
enc.dispatchThreads(staging.byteSize()/sizeof(uint32_t));

Resources::recycle(std::move(staging));
Resources::recycle(std::move(desc));
}

Resources::recycle(std::move(v.descInit));
Expand Down
2 changes: 1 addition & 1 deletion game/graphics/drawcommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DrawCommands {

const DrawCmd& operator[](size_t i) const { return cmd[i]; }

bool commit();
bool commit(Tempest::Encoder<Tempest::CommandBuffer>& enc, uint8_t fId);
uint16_t commandId(const Material& m, Type type, uint32_t bucketId);
void addClusters(uint16_t cmdId, uint32_t meshletCount);

Expand Down
2 changes: 1 addition & 1 deletion game/graphics/visualobjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void VisualObjects::prepareGlobals(Encoder<CommandBuffer>& enc, uint8_t fId) {
bool mem = instanceMem.commit(enc, fId);
bool buk = bucketsMem.commit(enc, fId);
bool cs = clusters.commit(enc, fId);
bool cmd = drawCmd.commit();
bool cmd = drawCmd.commit(enc, fId);

if(cs)
drawCmd.updateTasksUniforms();
Expand Down

0 comments on commit 0db60b0

Please sign in to comment.