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

What if Ash #12

Closed
wants to merge 21 commits into from
Closed

What if Ash #12

wants to merge 21 commits into from

Conversation

zakarumych
Copy link
Member

@zakarumych zakarumych commented Oct 28, 2018

This PR accumulates lots of commits I made for last weekend.
Overview:

  • Abandon hal for now.
  • Restructure into more self-contained crates. Main crate only reexports sub-crates
  • Add examples to main crate:
    1. init example loads Vulkan by instantiating Factory.
    2. window example uses wsi sub-crate to create render target for window.
    3. simple example (WIP) draws simple mesh.

This change is Reviewable

Copy link
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Looking forward to using it. 👍

}

#[allow(unused)]
fn fmt_version(version: &u32, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use std::fmt::Formatter now in 1.30 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally.
Can I omit extern crate <name>; now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so that will probably come in the next few releases as we inch closer to 2018 edition

extensions: Vec<ExtensionProperties>,
}

/// The `Factory<D>` type represents the overall creation type for `rendy`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the generic on the Factory type I believe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -0,0 +1,38 @@

# `gfx-mesh`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops.

hal = ["gfx-hal", "rendy-memory/hal", "rendy-resource/hal", "rendy-command/hal"]
vulkan = ["ash", "rendy-memory/vulkan", "rendy-resource/vulkan", "rendy-command/vulkan"]
[dev-dependencies]
ash = { path = "../../ash/ash" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you say what version of ash? I'm assuming off of the code that is in the WIP builder branch of ash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's MatusT's fork, generator branch, with my patch.
It must be in main repo generator branch soon (before merge).
If needed I can put it into my own fork for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that would be useful so I can try and build this locally as well 👍

Copy link
Contributor

@dotellie dotellie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I say wow? Awesome job Viral! I'm still not 100% convinced about removing hal considering we already had so much of the abstraction in place, but I'm sure you have a good plan for it.

}
}

pub unsafe trait HeapsConfigure {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name seems a bit off to me. Shouldn't it be something like HeapsConfig or HeapsConfiguration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a configuration, it's a configurer. I would opt for something like ConfigureHeaps or HeapsConfigurer.

}?;
trace!("Instance created");

