Add WiVRn-native Perfetto via Perfetto SDK
Optional server profiling built on the Perfetto SDK. Adds CPU spans (compositor, encoder, network), GPU encode/copy slices from Vulkan timestamp queries (Vulkan/NVENC/VAAPI), and headset feedback markers from dump_time. WIVRN_TRACING enables tracing and selects the backend (system, inprocess, or both); WIVRN_USE_PERFETTO gates it at build time and compiles it out otherwise. WIVRN_TRACE_MONADO additionally drives Monado's percetto tracing from the same switch so WiVRn and Monado land on one timeline. Tooling: server-tracing[-monado] presets and a CI build, two Perfetto configs (WiVRn-only and full-system), a wivrn_capture.py capture wrapper, a pftrace summary script, and docs/profiling.md.
This commit is contained in:
@@ -20,7 +20,9 @@
|
||||
#include "video_encoder_nvenc.h"
|
||||
#include "encoder_settings.h"
|
||||
|
||||
#include "os/os_time.h"
|
||||
#include "util/u_logging.h"
|
||||
#include "utils/wivrn_trace.h"
|
||||
#include "utils/wivrn_vk_bundle.h"
|
||||
|
||||
bool operator==(const GUID & l, const GUID & r)
|
||||
@@ -410,6 +412,8 @@ video_encoder_nvenc::video_encoder_nvenc(
|
||||
i.nvenc_resource = resource_params.registeredResource;
|
||||
}
|
||||
CU_CHECK(shared_state->cuda_fn->cuCtxPopCurrent(NULL));
|
||||
|
||||
ts_pool = gpu_timestamp_pool(vk, vk.queue.family_index, num_slots, std::format("nvenc encoder {} pixel copy", stream_idx));
|
||||
}
|
||||
|
||||
video_encoder_nvenc::~video_encoder_nvenc()
|
||||
@@ -418,7 +422,7 @@ video_encoder_nvenc::~video_encoder_nvenc()
|
||||
shared_state->fn.nvEncDestroyEncoder(session_handle);
|
||||
}
|
||||
|
||||
void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t)
|
||||
void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t frame_index)
|
||||
{
|
||||
if (vk.device.waitForFences(*in[slot].fence, true, 1'000'000'000) == vk::Result::eTimeout)
|
||||
{
|
||||
@@ -428,6 +432,8 @@ void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInf
|
||||
auto & cmd = in[slot].cmd;
|
||||
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
||||
|
||||
ts_pool.cmd_begin(cmd, slot, frame_index, vk::PipelineStageFlagBits2::eTopOfPipe);
|
||||
|
||||
cmd.copyImageToBuffer(
|
||||
y_cbcr,
|
||||
vk::ImageLayout::eGeneral,
|
||||
@@ -459,6 +465,7 @@ void video_encoder_nvenc::present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInf
|
||||
.depth = 1,
|
||||
},
|
||||
}});
|
||||
ts_pool.cmd_end(cmd, slot, vk::PipelineStageFlagBits2::eAllTransfer);
|
||||
cmd.end();
|
||||
|
||||
std::unique_lock lock(vk.queue.mutex);
|
||||
@@ -482,6 +489,16 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(uint8_t slot, uin
|
||||
return {};
|
||||
}
|
||||
|
||||
if (auto s = ts_pool.collect(slot))
|
||||
{
|
||||
wivrn::trace::gpu_slice(wivrn::trace::gpu_track::nvenc_copy,
|
||||
"vk_copy_image_to_buffer",
|
||||
s->begin_ns,
|
||||
s->end_ns,
|
||||
s->frame_index,
|
||||
stream_idx);
|
||||
}
|
||||
|
||||
CU_CHECK(shared_state->cuda_fn->cuCtxPushCurrent(shared_state->cuda));
|
||||
auto & idr_handler = ((default_idr_handler &)*idr);
|
||||
|
||||
@@ -557,14 +574,16 @@ std::optional<video_encoder::data> video_encoder_nvenc::encode(uint8_t slot, uin
|
||||
frame_params.pictureType = NV_ENC_PIC_TYPE_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
NVENC_CHECK(shared_state->fn.nvEncEncodePicture(session_handle, &frame_params));
|
||||
|
||||
NV_ENC_LOCK_BITSTREAM buf_lock_params{
|
||||
.version = NV_ENC_LOCK_BITSTREAM_VER,
|
||||
.doNotWait = 0,
|
||||
.outputBitstream = outputBuffer,
|
||||
};
|
||||
NVENC_CHECK(shared_state->fn.nvEncLockBitstream(session_handle, &buf_lock_params));
|
||||
{
|
||||
wivrn::trace::scope trace_nvenc(wivrn::trace::cpu_track::encoder, stream_idx, frame_index, "nvEncEncodePicture+Lock");
|
||||
NVENC_CHECK(shared_state->fn.nvEncEncodePicture(session_handle, &frame_params));
|
||||
NVENC_CHECK(shared_state->fn.nvEncLockBitstream(session_handle, &buf_lock_params));
|
||||
}
|
||||
|
||||
if (buf_lock_params.pictureType == NV_ENC_PIC_TYPE_NONREF_P)
|
||||
idr_handler.set_non_ref(frame_index);
|
||||
|
||||
Reference in New Issue
Block a user