blob: 4315e5f47e3e5e953c7f4e4ec21e884fd68099a8 [file] [log] [blame]
sfricke-samsung691299b2021-01-01 20:48:48 -08001/* 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 Hector6663c9b2020-11-05 10:18:02 +00005 * Modifications Copyright (C) 2020 Advanced Micro Devices, Inc. All rights reserved.
Chris Forbes47567b72017-06-09 12:09:45 -07006 *
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 Houlton51653902018-06-22 17:32:13 -060020 * Author: Dave Houlton <daveh@lunarg.com>
Tobias Hector6663c9b2020-11-05 10:18:02 +000021 * Author: Tobias Hector <tobias.hector@amd.com>
Chris Forbes47567b72017-06-09 12:09:45 -070022 */
23
Petr Kraus25810d02019-08-27 17:41:15 +020024#include "shader_validation.h"
25
Chris Forbes47567b72017-06-09 12:09:45 -070026#include <cassert>
Petr Kraus25810d02019-08-27 17:41:15 +020027#include <cinttypes>
Jeff Bolzf234bf82019-11-04 14:07:15 -060028#include <cmath>
Chris Forbes47567b72017-06-09 12:09:45 -070029#include <sstream>
Petr Kraus25810d02019-08-27 17:41:15 +020030#include <string>
Petr Kraus25810d02019-08-27 17:41:15 +020031#include <vector>
32
Mark Lobodzinski102687e2020-04-28 11:03:28 -060033#include <spirv/unified1/spirv.hpp>
Chris Forbes47567b72017-06-09 12:09:45 -070034#include "vk_enum_string_helper.h"
Chris Forbes47567b72017-06-09 12:09:45 -070035#include "vk_layer_data.h"
Chris Forbes47567b72017-06-09 12:09:45 -070036#include "vk_layer_utils.h"
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -070037#include "chassis.h"
Chris Forbes47567b72017-06-09 12:09:45 -070038#include "core_validation.h"
sfricke-samsung3c5dee22021-10-14 09:58:14 -070039#include "spirv_grammar_helper.h"
Petr Kraus25810d02019-08-27 17:41:15 +020040
Chris Forbes9a61e082017-07-24 15:35:29 -070041#include "xxhash.h"
Chris Forbes47567b72017-06-09 12:09:45 -070042
Chris Forbes47567b72017-06-09 12:09:45 -070043static shader_stage_attributes shader_stage_attribs[] = {
Ari Suonpaa696b3432019-03-11 14:02:57 +020044 {"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 Forbes47567b72017-06-09 12:09:45 -070049};
50
ziga-lunarg19fc6ae2021-09-09 00:05:19 +020051static 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-lunarg8346fe82021-08-22 17:30:50 +020057static 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-lunarg19fc6ae2021-09-09 00:05:19 +020074 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-lunarg8346fe82021-08-22 17:30:50 +020078 return false;
79 }
80 }
81
82 return true;
83 }
84 }
85 return false;
Chris Forbes47567b72017-06-09 12:09:45 -070086}
87
ziga-lunarg19fc6ae2021-09-09 00:05:19 +020088static 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 Forbes47567b72017-06-09 12:09:45 -070091
ziga-lunarg8346fe82021-08-22 17:30:50 +020092 return BaseTypesMatch(a, b, a_base_insn, b_base_insn);
Chris Forbes47567b72017-06-09 12:09:45 -070093}
94
Shannon McPhersonc06c33d2018-06-28 17:21:12 -060095static unsigned GetLocationsConsumedByFormat(VkFormat format) {
Chris Forbes47567b72017-06-09 12:09:45 -070096 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 McPhersonc06c33d2018-06-28 17:21:12 -0600109static unsigned GetFormatType(VkFormat fmt) {
Dave Houltona9df0ce2018-02-07 10:51:23 -0700110 if (FormatIsSInt(fmt)) return FORMAT_TYPE_SINT;
111 if (FormatIsUInt(fmt)) return FORMAT_TYPE_UINT;
sfricke-samsunged028b02021-09-06 23:14:51 -0700112 // Formats such as VK_FORMAT_D16_UNORM_S8_UINT are both
Dave Houltona9df0ce2018-02-07 10:51:23 -0700113 if (FormatIsDepthAndStencil(fmt)) return FORMAT_TYPE_FLOAT | FORMAT_TYPE_UINT;
114 if (fmt == VK_FORMAT_UNDEFINED) return 0;
Chris Forbes47567b72017-06-09 12:09:45 -0700115 // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
116 return FORMAT_TYPE_FLOAT;
117}
118
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600119static uint32_t GetShaderStageId(VkShaderStageFlagBits stage) {
Chris Forbes47567b72017-06-09 12:09:45 -0700120 uint32_t bit_pos = uint32_t(u_ffs(stage));
121 return bit_pos - 1;
122}
123
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -0700124bool CoreChecks::ValidateViConsistency(VkPipelineVertexInputStateCreateInfo const *vi) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700125 // Walk the binding descriptions, which describe the step rate and stride of each vertex buffer. Each binding should
126 // be specified only once.
Jeremy Gebbencbf22862021-03-03 12:01:22 -0700127 layer_data::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
Chris Forbes47567b72017-06-09 12:09:45 -0700128 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 Houlton78d09922018-05-17 15:48:45 -0600134 // TODO: "VUID-VkGraphicsPipelineCreateInfo-pStages-00742" perhaps?
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700135 skip |= LogError(device, kVUID_Core_Shader_InconsistentVi, "Duplicate vertex input binding descriptions for binding %d",
136 desc->binding);
Chris Forbes47567b72017-06-09 12:09:45 -0700137 } else {
138 binding = desc;
139 }
140 }
141
142 return skip;
143}
144
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -0700145bool CoreChecks::ValidateViAgainstVsInputs(VkPipelineVertexInputStateCreateInfo const *vi, SHADER_MODULE_STATE const *vs,
146 spirv_inst_iter entrypoint) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700147 bool skip = false;
148
sfricke-samsung962cad92021-04-13 00:46:29 -0700149 const auto inputs = vs->CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, false);
Chris Forbes47567b72017-06-09 12:09:45 -0700150
151 // Build index by location
Petr Kraus25810d02019-08-27 17:41:15 +0200152 std::map<uint32_t, const VkVertexInputAttributeDescription *> attribs;
Chris Forbes47567b72017-06-09 12:09:45 -0700153 if (vi) {
Petr Kraus25810d02019-08-27 17:41:15 +0200154 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 Forbes47567b72017-06-09 12:09:45 -0700157 attribs[vi->pVertexAttributeDescriptions[i].location + j] = &vi->pVertexAttributeDescriptions[i];
158 }
159 }
160 }
161
Petr Kraus25810d02019-08-27 17:41:15 +0200162 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 Forbes47567b72017-06-09 12:09:45 -0700169
Jamie Madillc1f7ca82020-03-16 17:08:26 -0400170 for (const auto &location_it : location_map) {
Petr Kraus25810d02019-08-27 17:41:15 +0200171 const auto location = location_it.first;
172 const auto attrib = location_it.second.attrib;
173 const auto input = location_it.second.input;
Mark Lobodzinski7caa39c2018-07-25 15:48:34 -0600174
Petr Kraus25810d02019-08-27 17:41:15 +0200175 if (attrib && !input) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600176 skip |= LogPerformanceWarning(vs->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700177 "Vertex attribute at location %" PRIu32 " not consumed by vertex shader", location);
Petr Kraus25810d02019-08-27 17:41:15 +0200178 } else if (!attrib && input) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600179 skip |= LogError(vs->vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700180 "Vertex shader consumes input at location %" PRIu32 " but not provided", location);
Petr Kraus25810d02019-08-27 17:41:15 +0200181 } else if (attrib && input) {
182 const auto attrib_type = GetFormatType(attrib->format);
sfricke-samsung962cad92021-04-13 00:46:29 -0700183 const auto input_type = vs->GetFundamentalType(input->type_id);
Chris Forbes47567b72017-06-09 12:09:45 -0700184
185 // Type checking
186 if (!(attrib_type & input_type)) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600187 skip |= LogError(vs->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700188 "Attribute type of `%s` at location %" PRIu32 " does not match vertex shader input type of `%s`",
sfricke-samsung962cad92021-04-13 00:46:29 -0700189 string_VkFormat(attrib->format), location, vs->DescribeType(input->type_id).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -0700190 }
Petr Kraus25810d02019-08-27 17:41:15 +0200191 } else { // !attrib && !input
192 assert(false); // at least one exists in the map
Chris Forbes47567b72017-06-09 12:09:45 -0700193 }
194 }
195
196 return skip;
197}
198
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -0700199bool CoreChecks::ValidateFsOutputsAgainstRenderPass(SHADER_MODULE_STATE const *fs, spirv_inst_iter entrypoint,
200 PIPELINE_STATE const *pipeline, uint32_t subpass_index) const {
Petr Kraus25810d02019-08-27 17:41:15 +0200201 bool skip = false;
Chris Forbes8bca1652017-07-20 11:10:09 -0700202
Petr Kraus25810d02019-08-27 17:41:15 +0200203 const auto rpci = pipeline->rp_state->createInfo.ptr();
204
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600205 struct Attachment {
Mike Schuchardt2df08912020-12-15 16:28:09 -0800206 const VkAttachmentReference2 *reference = nullptr;
207 const VkAttachmentDescription2 *attachment = nullptr;
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600208 const interface_var *output = nullptr;
209 };
210 std::map<uint32_t, Attachment> location_map;
211
Petr Kraus25810d02019-08-27 17:41:15 +0200212 const auto subpass = rpci->pSubpasses[subpass_index];
213 for (uint32_t i = 0; i < subpass.colorAttachmentCount; ++i) {
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600214 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];
Chris Forbes47567b72017-06-09 12:09:45 -0700219 }
220 }
221
Chris Forbes47567b72017-06-09 12:09:45 -0700222 // TODO: dual source blend index (spv::DecIndex, zero if not provided)
223
sfricke-samsung962cad92021-04-13 00:46:29 -0700224 const auto outputs = fs->CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false);
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600225 for (const auto &output_it : outputs) {
226 auto const location = output_it.first.first;
227 location_map[location].output = &output_it.second;
228 }
Chris Forbes47567b72017-06-09 12:09:45 -0700229
Jeremy Gebben11af9792021-08-20 10:20:09 -0600230 const bool alpha_to_coverage_enabled = pipeline->create_info.graphics.pMultisampleState != NULL &&
231 pipeline->create_info.graphics.pMultisampleState->alphaToCoverageEnable == VK_TRUE;
Chris Forbes47567b72017-06-09 12:09:45 -0700232
Jamie Madillc1f7ca82020-03-16 17:08:26 -0400233 for (const auto &location_it : location_map) {
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600234 const auto reference = location_it.second.reference;
235 if (reference != nullptr && reference->attachment == VK_ATTACHMENT_UNUSED) {
236 continue;
237 }
238
Petr Kraus25810d02019-08-27 17:41:15 +0200239 const auto location = location_it.first;
240 const auto attachment = location_it.second.attachment;
241 const auto output = location_it.second.output;
Petr Kraus25810d02019-08-27 17:41:15 +0200242 if (attachment && !output) {
243 if (pipeline->attachments[location].colorWriteMask != 0) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600244 skip |= LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700245 "Attachment %" PRIu32
246 " not written by fragment shader; undefined values will be written to attachment",
247 location);
Petr Kraus25810d02019-08-27 17:41:15 +0200248 }
249 } else if (!attachment && output) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700250 if (!(alpha_to_coverage_enabled && location == 0)) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600251 skip |= LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700252 "fragment shader writes to output location %" PRIu32 " with no matching attachment", location);
Ari Suonpaa412b23b2019-02-26 07:56:58 +0200253 }
Petr Kraus25810d02019-08-27 17:41:15 +0200254 } else if (attachment && output) {
255 const auto attachment_type = GetFormatType(attachment->format);
sfricke-samsung962cad92021-04-13 00:46:29 -0700256 const auto output_type = fs->GetFundamentalType(output->type_id);
Chris Forbes47567b72017-06-09 12:09:45 -0700257
258 // Type checking
Petr Kraus25810d02019-08-27 17:41:15 +0200259 if (!(output_type & attachment_type)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700260 skip |=
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600261 LogWarning(fs->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700262 "Attachment %" PRIu32
263 " of type `%s` does not match fragment shader output type of `%s`; resulting values are undefined",
sfricke-samsung962cad92021-04-13 00:46:29 -0700264 location, string_VkFormat(attachment->format), fs->DescribeType(output->type_id).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -0700265 }
Petr Kraus25810d02019-08-27 17:41:15 +0200266 } else { // !attachment && !output
267 assert(false); // at least one exists in the map
Chris Forbes47567b72017-06-09 12:09:45 -0700268 }
269 }
270
Petr Kraus25810d02019-08-27 17:41:15 +0200271 const auto output_zero = location_map.count(0) ? location_map[0].output : nullptr;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700272 bool location_zero_has_alpha = output_zero && fs->get_def(output_zero->type_id) != fs->end() &&
sfricke-samsung962cad92021-04-13 00:46:29 -0700273 fs->GetComponentsConsumedByType(output_zero->type_id, false) == 4;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700274 if (alpha_to_coverage_enabled && !location_zero_has_alpha) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600275 skip |= LogError(fs->vk_shader_module(), kVUID_Core_Shader_NoAlphaAtLocation0WithAlphaToCoverage,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700276 "fragment shader doesn't declare alpha output at location 0 even though alpha to coverage is enabled.");
Ari Suonpaa412b23b2019-02-26 07:56:58 +0200277 }
278
Chris Forbes47567b72017-06-09 12:09:45 -0700279 return skip;
280}
281
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600282PushConstantByteState CoreChecks::ValidatePushConstantSetUpdate(const std::vector<uint8_t> &push_constant_data_update,
283 const shader_struct_member &push_constant_used_in_shader,
284 uint32_t &out_issue_index) const {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600285 const auto *used_bytes = push_constant_used_in_shader.GetUsedbytes();
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600286 const auto used_bytes_size = used_bytes->size();
287 if (used_bytes_size == 0) return PC_Byte_Updated;
288
289 const auto push_constant_data_update_size = push_constant_data_update.size();
290 const auto *data = push_constant_data_update.data();
291 if ((*data == PC_Byte_Updated) && std::memcmp(data, data + 1, push_constant_data_update_size - 1) == 0) {
292 if (used_bytes_size <= push_constant_data_update_size) {
293 return PC_Byte_Updated;
294 }
295 const auto used_bytes_size1 = used_bytes_size - push_constant_data_update_size;
296
297 const auto *used_bytes_data1 = used_bytes->data() + push_constant_data_update_size;
298 if ((*used_bytes_data1 == 0) && std::memcmp(used_bytes_data1, used_bytes_data1 + 1, used_bytes_size1 - 1) == 0) {
299 return PC_Byte_Updated;
300 }
locke-lunargde3f0fa2020-09-10 11:55:31 -0600301 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600302
locke-lunargde3f0fa2020-09-10 11:55:31 -0600303 uint32_t i = 0;
304 for (const auto used : *used_bytes) {
305 if (used) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600306 if (i >= push_constant_data_update.size() || push_constant_data_update[i] == PC_Byte_Not_Set) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600307 out_issue_index = i;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600308 return PC_Byte_Not_Set;
309 } else if (push_constant_data_update[i] == PC_Byte_Not_Updated) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600310 out_issue_index = i;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600311 return PC_Byte_Not_Updated;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600312 }
313 }
314 ++i;
315 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600316 return PC_Byte_Updated;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600317}
318
319bool CoreChecks::ValidatePushConstantUsage(const PIPELINE_STATE &pipeline, SHADER_MODULE_STATE const *src,
sfricke-samsung7699b912021-04-12 23:01:51 -0700320 VkPipelineShaderStageCreateInfo const *pStage, const std::string &vuid) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700321 bool skip = false;
sfricke-samsung5c65b372021-03-25 05:39:57 -0700322 // Temp workaround to prevent false positive errors
323 // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2450
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -0600324 if (src->HasMultipleEntryPoints()) {
sfricke-samsung5c65b372021-03-25 05:39:57 -0700325 return skip;
326 }
327
Chris Forbes47567b72017-06-09 12:09:45 -0700328 // Validate directly off the offsets. this isn't quite correct for arrays and matrices, but is a good first step.
sfricke-samsung962cad92021-04-13 00:46:29 -0700329 const auto *entrypoint = src->FindEntrypointStruct(pStage->pName, pStage->stage);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600330 if (!entrypoint || !entrypoint->push_constant_used_in_shader.IsUsed()) {
331 return skip;
332 }
333 std::vector<VkPushConstantRange> const *push_constant_ranges = pipeline.pipeline_layout->push_constant_ranges.get();
Chris Forbes47567b72017-06-09 12:09:45 -0700334
locke-lunargde3f0fa2020-09-10 11:55:31 -0600335 bool found_stage = false;
336 for (auto const &range : *push_constant_ranges) {
337 if (range.stageFlags & pStage->stage) {
338 found_stage = true;
339 std::string location_desc;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600340 std::vector<uint8_t> push_constant_bytes_set;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600341 if (range.offset > 0) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600342 push_constant_bytes_set.resize(range.offset, PC_Byte_Not_Set);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600343 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600344 push_constant_bytes_set.resize(range.offset + range.size, PC_Byte_Updated);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600345 uint32_t issue_index = 0;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600346 const auto ret =
347 ValidatePushConstantSetUpdate(push_constant_bytes_set, entrypoint->push_constant_used_in_shader, issue_index);
Chris Forbes47567b72017-06-09 12:09:45 -0700348
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600349 if (ret == PC_Byte_Not_Set) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600350 const auto loc_descr = entrypoint->push_constant_used_in_shader.GetLocationDesc(issue_index);
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600351 LogObjectList objlist(src->vk_shader_module());
352 objlist.add(pipeline.pipeline_layout->layout());
sfricke-samsung7699b912021-04-12 23:01:51 -0700353 skip |= LogError(objlist, vuid, "Push constant buffer:%s in %s is out of range in %s.", loc_descr.c_str(),
locke-lunargde3f0fa2020-09-10 11:55:31 -0600354 string_VkShaderStageFlags(pStage->stage).c_str(),
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600355 report_data->FormatHandle(pipeline.pipeline_layout->layout()).c_str());
locke-lunargde3f0fa2020-09-10 11:55:31 -0600356 break;
Chris Forbes47567b72017-06-09 12:09:45 -0700357 }
358 }
359 }
360
locke-lunargde3f0fa2020-09-10 11:55:31 -0600361 if (!found_stage) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600362 LogObjectList objlist(src->vk_shader_module());
363 objlist.add(pipeline.pipeline_layout->layout());
sfricke-samsung7699b912021-04-12 23:01:51 -0700364 skip |= LogError(objlist, vuid, "Push constant is used in %s of %s. But %s doesn't set %s.",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -0600365 string_VkShaderStageFlags(pStage->stage).c_str(), report_data->FormatHandle(src->vk_shader_module()).c_str(),
366 report_data->FormatHandle(pipeline.pipeline_layout->layout()).c_str(),
sfricke-samsung7699b912021-04-12 23:01:51 -0700367 string_VkShaderStageFlags(pStage->stage).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -0700368 }
Chris Forbes47567b72017-06-09 12:09:45 -0700369 return skip;
370}
371
sfricke-samsungcfb44592021-07-25 00:36:28 -0700372bool CoreChecks::ValidateBuiltinLimits(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint) const {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700373 bool skip = false;
374
375 // Currently all builtin tested are only found in fragment shaders
sfricke-samsungcfb44592021-07-25 00:36:28 -0700376 if (entrypoint.word(1) != spv::ExecutionModelFragment) {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700377 return skip;
378 }
379
sfricke-samsungcfb44592021-07-25 00:36:28 -0700380 // Find all builtin from just the interface variables
381 for (uint32_t id : FindEntrypointInterfaces(entrypoint)) {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700382 auto insn = src->get_def(id);
sfricke-samsungcfb44592021-07-25 00:36:28 -0700383 assert(insn.opcode() == spv::OpVariable);
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700384 const decoration_set decorations = src->get_decorations(insn.word(2));
385
sfricke-samsungcfb44592021-07-25 00:36:28 -0700386 // Currently don't need to search in structs
387 if (((decorations.flags & decoration_set::builtin_bit) != 0) && (decorations.builtin == spv::BuiltInSampleMask)) {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700388 auto type_pointer = src->get_def(insn.word(1));
389 assert(type_pointer.opcode() == spv::OpTypePointer);
390
391 auto type = src->get_def(type_pointer.word(3));
392 if (type.opcode() == spv::OpTypeArray) {
sfricke-samsung962cad92021-04-13 00:46:29 -0700393 uint32_t length = static_cast<uint32_t>(src->GetConstantValueById(type.word(3)));
sfricke-samsungcfb44592021-07-25 00:36:28 -0700394 // Handles both the input and output sampleMask
395 if (length > phys_dev_props.limits.maxSampleMaskWords) {
396 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-maxSampleMaskWords-00711",
397 "vkCreateGraphicsPipelines(): The BuiltIns SampleMask array sizes is %u which exceeds "
398 "maxSampleMaskWords of %u in %s.",
399 length, phys_dev_props.limits.maxSampleMaskWords,
400 report_data->FormatHandle(src->vk_shader_module()).c_str());
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700401 }
sfricke-samsungcfb44592021-07-25 00:36:28 -0700402 break;
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700403 }
404 }
405 }
406
407 return skip;
408}
409
Chris Forbes47567b72017-06-09 12:09:45 -0700410// Validate that data for each specialization entry is fully contained within the buffer.
ziga-lunargae2a5c42021-07-23 16:18:09 +0200411bool CoreChecks::ValidateSpecializations(VkPipelineShaderStageCreateInfo const *info) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700412 bool skip = false;
413
414 VkSpecializationInfo const *spec = info->pSpecializationInfo;
415
416 if (spec) {
417 for (auto i = 0u; i < spec->mapEntryCount; i++) {
Jeremy Hayes6c555c32019-09-09 17:14:09 -0600418 if (spec->pMapEntries[i].offset >= spec->dataSize) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700419 skip |= LogError(device, "VUID-VkSpecializationInfo-offset-00773",
420 "Specialization entry %u (for constant id %u) references memory outside provided specialization "
Petr Krausb0d5e592021-05-21 23:37:11 +0200421 "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700422 i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset,
423 spec->pMapEntries[i].offset + spec->dataSize - 1, spec->dataSize);
Jeremy Hayes6c555c32019-09-09 17:14:09 -0600424
425 continue;
426 }
Chris Forbes47567b72017-06-09 12:09:45 -0700427 if (spec->pMapEntries[i].offset + spec->pMapEntries[i].size > spec->dataSize) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700428 skip |= LogError(device, "VUID-VkSpecializationInfo-pMapEntries-00774",
429 "Specialization entry %u (for constant id %u) references memory outside provided specialization "
Petr Krausb0d5e592021-05-21 23:37:11 +0200430 "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700431 i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset,
432 spec->pMapEntries[i].offset + spec->pMapEntries[i].size - 1, spec->dataSize);
Chris Forbes47567b72017-06-09 12:09:45 -0700433 }
ziga-lunargae2a5c42021-07-23 16:18:09 +0200434 for (uint32_t j = i + 1; j < spec->mapEntryCount; ++j) {
435 if (spec->pMapEntries[i].constantID == spec->pMapEntries[j].constantID) {
436 skip |= LogError(device, "VUID-VkSpecializationInfo-constantID-04911",
437 "Specialization entry %" PRIu32 " and %" PRIu32 " have the same constantID (%" PRIu32 ").", i,
438 j, spec->pMapEntries[i].constantID);
439 }
440 }
Chris Forbes47567b72017-06-09 12:09:45 -0700441 }
442 }
443
444 return skip;
445}
446
Jeff Bolz38b3ce72018-09-19 12:53:38 -0500447// TODO (jbolz): Can this return a const reference?
sourav parmarcd5fb182020-07-17 12:58:44 -0700448static std::set<uint32_t> TypeToDescriptorTypeSet(SHADER_MODULE_STATE const *module, uint32_t type_id, unsigned &descriptor_count,
449 bool is_khr) {
Chris Forbes47567b72017-06-09 12:09:45 -0700450 auto type = module->get_def(type_id);
Chris Forbes9f89d752018-03-07 12:57:48 -0800451 bool is_storage_buffer = false;
Chris Forbes47567b72017-06-09 12:09:45 -0700452 descriptor_count = 1;
Jeff Bolze54ae892018-09-08 12:16:29 -0500453 std::set<uint32_t> ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700454
455 // Strip off any array or ptrs. Where we remove array levels, adjust the descriptor count for each dimension.
Jeff Bolzfdf96072018-04-10 14:32:18 -0500456 while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray) {
457 if (type.opcode() == spv::OpTypeRuntimeArray) {
458 descriptor_count = 0;
459 type = module->get_def(type.word(2));
460 } else if (type.opcode() == spv::OpTypeArray) {
sfricke-samsung962cad92021-04-13 00:46:29 -0700461 descriptor_count *= module->GetConstantValueById(type.word(3));
Chris Forbes47567b72017-06-09 12:09:45 -0700462 type = module->get_def(type.word(2));
463 } else {
Chris Forbes9f89d752018-03-07 12:57:48 -0800464 if (type.word(2) == spv::StorageClassStorageBuffer) {
465 is_storage_buffer = true;
466 }
Chris Forbes47567b72017-06-09 12:09:45 -0700467 type = module->get_def(type.word(3));
468 }
469 }
470
471 switch (type.opcode()) {
472 case spv::OpTypeStruct: {
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -0600473 for (const auto insn : module->GetDecorationInstructions()) {
sfricke-samsung94d71a52021-02-26 05:25:43 -0800474 if (insn.word(1) == type.word(1)) {
Chris Forbes47567b72017-06-09 12:09:45 -0700475 if (insn.word(2) == spv::DecorationBlock) {
Chris Forbes9f89d752018-03-07 12:57:48 -0800476 if (is_storage_buffer) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500477 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
478 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC);
479 return ret;
Chris Forbes9f89d752018-03-07 12:57:48 -0800480 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500481 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
482 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC);
483 ret.insert(VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT);
484 return ret;
Chris Forbes9f89d752018-03-07 12:57:48 -0800485 }
Chris Forbes47567b72017-06-09 12:09:45 -0700486 } else if (insn.word(2) == spv::DecorationBufferBlock) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500487 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
488 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC);
489 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700490 }
491 }
492 }
493
494 // Invalid
Jeff Bolze54ae892018-09-08 12:16:29 -0500495 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700496 }
497
498 case spv::OpTypeSampler:
Jeff Bolze54ae892018-09-08 12:16:29 -0500499 ret.insert(VK_DESCRIPTOR_TYPE_SAMPLER);
500 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
501 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700502
Chris Forbes73c00bf2018-06-22 16:28:06 -0700503 case spv::OpTypeSampledImage: {
504 // Slight relaxation for some GLSL historical madness: samplerBuffer doesn't really have a sampler, and a texel
505 // buffer descriptor doesn't really provide one. Allow this slight mismatch.
506 auto image_type = module->get_def(type.word(2));
507 auto dim = image_type.word(3);
508 auto sampled = image_type.word(7);
509 if (dim == spv::DimBuffer && sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500510 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER);
511 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700512 }
Chris Forbes73c00bf2018-06-22 16:28:06 -0700513 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500514 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
515 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700516
517 case spv::OpTypeImage: {
518 // Many descriptor types backing image types-- depends on dimension and whether the image will be used with a sampler.
519 // SPIRV for Vulkan requires that sampled be 1 or 2 -- leaving the decision to runtime is unacceptable.
520 auto dim = type.word(3);
521 auto sampled = type.word(7);
522
523 if (dim == spv::DimSubpassData) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500524 ret.insert(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT);
525 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700526 } else if (dim == spv::DimBuffer) {
527 if (sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500528 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER);
529 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700530 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500531 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
532 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700533 }
534 } else if (sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500535 ret.insert(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
536 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
537 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700538 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500539 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE);
540 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700541 }
542 }
Shannon McPherson0fa28232018-11-01 11:59:02 -0600543 case spv::OpTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -0700544 is_khr ? ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
545 : ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV);
Jeff Bolz105d6492018-09-29 15:46:44 -0500546 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700547
548 // We shouldn't really see any other junk types -- but if we do, they're a mismatch.
549 default:
Jeff Bolze54ae892018-09-08 12:16:29 -0500550 return ret; // Matches nothing
Chris Forbes47567b72017-06-09 12:09:45 -0700551 }
552}
553
Jeff Bolze54ae892018-09-08 12:16:29 -0500554static std::string string_descriptorTypes(const std::set<uint32_t> &descriptor_types) {
Chris Forbes73c00bf2018-06-22 16:28:06 -0700555 std::stringstream ss;
Jeff Bolze54ae892018-09-08 12:16:29 -0500556 for (auto it = descriptor_types.begin(); it != descriptor_types.end(); ++it) {
557 if (ss.tellp()) ss << ", ";
558 ss << string_VkDescriptorType(VkDescriptorType(*it));
Chris Forbes73c00bf2018-06-22 16:28:06 -0700559 }
560 return ss.str();
561}
562
sfricke-samsung0065ce02020-12-03 22:46:37 -0800563bool CoreChecks::RequirePropertyFlag(VkBool32 check, char const *flag, char const *structure, const char *vuid) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500564 if (!check) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800565 if (LogError(device, vuid, "Shader requires flag %s set in %s but it is not set on the device", flag, structure)) {
Jeff Bolzee743412019-06-20 22:24:32 -0500566 return true;
567 }
568 }
569
570 return false;
571}
572
sfricke-samsung0065ce02020-12-03 22:46:37 -0800573bool CoreChecks::RequireFeature(VkBool32 feature, char const *feature_name, const char *vuid) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700574 if (!feature) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800575 if (LogError(device, vuid, "Shader requires %s but is not enabled on the device", feature_name)) {
Chris Forbes47567b72017-06-09 12:09:45 -0700576 return true;
577 }
578 }
579
580 return false;
581}
582
locke-lunarg63e4daf2020-08-17 17:53:25 -0600583bool CoreChecks::ValidateShaderStageWritableOrAtomicDescriptor(VkShaderStageFlagBits stage, bool has_writable_descriptor,
584 bool has_atomic_descriptor) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500585 bool skip = false;
586
locke-lunarg63e4daf2020-08-17 17:53:25 -0600587 if (has_writable_descriptor || has_atomic_descriptor) {
Chris Forbes349b3132018-03-07 11:38:08 -0800588 switch (stage) {
589 case VK_SHADER_STAGE_COMPUTE_BIT:
Jeff Bolz148d94e2018-12-13 21:25:56 -0600590 case VK_SHADER_STAGE_RAYGEN_BIT_NV:
591 case VK_SHADER_STAGE_ANY_HIT_BIT_NV:
592 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV:
593 case VK_SHADER_STAGE_MISS_BIT_NV:
594 case VK_SHADER_STAGE_INTERSECTION_BIT_NV:
595 case VK_SHADER_STAGE_CALLABLE_BIT_NV:
596 case VK_SHADER_STAGE_TASK_BIT_NV:
597 case VK_SHADER_STAGE_MESH_BIT_NV:
Chris Forbes349b3132018-03-07 11:38:08 -0800598 /* No feature requirements for writes and atomics from compute
Jeff Bolz148d94e2018-12-13 21:25:56 -0600599 * raytracing, or mesh stages */
Chris Forbes349b3132018-03-07 11:38:08 -0800600 break;
601 case VK_SHADER_STAGE_FRAGMENT_BIT:
sfricke-samsung0065ce02020-12-03 22:46:37 -0800602 skip |= RequireFeature(enabled_features.core.fragmentStoresAndAtomics, "fragmentStoresAndAtomics",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700603 "VUID-RuntimeSpirv-NonWritable-06340");
Chris Forbes349b3132018-03-07 11:38:08 -0800604 break;
605 default:
sfricke-samsung0065ce02020-12-03 22:46:37 -0800606 skip |= RequireFeature(enabled_features.core.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700607 "VUID-RuntimeSpirv-NonWritable-06341");
Chris Forbes349b3132018-03-07 11:38:08 -0800608 break;
609 }
610 }
611
Chris Forbes47567b72017-06-09 12:09:45 -0700612 return skip;
613}
614
sfricke-samsung94167ca2021-02-26 04:14:59 -0800615bool CoreChecks::ValidateShaderStageGroupNonUniform(SHADER_MODULE_STATE const *module, VkShaderStageFlagBits stage,
616 spirv_inst_iter &insn) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500617 bool skip = false;
618
sfricke-samsung94167ca2021-02-26 04:14:59 -0800619 // Check anything using a group operation (which currently is only OpGroupNonUnifrom* operations)
620 if (GroupOperation(insn.opcode()) == true) {
621 // Check the quad operations.
622 if ((insn.opcode() == spv::OpGroupNonUniformQuadBroadcast) || (insn.opcode() == spv::OpGroupNonUniformQuadSwap)) {
623 if ((stage != VK_SHADER_STAGE_FRAGMENT_BIT) && (stage != VK_SHADER_STAGE_COMPUTE_BIT)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700624 skip |=
625 RequireFeature(phys_dev_props_core11.subgroupQuadOperationsInAllStages,
626 "VkPhysicalDeviceSubgroupProperties::quadOperationsInAllStages", "VUID-RuntimeSpirv-None-06342");
sfricke-samsung0065ce02020-12-03 22:46:37 -0800627 }
sfricke-samsung94167ca2021-02-26 04:14:59 -0800628 }
Jeff Bolz526f2d52019-09-18 13:18:08 -0500629
sfricke-samsung94167ca2021-02-26 04:14:59 -0800630 uint32_t scope_type = spv::ScopeMax;
631 if (insn.opcode() == spv::OpGroupNonUniformPartitionNV) {
632 // OpGroupNonUniformPartitionNV always assumed subgroup as missing operand
633 scope_type = spv::ScopeSubgroup;
634 } else {
635 // "All <id> used for Scope <id> must be of an OpConstant"
636 auto scope_id = module->get_def(insn.word(3));
637 scope_type = scope_id.word(3);
638 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800639
sfricke-samsung94167ca2021-02-26 04:14:59 -0800640 if (scope_type == spv::ScopeSubgroup) {
641 // "Group operations with subgroup scope" must have stage support
642 const VkSubgroupFeatureFlags supported_stages = phys_dev_props_core11.subgroupSupportedStages;
643 skip |= RequirePropertyFlag(supported_stages & stage, string_VkShaderStageFlagBits(stage),
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700644 "VkPhysicalDeviceSubgroupProperties::supportedStages", "VUID-RuntimeSpirv-None-06343");
sfricke-samsung94167ca2021-02-26 04:14:59 -0800645 }
646
647 if (!enabled_features.core12.shaderSubgroupExtendedTypes) {
648 auto type = module->get_def(insn.word(1));
649
650 if (type.opcode() == spv::OpTypeVector) {
651 // Get the element type
652 type = module->get_def(type.word(2));
sfricke-samsung0065ce02020-12-03 22:46:37 -0800653 }
654
sfricke-samsung94167ca2021-02-26 04:14:59 -0800655 if (type.opcode() != spv::OpTypeBool) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800656 // Both OpTypeInt and OpTypeFloat the width is in the 2nd word.
657 const uint32_t width = type.word(2);
Jeff Bolz526f2d52019-09-18 13:18:08 -0500658
sfricke-samsung0065ce02020-12-03 22:46:37 -0800659 if ((type.opcode() == spv::OpTypeFloat && width == 16) ||
660 (type.opcode() == spv::OpTypeInt && (width == 8 || width == 16 || width == 64))) {
661 skip |= RequireFeature(enabled_features.core12.shaderSubgroupExtendedTypes,
662 "VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures::shaderSubgroupExtendedTypes",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700663 "VUID-RuntimeSpirv-None-06275");
Jeff Bolz526f2d52019-09-18 13:18:08 -0500664 }
665 }
666 }
Jeff Bolzee743412019-06-20 22:24:32 -0500667 }
668
669 return skip;
670}
671
ziga-lunarg2818f492021-08-12 14:30:51 +0200672bool CoreChecks::ValidateWorkgroupSize(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
673 const std::unordered_map<uint32_t, std::vector<uint32_t>>& id_value_map) const {
674 bool skip = false;
675
676 std::array<uint32_t, 3> work_group_size = src->GetWorkgroupSize(pStage, id_value_map);
677
678 for (uint32_t i = 0; i < 3; ++i) {
679 if (work_group_size[i] > phys_dev_props.limits.maxComputeWorkGroupSize[i]) {
680 const char member = 'x' + static_cast<int8_t>(i);
681 skip |= LogError(device, kVUID_Core_Shader_MaxComputeWorkGroupSize,
682 "Specialization constant is being used to specialize WorkGroupSize.%c, but value (%" PRIu32
683 ") is greater than VkPhysicalDeviceLimits::maxComputeWorkGroupSize[%" PRIu32 "] = %" PRIu32 ".",
684 member, work_group_size[i], i, phys_dev_props.limits.maxComputeWorkGroupSize[i]);
685 }
686 }
687 return skip;
688}
689
Mark Lobodzinski3c59d972019-04-25 11:28:14 -0600690bool CoreChecks::ValidateShaderStageInputOutputLimits(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
John Zulaufac4c6e12019-07-01 16:05:58 -0600691 const PIPELINE_STATE *pipeline, spirv_inst_iter entrypoint) const {
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200692 if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT || pStage->stage == VK_SHADER_STAGE_ALL_GRAPHICS ||
693 pStage->stage == VK_SHADER_STAGE_ALL) {
694 return false;
695 }
696
697 bool skip = false;
Mark Lobodzinski518eadc2019-03-09 12:07:30 -0700698 auto const &limits = phys_dev_props.limits;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200699
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700700 std::set<uint32_t> patch_i_ds;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200701 struct Variable {
702 uint32_t baseTypePtrID;
703 uint32_t ID;
704 uint32_t storageClass;
705 };
706 std::vector<Variable> variables;
707
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700708 uint32_t num_vertices = 0;
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700709 bool is_iso_lines = false;
710 bool is_point_mode = false;
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500711
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700712 auto entrypoint_variables = FindEntrypointInterfaces(entrypoint);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600713
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200714 for (auto insn : *src) {
715 switch (insn.opcode()) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500716 // Find all Patch decorations
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200717 case spv::OpDecorate:
718 switch (insn.word(2)) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500719 case spv::DecorationPatch: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700720 patch_i_ds.insert(insn.word(1));
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200721 break;
722 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200723 default:
724 break;
725 }
726 break;
727 // Find all input and output variables
728 case spv::OpVariable: {
729 Variable var = {};
730 var.storageClass = insn.word(3);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600731 if ((var.storageClass == spv::StorageClassInput || var.storageClass == spv::StorageClassOutput) &&
732 // Only include variables in the entrypoint's interface
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700733 find(entrypoint_variables.begin(), entrypoint_variables.end(), insn.word(2)) != entrypoint_variables.end()) {
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200734 var.baseTypePtrID = insn.word(1);
735 var.ID = insn.word(2);
736 variables.push_back(var);
737 }
738 break;
739 }
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500740 case spv::OpExecutionMode:
741 if (insn.word(1) == entrypoint.word(2)) {
742 switch (insn.word(2)) {
743 default:
744 break;
745 case spv::ExecutionModeOutputVertices:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700746 num_vertices = insn.word(3);
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500747 break;
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700748 case spv::ExecutionModeIsolines:
749 is_iso_lines = true;
750 break;
751 case spv::ExecutionModePointMode:
752 is_point_mode = true;
753 break;
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500754 }
755 }
756 break;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200757 default:
758 break;
759 }
760 }
761
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500762 bool strip_output_array_level =
763 (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStage->stage == VK_SHADER_STAGE_MESH_BIT_NV);
764 bool strip_input_array_level =
765 (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT ||
766 pStage->stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || pStage->stage == VK_SHADER_STAGE_GEOMETRY_BIT);
767
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700768 uint32_t num_comp_in = 0, num_comp_out = 0;
769 int max_comp_in = 0, max_comp_out = 0;
Jeff Bolzf234bf82019-11-04 14:07:15 -0600770
sfricke-samsung962cad92021-04-13 00:46:29 -0700771 auto inputs = src->CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, strip_input_array_level);
772 auto outputs = src->CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, strip_output_array_level);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600773
774 // Find max component location used for input variables.
775 for (auto &var : inputs) {
776 int location = var.first.first;
777 int component = var.first.second;
778 interface_var &iv = var.second;
779
780 // Only need to look at the first location, since we use the type's whole size
781 if (iv.offset != 0) {
782 continue;
783 }
784
785 if (iv.is_patch) {
786 continue;
787 }
788
sfricke-samsung962cad92021-04-13 00:46:29 -0700789 int num_components = src->GetComponentsConsumedByType(iv.type_id, strip_input_array_level);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700790 max_comp_in = std::max(max_comp_in, location * 4 + component + num_components);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600791 }
792
793 // Find max component location used for output variables.
794 for (auto &var : outputs) {
795 int location = var.first.first;
796 int component = var.first.second;
797 interface_var &iv = var.second;
798
799 // Only need to look at the first location, since we use the type's whole size
800 if (iv.offset != 0) {
801 continue;
802 }
803
804 if (iv.is_patch) {
805 continue;
806 }
807
sfricke-samsung962cad92021-04-13 00:46:29 -0700808 int num_components = src->GetComponentsConsumedByType(iv.type_id, strip_output_array_level);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700809 max_comp_out = std::max(max_comp_out, location * 4 + component + num_components);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600810 }
811
812 // XXX TODO: Would be nice to rewrite this to use CollectInterfaceByLocation (or something similar),
813 // but that doesn't include builtins.
sfricke-samsung406766a2021-07-02 12:04:09 -0700814 // When rewritten, using the CreatePipelineExceedVertexMaxComponentsWithBuiltins test it would be nice to also let the user know
815 // how many components were from builtins as it might not be obvious
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200816 for (auto &var : variables) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500817 // Check if the variable is a patch. Patches can also be members of blocks,
818 // but if they are then the top-level arrayness has already been stripped
819 // by the time GetComponentsConsumedByType gets to it.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700820 bool is_patch = patch_i_ds.find(var.ID) != patch_i_ds.end();
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200821
822 if (var.storageClass == spv::StorageClassInput) {
sfricke-samsung962cad92021-04-13 00:46:29 -0700823 num_comp_in += src->GetComponentsConsumedByType(var.baseTypePtrID, strip_input_array_level && !is_patch);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200824 } else { // var.storageClass == spv::StorageClassOutput
sfricke-samsung962cad92021-04-13 00:46:29 -0700825 num_comp_out += src->GetComponentsConsumedByType(var.baseTypePtrID, strip_output_array_level && !is_patch);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200826 }
827 }
828
829 switch (pStage->stage) {
830 case VK_SHADER_STAGE_VERTEX_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700831 if (num_comp_out > limits.maxVertexOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700832 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700833 "Invalid Pipeline CreateInfo State: Vertex shader exceeds "
834 "VkPhysicalDeviceLimits::maxVertexOutputComponents of %u "
835 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700836 limits.maxVertexOutputComponents, num_comp_out - limits.maxVertexOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200837 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700838 if (max_comp_out > static_cast<int>(limits.maxVertexOutputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700839 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700840 "Invalid Pipeline CreateInfo State: Vertex shader output variable uses location that "
841 "exceeds component limit VkPhysicalDeviceLimits::maxVertexOutputComponents (%u)",
842 limits.maxVertexOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600843 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200844 break;
845
846 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700847 if (num_comp_in > limits.maxTessellationControlPerVertexInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700848 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700849 "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds "
850 "VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents of %u "
851 "components by %u components",
852 limits.maxTessellationControlPerVertexInputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700853 num_comp_in - limits.maxTessellationControlPerVertexInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200854 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700855 if (max_comp_in > static_cast<int>(limits.maxTessellationControlPerVertexInputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600856 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700857 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700858 "Invalid Pipeline CreateInfo State: Tessellation control shader input variable uses location that "
859 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents (%u)",
860 limits.maxTessellationControlPerVertexInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600861 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700862 if (num_comp_out > limits.maxTessellationControlPerVertexOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700863 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700864 "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds "
865 "VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents of %u "
866 "components by %u components",
867 limits.maxTessellationControlPerVertexOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700868 num_comp_out - limits.maxTessellationControlPerVertexOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200869 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700870 if (max_comp_out > static_cast<int>(limits.maxTessellationControlPerVertexOutputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600871 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700872 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700873 "Invalid Pipeline CreateInfo State: Tessellation control shader output variable uses location that "
874 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents (%u)",
875 limits.maxTessellationControlPerVertexOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600876 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200877 break;
878
879 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700880 if (num_comp_in > limits.maxTessellationEvaluationInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700881 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700882 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds "
883 "VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents of %u "
884 "components by %u components",
885 limits.maxTessellationEvaluationInputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700886 num_comp_in - limits.maxTessellationEvaluationInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200887 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700888 if (max_comp_in > static_cast<int>(limits.maxTessellationEvaluationInputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600889 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700890 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700891 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader input variable uses location that "
892 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents (%u)",
893 limits.maxTessellationEvaluationInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600894 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700895 if (num_comp_out > limits.maxTessellationEvaluationOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700896 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700897 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds "
898 "VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents of %u "
899 "components by %u components",
900 limits.maxTessellationEvaluationOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700901 num_comp_out - limits.maxTessellationEvaluationOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200902 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700903 if (max_comp_out > static_cast<int>(limits.maxTessellationEvaluationOutputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600904 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700905 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700906 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader output variable uses location that "
907 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents (%u)",
908 limits.maxTessellationEvaluationOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600909 }
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700910 // Portability validation
911 if (IsExtEnabled(device_extensions.vk_khr_portability_subset)) {
912 if (is_iso_lines && (VK_FALSE == enabled_features.portability_subset_features.tessellationIsolines)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700913 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-tessellationShader-06326",
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700914 "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader"
915 " is using abstract patch type IsoLines, but this is not supported on this platform");
916 }
917 if (is_point_mode && (VK_FALSE == enabled_features.portability_subset_features.tessellationPointMode)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700918 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-tessellationShader-06327",
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700919 "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader"
920 " is using abstract patch type PointMode, but this is not supported on this platform");
921 }
922 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200923 break;
924
925 case VK_SHADER_STAGE_GEOMETRY_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700926 if (num_comp_in > limits.maxGeometryInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700927 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700928 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
929 "VkPhysicalDeviceLimits::maxGeometryInputComponents of %u "
930 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700931 limits.maxGeometryInputComponents, num_comp_in - limits.maxGeometryInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200932 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700933 if (max_comp_in > static_cast<int>(limits.maxGeometryInputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700934 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700935 "Invalid Pipeline CreateInfo State: Geometry shader input variable uses location that "
936 "exceeds component limit VkPhysicalDeviceLimits::maxGeometryInputComponents (%u)",
937 limits.maxGeometryInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600938 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700939 if (num_comp_out > limits.maxGeometryOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700940 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700941 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
942 "VkPhysicalDeviceLimits::maxGeometryOutputComponents of %u "
943 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700944 limits.maxGeometryOutputComponents, num_comp_out - limits.maxGeometryOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200945 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700946 if (max_comp_out > static_cast<int>(limits.maxGeometryOutputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700947 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700948 "Invalid Pipeline CreateInfo State: Geometry shader output variable uses location that "
949 "exceeds component limit VkPhysicalDeviceLimits::maxGeometryOutputComponents (%u)",
950 limits.maxGeometryOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600951 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700952 if (num_comp_out * num_vertices > limits.maxGeometryTotalOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700953 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700954 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
955 "VkPhysicalDeviceLimits::maxGeometryTotalOutputComponents of %u "
956 "components by %u components",
957 limits.maxGeometryTotalOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700958 num_comp_out * num_vertices - limits.maxGeometryTotalOutputComponents);
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500959 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200960 break;
961
962 case VK_SHADER_STAGE_FRAGMENT_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700963 if (num_comp_in > limits.maxFragmentInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700964 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700965 "Invalid Pipeline CreateInfo State: Fragment shader exceeds "
966 "VkPhysicalDeviceLimits::maxFragmentInputComponents of %u "
967 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700968 limits.maxFragmentInputComponents, num_comp_in - limits.maxFragmentInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200969 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700970 if (max_comp_in > static_cast<int>(limits.maxFragmentInputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700971 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700972 "Invalid Pipeline CreateInfo State: Fragment shader input variable uses location that "
973 "exceeds component limit VkPhysicalDeviceLimits::maxFragmentInputComponents (%u)",
974 limits.maxFragmentInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600975 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200976 break;
977
Jeff Bolz148d94e2018-12-13 21:25:56 -0600978 case VK_SHADER_STAGE_RAYGEN_BIT_NV:
979 case VK_SHADER_STAGE_ANY_HIT_BIT_NV:
980 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV:
981 case VK_SHADER_STAGE_MISS_BIT_NV:
982 case VK_SHADER_STAGE_INTERSECTION_BIT_NV:
983 case VK_SHADER_STAGE_CALLABLE_BIT_NV:
984 case VK_SHADER_STAGE_TASK_BIT_NV:
985 case VK_SHADER_STAGE_MESH_BIT_NV:
986 break;
987
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200988 default:
989 assert(false); // This should never happen
990 }
991 return skip;
992}
993
Lionel Landwerlin892d6c32021-05-05 12:56:19 +0300994bool CoreChecks::ValidateShaderStorageImageFormats(SHADER_MODULE_STATE const *src) const {
995 bool skip = false;
996
Lionel Landwerlin892d6c32021-05-05 12:56:19 +0300997 // Got through all ImageRead/Write instructions
998 for (auto insn : *src) {
999 switch (insn.opcode()) {
1000 case spv::OpImageSparseRead:
1001 case spv::OpImageRead: {
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +03001002 spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(3));
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001003 if (type_def != src->end()) {
Tim Van Pattenffe91322021-07-26 10:20:50 -06001004 const auto dim = type_def.word(3);
1005 // If the Image Dim operand is not SubpassData, the Image Format must not be Unknown, unless the
1006 // StorageImageReadWithoutFormat Capability was declared.
1007 if (dim != spv::DimSubpassData && type_def.word(8) == spv::ImageFormatUnknown) {
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001008 skip |= RequireFeature(enabled_features.core.shaderStorageImageReadWithoutFormat,
1009 "shaderStorageImageReadWithoutFormat",
1010 kVUID_Features_shaderStorageImageReadWithoutFormat);
1011 }
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001012 }
1013 break;
1014 }
1015 case spv::OpImageWrite: {
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +03001016 spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(1));
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001017 if (type_def != src->end()) {
1018 if (type_def.word(8) == spv::ImageFormatUnknown) {
1019 skip |= RequireFeature(enabled_features.core.shaderStorageImageWriteWithoutFormat,
1020 "shaderStorageImageWriteWithoutFormat",
1021 kVUID_Features_shaderStorageImageWriteWithoutFormat);
1022 }
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001023 }
1024 break;
1025 }
1026
1027 }
1028 }
1029
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001030 // Go through all variables for images and check decorations
1031 for (auto insn : *src) {
1032 if (insn.opcode() != spv::OpVariable)
1033 continue;
1034
1035 uint32_t var = insn.word(2);
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +03001036 spirv_inst_iter type_def = src->GetImageFormatInst(insn.word(1));
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001037 if (type_def == src->end())
1038 continue;
Tim Van Pattenffe91322021-07-26 10:20:50 -06001039 // Only check if the Image Dim operand is not SubpassData
1040 const auto dim = type_def.word(3);
1041 if (dim == spv::DimSubpassData) continue;
Corentin Wallez91f8b6d2021-07-23 10:11:31 +02001042 // Only check storage images
1043 if (type_def.word(7) != 2) continue;
Tim Van Pattenffe91322021-07-26 10:20:50 -06001044 if (type_def.word(8) != spv::ImageFormatUnknown) continue;
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001045
1046 decoration_set img_decorations = src->get_decorations(var);
1047
1048 if (!enabled_features.core.shaderStorageImageReadWithoutFormat &&
1049 !(img_decorations.flags & decoration_set::nonreadable_bit)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001050 skip |= LogError(device, "VUID-RuntimeSpirv-OpTypeImage-06270",
1051 "shaderStorageImageReadWithoutFormat not supported but variable %" PRIu32
1052 " "
1053 " without format not marked a NonReadable",
1054 var);
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001055 }
1056
1057 if (!enabled_features.core.shaderStorageImageWriteWithoutFormat &&
1058 !(img_decorations.flags & decoration_set::nonwritable_bit)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001059 skip |= LogError(device, "VUID-RuntimeSpirv-OpTypeImage-06269",
1060 "shaderStorageImageWriteWithoutFormat not supported but variable %" PRIu32
1061 " "
1062 "without format not marked a NonWritable",
1063 var);
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001064 }
1065 }
1066
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001067 return skip;
1068}
1069
sfricke-samsungdc96f302020-03-18 20:42:10 -07001070bool CoreChecks::ValidateShaderStageMaxResources(VkShaderStageFlagBits stage, const PIPELINE_STATE *pipeline) const {
1071 bool skip = false;
1072 uint32_t total_resources = 0;
1073
1074 // Only currently testing for graphics and compute pipelines
1075 // TODO: Add check and support for Ray Tracing pipeline VUID 03428
1076 if ((stage & (VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_COMPUTE_BIT)) == 0) {
1077 return false;
1078 }
1079
1080 if (stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
1081 // "For the fragment shader stage the framebuffer color attachments also count against this limit"
Jeremy Gebben11af9792021-08-20 10:20:09 -06001082 total_resources += pipeline->rp_state->createInfo.pSubpasses[pipeline->create_info.graphics.subpass].colorAttachmentCount;
sfricke-samsungdc96f302020-03-18 20:42:10 -07001083 }
1084
1085 // TODO: This reuses a lot of GetDescriptorCountMaxPerStage but currently would need to make it agnostic in a way to handle
1086 // input from CreatePipeline and CreatePipelineLayout level
1087 for (auto set_layout : pipeline->pipeline_layout->set_layouts) {
1088 if ((set_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) != 0) {
1089 continue;
1090 }
1091
1092 for (uint32_t binding_idx = 0; binding_idx < set_layout->GetBindingCount(); binding_idx++) {
1093 const VkDescriptorSetLayoutBinding *binding = set_layout->GetDescriptorSetLayoutBindingPtrFromIndex(binding_idx);
1094 // Bindings with a descriptorCount of 0 are "reserved" and should be skipped
1095 if (((stage & binding->stageFlags) != 0) && (binding->descriptorCount > 0)) {
1096 // Check only descriptor types listed in maxPerStageResources description in spec
1097 switch (binding->descriptorType) {
1098 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1099 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1100 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1101 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1102 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1103 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1104 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1105 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1106 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1107 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1108 total_resources += binding->descriptorCount;
1109 break;
1110 default:
1111 break;
1112 }
1113 }
1114 }
1115 }
1116
1117 if (total_resources > phys_dev_props.limits.maxPerStageResources) {
1118 const char *vuid = (stage == VK_SHADER_STAGE_COMPUTE_BIT) ? "VUID-VkComputePipelineCreateInfo-layout-01687"
1119 : "VUID-VkGraphicsPipelineCreateInfo-layout-01688";
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001120 skip |= LogError(pipeline->pipeline(), vuid,
sfricke-samsungdc96f302020-03-18 20:42:10 -07001121 "Invalid Pipeline CreateInfo State: Shader Stage %s exceeds component limit "
1122 "VkPhysicalDeviceLimits::maxPerStageResources (%u)",
1123 string_VkShaderStageFlagBits(stage), phys_dev_props.limits.maxPerStageResources);
1124 }
1125
1126 return skip;
1127}
1128
Jeff Bolze4356752019-03-07 11:23:46 -06001129// copy the specialization constant value into buf, if it is present
1130void GetSpecConstantValue(VkPipelineShaderStageCreateInfo const *pStage, uint32_t spec_id, void *buf) {
1131 VkSpecializationInfo const *spec = pStage->pSpecializationInfo;
1132
1133 if (spec && spec_id < spec->mapEntryCount) {
1134 memcpy(buf, (uint8_t *)spec->pData + spec->pMapEntries[spec_id].offset, spec->pMapEntries[spec_id].size);
1135 }
1136}
1137
1138// Fill in value with the constant or specialization constant value, if available.
1139// Returns true if the value has been accurately filled out.
Mark Lobodzinski3c59d972019-04-25 11:28:14 -06001140static bool GetIntConstantValue(spirv_inst_iter insn, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001141 const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id, uint32_t *value) {
Jeff Bolze4356752019-03-07 11:23:46 -06001142 auto type_id = src->get_def(insn.word(1));
1143 if (type_id.opcode() != spv::OpTypeInt || type_id.word(2) != 32) {
1144 return false;
1145 }
1146 switch (insn.opcode()) {
1147 case spv::OpSpecConstant:
1148 *value = insn.word(3);
1149 GetSpecConstantValue(pStage, id_to_spec_id.at(insn.word(2)), value);
1150 return true;
1151 case spv::OpConstant:
1152 *value = insn.word(3);
1153 return true;
1154 default:
1155 return false;
1156 }
1157}
1158
1159// Map SPIR-V type to VK_COMPONENT_TYPE enum
Mark Lobodzinski3c59d972019-04-25 11:28:14 -06001160VkComponentTypeNV GetComponentType(spirv_inst_iter insn, SHADER_MODULE_STATE const *src) {
Jeff Bolze4356752019-03-07 11:23:46 -06001161 switch (insn.opcode()) {
1162 case spv::OpTypeInt:
1163 switch (insn.word(2)) {
1164 case 8:
1165 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT8_NV : VK_COMPONENT_TYPE_UINT8_NV;
1166 case 16:
1167 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT16_NV : VK_COMPONENT_TYPE_UINT16_NV;
1168 case 32:
1169 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT32_NV : VK_COMPONENT_TYPE_UINT32_NV;
1170 case 64:
1171 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT64_NV : VK_COMPONENT_TYPE_UINT64_NV;
1172 default:
1173 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1174 }
1175 case spv::OpTypeFloat:
1176 switch (insn.word(2)) {
1177 case 16:
1178 return VK_COMPONENT_TYPE_FLOAT16_NV;
1179 case 32:
1180 return VK_COMPONENT_TYPE_FLOAT32_NV;
1181 case 64:
1182 return VK_COMPONENT_TYPE_FLOAT64_NV;
1183 default:
1184 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1185 }
1186 default:
1187 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1188 }
1189}
1190
1191// Validate SPV_NV_cooperative_matrix behavior that can't be statically validated
1192// in SPIRV-Tools (e.g. due to specialization constant usage).
Mark Lobodzinski3c59d972019-04-25 11:28:14 -06001193bool CoreChecks::ValidateCooperativeMatrix(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
John Zulaufac4c6e12019-07-01 16:05:58 -06001194 const PIPELINE_STATE *pipeline) const {
Jeff Bolze4356752019-03-07 11:23:46 -06001195 bool skip = false;
1196
1197 // Map SPIR-V result ID to specialization constant id (SpecId decoration value)
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001198 layer_data::unordered_map<uint32_t, uint32_t> id_to_spec_id;
Jeff Bolze4356752019-03-07 11:23:46 -06001199 // Map SPIR-V result ID to the ID of its type.
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001200 layer_data::unordered_map<uint32_t, uint32_t> id_to_type_id;
Jeff Bolze4356752019-03-07 11:23:46 -06001201
1202 struct CoopMatType {
1203 uint32_t scope, rows, cols;
1204 VkComponentTypeNV component_type;
1205 bool all_constant;
1206
1207 CoopMatType() : scope(0), rows(0), cols(0), component_type(VK_COMPONENT_TYPE_MAX_ENUM_NV), all_constant(false) {}
1208
Mark Lobodzinski3c59d972019-04-25 11:28:14 -06001209 void Init(uint32_t id, SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001210 const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id) {
Jeff Bolze4356752019-03-07 11:23:46 -06001211 spirv_inst_iter insn = src->get_def(id);
1212 uint32_t component_type_id = insn.word(2);
1213 uint32_t scope_id = insn.word(3);
1214 uint32_t rows_id = insn.word(4);
1215 uint32_t cols_id = insn.word(5);
1216 auto component_type_iter = src->get_def(component_type_id);
1217 auto scope_iter = src->get_def(scope_id);
1218 auto rows_iter = src->get_def(rows_id);
1219 auto cols_iter = src->get_def(cols_id);
1220
1221 all_constant = true;
1222 if (!GetIntConstantValue(scope_iter, src, pStage, id_to_spec_id, &scope)) {
1223 all_constant = false;
1224 }
1225 if (!GetIntConstantValue(rows_iter, src, pStage, id_to_spec_id, &rows)) {
1226 all_constant = false;
1227 }
1228 if (!GetIntConstantValue(cols_iter, src, pStage, id_to_spec_id, &cols)) {
1229 all_constant = false;
1230 }
1231 component_type = GetComponentType(component_type_iter, src);
1232 }
1233 };
1234
1235 bool seen_coopmat_capability = false;
1236
1237 for (auto insn : *src) {
1238 // Whitelist instructions whose result can be a cooperative matrix type, and
1239 // keep track of their types. It would be nice if SPIRV-Headers generated code
1240 // to identify which instructions have a result type and result id. Lacking that,
1241 // this whitelist is based on the set of instructions that
1242 // SPV_NV_cooperative_matrix says can be used with cooperative matrix types.
1243 switch (insn.opcode()) {
1244 case spv::OpLoad:
1245 case spv::OpCooperativeMatrixLoadNV:
1246 case spv::OpCooperativeMatrixMulAddNV:
1247 case spv::OpSNegate:
1248 case spv::OpFNegate:
1249 case spv::OpIAdd:
1250 case spv::OpFAdd:
1251 case spv::OpISub:
1252 case spv::OpFSub:
1253 case spv::OpFDiv:
1254 case spv::OpSDiv:
1255 case spv::OpUDiv:
1256 case spv::OpMatrixTimesScalar:
1257 case spv::OpConstantComposite:
1258 case spv::OpCompositeConstruct:
1259 case spv::OpConvertFToU:
1260 case spv::OpConvertFToS:
1261 case spv::OpConvertSToF:
1262 case spv::OpConvertUToF:
1263 case spv::OpUConvert:
1264 case spv::OpSConvert:
1265 case spv::OpFConvert:
1266 id_to_type_id[insn.word(2)] = insn.word(1);
1267 break;
1268 default:
1269 break;
1270 }
1271
1272 switch (insn.opcode()) {
1273 case spv::OpDecorate:
1274 if (insn.word(2) == spv::DecorationSpecId) {
1275 id_to_spec_id[insn.word(1)] = insn.word(3);
1276 }
1277 break;
1278 case spv::OpCapability:
1279 if (insn.word(1) == spv::CapabilityCooperativeMatrixNV) {
1280 seen_coopmat_capability = true;
1281
1282 if (!(pStage->stage & phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001283 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001284 pipeline->pipeline(), "VUID-RuntimeSpirv-OpTypeCooperativeMatrixNV-06322",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001285 "OpTypeCooperativeMatrixNV used in shader stage not in cooperativeMatrixSupportedStages (= %u)",
1286 phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages);
Jeff Bolze4356752019-03-07 11:23:46 -06001287 }
1288 }
1289 break;
1290 case spv::OpMemoryModel:
1291 // If the capability isn't enabled, don't bother with the rest of this function.
1292 // OpMemoryModel is the first required instruction after all OpCapability instructions.
1293 if (!seen_coopmat_capability) {
1294 return skip;
1295 }
1296 break;
1297 case spv::OpTypeCooperativeMatrixNV: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001298 CoopMatType m;
1299 m.Init(insn.word(1), src, pStage, id_to_spec_id);
Jeff Bolze4356752019-03-07 11:23:46 -06001300
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001301 if (m.all_constant) {
Jeff Bolze4356752019-03-07 11:23:46 -06001302 // Validate that the type parameters are all supported for one of the
1303 // operands of a cooperative matrix property.
1304 bool valid = false;
1305 for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001306 if (cooperative_matrix_properties[i].AType == m.component_type &&
1307 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].KSize == m.cols &&
1308 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001309 valid = true;
1310 break;
1311 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001312 if (cooperative_matrix_properties[i].BType == m.component_type &&
1313 cooperative_matrix_properties[i].KSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1314 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001315 valid = true;
1316 break;
1317 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001318 if (cooperative_matrix_properties[i].CType == m.component_type &&
1319 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1320 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001321 valid = true;
1322 break;
1323 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001324 if (cooperative_matrix_properties[i].DType == m.component_type &&
1325 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1326 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001327 valid = true;
1328 break;
1329 }
1330 }
1331 if (!valid) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001332 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixType,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001333 "OpTypeCooperativeMatrixNV (result id = %u) operands don't match a supported matrix type",
1334 insn.word(1));
Jeff Bolze4356752019-03-07 11:23:46 -06001335 }
1336 }
1337 break;
1338 }
1339 case spv::OpCooperativeMatrixMulAddNV: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001340 CoopMatType a, b, c, d;
Jeff Bolze4356752019-03-07 11:23:46 -06001341 if (id_to_type_id.find(insn.word(2)) == id_to_type_id.end() ||
1342 id_to_type_id.find(insn.word(3)) == id_to_type_id.end() ||
1343 id_to_type_id.find(insn.word(4)) == id_to_type_id.end() ||
1344 id_to_type_id.find(insn.word(5)) == id_to_type_id.end()) {
Mike Schuchardte48dc142019-04-18 09:12:03 -07001345 // Couldn't find type of matrix
1346 assert(false);
Jeff Bolze4356752019-03-07 11:23:46 -06001347 break;
1348 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001349 d.Init(id_to_type_id[insn.word(2)], src, pStage, id_to_spec_id);
1350 a.Init(id_to_type_id[insn.word(3)], src, pStage, id_to_spec_id);
1351 b.Init(id_to_type_id[insn.word(4)], src, pStage, id_to_spec_id);
1352 c.Init(id_to_type_id[insn.word(5)], src, pStage, id_to_spec_id);
Jeff Bolze4356752019-03-07 11:23:46 -06001353
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001354 if (a.all_constant && b.all_constant && c.all_constant && d.all_constant) {
Jeff Bolze4356752019-03-07 11:23:46 -06001355 // Validate that the type parameters are all supported for the same
1356 // cooperative matrix property.
1357 bool valid = false;
1358 for (unsigned i = 0; i < cooperative_matrix_properties.size(); ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001359 if (cooperative_matrix_properties[i].AType == a.component_type &&
1360 cooperative_matrix_properties[i].MSize == a.rows && cooperative_matrix_properties[i].KSize == a.cols &&
1361 cooperative_matrix_properties[i].scope == a.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001362
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001363 cooperative_matrix_properties[i].BType == b.component_type &&
1364 cooperative_matrix_properties[i].KSize == b.rows && cooperative_matrix_properties[i].NSize == b.cols &&
1365 cooperative_matrix_properties[i].scope == b.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001366
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001367 cooperative_matrix_properties[i].CType == c.component_type &&
1368 cooperative_matrix_properties[i].MSize == c.rows && cooperative_matrix_properties[i].NSize == c.cols &&
1369 cooperative_matrix_properties[i].scope == c.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001370
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001371 cooperative_matrix_properties[i].DType == d.component_type &&
1372 cooperative_matrix_properties[i].MSize == d.rows && cooperative_matrix_properties[i].NSize == d.cols &&
1373 cooperative_matrix_properties[i].scope == d.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001374 valid = true;
1375 break;
1376 }
1377 }
1378 if (!valid) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001379 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixMulAdd,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001380 "OpCooperativeMatrixMulAddNV (result id = %u) operands don't match a supported matrix "
1381 "VkCooperativeMatrixPropertiesNV",
1382 insn.word(2));
Jeff Bolze4356752019-03-07 11:23:46 -06001383 }
1384 }
1385 break;
1386 }
1387 default:
1388 break;
1389 }
1390 }
1391
1392 return skip;
1393}
1394
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001395bool CoreChecks::ValidateShaderResolveQCOM(SHADER_MODULE_STATE const *src, VkPipelineShaderStageCreateInfo const *pStage,
1396 const PIPELINE_STATE *pipeline) const {
1397 bool skip = false;
1398
1399 // If the pipeline's subpass description contains flag VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM,
1400 // then the fragment shader must not enable the SPIRV SampleRateShading capability.
1401 if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
1402 for (auto insn : *src) {
1403 switch (insn.opcode()) {
1404 case spv::OpCapability:
1405 if (insn.word(1) == spv::CapabilitySampleRateShading) {
1406 auto subpass_flags =
1407 (pipeline->rp_state == nullptr)
1408 ? 0
Jeremy Gebben11af9792021-08-20 10:20:09 -06001409 : pipeline->rp_state->createInfo.pSubpasses[pipeline->create_info.graphics.subpass].flags;
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001410 if ((subpass_flags & VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM) != 0) {
1411 skip |=
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001412 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-SampleRateShading-06378",
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001413 "Invalid Pipeline CreateInfo State: fragment shader enables SampleRateShading capability "
1414 "and the subpass flags includes VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM.");
1415 }
1416 }
1417 break;
1418 default:
1419 break;
1420 }
1421 }
1422 }
1423
1424 return skip;
1425}
1426
ziga-lunarg73163742021-08-25 13:15:29 +02001427bool CoreChecks::ValidateShaderSubgroupSizeControl(VkPipelineShaderStageCreateInfo const *pStage) const {
1428 bool skip = false;
1429
1430 if ((pStage->flags & VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) != 0 &&
1431 !enabled_features.subgroup_size_control_features.subgroupSizeControl) {
1432 skip |= LogError(
1433 device, "VUID-VkPipelineShaderStageCreateInfo-flags-02784",
1434 "VkPipelineShaderStageCreateInfo flags contain VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, "
1435 "but the VkPhysicalDeviceSubgroupSizeControlFeaturesEXT::subgroupSizeControl feature is not enabled.");
1436 }
1437
1438 if ((pStage->flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) != 0 &&
1439 !enabled_features.subgroup_size_control_features.computeFullSubgroups) {
1440 skip |= LogError(
1441 device, "VUID-VkPipelineShaderStageCreateInfo-flags-02785",
1442 "VkPipelineShaderStageCreateInfo flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT, but the "
1443 "VkPhysicalDeviceSubgroupSizeControlFeaturesEXT::computeFullSubgroups feature is not enabled");
1444 }
1445
1446 return skip;
1447}
1448
sfricke-samsung58b84352021-07-31 21:41:04 -07001449bool CoreChecks::ValidateAtomicsTypes(SHADER_MODULE_STATE const *src) const {
1450 bool skip = false;
1451
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001452 // "If sparseImageInt64Atomics is enabled, shaderImageInt64Atomics must be enabled"
sfricke-samsung828e59d2021-08-22 23:20:49 -07001453 const bool valid_image_64_int = enabled_features.shader_image_atomic_int64_features.shaderImageInt64Atomics == VK_TRUE;
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001454
sfricke-samsungf5042b12021-08-05 01:09:40 -07001455 const VkPhysicalDeviceShaderAtomicFloatFeaturesEXT &float_features = enabled_features.shader_atomic_float_features;
1456 const VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT &float2_features = enabled_features.shader_atomic_float2_features;
1457
1458 const bool valid_storage_buffer_float = (
1459 (float_features.shaderBufferFloat32Atomics == VK_TRUE) ||
1460 (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) ||
1461 (float_features.shaderBufferFloat64Atomics == VK_TRUE) ||
1462 (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) ||
1463 (float2_features.shaderBufferFloat16Atomics == VK_TRUE) ||
1464 (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) ||
1465 (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) ||
1466 (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) ||
1467 (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE));
1468
1469 const bool valid_workgroup_float = (
1470 (float_features.shaderSharedFloat32Atomics == VK_TRUE) ||
1471 (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) ||
1472 (float_features.shaderSharedFloat64Atomics == VK_TRUE) ||
1473 (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) ||
1474 (float2_features.shaderSharedFloat16Atomics == VK_TRUE) ||
1475 (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) ||
1476 (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE) ||
1477 (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) ||
1478 (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE));
1479
1480 const bool valid_image_float = (
1481 (float_features.shaderImageFloat32Atomics == VK_TRUE) ||
1482 (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) ||
1483 (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE));
1484
1485 const bool valid_16_float = (
1486 (float2_features.shaderBufferFloat16Atomics == VK_TRUE) ||
1487 (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) ||
1488 (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) ||
1489 (float2_features.shaderSharedFloat16Atomics == VK_TRUE) ||
1490 (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) ||
1491 (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE));
1492
1493 const bool valid_32_float = (
1494 (float_features.shaderBufferFloat32Atomics == VK_TRUE) ||
1495 (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) ||
1496 (float_features.shaderSharedFloat32Atomics == VK_TRUE) ||
1497 (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) ||
1498 (float_features.shaderImageFloat32Atomics == VK_TRUE) ||
1499 (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) ||
1500 (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) ||
1501 (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) ||
1502 (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE));
1503
1504 const bool valid_64_float = (
1505 (float_features.shaderBufferFloat64Atomics == VK_TRUE) ||
1506 (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) ||
1507 (float_features.shaderSharedFloat64Atomics == VK_TRUE) ||
1508 (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) ||
1509 (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE) ||
1510 (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE));
1511 // clang-format on
1512
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06001513 for (const auto &atomic_inst : src->GetAtomicInstructions()) {
sfricke-samsung58b84352021-07-31 21:41:04 -07001514 const atomic_instruction &atomic = atomic_inst.second;
sfricke-samsungf5042b12021-08-05 01:09:40 -07001515 const uint32_t opcode = src->at(atomic_inst.first).opcode();
sfricke-samsung58b84352021-07-31 21:41:04 -07001516
1517 if ((atomic.bit_width == 64) && (atomic.type == spv::OpTypeInt)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001518 // Validate 64-bit image atomics
sfricke-samsung58b84352021-07-31 21:41:04 -07001519 if (((atomic.storage_class == spv::StorageClassStorageBuffer) || (atomic.storage_class == spv::StorageClassUniform)) &&
1520 (enabled_features.core12.shaderBufferInt64Atomics == VK_FALSE)) {
1521 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001522 device, "VUID-RuntimeSpirv-None-06278",
sfricke-samsung58b84352021-07-31 21:41:04 -07001523 "%s: Can't use 64-bit int atomics operations with %s storage class without shaderBufferInt64Atomics enabled.",
1524 report_data->FormatHandle(src->vk_shader_module()).c_str(), StorageClassName(atomic.storage_class));
1525 } else if ((atomic.storage_class == spv::StorageClassWorkgroup) &&
1526 (enabled_features.core12.shaderSharedInt64Atomics == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001527 skip |= LogError(device, "VUID-RuntimeSpirv-None-06279",
sfricke-samsung58b84352021-07-31 21:41:04 -07001528 "%s: Can't use 64-bit int atomics operations with Workgroup storage class without "
1529 "shaderSharedInt64Atomics enabled.",
1530 report_data->FormatHandle(src->vk_shader_module()).c_str());
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001531 } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_64_int == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001532 skip |= LogError(device, "VUID-RuntimeSpirv-None-06288",
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001533 "%s: Can't use 64-bit int atomics operations with Image storage class without "
1534 "shaderImageInt64Atomics enabled.",
1535 report_data->FormatHandle(src->vk_shader_module()).c_str());
sfricke-samsung58b84352021-07-31 21:41:04 -07001536 }
sfricke-samsungf5042b12021-08-05 01:09:40 -07001537 } else if (atomic.type == spv::OpTypeFloat) {
1538 // Validate Floats
1539 if (atomic.storage_class == spv::StorageClassStorageBuffer) {
1540 if (valid_storage_buffer_float == false) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001541 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06284"
1542 : "VUID-RuntimeSpirv-None-06280";
1543 skip |= LogError(device, vuid,
sfricke-samsungf5042b12021-08-05 01:09:40 -07001544 "%s: Can't use float atomics operations with StorageBuffer storage class without "
1545 "shaderBufferFloat32Atomics or shaderBufferFloat32AtomicAdd or shaderBufferFloat64Atomics or "
1546 "shaderBufferFloat64AtomicAdd or shaderBufferFloat16Atomics or shaderBufferFloat16AtomicAdd "
1547 "or shaderBufferFloat16AtomicMinMax or shaderBufferFloat32AtomicMinMax or "
1548 "shaderBufferFloat64AtomicMinMax enabled.",
1549 report_data->FormatHandle(src->vk_shader_module()).c_str());
1550 } else if (opcode == spv::OpAtomicFAddEXT) {
1551 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicAdd == VK_FALSE)) {
1552 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1553 "%s: Can't use 16-bit float atomics for add operations (OpAtomicFAddEXT) with "
1554 "StorageBuffer storage class without shaderBufferFloat16AtomicAdd enabled.",
1555 report_data->FormatHandle(src->vk_shader_module()).c_str());
1556 } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32AtomicAdd == VK_FALSE)) {
1557 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1558 "%s: Can't use 32-bit float atomics for add operations (OpAtomicFAddEXT) with "
1559 "StorageBuffer storage class without shaderBufferFloat32AtomicAdd enabled.",
1560 report_data->FormatHandle(src->vk_shader_module()).c_str());
1561 } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64AtomicAdd == VK_FALSE)) {
1562 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1563 "%s: Can't use 64-bit float atomics for add operations (OpAtomicFAddEXT) with "
1564 "StorageBuffer storage class without shaderBufferFloat64AtomicAdd enabled.",
1565 report_data->FormatHandle(src->vk_shader_module()).c_str());
1566 }
1567 } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) {
1568 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicMinMax == VK_FALSE)) {
1569 skip |= LogError(
1570 device, kVUID_Core_Shader_AtomicFeature,
1571 "%s: Can't use 16-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1572 "StorageBuffer storage class without shaderBufferFloat16AtomicMinMax enabled.",
1573 report_data->FormatHandle(src->vk_shader_module()).c_str());
1574 } else if ((atomic.bit_width == 32) && (float2_features.shaderBufferFloat32AtomicMinMax == VK_FALSE)) {
1575 skip |= LogError(
1576 device, kVUID_Core_Shader_AtomicFeature,
1577 "%s: Can't use 32-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1578 "StorageBuffer storage class without shaderBufferFloat32AtomicMinMax enabled.",
1579 report_data->FormatHandle(src->vk_shader_module()).c_str());
1580 } else if ((atomic.bit_width == 64) && (float2_features.shaderBufferFloat64AtomicMinMax == VK_FALSE)) {
1581 skip |= LogError(
1582 device, kVUID_Core_Shader_AtomicFeature,
1583 "%s: Can't use 64-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1584 "StorageBuffer storage class without shaderBufferFloat64AtomicMinMax enabled.",
1585 report_data->FormatHandle(src->vk_shader_module()).c_str());
1586 }
1587 } else {
1588 // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch
1589 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16Atomics == VK_FALSE)) {
1590 skip |= LogError(
1591 device, kVUID_Core_Shader_AtomicFeature,
1592 "%s: Can't use 16-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1593 "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat16Atomics enabled.",
1594 report_data->FormatHandle(src->vk_shader_module()).c_str());
1595 } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32Atomics == VK_FALSE)) {
1596 skip |= LogError(
1597 device, kVUID_Core_Shader_AtomicFeature,
1598 "%s: Can't use 32-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1599 "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat32Atomics enabled.",
1600 report_data->FormatHandle(src->vk_shader_module()).c_str());
1601 } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64Atomics == VK_FALSE)) {
1602 skip |= LogError(
1603 device, kVUID_Core_Shader_AtomicFeature,
1604 "%s: Can't use 64-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1605 "OpAtomicExchange) with StorageBuffer storage class without shaderBufferFloat64Atomics enabled.",
1606 report_data->FormatHandle(src->vk_shader_module()).c_str());
1607 }
1608 }
1609 } else if (atomic.storage_class == spv::StorageClassWorkgroup) {
1610 if (valid_workgroup_float == false) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001611 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06285"
1612 : "VUID-RuntimeSpirv-None-06281";
sfricke-samsungf5042b12021-08-05 01:09:40 -07001613 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001614 device, vuid,
sfricke-samsungf5042b12021-08-05 01:09:40 -07001615 "%s: Can't use float atomics operations with Workgroup storage class without shaderSharedFloat32Atomics or "
1616 "shaderSharedFloat32AtomicAdd or shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd or "
1617 "shaderSharedFloat16Atomics or shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax or "
1618 "shaderSharedFloat32AtomicMinMax or shaderSharedFloat64AtomicMinMax enabled.",
1619 report_data->FormatHandle(src->vk_shader_module()).c_str());
1620 } else if (opcode == spv::OpAtomicFAddEXT) {
1621 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicAdd == VK_FALSE)) {
1622 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1623 "%s: Can't use 16-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup "
1624 "storage class without shaderSharedFloat16AtomicAdd enabled.",
1625 report_data->FormatHandle(src->vk_shader_module()).c_str());
1626 } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32AtomicAdd == VK_FALSE)) {
1627 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1628 "%s: Can't use 32-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup "
1629 "storage class without shaderSharedFloat32AtomicAdd enabled.",
1630 report_data->FormatHandle(src->vk_shader_module()).c_str());
1631 } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64AtomicAdd == VK_FALSE)) {
1632 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1633 "%s: Can't use 64-bit float atomics for add operations (OpAtomicFAddEXT) with Workgroup "
1634 "storage class without shaderSharedFloat64AtomicAdd enabled.",
1635 report_data->FormatHandle(src->vk_shader_module()).c_str());
1636 }
1637 } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) {
1638 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicMinMax == VK_FALSE)) {
1639 skip |= LogError(
1640 device, kVUID_Core_Shader_AtomicFeature,
1641 "%s: Can't use 16-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1642 "Workgroup storage class without shaderSharedFloat16AtomicMinMax enabled.",
1643 report_data->FormatHandle(src->vk_shader_module()).c_str());
1644 } else if ((atomic.bit_width == 32) && (float2_features.shaderSharedFloat32AtomicMinMax == VK_FALSE)) {
1645 skip |= LogError(
1646 device, kVUID_Core_Shader_AtomicFeature,
1647 "%s: Can't use 32-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1648 "Workgroup storage class without shaderSharedFloat32AtomicMinMax enabled.",
1649 report_data->FormatHandle(src->vk_shader_module()).c_str());
1650 } else if ((atomic.bit_width == 64) && (float2_features.shaderSharedFloat64AtomicMinMax == VK_FALSE)) {
1651 skip |= LogError(
1652 device, kVUID_Core_Shader_AtomicFeature,
1653 "%s: Can't use 64-bit float atomics for min/max operations (OpAtomicFMinEXT or OpAtomicFMaxEXT) with "
1654 "Workgroup storage class without shaderSharedFloat64AtomicMinMax enabled.",
1655 report_data->FormatHandle(src->vk_shader_module()).c_str());
1656 }
1657 } else {
1658 // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch
1659 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16Atomics == VK_FALSE)) {
1660 skip |= LogError(
1661 device, kVUID_Core_Shader_AtomicFeature,
1662 "%s: Can't use 16-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1663 "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat16Atomics enabled.",
1664 report_data->FormatHandle(src->vk_shader_module()).c_str());
1665 } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32Atomics == VK_FALSE)) {
1666 skip |= LogError(
1667 device, kVUID_Core_Shader_AtomicFeature,
1668 "%s: Can't use 32-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1669 "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat32Atomics enabled.",
1670 report_data->FormatHandle(src->vk_shader_module()).c_str());
1671 } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64Atomics == VK_FALSE)) {
1672 skip |= LogError(
1673 device, kVUID_Core_Shader_AtomicFeature,
1674 "%s: Can't use 64-bit float atomics for load/store/exhange operations (OpAtomicLoad, OpAtomicStore, "
1675 "OpAtomicExchange) with Workgroup storage class without shaderSharedFloat64Atomics enabled.",
1676 report_data->FormatHandle(src->vk_shader_module()).c_str());
1677 }
1678 }
1679 } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001680 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06286"
1681 : "VUID-RuntimeSpirv-None-06282";
sfricke-samsungf5042b12021-08-05 01:09:40 -07001682 skip |=
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001683 LogError(device, vuid,
sfricke-samsungf5042b12021-08-05 01:09:40 -07001684 "%s: Can't use float atomics operations with Image storage class without shaderImageFloat32Atomics or "
1685 "shaderImageFloat32AtomicAdd or shaderImageFloat32AtomicMinMax enabled.",
1686 report_data->FormatHandle(src->vk_shader_module()).c_str());
1687 } else if ((atomic.bit_width == 16) && (valid_16_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001688 skip |= LogError(device, "VUID-RuntimeSpirv-None-06337",
sfricke-samsungf5042b12021-08-05 01:09:40 -07001689 "%s: Can't use 16-bit float atomics operations without shaderBufferFloat16Atomics, "
1690 "shaderBufferFloat16AtomicAdd, shaderBufferFloat16AtomicMinMax, shaderSharedFloat16Atomics, "
1691 "shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax enabled.",
1692 report_data->FormatHandle(src->vk_shader_module()).c_str());
1693 } else if ((atomic.bit_width == 32) && (valid_32_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001694 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06338"
1695 : "VUID-RuntimeSpirv-None-06335";
1696 skip |= LogError(device, vuid,
sfricke-samsungf5042b12021-08-05 01:09:40 -07001697 "%s: Can't use 32-bit float atomics operations without shaderBufferFloat32AtomicMinMax, "
1698 "shaderSharedFloat32AtomicMinMax, shaderImageFloat32AtomicMinMax, sparseImageFloat32AtomicMinMax, "
1699 "shaderBufferFloat32Atomics, shaderBufferFloat32AtomicAdd, shaderSharedFloat32Atomics, "
1700 "shaderSharedFloat32AtomicAdd, shaderImageFloat32Atomics, shaderImageFloat32AtomicAdd, "
1701 "sparseImageFloat32Atomics or sparseImageFloat32AtomicAdd enabled.",
1702 report_data->FormatHandle(src->vk_shader_module()).c_str());
1703 } else if ((atomic.bit_width == 64) && (valid_64_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001704 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06339"
1705 : "VUID-RuntimeSpirv-None-06336";
1706 skip |= LogError(device, vuid,
sfricke-samsungf5042b12021-08-05 01:09:40 -07001707 "%s: Can't use 64-bit float atomics operations without shaderBufferFloat64AtomicMinMax, "
1708 "shaderSharedFloat64AtomicMinMax, shaderBufferFloat64Atomics, shaderBufferFloat64AtomicAdd, "
1709 "shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd enabled.",
1710 report_data->FormatHandle(src->vk_shader_module()).c_str());
1711 }
sfricke-samsung58b84352021-07-31 21:41:04 -07001712 }
1713 }
sfricke-samsung58b84352021-07-31 21:41:04 -07001714 return skip;
1715}
1716
John Zulaufac4c6e12019-07-01 16:05:58 -06001717bool CoreChecks::ValidateExecutionModes(SHADER_MODULE_STATE const *src, spirv_inst_iter entrypoint) const {
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001718 auto entrypoint_id = entrypoint.word(2);
1719
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001720 // The first denorm execution mode encountered, along with its bit width.
1721 // Used to check if SeparateDenormSettings is respected.
1722 std::pair<spv::ExecutionMode, uint32_t> first_denorm_execution_mode = std::make_pair(spv::ExecutionModeMax, 0);
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001723
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001724 // The first rounding mode encountered, along with its bit width.
1725 // Used to check if SeparateRoundingModeSettings is respected.
1726 std::pair<spv::ExecutionMode, uint32_t> first_rounding_mode = std::make_pair(spv::ExecutionModeMax, 0);
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001727
1728 bool skip = false;
1729
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001730 uint32_t vertices_out = 0;
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001731 uint32_t invocations = 0;
1732
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06001733 const auto &execution_mode_inst = src->GetExecutionModeInstructions();
1734 auto it = execution_mode_inst.find(entrypoint_id);
1735 if (it != execution_mode_inst.end()) {
sfricke-samsung8a7341a2021-02-28 07:30:21 -08001736 for (auto insn : it->second) {
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001737 auto mode = insn.word(2);
1738 switch (mode) {
1739 case spv::ExecutionModeSignedZeroInfNanPreserve: {
1740 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001741 if (bit_width == 16 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001742 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001743 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat16-06293",
1744 "Shader requires SignedZeroInfNanPreserve for bit width 16 but it is not enabled on the device");
1745 } else if (bit_width == 32 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32) {
1746 skip |= LogError(
1747 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat32-06294",
1748 "Shader requires SignedZeroInfNanPreserve for bit width 32 but it is not enabled on the device");
1749 } else if (bit_width == 64 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64) {
1750 skip |= LogError(
1751 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat64-06295",
1752 "Shader requires SignedZeroInfNanPreserve for bit width 64 but it is not enabled on the device");
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001753 }
1754 break;
1755 }
1756
1757 case spv::ExecutionModeDenormPreserve: {
1758 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001759 if (bit_width == 16 && !phys_dev_props_core12.shaderDenormPreserveFloat16) {
1760 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat16-06296",
1761 "Shader requires DenormPreserve for bit width 16 but it is not enabled on the device");
1762 } else if (bit_width == 32 && !phys_dev_props_core12.shaderDenormPreserveFloat32) {
1763 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat32-06297",
1764 "Shader requires DenormPreserve for bit width 32 but it is not enabled on the device");
1765 } else if (bit_width == 64 && !phys_dev_props_core12.shaderDenormPreserveFloat64) {
1766 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat64-06298",
1767 "Shader requires DenormPreserve for bit width 64 but it is not enabled on the device");
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001768 }
1769
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001770 if (first_denorm_execution_mode.first == spv::ExecutionModeMax) {
1771 // Register the first denorm execution mode found
1772 first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001773 } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001774 switch (phys_dev_props_core12.denormBehaviorIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001775 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001776 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001777 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06289",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001778 "Shader uses different denorm execution modes for 16 and 64-bit but "
1779 "denormBehaviorIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001780 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001781 }
1782 break;
1783
Mike Schuchardt2df08912020-12-15 16:28:09 -08001784 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001785 break;
1786
Mike Schuchardt2df08912020-12-15 16:28:09 -08001787 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001788 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06290",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001789 "Shader uses different denorm execution modes for different bit widths but "
1790 "denormBehaviorIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001791 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001792 break;
1793
1794 default:
1795 break;
1796 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001797 }
1798 break;
1799 }
1800
1801 case spv::ExecutionModeDenormFlushToZero: {
1802 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001803 if (bit_width == 16 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat16) {
1804 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat16-06299",
1805 "Shader requires DenormFlushToZero for bit width 16 but it is not enabled on the device");
1806 } else if (bit_width == 32 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat32) {
1807 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat32-06300",
1808 "Shader requires DenormFlushToZero for bit width 32 but it is not enabled on the device");
1809 } else if (bit_width == 64 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat64) {
1810 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat64-06301",
1811 "Shader requires DenormFlushToZero for bit width 64 but it is not enabled on the device");
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001812 }
1813
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001814 if (first_denorm_execution_mode.first == spv::ExecutionModeMax) {
1815 // Register the first denorm execution mode found
1816 first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001817 } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001818 switch (phys_dev_props_core12.denormBehaviorIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001819 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001820 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001821 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06289",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001822 "Shader uses different denorm execution modes for 16 and 64-bit but "
1823 "denormBehaviorIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001824 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001825 }
1826 break;
1827
Mike Schuchardt2df08912020-12-15 16:28:09 -08001828 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001829 break;
1830
Mike Schuchardt2df08912020-12-15 16:28:09 -08001831 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001832 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06290",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001833 "Shader uses different denorm execution modes for different bit widths but "
1834 "denormBehaviorIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001835 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001836 break;
1837
1838 default:
1839 break;
1840 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001841 }
1842 break;
1843 }
1844
1845 case spv::ExecutionModeRoundingModeRTE: {
1846 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001847 if (bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTEFloat16) {
1848 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat16-06302",
1849 "Shader requires RoundingModeRTE for bit width 16 but it is not enabled on the device");
1850 } else if (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTEFloat32) {
1851 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat32-06303",
1852 "Shader requires RoundingModeRTE for bit width 32 but it is not enabled on the device");
1853 } else if (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTEFloat64) {
1854 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat64-06304",
1855 "Shader requires RoundingModeRTE for bit width 64 but it is not enabled on the device");
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001856 }
1857
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001858 if (first_rounding_mode.first == spv::ExecutionModeMax) {
1859 // Register the first rounding mode found
1860 first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001861 } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001862 switch (phys_dev_props_core12.roundingModeIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001863 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001864 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001865 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06291",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001866 "Shader uses different rounding modes for 16 and 64-bit but "
1867 "roundingModeIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001868 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001869 }
1870 break;
1871
Mike Schuchardt2df08912020-12-15 16:28:09 -08001872 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001873 break;
1874
Mike Schuchardt2df08912020-12-15 16:28:09 -08001875 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001876 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06292",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001877 "Shader uses different rounding modes for different bit widths but "
1878 "roundingModeIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001879 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001880 break;
1881
1882 default:
1883 break;
1884 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001885 }
1886 break;
1887 }
1888
1889 case spv::ExecutionModeRoundingModeRTZ: {
1890 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001891 if (bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTZFloat16) {
1892 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat16-06305",
1893 "Shader requires RoundingModeRTZ for bit width 16 but it is not enabled on the device");
1894 } else if (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTZFloat32) {
1895 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat32-06306",
1896 "Shader requires RoundingModeRTZ for bit width 32 but it is not enabled on the device");
1897 } else if (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTZFloat64) {
1898 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat64-06307",
1899 "Shader requires RoundingModeRTZ for bit width 64 but it is not enabled on the device");
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001900 }
1901
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001902 if (first_rounding_mode.first == spv::ExecutionModeMax) {
1903 // Register the first rounding mode found
1904 first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001905 } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001906 switch (phys_dev_props_core12.roundingModeIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001907 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001908 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001909 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06291",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001910 "Shader uses different rounding modes for 16 and 64-bit but "
1911 "roundingModeIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001912 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001913 }
1914 break;
1915
Mike Schuchardt2df08912020-12-15 16:28:09 -08001916 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001917 break;
1918
Mike Schuchardt2df08912020-12-15 16:28:09 -08001919 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001920 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06292",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001921 "Shader uses different rounding modes for different bit widths but "
1922 "roundingModeIndependence is "
Mike Schuchardt2df08912020-12-15 16:28:09 -08001923 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device");
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001924 break;
1925
1926 default:
1927 break;
1928 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001929 }
1930 break;
1931 }
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001932
1933 case spv::ExecutionModeOutputVertices: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001934 vertices_out = insn.word(3);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001935 break;
1936 }
1937
1938 case spv::ExecutionModeInvocations: {
1939 invocations = insn.word(3);
1940 break;
1941 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001942 }
1943 }
1944 }
1945
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001946 if (entrypoint.word(1) == spv::ExecutionModelGeometry) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001947 if (vertices_out == 0 || vertices_out > phys_dev_props.limits.maxGeometryOutputVertices) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001948 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00714",
1949 "Geometry shader entry point must have an OpExecutionMode instruction that "
1950 "specifies a maximum output vertex count that is greater than 0 and less "
1951 "than or equal to maxGeometryOutputVertices. "
1952 "OutputVertices=%d, maxGeometryOutputVertices=%d",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001953 vertices_out, phys_dev_props.limits.maxGeometryOutputVertices);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001954 }
1955
1956 if (invocations == 0 || invocations > phys_dev_props.limits.maxGeometryShaderInvocations) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001957 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00715",
1958 "Geometry shader entry point must have an OpExecutionMode instruction that "
1959 "specifies an invocation count that is greater than 0 and less "
1960 "than or equal to maxGeometryShaderInvocations. "
1961 "Invocations=%d, maxGeometryShaderInvocations=%d",
1962 invocations, phys_dev_props.limits.maxGeometryShaderInvocations);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001963 }
1964 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001965 return skip;
1966}
1967
Chris Forbes47567b72017-06-09 12:09:45 -07001968// For given pipelineLayout verify that the set_layout_node at slot.first
1969// has the requested binding at slot.second and return ptr to that binding
Mark Lobodzinskica6ebe32019-04-25 11:43:37 -06001970static VkDescriptorSetLayoutBinding const *GetDescriptorBinding(PIPELINE_LAYOUT_STATE const *pipelineLayout,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06001971 DescriptorSlot slot) {
Chris Forbes47567b72017-06-09 12:09:45 -07001972 if (!pipelineLayout) return nullptr;
1973
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06001974 if (slot.set >= pipelineLayout->set_layouts.size()) return nullptr;
Chris Forbes47567b72017-06-09 12:09:45 -07001975
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06001976 return pipelineLayout->set_layouts[slot.set]->GetDescriptorSetLayoutBindingPtrFromBinding(slot.binding);
Chris Forbes47567b72017-06-09 12:09:45 -07001977}
1978
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06001979// If PointList topology is specified in the pipeline, verify that a shader geometry stage writes PointSize
1980// o If there is only a vertex shader : gl_PointSize must be written when using points
1981// o If there is a geometry or tessellation shader:
1982// - If shaderTessellationAndGeometryPointSize feature is enabled:
1983// * gl_PointSize must be written in the final geometry stage
1984// - If shaderTessellationAndGeometryPointSize feature is disabled:
1985// * gl_PointSize must NOT be written and a default of 1.0 is assumed
Mark Lobodzinski3c59d972019-04-25 11:28:14 -06001986bool CoreChecks::ValidatePointListShaderState(const PIPELINE_STATE *pipeline, SHADER_MODULE_STATE const *src,
John Zulaufac4c6e12019-07-01 16:05:58 -06001987 spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06001988 if (pipeline->topology_at_rasterizer != VK_PRIMITIVE_TOPOLOGY_POINT_LIST) {
1989 return false;
1990 }
1991
1992 bool pointsize_written = false;
1993 bool skip = false;
1994
1995 // Search for PointSize built-in decorations
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06001996 for (const auto &set : src->GetBuiltinDecorationList()) {
sfricke-samsungc0eb5282021-02-28 23:05:55 -08001997 auto insn = src->at(set.offset);
1998 if (set.builtin == spv::BuiltInPointSize) {
sfricke-samsung962cad92021-04-13 00:46:29 -07001999 pointsize_written = src->IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002000 if (pointsize_written) {
2001 break;
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002002 }
2003 }
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002004 }
2005
2006 if ((stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || stage == VK_SHADER_STAGE_GEOMETRY_BIT) &&
Mark Lobodzinskid7b03cc2019-04-19 14:23:10 -06002007 !enabled_features.core.shaderTessellationAndGeometryPointSize) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002008 if (pointsize_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002009 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_PointSizeBuiltInOverSpecified,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002010 "Pipeline topology is set to POINT_LIST and geometry or tessellation shaders write PointSize which "
2011 "is prohibited when the shaderTessellationAndGeometryPointSize feature is not enabled.");
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002012 }
2013 } else if (!pointsize_written) {
2014 skip |=
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002015 LogError(pipeline->pipeline(), kVUID_Core_Shader_MissingPointSizeBuiltIn,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002016 "Pipeline topology is set to POINT_LIST, but PointSize is not written to in the shader corresponding to %s.",
2017 string_VkShaderStageFlagBits(stage));
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002018 }
2019 return skip;
2020}
John Zulauf14c355b2019-06-27 16:09:37 -06002021
Tobias Hector6663c9b2020-11-05 10:18:02 +00002022bool CoreChecks::ValidatePrimitiveRateShaderState(const PIPELINE_STATE *pipeline, SHADER_MODULE_STATE const *src,
2023 spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const {
2024 bool primitiverate_written = false;
2025 bool viewportindex_written = false;
2026 bool viewportmask_written = false;
2027 bool skip = false;
2028
2029 // Check if the primitive shading rate is written
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002030 for (const auto &set : src->GetBuiltinDecorationList()) {
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002031 auto insn = src->at(set.offset);
2032 if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) {
sfricke-samsung962cad92021-04-13 00:46:29 -07002033 primitiverate_written = src->IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002034 } else if (set.builtin == spv::BuiltInViewportIndex) {
sfricke-samsung962cad92021-04-13 00:46:29 -07002035 viewportindex_written = src->IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002036 } else if (set.builtin == spv::BuiltInViewportMaskNV) {
sfricke-samsung962cad92021-04-13 00:46:29 -07002037 viewportmask_written = src->IsBuiltInWritten(insn, entrypoint);
Tobias Hector6663c9b2020-11-05 10:18:02 +00002038 }
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002039 if (primitiverate_written && viewportindex_written && viewportmask_written) {
2040 break;
2041 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00002042 }
2043
Tony-LunarGd44844c2021-01-22 13:24:37 -07002044 if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports &&
Jeremy Gebben11af9792021-08-20 10:20:09 -06002045 (pipeline->GetPipelineType() == VK_PIPELINE_BIND_POINT_GRAPHICS) && pipeline->create_info.graphics.pViewportState) {
Tobias Hector6663c9b2020-11-05 10:18:02 +00002046 if (!IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) &&
Jeremy Gebben11af9792021-08-20 10:20:09 -06002047 pipeline->create_info.graphics.pViewportState->viewportCount > 1 && primitiverate_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002048 skip |= LogError(pipeline->pipeline(),
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002049 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04503",
2050 "vkCreateGraphicsPipelines: %s shader statically writes to PrimitiveShadingRateKHR built-in, but "
2051 "multiple viewports "
2052 "are used and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2053 string_VkShaderStageFlagBits(stage));
Tobias Hector6663c9b2020-11-05 10:18:02 +00002054 }
2055
2056 if (primitiverate_written && viewportindex_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002057 skip |= LogError(pipeline->pipeline(),
Tobias Hector6663c9b2020-11-05 10:18:02 +00002058 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04504",
2059 "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and "
2060 "ViewportIndex built-ins,"
2061 "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2062 string_VkShaderStageFlagBits(stage));
2063 }
2064
2065 if (primitiverate_written && viewportmask_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002066 skip |= LogError(pipeline->pipeline(),
Tobias Hector6663c9b2020-11-05 10:18:02 +00002067 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04505",
2068 "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and "
2069 "ViewportMaskNV built-ins,"
2070 "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2071 string_VkShaderStageFlagBits(stage));
2072 }
2073 }
2074 return skip;
2075}
2076
ziga-lunargce66e542021-09-19 00:11:14 +02002077bool CoreChecks::ValidateDecorations(SHADER_MODULE_STATE const* module) const {
2078 bool skip = false;
2079
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002080 for (const auto &op_decorate : module->GetDecorationInstructions()) {
ziga-lunargce66e542021-09-19 00:11:14 +02002081 uint32_t decoration = op_decorate.word(2);
2082 if (decoration == spv::DecorationXfbStride) {
2083 uint32_t stride = op_decorate.word(3);
2084 if (stride > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride) {
2085 skip |= LogError(
2086 device, "VUID-RuntimeSpirv-XfbStride-06313",
2087 "vkCreateGraphicsPipelines(): shader uses transform feedback with xfb_stride (%" PRIu32
2088 ") greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBufferDataStride (%" PRIu32
2089 ").",
2090 stride, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride);
2091 }
2092 }
2093 }
2094
2095 return skip;
2096}
2097
2098bool CoreChecks::ValidateTransformFeedback(SHADER_MODULE_STATE const *module, spirv_inst_iter &insn) const {
2099 bool skip = false;
2100
2101 uint32_t opcode = insn.opcode();
2102 if (opcode == spv::OpEmitStreamVertex || opcode == spv::OpEndStreamPrimitive) {
2103 uint32_t stream = static_cast<uint32_t>(module->GetConstantValueById(insn.word(1)));
2104 if (stream >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams) {
2105 skip |= LogError(
2106 device, "VUID-RuntimeSpirv-OpEmitStreamVertex-06310",
2107 "vkCreateGraphicsPipelines(): shader uses transform feedback stream with index %" PRIu32
2108 ", which is not less than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackStreams (%" PRIu32
2109 ").",
2110 stream, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams);
2111 }
2112 }
2113
2114 return skip;
2115}
2116
ziga-lunarga12c75a2021-09-16 16:36:16 +02002117bool CoreChecks::ValidateTexelGatherOffset(SHADER_MODULE_STATE const *src, spirv_inst_iter &insn) const {
2118 bool skip = false;
2119
2120 const uint32_t opcode = insn.opcode();
2121 // If opcode is OpImage*Gather
2122 if (opcode == spv::OpImageGather || opcode == spv::OpImageDrefGather || opcode == spv::OpImageSparseGather ||
2123 opcode == spv::OpImageSparseDrefGather) {
2124 if (insn.len() > 6) { // Image operands are optional
2125 auto image_operand = insn.word(6);
2126 // Bits we are validating
2127 uint32_t offset_bits =
2128 spv::ImageOperandsOffsetMask | spv::ImageOperandsConstOffsetMask | spv::ImageOperandsConstOffsetsMask;
2129 if (image_operand & (offset_bits)) {
2130 // Operand values start at word 7
2131 uint32_t index = 7;
2132 // Each bit has it's own operand, starts with the smallest set bit and loop to the highest bit among
2133 // ImageOperandsOffsetMask, ImageOperandsConstOffsetMask and ImageOperandsConstOffsetsMask
2134 for (uint32_t i = 1; i < spv::ImageOperandsConstOffsetsMask; i <<= 1) {
2135 if (image_operand & i) { // If the bit is set, consume operand
2136 if (insn.len() > index && (i & offset_bits)) {
2137 uint32_t constant_id = insn.word(index);
2138 const auto &constant = src->get_def(constant_id);
Shahbaz Youssefi7a6a5272021-10-06 15:07:10 -04002139 const bool is_dynamic_offset = constant == src->end();
2140 if (!is_dynamic_offset && constant.opcode() == spv::OpConstantComposite) {
ziga-lunarga12c75a2021-09-16 16:36:16 +02002141 for (uint32_t j = 3; j < constant.len(); ++j) {
2142 uint32_t comp_id = constant.word(j);
2143 const auto &comp = src->get_def(comp_id);
sfricke-samsungef3fe742021-10-06 10:51:34 -07002144 const auto &comp_type = src->get_def(comp.word(1));
ziga-lunarga12c75a2021-09-16 16:36:16 +02002145 // Get operand value
sfricke-samsungef3fe742021-10-06 10:51:34 -07002146 const uint32_t offset = comp.word(3);
2147 const int32_t signed_offset = static_cast<int32_t>(offset);
2148 const bool use_signed = (comp_type.opcode() == spv::OpTypeInt && comp_type.word(3) != 0);
2149
2150 // spec requires minTexelGatherOffset to be -8 or less so never can compare if unsigned
2151 // spec requires maxTexelGatherOffset to be 7 or greater so never can compare if signed is less
2152 // then zero
2153 if (use_signed && (signed_offset < phys_dev_props.limits.minTexelGatherOffset)) {
ziga-lunarga12c75a2021-09-16 16:36:16 +02002154 skip |= LogError(device, "VUID-RuntimeSpirv-OpImage-06376",
2155 "vkCreateShaderModule(): Shader uses OpImageGather with offset (%" PRIi32
sfricke-samsungef3fe742021-10-06 10:51:34 -07002156 ") less than VkPhysicalDeviceLimits::minTexelGatherOffset (%" PRIi32 ").",
2157 signed_offset, phys_dev_props.limits.minTexelGatherOffset);
2158 } else if ((offset > phys_dev_props.limits.maxTexelGatherOffset) &&
2159 (!use_signed || (use_signed && signed_offset > 0))) {
ziga-lunarga12c75a2021-09-16 16:36:16 +02002160 skip |=
2161 LogError(device, "VUID-RuntimeSpirv-OpImage-06377",
sfricke-samsungef3fe742021-10-06 10:51:34 -07002162 "vkCreateShaderModule(): Shader uses OpImageGather with offset (%" PRIu32
ziga-lunarga12c75a2021-09-16 16:36:16 +02002163 ") greater than VkPhysicalDeviceLimits::maxTexelGatherOffset (%" PRIu32 ").",
2164 offset, phys_dev_props.limits.maxTexelGatherOffset);
2165 }
2166 }
2167 }
2168 }
2169 index += src->ImageOperandsCount(i);
2170 }
2171 }
2172 }
2173 }
2174 }
2175
2176 return skip;
2177}
2178
sfricke-samsung306dc4c2021-09-20 15:25:18 -07002179bool CoreChecks::ValidateShaderClock(SHADER_MODULE_STATE const *module, spirv_inst_iter &insn) const {
sfricke-samsung486a51e2021-01-02 00:10:15 -08002180 bool skip = false;
2181
sfricke-samsung94167ca2021-02-26 04:14:59 -08002182 switch (insn.opcode()) {
2183 case spv::OpReadClockKHR: {
2184 auto scope_id = module->get_def(insn.word(3));
2185 auto scope_type = scope_id.word(3);
2186 // if scope isn't Subgroup or Device, spirv-val will catch
sfricke-samsung828e59d2021-08-22 23:20:49 -07002187 if ((scope_type == spv::ScopeSubgroup) && (enabled_features.shader_clock_features.shaderSubgroupClock == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07002188 skip |= LogError(device, "VUID-RuntimeSpirv-shaderSubgroupClock-06267",
sfricke-samsung94167ca2021-02-26 04:14:59 -08002189 "%s: OpReadClockKHR is used with a Subgroup scope but shaderSubgroupClock was not enabled.",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002190 report_data->FormatHandle(module->vk_shader_module()).c_str());
sfricke-samsung828e59d2021-08-22 23:20:49 -07002191 } else if ((scope_type == spv::ScopeDevice) && (enabled_features.shader_clock_features.shaderDeviceClock == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07002192 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDeviceClock-06268",
sfricke-samsung94167ca2021-02-26 04:14:59 -08002193 "%s: OpReadClockKHR is used with a Device scope but shaderDeviceClock was not enabled.",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002194 report_data->FormatHandle(module->vk_shader_module()).c_str());
sfricke-samsung486a51e2021-01-02 00:10:15 -08002195 }
sfricke-samsung94167ca2021-02-26 04:14:59 -08002196 break;
sfricke-samsung486a51e2021-01-02 00:10:15 -08002197 }
2198 }
2199 return skip;
2200}
2201
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002202bool CoreChecks::ValidatePipelineShaderStage(const PIPELINE_STATE *pipeline, const PipelineStageState &stage_state,
2203 bool check_point_size) const {
John Zulauf14c355b2019-06-27 16:09:37 -06002204 bool skip = false;
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002205 const auto *pStage = stage_state.create_info;
2206 const auto *module = stage_state.module.get();
2207 const auto &entrypoint = stage_state.entrypoint;
John Zulauf14c355b2019-06-27 16:09:37 -06002208 // Check the module
2209 if (!module->has_valid_spirv) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002210 skip |= LogError(
2211 device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter", "%s does not contain valid spirv for stage %s.",
2212 report_data->FormatHandle(module->vk_shader_module()).c_str(), string_VkShaderStageFlagBits(stage_state.stage_flag));
John Zulauf14c355b2019-06-27 16:09:37 -06002213 }
2214
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002215 // If specialization-constant values are given and specialization-constant instructions are present in the shader, the
2216 // specializations should be applied and validated.
2217 if (pStage->pSpecializationInfo != nullptr && pStage->pSpecializationInfo->mapEntryCount > 0 &&
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002218 pStage->pSpecializationInfo->pMapEntries != nullptr && module->HasSpecConstants()) {
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002219 // Gather the specialization-constant values.
2220 auto const &specialization_info = pStage->pSpecializationInfo;
Jeremy Hayes521221d2020-01-15 16:48:49 -07002221 auto const &specialization_data = reinterpret_cast<uint8_t const *>(specialization_info->pData);
Jeremy Gebbencbf22862021-03-03 12:01:22 -07002222 std::unordered_map<uint32_t, std::vector<uint32_t>> id_value_map; // note: this must be std:: to work with spvtools
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002223 id_value_map.reserve(specialization_info->mapEntryCount);
2224 for (auto i = 0u; i < specialization_info->mapEntryCount; ++i) {
2225 auto const &map_entry = specialization_info->pMapEntries[i];
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002226 const auto itr = module->GetSpecConstMap().find(map_entry.constantID);
sfricke-samsung033b0262021-07-09 00:53:06 -07002227 // "If a constantID value is not a specialization constant ID used in the shader, that map entry does not affect the
2228 // behavior of the pipeline."
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002229 if (itr != module->GetSpecConstMap().cend()) {
sfricke-samsung033b0262021-07-09 00:53:06 -07002230 // Make sure map_entry.size matches the spec constant's size
2231 uint32_t spec_const_size = decoration_set::kInvalidValue;
2232 const auto def_ins = module->get_def(itr->second);
2233 const auto type_ins = module->get_def(def_ins.word(1));
2234 // Specialization constants can only be of type bool, scalar integer, or scalar floating point
2235 switch (type_ins.opcode()) {
2236 case spv::OpTypeBool:
2237 // "If the specialization constant is of type boolean, size must be the byte size of VkBool32"
2238 spec_const_size = sizeof(VkBool32);
2239 break;
2240 case spv::OpTypeInt:
2241 case spv::OpTypeFloat:
2242 spec_const_size = type_ins.word(2) / 8;
2243 break;
2244 default:
2245 // spirv-val should catch if SpecId is not used on a OpSpecConstantTrue/OpSpecConstantFalse/OpSpecConstant
2246 // and OpSpecConstant is validated to be a OpTypeInt or OpTypeFloat
2247 break;
2248 }
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002249
sfricke-samsung033b0262021-07-09 00:53:06 -07002250 if (map_entry.size != spec_const_size) {
2251 skip |=
2252 LogError(device, "VUID-VkSpecializationMapEntry-constantID-00776",
Nathaniel Cesariocf69bda2021-06-22 13:23:42 -06002253 "Specialization constant (ID = %" PRIu32 ", entry = %" PRIu32
2254 ") has invalid size %zu in shader module %s. Expected size is %" PRIu32 " from shader definition.",
2255 map_entry.constantID, i, map_entry.size,
2256 report_data->FormatHandle(module->vk_shader_module()).c_str(), spec_const_size);
sfricke-samsung033b0262021-07-09 00:53:06 -07002257 }
Nathaniel Cesariocf69bda2021-06-22 13:23:42 -06002258 }
2259
Jeremy Gebben12933ef2021-05-12 17:16:27 -06002260 if ((map_entry.offset + map_entry.size) <= specialization_info->dataSize) {
Nathaniel Cesario0b2a6422021-07-13 16:04:57 -06002261 // Allocate enough room for ceil(map_entry.size / 4) to store entries
2262 std::vector<uint32_t> entry_data((map_entry.size + 4 - 1) / 4, 0);
2263 uint8_t *out_p = reinterpret_cast<uint8_t *>(entry_data.data());
2264 const uint8_t *const start_in_p = specialization_data + map_entry.offset;
2265 const uint8_t *const end_in_p = start_in_p + map_entry.size;
2266
2267 std::copy(start_in_p, end_in_p, out_p);
2268 id_value_map.emplace(map_entry.constantID, std::move(entry_data));
Jeremy Gebben12933ef2021-05-12 17:16:27 -06002269 }
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002270 }
2271
2272 // Apply the specialization-constant values and revalidate the shader module.
sfricke-samsung45996a42021-09-16 13:45:27 -07002273 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002274 spvtools::Optimizer optimizer(spirv_environment);
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002275 spvtools::MessageConsumer consumer = [&skip, &module, &stage_state, this](spv_message_level_t level, const char *source,
2276 const spv_position_t &position,
2277 const char *message) {
2278 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter",
2279 "%s does not contain valid spirv for stage %s. %s",
2280 report_data->FormatHandle(module->vk_shader_module()).c_str(),
2281 string_VkShaderStageFlagBits(stage_state.stage_flag), message);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002282 };
2283 optimizer.SetMessageConsumer(consumer);
2284 optimizer.RegisterPass(spvtools::CreateSetSpecConstantDefaultValuePass(id_value_map));
2285 optimizer.RegisterPass(spvtools::CreateFreezeSpecConstantValuePass());
2286 std::vector<uint32_t> specialized_spirv;
Nathaniel Cesario0b2a6422021-07-13 16:04:57 -06002287 auto const optimized = optimizer.Run(module->words.data(), module->words.size(), &specialized_spirv);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002288 assert(optimized == true);
2289
2290 if (optimized) {
2291 spv_context ctx = spvContextCreate(spirv_environment);
2292 spv_const_binary_t binary{specialized_spirv.data(), specialized_spirv.size()};
2293 spv_diagnostic diag = nullptr;
Tony-LunarG9fe69a42020-07-23 15:09:37 -06002294 spvtools::ValidatorOptions options;
2295 AdjustValidatorOptions(device_extensions, enabled_features, options);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002296 auto const spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag);
2297 if (spv_valid != SPV_SUCCESS) {
sfricke-samsungd3793802020-08-18 22:55:03 -07002298 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-04145",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002299 "After specialization was applied, %s does not contain valid spirv for stage %s.",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002300 report_data->FormatHandle(module->vk_shader_module()).c_str(),
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002301 string_VkShaderStageFlagBits(stage_state.stage_flag));
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002302 }
2303
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002304 spvDiagnosticDestroy(diag);
2305 spvContextDestroy(ctx);
2306 }
ziga-lunarg2818f492021-08-12 14:30:51 +02002307
2308 skip |= ValidateWorkgroupSize(module, pStage, id_value_map);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002309 }
2310
John Zulauf14c355b2019-06-27 16:09:37 -06002311 // Check the entrypoint
2312 if (entrypoint == module->end()) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002313 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-pName-00707", "No entrypoint found named `%s` for stage %s.",
2314 pStage->pName, string_VkShaderStageFlagBits(stage_state.stage_flag));
John Zulauf14c355b2019-06-27 16:09:37 -06002315 }
2316 if (skip) return true; // no point continuing beyond here, any analysis is just going to be garbage.
2317
2318 // Mark accessible ids
2319 auto &accessible_ids = stage_state.accessible_ids;
2320
Chris Forbes47567b72017-06-09 12:09:45 -07002321 // Validate descriptor set layout against what the entrypoint actually uses
Chris Forbes47567b72017-06-09 12:09:45 -07002322
sfricke-samsung94167ca2021-02-26 04:14:59 -08002323 // The following tries to limit the number of passes through the shader module. The validation passes in here are "stateless"
2324 // and mainly only checking the instruction in detail for a single operation
ziga-lunarga26b3602021-08-08 15:53:00 +02002325 uint32_t total_shared_size = 0;
sfricke-samsung94167ca2021-02-26 04:14:59 -08002326 for (auto insn : *module) {
ziga-lunargce66e542021-09-19 00:11:14 +02002327 skip |= ValidateTransformFeedback(module, insn);
ziga-lunarga12c75a2021-09-16 16:36:16 +02002328 skip |= ValidateTexelGatherOffset(module, insn);
sfricke-samsung94167ca2021-02-26 04:14:59 -08002329 skip |= ValidateShaderCapabilitiesAndExtensions(module, insn);
sfricke-samsung306dc4c2021-09-20 15:25:18 -07002330 skip |= ValidateShaderClock(module, insn);
sfricke-samsung94167ca2021-02-26 04:14:59 -08002331 skip |= ValidateShaderStageGroupNonUniform(module, pStage->stage, insn);
ziga-lunarga26b3602021-08-08 15:53:00 +02002332 total_shared_size += module->CalcComputeSharedMemory(pStage->stage, insn);
2333 }
2334
2335 if (total_shared_size > phys_dev_props.limits.maxComputeSharedMemorySize) {
2336 skip |= LogError(device, kVUID_Core_Shader_MaxComputeSharedMemorySize,
ziga-lunarg76a2e6c2021-08-08 15:55:03 +02002337 "Shader uses %" PRIu32 " bytes of shared memory, more than allowed by physicalDeviceLimits::maxComputeSharedMemorySize (%" PRIu32 ")",
ziga-lunarga26b3602021-08-08 15:53:00 +02002338 total_shared_size, phys_dev_props.limits.maxComputeSharedMemorySize);
sfricke-samsung94167ca2021-02-26 04:14:59 -08002339 }
2340
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002341 skip |= ValidateShaderStageWritableOrAtomicDescriptor(pStage->stage, stage_state.has_writable_descriptor,
2342 stage_state.has_atomic_descriptor);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002343 skip |= ValidateShaderStageInputOutputLimits(module, pStage, pipeline, entrypoint);
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03002344 skip |= ValidateShaderStorageImageFormats(module);
sfricke-samsungdc96f302020-03-18 20:42:10 -07002345 skip |= ValidateShaderStageMaxResources(pStage->stage, pipeline);
sfricke-samsung58b84352021-07-31 21:41:04 -07002346 skip |= ValidateAtomicsTypes(module);
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00002347 skip |= ValidateExecutionModes(module, entrypoint);
ziga-lunargae2a5c42021-07-23 16:18:09 +02002348 skip |= ValidateSpecializations(pStage);
ziga-lunargce66e542021-09-19 00:11:14 +02002349 skip |= ValidateDecorations(module);
Jeremy Gebben11af9792021-08-20 10:20:09 -06002350 if (check_point_size && !pipeline->create_info.graphics.pRasterizationState->rasterizerDiscardEnable) {
Mark Lobodzinski518eadc2019-03-09 12:07:30 -07002351 skip |= ValidatePointListShaderState(pipeline, module, entrypoint, pStage->stage);
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002352 }
sfricke-samsungcfb44592021-07-25 00:36:28 -07002353 skip |= ValidateBuiltinLimits(module, entrypoint);
sfricke-samsungd093e522021-02-26 04:17:45 -08002354 if (enabled_features.cooperative_matrix_features.cooperativeMatrix) {
2355 skip |= ValidateCooperativeMatrix(module, pStage, pipeline);
2356 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00002357 if (enabled_features.fragment_shading_rate_features.primitiveFragmentShadingRate) {
2358 skip |= ValidatePrimitiveRateShaderState(pipeline, module, entrypoint, pStage->stage);
2359 }
sfricke-samsung45996a42021-09-16 13:45:27 -07002360 if (IsExtEnabled(device_extensions.vk_qcom_render_pass_shader_resolve)) {
Jeff Leger9b3dcff2021-05-27 15:40:20 -04002361 skip |= ValidateShaderResolveQCOM(module, pStage, pipeline);
2362 }
ziga-lunarg73163742021-08-25 13:15:29 +02002363 if (IsExtEnabled(device_extensions.vk_ext_subgroup_size_control)) {
2364 skip |= ValidateShaderSubgroupSizeControl(pStage);
2365 }
Chris Forbes47567b72017-06-09 12:09:45 -07002366
sfricke-samsung7699b912021-04-12 23:01:51 -07002367 // "layout must be consistent with the layout of the * shader"
2368 // 'consistent' -> #descriptorsets-pipelinelayout-consistency
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002369 std::string vuid_layout_mismatch;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002370 switch (pipeline->create_info.graphics.sType) {
2371 case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
2372 vuid_layout_mismatch = "VUID-VkGraphicsPipelineCreateInfo-layout-00756";
2373 break;
2374 case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
2375 vuid_layout_mismatch = "VUID-VkComputePipelineCreateInfo-layout-00703";
2376 break;
2377 case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR:
2378 vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoKHR-layout-03427";
2379 break;
2380 case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV:
2381 vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoNV-layout-03427";
2382 break;
2383 default:
2384 assert(false);
2385 break;
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002386 }
2387
sfricke-samsung7699b912021-04-12 23:01:51 -07002388 // Validate Push Constants use
2389 skip |= ValidatePushConstantUsage(*pipeline, module, pStage, vuid_layout_mismatch);
2390
Chris Forbes47567b72017-06-09 12:09:45 -07002391 // Validate descriptor use
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002392 for (auto use : stage_state.descriptor_uses) {
Chris Forbes47567b72017-06-09 12:09:45 -07002393 // Verify given pipelineLayout has requested setLayout with requested binding
Jeff Bolze7fc67b2019-10-04 12:29:31 -05002394 const auto &binding = GetDescriptorBinding(pipeline->pipeline_layout.get(), use.first);
Chris Forbes47567b72017-06-09 12:09:45 -07002395 unsigned required_descriptor_count;
sourav parmarcd5fb182020-07-17 12:58:44 -07002396 bool is_khr = binding && binding->descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
2397 std::set<uint32_t> descriptor_types =
2398 TypeToDescriptorTypeSet(module, use.second.type_id, required_descriptor_count, is_khr);
Chris Forbes47567b72017-06-09 12:09:45 -07002399
2400 if (!binding) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002401 skip |= LogError(device, vuid_layout_mismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002402 "Shader uses descriptor slot %u.%u (expected `%s`) but not declared in pipeline layout",
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002403 use.first.set, use.first.binding, string_descriptorTypes(descriptor_types).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -07002404 } else if (~binding->stageFlags & pStage->stage) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002405 skip |= LogError(device, vuid_layout_mismatch,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002406 "Shader uses descriptor slot %u.%u but descriptor not accessible from stage %s", use.first.set,
2407 use.first.binding, string_VkShaderStageFlagBits(pStage->stage));
Tony-LunarGf563b362021-03-18 16:13:18 -06002408 } else if ((binding->descriptorType != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE) &&
2409 (descriptor_types.find(binding->descriptorType) == descriptor_types.end())) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002410 skip |= LogError(device, vuid_layout_mismatch,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002411 "Type mismatch on descriptor slot %u.%u (expected `%s`) but descriptor of type %s", use.first.set,
2412 use.first.binding, string_descriptorTypes(descriptor_types).c_str(),
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002413 string_VkDescriptorType(binding->descriptorType));
Chris Forbes47567b72017-06-09 12:09:45 -07002414 } else if (binding->descriptorCount < required_descriptor_count) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002415 skip |= LogError(device, vuid_layout_mismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002416 "Shader expects at least %u descriptors for binding %u.%u but only %u provided",
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002417 required_descriptor_count, use.first.set, use.first.binding, binding->descriptorCount);
Chris Forbes47567b72017-06-09 12:09:45 -07002418 }
2419 }
2420
2421 // Validate use of input attachments against subpass structure
2422 if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
sfricke-samsung962cad92021-04-13 00:46:29 -07002423 auto input_attachment_uses = module->CollectInterfaceByInputAttachmentIndex(accessible_ids);
Chris Forbes47567b72017-06-09 12:09:45 -07002424
Petr Krause91f7a12017-12-14 20:57:36 +01002425 auto rpci = pipeline->rp_state->createInfo.ptr();
Jeremy Gebben11af9792021-08-20 10:20:09 -06002426 auto subpass = pipeline->create_info.graphics.subpass;
Chris Forbes47567b72017-06-09 12:09:45 -07002427
2428 for (auto use : input_attachment_uses) {
2429 auto input_attachments = rpci->pSubpasses[subpass].pInputAttachments;
2430 auto index = (input_attachments && use.first < rpci->pSubpasses[subpass].inputAttachmentCount)
Dave Houltona9df0ce2018-02-07 10:51:23 -07002431 ? input_attachments[use.first].attachment
2432 : VK_ATTACHMENT_UNUSED;
Chris Forbes47567b72017-06-09 12:09:45 -07002433
2434 if (index == VK_ATTACHMENT_UNUSED) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002435 skip |= LogError(device, kVUID_Core_Shader_MissingInputAttachment,
2436 "Shader consumes input attachment index %d but not provided in subpass", use.first);
sfricke-samsung962cad92021-04-13 00:46:29 -07002437 } else if (!(GetFormatType(rpci->pAttachments[index].format) & module->GetFundamentalType(use.second.type_id))) {
Chris Forbes47567b72017-06-09 12:09:45 -07002438 skip |=
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002439 LogError(device, kVUID_Core_Shader_InputAttachmentTypeMismatch,
2440 "Subpass input attachment %u format of %s does not match type used in shader `%s`", use.first,
sfricke-samsung962cad92021-04-13 00:46:29 -07002441 string_VkFormat(rpci->pAttachments[index].format), module->DescribeType(use.second.type_id).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -07002442 }
2443 }
2444 }
Lockeaa8fdc02019-04-02 11:59:20 -06002445 if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT) {
ziga-lunarg11fecb92021-09-20 16:48:06 +02002446 skip |= ValidateComputeWorkGroupSizes(module, entrypoint, stage_state);
Lockeaa8fdc02019-04-02 11:59:20 -06002447 }
ziga-lunarg73163742021-08-25 13:15:29 +02002448
Chris Forbes47567b72017-06-09 12:09:45 -07002449 return skip;
2450}
2451
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -07002452bool CoreChecks::ValidateInterfaceBetweenStages(SHADER_MODULE_STATE const *producer, spirv_inst_iter producer_entrypoint,
2453 shader_stage_attributes const *producer_stage, SHADER_MODULE_STATE const *consumer,
2454 spirv_inst_iter consumer_entrypoint,
2455 shader_stage_attributes const *consumer_stage) const {
Chris Forbes47567b72017-06-09 12:09:45 -07002456 bool skip = false;
2457
2458 auto outputs =
sfricke-samsung962cad92021-04-13 00:46:29 -07002459 producer->CollectInterfaceByLocation(producer_entrypoint, spv::StorageClassOutput, producer_stage->arrayed_output);
2460 auto inputs = consumer->CollectInterfaceByLocation(consumer_entrypoint, spv::StorageClassInput, consumer_stage->arrayed_input);
Chris Forbes47567b72017-06-09 12:09:45 -07002461
2462 auto a_it = outputs.begin();
2463 auto b_it = inputs.begin();
2464
ziga-lunarg8346fe82021-08-22 17:30:50 +02002465 uint32_t a_component = 0;
2466 uint32_t b_component = 0;
2467
Chris Forbes47567b72017-06-09 12:09:45 -07002468 // Maps sorted by key (location); walk them together to find mismatches
2469 while ((outputs.size() > 0 && a_it != outputs.end()) || (inputs.size() && b_it != inputs.end())) {
2470 bool a_at_end = outputs.size() == 0 || a_it == outputs.end();
2471 bool b_at_end = inputs.size() == 0 || b_it == inputs.end();
2472 auto a_first = a_at_end ? std::make_pair(0u, 0u) : a_it->first;
2473 auto b_first = b_at_end ? std::make_pair(0u, 0u) : b_it->first;
2474
ziga-lunarg8346fe82021-08-22 17:30:50 +02002475 a_first.second += a_component;
2476 b_first.second += b_component;
2477
2478 const auto a_length = a_at_end ? 0 : producer->GetNumComponentsInBaseType(producer->get_def(a_it->second.type_id));
2479 const auto b_length = b_at_end ? 0 : consumer->GetNumComponentsInBaseType(consumer->get_def(b_it->second.type_id));
2480 assert(a_at_end || a_component < a_length);
2481 assert(b_at_end || b_component < b_length);
2482
Chris Forbes47567b72017-06-09 12:09:45 -07002483 if (b_at_end || ((!a_at_end) && (a_first < b_first))) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002484 skip |= LogPerformanceWarning(producer->vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed,
ziga-lunarg8346fe82021-08-22 17:30:50 +02002485 "%s writes to output location %" PRIu32 ".%" PRIu32 " which is not consumed by %s",
2486 producer_stage->name, a_first.first, a_first.second, consumer_stage->name);
2487 if ((b_first.first > a_first.first) || b_at_end || (a_component + 1 == a_length)) {
2488 a_it++;
2489 a_component = 0;
2490 } else {
2491 a_component++;
2492 }
Chris Forbes47567b72017-06-09 12:09:45 -07002493 } else if (a_at_end || a_first > b_first) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002494 skip |= LogError(consumer->vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
ziga-lunarg8346fe82021-08-22 17:30:50 +02002495 "%s consumes input location %" PRIu32 ".%" PRIu32 " which is not written by %s", consumer_stage->name,
2496 b_first.first, b_first.second, producer_stage->name);
2497 if ((a_first.first > b_first.first) || a_at_end || (b_component + 1 == b_length)) {
2498 b_it++;
2499 b_component = 0;
2500 } else {
2501 b_component++;
2502 }
Chris Forbes47567b72017-06-09 12:09:45 -07002503 } else {
2504 // subtleties of arrayed interfaces:
2505 // - if is_patch, then the member is not arrayed, even though the interface may be.
2506 // - if is_block_member, then the extra array level of an arrayed interface is not
2507 // expressed in the member type -- it's expressed in the block type.
ziga-lunarg8346fe82021-08-22 17:30:50 +02002508 if (!TypesMatch(producer, consumer, a_it->second.type_id, b_it->second.type_id)) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002509 skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
ziga-lunarg8346fe82021-08-22 17:30:50 +02002510 "Type mismatch on location %" PRIu32 ".%" PRIu32 ": '%s' vs '%s'", a_first.first, a_first.second,
sfricke-samsung962cad92021-04-13 00:46:29 -07002511 producer->DescribeType(a_it->second.type_id).c_str(),
2512 consumer->DescribeType(b_it->second.type_id).c_str());
ziga-lunarg8346fe82021-08-22 17:30:50 +02002513 a_it++;
2514 b_it++;
2515 continue;
Chris Forbes47567b72017-06-09 12:09:45 -07002516 }
2517 if (a_it->second.is_patch != b_it->second.is_patch) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002518 skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002519 "Decoration mismatch on location %u.%u: is per-%s in %s stage but per-%s in %s stage",
2520 a_first.first, a_first.second, a_it->second.is_patch ? "patch" : "vertex", producer_stage->name,
2521 b_it->second.is_patch ? "patch" : "vertex", consumer_stage->name);
Chris Forbes47567b72017-06-09 12:09:45 -07002522 }
2523 if (a_it->second.is_relaxed_precision != b_it->second.is_relaxed_precision) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002524 skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
ziga-lunarg8346fe82021-08-22 17:30:50 +02002525 "Decoration mismatch on location %" PRIu32 ".%" PRIu32 ": %s and %s stages differ in precision",
2526 a_first.first, a_first.second, producer_stage->name, consumer_stage->name);
Chris Forbes47567b72017-06-09 12:09:45 -07002527 }
ziga-lunarg8346fe82021-08-22 17:30:50 +02002528 uint32_t a_remaining = a_length - a_component;
2529 uint32_t b_remaining = b_length - b_component;
2530 if (a_remaining == b_remaining) { // Sizes match so we can advance both a_it and b_it
2531 a_it++;
2532 b_it++;
2533 a_component = 0;
2534 b_component = 0;
2535 } else if (a_remaining > b_remaining) { // a has more components remaining
2536 a_component += b_remaining;
2537 b_component = 0;
2538 b_it++;
2539 } else if (b_remaining > a_remaining) { // b has more components remaining
2540 b_component += a_remaining;
2541 a_component = 0;
2542 a_it++;
2543 }
Chris Forbes47567b72017-06-09 12:09:45 -07002544 }
2545 }
2546
Ari Suonpaa696b3432019-03-11 14:02:57 +02002547 if (consumer_stage->stage != VK_SHADER_STAGE_FRAGMENT_BIT) {
sfricke-samsung962cad92021-04-13 00:46:29 -07002548 auto builtins_producer = producer->CollectBuiltinBlockMembers(producer_entrypoint, spv::StorageClassOutput);
2549 auto builtins_consumer = consumer->CollectBuiltinBlockMembers(consumer_entrypoint, spv::StorageClassInput);
Ari Suonpaa696b3432019-03-11 14:02:57 +02002550
2551 if (!builtins_producer.empty() && !builtins_consumer.empty()) {
2552 if (builtins_producer.size() != builtins_consumer.size()) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002553 skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002554 "Number of elements inside builtin block differ between stages (%s %d vs %s %d).",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002555 producer_stage->name, static_cast<int>(builtins_producer.size()), consumer_stage->name,
2556 static_cast<int>(builtins_consumer.size()));
Ari Suonpaa696b3432019-03-11 14:02:57 +02002557 } else {
2558 auto it_producer = builtins_producer.begin();
2559 auto it_consumer = builtins_consumer.begin();
2560 while (it_producer != builtins_producer.end() && it_consumer != builtins_consumer.end()) {
2561 if (*it_producer != *it_consumer) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002562 skip |= LogError(producer->vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002563 "Builtin variable inside block doesn't match between %s and %s.", producer_stage->name,
2564 consumer_stage->name);
Ari Suonpaa696b3432019-03-11 14:02:57 +02002565 break;
2566 }
2567 it_producer++;
2568 it_consumer++;
2569 }
2570 }
2571 }
2572 }
2573
Chris Forbes47567b72017-06-09 12:09:45 -07002574 return skip;
2575}
2576
John Zulauf14c355b2019-06-27 16:09:37 -06002577static inline uint32_t DetermineFinalGeomStage(const PIPELINE_STATE *pipeline, const VkGraphicsPipelineCreateInfo *pCreateInfo) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002578 uint32_t stage_mask = 0;
2579 if (pipeline->topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) {
2580 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
2581 stage_mask |= pCreateInfo->pStages[i].stage;
2582 }
2583 // Determine which shader in which PointSize should be written (the final geometry stage)
Jeff Bolz105d6492018-09-29 15:46:44 -05002584 if (stage_mask & VK_SHADER_STAGE_MESH_BIT_NV) {
2585 stage_mask = VK_SHADER_STAGE_MESH_BIT_NV;
2586 } else if (stage_mask & VK_SHADER_STAGE_GEOMETRY_BIT) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002587 stage_mask = VK_SHADER_STAGE_GEOMETRY_BIT;
2588 } else if (stage_mask & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
2589 stage_mask = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
2590 } else if (stage_mask & VK_SHADER_STAGE_VERTEX_BIT) {
2591 stage_mask = VK_SHADER_STAGE_VERTEX_BIT;
Mark Lobodzinski2c984cc2018-07-31 09:57:46 -06002592 }
2593 }
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002594 return stage_mask;
Mark Lobodzinski2c984cc2018-07-31 09:57:46 -06002595}
2596
Chris Forbes47567b72017-06-09 12:09:45 -07002597// Validate that the shaders used by the given pipeline and store the active_slots
2598// that are actually used by the pipeline into pPipeline->active_slots
John Zulaufac4c6e12019-07-01 16:05:58 -06002599bool CoreChecks::ValidateGraphicsPipelineShaderState(const PIPELINE_STATE *pipeline) const {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002600 const auto create_info = pipeline->create_info.graphics.ptr();
Chris Forbes47567b72017-06-09 12:09:45 -07002601
Chris Forbes47567b72017-06-09 12:09:45 -07002602 bool skip = false;
2603
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002604 uint32_t pointlist_stage_mask = DetermineFinalGeomStage(pipeline, create_info);
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002605
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002606 const PipelineStageState *vertex_stage = nullptr, *fragment_stage = nullptr;
2607 for (auto &stage : pipeline->stage_state) {
2608 skip |= ValidatePipelineShaderStage(pipeline, stage, (pointlist_stage_mask == stage.stage_flag));
2609 if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT) {
2610 vertex_stage = &stage;
2611 }
2612 if (stage.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT) {
2613 fragment_stage = &stage;
2614 }
Chris Forbes47567b72017-06-09 12:09:45 -07002615 }
2616
2617 // if the shader stages are no good individually, cross-stage validation is pointless.
2618 if (skip) return true;
2619
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002620 auto vi = create_info->pVertexInputState;
Chris Forbes47567b72017-06-09 12:09:45 -07002621
2622 if (vi) {
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -07002623 skip |= ValidateViConsistency(vi);
Chris Forbes47567b72017-06-09 12:09:45 -07002624 }
2625
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002626 if (vertex_stage && vertex_stage->module->has_valid_spirv && !IsDynamic(pipeline, VK_DYNAMIC_STATE_VERTEX_INPUT_EXT)) {
2627 skip |= ValidateViAgainstVsInputs(vi, vertex_stage->module.get(), vertex_stage->entrypoint);
Chris Forbes47567b72017-06-09 12:09:45 -07002628 }
2629
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002630 for (size_t i = 1; i < pipeline->stage_state.size(); i++) {
2631 const auto &producer = pipeline->stage_state[i - 1];
2632 const auto &consumer = pipeline->stage_state[i];
2633 assert(producer.module);
2634 if (&producer == fragment_stage) {
2635 break;
2636 }
2637 if (consumer.module) {
2638 if (consumer.module->has_valid_spirv && producer.module->has_valid_spirv) {
2639 auto producer_id = GetShaderStageId(producer.stage_flag);
2640 auto consumer_id = GetShaderStageId(consumer.stage_flag);
2641 skip |=
2642 ValidateInterfaceBetweenStages(producer.module.get(), producer.entrypoint, &shader_stage_attribs[producer_id],
2643 consumer.module.get(), consumer.entrypoint, &shader_stage_attribs[consumer_id]);
Chris Forbesdbb43fc2018-02-16 16:59:23 -08002644 }
Chris Forbes47567b72017-06-09 12:09:45 -07002645
Chris Forbes47567b72017-06-09 12:09:45 -07002646 }
2647 }
2648
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002649 if (fragment_stage && fragment_stage->module->has_valid_spirv) {
2650 skip |= ValidateFsOutputsAgainstRenderPass(fragment_stage->module.get(), fragment_stage->entrypoint, pipeline,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002651 create_info->subpass);
Chris Forbes47567b72017-06-09 12:09:45 -07002652 }
2653
2654 return skip;
2655}
2656
Tony-LunarGb2ded512021-02-02 16:03:30 -07002657void CoreChecks::RecordGraphicsPipelineShaderDynamicState(PIPELINE_STATE *pipeline_state) {
Tony-LunarGb2ded512021-02-02 16:03:30 -07002658 if (phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports ||
2659 !IsDynamic(pipeline_state, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT)) {
2660 return;
2661 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00002662
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002663 for (auto &stage : pipeline_state->stage_state) {
2664 if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage.stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT ||
2665 stage.stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) {
Tony-LunarGb2ded512021-02-02 16:03:30 -07002666 bool primitiverate_written = false;
Tobias Hector6663c9b2020-11-05 10:18:02 +00002667
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06002668 for (const auto &set : stage.module->GetBuiltinDecorationList()) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002669 auto insn = stage.module->at(set.offset);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002670 if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002671 primitiverate_written = stage.module->IsBuiltInWritten(insn, stage.entrypoint);
Tobias Hector6663c9b2020-11-05 10:18:02 +00002672 }
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002673 if (primitiverate_written) {
2674 break;
2675 }
Tony-LunarGb2ded512021-02-02 16:03:30 -07002676 }
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002677
Tony-LunarGb2ded512021-02-02 16:03:30 -07002678 if (primitiverate_written) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002679 pipeline_state->wrote_primitive_shading_rate.insert(stage.stage_flag);
Tony-LunarGb2ded512021-02-02 16:03:30 -07002680 }
2681 }
2682 }
2683}
2684
2685bool CoreChecks::ValidateGraphicsPipelineShaderDynamicState(const PIPELINE_STATE *pipeline, const CMD_BUFFER_STATE *pCB,
2686 const char *caller, const DrawDispatchVuid &vuid) const {
Tony-LunarGb2ded512021-02-02 16:03:30 -07002687 bool skip = false;
2688
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002689 for (auto &stage : pipeline->stage_state) {
2690 if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage.stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT ||
2691 stage.stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) {
Tony-LunarGb2ded512021-02-02 16:03:30 -07002692 if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports &&
2693 IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) && pCB->viewportWithCountCount != 1) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002694 if (pipeline->wrote_primitive_shading_rate.find(stage.stage_flag) != pipeline->wrote_primitive_shading_rate.end()) {
Tobias Hector6663c9b2020-11-05 10:18:02 +00002695 skip |=
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002696 LogError(pipeline->pipeline(), vuid.viewport_count_primitive_shading_rate,
Tobias Hector6663c9b2020-11-05 10:18:02 +00002697 "%s: %s shader of currently bound pipeline statically writes to PrimitiveShadingRateKHR built-in"
2698 "but multiple viewports are set by the last call to vkCmdSetViewportWithCountEXT,"
2699 "and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002700 caller, string_VkShaderStageFlagBits(stage.stage_flag));
Tobias Hector6663c9b2020-11-05 10:18:02 +00002701 }
2702 }
2703 }
2704 }
2705
2706 return skip;
2707}
2708
sfricke-samsunge72a85e2020-02-29 21:48:37 -08002709bool CoreChecks::ValidateComputePipelineShaderState(PIPELINE_STATE *pipeline) const {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002710 return ValidatePipelineShaderStage(pipeline, pipeline->stage_state[0], false);
Chris Forbes47567b72017-06-09 12:09:45 -07002711}
Chris Forbes4ae55b32017-06-09 14:42:56 -07002712
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002713uint32_t CoreChecks::CalcShaderStageCount(const PIPELINE_STATE *pipeline, VkShaderStageFlagBits stageBit) const {
2714 uint32_t total = 0;
Jeremy Gebben11af9792021-08-20 10:20:09 -06002715 const auto &create_info = pipeline->create_info.raytracing;
2716 const auto *stages = create_info.ptr()->pStages;
2717 for (uint32_t stage_index = 0; stage_index < create_info.stageCount; stage_index++) {
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002718 if (stages[stage_index].stage == stageBit) {
2719 total++;
2720 }
2721 }
2722
Jeremy Gebben11af9792021-08-20 10:20:09 -06002723 if (create_info.pLibraryInfo) {
2724 for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) {
2725 const PIPELINE_STATE *library_pipeline = GetPipelineState(create_info.pLibraryInfo->pLibraries[i]);
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002726 total += CalcShaderStageCount(library_pipeline, stageBit);
2727 }
2728 }
2729
2730 return total;
2731}
2732
Sebastian Neubauer7c826172021-10-04 12:05:51 +02002733bool CoreChecks::GroupHasValidIndex(const PIPELINE_STATE *pipeline, uint32_t group, uint32_t stage) const {
2734 if (group == VK_SHADER_UNUSED_NV) {
2735 return true;
2736 }
2737
2738 const auto &create_info = pipeline->create_info.raytracing;
2739 const auto *stages = create_info.ptr()->pStages;
2740
2741 if (group < create_info.stageCount) {
2742 return (stages[group].stage & stage) != 0;
2743 }
2744 group -= create_info.stageCount;
2745
2746 // Search libraries
2747 if (create_info.pLibraryInfo) {
2748 for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) {
2749 const PIPELINE_STATE *library_pipeline = GetPipelineState(create_info.pLibraryInfo->pLibraries[i]);
2750 const uint32_t stage_count = library_pipeline->create_info.raytracing.ptr()->stageCount;
2751 if (group < stage_count) {
2752 return (library_pipeline->create_info.raytracing.ptr()->pStages[group].stage & stage) != 0;
2753 }
2754 group -= stage_count;
2755 }
2756 }
2757
2758 // group index too large
2759 return false;
2760}
2761
sourav parmarcd5fb182020-07-17 12:58:44 -07002762bool CoreChecks::ValidateRayTracingPipeline(PIPELINE_STATE *pipeline, VkPipelineCreateFlags flags, bool isKHR) const {
John Zulaufe4474e72019-07-01 17:28:27 -06002763 bool skip = false;
Jason Macnak15f95e82019-08-21 21:52:02 -04002764
Jeremy Gebben11af9792021-08-20 10:20:09 -06002765 const auto &create_info = pipeline->create_info.raytracing;
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002766 if (isKHR) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002767 if (create_info.maxPipelineRayRecursionDepth > phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth) {
2768 skip |=
2769 LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-maxPipelineRayRecursionDepth-03589",
2770 "vkCreateRayTracingPipelinesKHR: maxPipelineRayRecursionDepth (%d ) must be less than or equal to "
2771 "VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxRayRecursionDepth %d",
2772 create_info.maxPipelineRayRecursionDepth, phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002773 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06002774 if (create_info.pLibraryInfo) {
2775 for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) {
2776 const PIPELINE_STATE *library_pipelinestate = GetPipelineState(create_info.pLibraryInfo->pLibraries[i]);
2777 const auto &library_create_info = library_pipelinestate->create_info.raytracing;
2778 if (library_create_info.maxPipelineRayRecursionDepth != create_info.maxPipelineRayRecursionDepth) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002779 skip |= LogError(
2780 device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraries-03591",
2781 "vkCreateRayTracingPipelinesKHR: Each element (%d) of the pLibraries member of libraries must have been"
2782 "created with the value of maxPipelineRayRecursionDepth (%d) equal to that in this pipeline (%d) .",
Jeremy Gebben11af9792021-08-20 10:20:09 -06002783 i, library_create_info.maxPipelineRayRecursionDepth, create_info.maxPipelineRayRecursionDepth);
sourav parmarcd5fb182020-07-17 12:58:44 -07002784 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06002785 if (library_create_info.pLibraryInfo && (library_create_info.pLibraryInterface->maxPipelineRayHitAttributeSize !=
2786 create_info.pLibraryInterface->maxPipelineRayHitAttributeSize ||
2787 library_create_info.pLibraryInterface->maxPipelineRayPayloadSize !=
2788 create_info.pLibraryInterface->maxPipelineRayPayloadSize)) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002789 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraryInfo-03593",
2790 "vkCreateRayTracingPipelinesKHR: If pLibraryInfo is not NULL, each element of its pLibraries "
2791 "member must have been created with values of the maxPipelineRayPayloadSize and "
2792 "maxPipelineRayHitAttributeSize members of pLibraryInterface equal to those in this pipeline");
2793 }
2794 if ((flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR) &&
Jeremy Gebben11af9792021-08-20 10:20:09 -06002795 !(library_create_info.flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR)) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002796 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03594",
2797 "vkCreateRayTracingPipelinesKHR: If flags includes "
2798 "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR, each element of "
2799 "the pLibraries member of libraries must have been created with the "
2800 "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR bit set");
2801 }
sourav parmar83c31b12020-05-06 12:30:54 -07002802 }
2803 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002804 } else {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002805 if (create_info.maxRecursionDepth > phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth) {
sourav parmarcd5fb182020-07-17 12:58:44 -07002806 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-maxRecursionDepth-03457",
2807 "vkCreateRayTracingPipelinesNV: maxRecursionDepth (%d) must be less than or equal to "
2808 "VkPhysicalDeviceRayTracingPropertiesNV::maxRecursionDepth (%d)",
Jeremy Gebben11af9792021-08-20 10:20:09 -06002809 create_info.maxRecursionDepth, phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002810 }
Jason Macnak15f95e82019-08-21 21:52:02 -04002811 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06002812 const auto *groups = create_info.ptr()->pGroups;
Jason Macnak15f95e82019-08-21 21:52:02 -04002813
Jeremy Gebben11af9792021-08-20 10:20:09 -06002814 for (uint32_t stage_index = 0; stage_index < create_info.stageCount; stage_index++) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002815 skip |= ValidatePipelineShaderStage(pipeline, pipeline->stage_state[stage_index], false);
Jason Macnak15f95e82019-08-21 21:52:02 -04002816 }
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002817
Jeremy Gebben11af9792021-08-20 10:20:09 -06002818 if ((create_info.flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) == 0) {
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002819 const uint32_t raygen_stages_count = CalcShaderStageCount(pipeline, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
2820 if (raygen_stages_count == 0) {
2821 skip |= LogError(
2822 device,
Mike Schuchardt7b152fa2021-08-03 16:30:27 -07002823 isKHR ? "VUID-VkRayTracingPipelineCreateInfoKHR-stage-03425" : "VUID-VkRayTracingPipelineCreateInfoNV-stage-06232",
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02002824 " : The stage member of at least one element of pStages must be VK_SHADER_STAGE_RAYGEN_BIT_KHR.");
2825 }
Jason Macnak15f95e82019-08-21 21:52:02 -04002826 }
2827
Jeremy Gebben11af9792021-08-20 10:20:09 -06002828 for (uint32_t group_index = 0; group_index < create_info.groupCount; group_index++) {
Jason Macnak15f95e82019-08-21 21:52:02 -04002829 const auto &group = groups[group_index];
2830
2831 if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV) {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02002832 if (!GroupHasValidIndex(
2833 pipeline, group.generalShader,
2834 VK_SHADER_STAGE_RAYGEN_BIT_NV | VK_SHADER_STAGE_MISS_BIT_NV | VK_SHADER_STAGE_CALLABLE_BIT_NV)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002835 skip |= LogError(device,
2836 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03474"
2837 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02413",
2838 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002839 }
2840 if (group.anyHitShader != VK_SHADER_UNUSED_NV || group.closestHitShader != VK_SHADER_UNUSED_NV ||
2841 group.intersectionShader != VK_SHADER_UNUSED_NV) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002842 skip |= LogError(device,
2843 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03475"
2844 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02414",
2845 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002846 }
2847 } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV) {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02002848 if (!GroupHasValidIndex(pipeline, group.intersectionShader, VK_SHADER_STAGE_INTERSECTION_BIT_NV)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002849 skip |= LogError(device,
2850 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03476"
2851 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02415",
2852 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002853 }
2854 } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) {
2855 if (group.intersectionShader != VK_SHADER_UNUSED_NV) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002856 skip |= LogError(device,
2857 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03477"
2858 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02416",
2859 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002860 }
2861 }
2862
2863 if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV ||
2864 group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02002865 if (!GroupHasValidIndex(pipeline, group.anyHitShader, VK_SHADER_STAGE_ANY_HIT_BIT_NV)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002866 skip |= LogError(device,
2867 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-anyHitShader-03479"
2868 : "VUID-VkRayTracingShaderGroupCreateInfoNV-anyHitShader-02418",
2869 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002870 }
Sebastian Neubauer7c826172021-10-04 12:05:51 +02002871 if (!GroupHasValidIndex(pipeline, group.closestHitShader, VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05002872 skip |= LogError(device,
2873 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-closestHitShader-03478"
2874 : "VUID-VkRayTracingShaderGroupCreateInfoNV-closestHitShader-02417",
2875 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04002876 }
2877 }
John Zulaufe4474e72019-07-01 17:28:27 -06002878 }
2879 return skip;
Jeff Bolzfbe51582018-09-13 10:01:35 -05002880}
2881
Dave Houltona9df0ce2018-02-07 10:51:23 -07002882uint32_t ValidationCache::MakeShaderHash(VkShaderModuleCreateInfo const *smci) { return XXH32(smci->pCode, smci->codeSize, 0); }
Chris Forbes9a61e082017-07-24 15:35:29 -07002883
Dave Houltona9df0ce2018-02-07 10:51:23 -07002884static ValidationCache *GetValidationCacheInfo(VkShaderModuleCreateInfo const *pCreateInfo) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002885 const auto validation_cache_ci = LvlFindInChain<VkShaderModuleValidationCacheCreateInfoEXT>(pCreateInfo->pNext);
John Zulauf25ea2432019-04-05 10:07:38 -06002886 if (validation_cache_ci) {
John Zulauf146ee802019-04-05 15:31:06 -06002887 return CastFromHandle<ValidationCache *>(validation_cache_ci->validationCache);
Chris Forbes9a61e082017-07-24 15:35:29 -07002888 }
Chris Forbes9a61e082017-07-24 15:35:29 -07002889 return nullptr;
2890}
2891
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07002892bool CoreChecks::PreCallValidateCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05002893 const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule) const {
Chris Forbes4ae55b32017-06-09 14:42:56 -07002894 bool skip = false;
2895 spv_result_t spv_valid = SPV_SUCCESS;
Chris Forbes4ae55b32017-06-09 14:42:56 -07002896
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06002897 if (disabled[shader_validation]) {
Chris Forbes4ae55b32017-06-09 14:42:56 -07002898 return false;
2899 }
2900
sfricke-samsung45996a42021-09-16 13:45:27 -07002901 auto have_glsl_shader = IsExtEnabled(device_extensions.vk_nv_glsl_shader);
Chris Forbes4ae55b32017-06-09 14:42:56 -07002902
2903 if (!have_glsl_shader && (pCreateInfo->codeSize % 4)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002904 skip |= LogError(device, "VUID-VkShaderModuleCreateInfo-pCode-01376",
2905 "SPIR-V module not valid: Codesize must be a multiple of 4 but is " PRINTF_SIZE_T_SPECIFIER ".",
2906 pCreateInfo->codeSize);
Chris Forbes4ae55b32017-06-09 14:42:56 -07002907 } else {
Chris Forbes9a61e082017-07-24 15:35:29 -07002908 auto cache = GetValidationCacheInfo(pCreateInfo);
2909 uint32_t hash = 0;
Tony-LunarG55fdf1e2021-01-13 14:32:56 -07002910 // If app isn't using a shader validation cache, use the default one from CoreChecks
2911 if (!cache) cache = CastFromHandle<ValidationCache *>(core_validation_cache);
Chris Forbes9a61e082017-07-24 15:35:29 -07002912 if (cache) {
2913 hash = ValidationCache::MakeShaderHash(pCreateInfo);
Dave Houltona9df0ce2018-02-07 10:51:23 -07002914 if (cache->Contains(hash)) return false;
Chris Forbes9a61e082017-07-24 15:35:29 -07002915 }
2916
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002917 // Use SPIRV-Tools validator to try and catch any issues with the module itself. If specialization constants are present,
2918 // the default values will be used during validation.
sfricke-samsung45996a42021-09-16 13:45:27 -07002919 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
Dave Houlton0ea2d012018-06-21 14:00:26 -06002920 spv_context ctx = spvContextCreate(spirv_environment);
Dave Houltona9df0ce2018-02-07 10:51:23 -07002921 spv_const_binary_t binary{pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t)};
Chris Forbes4ae55b32017-06-09 14:42:56 -07002922 spv_diagnostic diag = nullptr;
Tony-LunarG9fe69a42020-07-23 15:09:37 -06002923 spvtools::ValidatorOptions options;
2924 AdjustValidatorOptions(device_extensions, enabled_features, options);
Karl Schultzfda1b382018-08-08 18:56:11 -06002925 spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag);
Chris Forbes4ae55b32017-06-09 14:42:56 -07002926 if (spv_valid != SPV_SUCCESS) {
2927 if (!have_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002928 if (spv_valid == SPV_WARNING) {
2929 skip |= LogWarning(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s",
2930 diag && diag->error ? diag->error : "(no error text)");
2931 } else {
2932 skip |= LogError(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s",
2933 diag && diag->error ? diag->error : "(no error text)");
2934 }
Chris Forbes4ae55b32017-06-09 14:42:56 -07002935 }
Chris Forbes9a61e082017-07-24 15:35:29 -07002936 } else {
2937 if (cache) {
2938 cache->Insert(hash);
2939 }
Chris Forbes4ae55b32017-06-09 14:42:56 -07002940 }
2941
2942 spvDiagnosticDestroy(diag);
2943 spvContextDestroy(ctx);
2944 }
2945
Chris Forbes4ae55b32017-06-09 14:42:56 -07002946 return skip;
Mark Lobodzinski01734072019-02-13 17:39:15 -07002947}
2948
ziga-lunarg11fecb92021-09-20 16:48:06 +02002949bool CoreChecks::ValidateComputeWorkGroupSizes(const SHADER_MODULE_STATE *shader, const spirv_inst_iter &entrypoint,
2950 const PipelineStageState &stage_state) const {
Lockeaa8fdc02019-04-02 11:59:20 -06002951 bool skip = false;
2952 uint32_t local_size_x = 0;
2953 uint32_t local_size_y = 0;
2954 uint32_t local_size_z = 0;
sfricke-samsung962cad92021-04-13 00:46:29 -07002955 if (shader->FindLocalSize(entrypoint, local_size_x, local_size_y, local_size_z)) {
Lockeaa8fdc02019-04-02 11:59:20 -06002956 if (local_size_x > phys_dev_props.limits.maxComputeWorkGroupSize[0]) {
Mike Schuchardt37b8cc12021-10-05 14:31:11 -07002957 skip |= LogError(shader->vk_shader_module(), "VUID-RuntimeSpirv-x-06429",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002958 "%s local_size_x (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[0] (%" PRIu32 ").",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002959 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002960 phys_dev_props.limits.maxComputeWorkGroupSize[0]);
Lockeaa8fdc02019-04-02 11:59:20 -06002961 }
2962 if (local_size_y > phys_dev_props.limits.maxComputeWorkGroupSize[1]) {
Mike Schuchardt37b8cc12021-10-05 14:31:11 -07002963 skip |= LogError(shader->vk_shader_module(), "VUID-RuntimeSpirv-y-06430",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002964 "%s local_size_y (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[1] (%" PRIu32 ").",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002965 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002966 phys_dev_props.limits.maxComputeWorkGroupSize[1]);
Lockeaa8fdc02019-04-02 11:59:20 -06002967 }
2968 if (local_size_z > phys_dev_props.limits.maxComputeWorkGroupSize[2]) {
Mike Schuchardt37b8cc12021-10-05 14:31:11 -07002969 skip |= LogError(shader->vk_shader_module(), "VUID-RuntimeSpirv-z-06431",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002970 "%s local_size_z (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[2] (%" PRIu32 ").",
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002971 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002972 phys_dev_props.limits.maxComputeWorkGroupSize[2]);
Lockeaa8fdc02019-04-02 11:59:20 -06002973 }
2974
2975 uint32_t limit = phys_dev_props.limits.maxComputeWorkGroupInvocations;
2976 uint64_t invocations = local_size_x * local_size_y;
2977 // Prevent overflow.
2978 bool fail = false;
2979 if (invocations > UINT32_MAX || invocations > limit) {
2980 fail = true;
2981 }
2982 if (!fail) {
2983 invocations *= local_size_z;
2984 if (invocations > UINT32_MAX || invocations > limit) {
2985 fail = true;
2986 }
2987 }
2988 if (fail) {
Mike Schuchardt37b8cc12021-10-05 14:31:11 -07002989 skip |= LogError(shader->vk_shader_module(), "VUID-RuntimeSpirv-x-06432",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002990 "%s local_size (%" PRIu32 ", %" PRIu32 ", %" PRIu32
2991 ") exceeds device limit maxComputeWorkGroupInvocations (%" PRIu32 ").",
sfricke-samsung1ff329f2021-09-16 10:06:47 -07002992 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x, local_size_y,
2993 local_size_z, limit);
Lockeaa8fdc02019-04-02 11:59:20 -06002994 }
ziga-lunarg11fecb92021-09-20 16:48:06 +02002995
2996 const auto subgroup_flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT |
2997 VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT;
2998 if ((stage_state.create_info->flags & subgroup_flags) == subgroup_flags) {
2999 if (SafeModulo(local_size_x, phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize) != 0) {
3000 skip |= LogError(
3001 shader->vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-flags-02758",
3002 "%s flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT and "
3003 "VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT bits, but local workgroup size in the X "
3004 "dimension (%" PRIu32
3005 ") is not a multiple of VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::maxSubgroupSize (%" PRIu32 ").",
3006 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x,
3007 phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize);
3008 }
3009 } else if ((stage_state.create_info->flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) &&
3010 (stage_state.create_info->flags & VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) == 0) {
3011 const auto *required_subgroup_size_features =
3012 LvlFindInChain<VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT>(stage_state.create_info->pNext);
3013 if (!required_subgroup_size_features) {
3014 if (SafeModulo(local_size_x, phys_dev_props_core11.subgroupSize) != 0) {
3015 skip |= LogError(
3016 shader->vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-flags-02759",
3017 "%s flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT bit, and not the"
3018 "VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT bit, but local workgroup size in the "
3019 "X dimension (%" PRIu32 ") is not a multiple of VkPhysicalDeviceVulkan11Properties::subgroupSize (%" PRIu32
3020 ").",
3021 report_data->FormatHandle(shader->vk_shader_module()).c_str(), local_size_x,
3022 phys_dev_props_core11.subgroupSize);
3023 }
3024 }
3025 }
Lockeaa8fdc02019-04-02 11:59:20 -06003026 }
3027 return skip;
3028}
Tony-LunarG8a51b7d2020-07-01 15:57:23 -06003029
3030spv_target_env PickSpirvEnv(uint32_t api_version, bool spirv_1_4) {
3031 if (api_version >= VK_API_VERSION_1_2) {
3032 return SPV_ENV_VULKAN_1_2;
3033 } else if (api_version >= VK_API_VERSION_1_1) {
3034 if (spirv_1_4) {
3035 return SPV_ENV_VULKAN_1_1_SPIRV_1_4;
3036 } else {
3037 return SPV_ENV_VULKAN_1_1;
3038 }
3039 }
3040 return SPV_ENV_VULKAN_1_0;
3041}
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003042
sfricke-samsungecc112a2021-09-03 05:32:17 -07003043// Some Vulkan extensions/features are just all done in spirv-val behind optional settings
Jeremy Gebben5d970742021-05-31 16:04:14 -06003044void AdjustValidatorOptions(const DeviceExtensions &device_extensions, const DeviceFeatures &enabled_features,
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003045 spvtools::ValidatorOptions &options) {
sfricke-samsungecc112a2021-09-03 05:32:17 -07003046 // VK_KHR_relaxed_block_layout never had a feature bit so just enabling the extension allows relaxed layout
3047 // Was promotoed in Vulkan 1.1 so anyone using Vulkan 1.1 also gets this for free
sfricke-samsung45996a42021-09-16 13:45:27 -07003048 if (IsExtEnabled(device_extensions.vk_khr_relaxed_block_layout)) {
sfricke-samsungecc112a2021-09-03 05:32:17 -07003049 // --relax-block-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003050 options.SetRelaxBlockLayout(true);
3051 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003052
3053 // The rest of the settings are controlled from a feature bit, which are set correctly in the state tracking. Regardless of
3054 // Vulkan version used, the feature bit is needed (also described in the spec).
3055
3056 if (enabled_features.core12.uniformBufferStandardLayout == VK_TRUE) {
3057 // --uniform-buffer-standard-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003058 options.SetUniformBufferStandardLayout(true);
3059 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003060 if (enabled_features.core12.scalarBlockLayout == VK_TRUE) {
3061 // --scalar-block-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003062 options.SetScalarBlockLayout(true);
3063 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003064 if (enabled_features.workgroup_memory_explicit_layout_features.workgroupMemoryExplicitLayoutScalarBlockLayout) {
3065 // --workgroup-scalar-block-layout
Caio Marcelo de Oliveira Filhod1bfbcd2021-01-27 01:44:04 -08003066 options.SetWorkgroupScalarBlockLayout(true);
3067 }
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003068}