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/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 mtx_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 mtx_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
;
209 mtx_lock(&rb_screen
->list_mutex
);
210 foreach(ptr
, &rb_screen
->resources
) {
211 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
212 if (gpti
->texture
== VOID2U64(tr_tex
))
218 mtx_unlock(&rb_screen
->list_mutex
);
222 t
= tr_tex
->resource
;
223 num_layers
= util_max_layer(t
, 0) + 1;
225 rbug_send_texture_info_reply(tr_rbug
->con
, serial
,
226 t
->target
, t
->format
,
230 util_format_get_blockwidth(t
->format
),
231 util_format_get_blockheight(t
->format
),
232 util_format_get_blocksize(t
->format
),
238 mtx_unlock(&rb_screen
->list_mutex
);
244 rbug_texture_read(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
246 struct rbug_proto_texture_read
*gptr
= (struct rbug_proto_texture_read
*)header
;
248 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
249 struct rbug_resource
*tr_tex
= NULL
;
250 struct rbug_list
*ptr
;
252 struct pipe_context
*context
= rb_screen
->private_context
;
253 struct pipe_resource
*tex
;
254 struct pipe_transfer
*t
;
258 mtx_lock(&rb_screen
->list_mutex
);
259 foreach(ptr
, &rb_screen
->resources
) {
260 tr_tex
= container_of(ptr
, struct rbug_resource
, list
);
261 if (gptr
->texture
== VOID2U64(tr_tex
))
267 mtx_unlock(&rb_screen
->list_mutex
);
271 tex
= tr_tex
->resource
;
272 map
= pipe_transfer_map(context
, tex
,
273 gptr
->level
, gptr
->face
+ gptr
->zslice
,
275 gptr
->x
, gptr
->y
, gptr
->w
, gptr
->h
, &t
);
277 rbug_send_texture_read_reply(tr_rbug
->con
, serial
,
279 util_format_get_blockwidth(t
->resource
->format
),
280 util_format_get_blockheight(t
->resource
->format
),
281 util_format_get_blocksize(t
->resource
->format
),
283 t
->stride
* util_format_get_nblocksy(t
->resource
->format
,
288 context
->transfer_unmap(context
, t
);
290 mtx_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 mtx_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 mtx_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_SHADER_SAMPLER_VIEWS
];
329 mtx_lock(&rb_screen
->list_mutex
);
330 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
333 mtx_unlock(&rb_screen
->list_mutex
);
337 /* protect the pipe context */
338 mtx_lock(&rb_context
->draw_mutex
);
339 mtx_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 /* XXX what about vertex/geometry shader texture views? */
345 for (i
= 0; i
< rb_context
->curr
.num_views
[PIPE_SHADER_FRAGMENT
]; i
++)
346 texs
[i
] = VOID2U64(rb_context
->curr
.texs
[PIPE_SHADER_FRAGMENT
][i
]);
348 rbug_send_context_info_reply(tr_rbug
->con
, serial
,
349 VOID2U64(rb_context
->curr
.shader
[PIPE_SHADER_VERTEX
]), VOID2U64(rb_context
->curr
.shader
[PIPE_SHADER_FRAGMENT
]),
350 texs
, rb_context
->curr
.num_views
[PIPE_SHADER_FRAGMENT
],
351 cbufs
, rb_context
->curr
.nr_cbufs
,
352 VOID2U64(rb_context
->curr
.zsbuf
),
353 rb_context
->draw_blocker
, rb_context
->draw_blocked
, NULL
);
355 mtx_unlock(&rb_context
->call_mutex
);
356 mtx_unlock(&rb_context
->draw_mutex
);
357 mtx_unlock(&rb_screen
->list_mutex
);
363 rbug_context_draw_block(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
365 struct rbug_proto_context_draw_block
*block
= (struct rbug_proto_context_draw_block
*)header
;
367 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
368 struct rbug_context
*rb_context
= NULL
;
370 mtx_lock(&rb_screen
->list_mutex
);
371 rb_context
= rbug_get_context_locked(rb_screen
, block
->context
);
374 mtx_unlock(&rb_screen
->list_mutex
);
378 mtx_lock(&rb_context
->draw_mutex
);
379 rb_context
->draw_blocker
|= block
->block
;
380 mtx_unlock(&rb_context
->draw_mutex
);
382 mtx_unlock(&rb_screen
->list_mutex
);
388 rbug_context_draw_step(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
390 struct rbug_proto_context_draw_step
*step
= (struct rbug_proto_context_draw_step
*)header
;
392 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
393 struct rbug_context
*rb_context
= NULL
;
395 mtx_lock(&rb_screen
->list_mutex
);
396 rb_context
= rbug_get_context_locked(rb_screen
, step
->context
);
399 mtx_unlock(&rb_screen
->list_mutex
);
403 mtx_lock(&rb_context
->draw_mutex
);
404 if (rb_context
->draw_blocked
& RBUG_BLOCK_RULE
) {
405 if (step
->step
& RBUG_BLOCK_RULE
)
406 rb_context
->draw_blocked
&= ~RBUG_BLOCK_MASK
;
408 rb_context
->draw_blocked
&= ~step
->step
;
410 mtx_unlock(&rb_context
->draw_mutex
);
412 cnd_broadcast(&rb_context
->draw_cond
);
414 mtx_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 mtx_lock(&rb_screen
->list_mutex
);
428 rb_context
= rbug_get_context_locked(rb_screen
, unblock
->context
);
431 mtx_unlock(&rb_screen
->list_mutex
);
435 mtx_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 mtx_unlock(&rb_context
->draw_mutex
);
445 cnd_broadcast(&rb_context
->draw_cond
);
447 mtx_unlock(&rb_screen
->list_mutex
);
453 rbug_context_draw_rule(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
455 struct rbug_proto_context_draw_rule
*rule
= (struct rbug_proto_context_draw_rule
*)header
;
457 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
458 struct rbug_context
*rb_context
= NULL
;
460 mtx_lock(&rb_screen
->list_mutex
);
461 rb_context
= rbug_get_context_locked(rb_screen
, rule
->context
);
464 mtx_unlock(&rb_screen
->list_mutex
);
468 mtx_lock(&rb_context
->draw_mutex
);
469 rb_context
->draw_rule
.shader
[PIPE_SHADER_VERTEX
] = U642VOID(rule
->vertex
);
470 rb_context
->draw_rule
.shader
[PIPE_SHADER_FRAGMENT
] = U642VOID(rule
->fragment
);
471 rb_context
->draw_rule
.texture
= U642VOID(rule
->texture
);
472 rb_context
->draw_rule
.surf
= U642VOID(rule
->surface
);
473 rb_context
->draw_rule
.blocker
= rule
->block
;
474 rb_context
->draw_blocker
|= RBUG_BLOCK_RULE
;
475 mtx_unlock(&rb_context
->draw_mutex
);
477 cnd_broadcast(&rb_context
->draw_cond
);
479 mtx_unlock(&rb_screen
->list_mutex
);
485 rbug_context_flush(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
487 struct rbug_proto_context_flush
*flush
= (struct rbug_proto_context_flush
*)header
;
489 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
490 struct rbug_context
*rb_context
= NULL
;
492 mtx_lock(&rb_screen
->list_mutex
);
493 rb_context
= rbug_get_context_locked(rb_screen
, flush
->context
);
496 mtx_unlock(&rb_screen
->list_mutex
);
500 /* protect the pipe context */
501 mtx_lock(&rb_context
->call_mutex
);
503 rb_context
->pipe
->flush(rb_context
->pipe
, NULL
, 0);
505 mtx_unlock(&rb_context
->call_mutex
);
506 mtx_unlock(&rb_screen
->list_mutex
);
512 rbug_shader_list(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
514 struct rbug_proto_shader_list
*list
= (struct rbug_proto_shader_list
*)header
;
516 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
517 struct rbug_context
*rb_context
= NULL
;
518 struct rbug_shader
*tr_shdr
= NULL
;
519 struct rbug_list
*ptr
;
520 rbug_shader_t
*shdrs
;
523 mtx_lock(&rb_screen
->list_mutex
);
524 rb_context
= rbug_get_context_locked(rb_screen
, list
->context
);
527 mtx_unlock(&rb_screen
->list_mutex
);
531 mtx_lock(&rb_context
->list_mutex
);
532 shdrs
= MALLOC(rb_context
->num_shaders
* sizeof(rbug_shader_t
));
533 foreach(ptr
, &rb_context
->shaders
) {
534 tr_shdr
= container_of(ptr
, struct rbug_shader
, list
);
535 shdrs
[i
++] = VOID2U64(tr_shdr
);
538 mtx_unlock(&rb_context
->list_mutex
);
539 mtx_unlock(&rb_screen
->list_mutex
);
541 rbug_send_shader_list_reply(tr_rbug
->con
, serial
, shdrs
, i
, NULL
);
548 rbug_shader_info(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
550 struct rbug_proto_shader_info
*info
= (struct rbug_proto_shader_info
*)header
;
552 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
553 struct rbug_context
*rb_context
= NULL
;
554 struct rbug_shader
*tr_shdr
= NULL
;
555 unsigned original_len
;
556 unsigned replaced_len
;
558 mtx_lock(&rb_screen
->list_mutex
);
559 rb_context
= rbug_get_context_locked(rb_screen
, info
->context
);
562 mtx_unlock(&rb_screen
->list_mutex
);
566 mtx_lock(&rb_context
->list_mutex
);
568 tr_shdr
= rbug_get_shader_locked(rb_context
, info
->shader
);
571 mtx_unlock(&rb_context
->list_mutex
);
572 mtx_unlock(&rb_screen
->list_mutex
);
577 assert(sizeof(struct tgsi_token
) == 4);
579 original_len
= tgsi_num_tokens(tr_shdr
->tokens
);
580 if (tr_shdr
->replaced_tokens
)
581 replaced_len
= tgsi_num_tokens(tr_shdr
->replaced_tokens
);
585 rbug_send_shader_info_reply(tr_rbug
->con
, serial
,
586 (uint32_t*)tr_shdr
->tokens
, original_len
,
587 (uint32_t*)tr_shdr
->replaced_tokens
, replaced_len
,
591 mtx_unlock(&rb_context
->list_mutex
);
592 mtx_unlock(&rb_screen
->list_mutex
);
598 rbug_shader_disable(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
600 struct rbug_proto_shader_disable
*dis
= (struct rbug_proto_shader_disable
*)header
;
602 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
603 struct rbug_context
*rb_context
= NULL
;
604 struct rbug_shader
*tr_shdr
= NULL
;
606 mtx_lock(&rb_screen
->list_mutex
);
607 rb_context
= rbug_get_context_locked(rb_screen
, dis
->context
);
610 mtx_unlock(&rb_screen
->list_mutex
);
614 mtx_lock(&rb_context
->list_mutex
);
616 tr_shdr
= rbug_get_shader_locked(rb_context
, dis
->shader
);
619 mtx_unlock(&rb_context
->list_mutex
);
620 mtx_unlock(&rb_screen
->list_mutex
);
624 tr_shdr
->disabled
= dis
->disable
;
626 mtx_unlock(&rb_context
->list_mutex
);
627 mtx_unlock(&rb_screen
->list_mutex
);
633 rbug_shader_replace(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
)
635 struct rbug_proto_shader_replace
*rep
= (struct rbug_proto_shader_replace
*)header
;
637 struct rbug_screen
*rb_screen
= tr_rbug
->rb_screen
;
638 struct rbug_context
*rb_context
= NULL
;
639 struct rbug_shader
*tr_shdr
= NULL
;
640 struct pipe_context
*pipe
= NULL
;
643 mtx_lock(&rb_screen
->list_mutex
);
644 rb_context
= rbug_get_context_locked(rb_screen
, rep
->context
);
647 mtx_unlock(&rb_screen
->list_mutex
);
651 mtx_lock(&rb_context
->list_mutex
);
653 tr_shdr
= rbug_get_shader_locked(rb_context
, rep
->shader
);
656 mtx_unlock(&rb_context
->list_mutex
);
657 mtx_unlock(&rb_screen
->list_mutex
);
661 /* protect the pipe context */
662 mtx_lock(&rb_context
->call_mutex
);
664 pipe
= rb_context
->pipe
;
666 /* remove old replaced shader */
667 if (tr_shdr
->replaced_shader
) {
668 /* if this shader is bound rebind the original shader */
669 if (rb_context
->curr
.shader
[PIPE_SHADER_FRAGMENT
] == tr_shdr
|| rb_context
->curr
.shader
[PIPE_SHADER_VERTEX
] == tr_shdr
)
670 rbug_shader_bind_locked(pipe
, tr_shdr
, tr_shdr
->shader
);
672 FREE(tr_shdr
->replaced_tokens
);
673 rbug_shader_delete_locked(pipe
, tr_shdr
, tr_shdr
->replaced_shader
);
674 tr_shdr
->replaced_shader
= NULL
;
675 tr_shdr
->replaced_tokens
= NULL
;
678 /* empty inputs means restore old which we did above */
679 if (rep
->tokens_len
== 0)
682 tr_shdr
->replaced_tokens
= tgsi_dup_tokens((struct tgsi_token
*)rep
->tokens
);
683 if (!tr_shdr
->replaced_tokens
)
686 state
= rbug_shader_create_locked(pipe
, tr_shdr
, tr_shdr
->replaced_tokens
);
690 /* bind new shader if the shader is currently a bound */
691 if (rb_context
->curr
.shader
[PIPE_SHADER_FRAGMENT
] == tr_shdr
|| rb_context
->curr
.shader
[PIPE_SHADER_VERTEX
] == tr_shdr
)
692 rbug_shader_bind_locked(pipe
, tr_shdr
, state
);
695 tr_shdr
->replaced_shader
= state
;
698 mtx_unlock(&rb_context
->call_mutex
);
699 mtx_unlock(&rb_context
->list_mutex
);
700 mtx_unlock(&rb_screen
->list_mutex
);
705 FREE(tr_shdr
->replaced_tokens
);
706 tr_shdr
->replaced_shader
= NULL
;
707 tr_shdr
->replaced_tokens
= NULL
;
709 mtx_unlock(&rb_context
->call_mutex
);
710 mtx_unlock(&rb_context
->list_mutex
);
711 mtx_unlock(&rb_screen
->list_mutex
);
716 rbug_header(struct rbug_rbug
*tr_rbug
, struct rbug_header
*header
, uint32_t serial
)
720 switch(header
->opcode
) {
722 rbug_send_ping_reply(tr_rbug
->con
, serial
, NULL
);
724 case RBUG_OP_TEXTURE_LIST
:
725 ret
= rbug_texture_list(tr_rbug
, header
, serial
);
727 case RBUG_OP_TEXTURE_INFO
:
728 ret
= rbug_texture_info(tr_rbug
, header
, serial
);
730 case RBUG_OP_TEXTURE_READ
:
731 ret
= rbug_texture_read(tr_rbug
, header
, serial
);
733 case RBUG_OP_CONTEXT_LIST
:
734 ret
= rbug_context_list(tr_rbug
, header
, serial
);
736 case RBUG_OP_CONTEXT_INFO
:
737 ret
= rbug_context_info(tr_rbug
, header
, serial
);
739 case RBUG_OP_CONTEXT_DRAW_BLOCK
:
740 ret
= rbug_context_draw_block(tr_rbug
, header
, serial
);
742 case RBUG_OP_CONTEXT_DRAW_STEP
:
743 ret
= rbug_context_draw_step(tr_rbug
, header
, serial
);
745 case RBUG_OP_CONTEXT_DRAW_UNBLOCK
:
746 ret
= rbug_context_draw_unblock(tr_rbug
, header
, serial
);
748 case RBUG_OP_CONTEXT_DRAW_RULE
:
749 ret
= rbug_context_draw_rule(tr_rbug
, header
, serial
);
751 case RBUG_OP_CONTEXT_FLUSH
:
752 ret
= rbug_context_flush(tr_rbug
, header
, serial
);
754 case RBUG_OP_SHADER_LIST
:
755 ret
= rbug_shader_list(tr_rbug
, header
, serial
);
757 case RBUG_OP_SHADER_INFO
:
758 ret
= rbug_shader_info(tr_rbug
, header
, serial
);
760 case RBUG_OP_SHADER_DISABLE
:
761 ret
= rbug_shader_disable(tr_rbug
, header
);
763 case RBUG_OP_SHADER_REPLACE
:
764 ret
= rbug_shader_replace(tr_rbug
, header
);
767 debug_printf("%s - unsupported opcode %u\n", __FUNCTION__
, header
->opcode
);
771 rbug_free_header(header
);
774 rbug_send_error_reply(tr_rbug
->con
, serial
, ret
, NULL
);
780 rbug_con(struct rbug_rbug
*tr_rbug
)
782 struct rbug_header
*header
;
785 debug_printf("%s - connection received\n", __FUNCTION__
);
787 while(tr_rbug
->running
) {
788 header
= rbug_get_message(tr_rbug
->con
, &serial
);
792 if (!rbug_header(tr_rbug
, header
, serial
))
796 debug_printf("%s - connection closed\n", __FUNCTION__
);
798 rbug_disconnect(tr_rbug
->con
);
802 PIPE_THREAD_ROUTINE(rbug_thread
, void_tr_rbug
)
804 struct rbug_rbug
*tr_rbug
= void_tr_rbug
;
805 uint16_t port
= 13370;
811 for (;port
<= 13379 && s
< 0; port
++)
812 s
= u_socket_listen_on_port(port
);
815 debug_printf("rbug_rbug - failed to listen\n");
819 u_socket_block(s
, false);
821 debug_printf("rbug_rbug - remote debugging listening on port %u\n", --port
);
823 while(tr_rbug
->running
) {
826 c
= u_socket_accept(s
);
830 u_socket_block(c
, true);
831 tr_rbug
->con
= rbug_from_socket(c
);
845 /**********************************************************
850 rbug_start(struct rbug_screen
*rb_screen
)
852 struct rbug_rbug
*tr_rbug
= CALLOC_STRUCT(rbug_rbug
);
856 tr_rbug
->rb_screen
= rb_screen
;
857 tr_rbug
->running
= TRUE
;
858 tr_rbug
->thread
= pipe_thread_create(rbug_thread
, tr_rbug
);
864 rbug_stop(struct rbug_rbug
*tr_rbug
)
869 tr_rbug
->running
= false;
870 pipe_thread_wait(tr_rbug
->thread
);
878 rbug_notify_draw_blocked(struct rbug_context
*rb_context
)
880 struct rbug_screen
*rb_screen
= rbug_screen(rb_context
->base
.screen
);
881 struct rbug_rbug
*tr_rbug
= rb_screen
->rbug
;
883 if (tr_rbug
&& tr_rbug
->con
)
884 rbug_send_context_draw_blocked(tr_rbug
->con
,
885 VOID2U64(rb_context
), rb_context
->draw_blocked
, NULL
);