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.

svga_pipe_vs.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /**********************************************************
  2. * Copyright 2008-2009 VMware, Inc. All rights reserved.
  3. *
  4. * Permission is hereby granted, free of charge, to any person
  5. * obtaining a copy of this software and associated documentation
  6. * files (the "Software"), to deal in the Software without
  7. * restriction, including without limitation the rights to use, copy,
  8. * modify, merge, publish, distribute, sublicense, and/or sell copies
  9. * of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be
  13. * included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  19. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  20. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. *
  24. **********************************************************/
  25. #include "draw/draw_context.h"
  26. #include "pipe/p_inlines.h"
  27. #include "util/u_math.h"
  28. #include "util/u_memory.h"
  29. #include "util/u_bitmask.h"
  30. #include "tgsi/tgsi_parse.h"
  31. #include "tgsi/tgsi_text.h"
  32. #include "svga_screen.h"
  33. #include "svga_context.h"
  34. #include "svga_state.h"
  35. #include "svga_tgsi.h"
  36. #include "svga_hw_reg.h"
  37. #include "svga_cmd.h"
  38. #include "svga_debug.h"
  39. static const struct tgsi_token *substitute_vs(
  40. unsigned shader_id,
  41. const struct tgsi_token *old_tokens )
  42. {
  43. #if 0
  44. if (shader_id == 12) {
  45. static struct tgsi_token tokens[300];
  46. const char *text =
  47. "VERT1.1\n"
  48. "DCL IN[0]\n"
  49. "DCL IN[1]\n"
  50. "DCL IN[2]\n"
  51. "DCL OUT[0], POSITION\n"
  52. "DCL TEMP[0..4]\n"
  53. "IMM FLT32 { 1.0000, 1.0000, 1.0000, 1.0000 }\n"
  54. "IMM FLT32 { 0.45, 1.0000, 1.0000, 1.0000 }\n"
  55. "IMM FLT32 { 1.297863, 0.039245, 0.035993, 0.035976}\n"
  56. "IMM FLT32 { -0.019398, 1.696131, -0.202151, -0.202050 }\n"
  57. "IMM FLT32 { 0.051711, -0.348713, -0.979204, -0.978714 }\n"
  58. "IMM FLT32 { 0.000000, 0.000003, 139.491577, 141.421356 }\n"
  59. "DCL CONST[0..7]\n"
  60. "DCL CONST[9..16]\n"
  61. " MOV TEMP[2], IMM[0]\n"
  62. " MOV TEMP[2].xyz, IN[2]\n"
  63. " MOV TEMP[2].xyz, IN[0]\n"
  64. " MOV TEMP[2].xyz, IN[1]\n"
  65. " MUL TEMP[1], IMM[3], TEMP[2].yyyy\n"
  66. " MAD TEMP[3], IMM[2], TEMP[2].xxxx, TEMP[1]\n"
  67. " MAD TEMP[1], IMM[4], TEMP[2].zzzz, TEMP[3]\n"
  68. " MAD TEMP[4], IMM[5], TEMP[2].wwww, TEMP[1]\n"
  69. " MOV OUT[0], TEMP[4]\n"
  70. " END\n";
  71. if (!tgsi_text_translate( text,
  72. tokens,
  73. Elements(tokens) ))
  74. {
  75. assert(0);
  76. return NULL;
  77. }
  78. return tokens;
  79. }
  80. #endif
  81. return old_tokens;
  82. }
  83. /***********************************************************************
  84. * Vertex shaders
  85. */
  86. static void *
  87. svga_create_vs_state(struct pipe_context *pipe,
  88. const struct pipe_shader_state *templ)
  89. {
  90. struct svga_context *svga = svga_context(pipe);
  91. struct svga_screen *svgascreen = svga_screen(pipe->screen);
  92. struct svga_vertex_shader *vs = CALLOC_STRUCT(svga_vertex_shader);
  93. if (!vs)
  94. return NULL;
  95. /* substitute a debug shader?
  96. */
  97. vs->base.tokens = tgsi_dup_tokens(substitute_vs(svga->debug.shader_id,
  98. templ->tokens));
  99. /* Collect basic info that we'll need later:
  100. */
  101. tgsi_scan_shader(vs->base.tokens, &vs->base.info);
  102. {
  103. /* Need to do construct a new template in case we substitued a
  104. * debug shader.
  105. */
  106. struct pipe_shader_state tmp2 = *templ;
  107. tmp2.tokens = vs->base.tokens;
  108. vs->draw_shader = draw_create_vertex_shader(svga->swtnl.draw, &tmp2);
  109. }
  110. vs->base.id = svga->debug.shader_id++;
  111. vs->base.use_sm30 = svgascreen->use_vs30;
  112. if (SVGA_DEBUG & DEBUG_TGSI || 0) {
  113. debug_printf("%s id: %u, inputs: %u, outputs: %u\n",
  114. __FUNCTION__, vs->base.id,
  115. vs->base.info.num_inputs, vs->base.info.num_outputs);
  116. }
  117. return vs;
  118. }
  119. static void svga_bind_vs_state(struct pipe_context *pipe, void *shader)
  120. {
  121. struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader;
  122. struct svga_context *svga = svga_context(pipe);
  123. svga->curr.vs = vs;
  124. svga->dirty |= SVGA_NEW_VS;
  125. }
  126. static void svga_delete_vs_state(struct pipe_context *pipe, void *shader)
  127. {
  128. struct svga_context *svga = svga_context(pipe);
  129. struct svga_vertex_shader *vs = (struct svga_vertex_shader *)shader;
  130. struct svga_shader_result *result, *tmp;
  131. enum pipe_error ret;
  132. svga_hwtnl_flush_retry( svga );
  133. draw_delete_vertex_shader(svga->swtnl.draw, vs->draw_shader);
  134. for (result = vs->base.results; result; result = tmp ) {
  135. tmp = result->next;
  136. ret = SVGA3D_DestroyShader(svga->swc,
  137. result->id,
  138. SVGA3D_SHADERTYPE_VS );
  139. if(ret != PIPE_OK) {
  140. svga_context_flush(svga, NULL);
  141. ret = SVGA3D_DestroyShader(svga->swc,
  142. result->id,
  143. SVGA3D_SHADERTYPE_VS );
  144. assert(ret == PIPE_OK);
  145. }
  146. util_bitmask_clear( svga->vs_bm, result->id );
  147. svga_destroy_shader_result( result );
  148. /*
  149. * Remove stale references to this result to ensure a new result on the
  150. * same address will be detected as a change.
  151. */
  152. if(result == svga->state.hw_draw.vs)
  153. svga->state.hw_draw.vs = NULL;
  154. }
  155. FREE((void *)vs->base.tokens);
  156. FREE(vs);
  157. }
  158. void svga_init_vs_functions( struct svga_context *svga )
  159. {
  160. svga->pipe.create_vs_state = svga_create_vs_state;
  161. svga->pipe.bind_vs_state = svga_bind_vs_state;
  162. svga->pipe.delete_vs_state = svga_delete_vs_state;
  163. }