feat: add GPU particle time interpolation

This commit is contained in:
OpenAI Codex
2026-09-02 09:45:10 +08:00
parent b0f855eb09
commit 4675a8a29d
20 changed files with 425 additions and 57 deletions

View File

@@ -24,8 +24,17 @@ std::atomic_uint64_t nextRasterArrayFieldGeneration{0};
RasterArraySource::RasterArraySource(std::string id,
std::string fixtureID,
std::string metadataURL,
std::string fieldURL)
: Source(makeMutable<Impl>(std::move(id), std::move(fixtureID), std::move(metadataURL), std::move(fieldURL))) {}
std::string fieldURL,
std::string nextFixtureID,
std::string nextMetadataURL,
std::string nextFieldURL)
: Source(makeMutable<Impl>(std::move(id),
std::move(fixtureID),
std::move(metadataURL),
std::move(fieldURL),
std::move(nextFixtureID),
std::move(nextMetadataURL),
std::move(nextFieldURL))) {}
RasterArraySource::~RasterArraySource() {
weakFactory.invalidateWeakPtrs();
@@ -61,21 +70,69 @@ void RasterArraySource::loadDescription(FileSource& fileSource) {
tryLoad();
}
});
if (!impl().nextFixtureID.empty()) {
if (impl().nextMetadataURL.empty() || impl().nextFieldURL.empty()) {
observer->onSourceError(
*this,
std::make_exception_ptr(std::runtime_error("particle next fixture requires metadata and field URLs")));
return;
}
nextMetadataRequest = fileSource.request(
Resource::source(impl().nextMetadataURL), [this, self = makeWeakPtr()](const Response& response) {
if (auto guard = self.lock(); self) {
if (response.error || response.noContent || !response.data) {
observer->onSourceError(
*this,
std::make_exception_ptr(std::runtime_error("particle next metadata request failed")));
return;
}
nextMetadata = *response.data;
tryLoad();
}
});
nextFieldRequest = fileSource.request(
Resource::source(impl().nextFieldURL), [this, self = makeWeakPtr()](const Response& response) {
if (auto guard = self.lock(); self) {
if (response.error || response.noContent || !response.data) {
observer->onSourceError(
*this, std::make_exception_ptr(std::runtime_error("particle next field request failed")));
return;
}
nextFieldBytes = std::vector<char>(response.data->begin(), response.data->end());
tryLoad();
}
});
}
}
void RasterArraySource::tryLoad() {
if (!metadata || !fieldBytes) return;
if (!metadata || !fieldBytes || (!impl().nextFixtureID.empty() && (!nextMetadata || !nextFieldBytes))) return;
try {
const auto fieldGeneration = ++nextRasterArrayFieldGeneration;
auto field = particle::OfflineFixtureParticleAdapter::load(
impl().fixtureID, *metadata, *fieldBytes, fieldGeneration);
baseImpl = makeMutable<Impl>(impl(), std::move(field));
if (impl().nextFixtureID.empty()) {
baseImpl = makeMutable<Impl>(impl(), std::move(field));
} else {
auto nextField = particle::OfflineFixtureParticleAdapter::load(
impl().nextFixtureID, *nextMetadata, *nextFieldBytes, ++nextRasterArrayFieldGeneration);
if (!field.isTimeInterpolationCompatibleWith(nextField)) {
throw std::invalid_argument("particle time-window fixtures are incompatible");
}
baseImpl = makeMutable<Impl>(impl(), std::move(field), std::move(nextField));
}
loaded = true;
const auto& loadedField = *impl().field;
Log::Info(Event::Render,
"ParticleField: source loaded fixtureId=" + impl().fixtureID + " metadata=" + impl().metadataURL +
" field=" + impl().fieldURL + " generation=" + std::to_string(loadedField.generation) +
" dataVersion=" + std::to_string(loadedField.dataVersion));
if (impl().nextField) {
Log::Info(Event::Render,
"ParticleField: source loaded next fixtureId=" + impl().nextField->fixtureID +
" generation=" + std::to_string(impl().nextField->generation) +
" dataVersion=" + std::to_string(impl().nextField->dataVersion));
}
observer->onSourceLoaded(*this);
observer->onSourceChanged(*this);
} catch (const std::exception& error) {