From: Nicolai Hähnle <nicolai.haeh...@amd.com> --- src/gallium/auxiliary/pipe-loader/pipe_loader.c | 29 +++++++++++++++ src/gallium/auxiliary/pipe-loader/pipe_loader.h | 14 ++++++++ .../auxiliary/pipe-loader/pipe_loader_drm.c | 3 +- .../auxiliary/pipe-loader/pipe_loader_priv.h | 11 ++++++ src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c | 3 +- src/gallium/state_trackers/dri/dri2.c | 18 +++++----- src/gallium/state_trackers/dri/dri_context.c | 3 +- src/gallium/state_trackers/dri/dri_screen.c | 41 ++++------------------ src/gallium/state_trackers/dri/dri_screen.h | 10 +----- src/gallium/state_trackers/dri/drisw.c | 2 +- 10 files changed, 76 insertions(+), 58 deletions(-)
diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.c b/src/gallium/auxiliary/pipe-loader/pipe_loader.c index bb65be1..95e6b42 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.c @@ -24,20 +24,21 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * **************************************************************************/ #include "pipe_loader_priv.h" #include "util/u_inlines.h" #include "util/u_memory.h" #include "util/u_string.h" #include "util/u_dl.h" +#include "util/xmlconfig.h" #include "util/xmlpool.h" #ifdef _MSC_VER #include <stdlib.h> #define PATH_MAX _MAX_PATH #endif #define MODULE_PREFIX "pipe_" static int (*backends[])(struct pipe_loader_device **, int) = { @@ -64,27 +65,55 @@ pipe_loader_probe(struct pipe_loader_device **devs, int ndev) void pipe_loader_release(struct pipe_loader_device **devs, int ndev) { int i; for (i = 0; i < ndev; i++) devs[i]->ops->release(&devs[i]); } +void +pipe_loader_base_release(struct pipe_loader_device **dev) +{ + driDestroyOptionCache(&(*dev)->option_cache); + driDestroyOptionInfo(&(*dev)->option_info); + + FREE(*dev); + *dev = NULL; +} + const struct drm_conf_ret * pipe_loader_configuration(struct pipe_loader_device *dev, enum drm_conf conf) { return dev->ops->configuration(dev, conf); } +void +pipe_loader_load_options(struct pipe_loader_device *dev) +{ + if (dev->option_info.info) + return; + + const char *xml_options = gallium_driinfo_xml; + const struct drm_conf_ret *xml_options_conf = + pipe_loader_configuration(dev, DRM_CONF_XML_OPTIONS); + + if (xml_options_conf) + xml_options = xml_options_conf->val.val_pointer; + + driParseOptionInfo(&dev->option_info, xml_options); + driParseConfigFiles(&dev->option_cache, &dev->option_info, 0, + dev->driver_name); +} + struct pipe_screen * pipe_loader_create_screen(struct pipe_loader_device *dev, struct pipe_screen_config *config) { return dev->ops->create_screen(dev, config); } struct util_dl_library * pipe_loader_find_module(struct pipe_loader_device *dev, const char *library_paths) diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader.h b/src/gallium/auxiliary/pipe-loader/pipe_loader.h index d24480d..a4502ae 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader.h +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader.h @@ -28,20 +28,21 @@ /** * \file Library that provides device enumeration and creation of * winsys/pipe_screen instances. */ #ifndef PIPE_LOADER_H #define PIPE_LOADER_H #include "pipe/p_compiler.h" #include "state_tracker/drm_driver.h" +#include "util/xmlconfig.h" #ifdef __cplusplus extern "C" { #endif struct pipe_screen; struct drisw_loader_funcs; enum pipe_loader_device_type { PIPE_LOADER_DEVICE_SOFTWARE, @@ -58,20 +59,23 @@ struct pipe_loader_device { union { struct { int vendor_id; int chip_id; } pci; } u; /**< Discriminated by \a type */ char *driver_name; const struct pipe_loader_ops *ops; + + driOptionCache option_cache; + driOptionCache option_info; }; /** * Get a list of known devices. * * \param devs Array that will be filled with pointers to the devices * available in the system. * \param ndev Maximum number of devices to return. * \return Number of devices available in the system. */ @@ -93,20 +97,30 @@ pipe_loader_create_screen(struct pipe_loader_device *dev, * Query the configuration parameters for the specified device. * * \param dev Device that will be queried. * \param conf The drm_conf id of the option to be queried. */ const struct drm_conf_ret * pipe_loader_configuration(struct pipe_loader_device *dev, enum drm_conf conf); /** + * Ensure that dev->option_cache is initialized appropriately for the driver. + * + * This function can be called multiple times. + * + * \param dev Device for which options should be loaded. + */ +void +pipe_loader_load_options(struct pipe_loader_device *dev); + +/** * Release resources allocated for a list of devices. * * Should be called when the specified devices are no longer in use to * release any resources allocated by pipe_loader_probe. * * \param devs Devices to release. * \param ndev Number of devices to release. */ void pipe_loader_release(struct pipe_loader_device **devs, int ndev); diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c index 385d814..193c8dd 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c @@ -257,22 +257,21 @@ pipe_loader_drm_release(struct pipe_loader_device **dev) { struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(*dev); #ifndef GALLIUM_STATIC_TARGETS if (ddev->lib) util_dl_close(ddev->lib); #endif close(ddev->fd); FREE(ddev->base.driver_name); - FREE(ddev); - *dev = NULL; + pipe_loader_base_release(dev); } static const struct drm_conf_ret * pipe_loader_drm_configuration(struct pipe_loader_device *dev, enum drm_conf conf) { struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(dev); if (!ddev->dd->configuration) return NULL; diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_priv.h b/src/gallium/auxiliary/pipe-loader/pipe_loader_priv.h index 7708455..37219fb 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_priv.h +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_priv.h @@ -40,11 +40,22 @@ struct pipe_loader_ops { void (*release)(struct pipe_loader_device **dev); }; /** * Open the pipe driver module that handles a specified device. */ struct util_dl_library * pipe_loader_find_module(struct pipe_loader_device *dev, const char *library_paths); +/** + * Free the base device structure. + * + * Implementations of pipe_loader_ops::release must call this. + * + * (*dev)->driver_name must be freed by the caller if it was allocated on the + * heap. + */ +void +pipe_loader_base_release(struct pipe_loader_device **dev); + #endif /* PIPE_LOADER_PRIV_H */ diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c index 3c8e0c2..696ba2c 100644 --- a/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c +++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_sw.c @@ -275,22 +275,21 @@ pipe_loader_sw_release(struct pipe_loader_device **dev) #ifndef GALLIUM_STATIC_TARGETS if (sdev->lib) util_dl_close(sdev->lib); #endif #ifdef HAVE_PIPE_LOADER_KMS if (sdev->fd != -1) close(sdev->fd); #endif - FREE(sdev); - *dev = NULL; + pipe_loader_base_release(dev); } static const struct drm_conf_ret * pipe_loader_sw_configuration(struct pipe_loader_device *dev, enum drm_conf conf) { return NULL; } static struct pipe_screen * diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c index 2dceb1d..6f2b634 100644 --- a/src/gallium/state_trackers/dri/dri2.c +++ b/src/gallium/state_trackers/dri/dri2.c @@ -1913,57 +1913,57 @@ static const __DRI2interopExtension dri2InteropExtension = { /** * \brief the DRI2ConfigQueryExtension configQueryb method */ static int dri2GalliumConfigQueryb(__DRIscreen *sPriv, const char *var, unsigned char *val) { struct dri_screen *screen = dri_screen(sPriv); - if (!driCheckOption(&screen->optionCache, var, DRI_BOOL)) + if (!driCheckOption(&screen->dev->option_cache, var, DRI_BOOL)) return dri2ConfigQueryExtension.configQueryb(sPriv, var, val); - *val = driQueryOptionb(&screen->optionCache, var); + *val = driQueryOptionb(&screen->dev->option_cache, var); return 0; } /** * \brief the DRI2ConfigQueryExtension configQueryi method */ static int dri2GalliumConfigQueryi(__DRIscreen *sPriv, const char *var, int *val) { struct dri_screen *screen = dri_screen(sPriv); - if (!driCheckOption(&screen->optionCache, var, DRI_INT) && - !driCheckOption(&screen->optionCache, var, DRI_ENUM)) + if (!driCheckOption(&screen->dev->option_cache, var, DRI_INT) && + !driCheckOption(&screen->dev->option_cache, var, DRI_ENUM)) return dri2ConfigQueryExtension.configQueryi(sPriv, var, val); - *val = driQueryOptioni(&screen->optionCache, var); + *val = driQueryOptioni(&screen->dev->option_cache, var); return 0; } /** * \brief the DRI2ConfigQueryExtension configQueryf method */ static int dri2GalliumConfigQueryf(__DRIscreen *sPriv, const char *var, float *val) { struct dri_screen *screen = dri_screen(sPriv); - if (!driCheckOption(&screen->optionCache, var, DRI_FLOAT)) + if (!driCheckOption(&screen->dev->option_cache, var, DRI_FLOAT)) return dri2ConfigQueryExtension.configQueryf(sPriv, var, val); - *val = driQueryOptionf(&screen->optionCache, var); + *val = driQueryOptionf(&screen->dev->option_cache, var); return 0; } /** * \brief the DRI2ConfigQueryExtension struct. * * We first query the driver option cache. Then the dri2 option cache. */ static const __DRI2configQueryExtension dri2GalliumConfigQueryExtension = { @@ -2029,21 +2029,21 @@ dri2_init_screen(__DRIscreen * sPriv) sPriv->driverPrivate = (void *)screen; if (screen->fd < 0 || (fd = fcntl(screen->fd, F_DUPFD_CLOEXEC, 3)) < 0) goto free_screen; if (pipe_loader_drm_probe_fd(&screen->dev, fd)) { struct pipe_screen_config config = {}; config.flags = - dri_init_options_get_screen_flags(screen, screen->dev->driver_name); + dri_init_options_get_screen_flags(screen); pscreen = pipe_loader_create_screen(screen->dev, &config); } if (!pscreen) goto release_pipe; throttle_ret = pipe_loader_configuration(screen->dev, DRM_CONF_THROTTLE); dmabuf_ret = pipe_loader_configuration(screen->dev, DRM_CONF_SHARE_FD); @@ -2124,21 +2124,21 @@ dri_kms_init_screen(__DRIscreen * sPriv) screen->sPriv = sPriv; screen->fd = sPriv->fd; sPriv->driverPrivate = (void *)screen; if (screen->fd < 0 || (fd = fcntl(screen->fd, F_DUPFD_CLOEXEC, 3)) < 0) goto free_screen; struct pipe_screen_config config = {}; - config.flags = dri_init_options_get_screen_flags(screen, "swrast"); + config.flags = dri_init_options_get_screen_flags(screen); if (pipe_loader_sw_probe_kms(&screen->dev, fd)) pscreen = pipe_loader_create_screen(screen->dev, &config); if (!pscreen) goto release_pipe; if (pscreen->resource_create_with_modifiers) dri2ImageExtension.createImageWithModifiers = dri2_create_image_with_modifiers; diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c index ec555e4..a3e5020 100644 --- a/src/gallium/state_trackers/dri/dri_context.c +++ b/src/gallium/state_trackers/dri/dri_context.c @@ -30,20 +30,21 @@ */ #include "utils.h" #include "dri_screen.h" #include "dri_drawable.h" #include "dri_context.h" #include "state_tracker/drm_driver.h" #include "pipe/p_context.h" +#include "pipe-loader/pipe_loader.h" #include "state_tracker/st_context.h" GLboolean dri_create_context(gl_api api, const struct gl_config * visual, __DRIcontext * cPriv, unsigned major_version, unsigned minor_version, uint32_t flags, bool notify_reset, unsigned *error, @@ -153,21 +154,21 @@ dri_create_context(gl_api api, const struct gl_config * visual, ctx->st->st_manager_private = (void *) ctx; ctx->stapi = stapi; if (ctx->st->cso_context) { ctx->pp = pp_init(ctx->st->pipe, screen->pp_enabled, ctx->st->cso_context); ctx->hud = hud_create(ctx->st->pipe, ctx->st->cso_context); } /* Do this last. */ if (ctx->st->start_thread && - driQueryOptionb(&screen->optionCache, "mesa_glthread")) { + driQueryOptionb(&screen->dev->option_cache, "mesa_glthread")) { if (backgroundCallable && backgroundCallable->base.version >= 2 && backgroundCallable->isThreadSafe) { if (backgroundCallable->isThreadSafe(cPriv->loaderPrivate)) ctx->st->start_thread(ctx->st); else fprintf(stderr, "dri_create_context: glthread isn't thread safe " "- missing call XInitThreads\n"); } else { diff --git a/src/gallium/state_trackers/dri/dri_screen.c b/src/gallium/state_trackers/dri/dri_screen.c index 2117dbb..c130091 100644 --- a/src/gallium/state_trackers/dri/dri_screen.c +++ b/src/gallium/state_trackers/dri/dri_screen.c @@ -52,21 +52,21 @@ const __DRIconfigOptionsExtension gallium_config_options = { .base = { __DRI_CONFIG_OPTIONS, 1 }, .xml = gallium_driinfo_xml }; #define false 0 static void dri_fill_st_options(struct dri_screen *screen) { struct st_config_options *options = &screen->options; - const struct driOptionCache *optionCache = &screen->optionCache; + const struct driOptionCache *optionCache = &screen->dev->option_cache; options->disable_blend_func_extended = driQueryOptionb(optionCache, "disable_blend_func_extended"); options->disable_glsl_line_continuations = driQueryOptionb(optionCache, "disable_glsl_line_continuations"); options->disable_shader_bit_encoding = driQueryOptionb(optionCache, "disable_shader_bit_encoding"); options->force_glsl_extensions_warn = driQueryOptionb(optionCache, "force_glsl_extensions_warn"); options->force_glsl_version = @@ -111,21 +111,21 @@ dri_fill_in_modes(struct dri_screen *screen) unsigned msaa_samples_max; unsigned i; struct pipe_screen *p_screen = screen->base.screen; boolean pf_z16, pf_x8z24, pf_z24x8, pf_s8z24, pf_z24s8, pf_z32; boolean mixed_color_depth; static const GLenum back_buffer_modes[] = { GLX_NONE, GLX_SWAP_UNDEFINED_OML, GLX_SWAP_COPY_OML }; - if (driQueryOptionb(&screen->optionCache, "always_have_depth_buffer")) { + if (driQueryOptionb(&screen->dev->option_cache, "always_have_depth_buffer")) { /* all visuals will have a depth buffer */ depth_buffer_factor = 0; } else { depth_bits_array[0] = 0; stencil_bits_array[0] = 0; depth_buffer_factor = 1; } msaa_samples_max = (screen->st_api->feature_mask & ST_API_FEATURE_MS_VISUALS_MASK) @@ -342,52 +342,29 @@ dri_get_param(struct st_manager *smapi, struct dri_screen *screen = (struct dri_screen *)smapi; switch(param) { case ST_MANAGER_BROKEN_INVALIDATE: return screen->broken_invalidate; default: return 0; } } -static void -dri_destroy_option_cache(struct dri_screen * screen) -{ - int i; - - if (screen->optionCache.info) { - for (i = 0; i < (1 << screen->optionCache.tableSize); ++i) { - free(screen->optionCache.info[i].name); - free(screen->optionCache.info[i].ranges); - } - free(screen->optionCache.info); - } - - free(screen->optionCache.values); - - /* Default values are copied to screen->optionCache->values in - * initOptionCache. The info field, however, is a pointer copy, so don't free - * that twice. - */ - free(screen->optionCacheDefaults.values); -} - void dri_destroy_screen_helper(struct dri_screen * screen) { if (screen->st_api && screen->st_api->destroy) screen->st_api->destroy(screen->st_api); if (screen->base.screen) screen->base.screen->destroy(screen->base.screen); - dri_destroy_option_cache(screen); mtx_destroy(&screen->opencl_func_mutex); } void dri_destroy_screen(__DRIscreen * sPriv) { struct dri_screen *screen = dri_screen(sPriv); dri_destroy_screen_helper(screen); @@ -397,21 +374,21 @@ dri_destroy_screen(__DRIscreen * sPriv) sPriv->driverPrivate = NULL; sPriv->extensions = NULL; } static void dri_postprocessing_init(struct dri_screen *screen) { unsigned i; for (i = 0; i < PP_FILTERS; i++) { - screen->pp_enabled[i] = driQueryOptioni(&screen->optionCache, + screen->pp_enabled[i] = driQueryOptioni(&screen->dev->option_cache, pp_filters[i].name); } } static void dri_set_background_context(struct st_context_iface *st, struct util_queue_monitoring *queue_info) { struct dri_context *ctx = (struct dri_context *)st->st_manager_private; const __DRIbackgroundCallableExtension *backgroundCallable = @@ -422,33 +399,29 @@ dri_set_background_context(struct st_context_iface *st, * extension. So we know that backgroundCallable is not NULL. */ assert(backgroundCallable); backgroundCallable->setBackgroundContext(ctx->cPriv->loaderPrivate); if (ctx->hud) hud_add_queue_for_monitoring(ctx->hud, queue_info); } unsigned -dri_init_options_get_screen_flags(struct dri_screen *screen, - const char* driver_name) +dri_init_options_get_screen_flags(struct dri_screen *screen) { unsigned flags = 0; - driParseOptionInfo(&screen->optionCacheDefaults, gallium_config_options.xml); - driParseConfigFiles(&screen->optionCache, - &screen->optionCacheDefaults, - screen->sPriv->myNum, - driver_name); + pipe_loader_load_options(screen->dev); + dri_fill_st_options(screen); - if (driQueryOptionb(&screen->optionCache, + if (driQueryOptionb(&screen->dev->option_cache, "glsl_correct_derivatives_after_discard")) flags |= PIPE_SCREEN_ENABLE_CORRECT_TGSI_DERIVATIVES_AFTER_KILL; return flags; } const __DRIconfig ** dri_init_screen_helper(struct dri_screen *screen, struct pipe_screen *pscreen) { diff --git a/src/gallium/state_trackers/dri/dri_screen.h b/src/gallium/state_trackers/dri/dri_screen.h index 383e762..b8b27c3 100644 --- a/src/gallium/state_trackers/dri/dri_screen.h +++ b/src/gallium/state_trackers/dri/dri_screen.h @@ -26,21 +26,20 @@ **************************************************************************/ /* * Author: Keith Whitwell <kei...@vmware.com> * Author: Jakob Bornecrantz <wallbra...@gmail.com> */ #ifndef DRI_SCREEN_H #define DRI_SCREEN_H #include "dri_util.h" -#include "util/xmlconfig.h" #include "pipe/p_compiler.h" #include "pipe/p_context.h" #include "pipe/p_state.h" #include "state_tracker/st_api.h" #include "state_tracker/opencl_interop.h" #include "os/os_thread.h" #include "postprocess/filters.h" struct dri_context; @@ -54,26 +53,20 @@ struct dri_screen struct st_api *st_api; /* on old libGL's invalidate doesn't get called as it should */ boolean broken_invalidate; /* dri */ __DRIscreen *sPriv; boolean throttling_enabled; int default_throttle_frames; - /** Configuration cache with default values for all contexts */ - driOptionCache optionCacheDefaults; - - /** The screen's effective configuration options */ - driOptionCache optionCache; - struct st_config_options options; /* Which postprocessing filters are enabled. */ unsigned pp_enabled[PP_FILTERS]; /* drm */ int fd; boolean can_share_buffer; struct pipe_loader_device *dev; @@ -131,22 +124,21 @@ dri_with_format(__DRIscreen * sPriv) return loader && (loader->base.version >= 3) && (loader->getBuffersWithFormat != NULL); } void dri_fill_st_visual(struct st_visual *stvis, struct dri_screen *screen, const struct gl_config *mode); unsigned -dri_init_options_get_screen_flags(struct dri_screen *screen, - const char* driver_name); +dri_init_options_get_screen_flags(struct dri_screen *screen); const __DRIconfig ** dri_init_screen_helper(struct dri_screen *screen, struct pipe_screen *pscreen); void dri_destroy_screen_helper(struct dri_screen * screen); void dri_destroy_screen(__DRIscreen * sPriv); diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c index 2e3ab96..f89857c 100644 --- a/src/gallium/state_trackers/dri/drisw.c +++ b/src/gallium/state_trackers/dri/drisw.c @@ -394,21 +394,21 @@ drisw_init_screen(__DRIscreen * sPriv) screen->sPriv = sPriv; screen->fd = -1; swrast_no_present = debug_get_option_swrast_no_present(); sPriv->driverPrivate = (void *)screen; sPriv->extensions = drisw_screen_extensions; struct pipe_screen_config config; - config.flags = dri_init_options_get_screen_flags(screen, "swrast"); + config.flags = dri_init_options_get_screen_flags(screen); if (pipe_loader_sw_probe_dri(&screen->dev, &drisw_lf)) pscreen = pipe_loader_create_screen(screen->dev, &config); if (!pscreen) goto fail; configs = dri_init_screen_helper(screen, pscreen); if (!configs) goto fail; -- 2.9.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev