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 intel_context
*intel
= &brw
->intel
;
43 struct gl_context
*ctx
= &intel
->ctx
;
45 intel_emit_depth_stall_flushes(brw
);
47 /* _NEW_DEPTH, _NEW_STENCIL, _NEW_BUFFERS */
49 OUT_BATCH(GEN7_3DSTATE_DEPTH_BUFFER
<< 16 | (7 - 2));
50 OUT_BATCH((depth_mt
? depth_mt
->region
->pitch
- 1 : 0) |
51 (depthbuffer_format
<< 18) |
52 ((hiz
? 1 : 0) << 22) |
53 ((stencil_mt
!= NULL
&& ctx
->Stencil
._WriteEnabled
) << 27) |
54 ((ctx
->Depth
.Mask
!= 0) << 28) |
55 (depth_surface_type
<< 29));
58 OUT_RELOC(depth_mt
->region
->bo
,
59 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
65 OUT_BATCH(((width
+ tile_x
- 1) << 4) |
66 ((height
+ tile_y
- 1) << 18));
68 OUT_BATCH(tile_x
| (tile_y
<< 16));
74 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
79 struct intel_mipmap_tree
*hiz_mt
= depth_mt
->hiz_mt
;
81 OUT_BATCH(GEN7_3DSTATE_HIER_DEPTH_BUFFER
<< 16 | (3 - 2));
82 OUT_BATCH(hiz_mt
->region
->pitch
- 1);
83 OUT_RELOC(hiz_mt
->region
->bo
,
84 I915_GEM_DOMAIN_RENDER
,
85 I915_GEM_DOMAIN_RENDER
,
86 brw
->depthstencil
.hiz_offset
);
90 if (stencil_mt
== NULL
) {
92 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
97 const int enabled
= intel
->is_haswell
? HSW_STENCIL_ENABLED
: 0;
100 OUT_BATCH(GEN7_3DSTATE_STENCIL_BUFFER
<< 16 | (3 - 2));
101 /* The stencil buffer has quirky pitch requirements. From the Graphics
102 * BSpec: vol2a.11 3D Pipeline Windower > Early Depth/Stencil Processing
103 * > Depth/Stencil Buffer State > 3DSTATE_STENCIL_BUFFER [DevIVB+],
104 * field "Surface Pitch":
106 * The pitch must be set to 2x the value computed based on width, as
107 * the stencil buffer is stored with two rows interleaved.
109 * (Note that it is not 100% clear whether this intended to apply to
110 * Gen7; the BSpec flags this comment as "DevILK,DevSNB" (which would
111 * imply that it doesn't), however the comment appears on a "DevIVB+"
112 * page (which would imply that it does). Experiments with the hardware
113 * indicate that it does.
116 (2 * stencil_mt
->region
->pitch
- 1));
117 OUT_RELOC(stencil_mt
->region
->bo
,
118 I915_GEM_DOMAIN_RENDER
, I915_GEM_DOMAIN_RENDER
,
119 brw
->depthstencil
.stencil_offset
);
124 OUT_BATCH(GEN7_3DSTATE_CLEAR_PARAMS
<< 16 | (3 - 2));
125 OUT_BATCH(depth_mt
? depth_mt
->depth_clear_value
: 0);
131 * \see brw_context.state.depth_region
133 const struct brw_tracked_state gen7_depthbuffer
= {
135 .mesa
= (_NEW_BUFFERS
| _NEW_DEPTH
| _NEW_STENCIL
),
136 .brw
= BRW_NEW_BATCH
,
139 .emit
= brw_emit_depthbuffer
,