ilo: add 3DSTATE_VF to ilo_state_vf
[mesa.git] / src / gallium / drivers / ilo / core / ilo_state_vf.h
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_VF_H
29 #define ILO_STATE_VF_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 93:
38 *
39 * "Up to 34 (DevSNB+) vertex elements are supported."
40 *
41 * "Up to 33 VBs are supported"
42 *
43 * Reserve two VEs and one VB for internal use.
44 */
45 #define ILO_STATE_VF_MAX_ELEMENT_COUNT (34 - 2)
46 #define ILO_STATE_VF_MAX_BUFFER_COUNT (33 - 1)
47
48 enum ilo_state_vf_dirty_bits {
49 ILO_STATE_VF_3DSTATE_VERTEX_ELEMENTS = (1 << 0),
50 ILO_STATE_VF_3DSTATE_VF_SGVS = (1 << 1),
51 ILO_STATE_VF_3DSTATE_VF = (1 << 2),
52 ILO_STATE_VF_3DSTATE_INDEX_BUFFER = (1 << 3),
53 };
54
55 /**
56 * Fetch a 128-bit vertex attribute.
57 */
58 struct ilo_state_vf_element_info {
59 uint8_t buffer;
60 uint16_t vertex_offset;
61 enum gen_surface_format format;
62
63 uint8_t format_size;
64 uint8_t component_count;
65 bool is_integer;
66 bool is_double;
67 };
68
69 /**
70 * VF parameters.
71 */
72 struct ilo_state_vf_params_info {
73 enum gen_3dprim_type cv_topology;
74
75 /* prepend an attribute of zeros */
76 bool prepend_zeros;
77
78 /* prepend an attribute of VertexID and/or InstanceID */
79 bool prepend_vertexid;
80 bool prepend_instanceid;
81
82 bool last_element_edge_flag;
83
84 enum gen_index_format cv_index_format;
85 bool cut_index_enable;
86 uint32_t cut_index;
87 };
88
89 /**
90 * Vertex fetch.
91 */
92 struct ilo_state_vf_info {
93 void *data;
94 size_t data_size;
95
96 const struct ilo_state_vf_element_info *elements;
97 uint8_t element_count;
98
99 struct ilo_state_vf_params_info params;
100 };
101
102 struct ilo_state_vf {
103 /* two VEs are reserved for internal use */
104 uint32_t internal_ve[2][2];
105 uint32_t (*user_ve)[2];
106 uint8_t internal_ve_count;
107 uint8_t user_ve_count;
108
109 uint32_t sgvs[1];
110
111 uint32_t last_user_ve[2][2];
112 bool edge_flag_supported;
113
114 uint32_t cut[2];
115 };
116
117 struct ilo_state_vf_delta {
118 uint32_t dirty;
119 };
120
121 static inline size_t
122 ilo_state_vf_data_size(const struct ilo_dev *dev, uint8_t element_count)
123 {
124 const struct ilo_state_vf *vf = NULL;
125 return sizeof(vf->user_ve[0]) * element_count;
126 }
127
128 bool
129 ilo_state_vf_init(struct ilo_state_vf *vf,
130 const struct ilo_dev *dev,
131 const struct ilo_state_vf_info *info);
132
133 bool
134 ilo_state_vf_init_for_rectlist(struct ilo_state_vf *vf,
135 const struct ilo_dev *dev,
136 void *data, size_t data_size,
137 const struct ilo_state_vf_element_info *elements,
138 uint8_t element_count);
139
140 bool
141 ilo_state_vf_set_params(struct ilo_state_vf *vf,
142 const struct ilo_dev *dev,
143 const struct ilo_state_vf_params_info *params);
144
145 /**
146 * Return the number of attributes in the VUE.
147 */
148 static inline uint8_t
149 ilo_state_vf_get_attr_count(const struct ilo_state_vf *vf)
150 {
151 return vf->internal_ve_count + vf->user_ve_count;
152 }
153
154 void
155 ilo_state_vf_full_delta(const struct ilo_state_vf *vf,
156 const struct ilo_dev *dev,
157 struct ilo_state_vf_delta *delta);
158
159 void
160 ilo_state_vf_get_delta(const struct ilo_state_vf *vf,
161 const struct ilo_dev *dev,
162 const struct ilo_state_vf *old,
163 struct ilo_state_vf_delta *delta);
164
165 #endif /* ILO_STATE_VF_H */