2 * Copyright © 2014-2017 Broadcom
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "util/u_blitter.h"
25 #include "util/u_prim.h"
26 #include "util/u_format.h"
27 #include "util/u_pack_color.h"
28 #include "util/u_prim_restart.h"
29 #include "util/u_upload_mgr.h"
30 #include "indices/u_primconvert.h"
32 #include "v3d_context.h"
33 #include "v3d_resource.h"
35 #include "broadcom/compiler/v3d_compiler.h"
36 #include "broadcom/common/v3d_macros.h"
37 #include "broadcom/cle/v3dx_pack.h"
40 * Does the initial bining command list setup for drawing to a given FBO.
43 v3d_start_draw(struct v3d_context
*v3d
)
45 struct v3d_job
*job
= v3d
->job
;
50 /* Get space to emit our BCL state, using a branch to jump to a new BO
53 v3d_cl_ensure_space_with_branch(&job
->bcl
, 256 /* XXX */);
55 job
->submit
.bcl_start
= job
->bcl
.bo
->offset
;
56 v3d_job_add_bo(job
, job
->bcl
.bo
);
58 job
->tile_alloc
= v3d_bo_alloc(v3d
->screen
, 1024 * 1024, "tile_alloc");
59 uint32_t tsda_per_tile_size
= v3d
->screen
->devinfo
.ver
>= 40 ? 256 : 64;
60 job
->tile_state
= v3d_bo_alloc(v3d
->screen
,
67 cl_emit(&job
->bcl
, TILE_BINNING_MODE_CFG
, config
) {
68 config
.width_in_pixels
= v3d
->framebuffer
.width
;
69 config
.height_in_pixels
= v3d
->framebuffer
.height
;
70 config
.number_of_render_targets
=
71 MAX2(v3d
->framebuffer
.nr_cbufs
, 1);
73 config
.multisample_mode_4x
= job
->msaa
;
75 config
.maximum_bpp_of_all_render_targets
= job
->internal_bpp
;
77 #else /* V3D_VERSION < 40 */
78 /* "Binning mode lists start with a Tile Binning Mode Configuration
81 * Part1 signals the end of binning config setup.
83 cl_emit(&job
->bcl
, TILE_BINNING_MODE_CFG_PART2
, config
) {
84 config
.tile_allocation_memory_address
=
85 cl_address(job
->tile_alloc
, 0);
86 config
.tile_allocation_memory_size
= job
->tile_alloc
->size
;
89 cl_emit(&job
->bcl
, TILE_BINNING_MODE_CFG_PART1
, config
) {
90 config
.tile_state_data_array_base_address
=
91 cl_address(job
->tile_state
, 0);
93 config
.width_in_tiles
= job
->draw_tiles_x
;
94 config
.height_in_tiles
= job
->draw_tiles_y
;
96 config
.number_of_render_targets
=
97 MAX2(v3d
->framebuffer
.nr_cbufs
, 1);
99 config
.multisample_mode_4x
= job
->msaa
;
101 config
.maximum_bpp_of_all_render_targets
= job
->internal_bpp
;
103 #endif /* V3D_VERSION < 40 */
105 /* There's definitely nothing in the VCD cache we want. */
106 cl_emit(&job
->bcl
, FLUSH_VCD_CACHE
, bin
);
108 /* Disable any leftover OQ state from another job. */
109 cl_emit(&job
->bcl
, OCCLUSION_QUERY_COUNTER
, counter
);
111 /* "Binning mode lists must have a Start Tile Binning item (6) after
112 * any prefix state data before the binning list proper starts."
114 cl_emit(&job
->bcl
, START_TILE_BINNING
, bin
);
116 job
->needs_flush
= true;
117 job
->draw_width
= v3d
->framebuffer
.width
;
118 job
->draw_height
= v3d
->framebuffer
.height
;
122 v3d_predraw_check_textures(struct pipe_context
*pctx
,
123 struct v3d_texture_stateobj
*stage_tex
)
125 struct v3d_context
*v3d
= v3d_context(pctx
);
127 for (int i
= 0; i
< stage_tex
->num_textures
; i
++) {
128 struct pipe_sampler_view
*view
= stage_tex
->textures
[i
];
132 v3d_flush_jobs_writing_resource(v3d
, view
->texture
);
137 v3d_emit_gl_shader_state(struct v3d_context
*v3d
,
138 const struct pipe_draw_info
*info
)
140 struct v3d_job
*job
= v3d
->job
;
141 /* VC5_DIRTY_VTXSTATE */
142 struct v3d_vertex_stateobj
*vtx
= v3d
->vtx
;
143 /* VC5_DIRTY_VTXBUF */
144 struct v3d_vertexbuf_stateobj
*vertexbuf
= &v3d
->vertexbuf
;
146 /* Upload the uniforms to the indirect CL first */
147 struct v3d_cl_reloc fs_uniforms
=
148 v3d_write_uniforms(v3d
, v3d
->prog
.fs
,
149 &v3d
->constbuf
[PIPE_SHADER_FRAGMENT
],
151 struct v3d_cl_reloc vs_uniforms
=
152 v3d_write_uniforms(v3d
, v3d
->prog
.vs
,
153 &v3d
->constbuf
[PIPE_SHADER_VERTEX
],
155 struct v3d_cl_reloc cs_uniforms
=
156 v3d_write_uniforms(v3d
, v3d
->prog
.cs
,
157 &v3d
->constbuf
[PIPE_SHADER_VERTEX
],
160 /* See GFXH-930 workaround below */
161 uint32_t num_elements_to_emit
= MAX2(vtx
->num_elements
, 1);
162 uint32_t shader_rec_offset
=
163 v3d_cl_ensure_space(&job
->indirect
,
164 cl_packet_length(GL_SHADER_STATE_RECORD
) +
165 num_elements_to_emit
*
166 cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD
),
169 cl_emit(&job
->indirect
, GL_SHADER_STATE_RECORD
, shader
) {
170 shader
.enable_clipping
= true;
171 /* VC5_DIRTY_PRIM_MODE | VC5_DIRTY_RASTERIZER */
172 shader
.point_size_in_shaded_vertex_data
=
173 (info
->mode
== PIPE_PRIM_POINTS
&&
174 v3d
->rasterizer
->base
.point_size_per_vertex
);
176 /* Must be set if the shader modifies Z, discards, or modifies
177 * the sample mask. For any of these cases, the fragment
178 * shader needs to write the Z value (even just discards).
180 shader
.fragment_shader_does_z_writes
=
181 (v3d
->prog
.fs
->prog_data
.fs
->writes_z
||
182 v3d
->prog
.fs
->prog_data
.fs
->discard
);
184 shader
.fragment_shader_uses_real_pixel_centre_w_in_addition_to_centroid_w2
=
185 v3d
->prog
.fs
->prog_data
.fs
->uses_center_w
;
187 shader
.number_of_varyings_in_fragment_shader
=
188 v3d
->prog
.fs
->prog_data
.base
->num_inputs
;
190 shader
.coordinate_shader_propagate_nans
= true;
191 shader
.vertex_shader_propagate_nans
= true;
192 shader
.fragment_shader_propagate_nans
= true;
194 shader
.coordinate_shader_code_address
=
195 cl_address(v3d
->prog
.cs
->bo
, 0);
196 shader
.vertex_shader_code_address
=
197 cl_address(v3d
->prog
.vs
->bo
, 0);
198 shader
.fragment_shader_code_address
=
199 cl_address(v3d
->prog
.fs
->bo
, 0);
201 /* XXX: Use combined input/output size flag in the common
204 shader
.coordinate_shader_has_separate_input_and_output_vpm_blocks
= true;
205 shader
.vertex_shader_has_separate_input_and_output_vpm_blocks
= true;
206 shader
.coordinate_shader_input_vpm_segment_size
=
207 MAX2(v3d
->prog
.cs
->prog_data
.vs
->vpm_input_size
, 1);
208 shader
.vertex_shader_input_vpm_segment_size
=
209 MAX2(v3d
->prog
.vs
->prog_data
.vs
->vpm_input_size
, 1);
211 shader
.coordinate_shader_output_vpm_segment_size
=
212 v3d
->prog
.cs
->prog_data
.vs
->vpm_output_size
;
213 shader
.vertex_shader_output_vpm_segment_size
=
214 v3d
->prog
.vs
->prog_data
.vs
->vpm_output_size
;
216 shader
.coordinate_shader_uniforms_address
= cs_uniforms
;
217 shader
.vertex_shader_uniforms_address
= vs_uniforms
;
218 shader
.fragment_shader_uniforms_address
= fs_uniforms
;
220 #if V3D_VERSION >= 41
221 shader
.min_coord_shader_input_segments_required_in_play
= 1;
222 shader
.min_vertex_shader_input_segments_required_in_play
= 1;
224 shader
.coordinate_shader_4_way_threadable
=
225 v3d
->prog
.cs
->prog_data
.vs
->base
.threads
== 4;
226 shader
.vertex_shader_4_way_threadable
=
227 v3d
->prog
.vs
->prog_data
.vs
->base
.threads
== 4;
228 shader
.fragment_shader_4_way_threadable
=
229 v3d
->prog
.fs
->prog_data
.fs
->base
.threads
== 4;
231 shader
.coordinate_shader_start_in_final_thread_section
=
232 v3d
->prog
.cs
->prog_data
.vs
->base
.single_seg
;
233 shader
.vertex_shader_start_in_final_thread_section
=
234 v3d
->prog
.vs
->prog_data
.vs
->base
.single_seg
;
235 shader
.fragment_shader_start_in_final_thread_section
=
236 v3d
->prog
.fs
->prog_data
.fs
->base
.single_seg
;
238 shader
.coordinate_shader_4_way_threadable
=
239 v3d
->prog
.cs
->prog_data
.vs
->base
.threads
== 4;
240 shader
.coordinate_shader_2_way_threadable
=
241 v3d
->prog
.cs
->prog_data
.vs
->base
.threads
== 2;
242 shader
.vertex_shader_4_way_threadable
=
243 v3d
->prog
.vs
->prog_data
.vs
->base
.threads
== 4;
244 shader
.vertex_shader_2_way_threadable
=
245 v3d
->prog
.vs
->prog_data
.vs
->base
.threads
== 2;
246 shader
.fragment_shader_4_way_threadable
=
247 v3d
->prog
.fs
->prog_data
.fs
->base
.threads
== 4;
248 shader
.fragment_shader_2_way_threadable
=
249 v3d
->prog
.fs
->prog_data
.fs
->base
.threads
== 2;
252 shader
.vertex_id_read_by_coordinate_shader
=
253 v3d
->prog
.cs
->prog_data
.vs
->uses_vid
;
254 shader
.instance_id_read_by_coordinate_shader
=
255 v3d
->prog
.cs
->prog_data
.vs
->uses_iid
;
256 shader
.vertex_id_read_by_vertex_shader
=
257 v3d
->prog
.vs
->prog_data
.vs
->uses_vid
;
258 shader
.instance_id_read_by_vertex_shader
=
259 v3d
->prog
.vs
->prog_data
.vs
->uses_iid
;
261 shader
.address_of_default_attribute_values
=
262 cl_address(vtx
->default_attribute_values
, 0);
265 for (int i
= 0; i
< vtx
->num_elements
; i
++) {
266 struct pipe_vertex_element
*elem
= &vtx
->pipe
[i
];
267 struct pipe_vertex_buffer
*vb
=
268 &vertexbuf
->vb
[elem
->vertex_buffer_index
];
269 struct v3d_resource
*rsc
= v3d_resource(vb
->buffer
.resource
);
271 const uint32_t size
=
272 cl_packet_length(GL_SHADER_STATE_ATTRIBUTE_RECORD
);
273 cl_emit_with_prepacked(&job
->indirect
,
274 GL_SHADER_STATE_ATTRIBUTE_RECORD
,
275 &vtx
->attrs
[i
* size
], attr
) {
276 attr
.stride
= vb
->stride
;
277 attr
.address
= cl_address(rsc
->bo
,
280 attr
.number_of_values_read_by_coordinate_shader
=
281 v3d
->prog
.cs
->prog_data
.vs
->vattr_sizes
[i
];
282 attr
.number_of_values_read_by_vertex_shader
=
283 v3d
->prog
.vs
->prog_data
.vs
->vattr_sizes
[i
];
284 #if V3D_VERSION >= 41
285 attr
.maximum_index
= 0xffffff;
288 STATIC_ASSERT(sizeof(vtx
->attrs
) >= VC5_MAX_ATTRIBUTES
* size
);
291 if (vtx
->num_elements
== 0) {
292 /* GFXH-930: At least one attribute must be enabled and read
293 * by CS and VS. If we have no attributes being consumed by
294 * the shader, set up a dummy to be loaded into the VPM.
296 cl_emit(&job
->indirect
, GL_SHADER_STATE_ATTRIBUTE_RECORD
, attr
) {
297 /* Valid address of data whose value will be unused. */
298 attr
.address
= cl_address(job
->indirect
.bo
, 0);
300 attr
.type
= ATTRIBUTE_FLOAT
;
304 attr
.number_of_values_read_by_coordinate_shader
= 1;
305 attr
.number_of_values_read_by_vertex_shader
= 1;
309 cl_emit(&job
->bcl
, VCM_CACHE_SIZE
, vcm
) {
310 vcm
.number_of_16_vertex_batches_for_binning
=
311 v3d
->prog
.cs
->prog_data
.vs
->vcm_cache_size
;
312 vcm
.number_of_16_vertex_batches_for_rendering
=
313 v3d
->prog
.vs
->prog_data
.vs
->vcm_cache_size
;
316 cl_emit(&job
->bcl
, GL_SHADER_STATE
, state
) {
317 state
.address
= cl_address(job
->indirect
.bo
, shader_rec_offset
);
318 state
.number_of_attribute_arrays
= num_elements_to_emit
;
321 v3d_bo_unreference(&cs_uniforms
.bo
);
322 v3d_bo_unreference(&vs_uniforms
.bo
);
323 v3d_bo_unreference(&fs_uniforms
.bo
);
325 job
->shader_rec_count
++;
329 * Computes the various transform feedback statistics, since they can't be
330 * recorded by CL packets.
333 v3d_tf_statistics_record(struct v3d_context
*v3d
,
334 const struct pipe_draw_info
*info
,
337 if (!v3d
->active_queries
)
340 uint32_t prims
= u_prims_for_vertices(info
->mode
, info
->count
);
341 v3d
->prims_generated
+= prims
;
344 /* XXX: Only count if we didn't overflow. */
345 v3d
->tf_prims_generated
+= prims
;
350 v3d_update_job_ez(struct v3d_context
*v3d
, struct v3d_job
*job
)
352 switch (v3d
->zsa
->ez_state
) {
353 case VC5_EZ_UNDECIDED
:
354 /* If the Z/S state didn't pick a direction but didn't
355 * disable, then go along with the current EZ state. This
356 * allows EZ optimization for Z func == EQUAL or NEVER.
362 /* If the Z/S state picked a direction, then it needs to match
363 * the current direction if we've decided on one.
365 if (job
->ez_state
== VC5_EZ_UNDECIDED
)
366 job
->ez_state
= v3d
->zsa
->ez_state
;
367 else if (job
->ez_state
!= v3d
->zsa
->ez_state
)
368 job
->ez_state
= VC5_EZ_DISABLED
;
371 case VC5_EZ_DISABLED
:
372 /* If the current Z/S state disables EZ because of a bad Z
373 * func or stencil operation, then we can't do any more EZ in
376 job
->ez_state
= VC5_EZ_DISABLED
;
380 /* If the FS affects the Z of the pixels, then it may update against
381 * the chosen EZ direction (though we could use
382 * ARB_conservative_depth's hints to avoid this)
384 if (v3d
->prog
.fs
->prog_data
.fs
->writes_z
) {
385 job
->ez_state
= VC5_EZ_DISABLED
;
388 if (job
->first_ez_state
== VC5_EZ_UNDECIDED
&&
389 (job
->ez_state
!= VC5_EZ_DISABLED
|| job
->draw_calls_queued
== 0))
390 job
->first_ez_state
= job
->ez_state
;
394 v3d_draw_vbo(struct pipe_context
*pctx
, const struct pipe_draw_info
*info
)
396 struct v3d_context
*v3d
= v3d_context(pctx
);
398 if (!info
->count_from_stream_output
&& !info
->indirect
&&
399 !info
->primitive_restart
&&
400 !u_trim_pipe_prim(info
->mode
, (unsigned*)&info
->count
))
403 /* Fall back for weird desktop GL primitive restart values. */
404 if (info
->primitive_restart
&&
408 switch (info
->index_size
) {
417 if (info
->restart_index
!= mask
) {
418 util_draw_vbo_without_prim_restart(pctx
, info
);
423 if (info
->mode
>= PIPE_PRIM_QUADS
) {
424 util_primconvert_save_rasterizer_state(v3d
->primconvert
, &v3d
->rasterizer
->base
);
425 util_primconvert_draw_vbo(v3d
->primconvert
, info
);
426 perf_debug("Fallback conversion for %d %s vertices\n",
427 info
->count
, u_prim_name(info
->mode
));
431 /* Before setting up the draw, flush anything writing to the textures
434 v3d_predraw_check_textures(pctx
, &v3d
->verttex
);
435 v3d_predraw_check_textures(pctx
, &v3d
->fragtex
);
437 struct v3d_job
*job
= v3d_get_job_for_fbo(v3d
);
439 /* If vertex texturing depends on the output of rendering, we need to
440 * ensure that that rendering is complete before we run a coordinate
441 * shader that depends on it.
443 * Given that doing that is unusual, for now we just block the binner
444 * on the last submitted render, rather than tracking the last
445 * rendering to each texture's BO.
447 if (v3d
->verttex
.num_textures
) {
448 perf_debug("Blocking binner on last render "
449 "due to vertex texturing.\n");
450 job
->submit
.in_sync_bcl
= v3d
->out_sync
;
453 /* Get space to emit our draw call into the BCL, using a branch to
454 * jump to a new BO if necessary.
456 v3d_cl_ensure_space_with_branch(&job
->bcl
, 256 /* XXX */);
458 if (v3d
->prim_mode
!= info
->mode
) {
459 v3d
->prim_mode
= info
->mode
;
460 v3d
->dirty
|= VC5_DIRTY_PRIM_MODE
;
464 v3d_update_compiled_shaders(v3d
, info
->mode
);
465 v3d_update_job_ez(v3d
, job
);
467 #if V3D_VERSION >= 41
468 v3d41_emit_state(pctx
);
470 v3d33_emit_state(pctx
);
473 if (v3d
->dirty
& (VC5_DIRTY_VTXBUF
|
475 VC5_DIRTY_PRIM_MODE
|
476 VC5_DIRTY_RASTERIZER
|
477 VC5_DIRTY_COMPILED_CS
|
478 VC5_DIRTY_COMPILED_VS
|
479 VC5_DIRTY_COMPILED_FS
|
480 v3d
->prog
.cs
->uniform_dirty_bits
|
481 v3d
->prog
.vs
->uniform_dirty_bits
|
482 v3d
->prog
.fs
->uniform_dirty_bits
)) {
483 v3d_emit_gl_shader_state(v3d
, info
);
488 /* The Base Vertex/Base Instance packet sets those values to nonzero
489 * for the next draw call only.
491 if (info
->index_bias
|| info
->start_instance
) {
492 cl_emit(&job
->bcl
, BASE_VERTEX_BASE_INSTANCE
, base
) {
493 base
.base_instance
= info
->start_instance
;
494 base
.base_vertex
= info
->index_bias
;
498 uint32_t prim_tf_enable
= 0;
500 /* V3D 3.x: The HW only processes transform feedback on primitives
503 if (v3d
->streamout
.num_targets
)
504 prim_tf_enable
= (V3D_PRIM_POINTS_TF
- V3D_PRIM_POINTS
);
507 v3d_tf_statistics_record(v3d
, info
, v3d
->streamout
.num_targets
);
509 /* Note that the primitive type fields match with OpenGL/gallium
510 * definitions, up to but not including QUADS.
512 if (info
->index_size
) {
513 uint32_t index_size
= info
->index_size
;
514 uint32_t offset
= info
->start
* index_size
;
515 struct pipe_resource
*prsc
;
516 if (info
->has_user_indices
) {
518 u_upload_data(v3d
->uploader
, 0,
519 info
->count
* info
->index_size
, 4,
523 prsc
= info
->index
.resource
;
525 struct v3d_resource
*rsc
= v3d_resource(prsc
);
527 #if V3D_VERSION >= 40
528 cl_emit(&job
->bcl
, INDEX_BUFFER_SETUP
, ib
) {
529 ib
.address
= cl_address(rsc
->bo
, 0);
530 ib
.size
= rsc
->bo
->size
;
534 if (info
->instance_count
> 1) {
535 cl_emit(&job
->bcl
, INDEXED_INSTANCED_PRIM_LIST
, prim
) {
536 prim
.index_type
= ffs(info
->index_size
) - 1;
537 #if V3D_VERSION >= 40
538 prim
.index_offset
= offset
;
539 #else /* V3D_VERSION < 40 */
540 prim
.maximum_index
= (1u << 31) - 1; /* XXX */
541 prim
.address_of_indices_list
=
542 cl_address(rsc
->bo
, offset
);
543 #endif /* V3D_VERSION < 40 */
544 prim
.mode
= info
->mode
| prim_tf_enable
;
545 prim
.enable_primitive_restarts
= info
->primitive_restart
;
547 prim
.number_of_instances
= info
->instance_count
;
548 prim
.instance_length
= info
->count
;
551 cl_emit(&job
->bcl
, INDEXED_PRIM_LIST
, prim
) {
552 prim
.index_type
= ffs(info
->index_size
) - 1;
553 prim
.length
= info
->count
;
554 #if V3D_VERSION >= 40
555 prim
.index_offset
= offset
;
556 #else /* V3D_VERSION < 40 */
557 prim
.maximum_index
= (1u << 31) - 1; /* XXX */
558 prim
.address_of_indices_list
=
559 cl_address(rsc
->bo
, offset
);
560 #endif /* V3D_VERSION < 40 */
561 prim
.mode
= info
->mode
| prim_tf_enable
;
562 prim
.enable_primitive_restarts
= info
->primitive_restart
;
566 job
->draw_calls_queued
++;
568 if (info
->has_user_indices
)
569 pipe_resource_reference(&prsc
, NULL
);
571 if (info
->instance_count
> 1) {
572 cl_emit(&job
->bcl
, VERTEX_ARRAY_INSTANCED_PRIMS
, prim
) {
573 prim
.mode
= info
->mode
| prim_tf_enable
;
574 prim
.index_of_first_vertex
= info
->start
;
575 prim
.number_of_instances
= info
->instance_count
;
576 prim
.instance_length
= info
->count
;
579 cl_emit(&job
->bcl
, VERTEX_ARRAY_PRIMS
, prim
) {
580 prim
.mode
= info
->mode
| prim_tf_enable
;
581 prim
.length
= info
->count
;
582 prim
.index_of_first_vertex
= info
->start
;
587 /* A flush is required in between a TF draw and any following TF specs
588 * packet, or the GPU may hang. Just flush each time for now.
590 if (v3d
->streamout
.num_targets
)
591 cl_emit(&job
->bcl
, TRANSFORM_FEEDBACK_FLUSH_AND_COUNT
, flush
);
593 job
->draw_calls_queued
++;
595 /* Increment the TF offsets by how many verts we wrote. XXX: This
596 * needs some clamping to the buffer size.
598 for (int i
= 0; i
< v3d
->streamout
.num_targets
; i
++)
599 v3d
->streamout
.offsets
[i
] += info
->count
;
601 if (v3d
->zsa
&& job
->zsbuf
&& v3d
->zsa
->base
.depth
.enabled
) {
602 struct v3d_resource
*rsc
= v3d_resource(job
->zsbuf
->texture
);
603 v3d_job_add_bo(job
, rsc
->bo
);
605 job
->load
|= PIPE_CLEAR_DEPTH
& ~job
->clear
;
606 if (v3d
->zsa
->base
.depth
.writemask
)
607 job
->store
|= PIPE_CLEAR_DEPTH
;
608 rsc
->initialized_buffers
= PIPE_CLEAR_DEPTH
;
611 if (v3d
->zsa
&& job
->zsbuf
&& v3d
->zsa
->base
.stencil
[0].enabled
) {
612 struct v3d_resource
*rsc
= v3d_resource(job
->zsbuf
->texture
);
613 if (rsc
->separate_stencil
)
614 rsc
= rsc
->separate_stencil
;
616 v3d_job_add_bo(job
, rsc
->bo
);
618 job
->load
|= PIPE_CLEAR_STENCIL
& ~job
->clear
;
619 if (v3d
->zsa
->base
.stencil
[0].writemask
||
620 v3d
->zsa
->base
.stencil
[1].writemask
) {
621 job
->store
|= PIPE_CLEAR_STENCIL
;
623 rsc
->initialized_buffers
|= PIPE_CLEAR_STENCIL
;
626 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
627 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
628 int blend_rt
= v3d
->blend
->base
.independent_blend_enable
? i
: 0;
630 if (job
->store
& bit
|| !job
->cbufs
[i
])
632 struct v3d_resource
*rsc
= v3d_resource(job
->cbufs
[i
]->texture
);
634 job
->load
|= bit
& ~job
->clear
;
635 if (v3d
->blend
->base
.rt
[blend_rt
].colormask
)
637 v3d_job_add_bo(job
, rsc
->bo
);
640 if (job
->referenced_size
> 768 * 1024 * 1024) {
641 perf_debug("Flushing job with %dkb to try to free up memory\n",
642 job
->referenced_size
/ 1024);
646 if (V3D_DEBUG
& V3D_DEBUG_ALWAYS_FLUSH
)
651 * Implements gallium's clear() hook (glClear()) by drawing a pair of triangles.
654 v3d_draw_clear(struct v3d_context
*v3d
,
656 const union pipe_color_union
*color
,
657 double depth
, unsigned stencil
)
659 static const union pipe_color_union dummy_color
= {};
661 /* The blitter util dereferences the color regardless, even though the
662 * gallium clear API may not pass one in when only Z/S are cleared.
665 color
= &dummy_color
;
667 v3d_blitter_save(v3d
);
668 util_blitter_clear(v3d
->blitter
,
669 v3d
->framebuffer
.width
,
670 v3d
->framebuffer
.height
,
671 util_framebuffer_get_num_layers(&v3d
->framebuffer
),
672 buffers
, color
, depth
, stencil
);
676 * Attempts to perform the GL clear by using the TLB's fast clear at the start
680 v3d_tlb_clear(struct v3d_job
*job
, unsigned buffers
,
681 const union pipe_color_union
*color
,
682 double depth
, unsigned stencil
)
684 struct v3d_context
*v3d
= job
->v3d
;
686 if (job
->draw_calls_queued
) {
687 /* If anything in the CL has drawn using the buffer, then the
688 * TLB clear we're trying to add now would happen before that
691 buffers
&= ~(job
->load
| job
->store
);
694 /* GFXH-1461: If we were to emit a load of just depth or just stencil,
695 * then the clear for the other may get lost. We need to decide now
696 * if it would be possible to need to emit a load of just one after
697 * we've set up our TLB clears.
699 if (buffers
& PIPE_CLEAR_DEPTHSTENCIL
&&
700 (buffers
& PIPE_CLEAR_DEPTHSTENCIL
) != PIPE_CLEAR_DEPTHSTENCIL
&&
702 util_format_is_depth_and_stencil(job
->zsbuf
->texture
->format
)) {
703 buffers
&= ~PIPE_CLEAR_DEPTHSTENCIL
;
706 for (int i
= 0; i
< VC5_MAX_DRAW_BUFFERS
; i
++) {
707 uint32_t bit
= PIPE_CLEAR_COLOR0
<< i
;
708 if (!(buffers
& bit
))
711 struct pipe_surface
*psurf
= v3d
->framebuffer
.cbufs
[i
];
712 struct v3d_surface
*surf
= v3d_surface(psurf
);
713 struct v3d_resource
*rsc
= v3d_resource(psurf
->texture
);
716 uint32_t internal_size
= 4 << surf
->internal_bpp
;
718 static union pipe_color_union swapped_color
;
719 if (v3d
->swap_color_rb
& (1 << i
)) {
720 swapped_color
.f
[0] = color
->f
[2];
721 swapped_color
.f
[1] = color
->f
[1];
722 swapped_color
.f
[2] = color
->f
[0];
723 swapped_color
.f
[3] = color
->f
[3];
724 color
= &swapped_color
;
727 switch (surf
->internal_type
) {
728 case V3D_INTERNAL_TYPE_8
:
729 util_pack_color(color
->f
, PIPE_FORMAT_R8G8B8A8_UNORM
,
731 memcpy(job
->clear_color
[i
], uc
.ui
, internal_size
);
733 case V3D_INTERNAL_TYPE_8I
:
734 case V3D_INTERNAL_TYPE_8UI
:
735 job
->clear_color
[i
][0] = ((color
->ui
[0] & 0xff) |
736 (color
->ui
[1] & 0xff) << 8 |
737 (color
->ui
[2] & 0xff) << 16 |
738 (color
->ui
[3] & 0xff) << 24);
740 case V3D_INTERNAL_TYPE_16F
:
741 util_pack_color(color
->f
, PIPE_FORMAT_R16G16B16A16_FLOAT
,
743 memcpy(job
->clear_color
[i
], uc
.ui
, internal_size
);
745 case V3D_INTERNAL_TYPE_16I
:
746 case V3D_INTERNAL_TYPE_16UI
:
747 job
->clear_color
[i
][0] = ((color
->ui
[0] & 0xffff) |
749 job
->clear_color
[i
][1] = ((color
->ui
[2] & 0xffff) |
752 case V3D_INTERNAL_TYPE_32F
:
753 case V3D_INTERNAL_TYPE_32I
:
754 case V3D_INTERNAL_TYPE_32UI
:
755 memcpy(job
->clear_color
[i
], color
->ui
, internal_size
);
759 rsc
->initialized_buffers
|= bit
;
762 unsigned zsclear
= buffers
& PIPE_CLEAR_DEPTHSTENCIL
;
764 struct v3d_resource
*rsc
=
765 v3d_resource(v3d
->framebuffer
.zsbuf
->texture
);
767 if (zsclear
& PIPE_CLEAR_DEPTH
)
768 job
->clear_z
= depth
;
769 if (zsclear
& PIPE_CLEAR_STENCIL
)
770 job
->clear_s
= stencil
;
772 rsc
->initialized_buffers
|= zsclear
;
777 job
->draw_max_x
= v3d
->framebuffer
.width
;
778 job
->draw_max_y
= v3d
->framebuffer
.height
;
779 job
->clear
|= buffers
;
780 job
->store
|= buffers
;
788 v3d_clear(struct pipe_context
*pctx
, unsigned buffers
,
789 const union pipe_color_union
*color
, double depth
, unsigned stencil
)
791 struct v3d_context
*v3d
= v3d_context(pctx
);
792 struct v3d_job
*job
= v3d_get_job_for_fbo(v3d
);
794 buffers
&= ~v3d_tlb_clear(job
, buffers
, color
, depth
, stencil
);
797 v3d_draw_clear(v3d
, buffers
, color
, depth
, stencil
);
801 v3d_clear_render_target(struct pipe_context
*pctx
, struct pipe_surface
*ps
,
802 const union pipe_color_union
*color
,
803 unsigned x
, unsigned y
, unsigned w
, unsigned h
,
804 bool render_condition_enabled
)
806 fprintf(stderr
, "unimpl: clear RT\n");
810 v3d_clear_depth_stencil(struct pipe_context
*pctx
, struct pipe_surface
*ps
,
811 unsigned buffers
, double depth
, unsigned stencil
,
812 unsigned x
, unsigned y
, unsigned w
, unsigned h
,
813 bool render_condition_enabled
)
815 fprintf(stderr
, "unimpl: clear DS\n");
819 v3dX(draw_init
)(struct pipe_context
*pctx
)
821 pctx
->draw_vbo
= v3d_draw_vbo
;
822 pctx
->clear
= v3d_clear
;
823 pctx
->clear_render_target
= v3d_clear_render_target
;
824 pctx
->clear_depth_stencil
= v3d_clear_depth_stencil
;