Files
XCEngine/engine/src/Resources/Shader/ShaderAuthoringParser.cpp

76 lines
2.6 KiB
C++
Raw Normal View History

#include "ShaderAuthoringParser.h"
#include "Internal/ShaderAuthoringInternal.h"
namespace XCEngine {
namespace Resources {
ShaderAuthoringStyle DetectShaderAuthoringStyle(const std::string& sourceText) {
std::vector<std::string> lines;
Internal::SplitShaderAuthoringLines(sourceText, lines);
if (lines.empty() || !Internal::StartsWithKeyword(lines.front(), "Shader")) {
return ShaderAuthoringStyle::NotShaderAuthoring;
}
const bool hasBackendPragma = Internal::ContainsBackendPragma(lines);
const bool hasSingleSourceConstructs = Internal::ContainsSingleSourceAuthoringConstructs(lines);
if (hasBackendPragma && !hasSingleSourceConstructs) {
return ShaderAuthoringStyle::LegacyBackendSplit;
}
if (Internal::ContainsResourcesBlock(lines) || hasSingleSourceConstructs) {
return ShaderAuthoringStyle::UnityStyleSingleSource;
}
return ShaderAuthoringStyle::UnityStyleSingleSource;
}
void AppendAuthoringSourceBlock(
Containers::String& target,
const Containers::String& sourceBlock) {
Internal::AppendAuthoringSourceBlock(target, sourceBlock);
}
void CollectQuotedIncludeDependencyPaths(
const Containers::String& sourcePath,
const Containers::String& sourceText,
std::unordered_set<std::string>& seenPaths,
Containers::Array<Containers::String>& outDependencies) {
Internal::CollectQuotedIncludeDependencyPaths(sourcePath, sourceText, seenPaths, outDependencies);
}
Containers::String StripUnityStyleAuthoringPragmas(const Containers::String& sourceText) {
return Internal::StripUnityStyleAuthoringPragmas(sourceText);
}
std::vector<ShaderKeywordSet> BuildShaderKeywordVariantSets(
const Containers::Array<ShaderKeywordDeclaration>& declarations) {
return Internal::BuildShaderKeywordVariantSets(declarations);
}
Containers::String BuildKeywordVariantSource(
const Containers::String& baseSource,
const ShaderKeywordSet& requiredKeywords) {
return Internal::BuildKeywordVariantSource(baseSource, requiredKeywords);
}
bool ParseLegacyBackendSplitShaderAuthoring(
const Containers::String& path,
const std::string& sourceText,
ShaderIR& outDesc,
Containers::String* outError) {
return Internal::ParseLegacyBackendSplitShaderAuthoring(path, sourceText, outDesc, outError);
}
bool ParseUnityStyleSingleSourceShaderAuthoring(
const Containers::String& path,
const std::string& sourceText,
ShaderIR& outDesc,
Containers::String* outError) {
return Internal::ParseUnityStyleSingleSourceShaderAuthoring(path, sourceText, outDesc, outError);
}
} // namespace Resources
} // namespace XCEngine