Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / mesa / drivers / dri / intel / intel_span.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #include "main/glheader.h"
29 #include "main/macros.h"
30 #include "main/mtypes.h"
31 #include "main/colormac.h"
32
33 #include "intel_buffers.h"
34 #include "intel_fbo.h"
35 #include "intel_screen.h"
36 #include "intel_span.h"
37 #include "intel_regions.h"
38 #include "intel_tex.h"
39
40 #include "swrast/swrast.h"
41
42 static void
43 intel_set_span_functions(struct intel_context *intel,
44 struct gl_renderbuffer *rb);
45
46 #define SPAN_CACHE_SIZE 4096
47
48 static void
49 get_span_cache(struct intel_renderbuffer *irb, uint32_t offset)
50 {
51 if (irb->span_cache == NULL) {
52 irb->span_cache = _mesa_malloc(SPAN_CACHE_SIZE);
53 irb->span_cache_offset = -1;
54 }
55
56 if ((offset & ~(SPAN_CACHE_SIZE - 1)) != irb->span_cache_offset) {
57 irb->span_cache_offset = offset & ~(SPAN_CACHE_SIZE - 1);
58 dri_bo_get_subdata(irb->region->buffer, irb->span_cache_offset,
59 SPAN_CACHE_SIZE, irb->span_cache);
60 }
61 }
62
63 static void
64 clear_span_cache(struct intel_renderbuffer *irb)
65 {
66 irb->span_cache_offset = -1;
67 }
68
69 static uint32_t
70 pread_32(struct intel_renderbuffer *irb, uint32_t offset)
71 {
72 get_span_cache(irb, offset);
73
74 return *(uint32_t *)(irb->span_cache + (offset & (SPAN_CACHE_SIZE - 1)));
75 }
76
77 static uint32_t
78 pread_xrgb8888(struct intel_renderbuffer *irb, uint32_t offset)
79 {
80 get_span_cache(irb, offset);
81
82 return *(uint32_t *)(irb->span_cache + (offset & (SPAN_CACHE_SIZE - 1))) |
83 0xff000000;
84 }
85
86 static uint16_t
87 pread_16(struct intel_renderbuffer *irb, uint32_t offset)
88 {
89 get_span_cache(irb, offset);
90
91 return *(uint16_t *)(irb->span_cache + (offset & (SPAN_CACHE_SIZE - 1)));
92 }
93
94 static uint8_t
95 pread_8(struct intel_renderbuffer *irb, uint32_t offset)
96 {
97 get_span_cache(irb, offset);
98
99 return *(uint8_t *)(irb->span_cache + (offset & (SPAN_CACHE_SIZE - 1)));
100 }
101
102 static void
103 pwrite_32(struct intel_renderbuffer *irb, uint32_t offset, uint32_t val)
104 {
105 clear_span_cache(irb);
106
107 dri_bo_subdata(irb->region->buffer, offset, 4, &val);
108 }
109
110 static void
111 pwrite_xrgb8888(struct intel_renderbuffer *irb, uint32_t offset, uint32_t val)
112 {
113 clear_span_cache(irb);
114
115 dri_bo_subdata(irb->region->buffer, offset, 3, &val);
116 }
117
118 static void
119 pwrite_16(struct intel_renderbuffer *irb, uint32_t offset, uint16_t val)
120 {
121 clear_span_cache(irb);
122
123 dri_bo_subdata(irb->region->buffer, offset, 2, &val);
124 }
125
126 static void
127 pwrite_8(struct intel_renderbuffer *irb, uint32_t offset, uint8_t val)
128 {
129 clear_span_cache(irb);
130
131 dri_bo_subdata(irb->region->buffer, offset, 1, &val);
132 }
133
134 static uint32_t no_tile_swizzle(struct intel_renderbuffer *irb,
135 int x, int y)
136 {
137 return (y * irb->region->pitch + x) * irb->region->cpp;
138 }
139
140 /*
141 * Deal with tiled surfaces
142 */
143
144 static uint32_t x_tile_swizzle(struct intel_renderbuffer *irb,
145 int x, int y)
146 {
147 int tile_stride;
148 int xbyte;
149 int x_tile_off, y_tile_off;
150 int x_tile_number, y_tile_number;
151 int tile_off, tile_base;
152
153 x += irb->region->draw_x;
154 y += irb->region->draw_y;
155
156 tile_stride = (irb->region->pitch * irb->region->cpp) << 3;
157
158 xbyte = x * irb->region->cpp;
159
160 x_tile_off = xbyte & 0x1ff;
161 y_tile_off = y & 7;
162
163 x_tile_number = xbyte >> 9;
164 y_tile_number = y >> 3;
165
166 tile_off = (y_tile_off << 9) + x_tile_off;
167
168 switch (irb->region->bit_6_swizzle) {
169 case I915_BIT_6_SWIZZLE_NONE:
170 break;
171 case I915_BIT_6_SWIZZLE_9:
172 tile_off ^= ((tile_off >> 3) & 64);
173 break;
174 case I915_BIT_6_SWIZZLE_9_10:
175 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 4) & 64);
176 break;
177 case I915_BIT_6_SWIZZLE_9_11:
178 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 5) & 64);
179 break;
180 case I915_BIT_6_SWIZZLE_9_10_11:
181 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 4) & 64) ^
182 ((tile_off >> 5) & 64);
183 break;
184 default:
185 fprintf(stderr, "Unknown tile swizzling mode %d\n",
186 irb->region->bit_6_swizzle);
187 exit(1);
188 }
189
190 tile_base = (x_tile_number << 12) + y_tile_number * tile_stride;
191
192 #if 0
193 printf("(%d,%d) -> %d + %d = %d (pitch = %d, tstride = %d)\n",
194 x, y, tile_off, tile_base,
195 tile_off + tile_base,
196 irb->region->pitch, tile_stride);
197 #endif
198
199 return tile_base + tile_off;
200 }
201
202 static uint32_t y_tile_swizzle(struct intel_renderbuffer *irb,
203 int x, int y)
204 {
205 int tile_stride;
206 int xbyte;
207 int x_tile_off, y_tile_off;
208 int x_tile_number, y_tile_number;
209 int tile_off, tile_base;
210
211 x += irb->region->draw_x;
212 y += irb->region->draw_y;
213
214 tile_stride = (irb->region->pitch * irb->region->cpp) << 5;
215
216 xbyte = x * irb->region->cpp;
217
218 x_tile_off = xbyte & 0x7f;
219 y_tile_off = y & 0x1f;
220
221 x_tile_number = xbyte >> 7;
222 y_tile_number = y >> 5;
223
224 tile_off = ((x_tile_off & ~0xf) << 5) + (y_tile_off << 4) +
225 (x_tile_off & 0xf);
226
227 switch (irb->region->bit_6_swizzle) {
228 case I915_BIT_6_SWIZZLE_NONE:
229 break;
230 case I915_BIT_6_SWIZZLE_9:
231 tile_off ^= ((tile_off >> 3) & 64);
232 break;
233 case I915_BIT_6_SWIZZLE_9_10:
234 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 4) & 64);
235 break;
236 case I915_BIT_6_SWIZZLE_9_11:
237 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 5) & 64);
238 break;
239 case I915_BIT_6_SWIZZLE_9_10_11:
240 tile_off ^= ((tile_off >> 3) & 64) ^ ((tile_off >> 4) & 64) ^
241 ((tile_off >> 5) & 64);
242 break;
243 default:
244 fprintf(stderr, "Unknown tile swizzling mode %d\n",
245 irb->region->bit_6_swizzle);
246 exit(1);
247 }
248
249 tile_base = (x_tile_number << 12) + y_tile_number * tile_stride;
250
251 return tile_base + tile_off;
252 }
253
254 /*
255 break intelWriteRGBASpan_ARGB8888
256 */
257
258 #undef DBG
259 #define DBG 0
260
261 #define LOCAL_VARS \
262 struct intel_context *intel = intel_context(ctx); \
263 struct intel_renderbuffer *irb = intel_renderbuffer(rb); \
264 const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
265 const GLint yBias = ctx->DrawBuffer->Name ? 0 : irb->Base.Height - 1;\
266 unsigned int num_cliprects; \
267 struct drm_clip_rect *cliprects; \
268 int x_off, y_off; \
269 int pitch = irb->region->pitch * irb->region->cpp; \
270 void *buf = irb->region->buffer->virtual; \
271 GLuint p; \
272 (void) p; \
273 (void)buf; (void)pitch; /* unused for non-gttmap. */ \
274 intel_get_cliprects(intel, &cliprects, &num_cliprects, &x_off, &y_off);
275
276 /* XXX FBO: this is identical to the macro in spantmp2.h except we get
277 * the cliprect info from the context, not the driDrawable.
278 * Move this into spantmp2.h someday.
279 */
280 #define HW_CLIPLOOP() \
281 do { \
282 int _nc = num_cliprects; \
283 while ( _nc-- ) { \
284 int minx = cliprects[_nc].x1 - x_off; \
285 int miny = cliprects[_nc].y1 - y_off; \
286 int maxx = cliprects[_nc].x2 - x_off; \
287 int maxy = cliprects[_nc].y2 - y_off;
288
289 #if 0
290 }}
291 #endif
292
293 #define Y_FLIP(_y) ((_y) * yScale + yBias)
294
295 #define HW_LOCK()
296
297 #define HW_UNLOCK()
298
299 /* Convenience macros to avoid typing the swizzle argument over and over */
300 #define NO_TILE(_X, _Y) no_tile_swizzle(irb, (_X) + x_off, (_Y) + y_off)
301 #define X_TILE(_X, _Y) x_tile_swizzle(irb, (_X) + x_off, (_Y) + y_off)
302 #define Y_TILE(_X, _Y) y_tile_swizzle(irb, (_X) + x_off, (_Y) + y_off)
303
304 /* r5g6b5 color span and pixel functions */
305 #define INTEL_PIXEL_FMT GL_RGB
306 #define INTEL_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
307 #define INTEL_READ_VALUE(offset) pread_16(irb, offset)
308 #define INTEL_WRITE_VALUE(offset, v) pwrite_16(irb, offset, v)
309 #define INTEL_TAG(x) x##_RGB565
310 #include "intel_spantmp.h"
311
312 /* a4r4g4b4 color span and pixel functions */
313 #define INTEL_PIXEL_FMT GL_BGRA
314 #define INTEL_PIXEL_TYPE GL_UNSIGNED_SHORT_4_4_4_4_REV
315 #define INTEL_READ_VALUE(offset) pread_16(irb, offset)
316 #define INTEL_WRITE_VALUE(offset, v) pwrite_16(irb, offset, v)
317 #define INTEL_TAG(x) x##_ARGB4444
318 #include "intel_spantmp.h"
319
320 /* a1r5g5b5 color span and pixel functions */
321 #define INTEL_PIXEL_FMT GL_BGRA
322 #define INTEL_PIXEL_TYPE GL_UNSIGNED_SHORT_1_5_5_5_REV
323 #define INTEL_READ_VALUE(offset) pread_16(irb, offset)
324 #define INTEL_WRITE_VALUE(offset, v) pwrite_16(irb, offset, v)
325 #define INTEL_TAG(x) x##_ARGB1555
326 #include "intel_spantmp.h"
327
328 /* a8r8g8b8 color span and pixel functions */
329 #define INTEL_PIXEL_FMT GL_BGRA
330 #define INTEL_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
331 #define INTEL_READ_VALUE(offset) pread_32(irb, offset)
332 #define INTEL_WRITE_VALUE(offset, v) pwrite_32(irb, offset, v)
333 #define INTEL_TAG(x) x##_ARGB8888
334 #include "intel_spantmp.h"
335
336 /* x8r8g8b8 color span and pixel functions */
337 #define INTEL_PIXEL_FMT GL_BGR
338 #define INTEL_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
339 #define INTEL_READ_VALUE(offset) pread_xrgb8888(irb, offset)
340 #define INTEL_WRITE_VALUE(offset, v) pwrite_xrgb8888(irb, offset, v)
341 #define INTEL_TAG(x) x##_xRGB8888
342 #include "intel_spantmp.h"
343
344 #define LOCAL_DEPTH_VARS \
345 struct intel_context *intel = intel_context(ctx); \
346 struct intel_renderbuffer *irb = intel_renderbuffer(rb); \
347 const GLint yScale = ctx->DrawBuffer->Name ? 1 : -1; \
348 const GLint yBias = ctx->DrawBuffer->Name ? 0 : irb->Base.Height - 1;\
349 unsigned int num_cliprects; \
350 struct drm_clip_rect *cliprects; \
351 int x_off, y_off; \
352 int pitch = irb->region->pitch * irb->region->cpp; \
353 void *buf = irb->region->buffer->virtual; \
354 (void)buf; (void)pitch; /* unused for non-gttmap. */ \
355 intel_get_cliprects(intel, &cliprects, &num_cliprects, &x_off, &y_off);
356
357
358 #define LOCAL_STENCIL_VARS LOCAL_DEPTH_VARS
359
360 /* z16 depthbuffer functions. */
361 #define INTEL_VALUE_TYPE GLushort
362 #define INTEL_WRITE_DEPTH(offset, d) pwrite_16(irb, offset, d)
363 #define INTEL_READ_DEPTH(offset) pread_16(irb, offset)
364 #define INTEL_TAG(name) name##_z16
365 #include "intel_depthtmp.h"
366
367 /* z24x8 depthbuffer functions. */
368 #define INTEL_VALUE_TYPE GLuint
369 #define INTEL_WRITE_DEPTH(offset, d) pwrite_32(irb, offset, d)
370 #define INTEL_READ_DEPTH(offset) pread_32(irb, offset)
371 #define INTEL_TAG(name) name##_z24_x8
372 #include "intel_depthtmp.h"
373
374
375 /**
376 ** 8-bit stencil function (XXX FBO: This is obsolete)
377 **/
378 /* XXX */
379 #define WRITE_STENCIL(_x, _y, d) pwrite_8(irb, NO_TILE(_x, _y) + 3, d)
380 #define READ_STENCIL(d, _x, _y) d = pread_8(irb, NO_TILE(_x, _y) + 3);
381 #define TAG(x) intel_gttmap_##x##_z24_s8
382 #include "stenciltmp.h"
383
384 /**
385 ** 8-bit stencil function (XXX FBO: This is obsolete)
386 **/
387 #define WRITE_STENCIL(_x, _y, d) pwrite_8(irb, NO_TILE(_x, _y) + 3, d)
388 #define READ_STENCIL(d, _x, _y) d = pread_8(irb, NO_TILE(_x, _y) + 3);
389 #define TAG(x) intel##x##_z24_s8
390 #include "stenciltmp.h"
391
392 /**
393 ** 8-bit x-tile stencil function (XXX FBO: This is obsolete)
394 **/
395 #define WRITE_STENCIL(_x, _y, d) pwrite_8(irb, X_TILE(_x, _y) + 3, d)
396 #define READ_STENCIL(d, _x, _y) d = pread_8(irb, X_TILE(_x, _y) + 3);
397 #define TAG(x) intel_XTile_##x##_z24_s8
398 #include "stenciltmp.h"
399
400 /**
401 ** 8-bit y-tile stencil function (XXX FBO: This is obsolete)
402 **/
403 #define WRITE_STENCIL(_x, _y, d) pwrite_8(irb, Y_TILE(_x, _y) + 3, d)
404 #define READ_STENCIL(d, _x, _y) d = pread_8(irb, Y_TILE(_x, _y) + 3)
405 #define TAG(x) intel_YTile_##x##_z24_s8
406 #include "stenciltmp.h"
407
408 void
409 intel_renderbuffer_map(struct intel_context *intel, struct gl_renderbuffer *rb)
410 {
411 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
412
413 if (irb == NULL || irb->region == NULL)
414 return;
415
416 if (intel->intelScreen->kernel_exec_fencing)
417 drm_intel_gem_bo_map_gtt(irb->region->buffer);
418
419 intel_set_span_functions(intel, rb);
420 }
421
422 void
423 intel_renderbuffer_unmap(struct intel_context *intel,
424 struct gl_renderbuffer *rb)
425 {
426 struct intel_renderbuffer *irb = intel_renderbuffer(rb);
427
428 if (irb == NULL || irb->region == NULL)
429 return;
430
431 if (intel->intelScreen->kernel_exec_fencing)
432 drm_intel_gem_bo_unmap_gtt(irb->region->buffer);
433 else
434 clear_span_cache(irb);
435
436 rb->GetRow = NULL;
437 rb->PutRow = NULL;
438 }
439
440 /**
441 * Map or unmap all the renderbuffers which we may need during
442 * software rendering.
443 * XXX in the future, we could probably convey extra information to
444 * reduce the number of mappings needed. I.e. if doing a glReadPixels
445 * from the depth buffer, we really only need one mapping.
446 *
447 * XXX Rewrite this function someday.
448 * We can probably just loop over all the renderbuffer attachments,
449 * map/unmap all of them, and not worry about the _ColorDrawBuffers
450 * _ColorReadBuffer, _DepthBuffer or _StencilBuffer fields.
451 */
452 static void
453 intel_map_unmap_framebuffer(struct intel_context *intel,
454 struct gl_framebuffer *fb,
455 GLboolean map)
456 {
457 GLuint i;
458
459 /* color draw buffers */
460 for (i = 0; i < fb->_NumColorDrawBuffers; i++) {
461 if (map)
462 intel_renderbuffer_map(intel, fb->_ColorDrawBuffers[i]);
463 else
464 intel_renderbuffer_unmap(intel, fb->_ColorDrawBuffers[i]);
465 }
466
467 /* color read buffer */
468 if (map)
469 intel_renderbuffer_map(intel, fb->_ColorReadBuffer);
470 else
471 intel_renderbuffer_unmap(intel, fb->_ColorReadBuffer);
472
473 /* check for render to textures */
474 for (i = 0; i < BUFFER_COUNT; i++) {
475 struct gl_renderbuffer_attachment *att =
476 fb->Attachment + i;
477 struct gl_texture_object *tex = att->Texture;
478 if (tex) {
479 /* render to texture */
480 ASSERT(att->Renderbuffer);
481 if (map)
482 intel_tex_map_images(intel, intel_texture_object(tex));
483 else
484 intel_tex_unmap_images(intel, intel_texture_object(tex));
485 }
486 }
487
488 /* depth buffer (Note wrapper!) */
489 if (fb->_DepthBuffer) {
490 if (map)
491 intel_renderbuffer_map(intel, fb->_DepthBuffer->Wrapped);
492 else
493 intel_renderbuffer_unmap(intel, fb->_DepthBuffer->Wrapped);
494 }
495
496 /* stencil buffer (Note wrapper!) */
497 if (fb->_StencilBuffer) {
498 if (map)
499 intel_renderbuffer_map(intel, fb->_StencilBuffer->Wrapped);
500 else
501 intel_renderbuffer_unmap(intel, fb->_StencilBuffer->Wrapped);
502 }
503
504 intel_check_front_buffer_rendering(intel);
505 }
506
507 /**
508 * Prepare for software rendering. Map current read/draw framebuffers'
509 * renderbuffes and all currently bound texture objects.
510 *
511 * Old note: Moved locking out to get reasonable span performance.
512 */
513 void
514 intelSpanRenderStart(GLcontext * ctx)
515 {
516 struct intel_context *intel = intel_context(ctx);
517 GLuint i;
518
519 intelFlush(&intel->ctx);
520 LOCK_HARDWARE(intel);
521
522 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
523 if (ctx->Texture.Unit[i]._ReallyEnabled) {
524 struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
525 intel_tex_map_images(intel, intel_texture_object(texObj));
526 }
527 }
528
529 intel_map_unmap_framebuffer(intel, ctx->DrawBuffer, GL_TRUE);
530 if (ctx->ReadBuffer != ctx->DrawBuffer)
531 intel_map_unmap_framebuffer(intel, ctx->ReadBuffer, GL_TRUE);
532 }
533
534 /**
535 * Called when done software rendering. Unmap the buffers we mapped in
536 * the above function.
537 */
538 void
539 intelSpanRenderFinish(GLcontext * ctx)
540 {
541 struct intel_context *intel = intel_context(ctx);
542 GLuint i;
543
544 _swrast_flush(ctx);
545
546 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
547 if (ctx->Texture.Unit[i]._ReallyEnabled) {
548 struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
549 intel_tex_unmap_images(intel, intel_texture_object(texObj));
550 }
551 }
552
553 intel_map_unmap_framebuffer(intel, ctx->DrawBuffer, GL_FALSE);
554 if (ctx->ReadBuffer != ctx->DrawBuffer)
555 intel_map_unmap_framebuffer(intel, ctx->ReadBuffer, GL_FALSE);
556
557 UNLOCK_HARDWARE(intel);
558 }
559
560
561 void
562 intelInitSpanFuncs(GLcontext * ctx)
563 {
564 struct swrast_device_driver *swdd = _swrast_GetDeviceDriverReference(ctx);
565 swdd->SpanRenderStart = intelSpanRenderStart;
566 swdd->SpanRenderFinish = intelSpanRenderFinish;
567 }
568
569 void
570 intel_map_vertex_shader_textures(GLcontext *ctx)
571 {
572 struct intel_context *intel = intel_context(ctx);
573 int i;
574
575 if (ctx->VertexProgram._Current == NULL)
576 return;
577
578 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
579 if (ctx->Texture.Unit[i]._ReallyEnabled &&
580 ctx->VertexProgram._Current->Base.TexturesUsed[i] != 0) {
581 struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
582
583 intel_tex_map_images(intel, intel_texture_object(texObj));
584 }
585 }
586 }
587
588 void
589 intel_unmap_vertex_shader_textures(GLcontext *ctx)
590 {
591 struct intel_context *intel = intel_context(ctx);
592 int i;
593
594 if (ctx->VertexProgram._Current == NULL)
595 return;
596
597 for (i = 0; i < ctx->Const.MaxTextureImageUnits; i++) {
598 if (ctx->Texture.Unit[i]._ReallyEnabled &&
599 ctx->VertexProgram._Current->Base.TexturesUsed[i] != 0) {
600 struct gl_texture_object *texObj = ctx->Texture.Unit[i]._Current;
601
602 intel_tex_unmap_images(intel, intel_texture_object(texObj));
603 }
604 }
605 }
606
607 /**
608 * Plug in appropriate span read/write functions for the given renderbuffer.
609 * These are used for the software fallbacks.
610 */
611 static void
612 intel_set_span_functions(struct intel_context *intel,
613 struct gl_renderbuffer *rb)
614 {
615 struct intel_renderbuffer *irb = (struct intel_renderbuffer *) rb;
616 uint32_t tiling;
617
618 /* If in GEM mode, we need to do the tile address swizzling ourselves,
619 * instead of the fence registers handling it.
620 */
621 if (intel->ttm)
622 tiling = irb->region->tiling;
623 else
624 tiling = I915_TILING_NONE;
625
626 if (intel->intelScreen->kernel_exec_fencing) {
627 switch (irb->Base.Format) {
628 case MESA_FORMAT_RGB565:
629 intel_gttmap_InitPointers_RGB565(rb);
630 break;
631 case MESA_FORMAT_ARGB4444:
632 intel_gttmap_InitPointers_ARGB4444(rb);
633 break;
634 case MESA_FORMAT_ARGB1555:
635 intel_gttmap_InitPointers_ARGB1555(rb);
636 break;
637 case MESA_FORMAT_XRGB8888:
638 intel_gttmap_InitPointers_xRGB8888(rb);
639 break;
640 case MESA_FORMAT_ARGB8888:
641 intel_gttmap_InitPointers_ARGB8888(rb);
642 break;
643 case MESA_FORMAT_Z16:
644 intel_gttmap_InitDepthPointers_z16(rb);
645 break;
646 case MESA_FORMAT_X8_Z24:
647 intel_gttmap_InitDepthPointers_z24_x8(rb);
648 break;
649 case MESA_FORMAT_S8_Z24:
650 /* There are a few different ways SW asks us to access the S8Z24 data:
651 * Z24 depth-only depth reads
652 * S8Z24 depth reads
653 * S8Z24 stencil reads.
654 */
655 if (rb->Format == MESA_FORMAT_S8_Z24) {
656 intel_gttmap_InitDepthPointers_z24_x8(rb);
657 } else if (rb->Format == MESA_FORMAT_S8) {
658 intel_gttmap_InitStencilPointers_z24_s8(rb);
659 }
660 break;
661 default:
662 _mesa_problem(NULL,
663 "Unexpected MesaFormat %d in intelSetSpanFunctions",
664 irb->Base.Format);
665 break;
666 }
667 return;
668 }
669
670 switch (irb->Base.Format) {
671 case MESA_FORMAT_RGB565:
672 switch (tiling) {
673 case I915_TILING_NONE:
674 default:
675 intelInitPointers_RGB565(rb);
676 break;
677 case I915_TILING_X:
678 intel_XTile_InitPointers_RGB565(rb);
679 break;
680 case I915_TILING_Y:
681 intel_YTile_InitPointers_RGB565(rb);
682 break;
683 }
684 break;
685 case MESA_FORMAT_ARGB4444:
686 switch (tiling) {
687 case I915_TILING_NONE:
688 default:
689 intelInitPointers_ARGB4444(rb);
690 break;
691 case I915_TILING_X:
692 intel_XTile_InitPointers_ARGB4444(rb);
693 break;
694 case I915_TILING_Y:
695 intel_YTile_InitPointers_ARGB4444(rb);
696 break;
697 }
698 break;
699 case MESA_FORMAT_ARGB1555:
700 switch (tiling) {
701 case I915_TILING_NONE:
702 default:
703 intelInitPointers_ARGB1555(rb);
704 break;
705 case I915_TILING_X:
706 intel_XTile_InitPointers_ARGB1555(rb);
707 break;
708 case I915_TILING_Y:
709 intel_YTile_InitPointers_ARGB1555(rb);
710 break;
711 }
712 break;
713 case MESA_FORMAT_XRGB8888:
714 switch (tiling) {
715 case I915_TILING_NONE:
716 default:
717 intelInitPointers_xRGB8888(rb);
718 break;
719 case I915_TILING_X:
720 intel_XTile_InitPointers_xRGB8888(rb);
721 break;
722 case I915_TILING_Y:
723 intel_YTile_InitPointers_xRGB8888(rb);
724 break;
725 }
726 break;
727 case MESA_FORMAT_ARGB8888:
728 /* 8888 RGBA */
729 switch (tiling) {
730 case I915_TILING_NONE:
731 default:
732 intelInitPointers_ARGB8888(rb);
733 break;
734 case I915_TILING_X:
735 intel_XTile_InitPointers_ARGB8888(rb);
736 break;
737 case I915_TILING_Y:
738 intel_YTile_InitPointers_ARGB8888(rb);
739 break;
740 }
741 break;
742 case MESA_FORMAT_Z16:
743 switch (tiling) {
744 case I915_TILING_NONE:
745 default:
746 intelInitDepthPointers_z16(rb);
747 break;
748 case I915_TILING_X:
749 intel_XTile_InitDepthPointers_z16(rb);
750 break;
751 case I915_TILING_Y:
752 intel_YTile_InitDepthPointers_z16(rb);
753 break;
754 }
755 break;
756 case MESA_FORMAT_X8_Z24:
757 case MESA_FORMAT_S8_Z24:
758 /* There are a few different ways SW asks us to access the S8Z24 data:
759 * Z24 depth-only depth reads
760 * S8Z24 depth reads
761 * S8Z24 stencil reads.
762 */
763 if (rb->Format == MESA_FORMAT_S8_Z24) {
764 switch (tiling) {
765 case I915_TILING_NONE:
766 default:
767 intelInitDepthPointers_z24_x8(rb);
768 break;
769 case I915_TILING_X:
770 intel_XTile_InitDepthPointers_z24_x8(rb);
771 break;
772 case I915_TILING_Y:
773 intel_YTile_InitDepthPointers_z24_x8(rb);
774 break;
775 }
776 } else if (rb->Format == MESA_FORMAT_S8) {
777 switch (tiling) {
778 case I915_TILING_NONE:
779 default:
780 intelInitStencilPointers_z24_s8(rb);
781 break;
782 case I915_TILING_X:
783 intel_XTile_InitStencilPointers_z24_s8(rb);
784 break;
785 case I915_TILING_Y:
786 intel_YTile_InitStencilPointers_z24_s8(rb);
787 break;
788 }
789 } else {
790 _mesa_problem(NULL,
791 "Unexpected ActualFormat in intelSetSpanFunctions");
792 }
793 break;
794 default:
795 _mesa_problem(NULL,
796 "Unexpected MesaFormat in intelSetSpanFunctions");
797 break;
798 }
799 }