let surface = Surface::new(&entry, &instance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we really provide a surface by default? I may be wrong here, but in VR for example, although you do almost always end up with a window somehow, it might now be desirable to have. Rather you would just use whatever you get from the compositor.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we shouldn't. We'll add it to configuration.

.application_name(&CString::new(config.app_name)?)
.application_version(config.app_version)
.build(),
).enabled_extension_names(&extensions_to_enable(&extensions)?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just enabling all extensions unconditionally? I think a better solution would be to have a set of required extensions that rendy always requires and then allow the user to pass in what extensions they need.

physical.handle,
&DeviceCreateInfo::builder()
.queue_create_infos(&create_queues)
.enabled_extension_names(&extensions_to_enable(&physical.extensions).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a callback here to enable more extensions. OpenVR (and probably more XR compositors) require to be able to enable specific extensions based off of a physical device.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. I'll add a TODO

.cloned()
.filter_map(|name| {
let cstr_name = CStr::from_ptr(name);
trace!("Look for {:?}", cstr_name);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify what you're looking for here so the logs aren't too confusing to someone that doesn't really know graphics programming? 😅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my debugging stuff 😅

#[derivative(Debug(bound = "T: Debug", format_with = "super::memory_ptr_fmt"))]
memory: *const Memory<T>,
pub struct ArenaBlock {
// #[derivative(Debug(format_with = "::memory::memory_ptr_fmt"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Derivative seems broken somehow. I'll uncomment once it works again.

index: u32,
#[derivative(Debug(bound = "T: Debug", format_with = "super::memory_ptr_fmt"))]
memory: *const Memory<T>,
// #[derivative(Debug(format_with = "super::memory_ptr_fmt"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code

match block {
BlockFlavor::Dedicated(block) => self.dedicated.free(device, block),
BlockFlavor::Arena(block) => self.arena.as_mut().unwrap().free(device, block),
BlockFlavor::Dynamic(block) => self.dynamic.as_mut().unwrap().free(device, block),
// BlockFlavor::Chunk(block) => self.chunk.free(device, block),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come you removed this line when you still have Chunk commented out on the various config structs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should remove it everywhere.

len,
})
}).collect::<Result<_, Error>>()?,
ibuf: match self.indices {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this match can be replaced with a simple .map()


/// Error type returned by `Mesh::bind` in case of mesh's vertex buffers are incompatible with requested vertex formats.
#[derive(Clone, Copy, Debug)]
pub struct Incompatible;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we have a failure error enum here like for the other crates?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely

@kvark
Copy link
Member

kvark commented Oct 29, 2018

What's the reasoning behind "Abandon hal for now."?

"Arenas are not empty during allocator disposal. Arenas: {:#?}",
self.arenas
);
if !self.arenas.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add debug_assert maybe? So it crashes on debug mode, but only logs on release?

@zakarumych
Copy link
Member Author

zakarumych commented Oct 30, 2018

@kvark without reinventing the wheel (abstraction layer over ash and hal 😓) I'm way more productive.

Instead of providing own abstractions I believe it is better to implement ash::DeviceV* etc traits for hal. I heard that someone already suggesting to do so (or even started).
Then to work over hal rendy would only need to parametrize Factory type.

@Moxinilian
Copy link
Member

Moxinilian commented Oct 31, 2018

To the reader: please note that "dropping hal" does not mean that hal will not have anything to do with rendy. Viral is focusing on ash right now as it is closer to Vulkan so easier to use for him, but when all of this is done rendy is made in such a way that it will be "easy" to implement the hal backend. It's just to not have to implement two backends at once.

@kvark
Copy link
Member

kvark commented Oct 31, 2018

@Moxinilian thank you for clarification. I don't see the story the same way. gfx-hal is already pretty much Vulkan, just a bit rustier (borrowing, move semantics, and references instead of pointers and opaque handles). You could just have used gfx-hal and have access to all platforms, while benefiting gfx-rs community with your feedback.

Truth is that @omni-viral found gfx-hal inconvenient for their needs, hence the departure. I don't see it temporary. The expressed solution (in https://github.com/rustgd/rendy/pull/12#issuecomment-434338491) is basically - solve it on the Ash level, so that Amethyst wouldn't care about gfx-rs APIs.

Tight Ash (and Vulkano) integration is certainly one of our goals, but it's not going to be the most performant path at the end of the day, so we'd like Rust projects which really need performance (like Amethyst and WebRender) to work with gfx-hal directly.

@Moxinilian
Copy link
Member

Moxinilian commented Oct 31, 2018

There is enough motivation within the Amethyst team to make sure hal will be supported by rendy, most notably in the perspective of WebGL (and eventually WebGPU). From what has been discussed on Discord, it seems like first class hal is planned in the future.

If I misunderstood, then this is going to be a much larger issue considering Amethyst's next step after mobile support will be web technologies, in which gfx-hal would help in a significant way.

@kvark
Copy link
Member

kvark commented Oct 31, 2018

@Moxinilian FYI, this is a very poor communication on the Amethyst side. Your team discussed something on discord (which we don't even have any visibility into, since we use Gitter) and decided to drop gfx-hal without any heads up to our team, without even bothering to explain this in PR description... We hope that in the future, if there is any news of that scale, we'd know about it from you.

@Moxinilian
Copy link
Member

Yes, I agree. If I recall correctly, an issue is being written to be posted on the gfx issue tracker regarding the reasons for such a decision. I still believe that supporting hal from the ground up would have been better, but I am not involved enough in rendering to have a meaningful opinion.

@Moxinilian
Copy link
Member

We handled this very poorly, and apologize to the entire gfx-hal team. It was inexcusable, and we will take steps internally to ensure it doesn't happen again. We would like to re-open a dialog on this with the gfx-hal team, if they are ok with it.

@zakarumych
Copy link
Member Author

@kvark Sorry I didn't explained in detail why I abandoned hal in this PR. I also sad for that I didn't state my opinion clearly in gfx-rs/gfx#2206 😭

Correct me if I'm wrong.
As I understand it the main idea of hal API to stay is that it is rustier and reduces boxing overhead over non-Vulkan backends. But I also see calling overhead in hal's API for Vulkan backend which you underestimate (I think). Hence I'd really like to see ash's API implemented for hal's backends (notably metal backend which is awesome 👍).

Sorry. It's hard for me to express sophisticated stuff in language I barely know. It took me 15 minutes to write this comment 😅

@torkleyy torkleyy mentioned this pull request Oct 31, 2018
@zakarumych zakarumych changed the title Getting rendy ready What if Ash Nov 4, 2018
@zakarumych zakarumych closed this Nov 13, 2018
@zakarumych zakarumych deleted the ash branch November 30, 2018 11:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants