glapi: move apiexec API condition determination to common code

it will be used elsewhere

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14000>
This commit is contained in:
Marek Olšák 2021-11-28 19:28:57 -05:00
parent 6e4238f99a
commit 1aa0b587cd
2 changed files with 52 additions and 47 deletions

View File

@ -179,54 +179,9 @@ class PrintCode(gl_XML.gl_print_base):
if f.exec_flavor not in exec_flavor_map:
raise Exception(
'Unrecognized exec flavor {0!r}'.format(f.exec_flavor))
condition_parts = []
if f.name in apiexec.functions:
ex = apiexec.functions[f.name]
unconditional_count = 0
if ex.compatibility is not None:
condition_parts.append('ctx->API == API_OPENGL_COMPAT')
unconditional_count += 1
if ex.core is not None:
condition_parts.append('ctx->API == API_OPENGL_CORE')
unconditional_count += 1
if ex.es1 is not None:
condition_parts.append('ctx->API == API_OPENGLES')
unconditional_count += 1
if ex.es2 is not None:
if ex.es2 > 20:
condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(ex.es2))
else:
condition_parts.append('ctx->API == API_OPENGLES2')
unconditional_count += 1
# If the function is unconditionally available in all four
# APIs, then it is always available. Replace the complex
# tautology condition with "true" and let GCC do the right
# thing.
if unconditional_count == 4:
condition_parts = ['true']
else:
if f.desktop:
if f.deprecated:
condition_parts.append('ctx->API == API_OPENGL_COMPAT')
else:
condition_parts.append('_mesa_is_desktop_gl(ctx)')
if 'es1' in f.api_map:
condition_parts.append('ctx->API == API_OPENGLES')
if 'es2' in f.api_map:
if f.api_map['es2'] > 2.0:
condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(int(f.api_map['es2'] * 10)))
else:
condition_parts.append('ctx->API == API_OPENGLES2')
if not condition_parts:
# This function does not exist in any API.
condition = apiexec.get_api_condition(f)
if not condition:
continue
condition = ' || '.join(condition_parts)
prefix = exec_flavor_map[f.exec_flavor]
if prefix is None:
# This function is not implemented, or is dispatched

View File

@ -295,3 +295,53 @@ functions = {
# GL_ARB_bindless_texture
"GetVertexAttribLui64vARB": exec_info(compatibility=30, core=31),
}
def get_api_condition(f):
condition_parts = []
if f.name in functions:
ex = functions[f.name]
unconditional_count = 0
if ex.compatibility is not None:
condition_parts.append('ctx->API == API_OPENGL_COMPAT')
unconditional_count += 1
if ex.core is not None:
condition_parts.append('ctx->API == API_OPENGL_CORE')
unconditional_count += 1
if ex.es1 is not None:
condition_parts.append('ctx->API == API_OPENGLES')
unconditional_count += 1
if ex.es2 is not None:
if ex.es2 > 20:
condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(ex.es2))
else:
condition_parts.append('ctx->API == API_OPENGLES2')
unconditional_count += 1
# If the function is unconditionally available in all four
# APIs, then it is always available. Replace the complex
# tautology condition with "true" and let GCC do the right
# thing.
if unconditional_count == 4:
condition_parts = ['true']
else:
if f.desktop:
if f.deprecated:
condition_parts.append('ctx->API == API_OPENGL_COMPAT')
else:
condition_parts.append('_mesa_is_desktop_gl(ctx)')
if 'es1' in f.api_map:
condition_parts.append('ctx->API == API_OPENGLES')
if 'es2' in f.api_map:
if f.api_map['es2'] > 2.0:
condition_parts.append('(ctx->API == API_OPENGLES2 && ctx->Version >= {0})'.format(int(f.api_map['es2'] * 10)))
else:
condition_parts.append('ctx->API == API_OPENGLES2')
if not condition_parts:
# This function does not exist in any API.
return None
return ' || '.join(condition_parts)