blob: af84a2d91f811a0c6601bc28842d2b776b727b02 [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,
28 vertex and geometry samplers. Note that sampler states are set en masse.
29 If M is the max number of sampler units supported by the driver and N
30 samplers are bound with ``bind_fragment_sampler_states`` then sampler
31 units N..M-1 are considered disabled/NULL.
Corbin Simpsona524aab2009-12-20 19:41:50 -080032* :ref:`Rasterizer`: ``*_rasterizer_state``
33* :ref:`Depth, Stencil, & Alpha`: ``*_depth_stencil_alpha_state``
Brian Paul73e37d92011-02-03 12:30:19 -070034* :ref:`Shader`: These are create, bind and destroy methods for vertex,
35 fragment and geometry shaders.
Roland Scheidegger8397c802010-03-01 18:42:47 +010036* :ref:`Vertex Elements`: ``*_vertex_elements_state``
Corbin Simpsona524aab2009-12-20 19:41:50 -080037
Keith Whitwellf3347fe2009-12-21 23:44:32 +000038
39Resource Binding State
40^^^^^^^^^^^^^^^^^^^^^^
41
42This state describes how resources in various flavours (textures,
43buffers, surfaces) are bound to the driver.
44
45
Roland Scheideggerbf575b62010-01-15 18:25:14 +010046* ``set_constant_buffer`` sets a constant buffer to be used for a given shader
47 type. index is used to indicate which buffer to set (some apis may allow
48 multiple ones to be set, and binding a specific one later, though drivers
49 are mostly restricted to the first one right now).
50
Keith Whitwellf3347fe2009-12-21 23:44:32 +000051* ``set_framebuffer_state``
Michal Krole81caad2010-02-25 15:33:15 +010052
Keith Whitwellf3347fe2009-12-21 23:44:32 +000053* ``set_vertex_buffers``
54
Chia-I Wue7f69c42010-07-17 22:00:04 +080055* ``set_index_buffer``
Keith Whitwellf3347fe2009-12-21 23:44:32 +000056
Brian Paul73e37d92011-02-03 12:30:19 -070057
Corbin Simpsona524aab2009-12-20 19:41:50 -080058Non-CSO State
59^^^^^^^^^^^^^
60
61These pieces of state are too small, variable, and/or trivial to have CSO
62objects. They all follow simple, one-method binding calls, e.g.
Roland Scheidegger98f8c4d02010-02-09 21:48:43 +010063``set_blend_color``.
Corbin Simpson8e1768c2010-03-19 00:07:55 -070064
Roland Scheidegger98f8c4d02010-02-09 21:48:43 +010065* ``set_stencil_ref`` sets the stencil front and back reference values
66 which are used as comparison values in stencil test.
Corbin Simpsona524aab2009-12-20 19:41:50 -080067* ``set_blend_color``
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +020068* ``set_sample_mask``
Corbin Simpsona524aab2009-12-20 19:41:50 -080069* ``set_clip_state``
Corbin Simpsona524aab2009-12-20 19:41:50 -080070* ``set_polygon_stipple``
Corbin Simpson8cf1af42010-01-25 01:12:30 -080071* ``set_scissor_state`` sets the bounds for the scissor test, which culls
72 pixels before blending to render targets. If the :ref:`Rasterizer` does
73 not have the scissor test enabled, then the scissor bounds never need to
Keith Whitwellbc3cff22010-08-20 11:38:33 +010074 be set since they will not be used. Note that scissor xmin and ymin are
75 inclusive, but xmax and ymax are exclusive. The inclusive ranges in x
76 and y would be [xmin..xmax-1] and [ymin..ymax-1].
Corbin Simpsona524aab2009-12-20 19:41:50 -080077* ``set_viewport_state``
Corbin Simpsona524aab2009-12-20 19:41:50 -080078
Keith Whitwellf3347fe2009-12-21 23:44:32 +000079
Michal Krole4b8a302010-03-16 10:58:33 +010080Sampler Views
81^^^^^^^^^^^^^
82
83These are the means to bind textures to shader stages. To create one, specify
84its format, swizzle and LOD range in sampler view template.
85
86If texture format is different than template format, it is said the texture
87is being cast to another format. Casting can be done only between compatible
88formats, that is formats that have matching component order and sizes.
89
90Swizzle fields specify they way in which fetched texel components are placed
Michal Krol980da4a2010-03-19 09:08:33 +010091in the result register. For example, ``swizzle_r`` specifies what is going to be
92placed in first component of result register.
Michal Krole4b8a302010-03-16 10:58:33 +010093
Michal Krol980da4a2010-03-19 09:08:33 +010094The ``first_level`` and ``last_level`` fields of sampler view template specify
Roland Scheidegger4c700142010-12-02 04:33:43 +010095the LOD range the texture is going to be constrained to. Note that these
96values are in addition to the respective min_lod, max_lod values in the
97pipe_sampler_state (that is if min_lod is 2.0, and first_level 3, the first mip
98level used for sampling from the resource is effectively the fifth).
99
100The ``first_layer`` and ``last_layer`` fields specify the layer range the
101texture is going to be constrained to. Similar to the LOD range, this is added
102to the array index which is used for sampling.
Michal Krole4b8a302010-03-16 10:58:33 +0100103
104* ``set_fragment_sampler_views`` binds an array of sampler views to
105 fragment shader stage. Every binding point acquires a reference
106 to a respective sampler view and releases a reference to the previous
Brian Paul73e37d92011-02-03 12:30:19 -0700107 sampler view. If M is the maximum number of sampler units and N units
108 is passed to set_fragment_sampler_views, the driver should unbind the
109 sampler views for units N..M-1.
Michal Krole4b8a302010-03-16 10:58:33 +0100110
111* ``set_vertex_sampler_views`` binds an array of sampler views to vertex
112 shader stage. Every binding point acquires a reference to a respective
113 sampler view and releases a reference to the previous sampler view.
114
Michal Krol980da4a2010-03-19 09:08:33 +0100115* ``create_sampler_view`` creates a new sampler view. ``texture`` is associated
Michal Krole4b8a302010-03-16 10:58:33 +0100116 with the sampler view which results in sampler view holding a reference
117 to the texture. Format specified in template must be compatible
118 with texture format.
119
120* ``sampler_view_destroy`` destroys a sampler view and releases its reference
121 to associated texture.
122
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200123Shader Resources
124^^^^^^^^^^^^^^^^
125
126Shader resources are textures or buffers that may be read or written
127from a shader without an associated sampler. This means that they
128have no support for floating point coordinates, address wrap modes or
129filtering.
130
131Shader resources are specified for all the shader stages at once using
132the ``set_shader_resources`` method. When binding texture resources,
133the ``level``, ``first_layer`` and ``last_layer`` pipe_surface fields
134specify the mipmap level and the range of layers the texture will be
135constrained to. In the case of buffers, ``first_element`` and
136``last_element`` specify the range within the buffer that will be used
Francisco Jerezb8e808f2012-04-30 20:20:29 +0200137by the shader resource. Writes to a shader resource are only allowed
138when the ``writable`` flag is set.
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200139
Roland Scheidegger4c700142010-12-02 04:33:43 +0100140Surfaces
141^^^^^^^^
142
143These are the means to use resources as color render targets or depthstencil
144attachments. To create one, specify the mip level, the range of layers, and
145the bind flags (either PIPE_BIND_DEPTH_STENCIL or PIPE_BIND_RENDER_TARGET).
146Note that layer values are in addition to what is indicated by the geometry
147shader output variable XXX_FIXME (that is if first_layer is 3 and geometry
148shader indicates index 2, the 5th layer of the resource will be used). These
149first_layer and last_layer parameters will only be used for 1d array, 2d array,
150cube, and 3d textures otherwise they are 0.
151
152* ``create_surface`` creates a new surface.
153
154* ``surface_destroy`` destroys a surface and releases its reference to the
155 associated resource.
Michal Krole4b8a302010-03-16 10:58:33 +0100156
Marek Olšák861a0292011-12-15 18:42:21 +0100157Stream output targets
158^^^^^^^^^^^^^^^^^^^^^
159
160Stream output, also known as transform feedback, allows writing the primitives
161produced by the vertex pipeline to buffers. This is done after the geometry
162shader or vertex shader if no geometry shader is present.
163
164The stream output targets are views into buffer resources which can be bound
165as stream outputs and specify a memory range where it's valid to write
166primitives. The pipe driver must implement memory protection such that any
167primitives written outside of the specified memory range are discarded.
168
169Two stream output targets can use the same resource at the same time, but
170with a disjoint memory range.
171
172Additionally, the stream output target internally maintains the offset
173into the buffer which is incremented everytime something is written to it.
174The internal offset is equal to how much data has already been written.
175It can be stored in device memory and the CPU actually doesn't have to query
176it.
177
178The stream output target can be used in a draw command to provide
179the vertex count. The vertex count is derived from the internal offset
180discussed above.
181
182* ``create_stream_output_target`` create a new target.
183
184* ``stream_output_target_destroy`` destroys a target. Users of this should
185 use pipe_so_target_reference instead.
186
187* ``set_stream_output_targets`` binds stream output targets. The parameter
188 append_bitmask is a bitmask, where the i-th bit specifies whether new
189 primitives should be appended to the i-th buffer (writing starts at
190 the internal offset), or whether writing should start at the beginning
191 (the internal offset is effectively set to 0).
192
193NOTE: The currently-bound vertex or geometry shader must be compiled with
194the properly-filled-in structure pipe_stream_output_info describing which
195outputs should be written to buffers and how. The structure is part of
196pipe_shader_state.
197
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000198Clearing
199^^^^^^^^
200
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200201Clear is one of the most difficult concepts to nail down to a single
202interface (due to both different requirements from APIs and also driver/hw
203specific differences).
204
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000205``clear`` initializes some or all of the surfaces currently bound to
206the framebuffer to particular RGBA, depth, or stencil values.
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200207Currently, this does not take into account color or stencil write masks (as
208used by GL), and always clears the whole surfaces (no scissoring as used by
209GL clear or explicit rectangles like d3d9 uses). It can, however, also clear
210only depth or stencil in a combined depth/stencil surface, if the driver
211supports PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE.
Roland Scheidegger4c700142010-12-02 04:33:43 +0100212If a surface includes several layers then all layers will be cleared.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000213
Roland Scheideggera6e5c6c2010-06-03 16:33:25 +0200214``clear_render_target`` clears a single color rendertarget with the specified
215color value. While it is only possible to clear one surface at a time (which can
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200216include several layers), this surface need not be bound to the framebuffer.
217
Corbin Simpson517a4fb2010-06-16 11:10:46 -0700218``clear_depth_stencil`` clears a single depth, stencil or depth/stencil surface
Roland Scheideggera6e5c6c2010-06-03 16:33:25 +0200219with the specified depth and stencil values (for combined depth/stencil buffers,
Roland Scheidegger0cd70b52010-05-28 23:57:47 +0200220is is also possible to only clear one or the other part). While it is only
221possible to clear one surface at a time (which can include several layers),
222this surface need not be bound to the framebuffer.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000223
224
225Drawing
Corbin Simpsona524aab2009-12-20 19:41:50 -0800226^^^^^^^
227
Chia-I Wue7f69c42010-07-17 22:00:04 +0800228``draw_vbo`` draws a specified primitive. The primitive mode and other
229properties are described by ``pipe_draw_info``.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800230
Chia-I Wue7f69c42010-07-17 22:00:04 +0800231The ``mode``, ``start``, and ``count`` fields of ``pipe_draw_info`` specify the
232the mode of the primitive and the vertices to be fetched, in the range between
233``start`` to ``start``+``count``-1, inclusive.
Michal Krolffd28482010-01-14 18:55:52 +0100234
Chia-I Wue7f69c42010-07-17 22:00:04 +0800235Every instance with instanceID in the range between ``start_instance`` and
236``start_instance``+``instance_count``-1, inclusive, will be drawn.
Michal Krolffd28482010-01-14 18:55:52 +0100237
José Fonsecabb78f6a2011-04-16 10:18:20 +0100238If there is an index buffer bound, and ``indexed`` field is true, all vertex
239indices will be looked up in the index buffer.
240
241In indexed draw, ``min_index`` and ``max_index`` respectively provide a lower
242and upper bound of the indices contained in the index buffer inside the range
243between ``start`` to ``start``+``count``-1. This allows the driver to
244determine which subset of vertices will be referenced during te draw call
245without having to scan the index buffer. Providing a over-estimation of the
246the true bounds, for example, a ``min_index`` and ``max_index`` of 0 and
2470xffffffff respectively, must give exactly the same rendering, albeit with less
248performance due to unreferenced vertex buffers being unnecessarily DMA'ed or
249processed. Providing a underestimation of the true bounds will result in
250undefined behavior, but should not result in program or system failure.
251
252In case of non-indexed draw, ``min_index`` should be set to
Chia-I Wue7f69c42010-07-17 22:00:04 +0800253``start`` and ``max_index`` should be set to ``start``+``count``-1.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800254
José Fonsecabb78f6a2011-04-16 10:18:20 +0100255``index_bias`` is a value added to every vertex index after lookup and before
256fetching vertex attributes.
José Fonseca493a1bb2010-04-20 10:22:28 +0200257
Brian Pauladf35e82010-10-21 19:03:38 -0600258When drawing indexed primitives, the primitive restart index can be
259used to draw disjoint primitive strips. For example, several separate
260line strips can be drawn by designating a special index value as the
261restart index. The ``primitive_restart`` flag enables/disables this
262feature. The ``restart_index`` field specifies the restart index value.
263
264When primitive restart is in use, array indexes are compared to the
265restart index before adding the index_bias offset.
266
Michal Krolffd28482010-01-14 18:55:52 +0100267If a given vertex element has ``instance_divisor`` set to 0, it is said
268it contains per-vertex data and effective vertex attribute address needs
269to be recalculated for every index.
270
271 attribAddr = ``stride`` * index + ``src_offset``
272
273If a given vertex element has ``instance_divisor`` set to non-zero,
274it is said it contains per-instance data and effective vertex attribute
275address needs to recalculated for every ``instance_divisor``-th instance.
276
277 attribAddr = ``stride`` * instanceID / ``instance_divisor`` + ``src_offset``
278
279In the above formulas, ``src_offset`` is taken from the given vertex element
280and ``stride`` is taken from a vertex buffer associated with the given
281vertex element.
282
283The calculated attribAddr is used as an offset into the vertex buffer to
284fetch the attribute data.
285
286The value of ``instanceID`` can be read in a vertex shader through a system
287value register declared with INSTANCEID semantic name.
288
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000289
290Queries
291^^^^^^^
292
293Queries gather some statistic from the 3D pipeline over one or more
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200294draws. Queries may be nested, though only d3d1x currently exercises this.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000295
296Queries can be created with ``create_query`` and deleted with
Brian Paul98f3f1c2010-01-29 12:36:26 -0700297``destroy_query``. To start a query, use ``begin_query``, and when finished,
298use ``end_query`` to end the query.
299
300``get_query_result`` is used to retrieve the results of a query. If
301the ``wait`` parameter is TRUE, then the ``get_query_result`` call
302will block until the results of the query are ready (and TRUE will be
303returned). Otherwise, if the ``wait`` parameter is FALSE, the call
304will not block and the return value will be TRUE if the query has
305completed or FALSE otherwise.
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000306
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200307The interface currently includes the following types of queries:
308
309``PIPE_QUERY_OCCLUSION_COUNTER`` counts the number of fragments which
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700310are written to the framebuffer without being culled by
311:ref:`Depth, Stencil, & Alpha` testing or shader KILL instructions.
Brian Paul34613c62011-01-18 16:34:22 -0700312The result is an unsigned 64-bit integer.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200313This query can be used with ``render_condition``.
314
Zack Rusin0657fc02011-01-26 00:01:51 -0500315In cases where a boolean result of an occlusion query is enough,
316``PIPE_QUERY_OCCLUSION_PREDICATE`` should be used. It is just like
317``PIPE_QUERY_OCCLUSION_COUNTER`` except that the result is a boolean
318value of FALSE for cases where COUNTER would result in 0 and TRUE
319for all other cases.
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200320This query can be used with ``render_condition``.
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700321
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200322``PIPE_QUERY_TIME_ELAPSED`` returns the amount of time, in nanoseconds,
323the context takes to perform operations.
Brian Paul34613c62011-01-18 16:34:22 -0700324The result is an unsigned 64-bit integer.
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700325
Christoph Bumiller10f67c02011-10-20 18:03:23 +0200326``PIPE_QUERY_TIMESTAMP`` returns a device/driver internal timestamp,
327scaled to nanoseconds, recorded after all commands issued prior to
328``end_query`` have been processed.
329This query does not require a call to ``begin_query``.
330The result is an unsigned 64-bit integer.
331
332``PIPE_QUERY_TIMESTAMP_DISJOINT`` can be used to check whether the
333internal timer resolution is good enough to distinguish between the
334events at ``begin_query`` and ``end_query``.
335The result is a 64-bit integer specifying the timer resolution in Hz,
336followed by a boolean value indicating whether the timer has incremented.
337
338``PIPE_QUERY_PRIMITIVES_GENERATED`` returns a 64-bit integer indicating
339the number of primitives processed by the pipeline.
340
341``PIPE_QUERY_PRIMITIVES_EMITTED`` returns a 64-bit integer indicating
342the number of primitives written to stream output buffers.
343
344``PIPE_QUERY_SO_STATISTICS`` returns 2 64-bit integers corresponding to
345the results of
346``PIPE_QUERY_PRIMITIVES_EMITTED`` and
347``PIPE_QUERY_PRIMITIVES_GENERATED``, in this order.
348
349``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` returns a boolean value indicating
350whether the stream output targets have overflowed as a result of the
351commands issued between ``begin_query`` and ``end_query``.
352This query can be used with ``render_condition``.
353
354``PIPE_QUERY_GPU_FINISHED`` returns a boolean value indicating whether
355all commands issued before ``end_query`` have completed. However, this
356does not imply serialization.
357This query does not require a call to ``begin_query``.
358
359``PIPE_QUERY_PIPELINE_STATISTICS`` returns an array of the following
36064-bit integers:
361Number of vertices read from vertex buffers.
362Number of primitives read from vertex buffers.
363Number of vertex shader threads launched.
364Number of geometry shader threads launched.
365Number of primitives generated by geometry shaders.
366Number of primitives forwarded to the rasterizer.
367Number of primitives rasterized.
368Number of fragment shader threads launched.
369Number of tessellation control shader threads launched.
370Number of tessellation evaluation shader threads launched.
371If a shader type is not supported by the device/driver,
372the corresponding values should be set to 0.
373
Corbin Simpsonf1cf6b02010-05-17 12:00:59 -0700374Gallium does not guarantee the availability of any query types; one must
375always check the capabilities of the :ref:`Screen` first.
Brian Paul6c1549a2010-01-21 11:52:36 -0700376
377
378Conditional Rendering
379^^^^^^^^^^^^^^^^^^^^^
380
381A drawing command can be skipped depending on the outcome of a query
382(typically an occlusion query). The ``render_condition`` function specifies
383the query which should be checked prior to rendering anything.
384
385If ``render_condition`` is called with ``query`` = NULL, conditional
386rendering is disabled and drawing takes place normally.
387
388If ``render_condition`` is called with a non-null ``query`` subsequent
389drawing commands will be predicated on the outcome of the query. If
390the query result is zero subsequent drawing commands will be skipped.
391
392If ``mode`` is PIPE_RENDER_COND_WAIT the driver will wait for the
393query to complete before deciding whether to render.
394
395If ``mode`` is PIPE_RENDER_COND_NO_WAIT and the query has not yet
396completed, the drawing command will be executed normally. If the query
397has completed, drawing will be predicated on the outcome of the query.
398
399If ``mode`` is PIPE_RENDER_COND_BY_REGION_WAIT or
400PIPE_RENDER_COND_BY_REGION_NO_WAIT rendering will be predicated as above
401for the non-REGION modes but in the case that an occulusion query returns
402a non-zero result, regions which were occluded may be ommitted by subsequent
403drawing commands. This can result in better performance with some GPUs.
404Normally, if the occlusion query returned a non-zero result subsequent
405drawing happens normally so fragments may be generated, shaded and
406processed even where they're known to be obscured.
407
408
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000409Flushing
410^^^^^^^^
411
Corbin Simpsona524aab2009-12-20 19:41:50 -0800412``flush``
413
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000414
415Resource Busy Queries
416^^^^^^^^^^^^^^^^^^^^^
417
Keith Whitwell287c94e2010-04-10 16:05:54 +0100418``is_resource_referenced``
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000419
420
421
422Blitting
423^^^^^^^^
Corbin Simpsona524aab2009-12-20 19:41:50 -0800424
Roland Scheidegger379db6a2010-05-17 21:02:24 +0200425These methods emulate classic blitter controls.
Corbin Simpsona524aab2009-12-20 19:41:50 -0800426
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +0200427These methods operate directly on ``pipe_resource`` objects, and stand
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000428apart from any 3D state in the context. Blitting functionality may be
429moved to a separate abstraction at some point in the future.
430
Roland Scheidegger4c700142010-12-02 04:33:43 +0100431``resource_copy_region`` blits a region of a resource to a region of another
432resource, provided that both resources have the same format, or compatible
433formats, i.e., formats for which copying the bytes from the source resource
434unmodified to the destination resource will achieve the same effect of a
435textured quad blitter.. The source and destination may be the same resource,
436but overlapping blits are not permitted.
Marek Olšákc4df2e32012-09-12 01:36:31 +0200437This can be considered the equivalent of a CPU memcpy.
438
439``blit`` blits a region of a resource to a region of another resource, including
440scaling, format conversion, and up-/downsampling, as well as
441a destination clip rectangle (scissors).
442As opposed to manually drawing a textured quad, this lets the pipe driver choose
443the optimal method for blitting (like using a special 2D engine), and usually
444offers, for example, accelerated stencil-only copies even where
445PIPE_CAP_SHADER_STENCIL_EXPORT is not available.
Roland Scheideggeraac2cccc2010-04-26 19:50:57 +0200446
Keith Whitwellf3347fe2009-12-21 23:44:32 +0000447
Keith Whitwell287c94e2010-04-10 16:05:54 +0100448Transfers
449^^^^^^^^^
450
451These methods are used to get data to/from a resource.
452
Marek Olšák369e4682012-10-08 04:06:42 +0200453``transfer_map`` creates a memory mapping and the transfer object
454associated with it.
455The returned pointer points to the start of the mapped range according to
456the box region, not the beginning of the resource. If transfer_map fails,
457the returned pointer to the buffer memory is NULL, and the pointer
458to the transfer object remains unchanged (i.e. it can be non-NULL).
Keith Whitwell287c94e2010-04-10 16:05:54 +0100459
Marek Olšák369e4682012-10-08 04:06:42 +0200460``transfer_unmap`` remove the memory mapping for and destroy
461the transfer object. The pointer into the resource should be considered
462invalid and discarded.
Keith Whitwell287c94e2010-04-10 16:05:54 +0100463
464``transfer_inline_write`` performs a simplified transfer for simple writes.
Marek Olšák369e4682012-10-08 04:06:42 +0200465Basically transfer_map, data write, and transfer_unmap all in one.
Keith Whitwell287c94e2010-04-10 16:05:54 +0100466
Brian Paulc5fb0512011-01-28 20:25:27 -0700467
468The box parameter to some of these functions defines a 1D, 2D or 3D
469region of pixels. This is self-explanatory for 1D, 2D and 3D texture
470targets.
471
472For PIPE_TEXTURE_1D_ARRAY, the box::y and box::height fields refer to the
473array dimension of the texture.
474
475For PIPE_TEXTURE_2D_ARRAY, the box::z and box::depth fields refer to the
476array dimension of the texture.
477
478For PIPE_TEXTURE_CUBE, the box:z and box::depth fields refer to the
479faces of the cube map (z + depth <= 6).
480
481
482
Corbin Simpsonbb81f652010-05-17 12:58:29 -0700483.. _transfer_flush_region:
484
485transfer_flush_region
486%%%%%%%%%%%%%%%%%%%%%
487
488If a transfer was created with ``FLUSH_EXPLICIT``, it will not automatically
489be flushed on write or unmap. Flushes must be requested with
490``transfer_flush_region``. Flush ranges are relative to the mapped range, not
491the beginning of the resource.
492
Marek Olšák588fa882011-02-09 01:10:11 +0100493
494
Marek Olšákaea4ed42011-03-08 11:32:35 +0100495.. _texture_barrier
496
497texture_barrier
498%%%%%%%%%%%%%%%
499
500This function flushes all pending writes to the currently-set surfaces and
501invalidates all read caches of the currently-set samplers.
502
503
504
Keith Whitwell287c94e2010-04-10 16:05:54 +0100505.. _pipe_transfer:
506
507PIPE_TRANSFER
508^^^^^^^^^^^^^
509
510These flags control the behavior of a transfer object.
511
José Fonseca0562f442011-02-22 14:14:22 +0000512``PIPE_TRANSFER_READ``
513 Resource contents read back (or accessed directly) at transfer create time.
514
515``PIPE_TRANSFER_WRITE``
Marek Olšák369e4682012-10-08 04:06:42 +0200516 Resource contents will be written back at transfer_unmap time (or modified
José Fonseca0562f442011-02-22 14:14:22 +0000517 as a result of being accessed directly).
518
519``PIPE_TRANSFER_MAP_DIRECTLY``
520 a transfer should directly map the resource. May return NULL if not supported.
521
522``PIPE_TRANSFER_DISCARD_RANGE``
523 The memory within the mapped region is discarded. Cannot be used with
524 ``PIPE_TRANSFER_READ``.
525
526``PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE``
527 Discards all memory backing the resource. It should not be used with
528 ``PIPE_TRANSFER_READ``.
529
530``PIPE_TRANSFER_DONTBLOCK``
531 Fail if the resource cannot be mapped immediately.
532
533``PIPE_TRANSFER_UNSYNCHRONIZED``
534 Do not synchronize pending operations on the resource when mapping. The
535 interaction of any writes to the map and any operations pending on the
536 resource are undefined. Cannot be used with ``PIPE_TRANSFER_READ``.
537
538``PIPE_TRANSFER_FLUSH_EXPLICIT``
539 Written ranges will be notified later with :ref:`transfer_flush_region`.
540 Cannot be used with ``PIPE_TRANSFER_READ``.
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200541
542
543Compute kernel execution
544^^^^^^^^^^^^^^^^^^^^^^^^
545
546A compute program can be defined, bound or destroyed using
547``create_compute_state``, ``bind_compute_state`` or
548``destroy_compute_state`` respectively.
549
550Any of the subroutines contained within the compute program can be
551executed on the device using the ``launch_grid`` method. This method
552will execute as many instances of the program as elements in the
553specified N-dimensional grid, hopefully in parallel.
554
555The compute program has access to four special resources:
556
557* ``GLOBAL`` represents a memory space shared among all the threads
558 running on the device. An arbitrary buffer created with the
559 ``PIPE_BIND_GLOBAL`` flag can be mapped into it using the
560 ``set_global_binding`` method.
561
562* ``LOCAL`` represents a memory space shared among all the threads
563 running in the same working group. The initial contents of this
564 resource are undefined.
565
566* ``PRIVATE`` represents a memory space local to a single thread.
567 The initial contents of this resource are undefined.
568
569* ``INPUT`` represents a read-only memory space that can be
570 initialized at ``launch_grid`` time.
571
572These resources use a byte-based addressing scheme, and they can be
573accessed from the compute program by means of the LOAD/STORE TGSI
Francisco Jerez5f55cbc2012-05-01 02:47:03 +0200574opcodes. Additional resources to be accessed using the same opcodes
575may be specified by the user with the ``set_compute_resources``
576method.
Francisco Jerezd9d82dc2012-04-25 22:15:16 +0200577
578In addition, normal texture sampling is allowed from the compute
579program: ``bind_compute_sampler_states`` may be used to set up texture
580samplers for the compute stage and ``set_compute_sampler_views`` may
581be used to bind a number of sampler views to it.