7 #include "nv_include.h"
8 #include "nv_shaders.h"
10 typedef struct nv_pict_surface_format {
13 } nv_pict_surface_format_t;
15 typedef struct nv_pict_texture_format {
19 } nv_pict_texture_format_t;
21 typedef struct nv_pict_op {
28 typedef struct nv30_exa_state {
32 PictTransformPtr transform;
37 static nv30_exa_state_t exa_state;
38 #define NV30EXA_STATE nv30_exa_state_t *state = &exa_state
40 static nv_pict_surface_format_t
41 NV30SurfaceFormat[] = {
42 { PICT_a8r8g8b8 , 0x148 },
43 { PICT_x8r8g8b8 , 0x145 },
44 { PICT_r5g6b5 , 0x143 },
45 // { PICT_a8 , 0x149 },
48 static nv_pict_surface_format_t *
49 NV30_GetPictSurfaceFormat(int format)
53 for(i=0;i<sizeof(NV30SurfaceFormat)/sizeof(NV30SurfaceFormat[0]);i++)
55 if (NV30SurfaceFormat[i].pict_fmt == format)
56 return &NV30SurfaceFormat[i];
63 NV30EXA_FPID_PASS_COL0 = 0,
64 NV30EXA_FPID_PASS_TEX0 = 1,
65 NV30EXA_FPID_COMPOSITE_MASK = 2,
66 NV30EXA_FPID_COMPOSITE_MASK_SA_CA = 3,
67 NV30EXA_FPID_COMPOSITE_MASK_CA = 4,
71 static nv_shader_t *nv40_fp_map[NV30EXA_FPID_MAX] = {
74 &nv30_fp_composite_mask,
75 &nv30_fp_composite_mask_sa_ca,
76 &nv30_fp_composite_mask_ca
79 static nv_shader_t *nv40_fp_map_a8[NV30EXA_FPID_MAX];
82 NV30EXAHackupA8Shaders(ScrnInfoPtr pScrn)
86 for (s = 0; s < NV30EXA_FPID_MAX; s++) {
87 nv_shader_t *def, *a8;
90 a8 = xcalloc(1, sizeof(nv_shader_t));
91 a8->card_priv.NV30FP.num_regs = def->card_priv.NV30FP.num_regs;
92 a8->size = def->size + 4;
93 memcpy(a8->data, def->data, def->size * sizeof(uint32_t));
94 nv40_fp_map_a8[s] = a8;
96 a8->data[a8->size - 8 + 0] &= ~0x00000081;
97 a8->data[a8->size - 4 + 0] = 0x01401e81;
98 a8->data[a8->size - 4 + 1] = 0x1c9dfe00;
99 a8->data[a8->size - 4 + 2] = 0x0001c800;
100 a8->data[a8->size - 4 + 3] = 0x0001c800;
104 /* should be in nouveau_reg.h at some point.. */
105 #define NV30TCL_TX_SWIZZLE_UNIT_S0_X_SHIFT 14
106 #define NV30TCL_TX_SWIZZLE_UNIT_S0_X_ZERO 0
107 #define NV30TCL_TX_SWIZZLE_UNIT_S0_X_ONE 1
108 #define NV30TCL_TX_SWIZZLE_UNIT_S0_X_S1 2
109 #define NV30TCL_TX_SWIZZLE_UNIT_S0_Y_SHIFT 12
110 #define NV30TCL_TX_SWIZZLE_UNIT_S0_Z_SHIFT 10
111 #define NV30TCL_TX_SWIZZLE_UNIT_S0_W_SHIFT 8
112 #define NV30TCL_TX_SWIZZLE_UNIT_S1_X_SHIFT 6
113 #define NV30TCL_TX_SWIZZLE_UNIT_S1_X_X 3
114 #define NV30TCL_TX_SWIZZLE_UNIT_S1_X_Y 2
115 #define NV30TCL_TX_SWIZZLE_UNIT_S1_X_Z 1
116 #define NV30TCL_TX_SWIZZLE_UNIT_S1_X_W 0
117 #define NV30TCL_TX_SWIZZLE_UNIT_S1_Y_SHIFT 4
118 #define NV30TCL_TX_SWIZZLE_UNIT_S1_Z_SHIFT 2
119 #define NV30TCL_TX_SWIZZLE_UNIT_S1_W_SHIFT 0
121 #define _(r,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w) \
125 (NV30TCL_TX_SWIZZLE_UNIT_S0_X_##ts0x << NV30TCL_TX_SWIZZLE_UNIT_S0_X_SHIFT)|\
126 (NV30TCL_TX_SWIZZLE_UNIT_S0_X_##ts0y << NV30TCL_TX_SWIZZLE_UNIT_S0_Y_SHIFT)|\
127 (NV30TCL_TX_SWIZZLE_UNIT_S0_X_##ts0z << NV30TCL_TX_SWIZZLE_UNIT_S0_Z_SHIFT)|\
128 (NV30TCL_TX_SWIZZLE_UNIT_S0_X_##ts0w << NV30TCL_TX_SWIZZLE_UNIT_S0_W_SHIFT)|\
129 (NV30TCL_TX_SWIZZLE_UNIT_S1_X_##ts1x << NV30TCL_TX_SWIZZLE_UNIT_S1_X_SHIFT)|\
130 (NV30TCL_TX_SWIZZLE_UNIT_S1_X_##ts1y << NV30TCL_TX_SWIZZLE_UNIT_S1_Y_SHIFT)|\
131 (NV30TCL_TX_SWIZZLE_UNIT_S1_X_##ts1z << NV30TCL_TX_SWIZZLE_UNIT_S1_Z_SHIFT)|\
132 (NV30TCL_TX_SWIZZLE_UNIT_S1_X_##ts1w << NV30TCL_TX_SWIZZLE_UNIT_S1_W_SHIFT)\
135 static nv_pict_texture_format_t
136 NV30TextureFormat[] = {
137 _(a8r8g8b8, 0x12, S1, S1, S1, S1, X, Y, Z, W),
138 _(a8b8g8r8, 0x12, S1, S1, S1, S1, Z, Y, X, W),
139 _(x8r8g8b8, 0x12, S1, S1, S1, ONE, X, Y, Z, W),
140 _(x8b8g8r8, 0x12, S1, S1, S1, ONE, Z, Y, X, W),
141 _(a1r5g5b5, 0x10, S1, S1, S1, S1, X, Y, Z, W),
142 _(x1r5g5b5, 0x10, S1, S1, S1, ONE, X, Y, Z, W),
143 _(x4r4g4b4, 0x1d, S1, S1, S1, ONE, X, Y, Z, W),
144 _(a4r4g4b4, 0x1d, S1, S1, S1, S1, X, Y, Z, W),
145 _( a8, 0x1b, ZERO, ZERO, ZERO, S1, W, W, W, W),
149 static nv_pict_texture_format_t *
150 NV30_GetPictTextureFormat(int format)
154 for(i=0;i<sizeof(NV30TextureFormat)/sizeof(NV30TextureFormat[0]);i++)
156 if (NV30TextureFormat[i].pict_fmt == format)
157 return &NV30TextureFormat[i];
163 #define NV34_TCL_PRIMITIVE_3D_BF_ZERO 0x0000
164 #define NV34_TCL_PRIMITIVE_3D_BF_ONE 0x0001
165 #define NV34_TCL_PRIMITIVE_3D_BF_SRC_COLOR 0x0300
166 #define NV34_TCL_PRIMITIVE_3D_BF_ONE_MINUS_SRC_COLOR 0x0301
167 #define NV34_TCL_PRIMITIVE_3D_BF_SRC_ALPHA 0x0302
168 #define NV34_TCL_PRIMITIVE_3D_BF_ONE_MINUS_SRC_ALPHA 0x0303
169 #define NV34_TCL_PRIMITIVE_3D_BF_DST_ALPHA 0x0304
170 #define NV34_TCL_PRIMITIVE_3D_BF_ONE_MINUS_DST_ALPHA 0x0305
171 #define NV34_TCL_PRIMITIVE_3D_BF_DST_COLOR 0x0306
172 #define NV34_TCL_PRIMITIVE_3D_BF_ONE_MINUS_DST_COLOR 0x0307
173 #define NV34_TCL_PRIMITIVE_3D_BF_ALPHA_SATURATE 0x0308
174 #define BF(bf) NV34_TCL_PRIMITIVE_3D_BF_##bf
178 /* Clear */ { 0, 0, BF( ZERO), BF( ZERO) },
179 /* Src */ { 0, 0, BF( ONE), BF( ZERO) },
180 /* Dst */ { 0, 0, BF( ZERO), BF( ONE) },
181 /* Over */ { 1, 0, BF( ONE), BF(ONE_MINUS_SRC_ALPHA) },
182 /* OverReverse */ { 0, 1, BF(ONE_MINUS_DST_ALPHA), BF( ONE) },
183 /* In */ { 0, 1, BF( DST_ALPHA), BF( ZERO) },
184 /* InReverse */ { 1, 0, BF( ZERO), BF( SRC_ALPHA) },
185 /* Out */ { 0, 1, BF(ONE_MINUS_DST_ALPHA), BF( ZERO) },
186 /* OutReverse */ { 1, 0, BF( ZERO), BF(ONE_MINUS_SRC_ALPHA) },
187 /* Atop */ { 1, 1, BF( DST_ALPHA), BF(ONE_MINUS_SRC_ALPHA) },
188 /* AtopReverse */ { 1, 1, BF(ONE_MINUS_DST_ALPHA), BF( SRC_ALPHA) },
189 /* Xor */ { 1, 1, BF(ONE_MINUS_DST_ALPHA), BF(ONE_MINUS_SRC_ALPHA) },
190 /* Add */ { 0, 0, BF( ONE), BF( ONE) }
193 static nv_pict_op_t *
194 NV30_GetPictOpRec(int op)
196 if (op >= PictOpSaturate)
201 case 0:ErrorF("Op Clear\n");break;
202 case 1:ErrorF("Op Src\n");break;
203 case 2:ErrorF("Op Dst\n");break;
204 case 3:ErrorF("Op Over\n");break;
205 case 4:ErrorF("Op OverReverse\n");break;
206 case 5:ErrorF("Op In\n");break;
207 case 6:ErrorF("Op InReverse\n");break;
208 case 7:ErrorF("Op Out\n");break;
209 case 8:ErrorF("Op OutReverse\n");break;
210 case 9:ErrorF("Op Atop\n");break;
211 case 10:ErrorF("Op AtopReverse\n");break;
212 case 11:ErrorF("Op Xor\n");break;
213 case 12:ErrorF("Op Add\n");break;
216 return &NV30PictOp[op];
219 #define FALLBACK_DEBUG 0
220 #if FALLBACK_DEBUG == 1
221 #define FALLBACK(fmt,args...) do { \
222 ErrorF("FALLBACK %s:%d> " fmt, __func__, __LINE__, ##args); \
226 #define FALLBACK(fmt,args...) do { \
232 NV30_LoadFragProg(ScrnInfoPtr pScrn, nv_shader_t *shader)
234 NVPtr pNv = NVPTR(pScrn);
235 static NVAllocRec *fp_mem = NULL;
236 static int next_hw_id_offset = 0;
239 fp_mem = NVAllocateMemory(pNv, NOUVEAU_MEM_FB, 0x1000);
241 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
242 "Couldn't alloc fragprog buffer!\n");
247 if (!shader->hw_id) {
248 memcpy(fp_mem->map + next_hw_id_offset, shader->data,
252 shader->hw_id = fp_mem->offset;
253 shader->hw_id += next_hw_id_offset;
255 next_hw_id_offset += (shader->size * sizeof(uint32_t));
256 next_hw_id_offset = (next_hw_id_offset + 63) & ~63;
259 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_FP_ACTIVE_PROGRAM, 1);
260 OUT_RING (shader->hw_id|1);
262 BEGIN_RING(Nv3D, 0x23c, 1);
264 BEGIN_RING(Nv3D, 0x1d60, 1);
265 OUT_RING (0); /* USES_KIL (1<<7) == 0 */
266 BEGIN_RING(Nv3D, 0x1450, 1);
267 OUT_RING (shader->card_priv.NV30FP.num_regs << 16| 4);
268 BEGIN_RING(Nv3D, 0x1d7c, 1);
269 OUT_RING (0xffff0000);
274 NV30_SetupBlend(ScrnInfoPtr pScrn, nv_pict_op_t *blend,
275 PictFormatShort dest_format, Bool component_alpha)
277 NVPtr pNv = NVPTR(pScrn);
278 uint32_t sblend, dblend;
280 sblend = blend->src_card_op;
281 dblend = blend->dst_card_op;
283 if (blend->dst_alpha) {
284 if (!PICT_FORMAT_A(dest_format)) {
285 if (sblend == BF(DST_ALPHA)) {
287 } else if (sblend == BF(ONE_MINUS_DST_ALPHA)) {
290 } else if (dest_format == PICT_a8) {
291 if (sblend == BF(DST_ALPHA)) {
292 sblend = BF(DST_COLOR);
293 } else if (sblend == BF(ONE_MINUS_DST_ALPHA)) {
294 sblend = BF(ONE_MINUS_DST_COLOR);
299 if (blend->src_alpha && (component_alpha || dest_format == PICT_a8)) {
300 if (dblend == BF(SRC_ALPHA)) {
301 dblend = BF(SRC_COLOR);
302 } else if (dblend == BF(ONE_MINUS_SRC_ALPHA)) {
303 dblend = BF(ONE_MINUS_SRC_COLOR);
307 if (sblend == BF(ONE) && dblend == BF(ZERO)) {
308 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1);
311 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 5);
313 OUT_RING ((sblend << 16) | sblend);
314 OUT_RING ((dblend << 16) | dblend);
315 OUT_RING (0x00000000); /* Blend colour */
316 OUT_RING ((0x8006 << 16) | 0x8006); /* FUNC_ADD, FUNC_ADD */
321 NV30EXATexture(ScrnInfoPtr pScrn, PixmapPtr pPix, PicturePtr pPict, int unit)
323 NVPtr pNv = NVPTR(pScrn);
324 nv_pict_texture_format_t *fmt;
325 uint32_t card_filter, card_repeat;
328 fmt = NV30_GetPictTextureFormat(pPict->format);
332 card_repeat = 3; /* repeatNone */
334 if (pPict->filter == PictFilterBilinear)
340 NV34_TCL_PRIMITIVE_3D_TX_OFFSET(unit), 8);
341 OUT_RING (NVAccelGetPixmapOffset(pPix));
343 OUT_RING ((2 << 4) /* 2D */ |
344 (fmt->card_fmt << 8) |
345 (1 << 16) /* 1 mipmap level */ |
346 /* (log2i(pPix->drawable.width) << 20) |
347 (log2i(pPix->drawable.height) << 24) |*/
350 OUT_RING ((card_repeat << 0) /* S */ |
351 (card_repeat << 8) /* T */ |
352 (card_repeat << 16) /* R */);
353 OUT_RING (0x40000000); /* enable */
354 OUT_RING ((((uint32_t)exaGetPixmapPitch(pPix))<<16) | fmt->card_swz);
356 OUT_RING ((card_filter << 16) /* min */ |
357 (card_filter << 24) /* mag */ |
358 0x3fd6 /* engine lock */);
359 OUT_RING ((pPix->drawable.width << 16) | pPix->drawable.height);
360 OUT_RING (0); /* border ARGB */
362 state->unit[unit].width = (float)pPix->drawable.width;
363 state->unit[unit].height = (float)pPix->drawable.height;
364 state->unit[unit].transform = pPict->transform;
370 NV30_SetupSurface(ScrnInfoPtr pScrn, PixmapPtr pPix, PicturePtr pPict)
372 NVPtr pNv = NVPTR(pScrn);
373 nv_pict_surface_format_t *fmt;
375 fmt = NV30_GetPictSurfaceFormat(pPict->format);
377 ErrorF("AIII no format\n");
381 uint32_t pitch = (uint32_t)exaGetPixmapPitch(pPix);
383 int w = pPict->pDrawable->width;
384 int h = pPict->pDrawable->height;
385 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 5);
388 OUT_RING (fmt->card_fmt); /* format */
389 OUT_RING (pitch << 16 | pitch);
390 OUT_RING (NVAccelGetPixmapOffset(pPix));
391 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_CLIP_HORIZ(0), 2);
392 OUT_RING ((w-1)<<16);
393 OUT_RING ((h-1)<<16);
394 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 2);
402 NV30EXACheckCompositeTexture(PicturePtr pPict)
404 nv_pict_texture_format_t *fmt;
405 int w = pPict->pDrawable->width;
406 int h = pPict->pDrawable->height;
408 if ((w > 4096) || (h>4096))
409 FALLBACK("picture too large, %dx%d\n", w, h);
411 fmt = NV30_GetPictTextureFormat(pPict->format);
413 FALLBACK("picture format 0x%08x not supported\n",
416 if (pPict->filter != PictFilterNearest &&
417 pPict->filter != PictFilterBilinear)
418 FALLBACK("filter 0x%x not supported\n", pPict->filter);
420 if (pPict->repeat && pPict->repeatType != RepeatNone)
421 FALLBACK("repeat 0x%x not supported\n", pPict->repeatType);
427 NV30EXACheckComposite(int op, PicturePtr psPict,
431 nv_pict_surface_format_t *fmt;
434 opr = NV30_GetPictOpRec(op);
436 FALLBACK("unsupported blend op 0x%x\n", op);
438 fmt = NV30_GetPictSurfaceFormat(pdPict->format);
440 FALLBACK("dst picture format 0x%08x not supported\n",
443 if (!NV30EXACheckCompositeTexture(psPict))
444 FALLBACK("src picture\n");
446 if (pmPict->componentAlpha &&
447 PICT_FORMAT_RGB(pmPict->format) &&
448 opr->src_alpha && opr->src_card_op != BF(ZERO))
449 FALLBACK("mask CA + SA\n");
450 if (!NV30EXACheckCompositeTexture(pmPict))
451 FALLBACK("mask picture\n");
457 void NV30_SetVtx(ScrnInfoPtr pScrn, int multitex)
459 NVPtr pNv = NVPTR(pScrn);
461 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ARRAY_FORMAT(0), 16);
485 NV30EXAPrepareComposite(int op, PicturePtr psPict,
492 ScrnInfoPtr pScrn = xf86Screens[psPix->drawable.pScreen->myNum];
493 NVPtr pNv = NVPTR(pScrn);
495 int fpid = NV30EXA_FPID_PASS_COL0;
498 blend = NV30_GetPictOpRec(op);
500 NV30_SetupBlend(pScrn, blend, pdPict->format,
501 (pmPict && pmPict->componentAlpha &&
502 PICT_FORMAT_RGB(pmPict->format)));
504 NV30_SetupSurface(pScrn, pdPix, pdPict);
505 NV30EXATexture(pScrn, psPix, psPict, 0);
508 #define printformat(f) ErrorF("(%xh %dbpp A%dR%dG%dB%d)",f,(f>>24),(f&0xf000)>>12,(f&0xf00)>>8,(f&0xf0)>>4,f&0xf)
509 ErrorF("Preparecomposite src(%dx%d)",psPict->pDrawable->width,psPict->pDrawable->height);
510 printformat((psPict->format));
511 ErrorF(" dst(%dx%d)",pdPict->pDrawable->width,pdPict->pDrawable->height);
512 printformat((pdPict->format));
515 ErrorF(" mask(%dx%d)",pmPict->pDrawable->width,pmPict->pDrawable->height);
516 printformat((pmPict->format));
521 NV30_SetVtx(pScrn,pmPict?1:0);
523 NV30EXATexture(pScrn, pmPix, pmPict, 1);
525 if (pmPict->componentAlpha && PICT_FORMAT_RGB(pmPict->format)) {
526 if (blend->src_alpha)
527 fpid = NV30EXA_FPID_COMPOSITE_MASK_SA_CA;
529 fpid = NV30EXA_FPID_COMPOSITE_MASK_CA;
531 fpid = NV30EXA_FPID_COMPOSITE_MASK;
534 state->have_mask = TRUE;
536 fpid = NV30EXA_FPID_PASS_TEX0;
538 state->have_mask = FALSE;
541 if (pdPict->format == PICT_a8)
542 NV30_LoadFragProg(pScrn, nv40_fp_map_a8[fpid]);
544 NV30_LoadFragProg(pScrn, nv40_fp_map[fpid]);
546 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_BEGIN_END, 1);
547 OUT_RING (8); /* GL_QUADS */
552 #define xFixedToFloat(v) \
553 ((float)xFixedToInt((v)) + ((float)xFixedFrac(v) / 65536.0))
556 NV30EXATransformCoord(PictTransformPtr t, int x, int y, float sx, float sy,
557 float *x_ret, float *y_ret)
562 v.vector[0] = IntToxFixed(x);
563 v.vector[1] = IntToxFixed(y);
564 v.vector[2] = xFixed1;
565 PictureTransformPoint(t, &v);
566 *x_ret = xFixedToFloat(v.vector[0]);
567 *y_ret = xFixedToFloat(v.vector[1]);
574 #define CV_OUTm(sx,sy,mx,my,dx,dy) do { \
575 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2F_X(8), 4); \
576 OUT_RINGf ((sx)); OUT_RINGf ((sy)); \
577 OUT_RINGf ((mx)); OUT_RINGf ((my)); \
578 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2I(0), 1); \
579 OUT_RING (((dy)<<16)|(dx)); \
581 #define CV_OUT(sx,sy,dx,dy) do { \
582 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2F_X(8), 2); \
583 OUT_RINGf ((sx)); OUT_RINGf ((sy)); \
584 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2I(0), 1); \
585 OUT_RING (((dy)<<16)|(dx)); \
589 NV30EXAComposite(PixmapPtr pdPix, int srcX , int srcY,
590 int maskX, int maskY,
592 int width, int height)
594 ScrnInfoPtr pScrn = xf86Screens[pdPix->drawable.pScreen->myNum];
595 NVPtr pNv = NVPTR(pScrn);
596 float sX0, sX1, sY0, sY1;
597 float mX0, mX1, mY0, mY1;
601 ErrorF("Composite [%dx%d] (%d,%d)IN(%d,%d)OP(%d,%d)\n",width,height,srcX,srcY,maskX,maskY,dstX,dstY);
603 NV30EXATransformCoord(state->unit[0].transform, srcX, srcY,
604 state->unit[0].width,
605 state->unit[0].height, &sX0, &sY0);
606 NV30EXATransformCoord(state->unit[0].transform,
607 srcX + width, srcY + height,
608 state->unit[0].width,
609 state->unit[0].height, &sX1, &sY1);
611 if (state->have_mask) {
612 NV30EXATransformCoord(state->unit[1].transform, maskX, maskY,
613 state->unit[1].width,
614 state->unit[1].height, &mX0, &mY0);
615 NV30EXATransformCoord(state->unit[1].transform,
616 maskX + width, maskY + height,
617 state->unit[1].width,
618 state->unit[1].height, &mX1, &mY1);
619 CV_OUTm(sX0 , sY0 , mX0, mY0, dstX , dstY);
620 CV_OUTm(sX1 , sY0 , mX1, mY0, dstX + width, dstY);
621 CV_OUTm(sX1 , sY1 , mX1, mY1, dstX + width, dstY + height);
622 CV_OUTm(sX0 , sY1 , mX0, mY1, dstX , dstY + height);
624 CV_OUT(sX0 , sY0 , dstX , dstY);
625 CV_OUT(sX1 , sY0 , dstX + width, dstY);
626 CV_OUT(sX1 , sY1 , dstX + width, dstY + height);
627 CV_OUT(sX0 , sY1 , dstX , dstY + height);
634 NV30EXADoneComposite(PixmapPtr pdPix)
636 ScrnInfoPtr pScrn = xf86Screens[pdPix->drawable.pScreen->myNum];
637 NVPtr pNv = NVPTR(pScrn);
639 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_BEGIN_END, 1);
644 NVAccelInitNV30TCL(ScrnInfoPtr pScrn)
646 NVPtr pNv = NVPTR(pScrn);
647 static int have_object = FALSE;
648 uint32_t class = 0, chipset;
651 NV30EXAHackupA8Shaders(pScrn);
653 #undef NV30_TCL_PRIMITIVE_3D
654 #define NV30_TCL_PRIMITIVE_3D 0x0397
655 #define NV30_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x00000003
656 #define NV35_TCL_PRIMITIVE_3D 0x0497
657 #define NV35_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x000001e0
658 #define NV34_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x00000010
660 chipset = (nvReadMC(pNv, 0) >> 20) & 0xff;
661 if ((chipset & 0xf0) != NV_ARCH_30)
665 if (NV30_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
666 class = NV30_TCL_PRIMITIVE_3D;
667 else if (NV35_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
668 class = NV35_TCL_PRIMITIVE_3D;
669 else if (NV34_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
670 class = NV34_TCL_PRIMITIVE_3D;
672 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
673 "NV30EXA: Unknown chipset NV3%1x\n", chipset);
678 if (!NVDmaCreateContextObject(pNv, Nv3D, class))
683 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY0, 3);
687 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY7, 1);
689 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY3, 2);
692 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY8, 1);
695 for(i = 0x2c8; i <= 0x2fc; i += 4)
697 BEGIN_RING(Nv3D, i, 1);
701 BEGIN_RING(Nv3D, 0x220, 1);
704 BEGIN_RING(Nv3D, 0x03b0, 1);
705 OUT_RING (0x00100000);
706 BEGIN_RING(Nv3D, 0x1454, 1);
708 BEGIN_RING(Nv3D, 0x1d80, 1);
712 BEGIN_RING(Nv3D, 0x1e98, 1);
714 BEGIN_RING(Nv3D, 0x17e0, 3);
717 OUT_RING (0x3f800000);
718 BEGIN_RING(Nv3D, 0x1f80, 16);
719 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
720 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
721 OUT_RING (0x0000ffff);
722 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
723 OUT_RING (0); OUT_RING (0); OUT_RING (0);
725 BEGIN_RING(Nv3D, 0x120, 3);
730 BEGIN_RING(Nv3D, 0x1d88, 1);
731 OUT_RING (0x00001200);
733 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_RC_ENABLE, 1);
736 /* Attempt to setup a known state.. Probably missing a heap of
739 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_STENCIL_FRONT_ENABLE, 1);
741 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_STENCIL_BACK_ENABLE, 1);
743 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_ALPHA_FUNC_ENABLE, 1);
745 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DEPTH_WRITE_ENABLE, 2);
746 OUT_RING (0); /* wr disable */
747 OUT_RING (0); /* test disable */
748 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_COLOR_MASK, 1);
749 OUT_RING (0x01010101); /* TR,TR,TR,TR */
750 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_CULL_FACE_ENABLE, 1);
752 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1);
754 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_COLOR_LOGIC_OP_ENABLE, 2);
756 OUT_RING (0x1503 /*GL_COPY*/);
757 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DITHER_ENABLE, 1);
759 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SHADE_MODEL, 1);
760 OUT_RING (0x1d01 /*GL_SMOOTH*/);
761 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_POLYGON_OFFSET_FACTOR,2);
764 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_POLYGON_MODE_FRONT, 2);
765 OUT_RING (0x1b02 /*GL_FILL*/);
766 OUT_RING (0x1b02 /*GL_FILL*/);
767 /* - Disable texture units
768 * - Set fragprog to MOVR result.color, fragment.color */
771 NV34_TCL_PRIMITIVE_3D_TX_ENABLE(i), 1);
774 /* Polygon stipple */
776 NV34_TCL_PRIMITIVE_3D_POLYGON_STIPPLE_PATTERN(0), 0x20);
778 OUT_RING (0xFFFFFFFF);
780 /* Ok. If you start X with the nvidia driver, kill it, and then
781 * start X with nouveau you will get black rendering instead of
782 * what you'd expect. This fixes the problem, and it seems that
783 * it's not needed between nouveau restarts - which suggests that
784 * the 3D context (wherever it's stored?) survives somehow.
786 //BEGIN_RING(Nv3D, 0x1d60,1);
787 //OUT_RING (0x03008000);
792 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 5);
795 OUT_RING (0x148); /* format */
796 OUT_RING (pitch << 16 | pitch);
798 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_CLIP_HORIZ(0), 2);
799 OUT_RING ((w-1)<<16);
800 OUT_RING ((h-1)<<16);
801 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SCISSOR_HORIZ, 2);
804 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 2);
808 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_SCALE0_X, 8);
818 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_MODELVIEW_MATRIX(0), 16);
836 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_PROJECTION_MATRIX(0), 16);
854 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SCISSOR_HORIZ, 2);
863 #endif /* ENABLE_NV30EXA */