Karl Schultz | 7b024b4 | 2018-08-30 16:18:18 -0600 | [diff] [blame] | 1 | /* Copyright (c) 2015-2019 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2019 Valve Corporation |
| 3 | * Copyright (c) 2015-2019 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2019 Google Inc. |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 19 | * Author: Dave Houlton <daveh@lunarg.com> |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <cinttypes> |
| 23 | #include <cassert> |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 24 | #include <chrono> |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 25 | #include <vector> |
| 26 | #include <unordered_map> |
| 27 | #include <string> |
| 28 | #include <sstream> |
| 29 | #include <SPIRV/spirv.hpp> |
| 30 | #include "vk_loader_platform.h" |
| 31 | #include "vk_enum_string_helper.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 32 | #include "vk_layer_data.h" |
| 33 | #include "vk_layer_extension_utils.h" |
| 34 | #include "vk_layer_utils.h" |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 35 | #include "chassis.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 36 | #include "core_validation.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 37 | #include "shader_validation.h" |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 38 | #include "spirv-tools/libspirv.h" |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 39 | #include "xxhash.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 40 | |
| 41 | enum FORMAT_TYPE { |
| 42 | FORMAT_TYPE_FLOAT = 1, // UNORM, SNORM, FLOAT, USCALED, SSCALED, SRGB -- anything we consider float in the shader |
| 43 | FORMAT_TYPE_SINT = 2, |
| 44 | FORMAT_TYPE_UINT = 4, |
| 45 | }; |
| 46 | |
| 47 | typedef std::pair<unsigned, unsigned> location_t; |
| 48 | |
| 49 | struct interface_var { |
| 50 | uint32_t id; |
| 51 | uint32_t type_id; |
| 52 | uint32_t offset; |
| 53 | bool is_patch; |
| 54 | bool is_block_member; |
| 55 | bool is_relaxed_precision; |
| 56 | // TODO: collect the name, too? Isn't required to be present. |
| 57 | }; |
| 58 | |
| 59 | struct shader_stage_attributes { |
| 60 | char const *const name; |
| 61 | bool arrayed_input; |
| 62 | bool arrayed_output; |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 63 | VkShaderStageFlags stage; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static shader_stage_attributes shader_stage_attribs[] = { |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 67 | {"vertex shader", false, false, VK_SHADER_STAGE_VERTEX_BIT}, |
| 68 | {"tessellation control shader", true, true, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT}, |
| 69 | {"tessellation evaluation shader", true, false, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT}, |
| 70 | {"geometry shader", true, false, VK_SHADER_STAGE_GEOMETRY_BIT}, |
| 71 | {"fragment shader", false, false, VK_SHADER_STAGE_FRAGMENT_BIT}, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | // SPIRV utility functions |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 75 | void SHADER_MODULE_STATE::BuildDefIndex() { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 76 | for (auto insn : *this) { |
| 77 | switch (insn.opcode()) { |
| 78 | // Types |
| 79 | case spv::OpTypeVoid: |
| 80 | case spv::OpTypeBool: |
| 81 | case spv::OpTypeInt: |
| 82 | case spv::OpTypeFloat: |
| 83 | case spv::OpTypeVector: |
| 84 | case spv::OpTypeMatrix: |
| 85 | case spv::OpTypeImage: |
| 86 | case spv::OpTypeSampler: |
| 87 | case spv::OpTypeSampledImage: |
| 88 | case spv::OpTypeArray: |
| 89 | case spv::OpTypeRuntimeArray: |
| 90 | case spv::OpTypeStruct: |
| 91 | case spv::OpTypeOpaque: |
| 92 | case spv::OpTypePointer: |
| 93 | case spv::OpTypeFunction: |
| 94 | case spv::OpTypeEvent: |
| 95 | case spv::OpTypeDeviceEvent: |
| 96 | case spv::OpTypeReserveId: |
| 97 | case spv::OpTypeQueue: |
| 98 | case spv::OpTypePipe: |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 99 | case spv::OpTypeAccelerationStructureNV: |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 100 | case spv::OpTypeCooperativeMatrixNV: |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 101 | def_index[insn.word(1)] = insn.offset(); |
| 102 | break; |
| 103 | |
| 104 | // Fixed constants |
| 105 | case spv::OpConstantTrue: |
| 106 | case spv::OpConstantFalse: |
| 107 | case spv::OpConstant: |
| 108 | case spv::OpConstantComposite: |
| 109 | case spv::OpConstantSampler: |
| 110 | case spv::OpConstantNull: |
| 111 | def_index[insn.word(2)] = insn.offset(); |
| 112 | break; |
| 113 | |
| 114 | // Specialization constants |
| 115 | case spv::OpSpecConstantTrue: |
| 116 | case spv::OpSpecConstantFalse: |
| 117 | case spv::OpSpecConstant: |
| 118 | case spv::OpSpecConstantComposite: |
| 119 | case spv::OpSpecConstantOp: |
| 120 | def_index[insn.word(2)] = insn.offset(); |
| 121 | break; |
| 122 | |
| 123 | // Variables |
| 124 | case spv::OpVariable: |
| 125 | def_index[insn.word(2)] = insn.offset(); |
| 126 | break; |
| 127 | |
| 128 | // Functions |
| 129 | case spv::OpFunction: |
| 130 | def_index[insn.word(2)] = insn.offset(); |
| 131 | break; |
| 132 | |
| 133 | default: |
| 134 | // We don't care about any other defs for now. |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 140 | unsigned ExecutionModelToShaderStageFlagBits(unsigned mode) { |
| 141 | switch (mode) { |
| 142 | case spv::ExecutionModelVertex: |
| 143 | return VK_SHADER_STAGE_VERTEX_BIT; |
| 144 | case spv::ExecutionModelTessellationControl: |
| 145 | return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT; |
| 146 | case spv::ExecutionModelTessellationEvaluation: |
| 147 | return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
| 148 | case spv::ExecutionModelGeometry: |
| 149 | return VK_SHADER_STAGE_GEOMETRY_BIT; |
| 150 | case spv::ExecutionModelFragment: |
| 151 | return VK_SHADER_STAGE_FRAGMENT_BIT; |
| 152 | case spv::ExecutionModelGLCompute: |
| 153 | return VK_SHADER_STAGE_COMPUTE_BIT; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 154 | case spv::ExecutionModelRayGenerationNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 155 | return VK_SHADER_STAGE_RAYGEN_BIT_NV; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 156 | case spv::ExecutionModelAnyHitNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 157 | return VK_SHADER_STAGE_ANY_HIT_BIT_NV; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 158 | case spv::ExecutionModelClosestHitNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 159 | return VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 160 | case spv::ExecutionModelMissNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 161 | return VK_SHADER_STAGE_MISS_BIT_NV; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 162 | case spv::ExecutionModelIntersectionNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 163 | return VK_SHADER_STAGE_INTERSECTION_BIT_NV; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 164 | case spv::ExecutionModelCallableNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 165 | return VK_SHADER_STAGE_CALLABLE_BIT_NV; |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 166 | case spv::ExecutionModelTaskNV: |
| 167 | return VK_SHADER_STAGE_TASK_BIT_NV; |
| 168 | case spv::ExecutionModelMeshNV: |
| 169 | return VK_SHADER_STAGE_MESH_BIT_NV; |
| 170 | default: |
| 171 | return 0; |
| 172 | } |
| 173 | } |
| 174 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 175 | static spirv_inst_iter FindEntrypoint(SHADER_MODULE_STATE const *src, char const *name, VkShaderStageFlagBits stageBits) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 176 | for (auto insn : *src) { |
| 177 | if (insn.opcode() == spv::OpEntryPoint) { |
| 178 | auto entrypointName = (char const *)&insn.word(3); |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 179 | auto executionModel = insn.word(1); |
| 180 | auto entrypointStageBits = ExecutionModelToShaderStageFlagBits(executionModel); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 181 | |
| 182 | if (!strcmp(entrypointName, name) && (entrypointStageBits & stageBits)) { |
| 183 | return insn; |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return src->end(); |
| 189 | } |
| 190 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 191 | static char const *StorageClassName(unsigned sc) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 192 | switch (sc) { |
| 193 | case spv::StorageClassInput: |
| 194 | return "input"; |
| 195 | case spv::StorageClassOutput: |
| 196 | return "output"; |
| 197 | case spv::StorageClassUniformConstant: |
| 198 | return "const uniform"; |
| 199 | case spv::StorageClassUniform: |
| 200 | return "uniform"; |
| 201 | case spv::StorageClassWorkgroup: |
| 202 | return "workgroup local"; |
| 203 | case spv::StorageClassCrossWorkgroup: |
| 204 | return "workgroup global"; |
| 205 | case spv::StorageClassPrivate: |
| 206 | return "private global"; |
| 207 | case spv::StorageClassFunction: |
| 208 | return "function"; |
| 209 | case spv::StorageClassGeneric: |
| 210 | return "generic"; |
| 211 | case spv::StorageClassAtomicCounter: |
| 212 | return "atomic counter"; |
| 213 | case spv::StorageClassImage: |
| 214 | return "image"; |
| 215 | case spv::StorageClassPushConstant: |
| 216 | return "push constant"; |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 217 | case spv::StorageClassStorageBuffer: |
| 218 | return "storage buffer"; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 219 | default: |
| 220 | return "unknown"; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | // Get the value of an integral constant |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 225 | unsigned GetConstantValue(SHADER_MODULE_STATE const *src, unsigned id) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 226 | auto value = src->get_def(id); |
| 227 | assert(value != src->end()); |
| 228 | |
| 229 | if (value.opcode() != spv::OpConstant) { |
| 230 | // TODO: Either ensure that the specialization transform is already performed on a module we're |
| 231 | // considering here, OR -- specialize on the fly now. |
| 232 | return 1; |
| 233 | } |
| 234 | |
| 235 | return value.word(3); |
| 236 | } |
| 237 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 238 | static void DescribeTypeInner(std::ostringstream &ss, SHADER_MODULE_STATE const *src, unsigned type) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 239 | auto insn = src->get_def(type); |
| 240 | assert(insn != src->end()); |
| 241 | |
| 242 | switch (insn.opcode()) { |
| 243 | case spv::OpTypeBool: |
| 244 | ss << "bool"; |
| 245 | break; |
| 246 | case spv::OpTypeInt: |
| 247 | ss << (insn.word(3) ? 's' : 'u') << "int" << insn.word(2); |
| 248 | break; |
| 249 | case spv::OpTypeFloat: |
| 250 | ss << "float" << insn.word(2); |
| 251 | break; |
| 252 | case spv::OpTypeVector: |
| 253 | ss << "vec" << insn.word(3) << " of "; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 254 | DescribeTypeInner(ss, src, insn.word(2)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 255 | break; |
| 256 | case spv::OpTypeMatrix: |
| 257 | ss << "mat" << insn.word(3) << " of "; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 258 | DescribeTypeInner(ss, src, insn.word(2)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 259 | break; |
| 260 | case spv::OpTypeArray: |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 261 | ss << "arr[" << GetConstantValue(src, insn.word(3)) << "] of "; |
| 262 | DescribeTypeInner(ss, src, insn.word(2)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 263 | break; |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 264 | case spv::OpTypeRuntimeArray: |
| 265 | ss << "runtime arr[] of "; |
| 266 | DescribeTypeInner(ss, src, insn.word(2)); |
| 267 | break; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 268 | case spv::OpTypePointer: |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 269 | ss << "ptr to " << StorageClassName(insn.word(2)) << " "; |
| 270 | DescribeTypeInner(ss, src, insn.word(3)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 271 | break; |
| 272 | case spv::OpTypeStruct: { |
| 273 | ss << "struct of ("; |
| 274 | for (unsigned i = 2; i < insn.len(); i++) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 275 | DescribeTypeInner(ss, src, insn.word(i)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 276 | if (i == insn.len() - 1) { |
| 277 | ss << ")"; |
| 278 | } else { |
| 279 | ss << ", "; |
| 280 | } |
| 281 | } |
| 282 | break; |
| 283 | } |
| 284 | case spv::OpTypeSampler: |
| 285 | ss << "sampler"; |
| 286 | break; |
| 287 | case spv::OpTypeSampledImage: |
| 288 | ss << "sampler+"; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 289 | DescribeTypeInner(ss, src, insn.word(2)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 290 | break; |
| 291 | case spv::OpTypeImage: |
| 292 | ss << "image(dim=" << insn.word(3) << ", sampled=" << insn.word(7) << ")"; |
| 293 | break; |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 294 | case spv::OpTypeAccelerationStructureNV: |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 295 | ss << "accelerationStruture"; |
| 296 | break; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 297 | default: |
| 298 | ss << "oddtype"; |
| 299 | break; |
| 300 | } |
| 301 | } |
| 302 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 303 | static std::string DescribeType(SHADER_MODULE_STATE const *src, unsigned type) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 304 | std::ostringstream ss; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 305 | DescribeTypeInner(ss, src, type); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 306 | return ss.str(); |
| 307 | } |
| 308 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 309 | static bool IsNarrowNumericType(spirv_inst_iter type) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 310 | if (type.opcode() != spv::OpTypeInt && type.opcode() != spv::OpTypeFloat) return false; |
| 311 | return type.word(2) < 64; |
| 312 | } |
| 313 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 314 | static bool TypesMatch(SHADER_MODULE_STATE const *a, SHADER_MODULE_STATE const *b, unsigned a_type, unsigned b_type, bool a_arrayed, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 315 | bool b_arrayed, bool relaxed) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 316 | // Walk two type trees together, and complain about differences |
| 317 | auto a_insn = a->get_def(a_type); |
| 318 | auto b_insn = b->get_def(b_type); |
| 319 | assert(a_insn != a->end()); |
| 320 | assert(b_insn != b->end()); |
| 321 | |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 322 | // Ignore runtime-sized arrays-- they cannot appear in these interfaces. |
| 323 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 324 | if (a_arrayed && a_insn.opcode() == spv::OpTypeArray) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 325 | return TypesMatch(a, b, a_insn.word(2), b_type, false, b_arrayed, relaxed); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | if (b_arrayed && b_insn.opcode() == spv::OpTypeArray) { |
| 329 | // We probably just found the extra level of arrayness in b_type: compare the type inside it to a_type |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 330 | return TypesMatch(a, b, a_type, b_insn.word(2), a_arrayed, false, relaxed); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 333 | if (a_insn.opcode() == spv::OpTypeVector && relaxed && IsNarrowNumericType(b_insn)) { |
| 334 | return TypesMatch(a, b, a_insn.word(2), b_type, a_arrayed, b_arrayed, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | if (a_insn.opcode() != b_insn.opcode()) { |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | if (a_insn.opcode() == spv::OpTypePointer) { |
| 342 | // Match on pointee type. storage class is expected to differ |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 343 | return TypesMatch(a, b, a_insn.word(3), b_insn.word(3), a_arrayed, b_arrayed, relaxed); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | if (a_arrayed || b_arrayed) { |
| 347 | // If we havent resolved array-of-verts by here, we're not going to. |
| 348 | return false; |
| 349 | } |
| 350 | |
| 351 | switch (a_insn.opcode()) { |
| 352 | case spv::OpTypeBool: |
| 353 | return true; |
| 354 | case spv::OpTypeInt: |
| 355 | // Match on width, signedness |
| 356 | return a_insn.word(2) == b_insn.word(2) && a_insn.word(3) == b_insn.word(3); |
| 357 | case spv::OpTypeFloat: |
| 358 | // Match on width |
| 359 | return a_insn.word(2) == b_insn.word(2); |
| 360 | case spv::OpTypeVector: |
| 361 | // Match on element type, count. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 362 | if (!TypesMatch(a, b, a_insn.word(2), b_insn.word(2), a_arrayed, b_arrayed, false)) return false; |
| 363 | if (relaxed && IsNarrowNumericType(a->get_def(a_insn.word(2)))) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 364 | return a_insn.word(3) >= b_insn.word(3); |
| 365 | } else { |
| 366 | return a_insn.word(3) == b_insn.word(3); |
| 367 | } |
| 368 | case spv::OpTypeMatrix: |
| 369 | // Match on element type, count. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 370 | return TypesMatch(a, b, a_insn.word(2), b_insn.word(2), a_arrayed, b_arrayed, false) && |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 371 | a_insn.word(3) == b_insn.word(3); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 372 | case spv::OpTypeArray: |
| 373 | // Match on element type, count. these all have the same layout. we don't get here if b_arrayed. This differs from |
| 374 | // vector & matrix types in that the array size is the id of a constant instruction, * not a literal within OpTypeArray |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 375 | return TypesMatch(a, b, a_insn.word(2), b_insn.word(2), a_arrayed, b_arrayed, false) && |
| 376 | GetConstantValue(a, a_insn.word(3)) == GetConstantValue(b, b_insn.word(3)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 377 | case spv::OpTypeStruct: |
| 378 | // Match on all element types |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 379 | { |
| 380 | if (a_insn.len() != b_insn.len()) { |
| 381 | return false; // Structs cannot match if member counts differ |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 382 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 383 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 384 | for (unsigned i = 2; i < a_insn.len(); i++) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 385 | if (!TypesMatch(a, b, a_insn.word(i), b_insn.word(i), a_arrayed, b_arrayed, false)) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 386 | return false; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | return true; |
| 391 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 392 | default: |
| 393 | // Remaining types are CLisms, or may not appear in the interfaces we are interested in. Just claim no match. |
| 394 | return false; |
| 395 | } |
| 396 | } |
| 397 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 398 | static unsigned ValueOrDefault(std::unordered_map<unsigned, unsigned> const &map, unsigned id, unsigned def) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 399 | auto it = map.find(id); |
| 400 | if (it == map.end()) |
| 401 | return def; |
| 402 | else |
| 403 | return it->second; |
| 404 | } |
| 405 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 406 | static unsigned GetLocationsConsumedByType(SHADER_MODULE_STATE const *src, unsigned type, bool strip_array_level) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 407 | auto insn = src->get_def(type); |
| 408 | assert(insn != src->end()); |
| 409 | |
| 410 | switch (insn.opcode()) { |
| 411 | case spv::OpTypePointer: |
| 412 | // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing |
| 413 | // pointers around. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 414 | return GetLocationsConsumedByType(src, insn.word(3), strip_array_level); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 415 | case spv::OpTypeArray: |
| 416 | if (strip_array_level) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 417 | return GetLocationsConsumedByType(src, insn.word(2), false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 418 | } else { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 419 | return GetConstantValue(src, insn.word(3)) * GetLocationsConsumedByType(src, insn.word(2), false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 420 | } |
| 421 | case spv::OpTypeMatrix: |
| 422 | // Num locations is the dimension * element size |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 423 | return insn.word(3) * GetLocationsConsumedByType(src, insn.word(2), false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 424 | case spv::OpTypeVector: { |
| 425 | auto scalar_type = src->get_def(insn.word(2)); |
| 426 | auto bit_width = |
| 427 | (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32; |
| 428 | |
| 429 | // Locations are 128-bit wide; 3- and 4-component vectors of 64 bit types require two. |
| 430 | return (bit_width * insn.word(3) + 127) / 128; |
| 431 | } |
| 432 | default: |
| 433 | // Everything else is just 1. |
| 434 | return 1; |
| 435 | |
| 436 | // TODO: extend to handle 64bit scalar types, whose vectors may need multiple locations. |
| 437 | } |
| 438 | } |
| 439 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 440 | static unsigned GetComponentsConsumedByType(SHADER_MODULE_STATE const *src, unsigned type, bool strip_array_level) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 441 | auto insn = src->get_def(type); |
| 442 | assert(insn != src->end()); |
| 443 | |
| 444 | switch (insn.opcode()) { |
| 445 | case spv::OpTypePointer: |
| 446 | // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing |
| 447 | // pointers around. |
| 448 | return GetComponentsConsumedByType(src, insn.word(3), strip_array_level); |
| 449 | case spv::OpTypeStruct: { |
| 450 | uint32_t sum = 0; |
| 451 | for (uint32_t i = 2; i < insn.len(); i++) { // i=2 to skip word(0) and word(1)=ID of struct |
| 452 | sum += GetComponentsConsumedByType(src, insn.word(i), false); |
| 453 | } |
| 454 | return sum; |
| 455 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 456 | case spv::OpTypeArray: |
| 457 | if (strip_array_level) { |
| 458 | return GetComponentsConsumedByType(src, insn.word(2), false); |
| 459 | } else { |
| 460 | return GetConstantValue(src, insn.word(3)) * GetComponentsConsumedByType(src, insn.word(2), false); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 461 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 462 | case spv::OpTypeMatrix: |
| 463 | // Num locations is the dimension * element size |
| 464 | return insn.word(3) * GetComponentsConsumedByType(src, insn.word(2), false); |
| 465 | case spv::OpTypeVector: { |
| 466 | auto scalar_type = src->get_def(insn.word(2)); |
| 467 | auto bit_width = |
| 468 | (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32; |
| 469 | // One component is 32-bit |
| 470 | return (bit_width * insn.word(3) + 31) / 32; |
| 471 | } |
| 472 | case spv::OpTypeFloat: { |
| 473 | auto bit_width = insn.word(2); |
| 474 | return (bit_width + 31) / 32; |
| 475 | } |
| 476 | case spv::OpTypeInt: { |
| 477 | auto bit_width = insn.word(2); |
| 478 | return (bit_width + 31) / 32; |
| 479 | } |
| 480 | case spv::OpConstant: |
| 481 | return GetComponentsConsumedByType(src, insn.word(1), false); |
| 482 | default: |
| 483 | return 0; |
| 484 | } |
| 485 | } |
| 486 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 487 | static unsigned GetLocationsConsumedByFormat(VkFormat format) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 488 | switch (format) { |
| 489 | case VK_FORMAT_R64G64B64A64_SFLOAT: |
| 490 | case VK_FORMAT_R64G64B64A64_SINT: |
| 491 | case VK_FORMAT_R64G64B64A64_UINT: |
| 492 | case VK_FORMAT_R64G64B64_SFLOAT: |
| 493 | case VK_FORMAT_R64G64B64_SINT: |
| 494 | case VK_FORMAT_R64G64B64_UINT: |
| 495 | return 2; |
| 496 | default: |
| 497 | return 1; |
| 498 | } |
| 499 | } |
| 500 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 501 | static unsigned GetFormatType(VkFormat fmt) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 502 | if (FormatIsSInt(fmt)) return FORMAT_TYPE_SINT; |
| 503 | if (FormatIsUInt(fmt)) return FORMAT_TYPE_UINT; |
| 504 | if (FormatIsDepthAndStencil(fmt)) return FORMAT_TYPE_FLOAT | FORMAT_TYPE_UINT; |
| 505 | if (fmt == VK_FORMAT_UNDEFINED) return 0; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 506 | // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader. |
| 507 | return FORMAT_TYPE_FLOAT; |
| 508 | } |
| 509 | |
| 510 | // characterizes a SPIR-V type appearing in an interface to a FF stage, for comparison to a VkFormat's characterization above. |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 511 | // also used for input attachments, as we statically know their format. |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 512 | static unsigned GetFundamentalType(SHADER_MODULE_STATE const *src, unsigned type) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 513 | auto insn = src->get_def(type); |
| 514 | assert(insn != src->end()); |
| 515 | |
| 516 | switch (insn.opcode()) { |
| 517 | case spv::OpTypeInt: |
| 518 | return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT; |
| 519 | case spv::OpTypeFloat: |
| 520 | return FORMAT_TYPE_FLOAT; |
| 521 | case spv::OpTypeVector: |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 522 | case spv::OpTypeMatrix: |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 523 | case spv::OpTypeArray: |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 524 | case spv::OpTypeRuntimeArray: |
| 525 | case spv::OpTypeImage: |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 526 | return GetFundamentalType(src, insn.word(2)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 527 | case spv::OpTypePointer: |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 528 | return GetFundamentalType(src, insn.word(3)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 529 | |
| 530 | default: |
| 531 | return 0; |
| 532 | } |
| 533 | } |
| 534 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 535 | static uint32_t GetShaderStageId(VkShaderStageFlagBits stage) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 536 | uint32_t bit_pos = uint32_t(u_ffs(stage)); |
| 537 | return bit_pos - 1; |
| 538 | } |
| 539 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 540 | static spirv_inst_iter GetStructType(SHADER_MODULE_STATE const *src, spirv_inst_iter def, bool is_array_of_verts) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 541 | while (true) { |
| 542 | if (def.opcode() == spv::OpTypePointer) { |
| 543 | def = src->get_def(def.word(3)); |
| 544 | } else if (def.opcode() == spv::OpTypeArray && is_array_of_verts) { |
| 545 | def = src->get_def(def.word(2)); |
| 546 | is_array_of_verts = false; |
| 547 | } else if (def.opcode() == spv::OpTypeStruct) { |
| 548 | return def; |
| 549 | } else { |
| 550 | return src->end(); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 555 | static bool CollectInterfaceBlockMembers(SHADER_MODULE_STATE const *src, std::map<location_t, interface_var> *out, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 556 | std::unordered_map<unsigned, unsigned> const &blocks, bool is_array_of_verts, uint32_t id, |
| 557 | uint32_t type_id, bool is_patch, int /*first_location*/) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 558 | // Walk down the type_id presented, trying to determine whether it's actually an interface block. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 559 | auto type = GetStructType(src, src->get_def(type_id), is_array_of_verts && !is_patch); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 560 | if (type == src->end() || blocks.find(type.word(1)) == blocks.end()) { |
| 561 | // This isn't an interface block. |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 562 | return false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | std::unordered_map<unsigned, unsigned> member_components; |
| 566 | std::unordered_map<unsigned, unsigned> member_relaxed_precision; |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 567 | std::unordered_map<unsigned, unsigned> member_patch; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 568 | |
| 569 | // Walk all the OpMemberDecorate for type's result id -- first pass, collect components. |
| 570 | for (auto insn : *src) { |
| 571 | if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) { |
| 572 | unsigned member_index = insn.word(2); |
| 573 | |
| 574 | if (insn.word(3) == spv::DecorationComponent) { |
| 575 | unsigned component = insn.word(4); |
| 576 | member_components[member_index] = component; |
| 577 | } |
| 578 | |
| 579 | if (insn.word(3) == spv::DecorationRelaxedPrecision) { |
| 580 | member_relaxed_precision[member_index] = 1; |
| 581 | } |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 582 | |
| 583 | if (insn.word(3) == spv::DecorationPatch) { |
| 584 | member_patch[member_index] = 1; |
| 585 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 589 | // TODO: correctly handle location assignment from outside |
| 590 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 591 | // Second pass -- produce the output, from Location decorations |
| 592 | for (auto insn : *src) { |
| 593 | if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) { |
| 594 | unsigned member_index = insn.word(2); |
| 595 | unsigned member_type_id = type.word(2 + member_index); |
| 596 | |
| 597 | if (insn.word(3) == spv::DecorationLocation) { |
| 598 | unsigned location = insn.word(4); |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 599 | unsigned num_locations = GetLocationsConsumedByType(src, member_type_id, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 600 | auto component_it = member_components.find(member_index); |
| 601 | unsigned component = component_it == member_components.end() ? 0 : component_it->second; |
| 602 | bool is_relaxed_precision = member_relaxed_precision.find(member_index) != member_relaxed_precision.end(); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 603 | bool member_is_patch = is_patch || member_patch.count(member_index) > 0; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 604 | |
| 605 | for (unsigned int offset = 0; offset < num_locations; offset++) { |
| 606 | interface_var v = {}; |
| 607 | v.id = id; |
| 608 | // TODO: member index in interface_var too? |
| 609 | v.type_id = member_type_id; |
| 610 | v.offset = offset; |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 611 | v.is_patch = member_is_patch; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 612 | v.is_block_member = true; |
| 613 | v.is_relaxed_precision = is_relaxed_precision; |
| 614 | (*out)[std::make_pair(location + offset, component)] = v; |
| 615 | } |
| 616 | } |
| 617 | } |
| 618 | } |
Chris Forbes | a313d77 | 2017-06-13 13:59:41 -0700 | [diff] [blame] | 619 | |
| 620 | return true; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 623 | static std::vector<uint32_t> FindEntrypointInterfaces(spirv_inst_iter entrypoint) { |
| 624 | std::vector<uint32_t> interfaces; |
| 625 | // Find the end of the entrypoint's name string. additional zero bytes follow the actual null terminator, to fill out the |
| 626 | // rest of the word - so we only need to look at the last byte in the word to determine which word contains the terminator. |
| 627 | uint32_t word = 3; |
| 628 | while (entrypoint.word(word) & 0xff000000u) { |
| 629 | ++word; |
| 630 | } |
| 631 | ++word; |
| 632 | |
| 633 | for (; word < entrypoint.len(); word++) interfaces.push_back(entrypoint.word(word)); |
| 634 | |
| 635 | return interfaces; |
| 636 | } |
| 637 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 638 | static std::map<location_t, interface_var> CollectInterfaceByLocation(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 639 | spv::StorageClass sinterface, bool is_array_of_verts) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 640 | std::unordered_map<unsigned, unsigned> var_locations; |
| 641 | std::unordered_map<unsigned, unsigned> var_builtins; |
| 642 | std::unordered_map<unsigned, unsigned> var_components; |
| 643 | std::unordered_map<unsigned, unsigned> blocks; |
| 644 | std::unordered_map<unsigned, unsigned> var_patch; |
| 645 | std::unordered_map<unsigned, unsigned> var_relaxed_precision; |
| 646 | |
| 647 | for (auto insn : *src) { |
| 648 | // We consider two interface models: SSO rendezvous-by-location, and builtins. Complain about anything that |
| 649 | // fits neither model. |
| 650 | if (insn.opcode() == spv::OpDecorate) { |
| 651 | if (insn.word(2) == spv::DecorationLocation) { |
| 652 | var_locations[insn.word(1)] = insn.word(3); |
| 653 | } |
| 654 | |
| 655 | if (insn.word(2) == spv::DecorationBuiltIn) { |
| 656 | var_builtins[insn.word(1)] = insn.word(3); |
| 657 | } |
| 658 | |
| 659 | if (insn.word(2) == spv::DecorationComponent) { |
| 660 | var_components[insn.word(1)] = insn.word(3); |
| 661 | } |
| 662 | |
| 663 | if (insn.word(2) == spv::DecorationBlock) { |
| 664 | blocks[insn.word(1)] = 1; |
| 665 | } |
| 666 | |
| 667 | if (insn.word(2) == spv::DecorationPatch) { |
| 668 | var_patch[insn.word(1)] = 1; |
| 669 | } |
| 670 | |
| 671 | if (insn.word(2) == spv::DecorationRelaxedPrecision) { |
| 672 | var_relaxed_precision[insn.word(1)] = 1; |
| 673 | } |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | // TODO: handle grouped decorations |
| 678 | // TODO: handle index=1 dual source outputs from FS -- two vars will have the same location, and we DON'T want to clobber. |
| 679 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 680 | std::map<location_t, interface_var> out; |
| 681 | |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 682 | for (uint32_t word : FindEntrypointInterfaces(entrypoint)) { |
| 683 | auto insn = src->get_def(word); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 684 | assert(insn != src->end()); |
| 685 | assert(insn.opcode() == spv::OpVariable); |
| 686 | |
| 687 | if (insn.word(3) == static_cast<uint32_t>(sinterface)) { |
| 688 | unsigned id = insn.word(2); |
| 689 | unsigned type = insn.word(1); |
| 690 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 691 | int location = ValueOrDefault(var_locations, id, static_cast<unsigned>(-1)); |
| 692 | int builtin = ValueOrDefault(var_builtins, id, static_cast<unsigned>(-1)); |
| 693 | unsigned component = ValueOrDefault(var_components, id, 0); // Unspecified is OK, is 0 |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 694 | bool is_patch = var_patch.find(id) != var_patch.end(); |
| 695 | bool is_relaxed_precision = var_relaxed_precision.find(id) != var_relaxed_precision.end(); |
| 696 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 697 | if (builtin != -1) |
| 698 | continue; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 699 | else if (!CollectInterfaceBlockMembers(src, &out, blocks, is_array_of_verts, id, type, is_patch, location)) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 700 | // A user-defined interface variable, with a location. Where a variable occupied multiple locations, emit |
| 701 | // one result for each. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 702 | unsigned num_locations = GetLocationsConsumedByType(src, type, is_array_of_verts && !is_patch); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 703 | for (unsigned int offset = 0; offset < num_locations; offset++) { |
| 704 | interface_var v = {}; |
| 705 | v.id = id; |
| 706 | v.type_id = type; |
| 707 | v.offset = offset; |
| 708 | v.is_patch = is_patch; |
| 709 | v.is_relaxed_precision = is_relaxed_precision; |
| 710 | out[std::make_pair(location + offset, component)] = v; |
| 711 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
| 716 | return out; |
| 717 | } |
| 718 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 719 | static std::vector<uint32_t> CollectBuiltinBlockMembers(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint, |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 720 | uint32_t storageClass) { |
| 721 | std::vector<uint32_t> variables; |
| 722 | std::vector<uint32_t> builtinStructMembers; |
| 723 | std::vector<uint32_t> builtinDecorations; |
| 724 | |
| 725 | for (auto insn : *src) { |
| 726 | switch (insn.opcode()) { |
| 727 | // Find all built-in member decorations |
| 728 | case spv::OpMemberDecorate: |
| 729 | if (insn.word(3) == spv::DecorationBuiltIn) { |
| 730 | builtinStructMembers.push_back(insn.word(1)); |
| 731 | } |
| 732 | break; |
| 733 | // Find all built-in decorations |
| 734 | case spv::OpDecorate: |
| 735 | switch (insn.word(2)) { |
| 736 | case spv::DecorationBlock: { |
| 737 | uint32_t blockID = insn.word(1); |
| 738 | for (auto builtInBlockID : builtinStructMembers) { |
| 739 | // Check if one of the members of the block are built-in -> the block is built-in |
| 740 | if (blockID == builtInBlockID) { |
| 741 | builtinDecorations.push_back(blockID); |
| 742 | break; |
| 743 | } |
| 744 | } |
| 745 | break; |
| 746 | } |
| 747 | case spv::DecorationBuiltIn: |
| 748 | builtinDecorations.push_back(insn.word(1)); |
| 749 | break; |
| 750 | default: |
| 751 | break; |
| 752 | } |
| 753 | break; |
| 754 | default: |
| 755 | break; |
| 756 | } |
| 757 | } |
| 758 | |
| 759 | // Find all interface variables belonging to the entrypoint and matching the storage class |
| 760 | for (uint32_t id : FindEntrypointInterfaces(entrypoint)) { |
| 761 | auto def = src->get_def(id); |
| 762 | assert(def != src->end()); |
| 763 | assert(def.opcode() == spv::OpVariable); |
| 764 | |
| 765 | if (def.word(3) == storageClass) variables.push_back(def.word(1)); |
| 766 | } |
| 767 | |
| 768 | // Find all members belonging to the builtin block selected |
| 769 | std::vector<uint32_t> builtinBlockMembers; |
| 770 | for (auto &var : variables) { |
| 771 | auto def = src->get_def(src->get_def(var).word(3)); |
| 772 | |
| 773 | // It could be an array of IO blocks. The element type should be the struct defining the block contents |
| 774 | if (def.opcode() == spv::OpTypeArray) def = src->get_def(def.word(2)); |
| 775 | |
| 776 | // Now find all members belonging to the struct defining the IO block |
| 777 | if (def.opcode() == spv::OpTypeStruct) { |
| 778 | for (auto builtInID : builtinDecorations) { |
| 779 | if (builtInID == def.word(1)) { |
| 780 | for (int i = 2; i < (int)def.len(); i++) |
| 781 | builtinBlockMembers.push_back(spv::BuiltInMax); // Start with undefined builtin for each struct member. |
| 782 | // These shouldn't be left after replacing. |
| 783 | for (auto insn : *src) { |
| 784 | if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == builtInID && |
| 785 | insn.word(3) == spv::DecorationBuiltIn) { |
| 786 | auto structIndex = insn.word(2); |
| 787 | assert(structIndex < builtinBlockMembers.size()); |
| 788 | builtinBlockMembers[structIndex] = insn.word(4); |
| 789 | } |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | return builtinBlockMembers; |
| 797 | } |
| 798 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 799 | static std::vector<std::pair<uint32_t, interface_var>> CollectInterfaceByInputAttachmentIndex( |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 800 | SHADER_MODULE_STATE const *src, std::unordered_set<uint32_t> const &accessible_ids) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 801 | std::vector<std::pair<uint32_t, interface_var>> out; |
| 802 | |
| 803 | for (auto insn : *src) { |
| 804 | if (insn.opcode() == spv::OpDecorate) { |
| 805 | if (insn.word(2) == spv::DecorationInputAttachmentIndex) { |
| 806 | auto attachment_index = insn.word(3); |
| 807 | auto id = insn.word(1); |
| 808 | |
| 809 | if (accessible_ids.count(id)) { |
| 810 | auto def = src->get_def(id); |
| 811 | assert(def != src->end()); |
| 812 | |
| 813 | if (def.opcode() == spv::OpVariable && insn.word(3) == spv::StorageClassUniformConstant) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 814 | auto num_locations = GetLocationsConsumedByType(src, def.word(1), false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 815 | for (unsigned int offset = 0; offset < num_locations; offset++) { |
| 816 | interface_var v = {}; |
| 817 | v.id = id; |
| 818 | v.type_id = def.word(1); |
| 819 | v.offset = offset; |
| 820 | out.emplace_back(attachment_index + offset, v); |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | return out; |
| 829 | } |
| 830 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 831 | static bool IsWritableDescriptorType(SHADER_MODULE_STATE const *module, uint32_t type_id, bool is_storage_buffer) { |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 832 | auto type = module->get_def(type_id); |
| 833 | |
| 834 | // Strip off any array or ptrs. Where we remove array levels, adjust the descriptor count for each dimension. |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 835 | while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray) { |
| 836 | if (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypeRuntimeArray) { |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 837 | type = module->get_def(type.word(2)); // Element type |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 838 | } else { |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 839 | type = module->get_def(type.word(3)); // Pointee type |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
| 843 | switch (type.opcode()) { |
| 844 | case spv::OpTypeImage: { |
| 845 | auto dim = type.word(3); |
| 846 | auto sampled = type.word(7); |
| 847 | return sampled == 2 && dim != spv::DimSubpassData; |
| 848 | } |
| 849 | |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 850 | case spv::OpTypeStruct: { |
| 851 | std::unordered_set<unsigned> nonwritable_members; |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 852 | for (auto insn : *module) { |
| 853 | if (insn.opcode() == spv::OpDecorate && insn.word(1) == type.word(1)) { |
| 854 | if (insn.word(2) == spv::DecorationBufferBlock) { |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 855 | // Legacy storage block in the Uniform storage class |
| 856 | // has its struct type decorated with BufferBlock. |
| 857 | is_storage_buffer = true; |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 858 | } |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 859 | } else if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1) && |
| 860 | insn.word(3) == spv::DecorationNonWritable) { |
| 861 | nonwritable_members.insert(insn.word(2)); |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 862 | } |
| 863 | } |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 864 | |
| 865 | // A buffer is writable if it's either flavor of storage buffer, and has any member not decorated |
| 866 | // as nonwritable. |
| 867 | return is_storage_buffer && nonwritable_members.size() != type.len() - 2; |
| 868 | } |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | return false; |
| 872 | } |
| 873 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 874 | static std::vector<std::pair<descriptor_slot_t, interface_var>> CollectInterfaceByDescriptorSlot( |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 875 | debug_report_data const *report_data, SHADER_MODULE_STATE const *src, std::unordered_set<uint32_t> const &accessible_ids, |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 876 | bool *has_writable_descriptor) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 877 | std::unordered_map<unsigned, unsigned> var_sets; |
| 878 | std::unordered_map<unsigned, unsigned> var_bindings; |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 879 | std::unordered_map<unsigned, unsigned> var_nonwritable; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 880 | |
| 881 | for (auto insn : *src) { |
| 882 | // All variables in the Uniform or UniformConstant storage classes are required to be decorated with both |
| 883 | // DecorationDescriptorSet and DecorationBinding. |
| 884 | if (insn.opcode() == spv::OpDecorate) { |
| 885 | if (insn.word(2) == spv::DecorationDescriptorSet) { |
| 886 | var_sets[insn.word(1)] = insn.word(3); |
| 887 | } |
| 888 | |
| 889 | if (insn.word(2) == spv::DecorationBinding) { |
| 890 | var_bindings[insn.word(1)] = insn.word(3); |
| 891 | } |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 892 | |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 893 | // Note: do toplevel DecorationNonWritable out here; it applies to |
| 894 | // the OpVariable rather than the type. |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 895 | if (insn.word(2) == spv::DecorationNonWritable) { |
| 896 | var_nonwritable[insn.word(1)] = 1; |
| 897 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | |
| 901 | std::vector<std::pair<descriptor_slot_t, interface_var>> out; |
| 902 | |
| 903 | for (auto id : accessible_ids) { |
| 904 | auto insn = src->get_def(id); |
| 905 | assert(insn != src->end()); |
| 906 | |
| 907 | if (insn.opcode() == spv::OpVariable && |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 908 | (insn.word(3) == spv::StorageClassUniform || insn.word(3) == spv::StorageClassUniformConstant || |
| 909 | insn.word(3) == spv::StorageClassStorageBuffer)) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 910 | unsigned set = ValueOrDefault(var_sets, insn.word(2), 0); |
| 911 | unsigned binding = ValueOrDefault(var_bindings, insn.word(2), 0); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 912 | |
| 913 | interface_var v = {}; |
| 914 | v.id = insn.word(2); |
| 915 | v.type_id = insn.word(1); |
| 916 | out.emplace_back(std::make_pair(set, binding), v); |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 917 | |
Chris Forbes | 8d31e5d | 2018-10-08 17:19:15 -0700 | [diff] [blame] | 918 | if (var_nonwritable.find(id) == var_nonwritable.end() && |
| 919 | IsWritableDescriptorType(src, insn.word(1), insn.word(3) == spv::StorageClassStorageBuffer)) { |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 920 | *has_writable_descriptor = true; |
| 921 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 922 | } |
| 923 | } |
| 924 | |
| 925 | return out; |
| 926 | } |
| 927 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 928 | static bool ValidateViConsistency(debug_report_data const *report_data, VkPipelineVertexInputStateCreateInfo const *vi) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 929 | // Walk the binding descriptions, which describe the step rate and stride of each vertex buffer. Each binding should |
| 930 | // be specified only once. |
| 931 | std::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings; |
| 932 | bool skip = false; |
| 933 | |
| 934 | for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) { |
| 935 | auto desc = &vi->pVertexBindingDescriptions[i]; |
| 936 | auto &binding = bindings[desc->binding]; |
| 937 | if (binding) { |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 938 | // TODO: "VUID-VkGraphicsPipelineCreateInfo-pStages-00742" perhaps? |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 939 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 940 | kVUID_Core_Shader_InconsistentVi, "Duplicate vertex input binding descriptions for binding %d", |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 941 | desc->binding); |
| 942 | } else { |
| 943 | binding = desc; |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | return skip; |
| 948 | } |
| 949 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 950 | static bool ValidateViAgainstVsInputs(debug_report_data const *report_data, VkPipelineVertexInputStateCreateInfo const *vi, |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 951 | SHADER_MODULE_STATE const *vs, spirv_inst_iter entrypoint) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 952 | bool skip = false; |
| 953 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 954 | auto inputs = CollectInterfaceByLocation(vs, entrypoint, spv::StorageClassInput, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 955 | |
| 956 | // Build index by location |
| 957 | std::map<uint32_t, VkVertexInputAttributeDescription const *> attribs; |
| 958 | if (vi) { |
| 959 | for (unsigned i = 0; i < vi->vertexAttributeDescriptionCount; i++) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 960 | auto num_locations = GetLocationsConsumedByFormat(vi->pVertexAttributeDescriptions[i].format); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 961 | for (auto j = 0u; j < num_locations; j++) { |
| 962 | attribs[vi->pVertexAttributeDescriptions[i].location + j] = &vi->pVertexAttributeDescriptions[i]; |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | auto it_a = attribs.begin(); |
| 968 | auto it_b = inputs.begin(); |
| 969 | bool used = false; |
| 970 | |
| 971 | while ((attribs.size() > 0 && it_a != attribs.end()) || (inputs.size() > 0 && it_b != inputs.end())) { |
| 972 | bool a_at_end = attribs.size() == 0 || it_a == attribs.end(); |
| 973 | bool b_at_end = inputs.size() == 0 || it_b == inputs.end(); |
| 974 | auto a_first = a_at_end ? 0 : it_a->first; |
| 975 | auto b_first = b_at_end ? 0 : it_b->first.first; |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 976 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 977 | if (!a_at_end && (b_at_end || a_first < b_first)) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 978 | if (!used && |
| 979 | log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 980 | HandleToUint64(vs->vk_shader_module), kVUID_Core_Shader_OutputNotConsumed, |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 981 | "Vertex attribute at location %d not consumed by vertex shader", a_first)) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 982 | skip = true; |
| 983 | } |
| 984 | used = false; |
| 985 | it_a++; |
| 986 | } else if (!b_at_end && (a_at_end || b_first < a_first)) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 987 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 988 | HandleToUint64(vs->vk_shader_module), kVUID_Core_Shader_InputNotProduced, |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 989 | "Vertex shader consumes input at location %d but not provided", b_first); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 990 | it_b++; |
| 991 | } else { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 992 | unsigned attrib_type = GetFormatType(it_a->second->format); |
| 993 | unsigned input_type = GetFundamentalType(vs, it_b->second.type_id); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 994 | |
| 995 | // Type checking |
| 996 | if (!(attrib_type & input_type)) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 997 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 998 | HandleToUint64(vs->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 999 | "Attribute type of `%s` at location %d does not match vertex shader input type of `%s`", |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1000 | string_VkFormat(it_a->second->format), a_first, DescribeType(vs, it_b->second.type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | // OK! |
| 1004 | used = true; |
| 1005 | it_b++; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | return skip; |
| 1010 | } |
| 1011 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1012 | static bool ValidateFsOutputsAgainstRenderPass(debug_report_data const *report_data, SHADER_MODULE_STATE const *fs, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1013 | spirv_inst_iter entrypoint, PIPELINE_STATE const *pipeline, uint32_t subpass_index) { |
Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 1014 | auto rpci = pipeline->rp_state->createInfo.ptr(); |
Chris Forbes | 8bca165 | 2017-07-20 11:10:09 -0700 | [diff] [blame] | 1015 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1016 | std::map<uint32_t, VkFormat> color_attachments; |
| 1017 | auto subpass = rpci->pSubpasses[subpass_index]; |
| 1018 | for (auto i = 0u; i < subpass.colorAttachmentCount; ++i) { |
| 1019 | uint32_t attachment = subpass.pColorAttachments[i].attachment; |
| 1020 | if (attachment == VK_ATTACHMENT_UNUSED) continue; |
| 1021 | if (rpci->pAttachments[attachment].format != VK_FORMAT_UNDEFINED) { |
| 1022 | color_attachments[i] = rpci->pAttachments[attachment].format; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | bool skip = false; |
| 1027 | |
| 1028 | // TODO: dual source blend index (spv::DecIndex, zero if not provided) |
| 1029 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1030 | auto outputs = CollectInterfaceByLocation(fs, entrypoint, spv::StorageClassOutput, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1031 | |
| 1032 | auto it_a = outputs.begin(); |
| 1033 | auto it_b = color_attachments.begin(); |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1034 | bool used = false; |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 1035 | bool alphaToCoverageEnabled = pipeline->graphicsPipelineCI.pMultisampleState != NULL && |
| 1036 | pipeline->graphicsPipelineCI.pMultisampleState->alphaToCoverageEnable == VK_TRUE; |
| 1037 | bool locationZeroHasAlpha = false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1038 | |
| 1039 | // Walk attachment list and outputs together |
| 1040 | |
| 1041 | while ((outputs.size() > 0 && it_a != outputs.end()) || (color_attachments.size() > 0 && it_b != color_attachments.end())) { |
| 1042 | bool a_at_end = outputs.size() == 0 || it_a == outputs.end(); |
| 1043 | bool b_at_end = color_attachments.size() == 0 || it_b == color_attachments.end(); |
| 1044 | |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 1045 | if (!a_at_end && it_a->first.first == 0 && fs->get_def(it_a->second.type_id) != fs->end() && |
| 1046 | GetComponentsConsumedByType(fs, it_a->second.type_id, false) == 4) |
| 1047 | locationZeroHasAlpha = true; |
| 1048 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1049 | if (!a_at_end && (b_at_end || it_a->first.first < it_b->first)) { |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 1050 | if (!alphaToCoverageEnabled || it_a->first.first != 0) { |
| 1051 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 1052 | HandleToUint64(fs->vk_shader_module), kVUID_Core_Shader_OutputNotConsumed, |
| 1053 | "fragment shader writes to output location %d with no matching attachment", it_a->first.first); |
| 1054 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1055 | it_a++; |
| 1056 | } else if (!b_at_end && (a_at_end || it_a->first.first > it_b->first)) { |
Chris Forbes | efdd408 | 2017-07-20 11:19:16 -0700 | [diff] [blame] | 1057 | // Only complain if there are unmasked channels for this attachment. If the writemask is 0, it's acceptable for the |
| 1058 | // shader to not produce a matching output. |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1059 | if (!used) { |
| 1060 | if (pipeline->attachments[it_b->first].colorWriteMask != 0) { |
Chris Forbes | cfe4dca | 2018-10-05 10:15:00 -0700 | [diff] [blame] | 1061 | skip |= log_msg(report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1062 | HandleToUint64(fs->vk_shader_module), kVUID_Core_Shader_InputNotProduced, |
Chris Forbes | cfe4dca | 2018-10-05 10:15:00 -0700 | [diff] [blame] | 1063 | "Attachment %d not written by fragment shader; undefined values will be written to attachment", |
| 1064 | it_b->first); |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1065 | } |
Chris Forbes | efdd408 | 2017-07-20 11:19:16 -0700 | [diff] [blame] | 1066 | } |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1067 | used = false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1068 | it_b++; |
| 1069 | } else { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1070 | unsigned output_type = GetFundamentalType(fs, it_a->second.type_id); |
| 1071 | unsigned att_type = GetFormatType(it_b->second); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1072 | |
| 1073 | // Type checking |
| 1074 | if (!(output_type & att_type)) { |
Chris Forbes | cfe4dca | 2018-10-05 10:15:00 -0700 | [diff] [blame] | 1075 | skip |= log_msg( |
| 1076 | report_data, VK_DEBUG_REPORT_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 1077 | HandleToUint64(fs->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
| 1078 | "Attachment %d of type `%s` does not match fragment shader output type of `%s`; resulting values are undefined", |
| 1079 | it_b->first, string_VkFormat(it_b->second), DescribeType(fs, it_a->second.type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | // OK! |
| 1083 | it_a++; |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 1084 | used = true; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1085 | } |
| 1086 | } |
| 1087 | |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 1088 | if (alphaToCoverageEnabled && !locationZeroHasAlpha) { |
| 1089 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 1090 | HandleToUint64(fs->vk_shader_module), kVUID_Core_Shader_NoAlphaAtLocation0WithAlphaToCoverage, |
| 1091 | "fragment shader doesn't declare alpha output at location 0 even though alpha to coverage is enabled."); |
| 1092 | } |
| 1093 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1094 | return skip; |
| 1095 | } |
| 1096 | |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1097 | // For PointSize analysis we need to know if the variable decorated with the PointSize built-in was actually written to. |
| 1098 | // This function examines instructions in the static call tree for a write to this variable. |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1099 | static bool IsPointSizeWritten(SHADER_MODULE_STATE const *src, spirv_inst_iter builtin_instr, spirv_inst_iter entrypoint) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1100 | auto type = builtin_instr.opcode(); |
| 1101 | uint32_t target_id = builtin_instr.word(1); |
| 1102 | bool init_complete = false; |
| 1103 | |
| 1104 | if (type == spv::OpMemberDecorate) { |
| 1105 | // Built-in is part of a structure -- examine instructions up to first function body to get initial IDs |
| 1106 | auto insn = entrypoint; |
| 1107 | while (!init_complete && (insn.opcode() != spv::OpFunction)) { |
| 1108 | switch (insn.opcode()) { |
| 1109 | case spv::OpTypePointer: |
| 1110 | if ((insn.word(3) == target_id) && (insn.word(2) == spv::StorageClassOutput)) { |
| 1111 | target_id = insn.word(1); |
| 1112 | } |
| 1113 | break; |
| 1114 | case spv::OpVariable: |
| 1115 | if (insn.word(1) == target_id) { |
| 1116 | target_id = insn.word(2); |
| 1117 | init_complete = true; |
| 1118 | } |
| 1119 | break; |
| 1120 | } |
| 1121 | insn++; |
| 1122 | } |
| 1123 | } |
| 1124 | |
Mark Lobodzinski | f84b0b4 | 2018-09-11 14:54:32 -0600 | [diff] [blame] | 1125 | if (!init_complete && (type == spv::OpMemberDecorate)) return false; |
| 1126 | |
| 1127 | bool found_write = false; |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1128 | std::unordered_set<uint32_t> worklist; |
| 1129 | worklist.insert(entrypoint.word(2)); |
| 1130 | |
| 1131 | // Follow instructions in call graph looking for writes to target |
| 1132 | while (!worklist.empty() && !found_write) { |
| 1133 | auto id_iter = worklist.begin(); |
| 1134 | auto id = *id_iter; |
| 1135 | worklist.erase(id_iter); |
| 1136 | |
| 1137 | auto insn = src->get_def(id); |
| 1138 | if (insn == src->end()) { |
| 1139 | continue; |
| 1140 | } |
| 1141 | |
| 1142 | if (insn.opcode() == spv::OpFunction) { |
| 1143 | // Scan body of function looking for other function calls or items in our ID chain |
| 1144 | while (++insn, insn.opcode() != spv::OpFunctionEnd) { |
| 1145 | switch (insn.opcode()) { |
| 1146 | case spv::OpAccessChain: |
| 1147 | if (insn.word(3) == target_id) { |
| 1148 | if (type == spv::OpMemberDecorate) { |
| 1149 | auto value = GetConstantValue(src, insn.word(4)); |
| 1150 | if (value == builtin_instr.word(2)) { |
| 1151 | target_id = insn.word(2); |
| 1152 | } |
| 1153 | } else { |
| 1154 | target_id = insn.word(2); |
| 1155 | } |
| 1156 | } |
| 1157 | break; |
| 1158 | case spv::OpStore: |
| 1159 | if (insn.word(1) == target_id) { |
| 1160 | found_write = true; |
| 1161 | } |
| 1162 | break; |
| 1163 | case spv::OpFunctionCall: |
| 1164 | worklist.insert(insn.word(3)); |
| 1165 | break; |
| 1166 | } |
| 1167 | } |
| 1168 | } |
| 1169 | } |
| 1170 | return found_write; |
| 1171 | } |
| 1172 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1173 | // For some analyses, we need to know about all ids referenced by the static call tree of a particular entrypoint. This is |
| 1174 | // important for identifying the set of shader resources actually used by an entrypoint, for example. |
| 1175 | // Note: we only explore parts of the image which might actually contain ids we care about for the above analyses. |
| 1176 | // - NOT the shader input/output interfaces. |
| 1177 | // |
| 1178 | // TODO: The set of interesting opcodes here was determined by eyeballing the SPIRV spec. It might be worth |
| 1179 | // converting parts of this to be generated from the machine-readable spec instead. |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1180 | static std::unordered_set<uint32_t> MarkAccessibleIds(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1181 | std::unordered_set<uint32_t> ids; |
| 1182 | std::unordered_set<uint32_t> worklist; |
| 1183 | worklist.insert(entrypoint.word(2)); |
| 1184 | |
| 1185 | while (!worklist.empty()) { |
| 1186 | auto id_iter = worklist.begin(); |
| 1187 | auto id = *id_iter; |
| 1188 | worklist.erase(id_iter); |
| 1189 | |
| 1190 | auto insn = src->get_def(id); |
| 1191 | if (insn == src->end()) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1192 | // ID is something we didn't collect in BuildDefIndex. that's OK -- we'll stumble across all kinds of things here |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1193 | // that we may not care about. |
| 1194 | continue; |
| 1195 | } |
| 1196 | |
| 1197 | // Try to add to the output set |
| 1198 | if (!ids.insert(id).second) { |
| 1199 | continue; // If we already saw this id, we don't want to walk it again. |
| 1200 | } |
| 1201 | |
| 1202 | switch (insn.opcode()) { |
| 1203 | case spv::OpFunction: |
| 1204 | // Scan whole body of the function, enlisting anything interesting |
| 1205 | while (++insn, insn.opcode() != spv::OpFunctionEnd) { |
| 1206 | switch (insn.opcode()) { |
| 1207 | case spv::OpLoad: |
| 1208 | case spv::OpAtomicLoad: |
| 1209 | case spv::OpAtomicExchange: |
| 1210 | case spv::OpAtomicCompareExchange: |
| 1211 | case spv::OpAtomicCompareExchangeWeak: |
| 1212 | case spv::OpAtomicIIncrement: |
| 1213 | case spv::OpAtomicIDecrement: |
| 1214 | case spv::OpAtomicIAdd: |
| 1215 | case spv::OpAtomicISub: |
| 1216 | case spv::OpAtomicSMin: |
| 1217 | case spv::OpAtomicUMin: |
| 1218 | case spv::OpAtomicSMax: |
| 1219 | case spv::OpAtomicUMax: |
| 1220 | case spv::OpAtomicAnd: |
| 1221 | case spv::OpAtomicOr: |
| 1222 | case spv::OpAtomicXor: |
| 1223 | worklist.insert(insn.word(3)); // ptr |
| 1224 | break; |
| 1225 | case spv::OpStore: |
| 1226 | case spv::OpAtomicStore: |
| 1227 | worklist.insert(insn.word(1)); // ptr |
| 1228 | break; |
| 1229 | case spv::OpAccessChain: |
| 1230 | case spv::OpInBoundsAccessChain: |
| 1231 | worklist.insert(insn.word(3)); // base ptr |
| 1232 | break; |
| 1233 | case spv::OpSampledImage: |
| 1234 | case spv::OpImageSampleImplicitLod: |
| 1235 | case spv::OpImageSampleExplicitLod: |
| 1236 | case spv::OpImageSampleDrefImplicitLod: |
| 1237 | case spv::OpImageSampleDrefExplicitLod: |
| 1238 | case spv::OpImageSampleProjImplicitLod: |
| 1239 | case spv::OpImageSampleProjExplicitLod: |
| 1240 | case spv::OpImageSampleProjDrefImplicitLod: |
| 1241 | case spv::OpImageSampleProjDrefExplicitLod: |
| 1242 | case spv::OpImageFetch: |
| 1243 | case spv::OpImageGather: |
| 1244 | case spv::OpImageDrefGather: |
| 1245 | case spv::OpImageRead: |
| 1246 | case spv::OpImage: |
| 1247 | case spv::OpImageQueryFormat: |
| 1248 | case spv::OpImageQueryOrder: |
| 1249 | case spv::OpImageQuerySizeLod: |
| 1250 | case spv::OpImageQuerySize: |
| 1251 | case spv::OpImageQueryLod: |
| 1252 | case spv::OpImageQueryLevels: |
| 1253 | case spv::OpImageQuerySamples: |
| 1254 | case spv::OpImageSparseSampleImplicitLod: |
| 1255 | case spv::OpImageSparseSampleExplicitLod: |
| 1256 | case spv::OpImageSparseSampleDrefImplicitLod: |
| 1257 | case spv::OpImageSparseSampleDrefExplicitLod: |
| 1258 | case spv::OpImageSparseSampleProjImplicitLod: |
| 1259 | case spv::OpImageSparseSampleProjExplicitLod: |
| 1260 | case spv::OpImageSparseSampleProjDrefImplicitLod: |
| 1261 | case spv::OpImageSparseSampleProjDrefExplicitLod: |
| 1262 | case spv::OpImageSparseFetch: |
| 1263 | case spv::OpImageSparseGather: |
| 1264 | case spv::OpImageSparseDrefGather: |
| 1265 | case spv::OpImageTexelPointer: |
| 1266 | worklist.insert(insn.word(3)); // Image or sampled image |
| 1267 | break; |
| 1268 | case spv::OpImageWrite: |
| 1269 | worklist.insert(insn.word(1)); // Image -- different operand order to above |
| 1270 | break; |
| 1271 | case spv::OpFunctionCall: |
| 1272 | for (uint32_t i = 3; i < insn.len(); i++) { |
| 1273 | worklist.insert(insn.word(i)); // fn itself, and all args |
| 1274 | } |
| 1275 | break; |
| 1276 | |
| 1277 | case spv::OpExtInst: |
| 1278 | for (uint32_t i = 5; i < insn.len(); i++) { |
| 1279 | worklist.insert(insn.word(i)); // Operands to ext inst |
| 1280 | } |
| 1281 | break; |
| 1282 | } |
| 1283 | } |
| 1284 | break; |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | return ids; |
| 1289 | } |
| 1290 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1291 | static bool ValidatePushConstantBlockAgainstPipeline(debug_report_data const *report_data, |
| 1292 | std::vector<VkPushConstantRange> const *push_constant_ranges, |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1293 | SHADER_MODULE_STATE const *src, spirv_inst_iter type, |
| 1294 | VkShaderStageFlagBits stage) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1295 | bool skip = false; |
| 1296 | |
| 1297 | // Strip off ptrs etc |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1298 | type = GetStructType(src, type, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1299 | assert(type != src->end()); |
| 1300 | |
| 1301 | // Validate directly off the offsets. this isn't quite correct for arrays and matrices, but is a good first step. |
| 1302 | // TODO: arrays, matrices, weird sizes |
| 1303 | for (auto insn : *src) { |
| 1304 | if (insn.opcode() == spv::OpMemberDecorate && insn.word(1) == type.word(1)) { |
| 1305 | if (insn.word(3) == spv::DecorationOffset) { |
| 1306 | unsigned offset = insn.word(4); |
| 1307 | auto size = 4; // Bytes; TODO: calculate this based on the type |
| 1308 | |
| 1309 | bool found_range = false; |
| 1310 | for (auto const &range : *push_constant_ranges) { |
| 1311 | if (range.offset <= offset && range.offset + range.size >= offset + size) { |
| 1312 | found_range = true; |
| 1313 | |
| 1314 | if ((range.stageFlags & stage) == 0) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1315 | skip |= |
| 1316 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1317 | kVUID_Core_Shader_PushConstantNotAccessibleFromStage, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1318 | "Push constant range covering variable starting at offset %u not accessible from stage %s", |
| 1319 | offset, string_VkShaderStageFlagBits(stage)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | break; |
| 1323 | } |
| 1324 | } |
| 1325 | |
| 1326 | if (!found_range) { |
| 1327 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1328 | kVUID_Core_Shader_PushConstantOutOfRange, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1329 | "Push constant range covering variable starting at offset %u not declared in layout", offset); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1330 | } |
| 1331 | } |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | return skip; |
| 1336 | } |
| 1337 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1338 | static bool ValidatePushConstantUsage(debug_report_data const *report_data, |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1339 | std::vector<VkPushConstantRange> const *push_constant_ranges, SHADER_MODULE_STATE const *src, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1340 | std::unordered_set<uint32_t> accessible_ids, VkShaderStageFlagBits stage) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1341 | bool skip = false; |
| 1342 | |
| 1343 | for (auto id : accessible_ids) { |
| 1344 | auto def_insn = src->get_def(id); |
| 1345 | if (def_insn.opcode() == spv::OpVariable && def_insn.word(3) == spv::StorageClassPushConstant) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1346 | skip |= ValidatePushConstantBlockAgainstPipeline(report_data, push_constant_ranges, src, src->get_def(def_insn.word(1)), |
| 1347 | stage); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | |
| 1351 | return skip; |
| 1352 | } |
| 1353 | |
| 1354 | // Validate that data for each specialization entry is fully contained within the buffer. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1355 | static bool ValidateSpecializationOffsets(debug_report_data const *report_data, VkPipelineShaderStageCreateInfo const *info) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1356 | bool skip = false; |
| 1357 | |
| 1358 | VkSpecializationInfo const *spec = info->pSpecializationInfo; |
| 1359 | |
| 1360 | if (spec) { |
| 1361 | for (auto i = 0u; i < spec->mapEntryCount; i++) { |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 1362 | // TODO: This is a good place for "VUID-VkSpecializationInfo-offset-00773". |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1363 | if (spec->pMapEntries[i].offset + spec->pMapEntries[i].size > spec->dataSize) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1364 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, 0, |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 1365 | "VUID-VkSpecializationInfo-pMapEntries-00774", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1366 | "Specialization entry %u (for constant id %u) references memory outside provided specialization " |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1367 | "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided)..", |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 1368 | i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset, |
Mark Lobodzinski | 487a0d1 | 2018-03-30 10:09:03 -0600 | [diff] [blame] | 1369 | spec->pMapEntries[i].offset + spec->pMapEntries[i].size - 1, spec->dataSize); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1370 | } |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | return skip; |
| 1375 | } |
| 1376 | |
Jeff Bolz | 38b3ce7 | 2018-09-19 12:53:38 -0500 | [diff] [blame] | 1377 | // TODO (jbolz): Can this return a const reference? |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1378 | static std::set<uint32_t> TypeToDescriptorTypeSet(SHADER_MODULE_STATE const *module, uint32_t type_id, unsigned &descriptor_count) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1379 | auto type = module->get_def(type_id); |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 1380 | bool is_storage_buffer = false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1381 | descriptor_count = 1; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1382 | std::set<uint32_t> ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1383 | |
| 1384 | // Strip off any array or ptrs. Where we remove array levels, adjust the descriptor count for each dimension. |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1385 | while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray) { |
| 1386 | if (type.opcode() == spv::OpTypeRuntimeArray) { |
| 1387 | descriptor_count = 0; |
| 1388 | type = module->get_def(type.word(2)); |
| 1389 | } else if (type.opcode() == spv::OpTypeArray) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1390 | descriptor_count *= GetConstantValue(module, type.word(3)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1391 | type = module->get_def(type.word(2)); |
| 1392 | } else { |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 1393 | if (type.word(2) == spv::StorageClassStorageBuffer) { |
| 1394 | is_storage_buffer = true; |
| 1395 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1396 | type = module->get_def(type.word(3)); |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | switch (type.opcode()) { |
| 1401 | case spv::OpTypeStruct: { |
| 1402 | for (auto insn : *module) { |
| 1403 | if (insn.opcode() == spv::OpDecorate && insn.word(1) == type.word(1)) { |
| 1404 | if (insn.word(2) == spv::DecorationBlock) { |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 1405 | if (is_storage_buffer) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1406 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); |
| 1407 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC); |
| 1408 | return ret; |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 1409 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1410 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
| 1411 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC); |
| 1412 | ret.insert(VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT); |
| 1413 | return ret; |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 1414 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1415 | } else if (insn.word(2) == spv::DecorationBufferBlock) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1416 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); |
| 1417 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC); |
| 1418 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | // Invalid |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1424 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | case spv::OpTypeSampler: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1428 | ret.insert(VK_DESCRIPTOR_TYPE_SAMPLER); |
| 1429 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 1430 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1431 | |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 1432 | case spv::OpTypeSampledImage: { |
| 1433 | // Slight relaxation for some GLSL historical madness: samplerBuffer doesn't really have a sampler, and a texel |
| 1434 | // buffer descriptor doesn't really provide one. Allow this slight mismatch. |
| 1435 | auto image_type = module->get_def(type.word(2)); |
| 1436 | auto dim = image_type.word(3); |
| 1437 | auto sampled = image_type.word(7); |
| 1438 | if (dim == spv::DimBuffer && sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1439 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER); |
| 1440 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1441 | } |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 1442 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1443 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 1444 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1445 | |
| 1446 | case spv::OpTypeImage: { |
| 1447 | // Many descriptor types backing image types-- depends on dimension and whether the image will be used with a sampler. |
| 1448 | // SPIRV for Vulkan requires that sampled be 1 or 2 -- leaving the decision to runtime is unacceptable. |
| 1449 | auto dim = type.word(3); |
| 1450 | auto sampled = type.word(7); |
| 1451 | |
| 1452 | if (dim == spv::DimSubpassData) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1453 | ret.insert(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT); |
| 1454 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1455 | } else if (dim == spv::DimBuffer) { |
| 1456 | if (sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1457 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER); |
| 1458 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1459 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1460 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER); |
| 1461 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1462 | } |
| 1463 | } else if (sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1464 | ret.insert(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); |
| 1465 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 1466 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1467 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1468 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE); |
| 1469 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1470 | } |
| 1471 | } |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 1472 | case spv::OpTypeAccelerationStructureNV: |
Eric Werness | 30127fd | 2018-10-31 21:01:03 -0700 | [diff] [blame] | 1473 | ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV); |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 1474 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1475 | |
| 1476 | // We shouldn't really see any other junk types -- but if we do, they're a mismatch. |
| 1477 | default: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1478 | return ret; // Matches nothing |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1482 | static std::string string_descriptorTypes(const std::set<uint32_t> &descriptor_types) { |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 1483 | std::stringstream ss; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 1484 | for (auto it = descriptor_types.begin(); it != descriptor_types.end(); ++it) { |
| 1485 | if (ss.tellp()) ss << ", "; |
| 1486 | ss << string_VkDescriptorType(VkDescriptorType(*it)); |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 1487 | } |
| 1488 | return ss.str(); |
| 1489 | } |
| 1490 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1491 | static bool RequireFeature(debug_report_data const *report_data, VkBool32 feature, char const *feature_name) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1492 | if (!feature) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1493 | if (log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1494 | kVUID_Core_Shader_FeatureNotEnabled, "Shader requires %s but is not enabled on the device", feature_name)) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1495 | return true; |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | return false; |
| 1500 | } |
| 1501 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1502 | static bool RequireExtension(debug_report_data const *report_data, bool extension, char const *extension_name) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1503 | if (!extension) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 1504 | if (log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 1505 | kVUID_Core_Shader_FeatureNotEnabled, "Shader requires extension %s but is not enabled on the device", |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1506 | extension_name)) { |
| 1507 | return true; |
| 1508 | } |
| 1509 | } |
| 1510 | |
| 1511 | return false; |
| 1512 | } |
| 1513 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1514 | bool CoreChecks::ValidateShaderCapabilities(SHADER_MODULE_STATE const *src, VkShaderStageFlagBits stage, |
| 1515 | bool has_writable_descriptor) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1516 | bool skip = false; |
| 1517 | |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1518 | struct FeaturePointer { |
| 1519 | // Callable object to test if this feature is enabled in the given aggregate feature struct |
| 1520 | const std::function<VkBool32(const DeviceFeatures &)> IsEnabled; |
| 1521 | |
| 1522 | // Test if feature pointer is populated |
| 1523 | explicit operator bool() const { return static_cast<bool>(IsEnabled); } |
| 1524 | |
| 1525 | // Default and nullptr constructor to create an empty FeaturePointer |
| 1526 | FeaturePointer() : IsEnabled(nullptr) {} |
| 1527 | FeaturePointer(std::nullptr_t ptr) : IsEnabled(nullptr) {} |
| 1528 | |
| 1529 | // Constructors to populate FeaturePointer based on given pointer to member |
| 1530 | FeaturePointer(VkBool32 VkPhysicalDeviceFeatures::*ptr) |
| 1531 | : IsEnabled([=](const DeviceFeatures &features) { return features.core.*ptr; }) {} |
| 1532 | FeaturePointer(VkBool32 VkPhysicalDeviceDescriptorIndexingFeaturesEXT::*ptr) |
| 1533 | : IsEnabled([=](const DeviceFeatures &features) { return features.descriptor_indexing.*ptr; }) {} |
| 1534 | FeaturePointer(VkBool32 VkPhysicalDevice8BitStorageFeaturesKHR::*ptr) |
| 1535 | : IsEnabled([=](const DeviceFeatures &features) { return features.eight_bit_storage.*ptr; }) {} |
Brett Lawson | bebfb6f | 2018-10-23 16:58:50 -0700 | [diff] [blame] | 1536 | FeaturePointer(VkBool32 VkPhysicalDeviceTransformFeedbackFeaturesEXT::*ptr) |
| 1537 | : IsEnabled([=](const DeviceFeatures &features) { return features.transform_feedback_features.*ptr; }) {} |
Jose-Emilio Munoz-Lopez | 1109b45 | 2018-08-21 09:44:07 +0100 | [diff] [blame] | 1538 | FeaturePointer(VkBool32 VkPhysicalDeviceFloat16Int8FeaturesKHR::*ptr) |
| 1539 | : IsEnabled([=](const DeviceFeatures &features) { return features.float16_int8.*ptr; }) {} |
Tobias Hector | 6a0ece7 | 2018-12-10 12:24:05 +0000 | [diff] [blame] | 1540 | FeaturePointer(VkBool32 VkPhysicalDeviceScalarBlockLayoutFeaturesEXT::*ptr) |
| 1541 | : IsEnabled([=](const DeviceFeatures &features) { return features.scalar_block_layout_features.*ptr; }) {} |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1542 | FeaturePointer(VkBool32 VkPhysicalDeviceCooperativeMatrixFeaturesNV::*ptr) |
| 1543 | : IsEnabled([=](const DeviceFeatures &features) { return features.cooperative_matrix_features.*ptr; }) {} |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1544 | FeaturePointer(VkBool32 VkPhysicalDeviceFloatControlsPropertiesKHR::*ptr) |
| 1545 | : IsEnabled([=](const DeviceFeatures &features) { return features.float_controls.*ptr; }) {} |
Jason Macnak | c5a621d | 2019-06-10 12:42:50 -0700 | [diff] [blame] | 1546 | FeaturePointer(VkBool32 VkPhysicalDeviceComputeShaderDerivativesFeaturesNV::*ptr) |
| 1547 | : IsEnabled([=](const DeviceFeatures &features) { return features.compute_shader_derivatives_features.*ptr; }) {} |
Jason Macnak | 325e8b5 | 2019-06-10 13:33:10 -0700 | [diff] [blame] | 1548 | FeaturePointer(VkBool32 VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV::*ptr) |
| 1549 | : IsEnabled([=](const DeviceFeatures &features) { return features.fragment_shader_barycentric_features.*ptr; }) {} |
Jason Macnak | d7fddf8 | 2019-06-13 09:52:49 -0700 | [diff] [blame^] | 1550 | FeaturePointer(VkBool32 VkPhysicalDeviceShaderImageFootprintFeaturesNV::*ptr) |
| 1551 | : IsEnabled([=](const DeviceFeatures &features) { return features.shader_image_footprint_features.*ptr; }) {} |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1552 | }; |
| 1553 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1554 | struct CapabilityInfo { |
| 1555 | char const *name; |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1556 | FeaturePointer feature; |
| 1557 | bool DeviceExtensions::*extension; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1558 | }; |
| 1559 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1560 | // clang-format off |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1561 | static const std::unordered_multimap<uint32_t, CapabilityInfo> capabilities = { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1562 | // Capabilities always supported by a Vulkan 1.0 implementation -- no |
| 1563 | // feature bits. |
| 1564 | {spv::CapabilityMatrix, {nullptr}}, |
| 1565 | {spv::CapabilityShader, {nullptr}}, |
| 1566 | {spv::CapabilityInputAttachment, {nullptr}}, |
| 1567 | {spv::CapabilitySampled1D, {nullptr}}, |
| 1568 | {spv::CapabilityImage1D, {nullptr}}, |
| 1569 | {spv::CapabilitySampledBuffer, {nullptr}}, |
Toni Merilehti | b13a4a2 | 2019-05-21 12:58:44 +0300 | [diff] [blame] | 1570 | {spv::CapabilityStorageImageExtendedFormats, {nullptr}}, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1571 | {spv::CapabilityImageQuery, {nullptr}}, |
| 1572 | {spv::CapabilityDerivativeControl, {nullptr}}, |
| 1573 | |
| 1574 | // Capabilities that are optionally supported, but require a feature to |
| 1575 | // be enabled on the device |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1576 | {spv::CapabilityGeometry, {"VkPhysicalDeviceFeatures::geometryShader", &VkPhysicalDeviceFeatures::geometryShader}}, |
| 1577 | {spv::CapabilityTessellation, {"VkPhysicalDeviceFeatures::tessellationShader", &VkPhysicalDeviceFeatures::tessellationShader}}, |
| 1578 | {spv::CapabilityFloat64, {"VkPhysicalDeviceFeatures::shaderFloat64", &VkPhysicalDeviceFeatures::shaderFloat64}}, |
| 1579 | {spv::CapabilityInt64, {"VkPhysicalDeviceFeatures::shaderInt64", &VkPhysicalDeviceFeatures::shaderInt64}}, |
| 1580 | {spv::CapabilityTessellationPointSize, {"VkPhysicalDeviceFeatures::shaderTessellationAndGeometryPointSize", &VkPhysicalDeviceFeatures::shaderTessellationAndGeometryPointSize}}, |
| 1581 | {spv::CapabilityGeometryPointSize, {"VkPhysicalDeviceFeatures::shaderTessellationAndGeometryPointSize", &VkPhysicalDeviceFeatures::shaderTessellationAndGeometryPointSize}}, |
| 1582 | {spv::CapabilityImageGatherExtended, {"VkPhysicalDeviceFeatures::shaderImageGatherExtended", &VkPhysicalDeviceFeatures::shaderImageGatherExtended}}, |
| 1583 | {spv::CapabilityStorageImageMultisample, {"VkPhysicalDeviceFeatures::shaderStorageImageMultisample", &VkPhysicalDeviceFeatures::shaderStorageImageMultisample}}, |
| 1584 | {spv::CapabilityUniformBufferArrayDynamicIndexing, {"VkPhysicalDeviceFeatures::shaderUniformBufferArrayDynamicIndexing", &VkPhysicalDeviceFeatures::shaderUniformBufferArrayDynamicIndexing}}, |
| 1585 | {spv::CapabilitySampledImageArrayDynamicIndexing, {"VkPhysicalDeviceFeatures::shaderSampledImageArrayDynamicIndexing", &VkPhysicalDeviceFeatures::shaderSampledImageArrayDynamicIndexing}}, |
| 1586 | {spv::CapabilityStorageBufferArrayDynamicIndexing, {"VkPhysicalDeviceFeatures::shaderStorageBufferArrayDynamicIndexing", &VkPhysicalDeviceFeatures::shaderStorageBufferArrayDynamicIndexing}}, |
| 1587 | {spv::CapabilityStorageImageArrayDynamicIndexing, {"VkPhysicalDeviceFeatures::shaderStorageImageArrayDynamicIndexing", &VkPhysicalDeviceFeatures::shaderStorageBufferArrayDynamicIndexing}}, |
| 1588 | {spv::CapabilityClipDistance, {"VkPhysicalDeviceFeatures::shaderClipDistance", &VkPhysicalDeviceFeatures::shaderClipDistance}}, |
| 1589 | {spv::CapabilityCullDistance, {"VkPhysicalDeviceFeatures::shaderCullDistance", &VkPhysicalDeviceFeatures::shaderCullDistance}}, |
| 1590 | {spv::CapabilityImageCubeArray, {"VkPhysicalDeviceFeatures::imageCubeArray", &VkPhysicalDeviceFeatures::imageCubeArray}}, |
| 1591 | {spv::CapabilitySampleRateShading, {"VkPhysicalDeviceFeatures::sampleRateShading", &VkPhysicalDeviceFeatures::sampleRateShading}}, |
| 1592 | {spv::CapabilitySparseResidency, {"VkPhysicalDeviceFeatures::shaderResourceResidency", &VkPhysicalDeviceFeatures::shaderResourceResidency}}, |
| 1593 | {spv::CapabilityMinLod, {"VkPhysicalDeviceFeatures::shaderResourceMinLod", &VkPhysicalDeviceFeatures::shaderResourceMinLod}}, |
| 1594 | {spv::CapabilitySampledCubeArray, {"VkPhysicalDeviceFeatures::imageCubeArray", &VkPhysicalDeviceFeatures::imageCubeArray}}, |
| 1595 | {spv::CapabilityImageMSArray, {"VkPhysicalDeviceFeatures::shaderStorageImageMultisample", &VkPhysicalDeviceFeatures::shaderStorageImageMultisample}}, |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1596 | {spv::CapabilityInterpolationFunction, {"VkPhysicalDeviceFeatures::sampleRateShading", &VkPhysicalDeviceFeatures::sampleRateShading}}, |
| 1597 | {spv::CapabilityStorageImageReadWithoutFormat, {"VkPhysicalDeviceFeatures::shaderStorageImageReadWithoutFormat", &VkPhysicalDeviceFeatures::shaderStorageImageReadWithoutFormat}}, |
| 1598 | {spv::CapabilityStorageImageWriteWithoutFormat, {"VkPhysicalDeviceFeatures::shaderStorageImageWriteWithoutFormat", &VkPhysicalDeviceFeatures::shaderStorageImageWriteWithoutFormat}}, |
| 1599 | {spv::CapabilityMultiViewport, {"VkPhysicalDeviceFeatures::multiViewport", &VkPhysicalDeviceFeatures::multiViewport}}, |
Jeff Bolz | fdf9607 | 2018-04-10 14:32:18 -0500 | [diff] [blame] | 1600 | |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1601 | {spv::CapabilityShaderNonUniformEXT, {VK_EXT_DESCRIPTOR_INDEXING_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_ext_descriptor_indexing}}, |
| 1602 | {spv::CapabilityRuntimeDescriptorArrayEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::runtimeDescriptorArray", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::runtimeDescriptorArray}}, |
| 1603 | {spv::CapabilityInputAttachmentArrayDynamicIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderInputAttachmentArrayDynamicIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderInputAttachmentArrayDynamicIndexing}}, |
| 1604 | {spv::CapabilityUniformTexelBufferArrayDynamicIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformTexelBufferArrayDynamicIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformTexelBufferArrayDynamicIndexing}}, |
| 1605 | {spv::CapabilityStorageTexelBufferArrayDynamicIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageTexelBufferArrayDynamicIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageTexelBufferArrayDynamicIndexing}}, |
| 1606 | {spv::CapabilityUniformBufferArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformBufferArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformBufferArrayNonUniformIndexing}}, |
| 1607 | {spv::CapabilitySampledImageArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderSampledImageArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderSampledImageArrayNonUniformIndexing}}, |
| 1608 | {spv::CapabilityStorageBufferArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageBufferArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageBufferArrayNonUniformIndexing}}, |
| 1609 | {spv::CapabilityStorageImageArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageImageArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageImageArrayNonUniformIndexing}}, |
| 1610 | {spv::CapabilityInputAttachmentArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderInputAttachmentArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderInputAttachmentArrayNonUniformIndexing}}, |
| 1611 | {spv::CapabilityUniformTexelBufferArrayNonUniformIndexingEXT, {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformTexelBufferArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderUniformTexelBufferArrayNonUniformIndexing}}, |
| 1612 | {spv::CapabilityStorageTexelBufferArrayNonUniformIndexingEXT , {"VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageTexelBufferArrayNonUniformIndexing", &VkPhysicalDeviceDescriptorIndexingFeaturesEXT::shaderStorageTexelBufferArrayNonUniformIndexing}}, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1613 | |
| 1614 | // Capabilities that require an extension |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1615 | {spv::CapabilityDrawParameters, {VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_khr_shader_draw_parameters}}, |
| 1616 | {spv::CapabilityGeometryShaderPassthroughNV, {VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_nv_geometry_shader_passthrough}}, |
| 1617 | {spv::CapabilitySampleMaskOverrideCoverageNV, {VK_NV_SAMPLE_MASK_OVERRIDE_COVERAGE_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_nv_sample_mask_override_coverage}}, |
| 1618 | {spv::CapabilityShaderViewportIndexLayerEXT, {VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_ext_shader_viewport_index_layer}}, |
| 1619 | {spv::CapabilityShaderViewportIndexLayerNV, {VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_nv_viewport_array2}}, |
| 1620 | {spv::CapabilityShaderViewportMaskNV, {VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_nv_viewport_array2}}, |
| 1621 | {spv::CapabilitySubgroupBallotKHR, {VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_ext_shader_subgroup_ballot }}, |
| 1622 | {spv::CapabilitySubgroupVoteKHR, {VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_ext_shader_subgroup_vote }}, |
Jason Macnak | b7d091c | 2019-06-10 11:13:11 -0700 | [diff] [blame] | 1623 | {spv::CapabilityGroupNonUniformPartitionedNV, {VK_NV_SHADER_SUBGROUP_PARTITIONED_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_nv_shader_subgroup_partitioned}}, |
aqnuep | 7033c70 | 2018-09-11 18:03:29 +0200 | [diff] [blame] | 1624 | {spv::CapabilityInt64Atomics, {VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, nullptr, &DeviceExtensions::vk_khr_shader_atomic_int64 }}, |
Alexander Galazin | 3bd8e34 | 2018-06-14 15:49:07 +0200 | [diff] [blame] | 1625 | |
Jason Macnak | c5a621d | 2019-06-10 12:42:50 -0700 | [diff] [blame] | 1626 | {spv::CapabilityComputeDerivativeGroupQuadsNV, {"VkPhysicalDeviceComputeShaderDerivativesFeaturesNV::computeDerivativeGroupQuads", &VkPhysicalDeviceComputeShaderDerivativesFeaturesNV::computeDerivativeGroupQuads, &DeviceExtensions::vk_nv_compute_shader_derivatives}}, |
| 1627 | {spv::CapabilityComputeDerivativeGroupLinearNV, {"VkPhysicalDeviceComputeShaderDerivativesFeaturesNV::computeDerivativeGroupLinear", &VkPhysicalDeviceComputeShaderDerivativesFeaturesNV::computeDerivativeGroupLinear, &DeviceExtensions::vk_nv_compute_shader_derivatives}}, |
Jason Macnak | 325e8b5 | 2019-06-10 13:33:10 -0700 | [diff] [blame] | 1628 | {spv::CapabilityFragmentBarycentricNV , {"VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV::fragmentShaderBarycentric", &VkPhysicalDeviceFragmentShaderBarycentricFeaturesNV::fragmentShaderBarycentric, &DeviceExtensions::vk_nv_fragment_shader_barycentric}}, |
Jason Macnak | c5a621d | 2019-06-10 12:42:50 -0700 | [diff] [blame] | 1629 | |
Mike Schuchardt | 8ed5ea0 | 2018-07-20 18:24:17 -0600 | [diff] [blame] | 1630 | {spv::CapabilityStorageBuffer8BitAccess , {"VkPhysicalDevice8BitStorageFeaturesKHR::storageBuffer8BitAccess", &VkPhysicalDevice8BitStorageFeaturesKHR::storageBuffer8BitAccess, &DeviceExtensions::vk_khr_8bit_storage}}, |
| 1631 | {spv::CapabilityUniformAndStorageBuffer8BitAccess , {"VkPhysicalDevice8BitStorageFeaturesKHR::uniformAndStorageBuffer8BitAccess", &VkPhysicalDevice8BitStorageFeaturesKHR::uniformAndStorageBuffer8BitAccess, &DeviceExtensions::vk_khr_8bit_storage}}, |
| 1632 | {spv::CapabilityStoragePushConstant8 , {"VkPhysicalDevice8BitStorageFeaturesKHR::storagePushConstant8", &VkPhysicalDevice8BitStorageFeaturesKHR::storagePushConstant8, &DeviceExtensions::vk_khr_8bit_storage}}, |
Brett Lawson | bebfb6f | 2018-10-23 16:58:50 -0700 | [diff] [blame] | 1633 | |
| 1634 | {spv::CapabilityTransformFeedback , { "VkPhysicalDeviceTransformFeedbackFeaturesEXT::transformFeedback", &VkPhysicalDeviceTransformFeedbackFeaturesEXT::transformFeedback, &DeviceExtensions::vk_ext_transform_feedback}}, |
Jose-Emilio Munoz-Lopez | 1109b45 | 2018-08-21 09:44:07 +0100 | [diff] [blame] | 1635 | {spv::CapabilityGeometryStreams , { "VkPhysicalDeviceTransformFeedbackFeaturesEXT::geometryStreams", &VkPhysicalDeviceTransformFeedbackFeaturesEXT::geometryStreams, &DeviceExtensions::vk_ext_transform_feedback}}, |
| 1636 | |
| 1637 | {spv::CapabilityFloat16 , {"VkPhysicalDeviceFloat16Int8FeaturesKHR::shaderFloat16", &VkPhysicalDeviceFloat16Int8FeaturesKHR::shaderFloat16, &DeviceExtensions::vk_khr_shader_float16_int8}}, |
| 1638 | {spv::CapabilityInt8 , {"VkPhysicalDeviceFloat16Int8FeaturesKHR::shaderInt8", &VkPhysicalDeviceFloat16Int8FeaturesKHR::shaderInt8, &DeviceExtensions::vk_khr_shader_float16_int8}}, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1639 | |
Jason Macnak | d7fddf8 | 2019-06-13 09:52:49 -0700 | [diff] [blame^] | 1640 | {spv::CapabilityImageFootprintNV, {"VkPhysicalDeviceShaderImageFootprintFeaturesNV::imageFootprint", &VkPhysicalDeviceShaderImageFootprintFeaturesNV::imageFootprint, &DeviceExtensions::vk_nv_shader_image_footprint}}, |
| 1641 | |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1642 | {spv::CapabilityCooperativeMatrixNV, {"VkPhysicalDeviceCooperativeMatrixFeaturesNV::cooperativeMatrix", &VkPhysicalDeviceCooperativeMatrixFeaturesNV::cooperativeMatrix, &DeviceExtensions::vk_nv_cooperative_matrix}}, |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1643 | |
| 1644 | {spv::CapabilitySignedZeroInfNanPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat16", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat16, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1645 | {spv::CapabilitySignedZeroInfNanPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat32", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat32, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1646 | {spv::CapabilitySignedZeroInfNanPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat64", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderSignedZeroInfNanPreserveFloat64, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1647 | {spv::CapabilityDenormPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat16", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat16, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1648 | {spv::CapabilityDenormPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat32", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat32, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1649 | {spv::CapabilityDenormPreserve, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat64", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormPreserveFloat64, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1650 | {spv::CapabilityDenormFlushToZero, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat16", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat16, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1651 | {spv::CapabilityDenormFlushToZero, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat32", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat32, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1652 | {spv::CapabilityDenormFlushToZero, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat64", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderDenormFlushToZeroFloat64, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1653 | {spv::CapabilityRoundingModeRTE, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat16", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat16, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1654 | {spv::CapabilityRoundingModeRTE, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat32", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat32, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1655 | {spv::CapabilityRoundingModeRTE, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat64", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTEFloat64, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1656 | {spv::CapabilityRoundingModeRTZ, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat16", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat16, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1657 | {spv::CapabilityRoundingModeRTZ, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat32", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat32, &DeviceExtensions::vk_khr_shader_float_controls}}, |
| 1658 | {spv::CapabilityRoundingModeRTZ, {"VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat64", &VkPhysicalDeviceFloatControlsPropertiesKHR::shaderRoundingModeRTZFloat64, &DeviceExtensions::vk_khr_shader_float_controls}}, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1659 | }; |
| 1660 | // clang-format on |
| 1661 | |
| 1662 | for (auto insn : *src) { |
| 1663 | if (insn.opcode() == spv::OpCapability) { |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1664 | size_t n = capabilities.count(insn.word(1)); |
| 1665 | if (1 == n) { // key occurs exactly once |
| 1666 | auto it = capabilities.find(insn.word(1)); |
| 1667 | if (it != capabilities.end()) { |
| 1668 | if (it->second.feature) { |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 1669 | skip |= RequireFeature(report_data, it->second.feature.IsEnabled(enabled_features), it->second.name); |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1670 | } |
| 1671 | if (it->second.extension) { |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 1672 | skip |= RequireExtension(report_data, device_extensions.*(it->second.extension), it->second.name); |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1673 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1674 | } |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1675 | } else if (1 < n) { // key occurs multiple times, at least one must be enabled |
| 1676 | bool needs_feature = false, has_feature = false; |
| 1677 | bool needs_ext = false, has_ext = false; |
| 1678 | std::string feature_names = "(one of) [ "; |
| 1679 | std::string extension_names = feature_names; |
| 1680 | auto caps = capabilities.equal_range(insn.word(1)); |
| 1681 | for (auto it = caps.first; it != caps.second; ++it) { |
| 1682 | if (it->second.feature) { |
| 1683 | needs_feature = true; |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 1684 | has_feature = has_feature || it->second.feature.IsEnabled(enabled_features); |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1685 | feature_names += it->second.name; |
| 1686 | feature_names += " "; |
| 1687 | } |
| 1688 | if (it->second.extension) { |
| 1689 | needs_ext = true; |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 1690 | has_ext = has_ext || device_extensions.*(it->second.extension); |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1691 | extension_names += it->second.name; |
| 1692 | extension_names += " "; |
| 1693 | } |
| 1694 | } |
| 1695 | if (needs_feature) { |
| 1696 | feature_names += "]"; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1697 | skip |= RequireFeature(report_data, has_feature, feature_names.c_str()); |
Dave Houlton | eb10ea8 | 2017-12-22 12:21:50 -0700 | [diff] [blame] | 1698 | } |
| 1699 | if (needs_ext) { |
| 1700 | extension_names += "]"; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 1701 | skip |= RequireExtension(report_data, has_ext, extension_names.c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1702 | } |
| 1703 | } |
| 1704 | } |
| 1705 | } |
| 1706 | |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 1707 | if (has_writable_descriptor) { |
| 1708 | switch (stage) { |
| 1709 | case VK_SHADER_STAGE_COMPUTE_BIT: |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 1710 | case VK_SHADER_STAGE_RAYGEN_BIT_NV: |
| 1711 | case VK_SHADER_STAGE_ANY_HIT_BIT_NV: |
| 1712 | case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV: |
| 1713 | case VK_SHADER_STAGE_MISS_BIT_NV: |
| 1714 | case VK_SHADER_STAGE_INTERSECTION_BIT_NV: |
| 1715 | case VK_SHADER_STAGE_CALLABLE_BIT_NV: |
| 1716 | case VK_SHADER_STAGE_TASK_BIT_NV: |
| 1717 | case VK_SHADER_STAGE_MESH_BIT_NV: |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 1718 | /* No feature requirements for writes and atomics from compute |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 1719 | * raytracing, or mesh stages */ |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 1720 | break; |
| 1721 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 1722 | skip |= RequireFeature(report_data, enabled_features.core.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"); |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 1723 | break; |
| 1724 | default: |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 1725 | skip |= RequireFeature(report_data, enabled_features.core.vertexPipelineStoresAndAtomics, |
| 1726 | "vertexPipelineStoresAndAtomics"); |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 1727 | break; |
| 1728 | } |
| 1729 | } |
| 1730 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1731 | return skip; |
| 1732 | } |
| 1733 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1734 | bool CoreChecks::ValidateShaderStageInputOutputLimits(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1735 | PIPELINE_STATE *pipeline, spirv_inst_iter entrypoint) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1736 | if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT || pStage->stage == VK_SHADER_STAGE_ALL_GRAPHICS || |
| 1737 | pStage->stage == VK_SHADER_STAGE_ALL) { |
| 1738 | return false; |
| 1739 | } |
| 1740 | |
| 1741 | bool skip = false; |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 1742 | auto const &limits = phys_dev_props.limits; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1743 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1744 | std::set<uint32_t> patchIDs; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1745 | struct Variable { |
| 1746 | uint32_t baseTypePtrID; |
| 1747 | uint32_t ID; |
| 1748 | uint32_t storageClass; |
| 1749 | }; |
| 1750 | std::vector<Variable> variables; |
| 1751 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1752 | uint32_t numVertices = 0; |
| 1753 | |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1754 | for (auto insn : *src) { |
| 1755 | switch (insn.opcode()) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1756 | // Find all Patch decorations |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1757 | case spv::OpDecorate: |
| 1758 | switch (insn.word(2)) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1759 | case spv::DecorationPatch: { |
| 1760 | patchIDs.insert(insn.word(1)); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1761 | break; |
| 1762 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1763 | default: |
| 1764 | break; |
| 1765 | } |
| 1766 | break; |
| 1767 | // Find all input and output variables |
| 1768 | case spv::OpVariable: { |
| 1769 | Variable var = {}; |
| 1770 | var.storageClass = insn.word(3); |
| 1771 | if (var.storageClass == spv::StorageClassInput || var.storageClass == spv::StorageClassOutput) { |
| 1772 | var.baseTypePtrID = insn.word(1); |
| 1773 | var.ID = insn.word(2); |
| 1774 | variables.push_back(var); |
| 1775 | } |
| 1776 | break; |
| 1777 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1778 | case spv::OpExecutionMode: |
| 1779 | if (insn.word(1) == entrypoint.word(2)) { |
| 1780 | switch (insn.word(2)) { |
| 1781 | default: |
| 1782 | break; |
| 1783 | case spv::ExecutionModeOutputVertices: |
| 1784 | numVertices = insn.word(3); |
| 1785 | break; |
| 1786 | } |
| 1787 | } |
| 1788 | break; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1789 | default: |
| 1790 | break; |
| 1791 | } |
| 1792 | } |
| 1793 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1794 | bool strip_output_array_level = |
| 1795 | (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStage->stage == VK_SHADER_STAGE_MESH_BIT_NV); |
| 1796 | bool strip_input_array_level = |
| 1797 | (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || |
| 1798 | pStage->stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || pStage->stage == VK_SHADER_STAGE_GEOMETRY_BIT); |
| 1799 | |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1800 | uint32_t numCompIn = 0, numCompOut = 0; |
| 1801 | for (auto &var : variables) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1802 | // Check if the variable is a patch. Patches can also be members of blocks, |
| 1803 | // but if they are then the top-level arrayness has already been stripped |
| 1804 | // by the time GetComponentsConsumedByType gets to it. |
| 1805 | bool isPatch = patchIDs.find(var.ID) != patchIDs.end(); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1806 | |
| 1807 | if (var.storageClass == spv::StorageClassInput) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1808 | numCompIn += GetComponentsConsumedByType(src, var.baseTypePtrID, strip_input_array_level && !isPatch); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1809 | } else { // var.storageClass == spv::StorageClassOutput |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1810 | numCompOut += GetComponentsConsumedByType(src, var.baseTypePtrID, strip_output_array_level && !isPatch); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1811 | } |
| 1812 | } |
| 1813 | |
| 1814 | switch (pStage->stage) { |
| 1815 | case VK_SHADER_STAGE_VERTEX_BIT: |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1816 | if (numCompOut > limits.maxVertexOutputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1817 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1818 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1819 | "Invalid Pipeline CreateInfo State: Vertex shader exceeds " |
| 1820 | "VkPhysicalDeviceLimits::maxVertexOutputComponents of %u " |
| 1821 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1822 | limits.maxVertexOutputComponents, numCompOut - limits.maxVertexOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1823 | } |
| 1824 | break; |
| 1825 | |
| 1826 | case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1827 | if (numCompIn > limits.maxTessellationControlPerVertexInputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1828 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1829 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1830 | "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds " |
| 1831 | "VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents of %u " |
| 1832 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1833 | limits.maxTessellationControlPerVertexInputComponents, |
| 1834 | numCompIn - limits.maxTessellationControlPerVertexInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1835 | } |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1836 | if (numCompOut > limits.maxTessellationControlPerVertexOutputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1837 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1838 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1839 | "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds " |
| 1840 | "VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents of %u " |
| 1841 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1842 | limits.maxTessellationControlPerVertexOutputComponents, |
| 1843 | numCompOut - limits.maxTessellationControlPerVertexOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1844 | } |
| 1845 | break; |
| 1846 | |
| 1847 | case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1848 | if (numCompIn > limits.maxTessellationEvaluationInputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1849 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1850 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1851 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds " |
| 1852 | "VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents of %u " |
| 1853 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1854 | limits.maxTessellationEvaluationInputComponents, |
| 1855 | numCompIn - limits.maxTessellationEvaluationInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1856 | } |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1857 | if (numCompOut > limits.maxTessellationEvaluationOutputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1858 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1859 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1860 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds " |
| 1861 | "VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents of %u " |
| 1862 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1863 | limits.maxTessellationEvaluationOutputComponents, |
| 1864 | numCompOut - limits.maxTessellationEvaluationOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1865 | } |
| 1866 | break; |
| 1867 | |
| 1868 | case VK_SHADER_STAGE_GEOMETRY_BIT: |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1869 | if (numCompIn > limits.maxGeometryInputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1870 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1871 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1872 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 1873 | "VkPhysicalDeviceLimits::maxGeometryInputComponents of %u " |
| 1874 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1875 | limits.maxGeometryInputComponents, numCompIn - limits.maxGeometryInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1876 | } |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1877 | if (numCompOut > limits.maxGeometryOutputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1878 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1879 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1880 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 1881 | "VkPhysicalDeviceLimits::maxGeometryOutputComponents of %u " |
| 1882 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1883 | limits.maxGeometryOutputComponents, numCompOut - limits.maxGeometryOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1884 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1885 | if (numCompOut * numVertices > limits.maxGeometryTotalOutputComponents) { |
| 1886 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1887 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1888 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 1889 | "VkPhysicalDeviceLimits::maxGeometryTotalOutputComponents of %u " |
| 1890 | "components by %u components", |
| 1891 | limits.maxGeometryTotalOutputComponents, |
| 1892 | numCompOut * numVertices - limits.maxGeometryTotalOutputComponents); |
| 1893 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1894 | break; |
| 1895 | |
| 1896 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1897 | if (numCompIn > limits.maxFragmentInputComponents) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1898 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
| 1899 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_ExceedDeviceLimit, |
| 1900 | "Invalid Pipeline CreateInfo State: Fragment shader exceeds " |
| 1901 | "VkPhysicalDeviceLimits::maxFragmentInputComponents of %u " |
| 1902 | "components by %u components", |
Mark Lobodzinski | 57a4427 | 2019-02-27 12:40:50 -0700 | [diff] [blame] | 1903 | limits.maxFragmentInputComponents, numCompIn - limits.maxFragmentInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1904 | } |
| 1905 | break; |
| 1906 | |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 1907 | case VK_SHADER_STAGE_RAYGEN_BIT_NV: |
| 1908 | case VK_SHADER_STAGE_ANY_HIT_BIT_NV: |
| 1909 | case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV: |
| 1910 | case VK_SHADER_STAGE_MISS_BIT_NV: |
| 1911 | case VK_SHADER_STAGE_INTERSECTION_BIT_NV: |
| 1912 | case VK_SHADER_STAGE_CALLABLE_BIT_NV: |
| 1913 | case VK_SHADER_STAGE_TASK_BIT_NV: |
| 1914 | case VK_SHADER_STAGE_MESH_BIT_NV: |
| 1915 | break; |
| 1916 | |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 1917 | default: |
| 1918 | assert(false); // This should never happen |
| 1919 | } |
| 1920 | return skip; |
| 1921 | } |
| 1922 | |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1923 | // copy the specialization constant value into buf, if it is present |
| 1924 | void GetSpecConstantValue(VkPipelineShaderStageCreateInfo const *pStage, uint32_t spec_id, void *buf) { |
| 1925 | VkSpecializationInfo const *spec = pStage->pSpecializationInfo; |
| 1926 | |
| 1927 | if (spec && spec_id < spec->mapEntryCount) { |
| 1928 | memcpy(buf, (uint8_t *)spec->pData + spec->pMapEntries[spec_id].offset, spec->pMapEntries[spec_id].size); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | // Fill in value with the constant or specialization constant value, if available. |
| 1933 | // Returns true if the value has been accurately filled out. |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1934 | static bool GetIntConstantValue(spirv_inst_iter insn, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1935 | const std::unordered_map<uint32_t, uint32_t> &id_to_spec_id, uint32_t *value) { |
| 1936 | auto type_id = src->get_def(insn.word(1)); |
| 1937 | if (type_id.opcode() != spv::OpTypeInt || type_id.word(2) != 32) { |
| 1938 | return false; |
| 1939 | } |
| 1940 | switch (insn.opcode()) { |
| 1941 | case spv::OpSpecConstant: |
| 1942 | *value = insn.word(3); |
| 1943 | GetSpecConstantValue(pStage, id_to_spec_id.at(insn.word(2)), value); |
| 1944 | return true; |
| 1945 | case spv::OpConstant: |
| 1946 | *value = insn.word(3); |
| 1947 | return true; |
| 1948 | default: |
| 1949 | return false; |
| 1950 | } |
| 1951 | } |
| 1952 | |
| 1953 | // Map SPIR-V type to VK_COMPONENT_TYPE enum |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1954 | VkComponentTypeNV GetComponentType(spirv_inst_iter insn, SHADER_MODULE_STATE const *src) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1955 | switch (insn.opcode()) { |
| 1956 | case spv::OpTypeInt: |
| 1957 | switch (insn.word(2)) { |
| 1958 | case 8: |
| 1959 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT8_NV : VK_COMPONENT_TYPE_UINT8_NV; |
| 1960 | case 16: |
| 1961 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT16_NV : VK_COMPONENT_TYPE_UINT16_NV; |
| 1962 | case 32: |
| 1963 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT32_NV : VK_COMPONENT_TYPE_UINT32_NV; |
| 1964 | case 64: |
| 1965 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT64_NV : VK_COMPONENT_TYPE_UINT64_NV; |
| 1966 | default: |
| 1967 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1968 | } |
| 1969 | case spv::OpTypeFloat: |
| 1970 | switch (insn.word(2)) { |
| 1971 | case 16: |
| 1972 | return VK_COMPONENT_TYPE_FLOAT16_NV; |
| 1973 | case 32: |
| 1974 | return VK_COMPONENT_TYPE_FLOAT32_NV; |
| 1975 | case 64: |
| 1976 | return VK_COMPONENT_TYPE_FLOAT64_NV; |
| 1977 | default: |
| 1978 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1979 | } |
| 1980 | default: |
| 1981 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1982 | } |
| 1983 | } |
| 1984 | |
| 1985 | // Validate SPV_NV_cooperative_matrix behavior that can't be statically validated |
| 1986 | // in SPIRV-Tools (e.g. due to specialization constant usage). |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1987 | bool CoreChecks::ValidateCooperativeMatrix(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1988 | PIPELINE_STATE *pipeline) { |
| 1989 | bool skip = false; |
| 1990 | |
| 1991 | // Map SPIR-V result ID to specialization constant id (SpecId decoration value) |
| 1992 | std::unordered_map<uint32_t, uint32_t> id_to_spec_id; |
| 1993 | // Map SPIR-V result ID to the ID of its type. |
| 1994 | std::unordered_map<uint32_t, uint32_t> id_to_type_id; |
| 1995 | |
| 1996 | struct CoopMatType { |
| 1997 | uint32_t scope, rows, cols; |
| 1998 | VkComponentTypeNV component_type; |
| 1999 | bool all_constant; |
| 2000 | |
| 2001 | CoopMatType() : scope(0), rows(0), cols(0), component_type(VK_COMPONENT_TYPE_MAX_ENUM_NV), all_constant(false) {} |
| 2002 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2003 | void Init(uint32_t id, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2004 | const std::unordered_map<uint32_t, uint32_t> &id_to_spec_id) { |
| 2005 | spirv_inst_iter insn = src->get_def(id); |
| 2006 | uint32_t component_type_id = insn.word(2); |
| 2007 | uint32_t scope_id = insn.word(3); |
| 2008 | uint32_t rows_id = insn.word(4); |
| 2009 | uint32_t cols_id = insn.word(5); |
| 2010 | auto component_type_iter = src->get_def(component_type_id); |
| 2011 | auto scope_iter = src->get_def(scope_id); |
| 2012 | auto rows_iter = src->get_def(rows_id); |
| 2013 | auto cols_iter = src->get_def(cols_id); |
| 2014 | |
| 2015 | all_constant = true; |
| 2016 | if (!GetIntConstantValue(scope_iter, src, pStage, id_to_spec_id, &scope)) { |
| 2017 | all_constant = false; |
| 2018 | } |
| 2019 | if (!GetIntConstantValue(rows_iter, src, pStage, id_to_spec_id, &rows)) { |
| 2020 | all_constant = false; |
| 2021 | } |
| 2022 | if (!GetIntConstantValue(cols_iter, src, pStage, id_to_spec_id, &cols)) { |
| 2023 | all_constant = false; |
| 2024 | } |
| 2025 | component_type = GetComponentType(component_type_iter, src); |
| 2026 | } |
| 2027 | }; |
| 2028 | |
| 2029 | bool seen_coopmat_capability = false; |
| 2030 | |
| 2031 | for (auto insn : *src) { |
| 2032 | // Whitelist instructions whose result can be a cooperative matrix type, and |
| 2033 | // keep track of their types. It would be nice if SPIRV-Headers generated code |
| 2034 | // to identify which instructions have a result type and result id. Lacking that, |
| 2035 | // this whitelist is based on the set of instructions that |
| 2036 | // SPV_NV_cooperative_matrix says can be used with cooperative matrix types. |
| 2037 | switch (insn.opcode()) { |
| 2038 | case spv::OpLoad: |
| 2039 | case spv::OpCooperativeMatrixLoadNV: |
| 2040 | case spv::OpCooperativeMatrixMulAddNV: |
| 2041 | case spv::OpSNegate: |
| 2042 | case spv::OpFNegate: |
| 2043 | case spv::OpIAdd: |
| 2044 | case spv::OpFAdd: |
| 2045 | case spv::OpISub: |
| 2046 | case spv::OpFSub: |
| 2047 | case spv::OpFDiv: |
| 2048 | case spv::OpSDiv: |
| 2049 | case spv::OpUDiv: |
| 2050 | case spv::OpMatrixTimesScalar: |
| 2051 | case spv::OpConstantComposite: |
| 2052 | case spv::OpCompositeConstruct: |
| 2053 | case spv::OpConvertFToU: |
| 2054 | case spv::OpConvertFToS: |
| 2055 | case spv::OpConvertSToF: |
| 2056 | case spv::OpConvertUToF: |
| 2057 | case spv::OpUConvert: |
| 2058 | case spv::OpSConvert: |
| 2059 | case spv::OpFConvert: |
| 2060 | id_to_type_id[insn.word(2)] = insn.word(1); |
| 2061 | break; |
| 2062 | default: |
| 2063 | break; |
| 2064 | } |
| 2065 | |
| 2066 | switch (insn.opcode()) { |
| 2067 | case spv::OpDecorate: |
| 2068 | if (insn.word(2) == spv::DecorationSpecId) { |
| 2069 | id_to_spec_id[insn.word(1)] = insn.word(3); |
| 2070 | } |
| 2071 | break; |
| 2072 | case spv::OpCapability: |
| 2073 | if (insn.word(1) == spv::CapabilityCooperativeMatrixNV) { |
| 2074 | seen_coopmat_capability = true; |
| 2075 | |
| 2076 | if (!(pStage->stage & phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages)) { |
| 2077 | skip |= |
Mark Lobodzinski | 93a1fa7 | 2019-04-19 12:12:25 -0600 | [diff] [blame] | 2078 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2079 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_CooperativeMatrixSupportedStages, |
| 2080 | "OpTypeCooperativeMatrixNV used in shader stage not in cooperativeMatrixSupportedStages (= %u)", |
| 2081 | phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages); |
| 2082 | } |
| 2083 | } |
| 2084 | break; |
| 2085 | case spv::OpMemoryModel: |
| 2086 | // If the capability isn't enabled, don't bother with the rest of this function. |
| 2087 | // OpMemoryModel is the first required instruction after all OpCapability instructions. |
| 2088 | if (!seen_coopmat_capability) { |
| 2089 | return skip; |
| 2090 | } |
| 2091 | break; |
| 2092 | case spv::OpTypeCooperativeMatrixNV: { |
| 2093 | CoopMatType M; |
| 2094 | M.Init(insn.word(1), src, pStage, id_to_spec_id); |
| 2095 | |
| 2096 | if (M.all_constant) { |
| 2097 | // Validate that the type parameters are all supported for one of the |
| 2098 | // operands of a cooperative matrix property. |
| 2099 | bool valid = false; |
| 2100 | for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) { |
| 2101 | if (cooperative_matrix_properties[i].AType == M.component_type && |
| 2102 | cooperative_matrix_properties[i].MSize == M.rows && cooperative_matrix_properties[i].KSize == M.cols && |
| 2103 | cooperative_matrix_properties[i].scope == M.scope) { |
| 2104 | valid = true; |
| 2105 | break; |
| 2106 | } |
| 2107 | if (cooperative_matrix_properties[i].BType == M.component_type && |
| 2108 | cooperative_matrix_properties[i].KSize == M.rows && cooperative_matrix_properties[i].NSize == M.cols && |
| 2109 | cooperative_matrix_properties[i].scope == M.scope) { |
| 2110 | valid = true; |
| 2111 | break; |
| 2112 | } |
| 2113 | if (cooperative_matrix_properties[i].CType == M.component_type && |
| 2114 | cooperative_matrix_properties[i].MSize == M.rows && cooperative_matrix_properties[i].NSize == M.cols && |
| 2115 | cooperative_matrix_properties[i].scope == M.scope) { |
| 2116 | valid = true; |
| 2117 | break; |
| 2118 | } |
| 2119 | if (cooperative_matrix_properties[i].DType == M.component_type && |
| 2120 | cooperative_matrix_properties[i].MSize == M.rows && cooperative_matrix_properties[i].NSize == M.cols && |
| 2121 | cooperative_matrix_properties[i].scope == M.scope) { |
| 2122 | valid = true; |
| 2123 | break; |
| 2124 | } |
| 2125 | } |
| 2126 | if (!valid) { |
Mark Lobodzinski | 93a1fa7 | 2019-04-19 12:12:25 -0600 | [diff] [blame] | 2127 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2128 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_CooperativeMatrixType, |
| 2129 | "OpTypeCooperativeMatrixNV (result id = %u) operands don't match a supported matrix type", |
| 2130 | insn.word(1)); |
| 2131 | } |
| 2132 | } |
| 2133 | break; |
| 2134 | } |
| 2135 | case spv::OpCooperativeMatrixMulAddNV: { |
| 2136 | CoopMatType A, B, C, D; |
| 2137 | if (id_to_type_id.find(insn.word(2)) == id_to_type_id.end() || |
| 2138 | id_to_type_id.find(insn.word(3)) == id_to_type_id.end() || |
| 2139 | id_to_type_id.find(insn.word(4)) == id_to_type_id.end() || |
| 2140 | id_to_type_id.find(insn.word(5)) == id_to_type_id.end()) { |
Mike Schuchardt | e48dc14 | 2019-04-18 09:12:03 -0700 | [diff] [blame] | 2141 | // Couldn't find type of matrix |
| 2142 | assert(false); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2143 | break; |
| 2144 | } |
| 2145 | D.Init(id_to_type_id[insn.word(2)], src, pStage, id_to_spec_id); |
| 2146 | A.Init(id_to_type_id[insn.word(3)], src, pStage, id_to_spec_id); |
| 2147 | B.Init(id_to_type_id[insn.word(4)], src, pStage, id_to_spec_id); |
| 2148 | C.Init(id_to_type_id[insn.word(5)], src, pStage, id_to_spec_id); |
| 2149 | |
| 2150 | if (A.all_constant && B.all_constant && C.all_constant && D.all_constant) { |
| 2151 | // Validate that the type parameters are all supported for the same |
| 2152 | // cooperative matrix property. |
| 2153 | bool valid = false; |
| 2154 | for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) { |
| 2155 | if (cooperative_matrix_properties[i].AType == A.component_type && |
| 2156 | cooperative_matrix_properties[i].MSize == A.rows && cooperative_matrix_properties[i].KSize == A.cols && |
| 2157 | cooperative_matrix_properties[i].scope == A.scope && |
| 2158 | |
| 2159 | cooperative_matrix_properties[i].BType == B.component_type && |
| 2160 | cooperative_matrix_properties[i].KSize == B.rows && cooperative_matrix_properties[i].NSize == B.cols && |
| 2161 | cooperative_matrix_properties[i].scope == B.scope && |
| 2162 | |
| 2163 | cooperative_matrix_properties[i].CType == C.component_type && |
| 2164 | cooperative_matrix_properties[i].MSize == C.rows && cooperative_matrix_properties[i].NSize == C.cols && |
| 2165 | cooperative_matrix_properties[i].scope == C.scope && |
| 2166 | |
| 2167 | cooperative_matrix_properties[i].DType == D.component_type && |
| 2168 | cooperative_matrix_properties[i].MSize == D.rows && cooperative_matrix_properties[i].NSize == D.cols && |
| 2169 | cooperative_matrix_properties[i].scope == D.scope) { |
| 2170 | valid = true; |
| 2171 | break; |
| 2172 | } |
| 2173 | } |
| 2174 | if (!valid) { |
Mark Lobodzinski | 93a1fa7 | 2019-04-19 12:12:25 -0600 | [diff] [blame] | 2175 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2176 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_CooperativeMatrixMulAdd, |
| 2177 | "OpCooperativeMatrixMulAddNV (result id = %u) operands don't match a supported matrix " |
| 2178 | "VkCooperativeMatrixPropertiesNV", |
| 2179 | insn.word(2)); |
| 2180 | } |
| 2181 | } |
| 2182 | break; |
| 2183 | } |
| 2184 | default: |
| 2185 | break; |
| 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | return skip; |
| 2190 | } |
| 2191 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2192 | bool CoreChecks::ValidateExecutionModes(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2193 | auto entrypoint_id = entrypoint.word(2); |
| 2194 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2195 | // The first denorm execution mode encountered, along with its bit width. |
| 2196 | // Used to check if SeparateDenormSettings is respected. |
| 2197 | std::pair<spv::ExecutionMode, uint32_t> first_denorm_execution_mode = std::make_pair(spv::ExecutionModeMax, 0); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2198 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2199 | // The first rounding mode encountered, along with its bit width. |
| 2200 | // Used to check if SeparateRoundingModeSettings is respected. |
| 2201 | std::pair<spv::ExecutionMode, uint32_t> first_rounding_mode = std::make_pair(spv::ExecutionModeMax, 0); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2202 | |
| 2203 | bool skip = false; |
| 2204 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 2205 | uint32_t verticesOut = 0; |
| 2206 | uint32_t invocations = 0; |
| 2207 | |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2208 | for (auto insn : *src) { |
| 2209 | if (insn.opcode() == spv::OpExecutionMode && insn.word(1) == entrypoint_id) { |
| 2210 | auto mode = insn.word(2); |
| 2211 | switch (mode) { |
| 2212 | case spv::ExecutionModeSignedZeroInfNanPreserve: { |
| 2213 | auto bit_width = insn.word(3); |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2214 | if ((bit_width == 16 && !enabled_features.float_controls.shaderSignedZeroInfNanPreserveFloat16) || |
| 2215 | (bit_width == 32 && !enabled_features.float_controls.shaderSignedZeroInfNanPreserveFloat32) || |
| 2216 | (bit_width == 64 && !enabled_features.float_controls.shaderSignedZeroInfNanPreserveFloat64)) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2217 | skip |= |
| 2218 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2219 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2220 | "Shader requires SignedZeroInfNanPreserve for bit width %d but it is not enabled on the device", |
| 2221 | bit_width); |
| 2222 | } |
| 2223 | break; |
| 2224 | } |
| 2225 | |
| 2226 | case spv::ExecutionModeDenormPreserve: { |
| 2227 | auto bit_width = insn.word(3); |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2228 | if ((bit_width == 16 && !enabled_features.float_controls.shaderDenormPreserveFloat16) || |
| 2229 | (bit_width == 32 && !enabled_features.float_controls.shaderDenormPreserveFloat32) || |
| 2230 | (bit_width == 64 && !enabled_features.float_controls.shaderDenormPreserveFloat64)) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2231 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2232 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2233 | "Shader requires DenormPreserve for bit width %d but it is not enabled on the device", |
| 2234 | bit_width); |
| 2235 | } |
| 2236 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2237 | if (first_denorm_execution_mode.first == spv::ExecutionModeMax) { |
| 2238 | // Register the first denorm execution mode found |
| 2239 | first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width); |
| 2240 | } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2241 | !enabled_features.float_controls.separateDenormSettings) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2242 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2243 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2244 | "Shader uses separate denorm execution modes for different bit widths but " |
| 2245 | "SeparateDenormSettings is not enabled on the device"); |
| 2246 | } |
| 2247 | break; |
| 2248 | } |
| 2249 | |
| 2250 | case spv::ExecutionModeDenormFlushToZero: { |
| 2251 | auto bit_width = insn.word(3); |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2252 | if ((bit_width == 16 && !enabled_features.float_controls.shaderDenormFlushToZeroFloat16) || |
| 2253 | (bit_width == 32 && !enabled_features.float_controls.shaderDenormFlushToZeroFloat32) || |
| 2254 | (bit_width == 64 && !enabled_features.float_controls.shaderDenormFlushToZeroFloat64)) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2255 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2256 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2257 | "Shader requires DenormFlushToZero for bit width %d but it is not enabled on the device", |
| 2258 | bit_width); |
| 2259 | } |
| 2260 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2261 | if (first_denorm_execution_mode.first == spv::ExecutionModeMax) { |
| 2262 | // Register the first denorm execution mode found |
| 2263 | first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width); |
| 2264 | } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2265 | !enabled_features.float_controls.separateDenormSettings) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2266 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2267 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2268 | "Shader uses separate denorm execution modes for different bit widths but " |
| 2269 | "SeparateDenormSettings is not enabled on the device"); |
| 2270 | } |
| 2271 | break; |
| 2272 | } |
| 2273 | |
| 2274 | case spv::ExecutionModeRoundingModeRTE: { |
| 2275 | auto bit_width = insn.word(3); |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2276 | if ((bit_width == 16 && !enabled_features.float_controls.shaderRoundingModeRTEFloat16) || |
| 2277 | (bit_width == 32 && !enabled_features.float_controls.shaderRoundingModeRTEFloat32) || |
| 2278 | (bit_width == 64 && !enabled_features.float_controls.shaderRoundingModeRTEFloat64)) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2279 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2280 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2281 | "Shader requires RoundingModeRTE for bit width %d but it is not enabled on the device", |
| 2282 | bit_width); |
| 2283 | } |
| 2284 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2285 | if (first_rounding_mode.first == spv::ExecutionModeMax) { |
| 2286 | // Register the first rounding mode found |
| 2287 | first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width); |
| 2288 | } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2289 | !enabled_features.float_controls.separateRoundingModeSettings) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2290 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2291 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2292 | "Shader uses separate rounding modes for different bit widths but " |
| 2293 | "SeparateRoundingModeSettings is not enabled on the device"); |
| 2294 | } |
| 2295 | break; |
| 2296 | } |
| 2297 | |
| 2298 | case spv::ExecutionModeRoundingModeRTZ: { |
| 2299 | auto bit_width = insn.word(3); |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2300 | if ((bit_width == 16 && !enabled_features.float_controls.shaderRoundingModeRTZFloat16) || |
| 2301 | (bit_width == 32 && !enabled_features.float_controls.shaderRoundingModeRTZFloat32) || |
| 2302 | (bit_width == 64 && !enabled_features.float_controls.shaderRoundingModeRTZFloat64)) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2303 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2304 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2305 | "Shader requires RoundingModeRTZ for bit width %d but it is not enabled on the device", |
| 2306 | bit_width); |
| 2307 | } |
| 2308 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 2309 | if (first_rounding_mode.first == spv::ExecutionModeMax) { |
| 2310 | // Register the first rounding mode found |
| 2311 | first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width); |
| 2312 | } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2313 | !enabled_features.float_controls.separateRoundingModeSettings) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2314 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2315 | kVUID_Core_Shader_FeatureNotEnabled, |
| 2316 | "Shader uses separate rounding modes for different bit widths but " |
| 2317 | "SeparateRoundingModeSettings is not enabled on the device"); |
| 2318 | } |
| 2319 | break; |
| 2320 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 2321 | |
| 2322 | case spv::ExecutionModeOutputVertices: { |
| 2323 | verticesOut = insn.word(3); |
| 2324 | break; |
| 2325 | } |
| 2326 | |
| 2327 | case spv::ExecutionModeInvocations: { |
| 2328 | invocations = insn.word(3); |
| 2329 | break; |
| 2330 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | } |
| 2334 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 2335 | if (entrypoint.word(1) == spv::ExecutionModelGeometry) { |
| 2336 | if (verticesOut == 0 || verticesOut > phys_dev_props.limits.maxGeometryOutputVertices) { |
| 2337 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2338 | "VUID-VkPipelineShaderStageCreateInfo-stage-00714", |
| 2339 | "Geometry shader entry point must have an OpExecutionMode instruction that " |
| 2340 | "specifies a maximum output vertex count that is greater than 0 and less " |
| 2341 | "than or equal to maxGeometryOutputVertices. " |
| 2342 | "OutputVertices=%d, maxGeometryOutputVertices=%d", |
| 2343 | verticesOut, phys_dev_props.limits.maxGeometryOutputVertices); |
| 2344 | } |
| 2345 | |
| 2346 | if (invocations == 0 || invocations > phys_dev_props.limits.maxGeometryShaderInvocations) { |
| 2347 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
| 2348 | "VUID-VkPipelineShaderStageCreateInfo-stage-00715", |
| 2349 | "Geometry shader entry point must have an OpExecutionMode instruction that " |
| 2350 | "specifies an invocation count that is greater than 0 and less " |
| 2351 | "than or equal to maxGeometryShaderInvocations. " |
| 2352 | "Invocations=%d, maxGeometryShaderInvocations=%d", |
| 2353 | invocations, phys_dev_props.limits.maxGeometryShaderInvocations); |
| 2354 | } |
| 2355 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2356 | return skip; |
| 2357 | } |
| 2358 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2359 | static uint32_t DescriptorTypeToReqs(SHADER_MODULE_STATE const *module, uint32_t type_id) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2360 | auto type = module->get_def(type_id); |
| 2361 | |
| 2362 | while (true) { |
| 2363 | switch (type.opcode()) { |
| 2364 | case spv::OpTypeArray: |
Chris Forbes | 062f122 | 2018-08-21 15:34:15 -0700 | [diff] [blame] | 2365 | case spv::OpTypeRuntimeArray: |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2366 | case spv::OpTypeSampledImage: |
| 2367 | type = module->get_def(type.word(2)); |
| 2368 | break; |
| 2369 | case spv::OpTypePointer: |
| 2370 | type = module->get_def(type.word(3)); |
| 2371 | break; |
| 2372 | case spv::OpTypeImage: { |
| 2373 | auto dim = type.word(3); |
| 2374 | auto arrayed = type.word(5); |
| 2375 | auto msaa = type.word(6); |
| 2376 | |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2377 | uint32_t bits = 0; |
| 2378 | switch (GetFundamentalType(module, type.word(2))) { |
| 2379 | case FORMAT_TYPE_FLOAT: |
| 2380 | bits = DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT; |
| 2381 | break; |
| 2382 | case FORMAT_TYPE_UINT: |
| 2383 | bits = DESCRIPTOR_REQ_COMPONENT_TYPE_UINT; |
| 2384 | break; |
| 2385 | case FORMAT_TYPE_SINT: |
| 2386 | bits = DESCRIPTOR_REQ_COMPONENT_TYPE_SINT; |
| 2387 | break; |
| 2388 | default: |
| 2389 | break; |
| 2390 | } |
| 2391 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2392 | switch (dim) { |
| 2393 | case spv::Dim1D: |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2394 | bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_1D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_1D; |
| 2395 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2396 | case spv::Dim2D: |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2397 | bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE; |
| 2398 | bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_2D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_2D; |
| 2399 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2400 | case spv::Dim3D: |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2401 | bits |= DESCRIPTOR_REQ_VIEW_TYPE_3D; |
| 2402 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2403 | case spv::DimCube: |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2404 | bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_CUBE_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_CUBE; |
| 2405 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2406 | case spv::DimSubpassData: |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2407 | bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE; |
| 2408 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2409 | default: // buffer, etc. |
Chris Forbes | 74ba223 | 2018-08-27 15:19:27 -0700 | [diff] [blame] | 2410 | return bits; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2411 | } |
| 2412 | } |
| 2413 | default: |
| 2414 | return 0; |
| 2415 | } |
| 2416 | } |
| 2417 | } |
| 2418 | |
| 2419 | // For given pipelineLayout verify that the set_layout_node at slot.first |
| 2420 | // has the requested binding at slot.second and return ptr to that binding |
Mark Lobodzinski | ca6ebe3 | 2019-04-25 11:43:37 -0600 | [diff] [blame] | 2421 | static VkDescriptorSetLayoutBinding const *GetDescriptorBinding(PIPELINE_LAYOUT_STATE const *pipelineLayout, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2422 | descriptor_slot_t slot) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2423 | if (!pipelineLayout) return nullptr; |
| 2424 | |
| 2425 | if (slot.first >= pipelineLayout->set_layouts.size()) return nullptr; |
| 2426 | |
| 2427 | return pipelineLayout->set_layouts[slot.first]->GetDescriptorSetLayoutBindingPtrFromBinding(slot.second); |
| 2428 | } |
| 2429 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2430 | static bool FindLocalSize(SHADER_MODULE_STATE const *src, uint32_t &local_size_x, uint32_t &local_size_y, uint32_t &local_size_z) { |
Locke | 1ec6d95 | 2019-04-02 11:57:21 -0600 | [diff] [blame] | 2431 | for (auto insn : *src) { |
| 2432 | if (insn.opcode() == spv::OpEntryPoint) { |
| 2433 | auto executionModel = insn.word(1); |
| 2434 | auto entrypointStageBits = ExecutionModelToShaderStageFlagBits(executionModel); |
| 2435 | if (entrypointStageBits == VK_SHADER_STAGE_COMPUTE_BIT) { |
| 2436 | auto entrypoint_id = insn.word(2); |
| 2437 | for (auto insn1 : *src) { |
| 2438 | if (insn1.opcode() == spv::OpExecutionMode && insn1.word(1) == entrypoint_id && |
| 2439 | insn1.word(2) == spv::ExecutionModeLocalSize) { |
| 2440 | local_size_x = insn1.word(3); |
| 2441 | local_size_y = insn1.word(4); |
| 2442 | local_size_z = insn1.word(5); |
| 2443 | return true; |
| 2444 | } |
| 2445 | } |
| 2446 | } |
| 2447 | } |
| 2448 | } |
| 2449 | return false; |
| 2450 | } |
| 2451 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2452 | static void ProcessExecutionModes(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint, PIPELINE_STATE *pipeline) { |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 2453 | auto entrypoint_id = entrypoint.word(2); |
Chris Forbes | 0771b67 | 2018-03-22 21:13:46 -0700 | [diff] [blame] | 2454 | bool is_point_mode = false; |
| 2455 | |
| 2456 | for (auto insn : *src) { |
| 2457 | if (insn.opcode() == spv::OpExecutionMode && insn.word(1) == entrypoint_id) { |
| 2458 | switch (insn.word(2)) { |
| 2459 | case spv::ExecutionModePointMode: |
| 2460 | // In tessellation shaders, PointMode is separate and trumps the tessellation topology. |
| 2461 | is_point_mode = true; |
| 2462 | break; |
| 2463 | |
| 2464 | case spv::ExecutionModeOutputPoints: |
| 2465 | pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; |
| 2466 | break; |
| 2467 | |
| 2468 | case spv::ExecutionModeIsolines: |
| 2469 | case spv::ExecutionModeOutputLineStrip: |
| 2470 | pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP; |
| 2471 | break; |
| 2472 | |
| 2473 | case spv::ExecutionModeTriangles: |
| 2474 | case spv::ExecutionModeQuads: |
| 2475 | case spv::ExecutionModeOutputTriangleStrip: |
| 2476 | pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP; |
| 2477 | break; |
| 2478 | } |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | if (is_point_mode) pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_POINT_LIST; |
| 2483 | } |
| 2484 | |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2485 | // If PointList topology is specified in the pipeline, verify that a shader geometry stage writes PointSize |
| 2486 | // o If there is only a vertex shader : gl_PointSize must be written when using points |
| 2487 | // o If there is a geometry or tessellation shader: |
| 2488 | // - If shaderTessellationAndGeometryPointSize feature is enabled: |
| 2489 | // * gl_PointSize must be written in the final geometry stage |
| 2490 | // - If shaderTessellationAndGeometryPointSize feature is disabled: |
| 2491 | // * gl_PointSize must NOT be written and a default of 1.0 is assumed |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2492 | bool CoreChecks::ValidatePointListShaderState(const PIPELINE_STATE *pipeline, SHADER_MODULE_STATE const *src, |
| 2493 | spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2494 | if (pipeline->topology_at_rasterizer != VK_PRIMITIVE_TOPOLOGY_POINT_LIST) { |
| 2495 | return false; |
| 2496 | } |
| 2497 | |
| 2498 | bool pointsize_written = false; |
| 2499 | bool skip = false; |
| 2500 | |
| 2501 | // Search for PointSize built-in decorations |
| 2502 | std::vector<uint32_t> pointsize_builtin_offsets; |
| 2503 | spirv_inst_iter insn = entrypoint; |
| 2504 | while (!pointsize_written && (insn.opcode() != spv::OpFunction)) { |
| 2505 | if (insn.opcode() == spv::OpMemberDecorate) { |
| 2506 | if (insn.word(3) == spv::DecorationBuiltIn) { |
| 2507 | if (insn.word(4) == spv::BuiltInPointSize) { |
| 2508 | pointsize_written = IsPointSizeWritten(src, insn, entrypoint); |
| 2509 | } |
| 2510 | } |
| 2511 | } else if (insn.opcode() == spv::OpDecorate) { |
| 2512 | if (insn.word(2) == spv::DecorationBuiltIn) { |
| 2513 | if (insn.word(3) == spv::BuiltInPointSize) { |
| 2514 | pointsize_written = IsPointSizeWritten(src, insn, entrypoint); |
| 2515 | } |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | insn++; |
| 2520 | } |
| 2521 | |
| 2522 | if ((stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || stage == VK_SHADER_STAGE_GEOMETRY_BIT) && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2523 | !enabled_features.core.shaderTessellationAndGeometryPointSize) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2524 | if (pointsize_written) { |
Mark Lobodzinski | 93a1fa7 | 2019-04-19 12:12:25 -0600 | [diff] [blame] | 2525 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2526 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_PointSizeBuiltInOverSpecified, |
| 2527 | "Pipeline topology is set to POINT_LIST and geometry or tessellation shaders write PointSize which " |
| 2528 | "is prohibited when the shaderTessellationAndGeometryPointSize feature is not enabled."); |
| 2529 | } |
| 2530 | } else if (!pointsize_written) { |
| 2531 | skip |= |
Mark Lobodzinski | 93a1fa7 | 2019-04-19 12:12:25 -0600 | [diff] [blame] | 2532 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_PIPELINE_EXT, |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2533 | HandleToUint64(pipeline->pipeline), kVUID_Core_Shader_MissingPointSizeBuiltIn, |
| 2534 | "Pipeline topology is set to POINT_LIST, but PointSize is not written to in the shader corresponding to %s.", |
| 2535 | string_VkShaderStageFlagBits(stage)); |
| 2536 | } |
| 2537 | return skip; |
| 2538 | } |
| 2539 | |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2540 | bool CoreChecks::ValidatePipelineShaderStage(VkPipelineShaderStageCreateInfo const *pStage, PIPELINE_STATE *pipeline, |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2541 | SHADER_MODULE_STATE const **out_module, spirv_inst_iter *out_entrypoint, |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2542 | bool check_point_size) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2543 | bool skip = false; |
Mark Lobodzinski | 9e9da29 | 2019-03-06 16:19:55 -0700 | [diff] [blame] | 2544 | auto module = *out_module = GetShaderModuleState(pStage->module); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2545 | |
| 2546 | if (!module->has_valid_spirv) return false; |
| 2547 | |
| 2548 | // Find the entrypoint |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2549 | auto entrypoint = *out_entrypoint = FindEntrypoint(module, pStage->pName, pStage->stage); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2550 | if (entrypoint == module->end()) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2551 | if (log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 2552 | "VUID-VkPipelineShaderStageCreateInfo-pName-00707", "No entrypoint found named `%s` for stage %s..", |
| 2553 | pStage->pName, string_VkShaderStageFlagBits(pStage->stage))) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2554 | return true; // no point continuing beyond here, any analysis is just going to be garbage. |
| 2555 | } |
| 2556 | } |
| 2557 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2558 | // Mark accessible ids |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2559 | auto accessible_ids = MarkAccessibleIds(module, entrypoint); |
| 2560 | ProcessExecutionModes(module, entrypoint, pipeline); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2561 | |
| 2562 | // Validate descriptor set layout against what the entrypoint actually uses |
Chris Forbes | 8af2452 | 2018-03-07 11:37:45 -0800 | [diff] [blame] | 2563 | bool has_writable_descriptor = false; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2564 | auto descriptor_uses = CollectInterfaceByDescriptorSlot(report_data, module, accessible_ids, &has_writable_descriptor); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2565 | |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 2566 | // Validate shader capabilities against enabled device features |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2567 | skip |= ValidateShaderCapabilities(module, pStage->stage, has_writable_descriptor); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 2568 | skip |= ValidateShaderStageInputOutputLimits(module, pStage, pipeline, entrypoint); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2569 | skip |= ValidateExecutionModes(module, entrypoint); |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2570 | skip |= ValidateSpecializationOffsets(report_data, pStage); |
| 2571 | skip |= ValidatePushConstantUsage(report_data, pipeline->pipeline_layout.push_constant_ranges.get(), module, accessible_ids, |
| 2572 | pStage->stage); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2573 | if (check_point_size && !pipeline->graphicsPipelineCI.pRasterizationState->rasterizerDiscardEnable) { |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2574 | skip |= ValidatePointListShaderState(pipeline, module, entrypoint, pStage->stage); |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2575 | } |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 2576 | skip |= ValidateCooperativeMatrix(module, pStage, pipeline); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2577 | |
| 2578 | // Validate descriptor use |
| 2579 | for (auto use : descriptor_uses) { |
| 2580 | // While validating shaders capture which slots are used by the pipeline |
| 2581 | auto &reqs = pipeline->active_slots[use.first.first][use.first.second]; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2582 | reqs = descriptor_req(reqs | DescriptorTypeToReqs(module, use.second.type_id)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2583 | |
| 2584 | // Verify given pipelineLayout has requested setLayout with requested binding |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2585 | const auto &binding = GetDescriptorBinding(&pipeline->pipeline_layout, use.first); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2586 | unsigned required_descriptor_count; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2587 | std::set<uint32_t> descriptor_types = TypeToDescriptorTypeSet(module, use.second.type_id, required_descriptor_count); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2588 | |
| 2589 | if (!binding) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2590 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2591 | kVUID_Core_Shader_MissingDescriptor, |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 2592 | "Shader uses descriptor slot %u.%u (expected `%s`) but not declared in pipeline layout", |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2593 | use.first.first, use.first.second, string_descriptorTypes(descriptor_types).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2594 | } else if (~binding->stageFlags & pStage->stage) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2595 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2596 | kVUID_Core_Shader_DescriptorNotAccessibleFromStage, |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 2597 | "Shader uses descriptor slot %u.%u but descriptor not accessible from stage %s", use.first.first, |
| 2598 | use.first.second, string_VkShaderStageFlagBits(pStage->stage)); |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2599 | } else if (descriptor_types.find(binding->descriptorType) == descriptor_types.end()) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2600 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2601 | kVUID_Core_Shader_DescriptorTypeMismatch, |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 2602 | "Type mismatch on descriptor slot %u.%u (expected `%s`) but descriptor of type %s", use.first.first, |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 2603 | use.first.second, string_descriptorTypes(descriptor_types).c_str(), |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2604 | string_VkDescriptorType(binding->descriptorType)); |
| 2605 | } else if (binding->descriptorCount < required_descriptor_count) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2606 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2607 | kVUID_Core_Shader_DescriptorTypeMismatch, |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 2608 | "Shader expects at least %u descriptors for binding %u.%u but only %u provided", |
| 2609 | required_descriptor_count, use.first.first, use.first.second, binding->descriptorCount); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | // Validate use of input attachments against subpass structure |
| 2614 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2615 | auto input_attachment_uses = CollectInterfaceByInputAttachmentIndex(module, accessible_ids); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2616 | |
Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 2617 | auto rpci = pipeline->rp_state->createInfo.ptr(); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2618 | auto subpass = pipeline->graphicsPipelineCI.subpass; |
| 2619 | |
| 2620 | for (auto use : input_attachment_uses) { |
| 2621 | auto input_attachments = rpci->pSubpasses[subpass].pInputAttachments; |
| 2622 | auto index = (input_attachments && use.first < rpci->pSubpasses[subpass].inputAttachmentCount) |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2623 | ? input_attachments[use.first].attachment |
| 2624 | : VK_ATTACHMENT_UNUSED; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2625 | |
| 2626 | if (index == VK_ATTACHMENT_UNUSED) { |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2627 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2628 | kVUID_Core_Shader_MissingInputAttachment, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2629 | "Shader consumes input attachment index %d but not provided in subpass", use.first); |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2630 | } else if (!(GetFormatType(rpci->pAttachments[index].format) & GetFundamentalType(module, use.second.type_id))) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2631 | skip |= |
Mark Lobodzinski | b1fd9d1 | 2018-03-30 14:26:00 -0600 | [diff] [blame] | 2632 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2633 | kVUID_Core_Shader_InputAttachmentTypeMismatch, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2634 | "Subpass input attachment %u format of %s does not match type used in shader `%s`", use.first, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2635 | string_VkFormat(rpci->pAttachments[index].format), DescribeType(module, use.second.type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2636 | } |
| 2637 | } |
| 2638 | } |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2639 | if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT) { |
| 2640 | skip |= ValidateComputeWorkGroupSizes(module); |
| 2641 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2642 | return skip; |
| 2643 | } |
| 2644 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2645 | static bool ValidateInterfaceBetweenStages(debug_report_data const *report_data, SHADER_MODULE_STATE const *producer, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2646 | spirv_inst_iter producer_entrypoint, shader_stage_attributes const *producer_stage, |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2647 | SHADER_MODULE_STATE const *consumer, spirv_inst_iter consumer_entrypoint, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2648 | shader_stage_attributes const *consumer_stage) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2649 | bool skip = false; |
| 2650 | |
| 2651 | auto outputs = |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2652 | CollectInterfaceByLocation(producer, producer_entrypoint, spv::StorageClassOutput, producer_stage->arrayed_output); |
| 2653 | auto inputs = CollectInterfaceByLocation(consumer, consumer_entrypoint, spv::StorageClassInput, consumer_stage->arrayed_input); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2654 | |
| 2655 | auto a_it = outputs.begin(); |
| 2656 | auto b_it = inputs.begin(); |
| 2657 | |
| 2658 | // Maps sorted by key (location); walk them together to find mismatches |
| 2659 | while ((outputs.size() > 0 && a_it != outputs.end()) || (inputs.size() && b_it != inputs.end())) { |
| 2660 | bool a_at_end = outputs.size() == 0 || a_it == outputs.end(); |
| 2661 | bool b_at_end = inputs.size() == 0 || b_it == inputs.end(); |
| 2662 | auto a_first = a_at_end ? std::make_pair(0u, 0u) : a_it->first; |
| 2663 | auto b_first = b_at_end ? std::make_pair(0u, 0u) : b_it->first; |
| 2664 | |
| 2665 | if (b_at_end || ((!a_at_end) && (a_first < b_first))) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2666 | skip |= log_msg(report_data, VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2667 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_OutputNotConsumed, |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2668 | "%s writes to output location %u.%u which is not consumed by %s", producer_stage->name, a_first.first, |
| 2669 | a_first.second, consumer_stage->name); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2670 | a_it++; |
| 2671 | } else if (a_at_end || a_first > b_first) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2672 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2673 | HandleToUint64(consumer->vk_shader_module), kVUID_Core_Shader_InputNotProduced, |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2674 | "%s consumes input location %u.%u which is not written by %s", consumer_stage->name, b_first.first, |
| 2675 | b_first.second, producer_stage->name); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2676 | b_it++; |
| 2677 | } else { |
| 2678 | // subtleties of arrayed interfaces: |
| 2679 | // - if is_patch, then the member is not arrayed, even though the interface may be. |
| 2680 | // - if is_block_member, then the extra array level of an arrayed interface is not |
| 2681 | // expressed in the member type -- it's expressed in the block type. |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2682 | if (!TypesMatch(producer, consumer, a_it->second.type_id, b_it->second.type_id, |
| 2683 | producer_stage->arrayed_output && !a_it->second.is_patch && !a_it->second.is_block_member, |
| 2684 | consumer_stage->arrayed_input && !b_it->second.is_patch && !b_it->second.is_block_member, true)) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2685 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2686 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2687 | "Type mismatch on location %u.%u: '%s' vs '%s'", a_first.first, a_first.second, |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2688 | DescribeType(producer, a_it->second.type_id).c_str(), |
| 2689 | DescribeType(consumer, b_it->second.type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2690 | } |
| 2691 | if (a_it->second.is_patch != b_it->second.is_patch) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2692 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2693 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2694 | "Decoration mismatch on location %u.%u: is per-%s in %s stage but per-%s in %s stage", |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2695 | a_first.first, a_first.second, a_it->second.is_patch ? "patch" : "vertex", producer_stage->name, |
| 2696 | b_it->second.is_patch ? "patch" : "vertex", consumer_stage->name); |
| 2697 | } |
| 2698 | if (a_it->second.is_relaxed_precision != b_it->second.is_relaxed_precision) { |
Mark Young | 4e919b2 | 2018-05-21 15:53:59 -0600 | [diff] [blame] | 2699 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 2700 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2701 | "Decoration mismatch on location %u.%u: %s and %s stages differ in precision", a_first.first, |
| 2702 | a_first.second, producer_stage->name, consumer_stage->name); |
| 2703 | } |
| 2704 | a_it++; |
| 2705 | b_it++; |
| 2706 | } |
| 2707 | } |
| 2708 | |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 2709 | if (consumer_stage->stage != VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 2710 | auto builtins_producer = CollectBuiltinBlockMembers(producer, producer_entrypoint, spv::StorageClassOutput); |
| 2711 | auto builtins_consumer = CollectBuiltinBlockMembers(consumer, consumer_entrypoint, spv::StorageClassInput); |
| 2712 | |
| 2713 | if (!builtins_producer.empty() && !builtins_consumer.empty()) { |
| 2714 | if (builtins_producer.size() != builtins_consumer.size()) { |
| 2715 | skip |= |
| 2716 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2717 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
| 2718 | "Number of elements inside builtin block differ between stages (%s %d vs %s %d).", producer_stage->name, |
| 2719 | (int)builtins_producer.size(), consumer_stage->name, (int)builtins_consumer.size()); |
| 2720 | } else { |
| 2721 | auto it_producer = builtins_producer.begin(); |
| 2722 | auto it_consumer = builtins_consumer.begin(); |
| 2723 | while (it_producer != builtins_producer.end() && it_consumer != builtins_consumer.end()) { |
| 2724 | if (*it_producer != *it_consumer) { |
| 2725 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2726 | HandleToUint64(producer->vk_shader_module), kVUID_Core_Shader_InterfaceTypeMismatch, |
| 2727 | "Builtin variable inside block doesn't match between %s and %s.", producer_stage->name, |
| 2728 | consumer_stage->name); |
| 2729 | break; |
| 2730 | } |
| 2731 | it_producer++; |
| 2732 | it_consumer++; |
| 2733 | } |
| 2734 | } |
| 2735 | } |
| 2736 | } |
| 2737 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2738 | return skip; |
| 2739 | } |
| 2740 | |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2741 | static inline uint32_t DetermineFinalGeomStage(PIPELINE_STATE *pipeline, VkGraphicsPipelineCreateInfo *pCreateInfo) { |
| 2742 | uint32_t stage_mask = 0; |
| 2743 | if (pipeline->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) { |
| 2744 | for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { |
| 2745 | stage_mask |= pCreateInfo->pStages[i].stage; |
| 2746 | } |
| 2747 | // Determine which shader in which PointSize should be written (the final geometry stage) |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 2748 | if (stage_mask & VK_SHADER_STAGE_MESH_BIT_NV) { |
| 2749 | stage_mask = VK_SHADER_STAGE_MESH_BIT_NV; |
| 2750 | } else if (stage_mask & VK_SHADER_STAGE_GEOMETRY_BIT) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2751 | stage_mask = VK_SHADER_STAGE_GEOMETRY_BIT; |
| 2752 | } else if (stage_mask & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) { |
| 2753 | stage_mask = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
| 2754 | } else if (stage_mask & VK_SHADER_STAGE_VERTEX_BIT) { |
| 2755 | stage_mask = VK_SHADER_STAGE_VERTEX_BIT; |
Mark Lobodzinski | 2c984cc | 2018-07-31 09:57:46 -0600 | [diff] [blame] | 2756 | } |
| 2757 | } |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2758 | return stage_mask; |
Mark Lobodzinski | 2c984cc | 2018-07-31 09:57:46 -0600 | [diff] [blame] | 2759 | } |
| 2760 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2761 | // Validate that the shaders used by the given pipeline and store the active_slots |
| 2762 | // that are actually used by the pipeline into pPipeline->active_slots |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2763 | bool CoreChecks::ValidateAndCapturePipelineShaderState(PIPELINE_STATE *pipeline) { |
Chris Forbes | a400a8a | 2017-07-20 13:10:24 -0700 | [diff] [blame] | 2764 | auto pCreateInfo = pipeline->graphicsPipelineCI.ptr(); |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2765 | int vertex_stage = GetShaderStageId(VK_SHADER_STAGE_VERTEX_BIT); |
| 2766 | int fragment_stage = GetShaderStageId(VK_SHADER_STAGE_FRAGMENT_BIT); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2767 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2768 | SHADER_MODULE_STATE const *shaders[32]; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2769 | memset(shaders, 0, sizeof(shaders)); |
Jeff Bolz | 7e35c39 | 2018-09-04 15:30:41 -0500 | [diff] [blame] | 2770 | spirv_inst_iter entrypoints[32]; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2771 | memset(entrypoints, 0, sizeof(entrypoints)); |
| 2772 | bool skip = false; |
| 2773 | |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2774 | uint32_t pointlist_stage_mask = DetermineFinalGeomStage(pipeline, pCreateInfo); |
| 2775 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2776 | for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { |
| 2777 | auto pStage = &pCreateInfo->pStages[i]; |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2778 | auto stage_id = GetShaderStageId(pStage->stage); |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2779 | skip |= ValidatePipelineShaderStage(pStage, pipeline, &shaders[stage_id], &entrypoints[stage_id], |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2780 | (pointlist_stage_mask == pStage->stage)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | // if the shader stages are no good individually, cross-stage validation is pointless. |
| 2784 | if (skip) return true; |
| 2785 | |
| 2786 | auto vi = pCreateInfo->pVertexInputState; |
| 2787 | |
| 2788 | if (vi) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2789 | skip |= ValidateViConsistency(report_data, vi); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | if (shaders[vertex_stage] && shaders[vertex_stage]->has_valid_spirv) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2793 | skip |= ValidateViAgainstVsInputs(report_data, vi, shaders[vertex_stage], entrypoints[vertex_stage]); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2794 | } |
| 2795 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2796 | int producer = GetShaderStageId(VK_SHADER_STAGE_VERTEX_BIT); |
| 2797 | int consumer = GetShaderStageId(VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2798 | |
| 2799 | while (!shaders[producer] && producer != fragment_stage) { |
| 2800 | producer++; |
| 2801 | consumer++; |
| 2802 | } |
| 2803 | |
| 2804 | for (; producer != fragment_stage && consumer <= fragment_stage; consumer++) { |
| 2805 | assert(shaders[producer]); |
Chris Forbes | dbb43fc | 2018-02-16 16:59:23 -0800 | [diff] [blame] | 2806 | if (shaders[consumer]) { |
| 2807 | if (shaders[consumer]->has_valid_spirv && shaders[producer]->has_valid_spirv) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2808 | skip |= ValidateInterfaceBetweenStages(report_data, shaders[producer], entrypoints[producer], |
| 2809 | &shader_stage_attribs[producer], shaders[consumer], entrypoints[consumer], |
| 2810 | &shader_stage_attribs[consumer]); |
Chris Forbes | dbb43fc | 2018-02-16 16:59:23 -0800 | [diff] [blame] | 2811 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2812 | |
| 2813 | producer = consumer; |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | if (shaders[fragment_stage] && shaders[fragment_stage]->has_valid_spirv) { |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 2818 | skip |= ValidateFsOutputsAgainstRenderPass(report_data, shaders[fragment_stage], entrypoints[fragment_stage], pipeline, |
| 2819 | pCreateInfo->subpass); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | return skip; |
| 2823 | } |
| 2824 | |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2825 | bool CoreChecks::ValidateComputePipeline(PIPELINE_STATE *pipeline) { |
Chris Forbes | a400a8a | 2017-07-20 13:10:24 -0700 | [diff] [blame] | 2826 | auto pCreateInfo = pipeline->computePipelineCI.ptr(); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2827 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2828 | SHADER_MODULE_STATE const *module; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2829 | spirv_inst_iter entrypoint; |
| 2830 | |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2831 | return ValidatePipelineShaderStage(&pCreateInfo->stage, pipeline, &module, &entrypoint, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2832 | } |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2833 | |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2834 | bool CoreChecks::ValidateRayTracingPipelineNV(PIPELINE_STATE *pipeline) { |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2835 | auto pCreateInfo = pipeline->raytracingPipelineCI.ptr(); |
| 2836 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2837 | SHADER_MODULE_STATE const *module; |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2838 | spirv_inst_iter entrypoint; |
| 2839 | |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2840 | return ValidatePipelineShaderStage(pCreateInfo->pStages, pipeline, &module, &entrypoint, false); |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2841 | } |
| 2842 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2843 | uint32_t ValidationCache::MakeShaderHash(VkShaderModuleCreateInfo const *smci) { return XXH32(smci->pCode, smci->codeSize, 0); } |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2844 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2845 | static ValidationCache *GetValidationCacheInfo(VkShaderModuleCreateInfo const *pCreateInfo) { |
John Zulauf | 25ea243 | 2019-04-05 10:07:38 -0600 | [diff] [blame] | 2846 | const auto validation_cache_ci = lvl_find_in_chain<VkShaderModuleValidationCacheCreateInfoEXT>(pCreateInfo->pNext); |
| 2847 | if (validation_cache_ci) { |
John Zulauf | 146ee80 | 2019-04-05 15:31:06 -0600 | [diff] [blame] | 2848 | return CastFromHandle<ValidationCache *>(validation_cache_ci->validationCache); |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2849 | } |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2850 | return nullptr; |
| 2851 | } |
| 2852 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2853 | bool CoreChecks::PreCallValidateCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 2854 | const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule) { |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2855 | bool skip = false; |
| 2856 | spv_result_t spv_valid = SPV_SUCCESS; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2857 | |
Mark Lobodzinski | b02a485 | 2019-04-19 12:35:30 -0600 | [diff] [blame] | 2858 | if (disabled.shader_validation) { |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2859 | return false; |
| 2860 | } |
| 2861 | |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 2862 | auto have_glsl_shader = device_extensions.vk_nv_glsl_shader; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2863 | |
| 2864 | if (!have_glsl_shader && (pCreateInfo->codeSize % 4)) { |
Mark Lobodzinski | 7767ad8 | 2019-03-09 13:35:25 -0700 | [diff] [blame] | 2865 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 2866 | "VUID-VkShaderModuleCreateInfo-pCode-01376", |
| 2867 | "SPIR-V module not valid: Codesize must be a multiple of 4 but is " PRINTF_SIZE_T_SPECIFIER ".", |
| 2868 | pCreateInfo->codeSize); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2869 | } else { |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2870 | auto cache = GetValidationCacheInfo(pCreateInfo); |
| 2871 | uint32_t hash = 0; |
| 2872 | if (cache) { |
| 2873 | hash = ValidationCache::MakeShaderHash(pCreateInfo); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2874 | if (cache->Contains(hash)) return false; |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2877 | // Use SPIRV-Tools validator to try and catch any issues with the module itself |
Dave Houlton | 0ea2d01 | 2018-06-21 14:00:26 -0600 | [diff] [blame] | 2878 | spv_target_env spirv_environment = SPV_ENV_VULKAN_1_0; |
Mark Lobodzinski | 544def7 | 2019-04-19 14:25:59 -0600 | [diff] [blame] | 2879 | if (api_version >= VK_API_VERSION_1_1) { |
Dave Houlton | 0ea2d01 | 2018-06-21 14:00:26 -0600 | [diff] [blame] | 2880 | spirv_environment = SPV_ENV_VULKAN_1_1; |
| 2881 | } |
| 2882 | spv_context ctx = spvContextCreate(spirv_environment); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2883 | spv_const_binary_t binary{pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t)}; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2884 | spv_diagnostic diag = nullptr; |
Karl Schultz | fda1b38 | 2018-08-08 18:56:11 -0600 | [diff] [blame] | 2885 | spv_validator_options options = spvValidatorOptionsCreate(); |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 2886 | if (device_extensions.vk_khr_relaxed_block_layout) { |
Karl Schultz | fda1b38 | 2018-08-08 18:56:11 -0600 | [diff] [blame] | 2887 | spvValidatorOptionsSetRelaxBlockLayout(options, true); |
| 2888 | } |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 2889 | if (device_extensions.vk_ext_scalar_block_layout && |
Mark Lobodzinski | d7b03cc | 2019-04-19 14:23:10 -0600 | [diff] [blame] | 2890 | enabled_features.scalar_block_layout_features.scalarBlockLayout == VK_TRUE) { |
Tobias Hector | 6a0ece7 | 2018-12-10 12:24:05 +0000 | [diff] [blame] | 2891 | spvValidatorOptionsSetScalarBlockLayout(options, true); |
| 2892 | } |
Karl Schultz | fda1b38 | 2018-08-08 18:56:11 -0600 | [diff] [blame] | 2893 | spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2894 | if (spv_valid != SPV_SUCCESS) { |
| 2895 | if (!have_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) { |
Mark Lobodzinski | 7767ad8 | 2019-03-09 13:35:25 -0700 | [diff] [blame] | 2896 | skip |= |
| 2897 | log_msg(report_data, spv_valid == SPV_WARNING ? VK_DEBUG_REPORT_WARNING_BIT_EXT : VK_DEBUG_REPORT_ERROR_BIT_EXT, |
| 2898 | VK_DEBUG_REPORT_OBJECT_TYPE_UNKNOWN_EXT, 0, kVUID_Core_Shader_InconsistentSpirv, |
| 2899 | "SPIR-V module not valid: %s", diag && diag->error ? diag->error : "(no error text)"); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2900 | } |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2901 | } else { |
| 2902 | if (cache) { |
| 2903 | cache->Insert(hash); |
| 2904 | } |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2905 | } |
| 2906 | |
Karl Schultz | fda1b38 | 2018-08-08 18:56:11 -0600 | [diff] [blame] | 2907 | spvValidatorOptionsDestroy(options); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2908 | spvDiagnosticDestroy(diag); |
| 2909 | spvContextDestroy(ctx); |
| 2910 | } |
| 2911 | |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2912 | return skip; |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2913 | } |
| 2914 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2915 | void CoreChecks::PreCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 2916 | const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule, |
| 2917 | void *csm_state_data) { |
Mark Lobodzinski | 1db77e8 | 2019-03-01 10:02:54 -0700 | [diff] [blame] | 2918 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
Mark Lobodzinski | b02a485 | 2019-04-19 12:35:30 -0600 | [diff] [blame] | 2919 | if (enabled.gpu_validation) { |
Mark Lobodzinski | 586d10e | 2019-03-08 18:19:48 -0700 | [diff] [blame] | 2920 | GpuPreCallCreateShaderModule(pCreateInfo, pAllocator, pShaderModule, &csm_state->unique_shader_id, |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2921 | &csm_state->instrumented_create_info, &csm_state->instrumented_pgm); |
| 2922 | } |
| 2923 | } |
| 2924 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2925 | void CoreChecks::PostCallRecordCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
| 2926 | const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule, |
| 2927 | VkResult result, void *csm_state_data) { |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2928 | if (VK_SUCCESS != result) return; |
Mark Lobodzinski | 1db77e8 | 2019-03-01 10:02:54 -0700 | [diff] [blame] | 2929 | create_shader_module_api_state *csm_state = reinterpret_cast<create_shader_module_api_state *>(csm_state_data); |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2930 | |
Mark Lobodzinski | 544def7 | 2019-04-19 14:25:59 -0600 | [diff] [blame] | 2931 | spv_target_env spirv_environment = ((api_version >= VK_API_VERSION_1_1) ? SPV_ENV_VULKAN_1_1 : SPV_ENV_VULKAN_1_0); |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2932 | bool is_spirv = (pCreateInfo->pCode[0] == spv::MagicNumber); |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2933 | std::unique_ptr<SHADER_MODULE_STATE> new_shader_module( |
| 2934 | is_spirv ? new SHADER_MODULE_STATE(pCreateInfo, *pShaderModule, spirv_environment, csm_state->unique_shader_id) |
| 2935 | : new SHADER_MODULE_STATE()); |
Mark Lobodzinski | 7767ad8 | 2019-03-09 13:35:25 -0700 | [diff] [blame] | 2936 | shaderModuleMap[*pShaderModule] = std::move(new_shader_module); |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2937 | } |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2938 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 2939 | bool CoreChecks::ValidateComputeWorkGroupSizes(const SHADER_MODULE_STATE *shader) { |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2940 | bool skip = false; |
| 2941 | uint32_t local_size_x = 0; |
| 2942 | uint32_t local_size_y = 0; |
| 2943 | uint32_t local_size_z = 0; |
| 2944 | if (FindLocalSize(shader, local_size_x, local_size_y, local_size_z)) { |
| 2945 | if (local_size_x > phys_dev_props.limits.maxComputeWorkGroupSize[0]) { |
| 2946 | skip |= |
| 2947 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2948 | HandleToUint64(shader->vk_shader_module), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Juan A. Suarez Romero | f817c0e | 2019-05-28 12:33:17 +0200 | [diff] [blame] | 2949 | "ShaderModule %s local_size_x (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[0] (%" PRIu32 ").", |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2950 | report_data->FormatHandle(shader->vk_shader_module).c_str(), local_size_x, |
| 2951 | phys_dev_props.limits.maxComputeWorkGroupSize[0]); |
| 2952 | } |
| 2953 | if (local_size_y > phys_dev_props.limits.maxComputeWorkGroupSize[1]) { |
| 2954 | skip |= |
| 2955 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2956 | HandleToUint64(shader->vk_shader_module), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Juan A. Suarez Romero | f817c0e | 2019-05-28 12:33:17 +0200 | [diff] [blame] | 2957 | "ShaderModule %s local_size_y (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[1] (%" PRIu32 ").", |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2958 | report_data->FormatHandle(shader->vk_shader_module).c_str(), local_size_x, |
| 2959 | phys_dev_props.limits.maxComputeWorkGroupSize[1]); |
| 2960 | } |
| 2961 | if (local_size_z > phys_dev_props.limits.maxComputeWorkGroupSize[2]) { |
| 2962 | skip |= |
| 2963 | log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2964 | HandleToUint64(shader->vk_shader_module), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Juan A. Suarez Romero | f817c0e | 2019-05-28 12:33:17 +0200 | [diff] [blame] | 2965 | "ShaderModule %s local_size_z (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[2] (%" PRIu32 ").", |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2966 | report_data->FormatHandle(shader->vk_shader_module).c_str(), local_size_x, |
| 2967 | phys_dev_props.limits.maxComputeWorkGroupSize[2]); |
| 2968 | } |
| 2969 | |
| 2970 | uint32_t limit = phys_dev_props.limits.maxComputeWorkGroupInvocations; |
| 2971 | uint64_t invocations = local_size_x * local_size_y; |
| 2972 | // Prevent overflow. |
| 2973 | bool fail = false; |
| 2974 | if (invocations > UINT32_MAX || invocations > limit) { |
| 2975 | fail = true; |
| 2976 | } |
| 2977 | if (!fail) { |
| 2978 | invocations *= local_size_z; |
| 2979 | if (invocations > UINT32_MAX || invocations > limit) { |
| 2980 | fail = true; |
| 2981 | } |
| 2982 | } |
| 2983 | if (fail) { |
| 2984 | skip |= log_msg(report_data, VK_DEBUG_REPORT_ERROR_BIT_EXT, VK_DEBUG_REPORT_OBJECT_TYPE_SHADER_MODULE_EXT, |
| 2985 | HandleToUint64(shader->vk_shader_module), "UNASSIGNED-features-limits-maxComputeWorkGroupInvocations", |
Juan A. Suarez Romero | f817c0e | 2019-05-28 12:33:17 +0200 | [diff] [blame] | 2986 | "ShaderModule %s local_size (%" PRIu32 ", %" PRIu32 ", %" PRIu32 |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2987 | ") exceeds device limit maxComputeWorkGroupInvocations (%" PRIu32 ").", |
| 2988 | report_data->FormatHandle(shader->vk_shader_module).c_str(), local_size_x, local_size_y, local_size_z, |
| 2989 | limit); |
| 2990 | } |
| 2991 | } |
| 2992 | return skip; |
| 2993 | } |