1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "util/u_string.h"
30 #include "util/u_memory.h"
31 #include "util/u_simple_list.h"
32 #include "util/u_network.h"
34 #include "tgsi/tgsi_parse.h"
38 #include "tr_buffer.h"
39 #include "tr_texture.h"
41 #include "rbug/rbug.h"
45 #if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
47 #elif defined(PIPE_OS_LINUX) || defined(PIPE_OS_BSD)
51 # warning "No socket implementation"
54 #define U642VOID(x) ((void *)(unsigned long)(x))
55 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
59 struct trace_screen
*tr_scr
;
60 struct rbug_connection
*con
;
65 PIPE_THREAD_ROUTINE(trace_rbug_thread
, void_tr_rbug
);
68 /**********************************************************
73 static struct trace_context
*
74 trace_rbug_get_context_locked(struct trace_screen
*tr_scr
, rbug_context_t ctx
)
76 struct trace_context
*tr_ctx
= NULL
;
79 foreach(ptr
, &tr_scr
->contexts
) {
80 tr_ctx
= (struct trace_context
*)((char*)ptr
- offsetof(struct trace_context
, list
));
81 if (ctx
== VOID2U64(tr_ctx
))
89 static struct trace_shader
*
90 trace_rbug_get_shader_locked(struct trace_context
*tr_ctx
, rbug_shader_t shdr
)
92 struct trace_shader
*tr_shdr
= NULL
;
95 foreach(ptr
, &tr_ctx
->shaders
) {
96 tr_shdr
= (struct trace_shader
*)((char*)ptr
- offsetof(struct trace_shader
, list
));
97 if (shdr
== VOID2U64(tr_shdr
))
106 trace_shader_create_locked(struct pipe_context
*pipe
,
107 struct trace_shader
*tr_shdr
,
108 struct tgsi_token
*tokens
)
111 struct pipe_shader_state pss
= { 0 };
114 if (tr_shdr
->type
== TRACE_SHADER_FRAGMENT
) {
115 state
= pipe
->create_fs_state(pipe
, &pss
);
116 } else if (tr_shdr
->type
== TRACE_SHADER_VERTEX
) {
117 state
= pipe
->create_vs_state(pipe
, &pss
);
125 trace_shader_bind_locked(struct pipe_context
*pipe
,
126 struct trace_shader
*tr_shdr
,
129 if (tr_shdr
->type
== TRACE_SHADER_FRAGMENT
) {
130 pipe
->bind_fs_state(pipe
, state
);
131 } else if (tr_shdr
->type
== TRACE_SHADER_VERTEX
) {
132 pipe
->bind_vs_state(pipe
, state
);
138 trace_shader_delete_locked(struct pipe_context
*pipe
,
139 struct trace_shader
*tr_shdr
,
142 if (tr_shdr
->type
== TRACE_SHADER_FRAGMENT
) {
143 pipe
->delete_fs_state(pipe
, state
);
144 } else if (tr_shdr
->type
== TRACE_SHADER_VERTEX
) {
145 pipe
->delete_vs_state(pipe
, state
);
150 /************************************************
151 * Request handler functions
156 trace_rbug_texture_list(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
158 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
159 struct trace_texture
*tr_tex
= NULL
;
161 rbug_texture_t
*texs
;
164 pipe_mutex_lock(tr_scr
->list_mutex
);
165 texs
= MALLOC(tr_scr
->num_textures
* sizeof(rbug_texture_t
));
166 foreach(ptr
, &tr_scr
->textures
) {
167 tr_tex
= (struct trace_texture
*)((char*)ptr
- offsetof(struct trace_texture
, list
));
168 texs
[i
++] = VOID2U64(tr_tex
);
170 pipe_mutex_unlock(tr_scr
->list_mutex
);
172 rbug_send_texture_list_reply(tr_rbug
->con
, serial
, texs
, i
, NULL
);
179 trace_rbug_texture_info(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
181 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
182 struct trace_texture
*tr_tex
;
183 struct rbug_proto_texture_info
*gpti
= (struct rbug_proto_texture_info
*)header
;
185 struct pipe_texture
*t
;
187 pipe_mutex_lock(tr_scr
->list_mutex
);
188 foreach(ptr
, &tr_scr
->textures
) {
189 tr_tex
= (struct trace_texture
*)((char*)ptr
- offsetof(struct trace_texture
, list
));
190 if (gpti
->texture
== VOID2U64(tr_tex
))
196 pipe_mutex_unlock(tr_scr
->list_mutex
);
201 rbug_send_texture_info_reply(tr_rbug
->con
, serial
,
202 t
->target
, t
->format
,
206 pf_get_blockwidth(t
->format
),
207 pf_get_blockheight(t
->format
),
208 pf_get_blocksize(t
->format
),
214 pipe_mutex_unlock(tr_scr
->list_mutex
);
220 trace_rbug_texture_read(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
222 struct rbug_proto_texture_read
*gptr
= (struct rbug_proto_texture_read
*)header
;
224 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
225 struct trace_texture
*tr_tex
;
228 struct pipe_screen
*screen
= tr_scr
->screen
;
229 struct pipe_texture
*tex
;
230 struct pipe_transfer
*t
;
234 pipe_mutex_lock(tr_scr
->list_mutex
);
235 foreach(ptr
, &tr_scr
->textures
) {
236 tr_tex
= (struct trace_texture
*)((char*)ptr
- offsetof(struct trace_texture
, list
));
237 if (gptr
->texture
== VOID2U64(tr_tex
))
243 pipe_mutex_unlock(tr_scr
->list_mutex
);
247 tex
= tr_tex
->texture
;
248 t
= screen
->get_tex_transfer(tr_scr
->screen
, tex
,
249 gptr
->face
, gptr
->level
, gptr
->zslice
,
251 gptr
->x
, gptr
->y
, gptr
->w
, gptr
->h
);
253 map
= screen
->transfer_map(screen
, t
);
255 rbug_send_texture_read_reply(tr_rbug
->con
, serial
,
257 pf_get_blockwidth(t
->texture
->format
),
258 pf_get_blockheight(t
->texture
->format
),
259 pf_get_blocksize(t
->texture
->format
),
261 t
->stride
* pf_get_nblocksy(t
->texture
->format
, t
->height
),
265 screen
->transfer_unmap(screen
, t
);
266 screen
->tex_transfer_destroy(t
);
268 pipe_mutex_unlock(tr_scr
->list_mutex
);
274 trace_rbug_context_list(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
276 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
278 struct trace_context
*tr_ctx
= NULL
;
279 rbug_context_t
*ctxs
;
282 pipe_mutex_lock(tr_scr
->list_mutex
);
283 ctxs
= MALLOC(tr_scr
->num_contexts
* sizeof(rbug_context_t
));
284 foreach(ptr
, &tr_scr
->contexts
) {
285 tr_ctx
= (struct trace_context
*)((char*)ptr
- offsetof(struct trace_context
, list
));
286 ctxs
[i
++] = VOID2U64(tr_ctx
);
288 pipe_mutex_unlock(tr_scr
->list_mutex
);
290 rbug_send_context_list_reply(tr_rbug
->con
, serial
, ctxs
, i
, NULL
);
297 trace_rbug_context_info(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
299 struct rbug_proto_context_info
*info
= (struct rbug_proto_context_info
*)header
;
301 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
302 struct trace_context
*tr_ctx
= NULL
;
303 rbug_texture_t cbufs
[PIPE_MAX_COLOR_BUFS
];
304 rbug_texture_t texs
[PIPE_MAX_SAMPLERS
];
307 pipe_mutex_lock(tr_scr
->list_mutex
);
308 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, info
->context
);
311 pipe_mutex_unlock(tr_scr
->list_mutex
);
315 /* protect the pipe context */
316 pipe_mutex_lock(tr_ctx
->draw_mutex
);
317 trace_dump_call_lock();
319 for (i
= 0; i
< tr_ctx
->curr
.nr_cbufs
; i
++)
320 cbufs
[i
] = VOID2U64(tr_ctx
->curr
.cbufs
[i
]);
322 for (i
= 0; i
< tr_ctx
->curr
.num_texs
; i
++)
323 texs
[i
] = VOID2U64(tr_ctx
->curr
.tex
[i
]);
325 rbug_send_context_info_reply(tr_rbug
->con
, serial
,
326 VOID2U64(tr_ctx
->curr
.vs
), VOID2U64(tr_ctx
->curr
.fs
),
327 texs
, tr_ctx
->curr
.num_texs
,
328 cbufs
, tr_ctx
->curr
.nr_cbufs
,
329 VOID2U64(tr_ctx
->curr
.zsbuf
),
330 tr_ctx
->draw_blocker
, tr_ctx
->draw_blocked
, NULL
);
332 trace_dump_call_unlock();
333 pipe_mutex_unlock(tr_ctx
->draw_mutex
);
335 pipe_mutex_unlock(tr_scr
->list_mutex
);
341 trace_rbug_context_draw_block(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
343 struct rbug_proto_context_draw_block
*block
= (struct rbug_proto_context_draw_block
*)header
;
345 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
346 struct trace_context
*tr_ctx
= NULL
;
348 pipe_mutex_lock(tr_scr
->list_mutex
);
349 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, block
->context
);
352 pipe_mutex_unlock(tr_scr
->list_mutex
);
356 pipe_mutex_lock(tr_ctx
->draw_mutex
);
357 tr_ctx
->draw_blocker
|= block
->block
;
358 pipe_mutex_unlock(tr_ctx
->draw_mutex
);
360 pipe_mutex_unlock(tr_scr
->list_mutex
);
366 trace_rbug_context_draw_step(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
368 struct rbug_proto_context_draw_step
*step
= (struct rbug_proto_context_draw_step
*)header
;
370 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
371 struct trace_context
*tr_ctx
= NULL
;
373 pipe_mutex_lock(tr_scr
->list_mutex
);
374 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, step
->context
);
377 pipe_mutex_unlock(tr_scr
->list_mutex
);
381 pipe_mutex_lock(tr_ctx
->draw_mutex
);
382 if (tr_ctx
->draw_blocked
& RBUG_BLOCK_RULE
) {
383 if (step
->step
& RBUG_BLOCK_RULE
)
384 tr_ctx
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
386 tr_ctx
->draw_blocked
&= ~step
->step
;
388 pipe_mutex_unlock(tr_ctx
->draw_mutex
);
390 #ifdef PIPE_THREAD_HAVE_CONDVAR
391 pipe_condvar_broadcast(tr_ctx
->draw_cond
);
394 pipe_mutex_unlock(tr_scr
->list_mutex
);
400 trace_rbug_context_draw_unblock(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
402 struct rbug_proto_context_draw_unblock
*unblock
= (struct rbug_proto_context_draw_unblock
*)header
;
404 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
405 struct trace_context
*tr_ctx
= NULL
;
407 pipe_mutex_lock(tr_scr
->list_mutex
);
408 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, unblock
->context
);
411 pipe_mutex_unlock(tr_scr
->list_mutex
);
415 pipe_mutex_lock(tr_ctx
->draw_mutex
);
416 if (tr_ctx
->draw_blocked
& RBUG_BLOCK_RULE
) {
417 if (unblock
->unblock
& RBUG_BLOCK_RULE
)
418 tr_ctx
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
420 tr_ctx
->draw_blocked
&= ~unblock
->unblock
;
422 tr_ctx
->draw_blocker
&= ~unblock
->unblock
;
423 pipe_mutex_unlock(tr_ctx
->draw_mutex
);
425 #ifdef PIPE_THREAD_HAVE_CONDVAR
426 pipe_condvar_broadcast(tr_ctx
->draw_cond
);
429 pipe_mutex_unlock(tr_scr
->list_mutex
);
435 trace_rbug_context_draw_rule(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
437 struct rbug_proto_context_draw_rule
*rule
= (struct rbug_proto_context_draw_rule
*)header
;
439 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
440 struct trace_context
*tr_ctx
= NULL
;
442 pipe_mutex_lock(tr_scr
->list_mutex
);
443 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, rule
->context
);
446 pipe_mutex_unlock(tr_scr
->list_mutex
);
450 pipe_mutex_lock(tr_ctx
->draw_mutex
);
451 tr_ctx
->draw_rule
.vs
= U642VOID(rule
->vertex
);
452 tr_ctx
->draw_rule
.fs
= U642VOID(rule
->fragment
);
453 tr_ctx
->draw_rule
.tex
= U642VOID(rule
->texture
);
454 tr_ctx
->draw_rule
.surf
= U642VOID(rule
->surface
);
455 tr_ctx
->draw_rule
.blocker
= rule
->block
;
456 tr_ctx
->draw_blocker
|= RBUG_BLOCK_RULE
;
457 pipe_mutex_unlock(tr_ctx
->draw_mutex
);
459 #ifdef PIPE_THREAD_HAVE_CONDVAR
460 pipe_condvar_broadcast(tr_ctx
->draw_cond
);
463 pipe_mutex_unlock(tr_scr
->list_mutex
);
469 trace_rbug_context_flush(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
471 struct rbug_proto_context_flush
*flush
= (struct rbug_proto_context_flush
*)header
;
473 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
474 struct trace_context
*tr_ctx
= NULL
;
476 pipe_mutex_lock(tr_scr
->list_mutex
);
477 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, flush
->context
);
480 pipe_mutex_unlock(tr_scr
->list_mutex
);
484 /* protect the pipe context */
485 trace_dump_call_lock();
487 tr_ctx
->pipe
->flush(tr_ctx
->pipe
, flush
->flags
, NULL
);
489 trace_dump_call_unlock();
490 pipe_mutex_unlock(tr_scr
->list_mutex
);
496 trace_rbug_shader_list(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
498 struct rbug_proto_shader_list
*list
= (struct rbug_proto_shader_list
*)header
;
500 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
501 struct trace_context
*tr_ctx
= NULL
;
502 struct trace_shader
*tr_shdr
= NULL
;
504 rbug_shader_t
*shdrs
;
507 pipe_mutex_lock(tr_scr
->list_mutex
);
508 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, list
->context
);
511 pipe_mutex_unlock(tr_scr
->list_mutex
);
515 pipe_mutex_lock(tr_ctx
->list_mutex
);
516 shdrs
= MALLOC(tr_ctx
->num_shaders
* sizeof(rbug_shader_t
));
517 foreach(ptr
, &tr_ctx
->shaders
) {
518 tr_shdr
= (struct trace_shader
*)((char*)ptr
- offsetof(struct trace_shader
, list
));
519 shdrs
[i
++] = VOID2U64(tr_shdr
);
522 pipe_mutex_unlock(tr_ctx
->list_mutex
);
523 pipe_mutex_unlock(tr_scr
->list_mutex
);
525 rbug_send_shader_list_reply(tr_rbug
->con
, serial
, shdrs
, i
, NULL
);
532 trace_rbug_shader_info(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
534 struct rbug_proto_shader_info
*info
= (struct rbug_proto_shader_info
*)header
;
536 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
537 struct trace_context
*tr_ctx
= NULL
;
538 struct trace_shader
*tr_shdr
= NULL
;
539 unsigned original_len
;
540 unsigned replaced_len
;
542 pipe_mutex_lock(tr_scr
->list_mutex
);
543 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, info
->context
);
546 pipe_mutex_unlock(tr_scr
->list_mutex
);
550 pipe_mutex_lock(tr_ctx
->list_mutex
);
552 tr_shdr
= trace_rbug_get_shader_locked(tr_ctx
, info
->shader
);
555 pipe_mutex_unlock(tr_ctx
->list_mutex
);
556 pipe_mutex_unlock(tr_scr
->list_mutex
);
561 assert(sizeof(struct tgsi_token
) == 4);
563 original_len
= tgsi_num_tokens(tr_shdr
->tokens
);
564 if (tr_shdr
->replaced_tokens
)
565 replaced_len
= tgsi_num_tokens(tr_shdr
->replaced_tokens
);
569 rbug_send_shader_info_reply(tr_rbug
->con
, serial
,
570 (uint32_t*)tr_shdr
->tokens
, original_len
,
571 (uint32_t*)tr_shdr
->replaced_tokens
, replaced_len
,
575 pipe_mutex_unlock(tr_ctx
->list_mutex
);
576 pipe_mutex_unlock(tr_scr
->list_mutex
);
582 trace_rbug_shader_disable(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
)
584 struct rbug_proto_shader_disable
*dis
= (struct rbug_proto_shader_disable
*)header
;
586 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
587 struct trace_context
*tr_ctx
= NULL
;
588 struct trace_shader
*tr_shdr
= NULL
;
590 pipe_mutex_lock(tr_scr
->list_mutex
);
591 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, dis
->context
);
594 pipe_mutex_unlock(tr_scr
->list_mutex
);
598 pipe_mutex_lock(tr_ctx
->list_mutex
);
600 tr_shdr
= trace_rbug_get_shader_locked(tr_ctx
, dis
->shader
);
603 pipe_mutex_unlock(tr_ctx
->list_mutex
);
604 pipe_mutex_unlock(tr_scr
->list_mutex
);
608 tr_shdr
->disabled
= dis
->disable
;
610 pipe_mutex_unlock(tr_ctx
->list_mutex
);
611 pipe_mutex_unlock(tr_scr
->list_mutex
);
617 trace_rbug_shader_replace(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
)
619 struct rbug_proto_shader_replace
*rep
= (struct rbug_proto_shader_replace
*)header
;
621 struct trace_screen
*tr_scr
= tr_rbug
->tr_scr
;
622 struct trace_context
*tr_ctx
= NULL
;
623 struct trace_shader
*tr_shdr
= NULL
;
624 struct pipe_context
*pipe
= NULL
;
627 pipe_mutex_lock(tr_scr
->list_mutex
);
628 tr_ctx
= trace_rbug_get_context_locked(tr_scr
, rep
->context
);
631 pipe_mutex_unlock(tr_scr
->list_mutex
);
635 pipe_mutex_lock(tr_ctx
->list_mutex
);
637 tr_shdr
= trace_rbug_get_shader_locked(tr_ctx
, rep
->shader
);
640 pipe_mutex_unlock(tr_ctx
->list_mutex
);
641 pipe_mutex_unlock(tr_scr
->list_mutex
);
645 /* protect the pipe context */
646 trace_dump_call_lock();
650 /* remove old replaced shader */
651 if (tr_shdr
->replaced
) {
652 if (tr_ctx
->curr
.fs
== tr_shdr
|| tr_ctx
->curr
.vs
== tr_shdr
)
653 trace_shader_bind_locked(pipe
, tr_shdr
, tr_shdr
->state
);
655 FREE(tr_shdr
->replaced_tokens
);
656 trace_shader_delete_locked(pipe
, tr_shdr
, tr_shdr
->replaced
);
657 tr_shdr
->replaced
= NULL
;
658 tr_shdr
->replaced_tokens
= NULL
;
661 /* empty inputs means restore old which we did above */
662 if (rep
->tokens_len
== 0)
665 tr_shdr
->replaced_tokens
= tgsi_dup_tokens((struct tgsi_token
*)rep
->tokens
);
666 if (!tr_shdr
->replaced_tokens
)
669 state
= trace_shader_create_locked(pipe
, tr_shdr
, tr_shdr
->replaced_tokens
);
673 /* bind new shader if the shader is currently a bound */
674 if (tr_ctx
->curr
.fs
== tr_shdr
|| tr_ctx
->curr
.vs
== tr_shdr
)
675 trace_shader_bind_locked(pipe
, tr_shdr
, state
);
678 tr_shdr
->replaced
= state
;
681 trace_dump_call_unlock();
682 pipe_mutex_unlock(tr_ctx
->list_mutex
);
683 pipe_mutex_unlock(tr_scr
->list_mutex
);
688 FREE(tr_shdr
->replaced_tokens
);
689 tr_shdr
->replaced
= NULL
;
690 tr_shdr
->replaced_tokens
= NULL
;
692 trace_dump_call_unlock();
693 pipe_mutex_unlock(tr_ctx
->list_mutex
);
694 pipe_mutex_unlock(tr_scr
->list_mutex
);
699 trace_rbug_header(struct trace_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
703 switch(header
->opcode
) {
705 rbug_send_ping_reply(tr_rbug
->con
, serial
, NULL
);
707 case RBUG_OP_TEXTURE_LIST
:
708 ret
= trace_rbug_texture_list(tr_rbug
, header
, serial
);
710 case RBUG_OP_TEXTURE_INFO
:
711 ret
= trace_rbug_texture_info(tr_rbug
, header
, serial
);
713 case RBUG_OP_TEXTURE_READ
:
714 ret
= trace_rbug_texture_read(tr_rbug
, header
, serial
);
716 case RBUG_OP_CONTEXT_LIST
:
717 ret
= trace_rbug_context_list(tr_rbug
, header
, serial
);
719 case RBUG_OP_CONTEXT_INFO
:
720 ret
= trace_rbug_context_info(tr_rbug
, header
, serial
);
722 case RBUG_OP_CONTEXT_DRAW_BLOCK
:
723 ret
= trace_rbug_context_draw_block(tr_rbug
, header
, serial
);
725 case RBUG_OP_CONTEXT_DRAW_STEP
:
726 ret
= trace_rbug_context_draw_step(tr_rbug
, header
, serial
);
728 case RBUG_OP_CONTEXT_DRAW_UNBLOCK
:
729 ret
= trace_rbug_context_draw_unblock(tr_rbug
, header
, serial
);
731 case RBUG_OP_CONTEXT_DRAW_RULE
:
732 ret
= trace_rbug_context_draw_rule(tr_rbug
, header
, serial
);
734 case RBUG_OP_CONTEXT_FLUSH
:
735 ret
= trace_rbug_context_flush(tr_rbug
, header
, serial
);
737 case RBUG_OP_SHADER_LIST
:
738 ret
= trace_rbug_shader_list(tr_rbug
, header
, serial
);
740 case RBUG_OP_SHADER_INFO
:
741 ret
= trace_rbug_shader_info(tr_rbug
, header
, serial
);
743 case RBUG_OP_SHADER_DISABLE
:
744 ret
= trace_rbug_shader_disable(tr_rbug
, header
);
746 case RBUG_OP_SHADER_REPLACE
:
747 ret
= trace_rbug_shader_replace(tr_rbug
, header
);
750 debug_printf("%s - unsupported opcode %u\n", __FUNCTION__
, header
->opcode
);
754 rbug_free_header(header
);
757 rbug_send_error_reply(tr_rbug
->con
, serial
, ret
, NULL
);
763 trace_rbug_con(struct trace_rbug
*tr_rbug
)
765 struct rbug_header
*header
;
768 debug_printf("%s - connection received\n", __FUNCTION__
);
770 while(tr_rbug
->running
) {
771 header
= rbug_get_message(tr_rbug
->con
, &serial
);
775 if (!trace_rbug_header(tr_rbug
, header
, serial
))
779 debug_printf("%s - connection closed\n", __FUNCTION__
);
781 rbug_disconnect(tr_rbug
->con
);
785 PIPE_THREAD_ROUTINE(trace_rbug_thread
, void_tr_rbug
)
787 struct trace_rbug
*tr_rbug
= void_tr_rbug
;
788 uint16_t port
= 13370;
794 for (;port
<= 13379 && s
< 0; port
++)
795 s
= u_socket_listen_on_port(port
);
798 debug_printf("trace_rbug - failed to listen\n");
802 u_socket_block(s
, false);
804 debug_printf("trace_rbug - remote debugging listening on port %u\n", --port
);
806 while(tr_rbug
->running
) {
809 c
= u_socket_accept(s
);
813 u_socket_block(c
, true);
814 tr_rbug
->con
= rbug_from_socket(c
);
816 trace_rbug_con(tr_rbug
);
828 /**********************************************************
833 trace_rbug_start(struct trace_screen
*tr_scr
)
835 struct trace_rbug
*tr_rbug
= CALLOC_STRUCT(trace_rbug
);
839 tr_rbug
->tr_scr
= tr_scr
;
840 tr_rbug
->running
= TRUE
;
841 tr_rbug
->thread
= pipe_thread_create(trace_rbug_thread
, tr_rbug
);
847 trace_rbug_stop(struct trace_rbug
*tr_rbug
)
852 tr_rbug
->running
= false;
853 pipe_thread_wait(tr_rbug
->thread
);
861 trace_rbug_notify_draw_blocked(struct trace_context
*tr_ctx
)
863 struct trace_screen
*tr_scr
= trace_screen(tr_ctx
->base
.screen
);
864 struct trace_rbug
*tr_rbug
= tr_scr
->rbug
;
866 if (tr_rbug
&& tr_rbug
->con
)
867 rbug_send_context_draw_blocked(tr_rbug
->con
,
868 VOID2U64(tr_ctx
), tr_ctx
->draw_blocked
, NULL
);