[virglrenderer-devel] [PATCH] features: convert current feature list to an array
Gert Wollny
gert.wollny at collabora.com
Mon Jul 23 17:39:58 UTC 2018
Am Montag, den 23.07.2018, 21:02 +1000 schrieb Dave Airlie:
> From: Dave Airlie <airlied at redhat.com>
>
> Instead of having the features in separate named bool, convert it
> to an array of bools indexed by an enum.
>
> This is a straight mechanical patch, no code flows should change
> and it doesn't change any functionality, it just refactors the
> code to use the enum list and a bool array.
>
> Future work should be a lot easier on this, so I'd like to
> land it first.
> ---
> src/vrend_renderer.c | 249 +++++++++++++++++++++++----------------
> ----
> 1 file changed, 132 insertions(+), 117 deletions(-)
>
> diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
> index 13a61bb..e011815 100644
> --- a/src/vrend_renderer.c
> +++ b/src/vrend_renderer.c
> @@ -87,6 +87,34 @@ struct global_error_state {
> enum virgl_errors last_error;
> };
>
> +enum features_id
> +{
> + FEAT_MESA_INVERT,
> + FEAT_SAMPLERS,
> + FEAT_GLES_KHR_ROBUSTNESS,
> + FEAT_ARB_ROBUSTNESS,
> + FEAT_ARB_OR_GLES_EXT_TEXTURE_BUFFER,
> + FEAT_MULTISAMPLE,
> + FEAT_MS_SCALED_BLIT,
> + FEAT_NV_PRIM_RESTART,
> + FEAT_GL_PRIM_RESTART,
> + FEAT_GL_CONDITIONAL_RENDER,
> + FEAT_NV_CONDITIONAL_RENDER,
> + FEAT_BIT_ENCODING,
> + FEAT_GLES31_VERTEX_ATTRIB_BINDING,
> + FEAT_TF2,
Team Fortress 2? One can probably always see from the context that its
transform feedback, but still ...
> + FEAT_STENCIL_TEXTURING,
> + FEAT_SAMPLE_SHADING,
> + FEAT_TEXTURE_BUFFER_RANGE,
> + FEAT_POLYGON_OFFSET_CLAMP,
> + FEAT_TEXTURE_STORAGE,
> + FEAT_TESSELLATION,
> + FEAT_TEXTURE_VIEW,
> + FEAT_COPY_IMAGE,
> + FEAT_SSBO,
> + FEAT_LAST,
> +};
Can we have lower-case enums? and like Elie wrote, alphabetic ordering
would be nice too
> +
> struct global_renderer_state {
> int gl_major_ver;
> int gl_minor_ver;
> @@ -99,31 +127,8 @@ struct global_renderer_state {
> bool use_gles;
> bool use_core_profile;
>
> + bool features[FEAT_LAST];
> bool have_debug_cb;
Didn't want to change this too?
All just nits, change as you see fit
Reviewed-By: Gert Wollny <gert.wollny at collabora.com>
> - bool have_mesa_invert;
> - bool have_samplers;
> - bool have_gles_khr_robustness;
> - bool have_arb_robustness;
> - bool have_arb_or_gles_ext_texture_buffer;
> - bool have_multisample;
> - bool have_ms_scaled_blit;
> - bool have_nv_prim_restart;
> - bool have_gl_prim_restart;
> - bool have_gl_conditional_render;
> - bool have_nv_conditional_render;
> - bool have_bit_encoding;
> - bool have_gles31_vertex_attrib_binding;
> - bool have_tf2;
> - bool have_stencil_texturing;
> - bool have_sample_shading;
> - bool have_texture_buffer_range;
> - bool have_polygon_offset_clamp;
> - bool have_texture_storage;
> - bool have_tessellation;
> - bool have_texture_view;
> - bool have_copy_image;
> - bool have_ssbo;
> -
> /* these appeared broken on at least one driver */
> bool use_explicit_locations;
> uint32_t max_uniform_blocks;
> @@ -145,6 +150,16 @@ struct global_renderer_state {
>
> static struct global_renderer_state vrend_state;
>
> +static inline bool has_feature(enum features_id feature_id)
> +{
> + return vrend_state.features[feature_id];
> +}
> +
> +static inline void set_feature(enum features_id feature_id)
> +{
> + vrend_state.features[feature_id] = true;
> +}
> +
> struct vrend_linked_shader_program {
> struct list_head head;
> struct list_head sl[PIPE_SHADER_TYPES];
> @@ -1072,7 +1087,7 @@ static struct vrend_linked_shader_program
> *add_shader_program(struct vrend_conte
> } else
> sprog->dual_src_linked = false;
>
> - if (vrend_state.have_gles31_vertex_attrib_binding) {
> + if (has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> uint32_t mask = vs->sel->sinfo.attrib_input_mask;
> while (mask) {
> i = u_bit_scan(&mask);
> @@ -1135,7 +1150,7 @@ static struct vrend_linked_shader_program
> *add_shader_program(struct vrend_conte
> bind_ssbo_locs(sprog, id);
> }
>
> - if (!vrend_state.have_gles31_vertex_attrib_binding) {
> + if (!has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> if (vs->sel->sinfo.num_inputs) {
> sprog->attrib_locs = calloc(vs->sel->sinfo.num_inputs,
> sizeof(uint32_t));
> if (sprog->attrib_locs) {
> @@ -1226,7 +1241,7 @@ static void
> vrend_destroy_streamout_object(struct vrend_streamout_object *obj)
> list_del(&obj->head);
> for (i = 0; i < obj->num_targets; i++)
> vrend_so_target_reference(&obj->so_targets[i], NULL);
> - if (vrend_state.have_tf2)
> + if (has_feature(FEAT_TF2))
> glDeleteTransformFeedbacks(1, &obj->id);
> FREE(obj);
> }
> @@ -1260,7 +1275,7 @@ int vrend_create_surface(struct vrend_context
> *ctx,
> surf->val1 = val1;
> surf->id = res->id;
>
> - if (vrend_state.have_texture_view && !res->is_buffer) {
> + if (has_feature(FEAT_TEXTURE_VIEW) && !res->is_buffer) {
> /* We don't need texture views for buffer objects.
> * Otherwise we only need a texture view if the
> * a) formats differ between the surface and base texture
> @@ -1329,10 +1344,10 @@ static void
> vrend_destroy_so_target_object(void *obj_ptr)
> if (obj == sub_ctx->current_so)
> sub_ctx->current_so = NULL;
> if (obj->xfb_state == XFB_STATE_PAUSED) {
> - if (vrend_state.have_tf2)
> + if (has_feature(FEAT_TF2))
> glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
> obj->id);
> glEndTransformFeedback();
> - if (sub_ctx->current_so && vrend_state.have_tf2)
> + if (sub_ctx->current_so && has_feature(FEAT_TF2))
> glBindTransformFeedback(GL_TRANSFORM_FEEDBACK,
> sub_ctx->current_so->id);
> }
> vrend_destroy_streamout_object(obj);
> @@ -1346,7 +1361,7 @@ static void
> vrend_destroy_vertex_elements_object(void *obj_ptr)
> {
> struct vrend_vertex_element_array *v = obj_ptr;
>
> - if (vrend_state.have_gles31_vertex_attrib_binding) {
> + if (has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> glDeleteVertexArrays(1, &v->id);
> }
> FREE(v);
> @@ -1356,7 +1371,7 @@ static void
> vrend_destroy_sampler_state_object(void *obj_ptr)
> {
> struct vrend_sampler_state *state = obj_ptr;
>
> - if (vrend_state.have_samplers)
> + if (has_feature(FEAT_SAMPLERS))
> glDeleteSamplers(1, &state->id);
> FREE(state);
> }
> @@ -1418,7 +1433,7 @@ int vrend_create_sampler_state(struct
> vrend_context *ctx,
>
> state->base = *templ;
>
> - if (vrend_state.have_samplers) {
> + if (has_feature(FEAT_SAMPLERS)) {
> glGenSamplers(1, &state->id);
>
> glSamplerParameteri(state->id, GL_TEXTURE_WRAP_S,
> convert_wrap(templ->wrap_s));
> @@ -1444,7 +1459,7 @@ int vrend_create_sampler_state(struct
> vrend_context *ctx,
> ret_handle = vrend_renderer_object_insert(ctx, state,
> sizeof(struct vrend_sampler_state), handle,
> VIRGL_OBJECT_SAMPLER_ST
> ATE);
> if (!ret_handle) {
> - if (vrend_state.have_samplers)
> + if (has_feature(FEAT_SAMPLERS))
> glDeleteSamplers(1, &state->id);
> FREE(state);
> return ENOMEM;
> @@ -1506,7 +1521,7 @@ int vrend_create_sampler_view(struct
> vrend_context *ctx,
> if (!view->target)
> view->target = view->texture->target;
>
> - if (vrend_state.have_texture_view && !view->texture-
> >is_buffer) {
> + if (has_feature(FEAT_TEXTURE_VIEW) && !view->texture-
> >is_buffer) {
> enum pipe_format format;
> bool needs_view = false;
>
> @@ -2003,7 +2018,7 @@ int vrend_create_vertex_elements_state(struct
> vrend_context *ctx,
> v->elements[i].nr_chan = desc->nr_channels;
> }
>
> - if (vrend_state.have_gles31_vertex_attrib_binding) {
> + if (has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> glGenVertexArrays(1, &v->id);
> glBindVertexArray(v->id);
> for (i = 0; i < num_elements; i++) {
> @@ -2208,7 +2223,7 @@ void vrend_set_single_sampler_view(struct
> vrend_context *ctx,
> view->depth_texture_mode = GL_RED;
> }
> }
> - if (vrend_state.have_stencil_texturing) {
> + if (has_feature(FEAT_STENCIL_TEXTURING)) {
> const struct util_format_description *desc =
> util_format_description(view->format);
> if (!util_format_has_depth(desc)) {
> glTexParameteri(view->texture->target,
> GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
> @@ -2243,7 +2258,7 @@ void vrend_set_single_sampler_view(struct
> vrend_context *ctx,
> view->cur_swizzle_a = view->gl_swizzle_a;
> }
> if (view->cur_srgb_decode != view->srgb_decode &&
> util_format_is_srgb(view->format)) {
> - if (vrend_state.have_samplers)
> + if (has_feature(FEAT_SAMPLERS))
> ctx->sub->sampler_state_dirty = true;
> else {
> glTexParameteri(view->texture->target,
> GL_TEXTURE_SRGB_DECODE_EXT,
> @@ -2259,7 +2274,7 @@ void vrend_set_single_sampler_view(struct
> vrend_context *ctx,
>
> glBindTexture(GL_TEXTURE_BUFFER, view->texture-
> >tbo_tex_id);
> internalformat = tex_conv_table[view-
> >format].internalformat;
> - if (vrend_state.have_texture_buffer_range) {
> + if (has_feature(FEAT_TEXTURE_BUFFER_RANGE)) {
> unsigned offset = view->val0;
> unsigned size = view->val1 - view->val0 + 1;
> int blsize = util_format_get_blocksize(view->format);
> @@ -2566,7 +2581,7 @@ int vrend_create_shader(struct vrend_context
> *ctx,
> if (type > PIPE_SHADER_TESS_EVAL)
> return EINVAL;
>
> - if (!vrend_state.have_tessellation &&
> + if (!has_feature(FEAT_TESSELLATION) &&
> (type == PIPE_SHADER_TESS_CTRL ||
> type == PIPE_SHADER_TESS_EVAL))
> return EINVAL;
> @@ -2993,7 +3008,7 @@ static void
> vrend_draw_bind_vertex_legacy(struct vrend_context *ctx,
> continue;
> }
>
> - if (vrend_state.use_explicit_locations ||
> vrend_state.have_gles31_vertex_attrib_binding) {
> + if (vrend_state.use_explicit_locations ||
> has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> loc = i;
> } else {
> if (ctx->sub->prog->attrib_locs) {
> @@ -3390,7 +3405,7 @@ void vrend_draw_vbo(struct vrend_context *ctx,
> }
> }
>
> - if (vrend_state.have_gles31_vertex_attrib_binding)
> + if (has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING))
> vrend_draw_bind_vertex_binding(ctx, ctx->sub->ve);
> else
> vrend_draw_bind_vertex_legacy(ctx, ctx->sub->ve);
> @@ -3430,10 +3445,10 @@ void vrend_draw_vbo(struct vrend_context
> *ctx,
> if (info->primitive_restart) {
> if (vrend_state.use_gles) {
> glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
> - } else if (vrend_state.have_nv_prim_restart) {
> + } else if (has_feature(FEAT_NV_PRIM_RESTART)) {
> glEnableClientState(GL_PRIMITIVE_RESTART_NV);
> glPrimitiveRestartIndexNV(info->restart_index);
> - } else if (vrend_state.have_gl_prim_restart) {
> + } else if (has_feature(FEAT_GL_PRIM_RESTART)) {
> glEnable(GL_PRIMITIVE_RESTART);
> glPrimitiveRestartIndex(info->restart_index);
> }
> @@ -3444,7 +3459,7 @@ void vrend_draw_vbo(struct vrend_context *ctx,
> else
> glBindBuffer(GL_DRAW_INDIRECT_BUFFER, 0);
>
> - if (info->vertices_per_patch && vrend_state.have_tessellation)
> + if (info->vertices_per_patch && has_feature(FEAT_TESSELLATION))
> glPatchParameteri(GL_PATCH_VERTICES, info-
> >vertices_per_patch);
>
> /* set the vertex state up now on a delay */
> @@ -3497,14 +3512,14 @@ void vrend_draw_vbo(struct vrend_context
> *ctx,
> if (info->primitive_restart) {
> if (vrend_state.use_gles) {
> glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
> - } else if (vrend_state.have_nv_prim_restart) {
> + } else if (has_feature(FEAT_NV_PRIM_RESTART)) {
> glDisableClientState(GL_PRIMITIVE_RESTART_NV);
> - } else if (vrend_state.have_gl_prim_restart) {
> + } else if (has_feature(FEAT_GL_PRIM_RESTART)) {
> glDisable(GL_PRIMITIVE_RESTART);
> }
> }
>
> - if (ctx->sub->current_so && vrend_state.have_tf2) {
> + if (ctx->sub->current_so && has_feature(FEAT_TF2)) {
> if (ctx->sub->current_so->xfb_state == XFB_STATE_STARTED) {
> glPauseTransformFeedback();
> ctx->sub->current_so->xfb_state = XFB_STATE_PAUSED;
> @@ -3708,7 +3723,7 @@ static void vrend_hw_emit_blend(struct
> vrend_context *ctx, struct pipe_blend_sta
> }
> ctx->sub->hw_blend_state.independent_blend_enable = state-
> >independent_blend_enable;
>
> - if (vrend_state.have_multisample) {
> + if (has_feature(FEAT_MULTISAMPLE)) {
> if (state->alpha_to_coverage)
> glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
> else
> @@ -4039,7 +4054,7 @@ static void vrend_hw_emit_rs(struct
> vrend_context *ctx)
> }
> }
>
> - if (!vrend_state.use_gles &&
> vrend_state.have_polygon_offset_clamp)
> + if (!vrend_state.use_gles &&
> has_feature(FEAT_POLYGON_OFFSET_CLAMP))
> glPolygonOffsetClampEXT(state->offset_scale, state-
> >offset_units, state->offset_clamp);
> else
> glPolygonOffset(state->offset_scale, state->offset_units);
> @@ -4154,7 +4169,7 @@ static void vrend_hw_emit_rs(struct
> vrend_context *ctx)
> report_core_warn(ctx, CORE_PROFILE_WARN_CLAMP, 0);
> }
>
> - if (vrend_state.have_multisample) {
> + if (has_feature(FEAT_MULTISAMPLE)) {
> if (state->multisample)
> glEnable(GL_SAMPLE_MASK);
> else
> @@ -4168,7 +4183,7 @@ static void vrend_hw_emit_rs(struct
> vrend_context *ctx)
> glDisable(GL_MULTISAMPLE);
> }
>
> - if (vrend_state.have_sample_shading) {
> + if (has_feature(FEAT_SAMPLE_SHADING)) {
> if (state->force_persample_interp)
> glEnable(GL_SAMPLE_SHADING);
> else
> @@ -4265,7 +4280,7 @@ static void vrend_apply_sampler_state(struct
> vrend_context *ctx,
> * the sampler to use the red channel and not the alpha one
> * by swizzling the GL_TEXTURE_BORDER_COLOR parameter.
> */
> - if (vrend_state.have_samplers) {
> + if (has_feature(FEAT_SAMPLERS)) {
> if (vrend_format_is_emulated_alpha(res->base.format)) {
> union pipe_color_union border_color;
> border_color = vstate->base.border_color;
> @@ -4582,79 +4597,79 @@ int vrend_renderer_init(struct vrend_if_cbs
> *cbs, uint32_t flags)
> glGetIntegerv(GL_MAX_DRAW_BUFFERS, (GLint *)
> &vrend_state.max_draw_buffers);
>
> if (epoxy_has_gl_extension("GL_ARB_robustness")) {
> - vrend_state.have_arb_robustness = true;
> + set_feature(FEAT_ARB_ROBUSTNESS);
> } else if (gles && epoxy_has_gl_extension("GL_KHR_robustness")) {
> - vrend_state.have_gles_khr_robustness = true;
> + set_feature(FEAT_GLES_KHR_ROBUSTNESS);
> } else {
> fprintf(stderr,"WARNING: running without ARB/KHR robustness in
> place may crash\n");
> }
>
> /* used for buffers that we want to texture from */
> if (epoxy_has_gl_extension("GL_ARB_texture_buffer_object")) {
> - vrend_state.have_arb_or_gles_ext_texture_buffer = true;
> + set_feature(FEAT_ARB_OR_GLES_EXT_TEXTURE_BUFFER);
> }
> if (gles && epoxy_has_gl_extension("GL_EXT_texture_buffer")) {
> - vrend_state.have_arb_or_gles_ext_texture_buffer = true;
> + set_feature(FEAT_ARB_OR_GLES_EXT_TEXTURE_BUFFER);
> }
>
> if (epoxy_has_gl_extension("GL_MESA_pack_invert"))
> - vrend_state.have_mesa_invert = true;
> + set_feature(FEAT_MESA_INVERT);
> if (gl_ver >= 43 || (gles && gl_ver >= 31) ||
> epoxy_has_gl_extension("GL_ARB_vertex_attrib_binding"))
> - vrend_state.have_gles31_vertex_attrib_binding = true;
> + set_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING);
> if (gl_ver >= 33 ||
> epoxy_has_gl_extension("GL_ARB_sampler_objects"))
> - vrend_state.have_samplers = true;
> + set_feature(FEAT_SAMPLERS);
> if (gl_ver >= 33 ||
> epoxy_has_gl_extension("GL_ARB_shader_bit_encoding"))
> - vrend_state.have_bit_encoding = true;
> + set_feature(FEAT_BIT_ENCODING);
> if (!gles && gl_ver >= 31)
> - vrend_state.have_gl_prim_restart = true;
> + set_feature(FEAT_GL_PRIM_RESTART);
> else if (epoxy_has_gl_extension("GL_NV_primitive_restart"))
> - vrend_state.have_nv_prim_restart = true;
> + set_feature(FEAT_NV_PRIM_RESTART);
> if (!gles && gl_ver >= 30)
> - vrend_state.have_gl_conditional_render = true;
> + set_feature(FEAT_GL_CONDITIONAL_RENDER);
> else if (epoxy_has_gl_extension("GL_NV_conditional_render"))
> - vrend_state.have_nv_conditional_render = true;
> + set_feature(FEAT_NV_CONDITIONAL_RENDER);
> if (gl_ver >= 40 || (gles && gl_ver >= 30) ||
> epoxy_has_gl_extension("GL_ARB_transform_feedback2")) {
> - vrend_state.have_tf2 = true;
> + set_feature(FEAT_TF2);
> }
>
> if (epoxy_has_gl_extension("GL_ARB_stencil_texturing"))
> - vrend_state.have_stencil_texturing = true;
> + set_feature(FEAT_STENCIL_TEXTURING);
> if ((gles && gl_ver >= 30) ||
> (epoxy_has_gl_extension("GL_EXT_framebuffer_multisample") &&
> epoxy_has_gl_extension("GL_ARB_texture_multisample"))) {
> - vrend_state.have_multisample = true;
> + set_feature(FEAT_MULTISAMPLE);
> if
> (epoxy_has_gl_extension("GL_EXT_framebuffer_multisample_blit_scaled")
> )
> - vrend_state.have_ms_scaled_blit = true;
> + set_feature(FEAT_MS_SCALED_BLIT);
> }
>
> if (gl_ver >= 40 ||
> epoxy_has_gl_extension("GL_ARB_sample_shading"))
> - vrend_state.have_sample_shading = true;
> + set_feature(FEAT_SAMPLE_SHADING);
>
> if (gl_ver >= 40 ||
> epoxy_has_gl_extension("GL_ARB_tessellation_shader"))
> - vrend_state.have_tessellation = true;
> + set_feature(FEAT_TESSELLATION);
>
> if (gl_ver >= 43 ||
> epoxy_has_gl_extension("GL_ARB_texture_buffer_range"))
> - vrend_state.have_texture_buffer_range = true;
> + set_feature(FEAT_TEXTURE_BUFFER_RANGE);
>
> if (gl_ver >= 42 ||
> epoxy_has_gl_extension("GL_ARB_texture_storage"))
> - vrend_state.have_texture_storage = true;
> + set_feature(FEAT_TEXTURE_STORAGE);
>
> if (gl_ver >= 43 ||
> epoxy_has_gl_extension("GL_ARB_texture_view"))
> - vrend_state.have_texture_view = true;
> + set_feature(FEAT_TEXTURE_VIEW);
>
> if (gl_ver >= 43 ||
> epoxy_has_gl_extension("GL_ARB_shader_storage_buffer_object"))
> - vrend_state.have_ssbo = true;
> + set_feature(FEAT_SSBO);
>
> if (gl_ver >= 46 ||
> epoxy_has_gl_extension("GL_ARB_polygon_offset_clamp"))
> - vrend_state.have_polygon_offset_clamp = true;
> + set_feature(FEAT_POLYGON_OFFSET_CLAMP);
>
> if (gl_ver >= 43 || (gles && gl_ver >= 32) ||
> epoxy_has_gl_extension("GL_ARB_copy_image") ||
> epoxy_has_gl_extension("GL_EXT_copy_image") ||
> epoxy_has_gl_extension("GL_OES_copy_image"))
> - vrend_state.have_copy_image = true;
> + set_feature(FEAT_COPY_IMAGE);
>
> /* callbacks for when we are cleaning up the object table */
> vrend_resource_set_destroy_callback(vrend_destroy_resource_object
> );
> @@ -4734,7 +4749,7 @@ static void vrend_destroy_sub_context(struct
> vrend_sub_context *sub)
>
> glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
>
> - if (!vrend_state.have_gles31_vertex_attrib_binding) {
> + if (!has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> while (sub->enabled_attribs_bitmask) {
> i = u_bit_scan(&sub->enabled_attribs_bitmask);
>
> @@ -5061,7 +5076,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> return EINVAL;
> }
> } else if (pr->nr_samples > 1) {
> - if (vrend_state.use_gles || vrend_state.have_texture_storage)
> {
> + if (vrend_state.use_gles || has_feature(FEAT_TEXTURE_STORAGE))
> {
> if (gr->target == GL_TEXTURE_2D_MULTISAMPLE) {
> glTexStorage2DMultisample(gr->target, pr->nr_samples,
> internalformat, pr->width0,
> pr->height0,
> @@ -5084,7 +5099,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> }
> } else if (gr->target == GL_TEXTURE_CUBE_MAP) {
> int i;
> - if (vrend_state.have_texture_storage)
> + if (has_feature(FEAT_TEXTURE_STORAGE))
> glTexStorage2D(GL_TEXTURE_CUBE_MAP, pr->last_level + 1,
> internalformat, pr->width0, pr->height0);
> else {
> for (i = 0; i < 6; i++) {
> @@ -5101,7 +5116,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> } else if (gr->target == GL_TEXTURE_3D ||
> gr->target == GL_TEXTURE_2D_ARRAY ||
> gr->target == GL_TEXTURE_CUBE_MAP_ARRAY) {
> - if (vrend_state.have_texture_storage) {
> + if (has_feature(FEAT_TEXTURE_STORAGE)) {
> unsigned depth_param = (gr->target == GL_TEXTURE_2D_ARRAY
> || gr->target == GL_TEXTURE_CUBE_MAP_ARRAY) ?
> pr->array_size : pr->depth0;
> glTexStorage3D(gr->target, pr->last_level + 1,
> internalformat, pr->width0, pr->height0, depth_param);
> @@ -5118,7 +5133,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> } else if (gr->target == GL_TEXTURE_1D && vrend_state.use_gles) {
> report_gles_missing_func(NULL, "glTexImage1D");
> } else if (gr->target == GL_TEXTURE_1D) {
> - if (vrend_state.have_texture_storage) {
> + if (has_feature(FEAT_TEXTURE_STORAGE)) {
> glTexStorage1D(gr->target, pr->last_level + 1,
> internalformat, pr->width0);
> } else {
> for (level = 0; level <= pr->last_level; level++) {
> @@ -5128,7 +5143,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> }
> }
> } else {
> - if (vrend_state.have_texture_storage)
> + if (has_feature(FEAT_TEXTURE_STORAGE))
> glTexStorage2D(gr->target, pr->last_level + 1,
> internalformat, pr->width0,
> gr->target == GL_TEXTURE_1D_ARRAY ? pr-
> >array_size : pr->height0);
> else {
> @@ -5142,7 +5157,7 @@ static int
> vrend_renderer_resource_allocate_texture(struct vrend_resource *gr,
> }
> }
>
> - if (!vrend_state.have_texture_storage) {
> + if (!has_feature(FEAT_TEXTURE_STORAGE)) {
> glTexParameteri(gr->target, GL_TEXTURE_BASE_LEVEL, 0);
> glTexParameteri(gr->target, GL_TEXTURE_MAX_LEVEL, pr-
> >last_level);
> }
> @@ -5205,7 +5220,7 @@ int vrend_renderer_resource_create(struct
> vrend_renderer_resource_create_args *a
> #endif
>
> /* need to check GL version here */
> - if (vrend_state.have_arb_or_gles_ext_texture_buffer) {
> + if (has_feature(FEAT_ARB_OR_GLES_EXT_TEXTURE_BUFFER)) {
> gr->target = GL_TEXTURE_BUFFER;
> } else {
> gr->target = GL_PIXEL_PACK_BUFFER_ARB;
> @@ -5776,7 +5791,7 @@ static int
> vrend_transfer_send_getteximage(struct vrend_context *ctx,
> target = res->target;
>
> if (compressed) {
> - if (vrend_state.have_arb_robustness) {
> + if (has_feature(FEAT_ARB_ROBUSTNESS)) {
> glGetnCompressedTexImageARB(target, info->level, tex_size,
> data);
> } else if (vrend_state.use_gles) {
> report_gles_missing_func(ctx, "glGetCompressedTexImage");
> @@ -5784,7 +5799,7 @@ static int
> vrend_transfer_send_getteximage(struct vrend_context *ctx,
> glGetCompressedTexImage(target, info->level, data);
> }
> } else {
> - if (vrend_state.have_arb_robustness) {
> + if (has_feature(FEAT_ARB_ROBUSTNESS)) {
> glGetnTexImageARB(target, info->level, format, type,
> tex_size, data);
> } else if (vrend_state.use_gles) {
> report_gles_missing_func(ctx, "glGetTexImage");
> @@ -5827,7 +5842,7 @@ static int
> vrend_transfer_send_readpixels(struct vrend_context *ctx,
>
> actually_invert = res->y_0_top;
>
> - if (actually_invert && !vrend_state.have_mesa_invert)
> + if (actually_invert && !has_feature(FEAT_MESA_INVERT))
> separate_invert = true;
>
> if (num_iovs > 1 || separate_invert)
> @@ -5866,7 +5881,7 @@ static int
> vrend_transfer_send_readpixels(struct vrend_context *ctx,
> else
> y1 = info->box->y;
>
> - if (vrend_state.have_mesa_invert && actually_invert)
> + if (has_feature(FEAT_MESA_INVERT) && actually_invert)
> glPixelStorei(GL_PACK_INVERT_MESA, 1);
> if (!vrend_format_is_ds(res->base.format))
> glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
> @@ -5927,9 +5942,9 @@ static int
> vrend_transfer_send_readpixels(struct vrend_context *ctx,
> }
> }
>
> - if (vrend_state.have_arb_robustness)
> + if (has_feature(FEAT_ARB_ROBUSTNESS))
> glReadnPixelsARB(info->box->x, y1, info->box->width, info-
> >box->height, format, type, send_size, data);
> - else if (vrend_state.have_gles_khr_robustness)
> + else if (has_feature(FEAT_GLES_KHR_ROBUSTNESS))
> glReadnPixelsKHR(info->box->x, y1, info->box->width, info-
> >box->height, format, type, send_size, data);
> else
> glReadPixels(info->box->x, y1, info->box->width, info->box-
> >height, format, type, data);
> @@ -5940,7 +5955,7 @@ static int
> vrend_transfer_send_readpixels(struct vrend_context *ctx,
> else
> vrend_scale_depth(data, send_size, depth_scale);
> }
> - if (vrend_state.have_mesa_invert && actually_invert)
> + if (has_feature(FEAT_MESA_INVERT) && actually_invert)
> glPixelStorei(GL_PACK_INVERT_MESA, 0);
> if (!need_temp && info->stride)
> glPixelStorei(GL_PACK_ROW_LENGTH, 0);
> @@ -6217,13 +6232,13 @@ void vrend_set_min_samples(struct
> vrend_context *ctx, unsigned min_samples)
> min_sample_shading /= MAX2(1, ctx->sub->surf[0]->texture-
> >base.nr_samples);
> }
>
> - if (vrend_state.have_sample_shading)
> + if (has_feature(FEAT_SAMPLE_SHADING))
> glMinSampleShading(min_sample_shading);
> }
>
> void vrend_set_tess_state(UNUSED struct vrend_context *ctx, const
> float tess_factors[6])
> {
> - if (vrend_state.have_tessellation) {
> + if (has_feature(FEAT_TESSELLATION)) {
> glPatchParameterfv(GL_PATCH_DEFAULT_OUTER_LEVEL,
> tess_factors);
> glPatchParameterfv(GL_PATCH_DEFAULT_INNER_LEVEL,
> &tess_factors[4]);
> }
> @@ -6267,7 +6282,7 @@ void vrend_set_streamout_targets(struct
> vrend_context *ctx,
> }
>
> obj = CALLOC_STRUCT(vrend_streamout_object);
> - if (vrend_state.have_tf2) {
> + if (has_feature(FEAT_TF2)) {
> glGenTransformFeedbacks(1, &obj->id);
> glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, obj->id);
> }
> @@ -6287,7 +6302,7 @@ void vrend_set_streamout_targets(struct
> vrend_context *ctx,
> ctx->sub->current_so = obj;
> obj->xfb_state = XFB_STATE_STARTED_NEED_BEGIN;
> } else {
> - if (vrend_state.have_tf2)
> + if (has_feature(FEAT_TF2))
> glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
> ctx->sub->current_so = NULL;
> }
> @@ -6403,12 +6418,12 @@ static void
> vrend_resource_copy_fallback(struct vrend_resource *src_res,
> GLenum ctarget = src_res->target == GL_TEXTURE_CUBE_MAP ?
> (GLenum)(GL_TEXTURE_CUBE_MAP_POSITIVE_X
> + i) : src_res->target;
> if (compressed) {
> - if (vrend_state.have_arb_robustness)
> + if (has_feature(FEAT_ARB_ROBUSTNESS))
> glGetnCompressedTexImageARB(ctarget, src_level,
> read_chunk_size, tptr + slice_offset);
> else
> glGetCompressedTexImage(ctarget, src_level, tptr +
> slice_offset);
> } else {
> - if (vrend_state.have_arb_robustness)
> + if (has_feature(FEAT_ARB_ROBUSTNESS))
> glGetnTexImageARB(ctarget, src_level, glformat,
> gltype, read_chunk_size, tptr + slice_offset);
> else
> glGetTexImage(ctarget, src_level, glformat, gltype,
> tptr + slice_offset);
> @@ -6519,7 +6534,7 @@ void vrend_renderer_resource_copy_region(struct
> vrend_context *ctx,
> return;
> }
>
> - if (vrend_state.have_copy_image) {
> + if (has_feature(FEAT_COPY_IMAGE)) {
> if (format_is_copy_compatible(src_res->base.format,dst_res-
> >base.format) &&
> src_res->base.nr_samples == dst_res->base.nr_samples) {
> vrend_copy_sub_image(src_res, dst_res, src_level, src_box,
> @@ -6627,7 +6642,7 @@ static void vrend_renderer_blit_int(struct
> vrend_context *ctx,
> src_res->base.nr_samples != dst_res->base.nr_samples &&
> (info->src.box.width != info->dst.box.width ||
> info->src.box.height != info->dst.box.height)) {
> - if (vrend_state.have_ms_scaled_blit)
> + if (has_feature(FEAT_MS_SCALED_BLIT))
> filter = GL_SCALED_RESOLVE_NICEST_EXT;
> else
> use_gl = true;
> @@ -6808,7 +6823,7 @@ void vrend_renderer_blit(struct vrend_context
> *ctx,
> * glCopyImageSubData. For the latter case forward the call to
> the
> * glCopyImageSubData function, otherwise use a framebuffer blit.
> */
> - if (vrend_state.have_copy_image && !info->render_condition_enable
> &&
> + if (has_feature(FEAT_COPY_IMAGE) && !info-
> >render_condition_enable &&
> format_is_copy_compatible(info->src.format,info->dst.format)
> &&
> !info->scissor_enable && (info->filter ==
> PIPE_TEX_FILTER_NEAREST) &&
> !info->alpha_blend && (info->mask == PIPE_MASK_RGBA) &&
> @@ -7151,17 +7166,17 @@ static void
> vrend_pause_render_condition(struct vrend_context *ctx, bool pause)
> {
> if (pause) {
> if (ctx->sub->cond_render_q_id) {
> - if (vrend_state.have_gl_conditional_render)
> + if (has_feature(FEAT_GL_CONDITIONAL_RENDER))
> glEndConditionalRender();
> - else if (vrend_state.have_nv_conditional_render)
> + else if (has_feature(FEAT_NV_CONDITIONAL_RENDER))
> glEndConditionalRenderNV();
> }
> } else {
> if (ctx->sub->cond_render_q_id) {
> - if (vrend_state.have_gl_conditional_render)
> + if (has_feature(FEAT_GL_CONDITIONAL_RENDER))
> glBeginConditionalRender(ctx->sub->cond_render_q_id,
> ctx->sub->cond_render_gl_mode);
> - else if (vrend_state.have_nv_conditional_render)
> + else if (has_feature(FEAT_NV_CONDITIONAL_RENDER))
> glBeginConditionalRenderNV(ctx->sub->cond_render_q_id,
> ctx->sub-
> >cond_render_gl_mode);
> }
> @@ -7177,9 +7192,9 @@ void vrend_render_condition(struct
> vrend_context *ctx,
> GLenum glmode = 0;
>
> if (handle == 0) {
> - if (vrend_state.have_gl_conditional_render)
> + if (has_feature(FEAT_GL_CONDITIONAL_RENDER))
> glEndConditionalRender();
> - else if (vrend_state.have_nv_conditional_render)
> + else if (has_feature(FEAT_NV_CONDITIONAL_RENDER))
> glEndConditionalRenderNV();
> ctx->sub->cond_render_q_id = 0;
> ctx->sub->cond_render_gl_mode = 0;
> @@ -7209,9 +7224,9 @@ void vrend_render_condition(struct
> vrend_context *ctx,
>
> ctx->sub->cond_render_q_id = q->id;
> ctx->sub->cond_render_gl_mode = glmode;
> - if (vrend_state.have_gl_conditional_render)
> + if (has_feature(FEAT_GL_CONDITIONAL_RENDER))
> glBeginConditionalRender(q->id, glmode);
> - if (vrend_state.have_nv_conditional_render)
> + if (has_feature(FEAT_NV_CONDITIONAL_RENDER))
> glBeginConditionalRenderNV(q->id, glmode);
> }
>
> @@ -7383,8 +7398,8 @@ static bool
> vrend_renderer_fill_caps_common(uint32_t set, UNUSED uint32_t versio
>
>
> /* These are filled in by the init code, so are common. */
> - if (vrend_state.have_nv_prim_restart ||
> - vrend_state.have_gl_prim_restart) {
> + if (has_feature(FEAT_NV_PRIM_RESTART) ||
> + has_feature(FEAT_GL_PRIM_RESTART)) {
> caps->v1.bset.primitive_restart = 1;
> }
>
> @@ -7514,7 +7529,7 @@ static void
> vrend_renderer_fill_caps_gles(uint32_t set, UNUSED uint32_t version,
>
> caps->v1.max_samples = vrend_renderer_query_multisample_caps(max,
> &caps->v2);
>
> - if (vrend_state.have_copy_image)
> + if (has_feature(FEAT_COPY_IMAGE))
> caps->v2.capability_bits |= VIRGL_CAP_COPY_IMAGE;
> }
>
> @@ -7763,7 +7778,7 @@ void vrend_renderer_fill_caps(uint32_t set,
> uint32_t version,
> if (gl_ver >= 43 ||
> epoxy_has_gl_extension("GL_ARB_texture_view"))
> caps->v2.capability_bits |= VIRGL_CAP_TEXTURE_VIEW;
>
> - if (vrend_state.have_copy_image)
> + if (has_feature(FEAT_COPY_IMAGE))
> caps->v2.capability_bits |= VIRGL_CAP_COPY_IMAGE;
> }
>
> @@ -7810,7 +7825,7 @@ void
> *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t
> *width, u
> return NULL;
> }
>
> - if (vrend_state.have_arb_robustness) {
> + if (has_feature(FEAT_ARB_ROBUSTNESS)) {
> glBindTexture(res->target, res->id);
> glGetnTexImageARB(res->target, 0, format, type, size, data);
> } else if (vrend_state.use_gles) {
> @@ -7833,9 +7848,9 @@ void
> *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t
> *width, u
> glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, res-
> >readback_fb_id);
> }
>
> - if (vrend_state.have_arb_robustness) {
> + if (has_feature(FEAT_ARB_ROBUSTNESS)) {
> glReadnPixelsARB(0, 0, *width, *height, format, type, size,
> data);
> - } else if (vrend_state.have_gles_khr_robustness) {
> + } else if (has_feature(FEAT_GLES_KHR_ROBUSTNESS)) {
> glReadnPixelsKHR(0, 0, *width, *height, format, type, size,
> data);
> } else {
> glReadPixels(0, 0, *width, *height, format, type, data);
> @@ -8016,7 +8031,7 @@ void vrend_renderer_create_sub_ctx(struct
> vrend_context *ctx, int sub_ctx_id)
> sub->vps[i].far_val = 1.0;
> }
>
> - if (!vrend_state.have_gles31_vertex_attrib_binding) {
> + if (!has_feature(FEAT_GLES31_VERTEX_ATTRIB_BINDING)) {
> glGenVertexArrays(1, &sub->vaoid);
> glBindVertexArray(sub->vaoid);
> }
More information about the virglrenderer-devel
mailing list