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
24 #include "intel_batchbuffer.h"
25 #include "intel_mipmap_tree.h"
26 #include "intel_regions.h"
27 #include "intel_fbo.h"
28 #include "brw_context.h"
29 #include "brw_state.h"
30 #include "brw_defines.h"
33 gen7_emit_depth_stencil_hiz(struct brw_context
*brw
,
34 struct intel_mipmap_tree
*depth_mt
,
35 uint32_t depth_offset
, uint32_t depthbuffer_format
,
36 uint32_t depth_surface_type
,
37 struct intel_mipmap_tree
*stencil_mt
,
38 bool hiz
, bool separate_stencil
,
39 uint32_t width
, uint32_t height
,
40 uint32_t tile_x
, uint32_t tile_y
)
42 struct gl_context
*ctx
= &brw
->ctx
;
44 intel_emit_depth_stall_flushes(brw
);
46 /* _NEW_DEPTH, _NEW_STENCIL, _NEW_BUFFERS */
48 OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
49 OUT_BATCH((depth_mt
? depth_mt
->region
->pitch
- 1 : 0) |
50 (depthbuffer_format
<< 18) |
51 ((hiz
? 1 : 0) << 22) |
52 ((stencil_mt
!= NULL
&& ctx
->Stencil
._WriteEnabled
) << 27) |
53 ((ctx
->Depth
.Mask
!= 0) << 28) |
54 (depth_surface_type
<< 29));
57 OUT_RELOC(depth_mt
->region
->bo
,
58 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
64 OUT_BATCH(((width
+ tile_x
- 1) << 4) |
65 ((height
+ tile_y
- 1) << 18));
67 OUT_BATCH(tile_x
| (tile_y
<< 16));
73 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
78 struct intel_mipmap_tree
*hiz_mt
= depth_mt
->hiz_mt
;
80 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
81 OUT_BATCH(hiz_mt
->region
->pitch
- 1);
82 OUT_RELOC(hiz_mt
->region
->bo
,
83 I915_GEM_DOMAIN_RENDER
,
84 I915_GEM_DOMAIN_RENDER
,
85 brw
->depthstencil
.hiz_offset
);
89 if (stencil_mt
== NULL
) {
91 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
96 const int enabled
= brw
->is_haswell
? HSW_STENCIL_ENABLED
: 0;
99 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
100 /* The stencil buffer has quirky pitch requirements. From the Graphics
101 * BSpec: vol2a.11 3D Pipeline Windower > Early Depth/Stencil Processing
102 * > Depth/Stencil Buffer State > 3DSTATE_STENCIL_BUFFER [DevIVB+],
103 * field "Surface Pitch":
105 * The pitch must be set to 2x the value computed based on width, as
106 * the stencil buffer is stored with two rows interleaved.
108 * (Note that it is not 100% clear whether this intended to apply to
109 * Gen7; the BSpec flags this comment as "DevILK,DevSNB" (which would
110 * imply that it doesn't), however the comment appears on a "DevIVB+"
111 * page (which would imply that it does). Experiments with the hardware
112 * indicate that it does.
115 (2 * stencil_mt
->region
->pitch
- 1));
116 OUT_RELOC(stencil_mt
->region
->bo
,
117 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
118 brw
->depthstencil
.stencil_offset
);
123 OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS
<< 16 | (3 - 2));
124 OUT_BATCH(depth_mt
? depth_mt
->depth_clear_value
: 0);
130 * \see brw_context.state.depth_region
132 const struct brw_tracked_state gen7_depthbuffer
= {
134 .mesa
= (_NEW_BUFFERS
| _NEW_DEPTH
| _NEW_STENCIL
),
135 .brw
= BRW_NEW_BATCH
,
138 .emit
= brw_emit_depthbuffer
,