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);
271 //BEGIN_RING(Nv3D, 0x0b00, 1);
272 //OUT_RING(0x00000004);
277 NV30_SetupBlend(ScrnInfoPtr pScrn, nv_pict_op_t *blend,
278 PictFormatShort dest_format, Bool component_alpha)
280 NVPtr pNv = NVPTR(pScrn);
281 uint32_t sblend, dblend;
283 sblend = blend->src_card_op;
284 dblend = blend->dst_card_op;
286 if (blend->dst_alpha) {
287 if (!PICT_FORMAT_A(dest_format)) {
288 if (sblend == BF(DST_ALPHA)) {
290 } else if (sblend == BF(ONE_MINUS_DST_ALPHA)) {
293 } else if (dest_format == PICT_a8) {
294 if (sblend == BF(DST_ALPHA)) {
295 sblend = BF(DST_COLOR);
296 } else if (sblend == BF(ONE_MINUS_DST_ALPHA)) {
297 sblend = BF(ONE_MINUS_DST_COLOR);
302 if (blend->src_alpha && (component_alpha || dest_format == PICT_a8)) {
303 if (dblend == BF(SRC_ALPHA)) {
304 dblend = BF(SRC_COLOR);
305 } else if (dblend == BF(ONE_MINUS_SRC_ALPHA)) {
306 dblend = BF(ONE_MINUS_SRC_COLOR);
310 if (sblend == BF(ONE) && dblend == BF(ZERO)) {
311 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1);
314 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 5);
316 OUT_RING ((sblend << 16) | sblend);
317 OUT_RING ((dblend << 16) | dblend);
318 OUT_RING (0x00000000); /* Blend colour */
319 OUT_RING ((0x8006 << 16) | 0x8006); /* FUNC_ADD, FUNC_ADD */
324 NV30EXATexture(ScrnInfoPtr pScrn, PixmapPtr pPix, PicturePtr pPict, int unit)
326 NVPtr pNv = NVPTR(pScrn);
327 nv_pict_texture_format_t *fmt;
328 uint32_t card_filter, card_repeat;
331 fmt = NV30_GetPictTextureFormat(pPict->format);
335 card_repeat = 3; /* repeatNone */
337 if (pPict->filter == PictFilterBilinear)
343 NV34_TCL_PRIMITIVE_3D_TX_OFFSET(unit), 8);
344 OUT_RING (NVAccelGetPixmapOffset(pPix));
346 OUT_RING ((2 << 4) /* 2D */ |
347 (fmt->card_fmt << 8) |
348 (1 << 16) /* 1 mipmap level */ |
349 /* (log2i(pPix->drawable.width) << 20) |
350 (log2i(pPix->drawable.height) << 24) |*/
353 OUT_RING ((card_repeat << 0) /* S */ |
354 (card_repeat << 8) /* T */ |
355 (card_repeat << 16) /* R */);
356 OUT_RING (0x40000000); /* enable */
357 OUT_RING ((((uint32_t)exaGetPixmapPitch(pPix))<<16) | fmt->card_swz);
359 OUT_RING ((card_filter << 16) /* min */ |
360 (card_filter << 24) /* mag */ |
361 0x3fd6 /* engine lock */);
362 OUT_RING ((pPix->drawable.width << 16) | pPix->drawable.height);
363 OUT_RING (0); /* border ARGB */
365 state->unit[unit].width = (float)pPix->drawable.width;
366 state->unit[unit].height = (float)pPix->drawable.height;
367 state->unit[unit].transform = pPict->transform;
373 NV30_SetupSurface(ScrnInfoPtr pScrn, PixmapPtr pPix, PicturePtr pPict)
375 NVPtr pNv = NVPTR(pScrn);
376 nv_pict_surface_format_t *fmt;
378 fmt = NV30_GetPictSurfaceFormat(pPict->format);
380 ErrorF("AIII no format\n");
384 uint32_t pitch = (uint32_t)exaGetPixmapPitch(pPix);
386 int w = pPict->pDrawable->width;
387 int h = pPict->pDrawable->height;
388 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 5);
391 OUT_RING (fmt->card_fmt); /* format */
392 OUT_RING (pitch << 16 | pitch);
393 OUT_RING (NVAccelGetPixmapOffset(pPix));
394 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_CLIP_HORIZ(0), 2);
395 OUT_RING ((w-1)<<16);
396 OUT_RING ((h-1)<<16);
397 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 2);
405 NV30EXACheckCompositeTexture(PicturePtr pPict)
407 nv_pict_texture_format_t *fmt;
408 int w = pPict->pDrawable->width;
409 int h = pPict->pDrawable->height;
411 if ((w > 4096) || (h>4096))
412 FALLBACK("picture too large, %dx%d\n", w, h);
414 fmt = NV30_GetPictTextureFormat(pPict->format);
416 FALLBACK("picture format 0x%08x not supported\n",
419 if (pPict->filter != PictFilterNearest &&
420 pPict->filter != PictFilterBilinear)
421 FALLBACK("filter 0x%x not supported\n", pPict->filter);
423 if (pPict->repeat && pPict->repeatType != RepeatNone)
424 FALLBACK("repeat 0x%x not supported\n", pPict->repeatType);
430 NV30EXACheckComposite(int op, PicturePtr psPict,
434 nv_pict_surface_format_t *fmt;
437 opr = NV30_GetPictOpRec(op);
439 FALLBACK("unsupported blend op 0x%x\n", op);
441 fmt = NV30_GetPictSurfaceFormat(pdPict->format);
443 FALLBACK("dst picture format 0x%08x not supported\n",
446 if (!NV30EXACheckCompositeTexture(psPict))
447 FALLBACK("src picture\n");
449 if (pmPict->componentAlpha &&
450 PICT_FORMAT_RGB(pmPict->format) &&
451 opr->src_alpha && opr->src_card_op != BF(ZERO))
452 FALLBACK("mask CA + SA\n");
453 if (!NV30EXACheckCompositeTexture(pmPict))
454 FALLBACK("mask picture\n");
460 void NV30_SetVtx(ScrnInfoPtr pScrn, int multitex)
462 NVPtr pNv = NVPTR(pScrn);
464 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ARRAY_FORMAT(0), 16);
488 NV30EXAPrepareComposite(int op, PicturePtr psPict,
495 ScrnInfoPtr pScrn = xf86Screens[psPix->drawable.pScreen->myNum];
496 NVPtr pNv = NVPTR(pScrn);
498 int fpid = NV30EXA_FPID_PASS_COL0;
501 blend = NV30_GetPictOpRec(op);
503 NV30_SetupBlend(pScrn, blend, pdPict->format,
504 (pmPict && pmPict->componentAlpha &&
505 PICT_FORMAT_RGB(pmPict->format)));
507 NV30_SetupSurface(pScrn, pdPix, pdPict);
508 NV30EXATexture(pScrn, psPix, psPict, 0);
511 #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)
512 ErrorF("Preparecomposite src(%dx%d)",psPict->pDrawable->width,psPict->pDrawable->height);
513 printformat((psPict->format));
514 ErrorF(" dst(%dx%d)",pdPict->pDrawable->width,pdPict->pDrawable->height);
515 printformat((pdPict->format));
518 ErrorF(" mask(%dx%d)",pmPict->pDrawable->width,pmPict->pDrawable->height);
519 printformat((pmPict->format));
524 NV30_SetVtx(pScrn,pmPict?1:0);
526 NV30EXATexture(pScrn, pmPix, pmPict, 1);
528 if (pmPict->componentAlpha && PICT_FORMAT_RGB(pmPict->format)) {
529 if (blend->src_alpha)
530 fpid = NV30EXA_FPID_COMPOSITE_MASK_SA_CA;
532 fpid = NV30EXA_FPID_COMPOSITE_MASK_CA;
534 fpid = NV30EXA_FPID_COMPOSITE_MASK;
537 state->have_mask = TRUE;
539 fpid = NV30EXA_FPID_PASS_TEX0;
541 state->have_mask = FALSE;
544 if (pdPict->format == PICT_a8)
545 NV30_LoadFragProg(pScrn, nv40_fp_map_a8[fpid]);
547 NV30_LoadFragProg(pScrn, nv40_fp_map[fpid]);
549 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_BEGIN_END, 1);
550 OUT_RING (8); /* GL_QUADS */
555 #define xFixedToFloat(v) \
556 ((float)xFixedToInt((v)) + ((float)xFixedFrac(v) / 65536.0))
559 NV30EXATransformCoord(PictTransformPtr t, int x, int y, float sx, float sy,
560 float *x_ret, float *y_ret)
565 v.vector[0] = IntToxFixed(x);
566 v.vector[1] = IntToxFixed(y);
567 v.vector[2] = xFixed1;
568 PictureTransformPoint(t, &v);
569 *x_ret = xFixedToFloat(v.vector[0]);
570 *y_ret = xFixedToFloat(v.vector[1]);
577 #define CV_OUTm(sx,sy,mx,my,dx,dy) do { \
578 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2F_X(8), 4); \
579 OUT_RINGf ((sx)); OUT_RINGf ((sy)); \
580 OUT_RINGf ((mx)); OUT_RINGf ((my)); \
581 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2I(0), 1); \
582 OUT_RING (((dy)<<16)|(dx)); \
584 #define CV_OUT(sx,sy,dx,dy) do { \
585 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2F_X(8), 2); \
586 OUT_RINGf ((sx)); OUT_RINGf ((sy)); \
587 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_ATTR_2I(0), 1); \
588 OUT_RING (((dy)<<16)|(dx)); \
592 NV30EXAComposite(PixmapPtr pdPix, int srcX , int srcY,
593 int maskX, int maskY,
595 int width, int height)
597 ScrnInfoPtr pScrn = xf86Screens[pdPix->drawable.pScreen->myNum];
598 NVPtr pNv = NVPTR(pScrn);
599 float sX0, sX1, sY0, sY1;
600 float mX0, mX1, mY0, mY1;
604 ErrorF("Composite [%dx%d] (%d,%d)IN(%d,%d)OP(%d,%d)\n",width,height,srcX,srcY,maskX,maskY,dstX,dstY);
606 NV30EXATransformCoord(state->unit[0].transform, srcX, srcY,
607 state->unit[0].width,
608 state->unit[0].height, &sX0, &sY0);
609 NV30EXATransformCoord(state->unit[0].transform,
610 srcX + width, srcY + height,
611 state->unit[0].width,
612 state->unit[0].height, &sX1, &sY1);
614 if (state->have_mask) {
615 NV30EXATransformCoord(state->unit[1].transform, maskX, maskY,
616 state->unit[1].width,
617 state->unit[1].height, &mX0, &mY0);
618 NV30EXATransformCoord(state->unit[1].transform,
619 maskX + width, maskY + height,
620 state->unit[1].width,
621 state->unit[1].height, &mX1, &mY1);
622 CV_OUTm(sX0 , sY0 , mX0, mY0, dstX , dstY);
623 CV_OUTm(sX1 , sY0 , mX1, mY0, dstX + width, dstY);
624 CV_OUTm(sX1 , sY1 , mX1, mY1, dstX + width, dstY + height);
625 CV_OUTm(sX0 , sY1 , mX0, mY1, dstX , dstY + height);
627 CV_OUT(sX0 , sY0 , dstX , dstY);
628 CV_OUT(sX1 , sY0 , dstX + width, dstY);
629 CV_OUT(sX1 , sY1 , dstX + width, dstY + height);
630 CV_OUT(sX0 , sY1 , dstX , dstY + height);
637 NV30EXADoneComposite(PixmapPtr pdPix)
639 ScrnInfoPtr pScrn = xf86Screens[pdPix->drawable.pScreen->myNum];
640 NVPtr pNv = NVPTR(pScrn);
642 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VERTEX_BEGIN_END, 1);
647 NVAccelInitNV30TCL(ScrnInfoPtr pScrn)
649 NVPtr pNv = NVPTR(pScrn);
650 static int have_object = FALSE;
651 uint32_t class = 0, chipset;
654 NV30EXAHackupA8Shaders(pScrn);
656 #undef NV30_TCL_PRIMITIVE_3D
657 #define NV30_TCL_PRIMITIVE_3D 0x0397
658 #define NV30_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x00000003
659 #define NV35_TCL_PRIMITIVE_3D 0x0497
660 #define NV35_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x000001e0
661 #define NV34_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK 0x00000010
663 chipset = (nvReadMC(pNv, 0) >> 20) & 0xff;
664 if ((chipset & 0xf0) != NV_ARCH_30)
668 if (NV30_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
669 class = NV30_TCL_PRIMITIVE_3D;
670 else if (NV35_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
671 class = NV35_TCL_PRIMITIVE_3D;
672 else if (NV34_TCL_PRIMITIVE_3D_CHIPSET_3X_MASK & (1<<chipset))
673 class = NV34_TCL_PRIMITIVE_3D;
675 xf86DrvMsg(pScrn->scrnIndex, X_ERROR,
676 "NV30EXA: Unknown chipset NV3%1x\n", chipset);
681 if (!NVDmaCreateContextObject(pNv, Nv3D, class))
686 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY0, 3);
690 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY7, 1);
692 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY3, 2);
695 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DMA_IN_MEMORY8, 1);
698 for(i = 0x2c8; i <= 0x2fc; i += 4)
700 BEGIN_RING(Nv3D, i, 1);
704 BEGIN_RING(Nv3D, 0x220, 1);
707 BEGIN_RING(Nv3D, 0x03b0, 1);
708 OUT_RING (0x00100000);
709 BEGIN_RING(Nv3D, 0x1454, 1);
711 BEGIN_RING(Nv3D, 0x1d80, 1);
715 BEGIN_RING(Nv3D, 0x1e98, 1);
717 BEGIN_RING(Nv3D, 0x17e0, 3);
720 OUT_RING (0x3f800000);
721 BEGIN_RING(Nv3D, 0x1f80, 16);
722 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
723 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
724 OUT_RING (0x0000ffff);
725 OUT_RING (0); OUT_RING (0); OUT_RING (0); OUT_RING (0);
726 OUT_RING (0); OUT_RING (0); OUT_RING (0);
728 BEGIN_RING(Nv3D, 0x120, 3);
733 BEGIN_RING(Nv3D, 0x1d88, 1);
734 OUT_RING (0x00001200);
736 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_RC_ENABLE, 1);
739 /* Attempt to setup a known state.. Probably missing a heap of
742 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_STENCIL_FRONT_ENABLE, 1);
744 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_STENCIL_BACK_ENABLE, 1);
746 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_ALPHA_FUNC_ENABLE, 1);
748 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DEPTH_WRITE_ENABLE, 2);
749 OUT_RING (0); /* wr disable */
750 OUT_RING (0); /* test disable */
751 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_COLOR_MASK, 1);
752 OUT_RING (0x01010101); /* TR,TR,TR,TR */
753 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_CULL_FACE_ENABLE, 1);
755 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_BLEND_FUNC_ENABLE, 1);
757 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_COLOR_LOGIC_OP_ENABLE, 2);
759 OUT_RING (0x1503 /*GL_COPY*/);
760 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_DITHER_ENABLE, 1);
762 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SHADE_MODEL, 1);
763 OUT_RING (0x1d01 /*GL_SMOOTH*/);
764 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_POLYGON_OFFSET_FACTOR,2);
767 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_POLYGON_MODE_FRONT, 2);
768 OUT_RING (0x1b02 /*GL_FILL*/);
769 OUT_RING (0x1b02 /*GL_FILL*/);
770 /* - Disable texture units
771 * - Set fragprog to MOVR result.color, fragment.color */
774 NV34_TCL_PRIMITIVE_3D_TX_ENABLE(i), 1);
777 /* Polygon stipple */
779 NV34_TCL_PRIMITIVE_3D_POLYGON_STIPPLE_PATTERN(0), 0x20);
781 OUT_RING (0xFFFFFFFF);
783 /* Ok. If you start X with the nvidia driver, kill it, and then
784 * start X with nouveau you will get black rendering instead of
785 * what you'd expect. This fixes the problem, and it seems that
786 * it's not needed between nouveau restarts - which suggests that
787 * the 3D context (wherever it's stored?) survives somehow.
789 //BEGIN_RING(Nv3D, 0x1d60,1);
790 //OUT_RING (0x03008000);
795 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 5);
798 OUT_RING (0x148); /* format */
799 OUT_RING (pitch << 16 | pitch);
801 BEGIN_RING(Nv3D, 0x0a00, 2);
802 OUT_RING ((w<<16) | 0);
803 OUT_RING ((h<<16) | 0);
804 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_CLIP_HORIZ(0), 2);
805 OUT_RING ((w-1)<<16);
806 OUT_RING ((h-1)<<16);
807 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SCISSOR_HORIZ, 2);
810 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_HORIZ, 2);
814 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_VIEWPORT_SCALE0_X, 8);
824 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_MODELVIEW_MATRIX(0), 16);
842 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_PROJECTION_MATRIX(0), 16);
860 BEGIN_RING(Nv3D, NV34_TCL_PRIMITIVE_3D_SCISSOR_HORIZ, 2);
869 #endif /* ENABLE_NV30EXA */