-
Notifications
You must be signed in to change notification settings - Fork 543
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
[WIP] Merge window creation between backends #2136
Conversation
77af818
to
c98b8b8
Compare
src/hal/src/lib.rs
Outdated
@@ -375,6 +375,8 @@ pub trait Backend: 'static + Sized + Eq + Clone + Hash + fmt::Debug + Any + Send | |||
type Fence: fmt::Debug + Any + Send + Sync; | |||
type Semaphore: fmt::Debug + Any + Send + Sync; | |||
type QueryPool: fmt::Debug + Any + Send + Sync; | |||
|
|||
type Window: Any + Send + Sync; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be here, ideally.
Could you explain the thought process that leaded you to this decision? GL should not affect our HAL API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, the gl backend and the non gl backends use a different type for their windows, so I wanted to avoid having to define a type in the examples based on which backend is in use. But then I relized that we won't have a type to use for people not using either winit or glutin, so I'm already aware that it's going to need to get stripped out.
07fee6c
to
15d9dc4
Compare
Latest version was tested against rust-windowing/winit@c873c2d and goddessfreya/glutin@cdad4a9 FYI |
@@ -886,9 +886,13 @@ impl command::RawCommandBuffer<Backend> for RawCommandBuffer { | |||
for new_binding in &*desc_set.bindings.lock().unwrap() { | |||
match new_binding { | |||
n::DescSetBindings::Buffer {ty: btype, binding, buffer, offset, size} => { | |||
let btype = match btype { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not strictly necessary and could be separated into a separate PR.
15d9dc4
to
cd1a044
Compare
A couple notes:
Anyways, I quick summary of this PR off the top of my head is that we:
Edit: I've typed this big block of text at 1:34 AM so forgive me for any errors (and for the block of text). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I skimmed through it, need to re-read your comments and have another look.
let (window, _instance, mut adapters, mut surface) = { | ||
let window = wb.build(&events_loop).unwrap(); | ||
let instance = back::Instance::create("gfx-rs quad", 1); | ||
let instance = back::Instance::create("gfx-rs quad", 1, Arc::clone(&events_loop)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how would this map to gfx-portability? We don't have the event loop when we are creating an instance there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no clue, I'd have to look into it.
src/backend/gl/src/device.rs
Outdated
@@ -424,6 +428,74 @@ impl Device { | |||
} | |||
} | |||
} | |||
|
|||
pub fn create_shader_program<'a>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these changes a part of the windowing PR? or just refactoring accidentally got mixed in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to avoid re implementing create_shader_programs when making the shader for the swapchain quad stuff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need a shader?
src/backend/gl/src/lib.rs
Outdated
pub struct Instance { | ||
el: Arc<Mutex<glutin::EventsLoop>>, | ||
context: glutin::Context, | ||
pub(crate) quadvbo: Arc<Mutex<Option<u32>>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you can insert _
between words
src/backend/gl/src/lib.rs
Outdated
Arc::new(Instance { | ||
el, | ||
context, | ||
quadvbo: Arc::new(Mutex::new(None)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why aren't we initializing those here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't loaded the gl pointers yet nor done the stuff which is done when opening the device. I'm not actually sure what the opening the device stuff is done for so I avoided changing that code and just made the stuff get initialized when making a swap chain the first time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could make the physical device & open the device once in the instance then just return those. I think that's what I'll change it to do, and then we can avoid reloading the gl ptrs in drop.
src/backend/gl/src/lib.rs
Outdated
impl Drop for Instance { | ||
fn drop(&mut self) { | ||
unsafe { | ||
let gl = gl::Gl::load_with(|s| self.context.get_proc_address(s) as *const _); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we loading GL pointers here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the instance doesn't have a copy of the share or the gl ptrs, so it's easier (and still correct) to just load them in again.
@zegentzy what do you think about my earlier plan to go with the "pure" GL context (for the Instance) and sharing for all the others (created per window/swapchain)? Would it still be compatible with your approach if we get rust-windowing/glutin#942 merged eventually? |
I don't see why it wouldn't work, instead of sharing everything with the instance's context, we share them with each other. Then we need to make current the context for the window we are using. Which method is preferable is up to debate, and I personally don't have an opinion on this. |
964ff92
to
48c51b7
Compare
We now all the shared stuff in the instance. We now automatically change contexts only when necessary. |
48c51b7
to
291833c
Compare
We just blit fbo's now as discussed on gitter with @kvark . |
073ed46
to
cacdb1f
Compare
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
Signed-off-by: Hal Gentz <zegentzy@protonmail.com>
cacdb1f
to
d6be479
Compare
Honestly, this just makes the code a lot uglier, and after a five second glance at gfx-portability I relied that this wouldn't work. Shame, because the only reason I tried this was to get the GL backend to be added to gfx-portability. I'll sleep on this and think of a different solution. |
2211: Latest winit, dpi bugfix and remap descriptors fix. r=kvark a=ZeGentzy Some minor fixes I did while working on #2136 PR checklist: - [ ] `make` succeeds (on *nix) - [ ] `make reftests` succeeds - [x] tested examples with the following backends: gl + vulkan on archlinux Co-authored-by: Hal Gentz <zegentzy@protonmail.com>
Signed-off-by: Hal Gentz zegentzy@protonmail.com
Fixes #1619
PR checklist:
make
succeeds (on *nix)make reftests
succeeds