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:
2026-07-15 00:35:10 +02:00
parent 1b73361372
commit 4c3b11445c
396 changed files with 140058 additions and 0 deletions
@@ -0,0 +1,7 @@
add_granite_internal_lib(granite-application-events
application_wsi.hpp
application_wsi.cpp application_wsi_events.hpp
application_events.hpp)
target_include_directories(granite-application-events PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(granite-application-events
PRIVATE granite-vulkan granite-event granite-input granite-application-global)
@@ -0,0 +1,55 @@
/* 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 "event.hpp"
namespace Granite
{
enum class ApplicationLifecycle
{
Running,
Paused,
Stopped,
Dead
};
class ApplicationLifecycleEvent : public Event
{
public:
GRANITE_EVENT_TYPE_DECL(ApplicationLifecycleEvent)
explicit ApplicationLifecycleEvent(ApplicationLifecycle lifecycle_)
: lifecycle(lifecycle_)
{
}
ApplicationLifecycle get_lifecycle() const
{
return lifecycle;
}
private:
ApplicationLifecycle lifecycle;
};
}
@@ -0,0 +1,188 @@
/* 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.
*/
#include "application_wsi.hpp"
#include "application_wsi_events.hpp"
#include "application_events.hpp"
#include "global_managers.hpp"
#include "event.hpp"
namespace Granite
{
GraniteWSIPlatform::GraniteWSIPlatform()
{
input_tracker.set_input_handler(this);
}
void GraniteWSIPlatform::event_swapchain_created(Vulkan::Device *device, VkSwapchainKHR, unsigned width, unsigned height,
float aspect_ratio, size_t image_count, VkFormat format,
VkColorSpaceKHR color_space,
VkSurfaceTransformFlagBitsKHR transform)
{
auto *em = GRANITE_EVENT_MANAGER();
if (em)
{
em->enqueue_latched<Vulkan::SwapchainParameterEvent>(device, width, height, aspect_ratio, image_count, format,
color_space, transform);
}
}
void GraniteWSIPlatform::event_swapchain_destroyed()
{
auto *em = GRANITE_EVENT_MANAGER();
if (em)
em->dequeue_all_latched(Vulkan::SwapchainParameterEvent::get_type_id());
}
void GraniteWSIPlatform::event_device_created(Vulkan::Device *device)
{
auto *em = GRANITE_EVENT_MANAGER();
if (em)
em->enqueue_latched<Vulkan::DeviceCreatedEvent>(device);
}
void GraniteWSIPlatform::event_device_destroyed()
{
auto *em = GRANITE_EVENT_MANAGER();
if (em)
em->dequeue_all_latched(Vulkan::DeviceCreatedEvent::get_type_id());
}
void GraniteWSIPlatform::event_swapchain_index(Vulkan::Device *device, unsigned index)
{
auto *em = GRANITE_EVENT_MANAGER();
if (em)
{
em->dequeue_all_latched(Vulkan::SwapchainIndexEvent::get_type_id());
em->enqueue_latched<Vulkan::SwapchainIndexEvent>(device, index);
}
}
void GraniteWSIPlatform::event_frame_tick(double, double)
{
}
template <typename T>
void GraniteWSIPlatform::dispatch_template(const T &t)
{
if (auto *em = GRANITE_EVENT_MANAGER())
em->dispatch_inline(t);
}
template <typename T>
void GraniteWSIPlatform::dispatch_template_filter(const T &t)
{
auto *ui = Global::ui_manager();
if (ui && !ui->filter_input_event(t))
return;
dispatch_template(t);
}
template <typename Func>
void GraniteWSIPlatform::dispatch_or_defer(Func &&func)
{
if (in_async_input)
captured.emplace_back(std::forward<Func>(func));
else
func();
}
#define WORK(work) dispatch_or_defer([this, e]() { work; })
void GraniteWSIPlatform::dispatch(const TouchDownEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const TouchUpEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const TouchGestureEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const JoypadButtonEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const JoypadAxisEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const KeyboardEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const OrientationEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const MouseButtonEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const MouseMoveEvent &e)
{
WORK(dispatch_template_filter(e));
}
void GraniteWSIPlatform::dispatch(const JoypadStateEvent &e)
{
WORK(dispatch_template(e));
}
void GraniteWSIPlatform::dispatch(const InputStateEvent &e)
{
WORK(dispatch_template(e));
}
void GraniteWSIPlatform::dispatch(const JoypadConnectionEvent &e)
{
WORK(dispatch_template(e));
}
void GraniteWSIPlatform::begin_async_input_handling()
{
in_async_input = true;
}
void GraniteWSIPlatform::end_async_input_handling()
{
in_async_input = false;
}
void GraniteWSIPlatform::flush_deferred_input_events()
{
VK_ASSERT(!in_async_input);
for (auto &func : captured)
func();
captured.clear();
}
}
@@ -0,0 +1,81 @@
/* 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 "wsi.hpp"
#include "input.hpp"
#include <functional>
namespace Granite
{
class GraniteWSIPlatform : public Vulkan::WSIPlatform, private InputTrackerHandler
{
public:
GraniteWSIPlatform();
InputTracker &get_input_tracker()
{
return input_tracker;
}
protected:
void event_device_created(Vulkan::Device *device) override;
void event_device_destroyed() override;
void event_swapchain_created(Vulkan::Device *device, VkSwapchainKHR swapchain,
unsigned width, unsigned height,
float aspect_ratio, size_t image_count,
VkFormat format, VkColorSpaceKHR color_space,
VkSurfaceTransformFlagBitsKHR pre_rotate) override;
void event_swapchain_destroyed() override;
void event_swapchain_index(Vulkan::Device *device, unsigned index) override;
void event_frame_tick(double frame, double elapsed) override;
void begin_async_input_handling();
void end_async_input_handling();
void flush_deferred_input_events();
private:
InputTracker input_tracker;
void dispatch(const TouchDownEvent &e) override;
void dispatch(const TouchUpEvent &e) override;
void dispatch(const TouchGestureEvent &e) override;
void dispatch(const JoypadButtonEvent &e) override;
void dispatch(const JoypadAxisEvent &e) override;
void dispatch(const KeyboardEvent &e) override;
void dispatch(const OrientationEvent &e) override;
void dispatch(const MouseButtonEvent &e) override;
void dispatch(const MouseMoveEvent &e) override;
void dispatch(const JoypadStateEvent &e) override;
void dispatch(const InputStateEvent &e) override;
void dispatch(const JoypadConnectionEvent &e) override;
template <typename T>
void dispatch_template_filter(const T &t);
template <typename T>
void dispatch_template(const T &t);
template <typename Func>
void dispatch_or_defer(Func &&func);
bool in_async_input = false;
std::vector<std::function<void ()>> captured;
};
}
@@ -0,0 +1,258 @@
/* 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 "event.hpp"
#include "vulkan_headers.hpp"
namespace Vulkan
{
class Device;
class ShaderManager;
class WSIPlatform;
class DeviceCreatedEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(DeviceCreatedEvent)
explicit DeviceCreatedEvent(Device *device_)
: device(*device_)
{}
Device &get_device() const
{
return device;
}
private:
Device &device;
};
class DeviceShaderModuleReadyEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(DeviceShaderModuleReadyEvent)
explicit DeviceShaderModuleReadyEvent(Device *device_, ShaderManager *manager_)
: device(*device_), manager(*manager_)
{}
Device &get_device() const
{
return device;
}
ShaderManager &get_shader_manager() const
{
return manager;
}
private:
Device &device;
ShaderManager &manager;
};
class DevicePipelineReadyEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(DevicePipelineReadyEvent)
explicit DevicePipelineReadyEvent(Device *device_, ShaderManager *manager_)
: device(*device_), manager(*manager_)
{}
Device &get_device() const
{
return device;
}
ShaderManager &get_shader_manager() const
{
return manager;
}
private:
Device &device;
ShaderManager &manager;
};
class SwapchainParameterEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(SwapchainParameterEvent)
SwapchainParameterEvent(Device *device_,
unsigned width_, unsigned height_,
float aspect_ratio_, unsigned count_,
VkFormat format_, VkColorSpaceKHR color_space_,
VkSurfaceTransformFlagBitsKHR transform_)
: device(*device_), width(width_), height(height_),
aspect_ratio(aspect_ratio_), image_count(count_), format(format_), color_space(color_space_), transform(transform_)
{}
Device &get_device() const
{
return device;
}
unsigned get_width() const
{
return width;
}
unsigned get_height() const
{
return height;
}
float get_aspect_ratio() const
{
return aspect_ratio;
}
unsigned get_image_count() const
{
return image_count;
}
VkFormat get_format() const
{
return format;
}
VkColorSpaceKHR get_color_space() const
{
return color_space;
}
VkSurfaceTransformFlagBitsKHR get_prerotate() const
{
return transform;
}
private:
Device &device;
unsigned width;
unsigned height;
float aspect_ratio;
unsigned image_count;
VkFormat format;
VkColorSpaceKHR color_space;
VkSurfaceTransformFlagBitsKHR transform;
};
class SwapchainIndexEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(SwapchainIndexEvent)
SwapchainIndexEvent(Device *device_, unsigned index_)
: device(*device_), index(index_)
{}
Device &get_device() const
{
return device;
}
unsigned get_index() const
{
return index;
}
private:
Device &device;
unsigned index;
};
class ApplicationWSIPlatformEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(ApplicationWSIPlatformEvent)
explicit ApplicationWSIPlatformEvent(WSIPlatform &platform_)
: platform(platform_)
{}
WSIPlatform &get_platform() const
{
return platform;
}
private:
WSIPlatform &platform;
};
class ApplicationWindowFileDropEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(ApplicationWindowFileDropEvent)
explicit ApplicationWindowFileDropEvent(std::string path_)
: path(std::move(path_))
{}
const std::string &get_path() const
{
return path;
}
private:
std::string path;
};
class ApplicationWindowTextDropEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(ApplicationWindowTextDropEvent)
explicit ApplicationWindowTextDropEvent(std::string str_)
: str(std::move(str_))
{}
const std::string &get_text() const
{
return str;
}
private:
std::string str;
};
class ApplicationSoftKeyboardUpdateEvent : public Granite::Event
{
public:
GRANITE_EVENT_TYPE_DECL(ApplicationSoftKeyboardUpdateEvent)
explicit ApplicationSoftKeyboardUpdateEvent(std::string str_)
: str(std::move(str_))
{
}
const std::string &get_text() const
{
return str;
}
private:
std::string str;
};
}