xref: /aosp_15_r20/external/mesa3d/docs/gallium/context.rst (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker.. _context:
2*61046927SAndroid Build Coastguard Worker
3*61046927SAndroid Build Coastguard WorkerContext
4*61046927SAndroid Build Coastguard Worker=======
5*61046927SAndroid Build Coastguard Worker
6*61046927SAndroid Build Coastguard WorkerA Gallium rendering context encapsulates the state which effects 3D
7*61046927SAndroid Build Coastguard Workerrendering such as blend state, depth/stencil state, texture samplers,
8*61046927SAndroid Build Coastguard Workeretc.
9*61046927SAndroid Build Coastguard Worker
10*61046927SAndroid Build Coastguard WorkerNote that resource/texture allocation is not per-context but per-screen.
11*61046927SAndroid Build Coastguard Worker
12*61046927SAndroid Build Coastguard Worker
13*61046927SAndroid Build Coastguard WorkerMethods
14*61046927SAndroid Build Coastguard Worker-------
15*61046927SAndroid Build Coastguard Worker
16*61046927SAndroid Build Coastguard WorkerCSO State
17*61046927SAndroid Build Coastguard Worker^^^^^^^^^
18*61046927SAndroid Build Coastguard Worker
19*61046927SAndroid Build Coastguard WorkerAll Constant State Object (CSO) state is created, bound, and destroyed,
20*61046927SAndroid Build Coastguard Workerwith triplets of methods that all follow a specific naming scheme.
21*61046927SAndroid Build Coastguard WorkerFor example, ``create_blend_state``, ``bind_blend_state``, and
22*61046927SAndroid Build Coastguard Worker``destroy_blend_state``.
23*61046927SAndroid Build Coastguard Worker
24*61046927SAndroid Build Coastguard WorkerCSO objects handled by the context object:
25*61046927SAndroid Build Coastguard Worker
26*61046927SAndroid Build Coastguard Worker* :ref:`Blend`: ``*_blend_state``
27*61046927SAndroid Build Coastguard Worker* :ref:`Sampler`: Texture sampler states are bound separately for fragment,
28*61046927SAndroid Build Coastguard Worker  vertex, geometry and compute shaders with the ``bind_sampler_states``
29*61046927SAndroid Build Coastguard Worker  function.  The ``start`` and ``num_samplers`` parameters indicate a range
30*61046927SAndroid Build Coastguard Worker  of samplers to change.  NOTE: at this time, start is always zero and
31*61046927SAndroid Build Coastguard Worker  the CSO module will always replace all samplers at once (no sub-ranges).
32*61046927SAndroid Build Coastguard Worker  This may change in the future.
33*61046927SAndroid Build Coastguard Worker* :ref:`Rasterizer`: ``*_rasterizer_state``
34*61046927SAndroid Build Coastguard Worker* :ref:`depth-stencil-alpha`: ``*_depth_stencil_alpha_state``
35*61046927SAndroid Build Coastguard Worker* :ref:`Shader`: These are create, bind and destroy methods for vertex,
36*61046927SAndroid Build Coastguard Worker  fragment and geometry shaders.
37*61046927SAndroid Build Coastguard Worker* :ref:`vertexelements`: ``*_vertex_elements_state``
38*61046927SAndroid Build Coastguard Worker
39*61046927SAndroid Build Coastguard Worker
40*61046927SAndroid Build Coastguard WorkerResource Binding State
41*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^
42*61046927SAndroid Build Coastguard Worker
43*61046927SAndroid Build Coastguard WorkerThis state describes how resources in various flavors (textures,
44*61046927SAndroid Build Coastguard Workerbuffers, surfaces) are bound to the driver.
45*61046927SAndroid Build Coastguard Worker
46*61046927SAndroid Build Coastguard Worker
47*61046927SAndroid Build Coastguard Worker* ``set_constant_buffer`` sets a constant buffer to be used for a given shader
48*61046927SAndroid Build Coastguard Worker  type. index is used to indicate which buffer to set (some APIs may allow
49*61046927SAndroid Build Coastguard Worker  multiple ones to be set, and binding a specific one later, though drivers
50*61046927SAndroid Build Coastguard Worker  are mostly restricted to the first one right now).
51*61046927SAndroid Build Coastguard Worker  If take_ownership is true, the buffer reference is passed to the driver, so
52*61046927SAndroid Build Coastguard Worker  that the driver doesn't have to increment the reference count.
53*61046927SAndroid Build Coastguard Worker
54*61046927SAndroid Build Coastguard Worker* ``set_inlinable_constants`` sets inlinable constants for constant buffer 0.
55*61046927SAndroid Build Coastguard Worker
56*61046927SAndroid Build Coastguard WorkerThese are constants that the driver would like to inline in the IR
57*61046927SAndroid Build Coastguard Workerof the current shader and recompile it. Drivers can determine which
58*61046927SAndroid Build Coastguard Workerconstants they prefer to inline in finalize_nir and store that
59*61046927SAndroid Build Coastguard Workerinformation in shader_info::*inlinable_uniform*. When the state tracker
60*61046927SAndroid Build Coastguard Workeror frontend uploads constants to a constant buffer, it can pass
61*61046927SAndroid Build Coastguard Workerinlinable constants separately via this call.
62*61046927SAndroid Build Coastguard Worker
63*61046927SAndroid Build Coastguard WorkerAny ``set_constant_buffer`` call invalidates inlinable constants, so
64*61046927SAndroid Build Coastguard Worker``set_inlinable_constants`` must be called after it. Binding a shader also
65*61046927SAndroid Build Coastguard Workerinvalidates this state.
66*61046927SAndroid Build Coastguard Worker
67*61046927SAndroid Build Coastguard WorkerThere is no ``PIPE_CAP`` for this. Drivers shouldn't set the shader_info
68*61046927SAndroid Build Coastguard Workerfields if they don't implement ``set_inlinable_constants``.
69*61046927SAndroid Build Coastguard Worker
70*61046927SAndroid Build Coastguard Worker* ``set_framebuffer_state``
71*61046927SAndroid Build Coastguard Worker
72*61046927SAndroid Build Coastguard Worker* ``set_vertex_buffers``
73*61046927SAndroid Build Coastguard Worker
74*61046927SAndroid Build Coastguard Worker
75*61046927SAndroid Build Coastguard WorkerNon-CSO State
76*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^
77*61046927SAndroid Build Coastguard Worker
78*61046927SAndroid Build Coastguard WorkerThese pieces of state are too small, variable, and/or trivial to have CSO
79*61046927SAndroid Build Coastguard Workerobjects. They all follow simple, one-method binding calls, e.g.
80*61046927SAndroid Build Coastguard Worker``set_blend_color``.
81*61046927SAndroid Build Coastguard Worker
82*61046927SAndroid Build Coastguard Worker* ``set_stencil_ref`` sets the stencil front and back reference values
83*61046927SAndroid Build Coastguard Worker  which are used as comparison values in stencil test.
84*61046927SAndroid Build Coastguard Worker* ``set_blend_color``
85*61046927SAndroid Build Coastguard Worker* ``set_sample_mask``  sets the per-context multisample sample mask.  Note
86*61046927SAndroid Build Coastguard Worker  that this takes effect even if multisampling is not explicitly enabled if
87*61046927SAndroid Build Coastguard Worker  the framebuffer surface(s) are multisampled.  Also, this mask is AND-ed
88*61046927SAndroid Build Coastguard Worker  with the optional fragment shader sample mask output (when emitted).
89*61046927SAndroid Build Coastguard Worker* ``set_sample_locations`` sets the sample locations used for rasterization.
90*61046927SAndroid Build Coastguard Worker  ```get_sample_position``` still returns the default locations. When NULL,
91*61046927SAndroid Build Coastguard Worker  the default locations are used.
92*61046927SAndroid Build Coastguard Worker* ``set_min_samples`` sets the minimum number of samples that must be run.
93*61046927SAndroid Build Coastguard Worker* ``set_clip_state``
94*61046927SAndroid Build Coastguard Worker* ``set_polygon_stipple``
95*61046927SAndroid Build Coastguard Worker* ``set_scissor_states`` sets the bounds for the scissor test, which culls
96*61046927SAndroid Build Coastguard Worker  pixels before blending to render targets. If the :ref:`Rasterizer` does
97*61046927SAndroid Build Coastguard Worker  not have the scissor test enabled, then the scissor bounds never need to
98*61046927SAndroid Build Coastguard Worker  be set since they will not be used.  Note that scissor xmin and ymin are
99*61046927SAndroid Build Coastguard Worker  inclusive, but  xmax and ymax are exclusive.  The inclusive ranges in x
100*61046927SAndroid Build Coastguard Worker  and y would be [xmin..xmax-1] and [ymin..ymax-1]. The number of scissors
101*61046927SAndroid Build Coastguard Worker  should be the same as the number of set viewports and can be up to
102*61046927SAndroid Build Coastguard Worker  PIPE_MAX_VIEWPORTS.
103*61046927SAndroid Build Coastguard Worker* ``set_viewport_states``
104*61046927SAndroid Build Coastguard Worker* ``set_window_rectangles`` sets the window rectangles to be used for
105*61046927SAndroid Build Coastguard Worker  rendering, as defined by :ext:`GL_EXT_window_rectangles`. There are two
106*61046927SAndroid Build Coastguard Worker  modes - include and exclude, which define whether the supplied
107*61046927SAndroid Build Coastguard Worker  rectangles are to be used for including fragments or excluding
108*61046927SAndroid Build Coastguard Worker  them. All of the rectangles are ORed together, so in exclude mode,
109*61046927SAndroid Build Coastguard Worker  any fragment inside any rectangle would be culled, while in include
110*61046927SAndroid Build Coastguard Worker  mode, any fragment outside all rectangles would be culled. xmin/ymin
111*61046927SAndroid Build Coastguard Worker  are inclusive, while xmax/ymax are exclusive (same as scissor states
112*61046927SAndroid Build Coastguard Worker  above). Note that this only applies to draws, not clears or
113*61046927SAndroid Build Coastguard Worker  blits. (Blits have their own way to pass the requisite rectangles
114*61046927SAndroid Build Coastguard Worker  in.)
115*61046927SAndroid Build Coastguard Worker* ``set_tess_state`` configures the default tessellation parameters:
116*61046927SAndroid Build Coastguard Worker
117*61046927SAndroid Build Coastguard Worker  * ``default_outer_level`` is the default value for the outer tessellation
118*61046927SAndroid Build Coastguard Worker    levels. This corresponds to GL's ``PATCH_DEFAULT_OUTER_LEVEL``.
119*61046927SAndroid Build Coastguard Worker  * ``default_inner_level`` is the default value for the inner tessellation
120*61046927SAndroid Build Coastguard Worker    levels. This corresponds to GL's ``PATCH_DEFAULT_INNER_LEVEL``.
121*61046927SAndroid Build Coastguard Worker* ``set_patch_vertices`` sets the number of vertices per input patch
122*61046927SAndroid Build Coastguard Worker  for tessellation.
123*61046927SAndroid Build Coastguard Worker
124*61046927SAndroid Build Coastguard Worker* ``set_debug_callback`` sets the callback to be used for reporting
125*61046927SAndroid Build Coastguard Worker  various debug messages, eventually reported via :ext:`GL_KHR_debug` and
126*61046927SAndroid Build Coastguard Worker  similar mechanisms.
127*61046927SAndroid Build Coastguard Worker
128*61046927SAndroid Build Coastguard WorkerSamplers
129*61046927SAndroid Build Coastguard Worker^^^^^^^^
130*61046927SAndroid Build Coastguard Worker
131*61046927SAndroid Build Coastguard Workerpipe_sampler_state objects control how textures are sampled (coordinate wrap
132*61046927SAndroid Build Coastguard Workermodes, interpolation modes, etc). Samplers are only required for texture
133*61046927SAndroid Build Coastguard Workerinstructions for which nir_tex_instr_need_sampler returns true. Drivers must
134*61046927SAndroid Build Coastguard Workerignore samplers for other texture instructions. Frontends may or may not bind
135*61046927SAndroid Build Coastguard Workersamplers when no texture instruction use them. Notably, frontends may not bind
136*61046927SAndroid Build Coastguard Workersamplers for texture buffer objects, which are never accessed with samplers.
137*61046927SAndroid Build Coastguard Worker
138*61046927SAndroid Build Coastguard WorkerSampler Views
139*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^
140*61046927SAndroid Build Coastguard Worker
141*61046927SAndroid Build Coastguard WorkerThese are the means to bind textures to shader stages. To create one, specify
142*61046927SAndroid Build Coastguard Workerits format, swizzle and LOD range in sampler view template.
143*61046927SAndroid Build Coastguard Worker
144*61046927SAndroid Build Coastguard WorkerIf texture format is different than template format, it is said the texture
145*61046927SAndroid Build Coastguard Workeris being cast to another format. Casting can be done only between compatible
146*61046927SAndroid Build Coastguard Workerformats, that is formats that have matching component order and sizes.
147*61046927SAndroid Build Coastguard Worker
148*61046927SAndroid Build Coastguard WorkerSwizzle fields specify the way in which fetched texel components are placed
149*61046927SAndroid Build Coastguard Workerin the result register. For example, ``swizzle_r`` specifies what is going to be
150*61046927SAndroid Build Coastguard Workerplaced in first component of result register.
151*61046927SAndroid Build Coastguard Worker
152*61046927SAndroid Build Coastguard WorkerThe ``first_level`` and ``last_level`` fields of sampler view template specify
153*61046927SAndroid Build Coastguard Workerthe LOD range the texture is going to be constrained to. Note that these
154*61046927SAndroid Build Coastguard Workervalues are in addition to the respective min_lod, max_lod values in the
155*61046927SAndroid Build Coastguard Workerpipe_sampler_state (that is if min_lod is 2.0, and first_level 3, the first mip
156*61046927SAndroid Build Coastguard Workerlevel used for sampling from the resource is effectively the fifth).
157*61046927SAndroid Build Coastguard Worker
158*61046927SAndroid Build Coastguard WorkerThe ``first_layer`` and ``last_layer`` fields specify the layer range the
159*61046927SAndroid Build Coastguard Workertexture is going to be constrained to. Similar to the LOD range, this is added
160*61046927SAndroid Build Coastguard Workerto the array index which is used for sampling.
161*61046927SAndroid Build Coastguard Worker
162*61046927SAndroid Build Coastguard Worker* ``set_sampler_views`` binds an array of sampler views to a shader stage.
163*61046927SAndroid Build Coastguard Worker  Every binding point acquires a reference
164*61046927SAndroid Build Coastguard Worker  to a respective sampler view and releases a reference to the previous
165*61046927SAndroid Build Coastguard Worker  sampler view.
166*61046927SAndroid Build Coastguard Worker
167*61046927SAndroid Build Coastguard Worker  Sampler views outside of ``[start_slot, start_slot + num_views)`` are
168*61046927SAndroid Build Coastguard Worker  unmodified.  If ``views`` is NULL, the behavior is the same as if
169*61046927SAndroid Build Coastguard Worker  ``views[n]`` was NULL for the entire range, i.e. releasing the reference
170*61046927SAndroid Build Coastguard Worker  for all the sampler views in the specified range.
171*61046927SAndroid Build Coastguard Worker
172*61046927SAndroid Build Coastguard Worker* ``create_sampler_view`` creates a new sampler view. ``texture`` is associated
173*61046927SAndroid Build Coastguard Worker  with the sampler view which results in sampler view holding a reference
174*61046927SAndroid Build Coastguard Worker  to the texture. Format specified in template must be compatible
175*61046927SAndroid Build Coastguard Worker  with texture format.
176*61046927SAndroid Build Coastguard Worker
177*61046927SAndroid Build Coastguard Worker* ``sampler_view_destroy`` destroys a sampler view and releases its reference
178*61046927SAndroid Build Coastguard Worker  to associated texture.
179*61046927SAndroid Build Coastguard Worker
180*61046927SAndroid Build Coastguard WorkerHardware Atomic buffers
181*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^
182*61046927SAndroid Build Coastguard Worker
183*61046927SAndroid Build Coastguard WorkerBuffers containing HW atomics are required to support the feature
184*61046927SAndroid Build Coastguard Workeron some drivers.
185*61046927SAndroid Build Coastguard Worker
186*61046927SAndroid Build Coastguard WorkerDrivers that require this need to fill the ``set_hw_atomic_buffers`` method.
187*61046927SAndroid Build Coastguard Worker
188*61046927SAndroid Build Coastguard WorkerShader Resources
189*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^
190*61046927SAndroid Build Coastguard Worker
191*61046927SAndroid Build Coastguard WorkerShader resources are textures or buffers that may be read or written
192*61046927SAndroid Build Coastguard Workerfrom a shader without an associated sampler.  This means that they
193*61046927SAndroid Build Coastguard Workerhave no support for floating point coordinates, address wrap modes or
194*61046927SAndroid Build Coastguard Workerfiltering.
195*61046927SAndroid Build Coastguard Worker
196*61046927SAndroid Build Coastguard WorkerThere are 2 types of shader resources: buffers and images.
197*61046927SAndroid Build Coastguard Worker
198*61046927SAndroid Build Coastguard WorkerBuffers are specified using the ``set_shader_buffers`` method.
199*61046927SAndroid Build Coastguard Worker
200*61046927SAndroid Build Coastguard WorkerImages are specified using the ``set_shader_images`` method. When binding
201*61046927SAndroid Build Coastguard Workerimages, the ``level``, ``first_layer`` and ``last_layer`` pipe_image_view
202*61046927SAndroid Build Coastguard Workerfields specify the mipmap level and the range of layers the image will be
203*61046927SAndroid Build Coastguard Workerconstrained to.
204*61046927SAndroid Build Coastguard Worker
205*61046927SAndroid Build Coastguard WorkerSurfaces
206*61046927SAndroid Build Coastguard Worker^^^^^^^^
207*61046927SAndroid Build Coastguard Worker
208*61046927SAndroid Build Coastguard WorkerThese are the means to use resources as color render targets or depthstencil
209*61046927SAndroid Build Coastguard Workerattachments. To create one, specify the mip level, the range of layers, and
210*61046927SAndroid Build Coastguard Workerthe bind flags (either PIPE_BIND_DEPTH_STENCIL or PIPE_BIND_RENDER_TARGET).
211*61046927SAndroid Build Coastguard WorkerNote that layer values are in addition to what is indicated by the geometry
212*61046927SAndroid Build Coastguard Workershader output variable XXX_FIXME (that is if first_layer is 3 and geometry
213*61046927SAndroid Build Coastguard Workershader indicates index 2, the 5th layer of the resource will be used). These
214*61046927SAndroid Build Coastguard Workerfirst_layer and last_layer parameters will only be used for 1d array, 2d array,
215*61046927SAndroid Build Coastguard Workercube, and 3d textures otherwise they are 0.
216*61046927SAndroid Build Coastguard Worker
217*61046927SAndroid Build Coastguard Worker* ``create_surface`` creates a new surface.
218*61046927SAndroid Build Coastguard Worker
219*61046927SAndroid Build Coastguard Worker* ``surface_destroy`` destroys a surface and releases its reference to the
220*61046927SAndroid Build Coastguard Worker  associated resource.
221*61046927SAndroid Build Coastguard Worker
222*61046927SAndroid Build Coastguard WorkerStream output targets
223*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^
224*61046927SAndroid Build Coastguard Worker
225*61046927SAndroid Build Coastguard WorkerStream output, also known as transform feedback, allows writing the primitives
226*61046927SAndroid Build Coastguard Workerproduced by the vertex pipeline to buffers. This is done after the geometry
227*61046927SAndroid Build Coastguard Workershader or vertex shader if no geometry shader is present.
228*61046927SAndroid Build Coastguard Worker
229*61046927SAndroid Build Coastguard WorkerThe stream output targets are views into buffer resources which can be bound
230*61046927SAndroid Build Coastguard Workeras stream outputs and specify a memory range where it's valid to write
231*61046927SAndroid Build Coastguard Workerprimitives. The pipe driver must implement memory protection such that any
232*61046927SAndroid Build Coastguard Workerprimitives written outside of the specified memory range are discarded.
233*61046927SAndroid Build Coastguard Worker
234*61046927SAndroid Build Coastguard WorkerTwo stream output targets can use the same resource at the same time, but
235*61046927SAndroid Build Coastguard Workerwith a disjoint memory range.
236*61046927SAndroid Build Coastguard Worker
237*61046927SAndroid Build Coastguard WorkerAdditionally, the stream output target internally maintains the offset
238*61046927SAndroid Build Coastguard Workerinto the buffer which is incremented every time something is written to it.
239*61046927SAndroid Build Coastguard WorkerThe internal offset is equal to how much data has already been written.
240*61046927SAndroid Build Coastguard WorkerIt can be stored in device memory and the CPU actually doesn't have to query
241*61046927SAndroid Build Coastguard Workerit.
242*61046927SAndroid Build Coastguard Worker
243*61046927SAndroid Build Coastguard WorkerThe stream output target can be used in a draw command to provide
244*61046927SAndroid Build Coastguard Workerthe vertex count. The vertex count is derived from the internal offset
245*61046927SAndroid Build Coastguard Workerdiscussed above.
246*61046927SAndroid Build Coastguard Worker
247*61046927SAndroid Build Coastguard Worker* ``create_stream_output_target`` create a new target.
248*61046927SAndroid Build Coastguard Worker
249*61046927SAndroid Build Coastguard Worker* ``stream_output_target_destroy`` destroys a target. Users of this should
250*61046927SAndroid Build Coastguard Worker  use pipe_so_target_reference instead.
251*61046927SAndroid Build Coastguard Worker
252*61046927SAndroid Build Coastguard Worker* ``set_stream_output_targets`` binds stream output targets. The parameter
253*61046927SAndroid Build Coastguard Worker  offset is an array which specifies the internal offset of the buffer. The
254*61046927SAndroid Build Coastguard Worker  internal offset is, besides writing, used for reading the data during the
255*61046927SAndroid Build Coastguard Worker  draw_auto stage, i.e. it specifies how much data there is in the buffer
256*61046927SAndroid Build Coastguard Worker  for the purposes of the draw_auto stage. -1 means the buffer should
257*61046927SAndroid Build Coastguard Worker  be appended to, and everything else sets the internal offset.
258*61046927SAndroid Build Coastguard Worker
259*61046927SAndroid Build Coastguard Worker* ``stream_output_target_offset`` Retrieve the internal stream offset from
260*61046927SAndroid Build Coastguard Worker  an streamout target. This is used to implement Vulkan pause/resume support
261*61046927SAndroid Build Coastguard Worker  which needs to pass the internal offset to the API.
262*61046927SAndroid Build Coastguard Worker
263*61046927SAndroid Build Coastguard WorkerNOTE: The currently-bound vertex or geometry shader must be compiled with
264*61046927SAndroid Build Coastguard Workerthe properly-filled-in structure pipe_stream_output_info describing which
265*61046927SAndroid Build Coastguard Workeroutputs should be written to buffers and how. The structure is part of
266*61046927SAndroid Build Coastguard Workerpipe_shader_state.
267*61046927SAndroid Build Coastguard Worker
268*61046927SAndroid Build Coastguard WorkerClearing
269*61046927SAndroid Build Coastguard Worker^^^^^^^^
270*61046927SAndroid Build Coastguard Worker
271*61046927SAndroid Build Coastguard WorkerClear is one of the most difficult concepts to nail down to a single
272*61046927SAndroid Build Coastguard Workerinterface (due to both different requirements from APIs and also driver/HW
273*61046927SAndroid Build Coastguard Workerspecific differences).
274*61046927SAndroid Build Coastguard Worker
275*61046927SAndroid Build Coastguard Worker``clear`` initializes some or all of the surfaces currently bound to
276*61046927SAndroid Build Coastguard Workerthe framebuffer to particular RGBA, depth, or stencil values.
277*61046927SAndroid Build Coastguard WorkerCurrently, this does not take into account color or stencil write masks (as
278*61046927SAndroid Build Coastguard Workerused by GL), and always clears the whole surfaces (no scissoring as used by
279*61046927SAndroid Build Coastguard WorkerGL clear or explicit rectangles like d3d9 uses). It can, however, also clear
280*61046927SAndroid Build Coastguard Workeronly depth or stencil in a combined depth/stencil surface.
281*61046927SAndroid Build Coastguard WorkerIf a surface includes several layers then all layers will be cleared.
282*61046927SAndroid Build Coastguard Worker
283*61046927SAndroid Build Coastguard Worker``clear_render_target`` clears a single color rendertarget with the specified
284*61046927SAndroid Build Coastguard Workercolor value. While it is only possible to clear one surface at a time (which can
285*61046927SAndroid Build Coastguard Workerinclude several layers), this surface need not be bound to the framebuffer.
286*61046927SAndroid Build Coastguard WorkerIf render_condition_enabled is false, any current rendering condition is ignored
287*61046927SAndroid Build Coastguard Workerand the clear will be unconditional.
288*61046927SAndroid Build Coastguard Worker
289*61046927SAndroid Build Coastguard Worker``clear_depth_stencil`` clears a single depth, stencil or depth/stencil surface
290*61046927SAndroid Build Coastguard Workerwith the specified depth and stencil values (for combined depth/stencil buffers,
291*61046927SAndroid Build Coastguard Workerit is also possible to only clear one or the other part). While it is only
292*61046927SAndroid Build Coastguard Workerpossible to clear one surface at a time (which can include several layers),
293*61046927SAndroid Build Coastguard Workerthis surface need not be bound to the framebuffer.
294*61046927SAndroid Build Coastguard WorkerIf render_condition_enabled is false, any current rendering condition is ignored
295*61046927SAndroid Build Coastguard Workerand the clear will be unconditional.
296*61046927SAndroid Build Coastguard Worker
297*61046927SAndroid Build Coastguard Worker``clear_texture`` clears a non-PIPE_BUFFER resource's specified level
298*61046927SAndroid Build Coastguard Workerand bounding box with a clear value provided in that resource's native
299*61046927SAndroid Build Coastguard Workerformat.
300*61046927SAndroid Build Coastguard Worker
301*61046927SAndroid Build Coastguard Worker``clear_buffer`` clears a PIPE_BUFFER resource with the specified clear value
302*61046927SAndroid Build Coastguard Worker(which may be multiple bytes in length). Logically this is a memset with a
303*61046927SAndroid Build Coastguard Workermulti-byte element value starting at offset bytes from resource start, going
304*61046927SAndroid Build Coastguard Workerfor size bytes. It is guaranteed that size % clear_value_size == 0.
305*61046927SAndroid Build Coastguard Worker
306*61046927SAndroid Build Coastguard WorkerEvaluating Depth Buffers
307*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^
308*61046927SAndroid Build Coastguard Worker
309*61046927SAndroid Build Coastguard Worker``evaluate_depth_buffer`` is a hint to decompress the current depth buffer
310*61046927SAndroid Build Coastguard Workerassuming the current sample locations to avoid problems that could arise when
311*61046927SAndroid Build Coastguard Workerusing programmable sample locations.
312*61046927SAndroid Build Coastguard Worker
313*61046927SAndroid Build Coastguard WorkerIf a depth buffer is rendered with different sample location state than
314*61046927SAndroid Build Coastguard Workerwhat is current at the time of reading the depth buffer, the values may differ
315*61046927SAndroid Build Coastguard Workerbecause depth buffer compression can depend the sample locations.
316*61046927SAndroid Build Coastguard Worker
317*61046927SAndroid Build Coastguard Worker
318*61046927SAndroid Build Coastguard WorkerUploading
319*61046927SAndroid Build Coastguard Worker^^^^^^^^^
320*61046927SAndroid Build Coastguard Worker
321*61046927SAndroid Build Coastguard WorkerFor simple single-use uploads, use ``pipe_context::stream_uploader`` or
322*61046927SAndroid Build Coastguard Worker``pipe_context::const_uploader``. The latter should be used for uploading
323*61046927SAndroid Build Coastguard Workerconstants, while the former should be used for uploading everything else.
324*61046927SAndroid Build Coastguard WorkerPIPE_USAGE_STREAM is implied in both cases, so don't use the uploaders
325*61046927SAndroid Build Coastguard Workerfor static allocations.
326*61046927SAndroid Build Coastguard Worker
327*61046927SAndroid Build Coastguard WorkerUsage:
328*61046927SAndroid Build Coastguard Worker
329*61046927SAndroid Build Coastguard WorkerCall u_upload_alloc or u_upload_data as many times as you want. After you are
330*61046927SAndroid Build Coastguard Workerdone, call u_upload_unmap. If the driver doesn't support persistent mappings,
331*61046927SAndroid Build Coastguard Workeru_upload_unmap makes sure the previously mapped memory is unmapped.
332*61046927SAndroid Build Coastguard Worker
333*61046927SAndroid Build Coastguard WorkerGotchas:
334*61046927SAndroid Build Coastguard Worker- Always fill the memory immediately after u_upload_alloc. Any following call
335*61046927SAndroid Build Coastguard Workerto u_upload_alloc and u_upload_data can unmap memory returned by previous
336*61046927SAndroid Build Coastguard Workeru_upload_alloc.
337*61046927SAndroid Build Coastguard Worker- Don't interleave calls using stream_uploader and const_uploader. If you use
338*61046927SAndroid Build Coastguard Workerone of them, do the upload, unmap, and only then can you use the other one.
339*61046927SAndroid Build Coastguard Worker
340*61046927SAndroid Build Coastguard Worker
341*61046927SAndroid Build Coastguard WorkerDrawing
342*61046927SAndroid Build Coastguard Worker^^^^^^^
343*61046927SAndroid Build Coastguard Worker
344*61046927SAndroid Build Coastguard Worker``draw_vbo`` draws a specified primitive.  The primitive mode and other
345*61046927SAndroid Build Coastguard Workerproperties are described by ``pipe_draw_info``.
346*61046927SAndroid Build Coastguard Worker
347*61046927SAndroid Build Coastguard WorkerThe ``mode``, ``start``, and ``count`` fields of ``pipe_draw_info`` specify the
348*61046927SAndroid Build Coastguard Workerthe mode of the primitive and the vertices to be fetched, in the range between
349*61046927SAndroid Build Coastguard Worker``start`` to ``start``+``count``-1, inclusive.
350*61046927SAndroid Build Coastguard Worker
351*61046927SAndroid Build Coastguard WorkerEvery instance with instanceID in the range between ``start_instance`` and
352*61046927SAndroid Build Coastguard Worker``start_instance``+``instance_count``-1, inclusive, will be drawn.
353*61046927SAndroid Build Coastguard Worker
354*61046927SAndroid Build Coastguard WorkerIf  ``index_size`` != 0, all vertex indices will be looked up from the index
355*61046927SAndroid Build Coastguard Workerbuffer.
356*61046927SAndroid Build Coastguard Worker
357*61046927SAndroid Build Coastguard WorkerIn indexed draw, ``min_index`` and ``max_index`` respectively provide a lower
358*61046927SAndroid Build Coastguard Workerand upper bound of the indices contained in the index buffer inside the range
359*61046927SAndroid Build Coastguard Workerbetween ``start`` to ``start``+``count``-1.  This allows the driver to
360*61046927SAndroid Build Coastguard Workerdetermine which subset of vertices will be referenced during the draw call
361*61046927SAndroid Build Coastguard Workerwithout having to scan the index buffer.  Providing a over-estimation of the
362*61046927SAndroid Build Coastguard Workerthe true bounds, for example, a ``min_index`` and ``max_index`` of 0 and
363*61046927SAndroid Build Coastguard Worker0xffffffff respectively, must give exactly the same rendering, albeit with less
364*61046927SAndroid Build Coastguard Workerperformance due to unreferenced vertex buffers being unnecessarily DMA'ed or
365*61046927SAndroid Build Coastguard Workerprocessed.  Providing a underestimation of the true bounds will result in
366*61046927SAndroid Build Coastguard Workerundefined behavior, but should not result in program or system failure.
367*61046927SAndroid Build Coastguard Worker
368*61046927SAndroid Build Coastguard WorkerIn case of non-indexed draw, ``min_index`` should be set to
369*61046927SAndroid Build Coastguard Worker``start`` and ``max_index`` should be set to ``start``+``count``-1.
370*61046927SAndroid Build Coastguard Worker
371*61046927SAndroid Build Coastguard Worker``index_bias`` is a value added to every vertex index after lookup and before
372*61046927SAndroid Build Coastguard Workerfetching vertex attributes.
373*61046927SAndroid Build Coastguard Worker
374*61046927SAndroid Build Coastguard WorkerWhen drawing indexed primitives, the primitive restart index can be
375*61046927SAndroid Build Coastguard Workerused to draw disjoint primitive strips.  For example, several separate
376*61046927SAndroid Build Coastguard Workerline strips can be drawn by designating a special index value as the
377*61046927SAndroid Build Coastguard Workerrestart index.  The ``primitive_restart`` flag enables/disables this
378*61046927SAndroid Build Coastguard Workerfeature.  The ``restart_index`` field specifies the restart index value.
379*61046927SAndroid Build Coastguard Worker
380*61046927SAndroid Build Coastguard WorkerWhen primitive restart is in use, array indexes are compared to the
381*61046927SAndroid Build Coastguard Workerrestart index before adding the index_bias offset.
382*61046927SAndroid Build Coastguard Worker
383*61046927SAndroid Build Coastguard WorkerIf a given vertex element has ``instance_divisor`` set to 0, it is said
384*61046927SAndroid Build Coastguard Workerit contains per-vertex data and effective vertex attribute address needs
385*61046927SAndroid Build Coastguard Workerto be recalculated for every index.
386*61046927SAndroid Build Coastguard Worker
387*61046927SAndroid Build Coastguard Worker  attribAddr = ``stride`` * index + ``src_offset``
388*61046927SAndroid Build Coastguard Worker
389*61046927SAndroid Build Coastguard WorkerIf a given vertex element has ``instance_divisor`` set to non-zero,
390*61046927SAndroid Build Coastguard Workerit is said it contains per-instance data and effective vertex attribute
391*61046927SAndroid Build Coastguard Workeraddress needs to recalculated for every ``instance_divisor``-th instance.
392*61046927SAndroid Build Coastguard Worker
393*61046927SAndroid Build Coastguard Worker  attribAddr = ``stride`` * instanceID / ``instance_divisor`` + ``src_offset``
394*61046927SAndroid Build Coastguard Worker
395*61046927SAndroid Build Coastguard WorkerIn the above formulas, ``src_offset`` is taken from the given vertex element
396*61046927SAndroid Build Coastguard Workerand ``stride`` is taken from a vertex buffer associated with the given
397*61046927SAndroid Build Coastguard Workervertex element.
398*61046927SAndroid Build Coastguard Worker
399*61046927SAndroid Build Coastguard WorkerThe calculated attribAddr is used as an offset into the vertex buffer to
400*61046927SAndroid Build Coastguard Workerfetch the attribute data.
401*61046927SAndroid Build Coastguard Worker
402*61046927SAndroid Build Coastguard WorkerThe value of ``instanceID`` can be read in a vertex shader through a system
403*61046927SAndroid Build Coastguard Workervalue register declared with INSTANCEID semantic name.
404*61046927SAndroid Build Coastguard Worker
405*61046927SAndroid Build Coastguard Worker
406*61046927SAndroid Build Coastguard WorkerQueries
407*61046927SAndroid Build Coastguard Worker^^^^^^^
408*61046927SAndroid Build Coastguard Worker
409*61046927SAndroid Build Coastguard WorkerQueries gather some statistic from the 3D pipeline over one or more
410*61046927SAndroid Build Coastguard Workerdraws.  Queries may be nested, though not all gallium frontends exercise this.
411*61046927SAndroid Build Coastguard Worker
412*61046927SAndroid Build Coastguard WorkerQueries can be created with ``create_query`` and deleted with
413*61046927SAndroid Build Coastguard Worker``destroy_query``. To start a query, use ``begin_query``, and when finished,
414*61046927SAndroid Build Coastguard Workeruse ``end_query`` to end the query.
415*61046927SAndroid Build Coastguard Worker
416*61046927SAndroid Build Coastguard Worker``create_query`` takes a query type (``PIPE_QUERY_*``), as well as an index,
417*61046927SAndroid Build Coastguard Workerwhich is the vertex stream for ``PIPE_QUERY_PRIMITIVES_GENERATED`` and
418*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PRIMITIVES_EMITTED``, and allocates a query structure.
419*61046927SAndroid Build Coastguard Worker
420*61046927SAndroid Build Coastguard Worker``begin_query`` will clear/reset previous query results.
421*61046927SAndroid Build Coastguard Worker
422*61046927SAndroid Build Coastguard Worker``get_query_result`` is used to retrieve the results of a query.  If
423*61046927SAndroid Build Coastguard Workerthe ``wait`` parameter is TRUE, then the ``get_query_result`` call
424*61046927SAndroid Build Coastguard Workerwill block until the results of the query are ready (and TRUE will be
425*61046927SAndroid Build Coastguard Workerreturned).  Otherwise, if the ``wait`` parameter is FALSE, the call
426*61046927SAndroid Build Coastguard Workerwill not block and the return value will be TRUE if the query has
427*61046927SAndroid Build Coastguard Workercompleted or FALSE otherwise.
428*61046927SAndroid Build Coastguard Worker
429*61046927SAndroid Build Coastguard Worker``get_query_result_resource`` is used to store the result of a query into
430*61046927SAndroid Build Coastguard Workera resource without synchronizing with the CPU. This write will optionally
431*61046927SAndroid Build Coastguard Workerwait for the query to complete, and will optionally write whether the value
432*61046927SAndroid Build Coastguard Workeris available instead of the value itself.
433*61046927SAndroid Build Coastguard Worker
434*61046927SAndroid Build Coastguard Worker``set_active_query_state`` Set whether all current non-driver queries except
435*61046927SAndroid Build Coastguard WorkerTIME_ELAPSED are active or paused.
436*61046927SAndroid Build Coastguard Worker
437*61046927SAndroid Build Coastguard WorkerThe interface currently includes the following types of queries:
438*61046927SAndroid Build Coastguard Worker
439*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_OCCLUSION_COUNTER`` counts the number of fragments which
440*61046927SAndroid Build Coastguard Workerare written to the framebuffer without being culled by
441*61046927SAndroid Build Coastguard Worker:ref:`depth-stencil-alpha` testing or shader KILL instructions.
442*61046927SAndroid Build Coastguard WorkerThe result is an unsigned 64-bit integer.
443*61046927SAndroid Build Coastguard WorkerThis query can be used with ``render_condition``.
444*61046927SAndroid Build Coastguard Worker
445*61046927SAndroid Build Coastguard WorkerIn cases where a boolean result of an occlusion query is enough,
446*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_OCCLUSION_PREDICATE`` should be used. It is just like
447*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_OCCLUSION_COUNTER`` except that the result is a boolean
448*61046927SAndroid Build Coastguard Workervalue of FALSE for cases where COUNTER would result in 0 and TRUE
449*61046927SAndroid Build Coastguard Workerfor all other cases.
450*61046927SAndroid Build Coastguard WorkerThis query can be used with ``render_condition``.
451*61046927SAndroid Build Coastguard Worker
452*61046927SAndroid Build Coastguard WorkerIn cases where a conservative approximation of an occlusion query is enough,
453*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_OCCLUSION_PREDICATE_CONSERVATIVE`` should be used. It behaves
454*61046927SAndroid Build Coastguard Workerlike ``PIPE_QUERY_OCCLUSION_PREDICATE``, except that it may return TRUE in
455*61046927SAndroid Build Coastguard Workeradditional, implementation-dependent cases.
456*61046927SAndroid Build Coastguard WorkerThis query can be used with ``render_condition``.
457*61046927SAndroid Build Coastguard Worker
458*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_TIME_ELAPSED`` returns the amount of time, in nanoseconds,
459*61046927SAndroid Build Coastguard Workerthe context takes to perform operations.
460*61046927SAndroid Build Coastguard WorkerThe result is an unsigned 64-bit integer.
461*61046927SAndroid Build Coastguard Worker
462*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_TIMESTAMP`` returns a device/driver internal timestamp,
463*61046927SAndroid Build Coastguard Workerscaled to nanoseconds, recorded after all commands issued prior to
464*61046927SAndroid Build Coastguard Worker``end_query`` have been processed.
465*61046927SAndroid Build Coastguard WorkerThis query does not require a call to ``begin_query``.
466*61046927SAndroid Build Coastguard WorkerThe result is an unsigned 64-bit integer.
467*61046927SAndroid Build Coastguard Worker
468*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_TIMESTAMP_DISJOINT`` can be used to check the
469*61046927SAndroid Build Coastguard Workerinternal timer resolution and whether the timestamp counter has become
470*61046927SAndroid Build Coastguard Workerunreliable due to things like throttling etc. - only if this is FALSE
471*61046927SAndroid Build Coastguard Workera timestamp query (within the timestamp_disjoint query) should be trusted.
472*61046927SAndroid Build Coastguard WorkerThe result is a 64-bit integer specifying the timer resolution in Hz,
473*61046927SAndroid Build Coastguard Workerfollowed by a boolean value indicating whether the timestamp counter
474*61046927SAndroid Build Coastguard Workeris discontinuous or disjoint.
475*61046927SAndroid Build Coastguard Worker
476*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PRIMITIVES_GENERATED`` returns a 64-bit integer indicating
477*61046927SAndroid Build Coastguard Workerthe number of primitives processed by the pipeline (regardless of whether
478*61046927SAndroid Build Coastguard Workerstream output is active or not).
479*61046927SAndroid Build Coastguard Worker
480*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PRIMITIVES_EMITTED`` returns a 64-bit integer indicating
481*61046927SAndroid Build Coastguard Workerthe number of primitives written to stream output buffers.
482*61046927SAndroid Build Coastguard Worker
483*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_SO_STATISTICS`` returns 2 64-bit integers corresponding to
484*61046927SAndroid Build Coastguard Workerthe result of
485*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PRIMITIVES_EMITTED`` and
486*61046927SAndroid Build Coastguard Workerthe number of primitives that would have been written to stream output buffers
487*61046927SAndroid Build Coastguard Workerif they had infinite space available (primitives_storage_needed), in this order.
488*61046927SAndroid Build Coastguard WorkerXXX the 2nd value is equivalent to ``PIPE_QUERY_PRIMITIVES_GENERATED`` but it is
489*61046927SAndroid Build Coastguard Workerunclear if it should be increased if stream output is not active.
490*61046927SAndroid Build Coastguard Worker
491*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` returns a boolean value indicating
492*61046927SAndroid Build Coastguard Workerwhether a selected stream output target has overflowed as a result of the
493*61046927SAndroid Build Coastguard Workercommands issued between ``begin_query`` and ``end_query``.
494*61046927SAndroid Build Coastguard WorkerThis query can be used with ``render_condition``. The output stream is
495*61046927SAndroid Build Coastguard Workerselected by the stream number passed to ``create_query``.
496*61046927SAndroid Build Coastguard Worker
497*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_SO_OVERFLOW_ANY_PREDICATE`` returns a boolean value indicating
498*61046927SAndroid Build Coastguard Workerwhether any stream output target has overflowed as a result of the commands
499*61046927SAndroid Build Coastguard Workerissued between ``begin_query`` and ``end_query``. This query can be used
500*61046927SAndroid Build Coastguard Workerwith ``render_condition``, and its result is the logical OR of multiple
501*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_SO_OVERFLOW_PREDICATE`` queries, one for each stream output
502*61046927SAndroid Build Coastguard Workertarget.
503*61046927SAndroid Build Coastguard Worker
504*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_GPU_FINISHED`` returns a boolean value indicating whether
505*61046927SAndroid Build Coastguard Workerall commands issued before ``end_query`` have completed. However, this
506*61046927SAndroid Build Coastguard Workerdoes not imply serialization.
507*61046927SAndroid Build Coastguard WorkerThis query does not require a call to ``begin_query``.
508*61046927SAndroid Build Coastguard Worker
509*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PIPELINE_STATISTICS`` returns an array of the following
510*61046927SAndroid Build Coastguard Worker64-bit integers:
511*61046927SAndroid Build Coastguard WorkerNumber of vertices read from vertex buffers.
512*61046927SAndroid Build Coastguard WorkerNumber of primitives read from vertex buffers.
513*61046927SAndroid Build Coastguard WorkerNumber of vertex shader threads launched.
514*61046927SAndroid Build Coastguard WorkerNumber of geometry shader threads launched.
515*61046927SAndroid Build Coastguard WorkerNumber of primitives generated by geometry shaders.
516*61046927SAndroid Build Coastguard WorkerNumber of primitives forwarded to the rasterizer.
517*61046927SAndroid Build Coastguard WorkerNumber of primitives rasterized.
518*61046927SAndroid Build Coastguard WorkerNumber of fragment shader threads launched.
519*61046927SAndroid Build Coastguard WorkerNumber of tessellation control shader threads launched.
520*61046927SAndroid Build Coastguard WorkerNumber of tessellation evaluation shader threads launched.
521*61046927SAndroid Build Coastguard WorkerIf a shader type is not supported by the device/driver,
522*61046927SAndroid Build Coastguard Workerthe corresponding values should be set to 0.
523*61046927SAndroid Build Coastguard Worker
524*61046927SAndroid Build Coastguard Worker``PIPE_QUERY_PIPELINE_STATISTICS_SINGLE`` returns a single counter from
525*61046927SAndroid Build Coastguard Workerthe ``PIPE_QUERY_PIPELINE_STATISTICS`` group.  The specific counter must
526*61046927SAndroid Build Coastguard Workerbe selected when calling ``create_query`` by passing one of the
527*61046927SAndroid Build Coastguard Worker``PIPE_STAT_QUERY`` enums as the query's ``index``.
528*61046927SAndroid Build Coastguard Worker
529*61046927SAndroid Build Coastguard WorkerGallium does not guarantee the availability of any query types; one must
530*61046927SAndroid Build Coastguard Workeralways check the capabilities of the :ref:`Screen` first.
531*61046927SAndroid Build Coastguard Worker
532*61046927SAndroid Build Coastguard Worker
533*61046927SAndroid Build Coastguard WorkerConditional Rendering
534*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^
535*61046927SAndroid Build Coastguard Worker
536*61046927SAndroid Build Coastguard WorkerA drawing command can be skipped depending on the outcome of a query
537*61046927SAndroid Build Coastguard Worker(typically an occlusion query, or streamout overflow predicate).
538*61046927SAndroid Build Coastguard WorkerThe ``render_condition`` function specifies the query which should be checked
539*61046927SAndroid Build Coastguard Workerprior to rendering anything. Functions always honoring render_condition include
540*61046927SAndroid Build Coastguard Worker(and are limited to) draw_vbo and clear.
541*61046927SAndroid Build Coastguard WorkerThe blit, clear_render_target and clear_depth_stencil functions (but
542*61046927SAndroid Build Coastguard Workernot resource_copy_region, which seems inconsistent) can also optionally honor
543*61046927SAndroid Build Coastguard Workerthe current render condition.
544*61046927SAndroid Build Coastguard Worker
545*61046927SAndroid Build Coastguard WorkerIf ``render_condition`` is called with ``query`` = NULL, conditional
546*61046927SAndroid Build Coastguard Workerrendering is disabled and drawing takes place normally.
547*61046927SAndroid Build Coastguard Worker
548*61046927SAndroid Build Coastguard WorkerIf ``render_condition`` is called with a non-null ``query`` subsequent
549*61046927SAndroid Build Coastguard Workerdrawing commands will be predicated on the outcome of the query.
550*61046927SAndroid Build Coastguard WorkerCommands will be skipped if ``condition`` is equal to the predicate result
551*61046927SAndroid Build Coastguard Worker(for non-boolean queries such as OCCLUSION_QUERY, zero counts as FALSE,
552*61046927SAndroid Build Coastguard Workernon-zero as TRUE).
553*61046927SAndroid Build Coastguard Worker
554*61046927SAndroid Build Coastguard WorkerIf ``mode`` is PIPE_RENDER_COND_WAIT the driver will wait for the
555*61046927SAndroid Build Coastguard Workerquery to complete before deciding whether to render.
556*61046927SAndroid Build Coastguard Worker
557*61046927SAndroid Build Coastguard WorkerIf ``mode`` is PIPE_RENDER_COND_NO_WAIT and the query has not yet
558*61046927SAndroid Build Coastguard Workercompleted, the drawing command will be executed normally.  If the query
559*61046927SAndroid Build Coastguard Workerhas completed, drawing will be predicated on the outcome of the query.
560*61046927SAndroid Build Coastguard Worker
561*61046927SAndroid Build Coastguard WorkerIf ``mode`` is PIPE_RENDER_COND_BY_REGION_WAIT or
562*61046927SAndroid Build Coastguard WorkerPIPE_RENDER_COND_BY_REGION_NO_WAIT rendering will be predicated as above
563*61046927SAndroid Build Coastguard Workerfor the non-REGION modes but in the case that an occlusion query returns
564*61046927SAndroid Build Coastguard Workera non-zero result, regions which were occluded may be omitted by subsequent
565*61046927SAndroid Build Coastguard Workerdrawing commands.  This can result in better performance with some GPUs.
566*61046927SAndroid Build Coastguard WorkerNormally, if the occlusion query returned a non-zero result subsequent
567*61046927SAndroid Build Coastguard Workerdrawing happens normally so fragments may be generated, shaded and
568*61046927SAndroid Build Coastguard Workerprocessed even where they're known to be obscured.
569*61046927SAndroid Build Coastguard Worker
570*61046927SAndroid Build Coastguard WorkerThe ''render_condition_mem'' function specifies the drawing is dependent
571*61046927SAndroid Build Coastguard Workeron a value in memory. A buffer resource and offset denote which 32-bit
572*61046927SAndroid Build Coastguard Workervalue to use for the query. This is used for Vulkan API.
573*61046927SAndroid Build Coastguard Worker
574*61046927SAndroid Build Coastguard WorkerFlushing
575*61046927SAndroid Build Coastguard Worker^^^^^^^^
576*61046927SAndroid Build Coastguard Worker
577*61046927SAndroid Build Coastguard Worker``flush``
578*61046927SAndroid Build Coastguard Worker
579*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_END_OF_FRAME: Whether the flush marks the end of frame.
580*61046927SAndroid Build Coastguard Worker
581*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_DEFERRED: It is not required to flush right away, but it is required
582*61046927SAndroid Build Coastguard Workerto return a valid fence. If fence_finish is called with the returned fence
583*61046927SAndroid Build Coastguard Workerand the context is still unflushed, and the ctx parameter of fence_finish is
584*61046927SAndroid Build Coastguard Workerequal to the context where the fence was created, fence_finish will flush
585*61046927SAndroid Build Coastguard Workerthe context.
586*61046927SAndroid Build Coastguard Worker
587*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_ASYNC: The flush is allowed to be asynchronous. Unlike
588*61046927SAndroid Build Coastguard Worker``PIPE_FLUSH_DEFERRED``, the driver must still ensure that the returned fence
589*61046927SAndroid Build Coastguard Workerwill finish in finite time. However, subsequent operations in other contexts of
590*61046927SAndroid Build Coastguard Workerthe same screen are no longer guaranteed to happen after the flush. Drivers
591*61046927SAndroid Build Coastguard Workerwhich use this flag must implement pipe_context::fence_server_sync.
592*61046927SAndroid Build Coastguard Worker
593*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_HINT_FINISH: Hints to the driver that the caller will immediately
594*61046927SAndroid Build Coastguard Workerwait for the returned fence.
595*61046927SAndroid Build Coastguard Worker
596*61046927SAndroid Build Coastguard WorkerAdditional flags may be set together with ``PIPE_FLUSH_DEFERRED`` for even
597*61046927SAndroid Build Coastguard Workerfiner-grained fences. Note that as a general rule, GPU caches may not have been
598*61046927SAndroid Build Coastguard Workerflushed yet when these fences are signaled. Drivers are free to ignore these
599*61046927SAndroid Build Coastguard Workerflags and create normal fences instead. At most one of the following flags can
600*61046927SAndroid Build Coastguard Workerbe specified:
601*61046927SAndroid Build Coastguard Worker
602*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_TOP_OF_PIPE: The fence should be signaled as soon as the next
603*61046927SAndroid Build Coastguard Workercommand is ready to start executing at the top of the pipeline, before any of
604*61046927SAndroid Build Coastguard Workerits data is actually read (including indirect draw parameters).
605*61046927SAndroid Build Coastguard Worker
606*61046927SAndroid Build Coastguard WorkerPIPE_FLUSH_BOTTOM_OF_PIPE: The fence should be signaled as soon as the previous
607*61046927SAndroid Build Coastguard Workercommand has finished executing on the GPU entirely (but data written by the
608*61046927SAndroid Build Coastguard Workercommand may still be in caches and inaccessible to the CPU).
609*61046927SAndroid Build Coastguard Worker
610*61046927SAndroid Build Coastguard Worker
611*61046927SAndroid Build Coastguard Worker``flush_resource``
612*61046927SAndroid Build Coastguard Worker
613*61046927SAndroid Build Coastguard WorkerFlush the resource cache, so that the resource can be used
614*61046927SAndroid Build Coastguard Workerby an external client. Possible usage:
615*61046927SAndroid Build Coastguard Worker- flushing a resource before presenting it on the screen
616*61046927SAndroid Build Coastguard Worker- flushing a resource if some other process or device wants to use it
617*61046927SAndroid Build Coastguard WorkerThis shouldn't be used to flush caches if the resource is only managed
618*61046927SAndroid Build Coastguard Workerby a single pipe_screen and is not shared with another process.
619*61046927SAndroid Build Coastguard Worker(i.e. you shouldn't use it to flush caches explicitly if you want to e.g.
620*61046927SAndroid Build Coastguard Workeruse the resource for texturing)
621*61046927SAndroid Build Coastguard Worker
622*61046927SAndroid Build Coastguard WorkerFences
623*61046927SAndroid Build Coastguard Worker^^^^^^
624*61046927SAndroid Build Coastguard Worker
625*61046927SAndroid Build Coastguard Worker``pipe_fence_handle``, and related methods, are used to synchronize
626*61046927SAndroid Build Coastguard Workerexecution between multiple parties. Examples include CPU <-> GPU synchronization,
627*61046927SAndroid Build Coastguard Workerrenderer <-> windowing system, multiple external APIs, etc.
628*61046927SAndroid Build Coastguard Worker
629*61046927SAndroid Build Coastguard WorkerA ``pipe_fence_handle`` can either be 'one time use' or 're-usable'. A 'one time use'
630*61046927SAndroid Build Coastguard Workerfence behaves like a traditional GPU fence. Once it reaches the signaled state it
631*61046927SAndroid Build Coastguard Workeris forever considered to be signaled.
632*61046927SAndroid Build Coastguard Worker
633*61046927SAndroid Build Coastguard WorkerOnce a re-usable ``pipe_fence_handle`` becomes signaled, it can be reset
634*61046927SAndroid Build Coastguard Workerback into an unsignaled state. The ``pipe_fence_handle`` will be reset to
635*61046927SAndroid Build Coastguard Workerthe unsignaled state by performing a wait operation on said object, i.e.
636*61046927SAndroid Build Coastguard Worker``fence_server_sync``. As a corollary to this behavior, a re-usable
637*61046927SAndroid Build Coastguard Worker``pipe_fence_handle`` can only have one waiter.
638*61046927SAndroid Build Coastguard Worker
639*61046927SAndroid Build Coastguard WorkerThis behavior is useful in producer <-> consumer chains. It helps avoid
640*61046927SAndroid Build Coastguard Workerunnecessarily sharing a new ``pipe_fence_handle`` each time a new frame is
641*61046927SAndroid Build Coastguard Workerready. Instead, the fences are exchanged once ahead of time, and access is synchronized
642*61046927SAndroid Build Coastguard Workerthrough GPU signaling instead of direct producer <-> consumer communication.
643*61046927SAndroid Build Coastguard Worker
644*61046927SAndroid Build Coastguard Worker``fence_server_sync`` inserts a wait command into the GPU's command stream.
645*61046927SAndroid Build Coastguard Worker
646*61046927SAndroid Build Coastguard Worker``fence_server_signal`` inserts a signal command into the GPU's command stream.
647*61046927SAndroid Build Coastguard Worker
648*61046927SAndroid Build Coastguard WorkerThere are no guarantees that the wait/signal commands will be flushed when
649*61046927SAndroid Build Coastguard Workercalling ``fence_server_sync`` or ``fence_server_signal``. An explicit
650*61046927SAndroid Build Coastguard Workercall to ``flush`` is required to make sure the commands are emitted to the GPU.
651*61046927SAndroid Build Coastguard Worker
652*61046927SAndroid Build Coastguard WorkerThe Gallium implementation may implicitly ``flush`` the command stream during a
653*61046927SAndroid Build Coastguard Worker``fence_server_sync`` or ``fence_server_signal`` call if necessary.
654*61046927SAndroid Build Coastguard Worker
655*61046927SAndroid Build Coastguard WorkerResource Busy Queries
656*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^
657*61046927SAndroid Build Coastguard Worker
658*61046927SAndroid Build Coastguard Worker``is_resource_referenced``
659*61046927SAndroid Build Coastguard Worker
660*61046927SAndroid Build Coastguard Worker
661*61046927SAndroid Build Coastguard Worker
662*61046927SAndroid Build Coastguard WorkerBlitting
663*61046927SAndroid Build Coastguard Worker^^^^^^^^
664*61046927SAndroid Build Coastguard Worker
665*61046927SAndroid Build Coastguard WorkerThese methods emulate classic blitter controls.
666*61046927SAndroid Build Coastguard Worker
667*61046927SAndroid Build Coastguard WorkerThese methods operate directly on ``pipe_resource`` objects, and stand
668*61046927SAndroid Build Coastguard Workerapart from any 3D state in the context. Each method is assumed to have an
669*61046927SAndroid Build Coastguard Workerimplicit memory barrier around itself. They do not need any explicit
670*61046927SAndroid Build Coastguard Worker``memory_barrier``. Blitting functionality may be moved to a separate
671*61046927SAndroid Build Coastguard Workerabstraction at some point in the future.
672*61046927SAndroid Build Coastguard Worker
673*61046927SAndroid Build Coastguard Worker``resource_copy_region`` blits a region of a resource to a region of another
674*61046927SAndroid Build Coastguard Workerresource, provided that both resources have the same format, or compatible
675*61046927SAndroid Build Coastguard Workerformats, i.e., formats for which copying the bytes from the source resource
676*61046927SAndroid Build Coastguard Workerunmodified to the destination resource will achieve the same effect of a
677*61046927SAndroid Build Coastguard Workertextured quad blitter.. The source and destination may be the same resource,
678*61046927SAndroid Build Coastguard Workerbut overlapping blits are not permitted.
679*61046927SAndroid Build Coastguard WorkerThis can be considered the equivalent of a CPU memcpy.
680*61046927SAndroid Build Coastguard Worker
681*61046927SAndroid Build Coastguard Worker``blit`` blits a region of a resource to a region of another resource, including
682*61046927SAndroid Build Coastguard Workerscaling, format conversion, and up-/downsampling, as well as a destination clip
683*61046927SAndroid Build Coastguard Workerrectangle (scissors) and window rectangles. It can also optionally honor the
684*61046927SAndroid Build Coastguard Workercurrent render condition (but either way the blit itself never contributes
685*61046927SAndroid Build Coastguard Workeranything to queries currently gathering data).
686*61046927SAndroid Build Coastguard WorkerAs opposed to manually drawing a textured quad, this lets the pipe driver choose
687*61046927SAndroid Build Coastguard Workerthe optimal method for blitting (like using a special 2D engine), and usually
688*61046927SAndroid Build Coastguard Workeroffers, for example, accelerated stencil-only copies even where
689*61046927SAndroid Build Coastguard WorkerPIPE_CAP_SHADER_STENCIL_EXPORT is not available.
690*61046927SAndroid Build Coastguard Worker
691*61046927SAndroid Build Coastguard Worker
692*61046927SAndroid Build Coastguard WorkerTransfers
693*61046927SAndroid Build Coastguard Worker^^^^^^^^^
694*61046927SAndroid Build Coastguard Worker
695*61046927SAndroid Build Coastguard WorkerThese methods are used to get data to/from a resource.
696*61046927SAndroid Build Coastguard Worker
697*61046927SAndroid Build Coastguard Worker``transfer_map`` creates a memory mapping and the transfer object
698*61046927SAndroid Build Coastguard Workerassociated with it.
699*61046927SAndroid Build Coastguard WorkerThe returned pointer points to the start of the mapped range according to
700*61046927SAndroid Build Coastguard Workerthe box region, not the beginning of the resource. If transfer_map fails,
701*61046927SAndroid Build Coastguard Workerthe returned pointer to the buffer memory is NULL, and the pointer
702*61046927SAndroid Build Coastguard Workerto the transfer object remains unchanged (i.e. it can be non-NULL).
703*61046927SAndroid Build Coastguard Worker
704*61046927SAndroid Build Coastguard WorkerWhen mapping an MSAA surface, the samples are implicitly resolved to
705*61046927SAndroid Build Coastguard Workersingle-sampled for reads (returning the first sample for depth/stencil/integer,
706*61046927SAndroid Build Coastguard Workeraveraged for others).  See u_transfer_helper's U_TRANSFER_HELPER_MSAA_MAP for a
707*61046927SAndroid Build Coastguard Workerway to get that behavior using a resolve blit.
708*61046927SAndroid Build Coastguard Worker
709*61046927SAndroid Build Coastguard Worker``transfer_unmap`` remove the memory mapping for and destroy
710*61046927SAndroid Build Coastguard Workerthe transfer object. The pointer into the resource should be considered
711*61046927SAndroid Build Coastguard Workerinvalid and discarded.
712*61046927SAndroid Build Coastguard Worker
713*61046927SAndroid Build Coastguard Worker``texture_subdata`` and ``buffer_subdata`` perform a simplified
714*61046927SAndroid Build Coastguard Workertransfer for simple writes. Basically transfer_map, data write, and
715*61046927SAndroid Build Coastguard Workertransfer_unmap all in one.
716*61046927SAndroid Build Coastguard Worker
717*61046927SAndroid Build Coastguard Worker
718*61046927SAndroid Build Coastguard WorkerThe box parameter to some of these functions defines a 1D, 2D or 3D
719*61046927SAndroid Build Coastguard Workerregion of pixels.  This is self-explanatory for 1D, 2D and 3D texture
720*61046927SAndroid Build Coastguard Workertargets.
721*61046927SAndroid Build Coastguard Worker
722*61046927SAndroid Build Coastguard WorkerFor PIPE_TEXTURE_1D_ARRAY and PIPE_TEXTURE_2D_ARRAY, the box::z and box::depth
723*61046927SAndroid Build Coastguard Workerfields refer to the array dimension of the texture.
724*61046927SAndroid Build Coastguard Worker
725*61046927SAndroid Build Coastguard WorkerFor PIPE_TEXTURE_CUBE, the box:z and box::depth fields refer to the
726*61046927SAndroid Build Coastguard Workerfaces of the cube map (z + depth <= 6).
727*61046927SAndroid Build Coastguard Worker
728*61046927SAndroid Build Coastguard WorkerFor PIPE_TEXTURE_CUBE_ARRAY, the box:z and box::depth fields refer to both
729*61046927SAndroid Build Coastguard Workerthe face and array dimension of the texture (face = z % 6, array = z / 6).
730*61046927SAndroid Build Coastguard Worker
731*61046927SAndroid Build Coastguard Worker
732*61046927SAndroid Build Coastguard Worker.. _transfer_flush_region:
733*61046927SAndroid Build Coastguard Worker
734*61046927SAndroid Build Coastguard Workertransfer_flush_region
735*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%%%%%%%
736*61046927SAndroid Build Coastguard Worker
737*61046927SAndroid Build Coastguard WorkerIf a transfer was created with ``FLUSH_EXPLICIT``, it will not automatically
738*61046927SAndroid Build Coastguard Workerbe flushed on write or unmap. Flushes must be requested with
739*61046927SAndroid Build Coastguard Worker``transfer_flush_region``. Flush ranges are relative to the mapped range, not
740*61046927SAndroid Build Coastguard Workerthe beginning of the resource.
741*61046927SAndroid Build Coastguard Worker
742*61046927SAndroid Build Coastguard Worker
743*61046927SAndroid Build Coastguard Worker
744*61046927SAndroid Build Coastguard Worker.. _texture_barrier:
745*61046927SAndroid Build Coastguard Worker
746*61046927SAndroid Build Coastguard Workertexture_barrier
747*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%
748*61046927SAndroid Build Coastguard Worker
749*61046927SAndroid Build Coastguard WorkerThis function flushes all pending writes to the currently-set surfaces and
750*61046927SAndroid Build Coastguard Workerinvalidates all read caches of the currently-set samplers. This can be used
751*61046927SAndroid Build Coastguard Workerfor both regular textures as well as for framebuffers read via FBFETCH.
752*61046927SAndroid Build Coastguard Worker
753*61046927SAndroid Build Coastguard Worker
754*61046927SAndroid Build Coastguard Worker
755*61046927SAndroid Build Coastguard Worker.. _memory_barrier:
756*61046927SAndroid Build Coastguard Worker
757*61046927SAndroid Build Coastguard Workermemory_barrier
758*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%
759*61046927SAndroid Build Coastguard Worker
760*61046927SAndroid Build Coastguard WorkerThis function flushes caches according to which of the PIPE_BARRIER_* flags
761*61046927SAndroid Build Coastguard Workerare set.
762*61046927SAndroid Build Coastguard Worker
763*61046927SAndroid Build Coastguard Worker
764*61046927SAndroid Build Coastguard Worker
765*61046927SAndroid Build Coastguard Worker.. _resource_commit:
766*61046927SAndroid Build Coastguard Worker
767*61046927SAndroid Build Coastguard Workerresource_commit
768*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%
769*61046927SAndroid Build Coastguard Worker
770*61046927SAndroid Build Coastguard WorkerThis function changes the commit state of a part of a sparse resource. Sparse
771*61046927SAndroid Build Coastguard Workerresources are created by setting the ``PIPE_RESOURCE_FLAG_SPARSE`` flag when
772*61046927SAndroid Build Coastguard Workercalling ``resource_create``. Initially, sparse resources only reserve a virtual
773*61046927SAndroid Build Coastguard Workermemory region that is not backed by memory (i.e., it is uncommitted). The
774*61046927SAndroid Build Coastguard Worker``resource_commit`` function can be called to commit or uncommit parts (or all)
775*61046927SAndroid Build Coastguard Workerof a resource. The driver manages the underlying backing memory.
776*61046927SAndroid Build Coastguard Worker
777*61046927SAndroid Build Coastguard WorkerThe contents of newly committed memory regions are undefined. Calling this
778*61046927SAndroid Build Coastguard Workerfunction to commit an already committed memory region is allowed and leaves its
779*61046927SAndroid Build Coastguard Workercontent unchanged. Similarly, calling this function to uncommit an already
780*61046927SAndroid Build Coastguard Workeruncommitted memory region is allowed.
781*61046927SAndroid Build Coastguard Worker
782*61046927SAndroid Build Coastguard WorkerFor buffers, the given box must be aligned to multiples of
783*61046927SAndroid Build Coastguard Worker``PIPE_CAP_SPARSE_BUFFER_PAGE_SIZE``. As an exception to this rule, if the size
784*61046927SAndroid Build Coastguard Workerof the buffer is not a multiple of the page size, changing the commit state of
785*61046927SAndroid Build Coastguard Workerthe last (partial) page requires a box that ends at the end of the buffer
786*61046927SAndroid Build Coastguard Worker(i.e., box->x + box->width == buffer->width0).
787*61046927SAndroid Build Coastguard Worker
788*61046927SAndroid Build Coastguard Worker
789*61046927SAndroid Build Coastguard Worker
790*61046927SAndroid Build Coastguard Worker.. _pipe_transfer:
791*61046927SAndroid Build Coastguard Worker
792*61046927SAndroid Build Coastguard WorkerPIPE_MAP
793*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^
794*61046927SAndroid Build Coastguard Worker
795*61046927SAndroid Build Coastguard WorkerThese flags control the behavior of a transfer object.
796*61046927SAndroid Build Coastguard Worker
797*61046927SAndroid Build Coastguard Worker``PIPE_MAP_READ``
798*61046927SAndroid Build Coastguard Worker  Resource contents read back (or accessed directly) at transfer create time.
799*61046927SAndroid Build Coastguard Worker
800*61046927SAndroid Build Coastguard Worker``PIPE_MAP_WRITE``
801*61046927SAndroid Build Coastguard Worker  Resource contents will be written back at transfer_unmap time (or modified
802*61046927SAndroid Build Coastguard Worker  as a result of being accessed directly).
803*61046927SAndroid Build Coastguard Worker
804*61046927SAndroid Build Coastguard Worker``PIPE_MAP_DIRECTLY``
805*61046927SAndroid Build Coastguard Worker  a transfer should directly map the resource. May return NULL if not supported.
806*61046927SAndroid Build Coastguard Worker
807*61046927SAndroid Build Coastguard Worker``PIPE_MAP_DISCARD_RANGE``
808*61046927SAndroid Build Coastguard Worker  The memory within the mapped region is discarded.  Cannot be used with
809*61046927SAndroid Build Coastguard Worker  ``PIPE_MAP_READ``.
810*61046927SAndroid Build Coastguard Worker
811*61046927SAndroid Build Coastguard Worker``PIPE_MAP_DISCARD_WHOLE_RESOURCE``
812*61046927SAndroid Build Coastguard Worker  Discards all memory backing the resource.  It should not be used with
813*61046927SAndroid Build Coastguard Worker  ``PIPE_MAP_READ``.
814*61046927SAndroid Build Coastguard Worker
815*61046927SAndroid Build Coastguard Worker``PIPE_MAP_DONTBLOCK``
816*61046927SAndroid Build Coastguard Worker  Fail if the resource cannot be mapped immediately.
817*61046927SAndroid Build Coastguard Worker
818*61046927SAndroid Build Coastguard Worker``PIPE_MAP_UNSYNCHRONIZED``
819*61046927SAndroid Build Coastguard Worker  Do not synchronize pending operations on the resource when mapping. The
820*61046927SAndroid Build Coastguard Worker  interaction of any writes to the map and any operations pending on the
821*61046927SAndroid Build Coastguard Worker  resource are undefined. Cannot be used with ``PIPE_MAP_READ``.
822*61046927SAndroid Build Coastguard Worker
823*61046927SAndroid Build Coastguard Worker``PIPE_MAP_FLUSH_EXPLICIT``
824*61046927SAndroid Build Coastguard Worker  Written ranges will be notified later with :ref:`transfer_flush_region`.
825*61046927SAndroid Build Coastguard Worker  Cannot be used with ``PIPE_MAP_READ``.
826*61046927SAndroid Build Coastguard Worker
827*61046927SAndroid Build Coastguard Worker``PIPE_MAP_PERSISTENT``
828*61046927SAndroid Build Coastguard Worker  Allows the resource to be used for rendering while mapped.
829*61046927SAndroid Build Coastguard Worker  PIPE_RESOURCE_FLAG_MAP_PERSISTENT must be set when creating
830*61046927SAndroid Build Coastguard Worker  the resource.
831*61046927SAndroid Build Coastguard Worker  If COHERENT is not set, memory_barrier(PIPE_BARRIER_MAPPED_BUFFER)
832*61046927SAndroid Build Coastguard Worker  must be called to ensure the device can see what the CPU has written.
833*61046927SAndroid Build Coastguard Worker
834*61046927SAndroid Build Coastguard Worker``PIPE_MAP_COHERENT``
835*61046927SAndroid Build Coastguard Worker  If PERSISTENT is set, this ensures any writes done by the device are
836*61046927SAndroid Build Coastguard Worker  immediately visible to the CPU and vice versa.
837*61046927SAndroid Build Coastguard Worker  PIPE_RESOURCE_FLAG_MAP_COHERENT must be set when creating
838*61046927SAndroid Build Coastguard Worker  the resource.
839*61046927SAndroid Build Coastguard Worker
840*61046927SAndroid Build Coastguard WorkerCompute kernel execution
841*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^^^
842*61046927SAndroid Build Coastguard Worker
843*61046927SAndroid Build Coastguard WorkerA compute program can be defined, bound or destroyed using
844*61046927SAndroid Build Coastguard Worker``create_compute_state``, ``bind_compute_state`` or
845*61046927SAndroid Build Coastguard Worker``destroy_compute_state`` respectively.
846*61046927SAndroid Build Coastguard Worker
847*61046927SAndroid Build Coastguard WorkerAny of the subroutines contained within the compute program can be
848*61046927SAndroid Build Coastguard Workerexecuted on the device using the ``launch_grid`` method.  This method
849*61046927SAndroid Build Coastguard Workerwill execute as many instances of the program as elements in the
850*61046927SAndroid Build Coastguard Workerspecified N-dimensional grid, hopefully in parallel.
851*61046927SAndroid Build Coastguard Worker
852*61046927SAndroid Build Coastguard WorkerThe compute program has access to four special resources:
853*61046927SAndroid Build Coastguard Worker
854*61046927SAndroid Build Coastguard Worker* ``GLOBAL`` represents a memory space shared among all the threads
855*61046927SAndroid Build Coastguard Worker  running on the device.  An arbitrary buffer created with the
856*61046927SAndroid Build Coastguard Worker  ``PIPE_BIND_GLOBAL`` flag can be mapped into it using the
857*61046927SAndroid Build Coastguard Worker  ``set_global_binding`` method.
858*61046927SAndroid Build Coastguard Worker
859*61046927SAndroid Build Coastguard Worker* ``LOCAL`` represents a memory space shared among all the threads
860*61046927SAndroid Build Coastguard Worker  running in the same working group.  The initial contents of this
861*61046927SAndroid Build Coastguard Worker  resource are undefined.
862*61046927SAndroid Build Coastguard Worker
863*61046927SAndroid Build Coastguard Worker* ``PRIVATE`` represents a memory space local to a single thread.
864*61046927SAndroid Build Coastguard Worker  The initial contents of this resource are undefined.
865*61046927SAndroid Build Coastguard Worker
866*61046927SAndroid Build Coastguard Worker* ``INPUT`` represents a read-only memory space that can be
867*61046927SAndroid Build Coastguard Worker  initialized at ``launch_grid`` time.
868*61046927SAndroid Build Coastguard Worker
869*61046927SAndroid Build Coastguard WorkerThese resources use a byte-based addressing scheme, and they can be
870*61046927SAndroid Build Coastguard Workeraccessed from the compute program by means of the LOAD/STORE TGSI
871*61046927SAndroid Build Coastguard Workeropcodes.  Additional resources to be accessed using the same opcodes
872*61046927SAndroid Build Coastguard Workermay be specified by the user with the ``set_compute_resources``
873*61046927SAndroid Build Coastguard Workermethod.
874*61046927SAndroid Build Coastguard Worker
875*61046927SAndroid Build Coastguard WorkerIn addition, normal texture sampling is allowed from the compute
876*61046927SAndroid Build Coastguard Workerprogram: ``bind_sampler_states`` may be used to set up texture
877*61046927SAndroid Build Coastguard Workersamplers for the compute stage and ``set_sampler_views`` may
878*61046927SAndroid Build Coastguard Workerbe used to bind a number of sampler views to it.
879*61046927SAndroid Build Coastguard Worker
880*61046927SAndroid Build Coastguard WorkerCompute kernel queries
881*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^^^^^^
882*61046927SAndroid Build Coastguard Worker
883*61046927SAndroid Build Coastguard Worker.. _get_compute_state_info:
884*61046927SAndroid Build Coastguard Worker
885*61046927SAndroid Build Coastguard Workerget_compute_state_info
886*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%%%%%%%%
887*61046927SAndroid Build Coastguard Worker
888*61046927SAndroid Build Coastguard WorkerThis function allows frontends to query kernel information defined inside
889*61046927SAndroid Build Coastguard Worker``pipe_compute_state_object_info``.
890*61046927SAndroid Build Coastguard Worker
891*61046927SAndroid Build Coastguard Worker.. _get_compute_state_subgroup_size:
892*61046927SAndroid Build Coastguard Worker
893*61046927SAndroid Build Coastguard Workerget_compute_state_subgroup_size
894*61046927SAndroid Build Coastguard Worker%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
895*61046927SAndroid Build Coastguard Worker
896*61046927SAndroid Build Coastguard WorkerThis function returns the choosen subgroup size when ``launch_grid`` is
897*61046927SAndroid Build Coastguard Workercalled with the given block size. This doesn't need to be implemented when
898*61046927SAndroid Build Coastguard Workeronly one size is reported through ``PIPE_COMPUTE_CAP_SUBGROUP_SIZES`` or
899*61046927SAndroid Build Coastguard Worker``pipe_compute_state_object_info::simd_sizes``.
900*61046927SAndroid Build Coastguard Worker
901*61046927SAndroid Build Coastguard WorkerMipmap generation
902*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^^^^^
903*61046927SAndroid Build Coastguard Worker
904*61046927SAndroid Build Coastguard WorkerIf PIPE_CAP_GENERATE_MIPMAP is true, ``generate_mipmap`` can be used
905*61046927SAndroid Build Coastguard Workerto generate mipmaps for the specified texture resource.
906*61046927SAndroid Build Coastguard WorkerIt replaces texel image levels base_level+1 through
907*61046927SAndroid Build Coastguard Workerlast_level for layers range from first_layer through last_layer.
908*61046927SAndroid Build Coastguard WorkerIt returns TRUE if mipmap generation succeeds, otherwise it
909*61046927SAndroid Build Coastguard Workerreturns FALSE. Mipmap generation may fail when it is not supported
910*61046927SAndroid Build Coastguard Workerfor particular texture types or formats.
911*61046927SAndroid Build Coastguard Worker
912*61046927SAndroid Build Coastguard WorkerDevice resets
913*61046927SAndroid Build Coastguard Worker^^^^^^^^^^^^^
914*61046927SAndroid Build Coastguard Worker
915*61046927SAndroid Build Coastguard WorkerGallium frontends can query or request notifications of when the GPU
916*61046927SAndroid Build Coastguard Workeris reset for whatever reason (application error, driver error). When
917*61046927SAndroid Build Coastguard Workera GPU reset happens, the context becomes unusable and all related state
918*61046927SAndroid Build Coastguard Workershould be considered lost and undefined. Despite that, context
919*61046927SAndroid Build Coastguard Workernotifications are single-shot, i.e. subsequent calls to
920*61046927SAndroid Build Coastguard Worker``get_device_reset_status`` will return PIPE_NO_RESET.
921*61046927SAndroid Build Coastguard Worker
922*61046927SAndroid Build Coastguard Worker* ``get_device_reset_status`` queries whether a device reset has happened
923*61046927SAndroid Build Coastguard Worker  since the last call or since the last notification by callback.
924*61046927SAndroid Build Coastguard Worker* ``set_device_reset_callback`` sets a callback which will be called when
925*61046927SAndroid Build Coastguard Worker  a device reset is detected. The callback is only called synchronously.
926*61046927SAndroid Build Coastguard Worker
927*61046927SAndroid Build Coastguard WorkerBindless
928*61046927SAndroid Build Coastguard Worker^^^^^^^^
929*61046927SAndroid Build Coastguard Worker
930*61046927SAndroid Build Coastguard WorkerIf PIPE_CAP_BINDLESS_TEXTURE is TRUE, the following ``pipe_context`` functions
931*61046927SAndroid Build Coastguard Workerare used to create/delete bindless handles, and to make them resident in the
932*61046927SAndroid Build Coastguard Workercurrent context when they are going to be used by shaders.
933*61046927SAndroid Build Coastguard Worker
934*61046927SAndroid Build Coastguard Worker* ``create_texture_handle`` creates a 64-bit unsigned integer texture handle
935*61046927SAndroid Build Coastguard Worker  that is going to be directly used in shaders.
936*61046927SAndroid Build Coastguard Worker* ``delete_texture_handle`` deletes a 64-bit unsigned integer texture handle.
937*61046927SAndroid Build Coastguard Worker* ``make_texture_handle_resident`` makes a 64-bit unsigned texture handle
938*61046927SAndroid Build Coastguard Worker  resident in the current context to be accessible by shaders for texture
939*61046927SAndroid Build Coastguard Worker  mapping.
940*61046927SAndroid Build Coastguard Worker* ``create_image_handle`` creates a 64-bit unsigned integer image handle that
941*61046927SAndroid Build Coastguard Worker  is going to be directly used in shaders.
942*61046927SAndroid Build Coastguard Worker* ``delete_image_handle`` deletes a 64-bit unsigned integer image handle.
943*61046927SAndroid Build Coastguard Worker* ``make_image_handle_resident`` makes a 64-bit unsigned integer image handle
944*61046927SAndroid Build Coastguard Worker  resident in the current context to be accessible by shaders for image loads,
945*61046927SAndroid Build Coastguard Worker  stores and atomic operations.
946*61046927SAndroid Build Coastguard Worker
947*61046927SAndroid Build Coastguard WorkerUsing several contexts
948*61046927SAndroid Build Coastguard Worker----------------------
949*61046927SAndroid Build Coastguard Worker
950*61046927SAndroid Build Coastguard WorkerSeveral contexts from the same screen can be used at the same time. Objects
951*61046927SAndroid Build Coastguard Workercreated on one context cannot be used in another context, but the objects
952*61046927SAndroid Build Coastguard Workercreated by the screen methods can be used by all contexts.
953*61046927SAndroid Build Coastguard Worker
954*61046927SAndroid Build Coastguard WorkerTransfers
955*61046927SAndroid Build Coastguard Worker^^^^^^^^^
956*61046927SAndroid Build Coastguard WorkerA transfer on one context is not expected to synchronize properly with
957*61046927SAndroid Build Coastguard Workerrendering on other contexts, thus only areas not yet used for rendering should
958*61046927SAndroid Build Coastguard Workerbe locked.
959*61046927SAndroid Build Coastguard Worker
960*61046927SAndroid Build Coastguard WorkerA flush is required after transfer_unmap to expect other contexts to see the
961*61046927SAndroid Build Coastguard Workeruploaded data, unless:
962*61046927SAndroid Build Coastguard Worker
963*61046927SAndroid Build Coastguard Worker* Using persistent mapping. Associated with coherent mapping, unmapping the
964*61046927SAndroid Build Coastguard Worker  resource is also not required to use it in other contexts. Without coherent
965*61046927SAndroid Build Coastguard Worker  mapping, memory_barrier(PIPE_BARRIER_MAPPED_BUFFER) should be called on the
966*61046927SAndroid Build Coastguard Worker  context that has mapped the resource. No flush is required.
967*61046927SAndroid Build Coastguard Worker
968*61046927SAndroid Build Coastguard Worker* Mapping the resource with PIPE_MAP_DIRECTLY.
969