revert 213 commits (to 56092) from the last month. 10 still need work to resolve...
[AROS.git] / workbench / libs / mesa / src / gallium / auxiliary / rbug / rbug_shader.c
blob1742941cc177fb36a6cea6913f262f3a12123609
1 /*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * This file holds the function implementation for one of the rbug extensions.
27 * Prototypes and declerations of functions and structs is in the same folder
28 * in the header file matching this file's name.
30 * The functions starting rbug_send_* encodes a call to the write format and
31 * sends that to the supplied connection, while functions starting with
32 * rbug_demarshal_* demarshal data in the wire protocol.
34 * Functions ending with _reply are replies to requests.
37 #include "rbug_internal.h"
38 #include "rbug/rbug_shader.h"
40 int rbug_send_shader_list(struct rbug_connection *__con,
41 rbug_context_t context,
42 uint32_t *__serial)
44 uint32_t __len = 0;
45 uint32_t __pos = 0;
46 uint8_t *__data = NULL;
47 int __ret = 0;
49 LEN(8); /* header */
50 LEN(8); /* context */
52 /* align */
53 PAD(__len, 8);
55 __data = (uint8_t*)MALLOC(__len);
56 if (!__data)
57 return -ENOMEM;
59 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST));
60 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
61 WRITE(8, rbug_context_t, context); /* context */
63 /* final pad */
64 PAD(__pos, 8);
66 if (__pos != __len) {
67 __ret = -EINVAL;
68 } else {
69 rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len);
70 rbug_connection_write(__con, __data, __len);
71 __ret = rbug_connection_send_finish(__con, __serial);
74 FREE(__data);
75 return __ret;
78 int rbug_send_shader_info(struct rbug_connection *__con,
79 rbug_context_t context,
80 rbug_shader_t shader,
81 uint32_t *__serial)
83 uint32_t __len = 0;
84 uint32_t __pos = 0;
85 uint8_t *__data = NULL;
86 int __ret = 0;
88 LEN(8); /* header */
89 LEN(8); /* context */
90 LEN(8); /* shader */
92 /* align */
93 PAD(__len, 8);
95 __data = (uint8_t*)MALLOC(__len);
96 if (!__data)
97 return -ENOMEM;
99 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO));
100 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
101 WRITE(8, rbug_context_t, context); /* context */
102 WRITE(8, rbug_shader_t, shader); /* shader */
104 /* final pad */
105 PAD(__pos, 8);
107 if (__pos != __len) {
108 __ret = -EINVAL;
109 } else {
110 rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len);
111 rbug_connection_write(__con, __data, __len);
112 __ret = rbug_connection_send_finish(__con, __serial);
115 FREE(__data);
116 return __ret;
119 int rbug_send_shader_disable(struct rbug_connection *__con,
120 rbug_context_t context,
121 rbug_shader_t shader,
122 uint8_t disable,
123 uint32_t *__serial)
125 uint32_t __len = 0;
126 uint32_t __pos = 0;
127 uint8_t *__data = NULL;
128 int __ret = 0;
130 LEN(8); /* header */
131 LEN(8); /* context */
132 LEN(8); /* shader */
133 LEN(1); /* disable */
135 /* align */
136 PAD(__len, 8);
138 __data = (uint8_t*)MALLOC(__len);
139 if (!__data)
140 return -ENOMEM;
142 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE));
143 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
144 WRITE(8, rbug_context_t, context); /* context */
145 WRITE(8, rbug_shader_t, shader); /* shader */
146 WRITE(1, uint8_t, disable); /* disable */
148 /* final pad */
149 PAD(__pos, 8);
151 if (__pos != __len) {
152 __ret = -EINVAL;
153 } else {
154 rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len);
155 rbug_connection_write(__con, __data, __len);
156 __ret = rbug_connection_send_finish(__con, __serial);
159 FREE(__data);
160 return __ret;
163 int rbug_send_shader_replace(struct rbug_connection *__con,
164 rbug_context_t context,
165 rbug_shader_t shader,
166 uint32_t *tokens,
167 uint32_t tokens_len,
168 uint32_t *__serial)
170 uint32_t __len = 0;
171 uint32_t __pos = 0;
172 uint8_t *__data = NULL;
173 int __ret = 0;
175 LEN(8); /* header */
176 LEN(8); /* context */
177 LEN(8); /* shader */
178 LEN_ARRAY(4, tokens); /* tokens */
180 /* align */
181 PAD(__len, 8);
183 __data = (uint8_t*)MALLOC(__len);
184 if (!__data)
185 return -ENOMEM;
187 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE));
188 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
189 WRITE(8, rbug_context_t, context); /* context */
190 WRITE(8, rbug_shader_t, shader); /* shader */
191 WRITE_ARRAY(4, uint32_t, tokens); /* tokens */
193 /* final pad */
194 PAD(__pos, 8);
196 if (__pos != __len) {
197 __ret = -EINVAL;
198 } else {
199 rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len);
200 rbug_connection_write(__con, __data, __len);
201 __ret = rbug_connection_send_finish(__con, __serial);
204 FREE(__data);
205 return __ret;
208 int rbug_send_shader_list_reply(struct rbug_connection *__con,
209 uint32_t serial,
210 rbug_shader_t *shaders,
211 uint32_t shaders_len,
212 uint32_t *__serial)
214 uint32_t __len = 0;
215 uint32_t __pos = 0;
216 uint8_t *__data = NULL;
217 int __ret = 0;
219 LEN(8); /* header */
220 LEN(4); /* serial */
221 LEN_ARRAY(8, shaders); /* shaders */
223 /* align */
224 PAD(__len, 8);
226 __data = (uint8_t*)MALLOC(__len);
227 if (!__data)
228 return -ENOMEM;
230 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY));
231 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
232 WRITE(4, uint32_t, serial); /* serial */
233 WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */
235 /* final pad */
236 PAD(__pos, 8);
238 if (__pos != __len) {
239 __ret = -EINVAL;
240 } else {
241 rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len);
242 rbug_connection_write(__con, __data, __len);
243 __ret = rbug_connection_send_finish(__con, __serial);
246 FREE(__data);
247 return __ret;
250 int rbug_send_shader_info_reply(struct rbug_connection *__con,
251 uint32_t serial,
252 uint32_t *original,
253 uint32_t original_len,
254 uint32_t *replaced,
255 uint32_t replaced_len,
256 uint8_t disabled,
257 uint32_t *__serial)
259 uint32_t __len = 0;
260 uint32_t __pos = 0;
261 uint8_t *__data = NULL;
262 int __ret = 0;
264 LEN(8); /* header */
265 LEN(4); /* serial */
266 LEN_ARRAY(4, original); /* original */
267 LEN_ARRAY(4, replaced); /* replaced */
268 LEN(1); /* disabled */
270 /* align */
271 PAD(__len, 8);
273 __data = (uint8_t*)MALLOC(__len);
274 if (!__data)
275 return -ENOMEM;
277 WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY));
278 WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
279 WRITE(4, uint32_t, serial); /* serial */
280 WRITE_ARRAY(4, uint32_t, original); /* original */
281 WRITE_ARRAY(4, uint32_t, replaced); /* replaced */
282 WRITE(1, uint8_t, disabled); /* disabled */
284 /* final pad */
285 PAD(__pos, 8);
287 if (__pos != __len) {
288 __ret = -EINVAL;
289 } else {
290 rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len);
291 rbug_connection_write(__con, __data, __len);
292 __ret = rbug_connection_send_finish(__con, __serial);
295 FREE(__data);
296 return __ret;
299 struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header)
301 uint32_t len = 0;
302 uint32_t pos = 0;
303 uint8_t *data = NULL;
304 struct rbug_proto_shader_list *ret;
306 if (!header)
307 return NULL;
308 if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST)
309 return NULL;
311 pos = 0;
312 len = header->length * 4;
313 data = (uint8_t*)&header[1];
314 ret = MALLOC(sizeof(*ret));
315 if (!ret)
316 return NULL;
318 ret->header.__message = header;
319 ret->header.opcode = header->opcode;
321 READ(8, rbug_context_t, context); /* context */
323 return ret;
326 struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header)
328 uint32_t len = 0;
329 uint32_t pos = 0;
330 uint8_t *data = NULL;
331 struct rbug_proto_shader_info *ret;
333 if (!header)
334 return NULL;
335 if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO)
336 return NULL;
338 pos = 0;
339 len = header->length * 4;
340 data = (uint8_t*)&header[1];
341 ret = MALLOC(sizeof(*ret));
342 if (!ret)
343 return NULL;
345 ret->header.__message = header;
346 ret->header.opcode = header->opcode;
348 READ(8, rbug_context_t, context); /* context */
349 READ(8, rbug_shader_t, shader); /* shader */
351 return ret;
354 struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header)
356 uint32_t len = 0;
357 uint32_t pos = 0;
358 uint8_t *data = NULL;
359 struct rbug_proto_shader_disable *ret;
361 if (!header)
362 return NULL;
363 if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE)
364 return NULL;
366 pos = 0;
367 len = header->length * 4;
368 data = (uint8_t*)&header[1];
369 ret = MALLOC(sizeof(*ret));
370 if (!ret)
371 return NULL;
373 ret->header.__message = header;
374 ret->header.opcode = header->opcode;
376 READ(8, rbug_context_t, context); /* context */
377 READ(8, rbug_shader_t, shader); /* shader */
378 READ(1, uint8_t, disable); /* disable */
380 return ret;
383 struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header)
385 uint32_t len = 0;
386 uint32_t pos = 0;
387 uint8_t *data = NULL;
388 struct rbug_proto_shader_replace *ret;
390 if (!header)
391 return NULL;
392 if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE)
393 return NULL;
395 pos = 0;
396 len = header->length * 4;
397 data = (uint8_t*)&header[1];
398 ret = MALLOC(sizeof(*ret));
399 if (!ret)
400 return NULL;
402 ret->header.__message = header;
403 ret->header.opcode = header->opcode;
405 READ(8, rbug_context_t, context); /* context */
406 READ(8, rbug_shader_t, shader); /* shader */
407 READ_ARRAY(4, uint32_t, tokens); /* tokens */
409 return ret;
412 struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header)
414 uint32_t len = 0;
415 uint32_t pos = 0;
416 uint8_t *data = NULL;
417 struct rbug_proto_shader_list_reply *ret;
419 if (!header)
420 return NULL;
421 if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY)
422 return NULL;
424 pos = 0;
425 len = header->length * 4;
426 data = (uint8_t*)&header[1];
427 ret = MALLOC(sizeof(*ret));
428 if (!ret)
429 return NULL;
431 ret->header.__message = header;
432 ret->header.opcode = header->opcode;
434 READ(4, uint32_t, serial); /* serial */
435 READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */
437 return ret;
440 struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header)
442 uint32_t len = 0;
443 uint32_t pos = 0;
444 uint8_t *data = NULL;
445 struct rbug_proto_shader_info_reply *ret;
447 if (!header)
448 return NULL;
449 if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY)
450 return NULL;
452 pos = 0;
453 len = header->length * 4;
454 data = (uint8_t*)&header[1];
455 ret = MALLOC(sizeof(*ret));
456 if (!ret)
457 return NULL;
459 ret->header.__message = header;
460 ret->header.opcode = header->opcode;
462 READ(4, uint32_t, serial); /* serial */
463 READ_ARRAY(4, uint32_t, original); /* original */
464 READ_ARRAY(4, uint32_t, replaced); /* replaced */
465 READ(1, uint8_t, disabled); /* disabled */
467 return ret;