Home | History | Annotate | Download | only in state_tracker
      1 /**************************************************************************
      2  *
      3  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
      4  * Copyright (c) 2008 VMware, Inc.
      5  * All Rights Reserved.
      6  *
      7  * Permission is hereby granted, free of charge, to any person obtaining a
      8  * copy of this software and associated documentation files (the
      9  * "Software"), to deal in the Software without restriction, including
     10  * without limitation the rights to use, copy, modify, merge, publish,
     11  * distribute, sub license, and/or sell copies of the Software, and to
     12  * permit persons to whom the Software is furnished to do so, subject to
     13  * the following conditions:
     14  *
     15  * The above copyright notice and this permission notice (including the
     16  * next paragraph) shall be included in all copies or substantial portions
     17  * of the Software.
     18  *
     19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
     20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
     22  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
     23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
     24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
     25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     26  *
     27  **************************************************************************/
     28 
     29 #include "main/imports.h"
     30 #include "main/context.h"
     31 #include "main/macros.h"
     32 #include "main/mfeatures.h"
     33 #include "main/version.h"
     34 
     35 #include "pipe/p_context.h"
     36 #include "pipe/p_defines.h"
     37 #include "pipe/p_screen.h"
     38 
     39 #include "st_context.h"
     40 #include "st_extensions.h"
     41 
     42 
     43 static int _min(int a, int b)
     44 {
     45    return (a < b) ? a : b;
     46 }
     47 
     48 static float _maxf(float a, float b)
     49 {
     50    return (a > b) ? a : b;
     51 }
     52 
     53 static int _clamp(int a, int min, int max)
     54 {
     55    if (a < min)
     56       return min;
     57    else if (a > max)
     58       return max;
     59    else
     60       return a;
     61 }
     62 
     63 
     64 /**
     65  * Query driver to get implementation limits.
     66  * Note that we have to limit/clamp against Mesa's internal limits too.
     67  */
     68 void st_init_limits(struct st_context *st)
     69 {
     70    struct pipe_screen *screen = st->pipe->screen;
     71    struct gl_constants *c = &st->ctx->Const;
     72    gl_shader_type sh;
     73 
     74    c->MaxTextureLevels
     75       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_2D_LEVELS),
     76             MAX_TEXTURE_LEVELS);
     77 
     78    c->Max3DTextureLevels
     79       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_3D_LEVELS),
     80             MAX_3D_TEXTURE_LEVELS);
     81 
     82    c->MaxCubeTextureLevels
     83       = _min(screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS),
     84             MAX_CUBE_TEXTURE_LEVELS);
     85 
     86    c->MaxTextureRectSize
     87       = _min(1 << (c->MaxTextureLevels - 1), MAX_TEXTURE_RECT_SIZE);
     88 
     89    c->MaxArrayTextureLayers
     90       = screen->get_param(screen, PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS);
     91 
     92    c->MaxTextureImageUnits
     93       = _min(screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
     94                                       PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
     95             MAX_TEXTURE_IMAGE_UNITS);
     96 
     97    c->MaxVertexTextureImageUnits
     98       = _min(screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
     99                                       PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS),
    100              MAX_VERTEX_TEXTURE_IMAGE_UNITS);
    101 
    102    c->MaxCombinedTextureImageUnits
    103       = _min(screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SAMPLERS),
    104              MAX_COMBINED_TEXTURE_IMAGE_UNITS);
    105 
    106    c->MaxTextureCoordUnits
    107       = _min(c->MaxTextureImageUnits, MAX_TEXTURE_COORD_UNITS);
    108 
    109    c->MaxTextureUnits = _min(c->MaxTextureImageUnits, c->MaxTextureCoordUnits);
    110 
    111    /* Define max viewport size and max renderbuffer size in terms of
    112     * max texture size (note: max tex RECT size = max tex 2D size).
    113     * If this isn't true for some hardware we'll need new PIPE_CAP_ queries.
    114     */
    115    c->MaxViewportWidth =
    116    c->MaxViewportHeight =
    117    c->MaxRenderbufferSize = c->MaxTextureRectSize;
    118 
    119    c->MaxDrawBuffers
    120       = _clamp(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
    121               1, MAX_DRAW_BUFFERS);
    122 
    123    c->MaxDualSourceDrawBuffers
    124       = _clamp(screen->get_param(screen, PIPE_CAP_MAX_DUAL_SOURCE_RENDER_TARGETS),
    125               0, MAX_DRAW_BUFFERS);
    126 
    127    c->MaxLineWidth
    128       = _maxf(1.0f, screen->get_paramf(screen,
    129                                        PIPE_CAPF_MAX_LINE_WIDTH));
    130    c->MaxLineWidthAA
    131       = _maxf(1.0f, screen->get_paramf(screen,
    132                                        PIPE_CAPF_MAX_LINE_WIDTH_AA));
    133 
    134    c->MaxPointSize
    135       = _maxf(1.0f, screen->get_paramf(screen,
    136                                        PIPE_CAPF_MAX_POINT_WIDTH));
    137    c->MaxPointSizeAA
    138       = _maxf(1.0f, screen->get_paramf(screen,
    139                                        PIPE_CAPF_MAX_POINT_WIDTH_AA));
    140    /* called after _mesa_create_context/_mesa_init_point, fix default user
    141     * settable max point size up
    142     */
    143    st->ctx->Point.MaxSize = MAX2(c->MaxPointSize, c->MaxPointSizeAA);
    144    /* these are not queryable. Note that GL basically mandates a 1.0 minimum
    145     * for non-aa sizes, but we can go down to 0.0 for aa points.
    146     */
    147    c->MinPointSize = 1.0f;
    148    c->MinPointSizeAA = 0.0f;
    149 
    150    c->MaxTextureMaxAnisotropy
    151       = _maxf(2.0f, screen->get_paramf(screen,
    152                                  PIPE_CAPF_MAX_TEXTURE_ANISOTROPY));
    153 
    154    c->MaxTextureLodBias
    155       = screen->get_paramf(screen, PIPE_CAPF_MAX_TEXTURE_LOD_BIAS);
    156 
    157    c->MaxDrawBuffers
    158       = CLAMP(screen->get_param(screen, PIPE_CAP_MAX_RENDER_TARGETS),
    159               1, MAX_DRAW_BUFFERS);
    160 
    161    c->QuadsFollowProvokingVertexConvention = screen->get_param(
    162       screen, PIPE_CAP_QUADS_FOLLOW_PROVOKING_VERTEX_CONVENTION);
    163 
    164    for (sh = 0; sh < MESA_SHADER_TYPES; ++sh) {
    165       struct gl_shader_compiler_options *options =
    166          &st->ctx->ShaderCompilerOptions[sh];
    167       struct gl_program_constants *pc;
    168 
    169       switch (sh) {
    170       case PIPE_SHADER_FRAGMENT:
    171          pc = &c->FragmentProgram;
    172          break;
    173       case PIPE_SHADER_VERTEX:
    174          pc = &c->VertexProgram;
    175          break;
    176       case PIPE_SHADER_GEOMETRY:
    177          pc = &c->GeometryProgram;
    178          break;
    179       default:
    180          assert(0);
    181          continue;
    182       }
    183 
    184       pc->MaxNativeInstructions    = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS);
    185       pc->MaxNativeAluInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS);
    186       pc->MaxNativeTexInstructions = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS);
    187       pc->MaxNativeTexIndirections = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS);
    188       pc->MaxNativeAttribs         = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INPUTS);
    189       pc->MaxNativeTemps           = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_TEMPS);
    190       pc->MaxNativeAddressRegs     = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_ADDRS);
    191       pc->MaxNativeParameters      = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONSTS);
    192       pc->MaxUniformComponents     = 4 * MIN2(pc->MaxNativeParameters, MAX_UNIFORMS);
    193       /* raise MaxParameters if native support is higher */
    194       pc->MaxParameters            = MAX2(pc->MaxParameters, pc->MaxNativeParameters);
    195 
    196       /* Gallium doesn't really care about local vs. env parameters so use the
    197        * same limits.
    198        */
    199       pc->MaxLocalParams = MIN2(pc->MaxParameters, MAX_PROGRAM_LOCAL_PARAMS);
    200       pc->MaxEnvParams = MIN2(pc->MaxParameters, MAX_PROGRAM_ENV_PARAMS);
    201 
    202       options->EmitNoNoise = TRUE;
    203 
    204       /* TODO: make these more fine-grained if anyone needs it */
    205       options->MaxIfDepth = screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
    206       options->EmitNoLoops = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH);
    207       options->EmitNoFunctions = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
    208       options->EmitNoMainReturn = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_SUBROUTINES);
    209 
    210       options->EmitNoCont = !screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED);
    211 
    212       options->EmitNoIndirectInput = !screen->get_shader_param(screen, sh,
    213                                         PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR);
    214       options->EmitNoIndirectOutput = !screen->get_shader_param(screen, sh,
    215                                         PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR);
    216       options->EmitNoIndirectTemp = !screen->get_shader_param(screen, sh,
    217                                         PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR);
    218       options->EmitNoIndirectUniform = !screen->get_shader_param(screen, sh,
    219                                         PIPE_SHADER_CAP_INDIRECT_CONST_ADDR);
    220 
    221       if (options->EmitNoLoops)
    222          options->MaxUnrollIterations = MIN2(screen->get_shader_param(screen, sh, PIPE_SHADER_CAP_MAX_INSTRUCTIONS), 65536);
    223       else
    224          options->MaxUnrollIterations = 255; /* SM3 limit */
    225       options->LowerClipDistance = true;
    226    }
    227 
    228    /* PIPE_SHADER_CAP_MAX_INPUTS for the FS specifies the maximum number
    229     * of inputs. It's always 2 colors + N generic inputs. */
    230    c->MaxVarying = screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
    231                                             PIPE_SHADER_CAP_MAX_INPUTS);
    232    c->MaxVarying = MIN2(c->MaxVarying, MAX_VARYING);
    233 
    234    c->MinProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MIN_TEXEL_OFFSET);
    235    c->MaxProgramTexelOffset = screen->get_param(screen, PIPE_CAP_MAX_TEXEL_OFFSET);
    236 
    237    c->UniformBooleanTrue = ~0;
    238 
    239    c->MaxTransformFeedbackBuffers =
    240       screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS);
    241    c->MaxTransformFeedbackBuffers = MIN2(c->MaxTransformFeedbackBuffers, MAX_FEEDBACK_BUFFERS);
    242    c->MaxTransformFeedbackSeparateComponents =
    243       screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_SEPARATE_COMPONENTS);
    244    c->MaxTransformFeedbackInterleavedComponents =
    245       screen->get_param(screen, PIPE_CAP_MAX_STREAM_OUTPUT_INTERLEAVED_COMPONENTS);
    246 
    247    c->StripTextureBorder = GL_TRUE;
    248 
    249    c->GLSLSkipStrictMaxUniformLimitCheck =
    250       screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_CONSTANTS);
    251 
    252    c->GLSLSkipStrictMaxVaryingLimitCheck =
    253       screen->get_param(screen, PIPE_CAP_TGSI_CAN_COMPACT_VARYINGS);
    254 }
    255 
    256 
    257 static GLboolean st_get_s3tc_override(void)
    258 {
    259    const char *override = _mesa_getenv("force_s3tc_enable");
    260    if (override && !strcmp(override, "true"))
    261       return GL_TRUE;
    262    return GL_FALSE;
    263 }
    264 
    265 /**
    266  * Given a member \c x of struct gl_extensions, return offset of
    267  * \c x in bytes.
    268  */
    269 #define o(x) offsetof(struct gl_extensions, x)
    270 
    271 
    272 struct st_extension_cap_mapping {
    273    int extension_offset;
    274    int cap;
    275 };
    276 
    277 struct st_extension_format_mapping {
    278    int extension_offset[2];
    279    enum pipe_format format[8];
    280 
    281    /* If TRUE, at least one format must be supported for the extensions to be
    282     * advertised. If FALSE, all the formats must be supported. */
    283    GLboolean need_at_least_one;
    284 };
    285 
    286 /**
    287  * Enable extensions if certain pipe formats are supported by the driver.
    288  * What extensions will be enabled and what formats must be supported is
    289  * described by the array of st_extension_format_mapping.
    290  *
    291  * target and bind_flags are passed to is_format_supported.
    292  */
    293 static void init_format_extensions(struct st_context *st,
    294                            const struct st_extension_format_mapping *mapping,
    295                            unsigned num_mappings,
    296                            enum pipe_texture_target target,
    297                            unsigned bind_flags)
    298 {
    299    struct pipe_screen *screen = st->pipe->screen;
    300    GLboolean *extensions = (GLboolean *) &st->ctx->Extensions;
    301    int i, j;
    302    int num_formats = Elements(mapping->format);
    303    int num_ext = Elements(mapping->extension_offset);
    304 
    305    for (i = 0; i < num_mappings; i++) {
    306       int num_supported = 0;
    307 
    308       /* Examine each format in the list. */
    309       for (j = 0; j < num_formats && mapping[i].format[j]; j++) {
    310          if (screen->is_format_supported(screen, mapping[i].format[j],
    311                                          target, 0, bind_flags)) {
    312             num_supported++;
    313          }
    314       }
    315 
    316       if (!num_supported ||
    317           (!mapping[i].need_at_least_one && num_supported != j)) {
    318          continue;
    319       }
    320 
    321       /* Enable all extensions in the list. */
    322       for (j = 0; j < num_ext && mapping[i].extension_offset[j]; j++)
    323          extensions[mapping[i].extension_offset[j]] = GL_TRUE;
    324    }
    325 }
    326 
    327 /**
    328  * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
    329  * which GL extensions are supported.
    330  * Quite a few extensions are always supported because they are standard
    331  * features or can be built on top of other gallium features.
    332  * Some fine tuning may still be needed.
    333  */
    334 void st_init_extensions(struct st_context *st)
    335 {
    336    struct pipe_screen *screen = st->pipe->screen;
    337    struct gl_context *ctx = st->ctx;
    338    int i, glsl_feature_level;
    339    GLboolean *extensions = (GLboolean *) &ctx->Extensions;
    340 
    341    static const struct st_extension_cap_mapping cap_mapping[] = {
    342       { o(ARB_base_instance),                PIPE_CAP_START_INSTANCE                   },
    343       { o(ARB_depth_clamp),                  PIPE_CAP_DEPTH_CLIP_DISABLE               },
    344       { o(ARB_depth_texture),                PIPE_CAP_TEXTURE_SHADOW_MAP               },
    345       { o(ARB_draw_buffers_blend),           PIPE_CAP_INDEP_BLEND_FUNC                 },
    346       { o(ARB_draw_instanced),               PIPE_CAP_TGSI_INSTANCEID                  },
    347       { o(ARB_fragment_program_shadow),      PIPE_CAP_TEXTURE_SHADOW_MAP               },
    348       { o(ARB_instanced_arrays),             PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR  },
    349       { o(ARB_occlusion_query),              PIPE_CAP_OCCLUSION_QUERY                  },
    350       { o(ARB_occlusion_query2),             PIPE_CAP_OCCLUSION_QUERY                  },
    351       { o(ARB_point_sprite),                 PIPE_CAP_POINT_SPRITE                     },
    352       { o(ARB_seamless_cube_map),            PIPE_CAP_SEAMLESS_CUBE_MAP                },
    353       { o(ARB_shader_stencil_export),        PIPE_CAP_SHADER_STENCIL_EXPORT            },
    354       { o(ARB_shader_texture_lod),           PIPE_CAP_SM3                              },
    355       { o(ARB_shadow),                       PIPE_CAP_TEXTURE_SHADOW_MAP               },
    356       { o(ARB_texture_non_power_of_two),     PIPE_CAP_NPOT_TEXTURES                    },
    357       { o(ARB_transform_feedback2),          PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME       },
    358       { o(ARB_transform_feedback3),          PIPE_CAP_STREAM_OUTPUT_PAUSE_RESUME       },
    359 
    360       { o(EXT_blend_equation_separate),      PIPE_CAP_BLEND_EQUATION_SEPARATE          },
    361       { o(EXT_draw_buffers2),                PIPE_CAP_INDEP_BLEND_ENABLE               },
    362       { o(EXT_shadow_funcs),                 PIPE_CAP_TEXTURE_SHADOW_MAP               },
    363       { o(EXT_stencil_two_side),             PIPE_CAP_TWO_SIDED_STENCIL                },
    364       { o(EXT_texture_array),                PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS         },
    365       { o(EXT_texture_filter_anisotropic),   PIPE_CAP_ANISOTROPIC_FILTER               },
    366       { o(EXT_texture_mirror_clamp),         PIPE_CAP_TEXTURE_MIRROR_CLAMP             },
    367       { o(EXT_texture_swizzle),              PIPE_CAP_TEXTURE_SWIZZLE                  },
    368       { o(EXT_timer_query),                  PIPE_CAP_TIMER_QUERY                      },
    369       { o(EXT_transform_feedback),           PIPE_CAP_MAX_STREAM_OUTPUT_BUFFERS        },
    370 
    371       { o(AMD_seamless_cubemap_per_texture), PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE    },
    372       { o(ATI_separate_stencil),             PIPE_CAP_TWO_SIDED_STENCIL                },
    373       { o(ATI_texture_mirror_once),          PIPE_CAP_TEXTURE_MIRROR_CLAMP             },
    374       { o(NV_conditional_render),            PIPE_CAP_CONDITIONAL_RENDER               },
    375       { o(NV_texture_barrier),               PIPE_CAP_TEXTURE_BARRIER                  },
    376       /* GL_NV_point_sprite is not supported by gallium because we don't
    377        * support the GL_POINT_SPRITE_R_MODE_NV option. */
    378       { o(MESA_texture_array),               PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS         },
    379    };
    380 
    381    /* Required: render target and sampler support */
    382    static const struct st_extension_format_mapping rendertarget_mapping[] = {
    383       { { o(ARB_texture_float) },
    384         { PIPE_FORMAT_R32G32B32A32_FLOAT,
    385           PIPE_FORMAT_R16G16B16A16_FLOAT } },
    386 
    387       { { o(ARB_texture_rgb10_a2ui) },
    388         { PIPE_FORMAT_B10G10R10A2_UINT } },
    389 
    390       { { o(EXT_framebuffer_sRGB) },
    391         { PIPE_FORMAT_A8B8G8R8_SRGB,
    392           PIPE_FORMAT_B8G8R8A8_SRGB },
    393          GL_TRUE }, /* at least one format must be supported */
    394 
    395       { { o(EXT_packed_float) },
    396         { PIPE_FORMAT_R11G11B10_FLOAT } },
    397 
    398       { { o(EXT_texture_integer) },
    399         { PIPE_FORMAT_R32G32B32A32_UINT,
    400           PIPE_FORMAT_R32G32B32A32_SINT } },
    401    };
    402 
    403    /* Required: depth stencil and sampler support */
    404    static const struct st_extension_format_mapping depthstencil_mapping[] = {
    405       { { o(ARB_depth_buffer_float) },
    406         { PIPE_FORMAT_Z32_FLOAT,
    407           PIPE_FORMAT_Z32_FLOAT_S8X24_UINT } },
    408 
    409       { { o(ARB_framebuffer_object),
    410           o(EXT_packed_depth_stencil) },
    411         { PIPE_FORMAT_S8_UINT_Z24_UNORM,
    412           PIPE_FORMAT_Z24_UNORM_S8_UINT },
    413         GL_TRUE }, /* at least one format must be supported */
    414    };
    415 
    416    /* Required: sampler support */
    417    static const struct st_extension_format_mapping texture_mapping[] = {
    418       { { o(ARB_texture_compression_rgtc) },
    419         { PIPE_FORMAT_RGTC1_UNORM,
    420           PIPE_FORMAT_RGTC1_SNORM,
    421           PIPE_FORMAT_RGTC2_UNORM,
    422           PIPE_FORMAT_RGTC2_SNORM } },
    423 
    424       { { o(ARB_texture_rg) },
    425         { PIPE_FORMAT_R8G8_UNORM } },
    426 
    427       { { o(EXT_texture_compression_latc) },
    428         { PIPE_FORMAT_LATC1_UNORM,
    429           PIPE_FORMAT_LATC1_SNORM,
    430           PIPE_FORMAT_LATC2_UNORM,
    431           PIPE_FORMAT_LATC2_SNORM } },
    432 
    433       { { o(EXT_texture_compression_s3tc),
    434           o(S3_s3tc) },
    435         { PIPE_FORMAT_DXT1_RGB,
    436           PIPE_FORMAT_DXT1_RGBA,
    437           PIPE_FORMAT_DXT3_RGBA,
    438           PIPE_FORMAT_DXT5_RGBA } },
    439 
    440       { { o(EXT_texture_shared_exponent) },
    441         { PIPE_FORMAT_R9G9B9E5_FLOAT } },
    442 
    443       { { o(EXT_texture_snorm) },
    444         { PIPE_FORMAT_R8G8B8A8_SNORM } },
    445 
    446       { { o(EXT_texture_sRGB),
    447           o(EXT_texture_sRGB_decode) },
    448         { PIPE_FORMAT_A8B8G8R8_SRGB,
    449           PIPE_FORMAT_B8G8R8A8_SRGB },
    450         GL_TRUE }, /* at least one format must be supported */
    451 
    452       { { o(ATI_texture_compression_3dc) },
    453         { PIPE_FORMAT_LATC2_UNORM } },
    454 
    455       { { o(MESA_ycbcr_texture) },
    456         { PIPE_FORMAT_UYVY,
    457           PIPE_FORMAT_YUYV },
    458         GL_TRUE }, /* at least one format must be supported */
    459 
    460       { { o(OES_compressed_ETC1_RGB8_texture) },
    461         { PIPE_FORMAT_ETC1_RGB8 } },
    462    };
    463 
    464    /* Required: vertex fetch support. */
    465    static const struct st_extension_format_mapping vertex_mapping[] = {
    466       { { o(ARB_vertex_type_2_10_10_10_rev) },
    467         { PIPE_FORMAT_R10G10B10A2_UNORM,
    468           PIPE_FORMAT_B10G10R10A2_UNORM,
    469           PIPE_FORMAT_R10G10B10A2_SNORM,
    470           PIPE_FORMAT_B10G10R10A2_SNORM,
    471           PIPE_FORMAT_R10G10B10A2_USCALED,
    472           PIPE_FORMAT_B10G10R10A2_USCALED,
    473           PIPE_FORMAT_R10G10B10A2_SSCALED,
    474           PIPE_FORMAT_B10G10R10A2_SSCALED } },
    475    };
    476 
    477    /*
    478     * Extensions that are supported by all Gallium drivers:
    479     */
    480    ctx->Extensions.ARB_ES2_compatibility = GL_TRUE;
    481    ctx->Extensions.ARB_copy_buffer = GL_TRUE;
    482    ctx->Extensions.ARB_draw_elements_base_vertex = GL_TRUE;
    483    ctx->Extensions.ARB_explicit_attrib_location = GL_TRUE;
    484    ctx->Extensions.ARB_fragment_coord_conventions = GL_TRUE;
    485    ctx->Extensions.ARB_fragment_program = GL_TRUE;
    486    ctx->Extensions.ARB_fragment_shader = GL_TRUE;
    487    ctx->Extensions.ARB_half_float_pixel = GL_TRUE;
    488    ctx->Extensions.ARB_half_float_vertex = GL_TRUE;
    489    ctx->Extensions.ARB_map_buffer_range = GL_TRUE;
    490    ctx->Extensions.ARB_shader_objects = GL_TRUE;
    491    ctx->Extensions.ARB_shading_language_100 = GL_TRUE;
    492    ctx->Extensions.ARB_texture_border_clamp = GL_TRUE; /* XXX temp */
    493    ctx->Extensions.ARB_texture_cube_map = GL_TRUE;
    494    ctx->Extensions.ARB_texture_env_combine = GL_TRUE;
    495    ctx->Extensions.ARB_texture_env_crossbar = GL_TRUE;
    496    ctx->Extensions.ARB_texture_env_dot3 = GL_TRUE;
    497    ctx->Extensions.ARB_texture_storage = GL_TRUE;
    498    ctx->Extensions.ARB_vertex_program = GL_TRUE;
    499    ctx->Extensions.ARB_vertex_shader = GL_TRUE;
    500    ctx->Extensions.ARB_window_pos = GL_TRUE;
    501 
    502    ctx->Extensions.EXT_blend_color = GL_TRUE;
    503    ctx->Extensions.EXT_blend_func_separate = GL_TRUE;
    504    ctx->Extensions.EXT_blend_minmax = GL_TRUE;
    505    ctx->Extensions.EXT_framebuffer_blit = GL_TRUE;
    506    ctx->Extensions.EXT_framebuffer_object = GL_TRUE;
    507    ctx->Extensions.EXT_fog_coord = GL_TRUE;
    508    ctx->Extensions.EXT_gpu_program_parameters = GL_TRUE;
    509    ctx->Extensions.EXT_pixel_buffer_object = GL_TRUE;
    510    ctx->Extensions.EXT_point_parameters = GL_TRUE;
    511    ctx->Extensions.EXT_provoking_vertex = GL_TRUE;
    512    ctx->Extensions.EXT_secondary_color = GL_TRUE;
    513    ctx->Extensions.EXT_separate_shader_objects = GL_TRUE;
    514    ctx->Extensions.EXT_texture_env_dot3 = GL_TRUE;
    515    ctx->Extensions.EXT_vertex_array_bgra = GL_TRUE;
    516 
    517    ctx->Extensions.ATI_texture_env_combine3 = GL_TRUE;
    518 
    519    ctx->Extensions.MESA_pack_invert = GL_TRUE;
    520 
    521    ctx->Extensions.NV_blend_square = GL_TRUE;
    522    ctx->Extensions.NV_fog_distance = GL_TRUE;
    523    ctx->Extensions.NV_texgen_reflection = GL_TRUE;
    524    ctx->Extensions.NV_texture_env_combine4 = GL_TRUE;
    525    ctx->Extensions.NV_texture_rectangle = GL_TRUE;
    526 #if 0
    527    /* possibly could support the following two */
    528    ctx->Extensions.NV_vertex_program = GL_TRUE;
    529    ctx->Extensions.NV_vertex_program1_1 = GL_TRUE;
    530 #endif
    531 
    532 #if FEATURE_OES_EGL_image
    533    ctx->Extensions.OES_EGL_image = GL_TRUE;
    534    if (ctx->API != API_OPENGL)
    535       ctx->Extensions.OES_EGL_image_external = GL_TRUE;
    536 #endif
    537 #if FEATURE_OES_draw_texture
    538    ctx->Extensions.OES_draw_texture = GL_TRUE;
    539 #endif
    540 
    541    /* Expose the extensions which directly correspond to gallium caps. */
    542    for (i = 0; i < Elements(cap_mapping); i++) {
    543       if (screen->get_param(screen, cap_mapping[i].cap)) {
    544          extensions[cap_mapping[i].extension_offset] = GL_TRUE;
    545       }
    546    }
    547 
    548    /* Expose the extensions which directly correspond to gallium formats. */
    549    init_format_extensions(st, rendertarget_mapping,
    550                           Elements(rendertarget_mapping), PIPE_TEXTURE_2D,
    551                           PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW);
    552    init_format_extensions(st, depthstencil_mapping,
    553                           Elements(depthstencil_mapping), PIPE_TEXTURE_2D,
    554                           PIPE_BIND_DEPTH_STENCIL | PIPE_BIND_SAMPLER_VIEW);
    555    init_format_extensions(st, texture_mapping, Elements(texture_mapping),
    556                           PIPE_TEXTURE_2D, PIPE_BIND_SAMPLER_VIEW);
    557    init_format_extensions(st, vertex_mapping, Elements(vertex_mapping),
    558                           PIPE_BUFFER, PIPE_BIND_VERTEX_BUFFER);
    559 
    560    /* Figure out GLSL support. */
    561    glsl_feature_level = screen->get_param(screen, PIPE_CAP_GLSL_FEATURE_LEVEL);
    562 
    563    if (glsl_feature_level >= 130) {
    564       ctx->Const.GLSLVersion = 130;
    565    } else {
    566       ctx->Const.GLSLVersion = 120;
    567    }
    568 
    569    _mesa_override_glsl_version(st->ctx);
    570 
    571    if (ctx->Const.GLSLVersion >= 130) {
    572       ctx->Const.NativeIntegers = GL_TRUE;
    573       ctx->Const.MaxClipPlanes = 8;
    574 
    575       /* Extensions that only depend on GLSL 1.3. */
    576       ctx->Extensions.ARB_conservative_depth = GL_TRUE;
    577       ctx->Extensions.ARB_shader_bit_encoding = GL_TRUE;
    578    } else {
    579       /* Optional integer support for GLSL 1.2. */
    580       if (screen->get_shader_param(screen, PIPE_SHADER_VERTEX,
    581                                    PIPE_SHADER_CAP_INTEGERS) &&
    582           screen->get_shader_param(screen, PIPE_SHADER_FRAGMENT,
    583                                    PIPE_SHADER_CAP_INTEGERS)) {
    584          ctx->Const.NativeIntegers = GL_TRUE;
    585       }
    586    }
    587 
    588    /* Below are the cases which cannot be moved into tables easily. */
    589 
    590    if (!ctx->Mesa_DXTn && !st_get_s3tc_override()) {
    591       ctx->Extensions.EXT_texture_compression_s3tc = GL_FALSE;
    592       ctx->Extensions.S3_s3tc = GL_FALSE;
    593    }
    594 
    595    if (screen->get_shader_param(screen, PIPE_SHADER_GEOMETRY,
    596                                 PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) {
    597 #if 0 /* XXX re-enable when GLSL compiler again supports geometry shaders */
    598       ctx->Extensions.ARB_geometry_shader4 = GL_TRUE;
    599 #endif
    600    }
    601 
    602    ctx->Extensions.NV_primitive_restart = GL_TRUE;
    603    if (!screen->get_param(screen, PIPE_CAP_PRIMITIVE_RESTART)) {
    604       ctx->Const.PrimitiveRestartInSoftware = GL_TRUE;
    605    }
    606 
    607    if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
    608       ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
    609 
    610       if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
    611          st->clamp_vert_color_in_shader = TRUE;
    612       }
    613 
    614       if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
    615          st->clamp_frag_color_in_shader = TRUE;
    616       }
    617    }
    618 
    619    if (screen->fence_finish) {
    620       ctx->Extensions.ARB_sync = GL_TRUE;
    621    }
    622 
    623    /* Maximum sample count. */
    624    for (i = 16; i > 0; --i) {
    625       if (screen->is_format_supported(screen, PIPE_FORMAT_B8G8R8A8_UNORM,
    626                                       PIPE_TEXTURE_2D, i,
    627                                       PIPE_BIND_RENDER_TARGET)) {
    628          ctx->Const.MaxSamples = i;
    629          break;
    630       }
    631    }
    632    if (ctx->Const.MaxSamples == 1) {
    633       /* one sample doesn't really make sense */
    634       ctx->Const.MaxSamples = 0;
    635    }
    636    else if (ctx->Const.MaxSamples >= 2) {
    637       ctx->Extensions.EXT_framebuffer_multisample = GL_TRUE;
    638    }
    639 
    640    if (ctx->Const.MaxDualSourceDrawBuffers > 0)
    641       ctx->Extensions.ARB_blend_func_extended = GL_TRUE;
    642 
    643    if (screen->get_param(screen, PIPE_CAP_TIMER_QUERY) &&
    644        screen->get_param(screen, PIPE_CAP_QUERY_TIMESTAMP)) {
    645       ctx->Extensions.ARB_timer_query = GL_TRUE;
    646    }
    647 
    648    if (ctx->Extensions.ARB_transform_feedback2 &&
    649        ctx->Extensions.ARB_draw_instanced) {
    650       ctx->Extensions.ARB_transform_feedback_instanced = GL_TRUE;
    651    }
    652    if (st->options.force_glsl_extensions_warn)
    653 	   ctx->Const.ForceGLSLExtensionsWarn = 1;
    654 }
    655