<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<div style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr style="display: inline-block; width: 98%;">
<div id="divRplyFwdMsg" dir="ltr"><span style="font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(0, 0, 0);"><b>From:</b> Thomas Hellström <thomas.hellstrom@linux.intel.com><br>
<b>Sent:</b> Tuesday, May 14, 2024 9:51 AM<br>
<b>To:</b> Joonas Lahtinen <joonas.lahtinen@linux.intel.com>; Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com>; Graunke, Kenneth W <kenneth.w.graunke@intel.com>; Roper, Matthew D <matthew.d.roper@intel.com><br>
<b>Cc:</b> intel-xe@lists.freedesktop.org <intel-xe@lists.freedesktop.org>; intel-gfx@lists.freedesktop.org <intel-gfx@lists.freedesktop.org>; Chery, Nanley G <nanley.g.chery@intel.com>; Saarinen, Jani <jani.saarinen@intel.com>; Souza, Jose <jose.souza@intel.com>;
Mathew, Alwin <alwin.mathew@intel.com>; Zhang, Jianxun <jianxun.zhang@intel.com>; Syrjala, Ville <ville.syrjala@linux.intel.com>; Nikula, Jani <jani.nikula@intel.com><br>
<b>Subject:</b> Re: [RFC PATCH 0/3] Introducing I915_FORMAT_MOD_4_TILED_XE2_CCS Modifier for Xe2</span>
<div> </div>
</div>
<div class="elementToProof" style="font-size: 11pt;">On Tue, 2024-05-14 at 12:25 +0300, Joonas Lahtinen wrote:<br>
> Quoting Kenneth Graunke (2024-05-11 03:58:34)<br>
> > On Tuesday, May 7, 2024 3:56:57 PM PDT Matt Roper wrote:<br>
> > > On Mon, May 06, 2024 at 09:52:35PM +0300, Juha-Pekka Heikkila<br>
> > > wrote:<br>
> > > > These patches introduce I915_FORMAT_MOD_4_TILED_XE2_CCS<br>
> > > > modifier, which,<br>
> > > > from the kernel's perspective, behaves similarly to<br>
> > `I915_FORMAT_MOD_4_TILED`.<br>
> > > > This new modifier is primarily intended for user space to<br>
> > > > effectively<br>
> > monitor<br>
> > > > compression status, especially when dealing with a mix of<br>
> > > > compressed and<br>
> > > > uncompressed buffers.<br>
> > > ><br>
> > > > The addition of this modifier facilitates user space in<br>
> > > > managing<br>
> > compression<br>
> > > > status, particularly when utilizing both compressed and<br>
> > > > uncompressed<br>
> > buffers<br>
> > > > concurrently. To leverage compression for these buffers, user<br>
> > > > space<br>
> > > > applications must configure the appropriate Page Attribute<br>
> > > > Table (PAT)<br>
> > index.<br>
> > > > Display engine will treat all Tile4 as if it were compressed<br>
> > > > under all<br>
> > > > circumstances on Xe2 architecture.<br>
> > ><br>
> > > I may have missed some discussion about this, but I thought the<br>
> > > previous<br>
> > > consensus was that we didn't want/need new modifiers for<br>
> > > compression on<br>
> > > Xe2? If a userspace client (or the display hardware) receives a<br>
> > > buffer<br>
> > > of unknown origin and unknown compression status, it's always<br>
> > > fine to<br>
> > > select a compressed PAT when binding the buffer to read since<br>
> > > even for<br>
> > > uncompressed buffers the CCS metadata will accurately reflect the<br>
> > > compression status. Unlike Xe1, where generating content without<br>
> > > compression enabled would leave random garbage in the FlatCCS<br>
> > > area, Xe2<br>
> > > will set the corresponding FlatCCS to '0x0' for each block,<br>
> > > indicating<br>
> > > uncompressed data.<br>
> > ><br>
> > > Can you explain more what the benefit of handling these modifiers<br>
> > > explicitly is?</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);">I am not sure if there is another nice way to address this case in the eco-system without an explicit modifier even if it is not necessary from kernel driver aspect, so I just put it
here to get some insights.</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);"><br>
</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);">I assume we still want to support existing modifiers like I915_FORMAT_MOD_4_TILED, then the modifier extension of Vulkan becomes relevant (<a href="https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html" id="LPlnk550388">https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_EXT_image_drm_format_modifier.html</a>).
In the section of export, the spec depicts the driver can choose the optimal modifier to create the image from a list of modifiers application provides, which could be all modifiers reported by driver from a prior query. Then the application will export the
modifier along with other necessary meta data and buffer. For these legacy modifiers like TILE_4, we can disable compression on it since it is defined without compression schemas in drm_fourcc.h, or we can keep the image compressed internally but need to uncompress
it before exporting. Either of the two options has a performance penalty, but this won't be a concern when we have an explicit TILE_4+compression modifier (e.g. DG2, MTL) to choose. The rest of export-import process has no ambiguity on compression support,
so no resolve or special treatment is needed. Without such modifier, what should driver assign to image or report back to application? In this case we can only have these legacy modifiers as options with penalty.</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);"><br>
</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);">There was also a discussion on assuming shared data always compressed between both ends to eliminate the need of a new modifier on Xe2, but it has to be defined between the parties in
design and cannot guarantee data is still sharable between different devices.</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);"><br>
</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);">It seems to me that the drm modifier has been there from a while, always portraited as beneficial enhancements and get promoted, so more apps would be on the path with modifiers by default.
On the other hand, even if it turns out that this explicit modifier is not useful, it won't hurt anyway as the last drm modifier inherited by later Hardwares. It seems still better and safer to have it then getting caught by some corner cases on the road.<br>
<br>
If there is another logical path to deal it without such modifier, that will be great too.</div>
<div class="elementToProof" style="font-size: 11pt; color: rgb(0, 0, 0);"><br>
</div>
<div class="elementToProof" style="font-size: 11pt;">> > ><br>
> > ><br>
> > > Matt<br>
> ><br>
> > Thanks, Matt! I'm a bit late in getting up to speed with the Xe2<br>
> > compression<br>
> > changes; this is really good information.<br>
> ><br>
> > As I understand it...all blocks on the GPU behave in the way you<br>
> > mentioned,<br>
> > where generating uncompressed data via the GPU will set FlatCCS =<br>
> > 0, so you<br>
> > can assume a compressed PAT entry and everything works.<br>
> ><br>
> > One snag is...I've heard that CPU access doesn't work that way. <br>
> > So, if you<br>
> > mmap a buffer on the CPU, and write data with the CPU, then I think<br>
> > we're back<br>
> > to the "FlatCCS contains uninitialized garbage" case, where it's<br>
> > unsafe to<br>
> > assume a compressed PAT. And... we don't really know when sharing<br>
> > buffers<br>
> > whether the other side is going to want to do CPU access.<br>
><br>
> I think the previous discussion has specifically happened in the<br>
> context of<br>
> dma-buf, so not only CPU but other GPUs/accelerators/decoders/devices<br>
> in the<br>
> system are also relevant.<br>
><br>
> It boils down to the fact that when exporting a dma-buf, one can't<br>
> know it will<br>
> be consumed only by the same GPU (or other device for that matter)<br>
> unless there<br>
> is an explicit negotiation between exporter and importers.<br>
><br>
> > It would be really nice to assume compression by default, though,<br>
> > which got me<br>
> > thinking: if we mmap a buffer via DRM_XE_GEM_MMAP_OFFSET, could<br>
> > xe.ko disable<br>
> > compression for us? So, resolve any outstanding CCS data, and then<br>
> > switch any<br>
> > PAT entries to uncompressed. Mapping would block until that<br>
> > resolve is done. <br>
> > It could leave compression off forever (once you CPU map a buffer,<br>
> > it's never<br>
> > compressed again). Or it could turn CCS back on when map count<br>
> > reaches 0 (but<br>
> > frankly I'm not sure that's terribly important, and sounds more<br>
> > complex).<br>
><br>
> This would only really work for a single device but the dma-buf is<br>
> specifically targeting more generic sharing. There's no built-in<br>
> mechanism<br>
> to limit the sharing to subset of devices without explicit<br>
> negotiation<br>
> between the exporter and importers.<br>
><br>
> So I think the "by default" mode needs to be interoperable, and the<br>
> explicit negotiation can then use less compatible formats given those<br>
> FD<br>
> are never passed to importers that were not part of the negotiation.<br>
><br>
> > As I understand it, at least on discrete GPUs, the kernel already<br>
> > has to do<br>
> > something similar for eviction, when migrating BOs to system memory<br>
> > (which<br>
> > doesn't support compression). So this would be doing basically the<br>
> > same<br>
> > "resolve and disable CCS" step the kernel can presumably already<br>
> > do, but now<br>
> > on mmap as well.<br>
><br>
> So far the eviction strategy has been to copy both the backing store<br>
> and<br>
> compression bits in raw form. With Xe2 it would indeed be possible to<br>
> do<br>
> an implicit resolve IFF the buffer has not been shared to someone who<br>
> doesn't<br>
> understand compression and might have left garbage in the CCS bits.<br>
><br>
> When evicting in raw form, kernel doesn't have to know if the CCS<br>
> bits<br>
> are garbage or not on any given moment.<br>
><br>
> Regards, Joonas<br>
<br>
Just a follow-up comment (TBC), IF we're going for the everything-is-<br>
compressed approach, I think there are some considerations to be made:<br>
<br>
dma-buf exports to foreign devices need to resolve at map_attachment<br>
time. Foreign devices are all devices that can't interpret the<br>
compressed content.<br>
dma-buf mmaps need to resolve. IIRC Could be implemented in the<br>
DMA_BUF_IOCTL_SYNC callbacks that wrap cpu access.<br>
dma-buf imports from foreign devices need to never use compressed PAT<br>
for writing. Should KMD enforce this? Implicitly? Explicitly? I don't<br>
see how UMD could know whether the imported dma-buf is from a foreign<br>
device.<br>
<br>
For mmaps of buffer objects of local device a resolve is needed. Having<br>
KMD do that on a pagefault-basis is definitely possible, but will most<br>
likely be terribly inefficient. Better to leave that to UMD?<br>
<br>
/Thomas<br>
<br>
><br>
> ><br>
> > What do you think? Viable? Crazy? Have I missed something?<br>
> ><br>
> > --Ken<br>
<br>
</div>
</body>
</html>