~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/radeon/radeon_fbo.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
  free(rrb);
71
71
}
72
72
 
73
 
static void *
74
 
radeon_get_pointer(struct gl_context *ctx, struct gl_renderbuffer *rb,
75
 
                   GLint x, GLint y)
76
 
{
77
 
  radeon_print(RADEON_TEXTURE, RADEON_TRACE,
78
 
                "%s(%p, rb %p) \n",
79
 
                __func__, ctx, rb);
80
 
 
81
 
  return NULL;
82
 
}
 
73
#if defined(RADEON_R100)
 
74
static GLuint get_depth_z32(const struct radeon_renderbuffer * rrb,
 
75
                               GLint x, GLint y)
 
76
{
 
77
    GLuint ba, address = 0;
 
78
 
 
79
    ba = (y >> 4) * (rrb->pitch >> 6) + (x >> 4);
 
80
 
 
81
    address |= (x & 0x7) << 2;
 
82
    address |= (y & 0x3) << 5;
 
83
    address |= (((x & 0x10) >> 2) ^ (y & 0x4)) << 5;
 
84
    address |= (ba & 3) << 8;
 
85
    address |= (y & 0x8) << 7;
 
86
    address |= (((x & 0x8) << 1) ^ (y & 0x10)) << 7;
 
87
    address |= (ba & ~0x3) << 10;
 
88
    return address;
 
89
}
 
90
 
 
91
static GLuint get_depth_z16(const struct radeon_renderbuffer * rrb,
 
92
                               GLint x, GLint y)
 
93
{
 
94
    GLuint ba, address = 0;                   /* a[0]    = 0           */
 
95
 
 
96
    ba = (y / 16) * (rrb->pitch >> 6) + (x / 32);
 
97
 
 
98
    address |= (x & 0x7) << 1;                /* a[1..3] = x[0..2]     */
 
99
    address |= (y & 0x7) << 4;                /* a[4..6] = y[0..2]     */
 
100
    address |= (x & 0x8) << 4;                /* a[7]    = x[3]        */
 
101
    address |= (ba & 0x3) << 8;               /* a[8..9] = ba[0..1]    */
 
102
    address |= (y & 0x8) << 7;                /* a[10]   = y[3]        */
 
103
    address |= ((x & 0x10) ^ (y & 0x10)) << 7;/* a[11]   = x[4] ^ y[4] */
 
104
    address |= (ba & ~0x3) << 10;             /* a[12..] = ba[2..] */
 
105
    return address;
 
106
}
 
107
#endif
 
108
 
 
109
#if defined(RADEON_R200)
 
110
static GLuint get_depth_z32(const struct radeon_renderbuffer * rrb,
 
111
                                 GLint x, GLint y)
 
112
{
 
113
    GLuint offset;
 
114
    GLuint b;
 
115
    offset = 0;
 
116
    b = (((y & 0x7ff) >> 4) * (rrb->pitch >> 7) + (x >> 5));
 
117
    offset += (b >> 1) << 12;
 
118
    offset += (((rrb->pitch >> 7) & 0x1) ? (b & 0x1) : ((b & 0x1) ^ ((y >> 4) & 0x1))) << 11;
 
119
    offset += ((y >> 2) & 0x3) << 9;
 
120
    offset += ((x >> 2) & 0x1) << 8;
 
121
    offset += ((x >> 3) & 0x3) << 6;
 
122
    offset += ((y >> 1) & 0x1) << 5;
 
123
    offset += ((x >> 1) & 0x1) << 4;
 
124
    offset += (y & 0x1) << 3;
 
125
    offset += (x & 0x1) << 2;
 
126
 
 
127
    return offset;
 
128
}
 
129
 
 
130
static GLuint get_depth_z16(const struct radeon_renderbuffer *rrb,
 
131
                               GLint x, GLint y)
 
132
{
 
133
   GLuint offset;
 
134
   GLuint b;
 
135
 
 
136
   offset = 0;
 
137
   b = (((y  >> 4) * (rrb->pitch >> 7) + (x >> 6)));
 
138
   offset += (b >> 1) << 12;
 
139
   offset += (((rrb->pitch >> 7) & 0x1) ? (b & 0x1) : ((b & 0x1) ^ ((y >> 4) & 0x1))) << 11;
 
140
   offset += ((y >> 2) & 0x3) << 9;
 
141
   offset += ((x >> 3) & 0x1) << 8;
 
142
   offset += ((x >> 4) & 0x3) << 6;
 
143
   offset += ((x >> 2) & 0x1) << 5;
 
144
   offset += ((y >> 1) & 0x1) << 4;
 
145
   offset += ((x >> 1) & 0x1) << 3;
 
146
   offset += (y & 0x1) << 2;
 
147
   offset += (x & 0x1) << 1;
 
148
 
 
149
   return offset;
 
150
}
 
