载入中...
搜索中...
未找到
AssetCooker.cpp
浏览该文件的文档.
1#include "asset/AssetCooker.h"
2#include <algorithm>
3#include <functional>
4#include <map>
5#include <set>
6#include <tuple>
8#include "asset/AssetDiff.h"
15#include "asset/ShaderAsset.h"
16#include "data/HashFunction.h"
17
18// AssetCooker.cpp
19namespace eve::asset {
20namespace {
21
22std::array<std::uint8_t, 32> sha256(std::span<const std::uint8_t> bytes) {
24 data::HashFunction::getHashFunction("sha256")->hash("sha256", reinterpret_cast<const char*>(bytes.data()),
25 bytes.size(), digest);
26 std::array<std::uint8_t, 32> result{};
27 std::copy_n(reinterpret_cast<const std::uint8_t*>(digest.data), result.size(), result.begin());
28 return result;
29}
30
31void appendString(std::vector<std::uint8_t>& bytes, std::string_view text) {
32 const std::uint64_t size = text.size();
33 for (unsigned shift = 0; shift != 64; shift += 8) bytes.push_back(static_cast<std::uint8_t>(size >> shift));
34 bytes.insert(bytes.end(), text.begin(), text.end());
35}
36
37PersistentId buildIdentity(const EvaArchive& source, const AssetCookProfile& profile,
38 std::string_view canonicalManifest) {
39 std::vector<std::uint8_t> key;
40 appendString(key, "eve.asset-cooker/1");
41 appendString(key, evpackCodecBuildIdentity(profile.chunkCodec));
42 const auto packageBytes = source.manifest.packageId.bytes();
43 key.insert(key.end(), packageBytes.begin(), packageBytes.end());
44 appendString(key, canonicalManifest);
45 appendString(key, profile.variant.os);
46 appendString(key, profile.variant.arch);
47 appendString(key, profile.variant.graphics);
48 appendString(key, profile.variant.shaderFormat);
49 appendString(key, profile.variant.quality);
50 for (const auto& family : profile.variant.textureFamilies) appendString(key, family);
51 for (const auto& feature : profile.variant.features) appendString(key, feature);
52 for (unsigned shift = 0; shift != 32; shift += 8)
53 key.push_back(static_cast<std::uint8_t>(profile.bulkAlignment >> shift));
54 for (const auto& entry : source.entries) {
55 appendString(key, entry.path);
56 const auto hash = sha256(entry.bytes);
57 key.insert(key.end(), hash.begin(), hash.end());
58 }
59 auto digest = sha256(key);
61 std::copy_n(digest.begin(), bytes.size(), bytes.begin());
62 bytes[6] = static_cast<std::uint8_t>((bytes[6] & 0x0f) | 0x50);
63 bytes[8] = static_cast<std::uint8_t>((bytes[8] & 0x3f) | 0x80);
64 return PersistentId(bytes);
65}
66
67const Value* field(const Value::Object& object, std::string_view name) {
68 const auto found = object.find(std::string(name));
69 return found == object.end() ? nullptr : &found->second;
70}
71
72bool predicateText(const Value::Object& predicate, std::string_view name, std::string_view actual) {
73 const Value* value = field(predicate, name);
74 return !value || (value->isString() && value->asString() == actual);
75}
76
77bool platformDependencyApplies(const EvaDependency& dependency, const EvpackVariant& variant) {
78 if (dependency.kind != EvaDependencyKind::Platform) return true;
79 return predicateText(dependency.predicate, "os", variant.os) &&
80 predicateText(dependency.predicate, "arch", variant.arch) &&
81 predicateText(dependency.predicate, "graphics", variant.graphics) &&
82 predicateText(dependency.predicate, "quality", variant.quality);
83}
84
85Result<void> validatePublication(const EvaManifest& manifest, CookPublication publication) {
87 const Value* license = field(manifest.provenance, "license");
88 const auto* object = license ? license->getIf<Value::Object>() : nullptr;
89 const Value* redistribution = object ? field(*object, "redistribution") : nullptr;
90 if (!redistribution || !redistribution->isString() ||
91 (redistribution->asString() != "runtime-embedded" && redistribution->asString() != "project-only"))
93 "public Cook requires an explicit redistribution policy",
94 "$.provenance.license.redistribution", {}, "asset.cook"));
95 return Result<void>::success();
96}
97
98EvpackChunkKind kindForPath(std::string_view path) {
99 if (path.find("/stream/") != std::string_view::npos) return EvpackChunkKind::Stream;
100 if (path.find("/shaders/") != std::string_view::npos) return EvpackChunkKind::Shader;
102}
103
104Result<std::vector<std::uint8_t>> binaryDefinition(std::span<const std::uint8_t> json, std::uint64_t maximumBytes,
105 std::span<const EvaDependency> dependencies = {}) {
106 auto parsed = Value::fromJson(std::string_view(reinterpret_cast<const char*>(json.data()), json.size()));
107 if (!parsed) return Result<std::vector<std::uint8_t>>::failure(parsed.status());
108 auto* object = parsed.value().getIf<Value::Object>();
109 if (!object)
111 DiagnosticCode::ParseError, "runtime definition root must be an object", {}, {}, "asset.cook"));
112 Value::Array fallbacks;
113 for (const auto& dependency : dependencies) {
114 if (dependency.kind != EvaDependencyKind::RuntimeOptional) continue;
115 Value::Object fallback;
116 fallback["path"] = Value(dependency.path);
117 fallback["to"] = Value(dependency.to.format());
118 fallback["expectedType"] = Value(dependency.expectedType);
119 fallback["policy"] = Value(dependency.fallback);
120 fallbacks.emplace_back(std::move(fallback));
121 }
122 if (!fallbacks.empty()) (*object)["dependencyFallbacks"] = Value(std::move(fallbacks));
124 limits.maximumBytes = maximumBytes;
125 return encodeRuntimeDefinition(parsed.value(), limits);
126}
127
128} // namespace
129
131 AssetCookProfile profile;
133 if (target == "windows-x86_64-vulkan")
134 profile.variant = {"windows", "x86_64", "vulkan", {"bc", "rgba8"}, "spirv-1.6", "high", {}};
135 else if (target == "linux-x86_64-vulkan")
136 profile.variant = {"linux", "x86_64", "vulkan", {"bc", "rgba8"}, "spirv-1.6", "high", {}};
137 else if (target == "macos-arm64-vulkan")
138 profile.variant = {"macos", "arm64", "vulkan", {"rgba8"}, "spirv-1.6", "high", {}};
139 else if (target == "android-arm64-vulkan")
140 profile.variant = {"android", "arm64", "vulkan", {"astc", "etc2", "rgba8"}, "spirv-1.6", "high", {}};
141 else if (target == "ios-arm64-vulkan")
142 profile.variant = {"ios", "arm64", "vulkan", {"astc", "rgba8"}, "spirv-1.6", "high", {}};
143 else if (target == "web-wasm32-webgpu")
144 profile.variant = {"web", "wasm32", "webgpu", {"rgba8"}, "wgsl-1", "high", {}};
145 else
147 DiagnosticCode::Unsupported, "unknown asset Cook target", std::string(target), {}, "asset.cook"));
148 return Result<AssetCookProfile>::success(std::move(profile));
149}
150
152 const EvaArchiveLimits& evaLimits, const EvpackLimits& evpackLimits) {
153 auto migrated = migrateEvaArchive(source, evaLimits);
154 if (!migrated) return Result<AssetCookReceipt>::failure(migrated.status());
155 auto rebuilt = buildEvaArchive(migrated.value().manifest, migrated.value().entries, evaLimits);
156 if (!rebuilt) return Result<AssetCookReceipt>::failure(rebuilt.status());
157 auto admitted = parseEvaArchive(rebuilt.value(), evaLimits);
158 if (!admitted) return Result<AssetCookReceipt>::failure(admitted.status());
159 EvaArchive canonical = std::move(admitted).takeValue();
160 EvaManifest dependencyManifest = canonical.manifest;
161 std::erase_if(dependencyManifest.dependencies, [&](const EvaDependency& dependency) {
162 return dependency.kind == EvaDependencyKind::Platform &&
163 !platformDependencyApplies(dependency, profile.variant);
164 });
165 auto dependencyValidation = validateEvaDependencies(dependencyManifest, profile.availableDependencies);
166 if (!dependencyValidation) return Result<AssetCookReceipt>::failure(dependencyValidation.status());
167 auto canonicalManifest = serializeEvaManifest(canonical.manifest);
168 if (!canonicalManifest) return Result<AssetCookReceipt>::failure(canonicalManifest.status());
169 auto publication = validatePublication(canonical.manifest, profile.publication);
170 if (!publication) return Result<AssetCookReceipt>::failure(publication.status());
171
172 std::map<PersistentId, std::vector<PersistentId>> runtimeDependencies;
173 for (const auto& dependency : canonical.manifest.dependencies) {
174 if (dependency.kind == EvaDependencyKind::RuntimeOptional || dependency.kind == EvaDependencyKind::Build ||
175 dependency.kind == EvaDependencyKind::Editor || dependency.kind == EvaDependencyKind::Source ||
176 !platformDependencyApplies(dependency, profile.variant))
177 continue;
178 const bool present = std::binary_search(dependencyValidation.value().presentAssets.begin(),
179 dependencyValidation.value().presentAssets.end(), dependency.to.id());
180 if (present) runtimeDependencies[dependency.from.id()].push_back(dependency.to.id());
181 }
182 for (auto& [asset, dependencies] : runtimeDependencies) {
183 (void)asset;
184 std::sort(dependencies.begin(), dependencies.end());
185 dependencies.erase(std::unique(dependencies.begin(), dependencies.end()), dependencies.end());
186 }
187
189 build.packageId = canonical.manifest.packageId;
190 build.buildId = buildIdentity(canonical, profile, canonicalManifest.value());
191 build.variants.push_back(profile.variant);
192 for (const auto& asset : canonical.manifest.assets) {
193 std::vector<EvaDependency> assetDependencyPolicies;
194 for (const auto& dependency : canonical.manifest.dependencies)
195 if (dependency.from.id() == asset.asset.id() && platformDependencyApplies(dependency, profile.variant))
196 assetDependencyPolicies.push_back(dependency);
197 const auto definition =
198 std::lower_bound(canonical.entries.begin(), canonical.entries.end(), asset.definition,
199 [](const EvaArchiveEntry& entry, std::string_view path) { return entry.path < path; });
200 if (definition == canonical.entries.end() || definition->path != asset.definition)
202 DiagnosticCode::NotFound, "asset definition is missing", asset.definition, {}, "asset.cook"));
203 const auto dependencies = runtimeDependencies[asset.asset.id()];
204 if (asset.type == "eve.shader") {
205 if (profile.variant.graphics != "vulkan" || profile.variant.shaderFormat != "spirv-1.6")
207 Diagnostic::error(DiagnosticCode::Unsupported, "eve.shader/1 requires Vulkan SPIR-V 1.6 target",
208 asset.definition, {}, "asset.cook"));
209 auto value = Value::fromJson(
210 std::string_view(reinterpret_cast<const char*>(definition->bytes.data()), definition->bytes.size()));
211 if (!value) return Result<AssetCookReceipt>::failure(value.status());
212 auto shader = decodeShaderAsset(value.value());
213 if (!shader) return Result<AssetCookReceipt>::failure(shader.status());
214 const std::string shaderPrefix = "assets/" + asset.asset.id().format() + "/";
215 if (!assetDependencyPolicies.empty() ||
216 std::any_of(canonical.entries.begin(), canonical.entries.end(), [&](const EvaArchiveEntry& entry) {
217 return entry.path.starts_with(shaderPrefix) && entry.path != asset.definition;
218 }))
220 "eve.shader/1 must be self-contained",
221 asset.definition, {}, "asset.cook"));
222 }
223 if (asset.type == "eve.image") {
224 if (std::find(profile.variant.textureFamilies.begin(), profile.variant.textureFamilies.end(), "rgba8") ==
225 profile.variant.textureFamilies.end())
227 DiagnosticCode::Unsupported, "eve.image/3 requires an explicit rgba8 target texture family",
228 asset.definition, {}, "asset.cook"));
229 auto parsedDefinition = Value::fromJson(
230 std::string_view(reinterpret_cast<const char*>(definition->bytes.data()), definition->bytes.size()));
231 if (!parsedDefinition) return Result<AssetCookReceipt>::failure(parsedDefinition.status());
232 const auto* definitionObject = parsedDefinition.value().getIf<Value::Object>();
233 const Value* blobValue = definitionObject ? field(*definitionObject, "blob") : nullptr;
234 if (!blobValue || !blobValue->isString())
236 "eve.image/3 source blob path is missing",
237 asset.definition, {}, "asset.cook"));
238 const auto sourceBlob =
239 std::lower_bound(canonical.entries.begin(), canonical.entries.end(), blobValue->asString(),
240 [](const EvaArchiveEntry& entry, std::string_view path) { return entry.path < path; });
241 if (sourceBlob == canonical.entries.end() || sourceBlob->path != blobValue->asString())
243 "eve.image/3 source blob is missing",
244 blobValue->asString(), {}, "asset.cook"));
245 auto image = cookCanonicalImageRgba8(definition->bytes, sourceBlob->bytes, evpackLimits.maximumChunkBytes);
246 if (!image) return Result<AssetCookReceipt>::failure(image.status());
247 auto runtimeDefinition =
248 binaryDefinition(image.value().definition, evpackLimits.maximumChunkBytes, assetDependencyPolicies);
249 if (!runtimeDefinition) return Result<AssetCookReceipt>::failure(runtimeDefinition.status());
250 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Definition,
251 0, profile.chunkCodec, 8, dependencies, std::move(runtimeDefinition).takeValue()});
252 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Bulk, 1,
253 EvpackCodec::None, profile.bulkAlignment, dependencies,
254 std::move(image).takeValue().bulk});
255 continue;
256 }
257 if (asset.type == "eve.volume-texture") {
258 if (std::find(profile.variant.textureFamilies.begin(), profile.variant.textureFamilies.end(), "rgba8") ==
259 profile.variant.textureFamilies.end())
262 "eve.volume-texture/1 requires an explicit rgba8 target texture family",
263 asset.definition, {}, "asset.cook"));
264 auto parsedDefinition = Value::fromJson(
265 std::string_view(reinterpret_cast<const char*>(definition->bytes.data()), definition->bytes.size()));
266 if (!parsedDefinition) return Result<AssetCookReceipt>::failure(parsedDefinition.status());
267 const auto* definitionObject = parsedDefinition.value().getIf<Value::Object>();
268 const Value* blobValue = definitionObject ? field(*definitionObject, "blob") : nullptr;
269 if (!blobValue || !blobValue->isString())
271 Diagnostic::error(DiagnosticCode::ParseError, "eve.volume-texture/1 source blob path is missing",
272 asset.definition, {}, "asset.cook"));
273 const auto sourceBlob =
274 std::lower_bound(canonical.entries.begin(), canonical.entries.end(), blobValue->asString(),
275 [](const EvaArchiveEntry& entry, std::string_view path) { return entry.path < path; });
276 if (sourceBlob == canonical.entries.end() || sourceBlob->path != blobValue->asString())
278 Diagnostic::error(DiagnosticCode::NotFound, "eve.volume-texture/1 source blob is missing",
279 blobValue->asString(), {}, "asset.cook"));
280 auto volume =
281 cookCanonicalVolumeTextureRgba8(definition->bytes, sourceBlob->bytes, evpackLimits.maximumChunkBytes);
282 if (!volume) return Result<AssetCookReceipt>::failure(volume.status());
283 auto runtimeDefinition =
284 binaryDefinition(volume.value().definition, evpackLimits.maximumChunkBytes, assetDependencyPolicies);
285 if (!runtimeDefinition) return Result<AssetCookReceipt>::failure(runtimeDefinition.status());
286 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Definition,
287 0, profile.chunkCodec, 8, dependencies, std::move(runtimeDefinition).takeValue()});
288 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Bulk, 1,
289 EvpackCodec::None, profile.bulkAlignment, dependencies,
290 std::move(volume).takeValue().bulk});
291 continue;
292 }
293 if (asset.type == "eve.pcg-graph") {
294 auto pcg = cookCanonicalPcgGraph(definition->bytes, 4096, evpackLimits.maximumChunkBytes);
295 if (!pcg) return Result<AssetCookReceipt>::failure(pcg.status());
296 auto runtimeDefinition =
297 binaryDefinition(pcg.value().definition, evpackLimits.maximumChunkBytes, assetDependencyPolicies);
298 if (!runtimeDefinition) return Result<AssetCookReceipt>::failure(runtimeDefinition.status());
299 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Definition,
300 0, profile.chunkCodec, 8, dependencies, std::move(runtimeDefinition).takeValue()});
301 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Bulk, 1,
302 profile.chunkCodec, profile.bulkAlignment, dependencies,
303 std::move(pcg).takeValue().executionPlan});
304 continue;
305 }
306 auto runtimeDefinition =
307 binaryDefinition(definition->bytes, evpackLimits.maximumChunkBytes, assetDependencyPolicies);
308 if (!runtimeDefinition) return Result<AssetCookReceipt>::failure(runtimeDefinition.status());
309 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, EvpackChunkKind::Definition, 0,
310 profile.chunkCodec, 8, dependencies, std::move(runtimeDefinition).takeValue()});
311 const std::string prefix = "assets/" + asset.asset.id().format() + "/";
312 std::uint32_t chunkId = 1;
313 for (const auto& entry : canonical.entries) {
314 if (entry.path == asset.definition || !entry.path.starts_with(prefix)) continue;
315 build.chunks.push_back({asset.asset.id(), asset.type, asset.schemaVersion, 0, kindForPath(entry.path),
316 chunkId++, profile.chunkCodec, profile.bulkAlignment, dependencies, entry.bytes});
317 }
318 }
319 const std::uint32_t chunkCount = static_cast<std::uint32_t>(build.chunks.size());
320 const PersistentId buildId = build.buildId;
321 auto packageBytes = buildEvpack(std::move(build), evpackLimits);
322 if (!packageBytes) return Result<AssetCookReceipt>::failure(packageBytes.status());
323 auto verified = parseEvpack(packageBytes.value(), evpackLimits);
324 if (!verified) return Result<AssetCookReceipt>::failure(verified.status());
326 {canonical.manifest.packageId, buildId, chunkCount, std::move(packageBytes).takeValue()});
327}
328
329} // namespace eve::asset
330
331// AssetDependency.cpp
332namespace eve::asset {
333namespace {
334bool requiresPresence(EvaDependencyKind kind) {
337}
338bool validFallback(const EvaDependency& dependency) {
339 if (dependency.kind != EvaDependencyKind::RuntimeOptional) return dependency.fallback.empty();
340 const auto behavior = dependency.fallback.find("behavior");
341 const auto observable = dependency.fallback.find("observableCode");
342 if (behavior == dependency.fallback.end() || !behavior->second.isString() ||
343 observable == dependency.fallback.end() || !observable->second.isString() ||
344 observable->second.asString().empty())
345 return false;
346 const std::string& name = behavior->second.asString();
347 const auto asset = dependency.fallback.find("asset");
348 if (name == "use-asset")
349 return asset != dependency.fallback.end() && asset->second.isString() &&
350 AssetRef::parse(asset->second.asString()).ok();
351 return (name == "omit-feature" || name == "use-default") && asset == dependency.fallback.end();
352}
353} // namespace
354
356 std::span<const AvailableAssetDependency> available) {
357 using TypeIdentity = std::pair<std::string, SchemaVersion>;
358 std::map<PersistentId, TypeIdentity> types;
359 std::set<PersistentId> local;
360 for (const auto& asset : manifest.assets) {
361 types.emplace(asset.asset.id(), TypeIdentity{asset.type, asset.schemaVersion});
362 local.emplace(asset.asset.id());
363 }
364 for (const auto& external : available) {
365 if (external.asset.id().isNil() || external.type.empty() || external.schemaVersion.isZero())
367 DiagnosticCode::InvalidArgument, "external dependency fact is invalid", {}, {}, "asset.dependency"));
368 const auto [found, inserted] =
369 types.emplace(external.asset.id(), TypeIdentity{external.type, external.schemaVersion});
370 if (!inserted && found->second != TypeIdentity{external.type, external.schemaVersion})
372 Diagnostic::error(DiagnosticCode::TypeMismatch, "dependency resolver reports conflicting types",
373 external.asset.format(), {}, "asset.dependency"));
374 }
375 for (const auto& [name, entrypoint] : manifest.entrypoints)
376 if (!local.contains(entrypoint.id()))
377 return Result<EvaDependencyValidation>::failure(
378 Diagnostic::error(DiagnosticCode::NotFound, "entrypoint does not resolve to a local asset", name, {},
379 "asset.dependency"));
380
381 using EdgeKey = std::tuple<PersistentId, PersistentId, EvaDependencyKind, std::string>;
382 std::set<EdgeKey> edges;
383 std::map<PersistentId, std::vector<PersistentId>> graph;
384 EvaDependencyValidation result;
385 for (const auto& dependency : manifest.dependencies) {
386 if (!validFallback(dependency))
388 "dependency fallback policy is invalid",
389 dependency.path, {}, "asset.dependency"));
390 if (!local.contains(dependency.from.id()))
392 Diagnostic::error(DiagnosticCode::NotFound, "dependency source is not locally authoritative",
393 dependency.from.format(), {}, "asset.dependency"));
394 if (!edges.emplace(dependency.from.id(), dependency.to.id(), dependency.kind, dependency.path).second)
396 DiagnosticCode::Conflict, "duplicate dependency edge", dependency.path, {}, "asset.dependency"));
397 const auto target = types.find(dependency.to.id());
398 if (target == types.end()) {
399 if (requiresPresence(dependency.kind))
401 Diagnostic::error(DiagnosticCode::NotFound, "required dependency is unavailable",
402 dependency.to.format(), {}, "asset.dependency"));
403 result.omittedOptionalAssets.push_back(dependency.to.id());
404 continue;
405 }
406 const std::string resolvedType = target->second.first + "/" + std::to_string(target->second.second.value());
407 if (!dependency.expectedType.empty() && resolvedType != dependency.expectedType)
409 Diagnostic::error(DiagnosticCode::TypeMismatch, "dependency resolved to the wrong asset type",
410 dependency.path, {}, "asset.dependency"));
411 result.presentAssets.push_back(dependency.to.id());
412 if (dependency.kind == EvaDependencyKind::RuntimeRequired && local.contains(dependency.to.id()))
413 graph[dependency.from.id()].push_back(dependency.to.id());
414 }
415
416 enum class Mark : std::uint8_t { Visiting, Complete };
417 std::map<PersistentId, Mark> marks;
418 std::function<Result<void>(const PersistentId&)> visit = [&](const PersistentId& node) -> Result<void> {
419 const auto marked = marks.find(node);
420 if (marked != marks.end()) {
421 if (marked->second == Mark::Visiting)
423 "runtime-required dependency cycle detected",
424 node.format(), {}, "asset.dependency"));
425 return Result<void>::success();
426 }
427 marks.emplace(node, Mark::Visiting);
428 auto& targets = graph[node];
429 std::sort(targets.begin(), targets.end());
430 for (const auto& target : targets) {
431 auto nested = visit(target);
432 if (!nested) return nested;
433 }
434 marks[node] = Mark::Complete;
435 return Result<void>::success();
436 };
437 for (const auto& id : local) {
438 auto visited = visit(id);
439 if (!visited) return Result<EvaDependencyValidation>::failure(visited.status());
440 }
441 std::sort(result.presentAssets.begin(), result.presentAssets.end());
442 result.presentAssets.erase(std::unique(result.presentAssets.begin(), result.presentAssets.end()),
443 result.presentAssets.end());
444 std::sort(result.omittedOptionalAssets.begin(), result.omittedOptionalAssets.end());
445 result.omittedOptionalAssets.erase(
446 std::unique(result.omittedOptionalAssets.begin(), result.omittedOptionalAssets.end()),
447 result.omittedOptionalAssets.end());
449}
450} // namespace eve::asset
451
452// AssetDiff.cpp
453namespace eve::asset {
454namespace {
455using DependencyKey =
456 std::tuple<PersistentId, PersistentId, EvaDependencyKind, std::string, std::string, std::string, std::string>;
457Result<std::set<DependencyKey>> dependencyKeys(const EvaManifest& manifest) {
458 std::set<DependencyKey> result;
459 for (const auto& value : manifest.dependencies) {
460 auto predicate = Value(value.predicate).toJson();
461 if (!predicate) return Result<std::set<DependencyKey>>::failure(predicate.status());
462 auto fallback = Value(value.fallback).toJson();
463 if (!fallback) return Result<std::set<DependencyKey>>::failure(fallback.status());
464 result.emplace(value.from.id(), value.to.id(), value.kind, value.path, value.expectedType,
465 std::move(predicate).takeValue(), std::move(fallback).takeValue());
466 }
467 return Result<std::set<DependencyKey>>::success(std::move(result));
468}
469} // namespace
470
472 std::map<PersistentId, const EvaAssetEntry*> left, right;
473 for (const auto& asset : before.assets) left.emplace(asset.asset.id(), &asset);
474 for (const auto& asset : after.assets) right.emplace(asset.asset.id(), &asset);
476 for (const auto& [id, asset] : left) {
477 const auto found = right.find(id);
478 if (found == right.end()) {
479 result.assets.push_back(
480 {id, EvaAssetChangeKind::Removed, asset->type, asset->schemaVersion, asset->contentHash, {}, {}, {}});
481 } else if (asset->type != found->second->type || asset->schemaVersion != found->second->schemaVersion ||
482 asset->contentHash != found->second->contentHash) {
483 result.assets.push_back({id, EvaAssetChangeKind::Changed, asset->type, asset->schemaVersion,
484 asset->contentHash, found->second->type, found->second->schemaVersion,
485 found->second->contentHash});
486 }
487 }
488 for (const auto& [id, asset] : right)
489 if (!left.contains(id))
490 result.assets.push_back(
491 {id, EvaAssetChangeKind::Added, {}, {}, {}, asset->type, asset->schemaVersion, asset->contentHash});
492 std::sort(result.assets.begin(), result.assets.end(),
493 [](const auto& a, const auto& b) { return a.assetId < b.assetId; });
494 const auto leftDependencies = dependencyKeys(before);
495 if (!leftDependencies) return Result<EvaPackageDiff>::failure(leftDependencies.status());
496 const auto rightDependencies = dependencyKeys(after);
497 if (!rightDependencies) return Result<EvaPackageDiff>::failure(rightDependencies.status());
498 std::vector<DependencyKey> added, removed;
499 std::set_difference(rightDependencies.value().begin(), rightDependencies.value().end(),
500 leftDependencies.value().begin(), leftDependencies.value().end(), std::back_inserter(added));
501 std::set_difference(leftDependencies.value().begin(), leftDependencies.value().end(),
502 rightDependencies.value().begin(), rightDependencies.value().end(),
503 std::back_inserter(removed));
504 result.addedDependencies = static_cast<std::uint32_t>(added.size());
505 result.removedDependencies = static_cast<std::uint32_t>(removed.size());
506 result.entrypointsChanged = before.entrypoints != after.entrypoints;
507 return Result<EvaPackageDiff>::success(std::move(result));
508}
509} // namespace eve::asset
LogicalId target
Deterministic canonical .eva to capability-targeted .evpack Cook.
Typed dependency closure validation for `.eva`.
Deterministic semantic comparison of two `.eva` manifests.
Transactional migrations for canonical definitions stored in .eva.
double volume
std::string variant
Safe source-image conversion to runtime EVIMG payloads.
Canonical PCG graph compilation to runtime execution plans.
Bounded R8 volume conversion to runtime EVVOL.
SQObjectPtr key
Definition ECS.cpp:155
std::string name
Definition ECS.cpp:154
Bounded deterministic compression used by the .evpack wire format.
std::vector< FieldTarget > targets
vk::UniqueImage image
HexVec3 left
HexVec3 right
std::string local
bool present
std::vector< Edge > edges
std::string id
Poco::JSON::Object::Ptr result
std::uint64_t bytes
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
std::string error
Definition Package.cpp:174
std::map< std::string, std::vector< std::string > > graph
Definition Package.cpp:173
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
std::string hash
std::string build
Shader * shader
const RoadNode * node
bool found
JSON-free versioned runtime metadata codec.
int removed
std::string text
std::string_view source
std::string kind
std::string digest
float size
Definition TreeMesh.cpp:158
const AssetImportLimits & limits
const PersistentId & id() const noexcept
Return the stable asset identity.
Definition ResourceRef.h:65
static Result< AssetRef > parse(std::string_view text)
Parse an asset://<canonical UUID> reference.
std::string format() const
Return canonical asset://<uuid> text.
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
The canonical owning dynamic value used by data-facing protocols.
Definition Value.h:31
const std::string & asString() const
Return the string payload; the caller must have checked the kind.
Definition Value.cpp:207
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:177
std::map< std::string, Value > Object
Definition Value.h:34
bool isString() const noexcept
Return true when this value is a string.
Definition Value.h:106
std::vector< Value > Array
Definition Value.h:33
const T * getIf() const noexcept
Return a typed pointer, or nullptr when the kind differs.
Definition Value.h:209
static HashFunction * getHashFunction(std::string function)
Get a HashFunction instance for the given function.
virtual void hash(std::string function, const char *input, uint64_t length, Value &output) const =0
Hash the input, producing an set of bytes as output.
Id128 public API.
Definition Identity.h:111
std::array< std::uint8_t, 16 > Bytes
Definition Identity.h:113
Result< Evpack > parseEvpack(std::span< const std::uint8_t > bytes, const EvpackLimits &limits, const EvpackTrust &trust)
Parse, bound-check and hash-verify a complete untrusted .evpack.
Definition Evpack.cpp:542
Result< CookedCanonicalVolumeTexture > cookCanonicalVolumeTextureRgba8(std::span< const uint8_t > definition, std::span< const uint8_t > sourceR8, uint64_t maximumDecodedBytes)
Result< std::vector< std::uint8_t > > buildEvaArchive(const EvaManifest &manifest, std::vector< EvaArchiveEntry > entries, const EvaArchiveLimits &limits)
Build a deterministic ZIP64 .eva, selecting raw Deflate only when smaller than Store.
std::string evpackCodecBuildIdentity(EvpackCodec codec)
Stable codec implementation identity included in deterministic Cook keys.
Result< std::vector< std::uint8_t > > buildEvpack(EvpackBuild build, const EvpackLimits &limits)
Build deterministic little-endian .evpack bytes from validated Cook output.
Definition Evpack.cpp:248
Result< CookedCanonicalImage > cookCanonicalImageRgba8(std::span< const std::uint8_t > definition, std::span< const std::uint8_t > encodedSource, std::uint64_t maximumDecodedBytes)
Decode image/2 base images or image/3 explicit linear RGBA8 mip chains into bounded EVIMG.
Result< EvaArchive > parseEvaArchive(std::span< const std::uint8_t > bytes, const EvaArchiveLimits &limits)
Parse and fully verify an untrusted .eva ZIP64 image.
Result< EvaPackageDiff > diffEvaManifests(const EvaManifest &before, const EvaManifest &after)
Compare two admitted manifests without using paths, timestamps or archive order.
CookPublication
Publication policy controls license admission without making legal inferences.
Definition AssetCooker.h:17
Result< AssetCookReceipt > cookEvaToEvpack(const EvaArchive &source, const AssetCookProfile &profile, const EvaArchiveLimits &evaLimits, const EvpackLimits &evpackLimits)
Cook an admitted source archive into one target-specific runtime pack.
Result< EvaArchive > migrateEvaArchive(EvaArchive source, const EvaArchiveLimits &limits)
Migrate every definition in an owning archive to its current schema.
EvaDependencyKind
Dependency role recorded by a source asset archive.
Definition EvaManifest.h:21
Result< CookedCanonicalPcgGraph > cookCanonicalPcgGraph(std::span< const std::uint8_t > definition, std::uint32_t maximumRules, std::uint64_t maximumPlanBytes)
Compile eve.pcg-graph/1 terrain scatter rules to a bounded PointGraph plan.
Result< AssetCookProfile > assetCookProfileForTarget(std::string_view target)
Resolve a stable CLI/tool target name to its exact capability profile.
Result< std::vector< std::uint8_t > > encodeRuntimeDefinition(const Value &value, const RuntimeDefinitionLimits &limits)
Encode an owning metadata tree as deterministic EVDEF\0\1 bytes.
Result< std::string > serializeEvaManifest(const EvaManifest &manifest)
Serialize a validated manifest as deterministic compact JSON.
Result< ShaderAsset > decodeShaderAsset(const Value &definition, const ShaderAssetLimits &limits)
Decode strict eve.shader/1 metadata with SPIR-V 1.0 through 1.6 stages.
Result< EvaDependencyValidation > validateEvaDependencies(const EvaManifest &manifest, std::span< const AvailableAssetDependency > available)
Validate local/external references, expected types and required-edge acyclicity.
EvpackChunkKind
Semantic role of a runtime chunk.
Definition Evpack.h:26
std::variant< std::monostate, std::int64_t, double, std::string, bool > Value
Definition Database.h:27
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
@ TypeMismatch
A stable reference resolved to a different canonical domain type.
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:253
Explicit deterministic target profile for one runtime variant.
Definition AssetCooker.h:23
std::vector< AvailableAssetDependency > availableDependencies
Definition AssetCooker.h:28
CookPublication publication
Definition AssetCooker.h:25
One owning regular-file entry inside an .eva archive.
Definition EvaArchive.h:31
std::vector< std::uint8_t > bytes
Definition EvaArchive.h:33
Admission budgets applied before allocating decoded archive entries.
Definition EvaArchive.h:21
Fully admitted source archive with its typed manifest and payloads.
Definition EvaArchive.h:37
std::vector< EvaArchiveEntry > entries
Definition EvaArchive.h:39
One directed dependency between stable asset identities.
Definition EvaManifest.h:44
Value::Object fallback
Required observable behavior when a runtime-optional target is unavailable.
Definition EvaManifest.h:52
EvaDependencyKind kind
Definition EvaManifest.h:47
Validated, owning .eva manifest.
Definition EvaManifest.h:62
std::vector< EvaAssetEntry > assets
Definition EvaManifest.h:69
std::vector< EvaDependency > dependencies
Definition EvaManifest.h:70
Value::Object provenance
Definition EvaManifest.h:72
Deterministically ordered semantic package difference.
Definition AssetDiff.h:27
std::vector< EvaAssetChange > assets
Definition AssetDiff.h:28
Complete input to deterministic .evpack assembly.
Definition Evpack.h:117
PersistentId packageId
Definition Evpack.h:118
Resource limits checked before package allocations and hash work.
Definition Evpack.h:126
std::uint64_t maximumChunkBytes
Definition Evpack.h:128
Capability-addressed runtime representation; list order is fallback order.
Definition Evpack.h:81
std::string quality
Definition Evpack.h:87
std::string shaderFormat
Definition Evpack.h:86
std::vector< std::string > features
Definition Evpack.h:88
std::vector< std::string > textureFamilies
Definition Evpack.h:85
std::string graphics
Definition Evpack.h:84
Structural and allocation limits for untrusted EVDEF metadata.