[Mesa-dev] [RFCv0 0/8] gallium: add support for NIR as alternate IR
robdclark at gmail.com
Tue Oct 20 05:37:15 PDT 2015
On Tue, Oct 20, 2015 at 6:49 AM, Marek Olšák <maraeo at gmail.com> wrote:
> On Tue, Oct 20, 2015 at 3:51 AM, Rob Clark <robdclark at gmail.com> wrote:
>> On Mon, Oct 19, 2015 at 8:53 PM, Marek Olšák <maraeo at gmail.com> wrote:
>>> Yes, drivers need to "dup" tokens if they want to keep them. Their
>>> lifetime is the create function and that's it. st/mesa only keeps the
>>> tokens for vertex shaders, because it needs for emulating some
>>> features with the Draw module.
>> It is something that I think would be worth revisiting, since the
>> common case is that drivers have to dup the tokens to do their own
>> variant mgmt.. so that seems like the better case to optimize for. I
>> think the only one that isn't doing it's own variant mgmt is nouveau,
>> but Ilia mentioned at some point that there where some edge cases
>> where they really do need a variant.
> This would add more cruft into state trackers and modules. Doing "dup"
> in the driver is the easiest way to handle this.
> Also, drivers should be able to release any incoming IR if they don't
> need it. Including NIR. Having a requirement that some IR must be in
> memory for the lifetime of shaders is just overall a bad idea.
If you need to create variants, you need to hang on to the IR until
all possible variants are created (ie. forever)
But if we are changing things, we could also just redefine things that
the driver takes ownership of the IR and frees it whenever it feels
>> it would be a lot of churn to change this for the tgsi case, but I
>> still think worthwhile. Either way, I think we should at least
>> consider this while introducing the possibility for other IR's (since
>> cloning llvm or nir, for example, would be more expensive than cloning
> For more complex IRs and *if* drivers want to keep them (some really
> don't), you need reference counting on the whole IR, so that state
> trackers can unreference it and drivers can keep it.
It could be an idea.. we'd have to track down and clean up all the
various different ways that tgsi is freed
(tgsi_free_tokens()/ureg_free_tokens().. maybe some places are just
calling free() directly?). For NIR, everyone just calls ralloc_free()
directly, but there aren't so many users yet so I guess not too hard
to track down.
I guess at least for NIR (since the IR is mutable) some minor smarts
would be needed when driver wants a writeable copy to see if there is
only a single outstanding reference to the IR (and clone otherwise).
More information about the mesa-dev