载入中...
搜索中...
未找到
Evpack.cpp
浏览该文件的文档.
32 for (unsigned shift = 0; shift != 32; shift += 8) bytes.push_back(static_cast<std::uint8_t>(value >> shift));
35 for (unsigned shift = 0; shift != 64; shift += 8) bytes.push_back(static_cast<std::uint8_t>(value >> shift));
112 for (unsigned index = 0; index != 4; ++index) value |= std::uint32_t(data[index]) << (index * 8);
119 for (unsigned index = 0; index != 8; ++index) value |= std::uint64_t(data[index]) << (index * 8);
162 putString(bytes, variant.os); putString(bytes, variant.arch); putString(bytes, variant.graphics);
185 put64(bytes, record.offset); put64(bytes, record.stored.size()); put64(bytes, input.bytes.size());
200 variant.graphics != capabilities.graphics || !contains(capabilities.shaderFormats, variant.shaderFormat) ||
204 [&](const auto& family) { return contains(capabilities.textureFamilies, family); })) return false;
213 DiagnosticCode::InvalidArgument, "signature algorithm identifier is invalid", {}, {}, "asset.evpack"));
226 DiagnosticCode::ParseError, "runtime package signature block is invalid", {}, {}, "asset.evpack"));
230 DiagnosticCode::ParseError, "runtime package signature algorithm is empty", {}, {}, "asset.evpack"));
231 if (std::any_of(terminator, bytes.begin() + 24, [](std::uint8_t value) { return value != 0; }) ||
234 DiagnosticCode::ParseError, "runtime package signature padding is not canonical", {}, {}, "asset.evpack"));
240 DiagnosticCode::ParseError, "runtime package signature algorithm is invalid", {}, {}, "asset.evpack"));
251 DiagnosticCode::InvalidArgument, "packageId and buildId must be non-nil", {}, {}, "asset.evpack"));
255 DiagnosticCode::InvalidArgument, "variant or chunk count is outside limits", {}, {}, "asset.evpack"));
262 DiagnosticCode::InvalidArgument, "variant contains invalid capability text", {}, {}, "asset.evpack"));
268 if (input.assetId.isNil() || !validText(input.type, limits) || input.schemaVersion.value() == 0 ||
276 Diagnostic::error(DiagnosticCode::InvalidArgument, "chunk metadata or resource budget is invalid",
280 return Result<std::vector<std::uint8_t>>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,
284 if (std::adjacent_find(input.dependencies.begin(), input.dependencies.end()) != input.dependencies.end())
286 DiagnosticCode::Conflict, "chunk dependencies contain duplicates", input.type, {}, "asset.evpack"));
298 std::sort(records.begin(), records.end(), [](const BuildRecord& left, const BuildRecord& right) {
299 return std::tie(left.input.assetId, left.input.type, left.input.schemaVersion, left.input.variantIndex,
301 std::tie(right.input.assetId, right.input.type, right.input.schemaVersion, right.input.variantIndex,
311 Diagnostic::error(DiagnosticCode::Conflict, "duplicate runtime chunk key", records[index].input.type,
317 if (manifest.size() > limits.maximumMetadataBytes || preliminaryToc.size() > limits.maximumMetadataBytes ||
320 DiagnosticCode::InvalidArgument, "runtime package metadata exceeds size limits", {}, {}, "asset.evpack"));
325 !checkedAdd(record.offset, record.stored.size(), cursor) || cursor > limits.maximumPackageBytes)
327 DiagnosticCode::InvalidArgument, "encoded package exceeds size limits", {}, {}, "asset.evpack"));
361Result<Evpack> parseEvpackMetadata(std::span<const std::uint8_t> bytes, std::uint64_t packageSize,
366 Diagnostic::error(DiagnosticCode::ParseError, "package size is outside limits", {}, {}, "asset.evpack"));
372 std::uint64_t tocOffset = 0, tocSize = 0, manifestOffset = 0, manifestSize = 0, signatureOffset = 0,
378 !header.id(packageId) || !header.id(buildId) || !header.u64(tocOffset) || !header.u64(tocSize) ||
383 Diagnostic::error(DiagnosticCode::ParseError, "runtime package header is invalid", {}, {}, "asset.evpack"));
392 Diagnostic::error(DiagnosticCode::ParseError, "manifest or TOC range is invalid", {}, {}, "asset.evpack"));
399 Diagnostic::error(DiagnosticCode::ParseError, "signature range is invalid", {}, {}, "asset.evpack"));
402 DiagnosticCode::ParseError, "metadata prefix does not contain the complete TOC", {}, {}, "asset.evpack"));
405 metadataHashInput.insert(metadataHashInput.end(), bytes.begin() + static_cast<std::size_t>(manifestOffset),
407 metadataHashInput.insert(metadataHashInput.end(), bytes.begin() + static_cast<std::size_t>(tocOffset),
410 if (!std::equal(storedHeaderHash.begin(), storedHeaderHash.end(), computedMetadataHash.begin()))
443 if (!manifestReader.raw(8, magic) || !std::equal(magic.begin(), magic.end(), kManifestMagic.begin()) ||
444 !manifestReader.u32(variantCount) || variantCount == 0 || variantCount > limits.maximumVariants ||
447 Diagnostic::error(DiagnosticCode::ParseError, "binary Cook manifest is invalid", {}, {}, "asset.evpack"));
451 if (!manifestReader.string(variant.os, limits) || !manifestReader.string(variant.arch, limits) ||
454 !manifestReader.string(variant.shaderFormat, limits) || !manifestReader.string(variant.quality, limits) ||
457 Diagnostic::error(DiagnosticCode::ParseError, "variant record is invalid", {}, {}, "asset.evpack"));
462 DiagnosticCode::ParseError, "binary Cook manifest has trailing bytes", {}, {}, "asset.evpack"));
464 Reader tocReader(bytes, static_cast<std::size_t>(tocOffset), static_cast<std::size_t>(tocOffset + tocSize));
470 Diagnostic::error(DiagnosticCode::ParseError, "runtime package TOC is invalid", {}, {}, "asset.evpack"));
472 std::uint64_t previousEnd = signedPackage ? signatureOffset + signatureSize : tocOffset + tocSize;
485 !tocReader.u32(chunk.chunkId) || !tocReader.u32(chunk.alignment) || !powerOfTwo(chunk.alignment) ||
498 chunk.storedSize > limits.maximumChunkBytes || chunk.decodedSize > limits.maximumDecodedBytes ||
499 decodedTotal > limits.maximumDecodedBytes - chunk.decodedSize || chunk.offset % chunk.alignment != 0 ||
500 chunk.offset < previousEnd || chunk.offset > packageSize || chunk.storedSize > packageSize - chunk.offset)
502 DiagnosticCode::Unsupported, "unsupported or unsafe runtime chunk", chunk.type, {}, "asset.evpack"));
503 ChunkKey key{chunk.assetId, chunk.type, chunk.schemaVersion.value(), chunk.variantIndex, kind, chunk.chunkId};
506 DiagnosticCode::Conflict, "runtime chunk TOC is not canonical", chunk.type, {}, "asset.evpack"));
518 std::adjacent_find(chunk.dependencies.begin(), chunk.dependencies.end()) != chunk.dependencies.end())
520 DiagnosticCode::Conflict, "chunk dependencies are not canonical", chunk.type, {}, "asset.evpack"));
529 DiagnosticCode::HashMismatch, "runtime chunk hash does not match", chunk.type, {}, "asset.evpack"));
553 Diagnostic::error(DiagnosticCode::PreconditionViolation, "metadata-only package requires a range source",
572 Diagnostic::error(DiagnosticCode::PreconditionViolation, "metadata-only package requires a range source",
577 auto decoded = decompressEvpackChunk(chunk.codec, stored, chunk.decodedSize, maximumDecodedBytes);
Bounded deterministic compression used by the .evpack wire format.
Versioned random-access runtime package produced by the asset cooker.
Strict allocation-free UTF-8 validation.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
const std::vector< EvpackVariant > & variants() const noexcept
Ordered capability variants encoded in the binary manifest.
Definition Evpack.h:171
static HashFunction * getHashFunction(std::string function)
Get a HashFunction instance for the given function.
Definition HashFunction.cpp:589
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.
static std::optional< Id128 > fromBytes(std::span< const std::uint8_t > bytes) noexcept
Constructs an ID from exactly 16 bytes.
Definition Identity.h:161
constexpr bool isNil() const noexcept
Returns whether this value is the all-zero nil ID.
Definition Identity.h:176
constexpr std::uint64_t value() const noexcept
Returns the underlying value at an explicit protocol boundary.
Definition StrongUint64.h:26
Definition AssetCooker.cpp:17
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< 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< std::vector< std::uint8_t > > compressEvpackChunk(EvpackCodec codec, std::span< const std::uint8_t > decoded)
Compress decoded chunk bytes using the selected stable wire codec.
Definition EvpackCompression.cpp:12
Result< std::vector< std::uint8_t > > decompressEvpackChunk(EvpackCodec codec, std::span< const std::uint8_t > stored, std::uint64_t decodedSize, std::uint64_t maximumDecodedBytes)
Decode one chunk into its authenticated canonical bytes.
Definition EvpackCompression.cpp:34
Result< EvpackVariantSelection > selectEvpackVariant(const Evpack &pack, const EvpackCapabilities &capabilities)
Select the first explicitly ordered variant satisfied by device capabilities.
Definition Evpack.cpp:585
Result< Evpack > parseEvpackMetadata(std::span< const std::uint8_t > bytes, std::uint64_t packageSize, const EvpackLimits &limits, const EvpackTrust &trust)
Admit only the contiguous header/manifest/TOC prefix of a range-readable package.
Definition Evpack.cpp:361
@ InvalidArgument
@ ParseError
@ Conflict
StrongUuid< detail::PersistentIdTag > PersistentId
Stable instance identity for persistence, networking and process boundaries.
Definition Identity.h:254
bool isValidUtf8(std::string_view text, Utf8NullPolicy nullPolicy) noexcept
Validate shortest-form UTF-8, Unicode scalar range and optional NUL exclusion.
Definition Utf8Validation.cpp:5
@ Reject
Definition Container.h:602
Actual runtime device capabilities used for variant selection.
Definition Evpack.h:92
std::vector< PersistentId > dependencies
Definition Evpack.h:112
std::array< std::uint8_t, 32 > contentHash
Definition Evpack.h:150
std::vector< PersistentId > dependencies
Definition Evpack.h:151
Resource limits checked before package allocations and hash work.
Definition Evpack.h:126
std::shared_ptr< const EvpackSignatureVerifier > verifier
Definition Evpack.h:77
Capability-addressed runtime representation; list order is fallback order.
Definition Evpack.h:81