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