diff options
author | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:56:54 +0000 |
---|---|---|
committer | Jonathan Gray <jsg@cvs.openbsd.org> | 2023-01-28 08:56:54 +0000 |
commit | d305570c9b1fd87c4acdec589761cfa39fd04a3b (patch) | |
tree | e340315dd9d6966ccc3a48aa7a845e2213e40e62 /lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c | |
parent | 1c5c7896c1d54abd25c0f33ca996165b359eecb3 (diff) |
Merge Mesa 22.3.4
Diffstat (limited to 'lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c')
-rw-r--r-- | lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c | 194 |
1 files changed, 95 insertions, 99 deletions
diff --git a/lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c b/lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c index dbe0cc387..7ad04fe10 100644 --- a/lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c +++ b/lib/mesa/src/gallium/drivers/llvmpipe/lp_scene.c @@ -28,19 +28,18 @@ #include "util/u_framebuffer.h" #include "util/u_math.h" #include "util/u_memory.h" +#include "util/reallocarray.h" #include "util/u_inlines.h" -#include "util/simple_list.h" #include "util/format/u_format.h" #include "lp_scene.h" #include "lp_fence.h" #include "lp_debug.h" #include "lp_context.h" #include "lp_state_fs.h" - #include "lp_setup_context.h" -#define RESOURCE_REF_SZ 32 +#define RESOURCE_REF_SZ 32 /** List of resource references */ struct resource_ref { struct pipe_resource *resource[RESOURCE_REF_SZ]; @@ -48,6 +47,7 @@ struct resource_ref { struct resource_ref *next; }; + #define SHADER_REF_SZ 32 /** List of shader variant references */ struct shader_ref { @@ -62,7 +62,7 @@ struct shader_ref { * \param queue the queue to put newly rendered/emptied scenes into */ struct lp_scene * -lp_scene_create( struct lp_setup_context *setup ) +lp_scene_create(struct lp_setup_context *setup) { struct lp_scene *scene = slab_alloc_st(&setup->scene_slab); if (!scene) @@ -102,6 +102,7 @@ lp_scene_destroy(struct lp_scene *scene) { lp_scene_end_rasterization(scene); mtx_destroy(&scene->mutex); + free(scene->tiles); assert(scene->data.head == &scene->data.first); slab_free_st(&scene->setup->scene_slab, scene); } @@ -112,12 +113,10 @@ lp_scene_destroy(struct lp_scene *scene) * For debugging purposes. */ boolean -lp_scene_is_empty(struct lp_scene *scene ) +lp_scene_is_empty(struct lp_scene *scene) { - unsigned x, y; - - for (y = 0; y < scene->tiles_y; y++) { - for (x = 0; x < scene->tiles_x; x++) { + for (unsigned y = 0; y < scene->tiles_y; y++) { + for (unsigned x = 0; x < scene->tiles_x; x++) { const struct cmd_bin *bin = lp_scene_get_bin(scene, x, y); if (bin->head) { return FALSE; @@ -155,6 +154,7 @@ lp_scene_bin_reset(struct lp_scene *scene, unsigned x, unsigned y) } } + static void init_scene_texture(struct lp_scene_surface *ssurf, struct pipe_surface *psurf) { @@ -180,8 +180,7 @@ init_scene_texture(struct lp_scene_surface *ssurf, struct pipe_surface *psurf) LP_TEX_USAGE_READ_WRITE); ssurf->format_bytes = util_format_get_blocksize(psurf->format); ssurf->nr_samples = util_res_sample_count(psurf->texture); - } - else { + } else { struct llvmpipe_resource *lpr = llvmpipe_resource(psurf->texture); unsigned pixstride = util_format_get_blocksize(psurf->format); ssurf->stride = psurf->texture->width0; @@ -194,15 +193,15 @@ init_scene_texture(struct lp_scene_surface *ssurf, struct pipe_surface *psurf) } } + void lp_scene_begin_rasterization(struct lp_scene *scene) { const struct pipe_framebuffer_state *fb = &scene->fb; - int i; //LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__); - for (i = 0; i < scene->fb.nr_cbufs; i++) { + for (unsigned i = 0; i < scene->fb.nr_cbufs; i++) { struct pipe_surface *cbuf = scene->fb.cbufs[i]; init_scene_texture(&scene->cbufs[i], cbuf); } @@ -214,13 +213,11 @@ lp_scene_begin_rasterization(struct lp_scene *scene) } - - /** * Free all the temporary data in a scene. */ void -lp_scene_end_rasterization(struct lp_scene *scene ) +lp_scene_end_rasterization(struct lp_scene *scene) { int i; @@ -248,62 +245,57 @@ lp_scene_end_rasterization(struct lp_scene *scene ) /* Reset all command lists: */ - memset(scene->tile, 0, sizeof scene->tile); + memset(scene->tiles, 0, sizeof(struct cmd_bin) * scene->num_alloced_tiles); /* Decrement texture ref counts */ - { - struct resource_ref *ref; - int i, j = 0; - - for (ref = scene->resources; ref; ref = ref->next) { - for (i = 0; i < ref->count; i++) { - if (LP_DEBUG & DEBUG_SETUP) - debug_printf("resource %d: %p %dx%d sz %d\n", - j, - (void *) ref->resource[i], - ref->resource[i]->width0, - ref->resource[i]->height0, - llvmpipe_resource_size(ref->resource[i])); - j++; - llvmpipe_resource_unmap(ref->resource[i], 0, 0); - pipe_resource_reference(&ref->resource[i], NULL); - } + int j = 0; + for (struct resource_ref *ref = scene->resources; ref; ref = ref->next) { + for (int i = 0; i < ref->count; i++) { + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("resource %d: %p %dx%d sz %d\n", + j, + (void *) ref->resource[i], + ref->resource[i]->width0, + ref->resource[i]->height0, + llvmpipe_resource_size(ref->resource[i])); + j++; + llvmpipe_resource_unmap(ref->resource[i], 0, 0); + pipe_resource_reference(&ref->resource[i], NULL); } + } - for (ref = scene->writeable_resources; ref; ref = ref->next) { - for (i = 0; i < ref->count; i++) { - if (LP_DEBUG & DEBUG_SETUP) - debug_printf("resource %d: %p %dx%d sz %d\n", - j, - (void *) ref->resource[i], - ref->resource[i]->width0, + for (struct resource_ref *ref = scene->writeable_resources; ref; + ref = ref->next) { + for (int i = 0; i < ref->count; i++) { + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("resource %d: %p %dx%d sz %d\n", + j, + (void *) ref->resource[i], + ref->resource[i]->width0, ref->resource[i]->height0, - llvmpipe_resource_size(ref->resource[i])); - j++; - llvmpipe_resource_unmap(ref->resource[i], 0, 0); - pipe_resource_reference(&ref->resource[i], NULL); - } + llvmpipe_resource_size(ref->resource[i])); + j++; + llvmpipe_resource_unmap(ref->resource[i], 0, 0); + pipe_resource_reference(&ref->resource[i], NULL); } + } - if (LP_DEBUG & DEBUG_SETUP) - debug_printf("scene %d resources, sz %d\n", - j, scene->resource_reference_size); + if (LP_DEBUG & DEBUG_SETUP) { + debug_printf("scene %d resources, sz %d\n", + j, scene->resource_reference_size); } /* Decrement shader variant ref counts */ - { - struct shader_ref *ref; - int i, j = 0; - - for (ref = scene->frag_shaders; ref; ref = ref->next) { - for (i = 0; i < ref->count; i++) { - if (LP_DEBUG & DEBUG_SETUP) - debug_printf("shader %d: %p\n", j, (void *) ref->variant[i]); - j++; - lp_fs_variant_reference(llvmpipe_context(scene->pipe), &ref->variant[i], NULL); - } + j = 0; + for (struct shader_ref *ref = scene->frag_shaders; ref; ref = ref->next) { + for (i = 0; i < ref->count; i++) { + if (LP_DEBUG & DEBUG_SETUP) + debug_printf("shader %d: %p\n", j, (void *) ref->variant[i]); + j++; + lp_fs_variant_reference(llvmpipe_context(scene->pipe), + &ref->variant[i], NULL); } } @@ -333,25 +325,20 @@ lp_scene_end_rasterization(struct lp_scene *scene ) scene->alloc_failed = FALSE; - util_unreference_framebuffer_state( &scene->fb ); + util_unreference_framebuffer_state(&scene->fb); } - - - - struct cmd_block * -lp_scene_new_cmd_block( struct lp_scene *scene, - struct cmd_bin *bin ) +lp_scene_new_cmd_block(struct lp_scene *scene, + struct cmd_bin *bin) { struct cmd_block *block = lp_scene_alloc(scene, sizeof(struct cmd_block)); if (block) { if (bin->tail) { bin->tail->next = block; bin->tail = block; - } - else { + } else { bin->head = block; bin->tail = block; } @@ -364,18 +351,17 @@ lp_scene_new_cmd_block( struct lp_scene *scene, struct data_block * -lp_scene_new_data_block( struct lp_scene *scene ) +lp_scene_new_data_block(struct lp_scene *scene) { if (scene->scene_size + DATA_BLOCK_SIZE > LP_SCENE_MAX_SIZE) { if (0) debug_printf("%s: failed\n", __FUNCTION__); scene->alloc_failed = TRUE; return NULL; - } - else { + } else { struct data_block *block = MALLOC_STRUCT(data_block); if (!block) return NULL; - + scene->scene_size += sizeof *block; block->used = 0; @@ -392,7 +378,7 @@ lp_scene_new_data_block( struct lp_scene *scene ) * This does not include resources (textures) referenced by the scene. */ static unsigned -lp_scene_data_size( const struct lp_scene *scene ) +lp_scene_data_size(const struct lp_scene *scene) { unsigned size = 0; const struct data_block *block; @@ -474,13 +460,13 @@ lp_scene_add_resource_reference(struct lp_scene *scene, /** * Add a reference to a fragment shader variant + * Return FALSE if out of memory, TRUE otherwise. */ boolean lp_scene_add_frag_shader_reference(struct lp_scene *scene, struct lp_fragment_shader_variant *variant) { struct shader_ref *ref, **last = &scene->frag_shaders; - int i; /* Look at existing resource blocks: */ @@ -489,7 +475,7 @@ lp_scene_add_frag_shader_reference(struct lp_scene *scene, /* Search for this resource: */ - for (i = 0; i < ref->count; i++) + for (int i = 0; i < ref->count; i++) if (ref->variant[i] == variant) return TRUE; @@ -514,29 +500,31 @@ lp_scene_add_frag_shader_reference(struct lp_scene *scene, /* Append the reference to the reference block. */ - lp_fs_variant_reference(llvmpipe_context(scene->pipe), &ref->variant[ref->count++], variant); + lp_fs_variant_reference(llvmpipe_context(scene->pipe), + &ref->variant[ref->count++], variant); return TRUE; } + /** * Does this scene have a reference to the given resource? + * Returns bitmask of LP_REFERENCED_FOR_READ/WRITE bits. */ unsigned lp_scene_is_resource_referenced(const struct lp_scene *scene, const struct pipe_resource *resource) { const struct resource_ref *ref; - int i; for (ref = scene->resources; ref; ref = ref->next) { - for (i = 0; i < ref->count; i++) + for (int i = 0; i < ref->count; i++) if (ref->resource[i] == resource) return LP_REFERENCED_FOR_READ; } for (ref = scene->writeable_resources; ref; ref = ref->next) { - for (i = 0; i < ref->count; i++) + for (int i = 0; i < ref->count; i++) if (ref->resource[i] == resource) return LP_REFERENCED_FOR_READ | LP_REFERENCED_FOR_WRITE; } @@ -545,8 +533,6 @@ lp_scene_is_resource_referenced(const struct lp_scene *scene, } - - /** advance curr_x,y to the next bin */ static boolean next_bin(struct lp_scene *scene) @@ -565,7 +551,7 @@ next_bin(struct lp_scene *scene) void -lp_scene_bin_iter_begin( struct lp_scene *scene ) +lp_scene_bin_iter_begin(struct lp_scene *scene) { scene->curr_x = scene->curr_y = -1; } @@ -578,7 +564,7 @@ lp_scene_bin_iter_begin( struct lp_scene *scene ) * of work (a bin) to work on. */ struct cmd_bin * -lp_scene_bin_iter_next( struct lp_scene *scene , int *x, int *y) +lp_scene_bin_iter_next(struct lp_scene *scene , int *x, int *y) { struct cmd_bin *bin = NULL; @@ -588,8 +574,7 @@ lp_scene_bin_iter_next( struct lp_scene *scene , int *x, int *y) /* first bin */ scene->curr_x = 0; scene->curr_y = 0; - } - else if (!next_bin(scene)) { + } else if (!next_bin(scene)) { /* no more bins left */ goto end; } @@ -605,12 +590,10 @@ end: } -void lp_scene_begin_binning(struct lp_scene *scene, - struct pipe_framebuffer_state *fb) +void +lp_scene_begin_binning(struct lp_scene *scene, + struct pipe_framebuffer_state *fb) { - int i; - unsigned max_layer = ~0; - assert(lp_scene_is_empty(scene)); util_copy_framebuffer_state(&scene->fb, fb); @@ -620,28 +603,40 @@ void lp_scene_begin_binning(struct lp_scene *scene, assert(scene->tiles_x <= TILES_X); assert(scene->tiles_y <= TILES_Y); + unsigned num_required_tiles = scene->tiles_x * scene->tiles_y; + if (scene->num_alloced_tiles < num_required_tiles) { + scene->tiles = reallocarray(scene->tiles, num_required_tiles, + sizeof(struct cmd_bin)); + if (!scene->tiles) + return; + memset(scene->tiles, 0, sizeof(struct cmd_bin) * num_required_tiles); + scene->num_alloced_tiles = num_required_tiles; + } + /* * Determine how many layers the fb has (used for clamping layer value). - * OpenGL (but not d3d10) permits different amount of layers per rt, however - * results are undefined if layer exceeds the amount of layers of ANY - * attachment hence don't need separate per cbuf and zsbuf max. + * OpenGL (but not d3d10) permits different amount of layers per rt, + * however results are undefined if layer exceeds the amount of layers of + * ANY attachment hence don't need separate per cbuf and zsbuf max. */ - for (i = 0; i < scene->fb.nr_cbufs; i++) { + unsigned max_layer = ~0; + for (unsigned i = 0; i < scene->fb.nr_cbufs; i++) { struct pipe_surface *cbuf = scene->fb.cbufs[i]; if (cbuf) { if (llvmpipe_resource_is_texture(cbuf->texture)) { max_layer = MIN2(max_layer, cbuf->u.tex.last_layer - cbuf->u.tex.first_layer); - } - else { + } else { max_layer = 0; } } } + if (fb->zsbuf) { struct pipe_surface *zsbuf = scene->fb.zsbuf; max_layer = MIN2(max_layer, zsbuf->u.tex.last_layer - zsbuf->u.tex.first_layer); } + scene->fb_max_layer = max_layer; scene->fb_max_samples = util_framebuffer_get_num_samples(fb); if (scene->fb_max_samples == 4) { @@ -653,7 +648,8 @@ void lp_scene_begin_binning(struct lp_scene *scene, } -void lp_scene_end_binning( struct lp_scene *scene ) +void +lp_scene_end_binning(struct lp_scene *scene) { if (LP_DEBUG & DEBUG_SCENE) { debug_printf("rasterize scene:\n"); @@ -663,6 +659,6 @@ void lp_scene_end_binning( struct lp_scene *scene ) lp_scene_data_size(scene)); if (0) - lp_debug_bins( scene ); + lp_debug_bins(scene); } } |