<div dir="ltr"><div dir="ltr">> So far, we've been trying to build those components in terms of the Vulkan API itself with calls jumping back into the dispatch table to try and get inside the driver. This is working but it's getting more and more fragile the more tools we add to that box. A lot of what I want to do with gallium2 or whatever we're calling it is to fix our layering problems so that calls go in one direction and we can untangle the jumble. I'm still not sure what I want that to look like but I think I want it to look a lot like Vulkan, just with a handier interface.</div><div><br></div><div>That resonates with my experience. For example, Galllium draw module does some of this too -- it provides its own internal interfaces for drivers, but it also loops back into Gallium top interface to set FS and rasterizer state -- and that has <u>always</u> been a source of grief. Having control flow proceeding through layers in one direction only seems an important principle to observe. It's fine if the lower interface is the same interface (e.g., Gallium to Gallium, or Vulkan to Vulkan as you allude), but they shouldn't be the same exact entry-points/modules (ie, no reentrancy/recursion.)</div><div><br></div><div>It's also worth considering that Vulkan extensibility could come in hand too in what you want to achieve. For example, Mesa Vulkan drivers could have their own VK_MESA_internal_xxxx extensions that could be used by the shared Vulkan code to do lower level things.</div><div><div dir="ltr"><br></div><div>Jose</div><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 24, 2024 at 3:26 PM Faith Ekstrand <<a href="mailto:faith@gfxstrand.net">faith@gfxstrand.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Jose,<br>
<br>
Thanks for your thoughts!<br>
<br>
On Wed, Jan 24, 2024 at 4:30 AM Jose Fonseca <<a href="mailto:jose.fonseca@broadcom.com" target="_blank">jose.fonseca@broadcom.com</a>> wrote:<br>
><br>
> I don't know much about the current Vulkan driver internals to have or provide an informed opinion on the path forward, but I'd like to share my backwards looking perspective.<br>
><br>
> Looking back, Gallium was two things effectively:<br>
> (1) an abstraction layer, that's watertight (as in upper layers shouldn't reach through to lower layers)<br>
> (2) an ecosystem of reusable components (draw, util, tgsi, etc.)<br>
><br>
> (1) was of course important -- and the discipline it imposed is what enabled to great simplifications -- but it also became a straight-jacket, as GPUs didn't stand still, and sooner or later the see-every-hardware-as-the-same lenses stop reflecting reality.<br>
><br>
> If I had to pick one, I'd say that (2) is far more useful and practical. Take components like gallium's draw and other util modules. A driver can choose to use them or not. One could fork them within Mesa source tree, and only the drivers that opt-in into the fork would need to be tested/adapted/etc<br>
><br>
> On the flip side, Vulkan API is already a pretty low level HW abstraction. It's also very flexible and extensible, so it's hard to provide a watertight abstraction underneath it without either taking the lowest common denominator, or having lots of optional bits of functionality governed by a myriad of caps like you alluded to.<br>
<br>
There is a third thing that isn't really recognized in your description:<br>
<br>
(3) A common "language" to talk about GPUs and data structures that<br>
represent that language<br>
<br>
This is precisely what the Vulkan runtime today doesn't have. Classic<br>
meta sucked because we were trying to implement GL in GL. u_blitter,<br>
on the other hand, is pretty fantastic because Gallium provides a much<br>
more sane interface to write those common components in terms of.<br>
<br>
So far, we've been trying to build those components in terms of the<br>
Vulkan API itself with calls jumping back into the dispatch table to<br>
try and get inside the driver. This is working but it's getting more<br>
and more fragile the more tools we add to that box. A lot of what I<br>
want to do with gallium2 or whatever we're calling it is to fix our<br>
layering problems so that calls go in one direction and we can<br>
untangle the jumble. I'm still not sure what I want that to look like<br>
but I think I want it to look a lot like Vulkan, just with a handier<br>
interface.<br>
<br>
~Faith<br>
<br>
> Not sure how useful this is in practice to you, but the lesson from my POV is that opt-in reusable and shared libraries are always time well spent as they can bend and adapt with the times, whereas no opt-out watertight abstractions inherently have a shelf life.<br>
><br>
> Jose<br>
><br>
> On Fri, Jan 19, 2024 at 5:30 PM Faith Ekstrand <<a href="mailto:faith@gfxstrand.net" target="_blank">faith@gfxstrand.net</a>> wrote:<br>
>><br>
>> Yeah, this one's gonna hit Phoronix...<br>
>><br>
>> When we started writing Vulkan drivers back in the day, there was this<br>
>> notion that Vulkan was a low-level API that directly targets hardware.<br>
>> Vulkan drivers were these super thin things that just blasted packets<br>
>> straight into the hardware. What little code was common was small and<br>
>> pretty easy to just copy+paste around. It was a nice thought...<br>
>><br>
>> What's happened in the intervening 8 years is that Vulkan has grown. A lot.<br>
>><br>
>> We already have several places where we're doing significant layering.<br>
>> It started with sharing the WSI code and some Python for generating<br>
>> dispatch tables. Later we added common synchronization code and a few<br>
>> vkFoo2 wrappers. Then render passes and...<br>
>><br>
>> <a href="https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27024" rel="noreferrer" target="_blank">https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27024</a><br>
>><br>
>> That's been my project the last couple weeks: A common VkPipeline<br>
>> implementation built on top of an ESO-like interface. The big<br>
>> deviation this MR makes from prior art is that I make no attempt at<br>
>> pretending it's a layered implementation. The vtable for shader<br>
>> objects looks like ESO but takes its own path when it's useful to do<br>
>> so. For instance, shader creation always consumes NIR and a handful of<br>
>> lowering passes are run for you. It's no st_glsl_to_nir but it is a<br>
>> bit opinionated. Also, a few of the bits that are missing from ESO<br>
>> such as robustness have been added to the interface.<br>
>><br>
>> In my mind, this marks a pretty fundamental shift in how the Vulkan<br>
>> runtime works, at least in my mind. Previously, everything was<br>
>> designed to be a toolbox where you can kind of pick and choose what<br>
>> you want to use. Also, everything at least tried to act like a layer<br>
>> where you still implemented Vulkan but you could leave out bits like<br>
>> render passes if you implemented the new thing and were okay with the<br>
>> layer. With the ESO code, you implement something that isn't Vulkan<br>
>> entrypoints and the actual entrypoints live in the runtime. This lets<br>
>> us expand and adjust the interface as needed for our purposes as well<br>
>> as sanitize certain things even in the modern API.<br>
>><br>
>> The result is that NVK is starting to feel like a gallium driver. 🙃<br>
>><br>
>> So here's the question: do we like this? Do we want to push in this<br>
>> direction? Should we start making more things work more this way? I'm<br>
>> not looking for MRs just yet nor do I have more reworks directly<br>
>> planned. I'm more looking for thoughts and opinions as to how the<br>
>> various Vulkan driver teams feel about this. We'll leave the detailed<br>
>> planning for the Mesa issue tracker.<br>
>><br>
>> It's worth noting that, even though I said we've tried to keep things<br>
>> layerish, there are other parts of the runtime that look like this.<br>
>> The synchronization code is a good example. The vk_sync interface is<br>
>> pretty significantly different from the Vulkan objects it's used to<br>
>> implement. That's worked out pretty well, IMO. With as complicated as<br>
>> something like pipelines or synchronization are, trying to keep the<br>
>> illusion of a layer just isn't practical.<br>
>><br>
>> So, do we like this? Should we be pushing more towards drivers being a<br>
>> backed of the runtime instead of a user of it?<br>
>><br>
>> Now, before anyone asks, no, I don't really want to build a multi-API<br>
>> abstraction with a Vulkan state tracker. If we were doing this 5 years<br>
>> ago and Zink didn't already exist, one might be able to make an<br>
>> argument for pushing in that direction. However, that would add a huge<br>
>> amount of weight to the project and make it even harder to develop the<br>
>> runtime than it already is and for little benefit at this point.<br>
>><br>
>> Here's a few other constraints on what I'm thinking:<br>
>><br>
>> 1. I want it to still be possible for drivers to implement an<br>
>> extension without piles of runtime plumbing or even bypass the runtime<br>
>> on occasion as needed.<br>
>><br>
>> 2. I don't want to recreate the gallium cap disaster drivers should<br>
>> know exactly what they're advertising. We may want to have some<br>
>> internal features or properties that are used by the runtime to make<br>
>> decisions but they'll be in addition to the features and properties in<br>
>> Vulkan.<br>
>><br>
>> 3. We've got some meta stuff already but we probably want more.<br>
>> However, I don't want to force meta on folks who don't want it.<br>
>><br>
>> The big thing here is that if we do this, I'm going to need help. I'm<br>
>> happy to do a lot of the architectural work but drivers are going to<br>
>> have to keep up with the changes and I can't take on the burden of<br>
>> moving 8 different drivers forward. I can answer questions and maybe<br>
>> help out a bit but the refactoring is going to be too much for one<br>
>> person, even if that person is me.<br>
>><br>
>> Thoughts?<br>
>><br>
>> ~Faith<br>
><br>
><br>
> This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.<br>
</blockquote></div></div></div>
<br>
<span style="background-color:rgb(255,255,255)"><font size="2">This electronic communication and the information and any files transmitted with it, or attached to it, are confidential and are intended solely for the use of the individual or entity to whom it is addressed and may contain information that is confidential, legally privileged, protected by privacy laws, or otherwise restricted from disclosure to anyone else. If you are not the intended recipient or the person responsible for delivering the e-mail to the intended recipient, you are hereby notified that any use, copying, distributing, dissemination, forwarding, printing, or copying of this e-mail is strictly prohibited. If you received this e-mail in error, please return the e-mail to the sender, delete it from your computer, and destroy any printed copy of it.</font></span>