gallium/docs: fix a typo
[mesa.git] / src / gallium / docs / source / context.rst
1 .. _context:
2
3 Context
4 =======
5
6 A Gallium rendering context encapsulates the state which effects 3D
7 rendering such as blend state, depth/stencil state, texture samplers,
8 etc.
9
10 Note that resource/texture allocation is not per-context but per-screen.
11
12
13 Methods
14 -------
15
16 CSO State
17 ^^^^^^^^^
18
19 All Constant State Object (CSO) state is created, bound, and destroyed,
20 with triplets of methods that all follow a specific naming scheme.
21 For example, ``create_blend_state``, ``bind_blend_state``, and
22 ``destroy_blend_state``.
23
24 CSO objects handled by the context object:
25
26 * :ref:`Blend`: ``*_blend_state``
27 * :ref:`Sampler`: Texture sampler states are bound separately for fragment,
28 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.
33 * :ref:`Rasterizer`: ``*_rasterizer_state``
34 * :ref:`depth-stencil-alpha`: ``*_depth_stencil_alpha_state``
35 * :ref:`Shader`: These are create, bind and destroy methods for vertex,
36 fragment and geometry shaders.
37 * :ref:`vertexelements`: ``*_vertex_elements_state``
38
39
40 Resource Binding State
41 ^^^^^^^^^^^^^^^^^^^^^^
42
43 This state describes how resources in various flavours (textures,
44 buffers, surfaces) are bound to the driver.
45
46
47 * ``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
52 * ``set_framebuffer_state``
53
54 * ``set_vertex_buffers``
55
56
57 Non-CSO State
58 ^^^^^^^^^^^^^
59
60 These pieces of state are too small, variable, and/or trivial to have CSO
61 objects. They all follow simple, one-method binding calls, e.g.
62 ``set_blend_color``.
63
64 * ``set_stencil_ref`` sets the stencil front and back reference values
65 which are used as comparison values in stencil test.
66 * ``set_blend_color``
67 * ``set_sample_mask``
68 * ``set_min_samples`` sets the minimum number of samples that must be run.
69 * ``set_clip_state``
70 * ``set_polygon_stipple``
71 * ``set_scissor_states`` 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
74 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]. The number of scissors
77 should be the same as the number of set viewports and can be up to
78 PIPE_MAX_VIEWPORTS.
79 * ``set_viewport_states``
80 * ``set_window_rectangles`` sets the window rectangles to be used for
81 rendering, as defined by GL_EXT_window_rectangles. There are two
82 modes - include and exclude, which define whether the supplied
83 rectangles are to be used for including fragments or excluding
84 them. All of the rectangles are ORed together, so in exclude mode,
85 any fragment inside any rectangle would be culled, while in include
86 mode, any fragment outside all rectangles would be culled. xmin/ymin
87 are inclusive, while xmax/ymax are exclusive (same as scissor states
88 above). Note that this only applies to draws, not clears or
89 blits. (Blits have their own way to pass the requisite rectangles
90 in.)
91 * ``set_tess_state`` configures the default tessellation parameters:
92
93 * ``default_outer_level`` is the default value for the outer tessellation
94 levels. This corresponds to GL's ``PATCH_DEFAULT_OUTER_LEVEL``.
95 * ``default_inner_level`` is the default value for the inner tessellation
96 levels. This corresponds to GL's ``PATCH_DEFAULT_INNER_LEVEL``.
97
98 * ``set_debug_callback`` sets the callback to be used for reporting
99 various debug messages, eventually reported via KHR_debug and
100 similar mechanisms.
101
102 Samplers
103 ^^^^^^^^
104
105 pipe_sampler_state objects control how textures are sampled (coordinate
106 wrap modes, interpolation modes, etc). Note that samplers are not used
107 for texture buffer objects. That is, pipe_context::bind_sampler_views()
108 will not bind a sampler if the corresponding sampler view refers to a
109 PIPE_BUFFER resource.
110
111 Sampler Views
112 ^^^^^^^^^^^^^
113
114 These are the means to bind textures to shader stages. To create one, specify
115 its format, swizzle and LOD range in sampler view template.
116
117 If texture format is different than template format, it is said the texture
118 is being cast to another format. Casting can be done only between compatible
119 formats, that is formats that have matching component order and sizes.
120
121 Swizzle fields specify the way in which fetched texel components are placed
122 in the result register. For example, ``swizzle_r`` specifies what is going to be
123 placed in first component of result register.
124
125 The ``first_level`` and ``last_level`` fields of sampler view template specify
126 the LOD range the texture is going to be constrained to. Note that these
127 values are in addition to the respective min_lod, max_lod values in the
128 pipe_sampler_state (that is if min_lod is 2.0, and first_level 3, the first mip
129 level used for sampling from the resource is effectively the fifth).
130
131 The ``first_layer`` and ``last_layer`` fields specify the layer range the
132 texture is going to be constrained to. Similar to the LOD range, this is added
133 to the array index which is used for sampling.
134
135 * ``set_sampler_views`` binds an array of sampler views to a shader stage.
136 Every binding point acquires a reference
137 to a respective sampler view and releases a reference to the previous
138 sampler view.
139
140 * ``create_sampler_view`` creates a new sampler view. ``texture`` is associated
141 with the sampler view which results in sampler view holding a reference
142 to the texture. Format specified in template must be compatible
143 with texture format.
144
145 * ``sampler_view_destroy`` destroys a sampler view and releases its reference
146 to associated texture.
147
148 Shader Resources
149 ^^^^^^^^^^^^^^^^
150
151 Shader resources are textures or buffers that may be read or written
152 from a shader without an associated sampler. This means that they
153 have no support for floating point coordinates, address wrap modes or
154 filtering.
155
156 There are 2 types of shader resources: buffers and images.
157
158 Buffers are specified using the ``set_shader_buffers`` method.
159
160 Images are specified using the ``set_shader_images`` method. When binding
161 images, the ``level``, ``first_layer`` and ``last_layer`` pipe_image_view
162 fields specify the mipmap level and the range of layers the image will be
163 constrained to.
164
165 Surfaces
166 ^^^^^^^^
167
168 These are the means to use resources as color render targets or depthstencil
169 attachments. To create one, specify the mip level, the range of layers, and
170 the bind flags (either PIPE_BIND_DEPTH_STENCIL or PIPE_BIND_RENDER_TARGET).
171 Note that layer values are in addition to what is indicated by the geometry
172 shader output variable XXX_FIXME (that is if first_layer is 3 and geometry
173 shader indicates index 2, the 5th layer of the resource will be used). These
174 first_layer and last_layer parameters will only be used for 1d array, 2d array,
175 cube, and 3d textures otherwise they are 0.
176
177 * ``create_surface`` creates a new surface.
178
179 * ``surface_destroy`` destroys a surface and releases its reference to the
180 associated resource.
181
182 Stream output targets
183 ^^^^^^^^^^^^^^^^^^^^^
184
185 Stream output, also known as transform feedback, allows writing the primitives
186 produced by the vertex pipeline to buffers. This is done after the geometry
187 shader or vertex shader if no geometry shader is present.
188
189 The stream output targets are views into buffer resources which can be bound
190 as stream outputs and specify a memory range where it's valid to write
191 primitives. The pipe driver must implement memory protection such that any
192 primitives written outside of the specified memory range are discarded.
193
194 Two stream output targets can use the same resource at the same time, but
195 with a disjoint memory range.
196
197 Additionally, the stream output target internally maintains the offset
198 into the buffer which is incremented everytime something is written to it.
199 The internal offset is equal to how much data has already been written.
200 It can be stored in device memory and the CPU actually doesn't have to query
201 it.
202
203 The stream output target can be used in a draw command to provide
204 the vertex count. The vertex count is derived from the internal offset
205 discussed above.
206
207 * ``create_stream_output_target`` create a new target.
208
209 * ``stream_output_target_destroy`` destroys a target. Users of this should
210 use pipe_so_target_reference instead.
211
212 * ``set_stream_output_targets`` binds stream output targets. The parameter
213 offset is an array which specifies the internal offset of the buffer. The
214 internal offset is, besides writing, used for reading the data during the
215 draw_auto stage, i.e. it specifies how much data there is in the buffer
216 for the purposes of the draw_auto stage. -1 means the buffer should
217 be appended to, and everything else sets the internal offset.
218
219 NOTE: The currently-bound vertex or geometry shader must be compiled with
220 the properly-filled-in structure pipe_stream_output_info describing which
221 outputs should be written to buffers and how. The structure is part of
222 pipe_shader_state.
223
224 Clearing
225 ^^^^^^^^
226
227 Clear is one of the most difficult concepts to nail down to a single
228 interface (due to both different requirements from APIs and also driver/hw
229 specific differences).
230
231 ``clear`` initializes some or all of the surfaces currently bound to
232 the framebuffer to particular RGBA, depth, or stencil values.
233 Currently, this does not take into account color or stencil write masks (as
234 used by GL), and always clears the whole surfaces (no scissoring as used by
235 GL clear or explicit rectangles like d3d9 uses). It can, however, also clear
236 only depth or stencil in a combined depth/stencil surface.
237 If a surface includes several layers then all layers will be cleared.
238
239 ``clear_render_target`` clears a single color rendertarget with the specified
240 color value. While it is only possible to clear one surface at a time (which can
241 include several layers), this surface need not be bound to the framebuffer.
242 If render_condition_enabled is false, any current rendering condition is ignored
243 and the clear will be unconditional.
244
245 ``clear_depth_stencil`` clears a single depth, stencil or depth/stencil surface
246 with the specified depth and stencil values (for combined depth/stencil buffers,
247 it is also possible to only clear one or the other part). While it is only
248 possible to clear one surface at a time (which can include several layers),
249 this surface need not be bound to the framebuffer.
250 If render_condition_enabled is false, any current rendering condition is ignored
251 and the clear will be unconditional.
252
253 ``clear_texture`` clears a non-PIPE_BUFFER resource's specified level
254 and bounding box with a clear value provided in that resource's native
255 format.
256
257 ``clear_buffer`` clears a PIPE_BUFFER resource with the specified clear value
258 (which may be multiple bytes in length). Logically this is a memset with a
259 multi-byte element value starting at offset bytes from resource start, going
260 for size bytes. It is guaranteed that size % clear_value_size == 0.
261
262
263 Uploading
264 ^^^^^^^^^
265
266 For simple single-use uploads, use ``pipe_context::stream_uploader`` or
267 ``pipe_context::const_uploader``. The latter should be used for uploading
268 constants, while the former should be used for uploading everything else.
269 PIPE_USAGE_STREAM is implied in both cases, so don't use the uploaders
270 for static allocations.
271
272 Usage:
273
274 Call u_upload_alloc or u_upload_data as many times as you want. After you are
275 done, call u_upload_unmap. If the driver doesn't support persistent mappings,
276 u_upload_unmap makes sure the previously mapped memory is unmapped.
277
278 Gotchas:
279 - Always fill the memory immediately after u_upload_alloc. Any following call
280 to u_upload_alloc and u_upload_data can unmap memory returned by previous
281 u_upload_alloc.
282 - Don't interleave calls using stream_uploader and const_uploader. If you use
283 one of them, do the upload, unmap, and only then can you use the other one.
284
285
286 Drawing
287 ^^^^^^^
288
289 ``draw_vbo`` draws a specified primitive. The primitive mode and other
290 properties are described by ``pipe_draw_info``.
291
292 The ``mode``, ``start``, and ``count`` fields of ``pipe_draw_info`` specify the
293 the mode of the primitive and the vertices to be fetched, in the range between
294 ``start`` to ``start``+``count``-1, inclusive.
295
296 Every instance with instanceID in the range between ``start_instance`` and
297 ``start_instance``+``instance_count``-1, inclusive, will be drawn.
298
299 If ``index_size`` != 0, all vertex indices will be looked up from the index
300 buffer.
301
302 In indexed draw, ``min_index`` and ``max_index`` respectively provide a lower
303 and upper bound of the indices contained in the index buffer inside the range
304 between ``start`` to ``start``+``count``-1. This allows the driver to
305 determine which subset of vertices will be referenced during te draw call
306 without having to scan the index buffer. Providing a over-estimation of the
307 the true bounds, for example, a ``min_index`` and ``max_index`` of 0 and
308 0xffffffff respectively, must give exactly the same rendering, albeit with less
309 performance due to unreferenced vertex buffers being unnecessarily DMA'ed or
310 processed. Providing a underestimation of the true bounds will result in
311 undefined behavior, but should not result in program or system failure.
312
313 In case of non-indexed draw, ``min_index`` should be set to
314 ``start`` and ``max_index`` should be set to ``start``+``count``-1.
315
316 ``index_bias`` is a value added to every vertex index after lookup and before
317 fetching vertex attributes.
318
319 When drawing indexed primitives, the primitive restart index can be
320 used to draw disjoint primitive strips. For example, several separate
321 line strips can be drawn by designating a special index value as the
322 restart index. The ``primitive_restart`` flag enables/disables this
323 feature. The ``restart_index`` field specifies the restart index value.
324
325 When primitive restart is in use, array indexes are compared to the
326 restart index before adding the index_bias offset.
327
328 If a given vertex element has ``instance_divisor`` set to 0, it is said
329 it contains per-vertex data and effective vertex attribute address needs
330 to be recalculated for every index.
331
332 attribAddr = ``stride`` * index + ``src_offset``
333
334 If a given vertex element has ``instance_divisor`` set to non-zero,
335 it is said it contains per-instance data and effective vertex attribute
336 address needs to recalculated for every ``instance_divisor``-th instance.
337
338 attribAddr = ``stride`` * instanceID / ``instance_divisor`` + ``src_offset``
339
340 In the above formulas, ``src_offset`` is taken from the given vertex element
341 and ``stride`` is taken from a vertex buffer associated with the given
342 vertex element.
343
344 The calculated attribAddr is used as an offset into the vertex buffer to
345 fetch the attribute data.
346
347 The value of ``instanceID`` can be read in a vertex shader through a system
348 value register declared with INSTANCEID semantic name.
349
350
351 Queries
352 ^^^^^^^
353
354 Queries gather some statistic from the 3D pipeline over one or more
355 draws. Queries may be nested, though not all state trackers exercise this.
356
357 Queries can be created with ``create_query`` and deleted with
358 ``destroy_query``. To start a query, use ``begin_query``, and when finished,
359 use ``end_query`` to end the query.
360
361 ``create_query`` takes a query type (``PIPE_QUERY_*``), as well as an index,
362 which is the vertex stream for ``PIPE_QUERY_PRIMITIVES_GENERATED`` and
363 ``PIPE_QUERY_PRIMITIVES_EMITTED``, and allocates a query structure.
364
365 ``begin_query`` will clear/reset previous query results.
366
367 ``get_query_result`` is used to retrieve the results of a query. If
368 the ``wait`` parameter is TRUE, then the ``get_query_result`` call
369 will block until the results of the query are ready (and TRUE will be
370 returned). Otherwise, if the ``wait`` parameter is FALSE, the call
371 will not block and the return value will be TRUE if the query has
372 completed or FALSE otherwise.
373
374 ``get_query_result_resource`` is used to store the result of a query into
375 a resource without synchronizing with the CPU. This write will optionally
376 wait for the query to complete, and will optionally write whether the value
377 is available instead of the value itself.
378
379 ``set_active_query_state`` Set whether all current non-driver queries except
380 TIME_ELAPSED are active or paused.
381
382 The interface currently includes the following types of queries:
383
384 ``PIPE_QUERY_OCCLUSION_COUNTER`` counts the number of fragments which
385 are written to the framebuffer without being culled by
386 :ref:`depth-stencil-alpha` testing or shader KILL instructions.
387 The result is an unsigned 64-bit integer.
388 This query can be used with ``render_condition``.
389
390 In cases where a boolean result of an occlusion query is enough,
391 ``PIPE_QUERY_OCCLUSION_PREDICATE`` should be used. It is just like
392 ``PIPE_QUERY_OCCLUSION_COUNTER`` except that the result is a boolean
393 value of FALSE for cases where COUNTER would result in 0 and TRUE
394 for all other cases.
395 This query can be used with ``render_condition``.
396
397 ``PIPE_QUERY_TIME_ELAPSED`` returns the amount of time, in nanoseconds,
398 the context takes to perform operations.
399 The result is an unsigned 64-bit integer.
400
401 ``PIPE_QUERY_TIMESTAMP`` returns a device/driver internal timestamp,
402 scaled to nanoseconds, recorded after all commands issued prior to
403 ``end_query`` have been processed.
404 This query does not require a call to ``begin_query``.
405 The result is an unsigned 64-bit integer.
406
407 ``PIPE_QUERY_TIMESTAMP_DISJOINT`` can be used to check the
408 internal timer resolution and whether the timestamp counter has become
409 unreliable due to things like throttling etc. - only if this is FALSE
410 a timestamp query (within the timestamp_disjoint query) should be trusted.
411 The result is a 64-bit integer specifying the timer resolution in Hz,
412 followed by a boolean value indicating whether the timestamp counter
413 is discontinuous or disjoint.
414
415 ``PIPE_QUERY_PRIMITIVES_GENERATED`` returns a 64-bit integer indicating
416 the number of primitives processed by the pipeline (regardless of whether
417 stream output is active or not).
418
419 ``PIPE_QUERY_PRIMITIVES_EMITTED`` returns a 64-bit integer indicating
420 the number of primitives written to stream output buffers.
421
422 ``PIPE_QUERY_SO_STATISTICS`` returns 2 64-bit integers corresponding to
423 the result of
424 ``PIPE_QUERY_PRIMITIVES_EMITTED`` and
425 the number of primitives that would have been written to stream output buffers
426 if they had infinite space available (primitives_storage_needed), in this order.
427 XXX the 2nd value is equivalent to ``PIPE_QUERY_PRIMITIVES_GENERATED`` but it is
428 unclear if it should be increased if stream output is not active.
429
430 ``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` returns a boolean value indicating
431 whether a selected stream output target has overflowed as a result of the
432 commands issued between ``begin_query`` and ``end_query``.
433 This query can be used with ``render_condition``. The output stream is
434 selected by the stream number passed to ``create_query``.
435
436 ``PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE`` returns a boolean value indicating
437 whether any stream output target has overflowed as a result of the commands
438 issued between ``begin_query`` and ``end_query``. This query can be used
439 with ``render_condition``, and its result is the logical OR of multiple
440 ``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` queries, one for each stream output
441 target.
442
443 ``PIPE_QUERY_GPU_FINISHED`` returns a boolean value indicating whether
444 all commands issued before ``end_query`` have completed. However, this
445 does not imply serialization.
446 This query does not require a call to ``begin_query``.
447
448 ``PIPE_QUERY_PIPELINE_STATISTICS`` returns an array of the following
449 64-bit integers:
450 Number of vertices read from vertex buffers.
451 Number of primitives read from vertex buffers.
452 Number of vertex shader threads launched.
453 Number of geometry shader threads launched.
454 Number of primitives generated by geometry shaders.
455 Number of primitives forwarded to the rasterizer.
456 Number of primitives rasterized.
457 Number of fragment shader threads launched.
458 Number of tessellation control shader threads launched.
459 Number of tessellation evaluation shader threads launched.
460 If a shader type is not supported by the device/driver,
461 the corresponding values should be set to 0.
462
463 Gallium does not guarantee the availability of any query types; one must
464 always check the capabilities of the :ref:`Screen` first.
465
466
467 Conditional Rendering
468 ^^^^^^^^^^^^^^^^^^^^^
469
470 A drawing command can be skipped depending on the outcome of a query
471 (typically an occlusion query, or streamout overflow predicate).
472 The ``render_condition`` function specifies the query which should be checked
473 prior to rendering anything. Functions always honoring render_condition include
474 (and are limited to) draw_vbo and clear.
475 The blit, clear_render_target and clear_depth_stencil functions (but
476 not resource_copy_region, which seems inconsistent) can also optionally honor
477 the current render condition.
478
479 If ``render_condition`` is called with ``query`` = NULL, conditional
480 rendering is disabled and drawing takes place normally.
481
482 If ``render_condition`` is called with a non-null ``query`` subsequent
483 drawing commands will be predicated on the outcome of the query.
484 Commands will be skipped if ``condition`` is equal to the predicate result
485 (for non-boolean queries such as OCCLUSION_QUERY, zero counts as FALSE,
486 non-zero as TRUE).
487
488 If ``mode`` is PIPE_RENDER_COND_WAIT the driver will wait for the
489 query to complete before deciding whether to render.
490
491 If ``mode`` is PIPE_RENDER_COND_NO_WAIT and the query has not yet
492 completed, the drawing command will be executed normally. If the query
493 has completed, drawing will be predicated on the outcome of the query.
494
495 If ``mode`` is PIPE_RENDER_COND_BY_REGION_WAIT or
496 PIPE_RENDER_COND_BY_REGION_NO_WAIT rendering will be predicated as above
497 for the non-REGION modes but in the case that an occlusion query returns
498 a non-zero result, regions which were occluded may be ommitted by subsequent
499 drawing commands. This can result in better performance with some GPUs.
500 Normally, if the occlusion query returned a non-zero result subsequent
501 drawing happens normally so fragments may be generated, shaded and
502 processed even where they're known to be obscured.
503
504
505 Flushing
506 ^^^^^^^^
507
508 ``flush``
509
510 PIPE_FLUSH_END_OF_FRAME: Whether the flush marks the end of frame.
511
512 PIPE_FLUSH_DEFERRED: It is not required to flush right away, but it is required
513 to return a valid fence. If fence_finish is called with the returned fence
514 and the context is still unflushed, and the ctx parameter of fence_finish is
515 equal to the context where the fence was created, fence_finish will flush
516 the context.
517
518
519 ``flush_resource``
520
521 Flush the resource cache, so that the resource can be used
522 by an external client. Possible usage:
523 - flushing a resource before presenting it on the screen
524 - flushing a resource if some other process or device wants to use it
525 This shouldn't be used to flush caches if the resource is only managed
526 by a single pipe_screen and is not shared with another process.
527 (i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
528 use the resource for texturing)
529
530
531
532 Resource Busy Queries
533 ^^^^^^^^^^^^^^^^^^^^^
534
535 ``is_resource_referenced``
536
537
538
539 Blitting
540 ^^^^^^^^
541
542 These methods emulate classic blitter controls.
543
544 These methods operate directly on ``pipe_resource`` objects, and stand
545 apart from any 3D state in the context. Blitting functionality may be
546 moved to a separate abstraction at some point in the future.
547
548 ``resource_copy_region`` blits a region of a resource to a region of another
549 resource, provided that both resources have the same format, or compatible
550 formats, i.e., formats for which copying the bytes from the source resource
551 unmodified to the destination resource will achieve the same effect of a
552 textured quad blitter.. The source and destination may be the same resource,
553 but overlapping blits are not permitted.
554 This can be considered the equivalent of a CPU memcpy.
555
556 ``blit`` blits a region of a resource to a region of another resource, including
557 scaling, format conversion, and up-/downsampling, as well as a destination clip
558 rectangle (scissors) and window rectangles. It can also optionally honor the
559 current render condition (but either way the blit itself never contributes
560 anything to queries currently gathering data).
561 As opposed to manually drawing a textured quad, this lets the pipe driver choose
562 the optimal method for blitting (like using a special 2D engine), and usually
563 offers, for example, accelerated stencil-only copies even where
564 PIPE_CAP_SHADER_STENCIL_EXPORT is not available.
565
566
567 Transfers
568 ^^^^^^^^^
569
570 These methods are used to get data to/from a resource.
571
572 ``transfer_map`` creates a memory mapping and the transfer object
573 associated with it.
574 The returned pointer points to the start of the mapped range according to
575 the box region, not the beginning of the resource. If transfer_map fails,
576 the returned pointer to the buffer memory is NULL, and the pointer
577 to the transfer object remains unchanged (i.e. it can be non-NULL).
578
579 ``transfer_unmap`` remove the memory mapping for and destroy
580 the transfer object. The pointer into the resource should be considered
581 invalid and discarded.
582
583 ``texture_subdata`` and ``buffer_subdata`` perform a simplified
584 transfer for simple writes. Basically transfer_map, data write, and
585 transfer_unmap all in one.
586
587
588 The box parameter to some of these functions defines a 1D, 2D or 3D
589 region of pixels. This is self-explanatory for 1D, 2D and 3D texture
590 targets.
591
592 For PIPE_TEXTURE_1D_ARRAY and PIPE_TEXTURE_2D_ARRAY, the box::z and box::depth
593 fields refer to the array dimension of the texture.
594
595 For PIPE_TEXTURE_CUBE, the box:z and box::depth fields refer to the
596 faces of the cube map (z + depth <= 6).
597
598 For PIPE_TEXTURE_CUBE_ARRAY, the box:z and box::depth fields refer to both
599 the face and array dimension of the texture (face = z % 6, array = z / 6).
600
601
602 .. _transfer_flush_region:
603
604 transfer_flush_region
605 %%%%%%%%%%%%%%%%%%%%%
606
607 If a transfer was created with ``FLUSH_EXPLICIT``, it will not automatically
608 be flushed on write or unmap. Flushes must be requested with
609 ``transfer_flush_region``. Flush ranges are relative to the mapped range, not
610 the beginning of the resource.
611
612
613
614 .. _texture_barrier:
615
616 texture_barrier
617 %%%%%%%%%%%%%%%
618
619 This function flushes all pending writes to the currently-set surfaces and
620 invalidates all read caches of the currently-set samplers. This can be used
621 for both regular textures as well as for framebuffers read via FBFETCH.
622
623
624
625 .. _memory_barrier:
626
627 memory_barrier
628 %%%%%%%%%%%%%%%
629
630 This function flushes caches according to which of the PIPE_BARRIER_* flags
631 are set.
632
633
634
635 .. _resource_commit:
636
637 resource_commit
638 %%%%%%%%%%%%%%%
639
640 This function changes the commit state of a part of a sparse resource. Sparse
641 resources are created by setting the ``PIPE_RESOURCE_FLAG_SPARSE`` flag when
642 calling ``resource_create``. Initially, sparse resources only reserve a virtual
643 memory region that is not backed by memory (i.e., it is uncommitted). The
644 ``resource_commit`` function can be called to commit or uncommit parts (or all)
645 of a resource. The driver manages the underlying backing memory.
646
647 The contents of newly committed memory regions are undefined. Calling this
648 function to commit an already committed memory region is allowed and leaves its
649 content unchanged. Similarly, calling this function to uncommit an already
650 uncommitted memory region is allowed.
651
652 For buffers, the given box must be aligned to multiples of
653 ``PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE``. As an exception to this rule, if the size
654 of the buffer is not a multiple of the page size, changing the commit state of
655 the last (partial) page requires a box that ends at the end of the buffer
656 (i.e., box->x + box->width == buffer->width0).
657
658
659
660 .. _pipe_transfer:
661
662 PIPE_TRANSFER
663 ^^^^^^^^^^^^^
664
665 These flags control the behavior of a transfer object.
666
667 ``PIPE_TRANSFER_READ``
668 Resource contents read back (or accessed directly) at transfer create time.
669
670 ``PIPE_TRANSFER_WRITE``
671 Resource contents will be written back at transfer_unmap time (or modified
672 as a result of being accessed directly).
673
674 ``PIPE_TRANSFER_MAP_DIRECTLY``
675 a transfer should directly map the resource. May return NULL if not supported.
676
677 ``PIPE_TRANSFER_DISCARD_RANGE``
678 The memory within the mapped region is discarded. Cannot be used with
679 ``PIPE_TRANSFER_READ``.
680
681 ``PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE``
682 Discards all memory backing the resource. It should not be used with
683 ``PIPE_TRANSFER_READ``.
684
685 ``PIPE_TRANSFER_DONTBLOCK``
686 Fail if the resource cannot be mapped immediately.
687
688 ``PIPE_TRANSFER_UNSYNCHRONIZED``
689 Do not synchronize pending operations on the resource when mapping. The
690 interaction of any writes to the map and any operations pending on the
691 resource are undefined. Cannot be used with ``PIPE_TRANSFER_READ``.
692
693 ``PIPE_TRANSFER_FLUSH_EXPLICIT``
694 Written ranges will be notified later with :ref:`transfer_flush_region`.
695 Cannot be used with ``PIPE_TRANSFER_READ``.
696
697 ``PIPE_TRANSFER_PERSISTENT``
698 Allows the resource to be used for rendering while mapped.
699 PIPE_RESOURCE_FLAG_MAP_PERSISTENT must be set when creating
700 the resource.
701 If COHERENT is not set, memory_barrier(PIPE_BARRIER_MAPPED_BUFFER)
702 must be called to ensure the device can see what the CPU has written.
703
704 ``PIPE_TRANSFER_COHERENT``
705 If PERSISTENT is set, this ensures any writes done by the device are
706 immediately visible to the CPU and vice versa.
707 PIPE_RESOURCE_FLAG_MAP_COHERENT must be set when creating
708 the resource.
709
710 Compute kernel execution
711 ^^^^^^^^^^^^^^^^^^^^^^^^
712
713 A compute program can be defined, bound or destroyed using
714 ``create_compute_state``, ``bind_compute_state`` or
715 ``destroy_compute_state`` respectively.
716
717 Any of the subroutines contained within the compute program can be
718 executed on the device using the ``launch_grid`` method. This method
719 will execute as many instances of the program as elements in the
720 specified N-dimensional grid, hopefully in parallel.
721
722 The compute program has access to four special resources:
723
724 * ``GLOBAL`` represents a memory space shared among all the threads
725 running on the device. An arbitrary buffer created with the
726 ``PIPE_BIND_GLOBAL`` flag can be mapped into it using the
727 ``set_global_binding`` method.
728
729 * ``LOCAL`` represents a memory space shared among all the threads
730 running in the same working group. The initial contents of this
731 resource are undefined.
732
733 * ``PRIVATE`` represents a memory space local to a single thread.
734 The initial contents of this resource are undefined.
735
736 * ``INPUT`` represents a read-only memory space that can be
737 initialized at ``launch_grid`` time.
738
739 These resources use a byte-based addressing scheme, and they can be
740 accessed from the compute program by means of the LOAD/STORE TGSI
741 opcodes. Additional resources to be accessed using the same opcodes
742 may be specified by the user with the ``set_compute_resources``
743 method.
744
745 In addition, normal texture sampling is allowed from the compute
746 program: ``bind_sampler_states`` may be used to set up texture
747 samplers for the compute stage and ``set_sampler_views`` may
748 be used to bind a number of sampler views to it.
749
750 Mipmap generation
751 ^^^^^^^^^^^^^^^^^
752
753 If PIPE_CAP_GENERATE_MIPMAP is true, ``generate_mipmap`` can be used
754 to generate mipmaps for the specified texture resource.
755 It replaces texel image levels base_level+1 through
756 last_level for layers range from first_layer through last_layer.
757 It returns TRUE if mipmap generation succeeds, otherwise it
758 returns FALSE. Mipmap generation may fail when it is not supported
759 for particular texture types or formats.
760
761 Device resets
762 ^^^^^^^^^^^^^
763
764 The state tracker can query or request notifications of when the GPU
765 is reset for whatever reason (application error, driver error). When
766 a GPU reset happens, the context becomes unusable and all related state
767 should be considered lost and undefined. Despite that, context
768 notifications are single-shot, i.e. subsequent calls to
769 ``get_device_reset_status`` will return PIPE_NO_RESET.
770
771 * ``get_device_reset_status`` queries whether a device reset has happened
772 since the last call or since the last notification by callback.
773 * ``set_device_reset_callback`` sets a callback which will be called when
774 a device reset is detected. The callback is only called synchronously.
775
776 Bindless
777 ^^^^^^^^
778
779 If PIPE_CAP_BINDLESS_TEXTURE is TRUE, the following ``pipe_context`` functions
780 are used to create/delete bindless handles, and to make them resident in the
781 current context when they are going to be used by shaders.
782
783 * ``create_texture_handle`` creates a 64-bit unsigned integer texture handle
784 that is going to be directly used in shaders.
785 * ``delete_texture_handle`` deletes a 64-bit unsigned integer texture handle.
786 * ``make_texture_handle_resident`` makes a 64-bit unsigned texture handle
787 resident in the current context to be accessible by shaders for texture
788 mapping.
789 * ``create_image_handle`` creates a 64-bit unsigned integer image handle that
790 is going to be directly used in shaders.
791 * ``delete_image_handle`` deletes a 64-bit unsigned integer image handle.
792 * ``make_image_handle_resident`` makes a 64-bit unsigned integer image handle
793 resident in the current context to be accessible by shaders for image loads,
794 stores and atomic operations.
795
796 Using several contexts
797 ----------------------
798
799 Several contexts from the same screen can be used at the same time. Objects
800 created on one context cannot be used in another context, but the objects
801 created by the screen methods can be used by all contexts.
802
803 Transfers
804 ^^^^^^^^^
805 A transfer on one context is not expected to synchronize properly with
806 rendering on other contexts, thus only areas not yet used for rendering should
807 be locked.
808
809 A flush is required after transfer_unmap to expect other contexts to see the
810 uploaded data, unless:
811
812 * Using persistent mapping. Associated with coherent mapping, unmapping the
813 resource is also not required to use it in other contexts. Without coherent
814 mapping, memory_barrier(PIPE_BARRIER_MAPPED_BUFFER) should be called on the
815 context that has mapped the resource. No flush is required.
816
817 * Mapping the resource with PIPE_TRANSFER_MAP_DIRECTLY.