[Mesa-dev] [PATCH 03/12] st/mesa: make st_init_extensions context-independent
Ilia Mirkin
imirkin at alum.mit.edu
Sun Aug 3 09:35:14 PDT 2014
On Sun, Aug 3, 2014 at 12:28 PM, Marek Olšák <maraeo at gmail.com> wrote:
> On Sun, Aug 3, 2014 at 6:06 PM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
>> On Sun, Aug 3, 2014 at 11:18 AM, Marek Olšák <maraeo at gmail.com> wrote:
>>> From: Marek Olšák <marek.olsak at amd.com>
>>>
>>> Setting Const.MaxSamples needed a rework, so that it doesn't call
>>> st_choose_format, which depends on st_context.
>>>
>>> Other than that, there is no change in functionality.
>>> ---
>>> src/mesa/state_tracker/st_context.c | 26 ++-
>>> src/mesa/state_tracker/st_extensions.c | 400 +++++++++++++++++----------------
>>> src/mesa/state_tracker/st_extensions.h | 8 +-
>>> 3 files changed, 242 insertions(+), 192 deletions(-)
>>>
>>> diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
>>> index ccd19f3..5f83e52 100644
>>> --- a/src/mesa/state_tracker/st_context.c
>>> +++ b/src/mesa/state_tracker/st_context.c
>>> @@ -201,10 +201,34 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe,
>>> !!(screen->get_param(screen, PIPE_CAP_TEXTURE_BORDER_COLOR_QUIRK) &
>>> (PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_NV50 |
>>> PIPE_QUIRK_TEXTURE_BORDER_COLOR_SWIZZLE_R600));
>>> + st->has_time_elapsed =
>>> + screen->get_param(screen, PIPE_CAP_QUERY_TIME_ELAPSED);
>>>
>>> /* GL limits and extensions */
>>> st_init_limits(st);
>>> - st_init_extensions(st);
>>> + st_init_extensions(st->pipe->screen, ctx->API, &ctx->Const,
>>> + &ctx->Extensions, &st->options, ctx->Mesa_DXTn);
>>> +
>>> + /* Enable shader-based fallbacks for ARB_color_buffer_float if needed. */
>>> + if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
>>> + if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
>>> + st->clamp_vert_color_in_shader = TRUE;
>>> + }
>>> +
>>> + if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
>>> + st->clamp_frag_color_in_shader = TRUE;
>>> + }
>>> +
>>> + /* For drivers which cannot do color clamping, it's better to just
>>> + * disable ARB_color_buffer_float in the core profile, because
>>> + * the clamping is deprecated there anyway. */
>>> + if (ctx->API == API_OPENGL_CORE &&
>>> + (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) {
>>> + st->clamp_vert_color_in_shader = GL_FALSE;
>>> + st->clamp_frag_color_in_shader = GL_FALSE;
>>
>> I know it was like that in the original code, but you should either
>> use TRUE/FALSE or GL_TRUE/GL_FALSE in both places... the fields are
>> declared as GLbooleans ftr.
>
> Okay, consider it fixed.
>
>>
>>> + ctx->Extensions.ARB_color_buffer_float = GL_FALSE;
>>> + }
>>> + }
>>>
>>> _mesa_compute_version(ctx);
>>>
>>> diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c
>>> index f04ff4c..6901b51 100644
>>> --- a/src/mesa/state_tracker/st_extensions.c
>>> +++ b/src/mesa/state_tracker/st_extensions.c
>>> @@ -340,14 +340,15 @@ struct st_extension_format_mapping {
>>> *
>>> * target and bind_flags are passed to is_format_supported.
>>> */
>>> -static void init_format_extensions(struct st_context *st,
>>> - const struct st_extension_format_mapping *mapping,
>>> - unsigned num_mappings,
>>> - enum pipe_texture_target target,
>>> - unsigned bind_flags)
>>> +static void
>>> +init_format_extensions(struct pipe_screen *screen,
>>> + struct gl_extensions *extensions,
>>> + const struct st_extension_format_mapping *mapping,
>>> + unsigned num_mappings,
>>> + enum pipe_texture_target target,
>>> + unsigned bind_flags)
>>> {
>>> - struct pipe_screen *screen = st->pipe->screen;
>>> - GLboolean *extensions = (GLboolean *) &st->ctx->Extensions;
>>> + GLboolean *extension_table = (GLboolean *) extensions;
>>> unsigned i;
>>> int j;
>>> int num_formats = Elements(mapping->format);
>>> @@ -371,10 +372,36 @@ static void init_format_extensions(struct st_context *st,
>>>
>>> /* Enable all extensions in the list. */
>>> for (j = 0; j < num_ext && mapping[i].extension_offset[j]; j++)
>>> - extensions[mapping[i].extension_offset[j]] = GL_TRUE;
>>> + extension_table[mapping[i].extension_offset[j]] = GL_TRUE;
>>> + }
>>> +}
>>> +
>>> +
>>> +/**
>>> + * Given a list of formats and bind flags, return the maximum number
>>> + * of samples supported by any of those formats.
>>> + */
>>> +static unsigned
>>> +get_max_samples_for_formats(struct pipe_screen *screen,
>>> + unsigned num_formats,
>>> + enum pipe_format *formats,
>>> + unsigned max_samples,
>>> + unsigned bind)
>>> +{
>>> + unsigned i, f;
>>> +
>>> + for (i = max_samples; i > 0; --i) {
>>> + for (f = 0; f < num_formats; f++) {
>>> + if (screen->is_format_supported(screen, formats[f],
>>> + PIPE_TEXTURE_2D, i, bind)) {
>>> + return i;
>>> + }
>>> + }
>>> }
>>> + return 0;
>>> }
>>>
>>> +
>>> /**
>>> * Use pipe_screen::get_param() to query PIPE_CAP_ values to determine
>>> * which GL extensions are supported.
>>> @@ -382,12 +409,15 @@ static void init_format_extensions(struct st_context *st,
>>> * features or can be built on top of other gallium features.
>>> * Some fine tuning may still be needed.
>>> */
>>> -void st_init_extensions(struct st_context *st)
>>> +void st_init_extensions(struct pipe_screen *screen,
>>> + gl_api api,
>>> + struct gl_constants *consts,
>>> + struct gl_extensions *extensions,
>>> + struct st_config_options *options,
>>> + boolean has_lib_dxtc)
>>> {
>>> - struct pipe_screen *screen = st->pipe->screen;
>>> - struct gl_context *ctx = st->ctx;
>>> int i, glsl_feature_level;
>>> - GLboolean *extensions = (GLboolean *) &ctx->Extensions;
>>> + GLboolean *extension_table = (GLboolean *) extensions;
>>>
>>> static const struct st_extension_cap_mapping cap_mapping[] = {
>>> { o(ARB_base_instance), PIPE_CAP_START_INSTANCE },
>>
>> [...]
>>
>>> /* ARB_color_buffer_float. */
>>> if (screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_UNCLAMPED)) {
>>> - ctx->Extensions.ARB_color_buffer_float = GL_TRUE;
>>> -
>>> - if (!screen->get_param(screen, PIPE_CAP_VERTEX_COLOR_CLAMPED)) {
>>> - st->clamp_vert_color_in_shader = TRUE;
>>> - }
>>> -
>>> - if (!screen->get_param(screen, PIPE_CAP_FRAGMENT_COLOR_CLAMPED)) {
>>> - st->clamp_frag_color_in_shader = TRUE;
>>> - }
>>> -
>>> - /* For drivers which cannot do color clamping, it's better to just
>>> - * disable ARB_color_buffer_float in the core profile, because
>>> - * the clamping is deprecated there anyway. */
>>> - if (ctx->API == API_OPENGL_CORE &&
>>> - (st->clamp_frag_color_in_shader || st->clamp_vert_color_in_shader)) {
>>> - st->clamp_vert_color_in_shader = GL_FALSE;
>>> - st->clamp_frag_color_in_shader = GL_FALSE;
>>> - ctx->Extensions.ARB_color_buffer_float = GL_FALSE;
>>> - }
>>> + extensions->ARB_color_buffer_float = GL_TRUE;
>>
>> This should just go into the big table then, right?
>
> Yes, but not in this patch. Maybe in a later patch as a cleanup.
>
>>
>>> }
>>>
>>> if (screen->fence_finish) {
>>> - ctx->Extensions.ARB_sync = GL_TRUE;
>>> + extensions->ARB_sync = GL_TRUE;
>>> }
>>>
>>> /* Maximum sample count. */
>>> - for (i = 16; i > 0; --i) {
>>> - enum pipe_format pformat = st_choose_format(st, GL_RGBA,
>>> - GL_NONE, GL_NONE,
>>> - PIPE_TEXTURE_2D, i,
>>> - PIPE_BIND_RENDER_TARGET, FALSE);
>>> - if (pformat != PIPE_FORMAT_NONE) {
>>> - ctx->Const.MaxSamples = i;
>>> - ctx->Const.MaxColorTextureSamples = i;
>>> - break;
>>> - }
>>> + {
>>> + enum pipe_format color_formats[] = {
>>> + PIPE_FORMAT_R8G8B8A8_UNORM,
>>> + PIPE_FORMAT_B8G8R8A8_UNORM,
>>> + PIPE_FORMAT_A8R8G8B8_UNORM,
>>> + PIPE_FORMAT_A8B8G8R8_UNORM,
>>> + };
>>> + enum pipe_format depth_formats[] = {
>>> + PIPE_FORMAT_Z16_UNORM,
>>> + PIPE_FORMAT_Z24X8_UNORM,
>>> + PIPE_FORMAT_X8Z24_UNORM,
>>> + PIPE_FORMAT_Z32_UNORM,
>>> + PIPE_FORMAT_Z32_FLOAT
>>> + };
>>> + enum pipe_format int_formats[] = {
>>> + PIPE_FORMAT_R32G32B32A32_UINT,
>>> + PIPE_FORMAT_R32G32B32A32_SINT,
>>
>> Uhm... should this be R8G8B8A8 instead? At least that's what's in the
>> format_map in st_format.c for GL_RGBA_INTEGER_EXT. (And it doesn't
>> include the UINT variant...)
>
> It doesn't matter which formats are tested as long as at least one
> format in the list is supported for MSAA texturing. I assume all
> drivers that support MSAA integer texturing support it with all
> integer formats. R32G32B32A32 seemed like a safe choice.
For nv50 it'll still work out since you'll check lower MS levels, but
e.g. we have:
if (sample_count == 8 && util_format_get_blocksizebits(format) >= 128)
return FALSE;
I wouldn't be surprised if the 128-bit wide thing were a restriction
elsewhere too. Especially since the old format check was for RGBA8,
that seems like the more prudent thing to do, IMO.
-ilia
More information about the mesa-dev
mailing list