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_VIEWPORT_H
29 #define ILO_STATE_VIEWPORT_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 * "... 16 sets of viewport (VP) state parameters in the Clip unit's
40 * VertexClipTest function and in the SF unit's ViewportMapping and
41 * Scissor functions."
42 */
43 #define ILO_STATE_VIEWPORT_MAX_COUNT 16
44
45 enum ilo_state_viewport_dirty_bits {
46 ILO_STATE_VIEWPORT_SF_CLIP_VIEWPORT = (1 << 0),
47 ILO_STATE_VIEWPORT_CC_VIEWPORT = (1 << 1),
48 ILO_STATE_VIEWPORT_SCISSOR_RECT = (1 << 2),
49 };
50
51 struct ilo_state_viewport_matrix_info {
52 float scale[3];
53 float translate[3];
54 };
55
56 struct ilo_state_viewport_scissor_info {
57 /* all inclusive */
58 uint16_t min_x;
59 uint16_t min_y;
60 uint16_t max_x;
61 uint16_t max_y;
62 };
63
64 struct ilo_state_viewport_params_info {
65 const struct ilo_state_viewport_matrix_info *matrices;
66 const struct ilo_state_viewport_scissor_info *scissors;
67 uint8_t count;
68 };
69
70 struct ilo_state_viewport_info {
71 void *data;
72 size_t data_size;
73
74 struct ilo_state_viewport_params_info params;
75 };
76
77 struct ilo_state_viewport {
78 void *data;
79 uint8_t array_size;
80
81 uint8_t count;
82 uint32_t (*sf_clip)[16];
83 uint32_t (*cc)[2];
84 uint32_t (*scissor)[2];
85 };
86
87 struct ilo_state_viewport_delta {
88 uint32_t dirty;
89 };
90
91 static inline size_t
ilo_state_viewport_data_size(const struct ilo_dev * dev,uint8_t array_size)92 ilo_state_viewport_data_size(const struct ilo_dev *dev, uint8_t array_size)
93 {
94 const struct ilo_state_viewport *vp = NULL;
95 return (sizeof(vp->sf_clip[0]) +
96 sizeof(vp->cc[0]) +
97 sizeof(vp->scissor[0])) * array_size;
98 }
99
100 bool
101 ilo_state_viewport_init(struct ilo_state_viewport *vp,
102 const struct ilo_dev *dev,
103 const struct ilo_state_viewport_info *info);
104
105 bool
106 ilo_state_viewport_init_data_only(struct ilo_state_viewport *vp,
107 const struct ilo_dev *dev,
108 void *data, size_t data_size);
109
110 bool
111 ilo_state_viewport_init_for_rectlist(struct ilo_state_viewport *vp,
112 const struct ilo_dev *dev,
113 void *data, size_t data_size);
114
115 bool
116 ilo_state_viewport_set_params(struct ilo_state_viewport *vp,
117 const struct ilo_dev *dev,
118 const struct ilo_state_viewport_params_info *params,
119 bool scissors_only);
120
121 void
122 ilo_state_viewport_full_delta(const struct ilo_state_viewport *vp,
123 const struct ilo_dev *dev,
124 struct ilo_state_viewport_delta *delta);
125
126 void
127 ilo_state_viewport_get_delta(const struct ilo_state_viewport *vp,
128 const struct ilo_dev *dev,
129 const struct ilo_state_viewport *old,
130 struct ilo_state_viewport_delta *delta);
131
132 #endif /* ILO_STATE_VIEWPORT_H */
133