MCPcopy Create free account
hub / github.com/SakuraEngine/SakuraEngine / Resize

Method Resize

modules/render/animation/ozz_src/runtime/sampling_job.cc:366–433  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

364}
365
366void SamplingJob::Context::Resize(int _max_tracks) {
367 using internal::InterpSoaFloat3;
368 using internal::InterpSoaQuaternion;
369
370 // Reset existing data.
371 Invalidate();
372 memory::default_allocator()->Deallocate(soa_translations_, alignof(InterpSoaFloat3));
373
374 // Updates maximum supported soa tracks.
375 max_soa_tracks_ = (_max_tracks + 3) / 4;
376
377 // Allocate all context data at once in a single allocation.
378 // Alignment is guaranteed because memory is dispatch from the highest
379 // alignment requirement (Soa data: SimdFloat4) to the lowest (outdated
380 // flag: unsigned char).
381
382 // Computes allocation size.
383 const size_t max_tracks = max_soa_tracks_ * 4;
384 const size_t num_outdated = (max_soa_tracks_ + 7) / 8;
385 const size_t size =
386 sizeof(InterpSoaFloat3) * max_soa_tracks_ +
387 sizeof(InterpSoaQuaternion) * max_soa_tracks_ +
388 sizeof(InterpSoaFloat3) * max_soa_tracks_ +
389 sizeof(int) * max_tracks * 2 * 3 + // 2 keys * (trans + rot + scale).
390 sizeof(uint8_t) * 3 * num_outdated;
391
392 // Allocates all at once.
393 memory::Allocator* allocator = memory::default_allocator();
394 char* alloc_begin = reinterpret_cast<char*>(
395 allocator->Allocate(size, alignof(InterpSoaFloat3)));
396 char* alloc_cursor = alloc_begin;
397
398 // Distributes buffer memory while ensuring proper alignment (serves larger
399 // alignment values first).
400 static_assert(alignof(InterpSoaFloat3) >= alignof(InterpSoaQuaternion) &&
401 alignof(InterpSoaQuaternion) >= alignof(InterpSoaFloat3) &&
402 alignof(InterpSoaFloat3) >= alignof(int) &&
403 alignof(int) >= alignof(uint8_t),
404 "Must serve larger alignment values first)");
405
406 soa_translations_ = reinterpret_cast<InterpSoaFloat3*>(alloc_cursor);
407 assert(IsAligned(soa_translations_, alignof(InterpSoaFloat3)));
408 alloc_cursor += sizeof(InterpSoaFloat3) * max_soa_tracks_;
409 soa_rotations_ = reinterpret_cast<InterpSoaQuaternion*>(alloc_cursor);
410 assert(IsAligned(soa_rotations_, alignof(InterpSoaQuaternion)));
411 alloc_cursor += sizeof(InterpSoaQuaternion) * max_soa_tracks_;
412 soa_scales_ = reinterpret_cast<InterpSoaFloat3*>(alloc_cursor);
413 assert(IsAligned(soa_scales_, alignof(InterpSoaFloat3)));
414 alloc_cursor += sizeof(InterpSoaFloat3) * max_soa_tracks_;
415
416 translation_keys_ = reinterpret_cast<int*>(alloc_cursor);
417 assert(IsAligned(translation_keys_, alignof(int)));
418 alloc_cursor += sizeof(int) * max_tracks * 2;
419 rotation_keys_ = reinterpret_cast<int*>(alloc_cursor);
420 alloc_cursor += sizeof(int) * max_tracks * 2;
421 scale_keys_ = reinterpret_cast<int*>(alloc_cursor);
422 alloc_cursor += sizeof(int) * max_tracks * 2;
423

Callers

nothing calls this directly

Calls 4

default_allocatorFunction · 0.85
IsAlignedFunction · 0.50
DeallocateMethod · 0.45
AllocateMethod · 0.45

Tested by

no test coverage detected