Skip to content

Commit

Permalink
DXIL ControlFlow optimisations
Browse files Browse the repository at this point in the history
Lazy evaluate the connections map
  • Loading branch information
Zorro666 committed Dec 9, 2024
1 parent 89c5724 commit ca5c0e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
30 changes: 29 additions & 1 deletion renderdoc/driver/shaders/dxil/dxil_controlflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,23 @@ void ControlFlow::Construct(const rdcarray<rdcpair<uint32_t, uint32_t>> &links)
{
m_Connections[from].resize(maxBlockIndex);
for(uint32_t to = 0; to < maxBlockIndex; ++to)
m_Connections[from][to] = IsBlockConnected(from, to);
m_Connections[from][to] = ConnectionState::Unknown;
}

for(uint32_t p = 0; p < m_Paths.size(); ++p)
{
const BlockPath &path = m_Paths[p];
for(size_t i = 0; i < path.size() - 1; ++i)
{
uint32_t from = path[i];
for(size_t j = i + 1; j < path.size(); ++j)
{
uint32_t to = path[j];
if(to == PATH_END)
break;
m_Connections[from][to] = ConnectionState::Connected;
}
}
}

// A loop block is defined by any block which appears in any path starting from the block
Expand Down Expand Up @@ -446,6 +462,18 @@ uint32_t ControlFlow::GetNextUniformBlock(uint32_t from) const
}
return bestBlock;
}

bool ControlFlow::IsForwardConnection(uint32_t from, uint32_t to) const
{
if(m_Connections[from][to] == ConnectionState::Unknown)
{
if(IsBlockConnected(from, to))
m_Connections[from][to] = ConnectionState::Connected;
else
m_Connections[from][to] = ConnectionState::NotConnected;
}
return m_Connections[from][to] == ConnectionState::Connected;
}
}; // namespace DXIL

#if ENABLED(ENABLE_UNIT_TESTS)
Expand Down
11 changes: 9 additions & 2 deletions renderdoc/driver/shaders/dxil/dxil_controlflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,18 @@ struct ControlFlow
rdcarray<uint32_t> GetUniformBlocks() const { return m_UniformBlocks; }
rdcarray<uint32_t> GetLoopBlocks() const { return m_LoopBlocks; }
uint32_t GetNextUniformBlock(uint32_t from) const;
bool IsForwardConnection(uint32_t from, uint32_t to) const { return m_Connections[from][to]; }
bool IsForwardConnection(uint32_t from, uint32_t to) const;

private:
typedef rdcarray<uint32_t> BlockPath;

enum class ConnectionState : uint8_t
{
Unknown,
NotConnected,
Connected,
};

bool TraceBlockFlow(const uint32_t from, BlockPath &path);
bool BlockInAllPaths(uint32_t block, uint32_t pathIdx, int32_t startIdx) const;
int32_t BlockInAnyPath(uint32_t block, uint32_t pathIdx, int32_t startIdx, int32_t steps) const;
Expand All @@ -61,6 +68,6 @@ struct ControlFlow

rdcarray<uint32_t> m_UniformBlocks;
rdcarray<uint32_t> m_LoopBlocks;
rdcarray<rdcarray<bool>> m_Connections;
mutable rdcarray<rdcarray<ConnectionState>> m_Connections;
};
}; // namespace DXIL

0 comments on commit ca5c0e8

Please sign in to comment.