151
#endif
 
152
 
 
153
static void
 
154
radeon_map_renderbuffer_s8z24(struct gl_context *ctx,
 
155
                       struct gl_renderbuffer *rb,
 
156
                       GLuint x, GLuint y, GLuint w, GLuint h,
 
157
                       GLbitfield mode,
 
158
                       GLubyte **out_map,
 
159
                       GLint *out_stride)
 
160
{
 
161
    struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
162
    uint32_t *untiled_s8z24_map, *tiled_s8z24_map;
 
163
    int ret;
 
164
    int y_flip = (rb->Name == 0) ? -1 : 1;
 
165
    int y_bias = (rb->Name == 0) ? (rb->Height - 1) : 0;
 
166
    uint32_t pitch = w * rrb->cpp;
 
167
 
 
168
    rrb->map_pitch = pitch;
 
169
 
 
170
    rrb->map_buffer = malloc(w * h * 4);
 
171
    ret = radeon_bo_map(rrb->bo, !!(mode & GL_MAP_WRITE_BIT));
 
172
    assert(!ret);
 
173
    untiled_s8z24_map = rrb->map_buffer;
 
174
    tiled_s8z24_map = rrb->bo->ptr;
 
175
 
 
176
    for (uint32_t pix_y = 0; pix_y < h; ++ pix_y) {
 
177
        for (uint32_t pix_x = 0; pix_x < w; ++pix_x) {
 
178
            uint32_t flipped_y = y_flip * (int32_t)(y + pix_y) + y_bias;
 
179
            uint32_t src_offset = get_depth_z32(rrb, x + pix_x, flipped_y);
 
180
            uint32_t dst_offset = pix_y * rrb->map_pitch + pix_x * rrb->cpp;
 
181
            untiled_s8z24_map[dst_offset/4] = tiled_s8z24_map[src_offset/4];
 
182
        }
 
183
    }
 
184
 
 
185
    radeon_bo_unmap(rrb->bo);
 
186
                   
 
187
    *out_map = rrb->map_buffer;
 
188
    *out_stride = rrb->map_pitch;
 
189
}
 
190
 
 
191
static void
 
192
radeon_map_renderbuffer_z16(struct gl_context *ctx,
 
193
                            struct gl_renderbuffer *rb,
 
194
                            GLuint x, GLuint y, GLuint w, GLuint h,
 
195
                            GLbitfield mode,
 
196
                            GLubyte **out_map,
 
197
                            GLint *out_stride)
 
198
{
 
199
    struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
200
    uint16_t *untiled_z16_map, *tiled_z16_map;
 
201
    int ret;
 
202
    int y_flip = (rb->Name == 0) ? -1 : 1;
 
203
    int y_bias = (rb->Name == 0) ? (rb->Height - 1) : 0;
 
204
    uint32_t pitch = w * rrb->cpp;
 
205
 
 
206
    rrb->map_pitch = pitch;
 
207
 
 
208
    rrb->map_buffer = malloc(w * h * 2);
 
209
    ret = radeon_bo_map(rrb->bo, !!(mode & GL_MAP_WRITE_BIT));
 
210
    assert(!ret);
 
211
 
 
212
    untiled_z16_map = rrb->map_buffer;
 
213
    tiled_z16_map = rrb->bo->ptr;
 
214
 
 
215
    for (uint32_t pix_y = 0; pix_y < h; ++ pix_y) {
 
216
        for (uint32_t pix_x = 0; pix_x < w; ++pix_x) {
 
217
            uint32_t flipped_y = y_flip * (int32_t)(y + pix_y) + y_bias;
 
218
            uint32_t src_offset = get_depth_z16(rrb, x + pix_x, flipped_y);
 
219
            uint32_t dst_offset = pix_y * rrb->map_pitch + pix_x * rrb->cpp;
 
220
            untiled_z16_map[dst_offset/2] = tiled_z16_map[src_offset/2];
 
221
        }
 
222
    }
 
223
 
 
224
    radeon_bo_unmap(rrb->bo);
 
225
 
 
226
    *out_map = rrb->map_buffer;
 
227
    *out_stride = rrb->map_pitch;
 
228
}
 
229
 
 
230
static void
 
231
radeon_map_renderbuffer(struct gl_context *ctx,
 
232
                       struct gl_renderbuffer *rb,
 
233
                       GLuint x, GLuint y, GLuint w, GLuint h,
 
234
                       GLbitfield mode,
 
235
                       GLubyte **out_map,
 
236
                       GLint *out_stride)
 
