2 * Copyright © 2017 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "common/gen_device_info.h"
27 #include "genxml/gen_macros.h"
29 #include "brw_context.h"
30 #include "brw_state.h"
33 #include "intel_batchbuffer.h"
34 #include "intel_buffer_objects.h"
35 #include "intel_fbo.h"
37 #include "main/fbobject.h"
38 #include "main/framebuffer.h"
39 #include "main/stencil.h"
40 #include "main/transformfeedback.h"
43 emit_dwords(struct brw_context
*brw
, unsigned n
)
45 intel_batchbuffer_begin(brw
, n
, RENDER_RING
);
46 uint32_t *map
= brw
->batch
.map_next
;
47 brw
->batch
.map_next
+= n
;
48 intel_batchbuffer_advance(brw
);
54 uint32_t read_domains
;
55 uint32_t write_domain
;
60 emit_reloc(struct brw_context
*brw
,
61 void *location
, struct brw_address address
, uint32_t delta
)
63 uint32_t offset
= (char *) location
- (char *) brw
->batch
.map
;
65 return brw_emit_reloc(&brw
->batch
, offset
, address
.bo
,
66 address
.offset
+ delta
,
68 address
.write_domain
);
71 #define __gen_address_type struct brw_address
72 #define __gen_user_data struct brw_context
75 __gen_combine_address(struct brw_context
*brw
, void *location
,
76 struct brw_address address
, uint32_t delta
)
78 if (address
.bo
== NULL
) {
79 return address
.offset
+ delta
;
81 return emit_reloc(brw
, location
, address
, delta
);
85 static inline struct brw_address
86 render_bo(struct brw_bo
*bo
, uint32_t offset
)
88 return (struct brw_address
) {
91 .read_domains
= I915_GEM_DOMAIN_RENDER
,
92 .write_domain
= I915_GEM_DOMAIN_RENDER
,
96 static inline struct brw_address
97 instruction_bo(struct brw_bo
*bo
, uint32_t offset
)
99 return (struct brw_address
) {
102 .read_domains
= I915_GEM_DOMAIN_INSTRUCTION
,
103 .write_domain
= I915_GEM_DOMAIN_INSTRUCTION
,
107 #include "genxml/genX_pack.h"
109 #define _brw_cmd_length(cmd) cmd ## _length
110 #define _brw_cmd_length_bias(cmd) cmd ## _length_bias
111 #define _brw_cmd_header(cmd) cmd ## _header
112 #define _brw_cmd_pack(cmd) cmd ## _pack
114 #define brw_batch_emit(brw, cmd, name) \
115 for (struct cmd name = { _brw_cmd_header(cmd) }, \
116 *_dst = emit_dwords(brw, _brw_cmd_length(cmd)); \
117 __builtin_expect(_dst != NULL, 1); \
118 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
121 #define brw_batch_emitn(brw, cmd, n, ...) ({ \
122 uint32_t *_dw = emit_dwords(brw, n); \
123 struct cmd template = { \
124 _brw_cmd_header(cmd), \
125 .DWordLength = n - _brw_cmd_length_bias(cmd), \
128 _brw_cmd_pack(cmd)(brw, _dw, &template); \
129 _dw + 1; /* Array starts at dw[1] */ \
132 #define brw_state_emit(brw, cmd, align, offset, name) \
133 for (struct cmd name = { 0, }, \
134 *_dst = brw_state_batch(brw, _brw_cmd_length(cmd) * 4, \
136 __builtin_expect(_dst != NULL, 1); \
137 _brw_cmd_pack(cmd)(brw, (void *)_dst, &name), \
142 * Determine the appropriate attribute override value to store into the
143 * 3DSTATE_SF structure for a given fragment shader attribute. The attribute
144 * override value contains two pieces of information: the location of the
145 * attribute in the VUE (relative to urb_entry_read_offset, see below), and a
146 * flag indicating whether to "swizzle" the attribute based on the direction
147 * the triangle is facing.
149 * If an attribute is "swizzled", then the given VUE location is used for
150 * front-facing triangles, and the VUE location that immediately follows is
151 * used for back-facing triangles. We use this to implement the mapping from
152 * gl_FrontColor/gl_BackColor to gl_Color.
154 * urb_entry_read_offset is the offset into the VUE at which the SF unit is
155 * being instructed to begin reading attribute data. It can be set to a
156 * nonzero value to prevent the SF unit from wasting time reading elements of
157 * the VUE that are not needed by the fragment shader. It is measured in
158 * 256-bit increments.
161 genX(get_attr_override
)(struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr
,
162 const struct brw_vue_map
*vue_map
,
163 int urb_entry_read_offset
, int fs_attr
,
164 bool two_side_color
, uint32_t *max_source_attr
)
166 /* Find the VUE slot for this attribute. */
167 int slot
= vue_map
->varying_to_slot
[fs_attr
];
169 /* Viewport and Layer are stored in the VUE header. We need to override
170 * them to zero if earlier stages didn't write them, as GL requires that
171 * they read back as zero when not explicitly set.
173 if (fs_attr
== VARYING_SLOT_VIEWPORT
|| fs_attr
== VARYING_SLOT_LAYER
) {
174 attr
->ComponentOverrideX
= true;
175 attr
->ComponentOverrideW
= true;
176 attr
->ConstantSource
= CONST_0000
;
178 if (!(vue_map
->slots_valid
& VARYING_BIT_LAYER
))
179 attr
->ComponentOverrideY
= true;
180 if (!(vue_map
->slots_valid
& VARYING_BIT_VIEWPORT
))
181 attr
->ComponentOverrideZ
= true;
186 /* If there was only a back color written but not front, use back
187 * as the color instead of undefined
189 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL0
)
190 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC0
];
191 if (slot
== -1 && fs_attr
== VARYING_SLOT_COL1
)
192 slot
= vue_map
->varying_to_slot
[VARYING_SLOT_BFC1
];
195 /* This attribute does not exist in the VUE--that means that the vertex
196 * shader did not write to it. This means that either:
198 * (a) This attribute is a texture coordinate, and it is going to be
199 * replaced with point coordinates (as a consequence of a call to
200 * glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)), so the
201 * hardware will ignore whatever attribute override we supply.
203 * (b) This attribute is read by the fragment shader but not written by
204 * the vertex shader, so its value is undefined. Therefore the
205 * attribute override we supply doesn't matter.
207 * (c) This attribute is gl_PrimitiveID, and it wasn't written by the
208 * previous shader stage.
210 * Note that we don't have to worry about the cases where the attribute
211 * is gl_PointCoord or is undergoing point sprite coordinate
212 * replacement, because in those cases, this function isn't called.
214 * In case (c), we need to program the attribute overrides so that the
215 * primitive ID will be stored in this slot. In every other case, the
216 * attribute override we supply doesn't matter. So just go ahead and
217 * program primitive ID in every case.
219 attr
->ComponentOverrideW
= true;
220 attr
->ComponentOverrideX
= true;
221 attr
->ComponentOverrideY
= true;
222 attr
->ComponentOverrideZ
= true;
223 attr
->ConstantSource
= PRIM_ID
;
227 /* Compute the location of the attribute relative to urb_entry_read_offset.
228 * Each increment of urb_entry_read_offset represents a 256-bit value, so
229 * it counts for two 128-bit VUE slots.
231 int source_attr
= slot
- 2 * urb_entry_read_offset
;
232 assert(source_attr
>= 0 && source_attr
< 32);
234 /* If we are doing two-sided color, and the VUE slot following this one
235 * represents a back-facing color, then we need to instruct the SF unit to
236 * do back-facing swizzling.
238 bool swizzling
= two_side_color
&&
239 ((vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL0
&&
240 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC0
) ||
241 (vue_map
->slot_to_varying
[slot
] == VARYING_SLOT_COL1
&&
242 vue_map
->slot_to_varying
[slot
+1] == VARYING_SLOT_BFC1
));
244 /* Update max_source_attr. If swizzling, the SF will read this slot + 1. */
245 if (*max_source_attr
< source_attr
+ swizzling
)
246 *max_source_attr
= source_attr
+ swizzling
;
248 attr
->SourceAttribute
= source_attr
;
250 attr
->SwizzleSelect
= INPUTATTR_FACING
;
255 genX(calculate_attr_overrides
)(const struct brw_context
*brw
,
256 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) *attr_overrides
,
257 uint32_t *point_sprite_enables
,
258 uint32_t *urb_entry_read_length
,
259 uint32_t *urb_entry_read_offset
)
261 const struct gl_context
*ctx
= &brw
->ctx
;
264 const struct gl_point_attrib
*point
= &ctx
->Point
;
266 /* BRW_NEW_FS_PROG_DATA */
267 const struct brw_wm_prog_data
*wm_prog_data
=
268 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
269 uint32_t max_source_attr
= 0;
271 *point_sprite_enables
= 0;
273 /* BRW_NEW_FRAGMENT_PROGRAM
275 * If the fragment shader reads VARYING_SLOT_LAYER, then we need to pass in
276 * the full vertex header. Otherwise, we can program the SF to start
277 * reading at an offset of 1 (2 varying slots) to skip unnecessary data:
278 * - VARYING_SLOT_PSIZ and BRW_VARYING_SLOT_NDC on gen4-5
279 * - VARYING_SLOT_{PSIZ,LAYER} and VARYING_SLOT_POS on gen6+
282 bool fs_needs_vue_header
= brw
->fragment_program
->info
.inputs_read
&
283 (VARYING_BIT_LAYER
| VARYING_BIT_VIEWPORT
);
285 *urb_entry_read_offset
= fs_needs_vue_header
? 0 : 1;
287 /* From the Ivybridge PRM, Vol 2 Part 1, 3DSTATE_SBE,
288 * description of dw10 Point Sprite Texture Coordinate Enable:
290 * "This field must be programmed to zero when non-point primitives
293 * The SandyBridge PRM doesn't explicitly say that point sprite enables
294 * must be programmed to zero when rendering non-point primitives, but
295 * the IvyBridge PRM does, and if we don't, we get garbage.
297 * This is not required on Haswell, as the hardware ignores this state
298 * when drawing non-points -- although we do still need to be careful to
299 * correctly set the attr overrides.
302 * BRW_NEW_PRIMITIVE | BRW_NEW_GS_PROG_DATA | BRW_NEW_TES_PROG_DATA
304 bool drawing_points
= brw_is_drawing_points(brw
);
306 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
307 int input_index
= wm_prog_data
->urb_setup
[attr
];
313 bool point_sprite
= false;
314 if (drawing_points
) {
315 if (point
->PointSprite
&&
316 (attr
>= VARYING_SLOT_TEX0
&& attr
<= VARYING_SLOT_TEX7
) &&
317 (point
->CoordReplace
& (1u << (attr
- VARYING_SLOT_TEX0
)))) {
321 if (attr
== VARYING_SLOT_PNTC
)
325 *point_sprite_enables
|= (1 << input_index
);
328 /* BRW_NEW_VUE_MAP_GEOM_OUT | _NEW_LIGHT | _NEW_PROGRAM */
329 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attribute
= { 0 };
332 genX(get_attr_override
)(&attribute
,
333 &brw
->vue_map_geom_out
,
334 *urb_entry_read_offset
, attr
,
335 brw
->ctx
.VertexProgram
._TwoSideEnabled
,
339 /* The hardware can only do the overrides on 16 overrides at a
340 * time, and the other up to 16 have to be lined up so that the
341 * input index = the output index. We'll need to do some
342 * tweaking to make sure that's the case.
344 if (input_index
< 16)
345 attr_overrides
[input_index
] = attribute
;
347 assert(attribute
.SourceAttribute
== input_index
);
350 /* From the Sandy Bridge PRM, Volume 2, Part 1, documentation for
351 * 3DSTATE_SF DWord 1 bits 15:11, "Vertex URB Entry Read Length":
353 * "This field should be set to the minimum length required to read the
354 * maximum source attribute. The maximum source attribute is indicated
355 * by the maximum value of the enabled Attribute # Source Attribute if
356 * Attribute Swizzle Enable is set, Number of Output Attributes-1 if
358 * read_length = ceiling((max_source_attr + 1) / 2)
360 * [errata] Corruption/Hang possible if length programmed larger than
363 * Similar text exists for Ivy Bridge.
365 *urb_entry_read_length
= DIV_ROUND_UP(max_source_attr
+ 1, 2);
368 /* ---------------------------------------------------------------------- */
371 genX(upload_depth_stencil_state
)(struct brw_context
*brw
)
373 struct gl_context
*ctx
= &brw
->ctx
;
376 struct intel_renderbuffer
*depth_irb
=
377 intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
380 struct gl_depthbuffer_attrib
*depth
= &ctx
->Depth
;
383 struct gl_stencil_attrib
*stencil
= &ctx
->Stencil
;
384 const int b
= stencil
->_BackFace
;
387 brw_batch_emit(brw
, GENX(3DSTATE_WM_DEPTH_STENCIL
), wmds
) {
390 brw_state_emit(brw
, GENX(DEPTH_STENCIL_STATE
), 64, &ds_offset
, wmds
) {
392 if (depth
->Test
&& depth_irb
) {
393 wmds
.DepthTestEnable
= true;
394 wmds
.DepthBufferWriteEnable
= brw_depth_writes_enabled(brw
);
395 wmds
.DepthTestFunction
= intel_translate_compare_func(depth
->Func
);
398 if (stencil
->_Enabled
) {
399 wmds
.StencilTestEnable
= true;
400 wmds
.StencilWriteMask
= stencil
->WriteMask
[0] & 0xff;
401 wmds
.StencilTestMask
= stencil
->ValueMask
[0] & 0xff;
403 wmds
.StencilTestFunction
=
404 intel_translate_compare_func(stencil
->Function
[0]);
406 intel_translate_stencil_op(stencil
->FailFunc
[0]);
407 wmds
.StencilPassDepthPassOp
=
408 intel_translate_stencil_op(stencil
->ZPassFunc
[0]);
409 wmds
.StencilPassDepthFailOp
=
410 intel_translate_stencil_op(stencil
->ZFailFunc
[0]);
412 wmds
.StencilBufferWriteEnable
= stencil
->_WriteEnabled
;
414 if (stencil
->_TestTwoSide
) {
415 wmds
.DoubleSidedStencilEnable
= true;
416 wmds
.BackfaceStencilWriteMask
= stencil
->WriteMask
[b
] & 0xff;
417 wmds
.BackfaceStencilTestMask
= stencil
->ValueMask
[b
] & 0xff;
419 wmds
.BackfaceStencilTestFunction
=
420 intel_translate_compare_func(stencil
->Function
[b
]);
421 wmds
.BackfaceStencilFailOp
=
422 intel_translate_stencil_op(stencil
->FailFunc
[b
]);
423 wmds
.BackfaceStencilPassDepthPassOp
=
424 intel_translate_stencil_op(stencil
->ZPassFunc
[b
]);
425 wmds
.BackfaceStencilPassDepthFailOp
=
426 intel_translate_stencil_op(stencil
->ZFailFunc
[b
]);
430 wmds
.StencilReferenceValue
= _mesa_get_stencil_ref(ctx
, 0);
431 wmds
.BackfaceStencilReferenceValue
= _mesa_get_stencil_ref(ctx
, b
);
437 brw_batch_emit(brw
, GENX(3DSTATE_CC_STATE_POINTERS
), ptr
) {
438 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
439 ptr
.DEPTH_STENCIL_STATEChange
= true;
442 brw_batch_emit(brw
, GENX(3DSTATE_DEPTH_STENCIL_STATE_POINTERS
), ptr
) {
443 ptr
.PointertoDEPTH_STENCIL_STATE
= ds_offset
;
448 static const struct brw_tracked_state
genX(depth_stencil_state
) = {
450 .mesa
= _NEW_BUFFERS
|
453 .brw
= BRW_NEW_BLORP
|
454 (GEN_GEN
>= 8 ? BRW_NEW_CONTEXT
456 BRW_NEW_STATE_BASE_ADDRESS
),
458 .emit
= genX(upload_depth_stencil_state
),
461 /* ---------------------------------------------------------------------- */
464 genX(upload_clip_state
)(struct brw_context
*brw
)
466 struct gl_context
*ctx
= &brw
->ctx
;
469 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
471 /* BRW_NEW_FS_PROG_DATA */
472 struct brw_wm_prog_data
*wm_prog_data
=
473 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
475 brw_batch_emit(brw
, GENX(3DSTATE_CLIP
), clip
) {
476 clip
.StatisticsEnable
= !brw
->meta_in_progress
;
478 if (wm_prog_data
->barycentric_interp_modes
&
479 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
)
480 clip
.NonPerspectiveBarycentricEnable
= true;
483 clip
.EarlyCullEnable
= true;
487 clip
.FrontWinding
= ctx
->Polygon
._FrontBit
== _mesa_is_user_fbo(fb
);
489 if (ctx
->Polygon
.CullFlag
) {
490 switch (ctx
->Polygon
.CullFaceMode
) {
492 clip
.CullMode
= CULLMODE_FRONT
;
495 clip
.CullMode
= CULLMODE_BACK
;
497 case GL_FRONT_AND_BACK
:
498 clip
.CullMode
= CULLMODE_BOTH
;
501 unreachable("Should not get here: invalid CullFlag");
504 clip
.CullMode
= CULLMODE_NONE
;
509 clip
.UserClipDistanceCullTestEnableBitmask
=
510 brw_vue_prog_data(brw
->vs
.base
.prog_data
)->cull_distance_mask
;
512 clip
.ViewportZClipTestEnable
= !ctx
->Transform
.DepthClamp
;
516 if (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
) {
517 clip
.TriangleStripListProvokingVertexSelect
= 0;
518 clip
.TriangleFanProvokingVertexSelect
= 1;
519 clip
.LineStripListProvokingVertexSelect
= 0;
521 clip
.TriangleStripListProvokingVertexSelect
= 2;
522 clip
.TriangleFanProvokingVertexSelect
= 2;
523 clip
.LineStripListProvokingVertexSelect
= 1;
527 clip
.UserClipDistanceClipTestEnableBitmask
=
528 ctx
->Transform
.ClipPlanesEnabled
;
531 clip
.ForceUserClipDistanceClipTestEnableBitmask
= true;
534 if (ctx
->Transform
.ClipDepthMode
== GL_ZERO_TO_ONE
)
535 clip
.APIMode
= APIMODE_D3D
;
537 clip
.APIMode
= APIMODE_OGL
;
539 clip
.GuardbandClipTestEnable
= true;
541 /* BRW_NEW_VIEWPORT_COUNT */
542 const unsigned viewport_count
= brw
->clip
.viewport_count
;
544 if (ctx
->RasterDiscard
) {
545 clip
.ClipMode
= CLIPMODE_REJECT_ALL
;
547 perf_debug("Rasterizer discard is currently implemented via the "
548 "clipper; having the GS not write primitives would "
549 "likely be faster.\n");
552 clip
.ClipMode
= CLIPMODE_NORMAL
;
555 clip
.ClipEnable
= brw
->primitive
!= _3DPRIM_RECTLIST
;
558 * BRW_NEW_GEOMETRY_PROGRAM | BRW_NEW_TES_PROG_DATA | BRW_NEW_PRIMITIVE
560 if (!brw_is_drawing_points(brw
) && !brw_is_drawing_lines(brw
))
561 clip
.ViewportXYClipTestEnable
= true;
563 clip
.MinimumPointWidth
= 0.125;
564 clip
.MaximumPointWidth
= 255.875;
565 clip
.MaximumVPIndex
= viewport_count
- 1;
566 if (_mesa_geometric_layers(fb
) == 0)
567 clip
.ForceZeroRTAIndexEnable
= true;
571 static const struct brw_tracked_state
genX(clip_state
) = {
573 .mesa
= _NEW_BUFFERS
|
577 .brw
= BRW_NEW_BLORP
|
579 BRW_NEW_FS_PROG_DATA
|
580 BRW_NEW_GS_PROG_DATA
|
581 BRW_NEW_VS_PROG_DATA
|
582 BRW_NEW_META_IN_PROGRESS
|
584 BRW_NEW_RASTERIZER_DISCARD
|
585 BRW_NEW_TES_PROG_DATA
|
586 BRW_NEW_VIEWPORT_COUNT
,
588 .emit
= genX(upload_clip_state
),
591 /* ---------------------------------------------------------------------- */
594 genX(upload_sf
)(struct brw_context
*brw
)
596 struct gl_context
*ctx
= &brw
->ctx
;
601 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
602 const bool multisampled_fbo
= _mesa_geometric_samples(ctx
->DrawBuffer
) > 1;
605 brw_batch_emit(brw
, GENX(3DSTATE_SF
), sf
) {
606 sf
.StatisticsEnable
= true;
607 sf
.ViewportTransformEnable
= brw
->sf
.viewport_transform_enable
;
611 sf
.DepthBufferSurfaceFormat
= brw_depthbuffer_format(brw
);
616 sf
.FrontWinding
= ctx
->Polygon
._FrontBit
== render_to_fbo
;
617 sf
.GlobalDepthOffsetEnableSolid
= ctx
->Polygon
.OffsetFill
;
618 sf
.GlobalDepthOffsetEnableWireframe
= ctx
->Polygon
.OffsetLine
;
619 sf
.GlobalDepthOffsetEnablePoint
= ctx
->Polygon
.OffsetPoint
;
621 switch (ctx
->Polygon
.FrontMode
) {
623 sf
.FrontFaceFillMode
= FILL_MODE_SOLID
;
626 sf
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
629 sf
.FrontFaceFillMode
= FILL_MODE_POINT
;
632 unreachable("not reached");
635 switch (ctx
->Polygon
.BackMode
) {
637 sf
.BackFaceFillMode
= FILL_MODE_SOLID
;
640 sf
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
643 sf
.BackFaceFillMode
= FILL_MODE_POINT
;
646 unreachable("not reached");
649 sf
.ScissorRectangleEnable
= true;
651 if (ctx
->Polygon
.CullFlag
) {
652 switch (ctx
->Polygon
.CullFaceMode
) {
654 sf
.CullMode
= CULLMODE_FRONT
;
657 sf
.CullMode
= CULLMODE_BACK
;
659 case GL_FRONT_AND_BACK
:
660 sf
.CullMode
= CULLMODE_BOTH
;
663 unreachable("not reached");
666 sf
.CullMode
= CULLMODE_NONE
;
670 sf
.LineStippleEnable
= ctx
->Line
.StippleFlag
;
673 if (multisampled_fbo
&& ctx
->Multisample
.Enabled
)
674 sf
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
676 sf
.GlobalDepthOffsetConstant
= ctx
->Polygon
.OffsetUnits
* 2;
677 sf
.GlobalDepthOffsetScale
= ctx
->Polygon
.OffsetFactor
;
678 sf
.GlobalDepthOffsetClamp
= ctx
->Polygon
.OffsetClamp
;
682 sf
.LineWidth
= brw_get_line_width_float(brw
);
684 if (ctx
->Line
.SmoothFlag
) {
685 sf
.LineEndCapAntialiasingRegionWidth
= _10pixels
;
687 sf
.AntiAliasingEnable
= true;
691 /* _NEW_POINT - Clamp to ARB_point_parameters user limits */
692 point_size
= CLAMP(ctx
->Point
.Size
, ctx
->Point
.MinSize
, ctx
->Point
.MaxSize
);
693 /* Clamp to the hardware limits */
694 sf
.PointWidth
= CLAMP(point_size
, 0.125f
, 255.875f
);
696 /* _NEW_PROGRAM | _NEW_POINT, BRW_NEW_VUE_MAP_GEOM_OUT */
697 if (use_state_point_size(brw
))
698 sf
.PointWidthSource
= State
;
701 /* _NEW_POINT | _NEW_MULTISAMPLE */
702 if ((ctx
->Point
.SmoothFlag
|| _mesa_is_multisample_enabled(ctx
)) &&
703 !ctx
->Point
.PointSprite
)
704 sf
.SmoothPointEnable
= true;
707 sf
.AALineDistanceMode
= AALINEDISTANCE_TRUE
;
710 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
) {
711 sf
.TriangleStripListProvokingVertexSelect
= 2;
712 sf
.TriangleFanProvokingVertexSelect
= 2;
713 sf
.LineStripListProvokingVertexSelect
= 1;
715 sf
.TriangleFanProvokingVertexSelect
= 1;
719 /* BRW_NEW_FS_PROG_DATA */
720 const struct brw_wm_prog_data
*wm_prog_data
=
721 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
723 sf
.AttributeSwizzleEnable
= true;
724 sf
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
727 * Window coordinates in an FBO are inverted, which means point
728 * sprite origin must be inverted, too.
730 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
) {
731 sf
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
733 sf
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
736 /* BRW_NEW_VUE_MAP_GEOM_OUT | BRW_NEW_FRAGMENT_PROGRAM |
737 * _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM | BRW_NEW_FS_PROG_DATA
739 uint32_t urb_entry_read_length
;
740 uint32_t urb_entry_read_offset
;
741 uint32_t point_sprite_enables
;
742 genX(calculate_attr_overrides
)(brw
, sf
.Attribute
, &point_sprite_enables
,
743 &urb_entry_read_length
,
744 &urb_entry_read_offset
);
745 sf
.VertexURBEntryReadLength
= urb_entry_read_length
;
746 sf
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
747 sf
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
748 sf
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
753 static const struct brw_tracked_state
genX(sf_state
) = {
760 (GEN_GEN
<= 7 ? _NEW_BUFFERS
| _NEW_POLYGON
: 0),
761 .brw
= BRW_NEW_BLORP
|
763 BRW_NEW_VUE_MAP_GEOM_OUT
|
764 (GEN_GEN
<= 7 ? BRW_NEW_GS_PROG_DATA
|
766 BRW_NEW_TES_PROG_DATA
768 (GEN_GEN
== 6 ? BRW_NEW_FS_PROG_DATA
|
769 BRW_NEW_FRAGMENT_PROGRAM
772 .emit
= genX(upload_sf
),
777 /* ---------------------------------------------------------------------- */
781 genX(upload_sbe
)(struct brw_context
*brw
)
783 struct gl_context
*ctx
= &brw
->ctx
;
784 /* BRW_NEW_FS_PROG_DATA */
785 const struct brw_wm_prog_data
*wm_prog_data
=
786 brw_wm_prog_data(brw
->wm
.base
.prog_data
);
788 struct GENX(SF_OUTPUT_ATTRIBUTE_DETAIL
) attr_overrides
[16] = { { 0 } };
790 #define attr_overrides sbe.Attribute
792 uint32_t urb_entry_read_length
;
793 uint32_t urb_entry_read_offset
;
794 uint32_t point_sprite_enables
;
796 brw_batch_emit(brw
, GENX(3DSTATE_SBE
), sbe
) {
797 sbe
.AttributeSwizzleEnable
= true;
798 sbe
.NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
;
801 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
805 * Window coordinates in an FBO are inverted, which means point
806 * sprite origin must be inverted.
808 if ((ctx
->Point
.SpriteOrigin
== GL_LOWER_LEFT
) != render_to_fbo
)
809 sbe
.PointSpriteTextureCoordinateOrigin
= LOWERLEFT
;
811 sbe
.PointSpriteTextureCoordinateOrigin
= UPPERLEFT
;
813 /* _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM,
814 * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM |
815 * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA |
816 * BRW_NEW_VUE_MAP_GEOM_OUT
818 genX(calculate_attr_overrides
)(brw
,
820 &point_sprite_enables
,
821 &urb_entry_read_length
,
822 &urb_entry_read_offset
);
824 /* Typically, the URB entry read length and offset should be programmed
825 * in 3DSTATE_VS and 3DSTATE_GS; SBE inherits it from the last active
826 * stage which produces geometry. However, we don't know the proper
827 * value until we call calculate_attr_overrides().
829 * To fit with our existing code, we override the inherited values and
830 * specify it here directly, as we did on previous generations.
832 sbe
.VertexURBEntryReadLength
= urb_entry_read_length
;
833 sbe
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
834 sbe
.PointSpriteTextureCoordinateEnable
= point_sprite_enables
;
835 sbe
.ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
;
838 sbe
.ForceVertexURBEntryReadLength
= true;
839 sbe
.ForceVertexURBEntryReadOffset
= true;
843 /* prepare the active component dwords */
845 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
846 if (!(brw
->fragment_program
->info
.inputs_read
&
847 BITFIELD64_BIT(attr
))) {
851 assert(input_index
< 32);
853 sbe
.AttributeActiveComponentFormat
[input_index
] = ACTIVE_COMPONENT_XYZW
;
860 brw_batch_emit(brw
, GENX(3DSTATE_SBE_SWIZ
), sbes
) {
861 for (int i
= 0; i
< 16; i
++)
862 sbes
.Attribute
[i
] = attr_overrides
[i
];
866 #undef attr_overrides
869 static const struct brw_tracked_state
genX(sbe_state
) = {
871 .mesa
= _NEW_BUFFERS
|
876 .brw
= BRW_NEW_BLORP
|
878 BRW_NEW_FRAGMENT_PROGRAM
|
879 BRW_NEW_FS_PROG_DATA
|
880 BRW_NEW_GS_PROG_DATA
|
881 BRW_NEW_TES_PROG_DATA
|
882 BRW_NEW_VUE_MAP_GEOM_OUT
|
883 (GEN_GEN
== 7 ? BRW_NEW_PRIMITIVE
886 .emit
= genX(upload_sbe
),
889 /* ---------------------------------------------------------------------- */
892 * Outputs the 3DSTATE_SO_DECL_LIST command.
894 * The data output is a series of 64-bit entries containing a SO_DECL per
895 * stream. We only have one stream of rendering coming out of the GS unit, so
896 * we only emit stream 0 (low 16 bits) SO_DECLs.
899 genX(upload_3dstate_so_decl_list
)(struct brw_context
*brw
,
900 const struct brw_vue_map
*vue_map
)
902 struct gl_context
*ctx
= &brw
->ctx
;
903 /* BRW_NEW_TRANSFORM_FEEDBACK */
904 struct gl_transform_feedback_object
*xfb_obj
=
905 ctx
->TransformFeedback
.CurrentObject
;
906 const struct gl_transform_feedback_info
*linked_xfb_info
=
907 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
908 struct GENX(SO_DECL
) so_decl
[MAX_VERTEX_STREAMS
][128];
909 int buffer_mask
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
910 int next_offset
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
911 int decls
[MAX_VERTEX_STREAMS
] = {0, 0, 0, 0};
913 STATIC_ASSERT(ARRAY_SIZE(so_decl
[0]) >= MAX_PROGRAM_OUTPUTS
);
915 memset(so_decl
, 0, sizeof(so_decl
));
917 /* Construct the list of SO_DECLs to be emitted. The formatting of the
918 * command feels strange -- each dword pair contains a SO_DECL per stream.
920 for (unsigned i
= 0; i
< linked_xfb_info
->NumOutputs
; i
++) {
921 int buffer
= linked_xfb_info
->Outputs
[i
].OutputBuffer
;
922 struct GENX(SO_DECL
) decl
= {0};
923 int varying
= linked_xfb_info
->Outputs
[i
].OutputRegister
;
924 const unsigned components
= linked_xfb_info
->Outputs
[i
].NumComponents
;
925 unsigned component_mask
= (1 << components
) - 1;
926 unsigned stream_id
= linked_xfb_info
->Outputs
[i
].StreamId
;
927 unsigned decl_buffer_slot
= buffer
;
928 assert(stream_id
< MAX_VERTEX_STREAMS
);
930 /* gl_PointSize is stored in VARYING_SLOT_PSIZ.w
931 * gl_Layer is stored in VARYING_SLOT_PSIZ.y
932 * gl_ViewportIndex is stored in VARYING_SLOT_PSIZ.z
934 if (varying
== VARYING_SLOT_PSIZ
) {
935 assert(components
== 1);
936 component_mask
<<= 3;
937 } else if (varying
== VARYING_SLOT_LAYER
) {
938 assert(components
== 1);
939 component_mask
<<= 1;
940 } else if (varying
== VARYING_SLOT_VIEWPORT
) {
941 assert(components
== 1);
942 component_mask
<<= 2;
944 component_mask
<<= linked_xfb_info
->Outputs
[i
].ComponentOffset
;
947 buffer_mask
[stream_id
] |= 1 << buffer
;
949 decl
.OutputBufferSlot
= decl_buffer_slot
;
950 if (varying
== VARYING_SLOT_LAYER
|| varying
== VARYING_SLOT_VIEWPORT
) {
951 decl
.RegisterIndex
= vue_map
->varying_to_slot
[VARYING_SLOT_PSIZ
];
953 assert(vue_map
->varying_to_slot
[varying
] >= 0);
954 decl
.RegisterIndex
= vue_map
->varying_to_slot
[varying
];
956 decl
.ComponentMask
= component_mask
;
958 /* Mesa doesn't store entries for gl_SkipComponents in the Outputs[]
959 * array. Instead, it simply increments DstOffset for the following
960 * input by the number of components that should be skipped.
962 * Our hardware is unusual in that it requires us to program SO_DECLs
963 * for fake "hole" components, rather than simply taking the offset
964 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
965 * program as many size = 4 holes as we can, then a final hole to
966 * accommodate the final 1, 2, or 3 remaining.
968 int skip_components
=
969 linked_xfb_info
->Outputs
[i
].DstOffset
- next_offset
[buffer
];
971 next_offset
[buffer
] += skip_components
;
973 while (skip_components
>= 4) {
974 struct GENX(SO_DECL
) *d
= &so_decl
[stream_id
][decls
[stream_id
]++];
976 d
->OutputBufferSlot
= decl_buffer_slot
;
977 d
->ComponentMask
= 0xf;
978 skip_components
-= 4;
981 if (skip_components
> 0) {
982 struct GENX(SO_DECL
) *d
= &so_decl
[stream_id
][decls
[stream_id
]++];
984 d
->OutputBufferSlot
= decl_buffer_slot
;
985 d
->ComponentMask
= (1 << skip_components
) - 1;
988 assert(linked_xfb_info
->Outputs
[i
].DstOffset
== next_offset
[buffer
]);
990 next_offset
[buffer
] += components
;
992 so_decl
[stream_id
][decls
[stream_id
]++] = decl
;
994 if (decls
[stream_id
] > max_decls
)
995 max_decls
= decls
[stream_id
];
999 dw
= brw_batch_emitn(brw
, GENX(3DSTATE_SO_DECL_LIST
), 3 + 2 * max_decls
,
1000 .StreamtoBufferSelects0
= buffer_mask
[0],
1001 .StreamtoBufferSelects1
= buffer_mask
[1],
1002 .StreamtoBufferSelects2
= buffer_mask
[2],
1003 .StreamtoBufferSelects3
= buffer_mask
[3],
1004 .NumEntries0
= decls
[0],
1005 .NumEntries1
= decls
[1],
1006 .NumEntries2
= decls
[2],
1007 .NumEntries3
= decls
[3]);
1009 for (int i
= 0; i
< max_decls
; i
++) {
1010 GENX(SO_DECL_ENTRY_pack
)(
1011 brw
, dw
+ 2 + i
* 2,
1012 &(struct GENX(SO_DECL_ENTRY
)) {
1013 .Stream0Decl
= so_decl
[0][i
],
1014 .Stream1Decl
= so_decl
[1][i
],
1015 .Stream2Decl
= so_decl
[2][i
],
1016 .Stream3Decl
= so_decl
[3][i
],
1022 genX(upload_3dstate_so_buffers
)(struct brw_context
*brw
)
1024 struct gl_context
*ctx
= &brw
->ctx
;
1025 /* BRW_NEW_TRANSFORM_FEEDBACK */
1026 struct gl_transform_feedback_object
*xfb_obj
=
1027 ctx
->TransformFeedback
.CurrentObject
;
1029 const struct gl_transform_feedback_info
*linked_xfb_info
=
1030 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
1032 struct brw_transform_feedback_object
*brw_obj
=
1033 (struct brw_transform_feedback_object
*) xfb_obj
;
1034 uint32_t mocs_wb
= brw
->gen
>= 9 ? SKL_MOCS_WB
: BDW_MOCS_WB
;
1037 /* Set up the up to 4 output buffers. These are the ranges defined in the
1038 * gl_transform_feedback_object.
1040 for (int i
= 0; i
< 4; i
++) {
1041 struct intel_buffer_object
*bufferobj
=
1042 intel_buffer_object(xfb_obj
->Buffers
[i
]);
1045 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
1046 sob
.SOBufferIndex
= i
;
1051 uint32_t start
= xfb_obj
->Offset
[i
];
1052 assert(start
% 4 == 0);
1053 uint32_t end
= ALIGN(start
+ xfb_obj
->Size
[i
], 4);
1055 intel_bufferobj_buffer(brw
, bufferobj
, start
, end
- start
);
1056 assert(end
<= bo
->size
);
1058 brw_batch_emit(brw
, GENX(3DSTATE_SO_BUFFER
), sob
) {
1059 sob
.SOBufferIndex
= i
;
1061 sob
.SurfaceBaseAddress
= render_bo(bo
, start
);
1063 sob
.SurfacePitch
= linked_xfb_info
->Buffers
[i
].Stride
* 4;
1064 sob
.SurfaceEndAddress
= render_bo(bo
, end
);
1066 sob
.SOBufferEnable
= true;
1067 sob
.StreamOffsetWriteEnable
= true;
1068 sob
.StreamOutputBufferOffsetAddressEnable
= true;
1069 sob
.SOBufferMOCS
= mocs_wb
;
1071 sob
.SurfaceSize
= MAX2(xfb_obj
->Size
[i
] / 4, 1) - 1;
1072 sob
.StreamOutputBufferOffsetAddress
=
1073 instruction_bo(brw_obj
->offset_bo
, i
* sizeof(uint32_t));
1075 if (brw_obj
->zero_offsets
) {
1076 /* Zero out the offset and write that to offset_bo */
1077 sob
.StreamOffset
= 0;
1079 /* Use offset_bo as the "Stream Offset." */
1080 sob
.StreamOffset
= 0xFFFFFFFF;
1087 brw_obj
->zero_offsets
= false;
1092 query_active(struct gl_query_object
*q
)
1094 return q
&& q
->Active
;
1098 genX(upload_3dstate_streamout
)(struct brw_context
*brw
, bool active
,
1099 const struct brw_vue_map
*vue_map
)
1101 struct gl_context
*ctx
= &brw
->ctx
;
1102 /* BRW_NEW_TRANSFORM_FEEDBACK */
1103 struct gl_transform_feedback_object
*xfb_obj
=
1104 ctx
->TransformFeedback
.CurrentObject
;
1106 brw_batch_emit(brw
, GENX(3DSTATE_STREAMOUT
), sos
) {
1108 int urb_entry_read_offset
= 0;
1109 int urb_entry_read_length
= (vue_map
->num_slots
+ 1) / 2 -
1110 urb_entry_read_offset
;
1112 sos
.SOFunctionEnable
= true;
1113 sos
.SOStatisticsEnable
= true;
1115 /* BRW_NEW_RASTERIZER_DISCARD */
1116 if (ctx
->RasterDiscard
) {
1117 if (!query_active(ctx
->Query
.PrimitivesGenerated
[0])) {
1118 sos
.RenderingDisable
= true;
1120 perf_debug("Rasterizer discard with a GL_PRIMITIVES_GENERATED "
1121 "query active relies on the clipper.");
1126 if (ctx
->Light
.ProvokingVertex
!= GL_FIRST_VERTEX_CONVENTION
)
1127 sos
.ReorderMode
= TRAILING
;
1130 sos
.SOBufferEnable0
= xfb_obj
->Buffers
[0] != NULL
;
1131 sos
.SOBufferEnable1
= xfb_obj
->Buffers
[1] != NULL
;
1132 sos
.SOBufferEnable2
= xfb_obj
->Buffers
[2] != NULL
;
1133 sos
.SOBufferEnable3
= xfb_obj
->Buffers
[3] != NULL
;
1135 const struct gl_transform_feedback_info
*linked_xfb_info
=
1136 xfb_obj
->program
->sh
.LinkedTransformFeedback
;
1137 /* Set buffer pitches; 0 means unbound. */
1138 if (xfb_obj
->Buffers
[0])
1139 sos
.Buffer0SurfacePitch
= linked_xfb_info
->Buffers
[0].Stride
* 4;
1140 if (xfb_obj
->Buffers
[1])
1141 sos
.Buffer1SurfacePitch
= linked_xfb_info
->Buffers
[1].Stride
* 4;
1142 if (xfb_obj
->Buffers
[2])
1143 sos
.Buffer2SurfacePitch
= linked_xfb_info
->Buffers
[2].Stride
* 4;
1144 if (xfb_obj
->Buffers
[3])
1145 sos
.Buffer3SurfacePitch
= linked_xfb_info
->Buffers
[3].Stride
* 4;
1148 /* We always read the whole vertex. This could be reduced at some
1149 * point by reading less and offsetting the register index in the
1152 sos
.Stream0VertexReadOffset
= urb_entry_read_offset
;
1153 sos
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
1154 sos
.Stream1VertexReadOffset
= urb_entry_read_offset
;
1155 sos
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
1156 sos
.Stream2VertexReadOffset
= urb_entry_read_offset
;
1157 sos
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
1158 sos
.Stream3VertexReadOffset
= urb_entry_read_offset
;
1159 sos
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
1165 genX(upload_sol
)(struct brw_context
*brw
)
1167 struct gl_context
*ctx
= &brw
->ctx
;
1168 /* BRW_NEW_TRANSFORM_FEEDBACK */
1169 bool active
= _mesa_is_xfb_active_and_unpaused(ctx
);
1172 genX(upload_3dstate_so_buffers
)(brw
);
1174 /* BRW_NEW_VUE_MAP_GEOM_OUT */
1175 genX(upload_3dstate_so_decl_list
)(brw
, &brw
->vue_map_geom_out
);
1178 /* Finally, set up the SOL stage. This command must always follow updates to
1179 * the nonpipelined SOL state (3DSTATE_SO_BUFFER, 3DSTATE_SO_DECL_LIST) or
1180 * MMIO register updates (current performed by the kernel at each batch
1183 genX(upload_3dstate_streamout
)(brw
, active
, &brw
->vue_map_geom_out
);
1186 static const struct brw_tracked_state
genX(sol_state
) = {
1189 .brw
= BRW_NEW_BATCH
|
1191 BRW_NEW_RASTERIZER_DISCARD
|
1192 BRW_NEW_VUE_MAP_GEOM_OUT
|
1193 BRW_NEW_TRANSFORM_FEEDBACK
,
1195 .emit
= genX(upload_sol
),
1200 /* ---------------------------------------------------------------------- */
1204 genX(upload_raster
)(struct brw_context
*brw
)
1206 struct gl_context
*ctx
= &brw
->ctx
;
1209 bool render_to_fbo
= _mesa_is_user_fbo(ctx
->DrawBuffer
);
1212 struct gl_polygon_attrib
*polygon
= &ctx
->Polygon
;
1215 struct gl_point_attrib
*point
= &ctx
->Point
;
1217 brw_batch_emit(brw
, GENX(3DSTATE_RASTER
), raster
) {
1218 if (polygon
->_FrontBit
== render_to_fbo
)
1219 raster
.FrontWinding
= CounterClockwise
;
1221 if (polygon
->CullFlag
) {
1222 switch (polygon
->CullFaceMode
) {
1224 raster
.CullMode
= CULLMODE_FRONT
;
1227 raster
.CullMode
= CULLMODE_BACK
;
1229 case GL_FRONT_AND_BACK
:
1230 raster
.CullMode
= CULLMODE_BOTH
;
1233 unreachable("not reached");
1236 raster
.CullMode
= CULLMODE_NONE
;
1239 point
->SmoothFlag
= raster
.SmoothPointEnable
;
1241 raster
.DXMultisampleRasterizationEnable
=
1242 _mesa_is_multisample_enabled(ctx
);
1244 raster
.GlobalDepthOffsetEnableSolid
= polygon
->OffsetFill
;
1245 raster
.GlobalDepthOffsetEnableWireframe
= polygon
->OffsetLine
;
1246 raster
.GlobalDepthOffsetEnablePoint
= polygon
->OffsetPoint
;
1248 switch (polygon
->FrontMode
) {
1250 raster
.FrontFaceFillMode
= FILL_MODE_SOLID
;
1253 raster
.FrontFaceFillMode
= FILL_MODE_WIREFRAME
;
1256 raster
.FrontFaceFillMode
= FILL_MODE_POINT
;
1259 unreachable("not reached");
1262 switch (polygon
->BackMode
) {
1264 raster
.BackFaceFillMode
= FILL_MODE_SOLID
;
1267 raster
.BackFaceFillMode
= FILL_MODE_WIREFRAME
;
1270 raster
.BackFaceFillMode
= FILL_MODE_POINT
;
1273 unreachable("not reached");
1277 raster
.AntialiasingEnable
= ctx
->Line
.SmoothFlag
;
1280 raster
.ScissorRectangleEnable
= ctx
->Scissor
.EnableFlags
;
1282 /* _NEW_TRANSFORM */
1283 if (!ctx
->Transform
.DepthClamp
) {
1285 raster
.ViewportZFarClipTestEnable
= true;
1286 raster
.ViewportZNearClipTestEnable
= true;
1288 raster
.ViewportZClipTestEnable
= true;
1292 /* BRW_NEW_CONSERVATIVE_RASTERIZATION */
1294 raster
.ConservativeRasterizationEnable
=
1295 ctx
->IntelConservativeRasterization
;
1298 raster
.GlobalDepthOffsetClamp
= polygon
->OffsetClamp
;
1299 raster
.GlobalDepthOffsetScale
= polygon
->OffsetFactor
;
1301 raster
.GlobalDepthOffsetConstant
= polygon
->OffsetUnits
* 2;
1305 static const struct brw_tracked_state
genX(raster_state
) = {
1307 .mesa
= _NEW_BUFFERS
|
1314 .brw
= BRW_NEW_BLORP
|
1316 BRW_NEW_CONSERVATIVE_RASTERIZATION
,
1318 .emit
= genX(upload_raster
),
1322 /* ---------------------------------------------------------------------- */
1325 genX(init_atoms
)(struct brw_context
*brw
)
1328 static const struct brw_tracked_state
*render_atoms
[] =
1330 /* Once all the programs are done, we know how large urb entry
1331 * sizes need to be and can decide if we need to change the urb
1335 &brw_recalculate_urb_fence
,
1340 /* Surface state setup. Must come before the VS/WM unit. The binding
1341 * table upload must be last.
1343 &brw_vs_pull_constants
,
1344 &brw_wm_pull_constants
,
1345 &brw_renderbuffer_surfaces
,
1346 &brw_renderbuffer_read_surfaces
,
1347 &brw_texture_surfaces
,
1348 &brw_vs_binding_table
,
1349 &brw_wm_binding_table
,
1354 /* These set up state for brw_psp_urb_cbs */
1358 &brw_vs_unit
, /* always required, enabled or not */
1364 &brw_invariant_state
,
1366 &brw_binding_table_pointers
,
1367 &brw_blend_constant_color
,
1371 &brw_polygon_stipple
,
1372 &brw_polygon_stipple_offset
,
1379 &brw_indices
, /* must come before brw_vertices */
1383 &brw_constant_buffer
1386 static const struct brw_tracked_state
*render_atoms
[] =
1388 &gen6_sf_and_clip_viewports
,
1390 /* Command packets: */
1393 &gen6_viewport_state
, /* must do after *_vp stages */
1396 &gen6_blend_state
, /* must do before cc unit */
1397 &gen6_color_calc_state
, /* must do before cc unit */
1398 &gen6_depth_stencil_state
, /* must do before cc unit */
1400 &gen6_vs_push_constants
, /* Before vs_state */
1401 &gen6_gs_push_constants
, /* Before gs_state */
1402 &gen6_wm_push_constants
, /* Before wm_state */
1404 /* Surface state setup. Must come before the VS/WM unit. The binding
1405 * table upload must be last.
1407 &brw_vs_pull_constants
,
1408 &brw_vs_ubo_surfaces
,
1409 &brw_gs_pull_constants
,
1410 &brw_gs_ubo_surfaces
,
1411 &brw_wm_pull_constants
,
1412 &brw_wm_ubo_surfaces
,
1413 &gen6_renderbuffer_surfaces
,
1414 &brw_renderbuffer_read_surfaces
,
1415 &brw_texture_surfaces
,
1417 &brw_vs_binding_table
,
1418 &gen6_gs_binding_table
,
1419 &brw_wm_binding_table
,
1424 &gen6_sampler_state
,
1425 &gen6_multisample_state
,
1433 &gen6_scissor_state
,
1435 &gen6_binding_table_pointers
,
1439 &brw_polygon_stipple
,
1440 &brw_polygon_stipple_offset
,
1446 &brw_indices
, /* must come before brw_vertices */
1451 static const struct brw_tracked_state
*render_atoms
[] =
1453 /* Command packets: */
1456 &gen7_sf_clip_viewport
,
1459 &gen7_push_constant_space
,
1461 &gen6_blend_state
, /* must do before cc unit */
1462 &gen6_color_calc_state
, /* must do before cc unit */
1463 &genX(depth_stencil_state
), /* must do before cc unit */
1465 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
1466 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
1467 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
1468 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
1469 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
1471 &gen6_vs_push_constants
, /* Before vs_state */
1472 &gen7_tcs_push_constants
,
1473 &gen7_tes_push_constants
,
1474 &gen6_gs_push_constants
, /* Before gs_state */
1475 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
1477 /* Surface state setup. Must come before the VS/WM unit. The binding
1478 * table upload must be last.
1480 &brw_vs_pull_constants
,
1481 &brw_vs_ubo_surfaces
,
1482 &brw_vs_abo_surfaces
,
1483 &brw_tcs_pull_constants
,
1484 &brw_tcs_ubo_surfaces
,
1485 &brw_tcs_abo_surfaces
,
1486 &brw_tes_pull_constants
,
1487 &brw_tes_ubo_surfaces
,
1488 &brw_tes_abo_surfaces
,
1489 &brw_gs_pull_constants
,
1490 &brw_gs_ubo_surfaces
,
1491 &brw_gs_abo_surfaces
,
1492 &brw_wm_pull_constants
,
1493 &brw_wm_ubo_surfaces
,
1494 &brw_wm_abo_surfaces
,
1495 &gen6_renderbuffer_surfaces
,
1496 &brw_renderbuffer_read_surfaces
,
1497 &brw_texture_surfaces
,
1498 &brw_vs_binding_table
,
1499 &brw_tcs_binding_table
,
1500 &brw_tes_binding_table
,
1501 &brw_gs_binding_table
,
1502 &brw_wm_binding_table
,
1509 &gen6_multisample_state
,
1523 &gen6_scissor_state
,
1527 &brw_polygon_stipple
,
1528 &brw_polygon_stipple_offset
,
1534 &brw_indices
, /* must come before brw_vertices */
1541 static const struct brw_tracked_state
*render_atoms
[] =
1544 &gen8_sf_clip_viewport
,
1547 &gen7_push_constant_space
,
1550 &gen6_color_calc_state
,
1552 &brw_vs_image_surfaces
, /* Before vs push/pull constants and binding table */
1553 &brw_tcs_image_surfaces
, /* Before tcs push/pull constants and binding table */
1554 &brw_tes_image_surfaces
, /* Before tes push/pull constants and binding table */
1555 &brw_gs_image_surfaces
, /* Before gs push/pull constants and binding table */
1556 &brw_wm_image_surfaces
, /* Before wm push/pull constants and binding table */
1558 &gen6_vs_push_constants
, /* Before vs_state */
1559 &gen7_tcs_push_constants
,
1560 &gen7_tes_push_constants
,
1561 &gen6_gs_push_constants
, /* Before gs_state */
1562 &gen6_wm_push_constants
, /* Before wm_surfaces and constant_buffer */
1564 /* Surface state setup. Must come before the VS/WM unit. The binding
1565 * table upload must be last.
1567 &brw_vs_pull_constants
,
1568 &brw_vs_ubo_surfaces
,
1569 &brw_vs_abo_surfaces
,
1570 &brw_tcs_pull_constants
,
1571 &brw_tcs_ubo_surfaces
,
1572 &brw_tcs_abo_surfaces
,
1573 &brw_tes_pull_constants
,
1574 &brw_tes_ubo_surfaces
,
1575 &brw_tes_abo_surfaces
,
1576 &brw_gs_pull_constants
,
1577 &brw_gs_ubo_surfaces
,
1578 &brw_gs_abo_surfaces
,
1579 &brw_wm_pull_constants
,
1580 &brw_wm_ubo_surfaces
,
1581 &brw_wm_abo_surfaces
,
1582 &gen6_renderbuffer_surfaces
,
1583 &brw_renderbuffer_read_surfaces
,
1584 &brw_texture_surfaces
,
1585 &brw_vs_binding_table
,
1586 &brw_tcs_binding_table
,
1587 &brw_tes_binding_table
,
1588 &brw_gs_binding_table
,
1589 &brw_wm_binding_table
,
1596 &gen8_multisample_state
,
1605 &genX(raster_state
),
1611 &genX(depth_stencil_state
),
1614 &gen6_scissor_state
,
1618 &brw_polygon_stipple
,
1619 &brw_polygon_stipple_offset
,
1636 STATIC_ASSERT(ARRAY_SIZE(render_atoms
) <= ARRAY_SIZE(brw
->render_atoms
));
1637 brw_copy_pipeline_atoms(brw
, BRW_RENDER_PIPELINE
,
1638 render_atoms
, ARRAY_SIZE(render_atoms
));
1641 static const struct brw_tracked_state
*compute_atoms
[] =
1644 &brw_cs_image_surfaces
,
1645 &gen7_cs_push_constants
,
1646 &brw_cs_pull_constants
,
1647 &brw_cs_ubo_surfaces
,
1648 &brw_cs_abo_surfaces
,
1649 &brw_cs_texture_surfaces
,
1650 &brw_cs_work_groups_surface
,
1655 STATIC_ASSERT(ARRAY_SIZE(compute_atoms
) <= ARRAY_SIZE(brw
->compute_atoms
));
1656 brw_copy_pipeline_atoms(brw
, BRW_COMPUTE_PIPELINE
,
1657 compute_atoms
, ARRAY_SIZE(compute_atoms
));