diff options
author | Eric Anholt <[email protected]> | 2013-09-26 12:01:56 -0700 |
---|---|---|
committer | Eric Anholt <[email protected]> | 2013-10-10 16:34:30 -0700 |
commit | 083f66fdd6451648fe355b64b02b29a6a4389f0d (patch) | |
tree | 7965c2cd9f5b2f96ea1268ef6640d6e39ed55bff /src/mesa/drivers/dri/common | |
parent | d81632fb1e809a0b1ee9310ae3a4733a1c0651b7 (diff) |
dri: Move API version validation into dri/common.
i965, i915, radeon, r200, swrast, and nouveau were mostly trying to do the
same logic, except where they failed to. Notably, swrast had code that
appeared to try to enable GLES1/2 but forgot to set api_mask (thus
preventing any gles context from being created), and the non-intel drivers
didn't support MESA_GL_VERSION_OVERRIDE.
nouveau still relies on _mesa_compute_version(), because I don't know what
its limits actually are, and gallium drivers don't declare limits up front
at all. I think I've heard talk about doing so, though.
v2: Compat max version should be 30 (noted by Ken)
Drop r100's custom max version check, too (noted by Emil Velikov)
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/common')
-rw-r--r-- | src/mesa/drivers/dri/common/dri_util.c | 68 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/dri_util.h | 5 |
2 files changed, 71 insertions, 2 deletions
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 424b65d7a2f..70448c2df4d 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -39,6 +39,7 @@ */ +#include <stdbool.h> #ifndef __NOT_HAVE_DRM_H #include <xf86drm.h> #endif @@ -46,6 +47,8 @@ #include "utils.h" #include "xmlpool.h" #include "../glsl/glsl_parser_extras.h" +#include "main/version.h" +#include "main/macros.h" PUBLIC const char __dri2ConfigOptions[] = DRI_CONF_BEGIN @@ -116,17 +119,35 @@ dri2CreateNewScreen(int scrn, int fd, psp->fd = fd; psp->myNum = scrn; - psp->api_mask = (1 << __DRI_API_OPENGL); - *driver_configs = driDriverAPI.InitScreen(psp); if (*driver_configs == NULL) { free(psp); return NULL; } + int gl_version_override = _mesa_get_gl_version_override(); + if (gl_version_override >= 31) { + psp->max_gl_core_version = MAX2(psp->max_gl_core_version, + gl_version_override); + } else { + psp->max_gl_compat_version = MAX2(psp->max_gl_compat_version, + gl_version_override); + } + + psp->api_mask = (1 << __DRI_API_OPENGL); + if (psp->max_gl_core_version > 0) + psp->api_mask |= (1 << __DRI_API_OPENGL_CORE); + if (psp->max_gl_es1_version > 0) + psp->api_mask |= (1 << __DRI_API_GLES); + if (psp->max_gl_es2_version > 0) + psp->api_mask |= (1 << __DRI_API_GLES2); + if (psp->max_gl_es2_version >= 30) + psp->api_mask |= (1 << __DRI_API_GLES3); + driParseOptionInfo(&psp->optionInfo, __dri2ConfigOptions); driParseConfigFiles(&psp->optionCache, &psp->optionInfo, psp->myNum, "dri2"); + return psp; } @@ -172,6 +193,45 @@ static const __DRIextension **driGetExtensions(__DRIscreen *psp) /*@}*/ +static bool +validate_context_version(__DRIscreen *screen, + int mesa_api, + unsigned major_version, + unsigned minor_version, + unsigned *dri_ctx_error) +{ + unsigned req_version = 10 * major_version + minor_version; + unsigned max_version = 0; + + switch (mesa_api) { + case API_OPENGL_COMPAT: + max_version = screen->max_gl_compat_version; + break; + case API_OPENGL_CORE: + max_version = screen->max_gl_core_version; + break; + case API_OPENGLES: + max_version = screen->max_gl_es1_version; + break; + case API_OPENGLES2: + max_version = screen->max_gl_es2_version; + break; + default: + max_version = 0; + break; + } + + if (max_version == 0) { + *dri_ctx_error = __DRI_CTX_ERROR_BAD_API; + return false; + } else if (req_version > max_version) { + *dri_ctx_error = __DRI_CTX_ERROR_BAD_VERSION; + return false; + } + + return true; +} + /*****************************************************************/ /** \name Context handling functions */ /*****************************************************************/ @@ -293,6 +353,10 @@ dri2CreateContextAttribs(__DRIscreen *screen, int api, return NULL; } + if (!validate_context_version(screen, mesa_api, + major_version, minor_version, error)) + return NULL; + context = calloc(1, sizeof *context); if (!context) { *error = __DRI_CTX_ERROR_NO_MEMORY; diff --git a/src/mesa/drivers/dri/common/dri_util.h b/src/mesa/drivers/dri/common/dri_util.h index 900f04853a7..92edccbb02e 100644 --- a/src/mesa/drivers/dri/common/dri_util.h +++ b/src/mesa/drivers/dri/common/dri_util.h @@ -151,6 +151,11 @@ struct __DRIscreenRec { void *loaderPrivate; + int max_gl_core_version; + int max_gl_compat_version; + int max_gl_es1_version; + int max_gl_es2_version; + const __DRIextension **extensions; const __DRIswrastLoaderExtension *swrast_loader; |