ilo: rename ilo_3d_pipeline*.[ch] to ilo_render*.[ch]
[mesa.git] / src / gallium / drivers / ilo / ilo_render.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 2013 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 #include "intel_winsys.h"
29
30 #include "ilo_builder.h"
31 #include "ilo_render_gen.h"
32 #include "ilo_render_gen7.h"
33 #include "ilo_render.h"
34
35 /* in U0.4 */
36 struct sample_position {
37 uint8_t x, y;
38 };
39
40 /* \see gen6_get_sample_position() */
41 static const struct sample_position sample_position_1x[1] = {
42 { 8, 8 },
43 };
44
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) */
50 };
51
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) */
61 };
62
63 struct ilo_3d_pipeline *
64 ilo_3d_pipeline_create(struct ilo_builder *builder)
65 {
66 struct ilo_3d_pipeline *p;
67 int i;
68
69 p = CALLOC_STRUCT(ilo_3d_pipeline);
70 if (!p)
71 return NULL;
72
73 p->dev = builder->dev;
74 p->builder = builder;
75
76 switch (ilo_dev_gen(p->dev)) {
77 case ILO_GEN(6):
78 ilo_3d_pipeline_init_gen6(p);
79 break;
80 case ILO_GEN(7):
81 case ILO_GEN(7.5):
82 ilo_3d_pipeline_init_gen7(p);
83 break;
84 default:
85 assert(!"unsupported GEN");
86 FREE(p);
87 return NULL;
88 break;
89 }
90
91 p->invalidate_flags = ILO_3D_PIPELINE_INVALIDATE_ALL;
92
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");
97 FREE(p);
98 return NULL;
99 }
100
101 p->packed_sample_position_1x =
102 sample_position_1x[0].x << 4 |
103 sample_position_1x[0].y;
104
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);
110
111 p->packed_sample_position_8x[0] |=
112 sample_position_8x[i].x << (8 * i + 4) |
113 sample_position_8x[i].y << (8 * i);
114
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);
118 }
119
120 return p;
121 }
122
123 void
124 ilo_3d_pipeline_destroy(struct ilo_3d_pipeline *p)
125 {
126 if (p->workaround_bo)
127 intel_bo_unreference(p->workaround_bo);
128
129 FREE(p);
130 }
131
132 void
133 ilo_3d_pipeline_get_sample_position(struct ilo_3d_pipeline *p,
134 unsigned sample_count,
135 unsigned sample_index,
136 float *x, float *y)
137 {
138 const struct sample_position *pos;
139
140 switch (sample_count) {
141 case 1:
142 assert(sample_index < Elements(sample_position_1x));
143 pos = sample_position_1x;
144 break;
145 case 4:
146 assert(sample_index < Elements(sample_position_4x));
147 pos = sample_position_4x;
148 break;
149 case 8:
150 assert(sample_index < Elements(sample_position_8x));
151 pos = sample_position_8x;
152 break;
153 default:
154 assert(!"unknown sample count");
155 *x = 0.5f;
156 *y = 0.5f;
157 return;
158 break;
159 }
160
161 *x = (float) pos[sample_index].x / 16.0f;
162 *y = (float) pos[sample_index].y / 16.0f;
163 }