Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

sp_quad_fs.c 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  4. * All Rights Reserved.
  5. * Copyright 2008 VMware, Inc. All rights reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sub license, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the
  16. * next paragraph) shall be included in all copies or substantial portions
  17. * of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  21. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  22. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  23. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  24. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  25. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. **************************************************************************/
  28. /* Vertices are just an array of floats, with all the attributes
  29. * packed. We currently assume a layout like:
  30. *
  31. * attr[0][0..3] - window position
  32. * attr[1..n][0..3] - remaining attributes.
  33. *
  34. * Attributes are assumed to be 4 floats wide but are packed so that
  35. * all the enabled attributes run contiguously.
  36. */
  37. #include "util/u_math.h"
  38. #include "util/u_memory.h"
  39. #include "pipe/p_defines.h"
  40. #include "pipe/p_shader_tokens.h"
  41. #include "sp_context.h"
  42. #include "sp_state.h"
  43. #include "sp_quad.h"
  44. #include "sp_quad_pipe.h"
  45. struct quad_shade_stage
  46. {
  47. struct quad_stage stage; /**< base class */
  48. /* no other fields at this time */
  49. };
  50. /** cast wrapper */
  51. static INLINE struct quad_shade_stage *
  52. quad_shade_stage(struct quad_stage *qs)
  53. {
  54. return (struct quad_shade_stage *) qs;
  55. }
  56. /**
  57. * Execute fragment shader for the four fragments in the quad.
  58. * \return TRUE if quad is alive, FALSE if all four pixels are killed
  59. */
  60. static INLINE boolean
  61. shade_quad(struct quad_stage *qs, struct quad_header *quad)
  62. {
  63. struct softpipe_context *softpipe = qs->softpipe;
  64. struct tgsi_exec_machine *machine = softpipe->fs_machine;
  65. if (softpipe->active_statistics_queries) {
  66. softpipe->pipeline_statistics.ps_invocations +=
  67. util_bitcount(quad->inout.mask);
  68. }
  69. /* run shader */
  70. machine->flatshade_color = softpipe->rasterizer->flatshade ? TRUE : FALSE;
  71. return softpipe->fs_variant->run( softpipe->fs_variant, machine, quad );
  72. }
  73. static void
  74. coverage_quad(struct quad_stage *qs, struct quad_header *quad)
  75. {
  76. struct softpipe_context *softpipe = qs->softpipe;
  77. uint cbuf;
  78. /* loop over colorbuffer outputs */
  79. for (cbuf = 0; cbuf < softpipe->framebuffer.nr_cbufs; cbuf++) {
  80. float (*quadColor)[4] = quad->output.color[cbuf];
  81. unsigned j;
  82. for (j = 0; j < TGSI_QUAD_SIZE; j++) {
  83. assert(quad->input.coverage[j] >= 0.0);
  84. assert(quad->input.coverage[j] <= 1.0);
  85. quadColor[3][j] *= quad->input.coverage[j];
  86. }
  87. }
  88. }
  89. /**
  90. * Shade/write an array of quads
  91. * Called via quad_stage::run()
  92. */
  93. static void
  94. shade_quads(struct quad_stage *qs,
  95. struct quad_header *quads[],
  96. unsigned nr)
  97. {
  98. struct softpipe_context *softpipe = qs->softpipe;
  99. struct tgsi_exec_machine *machine = softpipe->fs_machine;
  100. unsigned i, nr_quads = 0;
  101. tgsi_exec_set_constant_buffers(machine, PIPE_MAX_CONSTANT_BUFFERS,
  102. softpipe->mapped_constants[PIPE_SHADER_FRAGMENT],
  103. softpipe->const_buffer_size[PIPE_SHADER_FRAGMENT]);
  104. machine->InterpCoefs = quads[0]->coef;
  105. for (i = 0; i < nr; i++) {
  106. /* Only omit this quad from the output list if all the fragments
  107. * are killed _AND_ it's not the first quad in the list.
  108. * The first quad is special in the (optimized) depth-testing code:
  109. * the quads' Z coordinates are step-wise interpolated with respect
  110. * to the first quad in the list.
  111. * For multi-pass algorithms we need to produce exactly the same
  112. * Z values in each pass. If interpolation starts with different quads
  113. * we can get different Z values for the same (x,y).
  114. */
  115. if (!shade_quad(qs, quads[i]) && i > 0)
  116. continue; /* quad totally culled/killed */
  117. if (/*do_coverage*/ 0)
  118. coverage_quad( qs, quads[i] );
  119. quads[nr_quads++] = quads[i];
  120. }
  121. if (nr_quads)
  122. qs->next->run(qs->next, quads, nr_quads);
  123. }
  124. /**
  125. * Per-primitive (or per-begin?) setup
  126. */
  127. static void
  128. shade_begin(struct quad_stage *qs)
  129. {
  130. qs->next->begin(qs->next);
  131. }
  132. static void
  133. shade_destroy(struct quad_stage *qs)
  134. {
  135. FREE( qs );
  136. }
  137. struct quad_stage *
  138. sp_quad_shade_stage( struct softpipe_context *softpipe )
  139. {
  140. struct quad_shade_stage *qss = CALLOC_STRUCT(quad_shade_stage);
  141. if (!qss)
  142. goto fail;
  143. qss->stage.softpipe = softpipe;
  144. qss->stage.begin = shade_begin;
  145. qss->stage.run = shade_quads;
  146. qss->stage.destroy = shade_destroy;
  147. return &qss->stage;
  148. fail:
  149. FREE(qss);
  150. return NULL;
  151. }