mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 09:38:07 +02:00
llvmpipe: asst. clean-ups in lp_scene.c
Signed-off-by: Brian Paul <brianp@vmware.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19289>
This commit is contained in:
parent
75d7bb2e16
commit
416fcfc6e5
1 changed files with 42 additions and 49 deletions
|
|
@ -36,11 +36,10 @@
|
|||
#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 {
|
||||
|
|
@ -113,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;
|
||||
|
|
@ -156,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)
|
||||
{
|
||||
|
|
@ -181,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;
|
||||
|
|
@ -195,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);
|
||||
}
|
||||
|
|
@ -219,7 +217,7 @@ 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;
|
||||
|
||||
|
|
@ -327,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;
|
||||
}
|
||||
|
|
@ -358,14 +351,13 @@ 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;
|
||||
|
|
@ -386,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;
|
||||
|
|
@ -508,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;
|
||||
}
|
||||
|
|
@ -539,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)
|
||||
|
|
@ -559,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;
|
||||
}
|
||||
|
|
@ -572,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;
|
||||
|
||||
|
|
@ -582,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;
|
||||
}
|
||||
|
|
@ -599,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);
|
||||
|
|
@ -616,7 +605,8 @@ void lp_scene_begin_binning(struct lp_scene *scene,
|
|||
|
||||
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));
|
||||
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);
|
||||
|
|
@ -625,26 +615,28 @@ void lp_scene_begin_binning(struct lp_scene *scene,
|
|||
|
||||
/*
|
||||
* 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) {
|
||||
|
|
@ -656,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");
|
||||
|
|
@ -666,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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue