Shader: Add support for exported functions

This commit is contained in:
Jérôme Leclercq
2022-03-14 18:00:02 +01:00
parent 1c4ce75aa0
commit bf44672354
14 changed files with 170 additions and 67 deletions

View File

@@ -498,6 +498,9 @@ namespace Nz::ShaderAst
if (!Compare(lhs.entryStage, rhs.entryStage))
return false;
if (!Compare(lhs.isExported, rhs.isExported))
return false;
if (!Compare(lhs.name, rhs.name))
return false;

View File

@@ -31,10 +31,12 @@ namespace Nz::ShaderAst
struct Callbacks
{
std::function<void(DeclareFunctionStatement& funcNode)> onExportedFunc;
std::function<void(DeclareStructStatement& structNode)> onExportedStruct;
};
private:
void Visit(DeclareFunctionStatement& node) override;
void Visit(DeclareStructStatement& node) override;
const Callbacks* m_callbacks;

View File

@@ -27,6 +27,7 @@ namespace Nz::ShaderAst
inline const UsageSet& GetUsage() const;
inline void MarkFunctionAsUsed(std::size_t funcIndex);
inline void MarkStructAsUsed(std::size_t structIndex);
inline void Process(Statement& statement);

View File

@@ -12,6 +12,11 @@ namespace Nz::ShaderAst
return m_resolvedUsage;
}
inline void DependencyCheckerVisitor::MarkFunctionAsUsed(std::size_t funcIndex)
{
m_globalUsage.usedFunctions.UnboundedSet(funcIndex);
}
inline void DependencyCheckerVisitor::MarkStructAsUsed(std::size_t structIndex)
{
m_globalUsage.usedStructs.UnboundedSet(structIndex);

View File

@@ -335,6 +335,7 @@ namespace Nz::ShaderAst
ExpressionValue<ShaderStageType> entryStage;
ExpressionValue<ExpressionType> returnType;
ExpressionValue<bool> earlyFragmentTests;
ExpressionValue<bool> isExported;
};
struct NAZARA_SHADER_API DeclareOptionStatement : Statement

View File

@@ -74,7 +74,7 @@ namespace Nz
template<typename T1, typename T2, typename... Args> void Append(const T1& firstParam, const T2& secondParam, Args&&... params);
void AppendComment(const std::string& section);
void AppendCommentSection(const std::string& section);
void AppendFunctionDeclaration(const ShaderAst::DeclareFunctionStatement& node, bool forward = false);
void AppendFunctionDeclaration(const ShaderAst::DeclareFunctionStatement& node, const std::string& nameOverride, bool forward = false);
void AppendHeader();
void AppendLine(const std::string& txt = {});
template<typename... Args> void AppendLine(Args&&... params);