diff options
author | Eric Anholt <eric@anholt.net> | 2009-10-06 16:30:08 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2009-10-06 17:10:31 -0700 |
commit | 8ae0e44e42db645abe6d385f561260d2ae4a1960 (patch) | |
tree | 2002c65e2d302a32ec5d0b19a8708c3c7264b7c6 /src/xvmc | |
parent | b9b159c49854d8d9d2207946bb583537bb0d48d6 (diff) |
Move to kernel coding style.
We've talked about doing this since the start of the project, putting it off
until "some convenient time". Just after removing a third of the driver seems
like a convenient time, when backporting's probably not happening much anyway.
Diffstat (limited to 'src/xvmc')
-rw-r--r-- | src/xvmc/dri2.c | 405 | ||||
-rw-r--r-- | src/xvmc/dri2.h | 37 | ||||
-rw-r--r-- | src/xvmc/i915_program.h | 146 | ||||
-rw-r--r-- | src/xvmc/i915_structs.h | 1441 | ||||
-rw-r--r-- | src/xvmc/i915_xvmc.c | 4366 | ||||
-rw-r--r-- | src/xvmc/i915_xvmc.h | 80 | ||||
-rw-r--r-- | src/xvmc/i965_xvmc.c | 1190 | ||||
-rw-r--r-- | src/xvmc/i965_xvmc.h | 1 | ||||
-rw-r--r-- | src/xvmc/intel_batchbuffer.c | 198 | ||||
-rw-r--r-- | src/xvmc/intel_batchbuffer.h | 5 | ||||
-rw-r--r-- | src/xvmc/intel_xvmc.c | 1362 | ||||
-rw-r--r-- | src/xvmc/intel_xvmc.h | 251 | ||||
-rw-r--r-- | src/xvmc/intel_xvmc_dump.c | 211 | ||||
-rw-r--r-- | src/xvmc/xvmc_vld.c | 1737 |
14 files changed, 5864 insertions, 5566 deletions
diff --git a/src/xvmc/dri2.c b/src/xvmc/dri2.c index f967432b..1ba94823 100644 --- a/src/xvmc/dri2.c +++ b/src/xvmc/dri2.c @@ -30,7 +30,6 @@ * Kristian Høgsberg (krh@redhat.com) */ - #define NEED_REPLIES #include <X11/Xlibint.h> #include <X11/extensions/Xext.h> @@ -41,261 +40,259 @@ static char dri2ExtensionName[] = DRI2_NAME; static XExtensionInfo *dri2Info; -static XEXT_GENERATE_CLOSE_DISPLAY (DRI2CloseDisplay, dri2Info) +static XEXT_GENERATE_CLOSE_DISPLAY(DRI2CloseDisplay, dri2Info) static /* const */ XExtensionHooks dri2ExtensionHooks = { - NULL, /* create_gc */ - NULL, /* copy_gc */ - NULL, /* flush_gc */ - NULL, /* free_gc */ - NULL, /* create_font */ - NULL, /* free_font */ - DRI2CloseDisplay, /* close_display */ - NULL, /* wire_to_event */ - NULL, /* event_to_wire */ - NULL, /* error */ - NULL, /* error_string */ + NULL, /* create_gc */ + NULL, /* copy_gc */ + NULL, /* flush_gc */ + NULL, /* free_gc */ + NULL, /* create_font */ + NULL, /* free_font */ + DRI2CloseDisplay, /* close_display */ + NULL, /* wire_to_event */ + NULL, /* event_to_wire */ + NULL, /* error */ + NULL, /* error_string */ }; -static XEXT_GENERATE_FIND_DISPLAY (DRI2FindDisplay, dri2Info, - dri2ExtensionName, - &dri2ExtensionHooks, - 0, NULL) +static XEXT_GENERATE_FIND_DISPLAY(DRI2FindDisplay, dri2Info, + dri2ExtensionName, + &dri2ExtensionHooks, 0, NULL) -Bool DRI2QueryExtension(Display *dpy, int *eventBase, int *errorBase) +Bool DRI2QueryExtension(Display * dpy, int *eventBase, int *errorBase) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); + XExtDisplayInfo *info = DRI2FindDisplay(dpy); - if (XextHasExtension(info)) { - *eventBase = info->codes->first_event; - *errorBase = info->codes->first_error; - return True; - } + if (XextHasExtension(info)) { + *eventBase = info->codes->first_event; + *errorBase = info->codes->first_error; + return True; + } - return False; + return False; } -Bool DRI2QueryVersion(Display *dpy, int *major, int *minor) +Bool DRI2QueryVersion(Display * dpy, int *major, int *minor) { - XExtDisplayInfo *info = DRI2FindDisplay (dpy); - xDRI2QueryVersionReply rep; - xDRI2QueryVersionReq *req; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReq(DRI2QueryVersion, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2QueryVersion; - req->majorVersion = DRI2_MAJOR; - req->minorVersion = DRI2_MINOR; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2QueryVersionReply rep; + xDRI2QueryVersionReq *req; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2QueryVersion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2QueryVersion; + req->majorVersion = DRI2_MAJOR; + req->minorVersion = DRI2_MINOR; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + *major = rep.majorVersion; + *minor = rep.minorVersion; UnlockDisplay(dpy); SyncHandle(); - return False; - } - *major = rep.majorVersion; - *minor = rep.minorVersion; - UnlockDisplay(dpy); - SyncHandle(); - return True; + return True; } -Bool DRI2Connect(Display *dpy, XID window, +Bool DRI2Connect(Display * dpy, XID window, char **driverName, char **deviceName) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2ConnectReply rep; - xDRI2ConnectReq *req; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReq(DRI2Connect, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2Connect; - req->window = window; - req->driverType = DRI2DriverDRI; - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return False; - } + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2ConnectReply rep; + xDRI2ConnectReq *req; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReq(DRI2Connect, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Connect; + req->window = window; + req->driverType = DRI2DriverDRI; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + + *driverName = Xmalloc(rep.driverNameLength + 1); + if (*driverName == NULL) { + _XEatData(dpy, + ((rep.driverNameLength + 3) & ~3) + + ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *driverName, rep.driverNameLength); + (*driverName)[rep.driverNameLength] = '\0'; + + *deviceName = Xmalloc(rep.deviceNameLength + 1); + if (*deviceName == NULL) { + Xfree(*driverName); + _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); + UnlockDisplay(dpy); + SyncHandle(); + return False; + } + _XReadPad(dpy, *deviceName, rep.deviceNameLength); + (*deviceName)[rep.deviceNameLength] = '\0'; - if (rep.driverNameLength == 0 && rep.deviceNameLength == 0) { UnlockDisplay(dpy); SyncHandle(); - return False; - } - - *driverName = Xmalloc(rep.driverNameLength + 1); - if (*driverName == NULL) { - _XEatData(dpy, - ((rep.driverNameLength + 3) & ~3) + - ((rep.deviceNameLength + 3) & ~3)); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - _XReadPad(dpy, *driverName, rep.driverNameLength); - (*driverName)[rep.driverNameLength] = '\0'; - - *deviceName = Xmalloc(rep.deviceNameLength + 1); - if (*deviceName == NULL) { - Xfree(*driverName); - _XEatData(dpy, ((rep.deviceNameLength + 3) & ~3)); - UnlockDisplay(dpy); - SyncHandle(); - return False; - } - _XReadPad(dpy, *deviceName, rep.deviceNameLength); - (*deviceName)[rep.deviceNameLength] = '\0'; - - UnlockDisplay(dpy); - SyncHandle(); - return True; + return True; } -Bool DRI2Authenticate(Display *dpy, XID window, drm_magic_t magic) +Bool DRI2Authenticate(Display * dpy, XID window, drm_magic_t magic) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2AuthenticateReq *req; - xDRI2AuthenticateReply rep; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2AuthenticateReq *req; + xDRI2AuthenticateReply rep; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); - XextCheckExtension (dpy, info, dri2ExtensionName, False); + LockDisplay(dpy); + GetReq(DRI2Authenticate, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2Authenticate; + req->window = window; + req->magic = magic; - LockDisplay(dpy); - GetReq(DRI2Authenticate, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2Authenticate; - req->window = window; - req->magic = magic; + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return False; + } - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { UnlockDisplay(dpy); SyncHandle(); - return False; - } - - UnlockDisplay(dpy); - SyncHandle(); - return rep.authenticated; + return rep.authenticated; } -void DRI2CreateDrawable(Display *dpy, XID drawable) +void DRI2CreateDrawable(Display * dpy, XID drawable) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2CreateDrawableReq *req; - - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); - - LockDisplay(dpy); - GetReq(DRI2CreateDrawable, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2CreateDrawable; - req->drawable = drawable; - UnlockDisplay(dpy); - SyncHandle(); + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CreateDrawableReq *req; + + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); + + LockDisplay(dpy); + GetReq(DRI2CreateDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CreateDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); } -void DRI2DestroyDrawable(Display *dpy, XID drawable) +void DRI2DestroyDrawable(Display * dpy, XID drawable) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2DestroyDrawableReq *req; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2DestroyDrawableReq *req; - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); - XSync(dpy, False); + XSync(dpy, False); - LockDisplay(dpy); - GetReq(DRI2DestroyDrawable, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2DestroyDrawable; - req->drawable = drawable; - UnlockDisplay(dpy); - SyncHandle(); + LockDisplay(dpy); + GetReq(DRI2DestroyDrawable, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2DestroyDrawable; + req->drawable = drawable; + UnlockDisplay(dpy); + SyncHandle(); } -DRI2Buffer *DRI2GetBuffers(Display *dpy, XID drawable, +DRI2Buffer *DRI2GetBuffers(Display * dpy, XID drawable, int *width, int *height, - unsigned int *attachments, int count, - int *outCount) + unsigned int *attachments, int count, int *outCount) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2GetBuffersReply rep; - xDRI2GetBuffersReq *req; - DRI2Buffer *buffers; - xDRI2Buffer repBuffer; - CARD32 *p; - int i; - - XextCheckExtension (dpy, info, dri2ExtensionName, False); - - LockDisplay(dpy); - GetReqExtra(DRI2GetBuffers, count * 4, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2GetBuffers; - req->drawable = drawable; - req->count = count; - p = (CARD32 *) &req[1]; - for (i = 0; i < count; i++) - p[i] = attachments[i]; - - if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) { - UnlockDisplay(dpy); - SyncHandle(); - return NULL; - } + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2GetBuffersReply rep; + xDRI2GetBuffersReq *req; + DRI2Buffer *buffers; + xDRI2Buffer repBuffer; + CARD32 *p; + int i; + + XextCheckExtension(dpy, info, dri2ExtensionName, False); + + LockDisplay(dpy); + GetReqExtra(DRI2GetBuffers, count * 4, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2GetBuffers; + req->drawable = drawable; + req->count = count; + p = (CARD32 *) & req[1]; + for (i = 0; i < count; i++) + p[i] = attachments[i]; + + if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + *width = rep.width; + *height = rep.height; + *outCount = rep.count; + + buffers = Xmalloc(rep.count * sizeof buffers[0]); + if (buffers == NULL) { + _XEatData(dpy, rep.count * sizeof repBuffer); + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + for (i = 0; i < rep.count; i++) { + _XReadPad(dpy, (char *)&repBuffer, sizeof repBuffer); + buffers[i].attachment = repBuffer.attachment; + buffers[i].name = repBuffer.name; + buffers[i].pitch = repBuffer.pitch; + buffers[i].cpp = repBuffer.cpp; + buffers[i].flags = repBuffer.flags; + } - *width = rep.width; - *height = rep.height; - *outCount = rep.count; - - buffers = Xmalloc(rep.count * sizeof buffers[0]); - if (buffers == NULL) { - _XEatData(dpy, rep.count * sizeof repBuffer); UnlockDisplay(dpy); SyncHandle(); - return NULL; - } - - for (i = 0; i < rep.count; i++) { - _XReadPad(dpy, (char *) &repBuffer, sizeof repBuffer); - buffers[i].attachment = repBuffer.attachment; - buffers[i].name = repBuffer.name; - buffers[i].pitch = repBuffer.pitch; - buffers[i].cpp = repBuffer.cpp; - buffers[i].flags = repBuffer.flags; - } - - UnlockDisplay(dpy); - SyncHandle(); - - return buffers; + + return buffers; } -void DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region, +void DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region, CARD32 dest, CARD32 src) { - XExtDisplayInfo *info = DRI2FindDisplay(dpy); - xDRI2CopyRegionReq *req; - xDRI2CopyRegionReply rep; + XExtDisplayInfo *info = DRI2FindDisplay(dpy); + xDRI2CopyRegionReq *req; + xDRI2CopyRegionReply rep; - XextSimpleCheckExtension (dpy, info, dri2ExtensionName); + XextSimpleCheckExtension(dpy, info, dri2ExtensionName); - LockDisplay(dpy); - GetReq(DRI2CopyRegion, req); - req->reqType = info->codes->major_opcode; - req->dri2ReqType = X_DRI2CopyRegion; - req->drawable = drawable; - req->region = region; - req->dest = dest; - req->src = src; + LockDisplay(dpy); + GetReq(DRI2CopyRegion, req); + req->reqType = info->codes->major_opcode; + req->dri2ReqType = X_DRI2CopyRegion; + req->drawable = drawable; + req->region = region; + req->dest = dest; + req->src = src; - _XReply(dpy, (xReply *)&rep, 0, xFalse); + _XReply(dpy, (xReply *) & rep, 0, xFalse); - UnlockDisplay(dpy); - SyncHandle(); + UnlockDisplay(dpy); + SyncHandle(); } diff --git a/src/xvmc/dri2.h b/src/xvmc/dri2.h index 356c6bcb..ac6ce58d 100644 --- a/src/xvmc/dri2.h +++ b/src/xvmc/dri2.h @@ -37,34 +37,29 @@ #include <X11/extensions/dri2tokens.h> typedef struct { - unsigned int attachment; - unsigned int name; - unsigned int pitch; - unsigned int cpp; - unsigned int flags; + unsigned int attachment; + unsigned int name; + unsigned int pitch; + unsigned int cpp; + unsigned int flags; } DRI2Buffer; extern Bool -DRI2QueryExtension(Display *display, int *eventBase, int *errorBase); +DRI2QueryExtension(Display * display, int *eventBase, int *errorBase); +extern Bool DRI2QueryVersion(Display * display, int *major, int *minor); extern Bool -DRI2QueryVersion(Display *display, int *major, int *minor); -extern Bool -DRI2Connect(Display *display, XID window, +DRI2Connect(Display * display, XID window, char **driverName, char **deviceName); -extern Bool -DRI2Authenticate(Display *display, XID window, drm_magic_t magic); -extern void -DRI2CreateDrawable(Display *display, XID drawable); -extern void -DRI2DestroyDrawable(Display *display, XID handle); -extern DRI2Buffer * -DRI2GetBuffers(Display *dpy, XID drawable, - int *width, int *height, - unsigned int *attachments, int count, - int *outCount); +extern Bool DRI2Authenticate(Display * display, XID window, drm_magic_t magic); +extern void DRI2CreateDrawable(Display * display, XID drawable); +extern void DRI2DestroyDrawable(Display * display, XID handle); +extern DRI2Buffer *DRI2GetBuffers(Display * dpy, XID drawable, + int *width, int *height, + unsigned int *attachments, int count, + int *outCount); extern void -DRI2CopyRegion(Display *dpy, XID drawable, XserverRegion region, +DRI2CopyRegion(Display * dpy, XID drawable, XserverRegion region, CARD32 dest, CARD32 src); #endif diff --git a/src/xvmc/i915_program.h b/src/xvmc/i915_program.h index 82c920e0..da315437 100644 --- a/src/xvmc/i915_program.h +++ b/src/xvmc/i915_program.h @@ -1,33 +1,33 @@ #ifndef _I915_PROGRAM_H #define _I915_PROGRAM_H -#define REG_TYPE_R 0 /* temporary regs, no need to - * dcl, must be written before - * read -- Preserved between - * phases. - */ -#define REG_TYPE_T 1 /* Interpolated values, must be - * dcl'ed before use. - * - * 0..7: texture coord, - * 8: diffuse spec, - * 9: specular color, - * 10: fog parameter in w. - */ -#define REG_TYPE_CONST 2 /* Restriction: only one const - * can be referenced per - * instruction, though it may be - * selected for multiple inputs. - * Constants not initialized - * default to zero. - */ -#define REG_TYPE_S 3 /* sampler */ -#define REG_TYPE_OC 4 /* output color (rgba) */ -#define REG_TYPE_OD 5 /* output depth (w), xyz are - * temporaries. If not written, - * interpolated depth is used? - */ -#define REG_TYPE_U 6 /* unpreserved temporaries */ +#define REG_TYPE_R 0 /* temporary regs, no need to + * dcl, must be written before + * read -- Preserved between + * phases. + */ +#define REG_TYPE_T 1 /* Interpolated values, must be + * dcl'ed before use. + * + * 0..7: texture coord, + * 8: diffuse spec, + * 9: specular color, + * 10: fog parameter in w. + */ +#define REG_TYPE_CONST 2 /* Restriction: only one const + * can be referenced per + * instruction, though it may be + * selected for multiple inputs. + * Constants not initialized + * default to zero. + */ +#define REG_TYPE_S 3 /* sampler */ +#define REG_TYPE_OC 4 /* output color (rgba) */ +#define REG_TYPE_OD 5 /* output depth (w), xyz are + * temporaries. If not written, + * interpolated depth is used? + */ +#define REG_TYPE_U 6 /* unpreserved temporaries */ #define REG_TYPE_MASK 0x7 #define REG_NR_MASK 0xf @@ -43,34 +43,34 @@ #define T_TEX7 7 #define T_DIFFUSE 8 #define T_SPECULAR 9 -#define T_FOG_W 10 /* interpolated fog is in W coord */ +#define T_FOG_W 10 /* interpolated fog is in W coord */ /* Arithmetic instructions */ /* .replicate_swizzle == selection and replication of a particular * scalar channel, ie., .xxxx, .yyyy, .zzzz or .wwww */ -#define A0_NOP (0x0<<24) /* no operation */ -#define A0_ADD (0x1<<24) /* dst = src0 + src1 */ -#define A0_MOV (0x2<<24) /* dst = src0 */ -#define A0_MUL (0x3<<24) /* dst = src0 * src1 */ -#define A0_MAD (0x4<<24) /* dst = src0 * src1 + src2 */ -#define A0_DP2ADD (0x5<<24) /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */ -#define A0_DP3 (0x6<<24) /* dst.xyzw = src0.xyz dot src1.xyz */ -#define A0_DP4 (0x7<<24) /* dst.xyzw = src0.xyzw dot src1.xyzw */ -#define A0_FRC (0x8<<24) /* dst = src0 - floor(src0) */ -#define A0_RCP (0x9<<24) /* dst.xyzw = 1/(src0.replicate_swizzle) */ -#define A0_RSQ (0xa<<24) /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */ -#define A0_EXP (0xb<<24) /* dst.xyzw = exp2(src0.replicate_swizzle) */ -#define A0_LOG (0xc<<24) /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */ -#define A0_CMP (0xd<<24) /* dst = (src0 >= 0.0) ? src1 : src2 */ -#define A0_MIN (0xe<<24) /* dst = (src0 < src1) ? src0 : src1 */ -#define A0_MAX (0xf<<24) /* dst = (src0 >= src1) ? src0 : src1 */ -#define A0_FLR (0x10<<24) /* dst = floor(src0) */ -#define A0_MOD (0x11<<24) /* dst = src0 fmod 1.0 */ -#define A0_TRC (0x12<<24) /* dst = int(src0) */ -#define A0_SGE (0x13<<24) /* dst = src0 >= src1 ? 1.0 : 0.0 */ -#define A0_SLT (0x14<<24) /* dst = src0 < src1 ? 1.0 : 0.0 */ +#define A0_NOP (0x0<<24) /* no operation */ +#define A0_ADD (0x1<<24) /* dst = src0 + src1 */ +#define A0_MOV (0x2<<24) /* dst = src0 */ +#define A0_MUL (0x3<<24) /* dst = src0 * src1 */ +#define A0_MAD (0x4<<24) /* dst = src0 * src1 + src2 */ +#define A0_DP2ADD (0x5<<24) /* dst.xyzw = src0.xy dot src1.xy + src2.replicate_swizzle */ +#define A0_DP3 (0x6<<24) /* dst.xyzw = src0.xyz dot src1.xyz */ +#define A0_DP4 (0x7<<24) /* dst.xyzw = src0.xyzw dot src1.xyzw */ +#define A0_FRC (0x8<<24) /* dst = src0 - floor(src0) */ +#define A0_RCP (0x9<<24) /* dst.xyzw = 1/(src0.replicate_swizzle) */ +#define A0_RSQ (0xa<<24) /* dst.xyzw = 1/(sqrt(abs(src0.replicate_swizzle))) */ +#define A0_EXP (0xb<<24) /* dst.xyzw = exp2(src0.replicate_swizzle) */ +#define A0_LOG (0xc<<24) /* dst.xyzw = log2(abs(src0.replicate_swizzle)) */ +#define A0_CMP (0xd<<24) /* dst = (src0 >= 0.0) ? src1 : src2 */ +#define A0_MIN (0xe<<24) /* dst = (src0 < src1) ? src0 : src1 */ +#define A0_MAX (0xf<<24) /* dst = (src0 >= src1) ? src0 : src1 */ +#define A0_FLR (0x10<<24) /* dst = floor(src0) */ +#define A0_MOD (0x11<<24) /* dst = src0 fmod 1.0 */ +#define A0_TRC (0x12<<24) /* dst = int(src0) */ +#define A0_SGE (0x13<<24) /* dst = src0 >= src1 ? 1.0 : 0.0 */ +#define A0_SLT (0x14<<24) /* dst = src0 < src1 ? 1.0 : 0.0 */ #define A0_DEST_SATURATE (1<<22) #define A0_DEST_TYPE_SHIFT 19 /* Allow: R, OC, OD, U */ @@ -126,9 +126,9 @@ #define A2_SRC2_CHANNEL_W_SHIFT 0 /* Declaration instructions */ -#define D0_DCL (0x19<<24) /* Declare a t (interpolated attrib) - * register or an s (sampler) - * register. */ +#define D0_DCL (0x19<<24) /* Declare a t (interpolated attrib) + * register or an s (sampler) + * register. */ #define D0_SAMPLE_TYPE_SHIFT 22 #define D0_SAMPLE_TYPE_2D (0x0<<22) #define D0_SAMPLE_TYPE_CUBE (0x1<<22) @@ -160,23 +160,23 @@ #define D2_MBZ 0 /* Texture instructions */ -#define T0_TEXLD (0x15<<24) /* Sample texture using predeclared - * sampler and address, and output - * filtered texel data to destination - * register */ -#define T0_TEXLDP (0x16<<24) /* Same as texld but performs a - * perspective divide of the texture - * coordinate .xyz values by .w before - * sampling. */ -#define T0_TEXLDB (0x17<<24) /* Same as texld but biases the - * computed LOD by w. Only S4.6 two's - * comp is used. This implies that a - * float to fixed conversion is - * done. */ -#define T0_TEXKILL (0x18<<24) /* Does not perform a sampling - * operation. Simply kills the pixel - * if any channel of the address - * register is < 0.0. */ +#define T0_TEXLD (0x15<<24) /* Sample texture using predeclared + * sampler and address, and output + * filtered texel data to destination + * register */ +#define T0_TEXLDP (0x16<<24) /* Same as texld but performs a + * perspective divide of the texture + * coordinate .xyz values by .w before + * sampling. */ +#define T0_TEXLDB (0x17<<24) /* Same as texld but biases the + * computed LOD by w. Only S4.6 two's + * comp is used. This implies that a + * float to fixed conversion is + * done. */ +#define T0_TEXKILL (0x18<<24) /* Does not perform a sampling + * operation. Simply kills the pixel + * if any channel of the address + * register is < 0.0. */ #define T0_DEST_TYPE_SHIFT 19 /* Allow: R, OC, OD, U */ /* Note: U (unpreserved) regs do not retain their values between @@ -188,15 +188,14 @@ */ #define T0_DEST_NR_SHIFT 14 /* Allow R: 0..15, OC,OD: 0..0, U: 0..2 */ -#define T0_SAMPLER_NR_SHIFT 0 /* This field ignored for TEXKILL */ +#define T0_SAMPLER_NR_SHIFT 0 /* This field ignored for TEXKILL */ #define T0_SAMPLER_NR_MASK (0xf<<0) -#define T1_ADDRESS_REG_TYPE_SHIFT 24 /* Reg to use as texture coord */ +#define T1_ADDRESS_REG_TYPE_SHIFT 24 /* Reg to use as texture coord */ /* Allow R, T, OC, OD -- R, OC, OD are 'dependent' reads, new program phase */ #define T1_ADDRESS_REG_NR_SHIFT 17 #define T2_MBZ 0 - /* Having zero and one in here makes the definition of swizzle a lot * easier. */ @@ -215,7 +214,7 @@ #define UREG_CHANNEL_ONE_NEGATE_MBZ 1 #define UREG_CHANNEL_ONE_SHIFT 0 -#define UREG_BAD 0xffffffff /* not a valid ureg */ +#define UREG_BAD 0xffffffff /* not a valid ureg */ #define X SRC_X #define Y SRC_Y @@ -258,7 +257,6 @@ #define T1_ADDRESS_REG( reg ) ((GET_UREG_NR(reg) << T1_ADDRESS_REG_NR_SHIFT) | \ (GET_UREG_TYPE(reg) << T1_ADDRESS_REG_TYPE_SHIFT)) - /* Macros for translating UREG's into the various register fields used * by the I915 programmable unit. */ diff --git a/src/xvmc/i915_structs.h b/src/xvmc/i915_structs.h index b5185cb7..f9e67477 100644 --- a/src/xvmc/i915_structs.h +++ b/src/xvmc/i915_structs.h @@ -35,53 +35,51 @@ #define OPC_MI_FLUSH (0x04) -struct i915_mi_flush -{ - struct { - unsigned map_cache_invalidate : 1; - unsigned pad0 : 1; - unsigned render_cache_flush_inhibit : 1; - unsigned scene_count : 1; - unsigned end_scene : 1; - unsigned pad1 : 18; - unsigned opcode : 6; - unsigned type : 3; - } dw0; +struct i915_mi_flush { + struct { + unsigned map_cache_invalidate:1; + unsigned pad0:1; + unsigned render_cache_flush_inhibit:1; + unsigned scene_count:1; + unsigned end_scene:1; + unsigned pad1:18; + unsigned opcode:6; + unsigned type:3; + } dw0; }; /* BLT */ #define CMD_2D 0x02 #define OPC_COLOR_BLT (0x40) -struct i915_color_blt -{ - struct { - unsigned length : 5; - unsigned pad0 : 15; - unsigned bpp_mask : 2; - unsigned opcode : 7; - unsigned type : 3; - } dw0; - - struct { - unsigned pitch : 16; - unsigned rop : 8; - unsigned color_depth : 2; - unsigned pad0 : 6; - } dw1; - - struct { - unsigned width : 16; - unsigned height : 16; - } dw2; - - struct { - unsigned address; - } dw3; - - struct { - unsigned pattern; - } dw4; +struct i915_color_blt { + struct { + unsigned length:5; + unsigned pad0:15; + unsigned bpp_mask:2; + unsigned opcode:7; + unsigned type:3; + } dw0; + + struct { + unsigned pitch:16; + unsigned rop:8; + unsigned color_depth:2; + unsigned pad0:6; + } dw1; + + struct { + unsigned width:16; + unsigned height:16; + } dw2; + + struct { + unsigned address; + } dw3; + + struct { + unsigned pattern; + } dw4; }; /* 3D_INSTRUCTION */ @@ -89,7 +87,7 @@ struct i915_color_blt #define OPC_3DMPEG_MACROBLOCK_IPICTURE (0x01 + (0x1e << 5)) #define OPC_3DMPEG_SET_ORIGIN (0x10 + (0x1e << 5)) -#define OPC_3DMPEG_MACROBLOCK (0x11 + (0x1e << 5)) +#define OPC_3DMPEG_MACROBLOCK (0x11 + (0x1e << 5)) #define OPC_3DMPEG_SLICE (0x12 + (0x1e << 5)) #define OPC_3DMPEG_QM_PALETTE_LOAD (0x13 + (0x1e << 5)) @@ -115,129 +113,119 @@ struct i915_color_blt /* * 3DMPEG instructions */ -struct i915_3dmpeg_macroblock_header -{ - struct { - unsigned length : 19; - unsigned opcode : 10; - unsigned type : 3; - } dw0; - - struct { - unsigned mb_intra : 1; - unsigned forward : 1; - unsigned backward : 1; - unsigned h263_4mv : 1; - unsigned pad0 : 1; - unsigned dct_type : 1; - unsigned pad1 : 2; - unsigned motion_type : 2; - unsigned pad2 : 2; - unsigned vertical_field_select : 4; - unsigned coded_block_pattern : 6; - unsigned pad3 : 2; - unsigned skipped_macroblocks : 7; - unsigned pad4 : 1; - } dw1; +struct i915_3dmpeg_macroblock_header { + struct { + unsigned length:19; + unsigned opcode:10; + unsigned type:3; + } dw0; + + struct { + unsigned mb_intra:1; + unsigned forward:1; + unsigned backward:1; + unsigned h263_4mv:1; + unsigned pad0:1; + unsigned dct_type:1; + unsigned pad1:2; + unsigned motion_type:2; + unsigned pad2:2; + unsigned vertical_field_select:4; + unsigned coded_block_pattern:6; + unsigned pad3:2; + unsigned skipped_macroblocks:7; + unsigned pad4:1; + } dw1; +}; + +struct i915_3dmpeg_macroblock_0mv { + struct i915_3dmpeg_macroblock_header header; +}; + +struct i915_3dmpeg_macroblock_1fbmv { + struct i915_3dmpeg_macroblock_header header; + unsigned dw2; + unsigned dw3; +}; +struct i915_3dmpeg_macroblock_2fbmv { + struct i915_3dmpeg_macroblock_header header; + unsigned dw2; + unsigned dw3; + unsigned dw4; + unsigned dw5; +}; + +struct i915_3dmpeg_macroblock_5fmv { + struct i915_3dmpeg_macroblock_header header; + unsigned dw2; + unsigned dw3; + unsigned dw4; + unsigned dw5; + unsigned dw6; +}; + +struct i915_3dmpeg_macroblock_ipicture { + struct { + unsigned pad0:5; + unsigned dct_type:1; + unsigned pad1:13; + unsigned opcode:10; + unsigned type:3; + } dw0; +}; + +struct i915_3dmpeg_set_origin { + struct { + unsigned length:19; + unsigned opcode:10; + unsigned type:3; + } dw0; + + struct { + unsigned v_origin:7; + unsigned pad0:1; + unsigned h_origin:7; + unsigned pad1:17; + } dw1; +}; + +struct i915_3dmpeg_slice { + struct { + unsigned length:19; + unsigned opcode:10; + unsigned type:3; + } dw0; + + struct { + unsigned fst_mb_bit_off:3; + unsigned pad0:5; + unsigned mb_count:7; + unsigned pad1:1; + unsigned v_position:7; + unsigned pad2:1; + unsigned h_position:7; + unsigned pad3:1; + } dw1; + + struct { + unsigned length_minus_one:17; + unsigned pad0:7; + unsigned qt_scale_code:5; + unsigned pad1:3; + } dw2; +}; + +struct i915_3dmpeg_qm_palette_load { + struct { + unsigned length:4; + unsigned pad0:15; + unsigned opcode:10; + unsigned type:3; + } dw0; + + unsigned quantmatrix[16]; }; -struct i915_3dmpeg_macroblock_0mv -{ - struct i915_3dmpeg_macroblock_header header; -}; - -struct i915_3dmpeg_macroblock_1fbmv -{ - struct i915_3dmpeg_macroblock_header header; - unsigned dw2; - unsigned dw3; -}; -struct i915_3dmpeg_macroblock_2fbmv -{ - struct i915_3dmpeg_macroblock_header header; - unsigned dw2; - unsigned dw3; - unsigned dw4; - unsigned dw5; -}; - -struct i915_3dmpeg_macroblock_5fmv -{ - struct i915_3dmpeg_macroblock_header header; - unsigned dw2; - unsigned dw3; - unsigned dw4; - unsigned dw5; - unsigned dw6; -}; - -struct i915_3dmpeg_macroblock_ipicture -{ - struct { - unsigned pad0 : 5; - unsigned dct_type : 1; - unsigned pad1 : 13; - unsigned opcode : 10; - unsigned type : 3; - } dw0; -}; - -struct i915_3dmpeg_set_origin -{ - struct { - unsigned length : 19; - unsigned opcode : 10; - unsigned type : 3; - } dw0; - - struct { - unsigned v_origin : 7; - unsigned pad0 : 1; - unsigned h_origin : 7; - unsigned pad1 : 17; - } dw1; -}; - -struct i915_3dmpeg_slice -{ - struct { - unsigned length : 19; - unsigned opcode : 10; - unsigned type : 3; - } dw0; - - struct { - unsigned fst_mb_bit_off : 3; - unsigned pad0 : 5; - unsigned mb_count : 7; - unsigned pad1 : 1; - unsigned v_position : 7; - unsigned pad2 : 1; - unsigned h_position : 7; - unsigned pad3 : 1; - } dw1; - - struct { - unsigned length_minus_one : 17; - unsigned pad0 : 7; - unsigned qt_scale_code : 5; - unsigned pad1 : 3; - } dw2; -}; - -struct i915_3dmpeg_qm_palette_load -{ - struct { - unsigned length : 4; - unsigned pad0 : 15; - unsigned opcode : 10; - unsigned type : 3; - } dw0; - - unsigned quantmatrix[16]; -}; - - /* * 3DSTATE instruction */ @@ -249,31 +237,30 @@ struct i915_3dmpeg_qm_palette_load #define TILEWALK_XMAJOR 0 #define TILEWALK_YMAJOR 1 -struct i915_3dstate_buffer_info -{ - struct { - unsigned length : 16; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned pad0 : 2; - unsigned pitch : 12; - unsigned pad1 : 7; - unsigned walk : 1; - unsigned tiled_surface : 1; - unsigned fence_regs : 1; - unsigned buffer_id : 4; - unsigned aux_id : 1; - unsigned pad2 : 3; - } dw1; - - struct { - unsigned pad0 : 2; - unsigned base_address : 27; - unsigned pad1 : 3; - } dw2; +struct i915_3dstate_buffer_info { + struct { + unsigned length:16; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned pad0:2; + unsigned pitch:12; + unsigned pad1:7; + unsigned walk:1; + unsigned tiled_surface:1; + unsigned fence_regs:1; + unsigned buffer_id:4; + unsigned aux_id:1; + unsigned pad2:3; + } dw1; + + struct { + unsigned pad0:2; + unsigned base_address:27; + unsigned pad1:3; + } dw2; }; #define COLORBUFFER_8BIT 0x00 @@ -288,33 +275,31 @@ struct i915_3dstate_buffer_info #define COLORBUFFER_A1R5G5B5 0x09 #define COLORBUFFER_A2R10G10B10 0x0a - -struct i915_3dstate_dest_buffer_variables -{ - struct { - unsigned length : 16; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned v_ls_offset : 1; - unsigned v_ls : 1; - unsigned depth_fmt : 2; - unsigned pad0 : 4; - unsigned color_fmt : 4; - unsigned yuv422_select : 3; - unsigned pad1 : 1; - unsigned dest_v_bias : 4; - unsigned dest_h_bias : 4; - unsigned dither_enhancement : 1; - unsigned linear_gamma : 1; - unsigned dither_pattern : 2; - unsigned lod_preclamp : 1; - unsigned edt_zone : 1; /* early depth test in zone rendering */ - unsigned texture_default_color : 1; - unsigned edt_classic : 1; /* early depth test in classic mode */ - } dw1; +struct i915_3dstate_dest_buffer_variables { + struct { + unsigned length:16; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned v_ls_offset:1; + unsigned v_ls:1; + unsigned depth_fmt:2; + unsigned pad0:4; + unsigned color_fmt:4; + unsigned yuv422_select:3; + unsigned pad1:1; + unsigned dest_v_bias:4; + unsigned dest_h_bias:4; + unsigned dither_enhancement:1; + unsigned linear_gamma:1; + unsigned dither_pattern:2; + unsigned lod_preclamp:1; + unsigned edt_zone:1; /* early depth test in zone rendering */ + unsigned texture_default_color:1; + unsigned edt_classic:1; /* early depth test in classic mode */ + } dw1; }; #define MPEG_DECODE_MC 0 @@ -331,56 +316,55 @@ struct i915_3dstate_dest_buffer_variables #define MC_SUB_1V 0 #define MC_SUB_2V 1 -struct i915_3dstate_dest_buffer_variables_mpeg -{ - struct { - unsigned length : 16; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned picture_width : 7; - unsigned pad0 : 1; - unsigned v_subsample_factor : 2; - unsigned h_subsample_factor : 2; - unsigned tff : 1; - unsigned mismatch : 1; - unsigned pad1 : 1; - unsigned intra8 : 1; - unsigned abort_on_error : 8; - unsigned pad2 : 4; - unsigned bidir_avrg_control : 1; - unsigned rcontrol : 1; - unsigned decode_mode : 2; - } dw1; - - struct { - unsigned pad0 : 1; - unsigned picture_coding_type : 2; - unsigned pad1 : 2; - unsigned scan_order : 1; - unsigned pad2 : 2; - unsigned q_scale_type : 1; - unsigned concealment : 1; - unsigned fpf_dct : 1; - unsigned pad3 : 2; - unsigned intra_dc : 2; - unsigned intra_vlc : 1; - unsigned f_code00 : 4; - unsigned f_code01 : 4; - unsigned f_code10 : 4; - unsigned f_code11 : 4; - } dw2; +struct i915_3dstate_dest_buffer_variables_mpeg { + struct { + unsigned length:16; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned picture_width:7; + unsigned pad0:1; + unsigned v_subsample_factor:2; + unsigned h_subsample_factor:2; + unsigned tff:1; + unsigned mismatch:1; + unsigned pad1:1; + unsigned intra8:1; + unsigned abort_on_error:8; + unsigned pad2:4; + unsigned bidir_avrg_control:1; + unsigned rcontrol:1; + unsigned decode_mode:2; + } dw1; + + struct { + unsigned pad0:1; + unsigned picture_coding_type:2; + unsigned pad1:2; + unsigned scan_order:1; + unsigned pad2:2; + unsigned q_scale_type:1; + unsigned concealment:1; + unsigned fpf_dct:1; + unsigned pad3:2; + unsigned intra_dc:2; + unsigned intra_vlc:1; + unsigned f_code00:4; + unsigned f_code01:4; + unsigned f_code10:4; + unsigned f_code11:4; + } dw2; }; struct i915_mc_static_indirect_state_buffer { - struct i915_3dstate_buffer_info dest_y; - struct i915_3dstate_buffer_info dest_u; - struct i915_3dstate_buffer_info dest_v; - struct i915_3dstate_dest_buffer_variables dest_buf; - struct i915_3dstate_dest_buffer_variables_mpeg dest_buf_mpeg; - struct i915_3dstate_buffer_info corr; + struct i915_3dstate_buffer_info dest_y; + struct i915_3dstate_buffer_info dest_u; + struct i915_3dstate_buffer_info dest_v; + struct i915_3dstate_dest_buffer_variables dest_buf; + struct i915_3dstate_dest_buffer_variables_mpeg dest_buf_mpeg; + struct i915_3dstate_buffer_info corr; }; #define MAP_MAP0 0x0001 @@ -400,61 +384,59 @@ struct i915_mc_static_indirect_state_buffer { #define MAP_MAP14 0x4000 #define MAP_MAP15 0x8000 -struct texture_map -{ - struct { - unsigned v_ls_offset : 1; - unsigned v_ls : 1; - unsigned base_address : 27; - unsigned pad0 : 2; - unsigned untrusted : 1; - } tm0; - - struct { - unsigned tile_walk : 1; - unsigned tiled_surface : 1; - unsigned utilize_fence_regs : 1; - unsigned texel_fmt : 4; - unsigned surface_fmt : 3; - unsigned width : 11; - unsigned height : 11; - } tm1; - - struct { - unsigned depth : 8; - unsigned mipmap_layout : 1; - unsigned max_lod : 6; - unsigned cube_face : 6; - unsigned pitch : 11; - } tm2; -}; - -struct i915_3dstate_map_state -{ - struct { - unsigned length : 6; - unsigned pad0 : 9; - unsigned retain : 1; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned map_mask : 16; - unsigned pad0 : 16; - } dw1; +struct texture_map { + struct { + unsigned v_ls_offset:1; + unsigned v_ls:1; + unsigned base_address:27; + unsigned pad0:2; + unsigned untrusted:1; + } tm0; + + struct { + unsigned tile_walk:1; + unsigned tiled_surface:1; + unsigned utilize_fence_regs:1; + unsigned texel_fmt:4; + unsigned surface_fmt:3; + unsigned width:11; + unsigned height:11; + } tm1; + + struct { + unsigned depth:8; + unsigned mipmap_layout:1; + unsigned max_lod:6; + unsigned cube_face:6; + unsigned pitch:11; + } tm2; +}; + +struct i915_3dstate_map_state { + struct { + unsigned length:6; + unsigned pad0:9; + unsigned retain:1; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned map_mask:16; + unsigned pad0:16; + } dw1; }; struct i915_mc_map_state { - struct i915_3dstate_map_state y_map; - struct texture_map y_forward; - struct texture_map y_backward; - struct i915_3dstate_map_state u_map; - struct texture_map u_forward; - struct texture_map u_backward; - struct i915_3dstate_map_state v_map; - struct texture_map v_forward; - struct texture_map v_backward; + struct i915_3dstate_map_state y_map; + struct texture_map y_forward; + struct texture_map y_backward; + struct i915_3dstate_map_state u_map; + struct texture_map u_forward; + struct texture_map u_backward; + struct i915_3dstate_map_state v_map; + struct texture_map v_forward; + struct texture_map v_backward; }; #define SAMPLER_SAMPLER0 0x0001 @@ -505,209 +487,202 @@ struct i915_mc_map_state { #define TEXCOORDMODE_CLAMP_BORDER 4 #define TEXCOORDMODE_MIRROR_ONCE 5 -struct texture_sampler -{ - struct { - unsigned shadow_function : 3; - unsigned max_anisotropy : 1; - unsigned shadow_enable : 1; - unsigned lod_bias : 9; - unsigned min_filter : 3; - unsigned mag_filter : 3; - unsigned mip_filter : 2; - unsigned base_level : 5; - unsigned chromakey_index : 2; - unsigned color_conversion : 1; - unsigned planar2packet : 1; - unsigned reverse_gamma : 1; - } ts0; - - struct { - unsigned east_deinterlacer : 1; - unsigned map_index : 4; - unsigned normalized_coor : 1; - unsigned tcz_control : 3; - unsigned tcy_control : 3; - unsigned tcx_control : 3; - unsigned chromakey_enable : 1; - unsigned keyed_texture_filter : 1; - unsigned kill_pixel : 1; - unsigned pad0 : 6; - unsigned min_lod : 8; - } ts1; - - struct { - unsigned default_color; - } ts2; -}; - -struct i915_3dstate_sampler_state -{ - struct { - unsigned length : 6; - unsigned pad0 : 10; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned sampler_masker : 16; - unsigned pad0 : 16; - } dw1; - /* we always use two samplers for mc */ - struct texture_sampler sampler0; - struct texture_sampler sampler1; -}; - -struct arithmetic_inst -{ - struct { - unsigned pad0 : 2; - unsigned src0_reg : 5; - unsigned src0_reg_t : 3; - unsigned dest_channel_mask : 4; - unsigned dest_reg : 4; - unsigned pad1 : 1; - unsigned dest_reg_t: 3; - unsigned dest_saturate : 1; - unsigned pad2 : 1; - unsigned opcode : 5; - unsigned pad3 : 3; - } dw0; - - struct { - unsigned src1_y_select : 3; - unsigned src1_y_negate : 1; - unsigned src1_x_select : 3; - unsigned src1_x_negate : 1; - unsigned src1_reg : 5; - unsigned src1_reg_t : 3; - unsigned src0_w_select : 3; - unsigned src0_w_negate : 1; - unsigned src0_z_select : 3; - unsigned src0_z_negate : 1; - unsigned src0_y_select : 3; - unsigned src0_y_negate : 1; - unsigned src0_x_select : 3; - unsigned src0_x_negate : 1; - } dw1; - - struct { - unsigned src2_w_select : 3; - unsigned src2_w_negate : 1; - unsigned src2_z_select : 3; - unsigned src2_z_negate : 1; - unsigned src2_y_select : 3; - unsigned src2_y_negate : 1; - unsigned src2_x_select : 3; - unsigned src2_x_negate : 1; - unsigned src2_reg : 5; - unsigned src2_reg_t : 3; - unsigned src1_w_select : 3; - unsigned src1_w_negate : 1; - unsigned src1_z_select : 3; - unsigned src1_z_negate : 1; - } dw2; -}; - -struct texture_inst -{ - struct { - unsigned sampler_reg : 4; - unsigned pad0 : 10; - unsigned dest_reg : 4; - unsigned pad1 : 1; - unsigned dest_reg_t : 3; - unsigned pad2 : 2; - unsigned opcode : 5; - unsigned pad3 : 3; - } dw0; - - struct { - unsigned pad0 : 16; - unsigned address_reg : 5; - unsigned pad1 : 3; - unsigned address_reg_t : 3; - unsigned pad2 : 5; - } dw1; - - struct { - unsigned pad0; - } dw2; -}; - -struct declaration_inst -{ - struct { - unsigned pad0 : 10; - unsigned decl_channel_mask : 4; - unsigned decl_reg : 4; - unsigned pad1 : 1; - unsigned decl_reg_t : 2; - unsigned pad2 : 1; - unsigned sampler_type : 2; - unsigned opcode : 5; - unsigned pad3 : 3; - } dw0; - - struct { - unsigned pad0; - } dw1; - - struct { - unsigned pad0; - } dw2; -}; - -union shader_inst -{ - struct arithmetic_inst a; - struct texture_inst t; - struct declaration_inst d; +struct texture_sampler { + struct { + unsigned shadow_function:3; + unsigned max_anisotropy:1; + unsigned shadow_enable:1; + unsigned lod_bias:9; + unsigned min_filter:3; + unsigned mag_filter:3; + unsigned mip_filter:2; + unsigned base_level:5; + unsigned chromakey_index:2; + unsigned color_conversion:1; + unsigned planar2packet:1; + unsigned reverse_gamma:1; + } ts0; + + struct { + unsigned east_deinterlacer:1; + unsigned map_index:4; + unsigned normalized_coor:1; + unsigned tcz_control:3; + unsigned tcy_control:3; + unsigned tcx_control:3; + unsigned chromakey_enable:1; + unsigned keyed_texture_filter:1; + unsigned kill_pixel:1; + unsigned pad0:6; + unsigned min_lod:8; + } ts1; + + struct { + unsigned default_color; + } ts2; +}; + +struct i915_3dstate_sampler_state { + struct { + unsigned length:6; + unsigned pad0:10; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned sampler_masker:16; + unsigned pad0:16; + } dw1; + /* we always use two samplers for mc */ + struct texture_sampler sampler0; + struct texture_sampler sampler1; +}; + +struct arithmetic_inst { + struct { + unsigned pad0:2; + unsigned src0_reg:5; + unsigned src0_reg_t:3; + unsigned dest_channel_mask:4; + unsigned dest_reg:4; + unsigned pad1:1; + unsigned dest_reg_t:3; + unsigned dest_saturate:1; + unsigned pad2:1; + unsigned opcode:5; + unsigned pad3:3; + } dw0; + + struct { + unsigned src1_y_select:3; + unsigned src1_y_negate:1; + unsigned src1_x_select:3; + unsigned src1_x_negate:1; + unsigned src1_reg:5; + unsigned src1_reg_t:3; + unsigned src0_w_select:3; + unsigned src0_w_negate:1; + unsigned src0_z_select:3; + unsigned src0_z_negate:1; + unsigned src0_y_select:3; + unsigned src0_y_negate:1; + unsigned src0_x_select:3; + unsigned src0_x_negate:1; + } dw1; + + struct { + unsigned src2_w_select:3; + unsigned src2_w_negate:1; + unsigned src2_z_select:3; + unsigned src2_z_negate:1; + unsigned src2_y_select:3; + unsigned src2_y_negate:1; + unsigned src2_x_select:3; + unsigned src2_x_negate:1; + unsigned src2_reg:5; + unsigned src2_reg_t:3; + unsigned src1_w_select:3; + unsigned src1_w_negate:1; + unsigned src1_z_select:3; + unsigned src1_z_negate:1; + } dw2; +}; + +struct texture_inst { + struct { + unsigned sampler_reg:4; + unsigned pad0:10; + unsigned dest_reg:4; + unsigned pad1:1; + unsigned dest_reg_t:3; + unsigned pad2:2; + unsigned opcode:5; + unsigned pad3:3; + } dw0; + + struct { + unsigned pad0:16; + unsigned address_reg:5; + unsigned pad1:3; + unsigned address_reg_t:3; + unsigned pad2:5; + } dw1; + + struct { + unsigned pad0; + } dw2; +}; + +struct declaration_inst { + struct { + unsigned pad0:10; + unsigned decl_channel_mask:4; + unsigned decl_reg:4; + unsigned pad1:1; + unsigned decl_reg_t:2; + unsigned pad2:1; + unsigned sampler_type:2; + unsigned opcode:5; + unsigned pad3:3; + } dw0; + + struct { + unsigned pad0; + } dw1; + + struct { + unsigned pad0; + } dw2; +}; + +union shader_inst { + struct arithmetic_inst a; + struct texture_inst t; + struct declaration_inst d; }; struct i915_3dstate_pixel_shader_header { - unsigned length : 9; - unsigned pad0 : 6; - unsigned retain : 1; - unsigned opcode : 13; - unsigned type : 3; -}; - -struct i915_3dstate_pixel_shader_program -{ - struct i915_3dstate_pixel_shader_header shader0; - /* mov oC, c0.0000 */ - uint32_t inst0[3]; - - struct i915_3dstate_pixel_shader_header shader1; - /* dcl t0.xy */ - /* dcl t1.xy */ - /* dcl_2D s0 */ - /* texld r0, t0, s0 */ - /* mov oC, r0 */ - uint32_t inst1[3*5]; - - struct i915_3dstate_pixel_shader_header shader2; - /* dcl t2.xy */ - /* dcl t3.xy */ - /* dcl_2D s1 */ - /* texld r0, t2, s1 */ - /* mov oC, r0 */ - uint32_t inst2[3*5]; - - struct i915_3dstate_pixel_shader_header shader3; - /* dcl t0.xy */ - /* dcl t1.xy */ - /* dcl t2.xy */ - /* dcl t3.xy */ - /* dcl_2D s0 */ - /* dcl_2D s1 */ - /* texld r0, t0, s0 */ - /* texld r0, t2, s1 */ - /* add r0, r0, r1*/ - /* mov oC, r0 */ - uint32_t inst3[3*10]; + unsigned length:9; + unsigned pad0:6; + unsigned retain:1; + unsigned opcode:13; + unsigned type:3; +}; + +struct i915_3dstate_pixel_shader_program { + struct i915_3dstate_pixel_shader_header shader0; + /* mov oC, c0.0000 */ + uint32_t inst0[3]; + + struct i915_3dstate_pixel_shader_header shader1; + /* dcl t0.xy */ + /* dcl t1.xy */ + /* dcl_2D s0 */ + /* texld r0, t0, s0 */ + /* mov oC, r0 */ + uint32_t inst1[3 * 5]; + + struct i915_3dstate_pixel_shader_header shader2; + /* dcl t2.xy */ + /* dcl t3.xy */ + /* dcl_2D s1 */ + /* texld r0, t2, s1 */ + /* mov oC, r0 */ + uint32_t inst2[3 * 5]; + + struct i915_3dstate_pixel_shader_header shader3; + /* dcl t0.xy */ + /* dcl t1.xy */ + /* dcl t2.xy */ + /* dcl t3.xy */ + /* dcl_2D s0 */ + /* dcl_2D s1 */ + /* texld r0, t0, s0 */ + /* texld r0, t2, s1 */ + /* add r0, r0, r1 */ + /* mov oC, r0 */ + uint32_t inst3[3 * 10]; }; #define REG_CR0 0x00000001 @@ -743,28 +718,26 @@ struct i915_3dstate_pixel_shader_program #define REG_CR30 0x40000000 #define REG_CR31 0x80000000 -struct shader_constant -{ - float x; - float y; - float z; - float w; +struct shader_constant { + float x; + float y; + float z; + float w; }; -struct i915_3dstate_pixel_shader_constants -{ - struct { - unsigned length : 8; - unsigned pad0 : 8; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned reg_mask; - } dw1; - /* we only need one constant */ - struct shader_constant value; +struct i915_3dstate_pixel_shader_constants { + struct { + unsigned length:8; + unsigned pad0:8; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned reg_mask; + } dw1; + /* we only need one constant */ + struct shader_constant value; }; #define BLOCK_SIS 0x01 @@ -774,39 +747,36 @@ struct i915_3dstate_pixel_shader_constants #define BLOCK_PSP 0x10 #define BLOCK_PSC 0x20 -typedef struct _state_ddword -{ - struct { - unsigned valid : 1; - unsigned force : 1; - unsigned buffer_address : 30; - } dw0; - - struct { - unsigned length : 9; - unsigned pad0 : 23; - } dw1; +typedef struct _state_ddword { + struct { + unsigned valid:1; + unsigned force:1; + unsigned buffer_address:30; + } dw0; + + struct { + unsigned length:9; + unsigned pad0:23; + } dw1; } sis_state, ssb_state, msb_state, psp_state, psc_state; -typedef struct _state_dword -{ - struct { - unsigned valid : 1; - unsigned reset : 1; - unsigned buffer_address : 30; - } dw0; +typedef struct _state_dword { + struct { + unsigned valid:1; + unsigned reset:1; + unsigned buffer_address:30; + } dw0; } dis_state; -struct i915_3dstate_load_indirect -{ - struct { - unsigned length : 8; - unsigned block_mask : 6; - unsigned mem_select : 1; - unsigned pad0 : 1; - unsigned opcode : 13; - unsigned type : 3; - } dw0; +struct i915_3dstate_load_indirect { + struct { + unsigned length:8; + unsigned block_mask:6; + unsigned mem_select:1; + unsigned pad0:1; + unsigned opcode:13; + unsigned type:3; + } dw0; }; #define TEXCOORDFMT_2FP 0x00 @@ -816,52 +786,50 @@ struct i915_3dstate_load_indirect #define TEXCOORDFMT_2FP_16 0x04 #define TEXCOORDFMT_4FP_16 0x05 #define TEXCOORDFMT_NOT_PRESENT 0x0f -struct s2_dword -{ - unsigned set0_texcoord_fmt : 4; - unsigned set1_texcoord_fmt : 4; - unsigned set2_texcoord_fmt : 4; - unsigned set3_texcoord_fmt : 4; - unsigned set4_texcoord_fmt : 4; - unsigned set5_texcoord_fmt : 4; - unsigned set6_texcoord_fmt : 4; - unsigned set7_texcoord_fmt : 4; -}; - -struct s3_dword -{ - unsigned set0_pcd : 1; - unsigned set0_ws_tcz : 1; - unsigned set0_ws_tcy : 1; - unsigned set0_ws_tcx : 1; - unsigned set1_pcd : 1; - unsigned set1_ws_tcz : 1; - unsigned set1_ws_tcy : 1; - unsigned set1_ws_tcx : 1; - unsigned set2_pcd : 1; - unsigned set2_ws_tcz : 1; - unsigned set2_ws_tcy : 1; - unsigned set2_ws_tcx : 1; - unsigned set3_pcd : 1; - unsigned set3_ws_tcz : 1; - unsigned set3_ws_tcy : 1; - unsigned set3_ws_tcx : 1; - unsigned set4_pcd : 1; - unsigned set4_ws_tcz : 1; - unsigned set4_ws_tcy : 1; - unsigned set4_ws_tcx : 1; - unsigned set5_pcd : 1; - unsigned set5_ws_tcz : 1; - unsigned set5_ws_tcy : 1; - unsigned set5_ws_tcx : 1; - unsigned set6_pcd : 1; - unsigned set6_ws_tcz : 1; - unsigned set6_ws_tcy : 1; - unsigned set6_ws_tcx : 1; - unsigned set7_pcd : 1; - unsigned set7_ws_tcz : 1; - unsigned set7_ws_tcy : 1; - unsigned set7_ws_tcx : 1; +struct s2_dword { + unsigned set0_texcoord_fmt:4; + unsigned set1_texcoord_fmt:4; + unsigned set2_texcoord_fmt:4; + unsigned set3_texcoord_fmt:4; + unsigned set4_texcoord_fmt:4; + unsigned set5_texcoord_fmt:4; + unsigned set6_texcoord_fmt:4; + unsigned set7_texcoord_fmt:4; +}; + +struct s3_dword { + unsigned set0_pcd:1; + unsigned set0_ws_tcz:1; + unsigned set0_ws_tcy:1; + unsigned set0_ws_tcx:1; + unsigned set1_pcd:1; + unsigned set1_ws_tcz:1; + unsigned set1_ws_tcy:1; + unsigned set1_ws_tcx:1; + unsigned set2_pcd:1; + unsigned set2_ws_tcz:1; + unsigned set2_ws_tcy:1; + unsigned set2_ws_tcx:1; + unsigned set3_pcd:1; + unsigned set3_ws_tcz:1; + unsigned set3_ws_tcy:1; + unsigned set3_ws_tcx:1; + unsigned set4_pcd:1; + unsigned set4_ws_tcz:1; + unsigned set4_ws_tcy:1; + unsigned set4_ws_tcx:1; + unsigned set5_pcd:1; + unsigned set5_ws_tcz:1; + unsigned set5_ws_tcy:1; + unsigned set5_ws_tcx:1; + unsigned set6_pcd:1; + unsigned set6_ws_tcz:1; + unsigned set6_ws_tcy:1; + unsigned set6_ws_tcx:1; + unsigned set7_pcd:1; + unsigned set7_ws_tcz:1; + unsigned set7_ws_tcy:1; + unsigned set7_ws_tcx:1; }; #define VERTEXHAS_XYZ 1 @@ -876,103 +844,97 @@ struct s3_dword #define SHADEMODE_LINEAR 0 #define SHADEMODE_FLAT 1 -struct s4_dword -{ - unsigned anti_aliasing_enable : 1; - unsigned sprite_point_enable : 1; - unsigned fog_parameter_present : 1; - unsigned local_depth_offset_enable : 1; - unsigned force_specular_diffuse_color : 1; - unsigned force_default_diffuse_color : 1; - unsigned position_mask : 3; - unsigned local_depth_offset_present : 1; - unsigned diffuse_color_presetn : 1; - unsigned specular_color_fog_factor_present : 1; - unsigned point_width_present : 1; - unsigned cull_mode : 2; - unsigned color_shade_mode : 1; - unsigned specular_shade_mode : 1; - unsigned fog_shade_mode : 1; - unsigned alpha_shade_mode : 1; - unsigned line_width : 4; - unsigned point_width : 9; -}; - -struct s5_dword -{ - unsigned logic_op_enable : 1; - unsigned color_dither_enable : 1; - unsigned stencil_test_enable : 1; - unsigned stencil_buffer_write_enable : 1; - unsigned stencil_pass_depth_pass_op : 3; - unsigned stencil_pass_depth_fail_op : 3; - unsigned stencil_fail_op : 3; - unsigned stencil_test_function : 3; - unsigned stencil_reference_value : 8; - unsigned fog_enable : 1; - unsigned global_depth_offset_enable : 1; - unsigned last_pixel_enable : 1; - unsigned force_default_point_width : 1; - unsigned color_buffer_component_write_disable : 4; -}; - -struct s6_dword -{ - unsigned triangle_pv : 2; - unsigned color_buffer_write : 1; - unsigned depth_buffer_write : 1; - unsigned dest_blend_factor : 4; - unsigned src_blend_factor : 4; - unsigned color_blend_function : 3; - unsigned color_buffer_blend : 1; - unsigned depth_test_function : 3; - unsigned depth_test_enable : 1; - unsigned alpha_reference_value : 8; - unsigned alpha_test_function : 3; - unsigned alpha_test_enable : 1; - -}; - -struct s7_dword -{ - unsigned global_depth_offset_const; -}; - -struct i915_3dstate_load_state_immediate_1 -{ - struct { - unsigned length : 4; - unsigned load_s0 : 1; - unsigned load_s1 : 1; - unsigned load_s2 : 1; - unsigned load_s3 : 1; - unsigned load_s4 : 1; - unsigned load_s5 : 1; - unsigned load_s6 : 1; - unsigned load_s7 : 1; - unsigned pad0 : 4; - unsigned opcode : 13; - unsigned type : 3; - } dw0; -}; - -struct i915_3dstate_scissor_rectangle -{ - struct { - unsigned length : 16; - unsigned opcode : 13; - unsigned type : 3; - } dw0; - - struct { - unsigned min_x : 16; - unsigned min_y : 16; - } dw1; - - struct { - unsigned max_x : 16; - unsigned max_y : 16; - } dw2; +struct s4_dword { + unsigned anti_aliasing_enable:1; + unsigned sprite_point_enable:1; + unsigned fog_parameter_present:1; + unsigned local_depth_offset_enable:1; + unsigned force_specular_diffuse_color:1; + unsigned force_default_diffuse_color:1; + unsigned position_mask:3; + unsigned local_depth_offset_present:1; + unsigned diffuse_color_presetn:1; + unsigned specular_color_fog_factor_present:1; + unsigned point_width_present:1; + unsigned cull_mode:2; + unsigned color_shade_mode:1; + unsigned specular_shade_mode:1; + unsigned fog_shade_mode:1; + unsigned alpha_shade_mode:1; + unsigned line_width:4; + unsigned point_width:9; +}; + +struct s5_dword { + unsigned logic_op_enable:1; + unsigned color_dither_enable:1; + unsigned stencil_test_enable:1; + unsigned stencil_buffer_write_enable:1; + unsigned stencil_pass_depth_pass_op:3; + unsigned stencil_pass_depth_fail_op:3; + unsigned stencil_fail_op:3; + unsigned stencil_test_function:3; + unsigned stencil_reference_value:8; + unsigned fog_enable:1; + unsigned global_depth_offset_enable:1; + unsigned last_pixel_enable:1; + unsigned force_default_point_width:1; + unsigned color_buffer_component_write_disable:4; +}; + +struct s6_dword { + unsigned triangle_pv:2; + unsigned color_buffer_write:1; + unsigned depth_buffer_write:1; + unsigned dest_blend_factor:4; + unsigned src_blend_factor:4; + unsigned color_blend_function:3; + unsigned color_buffer_blend:1; + unsigned depth_test_function:3; + unsigned depth_test_enable:1; + unsigned alpha_reference_value:8; + unsigned alpha_test_function:3; + unsigned alpha_test_enable:1; + +}; + +struct s7_dword { + unsigned global_depth_offset_const; +}; + +struct i915_3dstate_load_state_immediate_1 { + struct { + unsigned length:4; + unsigned load_s0:1; + unsigned load_s1:1; + unsigned load_s2:1; + unsigned load_s3:1; + unsigned load_s4:1; + unsigned load_s5:1; + unsigned load_s6:1; + unsigned load_s7:1; + unsigned pad0:4; + unsigned opcode:13; + unsigned type:3; + } dw0; +}; + +struct i915_3dstate_scissor_rectangle { + struct { + unsigned length:16; + unsigned opcode:13; + unsigned type:3; + } dw0; + + struct { + unsigned min_x:16; + unsigned min_y:16; + } dw1; + + struct { + unsigned max_x:16; + unsigned max_y:16; + } dw2; }; #define VERTEX_INLINE 0x00 @@ -991,40 +953,37 @@ struct i915_3dstate_scissor_rectangle #define PRIM_CLEAR_RECT 0x0a #define PRIM_ZONE_INIT 0x0d -struct texture_coordinate_set -{ - unsigned tcx; - unsigned tcy; -}; - -struct vertex_data -{ - unsigned x; - unsigned y; - struct texture_coordinate_set tc0; - struct texture_coordinate_set tc1; -}; - -struct i915_3dprimitive -{ - union { - struct { - unsigned length : 18; - unsigned prim : 5; - unsigned vertex_location : 1; - unsigned opcode : 5; - unsigned type : 3; - } inline_prim; - - struct { - unsigned vertex_count : 16; - unsigned pad0 : 1; - unsigned vertex_access_mode : 1; - unsigned prim : 5; - unsigned vertex_location : 1; - unsigned opcode : 5; - unsigned type : 3; - } indirect_prim; - } dw0; +struct texture_coordinate_set { + unsigned tcx; + unsigned tcy; +}; + +struct vertex_data { + unsigned x; + unsigned y; + struct texture_coordinate_set tc0; + struct texture_coordinate_set tc1; +}; + +struct i915_3dprimitive { + union { + struct { + unsigned length:18; + unsigned prim:5; + unsigned vertex_location:1; + unsigned opcode:5; + unsigned type:3; + } inline_prim; + + struct { + unsigned vertex_count:16; + unsigned pad0:1; + unsigned vertex_access_mode:1; + unsigned prim:5; + unsigned vertex_location:1; + unsigned opcode:5; + unsigned type:3; + } indirect_prim; + } dw0; }; #endif /*_I915_STRUCTS_H */ diff --git a/src/xvmc/i915_xvmc.c b/src/xvmc/i915_xvmc.c index d6f7f01d..84bdaf26 100644 --- a/src/xvmc/i915_xvmc.c +++ b/src/xvmc/i915_xvmc.c @@ -39,94 +39,93 @@ SIZE_Y420(surface->width, surface->height)) typedef union { - int16_t component[2]; - int32_t v; + int16_t component[2]; + int32_t v; } vector_t; #if 0 static int findOverlap(unsigned int width, unsigned int height, - short *dstX, short *dstY, - short *srcX, short *srcY, - unsigned short *areaW, unsigned short *areaH) + short *dstX, short *dstY, + short *srcX, short *srcY, + unsigned short *areaW, unsigned short *areaH) { - int w, h; - unsigned int mWidth, mHeight; - - w = *areaW; - h = *areaH; - - if ((*dstX >= width) || (*dstY >= height)) - return 1; - - if (*dstX < 0) { - w += *dstX; - *srcX -= *dstX; - *dstX = 0; - } - - if (*dstY < 0) { - h += *dstY; - *srcY -= *dstY; - *dstY = 0; - } - - if ((w <= 0) || ((h <= 0))) - return 1; - - mWidth = width - *dstX; - mHeight = height - *dstY; - *areaW = (w <= mWidth) ? w : mWidth; - *areaH = (h <= mHeight) ? h : mHeight; - return 0; + int w, h; + unsigned int mWidth, mHeight; + + w = *areaW; + h = *areaH; + + if ((*dstX >= width) || (*dstY >= height)) + return 1; + + if (*dstX < 0) { + w += *dstX; + *srcX -= *dstX; + *dstX = 0; + } + + if (*dstY < 0) { + h += *dstY; + *srcY -= *dstY; + *dstY = 0; + } + + if ((w <= 0) || ((h <= 0))) + return 1; + + mWidth = width - *dstX; + mHeight = height - *dstY; + *areaW = (w <= mWidth) ? w : mWidth; + *areaH = (h <= mHeight) ? h : mHeight; + return 0; } #endif static void i915_inst_arith(unsigned int *inst, - unsigned int op, - unsigned int dest, - unsigned int mask, - unsigned int saturate, - unsigned int src0, unsigned int src1, unsigned int src2) + unsigned int op, + unsigned int dest, + unsigned int mask, + unsigned int saturate, + unsigned int src0, unsigned int src1, + unsigned int src2) { - dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); - *inst = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0)); - inst++; - *inst = (A1_SRC0(src0) | A1_SRC1(src1)); - inst++; - *inst = (A2_SRC1(src1) | A2_SRC2(src2)); + dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); + *inst = (op | A0_DEST(dest) | mask | saturate | A0_SRC0(src0)); + inst++; + *inst = (A1_SRC0(src0) | A1_SRC1(src1)); + inst++; + *inst = (A2_SRC1(src1) | A2_SRC2(src2)); } static void i915_inst_decl(unsigned int *inst, - unsigned int type, - unsigned int nr, - unsigned int d0_flags) + unsigned int type, + unsigned int nr, unsigned int d0_flags) { - unsigned int reg = UREG(type, nr); + unsigned int reg = UREG(type, nr); - *inst = (D0_DCL | D0_DEST(reg) | d0_flags); - inst++; - *inst = D1_MBZ; - inst++; - *inst = D2_MBZ; + *inst = (D0_DCL | D0_DEST(reg) | d0_flags); + inst++; + *inst = D1_MBZ; + inst++; + *inst = D2_MBZ; } static void i915_inst_texld(unsigned int *inst, - unsigned int op, - unsigned int dest, - unsigned int coord, - unsigned int sampler) + unsigned int op, + unsigned int dest, + unsigned int coord, unsigned int sampler) { - dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); - *inst = (op | T0_DEST(dest) | T0_SAMPLER(sampler)); - inst++; - *inst = T1_ADDRESS_REG(coord); - inst++; - *inst = T2_MBZ; + dest = UREG(GET_UREG_TYPE(dest), GET_UREG_NR(dest)); + *inst = (op | T0_DEST(dest) | T0_SAMPLER(sampler)); + inst++; + *inst = T1_ADDRESS_REG(coord); + inst++; + *inst = T2_MBZ; } static void i915_emit_batch(void *data, int size, int flag) { - intelBatchbufferData(data, size, flag); + intelBatchbufferData(data, size, flag); } /* one time context initialization buffer */ @@ -138,2331 +137,2418 @@ static int one_time_load_state_imm1_size, one_time_load_indirect_size; static uint32_t *mc_render_load_indirect; static int mc_render_load_indirect_size; -static void i915_mc_one_time_context_init(XvMCContext *context) +static void i915_mc_one_time_context_init(XvMCContext * context) { - unsigned int dest, src0, src1, src2; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - int i; - struct i915_3dstate_sampler_state *sampler_state; - struct i915_3dstate_pixel_shader_program *pixel_shader_program; - struct i915_3dstate_pixel_shader_constants *pixel_shader_constants; - - /* sampler static state */ - sampler_state = (struct i915_3dstate_sampler_state *)pI915XvMC->ssb.map; - /* pixel shader static state */ - pixel_shader_program = (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map; - /* pixel shader contant static state */ - pixel_shader_constants = (struct i915_3dstate_pixel_shader_constants *)pI915XvMC->psc.map; - - memset(sampler_state, 0, sizeof(*sampler_state)); - sampler_state->dw0.type = CMD_3D; - sampler_state->dw0.opcode = OPC_3DSTATE_SAMPLER_STATE; - sampler_state->dw0.length = 6; - sampler_state->dw1.sampler_masker = SAMPLER_SAMPLER0 | SAMPLER_SAMPLER1; - - sampler_state->sampler0.ts0.reverse_gamma = 0; - sampler_state->sampler0.ts0.planar2packet = 0; - sampler_state->sampler0.ts0.color_conversion = 0; - sampler_state->sampler0.ts0.chromakey_index = 0; - sampler_state->sampler0.ts0.base_level = 0; - sampler_state->sampler0.ts0.mip_filter = MIPFILTER_NONE; /* NONE */ - sampler_state->sampler0.ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ - sampler_state->sampler0.ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ - sampler_state->sampler0.ts0.lod_bias = 0; /* 0.0 */ - sampler_state->sampler0.ts0.shadow_enable = 0; - sampler_state->sampler0.ts0.max_anisotropy = ANISORATIO_2; - sampler_state->sampler0.ts0.shadow_function = PREFILTEROP_ALWAYS; - sampler_state->sampler0.ts1.min_lod = 0; /* 0.0 Maximum Mip Level */ - sampler_state->sampler0.ts1.kill_pixel = 0; - sampler_state->sampler0.ts1.keyed_texture_filter = 0; - sampler_state->sampler0.ts1.chromakey_enable = 0; - sampler_state->sampler0.ts1.tcx_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler0.ts1.tcy_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler0.ts1.tcz_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler0.ts1.normalized_coor = 0; - sampler_state->sampler0.ts1.map_index = 0; - sampler_state->sampler0.ts1.east_deinterlacer = 0; - sampler_state->sampler0.ts2.default_color = 0; - - sampler_state->sampler1.ts0.reverse_gamma = 0; - sampler_state->sampler1.ts0.planar2packet = 0; - sampler_state->sampler1.ts0.color_conversion = 0; - sampler_state->sampler1.ts0.chromakey_index = 0; - sampler_state->sampler1.ts0.base_level = 0; - sampler_state->sampler1.ts0.mip_filter = MIPFILTER_NONE; /* NONE */ - sampler_state->sampler1.ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ - sampler_state->sampler1.ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ - sampler_state->sampler1.ts0.lod_bias = 0; /* 0.0 */ - sampler_state->sampler1.ts0.shadow_enable = 0; - sampler_state->sampler1.ts0.max_anisotropy = ANISORATIO_2; - sampler_state->sampler1.ts0.shadow_function = PREFILTEROP_ALWAYS; - sampler_state->sampler1.ts1.min_lod = 0; /* 0.0 Maximum Mip Level */ - sampler_state->sampler1.ts1.kill_pixel = 0; - sampler_state->sampler1.ts1.keyed_texture_filter = 0; - sampler_state->sampler1.ts1.chromakey_enable = 0; - sampler_state->sampler1.ts1.tcx_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler1.ts1.tcy_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler1.ts1.tcz_control = TEXCOORDMODE_CLAMP; - sampler_state->sampler1.ts1.normalized_coor = 0; - sampler_state->sampler1.ts1.map_index = 1; - sampler_state->sampler1.ts1.east_deinterlacer = 0; - sampler_state->sampler1.ts2.default_color = 0; - - memset(pixel_shader_program, 0, sizeof(*pixel_shader_program)); - pixel_shader_program->shader0.type = CMD_3D; - pixel_shader_program->shader0.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; - pixel_shader_program->shader0.retain = 1; - pixel_shader_program->shader0.length = 2; /* 1 inst */ - i = 0; - - dest = UREG(REG_TYPE_OC, 0); - src0 = UREG(REG_TYPE_CONST, 0); - src1 = 0; - src2 = 0; - i915_inst_arith(&pixel_shader_program->inst0[i], A0_MOV, - dest, A0_DEST_CHANNEL_ALL, A0_DEST_SATURATE, src0, src1, src2); - - pixel_shader_program->shader1.type = CMD_3D; - pixel_shader_program->shader1.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; - pixel_shader_program->shader1.retain = 1; - pixel_shader_program->shader1.length = 14; /* 5 inst */ - i = 0; - /* dcl t0.xy */ - i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_T, T_TEX0, D0_CHANNEL_XY); - i+=3; - /* dcl t1.xy */ - i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_T, T_TEX1, D0_CHANNEL_XY); - /* dcl_2D s0 */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_S, 0, D0_SAMPLE_TYPE_2D); - /* texld r0, t0, s0 */ - i += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_T, 0); /* COORD */ - src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ - i915_inst_texld(&pixel_shader_program->inst1[i], T0_TEXLD, dest, src0, src1); - /* mov oC, r0 */ - i += 3; - dest = UREG(REG_TYPE_OC, 0); - src0 = UREG(REG_TYPE_R, 0); - src1 = src2 = 0; - i915_inst_arith(&pixel_shader_program->inst1[i], A0_MOV, dest, A0_DEST_CHANNEL_ALL, - A0_DEST_SATURATE, src0, src1, src2); - - - pixel_shader_program->shader2.type = CMD_3D; - pixel_shader_program->shader2.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; - pixel_shader_program->shader2.retain = 1; - pixel_shader_program->shader2.length = 14; /* 5 inst */ - i = 0; - /* dcl t2.xy */ - i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_T, T_TEX2, D0_CHANNEL_XY); - /* dcl t3.xy */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_T, T_TEX3, D0_CHANNEL_XY); - /* dcl_2D s1 */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_S, 1, D0_SAMPLE_TYPE_2D); - /* texld r0, t2, s1 */ - i += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_T, 2); /* COORD */ - src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ - i915_inst_texld(&pixel_shader_program->inst2[i], T0_TEXLD, dest, src0, src1); - /* mov oC, r0 */ - i += 3; - dest = UREG(REG_TYPE_OC, 0); - src0 = UREG(REG_TYPE_R, 0); - src1 = src2 = 0; - i915_inst_arith(&pixel_shader_program->inst2[i], A0_MOV, dest, A0_DEST_CHANNEL_ALL, - A0_DEST_SATURATE, src0, src1, src2); - - /* Shader 3 */ - pixel_shader_program->shader3.type = CMD_3D; - pixel_shader_program->shader3.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; - pixel_shader_program->shader3.retain = 1; - pixel_shader_program->shader3.length = 29; /* 10 inst */ - i = 0; - /* dcl t0.xy */ - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX0, D0_CHANNEL_XY); - /* dcl t1.xy */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX1, D0_CHANNEL_XY); - /* dcl t2.xy */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX2, D0_CHANNEL_XY); - /* dcl t3.xy */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX3, D0_CHANNEL_XY); - /* dcl_2D s0 */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_S, 0, D0_SAMPLE_TYPE_2D); - /* dcl_2D s1 */ - i += 3; - i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_S, 1, D0_SAMPLE_TYPE_2D); - /* texld r0, t0, s0 */ - i += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_T, 0); /* COORD */ - src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ - i915_inst_texld(&pixel_shader_program->inst3[i], T0_TEXLD, dest, src0, src1); - /* texld r1, t2, s1 */ - i += 3; - dest = UREG(REG_TYPE_R, 1); - src0 = UREG(REG_TYPE_T, 2); /* COORD */ - src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ - i915_inst_texld(&pixel_shader_program->inst3[i], T0_TEXLD, dest, src0, src1); - /* add r0, r0, r1 */ - i += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_R, 0); - src1 = UREG(REG_TYPE_R, 1); - src2 = 0; - i915_inst_arith(&pixel_shader_program->inst3[i], A0_ADD, dest, A0_DEST_CHANNEL_ALL, - 0 /* A0_DEST_SATURATE */, src0, src1, src2); - /* mul oC, r0, c0 */ - i += 3; - dest = UREG(REG_TYPE_OC, 0); - src0 = UREG(REG_TYPE_R, 0); - src1 = UREG(REG_TYPE_CONST, 0); - src2 = 0; - i915_inst_arith(&pixel_shader_program->inst3[i], A0_MUL, dest, A0_DEST_CHANNEL_ALL, - A0_DEST_SATURATE, src0, src1, src2); - - memset(pixel_shader_constants, 0, sizeof(*pixel_shader_constants)); - pixel_shader_constants->dw0.type = CMD_3D; - pixel_shader_constants->dw0.opcode = OPC_3DSTATE_PIXEL_SHADER_CONSTANTS; - pixel_shader_constants->dw0.length = 4; - pixel_shader_constants->dw1.reg_mask = REG_CR0; - pixel_shader_constants->value.x = 0.5; - pixel_shader_constants->value.y = 0.5; - pixel_shader_constants->value.z = 0.5; - pixel_shader_constants->value.w = 0.5; + unsigned int dest, src0, src1, src2; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + int i; + struct i915_3dstate_sampler_state *sampler_state; + struct i915_3dstate_pixel_shader_program *pixel_shader_program; + struct i915_3dstate_pixel_shader_constants *pixel_shader_constants; + + /* sampler static state */ + sampler_state = (struct i915_3dstate_sampler_state *)pI915XvMC->ssb.map; + /* pixel shader static state */ + pixel_shader_program = + (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map; + /* pixel shader contant static state */ + pixel_shader_constants = + (struct i915_3dstate_pixel_shader_constants *)pI915XvMC->psc.map; + + memset(sampler_state, 0, sizeof(*sampler_state)); + sampler_state->dw0.type = CMD_3D; + sampler_state->dw0.opcode = OPC_3DSTATE_SAMPLER_STATE; + sampler_state->dw0.length = 6; + sampler_state->dw1.sampler_masker = SAMPLER_SAMPLER0 | SAMPLER_SAMPLER1; + + sampler_state->sampler0.ts0.reverse_gamma = 0; + sampler_state->sampler0.ts0.planar2packet = 0; + sampler_state->sampler0.ts0.color_conversion = 0; + sampler_state->sampler0.ts0.chromakey_index = 0; + sampler_state->sampler0.ts0.base_level = 0; + sampler_state->sampler0.ts0.mip_filter = MIPFILTER_NONE; /* NONE */ + sampler_state->sampler0.ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ + sampler_state->sampler0.ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ + sampler_state->sampler0.ts0.lod_bias = 0; /* 0.0 */ + sampler_state->sampler0.ts0.shadow_enable = 0; + sampler_state->sampler0.ts0.max_anisotropy = ANISORATIO_2; + sampler_state->sampler0.ts0.shadow_function = PREFILTEROP_ALWAYS; + sampler_state->sampler0.ts1.min_lod = 0; /* 0.0 Maximum Mip Level */ + sampler_state->sampler0.ts1.kill_pixel = 0; + sampler_state->sampler0.ts1.keyed_texture_filter = 0; + sampler_state->sampler0.ts1.chromakey_enable = 0; + sampler_state->sampler0.ts1.tcx_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler0.ts1.tcy_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler0.ts1.tcz_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler0.ts1.normalized_coor = 0; + sampler_state->sampler0.ts1.map_index = 0; + sampler_state->sampler0.ts1.east_deinterlacer = 0; + sampler_state->sampler0.ts2.default_color = 0; + + sampler_state->sampler1.ts0.reverse_gamma = 0; + sampler_state->sampler1.ts0.planar2packet = 0; + sampler_state->sampler1.ts0.color_conversion = 0; + sampler_state->sampler1.ts0.chromakey_index = 0; + sampler_state->sampler1.ts0.base_level = 0; + sampler_state->sampler1.ts0.mip_filter = MIPFILTER_NONE; /* NONE */ + sampler_state->sampler1.ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ + sampler_state->sampler1.ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ + sampler_state->sampler1.ts0.lod_bias = 0; /* 0.0 */ + sampler_state->sampler1.ts0.shadow_enable = 0; + sampler_state->sampler1.ts0.max_anisotropy = ANISORATIO_2; + sampler_state->sampler1.ts0.shadow_function = PREFILTEROP_ALWAYS; + sampler_state->sampler1.ts1.min_lod = 0; /* 0.0 Maximum Mip Level */ + sampler_state->sampler1.ts1.kill_pixel = 0; + sampler_state->sampler1.ts1.keyed_texture_filter = 0; + sampler_state->sampler1.ts1.chromakey_enable = 0; + sampler_state->sampler1.ts1.tcx_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler1.ts1.tcy_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler1.ts1.tcz_control = TEXCOORDMODE_CLAMP; + sampler_state->sampler1.ts1.normalized_coor = 0; + sampler_state->sampler1.ts1.map_index = 1; + sampler_state->sampler1.ts1.east_deinterlacer = 0; + sampler_state->sampler1.ts2.default_color = 0; + + memset(pixel_shader_program, 0, sizeof(*pixel_shader_program)); + pixel_shader_program->shader0.type = CMD_3D; + pixel_shader_program->shader0.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; + pixel_shader_program->shader0.retain = 1; + pixel_shader_program->shader0.length = 2; /* 1 inst */ + i = 0; + + dest = UREG(REG_TYPE_OC, 0); + src0 = UREG(REG_TYPE_CONST, 0); + src1 = 0; + src2 = 0; + i915_inst_arith(&pixel_shader_program->inst0[i], A0_MOV, + dest, A0_DEST_CHANNEL_ALL, A0_DEST_SATURATE, src0, src1, + src2); + + pixel_shader_program->shader1.type = CMD_3D; + pixel_shader_program->shader1.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; + pixel_shader_program->shader1.retain = 1; + pixel_shader_program->shader1.length = 14; /* 5 inst */ + i = 0; + /* dcl t0.xy */ + i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_T, T_TEX0, + D0_CHANNEL_XY); + i += 3; + /* dcl t1.xy */ + i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_T, T_TEX1, + D0_CHANNEL_XY); + /* dcl_2D s0 */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst1[i], REG_TYPE_S, 0, + D0_SAMPLE_TYPE_2D); + /* texld r0, t0, s0 */ + i += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_T, 0); /* COORD */ + src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ + i915_inst_texld(&pixel_shader_program->inst1[i], T0_TEXLD, dest, src0, + src1); + /* mov oC, r0 */ + i += 3; + dest = UREG(REG_TYPE_OC, 0); + src0 = UREG(REG_TYPE_R, 0); + src1 = src2 = 0; + i915_inst_arith(&pixel_shader_program->inst1[i], A0_MOV, dest, + A0_DEST_CHANNEL_ALL, A0_DEST_SATURATE, src0, src1, + src2); + + pixel_shader_program->shader2.type = CMD_3D; + pixel_shader_program->shader2.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; + pixel_shader_program->shader2.retain = 1; + pixel_shader_program->shader2.length = 14; /* 5 inst */ + i = 0; + /* dcl t2.xy */ + i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_T, T_TEX2, + D0_CHANNEL_XY); + /* dcl t3.xy */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_T, T_TEX3, + D0_CHANNEL_XY); + /* dcl_2D s1 */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst2[i], REG_TYPE_S, 1, + D0_SAMPLE_TYPE_2D); + /* texld r0, t2, s1 */ + i += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_T, 2); /* COORD */ + src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ + i915_inst_texld(&pixel_shader_program->inst2[i], T0_TEXLD, dest, src0, + src1); + /* mov oC, r0 */ + i += 3; + dest = UREG(REG_TYPE_OC, 0); + src0 = UREG(REG_TYPE_R, 0); + src1 = src2 = 0; + i915_inst_arith(&pixel_shader_program->inst2[i], A0_MOV, dest, + A0_DEST_CHANNEL_ALL, A0_DEST_SATURATE, src0, src1, + src2); + + /* Shader 3 */ + pixel_shader_program->shader3.type = CMD_3D; + pixel_shader_program->shader3.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; + pixel_shader_program->shader3.retain = 1; + pixel_shader_program->shader3.length = 29; /* 10 inst */ + i = 0; + /* dcl t0.xy */ + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX0, + D0_CHANNEL_XY); + /* dcl t1.xy */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX1, + D0_CHANNEL_XY); + /* dcl t2.xy */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX2, + D0_CHANNEL_XY); + /* dcl t3.xy */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_T, T_TEX3, + D0_CHANNEL_XY); + /* dcl_2D s0 */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_S, 0, + D0_SAMPLE_TYPE_2D); + /* dcl_2D s1 */ + i += 3; + i915_inst_decl(&pixel_shader_program->inst3[i], REG_TYPE_S, 1, + D0_SAMPLE_TYPE_2D); + /* texld r0, t0, s0 */ + i += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_T, 0); /* COORD */ + src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ + i915_inst_texld(&pixel_shader_program->inst3[i], T0_TEXLD, dest, src0, + src1); + /* texld r1, t2, s1 */ + i += 3; + dest = UREG(REG_TYPE_R, 1); + src0 = UREG(REG_TYPE_T, 2); /* COORD */ + src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ + i915_inst_texld(&pixel_shader_program->inst3[i], T0_TEXLD, dest, src0, + src1); + /* add r0, r0, r1 */ + i += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_R, 0); + src1 = UREG(REG_TYPE_R, 1); + src2 = 0; + i915_inst_arith(&pixel_shader_program->inst3[i], A0_ADD, dest, + A0_DEST_CHANNEL_ALL, 0 /* A0_DEST_SATURATE */ , src0, + src1, src2); + /* mul oC, r0, c0 */ + i += 3; + dest = UREG(REG_TYPE_OC, 0); + src0 = UREG(REG_TYPE_R, 0); + src1 = UREG(REG_TYPE_CONST, 0); + src2 = 0; + i915_inst_arith(&pixel_shader_program->inst3[i], A0_MUL, dest, + A0_DEST_CHANNEL_ALL, A0_DEST_SATURATE, src0, src1, + src2); + + memset(pixel_shader_constants, 0, sizeof(*pixel_shader_constants)); + pixel_shader_constants->dw0.type = CMD_3D; + pixel_shader_constants->dw0.opcode = OPC_3DSTATE_PIXEL_SHADER_CONSTANTS; + pixel_shader_constants->dw0.length = 4; + pixel_shader_constants->dw1.reg_mask = REG_CR0; + pixel_shader_constants->value.x = 0.5; + pixel_shader_constants->value.y = 0.5; + pixel_shader_constants->value.z = 0.5; + pixel_shader_constants->value.w = 0.5; } -static void i915_mc_one_time_state_init(XvMCContext *context) +static void i915_mc_one_time_state_init(XvMCContext * context) { - struct s3_dword *s3 = NULL; - struct s6_dword *s6 = NULL; - dis_state *dis = NULL; - ssb_state *ssb = NULL; - psp_state *psp = NULL; - psc_state *psc = NULL; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - struct i915_3dstate_load_state_immediate_1 *load_state_immediate_1; - struct i915_3dstate_load_indirect *load_indirect; - int mem_select; - - /* 3DSTATE_LOAD_STATE_IMMEDIATE_1 */ - one_time_load_state_imm1_size = sizeof(*load_state_immediate_1) + sizeof(*s3) + sizeof(*s6); - one_time_load_state_imm1 = calloc(1, one_time_load_state_imm1_size); - load_state_immediate_1 = (struct i915_3dstate_load_state_immediate_1 *)one_time_load_state_imm1; - load_state_immediate_1->dw0.type = CMD_3D; - load_state_immediate_1->dw0.opcode = OPC_3DSTATE_LOAD_STATE_IMMEDIATE_1; - load_state_immediate_1->dw0.load_s3 = 1; - load_state_immediate_1->dw0.load_s6 = 1; - load_state_immediate_1->dw0.length = (one_time_load_state_imm1_size >> 2) - 2; - - s3 = (struct s3_dword *)(++load_state_immediate_1); - s3->set0_pcd = 1; - s3->set1_pcd = 1; - s3->set2_pcd = 1; - s3->set3_pcd = 1; - s3->set4_pcd = 1; - s3->set5_pcd = 1; - s3->set6_pcd = 1; - s3->set7_pcd = 1; - - s6 = (struct s6_dword *)(++s3); - s6->alpha_test_enable = 0; - s6->alpha_test_function = 0; - s6->alpha_reference_value = 0; - s6->depth_test_enable = 1; - s6->depth_test_function = 0; - s6->color_buffer_blend = 0; - s6->color_blend_function = 0; - s6->src_blend_factor = 1; - s6->dest_blend_factor = 1; - s6->depth_buffer_write = 0; - s6->color_buffer_write = 1; - s6->triangle_pv = 0; - - /* 3DSTATE_LOAD_INDIRECT */ - one_time_load_indirect_size = sizeof(*load_indirect) + sizeof(*dis) + sizeof(*ssb) + sizeof(*psp) + sizeof(*psc); - one_time_load_indirect = calloc(1, one_time_load_indirect_size); - load_indirect = (struct i915_3dstate_load_indirect *)one_time_load_indirect; - load_indirect->dw0.type = CMD_3D; - load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; - load_indirect->dw0.block_mask = BLOCK_DIS | BLOCK_SSB | BLOCK_PSP | BLOCK_PSC; - load_indirect->dw0.length = (one_time_load_indirect_size >> 2) - 2; - - if (pI915XvMC->deviceID == PCI_CHIP_I915_G || - pI915XvMC->deviceID == PCI_CHIP_I915_GM) - mem_select = 0; /* use physical address */ - else - mem_select = 1; /* use gfx address */ - - load_indirect->dw0.mem_select = mem_select; - - - /* Dynamic indirect state buffer */ - dis = (dis_state *)(++load_indirect); - dis->dw0.valid = 0; - dis->dw0.reset = 0; - dis->dw0.buffer_address = 0; - - /* Sample state buffer */ - ssb = (ssb_state *)(++dis); - ssb->dw0.valid = 1; - ssb->dw0.force = 1; - ssb->dw1.length = 7; /* 8 - 1 */ - - if (mem_select) - ssb->dw0.buffer_address = (pI915XvMC->ssb.offset >> 2); - else - ssb->dw0.buffer_address = (pI915XvMC->ssb.bus_addr >> 2); - - /* Pixel shader program buffer */ - psp = (psp_state *)(++ssb); - psp->dw0.valid = 1; - psp->dw0.force = 1; - psp->dw1.length = 66; /* 4 + 16 + 16 + 31 - 1 */ - - if (mem_select) - psp->dw0.buffer_address = (pI915XvMC->psp.offset >> 2); - else - psp->dw0.buffer_address = (pI915XvMC->psp.bus_addr >> 2); - - /* Pixel shader constant buffer */ - psc = (psc_state *)(++psp); - psc->dw0.valid = 1; - psc->dw0.force = 1; - psc->dw1.length = 5; /* 6 - 1 */ - - if (mem_select) - psc->dw0.buffer_address = (pI915XvMC->psc.offset >> 2); - else - psc->dw0.buffer_address = (pI915XvMC->psc.bus_addr >> 2); + struct s3_dword *s3 = NULL; + struct s6_dword *s6 = NULL; + dis_state *dis = NULL; + ssb_state *ssb = NULL; + psp_state *psp = NULL; + psc_state *psc = NULL; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + struct i915_3dstate_load_state_immediate_1 *load_state_immediate_1; + struct i915_3dstate_load_indirect *load_indirect; + int mem_select; + + /* 3DSTATE_LOAD_STATE_IMMEDIATE_1 */ + one_time_load_state_imm1_size = + sizeof(*load_state_immediate_1) + sizeof(*s3) + sizeof(*s6); + one_time_load_state_imm1 = calloc(1, one_time_load_state_imm1_size); + load_state_immediate_1 = (struct i915_3dstate_load_state_immediate_1 *) + one_time_load_state_imm1; + load_state_immediate_1->dw0.type = CMD_3D; + load_state_immediate_1->dw0.opcode = OPC_3DSTATE_LOAD_STATE_IMMEDIATE_1; + load_state_immediate_1->dw0.load_s3 = 1; + load_state_immediate_1->dw0.load_s6 = 1; + load_state_immediate_1->dw0.length = + (one_time_load_state_imm1_size >> 2) - 2; + + s3 = (struct s3_dword *)(++load_state_immediate_1); + s3->set0_pcd = 1; + s3->set1_pcd = 1; + s3->set2_pcd = 1; + s3->set3_pcd = 1; + s3->set4_pcd = 1; + s3->set5_pcd = 1; + s3->set6_pcd = 1; + s3->set7_pcd = 1; + + s6 = (struct s6_dword *)(++s3); + s6->alpha_test_enable = 0; + s6->alpha_test_function = 0; + s6->alpha_reference_value = 0; + s6->depth_test_enable = 1; + s6->depth_test_function = 0; + s6->color_buffer_blend = 0; + s6->color_blend_function = 0; + s6->src_blend_factor = 1; + s6->dest_blend_factor = 1; + s6->depth_buffer_write = 0; + s6->color_buffer_write = 1; + s6->triangle_pv = 0; + + /* 3DSTATE_LOAD_INDIRECT */ + one_time_load_indirect_size = + sizeof(*load_indirect) + sizeof(*dis) + sizeof(*ssb) + + sizeof(*psp) + sizeof(*psc); + one_time_load_indirect = calloc(1, one_time_load_indirect_size); + load_indirect = + (struct i915_3dstate_load_indirect *)one_time_load_indirect; + load_indirect->dw0.type = CMD_3D; + load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; + load_indirect->dw0.block_mask = + BLOCK_DIS | BLOCK_SSB | BLOCK_PSP | BLOCK_PSC; + load_indirect->dw0.length = (one_time_load_indirect_size >> 2) - 2; + + if (pI915XvMC->deviceID == PCI_CHIP_I915_G || + pI915XvMC->deviceID == PCI_CHIP_I915_GM) + mem_select = 0; /* use physical address */ + else + mem_select = 1; /* use gfx address */ + + load_indirect->dw0.mem_select = mem_select; + + /* Dynamic indirect state buffer */ + dis = (dis_state *) (++load_indirect); + dis->dw0.valid = 0; + dis->dw0.reset = 0; + dis->dw0.buffer_address = 0; + + /* Sample state buffer */ + ssb = (ssb_state *) (++dis); + ssb->dw0.valid = 1; + ssb->dw0.force = 1; + ssb->dw1.length = 7; /* 8 - 1 */ + + if (mem_select) + ssb->dw0.buffer_address = (pI915XvMC->ssb.offset >> 2); + else + ssb->dw0.buffer_address = (pI915XvMC->ssb.bus_addr >> 2); + + /* Pixel shader program buffer */ + psp = (psp_state *) (++ssb); + psp->dw0.valid = 1; + psp->dw0.force = 1; + psp->dw1.length = 66; /* 4 + 16 + 16 + 31 - 1 */ + + if (mem_select) + psp->dw0.buffer_address = (pI915XvMC->psp.offset >> 2); + else + psp->dw0.buffer_address = (pI915XvMC->psp.bus_addr >> 2); + + /* Pixel shader constant buffer */ + psc = (psc_state *) (++psp); + psc->dw0.valid = 1; + psc->dw0.force = 1; + psc->dw1.length = 5; /* 6 - 1 */ + + if (mem_select) + psc->dw0.buffer_address = (pI915XvMC->psc.offset >> 2); + else + psc->dw0.buffer_address = (pI915XvMC->psc.bus_addr >> 2); } static void i915_mc_one_time_state_emit(void) { - i915_emit_batch(one_time_load_state_imm1, one_time_load_state_imm1_size, 0); - i915_emit_batch(one_time_load_indirect, one_time_load_indirect_size, 0); + i915_emit_batch(one_time_load_state_imm1, one_time_load_state_imm1_size, + 0); + i915_emit_batch(one_time_load_indirect, one_time_load_indirect_size, 0); } -static void i915_mc_static_indirect_state_init(XvMCContext *context) +static void i915_mc_static_indirect_state_init(XvMCContext * context) { - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - struct i915_mc_static_indirect_state_buffer *buffer_info = - (struct i915_mc_static_indirect_state_buffer *)pI915XvMC->sis.map; - - memset(buffer_info, 0, sizeof(*buffer_info)); - /* dest Y */ - buffer_info->dest_y.dw0.type = CMD_3D; - buffer_info->dest_y.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; - buffer_info->dest_y.dw0.length = 1; - buffer_info->dest_y.dw1.aux_id = 0; - buffer_info->dest_y.dw1.buffer_id = BUFFERID_COLOR_BACK; - buffer_info->dest_y.dw1.fence_regs = 0; /* disabled */ /* FIXME: tiled y for performance */ - buffer_info->dest_y.dw1.tiled_surface = 0; /* linear */ - buffer_info->dest_y.dw1.walk = TILEWALK_XMAJOR; - - /* dest U */ - buffer_info->dest_u.dw0.type = CMD_3D; - buffer_info->dest_u.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; - buffer_info->dest_u.dw0.length = 1; - buffer_info->dest_u.dw1.aux_id = 0; - buffer_info->dest_u.dw1.buffer_id = BUFFERID_COLOR_AUX; - buffer_info->dest_u.dw1.fence_regs = 0; - buffer_info->dest_u.dw1.tiled_surface = 0; - buffer_info->dest_u.dw1.walk = TILEWALK_XMAJOR; - - /* dest V */ - buffer_info->dest_v.dw0.type = CMD_3D; - buffer_info->dest_v.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; - buffer_info->dest_v.dw0.length = 1; - buffer_info->dest_v.dw1.aux_id = 1; - buffer_info->dest_v.dw1.buffer_id = BUFFERID_COLOR_AUX; - buffer_info->dest_v.dw1.fence_regs = 0; - buffer_info->dest_v.dw1.tiled_surface = 0; - buffer_info->dest_v.dw1.walk = TILEWALK_XMAJOR; - - buffer_info->dest_buf.dw0.type = CMD_3D; - buffer_info->dest_buf.dw0.opcode = OPC_3DSTATE_DEST_BUFFER_VARIABLES; - buffer_info->dest_buf.dw0.length = 0; - buffer_info->dest_buf.dw1.dest_v_bias = 8; /* 0.5 */ - buffer_info->dest_buf.dw1.dest_h_bias = 8; /* 0.5 */ - buffer_info->dest_buf.dw1.color_fmt = COLORBUFFER_8BIT; - buffer_info->dest_buf.dw1.v_ls = 0; /* fill later */ - buffer_info->dest_buf.dw1.v_ls_offset = 0; /* fill later */ - - buffer_info->dest_buf_mpeg.dw0.type = CMD_3D; - buffer_info->dest_buf_mpeg.dw0.opcode = OPC_3DSTATE_DEST_BUFFER_VARIABLES_MPEG; - buffer_info->dest_buf_mpeg.dw0.length = 1; - buffer_info->dest_buf_mpeg.dw1.decode_mode = MPEG_DECODE_MC; - buffer_info->dest_buf_mpeg.dw1.rcontrol = 0; /* for MPEG-1/MPEG-2 */ - buffer_info->dest_buf_mpeg.dw1.bidir_avrg_control = 0; /* for MPEG-1/MPEG-2/MPEG-4 */ - buffer_info->dest_buf_mpeg.dw1.abort_on_error = 1; - buffer_info->dest_buf_mpeg.dw1.intra8 = 0; /* 16-bit formatted correction data */ - buffer_info->dest_buf_mpeg.dw1.tff = 1; /* fill later */ - - buffer_info->dest_buf_mpeg.dw1.v_subsample_factor = MC_SUB_1V; - buffer_info->dest_buf_mpeg.dw1.h_subsample_factor = MC_SUB_1H; - - buffer_info->corr.dw0.type = CMD_3D; - buffer_info->corr.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; - buffer_info->corr.dw0.length = 1; - buffer_info->corr.dw1.aux_id = 0; - buffer_info->corr.dw1.buffer_id = BUFFERID_MC_INTRA_CORR; - buffer_info->corr.dw1.aux_id = 0; - buffer_info->corr.dw1.fence_regs = 0; - buffer_info->corr.dw1.tiled_surface = 0; - buffer_info->corr.dw1.walk = 0; - buffer_info->corr.dw1.pitch = 0; - buffer_info->corr.dw2.base_address = (pI915XvMC->corrdata.offset >> 2); /* starting DWORD address */ + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + struct i915_mc_static_indirect_state_buffer *buffer_info = + (struct i915_mc_static_indirect_state_buffer *)pI915XvMC->sis.map; + + memset(buffer_info, 0, sizeof(*buffer_info)); + /* dest Y */ + buffer_info->dest_y.dw0.type = CMD_3D; + buffer_info->dest_y.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; + buffer_info->dest_y.dw0.length = 1; + buffer_info->dest_y.dw1.aux_id = 0; + buffer_info->dest_y.dw1.buffer_id = BUFFERID_COLOR_BACK; + buffer_info->dest_y.dw1.fence_regs = 0; /* disabled *//* FIXME: tiled y for performance */ + buffer_info->dest_y.dw1.tiled_surface = 0; /* linear */ + buffer_info->dest_y.dw1.walk = TILEWALK_XMAJOR; + + /* dest U */ + buffer_info->dest_u.dw0.type = CMD_3D; + buffer_info->dest_u.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; + buffer_info->dest_u.dw0.length = 1; + buffer_info->dest_u.dw1.aux_id = 0; + buffer_info->dest_u.dw1.buffer_id = BUFFERID_COLOR_AUX; + buffer_info->dest_u.dw1.fence_regs = 0; + buffer_info->dest_u.dw1.tiled_surface = 0; + buffer_info->dest_u.dw1.walk = TILEWALK_XMAJOR; + + /* dest V */ + buffer_info->dest_v.dw0.type = CMD_3D; + buffer_info->dest_v.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; + buffer_info->dest_v.dw0.length = 1; + buffer_info->dest_v.dw1.aux_id = 1; + buffer_info->dest_v.dw1.buffer_id = BUFFERID_COLOR_AUX; + buffer_info->dest_v.dw1.fence_regs = 0; + buffer_info->dest_v.dw1.tiled_surface = 0; + buffer_info->dest_v.dw1.walk = TILEWALK_XMAJOR; + + buffer_info->dest_buf.dw0.type = CMD_3D; + buffer_info->dest_buf.dw0.opcode = OPC_3DSTATE_DEST_BUFFER_VARIABLES; + buffer_info->dest_buf.dw0.length = 0; + buffer_info->dest_buf.dw1.dest_v_bias = 8; /* 0.5 */ + buffer_info->dest_buf.dw1.dest_h_bias = 8; /* 0.5 */ + buffer_info->dest_buf.dw1.color_fmt = COLORBUFFER_8BIT; + buffer_info->dest_buf.dw1.v_ls = 0; /* fill later */ + buffer_info->dest_buf.dw1.v_ls_offset = 0; /* fill later */ + + buffer_info->dest_buf_mpeg.dw0.type = CMD_3D; + buffer_info->dest_buf_mpeg.dw0.opcode = + OPC_3DSTATE_DEST_BUFFER_VARIABLES_MPEG; + buffer_info->dest_buf_mpeg.dw0.length = 1; + buffer_info->dest_buf_mpeg.dw1.decode_mode = MPEG_DECODE_MC; + buffer_info->dest_buf_mpeg.dw1.rcontrol = 0; /* for MPEG-1/MPEG-2 */ + buffer_info->dest_buf_mpeg.dw1.bidir_avrg_control = 0; /* for MPEG-1/MPEG-2/MPEG-4 */ + buffer_info->dest_buf_mpeg.dw1.abort_on_error = 1; + buffer_info->dest_buf_mpeg.dw1.intra8 = 0; /* 16-bit formatted correction data */ + buffer_info->dest_buf_mpeg.dw1.tff = 1; /* fill later */ + + buffer_info->dest_buf_mpeg.dw1.v_subsample_factor = MC_SUB_1V; + buffer_info->dest_buf_mpeg.dw1.h_subsample_factor = MC_SUB_1H; + + buffer_info->corr.dw0.type = CMD_3D; + buffer_info->corr.dw0.opcode = OPC_3DSTATE_BUFFER_INFO; + buffer_info->corr.dw0.length = 1; + buffer_info->corr.dw1.aux_id = 0; + buffer_info->corr.dw1.buffer_id = BUFFERID_MC_INTRA_CORR; + buffer_info->corr.dw1.aux_id = 0; + buffer_info->corr.dw1.fence_regs = 0; + buffer_info->corr.dw1.tiled_surface = 0; + buffer_info->corr.dw1.walk = 0; + buffer_info->corr.dw1.pitch = 0; + buffer_info->corr.dw2.base_address = (pI915XvMC->corrdata.offset >> 2); /* starting DWORD address */ } -static void i915_mc_static_indirect_state_set(XvMCContext *context, XvMCSurface *dest, - unsigned int picture_structure, unsigned int flags, unsigned int picture_coding_type) +static void i915_mc_static_indirect_state_set(XvMCContext * context, + XvMCSurface * dest, + unsigned int picture_structure, + unsigned int flags, + unsigned int picture_coding_type) { - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - i915XvMCSurface *pI915Surface = (i915XvMCSurface *)dest->privData; - struct i915_mc_static_indirect_state_buffer *buffer_info = - (struct i915_mc_static_indirect_state_buffer *)pI915XvMC->sis.map; - unsigned int w = dest->width; - - buffer_info->dest_y.dw1.pitch = (pI915Surface->yStride >> 2); /* in DWords */ - buffer_info->dest_y.dw2.base_address = (YOFFSET(pI915Surface) >> 2); /* starting DWORD address */ - buffer_info->dest_u.dw1.pitch = (pI915Surface->uvStride >> 2); /* in DWords */ - buffer_info->dest_u.dw2.base_address = (UOFFSET(pI915Surface) >> 2); /* starting DWORD address */ - buffer_info->dest_v.dw1.pitch = (pI915Surface->uvStride >> 2); /* in Dwords */ - buffer_info->dest_v.dw2.base_address = (VOFFSET(pI915Surface) >> 2); /* starting DWORD address */ - - if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) { - ; - } else if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_TOP_FIELD) { - buffer_info->dest_buf.dw1.v_ls = 1; - } else if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_BOTTOM_FIELD) { - buffer_info->dest_buf.dw1.v_ls = 1; - buffer_info->dest_buf.dw1.v_ls_offset = 1; - } - - if (picture_structure & XVMC_FRAME_PICTURE) { - ; - } else if (picture_structure & XVMC_TOP_FIELD) { - if (flags & XVMC_SECOND_FIELD) - buffer_info->dest_buf_mpeg.dw1.tff = 0; - else - buffer_info->dest_buf_mpeg.dw1.tff = 1; - } else if (picture_structure & XVMC_BOTTOM_FIELD) { - if (flags & XVMC_SECOND_FIELD) - buffer_info->dest_buf_mpeg.dw1.tff = 1; - else - buffer_info->dest_buf_mpeg.dw1.tff = 0; - } - - buffer_info->dest_buf_mpeg.dw1.picture_width = (dest->width >> 4); /* in macroblocks */ - buffer_info->dest_buf_mpeg.dw2.picture_coding_type = picture_coding_type; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + i915XvMCSurface *pI915Surface = (i915XvMCSurface *) dest->privData; + struct i915_mc_static_indirect_state_buffer *buffer_info = + (struct i915_mc_static_indirect_state_buffer *)pI915XvMC->sis.map; + unsigned int w = dest->width; + + buffer_info->dest_y.dw1.pitch = (pI915Surface->yStride >> 2); /* in DWords */ + buffer_info->dest_y.dw2.base_address = (YOFFSET(pI915Surface) >> 2); /* starting DWORD address */ + buffer_info->dest_u.dw1.pitch = (pI915Surface->uvStride >> 2); /* in DWords */ + buffer_info->dest_u.dw2.base_address = (UOFFSET(pI915Surface) >> 2); /* starting DWORD address */ + buffer_info->dest_v.dw1.pitch = (pI915Surface->uvStride >> 2); /* in Dwords */ + buffer_info->dest_v.dw2.base_address = (VOFFSET(pI915Surface) >> 2); /* starting DWORD address */ + + if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) { + ; + } else if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_TOP_FIELD) { + buffer_info->dest_buf.dw1.v_ls = 1; + } else if ((picture_structure & XVMC_FRAME_PICTURE) == + XVMC_BOTTOM_FIELD) { + buffer_info->dest_buf.dw1.v_ls = 1; + buffer_info->dest_buf.dw1.v_ls_offset = 1; + } + + if (picture_structure & XVMC_FRAME_PICTURE) { + ; + } else if (picture_structure & XVMC_TOP_FIELD) { + if (flags & XVMC_SECOND_FIELD) + buffer_info->dest_buf_mpeg.dw1.tff = 0; + else + buffer_info->dest_buf_mpeg.dw1.tff = 1; + } else if (picture_structure & XVMC_BOTTOM_FIELD) { + if (flags & XVMC_SECOND_FIELD) + buffer_info->dest_buf_mpeg.dw1.tff = 1; + else + buffer_info->dest_buf_mpeg.dw1.tff = 0; + } + + buffer_info->dest_buf_mpeg.dw1.picture_width = (dest->width >> 4); /* in macroblocks */ + buffer_info->dest_buf_mpeg.dw2.picture_coding_type = + picture_coding_type; } -static void i915_mc_map_state_init(XvMCContext *context) +static void i915_mc_map_state_init(XvMCContext * context) { - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - unsigned int w = context->width; - unsigned int h = context->height; - struct i915_mc_map_state *map_state; - - map_state = (struct i915_mc_map_state *)pI915XvMC->msb.map; - - memset(map_state, 0, sizeof(*map_state)); - - /* 3DSATE_MAP_STATE: Y */ - map_state->y_map.dw0.type = CMD_3D; - map_state->y_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; - map_state->y_map.dw0.retain = 1; - map_state->y_map.dw0.length = 6; - map_state->y_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; - - /* Y Forward (Past) */ - map_state->y_forward.tm0.v_ls_offset = 0; - map_state->y_forward.tm0.v_ls = 0; - map_state->y_forward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->y_forward.tm1.tiled_surface = 0; - map_state->y_forward.tm1.utilize_fence_regs = 0; - map_state->y_forward.tm1.texel_fmt = 0; /* 8bit */ - map_state->y_forward.tm1.surface_fmt = 1; /* 8bit */ - map_state->y_forward.tm1.width = w - 1; - map_state->y_forward.tm1.height = h - 1; - map_state->y_forward.tm2.depth = 0; - map_state->y_forward.tm2.max_lod = 0; - map_state->y_forward.tm2.cube_face = 0; - - /* Y Backward (Future) */ - map_state->y_backward.tm0.v_ls_offset = 0; - map_state->y_backward.tm0.v_ls = 0; - map_state->y_backward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->y_backward.tm1.tiled_surface = 0; - map_state->y_backward.tm1.utilize_fence_regs = 0; - map_state->y_backward.tm1.texel_fmt = 0; /* 8bit */ - map_state->y_backward.tm1.surface_fmt = 1; /* 8bit */ - map_state->y_backward.tm1.width = w - 1; - map_state->y_backward.tm1.height = h - 1; - map_state->y_backward.tm2.depth = 0; - map_state->y_backward.tm2.max_lod = 0; - map_state->y_backward.tm2.cube_face = 0; - - /* 3DSATE_MAP_STATE: U */ - map_state->u_map.dw0.type = CMD_3D; - map_state->u_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; - map_state->u_map.dw0.retain = 1; - map_state->u_map.dw0.length = 6; - map_state->u_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; - - /* U Forward */ - map_state->u_forward.tm0.v_ls_offset = 0; - map_state->u_forward.tm0.v_ls = 0; - map_state->u_forward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->u_forward.tm1.tiled_surface = 0; - map_state->u_forward.tm1.utilize_fence_regs = 0; - map_state->u_forward.tm1.texel_fmt = 0; /* 8bit */ - map_state->u_forward.tm1.surface_fmt = 1; /* 8bit */ - map_state->u_forward.tm1.width = (w >> 1) - 1; - map_state->u_forward.tm1.height = (h >> 1) - 1; - map_state->u_forward.tm2.depth = 0; - map_state->u_forward.tm2.max_lod = 0; - map_state->u_forward.tm2.cube_face = 0; - - /* U Backward */ - map_state->u_backward.tm0.v_ls_offset = 0; - map_state->u_backward.tm0.v_ls = 0; - map_state->u_backward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->u_backward.tm1.tiled_surface = 0; - map_state->u_backward.tm1.utilize_fence_regs = 0; - map_state->u_backward.tm1.texel_fmt = 0; - map_state->u_backward.tm1.surface_fmt = 1; - map_state->u_backward.tm1.width = (w >> 1) - 1; - map_state->u_backward.tm1.height = (h >> 1) - 1; - map_state->u_backward.tm2.depth = 0; - map_state->u_backward.tm2.max_lod = 0; - map_state->u_backward.tm2.cube_face = 0; - - /* 3DSATE_MAP_STATE: V */ - map_state->v_map.dw0.type = CMD_3D; - map_state->v_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; - map_state->v_map.dw0.retain = 1; - map_state->v_map.dw0.length = 6; - map_state->v_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; - - /* V Forward */ - map_state->v_forward.tm0.v_ls_offset = 0; - map_state->v_forward.tm0.v_ls = 0; - map_state->v_forward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->v_forward.tm1.tiled_surface = 0; - map_state->v_forward.tm1.utilize_fence_regs = 0; - map_state->v_forward.tm1.texel_fmt = 0; - map_state->v_forward.tm1.surface_fmt = 1; - map_state->v_forward.tm1.width = (w >> 1) - 1; - map_state->v_forward.tm1.height = (h >> 1) - 1; - map_state->v_forward.tm2.depth = 0; - map_state->v_forward.tm2.max_lod = 0; - map_state->v_forward.tm2.cube_face = 0; - - /* V Backward */ - map_state->v_backward.tm0.v_ls_offset = 0; - map_state->v_backward.tm0.v_ls = 0; - map_state->v_backward.tm1.tile_walk = TILEWALK_XMAJOR; - map_state->v_backward.tm1.tiled_surface = 0; - map_state->v_backward.tm1.utilize_fence_regs = 0; - map_state->v_backward.tm1.texel_fmt = 0; - map_state->v_backward.tm1.surface_fmt = 1; - map_state->v_backward.tm1.width = (w >> 1) - 1; - map_state->v_backward.tm1.height = (h >> 1) - 1; - map_state->v_backward.tm2.depth = 0; - map_state->v_backward.tm2.max_lod = 0; - map_state->v_backward.tm2.cube_face = 0; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + unsigned int w = context->width; + unsigned int h = context->height; + struct i915_mc_map_state *map_state; + + map_state = (struct i915_mc_map_state *)pI915XvMC->msb.map; + + memset(map_state, 0, sizeof(*map_state)); + + /* 3DSATE_MAP_STATE: Y */ + map_state->y_map.dw0.type = CMD_3D; + map_state->y_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; + map_state->y_map.dw0.retain = 1; + map_state->y_map.dw0.length = 6; + map_state->y_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; + + /* Y Forward (Past) */ + map_state->y_forward.tm0.v_ls_offset = 0; + map_state->y_forward.tm0.v_ls = 0; + map_state->y_forward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->y_forward.tm1.tiled_surface = 0; + map_state->y_forward.tm1.utilize_fence_regs = 0; + map_state->y_forward.tm1.texel_fmt = 0; /* 8bit */ + map_state->y_forward.tm1.surface_fmt = 1; /* 8bit */ + map_state->y_forward.tm1.width = w - 1; + map_state->y_forward.tm1.height = h - 1; + map_state->y_forward.tm2.depth = 0; + map_state->y_forward.tm2.max_lod = 0; + map_state->y_forward.tm2.cube_face = 0; + + /* Y Backward (Future) */ + map_state->y_backward.tm0.v_ls_offset = 0; + map_state->y_backward.tm0.v_ls = 0; + map_state->y_backward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->y_backward.tm1.tiled_surface = 0; + map_state->y_backward.tm1.utilize_fence_regs = 0; + map_state->y_backward.tm1.texel_fmt = 0; /* 8bit */ + map_state->y_backward.tm1.surface_fmt = 1; /* 8bit */ + map_state->y_backward.tm1.width = w - 1; + map_state->y_backward.tm1.height = h - 1; + map_state->y_backward.tm2.depth = 0; + map_state->y_backward.tm2.max_lod = 0; + map_state->y_backward.tm2.cube_face = 0; + + /* 3DSATE_MAP_STATE: U */ + map_state->u_map.dw0.type = CMD_3D; + map_state->u_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; + map_state->u_map.dw0.retain = 1; + map_state->u_map.dw0.length = 6; + map_state->u_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; + + /* U Forward */ + map_state->u_forward.tm0.v_ls_offset = 0; + map_state->u_forward.tm0.v_ls = 0; + map_state->u_forward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->u_forward.tm1.tiled_surface = 0; + map_state->u_forward.tm1.utilize_fence_regs = 0; + map_state->u_forward.tm1.texel_fmt = 0; /* 8bit */ + map_state->u_forward.tm1.surface_fmt = 1; /* 8bit */ + map_state->u_forward.tm1.width = (w >> 1) - 1; + map_state->u_forward.tm1.height = (h >> 1) - 1; + map_state->u_forward.tm2.depth = 0; + map_state->u_forward.tm2.max_lod = 0; + map_state->u_forward.tm2.cube_face = 0; + + /* U Backward */ + map_state->u_backward.tm0.v_ls_offset = 0; + map_state->u_backward.tm0.v_ls = 0; + map_state->u_backward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->u_backward.tm1.tiled_surface = 0; + map_state->u_backward.tm1.utilize_fence_regs = 0; + map_state->u_backward.tm1.texel_fmt = 0; + map_state->u_backward.tm1.surface_fmt = 1; + map_state->u_backward.tm1.width = (w >> 1) - 1; + map_state->u_backward.tm1.height = (h >> 1) - 1; + map_state->u_backward.tm2.depth = 0; + map_state->u_backward.tm2.max_lod = 0; + map_state->u_backward.tm2.cube_face = 0; + + /* 3DSATE_MAP_STATE: V */ + map_state->v_map.dw0.type = CMD_3D; + map_state->v_map.dw0.opcode = OPC_3DSTATE_MAP_STATE; + map_state->v_map.dw0.retain = 1; + map_state->v_map.dw0.length = 6; + map_state->v_map.dw1.map_mask = MAP_MAP0 | MAP_MAP1; + + /* V Forward */ + map_state->v_forward.tm0.v_ls_offset = 0; + map_state->v_forward.tm0.v_ls = 0; + map_state->v_forward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->v_forward.tm1.tiled_surface = 0; + map_state->v_forward.tm1.utilize_fence_regs = 0; + map_state->v_forward.tm1.texel_fmt = 0; + map_state->v_forward.tm1.surface_fmt = 1; + map_state->v_forward.tm1.width = (w >> 1) - 1; + map_state->v_forward.tm1.height = (h >> 1) - 1; + map_state->v_forward.tm2.depth = 0; + map_state->v_forward.tm2.max_lod = 0; + map_state->v_forward.tm2.cube_face = 0; + + /* V Backward */ + map_state->v_backward.tm0.v_ls_offset = 0; + map_state->v_backward.tm0.v_ls = 0; + map_state->v_backward.tm1.tile_walk = TILEWALK_XMAJOR; + map_state->v_backward.tm1.tiled_surface = 0; + map_state->v_backward.tm1.utilize_fence_regs = 0; + map_state->v_backward.tm1.texel_fmt = 0; + map_state->v_backward.tm1.surface_fmt = 1; + map_state->v_backward.tm1.width = (w >> 1) - 1; + map_state->v_backward.tm1.height = (h >> 1) - 1; + map_state->v_backward.tm2.depth = 0; + map_state->v_backward.tm2.max_lod = 0; + map_state->v_backward.tm2.cube_face = 0; } -static void i915_mc_map_state_set(XvMCContext *context, - i915XvMCSurface *privPast, - i915XvMCSurface *privFuture) +static void i915_mc_map_state_set(XvMCContext * context, + i915XvMCSurface * privPast, + i915XvMCSurface * privFuture) { - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - struct i915_mc_map_state *map_state; - - map_state = (struct i915_mc_map_state *)pI915XvMC->msb.map; - - map_state->y_forward.tm0.base_address = (YOFFSET(privPast) >> 2); - map_state->y_forward.tm2.pitch = (privPast->yStride >> 2) - 1; /* in DWords - 1 */ - map_state->y_backward.tm0.base_address = (YOFFSET(privFuture) >> 2); - map_state->y_backward.tm2.pitch = (privFuture->yStride >> 2) - 1; - map_state->u_forward.tm0.base_address = (UOFFSET(privPast) >> 2); - map_state->u_forward.tm2.pitch = (privPast->uvStride >> 2) - 1; /* in DWords - 1 */ - map_state->u_backward.tm0.base_address = (UOFFSET(privFuture) >> 2); - map_state->u_backward.tm2.pitch = (privFuture->uvStride >> 2) - 1; - map_state->v_forward.tm0.base_address = (VOFFSET(privPast) >> 2); - map_state->v_forward.tm2.pitch = (privPast->uvStride >> 2) - 1; /* in DWords - 1 */ - map_state->v_backward.tm0.base_address = (VOFFSET(privFuture) >> 2); - map_state->v_backward.tm2.pitch = (privFuture->uvStride >> 2) - 1; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + struct i915_mc_map_state *map_state; + + map_state = (struct i915_mc_map_state *)pI915XvMC->msb.map; + + map_state->y_forward.tm0.base_address = (YOFFSET(privPast) >> 2); + map_state->y_forward.tm2.pitch = (privPast->yStride >> 2) - 1; /* in DWords - 1 */ + map_state->y_backward.tm0.base_address = (YOFFSET(privFuture) >> 2); + map_state->y_backward.tm2.pitch = (privFuture->yStride >> 2) - 1; + map_state->u_forward.tm0.base_address = (UOFFSET(privPast) >> 2); + map_state->u_forward.tm2.pitch = (privPast->uvStride >> 2) - 1; /* in DWords - 1 */ + map_state->u_backward.tm0.base_address = (UOFFSET(privFuture) >> 2); + map_state->u_backward.tm2.pitch = (privFuture->uvStride >> 2) - 1; + map_state->v_forward.tm0.base_address = (VOFFSET(privPast) >> 2); + map_state->v_forward.tm2.pitch = (privPast->uvStride >> 2) - 1; /* in DWords - 1 */ + map_state->v_backward.tm0.base_address = (VOFFSET(privFuture) >> 2); + map_state->v_backward.tm2.pitch = (privFuture->uvStride >> 2) - 1; } static void i915_flush(int map, int render) { - struct i915_mi_flush mi_flush; + struct i915_mi_flush mi_flush; - memset(&mi_flush, 0, sizeof(mi_flush)); - mi_flush.dw0.type = CMD_MI; - mi_flush.dw0.opcode = OPC_MI_FLUSH; - mi_flush.dw0.map_cache_invalidate = map; - mi_flush.dw0.render_cache_flush_inhibit = render; + memset(&mi_flush, 0, sizeof(mi_flush)); + mi_flush.dw0.type = CMD_MI; + mi_flush.dw0.opcode = OPC_MI_FLUSH; + mi_flush.dw0.map_cache_invalidate = map; + mi_flush.dw0.render_cache_flush_inhibit = render; - intelBatchbufferData(&mi_flush, sizeof(mi_flush), 0); + intelBatchbufferData(&mi_flush, sizeof(mi_flush), 0); } -static void i915_mc_load_indirect_render_init(XvMCContext *context) +static void i915_mc_load_indirect_render_init(XvMCContext * context) { - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - sis_state *sis; - msb_state *msb; - struct i915_3dstate_load_indirect *load_indirect; - int mem_select; - - mc_render_load_indirect_size = sizeof(*load_indirect) + sizeof(*sis) - + sizeof(*msb); - mc_render_load_indirect = calloc(1, mc_render_load_indirect_size); - - load_indirect = (struct i915_3dstate_load_indirect *)mc_render_load_indirect; - load_indirect->dw0.type = CMD_3D; - load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; - load_indirect->dw0.block_mask = BLOCK_SIS | BLOCK_MSB; - load_indirect->dw0.length = (mc_render_load_indirect_size >> 2) - 2; - - if (pI915XvMC->deviceID == PCI_CHIP_I915_G || - pI915XvMC->deviceID == PCI_CHIP_I915_GM) - mem_select = 0; - else - mem_select = 1; - - load_indirect->dw0.mem_select = mem_select; - - /* Static Indirect state buffer (dest buffer info) */ - sis = (sis_state *)(++load_indirect); - sis->dw0.valid = 1; - sis->dw0.force = 1; - sis->dw1.length = 16; /* 4 * 3 + 2 + 3 - 1 */ - - if (mem_select) - sis->dw0.buffer_address = (pI915XvMC->sis.offset >> 2); - else - sis->dw0.buffer_address = (pI915XvMC->sis.bus_addr >> 2); - - /* Map state buffer (reference buffer info) */ - msb = (msb_state *)(++sis); - msb->dw0.valid = 1; - msb->dw0.force = 1; - msb->dw1.length = 23; /* 3 * 8 - 1 */ - - if (mem_select) - msb->dw0.buffer_address = (pI915XvMC->msb.offset >> 2); - else - msb->dw0.buffer_address = (pI915XvMC->msb.bus_addr >> 2); + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + sis_state *sis; + msb_state *msb; + struct i915_3dstate_load_indirect *load_indirect; + int mem_select; + + mc_render_load_indirect_size = sizeof(*load_indirect) + sizeof(*sis) + + sizeof(*msb); + mc_render_load_indirect = calloc(1, mc_render_load_indirect_size); + + load_indirect = + (struct i915_3dstate_load_indirect *)mc_render_load_indirect; + load_indirect->dw0.type = CMD_3D; + load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; + load_indirect->dw0.block_mask = BLOCK_SIS | BLOCK_MSB; + load_indirect->dw0.length = (mc_render_load_indirect_size >> 2) - 2; + + if (pI915XvMC->deviceID == PCI_CHIP_I915_G || + pI915XvMC->deviceID == PCI_CHIP_I915_GM) + mem_select = 0; + else + mem_select = 1; + + load_indirect->dw0.mem_select = mem_select; + + /* Static Indirect state buffer (dest buffer info) */ + sis = (sis_state *) (++load_indirect); + sis->dw0.valid = 1; + sis->dw0.force = 1; + sis->dw1.length = 16; /* 4 * 3 + 2 + 3 - 1 */ + + if (mem_select) + sis->dw0.buffer_address = (pI915XvMC->sis.offset >> 2); + else + sis->dw0.buffer_address = (pI915XvMC->sis.bus_addr >> 2); + + /* Map state buffer (reference buffer info) */ + msb = (msb_state *) (++sis); + msb->dw0.valid = 1; + msb->dw0.force = 1; + msb->dw1.length = 23; /* 3 * 8 - 1 */ + + if (mem_select) + msb->dw0.buffer_address = (pI915XvMC->msb.offset >> 2); + else + msb->dw0.buffer_address = (pI915XvMC->msb.bus_addr >> 2); } static void i915_mc_load_indirect_render_emit(void) { - i915_emit_batch(mc_render_load_indirect, mc_render_load_indirect_size, 0); + i915_emit_batch(mc_render_load_indirect, mc_render_load_indirect_size, + 0); } -static void i915_mc_mpeg_set_origin(XvMCContext *context, XvMCMacroBlock *mb) +static void i915_mc_mpeg_set_origin(XvMCContext * context, XvMCMacroBlock * mb) { - struct i915_3dmpeg_set_origin set_origin; + struct i915_3dmpeg_set_origin set_origin; - /* 3DMPEG_SET_ORIGIN */ - memset(&set_origin, 0, sizeof(set_origin)); - set_origin.dw0.type = CMD_3D; - set_origin.dw0.opcode = OPC_3DMPEG_SET_ORIGIN; - set_origin.dw0.length = 0; - set_origin.dw1.h_origin = mb->x; - set_origin.dw1.v_origin = mb->y; + /* 3DMPEG_SET_ORIGIN */ + memset(&set_origin, 0, sizeof(set_origin)); + set_origin.dw0.type = CMD_3D; + set_origin.dw0.opcode = OPC_3DMPEG_SET_ORIGIN; + set_origin.dw0.length = 0; + set_origin.dw1.h_origin = mb->x; + set_origin.dw1.v_origin = mb->y; - intelBatchbufferData(&set_origin, sizeof(set_origin), 0); + intelBatchbufferData(&set_origin, sizeof(set_origin), 0); } -static void i915_mc_mpeg_macroblock_ipicture(XvMCContext *context, XvMCMacroBlock *mb) +static void i915_mc_mpeg_macroblock_ipicture(XvMCContext * context, + XvMCMacroBlock * mb) { - struct i915_3dmpeg_macroblock_ipicture macroblock_ipicture; + struct i915_3dmpeg_macroblock_ipicture macroblock_ipicture; - /* 3DMPEG_MACROBLOCK_IPICTURE */ - memset(¯oblock_ipicture, 0, sizeof(macroblock_ipicture)); - macroblock_ipicture.dw0.type = CMD_3D; - macroblock_ipicture.dw0.opcode = OPC_3DMPEG_MACROBLOCK_IPICTURE; - macroblock_ipicture.dw0.dct_type = (mb->dct_type == XVMC_DCT_TYPE_FIELD); + /* 3DMPEG_MACROBLOCK_IPICTURE */ + memset(¯oblock_ipicture, 0, sizeof(macroblock_ipicture)); + macroblock_ipicture.dw0.type = CMD_3D; + macroblock_ipicture.dw0.opcode = OPC_3DMPEG_MACROBLOCK_IPICTURE; + macroblock_ipicture.dw0.dct_type = + (mb->dct_type == XVMC_DCT_TYPE_FIELD); - intelBatchbufferData(¯oblock_ipicture, sizeof(macroblock_ipicture), 0); + intelBatchbufferData(¯oblock_ipicture, sizeof(macroblock_ipicture), + 0); } #if 0 -static void i915_mc_mpeg_macroblock_0mv(XvMCContext *context, XvMCMacroBlock *mb) +static void i915_mc_mpeg_macroblock_0mv(XvMCContext * context, + XvMCMacroBlock * mb) { - struct i915_3dmpeg_macroblock_0mv macroblock_0mv; - - /* 3DMPEG_MACROBLOCK(0mv) */ - memset(¯oblock_0mv, 0, sizeof(macroblock_0mv)); - macroblock_0mv.header.dw0.type = CMD_3D; - macroblock_0mv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; - macroblock_0mv.header.dw0.length = 0; - macroblock_0mv.header.dw1.mb_intra = 1; /* should be 1 */ - macroblock_0mv.header.dw1.forward = 0; /* should be 0 */ - macroblock_0mv.header.dw1.backward = 0; /* should be 0 */ - macroblock_0mv.header.dw1.h263_4mv = 0; /* should be 0 */ - macroblock_0mv.header.dw1.dct_type = (mb->dct_type == XVMC_DCT_TYPE_FIELD); + struct i915_3dmpeg_macroblock_0mv macroblock_0mv; + + /* 3DMPEG_MACROBLOCK(0mv) */ + memset(¯oblock_0mv, 0, sizeof(macroblock_0mv)); + macroblock_0mv.header.dw0.type = CMD_3D; + macroblock_0mv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; + macroblock_0mv.header.dw0.length = 0; + macroblock_0mv.header.dw1.mb_intra = 1; /* should be 1 */ + macroblock_0mv.header.dw1.forward = 0; /* should be 0 */ + macroblock_0mv.header.dw1.backward = 0; /* should be 0 */ + macroblock_0mv.header.dw1.h263_4mv = 0; /* should be 0 */ + macroblock_0mv.header.dw1.dct_type = + (mb->dct_type == XVMC_DCT_TYPE_FIELD); /* if (!mb->coded_block_pattern) macroblock_0mv.header.dw1.dct_type = XVMC_DCT_TYPE_FRAME; */ - macroblock_0mv.header.dw1.motion_type = 0; // (mb->motion_type & 0x3); - macroblock_0mv.header.dw1.vertical_field_select = 0; // mb->motion_vertical_field_select & 0xf; - macroblock_0mv.header.dw1.coded_block_pattern = mb->coded_block_pattern; - macroblock_0mv.header.dw1.skipped_macroblocks = 0; + macroblock_0mv.header.dw1.motion_type = 0; // (mb->motion_type & 0x3); + macroblock_0mv.header.dw1.vertical_field_select = 0; // mb->motion_vertical_field_select & 0xf; + macroblock_0mv.header.dw1.coded_block_pattern = mb->coded_block_pattern; + macroblock_0mv.header.dw1.skipped_macroblocks = 0; - intelBatchbufferData(¯oblock_0mv, sizeof(macroblock_0mv), 0); + intelBatchbufferData(¯oblock_0mv, sizeof(macroblock_0mv), 0); } #endif -static void i915_mc_mpeg_macroblock_1fbmv(XvMCContext *context, XvMCMacroBlock *mb) +static void i915_mc_mpeg_macroblock_1fbmv(XvMCContext * context, + XvMCMacroBlock * mb) { - struct i915_3dmpeg_macroblock_1fbmv macroblock_1fbmv; - vector_t mv0[2]; - - /* 3DMPEG_MACROBLOCK(1fbmv) */ - memset(¯oblock_1fbmv, 0, sizeof(macroblock_1fbmv)); - macroblock_1fbmv.header.dw0.type = CMD_3D; - macroblock_1fbmv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; - macroblock_1fbmv.header.dw0.length = 2; - macroblock_1fbmv.header.dw1.mb_intra = 0; /* should be 0 */ - macroblock_1fbmv.header.dw1.forward = ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) ? 1 : 0); - macroblock_1fbmv.header.dw1.backward = ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) ? 1 : 0); - macroblock_1fbmv.header.dw1.h263_4mv = 0; /* should be 0 */ - macroblock_1fbmv.header.dw1.dct_type = (mb->dct_type == XVMC_DCT_TYPE_FIELD); - - if (!(mb->coded_block_pattern & 0x3f)) - macroblock_1fbmv.header.dw1.dct_type = XVMC_DCT_TYPE_FRAME; - - macroblock_1fbmv.header.dw1.motion_type = (mb->motion_type & 0x03); - macroblock_1fbmv.header.dw1.vertical_field_select = (mb->motion_vertical_field_select & 0x0f); - macroblock_1fbmv.header.dw1.coded_block_pattern = mb->coded_block_pattern; - macroblock_1fbmv.header.dw1.skipped_macroblocks = 0; - - mv0[0].component[0] = mb->PMV[0][0][0]; - mv0[0].component[1] = mb->PMV[0][0][1]; - mv0[1].component[0] = mb->PMV[0][1][0]; - mv0[1].component[1] = mb->PMV[0][1][1]; - - macroblock_1fbmv.dw2 = mv0[0].v; - macroblock_1fbmv.dw3 = mv0[1].v; - - intelBatchbufferData(¯oblock_1fbmv, sizeof(macroblock_1fbmv), 0); + struct i915_3dmpeg_macroblock_1fbmv macroblock_1fbmv; + vector_t mv0[2]; + + /* 3DMPEG_MACROBLOCK(1fbmv) */ + memset(¯oblock_1fbmv, 0, sizeof(macroblock_1fbmv)); + macroblock_1fbmv.header.dw0.type = CMD_3D; + macroblock_1fbmv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; + macroblock_1fbmv.header.dw0.length = 2; + macroblock_1fbmv.header.dw1.mb_intra = 0; /* should be 0 */ + macroblock_1fbmv.header.dw1.forward = + ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) ? 1 : 0); + macroblock_1fbmv.header.dw1.backward = + ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) ? 1 : 0); + macroblock_1fbmv.header.dw1.h263_4mv = 0; /* should be 0 */ + macroblock_1fbmv.header.dw1.dct_type = + (mb->dct_type == XVMC_DCT_TYPE_FIELD); + + if (!(mb->coded_block_pattern & 0x3f)) + macroblock_1fbmv.header.dw1.dct_type = XVMC_DCT_TYPE_FRAME; + + macroblock_1fbmv.header.dw1.motion_type = (mb->motion_type & 0x03); + macroblock_1fbmv.header.dw1.vertical_field_select = + (mb->motion_vertical_field_select & 0x0f); + macroblock_1fbmv.header.dw1.coded_block_pattern = + mb->coded_block_pattern; + macroblock_1fbmv.header.dw1.skipped_macroblocks = 0; + + mv0[0].component[0] = mb->PMV[0][0][0]; + mv0[0].component[1] = mb->PMV[0][0][1]; + mv0[1].component[0] = mb->PMV[0][1][0]; + mv0[1].component[1] = mb->PMV[0][1][1]; + + macroblock_1fbmv.dw2 = mv0[0].v; + macroblock_1fbmv.dw3 = mv0[1].v; + + intelBatchbufferData(¯oblock_1fbmv, sizeof(macroblock_1fbmv), 0); } -static void i915_mc_mpeg_macroblock_2fbmv(XvMCContext *context, XvMCMacroBlock *mb, unsigned int ps) +static void i915_mc_mpeg_macroblock_2fbmv(XvMCContext * context, + XvMCMacroBlock * mb, unsigned int ps) { - struct i915_3dmpeg_macroblock_2fbmv macroblock_2fbmv; - vector_t mv0[2]; - vector_t mv1[2]; - - /* 3DMPEG_MACROBLOCK(2fbmv) */ - memset(¯oblock_2fbmv, 0, sizeof(macroblock_2fbmv)); - macroblock_2fbmv.header.dw0.type = CMD_3D; - macroblock_2fbmv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; - macroblock_2fbmv.header.dw0.length = 4; - macroblock_2fbmv.header.dw1.mb_intra = 0; /* should be 0 */ - macroblock_2fbmv.header.dw1.forward = ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) ? 1 : 0); - macroblock_2fbmv.header.dw1.backward = ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) ? 1 : 0); - macroblock_2fbmv.header.dw1.h263_4mv = 0; /* should be 0 */ - macroblock_2fbmv.header.dw1.dct_type = (mb->dct_type == XVMC_DCT_TYPE_FIELD); - - if (!(mb->coded_block_pattern & 0x3f)) - macroblock_2fbmv.header.dw1.dct_type = XVMC_DCT_TYPE_FRAME; - - macroblock_2fbmv.header.dw1.motion_type = (mb->motion_type & 0x03); - macroblock_2fbmv.header.dw1.vertical_field_select = (mb->motion_vertical_field_select & 0x0f); - macroblock_2fbmv.header.dw1.coded_block_pattern = mb->coded_block_pattern; - macroblock_2fbmv.header.dw1.skipped_macroblocks = 0; - - mv0[0].component[0] = mb->PMV[0][0][0]; - mv0[0].component[1] = mb->PMV[0][0][1]; - mv0[1].component[0] = mb->PMV[0][1][0]; - mv0[1].component[1] = mb->PMV[0][1][1]; - mv1[0].component[0] = mb->PMV[1][0][0]; - mv1[0].component[1] = mb->PMV[1][0][1]; - mv1[1].component[0] = mb->PMV[1][1][0]; - mv1[1].component[1] = mb->PMV[1][1][1]; - - if ((ps & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) { - if ((mb->motion_type & 3) == XVMC_PREDICTION_FIELD) { - mv0[0].component[1] = mb->PMV[0][0][1] >> 1; - mv0[1].component[1] = mb->PMV[0][1][1] >> 1; - mv1[0].component[1] = mb->PMV[1][0][1] >> 1; - mv1[1].component[1] = mb->PMV[1][1][1] >> 1; - } else if ((mb->motion_type & 3) == XVMC_PREDICTION_DUAL_PRIME) { - mv0[0].component[1] = mb->PMV[0][0][1] >> 1; - mv0[1].component[1] = mb->PMV[0][1][1] >> 1; // MPEG2 MV[0][1] isn't used - mv1[0].component[1] = mb->PMV[1][0][1] >> 1; - mv1[1].component[1] = mb->PMV[1][1][1] >> 1; - } - } - - macroblock_2fbmv.dw2 = mv0[0].v; - macroblock_2fbmv.dw3 = mv0[1].v; - macroblock_2fbmv.dw4 = mv1[0].v; - macroblock_2fbmv.dw5 = mv1[1].v; - - intelBatchbufferData(¯oblock_2fbmv, sizeof(macroblock_2fbmv), 0); + struct i915_3dmpeg_macroblock_2fbmv macroblock_2fbmv; + vector_t mv0[2]; + vector_t mv1[2]; + + /* 3DMPEG_MACROBLOCK(2fbmv) */ + memset(¯oblock_2fbmv, 0, sizeof(macroblock_2fbmv)); + macroblock_2fbmv.header.dw0.type = CMD_3D; + macroblock_2fbmv.header.dw0.opcode = OPC_3DMPEG_MACROBLOCK; + macroblock_2fbmv.header.dw0.length = 4; + macroblock_2fbmv.header.dw1.mb_intra = 0; /* should be 0 */ + macroblock_2fbmv.header.dw1.forward = + ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) ? 1 : 0); + macroblock_2fbmv.header.dw1.backward = + ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) ? 1 : 0); + macroblock_2fbmv.header.dw1.h263_4mv = 0; /* should be 0 */ + macroblock_2fbmv.header.dw1.dct_type = + (mb->dct_type == XVMC_DCT_TYPE_FIELD); + + if (!(mb->coded_block_pattern & 0x3f)) + macroblock_2fbmv.header.dw1.dct_type = XVMC_DCT_TYPE_FRAME; + + macroblock_2fbmv.header.dw1.motion_type = (mb->motion_type & 0x03); + macroblock_2fbmv.header.dw1.vertical_field_select = + (mb->motion_vertical_field_select & 0x0f); + macroblock_2fbmv.header.dw1.coded_block_pattern = + mb->coded_block_pattern; + macroblock_2fbmv.header.dw1.skipped_macroblocks = 0; + + mv0[0].component[0] = mb->PMV[0][0][0]; + mv0[0].component[1] = mb->PMV[0][0][1]; + mv0[1].component[0] = mb->PMV[0][1][0]; + mv0[1].component[1] = mb->PMV[0][1][1]; + mv1[0].component[0] = mb->PMV[1][0][0]; + mv1[0].component[1] = mb->PMV[1][0][1]; + mv1[1].component[0] = mb->PMV[1][1][0]; + mv1[1].component[1] = mb->PMV[1][1][1]; + + if ((ps & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) { + if ((mb->motion_type & 3) == XVMC_PREDICTION_FIELD) { + mv0[0].component[1] = mb->PMV[0][0][1] >> 1; + mv0[1].component[1] = mb->PMV[0][1][1] >> 1; + mv1[0].component[1] = mb->PMV[1][0][1] >> 1; + mv1[1].component[1] = mb->PMV[1][1][1] >> 1; + } else if ((mb->motion_type & 3) == XVMC_PREDICTION_DUAL_PRIME) { + mv0[0].component[1] = mb->PMV[0][0][1] >> 1; + mv0[1].component[1] = mb->PMV[0][1][1] >> 1; // MPEG2 MV[0][1] isn't used + mv1[0].component[1] = mb->PMV[1][0][1] >> 1; + mv1[1].component[1] = mb->PMV[1][1][1] >> 1; + } + } + + macroblock_2fbmv.dw2 = mv0[0].v; + macroblock_2fbmv.dw3 = mv0[1].v; + macroblock_2fbmv.dw4 = mv1[0].v; + macroblock_2fbmv.dw5 = mv1[1].v; + + intelBatchbufferData(¯oblock_2fbmv, sizeof(macroblock_2fbmv), 0); } #if 0 -static void i915_mc_invalidate_subcontext_buffers(XvMCContext *context, unsigned int mask) +static void i915_mc_invalidate_subcontext_buffers(XvMCContext * context, + unsigned int mask) { - struct i915_3dstate_load_indirect *load_indirect = NULL; - sis_state *sis = NULL; - dis_state *dis = NULL; - ssb_state *ssb = NULL; - msb_state *msb = NULL; - psp_state *psp = NULL; - psc_state *psc = NULL; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)context->privData; - unsigned int size; - void *base = NULL, *ptr = NULL; - - size = sizeof(*load_indirect); - if (mask & BLOCK_SIS) - size += sizeof(*sis); - if (mask & BLOCK_DIS) - size += sizeof(*dis); - if (mask & BLOCK_SSB) - size += sizeof(*ssb); - if (mask & BLOCK_MSB) - size += sizeof(*msb); - if (mask & BLOCK_PSP) - size += sizeof(*psp); - if (mask & BLOCK_PSC) - size += sizeof(*psc); - - if (size == sizeof(*load_indirect)) { - XVMC_ERR("There must be at least one bit set\n"); - return; - } - - /* 3DSTATE_LOAD_INDIRECT */ - base = calloc(1, size); - load_indirect = (struct i915_3dstate_load_indirect *)base; - load_indirect->dw0.type = CMD_3D; - load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; - - if (pI915XvMC->deviceID == PCI_CHIP_I915_G || - pI915XvMC->deviceID == PCI_CHIP_I915_GM || - pI915XvMC->deviceID == PCI_CHIP_I945_G || - pI915XvMC->deviceID == PCI_CHIP_I945_GM) - load_indirect->dw0.mem_select = 0; - else - load_indirect->dw0.mem_select = 1; - - load_indirect->dw0.block_mask = mask; - load_indirect->dw0.length = (size >> 2) - 2; - ptr = ++load_indirect; - - /* SIS */ - if (mask & BLOCK_SIS) { - sis = (sis_state *)ptr; - sis->dw0.valid = 0; - sis->dw0.buffer_address = 0; - sis->dw1.length = 0; - ptr = ++sis; - } - - /* DIS */ - if (mask & BLOCK_DIS) { - dis = (dis_state *)ptr; - dis->dw0.valid = 0; - dis->dw0.reset = 0; - dis->dw0.buffer_address = 0; - ptr = ++dis; - } - - /* SSB */ - if (mask & BLOCK_SSB) { - ssb = (ssb_state *)ptr; - ssb->dw0.valid = 0; - ssb->dw0.buffer_address = 0; - ssb->dw1.length = 0; - ptr = ++ssb; - } - - /* MSB */ - if (mask & BLOCK_MSB) { - msb = (msb_state *)ptr; - msb->dw0.valid = 0; - msb->dw0.buffer_address = 0; - msb->dw1.length = 0; - ptr = ++msb; - } - - /* PSP */ - if (mask & BLOCK_PSP) { - psp = (psp_state *)ptr; - psp->dw0.valid = 0; - psp->dw0.buffer_address = 0; - psp->dw1.length = 0; - ptr = ++psp; - } - - /* PSC */ - if (mask & BLOCK_PSC) { - psc = (psc_state *)ptr; - psc->dw0.valid = 0; - psc->dw0.buffer_address = 0; - psc->dw1.length = 0; - ptr = ++psc; - } - - intelBatchbufferData(base, size, 0); - free(base); + struct i915_3dstate_load_indirect *load_indirect = NULL; + sis_state *sis = NULL; + dis_state *dis = NULL; + ssb_state *ssb = NULL; + msb_state *msb = NULL; + psp_state *psp = NULL; + psc_state *psc = NULL; + i915XvMCContext *pI915XvMC = (i915XvMCContext *) context->privData; + unsigned int size; + void *base = NULL, *ptr = NULL; + + size = sizeof(*load_indirect); + if (mask & BLOCK_SIS) + size += sizeof(*sis); + if (mask & BLOCK_DIS) + size += sizeof(*dis); + if (mask & BLOCK_SSB) + size += sizeof(*ssb); + if (mask & BLOCK_MSB) + size += sizeof(*msb); + if (mask & BLOCK_PSP) + size += sizeof(*psp); + if (mask & BLOCK_PSC) + size += sizeof(*psc); + + if (size == sizeof(*load_indirect)) { + XVMC_ERR("There must be at least one bit set\n"); + return; + } + + /* 3DSTATE_LOAD_INDIRECT */ + base = calloc(1, size); + load_indirect = (struct i915_3dstate_load_indirect *)base; + load_indirect->dw0.type = CMD_3D; + load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; + + if (pI915XvMC->deviceID == PCI_CHIP_I915_G || + pI915XvMC->deviceID == PCI_CHIP_I915_GM || + pI915XvMC->deviceID == PCI_CHIP_I945_G || + pI915XvMC->deviceID == PCI_CHIP_I945_GM) + load_indirect->dw0.mem_select = 0; + else + load_indirect->dw0.mem_select = 1; + + load_indirect->dw0.block_mask = mask; + load_indirect->dw0.length = (size >> 2) - 2; + ptr = ++load_indirect; + + /* SIS */ + if (mask & BLOCK_SIS) { + sis = (sis_state *) ptr; + sis->dw0.valid = 0; + sis->dw0.buffer_address = 0; + sis->dw1.length = 0; + ptr = ++sis; + } + + /* DIS */ + if (mask & BLOCK_DIS) { + dis = (dis_state *) ptr; + dis->dw0.valid = 0; + dis->dw0.reset = 0; + dis->dw0.buffer_address = 0; + ptr = ++dis; + } + + /* SSB */ + if (mask & BLOCK_SSB) { + ssb = (ssb_state *) ptr; + ssb->dw0.valid = 0; + ssb->dw0.buffer_address = 0; + ssb->dw1.length = 0; + ptr = ++ssb; + } + + /* MSB */ + if (mask & BLOCK_MSB) { + msb = (msb_state *) ptr; + msb->dw0.valid = 0; + msb->dw0.buffer_address = 0; + msb->dw1.length = 0; + ptr = ++msb; + } + + /* PSP */ + if (mask & BLOCK_PSP) { + psp = (psp_state *) ptr; + psp->dw0.valid = 0; + psp->dw0.buffer_address = 0; + psp->dw1.length = 0; + ptr = ++psp; + } + + /* PSC */ + if (mask & BLOCK_PSC) { + psc = (psc_state *) ptr; + psc->dw0.valid = 0; + psc->dw0.buffer_address = 0; + psc->dw1.length = 0; + ptr = ++psc; + } + + intelBatchbufferData(base, size, 0); + free(base); } #endif -static int i915_xvmc_map_buffers(i915XvMCContext *pI915XvMC) +static int i915_xvmc_map_buffers(i915XvMCContext * pI915XvMC) { - if (drmMap(xvmc_driver->fd, - pI915XvMC->sis.handle, - pI915XvMC->sis.size, - (drmAddress *)&pI915XvMC->sis.map) != 0) { - return -1; - } - - if (drmMap(xvmc_driver->fd, - pI915XvMC->ssb.handle, - pI915XvMC->ssb.size, - (drmAddress *)&pI915XvMC->ssb.map) != 0) { - return -1; - } - - if (drmMap(xvmc_driver->fd, - pI915XvMC->msb.handle, - pI915XvMC->msb.size, - (drmAddress *)&pI915XvMC->msb.map) != 0) { - return -1; - } - - if (drmMap(xvmc_driver->fd, - pI915XvMC->psp.handle, - pI915XvMC->psp.size, - (drmAddress *)&pI915XvMC->psp.map) != 0) { - return -1; - } - - if (drmMap(xvmc_driver->fd, - pI915XvMC->psc.handle, - pI915XvMC->psc.size, - (drmAddress *)&pI915XvMC->psc.map) != 0) { - return -1; - } - - if (drmMap(xvmc_driver->fd, - pI915XvMC->corrdata.handle, - pI915XvMC->corrdata.size, - (drmAddress *)&pI915XvMC->corrdata.map) != 0) { - return -1; - } - - return 0; + if (drmMap(xvmc_driver->fd, + pI915XvMC->sis.handle, + pI915XvMC->sis.size, + (drmAddress *) & pI915XvMC->sis.map) != 0) { + return -1; + } + + if (drmMap(xvmc_driver->fd, + pI915XvMC->ssb.handle, + pI915XvMC->ssb.size, + (drmAddress *) & pI915XvMC->ssb.map) != 0) { + return -1; + } + + if (drmMap(xvmc_driver->fd, + pI915XvMC->msb.handle, + pI915XvMC->msb.size, + (drmAddress *) & pI915XvMC->msb.map) != 0) { + return -1; + } + + if (drmMap(xvmc_driver->fd, + pI915XvMC->psp.handle, + pI915XvMC->psp.size, + (drmAddress *) & pI915XvMC->psp.map) != 0) { + return -1; + } + + if (drmMap(xvmc_driver->fd, + pI915XvMC->psc.handle, + pI915XvMC->psc.size, + (drmAddress *) & pI915XvMC->psc.map) != 0) { + return -1; + } + + if (drmMap(xvmc_driver->fd, + pI915XvMC->corrdata.handle, + pI915XvMC->corrdata.size, + (drmAddress *) & pI915XvMC->corrdata.map) != 0) { + return -1; + } + + return 0; } -static void i915_xvmc_unmap_buffers(i915XvMCContext *pI915XvMC) +static void i915_xvmc_unmap_buffers(i915XvMCContext * pI915XvMC) { - if (pI915XvMC->sis.map) { - drmUnmap(pI915XvMC->sis.map, pI915XvMC->sis.size); - pI915XvMC->sis.map = NULL; - } - - if (pI915XvMC->ssb.map) { - drmUnmap(pI915XvMC->ssb.map, pI915XvMC->ssb.size); - pI915XvMC->ssb.map = NULL; - } - - if (pI915XvMC->msb.map) { - drmUnmap(pI915XvMC->msb.map, pI915XvMC->msb.size); - pI915XvMC->msb.map = NULL; - } - - if (pI915XvMC->psp.map) { - drmUnmap(pI915XvMC->psp.map, pI915XvMC->psp.size); - pI915XvMC->psp.map = NULL; - } - - if (pI915XvMC->psc.map) { - drmUnmap(pI915XvMC->psc.map, pI915XvMC->psc.size); - pI915XvMC->psc.map = NULL; - } - - if (pI915XvMC->corrdata.map) { - drmUnmap(pI915XvMC->corrdata.map, pI915XvMC->corrdata.size); - pI915XvMC->corrdata.map = NULL; - } + if (pI915XvMC->sis.map) { + drmUnmap(pI915XvMC->sis.map, pI915XvMC->sis.size); + pI915XvMC->sis.map = NULL; + } + + if (pI915XvMC->ssb.map) { + drmUnmap(pI915XvMC->ssb.map, pI915XvMC->ssb.size); + pI915XvMC->ssb.map = NULL; + } + + if (pI915XvMC->msb.map) { + drmUnmap(pI915XvMC->msb.map, pI915XvMC->msb.size); + pI915XvMC->msb.map = NULL; + } + + if (pI915XvMC->psp.map) { + drmUnmap(pI915XvMC->psp.map, pI915XvMC->psp.size); + pI915XvMC->psp.map = NULL; + } + + if (pI915XvMC->psc.map) { + drmUnmap(pI915XvMC->psc.map, pI915XvMC->psc.size); + pI915XvMC->psc.map = NULL; + } + + if (pI915XvMC->corrdata.map) { + drmUnmap(pI915XvMC->corrdata.map, pI915XvMC->corrdata.size); + pI915XvMC->corrdata.map = NULL; + } } #if 0 /* * Video post processing */ -static void i915_yuv2rgb_map_state_buffer(XvMCSurface *target_surface) +static void i915_yuv2rgb_map_state_buffer(XvMCSurface * target_surface) { - struct i915_3dstate_map_state *map_state; - struct texture_map *tm; - i915XvMCSurface *privTarget = NULL; - i915XvMCContext *pI915XvMC = NULL; - unsigned int w = target_surface->width, h = target_surface->height; - - privTarget = (i915XvMCSurface *)target_surface->privData; - pI915XvMC = (i915XvMCContext *)privTarget->privContext; - /* 3DSATE_MAP_STATE */ - map_state = (struct i915_3dstate_map_state *)pI915XvMC->msb.map; - memset(map_state, 0, sizeof(*map_state)); - map_state->dw0.type = CMD_3D; - map_state->dw0.opcode = OPC_3DSTATE_MAP_STATE; - map_state->dw0.retain = 0; - map_state->dw0.length = 9; - map_state->dw1.map_mask = MAP_MAP0 | MAP_MAP1 | MAP_MAP2; - - /* texture map 0: V Plane */ - tm = (struct texture_map *)(++map_state); - memset(tm, 0, sizeof(*tm)); - tm->tm0.v_ls_offset = 0; - tm->tm0.v_ls = 0; - tm->tm0.base_address = VOFFSET(privTarget); - tm->tm1.tile_walk = TILEWALK_XMAJOR; - tm->tm1.tiled_surface = 0; - tm->tm1.utilize_fence_regs = 1; - tm->tm1.texel_fmt = 0; - tm->tm1.surface_fmt = 1; - tm->tm1.width = (w >> 1) - 1; - tm->tm1.height = (h >> 1) - 1; - tm->tm2.depth = 0; - tm->tm2.max_lod = 0; - tm->tm2.cube_face = 0; - tm->tm2.pitch = (privTarget->uvStride >> 2) - 1; /* in DWords - 1 */ - - /* texture map 1: Y Plane */ - ++tm; - memset(tm, 0, sizeof(*tm)); - tm->tm0.v_ls_offset = 0; - tm->tm0.v_ls = 0; - tm->tm0.base_address = YOFFSET(privTarget); - tm->tm1.tile_walk = TILEWALK_XMAJOR; - tm->tm1.tiled_surface = 0; - tm->tm1.utilize_fence_regs = 1; - tm->tm1.texel_fmt = 0; - tm->tm1.surface_fmt = 1; - tm->tm1.width = w - 1; - tm->tm1.height = h - 1; - tm->tm2.depth = 0; - tm->tm2.max_lod = 0; - tm->tm2.cube_face = 0; - tm->tm2.pitch = (privTarget->yStride >> 2) - 1; /* in DWords - 1 */ - - /* texture map 2: U Plane */ - ++tm; - memset(tm, 0, sizeof(*tm)); - tm->tm0.v_ls_offset = 0; - tm->tm0.v_ls = 0; - tm->tm0.base_address = UOFFSET(privTarget); - tm->tm1.tile_walk = TILEWALK_XMAJOR; - tm->tm1.tiled_surface = 0; - tm->tm1.utilize_fence_regs = 1; - tm->tm1.texel_fmt = 0; - tm->tm1.surface_fmt = 1; - tm->tm1.width = (w >> 1) - 1; - tm->tm1.height = (h >> 1) - 1; - tm->tm2.depth = 0; - tm->tm2.max_lod = 0; - tm->tm2.cube_face = 0; - tm->tm2.pitch = (privTarget->uvStride >> 2) - 1; /* in DWords - 1 */ + struct i915_3dstate_map_state *map_state; + struct texture_map *tm; + i915XvMCSurface *privTarget = NULL; + i915XvMCContext *pI915XvMC = NULL; + unsigned int w = target_surface->width, h = target_surface->height; + + privTarget = (i915XvMCSurface *) target_surface->privData; + pI915XvMC = (i915XvMCContext *) privTarget->privContext; + /* 3DSATE_MAP_STATE */ + map_state = (struct i915_3dstate_map_state *)pI915XvMC->msb.map; + memset(map_state, 0, sizeof(*map_state)); + map_state->dw0.type = CMD_3D; + map_state->dw0.opcode = OPC_3DSTATE_MAP_STATE; + map_state->dw0.retain = 0; + map_state->dw0.length = 9; + map_state->dw1.map_mask = MAP_MAP0 | MAP_MAP1 | MAP_MAP2; + + /* texture map 0: V Plane */ + tm = (struct texture_map *)(++map_state); + memset(tm, 0, sizeof(*tm)); + tm->tm0.v_ls_offset = 0; + tm->tm0.v_ls = 0; + tm->tm0.base_address = VOFFSET(privTarget); + tm->tm1.tile_walk = TILEWALK_XMAJOR; + tm->tm1.tiled_surface = 0; + tm->tm1.utilize_fence_regs = 1; + tm->tm1.texel_fmt = 0; + tm->tm1.surface_fmt = 1; + tm->tm1.width = (w >> 1) - 1; + tm->tm1.height = (h >> 1) - 1; + tm->tm2.depth = 0; + tm->tm2.max_lod = 0; + tm->tm2.cube_face = 0; + tm->tm2.pitch = (privTarget->uvStride >> 2) - 1; /* in DWords - 1 */ + + /* texture map 1: Y Plane */ + ++tm; + memset(tm, 0, sizeof(*tm)); + tm->tm0.v_ls_offset = 0; + tm->tm0.v_ls = 0; + tm->tm0.base_address = YOFFSET(privTarget); + tm->tm1.tile_walk = TILEWALK_XMAJOR; + tm->tm1.tiled_surface = 0; + tm->tm1.utilize_fence_regs = 1; + tm->tm1.texel_fmt = 0; + tm->tm1.surface_fmt = 1; + tm->tm1.width = w - 1; + tm->tm1.height = h - 1; + tm->tm2.depth = 0; + tm->tm2.max_lod = 0; + tm->tm2.cube_face = 0; + tm->tm2.pitch = (privTarget->yStride >> 2) - 1; /* in DWords - 1 */ + + /* texture map 2: U Plane */ + ++tm; + memset(tm, 0, sizeof(*tm)); + tm->tm0.v_ls_offset = 0; + tm->tm0.v_ls = 0; + tm->tm0.base_address = UOFFSET(privTarget); + tm->tm1.tile_walk = TILEWALK_XMAJOR; + tm->tm1.tiled_surface = 0; + tm->tm1.utilize_fence_regs = 1; + tm->tm1.texel_fmt = 0; + tm->tm1.surface_fmt = 1; + tm->tm1.width = (w >> 1) - 1; + tm->tm1.height = (h >> 1) - 1; + tm->tm2.depth = 0; + tm->tm2.max_lod = 0; + tm->tm2.cube_face = 0; + tm->tm2.pitch = (privTarget->uvStride >> 2) - 1; /* in DWords - 1 */ } #endif #if 0 -static void i915_yuv2rgb_sampler_state_buffer(XvMCSurface *surface) +static void i915_yuv2rgb_sampler_state_buffer(XvMCSurface * surface) { - struct i915_3dstate_sampler_state *sampler_state; - struct texture_sampler *ts; - i915XvMCSurface *privSurface = (i915XvMCSurface *)surface->privData; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)privSurface->privContext; - - /* 3DSATE_SAMPLER_STATE */ - sampler_state = (struct i915_3dstate_sampler_state *)pI915XvMC->ssb.map; - memset(sampler_state, 0, sizeof(*sampler_state)); - sampler_state->dw0.type = CMD_3D; - sampler_state->dw0.opcode = OPC_3DSTATE_SAMPLER_STATE; - sampler_state->dw0.length = 9; - sampler_state->dw1.sampler_masker = SAMPLER_SAMPLER0 | SAMPLER_SAMPLER1 | SAMPLER_SAMPLER2; - - /* Sampler 0 */ - ts = (struct texture_sampler *)(++sampler_state); - memset(ts, 0, sizeof(*ts)); - ts->ts0.reverse_gamma = 0; - ts->ts0.planar2packet = 1; - ts->ts0.color_conversion = 1; - ts->ts0.chromakey_index = 0; - ts->ts0.base_level = 0; - ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ - ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.lod_bias = 0; - ts->ts0.shadow_enable = 0; - ts->ts0.max_anisotropy = ANISORATIO_2; - ts->ts0.shadow_function = PREFILTEROP_ALWAYS; - ts->ts1.min_lod = 0; /* Maximum Mip Level */ - ts->ts1.kill_pixel = 0; - ts->ts1.keyed_texture_filter = 0; - ts->ts1.chromakey_enable = 0; - ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; - ts->ts1.normalized_coor = 0; - ts->ts1.map_index = 0; - ts->ts1.east_deinterlacer = 0; - ts->ts2.default_color = 0; - - /* Sampler 1 */ - ++ts; - memset(ts, 0, sizeof(*ts)); - ts->ts0.reverse_gamma = 0; - ts->ts0.planar2packet = 1; - ts->ts0.color_conversion = 1; - ts->ts0.chromakey_index = 0; - ts->ts0.base_level = 0; - ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ - ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.lod_bias = 0; - ts->ts0.shadow_enable = 0; - ts->ts0.max_anisotropy = ANISORATIO_2; - ts->ts0.shadow_function = PREFILTEROP_ALWAYS; - ts->ts1.min_lod = 0; /* Maximum Mip Level */ - ts->ts1.kill_pixel = 0; - ts->ts1.keyed_texture_filter = 0; - ts->ts1.chromakey_enable = 0; - ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; - ts->ts1.normalized_coor = 0; - ts->ts1.map_index = 1; - ts->ts1.east_deinterlacer = 0; - ts->ts2.default_color = 0; - - /* Sampler 2 */ - ++ts; - memset(ts, 0, sizeof(*ts)); - ts->ts0.reverse_gamma = 0; - ts->ts0.planar2packet = 1; - ts->ts0.color_conversion = 1; - ts->ts0.chromakey_index = 0; - ts->ts0.base_level = 0; - ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ - ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ - ts->ts0.lod_bias = 0; - ts->ts0.shadow_enable = 0; - ts->ts0.max_anisotropy = ANISORATIO_2; - ts->ts0.shadow_function = PREFILTEROP_ALWAYS; - ts->ts1.min_lod = 0; /* Maximum Mip Level */ - ts->ts1.kill_pixel = 0; - ts->ts1.keyed_texture_filter = 0; - ts->ts1.chromakey_enable = 0; - ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; - ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; - ts->ts1.normalized_coor = 0; - ts->ts1.map_index = 2; - ts->ts1.east_deinterlacer = 0; - ts->ts2.default_color = 0; + struct i915_3dstate_sampler_state *sampler_state; + struct texture_sampler *ts; + i915XvMCSurface *privSurface = (i915XvMCSurface *) surface->privData; + i915XvMCContext *pI915XvMC = + (i915XvMCContext *) privSurface->privContext; + + /* 3DSATE_SAMPLER_STATE */ + sampler_state = (struct i915_3dstate_sampler_state *)pI915XvMC->ssb.map; + memset(sampler_state, 0, sizeof(*sampler_state)); + sampler_state->dw0.type = CMD_3D; + sampler_state->dw0.opcode = OPC_3DSTATE_SAMPLER_STATE; + sampler_state->dw0.length = 9; + sampler_state->dw1.sampler_masker = + SAMPLER_SAMPLER0 | SAMPLER_SAMPLER1 | SAMPLER_SAMPLER2; + + /* Sampler 0 */ + ts = (struct texture_sampler *)(++sampler_state); + memset(ts, 0, sizeof(*ts)); + ts->ts0.reverse_gamma = 0; + ts->ts0.planar2packet = 1; + ts->ts0.color_conversion = 1; + ts->ts0.chromakey_index = 0; + ts->ts0.base_level = 0; + ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ + ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.lod_bias = 0; + ts->ts0.shadow_enable = 0; + ts->ts0.max_anisotropy = ANISORATIO_2; + ts->ts0.shadow_function = PREFILTEROP_ALWAYS; + ts->ts1.min_lod = 0; /* Maximum Mip Level */ + ts->ts1.kill_pixel = 0; + ts->ts1.keyed_texture_filter = 0; + ts->ts1.chromakey_enable = 0; + ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; + ts->ts1.normalized_coor = 0; + ts->ts1.map_index = 0; + ts->ts1.east_deinterlacer = 0; + ts->ts2.default_color = 0; + + /* Sampler 1 */ + ++ts; + memset(ts, 0, sizeof(*ts)); + ts->ts0.reverse_gamma = 0; + ts->ts0.planar2packet = 1; + ts->ts0.color_conversion = 1; + ts->ts0.chromakey_index = 0; + ts->ts0.base_level = 0; + ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ + ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.lod_bias = 0; + ts->ts0.shadow_enable = 0; + ts->ts0.max_anisotropy = ANISORATIO_2; + ts->ts0.shadow_function = PREFILTEROP_ALWAYS; + ts->ts1.min_lod = 0; /* Maximum Mip Level */ + ts->ts1.kill_pixel = 0; + ts->ts1.keyed_texture_filter = 0; + ts->ts1.chromakey_enable = 0; + ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; + ts->ts1.normalized_coor = 0; + ts->ts1.map_index = 1; + ts->ts1.east_deinterlacer = 0; + ts->ts2.default_color = 0; + + /* Sampler 2 */ + ++ts; + memset(ts, 0, sizeof(*ts)); + ts->ts0.reverse_gamma = 0; + ts->ts0.planar2packet = 1; + ts->ts0.color_conversion = 1; + ts->ts0.chromakey_index = 0; + ts->ts0.base_level = 0; + ts->ts0.mip_filter = MIPFILTER_NONE; /* NONE */ + ts->ts0.mag_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.min_filter = MAPFILTER_LINEAR; /* LINEAR */ + ts->ts0.lod_bias = 0; + ts->ts0.shadow_enable = 0; + ts->ts0.max_anisotropy = ANISORATIO_2; + ts->ts0.shadow_function = PREFILTEROP_ALWAYS; + ts->ts1.min_lod = 0; /* Maximum Mip Level */ + ts->ts1.kill_pixel = 0; + ts->ts1.keyed_texture_filter = 0; + ts->ts1.chromakey_enable = 0; + ts->ts1.tcx_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcy_control = TEXCOORDMODE_CLAMP; + ts->ts1.tcz_control = TEXCOORDMODE_CLAMP; + ts->ts1.normalized_coor = 0; + ts->ts1.map_index = 2; + ts->ts1.east_deinterlacer = 0; + ts->ts2.default_color = 0; } #endif #if 0 -static void i915_yuv2rgb_static_indirect_state_buffer(XvMCSurface *surface, - unsigned int dstaddr, - int dstpitch) +static void i915_yuv2rgb_static_indirect_state_buffer(XvMCSurface * surface, + unsigned int dstaddr, + int dstpitch) { - struct i915_3dstate_buffer_info *buffer_info; - struct i915_3dstate_dest_buffer_variables *dest_buffer_variables; - i915XvMCSurface *privSurface = (i915XvMCSurface *)surface->privData; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)privSurface->privContext; - - /* 3DSTATE_BUFFER_INFO */ - buffer_info = (struct i915_3dstate_buffer_info *)pI915XvMC->sis.map; - memset(buffer_info, 0, sizeof(*buffer_info)); - buffer_info->dw0.type = CMD_3D; - buffer_info->dw0.opcode = OPC_3DSTATE_BUFFER_INFO; - buffer_info->dw0.length = 1; - buffer_info->dw1.aux_id = 0; - buffer_info->dw1.buffer_id = BUFFERID_COLOR_BACK; - buffer_info->dw1.fence_regs = 1; - buffer_info->dw1.tiled_surface = 0; /* linear */ - buffer_info->dw1.walk = TILEWALK_XMAJOR; - buffer_info->dw1.pitch = dstpitch; - buffer_info->dw2.base_address = dstaddr; - - /* 3DSTATE_DEST_BUFFER_VARIABLES */ - dest_buffer_variables = (struct i915_3dstate_dest_buffer_variables *)(++buffer_info); - memset(dest_buffer_variables, 0, sizeof(*dest_buffer_variables)); - dest_buffer_variables->dw0.type = CMD_3D; - dest_buffer_variables->dw0.opcode = OPC_3DSTATE_DEST_BUFFER_VARIABLES; - dest_buffer_variables->dw0.length = 0; - dest_buffer_variables->dw1.dest_v_bias = 8; /* FIXME 0x1000 .5 ??? */ - dest_buffer_variables->dw1.dest_h_bias = 8; - dest_buffer_variables->dw1.color_fmt = COLORBUFFER_A8R8G8B8; /* FIXME */ + struct i915_3dstate_buffer_info *buffer_info; + struct i915_3dstate_dest_buffer_variables *dest_buffer_variables; + i915XvMCSurface *privSurface = (i915XvMCSurface *) surface->privData; + i915XvMCContext *pI915XvMC = + (i915XvMCContext *) privSurface->privContext; + + /* 3DSTATE_BUFFER_INFO */ + buffer_info = (struct i915_3dstate_buffer_info *)pI915XvMC->sis.map; + memset(buffer_info, 0, sizeof(*buffer_info)); + buffer_info->dw0.type = CMD_3D; + buffer_info->dw0.opcode = OPC_3DSTATE_BUFFER_INFO; + buffer_info->dw0.length = 1; + buffer_info->dw1.aux_id = 0; + buffer_info->dw1.buffer_id = BUFFERID_COLOR_BACK; + buffer_info->dw1.fence_regs = 1; + buffer_info->dw1.tiled_surface = 0; /* linear */ + buffer_info->dw1.walk = TILEWALK_XMAJOR; + buffer_info->dw1.pitch = dstpitch; + buffer_info->dw2.base_address = dstaddr; + + /* 3DSTATE_DEST_BUFFER_VARIABLES */ + dest_buffer_variables = + (struct i915_3dstate_dest_buffer_variables *)(++buffer_info); + memset(dest_buffer_variables, 0, sizeof(*dest_buffer_variables)); + dest_buffer_variables->dw0.type = CMD_3D; + dest_buffer_variables->dw0.opcode = OPC_3DSTATE_DEST_BUFFER_VARIABLES; + dest_buffer_variables->dw0.length = 0; + dest_buffer_variables->dw1.dest_v_bias = 8; /* FIXME 0x1000 .5 ??? */ + dest_buffer_variables->dw1.dest_h_bias = 8; + dest_buffer_variables->dw1.color_fmt = COLORBUFFER_A8R8G8B8; /* FIXME */ } #endif #if 0 -static void i915_yuv2rgb_pixel_shader_program_buffer(XvMCSurface *surface) +static void i915_yuv2rgb_pixel_shader_program_buffer(XvMCSurface * surface) { - struct i915_3dstate_pixel_shader_program *pixel_shader_program; - i915XvMCSurface *privSurface = (i915XvMCSurface *)surface->privData; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)privSurface->privContext; - unsigned int *inst; - unsigned int dest, src0, src1; - - /* Shader 0 */ - pixel_shader_program = (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map; - memset(pixel_shader_program, 0, sizeof(*pixel_shader_program)); - pixel_shader_program->dw0.type = CMD_3D; - pixel_shader_program->dw0.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; - pixel_shader_program->dw0.retain = 0; - pixel_shader_program->dw0.length = 23; - /* dcl t0.xy */ - inst = (unsigned int*)(++pixel_shader_program); - i915_inst_decl(inst, REG_TYPE_T, T_TEX0, D0_CHANNEL_XY); - /* dcl t1.xy */ - inst += 3; - i915_inst_decl(inst, REG_TYPE_T, T_TEX1, D0_CHANNEL_XY); - /* dcl_2D s0 */ - inst += 3; - i915_inst_decl(inst, REG_TYPE_S, 0, D0_SAMPLE_TYPE_2D); - /* dcl_2D s1 */ - inst += 3; - i915_inst_decl(inst, REG_TYPE_S, 1, D0_SAMPLE_TYPE_2D); - /* dcl_2D s2 */ - inst += 3; - i915_inst_decl(inst, REG_TYPE_S, 2, D0_SAMPLE_TYPE_2D); - /* texld r0 t1 s0 */ - inst += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_T, 1); /* COORD */ - src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ - i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); - /* texld r0 t0 s1 */ - inst += 3; - dest = UREG(REG_TYPE_R, 0); - src0 = UREG(REG_TYPE_T, 0); /* COORD */ - src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ - i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); - /* texld oC t1 s2 */ - inst += 3; - dest = UREG(REG_TYPE_OC, 0); - src0 = UREG(REG_TYPE_T, 1); /* COORD */ - src1 = UREG(REG_TYPE_S, 2); /* SAMPLER */ - i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); + struct i915_3dstate_pixel_shader_program *pixel_shader_program; + i915XvMCSurface *privSurface = (i915XvMCSurface *) surface->privData; + i915XvMCContext *pI915XvMC = + (i915XvMCContext *) privSurface->privContext; + unsigned int *inst; + unsigned int dest, src0, src1; + + /* Shader 0 */ + pixel_shader_program = + (struct i915_3dstate_pixel_shader_program *)pI915XvMC->psp.map; + memset(pixel_shader_program, 0, sizeof(*pixel_shader_program)); + pixel_shader_program->dw0.type = CMD_3D; + pixel_shader_program->dw0.opcode = OPC_3DSTATE_PIXEL_SHADER_PROGRAM; + pixel_shader_program->dw0.retain = 0; + pixel_shader_program->dw0.length = 23; + /* dcl t0.xy */ + inst = (unsigned int *)(++pixel_shader_program); + i915_inst_decl(inst, REG_TYPE_T, T_TEX0, D0_CHANNEL_XY); + /* dcl t1.xy */ + inst += 3; + i915_inst_decl(inst, REG_TYPE_T, T_TEX1, D0_CHANNEL_XY); + /* dcl_2D s0 */ + inst += 3; + i915_inst_decl(inst, REG_TYPE_S, 0, D0_SAMPLE_TYPE_2D); + /* dcl_2D s1 */ + inst += 3; + i915_inst_decl(inst, REG_TYPE_S, 1, D0_SAMPLE_TYPE_2D); + /* dcl_2D s2 */ + inst += 3; + i915_inst_decl(inst, REG_TYPE_S, 2, D0_SAMPLE_TYPE_2D); + /* texld r0 t1 s0 */ + inst += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_T, 1); /* COORD */ + src1 = UREG(REG_TYPE_S, 0); /* SAMPLER */ + i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); + /* texld r0 t0 s1 */ + inst += 3; + dest = UREG(REG_TYPE_R, 0); + src0 = UREG(REG_TYPE_T, 0); /* COORD */ + src1 = UREG(REG_TYPE_S, 1); /* SAMPLER */ + i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); + /* texld oC t1 s2 */ + inst += 3; + dest = UREG(REG_TYPE_OC, 0); + src0 = UREG(REG_TYPE_T, 1); /* COORD */ + src1 = UREG(REG_TYPE_S, 2); /* SAMPLER */ + i915_inst_texld(inst, T0_TEXLD, dest, src0, src1); } #endif #if 0 -static void i915_yuv2rgb_proc(XvMCSurface *surface) +static void i915_yuv2rgb_proc(XvMCSurface * surface) { - i915XvMCSurface *privSurface = (i915XvMCSurface *)surface->privData; - i915XvMCContext *pI915XvMC = (i915XvMCContext *)privSurface->privContext; - struct i915_3dstate_load_state_immediate_1 *load_state_immediate_1 = NULL; - struct s2_dword *s2 = NULL; - struct s3_dword *s3 = NULL; - struct s4_dword *s4 = NULL; - struct s5_dword *s5 = NULL; - struct s6_dword *s6 = NULL; - struct s7_dword *s7 = NULL; - struct i915_3dstate_scissor_rectangle scissor_rectangle; - struct i915_3dstate_load_indirect *load_indirect = NULL; - sis_state *sis = NULL; - ssb_state *ssb = NULL; - msb_state *msb = NULL; - psp_state *psp = NULL; - struct i915_3dprimitive *_3dprimitive = NULL; - struct vertex_data *vd = NULL; - unsigned int size; - void *base = NULL; - - /* 3DSTATE_LOAD_STATE_IMMEDIATE_1 */ - size = sizeof(*load_state_immediate_1) + sizeof(*s2) + sizeof(*s3) + - sizeof(*s4) + sizeof(*s5) + sizeof(*s6) + sizeof(*s7); - base = calloc(1, size); - load_state_immediate_1 = (struct i915_3dstate_load_state_immediate_1 *)base; - load_state_immediate_1->dw0.type = CMD_3D; - load_state_immediate_1->dw0.opcode = OPC_3DSTATE_LOAD_STATE_IMMEDIATE_1; - load_state_immediate_1->dw0.load_s2 = 1; - load_state_immediate_1->dw0.load_s3 = 1; - load_state_immediate_1->dw0.load_s4 = 1; - load_state_immediate_1->dw0.load_s5 = 1; - load_state_immediate_1->dw0.load_s6 = 1; - load_state_immediate_1->dw0.load_s7 = 1; - load_state_immediate_1->dw0.length = 5; - - s2 = (struct s2_dword *)(++load_state_immediate_1); - s2->set0_texcoord_fmt = TEXCOORDFMT_2FP; - s2->set1_texcoord_fmt = TEXCOORDFMT_2FP; - s2->set2_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - s2->set3_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - s2->set4_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - s2->set5_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - s2->set6_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - s2->set7_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; - - s3 = (struct s3_dword *)(++s2); - s4 = (struct s4_dword *)(++s3); - s4->position_mask = VERTEXHAS_XY; - s4->cull_mode = CULLMODE_NONE; - s4->color_shade_mode = SHADEMODE_FLAT; - s4->specular_shade_mode = SHADEMODE_FLAT; - s4->fog_shade_mode = SHADEMODE_FLAT; - s4->alpha_shade_mode = SHADEMODE_FLAT; - s4->line_width = 0x2; /* FIXME: 1.0??? */ - s4->point_width = 0x1; - - s5 = (struct s5_dword *)(++s4); - s6 = (struct s6_dword *)(++s5); - s6->src_blend_factor = 1; - s6->dest_blend_factor = 1; - s6->color_buffer_write = 1; - - s7 = (struct s7_dword *)(++s6); - intelBatchbufferData(base, size, 0); - free(base); - - /* 3DSTATE_3DSTATE_SCISSOR_RECTANGLE */ - scissor_rectangle.dw0.type = CMD_3D; - scissor_rectangle.dw0.opcode = OPC_3DSTATE_SCISSOR_RECTANGLE; - scissor_rectangle.dw0.length = 1; - scissor_rectangle.dw1.min_x = 0; - scissor_rectangle.dw1.min_y = 0; - scissor_rectangle.dw2.max_x = 2047; - scissor_rectangle.dw2.max_y = 2047; - intelBatchbufferData(&scissor_rectangle, sizeof(scissor_rectangle), 0); - - /* 3DSTATE_LOAD_INDIRECT */ - size = sizeof(*load_indirect) + sizeof(*sis) + sizeof(*ssb) + sizeof(*msb) + sizeof(*psp); - base = calloc(1, size); - load_indirect = (struct i915_3dstate_load_indirect *)base; - load_indirect->dw0.type = CMD_3D; - load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; - load_indirect->dw0.mem_select = 1; /* Bearlake only */ - load_indirect->dw0.block_mask = BLOCK_SIS | BLOCK_SSB | BLOCK_MSB | BLOCK_PSP; - load_indirect->dw0.length = 7; - - /* SIS */ - sis = (sis_state *)(++load_indirect); - sis->dw0.valid = 1; - sis->dw0.buffer_address = pI915XvMC->sis.offset; - sis->dw1.length = ((sizeof(struct i915_3dstate_buffer_info) + - sizeof(struct i915_3dstate_dest_buffer_variables)) >> 2) - 1; - - /* SSB */ - ssb = (ssb_state *)(++sis); - ssb->dw0.valid = 1; - ssb->dw0.buffer_address = pI915XvMC->ssb.offset; - ssb->dw1.length = ((sizeof(struct i915_3dstate_sampler_state) + - sizeof(struct texture_sampler) * 3) >> 2) - 1; - - /* MSB */ - msb = (msb_state *)(++ssb); - msb->dw0.valid = 1; - msb->dw0.buffer_address = pI915XvMC->msb.offset; - msb->dw1.length = ((sizeof(struct i915_3dstate_map_state) + - sizeof(struct texture_map) * 3) >> 2) - 1; - - /* PSP */ - psp = (psp_state *)(++msb); - psp->dw0.valid = 1; - psp->dw0.buffer_address = pI915XvMC->psp.offset; - psp->dw1.length = ((sizeof(struct i915_3dstate_pixel_shader_program) + - sizeof(union shader_inst)) >> 2) - 1; - - intelBatchbufferData(base, size, 0); - free(base); - - /* 3DPRIMITIVE */ - size = sizeof(*_3dprimitive) + sizeof(*vd) * 3; - base = calloc(1, size); - _3dprimitive = (struct i915_3dprimitive *)base; - _3dprimitive->dw0.inline_prim.type = CMD_3D; - _3dprimitive->dw0.inline_prim.opcode = OPC_3DPRIMITIVE; - _3dprimitive->dw0.inline_prim.vertex_location = VERTEX_INLINE; - _3dprimitive->dw0.inline_prim.prim = PRIM_RECTLIST; - _3dprimitive->dw0.inline_prim.length = size - 2; - - vd = (struct vertex_data *)(++_3dprimitive); - vd->x = 0; /* FIXME!!! */ - vd->x = 0; /* FIXME */ - vd->tc0.tcx = 0; - vd->tc0.tcy = 0; - vd->tc1.tcx = 0; - vd->tc1.tcy = 0; - - ++vd; - vd->x = 0; /* FIXME!!! */ - vd->x = 0; /* FIXME */ - vd->tc0.tcx = 0; - vd->tc0.tcy = 0; - vd->tc1.tcx = 0; - vd->tc1.tcy = 0; - - ++vd; - vd->x = 0; /* FIXME!!! */ - vd->x = 0; /* FIXME */ - vd->tc0.tcx = 0; - vd->tc0.tcy = 0; - vd->tc1.tcx = 0; - vd->tc1.tcy = 0; - - intelBatchbufferData(base, size, 0); - free(base); + i915XvMCSurface *privSurface = (i915XvMCSurface *) surface->privData; + i915XvMCContext *pI915XvMC = + (i915XvMCContext *) privSurface->privContext; + struct i915_3dstate_load_state_immediate_1 *load_state_immediate_1 = + NULL; + struct s2_dword *s2 = NULL; + struct s3_dword *s3 = NULL; + struct s4_dword *s4 = NULL; + struct s5_dword *s5 = NULL; + struct s6_dword *s6 = NULL; + struct s7_dword *s7 = NULL; + struct i915_3dstate_scissor_rectangle scissor_rectangle; + struct i915_3dstate_load_indirect *load_indirect = NULL; + sis_state *sis = NULL; + ssb_state *ssb = NULL; + msb_state *msb = NULL; + psp_state *psp = NULL; + struct i915_3dprimitive *_3dprimitive = NULL; + struct vertex_data *vd = NULL; + unsigned int size; + void *base = NULL; + + /* 3DSTATE_LOAD_STATE_IMMEDIATE_1 */ + size = sizeof(*load_state_immediate_1) + sizeof(*s2) + sizeof(*s3) + + sizeof(*s4) + sizeof(*s5) + sizeof(*s6) + sizeof(*s7); + base = calloc(1, size); + load_state_immediate_1 = + (struct i915_3dstate_load_state_immediate_1 *)base; + load_state_immediate_1->dw0.type = CMD_3D; + load_state_immediate_1->dw0.opcode = OPC_3DSTATE_LOAD_STATE_IMMEDIATE_1; + load_state_immediate_1->dw0.load_s2 = 1; + load_state_immediate_1->dw0.load_s3 = 1; + load_state_immediate_1->dw0.load_s4 = 1; + load_state_immediate_1->dw0.load_s5 = 1; + load_state_immediate_1->dw0.load_s6 = 1; + load_state_immediate_1->dw0.load_s7 = 1; + load_state_immediate_1->dw0.length = 5; + + s2 = (struct s2_dword *)(++load_state_immediate_1); + s2->set0_texcoord_fmt = TEXCOORDFMT_2FP; + s2->set1_texcoord_fmt = TEXCOORDFMT_2FP; + s2->set2_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + s2->set3_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + s2->set4_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + s2->set5_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + s2->set6_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + s2->set7_texcoord_fmt = TEXCOORDFMT_NOT_PRESENT; + + s3 = (struct s3_dword *)(++s2); + s4 = (struct s4_dword *)(++s3); + s4->position_mask = VERTEXHAS_XY; + s4->cull_mode = CULLMODE_NONE; + s4->color_shade_mode = SHADEMODE_FLAT; + s4->specular_shade_mode = SHADEMODE_FLAT; + s4->fog_shade_mode = SHADEMODE_FLAT; + s4->alpha_shade_mode = SHADEMODE_FLAT; + s4->line_width = 0x2; /* FIXME: 1.0??? */ + s4->point_width = 0x1; + + s5 = (struct s5_dword *)(++s4); + s6 = (struct s6_dword *)(++s5); + s6->src_blend_factor = 1; + s6->dest_blend_factor = 1; + s6->color_buffer_write = 1; + + s7 = (struct s7_dword *)(++s6); + intelBatchbufferData(base, size, 0); + free(base); + + /* 3DSTATE_3DSTATE_SCISSOR_RECTANGLE */ + scissor_rectangle.dw0.type = CMD_3D; + scissor_rectangle.dw0.opcode = OPC_3DSTATE_SCISSOR_RECTANGLE; + scissor_rectangle.dw0.length = 1; + scissor_rectangle.dw1.min_x = 0; + scissor_rectangle.dw1.min_y = 0; + scissor_rectangle.dw2.max_x = 2047; + scissor_rectangle.dw2.max_y = 2047; + intelBatchbufferData(&scissor_rectangle, sizeof(scissor_rectangle), 0); + + /* 3DSTATE_LOAD_INDIRECT */ + size = + sizeof(*load_indirect) + sizeof(*sis) + sizeof(*ssb) + + sizeof(*msb) + sizeof(*psp); + base = calloc(1, size); + load_indirect = (struct i915_3dstate_load_indirect *)base; + load_indirect->dw0.type = CMD_3D; + load_indirect->dw0.opcode = OPC_3DSTATE_LOAD_INDIRECT; + load_indirect->dw0.mem_select = 1; /* Bearlake only */ + load_indirect->dw0.block_mask = + BLOCK_SIS | BLOCK_SSB | BLOCK_MSB | BLOCK_PSP; + load_indirect->dw0.length = 7; + + /* SIS */ + sis = (sis_state *) (++load_indirect); + sis->dw0.valid = 1; + sis->dw0.buffer_address = pI915XvMC->sis.offset; + sis->dw1.length = ((sizeof(struct i915_3dstate_buffer_info) + + sizeof(struct i915_3dstate_dest_buffer_variables)) + >> 2) - 1; + + /* SSB */ + ssb = (ssb_state *) (++sis); + ssb->dw0.valid = 1; + ssb->dw0.buffer_address = pI915XvMC->ssb.offset; + ssb->dw1.length = ((sizeof(struct i915_3dstate_sampler_state) + + sizeof(struct texture_sampler) * 3) >> 2) - 1; + + /* MSB */ + msb = (msb_state *) (++ssb); + msb->dw0.valid = 1; + msb->dw0.buffer_address = pI915XvMC->msb.offset; + msb->dw1.length = ((sizeof(struct i915_3dstate_map_state) + + sizeof(struct texture_map) * 3) >> 2) - 1; + + /* PSP */ + psp = (psp_state *) (++msb); + psp->dw0.valid = 1; + psp->dw0.buffer_address = pI915XvMC->psp.offset; + psp->dw1.length = ((sizeof(struct i915_3dstate_pixel_shader_program) + + sizeof(union shader_inst)) >> 2) - 1; + + intelBatchbufferData(base, size, 0); + free(base); + + /* 3DPRIMITIVE */ + size = sizeof(*_3dprimitive) + sizeof(*vd) * 3; + base = calloc(1, size); + _3dprimitive = (struct i915_3dprimitive *)base; + _3dprimitive->dw0.inline_prim.type = CMD_3D; + _3dprimitive->dw0.inline_prim.opcode = OPC_3DPRIMITIVE; + _3dprimitive->dw0.inline_prim.vertex_location = VERTEX_INLINE; + _3dprimitive->dw0.inline_prim.prim = PRIM_RECTLIST; + _3dprimitive->dw0.inline_prim.length = size - 2; + + vd = (struct vertex_data *)(++_3dprimitive); + vd->x = 0; /* FIXME!!! */ + vd->x = 0; /* FIXME */ + vd->tc0.tcx = 0; + vd->tc0.tcy = 0; + vd->tc1.tcx = 0; + vd->tc1.tcy = 0; + + ++vd; + vd->x = 0; /* FIXME!!! */ + vd->x = 0; /* FIXME */ + vd->tc0.tcx = 0; + vd->tc0.tcy = 0; + vd->tc1.tcx = 0; + vd->tc1.tcy = 0; + + ++vd; + vd->x = 0; /* FIXME!!! */ + vd->x = 0; /* FIXME */ + vd->tc0.tcx = 0; + vd->tc0.tcy = 0; + vd->tc1.tcx = 0; + vd->tc1.tcy = 0; + + intelBatchbufferData(base, size, 0); + free(base); } #endif /* * Function: i915_release_resource */ -static void i915_release_resource(Display *display, XvMCContext *context) +static void i915_release_resource(Display * display, XvMCContext * context) { - i915XvMCContext *pI915XvMC; + i915XvMCContext *pI915XvMC; - if (!(pI915XvMC = context->privData)) - return; + if (!(pI915XvMC = context->privData)) + return; - pI915XvMC->ref--; - i915_xvmc_unmap_buffers(pI915XvMC); + pI915XvMC->ref--; + i915_xvmc_unmap_buffers(pI915XvMC); - free(pI915XvMC); - context->privData = NULL; + free(pI915XvMC); + context->privData = NULL; } -static Status i915_xvmc_mc_create_context(Display *display, XvMCContext *context, - int priv_count, CARD32 *priv_data) +static Status i915_xvmc_mc_create_context(Display * display, + XvMCContext * context, int priv_count, + CARD32 * priv_data) { - i915XvMCContext *pI915XvMC = NULL; - I915XvMCCreateContextRec *tmpComm = NULL; - - XVMC_DBG("%s\n", __FUNCTION__); - - if (priv_count != (sizeof(I915XvMCCreateContextRec) >> 2)) { - XVMC_ERR("_xvmc_create_context() returned incorrect data size!"); - XVMC_INFO("\tExpected %d, got %d", - (int)(sizeof(I915XvMCCreateContextRec) >> 2),priv_count); - _xvmc_destroy_context(display, context); - XFree(priv_data); - context->privData = NULL; - return BadValue; - } - - context->privData = (void *)calloc(1, sizeof(i915XvMCContext)); - if (!context->privData) { - XVMC_ERR("Unable to allocate resources for XvMC context."); - return BadAlloc; - } - pI915XvMC = (i915XvMCContext *)context->privData; - - tmpComm = (I915XvMCCreateContextRec *)priv_data; - pI915XvMC->ctxno = tmpComm->ctxno; - pI915XvMC->deviceID = tmpComm->deviceID; - pI915XvMC->sis.handle = tmpComm->sis.handle; - pI915XvMC->sis.offset = tmpComm->sis.offset; - pI915XvMC->sis.size = tmpComm->sis.size; - pI915XvMC->ssb.handle = tmpComm->ssb.handle; - pI915XvMC->ssb.offset = tmpComm->ssb.offset; - pI915XvMC->ssb.size = tmpComm->ssb.size; - pI915XvMC->msb.handle = tmpComm->msb.handle; - pI915XvMC->msb.offset = tmpComm->msb.offset; - pI915XvMC->msb.size = tmpComm->msb.size; - pI915XvMC->psp.handle = tmpComm->psp.handle; - pI915XvMC->psp.offset = tmpComm->psp.offset; - pI915XvMC->psp.size = tmpComm->psp.size; - pI915XvMC->psc.handle = tmpComm->psc.handle; - pI915XvMC->psc.offset = tmpComm->psc.offset; - pI915XvMC->psc.size = tmpComm->psc.size; - - if (pI915XvMC->deviceID == PCI_CHIP_I915_G || - pI915XvMC->deviceID == PCI_CHIP_I915_GM) { - pI915XvMC->sis.bus_addr = tmpComm->sis.bus_addr; - pI915XvMC->ssb.bus_addr = tmpComm->ssb.bus_addr; - pI915XvMC->msb.bus_addr = tmpComm->msb.bus_addr; - pI915XvMC->psp.bus_addr = tmpComm->psp.bus_addr; - pI915XvMC->psc.bus_addr = tmpComm->psc.bus_addr; - } - - pI915XvMC->corrdata.handle = tmpComm->corrdata.handle; - pI915XvMC->corrdata.offset = tmpComm->corrdata.offset; - pI915XvMC->corrdata.size = tmpComm->corrdata.size; - - /* Must free the private data we were passed from X */ - XFree(priv_data); - priv_data = NULL; - - if (i915_xvmc_map_buffers(pI915XvMC)) { - i915_xvmc_unmap_buffers(pI915XvMC); - free(pI915XvMC); - context->privData = NULL; - return BadAlloc; - } - - /* Initialize private context values */ - pI915XvMC->yStride = STRIDE(context->width); - pI915XvMC->uvStride = STRIDE(context->width >> 1); - pI915XvMC->haveXv = 0; - pI915XvMC->dual_prime = 0; - pI915XvMC->last_flip = 0; - pI915XvMC->port = context->port; - pI915XvMC->ref = 1; - - /* pre-init state buffers */ - i915_mc_one_time_context_init(context); - i915_mc_one_time_state_init(context); - - i915_mc_static_indirect_state_init(context); - - i915_mc_map_state_init(context); - - i915_mc_load_indirect_render_init(context); - return Success; + i915XvMCContext *pI915XvMC = NULL; + I915XvMCCreateContextRec *tmpComm = NULL; + + XVMC_DBG("%s\n", __FUNCTION__); + + if (priv_count != (sizeof(I915XvMCCreateContextRec) >> 2)) { + XVMC_ERR + ("_xvmc_create_context() returned incorrect data size!"); + XVMC_INFO("\tExpected %d, got %d", + (int)(sizeof(I915XvMCCreateContextRec) >> 2), + priv_count); + _xvmc_destroy_context(display, context); + XFree(priv_data); + context->privData = NULL; + return BadValue; + } + + context->privData = (void *)calloc(1, sizeof(i915XvMCContext)); + if (!context->privData) { + XVMC_ERR("Unable to allocate resources for XvMC context."); + return BadAlloc; + } + pI915XvMC = (i915XvMCContext *) context->privData; + + tmpComm = (I915XvMCCreateContextRec *) priv_data; + pI915XvMC->ctxno = tmpComm->ctxno; + pI915XvMC->deviceID = tmpComm->deviceID; + pI915XvMC->sis.handle = tmpComm->sis.handle; + pI915XvMC->sis.offset = tmpComm->sis.offset; + pI915XvMC->sis.size = tmpComm->sis.size; + pI915XvMC->ssb.handle = tmpComm->ssb.handle; + pI915XvMC->ssb.offset = tmpComm->ssb.offset; + pI915XvMC->ssb.size = tmpComm->ssb.size; + pI915XvMC->msb.handle = tmpComm->msb.handle; + pI915XvMC->msb.offset = tmpComm->msb.offset; + pI915XvMC->msb.size = tmpComm->msb.size; + pI915XvMC->psp.handle = tmpComm->psp.handle; + pI915XvMC->psp.offset = tmpComm->psp.offset; + pI915XvMC->psp.size = tmpComm->psp.size; + pI915XvMC->psc.handle = tmpComm->psc.handle; + pI915XvMC->psc.offset = tmpComm->psc.offset; + pI915XvMC->psc.size = tmpComm->psc.size; + + if (pI915XvMC->deviceID == PCI_CHIP_I915_G || + pI915XvMC->deviceID == PCI_CHIP_I915_GM) { + pI915XvMC->sis.bus_addr = tmpComm->sis.bus_addr; + pI915XvMC->ssb.bus_addr = tmpComm->ssb.bus_addr; + pI915XvMC->msb.bus_addr = tmpComm->msb.bus_addr; + pI915XvMC->psp.bus_addr = tmpComm->psp.bus_addr; + pI915XvMC->psc.bus_addr = tmpComm->psc.bus_addr; + } + + pI915XvMC->corrdata.handle = tmpComm->corrdata.handle; + pI915XvMC->corrdata.offset = tmpComm->corrdata.offset; + pI915XvMC->corrdata.size = tmpComm->corrdata.size; + + /* Must free the private data we were passed from X */ + XFree(priv_data); + priv_data = NULL; + + if (i915_xvmc_map_buffers(pI915XvMC)) { + i915_xvmc_unmap_buffers(pI915XvMC); + free(pI915XvMC); + context->privData = NULL; + return BadAlloc; + } + + /* Initialize private context values */ + pI915XvMC->yStride = STRIDE(context->width); + pI915XvMC->uvStride = STRIDE(context->width >> 1); + pI915XvMC->haveXv = 0; + pI915XvMC->dual_prime = 0; + pI915XvMC->last_flip = 0; + pI915XvMC->port = context->port; + pI915XvMC->ref = 1; + + /* pre-init state buffers */ + i915_mc_one_time_context_init(context); + i915_mc_one_time_state_init(context); + + i915_mc_static_indirect_state_init(context); + + i915_mc_map_state_init(context); + + i915_mc_load_indirect_render_init(context); + return Success; } -static int i915_xvmc_mc_destroy_context(Display *display, XvMCContext *context) +static int i915_xvmc_mc_destroy_context(Display * display, + XvMCContext * context) { - i915XvMCContext *pI915XvMC; + i915XvMCContext *pI915XvMC; - if (!(pI915XvMC = context->privData)) - return XvMCBadContext; + if (!(pI915XvMC = context->privData)) + return XvMCBadContext; - /* Pass Control to the X server to destroy the drm_context_t */ - i915_release_resource(display,context); + /* Pass Control to the X server to destroy the drm_context_t */ + i915_release_resource(display, context); - free(one_time_load_state_imm1); - free(one_time_load_indirect); - free(mc_render_load_indirect); - return Success; + free(one_time_load_state_imm1); + free(one_time_load_indirect); + free(mc_render_load_indirect); + return Success; } -static Status i915_xvmc_mc_create_surface(Display *display, - XvMCContext *context, XvMCSurface *surface, int priv_count, - CARD32 *priv_data) +static Status i915_xvmc_mc_create_surface(Display * display, + XvMCContext * context, + XvMCSurface * surface, int priv_count, + CARD32 * priv_data) { - i915XvMCContext *pI915XvMC; - i915XvMCSurface *pI915Surface; - I915XvMCCreateSurfaceRec *tmpComm = NULL; - - if (!(pI915XvMC = context->privData)) - return XvMCBadContext; - - XVMC_DBG("%s\n", __FUNCTION__); - - if (priv_count != (sizeof(I915XvMCCreateSurfaceRec) >> 2)) { - XVMC_ERR("_xvmc_create_surface() returned incorrect data size!"); - XVMC_INFO("\tExpected %d, got %d", - (int)(sizeof(I915XvMCCreateSurfaceRec) >> 2), priv_count); - _xvmc_destroy_surface(display, surface); - XFree(priv_data); - return BadAlloc; - } - - PPTHREAD_MUTEX_LOCK(); - surface->privData = (i915XvMCSurface *)malloc(sizeof(i915XvMCSurface)); - - if (!(pI915Surface = surface->privData)) { - PPTHREAD_MUTEX_UNLOCK(); - return BadAlloc; - } - - /* Initialize private values */ - pI915Surface->last_render = 0; - pI915Surface->last_flip = 0; - pI915Surface->yStride = pI915XvMC->yStride; - pI915Surface->uvStride = pI915XvMC->uvStride; - pI915Surface->width = context->width; - pI915Surface->height = context->height; - pI915Surface->privContext = pI915XvMC; - pI915Surface->privSubPic = NULL; - pI915Surface->srf.map = NULL; - - tmpComm = (I915XvMCCreateSurfaceRec *)priv_data; - - pI915Surface->srfNo = tmpComm->srfno; - pI915Surface->srf.handle = tmpComm->srf.handle; - pI915Surface->srf.offset = tmpComm->srf.offset; - pI915Surface->srf.size = tmpComm->srf.size; - - XFree(priv_data); - - if (drmMap(xvmc_driver->fd, - pI915Surface->srf.handle, - pI915Surface->srf.size, - (drmAddress *)&pI915Surface->srf.map) != 0) { - XVMC_ERR("mapping surface memory failed!\n"); - _xvmc_destroy_surface(display, surface); - free(pI915Surface); - surface->privData = NULL; - PPTHREAD_MUTEX_UNLOCK(); - return BadAlloc; - } - - pI915XvMC->ref++; - PPTHREAD_MUTEX_UNLOCK(); - return 0; + i915XvMCContext *pI915XvMC; + i915XvMCSurface *pI915Surface; + I915XvMCCreateSurfaceRec *tmpComm = NULL; + + if (!(pI915XvMC = context->privData)) + return XvMCBadContext; + + XVMC_DBG("%s\n", __FUNCTION__); + + if (priv_count != (sizeof(I915XvMCCreateSurfaceRec) >> 2)) { + XVMC_ERR + ("_xvmc_create_surface() returned incorrect data size!"); + XVMC_INFO("\tExpected %d, got %d", + (int)(sizeof(I915XvMCCreateSurfaceRec) >> 2), + priv_count); + _xvmc_destroy_surface(display, surface); + XFree(priv_data); + return BadAlloc; + } + + PPTHREAD_MUTEX_LOCK(); + surface->privData = (i915XvMCSurface *) malloc(sizeof(i915XvMCSurface)); + + if (!(pI915Surface = surface->privData)) { + PPTHREAD_MUTEX_UNLOCK(); + return BadAlloc; + } + + /* Initialize private values */ + pI915Surface->last_render = 0; + pI915Surface->last_flip = 0; + pI915Surface->yStride = pI915XvMC->yStride; + pI915Surface->uvStride = pI915XvMC->uvStride; + pI915Surface->width = context->width; + pI915Surface->height = context->height; + pI915Surface->privContext = pI915XvMC; + pI915Surface->privSubPic = NULL; + pI915Surface->srf.map = NULL; + + tmpComm = (I915XvMCCreateSurfaceRec *) priv_data; + + pI915Surface->srfNo = tmpComm->srfno; + pI915Surface->srf.handle = tmpComm->srf.handle; + pI915Surface->srf.offset = tmpComm->srf.offset; + pI915Surface->srf.size = tmpComm->srf.size; + + XFree(priv_data); + + if (drmMap(xvmc_driver->fd, + pI915Surface->srf.handle, + pI915Surface->srf.size, + (drmAddress *) & pI915Surface->srf.map) != 0) { + XVMC_ERR("mapping surface memory failed!\n"); + _xvmc_destroy_surface(display, surface); + free(pI915Surface); + surface->privData = NULL; + PPTHREAD_MUTEX_UNLOCK(); + return BadAlloc; + } + + pI915XvMC->ref++; + PPTHREAD_MUTEX_UNLOCK(); + return 0; } - -static int i915_xvmc_mc_destroy_surface(Display *display, XvMCSurface *surface) +static int i915_xvmc_mc_destroy_surface(Display * display, + XvMCSurface * surface) { - i915XvMCSurface *pI915Surface; - i915XvMCContext *pI915XvMC; + i915XvMCSurface *pI915Surface; + i915XvMCContext *pI915XvMC; - if (!display || !surface) - return BadValue; + if (!display || !surface) + return BadValue; - if (!(pI915Surface = surface->privData)) - return XvMCBadSurface; + if (!(pI915Surface = surface->privData)) + return XvMCBadSurface; - if (!(pI915XvMC = pI915Surface->privContext)) - return XvMCBadSurface; + if (!(pI915XvMC = pI915Surface->privContext)) + return XvMCBadSurface; - if (pI915Surface->last_flip) - XvMCSyncSurface(display,surface); + if (pI915Surface->last_flip) + XvMCSyncSurface(display, surface); - if (pI915Surface->srf.map) - drmUnmap(pI915Surface->srf.map, pI915Surface->srf.size); + if (pI915Surface->srf.map) + drmUnmap(pI915Surface->srf.map, pI915Surface->srf.size); - free(pI915Surface); - surface->privData = NULL; - pI915XvMC->ref--; + free(pI915Surface); + surface->privData = NULL; + pI915XvMC->ref--; - return Success; + return Success; } - -static int i915_xvmc_mc_render_surface(Display *display, XvMCContext *context, - unsigned int picture_structure, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - unsigned int flags, - unsigned int num_macroblocks, - unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, - XvMCBlockArray *blocks) +static int i915_xvmc_mc_render_surface(Display * display, XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks) { - int i; - int picture_coding_type = MPEG_I_PICTURE; - /* correction data buffer */ - char *corrdata_ptr; - int corrdata_size = 0; - - /* Block Pointer */ - short *block_ptr; - /* Current Macroblock Pointer */ - XvMCMacroBlock *mb; - - intel_xvmc_context_ptr intel_ctx; - - i915XvMCSurface *privTarget = NULL; - i915XvMCSurface *privFuture = NULL; - i915XvMCSurface *privPast = NULL; - i915XvMCContext *pI915XvMC = NULL; - - XVMC_DBG("%s\n", __FUNCTION__); - - /* Check Parameters for validity */ - if (!display || !context || !target_surface) { - XVMC_ERR("Invalid Display, Context or Target!"); - return BadValue; - } - - if (!num_macroblocks) - return Success; - - if (!macroblock_array || !blocks) { - XVMC_ERR("Invalid block data!"); - return BadValue; - } - - if (macroblock_array->num_blocks < (num_macroblocks + first_macroblock)) { - XVMC_ERR("Too many macroblocks requested for MB array size."); - return BadValue; - } - - if (!(pI915XvMC = context->privData)) - return XvMCBadContext; - - if (!(privTarget = target_surface->privData)) - return XvMCBadSurface; - - if (context->surface_type_id >= SURFACE_TYPE_MAX) { - XVMC_ERR("Unsupprted surface_type_id %d.", context->surface_type_id); - return BadValue; - } - - intel_ctx = intel_xvmc_find_context(context->context_id); - if (!intel_ctx) { - XVMC_ERR("Can't find intel xvmc context\n"); - return BadValue; - } - - /* P Frame Test */ - if (!past_surface) { - /* Just to avoid some ifs later. */ - privPast = privTarget; - } else { - if (!(privPast = past_surface->privData)) { - XVMC_ERR("Invalid Past Surface!"); - return XvMCBadSurface; - } - picture_coding_type = MPEG_P_PICTURE; - } - - /* B Frame Test */ - if (!future_surface) { - privFuture = privPast; // privTarget; - } else { - if (!past_surface) { - XVMC_ERR("No Past Surface!"); - return BadValue; - } - - if (!(privFuture = future_surface->privData)) { - XVMC_ERR("Invalid Future Surface!"); - return XvMCBadSurface; - } - - picture_coding_type = MPEG_B_PICTURE; - } - - LOCK_HARDWARE(intel_ctx->hw_context); - corrdata_ptr = pI915XvMC->corrdata.map; - corrdata_size = 0; - - for (i = first_macroblock; i < (num_macroblocks + first_macroblock); i++) { - int bspm = 0; - mb = ¯oblock_array->macro_blocks[i]; - block_ptr = &(blocks->blocks[mb->index << 6]); - - /* Lockup can happen if the coordinates are too far out of range */ - if (mb->x > (target_surface->width >> 4)) { - mb->x = 0; - XVMC_INFO("reset x"); - } - - if (mb->y > (target_surface->height >> 4)) { - mb->y = 0; - XVMC_INFO("reset y"); - } - - /* Catch no pattern case */ - if (!(mb->macroblock_type & XVMC_MB_TYPE_PATTERN) && - !(mb->macroblock_type & XVMC_MB_TYPE_INTRA) && - mb->coded_block_pattern) { - mb->coded_block_pattern = 0; - XVMC_INFO("no coded blocks present!"); - } - - bspm = mb_bytes_420[mb->coded_block_pattern]; - - if (!bspm) - continue; - - corrdata_size += bspm; - - if (corrdata_size > pI915XvMC->corrdata.size) { - XVMC_ERR("correction data buffer overflow."); - break; - } - memcpy(corrdata_ptr, block_ptr, bspm); - corrdata_ptr += bspm; - } - - i915_flush(1, 0); - // i915_mc_invalidate_subcontext_buffers(context, BLOCK_SIS | BLOCK_DIS | BLOCK_SSB - // | BLOCK_MSB | BLOCK_PSP | BLOCK_PSC); - - i915_mc_one_time_state_emit(); - - i915_mc_static_indirect_state_set(context, target_surface, picture_structure, - flags, picture_coding_type); - /* setup reference surfaces */ - i915_mc_map_state_set(context, privPast, privFuture); - - i915_mc_load_indirect_render_emit(); - - i915_mc_mpeg_set_origin(context, ¯oblock_array->macro_blocks[first_macroblock]); - - for (i = first_macroblock; i < (num_macroblocks + first_macroblock); i++) { - mb = ¯oblock_array->macro_blocks[i]; - - /* Intra Blocks */ - if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { - i915_mc_mpeg_macroblock_ipicture(context, mb); - } else if ((picture_structure & XVMC_FRAME_PICTURE) == XVMC_FRAME_PICTURE) { - /* Frame Picture */ - switch (mb->motion_type & 3) { - case XVMC_PREDICTION_FIELD: /* Field Based */ - i915_mc_mpeg_macroblock_2fbmv(context, mb, picture_structure); - break; - - case XVMC_PREDICTION_FRAME: /* Frame Based */ - i915_mc_mpeg_macroblock_1fbmv(context, mb); - break; - - case XVMC_PREDICTION_DUAL_PRIME: /* Dual Prime */ - i915_mc_mpeg_macroblock_2fbmv(context, mb, picture_structure); - break; - - default: /* No Motion Type */ - XVMC_ERR("Invalid Macroblock Parameters found."); - break; - } - } else { /* Field Picture */ - switch (mb->motion_type & 3) { - case XVMC_PREDICTION_FIELD: /* Field Based */ - i915_mc_mpeg_macroblock_1fbmv(context, mb); - break; - - case XVMC_PREDICTION_16x8: /* 16x8 MC */ - i915_mc_mpeg_macroblock_2fbmv(context, mb, picture_structure); - break; - - case XVMC_PREDICTION_DUAL_PRIME: /* Dual Prime */ - i915_mc_mpeg_macroblock_1fbmv(context, mb); - break; - - default: /* No Motion Type */ - XVMC_ERR("Invalid Macroblock Parameters found."); - break; - } - } - } - - intelFlushBatch(TRUE); - xvmc_driver->last_render = xvmc_driver->alloc.irq_emitted; - privTarget->last_render = xvmc_driver->last_render; - - UNLOCK_HARDWARE(intel_ctx->hw_context); - return 0; + int i; + int picture_coding_type = MPEG_I_PICTURE; + /* correction data buffer */ + char *corrdata_ptr; + int corrdata_size = 0; + + /* Block Pointer */ + short *block_ptr; + /* Current Macroblock Pointer */ + XvMCMacroBlock *mb; + + intel_xvmc_context_ptr intel_ctx; + + i915XvMCSurface *privTarget = NULL; + i915XvMCSurface *privFuture = NULL; + i915XvMCSurface *privPast = NULL; + i915XvMCContext *pI915XvMC = NULL; + + XVMC_DBG("%s\n", __FUNCTION__); + + /* Check Parameters for validity */ + if (!display || !context || !target_surface) { + XVMC_ERR("Invalid Display, Context or Target!"); + return BadValue; + } + + if (!num_macroblocks) + return Success; + + if (!macroblock_array || !blocks) { + XVMC_ERR("Invalid block data!"); + return BadValue; + } + + if (macroblock_array->num_blocks < (num_macroblocks + first_macroblock)) { + XVMC_ERR("Too many macroblocks requested for MB array size."); + return BadValue; + } + + if (!(pI915XvMC = context->privData)) + return XvMCBadContext; + + if (!(privTarget = target_surface->privData)) + return XvMCBadSurface; + + if (context->surface_type_id >= SURFACE_TYPE_MAX) { + XVMC_ERR("Unsupprted surface_type_id %d.", + context->surface_type_id); + return BadValue; + } + + intel_ctx = intel_xvmc_find_context(context->context_id); + if (!intel_ctx) { + XVMC_ERR("Can't find intel xvmc context\n"); + return BadValue; + } + + /* P Frame Test */ + if (!past_surface) { + /* Just to avoid some ifs later. */ + privPast = privTarget; + } else { + if (!(privPast = past_surface->privData)) { + XVMC_ERR("Invalid Past Surface!"); + return XvMCBadSurface; + } + picture_coding_type = MPEG_P_PICTURE; + } + + /* B Frame Test */ + if (!future_surface) { + privFuture = privPast; // privTarget; + } else { + if (!past_surface) { + XVMC_ERR("No Past Surface!"); + return BadValue; + } + + if (!(privFuture = future_surface->privData)) { + XVMC_ERR("Invalid Future Surface!"); + return XvMCBadSurface; + } + + picture_coding_type = MPEG_B_PICTURE; + } + + LOCK_HARDWARE(intel_ctx->hw_context); + corrdata_ptr = pI915XvMC->corrdata.map; + corrdata_size = 0; + + for (i = first_macroblock; i < (num_macroblocks + first_macroblock); + i++) { + int bspm = 0; + mb = ¯oblock_array->macro_blocks[i]; + block_ptr = &(blocks->blocks[mb->index << 6]); + + /* Lockup can happen if the coordinates are too far out of range */ + if (mb->x > (target_surface->width >> 4)) { + mb->x = 0; + XVMC_INFO("reset x"); + } + + if (mb->y > (target_surface->height >> 4)) { + mb->y = 0; + XVMC_INFO("reset y"); + } + + /* Catch no pattern case */ + if (!(mb->macroblock_type & XVMC_MB_TYPE_PATTERN) && + !(mb->macroblock_type & XVMC_MB_TYPE_INTRA) && + mb->coded_block_pattern) { + mb->coded_block_pattern = 0; + XVMC_INFO("no coded blocks present!"); + } + + bspm = mb_bytes_420[mb->coded_block_pattern]; + + if (!bspm) + continue; + + corrdata_size += bspm; + + if (corrdata_size > pI915XvMC->corrdata.size) { + XVMC_ERR("correction data buffer overflow."); + break; + } + memcpy(corrdata_ptr, block_ptr, bspm); + corrdata_ptr += bspm; + } + + i915_flush(1, 0); + // i915_mc_invalidate_subcontext_buffers(context, BLOCK_SIS | BLOCK_DIS | BLOCK_SSB + // | BLOCK_MSB | BLOCK_PSP | BLOCK_PSC); + + i915_mc_one_time_state_emit(); + + i915_mc_static_indirect_state_set(context, target_surface, + picture_structure, flags, + picture_coding_type); + /* setup reference surfaces */ + i915_mc_map_state_set(context, privPast, privFuture); + + i915_mc_load_indirect_render_emit(); + + i915_mc_mpeg_set_origin(context, + ¯oblock_array->macro_blocks + [first_macroblock]); + + for (i = first_macroblock; i < (num_macroblocks + first_macroblock); + i++) { + mb = ¯oblock_array->macro_blocks[i]; + + /* Intra Blocks */ + if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { + i915_mc_mpeg_macroblock_ipicture(context, mb); + } else if ((picture_structure & XVMC_FRAME_PICTURE) == + XVMC_FRAME_PICTURE) { + /* Frame Picture */ + switch (mb->motion_type & 3) { + case XVMC_PREDICTION_FIELD: /* Field Based */ + i915_mc_mpeg_macroblock_2fbmv(context, mb, + picture_structure); + break; + + case XVMC_PREDICTION_FRAME: /* Frame Based */ + i915_mc_mpeg_macroblock_1fbmv(context, mb); + break; + + case XVMC_PREDICTION_DUAL_PRIME: /* Dual Prime */ + i915_mc_mpeg_macroblock_2fbmv(context, mb, + picture_structure); + break; + + default: /* No Motion Type */ + XVMC_ERR + ("Invalid Macroblock Parameters found."); + break; + } + } else { /* Field Picture */ + switch (mb->motion_type & 3) { + case XVMC_PREDICTION_FIELD: /* Field Based */ + i915_mc_mpeg_macroblock_1fbmv(context, mb); + break; + + case XVMC_PREDICTION_16x8: /* 16x8 MC */ + i915_mc_mpeg_macroblock_2fbmv(context, mb, + picture_structure); + break; + + case XVMC_PREDICTION_DUAL_PRIME: /* Dual Prime */ + i915_mc_mpeg_macroblock_1fbmv(context, mb); + break; + + default: /* No Motion Type */ + XVMC_ERR + ("Invalid Macroblock Parameters found."); + break; + } + } + } + + intelFlushBatch(TRUE); + xvmc_driver->last_render = xvmc_driver->alloc.irq_emitted; + privTarget->last_render = xvmc_driver->last_render; + + UNLOCK_HARDWARE(intel_ctx->hw_context); + return 0; } -static int i915_xvmc_mc_put_surface(Display *display,XvMCSurface *surface, - Drawable draw, short srcx, short srcy, - unsigned short srcw, unsigned short srch, - short destx, short desty, - unsigned short destw, unsigned short desth, - int flags, struct intel_xvmc_command *data) +static int i915_xvmc_mc_put_surface(Display * display, XvMCSurface * surface, + Drawable draw, short srcx, short srcy, + unsigned short srcw, unsigned short srch, + short destx, short desty, + unsigned short destw, unsigned short desth, + int flags, struct intel_xvmc_command *data) { - i915XvMCContext *pI915XvMC; - i915XvMCSurface *pI915Surface; - i915XvMCSubpicture *pI915SubPic; + i915XvMCContext *pI915XvMC; + i915XvMCSurface *pI915Surface; + i915XvMCSubpicture *pI915SubPic; - if (!(pI915Surface = surface->privData)) - return XvMCBadSurface; + if (!(pI915Surface = surface->privData)) + return XvMCBadSurface; - if (!(pI915XvMC = pI915Surface->privContext)) - return XvMCBadSurface; + if (!(pI915XvMC = pI915Surface->privContext)) + return XvMCBadSurface; - PPTHREAD_MUTEX_LOCK(); + PPTHREAD_MUTEX_LOCK(); - data->command = INTEL_XVMC_COMMAND_DISPLAY; - data->ctxNo = pI915XvMC->ctxno; - data->srfNo = pI915Surface->srfNo; - pI915SubPic = pI915Surface->privSubPic; - data->subPicNo = (!pI915SubPic ? 0 : pI915SubPic->srfNo); - data->real_id = FOURCC_YV12; - data->flags = flags; + data->command = INTEL_XVMC_COMMAND_DISPLAY; + data->ctxNo = pI915XvMC->ctxno; + data->srfNo = pI915Surface->srfNo; + pI915SubPic = pI915Surface->privSubPic; + data->subPicNo = (!pI915SubPic ? 0 : pI915SubPic->srfNo); + data->real_id = FOURCC_YV12; + data->flags = flags; - PPTHREAD_MUTEX_UNLOCK(); + PPTHREAD_MUTEX_UNLOCK(); - return 0; + return 0; } -static int i915_xvmc_mc_get_surface_status(Display *display, - XvMCSurface *surface, int *stat) +static int i915_xvmc_mc_get_surface_status(Display * display, + XvMCSurface * surface, int *stat) { - i915XvMCSurface *pI915Surface; - i915XvMCContext *pI915XvMC; - - if (!display || !surface || !stat) - return BadValue; - - *stat = 0; - - if (!(pI915Surface = surface->privData)) - return XvMCBadSurface; - - if (!(pI915XvMC = pI915Surface->privContext)) - return XvMCBadSurface; - - PPTHREAD_MUTEX_LOCK(); - if (pI915Surface->last_flip) { - /* This can not happen */ - if (pI915XvMC->last_flip < pI915Surface->last_flip) { - XVMC_ERR("Context last flip is less than surface last flip."); - PPTHREAD_MUTEX_UNLOCK(); - return BadValue; - } - - /* - If the context has 2 or more flips after this surface it - cannot be displaying. Don't bother to check. - */ - if (!(pI915XvMC->last_flip > (pI915Surface->last_flip + 1))) { - /* - If this surface was the last flipped it is either displaying - or about to be so don't bother checking. - */ - if (pI915XvMC->last_flip == pI915Surface->last_flip) { - *stat |= XVMC_DISPLAYING; - } - } - } - - PPTHREAD_MUTEX_UNLOCK(); - return 0; + i915XvMCSurface *pI915Surface; + i915XvMCContext *pI915XvMC; + + if (!display || !surface || !stat) + return BadValue; + + *stat = 0; + + if (!(pI915Surface = surface->privData)) + return XvMCBadSurface; + + if (!(pI915XvMC = pI915Surface->privContext)) + return XvMCBadSurface; + + PPTHREAD_MUTEX_LOCK(); + if (pI915Surface->last_flip) { + /* This can not happen */ + if (pI915XvMC->last_flip < pI915Surface->last_flip) { + XVMC_ERR + ("Context last flip is less than surface last flip."); + PPTHREAD_MUTEX_UNLOCK(); + return BadValue; + } + + /* + If the context has 2 or more flips after this surface it + cannot be displaying. Don't bother to check. + */ + if (!(pI915XvMC->last_flip > (pI915Surface->last_flip + 1))) { + /* + If this surface was the last flipped it is either displaying + or about to be so don't bother checking. + */ + if (pI915XvMC->last_flip == pI915Surface->last_flip) { + *stat |= XVMC_DISPLAYING; + } + } + } + + PPTHREAD_MUTEX_UNLOCK(); + return 0; } /* XXX WIP code */ #if 0 -Status XvMCHideSurface(Display *display, XvMCSurface *surface) +Status XvMCHideSurface(Display * display, XvMCSurface * surface) { - i915XvMCSurface *pI915Surface; - i915XvMCContext *pI915XvMC; - int stat = 0, ret; + i915XvMCSurface *pI915Surface; + i915XvMCContext *pI915XvMC; + int stat = 0, ret; - if (!display || !surface) - return BadValue; + if (!display || !surface) + return BadValue; - if (!(pI915Surface = surface->privData)) - return XvMCBadSurface; + if (!(pI915Surface = surface->privData)) + return XvMCBadSurface; - /* Get the associated context pointer */ - if (!(pI915XvMC = pI915Surface->privContext)) - return XvMCBadSurface; + /* Get the associated context pointer */ + if (!(pI915XvMC = pI915Surface->privContext)) + return XvMCBadSurface; - XvMCSyncSurface(display, surface); + XvMCSyncSurface(display, surface); - /* - Get the status of the surface, if it is not currently displayed - we don't need to worry about it. - */ - if ((ret = XvMCGetSurfaceStatus(display, surface, &stat)) != Success) - return ret; + /* + Get the status of the surface, if it is not currently displayed + we don't need to worry about it. + */ + if ((ret = XvMCGetSurfaceStatus(display, surface, &stat)) != Success) + return ret; - if (!(stat & XVMC_DISPLAYING)) - return Success; + if (!(stat & XVMC_DISPLAYING)) + return Success; - /* FIXME: */ - return Success; + /* FIXME: */ + return Success; } -Status i915_xvmc_create_subpict(Display *display, XvMCContext *context, - XvMCSubpicture *subpicture, - unsigned short width, unsigned short height, - int xvimage_id) +Status i915_xvmc_create_subpict(Display * display, XvMCContext * context, + XvMCSubpicture * subpicture, + unsigned short width, unsigned short height, + int xvimage_id) { - Status ret; - i915XvMCContext *pI915XvMC; - i915XvMCSubpicture *pI915Subpicture; - I915XvMCCreateSurfaceRec *tmpComm = NULL; - int priv_count; - uint *priv_data; - - if (!subpicture || !context || !display) - return BadValue; - - pI915XvMC = (i915XvMCContext *)context->privData; - - if (!pI915XvMC) - return XvMCBadContext; - - subpicture->privData = - (i915XvMCSubpicture *)malloc(sizeof(i915XvMCSubpicture)); - - if (!subpicture->privData) - return BadAlloc; - - PPTHREAD_MUTEX_LOCK(); - subpicture->context_id = context->context_id; - subpicture->xvimage_id = xvimage_id; - subpicture->width = width; - subpicture->height = height; - pI915Subpicture = (i915XvMCSubpicture *)subpicture->privData; - - XLockDisplay(display); - if ((ret = _xvmc_create_subpicture(display, context, subpicture, - &priv_count, &priv_data))) { - XUnlockDisplay(display); - XVMC_ERR("Unable to create XvMCSubpicture."); - free(pI915Subpicture); - subpicture->privData = NULL; - PPTHREAD_MUTEX_UNLOCK(); - return ret; - } - XUnlockDisplay(display); - - if (priv_count != (sizeof(I915XvMCCreateSurfaceRec) >> 2)) { - XVMC_ERR("_xvmc_create_subpicture() returned incorrect data size!"); - XVMC_INFO("\tExpected %d, got %d", - (int)(sizeof(I915XvMCCreateSurfaceRec) >> 2), priv_count); - XLockDisplay(display); - _xvmc_destroy_subpicture(display, subpicture); - XUnlockDisplay(display); - XFree(priv_data); - free(pI915Subpicture); - subpicture->privData = NULL; - PPTHREAD_MUTEX_UNLOCK(); - return BadAlloc; - } - - tmpComm = (I915XvMCCreateSurfaceRec *)priv_data; - pI915Subpicture->srfNo = tmpComm->srfno; - pI915Subpicture->srf.handle = tmpComm->srf.handle; - pI915Subpicture->srf.offset = tmpComm->srf.offset; - pI915Subpicture->srf.size = tmpComm->srf.size; - XFree(priv_data); - - if (drmMap(pI915XvMC->fd, - pI915Subpicture->srf.handle, - pI915Subpicture->srf.size, - (drmAddress *)&pI915Subpicture->srf.map) != 0) { - XLockDisplay(display); - _xvmc_destroy_subpicture(display, subpicture); - XUnlockDisplay(display); - free(pI915Subpicture); - subpicture->privData = NULL; - PPTHREAD_MUTEX_UNLOCK(); - return BadAlloc; - } - - /* subpicture */ - subpicture->num_palette_entries = I915_SUBPIC_PALETTE_SIZE; - subpicture->entry_bytes = 3; - strncpy(subpicture->component_order, "YUV", 4); - - /* Initialize private values */ - pI915Subpicture->privContext = pI915XvMC; - pI915Subpicture->last_render= 0; - pI915Subpicture->last_flip = 0; - pI915Subpicture->pitch = ((subpicture->width + 3) & ~3); - - switch(subpicture->xvimage_id) { - case FOURCC_IA44: - case FOURCC_AI44: - break; - - default: - drmUnmap(pI915Subpicture->srf.map, pI915Subpicture->srf.size); - XLockDisplay(display); - _xvmc_destroy_subpicture(display, subpicture); - XUnlockDisplay(display); - free(pI915Subpicture); - subpicture->privData = NULL; - PPTHREAD_MUTEX_UNLOCK(); - return BadMatch; - } - - pI915XvMC->ref++; - PPTHREAD_MUTEX_UNLOCK(); - return Success; + Status ret; + i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; + I915XvMCCreateSurfaceRec *tmpComm = NULL; + int priv_count; + uint *priv_data; + + if (!subpicture || !context || !display) + return BadValue; + + pI915XvMC = (i915XvMCContext *) context->privData; + + if (!pI915XvMC) + return XvMCBadContext; + + subpicture->privData = + (i915XvMCSubpicture *) malloc(sizeof(i915XvMCSubpicture)); + + if (!subpicture->privData) + return BadAlloc; + + PPTHREAD_MUTEX_LOCK(); + subpicture->context_id = context->context_id; + subpicture->xvimage_id = xvimage_id; + subpicture->width = width; + subpicture->height = height; + pI915Subpicture = (i915XvMCSubpicture *) subpicture->privData; + + XLockDisplay(display); + if ((ret = _xvmc_create_subpicture(display, context, subpicture, + &priv_count, &priv_data))) { + XUnlockDisplay(display); + XVMC_ERR("Unable to create XvMCSubpicture."); + free(pI915Subpicture); + subpicture->privData = NULL; + PPTHREAD_MUTEX_UNLOCK(); + return ret; + } + XUnlockDisplay(display); + + if (priv_count != (sizeof(I915XvMCCreateSurfaceRec) >> 2)) { + XVMC_ERR + ("_xvmc_create_subpicture() returned incorrect data size!"); + XVMC_INFO("\tExpected %d, got %d", + (int)(sizeof(I915XvMCCreateSurfaceRec) >> 2), + priv_count); + XLockDisplay(display); + _xvmc_destroy_subpicture(display, subpicture); + XUnlockDisplay(display); + XFree(priv_data); + free(pI915Subpicture); + subpicture->privData = NULL; + PPTHREAD_MUTEX_UNLOCK(); + return BadAlloc; + } + + tmpComm = (I915XvMCCreateSurfaceRec *) priv_data; + pI915Subpicture->srfNo = tmpComm->srfno; + pI915Subpicture->srf.handle = tmpComm->srf.handle; + pI915Subpicture->srf.offset = tmpComm->srf.offset; + pI915Subpicture->srf.size = tmpComm->srf.size; + XFree(priv_data); + + if (drmMap(pI915XvMC->fd, + pI915Subpicture->srf.handle, + pI915Subpicture->srf.size, + (drmAddress *) & pI915Subpicture->srf.map) != 0) { + XLockDisplay(display); + _xvmc_destroy_subpicture(display, subpicture); + XUnlockDisplay(display); + free(pI915Subpicture); + subpicture->privData = NULL; + PPTHREAD_MUTEX_UNLOCK(); + return BadAlloc; + } + + /* subpicture */ + subpicture->num_palette_entries = I915_SUBPIC_PALETTE_SIZE; + subpicture->entry_bytes = 3; + strncpy(subpicture->component_order, "YUV", 4); + + /* Initialize private values */ + pI915Subpicture->privContext = pI915XvMC; + pI915Subpicture->last_render = 0; + pI915Subpicture->last_flip = 0; + pI915Subpicture->pitch = ((subpicture->width + 3) & ~3); + + switch (subpicture->xvimage_id) { + case FOURCC_IA44: + case FOURCC_AI44: + break; + + default: + drmUnmap(pI915Subpicture->srf.map, pI915Subpicture->srf.size); + XLockDisplay(display); + _xvmc_destroy_subpicture(display, subpicture); + XUnlockDisplay(display); + free(pI915Subpicture); + subpicture->privData = NULL; + PPTHREAD_MUTEX_UNLOCK(); + return BadMatch; + } + + pI915XvMC->ref++; + PPTHREAD_MUTEX_UNLOCK(); + return Success; } -Status i915_xvmc_clear_subpict(Display *display, XvMCSubpicture *subpicture, - short x, short y, - unsigned short width, unsigned short height, - unsigned int color) +Status i915_xvmc_clear_subpict(Display * display, XvMCSubpicture * subpicture, + short x, short y, + unsigned short width, unsigned short height, + unsigned int color) { - i915XvMCContext *pI915XvMC; - i915XvMCSubpicture *pI915Subpicture; + i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if (!(pI915XvMC = pI915Subpicture->privContext)) - return XvMCBadSubpicture; + if (!(pI915XvMC = pI915Subpicture->privContext)) + return XvMCBadSubpicture; - if ((x < 0) || (x + width) > subpicture->width) - return BadValue; + if ((x < 0) || (x + width) > subpicture->width) + return BadValue; - if ((y < 0) || (y + height) > subpicture->height) - return BadValue; + if ((y < 0) || (y + height) > subpicture->height) + return BadValue; - /* FIXME: clear the area */ + /* FIXME: clear the area */ - return Success; + return Success; } -Status i915_xvmc_composite_subpict(Display *display, XvMCSubpicture *subpicture, - XvImage *image, - short srcx, short srcy, - unsigned short width, unsigned short height, - short dstx, short dsty) +Status i915_xvmc_composite_subpict(Display * display, + XvMCSubpicture * subpicture, XvImage * image, + short srcx, short srcy, unsigned short width, + unsigned short height, short dstx, + short dsty) { - i915XvMCContext *pI915XvMC; - i915XvMCSubpicture *pI915Subpicture; + i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if (!(pI915XvMC = pI915Subpicture->privContext)) - return XvMCBadSubpicture; + if (!(pI915XvMC = pI915Subpicture->privContext)) + return XvMCBadSubpicture; - if ((srcx < 0) || (srcx + width) > subpicture->width) - return BadValue; + if ((srcx < 0) || (srcx + width) > subpicture->width) + return BadValue; - if ((srcy < 0) || (srcy + height) > subpicture->height) - return BadValue; + if ((srcy < 0) || (srcy + height) > subpicture->height) + return BadValue; - if ((dstx < 0) || (dstx + width) > subpicture->width) - return BadValue; + if ((dstx < 0) || (dstx + width) > subpicture->width) + return BadValue; - if ((dsty < 0) || (dsty + width) > subpicture->height) - return BadValue; + if ((dsty < 0) || (dsty + width) > subpicture->height) + return BadValue; - if (image->id != subpicture->xvimage_id) - return BadMatch; + if (image->id != subpicture->xvimage_id) + return BadMatch; - /* FIXME */ - return Success; + /* FIXME */ + return Success; } - -Status i915_xvmc_destroy_subpict(Display *display, XvMCSubpicture *subpicture) +Status i915_xvmc_destroy_subpict(Display * display, XvMCSubpicture * subpicture) { - i915XvMCSubpicture *pI915Subpicture; - i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; + i915XvMCContext *pI915XvMC; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if (!(pI915XvMC = pI915Subpicture->privContext)) - return XvMCBadSubpicture; + if (!(pI915XvMC = pI915Subpicture->privContext)) + return XvMCBadSubpicture; - if (pI915Subpicture->last_render) - XvMCSyncSubpicture(display, subpicture); + if (pI915Subpicture->last_render) + XvMCSyncSubpicture(display, subpicture); - if (pI915Subpicture->srf.map) - drmUnmap(pI915Subpicture->srf.map, pI915Subpicture->srf.size); + if (pI915Subpicture->srf.map) + drmUnmap(pI915Subpicture->srf.map, pI915Subpicture->srf.size); - PPTHREAD_MUTEX_LOCK(); - XLockDisplay(display); - _xvmc_destroy_subpicture(display,subpicture); - XUnlockDisplay(display); + PPTHREAD_MUTEX_LOCK(); + XLockDisplay(display); + _xvmc_destroy_subpicture(display, subpicture); + XUnlockDisplay(display); - free(pI915Subpicture); - subpicture->privData = NULL; - pI915XvMC->ref--; - PPTHREAD_MUTEX_UNLOCK(); + free(pI915Subpicture); + subpicture->privData = NULL; + pI915XvMC->ref--; + PPTHREAD_MUTEX_UNLOCK(); - return Success; + return Success; } - -Status i915_xvmc_set_subpict_palette(Display *display, - XvMCSubpicture *subpicture, - unsigned char *palette) +Status i915_xvmc_set_subpict_palette(Display * display, + XvMCSubpicture * subpicture, + unsigned char *palette) { - i915XvMCSubpicture *pI915Subpicture; - int i, j; + i915XvMCSubpicture *pI915Subpicture; + int i, j; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - j = 0; - for (i = 0; i < 16; i++) { - pI915Subpicture->palette[0][i] = palette[j++]; - pI915Subpicture->palette[1][i] = palette[j++]; - pI915Subpicture->palette[2][i] = palette[j++]; - } + j = 0; + for (i = 0; i < 16; i++) { + pI915Subpicture->palette[0][i] = palette[j++]; + pI915Subpicture->palette[1][i] = palette[j++]; + pI915Subpicture->palette[2][i] = palette[j++]; + } - /* FIXME: Update the subpicture with the new palette */ - return Success; + /* FIXME: Update the subpicture with the new palette */ + return Success; } -Status i915_xvmc_blend_subpict(Display *display, XvMCSurface *target_surface, - XvMCSubpicture *subpicture, - short subx, short suby, - unsigned short subw, unsigned short subh, - short surfx, short surfy, - unsigned short surfw, unsigned short surfh) +Status i915_xvmc_blend_subpict(Display * display, XvMCSurface * target_surface, + XvMCSubpicture * subpicture, + short subx, short suby, + unsigned short subw, unsigned short subh, + short surfx, short surfy, + unsigned short surfw, unsigned short surfh) { - i915XvMCSubpicture *pI915Subpicture; - i915XvMCSurface *privTargetSurface; + i915XvMCSubpicture *pI915Subpicture; + i915XvMCSurface *privTargetSurface; - if (!display || !target_surface) - return BadValue; + if (!display || !target_surface) + return BadValue; - if (!(privTargetSurface = target_surface->privData)) - return XvMCBadSurface; + if (!(privTargetSurface = target_surface->privData)) + return XvMCBadSurface; - if (subpicture) { - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (subpicture) { + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if ((FOURCC_AI44 != subpicture->xvimage_id) && - (FOURCC_IA44 != subpicture->xvimage_id)) - return XvMCBadSubpicture; + if ((FOURCC_AI44 != subpicture->xvimage_id) && + (FOURCC_IA44 != subpicture->xvimage_id)) + return XvMCBadSubpicture; - privTargetSurface->privSubPic = pI915Subpicture; - } else { - privTargetSurface->privSubPic = NULL; - } + privTargetSurface->privSubPic = pI915Subpicture; + } else { + privTargetSurface->privSubPic = NULL; + } - return Success; + return Success; } -Status i915_xvmc_blend_subpict2(Display *display, - XvMCSurface *source_surface, - XvMCSurface *target_surface, - XvMCSubpicture *subpicture, - short subx, short suby, - unsigned short subw, unsigned short subh, - short surfx, short surfy, - unsigned short surfw, unsigned short surfh) +Status i915_xvmc_blend_subpict2(Display * display, + XvMCSurface * source_surface, + XvMCSurface * target_surface, + XvMCSubpicture * subpicture, + short subx, short suby, + unsigned short subw, unsigned short subh, + short surfx, short surfy, + unsigned short surfw, unsigned short surfh) { - i915XvMCContext *pI915XvMC; - i915XvMCSubpicture *pI915Subpicture; - i915XvMCSurface *privSourceSurface; - i915XvMCSurface *privTargetSurface; + i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; + i915XvMCSurface *privSourceSurface; + i915XvMCSurface *privTargetSurface; - if (!display || !source_surface || !target_surface) - return BadValue; + if (!display || !source_surface || !target_surface) + return BadValue; - if (!(privSourceSurface = source_surface->privData)) - return XvMCBadSurface; + if (!(privSourceSurface = source_surface->privData)) + return XvMCBadSurface; - if (!(privTargetSurface = target_surface->privData)) - return XvMCBadSurface; + if (!(privTargetSurface = target_surface->privData)) + return XvMCBadSurface; - if (!(pI915XvMC = privTargetSurface->privContext)) - return XvMCBadSurface; + if (!(pI915XvMC = privTargetSurface->privContext)) + return XvMCBadSurface; - if (((surfx + surfw) > privTargetSurface->width) || - ((surfy + surfh) > privTargetSurface->height)) - return BadValue; + if (((surfx + surfw) > privTargetSurface->width) || + ((surfy + surfh) > privTargetSurface->height)) + return BadValue; - if ((privSourceSurface->width != privTargetSurface->width) || - (privTargetSurface->height != privTargetSurface->height)) - return BadValue; + if ((privSourceSurface->width != privTargetSurface->width) || + (privTargetSurface->height != privTargetSurface->height)) + return BadValue; - if (XvMCSyncSurface(display, source_surface)) - return BadValue; + if (XvMCSyncSurface(display, source_surface)) + return BadValue; - /* FIXME: update Target Surface */ + /* FIXME: update Target Surface */ - if (subpicture) { - if (((subx + subw) > subpicture->width) || - ((suby + subh) > subpicture->height)) - return BadValue; + if (subpicture) { + if (((subx + subw) > subpicture->width) || + ((suby + subh) > subpicture->height)) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if ((FOURCC_AI44 != subpicture->xvimage_id) && - (FOURCC_IA44 != subpicture->xvimage_id)) - return XvMCBadSubpicture; + if ((FOURCC_AI44 != subpicture->xvimage_id) && + (FOURCC_IA44 != subpicture->xvimage_id)) + return XvMCBadSubpicture; - privTargetSurface->privSubPic = pI915Subpicture; - } else { - privTargetSurface->privSubPic = NULL; - } + privTargetSurface->privSubPic = pI915Subpicture; + } else { + privTargetSurface->privSubPic = NULL; + } - return Success; + return Success; } -Status i915_xvmc_sync_subpict(Display *display, XvMCSubpicture *subpicture) +Status i915_xvmc_sync_subpict(Display * display, XvMCSubpicture * subpicture) { - Status ret; - int stat = 0; + Status ret; + int stat = 0; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - do { - ret = XvMCGetSubpictureStatus(display, subpicture, &stat); - } while(!ret && (stat & XVMC_RENDERING)); + do { + ret = XvMCGetSubpictureStatus(display, subpicture, &stat); + } while (!ret && (stat & XVMC_RENDERING)); - return ret; + return ret; } -Status i915_xvmc_flush_subpict(Display *display, XvMCSubpicture *subpicture) +Status i915_xvmc_flush_subpict(Display * display, XvMCSubpicture * subpicture) { - i915XvMCSubpicture *pI915Subpicture; + i915XvMCSubpicture *pI915Subpicture; - if (!display || !subpicture) - return BadValue; + if (!display || !subpicture) + return BadValue; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - return Success; + return Success; } -Status i915_xvmc_get_subpict_status(Display *display, XvMCSubpicture *subpicture, - int *stat) +Status i915_xvmc_get_subpict_status(Display * display, + XvMCSubpicture * subpicture, int *stat) { - i915XvMCSubpicture *pI915Subpicture; - i915XvMCContext *pI915XvMC; + i915XvMCSubpicture *pI915Subpicture; + i915XvMCContext *pI915XvMC; + + if (!display || !subpicture || stat) + return BadValue; - if (!display || !subpicture || stat) - return BadValue; + *stat = 0; - *stat = 0; + if (!(pI915Subpicture = subpicture->privData)) + return XvMCBadSubpicture; - if (!(pI915Subpicture = subpicture->privData)) - return XvMCBadSubpicture; + if (!(pI915XvMC = pI915Subpicture->privContext)) + return XvMCBadSubpicture; - if (!(pI915XvMC = pI915Subpicture->privContext)) - return XvMCBadSubpicture; + PPTHREAD_MUTEX_LOCK(); - PPTHREAD_MUTEX_LOCK(); - - PPTHREAD_MUTEX_UNLOCK(); - return Success; + PPTHREAD_MUTEX_UNLOCK(); + return Success; } #endif struct _intel_xvmc_driver i915_xvmc_mc_driver = { - .type = XVMC_I915_MPEG2_MC, - .num_ctx = 0, - .ctx_list = NULL, - .create_context = i915_xvmc_mc_create_context, - .destroy_context = i915_xvmc_mc_destroy_context, - .create_surface = i915_xvmc_mc_create_surface, - .destroy_surface = i915_xvmc_mc_destroy_surface, - .render_surface = i915_xvmc_mc_render_surface, - .put_surface = i915_xvmc_mc_put_surface, - .get_surface_status = i915_xvmc_mc_get_surface_status, + .type = XVMC_I915_MPEG2_MC, + .num_ctx = 0, + .ctx_list = NULL, + .create_context = i915_xvmc_mc_create_context, + .destroy_context = i915_xvmc_mc_destroy_context, + .create_surface = i915_xvmc_mc_create_surface, + .destroy_surface = i915_xvmc_mc_destroy_surface, + .render_surface = i915_xvmc_mc_render_surface, + .put_surface = i915_xvmc_mc_put_surface, + .get_surface_status = i915_xvmc_mc_get_surface_status, }; diff --git a/src/xvmc/i915_xvmc.h b/src/xvmc/i915_xvmc.h index de9eb787..f0e8d3e4 100644 --- a/src/xvmc/i915_xvmc.h +++ b/src/xvmc/i915_xvmc.h @@ -49,29 +49,29 @@ * pointer in the XvMCContext structure. */ typedef struct _i915XvMCContext { - unsigned int ctxno; - unsigned int last_flip; - unsigned int dual_prime; /* Flag to identify when dual prime is in use. */ - unsigned int yStride; - unsigned int uvStride; - unsigned short ref; - unsigned int depth; - XvPortID port; /* Xv Port ID when displaying */ - int haveXv; /* Have I initialized the Xv - * connection for this surface? */ - XvImage *xvImage; /* Fake Xv Image used for command - * buffer transport to the X server */ - GC gc; /* X GC needed for displaying */ - Drawable draw; /* Drawable to undisplay from */ - void *drawHash; - int deviceID; + unsigned int ctxno; + unsigned int last_flip; + unsigned int dual_prime; /* Flag to identify when dual prime is in use. */ + unsigned int yStride; + unsigned int uvStride; + unsigned short ref; + unsigned int depth; + XvPortID port; /* Xv Port ID when displaying */ + int haveXv; /* Have I initialized the Xv + * connection for this surface? */ + XvImage *xvImage; /* Fake Xv Image used for command + * buffer transport to the X server */ + GC gc; /* X GC needed for displaying */ + Drawable draw; /* Drawable to undisplay from */ + void *drawHash; + int deviceID; - intel_xvmc_drm_map_t sis; - intel_xvmc_drm_map_t msb; - intel_xvmc_drm_map_t ssb; - intel_xvmc_drm_map_t psp; - intel_xvmc_drm_map_t psc; - intel_xvmc_drm_map_t corrdata; + intel_xvmc_drm_map_t sis; + intel_xvmc_drm_map_t msb; + intel_xvmc_drm_map_t ssb; + intel_xvmc_drm_map_t psp; + intel_xvmc_drm_map_t psc; + intel_xvmc_drm_map_t corrdata; } i915XvMCContext; /* @@ -81,13 +81,13 @@ typedef struct _i915XvMCContext { * structure. */ typedef struct _i915XvMCSubpicture { - unsigned int srfNo; - unsigned int last_render; - unsigned int last_flip; - unsigned int pitch; - unsigned char palette[3][16]; - intel_xvmc_drm_map_t srf; - i915XvMCContext *privContext; + unsigned int srfNo; + unsigned int last_render; + unsigned int last_flip; + unsigned int pitch; + unsigned char palette[3][16]; + intel_xvmc_drm_map_t srf; + i915XvMCContext *privContext; } i915XvMCSubpicture; /* Number of YUV buffers per surface */ @@ -99,17 +99,17 @@ typedef struct _i915XvMCSubpicture { * structure. */ typedef struct _i915XvMCSurface { - unsigned int srfNo; /* XvMC private surface numbers */ - unsigned int last_render; - unsigned int last_flip; - unsigned int yStride; /* Stride of YUV420 Y component. */ - unsigned int uvStride; - unsigned int width; /* Dimensions */ - unsigned int height; - intel_xvmc_drm_map_t srf; - i915XvMCContext *privContext; - i915XvMCSubpicture *privSubPic; /* Subpicture to be blended when - * displaying. NULL if none. */ + unsigned int srfNo; /* XvMC private surface numbers */ + unsigned int last_render; + unsigned int last_flip; + unsigned int yStride; /* Stride of YUV420 Y component. */ + unsigned int uvStride; + unsigned int width; /* Dimensions */ + unsigned int height; + intel_xvmc_drm_map_t srf; + i915XvMCContext *privContext; + i915XvMCSubpicture *privSubPic; /* Subpicture to be blended when + * displaying. NULL if none. */ } i915XvMCSurface; #endif /* _I915XVMC_H */ diff --git a/src/xvmc/i965_xvmc.c b/src/xvmc/i965_xvmc.c index 316b7a2b..ff67995f 100644 --- a/src/xvmc/i965_xvmc.c +++ b/src/xvmc/i965_xvmc.c @@ -31,98 +31,133 @@ #include "intel_batchbuffer.h" #include "i965_hwmc.h" #define BATCH_STRUCT(x) intelBatchbufferData(&x, sizeof(x), 0) -#define URB_SIZE 256 /* XXX */ +#define URB_SIZE 256 /* XXX */ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) enum interface { - INTRA_INTERFACE = 0, /* non field intra */ - NULL_INTERFACE, /* fill with white, do nothing, for debug */ - FORWARD_INTERFACE, /* non field forward predict */ - BACKWARD_INTERFACE, /* non field backward predict */ - F_B_INTERFACE, /* non field forward and backward predict */ - FIELD_FORWARD_INTERFACE, /* field forward predict */ - FIELD_BACKWARD_INTERFACE, /* field backward predict */ - FIELD_F_B_INTERFACE, /* field forward and backward predict */ - DUAL_PRIME_INTERFACE + INTRA_INTERFACE = 0, /* non field intra */ + NULL_INTERFACE, /* fill with white, do nothing, for debug */ + FORWARD_INTERFACE, /* non field forward predict */ + BACKWARD_INTERFACE, /* non field backward predict */ + F_B_INTERFACE, /* non field forward and backward predict */ + FIELD_FORWARD_INTERFACE, /* field forward predict */ + FIELD_BACKWARD_INTERFACE, /* field backward predict */ + FIELD_F_B_INTERFACE, /* field forward and backward predict */ + DUAL_PRIME_INTERFACE }; static const uint32_t ipicture_kernel_static[][4] = { - #include "shader/mc/ipicture.g4b" +#include "shader/mc/ipicture.g4b" }; + static const uint32_t null_kernel_static[][4] = { - #include "shader/mc/null.g4b" +#include "shader/mc/null.g4b" }; + static const uint32_t frame_forward_kernel_static[][4] = { - #include "shader/mc/frame_forward.g4b" +#include "shader/mc/frame_forward.g4b" }; + static const uint32_t frame_backward_kernel_static[][4] = { - #include "shader/mc/frame_backward.g4b" +#include "shader/mc/frame_backward.g4b" }; + static const uint32_t frame_f_b_kernel_static[][4] = { - #include "shader/mc/frame_f_b.g4b" -}; +#include "shader/mc/frame_f_b.g4b" +}; + static const uint32_t field_forward_kernel_static[][4] = { - #include "shader/mc/field_forward.g4b" +#include "shader/mc/field_forward.g4b" }; + static const uint32_t field_backward_kernel_static[][4] = { - #include "shader/mc/field_backward.g4b" +#include "shader/mc/field_backward.g4b" }; + static const uint32_t field_f_b_kernel_static[][4] = { - #include "shader/mc/field_f_b.g4b" -}; -static const uint32_t dual_prime_kernel_static[][4]= { - #include "shader/mc/dual_prime.g4b" -}; +#include "shader/mc/field_f_b.g4b" +}; + +static const uint32_t dual_prime_kernel_static[][4] = { +#include "shader/mc/dual_prime.g4b" +}; + static const uint32_t frame_forward_igd_kernel_static[][4] = { - #include "shader/mc/frame_forward_igd.g4b" +#include "shader/mc/frame_forward_igd.g4b" }; + static const uint32_t frame_backward_igd_kernel_static[][4] = { - #include "shader/mc/frame_backward_igd.g4b" +#include "shader/mc/frame_backward_igd.g4b" }; + static const uint32_t frame_f_b_igd_kernel_static[][4] = { - #include "shader/mc/frame_f_b_igd.g4b" -}; +#include "shader/mc/frame_f_b_igd.g4b" +}; + static const uint32_t field_forward_igd_kernel_static[][4] = { - #include "shader/mc/field_forward_igd.g4b" +#include "shader/mc/field_forward_igd.g4b" }; + static const uint32_t field_backward_igd_kernel_static[][4] = { - #include "shader/mc/field_backward_igd.g4b" +#include "shader/mc/field_backward_igd.g4b" }; + static const uint32_t field_f_b_igd_kernel_static[][4] = { - #include "shader/mc/field_f_b_igd.g4b" -}; -static const uint32_t dual_prime_igd_kernel_static[][4]= { - #include "shader/mc/dual_prime_igd.g4b" -}; - -struct kernel_struct{ - const uint32_t (*bin)[4]; +#include "shader/mc/field_f_b_igd.g4b" +}; + +static const uint32_t dual_prime_igd_kernel_static[][4] = { +#include "shader/mc/dual_prime_igd.g4b" +}; + +struct kernel_struct { + const uint32_t(*bin)[4]; uint32_t size; }; struct kernel_struct kernels_igd[] = { - {ipicture_kernel_static, sizeof(ipicture_kernel_static)}, - {null_kernel_static, sizeof(null_kernel_static)}, - {frame_forward_igd_kernel_static, sizeof(frame_forward_igd_kernel_static)}, - {frame_backward_igd_kernel_static, sizeof(frame_backward_igd_kernel_static)}, - {frame_f_b_igd_kernel_static, sizeof(frame_f_b_igd_kernel_static)}, - {field_forward_igd_kernel_static, sizeof(field_forward_igd_kernel_static)}, - {field_backward_igd_kernel_static, sizeof(field_backward_igd_kernel_static)}, - {field_f_b_igd_kernel_static, sizeof(field_f_b_igd_kernel_static)}, - {dual_prime_igd_kernel_static, sizeof(dual_prime_igd_kernel_static)} + {ipicture_kernel_static, sizeof(ipicture_kernel_static)} + , + {null_kernel_static, sizeof(null_kernel_static)} + , + {frame_forward_igd_kernel_static, + sizeof(frame_forward_igd_kernel_static)} + , + {frame_backward_igd_kernel_static, + sizeof(frame_backward_igd_kernel_static)} + , + {frame_f_b_igd_kernel_static, sizeof(frame_f_b_igd_kernel_static)} + , + {field_forward_igd_kernel_static, + sizeof(field_forward_igd_kernel_static)} + , + {field_backward_igd_kernel_static, + sizeof(field_backward_igd_kernel_static)} + , + {field_f_b_igd_kernel_static, sizeof(field_f_b_igd_kernel_static)} + , + {dual_prime_igd_kernel_static, sizeof(dual_prime_igd_kernel_static)} }; struct kernel_struct kernels_965[] = { - {ipicture_kernel_static, sizeof(ipicture_kernel_static)}, - {null_kernel_static, sizeof(null_kernel_static)}, - {frame_forward_kernel_static, sizeof(frame_forward_kernel_static)}, - {frame_backward_kernel_static, sizeof(frame_backward_kernel_static)}, - {frame_f_b_kernel_static, sizeof(frame_f_b_kernel_static)}, - {field_forward_kernel_static, sizeof(field_forward_kernel_static)}, - {field_backward_kernel_static, sizeof(field_backward_kernel_static)}, - {field_f_b_kernel_static, sizeof(field_f_b_kernel_static)}, - {dual_prime_kernel_static, sizeof(dual_prime_kernel_static)} + {ipicture_kernel_static, sizeof(ipicture_kernel_static)} + , + {null_kernel_static, sizeof(null_kernel_static)} + , + {frame_forward_kernel_static, sizeof(frame_forward_kernel_static)} + , + {frame_backward_kernel_static, sizeof(frame_backward_kernel_static)} + , + {frame_f_b_kernel_static, sizeof(frame_f_b_kernel_static)} + , + {field_forward_kernel_static, sizeof(field_forward_kernel_static)} + , + {field_backward_kernel_static, sizeof(field_backward_kernel_static)} + , + {field_f_b_kernel_static, sizeof(field_f_b_kernel_static)} + , + {dual_prime_kernel_static, sizeof(dual_prime_kernel_static)} }; #define ALIGN(i,m) (((i) + (m) - 1) & ~((m) - 1)) @@ -131,390 +166,411 @@ struct kernel_struct kernels_965[] = { #define DESCRIPTOR_NUM 12 struct media_kernel_obj { - dri_bo *bo; + dri_bo *bo; }; struct interface_descriptor_obj { - dri_bo *bo; - struct media_kernel_obj kernels[DESCRIPTOR_NUM]; + dri_bo *bo; + struct media_kernel_obj kernels[DESCRIPTOR_NUM]; }; struct vfe_state_obj { - dri_bo *bo; - struct interface_descriptor_obj interface; + dri_bo *bo; + struct interface_descriptor_obj interface; }; struct surface_obj { - dri_bo *bo; + dri_bo *bo; }; struct surface_state_obj { - struct surface_obj surface; - dri_bo *bo; + struct surface_obj surface; + dri_bo *bo; }; struct binding_table_obj { - dri_bo *bo; - struct surface_state_obj surface_states[MAX_SURFACE_NUM]; + dri_bo *bo; + struct surface_state_obj surface_states[MAX_SURFACE_NUM]; }; struct indirect_data_obj { - dri_bo *bo; + dri_bo *bo; }; struct media_state { - unsigned int is_g4x:1; - unsigned int is_965_q:1; + unsigned int is_g4x:1; + unsigned int is_965_q:1; - struct vfe_state_obj vfe_state; - struct binding_table_obj binding_table; - struct indirect_data_obj indirect_data; + struct vfe_state_obj vfe_state; + struct binding_table_obj binding_table; + struct indirect_data_obj indirect_data; }; struct media_state media_state; static int free_object(struct media_state *s) { - int i; + int i; #define FREE_ONE_BO(bo) drm_intel_bo_unreference(bo) - FREE_ONE_BO(s->vfe_state.bo); - FREE_ONE_BO(s->vfe_state.interface.bo); - for (i = 0; i < DESCRIPTOR_NUM; i++) - FREE_ONE_BO(s->vfe_state.interface.kernels[i].bo); - FREE_ONE_BO(s->binding_table.bo); - for (i = 0; i < MAX_SURFACE_NUM; i++) - FREE_ONE_BO(s->binding_table.surface_states[i].bo); - FREE_ONE_BO(s->indirect_data.bo); + FREE_ONE_BO(s->vfe_state.bo); + FREE_ONE_BO(s->vfe_state.interface.bo); + for (i = 0; i < DESCRIPTOR_NUM; i++) + FREE_ONE_BO(s->vfe_state.interface.kernels[i].bo); + FREE_ONE_BO(s->binding_table.bo); + for (i = 0; i < MAX_SURFACE_NUM; i++) + FREE_ONE_BO(s->binding_table.surface_states[i].bo); + FREE_ONE_BO(s->indirect_data.bo); } static int alloc_object(struct media_state *s) { - int i; - - for (i = 0; i < MAX_SURFACE_NUM; i++) { - s->binding_table.surface_states[i].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", - sizeof(struct brw_surface_state), 0x1000); - if (!s->binding_table.surface_states[i].bo) - goto out; - } - return 0; + int i; + + for (i = 0; i < MAX_SURFACE_NUM; i++) { + s->binding_table.surface_states[i].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", + sizeof(struct brw_surface_state), + 0x1000); + if (!s->binding_table.surface_states[i].bo) + goto out; + } + return 0; out: - free_object(s); - return BadAlloc; + free_object(s); + return BadAlloc; } - -static Status destroy_context(Display *display, XvMCContext *context) +static Status destroy_context(Display * display, XvMCContext * context) { - struct i965_xvmc_context *private_context; - private_context = context->privData; + struct i965_xvmc_context *private_context; + private_context = context->privData; - free_object(&media_state); - Xfree(private_context); - return Success; + free_object(&media_state); + Xfree(private_context); + return Success; } #define STRIDE(w) (w) #define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1))) -static Status create_surface(Display *display, - XvMCContext *context, XvMCSurface *surface, int priv_count, - CARD32 *priv_data) +static Status create_surface(Display * display, + XvMCContext * context, XvMCSurface * surface, + int priv_count, CARD32 * priv_data) { - struct i965_xvmc_surface *priv_surface = - (struct i965_xvmc_surface *)priv_data; - size_t size = SIZE_YUV420(priv_surface->w, priv_surface->h); - surface->privData = priv_data; - priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface", - size, 0x1000); - return Success; + struct i965_xvmc_surface *priv_surface = + (struct i965_xvmc_surface *)priv_data; + size_t size = SIZE_YUV420(priv_surface->w, priv_surface->h); + surface->privData = priv_data; + priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface", + size, 0x1000); + return Success; } -static Status destroy_surface(Display *display, XvMCSurface *surface) +static Status destroy_surface(Display * display, XvMCSurface * surface) { - struct i965_xvmc_surface *priv_surface = - surface->privData; - XSync(display, False); + struct i965_xvmc_surface *priv_surface = surface->privData; + XSync(display, False); - drm_intel_bo_unreference(priv_surface->bo); - return Success; + drm_intel_bo_unreference(priv_surface->bo); + return Success; } static void flush() { - struct brw_mi_flush flush; - memset(&flush, 0, sizeof(flush)); - flush.opcode = CMD_MI_FLUSH; - flush.flags = (1<<1); - BATCH_STRUCT(flush); + struct brw_mi_flush flush; + memset(&flush, 0, sizeof(flush)); + flush.opcode = CMD_MI_FLUSH; + flush.flags = (1 << 1); + BATCH_STRUCT(flush); } static void clear_sf_state() { - struct brw_sf_unit_state sf; - memset(&sf, 0, sizeof(sf)); - /* TODO */ + struct brw_sf_unit_state sf; + memset(&sf, 0, sizeof(sf)); + /* TODO */ } - /* urb fence must be aligned to cacheline */ static void align_urb_fence() { - BATCH_LOCALS; - int i, offset_to_next_cacheline; - unsigned long batch_offset; - BEGIN_BATCH(3); - batch_offset = (void *)batch_ptr - xvmc_driver->alloc.ptr; - offset_to_next_cacheline = ALIGN(batch_offset, 64) - batch_offset; - if (offset_to_next_cacheline <= 12 && offset_to_next_cacheline != 0) { - for (i = 0; i < offset_to_next_cacheline/4; i++) - OUT_BATCH(0); - ADVANCE_BATCH(); - } + BATCH_LOCALS; + int i, offset_to_next_cacheline; + unsigned long batch_offset; + BEGIN_BATCH(3); + batch_offset = (void *)batch_ptr - xvmc_driver->alloc.ptr; + offset_to_next_cacheline = ALIGN(batch_offset, 64) - batch_offset; + if (offset_to_next_cacheline <= 12 && offset_to_next_cacheline != 0) { + for (i = 0; i < offset_to_next_cacheline / 4; i++) + OUT_BATCH(0); + ADVANCE_BATCH(); + } } /* setup urb layout for media */ static void urb_layout() { - BATCH_LOCALS; - align_urb_fence(); - BEGIN_BATCH(3); - OUT_BATCH(BRW_URB_FENCE | - UF0_VFE_REALLOC | - UF0_CS_REALLOC | - UF0_SF_REALLOC | - UF0_CLIP_REALLOC | - UF0_GS_REALLOC | - UF0_VS_REALLOC | - 1); - OUT_BATCH((0 << UF1_CLIP_FENCE_SHIFT) | - (0 << UF1_GS_FENCE_SHIFT) | - (0 << UF1_VS_FENCE_SHIFT)); - - OUT_BATCH(((URB_SIZE)<< UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */ - ((URB_SIZE)<< UF2_CS_FENCE_SHIFT)); /* CS_SIZE is 0 */ - ADVANCE_BATCH(); + BATCH_LOCALS; + align_urb_fence(); + BEGIN_BATCH(3); + OUT_BATCH(BRW_URB_FENCE | + UF0_VFE_REALLOC | + UF0_CS_REALLOC | + UF0_SF_REALLOC | + UF0_CLIP_REALLOC | UF0_GS_REALLOC | UF0_VS_REALLOC | 1); + OUT_BATCH((0 << UF1_CLIP_FENCE_SHIFT) | + (0 << UF1_GS_FENCE_SHIFT) | (0 << UF1_VS_FENCE_SHIFT)); + + OUT_BATCH(((URB_SIZE) << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */ + ((URB_SIZE) << UF2_CS_FENCE_SHIFT)); /* CS_SIZE is 0 */ + ADVANCE_BATCH(); } static void media_state_pointers(struct media_state *media_state) { - BATCH_LOCALS; - BEGIN_BATCH(3); - OUT_BATCH(BRW_MEDIA_STATE_POINTERS|1); - OUT_BATCH(0); - OUT_RELOC(media_state->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(3); + OUT_BATCH(BRW_MEDIA_STATE_POINTERS | 1); + OUT_BATCH(0); + OUT_RELOC(media_state->vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); + ADVANCE_BATCH(); } /* setup 2D surface for media_read or media_write */ static Status setup_media_surface(struct media_state *media_state, - int surface_num, dri_bo *bo, unsigned long offset, int w, int h, Bool write) + int surface_num, dri_bo * bo, + unsigned long offset, int w, int h, + Bool write) { - struct brw_surface_state s, *ss = &s; - - memset(ss, 0, sizeof(struct brw_surface_state)); - ss->ss0.surface_type = BRW_SURFACE_2D; - ss->ss0.surface_format = BRW_SURFACEFORMAT_R8_SINT; - ss->ss1.base_addr = offset + bo->offset; - ss->ss2.width = w - 1; - ss->ss2.height = h - 1; - ss->ss3.pitch = w - 1; - - if (media_state->binding_table.surface_states[surface_num].bo) - drm_intel_bo_unreference(media_state->binding_table.surface_states[surface_num].bo); - media_state->binding_table.surface_states[surface_num].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", - sizeof(struct brw_surface_state), 0x1000); - if (!media_state->binding_table.surface_states[surface_num].bo) - return BadAlloc; - - drm_intel_bo_subdata( - media_state->binding_table.surface_states[surface_num].bo, - 0, sizeof(*ss), ss); - - drm_intel_bo_emit_reloc(media_state->binding_table.surface_states[surface_num].bo, - offsetof(struct brw_surface_state, ss1), - bo, - offset, - I915_GEM_DOMAIN_RENDER, write?I915_GEM_DOMAIN_RENDER:0); - - return Success; + struct brw_surface_state s, *ss = &s; + + memset(ss, 0, sizeof(struct brw_surface_state)); + ss->ss0.surface_type = BRW_SURFACE_2D; + ss->ss0.surface_format = BRW_SURFACEFORMAT_R8_SINT; + ss->ss1.base_addr = offset + bo->offset; + ss->ss2.width = w - 1; + ss->ss2.height = h - 1; + ss->ss3.pitch = w - 1; + + if (media_state->binding_table.surface_states[surface_num].bo) + drm_intel_bo_unreference(media_state-> + binding_table.surface_states + [surface_num].bo); + media_state->binding_table.surface_states[surface_num].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", + sizeof(struct brw_surface_state), 0x1000); + if (!media_state->binding_table.surface_states[surface_num].bo) + return BadAlloc; + + drm_intel_bo_subdata(media_state-> + binding_table.surface_states[surface_num].bo, 0, + sizeof(*ss), ss); + + drm_intel_bo_emit_reloc(media_state-> + binding_table.surface_states[surface_num].bo, + offsetof(struct brw_surface_state, ss1), bo, + offset, I915_GEM_DOMAIN_RENDER, + write ? I915_GEM_DOMAIN_RENDER : 0); + + return Success; } -static Status setup_surfaces(struct media_state *media_state, - dri_bo *dst_bo, dri_bo *past_bo, dri_bo *future_bo, - int w, int h) +static Status setup_surfaces(struct media_state *media_state, + dri_bo * dst_bo, dri_bo * past_bo, + dri_bo * future_bo, int w, int h) { - Status ret; - ret = setup_media_surface(media_state, 0, dst_bo, 0, w, h, TRUE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 1, dst_bo, w*h, w/2, h/2, TRUE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 2, dst_bo, w*h + w*h/4, w/2, h/2, TRUE); - if (ret != Success) - return ret; - if (past_bo) { - ret = setup_media_surface(media_state, 4, past_bo, 0, w, h, FALSE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 5, past_bo, w*h, w/2, h/2, FALSE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 6, past_bo, w*h + w*h/4, w/2, h/2, FALSE); - if (ret != Success) - return ret; - } - if (future_bo) { - ret = setup_media_surface(media_state, 7, future_bo, 0, w, h, FALSE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 8, future_bo, w*h, w/2, h/2, FALSE); - if (ret != Success) - return ret; - ret = setup_media_surface(media_state, 9, future_bo, w*h + w*h/4, w/2, h/2, FALSE); - if (ret != Success) - return ret; - } - return Success; + Status ret; + ret = setup_media_surface(media_state, 0, dst_bo, 0, w, h, TRUE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 1, dst_bo, w * h, w / 2, h / 2, + TRUE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 2, dst_bo, w * h + w * h / 4, + w / 2, h / 2, TRUE); + if (ret != Success) + return ret; + if (past_bo) { + ret = + setup_media_surface(media_state, 4, past_bo, 0, w, h, + FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 5, past_bo, w * h, w / 2, + h / 2, FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 6, past_bo, + w * h + w * h / 4, w / 2, h / 2, FALSE); + if (ret != Success) + return ret; + } + if (future_bo) { + ret = + setup_media_surface(media_state, 7, future_bo, 0, w, h, + FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 8, future_bo, w * h, w / 2, + h / 2, FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(media_state, 9, future_bo, + w * h + w * h / 4, w / 2, h / 2, FALSE); + if (ret != Success) + return ret; + } + return Success; } + /* BUFFER SURFACE has a strange format * the size of the surface is in part of w h and d component */ -static Status setup_blocks(struct media_state *media_state, unsigned int block_size) +static Status setup_blocks(struct media_state *media_state, + unsigned int block_size) { - union element{ + union element { struct { unsigned int w:7; unsigned int h:13; unsigned int d:7; unsigned int pad:7; - }whd; - unsigned int size; - }e; - struct brw_surface_state ss; - memset(&ss, 0, sizeof(struct brw_surface_state)); - ss.ss0.surface_type = BRW_SURFACE_BUFFER; - ss.ss0.surface_format = BRW_SURFACEFORMAT_R8_UINT; - ss.ss1.base_addr = media_state->indirect_data.bo->offset; - - e.size = block_size - 1; - ss.ss2.width = e.whd.w; - ss.ss2.height = e.whd.h; - ss.ss3.depth = e.whd.d; - ss.ss3.pitch = block_size - 1; - - if (media_state->binding_table.surface_states[3].bo) - drm_intel_bo_unreference(media_state->binding_table.surface_states[3].bo); - - media_state->binding_table.surface_states[3].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", - sizeof(struct brw_surface_state), 0x1000); - if (!media_state->binding_table.surface_states[3].bo) - return BadAlloc; - - drm_intel_bo_subdata(media_state->binding_table.surface_states[3].bo, 0, - sizeof(ss), &ss); - - drm_intel_bo_emit_reloc(media_state->binding_table.surface_states[3].bo, - offsetof(struct brw_surface_state, ss1), - media_state->indirect_data.bo, 0, - I915_GEM_DOMAIN_SAMPLER, 0); - return Success; + } whd; + unsigned int size; + } e; + struct brw_surface_state ss; + memset(&ss, 0, sizeof(struct brw_surface_state)); + ss.ss0.surface_type = BRW_SURFACE_BUFFER; + ss.ss0.surface_format = BRW_SURFACEFORMAT_R8_UINT; + ss.ss1.base_addr = media_state->indirect_data.bo->offset; + + e.size = block_size - 1; + ss.ss2.width = e.whd.w; + ss.ss2.height = e.whd.h; + ss.ss3.depth = e.whd.d; + ss.ss3.pitch = block_size - 1; + + if (media_state->binding_table.surface_states[3].bo) + drm_intel_bo_unreference(media_state-> + binding_table.surface_states[3].bo); + + media_state->binding_table.surface_states[3].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", + sizeof(struct brw_surface_state), 0x1000); + if (!media_state->binding_table.surface_states[3].bo) + return BadAlloc; + + drm_intel_bo_subdata(media_state->binding_table.surface_states[3].bo, 0, + sizeof(ss), &ss); + + drm_intel_bo_emit_reloc(media_state->binding_table.surface_states[3].bo, + offsetof(struct brw_surface_state, ss1), + media_state->indirect_data.bo, 0, + I915_GEM_DOMAIN_SAMPLER, 0); + return Success; } /* setup state base address */ static void state_base_address() { - BATCH_LOCALS; - BEGIN_BATCH(6); - OUT_BATCH(BRW_STATE_BASE_ADDRESS | 4); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0xFFFFF000|BASE_ADDRESS_MODIFY); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(6); + OUT_BATCH(BRW_STATE_BASE_ADDRESS | 4); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0xFFFFF000 | BASE_ADDRESS_MODIFY); + ADVANCE_BATCH(); } /* select media pipeline */ static void pipeline_select(struct media_state *media_state) { - BATCH_LOCALS; - BEGIN_BATCH(1); - if (media_state->is_g4x) - OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA); - else - OUT_BATCH(BRW_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(1); + if (media_state->is_g4x) + OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA); + else + OUT_BATCH(BRW_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA); + ADVANCE_BATCH(); } /* kick media object to gpu */ -static void send_media_object(XvMCMacroBlock *mb, int offset, enum interface interface) +static void send_media_object(XvMCMacroBlock * mb, int offset, + enum interface interface) { - BATCH_LOCALS; - BEGIN_BATCH(13); - OUT_BATCH(BRW_MEDIA_OBJECT|11); - OUT_BATCH(interface); - if (media_state.is_965_q) { - OUT_BATCH(0); - OUT_BATCH(0); - }else { - OUT_BATCH(6*128); - OUT_RELOC(media_state.indirect_data.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, offset); - } - - OUT_BATCH(mb->x<<4); //g1.0 - OUT_BATCH(mb->y<<4); - OUT_RELOC(media_state.indirect_data.bo, //g1.8 - I915_GEM_DOMAIN_INSTRUCTION, 0, offset); - OUT_BATCH_SHORT(mb->coded_block_pattern); //g1.12 - OUT_BATCH_SHORT(mb->PMV[0][0][0]); //g1.14 - OUT_BATCH_SHORT(mb->PMV[0][0][1]); //g1.16 - OUT_BATCH_SHORT(mb->PMV[0][1][0]); //g1.18 - OUT_BATCH_SHORT(mb->PMV[0][1][1]); //g1.20 - - OUT_BATCH_SHORT(mb->PMV[1][0][0]); //g1.22 - OUT_BATCH_SHORT(mb->PMV[1][0][1]); //g1.24 - OUT_BATCH_SHORT(mb->PMV[1][1][0]); //g1.26 - OUT_BATCH_SHORT(mb->PMV[1][1][1]); //g1.28 - OUT_BATCH_CHAR(mb->dct_type); //g1.30 - OUT_BATCH_CHAR(mb->motion_vertical_field_select);//g1.31 - - if (media_state.is_965_q) - OUT_BATCH(0x0); - else - OUT_BATCH(0xffffffff); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(13); + OUT_BATCH(BRW_MEDIA_OBJECT | 11); + OUT_BATCH(interface); + if (media_state.is_965_q) { + OUT_BATCH(0); + OUT_BATCH(0); + } else { + OUT_BATCH(6 * 128); + OUT_RELOC(media_state.indirect_data.bo, + I915_GEM_DOMAIN_INSTRUCTION, 0, offset); + } + + OUT_BATCH(mb->x << 4); //g1.0 + OUT_BATCH(mb->y << 4); + OUT_RELOC(media_state.indirect_data.bo, //g1.8 + I915_GEM_DOMAIN_INSTRUCTION, 0, offset); + OUT_BATCH_SHORT(mb->coded_block_pattern); //g1.12 + OUT_BATCH_SHORT(mb->PMV[0][0][0]); //g1.14 + OUT_BATCH_SHORT(mb->PMV[0][0][1]); //g1.16 + OUT_BATCH_SHORT(mb->PMV[0][1][0]); //g1.18 + OUT_BATCH_SHORT(mb->PMV[0][1][1]); //g1.20 + + OUT_BATCH_SHORT(mb->PMV[1][0][0]); //g1.22 + OUT_BATCH_SHORT(mb->PMV[1][0][1]); //g1.24 + OUT_BATCH_SHORT(mb->PMV[1][1][0]); //g1.26 + OUT_BATCH_SHORT(mb->PMV[1][1][1]); //g1.28 + OUT_BATCH_CHAR(mb->dct_type); //g1.30 + OUT_BATCH_CHAR(mb->motion_vertical_field_select); //g1.31 + + if (media_state.is_965_q) + OUT_BATCH(0x0); + else + OUT_BATCH(0xffffffff); + ADVANCE_BATCH(); } static Status binding_tables(struct media_state *media_state) { - unsigned int binding_table[MAX_SURFACE_NUM]; - int i; - - if (media_state->binding_table.bo) - drm_intel_bo_unreference(media_state->binding_table.bo); - media_state->binding_table.bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "binding_table", - MAX_SURFACE_NUM*4, 0x1000); - if (!media_state->binding_table.bo) - return BadAlloc; - - for (i = 0; i < MAX_SURFACE_NUM; i++) - binding_table[i] = media_state->binding_table.surface_states[i].bo->offset; - drm_intel_bo_subdata(media_state->binding_table.bo, 0, sizeof(binding_table), - binding_table); - - for (i = 0; i < MAX_SURFACE_NUM; i++) - drm_intel_bo_emit_reloc(media_state->binding_table.bo, - i * sizeof(unsigned int), - media_state->binding_table.surface_states[i].bo, 0, - I915_GEM_DOMAIN_INSTRUCTION, 0); - return Success; + unsigned int binding_table[MAX_SURFACE_NUM]; + int i; + + if (media_state->binding_table.bo) + drm_intel_bo_unreference(media_state->binding_table.bo); + media_state->binding_table.bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "binding_table", + MAX_SURFACE_NUM * 4, 0x1000); + if (!media_state->binding_table.bo) + return BadAlloc; + + for (i = 0; i < MAX_SURFACE_NUM; i++) + binding_table[i] = + media_state->binding_table.surface_states[i].bo->offset; + drm_intel_bo_subdata(media_state->binding_table.bo, 0, + sizeof(binding_table), binding_table); + + for (i = 0; i < MAX_SURFACE_NUM; i++) + drm_intel_bo_emit_reloc(media_state->binding_table.bo, + i * sizeof(unsigned int), + media_state-> + binding_table.surface_states[i].bo, 0, + I915_GEM_DOMAIN_INSTRUCTION, 0); + return Success; } static int media_kernels(struct media_state *media_state) @@ -532,8 +588,8 @@ static int media_kernels(struct media_state *media_state) for (i = 0; i < kernel_array_size; i++) { media_state->vfe_state.interface.kernels[i].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernel", - kernels[i].size, 0x1000); + drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernel", + kernels[i].size, 0x1000); if (!media_state->vfe_state.interface.kernels[i].bo) goto out; } @@ -548,51 +604,51 @@ out: return BadAlloc; } -static void setup_interface(struct media_state *media_state, - enum interface i) +static void setup_interface(struct media_state *media_state, enum interface i) { - struct brw_interface_descriptor desc; - memset(&desc, 0, sizeof(desc)); - - desc.desc0.grf_reg_blocks = 15; - desc.desc0.kernel_start_pointer = - media_state->vfe_state.interface.kernels[i].bo->offset >> 6; - - desc.desc1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; - - /* use same binding table for all interface - * may change this if it affect performance - */ - desc.desc3.binding_table_entry_count = MAX_SURFACE_NUM; - desc.desc3.binding_table_pointer = media_state->binding_table.bo->offset >> 5; - - drm_intel_bo_subdata(media_state->vfe_state.interface.bo, i*sizeof(desc), - sizeof(desc), &desc); - - drm_intel_bo_emit_reloc( - media_state->vfe_state.interface.bo, - i * sizeof(desc) + - offsetof(struct brw_interface_descriptor, desc0), - media_state->vfe_state.interface.kernels[i].bo, - desc.desc0.grf_reg_blocks, - I915_GEM_DOMAIN_INSTRUCTION, 0); - - drm_intel_bo_emit_reloc( - media_state->vfe_state.interface.bo, - i * sizeof(desc) + - offsetof(struct brw_interface_descriptor, desc3), - media_state->binding_table.bo, - desc.desc3.binding_table_entry_count, - I915_GEM_DOMAIN_INSTRUCTION, 0); + struct brw_interface_descriptor desc; + memset(&desc, 0, sizeof(desc)); + + desc.desc0.grf_reg_blocks = 15; + desc.desc0.kernel_start_pointer = + media_state->vfe_state.interface.kernels[i].bo->offset >> 6; + + desc.desc1.floating_point_mode = BRW_FLOATING_POINT_NON_IEEE_754; + + /* use same binding table for all interface + * may change this if it affect performance + */ + desc.desc3.binding_table_entry_count = MAX_SURFACE_NUM; + desc.desc3.binding_table_pointer = + media_state->binding_table.bo->offset >> 5; + + drm_intel_bo_subdata(media_state->vfe_state.interface.bo, + i * sizeof(desc), sizeof(desc), &desc); + + drm_intel_bo_emit_reloc(media_state->vfe_state.interface.bo, + i * sizeof(desc) + + offsetof(struct brw_interface_descriptor, + desc0), + media_state->vfe_state.interface.kernels[i].bo, + desc.desc0.grf_reg_blocks, + I915_GEM_DOMAIN_INSTRUCTION, 0); + + drm_intel_bo_emit_reloc(media_state->vfe_state.interface.bo, + i * sizeof(desc) + + offsetof(struct brw_interface_descriptor, + desc3), media_state->binding_table.bo, + desc.desc3.binding_table_entry_count, + I915_GEM_DOMAIN_INSTRUCTION, 0); } static Status interface_descriptor(struct media_state *media_state) { if (media_state->vfe_state.interface.bo) drm_intel_bo_unreference(media_state->vfe_state.interface.bo); - media_state->vfe_state.interface.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "interfaces", DESCRIPTOR_NUM*sizeof(struct brw_interface_descriptor), - 0x1000); + media_state->vfe_state.interface.bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "interfaces", + DESCRIPTOR_NUM * + sizeof(struct brw_interface_descriptor), 0x1000); if (!media_state->vfe_state.interface.bo) return BadAlloc; @@ -620,184 +676,215 @@ static Status vfe_state(struct media_state *media_state) /* should carefully caculate those values for performance */ state.vfe1.urb_entry_alloc_size = 2; state.vfe1.max_threads = 31; - state.vfe2.interface_descriptor_base = - media_state->vfe_state.interface.bo->offset >> 4; + state.vfe2.interface_descriptor_base = + media_state->vfe_state.interface.bo->offset >> 4; if (media_state->vfe_state.bo) drm_intel_bo_unreference(media_state->vfe_state.bo); media_state->vfe_state.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "vfe state", sizeof(struct brw_vfe_state), 0x1000); + "vfe state", + sizeof(struct + brw_vfe_state), + 0x1000); if (!media_state->vfe_state.bo) return BadAlloc; - drm_intel_bo_subdata(media_state->vfe_state.bo, 0, sizeof(state), &state); + drm_intel_bo_subdata(media_state->vfe_state.bo, 0, sizeof(state), + &state); drm_intel_bo_emit_reloc(media_state->vfe_state.bo, - offsetof(struct brw_vfe_state, vfe2), - media_state->vfe_state.interface.bo, 0, - I915_GEM_DOMAIN_INSTRUCTION, 0); + offsetof(struct brw_vfe_state, vfe2), + media_state->vfe_state.interface.bo, 0, + I915_GEM_DOMAIN_INSTRUCTION, 0); return Success; } -static Status render_surface(Display *display, - XvMCContext *context, - unsigned int picture_structure, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - unsigned int flags, - unsigned int num_macroblocks, - unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, - XvMCBlockArray *blocks) +static Status render_surface(Display * display, + XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks) { - intel_xvmc_context_ptr intel_ctx; - int i, j; - struct i965_xvmc_context *i965_ctx; - XvMCMacroBlock *mb; - struct i965_xvmc_surface *priv_target_surface = - target_surface->privData; - struct i965_xvmc_surface *priv_past_surface = - past_surface?past_surface->privData:0; - struct i965_xvmc_surface *priv_future_surface = - future_surface?future_surface->privData:0; - unsigned short *block_ptr; - intel_ctx = intel_xvmc_find_context(context->context_id); - i965_ctx = context->privData; - if (!intel_ctx) { - XVMC_ERR("Can't find intel xvmc context\n"); - return BadValue; - } - - if (media_state.indirect_data.bo) { - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_unmap_gtt(media_state.indirect_data.bo); - else - drm_intel_bo_unmap(media_state.indirect_data.bo); - - drm_intel_bo_unreference(media_state.indirect_data.bo); - } - media_state.indirect_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "indirect data", 128*6*num_macroblocks, 64); - if (!media_state.indirect_data.bo) - return BadAlloc; - setup_surfaces(&media_state, - priv_target_surface->bo, - past_surface? priv_past_surface->bo:NULL, - future_surface?priv_future_surface->bo:NULL, - context->width, context->height); - setup_blocks(&media_state, 128*6*num_macroblocks); - binding_tables(&media_state); - interface_descriptor(&media_state); - vfe_state(&media_state); - - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(media_state.indirect_data.bo); - else - drm_intel_bo_map(media_state.indirect_data.bo, 1); - - block_ptr = media_state.indirect_data.bo->virtual; - for (i = first_macroblock; - i < num_macroblocks + first_macroblock; i++) { - unsigned short *mb_block_ptr; - mb = ¯oblock_array->macro_blocks[i]; - mb_block_ptr = &blocks->blocks[(mb->index<<6)]; - if (mb->coded_block_pattern & 0x20) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; + intel_xvmc_context_ptr intel_ctx; + int i, j; + struct i965_xvmc_context *i965_ctx; + XvMCMacroBlock *mb; + struct i965_xvmc_surface *priv_target_surface = + target_surface->privData; + struct i965_xvmc_surface *priv_past_surface = + past_surface ? past_surface->privData : 0; + struct i965_xvmc_surface *priv_future_surface = + future_surface ? future_surface->privData : 0; + unsigned short *block_ptr; + intel_ctx = intel_xvmc_find_context(context->context_id); + i965_ctx = context->privData; + if (!intel_ctx) { + XVMC_ERR("Can't find intel xvmc context\n"); + return BadValue; } - if (mb->coded_block_pattern & 0x10) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j + 8, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; - } - block_ptr += 2*64; - if (mb->coded_block_pattern & 0x08) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; - } + if (media_state.indirect_data.bo) { + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_unmap_gtt(media_state. + indirect_data.bo); + else + drm_intel_bo_unmap(media_state.indirect_data.bo); - if (mb->coded_block_pattern & 0x04) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j + 8, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; + drm_intel_bo_unreference(media_state.indirect_data.bo); } + media_state.indirect_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, + "indirect data", + 128 * 6 * + num_macroblocks, 64); + if (!media_state.indirect_data.bo) + return BadAlloc; + setup_surfaces(&media_state, + priv_target_surface->bo, + past_surface ? priv_past_surface->bo : NULL, + future_surface ? priv_future_surface->bo : NULL, + context->width, context->height); + setup_blocks(&media_state, 128 * 6 * num_macroblocks); + binding_tables(&media_state); + interface_descriptor(&media_state); + vfe_state(&media_state); + + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_map_gtt(media_state.indirect_data.bo); + else + drm_intel_bo_map(media_state.indirect_data.bo, 1); + + block_ptr = media_state.indirect_data.bo->virtual; + for (i = first_macroblock; i < num_macroblocks + first_macroblock; i++) { + unsigned short *mb_block_ptr; + mb = ¯oblock_array->macro_blocks[i]; + mb_block_ptr = &blocks->blocks[(mb->index << 6)]; + if (mb->coded_block_pattern & 0x20) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j, mb_block_ptr + 8 * j, + 16); + mb_block_ptr += 64; + } - block_ptr += 2*64; - if (mb->coded_block_pattern & 0x2) { - memcpy(block_ptr, mb_block_ptr, 128); - mb_block_ptr += 64; - } + if (mb->coded_block_pattern & 0x10) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j + 8, + mb_block_ptr + 8 * j, 16); + mb_block_ptr += 64; + } + block_ptr += 2 * 64; + if (mb->coded_block_pattern & 0x08) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j, mb_block_ptr + 8 * j, + 16); + mb_block_ptr += 64; + } + + if (mb->coded_block_pattern & 0x04) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j + 8, + mb_block_ptr + 8 * j, 16); + mb_block_ptr += 64; + } + + block_ptr += 2 * 64; + if (mb->coded_block_pattern & 0x2) { + memcpy(block_ptr, mb_block_ptr, 128); + mb_block_ptr += 64; + } - block_ptr += 64; - if (mb->coded_block_pattern & 0x1) - memcpy(block_ptr, mb_block_ptr, 128); - block_ptr += 64; - } - { - int block_offset = 0; - LOCK_HARDWARE(intel_ctx->hw_context); - state_base_address(); - flush(); - clear_sf_state(); - pipeline_select(&media_state); - urb_layout(); - media_state_pointers(&media_state); - for (i = first_macroblock; - i < num_macroblocks + first_macroblock; - i++, block_offset += 128*6) { - mb = ¯oblock_array->macro_blocks[i]; - - if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { - send_media_object(mb, block_offset, INTRA_INTERFACE); - } else { - if (((mb->motion_type & 3) == XVMC_PREDICTION_FRAME)) { - if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_FORWARD)) - { - if (((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD))) - send_media_object(mb, block_offset, F_B_INTERFACE); - else - send_media_object(mb, block_offset, FORWARD_INTERFACE); - } else if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD)) - { - send_media_object(mb, block_offset, BACKWARD_INTERFACE); - } - } else if ((mb->motion_type & 3) == XVMC_PREDICTION_FIELD) { - if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_FORWARD)) - { - if (((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD))) - send_media_object(mb, block_offset, FIELD_F_B_INTERFACE); - else - - send_media_object(mb, block_offset, FIELD_FORWARD_INTERFACE); - } else if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD)) - { - send_media_object(mb, block_offset, FIELD_BACKWARD_INTERFACE); - } - }else { - send_media_object(mb, block_offset, DUAL_PRIME_INTERFACE); + block_ptr += 64; + if (mb->coded_block_pattern & 0x1) + memcpy(block_ptr, mb_block_ptr, 128); + block_ptr += 64; + } + { + int block_offset = 0; + LOCK_HARDWARE(intel_ctx->hw_context); + state_base_address(); + flush(); + clear_sf_state(); + pipeline_select(&media_state); + urb_layout(); + media_state_pointers(&media_state); + for (i = first_macroblock; + i < num_macroblocks + first_macroblock; + i++, block_offset += 128 * 6) { + mb = ¯oblock_array->macro_blocks[i]; + + if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { + send_media_object(mb, block_offset, + INTRA_INTERFACE); + } else { + if (((mb->motion_type & 3) == + XVMC_PREDICTION_FRAME)) { + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_FORWARD)) { + if (((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD))) + send_media_object(mb, + block_offset, + F_B_INTERFACE); + else + send_media_object(mb, + block_offset, + FORWARD_INTERFACE); + } else + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD)) + { + send_media_object(mb, + block_offset, + BACKWARD_INTERFACE); + } + } else if ((mb->motion_type & 3) == + XVMC_PREDICTION_FIELD) { + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_FORWARD)) { + if (((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD))) + send_media_object(mb, + block_offset, + FIELD_F_B_INTERFACE); + else + + send_media_object(mb, + block_offset, + FIELD_FORWARD_INTERFACE); + } else + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD)) + { + send_media_object(mb, + block_offset, + FIELD_BACKWARD_INTERFACE); + } + } else { + send_media_object(mb, block_offset, + DUAL_PRIME_INTERFACE); + } + } } - } + intelFlushBatch(TRUE); + UNLOCK_HARDWARE(intel_ctx->hw_context); } - intelFlushBatch(TRUE); - UNLOCK_HARDWARE(intel_ctx->hw_context); - } - return Success; + return Success; } -static Status put_surface(Display *display,XvMCSurface *surface, - Drawable draw, short srcx, short srcy, - unsigned short srcw, unsigned short srch, - short destx, short desty, - unsigned short destw, unsigned short desth, - int flags, struct intel_xvmc_command *data) +static Status put_surface(Display * display, XvMCSurface * surface, + Drawable draw, short srcx, short srcy, + unsigned short srcw, unsigned short srch, + short destx, short desty, + unsigned short destw, unsigned short desth, + int flags, struct intel_xvmc_command *data) { - struct i965_xvmc_surface *private_surface = - surface->privData; + struct i965_xvmc_surface *private_surface = surface->privData; uint32_t handle = 0; drm_intel_bo_flink(private_surface->bo, &handle); @@ -806,38 +893,37 @@ static Status put_surface(Display *display,XvMCSurface *surface, return Success; } -static Status get_surface_status(Display *display, - XvMCSurface *surface, int *stats) +static Status get_surface_status(Display * display, + XvMCSurface * surface, int *stats) { - *stats = 0; - return 0; + *stats = 0; + return 0; } -static Status create_context(Display *display, XvMCContext *context, - int priv_count, CARD32 *priv_data) +static Status create_context(Display * display, XvMCContext * context, + int priv_count, CARD32 * priv_data) { - struct i965_xvmc_context *i965_ctx; - i965_ctx = (struct i965_xvmc_context *)priv_data; - context->privData = i965_ctx; - - media_state.is_g4x = i965_ctx->is_g4x; - media_state.is_965_q = i965_ctx->is_965_q; - - if (alloc_object(&media_state)) - return BadAlloc; - if (media_kernels(&media_state)) - return BadAlloc; - return Success; + struct i965_xvmc_context *i965_ctx; + i965_ctx = (struct i965_xvmc_context *)priv_data; + context->privData = i965_ctx; + + media_state.is_g4x = i965_ctx->is_g4x; + media_state.is_965_q = i965_ctx->is_965_q; + + if (alloc_object(&media_state)) + return BadAlloc; + if (media_kernels(&media_state)) + return BadAlloc; + return Success; } struct _intel_xvmc_driver i965_xvmc_mc_driver = { - .type = XVMC_I965_MPEG2_MC, - .create_context = create_context, - .destroy_context = destroy_context, - .create_surface = create_surface, - .destroy_surface = destroy_surface, - .render_surface = render_surface, - .put_surface = put_surface, - .get_surface_status = get_surface_status, + .type = XVMC_I965_MPEG2_MC, + .create_context = create_context, + .destroy_context = destroy_context, + .create_surface = create_surface, + .destroy_surface = destroy_surface, + .render_surface = render_surface, + .put_surface = put_surface, + .get_surface_status = get_surface_status, }; - diff --git a/src/xvmc/i965_xvmc.h b/src/xvmc/i965_xvmc.h index bbee76c0..ed201c89 100644 --- a/src/xvmc/i965_xvmc.h +++ b/src/xvmc/i965_xvmc.h @@ -1,2 +1 @@ #include "intel_xvmc.h" - diff --git a/src/xvmc/intel_batchbuffer.c b/src/xvmc/intel_batchbuffer.c index 8c96d7f1..ebaac7a4 100644 --- a/src/xvmc/intel_batchbuffer.c +++ b/src/xvmc/intel_batchbuffer.c @@ -48,142 +48,144 @@ #include "brw_defines.h" #include "brw_structs.h" #define MI_BATCH_BUFFER_END (0xA << 23) -#define BATCH_SIZE 8*1024 /* one bo is allocated each time, so the size can be small */ +#define BATCH_SIZE 8*1024 /* one bo is allocated each time, so the size can be small */ static int intelEmitIrqLocked(void) { - drmI830IrqEmit ie; - int ret, seq; + drmI830IrqEmit ie; + int ret, seq; - ie.irq_seq = &seq; - ret = drmCommandWriteRead(xvmc_driver->fd, DRM_I830_IRQ_EMIT, - &ie, sizeof(ie)); + ie.irq_seq = &seq; + ret = drmCommandWriteRead(xvmc_driver->fd, DRM_I830_IRQ_EMIT, + &ie, sizeof(ie)); - if ( ret ) { - fprintf(stderr, "%s: drmI830IrqEmit: %d\n", __FUNCTION__, ret); - exit(1); - } + if (ret) { + fprintf(stderr, "%s: drmI830IrqEmit: %d\n", __FUNCTION__, ret); + exit(1); + } - return seq; + return seq; } static void intelWaitIrq(int seq) { - int ret; - drmI830IrqWait iw; + int ret; + drmI830IrqWait iw; - iw.irq_seq = seq; + iw.irq_seq = seq; - do { - ret = drmCommandWrite(xvmc_driver->fd, DRM_I830_IRQ_WAIT, &iw, sizeof(iw) ); - } while (ret == -EAGAIN || ret == -EINTR); + do { + ret = + drmCommandWrite(xvmc_driver->fd, DRM_I830_IRQ_WAIT, &iw, + sizeof(iw)); + } while (ret == -EAGAIN || ret == -EINTR); - if (ret) { - fprintf(stderr, "%s: drmI830IrqWait: %d\n", __FUNCTION__, ret); - exit(1); - } + if (ret) { + fprintf(stderr, "%s: drmI830IrqWait: %d\n", __FUNCTION__, ret); + exit(1); + } } static void i965_end_batch(void) { - unsigned int size = xvmc_driver->batch.ptr - - xvmc_driver->batch.init_ptr; - if ((size & 4) == 0) { - *(unsigned int*)xvmc_driver->batch.ptr = 0; + unsigned int size = xvmc_driver->batch.ptr - + xvmc_driver->batch.init_ptr; + if ((size & 4) == 0) { + *(unsigned int *)xvmc_driver->batch.ptr = 0; + xvmc_driver->batch.ptr += 4; + } + *(unsigned int *)xvmc_driver->batch.ptr = MI_BATCH_BUFFER_END; xvmc_driver->batch.ptr += 4; - } - *(unsigned int*)xvmc_driver->batch.ptr = MI_BATCH_BUFFER_END; - xvmc_driver->batch.ptr += 4; } Bool intelInitBatchBuffer(void) { - int i; - - if((xvmc_driver->batch.buf = - drm_intel_bo_alloc(xvmc_driver->bufmgr, - "batch buffer", BATCH_SIZE, 0x1000)) == NULL) { - fprintf(stderr, "unable to alloc batch buffer\n"); - return False; - } - - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf); - else - drm_intel_bo_map(xvmc_driver->batch.buf, 1); - - xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual; - xvmc_driver->batch.size = BATCH_SIZE; - xvmc_driver->batch.space = BATCH_SIZE; - xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr; - return True; + int i; + + if ((xvmc_driver->batch.buf = + drm_intel_bo_alloc(xvmc_driver->bufmgr, + "batch buffer", BATCH_SIZE, 0x1000)) == NULL) { + fprintf(stderr, "unable to alloc batch buffer\n"); + return False; + } + + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf); + else + drm_intel_bo_map(xvmc_driver->batch.buf, 1); + + xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual; + xvmc_driver->batch.size = BATCH_SIZE; + xvmc_driver->batch.space = BATCH_SIZE; + xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr; + return True; } void intelFiniBatchBuffer(void) { - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf); - else - drm_intel_bo_unmap(xvmc_driver->batch.buf); + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf); + else + drm_intel_bo_unmap(xvmc_driver->batch.buf); - drm_intel_bo_unreference(xvmc_driver->batch.buf); + drm_intel_bo_unreference(xvmc_driver->batch.buf); } - -void intelFlushBatch(Bool refill ) +void intelFlushBatch(Bool refill) { - i965_end_batch(); - - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf); - else - drm_intel_bo_unmap(xvmc_driver->batch.buf); - - drm_intel_bo_exec(xvmc_driver->batch.buf, - xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr, - 0, 0, 0); - - if (xvmc_driver == &i915_xvmc_mc_driver) - dri_bo_wait_rendering(xvmc_driver->batch.buf); - - drm_intel_bo_unreference(xvmc_driver->batch.buf); - if((xvmc_driver->batch.buf = - drm_intel_bo_alloc(xvmc_driver->bufmgr, - "batch buffer", BATCH_SIZE, 0x1000)) == NULL) { - fprintf(stderr, "unable to alloc batch buffer\n"); - } - - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf); - else - drm_intel_bo_map(xvmc_driver->batch.buf, 1); - - xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual; - xvmc_driver->batch.size = BATCH_SIZE; - xvmc_driver->batch.space = BATCH_SIZE; - xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr; + i965_end_batch(); + + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_unmap_gtt(xvmc_driver->batch.buf); + else + drm_intel_bo_unmap(xvmc_driver->batch.buf); + + drm_intel_bo_exec(xvmc_driver->batch.buf, + xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr, + 0, 0, 0); + + if (xvmc_driver == &i915_xvmc_mc_driver) + dri_bo_wait_rendering(xvmc_driver->batch.buf); + + drm_intel_bo_unreference(xvmc_driver->batch.buf); + if ((xvmc_driver->batch.buf = + drm_intel_bo_alloc(xvmc_driver->bufmgr, + "batch buffer", BATCH_SIZE, 0x1000)) == NULL) { + fprintf(stderr, "unable to alloc batch buffer\n"); + } + + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_map_gtt(xvmc_driver->batch.buf); + else + drm_intel_bo_map(xvmc_driver->batch.buf, 1); + + xvmc_driver->batch.init_ptr = xvmc_driver->batch.buf->virtual; + xvmc_driver->batch.size = BATCH_SIZE; + xvmc_driver->batch.space = BATCH_SIZE; + xvmc_driver->batch.ptr = xvmc_driver->batch.init_ptr; } void intelBatchbufferRequireSpace(int size) { - assert(xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size < - xvmc_driver->batch.size - 8); - if (xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size - >= xvmc_driver->batch.size - 8) - intelFlushBatch(1); + assert(xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size < + xvmc_driver->batch.size - 8); + if (xvmc_driver->batch.ptr - xvmc_driver->batch.init_ptr + size + >= xvmc_driver->batch.size - 8) + intelFlushBatch(1); } void intelBatchbufferData(const void *data, unsigned bytes, unsigned flags) { - intelBatchbufferRequireSpace(bytes); - memcpy(xvmc_driver->batch.ptr, data, bytes); - xvmc_driver->batch.ptr += bytes; - xvmc_driver->batch.space -= bytes; + intelBatchbufferRequireSpace(bytes); + memcpy(xvmc_driver->batch.ptr, data, bytes); + xvmc_driver->batch.ptr += bytes; + xvmc_driver->batch.space -= bytes; } -void intel_batch_emit_reloc(dri_bo *bo, uint32_t read_domain, - uint32_t write_domain, uint32_t delta, unsigned char *ptr) +void intel_batch_emit_reloc(dri_bo * bo, uint32_t read_domain, + uint32_t write_domain, uint32_t delta, + unsigned char *ptr) { - drm_intel_bo_emit_reloc(xvmc_driver->batch.buf, - ptr - xvmc_driver->batch.init_ptr, bo, delta, - read_domain, write_domain); + drm_intel_bo_emit_reloc(xvmc_driver->batch.buf, + ptr - xvmc_driver->batch.init_ptr, bo, delta, + read_domain, write_domain); } diff --git a/src/xvmc/intel_batchbuffer.h b/src/xvmc/intel_batchbuffer.h index ea9058ce..6fa1c05b 100644 --- a/src/xvmc/intel_batchbuffer.h +++ b/src/xvmc/intel_batchbuffer.h @@ -52,6 +52,7 @@ extern void intelBatchbufferData(const void *, unsigned, unsigned); extern Bool intelInitBatchBuffer(void); extern void intelFiniBatchBuffer(void); extern void intelCmdIoctl(char *, unsigned); -extern void intel_batch_emit_reloc(dri_bo *bo, uint32_t read_domain, - uint32_t write_domain, uint32_t delta, unsigned char *); +extern void intel_batch_emit_reloc(dri_bo * bo, uint32_t read_domain, + uint32_t write_domain, uint32_t delta, + unsigned char *); #endif /* _INTEL_BATCHBUFFER_H */ diff --git a/src/xvmc/intel_xvmc.c b/src/xvmc/intel_xvmc.c index 06763aef..947f97d4 100644 --- a/src/xvmc/intel_xvmc.c +++ b/src/xvmc/intel_xvmc.c @@ -33,207 +33,208 @@ struct _intel_xvmc_driver *xvmc_driver = NULL; /* Lookup tables to speed common calculations for coded_block_pattern */ /* each block is ((8*8) * sizeof(short)) */ unsigned int mb_bytes_420[] = { - 0, /* 0 */ - 128, /* 1 */ - 128, /* 10 */ - 256, /* 11 */ - 128, /* 100 */ - 256, /* 101 */ - 256, /* 110 */ - 384, /* 111 */ - 128, /* 1000 */ - 256, /* 1001 */ - 256, /* 1010 */ - 384, /* 1011 */ - 256, /* 1100 */ - 384, /* 1101 */ - 384, /* 1110 */ - 512, /* 1111 */ - 128, /* 10000 */ - 256, /* 10001 */ - 256, /* 10010 */ - 384, /* 10011 */ - 256, /* 10100 */ - 384, /* 10101 */ - 384, /* 10110 */ - 512, /* 10111 */ - 256, /* 11000 */ - 384, /* 11001 */ - 384, /* 11010 */ - 512, /* 11011 */ - 384, /* 11100 */ - 512, /* 11101 */ - 512, /* 11110 */ - 640, /* 11111 */ - 128, /* 100000 */ - 256, /* 100001 */ - 256, /* 100010 */ - 384, /* 100011 */ - 256, /* 100100 */ - 384, /* 100101 */ - 384, /* 100110 */ - 512, /* 100111 */ - 256, /* 101000 */ - 384, /* 101001 */ - 384, /* 101010 */ - 512, /* 101011 */ - 384, /* 101100 */ - 512, /* 101101 */ - 512, /* 101110 */ - 640, /* 101111 */ - 256, /* 110000 */ - 384, /* 110001 */ - 384, /* 110010 */ - 512, /* 110011 */ - 384, /* 110100 */ - 512, /* 110101 */ - 512, /* 110110 */ - 640, /* 110111 */ - 384, /* 111000 */ - 512, /* 111001 */ - 512, /* 111010 */ - 640, /* 111011 */ - 512, /* 111100 */ - 640, /* 111101 */ - 640, /* 111110 */ - 768 /* 111111 */ + 0, /* 0 */ + 128, /* 1 */ + 128, /* 10 */ + 256, /* 11 */ + 128, /* 100 */ + 256, /* 101 */ + 256, /* 110 */ + 384, /* 111 */ + 128, /* 1000 */ + 256, /* 1001 */ + 256, /* 1010 */ + 384, /* 1011 */ + 256, /* 1100 */ + 384, /* 1101 */ + 384, /* 1110 */ + 512, /* 1111 */ + 128, /* 10000 */ + 256, /* 10001 */ + 256, /* 10010 */ + 384, /* 10011 */ + 256, /* 10100 */ + 384, /* 10101 */ + 384, /* 10110 */ + 512, /* 10111 */ + 256, /* 11000 */ + 384, /* 11001 */ + 384, /* 11010 */ + 512, /* 11011 */ + 384, /* 11100 */ + 512, /* 11101 */ + 512, /* 11110 */ + 640, /* 11111 */ + 128, /* 100000 */ + 256, /* 100001 */ + 256, /* 100010 */ + 384, /* 100011 */ + 256, /* 100100 */ + 384, /* 100101 */ + 384, /* 100110 */ + 512, /* 100111 */ + 256, /* 101000 */ + 384, /* 101001 */ + 384, /* 101010 */ + 512, /* 101011 */ + 384, /* 101100 */ + 512, /* 101101 */ + 512, /* 101110 */ + 640, /* 101111 */ + 256, /* 110000 */ + 384, /* 110001 */ + 384, /* 110010 */ + 512, /* 110011 */ + 384, /* 110100 */ + 512, /* 110101 */ + 512, /* 110110 */ + 640, /* 110111 */ + 384, /* 111000 */ + 512, /* 111001 */ + 512, /* 111010 */ + 640, /* 111011 */ + 512, /* 111100 */ + 640, /* 111101 */ + 640, /* 111110 */ + 768 /* 111111 */ }; int DEBUG; static void intel_xvmc_debug_init(void) { - if (getenv("INTEL_XVMC_DEBUG")) - DEBUG = 1; + if (getenv("INTEL_XVMC_DEBUG")) + DEBUG = 1; } void LOCK_HARDWARE(drm_context_t ctx) { - char __ret = 0; + char __ret = 0; - PPTHREAD_MUTEX_LOCK(); - assert(!xvmc_driver->locked); + PPTHREAD_MUTEX_LOCK(); + assert(!xvmc_driver->locked); - xvmc_driver->locked = 1; + xvmc_driver->locked = 1; } void UNLOCK_HARDWARE(drm_context_t ctx) { - xvmc_driver->locked = 0; - - PPTHREAD_MUTEX_UNLOCK(); + xvmc_driver->locked = 0; + + PPTHREAD_MUTEX_UNLOCK(); } -static intel_xvmc_context_ptr intel_xvmc_new_context(Display *dpy) +static intel_xvmc_context_ptr intel_xvmc_new_context(Display * dpy) { - intel_xvmc_context_ptr ret; + intel_xvmc_context_ptr ret; - ret = (intel_xvmc_context_ptr)calloc(1, sizeof(intel_xvmc_context_t)); - if (!ret) - return NULL; + ret = (intel_xvmc_context_ptr) calloc(1, sizeof(intel_xvmc_context_t)); + if (!ret) + return NULL; - if (!xvmc_driver->ctx_list) - ret->next = NULL; - else - ret->next = xvmc_driver->ctx_list; - xvmc_driver->ctx_list = ret; - xvmc_driver->num_ctx++; + if (!xvmc_driver->ctx_list) + ret->next = NULL; + else + ret->next = xvmc_driver->ctx_list; + xvmc_driver->ctx_list = ret; + xvmc_driver->num_ctx++; - return ret; + return ret; } static void intel_xvmc_free_context(XID id) { - intel_xvmc_context_ptr p = xvmc_driver->ctx_list; - intel_xvmc_context_ptr pre = p; - - while(p) { - if (p->context && p->context->context_id == id) { - if (p == xvmc_driver->ctx_list) - xvmc_driver->ctx_list = p->next; - else - pre->next = p->next; - break; + intel_xvmc_context_ptr p = xvmc_driver->ctx_list; + intel_xvmc_context_ptr pre = p; + + while (p) { + if (p->context && p->context->context_id == id) { + if (p == xvmc_driver->ctx_list) + xvmc_driver->ctx_list = p->next; + else + pre->next = p->next; + break; + } + pre = p; + p = p->next; + } + + if (p) { + free(p); + xvmc_driver->num_ctx--; } - pre = p; - p = p->next; - } - - if (p) { - free(p); - xvmc_driver->num_ctx--; - } } intel_xvmc_context_ptr intel_xvmc_find_context(XID id) { - intel_xvmc_context_ptr p = xvmc_driver->ctx_list; - - while(p) { - if (p->context && p->context->context_id == id) - return p; - p = p->next; - } - return NULL; + intel_xvmc_context_ptr p = xvmc_driver->ctx_list; + + while (p) { + if (p->context && p->context->context_id == id) + return p; + p = p->next; + } + return NULL; } -static intel_xvmc_surface_ptr intel_xvmc_new_surface(Display *dpy) +static intel_xvmc_surface_ptr intel_xvmc_new_surface(Display * dpy) { - intel_xvmc_surface_ptr ret; + intel_xvmc_surface_ptr ret; - ret = (intel_xvmc_surface_ptr)calloc(1, sizeof(intel_xvmc_surface_t)); - if (!ret) - return NULL; + ret = (intel_xvmc_surface_ptr) calloc(1, sizeof(intel_xvmc_surface_t)); + if (!ret) + return NULL; - if (!xvmc_driver->surf_list) - ret->next = NULL; - else - ret->next = xvmc_driver->surf_list; - xvmc_driver->surf_list = ret; - xvmc_driver->num_surf++; + if (!xvmc_driver->surf_list) + ret->next = NULL; + else + ret->next = xvmc_driver->surf_list; + xvmc_driver->surf_list = ret; + xvmc_driver->num_surf++; - ret->image = NULL; - ret->gc_init = FALSE; + ret->image = NULL; + ret->gc_init = FALSE; - return ret; + return ret; } static void intel_xvmc_free_surface(XID id) { - intel_xvmc_surface_ptr p = xvmc_driver->surf_list; - intel_xvmc_surface_ptr pre = p; - - while(p) { - if (p->surface && p->surface->surface_id == id) { - if (p == xvmc_driver->surf_list) - xvmc_driver->surf_list = p->next; - else - pre->next = p->next; - break; + intel_xvmc_surface_ptr p = xvmc_driver->surf_list; + intel_xvmc_surface_ptr pre = p; + + while (p) { + if (p->surface && p->surface->surface_id == id) { + if (p == xvmc_driver->surf_list) + xvmc_driver->surf_list = p->next; + else + pre->next = p->next; + break; + } + pre = p; + p = p->next; + } + + if (p) { + free(p); + xvmc_driver->num_surf--; } - pre = p; - p = p->next; - } - - if (p) { - free(p); - xvmc_driver->num_surf--; - } } intel_xvmc_surface_ptr intel_xvmc_find_surface(XID id) { - intel_xvmc_surface_ptr p = xvmc_driver->surf_list; - - while(p) { - if (p->surface && p->surface->surface_id == id) - return p; - p = p->next; - } - return NULL; + intel_xvmc_surface_ptr p = xvmc_driver->surf_list; + + while (p) { + if (p->surface && p->surface->surface_id == id) + return p; + p = p->next; + } + return NULL; } + /* * Function: XvMCCreateContext * Description: Create a XvMC context for the given surface parameters. @@ -250,188 +251,194 @@ intel_xvmc_surface_ptr intel_xvmc_find_surface(XID id) * returned by XvMCListSurfaceTypes. * Returns: Status */ -_X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, - int surface_type_id, int width, int height, - int flags, XvMCContext *context) +_X_EXPORT Status XvMCCreateContext(Display * display, XvPortID port, + int surface_type_id, int width, int height, + int flags, XvMCContext * context) { - Status ret; - CARD32 *priv_data = NULL; - struct _intel_xvmc_common *comm; - drm_magic_t magic; - int major, minor; - int error_base; - int event_base; - int priv_count; - int isCapable; - int screen = DefaultScreen(display); - intel_xvmc_context_ptr intel_ctx; - int fd; - char *driverName = NULL, *deviceName = NULL; - - /* Verify Obvious things first */ - if (!display || !context) - return BadValue; - - if (!(flags & XVMC_DIRECT)) { - XVMC_ERR("Indirect Rendering not supported! Using Direct."); - return BadValue; - } - - intel_xvmc_debug_init(); - - /* - Width, Height, and flags are checked against surface_type_id - and port for validity inside the X server, no need to check - here. - */ - context->surface_type_id = surface_type_id; - context->width = (unsigned short)((width + 15) & ~15); - context->height = (unsigned short)((height + 15) & ~15); - context->flags = flags; - context->port = port; - - if (!XvMCQueryExtension(display, &event_base, &error_base)) { - XVMC_ERR("XvMCExtension is not available!"); - return BadValue; - } - ret = XvMCQueryVersion(display, &major, &minor); - if (ret) { - XVMC_ERR("XvMCQueryVersion Failed, unable to determine protocol version."); - return ret; - } - - /* XXX: major and minor could be checked in future for XvMC - * protocol capability (i.e H.264/AVC decode available) - */ - - /* - Pass control to the X server to create a drm_context_t for us and - validate the with/height and flags. - */ - if ((ret = _xvmc_create_context(display, context, &priv_count, &priv_data))) { - XVMC_ERR("Unable to create XvMC Context."); - return ret; - } - XVMC_DBG("new context %d created\n", (int)context->context_id); - - comm = (struct _intel_xvmc_common *)priv_data; - - if (xvmc_driver == NULL || xvmc_driver->type != comm->type) { - switch (comm->type) { - case XVMC_I915_MPEG2_MC: - xvmc_driver = &i915_xvmc_mc_driver; - break; - case XVMC_I965_MPEG2_MC: - xvmc_driver = &i965_xvmc_mc_driver; - break; - case XVMC_I965_MPEG2_VLD: - xvmc_driver = &xvmc_vld_driver; - break; - case XVMC_I945_MPEG2_VLD: - default: - XVMC_ERR("unimplemented xvmc type %d", comm->type); - XFree(priv_data); - priv_data = NULL; + Status ret; + CARD32 *priv_data = NULL; + struct _intel_xvmc_common *comm; + drm_magic_t magic; + int major, minor; + int error_base; + int event_base; + int priv_count; + int isCapable; + int screen = DefaultScreen(display); + intel_xvmc_context_ptr intel_ctx; + int fd; + char *driverName = NULL, *deviceName = NULL; + + /* Verify Obvious things first */ + if (!display || !context) + return BadValue; + + if (!(flags & XVMC_DIRECT)) { + XVMC_ERR("Indirect Rendering not supported! Using Direct."); return BadValue; } - } - if (xvmc_driver == NULL || xvmc_driver->type != comm->type) { - XVMC_ERR("fail to load xvmc driver for type %d\n", comm->type); - return BadValue; - } - - XVMC_INFO("decoder type is %s", intel_xvmc_decoder_string(comm->type)); - - xvmc_driver->kernel_exec_fencing = comm->kernel_exec_fencing; - - /* assign local ctx info */ - intel_ctx = intel_xvmc_new_context(display); - if (!intel_ctx) { - XVMC_ERR("Intel XvMC context create fail\n"); - return BadAlloc; - } - intel_ctx->context = context; - - /* check DRI2 */ - ret = Success; - xvmc_driver->fd = -1; - - do { - if (!DRI2QueryExtension(display, &event_base, &error_base)) { - ret = BadValue; - break; - } - - if (!DRI2QueryVersion(display, &major, &minor)) { - ret = BadValue; - break; - } - - if (!DRI2Connect(display, RootWindow(display, screen), - &driverName, &deviceName)) { - ret = BadValue; - break; - } - - xvmc_driver->fd = open(deviceName, O_RDWR); - - if (xvmc_driver->fd < 0) { - XVMC_ERR("Failed to open drm device: %s\n", strerror(errno)); - ret = BadValue; - break; - } - - if (drmGetMagic(xvmc_driver->fd, &magic)) { - XVMC_ERR("Failed to get magic\n"); - ret = BadValue; - break; - } - - if (!DRI2Authenticate(display, RootWindow(display, screen), magic)) { - XVMC_ERR("Failed to authenticate magic %d\n", magic); - ret = BadValue; - break; - } - } while (0); - - XFree(driverName); - XFree(deviceName); - - if (ret != Success) { - XFree(priv_data); - context->privData = NULL; - - if (xvmc_driver->fd >= 0) - close(xvmc_driver->fd); - - xvmc_driver = NULL; - return ret; - } - - if ((xvmc_driver->bufmgr = - intel_bufmgr_gem_init(xvmc_driver->fd, 1024*64)) == NULL) { - XVMC_ERR("Can't init bufmgr\n"); - return BadAlloc; - } - drm_intel_bufmgr_gem_enable_reuse(xvmc_driver->bufmgr); - - /* call driver hook. - * driver hook should free priv_data after return if success.*/ - ret = (xvmc_driver->create_context)(display, context, priv_count, priv_data); - if (ret) { - XVMC_ERR("driver create context failed\n"); - XFree(priv_data); - context->privData = NULL; - xvmc_driver = NULL; - return ret; - } + intel_xvmc_debug_init(); + + /* + Width, Height, and flags are checked against surface_type_id + and port for validity inside the X server, no need to check + here. + */ + context->surface_type_id = surface_type_id; + context->width = (unsigned short)((width + 15) & ~15); + context->height = (unsigned short)((height + 15) & ~15); + context->flags = flags; + context->port = port; + + if (!XvMCQueryExtension(display, &event_base, &error_base)) { + XVMC_ERR("XvMCExtension is not available!"); + return BadValue; + } + ret = XvMCQueryVersion(display, &major, &minor); + if (ret) { + XVMC_ERR + ("XvMCQueryVersion Failed, unable to determine protocol version."); + return ret; + } - pthread_mutex_init(&xvmc_driver->ctxmutex, NULL); - intelInitBatchBuffer(); - intel_xvmc_dump_open(); + /* XXX: major and minor could be checked in future for XvMC + * protocol capability (i.e H.264/AVC decode available) + */ + + /* + Pass control to the X server to create a drm_context_t for us and + validate the with/height and flags. + */ + if ((ret = + _xvmc_create_context(display, context, &priv_count, &priv_data))) { + XVMC_ERR("Unable to create XvMC Context."); + return ret; + } + XVMC_DBG("new context %d created\n", (int)context->context_id); + + comm = (struct _intel_xvmc_common *)priv_data; + + if (xvmc_driver == NULL || xvmc_driver->type != comm->type) { + switch (comm->type) { + case XVMC_I915_MPEG2_MC: + xvmc_driver = &i915_xvmc_mc_driver; + break; + case XVMC_I965_MPEG2_MC: + xvmc_driver = &i965_xvmc_mc_driver; + break; + case XVMC_I965_MPEG2_VLD: + xvmc_driver = &xvmc_vld_driver; + break; + case XVMC_I945_MPEG2_VLD: + default: + XVMC_ERR("unimplemented xvmc type %d", comm->type); + XFree(priv_data); + priv_data = NULL; + return BadValue; + } + } + + if (xvmc_driver == NULL || xvmc_driver->type != comm->type) { + XVMC_ERR("fail to load xvmc driver for type %d\n", comm->type); + return BadValue; + } + + XVMC_INFO("decoder type is %s", intel_xvmc_decoder_string(comm->type)); + + xvmc_driver->kernel_exec_fencing = comm->kernel_exec_fencing; + + /* assign local ctx info */ + intel_ctx = intel_xvmc_new_context(display); + if (!intel_ctx) { + XVMC_ERR("Intel XvMC context create fail\n"); + return BadAlloc; + } + intel_ctx->context = context; + + /* check DRI2 */ + ret = Success; + xvmc_driver->fd = -1; + + do { + if (!DRI2QueryExtension(display, &event_base, &error_base)) { + ret = BadValue; + break; + } + + if (!DRI2QueryVersion(display, &major, &minor)) { + ret = BadValue; + break; + } + + if (!DRI2Connect(display, RootWindow(display, screen), + &driverName, &deviceName)) { + ret = BadValue; + break; + } + + xvmc_driver->fd = open(deviceName, O_RDWR); + + if (xvmc_driver->fd < 0) { + XVMC_ERR("Failed to open drm device: %s\n", + strerror(errno)); + ret = BadValue; + break; + } + + if (drmGetMagic(xvmc_driver->fd, &magic)) { + XVMC_ERR("Failed to get magic\n"); + ret = BadValue; + break; + } + + if (!DRI2Authenticate + (display, RootWindow(display, screen), magic)) { + XVMC_ERR("Failed to authenticate magic %d\n", magic); + ret = BadValue; + break; + } + } while (0); + + XFree(driverName); + XFree(deviceName); + + if (ret != Success) { + XFree(priv_data); + context->privData = NULL; + + if (xvmc_driver->fd >= 0) + close(xvmc_driver->fd); - return Success; + xvmc_driver = NULL; + return ret; + } + + if ((xvmc_driver->bufmgr = + intel_bufmgr_gem_init(xvmc_driver->fd, 1024 * 64)) == NULL) { + XVMC_ERR("Can't init bufmgr\n"); + return BadAlloc; + } + drm_intel_bufmgr_gem_enable_reuse(xvmc_driver->bufmgr); + + /* call driver hook. + * driver hook should free priv_data after return if success.*/ + ret = + (xvmc_driver->create_context) (display, context, priv_count, + priv_data); + if (ret) { + XVMC_ERR("driver create context failed\n"); + XFree(priv_data); + context->privData = NULL; + xvmc_driver = NULL; + return ret; + } + + pthread_mutex_init(&xvmc_driver->ctxmutex, NULL); + intelInitBatchBuffer(); + intel_xvmc_dump_open(); + + return Success; } /* @@ -443,201 +450,207 @@ _X_EXPORT Status XvMCCreateContext(Display *display, XvPortID port, * context - The context to be destroyed. * */ -_X_EXPORT Status XvMCDestroyContext(Display *display, XvMCContext *context) +_X_EXPORT Status XvMCDestroyContext(Display * display, XvMCContext * context) { - Status ret; - int screen; - - if (!display || !context) - return XvMCBadContext; - screen = DefaultScreen(display); - ret = (xvmc_driver->destroy_context)(display, context); - if (ret) { - XVMC_ERR("destroy context fail\n"); - return ret; - } + Status ret; + int screen; + + if (!display || !context) + return XvMCBadContext; + screen = DefaultScreen(display); + ret = (xvmc_driver->destroy_context) (display, context); + if (ret) { + XVMC_ERR("destroy context fail\n"); + return ret; + } - intelFiniBatchBuffer(); + intelFiniBatchBuffer(); - dri_bufmgr_destroy(xvmc_driver->bufmgr); + dri_bufmgr_destroy(xvmc_driver->bufmgr); - intel_xvmc_free_context(context->context_id); + intel_xvmc_free_context(context->context_id); - ret = _xvmc_destroy_context(display, context); - if (ret != Success) { - XVMC_ERR("_xvmc_destroy_context fail\n"); - return ret; - } + ret = _xvmc_destroy_context(display, context); + if (ret != Success) { + XVMC_ERR("_xvmc_destroy_context fail\n"); + return ret; + } - if (xvmc_driver->num_ctx == 0) { - pthread_mutex_destroy(&xvmc_driver->ctxmutex); + if (xvmc_driver->num_ctx == 0) { + pthread_mutex_destroy(&xvmc_driver->ctxmutex); - if (xvmc_driver->fd >= 0) - close(xvmc_driver->fd); - - xvmc_driver->fd = -1; - intel_xvmc_dump_close(); - } - return Success; + if (xvmc_driver->fd >= 0) + close(xvmc_driver->fd); + + xvmc_driver->fd = -1; + intel_xvmc_dump_close(); + } + return Success; } /* * Function: XvMCCreateSurface */ -_X_EXPORT Status XvMCCreateSurface(Display *display, XvMCContext *context, XvMCSurface *surface) +_X_EXPORT Status XvMCCreateSurface(Display * display, XvMCContext * context, + XvMCSurface * surface) { - Status ret; - int priv_count; - CARD32 *priv_data; - intel_xvmc_surface_ptr intel_surf = NULL; - - if (!display || !context) - return XvMCBadContext; - - if (!surface) - return XvMCBadSurface; - - intel_surf = intel_xvmc_new_surface(display); - if (!intel_surf) - return BadAlloc; - intel_surf->surface = surface; - - if ((ret = _xvmc_create_surface(display, context, surface, - &priv_count, &priv_data))) { - XVMC_ERR("Unable to create XvMCSurface."); - return ret; - } - - intel_surf->image = XvCreateImage(display, context->port, - FOURCC_XVMC, (char *)&intel_surf->data, surface->width, - surface->height); - if (!intel_surf->image) { - XVMC_ERR("Can't create XvImage for surface\n"); - _xvmc_destroy_surface(display, surface); - intel_xvmc_free_surface(surface->surface_id); - return BadAlloc; - } - intel_surf->image->data = (char *)&intel_surf->data; - - ret = (xvmc_driver->create_surface)(display, context, surface, priv_count, - priv_data); - if (ret) { - XVMC_ERR("create surface failed\n"); - return ret; - } + Status ret; + int priv_count; + CARD32 *priv_data; + intel_xvmc_surface_ptr intel_surf = NULL; + + if (!display || !context) + return XvMCBadContext; + + if (!surface) + return XvMCBadSurface; + + intel_surf = intel_xvmc_new_surface(display); + if (!intel_surf) + return BadAlloc; + intel_surf->surface = surface; + + if ((ret = _xvmc_create_surface(display, context, surface, + &priv_count, &priv_data))) { + XVMC_ERR("Unable to create XvMCSurface."); + return ret; + } - return Success; -} + intel_surf->image = XvCreateImage(display, context->port, + FOURCC_XVMC, + (char *)&intel_surf->data, + surface->width, surface->height); + if (!intel_surf->image) { + XVMC_ERR("Can't create XvImage for surface\n"); + _xvmc_destroy_surface(display, surface); + intel_xvmc_free_surface(surface->surface_id); + return BadAlloc; + } + intel_surf->image->data = (char *)&intel_surf->data; + + ret = + (xvmc_driver->create_surface) (display, context, surface, + priv_count, priv_data); + if (ret) { + XVMC_ERR("create surface failed\n"); + return ret; + } + return Success; +} /* * Function: XvMCDestroySurface */ -_X_EXPORT Status XvMCDestroySurface(Display *display, XvMCSurface *surface) +_X_EXPORT Status XvMCDestroySurface(Display * display, XvMCSurface * surface) { - intel_xvmc_surface_ptr intel_surf; + intel_xvmc_surface_ptr intel_surf; - if (!display || !surface) - return XvMCBadSurface; + if (!display || !surface) + return XvMCBadSurface; - intel_surf = intel_xvmc_find_surface(surface->surface_id); - if (!intel_surf) - return XvMCBadSurface; + intel_surf = intel_xvmc_find_surface(surface->surface_id); + if (!intel_surf) + return XvMCBadSurface; - XFree(intel_surf->image); - if (intel_surf->gc_init) - XFreeGC(display, intel_surf->gc); - intel_xvmc_free_surface(surface->surface_id); + XFree(intel_surf->image); + if (intel_surf->gc_init) + XFreeGC(display, intel_surf->gc); + intel_xvmc_free_surface(surface->surface_id); - (xvmc_driver->destroy_surface)(display, surface); + (xvmc_driver->destroy_surface) (display, surface); - _xvmc_destroy_surface(display, surface); + _xvmc_destroy_surface(display, surface); - return Success; + return Success; } /* * Function: XvMCCreateBlocks */ -_X_EXPORT Status XvMCCreateBlocks(Display *display, XvMCContext *context, - unsigned int num_blocks, - XvMCBlockArray *block) +_X_EXPORT Status XvMCCreateBlocks(Display * display, XvMCContext * context, + unsigned int num_blocks, + XvMCBlockArray * block) { - Status ret; - if (!display || !context || !num_blocks || !block) - return BadValue; + Status ret; + if (!display || !context || !num_blocks || !block) + return BadValue; - memset(block, 0, sizeof(XvMCBlockArray)); + memset(block, 0, sizeof(XvMCBlockArray)); - if (!(block->blocks = (short *)malloc((num_blocks << 6) * sizeof(short)))) - return BadAlloc; + if (! + (block->blocks = + (short *)malloc((num_blocks << 6) * sizeof(short)))) + return BadAlloc; - block->num_blocks = num_blocks; - block->context_id = context->context_id; - block->privData = NULL; + block->num_blocks = num_blocks; + block->context_id = context->context_id; + block->privData = NULL; - return Success; + return Success; } /* * Function: XvMCDestroyBlocks */ -_X_EXPORT Status XvMCDestroyBlocks(Display *display, XvMCBlockArray *block) +_X_EXPORT Status XvMCDestroyBlocks(Display * display, XvMCBlockArray * block) { - Status ret; - if (!display || !block) - return BadValue; + Status ret; + if (!display || !block) + return BadValue; - if (block->blocks) - free(block->blocks); + if (block->blocks) + free(block->blocks); - block->context_id = 0; - block->num_blocks = 0; - block->blocks = NULL; - block->privData = NULL; + block->context_id = 0; + block->num_blocks = 0; + block->blocks = NULL; + block->privData = NULL; - return Success; + return Success; } /* * Function: XvMCCreateMacroBlocks */ -_X_EXPORT Status XvMCCreateMacroBlocks(Display *display, XvMCContext *context, - unsigned int num_blocks, - XvMCMacroBlockArray *blocks) +_X_EXPORT Status XvMCCreateMacroBlocks(Display * display, XvMCContext * context, + unsigned int num_blocks, + XvMCMacroBlockArray * blocks) { - if (!display || !context || !blocks || !num_blocks) - return BadValue; + if (!display || !context || !blocks || !num_blocks) + return BadValue; - memset(blocks, 0, sizeof(XvMCMacroBlockArray)); - blocks->macro_blocks = (XvMCMacroBlock *)malloc(num_blocks * sizeof(XvMCMacroBlock)); + memset(blocks, 0, sizeof(XvMCMacroBlockArray)); + blocks->macro_blocks = + (XvMCMacroBlock *) malloc(num_blocks * sizeof(XvMCMacroBlock)); - if (!blocks->macro_blocks) - return BadAlloc; + if (!blocks->macro_blocks) + return BadAlloc; - blocks->num_blocks = num_blocks; - blocks->context_id = context->context_id; - blocks->privData = NULL; + blocks->num_blocks = num_blocks; + blocks->context_id = context->context_id; + blocks->privData = NULL; - return Success; + return Success; } /* * Function: XvMCDestroyMacroBlocks */ -_X_EXPORT Status XvMCDestroyMacroBlocks(Display *display, XvMCMacroBlockArray *block) +_X_EXPORT Status XvMCDestroyMacroBlocks(Display * display, + XvMCMacroBlockArray * block) { - if (!display || !block) - return BadValue; - if (block->macro_blocks) - free(block->macro_blocks); + if (!display || !block) + return BadValue; + if (block->macro_blocks) + free(block->macro_blocks); - block->context_id = 0; - block->num_blocks = 0; - block->macro_blocks = NULL; - block->privData = NULL; + block->context_id = 0; + block->num_blocks = 0; + block->macro_blocks = NULL; + block->privData = NULL; - return Success; + return Success; } /* @@ -647,40 +660,43 @@ _X_EXPORT Status XvMCDestroyMacroBlocks(Display *display, XvMCMacroBlockArray *b * macroblock structures it dispatched the hardware commands to execute * them. */ -_X_EXPORT Status XvMCRenderSurface(Display *display, XvMCContext *context, - unsigned int picture_structure, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - unsigned int flags, - unsigned int num_macroblocks, - unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, - XvMCBlockArray *blocks) +_X_EXPORT Status XvMCRenderSurface(Display * display, XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks) { - Status ret; - - if (!display || !context) { - XVMC_ERR("Invalid Display, Context or Target!"); - return XvMCBadContext; - } - if (!target_surface) - return XvMCBadSurface; - - intel_xvmc_dump_render(context, picture_structure, target_surface, - past_surface, future_surface, flags, num_macroblocks, - first_macroblock, macroblock_array, blocks); - - ret = (xvmc_driver->render_surface)(display, context, picture_structure, - target_surface, past_surface, future_surface, flags, - num_macroblocks, first_macroblock, macroblock_array, - blocks); - - if (ret) { - XVMC_ERR("render surface fail\n"); - return ret; - } - return Success; + Status ret; + + if (!display || !context) { + XVMC_ERR("Invalid Display, Context or Target!"); + return XvMCBadContext; + } + if (!target_surface) + return XvMCBadSurface; + + intel_xvmc_dump_render(context, picture_structure, target_surface, + past_surface, future_surface, flags, + num_macroblocks, first_macroblock, + macroblock_array, blocks); + + ret = + (xvmc_driver->render_surface) (display, context, picture_structure, + target_surface, past_surface, + future_surface, flags, + num_macroblocks, first_macroblock, + macroblock_array, blocks); + + if (ret) { + XVMC_ERR("render surface fail\n"); + return ret; + } + return Success; } /* @@ -708,46 +724,47 @@ _X_EXPORT Status XvMCRenderSurface(Display *display, XvMCContext *context, * XVMC_BOTTOM_FIELD - Display only the Bottom Field of the surface. * XVMC_FRAME_PICTURE - Display both fields or frame. */ -_X_EXPORT Status XvMCPutSurface(Display *display,XvMCSurface *surface, - Drawable draw, short srcx, short srcy, - unsigned short srcw, unsigned short srch, - short destx, short desty, - unsigned short destw, unsigned short desth, - int flags) +_X_EXPORT Status XvMCPutSurface(Display * display, XvMCSurface * surface, + Drawable draw, short srcx, short srcy, + unsigned short srcw, unsigned short srch, + short destx, short desty, + unsigned short destw, unsigned short desth, + int flags) { - Status ret = Success; - XvMCContext *context; - intel_xvmc_context_ptr intel_ctx; - intel_xvmc_surface_ptr intel_surf; - - if (!display || !surface) - return XvMCBadSurface; - - intel_ctx = intel_xvmc_find_context(surface->context_id); - intel_surf = intel_xvmc_find_surface(surface->surface_id); - if (!intel_ctx || !intel_surf) - return XvMCBadSurface; - context = intel_ctx->context; - - if (intel_surf->gc_init == FALSE) { - intel_surf->gc = XCreateGC(display, draw, 0, NULL); - intel_surf->gc_init = TRUE; - } else if (draw != intel_surf->last_draw) { - XFreeGC(display, intel_surf->gc); - intel_surf->gc = XCreateGC(display, draw, 0, NULL); - } - intel_surf->last_draw = draw; - /* fill intel_surf->data */ - ret = (xvmc_driver->put_surface)(display, surface, draw, srcx, srcy, - srcw, srch, destx, desty, destw, desth, flags, &intel_surf->data); - if (ret) { - XVMC_ERR("put surface fail\n"); + Status ret = Success; + XvMCContext *context; + intel_xvmc_context_ptr intel_ctx; + intel_xvmc_surface_ptr intel_surf; + + if (!display || !surface) + return XvMCBadSurface; + + intel_ctx = intel_xvmc_find_context(surface->context_id); + intel_surf = intel_xvmc_find_surface(surface->surface_id); + if (!intel_ctx || !intel_surf) + return XvMCBadSurface; + context = intel_ctx->context; + + if (intel_surf->gc_init == FALSE) { + intel_surf->gc = XCreateGC(display, draw, 0, NULL); + intel_surf->gc_init = TRUE; + } else if (draw != intel_surf->last_draw) { + XFreeGC(display, intel_surf->gc); + intel_surf->gc = XCreateGC(display, draw, 0, NULL); + } + intel_surf->last_draw = draw; + /* fill intel_surf->data */ + ret = (xvmc_driver->put_surface) (display, surface, draw, srcx, srcy, + srcw, srch, destx, desty, destw, + desth, flags, &intel_surf->data); + if (ret) { + XVMC_ERR("put surface fail\n"); + return ret; + } + ret = XvPutImage(display, context->port, draw, intel_surf->gc, + intel_surf->image, srcx, srcy, srcw, srch, destx, + desty, destw, desth); return ret; - } - ret = XvPutImage(display, context->port, draw, intel_surf->gc, - intel_surf->image, srcx, srcy, srcw, srch, destx, desty, - destw, desth); - return ret; } /* @@ -756,19 +773,19 @@ _X_EXPORT Status XvMCPutSurface(Display *display,XvMCSurface *surface, * display - Connection to the X server * surface - The surface to synchronize */ -_X_EXPORT Status XvMCSyncSurface(Display *display, XvMCSurface *surface) +_X_EXPORT Status XvMCSyncSurface(Display * display, XvMCSurface * surface) { - Status ret; - int stat = 0; + Status ret; + int stat = 0; - if (!display || !surface) - return XvMCBadSurface; + if (!display || !surface) + return XvMCBadSurface; - do { - ret = XvMCGetSurfaceStatus(display, surface, &stat); - } while (!ret && (stat & XVMC_RENDERING)); + do { + ret = XvMCGetSurfaceStatus(display, surface, &stat); + } while (!ret && (stat & XVMC_RENDERING)); - return ret; + return ret; } /* @@ -781,11 +798,11 @@ _X_EXPORT Status XvMCSyncSurface(Display *display, XvMCSurface *surface) * surface - Surface to flush * Returns: Status */ -_X_EXPORT Status XvMCFlushSurface(Display * display, XvMCSurface *surface) +_X_EXPORT Status XvMCFlushSurface(Display * display, XvMCSurface * surface) { - if (!display || !surface) - return XvMCBadSurface; - return Success; + if (!display || !surface) + return XvMCBadSurface; + return Success; } /* @@ -800,20 +817,21 @@ _X_EXPORT Status XvMCFlushSurface(Display * display, XvMCSurface *surface) * XVMC_DISPLAYING - The surface is currently being displayed or a * display is pending. */ -_X_EXPORT Status XvMCGetSurfaceStatus(Display *display, XvMCSurface *surface, int *stat) +_X_EXPORT Status XvMCGetSurfaceStatus(Display * display, XvMCSurface * surface, + int *stat) { - Status ret; + Status ret; - if (!display || !surface || !stat) - return XvMCBadSurface; + if (!display || !surface || !stat) + return XvMCBadSurface; - ret = (xvmc_driver->get_surface_status)(display, surface, stat); - if (ret) { - XVMC_ERR("get surface status fail\n"); - return ret; - } + ret = (xvmc_driver->get_surface_status) (display, surface, stat); + if (ret) { + XVMC_ERR("get surface status fail\n"); + return ret; + } - return Success; + return Success; } /* @@ -825,29 +843,29 @@ _X_EXPORT Status XvMCGetSurfaceStatus(Display *display, XvMCSurface *surface, in * * Returns: Status */ -_X_EXPORT Status XvMCHideSurface(Display *display, XvMCSurface *surface) +_X_EXPORT Status XvMCHideSurface(Display * display, XvMCSurface * surface) { - int stat = 0; - Status ret; + int stat = 0; + Status ret; - if (!display || !surface) - return XvMCBadSurface; + if (!display || !surface) + return XvMCBadSurface; - XvMCSyncSurface(display, surface); + XvMCSyncSurface(display, surface); - /* - Get the status of the surface, if it is not currently displayed - we don't need to worry about it. - */ - if ((ret = XvMCGetSurfaceStatus(display, surface, &stat)) != Success) - return ret; + /* + Get the status of the surface, if it is not currently displayed + we don't need to worry about it. + */ + if ((ret = XvMCGetSurfaceStatus(display, surface, &stat)) != Success) + return ret; - if (!(stat & XVMC_DISPLAYING)) - return Success; + if (!(stat & XVMC_DISPLAYING)) + return Success; - /* FIXME: */ - XVMC_ERR("XvMCHideSurface not implemented!\n"); - return BadValue; + /* FIXME: */ + XVMC_ERR("XvMCHideSurface not implemented!\n"); + return BadValue; } /* @@ -864,13 +882,13 @@ _X_EXPORT Status XvMCHideSurface(Display *display, XvMCSurface *surface) * * Returns: Status */ -_X_EXPORT Status XvMCCreateSubpicture(Display *display, XvMCContext *context, - XvMCSubpicture *subpicture, - unsigned short width, unsigned short height, - int xvimage_id) +_X_EXPORT Status XvMCCreateSubpicture(Display * display, XvMCContext * context, + XvMCSubpicture * subpicture, + unsigned short width, + unsigned short height, int xvimage_id) { - XVMC_ERR("XvMCCreateSubpicture not implemented!\n"); - return BadValue; + XVMC_ERR("XvMCCreateSubpicture not implemented!\n"); + return BadValue; } /* @@ -885,13 +903,13 @@ _X_EXPORT Status XvMCCreateSubpicture(Display *display, XvMCContext *context, * * Returns: Status */ -_X_EXPORT Status XvMCClearSubpicture(Display *display, XvMCSubpicture *subpicture, - short x, short y, - unsigned short width, unsigned short height, - unsigned int color) +_X_EXPORT Status XvMCClearSubpicture(Display * display, + XvMCSubpicture * subpicture, short x, + short y, unsigned short width, + unsigned short height, unsigned int color) { - XVMC_ERR("XvMCClearSubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCClearSubpicture not implemented!"); + return BadValue; } /* @@ -909,17 +927,17 @@ _X_EXPORT Status XvMCClearSubpicture(Display *display, XvMCSubpicture *subpictur * * Returns: Status */ -_X_EXPORT Status XvMCCompositeSubpicture(Display *display, XvMCSubpicture *subpicture, - XvImage *image, - short srcx, short srcy, - unsigned short width, unsigned short height, - short dstx, short dsty) +_X_EXPORT Status XvMCCompositeSubpicture(Display * display, + XvMCSubpicture * subpicture, + XvImage * image, short srcx, + short srcy, unsigned short width, + unsigned short height, short dstx, + short dsty) { - XVMC_ERR("XvMCCompositeSubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCCompositeSubpicture not implemented!"); + return BadValue; } - /* * Function: XvMCDestroySubpicture * Description: Destroys the specified subpicture. @@ -929,13 +947,13 @@ _X_EXPORT Status XvMCCompositeSubpicture(Display *display, XvMCSubpicture *subpi * * Returns: Status */ -_X_EXPORT Status XvMCDestroySubpicture(Display *display, XvMCSubpicture *subpicture) +_X_EXPORT Status XvMCDestroySubpicture(Display * display, + XvMCSubpicture * subpicture) { - XVMC_ERR("XvMCDestroySubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCDestroySubpicture not implemented!"); + return BadValue; } - /* * Function: XvMCSetSubpicturePalette * Description: Set the subpictures palette @@ -946,11 +964,12 @@ _X_EXPORT Status XvMCDestroySubpicture(Display *display, XvMCSubpicture *subpict * is num_palette_entries * entry_bytes in size. * Returns: Status */ -_X_EXPORT Status XvMCSetSubpicturePalette(Display *display, XvMCSubpicture *subpicture, - unsigned char *palette) +_X_EXPORT Status XvMCSetSubpicturePalette(Display * display, + XvMCSubpicture * subpicture, + unsigned char *palette) { - XVMC_ERR("XvMCSetSubpicturePalette not implemented!"); - return BadValue; + XVMC_ERR("XvMCSetSubpicturePalette not implemented!"); + return BadValue; } /* @@ -976,15 +995,16 @@ _X_EXPORT Status XvMCSetSubpicturePalette(Display *display, XvMCSubpicture *subp * * Returns: Status */ -_X_EXPORT Status XvMCBlendSubpicture(Display *display, XvMCSurface *target_surface, - XvMCSubpicture *subpicture, - short subx, short suby, - unsigned short subw, unsigned short subh, - short surfx, short surfy, - unsigned short surfw, unsigned short surfh) +_X_EXPORT Status XvMCBlendSubpicture(Display * display, + XvMCSurface * target_surface, + XvMCSubpicture * subpicture, short subx, + short suby, unsigned short subw, + unsigned short subh, short surfx, + short surfy, unsigned short surfw, + unsigned short surfh) { - XVMC_ERR("XvMCBlendSubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCBlendSubpicture not implemented!"); + return BadValue; } /* @@ -1013,17 +1033,18 @@ _X_EXPORT Status XvMCBlendSubpicture(Display *display, XvMCSurface *target_surfa * * Returns: Status */ -_X_EXPORT Status XvMCBlendSubpicture2(Display *display, - XvMCSurface *source_surface, - XvMCSurface *target_surface, - XvMCSubpicture *subpicture, - short subx, short suby, - unsigned short subw, unsigned short subh, - short surfx, short surfy, - unsigned short surfw, unsigned short surfh) +_X_EXPORT Status XvMCBlendSubpicture2(Display * display, + XvMCSurface * source_surface, + XvMCSurface * target_surface, + XvMCSubpicture * subpicture, + short subx, short suby, + unsigned short subw, unsigned short subh, + short surfx, short surfy, + unsigned short surfw, + unsigned short surfh) { - XVMC_ERR("XvMCBlendSubpicture2 not implemented!"); - return BadValue; + XVMC_ERR("XvMCBlendSubpicture2 not implemented!"); + return BadValue; } /* @@ -1036,10 +1057,11 @@ _X_EXPORT Status XvMCBlendSubpicture2(Display *display, * * Returns: Status */ -_X_EXPORT Status XvMCSyncSubpicture(Display *display, XvMCSubpicture *subpicture) +_X_EXPORT Status XvMCSyncSubpicture(Display * display, + XvMCSubpicture * subpicture) { - XVMC_ERR("XvMCSyncSubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCSyncSubpicture not implemented!"); + return BadValue; } /* @@ -1053,10 +1075,11 @@ _X_EXPORT Status XvMCSyncSubpicture(Display *display, XvMCSubpicture *subpicture * * Returns: Status */ -_X_EXPORT Status XvMCFlushSubpicture(Display *display, XvMCSubpicture *subpicture) +_X_EXPORT Status XvMCFlushSubpicture(Display * display, + XvMCSubpicture * subpicture) { - XVMC_ERR("XvMCFlushSubpicture not implemented!"); - return BadValue; + XVMC_ERR("XvMCFlushSubpicture not implemented!"); + return BadValue; } /* @@ -1073,11 +1096,11 @@ _X_EXPORT Status XvMCFlushSubpicture(Display *display, XvMCSubpicture *subpictur * * Returns: Status */ -_X_EXPORT Status XvMCGetSubpictureStatus(Display *display, XvMCSubpicture *subpicture, - int *stat) +_X_EXPORT Status XvMCGetSubpictureStatus(Display * display, + XvMCSubpicture * subpicture, int *stat) { - XVMC_ERR("XvMCGetSubpictureStatus not implemented!"); - return BadValue; + XVMC_ERR("XvMCGetSubpictureStatus not implemented!"); + return BadValue; } /* @@ -1094,12 +1117,12 @@ _X_EXPORT Status XvMCGetSubpictureStatus(Display *display, XvMCSubpicture *subpi * Returns: * An array of XvAttributes. */ -_X_EXPORT XvAttribute *XvMCQueryAttributes(Display *display, XvMCContext *context, - int *number) +_X_EXPORT XvAttribute *XvMCQueryAttributes(Display * display, + XvMCContext * context, int *number) { - /* now XvMC has no extra attribs than Xv */ - *number = 0; - return NULL; + /* now XvMC has no extra attribs than Xv */ + *number = 0; + return NULL; } /* @@ -1115,10 +1138,10 @@ _X_EXPORT XvAttribute *XvMCQueryAttributes(Display *display, XvMCContext *contex * Returns: * Status */ -_X_EXPORT Status XvMCSetAttribute(Display *display, XvMCContext *context, - Atom attribute, int value) +_X_EXPORT Status XvMCSetAttribute(Display * display, XvMCContext * context, + Atom attribute, int value) { - return Success; + return Success; } /* @@ -1135,52 +1158,53 @@ _X_EXPORT Status XvMCSetAttribute(Display *display, XvMCContext *context, * Returns: * Status */ -_X_EXPORT Status XvMCGetAttribute(Display *display, XvMCContext *context, - Atom attribute, int *value) +_X_EXPORT Status XvMCGetAttribute(Display * display, XvMCContext * context, + Atom attribute, int *value) { - return Success; + return Success; } -_X_EXPORT Status XvMCBeginSurface(Display *display, XvMCContext *context, - XvMCSurface *target, - XvMCSurface *past, - XvMCSurface *future, - const XvMCMpegControl *control) +_X_EXPORT Status XvMCBeginSurface(Display * display, XvMCContext * context, + XvMCSurface * target, + XvMCSurface * past, + XvMCSurface * future, + const XvMCMpegControl * control) { - if (xvmc_driver->begin_surface(display, context, - target, past, future, control)) { - XVMC_ERR("BeginSurface fail\n"); - return BadValue; - } - return Success; + if (xvmc_driver->begin_surface(display, context, + target, past, future, control)) { + XVMC_ERR("BeginSurface fail\n"); + return BadValue; + } + return Success; } -_X_EXPORT Status XvMCLoadQMatrix(Display *display, XvMCContext *context, - const XvMCQMatrix *qmx) +_X_EXPORT Status XvMCLoadQMatrix(Display * display, XvMCContext * context, + const XvMCQMatrix * qmx) { - if (xvmc_driver->load_qmatrix(display, context, qmx)) { - XVMC_ERR("LoadQMatrix fail\n"); - return BadValue; - } - return Success; + if (xvmc_driver->load_qmatrix(display, context, qmx)) { + XVMC_ERR("LoadQMatrix fail\n"); + return BadValue; + } + return Success; } -_X_EXPORT Status XvMCPutSlice(Display *display, XvMCContext *context, - char *slice, int nbytes) +_X_EXPORT Status XvMCPutSlice(Display * display, XvMCContext * context, + char *slice, int nbytes) { - if (xvmc_driver->put_slice(display, context, slice, nbytes)) { - XVMC_ERR("PutSlice fail\n"); - return BadValue; - } - return Success; + if (xvmc_driver->put_slice(display, context, slice, nbytes)) { + XVMC_ERR("PutSlice fail\n"); + return BadValue; + } + return Success; } -_X_EXPORT Status XvMCPutSlice2(Display *display, XvMCContext *context, - char *slice, int nbytes, int slice_code) +_X_EXPORT Status XvMCPutSlice2(Display * display, XvMCContext * context, + char *slice, int nbytes, int slice_code) { - if (xvmc_driver->put_slice2(display, context, slice, nbytes, slice_code)) { - XVMC_ERR("PutSlice2 fail\n"); - return BadValue; - } - return Success; + if (xvmc_driver->put_slice2 + (display, context, slice, nbytes, slice_code)) { + XVMC_ERR("PutSlice2 fail\n"); + return BadValue; + } + return Success; } diff --git a/src/xvmc/intel_xvmc.h b/src/xvmc/intel_xvmc.h index 169e7f8d..67c7b380 100644 --- a/src/xvmc/intel_xvmc.h +++ b/src/xvmc/intel_xvmc.h @@ -83,131 +83,132 @@ extern int DEBUG; Definitions for temporary wire protocol hooks to be replaced when a HW independent libXvMC is created. */ -extern Status _xvmc_create_context(Display *dpy, XvMCContext *context, - int *priv_count, CARD32 **priv_data); +extern Status _xvmc_create_context(Display * dpy, XvMCContext * context, + int *priv_count, CARD32 ** priv_data); -extern Status _xvmc_destroy_context(Display *dpy, XvMCContext *context); +extern Status _xvmc_destroy_context(Display * dpy, XvMCContext * context); -extern Status _xvmc_create_surface(Display *dpy, XvMCContext *context, - XvMCSurface *surface, int *priv_count, - CARD32 **priv_data); +extern Status _xvmc_create_surface(Display * dpy, XvMCContext * context, + XvMCSurface * surface, int *priv_count, + CARD32 ** priv_data); -extern Status _xvmc_destroy_surface(Display *dpy, XvMCSurface *surface); +extern Status _xvmc_destroy_surface(Display * dpy, XvMCSurface * surface); -extern Status _xvmc_create_subpicture(Display *dpy, XvMCContext *context, - XvMCSubpicture *subpicture, - int *priv_count, uint **priv_data); +extern Status _xvmc_create_subpicture(Display * dpy, XvMCContext * context, + XvMCSubpicture * subpicture, + int *priv_count, uint ** priv_data); -extern Status _xvmc_destroy_subpicture(Display *dpy, - XvMCSubpicture *subpicture); +extern Status _xvmc_destroy_subpicture(Display * dpy, + XvMCSubpicture * subpicture); typedef struct _intel_xvmc_context { - XvMCContext *context; - drm_context_t hw_context; /* context id to kernel drm */ - struct _intel_xvmc_context *next; + XvMCContext *context; + drm_context_t hw_context; /* context id to kernel drm */ + struct _intel_xvmc_context *next; } intel_xvmc_context_t, *intel_xvmc_context_ptr; typedef struct _intel_xvmc_surface { - XvMCSurface *surface; - XvImage *image; - GC gc; - Bool gc_init; - Drawable last_draw; - struct intel_xvmc_command data; - struct _intel_xvmc_surface *next; + XvMCSurface *surface; + XvImage *image; + GC gc; + Bool gc_init; + Drawable last_draw; + struct intel_xvmc_command data; + struct _intel_xvmc_surface *next; } intel_xvmc_surface_t, *intel_xvmc_surface_ptr; typedef struct _intel_xvmc_drm_map { - drm_handle_t handle; - unsigned long offset; - unsigned long size; - unsigned long bus_addr; - drmAddress map; + drm_handle_t handle; + unsigned long offset; + unsigned long size; + unsigned long bus_addr; + drmAddress map; } intel_xvmc_drm_map_t, *intel_xvmc_drm_map_ptr; typedef struct _intel_xvmc_driver { - int type; /* hw xvmc type - i830_hwmc.h */ - int screen; /* current screen num*/ - - int fd; /* drm file handler */ - - dri_bufmgr *bufmgr; - unsigned int kernel_exec_fencing:1; - - struct { - unsigned int init_offset; - unsigned int size; - unsigned int space; - unsigned char *ptr; - unsigned char *init_ptr; - dri_bo *buf; - } batch; - - struct - { - void *ptr; - unsigned int size; - unsigned int offset; - unsigned int active_buf; - unsigned int irq_emitted; - } alloc; - intel_xvmc_drm_map_t batchbuffer; - unsigned int last_render; - - sigset_t sa_mask; - pthread_mutex_t ctxmutex; - int locked; - - int num_ctx; - intel_xvmc_context_ptr ctx_list; - int num_surf; - intel_xvmc_surface_ptr surf_list; - - void *private; - - /* driver specific xvmc callbacks */ - Status (*create_context)(Display* display, XvMCContext *context, - int priv_count, CARD32 *priv_data); - - Status (*destroy_context)(Display* display, XvMCContext *context); - - Status (*create_surface)(Display* display, XvMCContext *context, - XvMCSurface *surface, int priv_count, CARD32 *priv_data); - - Status (*destroy_surface)(Display* display, XvMCSurface *surface); - - Status (*render_surface)(Display *display, XvMCContext *context, - unsigned int picture_structure, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - unsigned int flags, - unsigned int num_macroblocks, - unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, - XvMCBlockArray *blocks); - - Status (*put_surface)(Display *display, XvMCSurface *surface, - Drawable draw, short srcx, short srcy, - unsigned short srcw, unsigned short srch, - short destx, short desty, - unsigned short destw, unsigned short desth, - int flags, struct intel_xvmc_command *data); - - Status (*get_surface_status)(Display *display, XvMCSurface *surface, int *stat); - - Status (*begin_surface)(Display *display, XvMCContext *context, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - const XvMCMpegControl *control); - Status (*load_qmatrix)(Display *display, XvMCContext *context, - const XvMCQMatrix *qmx); - Status (*put_slice)(Display *display, XvMCContext *context, - unsigned char *slice, int bytes); - Status (*put_slice2)(Display *display, XvMCContext *context, - unsigned char *slice, int bytes, int slice_code); - + int type; /* hw xvmc type - i830_hwmc.h */ + int screen; /* current screen num */ + + int fd; /* drm file handler */ + + dri_bufmgr *bufmgr; + unsigned int kernel_exec_fencing:1; + + struct { + unsigned int init_offset; + unsigned int size; + unsigned int space; + unsigned char *ptr; + unsigned char *init_ptr; + dri_bo *buf; + } batch; + + struct { + void *ptr; + unsigned int size; + unsigned int offset; + unsigned int active_buf; + unsigned int irq_emitted; + } alloc; + intel_xvmc_drm_map_t batchbuffer; + unsigned int last_render; + + sigset_t sa_mask; + pthread_mutex_t ctxmutex; + int locked; + + int num_ctx; + intel_xvmc_context_ptr ctx_list; + int num_surf; + intel_xvmc_surface_ptr surf_list; + + void *private; + + /* driver specific xvmc callbacks */ + Status(*create_context) (Display * display, XvMCContext * context, + int priv_count, CARD32 * priv_data); + + Status(*destroy_context) (Display * display, XvMCContext * context); + + Status(*create_surface) (Display * display, XvMCContext * context, + XvMCSurface * surface, int priv_count, + CARD32 * priv_data); + + Status(*destroy_surface) (Display * display, XvMCSurface * surface); + + Status(*render_surface) (Display * display, XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks); + + Status(*put_surface) (Display * display, XvMCSurface * surface, + Drawable draw, short srcx, short srcy, + unsigned short srcw, unsigned short srch, + short destx, short desty, + unsigned short destw, unsigned short desth, + int flags, struct intel_xvmc_command * data); + + Status(*get_surface_status) (Display * display, XvMCSurface * surface, + int *stat); + + Status(*begin_surface) (Display * display, XvMCContext * context, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + const XvMCMpegControl * control); + Status(*load_qmatrix) (Display * display, XvMCContext * context, + const XvMCQMatrix * qmx); + Status(*put_slice) (Display * display, XvMCContext * context, + unsigned char *slice, int bytes); + Status(*put_slice2) (Display * display, XvMCContext * context, + unsigned char *slice, int bytes, int slice_code); + } intel_xvmc_driver_t, *intel_xvmc_driver_ptr; extern struct _intel_xvmc_driver i915_xvmc_mc_driver; @@ -243,20 +244,20 @@ extern struct _intel_xvmc_driver *xvmc_driver; extern void LOCK_HARDWARE(drm_context_t); extern void UNLOCK_HARDWARE(drm_context_t); -static inline const char* intel_xvmc_decoder_string(int flag) +static inline const char *intel_xvmc_decoder_string(int flag) { - switch (flag) { + switch (flag) { case XVMC_I915_MPEG2_MC: - return "i915/945 MPEG2 MC decoder"; + return "i915/945 MPEG2 MC decoder"; case XVMC_I965_MPEG2_MC: - return "i965 MPEG2 MC decoder"; + return "i965 MPEG2 MC decoder"; case XVMC_I945_MPEG2_VLD: - return "i945 MPEG2 VLD decoder"; + return "i945 MPEG2 VLD decoder"; case XVMC_I965_MPEG2_VLD: - return "i965 MPEG2 VLD decoder"; + return "i965 MPEG2 VLD decoder"; default: - return "Unknown decoder"; - } + return "Unknown decoder"; + } } extern intel_xvmc_context_ptr intel_xvmc_find_context(XID id); @@ -267,12 +268,16 @@ extern unsigned int mb_bytes_420[64]; /* dump function */ extern void intel_xvmc_dump_open(void); extern void intel_xvmc_dump_close(void); -extern void intel_xvmc_dump_render(XvMCContext *context, unsigned int picture_structure, - XvMCSurface *target_surface, XvMCSurface *past_surface, - XvMCSurface *future_surface, unsigned int flags, - unsigned int num_macroblocks, unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, XvMCBlockArray *blocks); - +extern void intel_xvmc_dump_render(XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks); #define VFE_GENERIC_MODE 0x0 #define VFE_VLD_MODE 0x1 diff --git a/src/xvmc/intel_xvmc_dump.c b/src/xvmc/intel_xvmc_dump.c index 419bd0d8..015d4828 100644 --- a/src/xvmc/intel_xvmc_dump.c +++ b/src/xvmc/intel_xvmc_dump.c @@ -33,117 +33,126 @@ static FILE *fp = NULL; void intel_xvmc_dump_open(void) { - char *d = NULL; + char *d = NULL; - if (xvmc_dump) - return; + if (xvmc_dump) + return; - if (d = getenv("INTEL_XVMC_DUMP")) - xvmc_dump = 1; + if (d = getenv("INTEL_XVMC_DUMP")) + xvmc_dump = 1; - if (xvmc_dump) { - fp = fopen(DUMPFILE, "a"); - if (!fp) - xvmc_dump = 0; - } + if (xvmc_dump) { + fp = fopen(DUMPFILE, "a"); + if (!fp) + xvmc_dump = 0; + } } void intel_xvmc_dump_close(void) { - if (xvmc_dump) { - fclose(fp); - xvmc_dump = 0; - } + if (xvmc_dump) { + fclose(fp); + xvmc_dump = 0; + } } -void intel_xvmc_dump_render(XvMCContext *context, unsigned int picture_structure, - XvMCSurface *target, XvMCSurface *past, XvMCSurface *future, unsigned int flags, - unsigned int num_macroblocks, unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, XvMCBlockArray *blocks) +void intel_xvmc_dump_render(XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target, XvMCSurface * past, + XvMCSurface * future, unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks) { - int i; - XvMCMacroBlock *mb; - - if (!xvmc_dump) - return; - - fprintf(fp, "========== new surface rendering ==========\n"); - fprintf(fp, "Context (id:%d) (surface_type_id:%d) (width:%d) (height:%d)\n", - context->context_id, context->surface_type_id, context->width, context->height); - - if (picture_structure == XVMC_FRAME_PICTURE) - fprintf(fp, "picture structure: frame picture\n"); - else if (picture_structure == XVMC_TOP_FIELD) - fprintf(fp, "picture structure: top field picture (%s)\n", - (flags == XVMC_SECOND_FIELD)?"second":"first"); - else if (picture_structure == XVMC_BOTTOM_FIELD) - fprintf(fp, "picture structure: bottom field picture (%s)\n", - (flags == XVMC_SECOND_FIELD)?"second":"first"); - - if (!past && !future) - fprintf(fp, "picture type: I\n"); - else if (past && !future) - fprintf(fp, "picture type: P\n"); - else if (past && future) - fprintf(fp, "picture type: B\n"); - else - fprintf(fp, "picture type: Bad!\n"); - - fprintf(fp, "target picture: id (%d) width (%d) height (%d)\n", target->surface_id, - target->width, target->height); - if (past) - fprintf(fp, "past picture: id (%d) width (%d) height (%d)\n", past->surface_id, - past->width, past->height); - if (future) - fprintf(fp, "future picture: id (%d) width (%d) height (%d)\n", future->surface_id, - future->width, future->height); - - fprintf(fp, "num macroblocks: %d, first macroblocks %d\n", num_macroblocks, first_macroblock); - - for (i = first_macroblock; i < (first_macroblock + num_macroblocks); i++) { - mb = ¯oblock_array->macro_blocks[i]; - - fprintf(fp, "- MB(%d): ", i); - fprintf(fp, "x (%d) y (%d) ", mb->x, mb->y); - fprintf(fp, "macroblock type ("); - if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) - fprintf(fp, "motion_forward "); - if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) - fprintf(fp, "motion_backward "); - if (mb->macroblock_type & XVMC_MB_TYPE_PATTERN) - fprintf(fp, "pattern "); - if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) - fprintf(fp, "intra "); - fprintf(fp, ") "); - fprintf(fp, "mc type "); - if (picture_structure == XVMC_FRAME_PICTURE) { - if (mb->motion_type & XVMC_PREDICTION_FIELD) - fprintf(fp, "(field) "); - else if (mb->motion_type & XVMC_PREDICTION_FRAME) - fprintf(fp, "(frame) "); - else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME) - fprintf(fp, "(dual-prime) "); - else - fprintf(fp, "(unknown %d) ", mb->motion_type); - } else { /* field */ - if (mb->motion_type & XVMC_PREDICTION_FIELD) - fprintf(fp, "(field) "); - else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME) - fprintf(fp, "(dual-prime) "); - else if (mb->motion_type & XVMC_PREDICTION_16x8) - fprintf(fp, "(16x8) "); - else - fprintf(fp, "(unknown %d) ", mb->motion_type); + int i; + XvMCMacroBlock *mb; + + if (!xvmc_dump) + return; + + fprintf(fp, "========== new surface rendering ==========\n"); + fprintf(fp, + "Context (id:%d) (surface_type_id:%d) (width:%d) (height:%d)\n", + context->context_id, context->surface_type_id, context->width, + context->height); + + if (picture_structure == XVMC_FRAME_PICTURE) + fprintf(fp, "picture structure: frame picture\n"); + else if (picture_structure == XVMC_TOP_FIELD) + fprintf(fp, "picture structure: top field picture (%s)\n", + (flags == XVMC_SECOND_FIELD) ? "second" : "first"); + else if (picture_structure == XVMC_BOTTOM_FIELD) + fprintf(fp, "picture structure: bottom field picture (%s)\n", + (flags == XVMC_SECOND_FIELD) ? "second" : "first"); + + if (!past && !future) + fprintf(fp, "picture type: I\n"); + else if (past && !future) + fprintf(fp, "picture type: P\n"); + else if (past && future) + fprintf(fp, "picture type: B\n"); + else + fprintf(fp, "picture type: Bad!\n"); + + fprintf(fp, "target picture: id (%d) width (%d) height (%d)\n", + target->surface_id, target->width, target->height); + if (past) + fprintf(fp, "past picture: id (%d) width (%d) height (%d)\n", + past->surface_id, past->width, past->height); + if (future) + fprintf(fp, "future picture: id (%d) width (%d) height (%d)\n", + future->surface_id, future->width, future->height); + + fprintf(fp, "num macroblocks: %d, first macroblocks %d\n", + num_macroblocks, first_macroblock); + + for (i = first_macroblock; i < (first_macroblock + num_macroblocks); + i++) { + mb = ¯oblock_array->macro_blocks[i]; + + fprintf(fp, "- MB(%d): ", i); + fprintf(fp, "x (%d) y (%d) ", mb->x, mb->y); + fprintf(fp, "macroblock type ("); + if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD) + fprintf(fp, "motion_forward "); + if (mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD) + fprintf(fp, "motion_backward "); + if (mb->macroblock_type & XVMC_MB_TYPE_PATTERN) + fprintf(fp, "pattern "); + if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) + fprintf(fp, "intra "); + fprintf(fp, ") "); + fprintf(fp, "mc type "); + if (picture_structure == XVMC_FRAME_PICTURE) { + if (mb->motion_type & XVMC_PREDICTION_FIELD) + fprintf(fp, "(field) "); + else if (mb->motion_type & XVMC_PREDICTION_FRAME) + fprintf(fp, "(frame) "); + else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME) + fprintf(fp, "(dual-prime) "); + else + fprintf(fp, "(unknown %d) ", mb->motion_type); + } else { /* field */ + if (mb->motion_type & XVMC_PREDICTION_FIELD) + fprintf(fp, "(field) "); + else if (mb->motion_type & XVMC_PREDICTION_DUAL_PRIME) + fprintf(fp, "(dual-prime) "); + else if (mb->motion_type & XVMC_PREDICTION_16x8) + fprintf(fp, "(16x8) "); + else + fprintf(fp, "(unknown %d) ", mb->motion_type); + } + + if (mb->dct_type == XVMC_DCT_TYPE_FRAME) + fprintf(fp, "dct type (frame) "); + else if (mb->dct_type == XVMC_DCT_TYPE_FIELD) + fprintf(fp, "dct type (field) "); + + fprintf(fp, "coded_block_pattern (0x%x)\n", + mb->coded_block_pattern); + + /* XXX mv dump */ } - if (mb->dct_type == XVMC_DCT_TYPE_FRAME) - fprintf(fp, "dct type (frame) "); - else if (mb->dct_type == XVMC_DCT_TYPE_FIELD) - fprintf(fp, "dct type (field) "); - - fprintf(fp, "coded_block_pattern (0x%x)\n", mb->coded_block_pattern); - - /* XXX mv dump */ - } - } diff --git a/src/xvmc/xvmc_vld.c b/src/xvmc/xvmc_vld.c index d964fc1b..dca05737 100644 --- a/src/xvmc/xvmc_vld.c +++ b/src/xvmc/xvmc_vld.c @@ -47,246 +47,307 @@ #define C6 8867 #define C7 4520 const uint32_t idct_table[] = { - C4, C1, C2, C3, C4, C5, C6, C7, //g5 - C4, C1, C2, C3, C4, C5, C6, C7, - C4, C3, C6,-C7,-C4,-C1,-C2,-C5, - C4, C3, C6,-C7,-C4,-C1,-C2,-C5, - C4, C5,-C6,-C1,-C4, C7, C2, C3, - C4, C5,-C6,-C1,-C4, C7, C2, C3, - C4, C7,-C2,-C5, C4, C3,-C6,-C1, - C4, C7,-C2,-C5, C4, C3,-C6,-C1, - C4,-C7,-C2, C5, C4,-C3,-C6, C1, - C4,-C7,-C2, C5, C4,-C3,-C6, C1, - C4,-C5,-C6, C1,-C4,-C7, C2,-C3, - C4,-C5,-C6, C1,-C4,-C7, C2,-C3, - C4,-C3, C6, C7,-C4, C1,-C2, C5, - C4,-C3, C6, C7,-C4, C1,-C2, C5, - C4,-C1, C2,-C3, C4,-C5, C6,-C7, - C4,-C1, C2,-C3, C4,-C5, C6,-C7 //g20 + C4, C1, C2, C3, C4, C5, C6, C7, //g5 + C4, C1, C2, C3, C4, C5, C6, C7, + C4, C3, C6, -C7, -C4, -C1, -C2, -C5, + C4, C3, C6, -C7, -C4, -C1, -C2, -C5, + C4, C5, -C6, -C1, -C4, C7, C2, C3, + C4, C5, -C6, -C1, -C4, C7, C2, C3, + C4, C7, -C2, -C5, C4, C3, -C6, -C1, + C4, C7, -C2, -C5, C4, C3, -C6, -C1, + C4, -C7, -C2, C5, C4, -C3, -C6, C1, + C4, -C7, -C2, C5, C4, -C3, -C6, C1, + C4, -C5, -C6, C1, -C4, -C7, C2, -C3, + C4, -C5, -C6, C1, -C4, -C7, C2, -C3, + C4, -C3, C6, C7, -C4, C1, -C2, C5, + C4, -C3, C6, C7, -C4, C1, -C2, C5, + C4, -C1, C2, -C3, C4, -C5, C6, -C7, + C4, -C1, C2, -C3, C4, -C5, C6, -C7 //g20 }; -#undef C0 -#undef C1 -#undef C2 -#undef C3 -#undef C4 -#undef C5 -#undef C6 -#undef C7 + +#undef C0 +#undef C1 +#undef C2 +#undef C3 +#undef C4 +#undef C5 +#undef C6 +#undef C7 #define INTERFACE_NUM 8 enum interface { - FRAME_INTRA = 0, + FRAME_INTRA = 0, FRAME_FRAME_PRED_FORWARD, FRAME_FRAME_PRED_BACKWARD, FRAME_FRAME_PRED_BIDIRECT, FRAME_FIELD_PRED_FORWARD, FRAME_FIELD_PRED_BACKWARD, FRAME_FIELD_PRED_BIDIRECT, - LIB_INTERFACE + LIB_INTERFACE }; /*kernels for vld mode*/ static uint32_t lib_kernel[][4] = { - #include "shader/vld/lib.g4b" +#include "shader/vld/lib.g4b" }; + static uint32_t ipicture_kernel[][4] = { - #include "shader/vld/ipicture.g4b" +#include "shader/vld/ipicture.g4b" }; + static uint32_t frame_forward_kernel[][4] = { - #include "shader/vld/frame_forward.g4b" +#include "shader/vld/frame_forward.g4b" }; + static uint32_t frame_backward_kernel[][4] = { - #include "shader/vld/frame_backward.g4b" +#include "shader/vld/frame_backward.g4b" }; + static uint32_t frame_f_b_kernel[][4] = { - #include "shader/vld/frame_f_b.g4b" +#include "shader/vld/frame_f_b.g4b" }; + static uint32_t field_forward_kernel[][4] = { - #include "shader/vld/field_forward.g4b" +#include "shader/vld/field_forward.g4b" }; + static uint32_t field_backward_kernel[][4] = { - #include "shader/vld/field_backward.g4b" +#include "shader/vld/field_backward.g4b" }; + static uint32_t field_f_b_kernel[][4] = { - #include "shader/vld/field_f_b.g4b" +#include "shader/vld/field_f_b.g4b" }; /* on IGDNG */ static uint32_t lib_kernel_gen5[][4] = { - #include "shader/vld/lib.g4b.gen5" +#include "shader/vld/lib.g4b.gen5" }; + static uint32_t ipicture_kernel_gen5[][4] = { - #include "shader/vld/ipicture.g4b.gen5" +#include "shader/vld/ipicture.g4b.gen5" }; + static uint32_t frame_forward_kernel_gen5[][4] = { - #include "shader/vld/frame_forward.g4b.gen5" +#include "shader/vld/frame_forward.g4b.gen5" }; + static uint32_t frame_backward_kernel_gen5[][4] = { - #include "shader/vld/frame_backward.g4b.gen5" +#include "shader/vld/frame_backward.g4b.gen5" }; + static uint32_t frame_f_b_kernel_gen5[][4] = { - #include "shader/vld/frame_f_b.g4b.gen5" +#include "shader/vld/frame_f_b.g4b.gen5" }; + static uint32_t field_forward_kernel_gen5[][4] = { - #include "shader/vld/field_forward.g4b.gen5" +#include "shader/vld/field_forward.g4b.gen5" }; + static uint32_t field_backward_kernel_gen5[][4] = { - #include "shader/vld/field_backward.g4b.gen5" +#include "shader/vld/field_backward.g4b.gen5" }; + static uint32_t field_f_b_kernel_gen5[][4] = { - #include "shader/vld/field_f_b.g4b.gen5" +#include "shader/vld/field_f_b.g4b.gen5" }; /*kernels for mc mode*/ static uint32_t lib_kernel_idct[][4] = { - #include "shader/mc/lib_igd.g4b" +#include "shader/mc/lib_igd.g4b" }; + static uint32_t ipicture_kernel_idct[][4] = { - #include "shader/mc/ipicture_igd.g4b" +#include "shader/mc/ipicture_igd.g4b" }; + static uint32_t frame_forward_kernel_idct[][4] = { - #include "shader/mc/frame_forward_igd.g4b" +#include "shader/mc/frame_forward_igd.g4b" }; + static uint32_t frame_backward_kernel_idct[][4] = { - #include "shader/mc/frame_backward_igd.g4b" +#include "shader/mc/frame_backward_igd.g4b" }; + static uint32_t frame_f_b_kernel_idct[][4] = { - #include "shader/mc/frame_f_b_igd.g4b" +#include "shader/mc/frame_f_b_igd.g4b" }; + static uint32_t field_forward_kernel_idct[][4] = { - #include "shader/mc/field_forward_igd.g4b" +#include "shader/mc/field_forward_igd.g4b" }; + static uint32_t field_backward_kernel_idct[][4] = { - #include "shader/mc/field_backward_igd.g4b" +#include "shader/mc/field_backward_igd.g4b" }; + static uint32_t field_f_b_kernel_idct[][4] = { - #include "shader/mc/field_f_b_igd.g4b" +#include "shader/mc/field_f_b_igd.g4b" }; /* on IGDNG */ static uint32_t lib_kernel_idct_gen5[][4] = { - #include "shader/mc/lib_igd.g4b.gen5" +#include "shader/mc/lib_igd.g4b.gen5" }; + static uint32_t ipicture_kernel_idct_gen5[][4] = { - #include "shader/mc/ipicture_igd.g4b.gen5" +#include "shader/mc/ipicture_igd.g4b.gen5" }; + static uint32_t frame_forward_kernel_idct_gen5[][4] = { - #include "shader/mc/frame_forward_igd.g4b.gen5" +#include "shader/mc/frame_forward_igd.g4b.gen5" }; + static uint32_t frame_backward_kernel_idct_gen5[][4] = { - #include "shader/mc/frame_backward_igd.g4b.gen5" +#include "shader/mc/frame_backward_igd.g4b.gen5" }; + static uint32_t frame_f_b_kernel_idct_gen5[][4] = { - #include "shader/mc/frame_f_b_igd.g4b.gen5" +#include "shader/mc/frame_f_b_igd.g4b.gen5" }; + static uint32_t field_forward_kernel_idct_gen5[][4] = { - #include "shader/mc/field_forward_igd.g4b.gen5" +#include "shader/mc/field_forward_igd.g4b.gen5" }; + static uint32_t field_backward_kernel_idct_gen5[][4] = { - #include "shader/mc/field_backward_igd.g4b.gen5" +#include "shader/mc/field_backward_igd.g4b.gen5" }; + static uint32_t field_f_b_kernel_idct_gen5[][4] = { - #include "shader/mc/field_f_b_igd.g4b.gen5" +#include "shader/mc/field_f_b_igd.g4b.gen5" }; struct media_kernel { - uint32_t (*bin)[4]; - int size; + uint32_t(*bin)[4]; + int size; }; static struct media_kernel media_kernels[] = { - /*kernels for vld mode*/ - {ipicture_kernel, sizeof(ipicture_kernel)}, - {frame_forward_kernel, sizeof(frame_forward_kernel)}, - {frame_backward_kernel, sizeof(frame_backward_kernel)}, - {frame_f_b_kernel, sizeof(frame_f_b_kernel)}, - {field_forward_kernel, sizeof(field_forward_kernel)}, - {field_backward_kernel, sizeof(field_backward_kernel)}, - {field_f_b_kernel, sizeof(field_f_b_kernel)}, - {lib_kernel, sizeof(lib_kernel)}, - /*kernels for mc mode*/ - {ipicture_kernel_idct, sizeof(ipicture_kernel_idct)}, - {frame_forward_kernel_idct, sizeof(frame_forward_kernel_idct)}, - {frame_backward_kernel_idct, sizeof(frame_backward_kernel_idct)}, - {frame_f_b_kernel_idct, sizeof(frame_f_b_kernel_idct)}, - {field_forward_kernel_idct, sizeof(field_forward_kernel_idct)}, - {field_backward_kernel_idct, sizeof(field_backward_kernel_idct)}, - {field_f_b_kernel_idct, sizeof(field_f_b_kernel_idct)}, - {lib_kernel_idct, sizeof(lib_kernel_idct)} + /*kernels for vld mode */ + {ipicture_kernel, sizeof(ipicture_kernel)} + , + {frame_forward_kernel, sizeof(frame_forward_kernel)} + , + {frame_backward_kernel, sizeof(frame_backward_kernel)} + , + {frame_f_b_kernel, sizeof(frame_f_b_kernel)} + , + {field_forward_kernel, sizeof(field_forward_kernel)} + , + {field_backward_kernel, sizeof(field_backward_kernel)} + , + {field_f_b_kernel, sizeof(field_f_b_kernel)} + , + {lib_kernel, sizeof(lib_kernel)} + , + /*kernels for mc mode */ + {ipicture_kernel_idct, sizeof(ipicture_kernel_idct)} + , + {frame_forward_kernel_idct, sizeof(frame_forward_kernel_idct)} + , + {frame_backward_kernel_idct, sizeof(frame_backward_kernel_idct)} + , + {frame_f_b_kernel_idct, sizeof(frame_f_b_kernel_idct)} + , + {field_forward_kernel_idct, sizeof(field_forward_kernel_idct)} + , + {field_backward_kernel_idct, sizeof(field_backward_kernel_idct)} + , + {field_f_b_kernel_idct, sizeof(field_f_b_kernel_idct)} + , + {lib_kernel_idct, sizeof(lib_kernel_idct)} }; static struct media_kernel media_gen5_kernels[] = { - /*kernels for vld mode*/ - {ipicture_kernel_gen5, sizeof(ipicture_kernel_gen5)}, - {frame_forward_kernel_gen5, sizeof(frame_forward_kernel_gen5)}, - {frame_backward_kernel_gen5, sizeof(frame_backward_kernel_gen5)}, - {frame_f_b_kernel_gen5, sizeof(frame_f_b_kernel_gen5)}, - {field_forward_kernel_gen5, sizeof(field_forward_kernel_gen5)}, - {field_backward_kernel_gen5, sizeof(field_backward_kernel_gen5)}, - {field_f_b_kernel_gen5, sizeof(field_f_b_kernel_gen5)}, - {lib_kernel_gen5, sizeof(lib_kernel_gen5)}, - /*kernels for mc mode*/ - {ipicture_kernel_idct_gen5, sizeof(ipicture_kernel_idct_gen5)}, - {frame_forward_kernel_idct_gen5, sizeof(frame_forward_kernel_idct_gen5)}, - {frame_backward_kernel_idct_gen5, sizeof(frame_backward_kernel_idct_gen5)}, - {frame_f_b_kernel_idct_gen5, sizeof(frame_f_b_kernel_idct_gen5)}, - {field_forward_kernel_idct_gen5, sizeof(field_forward_kernel_idct_gen5)}, - {field_backward_kernel_idct_gen5, sizeof(field_backward_kernel_idct_gen5)}, - {field_f_b_kernel_idct_gen5, sizeof(field_f_b_kernel_idct_gen5)}, - {lib_kernel_idct_gen5, sizeof(lib_kernel_idct_gen5)} + /*kernels for vld mode */ + {ipicture_kernel_gen5, sizeof(ipicture_kernel_gen5)} + , + {frame_forward_kernel_gen5, sizeof(frame_forward_kernel_gen5)} + , + {frame_backward_kernel_gen5, sizeof(frame_backward_kernel_gen5)} + , + {frame_f_b_kernel_gen5, sizeof(frame_f_b_kernel_gen5)} + , + {field_forward_kernel_gen5, sizeof(field_forward_kernel_gen5)} + , + {field_backward_kernel_gen5, sizeof(field_backward_kernel_gen5)} + , + {field_f_b_kernel_gen5, sizeof(field_f_b_kernel_gen5)} + , + {lib_kernel_gen5, sizeof(lib_kernel_gen5)} + , + /*kernels for mc mode */ + {ipicture_kernel_idct_gen5, sizeof(ipicture_kernel_idct_gen5)} + , + {frame_forward_kernel_idct_gen5, sizeof(frame_forward_kernel_idct_gen5)} + , + {frame_backward_kernel_idct_gen5, + sizeof(frame_backward_kernel_idct_gen5)} + , + {frame_f_b_kernel_idct_gen5, sizeof(frame_f_b_kernel_idct_gen5)} + , + {field_forward_kernel_idct_gen5, sizeof(field_forward_kernel_idct_gen5)} + , + {field_backward_kernel_idct_gen5, + sizeof(field_backward_kernel_idct_gen5)} + , + {field_f_b_kernel_idct_gen5, sizeof(field_f_b_kernel_idct_gen5)} + , + {lib_kernel_idct_gen5, sizeof(lib_kernel_idct_gen5)} }; #define MEDIA_KERNEL_NUM (sizeof(media_kernels)/sizeof(media_kernels[0])) struct media_kernel_obj { - dri_bo *bo; + dri_bo *bo; }; struct interface_descriptor_obj { - dri_bo *bo; - struct media_kernel_obj kernels[MEDIA_KERNEL_NUM]; + dri_bo *bo; + struct media_kernel_obj kernels[MEDIA_KERNEL_NUM]; }; struct vfe_state_obj { - dri_bo *bo; - struct interface_descriptor_obj interface; + dri_bo *bo; + struct interface_descriptor_obj interface; }; struct vld_state_obj { - dri_bo *bo; + dri_bo *bo; }; struct surface_obj { - dri_bo *bo; + dri_bo *bo; }; struct surface_state_obj { - struct surface_obj surface; - dri_bo *bo; + struct surface_obj surface; + dri_bo *bo; }; struct binding_table_obj { - dri_bo *bo; - struct surface_state_obj surface_states[I965_MAX_SURFACES]; + dri_bo *bo; + struct surface_state_obj surface_states[I965_MAX_SURFACES]; }; struct slice_data_obj { - dri_bo *bo; + dri_bo *bo; }; struct mb_data_obj { - dri_bo *bo; + dri_bo *bo; }; struct cs_state_obj { - dri_bo *bo; + dri_bo *bo; }; static struct media_state { - struct vfe_state_obj vfe_state; - struct vld_state_obj vld_state; - struct binding_table_obj binding_table; - struct cs_state_obj cs_object; - struct slice_data_obj slice_data; + struct vfe_state_obj vfe_state; + struct vld_state_obj vld_state; + struct binding_table_obj binding_table; + struct cs_state_obj cs_object; + struct slice_data_obj slice_data; struct mb_data_obj mb_data; } media_state; @@ -294,48 +355,49 @@ static struct media_state { #define CS_OBJECT_SIZE (32*20 + sizeof(unsigned int) * 8) static int free_object(struct media_state *s) { - int i; + int i; #define FREE_ONE_BO(bo) \ if (bo) \ drm_intel_bo_unreference(bo) - FREE_ONE_BO(s->vfe_state.bo); - FREE_ONE_BO(s->vfe_state.interface.bo); - for (i = 0; i < MEDIA_KERNEL_NUM; i++) - FREE_ONE_BO(s->vfe_state.interface.kernels[i].bo); - FREE_ONE_BO(s->binding_table.bo); - for (i = 0; i < I965_MAX_SURFACES; i++) - FREE_ONE_BO(s->binding_table.surface_states[i].bo); - FREE_ONE_BO(s->slice_data.bo); - FREE_ONE_BO(s->mb_data.bo); - FREE_ONE_BO(s->cs_object.bo); - FREE_ONE_BO(s->vld_state.bo); + FREE_ONE_BO(s->vfe_state.bo); + FREE_ONE_BO(s->vfe_state.interface.bo); + for (i = 0; i < MEDIA_KERNEL_NUM; i++) + FREE_ONE_BO(s->vfe_state.interface.kernels[i].bo); + FREE_ONE_BO(s->binding_table.bo); + for (i = 0; i < I965_MAX_SURFACES; i++) + FREE_ONE_BO(s->binding_table.surface_states[i].bo); + FREE_ONE_BO(s->slice_data.bo); + FREE_ONE_BO(s->mb_data.bo); + FREE_ONE_BO(s->cs_object.bo); + FREE_ONE_BO(s->vld_state.bo); } static int alloc_object(struct media_state *s) { - int i; - - for (i = 0; i < I965_MAX_SURFACES; i++) { - s->binding_table.surface_states[i].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", - sizeof(struct brw_surface_state), 0x1000); - if (!s->binding_table.surface_states[i].bo) - goto out; - } - return 0; + int i; + + for (i = 0; i < I965_MAX_SURFACES; i++) { + s->binding_table.surface_states[i].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", + sizeof(struct brw_surface_state), + 0x1000); + if (!s->binding_table.surface_states[i].bo) + goto out; + } + return 0; out: - free_object(s); - return BadAlloc; + free_object(s); + return BadAlloc; } static void flush() { -#define FLUSH_STATE_CACHE 1 - struct brw_mi_flush f; - memset(&f, 0, sizeof(f)); - f.opcode = CMD_MI_FLUSH; - f.flags = (1<<FLUSH_STATE_CACHE); - BATCH_STRUCT(f); +#define FLUSH_STATE_CACHE 1 + struct brw_mi_flush f; + memset(&f, 0, sizeof(f)); + f.opcode = CMD_MI_FLUSH; + f.flags = (1 << FLUSH_STATE_CACHE); + BATCH_STRUCT(f); } static Status vfe_state(int vfe_mode) @@ -345,7 +407,7 @@ static Status vfe_state(int vfe_mode) if (vfe_mode == VFE_VLD_MODE) { vfe_state->vfe0.extend_vfe_state_present = 1; } else { - vfe_state->vfe0.extend_vfe_state_present = 0; + vfe_state->vfe0.extend_vfe_state_present = 0; } vfe_state->vfe1.vfe_mode = vfe_mode; vfe_state->vfe1.num_urb_entries = 1; @@ -353,793 +415,868 @@ static Status vfe_state(int vfe_mode) vfe_state->vfe1.urb_entry_alloc_size = 2; vfe_state->vfe1.max_threads = 31; vfe_state->vfe2.interface_descriptor_base = - media_state.vfe_state.interface.bo->offset >> 4; + media_state.vfe_state.interface.bo->offset >> 4; - if (media_state.vfe_state.bo) - drm_intel_bo_unreference(media_state.vfe_state.bo); + if (media_state.vfe_state.bo) + drm_intel_bo_unreference(media_state.vfe_state.bo); - media_state.vfe_state.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "vfe state", sizeof(struct brw_vfe_state), 0x1000); - if (!media_state.vfe_state.bo) - return BadAlloc; + media_state.vfe_state.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, + "vfe state", + sizeof(struct + brw_vfe_state), + 0x1000); + if (!media_state.vfe_state.bo) + return BadAlloc; - drm_intel_bo_subdata(media_state.vfe_state.bo, 0, sizeof(tmp), &tmp); + drm_intel_bo_subdata(media_state.vfe_state.bo, 0, sizeof(tmp), &tmp); - drm_intel_bo_emit_reloc(media_state.vfe_state.bo, - offsetof(struct brw_vfe_state, vfe2), - media_state.vfe_state.interface.bo, 0, - I915_GEM_DOMAIN_INSTRUCTION, 0); - return Success; + drm_intel_bo_emit_reloc(media_state.vfe_state.bo, + offsetof(struct brw_vfe_state, vfe2), + media_state.vfe_state.interface.bo, 0, + I915_GEM_DOMAIN_INSTRUCTION, 0); + return Success; } static Status interface_descriptor() { - int i; - struct brw_interface_descriptor tmp, *desc = &tmp; + int i; + struct brw_interface_descriptor tmp, *desc = &tmp; - if (media_state.vfe_state.interface.bo) - drm_intel_bo_unreference(media_state.vfe_state.interface.bo); + if (media_state.vfe_state.interface.bo) + drm_intel_bo_unreference(media_state.vfe_state.interface.bo); - media_state.vfe_state.interface.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "interfaces", MEDIA_KERNEL_NUM*sizeof(struct brw_interface_descriptor), - 0x1000); - if (!media_state.vfe_state.interface.bo) - return BadAlloc; + media_state.vfe_state.interface.bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "interfaces", + MEDIA_KERNEL_NUM * + sizeof(struct brw_interface_descriptor), 0x1000); + if (!media_state.vfe_state.interface.bo) + return BadAlloc; - for (i = 0; i < MEDIA_KERNEL_NUM; i++) { + for (i = 0; i < MEDIA_KERNEL_NUM; i++) { memset(desc, 0, sizeof(*desc)); desc->desc0.grf_reg_blocks = 15; desc->desc0.kernel_start_pointer = - media_state.vfe_state.interface.kernels[i].bo->offset >> 6; + media_state.vfe_state.interface.kernels[i].bo->offset >> 6; desc->desc1.const_urb_entry_read_offset = 0; desc->desc1.const_urb_entry_read_len = 30; desc->desc3.binding_table_entry_count = I965_MAX_SURFACES - 1; desc->desc3.binding_table_pointer = - media_state.binding_table.bo->offset >> 5; - - drm_intel_bo_subdata(media_state.vfe_state.interface.bo, i*sizeof(tmp), sizeof(tmp), desc); - - drm_intel_bo_emit_reloc( - media_state.vfe_state.interface.bo, - i * sizeof(*desc) + - offsetof(struct brw_interface_descriptor, desc0), - media_state.vfe_state.interface.kernels[i].bo, - desc->desc0.grf_reg_blocks, - I915_GEM_DOMAIN_INSTRUCTION, 0); - - drm_intel_bo_emit_reloc( - media_state.vfe_state.interface.bo, - i * sizeof(*desc) + - offsetof(struct brw_interface_descriptor, desc3), - media_state.binding_table.bo, - desc->desc3.binding_table_entry_count, - I915_GEM_DOMAIN_INSTRUCTION, 0); - } - return Success; + media_state.binding_table.bo->offset >> 5; + + drm_intel_bo_subdata(media_state.vfe_state.interface.bo, + i * sizeof(tmp), sizeof(tmp), desc); + + drm_intel_bo_emit_reloc(media_state.vfe_state.interface.bo, + i * sizeof(*desc) + offsetof(struct + brw_interface_descriptor, + desc0), + media_state.vfe_state. + interface.kernels[i].bo, + desc->desc0.grf_reg_blocks, + I915_GEM_DOMAIN_INSTRUCTION, 0); + + drm_intel_bo_emit_reloc(media_state.vfe_state.interface.bo, + i * sizeof(*desc) + offsetof(struct + brw_interface_descriptor, + desc3), + media_state.binding_table.bo, + desc->desc3.binding_table_entry_count, + I915_GEM_DOMAIN_INSTRUCTION, 0); + } + return Success; } static int setup_media_kernels(struct i965_xvmc_context *i965_ctx) { - int i; - - assert(MEDIA_KERNEL_NUM == sizeof(media_gen5_kernels) / sizeof(media_gen5_kernels[0])); - - for (i = 0; i < MEDIA_KERNEL_NUM; i++) { - if (i965_ctx->is_igdng) - media_state.vfe_state.interface.kernels[i].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernel", - media_gen5_kernels[i].size, 0x1000); - else - media_state.vfe_state.interface.kernels[i].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernels", - media_kernels[i].size, 0x1000); - - if (!media_state.vfe_state.interface.kernels[i].bo) - goto out; - } - - for (i = 0; i < MEDIA_KERNEL_NUM; i++) { - dri_bo *bo = media_state.vfe_state.interface.kernels[i].bo; - - if (i965_ctx->is_igdng) - drm_intel_bo_subdata(bo, 0, media_gen5_kernels[i].size, media_gen5_kernels[i].bin); - else - drm_intel_bo_subdata(bo, 0, media_kernels[i].size, media_kernels[i].bin); - } - return 0; + int i; + + assert(MEDIA_KERNEL_NUM == + sizeof(media_gen5_kernels) / sizeof(media_gen5_kernels[0])); + + for (i = 0; i < MEDIA_KERNEL_NUM; i++) { + if (i965_ctx->is_igdng) + media_state.vfe_state.interface.kernels[i].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernel", + media_gen5_kernels[i].size, + 0x1000); + else + media_state.vfe_state.interface.kernels[i].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "kernels", + media_kernels[i].size, 0x1000); + + if (!media_state.vfe_state.interface.kernels[i].bo) + goto out; + } + + for (i = 0; i < MEDIA_KERNEL_NUM; i++) { + dri_bo *bo = media_state.vfe_state.interface.kernels[i].bo; + + if (i965_ctx->is_igdng) + drm_intel_bo_subdata(bo, 0, media_gen5_kernels[i].size, + media_gen5_kernels[i].bin); + else + drm_intel_bo_subdata(bo, 0, media_kernels[i].size, + media_kernels[i].bin); + } + return 0; out: - free_object(&media_state); - return BadAlloc; + free_object(&media_state); + return BadAlloc; } static Status binding_tables() { - unsigned int table[I965_MAX_SURFACES]; - int i; - - if (media_state.binding_table.bo) - drm_intel_bo_unreference(media_state.binding_table.bo); - media_state.binding_table.bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "binding_table", - I965_MAX_SURFACES*4, 0x1000); - if (!media_state.binding_table.bo) - return BadAlloc; - - for (i = 0; i < I965_MAX_SURFACES; i++) { - table[i] = media_state.binding_table.surface_states[i].bo->offset; - drm_intel_bo_emit_reloc(media_state.binding_table.bo, - i * sizeof(unsigned int), - media_state.binding_table.surface_states[i].bo, 0, - I915_GEM_DOMAIN_INSTRUCTION, 0); - } - - drm_intel_bo_subdata(media_state.binding_table.bo, 0, sizeof(table), table); - return Success; + unsigned int table[I965_MAX_SURFACES]; + int i; + + if (media_state.binding_table.bo) + drm_intel_bo_unreference(media_state.binding_table.bo); + media_state.binding_table.bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "binding_table", + I965_MAX_SURFACES * 4, 0x1000); + if (!media_state.binding_table.bo) + return BadAlloc; + + for (i = 0; i < I965_MAX_SURFACES; i++) { + table[i] = + media_state.binding_table.surface_states[i].bo->offset; + drm_intel_bo_emit_reloc(media_state.binding_table.bo, + i * sizeof(unsigned int), + media_state. + binding_table.surface_states[i].bo, 0, + I915_GEM_DOMAIN_INSTRUCTION, 0); + } + + drm_intel_bo_subdata(media_state.binding_table.bo, 0, sizeof(table), + table); + return Success; } static Status cs_init(int interface_offset) { - char buf[CS_OBJECT_SIZE]; - unsigned int *lib_reloc; - int i; - - if (media_state.cs_object.bo) - drm_intel_bo_unreference(media_state.cs_object.bo); - - media_state.cs_object.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "cs object", CS_OBJECT_SIZE, 64); - if (!media_state.cs_object.bo) - return BadAlloc; - - memcpy(buf + 32*4, idct_table, sizeof(idct_table)); - /* idct lib reloction */ - lib_reloc = (unsigned int *)(buf + 32*20); - for (i = 0; i < 8; i++) - lib_reloc[i] = - media_state.vfe_state.interface.kernels[LIB_INTERFACE + interface_offset].bo->offset; - drm_intel_bo_subdata(media_state.cs_object.bo, 32*4, 32*16 + 8*sizeof(unsigned int), buf + 32*4); - - for (i = 0; i < 8; i++) - drm_intel_bo_emit_reloc(media_state.cs_object.bo, - 32*20 + sizeof(unsigned int) * i, - media_state.vfe_state.interface.kernels[LIB_INTERFACE + interface_offset].bo, 0, - I915_GEM_DOMAIN_INSTRUCTION, 0); - - return Success; + char buf[CS_OBJECT_SIZE]; + unsigned int *lib_reloc; + int i; + + if (media_state.cs_object.bo) + drm_intel_bo_unreference(media_state.cs_object.bo); + + media_state.cs_object.bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "cs object", CS_OBJECT_SIZE, + 64); + if (!media_state.cs_object.bo) + return BadAlloc; + + memcpy(buf + 32 * 4, idct_table, sizeof(idct_table)); + /* idct lib reloction */ + lib_reloc = (unsigned int *)(buf + 32 * 20); + for (i = 0; i < 8; i++) + lib_reloc[i] = + media_state.vfe_state.interface.kernels[LIB_INTERFACE + + interface_offset].bo-> + offset; + drm_intel_bo_subdata(media_state.cs_object.bo, 32 * 4, + 32 * 16 + 8 * sizeof(unsigned int), buf + 32 * 4); + + for (i = 0; i < 8; i++) + drm_intel_bo_emit_reloc(media_state.cs_object.bo, + 32 * 20 + sizeof(unsigned int) * i, + media_state.vfe_state. + interface.kernels[LIB_INTERFACE + + interface_offset].bo, + 0, I915_GEM_DOMAIN_INSTRUCTION, 0); + + return Success; } -static Status create_context(Display *display, XvMCContext *context, - int priv_count, CARD32 *priv_data) +static Status create_context(Display * display, XvMCContext * context, + int priv_count, CARD32 * priv_data) { - struct i965_xvmc_context *i965_ctx; - i965_ctx = (struct i965_xvmc_context *)priv_data; - context->privData = priv_data; + struct i965_xvmc_context *i965_ctx; + i965_ctx = (struct i965_xvmc_context *)priv_data; + context->privData = priv_data; - if (alloc_object(&media_state)) - return BadAlloc; + if (alloc_object(&media_state)) + return BadAlloc; - if (setup_media_kernels(i965_ctx)) - return BadAlloc; - return Success; + if (setup_media_kernels(i965_ctx)) + return BadAlloc; + return Success; } -static Status destroy_context(Display *display, XvMCContext *context) +static Status destroy_context(Display * display, XvMCContext * context) { - struct i965_xvmc_context *i965_ctx; - i965_ctx = context->privData; - Xfree(i965_ctx); - return Success; + struct i965_xvmc_context *i965_ctx; + i965_ctx = context->privData; + Xfree(i965_ctx); + return Success; } #define STRIDE(w) (w) #define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1))) -static Status create_surface(Display *display, - XvMCContext *context, XvMCSurface *surface, int priv_count, - CARD32 *priv_data) +static Status create_surface(Display * display, + XvMCContext * context, XvMCSurface * surface, + int priv_count, CARD32 * priv_data) { - struct i965_xvmc_surface *priv_surface = - (struct i965_xvmc_surface *)priv_data; - size_t size = SIZE_YUV420(priv_surface->w, priv_surface->h); - surface->privData = priv_data; - priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface", - size, 0x1000); - - return Success; + struct i965_xvmc_surface *priv_surface = + (struct i965_xvmc_surface *)priv_data; + size_t size = SIZE_YUV420(priv_surface->w, priv_surface->h); + surface->privData = priv_data; + priv_surface->bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface", + size, 0x1000); + + return Success; } -static Status destroy_surface(Display *display, - XvMCSurface *surface) + +static Status destroy_surface(Display * display, XvMCSurface * surface) { - struct i965_xvmc_surface *priv_surface = - surface->privData; - XSync(display, False); - drm_intel_bo_unreference(priv_surface->bo); - return Success; + struct i965_xvmc_surface *priv_surface = surface->privData; + XSync(display, False); + drm_intel_bo_unreference(priv_surface->bo); + return Success; } -static Status load_qmatrix(Display *display, XvMCContext *context, - const XvMCQMatrix *qmx) +static Status load_qmatrix(Display * display, XvMCContext * context, + const XvMCQMatrix * qmx) { - Status ret; - ret = cs_init(0); - if (ret != Success) - return ret; - drm_intel_bo_subdata(media_state.cs_object.bo, 0, 64, qmx->intra_quantiser_matrix); - drm_intel_bo_subdata(media_state.cs_object.bo, 64, 64, qmx->non_intra_quantiser_matrix); - - return Success; + Status ret; + ret = cs_init(0); + if (ret != Success) + return ret; + drm_intel_bo_subdata(media_state.cs_object.bo, 0, 64, + qmx->intra_quantiser_matrix); + drm_intel_bo_subdata(media_state.cs_object.bo, 64, 64, + qmx->non_intra_quantiser_matrix); + + return Success; } -static Status get_surface_status(Display *display, XvMCSurface *surface, - int *status) +static Status get_surface_status(Display * display, XvMCSurface * surface, + int *status) { - *status = 0; - return Success; + *status = 0; + return Success; } -static Status vld_state(const XvMCMpegControl *control) +static Status vld_state(const XvMCMpegControl * control) { - struct brw_vld_state tmp, *vld = &tmp; - - if (media_state.vld_state.bo) - drm_intel_bo_unreference(media_state.vld_state.bo); - media_state.vld_state.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "vld state", sizeof(struct brw_vld_state), 64); - if (!media_state.vld_state.bo) - return BadAlloc; - - memset(vld, 0, sizeof(*vld)); - vld->vld0.f_code_0_0 = control->FHMV_range + 1; - vld->vld0.f_code_0_1 = control->FVMV_range + 1; - vld->vld0.f_code_1_0 = control->BHMV_range + 1; - vld->vld0.f_code_1_1 = control->BVMV_range + 1; - vld->vld0.intra_dc_precision = control->intra_dc_precision; - vld->vld0.picture_structure = control->picture_structure; - vld->vld0.top_field_first = !!(control->flags & XVMC_TOP_FIELD_FIRST); - vld->vld0.frame_predict_frame_dct = - !!(control->flags & XVMC_PRED_DCT_FRAME); - vld->vld0.concealment_motion_vector = - !!(control->flags & XVMC_CONCEALMENT_MOTION_VECTORS); - vld->vld0.quantizer_scale_type = !!(control->flags & XVMC_Q_SCALE_TYPE); - vld->vld0.intra_vlc_format = !!(control->flags & XVMC_INTRA_VLC_FORMAT); - vld->vld0.scan_order = !!(control->flags & XVMC_ALTERNATE_SCAN); - - vld->vld1.picture_coding_type = control->picture_coding_type; - - vld->desc_remap_table0.index_0 = FRAME_INTRA; - vld->desc_remap_table0.index_1 = FRAME_FRAME_PRED_FORWARD; - vld->desc_remap_table0.index_2 = FRAME_FIELD_PRED_FORWARD; - vld->desc_remap_table0.index_3 = FRAME_FIELD_PRED_BIDIRECT; /* dual prime */ - vld->desc_remap_table0.index_4 = FRAME_FRAME_PRED_BACKWARD; - vld->desc_remap_table0.index_5 = FRAME_FIELD_PRED_BACKWARD; - vld->desc_remap_table0.index_6 = FRAME_FRAME_PRED_BIDIRECT; - vld->desc_remap_table0.index_7 = FRAME_FIELD_PRED_BIDIRECT; - - vld->desc_remap_table1.index_8 = FRAME_INTRA; - vld->desc_remap_table1.index_9 = FRAME_FRAME_PRED_FORWARD; - vld->desc_remap_table1.index_10 = FRAME_FIELD_PRED_FORWARD; - vld->desc_remap_table1.index_11 = FRAME_FIELD_PRED_BIDIRECT; - vld->desc_remap_table1.index_12 = FRAME_FRAME_PRED_BACKWARD; - vld->desc_remap_table1.index_13 = FRAME_FIELD_PRED_BACKWARD; - vld->desc_remap_table1.index_14 = FRAME_FRAME_PRED_BIDIRECT; - vld->desc_remap_table1.index_15 = FRAME_FIELD_PRED_BIDIRECT; - - drm_intel_bo_subdata(media_state.vld_state.bo, 0, sizeof(tmp), vld); - return Success; + struct brw_vld_state tmp, *vld = &tmp; + + if (media_state.vld_state.bo) + drm_intel_bo_unreference(media_state.vld_state.bo); + media_state.vld_state.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, + "vld state", + sizeof(struct + brw_vld_state), + 64); + if (!media_state.vld_state.bo) + return BadAlloc; + + memset(vld, 0, sizeof(*vld)); + vld->vld0.f_code_0_0 = control->FHMV_range + 1; + vld->vld0.f_code_0_1 = control->FVMV_range + 1; + vld->vld0.f_code_1_0 = control->BHMV_range + 1; + vld->vld0.f_code_1_1 = control->BVMV_range + 1; + vld->vld0.intra_dc_precision = control->intra_dc_precision; + vld->vld0.picture_structure = control->picture_structure; + vld->vld0.top_field_first = !!(control->flags & XVMC_TOP_FIELD_FIRST); + vld->vld0.frame_predict_frame_dct = + !!(control->flags & XVMC_PRED_DCT_FRAME); + vld->vld0.concealment_motion_vector = + !!(control->flags & XVMC_CONCEALMENT_MOTION_VECTORS); + vld->vld0.quantizer_scale_type = !!(control->flags & XVMC_Q_SCALE_TYPE); + vld->vld0.intra_vlc_format = !!(control->flags & XVMC_INTRA_VLC_FORMAT); + vld->vld0.scan_order = !!(control->flags & XVMC_ALTERNATE_SCAN); + + vld->vld1.picture_coding_type = control->picture_coding_type; + + vld->desc_remap_table0.index_0 = FRAME_INTRA; + vld->desc_remap_table0.index_1 = FRAME_FRAME_PRED_FORWARD; + vld->desc_remap_table0.index_2 = FRAME_FIELD_PRED_FORWARD; + vld->desc_remap_table0.index_3 = FRAME_FIELD_PRED_BIDIRECT; /* dual prime */ + vld->desc_remap_table0.index_4 = FRAME_FRAME_PRED_BACKWARD; + vld->desc_remap_table0.index_5 = FRAME_FIELD_PRED_BACKWARD; + vld->desc_remap_table0.index_6 = FRAME_FRAME_PRED_BIDIRECT; + vld->desc_remap_table0.index_7 = FRAME_FIELD_PRED_BIDIRECT; + + vld->desc_remap_table1.index_8 = FRAME_INTRA; + vld->desc_remap_table1.index_9 = FRAME_FRAME_PRED_FORWARD; + vld->desc_remap_table1.index_10 = FRAME_FIELD_PRED_FORWARD; + vld->desc_remap_table1.index_11 = FRAME_FIELD_PRED_BIDIRECT; + vld->desc_remap_table1.index_12 = FRAME_FRAME_PRED_BACKWARD; + vld->desc_remap_table1.index_13 = FRAME_FIELD_PRED_BACKWARD; + vld->desc_remap_table1.index_14 = FRAME_FRAME_PRED_BIDIRECT; + vld->desc_remap_table1.index_15 = FRAME_FIELD_PRED_BIDIRECT; + + drm_intel_bo_subdata(media_state.vld_state.bo, 0, sizeof(tmp), vld); + return Success; } -static Status setup_media_surface(int index, dri_bo *bo, - unsigned long offset, int w, int h, Bool write) +static Status setup_media_surface(int index, dri_bo * bo, + unsigned long offset, int w, int h, + Bool write) { - struct brw_surface_state tmp, *ss = &tmp; - memset(ss, 0, sizeof(*ss)); - ss->ss0.surface_type = BRW_SURFACE_2D; - ss->ss0.surface_format = BRW_SURFACEFORMAT_R8_SINT; - ss->ss1.base_addr = offset + bo->offset; - ss->ss2.width = w - 1; - ss->ss2.height = h - 1; - ss->ss3.pitch = w - 1; - - if (media_state.binding_table.surface_states[index].bo) - drm_intel_bo_unreference(media_state.binding_table.surface_states[index].bo); - - media_state.binding_table.surface_states[index].bo = - drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", - sizeof(struct brw_surface_state), 0x1000); - if (!media_state.binding_table.surface_states[index].bo) - return BadAlloc; - - drm_intel_bo_subdata( - media_state.binding_table.surface_states[index].bo, - 0, sizeof(*ss), ss); - drm_intel_bo_emit_reloc(media_state.binding_table.surface_states[index].bo, - offsetof(struct brw_surface_state, ss1), - bo, offset, - I915_GEM_DOMAIN_RENDER, write?I915_GEM_DOMAIN_RENDER:0); - return Success; + struct brw_surface_state tmp, *ss = &tmp; + memset(ss, 0, sizeof(*ss)); + ss->ss0.surface_type = BRW_SURFACE_2D; + ss->ss0.surface_format = BRW_SURFACEFORMAT_R8_SINT; + ss->ss1.base_addr = offset + bo->offset; + ss->ss2.width = w - 1; + ss->ss2.height = h - 1; + ss->ss3.pitch = w - 1; + + if (media_state.binding_table.surface_states[index].bo) + drm_intel_bo_unreference(media_state. + binding_table.surface_states[index]. + bo); + + media_state.binding_table.surface_states[index].bo = + drm_intel_bo_alloc(xvmc_driver->bufmgr, "surface_state", + sizeof(struct brw_surface_state), 0x1000); + if (!media_state.binding_table.surface_states[index].bo) + return BadAlloc; + + drm_intel_bo_subdata(media_state.binding_table.surface_states[index].bo, + 0, sizeof(*ss), ss); + drm_intel_bo_emit_reloc(media_state.binding_table. + surface_states[index].bo, + offsetof(struct brw_surface_state, ss1), bo, + offset, I915_GEM_DOMAIN_RENDER, + write ? I915_GEM_DOMAIN_RENDER : 0); + return Success; } static Status setup_surface(struct i965_xvmc_surface *target, - struct i965_xvmc_surface *past, - struct i965_xvmc_surface *future, - int w, int h) + struct i965_xvmc_surface *past, + struct i965_xvmc_surface *future, int w, int h) { - Status ret; - ret = setup_media_surface(0, target->bo, 0, w, h, TRUE); - if (ret != Success) - return ret; - ret = setup_media_surface(1, target->bo, w*h, w/2, h/2, TRUE); - if (ret != Success) - return ret; - ret = setup_media_surface(2, target->bo, w*h + w*h/4, w/2, h/2, TRUE); - if (ret != Success) - return ret; - if (past) { - ret = setup_media_surface(4, past->bo, 0, w, h, FALSE); + Status ret; + ret = setup_media_surface(0, target->bo, 0, w, h, TRUE); if (ret != Success) - return ret; - ret = setup_media_surface(5, past->bo, w*h, w/2, h/2, FALSE); + return ret; + ret = setup_media_surface(1, target->bo, w * h, w / 2, h / 2, TRUE); if (ret != Success) - return ret; - ret = setup_media_surface(6, past->bo, w*h + w*h/4, w/2, h/2, FALSE); + return ret; + ret = + setup_media_surface(2, target->bo, w * h + w * h / 4, w / 2, h / 2, + TRUE); if (ret != Success) - return ret; - } - if (future) { - ret = setup_media_surface(7, future->bo, 0, w, h, FALSE); + return ret; + if (past) { + ret = setup_media_surface(4, past->bo, 0, w, h, FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(5, past->bo, w * h, w / 2, h / 2, + FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(6, past->bo, w * h + w * h / 4, w / 2, + h / 2, FALSE); + if (ret != Success) + return ret; + } + if (future) { + ret = setup_media_surface(7, future->bo, 0, w, h, FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(8, future->bo, w * h, w / 2, h / 2, + FALSE); + if (ret != Success) + return ret; + ret = + setup_media_surface(9, future->bo, w * h + w * h / 4, w / 2, + h / 2, FALSE); + if (ret != Success) + return ret; + } + return Success; +} + +static Status begin_surface(Display * display, XvMCContext * context, + XvMCSurface * target, + XvMCSurface * past, + XvMCSurface * future, + const XvMCMpegControl * control) +{ + struct i965_xvmc_contex *i965_ctx; + struct i965_xvmc_surface *priv_target, *priv_past, *priv_future; + intel_xvmc_context_ptr intel_ctx; + Status ret; + + intel_ctx = intel_xvmc_find_context(context->context_id); + priv_target = target->privData; + priv_past = past ? past->privData : NULL; + priv_future = future ? future->privData : NULL; + + ret = vld_state(control); if (ret != Success) - return ret; - ret = setup_media_surface(8, future->bo, w*h, w/2, h/2, FALSE); + return ret; + ret = setup_surface(priv_target, priv_past, priv_future, + context->width, context->height); if (ret != Success) - return ret; - ret = setup_media_surface(9, future->bo, w*h + w*h/4, w/2, h/2, FALSE); + return ret; + ret = binding_tables(); if (ret != Success) - return ret; - } - return Success; -} + return ret; + ret = interface_descriptor(); + if (ret != Success) + return ret; + ret = vfe_state(VFE_VLD_MODE); + if (ret != Success) + return ret; -static Status begin_surface(Display *display, XvMCContext *context, - XvMCSurface *target, - XvMCSurface *past, - XvMCSurface *future, - const XvMCMpegControl *control) -{ - struct i965_xvmc_contex *i965_ctx; - struct i965_xvmc_surface *priv_target, *priv_past, *priv_future; - intel_xvmc_context_ptr intel_ctx; - Status ret; - - intel_ctx = intel_xvmc_find_context(context->context_id); - priv_target = target->privData; - priv_past = past?past->privData:NULL; - priv_future = future?future->privData:NULL; - - ret = vld_state(control); - if (ret != Success) - return ret; - ret = setup_surface(priv_target, priv_past, priv_future, - context->width, context->height); - if (ret != Success) - return ret; - ret = binding_tables(); - if (ret != Success) - return ret; - ret = interface_descriptor(); - if (ret != Success) - return ret; - ret = vfe_state(VFE_VLD_MODE); - if (ret != Success) - return ret; - - LOCK_HARDWARE(intel_ctx->hw_context); - flush(); - UNLOCK_HARDWARE(intel_ctx->hw_context); - return Success; + LOCK_HARDWARE(intel_ctx->hw_context); + flush(); + UNLOCK_HARDWARE(intel_ctx->hw_context); + return Success; } -static Status put_slice(Display *display, XvMCContext *context, - unsigned char *slice, int nbytes) +static Status put_slice(Display * display, XvMCContext * context, + unsigned char *slice, int nbytes) { - return Success; + return Success; } static void state_base_address(struct i965_xvmc_context *i965_ctx) { - BATCH_LOCALS; - - if (i965_ctx->is_igdng) { - BEGIN_BATCH(8); - OUT_BATCH(BRW_STATE_BASE_ADDRESS|6); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - ADVANCE_BATCH(); - } else { - BEGIN_BATCH(6); - OUT_BATCH(BRW_STATE_BASE_ADDRESS|4); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - OUT_BATCH(0 | BASE_ADDRESS_MODIFY); - ADVANCE_BATCH(); - } + BATCH_LOCALS; + + if (i965_ctx->is_igdng) { + BEGIN_BATCH(8); + OUT_BATCH(BRW_STATE_BASE_ADDRESS | 6); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + ADVANCE_BATCH(); + } else { + BEGIN_BATCH(6); + OUT_BATCH(BRW_STATE_BASE_ADDRESS | 4); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + OUT_BATCH(0 | BASE_ADDRESS_MODIFY); + ADVANCE_BATCH(); + } } + static void pipeline_select() { - BATCH_LOCALS; - BEGIN_BATCH(1); - OUT_BATCH(NEW_PIPELINE_SELECT|PIPELINE_SELECT_MEDIA); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(1); + OUT_BATCH(NEW_PIPELINE_SELECT | PIPELINE_SELECT_MEDIA); + ADVANCE_BATCH(); } static void media_state_pointers(int vfe_mode) { - BATCH_LOCALS; - BEGIN_BATCH(3); - OUT_BATCH(BRW_MEDIA_STATE_POINTERS|1); - if (vfe_mode == VFE_VLD_MODE) - OUT_RELOC(media_state.vld_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 1); + BATCH_LOCALS; + BEGIN_BATCH(3); + OUT_BATCH(BRW_MEDIA_STATE_POINTERS | 1); + if (vfe_mode == VFE_VLD_MODE) + OUT_RELOC(media_state.vld_state.bo, I915_GEM_DOMAIN_INSTRUCTION, + 0, 1); else OUT_BATCH(0); - OUT_RELOC(media_state.vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); - ADVANCE_BATCH(); + OUT_RELOC(media_state.vfe_state.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); + ADVANCE_BATCH(); } static void align_urb_fence() { - BATCH_LOCALS; - int i, offset_to_next_cacheline; - unsigned long batch_offset; - BEGIN_BATCH(3); - batch_offset = (void *)batch_ptr - xvmc_driver->alloc.ptr; - offset_to_next_cacheline = ALIGN(batch_offset, 64) - batch_offset; - if (offset_to_next_cacheline <= 12 && offset_to_next_cacheline != 0) { - for (i = 0; i < offset_to_next_cacheline/4; i++) - OUT_BATCH(0); - ADVANCE_BATCH(); - } + BATCH_LOCALS; + int i, offset_to_next_cacheline; + unsigned long batch_offset; + BEGIN_BATCH(3); + batch_offset = (void *)batch_ptr - xvmc_driver->alloc.ptr; + offset_to_next_cacheline = ALIGN(batch_offset, 64) - batch_offset; + if (offset_to_next_cacheline <= 12 && offset_to_next_cacheline != 0) { + for (i = 0; i < offset_to_next_cacheline / 4; i++) + OUT_BATCH(0); + ADVANCE_BATCH(); + } } static void urb_layout() { - BATCH_LOCALS; - align_urb_fence(); - BEGIN_BATCH(3); - OUT_BATCH(BRW_URB_FENCE | - UF0_VFE_REALLOC | - UF0_CS_REALLOC | - UF0_SF_REALLOC | - UF0_CLIP_REALLOC | - UF0_GS_REALLOC | - UF0_VS_REALLOC | - 1); - - OUT_BATCH((0 << UF1_CLIP_FENCE_SHIFT) | - (0 << UF1_GS_FENCE_SHIFT) | - (0 << UF1_VS_FENCE_SHIFT)); - - OUT_BATCH((0 << UF2_CS_FENCE_SHIFT) | - (0 << UF2_SF_FENCE_SHIFT) | - ((URB_SIZE - CS_SIZE - 1)<< UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */ - ((URB_SIZE)<< UF2_CS_FENCE_SHIFT)); /* CS_SIZE */ - ADVANCE_BATCH(); + BATCH_LOCALS; + align_urb_fence(); + BEGIN_BATCH(3); + OUT_BATCH(BRW_URB_FENCE | + UF0_VFE_REALLOC | + UF0_CS_REALLOC | + UF0_SF_REALLOC | + UF0_CLIP_REALLOC | UF0_GS_REALLOC | UF0_VS_REALLOC | 1); + + OUT_BATCH((0 << UF1_CLIP_FENCE_SHIFT) | + (0 << UF1_GS_FENCE_SHIFT) | (0 << UF1_VS_FENCE_SHIFT)); + + OUT_BATCH((0 << UF2_CS_FENCE_SHIFT) | (0 << UF2_SF_FENCE_SHIFT) | ((URB_SIZE - CS_SIZE - 1) << UF2_VFE_FENCE_SHIFT) | /* VFE_SIZE */ + ((URB_SIZE) << UF2_CS_FENCE_SHIFT)); /* CS_SIZE */ + ADVANCE_BATCH(); } static void cs_urb_layout() { - BATCH_LOCALS; - BEGIN_BATCH(2); - OUT_BATCH(BRW_CS_URB_STATE | 0); - OUT_BATCH((CS_SIZE << 4) | /* URB Entry Allocation Size */ - (1 << 0)); /* Number of URB Entries */ - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(2); + OUT_BATCH(BRW_CS_URB_STATE | 0); + OUT_BATCH((CS_SIZE << 4) | /* URB Entry Allocation Size */ + (1 << 0)); /* Number of URB Entries */ + ADVANCE_BATCH(); } static void cs_buffer() { - BATCH_LOCALS; - BEGIN_BATCH(2); - OUT_BATCH(BRW_CONSTANT_BUFFER|0|(1<<8)); - OUT_RELOC(media_state.cs_object.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, CS_SIZE); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(2); + OUT_BATCH(BRW_CONSTANT_BUFFER | 0 | (1 << 8)); + OUT_RELOC(media_state.cs_object.bo, I915_GEM_DOMAIN_INSTRUCTION, 0, + CS_SIZE); + ADVANCE_BATCH(); } /* kick media object to gpu in idct mode*/ -static void send_media_object(XvMCMacroBlock *mb, dri_bo *bo, - uint32_t offset, - enum interface interface) +static void send_media_object(XvMCMacroBlock * mb, dri_bo * bo, + uint32_t offset, enum interface interface) { - BATCH_LOCALS; - BEGIN_BATCH(13); - OUT_BATCH(BRW_MEDIA_OBJECT|11); - OUT_BATCH(interface); - OUT_BATCH(6*128); - OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, offset); - - OUT_BATCH(mb->x<<4); - OUT_BATCH(mb->y<<4); + BATCH_LOCALS; + BEGIN_BATCH(13); + OUT_BATCH(BRW_MEDIA_OBJECT | 11); + OUT_BATCH(interface); + OUT_BATCH(6 * 128); OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, offset); - OUT_BATCH_SHORT(mb->coded_block_pattern); - OUT_BATCH_SHORT(mb->PMV[0][0][0]); - OUT_BATCH_SHORT(mb->PMV[0][0][1]); - OUT_BATCH_SHORT(mb->PMV[0][1][0]); - OUT_BATCH_SHORT(mb->PMV[0][1][1]); - - OUT_BATCH_SHORT(mb->PMV[1][0][0]); - OUT_BATCH_SHORT(mb->PMV[1][0][1]); - OUT_BATCH_SHORT(mb->PMV[1][1][0]); - OUT_BATCH_SHORT(mb->PMV[1][1][1]); - OUT_BATCH_CHAR(mb->dct_type); - OUT_BATCH_CHAR(mb->motion_vertical_field_select); - - OUT_BATCH(0xffffffff); - ADVANCE_BATCH(); + + OUT_BATCH(mb->x << 4); + OUT_BATCH(mb->y << 4); + OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, offset); + OUT_BATCH_SHORT(mb->coded_block_pattern); + OUT_BATCH_SHORT(mb->PMV[0][0][0]); + OUT_BATCH_SHORT(mb->PMV[0][0][1]); + OUT_BATCH_SHORT(mb->PMV[0][1][0]); + OUT_BATCH_SHORT(mb->PMV[0][1][1]); + + OUT_BATCH_SHORT(mb->PMV[1][0][0]); + OUT_BATCH_SHORT(mb->PMV[1][0][1]); + OUT_BATCH_SHORT(mb->PMV[1][1][0]); + OUT_BATCH_SHORT(mb->PMV[1][1][1]); + OUT_BATCH_CHAR(mb->dct_type); + OUT_BATCH_CHAR(mb->motion_vertical_field_select); + + OUT_BATCH(0xffffffff); + ADVANCE_BATCH(); } /* kick media object to gpu in vld mode*/ -static void vld_send_media_object(dri_bo *bo, - int slice_len, int mb_h_pos, int mb_v_pos, int mb_bit_offset, - int mb_count, int q_scale_code) +static void vld_send_media_object(dri_bo * bo, + int slice_len, int mb_h_pos, int mb_v_pos, + int mb_bit_offset, int mb_count, + int q_scale_code) { - BATCH_LOCALS; - BEGIN_BATCH(6); - OUT_BATCH(BRW_MEDIA_OBJECT|4); - OUT_BATCH(0); - OUT_BATCH(slice_len); - OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); - OUT_BATCH((mb_h_pos<<24)|(mb_v_pos<<16)|(mb_count<<8)|(mb_bit_offset)); - OUT_BATCH(q_scale_code<<24); - ADVANCE_BATCH(); + BATCH_LOCALS; + BEGIN_BATCH(6); + OUT_BATCH(BRW_MEDIA_OBJECT | 4); + OUT_BATCH(0); + OUT_BATCH(slice_len); + OUT_RELOC(bo, I915_GEM_DOMAIN_INSTRUCTION, 0, 0); + OUT_BATCH((mb_h_pos << 24) | (mb_v_pos << 16) | (mb_count << 8) | + (mb_bit_offset)); + OUT_BATCH(q_scale_code << 24); + ADVANCE_BATCH(); } -static Status put_slice2(Display *display, XvMCContext *context, - unsigned char *slice, int nbytes, int sliceCode) +static Status put_slice2(Display * display, XvMCContext * context, + unsigned char *slice, int nbytes, int sliceCode) { - unsigned int bit_buf; - intel_xvmc_context_ptr intel_ctx; - struct i965_xvmc_context *i965_ctx; - int q_scale_code, mb_row; - - i965_ctx = (struct i965_xvmc_context *)context->privData; - mb_row = *(slice - 1) - 1; - bit_buf = (slice[0]<<24) | (slice[1]<<16) | (slice[2]<<8) | (slice[3]); - - q_scale_code = bit_buf>>27; - - if (media_state.slice_data.bo) { - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_unmap_gtt(media_state.slice_data.bo); - else - drm_intel_bo_unmap(media_state.slice_data.bo); - - drm_intel_bo_unreference(media_state.slice_data.bo); - } - media_state.slice_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "slice data", VLD_MAX_SLICE_SIZE, 64); - if (!media_state.slice_data.bo) - return BadAlloc; - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(media_state.slice_data.bo); - else - drm_intel_bo_map(media_state.slice_data.bo, 1); - - memcpy(media_state.slice_data.bo->virtual, slice, nbytes); - - intel_ctx = intel_xvmc_find_context(context->context_id); - LOCK_HARDWARE(intel_ctx->hw_context); - state_base_address(i965_ctx); - pipeline_select(); - media_state_pointers(VFE_VLD_MODE); - urb_layout(); - cs_urb_layout(); - cs_buffer(); - vld_send_media_object(media_state.slice_data.bo, - nbytes, - 0, mb_row, 6, 127, q_scale_code); - intelFlushBatch(TRUE); - UNLOCK_HARDWARE(intel_ctx->hw_context); - - return Success; + unsigned int bit_buf; + intel_xvmc_context_ptr intel_ctx; + struct i965_xvmc_context *i965_ctx; + int q_scale_code, mb_row; + + i965_ctx = (struct i965_xvmc_context *)context->privData; + mb_row = *(slice - 1) - 1; + bit_buf = + (slice[0] << 24) | (slice[1] << 16) | (slice[2] << 8) | (slice[3]); + + q_scale_code = bit_buf >> 27; + + if (media_state.slice_data.bo) { + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_unmap_gtt(media_state.slice_data.bo); + else + drm_intel_bo_unmap(media_state.slice_data.bo); + + drm_intel_bo_unreference(media_state.slice_data.bo); + } + media_state.slice_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, + "slice data", + VLD_MAX_SLICE_SIZE, 64); + if (!media_state.slice_data.bo) + return BadAlloc; + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_map_gtt(media_state.slice_data.bo); + else + drm_intel_bo_map(media_state.slice_data.bo, 1); + + memcpy(media_state.slice_data.bo->virtual, slice, nbytes); + + intel_ctx = intel_xvmc_find_context(context->context_id); + LOCK_HARDWARE(intel_ctx->hw_context); + state_base_address(i965_ctx); + pipeline_select(); + media_state_pointers(VFE_VLD_MODE); + urb_layout(); + cs_urb_layout(); + cs_buffer(); + vld_send_media_object(media_state.slice_data.bo, + nbytes, 0, mb_row, 6, 127, q_scale_code); + intelFlushBatch(TRUE); + UNLOCK_HARDWARE(intel_ctx->hw_context); + + return Success; } -static Status put_surface(Display *display,XvMCSurface *surface, - Drawable draw, short srcx, short srcy, - unsigned short srcw, unsigned short srch, - short destx, short desty, - unsigned short destw, unsigned short desth, - int flags, struct intel_xvmc_command *data) +static Status put_surface(Display * display, XvMCSurface * surface, + Drawable draw, short srcx, short srcy, + unsigned short srcw, unsigned short srch, + short destx, short desty, + unsigned short destw, unsigned short desth, + int flags, struct intel_xvmc_command *data) { - struct i965_xvmc_surface *private_surface = - surface->privData; - uint32_t handle; + struct i965_xvmc_surface *private_surface = surface->privData; + uint32_t handle; - drm_intel_bo_flink(private_surface->bo, &handle); - data->handle = handle; + drm_intel_bo_flink(private_surface->bo, &handle); + data->handle = handle; return Success; } -static Status render_surface(Display *display, - XvMCContext *context, - unsigned int picture_structure, - XvMCSurface *target_surface, - XvMCSurface *past_surface, - XvMCSurface *future_surface, - unsigned int flags, - unsigned int num_macroblocks, - unsigned int first_macroblock, - XvMCMacroBlockArray *macroblock_array, - XvMCBlockArray *blocks) +static Status render_surface(Display * display, + XvMCContext * context, + unsigned int picture_structure, + XvMCSurface * target_surface, + XvMCSurface * past_surface, + XvMCSurface * future_surface, + unsigned int flags, + unsigned int num_macroblocks, + unsigned int first_macroblock, + XvMCMacroBlockArray * macroblock_array, + XvMCBlockArray * blocks) { - struct i965_xvmc_surface *priv_target, *priv_past, *priv_future; - intel_xvmc_context_ptr intel_ctx; - XvMCMacroBlock *mb; - Status ret; - unsigned short *block_ptr; - int i, j; - int block_offset = 0; - struct i965_xvmc_context *i965_ctx; - - intel_ctx = intel_xvmc_find_context(context->context_id); - if (!intel_ctx) { - XVMC_ERR("Can't find intel xvmc context\n"); - return BadValue; - } - - i965_ctx = (struct i965_xvmc_context *)context->privData; - priv_target = target_surface->privData; - priv_past = past_surface?past_surface->privData:NULL; - priv_future = future_surface?future_surface->privData:NULL; - - ret = setup_surface(priv_target, priv_past, priv_future, - context->width, context->height); - if (ret != Success) - return ret; - ret = binding_tables(); - if (ret != Success) - return ret; - ret = interface_descriptor(); - if (ret != Success) - return ret; - ret = cs_init(INTERFACE_NUM); - if (ret != Success) - return ret; - ret = vfe_state(VFE_GENERIC_MODE); - if (ret != Success) - return ret; - - if (media_state.mb_data.bo) { - if (xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_unmap_gtt(media_state.mb_data.bo); - else - drm_intel_bo_unmap(media_state.mb_data.bo); - - drm_intel_bo_unreference(media_state.mb_data.bo); - } - unsigned int block_num = - (((context->width + 15) >> 4) * ((context->height + 15) >> 4)); - unsigned int surface_size = (64 * sizeof(short) * 6 * block_num); - media_state.mb_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, - "macroblock data", surface_size, 64); - if(!media_state.mb_data.bo) - return BadAlloc; - if(xvmc_driver->kernel_exec_fencing) - drm_intel_gem_bo_map_gtt(media_state.mb_data.bo); - else - drm_intel_bo_map(media_state.mb_data.bo, 1); - - block_ptr = media_state.mb_data.bo->virtual; - unsigned short *mb_block_ptr; - for (i = first_macroblock; - i < num_macroblocks + first_macroblock; i++) { - mb = ¯oblock_array->macro_blocks[i]; - mb_block_ptr = &blocks->blocks[(mb->index<<6)]; - - if (mb->coded_block_pattern & 0x20) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; - } - if (mb->coded_block_pattern & 0x10) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j + 8, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; + struct i965_xvmc_surface *priv_target, *priv_past, *priv_future; + intel_xvmc_context_ptr intel_ctx; + XvMCMacroBlock *mb; + Status ret; + unsigned short *block_ptr; + int i, j; + int block_offset = 0; + struct i965_xvmc_context *i965_ctx; + + intel_ctx = intel_xvmc_find_context(context->context_id); + if (!intel_ctx) { + XVMC_ERR("Can't find intel xvmc context\n"); + return BadValue; } - block_ptr += 2*64; - if (mb->coded_block_pattern & 0x08) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; - } - if (mb->coded_block_pattern & 0x04) { - for (j = 0; j < 8; j++) - memcpy(block_ptr + 16*j + 8, mb_block_ptr + 8*j, 16); - mb_block_ptr += 64; - } + i965_ctx = (struct i965_xvmc_context *)context->privData; + priv_target = target_surface->privData; + priv_past = past_surface ? past_surface->privData : NULL; + priv_future = future_surface ? future_surface->privData : NULL; + + ret = setup_surface(priv_target, priv_past, priv_future, + context->width, context->height); + if (ret != Success) + return ret; + ret = binding_tables(); + if (ret != Success) + return ret; + ret = interface_descriptor(); + if (ret != Success) + return ret; + ret = cs_init(INTERFACE_NUM); + if (ret != Success) + return ret; + ret = vfe_state(VFE_GENERIC_MODE); + if (ret != Success) + return ret; - block_ptr += 2*64; - if (mb->coded_block_pattern & 0x2) { - memcpy(block_ptr, mb_block_ptr, 128); - mb_block_ptr += 64; + if (media_state.mb_data.bo) { + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_unmap_gtt(media_state.mb_data.bo); + else + drm_intel_bo_unmap(media_state.mb_data.bo); + + drm_intel_bo_unreference(media_state.mb_data.bo); } + unsigned int block_num = + (((context->width + 15) >> 4) * ((context->height + 15) >> 4)); + unsigned int surface_size = (64 * sizeof(short) * 6 * block_num); + media_state.mb_data.bo = drm_intel_bo_alloc(xvmc_driver->bufmgr, + "macroblock data", + surface_size, 64); + if (!media_state.mb_data.bo) + return BadAlloc; + if (xvmc_driver->kernel_exec_fencing) + drm_intel_gem_bo_map_gtt(media_state.mb_data.bo); + else + drm_intel_bo_map(media_state.mb_data.bo, 1); + + block_ptr = media_state.mb_data.bo->virtual; + unsigned short *mb_block_ptr; + for (i = first_macroblock; i < num_macroblocks + first_macroblock; i++) { + mb = ¯oblock_array->macro_blocks[i]; + mb_block_ptr = &blocks->blocks[(mb->index << 6)]; + + if (mb->coded_block_pattern & 0x20) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j, mb_block_ptr + 8 * j, + 16); + mb_block_ptr += 64; + } + if (mb->coded_block_pattern & 0x10) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j + 8, + mb_block_ptr + 8 * j, 16); + mb_block_ptr += 64; + } - block_ptr += 64; - if (mb->coded_block_pattern & 0x1) - memcpy(block_ptr, mb_block_ptr, 128); - block_ptr += 64; - } - - LOCK_HARDWARE(intel_ctx->hw_context); - state_base_address(i965_ctx); - flush(); - pipeline_select(); - urb_layout(); - media_state_pointers(VFE_GENERIC_MODE); - cs_urb_layout(); - cs_buffer(); - for (i = first_macroblock; - i < num_macroblocks + first_macroblock; - i++, block_offset += 128*6) { - mb = ¯oblock_array->macro_blocks[i]; - - if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_INTRA + INTERFACE_NUM); - } else { - if (((mb->motion_type & 3) == XVMC_PREDICTION_FRAME)) { - if ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_FORWARD)) { - if ((mb->macroblock_type & XVMC_MB_TYPE_MOTION_BACKWARD)) { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FRAME_PRED_BIDIRECT + INTERFACE_NUM); - } else { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FRAME_PRED_FORWARD + INTERFACE_NUM); - } - } else if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD)) { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FRAME_PRED_BACKWARD + INTERFACE_NUM); + block_ptr += 2 * 64; + if (mb->coded_block_pattern & 0x08) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j, mb_block_ptr + 8 * j, + 16); + mb_block_ptr += 64; } - } else if ((mb->motion_type & 3) == XVMC_PREDICTION_FIELD) { - if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_FORWARD)) { - if (((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD))) { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FIELD_PRED_BIDIRECT + INTERFACE_NUM); - } else { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FIELD_PRED_FORWARD + INTERFACE_NUM); - } - } else if ((mb->macroblock_type&XVMC_MB_TYPE_MOTION_BACKWARD)) { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FIELD_PRED_BACKWARD + INTERFACE_NUM); + if (mb->coded_block_pattern & 0x04) { + for (j = 0; j < 8; j++) + memcpy(block_ptr + 16 * j + 8, + mb_block_ptr + 8 * j, 16); + mb_block_ptr += 64; } - } else { - send_media_object(mb, media_state.mb_data.bo, block_offset, - FRAME_FIELD_PRED_BIDIRECT + INTERFACE_NUM); /*dual prime*/ - } + + block_ptr += 2 * 64; + if (mb->coded_block_pattern & 0x2) { + memcpy(block_ptr, mb_block_ptr, 128); + mb_block_ptr += 64; + } + + block_ptr += 64; + if (mb->coded_block_pattern & 0x1) + memcpy(block_ptr, mb_block_ptr, 128); + block_ptr += 64; } - } - intelFlushBatch(TRUE); - UNLOCK_HARDWARE(intel_ctx->hw_context); - return Success; + + LOCK_HARDWARE(intel_ctx->hw_context); + state_base_address(i965_ctx); + flush(); + pipeline_select(); + urb_layout(); + media_state_pointers(VFE_GENERIC_MODE); + cs_urb_layout(); + cs_buffer(); + for (i = first_macroblock; + i < num_macroblocks + first_macroblock; + i++, block_offset += 128 * 6) { + mb = ¯oblock_array->macro_blocks[i]; + + if (mb->macroblock_type & XVMC_MB_TYPE_INTRA) { + send_media_object(mb, media_state.mb_data.bo, + block_offset, + FRAME_INTRA + INTERFACE_NUM); + } else { + if (((mb->motion_type & 3) == XVMC_PREDICTION_FRAME)) { + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_FORWARD)) { + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD)) { + send_media_object(mb, + media_state.mb_data. + bo, + block_offset, + FRAME_FRAME_PRED_BIDIRECT + + + INTERFACE_NUM); + } else { + send_media_object(mb, + media_state.mb_data. + bo, + block_offset, + FRAME_FRAME_PRED_FORWARD + + + INTERFACE_NUM); + } + } else + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD)) { + send_media_object(mb, + media_state. + mb_data.bo, + block_offset, + FRAME_FRAME_PRED_BACKWARD + + INTERFACE_NUM); + } + } else if ((mb->motion_type & 3) == + XVMC_PREDICTION_FIELD) { + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_FORWARD)) { + if (((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD))) { + send_media_object(mb, + media_state.mb_data. + bo, + block_offset, + FRAME_FIELD_PRED_BIDIRECT + + + INTERFACE_NUM); + } else { + send_media_object(mb, + media_state.mb_data. + bo, + block_offset, + FRAME_FIELD_PRED_FORWARD + + + INTERFACE_NUM); + } + } else + if ((mb->macroblock_type & + XVMC_MB_TYPE_MOTION_BACKWARD)) { + send_media_object(mb, + media_state. + mb_data.bo, + block_offset, + FRAME_FIELD_PRED_BACKWARD + + INTERFACE_NUM); + } + } else { + send_media_object(mb, media_state.mb_data.bo, block_offset, FRAME_FIELD_PRED_BIDIRECT + INTERFACE_NUM); /*dual prime */ + } + } + } + intelFlushBatch(TRUE); + UNLOCK_HARDWARE(intel_ctx->hw_context); + return Success; } struct _intel_xvmc_driver xvmc_vld_driver = { - .type = XVMC_I965_MPEG2_VLD, - .create_context = create_context, - .destroy_context = destroy_context, - .create_surface = create_surface, - .destroy_surface = destroy_surface, - .load_qmatrix = load_qmatrix, - .get_surface_status = get_surface_status, - .begin_surface = begin_surface, + .type = XVMC_I965_MPEG2_VLD, + .create_context = create_context, + .destroy_context = destroy_context, + .create_surface = create_surface, + .destroy_surface = destroy_surface, + .load_qmatrix = load_qmatrix, + .get_surface_status = get_surface_status, + .begin_surface = begin_surface, .render_surface = render_surface, - .put_surface = put_surface, - .put_slice = put_slice, - .put_slice2 = put_slice2 + .put_surface = put_surface, + .put_slice = put_slice, + .put_slice2 = put_slice2 }; |