feat(host): vendor PyroWave + minimal Granite subset as crates/pyrowave-sys
Phase 0 of design/pyrowave-codec-plan.md — the opt-in wired-LAN ultra-low- latency codec. Vendored at upstream 509e4f88 (API 0.4.0, Granite 44362775, volk + vulkan-headers pins in PUNKTFUNK-VENDOR.txt), pruned to the 6.6 MB the standalone no-renderer build needs; scripts/vendor-pyrowave.sh reproduces the tree (a pin bump is protocol-affecting, plan §4.2). build.rs drives the wrapper CMakeLists (static archives incl. a static C-API lib upstream only ships shared) + bindgen over pyrowave.h; Linux and Windows only, empty stub elsewhere (Apple gets a native Metal port, §4.7). Offline-safe by construction: no network, no system lib, vendored Vulkan headers — same model as the opus dep (flatpak builder has no network). Phase-0 validation on .21 (RTX 5070 Ti, driver 610.43.03): - upstream pyrowave-c-test + interop test (incl. dmabuf/DRM-modifier Vulkan<->Vulkan) pass, from the pristine AND the pruned tree - GPU kernel times at ~1.6 bpp noise: encode/decode 0.090/0.042 ms @800p, 0.146/0.067 @1080p, 0.226/0.103 @1440p, 0.477/0.201 @4K — order of magnitude under NVENC's 1-2 ms retrieve, CBR lands within ~100 B of target - cargo test -p pyrowave-sys green (static link + API-version pin check) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,175 @@
|
||||
/* Copyright (c) 2017-2026 Hans-Kristian Arntzen
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <stack>
|
||||
#include <utility>
|
||||
#include <stdint.h>
|
||||
#include "object_pool.hpp"
|
||||
#include <assert.h>
|
||||
|
||||
namespace Util
|
||||
{
|
||||
using GenerationalHandleID = uint32_t;
|
||||
template <typename T>
|
||||
class GenerationalHandlePool
|
||||
{
|
||||
public:
|
||||
using ID = GenerationalHandleID;
|
||||
|
||||
GenerationalHandlePool()
|
||||
{
|
||||
elements.resize(16);
|
||||
generation.resize(16);
|
||||
for (unsigned i = 0; i < 16; i++)
|
||||
vacant_indices.push(i);
|
||||
}
|
||||
|
||||
~GenerationalHandlePool()
|
||||
{
|
||||
for (auto &elem : elements)
|
||||
if (elem)
|
||||
pool.free(elem);
|
||||
}
|
||||
|
||||
GenerationalHandlePool(const GenerationalHandlePool &) = delete;
|
||||
void operator=(const GenerationalHandlePool &) = delete;
|
||||
|
||||
template <typename... P>
|
||||
ID emplace(P&&... p)
|
||||
{
|
||||
auto index = get_vacant_index();
|
||||
auto generation_index = uint8_t(++generation[index]);
|
||||
|
||||
// Reserve generation index 0 for sentinel purposes.
|
||||
if (!generation_index)
|
||||
generation_index = ++generation[index];
|
||||
|
||||
elements[index] = pool.allocate(std::forward<P>(p)...);
|
||||
return make_id(index, generation_index);
|
||||
}
|
||||
|
||||
void remove(ID id)
|
||||
{
|
||||
auto index = memory_index(id);
|
||||
auto gen_index = generation_index(id);
|
||||
|
||||
if (index >= elements.size())
|
||||
return;
|
||||
if (gen_index != generation[index])
|
||||
return;
|
||||
if (!elements[index])
|
||||
return;
|
||||
|
||||
pool.free(elements[index]);
|
||||
elements[index] = nullptr;
|
||||
vacant_indices.push(index);
|
||||
}
|
||||
|
||||
T *maybe_get(ID id) const
|
||||
{
|
||||
auto index = memory_index(id);
|
||||
auto gen_index = generation_index(id);
|
||||
|
||||
if (index >= elements.size())
|
||||
return nullptr;
|
||||
if (gen_index != generation[index])
|
||||
return nullptr;
|
||||
|
||||
return elements[index];
|
||||
}
|
||||
|
||||
T &get(ID id) const
|
||||
{
|
||||
auto index = memory_index(id);
|
||||
auto gen_index = generation_index(id);
|
||||
|
||||
if (index >= elements.size())
|
||||
throw std::logic_error("Invalid ID.");
|
||||
if (gen_index != generation[index])
|
||||
throw std::logic_error("Invalid ID.");
|
||||
if (!elements[index])
|
||||
throw std::logic_error("Invalid ID.");
|
||||
|
||||
return *elements[index];
|
||||
}
|
||||
|
||||
void clear()
|
||||
{
|
||||
for (size_t i = 0; i < elements.size(); i++)
|
||||
{
|
||||
if (elements[i])
|
||||
{
|
||||
pool.free(elements[i]);
|
||||
vacant_indices.push(i);
|
||||
elements[i] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
Util::ObjectPool<T> pool;
|
||||
std::vector<T *> elements;
|
||||
std::vector<uint8_t> generation;
|
||||
std::stack<uint32_t> vacant_indices;
|
||||
|
||||
uint32_t get_vacant_index()
|
||||
{
|
||||
if (vacant_indices.empty())
|
||||
{
|
||||
size_t current_size = elements.size();
|
||||
|
||||
// If this is ever a problem, we can bump to 64-bit IDs.
|
||||
if (current_size >= (size_t(1) << 24u))
|
||||
throw std::bad_alloc();
|
||||
|
||||
elements.resize(current_size * 2);
|
||||
generation.resize(current_size * 2);
|
||||
for (size_t index = current_size; index < 2 * current_size; index++)
|
||||
vacant_indices.push(index);
|
||||
}
|
||||
|
||||
auto ret = vacant_indices.top();
|
||||
vacant_indices.pop();
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ID make_id(uint32_t index, uint32_t generation_index)
|
||||
{
|
||||
assert(index <= 0x00ffffffu);
|
||||
assert(generation_index <= 0xffu);
|
||||
return (generation_index << 24u) | index;
|
||||
}
|
||||
|
||||
static uint32_t generation_index(ID id)
|
||||
{
|
||||
return (id >> 24u) & 0xffu;
|
||||
}
|
||||
|
||||
static uint32_t memory_index(ID id)
|
||||
{
|
||||
return id & 0xffffffu;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user