Skip to content

Commit

Permalink
render: implement a vulkan renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Feb 3, 2024
1 parent ffb2c63 commit eb4c9cd
Show file tree
Hide file tree
Showing 52 changed files with 3,908 additions and 139 deletions.
153 changes: 144 additions & 9 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@ chrono = "0.4.19"
parking_lot = "0.12.1"
arrayvec = "0.7.4"
indexmap = "2.1.0"
ash = "0.37.3"
gpu-alloc = "0.6.0"
gpu-alloc-ash = "0.6.0"

[build-dependencies]
repc = "0.1.1"
anyhow = "1.0.52"
bstr = { version = "1.1.0", default-features = false, features = ["std"] }
shaderc = "0.8.2"

#[profile.dev.build-override]
#opt-level = 3
Expand Down
2 changes: 2 additions & 0 deletions build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::{
mod egl;
mod enums;
mod tokens;
mod vulkan;
mod wire;
mod wire_dbus;
mod wire_xcon;
Expand All @@ -47,6 +48,7 @@ fn main() -> anyhow::Result<()> {
wire_xcon::main()?;
enums::main()?;
egl::main()?;
vulkan::main()?;

println!("cargo:rerun-if-changed=build/build.rs");
Ok(())
Expand Down
38 changes: 38 additions & 0 deletions build/vulkan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use {
crate::open,
anyhow::{bail, Context},
std::{io::Write, path::Path},
};

const ROOT: &str = "src/gfx_apis/vulkan/shaders";

pub fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed={}", ROOT);
for shader in std::fs::read_dir(ROOT)? {
let shader = shader?;
let name = shader.file_name().to_string_lossy().into_owned();
compile_shader(&name).context(name)?;
}
Ok(())
}

fn compile_shader(name: &str) -> anyhow::Result<()> {
let stage = match Path::new(name)
.extension()
.and_then(|e| e.to_str())
.unwrap_or("")
{
"frag" => shaderc::ShaderKind::Fragment,
"vert" => shaderc::ShaderKind::Vertex,
n => bail!("Unknown shader stage {}", n),
};
let src = std::fs::read_to_string(format!("{}/{}", ROOT, name))?;
let compiler = shaderc::Compiler::new().unwrap();
let binary = compiler
.compile_into_spirv(&src, stage, name, "main", None)
.unwrap();
let mut file = open(&format!("{}.spv", name))?;
file.write_all(binary.as_binary_u8())?;
file.flush()?;
Ok(())
}
6 changes: 5 additions & 1 deletion jay-config/src/_private/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use {
timer::Timer,
video::{
connector_type::{ConnectorType, CON_UNKNOWN},
Connector, DrmDevice, Mode,
Connector, DrmDevice, GfxApi, Mode,
},
Axis, Direction, ModifiedKeySym, PciId, Workspace,
},
Expand Down Expand Up @@ -506,6 +506,10 @@ impl Client {
self.send(&ClientMessage::MakeRenderDevice { device });
}

pub fn set_gfx_api(&self, device: Option<DrmDevice>, api: GfxApi) {
self.send(&ClientMessage::SetGfxApi { device, api });
}

pub fn connector_connected(&self, connector: Connector) -> bool {
let res = self.send_with_response(&ClientMessage::ConnectorConnected { connector });
get_response!(res, false, ConnectorConnected { connected });
Expand Down
6 changes: 5 additions & 1 deletion jay-config/src/_private/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use {
logging::LogLevel,
theme::{colors::Colorable, sized::Resizable, Color},
timer::Timer,
video::{connector_type::ConnectorType, Connector, DrmDevice},
video::{connector_type::ConnectorType, Connector, DrmDevice, GfxApi},
Axis, Direction, PciId, Workspace,
},
bincode::{BorrowDecode, Decode, Encode},
Expand Down Expand Up @@ -330,6 +330,10 @@ pub enum ClientMessage<'a> {
GetWorkspaceCapture {
workspace: Workspace,
},
SetGfxApi {
device: Option<DrmDevice>,
api: GfxApi,
},
}

#[derive(Encode, Decode, Debug)]
Expand Down
Loading

0 comments on commit eb4c9cd

Please sign in to comment.