Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

gen6_constant_state.c 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /*
  2. * Copyright © 2015 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. */
  23. #include "brw_context.h"
  24. #include "brw_state.h"
  25. #include "brw_defines.h"
  26. #include "intel_batchbuffer.h"
  27. #include "intel_buffer_objects.h"
  28. #include "program/prog_parameter.h"
  29. void
  30. brw_populate_constant_data(struct brw_context *brw,
  31. const struct gl_program *prog,
  32. const struct brw_stage_prog_data *prog_data,
  33. void *void_dst,
  34. const union gl_constant_value **param,
  35. unsigned nr_params)
  36. {
  37. gl_constant_value *dst = void_dst;
  38. for (unsigned i = 0; i < nr_params; i++)
  39. dst[i] = *param[i];
  40. }
  41. /**
  42. * Creates a streamed BO containing the push constants for the VS or GS on
  43. * gen6+.
  44. *
  45. * Push constants are constant values (such as GLSL uniforms) that are
  46. * pre-loaded into a shader stage's register space at thread spawn time.
  47. *
  48. * Not all GLSL uniforms will be uploaded as push constants: The hardware has
  49. * a limitation of 32 or 64 EU registers (256 or 512 floats) per stage to be
  50. * uploaded as push constants, while GL 4.4 requires at least 1024 components
  51. * to be usable for the VS. Plus, currently we always use pull constants
  52. * instead of push constants when doing variable-index array access.
  53. *
  54. * See brw_curbe.c for the equivalent gen4/5 code.
  55. */
  56. void
  57. gen6_upload_push_constants(struct brw_context *brw,
  58. const struct gl_program *prog,
  59. const struct brw_stage_prog_data *prog_data,
  60. struct brw_stage_state *stage_state)
  61. {
  62. const struct gen_device_info *devinfo = &brw->screen->devinfo;
  63. struct gl_context *ctx = &brw->ctx;
  64. if (prog_data->nr_params == 0) {
  65. stage_state->push_const_size = 0;
  66. } else {
  67. /* Updates the ParamaterValues[i] pointers for all parameters of the
  68. * basic type of PROGRAM_STATE_VAR.
  69. */
  70. /* XXX: Should this happen somewhere before to get our state flag set? */
  71. if (prog)
  72. _mesa_load_state_parameters(ctx, prog->Parameters);
  73. int i;
  74. const int size = prog_data->nr_params * sizeof(gl_constant_value);
  75. gl_constant_value *param;
  76. if (devinfo->gen >= 8 || devinfo->is_haswell) {
  77. param = intel_upload_space(brw, size, 32,
  78. &stage_state->push_const_bo,
  79. &stage_state->push_const_offset);
  80. } else {
  81. param = brw_state_batch(brw, size, 32,
  82. &stage_state->push_const_offset);
  83. }
  84. STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
  85. /* _NEW_PROGRAM_CONSTANTS
  86. *
  87. * Also _NEW_TRANSFORM -- we may reference clip planes other than as a
  88. * side effect of dereferencing uniforms, so _NEW_PROGRAM_CONSTANTS
  89. * wouldn't be set for them.
  90. */
  91. brw_populate_constant_data(brw, prog, prog_data, param,
  92. prog_data->param,
  93. prog_data->nr_params);
  94. if (0) {
  95. fprintf(stderr, "%s constants:\n",
  96. _mesa_shader_stage_to_string(stage_state->stage));
  97. for (i = 0; i < prog_data->nr_params; i++) {
  98. if ((i & 7) == 0)
  99. fprintf(stderr, "g%d: ",
  100. prog_data->dispatch_grf_start_reg + i / 8);
  101. fprintf(stderr, "%8f ", param[i].f);
  102. if ((i & 7) == 7)
  103. fprintf(stderr, "\n");
  104. }
  105. if ((i & 7) != 0)
  106. fprintf(stderr, "\n");
  107. fprintf(stderr, "\n");
  108. }
  109. stage_state->push_const_size = ALIGN(prog_data->nr_params, 8) / 8;
  110. /* We can only push 32 registers of constants at a time. */
  111. /* From the SNB PRM (vol2, part 1, section 3.2.1.4: 3DSTATE_CONSTANT_VS:
  112. *
  113. * "The sum of all four read length fields (each incremented to
  114. * represent the actual read length) must be less than or equal to
  115. * 32"
  116. *
  117. * From the IVB PRM (vol2, part 1, section 3.2.1.3: 3DSTATE_CONSTANT_VS:
  118. *
  119. * "The sum of all four read length fields must be less than or
  120. * equal to the size of 64"
  121. *
  122. * The other shader stages all match the VS's limits.
  123. */
  124. assert(stage_state->push_const_size <= 32);
  125. }
  126. stage_state->push_constants_dirty = true;
  127. }
  128. /**
  129. * Creates a temporary BO containing the pull constant data for the shader
  130. * stage, and the SURFACE_STATE struct that points at it.
  131. *
  132. * Pull constants are GLSL uniforms (and other constant data) beyond what we
  133. * could fit as push constants, or that have variable-index array access
  134. * (which is easiest to support using pull constants, and avoids filling
  135. * register space with mostly-unused data).
  136. *
  137. * Compare this path to brw_curbe.c for gen4/5 push constants, and
  138. * gen6_vs_state.c for gen6+ push constants.
  139. */
  140. void
  141. brw_upload_pull_constants(struct brw_context *brw,
  142. GLbitfield64 brw_new_constbuf,
  143. const struct gl_program *prog,
  144. struct brw_stage_state *stage_state,
  145. const struct brw_stage_prog_data *prog_data)
  146. {
  147. unsigned i;
  148. uint32_t surf_index = prog_data->binding_table.pull_constants_start;
  149. if (!prog_data->nr_pull_params) {
  150. if (stage_state->surf_offset[surf_index]) {
  151. stage_state->surf_offset[surf_index] = 0;
  152. brw->ctx.NewDriverState |= brw_new_constbuf;
  153. }
  154. return;
  155. }
  156. /* Updates the ParamaterValues[i] pointers for all parameters of the
  157. * basic type of PROGRAM_STATE_VAR.
  158. */
  159. _mesa_load_state_parameters(&brw->ctx, prog->Parameters);
  160. /* BRW_NEW_*_PROG_DATA | _NEW_PROGRAM_CONSTANTS */
  161. uint32_t size = prog_data->nr_pull_params * 4;
  162. struct brw_bo *const_bo = NULL;
  163. uint32_t const_offset;
  164. gl_constant_value *constants = intel_upload_space(brw, size, 64,
  165. &const_bo, &const_offset);
  166. STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
  167. brw_populate_constant_data(brw, prog, prog_data, constants,
  168. prog_data->pull_param,
  169. prog_data->nr_pull_params);
  170. if (0) {
  171. for (i = 0; i < ALIGN(prog_data->nr_pull_params, 4) / 4; i++) {
  172. const gl_constant_value *row = &constants[i * 4];
  173. fprintf(stderr, "const surface %3d: %4.3f %4.3f %4.3f %4.3f\n",
  174. i, row[0].f, row[1].f, row[2].f, row[3].f);
  175. }
  176. }
  177. brw_create_constant_surface(brw, const_bo, const_offset, size,
  178. &stage_state->surf_offset[surf_index]);
  179. brw_bo_unreference(const_bo);
  180. brw->ctx.NewDriverState |= brw_new_constbuf;
  181. }
  182. /**
  183. * Creates a region containing the push constants for the CS on gen7+.
  184. *
  185. * Push constants are constant values (such as GLSL uniforms) that are
  186. * pre-loaded into a shader stage's register space at thread spawn time.
  187. *
  188. * For other stages, see brw_curbe.c:brw_upload_constant_buffer for the
  189. * equivalent gen4/5 code and gen6_vs_state.c:gen6_upload_push_constants for
  190. * gen6+.
  191. */
  192. void
  193. brw_upload_cs_push_constants(struct brw_context *brw,
  194. const struct gl_program *prog,
  195. const struct brw_cs_prog_data *cs_prog_data,
  196. struct brw_stage_state *stage_state)
  197. {
  198. struct gl_context *ctx = &brw->ctx;
  199. const struct brw_stage_prog_data *prog_data =
  200. (struct brw_stage_prog_data*) cs_prog_data;
  201. /* Updates the ParamaterValues[i] pointers for all parameters of the
  202. * basic type of PROGRAM_STATE_VAR.
  203. */
  204. /* XXX: Should this happen somewhere before to get our state flag set? */
  205. _mesa_load_state_parameters(ctx, prog->Parameters);
  206. if (cs_prog_data->push.total.size == 0) {
  207. stage_state->push_const_size = 0;
  208. return;
  209. }
  210. gl_constant_value *param = (gl_constant_value*)
  211. brw_state_batch(brw, ALIGN(cs_prog_data->push.total.size, 64),
  212. 64, &stage_state->push_const_offset);
  213. assert(param);
  214. STATIC_ASSERT(sizeof(gl_constant_value) == sizeof(float));
  215. if (cs_prog_data->push.cross_thread.size > 0) {
  216. gl_constant_value *param_copy = param;
  217. assert(cs_prog_data->thread_local_id_index < 0 ||
  218. cs_prog_data->thread_local_id_index >=
  219. cs_prog_data->push.cross_thread.dwords);
  220. for (unsigned i = 0;
  221. i < cs_prog_data->push.cross_thread.dwords;
  222. i++) {
  223. param_copy[i] = *prog_data->param[i];
  224. }
  225. }
  226. gl_constant_value thread_id;
  227. if (cs_prog_data->push.per_thread.size > 0) {
  228. for (unsigned t = 0; t < cs_prog_data->threads; t++) {
  229. unsigned dst =
  230. 8 * (cs_prog_data->push.per_thread.regs * t +
  231. cs_prog_data->push.cross_thread.regs);
  232. unsigned src = cs_prog_data->push.cross_thread.dwords;
  233. for ( ; src < prog_data->nr_params; src++, dst++) {
  234. if (src != cs_prog_data->thread_local_id_index)
  235. param[dst] = *prog_data->param[src];
  236. else {
  237. thread_id.u = t * cs_prog_data->simd_size;
  238. param[dst] = thread_id;
  239. }
  240. }
  241. }
  242. }
  243. stage_state->push_const_size =
  244. cs_prog_data->push.cross_thread.regs +
  245. cs_prog_data->push.per_thread.regs;
  246. }