mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 04:48:08 +02:00
mesa/st: merge perfmon object from st into mesa
This just merges the perf mon subclass into the base class, and cleans up the result. Acked-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14327>
This commit is contained in:
parent
0fb946da94
commit
a3099f885e
4 changed files with 56 additions and 90 deletions
|
|
@ -1872,6 +1872,18 @@ struct gl_perf_monitor_object
|
|||
* BITSET_TEST(ActiveCounters[g], c)
|
||||
*/
|
||||
GLuint **ActiveCounters;
|
||||
|
||||
unsigned num_active_counters;
|
||||
|
||||
struct st_perf_counter_object {
|
||||
struct pipe_query *query;
|
||||
int id;
|
||||
int group_id;
|
||||
unsigned batch_index;
|
||||
} *active_counters;
|
||||
|
||||
struct pipe_query *batch_query;
|
||||
union pipe_query_result *batch_result;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include "performance_monitor.h"
|
||||
#include "util/bitset.h"
|
||||
#include "util/ralloc.h"
|
||||
#include "util/u_memory.h"
|
||||
#include "api_exec_decl.h"
|
||||
|
||||
#include "state_tracker/st_cb_perfmon.h"
|
||||
|
|
@ -67,7 +68,7 @@ static struct gl_perf_monitor_object *
|
|||
new_performance_monitor(struct gl_context *ctx, GLuint index)
|
||||
{
|
||||
unsigned i;
|
||||
struct gl_perf_monitor_object *m = st_NewPerfMonitor(ctx);
|
||||
struct gl_perf_monitor_object *m = CALLOC_STRUCT(gl_perf_monitor_object);
|
||||
|
||||
if (m == NULL)
|
||||
return NULL;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ static bool
|
|||
init_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_context *st = st_context(ctx);
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st->pipe;
|
||||
unsigned *batch = NULL;
|
||||
unsigned num_active_counters = 0;
|
||||
|
|
@ -73,9 +72,9 @@ init_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
|||
if (!num_active_counters)
|
||||
return true;
|
||||
|
||||
stm->active_counters = CALLOC(num_active_counters,
|
||||
sizeof(*stm->active_counters));
|
||||
if (!stm->active_counters)
|
||||
m->active_counters = CALLOC(num_active_counters,
|
||||
sizeof(*m->active_counters));
|
||||
if (!m->active_counters)
|
||||
return false;
|
||||
|
||||
if (max_batch_counters) {
|
||||
|
|
@ -92,7 +91,7 @@ init_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
|||
BITSET_FOREACH_SET(cid, m->ActiveCounters[gid], g->NumCounters) {
|
||||
const struct st_perf_monitor_counter *stc = &stg->counters[cid];
|
||||
struct st_perf_counter_object *cntr =
|
||||
&stm->active_counters[stm->num_active_counters];
|
||||
&m->active_counters[m->num_active_counters];
|
||||
|
||||
cntr->id = cid;
|
||||
cntr->group_id = gid;
|
||||
|
|
@ -104,16 +103,16 @@ init_perf_monitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
|||
if (!cntr->query)
|
||||
goto fail;
|
||||
}
|
||||
++stm->num_active_counters;
|
||||
++m->num_active_counters;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create the batch query. */
|
||||
if (num_batch_counters) {
|
||||
stm->batch_query = pipe->create_batch_query(pipe, num_batch_counters,
|
||||
m->batch_query = pipe->create_batch_query(pipe, num_batch_counters,
|
||||
batch);
|
||||
stm->batch_result = CALLOC(num_batch_counters, sizeof(stm->batch_result->batch[0]));
|
||||
if (!stm->batch_query || !stm->batch_result)
|
||||
m->batch_result = CALLOC(num_batch_counters, sizeof(m->batch_result->batch[0]));
|
||||
if (!m->batch_query || !m->batch_result)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
|
@ -126,55 +125,44 @@ fail:
|
|||
}
|
||||
|
||||
static void
|
||||
reset_perf_monitor(struct st_perf_monitor_object *stm,
|
||||
reset_perf_monitor(struct gl_perf_monitor_object *m,
|
||||
struct pipe_context *pipe)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < stm->num_active_counters; ++i) {
|
||||
struct pipe_query *query = stm->active_counters[i].query;
|
||||
for (i = 0; i < m->num_active_counters; ++i) {
|
||||
struct pipe_query *query = m->active_counters[i].query;
|
||||
if (query)
|
||||
pipe->destroy_query(pipe, query);
|
||||
}
|
||||
FREE(stm->active_counters);
|
||||
stm->active_counters = NULL;
|
||||
stm->num_active_counters = 0;
|
||||
FREE(m->active_counters);
|
||||
m->active_counters = NULL;
|
||||
m->num_active_counters = 0;
|
||||
|
||||
if (stm->batch_query) {
|
||||
pipe->destroy_query(pipe, stm->batch_query);
|
||||
stm->batch_query = NULL;
|
||||
if (m->batch_query) {
|
||||
pipe->destroy_query(pipe, m->batch_query);
|
||||
m->batch_query = NULL;
|
||||
}
|
||||
FREE(stm->batch_result);
|
||||
stm->batch_result = NULL;
|
||||
}
|
||||
|
||||
struct gl_perf_monitor_object *
|
||||
st_NewPerfMonitor(struct gl_context *ctx)
|
||||
{
|
||||
struct st_perf_monitor_object *stq = CALLOC_STRUCT(st_perf_monitor_object);
|
||||
if (stq)
|
||||
return &stq->base;
|
||||
return NULL;
|
||||
FREE(m->batch_result);
|
||||
m->batch_result = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
st_DeletePerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
|
||||
reset_perf_monitor(stm, pipe);
|
||||
FREE(stm);
|
||||
reset_perf_monitor(m, pipe);
|
||||
FREE(m);
|
||||
}
|
||||
|
||||
GLboolean
|
||||
st_BeginPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
unsigned i;
|
||||
|
||||
if (!stm->num_active_counters) {
|
||||
if (!m->num_active_counters) {
|
||||
/* Create a query for each active counter before starting
|
||||
* a new monitoring session. */
|
||||
if (!init_perf_monitor(ctx, m))
|
||||
|
|
@ -182,51 +170,49 @@ st_BeginPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
|||
}
|
||||
|
||||
/* Start the query for each active counter. */
|
||||
for (i = 0; i < stm->num_active_counters; ++i) {
|
||||
struct pipe_query *query = stm->active_counters[i].query;
|
||||
for (i = 0; i < m->num_active_counters; ++i) {
|
||||
struct pipe_query *query = m->active_counters[i].query;
|
||||
if (query && !pipe->begin_query(pipe, query))
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (stm->batch_query && !pipe->begin_query(pipe, stm->batch_query))
|
||||
if (m->batch_query && !pipe->begin_query(pipe, m->batch_query))
|
||||
goto fail;
|
||||
|
||||
return true;
|
||||
|
||||
fail:
|
||||
/* Failed to start the monitoring session. */
|
||||
reset_perf_monitor(stm, pipe);
|
||||
reset_perf_monitor(m, pipe);
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
st_EndPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
unsigned i;
|
||||
|
||||
/* Stop the query for each active counter. */
|
||||
for (i = 0; i < stm->num_active_counters; ++i) {
|
||||
struct pipe_query *query = stm->active_counters[i].query;
|
||||
for (i = 0; i < m->num_active_counters; ++i) {
|
||||
struct pipe_query *query = m->active_counters[i].query;
|
||||
if (query)
|
||||
pipe->end_query(pipe, query);
|
||||
}
|
||||
|
||||
if (stm->batch_query)
|
||||
pipe->end_query(pipe, stm->batch_query);
|
||||
if (m->batch_query)
|
||||
pipe->end_query(pipe, m->batch_query);
|
||||
}
|
||||
|
||||
void
|
||||
st_ResetPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
|
||||
if (!m->Ended)
|
||||
st_EndPerfMonitor(ctx, m);
|
||||
|
||||
reset_perf_monitor(stm, pipe);
|
||||
reset_perf_monitor(m, pipe);
|
||||
|
||||
if (m->Active)
|
||||
st_BeginPerfMonitor(ctx, m);
|
||||
|
|
@ -236,17 +222,16 @@ GLboolean
|
|||
st_IsPerfMonitorResultAvailable(struct gl_context *ctx,
|
||||
struct gl_perf_monitor_object *m)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
unsigned i;
|
||||
|
||||
if (!stm->num_active_counters)
|
||||
if (!m->num_active_counters)
|
||||
return false;
|
||||
|
||||
/* The result of a monitoring session is only available if the query of
|
||||
* each active counter is idle. */
|
||||
for (i = 0; i < stm->num_active_counters; ++i) {
|
||||
struct pipe_query *query = stm->active_counters[i].query;
|
||||
for (i = 0; i < m->num_active_counters; ++i) {
|
||||
struct pipe_query *query = m->active_counters[i].query;
|
||||
union pipe_query_result result;
|
||||
if (query && !pipe->get_query_result(pipe, query, FALSE, &result)) {
|
||||
/* The query is busy. */
|
||||
|
|
@ -254,8 +239,8 @@ st_IsPerfMonitorResultAvailable(struct gl_context *ctx,
|
|||
}
|
||||
}
|
||||
|
||||
if (stm->batch_query &&
|
||||
!pipe->get_query_result(pipe, stm->batch_query, FALSE, stm->batch_result))
|
||||
if (m->batch_query &&
|
||||
!pipe->get_query_result(pipe, m->batch_query, FALSE, m->batch_result))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -268,7 +253,6 @@ st_GetPerfMonitorResult(struct gl_context *ctx,
|
|||
GLuint *data,
|
||||
GLint *bytesWritten)
|
||||
{
|
||||
struct st_perf_monitor_object *stm = st_perf_monitor_object(m);
|
||||
struct pipe_context *pipe = st_context(ctx)->pipe;
|
||||
unsigned i;
|
||||
|
||||
|
|
@ -280,13 +264,13 @@ st_GetPerfMonitorResult(struct gl_context *ctx,
|
|||
GLsizei offset = 0;
|
||||
bool have_batch_query = false;
|
||||
|
||||
if (stm->batch_query)
|
||||
have_batch_query = pipe->get_query_result(pipe, stm->batch_query, TRUE,
|
||||
stm->batch_result);
|
||||
if (m->batch_query)
|
||||
have_batch_query = pipe->get_query_result(pipe, m->batch_query, TRUE,
|
||||
m->batch_result);
|
||||
|
||||
/* Read query results for each active counter. */
|
||||
for (i = 0; i < stm->num_active_counters; ++i) {
|
||||
struct st_perf_counter_object *cntr = &stm->active_counters[i];
|
||||
for (i = 0; i < m->num_active_counters; ++i) {
|
||||
struct st_perf_counter_object *cntr = &m->active_counters[i];
|
||||
union pipe_query_result result = { 0 };
|
||||
int gid, cid;
|
||||
GLenum type;
|
||||
|
|
@ -301,7 +285,7 @@ st_GetPerfMonitorResult(struct gl_context *ctx,
|
|||
} else {
|
||||
if (!have_batch_query)
|
||||
continue;
|
||||
result.batch[0] = stm->batch_result->batch[cntr->batch_index];
|
||||
result.batch[0] = m->batch_result->batch[cntr->batch_index];
|
||||
}
|
||||
|
||||
data[offset++] = gid;
|
||||
|
|
|
|||
|
|
@ -26,27 +26,6 @@
|
|||
|
||||
#include "util/list.h"
|
||||
|
||||
struct st_perf_counter_object
|
||||
{
|
||||
struct pipe_query *query;
|
||||
int id;
|
||||
int group_id;
|
||||
unsigned batch_index;
|
||||
};
|
||||
|
||||
/**
|
||||
* Subclass of gl_perf_monitor_object
|
||||
*/
|
||||
struct st_perf_monitor_object
|
||||
{
|
||||
struct gl_perf_monitor_object base;
|
||||
unsigned num_active_counters;
|
||||
struct st_perf_counter_object *active_counters;
|
||||
|
||||
struct pipe_query *batch_query;
|
||||
union pipe_query_result *batch_result;
|
||||
};
|
||||
|
||||
/**
|
||||
* Extra data per counter, supplementing gl_perf_monitor_counter with
|
||||
* driver-specific information.
|
||||
|
|
@ -63,22 +42,12 @@ struct st_perf_monitor_group
|
|||
bool has_batch;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cast wrapper
|
||||
*/
|
||||
static inline struct st_perf_monitor_object *
|
||||
st_perf_monitor_object(struct gl_perf_monitor_object *q)
|
||||
{
|
||||
return (struct st_perf_monitor_object *)q;
|
||||
}
|
||||
|
||||
bool
|
||||
st_have_perfmon(struct st_context *st);
|
||||
|
||||
void
|
||||
st_destroy_perfmon(struct st_context *st);
|
||||
|
||||
struct gl_perf_monitor_object *st_NewPerfMonitor(struct gl_context *ctx);
|
||||
void st_DeletePerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m);
|
||||
GLboolean st_BeginPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m);
|
||||
void st_EndPerfMonitor(struct gl_context *ctx, struct gl_perf_monitor_object *m);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue