Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vl_shader_build.c 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**************************************************************************
  2. *
  3. * Copyright 2009 Younes Manton.
  4. * All Rights Reserved.
  5. *
  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:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  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 TUNGSTEN GRAPHICS 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.
  25. *
  26. **************************************************************************/
  27. #include "vl_shader_build.h"
  28. #include <assert.h>
  29. #include <tgsi/tgsi_parse.h>
  30. #include <tgsi/tgsi_build.h>
  31. struct tgsi_full_declaration vl_decl_input(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
  32. {
  33. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  34. decl.Declaration.File = TGSI_FILE_INPUT;
  35. decl.Declaration.Semantic = 1;
  36. decl.Semantic.Name = name;
  37. decl.Semantic.Index = index;
  38. decl.DeclarationRange.First = first;
  39. decl.DeclarationRange.Last = last;
  40. return decl;
  41. }
  42. struct tgsi_full_declaration vl_decl_interpolated_input
  43. (
  44. unsigned int name,
  45. unsigned int index,
  46. unsigned int first,
  47. unsigned int last,
  48. int interpolation
  49. )
  50. {
  51. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  52. assert
  53. (
  54. interpolation == TGSI_INTERPOLATE_CONSTANT ||
  55. interpolation == TGSI_INTERPOLATE_LINEAR ||
  56. interpolation == TGSI_INTERPOLATE_PERSPECTIVE
  57. );
  58. decl.Declaration.File = TGSI_FILE_INPUT;
  59. decl.Declaration.Semantic = 1;
  60. decl.Semantic.Name = name;
  61. decl.Semantic.Index = index;
  62. decl.Declaration.Interpolate = interpolation;;
  63. decl.DeclarationRange.First = first;
  64. decl.DeclarationRange.Last = last;
  65. return decl;
  66. }
  67. struct tgsi_full_declaration vl_decl_constants(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
  68. {
  69. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  70. decl.Declaration.File = TGSI_FILE_CONSTANT;
  71. decl.Declaration.Semantic = 1;
  72. decl.Semantic.Name = name;
  73. decl.Semantic.Index = index;
  74. decl.DeclarationRange.First = first;
  75. decl.DeclarationRange.Last = last;
  76. return decl;
  77. }
  78. struct tgsi_full_declaration vl_decl_output(unsigned int name, unsigned int index, unsigned int first, unsigned int last)
  79. {
  80. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  81. decl.Declaration.File = TGSI_FILE_OUTPUT;
  82. decl.Declaration.Semantic = 1;
  83. decl.Semantic.Name = name;
  84. decl.Semantic.Index = index;
  85. decl.DeclarationRange.First = first;
  86. decl.DeclarationRange.Last = last;
  87. return decl;
  88. }
  89. struct tgsi_full_declaration vl_decl_temps(unsigned int first, unsigned int last)
  90. {
  91. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  92. decl = tgsi_default_full_declaration();
  93. decl.Declaration.File = TGSI_FILE_TEMPORARY;
  94. decl.DeclarationRange.First = first;
  95. decl.DeclarationRange.Last = last;
  96. return decl;
  97. }
  98. struct tgsi_full_declaration vl_decl_samplers(unsigned int first, unsigned int last)
  99. {
  100. struct tgsi_full_declaration decl = tgsi_default_full_declaration();
  101. decl = tgsi_default_full_declaration();
  102. decl.Declaration.File = TGSI_FILE_SAMPLER;
  103. decl.DeclarationRange.First = first;
  104. decl.DeclarationRange.Last = last;
  105. return decl;
  106. }
  107. struct tgsi_full_instruction vl_inst2
  108. (
  109. int opcode,
  110. enum tgsi_file_type dst_file,
  111. unsigned int dst_index,
  112. enum tgsi_file_type src_file,
  113. unsigned int src_index
  114. )
  115. {
  116. struct tgsi_full_instruction inst = tgsi_default_full_instruction();
  117. inst.Instruction.Opcode = opcode;
  118. inst.Instruction.NumDstRegs = 1;
  119. inst.FullDstRegisters[0].DstRegister.File = dst_file;
  120. inst.FullDstRegisters[0].DstRegister.Index = dst_index;
  121. inst.Instruction.NumSrcRegs = 1;
  122. inst.FullSrcRegisters[0].SrcRegister.File = src_file;
  123. inst.FullSrcRegisters[0].SrcRegister.Index = src_index;
  124. return inst;
  125. }
  126. struct tgsi_full_instruction vl_inst3
  127. (
  128. int opcode,
  129. enum tgsi_file_type dst_file,
  130. unsigned int dst_index,
  131. enum tgsi_file_type src1_file,
  132. unsigned int src1_index,
  133. enum tgsi_file_type src2_file,
  134. unsigned int src2_index
  135. )
  136. {
  137. struct tgsi_full_instruction inst = tgsi_default_full_instruction();
  138. inst.Instruction.Opcode = opcode;
  139. inst.Instruction.NumDstRegs = 1;
  140. inst.FullDstRegisters[0].DstRegister.File = dst_file;
  141. inst.FullDstRegisters[0].DstRegister.Index = dst_index;
  142. inst.Instruction.NumSrcRegs = 2;
  143. inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
  144. inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
  145. inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
  146. inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
  147. return inst;
  148. }
  149. struct tgsi_full_instruction vl_tex
  150. (
  151. int tex,
  152. enum tgsi_file_type dst_file,
  153. unsigned int dst_index,
  154. enum tgsi_file_type src1_file,
  155. unsigned int src1_index,
  156. enum tgsi_file_type src2_file,
  157. unsigned int src2_index
  158. )
  159. {
  160. struct tgsi_full_instruction inst = tgsi_default_full_instruction();
  161. inst.Instruction.Opcode = TGSI_OPCODE_TEX;
  162. inst.Instruction.NumDstRegs = 1;
  163. inst.FullDstRegisters[0].DstRegister.File = dst_file;
  164. inst.FullDstRegisters[0].DstRegister.Index = dst_index;
  165. inst.Instruction.NumSrcRegs = 2;
  166. inst.Instruction.Texture = 1;
  167. inst.InstructionTexture.Texture = tex;
  168. inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
  169. inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
  170. inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
  171. inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
  172. return inst;
  173. }
  174. struct tgsi_full_instruction vl_inst4
  175. (
  176. int opcode,
  177. enum tgsi_file_type dst_file,
  178. unsigned int dst_index,
  179. enum tgsi_file_type src1_file,
  180. unsigned int src1_index,
  181. enum tgsi_file_type src2_file,
  182. unsigned int src2_index,
  183. enum tgsi_file_type src3_file,
  184. unsigned int src3_index
  185. )
  186. {
  187. struct tgsi_full_instruction inst = tgsi_default_full_instruction();
  188. inst.Instruction.Opcode = opcode;
  189. inst.Instruction.NumDstRegs = 1;
  190. inst.FullDstRegisters[0].DstRegister.File = dst_file;
  191. inst.FullDstRegisters[0].DstRegister.Index = dst_index;
  192. inst.Instruction.NumSrcRegs = 3;
  193. inst.FullSrcRegisters[0].SrcRegister.File = src1_file;
  194. inst.FullSrcRegisters[0].SrcRegister.Index = src1_index;
  195. inst.FullSrcRegisters[1].SrcRegister.File = src2_file;
  196. inst.FullSrcRegisters[1].SrcRegister.Index = src2_index;
  197. inst.FullSrcRegisters[2].SrcRegister.File = src3_file;
  198. inst.FullSrcRegisters[2].SrcRegister.Index = src3_index;
  199. return inst;
  200. }
  201. struct tgsi_full_instruction vl_end(void)
  202. {
  203. struct tgsi_full_instruction inst = tgsi_default_full_instruction();
  204. inst.Instruction.Opcode = TGSI_OPCODE_END;
  205. inst.Instruction.NumDstRegs = 0;
  206. inst.Instruction.NumSrcRegs = 0;
  207. return inst;
  208. }