2 * Copyright © 2011 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 "intel_batchbuffer.h"
27 #include "intel_fbo.h"
28 #include "intel_mipmap_tree.h"
30 #include "brw_context.h"
31 #include "brw_defines.h"
32 #include "brw_state.h"
34 #include "brw_blorp.h"
35 #include "gen6_blorp.h"
38 * \name Constants for BLORP VBO
41 #define GEN6_BLORP_NUM_VERTICES 3
42 #define GEN6_BLORP_NUM_VUE_ELEMS 8
43 #define GEN6_BLORP_VBO_SIZE (GEN6_BLORP_NUM_VERTICES \
44 * GEN6_BLORP_NUM_VUE_ELEMS \
49 gen6_blorp_emit_batch_head(struct brw_context *brw,
50 const brw_blorp_params *params)
52 struct gl_context *ctx = &brw->intel.ctx;
53 struct intel_context *intel = &brw->intel;
55 /* To ensure that the batch contains only the resolve, flush the batch
56 * before beginning and after finishing emitting the resolve packets.
58 * Ideally, we would not need to flush for the resolve op. But, I suspect
59 * that it's unsafe for CMD_PIPELINE_SELECT to occur multiple times in
60 * a single batch, and there is no safe way to ensure that other than by
61 * fencing the resolve with flushes. Ideally, we would just detect if
62 * a batch is in progress and do the right thing, but that would require
63 * the ability to *safely* access brw_context::state::dirty::brw
64 * outside of the brw_upload_state() codepath.
68 /* CMD_PIPELINE_SELECT
70 * Select the 3D pipeline, as opposed to the media pipeline.
74 OUT_BATCH(brw->CMD_PIPELINE_SELECT << 16);
81 * CMD_STATE_BASE_ADDRESS
83 * From the Sandy Bridge PRM, Volume 1, Part 1, Table STATE_BASE_ADDRESS:
84 * The following commands must be reissued following any change to the
87 * 3DSTATE_BINDING_TABLE_POINTERS
88 * 3DSTATE_SAMPLER_STATE_POINTERS
89 * 3DSTATE_VIEWPORT_STATE_POINTERS
90 * MEDIA_STATE_POINTERS
93 gen6_blorp_emit_state_base_address(struct brw_context *brw,
94 const brw_blorp_params *params)
96 struct intel_context *intel = &brw->intel;
99 OUT_BATCH(CMD_STATE_BASE_ADDRESS << 16 | (10 - 2));
100 OUT_BATCH(1); /* GeneralStateBaseAddressModifyEnable */
101 /* SurfaceStateBaseAddress */
102 OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_SAMPLER, 0, 1);
103 /* DynamicStateBaseAddress */
104 OUT_RELOC(intel->batch.bo, (I915_GEM_DOMAIN_RENDER |
105 I915_GEM_DOMAIN_INSTRUCTION), 0, 1);
106 OUT_BATCH(1); /* IndirectObjectBaseAddress */
107 if (params->use_wm_prog) {
108 OUT_RELOC(brw->cache.bo, I915_GEM_DOMAIN_INSTRUCTION, 0,
109 1); /* Instruction base address: shader kernels */
111 OUT_BATCH(1); /* InstructionBaseAddress */
113 OUT_BATCH(1); /* GeneralStateUpperBound */
114 /* Dynamic state upper bound. Although the documentation says that
115 * programming it to zero will cause it to be ignored, that is a lie.
116 * If this isn't programmed to a real bound, the sampler border color
117 * pointer is rejected, causing border color to mysteriously fail.
119 OUT_BATCH(0xfffff001);
120 OUT_BATCH(1); /* IndirectObjectUpperBound*/
121 OUT_BATCH(1); /* InstructionAccessUpperBound */
127 gen6_blorp_emit_vertices(struct brw_context *brw,
128 const brw_blorp_params *params)
130 struct intel_context *intel = &brw->intel;
131 uint32_t vertex_offset;
133 /* Setup VBO for the rectangle primitive..
135 * A rectangle primitive (3DPRIM_RECTLIST) consists of only three
136 * vertices. The vertices reside in screen space with DirectX coordinates
137 * (that is, (0, 0) is the upper left corner).
144 * Since the VS is disabled, the clipper loads each VUE directly from
145 * the URB. This is controlled by the 3DSTATE_VERTEX_BUFFERS and
146 * 3DSTATE_VERTEX_ELEMENTS packets below. The VUE contents are as follows:
147 * dw0: Reserved, MBZ.
148 * dw1: Render Target Array Index. The HiZ op does not use indexed
149 * vertices, so set the dword to 0.
150 * dw2: Viewport Index. The HiZ op disables viewport mapping and
151 * scissoring, so set the dword to 0.
152 * dw3: Point Width: The HiZ op does not emit the POINTLIST primitive, so
153 * set the dword to 0.
154 * dw4: Vertex Position X.
155 * dw5: Vertex Position Y.
156 * dw6: Vertex Position Z.
157 * dw7: Vertex Position W.
159 * For details, see the Sandybridge PRM, Volume 2, Part 1, Section 1.5.1
160 * "Vertex URB Entry (VUE) Formats".
165 const float vertices[GEN6_BLORP_VBO_SIZE] = {
166 /* v0 */ 0, 0, 0, 0, (float) params->x0, (float) params->y1, 0, 1,
167 /* v1 */ 0, 0, 0, 0, (float) params->x1, (float) params->y1, 0, 1,
168 /* v2 */ 0, 0, 0, 0, (float) params->x0, (float) params->y0, 0, 1,
171 vertex_data = (float *) brw_state_batch(brw, AUB_TRACE_VERTEX_BUFFER,
172 GEN6_BLORP_VBO_SIZE, 32,
174 memcpy(vertex_data, vertices, GEN6_BLORP_VBO_SIZE);
177 /* 3DSTATE_VERTEX_BUFFERS */
179 const int num_buffers = 1;
180 const int batch_length = 1 + 4 * num_buffers;
182 uint32_t dw0 = GEN6_VB0_ACCESS_VERTEXDATA |
183 (GEN6_BLORP_NUM_VUE_ELEMS * sizeof(float)) << BRW_VB0_PITCH_SHIFT;
186 dw0 |= GEN7_VB0_ADDRESS_MODIFYENABLE;
188 BEGIN_BATCH(batch_length);
189 OUT_BATCH((_3DSTATE_VERTEX_BUFFERS << 16) | (batch_length - 2));
192 OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_VERTEX, 0,
195 OUT_RELOC(intel->batch.bo, I915_GEM_DOMAIN_VERTEX, 0,
196 vertex_offset + GEN6_BLORP_VBO_SIZE - 1);
201 /* 3DSTATE_VERTEX_ELEMENTS
203 * Fetch dwords 0 - 7 from each VUE. See the comments above where
204 * the vertex_bo is filled with data.
207 const int num_elements = 2;
208 const int batch_length = 1 + 2 * num_elements;
210 BEGIN_BATCH(batch_length);
211 OUT_BATCH((_3DSTATE_VERTEX_ELEMENTS << 16) | (batch_length - 2));
213 OUT_BATCH(GEN6_VE0_VALID |
214 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT << BRW_VE0_FORMAT_SHIFT |
215 0 << BRW_VE0_SRC_OFFSET_SHIFT);
216 OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_0_SHIFT |
217 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_1_SHIFT |
218 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_2_SHIFT |
219 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_3_SHIFT);
221 OUT_BATCH(GEN6_VE0_VALID |
222 BRW_SURFACEFORMAT_R32G32B32A32_FLOAT << BRW_VE0_FORMAT_SHIFT |
223 16 << BRW_VE0_SRC_OFFSET_SHIFT);
224 OUT_BATCH(BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_0_SHIFT |
225 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_1_SHIFT |
226 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_2_SHIFT |
227 BRW_VE1_COMPONENT_STORE_SRC << BRW_VE1_COMPONENT_3_SHIFT);
235 * Assign the entire URB to the VS. Even though the VS disabled, URB space
236 * is still needed because the clipper loads the VUE's from the URB. From
237 * the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE,
238 * Dword 1.15:0 "VS Number of URB Entries":
239 * This field is always used (even if VS Function Enable is DISABLED).
241 * The warning below appears in the PRM (Section 3DSTATE_URB), but we can
242 * safely ignore it because this batch contains only one draw call.
243 * Because of URB corruption caused by allocating a previous GS unit
244 * URB entry to the VS unit, software is required to send a “GS NULL
245 * Fence” (Send URB fence with VS URB size == 1 and GS URB size == 0)
246 * plus a dummy DRAW call before any case where VS will be taking over
250 gen6_blorp_emit_urb_config(struct brw_context *brw,
251 const brw_blorp_params *params)
253 struct intel_context *intel = &brw->intel;
256 OUT_BATCH(_3DSTATE_URB << 16 | (3 - 2));
257 OUT_BATCH(brw->urb.max_vs_entries << GEN6_URB_VS_ENTRIES_SHIFT);
265 gen6_blorp_emit_blend_state(struct brw_context *brw,
266 const brw_blorp_params *params)
268 uint32_t cc_blend_state_offset;
270 struct gen6_blend_state *blend = (struct gen6_blend_state *)
271 brw_state_batch(brw, AUB_TRACE_BLEND_STATE,
272 sizeof(struct gen6_blend_state), 64,
273 &cc_blend_state_offset);
275 memset(blend, 0, sizeof(*blend));
277 blend->blend1.pre_blend_clamp_enable = 1;
278 blend->blend1.post_blend_clamp_enable = 1;
279 blend->blend1.clamp_range = BRW_RENDERTARGET_CLAMPRANGE_FORMAT;
281 blend->blend1.write_disable_r = params->color_write_disable[0];
282 blend->blend1.write_disable_g = params->color_write_disable[1];
283 blend->blend1.write_disable_b = params->color_write_disable[2];
284 blend->blend1.write_disable_a = params->color_write_disable[3];
286 /* When blitting from an XRGB source to a ARGB destination, we need to
287 * interpret the missing channel as 1.0. Blending can do that for us:
288 * we simply use the RGB values from the fragment shader ("source RGB"),
289 * but smash the alpha channel to 1.
291 if (params->src.mt &&
292 _mesa_get_format_bits(params->dst.mt->format, GL_ALPHA_BITS) > 0 &&
293 _mesa_get_format_bits(params->src.mt->format, GL_ALPHA_BITS) == 0) {
294 blend->blend0.blend_enable = 1;
295 blend->blend0.ia_blend_enable = 1;
297 blend->blend0.blend_func = BRW_BLENDFUNCTION_ADD;
298 blend->blend0.ia_blend_func = BRW_BLENDFUNCTION_ADD;
300 blend->blend0.source_blend_factor = BRW_BLENDFACTOR_SRC_COLOR;
301 blend->blend0.dest_blend_factor = BRW_BLENDFACTOR_ZERO;
302 blend->blend0.ia_source_blend_factor = BRW_BLENDFACTOR_ONE;
303 blend->blend0.ia_dest_blend_factor = BRW_BLENDFACTOR_ZERO;
306 return cc_blend_state_offset;
312 gen6_blorp_emit_cc_state(struct brw_context *brw,
313 const brw_blorp_params *params)
315 uint32_t cc_state_offset;
317 struct gen6_color_calc_state *cc = (struct gen6_color_calc_state *)
318 brw_state_batch(brw, AUB_TRACE_CC_STATE,
319 sizeof(gen6_color_calc_state), 64,
321 memset(cc, 0, sizeof(*cc));
323 return cc_state_offset;
328 * \param out_offset is relative to
329 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
332 gen6_blorp_emit_depth_stencil_state(struct brw_context *brw,
333 const brw_blorp_params *params)
335 uint32_t depthstencil_offset;
337 struct gen6_depth_stencil_state *state;
338 state = (struct gen6_depth_stencil_state *)
339 brw_state_batch(brw, AUB_TRACE_DEPTH_STENCIL_STATE,
341 &depthstencil_offset);
342 memset(state, 0, sizeof(*state));
344 /* See the following sections of the Sandy Bridge PRM, Volume 1, Part2:
345 * - 7.5.3.1 Depth Buffer Clear
346 * - 7.5.3.2 Depth Buffer Resolve
347 * - 7.5.3.3 Hierarchical Depth Buffer Resolve
349 state->ds2.depth_write_enable = 1;
350 if (params->hiz_op == GEN6_HIZ_OP_DEPTH_RESOLVE) {
351 state->ds2.depth_test_enable = 1;
352 state->ds2.depth_test_func = COMPAREFUNC_NEVER;
355 return depthstencil_offset;
359 /* 3DSTATE_CC_STATE_POINTERS
361 * The pointer offsets are relative to
362 * CMD_STATE_BASE_ADDRESS.DynamicStateBaseAddress.
364 * The HiZ op doesn't use BLEND_STATE or COLOR_CALC_STATE.
367 gen6_blorp_emit_cc_state_pointers(struct brw_context *brw,
368 const brw_blorp_params *params,
369 uint32_t cc_blend_state_offset,
370 uint32_t depthstencil_offset,
371 uint32_t cc_state_offset)
373 struct intel_context *intel = &brw->intel;
376 OUT_BATCH(_3DSTATE_CC_STATE_POINTERS << 16 | (4 - 2));
377 OUT_BATCH(cc_blend_state_offset | 1); /* BLEND_STATE offset */
378 OUT_BATCH(depthstencil_offset | 1); /* DEPTH_STENCIL_STATE offset */
379 OUT_BATCH(cc_state_offset | 1); /* COLOR_CALC_STATE offset */
384 /* WM push constants */
386 gen6_blorp_emit_wm_constants(struct brw_context *brw,
387 const brw_blorp_params *params)
389 uint32_t wm_push_const_offset;
391 void *constants = brw_state_batch(brw, AUB_TRACE_WM_CONSTANTS,
392 sizeof(params->wm_push_consts),
393 32, &wm_push_const_offset);
394 memcpy(constants, ¶ms->wm_push_consts,
395 sizeof(params->wm_push_consts));
397 return wm_push_const_offset;
401 /* SURFACE_STATE for renderbuffer or texture surface (see
402 * brw_update_renderbuffer_surface and brw_update_texture_surface)
405 gen6_blorp_emit_surface_state(struct brw_context *brw,
406 const brw_blorp_params *params,
407 const brw_blorp_surface_info *surface,
408 uint32_t read_domains, uint32_t write_domain)
410 uint32_t wm_surf_offset;
411 uint32_t width = surface->width;
412 uint32_t height = surface->height;
413 if (surface->num_samples > 1) {
414 /* Since gen6 uses INTEL_MSAA_LAYOUT_IMS, width and height are measured
415 * in samples. But SURFACE_STATE wants them in pixels, so we need to
416 * divide them each by 2.
421 struct intel_region *region = surface->mt->region;
422 uint32_t tile_x, tile_y;
424 uint32_t *surf = (uint32_t *)
425 brw_state_batch(brw, AUB_TRACE_SURFACE_STATE, 6 * 4, 32,
428 surf[0] = (BRW_SURFACE_2D << BRW_SURFACE_TYPE_SHIFT |
429 BRW_SURFACE_MIPMAPLAYOUT_BELOW << BRW_SURFACE_MIPLAYOUT_SHIFT |
430 BRW_SURFACE_CUBEFACE_ENABLES |
431 surface->brw_surfaceformat << BRW_SURFACE_FORMAT_SHIFT);
434 surf[1] = (surface->compute_tile_offsets(&tile_x, &tile_y) +
437 surf[2] = (0 << BRW_SURFACE_LOD_SHIFT |
438 (width - 1) << BRW_SURFACE_WIDTH_SHIFT |
439 (height - 1) << BRW_SURFACE_HEIGHT_SHIFT);
441 uint32_t tiling = surface->map_stencil_as_y_tiled
442 ? BRW_SURFACE_TILED | BRW_SURFACE_TILED_Y
443 : brw_get_surface_tiling_bits(region->tiling);
444 uint32_t pitch_bytes = region->pitch;
445 if (surface->map_stencil_as_y_tiled)
448 0 << BRW_SURFACE_DEPTH_SHIFT |
449 (pitch_bytes - 1) << BRW_SURFACE_PITCH_SHIFT);
451 surf[4] = brw_get_surface_num_multisamples(surface->num_samples);
453 /* Note that the low bits of these fields are missing, so
454 * there's the possibility of getting in trouble.
456 assert(tile_x % 4 == 0);
457 assert(tile_y % 2 == 0);
458 surf[5] = ((tile_x / 4) << BRW_SURFACE_X_OFFSET_SHIFT |
459 (tile_y / 2) << BRW_SURFACE_Y_OFFSET_SHIFT |
460 (surface->mt->align_h == 4 ?
461 BRW_SURFACE_VERTICAL_ALIGN_ENABLE : 0));
463 /* Emit relocation to surface contents */
464 drm_intel_bo_emit_reloc(brw->intel.batch.bo,
467 surf[1] - region->bo->offset,
468 read_domains, write_domain);
470 return wm_surf_offset;
474 /* BINDING_TABLE. See brw_wm_binding_table(). */
476 gen6_blorp_emit_binding_table(struct brw_context *brw,
477 const brw_blorp_params *params,
478 uint32_t wm_surf_offset_renderbuffer,
479 uint32_t wm_surf_offset_texture)
481 uint32_t wm_bind_bo_offset;
482 uint32_t *bind = (uint32_t *)
483 brw_state_batch(brw, AUB_TRACE_BINDING_TABLE,
485 BRW_BLORP_NUM_BINDING_TABLE_ENTRIES,
488 bind[BRW_BLORP_RENDERBUFFER_BINDING_TABLE_INDEX] =
489 wm_surf_offset_renderbuffer;
490 bind[BRW_BLORP_TEXTURE_BINDING_TABLE_INDEX] = wm_surf_offset_texture;
492 return wm_bind_bo_offset;
497 * SAMPLER_STATE. See brw_update_sampler_state().
500 gen6_blorp_emit_sampler_state(struct brw_context *brw,
501 const brw_blorp_params *params)
503 uint32_t sampler_offset;
505 struct brw_sampler_state *sampler = (struct brw_sampler_state *)
506 brw_state_batch(brw, AUB_TRACE_SAMPLER_STATE,
507 sizeof(struct brw_sampler_state),
508 32, &sampler_offset);
509 memset(sampler, 0, sizeof(*sampler));
511 sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
512 sampler->ss0.mip_filter = BRW_MIPFILTER_NONE;
513 sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
515 sampler->ss1.r_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
516 sampler->ss1.s_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
517 sampler->ss1.t_wrap_mode = BRW_TEXCOORDMODE_CLAMP;
519 sampler->ss0.min_mag_neq = 1;
523 sampler->ss0.lod_bias = 0;
525 sampler->ss0.lod_preclamp = 1; /* OpenGL mode */
526 sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */
528 /* Set BaseMipLevel, MaxLOD, MinLOD:
530 * XXX: I don't think that using firstLevel, lastLevel works,
531 * because we always setup the surface state as if firstLevel ==
532 * level zero. Probably have to subtract firstLevel from each of
535 sampler->ss0.base_level = U_FIXED(0, 1);
537 sampler->ss1.max_lod = U_FIXED(0, 6);
538 sampler->ss1.min_lod = U_FIXED(0, 6);
540 sampler->ss3.non_normalized_coord = 1;
542 sampler->ss3.address_round |= BRW_ADDRESS_ROUNDING_ENABLE_U_MIN |
543 BRW_ADDRESS_ROUNDING_ENABLE_V_MIN |
544 BRW_ADDRESS_ROUNDING_ENABLE_R_MIN;
545 sampler->ss3.address_round |= BRW_ADDRESS_ROUNDING_ENABLE_U_MAG |
546 BRW_ADDRESS_ROUNDING_ENABLE_V_MAG |
547 BRW_ADDRESS_ROUNDING_ENABLE_R_MAG;
549 return sampler_offset;
554 * 3DSTATE_SAMPLER_STATE_POINTERS. See upload_sampler_state_pointers().
557 gen6_blorp_emit_sampler_state_pointers(struct brw_context *brw,
558 const brw_blorp_params *params,
559 uint32_t sampler_offset)
561 struct intel_context *intel = &brw->intel;
564 OUT_BATCH(_3DSTATE_SAMPLER_STATE_POINTERS << 16 |
565 VS_SAMPLER_STATE_CHANGE |
566 GS_SAMPLER_STATE_CHANGE |
567 PS_SAMPLER_STATE_CHANGE |
569 OUT_BATCH(0); /* VS */
570 OUT_BATCH(0); /* GS */
571 OUT_BATCH(sampler_offset);
578 * Disable vertex shader.
581 gen6_blorp_emit_vs_disable(struct brw_context *brw,
582 const brw_blorp_params *params)
584 struct intel_context *intel = &brw->intel;
586 if (intel->gen == 6) {
587 /* From the BSpec, Volume 2a, Part 3 "Vertex Shader", Section
588 * 3DSTATE_VS, Dword 5.0 "VS Function Enable":
590 * [DevSNB] A pipeline flush must be programmed prior to a
591 * 3DSTATE_VS command that causes the VS Function Enable to
592 * toggle. Pipeline flush can be executed by sending a PIPE_CONTROL
593 * command with CS stall bit set and a post sync operation.
595 intel_emit_post_sync_nonzero_flush(intel);
598 /* Disable the push constant buffers. */
600 OUT_BATCH(_3DSTATE_CONSTANT_VS << 16 | (5 - 2));
608 OUT_BATCH(_3DSTATE_VS << 16 | (6 - 2));
620 * Disable the geometry shader.
623 gen6_blorp_emit_gs_disable(struct brw_context *brw,
624 const brw_blorp_params *params)
626 struct intel_context *intel = &brw->intel;
628 /* Disable all the constant buffers. */
630 OUT_BATCH(_3DSTATE_CONSTANT_GS << 16 | (5 - 2));
638 OUT_BATCH(_3DSTATE_GS << 16 | (7 - 2));
651 * Disable the clipper.
653 * The BLORP op emits a rectangle primitive, which requires clipping to
654 * be disabled. From page 10 of the Sandy Bridge PRM Volume 2 Part 1
655 * Section 1.3 "3D Primitives Overview":
657 * Either the CLIP unit should be DISABLED, or the CLIP unit's Clip
658 * Mode should be set to a value other than CLIPMODE_NORMAL.
660 * Also disable perspective divide. This doesn't change the clipper's
661 * output, but does spare a few electrons.
664 gen6_blorp_emit_clip_disable(struct brw_context *brw,
665 const brw_blorp_params *params)
667 struct intel_context *intel = &brw->intel;
670 OUT_BATCH(_3DSTATE_CLIP << 16 | (4 - 2));
672 OUT_BATCH(GEN6_CLIP_PERSPECTIVE_DIVIDE_DISABLE);
680 * Disable ViewportTransformEnable (dw2.1)
682 * From the SandyBridge PRM, Volume 2, Part 1, Section 1.3, "3D
683 * Primitives Overview":
684 * RECTLIST: Viewport Mapping must be DISABLED (as is typical with the
685 * use of screen- space coordinates).
687 * A solid rectangle must be rendered, so set FrontFaceFillMode (dw2.4:3)
688 * and BackFaceFillMode (dw2.5:6) to SOLID(0).
690 * From the Sandy Bridge PRM, Volume 2, Part 1, Section
691 * 6.4.1.1 3DSTATE_SF, Field FrontFaceFillMode:
692 * SOLID: Any triangle or rectangle object found to be front-facing
693 * is rendered as a solid object. This setting is required when
694 * (rendering rectangle (RECTLIST) objects.
697 gen6_blorp_emit_sf_config(struct brw_context *brw,
698 const brw_blorp_params *params)
700 struct intel_context *intel = &brw->intel;
703 OUT_BATCH(_3DSTATE_SF << 16 | (20 - 2));
704 OUT_BATCH((1 - 1) << GEN6_SF_NUM_OUTPUTS_SHIFT | /* only position */
705 1 << GEN6_SF_URB_ENTRY_READ_LENGTH_SHIFT |
706 0 << GEN6_SF_URB_ENTRY_READ_OFFSET_SHIFT);
707 OUT_BATCH(0); /* dw2 */
708 OUT_BATCH(params->num_samples > 1 ? GEN6_SF_MSRAST_ON_PATTERN : 0);
709 for (int i = 0; i < 16; ++i)
716 * Enable or disable thread dispatch and set the HiZ op appropriately.
719 gen6_blorp_emit_wm_config(struct brw_context *brw,
720 const brw_blorp_params *params,
721 uint32_t prog_offset,
722 brw_blorp_prog_data *prog_data)
724 struct intel_context *intel = &brw->intel;
725 uint32_t dw2, dw4, dw5, dw6;
727 /* Even when thread dispatch is disabled, max threads (dw5.25:31) must be
728 * nonzero to prevent the GPU from hanging. See the valid ranges in the
729 * BSpec, Volume 2a.11 Windower, Section 3DSTATE_WM, Dword 5.25:31
730 * "Maximum Number Of Threads".
732 * To be safe (and to minimize extraneous code) we go ahead and fully
733 * configure the WM state whether or not there is a WM program.
736 dw2 = dw4 = dw5 = dw6 = 0;
737 switch (params->hiz_op) {
738 case GEN6_HIZ_OP_DEPTH_CLEAR:
739 dw4 |= GEN6_WM_DEPTH_CLEAR;
741 case GEN6_HIZ_OP_DEPTH_RESOLVE:
742 dw4 |= GEN6_WM_DEPTH_RESOLVE;
744 case GEN6_HIZ_OP_HIZ_RESOLVE:
745 dw4 |= GEN6_WM_HIERARCHICAL_DEPTH_RESOLVE;
747 case GEN6_HIZ_OP_NONE:
753 dw5 |= GEN6_WM_LINE_AA_WIDTH_1_0;
754 dw5 |= GEN6_WM_LINE_END_CAP_AA_WIDTH_0_5;
755 dw5 |= (brw->max_wm_threads - 1) << GEN6_WM_MAX_THREADS_SHIFT;
756 dw6 |= 0 << GEN6_WM_BARYCENTRIC_INTERPOLATION_MODE_SHIFT; /* No interp */
757 dw6 |= 0 << GEN6_WM_NUM_SF_OUTPUTS_SHIFT; /* No inputs from SF */
758 if (params->use_wm_prog) {
759 dw2 |= 1 << GEN6_WM_SAMPLER_COUNT_SHIFT; /* Up to 4 samplers */
760 dw4 |= prog_data->first_curbe_grf << GEN6_WM_DISPATCH_START_GRF_SHIFT_0;
761 dw5 |= GEN6_WM_16_DISPATCH_ENABLE;
762 dw5 |= GEN6_WM_KILL_ENABLE; /* TODO: temporarily smash on */
763 dw5 |= GEN6_WM_DISPATCH_ENABLE; /* We are rendering */
766 if (params->num_samples > 1) {
767 dw6 |= GEN6_WM_MSRAST_ON_PATTERN;
768 if (prog_data && prog_data->persample_msaa_dispatch)
769 dw6 |= GEN6_WM_MSDISPMODE_PERSAMPLE;
771 dw6 |= GEN6_WM_MSDISPMODE_PERPIXEL;
773 dw6 |= GEN6_WM_MSRAST_OFF_PIXEL;
774 dw6 |= GEN6_WM_MSDISPMODE_PERSAMPLE;
778 OUT_BATCH(_3DSTATE_WM << 16 | (9 - 2));
779 OUT_BATCH(params->use_wm_prog ? prog_offset : 0);
781 OUT_BATCH(0); /* No scratch needed */
785 OUT_BATCH(0); /* No other programs */
786 OUT_BATCH(0); /* No other programs */
792 gen6_blorp_emit_constant_ps(struct brw_context *brw,
793 const brw_blorp_params *params,
794 uint32_t wm_push_const_offset)
796 struct intel_context *intel = &brw->intel;
798 /* Make sure the push constants fill an exact integer number of
801 assert(sizeof(brw_blorp_wm_push_constants) % 32 == 0);
803 /* There must be at least one register worth of push constant data. */
804 assert(BRW_BLORP_NUM_PUSH_CONST_REGS > 0);
806 /* Enable push constant buffer 0. */
808 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 |
809 GEN6_CONSTANT_BUFFER_0_ENABLE |
811 OUT_BATCH(wm_push_const_offset + (BRW_BLORP_NUM_PUSH_CONST_REGS - 1));
819 gen6_blorp_emit_constant_ps_disable(struct brw_context *brw,
820 const brw_blorp_params *params)
822 struct intel_context *intel = &brw->intel;
824 /* Disable the push constant buffers. */
826 OUT_BATCH(_3DSTATE_CONSTANT_PS << 16 | (5 - 2));
835 * 3DSTATE_BINDING_TABLE_POINTERS
838 gen6_blorp_emit_binding_table_pointers(struct brw_context *brw,
839 const brw_blorp_params *params,
840 uint32_t wm_bind_bo_offset)
842 struct intel_context *intel = &brw->intel;
845 OUT_BATCH(_3DSTATE_BINDING_TABLE_POINTERS << 16 |
846 GEN6_BINDING_TABLE_MODIFY_PS |
848 OUT_BATCH(0); /* vs -- ignored */
849 OUT_BATCH(0); /* gs -- ignored */
850 OUT_BATCH(wm_bind_bo_offset); /* wm/ps */
856 gen6_blorp_emit_depth_stencil_config(struct brw_context *brw,
857 const brw_blorp_params *params)
859 struct intel_context *intel = &brw->intel;
860 struct gl_context *ctx = &intel->ctx;
861 uint32_t draw_x = params->depth.x_offset;
862 uint32_t draw_y = params->depth.y_offset;
863 uint32_t tile_mask_x, tile_mask_y;
865 brw_get_depthstencil_tile_masks(params->depth.mt,
869 &tile_mask_x, &tile_mask_y);
871 /* 3DSTATE_DEPTH_BUFFER */
873 uint32_t tile_x = draw_x & tile_mask_x;
874 uint32_t tile_y = draw_y & tile_mask_y;
876 intel_region_get_aligned_offset(params->depth.mt->region,
877 draw_x & ~tile_mask_x,
878 draw_y & ~tile_mask_y, false);
880 /* According to the Sandy Bridge PRM, volume 2 part 1, pp326-327
881 * (3DSTATE_DEPTH_BUFFER dw5), in the documentation for "Depth
882 * Coordinate Offset X/Y":
884 * "The 3 LSBs of both offsets must be zero to ensure correct
887 * We have no guarantee that tile_x and tile_y are correctly aligned,
888 * since they are determined by the mipmap layout, which is only aligned
891 * So, to avoid hanging the GPU, just smash the low order 3 bits of
892 * tile_x and tile_y to 0. This is a temporary workaround until we come
893 * up with a better solution.
895 WARN_ONCE((tile_x & 7) || (tile_y & 7),
896 "Depth/stencil buffer needs alignment to 8-pixel boundaries.\n"
897 "Truncating offset, bad rendering may occur.\n");
901 intel_emit_post_sync_nonzero_flush(intel);
902 intel_emit_depth_stall_flushes(intel);
905 OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
906 OUT_BATCH((params->depth.mt->region->pitch - 1) |
907 params->depth_format << 18 |
908 1 << 21 | /* separate stencil enable */
909 1 << 22 | /* hiz enable */
910 BRW_TILEWALK_YMAJOR << 26 |
911 1 << 27 | /* y-tiled */
912 BRW_SURFACE_2D << 29);
913 OUT_RELOC(params->depth.mt->region->bo,
914 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
916 OUT_BATCH(BRW_SURFACE_MIPMAPLAYOUT_BELOW << 1 |
917 (params->depth.width + tile_x - 1) << 6 |
918 (params->depth.height + tile_y - 1) << 19);
926 /* 3DSTATE_HIER_DEPTH_BUFFER */
928 struct intel_region *hiz_region = params->depth.mt->hiz_mt->region;
929 uint32_t hiz_offset =
930 intel_region_get_aligned_offset(hiz_region,
931 draw_x & ~tile_mask_x,
932 (draw_y & ~tile_mask_y) / 2, false);
935 OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2));
936 OUT_BATCH(hiz_region->pitch - 1);
937 OUT_RELOC(hiz_region->bo,
938 I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER,
943 /* 3DSTATE_STENCIL_BUFFER */
946 OUT_BATCH((_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2));
955 gen6_blorp_emit_depth_disable(struct brw_context *brw,
956 const brw_blorp_params *params)
958 struct intel_context *intel = &brw->intel;
961 OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (7 - 2));
962 OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) |
963 (BRW_SURFACE_NULL << 29));
973 /* 3DSTATE_CLEAR_PARAMS
975 * From the Sandybridge PRM, Volume 2, Part 1, Section 3DSTATE_CLEAR_PARAMS:
976 * [DevSNB] 3DSTATE_CLEAR_PARAMS packet must follow the DEPTH_BUFFER_STATE
977 * packet when HiZ is enabled and the DEPTH_BUFFER_STATE changes.
980 gen6_blorp_emit_clear_params(struct brw_context *brw,
981 const brw_blorp_params *params)
983 struct intel_context *intel = &brw->intel;
986 OUT_BATCH(_3DSTATE_CLEAR_PARAMS << 16 |
987 GEN5_DEPTH_CLEAR_VALID |
989 OUT_BATCH(params->depth.mt ? params->depth.mt->depth_clear_value : 0);
994 /* 3DSTATE_DRAWING_RECTANGLE */
996 gen6_blorp_emit_drawing_rectangle(struct brw_context *brw,
997 const brw_blorp_params *params)
999 struct intel_context *intel = &brw->intel;
1002 OUT_BATCH(_3DSTATE_DRAWING_RECTANGLE << 16 | (4 - 2));
1004 OUT_BATCH(((params->x1 - 1) & 0xffff) |
1005 ((params->y1 - 1) << 16));
1010 /* 3DSTATE_VIEWPORT_STATE_POINTERS */
1012 gen6_blorp_emit_viewport_state(struct brw_context *brw,
1013 const brw_blorp_params *params)
1015 struct intel_context *intel = &brw->intel;
1016 struct brw_cc_viewport *ccv;
1017 uint32_t cc_vp_offset;
1019 ccv = (struct brw_cc_viewport *)brw_state_batch(brw, AUB_TRACE_CC_VP_STATE,
1023 ccv->min_depth = 0.0;
1024 ccv->max_depth = 1.0;
1027 OUT_BATCH(_3DSTATE_VIEWPORT_STATE_POINTERS << 16 | (4 - 2) |
1028 GEN6_CC_VIEWPORT_MODIFY);
1029 OUT_BATCH(0); /* clip VP */
1030 OUT_BATCH(0); /* SF VP */
1031 OUT_BATCH(cc_vp_offset);
1038 gen6_blorp_emit_primitive(struct brw_context *brw,
1039 const brw_blorp_params *params)
1041 struct intel_context *intel = &brw->intel;
1044 OUT_BATCH(CMD_3D_PRIM << 16 | (6 - 2) |
1045 _3DPRIM_RECTLIST << GEN4_3DPRIM_TOPOLOGY_TYPE_SHIFT |
1046 GEN4_3DPRIM_VERTEXBUFFER_ACCESS_SEQUENTIAL);
1047 OUT_BATCH(3); /* vertex count per instance */
1049 OUT_BATCH(1); /* instance count */
1057 * \brief Execute a blit or render pass operation.
1059 * To execute the operation, this function manually constructs and emits a
1060 * batch to draw a rectangle primitive. The batchbuffer is flushed before
1061 * constructing and after emitting the batch.
1063 * This function alters no GL state.
1066 gen6_blorp_exec(struct intel_context *intel,
1067 const brw_blorp_params *params)
1069 struct gl_context *ctx = &intel->ctx;
1070 struct brw_context *brw = brw_context(ctx);
1071 brw_blorp_prog_data *prog_data = NULL;
1072 uint32_t cc_blend_state_offset = 0;
1073 uint32_t cc_state_offset = 0;
1074 uint32_t depthstencil_offset;
1075 uint32_t wm_push_const_offset = 0;
1076 uint32_t wm_bind_bo_offset = 0;
1078 uint32_t prog_offset = params->get_wm_prog(brw, &prog_data);
1079 gen6_blorp_emit_batch_head(brw, params);
1080 gen6_emit_3dstate_multisample(brw, params->num_samples);
1081 gen6_emit_3dstate_sample_mask(brw, params->num_samples, 1.0, false, ~0u);
1082 gen6_blorp_emit_state_base_address(brw, params);
1083 gen6_blorp_emit_vertices(brw, params);
1084 gen6_blorp_emit_urb_config(brw, params);
1085 if (params->use_wm_prog) {
1086 cc_blend_state_offset = gen6_blorp_emit_blend_state(brw, params);
1087 cc_state_offset = gen6_blorp_emit_cc_state(brw, params);
1089 depthstencil_offset = gen6_blorp_emit_depth_stencil_state(brw, params);
1090 gen6_blorp_emit_cc_state_pointers(brw, params, cc_blend_state_offset,
1091 depthstencil_offset, cc_state_offset);
1092 if (params->use_wm_prog) {
1093 uint32_t wm_surf_offset_renderbuffer;
1094 uint32_t wm_surf_offset_texture = 0;
1095 uint32_t sampler_offset;
1096 wm_push_const_offset = gen6_blorp_emit_wm_constants(brw, params);
1097 wm_surf_offset_renderbuffer =
1098 gen6_blorp_emit_surface_state(brw, params, ¶ms->dst,
1099 I915_GEM_DOMAIN_RENDER,
1100 I915_GEM_DOMAIN_RENDER);
1101 if (params->src.mt) {
1102 wm_surf_offset_texture =
1103 gen6_blorp_emit_surface_state(brw, params, ¶ms->src,
1104 I915_GEM_DOMAIN_SAMPLER, 0);
1107 gen6_blorp_emit_binding_table(brw, params,
1108 wm_surf_offset_renderbuffer,
1109 wm_surf_offset_texture);
1110 sampler_offset = gen6_blorp_emit_sampler_state(brw, params);
1111 gen6_blorp_emit_sampler_state_pointers(brw, params, sampler_offset);
1113 gen6_blorp_emit_vs_disable(brw, params);
1114 gen6_blorp_emit_gs_disable(brw, params);
1115 gen6_blorp_emit_clip_disable(brw, params);
1116 gen6_blorp_emit_sf_config(brw, params);
1117 if (params->use_wm_prog)
1118 gen6_blorp_emit_constant_ps(brw, params, wm_push_const_offset);
1120 gen6_blorp_emit_constant_ps_disable(brw, params);
1121 gen6_blorp_emit_wm_config(brw, params, prog_offset, prog_data);
1122 if (params->use_wm_prog)
1123 gen6_blorp_emit_binding_table_pointers(brw, params, wm_bind_bo_offset);
1124 gen6_blorp_emit_viewport_state(brw, params);
1126 if (params->depth.mt)
1127 gen6_blorp_emit_depth_stencil_config(brw, params);
1129 gen6_blorp_emit_depth_disable(brw, params);
1130 gen6_blorp_emit_clear_params(brw, params);
1131 gen6_blorp_emit_drawing_rectangle(brw, params);
1132 gen6_blorp_emit_primitive(brw, params);