nv04_surface.c revision f9995b30756140724f41daf963fa06167912be7f
1/* 2 * Copyright (C) 2007-2010 The Nouveau Project. 3 * All Rights Reserved. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the 14 * next paragraph) shall be included in all copies or substantial 15 * portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 * 25 */ 26 27#include "nouveau_driver.h" 28#include "nouveau_class.h" 29#include "nouveau_context.h" 30#include "nouveau_util.h" 31#include "nv04_driver.h" 32 33static inline int 34swzsurf_format(gl_format format) 35{ 36 switch (format) { 37 case MESA_FORMAT_A8: 38 case MESA_FORMAT_L8: 39 case MESA_FORMAT_I8: 40 case MESA_FORMAT_RGB332: 41 case MESA_FORMAT_CI8: 42 return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_Y8; 43 44 case MESA_FORMAT_RGB565: 45 case MESA_FORMAT_RGB565_REV: 46 case MESA_FORMAT_ARGB4444: 47 case MESA_FORMAT_ARGB4444_REV: 48 case MESA_FORMAT_ARGB1555: 49 case MESA_FORMAT_RGBA5551: 50 case MESA_FORMAT_ARGB1555_REV: 51 case MESA_FORMAT_AL88: 52 case MESA_FORMAT_AL88_REV: 53 case MESA_FORMAT_YCBCR: 54 case MESA_FORMAT_YCBCR_REV: 55 case MESA_FORMAT_Z16: 56 return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_R5G6B5; 57 58 case MESA_FORMAT_RGBA8888: 59 case MESA_FORMAT_RGBA8888_REV: 60 case MESA_FORMAT_XRGB8888: 61 case MESA_FORMAT_ARGB8888: 62 case MESA_FORMAT_ARGB8888_REV: 63 case MESA_FORMAT_S8_Z24: 64 case MESA_FORMAT_Z24_S8: 65 case MESA_FORMAT_Z32: 66 return NV04_SWIZZLED_SURFACE_FORMAT_COLOR_A8R8G8B8; 67 68 default: 69 assert(0); 70 } 71} 72 73static inline int 74surf2d_format(gl_format format) 75{ 76 switch (format) { 77 case MESA_FORMAT_A8: 78 case MESA_FORMAT_L8: 79 case MESA_FORMAT_I8: 80 case MESA_FORMAT_RGB332: 81 case MESA_FORMAT_CI8: 82 return NV04_CONTEXT_SURFACES_2D_FORMAT_Y8; 83 84 case MESA_FORMAT_RGB565: 85 case MESA_FORMAT_RGB565_REV: 86 case MESA_FORMAT_ARGB4444: 87 case MESA_FORMAT_ARGB4444_REV: 88 case MESA_FORMAT_ARGB1555: 89 case MESA_FORMAT_RGBA5551: 90 case MESA_FORMAT_ARGB1555_REV: 91 case MESA_FORMAT_AL88: 92 case MESA_FORMAT_AL88_REV: 93 case MESA_FORMAT_YCBCR: 94 case MESA_FORMAT_YCBCR_REV: 95 case MESA_FORMAT_Z16: 96 return NV04_CONTEXT_SURFACES_2D_FORMAT_R5G6B5; 97 98 case MESA_FORMAT_RGBA8888: 99 case MESA_FORMAT_RGBA8888_REV: 100 case MESA_FORMAT_XRGB8888: 101 case MESA_FORMAT_ARGB8888: 102 case MESA_FORMAT_ARGB8888_REV: 103 case MESA_FORMAT_S8_Z24: 104 case MESA_FORMAT_Z24_S8: 105 case MESA_FORMAT_Z32: 106 return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32; 107 108 default: 109 assert(0); 110 } 111} 112 113static inline int 114rect_format(gl_format format) 115{ 116 switch (format) { 117 case MESA_FORMAT_A8: 118 case MESA_FORMAT_L8: 119 case MESA_FORMAT_I8: 120 case MESA_FORMAT_RGB332: 121 case MESA_FORMAT_CI8: 122 return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; 123 124 case MESA_FORMAT_RGB565: 125 case MESA_FORMAT_RGB565_REV: 126 case MESA_FORMAT_ARGB4444: 127 case MESA_FORMAT_ARGB4444_REV: 128 case MESA_FORMAT_ARGB1555: 129 case MESA_FORMAT_RGBA5551: 130 case MESA_FORMAT_ARGB1555_REV: 131 case MESA_FORMAT_AL88: 132 case MESA_FORMAT_AL88_REV: 133 case MESA_FORMAT_YCBCR: 134 case MESA_FORMAT_YCBCR_REV: 135 case MESA_FORMAT_Z16: 136 return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5; 137 138 case MESA_FORMAT_RGBA8888: 139 case MESA_FORMAT_RGBA8888_REV: 140 case MESA_FORMAT_XRGB8888: 141 case MESA_FORMAT_ARGB8888: 142 case MESA_FORMAT_ARGB8888_REV: 143 case MESA_FORMAT_S8_Z24: 144 case MESA_FORMAT_Z24_S8: 145 case MESA_FORMAT_Z32: 146 return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8; 147 148 default: 149 assert(0); 150 } 151} 152 153static inline int 154sifm_format(gl_format format) 155{ 156 switch (format) { 157 case MESA_FORMAT_A8: 158 case MESA_FORMAT_L8: 159 case MESA_FORMAT_I8: 160 case MESA_FORMAT_RGB332: 161 case MESA_FORMAT_CI8: 162 return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_AY8; 163 164 case MESA_FORMAT_RGB565: 165 case MESA_FORMAT_RGB565_REV: 166 case MESA_FORMAT_ARGB4444: 167 case MESA_FORMAT_ARGB4444_REV: 168 case MESA_FORMAT_ARGB1555: 169 case MESA_FORMAT_RGBA5551: 170 case MESA_FORMAT_ARGB1555_REV: 171 case MESA_FORMAT_AL88: 172 case MESA_FORMAT_AL88_REV: 173 case MESA_FORMAT_YCBCR: 174 case MESA_FORMAT_YCBCR_REV: 175 case MESA_FORMAT_Z16: 176 return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_R5G6B5; 177 178 case MESA_FORMAT_RGBA8888: 179 case MESA_FORMAT_RGBA8888_REV: 180 case MESA_FORMAT_XRGB8888: 181 case MESA_FORMAT_ARGB8888: 182 case MESA_FORMAT_ARGB8888_REV: 183 case MESA_FORMAT_S8_Z24: 184 case MESA_FORMAT_Z24_S8: 185 case MESA_FORMAT_Z32: 186 return NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT_A8R8G8B8; 187 188 default: 189 assert(0); 190 } 191} 192 193static void 194nv04_surface_copy_swizzle(struct gl_context *ctx, 195 struct nouveau_surface *dst, 196 struct nouveau_surface *src, 197 int dx, int dy, int sx, int sy, 198 int w, int h) 199{ 200 struct nouveau_channel *chan = context_chan(ctx); 201 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; 202 struct nouveau_grobj *swzsurf = hw->swzsurf; 203 struct nouveau_grobj *sifm = hw->sifm; 204 struct nouveau_bo_context *bctx = context_bctx(ctx, SURFACE); 205 const unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART; 206 /* Max width & height may not be the same on all HW, but must be POT */ 207 const unsigned max_w = 1024; 208 const unsigned max_h = 1024; 209 unsigned sub_w = w > max_w ? max_w : w; 210 unsigned sub_h = h > max_h ? max_h : h; 211 unsigned x, y; 212 213 /* Swizzled surfaces must be POT */ 214 assert(_mesa_is_pow_two(dst->width) && 215 _mesa_is_pow_two(dst->height)); 216 217 nouveau_bo_marko(bctx, sifm, NV03_SCALED_IMAGE_FROM_MEMORY_DMA_IMAGE, 218 src->bo, bo_flags | NOUVEAU_BO_RD); 219 nouveau_bo_marko(bctx, swzsurf, NV04_SWIZZLED_SURFACE_DMA_IMAGE, 220 dst->bo, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); 221 nouveau_bo_markl(bctx, swzsurf, NV04_SWIZZLED_SURFACE_OFFSET, 222 dst->bo, dst->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR); 223 224 BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_FORMAT, 1); 225 OUT_RING (chan, swzsurf_format(dst->format) | 226 log2i(dst->width) << 16 | 227 log2i(dst->height) << 24); 228 229 BEGIN_RING(chan, sifm, NV04_SCALED_IMAGE_FROM_MEMORY_SURFACE, 1); 230 OUT_RING (chan, swzsurf->handle); 231 232 for (y = 0; y < h; y += sub_h) { 233 sub_h = MIN2(sub_h, h - y); 234 235 for (x = 0; x < w; x += sub_w) { 236 sub_w = MIN2(sub_w, w - x); 237 238 MARK_RING(chan, 15, 1); 239 240 BEGIN_RING(chan, sifm, 241 NV03_SCALED_IMAGE_FROM_MEMORY_COLOR_FORMAT, 8); 242 OUT_RING(chan, sifm_format(src->format)); 243 OUT_RING(chan, NV03_SCALED_IMAGE_FROM_MEMORY_OPERATION_SRCCOPY); 244 OUT_RING(chan, (y + dy) << 16 | (x + dx)); 245 OUT_RING(chan, sub_h << 16 | sub_w); 246 OUT_RING(chan, (y + dy) << 16 | (x + dx)); 247 OUT_RING(chan, sub_h << 16 | sub_w); 248 OUT_RING(chan, 1 << 20); 249 OUT_RING(chan, 1 << 20); 250 251 BEGIN_RING(chan, sifm, 252 NV03_SCALED_IMAGE_FROM_MEMORY_SIZE, 4); 253 OUT_RING(chan, align(sub_h, 2) << 16 | align(sub_w, 2)); 254 OUT_RING(chan, src->pitch | 255 NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_ORIGIN_CENTER | 256 NV03_SCALED_IMAGE_FROM_MEMORY_FORMAT_FILTER_POINT_SAMPLE); 257 OUT_RELOCl(chan, src->bo, src->offset + 258 (y + sy) * src->pitch + 259 (x + sx) * src->cpp, 260 bo_flags | NOUVEAU_BO_RD); 261 OUT_RING(chan, 0); 262 } 263 } 264 265 nouveau_bo_context_reset(bctx); 266 267 if (context_chipset(ctx) < 0x10) 268 FIRE_RING(chan); 269} 270 271static void 272nv04_surface_copy_m2mf(struct gl_context *ctx, 273 struct nouveau_surface *dst, 274 struct nouveau_surface *src, 275 int dx, int dy, int sx, int sy, 276 int w, int h) 277{ 278 struct nouveau_channel *chan = context_chan(ctx); 279 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; 280 struct nouveau_grobj *m2mf = hw->m2mf; 281 struct nouveau_bo_context *bctx = context_bctx(ctx, SURFACE); 282 const unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART; 283 unsigned dst_offset = dst->offset + dy * dst->pitch + dx * dst->cpp; 284 unsigned src_offset = src->offset + sy * src->pitch + sx * src->cpp; 285 286 nouveau_bo_marko(bctx, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_IN, 287 src->bo, bo_flags | NOUVEAU_BO_RD); 288 nouveau_bo_marko(bctx, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_BUFFER_OUT, 289 dst->bo, bo_flags | NOUVEAU_BO_WR); 290 291 while (h) { 292 int count = (h > 2047) ? 2047 : h; 293 294 MARK_RING(chan, 9, 2); 295 296 BEGIN_RING(chan, m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); 297 OUT_RELOCl(chan, src->bo, src_offset, 298 bo_flags | NOUVEAU_BO_RD); 299 OUT_RELOCl(chan, dst->bo, dst_offset, 300 bo_flags | NOUVEAU_BO_WR); 301 OUT_RING (chan, src->pitch); 302 OUT_RING (chan, dst->pitch); 303 OUT_RING (chan, w * src->cpp); 304 OUT_RING (chan, count); 305 OUT_RING (chan, 0x0101); 306 OUT_RING (chan, 0); 307 308 h -= count; 309 src_offset += src->pitch * count; 310 dst_offset += dst->pitch * count; 311 } 312 313 nouveau_bo_context_reset(bctx); 314 315 if (context_chipset(ctx) < 0x10) 316 FIRE_RING(chan); 317} 318 319typedef unsigned (*get_offset_t)(struct nouveau_surface *s, 320 unsigned x, unsigned y); 321 322static unsigned 323get_linear_offset(struct nouveau_surface *s, unsigned x, unsigned y) 324{ 325 return x * s->cpp + y * s->pitch; 326} 327 328static unsigned 329get_swizzled_offset(struct nouveau_surface *s, unsigned x, unsigned y) 330{ 331 unsigned k = log2i(MIN2(s->width, s->height)); 332 333 unsigned u = (x & 0x001) << 0 | 334 (x & 0x002) << 1 | 335 (x & 0x004) << 2 | 336 (x & 0x008) << 3 | 337 (x & 0x010) << 4 | 338 (x & 0x020) << 5 | 339 (x & 0x040) << 6 | 340 (x & 0x080) << 7 | 341 (x & 0x100) << 8 | 342 (x & 0x200) << 9 | 343 (x & 0x400) << 10 | 344 (x & 0x800) << 11; 345 346 unsigned v = (y & 0x001) << 1 | 347 (y & 0x002) << 2 | 348 (y & 0x004) << 3 | 349 (y & 0x008) << 4 | 350 (y & 0x010) << 5 | 351 (y & 0x020) << 6 | 352 (y & 0x040) << 7 | 353 (y & 0x080) << 8 | 354 (y & 0x100) << 9 | 355 (y & 0x200) << 10 | 356 (y & 0x400) << 11 | 357 (y & 0x800) << 12; 358 359 return s->cpp * (((u | v) & ~(~0 << 2*k)) | 360 (x & (~0 << k)) << k | 361 (y & (~0 << k)) << k); 362} 363 364static void 365nv04_surface_copy_cpu(struct gl_context *ctx, 366 struct nouveau_surface *dst, 367 struct nouveau_surface *src, 368 int dx, int dy, int sx, int sy, 369 int w, int h) 370{ 371 int x, y; 372 get_offset_t get_dst = (dst->layout == SWIZZLED ? 373 get_swizzled_offset : get_linear_offset); 374 get_offset_t get_src = (src->layout == SWIZZLED ? 375 get_swizzled_offset : get_linear_offset); 376 void *dp, *sp; 377 378 nouveau_bo_map(dst->bo, NOUVEAU_BO_WR); 379 nouveau_bo_map(src->bo, NOUVEAU_BO_RD); 380 381 dp = dst->bo->map + dst->offset; 382 sp = src->bo->map + src->offset; 383 384 for (y = 0; y < h; y++) { 385 for (x = 0; x < w; x++) { 386 memcpy(dp + get_dst(dst, dx + x, dy + y), 387 sp + get_src(src, sx + x, sy + y), dst->cpp); 388 } 389 } 390 391 nouveau_bo_unmap(src->bo); 392 nouveau_bo_unmap(dst->bo); 393} 394 395void 396nv04_surface_copy(struct gl_context *ctx, 397 struct nouveau_surface *dst, 398 struct nouveau_surface *src, 399 int dx, int dy, int sx, int sy, 400 int w, int h) 401{ 402 /* Linear texture copy. */ 403 if ((src->layout == LINEAR && dst->layout == LINEAR) || 404 dst->width <= 2 || dst->height <= 1) { 405 nv04_surface_copy_m2mf(ctx, dst, src, dx, dy, sx, sy, w, h); 406 return; 407 } 408 409 /* Swizzle using sifm+swzsurf. */ 410 if (src->layout == LINEAR && dst->layout == SWIZZLED && 411 dst->cpp != 1 && !(dst->offset & 63)) { 412 nv04_surface_copy_swizzle(ctx, dst, src, dx, dy, sx, sy, w, h); 413 return; 414 } 415 416 /* Fallback to CPU copy. */ 417 nv04_surface_copy_cpu(ctx, dst, src, dx, dy, sx, sy, w, h); 418} 419 420void 421nv04_surface_fill(struct gl_context *ctx, 422 struct nouveau_surface *dst, 423 unsigned mask, unsigned value, 424 int dx, int dy, int w, int h) 425{ 426 struct nouveau_channel *chan = context_chan(ctx); 427 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; 428 struct nouveau_grobj *surf2d = hw->surf2d; 429 struct nouveau_grobj *patt = hw->patt; 430 struct nouveau_grobj *rect = hw->rect; 431 unsigned bo_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART; 432 433 MARK_RING (chan, 19, 4); 434 435 BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_DMA_IMAGE_SOURCE, 2); 436 OUT_RELOCo(chan, dst->bo, bo_flags | NOUVEAU_BO_WR); 437 OUT_RELOCo(chan, dst->bo, bo_flags | NOUVEAU_BO_WR); 438 BEGIN_RING(chan, surf2d, NV04_CONTEXT_SURFACES_2D_FORMAT, 4); 439 OUT_RING (chan, surf2d_format(dst->format)); 440 OUT_RING (chan, (dst->pitch << 16) | dst->pitch); 441 OUT_RELOCl(chan, dst->bo, dst->offset, bo_flags | NOUVEAU_BO_WR); 442 OUT_RELOCl(chan, dst->bo, dst->offset, bo_flags | NOUVEAU_BO_WR); 443 444 BEGIN_RING(chan, patt, NV04_IMAGE_PATTERN_COLOR_FORMAT, 1); 445 OUT_RING (chan, rect_format(dst->format)); 446 BEGIN_RING(chan, patt, NV04_IMAGE_PATTERN_MONOCHROME_COLOR1, 1); 447 OUT_RING (chan, mask | ~0ll << (8 * dst->cpp)); 448 449 BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT, 1); 450 OUT_RING (chan, rect_format(dst->format)); 451 BEGIN_RING(chan, rect, NV04_GDI_RECTANGLE_TEXT_COLOR1_A, 1); 452 OUT_RING (chan, value); 453 BEGIN_RING(chan, rect, 454 NV04_GDI_RECTANGLE_TEXT_UNCLIPPED_RECTANGLE_POINT(0), 2); 455 OUT_RING (chan, (dx << 16) | dy); 456 OUT_RING (chan, ( w << 16) | h); 457 458 if (context_chipset(ctx) < 0x10) 459 FIRE_RING(chan); 460} 461 462void 463nv04_surface_takedown(struct gl_context *ctx) 464{ 465 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; 466 467 nouveau_grobj_free(&hw->swzsurf); 468 nouveau_grobj_free(&hw->sifm); 469 nouveau_grobj_free(&hw->rect); 470 nouveau_grobj_free(&hw->rop); 471 nouveau_grobj_free(&hw->patt); 472 nouveau_grobj_free(&hw->surf2d); 473 nouveau_grobj_free(&hw->m2mf); 474 nouveau_notifier_free(&hw->ntfy); 475} 476 477GLboolean 478nv04_surface_init(struct gl_context *ctx) 479{ 480 struct nouveau_channel *chan = context_chan(ctx); 481 struct nouveau_hw_state *hw = &to_nouveau_context(ctx)->hw; 482 unsigned handle = 0x88000000, class; 483 int ret; 484 485 /* Notifier object. */ 486 ret = nouveau_notifier_alloc(chan, handle++, 1, &hw->ntfy); 487 if (ret) 488 goto fail; 489 490 /* Memory to memory format. */ 491 ret = nouveau_grobj_alloc(chan, handle++, NV04_MEMORY_TO_MEMORY_FORMAT, 492 &hw->m2mf); 493 if (ret) 494 goto fail; 495 496 BEGIN_RING(chan, hw->m2mf, NV04_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY, 1); 497 OUT_RING (chan, hw->ntfy->handle); 498 499 /* Context surfaces 2D. */ 500 if (context_chipset(ctx) < 0x10) 501 class = NV04_CONTEXT_SURFACES_2D; 502 else 503 class = NV10_CONTEXT_SURFACES_2D; 504 505 ret = nouveau_grobj_alloc(chan, handle++, class, &hw->surf2d); 506 if (ret) 507 goto fail; 508 509 /* Raster op. */ 510 ret = nouveau_grobj_alloc(chan, handle++, NV03_CONTEXT_ROP, &hw->rop); 511 if (ret) 512 goto fail; 513 514 BEGIN_RING(chan, hw->rop, NV03_CONTEXT_ROP_DMA_NOTIFY, 1); 515 OUT_RING (chan, hw->ntfy->handle); 516 517 BEGIN_RING(chan, hw->rop, NV03_CONTEXT_ROP_ROP, 1); 518 OUT_RING (chan, 0xca); /* DPSDxax in the GDI speech. */ 519 520 /* Image pattern. */ 521 ret = nouveau_grobj_alloc(chan, handle++, NV04_IMAGE_PATTERN, 522 &hw->patt); 523 if (ret) 524 goto fail; 525 526 BEGIN_RING(chan, hw->patt, NV04_IMAGE_PATTERN_DMA_NOTIFY, 1); 527 OUT_RING (chan, hw->ntfy->handle); 528 529 BEGIN_RING(chan, hw->patt, NV04_IMAGE_PATTERN_MONOCHROME_FORMAT, 3); 530 OUT_RING (chan, NV04_IMAGE_PATTERN_MONOCHROME_FORMAT_LE); 531 OUT_RING (chan, NV04_IMAGE_PATTERN_MONOCHROME_SHAPE_8X8); 532 OUT_RING (chan, NV04_IMAGE_PATTERN_PATTERN_SELECT_MONO); 533 534 BEGIN_RING(chan, hw->patt, NV04_IMAGE_PATTERN_MONOCHROME_COLOR0, 4); 535 OUT_RING (chan, 0); 536 OUT_RING (chan, 0); 537 OUT_RING (chan, ~0); 538 OUT_RING (chan, ~0); 539 540 /* GDI rectangle text. */ 541 ret = nouveau_grobj_alloc(chan, handle++, NV04_GDI_RECTANGLE_TEXT, 542 &hw->rect); 543 if (ret) 544 goto fail; 545 546 BEGIN_RING(chan, hw->rect, NV04_GDI_RECTANGLE_TEXT_DMA_NOTIFY, 1); 547 OUT_RING (chan, hw->ntfy->handle); 548 BEGIN_RING(chan, hw->rect, NV04_GDI_RECTANGLE_TEXT_SURFACE, 1); 549 OUT_RING (chan, hw->surf2d->handle); 550 BEGIN_RING(chan, hw->rect, NV04_GDI_RECTANGLE_TEXT_ROP, 1); 551 OUT_RING (chan, hw->rop->handle); 552 BEGIN_RING(chan, hw->rect, NV04_GDI_RECTANGLE_TEXT_PATTERN, 1); 553 OUT_RING (chan, hw->patt->handle); 554 555 BEGIN_RING(chan, hw->rect, NV04_GDI_RECTANGLE_TEXT_OPERATION, 1); 556 OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_OPERATION_ROP_AND); 557 BEGIN_RING(chan, hw->rect, 558 NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT, 1); 559 OUT_RING (chan, NV04_GDI_RECTANGLE_TEXT_MONOCHROME_FORMAT_LE); 560 561 /* Swizzled surface. */ 562 if (context_chipset(ctx) < 0x20) 563 class = NV04_SWIZZLED_SURFACE; 564 else 565 class = NV20_SWIZZLED_SURFACE; 566 567 ret = nouveau_grobj_alloc(chan, handle++, class, &hw->swzsurf); 568 if (ret) 569 goto fail; 570 571 /* Scaled image from memory. */ 572 if (context_chipset(ctx) < 0x10) 573 class = NV04_SCALED_IMAGE_FROM_MEMORY; 574 else 575 class = NV10_SCALED_IMAGE_FROM_MEMORY; 576 577 ret = nouveau_grobj_alloc(chan, handle++, class, &hw->sifm); 578 if (ret) 579 goto fail; 580 581 if (context_chipset(ctx) >= 0x10) { 582 BEGIN_RING(chan, hw->sifm, 583 NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 1); 584 OUT_RING(chan, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE); 585 } 586 587 return GL_TRUE; 588 589fail: 590 nv04_surface_takedown(ctx); 591 return GL_FALSE; 592} 593