From: Petri Latvala Date: Wed, 23 Apr 2014 08:08:52 +0000 (+0300) Subject: mesa: Add core support for the GL_INTEL_performance_query extension. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dac82ceac5d726ff8851051f671396cfbd1abc63;p=mesa.git mesa: Add core support for the GL_INTEL_performance_query extension. Like AMD_performance_monitor, this extension provides an interface for applications (and OpenGL-based tools) to access GPU performance counters. Since the exact performance counters available vary between vendors and hardware generations, the extension provides an API the application can use to get the names, types, and minimum/maximum values of all available counters. Applications create performance queries based on available query types, and begin/end measurement collection. Multiple queries can be measuring simultaneously. v2: Whitespace changes v3: src/mapi/glapi/gen/gl_API.xml: Also expose the functions to GLES2. v4: Whitespace changes, static_dispatch="false" for all functions, fix dispatch_sanity test for GLES2 functions Signed-off-by: Petri Latvala Reviewed-by: Ian Romanick --- diff --git a/src/mapi/glapi/gen/INTEL_performance_query.xml b/src/mapi/glapi/gen/INTEL_performance_query.xml new file mode 100644 index 00000000000..25cd1817f57 --- /dev/null +++ b/src/mapi/glapi/gen/INTEL_performance_query.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am index 35cf924da08..6f36989bcca 100644 --- a/src/mapi/glapi/gen/Makefile.am +++ b/src/mapi/glapi/gen/Makefile.am @@ -172,6 +172,7 @@ API_XML = \ EXT_texture_array.xml \ EXT_texture_integer.xml \ EXT_transform_feedback.xml \ + INTEL_performance_query.xml \ KHR_debug.xml \ NV_conditional_render.xml \ NV_primitive_restart.xml \ diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml index 46640397bcc..d6f9b578772 100644 --- a/src/mapi/glapi/gen/gl_API.xml +++ b/src/mapi/glapi/gen/gl_API.xml @@ -12812,6 +12812,8 @@ + + diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h index 30da5d4222b..c96502a7ff8 100644 --- a/src/mesa/main/config.h +++ b/src/mesa/main/config.h @@ -281,6 +281,14 @@ #define MAX_VERTEX_STREAMS 4 /*@}*/ +/** For GL_INTEL_performance_query */ +/*@{*/ +#define MAX_PERFQUERY_QUERY_NAME_LENGTH 256 +#define MAX_PERFQUERY_COUNTER_NAME_LENGTH 256 +#define MAX_PERFQUERY_COUNTER_DESC_LENGTH 1024 +#define PERFQUERY_HAVE_GPA_EXTENDED_COUNTERS 0 +/*@}*/ + /* * Color channel component order * diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c index 55ed5d3cc2c..c2ff7e3b752 100644 --- a/src/mesa/main/extensions.c +++ b/src/mesa/main/extensions.c @@ -331,6 +331,7 @@ static const struct extension extension_table[] = { { "GL_IBM_rasterpos_clip", o(dummy_true), GLL, 1996 }, { "GL_IBM_texture_mirrored_repeat", o(dummy_true), GLL, 1998 }, { "GL_INGR_blend_func_separate", o(EXT_blend_func_separate), GLL, 1999 }, + { "GL_INTEL_performance_query", o(INTEL_performance_query), GL | ES2, 2013 }, { "GL_MESA_pack_invert", o(MESA_pack_invert), GL, 2002 }, { "GL_MESA_texture_signed_rgba", o(EXT_texture_snorm), GL, 2009 }, { "GL_MESA_window_pos", o(dummy_true), GLL, 2000 }, diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c index 937d7aa67b4..80a5839b575 100644 --- a/src/mesa/main/get.c +++ b/src/mesa/main/get.c @@ -394,6 +394,7 @@ EXTRA_EXT(ARB_viewport_array); EXTRA_EXT(ARB_compute_shader); EXTRA_EXT(ARB_gpu_shader5); EXTRA_EXT2(ARB_transform_feedback3, ARB_gpu_shader5); +EXTRA_EXT(INTEL_performance_query); static const int extra_ARB_color_buffer_float_or_glcore[] = { diff --git a/src/mesa/main/get_hash_params.py b/src/mesa/main/get_hash_params.py index 1d565028ebb..d40fa077827 100644 --- a/src/mesa/main/get_hash_params.py +++ b/src/mesa/main/get_hash_params.py @@ -311,6 +311,12 @@ descriptor=[ # GL_ARB_get_program_binary / GL_OES_get_program_binary [ "NUM_PROGRAM_BINARY_FORMATS", "CONST(0), NO_EXTRA" ], [ "PROGRAM_BINARY_FORMATS", "LOC_CUSTOM, TYPE_INVALID, 0, NO_EXTRA" ], + +# GL_INTEL_performance_query + [ "PERFQUERY_QUERY_NAME_LENGTH_MAX_INTEL", "CONST(MAX_PERFQUERY_QUERY_NAME_LENGTH), extra_INTEL_performance_query" ], + [ "PERFQUERY_COUNTER_NAME_LENGTH_MAX_INTEL", "CONST(MAX_PERFQUERY_COUNTER_NAME_LENGTH), extra_INTEL_performance_query" ], + [ "PERFQUERY_COUNTER_DESC_LENGTH_MAX_INTEL", "CONST(MAX_PERFQUERY_COUNTER_DESC_LENGTH), extra_INTEL_performance_query" ], + [ "PERFQUERY_GPA_EXTENDED_COUNTERS_INTEL", "CONST(PERFQUERY_HAVE_GPA_EXTENDED_COUNTERS), extra_INTEL_performance_query" ], ]}, # GLES3 is not a typo. diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index e57c04db3d9..917d071a2c8 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3613,6 +3613,7 @@ struct gl_extensions GLboolean ATI_texture_env_combine3; GLboolean ATI_fragment_shader; GLboolean ATI_separate_stencil; + GLboolean INTEL_performance_query; GLboolean MESA_pack_invert; GLboolean MESA_ycbcr_texture; GLboolean NV_conditional_render; diff --git a/src/mesa/main/performance_monitor.c b/src/mesa/main/performance_monitor.c index e62f7701217..597f633f6f9 100644 --- a/src/mesa/main/performance_monitor.c +++ b/src/mesa/main/performance_monitor.c @@ -639,3 +639,222 @@ _mesa_perf_monitor_counter_size(const struct gl_perf_monitor_counter *c) return 0; } } + +extern void GLAPIENTRY +_mesa_GetFirstPerfQueryIdINTEL(GLuint *queryId) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If queryId pointer is equal to 0, INVALID_VALUE error is generated." + */ + if (!queryId) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetFirstPerfQueryIdINTEL(queryId == NULL)"); + return; + } + + /* The GL_INTEL_performance_query spec says: + * + * "If the given hardware platform doesn't support any performance + * queries, then the value of 0 is returned and INVALID_OPERATION error + * is raised." + */ + + *queryId = 0; + _mesa_error(ctx, GL_INVALID_OPERATION, + "glGetFirstPerfQueryIdINTEL(no queries supported)"); +} + +extern void GLAPIENTRY +_mesa_GetNextPerfQueryIdINTEL(GLuint queryId, GLuint *nextQueryId) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If nextQueryId pointer is equal to 0, an INVALID_VALUE error is + * generated." + */ + if (!nextQueryId) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetNextPerfQueryIdINTEL(nextQueryId == NULL)"); + return; + } + + /* The GL_INTEL_performance_query spec says: + * + * "If the specified performance query identifier is invalid then + * INVALID_VALUE error is generated. Whenever error is generated, the + * value of 0 is returned." + * + * No queries are supported, so all queries are invalid. + */ + *nextQueryId = 0; + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetNextPerfQueryIdINTEL(invalid query)"); +} + +extern void GLAPIENTRY +_mesa_GetPerfQueryIdByNameINTEL(char *queryName, GLuint *queryId) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If queryName does not reference a valid query name, an INVALID_VALUE + * error is generated." + * + * No queries are supported, so all query names are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetPerfQueryIdByNameINTEL(invalid query name)"); +} + +extern void GLAPIENTRY +_mesa_GetPerfQueryInfoINTEL(GLuint queryId, + GLuint queryNameLength, char *queryName, + GLuint *dataSize, GLuint *noCounters, + GLuint *noActiveInstances, + GLuint *capsMask) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If queryId does not reference a valid query type, an INVALID_VALUE + * error is generated." + * + * No queries are supported, so all queries are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetPerfQueryInfoINTEL(invalid query)"); +} + +extern void GLAPIENTRY +_mesa_GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId, + GLuint counterNameLength, char *counterName, + GLuint counterDescLength, char *counterDesc, + GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, + GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If the pair of queryId and counterId does not reference a valid + * counter, an INVALID_VALUE error is generated." + * + * No queries are supported, so all queries are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetPerfCounterInfoINTEL(invalid counterId)"); +} + +extern void GLAPIENTRY +_mesa_CreatePerfQueryINTEL(GLuint queryId, GLuint *queryHandle) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If queryId does not reference a valid query type, an INVALID_VALUE + * error is generated." + * + * No queries are supported, so all queries are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glCreatePerfQueryINTEL(invalid queryId)"); +} + +extern void GLAPIENTRY +_mesa_DeletePerfQueryINTEL(GLuint queryHandle) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If a query handle doesn't reference a previously created performance + * query instance, an INVALID_VALUE error is generated." + * + * No queries are supported, so all queries are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glDeletePerfQueryINTEL(invalid queryHandle)"); +} + +extern void GLAPIENTRY +_mesa_BeginPerfQueryINTEL(GLuint queryHandle) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If a query handle doesn't reference a previously created performance + * query instance, an INVALID_VALUE error is generated." + * + * No queries are supported, so all queries are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glBeginPerfQueryINTEL(invalid queryHandle)"); +} + +extern void GLAPIENTRY +_mesa_EndPerfQueryINTEL(GLuint queryHandle) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If a performance query is not currently started, an + * INVALID_OPERATION error will be generated." + * + * The specification doesn't state that an invalid handle would be an + * INVALID_VALUE error. Regardless, query for such a handle will not be + * started, so we generate an INVALID_OPERATION in that case. + * + * No queries are supported, so all handles are invalid. + */ + + _mesa_error(ctx, GL_INVALID_OPERATION, + "glEndPerfQueryINTEL(query not started)"); +} + +extern void GLAPIENTRY +_mesa_GetPerfQueryDataINTEL(GLuint queryHandle, GLuint flags, + GLsizei dataSize, void *data, GLuint *bytesWritten) +{ + GET_CURRENT_CONTEXT(ctx); + + /* The GL_INTEL_performance_query spec says: + * + * "If bytesWritten or data pointers are NULL then an INVALID_VALUE + * error is generated." + */ + if (!bytesWritten || !data) { + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetPerfQueryDataINTEL(bytesWritten or data is NULL)"); + return; + } + + /* The specification doesn't state that an invalid handle generates an + * error. We could interpret that to mean the case should be handled as + * "measurement not ready for this query", but what should be done if + * `flags' equals PERFQUERY_WAIT_INTEL? + * + * To resolve this, we just generate an INVALID_VALUE from an invalid query + * handle. + * + * No queries are supported, so all handles are invalid. + */ + + _mesa_error(ctx, GL_INVALID_VALUE, + "glGetPerfQueryDataINTEL(invalid queryHandle)"); +} diff --git a/src/mesa/main/performance_monitor.h b/src/mesa/main/performance_monitor.h index 76234e5c1bc..7b311e4e01d 100644 --- a/src/mesa/main/performance_monitor.h +++ b/src/mesa/main/performance_monitor.h @@ -23,7 +23,8 @@ /** * \file performance_monitor.h - * Core Mesa support for the AMD_performance_monitor extension. + * Core Mesa support for the AMD_performance_monitor extension and the + * INTEL_performance_query extension. */ #pragma once @@ -85,4 +86,44 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, unsigned _mesa_perf_monitor_counter_size(const struct gl_perf_monitor_counter *); + +extern void GLAPIENTRY +_mesa_GetFirstPerfQueryIdINTEL(GLuint *queryId); + +extern void GLAPIENTRY +_mesa_GetNextPerfQueryIdINTEL(GLuint queryId, GLuint *nextQueryId); + +extern void GLAPIENTRY +_mesa_GetPerfQueryIdByNameINTEL(char *queryName, GLuint *queryId); + +extern void GLAPIENTRY +_mesa_GetPerfQueryInfoINTEL(GLuint queryId, + GLuint queryNameLength, char *queryName, + GLuint *dataSize, GLuint *noCounters, + GLuint *noActiveInstances, + GLuint *capsMask); + +extern void GLAPIENTRY +_mesa_GetPerfCounterInfoINTEL(GLuint queryId, GLuint counterId, + GLuint counterNameLength, char *counterName, + GLuint counterDescLength, char *counterDesc, + GLuint *counterOffset, GLuint *counterDataSize, GLuint *counterTypeEnum, + GLuint *counterDataTypeEnum, GLuint64 *rawCounterMaxValue); + +extern void GLAPIENTRY +_mesa_CreatePerfQueryINTEL(GLuint queryId, GLuint *queryHandle); + +extern void GLAPIENTRY +_mesa_DeletePerfQueryINTEL(GLuint queryHandle); + +extern void GLAPIENTRY +_mesa_BeginPerfQueryINTEL(GLuint queryHandle); + +extern void GLAPIENTRY +_mesa_EndPerfQueryINTEL(GLuint queryHandle); + +extern void GLAPIENTRY +_mesa_GetPerfQueryDataINTEL(GLuint queryHandle, GLuint flags, + GLsizei dataSize, void *data, GLuint *bytesWritten); + #endif diff --git a/src/mesa/main/tests/dispatch_sanity.cpp b/src/mesa/main/tests/dispatch_sanity.cpp index fe797f98088..0e57653b4b4 100644 --- a/src/mesa/main/tests/dispatch_sanity.cpp +++ b/src/mesa/main/tests/dispatch_sanity.cpp @@ -920,6 +920,18 @@ const struct function gl_core_functions_possible[] = { { "glEndPerfMonitorAMD", 11, -1 }, { "glGetPerfMonitorCounterDataAMD", 11, -1 }, + /* GL_INTEL_performance_query */ + { "glGetFirstPerfQueryIdINTEL", 30, -1 }, + { "glGetNextPerfQueryIdINTEL", 30, -1 }, + { "glGetPerfQueryIdByNameINTEL", 30, -1 }, + { "glGetPerfQueryInfoINTEL", 30, -1 }, + { "glGetPerfCounterInfoINTEL", 30, -1 }, + { "glCreatePerfQueryINTEL", 30, -1 }, + { "glDeletePerfQueryINTEL", 30, -1 }, + { "glBeginPerfQueryINTEL", 30, -1 }, + { "glEndPerfQueryINTEL", 30, -1 }, + { "glGetPerfQueryDataINTEL", 30, -1 }, + /* GL_NV_vdpau_interop */ { "glVDPAUInitNV", 11, -1 }, { "glVDPAUFiniNV", 11, -1 }, @@ -1340,6 +1352,19 @@ const struct function gles2_functions_possible[] = { { "glProgramUniformMatrix4x3fvEXT", 20, -1 }, { "glValidateProgramPipelineEXT", 20, -1 }, { "glGetProgramPipelineInfoLogEXT", 20, -1 }, + + /* GL_INTEL_performance_query */ + { "glGetFirstPerfQueryIdINTEL", 20, -1 }, + { "glGetNextPerfQueryIdINTEL", 20, -1 }, + { "glGetPerfQueryIdByNameINTEL", 20, -1 }, + { "glGetPerfQueryInfoINTEL", 20, -1 }, + { "glGetPerfCounterInfoINTEL", 20, -1 }, + { "glCreatePerfQueryINTEL", 20, -1 }, + { "glDeletePerfQueryINTEL", 20, -1 }, + { "glBeginPerfQueryINTEL", 20, -1 }, + { "glEndPerfQueryINTEL", 20, -1 }, + { "glGetPerfQueryDataINTEL", 20, -1 }, + { NULL, 0, -1 } };