From 17076d700c94402f82c22b2e1d99a1753e4a0834 Mon Sep 17 00:00:00 2001 From: Zack Rusin Date: Mon, 24 Aug 2009 18:38:46 -0400 Subject: [PATCH] xorg: start on code accelerating render --- .../state_trackers/xorg/xorg_composite.c | 31 ++++ src/gallium/state_trackers/xorg/xorg_driver.c | 15 -- src/gallium/state_trackers/xorg/xorg_exa.c | 63 ++++--- src/gallium/state_trackers/xorg/xorg_exa.h | 23 +-- .../state_trackers/xorg/xorg_exa_tgsi.c | 157 ++++++++++++++++++ .../state_trackers/xorg/xorg_exa_tgsi.h | 17 ++ 6 files changed, 255 insertions(+), 51 deletions(-) create mode 100644 src/gallium/state_trackers/xorg/xorg_exa_tgsi.c create mode 100644 src/gallium/state_trackers/xorg/xorg_exa_tgsi.h diff --git a/src/gallium/state_trackers/xorg/xorg_composite.c b/src/gallium/state_trackers/xorg/xorg_composite.c index 255ae91f096..05143ad11a7 100644 --- a/src/gallium/state_trackers/xorg/xorg_composite.c +++ b/src/gallium/state_trackers/xorg/xorg_composite.c @@ -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, diff --git a/src/gallium/state_trackers/xorg/xorg_driver.c b/src/gallium/state_trackers/xorg/xorg_driver.c index 53d1a330951..d68fd376973 100644 --- a/src/gallium/state_trackers/xorg/xorg_driver.c +++ b/src/gallium/state_trackers/xorg/xorg_driver.c @@ -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. diff --git a/src/gallium/state_trackers/xorg/xorg_exa.c b/src/gallium/state_trackers/xorg/xorg_exa.c index 8da113ec618..9f3f82c6c89 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.c +++ b/src/gallium/state_trackers/xorg/xorg_exa.c @@ -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: diff --git a/src/gallium/state_trackers/xorg/xorg_exa.h b/src/gallium/state_trackers/xorg/xorg_exa.h index f0508eb2d53..0189eabaa40 100644 --- a/src/gallium/state_trackers/xorg/xorg_exa.h +++ b/src/gallium/state_trackers/xorg/xorg_exa.h @@ -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 index 00000000000..151cb84b600 --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.c @@ -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 index 00000000000..b7245c8e89e --- /dev/null +++ b/src/gallium/state_trackers/xorg/xorg_exa_tgsi.h @@ -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 -- 2.30.2