asahi: Augment PBE descriptor for software access
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Wed, 28 Jun 2023 19:39:57 +0000 (15:39 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 20 Jul 2023 15:33:28 +0000 (15:33 +0000)
For implementing image atomics (and multisample image writes), we need
information about the image layout in the shader. It's a lot nicer to determine
the image layouts on the CPU (where we have ail) and stash the results in the
PBE descriptor, where we have a convenient hole to do so, rather than trying to
do all the layout calculations on the GPU on the fly. Add a data structure that
the driver will fill out and the image atomic lowering will consider as part of
the hardware.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24258>

src/asahi/lib/cmdbuf.xml

index 209d402..ea1c899 100644 (file)
     <value name="4" value="1"/>
   </enum>
 
+  <!-- Beginning of software-defined metadata used to implement image atomics
+     and multisampled image writes. For atomics, information could be
+     recovered from the PBE descriptor, but it is convenient to compute on the
+     CPU where we have ail.
+
+     This descriptor (or a pointer to it, if the extended form is used) is stashed
+     in the last 8 bytes of a PBE descriptor. Ordinarily used for
+     acceleration buffers or linear layer stride. We forbid atomics and
+     multisampled writes to compressed images and linear 2D arrays, leaving this
+     area free.
+   -->
+
+  <struct name="Atomic (software)" size="16">
+    <field name="Base" size="33" start="0" type="address" modifier="shr(7)"/>
+    <field name="Tile width" size="3" start="33" type="uint" modifier="log2" default="1"/>
+    <field name="Tile height" size="3" start="36" type="uint" modifier="log2" default="1"/>
+    <field name="Tiles per row" size="15" start="39" type="uint"/>
+    <field name="Sample count" size="2" start="54" type="uint" modifier="log2" default="1"/>
+
+    <!-- Extended fields begin here -->
+    <field name="Layer stride (elements)" size="32" start="64" type="uint"/>
+  </struct>
+
+  <struct name="PBE Buffer (software)" size="8">
+     <!-- Not necessarily aligned -->
+     <field name="Base" size="40" start="0" type="address"/>
+  </struct>
+
+  <!-- End of software defined data structures -->
+
   <struct name="PBE" size="24">
     <field name="Dimension" size="4" start="0" type="Texture dimension" default="2D"/>
     <field name="Layout" size="2" start="4" type="Layout"/>
     <!-- If layout is linear, stride has the minus 1 encoded -->
     <field name="Depth (linear)" size="11" start="128" type="uint" modifier="minus(1)" default="1"/>
     <field name="Layer stride (linear)" size="27" start="139" type="uint" modifier="shr(7)"/>
+
+    <!-- If neither, for software use -->
+    <field name="Software-defined" size="64" start="128" type="hex"/>
   </struct>
 
   <struct name="Texture" size="24">