237
{
 
238
   struct radeon_context *const rmesa = RADEON_CONTEXT(ctx);
 
239
   struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
240
   GLubyte *map;
 
241
   GLboolean ok;
 
242
   int stride, flip_stride;
 
243
   int ret;
 
244
   int src_x, src_y;
 
245
 
 
246
   if (!rrb || !rrb->bo) {
 
247
           *out_map = NULL;
 
248
           *out_stride = 0;
 
249
           return;
 
250
   }
 
251
 
 
252
   rrb->map_mode = mode;
 
253
   rrb->map_x = x;
 
254
   rrb->map_y = y;
 
255
   rrb->map_w = w;
 
256
   rrb->map_h = h;
 
257
   rrb->map_pitch = rrb->pitch;
 
258
 
 
259
   ok = rmesa->vtbl.check_blit(rb->Format, rrb->pitch / rrb->cpp);
 
260
   if (ok) {
 
261
       if (rb->Name) {
 
262
           src_x = x;
 
263
           src_y = y;
 
264
       } else {
 
265
           src_x = x;
 
266
           src_y = rrb->base.Base.Height - y - h;
 
267
       }
 
268
 
 
269
       /* Make a temporary buffer and blit the current contents of the renderbuffer
 
270
        * out to it.  This gives us linear access to the buffer, instead of having
 
271
        * to do detiling in software.
 
272
        */
 
273
 
 
274
       rrb->map_pitch = rrb->pitch;
 
275
 
 
276
       assert(!rrb->map_bo);
 
277
       rrb->map_bo = radeon_bo_open(rmesa->radeonScreen->bom, 0,
 
278
                                    rrb->map_pitch * h, 4,
 
279
                                    RADEON_GEM_DOMAIN_GTT, 0);
 
280
       
 
281
       ok = rmesa->vtbl.blit(ctx, rrb->bo, rrb->draw_offset,
 
282
                             rb->Format, rrb->pitch / rrb->cpp,
 
283
                             rb->Width, rb->Height,
 
284
                             src_x, src_y,
 
285
                             rrb->map_bo, 0,
 
286
                             rb->Format, rrb->map_pitch / rrb->cpp,
 
287
                             w, h,
 
288
                             0, 0,
 
289
                             w, h,
 
290
                             GL_FALSE);
 
291
       assert(ok);
 
292
 
 
293
       ret = radeon_bo_map(rrb->map_bo, !!(mode & GL_MAP_WRITE_BIT));
 
294
       assert(!ret);
 
295
 
 
296
       map = rrb->map_bo->ptr;
 
297
 
 
298
       if (rb->Name) {
 
299
           *out_map = map;
 
300
           *out_stride = rrb->map_pitch;
 
301
       } else {
 
302
           *out_map = map + (h - 1) * rrb->map_pitch;
 
303
           *out_stride = -rrb->map_pitch;
 
304
       }
 
305
       return;
 
306
   }
 
307
 
 
308
   /* sw fallback flush stuff */
 
309
   if (radeon_bo_is_referenced_by_cs(rrb->bo, rmesa->cmdbuf.cs)) {
 
310
      radeon_firevertices(rmesa);
 
311
   }
 
312
 
 
313
   if ((rmesa->radeonScreen->chip_flags & RADEON_CHIPSET_DEPTH_ALWAYS_TILED) && !rrb->has_surface) {
 
314
       if (rb->Format == MESA_FORMAT_S8_Z24 || rb->Format == MESA_FORMAT_X8_Z24) {
 
315
           radeon_map_renderbuffer_s8z24(ctx, rb, x, y, w, h,
 
316
                                         mode, out_map, out_stride);
 
317
           return;
 
318
       }
 
319
       if (rb->Format == MESA_FORMAT_Z16) {
 
320
           radeon_map_renderbuffer_z16(ctx, rb, x, y, w, h,
 
321
                                       mode, out_map, out_stride);
 
322
           return;
 
323
       }
 
324
   }
 
325
 
 
326
   ret = radeon_bo_map(rrb->bo, !!(mode & GL_MAP_WRITE_BIT));
 
327
   assert(!ret);
 
328
 
 
329
   map = rrb->bo->ptr;
 
330
   stride = rrb->map_pitch;
 
331
 
 
332
   if (rb->Name == 0) {
 
333
      y = rb->Height - 1 - y;
 
334
      flip_stride = -stride;
 
335
   } else {
 
336
      flip_stride = stride;
 
337
      map += rrb->draw_offset;
 
338
   }
 
339
 
 
340
   map += x * rrb->cpp;
 
341
   map += (int)y * stride;
 
342
 
 
343
   *out_map = map;
 
344
   *out_stride = flip_stride;
 
345
}
 
346
 
 
347
static void
 
348
radeon_unmap_renderbuffer_s8z24(struct gl_context *ctx,
 
349
                          struct gl_renderbuffer *rb)
 
