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