- if (INTEL_DEBUG & DEBUG_SINGLE_THREAD)
- clip.thread4.max_threads = 0;
-
- if (INTEL_DEBUG & DEBUG_STATS)
- clip.thread4.stats_enable = 1;
-
- clip.clip5.userclip_enable_flags = 0x7f;
- clip.clip5.userclip_must_clip = 1;
- clip.clip5.guard_band_enable = 0;
- if (!key->depth_clamp)
- clip.clip5.viewport_z_clip_enable = 1;
- clip.clip5.viewport_xy_clip_enable = 1;
- clip.clip5.vertex_position_space = BRW_CLIP_NDCSPACE;
- clip.clip5.api_mode = BRW_CLIP_API_OGL;
- clip.clip5.clip_mode = key->clip_mode;
-
- if (BRW_IS_G4X(brw))
- clip.clip5.negative_w_clip_test = 1;
-
- clip.clip6.clipper_viewport_state_ptr = 0;
- clip.viewport_xmin = -1;
- clip.viewport_xmax = 1;
- clip.viewport_ymin = -1;
- clip.viewport_ymax = 1;
-
- bo = brw_upload_cache(&brw->cache, BRW_CLIP_UNIT,
- key, sizeof(*key),
- &brw->clip.prog_bo, 1,
- &clip, sizeof(clip),
- NULL, NULL);
-
- /* Emit clip program relocation */
- assert(brw->clip.prog_bo);
- dri_bo_emit_reloc(bo,
- I915_GEM_DOMAIN_INSTRUCTION,
- 0,
- clip.thread0.grf_reg_count << 1,
- offsetof(struct brw_clip_unit_state, thread0),
- brw->clip.prog_bo);
-
- return bo;
-}
-
-static void upload_clip_unit( struct brw_context *brw )
-{
- struct brw_clip_unit_key key;
-
- clip_unit_populate_key(brw, &key);
-
- dri_bo_unreference(brw->clip.state_bo);
- brw->clip.state_bo = brw_search_cache(&brw->cache, BRW_CLIP_UNIT,
- &key, sizeof(key),
- &brw->clip.prog_bo, 1,
- NULL);
- if (brw->clip.state_bo == NULL) {
- brw->clip.state_bo = clip_unit_create_from_key(brw, &key);
+ if (unlikely(INTEL_DEBUG & DEBUG_STATS))
+ clip->thread4.stats_enable = 1;
+
+ /* _NEW_TRANSFORM */
+ if (brw->gen == 5 || brw->is_g4x)
+ clip->clip5.userclip_enable_flags = ctx->Transform.ClipPlanesEnabled;
+ else
+ /* Up to 6 actual clip flags, plus the 7th for negative RHW workaround. */
+ clip->clip5.userclip_enable_flags = (ctx->Transform.ClipPlanesEnabled & 0x3f) | 0x40;
+
+ clip->clip5.userclip_must_clip = 1;
+
+ /* enable guardband clipping if we can */
+ if (ctx->ViewportArray[0].X == 0 &&
+ ctx->ViewportArray[0].Y == 0 &&
+ ctx->ViewportArray[0].Width == fb_width &&
+ ctx->ViewportArray[0].Height == fb_height)
+ {
+ clip->clip5.guard_band_enable = 1;
+ clip->clip6.clipper_viewport_state_ptr =
+ (brw->batch.bo->offset64 + brw->clip.vp_offset) >> 5;
+
+ /* emit clip viewport relocation */
+ drm_intel_bo_emit_reloc(brw->batch.bo,
+ (brw->clip.state_offset +
+ offsetof(struct brw_clip_unit_state, clip6)),
+ brw->batch.bo, brw->clip.vp_offset,
+ I915_GEM_DOMAIN_INSTRUCTION, 0);