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.

context.rst 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. Context
  2. =======
  3. The context object represents the purest, most directly accessible, abilities
  4. of the device's 3D rendering pipeline.
  5. Methods
  6. -------
  7. CSO State
  8. ^^^^^^^^^
  9. All CSO state is created, bound, and destroyed, with triplets of methods that
  10. all follow a specific naming scheme. For example, ``create_blend_state``,
  11. ``bind_blend_state``, and ``destroy_blend_state``.
  12. CSO objects handled by the context object:
  13. * :ref:`Blend`: ``*_blend_state``
  14. * :ref:`Sampler`: These are special; they can be bound to either vertex or
  15. fragment samplers, and they are bound in groups.
  16. ``bind_fragment_sampler_states``, ``bind_vertex_sampler_states``
  17. * :ref:`Rasterizer`: ``*_rasterizer_state``
  18. * :ref:`Depth, Stencil, & Alpha`: ``*_depth_stencil_alpha_state``
  19. * :ref:`Shader`: These have two sets of methods. ``*_fs_state`` is for
  20. fragment shaders, and ``*_vs_state`` is for vertex shaders.
  21. * :ref:`Vertex Elements`: ``*_vertex_elements_state``
  22. Resource Binding State
  23. ^^^^^^^^^^^^^^^^^^^^^^
  24. This state describes how resources in various flavours (textures,
  25. buffers, surfaces) are bound to the driver.
  26. * ``set_constant_buffer`` sets a constant buffer to be used for a given shader
  27. type. index is used to indicate which buffer to set (some apis may allow
  28. multiple ones to be set, and binding a specific one later, though drivers
  29. are mostly restricted to the first one right now).
  30. * ``set_framebuffer_state``
  31. * ``set_vertex_buffers``
  32. Non-CSO State
  33. ^^^^^^^^^^^^^
  34. These pieces of state are too small, variable, and/or trivial to have CSO
  35. objects. They all follow simple, one-method binding calls, e.g.
  36. ``set_blend_color``.
  37. * ``set_stencil_ref`` sets the stencil front and back reference values
  38. which are used as comparison values in stencil test.
  39. * ``set_blend_color``
  40. * ``set_clip_state``
  41. * ``set_polygon_stipple``
  42. * ``set_scissor_state`` sets the bounds for the scissor test, which culls
  43. pixels before blending to render targets. If the :ref:`Rasterizer` does
  44. not have the scissor test enabled, then the scissor bounds never need to
  45. be set since they will not be used.
  46. * ``set_viewport_state``
  47. Sampler Views
  48. ^^^^^^^^^^^^^
  49. These are the means to bind textures to shader stages. To create one, specify
  50. its format, swizzle and LOD range in sampler view template.
  51. If texture format is different than template format, it is said the texture
  52. is being cast to another format. Casting can be done only between compatible
  53. formats, that is formats that have matching component order and sizes.
  54. Swizzle fields specify they way in which fetched texel components are placed
  55. in the result register. For example, swizzle_r specifies what is going to be
  56. placed in destination register x (AKA r).
  57. first_level and last_level fields of sampler view template specify the LOD
  58. range the texture is going to be constrained to.
  59. * ``set_fragment_sampler_views`` binds an array of sampler views to
  60. fragment shader stage. Every binding point acquires a reference
  61. to a respective sampler view and releases a reference to the previous
  62. sampler view.
  63. * ``set_vertex_sampler_views`` binds an array of sampler views to vertex
  64. shader stage. Every binding point acquires a reference to a respective
  65. sampler view and releases a reference to the previous sampler view.
  66. * ``create_sampler_view`` creates a new sampler view. texture is associated
  67. with the sampler view which results in sampler view holding a reference
  68. to the texture. Format specified in template must be compatible
  69. with texture format.
  70. * ``sampler_view_destroy`` destroys a sampler view and releases its reference
  71. to associated texture.
  72. Clearing
  73. ^^^^^^^^
  74. ``clear`` initializes some or all of the surfaces currently bound to
  75. the framebuffer to particular RGBA, depth, or stencil values.
  76. Clear is one of the most difficult concepts to nail down to a single
  77. interface and it seems likely that we will want to add additional
  78. clear paths, for instance clearing surfaces not bound to the
  79. framebuffer, or read-modify-write clears such as depth-only or
  80. stencil-only clears of packed depth-stencil buffers.
  81. Drawing
  82. ^^^^^^^
  83. ``draw_arrays`` draws a specified primitive.
  84. This command is equivalent to calling ``draw_arrays_instanced``
  85. with ``startInstance`` set to 0 and ``instanceCount`` set to 1.
  86. ``draw_elements`` draws a specified primitive using an optional
  87. index buffer.
  88. This command is equivalent to calling ``draw_elements_instanced``
  89. with ``startInstance`` set to 0 and ``instanceCount`` set to 1.
  90. ``draw_range_elements``
  91. XXX: this is (probably) a temporary entrypoint, as the range
  92. information should be available from the vertex_buffer state.
  93. Using this to quickly evaluate a specialized path in the draw
  94. module.
  95. ``draw_arrays_instanced`` draws multiple instances of the same primitive.
  96. This command is equivalent to calling ``draw_elements_instanced``
  97. with ``indexBuffer`` set to NULL and ``indexSize`` set to 0.
  98. ``draw_elements_instanced`` draws multiple instances of the same primitive
  99. using an optional index buffer.
  100. For instanceID in the range between ``startInstance``
  101. and ``startInstance``+``instanceCount``-1, inclusive, draw a primitive
  102. specified by ``mode`` and sequential numbers in the range between ``start``
  103. and ``start``+``count``-1, inclusive.
  104. If ``indexBuffer`` is not NULL, it specifies an index buffer with index
  105. byte size of ``indexSize``. The sequential numbers are used to lookup
  106. the index buffer and the resulting indices in turn are used to fetch
  107. vertex attributes.
  108. If ``indexBuffer`` is NULL, the sequential numbers are used directly
  109. as indices to fetch vertex attributes.
  110. If a given vertex element has ``instance_divisor`` set to 0, it is said
  111. it contains per-vertex data and effective vertex attribute address needs
  112. to be recalculated for every index.
  113. attribAddr = ``stride`` * index + ``src_offset``
  114. If a given vertex element has ``instance_divisor`` set to non-zero,
  115. it is said it contains per-instance data and effective vertex attribute
  116. address needs to recalculated for every ``instance_divisor``-th instance.
  117. attribAddr = ``stride`` * instanceID / ``instance_divisor`` + ``src_offset``
  118. In the above formulas, ``src_offset`` is taken from the given vertex element
  119. and ``stride`` is taken from a vertex buffer associated with the given
  120. vertex element.
  121. The calculated attribAddr is used as an offset into the vertex buffer to
  122. fetch the attribute data.
  123. The value of ``instanceID`` can be read in a vertex shader through a system
  124. value register declared with INSTANCEID semantic name.
  125. Queries
  126. ^^^^^^^
  127. Queries gather some statistic from the 3D pipeline over one or more
  128. draws. Queries may be nested, though no state tracker currently
  129. exercises this.
  130. Queries can be created with ``create_query`` and deleted with
  131. ``destroy_query``. To start a query, use ``begin_query``, and when finished,
  132. use ``end_query`` to end the query.
  133. ``get_query_result`` is used to retrieve the results of a query. If
  134. the ``wait`` parameter is TRUE, then the ``get_query_result`` call
  135. will block until the results of the query are ready (and TRUE will be
  136. returned). Otherwise, if the ``wait`` parameter is FALSE, the call
  137. will not block and the return value will be TRUE if the query has
  138. completed or FALSE otherwise.
  139. A common type of query is the occlusion query which counts the number of
  140. fragments/pixels which are written to the framebuffer (and not culled by
  141. Z/stencil/alpha testing or shader KILL instructions).
  142. Conditional Rendering
  143. ^^^^^^^^^^^^^^^^^^^^^
  144. A drawing command can be skipped depending on the outcome of a query
  145. (typically an occlusion query). The ``render_condition`` function specifies
  146. the query which should be checked prior to rendering anything.
  147. If ``render_condition`` is called with ``query`` = NULL, conditional
  148. rendering is disabled and drawing takes place normally.
  149. If ``render_condition`` is called with a non-null ``query`` subsequent
  150. drawing commands will be predicated on the outcome of the query. If
  151. the query result is zero subsequent drawing commands will be skipped.
  152. If ``mode`` is PIPE_RENDER_COND_WAIT the driver will wait for the
  153. query to complete before deciding whether to render.
  154. If ``mode`` is PIPE_RENDER_COND_NO_WAIT and the query has not yet
  155. completed, the drawing command will be executed normally. If the query
  156. has completed, drawing will be predicated on the outcome of the query.
  157. If ``mode`` is PIPE_RENDER_COND_BY_REGION_WAIT or
  158. PIPE_RENDER_COND_BY_REGION_NO_WAIT rendering will be predicated as above
  159. for the non-REGION modes but in the case that an occulusion query returns
  160. a non-zero result, regions which were occluded may be ommitted by subsequent
  161. drawing commands. This can result in better performance with some GPUs.
  162. Normally, if the occlusion query returned a non-zero result subsequent
  163. drawing happens normally so fragments may be generated, shaded and
  164. processed even where they're known to be obscured.
  165. Flushing
  166. ^^^^^^^^
  167. ``flush``
  168. Resource Busy Queries
  169. ^^^^^^^^^^^^^^^^^^^^^
  170. ``is_texture_referenced``
  171. ``is_buffer_referenced``
  172. Blitting
  173. ^^^^^^^^
  174. These methods emulate classic blitter controls. They are not guaranteed to be
  175. available; if they are set to NULL, then they are not present.
  176. These methods operate directly on ``pipe_surface`` objects, and stand
  177. apart from any 3D state in the context. Blitting functionality may be
  178. moved to a separate abstraction at some point in the future.
  179. ``surface_fill`` performs a fill operation on a section of a surface.
  180. ``surface_copy`` blits a region of a surface to a region of another surface,
  181. provided that both surfaces are the same format. The source and destination
  182. may be the same surface, and overlapping blits are permitted.
  183. The interfaces to these calls are likely to change to make it easier
  184. for a driver to batch multiple blits with the same source and
  185. destination.