Re: [Mesa-dev] [PATCH 3/3] st/mesa: don't allocate bitmap drawing state until needed
On 08.02.2016 12:07, Brian Paul wrote: Most apps don't use glBitmap so don't allocate the bitmap cache or gallium state objects/shaders/etc until the first call to st_Bitmap(). --- src/mesa/state_tracker/st_cb_bitmap.c | 145 ++ src/mesa/state_tracker/st_cb_bitmap.h | 3 - src/mesa/state_tracker/st_context.c | 1 - 3 files changed, 77 insertions(+), 72 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index c26ee7f..ca1dfab 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -497,8 +497,9 @@ create_cache_trans(struct st_context *st) void st_flush_bitmap_cache(struct st_context *st) { - if (!st->bitmap.cache->empty) { - struct bitmap_cache *cache = st->bitmap.cache; + struct bitmap_cache *cache = st->bitmap.cache; + + if (cache && !st->bitmap.cache->empty) { struct pipe_context *pipe = st->pipe; struct pipe_sampler_view *sv; @@ -617,6 +618,76 @@ accum_bitmap(struct gl_context *ctx, } +/** + * One-time init for drawing bitmaps. + */ +static void +init_bitmap_state(struct st_context *st) +{ + struct pipe_sampler_state *sampler = >bitmap.samplers[0]; + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + + /* This function should only be called once */ + assert(st->bitmap.cache == NULL); + + /* alloc bitmap cache object */ + st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); What if the allocation fails? I know the old code didn't check this either, but... Apart from this and the comment by Gustaw, the series is Reviewed-by: Nicolai Hähnle+ + /* init sampler state once */ + memset(sampler, 0, sizeof(*sampler)); + sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; + sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; + st->bitmap.samplers[1] = *sampler; + st->bitmap.samplers[1].normalized_coords = 1; + + /* init baseline rasterizer state once */ + memset(>bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); + st->bitmap.rasterizer.half_pixel_center = 1; + st->bitmap.rasterizer.bottom_edge_rule = 1; + st->bitmap.rasterizer.depth_clip = 1; + + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, +PIPE_TEXTURE_2D, 0, +PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, +PIPE_TEXTURE_2D, 0, +PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; + } + else { + /* XXX support more formats */ + assert(0); + } + + /* Create the vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR, +st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0, 0 }; + st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, + semantic_names, + semantic_indexes, + FALSE); + } + + reset_cache(st); +} + /** * Called via ctx->Driver.Bitmap() @@ -632,6 +703,10 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, assert(width > 0); assert(height > 0); + if (!st->bitmap.cache) { + init_bitmap_state(st); + } + /* We only need to validate state of the st dirty flags are set or * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use * for bitmap drawing uses no constants and the FS constants are @@ -641,19 +716,6 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, st_validate_state(st); } - if (!st->bitmap.vs) { - /* create pass-through vertex shader now */ - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_COLOR, -st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : - TGSI_SEMANTIC_GENERIC }; - const uint semantic_indexes[] = { 0, 0, 0 }; - st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe,
[Mesa-dev] [PATCH 3/3] st/mesa: don't allocate bitmap drawing state until needed
Most apps don't use glBitmap so don't allocate the bitmap cache or gallium state objects/shaders/etc until the first call to st_Bitmap(). --- src/mesa/state_tracker/st_cb_bitmap.c | 145 ++ src/mesa/state_tracker/st_cb_bitmap.h | 3 - src/mesa/state_tracker/st_context.c | 1 - 3 files changed, 77 insertions(+), 72 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index c26ee7f..ca1dfab 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -497,8 +497,9 @@ create_cache_trans(struct st_context *st) void st_flush_bitmap_cache(struct st_context *st) { - if (!st->bitmap.cache->empty) { - struct bitmap_cache *cache = st->bitmap.cache; + struct bitmap_cache *cache = st->bitmap.cache; + + if (cache && !st->bitmap.cache->empty) { struct pipe_context *pipe = st->pipe; struct pipe_sampler_view *sv; @@ -617,6 +618,76 @@ accum_bitmap(struct gl_context *ctx, } +/** + * One-time init for drawing bitmaps. + */ +static void +init_bitmap_state(struct st_context *st) +{ + struct pipe_sampler_state *sampler = >bitmap.samplers[0]; + struct pipe_context *pipe = st->pipe; + struct pipe_screen *screen = pipe->screen; + + /* This function should only be called once */ + assert(st->bitmap.cache == NULL); + + /* alloc bitmap cache object */ + st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); + + /* init sampler state once */ + memset(sampler, 0, sizeof(*sampler)); + sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; + sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; + sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; + sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; + sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; + st->bitmap.samplers[1] = *sampler; + st->bitmap.samplers[1].normalized_coords = 1; + + /* init baseline rasterizer state once */ + memset(>bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); + st->bitmap.rasterizer.half_pixel_center = 1; + st->bitmap.rasterizer.bottom_edge_rule = 1; + st->bitmap.rasterizer.depth_clip = 1; + + /* find a usable texture format */ + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, + PIPE_TEXTURE_2D, 0, + PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, +PIPE_TEXTURE_2D, 0, +PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; + } + else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, +PIPE_TEXTURE_2D, 0, +PIPE_BIND_SAMPLER_VIEW)) { + st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; + } + else { + /* XXX support more formats */ + assert(0); + } + + /* Create the vertex shader */ + { + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, + TGSI_SEMANTIC_COLOR, +st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : + TGSI_SEMANTIC_GENERIC }; + const uint semantic_indexes[] = { 0, 0, 0 }; + st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, + semantic_names, + semantic_indexes, + FALSE); + } + + reset_cache(st); +} + /** * Called via ctx->Driver.Bitmap() @@ -632,6 +703,10 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, assert(width > 0); assert(height > 0); + if (!st->bitmap.cache) { + init_bitmap_state(st); + } + /* We only need to validate state of the st dirty flags are set or * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use * for bitmap drawing uses no constants and the FS constants are @@ -641,19 +716,6 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, st_validate_state(st); } - if (!st->bitmap.vs) { - /* create pass-through vertex shader now */ - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, - TGSI_SEMANTIC_COLOR, -st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : - TGSI_SEMANTIC_GENERIC }; - const uint semantic_indexes[] = { 0, 0, 0 }; - st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, - semantic_names, - semantic_indexes, - FALSE); - } - if (UseBitmapCache &&
Re: [Mesa-dev] [PATCH 3/3] st/mesa: don't allocate bitmap drawing state until needed
2016-02-08 18:07 GMT+01:00 Brian Paul: > Most apps don't use glBitmap so don't allocate the bitmap cache or > gallium state objects/shaders/etc until the first call to st_Bitmap(). > --- > src/mesa/state_tracker/st_cb_bitmap.c | 145 > ++ > src/mesa/state_tracker/st_cb_bitmap.h | 3 - > src/mesa/state_tracker/st_context.c | 1 - > 3 files changed, 77 insertions(+), 72 deletions(-) > > diff --git a/src/mesa/state_tracker/st_cb_bitmap.c > b/src/mesa/state_tracker/st_cb_bitmap.c > index c26ee7f..ca1dfab 100644 > --- a/src/mesa/state_tracker/st_cb_bitmap.c > +++ b/src/mesa/state_tracker/st_cb_bitmap.c > @@ -497,8 +497,9 @@ create_cache_trans(struct st_context *st) > void > st_flush_bitmap_cache(struct st_context *st) > { > - if (!st->bitmap.cache->empty) { > - struct bitmap_cache *cache = st->bitmap.cache; > + struct bitmap_cache *cache = st->bitmap.cache; > + > + if (cache && !st->bitmap.cache->empty) { Maybe do the following: if (cache && !cache->empty) { >struct pipe_context *pipe = st->pipe; >struct pipe_sampler_view *sv; > > @@ -617,6 +618,76 @@ accum_bitmap(struct gl_context *ctx, > } > > > +/** > + * One-time init for drawing bitmaps. > + */ > +static void > +init_bitmap_state(struct st_context *st) > +{ > + struct pipe_sampler_state *sampler = >bitmap.samplers[0]; > + struct pipe_context *pipe = st->pipe; > + struct pipe_screen *screen = pipe->screen; > + > + /* This function should only be called once */ > + assert(st->bitmap.cache == NULL); > + > + /* alloc bitmap cache object */ > + st->bitmap.cache = ST_CALLOC_STRUCT(bitmap_cache); > + > + /* init sampler state once */ > + memset(sampler, 0, sizeof(*sampler)); > + sampler->wrap_s = PIPE_TEX_WRAP_CLAMP; > + sampler->wrap_t = PIPE_TEX_WRAP_CLAMP; > + sampler->wrap_r = PIPE_TEX_WRAP_CLAMP; > + sampler->min_img_filter = PIPE_TEX_FILTER_NEAREST; > + sampler->min_mip_filter = PIPE_TEX_MIPFILTER_NONE; > + sampler->mag_img_filter = PIPE_TEX_FILTER_NEAREST; > + st->bitmap.samplers[1] = *sampler; > + st->bitmap.samplers[1].normalized_coords = 1; > + > + /* init baseline rasterizer state once */ > + memset(>bitmap.rasterizer, 0, sizeof(st->bitmap.rasterizer)); > + st->bitmap.rasterizer.half_pixel_center = 1; > + st->bitmap.rasterizer.bottom_edge_rule = 1; > + st->bitmap.rasterizer.depth_clip = 1; > + > + /* find a usable texture format */ > + if (screen->is_format_supported(screen, PIPE_FORMAT_I8_UNORM, > + PIPE_TEXTURE_2D, 0, > + PIPE_BIND_SAMPLER_VIEW)) { > + st->bitmap.tex_format = PIPE_FORMAT_I8_UNORM; > + } > + else if (screen->is_format_supported(screen, PIPE_FORMAT_A8_UNORM, > +PIPE_TEXTURE_2D, 0, > +PIPE_BIND_SAMPLER_VIEW)) { > + st->bitmap.tex_format = PIPE_FORMAT_A8_UNORM; > + } > + else if (screen->is_format_supported(screen, PIPE_FORMAT_L8_UNORM, > +PIPE_TEXTURE_2D, 0, > +PIPE_BIND_SAMPLER_VIEW)) { > + st->bitmap.tex_format = PIPE_FORMAT_L8_UNORM; > + } > + else { > + /* XXX support more formats */ > + assert(0); > + } > + > + /* Create the vertex shader */ > + { > + const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, > + TGSI_SEMANTIC_COLOR, > +st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : > + TGSI_SEMANTIC_GENERIC }; > + const uint semantic_indexes[] = { 0, 0, 0 }; > + st->bitmap.vs = util_make_vertex_passthrough_shader(st->pipe, 3, > + semantic_names, > + semantic_indexes, > + FALSE); > + } > + > + reset_cache(st); > +} > + > > /** > * Called via ctx->Driver.Bitmap() > @@ -632,6 +703,10 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, > assert(width > 0); > assert(height > 0); > > + if (!st->bitmap.cache) { > + init_bitmap_state(st); > + } > + > /* We only need to validate state of the st dirty flags are set or > * any non-_NEW_PROGRAM_CONSTANTS mesa flags are set. The VS we use > * for bitmap drawing uses no constants and the FS constants are > @@ -641,19 +716,6 @@ st_Bitmap(struct gl_context *ctx, GLint x, GLint y, >st_validate_state(st); > } > > - if (!st->bitmap.vs) { > - /* create pass-through vertex shader now */ > - const uint semantic_names[] = { TGSI_SEMANTIC_POSITION, > - TGSI_SEMANTIC_COLOR, > -st->needs_texcoord_semantic ? TGSI_SEMANTIC_TEXCOORD : > - TGSI_SEMANTIC_GENERIC }; > - const uint
Re: [Mesa-dev] [PATCH 3/3] st/mesa: don't allocate bitmap drawing state until needed
On 02/08/2016 10:10 AM, Gustaw Smolarczyk wrote: 2016-02-08 18:07 GMT+01:00 Brian Paul: Most apps don't use glBitmap so don't allocate the bitmap cache or gallium state objects/shaders/etc until the first call to st_Bitmap(). --- src/mesa/state_tracker/st_cb_bitmap.c | 145 ++ src/mesa/state_tracker/st_cb_bitmap.h | 3 - src/mesa/state_tracker/st_context.c | 1 - 3 files changed, 77 insertions(+), 72 deletions(-) diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index c26ee7f..ca1dfab 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -497,8 +497,9 @@ create_cache_trans(struct st_context *st) void st_flush_bitmap_cache(struct st_context *st) { - if (!st->bitmap.cache->empty) { - struct bitmap_cache *cache = st->bitmap.cache; + struct bitmap_cache *cache = st->bitmap.cache; + + if (cache && !st->bitmap.cache->empty) { Maybe do the following: if (cache && !cache->empty) { Yes. Thanks. -Brian ___ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev