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_buffer(struct u_trace_context * utctx,uint64_t size_B)37 u_trace_pipe_create_buffer(struct u_trace_context *utctx, uint64_t size_B)
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_B,
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_buffer(struct u_trace_context * utctx,void * timestamps)55 u_trace_pipe_delete_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,uint32_t timestamp_size_B,uint32_t max_indirect_size_B,u_trace_record_ts record_timestamp,u_trace_read_ts read_timestamp,u_trace_capture_data capture_data,u_trace_get_data get_data,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 uint32_t timestamp_size_B,
65 uint32_t max_indirect_size_B,
66 u_trace_record_ts record_timestamp,
67 u_trace_read_ts read_timestamp,
68 u_trace_capture_data capture_data,
69 u_trace_get_data get_data,
70 u_trace_delete_flush_data delete_flush_data)
71 {
72 u_trace_context_init(utctx, pctx,
73 timestamp_size_B,
74 max_indirect_size_B,
75 u_trace_pipe_create_buffer,
76 u_trace_pipe_delete_buffer,
77 record_timestamp,
78 read_timestamp,
79 capture_data,
80 get_data,
81 delete_flush_data);
82 }
83
84 inline void
trace_framebuffer_state(struct u_trace * ut,void * cs,const struct pipe_framebuffer_state * pfb)85 trace_framebuffer_state(struct u_trace *ut, void *cs, const struct pipe_framebuffer_state *pfb)
86 {
87 if (likely(!u_trace_enabled(ut->utctx)))
88 return;
89
90 trace_framebuffer(ut, cs, pfb);
91
92 for (unsigned i = 0; i < pfb->nr_cbufs; i++) {
93 if (pfb->cbufs[i]) {
94 trace_surface(ut, cs, pfb->cbufs[i]);
95 }
96 }
97 if (pfb->zsbuf) {
98 trace_surface(ut, cs, pfb->zsbuf);
99 }
100 }
101
102 #ifdef __cplusplus
103 }
104 #endif
105