2 * Copyright © 2017 Intel Corporation
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
26 #include "common/gen_device_info.h"
27 #include "common/gen_sample_positions.h"
28 #include "genxml/gen_macros.h"
30 #include "main/bufferobj.h"
31 #include "main/context.h"
32 #include "main/enums.h"
33 #include "main/macros.h"
35 #include "brw_context.h"
37 #include "brw_defines.h"
40 #include "brw_multisample_state.h"
41 #include "brw_state.h"
45 #include "intel_batchbuffer.h"
46 #include "intel_buffer_objects.h"
47 #include "intel_fbo.h"
49 #include "main/enums.h"
50 #include "main/fbobject.h"
51 #include "main/framebuffer.h"
52 #include "main/glformats.h"
53 #include "main/shaderapi.h"
54 #include "main/stencil.h"
55 #include "main/transformfeedback.h"
56 #include "main/varray.h"
57 #include "main/viewport.h"
60 emit_dwords(struct brw_context
*brw
, unsigned n
)
62 intel_batchbuffer_begin(brw
, n
, RENDER_RING
);
63 uint32_t *map
= brw
->batch
.map_next
;
64 brw
->batch
.map_next
+= n
;
65 intel_batchbuffer_advance(brw
);
71 uint32_t read_domains
;
72 uint32_t write_domain
;
77 emit_reloc(struct brw_context
*brw
,
78 void *location
, struct brw_address address
, uint32_t delta
)
80 uint32_t offset
= (char *) location
- (char *) brw
->batch
.map
;
82 return brw_emit_reloc(&brw
->batch
, offset
, address
.bo
,
83 address
.offset
+ delta
,
85 address
.write_domain
);
88 #define __gen_address_type struct brw_address
89 #define __gen_user_data struct brw_context
92 __gen_combine_address(struct brw_context
*brw
, void *location
,
93 struct brw_address address
, uint32_t delta
)
95 if (address
.bo
== NULL
) {
96 return address
.offset
+ delta
;
98 return emit_reloc(brw
, location
, address
, delta
);
102 static inline struct brw_address
103 render_bo(struct brw_bo
*bo
, uint32_t offset
)
105 return (struct brw_address
) {
108 .read_domains
= I915_GEM_DOMAIN_RENDER
,
109 .write_domain
= I915_GEM_DOMAIN_RENDER
,
113 static inline struct brw_address
114 render_ro_bo(struct brw_bo
*bo
, uint32_t offset
)
116 return (struct brw_address
) {
119 .read_domains
= I915_GEM_DOMAIN_RENDER
,
124 static inline struct brw_address
125 instruction_bo(struct brw_bo
*bo
, uint32_t offset
)
127 return (struct brw_address
) {
130 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
131 .write_domain
= I915_GEM_DOMAIN_INSTRUCTION
,
135 static inline struct brw_address
136 vertex_bo(struct brw_bo
*bo
, uint32_t offset
)
138 return (struct brw_address
) {
141 .read_domains
= I915_GEM_DOMAIN_VERTEX
,
146 #include "genxml/genX_pack.h"
148 #define _brw_cmd_length(cmd) cmd ## _length
149 #define _brw_cmd_length_bias(cmd) cmd ## _length_bias
150 #define _brw_cmd_header(cmd) cmd ## _header
151 #define _brw_cmd_pack(cmd) cmd ## _pack
153 #define brw_batch_emit(brw, cmd, name) \
154 for (struct cmd name = { _brw_cmd_header(cmd) }, \
155 *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
156 __builtin_expect(_dst != NULL, 1); \
157 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
160 #define brw_batch_emitn(brw, cmd, n, ...) ({ \
161 uint32_t *_dw = emit_dwords(brw, n); \
162 struct cmd template = { \
163 _brw_cmd_header(cmd), \
164 .DWordLength = n - _brw_cmd_length_bias(cmd), \
167 _brw_cmd_pack(cmd)(brw, _dw, &template); \
168 _dw + 1; /* Array starts at dw[1] */ \
171 #define brw_state_emit(brw, cmd, align, offset, name) \
172 for (struct cmd name = { 0, }, \
173 *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4, \
175 __builtin_expect(_dst != NULL, 1); \
176 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
180 * Polygon stipple packet
183 genX(upload_polygon_stipple
)(struct brw_context
*brw
)
185 struct gl_context
*ctx
= &brw
->ctx
;
188 if (!ctx
->Polygon
.StippleFlag
)
191 brw_batch_emit(brw
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
192 /* Polygon stipple is provided in OpenGL order, i.e. bottom
193 * row first. If we're rendering to a window (i.e. the
194 * default frame buffer object, 0), then we need to invert
195 * it to match our pixel layout. But if we're rendering
196 * to a FBO (i.e. any named frame buffer object), we *don't*
197 * need to invert - we already match the layout.
199 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
200 for (unsigned i
= 0; i
< 32; i
++)
201 poly
.PatternRow
[i
] = ctx
->PolygonStipple
[31 - i
]; /* invert */
203 for (unsigned i
= 0; i
< 32; i
++)
204 poly
.PatternRow
[i
] = ctx
->PolygonStipple
[i
];
209 static const struct brw_tracked_state
genX(polygon_stipple
) = {
211 .mesa
= _NEW_POLYGON
|
213 .brw
= BRW_NEW_CONTEXT
,
215 .emit
= genX(upload_polygon_stipple
),
219 * Polygon stipple offset packet
222 genX(upload_polygon_stipple_offset
)(struct brw_context
*brw
)
224 struct gl_context
*ctx
= &brw
->ctx
;
227 if (!ctx
->Polygon
.StippleFlag
)
230 brw_batch_emit(brw
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), poly
) {
233 * If we're drawing to a system window we have to invert the Y axis
234 * in order to match the OpenGL pixel coordinate system, and our
235 * offset must be matched to the window position. If we're drawing
236 * to a user-created FBO then our native pixel coordinate system
237 * works just fine, and there's no window system to worry about.
239 if (_mesa_is_winsys_fbo(ctx
->DrawBuffer
)) {
240 poly
.PolygonStippleYOffset
=
241 (32 - (_mesa_geometric_height(ctx
->DrawBuffer
) & 31)) & 31;
246 static const struct brw_tracked_state
genX(polygon_stipple_offset
) = {
248 .mesa
= _NEW_BUFFERS
|
250 .brw
= BRW_NEW_CONTEXT
,
252 .emit
= genX(upload_polygon_stipple_offset
),
256 * Line stipple packet
259 genX(upload_line_stipple
)(struct brw_context
*brw
)
261 struct gl_context
*ctx
= &brw
->ctx
;
263 if (!ctx
->Line
.StippleFlag
)
266 brw_batch_emit(brw
, GENX(3DSTATE_LINE_STIPPLE
), line
) {
267 line
.LineStipplePattern
= ctx
->Line
.StipplePattern
;
269 line
.LineStippleInverseRepeatCount
= 1.0f
/ ctx
->Line
.StippleFactor
;
270 line
.LineStippleRepeatCount
= ctx
->Line
.StippleFactor
;
274 static const struct brw_tracked_state
genX(line_stipple
) = {
277 .brw
= BRW_NEW_CONTEXT
,
279 .emit
= genX(upload_line_stipple
),
282 /* Constant single cliprect for framebuffer object or DRI2 drawing */
284 genX(upload_drawing_rect
)(struct brw_context
*brw
)
286 struct gl_context
*ctx
= &brw
->ctx
;
287 const struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
288 const unsigned int fb_width
= _mesa_geometric_width(fb
);
289 const unsigned int fb_height
= _mesa_geometric_height(fb
);
291 brw_batch_emit(brw
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
292 rect
.ClippedDrawingRectangleXMax
= fb_width
- 1;
293 rect
.ClippedDrawingRectangleYMax
= fb_height
- 1;
297 static const struct brw_tracked_state
genX(drawing_rect
) = {
299 .mesa
= _NEW_BUFFERS
,
300 .brw
= BRW_NEW_BLORP
|
303 .emit
= genX(upload_drawing_rect
),
307 genX(emit_vertex_buffer_state
)(struct brw_context
*brw
,
311 unsigned start_offset
,
316 struct GENX(VERTEX_BUFFER_STATE
) buf_state
= {
317 .VertexBufferIndex
= buffer_nr
,
318 .BufferPitch
= stride
,
319 .BufferStartingAddress
= vertex_bo(bo
, start_offset
),
321 .BufferSize
= end_offset
- start_offset
,
325 .AddressModifyEnable
= true,
329 .BufferAccessType
= step_rate
? INSTANCEDATA
: VERTEXDATA
,
330 .InstanceDataStepRate
= step_rate
,
332 .EndAddress
= vertex_bo(bo
, end_offset
- 1),
337 .VertexBufferMOCS
= SKL_MOCS_WB
,
339 .VertexBufferMOCS
= BDW_MOCS_WB
,
341 .VertexBufferMOCS
= GEN7_MOCS_L3
,
345 GENX(VERTEX_BUFFER_STATE_pack
)(brw
, dw
, &buf_state
);
346 return dw
+ GENX(VERTEX_BUFFER_STATE_length
);
350 is_passthru_format(uint32_t format
)
353 case ISL_FORMAT_R64_PASSTHRU
:
354 case ISL_FORMAT_R64G64_PASSTHRU
:
355 case ISL_FORMAT_R64G64B64_PASSTHRU
:
356 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
364 genX(uploads_needed
)(uint32_t format
)
366 if (!is_passthru_format(format
))
370 case ISL_FORMAT_R64_PASSTHRU
:
371 case ISL_FORMAT_R64G64_PASSTHRU
:
373 case ISL_FORMAT_R64G64B64_PASSTHRU
:
374 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
377 unreachable("not reached");
382 * Returns the format that we are finally going to use when upload a vertex
383 * element. It will only change if we are using *64*PASSTHRU formats, as for
384 * gen < 8 they need to be splitted on two *32*FLOAT formats.
386 * @upload points in which upload we are. Valid values are [0,1]
389 downsize_format_if_needed(uint32_t format
,
392 assert(upload
== 0 || upload
== 1);
394 if (!is_passthru_format(format
))
398 case ISL_FORMAT_R64_PASSTHRU
:
399 return ISL_FORMAT_R32G32_FLOAT
;
400 case ISL_FORMAT_R64G64_PASSTHRU
:
401 return ISL_FORMAT_R32G32B32A32_FLOAT
;
402 case ISL_FORMAT_R64G64B64_PASSTHRU
:
403 return !upload
? ISL_FORMAT_R32G32B32A32_FLOAT
404 : ISL_FORMAT_R32G32_FLOAT
;
405 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
406 return ISL_FORMAT_R32G32B32A32_FLOAT
;
408 unreachable("not reached");
413 * Returns the number of componentes associated with a format that is used on
414 * a 64 to 32 format split. See downsize_format()
417 upload_format_size(uint32_t upload_format
)
419 switch (upload_format
) {
420 case ISL_FORMAT_R32G32_FLOAT
:
422 case ISL_FORMAT_R32G32B32A32_FLOAT
:
425 unreachable("not reached");
430 genX(emit_vertices
)(struct brw_context
*brw
)
434 brw_prepare_vertices(brw
);
435 brw_prepare_shader_draw_parameters(brw
);
438 brw_emit_query_begin(brw
);
441 const struct brw_vs_prog_data
*vs_prog_data
=
442 brw_vs_prog_data(brw
->vs
.base
.prog_data
);
445 struct gl_context
*ctx
= &brw
->ctx
;
446 bool uses_edge_flag
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
447 ctx
->Polygon
.BackMode
!= GL_FILL
);
449 if (vs_prog_data
->uses_vertexid
|| vs_prog_data
->uses_instanceid
) {
450 unsigned vue
= brw
->vb
.nr_enabled
;
452 /* The element for the edge flags must always be last, so we have to
453 * insert the SGVS before it in that case.
455 if (uses_edge_flag
) {
461 "Trying to insert VID/IID past 33rd vertex element, "
462 "need to reorder the vertex attrbutes.");
464 brw_batch_emit(brw
, GENX(3DSTATE_VF_SGVS
), vfs
) {
465 if (vs_prog_data
->uses_vertexid
) {
466 vfs
.VertexIDEnable
= true;
467 vfs
.VertexIDComponentNumber
= 2;
468 vfs
.VertexIDElementOffset
= vue
;
471 if (vs_prog_data
->uses_instanceid
) {
472 vfs
.InstanceIDEnable
= true;
473 vfs
.InstanceIDComponentNumber
= 3;
474 vfs
.InstanceIDElementOffset
= vue
;
478 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
479 vfi
.InstancingEnable
= true;
480 vfi
.VertexElementIndex
= vue
;
483 brw_batch_emit(brw
, GENX(3DSTATE_VF_SGVS
), vfs
);
486 /* Normally we don't need an element for the SGVS attribute because the
487 * 3DSTATE_VF_SGVS instruction lets you store the generated attribute in an
488 * element that is past the list in 3DSTATE_VERTEX_ELEMENTS. However if
489 * we're using draw parameters then we need an element for the those
490 * values. Additionally if there is an edge flag element then the SGVS
491 * can't be inserted past that so we need a dummy element to ensure that
492 * the edge flag is the last one.
494 const bool needs_sgvs_element
= (vs_prog_data
->uses_basevertex
||
495 vs_prog_data
->uses_baseinstance
||
496 ((vs_prog_data
->uses_instanceid
||
497 vs_prog_data
->uses_vertexid
)
500 const bool needs_sgvs_element
= (vs_prog_data
->uses_basevertex
||
501 vs_prog_data
->uses_baseinstance
||
502 vs_prog_data
->uses_instanceid
||
503 vs_prog_data
->uses_vertexid
);
505 unsigned nr_elements
=
506 brw
->vb
.nr_enabled
+ needs_sgvs_element
+ vs_prog_data
->uses_drawid
;
509 /* If any of the formats of vb.enabled needs more that one upload, we need
510 * to add it to nr_elements
512 for (unsigned i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
513 struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
514 uint32_t format
= brw_get_vertex_surface_type(brw
, input
->glarray
);
516 if (genX(uploads_needed(format
)) > 1)
521 /* If the VS doesn't read any inputs (calculating vertex position from
522 * a state variable for some reason, for example), emit a single pad
523 * VERTEX_ELEMENT struct and bail.
525 * The stale VB state stays in place, but they don't do anything unless
526 * a VE loads from them.
528 if (nr_elements
== 0) {
529 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_ELEMENTS
), 1 + GENX(VERTEX_ELEMENT_STATE_length
));
530 struct GENX(VERTEX_ELEMENT_STATE
) elem
= {
532 .SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
,
533 .Component0Control
= VFCOMP_STORE_0
,
534 .Component1Control
= VFCOMP_STORE_0
,
535 .Component2Control
= VFCOMP_STORE_0
,
536 .Component3Control
= VFCOMP_STORE_1_FP
,
538 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem
);
542 /* Now emit 3DSTATE_VERTEX_BUFFERS and 3DSTATE_VERTEX_ELEMENTS packets. */
543 const bool uses_draw_params
=
544 vs_prog_data
->uses_basevertex
||
545 vs_prog_data
->uses_baseinstance
;
546 const unsigned nr_buffers
= brw
->vb
.nr_buffers
+
547 uses_draw_params
+ vs_prog_data
->uses_drawid
;
551 assert(nr_buffers
<= 33);
553 assert(nr_buffers
<= 17);
555 assert(nr_buffers
<= (GEN_GEN
>= 6 ? 33 : 17));
557 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_BUFFERS
),
558 1 + GENX(VERTEX_BUFFER_STATE_length
) * nr_buffers
);
560 for (unsigned i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
561 const struct brw_vertex_buffer
*buffer
= &brw
->vb
.buffers
[i
];
562 /* Prior to Haswell and Bay Trail we have to use 4-component formats
563 * to fake 3-component ones. In particular, we do this for
564 * half-float and 8 and 16-bit integer formats. This means that the
565 * vertex element may poke over the end of the buffer by 2 bytes.
568 (GEN_GEN
<= 7 && !brw
->is_baytrail
&& !brw
->is_haswell
) * 2;
569 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, i
, buffer
->bo
,
571 buffer
->offset
+ buffer
->size
+ padding
,
576 if (uses_draw_params
) {
577 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, brw
->vb
.nr_buffers
,
578 brw
->draw
.draw_params_bo
,
579 brw
->draw
.draw_params_offset
,
580 brw
->draw
.draw_params_bo
->size
,
585 if (vs_prog_data
->uses_drawid
) {
586 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, brw
->vb
.nr_buffers
+ 1,
587 brw
->draw
.draw_id_bo
,
588 brw
->draw
.draw_id_offset
,
589 brw
->draw
.draw_id_bo
->size
,
595 /* The hardware allows one more VERTEX_ELEMENTS than VERTEX_BUFFERS,
596 * presumably for VertexID/InstanceID.
599 assert(nr_elements
<= 34);
600 struct brw_vertex_element
*gen6_edgeflag_input
= NULL
;
602 assert(nr_elements
<= 18);
605 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_ELEMENTS
),
606 1 + GENX(VERTEX_ELEMENT_STATE_length
) * nr_elements
);
608 for (i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
609 struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
610 uint32_t format
= brw_get_vertex_surface_type(brw
, input
->glarray
);
611 uint32_t comp0
= VFCOMP_STORE_SRC
;
612 uint32_t comp1
= VFCOMP_STORE_SRC
;
613 uint32_t comp2
= VFCOMP_STORE_SRC
;
614 uint32_t comp3
= VFCOMP_STORE_SRC
;
615 unsigned num_uploads
= 1;
618 /* From the BDW PRM, Volume 2d, page 588 (VERTEX_ELEMENT_STATE):
619 * "Any SourceElementFormat of *64*_PASSTHRU cannot be used with an
620 * element which has edge flag enabled."
622 assert(!(is_passthru_format(format
) && uses_edge_flag
));
625 /* The gen4 driver expects edgeflag to come in as a float, and passes
626 * that float on to the tests in the clipper. Mesa's current vertex
627 * attribute value for EdgeFlag is stored as a float, which works out.
628 * glEdgeFlagPointer, on the other hand, gives us an unnormalized
629 * integer ubyte. Just rewrite that to convert to a float.
631 * Gen6+ passes edgeflag as sideband along with the vertex, instead
632 * of in the VUE. We have to upload it sideband as the last vertex
633 * element according to the B-Spec.
636 if (input
== &brw
->vb
.inputs
[VERT_ATTRIB_EDGEFLAG
]) {
637 gen6_edgeflag_input
= input
;
643 num_uploads
= genX(uploads_needed(format
));
646 for (unsigned c
= 0; c
< num_uploads
; c
++) {
647 uint32_t upload_format
= GEN_GEN
>= 8 ? format
:
648 downsize_format_if_needed(format
, c
);
649 /* If we need more that one upload, the offset stride would be 128
650 * bits (16 bytes), as for previous uploads we are using the full
652 unsigned int offset
= input
->offset
+ c
* 16;
653 int size
= input
->glarray
->Size
;
655 if (GEN_GEN
< 8 && is_passthru_format(format
))
656 size
= upload_format_size(upload_format
);
659 case 0: comp0
= VFCOMP_STORE_0
;
660 case 1: comp1
= VFCOMP_STORE_0
;
661 case 2: comp2
= VFCOMP_STORE_0
;
663 if (GEN_GEN
>= 8 && input
->glarray
->Doubles
) {
664 comp3
= VFCOMP_STORE_0
;
665 } else if (input
->glarray
->Integer
) {
666 comp3
= VFCOMP_STORE_1_INT
;
668 comp3
= VFCOMP_STORE_1_FP
;
675 /* From the BDW PRM, Volume 2d, page 586 (VERTEX_ELEMENT_STATE):
677 * "When SourceElementFormat is set to one of the *64*_PASSTHRU
678 * formats, 64-bit components are stored in the URB without any
679 * conversion. In this case, vertex elements must be written as 128
680 * or 256 bits, with VFCOMP_STORE_0 being used to pad the output as
681 * required. E.g., if R64_PASSTHRU is used to copy a 64-bit Red
682 * component into the URB, Component 1 must be specified as
683 * VFCOMP_STORE_0 (with Components 2,3 set to VFCOMP_NOSTORE) in
684 * order to output a 128-bit vertex element, or Components 1-3 must
685 * be specified as VFCOMP_STORE_0 in order to output a 256-bit vertex
686 * element. Likewise, use of R64G64B64_PASSTHRU requires Component 3
687 * to be specified as VFCOMP_STORE_0 in order to output a 256-bit
690 if (input
->glarray
->Doubles
&& !input
->is_dual_slot
) {
691 /* Store vertex elements which correspond to double and dvec2 vertex
692 * shader inputs as 128-bit vertex elements, instead of 256-bits.
694 comp2
= VFCOMP_NOSTORE
;
695 comp3
= VFCOMP_NOSTORE
;
699 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
700 .VertexBufferIndex
= input
->buffer
,
702 .SourceElementFormat
= upload_format
,
703 .SourceElementOffset
= offset
,
704 .Component0Control
= comp0
,
705 .Component1Control
= comp1
,
706 .Component2Control
= comp2
,
707 .Component3Control
= comp3
,
709 .DestinationElementOffset
= i
* 4,
713 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
714 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
718 if (needs_sgvs_element
) {
719 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
721 .Component0Control
= VFCOMP_STORE_0
,
722 .Component1Control
= VFCOMP_STORE_0
,
723 .Component2Control
= VFCOMP_STORE_0
,
724 .Component3Control
= VFCOMP_STORE_0
,
726 .DestinationElementOffset
= i
* 4,
731 if (vs_prog_data
->uses_basevertex
||
732 vs_prog_data
->uses_baseinstance
) {
733 elem_state
.VertexBufferIndex
= brw
->vb
.nr_buffers
;
734 elem_state
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
735 elem_state
.Component0Control
= VFCOMP_STORE_SRC
;
736 elem_state
.Component1Control
= VFCOMP_STORE_SRC
;
739 elem_state
.VertexBufferIndex
= brw
->vb
.nr_buffers
;
740 elem_state
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
741 if (vs_prog_data
->uses_basevertex
)
742 elem_state
.Component0Control
= VFCOMP_STORE_SRC
;
744 if (vs_prog_data
->uses_baseinstance
)
745 elem_state
.Component1Control
= VFCOMP_STORE_SRC
;
747 if (vs_prog_data
->uses_vertexid
)
748 elem_state
.Component2Control
= VFCOMP_STORE_VID
;
750 if (vs_prog_data
->uses_instanceid
)
751 elem_state
.Component3Control
= VFCOMP_STORE_IID
;
754 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
755 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
758 if (vs_prog_data
->uses_drawid
) {
759 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
761 .VertexBufferIndex
= brw
->vb
.nr_buffers
+ 1,
762 .SourceElementFormat
= ISL_FORMAT_R32_UINT
,
763 .Component0Control
= VFCOMP_STORE_SRC
,
764 .Component1Control
= VFCOMP_STORE_0
,
765 .Component2Control
= VFCOMP_STORE_0
,
766 .Component3Control
= VFCOMP_STORE_0
,
768 .DestinationElementOffset
= i
* 4,
772 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
773 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
777 if (gen6_edgeflag_input
) {
779 brw_get_vertex_surface_type(brw
, gen6_edgeflag_input
->glarray
);
781 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
783 .VertexBufferIndex
= gen6_edgeflag_input
->buffer
,
784 .EdgeFlagEnable
= true,
785 .SourceElementFormat
= format
,
786 .SourceElementOffset
= gen6_edgeflag_input
->offset
,
787 .Component0Control
= VFCOMP_STORE_SRC
,
788 .Component1Control
= VFCOMP_STORE_0
,
789 .Component2Control
= VFCOMP_STORE_0
,
790 .Component3Control
= VFCOMP_STORE_0
,
793 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
794 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
799 for (unsigned i
= 0, j
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
800 const struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
801 const struct brw_vertex_buffer
*buffer
= &brw
->vb
.buffers
[input
->buffer
];
802 unsigned element_index
;
804 /* The edge flag element is reordered to be the last one in the code
805 * above so we need to compensate for that in the element indices used
808 if (input
== gen6_edgeflag_input
)
809 element_index
= nr_elements
- 1;
813 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
814 vfi
.VertexElementIndex
= element_index
;
815 vfi
.InstancingEnable
= buffer
->step_rate
!= 0;
816 vfi
.InstanceDataStepRate
= buffer
->step_rate
;
820 if (vs_prog_data
->uses_drawid
) {
821 const unsigned element
= brw
->vb
.nr_enabled
+ needs_sgvs_element
;
823 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
824 vfi
.VertexElementIndex
= element
;
830 static const struct brw_tracked_state
genX(vertices
) = {
832 .mesa
= _NEW_POLYGON
,
833 .brw
= BRW_NEW_BATCH
|
836 BRW_NEW_VS_PROG_DATA
,
838 .emit
= genX(emit_vertices
),
841 #if GEN_IS_HASWELL || GEN_GEN >= 8
843 genX(upload_cut_index
)(struct brw_context
*brw
)
845 const struct gl_context
*ctx
= &brw
->ctx
;
847 brw_batch_emit(brw
, GENX(3DSTATE_VF
), vf
) {
848 if (ctx
->Array
._PrimitiveRestart
&& brw
->ib
.ib
) {
849 vf
.IndexedDrawCutIndexEnable
= true;
850 vf
.CutIndex
= _mesa_primitive_restart_index(ctx
, brw
->ib
.index_size
);
855 const struct brw_tracked_state
genX(cut_index
) = {
857 .mesa
= _NEW_TRANSFORM
,
858 .brw
= BRW_NEW_INDEX_BUFFER
,
860 .emit
= genX(upload_cut_index
),
866 * Determine the appropriate attribute override value to store into the
867 * 3DSTATE_SF structure for a given fragment shader attribute. The attribute
868 * override value contains two pieces of information: the location of the
869 * attribute in the VUE (relative to urb_entry_read_offset, see below), and a
870 * flag indicating whether to "swizzle" the attribute based on the direction
871 * the triangle is facing.
873 * If an attribute is "swizzled", then the given VUE location is used for
874 * front-facing triangles, and the VUE location that immediately follows is
875 * used for back-facing triangles. We use this to implement the mapping from
876 * gl_FrontColor/gl_BackColor to gl_Color.
878 * urb_entry_read_offset is the offset into the VUE at which the SF unit is
879 * being instructed to begin reading attribute data. It can be set to a
880 * nonzero value to prevent the SF unit from wasting time reading elements of
881 * the VUE that are not needed by the fragment shader. It is measured in
882 * 256-bit increments.
885 genX(get_attr_override
)(struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
,
886 const struct brw_vue_map
*vue_map
,
887 int urb_entry_read_offset
, int fs_attr
,
888 bool two_side_color
, uint32_t *max_source_attr
)
890 /* Find the VUE slot for this attribute. */
891 int slot
= vue_map
->varying_to_slot
[fs_attr
];
893 /* Viewport and Layer are stored in the VUE header. We need to override
894 * them to zero if earlier stages didn't write them, as GL requires that
895 * they read back as zero when not explicitly set.
897 if (fs_attr
== VARYING_SLOT_VIEWPORT
|| fs_attr
== VARYING_SLOT_LAYER
) {
898 attr
->ComponentOverrideX
= true;
899 attr
->ComponentOverrideW
= true;
900 attr
->ConstantSource
= CONST_0000
;
902 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
903 attr
->ComponentOverrideY
= true;
904 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
905 attr
->ComponentOverrideZ
= true;
910 /* If there was only a back color written but not front, use back
911 * as the color instead of undefined
913 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
914 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
915 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
916 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
919 /* This attribute does not exist in the VUE--that means that the vertex
920 * shader did not write to it. This means that either:
922 * (a) This attribute is a texture coordinate, and it is going to be
923 * replaced with point coordinates (as a consequence of a call to
924 * glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)), so the
925 * hardware will ignore whatever attribute override we supply.
927 * (b) This attribute is read by the fragment shader but not written by
928 * the vertex shader, so its value is undefined. Therefore the
929 * attribute override we supply doesn't matter.
931 * (c) This attribute is gl_PrimitiveID, and it wasn't written by the
932 * previous shader stage.
934 * Note that we don't have to worry about the cases where the attribute
935 * is gl_PointCoord or is undergoing point sprite coordinate
936 * replacement, because in those cases, this function isn't called.
938 * In case (c), we need to program the attribute overrides so that the
939 * primitive ID will be stored in this slot. In every other case, the
940 * attribute override we supply doesn't matter. So just go ahead and
941 * program primitive ID in every case.
943 attr
->ComponentOverrideW
= true;
944 attr
->ComponentOverrideX
= true;
945 attr
->ComponentOverrideY
= true;
946 attr
->ComponentOverrideZ
= true;
947 attr
->ConstantSource
= PRIM_ID
;
951 /* Compute the location of the attribute relative to urb_entry_read_offset.
952 * Each increment of urb_entry_read_offset represents a 256-bit value, so
953 * it counts for two 128-bit VUE slots.
955 int source_attr
= slot
- 2 * urb_entry_read_offset
;
956 assert(source_attr
>= 0 && source_attr
< 32);
958 /* If we are doing two-sided color, and the VUE slot following this one
959 * represents a back-facing color, then we need to instruct the SF unit to
960 * do back-facing swizzling.
962 bool swizzling
= two_side_color
&&
963 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
964 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
965 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
966 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
));
968 /* Update max_source_attr. If swizzling, the SF will read this slot + 1. */
969 if (*max_source_attr
< source_attr
+ swizzling
)
970 *max_source_attr
= source_attr
+ swizzling
;
972 attr
->SourceAttribute
= source_attr
;
974 attr
->SwizzleSelect
= INPUTATTR_FACING
;
979 genX(calculate_attr_overrides
)(const struct brw_context
*brw
,
980 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr_overrides
,
981 uint32_t *point_sprite_enables
,
982 uint32_t *urb_entry_read_length
,
983 uint32_t *urb_entry_read_offset
)
985 const struct gl_context
*ctx
= &brw
->ctx
;
988 const struct gl_point_attrib
*point
= &ctx
->Point
;
990 /* BRW_NEW_FS_PROG_DATA */
991 const struct brw_wm_prog_data
*wm_prog_data
=
992 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
993 uint32_t max_source_attr
= 0;
995 *point_sprite_enables
= 0;
997 /* BRW_NEW_FRAGMENT_PROGRAM
999 * If the fragment shader reads VARYING_SLOT_LAYER, then we need to pass in
1000 * the full vertex header. Otherwise, we can program the SF to start
1001 * reading at an offset of 1 (2 varying slots) to skip unnecessary data:
1002 * - VARYING_SLOT_PSIZ and BRW_VARYING_SLOT_NDC on gen4-5
1003 * - VARYING_SLOT_{PSIZ,LAYER} and VARYING_SLOT_POS on gen6+
1006 bool fs_needs_vue_header
= brw
->fragment_program
->info
.inputs_read
&
1007 (VARYING_BIT_LAYER
| VARYING_BIT_VIEWPORT
);
1009 *urb_entry_read_offset
= fs_needs_vue_header
? 0 : 1;
1011 /* From the Ivybridge PRM, Vol 2 Part 1, 3DSTATE_SBE,
1012 * description of dw10 Point Sprite Texture Coordinate Enable:
1014 * "This field must be programmed to zero when non-point primitives
1017 * The SandyBridge PRM doesn't explicitly say that point sprite enables
1018 * must be programmed to zero when rendering non-point primitives, but
1019 * the IvyBridge PRM does, and if we don't, we get garbage.
1021 * This is not required on Haswell, as the hardware ignores this state
1022 * when drawing non-points -- although we do still need to be careful to
1023 * correctly set the attr overrides.
1026 * BRW_NEW_PRIMITIVE | BRW_NEW_GS_PROG_DATA | BRW_NEW_TES_PROG_DATA
1028 bool drawing_points
= brw_is_drawing_points(brw
);
1030 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
1031 int input_index
= wm_prog_data
->urb_setup
[attr
];
1033 if (input_index
< 0)
1037 bool point_sprite
= false;
1038 if (drawing_points
) {
1039 if (point
->PointSprite
&&
1040 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) &&
1041 (point
->CoordReplace
& (1u << (attr
- VARYING_SLOT_TEX0
)))) {
1042 point_sprite
= true;
1045 if (attr
== VARYING_SLOT_PNTC
)
1046 point_sprite
= true;
1049 *point_sprite_enables
|= (1 << input_index
);
1052 /* BRW_NEW_VUE_MAP_GEOM_OUT | _NEW_LIGHT | _NEW_PROGRAM */
1053 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attribute
= { 0 };
1055 if (!point_sprite
) {
1056 genX(get_attr_override
)(&attribute
,
1057 &brw
->vue_map_geom_out
,
1058 *urb_entry_read_offset
, attr
,
1059 brw
->ctx
.VertexProgram
._TwoSideEnabled
,
1063 /* The hardware can only do the overrides on 16 overrides at a
1064 * time, and the other up to 16 have to be lined up so that the
1065 * input index = the output index. We'll need to do some
1066 * tweaking to make sure that's the case.
1068 if (input_index
< 16)
1069 attr_overrides
[input_index
] = attribute
;
1071 assert(attribute
.SourceAttribute
== input_index
);
1074 /* From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
1075 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
1077 * "This field should be set to the minimum length required to read the
1078 * maximum source attribute. The maximum source attribute is indicated
1079 * by the maximum value of the enabled Attribute # Source Attribute if
1080 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
1081 * enable is not set.
1082 * read_length = ceiling((max_source_attr + 1) / 2)
1084 * [errata] Corruption/Hang possible if length programmed larger than
1087 * Similar text exists for Ivy Bridge.
1089 *urb_entry_read_length
= DIV_ROUND_UP(max_source_attr
+ 1, 2);
1093 /* ---------------------------------------------------------------------- */
1097 genX(upload_depth_stencil_state
)(struct brw_context
*brw
)
1099 struct gl_context
*ctx
= &brw
->ctx
;
1102 struct intel_renderbuffer
*depth_irb
=
1103 intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
1106 struct gl_depthbuffer_attrib
*depth
= &ctx
->Depth
;
1109 struct gl_stencil_attrib
*stencil
= &ctx
->Stencil
;
1110 const int b
= stencil
->_BackFace
;
1113 brw_batch_emit(brw
, GENX(3DSTATE_WM_DEPTH_STENCIL
), wmds
) {
1116 brw_state_emit(brw
, GENX(DEPTH_STENCIL_STATE
), 64, &ds_offset
, wmds
) {
1118 if (depth
->Test
&& depth_irb
) {
1119 wmds
.DepthTestEnable
= true;
1120 wmds
.DepthBufferWriteEnable
= brw_depth_writes_enabled(brw
);
1121 wmds
.DepthTestFunction
= intel_translate_compare_func(depth
->Func
);
1124 if (stencil
->_Enabled
) {
1125 wmds
.StencilTestEnable
= true;
1126 wmds
.StencilWriteMask
= stencil
->WriteMask
[0] & 0xff;
1127 wmds
.StencilTestMask
= stencil
->ValueMask
[0] & 0xff;
1129 wmds
.StencilTestFunction
=
1130 intel_translate_compare_func(stencil
->Function
[0]);
1131 wmds
.StencilFailOp
=
1132 intel_translate_stencil_op(stencil
->FailFunc
[0]);
1133 wmds
.StencilPassDepthPassOp
=
1134 intel_translate_stencil_op(stencil
->ZPassFunc
[0]);
1135 wmds
.StencilPassDepthFailOp
=
1136 intel_translate_stencil_op(stencil
->ZFailFunc
[0]);
1138 wmds
.StencilBufferWriteEnable
= stencil
->_WriteEnabled
;
1140 if (stencil
->_TestTwoSide
) {
1141 wmds
.DoubleSidedStencilEnable
= true;
1142 wmds
.BackfaceStencilWriteMask
= stencil
->WriteMask
[b
] & 0xff;
1143 wmds
.BackfaceStencilTestMask
= stencil
->ValueMask
[b
] & 0xff;
1145 wmds
.BackfaceStencilTestFunction
=
1146 intel_translate_compare_func(stencil
->Function
[b
]);
1147 wmds
.BackfaceStencilFailOp
=
1148 intel_translate_stencil_op(stencil
->FailFunc
[b
]);
1149 wmds
.BackfaceStencilPassDepthPassOp
=
1150 intel_translate_stencil_op(stencil
->ZPassFunc
[b
]);
1151 wmds
.BackfaceStencilPassDepthFailOp
=
1152 intel_translate_stencil_op(stencil
->ZFailFunc
[b
]);
1156 wmds
.StencilReferenceValue
= _mesa_get_stencil_ref(ctx
, 0);
1157 wmds
.BackfaceStencilReferenceValue
= _mesa_get_stencil_ref(ctx
, b
);
1163 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
1164 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
1165 ptr
.DEPTH_STENCIL_STATEChange
= true;
1168 brw_batch_emit(brw
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), ptr
) {
1169 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
1174 static const struct brw_tracked_state
genX(depth_stencil_state
) = {
1176 .mesa
= _NEW_BUFFERS
|
1179 .brw
= BRW_NEW_BLORP
|
1180 (GEN_GEN
>= 8 ? BRW_NEW_CONTEXT
1182 BRW_NEW_STATE_BASE_ADDRESS
),
1184 .emit
= genX(upload_depth_stencil_state
),
1188 /* ---------------------------------------------------------------------- */
1192 genX(upload_clip_state
)(struct brw_context
*brw
)
1194 struct gl_context
*ctx
= &brw
->ctx
;
1197 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1199 /* BRW_NEW_FS_PROG_DATA */
1200 struct brw_wm_prog_data
*wm_prog_data
=
1201 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1203 brw_batch_emit(brw
, GENX(3DSTATE_CLIP
), clip
) {
1204 clip
.StatisticsEnable
= !brw
->meta_in_progress
;
1206 if (wm_prog_data
->barycentric_interp_modes
&
1207 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
1208 clip
.NonPerspectiveBarycentricEnable
= true;
1211 clip
.EarlyCullEnable
= true;
1215 clip
.FrontWinding
= ctx
->Polygon
._FrontBit
== _mesa_is_user_fbo(fb
);
1217 if (ctx
->Polygon
.CullFlag
) {
1218 switch (ctx
->Polygon
.CullFaceMode
) {
1220 clip
.CullMode
= CULLMODE_FRONT
;
1223 clip
.CullMode
= CULLMODE_BACK
;
1225 case GL_FRONT_AND_BACK
:
1226 clip
.CullMode
= CULLMODE_BOTH
;
1229 unreachable("Should not get here: invalid CullFlag");
1232 clip
.CullMode
= CULLMODE_NONE
;
1237 clip
.UserClipDistanceCullTestEnableBitmask
=
1238 brw_vue_prog_data(brw
->vs
.base
.prog_data
)->cull_distance_mask
;
1240 clip
.ViewportZClipTestEnable
= !ctx
->Transform
.DepthClamp
;
1244 if (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
) {
1245 clip
.TriangleStripListProvokingVertexSelect
= 0;
1246 clip
.TriangleFanProvokingVertexSelect
= 1;
1247 clip
.LineStripListProvokingVertexSelect
= 0;
1249 clip
.TriangleStripListProvokingVertexSelect
= 2;
1250 clip
.TriangleFanProvokingVertexSelect
= 2;
1251 clip
.LineStripListProvokingVertexSelect
= 1;
1254 /* _NEW_TRANSFORM */
1255 clip
.UserClipDistanceClipTestEnableBitmask
=
1256 ctx
->Transform
.ClipPlanesEnabled
;
1259 clip
.ForceUserClipDistanceClipTestEnableBitmask
= true;
1262 if (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
)
1263 clip
.APIMode
= APIMODE_D3D
;
1265 clip
.APIMode
= APIMODE_OGL
;
1267 clip
.GuardbandClipTestEnable
= true;
1269 /* BRW_NEW_VIEWPORT_COUNT */
1270 const unsigned viewport_count
= brw
->clip
.viewport_count
;
1272 if (ctx
->RasterDiscard
) {
1273 clip
.ClipMode
= CLIPMODE_REJECT_ALL
;
1275 perf_debug("Rasterizer discard is currently implemented via the "
1276 "clipper; having the GS not write primitives would "
1277 "likely be faster.\n");
1280 clip
.ClipMode
= CLIPMODE_NORMAL
;
1283 clip
.ClipEnable
= brw
->primitive
!= _3DPRIM_RECTLIST
;
1286 * BRW_NEW_GEOMETRY_PROGRAM | BRW_NEW_TES_PROG_DATA | BRW_NEW_PRIMITIVE
1288 if (!brw_is_drawing_points(brw
) && !brw_is_drawing_lines(brw
))
1289 clip
.ViewportXYClipTestEnable
= true;
1291 clip
.MinimumPointWidth
= 0.125;
1292 clip
.MaximumPointWidth
= 255.875;
1293 clip
.MaximumVPIndex
= viewport_count
- 1;
1294 if (_mesa_geometric_layers(fb
) == 0)
1295 clip
.ForceZeroRTAIndexEnable
= true;
1299 static const struct brw_tracked_state
genX(clip_state
) = {
1301 .mesa
= _NEW_BUFFERS
|
1305 .brw
= BRW_NEW_BLORP
|
1307 BRW_NEW_FS_PROG_DATA
|
1308 BRW_NEW_GS_PROG_DATA
|
1309 BRW_NEW_VS_PROG_DATA
|
1310 BRW_NEW_META_IN_PROGRESS
|
1312 BRW_NEW_RASTERIZER_DISCARD
|
1313 BRW_NEW_TES_PROG_DATA
|
1314 BRW_NEW_VIEWPORT_COUNT
,
1316 .emit
= genX(upload_clip_state
),
1320 /* ---------------------------------------------------------------------- */
1324 genX(upload_sf
)(struct brw_context
*brw
)
1326 struct gl_context
*ctx
= &brw
->ctx
;
1331 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
1332 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
1335 brw_batch_emit(brw
, GENX(3DSTATE_SF
), sf
) {
1336 sf
.StatisticsEnable
= true;
1337 sf
.ViewportTransformEnable
= brw
->sf
.viewport_transform_enable
;
1341 sf
.DepthBufferSurfaceFormat
= brw_depthbuffer_format(brw
);
1346 sf
.FrontWinding
= ctx
->Polygon
._FrontBit
== render_to_fbo
;
1347 sf
.GlobalDepthOffsetEnableSolid
= ctx
->Polygon
.OffsetFill
;
1348 sf
.GlobalDepthOffsetEnableWireframe
= ctx
->Polygon
.OffsetLine
;
1349 sf
.GlobalDepthOffsetEnablePoint
= ctx
->Polygon
.OffsetPoint
;
1351 switch (ctx
->Polygon
.FrontMode
) {
1353 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
1356 sf
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
1359 sf
.FrontFaceFillMode
= FILL_MODE_POINT
;
1362 unreachable("not reached");
1365 switch (ctx
->Polygon
.BackMode
) {
1367 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
1370 sf
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
1373 sf
.BackFaceFillMode
= FILL_MODE_POINT
;
1376 unreachable("not reached");
1379 sf
.ScissorRectangleEnable
= true;
1381 if (ctx
->Polygon
.CullFlag
) {
1382 switch (ctx
->Polygon
.CullFaceMode
) {
1384 sf
.CullMode
= CULLMODE_FRONT
;
1387 sf
.CullMode
= CULLMODE_BACK
;
1389 case GL_FRONT_AND_BACK
:
1390 sf
.CullMode
= CULLMODE_BOTH
;
1393 unreachable("not reached");
1396 sf
.CullMode
= CULLMODE_NONE
;
1400 sf
.LineStippleEnable
= ctx
->Line
.StippleFlag
;
1403 if (multisampled_fbo
&& ctx
->Multisample
.Enabled
)
1404 sf
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1406 sf
.GlobalDepthOffsetConstant
= ctx
->Polygon
.OffsetUnits
* 2;
1407 sf
.GlobalDepthOffsetScale
= ctx
->Polygon
.OffsetFactor
;
1408 sf
.GlobalDepthOffsetClamp
= ctx
->Polygon
.OffsetClamp
;
1413 if (brw
->is_cherryview
)
1414 sf
.CHVLineWidth
= brw_get_line_width(brw
);
1416 sf
.LineWidth
= brw_get_line_width(brw
);
1418 sf
.LineWidth
= brw_get_line_width(brw
);
1421 if (ctx
->Line
.SmoothFlag
) {
1422 sf
.LineEndCapAntialiasingRegionWidth
= _10pixels
;
1424 sf
.AntiAliasingEnable
= true;
1428 /* _NEW_POINT - Clamp to ARB_point_parameters user limits */
1429 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
1430 /* Clamp to the hardware limits */
1431 sf
.PointWidth
= CLAMP(point_size
, 0.125f
, 255.875f
);
1433 /* _NEW_PROGRAM | _NEW_POINT, BRW_NEW_VUE_MAP_GEOM_OUT */
1434 if (use_state_point_size(brw
))
1435 sf
.PointWidthSource
= State
;
1438 /* _NEW_POINT | _NEW_MULTISAMPLE */
1439 if ((ctx
->Point
.SmoothFlag
|| _mesa_is_multisample_enabled(ctx
)) &&
1440 !ctx
->Point
.PointSprite
)
1441 sf
.SmoothPointEnable
= true;
1444 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
1447 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
1448 sf
.TriangleStripListProvokingVertexSelect
= 2;
1449 sf
.TriangleFanProvokingVertexSelect
= 2;
1450 sf
.LineStripListProvokingVertexSelect
= 1;
1452 sf
.TriangleFanProvokingVertexSelect
= 1;
1456 /* BRW_NEW_FS_PROG_DATA */
1457 const struct brw_wm_prog_data
*wm_prog_data
=
1458 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1460 sf
.AttributeSwizzleEnable
= true;
1461 sf
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
1464 * Window coordinates in an FBO are inverted, which means point
1465 * sprite origin must be inverted, too.
1467 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
) {
1468 sf
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
1470 sf
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
1473 /* BRW_NEW_VUE_MAP_GEOM_OUT | BRW_NEW_FRAGMENT_PROGRAM |
1474 * _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM | BRW_NEW_FS_PROG_DATA
1476 uint32_t urb_entry_read_length
;
1477 uint32_t urb_entry_read_offset
;
1478 uint32_t point_sprite_enables
;
1479 genX(calculate_attr_overrides
)(brw
, sf
.Attribute
, &point_sprite_enables
,
1480 &urb_entry_read_length
,
1481 &urb_entry_read_offset
);
1482 sf
.VertexURBEntryReadLength
= urb_entry_read_length
;
1483 sf
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
1484 sf
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
1485 sf
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
1490 static const struct brw_tracked_state
genX(sf_state
) = {
1492 .mesa
= _NEW_LIGHT
|
1497 (GEN_GEN
<= 7 ? _NEW_BUFFERS
| _NEW_POLYGON
: 0),
1498 .brw
= BRW_NEW_BLORP
|
1500 BRW_NEW_VUE_MAP_GEOM_OUT
|
1501 (GEN_GEN
<= 7 ? BRW_NEW_GS_PROG_DATA
|
1503 BRW_NEW_TES_PROG_DATA
1505 (GEN_GEN
== 6 ? BRW_NEW_FS_PROG_DATA
|
1506 BRW_NEW_FRAGMENT_PROGRAM
1509 .emit
= genX(upload_sf
),
1513 /* ---------------------------------------------------------------------- */
1517 genX(upload_wm
)(struct brw_context
*brw
)
1519 struct gl_context
*ctx
= &brw
->ctx
;
1521 /* BRW_NEW_FS_PROG_DATA */
1522 const struct brw_wm_prog_data
*wm_prog_data
=
1523 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1525 UNUSED
bool writes_depth
=
1526 wm_prog_data
->computed_depth_mode
!= BRW_PSCDEPTH_OFF
;
1529 const struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
1530 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1532 /* We can't fold this into gen6_upload_wm_push_constants(), because
1533 * according to the SNB PRM, vol 2 part 1 section 7.2.2
1534 * (3DSTATE_CONSTANT_PS [DevSNB]):
1536 * "[DevSNB]: This packet must be followed by WM_STATE."
1538 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_PS
), wmcp
) {
1539 if (wm_prog_data
->base
.nr_params
!= 0) {
1540 wmcp
.Buffer0Valid
= true;
1541 /* Pointer to the WM constant buffer. Covered by the set of
1542 * state flags from gen6_upload_wm_push_constants.
1544 wmcp
.PointertoPSConstantBuffer0
= stage_state
->push_const_offset
;
1545 wmcp
.PSConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
1550 brw_batch_emit(brw
, GENX(3DSTATE_WM
), wm
) {
1551 wm
.StatisticsEnable
= true;
1552 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1553 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1556 if (wm_prog_data
->base
.use_alt_mode
)
1557 wm
.FloatingPointMode
= Alternate
;
1559 wm
.SamplerCount
= DIV_ROUND_UP(stage_state
->sampler_count
, 4);
1560 wm
.BindingTableEntryCount
= wm_prog_data
->base
.binding_table
.size_bytes
/ 4;
1561 wm
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1562 wm
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
1563 wm
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
1564 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
1565 wm_prog_data
->base
.dispatch_grf_start_reg
;
1566 wm
.DispatchGRFStartRegisterForConstantSetupData2
=
1567 wm_prog_data
->dispatch_grf_start_reg_2
;
1568 wm
.KernelStartPointer0
= stage_state
->prog_offset
;
1569 wm
.KernelStartPointer2
= stage_state
->prog_offset
+
1570 wm_prog_data
->prog_offset_2
;
1571 wm
.DualSourceBlendEnable
=
1572 wm_prog_data
->dual_src_blend
&& (ctx
->Color
.BlendEnabled
& 1) &&
1573 ctx
->Color
.Blend
[0]._UsesDualSrc
;
1574 wm
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1575 wm
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
1577 /* From the SNB PRM, volume 2 part 1, page 281:
1578 * "If the PS kernel does not need the Position XY Offsets
1579 * to compute a Position XY value, then this field should be
1580 * programmed to POSOFFSET_NONE."
1582 * "SW Recommendation: If the PS kernel needs the Position Offsets
1583 * to compute a Position XY value, this field should match Position
1584 * ZW Interpolation Mode to ensure a consistent position.xyzw
1586 * We only require XY sample offsets. So, this recommendation doesn't
1587 * look useful at the moment. We might need this in future.
1589 if (wm_prog_data
->uses_pos_offset
)
1590 wm
.PositionXYOffsetSelect
= POSOFFSET_SAMPLE
;
1592 wm
.PositionXYOffsetSelect
= POSOFFSET_NONE
;
1594 if (wm_prog_data
->base
.total_scratch
) {
1595 wm
.ScratchSpaceBasePointer
=
1596 render_bo(stage_state
->scratch_bo
,
1597 ffs(stage_state
->per_thread_scratch
) - 11);
1600 wm
.PixelShaderComputedDepth
= writes_depth
;
1603 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1606 wm
.LineStippleEnable
= ctx
->Line
.StippleFlag
;
1609 wm
.PolygonStippleEnable
= ctx
->Polygon
.StippleFlag
;
1610 wm
.BarycentricInterpolationMode
= wm_prog_data
->barycentric_interp_modes
;
1614 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
1616 wm
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1617 wm
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1618 if (wm_prog_data
->uses_kill
||
1619 _mesa_is_alpha_test_enabled(ctx
) ||
1620 _mesa_is_alpha_to_coverage_enabled(ctx
) ||
1621 wm_prog_data
->uses_omask
) {
1622 wm
.PixelShaderKillsPixel
= true;
1625 /* _NEW_BUFFERS | _NEW_COLOR */
1626 if (brw_color_buffer_write_enabled(brw
) || writes_depth
||
1627 wm_prog_data
->has_side_effects
|| wm
.PixelShaderKillsPixel
) {
1628 wm
.ThreadDispatchEnable
= true;
1630 if (multisampled_fbo
) {
1631 /* _NEW_MULTISAMPLE */
1632 if (ctx
->Multisample
.Enabled
)
1633 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1635 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
1637 if (wm_prog_data
->persample_dispatch
)
1638 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1640 wm
.MultisampleDispatchMode
= MSDISPMODE_PERPIXEL
;
1642 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
1643 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1647 wm
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1648 wm
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1651 /* The "UAV access enable" bits are unnecessary on HSW because they only
1652 * seem to have an effect on the HW-assisted coherency mechanism which we
1653 * don't need, and the rasterization-related UAV_ONLY flag and the
1654 * DISPATCH_ENABLE bit can be set independently from it.
1655 * C.f. gen8_upload_ps_extra().
1657 * BRW_NEW_FRAGMENT_PROGRAM | BRW_NEW_FS_PROG_DATA | _NEW_BUFFERS |
1661 if (!(brw_color_buffer_write_enabled(brw
) || writes_depth
) &&
1662 wm_prog_data
->has_side_effects
)
1668 /* BRW_NEW_FS_PROG_DATA */
1669 if (wm_prog_data
->early_fragment_tests
)
1670 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
1671 else if (wm_prog_data
->has_side_effects
)
1672 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
1677 static const struct brw_tracked_state
genX(wm_state
) = {
1681 (GEN_GEN
< 8 ? _NEW_BUFFERS
|
1685 (GEN_GEN
< 7 ? _NEW_PROGRAM_CONSTANTS
: 0),
1686 .brw
= BRW_NEW_BLORP
|
1687 BRW_NEW_FS_PROG_DATA
|
1688 (GEN_GEN
< 7 ? BRW_NEW_BATCH
: BRW_NEW_CONTEXT
),
1690 .emit
= genX(upload_wm
),
1694 /* ---------------------------------------------------------------------- */
1696 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix) \
1697 pkt.KernelStartPointer = stage_state->prog_offset; \
1698 pkt.SamplerCount = \
1699 DIV_ROUND_UP(CLAMP(stage_state->sampler_count, 0, 16), 4); \
1700 pkt.BindingTableEntryCount = \
1701 stage_prog_data->binding_table.size_bytes / 4; \
1702 pkt.FloatingPointMode = stage_prog_data->use_alt_mode; \
1704 if (stage_prog_data->total_scratch) { \
1705 pkt.ScratchSpaceBasePointer = \
1706 render_bo(stage_state->scratch_bo, 0); \
1707 pkt.PerThreadScratchSpace = \
1708 ffs(stage_state->per_thread_scratch) - 11; \
1711 pkt.DispatchGRFStartRegisterForURBData = \
1712 stage_prog_data->dispatch_grf_start_reg; \
1713 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
1714 pkt.prefix##URBEntryReadOffset = 0; \
1716 pkt.StatisticsEnable = true; \
1721 genX(upload_vs_state
)(struct brw_context
*brw
)
1723 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1724 const struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
1726 /* BRW_NEW_VS_PROG_DATA */
1727 const struct brw_vue_prog_data
*vue_prog_data
=
1728 brw_vue_prog_data(brw
->vs
.base
.prog_data
);
1729 const struct brw_stage_prog_data
*stage_prog_data
= &vue_prog_data
->base
;
1731 assert(vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
||
1732 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_4X2_DUAL_OBJECT
);
1735 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
1736 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
1738 * [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
1739 * command that causes the VS Function Enable to toggle. Pipeline
1740 * flush can be executed by sending a PIPE_CONTROL command with CS
1741 * stall bit set and a post sync operation.
1743 * We've already done such a flush at the start of state upload, so we
1744 * don't need to do another one here.
1746 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_VS
), cvs
) {
1747 if (stage_state
->push_const_size
!= 0) {
1748 cvs
.Buffer0Valid
= true;
1749 cvs
.PointertoVSConstantBuffer0
= stage_state
->push_const_offset
;
1750 cvs
.VSConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
1755 if (GEN_GEN
== 7 && devinfo
->is_ivybridge
)
1756 gen7_emit_vs_workaround_flush(brw
);
1758 brw_batch_emit(brw
, GENX(3DSTATE_VS
), vs
) {
1759 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
);
1761 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
1764 vs
.SIMD8DispatchEnable
=
1765 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
;
1767 vs
.UserClipDistanceCullTestEnableBitmask
=
1768 vue_prog_data
->cull_distance_mask
;
1773 /* Based on my reading of the simulator, the VS constants don't get
1774 * pulled into the VS FF unit until an appropriate pipeline flush
1775 * happens, and instead the 3DSTATE_CONSTANT_VS packet just adds
1776 * references to them into a little FIFO. The flushes are common,
1777 * but don't reliably happen between this and a 3DPRIMITIVE, causing
1778 * the primitive to use the wrong constants. Then the FIFO
1779 * containing the constant setup gets added to again on the next
1780 * constants change, and eventually when a flush does happen the
1781 * unit is overwhelmed by constant changes and dies.
1783 * To avoid this, send a PIPE_CONTROL down the line that will
1784 * update the unit immediately loading the constants. The flush
1785 * type bits here were those set by the STATE_BASE_ADDRESS whose
1786 * move in a82a43e8d99e1715dd11c9c091b5ab734079b6a6 triggered the
1787 * bug reports that led to this workaround, and may be more than
1788 * what is strictly required to avoid the issue.
1790 brw_emit_pipe_control_flush(brw
,
1791 PIPE_CONTROL_DEPTH_STALL
|
1792 PIPE_CONTROL_INSTRUCTION_INVALIDATE
|
1793 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
1797 static const struct brw_tracked_state
genX(vs_state
) = {
1799 .mesa
= (GEN_GEN
== 6 ? (_NEW_PROGRAM_CONSTANTS
| _NEW_TRANSFORM
) : 0),
1800 .brw
= BRW_NEW_BATCH
|
1803 BRW_NEW_VS_PROG_DATA
|
1804 (GEN_GEN
== 6 ? BRW_NEW_VERTEX_PROGRAM
: 0),
1806 .emit
= genX(upload_vs_state
),
1810 /* ---------------------------------------------------------------------- */
1814 brw_calculate_guardband_size(const struct gen_device_info
*devinfo
,
1815 uint32_t fb_width
, uint32_t fb_height
,
1816 float m00
, float m11
, float m30
, float m31
,
1817 float *xmin
, float *xmax
,
1818 float *ymin
, float *ymax
)
1820 /* According to the "Vertex X,Y Clamping and Quantization" section of the
1821 * Strips and Fans documentation:
1823 * "The vertex X and Y screen-space coordinates are also /clamped/ to the
1824 * fixed-point "guardband" range supported by the rasterization hardware"
1828 * "In almost all circumstances, if an object’s vertices are actually
1829 * modified by this clamping (i.e., had X or Y coordinates outside of
1830 * the guardband extent the rendered object will not match the intended
1831 * result. Therefore software should take steps to ensure that this does
1832 * not happen - e.g., by clipping objects such that they do not exceed
1833 * these limits after the Drawing Rectangle is applied."
1835 * I believe the fundamental restriction is that the rasterizer (in
1836 * the SF/WM stages) have a limit on the number of pixels that can be
1837 * rasterized. We need to ensure any coordinates beyond the rasterizer
1838 * limit are handled by the clipper. So effectively that limit becomes
1839 * the clipper's guardband size.
1841 * It goes on to say:
1843 * "In addition, in order to be correctly rendered, objects must have a
1844 * screenspace bounding box not exceeding 8K in the X or Y direction.
1845 * This additional restriction must also be comprehended by software,
1846 * i.e., enforced by use of clipping."
1848 * This makes no sense. Gen7+ hardware supports 16K render targets,
1849 * and you definitely need to be able to draw polygons that fill the
1850 * surface. Our assumption is that the rasterizer was limited to 8K
1851 * on Sandybridge, which only supports 8K surfaces, and it was actually
1852 * increased to 16K on Ivybridge and later.
1854 * So, limit the guardband to 16K on Gen7+ and 8K on Sandybridge.
1856 const float gb_size
= devinfo
->gen
>= 7 ? 16384.0f
: 8192.0f
;
1858 if (m00
!= 0 && m11
!= 0) {
1859 /* First, we compute the screen-space render area */
1860 const float ss_ra_xmin
= MIN3( 0, m30
+ m00
, m30
- m00
);
1861 const float ss_ra_xmax
= MAX3( fb_width
, m30
+ m00
, m30
- m00
);
1862 const float ss_ra_ymin
= MIN3( 0, m31
+ m11
, m31
- m11
);
1863 const float ss_ra_ymax
= MAX3(fb_height
, m31
+ m11
, m31
- m11
);
1865 /* We want the guardband to be centered on that */
1866 const float ss_gb_xmin
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 - gb_size
;
1867 const float ss_gb_xmax
= (ss_ra_xmin
+ ss_ra_xmax
) / 2 + gb_size
;
1868 const float ss_gb_ymin
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 - gb_size
;
1869 const float ss_gb_ymax
= (ss_ra_ymin
+ ss_ra_ymax
) / 2 + gb_size
;
1871 /* Now we need it in native device coordinates */
1872 const float ndc_gb_xmin
= (ss_gb_xmin
- m30
) / m00
;
1873 const float ndc_gb_xmax
= (ss_gb_xmax
- m30
) / m00
;
1874 const float ndc_gb_ymin
= (ss_gb_ymin
- m31
) / m11
;
1875 const float ndc_gb_ymax
= (ss_gb_ymax
- m31
) / m11
;
1877 /* Thanks to Y-flipping and ORIGIN_UPPER_LEFT, the Y coordinates may be
1878 * flipped upside-down. X should be fine though.
1880 assert(ndc_gb_xmin
<= ndc_gb_xmax
);
1881 *xmin
= ndc_gb_xmin
;
1882 *xmax
= ndc_gb_xmax
;
1883 *ymin
= MIN2(ndc_gb_ymin
, ndc_gb_ymax
);
1884 *ymax
= MAX2(ndc_gb_ymin
, ndc_gb_ymax
);
1886 /* The viewport scales to 0, so nothing will be rendered. */
1895 genX(upload_sf_clip_viewport
)(struct brw_context
*brw
)
1897 struct gl_context
*ctx
= &brw
->ctx
;
1898 float y_scale
, y_bias
;
1899 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1901 /* BRW_NEW_VIEWPORT_COUNT */
1902 const unsigned viewport_count
= brw
->clip
.viewport_count
;
1905 const bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
1906 const uint32_t fb_width
= (float)_mesa_geometric_width(ctx
->DrawBuffer
);
1907 const uint32_t fb_height
= (float)_mesa_geometric_height(ctx
->DrawBuffer
);
1911 struct GENX(SF_CLIP_VIEWPORT
) sfv
;
1912 uint32_t sf_clip_vp_offset
;
1913 uint32_t *sf_clip_map
= brw_state_batch(brw
, 16 * 4 * viewport_count
,
1914 64, &sf_clip_vp_offset
);
1916 struct GENX(SF_VIEWPORT
) sfv
;
1917 struct GENX(CLIP_VIEWPORT
) clv
;
1918 uint32_t *sf_map
= brw_state_batch(brw
, 8 * 4 * viewport_count
,
1919 32, &brw
->sf
.vp_offset
);
1920 uint32_t *clip_map
= brw_state_batch(brw
, 4 * 4 * viewport_count
,
1921 32, &brw
->clip
.vp_offset
);
1925 if (render_to_fbo
) {
1930 y_bias
= (float)fb_height
;
1933 for (unsigned i
= 0; i
< brw
->clip
.viewport_count
; i
++) {
1934 /* _NEW_VIEWPORT: Guardband Clipping */
1935 float scale
[3], translate
[3], gb_xmin
, gb_xmax
, gb_ymin
, gb_ymax
;
1936 _mesa_get_viewport_xform(ctx
, i
, scale
, translate
);
1938 sfv
.ViewportMatrixElementm00
= scale
[0];
1939 sfv
.ViewportMatrixElementm11
= scale
[1] * y_scale
,
1940 sfv
.ViewportMatrixElementm22
= scale
[2],
1941 sfv
.ViewportMatrixElementm30
= translate
[0],
1942 sfv
.ViewportMatrixElementm31
= translate
[1] * y_scale
+ y_bias
,
1943 sfv
.ViewportMatrixElementm32
= translate
[2],
1944 brw_calculate_guardband_size(devinfo
, fb_width
, fb_height
,
1945 sfv
.ViewportMatrixElementm00
,
1946 sfv
.ViewportMatrixElementm11
,
1947 sfv
.ViewportMatrixElementm30
,
1948 sfv
.ViewportMatrixElementm31
,
1949 &gb_xmin
, &gb_xmax
, &gb_ymin
, &gb_ymax
);
1952 clv
.XMinClipGuardband
= gb_xmin
;
1953 clv
.XMaxClipGuardband
= gb_xmax
;
1954 clv
.YMinClipGuardband
= gb_ymin
;
1955 clv
.YMaxClipGuardband
= gb_ymax
;
1958 /* _NEW_VIEWPORT | _NEW_BUFFERS: Screen Space Viewport
1959 * The hardware will take the intersection of the drawing rectangle,
1960 * scissor rectangle, and the viewport extents. We don't need to be
1961 * smart, and can therefore just program the viewport extents.
1963 const float viewport_Xmax
=
1964 ctx
->ViewportArray
[i
].X
+ ctx
->ViewportArray
[i
].Width
;
1965 const float viewport_Ymax
=
1966 ctx
->ViewportArray
[i
].Y
+ ctx
->ViewportArray
[i
].Height
;
1968 if (render_to_fbo
) {
1969 sfv
.XMinViewPort
= ctx
->ViewportArray
[i
].X
;
1970 sfv
.XMaxViewPort
= viewport_Xmax
- 1;
1971 sfv
.YMinViewPort
= ctx
->ViewportArray
[i
].Y
;
1972 sfv
.YMaxViewPort
= viewport_Ymax
- 1;
1974 sfv
.XMinViewPort
= ctx
->ViewportArray
[i
].X
;
1975 sfv
.XMaxViewPort
= viewport_Xmax
- 1;
1976 sfv
.YMinViewPort
= fb_height
- viewport_Ymax
;
1977 sfv
.YMaxViewPort
= fb_height
- ctx
->ViewportArray
[i
].Y
- 1;
1982 GENX(SF_CLIP_VIEWPORT_pack
)(NULL
, sf_clip_map
, &sfv
);
1985 GENX(SF_VIEWPORT_pack
)(NULL
, sf_map
, &sfv
);
1986 GENX(CLIP_VIEWPORT_pack
)(NULL
, clip_map
, &clv
);
1993 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
1994 ptr
.SFClipViewportPointer
= sf_clip_vp_offset
;
1997 brw
->ctx
.NewDriverState
|= BRW_NEW_SF_VP
| BRW_NEW_CLIP_VP
;
2001 static const struct brw_tracked_state
genX(sf_clip_viewport
) = {
2003 .mesa
= _NEW_BUFFERS
|
2005 .brw
= BRW_NEW_BATCH
|
2007 BRW_NEW_VIEWPORT_COUNT
,
2009 .emit
= genX(upload_sf_clip_viewport
),
2013 /* ---------------------------------------------------------------------- */
2017 genX(upload_gs_state
)(struct brw_context
*brw
)
2019 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
2020 const struct brw_stage_state
*stage_state
= &brw
->gs
.base
;
2021 /* BRW_NEW_GEOMETRY_PROGRAM */
2022 bool active
= brw
->geometry_program
;
2024 /* BRW_NEW_GS_PROG_DATA */
2025 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
2026 const struct brw_vue_prog_data
*vue_prog_data
=
2027 brw_vue_prog_data(stage_prog_data
);
2029 const struct brw_gs_prog_data
*gs_prog_data
=
2030 brw_gs_prog_data(stage_prog_data
);
2034 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_GS
), cgs
) {
2035 if (active
&& stage_state
->push_const_size
!= 0) {
2036 cgs
.Buffer0Valid
= true;
2037 cgs
.PointertoGSConstantBuffer0
= stage_state
->push_const_offset
;
2038 cgs
.GSConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
2043 #if GEN_GEN == 7 && !GEN_IS_HASWELL
2045 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
2046 * Geometry > Geometry Shader > State:
2048 * "Note: Because of corruption in IVB:GT2, software needs to flush the
2049 * whole fixed function pipeline when the GS enable changes value in
2052 * The hardware architects have clarified that in this context "flush the
2053 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
2056 if (brw
->gt
== 2 && brw
->gs
.enabled
!= active
)
2057 gen7_emit_cs_stall_flush(brw
);
2061 brw_batch_emit(brw
, GENX(3DSTATE_GS
), gs
) {
2062 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
);
2065 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
2066 gs
.OutputTopology
= gs_prog_data
->output_topology
;
2067 gs
.ControlDataHeaderSize
=
2068 gs_prog_data
->control_data_header_size_hwords
;
2070 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
2071 gs
.DispatchMode
= vue_prog_data
->dispatch_mode
;
2073 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
2075 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
2078 /* Note: the meaning of the GEN7_GS_REORDER_TRAILING bit changes between
2079 * Ivy Bridge and Haswell.
2081 * On Ivy Bridge, setting this bit causes the vertices of a triangle
2082 * strip to be delivered to the geometry shader in an order that does
2083 * not strictly follow the OpenGL spec, but preserves triangle
2084 * orientation. For example, if the vertices are (1, 2, 3, 4, 5), then
2085 * the geometry shader sees triangles:
2087 * (1, 2, 3), (2, 4, 3), (3, 4, 5)
2089 * (Clearing the bit is even worse, because it fails to preserve
2092 * Triangle strips with adjacency always ordered in a way that preserves
2093 * triangle orientation but does not strictly follow the OpenGL spec,
2094 * regardless of the setting of this bit.
2096 * On Haswell, both triangle strips and triangle strips with adjacency
2097 * are always ordered in a way that preserves triangle orientation.
2098 * Setting this bit causes the ordering to strictly follow the OpenGL
2101 * So in either case we want to set the bit. Unfortunately on Ivy
2102 * Bridge this will get the order close to correct but not perfect.
2104 gs
.ReorderMode
= TRAILING
;
2105 gs
.MaximumNumberofThreads
=
2106 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
2107 : (devinfo
->max_gs_threads
- 1);
2110 gs
.SOStatisticsEnable
= true;
2111 gs
.RenderingEnabled
= 1;
2112 if (brw
->geometry_program
->info
.has_transform_feedback_varyings
)
2113 gs
.SVBIPayloadEnable
= true;
2115 /* GEN6_GS_SPF_MODE and GEN6_GS_VECTOR_MASK_ENABLE are enabled as it
2116 * was previously done for gen6.
2118 * TODO: test with both disabled to see if the HW is behaving
2119 * as expected, like in gen7.
2121 gs
.SingleProgramFlow
= true;
2122 gs
.VectorMaskEnable
= true;
2126 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
2128 if (gs_prog_data
->static_vertex_count
!= -1) {
2129 gs
.StaticOutput
= true;
2130 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
2132 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
2134 gs
.UserClipDistanceCullTestEnableBitmask
=
2135 vue_prog_data
->cull_distance_mask
;
2137 const int urb_entry_write_offset
= 1;
2138 const uint32_t urb_entry_output_length
=
2139 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
2140 urb_entry_write_offset
;
2142 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
2143 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
2147 } else if (brw
->ff_gs
.prog_active
) {
2148 /* In gen6, transform feedback for the VS stage is done with an ad-hoc GS
2149 * program. This function provides the needed 3DSTATE_GS for this.
2151 upload_gs_state_for_tf(brw
);
2154 brw_batch_emit(brw
, GENX(3DSTATE_GS
), gs
) {
2155 gs
.StatisticsEnable
= true;
2157 gs
.RenderingEnabled
= true;
2161 gs
.DispatchGRFStartRegisterForURBData
= 1;
2163 gs
.IncludeVertexHandles
= true;
2169 brw
->gs
.enabled
= active
;
2173 static const struct brw_tracked_state
genX(gs_state
) = {
2175 .mesa
= (GEN_GEN
< 7 ? _NEW_PROGRAM_CONSTANTS
: 0),
2176 .brw
= BRW_NEW_BATCH
|
2179 BRW_NEW_GEOMETRY_PROGRAM
|
2180 BRW_NEW_GS_PROG_DATA
|
2181 (GEN_GEN
< 7 ? BRW_NEW_FF_GS_PROG_DATA
: 0),
2183 .emit
= genX(upload_gs_state
),
2187 /* ---------------------------------------------------------------------- */
2189 #define blend_factor(x) brw_translate_blend_factor(x)
2190 #define blend_eqn(x) brw_translate_blend_equation(x)
2194 genX(upload_blend_state
)(struct brw_context
*brw
)
2196 struct gl_context
*ctx
= &brw
->ctx
;
2199 /* We need at least one BLEND_STATE written, because we might do
2200 * thread dispatch even if _NumColorDrawBuffers is 0 (for example
2201 * for computed depth or alpha test), which will do an FB write
2202 * with render target 0, which will reference BLEND_STATE[0] for
2203 * alpha test enable.
2205 int nr_draw_buffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
2206 if (nr_draw_buffers
== 0 && ctx
->Color
.AlphaEnabled
)
2207 nr_draw_buffers
= 1;
2209 size
= GENX(BLEND_STATE_ENTRY_length
) * 4 * nr_draw_buffers
;
2211 size
+= GENX(BLEND_STATE_length
) * 4;
2214 uint32_t *blend_map
;
2215 blend_map
= brw_state_batch(brw
, size
, 64, &brw
->cc
.blend_state_offset
);
2218 struct GENX(BLEND_STATE
) blend
= { 0 };
2221 for (int i
= 0; i
< nr_draw_buffers
; i
++) {
2222 struct GENX(BLEND_STATE_ENTRY
) entry
= { 0 };
2225 /* OpenGL specification 3.3 (page 196), section 4.1.3 says:
2226 * "If drawbuffer zero is not NONE and the buffer it references has an
2227 * integer format, the SAMPLE_ALPHA_TO_COVERAGE and SAMPLE_ALPHA_TO_ONE
2228 * operations are skipped."
2230 if (!(ctx
->DrawBuffer
->_IntegerBuffers
& 0x1)) {
2231 /* _NEW_MULTISAMPLE */
2232 if (_mesa_is_multisample_enabled(ctx
)) {
2233 if (ctx
->Multisample
.SampleAlphaToCoverage
) {
2234 blend
.AlphaToCoverageEnable
= true;
2235 blend
.AlphaToCoverageDitherEnable
= GEN_GEN
>= 7;
2237 if (ctx
->Multisample
.SampleAlphaToOne
)
2238 blend
.AlphaToOneEnable
= true;
2242 if (ctx
->Color
.AlphaEnabled
) {
2243 blend
.AlphaTestEnable
= true;
2244 blend
.AlphaTestFunction
=
2245 intel_translate_compare_func(ctx
->Color
.AlphaFunc
);
2248 if (ctx
->Color
.DitherFlag
) {
2249 blend
.ColorDitherEnable
= true;
2254 for (int i
= 0; i
< nr_draw_buffers
; i
++) {
2255 struct GENX(BLEND_STATE_ENTRY
) entry
= { 0 };
2261 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
2263 /* Used for implementing the following bit of GL_EXT_texture_integer:
2264 * "Per-fragment operations that require floating-point color
2265 * components, including multisample alpha operations, alpha test,
2266 * blending, and dithering, have no effect when the corresponding
2267 * colors are written to an integer color buffer."
2269 bool integer
= ctx
->DrawBuffer
->_IntegerBuffers
& (0x1 << i
);
2272 if (ctx
->Color
.ColorLogicOpEnabled
) {
2273 GLenum rb_type
= rb
? _mesa_get_format_datatype(rb
->Format
)
2274 : GL_UNSIGNED_NORMALIZED
;
2275 WARN_ONCE(ctx
->Color
.LogicOp
!= GL_COPY
&&
2276 rb_type
!= GL_UNSIGNED_NORMALIZED
&&
2277 rb_type
!= GL_FLOAT
, "Ignoring %s logic op on %s "
2279 _mesa_enum_to_string(ctx
->Color
.LogicOp
),
2280 _mesa_enum_to_string(rb_type
));
2281 if (GEN_GEN
>= 8 || rb_type
== GL_UNSIGNED_NORMALIZED
) {
2282 entry
.LogicOpEnable
= true;
2283 entry
.LogicOpFunction
=
2284 intel_translate_logic_op(ctx
->Color
.LogicOp
);
2286 } else if (ctx
->Color
.BlendEnabled
& (1 << i
) && !integer
&&
2287 !ctx
->Color
._AdvancedBlendMode
) {
2288 GLenum eqRGB
= ctx
->Color
.Blend
[i
].EquationRGB
;
2289 GLenum eqA
= ctx
->Color
.Blend
[i
].EquationA
;
2290 GLenum srcRGB
= ctx
->Color
.Blend
[i
].SrcRGB
;
2291 GLenum dstRGB
= ctx
->Color
.Blend
[i
].DstRGB
;
2292 GLenum srcA
= ctx
->Color
.Blend
[i
].SrcA
;
2293 GLenum dstA
= ctx
->Color
.Blend
[i
].DstA
;
2295 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
)
2296 srcRGB
= dstRGB
= GL_ONE
;
2298 if (eqA
== GL_MIN
|| eqA
== GL_MAX
)
2299 srcA
= dstA
= GL_ONE
;
2301 /* Due to hardware limitations, the destination may have information
2302 * in an alpha channel even when the format specifies no alpha
2303 * channel. In order to avoid getting any incorrect blending due to
2304 * that alpha channel, coerce the blend factors to values that will
2305 * not read the alpha channel, but will instead use the correct
2306 * implicit value for alpha.
2308 if (rb
&& !_mesa_base_format_has_channel(rb
->_BaseFormat
,
2309 GL_TEXTURE_ALPHA_TYPE
)) {
2310 srcRGB
= brw_fix_xRGB_alpha(srcRGB
);
2311 srcA
= brw_fix_xRGB_alpha(srcA
);
2312 dstRGB
= brw_fix_xRGB_alpha(dstRGB
);
2313 dstA
= brw_fix_xRGB_alpha(dstA
);
2316 entry
.ColorBufferBlendEnable
= true;
2317 entry
.DestinationBlendFactor
= blend_factor(dstRGB
);
2318 entry
.SourceBlendFactor
= blend_factor(srcRGB
);
2319 entry
.DestinationAlphaBlendFactor
= blend_factor(dstA
);
2320 entry
.SourceAlphaBlendFactor
= blend_factor(srcA
);
2321 entry
.ColorBlendFunction
= blend_eqn(eqRGB
);
2322 entry
.AlphaBlendFunction
= blend_eqn(eqA
);
2324 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
)
2325 blend
.IndependentAlphaBlendEnable
= true;
2328 /* See section 8.1.6 "Pre-Blend Color Clamping" of the
2329 * SandyBridge PRM Volume 2 Part 1 for HW requirements.
2331 * We do our ARB_color_buffer_float CLAMP_FRAGMENT_COLOR
2332 * clamping in the fragment shader. For its clamping of
2333 * blending, the spec says:
2335 * "RESOLVED: For fixed-point color buffers, the inputs and
2336 * the result of the blending equation are clamped. For
2337 * floating-point color buffers, no clamping occurs."
2339 * So, generally, we want clamping to the render target's range.
2340 * And, good news, the hardware tables for both pre- and
2341 * post-blend color clamping are either ignored, or any are
2342 * allowed, or clamping is required but RT range clamping is a
2345 entry
.PreBlendColorClampEnable
= true;
2346 entry
.PostBlendColorClampEnable
= true;
2347 entry
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
2349 entry
.WriteDisableRed
= !ctx
->Color
.ColorMask
[i
][0];
2350 entry
.WriteDisableGreen
= !ctx
->Color
.ColorMask
[i
][1];
2351 entry
.WriteDisableBlue
= !ctx
->Color
.ColorMask
[i
][2];
2352 entry
.WriteDisableAlpha
= !ctx
->Color
.ColorMask
[i
][3];
2354 /* From the BLEND_STATE docs, DWord 0, Bit 29 (AlphaToOne Enable):
2355 * "If Dual Source Blending is enabled, this bit must be disabled."
2357 WARN_ONCE(ctx
->Color
.Blend
[i
]._UsesDualSrc
&&
2358 _mesa_is_multisample_enabled(ctx
) &&
2359 ctx
->Multisample
.SampleAlphaToOne
,
2360 "HW workaround: disabling alpha to one with dual src "
2362 if (ctx
->Color
.Blend
[i
]._UsesDualSrc
)
2363 blend
.AlphaToOneEnable
= false;
2365 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, &blend_map
[1 + i
* 2], &entry
);
2367 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, &blend_map
[i
* 2], &entry
);
2373 GENX(BLEND_STATE_pack
)(NULL
, blend_map
, &blend
);
2377 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
2378 ptr
.PointertoBLEND_STATE
= brw
->cc
.blend_state_offset
;
2379 ptr
.BLEND_STATEChange
= true;
2382 brw_batch_emit(brw
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
2383 ptr
.BlendStatePointer
= brw
->cc
.blend_state_offset
;
2385 ptr
.BlendStatePointerValid
= true;
2391 static const struct brw_tracked_state
genX(blend_state
) = {
2393 .mesa
= _NEW_BUFFERS
|
2396 .brw
= BRW_NEW_BATCH
|
2398 BRW_NEW_STATE_BASE_ADDRESS
,
2400 .emit
= genX(upload_blend_state
),
2404 /* ---------------------------------------------------------------------- */
2408 genX(upload_scissor_state
)(struct brw_context
*brw
)
2410 struct gl_context
*ctx
= &brw
->ctx
;
2411 const bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
2412 struct GENX(SCISSOR_RECT
) scissor
;
2413 uint32_t scissor_state_offset
;
2414 const unsigned int fb_width
= _mesa_geometric_width(ctx
->DrawBuffer
);
2415 const unsigned int fb_height
= _mesa_geometric_height(ctx
->DrawBuffer
);
2416 uint32_t *scissor_map
;
2418 /* BRW_NEW_VIEWPORT_COUNT */
2419 const unsigned viewport_count
= brw
->clip
.viewport_count
;
2421 scissor_map
= brw_state_batch(
2422 brw
, GENX(SCISSOR_RECT_length
) * sizeof(uint32_t) * viewport_count
,
2423 32, &scissor_state_offset
);
2425 /* _NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT */
2427 /* The scissor only needs to handle the intersection of drawable and
2428 * scissor rect. Clipping to the boundaries of static shared buffers
2429 * for front/back/depth is covered by looping over cliprects in brw_draw.c.
2431 * Note that the hardware's coordinates are inclusive, while Mesa's min is
2432 * inclusive but max is exclusive.
2434 for (unsigned i
= 0; i
< viewport_count
; i
++) {
2437 bbox
[0] = MAX2(ctx
->ViewportArray
[i
].X
, 0);
2438 bbox
[1] = MIN2(bbox
[0] + ctx
->ViewportArray
[i
].Width
, fb_width
);
2439 bbox
[2] = MAX2(ctx
->ViewportArray
[i
].Y
, 0);
2440 bbox
[3] = MIN2(bbox
[2] + ctx
->ViewportArray
[i
].Height
, fb_height
);
2441 _mesa_intersect_scissor_bounding_box(ctx
, i
, bbox
);
2443 if (bbox
[0] == bbox
[1] || bbox
[2] == bbox
[3]) {
2444 /* If the scissor was out of bounds and got clamped to 0 width/height
2445 * at the bounds, the subtraction of 1 from maximums could produce a
2446 * negative number and thus not clip anything. Instead, just provide
2447 * a min > max scissor inside the bounds, which produces the expected
2450 scissor
.ScissorRectangleXMin
= 1;
2451 scissor
.ScissorRectangleXMax
= 0;
2452 scissor
.ScissorRectangleYMin
= 1;
2453 scissor
.ScissorRectangleYMax
= 0;
2454 } else if (render_to_fbo
) {
2455 /* texmemory: Y=0=bottom */
2456 scissor
.ScissorRectangleXMin
= bbox
[0];
2457 scissor
.ScissorRectangleXMax
= bbox
[1] - 1;
2458 scissor
.ScissorRectangleYMin
= bbox
[2];
2459 scissor
.ScissorRectangleYMax
= bbox
[3] - 1;
2461 /* memory: Y=0=top */
2462 scissor
.ScissorRectangleXMin
= bbox
[0];
2463 scissor
.ScissorRectangleXMax
= bbox
[1] - 1;
2464 scissor
.ScissorRectangleYMin
= fb_height
- bbox
[3];
2465 scissor
.ScissorRectangleYMax
= fb_height
- bbox
[2] - 1;
2468 GENX(SCISSOR_RECT_pack
)(
2469 NULL
, scissor_map
+ i
* GENX(SCISSOR_RECT_length
), &scissor
);
2472 brw_batch_emit(brw
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
2473 ptr
.ScissorRectPointer
= scissor_state_offset
;
2477 static const struct brw_tracked_state
genX(scissor_state
) = {
2479 .mesa
= _NEW_BUFFERS
|
2482 .brw
= BRW_NEW_BATCH
|
2484 BRW_NEW_VIEWPORT_COUNT
,
2486 .emit
= genX(upload_scissor_state
),
2490 /* ---------------------------------------------------------------------- */
2493 UNUSED
static const uint32_t push_constant_opcodes
[] = {
2494 [MESA_SHADER_VERTEX
] = 21,
2495 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
2496 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
2497 [MESA_SHADER_GEOMETRY
] = 22,
2498 [MESA_SHADER_FRAGMENT
] = 23,
2499 [MESA_SHADER_COMPUTE
] = 0,
2503 upload_constant_state(struct brw_context
*brw
,
2504 struct brw_stage_state
*stage_state
,
2505 bool active
, uint32_t stage
)
2507 UNUSED
uint32_t mocs
= GEN_GEN
< 8 ? GEN7_MOCS_L3
: 0;
2508 active
= active
&& stage_state
->push_const_size
!= 0;
2510 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
2511 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
2514 pkt
.ConstantBody
.ConstantBuffer2ReadLength
=
2515 stage_state
->push_const_size
;
2516 pkt
.ConstantBody
.PointerToConstantBuffer2
=
2517 render_ro_bo(brw
->batch
.bo
, stage_state
->push_const_offset
);
2519 pkt
.ConstantBody
.ConstantBuffer0ReadLength
=
2520 stage_state
->push_const_size
;
2521 pkt
.ConstantBody
.PointerToConstantBuffer0
.offset
=
2522 stage_state
->push_const_offset
| mocs
;
2527 brw
->ctx
.NewDriverState
|= GEN_GEN
>= 9 ? BRW_NEW_SURFACES
: 0;
2533 genX(upload_vs_push_constants
)(struct brw_context
*brw
)
2535 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
2537 /* _BRW_NEW_VERTEX_PROGRAM */
2538 const struct brw_program
*vp
= brw_program_const(brw
->vertex_program
);
2539 /* BRW_NEW_VS_PROG_DATA */
2540 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
2542 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_VERTEX
);
2543 gen6_upload_push_constants(brw
, &vp
->program
, prog_data
, stage_state
);
2546 if (GEN_GEN
== 7 && !GEN_IS_HASWELL
&& !brw
->is_baytrail
)
2547 gen7_emit_vs_workaround_flush(brw
);
2549 upload_constant_state(brw
, stage_state
, true /* active */,
2550 MESA_SHADER_VERTEX
);
2554 static const struct brw_tracked_state
genX(vs_push_constants
) = {
2556 .mesa
= _NEW_PROGRAM_CONSTANTS
|
2558 .brw
= BRW_NEW_BATCH
|
2560 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
2561 BRW_NEW_VERTEX_PROGRAM
|
2562 BRW_NEW_VS_PROG_DATA
,
2564 .emit
= genX(upload_vs_push_constants
),
2568 genX(upload_gs_push_constants
)(struct brw_context
*brw
)
2570 struct brw_stage_state
*stage_state
= &brw
->gs
.base
;
2572 /* BRW_NEW_GEOMETRY_PROGRAM */
2573 const struct brw_program
*gp
= brw_program_const(brw
->geometry_program
);
2576 /* BRW_NEW_GS_PROG_DATA */
2577 struct brw_stage_prog_data
*prog_data
= brw
->gs
.base
.prog_data
;
2579 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_GEOMETRY
);
2580 gen6_upload_push_constants(brw
, &gp
->program
, prog_data
, stage_state
);
2584 upload_constant_state(brw
, stage_state
, gp
, MESA_SHADER_GEOMETRY
);
2588 static const struct brw_tracked_state
genX(gs_push_constants
) = {
2590 .mesa
= _NEW_PROGRAM_CONSTANTS
|
2592 .brw
= BRW_NEW_BATCH
|
2594 BRW_NEW_GEOMETRY_PROGRAM
|
2595 BRW_NEW_GS_PROG_DATA
|
2596 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
2598 .emit
= genX(upload_gs_push_constants
),
2602 genX(upload_wm_push_constants
)(struct brw_context
*brw
)
2604 struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
2605 /* BRW_NEW_FRAGMENT_PROGRAM */
2606 const struct brw_program
*fp
= brw_program_const(brw
->fragment_program
);
2607 /* BRW_NEW_FS_PROG_DATA */
2608 const struct brw_stage_prog_data
*prog_data
= brw
->wm
.base
.prog_data
;
2610 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_FRAGMENT
);
2612 gen6_upload_push_constants(brw
, &fp
->program
, prog_data
, stage_state
);
2615 upload_constant_state(brw
, stage_state
, true, MESA_SHADER_FRAGMENT
);
2619 static const struct brw_tracked_state
genX(wm_push_constants
) = {
2621 .mesa
= _NEW_PROGRAM_CONSTANTS
,
2622 .brw
= BRW_NEW_BATCH
|
2624 BRW_NEW_FRAGMENT_PROGRAM
|
2625 BRW_NEW_FS_PROG_DATA
|
2626 BRW_NEW_PUSH_CONSTANT_ALLOCATION
,
2628 .emit
= genX(upload_wm_push_constants
),
2632 /* ---------------------------------------------------------------------- */
2636 genX(determine_sample_mask
)(struct brw_context
*brw
)
2638 struct gl_context
*ctx
= &brw
->ctx
;
2639 float coverage
= 1.0f
;
2640 float coverage_invert
= false;
2641 unsigned sample_mask
= ~0u;
2643 /* BRW_NEW_NUM_SAMPLES */
2644 unsigned num_samples
= brw
->num_samples
;
2646 if (_mesa_is_multisample_enabled(ctx
)) {
2647 if (ctx
->Multisample
.SampleCoverage
) {
2648 coverage
= ctx
->Multisample
.SampleCoverageValue
;
2649 coverage_invert
= ctx
->Multisample
.SampleCoverageInvert
;
2651 if (ctx
->Multisample
.SampleMask
) {
2652 sample_mask
= ctx
->Multisample
.SampleMaskValue
;
2656 if (num_samples
> 1) {
2657 int coverage_int
= (int) (num_samples
* coverage
+ 0.5f
);
2658 uint32_t coverage_bits
= (1 << coverage_int
) - 1;
2659 if (coverage_invert
)
2660 coverage_bits
^= (1 << num_samples
) - 1;
2661 return coverage_bits
& sample_mask
;
2668 genX(emit_3dstate_multisample2
)(struct brw_context
*brw
,
2669 unsigned num_samples
)
2671 assert(brw
->num_samples
<= 16);
2673 unsigned log2_samples
= ffs(MAX2(num_samples
, 1)) - 1;
2675 brw_batch_emit(brw
, GENX(3DSTATE_MULTISAMPLE
), multi
) {
2676 multi
.PixelLocation
= CENTER
;
2677 multi
.NumberofMultisamples
= log2_samples
;
2679 GEN_SAMPLE_POS_4X(multi
.Sample
);
2681 switch (num_samples
) {
2683 GEN_SAMPLE_POS_1X(multi
.Sample
);
2686 GEN_SAMPLE_POS_2X(multi
.Sample
);
2689 GEN_SAMPLE_POS_4X(multi
.Sample
);
2692 GEN_SAMPLE_POS_8X(multi
.Sample
);
2702 genX(upload_multisample_state
)(struct brw_context
*brw
)
2704 genX(emit_3dstate_multisample2
)(brw
, brw
->num_samples
);
2706 brw_batch_emit(brw
, GENX(3DSTATE_SAMPLE_MASK
), sm
) {
2707 sm
.SampleMask
= genX(determine_sample_mask
)(brw
);
2711 static const struct brw_tracked_state
genX(multisample_state
) = {
2713 .mesa
= _NEW_MULTISAMPLE
,
2714 .brw
= BRW_NEW_BLORP
|
2716 BRW_NEW_NUM_SAMPLES
,
2718 .emit
= genX(upload_multisample_state
)
2722 /* ---------------------------------------------------------------------- */
2726 genX(upload_color_calc_state
)(struct brw_context
*brw
)
2728 struct gl_context
*ctx
= &brw
->ctx
;
2730 brw_state_emit(brw
, GENX(COLOR_CALC_STATE
), 64, &brw
->cc
.state_offset
, cc
) {
2732 cc
.AlphaTestFormat
= ALPHATEST_UNORM8
;
2733 UNCLAMPED_FLOAT_TO_UBYTE(cc
.AlphaReferenceValueAsUNORM8
,
2734 ctx
->Color
.AlphaRef
);
2738 cc
.StencilReferenceValue
= _mesa_get_stencil_ref(ctx
, 0);
2739 cc
.BackfaceStencilReferenceValue
=
2740 _mesa_get_stencil_ref(ctx
, ctx
->Stencil
._BackFace
);
2744 cc
.BlendConstantColorRed
= ctx
->Color
.BlendColorUnclamped
[0];
2745 cc
.BlendConstantColorGreen
= ctx
->Color
.BlendColorUnclamped
[1];
2746 cc
.BlendConstantColorBlue
= ctx
->Color
.BlendColorUnclamped
[2];
2747 cc
.BlendConstantColorAlpha
= ctx
->Color
.BlendColorUnclamped
[3];
2750 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
2751 ptr
.ColorCalcStatePointer
= brw
->cc
.state_offset
;
2753 ptr
.ColorCalcStatePointerValid
= true;
2758 static const struct brw_tracked_state
genX(color_calc_state
) = {
2760 .mesa
= _NEW_COLOR
|
2762 .brw
= BRW_NEW_BATCH
|
2765 BRW_NEW_STATE_BASE_ADDRESS
,
2767 .emit
= genX(upload_color_calc_state
),
2772 /* ---------------------------------------------------------------------- */
2776 genX(upload_sbe
)(struct brw_context
*brw
)
2778 struct gl_context
*ctx
= &brw
->ctx
;
2779 /* BRW_NEW_FS_PROG_DATA */
2780 const struct brw_wm_prog_data
*wm_prog_data
=
2781 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
2783 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = { { 0 } };
2785 #define attr_overrides sbe.Attribute
2787 uint32_t urb_entry_read_length
;
2788 uint32_t urb_entry_read_offset
;
2789 uint32_t point_sprite_enables
;
2791 brw_batch_emit(brw
, GENX(3DSTATE_SBE
), sbe
) {
2792 sbe
.AttributeSwizzleEnable
= true;
2793 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
2796 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
2800 * Window coordinates in an FBO are inverted, which means point
2801 * sprite origin must be inverted.
2803 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
)
2804 sbe
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
2806 sbe
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
2808 /* _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM,
2809 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM |
2810 * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA |
2811 * BRW_NEW_VUE_MAP_GEOM_OUT
2813 genX(calculate_attr_overrides
)(brw
,
2815 &point_sprite_enables
,
2816 &urb_entry_read_length
,
2817 &urb_entry_read_offset
);
2819 /* Typically, the URB entry read length and offset should be programmed
2820 * in 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active
2821 * stage which produces geometry. However, we don't know the proper
2822 * value until we call calculate_attr_overrides().
2824 * To fit with our existing code, we override the inherited values and
2825 * specify it here directly, as we did on previous generations.
2827 sbe
.VertexURBEntryReadLength
= urb_entry_read_length
;
2828 sbe
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
2829 sbe
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
2830 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
2833 sbe
.ForceVertexURBEntryReadLength
= true;
2834 sbe
.ForceVertexURBEntryReadOffset
= true;
2838 /* prepare the active component dwords */
2839 int input_index
= 0;
2840 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
2841 if (!(brw
->fragment_program
->info
.inputs_read
&
2842 BITFIELD64_BIT(attr
))) {
2846 assert(input_index
< 32);
2848 sbe
.AttributeActiveComponentFormat
[input_index
] = ACTIVE_COMPONENT_XYZW
;
2855 brw_batch_emit(brw
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
2856 for (int i
= 0; i
< 16; i
++)
2857 sbes
.Attribute
[i
] = attr_overrides
[i
];
2861 #undef attr_overrides
2864 static const struct brw_tracked_state
genX(sbe_state
) = {
2866 .mesa
= _NEW_BUFFERS
|
2871 .brw
= BRW_NEW_BLORP
|
2873 BRW_NEW_FRAGMENT_PROGRAM
|
2874 BRW_NEW_FS_PROG_DATA
|
2875 BRW_NEW_GS_PROG_DATA
|
2876 BRW_NEW_TES_PROG_DATA
|
2877 BRW_NEW_VUE_MAP_GEOM_OUT
|
2878 (GEN_GEN
== 7 ? BRW_NEW_PRIMITIVE
2881 .emit
= genX(upload_sbe
),
2885 /* ---------------------------------------------------------------------- */
2889 * Outputs the 3DSTATE_SO_DECL_LIST command.
2891 * The data output is a series of 64-bit entries containing a SO_DECL per
2892 * stream. We only have one stream of rendering coming out of the GS unit, so
2893 * we only emit stream 0 (low 16 bits) SO_DECLs.
2896 genX(upload_3dstate_so_decl_list
)(struct brw_context
*brw
,
2897 const struct brw_vue_map
*vue_map
)
2899 struct gl_context
*ctx
= &brw
->ctx
;
2900 /* BRW_NEW_TRANSFORM_FEEDBACK */
2901 struct gl_transform_feedback_object
*xfb_obj
=
2902 ctx
->TransformFeedback
.CurrentObject
;
2903 const struct gl_transform_feedback_info
*linked_xfb_info
=
2904 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
2905 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
2906 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2907 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2908 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
2910 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
2912 memset(so_decl
, 0, sizeof(so_decl
));
2914 /* Construct the list of SO_DECLs to be emitted. The formatting of the
2915 * command feels strange -- each dword pair contains a SO_DECL per stream.
2917 for (unsigned i
= 0; i
< linked_xfb_info
->NumOutputs
; i
++) {
2918 int buffer
= linked_xfb_info
->Outputs
[i
].OutputBuffer
;
2919 struct GENX(SO_DECL
) decl
= {0};
2920 int varying
= linked_xfb_info
->Outputs
[i
].OutputRegister
;
2921 const unsigned components
= linked_xfb_info
->Outputs
[i
].NumComponents
;
2922 unsigned component_mask
= (1 << components
) - 1;
2923 unsigned stream_id
= linked_xfb_info
->Outputs
[i
].StreamId
;
2924 unsigned decl_buffer_slot
= buffer
;
2925 assert(stream_id
< MAX_VERTEX_STREAMS
);
2927 /* gl_PointSize is stored in VARYING_SLOT_PSIZ.w
2928 * gl_Layer is stored in VARYING_SLOT_PSIZ.y
2929 * gl_ViewportIndex is stored in VARYING_SLOT_PSIZ.z
2931 if (varying
== VARYING_SLOT_PSIZ
) {
2932 assert(components
== 1);
2933 component_mask
<<= 3;
2934 } else if (varying
== VARYING_SLOT_LAYER
) {
2935 assert(components
== 1);
2936 component_mask
<<= 1;
2937 } else if (varying
== VARYING_SLOT_VIEWPORT
) {
2938 assert(components
== 1);
2939 component_mask
<<= 2;
2941 component_mask
<<= linked_xfb_info
->Outputs
[i
].ComponentOffset
;
2944 buffer_mask
[stream_id
] |= 1 << buffer
;
2946 decl
.OutputBufferSlot
= decl_buffer_slot
;
2947 if (varying
== VARYING_SLOT_LAYER
|| varying
== VARYING_SLOT_VIEWPORT
) {
2948 decl
.RegisterIndex
= vue_map
->varying_to_slot
[VARYING_SLOT_PSIZ
];
2950 assert(vue_map
->varying_to_slot
[varying
] >= 0);
2951 decl
.RegisterIndex
= vue_map
->varying_to_slot
[varying
];
2953 decl
.ComponentMask
= component_mask
;
2955 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
2956 * array. Instead, it simply increments DstOffset for the following
2957 * input by the number of components that should be skipped.
2959 * Our hardware is unusual in that it requires us to program SO_DECLs
2960 * for fake "hole" components, rather than simply taking the offset
2961 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
2962 * program as many size = 4 holes as we can, then a final hole to
2963 * accommodate the final 1, 2, or 3 remaining.
2965 int skip_components
=
2966 linked_xfb_info
->Outputs
[i
].DstOffset
- next_offset
[buffer
];
2968 next_offset
[buffer
] += skip_components
;
2970 while (skip_components
>= 4) {
2971 struct GENX(SO_DECL
) *d
= &so_decl
[stream_id
][decls
[stream_id
]++];
2973 d
->OutputBufferSlot
= decl_buffer_slot
;
2974 d
->ComponentMask
= 0xf;
2975 skip_components
-= 4;
2978 if (skip_components
> 0) {
2979 struct GENX(SO_DECL
) *d
= &so_decl
[stream_id
][decls
[stream_id
]++];
2981 d
->OutputBufferSlot
= decl_buffer_slot
;
2982 d
->ComponentMask
= (1 << skip_components
) - 1;
2985 assert(linked_xfb_info
->Outputs
[i
].DstOffset
== next_offset
[buffer
]);
2987 next_offset
[buffer
] += components
;
2989 so_decl
[stream_id
][decls
[stream_id
]++] = decl
;
2991 if (decls
[stream_id
] > max_decls
)
2992 max_decls
= decls
[stream_id
];
2996 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_SO_DECL_LIST
), 3 + 2 * max_decls
,
2997 .StreamtoBufferSelects0
= buffer_mask
[0],
2998 .StreamtoBufferSelects1
= buffer_mask
[1],
2999 .StreamtoBufferSelects2
= buffer_mask
[2],
3000 .StreamtoBufferSelects3
= buffer_mask
[3],
3001 .NumEntries0
= decls
[0],
3002 .NumEntries1
= decls
[1],
3003 .NumEntries2
= decls
[2],
3004 .NumEntries3
= decls
[3]);
3006 for (int i
= 0; i
< max_decls
; i
++) {
3007 GENX(SO_DECL_ENTRY_pack
)(
3008 brw
, dw
+ 2 + i
* 2,
3009 &(struct GENX(SO_DECL_ENTRY
)) {
3010 .Stream0Decl
= so_decl
[0][i
],
3011 .Stream1Decl
= so_decl
[1][i
],
3012 .Stream2Decl
= so_decl
[2][i
],
3013 .Stream3Decl
= so_decl
[3][i
],
3019 genX(upload_3dstate_so_buffers
)(struct brw_context
*brw
)
3021 struct gl_context
*ctx
= &brw
->ctx
;
3022 /* BRW_NEW_TRANSFORM_FEEDBACK */
3023 struct gl_transform_feedback_object
*xfb_obj
=
3024 ctx
->TransformFeedback
.CurrentObject
;
3026 const struct gl_transform_feedback_info
*linked_xfb_info
=
3027 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
3029 struct brw_transform_feedback_object
*brw_obj
=
3030 (struct brw_transform_feedback_object
*) xfb_obj
;
3031 uint32_t mocs_wb
= brw
->gen
>= 9 ? SKL_MOCS_WB
: BDW_MOCS_WB
;
3034 /* Set up the up to 4 output buffers. These are the ranges defined in the
3035 * gl_transform_feedback_object.
3037 for (int i
= 0; i
< 4; i
++) {
3038 struct intel_buffer_object
*bufferobj
=
3039 intel_buffer_object(xfb_obj
->Buffers
[i
]);
3042 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
3043 sob
.SOBufferIndex
= i
;
3048 uint32_t start
= xfb_obj
->Offset
[i
];
3049 assert(start
% 4 == 0);
3050 uint32_t end
= ALIGN(start
+ xfb_obj
->Size
[i
], 4);
3052 intel_bufferobj_buffer(brw
, bufferobj
, start
, end
- start
);
3053 assert(end
<= bo
->size
);
3055 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
3056 sob
.SOBufferIndex
= i
;
3058 sob
.SurfaceBaseAddress
= render_bo(bo
, start
);
3060 sob
.SurfacePitch
= linked_xfb_info
->Buffers
[i
].Stride
* 4;
3061 sob
.SurfaceEndAddress
= render_bo(bo
, end
);
3063 sob
.SOBufferEnable
= true;
3064 sob
.StreamOffsetWriteEnable
= true;
3065 sob
.StreamOutputBufferOffsetAddressEnable
= true;
3066 sob
.SOBufferMOCS
= mocs_wb
;
3068 sob
.SurfaceSize
= MAX2(xfb_obj
->Size
[i
] / 4, 1) - 1;
3069 sob
.StreamOutputBufferOffsetAddress
=
3070 instruction_bo(brw_obj
->offset_bo
, i
* sizeof(uint32_t));
3072 if (brw_obj
->zero_offsets
) {
3073 /* Zero out the offset and write that to offset_bo */
3074 sob
.StreamOffset
= 0;
3076 /* Use offset_bo as the "Stream Offset." */
3077 sob
.StreamOffset
= 0xFFFFFFFF;
3084 brw_obj
->zero_offsets
= false;
3089 query_active(struct gl_query_object
*q
)
3091 return q
&& q
->Active
;
3095 genX(upload_3dstate_streamout
)(struct brw_context
*brw
, bool active
,
3096 const struct brw_vue_map
*vue_map
)
3098 struct gl_context
*ctx
= &brw
->ctx
;
3099 /* BRW_NEW_TRANSFORM_FEEDBACK */
3100 struct gl_transform_feedback_object
*xfb_obj
=
3101 ctx
->TransformFeedback
.CurrentObject
;
3103 brw_batch_emit(brw
, GENX(3DSTATE_STREAMOUT
), sos
) {
3105 int urb_entry_read_offset
= 0;
3106 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
3107 urb_entry_read_offset
;
3109 sos
.SOFunctionEnable
= true;
3110 sos
.SOStatisticsEnable
= true;
3112 /* BRW_NEW_RASTERIZER_DISCARD */
3113 if (ctx
->RasterDiscard
) {
3114 if (!query_active(ctx
->Query
.PrimitivesGenerated
[0])) {
3115 sos
.RenderingDisable
= true;
3117 perf_debug("Rasterizer discard with a GL_PRIMITIVES_GENERATED "
3118 "query active relies on the clipper.");
3123 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
)
3124 sos
.ReorderMode
= TRAILING
;
3127 sos
.SOBufferEnable0
= xfb_obj
->Buffers
[0] != NULL
;
3128 sos
.SOBufferEnable1
= xfb_obj
->Buffers
[1] != NULL
;
3129 sos
.SOBufferEnable2
= xfb_obj
->Buffers
[2] != NULL
;
3130 sos
.SOBufferEnable3
= xfb_obj
->Buffers
[3] != NULL
;
3132 const struct gl_transform_feedback_info
*linked_xfb_info
=
3133 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
3134 /* Set buffer pitches; 0 means unbound. */
3135 if (xfb_obj
->Buffers
[0])
3136 sos
.Buffer0SurfacePitch
= linked_xfb_info
->Buffers
[0].Stride
* 4;
3137 if (xfb_obj
->Buffers
[1])
3138 sos
.Buffer1SurfacePitch
= linked_xfb_info
->Buffers
[1].Stride
* 4;
3139 if (xfb_obj
->Buffers
[2])
3140 sos
.Buffer2SurfacePitch
= linked_xfb_info
->Buffers
[2].Stride
* 4;
3141 if (xfb_obj
->Buffers
[3])
3142 sos
.Buffer3SurfacePitch
= linked_xfb_info
->Buffers
[3].Stride
* 4;
3145 /* We always read the whole vertex. This could be reduced at some
3146 * point by reading less and offsetting the register index in the
3149 sos
.Stream0VertexReadOffset
= urb_entry_read_offset
;
3150 sos
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
3151 sos
.Stream1VertexReadOffset
= urb_entry_read_offset
;
3152 sos
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
3153 sos
.Stream2VertexReadOffset
= urb_entry_read_offset
;
3154 sos
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
3155 sos
.Stream3VertexReadOffset
= urb_entry_read_offset
;
3156 sos
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
3162 genX(upload_sol
)(struct brw_context
*brw
)
3164 struct gl_context
*ctx
= &brw
->ctx
;
3165 /* BRW_NEW_TRANSFORM_FEEDBACK */
3166 bool active
= _mesa_is_xfb_active_and_unpaused(ctx
);
3169 genX(upload_3dstate_so_buffers
)(brw
);
3171 /* BRW_NEW_VUE_MAP_GEOM_OUT */
3172 genX(upload_3dstate_so_decl_list
)(brw
, &brw
->vue_map_geom_out
);
3175 /* Finally, set up the SOL stage. This command must always follow updates to
3176 * the nonpipelined SOL state (3DSTATE_SO_BUFFER, 3DSTATE_SO_DECL_LIST) or
3177 * MMIO register updates (current performed by the kernel at each batch
3180 genX(upload_3dstate_streamout
)(brw
, active
, &brw
->vue_map_geom_out
);
3183 static const struct brw_tracked_state
genX(sol_state
) = {
3186 .brw
= BRW_NEW_BATCH
|
3188 BRW_NEW_RASTERIZER_DISCARD
|
3189 BRW_NEW_VUE_MAP_GEOM_OUT
|
3190 BRW_NEW_TRANSFORM_FEEDBACK
,
3192 .emit
= genX(upload_sol
),
3196 /* ---------------------------------------------------------------------- */
3200 genX(upload_ps
)(struct brw_context
*brw
)
3202 UNUSED
const struct gl_context
*ctx
= &brw
->ctx
;
3203 UNUSED
const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
3205 /* BRW_NEW_FS_PROG_DATA */
3206 const struct brw_wm_prog_data
*prog_data
=
3207 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
3208 const struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
3213 brw_batch_emit(brw
, GENX(3DSTATE_PS
), ps
) {
3214 /* Initialize the execution mask with VMask. Otherwise, derivatives are
3215 * incorrect for subspans where some of the pixels are unlit. We believe
3216 * the bit just didn't take effect in previous generations.
3218 ps
.VectorMaskEnable
= GEN_GEN
>= 8;
3221 DIV_ROUND_UP(CLAMP(stage_state
->sampler_count
, 0, 16), 4);
3223 /* BRW_NEW_FS_PROG_DATA */
3224 ps
.BindingTableEntryCount
= prog_data
->base
.binding_table
.size_bytes
/ 4;
3226 if (prog_data
->base
.use_alt_mode
)
3227 ps
.FloatingPointMode
= Alternate
;
3229 /* Haswell requires the sample mask to be set in this packet as well as
3230 * in 3DSTATE_SAMPLE_MASK; the values should match.
3233 /* _NEW_BUFFERS, _NEW_MULTISAMPLE */
3235 ps
.SampleMask
= genX(determine_sample_mask(brw
));
3238 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64;
3239 * it implicitly scales for different GT levels (which have some # of
3242 * In Gen8 the format is U8-2 whereas in Gen9 it is U8-1.
3245 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
3247 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
3249 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
3252 if (prog_data
->base
.nr_params
> 0)
3253 ps
.PushConstantEnable
= true;
3256 /* From the IVB PRM, volume 2 part 1, page 287:
3257 * "This bit is inserted in the PS payload header and made available to
3258 * the DataPort (either via the message header or via header bypass) to
3259 * indicate that oMask data (one or two phases) is included in Render
3260 * Target Write messages. If present, the oMask data is used to mask off
3263 ps
.oMaskPresenttoRenderTarget
= prog_data
->uses_omask
;
3265 /* The hardware wedges if you have this bit set but don't turn on any
3266 * dual source blend factors.
3268 * BRW_NEW_FS_PROG_DATA | _NEW_COLOR
3270 ps
.DualSourceBlendEnable
= prog_data
->dual_src_blend
&&
3271 (ctx
->Color
.BlendEnabled
& 1) &&
3272 ctx
->Color
.Blend
[0]._UsesDualSrc
;
3274 /* BRW_NEW_FS_PROG_DATA */
3275 ps
.AttributeEnable
= (prog_data
->num_varying_inputs
!= 0);
3278 /* From the documentation for this packet:
3279 * "If the PS kernel does not need the Position XY Offsets to
3280 * compute a Position Value, then this field should be programmed
3281 * to POSOFFSET_NONE."
3283 * "SW Recommendation: If the PS kernel needs the Position Offsets
3284 * to compute a Position XY value, this field should match Position
3285 * ZW Interpolation Mode to ensure a consistent position.xyzw
3288 * We only require XY sample offsets. So, this recommendation doesn't
3289 * look useful at the moment. We might need this in future.
3291 if (prog_data
->uses_pos_offset
)
3292 ps
.PositionXYOffsetSelect
= POSOFFSET_SAMPLE
;
3294 ps
.PositionXYOffsetSelect
= POSOFFSET_NONE
;
3296 ps
.RenderTargetFastClearEnable
= brw
->wm
.fast_clear_op
;
3297 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
3298 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
3299 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
3300 prog_data
->base
.dispatch_grf_start_reg
;
3301 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
3302 prog_data
->dispatch_grf_start_reg_2
;
3304 ps
.KernelStartPointer0
= stage_state
->prog_offset
;
3305 ps
.KernelStartPointer2
= stage_state
->prog_offset
+
3306 prog_data
->prog_offset_2
;
3308 if (prog_data
->base
.total_scratch
) {
3309 ps
.ScratchSpaceBasePointer
=
3310 render_bo(stage_state
->scratch_bo
,
3311 ffs(stage_state
->per_thread_scratch
) - 11);
3316 static const struct brw_tracked_state
genX(ps_state
) = {
3318 .mesa
= _NEW_MULTISAMPLE
|
3319 (GEN_GEN
< 8 ? _NEW_BUFFERS
|
3322 .brw
= BRW_NEW_BATCH
|
3324 BRW_NEW_FS_PROG_DATA
,
3326 .emit
= genX(upload_ps
),
3330 /* ---------------------------------------------------------------------- */
3334 genX(upload_hs_state
)(struct brw_context
*brw
)
3336 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
3337 struct brw_stage_state
*stage_state
= &brw
->tcs
.base
;
3338 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
3339 const struct brw_vue_prog_data
*vue_prog_data
=
3340 brw_vue_prog_data(stage_prog_data
);
3342 /* BRW_NEW_TES_PROG_DATA */
3343 struct brw_tcs_prog_data
*tcs_prog_data
=
3344 brw_tcs_prog_data(stage_prog_data
);
3346 if (!tcs_prog_data
) {
3347 brw_batch_emit(brw
, GENX(3DSTATE_HS
), hs
);
3349 brw_batch_emit(brw
, GENX(3DSTATE_HS
), hs
) {
3350 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
);
3352 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
3353 hs
.IncludeVertexHandles
= true;
3355 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
3360 static const struct brw_tracked_state
genX(hs_state
) = {
3363 .brw
= BRW_NEW_BATCH
|
3365 BRW_NEW_TCS_PROG_DATA
|
3366 BRW_NEW_TESS_PROGRAMS
,
3368 .emit
= genX(upload_hs_state
),
3372 genX(upload_ds_state
)(struct brw_context
*brw
)
3374 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
3375 const struct brw_stage_state
*stage_state
= &brw
->tes
.base
;
3376 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
3378 /* BRW_NEW_TES_PROG_DATA */
3379 const struct brw_tes_prog_data
*tes_prog_data
=
3380 brw_tes_prog_data(stage_prog_data
);
3381 const struct brw_vue_prog_data
*vue_prog_data
=
3382 brw_vue_prog_data(stage_prog_data
);
3384 if (!tes_prog_data
) {
3385 brw_batch_emit(brw
, GENX(3DSTATE_DS
), ds
);
3387 brw_batch_emit(brw
, GENX(3DSTATE_DS
), ds
) {
3388 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
);
3390 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
3391 ds
.ComputeWCoordinateEnable
=
3392 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
3395 if (vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
)
3396 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
3397 ds
.UserClipDistanceCullTestEnableBitmask
=
3398 vue_prog_data
->cull_distance_mask
;
3404 static const struct brw_tracked_state
genX(ds_state
) = {
3407 .brw
= BRW_NEW_BATCH
|
3409 BRW_NEW_TESS_PROGRAMS
|
3410 BRW_NEW_TES_PROG_DATA
,
3412 .emit
= genX(upload_ds_state
),
3415 /* ---------------------------------------------------------------------- */
3418 upload_te_state(struct brw_context
*brw
)
3420 /* BRW_NEW_TESS_PROGRAMS */
3421 bool active
= brw
->tess_eval_program
;
3423 /* BRW_NEW_TES_PROG_DATA */
3424 const struct brw_tes_prog_data
*tes_prog_data
=
3425 brw_tes_prog_data(brw
->tes
.base
.prog_data
);
3428 brw_batch_emit(brw
, GENX(3DSTATE_TE
), te
) {
3429 te
.Partitioning
= tes_prog_data
->partitioning
;
3430 te
.OutputTopology
= tes_prog_data
->output_topology
;
3431 te
.TEDomain
= tes_prog_data
->domain
;
3433 te
.MaximumTessellationFactorOdd
= 63.0;
3434 te
.MaximumTessellationFactorNotOdd
= 64.0;
3437 brw_batch_emit(brw
, GENX(3DSTATE_TE
), te
);
3441 static const struct brw_tracked_state
genX(te_state
) = {
3444 .brw
= BRW_NEW_BLORP
|
3446 BRW_NEW_TES_PROG_DATA
|
3447 BRW_NEW_TESS_PROGRAMS
,
3449 .emit
= upload_te_state
,
3452 /* ---------------------------------------------------------------------- */
3455 genX(upload_tes_push_constants
)(struct brw_context
*brw
)
3457 struct brw_stage_state
*stage_state
= &brw
->tes
.base
;
3458 /* BRW_NEW_TESS_PROGRAMS */
3459 const struct brw_program
*tep
= brw_program_const(brw
->tess_eval_program
);
3462 /* BRW_NEW_TES_PROG_DATA */
3463 const struct brw_stage_prog_data
*prog_data
= brw
->tes
.base
.prog_data
;
3464 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_TESS_EVAL
);
3465 gen6_upload_push_constants(brw
, &tep
->program
, prog_data
, stage_state
);
3468 upload_constant_state(brw
, stage_state
, tep
, MESA_SHADER_TESS_EVAL
);
3471 static const struct brw_tracked_state
genX(tes_push_constants
) = {
3473 .mesa
= _NEW_PROGRAM_CONSTANTS
,
3474 .brw
= BRW_NEW_BATCH
|
3476 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
3477 BRW_NEW_TESS_PROGRAMS
|
3478 BRW_NEW_TES_PROG_DATA
,
3480 .emit
= genX(upload_tes_push_constants
),
3484 genX(upload_tcs_push_constants
)(struct brw_context
*brw
)
3486 struct brw_stage_state
*stage_state
= &brw
->tcs
.base
;
3487 /* BRW_NEW_TESS_PROGRAMS */
3488 const struct brw_program
*tcp
= brw_program_const(brw
->tess_ctrl_program
);
3489 bool active
= brw
->tess_eval_program
;
3492 /* BRW_NEW_TCS_PROG_DATA */
3493 const struct brw_stage_prog_data
*prog_data
= brw
->tcs
.base
.prog_data
;
3495 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_TESS_CTRL
);
3496 gen6_upload_push_constants(brw
, &tcp
->program
, prog_data
, stage_state
);
3499 upload_constant_state(brw
, stage_state
, active
, MESA_SHADER_TESS_CTRL
);
3502 static const struct brw_tracked_state
genX(tcs_push_constants
) = {
3504 .mesa
= _NEW_PROGRAM_CONSTANTS
,
3505 .brw
= BRW_NEW_BATCH
|
3507 BRW_NEW_DEFAULT_TESS_LEVELS
|
3508 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
3509 BRW_NEW_TESS_PROGRAMS
|
3510 BRW_NEW_TCS_PROG_DATA
,
3512 .emit
= genX(upload_tcs_push_constants
),
3516 /* ---------------------------------------------------------------------- */
3520 genX(upload_raster
)(struct brw_context
*brw
)
3522 struct gl_context
*ctx
= &brw
->ctx
;
3525 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
3528 struct gl_polygon_attrib
*polygon
= &ctx
->Polygon
;
3531 struct gl_point_attrib
*point
= &ctx
->Point
;
3533 brw_batch_emit(brw
, GENX(3DSTATE_RASTER
), raster
) {
3534 if (polygon
->_FrontBit
== render_to_fbo
)
3535 raster
.FrontWinding
= CounterClockwise
;
3537 if (polygon
->CullFlag
) {
3538 switch (polygon
->CullFaceMode
) {
3540 raster
.CullMode
= CULLMODE_FRONT
;
3543 raster
.CullMode
= CULLMODE_BACK
;
3545 case GL_FRONT_AND_BACK
:
3546 raster
.CullMode
= CULLMODE_BOTH
;
3549 unreachable("not reached");
3552 raster
.CullMode
= CULLMODE_NONE
;
3555 point
->SmoothFlag
= raster
.SmoothPointEnable
;
3557 raster
.DXMultisampleRasterizationEnable
=
3558 _mesa_is_multisample_enabled(ctx
);
3560 raster
.GlobalDepthOffsetEnableSolid
= polygon
->OffsetFill
;
3561 raster
.GlobalDepthOffsetEnableWireframe
= polygon
->OffsetLine
;
3562 raster
.GlobalDepthOffsetEnablePoint
= polygon
->OffsetPoint
;
3564 switch (polygon
->FrontMode
) {
3566 raster
.FrontFaceFillMode
= FILL_MODE_SOLID
;
3569 raster
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
3572 raster
.FrontFaceFillMode
= FILL_MODE_POINT
;
3575 unreachable("not reached");
3578 switch (polygon
->BackMode
) {
3580 raster
.BackFaceFillMode
= FILL_MODE_SOLID
;
3583 raster
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
3586 raster
.BackFaceFillMode
= FILL_MODE_POINT
;
3589 unreachable("not reached");
3593 raster
.AntialiasingEnable
= ctx
->Line
.SmoothFlag
;
3596 raster
.ScissorRectangleEnable
= ctx
->Scissor
.EnableFlags
;
3598 /* _NEW_TRANSFORM */
3599 if (!ctx
->Transform
.DepthClamp
) {
3601 raster
.ViewportZFarClipTestEnable
= true;
3602 raster
.ViewportZNearClipTestEnable
= true;
3604 raster
.ViewportZClipTestEnable
= true;
3608 /* BRW_NEW_CONSERVATIVE_RASTERIZATION */
3610 raster
.ConservativeRasterizationEnable
=
3611 ctx
->IntelConservativeRasterization
;
3614 raster
.GlobalDepthOffsetClamp
= polygon
->OffsetClamp
;
3615 raster
.GlobalDepthOffsetScale
= polygon
->OffsetFactor
;
3617 raster
.GlobalDepthOffsetConstant
= polygon
->OffsetUnits
* 2;
3621 static const struct brw_tracked_state
genX(raster_state
) = {
3623 .mesa
= _NEW_BUFFERS
|
3630 .brw
= BRW_NEW_BLORP
|
3632 BRW_NEW_CONSERVATIVE_RASTERIZATION
,
3634 .emit
= genX(upload_raster
),
3638 /* ---------------------------------------------------------------------- */
3642 genX(upload_ps_extra
)(struct brw_context
*brw
)
3644 UNUSED
struct gl_context
*ctx
= &brw
->ctx
;
3646 const struct brw_wm_prog_data
*prog_data
=
3647 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
3649 brw_batch_emit(brw
, GENX(3DSTATE_PS_EXTRA
), psx
) {
3650 psx
.PixelShaderValid
= true;
3651 psx
.PixelShaderComputedDepthMode
= prog_data
->computed_depth_mode
;
3652 psx
.PixelShaderKillsPixel
= prog_data
->uses_kill
;
3653 psx
.AttributeEnable
= prog_data
->num_varying_inputs
!= 0;
3654 psx
.PixelShaderUsesSourceDepth
= prog_data
->uses_src_depth
;
3655 psx
.PixelShaderUsesSourceW
= prog_data
->uses_src_w
;
3656 psx
.PixelShaderIsPerSample
= prog_data
->persample_dispatch
;
3658 /* _NEW_MULTISAMPLE | BRW_NEW_CONSERVATIVE_RASTERIZATION */
3659 if (prog_data
->uses_sample_mask
) {
3661 if (prog_data
->post_depth_coverage
)
3662 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
3663 else if (prog_data
->inner_coverage
&& ctx
->IntelConservativeRasterization
)
3664 psx
.InputCoverageMaskState
= ICMS_INNER_CONSERVATIVE
;
3666 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
3668 psx
.PixelShaderUsesInputCoverageMask
= true;
3672 psx
.oMaskPresenttoRenderTarget
= prog_data
->uses_omask
;
3674 psx
.PixelShaderPullsBary
= prog_data
->pulls_bary
;
3675 psx
.PixelShaderComputesStencil
= prog_data
->computed_stencil
;
3678 /* The stricter cross-primitive coherency guarantees that the hardware
3679 * gives us with the "Accesses UAV" bit set for at least one shader stage
3680 * and the "UAV coherency required" bit set on the 3DPRIMITIVE command
3681 * are redundant within the current image, atomic counter and SSBO GL
3682 * APIs, which all have very loose ordering and coherency requirements
3683 * and generally rely on the application to insert explicit barriers when
3684 * a shader invocation is expected to see the memory writes performed by
3685 * the invocations of some previous primitive. Regardless of the value
3686 * of "UAV coherency required", the "Accesses UAV" bits will implicitly
3687 * cause an in most cases useless DC flush when the lowermost stage with
3688 * the bit set finishes execution.
3690 * It would be nice to disable it, but in some cases we can't because on
3691 * Gen8+ it also has an influence on rasterization via the PS UAV-only
3692 * signal (which could be set independently from the coherency mechanism
3693 * in the 3DSTATE_WM command on Gen7), and because in some cases it will
3694 * determine whether the hardware skips execution of the fragment shader
3695 * or not via the ThreadDispatchEnable signal. However if we know that
3696 * GEN8_PS_BLEND_HAS_WRITEABLE_RT is going to be set and
3697 * GEN8_PSX_PIXEL_SHADER_NO_RT_WRITE is not set it shouldn't make any
3698 * difference so we may just disable it here.
3700 * Gen8 hardware tries to compute ThreadDispatchEnable for us but doesn't
3701 * take into account KillPixels when no depth or stencil writes are
3702 * enabled. In order for occlusion queries to work correctly with no
3703 * attachments, we need to force-enable here.
3705 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM | _NEW_BUFFERS |
3708 if ((prog_data
->has_side_effects
|| prog_data
->uses_kill
) &&
3709 !brw_color_buffer_write_enabled(brw
))
3710 psx
.PixelShaderHasUAV
= true;
3714 const struct brw_tracked_state
genX(ps_extra
) = {
3716 .mesa
= _NEW_BUFFERS
| _NEW_COLOR
,
3717 .brw
= BRW_NEW_BLORP
|
3719 BRW_NEW_FRAGMENT_PROGRAM
|
3720 BRW_NEW_FS_PROG_DATA
|
3721 BRW_NEW_CONSERVATIVE_RASTERIZATION
,
3723 .emit
= genX(upload_ps_extra
),
3727 /* ---------------------------------------------------------------------- */
3731 genX(upload_ps_blend
)(struct brw_context
*brw
)
3733 struct gl_context
*ctx
= &brw
->ctx
;
3736 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
3737 const bool buffer0_is_integer
= ctx
->DrawBuffer
->_IntegerBuffers
& 0x1;
3740 struct gl_colorbuffer_attrib
*color
= &ctx
->Color
;
3742 brw_batch_emit(brw
, GENX(3DSTATE_PS_BLEND
), pb
) {
3743 /* BRW_NEW_FRAGMENT_PROGRAM | _NEW_BUFFERS | _NEW_COLOR */
3744 pb
.HasWriteableRT
= brw_color_buffer_write_enabled(brw
);
3746 if (!buffer0_is_integer
) {
3747 /* _NEW_MULTISAMPLE */
3748 pb
.AlphaToCoverageEnable
=
3749 _mesa_is_multisample_enabled(ctx
) &&
3750 ctx
->Multisample
.SampleAlphaToCoverage
;
3752 pb
.AlphaTestEnable
= color
->AlphaEnabled
;
3755 /* Used for implementing the following bit of GL_EXT_texture_integer:
3756 * "Per-fragment operations that require floating-point color
3757 * components, including multisample alpha operations, alpha test,
3758 * blending, and dithering, have no effect when the corresponding
3759 * colors are written to an integer color buffer."
3761 * The OpenGL specification 3.3 (page 196), section 4.1.3 says:
3762 * "If drawbuffer zero is not NONE and the buffer it references has an
3763 * integer format, the SAMPLE_ALPHA_TO_COVERAGE and SAMPLE_ALPHA_TO_ONE
3764 * operations are skipped."
3766 if (rb
&& !buffer0_is_integer
&& (color
->BlendEnabled
& 1)) {
3767 GLenum eqRGB
= color
->Blend
[0].EquationRGB
;
3768 GLenum eqA
= color
->Blend
[0].EquationA
;
3769 GLenum srcRGB
= color
->Blend
[0].SrcRGB
;
3770 GLenum dstRGB
= color
->Blend
[0].DstRGB
;
3771 GLenum srcA
= color
->Blend
[0].SrcA
;
3772 GLenum dstA
= color
->Blend
[0].DstA
;
3774 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
)
3775 srcRGB
= dstRGB
= GL_ONE
;
3777 if (eqA
== GL_MIN
|| eqA
== GL_MAX
)
3778 srcA
= dstA
= GL_ONE
;
3780 /* Due to hardware limitations, the destination may have information
3781 * in an alpha channel even when the format specifies no alpha
3782 * channel. In order to avoid getting any incorrect blending due to
3783 * that alpha channel, coerce the blend factors to values that will
3784 * not read the alpha channel, but will instead use the correct
3785 * implicit value for alpha.
3787 if (!_mesa_base_format_has_channel(rb
->_BaseFormat
,
3788 GL_TEXTURE_ALPHA_TYPE
)) {
3789 srcRGB
= brw_fix_xRGB_alpha(srcRGB
);
3790 srcA
= brw_fix_xRGB_alpha(srcA
);
3791 dstRGB
= brw_fix_xRGB_alpha(dstRGB
);
3792 dstA
= brw_fix_xRGB_alpha(dstA
);
3795 pb
.ColorBufferBlendEnable
= true;
3796 pb
.SourceAlphaBlendFactor
= brw_translate_blend_factor(srcA
);
3797 pb
.DestinationAlphaBlendFactor
= brw_translate_blend_factor(dstA
);
3798 pb
.SourceBlendFactor
= brw_translate_blend_factor(srcRGB
);
3799 pb
.DestinationBlendFactor
= brw_translate_blend_factor(dstRGB
);
3801 pb
.IndependentAlphaBlendEnable
=
3802 srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
;
3807 static const struct brw_tracked_state
genX(ps_blend
) = {
3809 .mesa
= _NEW_BUFFERS
|
3812 .brw
= BRW_NEW_BLORP
|
3814 BRW_NEW_FRAGMENT_PROGRAM
,
3816 .emit
= genX(upload_ps_blend
)
3821 /* ---------------------------------------------------------------------- */
3825 genX(upload_viewport_state_pointers
)(struct brw_context
*brw
)
3827 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vp
) {
3828 vp
.CCViewportStateChange
= 1;
3829 vp
.SFViewportStateChange
= 1;
3830 vp
.CLIPViewportStateChange
= 1;
3831 vp
.PointertoCLIP_VIEWPORT
= brw
->clip
.vp_offset
;
3832 vp
.PointertoSF_VIEWPORT
= brw
->sf
.vp_offset
;
3833 vp
.PointertoCC_VIEWPORT
= brw
->cc
.vp_offset
;
3837 static const struct brw_tracked_state
genX(viewport_state
) = {
3840 .brw
= BRW_NEW_BATCH
|
3845 BRW_NEW_STATE_BASE_ADDRESS
,
3847 .emit
= genX(upload_viewport_state_pointers
),
3851 /* ---------------------------------------------------------------------- */
3854 genX(init_atoms
)(struct brw_context
*brw
)
3857 static const struct brw_tracked_state
*render_atoms
[] =
3859 /* Once all the programs are done, we know how large urb entry
3860 * sizes need to be and can decide if we need to change the urb
3864 &brw_recalculate_urb_fence
,
3869 /* Surface state setup. Must come before the VS/WM unit. The binding
3870 * table upload must be last.
3872 &brw_vs_pull_constants
,
3873 &brw_wm_pull_constants
,
3874 &brw_renderbuffer_surfaces
,
3875 &brw_renderbuffer_read_surfaces
,
3876 &brw_texture_surfaces
,
3877 &brw_vs_binding_table
,
3878 &brw_wm_binding_table
,
3883 /* These set up state for brw_psp_urb_cbs */
3887 &brw_vs_unit
, /* always required, enabled or not */
3893 &brw_invariant_state
,
3895 &brw_binding_table_pointers
,
3896 &brw_blend_constant_color
,
3900 &genX(polygon_stipple
),
3901 &genX(polygon_stipple_offset
),
3903 &genX(line_stipple
),
3907 &genX(drawing_rect
),
3908 &brw_indices
, /* must come before brw_vertices */
3912 &brw_constant_buffer
3915 static const struct brw_tracked_state
*render_atoms
[] =
3917 &genX(sf_clip_viewport
),
3919 /* Command packets: */
3922 &genX(viewport_state
), /* must do after *_vp stages */
3925 &genX(blend_state
), /* must do before cc unit */
3926 &genX(color_calc_state
), /* must do before cc unit */
3927 &genX(depth_stencil_state
), /* must do before cc unit */
3929 &genX(vs_push_constants
), /* Before vs_state */
3930 &genX(gs_push_constants
), /* Before gs_state */
3931 &genX(wm_push_constants
), /* Before wm_state */
3933 /* Surface state setup. Must come before the VS/WM unit. The binding
3934 * table upload must be last.
3936 &brw_vs_pull_constants
,
3937 &brw_vs_ubo_surfaces
,
3938 &brw_gs_pull_constants
,
3939 &brw_gs_ubo_surfaces
,
3940 &brw_wm_pull_constants
,
3941 &brw_wm_ubo_surfaces
,
3942 &gen6_renderbuffer_surfaces
,
3943 &brw_renderbuffer_read_surfaces
,
3944 &brw_texture_surfaces
,
3946 &brw_vs_binding_table
,
3947 &gen6_gs_binding_table
,
3948 &brw_wm_binding_table
,
3953 &gen6_sampler_state
,
3954 &genX(multisample_state
),
3962 &genX(scissor_state
),
3964 &gen6_binding_table_pointers
,
3968 &genX(polygon_stipple
),
3969 &genX(polygon_stipple_offset
),
3971 &genX(line_stipple
),
3973 &genX(drawing_rect
),
3975 &brw_indices
, /* must come before brw_vertices */
3980 static const struct brw_tracked_state
*render_atoms
[] =
3982 /* Command packets: */
3985 &genX(sf_clip_viewport
),
3988 &gen7_push_constant_space
,
3990 &genX(blend_state
), /* must do before cc unit */
3991 &genX(color_calc_state
), /* must do before cc unit */
3992 &genX(depth_stencil_state
), /* must do before cc unit */
3994 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
3995 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
3996 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
3997 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
3998 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
4000 &genX(vs_push_constants
), /* Before vs_state */
4001 &genX(tcs_push_constants
),
4002 &genX(tes_push_constants
),
4003 &genX(gs_push_constants
), /* Before gs_state */
4004 &genX(wm_push_constants
), /* Before wm_surfaces and constant_buffer */
4006 /* Surface state setup. Must come before the VS/WM unit. The binding
4007 * table upload must be last.
4009 &brw_vs_pull_constants
,
4010 &brw_vs_ubo_surfaces
,
4011 &brw_vs_abo_surfaces
,
4012 &brw_tcs_pull_constants
,
4013 &brw_tcs_ubo_surfaces
,
4014 &brw_tcs_abo_surfaces
,
4015 &brw_tes_pull_constants
,
4016 &brw_tes_ubo_surfaces
,
4017 &brw_tes_abo_surfaces
,
4018 &brw_gs_pull_constants
,
4019 &brw_gs_ubo_surfaces
,
4020 &brw_gs_abo_surfaces
,
4021 &brw_wm_pull_constants
,
4022 &brw_wm_ubo_surfaces
,
4023 &brw_wm_abo_surfaces
,
4024 &gen6_renderbuffer_surfaces
,
4025 &brw_renderbuffer_read_surfaces
,
4026 &brw_texture_surfaces
,
4027 &brw_vs_binding_table
,
4028 &brw_tcs_binding_table
,
4029 &brw_tes_binding_table
,
4030 &brw_gs_binding_table
,
4031 &brw_wm_binding_table
,
4038 &genX(multisample_state
),
4052 &genX(scissor_state
),
4056 &genX(polygon_stipple
),
4057 &genX(polygon_stipple_offset
),
4059 &genX(line_stipple
),
4061 &genX(drawing_rect
),
4063 &brw_indices
, /* must come before brw_vertices */
4072 static const struct brw_tracked_state
*render_atoms
[] =
4075 &genX(sf_clip_viewport
),
4078 &gen7_push_constant_space
,
4081 &genX(color_calc_state
),
4083 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
4084 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
4085 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
4086 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
4087 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
4089 &genX(vs_push_constants
), /* Before vs_state */
4090 &genX(tcs_push_constants
),
4091 &genX(tes_push_constants
),
4092 &genX(gs_push_constants
), /* Before gs_state */
4093 &genX(wm_push_constants
), /* Before wm_surfaces and constant_buffer */
4095 /* Surface state setup. Must come before the VS/WM unit. The binding
4096 * table upload must be last.
4098 &brw_vs_pull_constants
,
4099 &brw_vs_ubo_surfaces
,
4100 &brw_vs_abo_surfaces
,
4101 &brw_tcs_pull_constants
,
4102 &brw_tcs_ubo_surfaces
,
4103 &brw_tcs_abo_surfaces
,
4104 &brw_tes_pull_constants
,
4105 &brw_tes_ubo_surfaces
,
4106 &brw_tes_abo_surfaces
,
4107 &brw_gs_pull_constants
,
4108 &brw_gs_ubo_surfaces
,
4109 &brw_gs_abo_surfaces
,
4110 &brw_wm_pull_constants
,
4111 &brw_wm_ubo_surfaces
,
4112 &brw_wm_abo_surfaces
,
4113 &gen6_renderbuffer_surfaces
,
4114 &brw_renderbuffer_read_surfaces
,
4115 &brw_texture_surfaces
,
4116 &brw_vs_binding_table
,
4117 &brw_tcs_binding_table
,
4118 &brw_tes_binding_table
,
4119 &brw_gs_binding_table
,
4120 &brw_wm_binding_table
,
4127 &genX(multisample_state
),
4136 &genX(raster_state
),
4142 &genX(depth_stencil_state
),
4145 &genX(scissor_state
),
4149 &genX(polygon_stipple
),
4150 &genX(polygon_stipple_offset
),
4152 &genX(line_stipple
),
4154 &genX(drawing_rect
),
4167 STATIC_ASSERT(ARRAY_SIZE(render_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
4168 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
4169 render_atoms
, ARRAY_SIZE(render_atoms
));
4172 static const struct brw_tracked_state
*compute_atoms
[] =
4175 &brw_cs_image_surfaces
,
4176 &gen7_cs_push_constants
,
4177 &brw_cs_pull_constants
,
4178 &brw_cs_ubo_surfaces
,
4179 &brw_cs_abo_surfaces
,
4180 &brw_cs_texture_surfaces
,
4181 &brw_cs_work_groups_surface
,
4186 STATIC_ASSERT(ARRAY_SIZE(compute_atoms
) <= ARRAY_SIZE(brw
->compute_atoms
));
4187 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
4188 compute_atoms
, ARRAY_SIZE(compute_atoms
));