2 * Mesa 3-D graphics library
4 * Copyright (C) 2013 LunarG, Inc.
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:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
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.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "intel_winsys.h"
30 #include "ilo_builder.h"
31 #include "ilo_render_gen.h"
32 #include "ilo_render_gen7.h"
33 #include "ilo_render.h"
36 struct sample_position
{
40 /* \see gen6_get_sample_position() */
41 static const struct sample_position sample_position_1x
[1] = {
45 static const struct sample_position sample_position_4x
[4] = {
46 { 6, 2 }, /* distance from the center is sqrt(40) */
47 { 14, 6 }, /* distance from the center is sqrt(40) */
48 { 2, 10 }, /* distance from the center is sqrt(40) */
49 { 10, 14 }, /* distance from the center is sqrt(40) */
52 static const struct sample_position sample_position_8x
[8] = {
53 { 7, 9 }, /* distance from the center is sqrt(2) */
54 { 9, 13 }, /* distance from the center is sqrt(26) */
55 { 11, 3 }, /* distance from the center is sqrt(34) */
56 { 13, 11 }, /* distance from the center is sqrt(34) */
57 { 1, 7 }, /* distance from the center is sqrt(50) */
58 { 5, 1 }, /* distance from the center is sqrt(58) */
59 { 15, 5 }, /* distance from the center is sqrt(58) */
60 { 3, 15 }, /* distance from the center is sqrt(74) */
63 struct ilo_3d_pipeline
*
64 ilo_3d_pipeline_create(struct ilo_builder
*builder
)
66 struct ilo_3d_pipeline
*p
;
69 p
= CALLOC_STRUCT(ilo_3d_pipeline
);
73 p
->dev
= builder
->dev
;
76 switch (ilo_dev_gen(p
->dev
)) {
78 ilo_3d_pipeline_init_gen6(p
);
82 ilo_3d_pipeline_init_gen7(p
);
85 assert(!"unsupported GEN");
91 p
->invalidate_flags
= ILO_3D_PIPELINE_INVALIDATE_ALL
;
93 p
->workaround_bo
= intel_winsys_alloc_buffer(builder
->winsys
,
94 "PIPE_CONTROL workaround", 4096, false);
95 if (!p
->workaround_bo
) {
96 ilo_warn("failed to allocate PIPE_CONTROL workaround bo\n");
101 p
->packed_sample_position_1x
=
102 sample_position_1x
[0].x
<< 4 |
103 sample_position_1x
[0].y
;
105 /* pack into dwords */
106 for (i
= 0; i
< 4; i
++) {
107 p
->packed_sample_position_4x
|=
108 sample_position_4x
[i
].x
<< (8 * i
+ 4) |
109 sample_position_4x
[i
].y
<< (8 * i
);
111 p
->packed_sample_position_8x
[0] |=
112 sample_position_8x
[i
].x
<< (8 * i
+ 4) |
113 sample_position_8x
[i
].y
<< (8 * i
);
115 p
->packed_sample_position_8x
[1] |=
116 sample_position_8x
[4 + i
].x
<< (8 * i
+ 4) |
117 sample_position_8x
[4 + i
].y
<< (8 * i
);
124 ilo_3d_pipeline_destroy(struct ilo_3d_pipeline
*p
)
126 if (p
->workaround_bo
)
127 intel_bo_unreference(p
->workaround_bo
);
133 ilo_3d_pipeline_get_sample_position(struct ilo_3d_pipeline
*p
,
134 unsigned sample_count
,
135 unsigned sample_index
,
138 const struct sample_position
*pos
;
140 switch (sample_count
) {
142 assert(sample_index
< Elements(sample_position_1x
));
143 pos
= sample_position_1x
;
146 assert(sample_index
< Elements(sample_position_4x
));
147 pos
= sample_position_4x
;
150 assert(sample_index
< Elements(sample_position_8x
));
151 pos
= sample_position_8x
;
154 assert(!"unknown sample count");
161 *x
= (float) pos
[sample_index
].x
/ 16.0f
;
162 *y
= (float) pos
[sample_index
].y
/ 16.0f
;