reuse wgfxpass on wayvr+screen

This commit is contained in:
galister
2025-06-18 03:04:51 +09:00
parent 6f4ea99fff
commit 76288f73c5
8 changed files with 128 additions and 242 deletions

View File

@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use std::{
f32::consts::PI,
ptr,
sync::{atomic::AtomicU64, Arc, LazyLock},
sync::{Arc, LazyLock, atomic::AtomicU64},
time::Instant,
};
use vulkano::{
@@ -11,15 +11,15 @@ use vulkano::{
command_buffer::CommandBufferUsage,
device::Queue,
format::Format,
image::{sampler::Filter, view::ImageView, Image},
image::{Image, sampler::Filter, view::ImageView},
pipeline::graphics::{color_blend::AttachmentBlend, input_assembly::PrimitiveTopology},
};
use wgui::gfx::{cmd::XferCommandBuffer, pass::WGfxPass, pipeline::WGfxPipeline, WGfx};
use wgui::gfx::{WGfx, cmd::XferCommandBuffer, pass::WGfxPass, pipeline::WGfxPipeline};
use wlx_capture::frame as wlx_frame;
use wlx_capture::{
frame::{FrameFormat, MouseMeta, WlxFrame},
WlxCapture,
frame::{FrameFormat, MouseMeta, WlxFrame},
};
#[cfg(feature = "pipewire")]
@@ -38,7 +38,7 @@ use wlx_capture::pipewire::PipewireStream;
use {
crate::config::AStrMapExt,
wlx_capture::{
wayland::{wayland_client::protocol::wl_output, WlxClient, WlxOutput},
wayland::{WlxClient, WlxOutput, wayland_client::protocol::wl_output},
wlr_dmabuf::WlrDmabufCapture,
wlr_screencopy::WlrScreencopyCapture,
},
@@ -47,7 +47,7 @@ use {
#[cfg(feature = "x11")]
use wlx_capture::xshm::{XshmCapture, XshmScreen};
use glam::{vec2, vec3a, Affine2, Affine3A, Quat, Vec2, Vec3};
use glam::{Affine2, Affine3A, Quat, Vec2, Vec3, vec2, vec3a};
use crate::{
backend::{
@@ -57,10 +57,11 @@ use crate::{
SplitOverlayBackend,
},
},
config::{def_pw_tokens, GeneralConfig, PwTokenMap},
config::{GeneralConfig, PwTokenMap, def_pw_tokens},
graphics::{
dmabuf::{fourcc_to_vk, WGfxDmabuf},
upload_quad_vertices, CommandBuffers, ExtentExt, Vert2Uv,
CommandBuffers, Vert2Uv,
dmabuf::{WGfxDmabuf, fourcc_to_vk},
upload_quad_vertices,
},
hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT},
state::{AppSession, AppState, KeyboardFocus, ScreenMeta},
@@ -166,12 +167,15 @@ struct MousePass {
struct ScreenPipeline {
mouse: Option<MousePass>,
pipeline: Arc<WGfxPipeline<Vert2Uv>>,
pass: WGfxPass<Vert2Uv>,
buf_alpha: Subbuffer<[f32]>,
extentf: [f32; 2],
}
impl ScreenPipeline {
fn new(extent: &[u32; 3], app: &mut AppState) -> anyhow::Result<Self> {
let extentf = [extent[0] as f32, extent[1] as f32];
let pipeline = app.gfx.create_pipeline(
app.gfx_extras.shaders.get("vert_quad").unwrap().clone(), // want panic
app.gfx_extras.shaders.get("frag_screen").unwrap().clone(), // want panic
@@ -185,11 +189,25 @@ impl ScreenPipeline {
.gfx
.empty_buffer(BufferUsage::TRANSFER_DST | BufferUsage::UNIFORM_BUFFER, 1)?;
let extentf = [extent[0] as f32, extent[1] as f32];
let set0 = pipeline.uniform_sampler(
0,
app.gfx_extras.fallback_image.clone(),
app.gfx.texture_filter,
)?;
let set1 = pipeline.buffer(1, buf_alpha.clone())?;
let pass = pipeline.create_pass(
extentf,
app.gfx_extras.quad_verts.clone(),
0..4,
0..1,
vec![set0.clone(), set1],
)?;
Ok(Self {
mouse: None,
pipeline,
pass,
buf_alpha,
extentf,
})
@@ -243,26 +261,15 @@ impl ScreenPipeline {
alpha: f32,
) -> anyhow::Result<()> {
let view = ImageView::new_default(image)?;
let set0 = self
.pipeline
.uniform_sampler(0, view, app.gfx.texture_filter)?;
self.pass.update_sampler(0, view, app.gfx.texture_filter)?;
self.buf_alpha.write()?[0] = alpha;
let set1 = self.pipeline.buffer(1, self.buf_alpha.clone())?;
let pass = self.pipeline.create_pass(
tgt.extent_f32(),
app.gfx_extras.quad_verts.clone(),
0..4,
0..1,
vec![set0, set1],
)?;
let mut cmd = app
.gfx
.create_gfx_command_buffer(CommandBufferUsage::OneTimeSubmit)?;
cmd.begin_rendering(tgt)?;
cmd.run_ref(&pass)?;
cmd.run_ref(&self.pass)?;
if let (Some(mouse), Some(pass)) = (mouse, self.mouse.as_mut()) {
let size = CURSOR_SIZE * self.extentf[1];
@@ -542,20 +549,26 @@ impl OverlayRenderer for ScreenRenderer {
let dmabuf_formats = if !supports_dmabuf {
log::info!("Capture method does not support DMA-buf");
if app.gfx_extras.queue_capture.is_none() {
log::warn!("Current GPU does not support multiple queues. Software capture will take place on the main thread. Expect degraded performance.");
log::warn!(
"Current GPU does not support multiple queues. Software capture will take place on the main thread. Expect degraded performance."
);
}
&Vec::new()
} else if !allow_dmabuf {
log::info!("Not using DMA-buf capture due to {capture_method}");
if app.gfx_extras.queue_capture.is_none() {
log::warn!("Current GPU does not support multiple queues. Software capture will take place on the main thread. Expect degraded performance.");
log::warn!(
"Current GPU does not support multiple queues. Software capture will take place on the main thread. Expect degraded performance."
);
}
&Vec::new()
} else {
log::warn!(
"Using DMA-buf capture. If screens are blank for you, switch to SHM using:"
);
log::warn!("echo 'capture_method: pw_fallback' > ~/.config/wlxoverlay/conf.d/pw_fallback.yaml");
log::warn!(
"echo 'capture_method: pw_fallback' > ~/.config/wlxoverlay/conf.d/pw_fallback.yaml"
);
&app.gfx_extras.drm_formats
};

View File

@@ -1,13 +1,14 @@
use glam::{vec3a, Affine2, Vec3, Vec3A};
use glam::{Affine2, Vec3, Vec3A, vec3a};
use std::{cell::RefCell, collections::HashMap, rc::Rc, sync::Arc};
use vulkano::{
buffer::{BufferUsage, Subbuffer},
command_buffer::CommandBufferUsage,
format::Format,
image::{view::ImageView, Image, ImageTiling, SubresourceLayout},
image::{Image, ImageTiling, SubresourceLayout, view::ImageView},
pipeline::graphics::input_assembly::PrimitiveTopology,
};
use wayvr_ipc::packet_server::{self, PacketServer, WvrStateChanged};
use wgui::gfx::{pipeline::WGfxPipeline, WGfx};
use wgui::gfx::{WGfx, pass::WGfxPass, pipeline::WGfxPipeline};
use wlx_capture::frame::{DmabufFrame, FourCC, FrameFormat, FramePlane};
use crate::{
@@ -15,18 +16,17 @@ use crate::{
common::{OverlayContainer, OverlaySelector},
input::{self, InteractionHandler},
overlay::{
ui_transform, FrameMeta, OverlayData, OverlayID, OverlayRenderer, OverlayState,
ShouldRender, SplitOverlayBackend, Z_ORDER_DASHBOARD,
FrameMeta, OverlayData, OverlayID, OverlayRenderer, OverlayState, ShouldRender,
SplitOverlayBackend, Z_ORDER_DASHBOARD, ui_transform,
},
task::TaskType,
wayvr::{
self, display,
self, WayVR, WayVRAction, WayVRDisplayClickAction, display,
server_ipc::{gen_args_vec, gen_env_vec},
WayVR, WayVRAction, WayVRDisplayClickAction,
},
},
config_wayvr,
graphics::{dmabuf::WGfxDmabuf, CommandBuffers, ExtentExt, Vert2Uv},
graphics::{CommandBuffers, Vert2Uv, dmabuf::WGfxDmabuf},
state::{self, AppState, KeyboardFocus},
};
@@ -183,6 +183,8 @@ struct ImageData {
pub struct WayVRRenderer {
pipeline: Arc<WGfxPipeline<Vert2Uv>>,
pass: WGfxPass<Vert2Uv>,
buf_alpha: Subbuffer<[f32]>,
image: Option<ImageData>,
context: Rc<RefCell<WayVRContext>>,
graphics: Arc<WGfx>,
@@ -205,8 +207,28 @@ impl WayVRRenderer {
false,
)?;
let buf_alpha = app
.gfx
.empty_buffer(BufferUsage::TRANSFER_DST | BufferUsage::UNIFORM_BUFFER, 1)?;
let set0 = pipeline.uniform_sampler(
0,
app.gfx_extras.fallback_image.clone(),
app.gfx.texture_filter,
)?;
let set1 = pipeline.buffer(1, buf_alpha.clone())?;
let pass = pipeline.create_pass(
[resolution[0] as _, resolution[1] as _],
app.gfx_extras.quad_verts.clone(),
0..4,
0..1,
vec![set0, set1],
)?;
Ok(Self {
pipeline,
pass,
buf_alpha,
context: Rc::new(RefCell::new(WayVRContext::new(wvr, display))),
graphics: app.gfx.clone(),
image: None,
@@ -728,27 +750,15 @@ impl OverlayRenderer for WayVRRenderer {
return Ok(false);
};
let set0 = self.pipeline.uniform_sampler(
0,
image.vk_image_view.clone(),
app.gfx.texture_filter,
)?;
let set1 = self.pipeline.uniform_buffer_upload(1, vec![alpha])?;
let pass = self.pipeline.create_pass(
tgt.extent_f32(),
app.gfx_extras.quad_verts.clone(),
0..4,
0..1,
vec![set0, set1],
)?;
self.pass
.update_sampler(0, image.vk_image_view.clone(), self.graphics.texture_filter)?;
self.buf_alpha.write()?[0] = alpha;
let mut cmd_buffer = app
.gfx
.create_gfx_command_buffer(CommandBufferUsage::OneTimeSubmit)?;
cmd_buffer.begin_rendering(tgt)?;
cmd_buffer.run_ref(&pass)?;
cmd_buffer.run_ref(&self.pass)?;
cmd_buffer.end_rendering()?;
buf.push(cmd_buffer.build()?);