Remove legacy shader pass and artifact fallbacks

This commit is contained in:
2026-04-08 04:59:49 +08:00
parent 2c1c815072
commit efdd6bd68f
9 changed files with 186 additions and 273 deletions

View File

@@ -2,7 +2,6 @@
#include <XCEngine/Core/Asset/ArtifactFormats.h>
#include <XCEngine/Debug/Logger.h>
#include <XCEngine/Rendering/Builtin/BuiltinPassMetadataUtils.h>
#include <XCEngine/Resources/Material/MaterialLoader.h>
#include <XCEngine/Resources/Mesh/MeshLoader.h>
#include <XCEngine/Resources/Shader/ShaderLoader.h>
@@ -11,6 +10,7 @@
#include <algorithm>
#include <cctype>
#include <cstring>
#include <filesystem>
#include <fstream>
#include <sstream>
@@ -108,6 +108,22 @@ void AddUniqueDependencyPath(const fs::path& path,
}
}
bool IsCurrentShaderArtifactFile(const fs::path& artifactPath) {
std::ifstream input(artifactPath, std::ios::binary);
if (!input.is_open()) {
return false;
}
ShaderArtifactFileHeader header = {};
input.read(reinterpret_cast<char*>(&header), sizeof(header));
if (!input || input.gcount() != static_cast<std::streamsize>(sizeof(header))) {
return false;
}
return std::memcmp(header.magic, "XCSHD05", 7) == 0 &&
header.schemaVersion == kShaderArtifactSchemaVersion;
}
std::string TrimCopy(const std::string& text) {
const auto begin = std::find_if_not(text.begin(), text.end(), [](unsigned char ch) {
return std::isspace(ch) != 0;
@@ -425,19 +441,6 @@ Containers::String ResolveTextureBindingPath(
return NormalizeArtifactPathString(material.GetTextureBindingPath(bindingIndex));
}
Containers::String ResolveSerializedLegacyMaterialShaderPassHint(const Material& material) {
const Containers::String& shaderPass = material.GetLegacyShaderPassHint();
if (shaderPass.Empty()) {
return Containers::String();
}
if (Rendering::IsRedundantLegacyMaterialShaderPassHint(material.GetShader(), shaderPass)) {
return Containers::String();
}
return shaderPass;
}
bool WriteMaterialArtifactFile(
const fs::path& artifactPath,
const Material& material,
@@ -459,7 +462,6 @@ bool WriteMaterialArtifactFile(
material.GetShader() != nullptr
? material.GetShader()->GetPath()
: Containers::String());
WriteString(output, ResolveSerializedLegacyMaterialShaderPassHint(material));
MaterialArtifactHeader header;
header.renderQueue = material.GetRenderQueue();
@@ -1454,6 +1456,11 @@ bool AssetDatabase::ShouldReimport(const SourceAssetRecord& sourceRecord,
return true;
}
if (artifactRecord->resourceType == ResourceType::Shader &&
!IsCurrentShaderArtifactFile(artifactMainPath)) {
return true;
}
return artifactRecord->importerVersion != sourceRecord.importerVersion ||
artifactRecord->sourceHash != sourceRecord.sourceHash ||
artifactRecord->metaHash != sourceRecord.metaHash ||