-
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
Replace iterators with slices (Non command buffer) #1665
Conversation
5bbd24b
to
baec41f
Compare
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.
Thank you for amazing work!
Those type signatures became really scary... And if for command buffer we had to go the zero overhead route, it's not as important here, since device functions are (or can be) slow by nature of HW, and the backends aren't currently trying to avoid allocations either (even though, they could in the future).
I'm not sure if we should make this call.
Pros:
- less overhead for device functions
Cons: - scary API, documentation
src/backend/empty/src/lib.rs
Outdated
&self, | ||
_: &[pso::GraphicsPipelineDesc<'a, Backend>], | ||
) -> Vec<Result<(), pso::CreationError>> { | ||
fn create_graphics_pipeline<'a, T>(&self, _: T) -> Result<(), pso::CreationError> |
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.
can't we just have &pso::GraphicsPipelineDesc<'a, Backend>
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.
Yes, the generic is completely unnecessary and doesn't provide any benefit.
src/backend/gl/src/device.rs
Outdated
@@ -328,7 +350,8 @@ impl d::Device<B> for Device { | |||
gl.BindFramebuffer(target, 0); | |||
} | |||
if let Err(err) = self.share.check() { | |||
panic!("Error creating FBO: {:?} for {:?} with attachments {:?}", err, pass, attachments); | |||
//TODO: attachments has been consumed |
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.
should be "have been"
I agree that the documentation would be a bit scary, but I'm not sure about API though; another pro is that this change means that the functions accept anything that looks vaguely like an iterator, which should simplify user's code. |
src/backend/vulkan/src/device.rs
Outdated
let mut color_attachments = Vec::with_capacity(descs.len()); | ||
let mut info_specializations = Vec::with_capacity(descs.len() * NUM_STAGES); | ||
let mut specialization_data = Vec::with_capacity(descs.len() * NUM_STAGES); | ||
let mut info_stages = Vec::with_capacity(desc_len_guess); |
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.
Before I forget it over the holidays.. it crucial in the current implementation that these vectors don't reallocate memory because we have pointers into the vector elements floating around.
This needs some serious documentation to make it obvious what types are accepted imho. |
548506c
to
69fc536
Compare
Amazing work! I definitely appreciate the bidirectional implementations and iterators for methods accepting a single list. The Reviewed 27 of 27 files at r1. examples/hal/compute/main.rs, line 145 at r1 (raw file):
really nice to have this shortcut examples/hal/quad/main.rs, line 164 at r1 (raw file):
nit: could probably also do src/backend/dx12/src/device.rs, line 444 at r1 (raw file):
should this be src/backend/dx12/src/device.rs, line 787 at r1 (raw file):
maybe we could apply some fair judgement and not try to optimize at least this method? no one is creating render passes on the fly (I hope) src/backend/dx12/src/device.rs, line 814 at r1 (raw file):
FTR, doesn't look like generic iterators are making any good for this specific implementation src/backend/dx12/src/device.rs, line 939 at r1 (raw file):
similarly, I don't expect this to be called often src/backend/vulkan/Cargo.toml, line 25 at r1 (raw file):
this can be reverted now src/hal/src/device.rs, line 203 at r1 (raw file):
strange idea: maybe we can omit this from src/hal/src/device.rs, line 494 at r1 (raw file):
I'm a little concerned that his would prevent the expected behavior when the user passes in timeout of src/hal/src/device.rs, line 505 at r1 (raw file):
why do we need to collect here? src/render/src/device.rs, line 312 at r1 (raw file):
don't bother updating the src/render/src/pso.rs, line 179 at r1 (raw file):
similarly, here. Current consensus is that Comments from Reviewable |
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.
Great work! Requires a few changes as requested by kvark otherwise ready to go from my side 👍
if as_ms(start.elapsed()) >= timeout_ms { | ||
return false; | ||
} | ||
thread::sleep(time::Duration::from_millis(1)); |
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 don't think we need issue a thread switch here, drivers will most likely do it internally anyways.
@kvark I'm in favor of keeping the iterator interface everywhere.
|
Ok, I'm fine with going all-in for iterators. Let's rebase this, address my concerns, and proceed. |
69fc536
to
28398a5
Compare
Review status: 16 of 25 files reviewed at latest revision, 13 unresolved discussions. examples/hal/quad/main.rs, line 164 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Sadly no, set_layout is used later and src/hal/src/device.rs, line 203 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
I'm not sure, not implementing either will probably do something funky at compile time, but src/hal/src/device.rs, line 494 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
I think this should work as expected now. src/hal/src/device.rs, line 505 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
src/hal/src/device.rs, line 515 at r1 (raw file): Previously, msiglreith wrote…
Could this not be a problem for the Mutex simulated fences in Metal, it will now just spin? Comments from Reviewable |
Review status: 16 of 25 files reviewed at latest revision, 13 unresolved discussions. src/hal/src/device.rs, line 515 at r1 (raw file): Previously, AIOOB (AIOOB) wrote…
wait_on_fence handling is a bit out of scope atm, but we should rather use native primitives for synchronization (in particular semaphores here) than trying to create our own with locks, loops, etc. IMO Comments from Reviewable |
Review status: 16 of 25 files reviewed at latest revision, 12 unresolved discussions. src/hal/src/device.rs, line 203 at r1 (raw file): Previously, AIOOB (AIOOB) wrote…
It's easy to try out, right? Just go to the empty backend, comment out a few methods, and see if it builds. I expect it to compile fine but go to the stack overflow when run. And this would be fine to me, since I don't think there is any value in guaranteeing the empty backend to instantly panic: it's only there to compile-test against. src/hal/src/device.rs, line 494 at r1 (raw file): Previously, AIOOB (AIOOB) wrote…
Well, technically, no. The src/hal/src/device.rs, line 505 at r1 (raw file): Previously, AIOOB (AIOOB) wrote…
Oh I see now. src/hal/src/device.rs, line 515 at r1 (raw file): Previously, msiglreith wrote…
In general, either there is a simple working default implementation, or just defer this decision to the backends. In this case, there appear to be enough concerns to consider this a non-trivial implementaiton. Comments from Reviewable |
28398a5
to
829843e
Compare
I think that its most things addressed. The only things that I can see that could be added are single variant versions of |
@aioob alright, shipit! |
1665: Replace iterators with slices (Non command buffer) r=kvark a=AIOOB A more debatable half of #1604, which APIs use slices and which should use iterators is more up for consideration. My implementation for the Device iterators frequently just collects them anyway which to me suggests there isn't much point (apart from some idea of API uniformity). <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/gfx-rs/gfx/1665) <!-- Reviewable:end -->
There appears to be general agreement on the topic. We can nail down the details (descriptor sets) in follow ups, if needed. |
A more debatable half of #1604, which APIs use slices and which should use iterators is more up for consideration. My implementation for the Device iterators frequently just collects them anyway which to me suggests there isn't much point (apart from some idea of API uniformity).
This change is