Skip to content

Commit

Permalink
refactor: ♻️ Move client graphics code to separate crate (#2639)
Browse files Browse the repository at this point in the history
  • Loading branch information
zmerp authored Jan 18, 2025
1 parent 14209b0 commit 393f894
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 70 deletions.
47 changes: 16 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ alvr_client_core = { path = "alvr/client_core" }
alvr_common = { path = "alvr/common" }
alvr_events = { path = "alvr/events" }
alvr_filesystem = { path = "alvr/filesystem" }
alvr_graphics = { path = "alvr/graphics" }
alvr_gui_common = { path = "alvr/gui_common" }
alvr_packets = { path = "alvr/packets" }
alvr_server_core = { path = "alvr/server_core"}
Expand Down
20 changes: 2 additions & 18 deletions alvr/client_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,28 @@ crate-type = ["rlib", "staticlib", "cdylib"]

[features]
link-stdcpp-shared = []
use-cpp = []
default = ["link-stdcpp-shared", "use-cpp"]
default = ["link-stdcpp-shared"]

[dependencies]
alvr_audio.workspace = true
alvr_common.workspace = true
alvr_graphics.workspace = true
alvr_packets.workspace = true
alvr_session.workspace = true
alvr_sockets.workspace = true
alvr_system_info.workspace = true

app_dirs2 = "2"
bincode = "1"
glow = "0.13"
glyph_brush_layout = "0.2"
jni = "0.21"
khronos-egl = { version = "6", features = ["dynamic"] }
local-ip-address = "0.6"
mdns-sd = "0.11"
pollster = "0.3"
rand = "0.8"
serde = "1"
serde_json = "1"
wgpu = "0.20"
wgpu-core = { version = "0.21", features = ["gles"] }
whoami = "1"

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.14"
ndk = { version = "0.9", features = ["api-level-26", "media"] }
ndk-context = "0.1"
ndk-sys = "0.6"
oboe = "0.6" # todo: remove once AudioThread shutdown crash is fixed

[target.'cfg(not(target_os = "android"))'.dependencies]
env_logger = "0.11"

[build-dependencies]
bindgen = "0.70"
cc = { version = "1", features = ["parallel"] }
walkdir = "2"
6 changes: 4 additions & 2 deletions alvr/client_core/src/c_api.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![expect(dead_code)]

use crate::{
graphics::{GraphicsContext, LobbyRenderer, LobbyViewParams, StreamRenderer, StreamViewParams},
storage,
video_decoder::{self, VideoDecoderConfig, VideoDecoderSource},
ClientCapabilities, ClientCoreContext, ClientCoreEvent,
Expand All @@ -15,6 +14,9 @@ use alvr_common::{
parking_lot::Mutex,
warn, DeviceMotion, Fov, OptLazy, Pose,
};
use alvr_graphics::{
GraphicsContext, LobbyRenderer, LobbyViewParams, StreamRenderer, StreamViewParams,
};
use alvr_packets::{ButtonEntry, ButtonValue, FaceData, ViewParams};
use alvr_session::{CodecType, FoveatedEncodingConfig, MediacodecPropType, MediacodecProperty};
use std::{
Expand Down Expand Up @@ -785,7 +787,7 @@ pub unsafe extern "C" fn alvr_start_stream_opengl(config: AlvrStreamConfig) {
GRAPHICS_CONTEXT.with_borrow(|c| c.as_ref().unwrap().clone()),
view_resolution,
swapchain_textures,
glow::RGBA8,
alvr_graphics::SDR_FORMAT_GL,
foveated_encoding,
true,
false, // TODO: limited range fix config
Expand Down
2 changes: 0 additions & 2 deletions alvr/client_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod storage;
#[cfg(target_os = "android")]
mod audio;

pub mod graphics;
pub mod video_decoder;

use alvr_common::{
Expand All @@ -39,7 +38,6 @@ use std::{
};
use storage::Config;

pub use alvr_system_info::Platform;
pub use logging_backend::init_logging;

pub enum ClientCoreEvent {
Expand Down
1 change: 1 addition & 0 deletions alvr/client_openxr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ crate-type = ["cdylib"]
[dependencies]
alvr_common.workspace = true
alvr_client_core.workspace = true
alvr_graphics.workspace = true
alvr_packets.workspace = true
alvr_session.workspace = true
alvr_system_info.workspace = true
Expand Down
4 changes: 2 additions & 2 deletions alvr/client_openxr/src/graphics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alvr_client_core::graphics::{self, GraphicsContext};
use alvr_common::glam::UVec2;
use alvr_graphics::GraphicsContext;
use openxr as xr;

#[allow(unused)]
Expand All @@ -24,7 +24,7 @@ pub fn swapchain_format(
gfx_ctx.make_current();

let formats = session.enumerate_swapchain_formats().unwrap();
graphics::choose_swapchain_format(&formats, enable_hdr)
alvr_graphics::choose_swapchain_format(&formats, enable_hdr)
}

#[allow(unused_variables)]
Expand Down
6 changes: 3 additions & 3 deletions alvr/client_openxr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ mod passthrough;
mod stream;

use crate::stream::ParsedStreamConfig;
use alvr_client_core::{
graphics::GraphicsContext, ClientCapabilities, ClientCoreContext, ClientCoreEvent, Platform,
};
use alvr_client_core::{ClientCapabilities, ClientCoreContext, ClientCoreEvent};
use alvr_common::{
error,
glam::{Quat, UVec2, Vec3},
info,
parking_lot::RwLock,
Fov, Pose, HAND_LEFT_ID,
};
use alvr_graphics::GraphicsContext;
use alvr_system_info::Platform;
use extra_extensions::{
META_BODY_TRACKING_FULL_BODY_EXTENSION_NAME, META_DETACHED_CONTROLLERS_EXTENSION_NAME,
META_SIMULTANEOUS_HANDS_AND_CONTROLLERS_EXTENSION_NAME,
Expand Down
2 changes: 1 addition & 1 deletion alvr/client_openxr/src/lobby.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::{
graphics::{self, ProjectionLayerAlphaConfig, ProjectionLayerBuilder},
interaction::{self, InteractionContext},
};
use alvr_client_core::graphics::{GraphicsContext, LobbyRenderer, LobbyViewParams, SDR_FORMAT_GL};
use alvr_common::{glam::UVec2, parking_lot::RwLock, Pose};
use alvr_graphics::{GraphicsContext, LobbyRenderer, LobbyViewParams, SDR_FORMAT_GL};
use alvr_system_info::Platform;
use openxr as xr;
use std::{rc::Rc, sync::Arc, time::Duration};
Expand Down
5 changes: 3 additions & 2 deletions alvr/client_openxr/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use crate::{
interaction::{self, InteractionContext, InteractionSourcesConfig},
};
use alvr_client_core::{
graphics::{GraphicsContext, StreamRenderer, StreamViewParams},
video_decoder::{self, VideoDecoderConfig, VideoDecoderSource},
ClientCoreContext, Platform,
ClientCoreContext,
};
use alvr_common::{
anyhow::Result,
Expand All @@ -14,11 +13,13 @@ use alvr_common::{
parking_lot::RwLock,
Pose, RelaxedAtomic, HAND_LEFT_ID, HAND_RIGHT_ID, HEAD_ID,
};
use alvr_graphics::{GraphicsContext, StreamRenderer, StreamViewParams};
use alvr_packets::{FaceData, StreamConfig, ViewParams};
use alvr_session::{
ClientsideFoveationConfig, ClientsideFoveationMode, CodecType, FoveatedEncodingConfig,
MediacodecProperty, PassthroughMode,
};
use alvr_system_info::Platform;
use openxr as xr;
use std::{
ptr,
Expand Down
18 changes: 18 additions & 0 deletions alvr/graphics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "alvr_graphics"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
alvr_common.workspace = true
alvr_session.workspace = true

glow = "0.13"
glyph_brush_layout = "0.2"
khronos-egl = { version = "6", features = ["dynamic"] }
pollster = "0.3"
wgpu = "0.20"
wgpu-core = { version = "0.21", features = ["gles"] }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ macro_rules! ck {
let res = $gl_ctx.$($gl_cmd)*;

#[cfg(debug_assertions)]
crate::graphics::check_error(&$gl_ctx, &format!("{}:{}: {}", file!(), line!(), stringify!($($gl_cmd)*)));
crate::check_error(&$gl_ctx, &format!("{}:{}: {}", file!(), line!(), stringify!($($gl_cmd)*)));

res
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl LobbyRenderer {
"lobby_quad",
&[&bind_group_layout],
QUAD_PUSH_CONTANTS_SIZE,
include_wgsl!("../../resources/lobby_quad.wgsl"),
include_wgsl!("../resources/lobby_quad.wgsl"),
PrimitiveTopology::TriangleStrip,
);

Expand All @@ -242,7 +242,7 @@ impl LobbyRenderer {
"lobby_line",
&[],
LINE_PUSH_CONTANTS_SIZE,
include_wgsl!("../../resources/lobby_line.wgsl"),
include_wgsl!("../resources/lobby_line.wgsl"),
PrimitiveTopology::LineList,
);

Expand Down Expand Up @@ -290,7 +290,7 @@ impl LobbyRenderer {

pub fn update_hud_message(&self, message: &str) {
let ubuntu_font =
FontRef::try_from_slice(include_bytes!("../../resources/Ubuntu-Medium.ttf")).unwrap();
FontRef::try_from_slice(include_bytes!("../resources/Ubuntu-Medium.ttf")).unwrap();

let section_glyphs = Layout::default()
.h_align(HorizontalAlign::Center)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{ck, GraphicsContext};
use crate::graphics::GL_TEXTURE_EXTERNAL_OES;
use crate::GL_TEXTURE_EXTERNAL_OES;
use alvr_common::glam::{IVec2, UVec2};
use glow::{self as gl, HasContext};
use std::{ffi::c_void, rc::Rc};
Expand Down Expand Up @@ -68,7 +68,7 @@ impl StagingRenderer {
context.make_current();

// Add #defines into the shader after the first line
let mut frag_lines: Vec<&str> = include_str!("../../resources/staging_fragment.glsl")
let mut frag_lines: Vec<&str> = include_str!("../resources/staging_fragment.glsl")
.lines()
.collect();
if fix_limited_range {
Expand All @@ -78,7 +78,7 @@ impl StagingRenderer {

let program = create_program(
gl,
include_str!("../../resources/staging_vertex.glsl"),
include_str!("../resources/staging_vertex.glsl"),
frag_str.as_str(),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ impl StreamRenderer {
],
});

let shader_module =
device.create_shader_module(include_wgsl!("../../resources/stream.wgsl"));
let shader_module = device.create_shader_module(include_wgsl!("../resources/stream.wgsl"));

let mut constants = HashMap::new();

Expand Down

0 comments on commit 393f894

Please sign in to comment.