Module: Mesa Branch: main Commit: 0fb946da94eeb562f726c39729552a6c4c4e7092 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=0fb946da94eeb562f726c39729552a6c4c4e7092
Author: Dave Airlie <[email protected]> Date: Wed Dec 15 11:19:43 2021 +1000 mesa/st: merge transform feedback code from st into mesa After the objects are merged, this moves the rest of the code from the state tracker into mesa. Acked-by: Marek Olšák <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14327> --- src/mesa/main/transformfeedback.c | 77 +++++++++++++++- src/mesa/meson.build | 2 - src/mesa/state_tracker/st_cb_xformfb.c | 163 --------------------------------- src/mesa/state_tracker/st_cb_xformfb.h | 57 ------------ src/mesa/state_tracker/st_draw.c | 4 +- 5 files changed, 74 insertions(+), 229 deletions(-) diff --git a/src/mesa/main/transformfeedback.c b/src/mesa/main/transformfeedback.c index 7f37ae50a45..3404274c7e3 100644 --- a/src/mesa/main/transformfeedback.c +++ b/src/mesa/main/transformfeedback.c @@ -47,9 +47,9 @@ #include "util/u_memory.h" #include "util/u_inlines.h" -#include "state_tracker/st_cb_xformfb.h" #include "api_exec_decl.h" +#include "cso_cache/cso_context.h" struct using_program_tuple { struct gl_program *prog; @@ -421,7 +421,46 @@ begin_transform_feedback(struct gl_context *ctx, GLenum mode, bool no_error) obj->program = source; } - st_begin_transform_feedback(ctx, mode, obj); + struct pipe_context *pipe = ctx->pipe; + unsigned max_num_targets; + unsigned offsets[PIPE_MAX_SO_BUFFERS] = {0}; + + max_num_targets = MIN2(ARRAY_SIZE(obj->Buffers), + ARRAY_SIZE(obj->targets)); + + /* Convert the transform feedback state into the gallium representation. */ + for (i = 0; i < max_num_targets; i++) { + struct gl_buffer_object *bo = obj->Buffers[i]; + + if (bo && bo->buffer) { + unsigned stream = obj->program->sh.LinkedTransformFeedback-> + Buffers[i].Stream; + + /* Check whether we need to recreate the target. */ + if (!obj->targets[i] || + obj->targets[i] == obj->draw_count[stream] || + obj->targets[i]->buffer != bo->buffer || + obj->targets[i]->buffer_offset != obj->Offset[i] || + obj->targets[i]->buffer_size != obj->Size[i]) { + /* Create a new target. */ + struct pipe_stream_output_target *so_target = + pipe->create_stream_output_target(pipe, bo->buffer, + obj->Offset[i], + obj->Size[i]); + + pipe_so_target_reference(&obj->targets[i], NULL); + obj->targets[i] = so_target; + } + + obj->num_targets = i+1; + } else { + pipe_so_target_reference(&obj->targets[i], NULL); + } + } + + /* Start writing at the beginning of each target. */ + cso_set_stream_outputs(ctx->cso_context, obj->num_targets, + obj->targets, offsets); _mesa_update_valid_to_render_state(ctx); } @@ -446,9 +485,30 @@ static void end_transform_feedback(struct gl_context *ctx, struct gl_transform_feedback_object *obj) { + unsigned i; FLUSH_VERTICES(ctx, 0, 0); - st_end_transform_feedback(ctx, obj); + cso_set_stream_outputs(ctx->cso_context, 0, NULL, NULL); + + /* The next call to glDrawTransformFeedbackStream should use the vertex + * count from the last call to glEndTransformFeedback. + * Therefore, save the targets for each stream. + * + * NULL means the vertex counter is 0 (initial state). + */ + for (i = 0; i < ARRAY_SIZE(obj->draw_count); i++) + pipe_so_target_reference(&obj->draw_count[i], NULL); + + for (i = 0; i < ARRAY_SIZE(obj->targets); i++) { + unsigned stream = obj->program->sh.LinkedTransformFeedback-> + Buffers[i].Stream; + + /* Is it not bound or already set for this stream? */ + if (!obj->targets[i] || obj->draw_count[stream]) + continue; + + pipe_so_target_reference(&obj->draw_count[stream], obj->targets[i]); + } _mesa_reference_program_(ctx, &obj->program, NULL); ctx->TransformFeedback.CurrentObject->Active = GL_FALSE; @@ -1190,7 +1250,7 @@ pause_transform_feedback(struct gl_context *ctx, { FLUSH_VERTICES(ctx, 0, 0); - st_pause_transform_feedback(ctx, obj); + cso_set_stream_outputs(ctx->cso_context, 0, NULL, NULL); obj->Paused = GL_TRUE; _mesa_update_valid_to_render_state(ctx); @@ -1235,7 +1295,14 @@ resume_transform_feedback(struct gl_context *ctx, obj->Paused = GL_FALSE; - st_resume_transform_feedback(ctx, obj); + unsigned offsets[PIPE_MAX_SO_BUFFERS]; + unsigned i; + + for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) + offsets[i] = (unsigned)-1; + + cso_set_stream_outputs(ctx->cso_context, obj->num_targets, + obj->targets, offsets); _mesa_update_valid_to_render_state(ctx); } diff --git a/src/mesa/meson.build b/src/mesa/meson.build index d7db0842b79..ef4ff77032e 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -356,8 +356,6 @@ files_libmesa = files( 'state_tracker/st_cb_texture.h', 'state_tracker/st_cb_viewport.c', 'state_tracker/st_cb_viewport.h', - 'state_tracker/st_cb_xformfb.c', - 'state_tracker/st_cb_xformfb.h', 'state_tracker/st_context.c', 'state_tracker/st_context.h', 'state_tracker/st_copytex.c', diff --git a/src/mesa/state_tracker/st_cb_xformfb.c b/src/mesa/state_tracker/st_cb_xformfb.c deleted file mode 100644 index 57357ec2e67..00000000000 --- a/src/mesa/state_tracker/st_cb_xformfb.c +++ /dev/null @@ -1,163 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - - -/** - * Transform feedback functions. - * - * \author Brian Paul - * Marek Olšák - */ - - -#include "main/bufferobj.h" -#include "main/context.h" -#include "main/transformfeedback.h" -#include "util/u_memory.h" - -#include "st_cb_xformfb.h" -#include "st_context.h" - -#include "pipe/p_context.h" -#include "util/u_draw.h" -#include "util/u_inlines.h" -#include "cso_cache/cso_context.h" - - - -/* XXX Do we really need the mode? */ -void -st_begin_transform_feedback(struct gl_context *ctx, GLenum mode, - struct gl_transform_feedback_object *obj) -{ - struct st_context *st = st_context(ctx); - struct pipe_context *pipe = ctx->pipe; - unsigned i, max_num_targets; - unsigned offsets[PIPE_MAX_SO_BUFFERS] = {0}; - - max_num_targets = MIN2(ARRAY_SIZE(obj->Buffers), - ARRAY_SIZE(obj->targets)); - - /* Convert the transform feedback state into the gallium representation. */ - for (i = 0; i < max_num_targets; i++) { - struct gl_buffer_object *bo = obj->Buffers[i]; - - if (bo && bo->buffer) { - unsigned stream = obj->program->sh.LinkedTransformFeedback-> - Buffers[i].Stream; - - /* Check whether we need to recreate the target. */ - if (!obj->targets[i] || - obj->targets[i] == obj->draw_count[stream] || - obj->targets[i]->buffer != bo->buffer || - obj->targets[i]->buffer_offset != obj->Offset[i] || - obj->targets[i]->buffer_size != obj->Size[i]) { - /* Create a new target. */ - struct pipe_stream_output_target *so_target = - pipe->create_stream_output_target(pipe, bo->buffer, - obj->Offset[i], - obj->Size[i]); - - pipe_so_target_reference(&obj->targets[i], NULL); - obj->targets[i] = so_target; - } - - obj->num_targets = i+1; - } else { - pipe_so_target_reference(&obj->targets[i], NULL); - } - } - - /* Start writing at the beginning of each target. */ - cso_set_stream_outputs(st->cso_context, obj->num_targets, - obj->targets, offsets); -} - - -void -st_pause_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj) -{ - struct st_context *st = st_context(ctx); - cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); -} - - -void -st_resume_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj) -{ - struct st_context *st = st_context(ctx); - unsigned offsets[PIPE_MAX_SO_BUFFERS]; - unsigned i; - - for (i = 0; i < PIPE_MAX_SO_BUFFERS; i++) - offsets[i] = (unsigned)-1; - - cso_set_stream_outputs(st->cso_context, obj->num_targets, - obj->targets, offsets); -} - -void -st_end_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj) -{ - struct st_context *st = st_context(ctx); - unsigned i; - - cso_set_stream_outputs(st->cso_context, 0, NULL, NULL); - - /* The next call to glDrawTransformFeedbackStream should use the vertex - * count from the last call to glEndTransformFeedback. - * Therefore, save the targets for each stream. - * - * NULL means the vertex counter is 0 (initial state). - */ - for (i = 0; i < ARRAY_SIZE(obj->draw_count); i++) - pipe_so_target_reference(&obj->draw_count[i], NULL); - - for (i = 0; i < ARRAY_SIZE(obj->targets); i++) { - unsigned stream = obj->program->sh.LinkedTransformFeedback-> - Buffers[i].Stream; - - /* Is it not bound or already set for this stream? */ - if (!obj->targets[i] || obj->draw_count[stream]) - continue; - - pipe_so_target_reference(&obj->draw_count[stream], obj->targets[i]); - } -} - - -bool -st_transform_feedback_draw_init(struct gl_transform_feedback_object *obj, - unsigned stream, - struct pipe_draw_indirect_info *out) -{ - out->count_from_stream_output = obj->draw_count[stream]; - return out->count_from_stream_output != NULL; -} diff --git a/src/mesa/state_tracker/st_cb_xformfb.h b/src/mesa/state_tracker/st_cb_xformfb.h deleted file mode 100644 index b2fbea58012..00000000000 --- a/src/mesa/state_tracker/st_cb_xformfb.h +++ /dev/null @@ -1,57 +0,0 @@ -/************************************************************************** - * - * Copyright 2010 VMware, Inc. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#ifndef ST_CB_XFORMFB_H -#define ST_CB_XFORMFB_H - - -struct gl_transform_feedback_object; -struct pipe_draw_indirect_info; - -void -st_begin_transform_feedback(struct gl_context *ctx, GLenum mode, - struct gl_transform_feedback_object *obj); - -void -st_pause_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj); - -void -st_resume_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj); - -void -st_end_transform_feedback(struct gl_context *ctx, - struct gl_transform_feedback_object *obj); - -extern bool -st_transform_feedback_draw_init(struct gl_transform_feedback_object *obj, - unsigned stream, - struct pipe_draw_indirect_info *out); - - -#endif /* ST_CB_XFORMFB_H */ diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index ad46f27d7e7..e121564d3be 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -50,7 +50,6 @@ #include "st_context.h" #include "st_atom.h" #include "st_cb_bitmap.h" -#include "st_cb_xformfb.h" #include "st_debug.h" #include "st_draw.h" #include "st_program.h" @@ -306,7 +305,8 @@ st_draw_transform_feedback(struct gl_context *ctx, GLenum mode, /* Transform feedback drawing is always non-indexed. */ /* Set info.count_from_stream_output. */ - if (!st_transform_feedback_draw_init(tfb_vertcount, stream, &indirect)) + indirect.count_from_stream_output = tfb_vertcount->draw_count[stream]; + if (indirect.count_from_stream_output == NULL) return; cso_draw_vbo(st->cso_context, &info, 0, &indirect, draw);
