From a6154c00c64932332e8f6e334661ffd579cfd894 Mon Sep 17 00:00:00 2001 From: Alex Deucher Date: Thu, 16 Jun 2011 12:48:43 -0400 Subject: dri2/eg+: fix size and alignment of depth/stencil buffers Base alignment may be 256B or 512B depending on the group size. Also need to check against front size for virtualX. Signed-off-by: Alex Deucher --- src/radeon_dri2.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/radeon_dri2.c b/src/radeon_dri2.c index bbe1a94e..9bb5f397 100644 --- a/src/radeon_dri2.c +++ b/src/radeon_dri2.c @@ -83,6 +83,7 @@ radeon_dri2_create_buffers(DrawablePtr drawable, int i, r, need_enlarge = 0; int flags = 0; unsigned front_width; + uint32_t tiling = 0; pixmap = screen->GetScreenPixmap(screen); front_width = pixmap->drawable.width; @@ -148,17 +149,34 @@ radeon_dri2_create_buffers(DrawablePtr drawable, flags = 0; } + if (flags & RADEON_CREATE_PIXMAP_TILING_MICRO) + tiling |= RADEON_TILING_MICRO; + if (flags & RADEON_CREATE_PIXMAP_TILING_MICRO) + tiling |= RADEON_TILING_MACRO; + if (need_enlarge) { /* evergreen uses separate allocations for depth and stencil * so we make an extra large depth buffer to cover stencil * as well. */ - int pitch = drawable->width * (drawable->depth / 8); - int aligned_height = (drawable->height + 7) & ~7; - int size = pitch * aligned_height; - size = (size + 255) & ~255; - size += drawable->width * aligned_height; - aligned_height = ((size / pitch) + 7) & ~7; + unsigned aligned_width = drawable->width; + unsigned width_align = drmmode_get_pitch_align(pScrn, drawable->depth / 8, tiling); + unsigned aligned_height; + unsigned height_align = drmmode_get_height_align(pScrn, tiling); + unsigned base_align = drmmode_get_base_align(pScrn, drawable->depth / 8, tiling); + unsigned pitch_bytes; + unsigned size; + + if (aligned_width == front_width) + aligned_width = pScrn->virtualX; + aligned_width = RADEON_ALIGN(aligned_width, width_align); + pitch_bytes = aligned_width * (drawable->depth / 8); + aligned_height = RADEON_ALIGN(drawable->height, height_align); + size = pitch_bytes * aligned_height; + size = RADEON_ALIGN(size, base_align); + /* add additional size for stencil */ + size += aligned_width * aligned_height; + aligned_height = RADEON_ALIGN(size / pitch_bytes, height_align); pixmap = (*pScreen->CreatePixmap)(pScreen, drawable->width, @@ -217,6 +235,7 @@ radeon_dri2_create_buffer(DrawablePtr drawable, int r, need_enlarge = 0; int flags; unsigned front_width; + uint32_t tiling = 0; pixmap = pScreen->GetScreenPixmap(pScreen); front_width = pixmap->drawable.width; @@ -282,18 +301,35 @@ radeon_dri2_create_buffer(DrawablePtr drawable, flags = 0; } + if (flags & RADEON_CREATE_PIXMAP_TILING_MICRO) + tiling |= RADEON_TILING_MICRO; + if (flags & RADEON_CREATE_PIXMAP_TILING_MICRO) + tiling |= RADEON_TILING_MACRO; + if (need_enlarge) { /* evergreen uses separate allocations for depth and stencil * so we make an extra large depth buffer to cover stencil * as well. */ int depth = (format != 0) ? format : drawable->depth; - int pitch = drawable->width * (depth / 8); - int aligned_height = (drawable->height + 7) & ~7; - int size = pitch * aligned_height; - size = (size + 255) & ~255; - size += drawable->width * aligned_height; - aligned_height = ((size / pitch) + 7) & ~7; + unsigned aligned_width = drawable->width; + unsigned width_align = drmmode_get_pitch_align(pScrn, drawable->depth / 8, tiling); + unsigned aligned_height; + unsigned height_align = drmmode_get_height_align(pScrn, tiling); + unsigned base_align = drmmode_get_base_align(pScrn, drawable->depth / 8, tiling); + unsigned pitch_bytes; + unsigned size; + + if (aligned_width == front_width) + aligned_width = pScrn->virtualX; + aligned_width = RADEON_ALIGN(aligned_width, width_align); + pitch_bytes = aligned_width * (depth / 8); + aligned_height = RADEON_ALIGN(drawable->height, height_align); + size = pitch_bytes * aligned_height; + size = RADEON_ALIGN(size, base_align); + /* add additional size for stencil */ + size += aligned_width * aligned_height; + aligned_height = RADEON_ALIGN(size / pitch_bytes, height_align); pixmap = (*pScreen->CreatePixmap)(pScreen, drawable->width, -- cgit v1.2.3