Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 2 | * Vulkan |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +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 | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include "genhw/genhw.h" |
| 29 | #include "img.h" |
Chia-I Wu | 714df45 | 2015-01-01 07:55:04 +0800 | [diff] [blame] | 30 | #include "buf.h" |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 31 | #include "cmd_priv.h" |
| 32 | |
| 33 | enum { |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 34 | READ_OP = 1 << 0, |
| 35 | WRITE_OP = 1 << 1, |
| 36 | HIZ_OP = 1 << 2, |
| 37 | }; |
| 38 | |
| 39 | enum { |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 40 | MEM_CACHE = 1 << 0, |
| 41 | DATA_READ_CACHE = 1 << 1, |
| 42 | DATA_WRITE_CACHE = 1 << 2, |
| 43 | RENDER_CACHE = 1 << 3, |
| 44 | SAMPLER_CACHE = 1 << 4, |
| 45 | }; |
| 46 | |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 47 | static uint32_t img_get_layout_ops(const struct intel_img *img, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 48 | VK_IMAGE_LAYOUT layout) |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 49 | { |
| 50 | uint32_t ops; |
| 51 | |
| 52 | switch (layout) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 53 | case VK_IMAGE_LAYOUT_GENERAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 54 | ops = READ_OP | WRITE_OP; |
| 55 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 56 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 57 | ops = READ_OP | WRITE_OP; |
| 58 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 59 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 60 | ops = READ_OP | WRITE_OP | HIZ_OP; |
| 61 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 62 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 63 | ops = READ_OP | HIZ_OP; |
| 64 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 65 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 66 | ops = READ_OP; |
| 67 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 68 | case VK_IMAGE_LAYOUT_CLEAR_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 69 | ops = WRITE_OP | HIZ_OP; |
| 70 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 71 | case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 72 | ops = READ_OP; |
| 73 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 74 | case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 75 | ops = WRITE_OP; |
| 76 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 77 | case VK_IMAGE_LAYOUT_UNDEFINED: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 78 | default: |
| 79 | ops = 0; |
| 80 | break; |
| 81 | } |
| 82 | |
| 83 | return ops; |
| 84 | } |
| 85 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 86 | static uint32_t img_get_layout_caches(const struct intel_img *img, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 87 | VK_IMAGE_LAYOUT layout) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 88 | { |
| 89 | uint32_t caches; |
| 90 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 91 | switch (layout) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 92 | case VK_IMAGE_LAYOUT_GENERAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 93 | // General layout when image can be used for any kind of access |
| 94 | caches = MEM_CACHE | DATA_READ_CACHE | DATA_WRITE_CACHE | RENDER_CACHE | SAMPLER_CACHE; |
Chia-I Wu | b5c1cdf | 2014-11-22 03:17:45 +0800 | [diff] [blame] | 95 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 96 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 97 | // Optimal layout when image is only used for color attachment read/write |
| 98 | caches = DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 99 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 100 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 101 | // Optimal layout when image is only used for depth/stencil attachment read/write |
| 102 | caches = DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 103 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 104 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 105 | // Optimal layout when image is used for read only depth/stencil attachment and shader access |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 106 | caches = RENDER_CACHE; |
| 107 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 108 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 109 | // Optimal layout when image is used for read only shader access |
| 110 | caches = DATA_READ_CACHE | SAMPLER_CACHE; |
| 111 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 112 | case VK_IMAGE_LAYOUT_CLEAR_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 113 | // Optimal layout when image is used only for clear operations |
| 114 | caches = RENDER_CACHE; |
| 115 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 116 | case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 117 | // Optimal layout when image is used only as source of transfer operations |
| 118 | caches = MEM_CACHE | DATA_READ_CACHE | RENDER_CACHE | SAMPLER_CACHE; |
| 119 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 120 | case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 121 | // Optimal layout when image is used only as destination of transfer operations |
| 122 | caches = MEM_CACHE | DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 123 | break; |
| 124 | default: |
| 125 | caches = 0; |
| 126 | break; |
| 127 | } |
| 128 | |
| 129 | return caches; |
| 130 | } |
| 131 | |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 132 | static void cmd_resolve_depth(struct intel_cmd *cmd, |
| 133 | struct intel_img *img, |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 134 | VK_IMAGE_LAYOUT old_layout, |
| 135 | VK_IMAGE_LAYOUT new_layout, |
| 136 | const VK_IMAGE_SUBRESOURCE_RANGE *range) |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 137 | { |
| 138 | const uint32_t old_ops = img_get_layout_ops(img, old_layout); |
| 139 | const uint32_t new_ops = img_get_layout_ops(img, new_layout); |
| 140 | |
| 141 | if (old_ops & WRITE_OP) { |
| 142 | if ((old_ops & HIZ_OP) && !(new_ops & HIZ_OP)) |
| 143 | cmd_meta_ds_op(cmd, INTEL_CMD_META_DS_RESOLVE, img, range); |
| 144 | else if (!(old_ops & HIZ_OP) && (new_ops & HIZ_OP)) |
| 145 | cmd_meta_ds_op(cmd, INTEL_CMD_META_DS_HIZ_RESOLVE, img, range); |
| 146 | } |
| 147 | } |
| 148 | |
Chia-I Wu | b5c1cdf | 2014-11-22 03:17:45 +0800 | [diff] [blame] | 149 | static uint32_t cmd_get_flush_flags(const struct intel_cmd *cmd, |
| 150 | uint32_t old_caches, |
| 151 | uint32_t new_caches, |
| 152 | bool is_ds) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 153 | { |
| 154 | uint32_t flags = 0; |
| 155 | |
| 156 | /* not dirty */ |
| 157 | if (!(old_caches & (MEM_CACHE | RENDER_CACHE | DATA_WRITE_CACHE))) |
| 158 | return 0; |
| 159 | |
| 160 | if ((old_caches & RENDER_CACHE) && (new_caches & ~RENDER_CACHE)) { |
Chia-I Wu | b5c1cdf | 2014-11-22 03:17:45 +0800 | [diff] [blame] | 161 | if (is_ds) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 162 | flags |= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 163 | else |
| 164 | flags |= GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH; |
| 165 | } |
| 166 | |
| 167 | if ((old_caches & DATA_WRITE_CACHE) && |
| 168 | (new_caches & ~(DATA_READ_CACHE | DATA_WRITE_CACHE))) { |
| 169 | if (cmd_gen(cmd) >= INTEL_GEN(7)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 170 | flags |= GEN7_PIPE_CONTROL_DC_FLUSH; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (new_caches & SAMPLER_CACHE) |
| 174 | flags |= GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 175 | |
| 176 | if ((new_caches & DATA_READ_CACHE) && old_caches != DATA_WRITE_CACHE) |
| 177 | flags |= GEN6_PIPE_CONTROL_CONSTANT_CACHE_INVALIDATE; |
| 178 | |
| 179 | if (!flags) |
| 180 | return 0; |
| 181 | |
| 182 | flags |= GEN6_PIPE_CONTROL_CS_STALL; |
| 183 | |
| 184 | return flags; |
| 185 | } |
| 186 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 187 | static void cmd_memory_barriers(struct intel_cmd *cmd, |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 188 | uint32_t flush_flags, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 189 | uint32_t memory_barrier_count, |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 190 | const void** memory_barriers) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 191 | { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 192 | uint32_t i; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 193 | VK_FLAGS input_mask = 0; |
| 194 | VK_FLAGS output_mask = 0; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 195 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 196 | for (i = 0; i < memory_barrier_count; i++) { |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 197 | |
| 198 | const union { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 199 | VK_STRUCTURE_TYPE type; |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 200 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 201 | VK_MEMORY_BARRIER mem; |
| 202 | VK_BUFFER_MEMORY_BARRIER buf; |
| 203 | VK_IMAGE_MEMORY_BARRIER img; |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 204 | } *u = memory_barriers[i]; |
| 205 | |
| 206 | switch(u->type) |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 207 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 208 | case VK_STRUCTURE_TYPE_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 209 | output_mask |= u->mem.outputMask; |
| 210 | input_mask |= u->mem.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 211 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 212 | case VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 213 | output_mask |= u->buf.outputMask; |
| 214 | input_mask |= u->buf.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 215 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 216 | case VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 217 | output_mask |= u->img.outputMask; |
| 218 | input_mask |= u->img.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 219 | { |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 220 | struct intel_img *img = intel_img(u->img.image); |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 221 | |
| 222 | cmd_resolve_depth(cmd, img, u->img.oldLayout, |
| 223 | u->img.newLayout, &u->img.subresourceRange); |
| 224 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 225 | flush_flags |= cmd_get_flush_flags(cmd, |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 226 | img_get_layout_caches(img, u->img.oldLayout), |
| 227 | img_get_layout_caches(img, u->img.newLayout), |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 228 | icd_format_is_ds(img->layout.format)); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 229 | } |
| 230 | break; |
| 231 | default: |
| 232 | break; |
| 233 | } |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 234 | } |
| 235 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 236 | if (output_mask & VK_MEMORY_OUTPUT_SHADER_WRITE_BIT) { |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 237 | flush_flags |= GEN7_PIPE_CONTROL_DC_FLUSH; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 238 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 239 | if (output_mask & VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 240 | flush_flags |= GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH; |
| 241 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 242 | if (output_mask & VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 243 | flush_flags |= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 244 | } |
| 245 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 246 | /* CPU write is cache coherent, so VK_MEMORY_OUTPUT_CPU_WRITE_BIT needs no flush. */ |
| 247 | /* Meta handles flushes, so VK_MEMORY_OUTPUT_COPY_BIT needs no flush. */ |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 248 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 249 | if (input_mask & (VK_MEMORY_INPUT_SHADER_READ_BIT | VK_MEMORY_INPUT_UNIFORM_READ_BIT)) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 250 | flush_flags |= GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 251 | } |
| 252 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 253 | if (input_mask & VK_MEMORY_INPUT_UNIFORM_READ_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 254 | flush_flags |= GEN6_PIPE_CONTROL_CONSTANT_CACHE_INVALIDATE; |
| 255 | } |
| 256 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 257 | if (input_mask & VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 258 | flush_flags |= GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 259 | } |
| 260 | |
| 261 | /* These bits have no corresponding cache invalidate operation. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 262 | * VK_MEMORY_INPUT_CPU_READ_BIT |
| 263 | * VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
| 264 | * VK_MEMORY_INPUT_INDEX_FETCH_BIT |
| 265 | * VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
| 266 | * VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
| 267 | * VK_MEMORY_INPUT_COPY_BIT |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 268 | */ |
| 269 | |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 270 | cmd_batch_flush(cmd, flush_flags); |
| 271 | } |
| 272 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 273 | ICD_EXPORT void VKAPI vkCmdWaitEvents( |
| 274 | VK_CMD_BUFFER cmdBuffer, |
| 275 | const VK_EVENT_WAIT_INFO* pWaitInfo) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 276 | { |
| 277 | struct intel_cmd *cmd = intel_cmd(cmdBuffer); |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 278 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 279 | /* This hardware will always wait at VK_WAIT_EVENT_TOP_OF_PIPE. |
| 280 | * Passing a pWaitInfo->waitEvent of VK_WAIT_EVENT_BEFORE_FRAGMENT_PROCESSING |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 281 | * does not change that. |
| 282 | */ |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 283 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 284 | /* Because the command buffer is serialized, reaching |
| 285 | * a pipelined wait is always after completion of prior events. |
| 286 | * pWaitInfo->pEvents need not be examined. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 287 | * vkCmdWaitEvents is equivalent to memory barrier part of vkCmdPipelineBarrier. |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 288 | * cmd_memory_barriers will wait for GEN6_PIPE_CONTROL_CS_STALL and perform |
| 289 | * appropriate cache control. |
| 290 | */ |
| 291 | cmd_memory_barriers(cmd, |
| 292 | GEN6_PIPE_CONTROL_CS_STALL, |
Mark Lobodzinski | 628a8a5 | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 293 | pWaitInfo->memBarrierCount, pWaitInfo->ppMemBarriers); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 296 | ICD_EXPORT void VKAPI vkCmdPipelineBarrier( |
| 297 | VK_CMD_BUFFER cmdBuffer, |
| 298 | const VK_PIPELINE_BARRIER* pBarrier) |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 299 | { |
| 300 | struct intel_cmd *cmd = intel_cmd(cmdBuffer); |
| 301 | uint32_t pipe_control_flags = 0; |
| 302 | uint32_t i; |
| 303 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 304 | /* This hardware will always wait at VK_WAIT_EVENT_TOP_OF_PIPE. |
| 305 | * Passing a pBarrier->waitEvent of VK_WAIT_EVENT_BEFORE_FRAGMENT_PROCESSING |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 306 | * does not change that. |
| 307 | */ |
| 308 | |
| 309 | /* Cache control is done with PIPE_CONTROL flags. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 310 | * With no GEN6_PIPE_CONTROL_CS_STALL flag set, it behaves as VK_PIPE_EVENT_TOP_OF_PIPE. |
| 311 | * All other pEvents values will behave as VK_PIPE_EVENT_GPU_COMMANDS_COMPLETE. |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 312 | */ |
| 313 | for (i = 0; i < pBarrier->eventCount; i++) { |
| 314 | switch(pBarrier->pEvents[i]) |
| 315 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 316 | case VK_PIPE_EVENT_TOP_OF_PIPE: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 317 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 318 | case VK_PIPE_EVENT_VERTEX_PROCESSING_COMPLETE: |
| 319 | case VK_PIPE_EVENT_LOCAL_FRAGMENT_PROCESSING_COMPLETE: |
| 320 | case VK_PIPE_EVENT_FRAGMENT_PROCESSING_COMPLETE: |
| 321 | case VK_PIPE_EVENT_GRAPHICS_PIPELINE_COMPLETE: |
| 322 | case VK_PIPE_EVENT_COMPUTE_PIPELINE_COMPLETE: |
| 323 | case VK_PIPE_EVENT_TRANSFER_COMPLETE: |
| 324 | case VK_PIPE_EVENT_GPU_COMMANDS_COMPLETE: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 325 | pipe_control_flags |= GEN6_PIPE_CONTROL_CS_STALL; |
| 326 | break; |
| 327 | default: |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame^] | 328 | cmd_fail(cmd, VK_ERROR_UNKNOWN); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 329 | return; |
| 330 | break; |
| 331 | } |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 332 | } |
| 333 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 334 | /* cmd_memory_barriers can wait for GEN6_PIPE_CONTROL_CS_STALL and perform |
| 335 | * appropriate cache control. |
| 336 | */ |
| 337 | cmd_memory_barriers(cmd, |
| 338 | pipe_control_flags, |
Mark Lobodzinski | 628a8a5 | 2015-02-02 11:55:52 -0600 | [diff] [blame] | 339 | pBarrier->memBarrierCount, pBarrier->ppMemBarriers); |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 340 | } |