1 /* 2 * Mesa 3-D graphics library 3 * 4 * Copyright (C) 2015 LunarG, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Chia-I Wu <olv@lunarg.com> 26 */ 27 28 #ifndef ILO_STATE_CC_H 29 #define ILO_STATE_CC_H 30 31 #include "genhw/genhw.h" 32 33 #include "ilo_core.h" 34 #include "ilo_dev.h" 35 36 /* 37 * From the Sandy Bridge PRM, volume 2 part 1, page 38: 38 * 39 * "Render Target Index. Specifies the render target index that will be 40 * used to select blend state from BLEND_STATE. 41 * Format = U3" 42 */ 43 #define ILO_STATE_CC_BLEND_MAX_RT_COUNT 8 44 45 enum ilo_state_cc_dirty_bits { 46 ILO_STATE_CC_3DSTATE_WM_DEPTH_STENCIL = (1 << 0), 47 ILO_STATE_CC_3DSTATE_PS_BLEND = (1 << 1), 48 ILO_STATE_CC_DEPTH_STENCIL_STATE = (1 << 2), 49 ILO_STATE_CC_BLEND_STATE = (1 << 3), 50 ILO_STATE_CC_COLOR_CALC_STATE = (1 << 4), 51 }; 52 53 /** 54 * AlphaCoverage and AlphaTest. 55 */ 56 struct ilo_state_cc_alpha_info { 57 bool cv_sample_count_one; 58 bool cv_float_source0_alpha; 59 60 bool alpha_to_coverage; 61 bool alpha_to_one; 62 63 bool test_enable; 64 enum gen_compare_function test_func; 65 }; 66 67 struct ilo_state_cc_stencil_op_info { 68 enum gen_compare_function test_func; 69 enum gen_stencil_op fail_op; 70 enum gen_stencil_op zfail_op; 71 enum gen_stencil_op zpass_op; 72 }; 73 74 /** 75 * StencilTest. 76 */ 77 struct ilo_state_cc_stencil_info { 78 bool cv_has_buffer; 79 80 bool test_enable; 81 bool twosided_enable; 82 83 struct ilo_state_cc_stencil_op_info front; 84 struct ilo_state_cc_stencil_op_info back; 85 }; 86 87 /** 88 * DepthTest. 89 */ 90 struct ilo_state_cc_depth_info { 91 bool cv_has_buffer; 92 93 bool test_enable; 94 /* independent from test_enable */ 95 bool write_enable; 96 97 enum gen_compare_function test_func; 98 }; 99 100 struct ilo_state_cc_blend_rt_info { 101 bool cv_has_buffer; 102 bool cv_is_unorm; 103 bool cv_is_integer; 104 105 uint8_t argb_write_disables; 106 107 bool logicop_enable; 108 enum gen_logic_op logicop_func; 109 110 bool blend_enable; 111 bool force_dst_alpha_one; 112 enum gen_blend_factor rgb_src; 113 enum gen_blend_factor rgb_dst; 114 enum gen_blend_function rgb_func; 115 enum gen_blend_factor a_src; 116 enum gen_blend_factor a_dst; 117 enum gen_blend_function a_func; 118 }; 119 120 /** 121 * ColorBufferBlending, Dithering, and LogicOps. 122 */ 123 struct ilo_state_cc_blend_info { 124 const struct ilo_state_cc_blend_rt_info *rt; 125 uint8_t rt_count; 126 127 bool dither_enable; 128 }; 129 130 struct ilo_state_cc_stencil_params_info { 131 uint8_t test_ref; 132 uint8_t test_mask; 133 uint8_t write_mask; 134 }; 135 136 /** 137 * CC parameters. 138 */ 139 struct ilo_state_cc_params_info { 140 float alpha_ref; 141 142 struct ilo_state_cc_stencil_params_info stencil_front; 143 struct ilo_state_cc_stencil_params_info stencil_back; 144 145 float blend_rgba[4]; 146 }; 147 148 /** 149 * Pixel processing. 150 */ 151 struct ilo_state_cc_info { 152 struct ilo_state_cc_alpha_info alpha; 153 struct ilo_state_cc_stencil_info stencil; 154 struct ilo_state_cc_depth_info depth; 155 struct ilo_state_cc_blend_info blend; 156 157 struct ilo_state_cc_params_info params; 158 }; 159 160 struct ilo_state_cc { 161 uint32_t ds[3]; 162 163 uint8_t blend_state_count; 164 uint32_t blend[1 + 1 + 2 * ILO_STATE_CC_BLEND_MAX_RT_COUNT]; 165 166 uint32_t cc[6]; 167 }; 168 169 struct ilo_state_cc_delta { 170 uint32_t dirty; 171 }; 172 173 bool 174 ilo_state_cc_init(struct ilo_state_cc *cc, 175 const struct ilo_dev *dev, 176 const struct ilo_state_cc_info *info); 177 178 bool 179 ilo_state_cc_set_info(struct ilo_state_cc *cc, 180 const struct ilo_dev *dev, 181 const struct ilo_state_cc_info *info); 182 183 bool 184 ilo_state_cc_set_params(struct ilo_state_cc *cc, 185 const struct ilo_dev *dev, 186 const struct ilo_state_cc_params_info *params); 187 188 void 189 ilo_state_cc_full_delta(const struct ilo_state_cc *cc, 190 const struct ilo_dev *dev, 191 struct ilo_state_cc_delta *delta); 192 193 void 194 ilo_state_cc_get_delta(const struct ilo_state_cc *cc, 195 const struct ilo_dev *dev, 196 const struct ilo_state_cc *old, 197 struct ilo_state_cc_delta *delta); 198 199 #endif /* ILO_STATE_CC_H */ 200