1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Copyright © 2020 Google, Inc.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
5bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
6bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
7bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
9bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
10bf215546Sopenharmony_ci *
11bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next
12bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
13bf215546Sopenharmony_ci * Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19bf215546Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20bf215546Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21bf215546Sopenharmony_ci * SOFTWARE.
22bf215546Sopenharmony_ci */
23bf215546Sopenharmony_ci
24bf215546Sopenharmony_ci#include "u_trace_gallium.h"
25bf215546Sopenharmony_ci#include "u_inlines.h"
26bf215546Sopenharmony_ci#include "pipe/p_state.h"
27bf215546Sopenharmony_ci#include "pipe/p_context.h"
28bf215546Sopenharmony_ci#include "pipe/p_screen.h"
29bf215546Sopenharmony_ci
30bf215546Sopenharmony_ci#include "u_tracepoints.h"
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci#ifdef __cplusplus
33bf215546Sopenharmony_ciextern "C" {
34bf215546Sopenharmony_ci#endif
35bf215546Sopenharmony_ci
36bf215546Sopenharmony_cistatic void *
37bf215546Sopenharmony_ciu_trace_pipe_create_ts_buffer(struct u_trace_context *utctx, uint32_t size)
38bf215546Sopenharmony_ci{
39bf215546Sopenharmony_ci   struct pipe_context *ctx = utctx->pctx;
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci   struct pipe_resource tmpl = {
42bf215546Sopenharmony_ci      .target     = PIPE_BUFFER,
43bf215546Sopenharmony_ci      .format     = PIPE_FORMAT_R8_UNORM,
44bf215546Sopenharmony_ci      .bind       = PIPE_BIND_QUERY_BUFFER | PIPE_BIND_LINEAR,
45bf215546Sopenharmony_ci      .width0     = size,
46bf215546Sopenharmony_ci      .height0    = 1,
47bf215546Sopenharmony_ci      .depth0     = 1,
48bf215546Sopenharmony_ci      .array_size = 1,
49bf215546Sopenharmony_ci   };
50bf215546Sopenharmony_ci
51bf215546Sopenharmony_ci   return ctx->screen->resource_create(ctx->screen, &tmpl);
52bf215546Sopenharmony_ci}
53bf215546Sopenharmony_ci
54bf215546Sopenharmony_cistatic void
55bf215546Sopenharmony_ciu_trace_pipe_delete_ts_buffer(struct u_trace_context *utctx, void *timestamps)
56bf215546Sopenharmony_ci{
57bf215546Sopenharmony_ci   struct pipe_resource *buffer = timestamps;
58bf215546Sopenharmony_ci   pipe_resource_reference(&buffer, NULL);
59bf215546Sopenharmony_ci}
60bf215546Sopenharmony_ci
61bf215546Sopenharmony_civoid
62bf215546Sopenharmony_ciu_trace_pipe_context_init(struct u_trace_context *utctx,
63bf215546Sopenharmony_ci                          struct pipe_context *pctx,
64bf215546Sopenharmony_ci                          u_trace_record_ts record_timestamp,
65bf215546Sopenharmony_ci                          u_trace_read_ts read_timestamp,
66bf215546Sopenharmony_ci                          u_trace_delete_flush_data delete_flush_data)
67bf215546Sopenharmony_ci{
68bf215546Sopenharmony_ci   u_trace_context_init(utctx, pctx,
69bf215546Sopenharmony_ci                        u_trace_pipe_create_ts_buffer,
70bf215546Sopenharmony_ci                        u_trace_pipe_delete_ts_buffer,
71bf215546Sopenharmony_ci                        record_timestamp,
72bf215546Sopenharmony_ci                        read_timestamp,
73bf215546Sopenharmony_ci                        delete_flush_data);
74bf215546Sopenharmony_ci}
75bf215546Sopenharmony_ci
76bf215546Sopenharmony_ciinline void
77bf215546Sopenharmony_citrace_framebuffer_state(struct u_trace *ut, void *cs, const struct pipe_framebuffer_state *pfb)
78bf215546Sopenharmony_ci{
79bf215546Sopenharmony_ci   if (likely(!ut->enabled))
80bf215546Sopenharmony_ci      return;
81bf215546Sopenharmony_ci
82bf215546Sopenharmony_ci   trace_framebuffer(ut, cs, pfb);
83bf215546Sopenharmony_ci
84bf215546Sopenharmony_ci   for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
85bf215546Sopenharmony_ci      if (pfb->cbufs[i]) {
86bf215546Sopenharmony_ci         trace_surface(ut, cs, pfb->cbufs[i]);
87bf215546Sopenharmony_ci      }
88bf215546Sopenharmony_ci   }
89bf215546Sopenharmony_ci   if (pfb->zsbuf) {
90bf215546Sopenharmony_ci      trace_surface(ut, cs, pfb->zsbuf);
91bf215546Sopenharmony_ci   }
92bf215546Sopenharmony_ci}
93bf215546Sopenharmony_ci
94bf215546Sopenharmony_ci#ifdef __cplusplus
95bf215546Sopenharmony_ci}
96bf215546Sopenharmony_ci#endif
97