Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

rbug_shader.c 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  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. * This file holds the function implementation for one of the rbug extensions.
  26. * Prototypes and declerations of functions and structs is in the same folder
  27. * in the header file matching this file's name.
  28. *
  29. * The functions starting rbug_send_* encodes a call to the write format and
  30. * sends that to the supplied connection, while functions starting with
  31. * rbug_demarshal_* demarshal data in the wire protocol.
  32. *
  33. * Functions ending with _reply are replies to requests.
  34. */
  35. #include "rbug_internal.h"
  36. #include "rbug/rbug_shader.h"
  37. int rbug_send_shader_list(struct rbug_connection *__con,
  38. rbug_context_t context,
  39. uint32_t *__serial)
  40. {
  41. uint32_t __len = 0;
  42. uint32_t __pos = 0;
  43. uint8_t *__data = NULL;
  44. int __ret = 0;
  45. LEN(8); /* header */
  46. LEN(8); /* context */
  47. /* align */
  48. PAD(__len, 8);
  49. __data = (uint8_t*)MALLOC(__len);
  50. if (!__data)
  51. return -ENOMEM;
  52. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST));
  53. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  54. WRITE(8, rbug_context_t, context); /* context */
  55. /* final pad */
  56. PAD(__pos, 8);
  57. if (__pos != __len) {
  58. __ret = -EINVAL;
  59. } else {
  60. rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST, __len);
  61. rbug_connection_write(__con, __data, __len);
  62. __ret = rbug_connection_send_finish(__con, __serial);
  63. }
  64. FREE(__data);
  65. return __ret;
  66. }
  67. int rbug_send_shader_info(struct rbug_connection *__con,
  68. rbug_context_t context,
  69. rbug_shader_t shader,
  70. uint32_t *__serial)
  71. {
  72. uint32_t __len = 0;
  73. uint32_t __pos = 0;
  74. uint8_t *__data = NULL;
  75. int __ret = 0;
  76. LEN(8); /* header */
  77. LEN(8); /* context */
  78. LEN(8); /* shader */
  79. /* align */
  80. PAD(__len, 8);
  81. __data = (uint8_t*)MALLOC(__len);
  82. if (!__data)
  83. return -ENOMEM;
  84. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO));
  85. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  86. WRITE(8, rbug_context_t, context); /* context */
  87. WRITE(8, rbug_shader_t, shader); /* shader */
  88. /* final pad */
  89. PAD(__pos, 8);
  90. if (__pos != __len) {
  91. __ret = -EINVAL;
  92. } else {
  93. rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO, __len);
  94. rbug_connection_write(__con, __data, __len);
  95. __ret = rbug_connection_send_finish(__con, __serial);
  96. }
  97. FREE(__data);
  98. return __ret;
  99. }
  100. int rbug_send_shader_disable(struct rbug_connection *__con,
  101. rbug_context_t context,
  102. rbug_shader_t shader,
  103. uint8_t disable,
  104. uint32_t *__serial)
  105. {
  106. uint32_t __len = 0;
  107. uint32_t __pos = 0;
  108. uint8_t *__data = NULL;
  109. int __ret = 0;
  110. LEN(8); /* header */
  111. LEN(8); /* context */
  112. LEN(8); /* shader */
  113. LEN(1); /* disable */
  114. /* align */
  115. PAD(__len, 8);
  116. __data = (uint8_t*)MALLOC(__len);
  117. if (!__data)
  118. return -ENOMEM;
  119. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_DISABLE));
  120. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  121. WRITE(8, rbug_context_t, context); /* context */
  122. WRITE(8, rbug_shader_t, shader); /* shader */
  123. WRITE(1, uint8_t, disable); /* disable */
  124. /* final pad */
  125. PAD(__pos, 8);
  126. if (__pos != __len) {
  127. __ret = -EINVAL;
  128. } else {
  129. rbug_connection_send_start(__con, RBUG_OP_SHADER_DISABLE, __len);
  130. rbug_connection_write(__con, __data, __len);
  131. __ret = rbug_connection_send_finish(__con, __serial);
  132. }
  133. FREE(__data);
  134. return __ret;
  135. }
  136. int rbug_send_shader_replace(struct rbug_connection *__con,
  137. rbug_context_t context,
  138. rbug_shader_t shader,
  139. uint32_t *tokens,
  140. uint32_t tokens_len,
  141. uint32_t *__serial)
  142. {
  143. uint32_t __len = 0;
  144. uint32_t __pos = 0;
  145. uint8_t *__data = NULL;
  146. int __ret = 0;
  147. LEN(8); /* header */
  148. LEN(8); /* context */
  149. LEN(8); /* shader */
  150. LEN_ARRAY(4, tokens); /* tokens */
  151. /* align */
  152. PAD(__len, 8);
  153. __data = (uint8_t*)MALLOC(__len);
  154. if (!__data)
  155. return -ENOMEM;
  156. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_REPLACE));
  157. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  158. WRITE(8, rbug_context_t, context); /* context */
  159. WRITE(8, rbug_shader_t, shader); /* shader */
  160. WRITE_ARRAY(4, uint32_t, tokens); /* tokens */
  161. /* final pad */
  162. PAD(__pos, 8);
  163. if (__pos != __len) {
  164. __ret = -EINVAL;
  165. } else {
  166. rbug_connection_send_start(__con, RBUG_OP_SHADER_REPLACE, __len);
  167. rbug_connection_write(__con, __data, __len);
  168. __ret = rbug_connection_send_finish(__con, __serial);
  169. }
  170. FREE(__data);
  171. return __ret;
  172. }
  173. int rbug_send_shader_list_reply(struct rbug_connection *__con,
  174. uint32_t serial,
  175. rbug_shader_t *shaders,
  176. uint32_t shaders_len,
  177. uint32_t *__serial)
  178. {
  179. uint32_t __len = 0;
  180. uint32_t __pos = 0;
  181. uint8_t *__data = NULL;
  182. int __ret = 0;
  183. LEN(8); /* header */
  184. LEN(4); /* serial */
  185. LEN_ARRAY(8, shaders); /* shaders */
  186. /* align */
  187. PAD(__len, 8);
  188. __data = (uint8_t*)MALLOC(__len);
  189. if (!__data)
  190. return -ENOMEM;
  191. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_LIST_REPLY));
  192. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  193. WRITE(4, uint32_t, serial); /* serial */
  194. WRITE_ARRAY(8, rbug_shader_t, shaders); /* shaders */
  195. /* final pad */
  196. PAD(__pos, 8);
  197. if (__pos != __len) {
  198. __ret = -EINVAL;
  199. } else {
  200. rbug_connection_send_start(__con, RBUG_OP_SHADER_LIST_REPLY, __len);
  201. rbug_connection_write(__con, __data, __len);
  202. __ret = rbug_connection_send_finish(__con, __serial);
  203. }
  204. FREE(__data);
  205. return __ret;
  206. }
  207. int rbug_send_shader_info_reply(struct rbug_connection *__con,
  208. uint32_t serial,
  209. uint32_t *original,
  210. uint32_t original_len,
  211. uint32_t *replaced,
  212. uint32_t replaced_len,
  213. uint8_t disabled,
  214. uint32_t *__serial)
  215. {
  216. uint32_t __len = 0;
  217. uint32_t __pos = 0;
  218. uint8_t *__data = NULL;
  219. int __ret = 0;
  220. LEN(8); /* header */
  221. LEN(4); /* serial */
  222. LEN_ARRAY(4, original); /* original */
  223. LEN_ARRAY(4, replaced); /* replaced */
  224. LEN(1); /* disabled */
  225. /* align */
  226. PAD(__len, 8);
  227. __data = (uint8_t*)MALLOC(__len);
  228. if (!__data)
  229. return -ENOMEM;
  230. WRITE(4, int32_t, ((int32_t)RBUG_OP_SHADER_INFO_REPLY));
  231. WRITE(4, uint32_t, ((uint32_t)(__len / 4)));
  232. WRITE(4, uint32_t, serial); /* serial */
  233. WRITE_ARRAY(4, uint32_t, original); /* original */
  234. WRITE_ARRAY(4, uint32_t, replaced); /* replaced */
  235. WRITE(1, uint8_t, disabled); /* disabled */
  236. /* final pad */
  237. PAD(__pos, 8);
  238. if (__pos != __len) {
  239. __ret = -EINVAL;
  240. } else {
  241. rbug_connection_send_start(__con, RBUG_OP_SHADER_INFO_REPLY, __len);
  242. rbug_connection_write(__con, __data, __len);
  243. __ret = rbug_connection_send_finish(__con, __serial);
  244. }
  245. FREE(__data);
  246. return __ret;
  247. }
  248. struct rbug_proto_shader_list * rbug_demarshal_shader_list(struct rbug_proto_header *header)
  249. {
  250. uint32_t len = 0;
  251. uint32_t pos = 0;
  252. uint8_t *data = NULL;
  253. struct rbug_proto_shader_list *ret;
  254. if (!header)
  255. return NULL;
  256. if (header->opcode != (int16_t)RBUG_OP_SHADER_LIST)
  257. return NULL;
  258. pos = 0;
  259. len = header->length * 4;
  260. data = (uint8_t*)&header[1];
  261. ret = MALLOC(sizeof(*ret));
  262. if (!ret)
  263. return NULL;
  264. ret->header.__message = header;
  265. ret->header.opcode = header->opcode;
  266. READ(8, rbug_context_t, context); /* context */
  267. return ret;
  268. }
  269. struct rbug_proto_shader_info * rbug_demarshal_shader_info(struct rbug_proto_header *header)
  270. {
  271. uint32_t len = 0;
  272. uint32_t pos = 0;
  273. uint8_t *data = NULL;
  274. struct rbug_proto_shader_info *ret;
  275. if (!header)
  276. return NULL;
  277. if (header->opcode != (int16_t)RBUG_OP_SHADER_INFO)
  278. return NULL;
  279. pos = 0;
  280. len = header->length * 4;
  281. data = (uint8_t*)&header[1];
  282. ret = MALLOC(sizeof(*ret));
  283. if (!ret)
  284. return NULL;
  285. ret->header.__message = header;
  286. ret->header.opcode = header->opcode;
  287. READ(8, rbug_context_t, context); /* context */
  288. READ(8, rbug_shader_t, shader); /* shader */
  289. return ret;
  290. }
  291. struct rbug_proto_shader_disable * rbug_demarshal_shader_disable(struct rbug_proto_header *header)
  292. {
  293. uint32_t len = 0;
  294. uint32_t pos = 0;
  295. uint8_t *data = NULL;
  296. struct rbug_proto_shader_disable *ret;
  297. if (!header)
  298. return NULL;
  299. if (header->opcode != (int16_t)RBUG_OP_SHADER_DISABLE)
  300. return NULL;
  301. pos = 0;
  302. len = header->length * 4;
  303. data = (uint8_t*)&header[1];
  304. ret = MALLOC(sizeof(*ret));
  305. if (!ret)
  306. return NULL;
  307. ret->header.__message = header;
  308. ret->header.opcode = header->opcode;
  309. READ(8, rbug_context_t, context); /* context */
  310. READ(8, rbug_shader_t, shader); /* shader */
  311. READ(1, uint8_t, disable); /* disable */
  312. return ret;
  313. }
  314. struct rbug_proto_shader_replace * rbug_demarshal_shader_replace(struct rbug_proto_header *header)
  315. {
  316. uint32_t len = 0;
  317. uint32_t pos = 0;
  318. uint8_t *data = NULL;
  319. struct rbug_proto_shader_replace *ret;
  320. if (!header)
  321. return NULL;
  322. if (header->opcode != (int16_t)RBUG_OP_SHADER_REPLACE)
  323. return NULL;
  324. pos = 0;
  325. len = header->length * 4;
  326. data = (uint8_t*)&header[1];
  327. ret = MALLOC(sizeof(*ret));
  328. if (!ret)
  329. return NULL;
  330. ret->header.__message = header;
  331. ret->header.opcode = header->opcode;
  332. READ(8, rbug_context_t, context); /* context */
  333. READ(8, rbug_shader_t, shader); /* shader */
  334. READ_ARRAY(4, uint32_t, tokens); /* tokens */
  335. return ret;
  336. }
  337. struct rbug_proto_shader_list_reply * rbug_demarshal_shader_list_reply(struct rbug_proto_header *header)
  338. {
  339. uint32_t len = 0;
  340. uint32_t pos = 0;
  341. uint8_t *data = NULL;
  342. struct rbug_proto_shader_list_reply *ret;
  343. if (!header)
  344. return NULL;
  345. if (header->opcode != (int16_t)RBUG_OP_SHADER_LIST_REPLY)
  346. return NULL;
  347. pos = 0;
  348. len = header->length * 4;
  349. data = (uint8_t*)&header[1];
  350. ret = MALLOC(sizeof(*ret));
  351. if (!ret)
  352. return NULL;
  353. ret->header.__message = header;
  354. ret->header.opcode = header->opcode;
  355. READ(4, uint32_t, serial); /* serial */
  356. READ_ARRAY(8, rbug_shader_t, shaders); /* shaders */
  357. return ret;
  358. }
  359. struct rbug_proto_shader_info_reply * rbug_demarshal_shader_info_reply(struct rbug_proto_header *header)
  360. {
  361. uint32_t len = 0;
  362. uint32_t pos = 0;
  363. uint8_t *data = NULL;
  364. struct rbug_proto_shader_info_reply *ret;
  365. if (!header)
  366. return NULL;
  367. if (header->opcode != (int16_t)RBUG_OP_SHADER_INFO_REPLY)
  368. return NULL;
  369. pos = 0;
  370. len = header->length * 4;
  371. data = (uint8_t*)&header[1];
  372. ret = MALLOC(sizeof(*ret));
  373. if (!ret)
  374. return NULL;
  375. ret->header.__message = header;
  376. ret->header.opcode = header->opcode;
  377. READ(4, uint32_t, serial); /* serial */
  378. READ_ARRAY(4, uint32_t, original); /* original */
  379. READ_ARRAY(4, uint32_t, replaced); /* replaced */
  380. READ(1, uint8_t, disabled); /* disabled */
  381. return ret;
  382. }