[Mesa-dev] [PATCH 07/17] st/mesa: simplify update_constants functions
Brian Paul
brianp at vmware.com
Mon May 1 16:40:23 UTC 2017
On 05/01/2017 06:52 AM, Marek Olšák wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> ---
> src/mesa/state_tracker/st_atom_constbuf.c | 45 +++++++++----------------------
> src/mesa/state_tracker/st_atom_constbuf.h | 4 +--
> src/mesa/state_tracker/st_cb_bitmap.c | 2 +-
> src/mesa/state_tracker/st_cb_drawpixels.c | 4 +--
> 4 files changed, 17 insertions(+), 38 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
> index 6cbfba7..cc1bd29 100644
> --- a/src/mesa/state_tracker/st_atom_constbuf.c
> +++ b/src/mesa/state_tracker/st_atom_constbuf.c
> @@ -44,26 +44,25 @@
> #include "st_debug.h"
> #include "st_context.h"
> #include "st_atom.h"
> #include "st_atom_constbuf.h"
> #include "st_program.h"
> #include "st_cb_bufferobjects.h"
>
> /**
> * Pass the given program parameters to the graphics pipe as a
> * constant buffer.
> - * \param shader_type either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT
> */
> -void st_upload_constants( struct st_context *st,
> - struct gl_program_parameter_list *params,
> - gl_shader_stage stage)
> +void st_upload_constants(struct st_context *st, struct gl_program *prog)
> {
> + gl_shader_stage stage = prog->info.stage;
> + struct gl_program_parameter_list *params = prog->Parameters;
> enum pipe_shader_type shader_type = st_shader_stage_to_ptarget(stage);
>
> assert(shader_type == PIPE_SHADER_VERTEX ||
> shader_type == PIPE_SHADER_FRAGMENT ||
> shader_type == PIPE_SHADER_GEOMETRY ||
> shader_type == PIPE_SHADER_TESS_CTRL ||
> shader_type == PIPE_SHADER_TESS_EVAL ||
> shader_type == PIPE_SHADER_COMPUTE);
>
> /* update the ATI constants before rendering */
> @@ -134,88 +133,70 @@ void st_upload_constants( struct st_context *st,
> cso_set_constant_buffer(st->cso_context, shader_type, 0, NULL);
> }
> }
>
>
> /**
> * Vertex shader:
> */
> void st_update_vs_constants(struct st_context *st )
> {
> - struct st_vertex_program *vp = st->vp;
> - struct gl_program_parameter_list *params = vp->Base.Parameters;
> -
> - st_upload_constants( st, params, MESA_SHADER_VERTEX );
> + st_upload_constants(st, &st->vp->Base);
> }
>
> /**
> * Fragment shader:
> */
> void st_update_fs_constants(struct st_context *st )
> {
> - struct st_fragment_program *fp = st->fp;
> - struct gl_program_parameter_list *params = fp->Base.Parameters;
> -
> - st_upload_constants( st, params, MESA_SHADER_FRAGMENT );
> + st_upload_constants(st, &st->fp->Base);
> }
>
>
> /* Geometry shader:
> */
> void st_update_gs_constants(struct st_context *st )
> {
> struct st_common_program *gp = st->gp;
> - struct gl_program_parameter_list *params;
>
> - if (gp) {
> - params = gp->Base.Parameters;
> - st_upload_constants( st, params, MESA_SHADER_GEOMETRY );
> - }
> + if (st->gp)
> + st_upload_constants(st, &gp->Base);
This could be further simplified to get rid of the local var.
if (st->gp)
st_upload_constants(st, &st->gp->Base);
Or, a least use 'gp' instead of 'st->gp' in the conditional.
-Brian
> }
>
> /* Tessellation control shader:
> */
> void st_update_tcs_constants(struct st_context *st )
> {
> struct st_common_program *tcp = st->tcp;
> - struct gl_program_parameter_list *params;
>
> - if (tcp) {
> - params = tcp->Base.Parameters;
> - st_upload_constants( st, params, MESA_SHADER_TESS_CTRL );
> - }
> + if (tcp)
> + st_upload_constants(st, &tcp->Base);
> }
>
> /* Tessellation evaluation shader:
> */
> void st_update_tes_constants(struct st_context *st )
> {
> struct st_common_program *tep = st->tep;
> - struct gl_program_parameter_list *params;
>
> - if (tep) {
> - params = tep->Base.Parameters;
> - st_upload_constants( st, params, MESA_SHADER_TESS_EVAL );
> - }
> + if (tep)
> + st_upload_constants(st, &tep->Base);
> }
>
> /* Compute shader:
> */
> void st_update_cs_constants(struct st_context *st )
> {
> struct st_compute_program *cp = st->cp;
> - struct gl_program_parameter_list *params;
>
> - if (cp) {
> - params = cp->Base.Parameters;
> - st_upload_constants( st, params, MESA_SHADER_COMPUTE );
> - }
> + if (cp)
> + st_upload_constants(st, &cp->Base);
> }
>
> static void st_bind_ubos(struct st_context *st, struct gl_program *prog,
> unsigned shader_type)
> {
> unsigned i;
> struct pipe_constant_buffer cb = { 0 };
>
> if (!prog)
> return;
> diff --git a/src/mesa/state_tracker/st_atom_constbuf.h b/src/mesa/state_tracker/st_atom_constbuf.h
> index df60a62..e810a24 100644
> --- a/src/mesa/state_tracker/st_atom_constbuf.h
> +++ b/src/mesa/state_tracker/st_atom_constbuf.h
> @@ -28,16 +28,14 @@
>
> #ifndef ST_ATOM_CONSTBUF_H
> #define ST_ATOM_CONSTBUF_H
>
> #include "compiler/shader_enums.h"
>
> struct gl_program_parameter_list;
> struct st_context;
>
>
> -void st_upload_constants( struct st_context *st,
> - struct gl_program_parameter_list *params,
> - gl_shader_stage stage);
> +void st_upload_constants(struct st_context *st, struct gl_program *prog);
>
>
> #endif /* ST_ATOM_CONSTBUF_H */
> diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c
> index 9e83c0e..ef3f64b 100644
> --- a/src/mesa/state_tracker/st_cb_bitmap.c
> +++ b/src/mesa/state_tracker/st_cb_bitmap.c
> @@ -184,21 +184,21 @@ setup_render_state(struct gl_context *ctx,
> * primary color from a statevar/constant rather than a varying variable.
> * when that's the case, we need to ensure that we use the 'color'
> * parameter and not the current attribute color (which may have changed
> * through glRasterPos and state validation.
> * So, we force the proper color here. Not elegant, but it works.
> */
> {
> GLfloat colorSave[4];
> COPY_4V(colorSave, ctx->Current.Attrib[VERT_ATTRIB_COLOR0]);
> COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], color);
> - st_upload_constants(st, st->fp->Base.Parameters, MESA_SHADER_FRAGMENT);
> + st_upload_constants(st, &st->fp->Base);
> COPY_4V(ctx->Current.Attrib[VERT_ATTRIB_COLOR0], colorSave);
> }
>
> cso_save_state(cso, (CSO_BIT_RASTERIZER |
> CSO_BIT_FRAGMENT_SAMPLERS |
> CSO_BIT_FRAGMENT_SAMPLER_VIEWS |
> CSO_BIT_VIEWPORT |
> CSO_BIT_STREAM_OUTPUTS |
> CSO_BIT_VERTEX_ELEMENTS |
> CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
> diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c
> index bc4e533..33d10f6 100644
> --- a/src/mesa/state_tracker/st_cb_drawpixels.c
> +++ b/src/mesa/state_tracker/st_cb_drawpixels.c
> @@ -1116,21 +1116,21 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
>
> if (ctx->Pixel.MapColorFlag) {
> pipe_sampler_view_reference(&sv[1],
> st->pixel_xfer.pixelmap_sampler_view);
> num_sampler_view++;
> }
>
> /* compiling a new fragment shader variant added new state constants
> * into the constant buffer, we need to update them
> */
> - st_upload_constants(st, st->fp->Base.Parameters, MESA_SHADER_FRAGMENT);
> + st_upload_constants(st, &st->fp->Base);
> }
>
> /* Put glDrawPixels image into a texture */
> pt = make_texture(st, width, height, format, type, unpack, pixels);
> if (!pt) {
> _mesa_error(ctx, GL_OUT_OF_MEMORY, "glDrawPixels");
> return;
> }
>
> /* create sampler view for the image */
> @@ -1479,21 +1479,21 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
>
> if (ctx->Pixel.MapColorFlag) {
> pipe_sampler_view_reference(&sv[1],
> st->pixel_xfer.pixelmap_sampler_view);
> num_sampler_view++;
> }
>
> /* compiling a new fragment shader variant added new state constants
> * into the constant buffer, we need to update them
> */
> - st_upload_constants(st, st->fp->Base.Parameters, MESA_SHADER_FRAGMENT);
> + st_upload_constants(st, &st->fp->Base);
> }
> else {
> assert(type == GL_DEPTH);
> rbRead = st_renderbuffer(ctx->ReadBuffer->
> Attachment[BUFFER_DEPTH].Renderbuffer);
>
> driver_fp = get_drawpix_z_stencil_program(st, GL_TRUE, GL_FALSE);
> driver_vp = make_passthrough_vertex_shader(st, GL_TRUE);
> }
>
>
More information about the mesa-dev
mailing list