From 70f47505a2e5d4cf949b7c2650f3d9f6559bacb3 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 7 Aug 2012 11:26:19 -0700 Subject: dri: Pass API_OPENGL_CORE through to the drivers This forces the drivers to do at least some validation of context API and version before creating the context. In r100 and r200 drivers, this means that they don't do any post-hoc validation. v2: Actually reject compatibility profile 3.2+ contexts. Thanks Ken. Signed-off-by: Ian Romanick Reviewed-by: Kenneth Graunke --- src/mesa/drivers/dri/common/dri_util.c | 16 ++++++++++++++++ src/mesa/drivers/dri/intel/intel_screen.c | 17 +++++++++++++++++ src/mesa/drivers/dri/nouveau/nouveau_context.c | 24 +++++++++++++++++++++++- src/mesa/drivers/dri/r200/r200_context.c | 22 +++++++++++++++------- src/mesa/drivers/dri/radeon/radeon_context.c | 22 +++++++++++++++------- src/mesa/drivers/dri/swrast/swrast.c | 19 ++++++++++++++----- 6 files changed, 100 insertions(+), 20 deletions(-) (limited to 'src/mesa/drivers/dri') diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c index 91ae186fe4b..d28f774dd63 100644 --- a/src/mesa/drivers/dri/common/dri_util.c +++ b/src/mesa/drivers/dri/common/dri_util.c @@ -192,6 +192,8 @@ dri2CreateContextAttribs(__DRIscreen *screen, int api, mesa_api = API_OPENGLES2; break; case __DRI_API_OPENGL_CORE: + mesa_api = API_OPENGL_CORE; + break; default: *error = __DRI_CTX_ERROR_BAD_API; return NULL; @@ -218,6 +220,20 @@ dri2CreateContextAttribs(__DRIscreen *screen, int api, } } + /* Mesa does not support the GL_ARB_compatibilty extension or the + * compatibility profile. This means that we treat a API_OPENGL 3.1 as + * API_OPENGL_CORE and reject API_OPENGL 3.2+. + */ + if (mesa_api == API_OPENGL && major_version == 3 && minor_version == 1) + mesa_api = API_OPENGL_CORE; + + if (mesa_api == API_OPENGL + && ((major_version > 3) + || (major_version == 3 && minor_version >= 2))) { + *error = __DRI_CTX_ERROR_BAD_API; + return NULL; + } + /* The EGL_KHR_create_context spec says: * * "Flags are only defined for OpenGL context creation, and specifying diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c index e1ec2eb0130..f3592af621a 100644 --- a/src/mesa/drivers/dri/intel/intel_screen.c +++ b/src/mesa/drivers/dri/intel/intel_screen.c @@ -714,6 +714,23 @@ intelCreateContext(gl_api api, struct intel_screen *intelScreen = sPriv->driverPrivate; bool success = false; + switch (api) { + case API_OPENGL: + case API_OPENGLES: + break; + case API_OPENGLES2: +#ifdef I915 + if (!IS_9XX(intelScreen->deviceID)) { + *error = __DRI_CTX_ERROR_BAD_API; + return false; + } +#endif + break; + case API_OPENGL_CORE: + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; + } + #ifdef I915 if (IS_9XX(intelScreen->deviceID)) { if (!IS_965(intelScreen->deviceID)) { diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c index f79430890fb..4409eae49bf 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_context.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c @@ -59,9 +59,31 @@ nouveau_context_create(gl_api api, struct nouveau_context *nctx; struct gl_context *ctx; + switch (api) { + case API_OPENGL: + /* Do after-the-fact version checking (below). + */ + break; + case API_OPENGLES: + /* NV10 and NV20 can support OpenGL ES 1.0 only. Older chips + * cannot do even that. + */ + if ((screen->device->chipset & 0xf0) == 0x00) { + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; + } else if (minor_version != 0) { + *error = __DRI_CTX_ERROR_BAD_VERSION; + return GL_FALSE; + } + break; + case API_OPENGLES2: + case API_OPENGL_CORE: + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; + } + /* API and flag filtering is handled in dri2CreateContextAttribs. */ - (void) api; (void) flags; ctx = screen->driver->context_create(screen, visual, share_ctx); diff --git a/src/mesa/drivers/dri/r200/r200_context.c b/src/mesa/drivers/dri/r200/r200_context.c index 17e08a10fc5..5f8cc866662 100644 --- a/src/mesa/drivers/dri/r200/r200_context.c +++ b/src/mesa/drivers/dri/r200/r200_context.c @@ -212,9 +212,22 @@ GLboolean r200CreateContext( gl_api api, int i; int tcl_mode; - /* API and flag filtering is handled in dri2CreateContextAttribs. + switch (api) { + case API_OPENGL: + if (major_version > 1 || minor_version > 3) { + *error = __DRI_CTX_ERROR_BAD_VERSION; + return GL_FALSE; + } + break; + case API_OPENGLES: + break; + default: + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; + } + + /* Flag filtering is handled in dri2CreateContextAttribs. */ - (void) api; (void) flags; assert(glVisual); @@ -454,11 +467,6 @@ GLboolean r200CreateContext( gl_api api, } _mesa_compute_version(ctx); - if (ctx->Version < major_version * 10 + minor_version) { - r200DestroyContext(driContextPriv); - *error = __DRI_CTX_ERROR_BAD_VERSION; - return GL_FALSE; - } *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; diff --git a/src/mesa/drivers/dri/radeon/radeon_context.c b/src/mesa/drivers/dri/radeon/radeon_context.c index 34c392ef8b7..e17c7860b1f 100644 --- a/src/mesa/drivers/dri/radeon/radeon_context.c +++ b/src/mesa/drivers/dri/radeon/radeon_context.c @@ -178,9 +178,22 @@ r100CreateContext( gl_api api, int i; int tcl_mode, fthrottle_mode; - /* API and flag filtering is handled in dri2CreateContextAttribs. + switch (api) { + case API_OPENGL: + if (major_version > 1 || minor_version > 3) { + *error = __DRI_CTX_ERROR_BAD_VERSION; + return GL_FALSE; + } + break; + case API_OPENGLES: + break; + default: + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; + } + + /* Flag filtering is handled in dri2CreateContextAttribs. */ - (void) api; (void) flags; assert(glVisual); @@ -402,11 +415,6 @@ r100CreateContext( gl_api api, } _mesa_compute_version(ctx); - if (ctx->Version < major_version * 10 + minor_version) { - radeonDestroyContext(driContextPriv); - *error = __DRI_CTX_ERROR_BAD_VERSION; - return GL_FALSE; - } *error = __DRI_CTX_ERROR_SUCCESS; return GL_TRUE; diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c index ca6bda02781..7773fd9050a 100644 --- a/src/mesa/drivers/dri/swrast/swrast.c +++ b/src/mesa/drivers/dri/swrast/swrast.c @@ -719,11 +719,20 @@ dri_create_context(gl_api api, */ (void) flags; - if (api == API_OPENGL - && (major_version > 2 - || (major_version == 2 && minor_version > 1))) { - *error = __DRI_CTX_ERROR_BAD_VERSION; - goto context_fail; + switch (api) { + case API_OPENGL: + if (major_version > 2 + || (major_version == 2 && minor_version > 1)) { + *error = __DRI_CTX_ERROR_BAD_VERSION; + return GL_FALSE; + } + break; + case API_OPENGLES: + case API_OPENGLES2: + break; + case API_OPENGL_CORE: + *error = __DRI_CTX_ERROR_BAD_API; + return GL_FALSE; } ctx = CALLOC_STRUCT(dri_context); -- cgit v1.2.3