X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fstate_tracker%2Fst_context.c;h=2fc4ffe672842d9ac779aaa22d8b2c9807341b16;hb=9037005d6034d6bcbeb508e0f783622e2351b957;hp=d0134bc3313d4a037b5b476e1c4955c6ec2bd894;hpb=28543f1640d459404413c244740291fe68a75a5c;p=mesa.git diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index d0134bc3313..2fc4ffe6728 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -25,7 +25,7 @@ * **************************************************************************/ -#include "main/imports.h" + #include "main/accum.h" #include "main/api_exec.h" #include "main/context.h" @@ -57,6 +57,7 @@ #include "st_cb_memoryobjects.h" #include "st_cb_msaa.h" #include "st_cb_perfmon.h" +#include "st_cb_perfquery.h" #include "st_cb_program.h" #include "st_cb_queryobj.h" #include "st_cb_readpixels.h" @@ -84,6 +85,7 @@ #include "util/u_inlines.h" #include "util/u_upload_mgr.h" #include "util/u_vbuf.h" +#include "util/u_memory.h" #include "cso_cache/cso_context.h" #include "compiler/glsl/glsl_parser_extras.h" @@ -104,6 +106,9 @@ st_Enable(struct gl_context *ctx, GLenum cap, GLboolean state) case GL_DEBUG_OUTPUT_SYNCHRONOUS: st_update_debug_callback(st); break; + case GL_BLACKHOLE_RENDER_INTEL: + st->pipe->set_frontend_noop(st->pipe, ctx->IntelBlackholeRender); + break; default: break; } @@ -137,18 +142,18 @@ st_query_memory_info(struct gl_context *ctx, struct gl_memory_info *out) static uint64_t st_get_active_states(struct gl_context *ctx) { - struct st_vertex_program *vp = - st_vertex_program(ctx->VertexProgram._Current); - struct st_common_program *tcp = - st_common_program(ctx->TessCtrlProgram._Current); - struct st_common_program *tep = - st_common_program(ctx->TessEvalProgram._Current); - struct st_common_program *gp = - st_common_program(ctx->GeometryProgram._Current); - struct st_fragment_program *fp = - st_fragment_program(ctx->FragmentProgram._Current); - struct st_common_program *cp = - st_common_program(ctx->ComputeProgram._Current); + struct st_program *vp = + st_program(ctx->VertexProgram._Current); + struct st_program *tcp = + st_program(ctx->TessCtrlProgram._Current); + struct st_program *tep = + st_program(ctx->TessEvalProgram._Current); + struct st_program *gp = + st_program(ctx->GeometryProgram._Current); + struct st_program *fp = + st_program(ctx->FragmentProgram._Current); + struct st_program *cp = + st_program(ctx->ComputeProgram._Current); uint64_t active_shader_states = 0; if (vp) @@ -214,13 +219,6 @@ st_invalidate_state(struct gl_context *ctx) if (new_state & _NEW_FOG) st->dirty |= ST_NEW_FS_STATE; - - if (new_state & _NEW_FRAG_CLAMP) { - if (st->clamp_frag_color_in_shader) - st->dirty |= ST_NEW_FS_STATE; - else - st->dirty |= ST_NEW_RASTERIZER; - } } if (new_state & (_NEW_LIGHT | @@ -307,7 +305,7 @@ st_save_zombie_sampler_view(struct st_context *st, * while free_zombie_resource_views() is called from another. */ simple_mtx_lock(&st->zombie_sampler_views.mutex); - LIST_ADDTAIL(&entry->node, &st->zombie_sampler_views.list.node); + list_addtail(&entry->node, &st->zombie_sampler_views.list.node); simple_mtx_unlock(&st->zombie_sampler_views.mutex); } @@ -340,7 +338,7 @@ st_save_zombie_shader(struct st_context *st, * while free_zombie_shaders() is called from another. */ simple_mtx_lock(&st->zombie_shaders.mutex); - LIST_ADDTAIL(&entry->node, &st->zombie_shaders.list.node); + list_addtail(&entry->node, &st->zombie_shaders.list.node); simple_mtx_unlock(&st->zombie_shaders.mutex); } @@ -353,7 +351,7 @@ free_zombie_sampler_views(struct st_context *st) { struct st_zombie_sampler_view_node *entry, *next; - if (LIST_IS_EMPTY(&st->zombie_sampler_views.list.node)) { + if (list_is_empty(&st->zombie_sampler_views.list.node)) { return; } @@ -361,7 +359,7 @@ free_zombie_sampler_views(struct st_context *st) LIST_FOR_EACH_ENTRY_SAFE(entry, next, &st->zombie_sampler_views.list.node, node) { - LIST_DEL(&entry->node); // remove this entry from the list + list_del(&entry->node); // remove this entry from the list assert(entry->view->context == st->pipe); pipe_sampler_view_reference(&entry->view, NULL); @@ -369,7 +367,7 @@ free_zombie_sampler_views(struct st_context *st) free(entry); } - assert(LIST_IS_EMPTY(&st->zombie_sampler_views.list.node)); + assert(list_is_empty(&st->zombie_sampler_views.list.node)); simple_mtx_unlock(&st->zombie_sampler_views.mutex); } @@ -383,7 +381,7 @@ free_zombie_shaders(struct st_context *st) { struct st_zombie_shader_node *entry, *next; - if (LIST_IS_EMPTY(&st->zombie_shaders.list.node)) { + if (list_is_empty(&st->zombie_shaders.list.node)) { return; } @@ -391,26 +389,32 @@ free_zombie_shaders(struct st_context *st) LIST_FOR_EACH_ENTRY_SAFE(entry, next, &st->zombie_shaders.list.node, node) { - LIST_DEL(&entry->node); // remove this entry from the list + list_del(&entry->node); // remove this entry from the list switch (entry->type) { case PIPE_SHADER_VERTEX: - cso_delete_vertex_shader(st->cso_context, entry->shader); + st->pipe->bind_vs_state(st->pipe, NULL); + st->pipe->delete_vs_state(st->pipe, entry->shader); break; case PIPE_SHADER_FRAGMENT: - cso_delete_fragment_shader(st->cso_context, entry->shader); + st->pipe->bind_fs_state(st->pipe, NULL); + st->pipe->delete_fs_state(st->pipe, entry->shader); break; case PIPE_SHADER_GEOMETRY: - cso_delete_geometry_shader(st->cso_context, entry->shader); + st->pipe->bind_gs_state(st->pipe, NULL); + st->pipe->delete_gs_state(st->pipe, entry->shader); break; case PIPE_SHADER_TESS_CTRL: - cso_delete_tessctrl_shader(st->cso_context, entry->shader); + st->pipe->bind_tcs_state(st->pipe, NULL); + st->pipe->delete_tcs_state(st->pipe, entry->shader); break; case PIPE_SHADER_TESS_EVAL: - cso_delete_tesseval_shader(st->cso_context, entry->shader); + st->pipe->bind_tes_state(st->pipe, NULL); + st->pipe->delete_tes_state(st->pipe, entry->shader); break; case PIPE_SHADER_COMPUTE: - cso_delete_compute_shader(st->cso_context, entry->shader); + st->pipe->bind_compute_state(st->pipe, NULL); + st->pipe->delete_compute_state(st->pipe, entry->shader); break; default: unreachable("invalid shader type in free_zombie_shaders()"); @@ -418,7 +422,7 @@ free_zombie_shaders(struct st_context *st) free(entry); } - assert(LIST_IS_EMPTY(&st->zombie_shaders.list.node)); + assert(list_is_empty(&st->zombie_shaders.list.node)); simple_mtx_unlock(&st->zombie_shaders.mutex); } @@ -453,6 +457,7 @@ st_destroy_context_priv(struct st_context *st, bool destroy_pipe) st_destroy_bound_image_handles(st); for (i = 0; i < ARRAY_SIZE(st->state.frag_sampler_views); i++) { + pipe_sampler_view_reference(&st->state.vert_sampler_views[i], NULL); pipe_sampler_view_reference(&st->state.frag_sampler_views[i], NULL); } @@ -529,7 +534,12 @@ st_init_driver_flags(struct st_context *st) f->NewClipControl = ST_NEW_VIEWPORT | ST_NEW_RASTERIZER; f->NewClipPlane = ST_NEW_CLIP_STATE; - f->NewClipPlaneEnable = ST_NEW_RASTERIZER; + + if (st->clamp_frag_color_in_shader) { + f->NewFragClamp = ST_NEW_FS_STATE; + } else { + f->NewFragClamp = ST_NEW_RASTERIZER; + } if (st->clamp_frag_depth_in_shader) { f->NewClipControl |= ST_NEW_VS_STATE | ST_NEW_GS_STATE | @@ -541,6 +551,11 @@ st_init_driver_flags(struct st_context *st) f->NewDepthClamp = ST_NEW_RASTERIZER; } + if (st->lower_ucp) + f->NewClipPlaneEnable = ST_NEW_VS_STATE; + else + f->NewClipPlaneEnable = ST_NEW_RASTERIZER; + f->NewLineState = ST_NEW_RASTERIZER; f->NewPolygonState = ST_NEW_RASTERIZER; f->NewPolygonStipple = ST_NEW_POLY_STIPPLE; @@ -565,10 +580,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->ctx = ctx; st->pipe = pipe; - - /* state tracker needs the VBO module */ - _vbo_CreateContext(ctx); - st->dirty = ST_ALL_STATES_MASK; st->can_bind_const_buffer_as_vertex = @@ -580,9 +591,21 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, * profile, so that u_vbuf is bypassed completely if there is nothing else * to do. */ - unsigned vbuf_flags = - ctx->API == API_OPENGL_CORE ? U_VBUF_FLAG_NO_USER_VBOS : 0; - st->cso_context = cso_create_context(pipe, vbuf_flags); + unsigned cso_flags; + switch (ctx->API) { + case API_OPENGL_CORE: + cso_flags = CSO_NO_USER_VERTEX_BUFFERS; + break; + case API_OPENGLES: + case API_OPENGLES2: + cso_flags = CSO_NO_64B_VERTEX_BUFFERS; + break; + default: + cso_flags = 0; + break; + } + + st->cso_context = cso_create_context(pipe, cso_flags); st_init_atoms(st); st_init_clear(st); @@ -600,28 +623,20 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, STATIC_ASSERT(sizeof(struct st_util_vertex) == 9 * sizeof(float)); memset(&st->util_velems, 0, sizeof(st->util_velems)); - st->util_velems[0].src_offset = 0; - st->util_velems[0].vertex_buffer_index = 0; - st->util_velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT; - st->util_velems[1].src_offset = 3 * sizeof(float); - st->util_velems[1].vertex_buffer_index = 0; - st->util_velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - st->util_velems[2].src_offset = 7 * sizeof(float); - st->util_velems[2].vertex_buffer_index = 0; - st->util_velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT; + st->util_velems.velems[0].src_offset = 0; + st->util_velems.velems[0].vertex_buffer_index = 0; + st->util_velems.velems[0].src_format = PIPE_FORMAT_R32G32B32_FLOAT; + st->util_velems.velems[1].src_offset = 3 * sizeof(float); + st->util_velems.velems[1].vertex_buffer_index = 0; + st->util_velems.velems[1].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + st->util_velems.velems[2].src_offset = 7 * sizeof(float); + st->util_velems.velems[2].vertex_buffer_index = 0; + st->util_velems.velems[2].src_format = PIPE_FORMAT_R32G32_FLOAT; } - /* we want all vertex data to be placed in buffer objects */ - vbo_use_buffer_objects(ctx); - - - /* make sure that no VBOs are left mapped when we're drawing. */ - vbo_always_unmap_buffers(ctx); - /* Need these flags: */ ctx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - ctx->VertexProgram._MaintainTnlProgram = GL_TRUE; if (no_error) @@ -646,6 +661,9 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->has_astc_2d_ldr = screen->is_format_supported(screen, PIPE_FORMAT_ASTC_4x4_SRGB, PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW); + st->has_astc_5x5_ldr = + screen->is_format_supported(screen, PIPE_FORMAT_ASTC_5x5_SRGB, + PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW); st->prefer_blit_based_texture_transfer = screen->get_param(screen, PIPE_CAP_PREFER_BLIT_BASED_TEXTURE_TRANSFER); st->force_persample_in_shader = @@ -671,8 +689,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, screen->get_param(screen, PIPE_CAP_INDEP_BLEND_FUNC); st->needs_rgb_dst_alpha_override = screen->get_param(screen, PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND); - st->has_signed_vertex_buffer_offset = - screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET); st->lower_flatshade = !screen->get_param(screen, PIPE_CAP_FLATSHADE); st->lower_alpha_test = @@ -681,6 +697,9 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, !screen->get_param(screen, PIPE_CAP_POINT_SIZE_FIXED); st->lower_two_sided_color = !screen->get_param(screen, PIPE_CAP_TWO_SIDED_COLOR); + st->lower_ucp = + !screen->get_param(screen, PIPE_CAP_CLIP_PLANES); + st->allow_st_finalize_nir_twice = screen->finalize_nir != NULL; st->has_hw_atomics = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT, @@ -696,10 +715,26 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st_init_extensions(pipe->screen, &ctx->Const, &ctx->Extensions, &st->options, ctx->API); + /* FIXME: add support for geometry and tessellation shaders for + * lower_point_size + */ + assert(!ctx->Extensions.OES_geometry_shader || !st->lower_point_size); + assert(!ctx->Extensions.ARB_tessellation_shader || !st->lower_point_size); + + /* FIXME: add support for geometry and tessellation shaders for + * lower_ucp + */ + assert(!ctx->Extensions.OES_geometry_shader || !st->lower_ucp); + assert(!ctx->Extensions.ARB_tessellation_shader || !st->lower_ucp); + if (st_have_perfmon(st)) { ctx->Extensions.AMD_performance_monitor = GL_TRUE; } + if (st_have_perfquery(st)) { + ctx->Extensions.INTEL_performance_query = GL_TRUE; + } + /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */ if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) { if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) { @@ -735,6 +770,13 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].EmitNoSat = !screen->get_param(screen, PIPE_CAP_VERTEX_SHADER_SATURATE); + ctx->Const.ShaderCompilerOptions[MESA_SHADER_VERTEX].PositionAlwaysInvariant = options->vs_position_always_invariant; + + enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir) + screen->get_shader_param(screen, PIPE_SHADER_VERTEX, + PIPE_SHADER_CAP_PREFERRED_IR); + ctx->Const.UseNIRGLSLLinker = preferred_ir == PIPE_SHADER_IR_NIR; + if (ctx->Const.GLSLVersion < 400) { for (i = 0; i < MESA_SHADER_STAGES; i++) ctx->Const.ShaderCompilerOptions[i].EmitNoIndirectSampler = true; @@ -745,7 +787,8 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, st->has_shareable_shaders && !st->clamp_frag_depth_in_shader && !st->clamp_vert_color_in_shader && - !st->lower_point_size; + !st->lower_point_size && + !st->lower_ucp; st->shader_has_one_variant[MESA_SHADER_FRAGMENT] = st->has_shareable_shaders && @@ -780,16 +823,21 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, return NULL; } + /* This must be done after extensions are initialized to enable persistent + * mappings immediately. + */ + _vbo_CreateContext(ctx, true); + _mesa_initialize_dispatch_tables(ctx); _mesa_initialize_vbo_vtxfmt(ctx); st_init_driver_flags(st); /* Initialize context's winsys buffers list */ - LIST_INITHEAD(&st->winsys_buffers); + list_inithead(&st->winsys_buffers); - LIST_INITHEAD(&st->zombie_sampler_views.list.node); + list_inithead(&st->zombie_sampler_views.list.node); simple_mtx_init(&st->zombie_sampler_views.mutex, mtx_plain); - LIST_INITHEAD(&st->zombie_shaders.list.node); + list_inithead(&st->zombie_shaders.list.node); simple_mtx_init(&st->zombie_shaders.mutex, mtx_plain); return st; @@ -863,6 +911,7 @@ st_init_driver_functions(struct pipe_screen *screen, st_init_memoryobject_functions(functions); st_init_msaa_functions(functions); st_init_perfmon_functions(functions); + st_init_perfquery_functions(functions); st_init_program_functions(functions); st_init_query_functions(functions); st_init_cond_render_functions(functions); @@ -940,8 +989,7 @@ st_create_context(gl_api api, struct pipe_context *pipe, st_debug_init(); - if (pipe->screen->get_disk_shader_cache && - !(ST_DEBUG & DEBUG_TGSI)) + if (pipe->screen->get_disk_shader_cache) ctx->Cache = pipe->screen->get_disk_shader_cache(pipe->screen); /* XXX: need a capability bit in gallium to query if the pipe @@ -1034,12 +1082,12 @@ st_destroy_context(struct st_context *st) simple_mtx_destroy(&st->zombie_sampler_views.mutex); simple_mtx_destroy(&st->zombie_shaders.mutex); - st_reference_fragprog(st, &st->fp, NULL); - st_reference_prog(st, &st->gp, NULL); - st_reference_vertprog(st, &st->vp, NULL); - st_reference_prog(st, &st->tcp, NULL); - st_reference_prog(st, &st->tep, NULL); - st_reference_compprog(st, &st->cp, NULL); + st_release_program(st, &st->fp); + st_release_program(st, &st->gp); + st_release_program(st, &st->vp); + st_release_program(st, &st->tcp); + st_release_program(st, &st->tep); + st_release_program(st, &st->cp); /* release framebuffer in the winsys buffers list */ LIST_FOR_EACH_ENTRY_SAFE_REV(stfb, next, &st->winsys_buffers, head) { @@ -1055,7 +1103,7 @@ st_destroy_context(struct st_context *st) st_destroy_program_variants(st); - _mesa_free_context_data(ctx, false); + _mesa_free_context_data(ctx); /* This will free the st_context too, so 'st' must not be accessed * afterwards. */