2 * Copyright © 2009 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
24 * Eric Anholt <eric@anholt.net>
28 #include "brw_context.h"
29 #include "brw_state.h"
30 #include "brw_defines.h"
32 #include "intel_batchbuffer.h"
35 * Return true if at least one of the inputs used by the given fragment
36 * program has the GLSL "noperspective" interpolation qualifier.
39 brw_fprog_uses_noperspective(const struct gl_fragment_program
*fprog
)
42 for (attr
= 0; attr
< FRAG_ATTRIB_MAX
; ++attr
) {
43 /* Ignore unused inputs. */
44 if (!(fprog
->Base
.InputsRead
& BITFIELD64_BIT(attr
)))
47 if (fprog
->InterpQualifier
[attr
] == INTERP_QUALIFIER_NOPERSPECTIVE
)
55 upload_clip_state(struct brw_context
*brw
)
57 struct intel_context
*intel
= &brw
->intel
;
58 struct gl_context
*ctx
= &intel
->ctx
;
59 uint32_t depth_clamp
= 0;
60 uint32_t provoking
, userclip
;
61 uint32_t nonperspective_barycentric_enable_flag
= 0;
62 /* BRW_NEW_FRAGMENT_PROGRAM */
63 const struct gl_fragment_program
*fprog
= brw
->fragment_program
;
65 if (brw_fprog_uses_noperspective(fprog
)) {
66 nonperspective_barycentric_enable_flag
=
67 GEN6_CLIP_NON_PERSPECTIVE_BARYCENTRIC_ENABLE
;
71 /* HiZ operations emit a rectangle primitive, which requires clipping to
72 * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
73 * Section 1.3 3D Primitives Overview:
75 * Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
76 * Mode should be set to a value other than CLIPMODE_NORMAL.
79 OUT_BATCH(_3DSTATE_CLIP
<< 16 | (4 - 2));
87 if (!ctx
->Transform
.DepthClamp
)
88 depth_clamp
= GEN6_CLIP_Z_TEST
;
91 if (ctx
->Light
.ProvokingVertex
== GL_FIRST_VERTEX_CONVENTION
) {
93 (0 << GEN6_CLIP_TRI_PROVOKE_SHIFT
) |
94 (1 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT
) |
95 (0 << GEN6_CLIP_LINE_PROVOKE_SHIFT
);
98 (2 << GEN6_CLIP_TRI_PROVOKE_SHIFT
) |
99 (2 << GEN6_CLIP_TRIFAN_PROVOKE_SHIFT
) |
100 (1 << GEN6_CLIP_LINE_PROVOKE_SHIFT
);
104 userclip
= ctx
->Transform
.ClipPlanesEnabled
;
107 OUT_BATCH(_3DSTATE_CLIP
<< 16 | (4 - 2));
108 OUT_BATCH(GEN6_CLIP_STATISTICS_ENABLE
);
109 OUT_BATCH(GEN6_CLIP_ENABLE
|
111 GEN6_CLIP_MODE_NORMAL
|
112 nonperspective_barycentric_enable_flag
|
114 userclip
<< GEN6_USER_CLIP_CLIP_DISTANCES_SHIFT
|
117 OUT_BATCH(U_FIXED(0.125, 3) << GEN6_CLIP_MIN_POINT_WIDTH_SHIFT
|
118 U_FIXED(255.875, 3) << GEN6_CLIP_MAX_POINT_WIDTH_SHIFT
|
119 GEN6_CLIP_FORCE_ZERO_RTAINDEX
);
123 const struct brw_tracked_state gen6_clip_state
= {
125 .mesa
= _NEW_TRANSFORM
| _NEW_LIGHT
,
126 .brw
= (BRW_NEW_CONTEXT
|
127 BRW_NEW_FRAGMENT_PROGRAM
|
131 .emit
= upload_clip_state
,