2 * Copyright © 2012 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_fbo.h"
26 #include "brw_context.h"
27 #include "brw_defines.h"
28 #include "brw_state.h"
29 #include "main/stencil.h"
32 gen8_upload_wm_depth_stencil(struct brw_context
*brw
)
34 struct gl_context
*ctx
= &brw
->ctx
;
35 uint32_t dw1
= 0, dw2
= 0, dw3
= 0;
38 struct intel_renderbuffer
*depth_irb
=
39 intel_get_renderbuffer(ctx
->DrawBuffer
, BUFFER_DEPTH
);
41 struct gl_stencil_attrib
*stencil
= &ctx
->Stencil
;
43 /* _NEW_STENCIL | _NEW_BUFFERS */
44 if (stencil
->_Enabled
) {
45 #define FUNC intel_translate_compare_func
46 #define OP intel_translate_stencil_op
49 GEN8_WM_DS_STENCIL_TEST_ENABLE
|
50 FUNC(stencil
->Function
[0]) << GEN8_WM_DS_STENCIL_FUNC_SHIFT
|
51 OP(stencil
->FailFunc
[0]) << GEN8_WM_DS_STENCIL_FAIL_OP_SHIFT
|
52 OP(stencil
->ZFailFunc
[0]) << GEN8_WM_DS_Z_FAIL_OP_SHIFT
|
53 OP(stencil
->ZPassFunc
[0]) << GEN8_WM_DS_Z_PASS_OP_SHIFT
;
55 if (stencil
->_WriteEnabled
)
56 dw1
|= GEN8_WM_DS_STENCIL_BUFFER_WRITE_ENABLE
;
59 SET_FIELD(stencil
->WriteMask
[0] & 0xff, GEN8_WM_DS_STENCIL_WRITE_MASK
) |
60 SET_FIELD(stencil
->ValueMask
[0] & 0xff, GEN8_WM_DS_STENCIL_TEST_MASK
);
62 if (stencil
->_TestTwoSide
) {
63 const int b
= stencil
->_BackFace
;
66 GEN8_WM_DS_DOUBLE_SIDED_STENCIL_ENABLE
|
67 FUNC(stencil
->Function
[b
]) << GEN8_WM_DS_BF_STENCIL_FUNC_SHIFT
|
68 OP(stencil
->FailFunc
[b
]) << GEN8_WM_DS_BF_STENCIL_FAIL_OP_SHIFT
|
69 OP(stencil
->ZFailFunc
[b
]) << GEN8_WM_DS_BF_Z_FAIL_OP_SHIFT
|
70 OP(stencil
->ZPassFunc
[b
]) << GEN8_WM_DS_BF_Z_PASS_OP_SHIFT
;
72 dw2
|= SET_FIELD(stencil
->WriteMask
[b
] & 0xff,
73 GEN8_WM_DS_BF_STENCIL_WRITE_MASK
) |
74 SET_FIELD(stencil
->ValueMask
[b
] & 0xff,
75 GEN8_WM_DS_BF_STENCIL_TEST_MASK
);
79 int stencil_ref
= _mesa_get_stencil_ref(ctx
, 0);
80 int backface_ref
= _mesa_get_stencil_ref(ctx
, ctx
->Stencil
._BackFace
);
82 dw3
= SET_FIELD(stencil_ref
, GEN9_WM_DS_STENCIL_REF
) |
83 SET_FIELD(backface_ref
, GEN9_WM_DS_BF_STENCIL_REF
);
88 if (ctx
->Depth
.Test
&& depth_irb
) {
90 GEN8_WM_DS_DEPTH_TEST_ENABLE
|
91 FUNC(ctx
->Depth
.Func
) << GEN8_WM_DS_DEPTH_FUNC_SHIFT
;
94 dw1
|= GEN8_WM_DS_DEPTH_BUFFER_WRITE_ENABLE
;
97 int pkt_len
= brw
->gen
>= 9 ? 4 : 3;
100 OUT_BATCH(_3DSTATE_WM_DEPTH_STENCIL
<< 16 | (pkt_len
- 2));
109 const struct brw_tracked_state gen8_wm_depth_stencil
= {
111 .mesa
= _NEW_BUFFERS
|
114 .brw
= BRW_NEW_CONTEXT
,
116 .emit
= gen8_upload_wm_depth_stencil
,