diff options
author | Marek Olšák <[email protected]> | 2020-01-20 22:59:49 -0500 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-02-28 00:53:45 +0000 |
commit | c9e4dc8d5e8f5e860f93eb3555a507402506b59a (patch) | |
tree | 60fe237f31934f94d67728e7d2940221b514faef /src/gallium/auxiliary/util | |
parent | 6c90e39a5b854595e3bbbf30f01aaf7dc798158e (diff) |
gallium: pass cso_velems_state into cso_context instead of pipe_vertex_element
This removes one memcpy from the CSO hashing code.
Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3990>
Diffstat (limited to 'src/gallium/auxiliary/util')
-rw-r--r-- | src/gallium/auxiliary/util/u_blit.c | 13 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_tests.c | 12 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_vbuf.c | 45 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_vbuf.h | 5 |
4 files changed, 38 insertions, 37 deletions
diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index 1216766ee84..79e5c6cba91 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -62,7 +62,7 @@ struct blit_state struct pipe_rasterizer_state rasterizer; struct pipe_sampler_state sampler; struct pipe_viewport_state viewport; - struct pipe_vertex_element velem[2]; + struct cso_velems_state velem; void *vs; void *fs[PIPE_MAX_TEXTURE_TYPES][4]; @@ -110,11 +110,12 @@ util_create_blit(struct pipe_context *pipe, struct cso_context *cso) ctx->sampler.mag_img_filter = 0; /* set later */ /* vertex elements state */ + ctx->velem.count = 2; for (i = 0; i < 2; i++) { - ctx->velem[i].src_offset = i * 4 * sizeof(float); - ctx->velem[i].instance_divisor = 0; - ctx->velem[i].vertex_buffer_index = 0; - ctx->velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + ctx->velem.velems[i].src_offset = i * 4 * sizeof(float); + ctx->velem.velems[i].instance_divisor = 0; + ctx->velem.velems[i].vertex_buffer_index = 0; + ctx->velem.velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } ctx->vbuf = NULL; @@ -583,7 +584,7 @@ util_blit_pixels_tex(struct blit_state *ctx, cso_set_sample_mask(ctx->cso, ~0); cso_set_min_samples(ctx->cso, 1); cso_set_rasterizer(ctx->cso, &ctx->rasterizer); - cso_set_vertex_elements(ctx->cso, 2, ctx->velem); + cso_set_vertex_elements(ctx->cso, &ctx->velem); cso_set_stream_outputs(ctx->cso, 0, NULL, NULL); /* sampler */ diff --git a/src/gallium/auxiliary/util/u_tests.c b/src/gallium/auxiliary/util/u_tests.c index 9751d9bcd6f..8ff22bccd4e 100644 --- a/src/gallium/auxiliary/util/u_tests.c +++ b/src/gallium/auxiliary/util/u_tests.c @@ -134,17 +134,17 @@ static void util_set_interleaved_vertex_elements(struct cso_context *cso, unsigned num_elements) { + struct cso_velems_state velem; unsigned i; - struct pipe_vertex_element *velem = - calloc(1, num_elements * sizeof(struct pipe_vertex_element)); + memset(&velem, 0, sizeof(velem)); + velem.count = num_elements; for (i = 0; i < num_elements; i++) { - velem[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - velem[i].src_offset = i * 16; + velem.velems[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + velem.velems[i].src_offset = i * 16; } - cso_set_vertex_elements(cso, num_elements, velem); - free(velem); + cso_set_vertex_elements(cso, &velem); } static void * diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c index 0201dc9b2bf..7a6e214b29a 100644 --- a/src/gallium/auxiliary/util/u_vbuf.c +++ b/src/gallium/auxiliary/util/u_vbuf.c @@ -167,7 +167,7 @@ struct u_vbuf { struct u_vbuf_elements *ve, *ve_saved; /* Vertex elements used for the translate fallback. */ - struct pipe_vertex_element fallback_velems[PIPE_MAX_ATTRIBS]; + struct cso_velems_state fallback_velems; /* If non-NULL, this is a vertex element state used for the translate * fallback and therefore used for rendering too. */ boolean using_translate; @@ -328,28 +328,26 @@ u_vbuf_create(struct pipe_context *pipe, struct u_vbuf_caps *caps) /* u_vbuf uses its own caching for vertex elements, because it needs to keep * its own preprocessed state per vertex element CSO. */ static struct u_vbuf_elements * -u_vbuf_set_vertex_elements_internal(struct u_vbuf *mgr, unsigned count, - const struct pipe_vertex_element *states) +u_vbuf_set_vertex_elements_internal(struct u_vbuf *mgr, + const struct cso_velems_state *velems) { struct pipe_context *pipe = mgr->pipe; unsigned key_size, hash_key; struct cso_hash_iter iter; struct u_vbuf_elements *ve; - struct cso_velems_state velems_state; /* need to include the count into the stored state data too. */ - key_size = sizeof(struct pipe_vertex_element) * count + sizeof(unsigned); - velems_state.count = count; - memcpy(velems_state.velems, states, - sizeof(struct pipe_vertex_element) * count); - hash_key = cso_construct_key((void*)&velems_state, key_size); + key_size = sizeof(struct pipe_vertex_element) * velems->count + + sizeof(unsigned); + hash_key = cso_construct_key((void*)velems, key_size); iter = cso_find_state_template(mgr->cso_cache, hash_key, CSO_VELEMENTS, - (void*)&velems_state, key_size); + (void*)velems, key_size); if (cso_hash_iter_is_null(iter)) { struct cso_velements *cso = MALLOC_STRUCT(cso_velements); - memcpy(&cso->state, &velems_state, key_size); - cso->data = u_vbuf_create_vertex_elements(mgr, count, states); + memcpy(&cso->state, velems, key_size); + cso->data = u_vbuf_create_vertex_elements(mgr, velems->count, + velems->velems); cso->delete_state = (cso_state_callback)u_vbuf_delete_vertex_elements; cso->context = (void*)mgr; @@ -367,10 +365,10 @@ u_vbuf_set_vertex_elements_internal(struct u_vbuf *mgr, unsigned count, return ve; } -void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, unsigned count, - const struct pipe_vertex_element *states) +void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, + const struct cso_velems_state *velems) { - mgr->ve = u_vbuf_set_vertex_elements_internal(mgr, count, states); + mgr->ve = u_vbuf_set_vertex_elements_internal(mgr, velems); } void u_vbuf_unset_vertex_elements(struct u_vbuf *mgr) @@ -726,10 +724,10 @@ u_vbuf_translate_begin(struct u_vbuf *mgr, for (type = 0; type < VB_NUM; type++) { if (elem_index[type][i] < key[type].nr_elements) { struct translate_element *te = &key[type].element[elem_index[type][i]]; - mgr->fallback_velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor; - mgr->fallback_velems[i].src_format = te->output_format; - mgr->fallback_velems[i].src_offset = te->output_offset; - mgr->fallback_velems[i].vertex_buffer_index = mgr->fallback_vbs[type]; + mgr->fallback_velems.velems[i].instance_divisor = mgr->ve->ve[i].instance_divisor; + mgr->fallback_velems.velems[i].src_format = te->output_format; + mgr->fallback_velems.velems[i].src_offset = te->output_offset; + mgr->fallback_velems.velems[i].vertex_buffer_index = mgr->fallback_vbs[type]; /* elem_index[type][i] can only be set for one type. */ assert(type > VB_INSTANCE || elem_index[type+1][i] == ~0u); @@ -739,13 +737,14 @@ u_vbuf_translate_begin(struct u_vbuf *mgr, } /* No translating, just copy the original vertex element over. */ if (type == VB_NUM) { - memcpy(&mgr->fallback_velems[i], &mgr->ve->ve[i], + memcpy(&mgr->fallback_velems.velems[i], &mgr->ve->ve[i], sizeof(struct pipe_vertex_element)); } } - u_vbuf_set_vertex_elements_internal(mgr, mgr->ve->count, - mgr->fallback_velems); + mgr->fallback_velems.count = mgr->ve->count; + + u_vbuf_set_vertex_elements_internal(mgr, &mgr->fallback_velems); mgr->using_translate = TRUE; return TRUE; } @@ -954,7 +953,7 @@ u_vbuf_upload_buffers(struct u_vbuf *mgr, unsigned i; unsigned nr_velems = mgr->ve->count; const struct pipe_vertex_element *velems = - mgr->using_translate ? mgr->fallback_velems : mgr->ve->ve; + mgr->using_translate ? mgr->fallback_velems.velems : mgr->ve->ve; unsigned start_offset[PIPE_MAX_ATTRIBS]; unsigned end_offset[PIPE_MAX_ATTRIBS]; uint32_t buffer_mask = 0; diff --git a/src/gallium/auxiliary/util/u_vbuf.h b/src/gallium/auxiliary/util/u_vbuf.h index b364e06344a..3031a30bb47 100644 --- a/src/gallium/auxiliary/util/u_vbuf.h +++ b/src/gallium/auxiliary/util/u_vbuf.h @@ -42,6 +42,7 @@ extern "C" { #include "pipe/p_format.h" struct cso_context; +struct cso_velems_state; struct u_vbuf; /* Hardware vertex fetcher limitations can be described by this structure. */ @@ -73,8 +74,8 @@ u_vbuf_create(struct pipe_context *pipe, struct u_vbuf_caps *caps); void u_vbuf_destroy(struct u_vbuf *mgr); /* State and draw functions. */ -void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, unsigned count, - const struct pipe_vertex_element *states); +void u_vbuf_set_vertex_elements(struct u_vbuf *mgr, + const struct cso_velems_state *velems); void u_vbuf_unset_vertex_elements(struct u_vbuf *mgr); void u_vbuf_set_vertex_buffers(struct u_vbuf *mgr, unsigned start_slot, unsigned count, |