blob: a4c5f2be2fef7e575ad2dfa3ccba0fd7f1e92738 [file] [log] [blame]
Chia-I Wua5714e82014-08-11 15:33:42 +08001/*
2 * XGL
3 *
4 * Copyright (C) 2014 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.
Chia-I Wu44e42362014-09-02 08:32:09 +080023 *
24 * Authors:
25 * Chia-I Wu <olv@lunarg.com>
Chia-I Wua5714e82014-08-11 15:33:42 +080026 */
27
Chia-I Wu97702a62014-08-11 15:33:42 +080028#include <math.h>
29#include "genhw/genhw.h"
Chia-I Wua5714e82014-08-11 15:33:42 +080030#include "dev.h"
31#include "state.h"
32
Chia-I Wu97702a62014-08-11 15:33:42 +080033static int translate_compare_func(XGL_COMPARE_FUNC func)
34{
35 switch (func) {
36 case XGL_COMPARE_NEVER: return GEN6_COMPAREFUNCTION_NEVER;
37 case XGL_COMPARE_LESS: return GEN6_COMPAREFUNCTION_LESS;
38 case XGL_COMPARE_EQUAL: return GEN6_COMPAREFUNCTION_EQUAL;
39 case XGL_COMPARE_LESS_EQUAL: return GEN6_COMPAREFUNCTION_LEQUAL;
40 case XGL_COMPARE_GREATER: return GEN6_COMPAREFUNCTION_GREATER;
41 case XGL_COMPARE_NOT_EQUAL: return GEN6_COMPAREFUNCTION_NOTEQUAL;
42 case XGL_COMPARE_GREATER_EQUAL: return GEN6_COMPAREFUNCTION_GEQUAL;
43 case XGL_COMPARE_ALWAYS: return GEN6_COMPAREFUNCTION_ALWAYS;
44 default:
45 assert(!"unknown compare_func");
46 return GEN6_COMPAREFUNCTION_NEVER;
47 }
48}
49
50static int translate_stencil_op(XGL_STENCIL_OP op)
51{
52 switch (op) {
53 case XGL_STENCIL_OP_KEEP: return GEN6_STENCILOP_KEEP;
54 case XGL_STENCIL_OP_ZERO: return GEN6_STENCILOP_ZERO;
55 case XGL_STENCIL_OP_REPLACE: return GEN6_STENCILOP_REPLACE;
56 case XGL_STENCIL_OP_INC_CLAMP: return GEN6_STENCILOP_INCRSAT;
57 case XGL_STENCIL_OP_DEC_CLAMP: return GEN6_STENCILOP_DECRSAT;
58 case XGL_STENCIL_OP_INVERT: return GEN6_STENCILOP_INVERT;
59 case XGL_STENCIL_OP_INC_WRAP: return GEN6_STENCILOP_INCR;
60 case XGL_STENCIL_OP_DEC_WRAP: return GEN6_STENCILOP_DECR;
61 default:
62 assert(!"unknown stencil op");
63 return GEN6_STENCILOP_KEEP;
64 }
65}
66
67static int translate_blend_func(XGL_BLEND_FUNC func)
68{
69 switch (func) {
70 case XGL_BLEND_FUNC_ADD: return GEN6_BLENDFUNCTION_ADD;
71 case XGL_BLEND_FUNC_SUBTRACT: return GEN6_BLENDFUNCTION_SUBTRACT;
72 case XGL_BLEND_FUNC_REVERSE_SUBTRACT: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT;
73 case XGL_BLEND_FUNC_MIN: return GEN6_BLENDFUNCTION_MIN;
74 case XGL_BLEND_FUNC_MAX: return GEN6_BLENDFUNCTION_MAX;
75 default:
76 assert(!"unknown blend func");
77 return GEN6_BLENDFUNCTION_ADD;
78 };
79}
80
81static int translate_blend(XGL_BLEND blend)
82{
83 switch (blend) {
84 case XGL_BLEND_ZERO: return GEN6_BLENDFACTOR_ZERO;
85 case XGL_BLEND_ONE: return GEN6_BLENDFACTOR_ONE;
86 case XGL_BLEND_SRC_COLOR: return GEN6_BLENDFACTOR_SRC_COLOR;
87 case XGL_BLEND_ONE_MINUS_SRC_COLOR: return GEN6_BLENDFACTOR_INV_SRC_COLOR;
88 case XGL_BLEND_DEST_COLOR: return GEN6_BLENDFACTOR_DST_COLOR;
89 case XGL_BLEND_ONE_MINUS_DEST_COLOR: return GEN6_BLENDFACTOR_INV_DST_COLOR;
90 case XGL_BLEND_SRC_ALPHA: return GEN6_BLENDFACTOR_SRC_ALPHA;
91 case XGL_BLEND_ONE_MINUS_SRC_ALPHA: return GEN6_BLENDFACTOR_INV_SRC_ALPHA;
92 case XGL_BLEND_DEST_ALPHA: return GEN6_BLENDFACTOR_DST_ALPHA;
93 case XGL_BLEND_ONE_MINUS_DEST_ALPHA: return GEN6_BLENDFACTOR_INV_DST_ALPHA;
94 case XGL_BLEND_CONSTANT_COLOR: return GEN6_BLENDFACTOR_CONST_COLOR;
95 case XGL_BLEND_ONE_MINUS_CONSTANT_COLOR: return GEN6_BLENDFACTOR_INV_CONST_COLOR;
96 case XGL_BLEND_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_CONST_ALPHA;
97 case XGL_BLEND_ONE_MINUS_CONSTANT_ALPHA: return GEN6_BLENDFACTOR_INV_CONST_ALPHA;
98 case XGL_BLEND_SRC_ALPHA_SATURATE: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE;
99 case XGL_BLEND_SRC1_COLOR: return GEN6_BLENDFACTOR_SRC1_COLOR;
100 case XGL_BLEND_ONE_MINUS_SRC1_COLOR: return GEN6_BLENDFACTOR_INV_SRC1_COLOR;
101 case XGL_BLEND_SRC1_ALPHA: return GEN6_BLENDFACTOR_SRC1_ALPHA;
102 case XGL_BLEND_ONE_MINUS_SRC1_ALPHA: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA;
103 default:
104 assert(!"unknown blend factor");
105 return GEN6_BLENDFACTOR_ONE;
106 };
107}
108
109static void
110raster_state_init(struct intel_raster_state *state,
111 const struct intel_gpu *gpu,
112 const XGL_RASTER_STATE_CREATE_INFO *info)
113{
114 switch (info->fillMode) {
115 case XFL_FILL_POINTS:
116 state->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_POINT |
117 GEN7_SF_DW1_BACKFACE_POINT;
118 break;
119 case XGL_FILL_WIREFRAME:
120 state->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_WIREFRAME |
121 GEN7_SF_DW1_BACKFACE_WIREFRAME;
122 break;
123 case XGL_FILL_SOLID:
124 default:
125 state->cmd_sf_fill |= GEN7_SF_DW1_FRONTFACE_SOLID |
126 GEN7_SF_DW1_BACKFACE_SOLID;
127 break;
128 }
129
130 if (info->frontFace == XGL_FRONT_FACE_CCW) {
131 state->cmd_sf_fill |= GEN7_SF_DW1_FRONTWINDING_CCW;
132 state->cmd_clip_cull |= GEN7_CLIP_DW1_FRONTWINDING_CCW;
133 }
134
135 switch (info->cullMode) {
136 case XGL_CULL_NONE:
137 default:
138 state->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_NONE;
139 state->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_NONE;
140 break;
141 case XGL_CULL_FRONT:
142 state->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_FRONT;
143 state->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_FRONT;
144 break;
145 case XGL_CULL_BACK:
146 state->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BACK;
147 state->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BACK;
148 break;
149 case XGL_CULL_FRONT_AND_BACK:
150 state->cmd_sf_cull |= GEN7_SF_DW2_CULLMODE_BOTH;
151 state->cmd_clip_cull |= GEN7_CLIP_DW1_CULLMODE_BOTH;
152 break;
153 }
154
155 /* only GEN7+ needs cull mode in 3DSTATE_CLIP */
156 if (intel_gpu_gen(gpu) == INTEL_GEN(6))
157 state->cmd_clip_cull = 0;
158
159 /* XXX scale info->depthBias back into NDC */
160 state->cmd_depth_offset_const = u_fui((float) info->depthBias * 2.0f);
161 state->cmd_depth_offset_clamp = u_fui(info->depthBiasClamp);
162 state->cmd_depth_offset_scale = u_fui(info->slopeScaledDepthBias);
163}
164
165static void
166viewport_get_guardband(const struct intel_gpu *gpu,
167 int center_x, int center_y,
168 int *min_gbx, int *max_gbx,
169 int *min_gby, int *max_gby)
170{
171 /*
172 * From the Sandy Bridge PRM, volume 2 part 1, page 234:
173 *
174 * "Per-Device Guardband Extents
175 *
176 * - Supported X,Y ScreenSpace "Guardband" Extent: [-16K,16K-1]
177 * - Maximum Post-Clamp Delta (X or Y): 16K"
178 *
179 * "In addition, in order to be correctly rendered, objects must have a
180 * screenspace bounding box not exceeding 8K in the X or Y direction.
181 * This additional restriction must also be comprehended by software,
182 * i.e., enforced by use of clipping."
183 *
184 * From the Ivy Bridge PRM, volume 2 part 1, page 248:
185 *
186 * "Per-Device Guardband Extents
187 *
188 * - Supported X,Y ScreenSpace "Guardband" Extent: [-32K,32K-1]
189 * - Maximum Post-Clamp Delta (X or Y): N/A"
190 *
191 * "In addition, in order to be correctly rendered, objects must have a
192 * screenspace bounding box not exceeding 8K in the X or Y direction.
193 * This additional restriction must also be comprehended by software,
194 * i.e., enforced by use of clipping."
195 *
196 * Combined, the bounding box of any object can not exceed 8K in both
197 * width and height.
198 *
199 * Below we set the guardband as a squre of length 8K, centered at where
200 * the viewport is. This makes sure all objects passing the GB test are
201 * valid to the renderer, and those failing the XY clipping have a
202 * better chance of passing the GB test.
203 */
204 const int max_extent = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 32768 : 16384;
205 const int half_len = 8192 / 2;
206
207 /* make sure the guardband is within the valid range */
208 if (center_x - half_len < -max_extent)
209 center_x = -max_extent + half_len;
210 else if (center_x + half_len > max_extent - 1)
211 center_x = max_extent - half_len;
212
213 if (center_y - half_len < -max_extent)
214 center_y = -max_extent + half_len;
215 else if (center_y + half_len > max_extent - 1)
216 center_y = max_extent - half_len;
217
218 *min_gbx = (float) (center_x - half_len);
219 *max_gbx = (float) (center_x + half_len);
220 *min_gby = (float) (center_y - half_len);
221 *max_gby = (float) (center_y + half_len);
222}
223
224static XGL_RESULT
Chia-I Wu7b566a42014-08-22 10:58:57 +0800225viewport_state_alloc_cmd(struct intel_viewport_state *state,
226 const struct intel_gpu *gpu,
227 const XGL_VIEWPORT_STATE_CREATE_INFO *info)
228{
229 INTEL_GPU_ASSERT(gpu, 6, 7.5);
230
Chia-I Wu7d841502014-08-30 14:29:15 +0800231 state->viewport_count = info->viewportCount;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800232 state->scissor_enable = info->scissorEnable;
233
234 if (intel_gpu_gen(gpu) >= INTEL_GEN(7)) {
Chia-I Wu7b566a42014-08-22 10:58:57 +0800235 state->cmd_len = 16 * info->viewportCount;
236
Chia-I Wub1d450a2014-09-09 13:48:03 +0800237 state->cmd_clip_pos = 8;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800238 } else {
Chia-I Wu7b566a42014-08-22 10:58:57 +0800239 state->cmd_len = 8 * info->viewportCount;
240
Chia-I Wub1d450a2014-09-09 13:48:03 +0800241 state->cmd_clip_pos = state->cmd_len;
242 state->cmd_len += 4 * info->viewportCount;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800243 }
244
Chia-I Wub1d450a2014-09-09 13:48:03 +0800245 state->cmd_cc_pos = state->cmd_len;
246 state->cmd_len += 2 * info->viewportCount;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800247
248 if (state->scissor_enable) {
Chia-I Wub1d450a2014-09-09 13:48:03 +0800249 state->cmd_scissor_rect_pos = state->cmd_len;
250 state->cmd_len += 2 * info->viewportCount;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800251 }
252
253 state->cmd = icd_alloc(sizeof(uint32_t) * state->cmd_len,
254 0, XGL_SYSTEM_ALLOC_INTERNAL);
255 if (!state->cmd)
256 return XGL_ERROR_OUT_OF_MEMORY;
257
258 return XGL_SUCCESS;
259}
260
261static XGL_RESULT
Chia-I Wu97702a62014-08-11 15:33:42 +0800262viewport_state_init(struct intel_viewport_state *state,
263 const struct intel_gpu *gpu,
264 const XGL_VIEWPORT_STATE_CREATE_INFO *info)
265{
266 const XGL_UINT sf_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 8;
267 const XGL_UINT clip_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 4;
268 uint32_t *sf_viewport, *clip_viewport, *cc_viewport, *scissor_rect;
269 XGL_UINT i;
Chia-I Wu7b566a42014-08-22 10:58:57 +0800270 XGL_RESULT ret;
Chia-I Wu97702a62014-08-11 15:33:42 +0800271
272 INTEL_GPU_ASSERT(gpu, 6, 7.5);
273
Chia-I Wu7b566a42014-08-22 10:58:57 +0800274 ret = viewport_state_alloc_cmd(state, gpu, info);
275 if (ret != XGL_SUCCESS)
276 return ret;
Chia-I Wu97702a62014-08-11 15:33:42 +0800277
278 sf_viewport = state->cmd;
Chia-I Wub1d450a2014-09-09 13:48:03 +0800279 clip_viewport = state->cmd + state->cmd_clip_pos;
280 cc_viewport = state->cmd + state->cmd_cc_pos;
281 scissor_rect = state->cmd + state->cmd_scissor_rect_pos;
Chia-I Wu97702a62014-08-11 15:33:42 +0800282
283 for (i = 0; i < info->viewportCount; i++) {
284 const XGL_VIEWPORT *viewport = &info->viewports[i];
285 const XGL_RECT *scissor = &info->scissors[i];
286 uint32_t *dw = NULL;
287 float translate[3], scale[3];
288 int min_gbx, max_gbx, min_gby, max_gby;
289
290 scale[0] = viewport->width / 2.0f;
291 scale[1] = viewport->height / 2.0f;
292 scale[2] = (viewport->maxDepth - viewport->minDepth) / 2.0;
293 translate[0] = viewport->originX + scale[0];
294 translate[1] = viewport->originY + scale[1];
295 translate[2] = (viewport->minDepth + viewport->maxDepth) / 2.0f;
296
297 viewport_get_guardband(gpu, (int) translate[0], (int) translate[1],
298 &min_gbx, &max_gbx, &min_gby, &max_gby);
299
300 /* SF_VIEWPORT */
301 dw = sf_viewport;
302 dw[0] = u_fui(scale[0]);
303 dw[1] = u_fui(scale[1]);
304 dw[2] = u_fui(scale[2]);
305 dw[3] = u_fui(translate[0]);
306 dw[4] = u_fui(translate[1]);
307 dw[5] = u_fui(translate[2]);
308 dw[6] = 0;
309 dw[7] = 0;
310 sf_viewport += sf_stride;
311
312 /* CLIP_VIEWPORT */
313 dw = clip_viewport;
Chia-I Wu3a702202014-08-30 18:23:55 +0800314 dw[0] = u_fui(((float) min_gbx - translate[0]) / fabsf(scale[0]));
315 dw[1] = u_fui(((float) max_gbx - translate[0]) / fabsf(scale[0]));
316 dw[2] = u_fui(((float) min_gby - translate[1]) / fabsf(scale[1]));
317 dw[3] = u_fui(((float) max_gby - translate[1]) / fabsf(scale[1]));
Chia-I Wu97702a62014-08-11 15:33:42 +0800318 clip_viewport += clip_stride;
319
320 /* CC_VIEWPORT */
321 dw = cc_viewport;
322 dw[0] = u_fui(viewport->minDepth);
323 dw[1] = u_fui(viewport->maxDepth);
324 cc_viewport += 2;
325
326 /* SCISSOR_RECT */
Chia-I Wu7b566a42014-08-22 10:58:57 +0800327 if (state->scissor_enable) {
328 int16_t max_x, max_y;
329
330 max_x = (scissor->offset.x + scissor->extent.width - 1) & 0xffff;
331 max_y = (scissor->offset.y + scissor->extent.height - 1) & 0xffff;
332
333 dw = scissor_rect;
334 if (scissor->extent.width && scissor->extent.height) {
335 dw[0] = (scissor->offset.y & 0xffff) << 16 |
336 (scissor->offset.x & 0xffff);
337 dw[1] = max_y << 16 | max_x;
338 } else {
339 dw[0] = 1 << 16 | 1;
340 dw[1] = 0;
341 }
342 scissor_rect += 2;
Chia-I Wu97702a62014-08-11 15:33:42 +0800343 }
Chia-I Wu97702a62014-08-11 15:33:42 +0800344 }
345
346 return XGL_SUCCESS;
347}
348
349static void
350msaa_state_init(struct intel_msaa_state *state,
351 const struct intel_gpu *gpu,
352 const XGL_MSAA_STATE_CREATE_INFO *info)
353{
354 /* taken from Mesa */
Chia-I Wu97702a62014-08-11 15:33:42 +0800355 static const uint32_t brw_multisample_positions_4x = 0xae2ae662;
356 static const uint32_t brw_multisample_positions_8x[] = { 0xdbb39d79, 0x3ff55117 };
357 uint32_t cmd, cmd_len;
358 uint32_t *dw = state->cmd;
359
360 INTEL_GPU_ASSERT(gpu, 6, 7.5);
361 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= 6);
362
Chia-I Wu0b171262014-08-29 15:03:28 +0800363 state->sample_count = info->samples;
364 if (!state->sample_count)
365 state->sample_count = 1;
366
Chia-I Wu97702a62014-08-11 15:33:42 +0800367 /* 3DSTATE_MULTISAMPLE */
Chia-I Wu426072d2014-08-26 14:31:55 +0800368 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_MULTISAMPLE);
Chia-I Wu97702a62014-08-11 15:33:42 +0800369 cmd_len = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 4 : 3;
370
371 dw[0] = cmd | (cmd_len - 2);
372 if (info->samples <= 1) {
373 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_1;
Chia-I Wu1586f6e2014-08-30 15:28:35 +0800374 dw[2] = 0;
Chia-I Wu97702a62014-08-11 15:33:42 +0800375 } else if (info->samples <= 4 || intel_gpu_gen(gpu) == INTEL_GEN(6)) {
376 dw[1] = GEN6_MULTISAMPLE_DW1_NUMSAMPLES_4;
377 dw[2] = brw_multisample_positions_4x;
378 } else {
379 dw[1] = GEN7_MULTISAMPLE_DW1_NUMSAMPLES_8;
380 dw[2] = brw_multisample_positions_8x[0];
381 dw[3] = brw_multisample_positions_8x[1];
382 }
383
384 dw += cmd_len;
385
Chia-I Wuf3c59252014-08-22 09:26:22 +0800386 state->cmd_len = cmd_len + 2;
387
Chia-I Wu97702a62014-08-11 15:33:42 +0800388 /* 3DSTATE_SAMPLE_MASK */
Chia-I Wu426072d2014-08-26 14:31:55 +0800389 cmd = GEN6_RENDER_CMD(3D, 3DSTATE_SAMPLE_MASK);
Chia-I Wu97702a62014-08-11 15:33:42 +0800390 cmd_len = 2;
391
392 dw[0] = cmd | (cmd_len - 2);
393 dw[1] = info->sampleMask & ((1 << info->samples) - 1);
394}
395
396static void
397blend_state_init(struct intel_blend_state *state,
398 const struct intel_gpu *gpu,
399 const XGL_COLOR_BLEND_STATE_CREATE_INFO *info)
400{
401 XGL_UINT i;
402
403 INTEL_GPU_ASSERT(gpu, 6, 7.5);
404
405 for (i = 0; i < ARRAY_SIZE(info->attachment); i++) {
406 const XGL_COLOR_ATTACHMENT_BLEND_STATE *att = &info->attachment[i];
407 uint32_t *dw = &state->cmd[2 * i];
408
409 if (att->blendEnable) {
410 dw[0] = 1 << 31 |
411 translate_blend_func(att->blendFuncAlpha) << 26 |
412 translate_blend(att->srcBlendAlpha) << 20 |
413 translate_blend(att->destBlendAlpha) << 15 |
414 translate_blend_func(att->blendFuncColor) << 11 |
415 translate_blend(att->srcBlendColor) << 5 |
416 translate_blend(att->destBlendColor);
417
418 if (att->blendFuncAlpha != att->blendFuncColor ||
419 att->srcBlendAlpha != att->srcBlendColor ||
420 att->destBlendAlpha != att->destBlendColor)
421 dw[0] |= 1 << 30;
422 }
423
424 dw[1] = GEN6_BLEND_DW1_COLORCLAMP_RTFORMAT |
425 0x3;
426 }
427
428 memcpy(state->cmd_blend_color, info->blendConst, sizeof(info->blendConst));
429}
430
431static XGL_RESULT
432ds_state_init(struct intel_ds_state *state,
433 const struct intel_gpu *gpu,
434 const XGL_DEPTH_STENCIL_STATE_CREATE_INFO *info)
435{
436 uint32_t *dw = state->cmd;
437
438 INTEL_GPU_ASSERT(gpu, 6, 7.5);
439
440 STATIC_ASSERT(ARRAY_SIZE(state->cmd) >= 3);
441
442 if (info->depthBoundsEnable)
443 return XGL_ERROR_UNKNOWN;
444
445 /*
446 * From the Sandy Bridge PRM, volume 2 part 1, page 359:
447 *
448 * "If the Depth Buffer is either undefined or does not have a surface
449 * format of D32_FLOAT_S8X24_UINT or D24_UNORM_S8_UINT and separate
450 * stencil buffer is disabled, Stencil Test Enable must be DISABLED"
451 *
452 * From the Sandy Bridge PRM, volume 2 part 1, page 370:
453 *
454 * "This field (Stencil Test Enable) cannot be enabled if
455 * Surface Format in 3DSTATE_DEPTH_BUFFER is set to D16_UNORM."
456 *
457 * TODO We do not check these yet.
458 */
459 if (info->stencilTestEnable) {
460 dw[0] = 1 << 31 |
461 translate_compare_func(info->front.stencilFunc) << 28 |
462 translate_stencil_op(info->front.stencilFailOp) << 25 |
463 translate_stencil_op(info->front.stencilDepthFailOp) << 22 |
464 translate_stencil_op(info->front.stencilPassOp) << 19 |
465 1 << 15 |
466 translate_compare_func(info->back.stencilFunc) << 12 |
467 translate_stencil_op(info->back.stencilFailOp) << 9 |
468 translate_stencil_op(info->back.stencilDepthFailOp) << 6 |
469 translate_stencil_op(info->back.stencilPassOp) << 3;
470
471 if (info->stencilWriteMask)
472 dw[0] |= 1 << 18;
473
474 dw[1] = (info->stencilReadMask & 0xff) << 24 |
475 (info->stencilWriteMask & 0xff) << 16;
476
477 state->cmd_stencil_ref = (info->front.stencilRef & 0xff) << 24 |
478 (info->back.stencilRef & 0xff) << 16;
479 }
480
481 /*
482 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
483 *
484 * "Enabling the Depth Test function without defining a Depth Buffer is
485 * UNDEFINED."
486 *
487 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
488 *
489 * "A Depth Buffer must be defined before enabling writes to it, or
490 * operation is UNDEFINED."
491 *
492 * TODO We do not check these yet.
493 */
494 if (info->depthTestEnable) {
495 dw[2] = 1 << 31 |
496 translate_compare_func(info->depthFunc) << 27 |
497 (bool) info->depthWriteEnable << 26;
498 } else {
499 dw[2] = GEN6_COMPAREFUNCTION_ALWAYS << 27;
500 }
501
502 return XGL_SUCCESS;
503}
504
Chia-I Wua5714e82014-08-11 15:33:42 +0800505static void viewport_state_destroy(struct intel_obj *obj)
506{
507 struct intel_viewport_state *state = intel_viewport_state_from_obj(obj);
508
509 intel_viewport_state_destroy(state);
510}
511
512XGL_RESULT intel_viewport_state_create(struct intel_dev *dev,
513 const XGL_VIEWPORT_STATE_CREATE_INFO *info,
514 struct intel_viewport_state **state_ret)
515{
516 struct intel_viewport_state *state;
Chia-I Wu97702a62014-08-11 15:33:42 +0800517 XGL_RESULT ret;
Chia-I Wua5714e82014-08-11 15:33:42 +0800518
519 state = (struct intel_viewport_state *) intel_base_create(dev,
520 sizeof(*state), dev->base.dbg, XGL_DBG_OBJECT_VIEWPORT_STATE,
521 info, 0);
522 if (!state)
523 return XGL_ERROR_OUT_OF_MEMORY;
524
525 state->obj.destroy = viewport_state_destroy;
526
Chia-I Wu97702a62014-08-11 15:33:42 +0800527 ret = viewport_state_init(state, dev->gpu, info);
528 if (ret != XGL_SUCCESS) {
529 intel_viewport_state_destroy(state);
530 return ret;
531 }
Chia-I Wua5714e82014-08-11 15:33:42 +0800532
533 *state_ret = state;
534
535 return XGL_SUCCESS;
536}
537
538void intel_viewport_state_destroy(struct intel_viewport_state *state)
539{
Chia-I Wu97702a62014-08-11 15:33:42 +0800540 icd_free(state->cmd);
Chia-I Wua5714e82014-08-11 15:33:42 +0800541 intel_base_destroy(&state->obj.base);
542}
543
544static void raster_state_destroy(struct intel_obj *obj)
545{
546 struct intel_raster_state *state = intel_raster_state_from_obj(obj);
547
548 intel_raster_state_destroy(state);
549}
550
551XGL_RESULT intel_raster_state_create(struct intel_dev *dev,
552 const XGL_RASTER_STATE_CREATE_INFO *info,
553 struct intel_raster_state **state_ret)
554{
555 struct intel_raster_state *state;
556
557 state = (struct intel_raster_state *) intel_base_create(dev,
558 sizeof(*state), dev->base.dbg, XGL_DBG_OBJECT_RASTER_STATE,
559 info, 0);
560 if (!state)
561 return XGL_ERROR_OUT_OF_MEMORY;
562
563 state->obj.destroy = raster_state_destroy;
564
Chia-I Wu97702a62014-08-11 15:33:42 +0800565 raster_state_init(state, dev->gpu, info);
Chia-I Wua5714e82014-08-11 15:33:42 +0800566
567 *state_ret = state;
568
569 return XGL_SUCCESS;
570}
571
572void intel_raster_state_destroy(struct intel_raster_state *state)
573{
574 intel_base_destroy(&state->obj.base);
575}
576
577static void msaa_state_destroy(struct intel_obj *obj)
578{
579 struct intel_msaa_state *state = intel_msaa_state_from_obj(obj);
580
581 intel_msaa_state_destroy(state);
582}
583
584XGL_RESULT intel_msaa_state_create(struct intel_dev *dev,
585 const XGL_MSAA_STATE_CREATE_INFO *info,
586 struct intel_msaa_state **state_ret)
587{
588 struct intel_msaa_state *state;
589
590 state = (struct intel_msaa_state *) intel_base_create(dev,
591 sizeof(*state), dev->base.dbg, XGL_DBG_OBJECT_MSAA_STATE,
592 info, 0);
593 if (!state)
594 return XGL_ERROR_OUT_OF_MEMORY;
595
596 state->obj.destroy = msaa_state_destroy;
597
Chia-I Wu97702a62014-08-11 15:33:42 +0800598 msaa_state_init(state, dev->gpu, info);
Chia-I Wua5714e82014-08-11 15:33:42 +0800599
600 *state_ret = state;
601
602 return XGL_SUCCESS;
603}
604
605void intel_msaa_state_destroy(struct intel_msaa_state *state)
606{
607 intel_base_destroy(&state->obj.base);
608}
609
610static void blend_state_destroy(struct intel_obj *obj)
611{
612 struct intel_blend_state *state = intel_blend_state_from_obj(obj);
613
614 intel_blend_state_destroy(state);
615}
616
617XGL_RESULT intel_blend_state_create(struct intel_dev *dev,
618 const XGL_COLOR_BLEND_STATE_CREATE_INFO *info,
619 struct intel_blend_state **state_ret)
620{
621 struct intel_blend_state *state;
622
623 state = (struct intel_blend_state *) intel_base_create(dev,
Courtney Goeltzenleuchter985ad492014-08-27 14:04:17 -0600624 sizeof(*state), dev->base.dbg, XGL_DBG_OBJECT_COLOR_BLEND_STATE,
Chia-I Wua5714e82014-08-11 15:33:42 +0800625 info, 0);
626 if (!state)
627 return XGL_ERROR_OUT_OF_MEMORY;
628
629 state->obj.destroy = blend_state_destroy;
630
Chia-I Wu97702a62014-08-11 15:33:42 +0800631 blend_state_init(state, dev->gpu, info);
Chia-I Wua5714e82014-08-11 15:33:42 +0800632
633 *state_ret = state;
634
635 return XGL_SUCCESS;
636}
637
638void intel_blend_state_destroy(struct intel_blend_state *state)
639{
640 intel_base_destroy(&state->obj.base);
641}
642
643static void ds_state_destroy(struct intel_obj *obj)
644{
645 struct intel_ds_state *state = intel_ds_state_from_obj(obj);
646
647 intel_ds_state_destroy(state);
648}
649
650XGL_RESULT intel_ds_state_create(struct intel_dev *dev,
651 const XGL_DEPTH_STENCIL_STATE_CREATE_INFO *info,
652 struct intel_ds_state **state_ret)
653{
654 struct intel_ds_state *state;
Chia-I Wu97702a62014-08-11 15:33:42 +0800655 XGL_RESULT ret;
Chia-I Wua5714e82014-08-11 15:33:42 +0800656
657 state = (struct intel_ds_state *) intel_base_create(dev,
Courtney Goeltzenleuchtere7dc05f2014-08-22 16:26:07 -0600658 sizeof(*state), dev->base.dbg, XGL_DBG_OBJECT_DEPTH_STENCIL_STATE,
Chia-I Wua5714e82014-08-11 15:33:42 +0800659 info, 0);
660 if (!state)
661 return XGL_ERROR_OUT_OF_MEMORY;
662
663 state->obj.destroy = ds_state_destroy;
664
Chia-I Wu97702a62014-08-11 15:33:42 +0800665 ret = ds_state_init(state, dev->gpu, info);
666 if (ret != XGL_SUCCESS) {
667 intel_ds_state_destroy(state);
668 return ret;
669 }
Chia-I Wua5714e82014-08-11 15:33:42 +0800670
671 *state_ret = state;
672
673 return XGL_SUCCESS;
674}
675
676void intel_ds_state_destroy(struct intel_ds_state *state)
677{
678 intel_base_destroy(&state->obj.base);
679}
680
681XGL_RESULT XGLAPI intelCreateViewportState(
682 XGL_DEVICE device,
683 const XGL_VIEWPORT_STATE_CREATE_INFO* pCreateInfo,
684 XGL_VIEWPORT_STATE_OBJECT* pState)
685{
686 struct intel_dev *dev = intel_dev(device);
687
688 return intel_viewport_state_create(dev, pCreateInfo,
689 (struct intel_viewport_state **) pState);
690}
691
692XGL_RESULT XGLAPI intelCreateRasterState(
693 XGL_DEVICE device,
694 const XGL_RASTER_STATE_CREATE_INFO* pCreateInfo,
695 XGL_RASTER_STATE_OBJECT* pState)
696{
697 struct intel_dev *dev = intel_dev(device);
698
699 return intel_raster_state_create(dev, pCreateInfo,
700 (struct intel_raster_state **) pState);
701}
702
703XGL_RESULT XGLAPI intelCreateMsaaState(
704 XGL_DEVICE device,
705 const XGL_MSAA_STATE_CREATE_INFO* pCreateInfo,
706 XGL_MSAA_STATE_OBJECT* pState)
707{
708 struct intel_dev *dev = intel_dev(device);
709
710 return intel_msaa_state_create(dev, pCreateInfo,
711 (struct intel_msaa_state **) pState);
712}
713
714XGL_RESULT XGLAPI intelCreateColorBlendState(
715 XGL_DEVICE device,
716 const XGL_COLOR_BLEND_STATE_CREATE_INFO* pCreateInfo,
717 XGL_COLOR_BLEND_STATE_OBJECT* pState)
718{
719 struct intel_dev *dev = intel_dev(device);
720
721 return intel_blend_state_create(dev, pCreateInfo,
722 (struct intel_blend_state **) pState);
723}
724
725XGL_RESULT XGLAPI intelCreateDepthStencilState(
726 XGL_DEVICE device,
727 const XGL_DEPTH_STENCIL_STATE_CREATE_INFO* pCreateInfo,
728 XGL_DEPTH_STENCIL_STATE_OBJECT* pState)
729{
730 struct intel_dev *dev = intel_dev(device);
731
732 return intel_ds_state_create(dev, pCreateInfo,
733 (struct intel_ds_state **) pState);
734}