From: Danilo Krummrich <dakr@kernel.org>
To: Lyude Paul <lyude@redhat.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
rust-for-linux@vger.kernel.org,
"Alice Ryhl" <aliceryhl@google.com>,
"Daniel Almeida" <daniel.almeida@collabora.com>,
"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
"Maxime Ripard" <mripard@kernel.org>,
"Thomas Zimmermann" <tzimmermann@suse.de>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
"Miguel Ojeda" <ojeda@kernel.org>,
"Alex Gaynor" <alex.gaynor@gmail.com>,
"Boqun Feng" <boqun.feng@gmail.com>,
"Gary Guo" <gary@garyguo.net>,
"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
"Benno Lossin" <lossin@kernel.org>,
"Andreas Hindborg" <a.hindborg@kernel.org>,
"Trevor Gross" <tmgross@umich.edu>,
"Asahi Lina" <lina+kernel@asahilina.net>,
"open list:DRM DRIVER FOR NVIDIA GPUS [RUST]"
<nouveau@lists.freedesktop.org>
Subject: Re: [PATCH v4 1/3] rust: drm: gem: Simplify use of generics
Date: Mon, 8 Sep 2025 21:04:46 +0200 [thread overview]
Message-ID: <b92c52f8-d5b5-45ba-9195-9d8e20b41f0e@kernel.org> (raw)
In-Reply-To: <20250908185239.135849-2-lyude@redhat.com>
On 9/8/25 8:46 PM, Lyude Paul wrote:
> Now that my rust skills have been honed, I noticed that there's a lot of
> generics in our gem bindings that don't actually need to be here. Currently
> the hierarchy of traits in our gem bindings looks like this:
>
> * Drivers implement:
> * BaseDriverObject<T: DriverObject> (has the callbacks)
> * DriverObject (has the drm::Driver type)
> * Crate implements:
> * IntoGEMObject for Object<T> where T: DriverObject
> Handles conversion to/from raw object pointers
> * BaseObject for T where T: IntoGEMObject
> Provides methods common to all gem interfaces
>
> Also of note, this leaves us with two different drm::Driver associated
> types:
> * DriverObject::Driver
> * IntoGEMObject::Driver
>
> I'm not entirely sure of the original intent here unfortunately (if anyone
> is, please let me know!), but my guess is that the idea would be that some
> objects can implement IntoGEMObject using a different ::Driver than
> DriverObject - presumably to enable the usage of gem objects from different
> drivers. A reasonable usecase of course.
>
> However - if I'm not mistaken, I don't think that this is actually how
> things would go in practice. Driver implementations are of course
> implemented by their associated drivers, and generally drivers are not
> linked to each-other when building the kernel. Which is to say that even in
> a situation where we would theoretically deal with gem objects from another
> driver, we still wouldn't have access to its drm::driver::Driver
> implementation. It's more likely we would simply want a variant of gem
> objects in such a situation that have no association with a
> drm::driver::Driver type.
>
> Taking that into consideration, we can assume the following:
> * Anything that implements BaseDriverObject will implement DriverObject
> In other words, all BaseDriverObjects indirectly have an associated
> ::Driver type - so the two traits can be combined into one with no
> generics.
> * Not everything that implements IntoGEMObject will have an associated
> ::Driver, and that's OK.
>
> And with this, we now can do quite a bit of cleanup with the use of
> generics here. As such, this commit:
>
> * Removes the generics on BaseDriverObject
> * Moves DriverObject::Driver into BaseDriverObject
> * Removes DriverObject
> * Removes IntoGEMObject::Driver
> * Add AllocImpl::Driver, which we can use as a binding to figure out the
> correct File type for BaseObject
>
> Leaving us with a simpler trait hierarchy that now looks like this:
>
> * Drivers implement: BaseDriverObject
> * Crate implements:
> * IntoGEMObject for Object<T> where T: DriverObject
> * BaseObject for T where T: IntoGEMObject
>
> Which makes the code a lot easier to understand and build on :).
>
> Signed-off-by: Lyude Paul <lyude@redhat.com>
> Reviewed-by: Daniel Almeida <daniel.almeida@collabora.com>
Acked-by: Danilo Krummrich <dakr@kernel.org>
next prev parent reply other threads:[~2025-09-08 19:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 18:46 [PATCH v4 0/3] rust/drm: Misc. gem bindings cleanup Lyude Paul
2025-09-08 18:46 ` [PATCH v4 1/3] rust: drm: gem: Simplify use of generics Lyude Paul
2025-09-08 19:04 ` Danilo Krummrich [this message]
2025-09-08 18:46 ` [PATCH v4 2/3] rust: drm: gem: Add DriverFile type alias Lyude Paul
2025-09-08 19:03 ` Danilo Krummrich
2025-09-08 18:46 ` [PATCH v4 3/3] rust: drm: gem: Drop Object::SIZE Lyude Paul
2025-09-08 19:02 ` [PATCH v4 0/3] rust/drm: Misc. gem bindings cleanup Alice Ryhl
2025-09-08 19:28 ` Alice Ryhl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b92c52f8-d5b5-45ba-9195-9d8e20b41f0e@kernel.org \
--to=dakr@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=airlied@gmail.com \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=daniel.almeida@collabora.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=gary@garyguo.net \
--cc=lina+kernel@asahilina.net \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
--cc=tmgross@umich.edu \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).