st/xorg: bind framebuffer and viewport for exa
This commit is contained in:
parent
3f15ea866f
commit
f9a3fce090
|
@ -1,5 +1,9 @@
|
|||
#include "xorg_composite.h"
|
||||
|
||||
#include <cso_cache/cso_context.h>
|
||||
|
||||
#include <pipe/p_inlines.h>
|
||||
|
||||
struct xorg_composite_blend {
|
||||
int op:8;
|
||||
|
||||
|
@ -97,12 +101,110 @@ boolean xorg_composite_accelerated(int op,
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
bind_framebuffer_state(struct exa_context *exa, PicturePtr pDstPicture,
|
||||
struct exa_pixmap_priv *pDst)
|
||||
{
|
||||
unsigned i;
|
||||
struct pipe_framebuffer_state state;
|
||||
struct pipe_surface *surface = exa_gpu_surface(exa, pDst);
|
||||
memset(&state, 0, sizeof(struct pipe_framebuffer_state));
|
||||
|
||||
state.width = pDstPicture->pDrawable->width;
|
||||
state.height = pDstPicture->pDrawable->height;
|
||||
|
||||
state.nr_cbufs = 1;
|
||||
state.cbufs[0] = surface;
|
||||
for (i = 1; i < PIPE_MAX_COLOR_BUFS; ++i)
|
||||
state.cbufs[i] = 0;
|
||||
|
||||
/* currently we don't use depth/stencil */
|
||||
state.zsbuf = 0;
|
||||
|
||||
cso_set_framebuffer(exa->cso, &state);
|
||||
}
|
||||
|
||||
enum AxisOrientation {
|
||||
Y0_BOTTOM,
|
||||
Y0_TOP
|
||||
};
|
||||
|
||||
static void
|
||||
set_viewport(struct exa_context *exa, int width, int height,
|
||||
enum AxisOrientation orientation)
|
||||
{
|
||||
struct pipe_viewport_state viewport;
|
||||
float y_scale = (orientation == Y0_BOTTOM) ? -2.f : 2.f;
|
||||
|
||||
viewport.scale[0] = width / 2.f;
|
||||
viewport.scale[1] = height / y_scale;
|
||||
viewport.scale[2] = 1.0;
|
||||
viewport.scale[3] = 1.0;
|
||||
viewport.translate[0] = width / 2.f;
|
||||
viewport.translate[1] = height / 2.f;
|
||||
viewport.translate[2] = 0.0;
|
||||
viewport.translate[3] = 0.0;
|
||||
|
||||
cso_set_viewport(exa->cso, &viewport);
|
||||
}
|
||||
|
||||
static void
|
||||
bind_viewport_state(struct exa_context *exa, PicturePtr pDstPicture)
|
||||
{
|
||||
const int param_bytes = 8 * sizeof(float);
|
||||
int width = pDstPicture->pDrawable->width;
|
||||
int height = pDstPicture->pDrawable->height;
|
||||
float vs_consts[8] = {
|
||||
2.f/width, 2.f/height, 1, 1,
|
||||
-1, -1, 0, 0
|
||||
};
|
||||
struct pipe_constant_buffer *cbuf = &exa->vs_const_buffer;
|
||||
|
||||
set_viewport(exa, width, height, Y0_BOTTOM);
|
||||
|
||||
pipe_buffer_reference(&cbuf->buffer, NULL);
|
||||
cbuf->buffer = pipe_buffer_create(exa->ctx->screen, 16,
|
||||
PIPE_BUFFER_USAGE_CONSTANT,
|
||||
param_bytes);
|
||||
|
||||
if (cbuf->buffer) {
|
||||
pipe_buffer_write(exa->ctx->screen, cbuf->buffer,
|
||||
0, param_bytes, vs_consts);
|
||||
}
|
||||
exa->ctx->set_constant_buffer(exa->ctx, PIPE_SHADER_VERTEX, 0, cbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
bind_blend_state()
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bind_rasterizer_state()
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
bind_shaders()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
boolean xorg_composite_bind_state(struct exa_context *exa,
|
||||
int op,
|
||||
PicturePtr pSrcPicture,
|
||||
PicturePtr pMaskPicture,
|
||||
PicturePtr pDstPicture)
|
||||
PicturePtr pDstPicture,
|
||||
struct exa_pixmap_priv *pSrc,
|
||||
struct exa_pixmap_priv *pMask,
|
||||
struct exa_pixmap_priv *pDst)
|
||||
{
|
||||
bind_framebuffer_state(exa, pDstPicture, pDst);
|
||||
bind_viewport_state(exa, pDstPicture);
|
||||
bind_blend_state();
|
||||
bind_rasterizer_state();
|
||||
bind_shaders();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,10 @@ boolean xorg_composite_bind_state(struct exa_context *exa,
|
|||
int op,
|
||||
PicturePtr pSrcPicture,
|
||||
PicturePtr pMaskPicture,
|
||||
PicturePtr pDstPicture);
|
||||
PicturePtr pDstPicture,
|
||||
struct exa_pixmap_priv *pSrc,
|
||||
struct exa_pixmap_priv *pMask,
|
||||
struct exa_pixmap_priv *pDst);
|
||||
|
||||
void xorg_composite(struct exa_context *exa,
|
||||
struct exa_pixmap_priv *dst,
|
||||
|
|
|
@ -217,10 +217,7 @@ ExaSolid(PixmapPtr pPixmap, int x0, int y0, int x1, int y1)
|
|||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa = ms->exa;
|
||||
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
|
||||
struct pipe_surface *surf =
|
||||
exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
|
||||
PIPE_BUFFER_USAGE_GPU_READ |
|
||||
PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
struct pipe_surface *surf = exa_gpu_surface(exa, priv);
|
||||
|
||||
exa->ctx->surface_fill(exa->ctx, surf, x0, y0, x1 - x0, y1 - y0,
|
||||
priv->color);
|
||||
|
@ -256,10 +253,7 @@ ExaPrepareCopy(PixmapPtr pSrcPixmap, PixmapPtr pDstPixmap, int xdir,
|
|||
if (!exa->ctx || !exa->ctx->surface_copy)
|
||||
return FALSE;
|
||||
|
||||
priv->src_surf =
|
||||
exa->scrn->get_tex_surface(exa->scrn, src_priv->tex, 0, 0, 0,
|
||||
PIPE_BUFFER_USAGE_GPU_READ |
|
||||
PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
priv->src_surf = exa_gpu_surface(exa, src_priv);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -272,10 +266,7 @@ ExaCopy(PixmapPtr pDstPixmap, int srcX, int srcY, int dstX, int dstY,
|
|||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa = ms->exa;
|
||||
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pDstPixmap);
|
||||
struct pipe_surface *surf =
|
||||
exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
|
||||
PIPE_BUFFER_USAGE_GPU_READ |
|
||||
PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
struct pipe_surface *surf = exa_gpu_surface(exa, priv);
|
||||
|
||||
exa->ctx->surface_copy(exa->ctx, surf, dstX, dstY, priv->src_surf,
|
||||
srcX, srcY, width, height);
|
||||
|
@ -292,7 +283,10 @@ ExaPrepareComposite(int op, PicturePtr pSrcPicture,
|
|||
struct exa_context *exa = ms->exa;
|
||||
|
||||
return xorg_composite_bind_state(exa, op, pSrcPicture, pMaskPicture,
|
||||
pDstPicture);
|
||||
pDstPicture,
|
||||
exaGetPixmapDriverPrivate(pSrc),
|
||||
exaGetPixmapDriverPrivate(pMask),
|
||||
exaGetPixmapDriverPrivate(pDst));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -512,101 +506,117 @@ ExaModifyPixmapHeader(PixmapPtr pPixmap, int width, int height,
|
|||
struct pipe_texture *
|
||||
xorg_exa_get_texture(PixmapPtr pPixmap)
|
||||
{
|
||||
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
|
||||
struct pipe_texture *tex = NULL;
|
||||
pipe_texture_reference(&tex, priv->tex);
|
||||
return tex;
|
||||
struct exa_pixmap_priv *priv = exaGetPixmapDriverPrivate(pPixmap);
|
||||
struct pipe_texture *tex = NULL;
|
||||
pipe_texture_reference(&tex, priv->tex);
|
||||
return tex;
|
||||
}
|
||||
|
||||
void
|
||||
xorg_exa_close(ScrnInfoPtr pScrn)
|
||||
{
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa = ms->exa;
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa = ms->exa;
|
||||
struct pipe_constant_buffer *vsbuf = &exa->vs_const_buffer;
|
||||
struct pipe_constant_buffer *fsbuf = &exa->fs_const_buffer;
|
||||
|
||||
if (exa->shaders) {
|
||||
xorg_shaders_destroy(exa->shaders);
|
||||
}
|
||||
if (exa->shaders) {
|
||||
xorg_shaders_destroy(exa->shaders);
|
||||
}
|
||||
|
||||
if (exa->cso) {
|
||||
cso_release_all(exa->cso);
|
||||
cso_destroy_context(exa->cso);
|
||||
}
|
||||
if (vsbuf && vsbuf->buffer)
|
||||
pipe_buffer_reference(&vsbuf->buffer, NULL);
|
||||
|
||||
if (exa->ctx)
|
||||
exa->ctx->destroy(exa->ctx);
|
||||
if (fsbuf && fsbuf->buffer)
|
||||
pipe_buffer_reference(&fsbuf->buffer, NULL);
|
||||
|
||||
exaDriverFini(pScrn->pScreen);
|
||||
xfree(exa);
|
||||
ms->exa = NULL;
|
||||
if (exa->cso) {
|
||||
cso_release_all(exa->cso);
|
||||
cso_destroy_context(exa->cso);
|
||||
}
|
||||
|
||||
if (exa->ctx)
|
||||
exa->ctx->destroy(exa->ctx);
|
||||
|
||||
exaDriverFini(pScrn->pScreen);
|
||||
xfree(exa);
|
||||
ms->exa = NULL;
|
||||
}
|
||||
|
||||
void *
|
||||
xorg_exa_init(ScrnInfoPtr pScrn)
|
||||
{
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa;
|
||||
ExaDriverPtr pExa;
|
||||
modesettingPtr ms = modesettingPTR(pScrn);
|
||||
struct exa_context *exa;
|
||||
ExaDriverPtr pExa;
|
||||
|
||||
exa = xcalloc(1, sizeof(struct exa_context));
|
||||
if (!exa)
|
||||
return NULL;
|
||||
exa = xcalloc(1, sizeof(struct exa_context));
|
||||
if (!exa)
|
||||
return NULL;
|
||||
|
||||
pExa = exaDriverAlloc();
|
||||
if (!pExa) {
|
||||
goto out_err;
|
||||
}
|
||||
pExa = exaDriverAlloc();
|
||||
if (!pExa) {
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
memset(pExa, 0, sizeof(*pExa));
|
||||
memset(pExa, 0, sizeof(*pExa));
|
||||
|
||||
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->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->ModifyPixmapHeader = ExaModifyPixmapHeader;
|
||||
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)) {
|
||||
goto out_err;
|
||||
}
|
||||
if (!exaDriverInit(pScrn->pScreen, pExa)) {
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
exa->scrn = ms->screen;
|
||||
exa->ctx = ms->api->create_context(ms->api, exa->scrn);
|
||||
/* Share context with DRI */
|
||||
ms->ctx = exa->ctx;
|
||||
exa->scrn = ms->screen;
|
||||
exa->ctx = ms->api->create_context(ms->api, exa->scrn);
|
||||
/* Share context with DRI */
|
||||
ms->ctx = exa->ctx;
|
||||
|
||||
exa->cso = cso_create_context(exa->ctx);
|
||||
exa->shaders = xorg_shaders_create(exa);
|
||||
exa->cso = cso_create_context(exa->ctx);
|
||||
exa->shaders = xorg_shaders_create(exa);
|
||||
|
||||
return (void *)exa;
|
||||
return (void *)exa;
|
||||
|
||||
out_err:
|
||||
xorg_exa_close(pScrn);
|
||||
out_err:
|
||||
xorg_exa_close(pScrn);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct pipe_surface *
|
||||
exa_gpu_surface(struct exa_context *exa, struct exa_pixmap_priv *priv)
|
||||
{
|
||||
return exa->scrn->get_tex_surface(exa->scrn, priv->tex, 0, 0, 0,
|
||||
PIPE_BUFFER_USAGE_GPU_READ |
|
||||
PIPE_BUFFER_USAGE_GPU_WRITE);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* vim: set sw=4 ts=8 sts=4: */
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "xorg_tracker.h"
|
||||
|
||||
#include <pipe/p_state.h>
|
||||
|
||||
struct cso_context;
|
||||
struct xorg_shaders;
|
||||
|
||||
|
@ -13,6 +15,9 @@ struct exa_context
|
|||
struct pipe_screen *scrn;
|
||||
struct cso_context *cso;
|
||||
struct xorg_shaders *shaders;
|
||||
|
||||
struct pipe_constant_buffer vs_const_buffer;
|
||||
struct pipe_constant_buffer fs_const_buffer;
|
||||
};
|
||||
|
||||
|
||||
|
@ -29,6 +34,8 @@ struct exa_pixmap_priv
|
|||
unsigned map_count;
|
||||
};
|
||||
|
||||
struct pipe_surface *
|
||||
exa_gpu_surface(struct exa_context *exa, struct exa_pixmap_priv *priv);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -17,14 +17,8 @@
|
|||
#include "cso_cache/cso_context.h"
|
||||
#include "cso_cache/cso_hash.h"
|
||||
|
||||
struct xorg_shaders {
|
||||
struct exa_context *exa;
|
||||
|
||||
struct cso_hash *vs_hash;
|
||||
struct cso_hash *fs_hash;
|
||||
};
|
||||
|
||||
/* SAMP[0] = dst
|
||||
/* Fragment shader:
|
||||
* SAMP[0] = dst
|
||||
* SAMP[1] = src
|
||||
* SAMP[2] = mask
|
||||
* IN[0] = pos dst
|
||||
|
@ -33,6 +27,13 @@ struct xorg_shaders {
|
|||
* CONST[0] = (0, 0, 0, 1)
|
||||
*/
|
||||
|
||||
struct xorg_shaders {
|
||||
struct exa_context *exa;
|
||||
|
||||
struct cso_hash *vs_hash;
|
||||
struct cso_hash *fs_hash;
|
||||
};
|
||||
|
||||
static const char over_op[] =
|
||||
"SUB TEMP[3], CONST[0].wwww, TEMP[1].wwww\n"
|
||||
"MUL TEMP[3], TEMP[0], TEMP[3]\n"
|
||||
|
|
Loading…
Reference in New Issue