blob: 1fc8a3e4bad0436961ecf5ae2e6ccab7a1110035 [file] [log] [blame]
Corbin Simpsone7d05f12010-06-16 16:52:52 -07001.. _context:
2
Corbin Simpson8283e202009-12-20 15:28:00 -08003Context
4=======
5
Brian Paul73e37d92011-02-03 12:30:19 -07006A Gallium rendering context encapsulates the state which effects 3D
7rendering such as blend state, depth/stencil state, texture samplers,
8etc.
9
10Note that resource/texture allocation is not per-context but per-screen.
11
Corbin Simpson8283e202009-12-20 15:28:00 -080012
13Methods
14-------
15
Corbin Simpsona524aab2009-12-20 19:41:50 -080016CSO State
17^^^^^^^^^
18
Brian Paul73e37d92011-02-03 12:30:19 -070019All Constant State Object (CSO) state is created, bound, and destroyed,
20with triplets of methods that all follow a specific naming scheme.
21For example, ``create_blend_state``, ``bind_blend_state``, and
22``destroy_blend_state``.
Corbin Simpsona524aab2009-12-20 19:41:50 -080023
24CSO objects handled by the context object:
25
26* :ref:`Blend`: ``*_blend_state``
Brian Paul73e37d92011-02-03 12:30:19 -070027* :ref:`Sampler`: Texture sampler states are bound separately for fragment,
Brian Paul55e81b02013-09-12 17:31:08 -060028 vertex, geometry and compute shaders with the ``bind_sampler_states``
29 function. The ``start`` and ``num_samplers`` parameters indicate a range
30 of samplers to change. NOTE: at this time, start is always zero and
31 the CSO module will always replace all samplers at once (no sub-ranges).
32 This may change in the future.
Corbin Simpsona524aab2009-12-20 19:41:50 -080033* :ref:`Rasterizer`: ``*_rasterizer_state``
Ilia Mirkin05d02232014-03-31 18:08:07 -040034* :ref:`depth-stencil-alpha`: ``*_depth_stencil_alpha_state``
Brian Paul73e37d92011-02-03 12:30:19 -070035* :ref:`Shader`: These are create, bind and destroy methods for vertex,
36 fragment and geometry shaders.
Ilia Mirkin05d02232014-03-31 18:08:07 -040037* :ref:`vertexelements`: ``*_vertex_elements_state``
Corbin Simpsona524aab2009-12-20 19:41:50 -080038
Keith Whitwellf3347fe2009-12-21 23:44:32 +000039
40Resource Binding State
41^^^^^^^^^^^^^^^^^^^^^^
42
43This state describes how resources in various flavours (textures,
44buffers, surfaces) are bound to the driver.
45
46
Roland Scheideggerbf575b62010-01-15 18:25:14 +010047* ``set_constant_buffer`` sets a constant buffer to be used for a given shader
48 type. index is used to indicate which buffer to set (some apis may allow
49 multiple ones to be set, and binding a specific one later, though drivers
50 are mostly restricted to the first one right now).
51
Keith Whitwellf3347fe2009-12-21 23:44:32 +000052* ``set_framebuffer_state``
Michal Krole81caad2010-02-25 15:33:15 +010053
Keith Whitwellf3347fe2009-12-21 23:44:32 +000054* ``set_vertex_buffers``
55
Chia-I Wue7f69c42010-07-17 22:00:04 +080056* ``set_index_buffer``
Keith Whitwellf3347fe2009-12-21 23:44:32 +000057
Brian Paul73e37d92011-02-03 12:30:19 -070058
Corbin Simpsona524aab2009-12-20 19:41:50 -080059Non-CSO State
60^^^^^^^^^^^^^
61
62These pieces of state are too small, variable, and/or trivial to have CSO
63objects. They all follow simple, one-method binding calls, e.g.
Roland Scheidegger98f8c4d02010-02-09 21:48:43 +010064``set_blend_color``.
Corbin Simpson8e1768c2010-03-19 00:07:55 -070065
Roland Scheidegger98f8c4d02010-02-09 21:48:43 +010066* ``set_stencil_ref`` sets the stencil front and back reference values
67 which are used as comparison values in stencil test.
Corbin Simpsona524aab2009-12-20 19:41:50 -080068* ``set_blend_color``
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +020069* ``set_sample_mask``
Corbin Simpsona524aab2009-12-20 19:41:50 -080070* ``set_clip_state``
Corbin Simpsona524aab2009-12-20 19:41:50 -080071* ``set_polygon_stipple``
Zack Rusineaabb4e2013-05-24 16:08:39 -040072* ``set_scissor_states`` sets the bounds for the scissor test, which culls
Corbin Simpson8cf1af42010-01-25 01:12:30 -080073 pixels before blending to render targets. If the :ref:`Rasterizer` does
74 not have the scissor test enabled, then the scissor bounds never need to
Keith Whitwellbc3cff22010-08-20 11:38:33 +010075 be set since they will not be used. Note that scissor xmin and ymin are
76 inclusive, but xmax and ymax are exclusive. The inclusive ranges in x
Zack Rusineaabb4e2013-05-24 16:08:39 -040077 and y would be [xmin..xmax-1] and [ymin..ymax-1]. The number of scissors
78 should be the same as the number of set viewports and can be up to
79 PIPE_MAX_VIEWPORTS.
80* ``set_viewport_states``
Corbin Simpsona524aab2009-12-20 19:41:50 -080081
Keith Whitwellf3347fe2009-12-21 23:44:32 +000082
Michal Krole4b8a302010-03-16 10:58:33 +010083Sampler Views
84^^^^^^^^^^^^^
85
86These are the means to bind textures to shader stages. To create one, specify
87its format, swizzle and LOD range in sampler view template.
88
89If texture format is different than template format, it is said the texture
90is being cast to another format. Casting can be done only between compatible
91formats, that is formats that have matching component order and sizes.
92
93Swizzle fields specify they way in which fetched texel components are placed
Michal Krol980da4a2010-03-19 09:08:33 +010094in the result register. For example, ``swizzle_r`` specifies what is going to be
95placed in first component of result register.
Michal Krole4b8a302010-03-16 10:58:33 +010096
Michal Krol980da4a2010-03-19 09:08:33 +010097The ``first_level`` and ``last_level`` fields of sampler view template specify
Roland Scheidegger4c700142010-12-02 04:33:43 +010098the LOD range the texture is going to be constrained to. Note that these
99values are in addition to the respective min_lod, max_lod values in the
100pipe_sampler_state (that is if min_lod is 2.0, and first_level 3, the first mip
101level used for sampling from the resource is effectively the fifth).
102
103The ``first_layer`` and ``last_layer`` fields specify the layer range the
104texture is going to be constrained to. Similar to the LOD range, this is added
105to the array index which is used for sampling.
Michal Krole4b8a302010-03-16 10:58:33 +0100106
Brian Paula3ed98f2013-10-07 18:16:22 -0600107* ``set_sampler_views`` binds an array of sampler views to a shader stage.
108 Every binding point acquires a reference
Michal Krole4b8a302010-03-16 10:58:33 +0100109 to a respective sampler view and releases a reference to the previous
Brian Paula3ed98f2013-10-07 18:16:22 -0600110 sampler view.
Michal Krole4b8a302010-03-16 10:58:33 +0100111
Michal Krol980da4a2010-03-19 09:08:33 +0100112* ``create_sampler_view`` creates a new sampler view. ``texture`` is associated
Michal Krole4b8a302010-03-16 10:58:33 +0100113 with the sampler view which results in sampler view holding a reference
114 to the texture. Format specified in template must be compatible
115 with texture format.
116
117* ``sampler_view_destroy`` destroys a sampler view and releases its reference
118 to associated texture.
119
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200120Shader Resources
121^^^^^^^^^^^^^^^^
122
123Shader resources are textures or buffers that may be read or written
124from a shader without an associated sampler. This means that they
125have no support for floating point coordinates, address wrap modes or
126filtering.
127
128Shader resources are specified for all the shader stages at once using
129the ``set_shader_resources`` method. When binding texture resources,
130the ``level``, ``first_layer`` and ``last_layer`` pipe_surface fields
131specify the mipmap level and the range of layers the texture will be
132constrained to. In the case of buffers, ``first_element`` and
133``last_element`` specify the range within the buffer that will be used
Francisco Jerezb8e808f2012-04-30 20:20:29 +0200134by the shader resource. Writes to a shader resource are only allowed
135when the ``writable`` flag is set.
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200136
Roland Scheidegger4c700142010-12-02 04:33:43 +0100137Surfaces
138^^^^^^^^
139
140These are the means to use resources as color render targets or depthstencil
141attachments. To create one, specify the mip level, the range of layers, and
142the bind flags (either PIPE_BIND_DEPTH_STENCIL or PIPE_BIND_RENDER_TARGET).
143Note that layer values are in addition to what is indicated by the geometry
144shader output variable XXX_FIXME (that is if first_layer is 3 and geometry
145shader indicates index 2, the 5th layer of the resource will be used). These
146first_layer and last_layer parameters will only be used for 1d array, 2d array,
147cube, and 3d textures otherwise they are 0.
148
149* ``create_surface`` creates a new surface.
150
151* ``surface_destroy`` destroys a surface and releases its reference to the
152 associated resource.
Michal Krole4b8a302010-03-16 10:58:33 +0100153
Marek Olšák861a0292011-12-15 18:42:21 +0100154Stream output targets
155^^^^^^^^^^^^^^^^^^^^^
156
157Stream output, also known as transform feedback, allows writing the primitives
158produced by the vertex pipeline to buffers. This is done after the geometry
159shader or vertex shader if no geometry shader is present.
160
161The stream output targets are views into buffer resources which can be bound
162as stream outputs and specify a memory range where it's valid to write
163primitives. The pipe driver must implement memory protection such that any
164primitives written outside of the specified memory range are discarded.
165
166Two stream output targets can use the same resource at the same time, but
167with a disjoint memory range.
168
169Additionally, the stream output target internally maintains the offset
170into the buffer which is incremented everytime something is written to it.
171The internal offset is equal to how much data has already been written.
172It can be stored in device memory and the CPU actually doesn't have to query
173it.
174
175The stream output target can be used in a draw command to provide
176the vertex count. The vertex count is derived from the internal offset
177discussed above.
178
179* ``create_stream_output_target`` create a new target.
180
181* ``stream_output_target_destroy`` destroys a target. Users of this should
182 use pipe_so_target_reference instead.
183
184* ``set_stream_output_targets`` binds stream output targets. The parameter
Zack Rusindfa25ea2014-03-06 18:43:44 -0500185 offset is an array which specifies the internal offset of the buffer. The
186 internal offset is, besides writing, used for reading the data during the
187 draw_auto stage, i.e. it specifies how much data there is in the buffer
188 for the purposes of the draw_auto stage. -1 means the buffer should
189 be appended to, and everything else sets the internal offset.
Marek Olšák861a0292011-12-15 18:42:21 +0100190
191NOTE: The currently-bound vertex or geometry shader must be compiled with
192the properly-filled-in structure pipe_stream_output_info describing which
193outputs should be written to buffers and how. The structure is part of
194pipe_shader_state.
195
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000196Clearing
197^^^^^^^^
198
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200199Clear is one of the most difficult concepts to nail down to a single
200interface (due to both different requirements from APIs and also driver/hw
201specific differences).
202
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000203``clear`` initializes some or all of the surfaces currently bound to
204the framebuffer to particular RGBA, depth, or stencil values.
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200205Currently, this does not take into account color or stencil write masks (as
206used by GL), and always clears the whole surfaces (no scissoring as used by
207GL clear or explicit rectangles like d3d9 uses). It can, however, also clear
Marek Olšákf04dd3d2013-01-14 06:58:52 +0100208only depth or stencil in a combined depth/stencil surface.
Roland Scheidegger4c700142010-12-02 04:33:43 +0100209If a surface includes several layers then all layers will be cleared.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000210
Roland Scheideggera6e5c6c2010-06-03 16:33:25 +0200211``clear_render_target`` clears a single color rendertarget with the specified
212color value. While it is only possible to clear one surface at a time (which can
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200213include several layers), this surface need not be bound to the framebuffer.
214
Corbin Simpson517a4fb2010-06-16 11:10:46 -0700215``clear_depth_stencil`` clears a single depth, stencil or depth/stencil surface
Roland Scheideggera6e5c6c2010-06-03 16:33:25 +0200216with the specified depth and stencil values (for combined depth/stencil buffers,
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200217is is also possible to only clear one or the other part). While it is only
218possible to clear one surface at a time (which can include several layers),
219this surface need not be bound to the framebuffer.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000220
Ilia Mirkin24b86cb2014-03-25 17:10:54 -0400221``clear_buffer`` clears a PIPE_BUFFER resource with the specified clear value
222(which may be multiple bytes in length). Logically this is a memset with a
223multi-byte element value starting at offset bytes from resource start, going
224for size bytes. It is guaranteed that size % clear_value_size == 0.
225
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000226
227Drawing
Corbin Simpsona524aab2009-12-20 19:41:50 -0800228^^^^^^^
229
Chia-I Wue7f69c42010-07-17 22:00:04 +0800230``draw_vbo`` draws a specified primitive. The primitive mode and other
231properties are described by ``pipe_draw_info``.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800232
Chia-I Wue7f69c42010-07-17 22:00:04 +0800233The ``mode``, ``start``, and ``count`` fields of ``pipe_draw_info`` specify the
234the mode of the primitive and the vertices to be fetched, in the range between
235``start`` to ``start``+``count``-1, inclusive.
Michal Krolffd28482010-01-14 18:55:52 +0100236
Chia-I Wue7f69c42010-07-17 22:00:04 +0800237Every instance with instanceID in the range between ``start_instance`` and
238``start_instance``+``instance_count``-1, inclusive, will be drawn.
Michal Krolffd28482010-01-14 18:55:52 +0100239
José Fonsecabb78f6a2011-04-16 10:18:20 +0100240If there is an index buffer bound, and ``indexed`` field is true, all vertex
241indices will be looked up in the index buffer.
242
243In indexed draw, ``min_index`` and ``max_index`` respectively provide a lower
244and upper bound of the indices contained in the index buffer inside the range
245between ``start`` to ``start``+``count``-1. This allows the driver to
246determine which subset of vertices will be referenced during te draw call
247without having to scan the index buffer. Providing a over-estimation of the
248the true bounds, for example, a ``min_index`` and ``max_index`` of 0 and
2490xffffffff respectively, must give exactly the same rendering, albeit with less
250performance due to unreferenced vertex buffers being unnecessarily DMA'ed or
251processed. Providing a underestimation of the true bounds will result in
252undefined behavior, but should not result in program or system failure.
253
254In case of non-indexed draw, ``min_index`` should be set to
Chia-I Wue7f69c42010-07-17 22:00:04 +0800255``start`` and ``max_index`` should be set to ``start``+``count``-1.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800256
José Fonsecabb78f6a2011-04-16 10:18:20 +0100257``index_bias`` is a value added to every vertex index after lookup and before
258fetching vertex attributes.
José Fonseca493a1bb2010-04-20 10:22:28 +0200259
Brian Pauladf35e82010-10-21 19:03:38 -0600260When drawing indexed primitives, the primitive restart index can be
261used to draw disjoint primitive strips. For example, several separate
262line strips can be drawn by designating a special index value as the
263restart index. The ``primitive_restart`` flag enables/disables this
264feature. The ``restart_index`` field specifies the restart index value.
265
266When primitive restart is in use, array indexes are compared to the
267restart index before adding the index_bias offset.
268
Michal Krolffd28482010-01-14 18:55:52 +0100269If a given vertex element has ``instance_divisor`` set to 0, it is said
270it contains per-vertex data and effective vertex attribute address needs
271to be recalculated for every index.
272
273 attribAddr = ``stride`` * index + ``src_offset``
274
275If a given vertex element has ``instance_divisor`` set to non-zero,
276it is said it contains per-instance data and effective vertex attribute
277address needs to recalculated for every ``instance_divisor``-th instance.
278
279 attribAddr = ``stride`` * instanceID / ``instance_divisor`` + ``src_offset``
280
281In the above formulas, ``src_offset`` is taken from the given vertex element
282and ``stride`` is taken from a vertex buffer associated with the given
283vertex element.
284
285The calculated attribAddr is used as an offset into the vertex buffer to
286fetch the attribute data.
287
288The value of ``instanceID`` can be read in a vertex shader through a system
289value register declared with INSTANCEID semantic name.
290
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000291
292Queries
293^^^^^^^
294
295Queries gather some statistic from the 3D pipeline over one or more
José Fonseca44a8e512013-03-11 10:13:47 +0000296draws. Queries may be nested, though not all state trackers exercise this.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000297
298Queries can be created with ``create_query`` and deleted with
Brian Paul98f3f1c2010-01-29 12:36:26 -0700299``destroy_query``. To start a query, use ``begin_query``, and when finished,
300use ``end_query`` to end the query.
301
302``get_query_result`` is used to retrieve the results of a query. If
303the ``wait`` parameter is TRUE, then the ``get_query_result`` call
304will block until the results of the query are ready (and TRUE will be
305returned). Otherwise, if the ``wait`` parameter is FALSE, the call
306will not block and the return value will be TRUE if the query has
307completed or FALSE otherwise.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000308
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200309The interface currently includes the following types of queries:
310
311``PIPE_QUERY_OCCLUSION_COUNTER`` counts the number of fragments which
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700312are written to the framebuffer without being culled by
Ilia Mirkin05d02232014-03-31 18:08:07 -0400313:ref:`depth-stencil-alpha` testing or shader KILL instructions.
Brian Paul34613c62011-01-18 16:34:22 -0700314The result is an unsigned 64-bit integer.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200315This query can be used with ``render_condition``.
316
Zack Rusin0657fc02011-01-26 00:01:51 -0500317In cases where a boolean result of an occlusion query is enough,
318``PIPE_QUERY_OCCLUSION_PREDICATE`` should be used. It is just like
319``PIPE_QUERY_OCCLUSION_COUNTER`` except that the result is a boolean
320value of FALSE for cases where COUNTER would result in 0 and TRUE
321for all other cases.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200322This query can be used with ``render_condition``.
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700323
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200324``PIPE_QUERY_TIME_ELAPSED`` returns the amount of time, in nanoseconds,
325the context takes to perform operations.
Brian Paul34613c62011-01-18 16:34:22 -0700326The result is an unsigned 64-bit integer.
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700327
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200328``PIPE_QUERY_TIMESTAMP`` returns a device/driver internal timestamp,
329scaled to nanoseconds, recorded after all commands issued prior to
330``end_query`` have been processed.
331This query does not require a call to ``begin_query``.
332The result is an unsigned 64-bit integer.
333
Roland Scheideggercdf89d02013-06-19 23:25:39 +0200334``PIPE_QUERY_TIMESTAMP_DISJOINT`` can be used to check the
335internal timer resolution and whether the timestamp counter has become
336unreliable due to things like throttling etc. - only if this is FALSE
337a timestamp query (within the timestamp_disjoint query) should be trusted.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200338The result is a 64-bit integer specifying the timer resolution in Hz,
Roland Scheideggercdf89d02013-06-19 23:25:39 +0200339followed by a boolean value indicating whether the timestamp counter
340is discontinuous or disjoint.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200341
342``PIPE_QUERY_PRIMITIVES_GENERATED`` returns a 64-bit integer indicating
Christoph Bumillerc620aad2013-03-29 14:30:49 +0100343the number of primitives processed by the pipeline (regardless of whether
344stream output is active or not).
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200345
346``PIPE_QUERY_PRIMITIVES_EMITTED`` returns a 64-bit integer indicating
347the number of primitives written to stream output buffers.
348
349``PIPE_QUERY_SO_STATISTICS`` returns 2 64-bit integers corresponding to
Christoph Bumillerc620aad2013-03-29 14:30:49 +0100350the result of
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200351``PIPE_QUERY_PRIMITIVES_EMITTED`` and
Christoph Bumillerc620aad2013-03-29 14:30:49 +0100352the number of primitives that would have been written to stream output buffers
353if they had infinite space available (primitives_storage_needed), in this order.
Roland Scheideggerbd3909f2013-08-23 23:08:43 +0200354XXX the 2nd value is equivalent to ``PIPE_QUERY_PRIMITIVES_GENERATED`` but it is
355unclear if it should be increased if stream output is not active.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200356
357``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` returns a boolean value indicating
358whether the stream output targets have overflowed as a result of the
359commands issued between ``begin_query`` and ``end_query``.
360This query can be used with ``render_condition``.
361
362``PIPE_QUERY_GPU_FINISHED`` returns a boolean value indicating whether
363all commands issued before ``end_query`` have completed. However, this
364does not imply serialization.
365This query does not require a call to ``begin_query``.
366
367``PIPE_QUERY_PIPELINE_STATISTICS`` returns an array of the following
36864-bit integers:
369Number of vertices read from vertex buffers.
370Number of primitives read from vertex buffers.
371Number of vertex shader threads launched.
372Number of geometry shader threads launched.
373Number of primitives generated by geometry shaders.
374Number of primitives forwarded to the rasterizer.
375Number of primitives rasterized.
376Number of fragment shader threads launched.
377Number of tessellation control shader threads launched.
378Number of tessellation evaluation shader threads launched.
379If a shader type is not supported by the device/driver,
380the corresponding values should be set to 0.
381
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700382Gallium does not guarantee the availability of any query types; one must
383always check the capabilities of the :ref:`Screen` first.
Brian Paul6c1549a2010-01-21 11:52:36 -0700384
385
386Conditional Rendering
387^^^^^^^^^^^^^^^^^^^^^
388
389A drawing command can be skipped depending on the outcome of a query
Roland Scheidegger793e8e32013-06-14 19:48:57 +0200390(typically an occlusion query, or streamout overflow predicate).
391The ``render_condition`` function specifies the query which should be checked
392prior to rendering anything. Functions honoring render_condition include
393(and are limited to) draw_vbo, clear, clear_render_target, clear_depth_stencil.
Brian Paul6c1549a2010-01-21 11:52:36 -0700394
395If ``render_condition`` is called with ``query`` = NULL, conditional
396rendering is disabled and drawing takes place normally.
397
398If ``render_condition`` is called with a non-null ``query`` subsequent
Roland Scheidegger793e8e32013-06-14 19:48:57 +0200399drawing commands will be predicated on the outcome of the query.
400Commands will be skipped if ``condition`` is equal to the predicate result
401(for non-boolean queries such as OCCLUSION_QUERY, zero counts as FALSE,
402non-zero as TRUE).
Brian Paul6c1549a2010-01-21 11:52:36 -0700403
404If ``mode`` is PIPE_RENDER_COND_WAIT the driver will wait for the
405query to complete before deciding whether to render.
406
407If ``mode`` is PIPE_RENDER_COND_NO_WAIT and the query has not yet
408completed, the drawing command will be executed normally. If the query
409has completed, drawing will be predicated on the outcome of the query.
410
411If ``mode`` is PIPE_RENDER_COND_BY_REGION_WAIT or
412PIPE_RENDER_COND_BY_REGION_NO_WAIT rendering will be predicated as above
Roland Scheidegger793e8e32013-06-14 19:48:57 +0200413for the non-REGION modes but in the case that an occlusion query returns
Brian Paul6c1549a2010-01-21 11:52:36 -0700414a non-zero result, regions which were occluded may be ommitted by subsequent
415drawing commands. This can result in better performance with some GPUs.
416Normally, if the occlusion query returned a non-zero result subsequent
417drawing happens normally so fragments may be generated, shaded and
418processed even where they're known to be obscured.
419
420
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000421Flushing
422^^^^^^^^
423
Corbin Simpsona524aab2009-12-20 19:41:50 -0800424``flush``
425
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000426
Marek Olšák419cd5f2013-09-20 15:08:29 +0200427``flush_resource``
428
429Flush the resource cache, so that the resource can be used
430by an external client. Possible usage:
431- flushing a resource before presenting it on the screen
432- flushing a resource if some other process or device wants to use it
433This shouldn't be used to flush caches if the resource is only managed
434by a single pipe_screen and is not shared with another process.
435(i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
436use the resource for texturing)
437
438
439
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000440Resource Busy Queries
441^^^^^^^^^^^^^^^^^^^^^
442
Keith Whitwell287c94e2010-04-10 16:05:54 +0100443``is_resource_referenced``
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000444
445
446
447Blitting
448^^^^^^^^
Corbin Simpsona524aab2009-12-20 19:41:50 -0800449
Roland Scheidegger379db6a2010-05-17 21:02:24 +0200450These methods emulate classic blitter controls.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800451
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +0200452These methods operate directly on ``pipe_resource`` objects, and stand
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000453apart from any 3D state in the context. Blitting functionality may be
454moved to a separate abstraction at some point in the future.
455
Roland Scheidegger4c700142010-12-02 04:33:43 +0100456``resource_copy_region`` blits a region of a resource to a region of another
457resource, provided that both resources have the same format, or compatible
458formats, i.e., formats for which copying the bytes from the source resource
459unmodified to the destination resource will achieve the same effect of a
460textured quad blitter.. The source and destination may be the same resource,
461but overlapping blits are not permitted.
Marek Olšákc4df2e32012-09-12 01:36:31 +0200462This can be considered the equivalent of a CPU memcpy.
463
464``blit`` blits a region of a resource to a region of another resource, including
465scaling, format conversion, and up-/downsampling, as well as
466a destination clip rectangle (scissors).
467As opposed to manually drawing a textured quad, this lets the pipe driver choose
468the optimal method for blitting (like using a special 2D engine), and usually
469offers, for example, accelerated stencil-only copies even where
470PIPE_CAP_SHADER_STENCIL_EXPORT is not available.
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +0200471
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000472
Keith Whitwell287c94e2010-04-10 16:05:54 +0100473Transfers
474^^^^^^^^^
475
476These methods are used to get data to/from a resource.
477
Marek Olšák369e4682012-10-08 04:06:42 +0200478``transfer_map`` creates a memory mapping and the transfer object
479associated with it.
480The returned pointer points to the start of the mapped range according to
481the box region, not the beginning of the resource. If transfer_map fails,
482the returned pointer to the buffer memory is NULL, and the pointer
483to the transfer object remains unchanged (i.e. it can be non-NULL).
Keith Whitwell287c94e2010-04-10 16:05:54 +0100484
Marek Olšák369e4682012-10-08 04:06:42 +0200485``transfer_unmap`` remove the memory mapping for and destroy
486the transfer object. The pointer into the resource should be considered
487invalid and discarded.
Keith Whitwell287c94e2010-04-10 16:05:54 +0100488
489``transfer_inline_write`` performs a simplified transfer for simple writes.
Marek Olšák369e4682012-10-08 04:06:42 +0200490Basically transfer_map, data write, and transfer_unmap all in one.
Keith Whitwell287c94e2010-04-10 16:05:54 +0100491
Brian Paulc5fb0512011-01-28 20:25:27 -0700492
493The box parameter to some of these functions defines a 1D, 2D or 3D
494region of pixels. This is self-explanatory for 1D, 2D and 3D texture
495targets.
496
Roland Scheidegger0f4c08a2013-06-07 20:54:54 +0200497For PIPE_TEXTURE_1D_ARRAY and PIPE_TEXTURE_2D_ARRAY, the box::z and box::depth
498fields refer to the array dimension of the texture.
Brian Paulc5fb0512011-01-28 20:25:27 -0700499
500For PIPE_TEXTURE_CUBE, the box:z and box::depth fields refer to the
501faces of the cube map (z + depth <= 6).
502
Roland Scheidegger0f4c08a2013-06-07 20:54:54 +0200503For PIPE_TEXTURE_CUBE_ARRAY, the box:z and box::depth fields refer to both
504the face and array dimension of the texture (face = z % 6, array = z / 6).
Brian Paulc5fb0512011-01-28 20:25:27 -0700505
506
Corbin Simpsonbb81f652010-05-17 12:58:29 -0700507.. _transfer_flush_region:
508
509transfer_flush_region
510%%%%%%%%%%%%%%%%%%%%%
511
512If a transfer was created with ``FLUSH_EXPLICIT``, it will not automatically
513be flushed on write or unmap. Flushes must be requested with
514``transfer_flush_region``. Flush ranges are relative to the mapped range, not
515the beginning of the resource.
516
Marek Olšák588fa882011-02-09 01:10:11 +0100517
518
Andreas Bollecb02c22012-10-23 18:29:41 +0200519.. _texture_barrier:
Marek Olšákaea4ed42011-03-08 11:32:35 +0100520
521texture_barrier
522%%%%%%%%%%%%%%%
523
524This function flushes all pending writes to the currently-set surfaces and
525invalidates all read caches of the currently-set samplers.
526
527
528
Marek Olšák5f61f052014-01-27 21:42:07 +0100529.. _memory_barrier:
530
531memory_barrier
532%%%%%%%%%%%%%%%
533
534This function flushes caches according to which of the PIPE_BARRIER_* flags
535are set.
536
537
538
Keith Whitwell287c94e2010-04-10 16:05:54 +0100539.. _pipe_transfer:
540
541PIPE_TRANSFER
542^^^^^^^^^^^^^
543
544These flags control the behavior of a transfer object.
545
José Fonseca0562f442011-02-22 14:14:22 +0000546``PIPE_TRANSFER_READ``
547 Resource contents read back (or accessed directly) at transfer create time.
548
549``PIPE_TRANSFER_WRITE``
Marek Olšák369e4682012-10-08 04:06:42 +0200550 Resource contents will be written back at transfer_unmap time (or modified
José Fonseca0562f442011-02-22 14:14:22 +0000551 as a result of being accessed directly).
552
553``PIPE_TRANSFER_MAP_DIRECTLY``
554 a transfer should directly map the resource. May return NULL if not supported.
555
556``PIPE_TRANSFER_DISCARD_RANGE``
557 The memory within the mapped region is discarded. Cannot be used with
558 ``PIPE_TRANSFER_READ``.
559
560``PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE``
561 Discards all memory backing the resource. It should not be used with
562 ``PIPE_TRANSFER_READ``.
563
564``PIPE_TRANSFER_DONTBLOCK``
565 Fail if the resource cannot be mapped immediately.
566
567``PIPE_TRANSFER_UNSYNCHRONIZED``
568 Do not synchronize pending operations on the resource when mapping. The
569 interaction of any writes to the map and any operations pending on the
570 resource are undefined. Cannot be used with ``PIPE_TRANSFER_READ``.
571
572``PIPE_TRANSFER_FLUSH_EXPLICIT``
573 Written ranges will be notified later with :ref:`transfer_flush_region`.
574 Cannot be used with ``PIPE_TRANSFER_READ``.
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200575
Marek Olšák5f61f052014-01-27 21:42:07 +0100576``PIPE_TRANSFER_PERSISTENT``
577 Allows the resource to be used for rendering while mapped.
578 PIPE_RESOURCE_FLAG_MAP_PERSISTENT must be set when creating
579 the resource.
580 If COHERENT is not set, memory_barrier(PIPE_BARRIER_MAPPED_BUFFER)
581 must be called to ensure the device can see what the CPU has written.
582
583``PIPE_TRANSFER_COHERENT``
584 If PERSISTENT is set, this ensures any writes done by the device are
585 immediately visible to the CPU and vice versa.
586 PIPE_RESOURCE_FLAG_MAP_COHERENT must be set when creating
587 the resource.
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200588
589Compute kernel execution
590^^^^^^^^^^^^^^^^^^^^^^^^
591
592A compute program can be defined, bound or destroyed using
593``create_compute_state``, ``bind_compute_state`` or
594``destroy_compute_state`` respectively.
595
596Any of the subroutines contained within the compute program can be
597executed on the device using the ``launch_grid`` method. This method
598will execute as many instances of the program as elements in the
599specified N-dimensional grid, hopefully in parallel.
600
601The compute program has access to four special resources:
602
603* ``GLOBAL`` represents a memory space shared among all the threads
604 running on the device. An arbitrary buffer created with the
605 ``PIPE_BIND_GLOBAL`` flag can be mapped into it using the
606 ``set_global_binding`` method.
607
608* ``LOCAL`` represents a memory space shared among all the threads
609 running in the same working group. The initial contents of this
610 resource are undefined.
611
612* ``PRIVATE`` represents a memory space local to a single thread.
613 The initial contents of this resource are undefined.
614
615* ``INPUT`` represents a read-only memory space that can be
616 initialized at ``launch_grid`` time.
617
618These resources use a byte-based addressing scheme, and they can be
619accessed from the compute program by means of the LOAD/STORE TGSI
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200620opcodes. Additional resources to be accessed using the same opcodes
621may be specified by the user with the ``set_compute_resources``
622method.
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200623
624In addition, normal texture sampling is allowed from the compute
Brian Paul55e81b02013-09-12 17:31:08 -0600625program: ``bind_sampler_states`` may be used to set up texture
Brian Paula3ed98f2013-10-07 18:16:22 -0600626samplers for the compute stage and ``set_sampler_views`` may
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200627be used to bind a number of sampler views to it.