From: Ian Romanick <[email protected]>

The previous code handled everything with the general case.  I noticed
that every time I converted an open-coded check to use a
_mesa_has_EXT_foo() function, the text size of the driver increased.

Almost all extensions only care what the current context API is, and
the version does not matter.  Handle those using more compact checks.

   text    data     bss     dec     hex filename
7037675  235248   37280 7310203  6f8b7b 32-bit i965_dri.so before
7034307  235248   37280 7306835  6f7e53 32-bit i965_dri.so after
6679695  303400   50608 7033703  6b5367 64-bit i965_dri.so before
6676143  303400   50608 7030151  6b4587 64-bit i965_dri.so after

Signed-off-by: Ian Romanick <[email protected]>
---
 src/mesa/main/extensions.h | 51 ++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/mesa/main/extensions.h b/src/mesa/main/extensions.h
index efef1be..8ffc076 100644
--- a/src/mesa/main/extensions.h
+++ b/src/mesa/main/extensions.h
@@ -94,11 +94,58 @@ MESA_EXTENSION_COUNT
 
 
 /** Checks if the context supports a user-facing extension */
-#define EXT(name_str, driver_cap, ...) \
+#define CHECK_CAP(ctx, driver_cap)                                      \
+   (offsetof(struct gl_extensions, driver_cap) == offsetof(struct 
gl_extensions, dummy_true) || \
+    ctx->Extensions.driver_cap)
+
+#define EXT(name_str, driver_cap, gll, glc, es1, es2, ...)                     
\
 static inline bool \
 _mesa_has_##name_str(const struct gl_context *ctx) \
 { \
-   return ctx->Extensions.driver_cap && (ctx->Extensions.Version >= \
+   STATIC_ASSERT(!(gll ==  0 && glc == ~0 && es1 == ~0 && es2 ==  0));/*  6 */ 
\
+   STATIC_ASSERT(!(gll == ~0 && glc ==  0 && es1 ==  0 && es2 ==  0));/*  8 */ 
\
+   STATIC_ASSERT(!(gll == ~0 && glc ==  0 && es1 ==  0 && es2 == ~0));/*  9 */ 
\
+   STATIC_ASSERT(!(gll == ~0 && glc ==  0 && es1 == ~0 && es2 ==  0));/* 10 */ 
\
+   /* 15 is also impossible, but it is used by dummy_true and dummy_false. */  
\
+                                                                               
\
+   if (gll == 0 && glc == 0 && es1 == 0 && es2 == 0)                  /*  0 */ 
\
+       /* e.g., GL_EXT_polygon_offset_clamp */                                 
\
+      return CHECK_CAP(ctx, driver_cap);                                       
\
+   else if (gll == 0 && glc == 0 && es1 == 0 && es2 == ~0)            /*  1 */ 
\
+      /* e.g., GL_OES_read_format */                                           
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API != API_OPENGLES2; 
\
+   else if (gll == 0 && glc == 0 && es1 == ~0 && es2 == 0)            /*  2 */ 
\
+      /* e.g., GL_KHR_robustness */                                            
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API != API_OPENGLES;  
\
+   else if (gll == 0 && glc == 0 && es1 == ~0 && es2 == ~0)           /*  3 */ 
\
+      /* e.g., GL_ARB_texture_rg */                                            
\
+      return CHECK_CAP(ctx, driver_cap) &&                                     
\
+         ((uint8_t)ctx->API == API_OPENGL_COMPAT || (uint8_t)ctx->API == 
API_OPENGL_CORE); \
+   else if (gll == 0 && glc == ~0 && es1 == 0 && es2 == 0)            /*  4 */ 
\
+      /* e.g., GL_EXT_blend_minmax */                                          
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API != 
API_OPENGL_CORE; \
+   else if (gll == 0 && glc == ~0 && es1 == 0 && es2 == ~0)           /*  5 */ 
\
+      /* e.g., GL_EXT_texture_lod_bias */                                      
\
+      return CHECK_CAP(ctx, driver_cap) &&                                     
\
+         ((uint8_t)ctx->API == API_OPENGL_COMPAT || (uint8_t)ctx->API == 
API_OPENGLES); \
+   else if (gll == 0 && glc == ~0 && es1 == ~0 && es2 == ~0)          /*  7 */ 
\
+      /* e.g., GL_ARB_depth_texture */                                         
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API == 
API_OPENGL_COMPAT; \
+   else if (gll == ~0 && glc == 0 && es1 == ~0 && es2 == ~0)          /* 11 */ 
\
+      /* e.g., GL_ARB_direct_state_access */                                   
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API == 
API_OPENGL_CORE; \
+   else if (gll == ~0 && glc == ~0 && es1 == 0 && es2 == 0)           /* 12 */ 
\
+      /* e.g., GL_EXT_map_buffer_range */                                      
\
+      return CHECK_CAP(ctx, driver_cap) &&                                     
\
+         ((uint8_t)ctx->API == API_OPENGLES || (uint8_t)ctx->API == 
API_OPENGLES2); \
+   else if (gll == ~0 && glc == ~0 && es1 == 0 && es2 == ~0)          /* 13 */ 
\
+      /* e.g., GL_OES_blend_equation_separate */                               
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API == API_OPENGLES;  
\
+   else if (gll == ~0 && glc == ~0 && es1 == ~0 && es2 == 0)          /* 14 */ 
\
+      /* e.g., GL_OES_depth_texture */                                         
\
+      return CHECK_CAP(ctx, driver_cap) && (uint8_t)ctx->API == API_OPENGLES2; 
\
+   else                                                                        
\
+      return CHECK_CAP(ctx, driver_cap) && (ctx->Extensions.Version >=         
\
           _mesa_extension_table[MESA_EXTENSION_##name_str].version[ctx->API]); 
\
 }
 #include "extensions_table.h"
-- 
2.7.4

_______________________________________________
mesa-dev mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to