[Mesa-dev] [PATCH 1/7] cso: add new cso_save/restore_state() functions
Jose Fonseca
jfonseca at vmware.com
Sat Feb 13 22:10:53 UTC 2016
On 12/02/16 15:44, Brian Paul wrote:
> cso_save_state() takes a bitmask of state items to save. Calling
> cso_restore_state() restores those states.
> ---
> src/gallium/auxiliary/cso_cache/cso_context.c | 109 ++++++++++++++++++++++++++
> src/gallium/auxiliary/cso_cache/cso_context.h | 24 ++++++
> 2 files changed, 133 insertions(+)
>
> diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
> index a05c1c7..cbddb06 100644
> --- a/src/gallium/auxiliary/cso_cache/cso_context.c
> +++ b/src/gallium/auxiliary/cso_cache/cso_context.c
> @@ -71,6 +71,8 @@ struct cso_context {
> boolean has_tessellation;
> boolean has_streamout;
>
> + unsigned saved_state; /**< bitmask of CSO_BIT_x flags */
> +
> struct pipe_sampler_view *fragment_views[PIPE_MAX_SHADER_SAMPLER_VIEWS];
> unsigned nr_fragment_views;
>
> @@ -1420,6 +1422,113 @@ cso_restore_constant_buffer_slot0(struct cso_context *cso,
> NULL);
> }
>
> +
> +/**
> + * Save all the CSO state items specified by the state_mask bitmask
> + * of CSO_BIT_x flags.
> + */
> +void
> +cso_save_state(struct cso_context *cso, unsigned state_mask)
> +{
> + assert(cso->saved_state == 0);
> +
> + cso->saved_state = state_mask;
> +
> + if (state_mask & CSO_BIT_AUX_VERTEX_BUFFER_SLOT)
> + cso_save_aux_vertex_buffer_slot(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)
> + cso_save_framebuffer(cso);
> + if (state_mask & CSO_BIT_GEOMETRY_SHADER)
> + cso_save_geometry_shader(cso);
> + if (state_mask & CSO_BIT_MIN_SAMPLES)
> + cso_save_min_samples(cso);
> + if (state_mask & CSO_BIT_RASTERIZER)
> + cso_save_rasterizer(cso);
> + if (state_mask & CSO_BIT_RENDER_CONDITION)
> + cso_save_render_condition(cso);
> + if (state_mask & CSO_BIT_SAMPLE_MASK)
> + cso_save_sample_mask(cso);
> + if (state_mask & CSO_BIT_STENCIL_REF)
> + cso_save_stencil_ref(cso);
> + if (state_mask & CSO_BIT_STREAM_OUTPUTS)
> + cso_save_stream_outputs(cso);
> + if (state_mask & CSO_BIT_TESSCTRL_SHADER)
> + cso_save_tessctrl_shader(cso);
> + if (state_mask & CSO_BIT_TESSEVAL_SHADER)
> + cso_save_tesseval_shader(cso);
> + if (state_mask & CSO_BIT_VERTEX_ELEMENTS)
> + cso_save_vertex_elements(cso);
> + if (state_mask & CSO_BIT_VERTEX_SHADER)
> + cso_save_vertex_shader(cso);
> + if (state_mask & CSO_BIT_VIEWPORT)
> + cso_save_viewport(cso);
> +}
> +
> +
> +/**
> + * Restore the state which was saved by cso_save_state().
> + */
> +void
> +cso_restore_state(struct cso_context *cso)
> +{
> + unsigned state_mask = cso->saved_state;
> +
> + assert(state_mask);
> +
> + if (state_mask & CSO_BIT_AUX_VERTEX_BUFFER_SLOT)
> + cso_restore_aux_vertex_buffer_slot(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)
> + cso_restore_framebuffer(cso);
> + if (state_mask & CSO_BIT_GEOMETRY_SHADER)
> + cso_restore_geometry_shader(cso);
> + if (state_mask & CSO_BIT_MIN_SAMPLES)
> + cso_restore_min_samples(cso);
> + if (state_mask & CSO_BIT_RASTERIZER)
> + cso_restore_rasterizer(cso);
> + if (state_mask & CSO_BIT_RENDER_CONDITION)
> + cso_restore_render_condition(cso);
> + if (state_mask & CSO_BIT_SAMPLE_MASK)
> + cso_restore_sample_mask(cso);
> + if (state_mask & CSO_BIT_STENCIL_REF)
> + cso_restore_stencil_ref(cso);
> + if (state_mask & CSO_BIT_STREAM_OUTPUTS)
> + cso_restore_stream_outputs(cso);
> + if (state_mask & CSO_BIT_TESSCTRL_SHADER)
> + cso_restore_tessctrl_shader(cso);
> + if (state_mask & CSO_BIT_TESSEVAL_SHADER)
> + cso_restore_tesseval_shader(cso);
> + if (state_mask & CSO_BIT_VERTEX_ELEMENTS)
> + cso_restore_vertex_elements(cso);
> + if (state_mask & CSO_BIT_VERTEX_SHADER)
> + cso_restore_vertex_shader(cso);
> + if (state_mask & CSO_BIT_VIEWPORT)
> + cso_restore_viewport(cso);
> +
> + cso->saved_state = 0;
> +}
> +
> +
> +
> /* drawing */
>
> void
> diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
> index 38bfb84..fa6fb18 100644
> --- a/src/gallium/auxiliary/cso_cache/cso_context.h
> +++ b/src/gallium/auxiliary/cso_cache/cso_context.h
> @@ -188,6 +188,30 @@ void cso_save_render_condition(struct cso_context *cso);
> void cso_restore_render_condition(struct cso_context *cso);
>
>
> +#define CSO_BIT_AUX_VERTEX_BUFFER_SLOT 0x1
> +#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
> +#define CSO_BIT_FRAGMENT_SHADER 0x20
> +#define CSO_BIT_FRAMEBUFFER 0x40
> +#define CSO_BIT_GEOMETRY_SHADER 0x80
> +#define CSO_BIT_MIN_SAMPLES 0x100
> +#define CSO_BIT_RASTERIZER 0x200
> +#define CSO_BIT_RENDER_CONDITION 0x400
> +#define CSO_BIT_SAMPLE_MASK 0x800
> +#define CSO_BIT_STENCIL_REF 0x1000
> +#define CSO_BIT_STREAM_OUTPUTS 0x2000
> +#define CSO_BIT_TESSCTRL_SHADER 0x4000
> +#define CSO_BIT_TESSEVAL_SHADER 0x8000
> +#define CSO_BIT_VERTEX_ELEMENTS 0x10000
> +#define CSO_BIT_VERTEX_SHADER 0x20000
> +#define CSO_BIT_VIEWPORT 0x40000
I think it might be worth defining a few CSO_BIT_ALL_xxxx with a common
flags combinations in a follow up change, so save typing elsewhere.
At least CSO_BIT_ALL_SHADERS makes sense.
> +
> +void cso_save_state(struct cso_context *cso, unsigned state_mask);
> +void cso_restore_state(struct cso_context *cso);
> +
> +
> /* sampler view state */
>
> void
>
Series looks good, except one of the patches I replied separately.
Another nice cleanup.
Reviewed-by: Jose Fonseca at vmware.com
More information about the mesa-dev
mailing list