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