From e372819589c2a66620e63a2cd11582c6ce5fb8f0 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Sat, 21 Dec 2013 21:21:24 +0800 Subject: [PATCH] ilo: refactor separate stencil allocation Move separate stencil allocation code to tex_create_separate_stencil to keep tex_create sane. --- src/gallium/drivers/ilo/ilo_resource.c | 47 +++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/gallium/drivers/ilo/ilo_resource.c b/src/gallium/drivers/ilo/ilo_resource.c index 7dd34359302..04927d8bfa4 100644 --- a/src/gallium/drivers/ilo/ilo_resource.c +++ b/src/gallium/drivers/ilo/ilo_resource.c @@ -969,6 +969,30 @@ tex_create_bo(struct ilo_texture *tex, return true; } +static bool +tex_create_separate_stencil(struct ilo_texture *tex) +{ + struct pipe_resource templ = tex->base; + struct pipe_resource *s8; + + /* + * Unless PIPE_BIND_DEPTH_STENCIL is set, the resource may have other + * tilings. But that should be fine since it will never be bound as the + * stencil buffer, and our transfer code can handle all tilings. + */ + templ.format = PIPE_FORMAT_S8_UINT; + + s8 = tex->base.screen->resource_create(tex->base.screen, &templ); + if (!s8) + return false; + + tex->separate_s8 = ilo_texture(s8); + + assert(tex->separate_s8->bo_format == PIPE_FORMAT_S8_UINT); + + return true; +} + static void tex_destroy(struct ilo_texture *tex) { @@ -1053,26 +1077,9 @@ tex_create(struct pipe_screen *screen, } /* allocate separate stencil resource */ - if (layout.separate_stencil) { - struct pipe_resource s8_templ = *layout.templ; - struct pipe_resource *s8; - - /* - * Unless PIPE_BIND_DEPTH_STENCIL is set, the resource may have other - * tilings. But that should be fine since it will never be bound as the - * stencil buffer, and our transfer code can handle all tilings. - */ - s8_templ.format = PIPE_FORMAT_S8_UINT; - - s8 = screen->resource_create(screen, &s8_templ); - if (!s8) { - tex_destroy(tex); - return NULL; - } - - tex->separate_s8 = ilo_texture(s8); - - assert(tex->separate_s8->bo_format == PIPE_FORMAT_S8_UINT); + if (layout.separate_stencil && !tex_create_separate_stencil(tex)) { + tex_destroy(tex); + return NULL; } return &tex->base; -- 2.30.2