diff --git a/src/mesa/main/performance_monitor.c b/src/mesa/main/performance_monitor.c index cfb9db649b3..c184a8bd165 100644 --- a/src/mesa/main/performance_monitor.c +++ b/src/mesa/main/performance_monitor.c @@ -941,6 +941,15 @@ perf_monitor_result_size(const struct gl_context *ctx, unsigned group, counter; unsigned size = 0; + /** + * If no BeginPerfMonitorAMD has been issued for a monitor, + * or if SelectPerfMonitorCountersAMD is called on a monitor, then the result + * of querying for PERFMON_RESULT_SIZE will be 0. + * Using the same logic in is_perf_monitor_result_available(). + */ + if (!m->num_active_counters) + return 0; + for (group = 0; group < ctx->PerfMonitor.NumGroups; group++) { const struct gl_perf_monitor_group *g = &ctx->PerfMonitor.Groups[group]; @@ -963,7 +972,6 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, GET_CURRENT_CONTEXT(ctx); struct gl_perf_monitor_object *m = lookup_monitor(ctx, monitor); - bool result_available; if (m == NULL) { _mesa_error(ctx, GL_INVALID_VALUE, @@ -985,12 +993,12 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, return; } - /* If the monitor has never ended, there is no result. */ - result_available = m->Ended && - is_perf_monitor_result_available(ctx, m); - - /* AMD appears to return 0 for all queries unless a result is available. */ - if (!result_available) { + /** + * If no EndPerfMonitorAMD has been issued for a monitor + * then the result of querying for PERFMON_RESULT_AVAILABLE and + * PERFMON_RESULT_SIZE will be 0 + */ + if (!m->Ended) { *data = 0; if (bytesWritten != NULL) *bytesWritten = sizeof(GLuint); @@ -999,7 +1007,10 @@ _mesa_GetPerfMonitorCounterDataAMD(GLuint monitor, GLenum pname, switch (pname) { case GL_PERFMON_RESULT_AVAILABLE_AMD: - *data = 1; + if (is_perf_monitor_result_available(ctx, m)) + *data = 1; + else + *data = 0; if (bytesWritten != NULL) *bytesWritten = sizeof(GLuint); break;