nouveau/codegen: Add capability to pre-specify tessellation domain
authorGeorge Ouzounoudis <geothrock@gmail.com>
Mon, 24 Oct 2022 17:02:02 +0000 (20:02 +0300)
committerMarge Bot <emma+marge@anholt.net>
Tue, 1 Aug 2023 18:58:04 +0000 (18:58 +0000)
In the case of SPIRV tessellation shaders, the execution mode can be
specified in the tessellation control shader. So we need a way to know the domain
when compiling the tessellation evaluation shader.

Acked-by: M Henning <drawoc@darkrefraction.com>
Reviewed-by: Karol Herbst <kherbst@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24327>

src/nouveau/codegen/nv50_ir_driver.h
src/nouveau/codegen/nv50_ir_lowering_nvc0.cpp

index 8a3f637..fdd8b21 100644 (file)
@@ -103,6 +103,9 @@ struct nv50_ir_prog_info
          uint32_t gridInfoBase;  /* base address for NTID,NCTAID */
          uint16_t numThreads[3]; /* max number of threads */
       } cp;
+      struct {
+         uint8_t prespecified_domain; /* MESA_PRIM_{QUADS,TRIANGLES,LINES}, POINTS if unspecified */
+      } tese;
    } prop;
 
    struct {
index 78fab61..da1f04e 100644 (file)
@@ -2916,6 +2916,18 @@ NVC0LoweringPass::handleLDST(Instruction *i)
 void
 NVC0LoweringPass::readTessCoord(LValue *dst, int c)
 {
+   // GLSL requires domain qualifier to be defined in TES while SPIRV allows
+   // domain to be defined in TES and/or TCS
+   uint8_t domain = prog->driver_out->prop.tp.domain;
+   const bool tese_defined_domain =
+      domain == MESA_PRIM_LINES ||
+      domain == MESA_PRIM_TRIANGLES ||
+      domain == MESA_PRIM_QUADS;
+
+   if (!tese_defined_domain) {
+      domain = prog->driver->prop.tese.prespecified_domain;
+   }
+
    Value *laneid = bld.getSSA();
    Value *x, *y;
 
@@ -2930,7 +2942,8 @@ NVC0LoweringPass::readTessCoord(LValue *dst, int c)
       y = dst;
    } else {
       assert(c == 2);
-      if (prog->driver_out->prop.tp.domain != MESA_PRIM_TRIANGLES) {
+      if (domain != MESA_PRIM_TRIANGLES) {
+         // optimize out tesscoord.z
          bld.mkMov(dst, bld.loadImm(NULL, 0));
          return;
       }
@@ -2943,6 +2956,7 @@ NVC0LoweringPass::readTessCoord(LValue *dst, int c)
       bld.mkFetch(y, TYPE_F32, FILE_SHADER_OUTPUT, 0x2f4, NULL, laneid);
 
    if (c == 2) {
+      // compute tesscoord.z from x, y
       bld.mkOp2(OP_ADD, TYPE_F32, dst, x, y);
       bld.mkOp2(OP_SUB, TYPE_F32, dst, bld.loadImm(NULL, 1.0f), dst);
    }