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 "dev/gen_device_info.h"
27 #include "common/gen_sample_positions.h"
28 #include "genxml/gen_macros.h"
29 #include "common/gen_guardband.h"
31 #include "main/bufferobj.h"
32 #include "main/context.h"
33 #include "main/enums.h"
34 #include "main/macros.h"
35 #include "main/state.h"
37 #include "genX_boilerplate.h"
39 #include "brw_context.h"
42 #include "brw_multisample_state.h"
43 #include "brw_state.h"
47 #include "intel_batchbuffer.h"
48 #include "intel_buffer_objects.h"
49 #include "intel_fbo.h"
51 #include "main/enums.h"
52 #include "main/fbobject.h"
53 #include "main/framebuffer.h"
54 #include "main/glformats.h"
55 #include "main/samplerobj.h"
56 #include "main/shaderapi.h"
57 #include "main/stencil.h"
58 #include "main/transformfeedback.h"
59 #include "main/varray.h"
60 #include "main/viewport.h"
61 #include "util/half_float.h"
64 static struct brw_address
65 KSP(struct brw_context
*brw
, uint32_t offset
)
67 return ro_bo(brw
->cache
.bo
, offset
);
71 KSP(UNUSED
struct brw_context
*brw
, uint32_t offset
)
79 emit_lrm(struct brw_context
*brw
, uint32_t reg
, struct brw_address addr
)
81 brw_batch_emit(brw
, GENX(MI_LOAD_REGISTER_MEM
), lrm
) {
82 lrm
.RegisterAddress
= reg
;
83 lrm
.MemoryAddress
= addr
;
90 emit_lri(struct brw_context
*brw
, uint32_t reg
, uint32_t imm
)
92 brw_batch_emit(brw
, GENX(MI_LOAD_REGISTER_IMM
), lri
) {
93 lri
.RegisterOffset
= reg
;
100 * Polygon stipple packet
103 genX(upload_polygon_stipple
)(struct brw_context
*brw
)
105 struct gl_context
*ctx
= &brw
->ctx
;
108 if (!ctx
->Polygon
.StippleFlag
)
111 brw_batch_emit(brw
, GENX(3DSTATE_POLY_STIPPLE_PATTERN
), poly
) {
112 /* Polygon stipple is provided in OpenGL order, i.e. bottom
113 * row first. If we're rendering to a window (i.e. the
114 * default frame buffer object, 0), then we need to invert
115 * it to match our pixel layout. But if we're rendering
116 * to a FBO (i.e. any named frame buffer object), we *don't*
117 * need to invert - we already match the layout.
119 if (ctx
->DrawBuffer
->FlipY
) {
120 for (unsigned i
= 0; i
< 32; i
++)
121 poly
.PatternRow
[i
] = ctx
->PolygonStipple
[31 - i
]; /* invert */
123 for (unsigned i
= 0; i
< 32; i
++)
124 poly
.PatternRow
[i
] = ctx
->PolygonStipple
[i
];
129 static const struct brw_tracked_state
genX(polygon_stipple
) = {
131 .mesa
= _NEW_POLYGON
|
133 .brw
= BRW_NEW_CONTEXT
,
135 .emit
= genX(upload_polygon_stipple
),
139 * Polygon stipple offset packet
142 genX(upload_polygon_stipple_offset
)(struct brw_context
*brw
)
144 struct gl_context
*ctx
= &brw
->ctx
;
147 if (!ctx
->Polygon
.StippleFlag
)
150 brw_batch_emit(brw
, GENX(3DSTATE_POLY_STIPPLE_OFFSET
), poly
) {
153 * If we're drawing to a system window we have to invert the Y axis
154 * in order to match the OpenGL pixel coordinate system, and our
155 * offset must be matched to the window position. If we're drawing
156 * to a user-created FBO then our native pixel coordinate system
157 * works just fine, and there's no window system to worry about.
159 if (ctx
->DrawBuffer
->FlipY
) {
160 poly
.PolygonStippleYOffset
=
161 (32 - (_mesa_geometric_height(ctx
->DrawBuffer
) & 31)) & 31;
166 static const struct brw_tracked_state
genX(polygon_stipple_offset
) = {
168 .mesa
= _NEW_BUFFERS
|
170 .brw
= BRW_NEW_CONTEXT
,
172 .emit
= genX(upload_polygon_stipple_offset
),
176 * Line stipple packet
179 genX(upload_line_stipple
)(struct brw_context
*brw
)
181 struct gl_context
*ctx
= &brw
->ctx
;
183 if (!ctx
->Line
.StippleFlag
)
186 brw_batch_emit(brw
, GENX(3DSTATE_LINE_STIPPLE
), line
) {
187 line
.LineStipplePattern
= ctx
->Line
.StipplePattern
;
189 line
.LineStippleInverseRepeatCount
= 1.0f
/ ctx
->Line
.StippleFactor
;
190 line
.LineStippleRepeatCount
= ctx
->Line
.StippleFactor
;
194 static const struct brw_tracked_state
genX(line_stipple
) = {
197 .brw
= BRW_NEW_CONTEXT
,
199 .emit
= genX(upload_line_stipple
),
202 /* Constant single cliprect for framebuffer object or DRI2 drawing */
204 genX(upload_drawing_rect
)(struct brw_context
*brw
)
206 struct gl_context
*ctx
= &brw
->ctx
;
207 const struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
208 const unsigned int fb_width
= _mesa_geometric_width(fb
);
209 const unsigned int fb_height
= _mesa_geometric_height(fb
);
211 brw_batch_emit(brw
, GENX(3DSTATE_DRAWING_RECTANGLE
), rect
) {
212 rect
.ClippedDrawingRectangleXMax
= fb_width
- 1;
213 rect
.ClippedDrawingRectangleYMax
= fb_height
- 1;
217 static const struct brw_tracked_state
genX(drawing_rect
) = {
219 .mesa
= _NEW_BUFFERS
,
220 .brw
= BRW_NEW_BLORP
|
223 .emit
= genX(upload_drawing_rect
),
227 genX(emit_vertex_buffer_state
)(struct brw_context
*brw
,
231 unsigned start_offset
,
232 UNUSED
unsigned end_offset
,
234 UNUSED
unsigned step_rate
)
236 struct GENX(VERTEX_BUFFER_STATE
) buf_state
= {
237 .VertexBufferIndex
= buffer_nr
,
238 .BufferPitch
= stride
,
240 /* The VF cache designers apparently cut corners, and made the cache
241 * only consider the bottom 32 bits of memory addresses. If you happen
242 * to have two vertex buffers which get placed exactly 4 GiB apart and
243 * use them in back-to-back draw calls, you can get collisions. To work
244 * around this problem, we restrict vertex buffers to the low 32 bits of
247 .BufferStartingAddress
= ro_32_bo(bo
, start_offset
),
249 .BufferSize
= end_offset
- start_offset
,
253 .AddressModifyEnable
= true,
257 .BufferAccessType
= step_rate
? INSTANCEDATA
: VERTEXDATA
,
258 .InstanceDataStepRate
= step_rate
,
260 .EndAddress
= ro_bo(bo
, end_offset
- 1),
273 .MOCS
= GEN7_MOCS_L3
,
277 GENX(VERTEX_BUFFER_STATE_pack
)(brw
, dw
, &buf_state
);
278 return dw
+ GENX(VERTEX_BUFFER_STATE_length
);
282 is_passthru_format(uint32_t format
)
285 case ISL_FORMAT_R64_PASSTHRU
:
286 case ISL_FORMAT_R64G64_PASSTHRU
:
287 case ISL_FORMAT_R64G64B64_PASSTHRU
:
288 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
296 uploads_needed(uint32_t format
,
299 if (!is_passthru_format(format
))
306 case ISL_FORMAT_R64_PASSTHRU
:
307 case ISL_FORMAT_R64G64_PASSTHRU
:
309 case ISL_FORMAT_R64G64B64_PASSTHRU
:
310 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
313 unreachable("not reached");
318 * Returns the format that we are finally going to use when upload a vertex
319 * element. It will only change if we are using *64*PASSTHRU formats, as for
320 * gen < 8 they need to be splitted on two *32*FLOAT formats.
322 * @upload points in which upload we are. Valid values are [0,1]
325 downsize_format_if_needed(uint32_t format
,
328 assert(upload
== 0 || upload
== 1);
330 if (!is_passthru_format(format
))
333 /* ISL_FORMAT_R64_PASSTHRU and ISL_FORMAT_R64G64_PASSTHRU with an upload ==
334 * 1 means that we have been forced to do 2 uploads for a size <= 2. This
335 * happens with gen < 8 and dvec3 or dvec4 vertex shader input
336 * variables. In those cases, we return ISL_FORMAT_R32_FLOAT as a way of
337 * flagging that we want to fill with zeroes this second forced upload.
340 case ISL_FORMAT_R64_PASSTHRU
:
341 return upload
== 0 ? ISL_FORMAT_R32G32_FLOAT
342 : ISL_FORMAT_R32_FLOAT
;
343 case ISL_FORMAT_R64G64_PASSTHRU
:
344 return upload
== 0 ? ISL_FORMAT_R32G32B32A32_FLOAT
345 : ISL_FORMAT_R32_FLOAT
;
346 case ISL_FORMAT_R64G64B64_PASSTHRU
:
347 return upload
== 0 ? ISL_FORMAT_R32G32B32A32_FLOAT
348 : ISL_FORMAT_R32G32_FLOAT
;
349 case ISL_FORMAT_R64G64B64A64_PASSTHRU
:
350 return ISL_FORMAT_R32G32B32A32_FLOAT
;
352 unreachable("not reached");
357 * Returns the number of componentes associated with a format that is used on
358 * a 64 to 32 format split. See downsize_format()
361 upload_format_size(uint32_t upload_format
)
363 switch (upload_format
) {
364 case ISL_FORMAT_R32_FLOAT
:
366 /* downsized_format has returned this one in order to flag that we are
367 * performing a second upload which we want to have filled with
368 * zeroes. This happens with gen < 8, a size <= 2, and dvec3 or dvec4
369 * vertex shader input variables.
373 case ISL_FORMAT_R32G32_FLOAT
:
375 case ISL_FORMAT_R32G32B32A32_FLOAT
:
378 unreachable("not reached");
382 static UNUSED
uint16_t
383 pinned_bo_high_bits(struct brw_bo
*bo
)
385 return (bo
->kflags
& EXEC_OBJECT_PINNED
) ? bo
->gtt_offset
>> 32ull : 0;
388 /* The VF cache designers apparently cut corners, and made the cache key's
389 * <VertexBufferIndex, Memory Address> tuple only consider the bottom 32 bits
390 * of the address. If you happen to have two vertex buffers which get placed
391 * exactly 4 GiB apart and use them in back-to-back draw calls, you can get
392 * collisions. (These collisions can happen within a single batch.)
394 * In the soft-pin world, we'd like to assign addresses up front, and never
395 * move buffers. So, we need to do a VF cache invalidate if the buffer for
396 * a particular VB slot has different [48:32] address bits than the last one.
398 * In the relocation world, we have no idea what the addresses will be, so
399 * we can't apply this workaround. Instead, we tell the kernel to move it
400 * to the low 4GB regardless.
402 * This HW issue is gone on Gen11+.
405 vf_invalidate_for_vb_48bit_transitions(struct brw_context
*brw
)
407 #if GEN_GEN >= 8 && GEN_GEN < 11
408 bool need_invalidate
= false;
410 for (unsigned i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
411 uint16_t high_bits
= pinned_bo_high_bits(brw
->vb
.buffers
[i
].bo
);
413 if (high_bits
!= brw
->vb
.last_bo_high_bits
[i
]) {
414 need_invalidate
= true;
415 brw
->vb
.last_bo_high_bits
[i
] = high_bits
;
419 if (brw
->draw
.draw_params_bo
) {
420 uint16_t high_bits
= pinned_bo_high_bits(brw
->draw
.draw_params_bo
);
422 if (brw
->vb
.last_bo_high_bits
[brw
->vb
.nr_buffers
] != high_bits
) {
423 need_invalidate
= true;
424 brw
->vb
.last_bo_high_bits
[brw
->vb
.nr_buffers
] = high_bits
;
428 if (brw
->draw
.derived_draw_params_bo
) {
429 uint16_t high_bits
= pinned_bo_high_bits(brw
->draw
.derived_draw_params_bo
);
431 if (brw
->vb
.last_bo_high_bits
[brw
->vb
.nr_buffers
+ 1] != high_bits
) {
432 need_invalidate
= true;
433 brw
->vb
.last_bo_high_bits
[brw
->vb
.nr_buffers
+ 1] = high_bits
;
437 if (need_invalidate
) {
438 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_VF_CACHE_INVALIDATE
| PIPE_CONTROL_CS_STALL
);
444 vf_invalidate_for_ib_48bit_transition(struct brw_context
*brw
)
447 uint16_t high_bits
= pinned_bo_high_bits(brw
->ib
.bo
);
449 if (high_bits
!= brw
->ib
.last_bo_high_bits
) {
450 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_VF_CACHE_INVALIDATE
);
451 brw
->ib
.last_bo_high_bits
= high_bits
;
457 genX(emit_vertices
)(struct brw_context
*brw
)
459 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
462 brw_prepare_vertices(brw
);
463 brw_prepare_shader_draw_parameters(brw
);
466 brw_emit_query_begin(brw
);
469 const struct brw_vs_prog_data
*vs_prog_data
=
470 brw_vs_prog_data(brw
->vs
.base
.prog_data
);
473 struct gl_context
*ctx
= &brw
->ctx
;
474 const bool uses_edge_flag
= (ctx
->Polygon
.FrontMode
!= GL_FILL
||
475 ctx
->Polygon
.BackMode
!= GL_FILL
);
477 if (vs_prog_data
->uses_vertexid
|| vs_prog_data
->uses_instanceid
) {
478 unsigned vue
= brw
->vb
.nr_enabled
;
480 /* The element for the edge flags must always be last, so we have to
481 * insert the SGVS before it in that case.
483 if (uses_edge_flag
) {
489 "Trying to insert VID/IID past 33rd vertex element, "
490 "need to reorder the vertex attrbutes.");
492 brw_batch_emit(brw
, GENX(3DSTATE_VF_SGVS
), vfs
) {
493 if (vs_prog_data
->uses_vertexid
) {
494 vfs
.VertexIDEnable
= true;
495 vfs
.VertexIDComponentNumber
= 2;
496 vfs
.VertexIDElementOffset
= vue
;
499 if (vs_prog_data
->uses_instanceid
) {
500 vfs
.InstanceIDEnable
= true;
501 vfs
.InstanceIDComponentNumber
= 3;
502 vfs
.InstanceIDElementOffset
= vue
;
506 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
507 vfi
.InstancingEnable
= true;
508 vfi
.VertexElementIndex
= vue
;
511 brw_batch_emit(brw
, GENX(3DSTATE_VF_SGVS
), vfs
);
515 const bool uses_draw_params
=
516 vs_prog_data
->uses_firstvertex
||
517 vs_prog_data
->uses_baseinstance
;
519 const bool uses_derived_draw_params
=
520 vs_prog_data
->uses_drawid
||
521 vs_prog_data
->uses_is_indexed_draw
;
523 const bool needs_sgvs_element
= (uses_draw_params
||
524 vs_prog_data
->uses_instanceid
||
525 vs_prog_data
->uses_vertexid
);
527 unsigned nr_elements
=
528 brw
->vb
.nr_enabled
+ needs_sgvs_element
+ uses_derived_draw_params
;
531 /* If any of the formats of vb.enabled needs more that one upload, we need
532 * to add it to nr_elements
534 for (unsigned i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
535 struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
536 uint32_t format
= brw_get_vertex_surface_type(brw
, input
->glformat
);
538 if (uploads_needed(format
, input
->is_dual_slot
) > 1)
543 /* If the VS doesn't read any inputs (calculating vertex position from
544 * a state variable for some reason, for example), emit a single pad
545 * VERTEX_ELEMENT struct and bail.
547 * The stale VB state stays in place, but they don't do anything unless
548 * a VE loads from them.
550 if (nr_elements
== 0) {
551 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_ELEMENTS
),
552 1 + GENX(VERTEX_ELEMENT_STATE_length
));
553 struct GENX(VERTEX_ELEMENT_STATE
) elem
= {
555 .SourceElementFormat
= ISL_FORMAT_R32G32B32A32_FLOAT
,
556 .Component0Control
= VFCOMP_STORE_0
,
557 .Component1Control
= VFCOMP_STORE_0
,
558 .Component2Control
= VFCOMP_STORE_0
,
559 .Component3Control
= VFCOMP_STORE_1_FP
,
561 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem
);
565 /* Now emit 3DSTATE_VERTEX_BUFFERS and 3DSTATE_VERTEX_ELEMENTS packets. */
566 const unsigned nr_buffers
= brw
->vb
.nr_buffers
+
567 uses_draw_params
+ uses_derived_draw_params
;
569 vf_invalidate_for_vb_48bit_transitions(brw
);
572 assert(nr_buffers
<= (GEN_GEN
>= 6 ? 33 : 17));
574 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_BUFFERS
),
575 1 + GENX(VERTEX_BUFFER_STATE_length
) * nr_buffers
);
577 for (unsigned i
= 0; i
< brw
->vb
.nr_buffers
; i
++) {
578 const struct brw_vertex_buffer
*buffer
= &brw
->vb
.buffers
[i
];
579 /* Prior to Haswell and Bay Trail we have to use 4-component formats
580 * to fake 3-component ones. In particular, we do this for
581 * half-float and 8 and 16-bit integer formats. This means that the
582 * vertex element may poke over the end of the buffer by 2 bytes.
584 const unsigned padding
=
585 (GEN_GEN
<= 7 && !GEN_IS_HASWELL
&& !devinfo
->is_baytrail
) * 2;
586 const unsigned end
= buffer
->offset
+ buffer
->size
+ padding
;
587 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, i
, buffer
->bo
,
594 if (uses_draw_params
) {
595 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, brw
->vb
.nr_buffers
,
596 brw
->draw
.draw_params_bo
,
597 brw
->draw
.draw_params_offset
,
598 brw
->draw
.draw_params_bo
->size
,
603 if (uses_derived_draw_params
) {
604 dw
= genX(emit_vertex_buffer_state
)(brw
, dw
, brw
->vb
.nr_buffers
+ 1,
605 brw
->draw
.derived_draw_params_bo
,
606 brw
->draw
.derived_draw_params_offset
,
607 brw
->draw
.derived_draw_params_bo
->size
,
613 /* The hardware allows one more VERTEX_ELEMENTS than VERTEX_BUFFERS,
614 * presumably for VertexID/InstanceID.
617 assert(nr_elements
<= 34);
618 const struct brw_vertex_element
*gen6_edgeflag_input
= NULL
;
620 assert(nr_elements
<= 18);
623 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_VERTEX_ELEMENTS
),
624 1 + GENX(VERTEX_ELEMENT_STATE_length
) * nr_elements
);
626 for (i
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
627 const struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
628 const struct gl_vertex_format
*glformat
= input
->glformat
;
629 uint32_t format
= brw_get_vertex_surface_type(brw
, glformat
);
630 uint32_t comp0
= VFCOMP_STORE_SRC
;
631 uint32_t comp1
= VFCOMP_STORE_SRC
;
632 uint32_t comp2
= VFCOMP_STORE_SRC
;
633 uint32_t comp3
= VFCOMP_STORE_SRC
;
634 const unsigned num_uploads
= GEN_GEN
< 8 ?
635 uploads_needed(format
, input
->is_dual_slot
) : 1;
638 /* From the BDW PRM, Volume 2d, page 588 (VERTEX_ELEMENT_STATE):
639 * "Any SourceElementFormat of *64*_PASSTHRU cannot be used with an
640 * element which has edge flag enabled."
642 assert(!(is_passthru_format(format
) && uses_edge_flag
));
645 /* The gen4 driver expects edgeflag to come in as a float, and passes
646 * that float on to the tests in the clipper. Mesa's current vertex
647 * attribute value for EdgeFlag is stored as a float, which works out.
648 * glEdgeFlagPointer, on the other hand, gives us an unnormalized
649 * integer ubyte. Just rewrite that to convert to a float.
651 * Gen6+ passes edgeflag as sideband along with the vertex, instead
652 * of in the VUE. We have to upload it sideband as the last vertex
653 * element according to the B-Spec.
656 if (input
== &brw
->vb
.inputs
[VERT_ATTRIB_EDGEFLAG
]) {
657 gen6_edgeflag_input
= input
;
662 for (unsigned c
= 0; c
< num_uploads
; c
++) {
663 const uint32_t upload_format
= GEN_GEN
>= 8 ? format
:
664 downsize_format_if_needed(format
, c
);
665 /* If we need more that one upload, the offset stride would be 128
666 * bits (16 bytes), as for previous uploads we are using the full
668 const unsigned offset
= input
->offset
+ c
* 16;
670 const int size
= (GEN_GEN
< 8 && is_passthru_format(format
)) ?
671 upload_format_size(upload_format
) : glformat
->Size
;
674 case 0: comp0
= VFCOMP_STORE_0
; /* fallthrough */
675 case 1: comp1
= VFCOMP_STORE_0
; /* fallthrough */
676 case 2: comp2
= VFCOMP_STORE_0
; /* fallthrough */
678 if (GEN_GEN
>= 8 && glformat
->Doubles
) {
679 comp3
= VFCOMP_STORE_0
;
680 } else if (glformat
->Integer
) {
681 comp3
= VFCOMP_STORE_1_INT
;
683 comp3
= VFCOMP_STORE_1_FP
;
690 /* From the BDW PRM, Volume 2d, page 586 (VERTEX_ELEMENT_STATE):
692 * "When SourceElementFormat is set to one of the *64*_PASSTHRU
693 * formats, 64-bit components are stored in the URB without any
694 * conversion. In this case, vertex elements must be written as 128
695 * or 256 bits, with VFCOMP_STORE_0 being used to pad the output as
696 * required. E.g., if R64_PASSTHRU is used to copy a 64-bit Red
697 * component into the URB, Component 1 must be specified as
698 * VFCOMP_STORE_0 (with Components 2,3 set to VFCOMP_NOSTORE) in
699 * order to output a 128-bit vertex element, or Components 1-3 must
700 * be specified as VFCOMP_STORE_0 in order to output a 256-bit vertex
701 * element. Likewise, use of R64G64B64_PASSTHRU requires Component 3
702 * to be specified as VFCOMP_STORE_0 in order to output a 256-bit
705 if (glformat
->Doubles
&& !input
->is_dual_slot
) {
706 /* Store vertex elements which correspond to double and dvec2 vertex
707 * shader inputs as 128-bit vertex elements, instead of 256-bits.
709 comp2
= VFCOMP_NOSTORE
;
710 comp3
= VFCOMP_NOSTORE
;
714 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
715 .VertexBufferIndex
= input
->buffer
,
717 .SourceElementFormat
= upload_format
,
718 .SourceElementOffset
= offset
,
719 .Component0Control
= comp0
,
720 .Component1Control
= comp1
,
721 .Component2Control
= comp2
,
722 .Component3Control
= comp3
,
724 .DestinationElementOffset
= i
* 4,
728 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
729 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
733 if (needs_sgvs_element
) {
734 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
736 .Component0Control
= VFCOMP_STORE_0
,
737 .Component1Control
= VFCOMP_STORE_0
,
738 .Component2Control
= VFCOMP_STORE_0
,
739 .Component3Control
= VFCOMP_STORE_0
,
741 .DestinationElementOffset
= i
* 4,
746 if (uses_draw_params
) {
747 elem_state
.VertexBufferIndex
= brw
->vb
.nr_buffers
;
748 elem_state
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
749 elem_state
.Component0Control
= VFCOMP_STORE_SRC
;
750 elem_state
.Component1Control
= VFCOMP_STORE_SRC
;
753 elem_state
.VertexBufferIndex
= brw
->vb
.nr_buffers
;
754 elem_state
.SourceElementFormat
= ISL_FORMAT_R32G32_UINT
;
755 if (uses_draw_params
) {
756 elem_state
.Component0Control
= VFCOMP_STORE_SRC
;
757 elem_state
.Component1Control
= VFCOMP_STORE_SRC
;
760 if (vs_prog_data
->uses_vertexid
)
761 elem_state
.Component2Control
= VFCOMP_STORE_VID
;
763 if (vs_prog_data
->uses_instanceid
)
764 elem_state
.Component3Control
= VFCOMP_STORE_IID
;
767 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
768 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
771 if (uses_derived_draw_params
) {
772 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
774 .VertexBufferIndex
= brw
->vb
.nr_buffers
+ 1,
775 .SourceElementFormat
= ISL_FORMAT_R32G32_UINT
,
776 .Component0Control
= VFCOMP_STORE_SRC
,
777 .Component1Control
= VFCOMP_STORE_SRC
,
778 .Component2Control
= VFCOMP_STORE_0
,
779 .Component3Control
= VFCOMP_STORE_0
,
781 .DestinationElementOffset
= i
* 4,
785 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
786 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
790 if (gen6_edgeflag_input
) {
791 const struct gl_vertex_format
*glformat
= gen6_edgeflag_input
->glformat
;
792 const uint32_t format
= brw_get_vertex_surface_type(brw
, glformat
);
794 struct GENX(VERTEX_ELEMENT_STATE
) elem_state
= {
796 .VertexBufferIndex
= gen6_edgeflag_input
->buffer
,
797 .EdgeFlagEnable
= true,
798 .SourceElementFormat
= format
,
799 .SourceElementOffset
= gen6_edgeflag_input
->offset
,
800 .Component0Control
= VFCOMP_STORE_SRC
,
801 .Component1Control
= VFCOMP_STORE_0
,
802 .Component2Control
= VFCOMP_STORE_0
,
803 .Component3Control
= VFCOMP_STORE_0
,
806 GENX(VERTEX_ELEMENT_STATE_pack
)(brw
, dw
, &elem_state
);
807 dw
+= GENX(VERTEX_ELEMENT_STATE_length
);
812 for (unsigned i
= 0, j
= 0; i
< brw
->vb
.nr_enabled
; i
++) {
813 const struct brw_vertex_element
*input
= brw
->vb
.enabled
[i
];
814 const struct brw_vertex_buffer
*buffer
= &brw
->vb
.buffers
[input
->buffer
];
815 unsigned element_index
;
817 /* The edge flag element is reordered to be the last one in the code
818 * above so we need to compensate for that in the element indices used
821 if (input
== gen6_edgeflag_input
)
822 element_index
= nr_elements
- 1;
826 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
827 vfi
.VertexElementIndex
= element_index
;
828 vfi
.InstancingEnable
= buffer
->step_rate
!= 0;
829 vfi
.InstanceDataStepRate
= buffer
->step_rate
;
833 if (vs_prog_data
->uses_drawid
) {
834 const unsigned element
= brw
->vb
.nr_enabled
+ needs_sgvs_element
;
836 brw_batch_emit(brw
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
837 vfi
.VertexElementIndex
= element
;
843 static const struct brw_tracked_state
genX(vertices
) = {
845 .mesa
= _NEW_POLYGON
,
846 .brw
= BRW_NEW_BATCH
|
848 BRW_NEW_VERTEX_PROGRAM
|
850 BRW_NEW_VS_PROG_DATA
,
852 .emit
= genX(emit_vertices
),
856 genX(emit_index_buffer
)(struct brw_context
*brw
)
858 const struct _mesa_index_buffer
*index_buffer
= brw
->ib
.ib
;
860 if (index_buffer
== NULL
)
863 vf_invalidate_for_ib_48bit_transition(brw
);
865 brw_batch_emit(brw
, GENX(3DSTATE_INDEX_BUFFER
), ib
) {
866 #if GEN_GEN < 8 && !GEN_IS_HASWELL
867 assert(brw
->ib
.enable_cut_index
== brw
->prim_restart
.enable_cut_index
);
868 ib
.CutIndexEnable
= brw
->ib
.enable_cut_index
;
870 ib
.IndexFormat
= brw_get_index_type(1 << index_buffer
->index_size_shift
);
872 /* The VF cache designers apparently cut corners, and made the cache
873 * only consider the bottom 32 bits of memory addresses. If you happen
874 * to have two index buffers which get placed exactly 4 GiB apart and
875 * use them in back-to-back draw calls, you can get collisions. To work
876 * around this problem, we restrict index buffers to the low 32 bits of
879 ib
.BufferStartingAddress
= ro_32_bo(brw
->ib
.bo
, 0);
881 ib
.MOCS
= GEN_GEN
>= 9 ? SKL_MOCS_WB
: BDW_MOCS_WB
;
882 ib
.BufferSize
= brw
->ib
.size
;
884 ib
.BufferEndingAddress
= ro_bo(brw
->ib
.bo
, brw
->ib
.size
- 1);
889 static const struct brw_tracked_state
genX(index_buffer
) = {
892 .brw
= BRW_NEW_BATCH
|
894 BRW_NEW_INDEX_BUFFER
,
896 .emit
= genX(emit_index_buffer
),
899 #if GEN_IS_HASWELL || GEN_GEN >= 8
901 genX(upload_cut_index
)(struct brw_context
*brw
)
903 const struct gl_context
*ctx
= &brw
->ctx
;
905 brw_batch_emit(brw
, GENX(3DSTATE_VF
), vf
) {
906 if (ctx
->Array
._PrimitiveRestart
&& brw
->ib
.ib
) {
907 vf
.IndexedDrawCutIndexEnable
= true;
908 vf
.CutIndex
= ctx
->Array
._RestartIndex
[brw
->ib
.index_size
- 1];
913 const struct brw_tracked_state
genX(cut_index
) = {
915 .mesa
= _NEW_TRANSFORM
,
916 .brw
= BRW_NEW_INDEX_BUFFER
,
918 .emit
= genX(upload_cut_index
),
923 genX(upload_vf_statistics
)(struct brw_context
*brw
)
925 brw_batch_emit(brw
, GENX(3DSTATE_VF_STATISTICS
), vf
) {
926 vf
.StatisticsEnable
= true;
930 const struct brw_tracked_state
genX(vf_statistics
) = {
933 .brw
= BRW_NEW_BLORP
| BRW_NEW_CONTEXT
,
935 .emit
= genX(upload_vf_statistics
),
940 * Determine the appropriate attribute override value to store into the
941 * 3DSTATE_SF structure for a given fragment shader attribute. The attribute
942 * override value contains two pieces of information: the location of the
943 * attribute in the VUE (relative to urb_entry_read_offset, see below), and a
944 * flag indicating whether to "swizzle" the attribute based on the direction
945 * the triangle is facing.
947 * If an attribute is "swizzled", then the given VUE location is used for
948 * front-facing triangles, and the VUE location that immediately follows is
949 * used for back-facing triangles. We use this to implement the mapping from
950 * gl_FrontColor/gl_BackColor to gl_Color.
952 * urb_entry_read_offset is the offset into the VUE at which the SF unit is
953 * being instructed to begin reading attribute data. It can be set to a
954 * nonzero value to prevent the SF unit from wasting time reading elements of
955 * the VUE that are not needed by the fragment shader. It is measured in
956 * 256-bit increments.
959 genX(get_attr_override
)(struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
,
960 const struct brw_vue_map
*vue_map
,
961 int urb_entry_read_offset
, int fs_attr
,
962 bool two_side_color
, uint32_t *max_source_attr
)
964 /* Find the VUE slot for this attribute. */
965 int slot
= vue_map
->varying_to_slot
[fs_attr
];
967 /* Viewport and Layer are stored in the VUE header. We need to override
968 * them to zero if earlier stages didn't write them, as GL requires that
969 * they read back as zero when not explicitly set.
971 if (fs_attr
== VARYING_SLOT_VIEWPORT
|| fs_attr
== VARYING_SLOT_LAYER
) {
972 attr
->ComponentOverrideX
= true;
973 attr
->ComponentOverrideW
= true;
974 attr
->ConstantSource
= CONST_0000
;
976 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
977 attr
->ComponentOverrideY
= true;
978 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
979 attr
->ComponentOverrideZ
= true;
984 /* If there was only a back color written but not front, use back
985 * as the color instead of undefined
987 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
988 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
989 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
990 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
993 /* This attribute does not exist in the VUE--that means that the vertex
994 * shader did not write to it. This means that either:
996 * (a) This attribute is a texture coordinate, and it is going to be
997 * replaced with point coordinates (as a consequence of a call to
998 * glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)), so the
999 * hardware will ignore whatever attribute override we supply.
1001 * (b) This attribute is read by the fragment shader but not written by
1002 * the vertex shader, so its value is undefined. Therefore the
1003 * attribute override we supply doesn't matter.
1005 * (c) This attribute is gl_PrimitiveID, and it wasn't written by the
1006 * previous shader stage.
1008 * Note that we don't have to worry about the cases where the attribute
1009 * is gl_PointCoord or is undergoing point sprite coordinate
1010 * replacement, because in those cases, this function isn't called.
1012 * In case (c), we need to program the attribute overrides so that the
1013 * primitive ID will be stored in this slot. In every other case, the
1014 * attribute override we supply doesn't matter. So just go ahead and
1015 * program primitive ID in every case.
1017 attr
->ComponentOverrideW
= true;
1018 attr
->ComponentOverrideX
= true;
1019 attr
->ComponentOverrideY
= true;
1020 attr
->ComponentOverrideZ
= true;
1021 attr
->ConstantSource
= PRIM_ID
;
1025 /* Compute the location of the attribute relative to urb_entry_read_offset.
1026 * Each increment of urb_entry_read_offset represents a 256-bit value, so
1027 * it counts for two 128-bit VUE slots.
1029 int source_attr
= slot
- 2 * urb_entry_read_offset
;
1030 assert(source_attr
>= 0 && source_attr
< 32);
1032 /* If we are doing two-sided color, and the VUE slot following this one
1033 * represents a back-facing color, then we need to instruct the SF unit to
1034 * do back-facing swizzling.
1036 bool swizzling
= two_side_color
&&
1037 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
1038 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
1039 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
1040 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
));
1042 /* Update max_source_attr. If swizzling, the SF will read this slot + 1. */
1043 if (*max_source_attr
< source_attr
+ swizzling
)
1044 *max_source_attr
= source_attr
+ swizzling
;
1046 attr
->SourceAttribute
= source_attr
;
1048 attr
->SwizzleSelect
= INPUTATTR_FACING
;
1053 genX(calculate_attr_overrides
)(const struct brw_context
*brw
,
1054 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr_overrides
,
1055 uint32_t *point_sprite_enables
,
1056 uint32_t *urb_entry_read_length
,
1057 uint32_t *urb_entry_read_offset
)
1059 const struct gl_context
*ctx
= &brw
->ctx
;
1062 const struct gl_point_attrib
*point
= &ctx
->Point
;
1064 /* BRW_NEW_FRAGMENT_PROGRAM */
1065 const struct gl_program
*fp
= brw
->programs
[MESA_SHADER_FRAGMENT
];
1067 /* BRW_NEW_FS_PROG_DATA */
1068 const struct brw_wm_prog_data
*wm_prog_data
=
1069 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1070 uint32_t max_source_attr
= 0;
1072 *point_sprite_enables
= 0;
1075 brw_compute_first_urb_slot_required(fp
->info
.inputs_read
,
1076 &brw
->vue_map_geom_out
);
1078 /* Each URB offset packs two varying slots */
1079 assert(first_slot
% 2 == 0);
1080 *urb_entry_read_offset
= first_slot
/ 2;
1082 /* From the Ivybridge PRM, Vol 2 Part 1, 3DSTATE_SBE,
1083 * description of dw10 Point Sprite Texture Coordinate Enable:
1085 * "This field must be programmed to zero when non-point primitives
1088 * The SandyBridge PRM doesn't explicitly say that point sprite enables
1089 * must be programmed to zero when rendering non-point primitives, but
1090 * the IvyBridge PRM does, and if we don't, we get garbage.
1092 * This is not required on Haswell, as the hardware ignores this state
1093 * when drawing non-points -- although we do still need to be careful to
1094 * correctly set the attr overrides.
1097 * BRW_NEW_PRIMITIVE | BRW_NEW_GS_PROG_DATA | BRW_NEW_TES_PROG_DATA
1099 bool drawing_points
= brw_is_drawing_points(brw
);
1101 for (uint8_t idx
= 0; idx
< wm_prog_data
->urb_setup_attribs_count
; idx
++) {
1102 uint8_t attr
= wm_prog_data
->urb_setup_attribs
[idx
];
1103 int input_index
= wm_prog_data
->urb_setup
[attr
];
1105 assert(0 <= input_index
);
1108 bool point_sprite
= false;
1109 if (drawing_points
) {
1110 if (point
->PointSprite
&&
1111 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) &&
1112 (point
->CoordReplace
& (1u << (attr
- VARYING_SLOT_TEX0
)))) {
1113 point_sprite
= true;
1116 if (attr
== VARYING_SLOT_PNTC
)
1117 point_sprite
= true;
1120 *point_sprite_enables
|= (1 << input_index
);
1123 /* BRW_NEW_VUE_MAP_GEOM_OUT | _NEW_LIGHT | _NEW_PROGRAM */
1124 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attribute
= { 0 };
1126 if (!point_sprite
) {
1127 genX(get_attr_override
)(&attribute
,
1128 &brw
->vue_map_geom_out
,
1129 *urb_entry_read_offset
, attr
,
1130 _mesa_vertex_program_two_side_enabled(ctx
),
1134 /* The hardware can only do the overrides on 16 overrides at a
1135 * time, and the other up to 16 have to be lined up so that the
1136 * input index = the output index. We'll need to do some
1137 * tweaking to make sure that's the case.
1139 if (input_index
< 16)
1140 attr_overrides
[input_index
] = attribute
;
1142 assert(attribute
.SourceAttribute
== input_index
);
1145 /* From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
1146 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
1148 * "This field should be set to the minimum length required to read the
1149 * maximum source attribute. The maximum source attribute is indicated
1150 * by the maximum value of the enabled Attribute # Source Attribute if
1151 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
1152 * enable is not set.
1153 * read_length = ceiling((max_source_attr + 1) / 2)
1155 * [errata] Corruption/Hang possible if length programmed larger than
1158 * Similar text exists for Ivy Bridge.
1160 *urb_entry_read_length
= DIV_ROUND_UP(max_source_attr
+ 1, 2);
1164 /* ---------------------------------------------------------------------- */
1167 typedef struct GENX(3DSTATE_WM_DEPTH_STENCIL
) DEPTH_STENCIL_GENXML
;
1169 typedef struct GENX(DEPTH_STENCIL_STATE
) DEPTH_STENCIL_GENXML
;
1171 typedef struct GENX(COLOR_CALC_STATE
) DEPTH_STENCIL_GENXML
;
1175 set_depth_stencil_bits(struct brw_context
*brw
, DEPTH_STENCIL_GENXML
*ds
)
1177 struct gl_context
*ctx
= &brw
->ctx
;
1180 struct intel_renderbuffer
*depth_irb
=
1181 intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
1184 struct gl_depthbuffer_attrib
*depth
= &ctx
->Depth
;
1187 struct gl_stencil_attrib
*stencil
= &ctx
->Stencil
;
1188 const int b
= stencil
->_BackFace
;
1190 if (depth
->Test
&& depth_irb
) {
1191 ds
->DepthTestEnable
= true;
1192 ds
->DepthBufferWriteEnable
= brw_depth_writes_enabled(brw
);
1193 ds
->DepthTestFunction
= intel_translate_compare_func(depth
->Func
);
1196 if (brw
->stencil_enabled
) {
1197 ds
->StencilTestEnable
= true;
1198 ds
->StencilWriteMask
= stencil
->WriteMask
[0] & 0xff;
1199 ds
->StencilTestMask
= stencil
->ValueMask
[0] & 0xff;
1201 ds
->StencilTestFunction
=
1202 intel_translate_compare_func(stencil
->Function
[0]);
1204 intel_translate_stencil_op(stencil
->FailFunc
[0]);
1205 ds
->StencilPassDepthPassOp
=
1206 intel_translate_stencil_op(stencil
->ZPassFunc
[0]);
1207 ds
->StencilPassDepthFailOp
=
1208 intel_translate_stencil_op(stencil
->ZFailFunc
[0]);
1210 ds
->StencilBufferWriteEnable
= brw
->stencil_write_enabled
;
1212 if (brw
->stencil_two_sided
) {
1213 ds
->DoubleSidedStencilEnable
= true;
1214 ds
->BackfaceStencilWriteMask
= stencil
->WriteMask
[b
] & 0xff;
1215 ds
->BackfaceStencilTestMask
= stencil
->ValueMask
[b
] & 0xff;
1217 ds
->BackfaceStencilTestFunction
=
1218 intel_translate_compare_func(stencil
->Function
[b
]);
1219 ds
->BackfaceStencilFailOp
=
1220 intel_translate_stencil_op(stencil
->FailFunc
[b
]);
1221 ds
->BackfaceStencilPassDepthPassOp
=
1222 intel_translate_stencil_op(stencil
->ZPassFunc
[b
]);
1223 ds
->BackfaceStencilPassDepthFailOp
=
1224 intel_translate_stencil_op(stencil
->ZFailFunc
[b
]);
1227 #if GEN_GEN <= 5 || GEN_GEN >= 9
1228 ds
->StencilReferenceValue
= _mesa_get_stencil_ref(ctx
, 0);
1229 ds
->BackfaceStencilReferenceValue
= _mesa_get_stencil_ref(ctx
, b
);
1236 genX(upload_depth_stencil_state
)(struct brw_context
*brw
)
1239 brw_batch_emit(brw
, GENX(3DSTATE_WM_DEPTH_STENCIL
), wmds
) {
1240 set_depth_stencil_bits(brw
, &wmds
);
1244 brw_state_emit(brw
, GENX(DEPTH_STENCIL_STATE
), 64, &ds_offset
, ds
) {
1245 set_depth_stencil_bits(brw
, &ds
);
1248 /* Now upload a pointer to the indirect state */
1250 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
1251 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
1252 ptr
.DEPTH_STENCIL_STATEChange
= true;
1255 brw_batch_emit(brw
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), ptr
) {
1256 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
1262 static const struct brw_tracked_state
genX(depth_stencil_state
) = {
1264 .mesa
= _NEW_BUFFERS
|
1267 .brw
= BRW_NEW_BLORP
|
1268 (GEN_GEN
>= 8 ? BRW_NEW_CONTEXT
1270 BRW_NEW_STATE_BASE_ADDRESS
),
1272 .emit
= genX(upload_depth_stencil_state
),
1276 /* ---------------------------------------------------------------------- */
1281 genX(upload_clip_state
)(struct brw_context
*brw
)
1283 struct gl_context
*ctx
= &brw
->ctx
;
1285 ctx
->NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
1286 brw_state_emit(brw
, GENX(CLIP_STATE
), 32, &brw
->clip
.state_offset
, clip
) {
1287 clip
.KernelStartPointer
= KSP(brw
, brw
->clip
.prog_offset
);
1288 clip
.GRFRegisterCount
=
1289 DIV_ROUND_UP(brw
->clip
.prog_data
->total_grf
, 16) - 1;
1290 clip
.FloatingPointMode
= FLOATING_POINT_MODE_Alternate
;
1291 clip
.SingleProgramFlow
= true;
1292 clip
.VertexURBEntryReadLength
= brw
->clip
.prog_data
->urb_read_length
;
1293 clip
.ConstantURBEntryReadLength
= brw
->clip
.prog_data
->curb_read_length
;
1295 /* BRW_NEW_PUSH_CONSTANT_ALLOCATION */
1296 clip
.ConstantURBEntryReadOffset
= brw
->curbe
.clip_start
* 2;
1297 clip
.DispatchGRFStartRegisterForURBData
= 1;
1298 clip
.VertexURBEntryReadOffset
= 0;
1300 /* BRW_NEW_URB_FENCE */
1301 clip
.NumberofURBEntries
= brw
->urb
.nr_clip_entries
;
1302 clip
.URBEntryAllocationSize
= brw
->urb
.vsize
- 1;
1304 if (brw
->urb
.nr_clip_entries
>= 10) {
1305 /* Half of the URB entries go to each thread, and it has to be an
1308 assert(brw
->urb
.nr_clip_entries
% 2 == 0);
1310 /* Although up to 16 concurrent Clip threads are allowed on Ironlake,
1311 * only 2 threads can output VUEs at a time.
1313 clip
.MaximumNumberofThreads
= (GEN_GEN
== 5 ? 16 : 2) - 1;
1315 assert(brw
->urb
.nr_clip_entries
>= 5);
1316 clip
.MaximumNumberofThreads
= 1 - 1;
1319 clip
.VertexPositionSpace
= VPOS_NDCSPACE
;
1320 clip
.UserClipFlagsMustClipEnable
= true;
1321 clip
.GuardbandClipTestEnable
= true;
1323 clip
.ClipperViewportStatePointer
=
1324 ro_bo(brw
->batch
.state
.bo
, brw
->clip
.vp_offset
);
1326 clip
.ScreenSpaceViewportXMin
= -1;
1327 clip
.ScreenSpaceViewportXMax
= 1;
1328 clip
.ScreenSpaceViewportYMin
= -1;
1329 clip
.ScreenSpaceViewportYMax
= 1;
1331 clip
.ViewportXYClipTestEnable
= true;
1332 clip
.ViewportZClipTestEnable
= !(ctx
->Transform
.DepthClampNear
&&
1333 ctx
->Transform
.DepthClampFar
);
1335 /* _NEW_TRANSFORM */
1336 if (GEN_GEN
== 5 || GEN_IS_G4X
) {
1337 clip
.UserClipDistanceClipTestEnableBitmask
=
1338 ctx
->Transform
.ClipPlanesEnabled
;
1340 /* Up to 6 actual clip flags, plus the 7th for the negative RHW
1343 clip
.UserClipDistanceClipTestEnableBitmask
=
1344 (ctx
->Transform
.ClipPlanesEnabled
& 0x3f) | 0x40;
1347 if (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
)
1348 clip
.APIMode
= APIMODE_D3D
;
1350 clip
.APIMode
= APIMODE_OGL
;
1352 clip
.GuardbandClipTestEnable
= true;
1354 clip
.ClipMode
= brw
->clip
.prog_data
->clip_mode
;
1357 clip
.NegativeWClipTestEnable
= true;
1362 const struct brw_tracked_state
genX(clip_state
) = {
1364 .mesa
= _NEW_TRANSFORM
|
1366 .brw
= BRW_NEW_BATCH
|
1368 BRW_NEW_CLIP_PROG_DATA
|
1369 BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
1370 BRW_NEW_PROGRAM_CACHE
|
1373 .emit
= genX(upload_clip_state
),
1379 genX(upload_clip_state
)(struct brw_context
*brw
)
1381 struct gl_context
*ctx
= &brw
->ctx
;
1384 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1386 /* BRW_NEW_FS_PROG_DATA */
1387 struct brw_wm_prog_data
*wm_prog_data
=
1388 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1390 brw_batch_emit(brw
, GENX(3DSTATE_CLIP
), clip
) {
1391 clip
.StatisticsEnable
= !brw
->meta_in_progress
;
1393 if (wm_prog_data
->barycentric_interp_modes
&
1394 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
1395 clip
.NonPerspectiveBarycentricEnable
= true;
1398 clip
.EarlyCullEnable
= true;
1402 clip
.FrontWinding
= brw
->polygon_front_bit
!= fb
->FlipY
;
1404 if (ctx
->Polygon
.CullFlag
) {
1405 switch (ctx
->Polygon
.CullFaceMode
) {
1407 clip
.CullMode
= CULLMODE_FRONT
;
1410 clip
.CullMode
= CULLMODE_BACK
;
1412 case GL_FRONT_AND_BACK
:
1413 clip
.CullMode
= CULLMODE_BOTH
;
1416 unreachable("Should not get here: invalid CullFlag");
1419 clip
.CullMode
= CULLMODE_NONE
;
1424 clip
.UserClipDistanceCullTestEnableBitmask
=
1425 brw_vue_prog_data(brw
->vs
.base
.prog_data
)->cull_distance_mask
;
1427 clip
.ViewportZClipTestEnable
= !(ctx
->Transform
.DepthClampNear
&&
1428 ctx
->Transform
.DepthClampFar
);
1432 if (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
) {
1433 clip
.TriangleStripListProvokingVertexSelect
= 0;
1434 clip
.TriangleFanProvokingVertexSelect
= 1;
1435 clip
.LineStripListProvokingVertexSelect
= 0;
1437 clip
.TriangleStripListProvokingVertexSelect
= 2;
1438 clip
.TriangleFanProvokingVertexSelect
= 2;
1439 clip
.LineStripListProvokingVertexSelect
= 1;
1442 /* _NEW_TRANSFORM */
1443 clip
.UserClipDistanceClipTestEnableBitmask
=
1444 ctx
->Transform
.ClipPlanesEnabled
;
1447 clip
.ForceUserClipDistanceClipTestEnableBitmask
= true;
1450 if (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
)
1451 clip
.APIMode
= APIMODE_D3D
;
1453 clip
.APIMode
= APIMODE_OGL
;
1455 clip
.GuardbandClipTestEnable
= true;
1457 /* BRW_NEW_VIEWPORT_COUNT */
1458 const unsigned viewport_count
= brw
->clip
.viewport_count
;
1460 if (ctx
->RasterDiscard
) {
1461 clip
.ClipMode
= CLIPMODE_REJECT_ALL
;
1463 perf_debug("Rasterizer discard is currently implemented via the "
1464 "clipper; having the GS not write primitives would "
1465 "likely be faster.\n");
1468 clip
.ClipMode
= CLIPMODE_NORMAL
;
1471 clip
.ClipEnable
= true;
1474 * BRW_NEW_GEOMETRY_PROGRAM | BRW_NEW_TES_PROG_DATA | BRW_NEW_PRIMITIVE
1476 if (!brw_is_drawing_points(brw
) && !brw_is_drawing_lines(brw
))
1477 clip
.ViewportXYClipTestEnable
= true;
1479 clip
.MinimumPointWidth
= 0.125;
1480 clip
.MaximumPointWidth
= 255.875;
1481 clip
.MaximumVPIndex
= viewport_count
- 1;
1482 if (_mesa_geometric_layers(fb
) == 0)
1483 clip
.ForceZeroRTAIndexEnable
= true;
1487 static const struct brw_tracked_state
genX(clip_state
) = {
1489 .mesa
= _NEW_BUFFERS
|
1493 .brw
= BRW_NEW_BLORP
|
1495 BRW_NEW_FS_PROG_DATA
|
1496 BRW_NEW_GS_PROG_DATA
|
1497 BRW_NEW_VS_PROG_DATA
|
1498 BRW_NEW_META_IN_PROGRESS
|
1500 BRW_NEW_RASTERIZER_DISCARD
|
1501 BRW_NEW_TES_PROG_DATA
|
1502 BRW_NEW_VIEWPORT_COUNT
,
1504 .emit
= genX(upload_clip_state
),
1508 /* ---------------------------------------------------------------------- */
1511 genX(upload_sf
)(struct brw_context
*brw
)
1513 struct gl_context
*ctx
= &brw
->ctx
;
1518 bool flip_y
= ctx
->DrawBuffer
->FlipY
;
1519 UNUSED
const bool multisampled_fbo
=
1520 _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
1524 const struct brw_sf_prog_data
*sf_prog_data
= brw
->sf
.prog_data
;
1526 ctx
->NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
1528 brw_state_emit(brw
, GENX(SF_STATE
), 64, &brw
->sf
.state_offset
, sf
) {
1529 sf
.KernelStartPointer
= KSP(brw
, brw
->sf
.prog_offset
);
1530 sf
.FloatingPointMode
= FLOATING_POINT_MODE_Alternate
;
1531 sf
.GRFRegisterCount
= DIV_ROUND_UP(sf_prog_data
->total_grf
, 16) - 1;
1532 sf
.DispatchGRFStartRegisterForURBData
= 3;
1533 sf
.VertexURBEntryReadOffset
= BRW_SF_URB_ENTRY_READ_OFFSET
;
1534 sf
.VertexURBEntryReadLength
= sf_prog_data
->urb_read_length
;
1535 sf
.NumberofURBEntries
= brw
->urb
.nr_sf_entries
;
1536 sf
.URBEntryAllocationSize
= brw
->urb
.sfsize
- 1;
1538 /* STATE_PREFETCH command description describes this state as being
1539 * something loaded through the GPE (L2 ISC), so it's INSTRUCTION
1542 sf
.SetupViewportStateOffset
=
1543 ro_bo(brw
->batch
.state
.bo
, brw
->sf
.vp_offset
);
1545 sf
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1547 /* sf.ConstantURBEntryReadLength = stage_prog_data->curb_read_length; */
1548 /* sf.ConstantURBEntryReadOffset = brw->curbe.vs_start * 2; */
1550 sf
.MaximumNumberofThreads
=
1551 MIN2(GEN_GEN
== 5 ? 48 : 24, brw
->urb
.nr_sf_entries
) - 1;
1553 sf
.SpritePointEnable
= ctx
->Point
.PointSprite
;
1555 sf
.DestinationOriginHorizontalBias
= 0.5;
1556 sf
.DestinationOriginVerticalBias
= 0.5;
1558 brw_batch_emit(brw
, GENX(3DSTATE_SF
), sf
) {
1559 sf
.StatisticsEnable
= true;
1561 sf
.ViewportTransformEnable
= true;
1565 sf
.DepthBufferSurfaceFormat
= brw_depthbuffer_format(brw
);
1570 sf
.FrontWinding
= brw
->polygon_front_bit
!= flip_y
;
1572 sf
.GlobalDepthOffsetEnableSolid
= ctx
->Polygon
.OffsetFill
;
1573 sf
.GlobalDepthOffsetEnableWireframe
= ctx
->Polygon
.OffsetLine
;
1574 sf
.GlobalDepthOffsetEnablePoint
= ctx
->Polygon
.OffsetPoint
;
1576 switch (ctx
->Polygon
.FrontMode
) {
1578 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
1581 sf
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
1584 sf
.FrontFaceFillMode
= FILL_MODE_POINT
;
1587 unreachable("not reached");
1590 switch (ctx
->Polygon
.BackMode
) {
1592 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
1595 sf
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
1598 sf
.BackFaceFillMode
= FILL_MODE_POINT
;
1601 unreachable("not reached");
1604 if (multisampled_fbo
&& ctx
->Multisample
.Enabled
)
1605 sf
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1607 sf
.GlobalDepthOffsetConstant
= ctx
->Polygon
.OffsetUnits
* 2;
1608 sf
.GlobalDepthOffsetScale
= ctx
->Polygon
.OffsetFactor
;
1609 sf
.GlobalDepthOffsetClamp
= ctx
->Polygon
.OffsetClamp
;
1612 sf
.ScissorRectangleEnable
= true;
1614 if (ctx
->Polygon
.CullFlag
) {
1615 switch (ctx
->Polygon
.CullFaceMode
) {
1617 sf
.CullMode
= CULLMODE_FRONT
;
1620 sf
.CullMode
= CULLMODE_BACK
;
1622 case GL_FRONT_AND_BACK
:
1623 sf
.CullMode
= CULLMODE_BOTH
;
1626 unreachable("not reached");
1629 sf
.CullMode
= CULLMODE_NONE
;
1633 sf
.LineStippleEnable
= ctx
->Line
.StippleFlag
;
1640 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1642 if (devinfo
->is_cherryview
)
1643 sf
.CHVLineWidth
= brw_get_line_width(brw
);
1645 sf
.LineWidth
= brw_get_line_width(brw
);
1647 sf
.LineWidth
= brw_get_line_width(brw
);
1650 if (ctx
->Line
.SmoothFlag
) {
1651 sf
.LineEndCapAntialiasingRegionWidth
= _10pixels
;
1653 sf
.AntialiasingEnable
= true;
1657 /* _NEW_POINT - Clamp to ARB_point_parameters user limits */
1658 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
1659 /* Clamp to the hardware limits */
1660 sf
.PointWidth
= CLAMP(point_size
, 0.125f
, 255.875f
);
1662 /* _NEW_PROGRAM | _NEW_POINT, BRW_NEW_VUE_MAP_GEOM_OUT */
1663 if (use_state_point_size(brw
))
1664 sf
.PointWidthSource
= State
;
1667 /* _NEW_POINT | _NEW_MULTISAMPLE */
1668 if ((ctx
->Point
.SmoothFlag
|| _mesa_is_multisample_enabled(ctx
)) &&
1669 !ctx
->Point
.PointSprite
)
1670 sf
.SmoothPointEnable
= true;
1675 * Smooth Point Enable bit MUST not be set when NUM_MULTISAMPLES > 1.
1677 const bool multisampled_fbo
=
1678 _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
1679 if (multisampled_fbo
)
1680 sf
.SmoothPointEnable
= false;
1683 #if GEN_IS_G4X || GEN_GEN >= 5
1684 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
1688 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
1689 sf
.TriangleStripListProvokingVertexSelect
= 2;
1690 sf
.TriangleFanProvokingVertexSelect
= 2;
1691 sf
.LineStripListProvokingVertexSelect
= 1;
1693 sf
.TriangleFanProvokingVertexSelect
= 1;
1697 /* BRW_NEW_FS_PROG_DATA */
1698 const struct brw_wm_prog_data
*wm_prog_data
=
1699 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1701 sf
.AttributeSwizzleEnable
= true;
1702 sf
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
1705 * Window coordinates in an FBO are inverted, which means point
1706 * sprite origin must be inverted, too.
1708 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) == flip_y
) {
1709 sf
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
1711 sf
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
1714 /* BRW_NEW_VUE_MAP_GEOM_OUT | BRW_NEW_FRAGMENT_PROGRAM |
1715 * _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM | BRW_NEW_FS_PROG_DATA
1717 uint32_t urb_entry_read_length
;
1718 uint32_t urb_entry_read_offset
;
1719 uint32_t point_sprite_enables
;
1720 genX(calculate_attr_overrides
)(brw
, sf
.Attribute
, &point_sprite_enables
,
1721 &urb_entry_read_length
,
1722 &urb_entry_read_offset
);
1723 sf
.VertexURBEntryReadLength
= urb_entry_read_length
;
1724 sf
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
1725 sf
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
1726 sf
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
1731 static const struct brw_tracked_state
genX(sf_state
) = {
1733 .mesa
= _NEW_LIGHT
|
1737 (GEN_GEN
>= 6 ? _NEW_MULTISAMPLE
: 0) |
1738 (GEN_GEN
<= 7 ? _NEW_BUFFERS
| _NEW_POLYGON
: 0) |
1739 (GEN_GEN
== 10 ? _NEW_BUFFERS
: 0),
1740 .brw
= BRW_NEW_BLORP
|
1741 BRW_NEW_VUE_MAP_GEOM_OUT
|
1742 (GEN_GEN
<= 5 ? BRW_NEW_BATCH
|
1743 BRW_NEW_PROGRAM_CACHE
|
1744 BRW_NEW_SF_PROG_DATA
|
1748 (GEN_GEN
>= 6 ? BRW_NEW_CONTEXT
: 0) |
1749 (GEN_GEN
>= 6 && GEN_GEN
<= 7 ?
1750 BRW_NEW_GS_PROG_DATA
|
1752 BRW_NEW_TES_PROG_DATA
1754 (GEN_GEN
== 6 ? BRW_NEW_FS_PROG_DATA
|
1755 BRW_NEW_FRAGMENT_PROGRAM
1758 .emit
= genX(upload_sf
),
1761 /* ---------------------------------------------------------------------- */
1764 brw_color_buffer_write_enabled(struct brw_context
*brw
)
1766 struct gl_context
*ctx
= &brw
->ctx
;
1767 /* BRW_NEW_FRAGMENT_PROGRAM */
1768 const struct gl_program
*fp
= brw
->programs
[MESA_SHADER_FRAGMENT
];
1772 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++) {
1773 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
1774 uint64_t outputs_written
= fp
->info
.outputs_written
;
1777 if (rb
&& (outputs_written
& BITFIELD64_BIT(FRAG_RESULT_COLOR
) ||
1778 outputs_written
& BITFIELD64_BIT(FRAG_RESULT_DATA0
+ i
)) &&
1779 GET_COLORMASK(ctx
->Color
.ColorMask
, i
)) {
1788 genX(upload_wm
)(struct brw_context
*brw
)
1790 struct gl_context
*ctx
= &brw
->ctx
;
1792 /* BRW_NEW_FS_PROG_DATA */
1793 const struct brw_wm_prog_data
*wm_prog_data
=
1794 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
1796 UNUSED
bool writes_depth
=
1797 wm_prog_data
->computed_depth_mode
!= BRW_PSCDEPTH_OFF
;
1798 UNUSED
struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
1799 UNUSED
const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
1802 /* We can't fold this into gen6_upload_wm_push_constants(), because
1803 * according to the SNB PRM, vol 2 part 1 section 7.2.2
1804 * (3DSTATE_CONSTANT_PS [DevSNB]):
1806 * "[DevSNB]: This packet must be followed by WM_STATE."
1808 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_PS
), wmcp
) {
1809 if (wm_prog_data
->base
.nr_params
!= 0) {
1810 wmcp
.Buffer0Valid
= true;
1811 /* Pointer to the WM constant buffer. Covered by the set of
1812 * state flags from gen6_upload_wm_push_constants.
1814 wmcp
.ConstantBody
.PointertoConstantBuffer0
= stage_state
->push_const_offset
;
1815 wmcp
.ConstantBody
.ConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
1821 brw_batch_emit(brw
, GENX(3DSTATE_WM
), wm
) {
1823 ctx
->NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
1824 brw_state_emit(brw
, GENX(WM_STATE
), 64, &stage_state
->state_offset
, wm
) {
1828 wm
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
1829 wm
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
1830 wm
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
1834 /* On gen4, we only have one shader kernel */
1835 if (brw_wm_state_has_ksp(wm
, 0)) {
1836 assert(brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 0) == 0);
1837 wm
.KernelStartPointer0
= KSP(brw
, stage_state
->prog_offset
);
1838 wm
.GRFRegisterCount0
= brw_wm_prog_data_reg_blocks(wm_prog_data
, wm
, 0);
1839 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
1840 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 0);
1843 /* On gen5, we have multiple shader kernels but only one GRF start
1844 * register for all kernels
1846 wm
.KernelStartPointer0
= stage_state
->prog_offset
+
1847 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 0);
1848 wm
.KernelStartPointer1
= stage_state
->prog_offset
+
1849 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 1);
1850 wm
.KernelStartPointer2
= stage_state
->prog_offset
+
1851 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 2);
1853 wm
.GRFRegisterCount0
= brw_wm_prog_data_reg_blocks(wm_prog_data
, wm
, 0);
1854 wm
.GRFRegisterCount1
= brw_wm_prog_data_reg_blocks(wm_prog_data
, wm
, 1);
1855 wm
.GRFRegisterCount2
= brw_wm_prog_data_reg_blocks(wm_prog_data
, wm
, 2);
1857 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
1858 wm_prog_data
->base
.dispatch_grf_start_reg
;
1860 /* Dispatch GRF Start should be the same for all shaders on gen5 */
1861 if (brw_wm_state_has_ksp(wm
, 1)) {
1862 assert(wm_prog_data
->base
.dispatch_grf_start_reg
==
1863 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 1));
1865 if (brw_wm_state_has_ksp(wm
, 2)) {
1866 assert(wm_prog_data
->base
.dispatch_grf_start_reg
==
1867 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 2));
1870 /* On gen6, we have multiple shader kernels and we no longer specify a
1871 * register count for each one.
1873 wm
.KernelStartPointer0
= stage_state
->prog_offset
+
1874 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 0);
1875 wm
.KernelStartPointer1
= stage_state
->prog_offset
+
1876 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 1);
1877 wm
.KernelStartPointer2
= stage_state
->prog_offset
+
1878 brw_wm_prog_data_prog_offset(wm_prog_data
, wm
, 2);
1880 wm
.DispatchGRFStartRegisterForConstantSetupData0
=
1881 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 0);
1882 wm
.DispatchGRFStartRegisterForConstantSetupData1
=
1883 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 1);
1884 wm
.DispatchGRFStartRegisterForConstantSetupData2
=
1885 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, wm
, 2);
1889 wm
.ConstantURBEntryReadLength
= wm_prog_data
->base
.curb_read_length
;
1890 /* BRW_NEW_PUSH_CONSTANT_ALLOCATION */
1891 wm
.ConstantURBEntryReadOffset
= brw
->curbe
.wm_start
* 2;
1892 wm
.SetupURBEntryReadLength
= wm_prog_data
->num_varying_inputs
* 2;
1893 wm
.SetupURBEntryReadOffset
= 0;
1894 wm
.EarlyDepthTestEnable
= true;
1898 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1899 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1901 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1902 wm
.BarycentricInterpolationMode
= wm_prog_data
->barycentric_interp_modes
;
1904 if (stage_state
->sampler_count
)
1905 wm
.SamplerStatePointer
=
1906 ro_bo(brw
->batch
.state
.bo
, stage_state
->sampler_offset
);
1908 wm
.LineAntialiasingRegionWidth
= _05pixels
;
1909 wm
.LineEndCapAntialiasingRegionWidth
= _10pixels
;
1912 if (ctx
->Polygon
.OffsetFill
) {
1913 wm
.GlobalDepthOffsetEnable
= true;
1914 /* Something weird going on with legacy_global_depth_bias,
1915 * offset_constant, scaling and MRD. This value passes glean
1916 * but gives some odd results elsewere (eg. the
1917 * quad-offset-units test).
1919 wm
.GlobalDepthOffsetConstant
= ctx
->Polygon
.OffsetUnits
* 2;
1921 /* This is the only value that passes glean:
1923 wm
.GlobalDepthOffsetScale
= ctx
->Polygon
.OffsetFactor
;
1926 wm
.DepthCoefficientURBReadOffset
= 1;
1929 /* BRW_NEW_STATS_WM */
1930 wm
.StatisticsEnable
= GEN_GEN
>= 6 || brw
->stats_wm
;
1933 if (wm_prog_data
->base
.use_alt_mode
)
1934 wm
.FloatingPointMode
= FLOATING_POINT_MODE_Alternate
;
1936 wm
.SamplerCount
= GEN_GEN
== 5 ?
1937 0 : DIV_ROUND_UP(stage_state
->sampler_count
, 4);
1939 wm
.BindingTableEntryCount
=
1940 wm_prog_data
->base
.binding_table
.size_bytes
/ 4;
1941 wm
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1944 wm
.DualSourceBlendEnable
=
1945 wm_prog_data
->dual_src_blend
&& (ctx
->Color
.BlendEnabled
& 1) &&
1946 ctx
->Color
.Blend
[0]._UsesDualSrc
;
1947 wm
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1948 wm
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
1950 /* From the SNB PRM, volume 2 part 1, page 281:
1951 * "If the PS kernel does not need the Position XY Offsets
1952 * to compute a Position XY value, then this field should be
1953 * programmed to POSOFFSET_NONE."
1955 * "SW Recommendation: If the PS kernel needs the Position Offsets
1956 * to compute a Position XY value, this field should match Position
1957 * ZW Interpolation Mode to ensure a consistent position.xyzw
1959 * We only require XY sample offsets. So, this recommendation doesn't
1960 * look useful at the moment. We might need this in future.
1962 if (wm_prog_data
->uses_pos_offset
)
1963 wm
.PositionXYOffsetSelect
= POSOFFSET_SAMPLE
;
1965 wm
.PositionXYOffsetSelect
= POSOFFSET_NONE
;
1968 if (wm_prog_data
->base
.total_scratch
) {
1969 wm
.ScratchSpaceBasePointer
= rw_32_bo(stage_state
->scratch_bo
, 0);
1970 wm
.PerThreadScratchSpace
=
1971 ffs(stage_state
->per_thread_scratch
) - 11;
1974 wm
.PixelShaderComputedDepth
= writes_depth
;
1978 wm
.LineStippleEnable
= ctx
->Line
.StippleFlag
;
1981 wm
.PolygonStippleEnable
= ctx
->Polygon
.StippleFlag
;
1986 wm
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1989 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
1991 if (multisampled_fbo
) {
1992 /* _NEW_MULTISAMPLE */
1993 if (ctx
->Multisample
.Enabled
)
1994 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1996 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
1998 if (wm_prog_data
->persample_dispatch
)
1999 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
2001 wm
.MultisampleDispatchMode
= MSDISPMODE_PERPIXEL
;
2003 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
2004 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
2007 wm
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
2008 if (wm_prog_data
->uses_kill
||
2009 _mesa_is_alpha_test_enabled(ctx
) ||
2010 _mesa_is_alpha_to_coverage_enabled(ctx
) ||
2011 (GEN_GEN
>= 6 && wm_prog_data
->uses_omask
)) {
2012 wm
.PixelShaderKillsPixel
= true;
2015 /* _NEW_BUFFERS | _NEW_COLOR */
2016 if (brw_color_buffer_write_enabled(brw
) || writes_depth
||
2017 wm
.PixelShaderKillsPixel
||
2018 (GEN_GEN
>= 6 && wm_prog_data
->has_side_effects
)) {
2019 wm
.ThreadDispatchEnable
= true;
2023 wm
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
2024 wm
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
2027 /* The "UAV access enable" bits are unnecessary on HSW because they only
2028 * seem to have an effect on the HW-assisted coherency mechanism which we
2029 * don't need, and the rasterization-related UAV_ONLY flag and the
2030 * DISPATCH_ENABLE bit can be set independently from it.
2031 * C.f. gen8_upload_ps_extra().
2033 * BRW_NEW_FRAGMENT_PROGRAM | BRW_NEW_FS_PROG_DATA | _NEW_BUFFERS |
2037 if (!(brw_color_buffer_write_enabled(brw
) || writes_depth
) &&
2038 wm_prog_data
->has_side_effects
)
2044 /* BRW_NEW_FS_PROG_DATA */
2045 if (wm_prog_data
->early_fragment_tests
)
2046 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
2047 else if (wm_prog_data
->has_side_effects
)
2048 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
2053 if (brw
->wm
.offset_clamp
!= ctx
->Polygon
.OffsetClamp
) {
2054 brw_batch_emit(brw
, GENX(3DSTATE_GLOBAL_DEPTH_OFFSET_CLAMP
), clamp
) {
2055 clamp
.GlobalDepthOffsetClamp
= ctx
->Polygon
.OffsetClamp
;
2058 brw
->wm
.offset_clamp
= ctx
->Polygon
.OffsetClamp
;
2063 static const struct brw_tracked_state
genX(wm_state
) = {
2067 (GEN_GEN
< 8 ? _NEW_BUFFERS
|
2070 (GEN_GEN
== 6 ? _NEW_PROGRAM_CONSTANTS
: 0) |
2071 (GEN_GEN
< 6 ? _NEW_POLYGONSTIPPLE
: 0) |
2072 (GEN_GEN
< 8 && GEN_GEN
>= 6 ? _NEW_MULTISAMPLE
: 0),
2073 .brw
= BRW_NEW_BLORP
|
2074 BRW_NEW_FS_PROG_DATA
|
2075 (GEN_GEN
< 6 ? BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
2076 BRW_NEW_FRAGMENT_PROGRAM
|
2077 BRW_NEW_PROGRAM_CACHE
|
2078 BRW_NEW_SAMPLER_STATE_TABLE
|
2081 (GEN_GEN
< 7 ? BRW_NEW_BATCH
: BRW_NEW_CONTEXT
),
2083 .emit
= genX(upload_wm
),
2086 /* ---------------------------------------------------------------------- */
2088 /* We restrict scratch buffers to the bottom 32 bits of the address space
2089 * by using rw_32_bo().
2091 * General State Base Address is a bit broken. If the address + size as
2092 * seen by STATE_BASE_ADDRESS overflows 48 bits, the GPU appears to treat
2093 * all accesses to the buffer as being out of bounds and returns zero.
2096 #define INIT_THREAD_DISPATCH_FIELDS(pkt, prefix) \
2097 pkt.KernelStartPointer = KSP(brw, stage_state->prog_offset); \
2098 /* WA_1606682166 */ \
2099 pkt.SamplerCount = \
2102 DIV_ROUND_UP(CLAMP(stage_state->sampler_count, 0, 16), 4); \
2103 pkt.BindingTableEntryCount = \
2104 stage_prog_data->binding_table.size_bytes / 4; \
2105 pkt.FloatingPointMode = stage_prog_data->use_alt_mode; \
2107 if (stage_prog_data->total_scratch) { \
2108 pkt.ScratchSpaceBasePointer = rw_32_bo(stage_state->scratch_bo, 0); \
2109 pkt.PerThreadScratchSpace = \
2110 ffs(stage_state->per_thread_scratch) - 11; \
2113 pkt.DispatchGRFStartRegisterForURBData = \
2114 stage_prog_data->dispatch_grf_start_reg; \
2115 pkt.prefix##URBEntryReadLength = vue_prog_data->urb_read_length; \
2116 pkt.prefix##URBEntryReadOffset = 0; \
2118 pkt.StatisticsEnable = true; \
2122 genX(upload_vs_state
)(struct brw_context
*brw
)
2124 UNUSED
struct gl_context
*ctx
= &brw
->ctx
;
2125 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
2126 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
2128 /* BRW_NEW_VS_PROG_DATA */
2129 const struct brw_vue_prog_data
*vue_prog_data
=
2130 brw_vue_prog_data(brw
->vs
.base
.prog_data
);
2131 const struct brw_stage_prog_data
*stage_prog_data
= &vue_prog_data
->base
;
2133 assert(vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
||
2134 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_4X2_DUAL_OBJECT
);
2135 assert(GEN_GEN
< 11 ||
2136 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
);
2139 /* From the BSpec, 3D Pipeline > Geometry > Vertex Shader > State,
2140 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
2142 * [DevSNB] A pipeline flush must be programmed prior to a 3DSTATE_VS
2143 * command that causes the VS Function Enable to toggle. Pipeline
2144 * flush can be executed by sending a PIPE_CONTROL command with CS
2145 * stall bit set and a post sync operation.
2147 * We've already done such a flush at the start of state upload, so we
2148 * don't need to do another one here.
2150 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_VS
), cvs
) {
2151 if (stage_state
->push_const_size
!= 0) {
2152 cvs
.Buffer0Valid
= true;
2153 cvs
.ConstantBody
.PointertoConstantBuffer0
= stage_state
->push_const_offset
;
2154 cvs
.ConstantBody
.ConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
2159 if (GEN_GEN
== 7 && devinfo
->is_ivybridge
)
2160 gen7_emit_vs_workaround_flush(brw
);
2163 brw_batch_emit(brw
, GENX(3DSTATE_VS
), vs
) {
2165 ctx
->NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
2166 brw_state_emit(brw
, GENX(VS_STATE
), 32, &stage_state
->state_offset
, vs
) {
2168 INIT_THREAD_DISPATCH_FIELDS(vs
, Vertex
);
2170 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
2173 vs
.GRFRegisterCount
= DIV_ROUND_UP(vue_prog_data
->total_grf
, 16) - 1;
2174 vs
.ConstantURBEntryReadLength
= stage_prog_data
->curb_read_length
;
2175 vs
.ConstantURBEntryReadOffset
= brw
->curbe
.vs_start
* 2;
2177 vs
.NumberofURBEntries
= brw
->urb
.nr_vs_entries
>> (GEN_GEN
== 5 ? 2 : 0);
2178 vs
.URBEntryAllocationSize
= brw
->urb
.vsize
- 1;
2180 vs
.MaximumNumberofThreads
=
2181 CLAMP(brw
->urb
.nr_vs_entries
/ 2, 1, devinfo
->max_vs_threads
) - 1;
2183 vs
.StatisticsEnable
= false;
2184 vs
.SamplerStatePointer
=
2185 ro_bo(brw
->batch
.state
.bo
, stage_state
->sampler_offset
);
2189 /* Force single program flow on Ironlake. We cannot reliably get
2190 * all applications working without it. See:
2191 * https://bugs.freedesktop.org/show_bug.cgi?id=29172
2193 * The most notable and reliably failing application is the Humus
2196 vs
.SingleProgramFlow
= true;
2197 vs
.SamplerCount
= 0; /* hardware requirement */
2201 vs
.SIMD8DispatchEnable
=
2202 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
;
2204 vs
.UserClipDistanceCullTestEnableBitmask
=
2205 vue_prog_data
->cull_distance_mask
;
2210 /* Based on my reading of the simulator, the VS constants don't get
2211 * pulled into the VS FF unit until an appropriate pipeline flush
2212 * happens, and instead the 3DSTATE_CONSTANT_VS packet just adds
2213 * references to them into a little FIFO. The flushes are common,
2214 * but don't reliably happen between this and a 3DPRIMITIVE, causing
2215 * the primitive to use the wrong constants. Then the FIFO
2216 * containing the constant setup gets added to again on the next
2217 * constants change, and eventually when a flush does happen the
2218 * unit is overwhelmed by constant changes and dies.
2220 * To avoid this, send a PIPE_CONTROL down the line that will
2221 * update the unit immediately loading the constants. The flush
2222 * type bits here were those set by the STATE_BASE_ADDRESS whose
2223 * move in a82a43e8d99e1715dd11c9c091b5ab734079b6a6 triggered the
2224 * bug reports that led to this workaround, and may be more than
2225 * what is strictly required to avoid the issue.
2227 brw_emit_pipe_control_flush(brw
,
2228 PIPE_CONTROL_DEPTH_STALL
|
2229 PIPE_CONTROL_INSTRUCTION_INVALIDATE
|
2230 PIPE_CONTROL_STATE_CACHE_INVALIDATE
);
2234 static const struct brw_tracked_state
genX(vs_state
) = {
2236 .mesa
= (GEN_GEN
== 6 ? (_NEW_PROGRAM_CONSTANTS
| _NEW_TRANSFORM
) : 0),
2237 .brw
= BRW_NEW_BATCH
|
2240 BRW_NEW_VS_PROG_DATA
|
2241 (GEN_GEN
== 6 ? BRW_NEW_VERTEX_PROGRAM
: 0) |
2242 (GEN_GEN
<= 5 ? BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
2243 BRW_NEW_PROGRAM_CACHE
|
2244 BRW_NEW_SAMPLER_STATE_TABLE
|
2248 .emit
= genX(upload_vs_state
),
2251 /* ---------------------------------------------------------------------- */
2254 genX(upload_cc_viewport
)(struct brw_context
*brw
)
2256 struct gl_context
*ctx
= &brw
->ctx
;
2258 /* BRW_NEW_VIEWPORT_COUNT */
2259 const unsigned viewport_count
= brw
->clip
.viewport_count
;
2261 struct GENX(CC_VIEWPORT
) ccv
;
2262 uint32_t cc_vp_offset
;
2264 brw_state_batch(brw
, 4 * GENX(CC_VIEWPORT_length
) * viewport_count
,
2267 for (unsigned i
= 0; i
< viewport_count
; i
++) {
2268 /* _NEW_VIEWPORT | _NEW_TRANSFORM */
2269 const struct gl_viewport_attrib
*vp
= &ctx
->ViewportArray
[i
];
2270 if (ctx
->Transform
.DepthClampNear
&& ctx
->Transform
.DepthClampFar
) {
2271 ccv
.MinimumDepth
= MIN2(vp
->Near
, vp
->Far
);
2272 ccv
.MaximumDepth
= MAX2(vp
->Near
, vp
->Far
);
2273 } else if (ctx
->Transform
.DepthClampNear
) {
2274 ccv
.MinimumDepth
= MIN2(vp
->Near
, vp
->Far
);
2275 ccv
.MaximumDepth
= 0.0;
2276 } else if (ctx
->Transform
.DepthClampFar
) {
2277 ccv
.MinimumDepth
= 0.0;
2278 ccv
.MaximumDepth
= MAX2(vp
->Near
, vp
->Far
);
2280 ccv
.MinimumDepth
= 0.0;
2281 ccv
.MaximumDepth
= 1.0;
2283 GENX(CC_VIEWPORT_pack
)(NULL
, cc_map
, &ccv
);
2284 cc_map
+= GENX(CC_VIEWPORT_length
);
2288 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_CC
), ptr
) {
2289 ptr
.CCViewportPointer
= cc_vp_offset
;
2292 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vp
) {
2293 vp
.CCViewportStateChange
= 1;
2294 vp
.PointertoCC_VIEWPORT
= cc_vp_offset
;
2297 brw
->cc
.vp_offset
= cc_vp_offset
;
2298 ctx
->NewDriverState
|= BRW_NEW_CC_VP
;
2302 const struct brw_tracked_state
genX(cc_vp
) = {
2304 .mesa
= _NEW_TRANSFORM
|
2306 .brw
= BRW_NEW_BATCH
|
2308 BRW_NEW_VIEWPORT_COUNT
,
2310 .emit
= genX(upload_cc_viewport
)
2313 /* ---------------------------------------------------------------------- */
2316 set_scissor_bits(const struct gl_context
*ctx
, int i
,
2317 bool flip_y
, unsigned fb_width
, unsigned fb_height
,
2318 struct GENX(SCISSOR_RECT
) *sc
)
2322 bbox
[0] = MAX2(ctx
->ViewportArray
[i
].X
, 0);
2323 bbox
[1] = MIN2(bbox
[0] + ctx
->ViewportArray
[i
].Width
, fb_width
);
2324 bbox
[2] = CLAMP(ctx
->ViewportArray
[i
].Y
, 0, fb_height
);
2325 bbox
[3] = MIN2(bbox
[2] + ctx
->ViewportArray
[i
].Height
, fb_height
);
2326 _mesa_intersect_scissor_bounding_box(ctx
, i
, bbox
);
2328 if (bbox
[0] == bbox
[1] || bbox
[2] == bbox
[3]) {
2329 /* If the scissor was out of bounds and got clamped to 0 width/height
2330 * at the bounds, the subtraction of 1 from maximums could produce a
2331 * negative number and thus not clip anything. Instead, just provide
2332 * a min > max scissor inside the bounds, which produces the expected
2335 sc
->ScissorRectangleXMin
= 1;
2336 sc
->ScissorRectangleXMax
= 0;
2337 sc
->ScissorRectangleYMin
= 1;
2338 sc
->ScissorRectangleYMax
= 0;
2339 } else if (!flip_y
) {
2340 /* texmemory: Y=0=bottom */
2341 sc
->ScissorRectangleXMin
= bbox
[0];
2342 sc
->ScissorRectangleXMax
= bbox
[1] - 1;
2343 sc
->ScissorRectangleYMin
= bbox
[2];
2344 sc
->ScissorRectangleYMax
= bbox
[3] - 1;
2346 /* memory: Y=0=top */
2347 sc
->ScissorRectangleXMin
= bbox
[0];
2348 sc
->ScissorRectangleXMax
= bbox
[1] - 1;
2349 sc
->ScissorRectangleYMin
= fb_height
- bbox
[3];
2350 sc
->ScissorRectangleYMax
= fb_height
- bbox
[2] - 1;
2356 genX(upload_scissor_state
)(struct brw_context
*brw
)
2358 struct gl_context
*ctx
= &brw
->ctx
;
2359 const bool flip_y
= ctx
->DrawBuffer
->FlipY
;
2360 struct GENX(SCISSOR_RECT
) scissor
;
2361 uint32_t scissor_state_offset
;
2362 const unsigned int fb_width
= _mesa_geometric_width(ctx
->DrawBuffer
);
2363 const unsigned int fb_height
= _mesa_geometric_height(ctx
->DrawBuffer
);
2364 uint32_t *scissor_map
;
2366 /* BRW_NEW_VIEWPORT_COUNT */
2367 const unsigned viewport_count
= brw
->clip
.viewport_count
;
2369 scissor_map
= brw_state_batch(
2370 brw
, GENX(SCISSOR_RECT_length
) * sizeof(uint32_t) * viewport_count
,
2371 32, &scissor_state_offset
);
2373 /* _NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT */
2375 /* The scissor only needs to handle the intersection of drawable and
2376 * scissor rect. Clipping to the boundaries of static shared buffers
2377 * for front/back/depth is covered by looping over cliprects in brw_draw.c.
2379 * Note that the hardware's coordinates are inclusive, while Mesa's min is
2380 * inclusive but max is exclusive.
2382 for (unsigned i
= 0; i
< viewport_count
; i
++) {
2383 set_scissor_bits(ctx
, i
, flip_y
, fb_width
, fb_height
, &scissor
);
2384 GENX(SCISSOR_RECT_pack
)(
2385 NULL
, scissor_map
+ i
* GENX(SCISSOR_RECT_length
), &scissor
);
2388 brw_batch_emit(brw
, GENX(3DSTATE_SCISSOR_STATE_POINTERS
), ptr
) {
2389 ptr
.ScissorRectPointer
= scissor_state_offset
;
2393 static const struct brw_tracked_state
genX(scissor_state
) = {
2395 .mesa
= _NEW_BUFFERS
|
2398 .brw
= BRW_NEW_BATCH
|
2400 BRW_NEW_VIEWPORT_COUNT
,
2402 .emit
= genX(upload_scissor_state
),
2406 /* ---------------------------------------------------------------------- */
2409 genX(upload_sf_clip_viewport
)(struct brw_context
*brw
)
2411 struct gl_context
*ctx
= &brw
->ctx
;
2412 float y_scale
, y_bias
;
2414 /* BRW_NEW_VIEWPORT_COUNT */
2415 const unsigned viewport_count
= brw
->clip
.viewport_count
;
2418 const bool flip_y
= ctx
->DrawBuffer
->FlipY
;
2419 const uint32_t fb_width
= (float)_mesa_geometric_width(ctx
->DrawBuffer
);
2420 const uint32_t fb_height
= (float)_mesa_geometric_height(ctx
->DrawBuffer
);
2424 struct GENX(SF_CLIP_VIEWPORT
) sfv
;
2425 uint32_t sf_clip_vp_offset
;
2426 uint32_t *sf_clip_map
=
2427 brw_state_batch(brw
, GENX(SF_CLIP_VIEWPORT_length
) * 4 * viewport_count
,
2428 64, &sf_clip_vp_offset
);
2430 struct GENX(SF_VIEWPORT
) sfv
;
2431 struct GENX(CLIP_VIEWPORT
) clv
;
2432 uint32_t sf_vp_offset
, clip_vp_offset
;
2434 brw_state_batch(brw
, GENX(SF_VIEWPORT_length
) * 4 * viewport_count
,
2436 uint32_t *clip_map
=
2437 brw_state_batch(brw
, GENX(CLIP_VIEWPORT_length
) * 4 * viewport_count
,
2438 32, &clip_vp_offset
);
2444 y_bias
= (float)fb_height
;
2450 for (unsigned i
= 0; i
< brw
->clip
.viewport_count
; i
++) {
2451 /* _NEW_VIEWPORT: Guardband Clipping */
2452 float scale
[3], translate
[3], gb_xmin
, gb_xmax
, gb_ymin
, gb_ymax
;
2453 _mesa_get_viewport_xform(ctx
, i
, scale
, translate
);
2455 sfv
.ViewportMatrixElementm00
= scale
[0];
2456 sfv
.ViewportMatrixElementm11
= scale
[1] * y_scale
,
2457 sfv
.ViewportMatrixElementm22
= scale
[2],
2458 sfv
.ViewportMatrixElementm30
= translate
[0],
2459 sfv
.ViewportMatrixElementm31
= translate
[1] * y_scale
+ y_bias
,
2460 sfv
.ViewportMatrixElementm32
= translate
[2],
2461 gen_calculate_guardband_size(fb_width
, fb_height
,
2462 sfv
.ViewportMatrixElementm00
,
2463 sfv
.ViewportMatrixElementm11
,
2464 sfv
.ViewportMatrixElementm30
,
2465 sfv
.ViewportMatrixElementm31
,
2466 &gb_xmin
, &gb_xmax
, &gb_ymin
, &gb_ymax
);
2469 clv
.XMinClipGuardband
= gb_xmin
;
2470 clv
.XMaxClipGuardband
= gb_xmax
;
2471 clv
.YMinClipGuardband
= gb_ymin
;
2472 clv
.YMaxClipGuardband
= gb_ymax
;
2475 set_scissor_bits(ctx
, i
, flip_y
, fb_width
, fb_height
,
2476 &sfv
.ScissorRectangle
);
2478 /* _NEW_VIEWPORT | _NEW_BUFFERS: Screen Space Viewport
2479 * The hardware will take the intersection of the drawing rectangle,
2480 * scissor rectangle, and the viewport extents. However, emitting
2481 * 3DSTATE_DRAWING_RECTANGLE is expensive since it requires a full
2482 * pipeline stall so we're better off just being a little more clever
2483 * with our viewport so we can emit it once at context creation time.
2485 const float viewport_Xmin
= MAX2(ctx
->ViewportArray
[i
].X
, 0);
2486 const float viewport_Ymin
= MAX2(ctx
->ViewportArray
[i
].Y
, 0);
2487 const float viewport_Xmax
=
2488 MIN2(ctx
->ViewportArray
[i
].X
+ ctx
->ViewportArray
[i
].Width
, fb_width
);
2489 const float viewport_Ymax
=
2490 MIN2(ctx
->ViewportArray
[i
].Y
+ ctx
->ViewportArray
[i
].Height
, fb_height
);
2493 sfv
.XMinViewPort
= viewport_Xmin
;
2494 sfv
.XMaxViewPort
= viewport_Xmax
- 1;
2495 sfv
.YMinViewPort
= fb_height
- viewport_Ymax
;
2496 sfv
.YMaxViewPort
= fb_height
- viewport_Ymin
- 1;
2498 sfv
.XMinViewPort
= viewport_Xmin
;
2499 sfv
.XMaxViewPort
= viewport_Xmax
- 1;
2500 sfv
.YMinViewPort
= viewport_Ymin
;
2501 sfv
.YMaxViewPort
= viewport_Ymax
- 1;
2506 GENX(SF_CLIP_VIEWPORT_pack
)(NULL
, sf_clip_map
, &sfv
);
2507 sf_clip_map
+= GENX(SF_CLIP_VIEWPORT_length
);
2509 GENX(SF_VIEWPORT_pack
)(NULL
, sf_map
, &sfv
);
2510 GENX(CLIP_VIEWPORT_pack
)(NULL
, clip_map
, &clv
);
2511 sf_map
+= GENX(SF_VIEWPORT_length
);
2512 clip_map
+= GENX(CLIP_VIEWPORT_length
);
2517 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS_SF_CLIP
), ptr
) {
2518 ptr
.SFClipViewportPointer
= sf_clip_vp_offset
;
2521 brw_batch_emit(brw
, GENX(3DSTATE_VIEWPORT_STATE_POINTERS
), vp
) {
2522 vp
.SFViewportStateChange
= 1;
2523 vp
.CLIPViewportStateChange
= 1;
2524 vp
.PointertoCLIP_VIEWPORT
= clip_vp_offset
;
2525 vp
.PointertoSF_VIEWPORT
= sf_vp_offset
;
2528 brw
->sf
.vp_offset
= sf_vp_offset
;
2529 brw
->clip
.vp_offset
= clip_vp_offset
;
2530 brw
->ctx
.NewDriverState
|= BRW_NEW_SF_VP
| BRW_NEW_CLIP_VP
;
2534 static const struct brw_tracked_state
genX(sf_clip_viewport
) = {
2536 .mesa
= _NEW_BUFFERS
|
2538 (GEN_GEN
<= 5 ? _NEW_SCISSOR
: 0),
2539 .brw
= BRW_NEW_BATCH
|
2541 BRW_NEW_VIEWPORT_COUNT
,
2543 .emit
= genX(upload_sf_clip_viewport
),
2546 /* ---------------------------------------------------------------------- */
2549 genX(upload_gs_state
)(struct brw_context
*brw
)
2551 UNUSED
struct gl_context
*ctx
= &brw
->ctx
;
2552 UNUSED
const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
2553 const struct brw_stage_state
*stage_state
= &brw
->gs
.base
;
2554 const struct gl_program
*gs_prog
= brw
->programs
[MESA_SHADER_GEOMETRY
];
2555 /* BRW_NEW_GEOMETRY_PROGRAM */
2556 bool active
= GEN_GEN
>= 6 && gs_prog
;
2558 /* BRW_NEW_GS_PROG_DATA */
2559 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
2560 UNUSED
const struct brw_vue_prog_data
*vue_prog_data
=
2561 brw_vue_prog_data(stage_prog_data
);
2563 const struct brw_gs_prog_data
*gs_prog_data
=
2564 brw_gs_prog_data(stage_prog_data
);
2568 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_GS
), cgs
) {
2569 if (active
&& stage_state
->push_const_size
!= 0) {
2570 cgs
.Buffer0Valid
= true;
2571 cgs
.ConstantBody
.PointertoConstantBuffer0
= stage_state
->push_const_offset
;
2572 cgs
.ConstantBody
.ConstantBuffer0ReadLength
= stage_state
->push_const_size
- 1;
2577 #if GEN_GEN == 7 && !GEN_IS_HASWELL
2579 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
2580 * Geometry > Geometry Shader > State:
2582 * "Note: Because of corruption in IVB:GT2, software needs to flush the
2583 * whole fixed function pipeline when the GS enable changes value in
2586 * The hardware architects have clarified that in this context "flush the
2587 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
2590 if (devinfo
->gt
== 2 && brw
->gs
.enabled
!= active
)
2591 gen7_emit_cs_stall_flush(brw
);
2595 brw_batch_emit(brw
, GENX(3DSTATE_GS
), gs
) {
2597 ctx
->NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
2598 brw_state_emit(brw
, GENX(GS_STATE
), 32, &brw
->ff_gs
.state_offset
, gs
) {
2603 INIT_THREAD_DISPATCH_FIELDS(gs
, Vertex
);
2606 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
2607 gs
.OutputTopology
= gs_prog_data
->output_topology
;
2608 gs
.ControlDataHeaderSize
=
2609 gs_prog_data
->control_data_header_size_hwords
;
2611 gs
.InstanceControl
= gs_prog_data
->invocations
- 1;
2612 gs
.DispatchMode
= vue_prog_data
->dispatch_mode
;
2614 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
2616 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
2619 /* Note: the meaning of the GEN7_GS_REORDER_TRAILING bit changes between
2620 * Ivy Bridge and Haswell.
2622 * On Ivy Bridge, setting this bit causes the vertices of a triangle
2623 * strip to be delivered to the geometry shader in an order that does
2624 * not strictly follow the OpenGL spec, but preserves triangle
2625 * orientation. For example, if the vertices are (1, 2, 3, 4, 5), then
2626 * the geometry shader sees triangles:
2628 * (1, 2, 3), (2, 4, 3), (3, 4, 5)
2630 * (Clearing the bit is even worse, because it fails to preserve
2633 * Triangle strips with adjacency always ordered in a way that preserves
2634 * triangle orientation but does not strictly follow the OpenGL spec,
2635 * regardless of the setting of this bit.
2637 * On Haswell, both triangle strips and triangle strips with adjacency
2638 * are always ordered in a way that preserves triangle orientation.
2639 * Setting this bit causes the ordering to strictly follow the OpenGL
2642 * So in either case we want to set the bit. Unfortunately on Ivy
2643 * Bridge this will get the order close to correct but not perfect.
2645 gs
.ReorderMode
= TRAILING
;
2646 gs
.MaximumNumberofThreads
=
2647 GEN_GEN
== 8 ? (devinfo
->max_gs_threads
/ 2 - 1)
2648 : (devinfo
->max_gs_threads
- 1);
2651 gs
.SOStatisticsEnable
= true;
2652 if (gs_prog
->info
.has_transform_feedback_varyings
)
2653 gs
.SVBIPayloadEnable
= _mesa_is_xfb_active_and_unpaused(ctx
);
2655 /* GEN6_GS_SPF_MODE and GEN6_GS_VECTOR_MASK_ENABLE are enabled as it
2656 * was previously done for gen6.
2658 * TODO: test with both disabled to see if the HW is behaving
2659 * as expected, like in gen7.
2661 gs
.SingleProgramFlow
= true;
2662 gs
.VectorMaskEnable
= true;
2666 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
2668 if (gs_prog_data
->static_vertex_count
!= -1) {
2669 gs
.StaticOutput
= true;
2670 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
;
2672 gs
.IncludeVertexHandles
= vue_prog_data
->include_vue_handles
;
2674 gs
.UserClipDistanceCullTestEnableBitmask
=
2675 vue_prog_data
->cull_distance_mask
;
2677 const int urb_entry_write_offset
= 1;
2678 const uint32_t urb_entry_output_length
=
2679 DIV_ROUND_UP(vue_prog_data
->vue_map
.num_slots
, 2) -
2680 urb_entry_write_offset
;
2682 gs
.VertexURBEntryOutputReadOffset
= urb_entry_write_offset
;
2683 gs
.VertexURBEntryOutputLength
= MAX2(urb_entry_output_length
, 1);
2689 if (!active
&& brw
->ff_gs
.prog_active
) {
2690 /* In gen6, transform feedback for the VS stage is done with an
2691 * ad-hoc GS program. This function provides the needed 3DSTATE_GS
2694 gs
.KernelStartPointer
= KSP(brw
, brw
->ff_gs
.prog_offset
);
2695 gs
.SingleProgramFlow
= true;
2696 gs
.DispatchGRFStartRegisterForURBData
= GEN_GEN
== 6 ? 2 : 1;
2697 gs
.VertexURBEntryReadLength
= brw
->ff_gs
.prog_data
->urb_read_length
;
2700 gs
.GRFRegisterCount
=
2701 DIV_ROUND_UP(brw
->ff_gs
.prog_data
->total_grf
, 16) - 1;
2702 /* BRW_NEW_URB_FENCE */
2703 gs
.NumberofURBEntries
= brw
->urb
.nr_gs_entries
;
2704 gs
.URBEntryAllocationSize
= brw
->urb
.vsize
- 1;
2705 gs
.MaximumNumberofThreads
= brw
->urb
.nr_gs_entries
>= 8 ? 1 : 0;
2706 gs
.FloatingPointMode
= FLOATING_POINT_MODE_Alternate
;
2709 gs
.VectorMaskEnable
= true;
2710 gs
.SVBIPayloadEnable
= true;
2711 gs
.SVBIPostIncrementEnable
= true;
2712 gs
.SVBIPostIncrementValue
=
2713 brw
->ff_gs
.prog_data
->svbi_postincrement_value
;
2714 gs
.SOStatisticsEnable
= true;
2715 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
- 1;
2719 if (!active
&& !brw
->ff_gs
.prog_active
) {
2721 gs
.DispatchGRFStartRegisterForURBData
= 1;
2723 gs
.IncludeVertexHandles
= true;
2729 gs
.StatisticsEnable
= true;
2731 #if GEN_GEN == 5 || GEN_GEN == 6
2732 gs
.RenderingEnabled
= true;
2735 gs
.MaximumVPIndex
= brw
->clip
.viewport_count
- 1;
2740 brw
->gs
.enabled
= active
;
2744 static const struct brw_tracked_state
genX(gs_state
) = {
2746 .mesa
= (GEN_GEN
== 6 ? _NEW_PROGRAM_CONSTANTS
: 0),
2747 .brw
= BRW_NEW_BATCH
|
2749 (GEN_GEN
<= 5 ? BRW_NEW_PUSH_CONSTANT_ALLOCATION
|
2750 BRW_NEW_PROGRAM_CACHE
|
2752 BRW_NEW_VIEWPORT_COUNT
2754 (GEN_GEN
>= 6 ? BRW_NEW_CONTEXT
|
2755 BRW_NEW_GEOMETRY_PROGRAM
|
2756 BRW_NEW_GS_PROG_DATA
2758 (GEN_GEN
< 7 ? BRW_NEW_FF_GS_PROG_DATA
: 0),
2760 .emit
= genX(upload_gs_state
),
2763 /* ---------------------------------------------------------------------- */
2765 UNUSED
static GLenum
2766 fix_dual_blend_alpha_to_one(GLenum function
)
2772 case GL_ONE_MINUS_SRC1_ALPHA
:
2779 #define blend_factor(x) brw_translate_blend_factor(x)
2780 #define blend_eqn(x) brw_translate_blend_equation(x)
2783 * Modify blend function to force destination alpha to 1.0
2785 * If \c function specifies a blend function that uses destination alpha,
2786 * replace it with a function that hard-wires destination alpha to 1.0. This
2787 * is used when rendering to xRGB targets.
2790 brw_fix_xRGB_alpha(GLenum function
)
2796 case GL_ONE_MINUS_DST_ALPHA
:
2797 case GL_SRC_ALPHA_SATURATE
:
2805 typedef struct GENX(BLEND_STATE_ENTRY
) BLEND_ENTRY_GENXML
;
2807 typedef struct GENX(COLOR_CALC_STATE
) BLEND_ENTRY_GENXML
;
2811 set_blend_entry_bits(struct brw_context
*brw
, BLEND_ENTRY_GENXML
*entry
, int i
,
2814 struct gl_context
*ctx
= &brw
->ctx
;
2817 const struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[i
];
2819 bool independent_alpha_blend
= false;
2821 /* Used for implementing the following bit of GL_EXT_texture_integer:
2822 * "Per-fragment operations that require floating-point color
2823 * components, including multisample alpha operations, alpha test,
2824 * blending, and dithering, have no effect when the corresponding
2825 * colors are written to an integer color buffer."
2827 const bool integer
= ctx
->DrawBuffer
->_IntegerBuffers
& (0x1 << i
);
2829 const unsigned blend_enabled
= GEN_GEN
>= 6 ?
2830 ctx
->Color
.BlendEnabled
& (1 << i
) : ctx
->Color
.BlendEnabled
;
2833 if (ctx
->Color
.ColorLogicOpEnabled
) {
2834 GLenum rb_type
= rb
? _mesa_get_format_datatype(rb
->Format
)
2835 : GL_UNSIGNED_NORMALIZED
;
2836 WARN_ONCE(ctx
->Color
.LogicOp
!= GL_COPY
&&
2837 rb_type
!= GL_UNSIGNED_NORMALIZED
&&
2838 rb_type
!= GL_FLOAT
, "Ignoring %s logic op on %s "
2840 _mesa_enum_to_string(ctx
->Color
.LogicOp
),
2841 _mesa_enum_to_string(rb_type
));
2842 if (GEN_GEN
>= 8 || rb_type
== GL_UNSIGNED_NORMALIZED
) {
2843 entry
->LogicOpEnable
= true;
2844 entry
->LogicOpFunction
= ctx
->Color
._LogicOp
;
2846 } else if (blend_enabled
&& !ctx
->Color
._AdvancedBlendMode
2847 && (GEN_GEN
<= 5 || !integer
)) {
2848 GLenum eqRGB
= ctx
->Color
.Blend
[i
].EquationRGB
;
2849 GLenum eqA
= ctx
->Color
.Blend
[i
].EquationA
;
2850 GLenum srcRGB
= ctx
->Color
.Blend
[i
].SrcRGB
;
2851 GLenum dstRGB
= ctx
->Color
.Blend
[i
].DstRGB
;
2852 GLenum srcA
= ctx
->Color
.Blend
[i
].SrcA
;
2853 GLenum dstA
= ctx
->Color
.Blend
[i
].DstA
;
2855 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
)
2856 srcRGB
= dstRGB
= GL_ONE
;
2858 if (eqA
== GL_MIN
|| eqA
== GL_MAX
)
2859 srcA
= dstA
= GL_ONE
;
2861 /* Due to hardware limitations, the destination may have information
2862 * in an alpha channel even when the format specifies no alpha
2863 * channel. In order to avoid getting any incorrect blending due to
2864 * that alpha channel, coerce the blend factors to values that will
2865 * not read the alpha channel, but will instead use the correct
2866 * implicit value for alpha.
2868 if (rb
&& !_mesa_base_format_has_channel(rb
->_BaseFormat
,
2869 GL_TEXTURE_ALPHA_TYPE
)) {
2870 srcRGB
= brw_fix_xRGB_alpha(srcRGB
);
2871 srcA
= brw_fix_xRGB_alpha(srcA
);
2872 dstRGB
= brw_fix_xRGB_alpha(dstRGB
);
2873 dstA
= brw_fix_xRGB_alpha(dstA
);
2876 /* From the BLEND_STATE docs, DWord 0, Bit 29 (AlphaToOne Enable):
2877 * "If Dual Source Blending is enabled, this bit must be disabled."
2879 * We override SRC1_ALPHA to ONE and ONE_MINUS_SRC1_ALPHA to ZERO,
2880 * and leave it enabled anyway.
2882 if (GEN_GEN
>= 6 && ctx
->Color
.Blend
[i
]._UsesDualSrc
&& alpha_to_one
) {
2883 srcRGB
= fix_dual_blend_alpha_to_one(srcRGB
);
2884 srcA
= fix_dual_blend_alpha_to_one(srcA
);
2885 dstRGB
= fix_dual_blend_alpha_to_one(dstRGB
);
2886 dstA
= fix_dual_blend_alpha_to_one(dstA
);
2889 /* BRW_NEW_FS_PROG_DATA */
2890 const struct brw_wm_prog_data
*wm_prog_data
=
2891 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
2893 /* The Dual Source Blending documentation says:
2895 * "If SRC1 is included in a src/dst blend factor and
2896 * a DualSource RT Write message is not used, results
2897 * are UNDEFINED. (This reflects the same restriction in DX APIs,
2898 * where undefined results are produced if “o1” is not written
2899 * by a PS – there are no default values defined).
2900 * If SRC1 is not included in a src/dst blend factor,
2901 * dual source blending must be disabled."
2903 * There is no way to gracefully fix this undefined situation
2904 * so we just disable the blending to prevent possible issues.
2906 entry
->ColorBufferBlendEnable
=
2907 !ctx
->Color
.Blend
[0]._UsesDualSrc
|| wm_prog_data
->dual_src_blend
;
2909 entry
->DestinationBlendFactor
= blend_factor(dstRGB
);
2910 entry
->SourceBlendFactor
= blend_factor(srcRGB
);
2911 entry
->DestinationAlphaBlendFactor
= blend_factor(dstA
);
2912 entry
->SourceAlphaBlendFactor
= blend_factor(srcA
);
2913 entry
->ColorBlendFunction
= blend_eqn(eqRGB
);
2914 entry
->AlphaBlendFunction
= blend_eqn(eqA
);
2916 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
)
2917 independent_alpha_blend
= true;
2920 return independent_alpha_blend
;
2925 genX(upload_blend_state
)(struct brw_context
*brw
)
2927 struct gl_context
*ctx
= &brw
->ctx
;
2930 /* We need at least one BLEND_STATE written, because we might do
2931 * thread dispatch even if _NumColorDrawBuffers is 0 (for example
2932 * for computed depth or alpha test), which will do an FB write
2933 * with render target 0, which will reference BLEND_STATE[0] for
2934 * alpha test enable.
2936 int nr_draw_buffers
= ctx
->DrawBuffer
->_NumColorDrawBuffers
;
2937 if (nr_draw_buffers
== 0 && ctx
->Color
.AlphaEnabled
)
2938 nr_draw_buffers
= 1;
2940 size
= GENX(BLEND_STATE_ENTRY_length
) * 4 * nr_draw_buffers
;
2942 size
+= GENX(BLEND_STATE_length
) * 4;
2945 uint32_t *blend_map
;
2946 blend_map
= brw_state_batch(brw
, size
, 64, &brw
->cc
.blend_state_offset
);
2949 struct GENX(BLEND_STATE
) blend
= { 0 };
2952 for (int i
= 0; i
< nr_draw_buffers
; i
++) {
2953 struct GENX(BLEND_STATE_ENTRY
) entry
= { 0 };
2956 /* OpenGL specification 3.3 (page 196), section 4.1.3 says:
2957 * "If drawbuffer zero is not NONE and the buffer it references has an
2958 * integer format, the SAMPLE_ALPHA_TO_COVERAGE and SAMPLE_ALPHA_TO_ONE
2959 * operations are skipped."
2961 if (!(ctx
->DrawBuffer
->_IntegerBuffers
& 0x1)) {
2962 /* _NEW_MULTISAMPLE */
2963 if (_mesa_is_multisample_enabled(ctx
)) {
2964 if (ctx
->Multisample
.SampleAlphaToCoverage
) {
2965 blend
.AlphaToCoverageEnable
= true;
2966 blend
.AlphaToCoverageDitherEnable
= GEN_GEN
>= 7;
2968 if (ctx
->Multisample
.SampleAlphaToOne
)
2969 blend
.AlphaToOneEnable
= true;
2973 if (ctx
->Color
.AlphaEnabled
) {
2974 blend
.AlphaTestEnable
= true;
2975 blend
.AlphaTestFunction
=
2976 intel_translate_compare_func(ctx
->Color
.AlphaFunc
);
2979 if (ctx
->Color
.DitherFlag
) {
2980 blend
.ColorDitherEnable
= true;
2985 for (int i
= 0; i
< nr_draw_buffers
; i
++) {
2986 struct GENX(BLEND_STATE_ENTRY
) entry
= { 0 };
2990 blend
.IndependentAlphaBlendEnable
=
2991 set_blend_entry_bits(brw
, &entry
, i
, blend
.AlphaToOneEnable
) ||
2992 blend
.IndependentAlphaBlendEnable
;
2994 /* See section 8.1.6 "Pre-Blend Color Clamping" of the
2995 * SandyBridge PRM Volume 2 Part 1 for HW requirements.
2997 * We do our ARB_color_buffer_float CLAMP_FRAGMENT_COLOR
2998 * clamping in the fragment shader. For its clamping of
2999 * blending, the spec says:
3001 * "RESOLVED: For fixed-point color buffers, the inputs and
3002 * the result of the blending equation are clamped. For
3003 * floating-point color buffers, no clamping occurs."
3005 * So, generally, we want clamping to the render target's range.
3006 * And, good news, the hardware tables for both pre- and
3007 * post-blend color clamping are either ignored, or any are
3008 * allowed, or clamping is required but RT range clamping is a
3011 entry
.PreBlendColorClampEnable
= true;
3012 entry
.PostBlendColorClampEnable
= true;
3013 entry
.ColorClampRange
= COLORCLAMP_RTFORMAT
;
3015 entry
.WriteDisableRed
= !GET_COLORMASK_BIT(ctx
->Color
.ColorMask
, i
, 0);
3016 entry
.WriteDisableGreen
= !GET_COLORMASK_BIT(ctx
->Color
.ColorMask
, i
, 1);
3017 entry
.WriteDisableBlue
= !GET_COLORMASK_BIT(ctx
->Color
.ColorMask
, i
, 2);
3018 entry
.WriteDisableAlpha
= !GET_COLORMASK_BIT(ctx
->Color
.ColorMask
, i
, 3);
3021 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, &blend_map
[1 + i
* 2], &entry
);
3023 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, &blend_map
[i
* 2], &entry
);
3029 GENX(BLEND_STATE_pack
)(NULL
, blend_map
, &blend
);
3033 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
3034 ptr
.PointertoBLEND_STATE
= brw
->cc
.blend_state_offset
;
3035 ptr
.BLEND_STATEChange
= true;
3038 brw_batch_emit(brw
, GENX(3DSTATE_BLEND_STATE_POINTERS
), ptr
) {
3039 ptr
.BlendStatePointer
= brw
->cc
.blend_state_offset
;
3041 ptr
.BlendStatePointerValid
= true;
3047 UNUSED
static const struct brw_tracked_state
genX(blend_state
) = {
3049 .mesa
= _NEW_BUFFERS
|
3052 .brw
= BRW_NEW_BATCH
|
3054 BRW_NEW_FS_PROG_DATA
|
3055 BRW_NEW_STATE_BASE_ADDRESS
,
3057 .emit
= genX(upload_blend_state
),
3061 /* ---------------------------------------------------------------------- */
3064 UNUSED
static const uint32_t push_constant_opcodes
[] = {
3065 [MESA_SHADER_VERTEX
] = 21,
3066 [MESA_SHADER_TESS_CTRL
] = 25, /* HS */
3067 [MESA_SHADER_TESS_EVAL
] = 26, /* DS */
3068 [MESA_SHADER_GEOMETRY
] = 22,
3069 [MESA_SHADER_FRAGMENT
] = 23,
3070 [MESA_SHADER_COMPUTE
] = 0,
3074 genX(upload_push_constant_packets
)(struct brw_context
*brw
)
3076 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
3077 struct gl_context
*ctx
= &brw
->ctx
;
3079 UNUSED
uint32_t mocs
= GEN_GEN
< 8 ? GEN7_MOCS_L3
: 0;
3081 struct brw_stage_state
*stage_states
[] = {
3089 if (GEN_GEN
== 7 && !GEN_IS_HASWELL
&& !devinfo
->is_baytrail
&&
3090 stage_states
[MESA_SHADER_VERTEX
]->push_constants_dirty
)
3091 gen7_emit_vs_workaround_flush(brw
);
3093 for (int stage
= 0; stage
<= MESA_SHADER_FRAGMENT
; stage
++) {
3094 struct brw_stage_state
*stage_state
= stage_states
[stage
];
3095 UNUSED
struct gl_program
*prog
= ctx
->_Shader
->CurrentProgram
[stage
];
3097 if (!stage_state
->push_constants_dirty
)
3100 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_VS
), pkt
) {
3101 pkt
._3DCommandSubOpcode
= push_constant_opcodes
[stage
];
3102 if (stage_state
->prog_data
) {
3103 #if GEN_GEN >= 8 || GEN_IS_HASWELL
3104 /* The Skylake PRM contains the following restriction:
3106 * "The driver must ensure The following case does not occur
3107 * without a flush to the 3D engine: 3DSTATE_CONSTANT_* with
3108 * buffer 3 read length equal to zero committed followed by a
3109 * 3DSTATE_CONSTANT_* with buffer 0 read length not equal to
3112 * To avoid this, we program the buffers in the highest slots.
3113 * This way, slot 0 is only used if slot 3 is also used.
3117 for (int i
= 3; i
>= 0; i
--) {
3118 const struct brw_ubo_range
*range
=
3119 &stage_state
->prog_data
->ubo_ranges
[i
];
3121 if (range
->length
== 0)
3124 const struct gl_uniform_block
*block
=
3125 prog
->sh
.UniformBlocks
[range
->block
];
3126 const struct gl_buffer_binding
*binding
=
3127 &ctx
->UniformBufferBindings
[block
->Binding
];
3129 if (!binding
->BufferObject
) {
3130 static unsigned msg_id
= 0;
3131 _mesa_gl_debugf(ctx
, &msg_id
, MESA_DEBUG_SOURCE_API
,
3132 MESA_DEBUG_TYPE_UNDEFINED
,
3133 MESA_DEBUG_SEVERITY_HIGH
,
3134 "UBO %d unbound, %s shader uniform data "
3135 "will be undefined.",
3137 _mesa_shader_stage_to_string(stage
));
3141 assert(binding
->Offset
% 32 == 0);
3143 struct brw_bo
*bo
= intel_bufferobj_buffer(brw
,
3144 intel_buffer_object(binding
->BufferObject
),
3145 binding
->Offset
, range
->length
* 32, false);
3147 pkt
.ConstantBody
.ReadLength
[n
] = range
->length
;
3148 pkt
.ConstantBody
.Buffer
[n
] =
3149 ro_bo(bo
, range
->start
* 32 + binding
->Offset
);
3153 if (stage_state
->push_const_size
> 0) {
3155 pkt
.ConstantBody
.ReadLength
[n
] = stage_state
->push_const_size
;
3156 pkt
.ConstantBody
.Buffer
[n
] =
3157 ro_bo(stage_state
->push_const_bo
,
3158 stage_state
->push_const_offset
);
3161 pkt
.ConstantBody
.ReadLength
[0] = stage_state
->push_const_size
;
3162 pkt
.ConstantBody
.Buffer
[0].offset
=
3163 stage_state
->push_const_offset
| mocs
;
3168 stage_state
->push_constants_dirty
= false;
3169 brw
->ctx
.NewDriverState
|= GEN_GEN
>= 9 ? BRW_NEW_SURFACES
: 0;
3173 const struct brw_tracked_state
genX(push_constant_packets
) = {
3176 .brw
= BRW_NEW_DRAW_CALL
,
3178 .emit
= genX(upload_push_constant_packets
),
3184 genX(upload_vs_push_constants
)(struct brw_context
*brw
)
3186 struct brw_stage_state
*stage_state
= &brw
->vs
.base
;
3188 /* BRW_NEW_VERTEX_PROGRAM */
3189 const struct gl_program
*vp
= brw
->programs
[MESA_SHADER_VERTEX
];
3190 /* BRW_NEW_VS_PROG_DATA */
3191 const struct brw_stage_prog_data
*prog_data
= brw
->vs
.base
.prog_data
;
3193 gen6_upload_push_constants(brw
, vp
, prog_data
, stage_state
);
3196 static const struct brw_tracked_state
genX(vs_push_constants
) = {
3198 .mesa
= _NEW_PROGRAM_CONSTANTS
|
3200 .brw
= BRW_NEW_BATCH
|
3202 BRW_NEW_VERTEX_PROGRAM
|
3203 BRW_NEW_VS_PROG_DATA
,
3205 .emit
= genX(upload_vs_push_constants
),
3209 genX(upload_gs_push_constants
)(struct brw_context
*brw
)
3211 struct brw_stage_state
*stage_state
= &brw
->gs
.base
;
3213 /* BRW_NEW_GEOMETRY_PROGRAM */
3214 const struct gl_program
*gp
= brw
->programs
[MESA_SHADER_GEOMETRY
];
3216 /* BRW_NEW_GS_PROG_DATA */
3217 struct brw_stage_prog_data
*prog_data
= brw
->gs
.base
.prog_data
;
3219 gen6_upload_push_constants(brw
, gp
, prog_data
, stage_state
);
3222 static const struct brw_tracked_state
genX(gs_push_constants
) = {
3224 .mesa
= _NEW_PROGRAM_CONSTANTS
|
3226 .brw
= BRW_NEW_BATCH
|
3228 BRW_NEW_GEOMETRY_PROGRAM
|
3229 BRW_NEW_GS_PROG_DATA
,
3231 .emit
= genX(upload_gs_push_constants
),
3235 genX(upload_wm_push_constants
)(struct brw_context
*brw
)
3237 struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
3238 /* BRW_NEW_FRAGMENT_PROGRAM */
3239 const struct gl_program
*fp
= brw
->programs
[MESA_SHADER_FRAGMENT
];
3240 /* BRW_NEW_FS_PROG_DATA */
3241 const struct brw_stage_prog_data
*prog_data
= brw
->wm
.base
.prog_data
;
3243 gen6_upload_push_constants(brw
, fp
, prog_data
, stage_state
);
3246 static const struct brw_tracked_state
genX(wm_push_constants
) = {
3248 .mesa
= _NEW_PROGRAM_CONSTANTS
,
3249 .brw
= BRW_NEW_BATCH
|
3251 BRW_NEW_FRAGMENT_PROGRAM
|
3252 BRW_NEW_FS_PROG_DATA
,
3254 .emit
= genX(upload_wm_push_constants
),
3258 /* ---------------------------------------------------------------------- */
3262 genX(determine_sample_mask
)(struct brw_context
*brw
)
3264 struct gl_context
*ctx
= &brw
->ctx
;
3265 float coverage
= 1.0f
;
3266 float coverage_invert
= false;
3267 unsigned sample_mask
= ~0u;
3269 /* BRW_NEW_NUM_SAMPLES */
3270 unsigned num_samples
= brw
->num_samples
;
3272 if (_mesa_is_multisample_enabled(ctx
)) {
3273 if (ctx
->Multisample
.SampleCoverage
) {
3274 coverage
= ctx
->Multisample
.SampleCoverageValue
;
3275 coverage_invert
= ctx
->Multisample
.SampleCoverageInvert
;
3277 if (ctx
->Multisample
.SampleMask
) {
3278 sample_mask
= ctx
->Multisample
.SampleMaskValue
;
3282 if (num_samples
> 1) {
3283 int coverage_int
= (int) (num_samples
* coverage
+ 0.5f
);
3284 uint32_t coverage_bits
= (1 << coverage_int
) - 1;
3285 if (coverage_invert
)
3286 coverage_bits
^= (1 << num_samples
) - 1;
3287 return coverage_bits
& sample_mask
;
3294 genX(emit_3dstate_multisample2
)(struct brw_context
*brw
,
3295 unsigned num_samples
)
3297 unsigned log2_samples
= ffs(num_samples
) - 1;
3299 brw_batch_emit(brw
, GENX(3DSTATE_MULTISAMPLE
), multi
) {
3300 multi
.PixelLocation
= CENTER
;
3301 multi
.NumberofMultisamples
= log2_samples
;
3303 GEN_SAMPLE_POS_4X(multi
.Sample
);
3305 switch (num_samples
) {
3307 GEN_SAMPLE_POS_1X(multi
.Sample
);
3310 GEN_SAMPLE_POS_2X(multi
.Sample
);
3313 GEN_SAMPLE_POS_4X(multi
.Sample
);
3316 GEN_SAMPLE_POS_8X(multi
.Sample
);
3326 genX(upload_multisample_state
)(struct brw_context
*brw
)
3328 assert(brw
->num_samples
> 0 && brw
->num_samples
<= 16);
3330 genX(emit_3dstate_multisample2
)(brw
, brw
->num_samples
);
3332 brw_batch_emit(brw
, GENX(3DSTATE_SAMPLE_MASK
), sm
) {
3333 sm
.SampleMask
= genX(determine_sample_mask
)(brw
);
3337 static const struct brw_tracked_state
genX(multisample_state
) = {
3339 .mesa
= _NEW_MULTISAMPLE
|
3340 (GEN_GEN
== 10 ? _NEW_BUFFERS
: 0),
3341 .brw
= BRW_NEW_BLORP
|
3343 BRW_NEW_NUM_SAMPLES
,
3345 .emit
= genX(upload_multisample_state
)
3349 /* ---------------------------------------------------------------------- */
3352 genX(upload_color_calc_state
)(struct brw_context
*brw
)
3354 struct gl_context
*ctx
= &brw
->ctx
;
3356 brw_state_emit(brw
, GENX(COLOR_CALC_STATE
), 64, &brw
->cc
.state_offset
, cc
) {
3358 cc
.IndependentAlphaBlendEnable
=
3359 set_blend_entry_bits(brw
, &cc
, 0, false);
3360 set_depth_stencil_bits(brw
, &cc
);
3362 if (ctx
->Color
.AlphaEnabled
&&
3363 ctx
->DrawBuffer
->_NumColorDrawBuffers
<= 1) {
3364 cc
.AlphaTestEnable
= true;
3365 cc
.AlphaTestFunction
=
3366 intel_translate_compare_func(ctx
->Color
.AlphaFunc
);
3369 cc
.ColorDitherEnable
= ctx
->Color
.DitherFlag
;
3371 cc
.StatisticsEnable
= brw
->stats_wm
;
3373 cc
.CCViewportStatePointer
=
3374 ro_bo(brw
->batch
.state
.bo
, brw
->cc
.vp_offset
);
3377 cc
.BlendConstantColorRed
= ctx
->Color
.BlendColorUnclamped
[0];
3378 cc
.BlendConstantColorGreen
= ctx
->Color
.BlendColorUnclamped
[1];
3379 cc
.BlendConstantColorBlue
= ctx
->Color
.BlendColorUnclamped
[2];
3380 cc
.BlendConstantColorAlpha
= ctx
->Color
.BlendColorUnclamped
[3];
3384 cc
.StencilReferenceValue
= _mesa_get_stencil_ref(ctx
, 0);
3385 cc
.BackfaceStencilReferenceValue
=
3386 _mesa_get_stencil_ref(ctx
, ctx
->Stencil
._BackFace
);
3392 UNCLAMPED_FLOAT_TO_UBYTE(cc
.AlphaReferenceValueAsUNORM8
,
3393 ctx
->Color
.AlphaRef
);
3397 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
3398 ptr
.ColorCalcStatePointer
= brw
->cc
.state_offset
;
3400 ptr
.ColorCalcStatePointerValid
= true;
3404 brw
->ctx
.NewDriverState
|= BRW_NEW_GEN4_UNIT_STATE
;
3408 UNUSED
static const struct brw_tracked_state
genX(color_calc_state
) = {
3410 .mesa
= _NEW_COLOR
|
3412 (GEN_GEN
<= 5 ? _NEW_BUFFERS
|
3415 .brw
= BRW_NEW_BATCH
|
3417 (GEN_GEN
<= 5 ? BRW_NEW_CC_VP
|
3419 : BRW_NEW_CC_STATE
|
3420 BRW_NEW_STATE_BASE_ADDRESS
),
3422 .emit
= genX(upload_color_calc_state
),
3426 /* ---------------------------------------------------------------------- */
3430 genX(upload_color_calc_and_blend_state
)(struct brw_context
*brw
)
3432 genX(upload_blend_state
)(brw
);
3433 genX(upload_color_calc_state
)(brw
);
3436 /* On Haswell when BLEND_STATE is emitted CC_STATE should also be re-emitted,
3437 * this workarounds the flickering shadows in several games.
3439 static const struct brw_tracked_state
genX(cc_and_blend_state
) = {
3441 .mesa
= _NEW_BUFFERS
|
3445 .brw
= BRW_NEW_BATCH
|
3448 BRW_NEW_FS_PROG_DATA
|
3449 BRW_NEW_STATE_BASE_ADDRESS
,
3451 .emit
= genX(upload_color_calc_and_blend_state
),
3455 /* ---------------------------------------------------------------------- */
3459 genX(upload_sbe
)(struct brw_context
*brw
)
3461 struct gl_context
*ctx
= &brw
->ctx
;
3462 /* BRW_NEW_FRAGMENT_PROGRAM */
3463 UNUSED
const struct gl_program
*fp
= brw
->programs
[MESA_SHADER_FRAGMENT
];
3464 /* BRW_NEW_FS_PROG_DATA */
3465 const struct brw_wm_prog_data
*wm_prog_data
=
3466 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
3468 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = { { 0 } };
3470 #define attr_overrides sbe.Attribute
3472 uint32_t urb_entry_read_length
;
3473 uint32_t urb_entry_read_offset
;
3474 uint32_t point_sprite_enables
;
3476 brw_batch_emit(brw
, GENX(3DSTATE_SBE
), sbe
) {
3477 sbe
.AttributeSwizzleEnable
= true;
3478 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
3481 bool flip_y
= ctx
->DrawBuffer
->FlipY
;
3485 * Window coordinates in an FBO are inverted, which means point
3486 * sprite origin must be inverted.
3488 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) == flip_y
)
3489 sbe
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
3491 sbe
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
3493 /* _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM,
3494 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM |
3495 * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA |
3496 * BRW_NEW_VUE_MAP_GEOM_OUT
3498 genX(calculate_attr_overrides
)(brw
,
3500 &point_sprite_enables
,
3501 &urb_entry_read_length
,
3502 &urb_entry_read_offset
);
3504 /* Typically, the URB entry read length and offset should be programmed
3505 * in 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active
3506 * stage which produces geometry. However, we don't know the proper
3507 * value until we call calculate_attr_overrides().
3509 * To fit with our existing code, we override the inherited values and
3510 * specify it here directly, as we did on previous generations.
3512 sbe
.VertexURBEntryReadLength
= urb_entry_read_length
;
3513 sbe
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
3514 sbe
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
3515 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
3518 sbe
.ForceVertexURBEntryReadLength
= true;
3519 sbe
.ForceVertexURBEntryReadOffset
= true;
3523 /* prepare the active component dwords */
3524 for (int i
= 0; i
< 32; i
++)
3525 sbe
.AttributeActiveComponentFormat
[i
] = ACTIVE_COMPONENT_XYZW
;
3530 brw_batch_emit(brw
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
3531 for (int i
= 0; i
< 16; i
++)
3532 sbes
.Attribute
[i
] = attr_overrides
[i
];
3536 #undef attr_overrides
3539 static const struct brw_tracked_state
genX(sbe_state
) = {
3541 .mesa
= _NEW_BUFFERS
|
3546 .brw
= BRW_NEW_BLORP
|
3548 BRW_NEW_FRAGMENT_PROGRAM
|
3549 BRW_NEW_FS_PROG_DATA
|
3550 BRW_NEW_GS_PROG_DATA
|
3551 BRW_NEW_TES_PROG_DATA
|
3552 BRW_NEW_VUE_MAP_GEOM_OUT
|
3553 (GEN_GEN
== 7 ? BRW_NEW_PRIMITIVE
3556 .emit
= genX(upload_sbe
),
3560 /* ---------------------------------------------------------------------- */
3564 * Outputs the 3DSTATE_SO_DECL_LIST command.
3566 * The data output is a series of 64-bit entries containing a SO_DECL per
3567 * stream. We only have one stream of rendering coming out of the GS unit, so
3568 * we only emit stream 0 (low 16 bits) SO_DECLs.
3571 genX(upload_3dstate_so_decl_list
)(struct brw_context
*brw
,
3572 const struct brw_vue_map
*vue_map
)
3574 struct gl_context
*ctx
= &brw
->ctx
;
3575 /* BRW_NEW_TRANSFORM_FEEDBACK */
3576 struct gl_transform_feedback_object
*xfb_obj
=
3577 ctx
->TransformFeedback
.CurrentObject
;
3578 const struct gl_transform_feedback_info
*linked_xfb_info
=
3579 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
3580 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
3581 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3582 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3583 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
3585 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
3587 memset(so_decl
, 0, sizeof(so_decl
));
3589 /* Construct the list of SO_DECLs to be emitted. The formatting of the
3590 * command feels strange -- each dword pair contains a SO_DECL per stream.
3592 for (unsigned i
= 0; i
< linked_xfb_info
->NumOutputs
; i
++) {
3593 const struct gl_transform_feedback_output
*output
=
3594 &linked_xfb_info
->Outputs
[i
];
3595 const int buffer
= output
->OutputBuffer
;
3596 const int varying
= output
->OutputRegister
;
3597 const unsigned stream_id
= output
->StreamId
;
3598 assert(stream_id
< MAX_VERTEX_STREAMS
);
3600 buffer_mask
[stream_id
] |= 1 << buffer
;
3602 assert(vue_map
->varying_to_slot
[varying
] >= 0);
3604 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
3605 * array. Instead, it simply increments DstOffset for the following
3606 * input by the number of components that should be skipped.
3608 * Our hardware is unusual in that it requires us to program SO_DECLs
3609 * for fake "hole" components, rather than simply taking the offset
3610 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
3611 * program as many size = 4 holes as we can, then a final hole to
3612 * accommodate the final 1, 2, or 3 remaining.
3614 int skip_components
= output
->DstOffset
- next_offset
[buffer
];
3616 while (skip_components
> 0) {
3617 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3619 .OutputBufferSlot
= output
->OutputBuffer
,
3620 .ComponentMask
= (1 << MIN2(skip_components
, 4)) - 1,
3622 skip_components
-= 4;
3625 next_offset
[buffer
] = output
->DstOffset
+ output
->NumComponents
;
3627 so_decl
[stream_id
][decls
[stream_id
]++] = (struct GENX(SO_DECL
)) {
3628 .OutputBufferSlot
= output
->OutputBuffer
,
3629 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
3631 ((1 << output
->NumComponents
) - 1) << output
->ComponentOffset
,
3634 if (decls
[stream_id
] > max_decls
)
3635 max_decls
= decls
[stream_id
];
3639 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_SO_DECL_LIST
), 3 + 2 * max_decls
,
3640 .StreamtoBufferSelects0
= buffer_mask
[0],
3641 .StreamtoBufferSelects1
= buffer_mask
[1],
3642 .StreamtoBufferSelects2
= buffer_mask
[2],
3643 .StreamtoBufferSelects3
= buffer_mask
[3],
3644 .NumEntries0
= decls
[0],
3645 .NumEntries1
= decls
[1],
3646 .NumEntries2
= decls
[2],
3647 .NumEntries3
= decls
[3]);
3649 for (int i
= 0; i
< max_decls
; i
++) {
3650 GENX(SO_DECL_ENTRY_pack
)(
3651 brw
, dw
+ 2 + i
* 2,
3652 &(struct GENX(SO_DECL_ENTRY
)) {
3653 .Stream0Decl
= so_decl
[0][i
],
3654 .Stream1Decl
= so_decl
[1][i
],
3655 .Stream2Decl
= so_decl
[2][i
],
3656 .Stream3Decl
= so_decl
[3][i
],
3662 genX(upload_3dstate_so_buffers
)(struct brw_context
*brw
)
3664 struct gl_context
*ctx
= &brw
->ctx
;
3665 /* BRW_NEW_TRANSFORM_FEEDBACK */
3666 struct gl_transform_feedback_object
*xfb_obj
=
3667 ctx
->TransformFeedback
.CurrentObject
;
3669 const struct gl_transform_feedback_info
*linked_xfb_info
=
3670 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
3672 struct brw_transform_feedback_object
*brw_obj
=
3673 (struct brw_transform_feedback_object
*) xfb_obj
;
3674 uint32_t mocs_wb
= GEN_GEN
>= 9 ? SKL_MOCS_WB
: BDW_MOCS_WB
;
3677 /* Set up the up to 4 output buffers. These are the ranges defined in the
3678 * gl_transform_feedback_object.
3680 for (int i
= 0; i
< 4; i
++) {
3681 struct intel_buffer_object
*bufferobj
=
3682 intel_buffer_object(xfb_obj
->Buffers
[i
]);
3683 uint32_t start
= xfb_obj
->Offset
[i
];
3684 uint32_t end
= ALIGN(start
+ xfb_obj
->Size
[i
], 4);
3685 uint32_t const size
= end
- start
;
3687 if (!bufferobj
|| !size
) {
3688 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
3689 sob
.SOBufferIndex
= i
;
3694 assert(start
% 4 == 0);
3696 intel_bufferobj_buffer(brw
, bufferobj
, start
, size
, true);
3697 assert(end
<= bo
->size
);
3699 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
3700 sob
.SOBufferIndex
= i
;
3702 sob
.SurfaceBaseAddress
= rw_bo(bo
, start
);
3704 sob
.SurfacePitch
= linked_xfb_info
->Buffers
[i
].Stride
* 4;
3705 sob
.SurfaceEndAddress
= rw_bo(bo
, end
);
3707 sob
.SOBufferEnable
= true;
3708 sob
.StreamOffsetWriteEnable
= true;
3709 sob
.StreamOutputBufferOffsetAddressEnable
= true;
3712 sob
.SurfaceSize
= MAX2(xfb_obj
->Size
[i
] / 4, 1) - 1;
3713 sob
.StreamOutputBufferOffsetAddress
=
3714 rw_bo(brw_obj
->offset_bo
, i
* sizeof(uint32_t));
3716 if (brw_obj
->zero_offsets
) {
3717 /* Zero out the offset and write that to offset_bo */
3718 sob
.StreamOffset
= 0;
3720 /* Use offset_bo as the "Stream Offset." */
3721 sob
.StreamOffset
= 0xFFFFFFFF;
3728 brw_obj
->zero_offsets
= false;
3733 query_active(struct gl_query_object
*q
)
3735 return q
&& q
->Active
;
3739 genX(upload_3dstate_streamout
)(struct brw_context
*brw
, bool active
,
3740 const struct brw_vue_map
*vue_map
)
3742 struct gl_context
*ctx
= &brw
->ctx
;
3743 /* BRW_NEW_TRANSFORM_FEEDBACK */
3744 struct gl_transform_feedback_object
*xfb_obj
=
3745 ctx
->TransformFeedback
.CurrentObject
;
3747 brw_batch_emit(brw
, GENX(3DSTATE_STREAMOUT
), sos
) {
3749 int urb_entry_read_offset
= 0;
3750 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
3751 urb_entry_read_offset
;
3753 sos
.SOFunctionEnable
= true;
3754 sos
.SOStatisticsEnable
= true;
3756 /* BRW_NEW_RASTERIZER_DISCARD */
3757 if (ctx
->RasterDiscard
) {
3758 if (!query_active(ctx
->Query
.PrimitivesGenerated
[0])) {
3759 sos
.RenderingDisable
= true;
3761 perf_debug("Rasterizer discard with a GL_PRIMITIVES_GENERATED "
3762 "query active relies on the clipper.\n");
3767 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
)
3768 sos
.ReorderMode
= TRAILING
;
3771 sos
.SOBufferEnable0
= xfb_obj
->Buffers
[0] != NULL
;
3772 sos
.SOBufferEnable1
= xfb_obj
->Buffers
[1] != NULL
;
3773 sos
.SOBufferEnable2
= xfb_obj
->Buffers
[2] != NULL
;
3774 sos
.SOBufferEnable3
= xfb_obj
->Buffers
[3] != NULL
;
3776 const struct gl_transform_feedback_info
*linked_xfb_info
=
3777 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
3778 /* Set buffer pitches; 0 means unbound. */
3779 if (xfb_obj
->Buffers
[0])
3780 sos
.Buffer0SurfacePitch
= linked_xfb_info
->Buffers
[0].Stride
* 4;
3781 if (xfb_obj
->Buffers
[1])
3782 sos
.Buffer1SurfacePitch
= linked_xfb_info
->Buffers
[1].Stride
* 4;
3783 if (xfb_obj
->Buffers
[2])
3784 sos
.Buffer2SurfacePitch
= linked_xfb_info
->Buffers
[2].Stride
* 4;
3785 if (xfb_obj
->Buffers
[3])
3786 sos
.Buffer3SurfacePitch
= linked_xfb_info
->Buffers
[3].Stride
* 4;
3789 /* We always read the whole vertex. This could be reduced at some
3790 * point by reading less and offsetting the register index in the
3793 sos
.Stream0VertexReadOffset
= urb_entry_read_offset
;
3794 sos
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
3795 sos
.Stream1VertexReadOffset
= urb_entry_read_offset
;
3796 sos
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
3797 sos
.Stream2VertexReadOffset
= urb_entry_read_offset
;
3798 sos
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
3799 sos
.Stream3VertexReadOffset
= urb_entry_read_offset
;
3800 sos
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
3806 genX(upload_sol
)(struct brw_context
*brw
)
3808 struct gl_context
*ctx
= &brw
->ctx
;
3809 /* BRW_NEW_TRANSFORM_FEEDBACK */
3810 bool active
= _mesa_is_xfb_active_and_unpaused(ctx
);
3813 genX(upload_3dstate_so_buffers
)(brw
);
3815 /* BRW_NEW_VUE_MAP_GEOM_OUT */
3816 genX(upload_3dstate_so_decl_list
)(brw
, &brw
->vue_map_geom_out
);
3819 /* Finally, set up the SOL stage. This command must always follow updates to
3820 * the nonpipelined SOL state (3DSTATE_SO_BUFFER, 3DSTATE_SO_DECL_LIST) or
3821 * MMIO register updates (current performed by the kernel at each batch
3824 genX(upload_3dstate_streamout
)(brw
, active
, &brw
->vue_map_geom_out
);
3827 static const struct brw_tracked_state
genX(sol_state
) = {
3830 .brw
= BRW_NEW_BATCH
|
3832 BRW_NEW_RASTERIZER_DISCARD
|
3833 BRW_NEW_VUE_MAP_GEOM_OUT
|
3834 BRW_NEW_TRANSFORM_FEEDBACK
,
3836 .emit
= genX(upload_sol
),
3840 /* ---------------------------------------------------------------------- */
3844 genX(upload_ps
)(struct brw_context
*brw
)
3846 UNUSED
const struct gl_context
*ctx
= &brw
->ctx
;
3847 UNUSED
const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
3849 /* BRW_NEW_FS_PROG_DATA */
3850 const struct brw_wm_prog_data
*prog_data
=
3851 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
3852 const struct brw_stage_state
*stage_state
= &brw
->wm
.base
;
3857 brw_batch_emit(brw
, GENX(3DSTATE_PS
), ps
) {
3858 /* Initialize the execution mask with VMask. Otherwise, derivatives are
3859 * incorrect for subspans where some of the pixels are unlit. We believe
3860 * the bit just didn't take effect in previous generations.
3862 ps
.VectorMaskEnable
= GEN_GEN
>= 8;
3865 * "Incorrect TDL's SSP address shift in SARB for 16:6 & 18:8 modes.
3866 * Disable the Sampler state prefetch functionality in the SARB by
3867 * programming 0xB000[30] to '1'."
3869 ps
.SamplerCount
= GEN_GEN
== 11 ?
3870 0 : DIV_ROUND_UP(CLAMP(stage_state
->sampler_count
, 0, 16), 4);
3872 /* BRW_NEW_FS_PROG_DATA */
3873 ps
.BindingTableEntryCount
= prog_data
->base
.binding_table
.size_bytes
/ 4;
3875 if (prog_data
->base
.use_alt_mode
)
3876 ps
.FloatingPointMode
= Alternate
;
3878 /* Haswell requires the sample mask to be set in this packet as well as
3879 * in 3DSTATE_SAMPLE_MASK; the values should match.
3882 /* _NEW_BUFFERS, _NEW_MULTISAMPLE */
3884 ps
.SampleMask
= genX(determine_sample_mask(brw
));
3887 /* 3DSTATE_PS expects the number of threads per PSD, which is always 64
3888 * for pre Gen11 and 128 for gen11+; On gen11+ If a programmed value is
3889 * k, it implies 2(k+1) threads. It implicitly scales for different GT
3890 * levels (which have some # of PSDs).
3892 * In Gen8 the format is U8-2 whereas in Gen9+ it is U9-1.
3895 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
3897 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
3899 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
3902 if (prog_data
->base
.nr_params
> 0 ||
3903 prog_data
->base
.ubo_ranges
[0].length
> 0)
3904 ps
.PushConstantEnable
= true;
3907 /* From the IVB PRM, volume 2 part 1, page 287:
3908 * "This bit is inserted in the PS payload header and made available to
3909 * the DataPort (either via the message header or via header bypass) to
3910 * indicate that oMask data (one or two phases) is included in Render
3911 * Target Write messages. If present, the oMask data is used to mask off
3914 ps
.oMaskPresenttoRenderTarget
= prog_data
->uses_omask
;
3916 /* The hardware wedges if you have this bit set but don't turn on any
3917 * dual source blend factors.
3919 * BRW_NEW_FS_PROG_DATA | _NEW_COLOR
3921 ps
.DualSourceBlendEnable
= prog_data
->dual_src_blend
&&
3922 (ctx
->Color
.BlendEnabled
& 1) &&
3923 ctx
->Color
.Blend
[0]._UsesDualSrc
;
3925 /* BRW_NEW_FS_PROG_DATA */
3926 ps
.AttributeEnable
= (prog_data
->num_varying_inputs
!= 0);
3929 /* From the documentation for this packet:
3930 * "If the PS kernel does not need the Position XY Offsets to
3931 * compute a Position Value, then this field should be programmed
3932 * to POSOFFSET_NONE."
3934 * "SW Recommendation: If the PS kernel needs the Position Offsets
3935 * to compute a Position XY value, this field should match Position
3936 * ZW Interpolation Mode to ensure a consistent position.xyzw
3939 * We only require XY sample offsets. So, this recommendation doesn't
3940 * look useful at the moment. We might need this in future.
3942 if (prog_data
->uses_pos_offset
)
3943 ps
.PositionXYOffsetSelect
= POSOFFSET_SAMPLE
;
3945 ps
.PositionXYOffsetSelect
= POSOFFSET_NONE
;
3947 ps
._8PixelDispatchEnable
= prog_data
->dispatch_8
;
3948 ps
._16PixelDispatchEnable
= prog_data
->dispatch_16
;
3949 ps
._32PixelDispatchEnable
= prog_data
->dispatch_32
;
3951 /* From the Sky Lake PRM 3DSTATE_PS::32 Pixel Dispatch Enable:
3953 * "When NUM_MULTISAMPLES = 16 or FORCE_SAMPLE_COUNT = 16, SIMD32
3954 * Dispatch must not be enabled for PER_PIXEL dispatch mode."
3956 * Since 16x MSAA is first introduced on SKL, we don't need to apply
3957 * the workaround on any older hardware.
3959 * BRW_NEW_NUM_SAMPLES
3961 if (GEN_GEN
>= 9 && !prog_data
->persample_dispatch
&&
3962 brw
->num_samples
== 16) {
3963 assert(ps
._8PixelDispatchEnable
|| ps
._16PixelDispatchEnable
);
3964 ps
._32PixelDispatchEnable
= false;
3967 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
3968 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 0);
3969 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
3970 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 1);
3971 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
3972 brw_wm_prog_data_dispatch_grf_start_reg(prog_data
, ps
, 2);
3974 ps
.KernelStartPointer0
= stage_state
->prog_offset
+
3975 brw_wm_prog_data_prog_offset(prog_data
, ps
, 0);
3976 ps
.KernelStartPointer1
= stage_state
->prog_offset
+
3977 brw_wm_prog_data_prog_offset(prog_data
, ps
, 1);
3978 ps
.KernelStartPointer2
= stage_state
->prog_offset
+
3979 brw_wm_prog_data_prog_offset(prog_data
, ps
, 2);
3981 if (prog_data
->base
.total_scratch
) {
3982 ps
.ScratchSpaceBasePointer
=
3983 rw_32_bo(stage_state
->scratch_bo
,
3984 ffs(stage_state
->per_thread_scratch
) - 11);
3989 static const struct brw_tracked_state
genX(ps_state
) = {
3991 .mesa
= _NEW_MULTISAMPLE
|
3992 (GEN_GEN
< 8 ? _NEW_BUFFERS
|
3995 .brw
= BRW_NEW_BATCH
|
3997 BRW_NEW_FS_PROG_DATA
|
3998 (GEN_GEN
>= 9 ? BRW_NEW_NUM_SAMPLES
: 0),
4000 .emit
= genX(upload_ps
),
4004 /* ---------------------------------------------------------------------- */
4008 genX(upload_hs_state
)(struct brw_context
*brw
)
4010 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
4011 struct brw_stage_state
*stage_state
= &brw
->tcs
.base
;
4012 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
4013 const struct brw_vue_prog_data
*vue_prog_data
=
4014 brw_vue_prog_data(stage_prog_data
);
4016 /* BRW_NEW_TES_PROG_DATA */
4017 struct brw_tcs_prog_data
*tcs_prog_data
=
4018 brw_tcs_prog_data(stage_prog_data
);
4020 if (!tcs_prog_data
) {
4021 brw_batch_emit(brw
, GENX(3DSTATE_HS
), hs
);
4023 brw_batch_emit(brw
, GENX(3DSTATE_HS
), hs
) {
4024 INIT_THREAD_DISPATCH_FIELDS(hs
, Vertex
);
4026 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
4027 hs
.IncludeVertexHandles
= true;
4029 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
4032 hs
.DispatchMode
= vue_prog_data
->dispatch_mode
;
4033 hs
.IncludePrimitiveID
= tcs_prog_data
->include_primitive_id
;
4039 static const struct brw_tracked_state
genX(hs_state
) = {
4042 .brw
= BRW_NEW_BATCH
|
4044 BRW_NEW_TCS_PROG_DATA
|
4045 BRW_NEW_TESS_PROGRAMS
,
4047 .emit
= genX(upload_hs_state
),
4051 genX(upload_ds_state
)(struct brw_context
*brw
)
4053 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
4054 const struct brw_stage_state
*stage_state
= &brw
->tes
.base
;
4055 struct brw_stage_prog_data
*stage_prog_data
= stage_state
->prog_data
;
4057 /* BRW_NEW_TES_PROG_DATA */
4058 const struct brw_tes_prog_data
*tes_prog_data
=
4059 brw_tes_prog_data(stage_prog_data
);
4060 const struct brw_vue_prog_data
*vue_prog_data
=
4061 brw_vue_prog_data(stage_prog_data
);
4063 if (!tes_prog_data
) {
4064 brw_batch_emit(brw
, GENX(3DSTATE_DS
), ds
);
4066 assert(GEN_GEN
< 11 ||
4067 vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
);
4069 brw_batch_emit(brw
, GENX(3DSTATE_DS
), ds
) {
4070 INIT_THREAD_DISPATCH_FIELDS(ds
, Patch
);
4072 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
4073 ds
.ComputeWCoordinateEnable
=
4074 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
4077 if (vue_prog_data
->dispatch_mode
== DISPATCH_MODE_SIMD8
)
4078 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
4079 ds
.UserClipDistanceCullTestEnableBitmask
=
4080 vue_prog_data
->cull_distance_mask
;
4086 static const struct brw_tracked_state
genX(ds_state
) = {
4089 .brw
= BRW_NEW_BATCH
|
4091 BRW_NEW_TESS_PROGRAMS
|
4092 BRW_NEW_TES_PROG_DATA
,
4094 .emit
= genX(upload_ds_state
),
4097 /* ---------------------------------------------------------------------- */
4100 upload_te_state(struct brw_context
*brw
)
4102 /* BRW_NEW_TESS_PROGRAMS */
4103 bool active
= brw
->programs
[MESA_SHADER_TESS_EVAL
];
4105 /* BRW_NEW_TES_PROG_DATA */
4106 const struct brw_tes_prog_data
*tes_prog_data
=
4107 brw_tes_prog_data(brw
->tes
.base
.prog_data
);
4110 brw_batch_emit(brw
, GENX(3DSTATE_TE
), te
) {
4111 te
.Partitioning
= tes_prog_data
->partitioning
;
4112 te
.OutputTopology
= tes_prog_data
->output_topology
;
4113 te
.TEDomain
= tes_prog_data
->domain
;
4115 te
.MaximumTessellationFactorOdd
= 63.0;
4116 te
.MaximumTessellationFactorNotOdd
= 64.0;
4119 brw_batch_emit(brw
, GENX(3DSTATE_TE
), te
);
4123 static const struct brw_tracked_state
genX(te_state
) = {
4126 .brw
= BRW_NEW_BLORP
|
4128 BRW_NEW_TES_PROG_DATA
|
4129 BRW_NEW_TESS_PROGRAMS
,
4131 .emit
= upload_te_state
,
4134 /* ---------------------------------------------------------------------- */
4137 genX(upload_tes_push_constants
)(struct brw_context
*brw
)
4139 struct brw_stage_state
*stage_state
= &brw
->tes
.base
;
4140 /* BRW_NEW_TESS_PROGRAMS */
4141 const struct gl_program
*tep
= brw
->programs
[MESA_SHADER_TESS_EVAL
];
4143 /* BRW_NEW_TES_PROG_DATA */
4144 const struct brw_stage_prog_data
*prog_data
= brw
->tes
.base
.prog_data
;
4145 gen6_upload_push_constants(brw
, tep
, prog_data
, stage_state
);
4148 static const struct brw_tracked_state
genX(tes_push_constants
) = {
4150 .mesa
= _NEW_PROGRAM_CONSTANTS
,
4151 .brw
= BRW_NEW_BATCH
|
4153 BRW_NEW_TESS_PROGRAMS
|
4154 BRW_NEW_TES_PROG_DATA
,
4156 .emit
= genX(upload_tes_push_constants
),
4160 genX(upload_tcs_push_constants
)(struct brw_context
*brw
)
4162 struct brw_stage_state
*stage_state
= &brw
->tcs
.base
;
4163 /* BRW_NEW_TESS_PROGRAMS */
4164 const struct gl_program
*tcp
= brw
->programs
[MESA_SHADER_TESS_CTRL
];
4166 /* BRW_NEW_TCS_PROG_DATA */
4167 const struct brw_stage_prog_data
*prog_data
= brw
->tcs
.base
.prog_data
;
4169 gen6_upload_push_constants(brw
, tcp
, prog_data
, stage_state
);
4172 static const struct brw_tracked_state
genX(tcs_push_constants
) = {
4174 .mesa
= _NEW_PROGRAM_CONSTANTS
,
4175 .brw
= BRW_NEW_BATCH
|
4177 BRW_NEW_DEFAULT_TESS_LEVELS
|
4178 BRW_NEW_TESS_PROGRAMS
|
4179 BRW_NEW_TCS_PROG_DATA
,
4181 .emit
= genX(upload_tcs_push_constants
),
4186 /* ---------------------------------------------------------------------- */
4190 genX(upload_cs_push_constants
)(struct brw_context
*brw
)
4192 struct brw_stage_state
*stage_state
= &brw
->cs
.base
;
4194 /* BRW_NEW_COMPUTE_PROGRAM */
4195 const struct gl_program
*cp
= brw
->programs
[MESA_SHADER_COMPUTE
];
4198 /* BRW_NEW_CS_PROG_DATA */
4199 struct brw_cs_prog_data
*cs_prog_data
=
4200 brw_cs_prog_data(brw
->cs
.base
.prog_data
);
4202 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_COMPUTE
);
4203 brw_upload_cs_push_constants(brw
, cp
, cs_prog_data
, stage_state
);
4207 const struct brw_tracked_state
genX(cs_push_constants
) = {
4209 .mesa
= _NEW_PROGRAM_CONSTANTS
,
4210 .brw
= BRW_NEW_BATCH
|
4212 BRW_NEW_COMPUTE_PROGRAM
|
4213 BRW_NEW_CS_PROG_DATA
,
4215 .emit
= genX(upload_cs_push_constants
),
4219 * Creates a new CS constant buffer reflecting the current CS program's
4220 * constants, if needed by the CS program.
4223 genX(upload_cs_pull_constants
)(struct brw_context
*brw
)
4225 struct brw_stage_state
*stage_state
= &brw
->cs
.base
;
4227 /* BRW_NEW_COMPUTE_PROGRAM */
4228 struct brw_program
*cp
=
4229 (struct brw_program
*) brw
->programs
[MESA_SHADER_COMPUTE
];
4231 /* BRW_NEW_CS_PROG_DATA */
4232 const struct brw_stage_prog_data
*prog_data
= brw
->cs
.base
.prog_data
;
4234 _mesa_shader_write_subroutine_indices(&brw
->ctx
, MESA_SHADER_COMPUTE
);
4235 /* _NEW_PROGRAM_CONSTANTS */
4236 brw_upload_pull_constants(brw
, BRW_NEW_SURFACES
, &cp
->program
,
4237 stage_state
, prog_data
);
4240 const struct brw_tracked_state
genX(cs_pull_constants
) = {
4242 .mesa
= _NEW_PROGRAM_CONSTANTS
,
4243 .brw
= BRW_NEW_BATCH
|
4245 BRW_NEW_COMPUTE_PROGRAM
|
4246 BRW_NEW_CS_PROG_DATA
,
4248 .emit
= genX(upload_cs_pull_constants
),
4252 genX(upload_cs_state
)(struct brw_context
*brw
)
4254 if (!brw
->cs
.base
.prog_data
)
4258 uint32_t *desc
= (uint32_t*) brw_state_batch(
4259 brw
, GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t), 64,
4262 struct brw_stage_state
*stage_state
= &brw
->cs
.base
;
4263 struct brw_stage_prog_data
*prog_data
= stage_state
->prog_data
;
4264 struct brw_cs_prog_data
*cs_prog_data
= brw_cs_prog_data(prog_data
);
4265 const struct gen_device_info
*devinfo
= &brw
->screen
->devinfo
;
4267 const struct brw_cs_parameters cs_params
= brw_cs_get_parameters(brw
);
4269 if (INTEL_DEBUG
& DEBUG_SHADER_TIME
) {
4270 brw_emit_buffer_surface_state(
4271 brw
, &stage_state
->surf_offset
[
4272 prog_data
->binding_table
.shader_time_start
],
4273 brw
->shader_time
.bo
, 0, ISL_FORMAT_RAW
,
4274 brw
->shader_time
.bo
->size
, 1,
4278 uint32_t *bind
= brw_state_batch(brw
, prog_data
->binding_table
.size_bytes
,
4279 32, &stage_state
->bind_bo_offset
);
4281 /* The MEDIA_VFE_STATE documentation for Gen8+ says:
4283 * "A stalling PIPE_CONTROL is required before MEDIA_VFE_STATE unless
4284 * the only bits that are changed are scoreboard related: Scoreboard
4285 * Enable, Scoreboard Type, Scoreboard Mask, Scoreboard * Delta. For
4286 * these scoreboard related states, a MEDIA_STATE_FLUSH is sufficient."
4288 * Earlier generations say "MI_FLUSH" instead of "stalling PIPE_CONTROL",
4289 * but MI_FLUSH isn't really a thing, so we assume they meant PIPE_CONTROL.
4291 brw_emit_pipe_control_flush(brw
, PIPE_CONTROL_CS_STALL
);
4293 brw_batch_emit(brw
, GENX(MEDIA_VFE_STATE
), vfe
) {
4294 if (prog_data
->total_scratch
) {
4295 uint32_t per_thread_scratch_value
;
4298 /* Broadwell's Per Thread Scratch Space is in the range [0, 11]
4299 * where 0 = 1k, 1 = 2k, 2 = 4k, ..., 11 = 2M.
4301 per_thread_scratch_value
= ffs(stage_state
->per_thread_scratch
) - 11;
4302 } else if (GEN_IS_HASWELL
) {
4303 /* Haswell's Per Thread Scratch Space is in the range [0, 10]
4304 * where 0 = 2k, 1 = 4k, 2 = 8k, ..., 10 = 2M.
4306 per_thread_scratch_value
= ffs(stage_state
->per_thread_scratch
) - 12;
4308 /* Earlier platforms use the range [0, 11] to mean [1kB, 12kB]
4309 * where 0 = 1kB, 1 = 2kB, 2 = 3kB, ..., 11 = 12kB.
4311 per_thread_scratch_value
= stage_state
->per_thread_scratch
/ 1024 - 1;
4313 vfe
.ScratchSpaceBasePointer
= rw_32_bo(stage_state
->scratch_bo
, 0);
4314 vfe
.PerThreadScratchSpace
= per_thread_scratch_value
;
4317 /* If brw->screen->subslice_total is greater than one, then
4318 * devinfo->max_cs_threads stores number of threads per sub-slice;
4319 * thus we need to multiply by that number by subslices to get
4320 * the actual maximum number of threads; the -1 is because the HW
4321 * has a bias of 1 (would not make sense to say the maximum number
4324 const uint32_t subslices
= MAX2(brw
->screen
->subslice_total
, 1);
4325 vfe
.MaximumNumberofThreads
= devinfo
->max_cs_threads
* subslices
- 1;
4326 vfe
.NumberofURBEntries
= GEN_GEN
>= 8 ? 2 : 0;
4328 vfe
.ResetGatewayTimer
=
4329 Resettingrelativetimerandlatchingtheglobaltimestamp
;
4332 vfe
.BypassGatewayControl
= BypassingOpenGatewayCloseGatewayprotocol
;
4338 /* We are uploading duplicated copies of push constant uniforms for each
4339 * thread. Although the local id data needs to vary per thread, it won't
4340 * change for other uniform data. Unfortunately this duplication is
4341 * required for gen7. As of Haswell, this duplication can be avoided,
4342 * but this older mechanism with duplicated data continues to work.
4344 * FINISHME: As of Haswell, we could make use of the
4345 * INTERFACE_DESCRIPTOR_DATA "Cross-Thread Constant Data Read Length"
4346 * field to only store one copy of uniform data.
4348 * FINISHME: Broadwell adds a new alternative "Indirect Payload Storage"
4349 * which is described in the GPGPU_WALKER command and in the Broadwell
4350 * PRM Volume 7: 3D Media GPGPU, under Media GPGPU Pipeline => Mode of
4351 * Operations => GPGPU Mode => Indirect Payload Storage.
4353 * Note: The constant data is built in brw_upload_cs_push_constants
4356 vfe
.URBEntryAllocationSize
= GEN_GEN
>= 8 ? 2 : 0;
4358 const uint32_t vfe_curbe_allocation
=
4359 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_params
.threads
+
4360 cs_prog_data
->push
.cross_thread
.regs
, 2);
4361 vfe
.CURBEAllocationSize
= vfe_curbe_allocation
;
4364 const unsigned push_const_size
=
4365 brw_cs_push_const_total_size(cs_prog_data
, cs_params
.threads
);
4366 if (push_const_size
> 0) {
4367 brw_batch_emit(brw
, GENX(MEDIA_CURBE_LOAD
), curbe
) {
4368 curbe
.CURBETotalDataLength
= ALIGN(push_const_size
, 64);
4369 curbe
.CURBEDataStartAddress
= stage_state
->push_const_offset
;
4373 /* BRW_NEW_SURFACES and BRW_NEW_*_CONSTBUF */
4374 memcpy(bind
, stage_state
->surf_offset
,
4375 prog_data
->binding_table
.size_bytes
);
4376 const uint64_t ksp
= brw
->cs
.base
.prog_offset
+
4377 brw_cs_prog_data_prog_offset(cs_prog_data
,
4378 cs_params
.simd_size
);
4379 const struct GENX(INTERFACE_DESCRIPTOR_DATA
) idd
= {
4380 .KernelStartPointer
= ksp
,
4381 .SamplerStatePointer
= stage_state
->sampler_offset
,
4383 .SamplerCount
= GEN_GEN
== 11 ? 0 :
4384 DIV_ROUND_UP(CLAMP(stage_state
->sampler_count
, 0, 16), 4),
4385 .BindingTablePointer
= stage_state
->bind_bo_offset
,
4386 .ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
,
4387 .NumberofThreadsinGPGPUThreadGroup
= cs_params
.threads
,
4388 .SharedLocalMemorySize
= encode_slm_size(GEN_GEN
,
4389 prog_data
->total_shared
),
4390 .BarrierEnable
= cs_prog_data
->uses_barrier
,
4391 #if GEN_GEN >= 8 || GEN_IS_HASWELL
4392 .CrossThreadConstantDataReadLength
=
4393 cs_prog_data
->push
.cross_thread
.regs
,
4397 GENX(INTERFACE_DESCRIPTOR_DATA_pack
)(brw
, desc
, &idd
);
4399 brw_batch_emit(brw
, GENX(MEDIA_INTERFACE_DESCRIPTOR_LOAD
), load
) {
4400 load
.InterfaceDescriptorTotalLength
=
4401 GENX(INTERFACE_DESCRIPTOR_DATA_length
) * sizeof(uint32_t);
4402 load
.InterfaceDescriptorDataStartAddress
= offset
;
4406 static const struct brw_tracked_state
genX(cs_state
) = {
4408 .mesa
= _NEW_PROGRAM_CONSTANTS
,
4409 .brw
= BRW_NEW_BATCH
|
4411 BRW_NEW_CS_PROG_DATA
|
4412 BRW_NEW_SAMPLER_STATE_TABLE
|
4415 .emit
= genX(upload_cs_state
)
4418 #define GPGPU_DISPATCHDIMX 0x2500
4419 #define GPGPU_DISPATCHDIMY 0x2504
4420 #define GPGPU_DISPATCHDIMZ 0x2508
4422 #define MI_PREDICATE_SRC0 0x2400
4423 #define MI_PREDICATE_SRC1 0x2408
4426 prepare_indirect_gpgpu_walker(struct brw_context
*brw
)
4428 GLintptr indirect_offset
= brw
->compute
.num_work_groups_offset
;
4429 struct brw_bo
*bo
= brw
->compute
.num_work_groups_bo
;
4431 emit_lrm(brw
, GPGPU_DISPATCHDIMX
, ro_bo(bo
, indirect_offset
+ 0));
4432 emit_lrm(brw
, GPGPU_DISPATCHDIMY
, ro_bo(bo
, indirect_offset
+ 4));
4433 emit_lrm(brw
, GPGPU_DISPATCHDIMZ
, ro_bo(bo
, indirect_offset
+ 8));
4436 /* Clear upper 32-bits of SRC0 and all 64-bits of SRC1 */
4437 emit_lri(brw
, MI_PREDICATE_SRC0
+ 4, 0);
4438 emit_lri(brw
, MI_PREDICATE_SRC1
, 0);
4439 emit_lri(brw
, MI_PREDICATE_SRC1
+ 4, 0);
4441 /* Load compute_dispatch_indirect_x_size into SRC0 */
4442 emit_lrm(brw
, MI_PREDICATE_SRC0
, ro_bo(bo
, indirect_offset
+ 0));
4444 /* predicate = (compute_dispatch_indirect_x_size == 0); */
4445 brw_batch_emit(brw
, GENX(MI_PREDICATE
), mip
) {
4446 mip
.LoadOperation
= LOAD_LOAD
;
4447 mip
.CombineOperation
= COMBINE_SET
;
4448 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
4451 /* Load compute_dispatch_indirect_y_size into SRC0 */
4452 emit_lrm(brw
, MI_PREDICATE_SRC0
, ro_bo(bo
, indirect_offset
+ 4));
4454 /* predicate |= (compute_dispatch_indirect_y_size == 0); */
4455 brw_batch_emit(brw
, GENX(MI_PREDICATE
), mip
) {
4456 mip
.LoadOperation
= LOAD_LOAD
;
4457 mip
.CombineOperation
= COMBINE_OR
;
4458 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
4461 /* Load compute_dispatch_indirect_z_size into SRC0 */
4462 emit_lrm(brw
, MI_PREDICATE_SRC0
, ro_bo(bo
, indirect_offset
+ 8));
4464 /* predicate |= (compute_dispatch_indirect_z_size == 0); */
4465 brw_batch_emit(brw
, GENX(MI_PREDICATE
), mip
) {
4466 mip
.LoadOperation
= LOAD_LOAD
;
4467 mip
.CombineOperation
= COMBINE_OR
;
4468 mip
.CompareOperation
= COMPARE_SRCS_EQUAL
;
4471 /* predicate = !predicate; */
4472 #define COMPARE_FALSE 1
4473 brw_batch_emit(brw
, GENX(MI_PREDICATE
), mip
) {
4474 mip
.LoadOperation
= LOAD_LOADINV
;
4475 mip
.CombineOperation
= COMBINE_OR
;
4476 mip
.CompareOperation
= COMPARE_FALSE
;
4482 genX(emit_gpgpu_walker
)(struct brw_context
*brw
)
4484 const GLuint
*num_groups
= brw
->compute
.num_work_groups
;
4486 bool indirect
= brw
->compute
.num_work_groups_bo
!= NULL
;
4488 prepare_indirect_gpgpu_walker(brw
);
4490 const struct brw_cs_parameters cs_params
= brw_cs_get_parameters(brw
);
4492 const uint32_t right_mask
=
4493 brw_cs_right_mask(cs_params
.group_size
, cs_params
.simd_size
);
4495 brw_batch_emit(brw
, GENX(GPGPU_WALKER
), ggw
) {
4496 ggw
.IndirectParameterEnable
= indirect
;
4497 ggw
.PredicateEnable
= GEN_GEN
<= 7 && indirect
;
4498 ggw
.SIMDSize
= cs_params
.simd_size
/ 16;
4499 ggw
.ThreadDepthCounterMaximum
= 0;
4500 ggw
.ThreadHeightCounterMaximum
= 0;
4501 ggw
.ThreadWidthCounterMaximum
= cs_params
.threads
- 1;
4502 ggw
.ThreadGroupIDXDimension
= num_groups
[0];
4503 ggw
.ThreadGroupIDYDimension
= num_groups
[1];
4504 ggw
.ThreadGroupIDZDimension
= num_groups
[2];
4505 ggw
.RightExecutionMask
= right_mask
;
4506 ggw
.BottomExecutionMask
= 0xffffffff;
4509 brw_batch_emit(brw
, GENX(MEDIA_STATE_FLUSH
), msf
);
4514 /* ---------------------------------------------------------------------- */
4518 genX(upload_raster
)(struct brw_context
*brw
)
4520 const struct gl_context
*ctx
= &brw
->ctx
;
4523 const bool flip_y
= ctx
->DrawBuffer
->FlipY
;
4526 const struct gl_polygon_attrib
*polygon
= &ctx
->Polygon
;
4529 const struct gl_point_attrib
*point
= &ctx
->Point
;
4531 brw_batch_emit(brw
, GENX(3DSTATE_RASTER
), raster
) {
4532 if (brw
->polygon_front_bit
!= flip_y
)
4533 raster
.FrontWinding
= CounterClockwise
;
4535 if (polygon
->CullFlag
) {
4536 switch (polygon
->CullFaceMode
) {
4538 raster
.CullMode
= CULLMODE_FRONT
;
4541 raster
.CullMode
= CULLMODE_BACK
;
4543 case GL_FRONT_AND_BACK
:
4544 raster
.CullMode
= CULLMODE_BOTH
;
4547 unreachable("not reached");
4550 raster
.CullMode
= CULLMODE_NONE
;
4553 raster
.SmoothPointEnable
= point
->SmoothFlag
;
4555 raster
.DXMultisampleRasterizationEnable
=
4556 _mesa_is_multisample_enabled(ctx
);
4558 raster
.GlobalDepthOffsetEnableSolid
= polygon
->OffsetFill
;
4559 raster
.GlobalDepthOffsetEnableWireframe
= polygon
->OffsetLine
;
4560 raster
.GlobalDepthOffsetEnablePoint
= polygon
->OffsetPoint
;
4562 switch (polygon
->FrontMode
) {
4564 raster
.FrontFaceFillMode
= FILL_MODE_SOLID
;
4567 raster
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
4570 raster
.FrontFaceFillMode
= FILL_MODE_POINT
;
4573 unreachable("not reached");
4576 switch (polygon
->BackMode
) {
4578 raster
.BackFaceFillMode
= FILL_MODE_SOLID
;
4581 raster
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
4584 raster
.BackFaceFillMode
= FILL_MODE_POINT
;
4587 unreachable("not reached");
4591 raster
.AntialiasingEnable
= ctx
->Line
.SmoothFlag
;
4595 * Antialiasing Enable bit MUST not be set when NUM_MULTISAMPLES > 1.
4597 const bool multisampled_fbo
=
4598 _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
4599 if (multisampled_fbo
)
4600 raster
.AntialiasingEnable
= false;
4604 raster
.ScissorRectangleEnable
= ctx
->Scissor
.EnableFlags
;
4606 /* _NEW_TRANSFORM */
4608 if (!(ctx
->Transform
.DepthClampNear
&&
4609 ctx
->Transform
.DepthClampFar
))
4610 raster
.ViewportZClipTestEnable
= true;
4614 if (!ctx
->Transform
.DepthClampNear
)
4615 raster
.ViewportZNearClipTestEnable
= true;
4617 if (!ctx
->Transform
.DepthClampFar
)
4618 raster
.ViewportZFarClipTestEnable
= true;
4621 /* BRW_NEW_CONSERVATIVE_RASTERIZATION */
4623 raster
.ConservativeRasterizationEnable
=
4624 ctx
->IntelConservativeRasterization
;
4627 raster
.GlobalDepthOffsetClamp
= polygon
->OffsetClamp
;
4628 raster
.GlobalDepthOffsetScale
= polygon
->OffsetFactor
;
4630 raster
.GlobalDepthOffsetConstant
= polygon
->OffsetUnits
* 2;
4634 static const struct brw_tracked_state
genX(raster_state
) = {
4636 .mesa
= _NEW_BUFFERS
|
4643 .brw
= BRW_NEW_BLORP
|
4645 BRW_NEW_CONSERVATIVE_RASTERIZATION
,
4647 .emit
= genX(upload_raster
),
4651 /* ---------------------------------------------------------------------- */
4655 genX(upload_ps_extra
)(struct brw_context
*brw
)
4657 UNUSED
struct gl_context
*ctx
= &brw
->ctx
;
4659 const struct brw_wm_prog_data
*prog_data
=
4660 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
4662 brw_batch_emit(brw
, GENX(3DSTATE_PS_EXTRA
), psx
) {
4663 psx
.PixelShaderValid
= true;
4664 psx
.PixelShaderComputedDepthMode
= prog_data
->computed_depth_mode
;
4665 psx
.PixelShaderKillsPixel
= prog_data
->uses_kill
;
4666 psx
.AttributeEnable
= prog_data
->num_varying_inputs
!= 0;
4667 psx
.PixelShaderUsesSourceDepth
= prog_data
->uses_src_depth
;
4668 psx
.PixelShaderUsesSourceW
= prog_data
->uses_src_w
;
4669 psx
.PixelShaderIsPerSample
= prog_data
->persample_dispatch
;
4671 /* _NEW_MULTISAMPLE | BRW_NEW_CONSERVATIVE_RASTERIZATION */
4672 if (prog_data
->uses_sample_mask
) {
4674 if (prog_data
->post_depth_coverage
)
4675 psx
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
4676 else if (prog_data
->inner_coverage
&& ctx
->IntelConservativeRasterization
)
4677 psx
.InputCoverageMaskState
= ICMS_INNER_CONSERVATIVE
;
4679 psx
.InputCoverageMaskState
= ICMS_NORMAL
;
4681 psx
.PixelShaderUsesInputCoverageMask
= true;
4685 psx
.oMaskPresenttoRenderTarget
= prog_data
->uses_omask
;
4687 psx
.PixelShaderPullsBary
= prog_data
->pulls_bary
;
4688 psx
.PixelShaderComputesStencil
= prog_data
->computed_stencil
;
4691 /* The stricter cross-primitive coherency guarantees that the hardware
4692 * gives us with the "Accesses UAV" bit set for at least one shader stage
4693 * and the "UAV coherency required" bit set on the 3DPRIMITIVE command
4694 * are redundant within the current image, atomic counter and SSBO GL
4695 * APIs, which all have very loose ordering and coherency requirements
4696 * and generally rely on the application to insert explicit barriers when
4697 * a shader invocation is expected to see the memory writes performed by
4698 * the invocations of some previous primitive. Regardless of the value
4699 * of "UAV coherency required", the "Accesses UAV" bits will implicitly
4700 * cause an in most cases useless DC flush when the lowermost stage with
4701 * the bit set finishes execution.
4703 * It would be nice to disable it, but in some cases we can't because on
4704 * Gen8+ it also has an influence on rasterization via the PS UAV-only
4705 * signal (which could be set independently from the coherency mechanism
4706 * in the 3DSTATE_WM command on Gen7), and because in some cases it will
4707 * determine whether the hardware skips execution of the fragment shader
4708 * or not via the ThreadDispatchEnable signal. However if we know that
4709 * GEN8_PS_BLEND_HAS_WRITEABLE_RT is going to be set and
4710 * GEN8_PSX_PIXEL_SHADER_NO_RT_WRITE is not set it shouldn't make any
4711 * difference so we may just disable it here.
4713 * Gen8 hardware tries to compute ThreadDispatchEnable for us but doesn't
4714 * take into account KillPixels when no depth or stencil writes are
4715 * enabled. In order for occlusion queries to work correctly with no
4716 * attachments, we need to force-enable here.
4718 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM | _NEW_BUFFERS |
4721 if ((prog_data
->has_side_effects
|| prog_data
->uses_kill
) &&
4722 !brw_color_buffer_write_enabled(brw
))
4723 psx
.PixelShaderHasUAV
= true;
4727 const struct brw_tracked_state
genX(ps_extra
) = {
4729 .mesa
= _NEW_BUFFERS
| _NEW_COLOR
,
4730 .brw
= BRW_NEW_BLORP
|
4732 BRW_NEW_FRAGMENT_PROGRAM
|
4733 BRW_NEW_FS_PROG_DATA
|
4734 BRW_NEW_CONSERVATIVE_RASTERIZATION
,
4736 .emit
= genX(upload_ps_extra
),
4740 /* ---------------------------------------------------------------------- */
4744 genX(upload_ps_blend
)(struct brw_context
*brw
)
4746 struct gl_context
*ctx
= &brw
->ctx
;
4749 struct gl_renderbuffer
*rb
= ctx
->DrawBuffer
->_ColorDrawBuffers
[0];
4750 const bool buffer0_is_integer
= ctx
->DrawBuffer
->_IntegerBuffers
& 0x1;
4753 struct gl_colorbuffer_attrib
*color
= &ctx
->Color
;
4755 brw_batch_emit(brw
, GENX(3DSTATE_PS_BLEND
), pb
) {
4756 /* BRW_NEW_FRAGMENT_PROGRAM | _NEW_BUFFERS | _NEW_COLOR */
4757 pb
.HasWriteableRT
= brw_color_buffer_write_enabled(brw
);
4759 bool alpha_to_one
= false;
4761 if (!buffer0_is_integer
) {
4762 /* _NEW_MULTISAMPLE */
4764 if (_mesa_is_multisample_enabled(ctx
)) {
4765 pb
.AlphaToCoverageEnable
= ctx
->Multisample
.SampleAlphaToCoverage
;
4766 alpha_to_one
= ctx
->Multisample
.SampleAlphaToOne
;
4769 pb
.AlphaTestEnable
= color
->AlphaEnabled
;
4772 /* Used for implementing the following bit of GL_EXT_texture_integer:
4773 * "Per-fragment operations that require floating-point color
4774 * components, including multisample alpha operations, alpha test,
4775 * blending, and dithering, have no effect when the corresponding
4776 * colors are written to an integer color buffer."
4778 * The OpenGL specification 3.3 (page 196), section 4.1.3 says:
4779 * "If drawbuffer zero is not NONE and the buffer it references has an
4780 * integer format, the SAMPLE_ALPHA_TO_COVERAGE and SAMPLE_ALPHA_TO_ONE
4781 * operations are skipped."
4783 if (rb
&& !buffer0_is_integer
&& (color
->BlendEnabled
& 1)) {
4784 GLenum eqRGB
= color
->Blend
[0].EquationRGB
;
4785 GLenum eqA
= color
->Blend
[0].EquationA
;
4786 GLenum srcRGB
= color
->Blend
[0].SrcRGB
;
4787 GLenum dstRGB
= color
->Blend
[0].DstRGB
;
4788 GLenum srcA
= color
->Blend
[0].SrcA
;
4789 GLenum dstA
= color
->Blend
[0].DstA
;
4791 if (eqRGB
== GL_MIN
|| eqRGB
== GL_MAX
)
4792 srcRGB
= dstRGB
= GL_ONE
;
4794 if (eqA
== GL_MIN
|| eqA
== GL_MAX
)
4795 srcA
= dstA
= GL_ONE
;
4797 /* Due to hardware limitations, the destination may have information
4798 * in an alpha channel even when the format specifies no alpha
4799 * channel. In order to avoid getting any incorrect blending due to
4800 * that alpha channel, coerce the blend factors to values that will
4801 * not read the alpha channel, but will instead use the correct
4802 * implicit value for alpha.
4804 if (!_mesa_base_format_has_channel(rb
->_BaseFormat
,
4805 GL_TEXTURE_ALPHA_TYPE
)) {
4806 srcRGB
= brw_fix_xRGB_alpha(srcRGB
);
4807 srcA
= brw_fix_xRGB_alpha(srcA
);
4808 dstRGB
= brw_fix_xRGB_alpha(dstRGB
);
4809 dstA
= brw_fix_xRGB_alpha(dstA
);
4812 /* Alpha to One doesn't work with Dual Color Blending. Override
4813 * SRC1_ALPHA to ONE and ONE_MINUS_SRC1_ALPHA to ZERO.
4815 if (alpha_to_one
&& color
->Blend
[0]._UsesDualSrc
) {
4816 srcRGB
= fix_dual_blend_alpha_to_one(srcRGB
);
4817 srcA
= fix_dual_blend_alpha_to_one(srcA
);
4818 dstRGB
= fix_dual_blend_alpha_to_one(dstRGB
);
4819 dstA
= fix_dual_blend_alpha_to_one(dstA
);
4822 /* BRW_NEW_FS_PROG_DATA */
4823 const struct brw_wm_prog_data
*wm_prog_data
=
4824 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
4826 /* The Dual Source Blending documentation says:
4828 * "If SRC1 is included in a src/dst blend factor and
4829 * a DualSource RT Write message is not used, results
4830 * are UNDEFINED. (This reflects the same restriction in DX APIs,
4831 * where undefined results are produced if “o1” is not written
4832 * by a PS – there are no default values defined).
4833 * If SRC1 is not included in a src/dst blend factor,
4834 * dual source blending must be disabled."
4836 * There is no way to gracefully fix this undefined situation
4837 * so we just disable the blending to prevent possible issues.
4839 pb
.ColorBufferBlendEnable
=
4840 !color
->Blend
[0]._UsesDualSrc
|| wm_prog_data
->dual_src_blend
;
4841 pb
.SourceAlphaBlendFactor
= brw_translate_blend_factor(srcA
);
4842 pb
.DestinationAlphaBlendFactor
= brw_translate_blend_factor(dstA
);
4843 pb
.SourceBlendFactor
= brw_translate_blend_factor(srcRGB
);
4844 pb
.DestinationBlendFactor
= brw_translate_blend_factor(dstRGB
);
4846 pb
.IndependentAlphaBlendEnable
=
4847 srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
;
4852 static const struct brw_tracked_state
genX(ps_blend
) = {
4854 .mesa
= _NEW_BUFFERS
|
4857 .brw
= BRW_NEW_BLORP
|
4859 BRW_NEW_FRAGMENT_PROGRAM
|
4860 BRW_NEW_FS_PROG_DATA
,
4862 .emit
= genX(upload_ps_blend
)
4866 /* ---------------------------------------------------------------------- */
4870 genX(emit_vf_topology
)(struct brw_context
*brw
)
4872 brw_batch_emit(brw
, GENX(3DSTATE_VF_TOPOLOGY
), vftopo
) {
4873 vftopo
.PrimitiveTopologyType
= brw
->primitive
;
4877 static const struct brw_tracked_state
genX(vf_topology
) = {
4880 .brw
= BRW_NEW_BLORP
|
4883 .emit
= genX(emit_vf_topology
),
4887 /* ---------------------------------------------------------------------- */
4891 genX(emit_mi_report_perf_count
)(struct brw_context
*brw
,
4893 uint32_t offset_in_bytes
,
4896 brw_batch_emit(brw
, GENX(MI_REPORT_PERF_COUNT
), mi_rpc
) {
4897 mi_rpc
.MemoryAddress
= ggtt_bo(bo
, offset_in_bytes
);
4898 mi_rpc
.ReportID
= report_id
;
4903 /* ---------------------------------------------------------------------- */
4906 * Emit a 3DSTATE_SAMPLER_STATE_POINTERS_{VS,HS,GS,DS,PS} packet.
4909 genX(emit_sampler_state_pointers_xs
)(UNUSED
struct brw_context
*brw
,
4910 UNUSED
struct brw_stage_state
*stage_state
)
4913 static const uint16_t packet_headers
[] = {
4914 [MESA_SHADER_VERTEX
] = 43,
4915 [MESA_SHADER_TESS_CTRL
] = 44,
4916 [MESA_SHADER_TESS_EVAL
] = 45,
4917 [MESA_SHADER_GEOMETRY
] = 46,
4918 [MESA_SHADER_FRAGMENT
] = 47,
4921 /* Ivybridge requires a workaround flush before VS packets. */
4922 if (GEN_GEN
== 7 && !GEN_IS_HASWELL
&&
4923 stage_state
->stage
== MESA_SHADER_VERTEX
) {
4924 gen7_emit_vs_workaround_flush(brw
);
4927 brw_batch_emit(brw
, GENX(3DSTATE_SAMPLER_STATE_POINTERS_VS
), ptr
) {
4928 ptr
._3DCommandSubOpcode
= packet_headers
[stage_state
->stage
];
4929 ptr
.PointertoVSSamplerState
= stage_state
->sampler_offset
;
4935 has_component(mesa_format format
, int i
)
4937 if (_mesa_is_format_color_format(format
))
4938 return _mesa_format_has_color_component(format
, i
);
4940 /* depth and stencil have only one component */
4945 * Upload SAMPLER_BORDER_COLOR_STATE.
4948 genX(upload_default_color
)(struct brw_context
*brw
,
4949 const struct gl_sampler_object
*sampler
,
4950 mesa_format format
, GLenum base_format
,
4951 bool is_integer_format
, bool is_stencil_sampling
,
4952 uint32_t *sdc_offset
)
4954 union gl_color_union color
;
4956 switch (base_format
) {
4957 case GL_DEPTH_COMPONENT
:
4958 /* GL specs that border color for depth textures is taken from the
4959 * R channel, while the hardware uses A. Spam R into all the
4960 * channels for safety.
4962 color
.ui
[0] = sampler
->BorderColor
.ui
[0];
4963 color
.ui
[1] = sampler
->BorderColor
.ui
[0];
4964 color
.ui
[2] = sampler
->BorderColor
.ui
[0];
4965 color
.ui
[3] = sampler
->BorderColor
.ui
[0];
4971 color
.ui
[3] = sampler
->BorderColor
.ui
[3];
4974 color
.ui
[0] = sampler
->BorderColor
.ui
[0];
4975 color
.ui
[1] = sampler
->BorderColor
.ui
[0];
4976 color
.ui
[2] = sampler
->BorderColor
.ui
[0];
4977 color
.ui
[3] = sampler
->BorderColor
.ui
[0];
4980 color
.ui
[0] = sampler
->BorderColor
.ui
[0];
4981 color
.ui
[1] = sampler
->BorderColor
.ui
[0];
4982 color
.ui
[2] = sampler
->BorderColor
.ui
[0];
4983 color
.ui
[3] = float_as_int(1.0);
4985 case GL_LUMINANCE_ALPHA
:
4986 color
.ui
[0] = sampler
->BorderColor
.ui
[0];
4987 color
.ui
[1] = sampler
->BorderColor
.ui
[0];
4988 color
.ui
[2] = sampler
->BorderColor
.ui
[0];
4989 color
.ui
[3] = sampler
->BorderColor
.ui
[3];
4992 color
.ui
[0] = sampler
->BorderColor
.ui
[0];
4993 color
.ui
[1] = sampler
->BorderColor
.ui
[1];
4994 color
.ui
[2] = sampler
->BorderColor
.ui
[2];
4995 color
.ui
[3] = sampler
->BorderColor
.ui
[3];
4999 /* In some cases we use an RGBA surface format for GL RGB textures,
5000 * where we've initialized the A channel to 1.0. We also have to set
5001 * the border color alpha to 1.0 in that case.
5003 if (base_format
== GL_RGB
)
5004 color
.ui
[3] = float_as_int(1.0);
5009 } else if (GEN_IS_HASWELL
&& (is_integer_format
|| is_stencil_sampling
)) {
5013 uint32_t *sdc
= brw_state_batch(
5014 brw
, GENX(SAMPLER_BORDER_COLOR_STATE_length
) * sizeof(uint32_t),
5015 alignment
, sdc_offset
);
5017 struct GENX(SAMPLER_BORDER_COLOR_STATE
) state
= { 0 };
5019 #define ASSIGN(dst, src) \
5024 #define ASSIGNu16(dst, src) \
5026 dst = (uint16_t)src; \
5029 #define ASSIGNu8(dst, src) \
5031 dst = (uint8_t)src; \
5034 #define BORDER_COLOR_ATTR(macro, _color_type, src) \
5035 macro(state.BorderColor ## _color_type ## Red, src[0]); \
5036 macro(state.BorderColor ## _color_type ## Green, src[1]); \
5037 macro(state.BorderColor ## _color_type ## Blue, src[2]); \
5038 macro(state.BorderColor ## _color_type ## Alpha, src[3]);
5041 /* On Broadwell, the border color is represented as four 32-bit floats,
5042 * integers, or unsigned values, interpreted according to the surface
5043 * format. This matches the sampler->BorderColor union exactly; just
5044 * memcpy the values.
5046 BORDER_COLOR_ATTR(ASSIGN
, 32bit
, color
.ui
);
5047 #elif GEN_IS_HASWELL
5048 if (is_integer_format
|| is_stencil_sampling
) {
5049 bool stencil
= format
== MESA_FORMAT_S_UINT8
|| is_stencil_sampling
;
5050 const int bits_per_channel
=
5051 _mesa_get_format_bits(format
, stencil
? GL_STENCIL_BITS
: GL_RED_BITS
);
5053 /* From the Haswell PRM, "Command Reference: Structures", Page 36:
5054 * "If any color channel is missing from the surface format,
5055 * corresponding border color should be programmed as zero and if
5056 * alpha channel is missing, corresponding Alpha border color should
5057 * be programmed as 1."
5059 unsigned c
[4] = { 0, 0, 0, 1 };
5060 for (int i
= 0; i
< 4; i
++) {
5061 if (has_component(format
, i
))
5065 switch (bits_per_channel
) {
5067 /* Copy RGBA in order. */
5068 BORDER_COLOR_ATTR(ASSIGNu8
, 8bit
, c
);
5071 /* R10G10B10A2_UINT is treated like a 16-bit format. */
5073 BORDER_COLOR_ATTR(ASSIGNu16
, 16bit
, c
);
5076 if (base_format
== GL_RG
) {
5077 /* Careful inspection of the tables reveals that for RG32 formats,
5078 * the green channel needs to go where blue normally belongs.
5080 state
.BorderColor32bitRed
= c
[0];
5081 state
.BorderColor32bitBlue
= c
[1];
5082 state
.BorderColor32bitAlpha
= 1;
5084 /* Copy RGBA in order. */
5085 BORDER_COLOR_ATTR(ASSIGN
, 32bit
, c
);
5089 assert(!"Invalid number of bits per channel in integer format.");
5093 BORDER_COLOR_ATTR(ASSIGN
, Float
, color
.f
);
5095 #elif GEN_GEN == 5 || GEN_GEN == 6
5096 BORDER_COLOR_ATTR(UNCLAMPED_FLOAT_TO_UBYTE
, Unorm
, color
.f
);
5097 BORDER_COLOR_ATTR(UNCLAMPED_FLOAT_TO_USHORT
, Unorm16
, color
.f
);
5098 BORDER_COLOR_ATTR(UNCLAMPED_FLOAT_TO_SHORT
, Snorm16
, color
.f
);
5100 #define MESA_FLOAT_TO_HALF(dst, src) \
5101 dst = _mesa_float_to_half(src);
5103 BORDER_COLOR_ATTR(MESA_FLOAT_TO_HALF
, Float16
, color
.f
);
5105 #undef MESA_FLOAT_TO_HALF
5107 state
.BorderColorSnorm8Red
= state
.BorderColorSnorm16Red
>> 8;
5108 state
.BorderColorSnorm8Green
= state
.BorderColorSnorm16Green
>> 8;
5109 state
.BorderColorSnorm8Blue
= state
.BorderColorSnorm16Blue
>> 8;
5110 state
.BorderColorSnorm8Alpha
= state
.BorderColorSnorm16Alpha
>> 8;
5112 BORDER_COLOR_ATTR(ASSIGN
, Float
, color
.f
);
5114 BORDER_COLOR_ATTR(ASSIGN
, , color
.f
);
5116 BORDER_COLOR_ATTR(ASSIGN
, Float
, color
.f
);
5120 #undef BORDER_COLOR_ATTR
5122 GENX(SAMPLER_BORDER_COLOR_STATE_pack
)(brw
, sdc
, &state
);
5126 translate_wrap_mode(GLenum wrap
, UNUSED
bool using_nearest
)
5133 /* GL_CLAMP is the weird mode where coordinates are clamped to
5134 * [0.0, 1.0], so linear filtering of coordinates outside of
5135 * [0.0, 1.0] give you half edge texel value and half border
5138 * Gen8+ supports this natively.
5140 return TCM_HALF_BORDER
;
5142 /* On Gen4-7.5, we clamp the coordinates in the fragment shader
5143 * and set clamp_border here, which gets the result desired.
5144 * We just use clamp(_to_edge) for nearest, because for nearest
5145 * clamping to 1.0 gives border color instead of the desired
5151 return TCM_CLAMP_BORDER
;
5153 case GL_CLAMP_TO_EDGE
:
5155 case GL_CLAMP_TO_BORDER
:
5156 return TCM_CLAMP_BORDER
;
5157 case GL_MIRRORED_REPEAT
:
5159 case GL_MIRROR_CLAMP_TO_EDGE
:
5160 return TCM_MIRROR_ONCE
;
5167 * Return true if the given wrap mode requires the border color to exist.
5170 wrap_mode_needs_border_color(unsigned wrap_mode
)
5173 return wrap_mode
== TCM_CLAMP_BORDER
||
5174 wrap_mode
== TCM_HALF_BORDER
;
5176 return wrap_mode
== TCM_CLAMP_BORDER
;
5181 * Sets the sampler state for a single unit based off of the sampler key
5185 genX(update_sampler_state
)(struct brw_context
*brw
,
5186 GLenum target
, bool tex_cube_map_seamless
,
5187 GLfloat tex_unit_lod_bias
,
5188 mesa_format format
, GLenum base_format
,
5189 const struct gl_texture_object
*texObj
,
5190 const struct gl_sampler_object
*sampler
,
5191 uint32_t *sampler_state
)
5193 struct GENX(SAMPLER_STATE
) samp_st
= { 0 };
5195 /* Select min and mip filters. */
5196 switch (sampler
->MinFilter
) {
5198 samp_st
.MinModeFilter
= MAPFILTER_NEAREST
;
5199 samp_st
.MipModeFilter
= MIPFILTER_NONE
;
5202 samp_st
.MinModeFilter
= MAPFILTER_LINEAR
;
5203 samp_st
.MipModeFilter
= MIPFILTER_NONE
;
5205 case GL_NEAREST_MIPMAP_NEAREST
:
5206 samp_st
.MinModeFilter
= MAPFILTER_NEAREST
;
5207 samp_st
.MipModeFilter
= MIPFILTER_NEAREST
;
5209 case GL_LINEAR_MIPMAP_NEAREST
:
5210 samp_st
.MinModeFilter
= MAPFILTER_LINEAR
;
5211 samp_st
.MipModeFilter
= MIPFILTER_NEAREST
;
5213 case GL_NEAREST_MIPMAP_LINEAR
:
5214 samp_st
.MinModeFilter
= MAPFILTER_NEAREST
;
5215 samp_st
.MipModeFilter
= MIPFILTER_LINEAR
;
5217 case GL_LINEAR_MIPMAP_LINEAR
:
5218 samp_st
.MinModeFilter
= MAPFILTER_LINEAR
;
5219 samp_st
.MipModeFilter
= MIPFILTER_LINEAR
;
5222 unreachable("not reached");
5225 /* Select mag filter. */
5226 samp_st
.MagModeFilter
= sampler
->MagFilter
== GL_LINEAR
?
5227 MAPFILTER_LINEAR
: MAPFILTER_NEAREST
;
5229 /* Enable anisotropic filtering if desired. */
5230 samp_st
.MaximumAnisotropy
= RATIO21
;
5232 if (sampler
->MaxAnisotropy
> 1.0f
) {
5233 if (samp_st
.MinModeFilter
== MAPFILTER_LINEAR
)
5234 samp_st
.MinModeFilter
= MAPFILTER_ANISOTROPIC
;
5235 if (samp_st
.MagModeFilter
== MAPFILTER_LINEAR
)
5236 samp_st
.MagModeFilter
= MAPFILTER_ANISOTROPIC
;
5238 if (sampler
->MaxAnisotropy
> 2.0f
) {
5239 samp_st
.MaximumAnisotropy
=
5240 MIN2((sampler
->MaxAnisotropy
- 2) / 2, RATIO161
);
5244 /* Set address rounding bits if not using nearest filtering. */
5245 if (samp_st
.MinModeFilter
!= MAPFILTER_NEAREST
) {
5246 samp_st
.UAddressMinFilterRoundingEnable
= true;
5247 samp_st
.VAddressMinFilterRoundingEnable
= true;
5248 samp_st
.RAddressMinFilterRoundingEnable
= true;
5251 if (samp_st
.MagModeFilter
!= MAPFILTER_NEAREST
) {
5252 samp_st
.UAddressMagFilterRoundingEnable
= true;
5253 samp_st
.VAddressMagFilterRoundingEnable
= true;
5254 samp_st
.RAddressMagFilterRoundingEnable
= true;
5257 bool either_nearest
=
5258 sampler
->MinFilter
== GL_NEAREST
|| sampler
->MagFilter
== GL_NEAREST
;
5259 unsigned wrap_s
= translate_wrap_mode(sampler
->WrapS
, either_nearest
);
5260 unsigned wrap_t
= translate_wrap_mode(sampler
->WrapT
, either_nearest
);
5261 unsigned wrap_r
= translate_wrap_mode(sampler
->WrapR
, either_nearest
);
5263 if (target
== GL_TEXTURE_CUBE_MAP
||
5264 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) {
5265 /* Cube maps must use the same wrap mode for all three coordinate
5266 * dimensions. Prior to Haswell, only CUBE and CLAMP are valid.
5268 * Ivybridge and Baytrail seem to have problems with CUBE mode and
5269 * integer formats. Fall back to CLAMP for now.
5271 if ((tex_cube_map_seamless
|| sampler
->CubeMapSeamless
) &&
5272 !(GEN_GEN
== 7 && !GEN_IS_HASWELL
&& texObj
->_IsIntegerFormat
)) {
5281 } else if (target
== GL_TEXTURE_1D
) {
5282 /* There's a bug in 1D texture sampling - it actually pays
5283 * attention to the wrap_t value, though it should not.
5284 * Override the wrap_t value here to GL_REPEAT to keep
5285 * any nonexistent border pixels from floating in.
5290 samp_st
.TCXAddressControlMode
= wrap_s
;
5291 samp_st
.TCYAddressControlMode
= wrap_t
;
5292 samp_st
.TCZAddressControlMode
= wrap_r
;
5294 samp_st
.ShadowFunction
=
5295 sampler
->CompareMode
== GL_COMPARE_R_TO_TEXTURE_ARB
?
5296 intel_translate_shadow_compare_func(sampler
->CompareFunc
) : 0;
5299 /* Set shadow function. */
5300 samp_st
.AnisotropicAlgorithm
=
5301 samp_st
.MinModeFilter
== MAPFILTER_ANISOTROPIC
?
5302 EWAApproximation
: LEGACY
;
5306 samp_st
.NonnormalizedCoordinateEnable
= target
== GL_TEXTURE_RECTANGLE
;
5309 const float hw_max_lod
= GEN_GEN
>= 7 ? 14 : 13;
5310 samp_st
.MinLOD
= CLAMP(sampler
->MinLod
, 0, hw_max_lod
);
5311 samp_st
.MaxLOD
= CLAMP(sampler
->MaxLod
, 0, hw_max_lod
);
5312 samp_st
.TextureLODBias
=
5313 CLAMP(tex_unit_lod_bias
+ sampler
->LodBias
, -16, 15);
5316 samp_st
.BaseMipLevel
=
5317 CLAMP(texObj
->MinLevel
+ texObj
->BaseLevel
, 0, hw_max_lod
);
5318 samp_st
.MinandMagStateNotEqual
=
5319 samp_st
.MinModeFilter
!= samp_st
.MagModeFilter
;
5322 /* Upload the border color if necessary. If not, just point it at
5323 * offset 0 (the start of the batch) - the color should be ignored,
5324 * but that address won't fault in case something reads it anyway.
5326 uint32_t border_color_offset
= 0;
5327 if (wrap_mode_needs_border_color(wrap_s
) ||
5328 wrap_mode_needs_border_color(wrap_t
) ||
5329 wrap_mode_needs_border_color(wrap_r
)) {
5330 genX(upload_default_color
)(brw
, sampler
, format
, base_format
,
5331 texObj
->_IsIntegerFormat
,
5332 texObj
->StencilSampling
,
5333 &border_color_offset
);
5336 samp_st
.BorderColorPointer
=
5337 ro_bo(brw
->batch
.state
.bo
, border_color_offset
);
5339 samp_st
.BorderColorPointer
= border_color_offset
;
5343 samp_st
.LODPreClampMode
= CLAMP_MODE_OGL
;
5345 samp_st
.LODPreClampEnable
= true;
5348 GENX(SAMPLER_STATE_pack
)(brw
, sampler_state
, &samp_st
);
5352 update_sampler_state(struct brw_context
*brw
,
5354 uint32_t *sampler_state
)
5356 struct gl_context
*ctx
= &brw
->ctx
;
5357 const struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
5358 const struct gl_texture_object
*texObj
= texUnit
->_Current
;
5359 const struct gl_sampler_object
*sampler
= _mesa_get_samplerobj(ctx
, unit
);
5361 /* These don't use samplers at all. */
5362 if (texObj
->Target
== GL_TEXTURE_BUFFER
)
5365 struct gl_texture_image
*firstImage
= texObj
->Image
[0][texObj
->BaseLevel
];
5366 genX(update_sampler_state
)(brw
, texObj
->Target
,
5367 ctx
->Texture
.CubeMapSeamless
,
5369 firstImage
->TexFormat
, firstImage
->_BaseFormat
,
5375 genX(upload_sampler_state_table
)(struct brw_context
*brw
,
5376 struct gl_program
*prog
,
5377 struct brw_stage_state
*stage_state
)
5379 struct gl_context
*ctx
= &brw
->ctx
;
5380 uint32_t sampler_count
= stage_state
->sampler_count
;
5382 GLbitfield SamplersUsed
= prog
->SamplersUsed
;
5384 if (sampler_count
== 0)
5387 /* SAMPLER_STATE is 4 DWords on all platforms. */
5388 const int dwords
= GENX(SAMPLER_STATE_length
);
5389 const int size_in_bytes
= dwords
* sizeof(uint32_t);
5391 uint32_t *sampler_state
= brw_state_batch(brw
,
5392 sampler_count
* size_in_bytes
,
5393 32, &stage_state
->sampler_offset
);
5394 /* memset(sampler_state, 0, sampler_count * size_in_bytes); */
5396 for (unsigned s
= 0; s
< sampler_count
; s
++) {
5397 if (SamplersUsed
& (1 << s
)) {
5398 const unsigned unit
= prog
->SamplerUnits
[s
];
5399 if (ctx
->Texture
.Unit
[unit
]._Current
) {
5400 update_sampler_state(brw
, unit
, sampler_state
);
5404 sampler_state
+= dwords
;
5407 if (GEN_GEN
>= 7 && stage_state
->stage
!= MESA_SHADER_COMPUTE
) {
5408 /* Emit a 3DSTATE_SAMPLER_STATE_POINTERS_XS packet. */
5409 genX(emit_sampler_state_pointers_xs
)(brw
, stage_state
);
5411 /* Flag that the sampler state table pointer has changed; later atoms
5414 brw
->ctx
.NewDriverState
|= BRW_NEW_SAMPLER_STATE_TABLE
;
5419 genX(upload_fs_samplers
)(struct brw_context
*brw
)
5421 /* BRW_NEW_FRAGMENT_PROGRAM */
5422 struct gl_program
*fs
= brw
->programs
[MESA_SHADER_FRAGMENT
];
5423 genX(upload_sampler_state_table
)(brw
, fs
, &brw
->wm
.base
);
5426 static const struct brw_tracked_state
genX(fs_samplers
) = {
5428 .mesa
= _NEW_TEXTURE
,
5429 .brw
= BRW_NEW_BATCH
|
5431 BRW_NEW_FRAGMENT_PROGRAM
,
5433 .emit
= genX(upload_fs_samplers
),
5437 genX(upload_vs_samplers
)(struct brw_context
*brw
)
5439 /* BRW_NEW_VERTEX_PROGRAM */
5440 struct gl_program
*vs
= brw
->programs
[MESA_SHADER_VERTEX
];
5441 genX(upload_sampler_state_table
)(brw
, vs
, &brw
->vs
.base
);
5444 static const struct brw_tracked_state
genX(vs_samplers
) = {
5446 .mesa
= _NEW_TEXTURE
,
5447 .brw
= BRW_NEW_BATCH
|
5449 BRW_NEW_VERTEX_PROGRAM
,
5451 .emit
= genX(upload_vs_samplers
),
5456 genX(upload_gs_samplers
)(struct brw_context
*brw
)
5458 /* BRW_NEW_GEOMETRY_PROGRAM */
5459 struct gl_program
*gs
= brw
->programs
[MESA_SHADER_GEOMETRY
];
5463 genX(upload_sampler_state_table
)(brw
, gs
, &brw
->gs
.base
);
5467 static const struct brw_tracked_state
genX(gs_samplers
) = {
5469 .mesa
= _NEW_TEXTURE
,
5470 .brw
= BRW_NEW_BATCH
|
5472 BRW_NEW_GEOMETRY_PROGRAM
,
5474 .emit
= genX(upload_gs_samplers
),
5480 genX(upload_tcs_samplers
)(struct brw_context
*brw
)
5482 /* BRW_NEW_TESS_PROGRAMS */
5483 struct gl_program
*tcs
= brw
->programs
[MESA_SHADER_TESS_CTRL
];
5487 genX(upload_sampler_state_table
)(brw
, tcs
, &brw
->tcs
.base
);
5490 static const struct brw_tracked_state
genX(tcs_samplers
) = {
5492 .mesa
= _NEW_TEXTURE
,
5493 .brw
= BRW_NEW_BATCH
|
5495 BRW_NEW_TESS_PROGRAMS
,
5497 .emit
= genX(upload_tcs_samplers
),
5503 genX(upload_tes_samplers
)(struct brw_context
*brw
)
5505 /* BRW_NEW_TESS_PROGRAMS */
5506 struct gl_program
*tes
= brw
->programs
[MESA_SHADER_TESS_EVAL
];
5510 genX(upload_sampler_state_table
)(brw
, tes
, &brw
->tes
.base
);
5513 static const struct brw_tracked_state
genX(tes_samplers
) = {
5515 .mesa
= _NEW_TEXTURE
,
5516 .brw
= BRW_NEW_BATCH
|
5518 BRW_NEW_TESS_PROGRAMS
,
5520 .emit
= genX(upload_tes_samplers
),
5526 genX(upload_cs_samplers
)(struct brw_context
*brw
)
5528 /* BRW_NEW_COMPUTE_PROGRAM */
5529 struct gl_program
*cs
= brw
->programs
[MESA_SHADER_COMPUTE
];
5533 genX(upload_sampler_state_table
)(brw
, cs
, &brw
->cs
.base
);
5536 const struct brw_tracked_state
genX(cs_samplers
) = {
5538 .mesa
= _NEW_TEXTURE
,
5539 .brw
= BRW_NEW_BATCH
|
5541 BRW_NEW_COMPUTE_PROGRAM
,
5543 .emit
= genX(upload_cs_samplers
),
5547 /* ---------------------------------------------------------------------- */
5551 static void genX(upload_blend_constant_color
)(struct brw_context
*brw
)
5553 struct gl_context
*ctx
= &brw
->ctx
;
5555 brw_batch_emit(brw
, GENX(3DSTATE_CONSTANT_COLOR
), blend_cc
) {
5556 blend_cc
.BlendConstantColorRed
= ctx
->Color
.BlendColorUnclamped
[0];
5557 blend_cc
.BlendConstantColorGreen
= ctx
->Color
.BlendColorUnclamped
[1];
5558 blend_cc
.BlendConstantColorBlue
= ctx
->Color
.BlendColorUnclamped
[2];
5559 blend_cc
.BlendConstantColorAlpha
= ctx
->Color
.BlendColorUnclamped
[3];
5563 static const struct brw_tracked_state
genX(blend_constant_color
) = {
5566 .brw
= BRW_NEW_CONTEXT
|
5569 .emit
= genX(upload_blend_constant_color
)
5573 /* ---------------------------------------------------------------------- */
5576 genX(init_atoms
)(struct brw_context
*brw
)
5579 static const struct brw_tracked_state
*render_atoms
[] =
5581 &genX(vf_statistics
),
5583 /* Once all the programs are done, we know how large urb entry
5584 * sizes need to be and can decide if we need to change the urb
5588 &brw_recalculate_urb_fence
,
5591 &genX(color_calc_state
),
5593 /* Surface state setup. Must come before the VS/WM unit. The binding
5594 * table upload must be last.
5596 &brw_vs_pull_constants
,
5597 &brw_wm_pull_constants
,
5598 &brw_renderbuffer_surfaces
,
5599 &brw_renderbuffer_read_surfaces
,
5600 &brw_texture_surfaces
,
5601 &brw_vs_binding_table
,
5602 &brw_wm_binding_table
,
5607 /* These set up state for brw_psp_urb_cbs */
5609 &genX(sf_clip_viewport
),
5611 &genX(vs_state
), /* always required, enabled or not */
5617 &brw_binding_table_pointers
,
5618 &genX(blend_constant_color
),
5622 &genX(polygon_stipple
),
5623 &genX(polygon_stipple_offset
),
5625 &genX(line_stipple
),
5629 &genX(drawing_rect
),
5630 &brw_indices
, /* must come before brw_vertices */
5631 &genX(index_buffer
),
5634 &brw_constant_buffer
5637 static const struct brw_tracked_state
*render_atoms
[] =
5639 &genX(vf_statistics
),
5641 &genX(sf_clip_viewport
),
5643 /* Command packets: */
5648 &genX(blend_state
), /* must do before cc unit */
5649 &genX(color_calc_state
), /* must do before cc unit */
5650 &genX(depth_stencil_state
), /* must do before cc unit */
5652 &genX(vs_push_constants
), /* Before vs_state */
5653 &genX(gs_push_constants
), /* Before gs_state */
5654 &genX(wm_push_constants
), /* Before wm_state */
5656 /* Surface state setup. Must come before the VS/WM unit. The binding
5657 * table upload must be last.
5659 &brw_vs_pull_constants
,
5660 &brw_vs_ubo_surfaces
,
5661 &brw_gs_pull_constants
,
5662 &brw_gs_ubo_surfaces
,
5663 &brw_wm_pull_constants
,
5664 &brw_wm_ubo_surfaces
,
5665 &gen6_renderbuffer_surfaces
,
5666 &brw_renderbuffer_read_surfaces
,
5667 &brw_texture_surfaces
,
5669 &brw_vs_binding_table
,
5670 &gen6_gs_binding_table
,
5671 &brw_wm_binding_table
,
5676 &gen6_sampler_state
,
5677 &genX(multisample_state
),
5685 &genX(scissor_state
),
5687 &gen6_binding_table_pointers
,
5691 &genX(polygon_stipple
),
5692 &genX(polygon_stipple_offset
),
5694 &genX(line_stipple
),
5696 &genX(drawing_rect
),
5698 &brw_indices
, /* must come before brw_vertices */
5699 &genX(index_buffer
),
5703 static const struct brw_tracked_state
*render_atoms
[] =
5705 &genX(vf_statistics
),
5707 /* Command packets: */
5710 &genX(sf_clip_viewport
),
5713 &gen7_push_constant_space
,
5716 &genX(cc_and_blend_state
),
5718 &genX(blend_state
), /* must do before cc unit */
5719 &genX(color_calc_state
), /* must do before cc unit */
5721 &genX(depth_stencil_state
), /* must do before cc unit */
5723 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
5724 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
5725 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
5726 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
5727 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
5729 &genX(vs_push_constants
), /* Before vs_state */
5730 &genX(tcs_push_constants
),
5731 &genX(tes_push_constants
),
5732 &genX(gs_push_constants
), /* Before gs_state */
5733 &genX(wm_push_constants
), /* Before wm_surfaces and constant_buffer */
5735 /* Surface state setup. Must come before the VS/WM unit. The binding
5736 * table upload must be last.
5738 &brw_vs_pull_constants
,
5739 &brw_vs_ubo_surfaces
,
5740 &brw_tcs_pull_constants
,
5741 &brw_tcs_ubo_surfaces
,
5742 &brw_tes_pull_constants
,
5743 &brw_tes_ubo_surfaces
,
5744 &brw_gs_pull_constants
,
5745 &brw_gs_ubo_surfaces
,
5746 &brw_wm_pull_constants
,
5747 &brw_wm_ubo_surfaces
,
5748 &gen6_renderbuffer_surfaces
,
5749 &brw_renderbuffer_read_surfaces
,
5750 &brw_texture_surfaces
,
5752 &genX(push_constant_packets
),
5754 &brw_vs_binding_table
,
5755 &brw_tcs_binding_table
,
5756 &brw_tes_binding_table
,
5757 &brw_gs_binding_table
,
5758 &brw_wm_binding_table
,
5762 &genX(tcs_samplers
),
5763 &genX(tes_samplers
),
5765 &genX(multisample_state
),
5779 &genX(scissor_state
),
5783 &genX(polygon_stipple
),
5784 &genX(polygon_stipple_offset
),
5786 &genX(line_stipple
),
5788 &genX(drawing_rect
),
5790 &brw_indices
, /* must come before brw_vertices */
5791 &genX(index_buffer
),
5799 static const struct brw_tracked_state
*render_atoms
[] =
5801 &genX(vf_statistics
),
5804 &genX(sf_clip_viewport
),
5807 &gen7_push_constant_space
,
5810 &genX(color_calc_state
),
5812 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
5813 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
5814 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
5815 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
5816 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
5818 &genX(vs_push_constants
), /* Before vs_state */
5819 &genX(tcs_push_constants
),
5820 &genX(tes_push_constants
),
5821 &genX(gs_push_constants
), /* Before gs_state */
5822 &genX(wm_push_constants
), /* Before wm_surfaces and constant_buffer */
5824 /* Surface state setup. Must come before the VS/WM unit. The binding
5825 * table upload must be last.
5827 &brw_vs_pull_constants
,
5828 &brw_vs_ubo_surfaces
,
5829 &brw_tcs_pull_constants
,
5830 &brw_tcs_ubo_surfaces
,
5831 &brw_tes_pull_constants
,
5832 &brw_tes_ubo_surfaces
,
5833 &brw_gs_pull_constants
,
5834 &brw_gs_ubo_surfaces
,
5835 &brw_wm_pull_constants
,
5836 &brw_wm_ubo_surfaces
,
5837 &gen6_renderbuffer_surfaces
,
5838 &brw_renderbuffer_read_surfaces
,
5839 &brw_texture_surfaces
,
5841 &genX(push_constant_packets
),
5843 &brw_vs_binding_table
,
5844 &brw_tcs_binding_table
,
5845 &brw_tes_binding_table
,
5846 &brw_gs_binding_table
,
5847 &brw_wm_binding_table
,
5851 &genX(tcs_samplers
),
5852 &genX(tes_samplers
),
5854 &genX(multisample_state
),
5863 &genX(raster_state
),
5869 &genX(depth_stencil_state
),
5872 &genX(scissor_state
),
5876 &genX(polygon_stipple
),
5877 &genX(polygon_stipple_offset
),
5879 &genX(line_stipple
),
5881 &genX(drawing_rect
),
5886 &genX(index_buffer
),
5894 STATIC_ASSERT(ARRAY_SIZE(render_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
5895 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
5896 render_atoms
, ARRAY_SIZE(render_atoms
));
5899 static const struct brw_tracked_state
*compute_atoms
[] =
5902 &brw_cs_image_surfaces
,
5903 &genX(cs_push_constants
),
5904 &genX(cs_pull_constants
),
5905 &brw_cs_ubo_surfaces
,
5906 &brw_cs_texture_surfaces
,
5907 &brw_cs_work_groups_surface
,
5912 STATIC_ASSERT(ARRAY_SIZE(compute_atoms
) <= ARRAY_SIZE(brw
->compute_atoms
));
5913 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
5914 compute_atoms
, ARRAY_SIZE(compute_atoms
));
5916 brw
->vtbl
.emit_mi_report_perf_count
= genX(emit_mi_report_perf_count
);
5917 brw
->vtbl
.emit_compute_walker
= genX(emit_gpgpu_walker
);