350
{
 
351
   struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
352
 
 
353
   if (!rrb->map_buffer)
 
354
     return;
 
355
 
 
356
   if (rrb->map_mode & GL_MAP_WRITE_BIT) {
 
357
       uint32_t *untiled_s8z24_map = rrb->map_buffer;
 
358
       uint32_t *tiled_s8z24_map;
 
359
       int y_flip = (rb->Name == 0) ? -1 : 1;
 
360
       int y_bias = (rb->Name == 0) ? (rb->Height - 1) : 0;
 
361
 
 
362
       radeon_bo_map(rrb->bo, 1);
 
363
       
 
364
       tiled_s8z24_map = rrb->bo->ptr;
 
365
 
 
366
       for (uint32_t pix_y = 0; pix_y < rrb->map_h; pix_y++) {
 
367
           for (uint32_t pix_x = 0; pix_x < rrb->map_w; pix_x++) {
 
368
               uint32_t flipped_y = y_flip * (int32_t)(pix_y + rrb->map_y) + y_bias;
 
369
               uint32_t dst_offset = get_depth_z32(rrb, rrb->map_x + pix_x, flipped_y);
 
370
               uint32_t src_offset = pix_y * rrb->map_pitch + pix_x * rrb->cpp;
 
371
               tiled_s8z24_map[dst_offset/4] = untiled_s8z24_map[src_offset/4];
 
372
           }
 
373
       }
 
374
       radeon_bo_unmap(rrb->bo);
 
375
   }
 
376
   free(rrb->map_buffer);
 
377
   rrb->map_buffer = NULL;
 
378
}
 
379
 
 
380
static void
 
381
radeon_unmap_renderbuffer_z16(struct gl_context *ctx,
 
382
                              struct gl_renderbuffer *rb)
 
383
{
 
384
   struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
385
 
 
386
   if (!rrb->map_buffer)
 
387
     return;
 
388
 
 
389
   if (rrb->map_mode & GL_MAP_WRITE_BIT) {
 
390
       uint16_t *untiled_z16_map = rrb->map_buffer;
 
391
       uint16_t *tiled_z16_map;
 
392
       int y_flip = (rb->Name == 0) ? -1 : 1;
 
393
       int y_bias = (rb->Name == 0) ? (rb->Height - 1) : 0;
 
394
 
 
395
       radeon_bo_map(rrb->bo, 1);
 
396
       
 
397
       tiled_z16_map = rrb->bo->ptr;
 
398
 
 
399
       for (uint32_t pix_y = 0; pix_y < rrb->map_h; pix_y++) {
 
400
           for (uint32_t pix_x = 0; pix_x < rrb->map_w; pix_x++) {
 
401
               uint32_t flipped_y = y_flip * (int32_t)(pix_y + rrb->map_y) + y_bias;
 
402
               uint32_t dst_offset = get_depth_z16(rrb, rrb->map_x + pix_x, flipped_y);
 
403
               uint32_t src_offset = pix_y * rrb->map_pitch + pix_x * rrb->cpp;
 
404
               tiled_z16_map[dst_offset/2] = untiled_z16_map[src_offset/2];
 
405
           }
 
406
       }
 
407
       radeon_bo_unmap(rrb->bo);
 
408
   }
 
409
   free(rrb->map_buffer);
 
410
   rrb->map_buffer = NULL;
 
411
}
 
412
 
 
413
 
 
414
static void
 
415
radeon_unmap_renderbuffer(struct gl_context *ctx,
 
416
                          struct gl_renderbuffer *rb)
 
417
{
 
418
   struct radeon_context *const rmesa = RADEON_CONTEXT(ctx);
 
419
   struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
 
420
   GLboolean ok;
 
421
 
 
422
   if ((rmesa->radeonScreen->chip_flags & RADEON_CHIPSET_DEPTH_ALWAYS_TILED) && !rrb->has_surface) {
 
423
       if (rb->Format == MESA_FORMAT_S8_Z24 || rb->Format == MESA_FORMAT_X8_Z24) {
 
424
           radeon_unmap_renderbuffer_s8z24(ctx, rb);
 
425
           return;
 
426
       }
 
427
       if (rb->Format == MESA_FORMAT_Z16) {
 
428
           radeon_unmap_renderbuffer_z16(ctx, rb);
 
429
           return;
 
430
       }
 
431
   }
 
432
 
 
433
   if (!rrb->map_bo) {
 
434
           if (rrb->bo)
 
435
                   radeon_bo_unmap(rrb->bo);
 
436
           return;
 
437
   }
 
438
 
 
439
   radeon_bo_unmap(rrb->map_bo);
 
440
 
 
441
   if (rrb->map_mode & GL_MAP_WRITE_BIT) {
 
442
      ok = rmesa->vtbl.blit(ctx, rrb->map_bo, 0,
 
443
                            rb->Format, rrb->map_pitch / rrb->cpp,
 
444
                            rrb->map_w, rrb->map_h,
 
445
                            0, 0,
 
446
                            rrb->bo, rrb->draw_offset,
 
447
                            rb->Format, rrb->pitch / rrb->cpp,
 
448
                            rb->Width, rb->Height,
 
449
                            rrb->map_x, rrb->map_y,
 
450
                            rrb->map_w, rrb->map_h,
 
451
                            GL_FALSE);
 
452
      assert(ok);
 
453
   }
 
454
 
 
455
   radeon_bo_unref(rrb->map_bo);
 
456
   rrb->map_bo = NULL;
 
457
}
 
