Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 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 Wu | 44e4236 | 2014-09-02 08:32:09 +0800 | [diff] [blame] | 23 | * |
| 24 | * Authors: |
| 25 | * Chia-I Wu <olv@lunarg.com> |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 28 | #include <math.h> |
| 29 | #include "genhw/genhw.h" |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 30 | #include "dev.h" |
| 31 | #include "state.h" |
| 32 | |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 33 | static void |
| 34 | viewport_get_guardband(const struct intel_gpu *gpu, |
| 35 | int center_x, int center_y, |
| 36 | int *min_gbx, int *max_gbx, |
| 37 | int *min_gby, int *max_gby) |
| 38 | { |
| 39 | /* |
| 40 | * From the Sandy Bridge PRM, volume 2 part 1, page 234: |
| 41 | * |
| 42 | * "Per-Device Guardband Extents |
| 43 | * |
| 44 | * - Supported X,Y ScreenSpace "Guardband" Extent: [-16K,16K-1] |
| 45 | * - Maximum Post-Clamp Delta (X or Y): 16K" |
| 46 | * |
| 47 | * "In addition, in order to be correctly rendered, objects must have a |
| 48 | * screenspace bounding box not exceeding 8K in the X or Y direction. |
| 49 | * This additional restriction must also be comprehended by software, |
| 50 | * i.e., enforced by use of clipping." |
| 51 | * |
| 52 | * From the Ivy Bridge PRM, volume 2 part 1, page 248: |
| 53 | * |
| 54 | * "Per-Device Guardband Extents |
| 55 | * |
| 56 | * - Supported X,Y ScreenSpace "Guardband" Extent: [-32K,32K-1] |
| 57 | * - Maximum Post-Clamp Delta (X or Y): N/A" |
| 58 | * |
| 59 | * "In addition, in order to be correctly rendered, objects must have a |
| 60 | * screenspace bounding box not exceeding 8K in the X or Y direction. |
| 61 | * This additional restriction must also be comprehended by software, |
| 62 | * i.e., enforced by use of clipping." |
| 63 | * |
| 64 | * Combined, the bounding box of any object can not exceed 8K in both |
| 65 | * width and height. |
| 66 | * |
| 67 | * Below we set the guardband as a squre of length 8K, centered at where |
| 68 | * the viewport is. This makes sure all objects passing the GB test are |
| 69 | * valid to the renderer, and those failing the XY clipping have a |
| 70 | * better chance of passing the GB test. |
| 71 | */ |
| 72 | const int max_extent = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 32768 : 16384; |
| 73 | const int half_len = 8192 / 2; |
| 74 | |
| 75 | /* make sure the guardband is within the valid range */ |
| 76 | if (center_x - half_len < -max_extent) |
| 77 | center_x = -max_extent + half_len; |
| 78 | else if (center_x + half_len > max_extent - 1) |
| 79 | center_x = max_extent - half_len; |
| 80 | |
| 81 | if (center_y - half_len < -max_extent) |
| 82 | center_y = -max_extent + half_len; |
| 83 | else if (center_y + half_len > max_extent - 1) |
| 84 | center_y = max_extent - half_len; |
| 85 | |
| 86 | *min_gbx = (float) (center_x - half_len); |
| 87 | *max_gbx = (float) (center_x + half_len); |
| 88 | *min_gby = (float) (center_y - half_len); |
| 89 | *max_gby = (float) (center_y + half_len); |
| 90 | } |
| 91 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 92 | static VkResult |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 93 | viewport_state_alloc_cmd(struct intel_dynamic_vp *state, |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 94 | const struct intel_gpu *gpu, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 95 | const VkDynamicVpStateCreateInfo *info) |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 96 | { |
| 97 | INTEL_GPU_ASSERT(gpu, 6, 7.5); |
| 98 | |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 99 | state->viewport_count = info->viewportAndScissorCount; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 100 | |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 101 | assert(info->viewportAndScissorCount < INTEL_MAX_RENDER_TARGETS); |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 102 | |
| 103 | if (intel_gpu_gen(gpu) >= INTEL_GEN(7)) { |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 104 | state->cmd_len = 16 * info->viewportAndScissorCount; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 105 | |
Chia-I Wu | b1d450a | 2014-09-09 13:48:03 +0800 | [diff] [blame] | 106 | state->cmd_clip_pos = 8; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 107 | } else { |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 108 | state->cmd_len = 8 * info->viewportAndScissorCount; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 109 | |
Chia-I Wu | b1d450a | 2014-09-09 13:48:03 +0800 | [diff] [blame] | 110 | state->cmd_clip_pos = state->cmd_len; |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 111 | state->cmd_len += 4 * info->viewportAndScissorCount; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 112 | } |
| 113 | |
Chia-I Wu | b1d450a | 2014-09-09 13:48:03 +0800 | [diff] [blame] | 114 | state->cmd_cc_pos = state->cmd_len; |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 115 | state->cmd_len += 2 * info->viewportAndScissorCount; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 116 | |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 117 | state->cmd_scissor_rect_pos = state->cmd_len; |
| 118 | state->cmd_len += 2 * info->viewportAndScissorCount; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 119 | |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 120 | state->cmd = intel_alloc(state, sizeof(uint32_t) * state->cmd_len, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 121 | 0, VK_SYSTEM_ALLOC_INTERNAL); |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 122 | if (!state->cmd) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 123 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 124 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 125 | return VK_SUCCESS; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 126 | } |
| 127 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 128 | static VkResult |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 129 | viewport_state_init(struct intel_dynamic_vp *state, |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 130 | const struct intel_gpu *gpu, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 131 | const VkDynamicVpStateCreateInfo *info) |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 132 | { |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 133 | const uint32_t sf_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 8; |
| 134 | const uint32_t clip_stride = (intel_gpu_gen(gpu) >= INTEL_GEN(7)) ? 16 : 4; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 135 | uint32_t *sf_viewport, *clip_viewport, *cc_viewport, *scissor_rect; |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 136 | uint32_t i; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 137 | VkResult ret; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 138 | |
| 139 | INTEL_GPU_ASSERT(gpu, 6, 7.5); |
| 140 | |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 141 | ret = viewport_state_alloc_cmd(state, gpu, info); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 142 | if (ret != VK_SUCCESS) |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 143 | return ret; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 144 | |
| 145 | sf_viewport = state->cmd; |
Chia-I Wu | b1d450a | 2014-09-09 13:48:03 +0800 | [diff] [blame] | 146 | clip_viewport = state->cmd + state->cmd_clip_pos; |
| 147 | cc_viewport = state->cmd + state->cmd_cc_pos; |
| 148 | scissor_rect = state->cmd + state->cmd_scissor_rect_pos; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 149 | |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 150 | for (i = 0; i < info->viewportAndScissorCount; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 151 | const VkViewport *viewport = &info->pViewports[i]; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 152 | uint32_t *dw = NULL; |
| 153 | float translate[3], scale[3]; |
| 154 | int min_gbx, max_gbx, min_gby, max_gby; |
| 155 | |
| 156 | scale[0] = viewport->width / 2.0f; |
| 157 | scale[1] = viewport->height / 2.0f; |
| 158 | scale[2] = (viewport->maxDepth - viewport->minDepth) / 2.0; |
| 159 | translate[0] = viewport->originX + scale[0]; |
| 160 | translate[1] = viewport->originY + scale[1]; |
| 161 | translate[2] = (viewport->minDepth + viewport->maxDepth) / 2.0f; |
| 162 | |
| 163 | viewport_get_guardband(gpu, (int) translate[0], (int) translate[1], |
| 164 | &min_gbx, &max_gbx, &min_gby, &max_gby); |
| 165 | |
| 166 | /* SF_VIEWPORT */ |
| 167 | dw = sf_viewport; |
| 168 | dw[0] = u_fui(scale[0]); |
| 169 | dw[1] = u_fui(scale[1]); |
| 170 | dw[2] = u_fui(scale[2]); |
| 171 | dw[3] = u_fui(translate[0]); |
| 172 | dw[4] = u_fui(translate[1]); |
| 173 | dw[5] = u_fui(translate[2]); |
| 174 | dw[6] = 0; |
| 175 | dw[7] = 0; |
| 176 | sf_viewport += sf_stride; |
| 177 | |
| 178 | /* CLIP_VIEWPORT */ |
| 179 | dw = clip_viewport; |
Chia-I Wu | 3a70220 | 2014-08-30 18:23:55 +0800 | [diff] [blame] | 180 | dw[0] = u_fui(((float) min_gbx - translate[0]) / fabsf(scale[0])); |
| 181 | dw[1] = u_fui(((float) max_gbx - translate[0]) / fabsf(scale[0])); |
| 182 | dw[2] = u_fui(((float) min_gby - translate[1]) / fabsf(scale[1])); |
| 183 | dw[3] = u_fui(((float) max_gby - translate[1]) / fabsf(scale[1])); |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 184 | clip_viewport += clip_stride; |
| 185 | |
| 186 | /* CC_VIEWPORT */ |
| 187 | dw = cc_viewport; |
| 188 | dw[0] = u_fui(viewport->minDepth); |
| 189 | dw[1] = u_fui(viewport->maxDepth); |
| 190 | cc_viewport += 2; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 191 | } |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 192 | |
Courtney Goeltzenleuchter | c6e32f9 | 2015-02-11 14:13:34 -0700 | [diff] [blame] | 193 | for (i = 0; i < info->viewportAndScissorCount; i++) { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 194 | const VkRect *scissor = &info->pScissors[i]; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 195 | /* SCISSOR_RECT */ |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 196 | int16_t max_x, max_y; |
| 197 | uint32_t *dw = NULL; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 198 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 199 | max_x = (scissor->offset.x + scissor->extent.width - 1) & 0xffff; |
| 200 | max_y = (scissor->offset.y + scissor->extent.height - 1) & 0xffff; |
Chia-I Wu | 7b566a4 | 2014-08-22 10:58:57 +0800 | [diff] [blame] | 201 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 202 | dw = scissor_rect; |
| 203 | if (scissor->extent.width && scissor->extent.height) { |
| 204 | dw[0] = (scissor->offset.y & 0xffff) << 16 | |
| 205 | (scissor->offset.x & 0xffff); |
| 206 | dw[1] = max_y << 16 | max_x; |
| 207 | } else { |
| 208 | dw[0] = 1 << 16 | 1; |
| 209 | dw[1] = 0; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 210 | } |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 211 | scissor_rect += 2; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 212 | } |
| 213 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 214 | return VK_SUCCESS; |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 215 | } |
| 216 | |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 217 | static void viewport_state_destroy(struct intel_obj *obj) |
| 218 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 219 | struct intel_dynamic_vp *state = intel_viewport_state_from_obj(obj); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 220 | |
| 221 | intel_viewport_state_destroy(state); |
| 222 | } |
| 223 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 224 | VkResult intel_viewport_state_create(struct intel_dev *dev, |
| 225 | const VkDynamicVpStateCreateInfo *info, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 226 | struct intel_dynamic_vp **state_ret) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 227 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 228 | struct intel_dynamic_vp *state; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 229 | VkResult ret; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 230 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 231 | state = (struct intel_dynamic_vp *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 232 | sizeof(*state), dev->base.dbg, VK_DBG_OBJECT_VIEWPORT_STATE, |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 233 | info, 0); |
| 234 | if (!state) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 235 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 236 | |
| 237 | state->obj.destroy = viewport_state_destroy; |
| 238 | |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 239 | ret = viewport_state_init(state, dev->gpu, info); |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 240 | if (ret != VK_SUCCESS) { |
Chia-I Wu | 97702a6 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 241 | intel_viewport_state_destroy(state); |
| 242 | return ret; |
| 243 | } |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 244 | |
| 245 | *state_ret = state; |
| 246 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 247 | return VK_SUCCESS; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 248 | } |
| 249 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 250 | void intel_viewport_state_destroy(struct intel_dynamic_vp *state) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 251 | { |
Chia-I Wu | f9c81ef | 2015-02-22 13:49:15 +0800 | [diff] [blame] | 252 | intel_free(state, state->cmd); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 253 | intel_base_destroy(&state->obj.base); |
| 254 | } |
| 255 | |
| 256 | static void raster_state_destroy(struct intel_obj *obj) |
| 257 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 258 | struct intel_dynamic_rs *state = intel_raster_state_from_obj(obj); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 259 | |
| 260 | intel_raster_state_destroy(state); |
| 261 | } |
| 262 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 263 | VkResult intel_raster_state_create(struct intel_dev *dev, |
| 264 | const VkDynamicRsStateCreateInfo *info, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 265 | struct intel_dynamic_rs **state_ret) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 266 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 267 | struct intel_dynamic_rs *state; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 268 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 269 | state = (struct intel_dynamic_rs *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 270 | sizeof(*state), dev->base.dbg, VK_DBG_OBJECT_RASTER_STATE, |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 271 | info, 0); |
| 272 | if (!state) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 273 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 274 | |
| 275 | state->obj.destroy = raster_state_destroy; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 276 | state->rs_info = *info; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 277 | |
| 278 | *state_ret = state; |
| 279 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 280 | return VK_SUCCESS; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 281 | } |
| 282 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 283 | void intel_raster_state_destroy(struct intel_dynamic_rs *state) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 284 | { |
| 285 | intel_base_destroy(&state->obj.base); |
| 286 | } |
| 287 | |
| 288 | static void blend_state_destroy(struct intel_obj *obj) |
| 289 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 290 | struct intel_dynamic_cb *state = intel_blend_state_from_obj(obj); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 291 | |
| 292 | intel_blend_state_destroy(state); |
| 293 | } |
| 294 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 295 | VkResult intel_blend_state_create(struct intel_dev *dev, |
| 296 | const VkDynamicCbStateCreateInfo *info, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 297 | struct intel_dynamic_cb **state_ret) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 298 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 299 | struct intel_dynamic_cb *state; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 300 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 301 | state = (struct intel_dynamic_cb *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 302 | sizeof(*state), dev->base.dbg, VK_DBG_OBJECT_COLOR_BLEND_STATE, |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 303 | info, 0); |
| 304 | if (!state) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 305 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 306 | |
| 307 | state->obj.destroy = blend_state_destroy; |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 308 | state->cb_info = *info; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 309 | |
| 310 | *state_ret = state; |
| 311 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 312 | return VK_SUCCESS; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 313 | } |
| 314 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 315 | void intel_blend_state_destroy(struct intel_dynamic_cb *state) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 316 | { |
| 317 | intel_base_destroy(&state->obj.base); |
| 318 | } |
| 319 | |
| 320 | static void ds_state_destroy(struct intel_obj *obj) |
| 321 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 322 | struct intel_dynamic_ds *state = intel_ds_state_from_obj(obj); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 323 | |
| 324 | intel_ds_state_destroy(state); |
| 325 | } |
| 326 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 327 | VkResult intel_ds_state_create(struct intel_dev *dev, |
| 328 | const VkDynamicDsStateCreateInfo *info, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 329 | struct intel_dynamic_ds **state_ret) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 330 | { |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 331 | struct intel_dynamic_ds *state; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 332 | |
Chia-I Wu | 545c2e1 | 2015-02-22 13:19:54 +0800 | [diff] [blame] | 333 | state = (struct intel_dynamic_ds *) intel_base_create(&dev->base.handle, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 334 | sizeof(*state), dev->base.dbg, VK_DBG_OBJECT_DEPTH_STENCIL_STATE, |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 335 | info, 0); |
| 336 | if (!state) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 337 | return VK_ERROR_OUT_OF_MEMORY; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 338 | |
| 339 | state->obj.destroy = ds_state_destroy; |
| 340 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 341 | /* |
| 342 | * From the Sandy Bridge PRM, volume 2 part 1, page 359: |
| 343 | * |
| 344 | * "If the Depth Buffer is either undefined or does not have a surface |
| 345 | * format of D32_FLOAT_S8X24_UINT or D24_UNORM_S8_UINT and separate |
| 346 | * stencil buffer is disabled, Stencil Test Enable must be DISABLED" |
| 347 | * |
| 348 | * From the Sandy Bridge PRM, volume 2 part 1, page 370: |
| 349 | * |
| 350 | * "This field (Stencil Test Enable) cannot be enabled if |
| 351 | * Surface Format in 3DSTATE_DEPTH_BUFFER is set to D16_UNORM." |
| 352 | * |
| 353 | * TODO We do not check these yet. |
| 354 | */ |
| 355 | |
| 356 | state->ds_info = *info; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 357 | |
| 358 | *state_ret = state; |
| 359 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 360 | return VK_SUCCESS; |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 361 | } |
| 362 | |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 363 | void intel_ds_state_destroy(struct intel_dynamic_ds *state) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 364 | { |
| 365 | intel_base_destroy(&state->obj.base); |
| 366 | } |
| 367 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 368 | ICD_EXPORT VkResult VKAPI vkCreateDynamicViewportState( |
| 369 | VkDevice device, |
| 370 | const VkDynamicVpStateCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fcf855f | 2015-04-10 16:24:50 -0600 | [diff] [blame] | 371 | VkDynamicVpState* pState) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 372 | { |
| 373 | struct intel_dev *dev = intel_dev(device); |
| 374 | |
| 375 | return intel_viewport_state_create(dev, pCreateInfo, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 376 | (struct intel_dynamic_vp **) pState); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 377 | } |
| 378 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 379 | ICD_EXPORT VkResult VKAPI vkCreateDynamicRasterState( |
| 380 | VkDevice device, |
| 381 | const VkDynamicRsStateCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fcf855f | 2015-04-10 16:24:50 -0600 | [diff] [blame] | 382 | VkDynamicRsState* pState) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 383 | { |
| 384 | struct intel_dev *dev = intel_dev(device); |
| 385 | |
| 386 | return intel_raster_state_create(dev, pCreateInfo, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 387 | (struct intel_dynamic_rs **) pState); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 388 | } |
| 389 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 390 | ICD_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState( |
| 391 | VkDevice device, |
| 392 | const VkDynamicCbStateCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fcf855f | 2015-04-10 16:24:50 -0600 | [diff] [blame] | 393 | VkDynamicCbState* pState) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 394 | { |
| 395 | struct intel_dev *dev = intel_dev(device); |
| 396 | |
| 397 | return intel_blend_state_create(dev, pCreateInfo, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 398 | (struct intel_dynamic_cb **) pState); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 399 | } |
| 400 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 401 | ICD_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState( |
| 402 | VkDevice device, |
| 403 | const VkDynamicDsStateCreateInfo* pCreateInfo, |
Courtney Goeltzenleuchter | fcf855f | 2015-04-10 16:24:50 -0600 | [diff] [blame] | 404 | VkDynamicDsState* pState) |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 405 | { |
| 406 | struct intel_dev *dev = intel_dev(device); |
| 407 | |
| 408 | return intel_ds_state_create(dev, pCreateInfo, |
Tony Barbour | fa6cac7 | 2015-01-16 14:27:35 -0700 | [diff] [blame] | 409 | (struct intel_dynamic_ds **) pState); |
Chia-I Wu | a5714e8 | 2014-08-11 15:33:42 +0800 | [diff] [blame] | 410 | } |