ilo: add ilo_state_vertex_buffer
[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_INSTANCING = (1 << 2),
52 ILO_STATE_VF_3DSTATE_VERTEX_BUFFERS = (1 << 3),
53 ILO_STATE_VF_3DSTATE_VF = (1 << 4),
54 ILO_STATE_VF_3DSTATE_INDEX_BUFFER = (1 << 5),
55 };
56
57 /**
58 * Fetch a 128-bit vertex attribute.
59 */
60 struct ilo_state_vf_element_info {
61 uint8_t buffer;
62 uint16_t vertex_offset;
63 enum gen_surface_format format;
64
65 uint8_t format_size;
66 uint8_t component_count;
67 bool is_integer;
68
69 /* must be the same for those share the same buffer before Gen8 */
70 bool instancing_enable;
71 uint32_t instancing_step_rate;
72 };
73
74 /**
75 * VF parameters.
76 */
77 struct ilo_state_vf_params_info {
78 enum gen_3dprim_type cv_topology;
79
80 /* prepend an attribute of zeros */
81 bool prepend_zeros;
82
83 /* prepend an attribute of VertexID and/or InstanceID */
84 bool prepend_vertexid;
85 bool prepend_instanceid;
86
87 bool last_element_edge_flag;
88
89 enum gen_index_format cv_index_format;
90 bool cut_index_enable;
91 uint32_t cut_index;
92 };
93
94 /**
95 * Vertex fetch.
96 */
97 struct ilo_state_vf_info {
98 void *data;
99 size_t data_size;
100
101 const struct ilo_state_vf_element_info *elements;
102 uint8_t element_count;
103
104 struct ilo_state_vf_params_info params;
105 };
106
107 struct ilo_state_vf {
108 uint32_t (*user_ve)[2];
109 uint32_t (*user_instancing)[2];
110 int8_t vb_to_first_elem[ILO_STATE_VF_MAX_BUFFER_COUNT];
111 uint8_t user_ve_count;
112
113 bool edge_flag_supported;
114 uint32_t last_user_ve[2][2];
115
116 /* two VEs are reserved for internal use */
117 uint32_t internal_ve[2][2];
118 uint8_t internal_ve_count;
119
120 uint32_t sgvs[1];
121
122 uint32_t cut[2];
123 };
124
125 struct ilo_state_vf_delta {
126 uint32_t dirty;
127 };
128
129 struct ilo_buffer;
130
131 struct ilo_state_vertex_buffer_info {
132 const struct ilo_buffer *buf;
133 uint32_t offset;
134 uint32_t size;
135
136 uint16_t stride;
137
138 /* doubles must be at 64-bit aligned addresses */
139 bool cv_has_double;
140 uint8_t cv_double_vertex_offset_mod_8;
141 };
142
143 struct ilo_state_vertex_buffer {
144 uint32_t vb[3];
145
146 bool need_bo;
147
148 /* managed by users */
149 struct intel_bo *bo;
150 };
151
152 static inline size_t
153 ilo_state_vf_data_size(const struct ilo_dev *dev, uint8_t element_count)
154 {
155 const struct ilo_state_vf *vf = NULL;
156 return (sizeof(vf->user_ve[0]) +
157 sizeof(vf->user_instancing[0])) * element_count;
158 }
159
160 bool
161 ilo_state_vf_init(struct ilo_state_vf *vf,
162 const struct ilo_dev *dev,
163 const struct ilo_state_vf_info *info);
164
165 bool
166 ilo_state_vf_init_for_rectlist(struct ilo_state_vf *vf,
167 const struct ilo_dev *dev,
168 void *data, size_t data_size,
169 const struct ilo_state_vf_element_info *elements,
170 uint8_t element_count);
171
172 bool
173 ilo_state_vf_set_params(struct ilo_state_vf *vf,
174 const struct ilo_dev *dev,
175 const struct ilo_state_vf_params_info *params);
176
177 /**
178 * Return the number of attributes in the VUE.
179 */
180 static inline uint8_t
181 ilo_state_vf_get_attr_count(const struct ilo_state_vf *vf)
182 {
183 return vf->internal_ve_count + vf->user_ve_count;
184 }
185
186 void
187 ilo_state_vf_full_delta(const struct ilo_state_vf *vf,
188 const struct ilo_dev *dev,
189 struct ilo_state_vf_delta *delta);
190
191 void
192 ilo_state_vf_get_delta(const struct ilo_state_vf *vf,
193 const struct ilo_dev *dev,
194 const struct ilo_state_vf *old,
195 struct ilo_state_vf_delta *delta);
196
197 bool
198 ilo_state_vertex_buffer_set_info(struct ilo_state_vertex_buffer *vb,
199 const struct ilo_dev *dev,
200 const struct ilo_state_vertex_buffer_info *info);
201
202 #endif /* ILO_STATE_VF_H */