1 /**************************************************************************
3 * Copyright 2010 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 VMWARE 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 "os/os_thread.h"
30 #include "util/u_format.h"
31 #include "util/u_string.h"
32 #include "util/u_inlines.h"
33 #include "util/u_memory.h"
34 #include "util/u_simple_list.h"
35 #include "util/u_network.h"
36 #include "os/os_time.h"
38 #include "tgsi/tgsi_parse.h"
40 #include "rbug_context.h"
41 #include "rbug_objects.h"
43 #include "rbug/rbug.h"
47 #define U642VOID(x) ((void *)(unsigned long)(x))
48 #define VOID2U64(x) ((uint64_t)(unsigned long)(x))
52 struct rbug_screen
*rb_screen
;
53 struct rbug_connection
*con
;
58 PIPE_THREAD_ROUTINE(rbug_thread
, void_rbug
);
61 /**********************************************************
66 static struct rbug_context
*
67 rbug_get_context_locked(struct rbug_screen
*rb_screen
, rbug_context_t ctx
)
69 struct rbug_context
*rb_context
= NULL
;
70 struct rbug_list
*ptr
;
72 foreach(ptr
, &rb_screen
->contexts
) {
73 rb_context
= (struct rbug_context
*)((char*)ptr
- offsetof(struct rbug_context
, list
));
74 if (ctx
== VOID2U64(rb_context
))
82 static struct rbug_shader
*
83 rbug_get_shader_locked(struct rbug_context
*rb_context
, rbug_shader_t shdr
)
85 struct rbug_shader
*tr_shdr
= NULL
;
86 struct rbug_list
*ptr
;
88 foreach(ptr
, &rb_context
->shaders
) {
89 tr_shdr
= (struct rbug_shader
*)((char*)ptr
- offsetof(struct rbug_shader
, list
));
90 if (shdr
== VOID2U64(tr_shdr
))
99 rbug_shader_create_locked(struct pipe_context
*pipe
,
100 struct rbug_shader
*rb_shader
,
101 struct tgsi_token
*tokens
)
104 struct pipe_shader_state pss
= { 0 };
107 switch(rb_shader
->type
) {
108 case RBUG_SHADER_FRAGMENT
:
109 state
= pipe
->create_fs_state(pipe
, &pss
);
111 case RBUG_SHADER_VERTEX
:
112 state
= pipe
->create_vs_state(pipe
, &pss
);
114 case RBUG_SHADER_GEOM
:
115 state
= pipe
->create_gs_state(pipe
, &pss
);
126 rbug_shader_bind_locked(struct pipe_context
*pipe
,
127 struct rbug_shader
*rb_shader
,
130 switch(rb_shader
->type
) {
131 case RBUG_SHADER_FRAGMENT
:
132 pipe
->bind_fs_state(pipe
, state
);
134 case RBUG_SHADER_VERTEX
:
135 pipe
->bind_vs_state(pipe
, state
);
137 case RBUG_SHADER_GEOM
:
138 pipe
->bind_gs_state(pipe
, state
);
147 rbug_shader_delete_locked(struct pipe_context
*pipe
,
148 struct rbug_shader
*rb_shader
,
151 switch(rb_shader
->type
) {
152 case RBUG_SHADER_FRAGMENT
:
153 pipe
->delete_fs_state(pipe
, state
);
155 case RBUG_SHADER_VERTEX
:
156 pipe
->delete_vs_state(pipe
, state
);
158 case RBUG_SHADER_GEOM
:
159 pipe
->delete_gs_state(pipe
, state
);
167 /************************************************
168 * Request handler functions
173 rbug_texture_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
175 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
176 struct rbug_resource
*tr_tex
= NULL
;
177 struct rbug_list
*ptr
;
178 rbug_texture_t
*texs
;
181 pipe_mutex_lock(rb_screen
->list_mutex
);
182 texs
= MALLOC(rb_screen
->num_resources
* sizeof(rbug_texture_t
));
183 foreach(ptr
, &rb_screen
->resources
) {
184 tr_tex
= (struct rbug_resource
*)((char*)ptr
- offsetof(struct rbug_resource
, list
));
185 texs
[i
++] = VOID2U64(tr_tex
);
187 pipe_mutex_unlock(rb_screen
->list_mutex
);
189 rbug_send_texture_list_reply(tr_rbug
->con
, serial
, texs
, i
, NULL
);
196 rbug_texture_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
198 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
199 struct rbug_resource
*tr_tex
= NULL
;
200 struct rbug_proto_texture_info
*gpti
= (struct rbug_proto_texture_info
*)header
;
201 struct rbug_list
*ptr
;
202 struct pipe_resource
*t
;
204 pipe_mutex_lock(rb_screen
->list_mutex
);
205 foreach(ptr
, &rb_screen
->resources
) {
206 tr_tex
= (struct rbug_resource
*)((char*)ptr
- offsetof(struct rbug_resource
, list
));
207 if (gpti
->texture
== VOID2U64(tr_tex
))
213 pipe_mutex_unlock(rb_screen
->list_mutex
);
217 t
= tr_tex
->resource
;
218 rbug_send_texture_info_reply(tr_rbug
->con
, serial
,
219 t
->target
, t
->format
,
223 util_format_get_blockwidth(t
->format
),
224 util_format_get_blockheight(t
->format
),
225 util_format_get_blocksize(t
->format
),
231 pipe_mutex_unlock(rb_screen
->list_mutex
);
237 rbug_texture_read(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
239 struct rbug_proto_texture_read
*gptr
= (struct rbug_proto_texture_read
*)header
;
241 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
242 struct rbug_resource
*tr_tex
= NULL
;
243 struct rbug_list
*ptr
;
245 struct pipe_context
*context
= rb_screen
->private_context
;
246 struct pipe_resource
*tex
;
247 struct pipe_transfer
*t
;
251 pipe_mutex_lock(rb_screen
->list_mutex
);
252 foreach(ptr
, &rb_screen
->resources
) {
253 tr_tex
= (struct rbug_resource
*)((char*)ptr
- offsetof(struct rbug_resource
, list
));
254 if (gptr
->texture
== VOID2U64(tr_tex
))
260 pipe_mutex_unlock(rb_screen
->list_mutex
);
264 tex
= tr_tex
->resource
;
265 t
= pipe_get_transfer(context
, tex
,
266 gptr
->face
, gptr
->level
, gptr
->zslice
,
268 gptr
->x
, gptr
->y
, gptr
->w
, gptr
->h
);
270 map
= context
->transfer_map(context
, t
);
272 rbug_send_texture_read_reply(tr_rbug
->con
, serial
,
274 util_format_get_blockwidth(t
->resource
->format
),
275 util_format_get_blockheight(t
->resource
->format
),
276 util_format_get_blocksize(t
->resource
->format
),
278 t
->stride
* util_format_get_nblocksy(t
->resource
->format
,
283 context
->transfer_unmap(context
, t
);
284 context
->transfer_destroy(context
, t
);
286 pipe_mutex_unlock(rb_screen
->list_mutex
);
292 rbug_context_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
294 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
295 struct rbug_list
*ptr
;
296 struct rbug_context
*rb_context
= NULL
;
297 rbug_context_t
*ctxs
;
300 pipe_mutex_lock(rb_screen
->list_mutex
);
301 ctxs
= MALLOC(rb_screen
->num_contexts
* sizeof(rbug_context_t
));
302 foreach(ptr
, &rb_screen
->contexts
) {
303 rb_context
= (struct rbug_context
*)((char*)ptr
- offsetof(struct rbug_context
, list
));
304 ctxs
[i
++] = VOID2U64(rb_context
);
306 pipe_mutex_unlock(rb_screen
->list_mutex
);
308 rbug_send_context_list_reply(tr_rbug
->con
, serial
, ctxs
, i
, NULL
);
315 rbug_context_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
317 struct rbug_proto_context_info
*info
= (struct rbug_proto_context_info
*)header
;
319 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
320 struct rbug_context
*rb_context
= NULL
;
321 rbug_texture_t cbufs
[PIPE_MAX_COLOR_BUFS
];
322 rbug_texture_t texs
[PIPE_MAX_SAMPLERS
];
325 pipe_mutex_lock(rb_screen
->list_mutex
);
326 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
329 pipe_mutex_unlock(rb_screen
->list_mutex
);
333 /* protect the pipe context */
334 pipe_mutex_lock(rb_context
->draw_mutex
);
335 pipe_mutex_lock(rb_context
->call_mutex
);
337 for (i
= 0; i
< rb_context
->curr
.nr_cbufs
; i
++)
338 cbufs
[i
] = VOID2U64(rb_context
->curr
.cbufs
[i
]);
340 for (i
= 0; i
< rb_context
->curr
.num_fs_views
; i
++)
341 texs
[i
] = VOID2U64(rb_context
->curr
.fs_texs
[i
]);
343 rbug_send_context_info_reply(tr_rbug
->con
, serial
,
344 VOID2U64(rb_context
->curr
.vs
), VOID2U64(rb_context
->curr
.fs
),
345 texs
, rb_context
->curr
.num_fs_views
,
346 cbufs
, rb_context
->curr
.nr_cbufs
,
347 VOID2U64(rb_context
->curr
.zsbuf
),
348 rb_context
->draw_blocker
, rb_context
->draw_blocked
, NULL
);
350 pipe_mutex_unlock(rb_context
->call_mutex
);
351 pipe_mutex_unlock(rb_context
->draw_mutex
);
352 pipe_mutex_unlock(rb_screen
->list_mutex
);
358 rbug_context_draw_block(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
360 struct rbug_proto_context_draw_block
*block
= (struct rbug_proto_context_draw_block
*)header
;
362 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
363 struct rbug_context
*rb_context
= NULL
;
365 pipe_mutex_lock(rb_screen
->list_mutex
);
366 rb_context
= rbug_get_context_locked(rb_screen
, block
->context
);
369 pipe_mutex_unlock(rb_screen
->list_mutex
);
373 pipe_mutex_lock(rb_context
->draw_mutex
);
374 rb_context
->draw_blocker
|= block
->block
;
375 pipe_mutex_unlock(rb_context
->draw_mutex
);
377 pipe_mutex_unlock(rb_screen
->list_mutex
);
383 rbug_context_draw_step(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
385 struct rbug_proto_context_draw_step
*step
= (struct rbug_proto_context_draw_step
*)header
;
387 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
388 struct rbug_context
*rb_context
= NULL
;
390 pipe_mutex_lock(rb_screen
->list_mutex
);
391 rb_context
= rbug_get_context_locked(rb_screen
, step
->context
);
394 pipe_mutex_unlock(rb_screen
->list_mutex
);
398 pipe_mutex_lock(rb_context
->draw_mutex
);
399 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
400 if (step
->step
& RBUG_BLOCK_RULE
)
401 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
403 rb_context
->draw_blocked
&= ~step
->step
;
405 pipe_mutex_unlock(rb_context
->draw_mutex
);
407 #ifdef PIPE_THREAD_HAVE_CONDVAR
408 pipe_condvar_broadcast(rb_context
->draw_cond
);
411 pipe_mutex_unlock(rb_screen
->list_mutex
);
417 rbug_context_draw_unblock(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
419 struct rbug_proto_context_draw_unblock
*unblock
= (struct rbug_proto_context_draw_unblock
*)header
;
421 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
422 struct rbug_context
*rb_context
= NULL
;
424 pipe_mutex_lock(rb_screen
->list_mutex
);
425 rb_context
= rbug_get_context_locked(rb_screen
, unblock
->context
);
428 pipe_mutex_unlock(rb_screen
->list_mutex
);
432 pipe_mutex_lock(rb_context
->draw_mutex
);
433 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
434 if (unblock
->unblock
& RBUG_BLOCK_RULE
)
435 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
437 rb_context
->draw_blocked
&= ~unblock
->unblock
;
439 rb_context
->draw_blocker
&= ~unblock
->unblock
;
440 pipe_mutex_unlock(rb_context
->draw_mutex
);
442 #ifdef PIPE_THREAD_HAVE_CONDVAR
443 pipe_condvar_broadcast(rb_context
->draw_cond
);
446 pipe_mutex_unlock(rb_screen
->list_mutex
);
452 rbug_context_draw_rule(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
454 struct rbug_proto_context_draw_rule
*rule
= (struct rbug_proto_context_draw_rule
*)header
;
456 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
457 struct rbug_context
*rb_context
= NULL
;
459 pipe_mutex_lock(rb_screen
->list_mutex
);
460 rb_context
= rbug_get_context_locked(rb_screen
, rule
->context
);
463 pipe_mutex_unlock(rb_screen
->list_mutex
);
467 pipe_mutex_lock(rb_context
->draw_mutex
);
468 rb_context
->draw_rule
.vs
= U642VOID(rule
->vertex
);
469 rb_context
->draw_rule
.fs
= U642VOID(rule
->fragment
);
470 rb_context
->draw_rule
.texture
= U642VOID(rule
->texture
);
471 rb_context
->draw_rule
.surf
= U642VOID(rule
->surface
);
472 rb_context
->draw_rule
.blocker
= rule
->block
;
473 rb_context
->draw_blocker
|= RBUG_BLOCK_RULE
;
474 pipe_mutex_unlock(rb_context
->draw_mutex
);
476 #ifdef PIPE_THREAD_HAVE_CONDVAR
477 pipe_condvar_broadcast(rb_context
->draw_cond
);
480 pipe_mutex_unlock(rb_screen
->list_mutex
);
486 rbug_context_flush(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
488 struct rbug_proto_context_flush
*flush
= (struct rbug_proto_context_flush
*)header
;
490 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
491 struct rbug_context
*rb_context
= NULL
;
493 pipe_mutex_lock(rb_screen
->list_mutex
);
494 rb_context
= rbug_get_context_locked(rb_screen
, flush
->context
);
497 pipe_mutex_unlock(rb_screen
->list_mutex
);
501 /* protect the pipe context */
502 pipe_mutex_lock(rb_context
->call_mutex
);
504 rb_context
->pipe
->flush(rb_context
->pipe
, flush
->flags
, NULL
);
506 pipe_mutex_unlock(rb_context
->call_mutex
);
507 pipe_mutex_unlock(rb_screen
->list_mutex
);
513 rbug_shader_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
515 struct rbug_proto_shader_list
*list
= (struct rbug_proto_shader_list
*)header
;
517 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
518 struct rbug_context
*rb_context
= NULL
;
519 struct rbug_shader
*tr_shdr
= NULL
;
520 struct rbug_list
*ptr
;
521 rbug_shader_t
*shdrs
;
524 pipe_mutex_lock(rb_screen
->list_mutex
);
525 rb_context
= rbug_get_context_locked(rb_screen
, list
->context
);
528 pipe_mutex_unlock(rb_screen
->list_mutex
);
532 pipe_mutex_lock(rb_context
->list_mutex
);
533 shdrs
= MALLOC(rb_context
->num_shaders
* sizeof(rbug_shader_t
));
534 foreach(ptr
, &rb_context
->shaders
) {
535 tr_shdr
= (struct rbug_shader
*)((char*)ptr
- offsetof(struct rbug_shader
, list
));
536 shdrs
[i
++] = VOID2U64(tr_shdr
);
539 pipe_mutex_unlock(rb_context
->list_mutex
);
540 pipe_mutex_unlock(rb_screen
->list_mutex
);
542 rbug_send_shader_list_reply(tr_rbug
->con
, serial
, shdrs
, i
, NULL
);
549 rbug_shader_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
551 struct rbug_proto_shader_info
*info
= (struct rbug_proto_shader_info
*)header
;
553 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
554 struct rbug_context
*rb_context
= NULL
;
555 struct rbug_shader
*tr_shdr
= NULL
;
556 unsigned original_len
;
557 unsigned replaced_len
;
559 pipe_mutex_lock(rb_screen
->list_mutex
);
560 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
563 pipe_mutex_unlock(rb_screen
->list_mutex
);
567 pipe_mutex_lock(rb_context
->list_mutex
);
569 tr_shdr
= rbug_get_shader_locked(rb_context
, info
->shader
);
572 pipe_mutex_unlock(rb_context
->list_mutex
);
573 pipe_mutex_unlock(rb_screen
->list_mutex
);
578 assert(sizeof(struct tgsi_token
) == 4);
580 original_len
= tgsi_num_tokens(tr_shdr
->tokens
);
581 if (tr_shdr
->replaced_tokens
)
582 replaced_len
= tgsi_num_tokens(tr_shdr
->replaced_tokens
);
586 rbug_send_shader_info_reply(tr_rbug
->con
, serial
,
587 (uint32_t*)tr_shdr
->tokens
, original_len
,
588 (uint32_t*)tr_shdr
->replaced_tokens
, replaced_len
,
592 pipe_mutex_unlock(rb_context
->list_mutex
);
593 pipe_mutex_unlock(rb_screen
->list_mutex
);
599 rbug_shader_disable(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
601 struct rbug_proto_shader_disable
*dis
= (struct rbug_proto_shader_disable
*)header
;
603 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
604 struct rbug_context
*rb_context
= NULL
;
605 struct rbug_shader
*tr_shdr
= NULL
;
607 pipe_mutex_lock(rb_screen
->list_mutex
);
608 rb_context
= rbug_get_context_locked(rb_screen
, dis
->context
);
611 pipe_mutex_unlock(rb_screen
->list_mutex
);
615 pipe_mutex_lock(rb_context
->list_mutex
);
617 tr_shdr
= rbug_get_shader_locked(rb_context
, dis
->shader
);
620 pipe_mutex_unlock(rb_context
->list_mutex
);
621 pipe_mutex_unlock(rb_screen
->list_mutex
);
625 tr_shdr
->disabled
= dis
->disable
;
627 pipe_mutex_unlock(rb_context
->list_mutex
);
628 pipe_mutex_unlock(rb_screen
->list_mutex
);
634 rbug_shader_replace(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
636 struct rbug_proto_shader_replace
*rep
= (struct rbug_proto_shader_replace
*)header
;
638 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
639 struct rbug_context
*rb_context
= NULL
;
640 struct rbug_shader
*tr_shdr
= NULL
;
641 struct pipe_context
*pipe
= NULL
;
644 pipe_mutex_lock(rb_screen
->list_mutex
);
645 rb_context
= rbug_get_context_locked(rb_screen
, rep
->context
);
648 pipe_mutex_unlock(rb_screen
->list_mutex
);
652 pipe_mutex_lock(rb_context
->list_mutex
);
654 tr_shdr
= rbug_get_shader_locked(rb_context
, rep
->shader
);
657 pipe_mutex_unlock(rb_context
->list_mutex
);
658 pipe_mutex_unlock(rb_screen
->list_mutex
);
662 /* protect the pipe context */
663 pipe_mutex_lock(rb_context
->call_mutex
);
665 pipe
= rb_context
->pipe
;
667 /* remove old replaced shader */
668 if (tr_shdr
->replaced_shader
) {
669 /* if this shader is bound rebind the original shader */
670 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
671 rbug_shader_bind_locked(pipe
, tr_shdr
, tr_shdr
->shader
);
673 FREE(tr_shdr
->replaced_tokens
);
674 rbug_shader_delete_locked(pipe
, tr_shdr
, tr_shdr
->replaced_shader
);
675 tr_shdr
->replaced_shader
= NULL
;
676 tr_shdr
->replaced_tokens
= NULL
;
679 /* empty inputs means restore old which we did above */
680 if (rep
->tokens_len
== 0)
683 tr_shdr
->replaced_tokens
= tgsi_dup_tokens((struct tgsi_token
*)rep
->tokens
);
684 if (!tr_shdr
->replaced_tokens
)
687 state
= rbug_shader_create_locked(pipe
, tr_shdr
, tr_shdr
->replaced_tokens
);
691 /* bind new shader if the shader is currently a bound */
692 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
693 rbug_shader_bind_locked(pipe
, tr_shdr
, state
);
696 tr_shdr
->replaced_shader
= state
;
699 pipe_mutex_unlock(rb_context
->call_mutex
);
700 pipe_mutex_unlock(rb_context
->list_mutex
);
701 pipe_mutex_unlock(rb_screen
->list_mutex
);
706 FREE(tr_shdr
->replaced_tokens
);
707 tr_shdr
->replaced_shader
= NULL
;
708 tr_shdr
->replaced_tokens
= NULL
;
710 pipe_mutex_unlock(rb_context
->call_mutex
);
711 pipe_mutex_unlock(rb_context
->list_mutex
);
712 pipe_mutex_unlock(rb_screen
->list_mutex
);
717 rbug_header(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
721 switch(header
->opcode
) {
723 rbug_send_ping_reply(tr_rbug
->con
, serial
, NULL
);
725 case RBUG_OP_TEXTURE_LIST
:
726 ret
= rbug_texture_list(tr_rbug
, header
, serial
);
728 case RBUG_OP_TEXTURE_INFO
:
729 ret
= rbug_texture_info(tr_rbug
, header
, serial
);
731 case RBUG_OP_TEXTURE_READ
:
732 ret
= rbug_texture_read(tr_rbug
, header
, serial
);
734 case RBUG_OP_CONTEXT_LIST
:
735 ret
= rbug_context_list(tr_rbug
, header
, serial
);
737 case RBUG_OP_CONTEXT_INFO
:
738 ret
= rbug_context_info(tr_rbug
, header
, serial
);
740 case RBUG_OP_CONTEXT_DRAW_BLOCK
:
741 ret
= rbug_context_draw_block(tr_rbug
, header
, serial
);
743 case RBUG_OP_CONTEXT_DRAW_STEP
:
744 ret
= rbug_context_draw_step(tr_rbug
, header
, serial
);
746 case RBUG_OP_CONTEXT_DRAW_UNBLOCK
:
747 ret
= rbug_context_draw_unblock(tr_rbug
, header
, serial
);
749 case RBUG_OP_CONTEXT_DRAW_RULE
:
750 ret
= rbug_context_draw_rule(tr_rbug
, header
, serial
);
752 case RBUG_OP_CONTEXT_FLUSH
:
753 ret
= rbug_context_flush(tr_rbug
, header
, serial
);
755 case RBUG_OP_SHADER_LIST
:
756 ret
= rbug_shader_list(tr_rbug
, header
, serial
);
758 case RBUG_OP_SHADER_INFO
:
759 ret
= rbug_shader_info(tr_rbug
, header
, serial
);
761 case RBUG_OP_SHADER_DISABLE
:
762 ret
= rbug_shader_disable(tr_rbug
, header
);
764 case RBUG_OP_SHADER_REPLACE
:
765 ret
= rbug_shader_replace(tr_rbug
, header
);
768 debug_printf("%s - unsupported opcode %u\n", __FUNCTION__
, header
->opcode
);
772 rbug_free_header(header
);
775 rbug_send_error_reply(tr_rbug
->con
, serial
, ret
, NULL
);
781 rbug_con(struct rbug_rbug
*tr_rbug
)
783 struct rbug_header
*header
;
786 debug_printf("%s - connection received\n", __FUNCTION__
);
788 while(tr_rbug
->running
) {
789 header
= rbug_get_message(tr_rbug
->con
, &serial
);
793 if (!rbug_header(tr_rbug
, header
, serial
))
797 debug_printf("%s - connection closed\n", __FUNCTION__
);
799 rbug_disconnect(tr_rbug
->con
);
803 PIPE_THREAD_ROUTINE(rbug_thread
, void_tr_rbug
)
805 struct rbug_rbug
*tr_rbug
= void_tr_rbug
;
806 uint16_t port
= 13370;
812 for (;port
<= 13379 && s
< 0; port
++)
813 s
= u_socket_listen_on_port(port
);
816 debug_printf("rbug_rbug - failed to listen\n");
820 u_socket_block(s
, false);
822 debug_printf("rbug_rbug - remote debugging listening on port %u\n", --port
);
824 while(tr_rbug
->running
) {
827 c
= u_socket_accept(s
);
831 u_socket_block(c
, true);
832 tr_rbug
->con
= rbug_from_socket(c
);
846 /**********************************************************
851 rbug_start(struct rbug_screen
*rb_screen
)
853 struct rbug_rbug
*tr_rbug
= CALLOC_STRUCT(rbug_rbug
);
857 tr_rbug
->rb_screen
= rb_screen
;
858 tr_rbug
->running
= TRUE
;
859 tr_rbug
->thread
= pipe_thread_create(rbug_thread
, tr_rbug
);
865 rbug_stop(struct rbug_rbug
*tr_rbug
)
870 tr_rbug
->running
= false;
871 pipe_thread_wait(tr_rbug
->thread
);
879 rbug_notify_draw_blocked(struct rbug_context
*rb_context
)
881 struct rbug_screen
*rb_screen
= rbug_screen(rb_context
->base
.screen
);
882 struct rbug_rbug
*tr_rbug
= rb_screen
->rbug
;
884 if (tr_rbug
&& tr_rbug
->con
)
885 rbug_send_context_draw_blocked(tr_rbug
->con
,
886 VOID2U64(rb_context
), rb_context
->draw_blocked
, NULL
);