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