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