xorg: start on code accelerating render
authorZack Rusin <zackr@vmware.com>
Mon, 24 Aug 2009 22:38:46 +0000 (18:38 -0400)
committerZack Rusin <zackr@vmware.com>
Mon, 24 Aug 2009 22:39:01 +0000 (18:39 -0400)
src/gallium/state_trackers/xorg/xorg_composite.c
src/gallium/state_trackers/xorg/xorg_driver.c
src/gallium/state_trackers/xorg/xorg_exa.c
src/gallium/state_trackers/xorg/xorg_exa.h
src/gallium/state_trackers/xorg/xorg_exa_tgsi.c [new file with mode: 0644]
src/gallium/state_trackers/xorg/xorg_exa_tgsi.h [new file with mode: 0644]

index 255ae91f09665ec7c30ea5fb68cf9dbaeea54e7b..05143ad11a7d59d1f5e40524fd3df2d064b8730e 100644 (file)
@@ -1,5 +1,36 @@
 #include "xorg_composite.h"
 
+struct xorg_composite_blend {
+   int op:8;
+
+   unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */
+   unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */
+
+   unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */
+   unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */
+};
+
+static const struct xorg_composite_blend xorg_blends[] = {
+   { PictOpClear,
+     PIPE_BLENDFACTOR_CONST_COLOR, PIPE_BLENDFACTOR_CONST_ALPHA,
+     PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_ZERO },
+
+   { PictOpSrc,
+     PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ONE,
+     PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_ZERO },
+
+   { PictOpDst,
+     PIPE_BLENDFACTOR_ZERO, PIPE_BLENDFACTOR_ZERO,
+     PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_ONE },
+
+   { PictOpOver,
+     PIPE_BLENDFACTOR_SRC_ALPHA, PIPE_BLENDFACTOR_ONE,
+     PIPE_BLENDFACTOR_INV_SRC_ALPHA, PIPE_BLENDFACTOR_INV_SRC_ALPHA },
+
+   { PictOpOverReverse,
+     PIPE_BLENDFACTOR_SRC_ALPHA, PIPE_BLENDFACTOR_ONE,
+     PIPE_BLENDFACTOR_INV_SRC_ALPHA, PIPE_BLENDFACTOR_INV_SRC_ALPHA },
+};
 
 boolean xorg_composite_accelerated(int op,
                                    PicturePtr pSrcPicture,
index 53d1a330951a84c68cc9fd5bf11f94ca58184e2b..d68fd376973fbe2a75bb1dff71de77a2bbf284e5 100644 (file)
@@ -633,10 +633,6 @@ LeaveVT(int scrnIndex, int flags)
 
     RestoreHWState(pScrn);
 
-    if (drmDropMaster(ms->fd))
-       xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                  "drmDropMaster failed: %s\n", strerror(errno));
-
     pScrn->vtSema = FALSE;
 }
 
@@ -649,17 +645,6 @@ EnterVT(int scrnIndex, int flags)
     ScrnInfoPtr pScrn = xf86Screens[scrnIndex];
     modesettingPtr ms = modesettingPTR(pScrn);
 
-    if (drmSetMaster(ms->fd)) {
-       if (errno == EINVAL) {
-           xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                      "drmSetMaster failed: 2.6.29 or newer kernel required for "
-                      "multi-server DRI\n");
-       } else {
-           xf86DrvMsg(pScrn->scrnIndex, X_WARNING,
-                      "drmSetMaster failed: %s\n", strerror(errno));
-       }
-    }
-
     /*
      * Only save state once per server generation since that's what most
      * drivers do.  Could change this to save state at each VT enter.
index 8da113ec61852426ed310ab2f21d864db8213d7e..9f3f82c6c890113969e8e8ddc15249685672953a 100644 (file)
@@ -42,6 +42,8 @@
 #include "pipe/p_state.h"
 #include "pipe/p_inlines.h"
 
+#include "cso_cache/cso_context.h"
+
 #include "util/u_rect.h"
 
 /*
@@ -516,6 +518,11 @@ xorg_exa_close(ScrnInfoPtr pScrn)
     modesettingPtr ms = modesettingPTR(pScrn);
     struct exa_context *exa = ms->exa;
 
+    if (exa->cso) {
+       cso_release_all(exa->cso);
+       cso_destroy_context(exa->cso);
+    }
+
     if (exa->ctx)
        exa->ctx->destroy(exa->ctx);
 
@@ -541,33 +548,35 @@ xorg_exa_init(ScrnInfoPtr pScrn)
     }
 
     memset(pExa, 0, sizeof(*pExa));
-    pExa->exa_major = 2;
-    pExa->exa_minor = 2;
-    pExa->memoryBase = 0;
-    pExa->memorySize = 0;
-    pExa->offScreenBase = 0;
+
+    pExa->exa_major         = 2;
+    pExa->exa_minor         = 2;
+    pExa->memoryBase        = 0;
+    pExa->memorySize        = 0;
+    pExa->offScreenBase     = 0;
     pExa->pixmapOffsetAlign = 0;
-    pExa->pixmapPitchAlign = 1;
-    pExa->flags = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
-    pExa->maxX = 8191;                /* FIXME */
-    pExa->maxY = 8191;                /* FIXME */
-    pExa->WaitMarker = ExaWaitMarker;
-    pExa->MarkSync = ExaMarkSync;
-    pExa->PrepareSolid = ExaPrepareSolid;
-    pExa->Solid = ExaSolid;
-    pExa->DoneSolid = ExaDone;
-    pExa->PrepareCopy = ExaPrepareCopy;
-    pExa->Copy = ExaCopy;
-    pExa->DoneCopy = ExaDone;
-    pExa->CheckComposite = ExaCheckComposite;
-    pExa->PrepareComposite = ExaPrepareComposite;
-    pExa->Composite = ExaComposite;
-    pExa->DoneComposite = ExaDoneComposite;
-    pExa->PixmapIsOffscreen = ExaPixmapIsOffscreen;
-    pExa->PrepareAccess = ExaPrepareAccess;
-    pExa->FinishAccess = ExaFinishAccess;
-    pExa->CreatePixmap = ExaCreatePixmap;
-    pExa->DestroyPixmap = ExaDestroyPixmap;
+    pExa->pixmapPitchAlign  = 1;
+    pExa->flags             = EXA_OFFSCREEN_PIXMAPS | EXA_HANDLES_PIXMAPS;
+    pExa->maxX              = 8191; /* FIXME */
+    pExa->maxY              = 8191; /* FIXME */
+
+    pExa->WaitMarker         = ExaWaitMarker;
+    pExa->MarkSync           = ExaMarkSync;
+    pExa->PrepareSolid       = ExaPrepareSolid;
+    pExa->Solid              = ExaSolid;
+    pExa->DoneSolid          = ExaDone;
+    pExa->PrepareCopy        = ExaPrepareCopy;
+    pExa->Copy               = ExaCopy;
+    pExa->DoneCopy           = ExaDone;
+    pExa->CheckComposite     = ExaCheckComposite;
+    pExa->PrepareComposite   = ExaPrepareComposite;
+    pExa->Composite          = ExaComposite;
+    pExa->DoneComposite      = ExaDoneComposite;
+    pExa->PixmapIsOffscreen  = ExaPixmapIsOffscreen;
+    pExa->PrepareAccess      = ExaPrepareAccess;
+    pExa->FinishAccess       = ExaFinishAccess;
+    pExa->CreatePixmap       = ExaCreatePixmap;
+    pExa->DestroyPixmap      = ExaDestroyPixmap;
     pExa->ModifyPixmapHeader = ExaModifyPixmapHeader;
 
     if (!exaDriverInit(pScrn->pScreen, pExa)) {
@@ -579,6 +588,8 @@ xorg_exa_init(ScrnInfoPtr pScrn)
     /* Share context with DRI */
     ms->ctx = exa->ctx;
 
+    exa->cso = cso_create_context(exa->ctx);
+
     return (void *)exa;
 
   out_err:
index f0508eb2d5342d242d21548bc549ca537894acf7..0189eabaa4049f9ed497b39c391b37993437aac4 100644 (file)
@@ -3,25 +3,28 @@
 
 #include "xorg_tracker.h"
 
+struct cso_context;
+
 struct exa_context
 {
-    ExaDriverPtr pExa;
-    struct pipe_context *ctx;
-    struct pipe_screen *scrn;
+   ExaDriverPtr pExa;
+   struct pipe_context *ctx;
+   struct pipe_screen *scrn;
+   struct cso_context *cso;
 };
 
 
 struct exa_pixmap_priv
 {
-    int flags;
-    int tex_flags;
+   int flags;
+   int tex_flags;
 
-    struct pipe_texture *tex;
-    unsigned int color;
-    struct pipe_surface *src_surf; /* for copies */
+   struct pipe_texture *tex;
+   unsigned int color;
+   struct pipe_surface *src_surf; /* for copies */
 
-    struct pipe_transfer *map_transfer;
-    unsigned map_count;
+   struct pipe_transfer *map_transfer;
+   unsigned map_count;
 };
 
 
diff --git a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c
new file mode 100644 (file)
index 0000000..151cb84
--- /dev/null
@@ -0,0 +1,157 @@
+#include "xorg_exa_tgsi.h"
+
+/*### stupidity defined in X11/extensions/XI.h */
+#undef Absolute
+
+#include "pipe/p_format.h"
+#include "pipe/p_context.h"
+#include "pipe/p_state.h"
+#include "pipe/p_inlines.h"
+#include "pipe/p_shader_tokens.h"
+
+#include "util/u_memory.h"
+#include "util/u_simple_shaders.h"
+
+#include "tgsi/tgsi_ureg.h"
+
+#include "cso_cache/cso_context.h"
+
+#define UNSUPPORTED_OP 0
+
+struct shader_id {
+   int op : 8;
+   int mask : 1;
+   int component_alpha : 1;
+   int is_fill : 1;
+};
+
+/* SAMP[0]  = dst
+ * SAMP[1]  = src
+ * SAMP[2]  = mask
+ * IN[0]    = pos dst
+ * IN[1]    = pos src
+ * IN[2]    = pos mask
+ * CONST[0] = (0, 0, 0, 1)
+ */
+struct xorg_render_ops_tgsi {
+   int op;
+};
+
+
+static const char over_op[] =
+   "SUB TEMP[3], CONST[0].wwww, TEMP[1].wwww\n"
+   "MUL TEMP[3], TEMP[0], TEMP[3]\n"
+   "ADD TEMP[0], TEMP[3], TEMP[0]\n";
+
+static const struct xorg_render_ops_tgsi ops_map[] = {
+   {PictOpClear},
+   {PictOpSrc},
+   {PictOpDst},
+   {PictOpOver},
+   {PictOpOverReverse},
+   {PictOpIn},
+   {PictOpInReverse},
+   {PictOpOut},
+   {PictOpOutReverse},
+   {PictOpAtop},
+   {PictOpAtopReverse},
+   {PictOpXor},
+   {PictOpAdd},
+   {PictOpSaturate},
+};
+
+
+static INLINE void
+create_preamble(struct ureg_program *ureg)
+{
+}
+
+
+static INLINE void
+src_in_mask(struct ureg_program *ureg,
+            struct ureg_dst dst,
+            struct ureg_src src,
+            struct ureg_src mask)
+{
+   /* MUL dst, src, mask.wwww */
+   ureg_MUL(ureg, dst, src,
+            ureg_scalar(mask, TGSI_SWIZZLE_W));
+}
+
+static INLINE
+struct shader_id shader_state(int op,
+                              PicturePtr src_picture,
+                              PicturePtr mask_picture,
+                              PicturePtr dst_picture)
+{
+   struct shader_id sid;
+
+   sid.op = op;
+   sid.mask = (mask_picture != 0);
+   sid.component_alpha = (mask_picture->componentAlpha);
+   sid.is_fill = (src_picture->pSourcePict != 0);
+   if (sid.is_fill) {
+      sid.is_fill =
+         (src_picture->pSourcePict->type == SourcePictTypeSolidFill);
+   }
+
+   return sid;
+}
+
+struct xorg_shader xorg_shader_construct(struct exa_context *exa,
+                                         int op,
+                                         PicturePtr src_picture,
+                                         PicturePtr mask_picture,
+                                         PicturePtr dst_picture)
+{
+   struct ureg_program *ureg;
+   struct ureg_src dst_sampler, src_sampler, mask_sampler;
+   struct ureg_src dst_pos, src_pos, mask_pos;
+   struct ureg_src src, mask;
+   struct shader_id sid = shader_state(op, src_picture,
+                                       mask_picture,
+                                       dst_picture);
+   struct xorg_shader shader = {0};
+
+   ureg = ureg_create(exa->ctx, TGSI_PROCESSOR_FRAGMENT);
+   if (ureg == NULL)
+      return shader;
+
+   if (sid.is_fill)
+      return shader;
+
+#if 0  /* unused right now */
+   dst_sampler = ureg_DECL_sampler(ureg);
+   dst_pos = ureg_DECL_fs_input(ureg,
+                                TGSI_SEMANTIC_POSITION,
+                                0,
+                                TGSI_INTERPOLATE_PERSPECTIVE);
+#endif
+
+   src_sampler = ureg_DECL_sampler(ureg);
+   src_pos = ureg_DECL_fs_input(ureg,
+                                TGSI_SEMANTIC_POSITION,
+                                1,
+                                TGSI_INTERPOLATE_PERSPECTIVE);
+
+   if (sid.mask) {
+      mask_sampler = ureg_DECL_sampler(ureg);
+      src_pos = ureg_DECL_fs_input(ureg,
+                                   TGSI_SEMANTIC_POSITION,
+                                   2,
+                                   TGSI_INTERPOLATE_PERSPECTIVE);
+   }
+
+   ureg_TEX(ureg, ureg_dst(src),
+            TGSI_TEXTURE_2D, src_pos, src_sampler);
+
+   if (sid.mask) {
+      ureg_TEX(ureg, ureg_dst(mask),
+               TGSI_TEXTURE_2D, mask_pos, mask_sampler);
+      /* src IN mask */
+      src_in_mask(ureg, ureg_dst(src), src, mask);
+   }
+
+   ureg_END(ureg);
+
+}
diff --git a/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h
new file mode 100644 (file)
index 0000000..b7245c8
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef XORG_EXA_TGSI_H
+#define XORG_EXA_TGSI_H
+
+#include "xorg_exa.h"
+
+struct xorg_shader {
+   void *fs;
+   void *vs;
+};
+
+struct xorg_shader xorg_shader_construct(struct exa_context *exa,
+                                         int op,
+                                         PicturePtr src_picture,
+                                         PicturePtr mask_picture,
+                                         PicturePtr dst_picture);
+
+#endif