Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Per-engine compositors #156

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6bf6a35
Heck dcomp ep1
veeenu Feb 6, 2024
422c1af
Non-dcomp DirectX 12 compositor
veeenu Feb 6, 2024
722fb15
Refactor
veeenu Feb 6, 2024
ee0b318
Replace swap chain with texture render target
veeenu Feb 6, 2024
2ed07fa
Just a checkpoint
veeenu Feb 10, 2024
14a1a74
Appropriate resource barrier
veeenu Feb 10, 2024
9a352ea
I don't even know anymore man
veeenu Feb 15, 2024
f847e43
Dx11 compositor working
veeenu Feb 19, 2024
d823f33
Cleanup and fmt
veeenu Feb 19, 2024
dc80900
Remove command queue from state
veeenu Feb 19, 2024
2248fec
Render engine cleanup
veeenu Feb 19, 2024
f131e88
More cleanup
veeenu Feb 19, 2024
6491a2a
Let's just start over
veeenu Feb 20, 2024
d102934
New render engine
veeenu Feb 20, 2024
0353ec9
Implement render engine parts minus render loop
veeenu Feb 20, 2024
fb3158d
Add barrier helpers
veeenu Feb 20, 2024
f47d730
Render draw data and sync
veeenu Feb 20, 2024
8efa843
New Dx12 compositor
veeenu Feb 20, 2024
275e44b
Error blob cleanup
veeenu Feb 21, 2024
d2577fa
A bloody mess but it works somehow
veeenu Feb 21, 2024
46afcd2
Oh my god
veeenu Feb 22, 2024
f6d889a
Dx11 works as well
veeenu Feb 22, 2024
6b7f408
Clippy cleanup
veeenu Feb 22, 2024
53cb57d
Cleanup
veeenu Feb 22, 2024
614819e
Dx9 attempt
veeenu Feb 22, 2024
1798181
Harnesses: resize and debug interface
veeenu Feb 23, 2024
c51dfc0
Compute shader attempt
veeenu Feb 24, 2024
8f7dacc
Compute compositor almost there
veeenu Feb 24, 2024
c057ac4
Add demo imgui window examples
veeenu Feb 24, 2024
2b59b5a
Cleanup test harnesses
veeenu Feb 24, 2024
b2266c1
Remove compute compositor
veeenu Feb 24, 2024
99ed141
Dx9 shows something
veeenu Feb 24, 2024
50b8e96
Got the copy pitch right
veeenu Feb 24, 2024
f3d2a0a
Remove unimportant stuff from the dx9 compositor
veeenu Feb 24, 2024
f3b6ce7
Refactor
veeenu Feb 24, 2024
fe0de85
There is a weird crash in the dx12 harness but it's not urgent
veeenu Feb 24, 2024
b81835a
I need a vacation
veeenu Feb 24, 2024
4d49d6b
Add OpenGL3 demo
veeenu Feb 24, 2024
8482e2e
Change ImguiRenderLoop to accept imgui::Context again
veeenu Feb 24, 2024
8e6def6
Readd render engine
veeenu Feb 24, 2024
322617e
Prepping for GL_EXT_memory_objects_win32
veeenu Feb 25, 2024
133e4e4
Backpedal
veeenu Feb 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env
Cargo.lock
/target
**/*.rs.bk
Expand All @@ -8,3 +9,4 @@ Cargo.lock
/tests/test_sample.exe

.idea
.cargo
29 changes: 28 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ default = ["dx9", "dx11", "dx12", "opengl3", "inject"]
dx9 = []
dx11 = []
dx12 = []
opengl3 = []
opengl3 = ["dep:gl_generator"]
inject = []

[[example]]
Expand All @@ -29,6 +29,26 @@ crate-type = ["cdylib"]
name = "hook_with_image"
crate-type = ["cdylib"]

[[example]]
name = "injector"
crate-type = ["bin"]

[[example]]
name = "demo_hook_dx12"
crate-type = ["cdylib"]

[[example]]
name = "demo_hook_dx11"
crate-type = ["cdylib"]

[[example]]
name = "demo_hook_dx9"
crate-type = ["cdylib"]

[[example]]
name = "demo_hook_opengl3"
crate-type = ["cdylib"]

[dependencies]
imgui = "0.11"
imgui-opengl = "0.1"
Expand All @@ -49,14 +69,19 @@ windows = { version = "0.51.0", features = [
"Win32_System_WindowsProgramming",
"Win32_Graphics_Dxgi",
"Win32_Graphics_Dxgi_Common",
"Win32_Graphics_Direct2D",
"Win32_Graphics_Direct2D_Common",
"Win32_Graphics_Direct3D9",
"Win32_Graphics_Direct3D11on12",
"Win32_Graphics_Direct3D11",
"Win32_Graphics_Direct3D12",
"Win32_Graphics_Direct3D_Fxc",
"Win32_Graphics_Direct3D",
"Win32_Graphics_DirectComposition",
"Win32_Graphics_Dwm",
"Win32_Graphics_Gdi",
"Win32_Graphics_OpenGL",
"Win32_UI_Controls",
"Win32_UI_Input",
"Win32_UI_Input_KeyboardAndMouse",
"Win32_UI_WindowsAndMessaging",
Expand All @@ -67,11 +92,13 @@ once_cell = "1.18.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[dev-dependencies]
dotenv = "0.15.0"
image = "0.24.8"
tracing-subscriber = "0.3"

[build-dependencies]
cc = "1.0.72"
gl_generator = { version = "0.14.0", optional = true }

[profile.test]
opt-level = 3
Expand Down
14 changes: 14 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ fn main() {

println!("cargo:rerun-if-changed=vendor/minhook/src");
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());

#[cfg(feature = "opengl3")]
{
use std::fs::File;

use gl_generator::{Api, Fallbacks, Profile, Registry, StructGenerator};

let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(Path::new(&dest).join("gl_bindings.rs")).unwrap();

Registry::new(Api::Gl, (3, 3), Profile::Core, Fallbacks::All, [])
.write_bindings(StructGenerator, &mut file)
.unwrap();
}
}
56 changes: 56 additions & 0 deletions examples/demo_hook_dx11.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use hudhook::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

pub fn setup_tracing() {
tracing_subscriber::registry()
.with(
fmt::layer().event_format(
fmt::format()
.with_level(true)
.with_thread_ids(true)
.with_file(true)
.with_line_number(true)
.with_thread_names(true),
),
)
.with(EnvFilter::from_default_env())
.init();
}

pub struct HookExample(bool);

impl ImguiRenderLoop for HookExample {
fn render(&mut self, ui: &mut imgui::Ui) {
ui.show_demo_window(&mut self.0);
}
}

/// Entry point created by the `hudhook` library.
///
/// # Safety
///
/// haha
#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(
hmodule: ::hudhook::windows::Win32::Foundation::HINSTANCE,
reason: u32,
_: *mut ::std::ffi::c_void,
) {
if reason == ::hudhook::windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH {
setup_tracing();
alloc_console().unwrap();
::hudhook::tracing::trace!("DllMain()");
::std::thread::spawn(move || {
if let Err(e) = ::hudhook::Hudhook::builder()
.with::<hooks::dx11::ImguiDx11Hooks>(HookExample(true))
.with_hmodule(hmodule)
.build()
.apply()
{
::hudhook::tracing::error!("Couldn't apply hooks: {e:?}");
::hudhook::eject();
}
});
}
}
56 changes: 56 additions & 0 deletions examples/demo_hook_dx12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use hudhook::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

pub fn setup_tracing() {
tracing_subscriber::registry()
.with(
fmt::layer().event_format(
fmt::format()
.with_level(true)
.with_thread_ids(true)
.with_file(true)
.with_line_number(true)
.with_thread_names(true),
),
)
.with(EnvFilter::from_default_env())
.init();
}

pub struct HookExample(bool);

impl ImguiRenderLoop for HookExample {
fn render(&mut self, ui: &mut imgui::Ui) {
ui.show_demo_window(&mut self.0);
}
}

/// Entry point created by the `hudhook` library.
///
/// # Safety
///
/// haha
#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(
hmodule: ::hudhook::windows::Win32::Foundation::HINSTANCE,
reason: u32,
_: *mut ::std::ffi::c_void,
) {
if reason == ::hudhook::windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH {
setup_tracing();
alloc_console().unwrap();
::hudhook::tracing::trace!("DllMain()");
::std::thread::spawn(move || {
if let Err(e) = ::hudhook::Hudhook::builder()
.with::<hooks::dx12::ImguiDx12Hooks>(HookExample(true))
.with_hmodule(hmodule)
.build()
.apply()
{
::hudhook::tracing::error!("Couldn't apply hooks: {e:?}");
::hudhook::eject();
}
});
}
}
56 changes: 56 additions & 0 deletions examples/demo_hook_dx9.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use hudhook::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

pub fn setup_tracing() {
tracing_subscriber::registry()
.with(
fmt::layer().event_format(
fmt::format()
.with_level(true)
.with_thread_ids(true)
.with_file(true)
.with_line_number(true)
.with_thread_names(true),
),
)
.with(EnvFilter::from_default_env())
.init();
}

pub struct HookExample(bool);

impl ImguiRenderLoop for HookExample {
fn render(&mut self, ui: &mut imgui::Ui) {
ui.show_demo_window(&mut self.0);
}
}

/// Entry point created by the `hudhook` library.
///
/// # Safety
///
/// haha
#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(
hmodule: ::hudhook::windows::Win32::Foundation::HINSTANCE,
reason: u32,
_: *mut ::std::ffi::c_void,
) {
if reason == ::hudhook::windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH {
setup_tracing();
alloc_console().unwrap();
::hudhook::tracing::trace!("DllMain()");
::std::thread::spawn(move || {
if let Err(e) = ::hudhook::Hudhook::builder()
.with::<hooks::dx9::ImguiDx9Hooks>(HookExample(true))
.with_hmodule(hmodule)
.build()
.apply()
{
::hudhook::tracing::error!("Couldn't apply hooks: {e:?}");
::hudhook::eject();
}
});
}
}
56 changes: 56 additions & 0 deletions examples/demo_hook_opengl3.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use hudhook::*;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

pub fn setup_tracing() {
tracing_subscriber::registry()
.with(
fmt::layer().event_format(
fmt::format()
.with_level(true)
.with_thread_ids(true)
.with_file(true)
.with_line_number(true)
.with_thread_names(true),
),
)
.with(EnvFilter::from_default_env())
.init();
}

pub struct HookExample(bool);

impl ImguiRenderLoop for HookExample {
fn render(&mut self, ui: &mut imgui::Ui) {
ui.show_demo_window(&mut self.0);
}
}

/// Entry point created by the `hudhook` library.
///
/// # Safety
///
/// haha
#[no_mangle]
pub unsafe extern "stdcall" fn DllMain(
hmodule: ::hudhook::windows::Win32::Foundation::HINSTANCE,
reason: u32,
_: *mut ::std::ffi::c_void,
) {
if reason == ::hudhook::windows::Win32::System::SystemServices::DLL_PROCESS_ATTACH {
setup_tracing();
alloc_console().unwrap();
::hudhook::tracing::trace!("DllMain()");
::std::thread::spawn(move || {
if let Err(e) = ::hudhook::Hudhook::builder()
.with::<hooks::opengl3::ImguiOpenGl3Hooks>(HookExample(true))
.with_hmodule(hmodule)
.build()
.apply()
{
::hudhook::tracing::error!("Couldn't apply hooks: {e:?}");
::hudhook::eject();
}
});
}
}
4 changes: 2 additions & 2 deletions examples/hook_with_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use hudhook::renderer::RenderEngine;
use hudhook::ImguiRenderLoop;
use image::io::Reader as ImageReader;
use image::{EncodableLayout, RgbaImage};
use imgui::{Condition, Image, TextureId};
use imgui::{Condition, Context, Image, TextureId};
use tracing_subscriber::prelude::*;
use tracing_subscriber::{fmt, EnvFilter};

Expand Down Expand Up @@ -49,7 +49,7 @@ impl Default for HookExample {
}

impl ImguiRenderLoop for HookExample {
fn initialize(&mut self, render_engine: &mut RenderEngine) {
fn initialize(&mut self, _ctx: &mut Context, render_engine: &mut RenderEngine) {
self.image_id = render_engine
.load_image(self.image.as_bytes(), self.image.width() as _, self.image.height() as _)
.ok();
Expand Down
12 changes: 12 additions & 0 deletions examples/injector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::path::PathBuf;

use hudhook::inject::Process;

fn main() {
let mut args = std::env::args();
args.next().unwrap();
let name = args.next().unwrap();
let dll: PathBuf = args.next().unwrap().into();
let process = Process::by_name(&name).expect("Process by name");
process.inject(dll).expect("Inject");
}
Loading
Loading