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.

st_atom_constbuf.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**************************************************************************
  2. *
  3. * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
  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. /*
  28. * Authors:
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. * Brian Paul
  31. */
  32. #include "main/imports.h"
  33. #include "shader/prog_parameter.h"
  34. #include "shader/prog_print.h"
  35. #include "pipe/p_context.h"
  36. #include "pipe/p_defines.h"
  37. #include "pipe/p_inlines.h"
  38. #include "st_context.h"
  39. #include "st_atom.h"
  40. #include "st_atom_constbuf.h"
  41. #include "st_program.h"
  42. #include "st_inlines.h"
  43. /**
  44. * Pass the given program parameters to the graphics pipe as a
  45. * constant buffer.
  46. * \param shader_type either PIPE_SHADER_VERTEX or PIPE_SHADER_FRAGMENT
  47. */
  48. void st_upload_constants( struct st_context *st,
  49. struct gl_program_parameter_list *params,
  50. unsigned shader_type)
  51. {
  52. struct pipe_context *pipe = st->pipe;
  53. struct pipe_constant_buffer *cbuf = &st->state.constants[shader_type];
  54. assert(shader_type == PIPE_SHADER_VERTEX ||
  55. shader_type == PIPE_SHADER_FRAGMENT);
  56. /* update constants */
  57. if (params && params->NumParameters) {
  58. const uint paramBytes = params->NumParameters * sizeof(GLfloat) * 4;
  59. _mesa_load_state_parameters(st->ctx, params);
  60. /* We always need to get a new buffer, to keep the drivers simple and
  61. * avoid gratuitous rendering synchronization.
  62. */
  63. pipe_buffer_reference(&cbuf->buffer, NULL );
  64. cbuf->buffer = pipe_buffer_create(pipe->screen, 16,
  65. PIPE_BUFFER_USAGE_CONSTANT,
  66. paramBytes );
  67. if (0) {
  68. debug_printf("%s(shader=%d, numParams=%d, stateFlags=0x%x)\n",
  69. __FUNCTION__, shader_type, params->NumParameters,
  70. params->StateFlags);
  71. _mesa_print_parameter_list(params);
  72. }
  73. /* load Mesa constants into the constant buffer */
  74. if (cbuf->buffer)
  75. st_no_flush_pipe_buffer_write(st, cbuf->buffer,
  76. 0, paramBytes,
  77. params->ParameterValues);
  78. st->pipe->set_constant_buffer(st->pipe, shader_type, 0, cbuf);
  79. }
  80. else {
  81. st->constants.tracked_state[shader_type].dirty.mesa = 0x0;
  82. }
  83. }
  84. /**
  85. * Vertex shader:
  86. */
  87. static void update_vs_constants(struct st_context *st )
  88. {
  89. struct st_vertex_program *vp = st->vp;
  90. struct gl_program_parameter_list *params = vp->Base.Base.Parameters;
  91. st_upload_constants( st, params, PIPE_SHADER_VERTEX );
  92. }
  93. const struct st_tracked_state st_update_vs_constants = {
  94. "st_update_vs_constants", /* name */
  95. { /* dirty */
  96. (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS), /* mesa */
  97. ST_NEW_VERTEX_PROGRAM, /* st */
  98. },
  99. update_vs_constants /* update */
  100. };
  101. /**
  102. * Fragment shader:
  103. */
  104. static void update_fs_constants(struct st_context *st )
  105. {
  106. struct st_fragment_program *fp = st->fp;
  107. struct gl_program_parameter_list *params = fp->Base.Base.Parameters;
  108. st_upload_constants( st, params, PIPE_SHADER_FRAGMENT );
  109. }
  110. const struct st_tracked_state st_update_fs_constants = {
  111. "st_update_fs_constants", /* name */
  112. { /* dirty */
  113. (_NEW_PROGRAM | _NEW_PROGRAM_CONSTANTS), /* mesa */
  114. ST_NEW_FRAGMENT_PROGRAM, /* st */
  115. },
  116. update_fs_constants /* update */
  117. };