Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2011 Intel Corporation |
| 3 | * |
| 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: |
| 10 | * |
| 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 |
| 13 | * Software. |
| 14 | * |
| 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 |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include "brw_context.h" |
| 25 | #include "brw_state.h" |
| 26 | #include "brw_defines.h" |
| 27 | #include "brw_util.h" |
| 28 | #include "main/macros.h" |
Brian Paul | 4433b03 | 2012-04-20 07:58:59 -0600 | [diff] [blame] | 29 | #include "main/fbobject.h" |
Kevin Rogovin | 41b6db2 | 2015-06-17 13:29:55 +0300 | [diff] [blame] | 30 | #include "main/framebuffer.h" |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 31 | #include "intel_batchbuffer.h" |
| 32 | |
| 33 | static void |
| 34 | upload_sbe_state(struct brw_context *brw) |
| 35 | { |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 36 | struct gl_context *ctx = &brw->ctx; |
Kenneth Graunke | ce44b20 | 2014-11-24 23:30:51 -0800 | [diff] [blame] | 37 | /* BRW_NEW_FS_PROG_DATA */ |
Kenneth Graunke | 16d5536 | 2016-09-08 23:48:53 -0700 | [diff] [blame] | 38 | const struct brw_wm_prog_data *wm_prog_data = |
| 39 | brw_wm_prog_data(brw->wm.base.prog_data); |
| 40 | uint32_t num_outputs = wm_prog_data->num_varying_inputs; |
Kenneth Graunke | 0d0edf8 | 2013-12-09 16:06:51 -0800 | [diff] [blame] | 41 | uint32_t dw1; |
| 42 | uint32_t point_sprite_enables; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 43 | int i; |
Paul Berry | 0af1252 | 2013-09-02 21:59:04 -0700 | [diff] [blame] | 44 | uint16_t attr_overrides[16]; |
Yuanhan Liu | eaf360e | 2012-01-20 07:48:52 +0800 | [diff] [blame] | 45 | /* _NEW_BUFFERS */ |
Brian Paul | 4433b03 | 2012-04-20 07:58:59 -0600 | [diff] [blame] | 46 | bool render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer); |
Yuanhan Liu | eaf360e | 2012-01-20 07:48:52 +0800 | [diff] [blame] | 47 | uint32_t point_sprite_origin; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 48 | |
| 49 | /* FINISHME: Attribute Swizzle Control Mode? */ |
Kenneth Graunke | 44aa2e1 | 2013-02-02 12:46:57 -0800 | [diff] [blame] | 50 | dw1 = GEN7_SBE_SWIZZLE_ENABLE | num_outputs << GEN7_SBE_NUM_OUTPUTS_SHIFT; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 51 | |
Yuanhan Liu | eaf360e | 2012-01-20 07:48:52 +0800 | [diff] [blame] | 52 | /* _NEW_POINT |
| 53 | * |
| 54 | * Window coordinates in an FBO are inverted, which means point |
| 55 | * sprite origin must be inverted. |
| 56 | */ |
| 57 | if ((ctx->Point.SpriteOrigin == GL_LOWER_LEFT) != render_to_fbo) { |
| 58 | point_sprite_origin = GEN6_SF_POINT_SPRITE_LOWERLEFT; |
| 59 | } else { |
| 60 | point_sprite_origin = GEN6_SF_POINT_SPRITE_UPPERLEFT; |
| 61 | } |
| 62 | dw1 |= point_sprite_origin; |
| 63 | |
Kenneth Graunke | cd19db4 | 2016-08-25 23:00:13 -0700 | [diff] [blame] | 64 | /* _NEW_POINT | _NEW_LIGHT | _NEW_PROGRAM, |
| 65 | * BRW_NEW_FS_PROG_DATA | BRW_NEW_FRAGMENT_PROGRAM | |
Kenneth Graunke | 4c116cb | 2016-08-25 22:52:22 -0700 | [diff] [blame] | 66 | * BRW_NEW_GS_PROG_DATA | BRW_NEW_PRIMITIVE | BRW_NEW_TES_PROG_DATA | |
Kenneth Graunke | cd19db4 | 2016-08-25 23:00:13 -0700 | [diff] [blame] | 67 | * BRW_NEW_VUE_MAP_GEOM_OUT |
Paul Berry | 0af1252 | 2013-09-02 21:59:04 -0700 | [diff] [blame] | 68 | */ |
Paul Berry | af84bbd | 2013-09-02 18:09:08 -0700 | [diff] [blame] | 69 | uint32_t urb_entry_read_length; |
Kenneth Graunke | 5392328 | 2015-10-26 00:52:14 -0700 | [diff] [blame] | 70 | uint32_t urb_entry_read_offset; |
Kenneth Graunke | 0d0edf8 | 2013-12-09 16:06:51 -0800 | [diff] [blame] | 71 | calculate_attr_overrides(brw, attr_overrides, &point_sprite_enables, |
Jason Ekstrand | c62db27 | 2016-04-05 18:23:36 -0700 | [diff] [blame] | 72 | &urb_entry_read_length, &urb_entry_read_offset); |
Kenneth Graunke | 44aa2e1 | 2013-02-02 12:46:57 -0800 | [diff] [blame] | 73 | dw1 |= urb_entry_read_length << GEN7_SBE_URB_ENTRY_READ_LENGTH_SHIFT | |
| 74 | urb_entry_read_offset << GEN7_SBE_URB_ENTRY_READ_OFFSET_SHIFT; |
| 75 | |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 76 | BEGIN_BATCH(14); |
| 77 | OUT_BATCH(_3DSTATE_SBE << 16 | (14 - 2)); |
| 78 | OUT_BATCH(dw1); |
| 79 | |
| 80 | /* Output dwords 2 through 9 */ |
| 81 | for (i = 0; i < 8; i++) { |
Kenneth Graunke | 5edb3dd | 2011-06-29 15:05:52 -0700 | [diff] [blame] | 82 | OUT_BATCH(attr_overrides[i * 2] | attr_overrides[i * 2 + 1] << 16); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Kenneth Graunke | 0d0edf8 | 2013-12-09 16:06:51 -0800 | [diff] [blame] | 85 | OUT_BATCH(point_sprite_enables); /* dw10 */ |
Kenneth Graunke | 16d5536 | 2016-09-08 23:48:53 -0700 | [diff] [blame] | 86 | OUT_BATCH(wm_prog_data->flat_inputs); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 87 | OUT_BATCH(0); /* wrapshortest enables 0-7 */ |
| 88 | OUT_BATCH(0); /* wrapshortest enables 8-15 */ |
| 89 | ADVANCE_BATCH(); |
| 90 | } |
| 91 | |
| 92 | const struct brw_tracked_state gen7_sbe_state = { |
| 93 | .dirty = { |
Kenneth Graunke | bea9b8e | 2014-11-24 23:16:56 -0800 | [diff] [blame] | 94 | .mesa = _NEW_BUFFERS | |
| 95 | _NEW_LIGHT | |
| 96 | _NEW_POINT | |
Kenneth Graunke | cd19db4 | 2016-08-25 23:00:13 -0700 | [diff] [blame] | 97 | _NEW_POLYGON | |
Kenneth Graunke | bea9b8e | 2014-11-24 23:16:56 -0800 | [diff] [blame] | 98 | _NEW_PROGRAM, |
Kenneth Graunke | 6d5ce1b | 2016-04-22 01:48:56 -0700 | [diff] [blame] | 99 | .brw = BRW_NEW_BLORP | |
| 100 | BRW_NEW_CONTEXT | |
Kenneth Graunke | bea9b8e | 2014-11-24 23:16:56 -0800 | [diff] [blame] | 101 | BRW_NEW_FRAGMENT_PROGRAM | |
Kenneth Graunke | 4f24c16 | 2014-11-24 23:57:48 -0800 | [diff] [blame] | 102 | BRW_NEW_FS_PROG_DATA | |
Kenneth Graunke | 4c116cb | 2016-08-25 22:52:22 -0700 | [diff] [blame] | 103 | BRW_NEW_GS_PROG_DATA | |
Kenneth Graunke | cd19db4 | 2016-08-25 23:00:13 -0700 | [diff] [blame] | 104 | BRW_NEW_TES_PROG_DATA | |
Kenneth Graunke | bea9b8e | 2014-11-24 23:16:56 -0800 | [diff] [blame] | 105 | BRW_NEW_PRIMITIVE | |
| 106 | BRW_NEW_VUE_MAP_GEOM_OUT, |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 107 | }, |
| 108 | .emit = upload_sbe_state, |
| 109 | }; |
| 110 | |
| 111 | static void |
| 112 | upload_sf_state(struct brw_context *brw) |
| 113 | { |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 114 | struct gl_context *ctx = &brw->ctx; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 115 | uint32_t dw1, dw2, dw3; |
| 116 | float point_size; |
| 117 | /* _NEW_BUFFERS */ |
Kenneth Graunke | e3c2bb1 | 2013-07-03 23:32:20 -0700 | [diff] [blame] | 118 | bool render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer); |
Kevin Rogovin | 41b6db2 | 2015-06-17 13:29:55 +0300 | [diff] [blame] | 119 | const bool multisampled_fbo = _mesa_geometric_samples(ctx->DrawBuffer) > 1; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 120 | |
Kristian Høgsberg | ff7a2fc | 2014-07-07 15:00:46 -0700 | [diff] [blame] | 121 | dw1 = GEN6_SF_STATISTICS_ENABLE; |
| 122 | |
| 123 | if (brw->sf.viewport_transform_enable) |
| 124 | dw1 |= GEN6_SF_VIEWPORT_TRANSFORM_ENABLE; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 125 | |
Eric Anholt | a98dd64 | 2011-05-13 11:54:15 -0700 | [diff] [blame] | 126 | /* _NEW_BUFFERS */ |
Eric Anholt | d84a180 | 2011-11-17 14:45:54 -0800 | [diff] [blame] | 127 | dw1 |= (brw_depthbuffer_format(brw) << GEN7_SF_DEPTH_BUFFER_SURFACE_FORMAT_SHIFT); |
Kenneth Graunke | 8c8985b | 2011-04-08 23:51:21 -0700 | [diff] [blame] | 128 | |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 129 | /* _NEW_POLYGON */ |
Mathias Fröhlich | fdd90fc | 2015-03-29 16:52:57 +0200 | [diff] [blame] | 130 | if (ctx->Polygon._FrontBit == render_to_fbo) |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 131 | dw1 |= GEN6_SF_WINDING_CCW; |
| 132 | |
| 133 | if (ctx->Polygon.OffsetFill) |
| 134 | dw1 |= GEN6_SF_GLOBAL_DEPTH_OFFSET_SOLID; |
| 135 | |
| 136 | if (ctx->Polygon.OffsetLine) |
| 137 | dw1 |= GEN6_SF_GLOBAL_DEPTH_OFFSET_WIREFRAME; |
| 138 | |
| 139 | if (ctx->Polygon.OffsetPoint) |
| 140 | dw1 |= GEN6_SF_GLOBAL_DEPTH_OFFSET_POINT; |
| 141 | |
| 142 | switch (ctx->Polygon.FrontMode) { |
| 143 | case GL_FILL: |
| 144 | dw1 |= GEN6_SF_FRONT_SOLID; |
| 145 | break; |
| 146 | |
| 147 | case GL_LINE: |
| 148 | dw1 |= GEN6_SF_FRONT_WIREFRAME; |
| 149 | break; |
| 150 | |
| 151 | case GL_POINT: |
| 152 | dw1 |= GEN6_SF_FRONT_POINT; |
| 153 | break; |
| 154 | |
| 155 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 156 | unreachable("not reached"); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | switch (ctx->Polygon.BackMode) { |
| 160 | case GL_FILL: |
| 161 | dw1 |= GEN6_SF_BACK_SOLID; |
| 162 | break; |
| 163 | |
| 164 | case GL_LINE: |
| 165 | dw1 |= GEN6_SF_BACK_WIREFRAME; |
| 166 | break; |
| 167 | |
| 168 | case GL_POINT: |
| 169 | dw1 |= GEN6_SF_BACK_POINT; |
| 170 | break; |
| 171 | |
| 172 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 173 | unreachable("not reached"); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Kenneth Graunke | 0946822 | 2017-01-11 21:38:52 -0800 | [diff] [blame^] | 176 | dw2 = GEN6_SF_SCISSOR_ENABLE; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 177 | |
| 178 | if (ctx->Polygon.CullFlag) { |
| 179 | switch (ctx->Polygon.CullFaceMode) { |
| 180 | case GL_FRONT: |
| 181 | dw2 |= GEN6_SF_CULL_FRONT; |
| 182 | break; |
| 183 | case GL_BACK: |
| 184 | dw2 |= GEN6_SF_CULL_BACK; |
| 185 | break; |
| 186 | case GL_FRONT_AND_BACK: |
| 187 | dw2 |= GEN6_SF_CULL_BOTH; |
| 188 | break; |
| 189 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 190 | unreachable("not reached"); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 191 | } |
| 192 | } else { |
| 193 | dw2 |= GEN6_SF_CULL_NONE; |
| 194 | } |
| 195 | |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 196 | /* _NEW_LINE */ |
Paul Berry | 19e9b24 | 2012-04-29 21:41:42 -0700 | [diff] [blame] | 197 | { |
Iago Toral Quiroga | 0f1fe64 | 2015-06-11 08:49:46 +0200 | [diff] [blame] | 198 | uint32_t line_width_u3_7 = brw_get_line_width(brw); |
Paul Berry | 19e9b24 | 2012-04-29 21:41:42 -0700 | [diff] [blame] | 199 | dw2 |= line_width_u3_7 << GEN6_SF_LINE_WIDTH_SHIFT; |
| 200 | } |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 201 | if (ctx->Line.SmoothFlag) { |
| 202 | dw2 |= GEN6_SF_LINE_AA_ENABLE; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 203 | dw2 |= GEN6_SF_LINE_END_CAP_WIDTH_1_0; |
| 204 | } |
Kenneth Graunke | 794de2f | 2013-07-06 00:15:44 -0700 | [diff] [blame] | 205 | if (ctx->Line.StippleFlag && brw->is_haswell) { |
Kenneth Graunke | b4410ac | 2011-09-24 00:42:23 -0700 | [diff] [blame] | 206 | dw2 |= HSW_SF_LINE_STIPPLE_ENABLE; |
| 207 | } |
Paul Berry | cde6544 | 2012-06-16 11:32:04 -0700 | [diff] [blame] | 208 | /* _NEW_MULTISAMPLE */ |
| 209 | if (multisampled_fbo && ctx->Multisample.Enabled) |
Paul Berry | 19e9b24 | 2012-04-29 21:41:42 -0700 | [diff] [blame] | 210 | dw2 |= GEN6_SF_MSRAST_ON_PATTERN; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 211 | |
| 212 | /* FINISHME: Last Pixel Enable? Vertex Sub Pixel Precision Select? |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 213 | */ |
| 214 | |
Kenneth Graunke | e639385 | 2012-11-08 04:13:26 -0800 | [diff] [blame] | 215 | dw3 = GEN6_SF_LINE_AA_MODE_TRUE; |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 216 | |
Kenneth Graunke | 77d6add | 2016-06-01 17:32:55 -0700 | [diff] [blame] | 217 | /* _NEW_PROGRAM | _NEW_POINT, BRW_NEW_VUE_MAP_GEOM_OUT */ |
| 218 | if (use_state_point_size(brw)) |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 219 | dw3 |= GEN6_SF_USE_STATE_POINT_WIDTH; |
| 220 | |
Kenneth Graunke | f74a291 | 2016-06-01 17:32:55 -0700 | [diff] [blame] | 221 | /* _NEW_POINT - Clamp to ARB_point_parameters user limits */ |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 222 | point_size = CLAMP(ctx->Point.Size, ctx->Point.MinSize, ctx->Point.MaxSize); |
| 223 | |
| 224 | /* Clamp to the hardware limits and convert to fixed point */ |
Matt Turner | c1da157 | 2015-07-12 00:13:45 -0700 | [diff] [blame] | 225 | dw3 |= U_FIXED(CLAMP(point_size, 0.125f, 255.875f), 3); |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 226 | |
| 227 | /* _NEW_LIGHT */ |
| 228 | if (ctx->Light.ProvokingVertex != GL_FIRST_VERTEX_CONVENTION) { |
| 229 | dw3 |= |
| 230 | (2 << GEN6_SF_TRI_PROVOKE_SHIFT) | |
| 231 | (2 << GEN6_SF_TRIFAN_PROVOKE_SHIFT) | |
| 232 | (1 << GEN6_SF_LINE_PROVOKE_SHIFT); |
| 233 | } else { |
| 234 | dw3 |= (1 << GEN6_SF_TRIFAN_PROVOKE_SHIFT); |
| 235 | } |
| 236 | |
| 237 | BEGIN_BATCH(7); |
| 238 | OUT_BATCH(_3DSTATE_SF << 16 | (7 - 2)); |
| 239 | OUT_BATCH(dw1); |
| 240 | OUT_BATCH(dw2); |
| 241 | OUT_BATCH(dw3); |
| 242 | OUT_BATCH_F(ctx->Polygon.OffsetUnits * 2); /* constant. copied from gen4 */ |
| 243 | OUT_BATCH_F(ctx->Polygon.OffsetFactor); /* scale */ |
Ilia Mirkin | 2ce29ce | 2014-12-31 02:15:23 -0500 | [diff] [blame] | 244 | OUT_BATCH_F(ctx->Polygon.OffsetClamp); /* global depth offset clamp */ |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 245 | ADVANCE_BATCH(); |
| 246 | } |
| 247 | |
| 248 | const struct brw_tracked_state gen7_sf_state = { |
| 249 | .dirty = { |
Kenneth Graunke | bea9b8e | 2014-11-24 23:16:56 -0800 | [diff] [blame] | 250 | .mesa = _NEW_BUFFERS | |
| 251 | _NEW_LIGHT | |
| 252 | _NEW_LINE | |
| 253 | _NEW_MULTISAMPLE | |
| 254 | _NEW_POINT | |
| 255 | _NEW_POLYGON | |
Kenneth Graunke | 0946822 | 2017-01-11 21:38:52 -0800 | [diff] [blame^] | 256 | _NEW_PROGRAM, |
Kenneth Graunke | 6d5ce1b | 2016-04-22 01:48:56 -0700 | [diff] [blame] | 257 | .brw = BRW_NEW_BLORP | |
| 258 | BRW_NEW_CONTEXT | |
Kenneth Graunke | 4c116cb | 2016-08-25 22:52:22 -0700 | [diff] [blame] | 259 | BRW_NEW_GS_PROG_DATA | |
Kenneth Graunke | 77d6add | 2016-06-01 17:32:55 -0700 | [diff] [blame] | 260 | BRW_NEW_PRIMITIVE | |
Kenneth Graunke | cd19db4 | 2016-08-25 23:00:13 -0700 | [diff] [blame] | 261 | BRW_NEW_TES_PROG_DATA | |
Kenneth Graunke | 77d6add | 2016-06-01 17:32:55 -0700 | [diff] [blame] | 262 | BRW_NEW_VUE_MAP_GEOM_OUT, |
Kenneth Graunke | 7d608d0 | 2011-01-05 01:21:06 -0800 | [diff] [blame] | 263 | }, |
| 264 | .emit = upload_sf_state, |
| 265 | }; |