Fix 32-bit dropouts: enable AVX2 and bound the render-ahead
This commit is contained in:
@@ -113,18 +113,19 @@
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<!--
|
||||
SIMD units, mirroring CMakeLists.txt (the JOC_SIMD_* block) exactly.
|
||||
SIMD units, mirroring CMakeLists.txt (the JOC_SIMD_* block).
|
||||
|
||||
The ISA in the file name, one translation unit per ISA, each compiled with
|
||||
its own /arch because MSVC has no function-level ISA attribute; dispatch.cpp
|
||||
(a baseline unit) picks one at run time from CPUID/XGETBV. The kernel
|
||||
enables SIMD only for x86_64 and aarch64, so:
|
||||
(a baseline unit) picks one at run time from CPUID/XGETBV.
|
||||
|
||||
* Win32 (x86) gets NO SIMD unit and NO SIMD define: the scalar reference
|
||||
and the probe/dispatch baseline are all it builds, exactly as
|
||||
CMAKE_SIZEOF_VOID_P EQUAL 8 gates them out upstream;
|
||||
* x64 gets the AVX2 and AVX-512 units, JOC_SIMD_HAVE_SSE2 / _AVX2 /
|
||||
_AVX512, and a per-file /arch for those two files only;
|
||||
* Win32 (x86) gets the AVX2 unit and JOC_SIMD_HAVE_AVX2. AVX2 is not an
|
||||
x86-64-only ISA and MSVC accepts /arch:AVX2 for x86, so gating it on the
|
||||
pointer size left the 32-bit component on the scalar reference, which is
|
||||
too slow to hold a 4096-frame read inside its own 85.3 ms of audio.
|
||||
AVX-512 stays x64-only: 32-bit mode addresses ZMM0-7 only.
|
||||
* src\simd\kernels_intrin_neon.cpp is excluded everywhere here: the CMake
|
||||
build lists it only for aarch64 (CMakeLists.txt lines 177-180), which no
|
||||
configuration of this project targets.
|
||||
@@ -134,6 +135,11 @@
|
||||
<PreprocessorDefinitions>JOC_SIMD_HAVE_SSE2=1;JOC_SIMD_HAVE_AVX2=1;JOC_SIMD_HAVE_AVX512=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Platform)'=='Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>JOC_SIMD_HAVE_AVX2=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Verbatim copies of the upstream native library (JOC_REUSED_SOURCES). -->
|
||||
@@ -203,6 +209,12 @@
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(Platform)'=='Win32'">
|
||||
<ClCompile Include="src\simd\kernels_intrin_avx2.cpp">
|
||||
<AdditionalOptions>/arch:AVX2 %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ClInclude Include="include\eac3joc_core.h" />
|
||||
<ClInclude Include="include\joc_core.h" />
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
#include "simd/cpu_probe.h"
|
||||
|
||||
#if defined(_M_X64)
|
||||
#if defined(_M_X64) || defined(_M_IX86)
|
||||
#include <immintrin.h>
|
||||
#include <intrin.h>
|
||||
#elif defined(__x86_64__)
|
||||
#elif defined(__x86_64__) || defined(__i386__)
|
||||
#include <cpuid.h>
|
||||
#endif
|
||||
|
||||
@@ -21,10 +21,13 @@
|
||||
namespace joc::simd {
|
||||
namespace {
|
||||
|
||||
// ------------------------------------------------------------------- x86-64 --
|
||||
#if defined(_M_X64) || defined(__x86_64__)
|
||||
// ---------------------------------------------------------------------- x86 --
|
||||
// Both pointer sizes are probed: AVX2 is not an x86-64-only ISA, and gating this
|
||||
// on _M_X64 / __x86_64__ left every 32-bit x86 build reporting "no features",
|
||||
// which pinned the dispatcher to the scalar kernels.
|
||||
#if defined(_M_X64) || defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)
|
||||
|
||||
#if defined(_M_X64)
|
||||
#if defined(_M_X64) || defined(_M_IX86)
|
||||
|
||||
// CPUID tells us what the silicon can do; XCR0 tells us whether the OS saves the
|
||||
// state the wider registers need. Both have to agree, or the first AVX
|
||||
@@ -53,7 +56,7 @@ CpuFeatures probe_x86() noexcept {
|
||||
return features;
|
||||
}
|
||||
|
||||
#else // GCC/Clang on x86-64
|
||||
#else // GCC/Clang on x86
|
||||
|
||||
// The compiler runtime performs the same CPUID + XGETBV probe (libgcc's cpuinfo
|
||||
// checks XCR0 before it reports AVX), which keeps this file free of inline
|
||||
|
||||
@@ -221,7 +221,7 @@ Status Stream::push_eac3(const std::uint8_t* data, std::size_t size, std::size_t
|
||||
}
|
||||
metadata_.push_back(entry);
|
||||
}
|
||||
return process_ready_frames();
|
||||
return process_ready_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_bed(const float* interleaved6, std::size_t samples, std::size_t* consumed) {
|
||||
@@ -235,7 +235,7 @@ Status Stream::push_bed(const float* interleaved6, std::size_t samples, std::siz
|
||||
bed_pending_.insert(bed_pending_.end(), interleaved6,
|
||||
interleaved6 + samples * kBedChannels);
|
||||
}
|
||||
return process_ready_frames();
|
||||
return process_ready_frames(false);
|
||||
}
|
||||
|
||||
Status Stream::push_objects16(const float* planar16, std::size_t samples, std::size_t* consumed) {
|
||||
@@ -267,8 +267,13 @@ Status Stream::push_objects16(const float* planar16, std::size_t samples, std::s
|
||||
return Status::success();
|
||||
}
|
||||
|
||||
Status Stream::process_ready_frames() {
|
||||
Status Stream::process_ready_frames(bool drain_all) {
|
||||
while (bed_pending_.size() / kBedChannels >= kFrameSamples && !metadata_.empty()) {
|
||||
// Stop before rendering what the caller is not about to take: the frames
|
||||
// stay queued, in order, and are rendered by a later push or by flush().
|
||||
if (!drain_all && buffered_samples() >= kMaxRenderAheadSamples) {
|
||||
break;
|
||||
}
|
||||
const FrameMetadata entry = metadata_.front();
|
||||
metadata_.pop_front();
|
||||
|
||||
@@ -429,6 +434,13 @@ Status Stream::pull(float* destination, std::size_t capacity_samples, std::size_
|
||||
}
|
||||
|
||||
Status Stream::flush() {
|
||||
// Input has ended, so the render-ahead bound has nothing left to wait for:
|
||||
// every frame still queued has to reach the renderer before its tail is
|
||||
// drained, or the end of the file would be dropped.
|
||||
const Status remaining = process_ready_frames(true);
|
||||
if (!remaining.ok()) {
|
||||
return remaining;
|
||||
}
|
||||
if (binaural_ready_) {
|
||||
std::vector<double> tail;
|
||||
const Status drained =
|
||||
|
||||
@@ -85,8 +85,18 @@ public:
|
||||
: 0u;
|
||||
}
|
||||
|
||||
// A push renders every frame it makes ready, and the caller decides how far
|
||||
// its demuxer runs ahead of playback. Without a bound, a demuxer that runs
|
||||
// far ahead turns its whole read-ahead burst into latency on whichever pull()
|
||||
// happens to follow it: the samples are not wasted, but they are rendered at
|
||||
// the worst possible moment. Rendering therefore stops once this many
|
||||
// samples are rendered and unpulled; flush() lifts the bound so the frames
|
||||
// still waiting when the input ends are drained rather than dropped.
|
||||
static constexpr std::size_t kMaxRenderAheadSamples = 16384;
|
||||
|
||||
private:
|
||||
Status process_ready_frames();
|
||||
// `drain_all` ignores kMaxRenderAheadSamples and renders every ready frame.
|
||||
Status process_ready_frames(bool drain_all);
|
||||
Status render_objects16(const std::vector<float>& objects16);
|
||||
Status render_rosella_objects16(const std::vector<float>& objects16);
|
||||
// Moves at most `limit` rendered stereo samples per channel out of the FIFO
|
||||
|
||||
Reference in New Issue
Block a user