[Mesa-dev] Question regarding cs_gem_write_reloc in radeon_cs_gem.c

Marek Olšák maraeo at gmail.com
Fri Jun 15 06:38:49 PDT 2012


On Fri, Jun 15, 2012 at 3:15 PM, Miguel Lopes Santos Ramos
<org.mesa3d at miguel.ramos.name> wrote:
> Hi all,
>
> I'm trying to learn to program radeons in assembly in Linux and
> already got help once in this mailing list.
>
> I'm programming in C++ using the kernel DRM ioctls directly because
> libdrm appears to be a thin wrapper around these (for my purpose,
> which is using the GPU for computing), but in doing so, I need to
> understand what libdrm is doing.
>
> Now, the cs_gem_write_reloc function, emits two dwords which encode a
> relocation and adds information on that relocation to an array which
> is passed to the kernel.
> The function goes to some length to make sure a single
> drm_radeon_cs_reloc structure is passed to the kernel for each buffer
> object.
>
> Now, I'm trying to understand what are the constraints, I don't know
> what is the desired behaviour.
>
> This function begins with:
>
>  if ((read_domain && write_domain) || (!read_domain && !write_domain)) {
>        /* in one CS a bo can only be in read or write domain but not
>         * in read & write domain at the same sime
>         */
>
> Now, the comment seems to say one thing whereas the if-condition seems
> to say the opposite. Am I mistaken? Which is the desired behaviour,
> that of the comment or that of the code?
>
> Then, the code block within if (reloc->handle == bo->handle) { ... }
> is even more confusing to me.
> For instance, the following line:
>
> reloc->flags |= (flags & reloc->flags);
>
> This seems to be a no-op. Anyway, I'm not so worried about these flags
> which appear never to be used...
> But what are really the constraints for this read_domains and write_domain?

I no longer remember how exactly the libdrm CS code works. Radeon
gallium drivers don't use it, because it's inefficient and awful.

To answer your question: the kernel uses write_domain if it's
non-zero, otherwise it uses read_domains. That's it.

The Mesa code that replaces libdrm resides in the Mesa repository in:
src/gallium/winsys/radeon/drm/

Marek


More information about the mesa-dev mailing list