458
 
83
459
 
84
460
/**
85
461
 * Called via glRenderbufferStorageEXT() to set the format and allocate
92
468
{
93
469
  struct radeon_context *radeon = RADEON_CONTEXT(ctx);
94
470
  struct radeon_renderbuffer *rrb = radeon_renderbuffer(rb);
95
 
  GLboolean software_buffer = GL_FALSE;
 
471
  uint32_t size, pitch;
96
472
  int cpp;
97
473
 
98
474
  radeon_print(RADEON_TEXTURE, RADEON_TRACE,
104
480
   case GL_R3_G3_B2:
105
481
   case GL_RGB4:
106
482
   case GL_RGB5:
107
 
      rb->Format = _dri_texformat_rgb565;
108
 
      rb->DataType = GL_UNSIGNED_BYTE;
 
483
      rb->Format = _radeon_texformat_rgb565;
109
484
      cpp = 2;
110
485
      break;
111
486
   case GL_RGB:
113
488
   case GL_RGB10:
114
489
   case GL_RGB12:
115
490
   case GL_RGB16:
116
 
      rb->Format = _dri_texformat_argb8888;
117
 
      rb->DataType = GL_UNSIGNED_BYTE;
 
491
      rb->Format = _radeon_texformat_argb8888;
118
492
      cpp = 4;
119
493
      break;
120
494
   case GL_RGBA:
125
499
   case GL_RGB10_A2:
126
500
   case GL_RGBA12:
127
501
   case GL_RGBA16:
128
 
      rb->Format = _dri_texformat_argb8888;
129
 
      rb->DataType = GL_UNSIGNED_BYTE;
 
502
      rb->Format = _radeon_texformat_argb8888;
130
503
      cpp = 4;
131
504
      break;
132
505
   case GL_STENCIL_INDEX:
136
509
   case GL_STENCIL_INDEX16_EXT:
137
510
      /* alloc a depth+stencil buffer */
138
511
      rb->Format = MESA_FORMAT_S8_Z24;
139
 
      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
140
512
      cpp = 4;
141
513
      break;
142
514
   case GL_DEPTH_COMPONENT16:
143
515
      rb->Format = MESA_FORMAT_Z16;
144
 
      rb->DataType = GL_UNSIGNED_SHORT;
145
516
      cpp = 2;
146
517
      break;
147
518
   case GL_DEPTH_COMPONENT:
148
519
   case GL_DEPTH_COMPONENT24:
149
520
   case GL_DEPTH_COMPONENT32:
150
521
      rb->Format = MESA_FORMAT_X8_Z24;
151
 
      rb->DataType = GL_UNSIGNED_INT;
152
522
      cpp = 4;
153
523
      break;
154
524
   case GL_DEPTH_STENCIL_EXT:
155
525
   case GL_DEPTH24_STENCIL8_EXT:
156
526
      rb->Format = MESA_FORMAT_S8_Z24;
157
 
      rb->DataType = GL_UNSIGNED_INT_24_8_EXT;
158
527
      cpp = 4;
159
528
      break;
160
529
   default:
170
539
 
171
540
  if (rrb->bo)
172
541
    radeon_bo_unref(rrb->bo);
173
 
  
174
 
    
175
 
   if (software_buffer) {
176
 
      return _mesa_soft_renderbuffer_storage(ctx, rb, internalFormat,
177
 
                                             width, height);
178
 
   }
179
 
   else {
180
 
     uint32_t size;
181
 
     uint32_t pitch = ((cpp * width + 63) & ~63) / cpp;
182
 
 
183
 
     if (RADEON_DEBUG & RADEON_MEMORY)
184
 
             fprintf(stderr,"Allocating %d x %d radeon RBO (pitch %d)\n", width,
185
 
                     height, pitch);
186
 
 
187
 
     size = pitch * height * cpp;
188
 
     rrb->pitch = pitch * cpp;
189
 
     rrb->cpp = cpp;
190
 
     rrb->bo = radeon_bo_open(radeon->radeonScreen->bom,
191
 
                              0,
192
 
                              size,
193
 
                              0,
194
 
                              RADEON_GEM_DOMAIN_VRAM,
195
 
                              0);
196
 
     rb->Width = width;
197
 
     rb->Height = height;
198
 
       return GL_TRUE;
199
 
   }    
