210
static inline GLint r600_log2(GLint n)
219
static inline GLint r600_2d_tile_helper(const struct radeon_renderbuffer * rrb,
220
GLint x, GLint y, GLint is_depth, GLint is_stencil)
222
GLint group_bytes = rrb->group_bytes;
223
GLint num_channels = rrb->num_channels;
224
GLint num_banks = rrb->num_banks;
225
GLint r7xx_bank_op = rrb->r7xx_bank_op;
227
GLint group_bits = r600_log2(group_bytes);
228
GLint channel_bits = r600_log2(num_channels);
229
GLint bank_bits = r600_log2(num_banks);
230
GLint element_bytes = rrb->cpp;
231
GLint num_samples = 1;
232
GLint tile_width = 8;
233
GLint tile_height = 8;
234
GLint tile_thickness = 1;
235
GLint macro_tile_width = num_banks;
236
GLint macro_tile_height = num_channels;
237
GLint pitch_elements = (rrb->pitch / element_bytes) / tile_width;
238
GLint height = rrb->base.Height / tile_height;
240
GLint sample_number = 0;
243
GLint macro_tile_bytes;
244
GLint macro_tiles_per_row;
245
GLint macro_tiles_per_slice;
247
GLint macro_tile_row_index;
248
GLint macro_tile_column_index;
249
GLint macro_tile_offset;
250
GLint pixel_number = 0;
251
GLint element_offset;
255
GLint group_mask = (1 << group_bits) - 1;
260
switch (num_channels) {
263
// channel[0] = x[3] ^ y[3]
264
channel |= (((x >> 3) ^ (y >> 3)) & 1) << 0;
267
// channel[0] = x[4] ^ y[3]
268
channel |= (((x >> 4) ^ (y >> 3)) & 1) << 0;
269
// channel[1] = x[3] ^ y[4]
270
channel |= (((x >> 3) ^ (y >> 4)) & 1) << 1;
273
// channel[0] = x[5] ^ y[3]
274
channel |= (((x >> 5) ^ (y >> 3)) & 1) << 0;
275
// channel[0] = x[4] ^ x[5] ^ y[4]
276
channel |= (((x >> 4) ^ (x >> 5) ^ (y >> 4)) & 1) << 1;
277
// channel[0] = x[3] ^ y[5]
278
channel |= (((x >> 3) ^ (y >> 5)) & 1) << 2;
284
// bank[0] = x[3] ^ y[4 + log2(num_channels)]
285
bank |= (((x >> 3) ^ (y >> (4 + channel_bits))) & 1) << 0;
287
// bank[1] = x[3] ^ y[4 + log2(num_channels)] ^ x[5]
288
bank |= (((x >> 4) ^ (y >> (3 + channel_bits)) ^ (x >> 5)) & 1) << 1;
290
// bank[1] = x[4] ^ y[3 + log2(num_channels)]
291
bank |= (((x >> 4) ^ (y >> (3 + channel_bits))) & 1) << 1;
294
// bank[0] = x[3] ^ y[5 + log2(num_channels)]
295
bank |= (((x >> 3) ^ (y >> (5 + channel_bits))) & 1) << 0;
296
// bank[1] = x[4] ^ y[4 + log2(num_channels)] ^ y[5 + log2(num_channels)]
297
bank |= (((x >> 4) ^ (y >> (4 + channel_bits)) ^ (y >> (5 + channel_bits))) & 1) << 1;
299
// bank[2] = x[5] ^ y[3 + log2(num_channels)] ^ x[6]
300
bank |= (((x >> 5) ^ (y >> (3 + channel_bits)) ^ (x >> 6)) & 1) << 2;
302
// bank[2] = x[5] ^ y[3 + log2(num_channels)]
303
bank |= (((x >> 5) ^ (y >> (3 + channel_bits))) & 1) << 2;
307
tile_bytes = tile_width * tile_height * tile_thickness * element_bytes * num_samples;
308
macro_tile_bytes = macro_tile_width * macro_tile_height * tile_bytes;
309
macro_tiles_per_row = pitch_elements / macro_tile_width;
310
macro_tiles_per_slice = macro_tiles_per_row * (height / macro_tile_height);
311
slice_offset = (z / tile_thickness) * macro_tiles_per_slice * macro_tile_bytes;
312
macro_tile_row_index = (y / tile_height) / macro_tile_height;
313
macro_tile_column_index = (x / tile_width) / macro_tile_width;
314
macro_tile_offset = ((macro_tile_row_index * macro_tiles_per_row) + macro_tile_column_index) * macro_tile_bytes;
317
GLint pixel_offset = 0;
319
pixel_number |= ((x >> 0) & 1) << 0; // pn[0] = x[0]
320
pixel_number |= ((y >> 0) & 1) << 1; // pn[1] = y[0]
321
pixel_number |= ((x >> 1) & 1) << 2; // pn[2] = x[1]
322
pixel_number |= ((y >> 1) & 1) << 3; // pn[3] = y[1]
323
pixel_number |= ((x >> 2) & 1) << 4; // pn[4] = x[2]
324
pixel_number |= ((y >> 2) & 1) << 5; // pn[5] = y[2]
325
switch (element_bytes) {
327
pixel_offset = pixel_number * element_bytes * num_samples;
330
/* stencil and depth data are stored separately within a tile.
331
* stencil is stored in a contiguous tile before the depth tile.
332
* stencil element is 1 byte, depth element is 3 bytes.
333
* stencil tile is 64 bytes.
336
pixel_offset = pixel_number * 1 * num_samples;
338
pixel_offset = (pixel_number * 3 * num_samples) + 64;
341
element_offset = pixel_offset + (sample_number * element_bytes);
345
switch (element_bytes) {
347
pixel_number |= ((x >> 0) & 1) << 0; // pn[0] = x[0]
348
pixel_number |= ((x >> 1) & 1) << 1; // pn[1] = x[1]
349
pixel_number |= ((x >> 2) & 1) << 2; // pn[2] = x[2]
350
pixel_number |= ((y >> 1) & 1) << 3; // pn[3] = y[1]
351
pixel_number |= ((y >> 0) & 1) << 4; // pn[4] = y[0]
352
pixel_number |= ((y >> 2) & 1) << 5; // pn[5] = y[2]
355
pixel_number |= ((x >> 0) & 1) << 0; // pn[0] = x[0]
356
pixel_number |= ((x >> 1) & 1) << 1; // pn[1] = x[1]
357
pixel_number |= ((x >> 2) & 1) << 2; // pn[2] = x[2]
358
pixel_number |= ((y >> 0) & 1) << 3; // pn[3] = y[0]
359
pixel_number |= ((y >> 1) & 1) << 4; // pn[4] = y[1]
360
pixel_number |= ((y >> 2) & 1) << 5; // pn[5] = y[2]
363
pixel_number |= ((x >> 0) & 1) << 0; // pn[0] = x[0]
364
pixel_number |= ((x >> 1) & 1) << 1; // pn[1] = x[1]
365
pixel_number |= ((y >> 0) & 1) << 2; // pn[2] = y[0]
366
pixel_number |= ((x >> 2) & 1) << 3; // pn[3] = x[2]
367
pixel_number |= ((y >> 1) & 1) << 4; // pn[4] = y[1]
368
pixel_number |= ((y >> 2) & 1) << 5; // pn[5] = y[2]
371
sample_offset = sample_number * (tile_bytes / num_samples);
372
element_offset = sample_offset + (pixel_number * element_bytes);
374
total_offset = (slice_offset + macro_tile_offset) >> (channel_bits + bank_bits);
375
total_offset += element_offset;
377
offset_low = total_offset & group_mask;
378
offset_high = (total_offset & ~group_mask) << (channel_bits + bank_bits);
379
offset = (bank << (group_bits + channel_bits)) + (channel << group_bits) + offset_low + offset_high;
211
384
/* depth buffers */
212
385
static GLubyte *r600_ptr_depth(const struct radeon_renderbuffer * rrb,
213
386
GLint x, GLint y)
215
388
GLubyte *ptr = rrb->bo->ptr;
216
GLint offset = r600_1d_tile_helper(rrb, x, y, 1, 0);
390
if (rrb->bo->flags & RADEON_BO_FLAGS_MACRO_TILE)
391
offset = r600_2d_tile_helper(rrb, x, y, 1, 0);
393
offset = r600_1d_tile_helper(rrb, x, y, 1, 0);
217
394
return &ptr[offset];