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 | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 48 | VkImageLayout layout) |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 49 | { |
| 50 | uint32_t ops; |
| 51 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 52 | switch ((int) layout) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 53 | case VK_IMAGE_LAYOUT_GENERAL: |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 54 | case VK_IMAGE_LAYOUT_PRESENT_SOURCE_KHR: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 55 | ops = READ_OP | WRITE_OP; |
| 56 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 57 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 58 | ops = READ_OP | WRITE_OP; |
| 59 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 60 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 61 | ops = READ_OP | WRITE_OP | HIZ_OP; |
| 62 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 63 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 64 | ops = READ_OP | HIZ_OP; |
| 65 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 66 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 67 | ops = READ_OP; |
| 68 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 69 | case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 70 | ops = READ_OP; |
| 71 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 72 | case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 73 | ops = WRITE_OP; |
| 74 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 75 | case VK_IMAGE_LAYOUT_UNDEFINED: |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 76 | default: |
| 77 | ops = 0; |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | return ops; |
| 82 | } |
| 83 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 84 | static uint32_t img_get_layout_caches(const struct intel_img *img, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 85 | VkImageLayout layout) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 86 | { |
| 87 | uint32_t caches; |
| 88 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 89 | switch ((int) layout) { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 90 | case VK_IMAGE_LAYOUT_GENERAL: |
Ian Elliott | 338dedb | 2015-08-21 15:09:33 -0600 | [diff] [blame] | 91 | case VK_IMAGE_LAYOUT_PRESENT_SOURCE_KHR: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 92 | // General layout when image can be used for any kind of access |
| 93 | 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] | 94 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 95 | case VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 96 | // Optimal layout when image is only used for color attachment read/write |
| 97 | caches = DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 98 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 99 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 100 | // Optimal layout when image is only used for depth/stencil attachment read/write |
| 101 | caches = DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 102 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 103 | case VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 104 | // 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] | 105 | caches = RENDER_CACHE; |
| 106 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 107 | case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 108 | // Optimal layout when image is used for read only shader access |
| 109 | caches = DATA_READ_CACHE | SAMPLER_CACHE; |
| 110 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 111 | case VK_IMAGE_LAYOUT_TRANSFER_SOURCE_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 112 | // Optimal layout when image is used only as source of transfer operations |
| 113 | caches = MEM_CACHE | DATA_READ_CACHE | RENDER_CACHE | SAMPLER_CACHE; |
| 114 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 115 | case VK_IMAGE_LAYOUT_TRANSFER_DESTINATION_OPTIMAL: |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 116 | // Optimal layout when image is used only as destination of transfer operations |
| 117 | caches = MEM_CACHE | DATA_WRITE_CACHE | RENDER_CACHE; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 118 | break; |
| 119 | default: |
| 120 | caches = 0; |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | return caches; |
| 125 | } |
| 126 | |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 127 | static void cmd_resolve_depth(struct intel_cmd *cmd, |
| 128 | struct intel_img *img, |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 129 | VkImageLayout old_layout, |
| 130 | VkImageLayout new_layout, |
| 131 | const VkImageSubresourceRange *range) |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 132 | { |
| 133 | const uint32_t old_ops = img_get_layout_ops(img, old_layout); |
| 134 | const uint32_t new_ops = img_get_layout_ops(img, new_layout); |
| 135 | |
| 136 | if (old_ops & WRITE_OP) { |
| 137 | if ((old_ops & HIZ_OP) && !(new_ops & HIZ_OP)) |
| 138 | cmd_meta_ds_op(cmd, INTEL_CMD_META_DS_RESOLVE, img, range); |
| 139 | else if (!(old_ops & HIZ_OP) && (new_ops & HIZ_OP)) |
| 140 | cmd_meta_ds_op(cmd, INTEL_CMD_META_DS_HIZ_RESOLVE, img, range); |
| 141 | } |
| 142 | } |
| 143 | |
Chia-I Wu | b5c1cdf | 2014-11-22 03:17:45 +0800 | [diff] [blame] | 144 | static uint32_t cmd_get_flush_flags(const struct intel_cmd *cmd, |
| 145 | uint32_t old_caches, |
| 146 | uint32_t new_caches, |
| 147 | bool is_ds) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 148 | { |
| 149 | uint32_t flags = 0; |
| 150 | |
| 151 | /* not dirty */ |
| 152 | if (!(old_caches & (MEM_CACHE | RENDER_CACHE | DATA_WRITE_CACHE))) |
| 153 | return 0; |
| 154 | |
| 155 | if ((old_caches & RENDER_CACHE) && (new_caches & ~RENDER_CACHE)) { |
Chia-I Wu | b5c1cdf | 2014-11-22 03:17:45 +0800 | [diff] [blame] | 156 | if (is_ds) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 157 | flags |= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 158 | else |
| 159 | flags |= GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH; |
| 160 | } |
| 161 | |
| 162 | if ((old_caches & DATA_WRITE_CACHE) && |
| 163 | (new_caches & ~(DATA_READ_CACHE | DATA_WRITE_CACHE))) { |
| 164 | if (cmd_gen(cmd) >= INTEL_GEN(7)) |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 165 | flags |= GEN7_PIPE_CONTROL_DC_FLUSH; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (new_caches & SAMPLER_CACHE) |
| 169 | flags |= GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 170 | |
| 171 | if ((new_caches & DATA_READ_CACHE) && old_caches != DATA_WRITE_CACHE) |
| 172 | flags |= GEN6_PIPE_CONTROL_CONSTANT_CACHE_INVALIDATE; |
| 173 | |
| 174 | if (!flags) |
| 175 | return 0; |
| 176 | |
| 177 | flags |= GEN6_PIPE_CONTROL_CS_STALL; |
| 178 | |
| 179 | return flags; |
| 180 | } |
| 181 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 182 | static void cmd_memory_barriers(struct intel_cmd *cmd, |
Courtney Goeltzenleuchter | aeffeae | 2015-09-10 17:58:54 -0600 | [diff] [blame^] | 183 | uint32_t flush_flags, |
Mark Lobodzinski | e2d07a5 | 2015-01-29 08:55:56 -0600 | [diff] [blame] | 184 | uint32_t memory_barrier_count, |
Courtney Goeltzenleuchter | 73a21d3 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 185 | const void* const* memory_barriers) |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 186 | { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 187 | uint32_t i; |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 188 | VkFlags input_mask = 0; |
| 189 | VkFlags output_mask = 0; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 190 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 191 | for (i = 0; i < memory_barrier_count; i++) { |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 192 | |
| 193 | const union { |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 194 | VkStructureType type; |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 195 | |
Courtney Goeltzenleuchter | 382489d | 2015-04-10 08:34:15 -0600 | [diff] [blame] | 196 | VkMemoryBarrier mem; |
| 197 | VkBufferMemoryBarrier buf; |
| 198 | VkImageMemoryBarrier img; |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 199 | } *u = memory_barriers[i]; |
| 200 | |
| 201 | switch(u->type) |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 202 | { |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 203 | case VK_STRUCTURE_TYPE_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 204 | output_mask |= u->mem.outputMask; |
| 205 | input_mask |= u->mem.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 206 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 207 | case VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 208 | output_mask |= u->buf.outputMask; |
| 209 | input_mask |= u->buf.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 210 | break; |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 211 | case VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER: |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 212 | output_mask |= u->img.outputMask; |
| 213 | input_mask |= u->img.inputMask; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 214 | { |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 215 | struct intel_img *img = intel_img(u->img.image); |
Chia-I Wu | c45db53 | 2015-02-19 11:20:38 -0700 | [diff] [blame] | 216 | |
| 217 | cmd_resolve_depth(cmd, img, u->img.oldLayout, |
| 218 | u->img.newLayout, &u->img.subresourceRange); |
| 219 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 220 | flush_flags |= cmd_get_flush_flags(cmd, |
Mark Lobodzinski | d3eabd7 | 2015-01-29 14:24:14 -0600 | [diff] [blame] | 221 | img_get_layout_caches(img, u->img.oldLayout), |
| 222 | img_get_layout_caches(img, u->img.newLayout), |
Jeremy Hayes | 2b7e88a | 2015-01-23 08:51:43 -0700 | [diff] [blame] | 223 | icd_format_is_ds(img->layout.format)); |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 224 | } |
| 225 | break; |
| 226 | default: |
| 227 | break; |
| 228 | } |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 231 | if (output_mask & VK_MEMORY_OUTPUT_SHADER_WRITE_BIT) { |
Chia-I Wu | 97aa4de | 2015-03-05 15:43:16 -0700 | [diff] [blame] | 232 | flush_flags |= GEN7_PIPE_CONTROL_DC_FLUSH; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 233 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 234 | if (output_mask & VK_MEMORY_OUTPUT_COLOR_ATTACHMENT_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 235 | flush_flags |= GEN6_PIPE_CONTROL_RENDER_CACHE_FLUSH; |
| 236 | } |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 237 | if (output_mask & VK_MEMORY_OUTPUT_DEPTH_STENCIL_ATTACHMENT_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 238 | flush_flags |= GEN6_PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 239 | } |
| 240 | |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 241 | /* CPU write is cache coherent, so VK_MEMORY_OUTPUT_HOST_WRITE_BIT needs no flush. */ |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 242 | /* Meta handles flushes, so VK_MEMORY_OUTPUT_TRANSFER_BIT needs no flush. */ |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 243 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 244 | 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] | 245 | flush_flags |= GEN6_PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 246 | } |
| 247 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 248 | if (input_mask & VK_MEMORY_INPUT_UNIFORM_READ_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 249 | flush_flags |= GEN6_PIPE_CONTROL_CONSTANT_CACHE_INVALIDATE; |
| 250 | } |
| 251 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 252 | if (input_mask & VK_MEMORY_INPUT_VERTEX_ATTRIBUTE_FETCH_BIT) { |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 253 | flush_flags |= GEN6_PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 254 | } |
| 255 | |
| 256 | /* These bits have no corresponding cache invalidate operation. |
Courtney Goeltzenleuchter | a569a50 | 2015-04-29 17:16:21 -0600 | [diff] [blame] | 257 | * VK_MEMORY_INPUT_HOST_READ_BIT |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 258 | * VK_MEMORY_INPUT_INDIRECT_COMMAND_BIT |
| 259 | * VK_MEMORY_INPUT_INDEX_FETCH_BIT |
| 260 | * VK_MEMORY_INPUT_COLOR_ATTACHMENT_BIT |
| 261 | * VK_MEMORY_INPUT_DEPTH_STENCIL_ATTACHMENT_BIT |
Courtney Goeltzenleuchter | ad87081 | 2015-04-15 15:29:59 -0600 | [diff] [blame] | 262 | * VK_MEMORY_INPUT_TRANSFER_BIT |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 263 | */ |
| 264 | |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 265 | cmd_batch_flush(cmd, flush_flags); |
| 266 | } |
| 267 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 268 | ICD_EXPORT void VKAPI vkCmdWaitEvents( |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 269 | VkCmdBuffer cmdBuffer, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 270 | uint32_t eventCount, |
| 271 | const VkEvent* pEvents, |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 272 | VkPipelineStageFlags sourceStageMask, |
| 273 | VkPipelineStageFlags destStageMask, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 274 | uint32_t memBarrierCount, |
Courtney Goeltzenleuchter | d9ba342 | 2015-07-12 12:58:58 -0600 | [diff] [blame] | 275 | const void* const* ppMemBarriers) |
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 | |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 279 | /* This hardware will always wait at VK_PIPELINE_STAGE_TOP_OF_PIPE. |
| 280 | * Passing a stageMask specifying other stages |
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, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 293 | memBarrierCount, 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( |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 297 | VkCmdBuffer cmdBuffer, |
Courtney Goeltzenleuchter | 82b348f | 2015-07-12 13:07:46 -0600 | [diff] [blame] | 298 | VkPipelineStageFlags srcStageMask, |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 299 | VkPipelineStageFlags destStageMask, |
Courtney Goeltzenleuchter | 1f41f54 | 2015-07-09 11:44:38 -0600 | [diff] [blame] | 300 | VkBool32 byRegion, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 301 | uint32_t memBarrierCount, |
Courtney Goeltzenleuchter | 82b348f | 2015-07-12 13:07:46 -0600 | [diff] [blame] | 302 | const void* const* ppMemBarriers) |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 303 | { |
| 304 | struct intel_cmd *cmd = intel_cmd(cmdBuffer); |
| 305 | uint32_t pipe_control_flags = 0; |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 306 | |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 307 | /* This hardware will always wait at VK_WAIT_EVENT_TOP_OF_PIPE. |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 308 | * Passing a stageMask specifying other stages |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 309 | * does not change that. |
| 310 | */ |
| 311 | |
| 312 | /* Cache control is done with PIPE_CONTROL flags. |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 313 | * With no GEN6_PIPE_CONTROL_CS_STALL flag set, it behaves as VK_PIPE_EVENT_TOP_OF_PIPE. |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 314 | * All other pEvents values will behave as VK_PIPE_EVENT_COMMANDS_COMPLETE. |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 315 | */ |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 316 | |
Courtney Goeltzenleuchter | 73a21d3 | 2015-07-12 13:20:05 -0600 | [diff] [blame] | 317 | if ((srcStageMask & VK_PIPELINE_STAGE_ALL_GRAPHICS) || |
Tony Barbour | c2e987e | 2015-06-29 16:20:35 -0600 | [diff] [blame] | 318 | (destStageMask & VK_PIPELINE_STAGE_ALL_GRAPHICS)){ |
| 319 | pipe_control_flags = GEN6_PIPE_CONTROL_CS_STALL; |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 320 | } |
| 321 | |
Mike Stroyan | 55658c2 | 2014-12-04 11:08:39 +0000 | [diff] [blame] | 322 | /* cmd_memory_barriers can wait for GEN6_PIPE_CONTROL_CS_STALL and perform |
| 323 | * appropriate cache control. |
| 324 | */ |
| 325 | cmd_memory_barriers(cmd, |
| 326 | pipe_control_flags, |
Tony Barbour | 8205d90 | 2015-04-16 15:59:00 -0600 | [diff] [blame] | 327 | memBarrierCount, ppMemBarriers); |
Chia-I Wu | 525c660 | 2014-08-27 10:22:34 +0800 | [diff] [blame] | 328 | } |