200
 
   
 
542
 
 
543
   pitch = ((cpp * width + 63) & ~63) / cpp;
 
544
 
 
545
   if (RADEON_DEBUG & RADEON_MEMORY)
 
546
      fprintf(stderr,"Allocating %d x %d radeon RBO (pitch %d)\n", width,
 
547
              height, pitch);
 
548
 
 
549
   size = pitch * height * cpp;
 
550
   rrb->pitch = pitch * cpp;
 
551
   rrb->cpp = cpp;
 
552
   rrb->bo = radeon_bo_open(radeon->radeonScreen->bom,
 
553
                            0,
 
554
                            size,
 
555
                            0,
 
556
                            RADEON_GEM_DOMAIN_VRAM,
 
557
                            0);
 
558
   rb->Width = width;
 
559
   rb->Height = height;
 
560
   return GL_TRUE;
201
561
}
202
562
 
203
563
#if FEATURE_OES_EGL_image
237
597
   rb->Width = image->width;
238
598
   rb->Height = image->height;
239
599
   rb->Format = image->format;
240
 
   rb->DataType = image->data_type;
241
600
   rb->_BaseFormat = _mesa_base_fbo_format(radeon->glCtx,
242
601
                                           image->internal_format);
243
602
}
286
645
 
287
646
   /* Make sure all window system renderbuffers are up to date */
288
647
   for (i = 0; i < 2; i++) {
289
 
      struct gl_renderbuffer *rb = &radeon_fb->color_rb[i]->base;
 
648
      struct gl_renderbuffer *rb = &radeon_fb->color_rb[i]->base.Base;
290
649
 
291
650
      /* only resize if size is changing */
292
651
      if (rb && (rb->Width != width || rb->Height != height)) {
314
673
radeon_create_renderbuffer(gl_format format, __DRIdrawable *driDrawPriv)
315
674
{
316
675
    struct radeon_renderbuffer *rrb;
 
676
    struct gl_renderbuffer *rb;
317
677
 
318
678
    rrb = CALLOC_STRUCT(radeon_renderbuffer);
319
679
 
324
684
    if (!rrb)
325
685
        return NULL;
326
686
 
327
 
    _mesa_init_renderbuffer(&rrb->base, 0);
328
 
    rrb->base.ClassID = RADEON_RB_CLASS;
329
 
 
330
 
    rrb->base.Format = format;
331
 
 
332
 
    switch (format) {
333
 
        case MESA_FORMAT_RGB565:
334
 
            assert(_mesa_little_endian());
335
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
336
 
            rrb->base._BaseFormat = GL_RGB;
337
 
            break;
338
 
        case MESA_FORMAT_RGB565_REV:
339
 
            assert(!_mesa_little_endian());
340
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
341
 
            rrb->base._BaseFormat = GL_RGB;
342
 
            break;
343
 
        case MESA_FORMAT_XRGB8888:
344
 
            assert(_mesa_little_endian());
345
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
346
 
            rrb->base._BaseFormat = GL_RGB;
347
 
            break;
348
 
        case MESA_FORMAT_XRGB8888_REV:
349
 
            assert(!_mesa_little_endian());
350
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
351
 
            rrb->base._BaseFormat = GL_RGB;
352
 
            break;
353
 
        case MESA_FORMAT_ARGB8888:
354
 
            assert(_mesa_little_endian());
355
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
356
 
            rrb->base._BaseFormat = GL_RGBA;
357
 
            break;
358
 
        case MESA_FORMAT_ARGB8888_REV:
359
 
            assert(!_mesa_little_endian());
360
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
361
 
            rrb->base._BaseFormat = GL_RGBA;
362
 
            break;
363
 
        case MESA_FORMAT_S8:
364
 
            rrb->base.DataType = GL_UNSIGNED_BYTE;
365
 
            rrb->base._BaseFormat = GL_STENCIL_INDEX;
366
 
            break;
367
 
        case MESA_FORMAT_Z16:
368
 
            rrb->base.DataType = GL_UNSIGNED_SHORT;
369
 
            rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
370
 
            break;
371
 
        case MESA_FORMAT_X8_Z24:
372
 
            rrb->base.DataType = GL_UNSIGNED_INT;
373
 
            rrb->base._BaseFormat = GL_DEPTH_COMPONENT;
374
 
            break;
375
 
        case MESA_FORMAT_S8_Z24:
376
 
            rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
377
 
            rrb->base._BaseFormat = GL_DEPTH_STENCIL;
378
 
            break;
379
 
        default:
380
 
            fprintf(stderr, "%s: Unknown format %s\n",
381
 
                    __FUNCTION__, _mesa_get_format_name(format));
382
 
            _mesa_delete_renderbuffer(&rrb->base);
383
 
            return NULL;
384
 
    }
 
687
    rb = &rrb->base.Base;
 
688
 
 
689
    _mesa_init_renderbuffer(rb, 0);
 
690
    rb->ClassID = RADEON_RB_CLASS;
 
691
    rb->Format = format;
 
692
    rb->_BaseFormat = _mesa_get_format_base_format(format);
 
693
    rb->InternalFormat = _mesa_get_format_base_format(format);
385
694
 
386
695
    rrb->dPriv = driDrawPriv;
387
 
    rrb->base.InternalFormat = _mesa_get_format_base_format(format);
388
696
 
389
 
    rrb->base.Delete = radeon_delete_renderbuffer;
390
 
    rrb->base.AllocStorage = radeon_alloc_window_storage;
391
 
    rrb->base.GetPointer = radeon_get_pointer;
 
697
    rb->Delete = radeon_delete_renderbuffer;
 
698
    rb->AllocStorage = radeon_alloc_window_storage;
392
699
 
393
700
    rrb->bo = NULL;
394
701
    return rrb;
398
705
radeon_new_renderbuffer(struct gl_context * ctx, GLuint name)
399
706
{
400
707
  struct radeon_renderbuffer *rrb;
 
708
  struct gl_renderbuffer *rb;
 
709
 
401
710
 
402
711
  rrb = CALLOC_STRUCT(radeon_renderbuffer);
403
712
 
408
717
  if (!rrb)
409
718
    return NULL;
410
719
 
411
 
  _mesa_init_renderbuffer(&rrb->base, name);
412
 
  rrb->base.ClassID = RADEON_RB_CLASS;
413
 
 
414
 
  rrb->base.Delete = radeon_delete_renderbuffer;
415
 
  rrb->base.AllocStorage = radeon_alloc_renderbuffer_storage;
416
 
  rrb->base.GetPointer = radeon_get_pointer;
417
 
 
418
 
  return &rrb->base;
 
720
  rb = &rrb->base.Base;
 
721
 
 
722
  _mesa_init_renderbuffer(rb, name);
 
723
  rb->ClassID = RADEON_RB_CLASS;
 
724
  rb->Delete = radeon_delete_renderbuffer;
 
725
  rb->AllocStorage = radeon_alloc_renderbuffer_storage;
 
726
 
 
727
  return rb;
419
728
}
420
729
 
421
730
static void
456
765
radeon_update_wrapper(struct gl_context *ctx, struct radeon_renderbuffer *rrb, 
457
766
                     struct gl_texture_image *texImage)
458
767
{
 
768
        struct gl_renderbuffer *rb = &rrb->base.Base;
 
769
 
459
770
        radeon_print(RADEON_TEXTURE, RADEON_TRACE,
460
771
                "%s(%p, rrb %p, texImage %p, texFormat %s) \n",
461
772
                __func__, ctx, rrb, texImage, _mesa_get_format_name(texImage->TexFormat));
462
773
 
463
 
        switch (texImage->TexFormat) {
464
 
                case MESA_FORMAT_RGBA8888:
465
 
                case MESA_FORMAT_RGBA8888_REV:
466
 
                case MESA_FORMAT_ARGB8888:
467
 
                case MESA_FORMAT_ARGB8888_REV:
468
 
                case MESA_FORMAT_XRGB8888:
469
 
                case MESA_FORMAT_XRGB8888_REV:
470
 
                case MESA_FORMAT_RGB565:
471
 
                case MESA_FORMAT_RGB565_REV:
472
 
                case MESA_FORMAT_RGBA5551:
473
 
                case MESA_FORMAT_ARGB1555:
474
 
                case MESA_FORMAT_ARGB1555_REV:
475
 
                case MESA_FORMAT_ARGB4444:
476
 
                case MESA_FORMAT_ARGB4444_REV:
477
 
                        rrb->base.DataType = GL_UNSIGNED_BYTE;
478
 
                        break;
479
 
                case MESA_FORMAT_Z16:
480
 
                        rrb->base.DataType = GL_UNSIGNED_SHORT;
481
 
                        break;
482
 
                case MESA_FORMAT_X8_Z24:
483
 
                        rrb->base.DataType = GL_UNSIGNED_INT;
484
 
                        break;
485
 
                case MESA_FORMAT_S8_Z24:
486
 
                        rrb->base.DataType = GL_UNSIGNED_INT_24_8_EXT;
487
 
                        break;
488
 
                default:
489
 
                        _mesa_problem(ctx, "Unexpected texture format in radeon_update_wrapper()");
490
 
        }
491
 
                
492
774
        rrb->cpp = _mesa_get_format_bytes(texImage->TexFormat);
493
775
        rrb->pitch = texImage->Width * rrb->cpp;
494
 
        rrb->base.Format = texImage->TexFormat;
495
 
        rrb->base.InternalFormat = texImage->InternalFormat;
496
 
        rrb->base._BaseFormat = _mesa_base_fbo_format(ctx, rrb->base.InternalFormat);
497
 
        rrb->base.Width = texImage->Width;
498
 
        rrb->base.Height = texImage->Height;
499
 
        rrb->base.Delete = radeon_delete_renderbuffer;
500
 
        rrb->base.AllocStorage = radeon_nop_alloc_storage;
 
776
        rb->Format = texImage->TexFormat;
 
777
        rb->InternalFormat = texImage->InternalFormat;
 
778
        rb->_BaseFormat = _mesa_base_fbo_format(ctx, rb->InternalFormat);
 
779
        rb->Width = texImage->Width;
 
780
        rb->Height = texImage->Height;
 
781
        rb->Delete = radeon_delete_renderbuffer;
 
782
        rb->AllocStorage = radeon_nop_alloc_storage;
501
783
 
502
784
        return GL_TRUE;
503
785
}
521
803
      return NULL;
522
804
   }
523
805
 
524
 
   _mesa_init_renderbuffer(&rrb->base, name);
525
 
   rrb->base.ClassID = RADEON_RB_CLASS;
 
806
   _mesa_init_renderbuffer(&rrb->base.Base, name);
 
807
   rrb->base.Base.ClassID = RADEON_RB_CLASS;
526
808
 
527
809
   if (!radeon_update_wrapper(ctx, rrb, texImage)) {
528
810
      free(rrb);
553
835
 
554
836
   radeon_image = (radeon_texture_image *)newImage;
555
837
 
556
 
   if (!radeon_image->mt || newImage->Border != 0) {
 
838
   if (!radeon_image->mt) {
557
839
      /* Fallback on drawing to a texture without a miptree.
558
840
       */
559
841
      _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
564
846
      rrb = radeon_wrap_texture(ctx, newImage);
565
847
      if (rrb) {
566
848
         /* bind the wrapper to the attachment point */
567
 
         _mesa_reference_renderbuffer(&att->Renderbuffer, &rrb->base);
 
849
         _mesa_reference_renderbuffer(&att->Renderbuffer, &rrb->base.Base);
568
850
      }
569
851
      else {
570
852
         /* fallback to software rendering */
582
864
   DBG("Begin render texture tid %lx tex=%u w=%d h=%d refcount=%d\n",
583
865
       _glthread_GetID(),
584
866
       att->Texture->Name, newImage->Width, newImage->Height,
585
 
       rrb->base.RefCount);
 
867
       rrb->base.Base.RefCount);
586
868
 
587
869
   /* point the renderbufer's region to the texture image region */
588
870
   if (rrb->bo != radeon_image->mt->bo) {
607
889
    * the image we are rendering to */
608
890
   rrb->draw_offset = imageOffset;
609
891
   rrb->pitch = radeon_image->mt->levels[att->TextureLevel].rowstride;
 
892
   radeon_image->used_as_render_target = GL_TRUE;
610
893
 
611
894
   /* update drawing region, etc */
612
895
   radeon_draw_buffer(ctx, fb);
616
899
radeon_finish_render_texture(struct gl_context * ctx,
617
900
                            struct gl_renderbuffer_attachment *att)
618
901
{
 
902
    struct gl_texture_object *tex_obj = att->Texture;
 
903
    struct gl_texture_image *image =
 
904
        tex_obj->Image[att->CubeMapFace][att->TextureLevel];
 
905
    radeon_texture_image *radeon_image = (radeon_texture_image *)image;
 
906
    
 
907
    if (radeon_image)
 
908
        radeon_image->used_as_render_target = GL_FALSE;
619
909
 
 
910
    if (ctx->Driver.Flush)
 
911
        ctx->Driver.Flush(ctx); /* +r6/r7 */
620
912
}
621
913
static void
622
914
radeon_validate_framebuffer(struct gl_context *ctx, struct gl_framebuffer *fb)
657
949
#if FEATURE_EXT_framebuffer_object
658
950
  radeon->glCtx->Driver.NewFramebuffer = radeon_new_framebuffer;
659
951
  radeon->glCtx->Driver.NewRenderbuffer = radeon_new_renderbuffer;
 
952
  radeon->glCtx->Driver.MapRenderbuffer = radeon_map_renderbuffer;
 
953
  radeon->glCtx->Driver.UnmapRenderbuffer = radeon_unmap_renderbuffer;
660
954
  radeon->glCtx->Driver.BindFramebuffer = radeon_bind_framebuffer;
661
955
  radeon->glCtx->Driver.FramebufferRenderbuffer = radeon_framebuffer_renderbuffer;
662
956
  radeon->glCtx->Driver.RenderTexture = radeon_render_texture;