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))
50 #define container_of(ptr, type, field) \
51 (type*)((char*)ptr - offsetof(type, field))
55 struct rbug_screen
*rb_screen
;
56 struct rbug_connection
*con
;
61 PIPE_THREAD_ROUTINE(rbug_thread
, void_rbug
);
64 /**********************************************************
69 static struct rbug_context
*
70 rbug_get_context_locked(struct rbug_screen
*rb_screen
, rbug_context_t ctx
)
72 struct rbug_context
*rb_context
= NULL
;
73 struct rbug_list
*ptr
;
75 foreach(ptr
, &rb_screen
->contexts
) {
76 rb_context
= container_of(ptr
, struct rbug_context
, list
);
77 if (ctx
== VOID2U64(rb_context
))
85 static struct rbug_shader
*
86 rbug_get_shader_locked(struct rbug_context
*rb_context
, rbug_shader_t shdr
)
88 struct rbug_shader
*tr_shdr
= NULL
;
89 struct rbug_list
*ptr
;
91 foreach(ptr
, &rb_context
->shaders
) {
92 tr_shdr
= container_of(ptr
, struct rbug_shader
, list
);
93 if (shdr
== VOID2U64(tr_shdr
))
102 rbug_shader_create_locked(struct pipe_context
*pipe
,
103 struct rbug_shader
*rb_shader
,
104 struct tgsi_token
*tokens
)
107 struct pipe_shader_state pss
= { 0 };
110 switch(rb_shader
->type
) {
111 case RBUG_SHADER_FRAGMENT
:
112 state
= pipe
->create_fs_state(pipe
, &pss
);
114 case RBUG_SHADER_VERTEX
:
115 state
= pipe
->create_vs_state(pipe
, &pss
);
117 case RBUG_SHADER_GEOM
:
118 state
= pipe
->create_gs_state(pipe
, &pss
);
129 rbug_shader_bind_locked(struct pipe_context
*pipe
,
130 struct rbug_shader
*rb_shader
,
133 switch(rb_shader
->type
) {
134 case RBUG_SHADER_FRAGMENT
:
135 pipe
->bind_fs_state(pipe
, state
);
137 case RBUG_SHADER_VERTEX
:
138 pipe
->bind_vs_state(pipe
, state
);
140 case RBUG_SHADER_GEOM
:
141 pipe
->bind_gs_state(pipe
, state
);
150 rbug_shader_delete_locked(struct pipe_context
*pipe
,
151 struct rbug_shader
*rb_shader
,
154 switch(rb_shader
->type
) {
155 case RBUG_SHADER_FRAGMENT
:
156 pipe
->delete_fs_state(pipe
, state
);
158 case RBUG_SHADER_VERTEX
:
159 pipe
->delete_vs_state(pipe
, state
);
161 case RBUG_SHADER_GEOM
:
162 pipe
->delete_gs_state(pipe
, state
);
170 /************************************************
171 * Request handler functions
176 rbug_texture_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
178 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
179 struct rbug_resource
*tr_tex
= NULL
;
180 struct rbug_list
*ptr
;
181 rbug_texture_t
*texs
;
184 pipe_mutex_lock(rb_screen
->list_mutex
);
185 texs
= MALLOC(rb_screen
->num_resources
* sizeof(rbug_texture_t
));
186 foreach(ptr
, &rb_screen
->resources
) {
187 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
188 texs
[i
++] = VOID2U64(tr_tex
);
190 pipe_mutex_unlock(rb_screen
->list_mutex
);
192 rbug_send_texture_list_reply(tr_rbug
->con
, serial
, texs
, i
, NULL
);
199 rbug_texture_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
201 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
202 struct rbug_resource
*tr_tex
= NULL
;
203 struct rbug_proto_texture_info
*gpti
= (struct rbug_proto_texture_info
*)header
;
204 struct rbug_list
*ptr
;
205 struct pipe_resource
*t
;
207 pipe_mutex_lock(rb_screen
->list_mutex
);
208 foreach(ptr
, &rb_screen
->resources
) {
209 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
210 if (gpti
->texture
== VOID2U64(tr_tex
))
216 pipe_mutex_unlock(rb_screen
->list_mutex
);
220 t
= tr_tex
->resource
;
221 rbug_send_texture_info_reply(tr_rbug
->con
, serial
,
222 t
->target
, t
->format
,
226 util_format_get_blockwidth(t
->format
),
227 util_format_get_blockheight(t
->format
),
228 util_format_get_blocksize(t
->format
),
234 pipe_mutex_unlock(rb_screen
->list_mutex
);
240 rbug_texture_read(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
242 struct rbug_proto_texture_read
*gptr
= (struct rbug_proto_texture_read
*)header
;
244 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
245 struct rbug_resource
*tr_tex
= NULL
;
246 struct rbug_list
*ptr
;
248 struct pipe_context
*context
= rb_screen
->private_context
;
249 struct pipe_resource
*tex
;
250 struct pipe_transfer
*t
;
254 pipe_mutex_lock(rb_screen
->list_mutex
);
255 foreach(ptr
, &rb_screen
->resources
) {
256 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
257 if (gptr
->texture
== VOID2U64(tr_tex
))
263 pipe_mutex_unlock(rb_screen
->list_mutex
);
267 tex
= tr_tex
->resource
;
268 t
= pipe_get_transfer(context
, tex
,
269 gptr
->face
, gptr
->level
, gptr
->zslice
,
271 gptr
->x
, gptr
->y
, gptr
->w
, gptr
->h
);
273 map
= context
->transfer_map(context
, t
);
275 rbug_send_texture_read_reply(tr_rbug
->con
, serial
,
277 util_format_get_blockwidth(t
->resource
->format
),
278 util_format_get_blockheight(t
->resource
->format
),
279 util_format_get_blocksize(t
->resource
->format
),
281 t
->stride
* util_format_get_nblocksy(t
->resource
->format
,
286 context
->transfer_unmap(context
, t
);
287 context
->transfer_destroy(context
, t
);
289 pipe_mutex_unlock(rb_screen
->list_mutex
);
295 rbug_context_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
297 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
298 struct rbug_list
*ptr
;
299 struct rbug_context
*rb_context
= NULL
;
300 rbug_context_t
*ctxs
;
303 pipe_mutex_lock(rb_screen
->list_mutex
);
304 ctxs
= MALLOC(rb_screen
->num_contexts
* sizeof(rbug_context_t
));
305 foreach(ptr
, &rb_screen
->contexts
) {
306 rb_context
= container_of(ptr
, struct rbug_context
, list
);
307 ctxs
[i
++] = VOID2U64(rb_context
);
309 pipe_mutex_unlock(rb_screen
->list_mutex
);
311 rbug_send_context_list_reply(tr_rbug
->con
, serial
, ctxs
, i
, NULL
);
318 rbug_context_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
320 struct rbug_proto_context_info
*info
= (struct rbug_proto_context_info
*)header
;
322 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
323 struct rbug_context
*rb_context
= NULL
;
324 rbug_texture_t cbufs
[PIPE_MAX_COLOR_BUFS
];
325 rbug_texture_t texs
[PIPE_MAX_SAMPLERS
];
328 pipe_mutex_lock(rb_screen
->list_mutex
);
329 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
332 pipe_mutex_unlock(rb_screen
->list_mutex
);
336 /* protect the pipe context */
337 pipe_mutex_lock(rb_context
->draw_mutex
);
338 pipe_mutex_lock(rb_context
->call_mutex
);
340 for (i
= 0; i
< rb_context
->curr
.nr_cbufs
; i
++)
341 cbufs
[i
] = VOID2U64(rb_context
->curr
.cbufs
[i
]);
343 for (i
= 0; i
< rb_context
->curr
.num_fs_views
; i
++)
344 texs
[i
] = VOID2U64(rb_context
->curr
.fs_texs
[i
]);
346 rbug_send_context_info_reply(tr_rbug
->con
, serial
,
347 VOID2U64(rb_context
->curr
.vs
), VOID2U64(rb_context
->curr
.fs
),
348 texs
, rb_context
->curr
.num_fs_views
,
349 cbufs
, rb_context
->curr
.nr_cbufs
,
350 VOID2U64(rb_context
->curr
.zsbuf
),
351 rb_context
->draw_blocker
, rb_context
->draw_blocked
, NULL
);
353 pipe_mutex_unlock(rb_context
->call_mutex
);
354 pipe_mutex_unlock(rb_context
->draw_mutex
);
355 pipe_mutex_unlock(rb_screen
->list_mutex
);
361 rbug_context_draw_block(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
363 struct rbug_proto_context_draw_block
*block
= (struct rbug_proto_context_draw_block
*)header
;
365 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
366 struct rbug_context
*rb_context
= NULL
;
368 pipe_mutex_lock(rb_screen
->list_mutex
);
369 rb_context
= rbug_get_context_locked(rb_screen
, block
->context
);
372 pipe_mutex_unlock(rb_screen
->list_mutex
);
376 pipe_mutex_lock(rb_context
->draw_mutex
);
377 rb_context
->draw_blocker
|= block
->block
;
378 pipe_mutex_unlock(rb_context
->draw_mutex
);
380 pipe_mutex_unlock(rb_screen
->list_mutex
);
386 rbug_context_draw_step(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
388 struct rbug_proto_context_draw_step
*step
= (struct rbug_proto_context_draw_step
*)header
;
390 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
391 struct rbug_context
*rb_context
= NULL
;
393 pipe_mutex_lock(rb_screen
->list_mutex
);
394 rb_context
= rbug_get_context_locked(rb_screen
, step
->context
);
397 pipe_mutex_unlock(rb_screen
->list_mutex
);
401 pipe_mutex_lock(rb_context
->draw_mutex
);
402 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
403 if (step
->step
& RBUG_BLOCK_RULE
)
404 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
406 rb_context
->draw_blocked
&= ~step
->step
;
408 pipe_mutex_unlock(rb_context
->draw_mutex
);
410 #ifdef PIPE_THREAD_HAVE_CONDVAR
411 pipe_condvar_broadcast(rb_context
->draw_cond
);
414 pipe_mutex_unlock(rb_screen
->list_mutex
);
420 rbug_context_draw_unblock(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
422 struct rbug_proto_context_draw_unblock
*unblock
= (struct rbug_proto_context_draw_unblock
*)header
;
424 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
425 struct rbug_context
*rb_context
= NULL
;
427 pipe_mutex_lock(rb_screen
->list_mutex
);
428 rb_context
= rbug_get_context_locked(rb_screen
, unblock
->context
);
431 pipe_mutex_unlock(rb_screen
->list_mutex
);
435 pipe_mutex_lock(rb_context
->draw_mutex
);
436 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
437 if (unblock
->unblock
& RBUG_BLOCK_RULE
)
438 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
440 rb_context
->draw_blocked
&= ~unblock
->unblock
;
442 rb_context
->draw_blocker
&= ~unblock
->unblock
;
443 pipe_mutex_unlock(rb_context
->draw_mutex
);
445 #ifdef PIPE_THREAD_HAVE_CONDVAR
446 pipe_condvar_broadcast(rb_context
->draw_cond
);
449 pipe_mutex_unlock(rb_screen
->list_mutex
);
455 rbug_context_draw_rule(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
457 struct rbug_proto_context_draw_rule
*rule
= (struct rbug_proto_context_draw_rule
*)header
;
459 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
460 struct rbug_context
*rb_context
= NULL
;
462 pipe_mutex_lock(rb_screen
->list_mutex
);
463 rb_context
= rbug_get_context_locked(rb_screen
, rule
->context
);
466 pipe_mutex_unlock(rb_screen
->list_mutex
);
470 pipe_mutex_lock(rb_context
->draw_mutex
);
471 rb_context
->draw_rule
.vs
= U642VOID(rule
->vertex
);
472 rb_context
->draw_rule
.fs
= U642VOID(rule
->fragment
);
473 rb_context
->draw_rule
.texture
= U642VOID(rule
->texture
);
474 rb_context
->draw_rule
.surf
= U642VOID(rule
->surface
);
475 rb_context
->draw_rule
.blocker
= rule
->block
;
476 rb_context
->draw_blocker
|= RBUG_BLOCK_RULE
;
477 pipe_mutex_unlock(rb_context
->draw_mutex
);
479 #ifdef PIPE_THREAD_HAVE_CONDVAR
480 pipe_condvar_broadcast(rb_context
->draw_cond
);
483 pipe_mutex_unlock(rb_screen
->list_mutex
);
489 rbug_context_flush(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
491 struct rbug_proto_context_flush
*flush
= (struct rbug_proto_context_flush
*)header
;
493 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
494 struct rbug_context
*rb_context
= NULL
;
496 pipe_mutex_lock(rb_screen
->list_mutex
);
497 rb_context
= rbug_get_context_locked(rb_screen
, flush
->context
);
500 pipe_mutex_unlock(rb_screen
->list_mutex
);
504 /* protect the pipe context */
505 pipe_mutex_lock(rb_context
->call_mutex
);
507 rb_context
->pipe
->flush(rb_context
->pipe
, flush
->flags
, NULL
);
509 pipe_mutex_unlock(rb_context
->call_mutex
);
510 pipe_mutex_unlock(rb_screen
->list_mutex
);
516 rbug_shader_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
518 struct rbug_proto_shader_list
*list
= (struct rbug_proto_shader_list
*)header
;
520 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
521 struct rbug_context
*rb_context
= NULL
;
522 struct rbug_shader
*tr_shdr
= NULL
;
523 struct rbug_list
*ptr
;
524 rbug_shader_t
*shdrs
;
527 pipe_mutex_lock(rb_screen
->list_mutex
);
528 rb_context
= rbug_get_context_locked(rb_screen
, list
->context
);
531 pipe_mutex_unlock(rb_screen
->list_mutex
);
535 pipe_mutex_lock(rb_context
->list_mutex
);
536 shdrs
= MALLOC(rb_context
->num_shaders
* sizeof(rbug_shader_t
));
537 foreach(ptr
, &rb_context
->shaders
) {
538 tr_shdr
= container_of(ptr
, struct rbug_shader
, list
);
539 shdrs
[i
++] = VOID2U64(tr_shdr
);
542 pipe_mutex_unlock(rb_context
->list_mutex
);
543 pipe_mutex_unlock(rb_screen
->list_mutex
);
545 rbug_send_shader_list_reply(tr_rbug
->con
, serial
, shdrs
, i
, NULL
);
552 rbug_shader_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
554 struct rbug_proto_shader_info
*info
= (struct rbug_proto_shader_info
*)header
;
556 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
557 struct rbug_context
*rb_context
= NULL
;
558 struct rbug_shader
*tr_shdr
= NULL
;
559 unsigned original_len
;
560 unsigned replaced_len
;
562 pipe_mutex_lock(rb_screen
->list_mutex
);
563 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
566 pipe_mutex_unlock(rb_screen
->list_mutex
);
570 pipe_mutex_lock(rb_context
->list_mutex
);
572 tr_shdr
= rbug_get_shader_locked(rb_context
, info
->shader
);
575 pipe_mutex_unlock(rb_context
->list_mutex
);
576 pipe_mutex_unlock(rb_screen
->list_mutex
);
581 assert(sizeof(struct tgsi_token
) == 4);
583 original_len
= tgsi_num_tokens(tr_shdr
->tokens
);
584 if (tr_shdr
->replaced_tokens
)
585 replaced_len
= tgsi_num_tokens(tr_shdr
->replaced_tokens
);
589 rbug_send_shader_info_reply(tr_rbug
->con
, serial
,
590 (uint32_t*)tr_shdr
->tokens
, original_len
,
591 (uint32_t*)tr_shdr
->replaced_tokens
, replaced_len
,
595 pipe_mutex_unlock(rb_context
->list_mutex
);
596 pipe_mutex_unlock(rb_screen
->list_mutex
);
602 rbug_shader_disable(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
604 struct rbug_proto_shader_disable
*dis
= (struct rbug_proto_shader_disable
*)header
;
606 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
607 struct rbug_context
*rb_context
= NULL
;
608 struct rbug_shader
*tr_shdr
= NULL
;
610 pipe_mutex_lock(rb_screen
->list_mutex
);
611 rb_context
= rbug_get_context_locked(rb_screen
, dis
->context
);
614 pipe_mutex_unlock(rb_screen
->list_mutex
);
618 pipe_mutex_lock(rb_context
->list_mutex
);
620 tr_shdr
= rbug_get_shader_locked(rb_context
, dis
->shader
);
623 pipe_mutex_unlock(rb_context
->list_mutex
);
624 pipe_mutex_unlock(rb_screen
->list_mutex
);
628 tr_shdr
->disabled
= dis
->disable
;
630 pipe_mutex_unlock(rb_context
->list_mutex
);
631 pipe_mutex_unlock(rb_screen
->list_mutex
);
637 rbug_shader_replace(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
639 struct rbug_proto_shader_replace
*rep
= (struct rbug_proto_shader_replace
*)header
;
641 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
642 struct rbug_context
*rb_context
= NULL
;
643 struct rbug_shader
*tr_shdr
= NULL
;
644 struct pipe_context
*pipe
= NULL
;
647 pipe_mutex_lock(rb_screen
->list_mutex
);
648 rb_context
= rbug_get_context_locked(rb_screen
, rep
->context
);
651 pipe_mutex_unlock(rb_screen
->list_mutex
);
655 pipe_mutex_lock(rb_context
->list_mutex
);
657 tr_shdr
= rbug_get_shader_locked(rb_context
, rep
->shader
);
660 pipe_mutex_unlock(rb_context
->list_mutex
);
661 pipe_mutex_unlock(rb_screen
->list_mutex
);
665 /* protect the pipe context */
666 pipe_mutex_lock(rb_context
->call_mutex
);
668 pipe
= rb_context
->pipe
;
670 /* remove old replaced shader */
671 if (tr_shdr
->replaced_shader
) {
672 /* if this shader is bound rebind the original shader */
673 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
674 rbug_shader_bind_locked(pipe
, tr_shdr
, tr_shdr
->shader
);
676 FREE(tr_shdr
->replaced_tokens
);
677 rbug_shader_delete_locked(pipe
, tr_shdr
, tr_shdr
->replaced_shader
);
678 tr_shdr
->replaced_shader
= NULL
;
679 tr_shdr
->replaced_tokens
= NULL
;
682 /* empty inputs means restore old which we did above */
683 if (rep
->tokens_len
== 0)
686 tr_shdr
->replaced_tokens
= tgsi_dup_tokens((struct tgsi_token
*)rep
->tokens
);
687 if (!tr_shdr
->replaced_tokens
)
690 state
= rbug_shader_create_locked(pipe
, tr_shdr
, tr_shdr
->replaced_tokens
);
694 /* bind new shader if the shader is currently a bound */
695 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
696 rbug_shader_bind_locked(pipe
, tr_shdr
, state
);
699 tr_shdr
->replaced_shader
= state
;
702 pipe_mutex_unlock(rb_context
->call_mutex
);
703 pipe_mutex_unlock(rb_context
->list_mutex
);
704 pipe_mutex_unlock(rb_screen
->list_mutex
);
709 FREE(tr_shdr
->replaced_tokens
);
710 tr_shdr
->replaced_shader
= NULL
;
711 tr_shdr
->replaced_tokens
= NULL
;
713 pipe_mutex_unlock(rb_context
->call_mutex
);
714 pipe_mutex_unlock(rb_context
->list_mutex
);
715 pipe_mutex_unlock(rb_screen
->list_mutex
);
720 rbug_header(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
724 switch(header
->opcode
) {
726 rbug_send_ping_reply(tr_rbug
->con
, serial
, NULL
);
728 case RBUG_OP_TEXTURE_LIST
:
729 ret
= rbug_texture_list(tr_rbug
, header
, serial
);
731 case RBUG_OP_TEXTURE_INFO
:
732 ret
= rbug_texture_info(tr_rbug
, header
, serial
);
734 case RBUG_OP_TEXTURE_READ
:
735 ret
= rbug_texture_read(tr_rbug
, header
, serial
);
737 case RBUG_OP_CONTEXT_LIST
:
738 ret
= rbug_context_list(tr_rbug
, header
, serial
);
740 case RBUG_OP_CONTEXT_INFO
:
741 ret
= rbug_context_info(tr_rbug
, header
, serial
);
743 case RBUG_OP_CONTEXT_DRAW_BLOCK
:
744 ret
= rbug_context_draw_block(tr_rbug
, header
, serial
);
746 case RBUG_OP_CONTEXT_DRAW_STEP
:
747 ret
= rbug_context_draw_step(tr_rbug
, header
, serial
);
749 case RBUG_OP_CONTEXT_DRAW_UNBLOCK
:
750 ret
= rbug_context_draw_unblock(tr_rbug
, header
, serial
);
752 case RBUG_OP_CONTEXT_DRAW_RULE
:
753 ret
= rbug_context_draw_rule(tr_rbug
, header
, serial
);
755 case RBUG_OP_CONTEXT_FLUSH
:
756 ret
= rbug_context_flush(tr_rbug
, header
, serial
);
758 case RBUG_OP_SHADER_LIST
:
759 ret
= rbug_shader_list(tr_rbug
, header
, serial
);
761 case RBUG_OP_SHADER_INFO
:
762 ret
= rbug_shader_info(tr_rbug
, header
, serial
);
764 case RBUG_OP_SHADER_DISABLE
:
765 ret
= rbug_shader_disable(tr_rbug
, header
);
767 case RBUG_OP_SHADER_REPLACE
:
768 ret
= rbug_shader_replace(tr_rbug
, header
);
771 debug_printf("%s - unsupported opcode %u\n", __FUNCTION__
, header
->opcode
);
775 rbug_free_header(header
);
778 rbug_send_error_reply(tr_rbug
->con
, serial
, ret
, NULL
);
784 rbug_con(struct rbug_rbug
*tr_rbug
)
786 struct rbug_header
*header
;
789 debug_printf("%s - connection received\n", __FUNCTION__
);
791 while(tr_rbug
->running
) {
792 header
= rbug_get_message(tr_rbug
->con
, &serial
);
796 if (!rbug_header(tr_rbug
, header
, serial
))
800 debug_printf("%s - connection closed\n", __FUNCTION__
);
802 rbug_disconnect(tr_rbug
->con
);
806 PIPE_THREAD_ROUTINE(rbug_thread
, void_tr_rbug
)
808 struct rbug_rbug
*tr_rbug
= void_tr_rbug
;
809 uint16_t port
= 13370;
815 for (;port
<= 13379 && s
< 0; port
++)
816 s
= u_socket_listen_on_port(port
);
819 debug_printf("rbug_rbug - failed to listen\n");
823 u_socket_block(s
, false);
825 debug_printf("rbug_rbug - remote debugging listening on port %u\n", --port
);
827 while(tr_rbug
->running
) {
830 c
= u_socket_accept(s
);
834 u_socket_block(c
, true);
835 tr_rbug
->con
= rbug_from_socket(c
);
849 /**********************************************************
854 rbug_start(struct rbug_screen
*rb_screen
)
856 struct rbug_rbug
*tr_rbug
= CALLOC_STRUCT(rbug_rbug
);
860 tr_rbug
->rb_screen
= rb_screen
;
861 tr_rbug
->running
= TRUE
;
862 tr_rbug
->thread
= pipe_thread_create(rbug_thread
, tr_rbug
);
868 rbug_stop(struct rbug_rbug
*tr_rbug
)
873 tr_rbug
->running
= false;
874 pipe_thread_wait(tr_rbug
->thread
);
882 rbug_notify_draw_blocked(struct rbug_context
*rb_context
)
884 struct rbug_screen
*rb_screen
= rbug_screen(rb_context
->base
.screen
);
885 struct rbug_rbug
*tr_rbug
= rb_screen
->rbug
;
887 if (tr_rbug
&& tr_rbug
->con
)
888 rbug_send_context_draw_blocked(tr_rbug
->con
,
889 VOID2U64(rb_context
), rb_context
->draw_blocked
, NULL
);