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
;
108 memset(&pss
, 0, sizeof(pss
));
111 switch(rb_shader
->type
) {
112 case RBUG_SHADER_FRAGMENT
:
113 state
= pipe
->create_fs_state(pipe
, &pss
);
115 case RBUG_SHADER_VERTEX
:
116 state
= pipe
->create_vs_state(pipe
, &pss
);
118 case RBUG_SHADER_GEOM
:
119 state
= pipe
->create_gs_state(pipe
, &pss
);
130 rbug_shader_bind_locked(struct pipe_context
*pipe
,
131 struct rbug_shader
*rb_shader
,
134 switch(rb_shader
->type
) {
135 case RBUG_SHADER_FRAGMENT
:
136 pipe
->bind_fs_state(pipe
, state
);
138 case RBUG_SHADER_VERTEX
:
139 pipe
->bind_vs_state(pipe
, state
);
141 case RBUG_SHADER_GEOM
:
142 pipe
->bind_gs_state(pipe
, state
);
151 rbug_shader_delete_locked(struct pipe_context
*pipe
,
152 struct rbug_shader
*rb_shader
,
155 switch(rb_shader
->type
) {
156 case RBUG_SHADER_FRAGMENT
:
157 pipe
->delete_fs_state(pipe
, state
);
159 case RBUG_SHADER_VERTEX
:
160 pipe
->delete_vs_state(pipe
, state
);
162 case RBUG_SHADER_GEOM
:
163 pipe
->delete_gs_state(pipe
, state
);
171 /************************************************
172 * Request handler functions
177 rbug_texture_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
179 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
180 struct rbug_resource
*tr_tex
= NULL
;
181 struct rbug_list
*ptr
;
182 rbug_texture_t
*texs
;
185 pipe_mutex_lock(rb_screen
->list_mutex
);
186 texs
= MALLOC(rb_screen
->num_resources
* sizeof(rbug_texture_t
));
187 foreach(ptr
, &rb_screen
->resources
) {
188 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
189 texs
[i
++] = VOID2U64(tr_tex
);
191 pipe_mutex_unlock(rb_screen
->list_mutex
);
193 rbug_send_texture_list_reply(tr_rbug
->con
, serial
, texs
, i
, NULL
);
200 rbug_texture_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
202 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
203 struct rbug_resource
*tr_tex
= NULL
;
204 struct rbug_proto_texture_info
*gpti
= (struct rbug_proto_texture_info
*)header
;
205 struct rbug_list
*ptr
;
206 struct pipe_resource
*t
;
208 pipe_mutex_lock(rb_screen
->list_mutex
);
209 foreach(ptr
, &rb_screen
->resources
) {
210 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
211 if (gpti
->texture
== VOID2U64(tr_tex
))
217 pipe_mutex_unlock(rb_screen
->list_mutex
);
221 t
= tr_tex
->resource
;
222 rbug_send_texture_info_reply(tr_rbug
->con
, serial
,
223 t
->target
, t
->format
,
227 util_format_get_blockwidth(t
->format
),
228 util_format_get_blockheight(t
->format
),
229 util_format_get_blocksize(t
->format
),
235 pipe_mutex_unlock(rb_screen
->list_mutex
);
241 rbug_texture_read(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
243 struct rbug_proto_texture_read
*gptr
= (struct rbug_proto_texture_read
*)header
;
245 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
246 struct rbug_resource
*tr_tex
= NULL
;
247 struct rbug_list
*ptr
;
249 struct pipe_context
*context
= rb_screen
->private_context
;
250 struct pipe_resource
*tex
;
251 struct pipe_transfer
*t
;
255 pipe_mutex_lock(rb_screen
->list_mutex
);
256 foreach(ptr
, &rb_screen
->resources
) {
257 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
258 if (gptr
->texture
== VOID2U64(tr_tex
))
264 pipe_mutex_unlock(rb_screen
->list_mutex
);
268 tex
= tr_tex
->resource
;
269 t
= pipe_get_transfer(context
, tex
,
270 gptr
->level
, gptr
->face
+ gptr
->zslice
,
272 gptr
->x
, gptr
->y
, gptr
->w
, gptr
->h
);
274 map
= context
->transfer_map(context
, t
);
276 rbug_send_texture_read_reply(tr_rbug
->con
, serial
,
278 util_format_get_blockwidth(t
->resource
->format
),
279 util_format_get_blockheight(t
->resource
->format
),
280 util_format_get_blocksize(t
->resource
->format
),
282 t
->stride
* util_format_get_nblocksy(t
->resource
->format
,
287 context
->transfer_unmap(context
, t
);
288 context
->transfer_destroy(context
, t
);
290 pipe_mutex_unlock(rb_screen
->list_mutex
);
296 rbug_context_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
298 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
299 struct rbug_list
*ptr
;
300 struct rbug_context
*rb_context
= NULL
;
301 rbug_context_t
*ctxs
;
304 pipe_mutex_lock(rb_screen
->list_mutex
);
305 ctxs
= MALLOC(rb_screen
->num_contexts
* sizeof(rbug_context_t
));
306 foreach(ptr
, &rb_screen
->contexts
) {
307 rb_context
= container_of(ptr
, struct rbug_context
, list
);
308 ctxs
[i
++] = VOID2U64(rb_context
);
310 pipe_mutex_unlock(rb_screen
->list_mutex
);
312 rbug_send_context_list_reply(tr_rbug
->con
, serial
, ctxs
, i
, NULL
);
319 rbug_context_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
321 struct rbug_proto_context_info
*info
= (struct rbug_proto_context_info
*)header
;
323 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
324 struct rbug_context
*rb_context
= NULL
;
325 rbug_texture_t cbufs
[PIPE_MAX_COLOR_BUFS
];
326 rbug_texture_t texs
[PIPE_MAX_SAMPLERS
];
329 pipe_mutex_lock(rb_screen
->list_mutex
);
330 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
333 pipe_mutex_unlock(rb_screen
->list_mutex
);
337 /* protect the pipe context */
338 pipe_mutex_lock(rb_context
->draw_mutex
);
339 pipe_mutex_lock(rb_context
->call_mutex
);
341 for (i
= 0; i
< rb_context
->curr
.nr_cbufs
; i
++)
342 cbufs
[i
] = VOID2U64(rb_context
->curr
.cbufs
[i
]);
344 for (i
= 0; i
< rb_context
->curr
.num_fs_views
; i
++)
345 texs
[i
] = VOID2U64(rb_context
->curr
.fs_texs
[i
]);
347 rbug_send_context_info_reply(tr_rbug
->con
, serial
,
348 VOID2U64(rb_context
->curr
.vs
), VOID2U64(rb_context
->curr
.fs
),
349 texs
, rb_context
->curr
.num_fs_views
,
350 cbufs
, rb_context
->curr
.nr_cbufs
,
351 VOID2U64(rb_context
->curr
.zsbuf
),
352 rb_context
->draw_blocker
, rb_context
->draw_blocked
, NULL
);
354 pipe_mutex_unlock(rb_context
->call_mutex
);
355 pipe_mutex_unlock(rb_context
->draw_mutex
);
356 pipe_mutex_unlock(rb_screen
->list_mutex
);
362 rbug_context_draw_block(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
364 struct rbug_proto_context_draw_block
*block
= (struct rbug_proto_context_draw_block
*)header
;
366 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
367 struct rbug_context
*rb_context
= NULL
;
369 pipe_mutex_lock(rb_screen
->list_mutex
);
370 rb_context
= rbug_get_context_locked(rb_screen
, block
->context
);
373 pipe_mutex_unlock(rb_screen
->list_mutex
);
377 pipe_mutex_lock(rb_context
->draw_mutex
);
378 rb_context
->draw_blocker
|= block
->block
;
379 pipe_mutex_unlock(rb_context
->draw_mutex
);
381 pipe_mutex_unlock(rb_screen
->list_mutex
);
387 rbug_context_draw_step(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
389 struct rbug_proto_context_draw_step
*step
= (struct rbug_proto_context_draw_step
*)header
;
391 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
392 struct rbug_context
*rb_context
= NULL
;
394 pipe_mutex_lock(rb_screen
->list_mutex
);
395 rb_context
= rbug_get_context_locked(rb_screen
, step
->context
);
398 pipe_mutex_unlock(rb_screen
->list_mutex
);
402 pipe_mutex_lock(rb_context
->draw_mutex
);
403 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
404 if (step
->step
& RBUG_BLOCK_RULE
)
405 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
407 rb_context
->draw_blocked
&= ~step
->step
;
409 pipe_mutex_unlock(rb_context
->draw_mutex
);
411 pipe_condvar_broadcast(rb_context
->draw_cond
);
413 pipe_mutex_unlock(rb_screen
->list_mutex
);
419 rbug_context_draw_unblock(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
421 struct rbug_proto_context_draw_unblock
*unblock
= (struct rbug_proto_context_draw_unblock
*)header
;
423 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
424 struct rbug_context
*rb_context
= NULL
;
426 pipe_mutex_lock(rb_screen
->list_mutex
);
427 rb_context
= rbug_get_context_locked(rb_screen
, unblock
->context
);
430 pipe_mutex_unlock(rb_screen
->list_mutex
);
434 pipe_mutex_lock(rb_context
->draw_mutex
);
435 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
436 if (unblock
->unblock
& RBUG_BLOCK_RULE
)
437 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
439 rb_context
->draw_blocked
&= ~unblock
->unblock
;
441 rb_context
->draw_blocker
&= ~unblock
->unblock
;
442 pipe_mutex_unlock(rb_context
->draw_mutex
);
444 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 pipe_condvar_broadcast(rb_context
->draw_cond
);
478 pipe_mutex_unlock(rb_screen
->list_mutex
);
484 rbug_context_flush(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
486 struct rbug_proto_context_flush
*flush
= (struct rbug_proto_context_flush
*)header
;
488 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
489 struct rbug_context
*rb_context
= NULL
;
491 pipe_mutex_lock(rb_screen
->list_mutex
);
492 rb_context
= rbug_get_context_locked(rb_screen
, flush
->context
);
495 pipe_mutex_unlock(rb_screen
->list_mutex
);
499 /* protect the pipe context */
500 pipe_mutex_lock(rb_context
->call_mutex
);
502 rb_context
->pipe
->flush(rb_context
->pipe
, NULL
);
504 pipe_mutex_unlock(rb_context
->call_mutex
);
505 pipe_mutex_unlock(rb_screen
->list_mutex
);
511 rbug_shader_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
513 struct rbug_proto_shader_list
*list
= (struct rbug_proto_shader_list
*)header
;
515 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
516 struct rbug_context
*rb_context
= NULL
;
517 struct rbug_shader
*tr_shdr
= NULL
;
518 struct rbug_list
*ptr
;
519 rbug_shader_t
*shdrs
;
522 pipe_mutex_lock(rb_screen
->list_mutex
);
523 rb_context
= rbug_get_context_locked(rb_screen
, list
->context
);
526 pipe_mutex_unlock(rb_screen
->list_mutex
);
530 pipe_mutex_lock(rb_context
->list_mutex
);
531 shdrs
= MALLOC(rb_context
->num_shaders
* sizeof(rbug_shader_t
));
532 foreach(ptr
, &rb_context
->shaders
) {
533 tr_shdr
= container_of(ptr
, struct rbug_shader
, list
);
534 shdrs
[i
++] = VOID2U64(tr_shdr
);
537 pipe_mutex_unlock(rb_context
->list_mutex
);
538 pipe_mutex_unlock(rb_screen
->list_mutex
);
540 rbug_send_shader_list_reply(tr_rbug
->con
, serial
, shdrs
, i
, NULL
);
547 rbug_shader_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
549 struct rbug_proto_shader_info
*info
= (struct rbug_proto_shader_info
*)header
;
551 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
552 struct rbug_context
*rb_context
= NULL
;
553 struct rbug_shader
*tr_shdr
= NULL
;
554 unsigned original_len
;
555 unsigned replaced_len
;
557 pipe_mutex_lock(rb_screen
->list_mutex
);
558 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
561 pipe_mutex_unlock(rb_screen
->list_mutex
);
565 pipe_mutex_lock(rb_context
->list_mutex
);
567 tr_shdr
= rbug_get_shader_locked(rb_context
, info
->shader
);
570 pipe_mutex_unlock(rb_context
->list_mutex
);
571 pipe_mutex_unlock(rb_screen
->list_mutex
);
576 assert(sizeof(struct tgsi_token
) == 4);
578 original_len
= tgsi_num_tokens(tr_shdr
->tokens
);
579 if (tr_shdr
->replaced_tokens
)
580 replaced_len
= tgsi_num_tokens(tr_shdr
->replaced_tokens
);
584 rbug_send_shader_info_reply(tr_rbug
->con
, serial
,
585 (uint32_t*)tr_shdr
->tokens
, original_len
,
586 (uint32_t*)tr_shdr
->replaced_tokens
, replaced_len
,
590 pipe_mutex_unlock(rb_context
->list_mutex
);
591 pipe_mutex_unlock(rb_screen
->list_mutex
);
597 rbug_shader_disable(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
599 struct rbug_proto_shader_disable
*dis
= (struct rbug_proto_shader_disable
*)header
;
601 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
602 struct rbug_context
*rb_context
= NULL
;
603 struct rbug_shader
*tr_shdr
= NULL
;
605 pipe_mutex_lock(rb_screen
->list_mutex
);
606 rb_context
= rbug_get_context_locked(rb_screen
, dis
->context
);
609 pipe_mutex_unlock(rb_screen
->list_mutex
);
613 pipe_mutex_lock(rb_context
->list_mutex
);
615 tr_shdr
= rbug_get_shader_locked(rb_context
, dis
->shader
);
618 pipe_mutex_unlock(rb_context
->list_mutex
);
619 pipe_mutex_unlock(rb_screen
->list_mutex
);
623 tr_shdr
->disabled
= dis
->disable
;
625 pipe_mutex_unlock(rb_context
->list_mutex
);
626 pipe_mutex_unlock(rb_screen
->list_mutex
);
632 rbug_shader_replace(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
634 struct rbug_proto_shader_replace
*rep
= (struct rbug_proto_shader_replace
*)header
;
636 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
637 struct rbug_context
*rb_context
= NULL
;
638 struct rbug_shader
*tr_shdr
= NULL
;
639 struct pipe_context
*pipe
= NULL
;
642 pipe_mutex_lock(rb_screen
->list_mutex
);
643 rb_context
= rbug_get_context_locked(rb_screen
, rep
->context
);
646 pipe_mutex_unlock(rb_screen
->list_mutex
);
650 pipe_mutex_lock(rb_context
->list_mutex
);
652 tr_shdr
= rbug_get_shader_locked(rb_context
, rep
->shader
);
655 pipe_mutex_unlock(rb_context
->list_mutex
);
656 pipe_mutex_unlock(rb_screen
->list_mutex
);
660 /* protect the pipe context */
661 pipe_mutex_lock(rb_context
->call_mutex
);
663 pipe
= rb_context
->pipe
;
665 /* remove old replaced shader */
666 if (tr_shdr
->replaced_shader
) {
667 /* if this shader is bound rebind the original shader */
668 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
669 rbug_shader_bind_locked(pipe
, tr_shdr
, tr_shdr
->shader
);
671 FREE(tr_shdr
->replaced_tokens
);
672 rbug_shader_delete_locked(pipe
, tr_shdr
, tr_shdr
->replaced_shader
);
673 tr_shdr
->replaced_shader
= NULL
;
674 tr_shdr
->replaced_tokens
= NULL
;
677 /* empty inputs means restore old which we did above */
678 if (rep
->tokens_len
== 0)
681 tr_shdr
->replaced_tokens
= tgsi_dup_tokens((struct tgsi_token
*)rep
->tokens
);
682 if (!tr_shdr
->replaced_tokens
)
685 state
= rbug_shader_create_locked(pipe
, tr_shdr
, tr_shdr
->replaced_tokens
);
689 /* bind new shader if the shader is currently a bound */
690 if (rb_context
->curr
.fs
== tr_shdr
|| rb_context
->curr
.vs
== tr_shdr
)
691 rbug_shader_bind_locked(pipe
, tr_shdr
, state
);
694 tr_shdr
->replaced_shader
= state
;
697 pipe_mutex_unlock(rb_context
->call_mutex
);
698 pipe_mutex_unlock(rb_context
->list_mutex
);
699 pipe_mutex_unlock(rb_screen
->list_mutex
);
704 FREE(tr_shdr
->replaced_tokens
);
705 tr_shdr
->replaced_shader
= NULL
;
706 tr_shdr
->replaced_tokens
= NULL
;
708 pipe_mutex_unlock(rb_context
->call_mutex
);
709 pipe_mutex_unlock(rb_context
->list_mutex
);
710 pipe_mutex_unlock(rb_screen
->list_mutex
);
715 rbug_header(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
719 switch(header
->opcode
) {
721 rbug_send_ping_reply(tr_rbug
->con
, serial
, NULL
);
723 case RBUG_OP_TEXTURE_LIST
:
724 ret
= rbug_texture_list(tr_rbug
, header
, serial
);
726 case RBUG_OP_TEXTURE_INFO
:
727 ret
= rbug_texture_info(tr_rbug
, header
, serial
);
729 case RBUG_OP_TEXTURE_READ
:
730 ret
= rbug_texture_read(tr_rbug
, header
, serial
);
732 case RBUG_OP_CONTEXT_LIST
:
733 ret
= rbug_context_list(tr_rbug
, header
, serial
);
735 case RBUG_OP_CONTEXT_INFO
:
736 ret
= rbug_context_info(tr_rbug
, header
, serial
);
738 case RBUG_OP_CONTEXT_DRAW_BLOCK
:
739 ret
= rbug_context_draw_block(tr_rbug
, header
, serial
);
741 case RBUG_OP_CONTEXT_DRAW_STEP
:
742 ret
= rbug_context_draw_step(tr_rbug
, header
, serial
);
744 case RBUG_OP_CONTEXT_DRAW_UNBLOCK
:
745 ret
= rbug_context_draw_unblock(tr_rbug
, header
, serial
);
747 case RBUG_OP_CONTEXT_DRAW_RULE
:
748 ret
= rbug_context_draw_rule(tr_rbug
, header
, serial
);
750 case RBUG_OP_CONTEXT_FLUSH
:
751 ret
= rbug_context_flush(tr_rbug
, header
, serial
);
753 case RBUG_OP_SHADER_LIST
:
754 ret
= rbug_shader_list(tr_rbug
, header
, serial
);
756 case RBUG_OP_SHADER_INFO
:
757 ret
= rbug_shader_info(tr_rbug
, header
, serial
);
759 case RBUG_OP_SHADER_DISABLE
:
760 ret
= rbug_shader_disable(tr_rbug
, header
);
762 case RBUG_OP_SHADER_REPLACE
:
763 ret
= rbug_shader_replace(tr_rbug
, header
);
766 debug_printf("%s - unsupported opcode %u\n", __FUNCTION__
, header
->opcode
);
770 rbug_free_header(header
);
773 rbug_send_error_reply(tr_rbug
->con
, serial
, ret
, NULL
);
779 rbug_con(struct rbug_rbug
*tr_rbug
)
781 struct rbug_header
*header
;
784 debug_printf("%s - connection received\n", __FUNCTION__
);
786 while(tr_rbug
->running
) {
787 header
= rbug_get_message(tr_rbug
->con
, &serial
);
791 if (!rbug_header(tr_rbug
, header
, serial
))
795 debug_printf("%s - connection closed\n", __FUNCTION__
);
797 rbug_disconnect(tr_rbug
->con
);
801 PIPE_THREAD_ROUTINE(rbug_thread
, void_tr_rbug
)
803 struct rbug_rbug
*tr_rbug
= void_tr_rbug
;
804 uint16_t port
= 13370;
810 for (;port
<= 13379 && s
< 0; port
++)
811 s
= u_socket_listen_on_port(port
);
814 debug_printf("rbug_rbug - failed to listen\n");
818 u_socket_block(s
, false);
820 debug_printf("rbug_rbug - remote debugging listening on port %u\n", --port
);
822 while(tr_rbug
->running
) {
825 c
= u_socket_accept(s
);
829 u_socket_block(c
, true);
830 tr_rbug
->con
= rbug_from_socket(c
);
844 /**********************************************************
849 rbug_start(struct rbug_screen
*rb_screen
)
851 struct rbug_rbug
*tr_rbug
= CALLOC_STRUCT(rbug_rbug
);
855 tr_rbug
->rb_screen
= rb_screen
;
856 tr_rbug
->running
= TRUE
;
857 tr_rbug
->thread
= pipe_thread_create(rbug_thread
, tr_rbug
);
863 rbug_stop(struct rbug_rbug
*tr_rbug
)
868 tr_rbug
->running
= false;
869 pipe_thread_wait(tr_rbug
->thread
);
877 rbug_notify_draw_blocked(struct rbug_context
*rb_context
)
879 struct rbug_screen
*rb_screen
= rbug_screen(rb_context
->base
.screen
);
880 struct rbug_rbug
*tr_rbug
= rb_screen
->rbug
;
882 if (tr_rbug
&& tr_rbug
->con
)
883 rbug_send_context_draw_blocked(tr_rbug
->con
,
884 VOID2U64(rb_context
), rb_context
->draw_blocked
, NULL
);