Mesa (master): cso_context: remove ability to restore VBs, const bufs, sampler views, images
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 10:07:39 UTC 2021
Module: Mesa
Branch: master
Commit: 211ec4226b02c407a75de013029f22e38ebc0227
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=211ec4226b02c407a75de013029f22e38ebc0227
Author: Marek Olšák <marek.olsak at amd.com>
Date: Sun Dec 20 03:13:20 2020 -0500
cso_context: remove ability to restore VBs, const bufs, sampler views, images
This is meant to decrease CPU overhead and reduce the use of cso_context when
better solutions are possible.
These functions are removed. Gallium frontends should just use pipe_context:
- cso_set_sampler_views
- cso_set_shader_images
- cso_set_constant_buffer*
Additionally, vertex buffers are passed through cso_context but they are not
saved there. The only remaining role of cso_context with regard to vertex
buffers is to decide whether to go through u_vbuf or skip it. u_vbuf also
can't save and restore vertex buffers anymore.
This is how the states are restored for meta ops:
- in st/mesa, set st->dirty |= flags to re-bind whatever state has been
touched
- outside of st/mesa, there is new interface st_context_iface::invalidate_-
_state that external modules can use to essentially set st->dirty through
it (like HUD)
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Zoltán Böszörményi <zboszor at gmail.com>
Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8180>
---
src/gallium/auxiliary/cso_cache/cso_context.c | 281 +-------------------------
src/gallium/auxiliary/cso_cache/cso_context.h | 41 +---
src/gallium/auxiliary/util/u_vbuf.c | 17 --
src/gallium/auxiliary/util/u_vbuf.h | 2 -
4 files changed, 8 insertions(+), 333 deletions(-)
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index 69077fcf2be..86c74123425 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -75,12 +75,6 @@ struct cso_context {
unsigned saved_state; /**< bitmask of CSO_BIT_x flags */
- struct pipe_sampler_view *fragment_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
- unsigned nr_fragment_views;
-
- struct pipe_sampler_view *fragment_views_saved[PIPE_MAX_SHADER_SAMPLER_VIEWS];
- unsigned nr_fragment_views_saved;
-
struct sampler_info fragment_samplers_saved;
struct sampler_info samplers[PIPE_SHADER_TYPES];
@@ -89,15 +83,6 @@ struct cso_context {
*/
int max_sampler_seen;
- struct pipe_vertex_buffer vertex_buffer0_current;
- struct pipe_vertex_buffer vertex_buffer0_saved;
-
- struct pipe_constant_buffer aux_constbuf_current[PIPE_SHADER_TYPES];
- struct pipe_constant_buffer aux_constbuf_saved[PIPE_SHADER_TYPES];
-
- struct pipe_image_view fragment_image0_current;
- struct pipe_image_view fragment_image0_saved;
-
unsigned nr_so_targets;
struct pipe_stream_output_target *so_targets[PIPE_MAX_SO_BUFFERS];
@@ -381,27 +366,9 @@ void cso_destroy_context( struct cso_context *ctx )
ctx->pipe->set_stream_output_targets(ctx->pipe, 0, NULL, NULL);
}
- for (i = 0; i < ctx->nr_fragment_views; i++) {
- pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
- }
- for (i = 0; i < ctx->nr_fragment_views_saved; i++) {
- pipe_sampler_view_reference(&ctx->fragment_views_saved[i], NULL);
- }
-
util_unreference_framebuffer_state(&ctx->fb);
util_unreference_framebuffer_state(&ctx->fb_saved);
- pipe_vertex_buffer_unreference(&ctx->vertex_buffer0_current);
- pipe_vertex_buffer_unreference(&ctx->vertex_buffer0_saved);
-
- for (i = 0; i < PIPE_SHADER_TYPES; i++) {
- pipe_resource_reference(&ctx->aux_constbuf_current[i].buffer, NULL);
- pipe_resource_reference(&ctx->aux_constbuf_saved[i].buffer, NULL);
- }
-
- pipe_resource_reference(&ctx->fragment_image0_current.resource, NULL);
- pipe_resource_reference(&ctx->fragment_image0_saved.resource, NULL);
-
for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) {
pipe_so_target_reference(&ctx->so_targets[i], NULL);
pipe_so_target_reference(&ctx->so_targets_saved[i], NULL);
@@ -1044,27 +1011,6 @@ cso_restore_vertex_elements(struct cso_context *ctx)
/* vertex buffers */
-static void
-cso_set_vertex_buffers_direct(struct cso_context *ctx,
- unsigned start_slot, unsigned count,
- const struct pipe_vertex_buffer *buffers)
-{
- /* Save what's in the auxiliary slot, so that we can save and restore it
- * for meta ops.
- */
- if (start_slot == 0) {
- if (buffers) {
- pipe_vertex_buffer_reference(&ctx->vertex_buffer0_current,
- buffers);
- } else {
- pipe_vertex_buffer_unreference(&ctx->vertex_buffer0_current);
- }
- }
-
- ctx->pipe->set_vertex_buffers(ctx->pipe, start_slot, count, buffers);
-}
-
-
void cso_set_vertex_buffers(struct cso_context *ctx,
unsigned start_slot, unsigned count,
const struct pipe_vertex_buffer *buffers)
@@ -1079,35 +1025,8 @@ void cso_set_vertex_buffers(struct cso_context *ctx,
return;
}
- cso_set_vertex_buffers_direct(ctx, start_slot, count, buffers);
-}
-
-static void
-cso_save_vertex_buffer0(struct cso_context *ctx)
-{
- struct u_vbuf *vbuf = ctx->vbuf_current;
-
- if (vbuf) {
- u_vbuf_save_vertex_buffer0(vbuf);
- return;
- }
-
- pipe_vertex_buffer_reference(&ctx->vertex_buffer0_saved,
- &ctx->vertex_buffer0_current);
-}
-
-static void
-cso_restore_vertex_buffer0(struct cso_context *ctx)
-{
- struct u_vbuf *vbuf = ctx->vbuf_current;
-
- if (vbuf) {
- u_vbuf_restore_vertex_buffer0(vbuf);
- return;
- }
-
- cso_set_vertex_buffers(ctx, 0, 1, &ctx->vertex_buffer0_saved);
- pipe_vertex_buffer_unreference(&ctx->vertex_buffer0_saved);
+ struct pipe_context *pipe = ctx->pipe;
+ pipe->set_vertex_buffers(pipe, start_slot, count, buffers);
}
/**
@@ -1131,13 +1050,14 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
bool uses_user_vertex_buffers)
{
struct u_vbuf *vbuf = ctx->vbuf;
+ struct pipe_context *pipe = ctx->pipe;
if (vbuf && (ctx->always_use_vbuf || uses_user_vertex_buffers)) {
if (!ctx->vbuf_current) {
/* Unbind all buffers in cso_context, because we'll use u_vbuf. */
unsigned unbind_vb_count = vb_count + unbind_trailing_vb_count;
if (unbind_vb_count)
- cso_set_vertex_buffers_direct(ctx, 0, unbind_vb_count, NULL);
+ pipe->set_vertex_buffers(pipe, 0, unbind_vb_count, NULL);
/* Unset this to make sure the CSO is re-bound on the next use. */
ctx->velements = NULL;
@@ -1163,12 +1083,11 @@ cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
u_vbuf_unset_vertex_elements(vbuf);
ctx->vbuf_current = NULL;
} else if (unbind_trailing_vb_count) {
- cso_set_vertex_buffers_direct(ctx, vb_count, unbind_trailing_vb_count,
- NULL);
+ pipe->set_vertex_buffers(pipe, vb_count, unbind_trailing_vb_count, NULL);
}
if (vb_count)
- cso_set_vertex_buffers_direct(ctx, 0, vb_count, vbuffers);
+ pipe->set_vertex_buffers(pipe, 0, vb_count, vbuffers);
cso_set_vertex_elements_direct(ctx, velems);
}
@@ -1280,113 +1199,6 @@ cso_restore_fragment_samplers(struct cso_context *ctx)
}
-void
-cso_set_sampler_views(struct cso_context *ctx,
- enum pipe_shader_type shader_stage,
- unsigned count,
- struct pipe_sampler_view **views)
-{
- if (shader_stage == PIPE_SHADER_FRAGMENT) {
- unsigned i;
- boolean any_change = FALSE;
-
- /* reference new views */
- for (i = 0; i < count; i++) {
- any_change |= ctx->fragment_views[i] != views[i];
- pipe_sampler_view_reference(&ctx->fragment_views[i], views[i]);
- }
- /* unref extra old views, if any */
- for (; i < ctx->nr_fragment_views; i++) {
- any_change |= ctx->fragment_views[i] != NULL;
- pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
- }
-
- /* bind the new sampler views */
- if (any_change) {
- ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0,
- MAX2(ctx->nr_fragment_views, count),
- ctx->fragment_views);
- }
-
- ctx->nr_fragment_views = count;
- }
- else
- ctx->pipe->set_sampler_views(ctx->pipe, shader_stage, 0, count, views);
-}
-
-
-static void
-cso_save_fragment_sampler_views(struct cso_context *ctx)
-{
- unsigned i;
-
- ctx->nr_fragment_views_saved = ctx->nr_fragment_views;
-
- for (i = 0; i < ctx->nr_fragment_views; i++) {
- assert(!ctx->fragment_views_saved[i]);
- pipe_sampler_view_reference(&ctx->fragment_views_saved[i],
- ctx->fragment_views[i]);
- }
-}
-
-
-static void
-cso_restore_fragment_sampler_views(struct cso_context *ctx)
-{
- unsigned i, nr_saved = ctx->nr_fragment_views_saved;
- unsigned num;
-
- for (i = 0; i < nr_saved; i++) {
- pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
- /* move the reference from one pointer to another */
- ctx->fragment_views[i] = ctx->fragment_views_saved[i];
- ctx->fragment_views_saved[i] = NULL;
- }
- for (; i < ctx->nr_fragment_views; i++) {
- pipe_sampler_view_reference(&ctx->fragment_views[i], NULL);
- }
-
- num = MAX2(ctx->nr_fragment_views, nr_saved);
-
- /* bind the old/saved sampler views */
- ctx->pipe->set_sampler_views(ctx->pipe, PIPE_SHADER_FRAGMENT, 0, num,
- ctx->fragment_views);
-
- ctx->nr_fragment_views = nr_saved;
- ctx->nr_fragment_views_saved = 0;
-}
-
-
-void
-cso_set_shader_images(struct cso_context *ctx,
- enum pipe_shader_type shader_stage,
- unsigned start, unsigned count,
- struct pipe_image_view *images)
-{
- if (shader_stage == PIPE_SHADER_FRAGMENT && start == 0 && count >= 1) {
- util_copy_image_view(&ctx->fragment_image0_current, &images[0]);
- }
-
- ctx->pipe->set_shader_images(ctx->pipe, shader_stage, start, count, images);
-}
-
-
-static void
-cso_save_fragment_image0(struct cso_context *ctx)
-{
- util_copy_image_view(&ctx->fragment_image0_saved,
- &ctx->fragment_image0_current);
-}
-
-
-static void
-cso_restore_fragment_image0(struct cso_context *ctx)
-{
- cso_set_shader_images(ctx, PIPE_SHADER_FRAGMENT, 0, 1,
- &ctx->fragment_image0_saved);
-}
-
-
void
cso_set_stream_outputs(struct cso_context *ctx,
unsigned num_targets,
@@ -1473,75 +1285,6 @@ cso_restore_stream_outputs(struct cso_context *ctx)
ctx->nr_so_targets_saved = 0;
}
-/* constant buffers */
-
-void
-cso_set_constant_buffer(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index, struct pipe_constant_buffer *cb)
-{
- struct pipe_context *pipe = cso->pipe;
-
- pipe->set_constant_buffer(pipe, shader_stage, index, cb);
-
- if (index == 0) {
- util_copy_constant_buffer(&cso->aux_constbuf_current[shader_stage], cb);
- }
-}
-
-void
-cso_set_constant_buffer_resource(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index,
- struct pipe_resource *buffer)
-{
- if (buffer) {
- struct pipe_constant_buffer cb;
- cb.buffer = buffer;
- cb.buffer_offset = 0;
- cb.buffer_size = buffer->width0;
- cb.user_buffer = NULL;
- cso_set_constant_buffer(cso, shader_stage, index, &cb);
- } else {
- cso_set_constant_buffer(cso, shader_stage, index, NULL);
- }
-}
-
-void
-cso_set_constant_user_buffer(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index, void *ptr, unsigned size)
-{
- if (ptr) {
- struct pipe_constant_buffer cb;
- cb.buffer = NULL;
- cb.buffer_offset = 0;
- cb.buffer_size = size;
- cb.user_buffer = ptr;
- cso_set_constant_buffer(cso, shader_stage, index, &cb);
- } else {
- cso_set_constant_buffer(cso, shader_stage, index, NULL);
- }
-}
-
-void
-cso_save_constant_buffer_slot0(struct cso_context *cso,
- enum pipe_shader_type shader_stage)
-{
- util_copy_constant_buffer(&cso->aux_constbuf_saved[shader_stage],
- &cso->aux_constbuf_current[shader_stage]);
-}
-
-void
-cso_restore_constant_buffer_slot0(struct cso_context *cso,
- enum pipe_shader_type shader_stage)
-{
- cso_set_constant_buffer(cso, shader_stage, 0,
- &cso->aux_constbuf_saved[shader_stage]);
- pipe_resource_reference(&cso->aux_constbuf_saved[shader_stage].buffer,
- NULL);
-}
-
/**
* Save all the CSO state items specified by the state_mask bitmask
@@ -1554,16 +1297,12 @@ cso_save_state(struct cso_context *cso, unsigned state_mask)
cso->saved_state = state_mask;
- if (state_mask & CSO_BIT_AUX_VERTEX_BUFFER_SLOT)
- cso_save_vertex_buffer0(cso);
if (state_mask & CSO_BIT_BLEND)
cso_save_blend(cso);
if (state_mask & CSO_BIT_DEPTH_STENCIL_ALPHA)
cso_save_depth_stencil_alpha(cso);
if (state_mask & CSO_BIT_FRAGMENT_SAMPLERS)
cso_save_fragment_samplers(cso);
- if (state_mask & CSO_BIT_FRAGMENT_SAMPLER_VIEWS)
- cso_save_fragment_sampler_views(cso);
if (state_mask & CSO_BIT_FRAGMENT_SHADER)
cso_save_fragment_shader(cso);
if (state_mask & CSO_BIT_FRAMEBUFFER)
@@ -1594,8 +1333,6 @@ cso_save_state(struct cso_context *cso, unsigned state_mask)
cso_save_viewport(cso);
if (state_mask & CSO_BIT_PAUSE_QUERIES)
cso->pipe->set_active_query_state(cso->pipe, false);
- if (state_mask & CSO_BIT_FRAGMENT_IMAGE0)
- cso_save_fragment_image0(cso);
}
@@ -1609,16 +1346,12 @@ cso_restore_state(struct cso_context *cso)
assert(state_mask);
- if (state_mask & CSO_BIT_AUX_VERTEX_BUFFER_SLOT)
- cso_restore_vertex_buffer0(cso);
if (state_mask & CSO_BIT_BLEND)
cso_restore_blend(cso);
if (state_mask & CSO_BIT_DEPTH_STENCIL_ALPHA)
cso_restore_depth_stencil_alpha(cso);
if (state_mask & CSO_BIT_FRAGMENT_SAMPLERS)
cso_restore_fragment_samplers(cso);
- if (state_mask & CSO_BIT_FRAGMENT_SAMPLER_VIEWS)
- cso_restore_fragment_sampler_views(cso);
if (state_mask & CSO_BIT_FRAGMENT_SHADER)
cso_restore_fragment_shader(cso);
if (state_mask & CSO_BIT_FRAMEBUFFER)
@@ -1649,8 +1382,6 @@ cso_restore_state(struct cso_context *cso)
cso_restore_viewport(cso);
if (state_mask & CSO_BIT_PAUSE_QUERIES)
cso->pipe->set_active_query_state(cso->pipe, true);
- if (state_mask & CSO_BIT_FRAGMENT_IMAGE0)
- cso_restore_fragment_image0(cso);
cso->saved_state = 0;
}
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index 1f55097ecf4..dd7121663ca 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -132,12 +132,11 @@ void cso_set_render_condition(struct cso_context *cso,
boolean condition,
enum pipe_render_cond_flag mode);
-
-#define CSO_BIT_AUX_VERTEX_BUFFER_SLOT 0x1
+/* gap */
#define CSO_BIT_BLEND 0x2
#define CSO_BIT_DEPTH_STENCIL_ALPHA 0x4
#define CSO_BIT_FRAGMENT_SAMPLERS 0x8
-#define CSO_BIT_FRAGMENT_SAMPLER_VIEWS 0x10
+/* gap */
#define CSO_BIT_FRAGMENT_SHADER 0x20
#define CSO_BIT_FRAMEBUFFER 0x40
#define CSO_BIT_GEOMETRY_SHADER 0x80
@@ -153,7 +152,6 @@ void cso_set_render_condition(struct cso_context *cso,
#define CSO_BIT_VERTEX_SHADER 0x20000
#define CSO_BIT_VIEWPORT 0x40000
#define CSO_BIT_PAUSE_QUERIES 0x80000
-#define CSO_BIT_FRAGMENT_IMAGE0 0x100000
#define CSO_BITS_ALL_SHADERS (CSO_BIT_VERTEX_SHADER | \
CSO_BIT_FRAGMENT_SHADER | \
@@ -165,41 +163,6 @@ void cso_save_state(struct cso_context *cso, unsigned state_mask);
void cso_restore_state(struct cso_context *cso);
-/* sampler view state */
-
-void
-cso_set_sampler_views(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned count,
- struct pipe_sampler_view **views);
-
-
-/* shader images */
-
-void
-cso_set_shader_images(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned start, unsigned count,
- struct pipe_image_view *views);
-
-
-/* constant buffers */
-
-void cso_set_constant_buffer(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index, struct pipe_constant_buffer *cb);
-void cso_set_constant_buffer_resource(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index,
- struct pipe_resource *buffer);
-void cso_set_constant_user_buffer(struct cso_context *cso,
- enum pipe_shader_type shader_stage,
- unsigned index, void *ptr, unsigned size);
-void cso_save_constant_buffer_slot0(struct cso_context *cso,
- enum pipe_shader_type shader_stage);
-void cso_restore_constant_buffer_slot0(struct cso_context *cso,
- enum pipe_shader_type shader_stage);
-
/* Optimized version. */
void
cso_set_vertex_buffers_and_elements(struct cso_context *ctx,
diff --git a/src/gallium/auxiliary/util/u_vbuf.c b/src/gallium/auxiliary/util/u_vbuf.c
index 4120948f401..add103df0bf 100644
--- a/src/gallium/auxiliary/util/u_vbuf.c
+++ b/src/gallium/auxiliary/util/u_vbuf.c
@@ -157,9 +157,6 @@ struct u_vbuf {
struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS];
uint32_t enabled_vb_mask;
- /* Saved vertex buffer. */
- struct pipe_vertex_buffer vertex_buffer0_saved;
-
/* Vertex buffers for the driver.
* There are usually no user buffers. */
struct pipe_vertex_buffer real_vertex_buffer[PIPE_MAX_ATTRIBS];
@@ -401,8 +398,6 @@ void u_vbuf_destroy(struct u_vbuf *mgr)
for (i = 0; i < PIPE_MAX_ATTRIBS; i++)
pipe_vertex_buffer_unreference(&mgr->real_vertex_buffer[i]);
- pipe_vertex_buffer_unreference(&mgr->vertex_buffer0_saved);
-
translate_cache_destroy(mgr->translate_cache);
cso_cache_delete(&mgr->cso_cache);
FREE(mgr);
@@ -1604,15 +1599,3 @@ void u_vbuf_restore_vertex_elements(struct u_vbuf *mgr)
}
mgr->ve_saved = NULL;
}
-
-void u_vbuf_save_vertex_buffer0(struct u_vbuf *mgr)
-{
- pipe_vertex_buffer_reference(&mgr->vertex_buffer0_saved,
- &mgr->vertex_buffer[0]);
-}
-
-void u_vbuf_restore_vertex_buffer0(struct u_vbuf *mgr)
-{
- u_vbuf_set_vertex_buffers(mgr, 0, 1, &mgr->vertex_buffer0_saved);
- pipe_vertex_buffer_unreference(&mgr->vertex_buffer0_saved);
-}
diff --git a/src/gallium/auxiliary/util/u_vbuf.h b/src/gallium/auxiliary/util/u_vbuf.h
index 30d831d2656..3df24030872 100644
--- a/src/gallium/auxiliary/util/u_vbuf.h
+++ b/src/gallium/auxiliary/util/u_vbuf.h
@@ -88,7 +88,5 @@ void u_vbuf_get_minmax_index(struct pipe_context *pipe,
/* Save/restore functionality. */
void u_vbuf_save_vertex_elements(struct u_vbuf *mgr);
void u_vbuf_restore_vertex_elements(struct u_vbuf *mgr);
-void u_vbuf_save_vertex_buffer0(struct u_vbuf *mgr);
-void u_vbuf_restore_vertex_buffer0(struct u_vbuf *mgr);
#endif
More information about the mesa-commit
mailing list