Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/auxiliary/rbug/rbug_shader.c
4561 views
1
/*
2
* Copyright 2009 VMware, Inc.
3
* All Rights Reserved.
4
*
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:
11
*
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.
15
*
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.
23
*/
24
25
/*
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.
29
*
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.
33
*
34
* Functions ending with _reply are replies to requests.
35
*/
36
37
#include "rbug_internal.h"
38
#include "rbug_shader.h"
39
40
int rbug_send_shader_list(struct rbug_connection *__con,
41
rbug_context_t context,
42
uint32_t *__serial)
43
{
44
uint32_t __len = 0;
45
uint32_t __pos = 0;
46
uint8_t *__data = NULL;
47
int __ret = 0;
48
49
LEN(8); /* header */
50
LEN(8); /* context */
51
52
/* align */
53
PAD(__len, 8);
54
55
__data = (uint8_t*)MALLOC(__len);
56
if (!__data)
57
return -ENOMEM;
58
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 */
62
63
/* final pad */
64
PAD(__pos, 8);
65
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);
72
}
73
74
FREE(__data);
75
return __ret;
76
}
77
78
int rbug_send_shader_info(struct rbug_connection *__con,
79
rbug_context_t context,
80
rbug_shader_t shader,
81
uint32_t *__serial)
82
{
83
uint32_t __len = 0;
84
uint32_t __pos = 0;
85
uint8_t *__data = NULL;
86
int __ret = 0;
87
88
LEN(8); /* header */
89
LEN(8); /* context */
90
LEN(8); /* shader */
91
92
/* align */
93
PAD(__len, 8);
94
95
__data = (uint8_t*)MALLOC(__len);
96
if (!__data)
97
return -ENOMEM;
98
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 */
103
104
/* final pad */
105
PAD(__pos, 8);
106
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);
113
}
114
115
FREE(__data);
116
return __ret;
117
}
118
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)
124
{
125
uint32_t __len = 0;
126
uint32_t __pos = 0;
127
uint8_t *__data = NULL;
128
int __ret = 0;
129
130
LEN(8); /* header */
131
LEN(8); /* context */
132
LEN(8); /* shader */
133
LEN(1); /* disable */
134
135
/* align */
136
PAD(__len, 8);
137
138
__data = (uint8_t*)MALLOC(__len);
139
if (!__data)
140
return -ENOMEM;
141
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 */
147
148
/* final pad */
149
PAD(__pos, 8);
150
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);
157
}
158
159
FREE(__data);
160
return __ret;
161
}
162
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)
169
{
170
uint32_t __len = 0;
171
uint32_t __pos = 0;
172
uint8_t *__data = NULL;
173
int __ret = 0;
174
175
LEN(8); /* header */
176
LEN(8); /* context */
177
LEN(8); /* shader */
178
LEN_ARRAY(4, tokens); /* tokens */
179
180
/* align */
181
PAD(__len, 8);
182
183
__data = (uint8_t*)MALLOC(__len);
184
if (!__data)
185
return -ENOMEM;
186
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 */
192
193
/* final pad */
194
PAD(__pos, 8);
195
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);
202
}
203
204
FREE(__data);
205
return __ret;
206
}
207
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)
213
{
214
uint32_t __len = 0;
215
uint32_t __pos = 0;
216
uint8_t *__data = NULL;
217
int __ret = 0;
218
219
LEN(8); /* header */
220
LEN(4); /* serial */
221
LEN_ARRAY(8, shaders); /* shaders */
222
223
/* align */
224
PAD(__len, 8);
225
226
__data = (uint8_t*)MALLOC(__len);
227
if (!__data)
228
return -ENOMEM;
229
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 */
234
235
/* final pad */
236
PAD(__pos, 8);
237
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);
244
}
245
246
FREE(__data);
247
return __ret;
248
}
249
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)
258
{
259
uint32_t __len = 0;
260
uint32_t __pos = 0;
261
uint8_t *__data = NULL;
262
int __ret = 0;
263
264
LEN(8); /* header */
265
LEN(4); /* serial */
266
LEN_ARRAY(4, original); /* original */
267
LEN_ARRAY(4, replaced); /* replaced */
268
LEN(1); /* disabled */
269
270
/* align */
271
PAD(__len, 8);
272
273
__data = (uint8_t*)MALLOC(__len);
274
if (!__data)
275
return -ENOMEM;
276
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 */
283
284
/* final pad */
285
PAD(__pos, 8);
286
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);
293
}
294
295
FREE(__data);
296
return __ret;
297
}
298
299
struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header)
300
{
301
uint32_t len = 0;
302
uint32_t pos = 0;
303
uint8_t *data = NULL;
304
struct rbug_proto_shader_list *ret;
305
306
if (!header)
307
return NULL;
308
if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST)
309
return NULL;
310
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;
317
318
ret->header.__message = header;
319
ret->header.opcode = header->opcode;
320
321
READ(8, rbug_context_t, context); /* context */
322
323
return ret;
324
}
325
326
struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header)
327
{
328
uint32_t len = 0;
329
uint32_t pos = 0;
330
uint8_t *data = NULL;
331
struct rbug_proto_shader_info *ret;
332
333
if (!header)
334
return NULL;
335
if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO)
336
return NULL;
337
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;
344
345
ret->header.__message = header;
346
ret->header.opcode = header->opcode;
347
348
READ(8, rbug_context_t, context); /* context */
349
READ(8, rbug_shader_t, shader); /* shader */
350
351
return ret;
352
}
353
354
struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header)
355
{
356
uint32_t len = 0;
357
uint32_t pos = 0;
358
uint8_t *data = NULL;
359
struct rbug_proto_shader_disable *ret;
360
361
if (!header)
362
return NULL;
363
if (header->opcode != (int32_t)RBUG_OP_SHADER_DISABLE)
364
return NULL;
365
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;
372
373
ret->header.__message = header;
374
ret->header.opcode = header->opcode;
375
376
READ(8, rbug_context_t, context); /* context */
377
READ(8, rbug_shader_t, shader); /* shader */
378
READ(1, uint8_t, disable); /* disable */
379
380
return ret;
381
}
382
383
struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header)
384
{
385
uint32_t len = 0;
386
uint32_t pos = 0;
387
uint8_t *data = NULL;
388
struct rbug_proto_shader_replace *ret;
389
390
if (!header)
391
return NULL;
392
if (header->opcode != (int32_t)RBUG_OP_SHADER_REPLACE)
393
return NULL;
394
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;
401
402
ret->header.__message = header;
403
ret->header.opcode = header->opcode;
404
405
READ(8, rbug_context_t, context); /* context */
406
READ(8, rbug_shader_t, shader); /* shader */
407
READ_ARRAY(4, uint32_t, tokens); /* tokens */
408
409
return ret;
410
}
411
412
struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header)
413
{
414
uint32_t len = 0;
415
uint32_t pos = 0;
416
uint8_t *data = NULL;
417
struct rbug_proto_shader_list_reply *ret;
418
419
if (!header)
420
return NULL;
421
if (header->opcode != (int32_t)RBUG_OP_SHADER_LIST_REPLY)
422
return NULL;
423
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;
430
431
ret->header.__message = header;
432
ret->header.opcode = header->opcode;
433
434
READ(4, uint32_t, serial); /* serial */
435
READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */
436
437
return ret;
438
}
439
440
struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header)
441
{
442
uint32_t len = 0;
443
uint32_t pos = 0;
444
uint8_t *data = NULL;
445
struct rbug_proto_shader_info_reply *ret;
446
447
if (!header)
448
return NULL;
449
if (header->opcode != (int32_t)RBUG_OP_SHADER_INFO_REPLY)
450
return NULL;
451
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;
458
459
ret->header.__message = header;
460
ret->header.opcode = header->opcode;
461
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 */
466
467
return ret;
468
}
469
470