sfricke-samsung | 691299b | 2021-01-01 20:48:48 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2015-2021 The Khronos Group Inc. |
| 2 | * Copyright (c) 2015-2021 Valve Corporation |
| 3 | * Copyright (c) 2015-2021 LunarG, Inc. |
| 4 | * Copyright (C) 2015-2021 Google Inc. |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 5 | * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved. |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | * you may not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | * |
| 19 | * Author: Chris Forbes <chrisf@ijw.co.nz> |
Dave Houlton | 5165390 | 2018-06-22 17:32:13 -0600 | [diff] [blame] | 20 | * Author: Dave Houlton <daveh@lunarg.com> |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 21 | * Author: Tobias Hector <tobias.hector@amd.com> |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 22 | */ |
| 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> |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 27 | #include <cinttypes> |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 28 | #include <cmath> |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 29 | #include <sstream> |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 30 | #include <string> |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 31 | #include <vector> |
| 32 | |
Mark Lobodzinski | 102687e | 2020-04-28 11:03:28 -0600 | [diff] [blame] | 33 | #include <spirv/unified1/spirv.hpp> |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 34 | #include "vk_enum_string_helper.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 35 | #include "vk_layer_data.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 36 | #include "vk_layer_utils.h" |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 37 | #include "chassis.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 38 | #include "core_validation.h" |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 39 | |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 40 | #include "xxhash.h" |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 41 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 42 | static shader_stage_attributes shader_stage_attribs[] = { |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 43 | {"vertex shader", false, false, VK_SHADER_STAGE_VERTEX_BIT}, |
| 44 | {"tessellation control shader", true, true, VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT}, |
| 45 | {"tessellation evaluation shader", true, false, VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT}, |
| 46 | {"geometry shader", true, false, VK_SHADER_STAGE_GEOMETRY_BIT}, |
| 47 | {"fragment shader", false, false, VK_SHADER_STAGE_FRAGMENT_BIT}, |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 50 | static bool BaseTypesMatch(SHADER_MODULE_STATE const *a, SHADER_MODULE_STATE const *b, const spirv_inst_iter &a_base_insn, |
| 51 | const spirv_inst_iter &b_base_insn) { |
| 52 | const uint32_t a_opcode = a_base_insn.opcode(); |
| 53 | const uint32_t b_opcode = b_base_insn.opcode(); |
| 54 | if (a_opcode == b_opcode) { |
| 55 | if (a_opcode == spv::OpTypeInt) { |
| 56 | // Match width and signedness |
| 57 | return a_base_insn.word(2) == b_base_insn.word(2) && a_base_insn.word(3) == b_base_insn.word(3); |
| 58 | } else if (a_opcode == spv::OpTypeFloat) { |
| 59 | // Match width |
| 60 | return a_base_insn.word(2) == b_base_insn.word(2); |
| 61 | } else if (a_opcode == spv::OpTypeStruct) { |
| 62 | // Match on all element types |
| 63 | if (a_base_insn.len() != b_base_insn.len()) { |
| 64 | return false; // Structs cannot match if member counts differ |
| 65 | } |
| 66 | |
| 67 | for (unsigned i = 2; i < a_base_insn.len(); i++) { |
| 68 | if (!BaseTypesMatch(a, b, a->get_def(a_base_insn.word(i)), b->get_def(b_base_insn.word(i)))) { |
| 69 | return false; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | } |
| 76 | return false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 77 | } |
| 78 | |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 79 | static bool TypesMatch(SHADER_MODULE_STATE const *a, SHADER_MODULE_STATE const *b, unsigned a_type, unsigned b_type) { |
| 80 | const auto &a_insn = a->get_def(a_type); |
| 81 | const auto &b_insn = b->get_def(b_type); |
| 82 | const uint32_t a_base_insn_id = a->GetBaseType(a_insn); |
| 83 | const uint32_t b_base_insn_id = b->GetBaseType(b_insn); |
| 84 | const auto &a_base_insn = a->get_def(a_base_insn_id); |
| 85 | const auto &b_base_insn = b->get_def(b_base_insn_id); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 86 | |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 87 | return BaseTypesMatch(a, b, a_base_insn, b_base_insn); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 90 | static unsigned GetLocationsConsumedByFormat(VkFormat format) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 91 | switch (format) { |
| 92 | case VK_FORMAT_R64G64B64A64_SFLOAT: |
| 93 | case VK_FORMAT_R64G64B64A64_SINT: |
| 94 | case VK_FORMAT_R64G64B64A64_UINT: |
| 95 | case VK_FORMAT_R64G64B64_SFLOAT: |
| 96 | case VK_FORMAT_R64G64B64_SINT: |
| 97 | case VK_FORMAT_R64G64B64_UINT: |
| 98 | return 2; |
| 99 | default: |
| 100 | return 1; |
| 101 | } |
| 102 | } |
| 103 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 104 | static unsigned GetFormatType(VkFormat fmt) { |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 105 | if (FormatIsSInt(fmt)) return FORMAT_TYPE_SINT; |
| 106 | if (FormatIsUInt(fmt)) return FORMAT_TYPE_UINT; |
| 107 | if (FormatIsDepthAndStencil(fmt)) return FORMAT_TYPE_FLOAT | FORMAT_TYPE_UINT; |
| 108 | if (fmt == VK_FORMAT_UNDEFINED) return 0; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 109 | // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader. |
| 110 | return FORMAT_TYPE_FLOAT; |
| 111 | } |
| 112 | |
Shannon McPherson | c06c33d | 2018-06-28 17:21:12 -0600 | [diff] [blame] | 113 | static uint32_t GetShaderStageId(VkShaderStageFlagBits stage) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 114 | uint32_t bit_pos = uint32_t(u_ffs(stage)); |
| 115 | return bit_pos - 1; |
| 116 | } |
| 117 | |
Mark Lobodzinski | d8d658e | 2020-01-30 15:05:51 -0700 | [diff] [blame] | 118 | bool CoreChecks::ValidateViConsistency(VkPipelineVertexInputStateCreateInfo const *vi) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 119 | // Walk the binding descriptions, which describe the step rate and stride of each vertex buffer. Each binding should |
| 120 | // be specified only once. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 121 | layer_data::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 122 | bool skip = false; |
| 123 | |
| 124 | for (unsigned i = 0; i < vi->vertexBindingDescriptionCount; i++) { |
| 125 | auto desc = &vi->pVertexBindingDescriptions[i]; |
| 126 | auto &binding = bindings[desc->binding]; |
| 127 | if (binding) { |
Dave Houlton | 78d0992 | 2018-05-17 15:48:45 -0600 | [diff] [blame] | 128 | // TODO: "VUID-VkGraphicsPipelineCreateInfo-pStages-00742" perhaps? |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 129 | skip |= LogError(device, kVUID_Core_Shader_InconsistentVi, "Duplicate vertex input binding descriptions for binding %d", |
| 130 | desc->binding); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 131 | } else { |
| 132 | binding = desc; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | return skip; |
| 137 | } |
| 138 | |
Mark Lobodzinski | d8d658e | 2020-01-30 15:05:51 -0700 | [diff] [blame] | 139 | bool CoreChecks::ValidateViAgainstVsInputs(VkPipelineVertexInputStateCreateInfo const *vi, SHADER_MODULE_STATE const *vs, |
| 140 | spirv_inst_iter entrypoint) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 141 | bool skip = false; |
| 142 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 143 | const auto inputs = vs->CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 144 | |
| 145 | // Build index by location |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 146 | std::map<uint32_t, const VkVertexInputAttributeDescription *> attribs; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 147 | if (vi) { |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 148 | for (uint32_t i = 0; i < vi->vertexAttributeDescriptionCount; ++i) { |
| 149 | const auto num_locations = GetLocationsConsumedByFormat(vi->pVertexAttributeDescriptions[i].format); |
| 150 | for (uint32_t j = 0; j < num_locations; ++j) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 151 | attribs[vi->pVertexAttributeDescriptions[i].location + j] = &vi->pVertexAttributeDescriptions[i]; |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 156 | struct AttribInputPair { |
| 157 | const VkVertexInputAttributeDescription *attrib = nullptr; |
| 158 | const interface_var *input = nullptr; |
| 159 | }; |
| 160 | std::map<uint32_t, AttribInputPair> location_map; |
| 161 | for (const auto &attrib_it : attribs) location_map[attrib_it.first].attrib = attrib_it.second; |
| 162 | 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] | 163 | |
Jamie Madill | c1f7ca8 | 2020-03-16 17:08:26 -0400 | [diff] [blame] | 164 | for (const auto &location_it : location_map) { |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 165 | const auto location = location_it.first; |
| 166 | const auto attrib = location_it.second.attrib; |
| 167 | const auto input = location_it.second.input; |
Mark Lobodzinski | 7caa39c | 2018-07-25 15:48:34 -0600 | [diff] [blame] | 168 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 169 | if (attrib && !input) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 170 | skip |= LogPerformanceWarning(vs->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 171 | "Vertex attribute at location %" PRIu32 " not consumed by vertex shader", location); |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 172 | } else if (!attrib && input) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 173 | skip |= LogError(vs->vk_shader_module(), kVUID_Core_Shader_InputNotProduced, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 174 | "Vertex shader consumes input at location %" PRIu32 " but not provided", location); |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 175 | } else if (attrib && input) { |
| 176 | const auto attrib_type = GetFormatType(attrib->format); |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 177 | const auto input_type = vs->GetFundamentalType(input->type_id); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 178 | |
| 179 | // Type checking |
| 180 | if (!(attrib_type & input_type)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 181 | skip |= LogError(vs->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 182 | "Attribute type of `%s` at location %" PRIu32 " does not match vertex shader input type of `%s`", |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 183 | string_VkFormat(attrib->format), location, vs->DescribeType(input->type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 184 | } |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 185 | } else { // !attrib && !input |
| 186 | assert(false); // at least one exists in the map |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | return skip; |
| 191 | } |
| 192 | |
Mark Lobodzinski | d8d658e | 2020-01-30 15:05:51 -0700 | [diff] [blame] | 193 | bool CoreChecks::ValidateFsOutputsAgainstRenderPass(SHADER_MODULE_STATE const *fs, spirv_inst_iter entrypoint, |
| 194 | PIPELINE_STATE const *pipeline, uint32_t subpass_index) const { |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 195 | bool skip = false; |
Chris Forbes | 8bca165 | 2017-07-20 11:10:09 -0700 | [diff] [blame] | 196 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 197 | const auto rpci = pipeline->rp_state->createInfo.ptr(); |
| 198 | |
Jeremy Hayes | 3699c7c | 2019-10-09 12:24:55 -0600 | [diff] [blame] | 199 | struct Attachment { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 200 | const VkAttachmentReference2 *reference = nullptr; |
| 201 | const VkAttachmentDescription2 *attachment = nullptr; |
Jeremy Hayes | 3699c7c | 2019-10-09 12:24:55 -0600 | [diff] [blame] | 202 | const interface_var *output = nullptr; |
| 203 | }; |
| 204 | std::map<uint32_t, Attachment> location_map; |
| 205 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 206 | const auto subpass = rpci->pSubpasses[subpass_index]; |
| 207 | for (uint32_t i = 0; i < subpass.colorAttachmentCount; ++i) { |
Jeremy Hayes | 3699c7c | 2019-10-09 12:24:55 -0600 | [diff] [blame] | 208 | auto const &reference = subpass.pColorAttachments[i]; |
| 209 | location_map[i].reference = &reference; |
| 210 | if (reference.attachment != VK_ATTACHMENT_UNUSED && |
| 211 | rpci->pAttachments[reference.attachment].format != VK_FORMAT_UNDEFINED) { |
| 212 | location_map[i].attachment = &rpci->pAttachments[reference.attachment]; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 216 | // TODO: dual source blend index (spv::DecIndex, zero if not provided) |
| 217 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 218 | const auto outputs = fs->CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false); |
Jeremy Hayes | 3699c7c | 2019-10-09 12:24:55 -0600 | [diff] [blame] | 219 | for (const auto &output_it : outputs) { |
| 220 | auto const location = output_it.first.first; |
| 221 | location_map[location].output = &output_it.second; |
| 222 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 223 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 224 | const bool alpha_to_coverage_enabled = pipeline->create_info.graphics.pMultisampleState != NULL && |
| 225 | pipeline->create_info.graphics.pMultisampleState->alphaToCoverageEnable == VK_TRUE; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 226 | |
Jamie Madill | c1f7ca8 | 2020-03-16 17:08:26 -0400 | [diff] [blame] | 227 | for (const auto &location_it : location_map) { |
Jeremy Hayes | 3699c7c | 2019-10-09 12:24:55 -0600 | [diff] [blame] | 228 | const auto reference = location_it.second.reference; |
| 229 | if (reference != nullptr && reference->attachment == VK_ATTACHMENT_UNUSED) { |
| 230 | continue; |
| 231 | } |
| 232 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 233 | const auto location = location_it.first; |
| 234 | const auto attachment = location_it.second.attachment; |
| 235 | const auto output = location_it.second.output; |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 236 | if (attachment && !output) { |
| 237 | if (pipeline->attachments[location].colorWriteMask != 0) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 238 | skip |= LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_InputNotProduced, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 239 | "Attachment %" PRIu32 |
| 240 | " not written by fragment shader; undefined values will be written to attachment", |
| 241 | location); |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 242 | } |
| 243 | } else if (!attachment && output) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 244 | if (!(alpha_to_coverage_enabled && location == 0)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 245 | skip |= LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 246 | "fragment shader writes to output location %" PRIu32 " with no matching attachment", location); |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 247 | } |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 248 | } else if (attachment && output) { |
| 249 | const auto attachment_type = GetFormatType(attachment->format); |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 250 | const auto output_type = fs->GetFundamentalType(output->type_id); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 251 | |
| 252 | // Type checking |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 253 | if (!(output_type & attachment_type)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 254 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 255 | LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 256 | "Attachment %" PRIu32 |
| 257 | " of type `%s` does not match fragment shader output type of `%s`; resulting values are undefined", |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 258 | location, string_VkFormat(attachment->format), fs->DescribeType(output->type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 259 | } |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 260 | } else { // !attachment && !output |
| 261 | assert(false); // at least one exists in the map |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | |
Petr Kraus | 25810d0 | 2019-08-27 17:41:15 +0200 | [diff] [blame] | 265 | const auto output_zero = location_map.count(0) ? location_map[0].output : nullptr; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 266 | bool location_zero_has_alpha = output_zero && fs->get_def(output_zero->type_id) != fs->end() && |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 267 | fs->GetComponentsConsumedByType(output_zero->type_id, false) == 4; |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 268 | if (alpha_to_coverage_enabled && !location_zero_has_alpha) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 269 | skip |= LogError(fs->vk_shader_module(), kVUID_Core_Shader_NoAlphaAtLocation0WithAlphaToCoverage, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 270 | "fragment shader doesn't declare alpha output at location 0 even though alpha to coverage is enabled."); |
Ari Suonpaa | 412b23b | 2019-02-26 07:56:58 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 273 | return skip; |
| 274 | } |
| 275 | |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 276 | PushConstantByteState CoreChecks::ValidatePushConstantSetUpdate(const std::vector<uint8_t> &push_constant_data_update, |
| 277 | const shader_struct_member &push_constant_used_in_shader, |
| 278 | uint32_t &out_issue_index) const { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 279 | const auto *used_bytes = push_constant_used_in_shader.GetUsedbytes(); |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 280 | const auto used_bytes_size = used_bytes->size(); |
| 281 | if (used_bytes_size == 0) return PC_Byte_Updated; |
| 282 | |
| 283 | const auto push_constant_data_update_size = push_constant_data_update.size(); |
| 284 | const auto *data = push_constant_data_update.data(); |
| 285 | if ((*data == PC_Byte_Updated) && std::memcmp(data, data + 1, push_constant_data_update_size - 1) == 0) { |
| 286 | if (used_bytes_size <= push_constant_data_update_size) { |
| 287 | return PC_Byte_Updated; |
| 288 | } |
| 289 | const auto used_bytes_size1 = used_bytes_size - push_constant_data_update_size; |
| 290 | |
| 291 | const auto *used_bytes_data1 = used_bytes->data() + push_constant_data_update_size; |
| 292 | if ((*used_bytes_data1 == 0) && std::memcmp(used_bytes_data1, used_bytes_data1 + 1, used_bytes_size1 - 1) == 0) { |
| 293 | return PC_Byte_Updated; |
| 294 | } |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 295 | } |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 296 | |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 297 | uint32_t i = 0; |
| 298 | for (const auto used : *used_bytes) { |
| 299 | if (used) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 300 | if (i >= push_constant_data_update.size() || push_constant_data_update[i] == PC_Byte_Not_Set) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 301 | out_issue_index = i; |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 302 | return PC_Byte_Not_Set; |
| 303 | } else if (push_constant_data_update[i] == PC_Byte_Not_Updated) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 304 | out_issue_index = i; |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 305 | return PC_Byte_Not_Updated; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 306 | } |
| 307 | } |
| 308 | ++i; |
| 309 | } |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 310 | return PC_Byte_Updated; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | bool CoreChecks::ValidatePushConstantUsage(const PIPELINE_STATE &pipeline, SHADER_MODULE_STATE const *src, |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 314 | VkPipelineShaderStageCreateInfo const *pStage, const std::string &vuid) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 315 | bool skip = false; |
sfricke-samsung | 5c65b37 | 2021-03-25 05:39:57 -0700 | [diff] [blame] | 316 | // Temp workaround to prevent false positive errors |
| 317 | // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2450 |
| 318 | if (src->multiple_entry_points) { |
| 319 | return skip; |
| 320 | } |
| 321 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 322 | // Validate directly off the offsets. this isn't quite correct for arrays and matrices, but is a good first step. |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 323 | const auto *entrypoint = src->FindEntrypointStruct(pStage->pName, pStage->stage); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 324 | if (!entrypoint || !entrypoint->push_constant_used_in_shader.IsUsed()) { |
| 325 | return skip; |
| 326 | } |
| 327 | std::vector<VkPushConstantRange> const *push_constant_ranges = pipeline.pipeline_layout->push_constant_ranges.get(); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 328 | |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 329 | bool found_stage = false; |
| 330 | for (auto const &range : *push_constant_ranges) { |
| 331 | if (range.stageFlags & pStage->stage) { |
| 332 | found_stage = true; |
| 333 | std::string location_desc; |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 334 | std::vector<uint8_t> push_constant_bytes_set; |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 335 | if (range.offset > 0) { |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 336 | push_constant_bytes_set.resize(range.offset, PC_Byte_Not_Set); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 337 | } |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 338 | push_constant_bytes_set.resize(range.offset + range.size, PC_Byte_Updated); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 339 | uint32_t issue_index = 0; |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 340 | const auto ret = |
| 341 | ValidatePushConstantSetUpdate(push_constant_bytes_set, entrypoint->push_constant_used_in_shader, issue_index); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 342 | |
locke-lunarg | 3d8b8f3 | 2020-10-26 17:04:16 -0600 | [diff] [blame] | 343 | if (ret == PC_Byte_Not_Set) { |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 344 | const auto loc_descr = entrypoint->push_constant_used_in_shader.GetLocationDesc(issue_index); |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 345 | LogObjectList objlist(src->vk_shader_module()); |
| 346 | objlist.add(pipeline.pipeline_layout->layout()); |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 347 | skip |= LogError(objlist, vuid, "Push constant buffer:%s in %s is out of range in %s.", loc_descr.c_str(), |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 348 | string_VkShaderStageFlags(pStage->stage).c_str(), |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 349 | report_data->FormatHandle(pipeline.pipeline_layout->layout()).c_str()); |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 350 | break; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | } |
| 354 | |
locke-lunarg | de3f0fa | 2020-09-10 11:55:31 -0600 | [diff] [blame] | 355 | if (!found_stage) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 356 | LogObjectList objlist(src->vk_shader_module()); |
| 357 | objlist.add(pipeline.pipeline_layout->layout()); |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 358 | skip |= LogError(objlist, vuid, "Push constant is used in %s of %s. But %s doesn't set %s.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 359 | string_VkShaderStageFlags(pStage->stage).c_str(), report_data->FormatHandle(src->vk_shader_module()).c_str(), |
| 360 | report_data->FormatHandle(pipeline.pipeline_layout->layout()).c_str(), |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 361 | string_VkShaderStageFlags(pStage->stage).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 362 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 363 | return skip; |
| 364 | } |
| 365 | |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 366 | bool CoreChecks::ValidateBuiltinLimits(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint) const { |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 367 | bool skip = false; |
| 368 | |
| 369 | // Currently all builtin tested are only found in fragment shaders |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 370 | if (entrypoint.word(1) != spv::ExecutionModelFragment) { |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 371 | return skip; |
| 372 | } |
| 373 | |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 374 | // Find all builtin from just the interface variables |
| 375 | for (uint32_t id : FindEntrypointInterfaces(entrypoint)) { |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 376 | auto insn = src->get_def(id); |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 377 | assert(insn.opcode() == spv::OpVariable); |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 378 | const decoration_set decorations = src->get_decorations(insn.word(2)); |
| 379 | |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 380 | // Currently don't need to search in structs |
| 381 | if (((decorations.flags & decoration_set::builtin_bit) != 0) && (decorations.builtin == spv::BuiltInSampleMask)) { |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 382 | auto type_pointer = src->get_def(insn.word(1)); |
| 383 | assert(type_pointer.opcode() == spv::OpTypePointer); |
| 384 | |
| 385 | auto type = src->get_def(type_pointer.word(3)); |
| 386 | if (type.opcode() == spv::OpTypeArray) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 387 | uint32_t length = static_cast<uint32_t>(src->GetConstantValueById(type.word(3))); |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 388 | // Handles both the input and output sampleMask |
| 389 | if (length > phys_dev_props.limits.maxSampleMaskWords) { |
| 390 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-maxSampleMaskWords-00711", |
| 391 | "vkCreateGraphicsPipelines(): The BuiltIns SampleMask array sizes is %u which exceeds " |
| 392 | "maxSampleMaskWords of %u in %s.", |
| 393 | length, phys_dev_props.limits.maxSampleMaskWords, |
| 394 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 395 | } |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 396 | break; |
sfricke-samsung | ef2a68c | 2020-10-26 04:22:46 -0700 | [diff] [blame] | 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | return skip; |
| 402 | } |
| 403 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 404 | // Validate that data for each specialization entry is fully contained within the buffer. |
ziga-lunarg | ae2a5c4 | 2021-07-23 16:18:09 +0200 | [diff] [blame] | 405 | bool CoreChecks::ValidateSpecializations(VkPipelineShaderStageCreateInfo const *info) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 406 | bool skip = false; |
| 407 | |
| 408 | VkSpecializationInfo const *spec = info->pSpecializationInfo; |
| 409 | |
| 410 | if (spec) { |
| 411 | for (auto i = 0u; i < spec->mapEntryCount; i++) { |
Jeremy Hayes | 6c555c3 | 2019-09-09 17:14:09 -0600 | [diff] [blame] | 412 | if (spec->pMapEntries[i].offset >= spec->dataSize) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 413 | skip |= LogError(device, "VUID-VkSpecializationInfo-offset-00773", |
| 414 | "Specialization entry %u (for constant id %u) references memory outside provided specialization " |
Petr Kraus | b0d5e59 | 2021-05-21 23:37:11 +0200 | [diff] [blame] | 415 | "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 416 | i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset, |
| 417 | spec->pMapEntries[i].offset + spec->dataSize - 1, spec->dataSize); |
Jeremy Hayes | 6c555c3 | 2019-09-09 17:14:09 -0600 | [diff] [blame] | 418 | |
| 419 | continue; |
| 420 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 421 | if (spec->pMapEntries[i].offset + spec->pMapEntries[i].size > spec->dataSize) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 422 | skip |= LogError(device, "VUID-VkSpecializationInfo-pMapEntries-00774", |
| 423 | "Specialization entry %u (for constant id %u) references memory outside provided specialization " |
Petr Kraus | b0d5e59 | 2021-05-21 23:37:11 +0200 | [diff] [blame] | 424 | "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 425 | i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset, |
| 426 | spec->pMapEntries[i].offset + spec->pMapEntries[i].size - 1, spec->dataSize); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 427 | } |
ziga-lunarg | ae2a5c4 | 2021-07-23 16:18:09 +0200 | [diff] [blame] | 428 | for (uint32_t j = i + 1; j < spec->mapEntryCount; ++j) { |
| 429 | if (spec->pMapEntries[i].constantID == spec->pMapEntries[j].constantID) { |
| 430 | skip |= LogError(device, "VUID-VkSpecializationInfo-constantID-04911", |
| 431 | "Specialization entry %" PRIu32 " and %" PRIu32 " have the same constantID (%" PRIu32 ").", i, |
| 432 | j, spec->pMapEntries[i].constantID); |
| 433 | } |
| 434 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
| 438 | return skip; |
| 439 | } |
| 440 | |
Jeff Bolz | 38b3ce7 | 2018-09-19 12:53:38 -0500 | [diff] [blame] | 441 | // TODO (jbolz): Can this return a const reference? |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 442 | static std::set<uint32_t> TypeToDescriptorTypeSet(SHADER_MODULE_STATE const *module, uint32_t type_id, unsigned &descriptor_count, |
| 443 | bool is_khr) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 444 | auto type = module->get_def(type_id); |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 445 | bool is_storage_buffer = false; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 446 | descriptor_count = 1; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 447 | std::set<uint32_t> ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 448 | |
| 449 | // 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] | 450 | while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray) { |
| 451 | if (type.opcode() == spv::OpTypeRuntimeArray) { |
| 452 | descriptor_count = 0; |
| 453 | type = module->get_def(type.word(2)); |
| 454 | } else if (type.opcode() == spv::OpTypeArray) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 455 | descriptor_count *= module->GetConstantValueById(type.word(3)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 456 | type = module->get_def(type.word(2)); |
| 457 | } else { |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 458 | if (type.word(2) == spv::StorageClassStorageBuffer) { |
| 459 | is_storage_buffer = true; |
| 460 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 461 | type = module->get_def(type.word(3)); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | switch (type.opcode()) { |
| 466 | case spv::OpTypeStruct: { |
sfricke-samsung | 94d71a5 | 2021-02-26 05:25:43 -0800 | [diff] [blame] | 467 | for (auto insn : module->decoration_inst) { |
| 468 | if (insn.word(1) == type.word(1)) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 469 | if (insn.word(2) == spv::DecorationBlock) { |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 470 | if (is_storage_buffer) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 471 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); |
| 472 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC); |
| 473 | return ret; |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 474 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 475 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); |
| 476 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC); |
| 477 | ret.insert(VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT); |
| 478 | return ret; |
Chris Forbes | 9f89d75 | 2018-03-07 12:57:48 -0800 | [diff] [blame] | 479 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 480 | } else if (insn.word(2) == spv::DecorationBufferBlock) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 481 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); |
| 482 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC); |
| 483 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | // Invalid |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 489 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | case spv::OpTypeSampler: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 493 | ret.insert(VK_DESCRIPTOR_TYPE_SAMPLER); |
| 494 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 495 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 496 | |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 497 | case spv::OpTypeSampledImage: { |
| 498 | // Slight relaxation for some GLSL historical madness: samplerBuffer doesn't really have a sampler, and a texel |
| 499 | // buffer descriptor doesn't really provide one. Allow this slight mismatch. |
| 500 | auto image_type = module->get_def(type.word(2)); |
| 501 | auto dim = image_type.word(3); |
| 502 | auto sampled = image_type.word(7); |
| 503 | if (dim == spv::DimBuffer && sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 504 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER); |
| 505 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 506 | } |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 507 | } |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 508 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 509 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 510 | |
| 511 | case spv::OpTypeImage: { |
| 512 | // Many descriptor types backing image types-- depends on dimension and whether the image will be used with a sampler. |
| 513 | // SPIRV for Vulkan requires that sampled be 1 or 2 -- leaving the decision to runtime is unacceptable. |
| 514 | auto dim = type.word(3); |
| 515 | auto sampled = type.word(7); |
| 516 | |
| 517 | if (dim == spv::DimSubpassData) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 518 | ret.insert(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT); |
| 519 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 520 | } else if (dim == spv::DimBuffer) { |
| 521 | if (sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 522 | ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER); |
| 523 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 524 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 525 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER); |
| 526 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 527 | } |
| 528 | } else if (sampled == 1) { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 529 | ret.insert(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); |
| 530 | ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER); |
| 531 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 532 | } else { |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 533 | ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE); |
| 534 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 535 | } |
| 536 | } |
Shannon McPherson | 0fa2823 | 2018-11-01 11:59:02 -0600 | [diff] [blame] | 537 | case spv::OpTypeAccelerationStructureNV: |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 538 | is_khr ? ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR) |
| 539 | : ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV); |
Jeff Bolz | 105d649 | 2018-09-29 15:46:44 -0500 | [diff] [blame] | 540 | return ret; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 541 | |
| 542 | // We shouldn't really see any other junk types -- but if we do, they're a mismatch. |
| 543 | default: |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 544 | return ret; // Matches nothing |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 545 | } |
| 546 | } |
| 547 | |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 548 | static std::string string_descriptorTypes(const std::set<uint32_t> &descriptor_types) { |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 549 | std::stringstream ss; |
Jeff Bolz | e54ae89 | 2018-09-08 12:16:29 -0500 | [diff] [blame] | 550 | for (auto it = descriptor_types.begin(); it != descriptor_types.end(); ++it) { |
| 551 | if (ss.tellp()) ss << ", "; |
| 552 | ss << string_VkDescriptorType(VkDescriptorType(*it)); |
Chris Forbes | 73c00bf | 2018-06-22 16:28:06 -0700 | [diff] [blame] | 553 | } |
| 554 | return ss.str(); |
| 555 | } |
| 556 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 557 | bool CoreChecks::RequirePropertyFlag(VkBool32 check, char const *flag, char const *structure, const char *vuid) const { |
Jeff Bolz | ee74341 | 2019-06-20 22:24:32 -0500 | [diff] [blame] | 558 | if (!check) { |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 559 | if (LogError(device, vuid, "Shader requires flag %s set in %s but it is not set on the device", flag, structure)) { |
Jeff Bolz | ee74341 | 2019-06-20 22:24:32 -0500 | [diff] [blame] | 560 | return true; |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | return false; |
| 565 | } |
| 566 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 567 | bool CoreChecks::RequireFeature(VkBool32 feature, char const *feature_name, const char *vuid) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 568 | if (!feature) { |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 569 | if (LogError(device, vuid, "Shader requires %s but is not enabled on the device", feature_name)) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 570 | return true; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | return false; |
| 575 | } |
| 576 | |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 577 | bool CoreChecks::ValidateShaderStageWritableOrAtomicDescriptor(VkShaderStageFlagBits stage, bool has_writable_descriptor, |
| 578 | bool has_atomic_descriptor) const { |
Jeff Bolz | ee74341 | 2019-06-20 22:24:32 -0500 | [diff] [blame] | 579 | bool skip = false; |
| 580 | |
locke-lunarg | 63e4daf | 2020-08-17 17:53:25 -0600 | [diff] [blame] | 581 | if (has_writable_descriptor || has_atomic_descriptor) { |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 582 | switch (stage) { |
| 583 | case VK_SHADER_STAGE_COMPUTE_BIT: |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 584 | case VK_SHADER_STAGE_RAYGEN_BIT_NV: |
| 585 | case VK_SHADER_STAGE_ANY_HIT_BIT_NV: |
| 586 | case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV: |
| 587 | case VK_SHADER_STAGE_MISS_BIT_NV: |
| 588 | case VK_SHADER_STAGE_INTERSECTION_BIT_NV: |
| 589 | case VK_SHADER_STAGE_CALLABLE_BIT_NV: |
| 590 | case VK_SHADER_STAGE_TASK_BIT_NV: |
| 591 | case VK_SHADER_STAGE_MESH_BIT_NV: |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 592 | /* No feature requirements for writes and atomics from compute |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 593 | * raytracing, or mesh stages */ |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 594 | break; |
| 595 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 596 | skip |= RequireFeature(enabled_features.core.fragmentStoresAndAtomics, "fragmentStoresAndAtomics", |
| 597 | kVUID_Core_Shader_FeatureNotEnabled); |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 598 | break; |
| 599 | default: |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 600 | skip |= RequireFeature(enabled_features.core.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics", |
| 601 | kVUID_Core_Shader_FeatureNotEnabled); |
Chris Forbes | 349b313 | 2018-03-07 11:38:08 -0800 | [diff] [blame] | 602 | break; |
| 603 | } |
| 604 | } |
| 605 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 606 | return skip; |
| 607 | } |
| 608 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 609 | bool CoreChecks::ValidateShaderStageGroupNonUniform(SHADER_MODULE_STATE const *module, VkShaderStageFlagBits stage, |
| 610 | spirv_inst_iter &insn) const { |
Jeff Bolz | ee74341 | 2019-06-20 22:24:32 -0500 | [diff] [blame] | 611 | bool skip = false; |
| 612 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 613 | // Check anything using a group operation (which currently is only OpGroupNonUnifrom* operations) |
| 614 | if (GroupOperation(insn.opcode()) == true) { |
| 615 | // Check the quad operations. |
| 616 | if ((insn.opcode() == spv::OpGroupNonUniformQuadBroadcast) || (insn.opcode() == spv::OpGroupNonUniformQuadSwap)) { |
| 617 | if ((stage != VK_SHADER_STAGE_FRAGMENT_BIT) && (stage != VK_SHADER_STAGE_COMPUTE_BIT)) { |
| 618 | skip |= RequireFeature(phys_dev_props_core11.subgroupQuadOperationsInAllStages, |
| 619 | "VkPhysicalDeviceSubgroupProperties::quadOperationsInAllStages", |
| 620 | kVUID_Core_Shader_FeatureNotEnabled); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 621 | } |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 622 | } |
Jeff Bolz | 526f2d5 | 2019-09-18 13:18:08 -0500 | [diff] [blame] | 623 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 624 | uint32_t scope_type = spv::ScopeMax; |
| 625 | if (insn.opcode() == spv::OpGroupNonUniformPartitionNV) { |
| 626 | // OpGroupNonUniformPartitionNV always assumed subgroup as missing operand |
| 627 | scope_type = spv::ScopeSubgroup; |
| 628 | } else { |
| 629 | // "All <id> used for Scope <id> must be of an OpConstant" |
| 630 | auto scope_id = module->get_def(insn.word(3)); |
| 631 | scope_type = scope_id.word(3); |
| 632 | } |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 633 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 634 | if (scope_type == spv::ScopeSubgroup) { |
| 635 | // "Group operations with subgroup scope" must have stage support |
| 636 | const VkSubgroupFeatureFlags supported_stages = phys_dev_props_core11.subgroupSupportedStages; |
| 637 | skip |= RequirePropertyFlag(supported_stages & stage, string_VkShaderStageFlagBits(stage), |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 638 | "VkPhysicalDeviceSubgroupProperties::supportedStages", kVUID_Core_Shader_ExceedDeviceLimit); |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | if (!enabled_features.core12.shaderSubgroupExtendedTypes) { |
| 642 | auto type = module->get_def(insn.word(1)); |
| 643 | |
| 644 | if (type.opcode() == spv::OpTypeVector) { |
| 645 | // Get the element type |
| 646 | type = module->get_def(type.word(2)); |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 647 | } |
| 648 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 649 | if (type.opcode() != spv::OpTypeBool) { |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 650 | // Both OpTypeInt and OpTypeFloat the width is in the 2nd word. |
| 651 | const uint32_t width = type.word(2); |
Jeff Bolz | 526f2d5 | 2019-09-18 13:18:08 -0500 | [diff] [blame] | 652 | |
sfricke-samsung | 0065ce0 | 2020-12-03 22:46:37 -0800 | [diff] [blame] | 653 | if ((type.opcode() == spv::OpTypeFloat && width == 16) || |
| 654 | (type.opcode() == spv::OpTypeInt && (width == 8 || width == 16 || width == 64))) { |
| 655 | skip |= RequireFeature(enabled_features.core12.shaderSubgroupExtendedTypes, |
| 656 | "VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures::shaderSubgroupExtendedTypes", |
| 657 | kVUID_Core_Shader_FeatureNotEnabled); |
Jeff Bolz | 526f2d5 | 2019-09-18 13:18:08 -0500 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | } |
Jeff Bolz | ee74341 | 2019-06-20 22:24:32 -0500 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return skip; |
| 664 | } |
| 665 | |
ziga-lunarg | 2818f49 | 2021-08-12 14:30:51 +0200 | [diff] [blame] | 666 | bool CoreChecks::ValidateWorkgroupSize(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
| 667 | const std::unordered_map<uint32_t, std::vector<uint32_t>>& id_value_map) const { |
| 668 | bool skip = false; |
| 669 | |
| 670 | std::array<uint32_t, 3> work_group_size = src->GetWorkgroupSize(pStage, id_value_map); |
| 671 | |
| 672 | for (uint32_t i = 0; i < 3; ++i) { |
| 673 | if (work_group_size[i] > phys_dev_props.limits.maxComputeWorkGroupSize[i]) { |
| 674 | const char member = 'x' + static_cast<int8_t>(i); |
| 675 | skip |= LogError(device, kVUID_Core_Shader_MaxComputeWorkGroupSize, |
| 676 | "Specialization constant is being used to specialize WorkGroupSize.%c, but value (%" PRIu32 |
| 677 | ") is greater than VkPhysicalDeviceLimits::maxComputeWorkGroupSize[%" PRIu32 "] = %" PRIu32 ".", |
| 678 | member, work_group_size[i], i, phys_dev_props.limits.maxComputeWorkGroupSize[i]); |
| 679 | } |
| 680 | } |
| 681 | return skip; |
| 682 | } |
| 683 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 684 | bool CoreChecks::ValidateShaderStageInputOutputLimits(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
John Zulauf | ac4c6e1 | 2019-07-01 16:05:58 -0600 | [diff] [blame] | 685 | const PIPELINE_STATE *pipeline, spirv_inst_iter entrypoint) const { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 686 | if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT || pStage->stage == VK_SHADER_STAGE_ALL_GRAPHICS || |
| 687 | pStage->stage == VK_SHADER_STAGE_ALL) { |
| 688 | return false; |
| 689 | } |
| 690 | |
| 691 | bool skip = false; |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 692 | auto const &limits = phys_dev_props.limits; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 693 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 694 | std::set<uint32_t> patch_i_ds; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 695 | struct Variable { |
| 696 | uint32_t baseTypePtrID; |
| 697 | uint32_t ID; |
| 698 | uint32_t storageClass; |
| 699 | }; |
| 700 | std::vector<Variable> variables; |
| 701 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 702 | uint32_t num_vertices = 0; |
Nathaniel Cesario | 75fb722 | 2020-12-07 10:54:53 -0700 | [diff] [blame] | 703 | bool is_iso_lines = false; |
| 704 | bool is_point_mode = false; |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 705 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 706 | auto entrypoint_variables = FindEntrypointInterfaces(entrypoint); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 707 | |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 708 | for (auto insn : *src) { |
| 709 | switch (insn.opcode()) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 710 | // Find all Patch decorations |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 711 | case spv::OpDecorate: |
| 712 | switch (insn.word(2)) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 713 | case spv::DecorationPatch: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 714 | patch_i_ds.insert(insn.word(1)); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 715 | break; |
| 716 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 717 | default: |
| 718 | break; |
| 719 | } |
| 720 | break; |
| 721 | // Find all input and output variables |
| 722 | case spv::OpVariable: { |
| 723 | Variable var = {}; |
| 724 | var.storageClass = insn.word(3); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 725 | if ((var.storageClass == spv::StorageClassInput || var.storageClass == spv::StorageClassOutput) && |
| 726 | // Only include variables in the entrypoint's interface |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 727 | find(entrypoint_variables.begin(), entrypoint_variables.end(), insn.word(2)) != entrypoint_variables.end()) { |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 728 | var.baseTypePtrID = insn.word(1); |
| 729 | var.ID = insn.word(2); |
| 730 | variables.push_back(var); |
| 731 | } |
| 732 | break; |
| 733 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 734 | case spv::OpExecutionMode: |
| 735 | if (insn.word(1) == entrypoint.word(2)) { |
| 736 | switch (insn.word(2)) { |
| 737 | default: |
| 738 | break; |
| 739 | case spv::ExecutionModeOutputVertices: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 740 | num_vertices = insn.word(3); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 741 | break; |
Nathaniel Cesario | 75fb722 | 2020-12-07 10:54:53 -0700 | [diff] [blame] | 742 | case spv::ExecutionModeIsolines: |
| 743 | is_iso_lines = true; |
| 744 | break; |
| 745 | case spv::ExecutionModePointMode: |
| 746 | is_point_mode = true; |
| 747 | break; |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 748 | } |
| 749 | } |
| 750 | break; |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 751 | default: |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 756 | bool strip_output_array_level = |
| 757 | (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStage->stage == VK_SHADER_STAGE_MESH_BIT_NV); |
| 758 | bool strip_input_array_level = |
| 759 | (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || |
| 760 | pStage->stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || pStage->stage == VK_SHADER_STAGE_GEOMETRY_BIT); |
| 761 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 762 | uint32_t num_comp_in = 0, num_comp_out = 0; |
| 763 | int max_comp_in = 0, max_comp_out = 0; |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 764 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 765 | auto inputs = src->CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, strip_input_array_level); |
| 766 | auto outputs = src->CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, strip_output_array_level); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 767 | |
| 768 | // Find max component location used for input variables. |
| 769 | for (auto &var : inputs) { |
| 770 | int location = var.first.first; |
| 771 | int component = var.first.second; |
| 772 | interface_var &iv = var.second; |
| 773 | |
| 774 | // Only need to look at the first location, since we use the type's whole size |
| 775 | if (iv.offset != 0) { |
| 776 | continue; |
| 777 | } |
| 778 | |
| 779 | if (iv.is_patch) { |
| 780 | continue; |
| 781 | } |
| 782 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 783 | int num_components = src->GetComponentsConsumedByType(iv.type_id, strip_input_array_level); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 784 | max_comp_in = std::max(max_comp_in, location * 4 + component + num_components); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | // Find max component location used for output variables. |
| 788 | for (auto &var : outputs) { |
| 789 | int location = var.first.first; |
| 790 | int component = var.first.second; |
| 791 | interface_var &iv = var.second; |
| 792 | |
| 793 | // Only need to look at the first location, since we use the type's whole size |
| 794 | if (iv.offset != 0) { |
| 795 | continue; |
| 796 | } |
| 797 | |
| 798 | if (iv.is_patch) { |
| 799 | continue; |
| 800 | } |
| 801 | |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 802 | int num_components = src->GetComponentsConsumedByType(iv.type_id, strip_output_array_level); |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 803 | max_comp_out = std::max(max_comp_out, location * 4 + component + num_components); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | // XXX TODO: Would be nice to rewrite this to use CollectInterfaceByLocation (or something similar), |
| 807 | // but that doesn't include builtins. |
sfricke-samsung | 406766a | 2021-07-02 12:04:09 -0700 | [diff] [blame] | 808 | // When rewritten, using the CreatePipelineExceedVertexMaxComponentsWithBuiltins test it would be nice to also let the user know |
| 809 | // how many components were from builtins as it might not be obvious |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 810 | for (auto &var : variables) { |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 811 | // Check if the variable is a patch. Patches can also be members of blocks, |
| 812 | // but if they are then the top-level arrayness has already been stripped |
| 813 | // by the time GetComponentsConsumedByType gets to it. |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 814 | bool is_patch = patch_i_ds.find(var.ID) != patch_i_ds.end(); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 815 | |
| 816 | if (var.storageClass == spv::StorageClassInput) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 817 | num_comp_in += src->GetComponentsConsumedByType(var.baseTypePtrID, strip_input_array_level && !is_patch); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 818 | } else { // var.storageClass == spv::StorageClassOutput |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 819 | num_comp_out += src->GetComponentsConsumedByType(var.baseTypePtrID, strip_output_array_level && !is_patch); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
| 823 | switch (pStage->stage) { |
| 824 | case VK_SHADER_STAGE_VERTEX_BIT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 825 | if (num_comp_out > limits.maxVertexOutputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 826 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 827 | "Invalid Pipeline CreateInfo State: Vertex shader exceeds " |
| 828 | "VkPhysicalDeviceLimits::maxVertexOutputComponents of %u " |
| 829 | "components by %u components", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 830 | limits.maxVertexOutputComponents, num_comp_out - limits.maxVertexOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 831 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 832 | if (max_comp_out > static_cast<int>(limits.maxVertexOutputComponents)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 833 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 834 | "Invalid Pipeline CreateInfo State: Vertex shader output variable uses location that " |
| 835 | "exceeds component limit VkPhysicalDeviceLimits::maxVertexOutputComponents (%u)", |
| 836 | limits.maxVertexOutputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 837 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 838 | break; |
| 839 | |
| 840 | case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 841 | if (num_comp_in > limits.maxTessellationControlPerVertexInputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 842 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 843 | "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds " |
| 844 | "VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents of %u " |
| 845 | "components by %u components", |
| 846 | limits.maxTessellationControlPerVertexInputComponents, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 847 | num_comp_in - limits.maxTessellationControlPerVertexInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 848 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 849 | if (max_comp_in > static_cast<int>(limits.maxTessellationControlPerVertexInputComponents)) { |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 850 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 851 | LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 852 | "Invalid Pipeline CreateInfo State: Tessellation control shader input variable uses location that " |
| 853 | "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents (%u)", |
| 854 | limits.maxTessellationControlPerVertexInputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 855 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 856 | if (num_comp_out > limits.maxTessellationControlPerVertexOutputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 857 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 858 | "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds " |
| 859 | "VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents of %u " |
| 860 | "components by %u components", |
| 861 | limits.maxTessellationControlPerVertexOutputComponents, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 862 | num_comp_out - limits.maxTessellationControlPerVertexOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 863 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 864 | if (max_comp_out > static_cast<int>(limits.maxTessellationControlPerVertexOutputComponents)) { |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 865 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 866 | LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 867 | "Invalid Pipeline CreateInfo State: Tessellation control shader output variable uses location that " |
| 868 | "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents (%u)", |
| 869 | limits.maxTessellationControlPerVertexOutputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 870 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 874 | if (num_comp_in > limits.maxTessellationEvaluationInputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 875 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 876 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds " |
| 877 | "VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents of %u " |
| 878 | "components by %u components", |
| 879 | limits.maxTessellationEvaluationInputComponents, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 880 | num_comp_in - limits.maxTessellationEvaluationInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 881 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 882 | if (max_comp_in > static_cast<int>(limits.maxTessellationEvaluationInputComponents)) { |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 883 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 884 | LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 885 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader input variable uses location that " |
| 886 | "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents (%u)", |
| 887 | limits.maxTessellationEvaluationInputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 888 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 889 | if (num_comp_out > limits.maxTessellationEvaluationOutputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 890 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 891 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds " |
| 892 | "VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents of %u " |
| 893 | "components by %u components", |
| 894 | limits.maxTessellationEvaluationOutputComponents, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 895 | num_comp_out - limits.maxTessellationEvaluationOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 896 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 897 | if (max_comp_out > static_cast<int>(limits.maxTessellationEvaluationOutputComponents)) { |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 898 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 899 | LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 900 | "Invalid Pipeline CreateInfo State: Tessellation evaluation shader output variable uses location that " |
| 901 | "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents (%u)", |
| 902 | limits.maxTessellationEvaluationOutputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 903 | } |
Nathaniel Cesario | 75fb722 | 2020-12-07 10:54:53 -0700 | [diff] [blame] | 904 | // Portability validation |
| 905 | if (IsExtEnabled(device_extensions.vk_khr_portability_subset)) { |
| 906 | if (is_iso_lines && (VK_FALSE == enabled_features.portability_subset_features.tessellationIsolines)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 907 | skip |= LogError(pipeline->pipeline(), kVUID_Portability_Tessellation_Isolines, |
Nathaniel Cesario | 75fb722 | 2020-12-07 10:54:53 -0700 | [diff] [blame] | 908 | "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader" |
| 909 | " is using abstract patch type IsoLines, but this is not supported on this platform"); |
| 910 | } |
| 911 | if (is_point_mode && (VK_FALSE == enabled_features.portability_subset_features.tessellationPointMode)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 912 | skip |= LogError(pipeline->pipeline(), kVUID_Portability_Tessellation_PointMode, |
Nathaniel Cesario | 75fb722 | 2020-12-07 10:54:53 -0700 | [diff] [blame] | 913 | "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader" |
| 914 | " is using abstract patch type PointMode, but this is not supported on this platform"); |
| 915 | } |
| 916 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 917 | break; |
| 918 | |
| 919 | case VK_SHADER_STAGE_GEOMETRY_BIT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 920 | if (num_comp_in > limits.maxGeometryInputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 921 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 922 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 923 | "VkPhysicalDeviceLimits::maxGeometryInputComponents of %u " |
| 924 | "components by %u components", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 925 | limits.maxGeometryInputComponents, num_comp_in - limits.maxGeometryInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 926 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 927 | if (max_comp_in > static_cast<int>(limits.maxGeometryInputComponents)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 928 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 929 | "Invalid Pipeline CreateInfo State: Geometry shader input variable uses location that " |
| 930 | "exceeds component limit VkPhysicalDeviceLimits::maxGeometryInputComponents (%u)", |
| 931 | limits.maxGeometryInputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 932 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 933 | if (num_comp_out > limits.maxGeometryOutputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 934 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 935 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 936 | "VkPhysicalDeviceLimits::maxGeometryOutputComponents of %u " |
| 937 | "components by %u components", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 938 | limits.maxGeometryOutputComponents, num_comp_out - limits.maxGeometryOutputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 939 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 940 | if (max_comp_out > static_cast<int>(limits.maxGeometryOutputComponents)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 941 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 942 | "Invalid Pipeline CreateInfo State: Geometry shader output variable uses location that " |
| 943 | "exceeds component limit VkPhysicalDeviceLimits::maxGeometryOutputComponents (%u)", |
| 944 | limits.maxGeometryOutputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 945 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 946 | if (num_comp_out * num_vertices > limits.maxGeometryTotalOutputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 947 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 948 | "Invalid Pipeline CreateInfo State: Geometry shader exceeds " |
| 949 | "VkPhysicalDeviceLimits::maxGeometryTotalOutputComponents of %u " |
| 950 | "components by %u components", |
| 951 | limits.maxGeometryTotalOutputComponents, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 952 | num_comp_out * num_vertices - limits.maxGeometryTotalOutputComponents); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 953 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 954 | break; |
| 955 | |
| 956 | case VK_SHADER_STAGE_FRAGMENT_BIT: |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 957 | if (num_comp_in > limits.maxFragmentInputComponents) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 958 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 959 | "Invalid Pipeline CreateInfo State: Fragment shader exceeds " |
| 960 | "VkPhysicalDeviceLimits::maxFragmentInputComponents of %u " |
| 961 | "components by %u components", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 962 | limits.maxFragmentInputComponents, num_comp_in - limits.maxFragmentInputComponents); |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 963 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 964 | if (max_comp_in > static_cast<int>(limits.maxFragmentInputComponents)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 965 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_ExceedDeviceLimit, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 966 | "Invalid Pipeline CreateInfo State: Fragment shader input variable uses location that " |
| 967 | "exceeds component limit VkPhysicalDeviceLimits::maxFragmentInputComponents (%u)", |
| 968 | limits.maxFragmentInputComponents); |
Jeff Bolz | f234bf8 | 2019-11-04 14:07:15 -0600 | [diff] [blame] | 969 | } |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 970 | break; |
| 971 | |
Jeff Bolz | 148d94e | 2018-12-13 21:25:56 -0600 | [diff] [blame] | 972 | case VK_SHADER_STAGE_RAYGEN_BIT_NV: |
| 973 | case VK_SHADER_STAGE_ANY_HIT_BIT_NV: |
| 974 | case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV: |
| 975 | case VK_SHADER_STAGE_MISS_BIT_NV: |
| 976 | case VK_SHADER_STAGE_INTERSECTION_BIT_NV: |
| 977 | case VK_SHADER_STAGE_CALLABLE_BIT_NV: |
| 978 | case VK_SHADER_STAGE_TASK_BIT_NV: |
| 979 | case VK_SHADER_STAGE_MESH_BIT_NV: |
| 980 | break; |
| 981 | |
Daniel Fedai Larsen | c939abc | 2018-08-07 10:01:58 +0200 | [diff] [blame] | 982 | default: |
| 983 | assert(false); // This should never happen |
| 984 | } |
| 985 | return skip; |
| 986 | } |
| 987 | |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 988 | bool CoreChecks::ValidateShaderStorageImageFormats(SHADER_MODULE_STATE const *src) const { |
| 989 | bool skip = false; |
| 990 | |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 991 | // Got through all ImageRead/Write instructions |
| 992 | for (auto insn : *src) { |
| 993 | switch (insn.opcode()) { |
| 994 | case spv::OpImageSparseRead: |
| 995 | case spv::OpImageRead: { |
Lionel Landwerlin | 5f2065a | 2021-07-23 11:51:28 +0300 | [diff] [blame] | 996 | spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(3)); |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 997 | if (type_def != src->end()) { |
Tim Van Patten | ffe9132 | 2021-07-26 10:20:50 -0600 | [diff] [blame] | 998 | const auto dim = type_def.word(3); |
| 999 | // If the Image Dim operand is not SubpassData, the Image Format must not be Unknown, unless the |
| 1000 | // StorageImageReadWithoutFormat Capability was declared. |
| 1001 | if (dim != spv::DimSubpassData && type_def.word(8) == spv::ImageFormatUnknown) { |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 1002 | skip |= RequireFeature(enabled_features.core.shaderStorageImageReadWithoutFormat, |
| 1003 | "shaderStorageImageReadWithoutFormat", |
| 1004 | kVUID_Features_shaderStorageImageReadWithoutFormat); |
| 1005 | } |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 1006 | } |
| 1007 | break; |
| 1008 | } |
| 1009 | case spv::OpImageWrite: { |
Lionel Landwerlin | 5f2065a | 2021-07-23 11:51:28 +0300 | [diff] [blame] | 1010 | spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(1)); |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 1011 | if (type_def != src->end()) { |
| 1012 | if (type_def.word(8) == spv::ImageFormatUnknown) { |
| 1013 | skip |= RequireFeature(enabled_features.core.shaderStorageImageWriteWithoutFormat, |
| 1014 | "shaderStorageImageWriteWithoutFormat", |
| 1015 | kVUID_Features_shaderStorageImageWriteWithoutFormat); |
| 1016 | } |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 1017 | } |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | } |
| 1022 | } |
| 1023 | |
Lionel Landwerlin | 38d2e12 | 2021-07-21 14:21:47 +0300 | [diff] [blame] | 1024 | // Go through all variables for images and check decorations |
| 1025 | for (auto insn : *src) { |
| 1026 | if (insn.opcode() != spv::OpVariable) |
| 1027 | continue; |
| 1028 | |
| 1029 | uint32_t var = insn.word(2); |
Lionel Landwerlin | 5f2065a | 2021-07-23 11:51:28 +0300 | [diff] [blame] | 1030 | spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(1)); |
Lionel Landwerlin | 38d2e12 | 2021-07-21 14:21:47 +0300 | [diff] [blame] | 1031 | if (type_def == src->end()) |
| 1032 | continue; |
Tim Van Patten | ffe9132 | 2021-07-26 10:20:50 -0600 | [diff] [blame] | 1033 | // Only check if the Image Dim operand is not SubpassData |
| 1034 | const auto dim = type_def.word(3); |
| 1035 | if (dim == spv::DimSubpassData) continue; |
Corentin Wallez | 91f8b6d | 2021-07-23 10:11:31 +0200 | [diff] [blame] | 1036 | // Only check storage images |
| 1037 | if (type_def.word(7) != 2) continue; |
Tim Van Patten | ffe9132 | 2021-07-26 10:20:50 -0600 | [diff] [blame] | 1038 | if (type_def.word(8) != spv::ImageFormatUnknown) continue; |
Lionel Landwerlin | 38d2e12 | 2021-07-21 14:21:47 +0300 | [diff] [blame] | 1039 | |
| 1040 | decoration_set img_decorations = src->get_decorations(var); |
| 1041 | |
| 1042 | if (!enabled_features.core.shaderStorageImageReadWithoutFormat && |
| 1043 | !(img_decorations.flags & decoration_set::nonreadable_bit)) { |
| 1044 | skip |= LogError(device, |
| 1045 | kVUID_Features_shaderStorageImageReadWithoutFormat_NonReadable, |
| 1046 | "shaderStorageImageReadWithoutFormat not supported but variable %" PRIu32 " " |
| 1047 | " without format not marked a NonReadable", var); |
| 1048 | } |
| 1049 | |
| 1050 | if (!enabled_features.core.shaderStorageImageWriteWithoutFormat && |
| 1051 | !(img_decorations.flags & decoration_set::nonwritable_bit)) { |
| 1052 | skip |= LogError(device, |
| 1053 | kVUID_Features_shaderStorageImageWriteWithoutFormat_NonWritable, |
| 1054 | "shaderStorageImageWriteWithoutFormat not supported but variable %" PRIu32 " " |
| 1055 | "without format not marked a NonWritable", var); |
| 1056 | } |
| 1057 | } |
| 1058 | |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 1059 | return skip; |
| 1060 | } |
| 1061 | |
sfricke-samsung | dc96f30 | 2020-03-18 20:42:10 -0700 | [diff] [blame] | 1062 | bool CoreChecks::ValidateShaderStageMaxResources(VkShaderStageFlagBits stage, const PIPELINE_STATE *pipeline) const { |
| 1063 | bool skip = false; |
| 1064 | uint32_t total_resources = 0; |
| 1065 | |
| 1066 | // Only currently testing for graphics and compute pipelines |
| 1067 | // TODO: Add check and support for Ray Tracing pipeline VUID 03428 |
| 1068 | if ((stage & (VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_COMPUTE_BIT)) == 0) { |
| 1069 | return false; |
| 1070 | } |
| 1071 | |
| 1072 | if (stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 1073 | // "For the fragment shader stage the framebuffer color attachments also count against this limit" |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1074 | total_resources += pipeline->rp_state->createInfo.pSubpasses[pipeline->create_info.graphics.subpass].colorAttachmentCount; |
sfricke-samsung | dc96f30 | 2020-03-18 20:42:10 -0700 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | // TODO: This reuses a lot of GetDescriptorCountMaxPerStage but currently would need to make it agnostic in a way to handle |
| 1078 | // input from CreatePipeline and CreatePipelineLayout level |
| 1079 | for (auto set_layout : pipeline->pipeline_layout->set_layouts) { |
| 1080 | if ((set_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) != 0) { |
| 1081 | continue; |
| 1082 | } |
| 1083 | |
| 1084 | for (uint32_t binding_idx = 0; binding_idx < set_layout->GetBindingCount(); binding_idx++) { |
| 1085 | const VkDescriptorSetLayoutBinding *binding = set_layout->GetDescriptorSetLayoutBindingPtrFromIndex(binding_idx); |
| 1086 | // Bindings with a descriptorCount of 0 are "reserved" and should be skipped |
| 1087 | if (((stage & binding->stageFlags) != 0) && (binding->descriptorCount > 0)) { |
| 1088 | // Check only descriptor types listed in maxPerStageResources description in spec |
| 1089 | switch (binding->descriptorType) { |
| 1090 | case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER: |
| 1091 | case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE: |
| 1092 | case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE: |
| 1093 | case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER: |
| 1094 | case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER: |
| 1095 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER: |
| 1096 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER: |
| 1097 | case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC: |
| 1098 | case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC: |
| 1099 | case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT: |
| 1100 | total_resources += binding->descriptorCount; |
| 1101 | break; |
| 1102 | default: |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | if (total_resources > phys_dev_props.limits.maxPerStageResources) { |
| 1110 | const char *vuid = (stage == VK_SHADER_STAGE_COMPUTE_BIT) ? "VUID-VkComputePipelineCreateInfo-layout-01687" |
| 1111 | : "VUID-VkGraphicsPipelineCreateInfo-layout-01688"; |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1112 | skip |= LogError(pipeline->pipeline(), vuid, |
sfricke-samsung | dc96f30 | 2020-03-18 20:42:10 -0700 | [diff] [blame] | 1113 | "Invalid Pipeline CreateInfo State: Shader Stage %s exceeds component limit " |
| 1114 | "VkPhysicalDeviceLimits::maxPerStageResources (%u)", |
| 1115 | string_VkShaderStageFlagBits(stage), phys_dev_props.limits.maxPerStageResources); |
| 1116 | } |
| 1117 | |
| 1118 | return skip; |
| 1119 | } |
| 1120 | |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1121 | // copy the specialization constant value into buf, if it is present |
| 1122 | void GetSpecConstantValue(VkPipelineShaderStageCreateInfo const *pStage, uint32_t spec_id, void *buf) { |
| 1123 | VkSpecializationInfo const *spec = pStage->pSpecializationInfo; |
| 1124 | |
| 1125 | if (spec && spec_id < spec->mapEntryCount) { |
| 1126 | memcpy(buf, (uint8_t *)spec->pData + spec->pMapEntries[spec_id].offset, spec->pMapEntries[spec_id].size); |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | // Fill in value with the constant or specialization constant value, if available. |
| 1131 | // Returns true if the value has been accurately filled out. |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1132 | static bool GetIntConstantValue(spirv_inst_iter insn, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1133 | const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id, uint32_t *value) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1134 | auto type_id = src->get_def(insn.word(1)); |
| 1135 | if (type_id.opcode() != spv::OpTypeInt || type_id.word(2) != 32) { |
| 1136 | return false; |
| 1137 | } |
| 1138 | switch (insn.opcode()) { |
| 1139 | case spv::OpSpecConstant: |
| 1140 | *value = insn.word(3); |
| 1141 | GetSpecConstantValue(pStage, id_to_spec_id.at(insn.word(2)), value); |
| 1142 | return true; |
| 1143 | case spv::OpConstant: |
| 1144 | *value = insn.word(3); |
| 1145 | return true; |
| 1146 | default: |
| 1147 | return false; |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | // Map SPIR-V type to VK_COMPONENT_TYPE enum |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1152 | VkComponentTypeNV GetComponentType(spirv_inst_iter insn, SHADER_MODULE_STATE const *src) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1153 | switch (insn.opcode()) { |
| 1154 | case spv::OpTypeInt: |
| 1155 | switch (insn.word(2)) { |
| 1156 | case 8: |
| 1157 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT8_NV : VK_COMPONENT_TYPE_UINT8_NV; |
| 1158 | case 16: |
| 1159 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT16_NV : VK_COMPONENT_TYPE_UINT16_NV; |
| 1160 | case 32: |
| 1161 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT32_NV : VK_COMPONENT_TYPE_UINT32_NV; |
| 1162 | case 64: |
| 1163 | return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT64_NV : VK_COMPONENT_TYPE_UINT64_NV; |
| 1164 | default: |
| 1165 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1166 | } |
| 1167 | case spv::OpTypeFloat: |
| 1168 | switch (insn.word(2)) { |
| 1169 | case 16: |
| 1170 | return VK_COMPONENT_TYPE_FLOAT16_NV; |
| 1171 | case 32: |
| 1172 | return VK_COMPONENT_TYPE_FLOAT32_NV; |
| 1173 | case 64: |
| 1174 | return VK_COMPONENT_TYPE_FLOAT64_NV; |
| 1175 | default: |
| 1176 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1177 | } |
| 1178 | default: |
| 1179 | return VK_COMPONENT_TYPE_MAX_ENUM_NV; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | // Validate SPV_NV_cooperative_matrix behavior that can't be statically validated |
| 1184 | // in SPIRV-Tools (e.g. due to specialization constant usage). |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1185 | bool CoreChecks::ValidateCooperativeMatrix(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
John Zulauf | ac4c6e1 | 2019-07-01 16:05:58 -0600 | [diff] [blame] | 1186 | const PIPELINE_STATE *pipeline) const { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1187 | bool skip = false; |
| 1188 | |
| 1189 | // Map SPIR-V result ID to specialization constant id (SpecId decoration value) |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1190 | layer_data::unordered_map<uint32_t, uint32_t> id_to_spec_id; |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1191 | // Map SPIR-V result ID to the ID of its type. |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1192 | layer_data::unordered_map<uint32_t, uint32_t> id_to_type_id; |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1193 | |
| 1194 | struct CoopMatType { |
| 1195 | uint32_t scope, rows, cols; |
| 1196 | VkComponentTypeNV component_type; |
| 1197 | bool all_constant; |
| 1198 | |
| 1199 | CoopMatType() : scope(0), rows(0), cols(0), component_type(VK_COMPONENT_TYPE_MAX_ENUM_NV), all_constant(false) {} |
| 1200 | |
Mark Lobodzinski | 3c59d97 | 2019-04-25 11:28:14 -0600 | [diff] [blame] | 1201 | void Init(uint32_t id, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 1202 | const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1203 | spirv_inst_iter insn = src->get_def(id); |
| 1204 | uint32_t component_type_id = insn.word(2); |
| 1205 | uint32_t scope_id = insn.word(3); |
| 1206 | uint32_t rows_id = insn.word(4); |
| 1207 | uint32_t cols_id = insn.word(5); |
| 1208 | auto component_type_iter = src->get_def(component_type_id); |
| 1209 | auto scope_iter = src->get_def(scope_id); |
| 1210 | auto rows_iter = src->get_def(rows_id); |
| 1211 | auto cols_iter = src->get_def(cols_id); |
| 1212 | |
| 1213 | all_constant = true; |
| 1214 | if (!GetIntConstantValue(scope_iter, src, pStage, id_to_spec_id, &scope)) { |
| 1215 | all_constant = false; |
| 1216 | } |
| 1217 | if (!GetIntConstantValue(rows_iter, src, pStage, id_to_spec_id, &rows)) { |
| 1218 | all_constant = false; |
| 1219 | } |
| 1220 | if (!GetIntConstantValue(cols_iter, src, pStage, id_to_spec_id, &cols)) { |
| 1221 | all_constant = false; |
| 1222 | } |
| 1223 | component_type = GetComponentType(component_type_iter, src); |
| 1224 | } |
| 1225 | }; |
| 1226 | |
| 1227 | bool seen_coopmat_capability = false; |
| 1228 | |
| 1229 | for (auto insn : *src) { |
| 1230 | // Whitelist instructions whose result can be a cooperative matrix type, and |
| 1231 | // keep track of their types. It would be nice if SPIRV-Headers generated code |
| 1232 | // to identify which instructions have a result type and result id. Lacking that, |
| 1233 | // this whitelist is based on the set of instructions that |
| 1234 | // SPV_NV_cooperative_matrix says can be used with cooperative matrix types. |
| 1235 | switch (insn.opcode()) { |
| 1236 | case spv::OpLoad: |
| 1237 | case spv::OpCooperativeMatrixLoadNV: |
| 1238 | case spv::OpCooperativeMatrixMulAddNV: |
| 1239 | case spv::OpSNegate: |
| 1240 | case spv::OpFNegate: |
| 1241 | case spv::OpIAdd: |
| 1242 | case spv::OpFAdd: |
| 1243 | case spv::OpISub: |
| 1244 | case spv::OpFSub: |
| 1245 | case spv::OpFDiv: |
| 1246 | case spv::OpSDiv: |
| 1247 | case spv::OpUDiv: |
| 1248 | case spv::OpMatrixTimesScalar: |
| 1249 | case spv::OpConstantComposite: |
| 1250 | case spv::OpCompositeConstruct: |
| 1251 | case spv::OpConvertFToU: |
| 1252 | case spv::OpConvertFToS: |
| 1253 | case spv::OpConvertSToF: |
| 1254 | case spv::OpConvertUToF: |
| 1255 | case spv::OpUConvert: |
| 1256 | case spv::OpSConvert: |
| 1257 | case spv::OpFConvert: |
| 1258 | id_to_type_id[insn.word(2)] = insn.word(1); |
| 1259 | break; |
| 1260 | default: |
| 1261 | break; |
| 1262 | } |
| 1263 | |
| 1264 | switch (insn.opcode()) { |
| 1265 | case spv::OpDecorate: |
| 1266 | if (insn.word(2) == spv::DecorationSpecId) { |
| 1267 | id_to_spec_id[insn.word(1)] = insn.word(3); |
| 1268 | } |
| 1269 | break; |
| 1270 | case spv::OpCapability: |
| 1271 | if (insn.word(1) == spv::CapabilityCooperativeMatrixNV) { |
| 1272 | seen_coopmat_capability = true; |
| 1273 | |
| 1274 | if (!(pStage->stage & phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1275 | skip |= LogError( |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1276 | pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixSupportedStages, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1277 | "OpTypeCooperativeMatrixNV used in shader stage not in cooperativeMatrixSupportedStages (= %u)", |
| 1278 | phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1279 | } |
| 1280 | } |
| 1281 | break; |
| 1282 | case spv::OpMemoryModel: |
| 1283 | // If the capability isn't enabled, don't bother with the rest of this function. |
| 1284 | // OpMemoryModel is the first required instruction after all OpCapability instructions. |
| 1285 | if (!seen_coopmat_capability) { |
| 1286 | return skip; |
| 1287 | } |
| 1288 | break; |
| 1289 | case spv::OpTypeCooperativeMatrixNV: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1290 | CoopMatType m; |
| 1291 | m.Init(insn.word(1), src, pStage, id_to_spec_id); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1292 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1293 | if (m.all_constant) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1294 | // Validate that the type parameters are all supported for one of the |
| 1295 | // operands of a cooperative matrix property. |
| 1296 | bool valid = false; |
| 1297 | for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1298 | if (cooperative_matrix_properties[i].AType == m.component_type && |
| 1299 | cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].KSize == m.cols && |
| 1300 | cooperative_matrix_properties[i].scope == m.scope) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1301 | valid = true; |
| 1302 | break; |
| 1303 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1304 | if (cooperative_matrix_properties[i].BType == m.component_type && |
| 1305 | cooperative_matrix_properties[i].KSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols && |
| 1306 | cooperative_matrix_properties[i].scope == m.scope) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1307 | valid = true; |
| 1308 | break; |
| 1309 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1310 | if (cooperative_matrix_properties[i].CType == m.component_type && |
| 1311 | cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols && |
| 1312 | cooperative_matrix_properties[i].scope == m.scope) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1313 | valid = true; |
| 1314 | break; |
| 1315 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1316 | if (cooperative_matrix_properties[i].DType == m.component_type && |
| 1317 | cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols && |
| 1318 | cooperative_matrix_properties[i].scope == m.scope) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1319 | valid = true; |
| 1320 | break; |
| 1321 | } |
| 1322 | } |
| 1323 | if (!valid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1324 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixType, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1325 | "OpTypeCooperativeMatrixNV (result id = %u) operands don't match a supported matrix type", |
| 1326 | insn.word(1)); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1327 | } |
| 1328 | } |
| 1329 | break; |
| 1330 | } |
| 1331 | case spv::OpCooperativeMatrixMulAddNV: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1332 | CoopMatType a, b, c, d; |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1333 | if (id_to_type_id.find(insn.word(2)) == id_to_type_id.end() || |
| 1334 | id_to_type_id.find(insn.word(3)) == id_to_type_id.end() || |
| 1335 | id_to_type_id.find(insn.word(4)) == id_to_type_id.end() || |
| 1336 | 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] | 1337 | // Couldn't find type of matrix |
| 1338 | assert(false); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1339 | break; |
| 1340 | } |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1341 | d.Init(id_to_type_id[insn.word(2)], src, pStage, id_to_spec_id); |
| 1342 | a.Init(id_to_type_id[insn.word(3)], src, pStage, id_to_spec_id); |
| 1343 | b.Init(id_to_type_id[insn.word(4)], src, pStage, id_to_spec_id); |
| 1344 | c.Init(id_to_type_id[insn.word(5)], src, pStage, id_to_spec_id); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1345 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1346 | if (a.all_constant && b.all_constant && c.all_constant && d.all_constant) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1347 | // Validate that the type parameters are all supported for the same |
| 1348 | // cooperative matrix property. |
| 1349 | bool valid = false; |
| 1350 | for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1351 | if (cooperative_matrix_properties[i].AType == a.component_type && |
| 1352 | cooperative_matrix_properties[i].MSize == a.rows && cooperative_matrix_properties[i].KSize == a.cols && |
| 1353 | cooperative_matrix_properties[i].scope == a.scope && |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1354 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1355 | cooperative_matrix_properties[i].BType == b.component_type && |
| 1356 | cooperative_matrix_properties[i].KSize == b.rows && cooperative_matrix_properties[i].NSize == b.cols && |
| 1357 | cooperative_matrix_properties[i].scope == b.scope && |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1358 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1359 | cooperative_matrix_properties[i].CType == c.component_type && |
| 1360 | cooperative_matrix_properties[i].MSize == c.rows && cooperative_matrix_properties[i].NSize == c.cols && |
| 1361 | cooperative_matrix_properties[i].scope == c.scope && |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1362 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1363 | cooperative_matrix_properties[i].DType == d.component_type && |
| 1364 | cooperative_matrix_properties[i].MSize == d.rows && cooperative_matrix_properties[i].NSize == d.cols && |
| 1365 | cooperative_matrix_properties[i].scope == d.scope) { |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1366 | valid = true; |
| 1367 | break; |
| 1368 | } |
| 1369 | } |
| 1370 | if (!valid) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1371 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixMulAdd, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1372 | "OpCooperativeMatrixMulAddNV (result id = %u) operands don't match a supported matrix " |
| 1373 | "VkCooperativeMatrixPropertiesNV", |
| 1374 | insn.word(2)); |
Jeff Bolz | e435675 | 2019-03-07 11:23:46 -0600 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | break; |
| 1378 | } |
| 1379 | default: |
| 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | return skip; |
| 1385 | } |
| 1386 | |
Jeff Leger | 9b3dcff | 2021-05-27 15:40:20 -0400 | [diff] [blame] | 1387 | bool CoreChecks::ValidateShaderResolveQCOM(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage, |
| 1388 | const PIPELINE_STATE *pipeline) const { |
| 1389 | bool skip = false; |
| 1390 | |
| 1391 | // If the pipeline's subpass description contains flag VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM, |
| 1392 | // then the fragment shader must not enable the SPIRV SampleRateShading capability. |
| 1393 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 1394 | for (auto insn : *src) { |
| 1395 | switch (insn.opcode()) { |
| 1396 | case spv::OpCapability: |
| 1397 | if (insn.word(1) == spv::CapabilitySampleRateShading) { |
| 1398 | auto subpass_flags = |
| 1399 | (pipeline->rp_state == nullptr) |
| 1400 | ? 0 |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1401 | : pipeline->rp_state->createInfo.pSubpasses[pipeline->create_info.graphics.subpass].flags; |
Jeff Leger | 9b3dcff | 2021-05-27 15:40:20 -0400 | [diff] [blame] | 1402 | if ((subpass_flags & VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM) != 0) { |
| 1403 | skip |= |
| 1404 | LogError(pipeline->pipeline(), kVUID_Core_Shader_ResolveQCOM_InvalidCapability, |
| 1405 | "Invalid Pipeline CreateInfo State: fragment shader enables SampleRateShading capability " |
| 1406 | "and the subpass flags includes VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM."); |
| 1407 | } |
| 1408 | } |
| 1409 | break; |
| 1410 | default: |
| 1411 | break; |
| 1412 | } |
| 1413 | } |
| 1414 | } |
| 1415 | |
| 1416 | return skip; |
| 1417 | } |
| 1418 | |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1419 | bool CoreChecks::ValidateAtomicsTypes(SHADER_MODULE_STATE const *src) const { |
| 1420 | bool skip = false; |
| 1421 | |
sfricke-samsung | 6c9eb71 | 2021-08-04 09:38:54 -0700 | [diff] [blame] | 1422 | // "If sparseImageInt64Atomics is enabled, shaderImageInt64Atomics must be enabled" |
sfricke-samsung | 828e59d | 2021-08-22 23:20:49 -0700 | [diff] [blame] | 1423 | const bool valid_image_64_int = enabled_features.shader_image_atomic_int64_features.shaderImageInt64Atomics == VK_TRUE; |
sfricke-samsung | 6c9eb71 | 2021-08-04 09:38:54 -0700 | [diff] [blame] | 1424 | |
sfricke-samsung | f5042b1 | 2021-08-05 01:09:40 -0700 | [diff] [blame] | 1425 | const VkPhysicalDeviceShaderAtomicFloatFeaturesEXT &float_features = enabled_features.shader_atomic_float_features; |
| 1426 | const VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT &float2_features = enabled_features.shader_atomic_float2_features; |
| 1427 | |
| 1428 | const bool valid_storage_buffer_float = ( |
| 1429 | (float_features.shaderBufferFloat32Atomics == VK_TRUE) || |
| 1430 | (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) || |
| 1431 | (float_features.shaderBufferFloat64Atomics == VK_TRUE) || |
| 1432 | (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) || |
| 1433 | (float2_features.shaderBufferFloat16Atomics == VK_TRUE) || |
| 1434 | (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) || |
| 1435 | (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) || |
| 1436 | (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) || |
| 1437 | (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE)); |
| 1438 | |
| 1439 | const bool valid_workgroup_float = ( |
| 1440 | (float_features.shaderSharedFloat32Atomics == VK_TRUE) || |
| 1441 | (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) || |
| 1442 | (float_features.shaderSharedFloat64Atomics == VK_TRUE) || |
| 1443 | (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) || |
| 1444 | (float2_features.shaderSharedFloat16Atomics == VK_TRUE) || |
| 1445 | (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) || |
| 1446 | (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE) || |
| 1447 | (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) || |
| 1448 | (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE)); |
| 1449 | |
| 1450 | const bool valid_image_float = ( |
| 1451 | (float_features.shaderImageFloat32Atomics == VK_TRUE) || |
| 1452 | (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) || |
| 1453 | (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE)); |
| 1454 | |
| 1455 | const bool valid_16_float = ( |
| 1456 | (float2_features.shaderBufferFloat16Atomics == VK_TRUE) || |
| 1457 | (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) || |
| 1458 | (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) || |
| 1459 | (float2_features.shaderSharedFloat16Atomics == VK_TRUE) || |
| 1460 | (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) || |
| 1461 | (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE)); |
| 1462 | |
| 1463 | const bool valid_32_float = ( |
| 1464 | (float_features.shaderBufferFloat32Atomics == VK_TRUE) || |
| 1465 | (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) || |
| 1466 | (float_features.shaderSharedFloat32Atomics == VK_TRUE) || |
| 1467 | (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) || |
| 1468 | (float_features.shaderImageFloat32Atomics == VK_TRUE) || |
| 1469 | (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) || |
| 1470 | (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) || |
| 1471 | (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) || |
| 1472 | (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE)); |
| 1473 | |
| 1474 | const bool valid_64_float = ( |
| 1475 | (float_features.shaderBufferFloat64Atomics == VK_TRUE) || |
| 1476 | (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) || |
| 1477 | (float_features.shaderSharedFloat64Atomics == VK_TRUE) || |
| 1478 | (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) || |
| 1479 | (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE) || |
| 1480 | (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE)); |
| 1481 | // clang-format on |
| 1482 | |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1483 | for (auto &atomic_inst : src->atomic_inst) { |
| 1484 | const atomic_instruction &atomic = atomic_inst.second; |
sfricke-samsung | f5042b1 | 2021-08-05 01:09:40 -0700 | [diff] [blame] | 1485 | const uint32_t opcode = src->at(atomic_inst.first).opcode(); |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1486 | |
| 1487 | if ((atomic.bit_width == 64) && (atomic.type == spv::OpTypeInt)) { |
| 1488 | // Validate 64-bit atomics |
| 1489 | if (((atomic.storage_class == spv::StorageClassStorageBuffer) || (atomic.storage_class == spv::StorageClassUniform)) && |
| 1490 | (enabled_features.core12.shaderBufferInt64Atomics == VK_FALSE)) { |
| 1491 | skip |= LogError( |
| 1492 | device, kVUID_Core_Shader_AtomicFeature, |
| 1493 | "%s: Can't use 64-bit int atomics operations with %s storage class without shaderBufferInt64Atomics enabled.", |
| 1494 | report_data->FormatHandle(src->vk_shader_module()).c_str(), StorageClassName(atomic.storage_class)); |
| 1495 | } else if ((atomic.storage_class == spv::StorageClassWorkgroup) && |
| 1496 | (enabled_features.core12.shaderSharedInt64Atomics == VK_FALSE)) { |
| 1497 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1498 | "%s: Can't use 64-bit int atomics operations with Workgroup storage class without " |
| 1499 | "shaderSharedInt64Atomics enabled.", |
| 1500 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
sfricke-samsung | 6c9eb71 | 2021-08-04 09:38:54 -0700 | [diff] [blame] | 1501 | } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_64_int == false)) { |
| 1502 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1503 | "%s: Can't use 64-bit int atomics operations with Image storage class without " |
| 1504 | "shaderImageInt64Atomics enabled.", |
| 1505 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1506 | } |
sfricke-samsung | f5042b1 | 2021-08-05 01:09:40 -0700 | [diff] [blame] | 1507 | } else if (atomic.type == spv::OpTypeFloat) { |
| 1508 | // Validate Floats |
| 1509 | if (atomic.storage_class == spv::StorageClassStorageBuffer) { |
| 1510 | if (valid_storage_buffer_float == false) { |
| 1511 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1512 | "%s: Can't use float atomics operations with StorageBuffer storage class without " |
| 1513 | "shaderBufferFloat32Atomics or shaderBufferFloat32AtomicAdd or shaderBufferFloat64Atomics or " |
| 1514 | "shaderBufferFloat64AtomicAdd or shaderBufferFloat16Atomics or shaderBufferFloat16AtomicAdd " |
| 1515 | "or shaderBufferFloat16AtomicMinMax or shaderBufferFloat32AtomicMinMax or " |
| 1516 | "shaderBufferFloat64AtomicMinMax enabled.", |
| 1517 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1518 | } else if (opcode == spv::OpAtomicFAddEXT) { |
| 1519 | if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicAdd == VK_FALSE)) { |
| 1520 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1521 | "%s: Can't use 16-bit float atomics for add operations (OpAtomicFAddEXT) with " |
| 1522 | "StorageBuffer storage class without shaderBufferFloat16AtomicAdd enabled.", |
| 1523 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1524 | } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32AtomicAdd == VK_FALSE)) { |
| 1525 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1526 | "%s: Can't use 32-bit float atomics for add operations (OpAtomicFAddEXT) with " |
| 1527 | "StorageBuffer storage class without shaderBufferFloat32AtomicAdd enabled.", |
| 1528 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1529 | } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64AtomicAdd == VK_FALSE)) { |
| 1530 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1531 | "%s: Can't use 64-bit float atomics for add operations (OpAtomicFAddEXT) with " |
| 1532 | "StorageBuffer storage class without shaderBufferFloat64AtomicAdd enabled.", |
| 1533 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1534 | } |
| 1535 | } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) { |
| 1536 | if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicMinMax == VK_FALSE)) { |
| 1537 | skip |= LogError( |
| 1538 | device, kVUID_Core_Shader_AtomicFeature, |
| 1539 | "%s: Can't use 16-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1540 | "StorageBuffer storage class without shaderBufferFloat16AtomicMinMax enabled.", |
| 1541 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1542 | } else if ((atomic.bit_width == 32) && (float2_features.shaderBufferFloat32AtomicMinMax == VK_FALSE)) { |
| 1543 | skip |= LogError( |
| 1544 | device, kVUID_Core_Shader_AtomicFeature, |
| 1545 | "%s: Can't use 32-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1546 | "StorageBuffer storage class without shaderBufferFloat32AtomicMinMax enabled.", |
| 1547 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1548 | } else if ((atomic.bit_width == 64) && (float2_features.shaderBufferFloat64AtomicMinMax == VK_FALSE)) { |
| 1549 | skip |= LogError( |
| 1550 | device, kVUID_Core_Shader_AtomicFeature, |
| 1551 | "%s: Can't use 64-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1552 | "StorageBuffer storage class without shaderBufferFloat64AtomicMinMax enabled.", |
| 1553 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1554 | } |
| 1555 | } else { |
| 1556 | // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch |
| 1557 | if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16Atomics == VK_FALSE)) { |
| 1558 | skip |= LogError( |
| 1559 | device, kVUID_Core_Shader_AtomicFeature, |
| 1560 | "%s: Can't use 16-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1561 | "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat16Atomics enabled.", |
| 1562 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1563 | } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32Atomics == VK_FALSE)) { |
| 1564 | skip |= LogError( |
| 1565 | device, kVUID_Core_Shader_AtomicFeature, |
| 1566 | "%s: Can't use 32-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1567 | "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat32Atomics enabled.", |
| 1568 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1569 | } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64Atomics == VK_FALSE)) { |
| 1570 | skip |= LogError( |
| 1571 | device, kVUID_Core_Shader_AtomicFeature, |
| 1572 | "%s: Can't use 64-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1573 | "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat64Atomics enabled.", |
| 1574 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1575 | } |
| 1576 | } |
| 1577 | } else if (atomic.storage_class == spv::StorageClassWorkgroup) { |
| 1578 | if (valid_workgroup_float == false) { |
| 1579 | skip |= LogError( |
| 1580 | device, kVUID_Core_Shader_AtomicFeature, |
| 1581 | "%s: Can't use float atomics operations with Workgroup storage class without shaderSharedFloat32Atomics or " |
| 1582 | "shaderSharedFloat32AtomicAdd or shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd or " |
| 1583 | "shaderSharedFloat16Atomics or shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax or " |
| 1584 | "shaderSharedFloat32AtomicMinMax or shaderSharedFloat64AtomicMinMax enabled.", |
| 1585 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1586 | } else if (opcode == spv::OpAtomicFAddEXT) { |
| 1587 | if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicAdd == VK_FALSE)) { |
| 1588 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1589 | "%s: Can't use 16-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup " |
| 1590 | "storage class without shaderSharedFloat16AtomicAdd enabled.", |
| 1591 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1592 | } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32AtomicAdd == VK_FALSE)) { |
| 1593 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1594 | "%s: Can't use 32-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup " |
| 1595 | "storage class without shaderSharedFloat32AtomicAdd enabled.", |
| 1596 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1597 | } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64AtomicAdd == VK_FALSE)) { |
| 1598 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1599 | "%s: Can't use 64-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup " |
| 1600 | "storage class without shaderSharedFloat64AtomicAdd enabled.", |
| 1601 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1602 | } |
| 1603 | } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) { |
| 1604 | if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicMinMax == VK_FALSE)) { |
| 1605 | skip |= LogError( |
| 1606 | device, kVUID_Core_Shader_AtomicFeature, |
| 1607 | "%s: Can't use 16-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1608 | "Workgroup storage class without shaderSharedFloat16AtomicMinMax enabled.", |
| 1609 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1610 | } else if ((atomic.bit_width == 32) && (float2_features.shaderSharedFloat32AtomicMinMax == VK_FALSE)) { |
| 1611 | skip |= LogError( |
| 1612 | device, kVUID_Core_Shader_AtomicFeature, |
| 1613 | "%s: Can't use 32-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1614 | "Workgroup storage class without shaderSharedFloat32AtomicMinMax enabled.", |
| 1615 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1616 | } else if ((atomic.bit_width == 64) && (float2_features.shaderSharedFloat64AtomicMinMax == VK_FALSE)) { |
| 1617 | skip |= LogError( |
| 1618 | device, kVUID_Core_Shader_AtomicFeature, |
| 1619 | "%s: Can't use 64-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with " |
| 1620 | "Workgroup storage class without shaderSharedFloat64AtomicMinMax enabled.", |
| 1621 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1622 | } |
| 1623 | } else { |
| 1624 | // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch |
| 1625 | if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16Atomics == VK_FALSE)) { |
| 1626 | skip |= LogError( |
| 1627 | device, kVUID_Core_Shader_AtomicFeature, |
| 1628 | "%s: Can't use 16-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1629 | "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat16Atomics enabled.", |
| 1630 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1631 | } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32Atomics == VK_FALSE)) { |
| 1632 | skip |= LogError( |
| 1633 | device, kVUID_Core_Shader_AtomicFeature, |
| 1634 | "%s: Can't use 32-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1635 | "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat32Atomics enabled.", |
| 1636 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1637 | } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64Atomics == VK_FALSE)) { |
| 1638 | skip |= LogError( |
| 1639 | device, kVUID_Core_Shader_AtomicFeature, |
| 1640 | "%s: Can't use 64-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, " |
| 1641 | "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat64Atomics enabled.", |
| 1642 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1643 | } |
| 1644 | } |
| 1645 | } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_float == false)) { |
| 1646 | skip |= |
| 1647 | LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1648 | "%s: Can't use float atomics operations with Image storage class without shaderImageFloat32Atomics or " |
| 1649 | "shaderImageFloat32AtomicAdd or shaderImageFloat32AtomicMinMax enabled.", |
| 1650 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1651 | } else if ((atomic.bit_width == 16) && (valid_16_float == false)) { |
| 1652 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1653 | "%s: Can't use 16-bit float atomics operations without shaderBufferFloat16Atomics, " |
| 1654 | "shaderBufferFloat16AtomicAdd, shaderBufferFloat16AtomicMinMax, shaderSharedFloat16Atomics, " |
| 1655 | "shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax enabled.", |
| 1656 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1657 | } else if ((atomic.bit_width == 32) && (valid_32_float == false)) { |
| 1658 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1659 | "%s: Can't use 32-bit float atomics operations without shaderBufferFloat32AtomicMinMax, " |
| 1660 | "shaderSharedFloat32AtomicMinMax, shaderImageFloat32AtomicMinMax, sparseImageFloat32AtomicMinMax, " |
| 1661 | "shaderBufferFloat32Atomics, shaderBufferFloat32AtomicAdd, shaderSharedFloat32Atomics, " |
| 1662 | "shaderSharedFloat32AtomicAdd, shaderImageFloat32Atomics, shaderImageFloat32AtomicAdd, " |
| 1663 | "sparseImageFloat32Atomics or sparseImageFloat32AtomicAdd enabled.", |
| 1664 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1665 | } else if ((atomic.bit_width == 64) && (valid_64_float == false)) { |
| 1666 | skip |= LogError(device, kVUID_Core_Shader_AtomicFeature, |
| 1667 | "%s: Can't use 64-bit float atomics operations without shaderBufferFloat64AtomicMinMax, " |
| 1668 | "shaderSharedFloat64AtomicMinMax, shaderBufferFloat64Atomics, shaderBufferFloat64AtomicAdd, " |
| 1669 | "shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd enabled.", |
| 1670 | report_data->FormatHandle(src->vk_shader_module()).c_str()); |
| 1671 | } |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1672 | } |
| 1673 | } |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 1674 | return skip; |
| 1675 | } |
| 1676 | |
John Zulauf | ac4c6e1 | 2019-07-01 16:05:58 -0600 | [diff] [blame] | 1677 | 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] | 1678 | auto entrypoint_id = entrypoint.word(2); |
| 1679 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1680 | // The first denorm execution mode encountered, along with its bit width. |
| 1681 | // Used to check if SeparateDenormSettings is respected. |
| 1682 | 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] | 1683 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1684 | // The first rounding mode encountered, along with its bit width. |
| 1685 | // Used to check if SeparateRoundingModeSettings is respected. |
| 1686 | 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] | 1687 | |
| 1688 | bool skip = false; |
| 1689 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1690 | uint32_t vertices_out = 0; |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1691 | uint32_t invocations = 0; |
| 1692 | |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 1693 | auto it = src->execution_mode_inst.find(entrypoint_id); |
| 1694 | if (it != src->execution_mode_inst.end()) { |
| 1695 | for (auto insn : it->second) { |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1696 | auto mode = insn.word(2); |
| 1697 | switch (mode) { |
| 1698 | case spv::ExecutionModeSignedZeroInfNanPreserve: { |
| 1699 | auto bit_width = insn.word(3); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1700 | if ((bit_width == 16 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16) || |
| 1701 | (bit_width == 32 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32) || |
| 1702 | (bit_width == 64 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1703 | skip |= LogError( |
| 1704 | device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1705 | "Shader requires SignedZeroInfNanPreserve for bit width %d but it is not enabled on the device", |
| 1706 | bit_width); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1707 | } |
| 1708 | break; |
| 1709 | } |
| 1710 | |
| 1711 | case spv::ExecutionModeDenormPreserve: { |
| 1712 | auto bit_width = insn.word(3); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1713 | if ((bit_width == 16 && !phys_dev_props_core12.shaderDenormPreserveFloat16) || |
| 1714 | (bit_width == 32 && !phys_dev_props_core12.shaderDenormPreserveFloat32) || |
| 1715 | (bit_width == 64 && !phys_dev_props_core12.shaderDenormPreserveFloat64)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1716 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1717 | "Shader requires DenormPreserve for bit width %d but it is not enabled on the device", |
| 1718 | bit_width); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1719 | } |
| 1720 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1721 | if (first_denorm_execution_mode.first == spv::ExecutionModeMax) { |
| 1722 | // Register the first denorm execution mode found |
| 1723 | 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] | 1724 | } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1725 | switch (phys_dev_props_core12.denormBehaviorIndependence) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1726 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1727 | if (first_rounding_mode.second != 32 && bit_width != 32) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1728 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1729 | "Shader uses different denorm execution modes for 16 and 64-bit but " |
| 1730 | "denormBehaviorIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1731 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1732 | } |
| 1733 | break; |
| 1734 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1735 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1736 | break; |
| 1737 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1738 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE: |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1739 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1740 | "Shader uses different denorm execution modes for different bit widths but " |
| 1741 | "denormBehaviorIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1742 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1743 | break; |
| 1744 | |
| 1745 | default: |
| 1746 | break; |
| 1747 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1748 | } |
| 1749 | break; |
| 1750 | } |
| 1751 | |
| 1752 | case spv::ExecutionModeDenormFlushToZero: { |
| 1753 | auto bit_width = insn.word(3); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1754 | if ((bit_width == 16 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat16) || |
| 1755 | (bit_width == 32 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat32) || |
| 1756 | (bit_width == 64 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat64)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1757 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1758 | "Shader requires DenormFlushToZero for bit width %d but it is not enabled on the device", |
| 1759 | bit_width); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1762 | if (first_denorm_execution_mode.first == spv::ExecutionModeMax) { |
| 1763 | // Register the first denorm execution mode found |
| 1764 | 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] | 1765 | } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1766 | switch (phys_dev_props_core12.denormBehaviorIndependence) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1767 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1768 | if (first_rounding_mode.second != 32 && bit_width != 32) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1769 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1770 | "Shader uses different denorm execution modes for 16 and 64-bit but " |
| 1771 | "denormBehaviorIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1772 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1773 | } |
| 1774 | break; |
| 1775 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1776 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1777 | break; |
| 1778 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1779 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE: |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1780 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1781 | "Shader uses different denorm execution modes for different bit widths but " |
| 1782 | "denormBehaviorIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1783 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1784 | break; |
| 1785 | |
| 1786 | default: |
| 1787 | break; |
| 1788 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1789 | } |
| 1790 | break; |
| 1791 | } |
| 1792 | |
| 1793 | case spv::ExecutionModeRoundingModeRTE: { |
| 1794 | auto bit_width = insn.word(3); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1795 | if ((bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTEFloat16) || |
| 1796 | (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTEFloat32) || |
| 1797 | (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTEFloat64)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1798 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1799 | "Shader requires RoundingModeRTE for bit width %d but it is not enabled on the device", |
| 1800 | bit_width); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1801 | } |
| 1802 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1803 | if (first_rounding_mode.first == spv::ExecutionModeMax) { |
| 1804 | // Register the first rounding mode found |
| 1805 | 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] | 1806 | } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1807 | switch (phys_dev_props_core12.roundingModeIndependence) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1808 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1809 | if (first_rounding_mode.second != 32 && bit_width != 32) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1810 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1811 | "Shader uses different rounding modes for 16 and 64-bit but " |
| 1812 | "roundingModeIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1813 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1814 | } |
| 1815 | break; |
| 1816 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1817 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1818 | break; |
| 1819 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1820 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE: |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1821 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1822 | "Shader uses different rounding modes for different bit widths but " |
| 1823 | "roundingModeIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1824 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1825 | break; |
| 1826 | |
| 1827 | default: |
| 1828 | break; |
| 1829 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1830 | } |
| 1831 | break; |
| 1832 | } |
| 1833 | |
| 1834 | case spv::ExecutionModeRoundingModeRTZ: { |
| 1835 | auto bit_width = insn.word(3); |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1836 | if ((bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTZFloat16) || |
| 1837 | (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTZFloat32) || |
| 1838 | (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTZFloat64)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1839 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1840 | "Shader requires RoundingModeRTZ for bit width %d but it is not enabled on the device", |
| 1841 | bit_width); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
Attilio Provenzano | f6c0e85 | 2019-04-09 11:01:18 +0100 | [diff] [blame] | 1844 | if (first_rounding_mode.first == spv::ExecutionModeMax) { |
| 1845 | // Register the first rounding mode found |
| 1846 | 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] | 1847 | } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) { |
Piers Daniell | 41b8c5d | 2020-01-10 15:42:00 -0700 | [diff] [blame] | 1848 | switch (phys_dev_props_core12.roundingModeIndependence) { |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1849 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1850 | if (first_rounding_mode.second != 32 && bit_width != 32) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1851 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1852 | "Shader uses different rounding modes for 16 and 64-bit but " |
| 1853 | "roundingModeIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1854 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1855 | } |
| 1856 | break; |
| 1857 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1858 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL: |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1859 | break; |
| 1860 | |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1861 | case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE: |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1862 | skip |= LogError(device, kVUID_Core_Shader_FeatureNotEnabled, |
| 1863 | "Shader uses different rounding modes for different bit widths but " |
| 1864 | "roundingModeIndependence is " |
Mike Schuchardt | 2df0891 | 2020-12-15 16:28:09 -0800 | [diff] [blame] | 1865 | "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device"); |
Jason Ekstrand | e1e06de | 2019-08-05 11:43:43 -0500 | [diff] [blame] | 1866 | break; |
| 1867 | |
| 1868 | default: |
| 1869 | break; |
| 1870 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1871 | } |
| 1872 | break; |
| 1873 | } |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1874 | |
| 1875 | case spv::ExecutionModeOutputVertices: { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1876 | vertices_out = insn.word(3); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | case spv::ExecutionModeInvocations: { |
| 1881 | invocations = insn.word(3); |
| 1882 | break; |
| 1883 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1888 | if (entrypoint.word(1) == spv::ExecutionModelGeometry) { |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1889 | if (vertices_out == 0 || vertices_out > phys_dev_props.limits.maxGeometryOutputVertices) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1890 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00714", |
| 1891 | "Geometry shader entry point must have an OpExecutionMode instruction that " |
| 1892 | "specifies a maximum output vertex count that is greater than 0 and less " |
| 1893 | "than or equal to maxGeometryOutputVertices. " |
| 1894 | "OutputVertices=%d, maxGeometryOutputVertices=%d", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 1895 | vertices_out, phys_dev_props.limits.maxGeometryOutputVertices); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | if (invocations == 0 || invocations > phys_dev_props.limits.maxGeometryShaderInvocations) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1899 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00715", |
| 1900 | "Geometry shader entry point must have an OpExecutionMode instruction that " |
| 1901 | "specifies an invocation count that is greater than 0 and less " |
| 1902 | "than or equal to maxGeometryShaderInvocations. " |
| 1903 | "Invocations=%d, maxGeometryShaderInvocations=%d", |
| 1904 | invocations, phys_dev_props.limits.maxGeometryShaderInvocations); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 1905 | } |
| 1906 | } |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 1907 | return skip; |
| 1908 | } |
| 1909 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1910 | // For given pipelineLayout verify that the set_layout_node at slot.first |
| 1911 | // 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] | 1912 | static VkDescriptorSetLayoutBinding const *GetDescriptorBinding(PIPELINE_LAYOUT_STATE const *pipelineLayout, |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1913 | DescriptorSlot slot) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1914 | if (!pipelineLayout) return nullptr; |
| 1915 | |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1916 | if (slot.set >= pipelineLayout->set_layouts.size()) return nullptr; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1917 | |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 1918 | return pipelineLayout->set_layouts[slot.set]->GetDescriptorSetLayoutBindingPtrFromBinding(slot.binding); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 1919 | } |
| 1920 | |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1921 | // If PointList topology is specified in the pipeline, verify that a shader geometry stage writes PointSize |
| 1922 | // o If there is only a vertex shader : gl_PointSize must be written when using points |
| 1923 | // o If there is a geometry or tessellation shader: |
| 1924 | // - If shaderTessellationAndGeometryPointSize feature is enabled: |
| 1925 | // * gl_PointSize must be written in the final geometry stage |
| 1926 | // - If shaderTessellationAndGeometryPointSize feature is disabled: |
| 1927 | // * 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] | 1928 | bool CoreChecks::ValidatePointListShaderState(const PIPELINE_STATE *pipeline, SHADER_MODULE_STATE const *src, |
John Zulauf | ac4c6e1 | 2019-07-01 16:05:58 -0600 | [diff] [blame] | 1929 | spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1930 | if (pipeline->topology_at_rasterizer != VK_PRIMITIVE_TOPOLOGY_POINT_LIST) { |
| 1931 | return false; |
| 1932 | } |
| 1933 | |
| 1934 | bool pointsize_written = false; |
| 1935 | bool skip = false; |
| 1936 | |
| 1937 | // Search for PointSize built-in decorations |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1938 | for (auto set : src->builtin_decoration_list) { |
| 1939 | auto insn = src->at(set.offset); |
| 1940 | if (set.builtin == spv::BuiltInPointSize) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1941 | pointsize_written = src->IsBuiltInWritten(insn, entrypoint); |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1942 | if (pointsize_written) { |
| 1943 | break; |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1944 | } |
| 1945 | } |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | 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] | 1949 | !enabled_features.core.shaderTessellationAndGeometryPointSize) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1950 | if (pointsize_written) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1951 | skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_PointSizeBuiltInOverSpecified, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1952 | "Pipeline topology is set to POINT_LIST and geometry or tessellation shaders write PointSize which " |
| 1953 | "is prohibited when the shaderTessellationAndGeometryPointSize feature is not enabled."); |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1954 | } |
| 1955 | } else if (!pointsize_written) { |
| 1956 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1957 | LogError(pipeline->pipeline(), kVUID_Core_Shader_MissingPointSizeBuiltIn, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 1958 | "Pipeline topology is set to POINT_LIST, but PointSize is not written to in the shader corresponding to %s.", |
| 1959 | string_VkShaderStageFlagBits(stage)); |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 1960 | } |
| 1961 | return skip; |
| 1962 | } |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 1963 | |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1964 | bool CoreChecks::ValidatePrimitiveRateShaderState(const PIPELINE_STATE *pipeline, SHADER_MODULE_STATE const *src, |
| 1965 | spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const { |
| 1966 | bool primitiverate_written = false; |
| 1967 | bool viewportindex_written = false; |
| 1968 | bool viewportmask_written = false; |
| 1969 | bool skip = false; |
| 1970 | |
| 1971 | // Check if the primitive shading rate is written |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1972 | for (auto set : src->builtin_decoration_list) { |
| 1973 | auto insn = src->at(set.offset); |
| 1974 | if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1975 | primitiverate_written = src->IsBuiltInWritten(insn, entrypoint); |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1976 | } else if (set.builtin == spv::BuiltInViewportIndex) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1977 | viewportindex_written = src->IsBuiltInWritten(insn, entrypoint); |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1978 | } else if (set.builtin == spv::BuiltInViewportMaskNV) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 1979 | viewportmask_written = src->IsBuiltInWritten(insn, entrypoint); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1980 | } |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 1981 | if (primitiverate_written && viewportindex_written && viewportmask_written) { |
| 1982 | break; |
| 1983 | } |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1984 | } |
| 1985 | |
Tony-LunarG | d44844c | 2021-01-22 13:24:37 -0700 | [diff] [blame] | 1986 | if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports && |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1987 | (pipeline->GetPipelineType() == VK_PIPELINE_BIND_POINT_GRAPHICS) && pipeline->create_info.graphics.pViewportState) { |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1988 | if (!IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) && |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 1989 | pipeline->create_info.graphics.pViewportState->viewportCount > 1 && primitiverate_written) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1990 | skip |= LogError(pipeline->pipeline(), |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 1991 | "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04503", |
| 1992 | "vkCreateGraphicsPipelines: %s shader statically writes to PrimitiveShadingRateKHR built-in, but " |
| 1993 | "multiple viewports " |
| 1994 | "are used and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.", |
| 1995 | string_VkShaderStageFlagBits(stage)); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 1996 | } |
| 1997 | |
| 1998 | if (primitiverate_written && viewportindex_written) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 1999 | skip |= LogError(pipeline->pipeline(), |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2000 | "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04504", |
| 2001 | "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and " |
| 2002 | "ViewportIndex built-ins," |
| 2003 | "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.", |
| 2004 | string_VkShaderStageFlagBits(stage)); |
| 2005 | } |
| 2006 | |
| 2007 | if (primitiverate_written && viewportmask_written) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2008 | skip |= LogError(pipeline->pipeline(), |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2009 | "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04505", |
| 2010 | "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and " |
| 2011 | "ViewportMaskNV built-ins," |
| 2012 | "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.", |
| 2013 | string_VkShaderStageFlagBits(stage)); |
| 2014 | } |
| 2015 | } |
| 2016 | return skip; |
| 2017 | } |
| 2018 | |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 2019 | // Validate runtime usage of various opcodes that depends on what Vulkan properties or features are exposed |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2020 | bool CoreChecks::ValidatePropertiesAndFeatures(SHADER_MODULE_STATE const *module, spirv_inst_iter &insn) const { |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 2021 | bool skip = false; |
| 2022 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2023 | switch (insn.opcode()) { |
| 2024 | case spv::OpReadClockKHR: { |
| 2025 | auto scope_id = module->get_def(insn.word(3)); |
| 2026 | auto scope_type = scope_id.word(3); |
| 2027 | // if scope isn't Subgroup or Device, spirv-val will catch |
sfricke-samsung | 828e59d | 2021-08-22 23:20:49 -0700 | [diff] [blame] | 2028 | if ((scope_type == spv::ScopeSubgroup) && (enabled_features.shader_clock_features.shaderSubgroupClock == VK_FALSE)) { |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2029 | skip |= LogError(device, "UNASSIGNED-spirv-shaderClock-shaderSubgroupClock", |
| 2030 | "%s: OpReadClockKHR is used with a Subgroup scope but shaderSubgroupClock was not enabled.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2031 | report_data->FormatHandle(module->vk_shader_module()).c_str()); |
sfricke-samsung | 828e59d | 2021-08-22 23:20:49 -0700 | [diff] [blame] | 2032 | } else if ((scope_type == spv::ScopeDevice) && (enabled_features.shader_clock_features.shaderDeviceClock == VK_FALSE)) { |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2033 | skip |= LogError(device, "UNASSIGNED-spirv-shaderClock-shaderDeviceClock", |
| 2034 | "%s: OpReadClockKHR is used with a Device scope but shaderDeviceClock was not enabled.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2035 | report_data->FormatHandle(module->vk_shader_module()).c_str()); |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 2036 | } |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2037 | break; |
sfricke-samsung | 486a51e | 2021-01-02 00:10:15 -0800 | [diff] [blame] | 2038 | } |
| 2039 | } |
| 2040 | return skip; |
| 2041 | } |
| 2042 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2043 | bool CoreChecks::ValidatePipelineShaderStage(const PIPELINE_STATE *pipeline, const PipelineStageState &stage_state, |
| 2044 | bool check_point_size) const { |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2045 | bool skip = false; |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2046 | const auto *pStage = stage_state.create_info; |
| 2047 | const auto *module = stage_state.module.get(); |
| 2048 | const auto &entrypoint = stage_state.entrypoint; |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2049 | // Check the module |
| 2050 | if (!module->has_valid_spirv) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2051 | skip |= LogError( |
| 2052 | device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter", "%s does not contain valid spirv for stage %s.", |
| 2053 | report_data->FormatHandle(module->vk_shader_module()).c_str(), string_VkShaderStageFlagBits(stage_state.stage_flag)); |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2054 | } |
| 2055 | |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2056 | // If specialization-constant values are given and specialization-constant instructions are present in the shader, the |
| 2057 | // specializations should be applied and validated. |
| 2058 | if (pStage->pSpecializationInfo != nullptr && pStage->pSpecializationInfo->mapEntryCount > 0 && |
| 2059 | pStage->pSpecializationInfo->pMapEntries != nullptr && module->has_specialization_constants) { |
| 2060 | // Gather the specialization-constant values. |
| 2061 | auto const &specialization_info = pStage->pSpecializationInfo; |
Jeremy Hayes | 521221d | 2020-01-15 16:48:49 -0700 | [diff] [blame] | 2062 | auto const &specialization_data = reinterpret_cast<uint8_t const *>(specialization_info->pData); |
Jeremy Gebben | cbf2286 | 2021-03-03 12:01:22 -0700 | [diff] [blame] | 2063 | std::unordered_map<uint32_t, std::vector<uint32_t>> id_value_map; // note: this must be std:: to work with spvtools |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2064 | id_value_map.reserve(specialization_info->mapEntryCount); |
| 2065 | for (auto i = 0u; i < specialization_info->mapEntryCount; ++i) { |
| 2066 | auto const &map_entry = specialization_info->pMapEntries[i]; |
sfricke-samsung | 033b026 | 2021-07-09 00:53:06 -0700 | [diff] [blame] | 2067 | auto itr = module->spec_const_map.find(map_entry.constantID); |
| 2068 | // "If a constantID value is not a specialization constant ID used in the shader, that map entry does not affect the |
| 2069 | // behavior of the pipeline." |
| 2070 | if (itr != module->spec_const_map.cend()) { |
| 2071 | // Make sure map_entry.size matches the spec constant's size |
| 2072 | uint32_t spec_const_size = decoration_set::kInvalidValue; |
| 2073 | const auto def_ins = module->get_def(itr->second); |
| 2074 | const auto type_ins = module->get_def(def_ins.word(1)); |
| 2075 | // Specialization constants can only be of type bool, scalar integer, or scalar floating point |
| 2076 | switch (type_ins.opcode()) { |
| 2077 | case spv::OpTypeBool: |
| 2078 | // "If the specialization constant is of type boolean, size must be the byte size of VkBool32" |
| 2079 | spec_const_size = sizeof(VkBool32); |
| 2080 | break; |
| 2081 | case spv::OpTypeInt: |
| 2082 | case spv::OpTypeFloat: |
| 2083 | spec_const_size = type_ins.word(2) / 8; |
| 2084 | break; |
| 2085 | default: |
| 2086 | // spirv-val should catch if SpecId is not used on a OpSpecConstantTrue/OpSpecConstantFalse/OpSpecConstant |
| 2087 | // and OpSpecConstant is validated to be a OpTypeInt or OpTypeFloat |
| 2088 | break; |
| 2089 | } |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2090 | |
sfricke-samsung | 033b026 | 2021-07-09 00:53:06 -0700 | [diff] [blame] | 2091 | if (map_entry.size != spec_const_size) { |
| 2092 | skip |= |
| 2093 | LogError(device, "VUID-VkSpecializationMapEntry-constantID-00776", |
Nathaniel Cesario | cf69bda | 2021-06-22 13:23:42 -0600 | [diff] [blame] | 2094 | "Specialization constant (ID = %" PRIu32 ", entry = %" PRIu32 |
| 2095 | ") has invalid size %zu in shader module %s. Expected size is %" PRIu32 " from shader definition.", |
| 2096 | map_entry.constantID, i, map_entry.size, |
| 2097 | report_data->FormatHandle(module->vk_shader_module()).c_str(), spec_const_size); |
sfricke-samsung | 033b026 | 2021-07-09 00:53:06 -0700 | [diff] [blame] | 2098 | } |
Nathaniel Cesario | cf69bda | 2021-06-22 13:23:42 -0600 | [diff] [blame] | 2099 | } |
| 2100 | |
Jeremy Gebben | 12933ef | 2021-05-12 17:16:27 -0600 | [diff] [blame] | 2101 | if ((map_entry.offset + map_entry.size) <= specialization_info->dataSize) { |
Nathaniel Cesario | 0b2a642 | 2021-07-13 16:04:57 -0600 | [diff] [blame] | 2102 | // Allocate enough room for ceil(map_entry.size / 4) to store entries |
| 2103 | std::vector<uint32_t> entry_data((map_entry.size + 4 - 1) / 4, 0); |
| 2104 | uint8_t *out_p = reinterpret_cast<uint8_t *>(entry_data.data()); |
| 2105 | const uint8_t *const start_in_p = specialization_data + map_entry.offset; |
| 2106 | const uint8_t *const end_in_p = start_in_p + map_entry.size; |
| 2107 | |
| 2108 | std::copy(start_in_p, end_in_p, out_p); |
| 2109 | id_value_map.emplace(map_entry.constantID, std::move(entry_data)); |
Jeremy Gebben | 12933ef | 2021-05-12 17:16:27 -0600 | [diff] [blame] | 2110 | } |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | // Apply the specialization-constant values and revalidate the shader module. |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 2114 | spv_target_env spirv_environment = PickSpirvEnv(api_version, (device_extensions.vk_khr_spirv_1_4 != kNotEnabled)); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2115 | spvtools::Optimizer optimizer(spirv_environment); |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2116 | spvtools::MessageConsumer consumer = [&skip, &module, &stage_state, this](spv_message_level_t level, const char *source, |
| 2117 | const spv_position_t &position, |
| 2118 | const char *message) { |
| 2119 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter", |
| 2120 | "%s does not contain valid spirv for stage %s. %s", |
| 2121 | report_data->FormatHandle(module->vk_shader_module()).c_str(), |
| 2122 | string_VkShaderStageFlagBits(stage_state.stage_flag), message); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2123 | }; |
| 2124 | optimizer.SetMessageConsumer(consumer); |
| 2125 | optimizer.RegisterPass(spvtools::CreateSetSpecConstantDefaultValuePass(id_value_map)); |
| 2126 | optimizer.RegisterPass(spvtools::CreateFreezeSpecConstantValuePass()); |
| 2127 | std::vector<uint32_t> specialized_spirv; |
Nathaniel Cesario | 0b2a642 | 2021-07-13 16:04:57 -0600 | [diff] [blame] | 2128 | auto const optimized = optimizer.Run(module->words.data(), module->words.size(), &specialized_spirv); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2129 | assert(optimized == true); |
| 2130 | |
| 2131 | if (optimized) { |
| 2132 | spv_context ctx = spvContextCreate(spirv_environment); |
| 2133 | spv_const_binary_t binary{specialized_spirv.data(), specialized_spirv.size()}; |
| 2134 | spv_diagnostic diag = nullptr; |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2135 | spvtools::ValidatorOptions options; |
| 2136 | AdjustValidatorOptions(device_extensions, enabled_features, options); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2137 | auto const spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag); |
| 2138 | if (spv_valid != SPV_SUCCESS) { |
sfricke-samsung | d379380 | 2020-08-18 22:55:03 -0700 | [diff] [blame] | 2139 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-04145", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2140 | "After specialization was applied, %s does not contain valid spirv for stage %s.", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2141 | report_data->FormatHandle(module->vk_shader_module()).c_str(), |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2142 | string_VkShaderStageFlagBits(stage_state.stage_flag)); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2143 | } |
| 2144 | |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2145 | spvDiagnosticDestroy(diag); |
| 2146 | spvContextDestroy(ctx); |
| 2147 | } |
ziga-lunarg | 2818f49 | 2021-08-12 14:30:51 +0200 | [diff] [blame] | 2148 | |
| 2149 | skip |= ValidateWorkgroupSize(module, pStage, id_value_map); |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2150 | } |
| 2151 | |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2152 | // Check the entrypoint |
| 2153 | if (entrypoint == module->end()) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2154 | skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-pName-00707", "No entrypoint found named `%s` for stage %s.", |
| 2155 | pStage->pName, string_VkShaderStageFlagBits(stage_state.stage_flag)); |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2156 | } |
| 2157 | if (skip) return true; // no point continuing beyond here, any analysis is just going to be garbage. |
| 2158 | |
| 2159 | // Mark accessible ids |
| 2160 | auto &accessible_ids = stage_state.accessible_ids; |
| 2161 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2162 | // Validate descriptor set layout against what the entrypoint actually uses |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2163 | |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2164 | // The following tries to limit the number of passes through the shader module. The validation passes in here are "stateless" |
| 2165 | // and mainly only checking the instruction in detail for a single operation |
ziga-lunarg | a26b360 | 2021-08-08 15:53:00 +0200 | [diff] [blame] | 2166 | uint32_t total_shared_size = 0; |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2167 | for (auto insn : *module) { |
| 2168 | skip |= ValidateShaderCapabilitiesAndExtensions(module, insn); |
| 2169 | skip |= ValidatePropertiesAndFeatures(module, insn); |
| 2170 | skip |= ValidateShaderStageGroupNonUniform(module, pStage->stage, insn); |
ziga-lunarg | a26b360 | 2021-08-08 15:53:00 +0200 | [diff] [blame] | 2171 | total_shared_size += module->CalcComputeSharedMemory(pStage->stage, insn); |
| 2172 | } |
| 2173 | |
| 2174 | if (total_shared_size > phys_dev_props.limits.maxComputeSharedMemorySize) { |
| 2175 | skip |= LogError(device, kVUID_Core_Shader_MaxComputeSharedMemorySize, |
ziga-lunarg | 76a2e6c | 2021-08-08 15:55:03 +0200 | [diff] [blame] | 2176 | "Shader uses %" PRIu32 " bytes of shared memory, more than allowed by physicalDeviceLimits::maxComputeSharedMemorySize (%" PRIu32 ")", |
ziga-lunarg | a26b360 | 2021-08-08 15:53:00 +0200 | [diff] [blame] | 2177 | total_shared_size, phys_dev_props.limits.maxComputeSharedMemorySize); |
sfricke-samsung | 94167ca | 2021-02-26 04:14:59 -0800 | [diff] [blame] | 2178 | } |
| 2179 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2180 | skip |= ValidateShaderStageWritableOrAtomicDescriptor(pStage->stage, stage_state.has_writable_descriptor, |
| 2181 | stage_state.has_atomic_descriptor); |
Jeff Bolz | e9ee3d8 | 2019-05-29 13:45:13 -0500 | [diff] [blame] | 2182 | skip |= ValidateShaderStageInputOutputLimits(module, pStage, pipeline, entrypoint); |
Lionel Landwerlin | 892d6c3 | 2021-05-05 12:56:19 +0300 | [diff] [blame] | 2183 | skip |= ValidateShaderStorageImageFormats(module); |
sfricke-samsung | dc96f30 | 2020-03-18 20:42:10 -0700 | [diff] [blame] | 2184 | skip |= ValidateShaderStageMaxResources(pStage->stage, pipeline); |
sfricke-samsung | 58b8435 | 2021-07-31 21:41:04 -0700 | [diff] [blame] | 2185 | skip |= ValidateAtomicsTypes(module); |
Attilio Provenzano | c5d5010 | 2019-03-25 17:40:37 +0000 | [diff] [blame] | 2186 | skip |= ValidateExecutionModes(module, entrypoint); |
ziga-lunarg | ae2a5c4 | 2021-07-23 16:18:09 +0200 | [diff] [blame] | 2187 | skip |= ValidateSpecializations(pStage); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2188 | if (check_point_size && !pipeline->create_info.graphics.pRasterizationState->rasterizerDiscardEnable) { |
Mark Lobodzinski | 518eadc | 2019-03-09 12:07:30 -0700 | [diff] [blame] | 2189 | skip |= ValidatePointListShaderState(pipeline, module, entrypoint, pStage->stage); |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2190 | } |
sfricke-samsung | cfb4459 | 2021-07-25 00:36:28 -0700 | [diff] [blame] | 2191 | skip |= ValidateBuiltinLimits(module, entrypoint); |
sfricke-samsung | d093e52 | 2021-02-26 04:17:45 -0800 | [diff] [blame] | 2192 | if (enabled_features.cooperative_matrix_features.cooperativeMatrix) { |
| 2193 | skip |= ValidateCooperativeMatrix(module, pStage, pipeline); |
| 2194 | } |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2195 | if (enabled_features.fragment_shading_rate_features.primitiveFragmentShadingRate) { |
| 2196 | skip |= ValidatePrimitiveRateShaderState(pipeline, module, entrypoint, pStage->stage); |
| 2197 | } |
Jeff Leger | 9b3dcff | 2021-05-27 15:40:20 -0400 | [diff] [blame] | 2198 | if (device_extensions.vk_qcom_render_pass_shader_resolve != kNotEnabled) { |
| 2199 | skip |= ValidateShaderResolveQCOM(module, pStage, pipeline); |
| 2200 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2201 | |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 2202 | // "layout must be consistent with the layout of the * shader" |
| 2203 | // 'consistent' -> #descriptorsets-pipelinelayout-consistency |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2204 | std::string vuid_layout_mismatch; |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2205 | switch (pipeline->create_info.graphics.sType) { |
| 2206 | case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO: |
| 2207 | vuid_layout_mismatch = "VUID-VkGraphicsPipelineCreateInfo-layout-00756"; |
| 2208 | break; |
| 2209 | case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO: |
| 2210 | vuid_layout_mismatch = "VUID-VkComputePipelineCreateInfo-layout-00703"; |
| 2211 | break; |
| 2212 | case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR: |
| 2213 | vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoKHR-layout-03427"; |
| 2214 | break; |
| 2215 | case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV: |
| 2216 | vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoNV-layout-03427"; |
| 2217 | break; |
| 2218 | default: |
| 2219 | assert(false); |
| 2220 | break; |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2221 | } |
| 2222 | |
sfricke-samsung | 7699b91 | 2021-04-12 23:01:51 -0700 | [diff] [blame] | 2223 | // Validate Push Constants use |
| 2224 | skip |= ValidatePushConstantUsage(*pipeline, module, pStage, vuid_layout_mismatch); |
| 2225 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2226 | // Validate descriptor use |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2227 | for (auto use : stage_state.descriptor_uses) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2228 | // Verify given pipelineLayout has requested setLayout with requested binding |
Jeff Bolz | e7fc67b | 2019-10-04 12:29:31 -0500 | [diff] [blame] | 2229 | const auto &binding = GetDescriptorBinding(pipeline->pipeline_layout.get(), use.first); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2230 | unsigned required_descriptor_count; |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2231 | bool is_khr = binding && binding->descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR; |
| 2232 | std::set<uint32_t> descriptor_types = |
| 2233 | TypeToDescriptorTypeSet(module, use.second.type_id, required_descriptor_count, is_khr); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2234 | |
| 2235 | if (!binding) { |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2236 | skip |= LogError(device, vuid_layout_mismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2237 | "Shader uses descriptor slot %u.%u (expected `%s`) but not declared in pipeline layout", |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2238 | use.first.set, use.first.binding, string_descriptorTypes(descriptor_types).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2239 | } else if (~binding->stageFlags & pStage->stage) { |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2240 | skip |= LogError(device, vuid_layout_mismatch, |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2241 | "Shader uses descriptor slot %u.%u but descriptor not accessible from stage %s", use.first.set, |
| 2242 | use.first.binding, string_VkShaderStageFlagBits(pStage->stage)); |
Tony-LunarG | f563b36 | 2021-03-18 16:13:18 -0600 | [diff] [blame] | 2243 | } else if ((binding->descriptorType != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE) && |
| 2244 | (descriptor_types.find(binding->descriptorType) == descriptor_types.end())) { |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2245 | skip |= LogError(device, vuid_layout_mismatch, |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2246 | "Type mismatch on descriptor slot %u.%u (expected `%s`) but descriptor of type %s", use.first.set, |
| 2247 | use.first.binding, string_descriptorTypes(descriptor_types).c_str(), |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2248 | string_VkDescriptorType(binding->descriptorType)); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2249 | } else if (binding->descriptorCount < required_descriptor_count) { |
locke-lunarg | 9a16ebb | 2020-07-30 16:56:33 -0600 | [diff] [blame] | 2250 | skip |= LogError(device, vuid_layout_mismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2251 | "Shader expects at least %u descriptors for binding %u.%u but only %u provided", |
Jeremy Gebben | 7fc88a2 | 2021-08-25 13:30:45 -0600 | [diff] [blame] | 2252 | required_descriptor_count, use.first.set, use.first.binding, binding->descriptorCount); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2253 | } |
| 2254 | } |
| 2255 | |
| 2256 | // Validate use of input attachments against subpass structure |
| 2257 | if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2258 | auto input_attachment_uses = module->CollectInterfaceByInputAttachmentIndex(accessible_ids); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2259 | |
Petr Kraus | e91f7a1 | 2017-12-14 20:57:36 +0100 | [diff] [blame] | 2260 | auto rpci = pipeline->rp_state->createInfo.ptr(); |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2261 | auto subpass = pipeline->create_info.graphics.subpass; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2262 | |
| 2263 | for (auto use : input_attachment_uses) { |
| 2264 | auto input_attachments = rpci->pSubpasses[subpass].pInputAttachments; |
| 2265 | auto index = (input_attachments && use.first < rpci->pSubpasses[subpass].inputAttachmentCount) |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2266 | ? input_attachments[use.first].attachment |
| 2267 | : VK_ATTACHMENT_UNUSED; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2268 | |
| 2269 | if (index == VK_ATTACHMENT_UNUSED) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2270 | skip |= LogError(device, kVUID_Core_Shader_MissingInputAttachment, |
| 2271 | "Shader consumes input attachment index %d but not provided in subpass", use.first); |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2272 | } else if (!(GetFormatType(rpci->pAttachments[index].format) & module->GetFundamentalType(use.second.type_id))) { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2273 | skip |= |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2274 | LogError(device, kVUID_Core_Shader_InputAttachmentTypeMismatch, |
| 2275 | "Subpass input attachment %u format of %s does not match type used in shader `%s`", use.first, |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2276 | string_VkFormat(rpci->pAttachments[index].format), module->DescribeType(use.second.type_id).c_str()); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2277 | } |
| 2278 | } |
| 2279 | } |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2280 | if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT) { |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 2281 | skip |= ValidateComputeWorkGroupSizes(module, entrypoint); |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2282 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2283 | return skip; |
| 2284 | } |
| 2285 | |
Mark Lobodzinski | d8d658e | 2020-01-30 15:05:51 -0700 | [diff] [blame] | 2286 | bool CoreChecks::ValidateInterfaceBetweenStages(SHADER_MODULE_STATE const *producer, spirv_inst_iter producer_entrypoint, |
| 2287 | shader_stage_attributes const *producer_stage, SHADER_MODULE_STATE const *consumer, |
| 2288 | spirv_inst_iter consumer_entrypoint, |
| 2289 | shader_stage_attributes const *consumer_stage) const { |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2290 | bool skip = false; |
| 2291 | |
| 2292 | auto outputs = |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2293 | producer->CollectInterfaceByLocation(producer_entrypoint, spv::StorageClassOutput, producer_stage->arrayed_output); |
| 2294 | auto inputs = consumer->CollectInterfaceByLocation(consumer_entrypoint, spv::StorageClassInput, consumer_stage->arrayed_input); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2295 | |
| 2296 | auto a_it = outputs.begin(); |
| 2297 | auto b_it = inputs.begin(); |
| 2298 | |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2299 | uint32_t a_component = 0; |
| 2300 | uint32_t b_component = 0; |
| 2301 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2302 | // Maps sorted by key (location); walk them together to find mismatches |
| 2303 | while ((outputs.size() > 0 && a_it != outputs.end()) || (inputs.size() && b_it != inputs.end())) { |
| 2304 | bool a_at_end = outputs.size() == 0 || a_it == outputs.end(); |
| 2305 | bool b_at_end = inputs.size() == 0 || b_it == inputs.end(); |
| 2306 | auto a_first = a_at_end ? std::make_pair(0u, 0u) : a_it->first; |
| 2307 | auto b_first = b_at_end ? std::make_pair(0u, 0u) : b_it->first; |
| 2308 | |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2309 | a_first.second += a_component; |
| 2310 | b_first.second += b_component; |
| 2311 | |
| 2312 | const auto a_length = a_at_end ? 0 : producer->GetNumComponentsInBaseType(producer->get_def(a_it->second.type_id)); |
| 2313 | const auto b_length = b_at_end ? 0 : consumer->GetNumComponentsInBaseType(consumer->get_def(b_it->second.type_id)); |
| 2314 | assert(a_at_end || a_component < a_length); |
| 2315 | assert(b_at_end || b_component < b_length); |
| 2316 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2317 | if (b_at_end || ((!a_at_end) && (a_first < b_first))) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2318 | skip |= LogPerformanceWarning(producer->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed, |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2319 | "%s writes to output location %" PRIu32 ".%" PRIu32 " which is not consumed by %s", |
| 2320 | producer_stage->name, a_first.first, a_first.second, consumer_stage->name); |
| 2321 | if ((b_first.first > a_first.first) || b_at_end || (a_component + 1 == a_length)) { |
| 2322 | a_it++; |
| 2323 | a_component = 0; |
| 2324 | } else { |
| 2325 | a_component++; |
| 2326 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2327 | } else if (a_at_end || a_first > b_first) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2328 | skip |= LogError(consumer->vk_shader_module(), kVUID_Core_Shader_InputNotProduced, |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2329 | "%s consumes input location %" PRIu32 ".%" PRIu32 " which is not written by %s", consumer_stage->name, |
| 2330 | b_first.first, b_first.second, producer_stage->name); |
| 2331 | if ((a_first.first > b_first.first) || a_at_end || (b_component + 1 == b_length)) { |
| 2332 | b_it++; |
| 2333 | b_component = 0; |
| 2334 | } else { |
| 2335 | b_component++; |
| 2336 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2337 | } else { |
| 2338 | // subtleties of arrayed interfaces: |
| 2339 | // - if is_patch, then the member is not arrayed, even though the interface may be. |
| 2340 | // - if is_block_member, then the extra array level of an arrayed interface is not |
| 2341 | // expressed in the member type -- it's expressed in the block type. |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2342 | if (!TypesMatch(producer, consumer, a_it->second.type_id, b_it->second.type_id)) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2343 | skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2344 | "Type mismatch on location %" PRIu32 ".%" PRIu32 ": '%s' vs '%s'", a_first.first, a_first.second, |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2345 | producer->DescribeType(a_it->second.type_id).c_str(), |
| 2346 | consumer->DescribeType(b_it->second.type_id).c_str()); |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2347 | a_it++; |
| 2348 | b_it++; |
| 2349 | continue; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2350 | } |
| 2351 | if (a_it->second.is_patch != b_it->second.is_patch) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2352 | skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2353 | "Decoration mismatch on location %u.%u: is per-%s in %s stage but per-%s in %s stage", |
| 2354 | a_first.first, a_first.second, a_it->second.is_patch ? "patch" : "vertex", producer_stage->name, |
| 2355 | b_it->second.is_patch ? "patch" : "vertex", consumer_stage->name); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2356 | } |
| 2357 | if (a_it->second.is_relaxed_precision != b_it->second.is_relaxed_precision) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2358 | skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2359 | "Decoration mismatch on location %" PRIu32 ".%" PRIu32 ": %s and %s stages differ in precision", |
| 2360 | a_first.first, a_first.second, producer_stage->name, consumer_stage->name); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2361 | } |
ziga-lunarg | 8346fe8 | 2021-08-22 17:30:50 +0200 | [diff] [blame^] | 2362 | uint32_t a_remaining = a_length - a_component; |
| 2363 | uint32_t b_remaining = b_length - b_component; |
| 2364 | if (a_remaining == b_remaining) { // Sizes match so we can advance both a_it and b_it |
| 2365 | a_it++; |
| 2366 | b_it++; |
| 2367 | a_component = 0; |
| 2368 | b_component = 0; |
| 2369 | } else if (a_remaining > b_remaining) { // a has more components remaining |
| 2370 | a_component += b_remaining; |
| 2371 | b_component = 0; |
| 2372 | b_it++; |
| 2373 | } else if (b_remaining > a_remaining) { // b has more components remaining |
| 2374 | b_component += a_remaining; |
| 2375 | a_component = 0; |
| 2376 | a_it++; |
| 2377 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2378 | } |
| 2379 | } |
| 2380 | |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 2381 | if (consumer_stage->stage != VK_SHADER_STAGE_FRAGMENT_BIT) { |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2382 | auto builtins_producer = producer->CollectBuiltinBlockMembers(producer_entrypoint, spv::StorageClassOutput); |
| 2383 | auto builtins_consumer = consumer->CollectBuiltinBlockMembers(consumer_entrypoint, spv::StorageClassInput); |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 2384 | |
| 2385 | if (!builtins_producer.empty() && !builtins_consumer.empty()) { |
| 2386 | if (builtins_producer.size() != builtins_consumer.size()) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2387 | skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2388 | "Number of elements inside builtin block differ between stages (%s %d vs %s %d).", |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2389 | producer_stage->name, static_cast<int>(builtins_producer.size()), consumer_stage->name, |
| 2390 | static_cast<int>(builtins_consumer.size())); |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 2391 | } else { |
| 2392 | auto it_producer = builtins_producer.begin(); |
| 2393 | auto it_consumer = builtins_consumer.begin(); |
| 2394 | while (it_producer != builtins_producer.end() && it_consumer != builtins_consumer.end()) { |
| 2395 | if (*it_producer != *it_consumer) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2396 | skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2397 | "Builtin variable inside block doesn't match between %s and %s.", producer_stage->name, |
| 2398 | consumer_stage->name); |
Ari Suonpaa | 696b343 | 2019-03-11 14:02:57 +0200 | [diff] [blame] | 2399 | break; |
| 2400 | } |
| 2401 | it_producer++; |
| 2402 | it_consumer++; |
| 2403 | } |
| 2404 | } |
| 2405 | } |
| 2406 | } |
| 2407 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2408 | return skip; |
| 2409 | } |
| 2410 | |
John Zulauf | 14c355b | 2019-06-27 16:09:37 -0600 | [diff] [blame] | 2411 | static inline uint32_t DetermineFinalGeomStage(const PIPELINE_STATE *pipeline, const VkGraphicsPipelineCreateInfo *pCreateInfo) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2412 | uint32_t stage_mask = 0; |
| 2413 | if (pipeline->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) { |
| 2414 | for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) { |
| 2415 | stage_mask |= pCreateInfo->pStages[i].stage; |
| 2416 | } |
| 2417 | // 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] | 2418 | if (stage_mask & VK_SHADER_STAGE_MESH_BIT_NV) { |
| 2419 | stage_mask = VK_SHADER_STAGE_MESH_BIT_NV; |
| 2420 | } else if (stage_mask & VK_SHADER_STAGE_GEOMETRY_BIT) { |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2421 | stage_mask = VK_SHADER_STAGE_GEOMETRY_BIT; |
| 2422 | } else if (stage_mask & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) { |
| 2423 | stage_mask = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT; |
| 2424 | } else if (stage_mask & VK_SHADER_STAGE_VERTEX_BIT) { |
| 2425 | stage_mask = VK_SHADER_STAGE_VERTEX_BIT; |
Mark Lobodzinski | 2c984cc | 2018-07-31 09:57:46 -0600 | [diff] [blame] | 2426 | } |
| 2427 | } |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2428 | return stage_mask; |
Mark Lobodzinski | 2c984cc | 2018-07-31 09:57:46 -0600 | [diff] [blame] | 2429 | } |
| 2430 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2431 | // Validate that the shaders used by the given pipeline and store the active_slots |
| 2432 | // that are actually used by the pipeline into pPipeline->active_slots |
John Zulauf | ac4c6e1 | 2019-07-01 16:05:58 -0600 | [diff] [blame] | 2433 | bool CoreChecks::ValidateGraphicsPipelineShaderState(const PIPELINE_STATE *pipeline) const { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2434 | const auto create_info = pipeline->create_info.graphics.ptr(); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2435 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2436 | bool skip = false; |
| 2437 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2438 | uint32_t pointlist_stage_mask = DetermineFinalGeomStage(pipeline, create_info); |
Mark Lobodzinski | 1b4a8ed | 2018-08-07 08:47:05 -0600 | [diff] [blame] | 2439 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2440 | const PipelineStageState *vertex_stage = nullptr, *fragment_stage = nullptr; |
| 2441 | for (auto &stage : pipeline->stage_state) { |
| 2442 | skip |= ValidatePipelineShaderStage(pipeline, stage, (pointlist_stage_mask == stage.stage_flag)); |
| 2443 | if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT) { |
| 2444 | vertex_stage = &stage; |
| 2445 | } |
| 2446 | if (stage.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT) { |
| 2447 | fragment_stage = &stage; |
| 2448 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | // if the shader stages are no good individually, cross-stage validation is pointless. |
| 2452 | if (skip) return true; |
| 2453 | |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2454 | auto vi = create_info->pVertexInputState; |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2455 | |
| 2456 | if (vi) { |
Mark Lobodzinski | d8d658e | 2020-01-30 15:05:51 -0700 | [diff] [blame] | 2457 | skip |= ValidateViConsistency(vi); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2458 | } |
| 2459 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2460 | if (vertex_stage && vertex_stage->module->has_valid_spirv && !IsDynamic(pipeline, VK_DYNAMIC_STATE_VERTEX_INPUT_EXT)) { |
| 2461 | skip |= ValidateViAgainstVsInputs(vi, vertex_stage->module.get(), vertex_stage->entrypoint); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2464 | for (size_t i = 1; i < pipeline->stage_state.size(); i++) { |
| 2465 | const auto &producer = pipeline->stage_state[i - 1]; |
| 2466 | const auto &consumer = pipeline->stage_state[i]; |
| 2467 | assert(producer.module); |
| 2468 | if (&producer == fragment_stage) { |
| 2469 | break; |
| 2470 | } |
| 2471 | if (consumer.module) { |
| 2472 | if (consumer.module->has_valid_spirv && producer.module->has_valid_spirv) { |
| 2473 | auto producer_id = GetShaderStageId(producer.stage_flag); |
| 2474 | auto consumer_id = GetShaderStageId(consumer.stage_flag); |
| 2475 | skip |= |
| 2476 | ValidateInterfaceBetweenStages(producer.module.get(), producer.entrypoint, &shader_stage_attribs[producer_id], |
| 2477 | consumer.module.get(), consumer.entrypoint, &shader_stage_attribs[consumer_id]); |
Chris Forbes | dbb43fc | 2018-02-16 16:59:23 -0800 | [diff] [blame] | 2478 | } |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2479 | |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2483 | if (fragment_stage && fragment_stage->module->has_valid_spirv) { |
| 2484 | skip |= ValidateFsOutputsAgainstRenderPass(fragment_stage->module.get(), fragment_stage->entrypoint, pipeline, |
Nathaniel Cesario | ce9b481 | 2020-12-17 08:55:28 -0700 | [diff] [blame] | 2485 | create_info->subpass); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | return skip; |
| 2489 | } |
| 2490 | |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2491 | void CoreChecks::RecordGraphicsPipelineShaderDynamicState(PIPELINE_STATE *pipeline_state) { |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2492 | if (phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports || |
| 2493 | !IsDynamic(pipeline_state, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT)) { |
| 2494 | return; |
| 2495 | } |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2496 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2497 | for (auto &stage : pipeline_state->stage_state) { |
| 2498 | if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage.stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT || |
| 2499 | stage.stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) { |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2500 | bool primitiverate_written = false; |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2501 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2502 | for (auto set : stage.module->builtin_decoration_list) { |
| 2503 | auto insn = stage.module->at(set.offset); |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 2504 | if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2505 | primitiverate_written = stage.module->IsBuiltInWritten(insn, stage.entrypoint); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2506 | } |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 2507 | if (primitiverate_written) { |
| 2508 | break; |
| 2509 | } |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2510 | } |
sfricke-samsung | c0eb528 | 2021-02-28 23:05:55 -0800 | [diff] [blame] | 2511 | |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2512 | if (primitiverate_written) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2513 | pipeline_state->wrote_primitive_shading_rate.insert(stage.stage_flag); |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2514 | } |
| 2515 | } |
| 2516 | } |
| 2517 | } |
| 2518 | |
| 2519 | bool CoreChecks::ValidateGraphicsPipelineShaderDynamicState(const PIPELINE_STATE *pipeline, const CMD_BUFFER_STATE *pCB, |
| 2520 | const char *caller, const DrawDispatchVuid &vuid) const { |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2521 | bool skip = false; |
| 2522 | |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2523 | for (auto &stage : pipeline->stage_state) { |
| 2524 | if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage.stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT || |
| 2525 | stage.stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) { |
Tony-LunarG | b2ded51 | 2021-02-02 16:03:30 -0700 | [diff] [blame] | 2526 | if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports && |
| 2527 | IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) && pCB->viewportWithCountCount != 1) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2528 | if (pipeline->wrote_primitive_shading_rate.find(stage.stage_flag) != pipeline->wrote_primitive_shading_rate.end()) { |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2529 | skip |= |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2530 | LogError(pipeline->pipeline(), vuid.viewport_count_primitive_shading_rate, |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2531 | "%s: %s shader of currently bound pipeline statically writes to PrimitiveShadingRateKHR built-in" |
| 2532 | "but multiple viewports are set by the last call to vkCmdSetViewportWithCountEXT," |
| 2533 | "and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.", |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2534 | caller, string_VkShaderStageFlagBits(stage.stage_flag)); |
Tobias Hector | 6663c9b | 2020-11-05 10:18:02 +0000 | [diff] [blame] | 2535 | } |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | return skip; |
| 2541 | } |
| 2542 | |
sfricke-samsung | e72a85e | 2020-02-29 21:48:37 -0800 | [diff] [blame] | 2543 | bool CoreChecks::ValidateComputePipelineShaderState(PIPELINE_STATE *pipeline) const { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2544 | return ValidatePipelineShaderStage(pipeline, pipeline->stage_state[0], false); |
Chris Forbes | 47567b7 | 2017-06-09 12:09:45 -0700 | [diff] [blame] | 2545 | } |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2546 | |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2547 | uint32_t CoreChecks::CalcShaderStageCount(const PIPELINE_STATE *pipeline, VkShaderStageFlagBits stageBit) const { |
| 2548 | uint32_t total = 0; |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2549 | const auto &create_info = pipeline->create_info.raytracing; |
| 2550 | const auto *stages = create_info.ptr()->pStages; |
| 2551 | for (uint32_t stage_index = 0; stage_index < create_info.stageCount; stage_index++) { |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2552 | if (stages[stage_index].stage == stageBit) { |
| 2553 | total++; |
| 2554 | } |
| 2555 | } |
| 2556 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2557 | if (create_info.pLibraryInfo) { |
| 2558 | for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) { |
| 2559 | const PIPELINE_STATE *library_pipeline = GetPipelineState(create_info.pLibraryInfo->pLibraries[i]); |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2560 | total += CalcShaderStageCount(library_pipeline, stageBit); |
| 2561 | } |
| 2562 | } |
| 2563 | |
| 2564 | return total; |
| 2565 | } |
| 2566 | |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2567 | bool CoreChecks::ValidateRayTracingPipeline(PIPELINE_STATE *pipeline, VkPipelineCreateFlags flags, bool isKHR) const { |
John Zulauf | e4474e7 | 2019-07-01 17:28:27 -0600 | [diff] [blame] | 2568 | bool skip = false; |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2569 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2570 | const auto &create_info = pipeline->create_info.raytracing; |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2571 | if (isKHR) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2572 | if (create_info.maxPipelineRayRecursionDepth > phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth) { |
| 2573 | skip |= |
| 2574 | LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-maxPipelineRayRecursionDepth-03589", |
| 2575 | "vkCreateRayTracingPipelinesKHR: maxPipelineRayRecursionDepth (%d ) must be less than or equal to " |
| 2576 | "VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxRayRecursionDepth %d", |
| 2577 | create_info.maxPipelineRayRecursionDepth, phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2578 | } |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2579 | if (create_info.pLibraryInfo) { |
| 2580 | for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) { |
| 2581 | const PIPELINE_STATE *library_pipelinestate = GetPipelineState(create_info.pLibraryInfo->pLibraries[i]); |
| 2582 | const auto &library_create_info = library_pipelinestate->create_info.raytracing; |
| 2583 | if (library_create_info.maxPipelineRayRecursionDepth != create_info.maxPipelineRayRecursionDepth) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2584 | skip |= LogError( |
| 2585 | device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraries-03591", |
| 2586 | "vkCreateRayTracingPipelinesKHR: Each element (%d) of the pLibraries member of libraries must have been" |
| 2587 | "created with the value of maxPipelineRayRecursionDepth (%d) equal to that in this pipeline (%d) .", |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2588 | i, library_create_info.maxPipelineRayRecursionDepth, create_info.maxPipelineRayRecursionDepth); |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2589 | } |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2590 | if (library_create_info.pLibraryInfo && (library_create_info.pLibraryInterface->maxPipelineRayHitAttributeSize != |
| 2591 | create_info.pLibraryInterface->maxPipelineRayHitAttributeSize || |
| 2592 | library_create_info.pLibraryInterface->maxPipelineRayPayloadSize != |
| 2593 | create_info.pLibraryInterface->maxPipelineRayPayloadSize)) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2594 | skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraryInfo-03593", |
| 2595 | "vkCreateRayTracingPipelinesKHR: If pLibraryInfo is not NULL, each element of its pLibraries " |
| 2596 | "member must have been created with values of the maxPipelineRayPayloadSize and " |
| 2597 | "maxPipelineRayHitAttributeSize members of pLibraryInterface equal to those in this pipeline"); |
| 2598 | } |
| 2599 | if ((flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR) && |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2600 | !(library_create_info.flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR)) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2601 | skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03594", |
| 2602 | "vkCreateRayTracingPipelinesKHR: If flags includes " |
| 2603 | "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR, each element of " |
| 2604 | "the pLibraries member of libraries must have been created with the " |
| 2605 | "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR bit set"); |
| 2606 | } |
sourav parmar | 83c31b1 | 2020-05-06 12:30:54 -0700 | [diff] [blame] | 2607 | } |
| 2608 | } |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2609 | } else { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2610 | if (create_info.maxRecursionDepth > phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth) { |
sourav parmar | cd5fb18 | 2020-07-17 12:58:44 -0700 | [diff] [blame] | 2611 | skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-maxRecursionDepth-03457", |
| 2612 | "vkCreateRayTracingPipelinesNV: maxRecursionDepth (%d) must be less than or equal to " |
| 2613 | "VkPhysicalDeviceRayTracingPropertiesNV::maxRecursionDepth (%d)", |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2614 | create_info.maxRecursionDepth, phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth); |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2615 | } |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2616 | } |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2617 | const auto *stages = create_info.ptr()->pStages; |
| 2618 | const auto *groups = create_info.ptr()->pGroups; |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2619 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2620 | for (uint32_t stage_index = 0; stage_index < create_info.stageCount; stage_index++) { |
Jeremy Gebben | 84b838b | 2021-08-23 08:41:39 -0600 | [diff] [blame] | 2621 | skip |= ValidatePipelineShaderStage(pipeline, pipeline->stage_state[stage_index], false); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2622 | } |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2623 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2624 | if ((create_info.flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) == 0) { |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2625 | const uint32_t raygen_stages_count = CalcShaderStageCount(pipeline, VK_SHADER_STAGE_RAYGEN_BIT_KHR); |
| 2626 | if (raygen_stages_count == 0) { |
| 2627 | skip |= LogError( |
| 2628 | device, |
Mike Schuchardt | 7b152fa | 2021-08-03 16:30:27 -0700 | [diff] [blame] | 2629 | isKHR ? "VUID-VkRayTracingPipelineCreateInfoKHR-stage-03425" : "VUID-VkRayTracingPipelineCreateInfoNV-stage-06232", |
Ricardo Garcia | 6f3477e | 2020-10-21 10:58:53 +0200 | [diff] [blame] | 2630 | " : The stage member of at least one element of pStages must be VK_SHADER_STAGE_RAYGEN_BIT_KHR."); |
| 2631 | } |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2632 | } |
| 2633 | |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2634 | for (uint32_t group_index = 0; group_index < create_info.groupCount; group_index++) { |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2635 | const auto &group = groups[group_index]; |
| 2636 | |
| 2637 | if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2638 | if (group.generalShader >= create_info.stageCount || |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2639 | (stages[group.generalShader].stage != VK_SHADER_STAGE_RAYGEN_BIT_NV && |
| 2640 | stages[group.generalShader].stage != VK_SHADER_STAGE_MISS_BIT_NV && |
| 2641 | stages[group.generalShader].stage != VK_SHADER_STAGE_CALLABLE_BIT_NV)) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2642 | skip |= LogError(device, |
| 2643 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03474" |
| 2644 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02413", |
| 2645 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2646 | } |
| 2647 | if (group.anyHitShader != VK_SHADER_UNUSED_NV || group.closestHitShader != VK_SHADER_UNUSED_NV || |
| 2648 | group.intersectionShader != VK_SHADER_UNUSED_NV) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2649 | skip |= LogError(device, |
| 2650 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03475" |
| 2651 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02414", |
| 2652 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2653 | } |
| 2654 | } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2655 | if (group.intersectionShader >= create_info.stageCount || |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2656 | stages[group.intersectionShader].stage != VK_SHADER_STAGE_INTERSECTION_BIT_NV) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2657 | skip |= LogError(device, |
| 2658 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03476" |
| 2659 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02415", |
| 2660 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2661 | } |
| 2662 | } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) { |
| 2663 | if (group.intersectionShader != VK_SHADER_UNUSED_NV) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2664 | skip |= LogError(device, |
| 2665 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03477" |
| 2666 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02416", |
| 2667 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV || |
| 2672 | group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) { |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2673 | if (group.anyHitShader != VK_SHADER_UNUSED_NV && (group.anyHitShader >= create_info.stageCount || |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2674 | stages[group.anyHitShader].stage != VK_SHADER_STAGE_ANY_HIT_BIT_NV)) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2675 | skip |= LogError(device, |
| 2676 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-anyHitShader-03479" |
| 2677 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-anyHitShader-02418", |
| 2678 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2679 | } |
| 2680 | if (group.closestHitShader != VK_SHADER_UNUSED_NV && |
Jeremy Gebben | 11af979 | 2021-08-20 10:20:09 -0600 | [diff] [blame] | 2681 | (group.closestHitShader >= create_info.stageCount || |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2682 | stages[group.closestHitShader].stage != VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV)) { |
Jeff Bolz | 443c2ca | 2020-03-19 12:11:51 -0500 | [diff] [blame] | 2683 | skip |= LogError(device, |
| 2684 | isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-closestHitShader-03478" |
| 2685 | : "VUID-VkRayTracingShaderGroupCreateInfoNV-closestHitShader-02417", |
| 2686 | ": pGroups[%d]", group_index); |
Jason Macnak | 15f95e8 | 2019-08-21 21:52:02 -0400 | [diff] [blame] | 2687 | } |
| 2688 | } |
John Zulauf | e4474e7 | 2019-07-01 17:28:27 -0600 | [diff] [blame] | 2689 | } |
| 2690 | return skip; |
Jeff Bolz | fbe5158 | 2018-09-13 10:01:35 -0500 | [diff] [blame] | 2691 | } |
| 2692 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2693 | 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] | 2694 | |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2695 | static ValidationCache *GetValidationCacheInfo(VkShaderModuleCreateInfo const *pCreateInfo) { |
Mark Lobodzinski | 1f887d3 | 2020-12-30 15:31:33 -0700 | [diff] [blame] | 2696 | const auto validation_cache_ci = LvlFindInChain<VkShaderModuleValidationCacheCreateInfoEXT>(pCreateInfo->pNext); |
John Zulauf | 25ea243 | 2019-04-05 10:07:38 -0600 | [diff] [blame] | 2697 | if (validation_cache_ci) { |
John Zulauf | 146ee80 | 2019-04-05 15:31:06 -0600 | [diff] [blame] | 2698 | return CastFromHandle<ValidationCache *>(validation_cache_ci->validationCache); |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2699 | } |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2700 | return nullptr; |
| 2701 | } |
| 2702 | |
Mark Lobodzinski | b56bbb9 | 2019-02-18 11:49:59 -0700 | [diff] [blame] | 2703 | bool CoreChecks::PreCallValidateCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo, |
Jeff Bolz | 5c801d1 | 2019-10-09 10:38:45 -0500 | [diff] [blame] | 2704 | const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule) const { |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2705 | bool skip = false; |
| 2706 | spv_result_t spv_valid = SPV_SUCCESS; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2707 | |
Mark Lobodzinski | 90eea5b | 2020-05-15 12:54:00 -0600 | [diff] [blame] | 2708 | if (disabled[shader_validation]) { |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2709 | return false; |
| 2710 | } |
| 2711 | |
Mark Lobodzinski | f45e45f | 2019-04-19 14:15:39 -0600 | [diff] [blame] | 2712 | auto have_glsl_shader = device_extensions.vk_nv_glsl_shader; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2713 | |
| 2714 | if (!have_glsl_shader && (pCreateInfo->codeSize % 4)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2715 | skip |= LogError(device, "VUID-VkShaderModuleCreateInfo-pCode-01376", |
| 2716 | "SPIR-V module not valid: Codesize must be a multiple of 4 but is " PRINTF_SIZE_T_SPECIFIER ".", |
| 2717 | pCreateInfo->codeSize); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2718 | } else { |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2719 | auto cache = GetValidationCacheInfo(pCreateInfo); |
| 2720 | uint32_t hash = 0; |
Tony-LunarG | 55fdf1e | 2021-01-13 14:32:56 -0700 | [diff] [blame] | 2721 | // If app isn't using a shader validation cache, use the default one from CoreChecks |
| 2722 | if (!cache) cache = CastFromHandle<ValidationCache *>(core_validation_cache); |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2723 | if (cache) { |
| 2724 | hash = ValidationCache::MakeShaderHash(pCreateInfo); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2725 | if (cache->Contains(hash)) return false; |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Jeremy Hayes | b3e4d53 | 2019-08-16 10:08:49 -0600 | [diff] [blame] | 2728 | // Use SPIRV-Tools validator to try and catch any issues with the module itself. If specialization constants are present, |
| 2729 | // the default values will be used during validation. |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 2730 | spv_target_env spirv_environment = PickSpirvEnv(api_version, (device_extensions.vk_khr_spirv_1_4 != kNotEnabled)); |
Dave Houlton | 0ea2d01 | 2018-06-21 14:00:26 -0600 | [diff] [blame] | 2731 | spv_context ctx = spvContextCreate(spirv_environment); |
Dave Houlton | a9df0ce | 2018-02-07 10:51:23 -0700 | [diff] [blame] | 2732 | spv_const_binary_t binary{pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t)}; |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2733 | spv_diagnostic diag = nullptr; |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2734 | spvtools::ValidatorOptions options; |
| 2735 | AdjustValidatorOptions(device_extensions, enabled_features, options); |
Karl Schultz | fda1b38 | 2018-08-08 18:56:11 -0600 | [diff] [blame] | 2736 | spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag); |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2737 | if (spv_valid != SPV_SUCCESS) { |
| 2738 | if (!have_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) { |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2739 | if (spv_valid == SPV_WARNING) { |
| 2740 | skip |= LogWarning(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s", |
| 2741 | diag && diag->error ? diag->error : "(no error text)"); |
| 2742 | } else { |
| 2743 | skip |= LogError(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s", |
| 2744 | diag && diag->error ? diag->error : "(no error text)"); |
| 2745 | } |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2746 | } |
Chris Forbes | 9a61e08 | 2017-07-24 15:35:29 -0700 | [diff] [blame] | 2747 | } else { |
| 2748 | if (cache) { |
| 2749 | cache->Insert(hash); |
| 2750 | } |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | spvDiagnosticDestroy(diag); |
| 2754 | spvContextDestroy(ctx); |
| 2755 | } |
| 2756 | |
Chris Forbes | 4ae55b3 | 2017-06-09 14:42:56 -0700 | [diff] [blame] | 2757 | return skip; |
Mark Lobodzinski | 0173407 | 2019-02-13 17:39:15 -0700 | [diff] [blame] | 2758 | } |
| 2759 | |
sfricke-samsung | 8a7341a | 2021-02-28 07:30:21 -0800 | [diff] [blame] | 2760 | bool CoreChecks::ValidateComputeWorkGroupSizes(const SHADER_MODULE_STATE *shader, const spirv_inst_iter &entrypoint) const { |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2761 | bool skip = false; |
| 2762 | uint32_t local_size_x = 0; |
| 2763 | uint32_t local_size_y = 0; |
| 2764 | uint32_t local_size_z = 0; |
sfricke-samsung | 962cad9 | 2021-04-13 00:46:29 -0700 | [diff] [blame] | 2765 | if (shader->FindLocalSize(entrypoint, local_size_x, local_size_y, local_size_z)) { |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2766 | if (local_size_x > phys_dev_props.limits.maxComputeWorkGroupSize[0]) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2767 | skip |= LogError(shader->vk_shader_module(), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2768 | "%s local_size_x (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[0] (%" PRIu32 ").", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2769 | report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2770 | phys_dev_props.limits.maxComputeWorkGroupSize[0]); |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2771 | } |
| 2772 | if (local_size_y > phys_dev_props.limits.maxComputeWorkGroupSize[1]) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2773 | skip |= LogError(shader->vk_shader_module(), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2774 | "%s local_size_y (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[1] (%" PRIu32 ").", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2775 | report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2776 | phys_dev_props.limits.maxComputeWorkGroupSize[1]); |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2777 | } |
| 2778 | if (local_size_z > phys_dev_props.limits.maxComputeWorkGroupSize[2]) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2779 | skip |= LogError(shader->vk_shader_module(), "UNASSIGNED-features-limits-maxComputeWorkGroupSize", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2780 | "%s local_size_z (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[2] (%" PRIu32 ").", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2781 | report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2782 | phys_dev_props.limits.maxComputeWorkGroupSize[2]); |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | uint32_t limit = phys_dev_props.limits.maxComputeWorkGroupInvocations; |
| 2786 | uint64_t invocations = local_size_x * local_size_y; |
| 2787 | // Prevent overflow. |
| 2788 | bool fail = false; |
| 2789 | if (invocations > UINT32_MAX || invocations > limit) { |
| 2790 | fail = true; |
| 2791 | } |
| 2792 | if (!fail) { |
| 2793 | invocations *= local_size_z; |
| 2794 | if (invocations > UINT32_MAX || invocations > limit) { |
| 2795 | fail = true; |
| 2796 | } |
| 2797 | } |
| 2798 | if (fail) { |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2799 | skip |= LogError(shader->vk_shader_module(), "UNASSIGNED-features-limits-maxComputeWorkGroupInvocations", |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2800 | "%s local_size (%" PRIu32 ", %" PRIu32 ", %" PRIu32 |
| 2801 | ") exceeds device limit maxComputeWorkGroupInvocations (%" PRIu32 ").", |
Jeremy Gebben | 14b0d1a | 2021-05-15 20:15:41 -0600 | [diff] [blame] | 2802 | report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x, local_size_y, local_size_z, |
Mark Lobodzinski | 12b9be9 | 2020-01-30 15:25:55 -0700 | [diff] [blame] | 2803 | limit); |
Locke | aa8fdc0 | 2019-04-02 11:59:20 -0600 | [diff] [blame] | 2804 | } |
| 2805 | } |
| 2806 | return skip; |
| 2807 | } |
Tony-LunarG | 8a51b7d | 2020-07-01 15:57:23 -0600 | [diff] [blame] | 2808 | |
| 2809 | spv_target_env PickSpirvEnv(uint32_t api_version, bool spirv_1_4) { |
| 2810 | if (api_version >= VK_API_VERSION_1_2) { |
| 2811 | return SPV_ENV_VULKAN_1_2; |
| 2812 | } else if (api_version >= VK_API_VERSION_1_1) { |
| 2813 | if (spirv_1_4) { |
| 2814 | return SPV_ENV_VULKAN_1_1_SPIRV_1_4; |
| 2815 | } else { |
| 2816 | return SPV_ENV_VULKAN_1_1; |
| 2817 | } |
| 2818 | } |
| 2819 | return SPV_ENV_VULKAN_1_0; |
| 2820 | } |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2821 | |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2822 | // Some Vulkan extensions/features are just all done in spirv-val behind optional settings |
Jeremy Gebben | 5d97074 | 2021-05-31 16:04:14 -0600 | [diff] [blame] | 2823 | void AdjustValidatorOptions(const DeviceExtensions &device_extensions, const DeviceFeatures &enabled_features, |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2824 | spvtools::ValidatorOptions &options) { |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2825 | // VK_KHR_relaxed_block_layout never had a feature bit so just enabling the extension allows relaxed layout |
| 2826 | // Was promotoed in Vulkan 1.1 so anyone using Vulkan 1.1 also gets this for free |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2827 | if (device_extensions.vk_khr_relaxed_block_layout) { |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2828 | // --relax-block-layout |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2829 | options.SetRelaxBlockLayout(true); |
| 2830 | } |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2831 | |
| 2832 | // The rest of the settings are controlled from a feature bit, which are set correctly in the state tracking. Regardless of |
| 2833 | // Vulkan version used, the feature bit is needed (also described in the spec). |
| 2834 | |
| 2835 | if (enabled_features.core12.uniformBufferStandardLayout == VK_TRUE) { |
| 2836 | // --uniform-buffer-standard-layout |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2837 | options.SetUniformBufferStandardLayout(true); |
| 2838 | } |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2839 | if (enabled_features.core12.scalarBlockLayout == VK_TRUE) { |
| 2840 | // --scalar-block-layout |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2841 | options.SetScalarBlockLayout(true); |
| 2842 | } |
sfricke-samsung | ecc112a | 2021-09-03 05:32:17 -0700 | [diff] [blame] | 2843 | if (enabled_features.workgroup_memory_explicit_layout_features.workgroupMemoryExplicitLayoutScalarBlockLayout) { |
| 2844 | // --workgroup-scalar-block-layout |
Caio Marcelo de Oliveira Filho | d1bfbcd | 2021-01-27 01:44:04 -0800 | [diff] [blame] | 2845 | options.SetWorkgroupScalarBlockLayout(true); |
| 2846 | } |
Tony-LunarG | 9fe69a4 | 2020-07-23 15:09:37 -0600 | [diff] [blame] | 2847 | } |