[Mesa-dev] [PATCH 3/9] dri: Change __DriverApiRec::CreateContext to take a struct for attribs
Nicolai Hähnle
nhaehnle at gmail.com
Fri Nov 3 09:50:27 UTC 2017
On 02.11.2017 20:01, Adam Jackson wrote:
> From: Neil Roberts <neil at linux.intel.com>
>
> Previously the CreateContext method of __DriverApiRec took a set of
> arguments to describe the attribute values from the window system API's
> CreateContextAttribs function. As more attributes get added this could
> quickly get unworkable and every new attribute needs a modification for
> every driver.
>
> To fix that, pass the attribute values in a struct instead. The struct
> has a bitmask to specify which members are used. The first three members
> (two for the GL version and one for the flags) are always set. If the
> bit is not set in the attribute mask then it can be assumed the
> attribute has the default value. Drivers will error if unknown bits in
> the mask are set.
>
> Reviewed-by: Adam Jackson <ajax at redhat.com>
> Signed-off-by: Neil Roberts <neil at linux.intel.com>
> ---
> src/gallium/state_trackers/dri/dri_context.c | 32 +++++++--------
> src/gallium/state_trackers/dri/dri_context.h | 6 +--
> src/mesa/drivers/dri/common/dri_util.c | 57 +++++++++++++++-----------
> src/mesa/drivers/dri/common/dri_util.h | 39 +++++++++++++++---
> src/mesa/drivers/dri/i915/intel_screen.c | 20 ++++-----
> src/mesa/drivers/dri/i965/brw_context.c | 45 +++++++++++---------
> src/mesa/drivers/dri/i965/brw_context.h | 6 +--
> src/mesa/drivers/dri/nouveau/nouveau_context.c | 15 +++----
> src/mesa/drivers/dri/nouveau/nouveau_context.h | 3 +-
> src/mesa/drivers/dri/r200/r200_context.c | 12 ++----
> src/mesa/drivers/dri/r200/r200_context.h | 7 +---
> src/mesa/drivers/dri/radeon/radeon_context.c | 12 ++----
> src/mesa/drivers/dri/radeon/radeon_context.h | 7 +---
> src/mesa/drivers/dri/swrast/swrast.c | 16 ++++----
> 14 files changed, 149 insertions(+), 128 deletions(-)
>
> diff --git a/src/gallium/state_trackers/dri/dri_context.c b/src/gallium/state_trackers/dri/dri_context.c
> index 8776aacc09..73910e1df3 100644
> --- a/src/gallium/state_trackers/dri/dri_context.c
> +++ b/src/gallium/state_trackers/dri/dri_context.c
> @@ -43,11 +43,7 @@
> 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 priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *sharedContextPrivate)
> {
> @@ -61,18 +57,21 @@ dri_create_context(gl_api api, const struct gl_config * visual,
> unsigned allowed_flags = __DRI_CTX_FLAG_DEBUG |
> __DRI_CTX_FLAG_FORWARD_COMPATIBLE |
> __DRI_CTX_FLAG_NO_ERROR;
> + unsigned allowed_attribs = 0;
> const __DRIbackgroundCallableExtension *backgroundCallable =
> screen->sPriv->dri2.backgroundCallable;
>
> - if (screen->has_reset_status_query)
> + if (screen->has_reset_status_query) {
> allowed_flags |= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS;
> + allowed_attribs |= __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY;
Please be aware of Rob's series plumbing context priorities through.
There may be a fixup required there at some point.
[snip]
> diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h
> index ecc2a47507..3d9ec9d072 100644
> --- a/src/mesa/drivers/dri/common/dri_util.h
> +++ b/src/mesa/drivers/dri/common/dri_util.h
> @@ -67,6 +67,37 @@ extern const __DRIswrastExtension driSWRastExtension;
> extern const __DRIdri2Extension driDRI2Extension;
> extern const __DRI2configQueryExtension dri2ConfigQueryExtension;
> extern const __DRIcopySubBufferExtension driCopySubBufferExtension;
> +
> +/**
> + * Description of the attributes used to create a config.
> + *
> + * This is passed as the context_config parameter to CreateContext. The idea
> + * with this struct is that it can be extended without having to modify all of
> + * the drivers. The first three members (major/minor_version and flags) are
> + * always valid, but the remaining members are only valid if the corresponding
> + * flag is set for the attribute. If the flag is not set then the default
> + * value should be assumed. That way the driver can quickly check if any
> + * attributes were set that it doesn't understand and report an error.
> + */
> +struct __DriverContextConfig {
> + /* These members are always valid */
> + unsigned major_version;
> + unsigned minor_version;
> + uint32_t flags;
> +
> + /* Flags describing which of the remaining members are valid */
> + uint32_t attribute_mask;
> +
> + /* Only valid if __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY is set */
> + int reset_strategy;
> +
> + /* Only valid if __DRIVER_CONTEXT_PRIORITY is set */
> + unsigned priority;
> +};
> +
> +#define __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY (1 << 0)
> +#define __DRIVER_CONTEXT_ATTRIB_PRIORITY (1 << 1)
> +
> /**
> * Driver callback functions.
> *
> @@ -85,12 +116,8 @@ struct __DriverAPIRec {
> GLboolean (*CreateContext)(gl_api api,
> const struct gl_config *glVis,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> - unsigned *error,
> + const struct __DriverContextConfig *ctx_config,
> + unsigned *error,
Inconsistent indentation.
> void *sharedContextPrivate);
>
> void (*DestroyContext)(__DRIcontext *driContextPriv);
> diff --git a/src/mesa/drivers/dri/i915/intel_screen.c b/src/mesa/drivers/dri/i915/intel_screen.c
> index 1621a6246b..fef784fce4 100644
> --- a/src/mesa/drivers/dri/i915/intel_screen.c
> +++ b/src/mesa/drivers/dri/i915/intel_screen.c
> @@ -958,12 +958,8 @@ static GLboolean
> intelCreateContext(gl_api api,
> const struct gl_config * mesaVis,
> __DRIcontext * driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> - unsigned *error,
> + const struct __DriverContextConfig *ctx_config,
> + unsigned *error,
Also here.
Apart from these, patches 1 & 3 are:
Reviewed-by: Nicolai Hähnle <nicolai.haehnle at amd.com>
> void *sharedContextPrivate)
> {
> bool success = false;
> @@ -971,24 +967,28 @@ intelCreateContext(gl_api api,
> __DRIscreen *sPriv = driContextPriv->driScreenPriv;
> struct intel_screen *intelScreen = sPriv->driverPrivate;
>
> - if (flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> + if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> return false;
> }
>
> - if (notify_reset) {
> + if (ctx_config->attribute_mask) {
> *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> return false;
> }
>
> if (IS_GEN3(intelScreen->deviceID)) {
> success = i915CreateContext(api, mesaVis, driContextPriv,
> - major_version, minor_version, flags,
> + ctx_config->major_version,
> + ctx_config->minor_version,
> + ctx_config->flags,
> error, sharedContextPrivate);
> } else {
> intelScreen->no_vbo = true;
> success = i830CreateContext(api, mesaVis, driContextPriv,
> - major_version, minor_version, flags,
> + ctx_config->major_version,
> + ctx_config->minor_version,
> + ctx_config->flags,
> error, sharedContextPrivate);
> }
>
> diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
> index fae7631266..60584e2744 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.c
> +++ b/src/mesa/drivers/dri/i965/brw_context.c
> @@ -824,13 +824,9 @@ brw_process_driconf_options(struct brw_context *brw)
>
> GLboolean
> brwCreateContext(gl_api api,
> - const struct gl_config *mesaVis,
> - __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct gl_config *mesaVis,
> + __DRIcontext *driContextPriv,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *dri_ctx_error,
> void *sharedContextPrivate)
> {
> @@ -849,11 +845,20 @@ brwCreateContext(gl_api api,
> if (screen->has_context_reset_notification)
> allowed_flags |= __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS;
>
> - if (flags & ~allowed_flags) {
> + if (ctx_config->flags & ~allowed_flags) {
> *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> return false;
> }
>
> + if (ctx_config->attribute_mask & ~__DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY) {
> + *dri_ctx_error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> + return false;
> + }
> +
> + bool notify_reset =
> + ((ctx_config->attribute_mask & __DRIVER_CONTEXT_ATTRIB_RESET_STRATEGY) &&
> + ctx_config->reset_strategy != __DRI_CTX_RESET_NO_NOTIFICATION);
> +
> struct brw_context *brw = rzalloc(NULL, struct brw_context);
> if (!brw) {
> fprintf(stderr, "%s: failed to alloc context\n", __func__);
> @@ -902,7 +907,7 @@ brwCreateContext(gl_api api,
> return false;
> }
>
> - driContextSetFlags(ctx, flags);
> + driContextSetFlags(ctx, ctx_config->flags);
>
> /* Initialize the software rasterizer and helper modules.
> *
> @@ -962,19 +967,21 @@ brwCreateContext(gl_api api,
> }
>
> int hw_priority = BRW_CONTEXT_MEDIUM_PRIORITY;
> - switch (priority) {
> - case __DRI_CTX_PRIORITY_LOW:
> - hw_priority = BRW_CONTEXT_LOW_PRIORITY;
> - break;
> - case __DRI_CTX_PRIORITY_HIGH:
> - hw_priority = BRW_CONTEXT_HIGH_PRIORITY;
> - break;
> + if (ctx_config->attribute_mask & __DRIVER_CONTEXT_ATTRIB_PRIORITY) {
> + switch (ctx_config->priority) {
> + case __DRI_CTX_PRIORITY_LOW:
> + hw_priority = BRW_CONTEXT_LOW_PRIORITY;
> + break;
> + case __DRI_CTX_PRIORITY_HIGH:
> + hw_priority = BRW_CONTEXT_HIGH_PRIORITY;
> + break;
> + }
> }
> if (hw_priority != I915_CONTEXT_DEFAULT_PRIORITY &&
> brw_hw_context_set_priority(brw->bufmgr, brw->hw_ctx, hw_priority)) {
> fprintf(stderr,
> "Failed to set priority [%d:%d] for hardware context.\n",
> - priority, hw_priority);
> + ctx_config->priority, hw_priority);
> intelDestroyContext(driContextPriv);
> return false;
> }
> @@ -1013,12 +1020,12 @@ brwCreateContext(gl_api api,
>
> brw_draw_init( brw );
>
> - if ((flags & __DRI_CTX_FLAG_DEBUG) != 0) {
> + if ((ctx_config->flags & __DRI_CTX_FLAG_DEBUG) != 0) {
> /* Turn on some extra GL_ARB_debug_output generation. */
> brw->perf_debug = true;
> }
>
> - if ((flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS) != 0) {
> + if ((ctx_config->flags & __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS) != 0) {
> ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_ROBUST_ACCESS_BIT_ARB;
> ctx->Const.RobustAccess = GL_TRUE;
> }
> diff --git a/src/mesa/drivers/dri/i965/brw_context.h b/src/mesa/drivers/dri/i965/brw_context.h
> index 3bee3e99ed..a85ac3e5f8 100644
> --- a/src/mesa/drivers/dri/i965/brw_context.h
> +++ b/src/mesa/drivers/dri/i965/brw_context.h
> @@ -1242,11 +1242,7 @@ void intel_resolve_for_dri2_flush(struct brw_context *brw,
> GLboolean brwCreateContext(gl_api api,
> const struct gl_config *mesaVis,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *sharedContextPrivate);
>
> diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c
> index 39620e1021..397e39603d 100644
> --- a/src/mesa/drivers/dri/nouveau/nouveau_context.c
> +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c
> @@ -51,11 +51,7 @@
> GLboolean
> nouveau_context_create(gl_api api,
> const struct gl_config *visual, __DRIcontext *dri_ctx,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *share_ctx)
> {
> @@ -64,12 +60,12 @@ nouveau_context_create(gl_api api,
> struct nouveau_context *nctx;
> struct gl_context *ctx;
>
> - if (flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> + if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> return false;
> }
>
> - if (notify_reset) {
> + if (ctx_config->attribute_mask) {
> *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> return false;
> }
> @@ -80,14 +76,15 @@ nouveau_context_create(gl_api api,
> return GL_FALSE;
> }
>
> - driContextSetFlags(ctx, flags);
> + driContextSetFlags(ctx, ctx_config->flags);
>
> nctx = to_nouveau_context(ctx);
> nctx->dri_context = dri_ctx;
> dri_ctx->driverPrivate = ctx;
>
> _mesa_compute_version(ctx);
> - if (ctx->Version < major_version * 10 + minor_version) {
> + if (ctx->Version < (ctx_config->major_version * 10 +
> + ctx_config->minor_version)) {
> nouveau_context_destroy(dri_ctx);
> *error = __DRI_CTX_ERROR_BAD_VERSION;
> return GL_FALSE;
> diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.h b/src/mesa/drivers/dri/nouveau/nouveau_context.h
> index 6ab865c7bd..dcb7bbb23a 100644
> --- a/src/mesa/drivers/dri/nouveau/nouveau_context.h
> +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.h
> @@ -110,8 +110,7 @@ struct nouveau_context {
> GLboolean
> nouveau_context_create(gl_api api,
> const struct gl_config *visual, __DRIcontext *dri_ctx,
> - unsigned major_version, unsigned minor_version,
> - uint32_t flags, bool notify_reset, unsigned priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error, void *share_ctx);
>
> GLboolean
> diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c
> index bd4f8b62cd..edd433ae97 100644
> --- a/src/mesa/drivers/dri/r200/r200_context.c
> +++ b/src/mesa/drivers/dri/r200/r200_context.c
> @@ -174,11 +174,7 @@ static void r200_init_vtbl(radeonContextPtr radeon)
> GLboolean r200CreateContext( gl_api api,
> const struct gl_config *glVisual,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *sharedContextPrivate)
> {
> @@ -190,12 +186,12 @@ GLboolean r200CreateContext( gl_api api,
> int i;
> int tcl_mode;
>
> - if (flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> + if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> return false;
> }
>
> - if (notify_reset) {
> + if (ctx_config->attribute_mask) {
> *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> return false;
> }
> @@ -251,7 +247,7 @@ GLboolean r200CreateContext( gl_api api,
>
> ctx = &rmesa->radeon.glCtx;
>
> - driContextSetFlags(ctx, flags);
> + driContextSetFlags(ctx, ctx_config->flags);
>
> /* Initialize the software rasterizer and helper modules.
> */
> diff --git a/src/mesa/drivers/dri/r200/r200_context.h b/src/mesa/drivers/dri/r200/r200_context.h
> index 200e0a2431..f9ba6835e8 100644
> --- a/src/mesa/drivers/dri/r200/r200_context.h
> +++ b/src/mesa/drivers/dri/r200/r200_context.h
> @@ -628,11 +628,8 @@ extern void r200DestroyContext( __DRIcontext *driContextPriv );
> extern GLboolean r200CreateContext( gl_api api,
> const struct gl_config *glVisual,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *
> + ctx_config,
> unsigned *error,
> void *sharedContextPrivate);
> extern GLboolean r200MakeCurrent( __DRIcontext *driContextPriv,
> diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c
> index 866dc80c98..04c76cdba1 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_context.c
> +++ b/src/mesa/drivers/dri/radeon/radeon_context.c
> @@ -140,11 +140,7 @@ GLboolean
> r100CreateContext( gl_api api,
> const struct gl_config *glVisual,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *sharedContextPrivate)
> {
> @@ -156,12 +152,12 @@ r100CreateContext( gl_api api,
> int i;
> int tcl_mode, fthrottle_mode;
>
> - if (flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> + if (ctx_config->flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_NO_ERROR)) {
> *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
> return false;
> }
>
> - if (notify_reset) {
> + if (ctx_config->attribute_mask) {
> *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> return false;
> }
> @@ -214,7 +210,7 @@ r100CreateContext( gl_api api,
>
> ctx = &rmesa->radeon.glCtx;
>
> - driContextSetFlags(ctx, flags);
> + driContextSetFlags(ctx, ctx_config->flags);
>
> /* Initialize the software rasterizer and helper modules.
> */
> diff --git a/src/mesa/drivers/dri/radeon/radeon_context.h b/src/mesa/drivers/dri/radeon/radeon_context.h
> index 4124f50db5..94917cf30b 100644
> --- a/src/mesa/drivers/dri/radeon/radeon_context.h
> +++ b/src/mesa/drivers/dri/radeon/radeon_context.h
> @@ -452,11 +452,8 @@ R100_CONTEXT(struct gl_context *ctx)
> extern GLboolean r100CreateContext( gl_api api,
> const struct gl_config *glVisual,
> __DRIcontext *driContextPriv,
> - unsigned major_version,
> - unsigned minor_version,
> - uint32_t flags,
> - bool notify_reset,
> - unsigned priority,
> + const struct __DriverContextConfig *
> + ctx_config,
> unsigned *error,
> void *sharedContextPrivate);
>
> diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
> index 6b71d806f0..f9bd1b9d56 100644
> --- a/src/mesa/drivers/dri/swrast/swrast.c
> +++ b/src/mesa/drivers/dri/swrast/swrast.c
> @@ -752,11 +752,7 @@ static 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 priority,
> + const struct __DriverContextConfig *ctx_config,
> unsigned *error,
> void *sharedContextPrivate)
> {
> @@ -770,7 +766,13 @@ dri_create_context(gl_api api,
>
> /* Flag filtering is handled in dri2CreateContextAttribs.
> */
> - (void) flags;
> + (void) ctx_config->flags;
> +
> + /* The swrast driver doesn't understand any of the attributes */
> + if (ctx_config->attribute_mask != 0) {
> + *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
> + return false;
> + }
>
> ctx = CALLOC_STRUCT(dri_context);
> if (ctx == NULL) {
> @@ -797,7 +799,7 @@ dri_create_context(gl_api api,
> goto context_fail;
> }
>
> - driContextSetFlags(mesaCtx, flags);
> + driContextSetFlags(mesaCtx, ctx_config->flags);
>
> /* create module contexts */
> _swrast_CreateContext( mesaCtx );
>
--
Lerne, wie die Welt wirklich ist,
Aber vergiss niemals, wie sie sein sollte.
More information about the mesa-dev
mailing list