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