blob: e020b4ba02f2cc3983f1baa4e6bd6d10d7b47340 [file] [log] [blame]
Lionel Landwerlin2d9f5632022-01-08 01:12:47 +02001/* Copyright (c) 2015-2022 The Khronos Group Inc.
2 * Copyright (c) 2015-2022 Valve Corporation
3 * Copyright (c) 2015-2022 LunarG, Inc.
4 * Copyright (C) 2015-2022 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
sjfricke4f600c82022-06-09 14:21:32 +090051static const spirv_inst_iter GetBaseTypeIter(const SHADER_MODULE_STATE &module_state, uint32_t type) {
52 const auto &insn = module_state.get_def(type);
53 const uint32_t base_insn_id = module_state.GetBaseType(insn);
sjfricke6086f792022-08-25 16:38:15 +090054 // Will return end() if an invalid/unknown base_insn_id is returned
sjfricke4f600c82022-06-09 14:21:32 +090055 return module_state.get_def(base_insn_id);
ziga-lunarg19fc6ae2021-09-09 00:05:19 +020056}
57
sjfricke4f600c82022-06-09 14:21:32 +090058static bool BaseTypesMatch(const SHADER_MODULE_STATE &a, const SHADER_MODULE_STATE &b, const spirv_inst_iter &a_base_insn,
ziga-lunarg8346fe82021-08-22 17:30:50 +020059 const spirv_inst_iter &b_base_insn) {
sjfricke6086f792022-08-25 16:38:15 +090060 if (a_base_insn == a.end() || b_base_insn == b.end()) {
61 return false;
62 }
ziga-lunarg8346fe82021-08-22 17:30:50 +020063 const uint32_t a_opcode = a_base_insn.opcode();
64 const uint32_t b_opcode = b_base_insn.opcode();
65 if (a_opcode == b_opcode) {
66 if (a_opcode == spv::OpTypeInt) {
67 // Match width and signedness
68 return a_base_insn.word(2) == b_base_insn.word(2) && a_base_insn.word(3) == b_base_insn.word(3);
69 } else if (a_opcode == spv::OpTypeFloat) {
70 // Match width
71 return a_base_insn.word(2) == b_base_insn.word(2);
sjfricke10f74a82022-08-18 18:12:56 +090072 } else if (a_opcode == spv::OpTypeBool) {
73 return true;
ziga-lunarg8346fe82021-08-22 17:30:50 +020074 } else if (a_opcode == spv::OpTypeStruct) {
75 // Match on all element types
76 if (a_base_insn.len() != b_base_insn.len()) {
77 return false; // Structs cannot match if member counts differ
78 }
79
ziga-lunarg19fc6ae2021-09-09 00:05:19 +020080 for (uint32_t i = 2; i < a_base_insn.len(); i++) {
81 const auto &c_base_insn = GetBaseTypeIter(a, a_base_insn.word(i));
82 const auto &d_base_insn = GetBaseTypeIter(b, b_base_insn.word(i));
83 if (!BaseTypesMatch(a, b, c_base_insn, d_base_insn)) {
ziga-lunarg8346fe82021-08-22 17:30:50 +020084 return false;
85 }
86 }
87
88 return true;
89 }
90 }
91 return false;
Chris Forbes47567b72017-06-09 12:09:45 -070092}
93
sjfricke4f600c82022-06-09 14:21:32 +090094static bool TypesMatch(const SHADER_MODULE_STATE &a, const SHADER_MODULE_STATE &b, uint32_t a_type, uint32_t b_type) {
ziga-lunarg19fc6ae2021-09-09 00:05:19 +020095 const auto &a_base_insn = GetBaseTypeIter(a, a_type);
96 const auto &b_base_insn = GetBaseTypeIter(b, b_type);
Chris Forbes47567b72017-06-09 12:09:45 -070097
ziga-lunarg8346fe82021-08-22 17:30:50 +020098 return BaseTypesMatch(a, b, a_base_insn, b_base_insn);
Chris Forbes47567b72017-06-09 12:09:45 -070099}
100
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800101static uint32_t GetLocationsConsumedByFormat(VkFormat format) {
Chris Forbes47567b72017-06-09 12:09:45 -0700102 switch (format) {
103 case VK_FORMAT_R64G64B64A64_SFLOAT:
104 case VK_FORMAT_R64G64B64A64_SINT:
105 case VK_FORMAT_R64G64B64A64_UINT:
106 case VK_FORMAT_R64G64B64_SFLOAT:
107 case VK_FORMAT_R64G64B64_SINT:
108 case VK_FORMAT_R64G64B64_UINT:
109 return 2;
110 default:
111 return 1;
112 }
113}
114
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800115static uint32_t GetFormatType(VkFormat fmt) {
sfricke-samsunge3086292021-11-18 23:02:35 -0800116 if (FormatIsSINT(fmt)) return FORMAT_TYPE_SINT;
117 if (FormatIsUINT(fmt)) return FORMAT_TYPE_UINT;
sfricke-samsunged028b02021-09-06 23:14:51 -0700118 // Formats such as VK_FORMAT_D16_UNORM_S8_UINT are both
Dave Houltona9df0ce2018-02-07 10:51:23 -0700119 if (FormatIsDepthAndStencil(fmt)) return FORMAT_TYPE_FLOAT | FORMAT_TYPE_UINT;
120 if (fmt == VK_FORMAT_UNDEFINED) return 0;
Chris Forbes47567b72017-06-09 12:09:45 -0700121 // everything else -- UNORM/SNORM/FLOAT/USCALED/SSCALED is all float in the shader.
122 return FORMAT_TYPE_FLOAT;
123}
124
Shannon McPhersonc06c33d2018-06-28 17:21:12 -0600125static uint32_t GetShaderStageId(VkShaderStageFlagBits stage) {
Chris Forbes47567b72017-06-09 12:09:45 -0700126 uint32_t bit_pos = uint32_t(u_ffs(stage));
127 return bit_pos - 1;
128}
129
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700130bool CoreChecks::ValidateViConsistency(safe_VkPipelineVertexInputStateCreateInfo const *vi) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700131 // Walk the binding descriptions, which describe the step rate and stride of each vertex buffer. Each binding should
132 // be specified only once.
Jeremy Gebbencbf22862021-03-03 12:01:22 -0700133 layer_data::unordered_map<uint32_t, VkVertexInputBindingDescription const *> bindings;
Chris Forbes47567b72017-06-09 12:09:45 -0700134 bool skip = false;
135
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800136 for (uint32_t i = 0; i < vi->vertexBindingDescriptionCount; i++) {
Chris Forbes47567b72017-06-09 12:09:45 -0700137 auto desc = &vi->pVertexBindingDescriptions[i];
138 auto &binding = bindings[desc->binding];
139 if (binding) {
Dave Houlton78d09922018-05-17 15:48:45 -0600140 // TODO: "VUID-VkGraphicsPipelineCreateInfo-pStages-00742" perhaps?
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700141 skip |= LogError(device, kVUID_Core_Shader_InconsistentVi, "Duplicate vertex input binding descriptions for binding %d",
142 desc->binding);
Chris Forbes47567b72017-06-09 12:09:45 -0700143 } else {
144 binding = desc;
145 }
146 }
147
148 return skip;
149}
150
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700151bool CoreChecks::ValidateViAgainstVsInputs(safe_VkPipelineVertexInputStateCreateInfo const *vi,
sjfricke4f600c82022-06-09 14:21:32 +0900152 const SHADER_MODULE_STATE &module_state, spirv_inst_iter entrypoint) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700153 bool skip = false;
154
sjfricke4f600c82022-06-09 14:21:32 +0900155 const auto inputs = module_state.CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, false);
Chris Forbes47567b72017-06-09 12:09:45 -0700156
157 // Build index by location
Petr Kraus25810d02019-08-27 17:41:15 +0200158 std::map<uint32_t, const VkVertexInputAttributeDescription *> attribs;
Chris Forbes47567b72017-06-09 12:09:45 -0700159 if (vi) {
Petr Kraus25810d02019-08-27 17:41:15 +0200160 for (uint32_t i = 0; i < vi->vertexAttributeDescriptionCount; ++i) {
161 const auto num_locations = GetLocationsConsumedByFormat(vi->pVertexAttributeDescriptions[i].format);
162 for (uint32_t j = 0; j < num_locations; ++j) {
Chris Forbes47567b72017-06-09 12:09:45 -0700163 attribs[vi->pVertexAttributeDescriptions[i].location + j] = &vi->pVertexAttributeDescriptions[i];
164 }
165 }
166 }
167
Petr Kraus25810d02019-08-27 17:41:15 +0200168 struct AttribInputPair {
169 const VkVertexInputAttributeDescription *attrib = nullptr;
170 const interface_var *input = nullptr;
171 };
172 std::map<uint32_t, AttribInputPair> location_map;
173 for (const auto &attrib_it : attribs) location_map[attrib_it.first].attrib = attrib_it.second;
174 for (const auto &input_it : inputs) location_map[input_it.first.first].input = &input_it.second;
Chris Forbes47567b72017-06-09 12:09:45 -0700175
Jamie Madillc1f7ca82020-03-16 17:08:26 -0400176 for (const auto &location_it : location_map) {
Petr Kraus25810d02019-08-27 17:41:15 +0200177 const auto location = location_it.first;
178 const auto attrib = location_it.second.attrib;
179 const auto input = location_it.second.input;
Mark Lobodzinski7caa39c2018-07-25 15:48:34 -0600180
Petr Kraus25810d02019-08-27 17:41:15 +0200181 if (attrib && !input) {
sjfricke4f600c82022-06-09 14:21:32 +0900182 skip |= LogPerformanceWarning(module_state.vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700183 "Vertex attribute at location %" PRIu32 " not consumed by vertex shader", location);
Petr Kraus25810d02019-08-27 17:41:15 +0200184 } else if (!attrib && input) {
sjfricke4f600c82022-06-09 14:21:32 +0900185 skip |= LogError(module_state.vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700186 "Vertex shader consumes input at location %" PRIu32 " but not provided", location);
Petr Kraus25810d02019-08-27 17:41:15 +0200187 } else if (attrib && input) {
188 const auto attrib_type = GetFormatType(attrib->format);
sjfricke4f600c82022-06-09 14:21:32 +0900189 const auto input_type = module_state.GetFundamentalType(input->type_id);
Chris Forbes47567b72017-06-09 12:09:45 -0700190
191 // Type checking
192 if (!(attrib_type & input_type)) {
sjfricke4f600c82022-06-09 14:21:32 +0900193 skip |= LogError(module_state.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700194 "Attribute type of `%s` at location %" PRIu32 " does not match vertex shader input type of `%s`",
sjfricke4f600c82022-06-09 14:21:32 +0900195 string_VkFormat(attrib->format), location, module_state.DescribeType(input->type_id).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -0700196 }
Petr Kraus25810d02019-08-27 17:41:15 +0200197 } else { // !attrib && !input
198 assert(false); // at least one exists in the map
Chris Forbes47567b72017-06-09 12:09:45 -0700199 }
200 }
201
202 return skip;
203}
204
sjfricke4f600c82022-06-09 14:21:32 +0900205bool CoreChecks::ValidateFsOutputsAgainstDynamicRenderingRenderPass(const SHADER_MODULE_STATE &module_state,
sfricke-samsungef15e482022-01-26 11:32:49 -0800206 spirv_inst_iter entrypoint,
207 PIPELINE_STATE const *pipeline) const {
Aaron Hagan1209c782021-11-22 19:37:14 -0500208 bool skip = false;
209
210 struct Attachment {
211 const interface_var* output = nullptr;
212 };
213 std::map<uint32_t, Attachment> location_map;
214
215 // TODO: dual source blend index (spv::DecIndex, zero if not provided)
sjfricke4f600c82022-06-09 14:21:32 +0900216 const auto outputs = module_state.CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false);
Aaron Hagan1209c782021-11-22 19:37:14 -0500217 for (const auto& output_it : outputs) {
218 auto const location = output_it.first.first;
219 location_map[location].output = &output_it.second;
220 }
221
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700222 const auto ms_state = pipeline->MultisampleState();
223 const bool alpha_to_coverage_enabled = ms_state && (ms_state->alphaToCoverageEnable == VK_TRUE);
Aaron Hagan1209c782021-11-22 19:37:14 -0500224
Aaron Haganaca50442021-12-07 22:26:29 -0500225 for (uint32_t location = 0; location < location_map.size(); ++location) {
Aaron Hagan1209c782021-11-22 19:37:14 -0500226 const auto output = location_map[location].output;
227
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700228 const auto &rp_state = pipeline->RenderPassState();
229 const auto &attachments = pipeline->Attachments();
230 if (!output && location < attachments.size() && attachments[location].colorWriteMask != 0) {
231 skip |= LogWarning(
sjfricke4f600c82022-06-09 14:21:32 +0900232 module_state.vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700233 "Attachment %" PRIu32 " not written by fragment shader; undefined values will be written to attachment", location);
234 } else if (output && (location < rp_state->dynamic_rendering_pipeline_create_info.colorAttachmentCount)) {
235 auto format = rp_state->dynamic_rendering_pipeline_create_info.pColorAttachmentFormats[location];
236 const auto attachment_type = GetFormatType(format);
sjfricke4f600c82022-06-09 14:21:32 +0900237 const auto output_type = module_state.GetFundamentalType(output->type_id);
Aaron Hagan1209c782021-11-22 19:37:14 -0500238
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700239 // Type checking
240 if (!(output_type & attachment_type)) {
241 skip |=
sjfricke4f600c82022-06-09 14:21:32 +0900242 LogWarning(module_state.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700243 "Attachment %" PRIu32
244 " of type `%s` does not match fragment shader output type of `%s`; resulting values are undefined",
sjfricke4f600c82022-06-09 14:21:32 +0900245 location, string_VkFormat(format), module_state.DescribeType(output->type_id).c_str());
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700246 }
247 }
Aaron Hagan1209c782021-11-22 19:37:14 -0500248 }
249
250 const auto output_zero = location_map.count(0) ? location_map[0].output : nullptr;
sjfricke4f600c82022-06-09 14:21:32 +0900251 bool location_zero_has_alpha = output_zero && module_state.get_def(output_zero->type_id) != module_state.end() &&
252 module_state.GetComponentsConsumedByType(output_zero->type_id, false) == 4;
Aaron Hagan1209c782021-11-22 19:37:14 -0500253 if (alpha_to_coverage_enabled && !location_zero_has_alpha) {
sjfricke4f600c82022-06-09 14:21:32 +0900254 skip |= LogError(module_state.vk_shader_module(), kVUID_Core_Shader_NoAlphaAtLocation0WithAlphaToCoverage,
sfricke-samsungef15e482022-01-26 11:32:49 -0800255 "fragment shader doesn't declare alpha output at location 0 even though alpha to coverage is enabled.");
Aaron Hagan1209c782021-11-22 19:37:14 -0500256 }
257
258 return skip;
Aaron Hagan1209c782021-11-22 19:37:14 -0500259}
260
sjfricke4f600c82022-06-09 14:21:32 +0900261bool CoreChecks::ValidateFsOutputsAgainstRenderPass(const SHADER_MODULE_STATE &module_state, spirv_inst_iter entrypoint,
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -0700262 PIPELINE_STATE const *pipeline, uint32_t subpass_index) const {
Petr Kraus25810d02019-08-27 17:41:15 +0200263 bool skip = false;
Chris Forbes8bca1652017-07-20 11:10:09 -0700264
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600265 struct Attachment {
Mike Schuchardt2df08912020-12-15 16:28:09 -0800266 const VkAttachmentReference2 *reference = nullptr;
267 const VkAttachmentDescription2 *attachment = nullptr;
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600268 const interface_var *output = nullptr;
269 };
270 std::map<uint32_t, Attachment> location_map;
271
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700272 const auto &rp_state = pipeline->RenderPassState();
Jeremy Gebbenb5dda542022-08-02 14:26:20 -0600273 if (rp_state && !rp_state->UsesDynamicRendering()) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700274 const auto rpci = rp_state->createInfo.ptr();
amhagana448ea52021-11-02 14:09:14 -0400275 const auto subpass = rpci->pSubpasses[subpass_index];
276 for (uint32_t i = 0; i < subpass.colorAttachmentCount; ++i) {
277 auto const &reference = subpass.pColorAttachments[i];
278 location_map[i].reference = &reference;
279 if (reference.attachment != VK_ATTACHMENT_UNUSED &&
280 rpci->pAttachments[reference.attachment].format != VK_FORMAT_UNDEFINED) {
281 location_map[i].attachment = &rpci->pAttachments[reference.attachment];
282 }
Chris Forbes47567b72017-06-09 12:09:45 -0700283 }
284 }
285
Chris Forbes47567b72017-06-09 12:09:45 -0700286 // TODO: dual source blend index (spv::DecIndex, zero if not provided)
287
sjfricke4f600c82022-06-09 14:21:32 +0900288 const auto outputs = module_state.CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false);
Jeremy Hayes3699c7c2019-10-09 12:24:55 -0600289 for (const auto &output_it : outputs) {
290 auto const location = output_it.first.first;
291 location_map[location].output = &output_it.second;
292 }
Chris Forbes47567b72017-06-09 12:09:45 -0700293
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700294 const auto *ms_state = pipeline->MultisampleState();
295 const bool alpha_to_coverage_enabled = ms_state && (ms_state->alphaToCoverageEnable == VK_TRUE);
Chris Forbes47567b72017-06-09 12:09:45 -0700296
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700297 // Don't check any color attachments if rasterization is disabled
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700298 const auto raster_state = pipeline->RasterizationState();
Nathaniel Cesario81257cb2022-02-16 17:15:58 -0700299 if (raster_state && !raster_state->rasterizerDiscardEnable) {
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700300 for (const auto &location_it : location_map) {
301 const auto reference = location_it.second.reference;
302 if (reference != nullptr && reference->attachment == VK_ATTACHMENT_UNUSED) {
303 continue;
Petr Kraus25810d02019-08-27 17:41:15 +0200304 }
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700305
306 const auto location = location_it.first;
307 const auto attachment = location_it.second.attachment;
308 const auto output = location_it.second.output;
309 if (attachment && !output) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700310 const auto &attachments = pipeline->Attachments();
311 if (location < attachments.size() && attachments[location].colorWriteMask != 0) {
sjfricke4f600c82022-06-09 14:21:32 +0900312 skip |= LogWarning(module_state.vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700313 "Attachment %" PRIu32
314 " not written by fragment shader; undefined values will be written to attachment",
315 location);
316 }
317 } else if (!attachment && output) {
318 if (!(alpha_to_coverage_enabled && location == 0)) {
319 skip |=
sjfricke4f600c82022-06-09 14:21:32 +0900320 LogWarning(module_state.vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700321 "fragment shader writes to output location %" PRIu32 " with no matching attachment", location);
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700322 }
323 } else if (attachment && output) {
324 const auto attachment_type = GetFormatType(attachment->format);
sjfricke4f600c82022-06-09 14:21:32 +0900325 const auto output_type = module_state.GetFundamentalType(output->type_id);
Chris Forbes47567b72017-06-09 12:09:45 -0700326
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700327 // Type checking
328 if (!(output_type & attachment_type)) {
329 skip |= LogWarning(
sjfricke4f600c82022-06-09 14:21:32 +0900330 module_state.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700331 "Attachment %" PRIu32
332 " of type `%s` does not match fragment shader output type of `%s`; resulting values are undefined",
sjfricke4f600c82022-06-09 14:21:32 +0900333 location, string_VkFormat(attachment->format), module_state.DescribeType(output->type_id).c_str());
Nathaniel Cesariobcb86652022-01-27 14:40:20 -0700334 }
335 } else { // !attachment && !output
336 assert(false); // at least one exists in the map
Chris Forbes47567b72017-06-09 12:09:45 -0700337 }
Chris Forbes47567b72017-06-09 12:09:45 -0700338 }
339 }
340
Petr Kraus25810d02019-08-27 17:41:15 +0200341 const auto output_zero = location_map.count(0) ? location_map[0].output : nullptr;
sjfricke4f600c82022-06-09 14:21:32 +0900342 bool location_zero_has_alpha = output_zero && module_state.get_def(output_zero->type_id) != module_state.end() &&
343 module_state.GetComponentsConsumedByType(output_zero->type_id, false) == 4;
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700344 if (alpha_to_coverage_enabled && !location_zero_has_alpha) {
sjfricke4f600c82022-06-09 14:21:32 +0900345 skip |= LogError(module_state.vk_shader_module(), kVUID_Core_Shader_NoAlphaAtLocation0WithAlphaToCoverage,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700346 "fragment shader doesn't declare alpha output at location 0 even though alpha to coverage is enabled.");
Ari Suonpaa412b23b2019-02-26 07:56:58 +0200347 }
348
Chris Forbes47567b72017-06-09 12:09:45 -0700349 return skip;
350}
351
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600352PushConstantByteState CoreChecks::ValidatePushConstantSetUpdate(const std::vector<uint8_t> &push_constant_data_update,
353 const shader_struct_member &push_constant_used_in_shader,
354 uint32_t &out_issue_index) const {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600355 const auto *used_bytes = push_constant_used_in_shader.GetUsedbytes();
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600356 const auto used_bytes_size = used_bytes->size();
357 if (used_bytes_size == 0) return PC_Byte_Updated;
358
359 const auto push_constant_data_update_size = push_constant_data_update.size();
360 const auto *data = push_constant_data_update.data();
361 if ((*data == PC_Byte_Updated) && std::memcmp(data, data + 1, push_constant_data_update_size - 1) == 0) {
362 if (used_bytes_size <= push_constant_data_update_size) {
363 return PC_Byte_Updated;
364 }
365 const auto used_bytes_size1 = used_bytes_size - push_constant_data_update_size;
366
367 const auto *used_bytes_data1 = used_bytes->data() + push_constant_data_update_size;
368 if ((*used_bytes_data1 == 0) && std::memcmp(used_bytes_data1, used_bytes_data1 + 1, used_bytes_size1 - 1) == 0) {
369 return PC_Byte_Updated;
370 }
locke-lunargde3f0fa2020-09-10 11:55:31 -0600371 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600372
locke-lunargde3f0fa2020-09-10 11:55:31 -0600373 uint32_t i = 0;
374 for (const auto used : *used_bytes) {
375 if (used) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600376 if (i >= push_constant_data_update.size() || push_constant_data_update[i] == PC_Byte_Not_Set) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600377 out_issue_index = i;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600378 return PC_Byte_Not_Set;
379 } else if (push_constant_data_update[i] == PC_Byte_Not_Updated) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600380 out_issue_index = i;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600381 return PC_Byte_Not_Updated;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600382 }
383 }
384 ++i;
385 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600386 return PC_Byte_Updated;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600387}
388
sjfricke4f600c82022-06-09 14:21:32 +0900389bool CoreChecks::ValidatePushConstantUsage(const PIPELINE_STATE &pipeline, const SHADER_MODULE_STATE &module_state,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700390 safe_VkPipelineShaderStageCreateInfo const *pStage, const std::string &vuid) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700391 bool skip = false;
sfricke-samsung5c65b372021-03-25 05:39:57 -0700392 // Temp workaround to prevent false positive errors
393 // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2450
sjfricke4f600c82022-06-09 14:21:32 +0900394 if (module_state.HasMultipleEntryPoints()) {
sfricke-samsung5c65b372021-03-25 05:39:57 -0700395 return skip;
396 }
397
Chris Forbes47567b72017-06-09 12:09:45 -0700398 // Validate directly off the offsets. this isn't quite correct for arrays and matrices, but is a good first step.
sjfricke4f600c82022-06-09 14:21:32 +0900399 const auto *entrypoint = module_state.FindEntrypointStruct(pStage->pName, pStage->stage);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600400 if (!entrypoint || !entrypoint->push_constant_used_in_shader.IsUsed()) {
401 return skip;
402 }
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700403 const auto &pipeline_layout = pipeline.PipelineLayoutState();
404 std::vector<VkPushConstantRange> const *push_constant_ranges = pipeline_layout->push_constant_ranges.get();
Chris Forbes47567b72017-06-09 12:09:45 -0700405
locke-lunargde3f0fa2020-09-10 11:55:31 -0600406 bool found_stage = false;
407 for (auto const &range : *push_constant_ranges) {
408 if (range.stageFlags & pStage->stage) {
409 found_stage = true;
410 std::string location_desc;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600411 std::vector<uint8_t> push_constant_bytes_set;
locke-lunargde3f0fa2020-09-10 11:55:31 -0600412 if (range.offset > 0) {
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600413 push_constant_bytes_set.resize(range.offset, PC_Byte_Not_Set);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600414 }
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600415 push_constant_bytes_set.resize(range.offset + range.size, PC_Byte_Updated);
locke-lunargde3f0fa2020-09-10 11:55:31 -0600416 uint32_t issue_index = 0;
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600417 const auto ret =
418 ValidatePushConstantSetUpdate(push_constant_bytes_set, entrypoint->push_constant_used_in_shader, issue_index);
Chris Forbes47567b72017-06-09 12:09:45 -0700419
locke-lunarg3d8b8f32020-10-26 17:04:16 -0600420 if (ret == PC_Byte_Not_Set) {
locke-lunargde3f0fa2020-09-10 11:55:31 -0600421 const auto loc_descr = entrypoint->push_constant_used_in_shader.GetLocationDesc(issue_index);
sjfricke4f600c82022-06-09 14:21:32 +0900422 LogObjectList objlist(module_state.vk_shader_module());
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700423 objlist.add(pipeline_layout->layout());
sfricke-samsung7699b912021-04-12 23:01:51 -0700424 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 -0600425 string_VkShaderStageFlags(pStage->stage).c_str(),
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700426 report_data->FormatHandle(pipeline_layout->layout()).c_str());
locke-lunargde3f0fa2020-09-10 11:55:31 -0600427 break;
Chris Forbes47567b72017-06-09 12:09:45 -0700428 }
429 }
430 }
431
locke-lunargde3f0fa2020-09-10 11:55:31 -0600432 if (!found_stage) {
sjfricke4f600c82022-06-09 14:21:32 +0900433 LogObjectList objlist(module_state.vk_shader_module());
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700434 objlist.add(pipeline_layout->layout());
435 skip |= LogError(
436 objlist, vuid, "Push constant is used in %s of %s. But %s doesn't set %s.",
sjfricke4f600c82022-06-09 14:21:32 +0900437 string_VkShaderStageFlags(pStage->stage).c_str(), report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700438 report_data->FormatHandle(pipeline_layout->layout()).c_str(), string_VkShaderStageFlags(pStage->stage).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -0700439 }
Chris Forbes47567b72017-06-09 12:09:45 -0700440 return skip;
441}
442
sjfricke4f600c82022-06-09 14:21:32 +0900443bool CoreChecks::ValidateBuiltinLimits(const SHADER_MODULE_STATE &module_state, spirv_inst_iter entrypoint) const {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700444 bool skip = false;
445
446 // Currently all builtin tested are only found in fragment shaders
sfricke-samsungcfb44592021-07-25 00:36:28 -0700447 if (entrypoint.word(1) != spv::ExecutionModelFragment) {
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700448 return skip;
449 }
450
sfricke-samsungcfb44592021-07-25 00:36:28 -0700451 // Find all builtin from just the interface variables
452 for (uint32_t id : FindEntrypointInterfaces(entrypoint)) {
sjfricke4f600c82022-06-09 14:21:32 +0900453 auto insn = module_state.get_def(id);
sfricke-samsungcfb44592021-07-25 00:36:28 -0700454 assert(insn.opcode() == spv::OpVariable);
sjfricke4f600c82022-06-09 14:21:32 +0900455 const decoration_set decorations = module_state.get_decorations(insn.word(2));
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700456
sfricke-samsungcfb44592021-07-25 00:36:28 -0700457 // Currently don't need to search in structs
458 if (((decorations.flags & decoration_set::builtin_bit) != 0) && (decorations.builtin == spv::BuiltInSampleMask)) {
sjfricke4f600c82022-06-09 14:21:32 +0900459 auto type_pointer = module_state.get_def(insn.word(1));
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700460 assert(type_pointer.opcode() == spv::OpTypePointer);
461
sjfricke4f600c82022-06-09 14:21:32 +0900462 auto type = module_state.get_def(type_pointer.word(3));
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700463 if (type.opcode() == spv::OpTypeArray) {
sjfricke4f600c82022-06-09 14:21:32 +0900464 uint32_t length = static_cast<uint32_t>(module_state.GetConstantValueById(type.word(3)));
sfricke-samsungcfb44592021-07-25 00:36:28 -0700465 // Handles both the input and output sampleMask
466 if (length > phys_dev_props.limits.maxSampleMaskWords) {
467 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-maxSampleMaskWords-00711",
468 "vkCreateGraphicsPipelines(): The BuiltIns SampleMask array sizes is %u which exceeds "
469 "maxSampleMaskWords of %u in %s.",
470 length, phys_dev_props.limits.maxSampleMaskWords,
sjfricke4f600c82022-06-09 14:21:32 +0900471 report_data->FormatHandle(module_state.vk_shader_module()).c_str());
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700472 }
sfricke-samsungcfb44592021-07-25 00:36:28 -0700473 break;
sfricke-samsungef2a68c2020-10-26 04:22:46 -0700474 }
475 }
476 }
477
478 return skip;
479}
480
Chris Forbes47567b72017-06-09 12:09:45 -0700481// Validate that data for each specialization entry is fully contained within the buffer.
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700482bool CoreChecks::ValidateSpecializations(safe_VkPipelineShaderStageCreateInfo const *info) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700483 bool skip = false;
484
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700485 const auto *spec = info->pSpecializationInfo;
Chris Forbes47567b72017-06-09 12:09:45 -0700486
487 if (spec) {
488 for (auto i = 0u; i < spec->mapEntryCount; i++) {
Jeremy Hayes6c555c32019-09-09 17:14:09 -0600489 if (spec->pMapEntries[i].offset >= spec->dataSize) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700490 skip |= LogError(device, "VUID-VkSpecializationInfo-offset-00773",
491 "Specialization entry %u (for constant id %u) references memory outside provided specialization "
Petr Krausb0d5e592021-05-21 23:37:11 +0200492 "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700493 i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset,
494 spec->pMapEntries[i].offset + spec->dataSize - 1, spec->dataSize);
Jeremy Hayes6c555c32019-09-09 17:14:09 -0600495
496 continue;
497 }
Chris Forbes47567b72017-06-09 12:09:45 -0700498 if (spec->pMapEntries[i].offset + spec->pMapEntries[i].size > spec->dataSize) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700499 skip |= LogError(device, "VUID-VkSpecializationInfo-pMapEntries-00774",
500 "Specialization entry %u (for constant id %u) references memory outside provided specialization "
Petr Krausb0d5e592021-05-21 23:37:11 +0200501 "data (bytes %u.." PRINTF_SIZE_T_SPECIFIER "; " PRINTF_SIZE_T_SPECIFIER " bytes provided).",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700502 i, spec->pMapEntries[i].constantID, spec->pMapEntries[i].offset,
503 spec->pMapEntries[i].offset + spec->pMapEntries[i].size - 1, spec->dataSize);
Chris Forbes47567b72017-06-09 12:09:45 -0700504 }
ziga-lunargae2a5c42021-07-23 16:18:09 +0200505 for (uint32_t j = i + 1; j < spec->mapEntryCount; ++j) {
506 if (spec->pMapEntries[i].constantID == spec->pMapEntries[j].constantID) {
507 skip |= LogError(device, "VUID-VkSpecializationInfo-constantID-04911",
508 "Specialization entry %" PRIu32 " and %" PRIu32 " have the same constantID (%" PRIu32 ").", i,
509 j, spec->pMapEntries[i].constantID);
510 }
511 }
Chris Forbes47567b72017-06-09 12:09:45 -0700512 }
513 }
514
515 return skip;
516}
517
Jeff Bolz38b3ce72018-09-19 12:53:38 -0500518// TODO (jbolz): Can this return a const reference?
sjfricke4f600c82022-06-09 14:21:32 +0900519static std::set<uint32_t> TypeToDescriptorTypeSet(const SHADER_MODULE_STATE &module_state, uint32_t type_id,
sfricke-samsung7fac88a2022-01-26 11:44:22 -0800520 uint32_t &descriptor_count, bool is_khr) {
sjfricke4f600c82022-06-09 14:21:32 +0900521 auto type = module_state.get_def(type_id);
Chris Forbes9f89d752018-03-07 12:57:48 -0800522 bool is_storage_buffer = false;
Chris Forbes47567b72017-06-09 12:09:45 -0700523 descriptor_count = 1;
Jeff Bolze54ae892018-09-08 12:16:29 -0500524 std::set<uint32_t> ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700525
526 // 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 -0500527 while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray) {
528 if (type.opcode() == spv::OpTypeRuntimeArray) {
529 descriptor_count = 0;
sjfricke4f600c82022-06-09 14:21:32 +0900530 type = module_state.get_def(type.word(2));
Jeff Bolzfdf96072018-04-10 14:32:18 -0500531 } else if (type.opcode() == spv::OpTypeArray) {
sjfricke4f600c82022-06-09 14:21:32 +0900532 descriptor_count *= module_state.GetConstantValueById(type.word(3));
533 type = module_state.get_def(type.word(2));
Chris Forbes47567b72017-06-09 12:09:45 -0700534 } else {
Chris Forbes9f89d752018-03-07 12:57:48 -0800535 if (type.word(2) == spv::StorageClassStorageBuffer) {
536 is_storage_buffer = true;
537 }
sjfricke4f600c82022-06-09 14:21:32 +0900538 type = module_state.get_def(type.word(3));
Chris Forbes47567b72017-06-09 12:09:45 -0700539 }
540 }
541
542 switch (type.opcode()) {
543 case spv::OpTypeStruct: {
sjfricke4f600c82022-06-09 14:21:32 +0900544 for (const auto insn : module_state.GetDecorationInstructions()) {
sfricke-samsung94d71a52021-02-26 05:25:43 -0800545 if (insn.word(1) == type.word(1)) {
Chris Forbes47567b72017-06-09 12:09:45 -0700546 if (insn.word(2) == spv::DecorationBlock) {
Chris Forbes9f89d752018-03-07 12:57:48 -0800547 if (is_storage_buffer) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500548 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
549 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC);
550 return ret;
Chris Forbes9f89d752018-03-07 12:57:48 -0800551 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500552 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
553 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC);
554 ret.insert(VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT);
555 return ret;
Chris Forbes9f89d752018-03-07 12:57:48 -0800556 }
Chris Forbes47567b72017-06-09 12:09:45 -0700557 } else if (insn.word(2) == spv::DecorationBufferBlock) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500558 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER);
559 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC);
560 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700561 }
562 }
563 }
564
565 // Invalid
Jeff Bolze54ae892018-09-08 12:16:29 -0500566 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700567 }
568
569 case spv::OpTypeSampler:
Jeff Bolze54ae892018-09-08 12:16:29 -0500570 ret.insert(VK_DESCRIPTOR_TYPE_SAMPLER);
571 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
572 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700573
Chris Forbes73c00bf2018-06-22 16:28:06 -0700574 case spv::OpTypeSampledImage: {
575 // Slight relaxation for some GLSL historical madness: samplerBuffer doesn't really have a sampler, and a texel
576 // buffer descriptor doesn't really provide one. Allow this slight mismatch.
sjfricke4f600c82022-06-09 14:21:32 +0900577 auto image_type = module_state.get_def(type.word(2));
Chris Forbes73c00bf2018-06-22 16:28:06 -0700578 auto dim = image_type.word(3);
579 auto sampled = image_type.word(7);
580 if (dim == spv::DimBuffer && sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500581 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER);
582 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700583 }
Chris Forbes73c00bf2018-06-22 16:28:06 -0700584 }
Jeff Bolze54ae892018-09-08 12:16:29 -0500585 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
586 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700587
588 case spv::OpTypeImage: {
589 // Many descriptor types backing image types-- depends on dimension and whether the image will be used with a sampler.
590 // SPIRV for Vulkan requires that sampled be 1 or 2 -- leaving the decision to runtime is unacceptable.
591 auto dim = type.word(3);
592 auto sampled = type.word(7);
593
594 if (dim == spv::DimSubpassData) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500595 ret.insert(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT);
596 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700597 } else if (dim == spv::DimBuffer) {
598 if (sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500599 ret.insert(VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER);
600 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700601 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500602 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER);
603 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700604 }
605 } else if (sampled == 1) {
Jeff Bolze54ae892018-09-08 12:16:29 -0500606 ret.insert(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE);
607 ret.insert(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER);
608 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700609 } else {
Jeff Bolze54ae892018-09-08 12:16:29 -0500610 ret.insert(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE);
611 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700612 }
613 }
Shannon McPherson0fa28232018-11-01 11:59:02 -0600614 case spv::OpTypeAccelerationStructureNV:
sourav parmarcd5fb182020-07-17 12:58:44 -0700615 is_khr ? ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR)
616 : ret.insert(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_NV);
Jeff Bolz105d6492018-09-29 15:46:44 -0500617 return ret;
Chris Forbes47567b72017-06-09 12:09:45 -0700618
619 // We shouldn't really see any other junk types -- but if we do, they're a mismatch.
620 default:
Jeff Bolze54ae892018-09-08 12:16:29 -0500621 return ret; // Matches nothing
Chris Forbes47567b72017-06-09 12:09:45 -0700622 }
623}
624
Jeff Bolze54ae892018-09-08 12:16:29 -0500625static std::string string_descriptorTypes(const std::set<uint32_t> &descriptor_types) {
Chris Forbes73c00bf2018-06-22 16:28:06 -0700626 std::stringstream ss;
Jeff Bolze54ae892018-09-08 12:16:29 -0500627 for (auto it = descriptor_types.begin(); it != descriptor_types.end(); ++it) {
628 if (ss.tellp()) ss << ", ";
629 ss << string_VkDescriptorType(VkDescriptorType(*it));
Chris Forbes73c00bf2018-06-22 16:28:06 -0700630 }
631 return ss.str();
632}
633
sfricke-samsung0065ce02020-12-03 22:46:37 -0800634bool CoreChecks::RequirePropertyFlag(VkBool32 check, char const *flag, char const *structure, const char *vuid) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500635 if (!check) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800636 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 -0500637 return true;
638 }
639 }
640
641 return false;
642}
643
sfricke-samsung0065ce02020-12-03 22:46:37 -0800644bool CoreChecks::RequireFeature(VkBool32 feature, char const *feature_name, const char *vuid) const {
Chris Forbes47567b72017-06-09 12:09:45 -0700645 if (!feature) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800646 if (LogError(device, vuid, "Shader requires %s but is not enabled on the device", feature_name)) {
Chris Forbes47567b72017-06-09 12:09:45 -0700647 return true;
648 }
649 }
650
651 return false;
652}
653
locke-lunarg63e4daf2020-08-17 17:53:25 -0600654bool CoreChecks::ValidateShaderStageWritableOrAtomicDescriptor(VkShaderStageFlagBits stage, bool has_writable_descriptor,
655 bool has_atomic_descriptor) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500656 bool skip = false;
657
locke-lunarg63e4daf2020-08-17 17:53:25 -0600658 if (has_writable_descriptor || has_atomic_descriptor) {
Chris Forbes349b3132018-03-07 11:38:08 -0800659 switch (stage) {
Chris Forbes349b3132018-03-07 11:38:08 -0800660 case VK_SHADER_STAGE_FRAGMENT_BIT:
sfricke-samsung0065ce02020-12-03 22:46:37 -0800661 skip |= RequireFeature(enabled_features.core.fragmentStoresAndAtomics, "fragmentStoresAndAtomics",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700662 "VUID-RuntimeSpirv-NonWritable-06340");
Chris Forbes349b3132018-03-07 11:38:08 -0800663 break;
sfricke-samsunged00aa42022-01-27 19:03:01 -0800664 case VK_SHADER_STAGE_VERTEX_BIT:
665 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
666 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
667 case VK_SHADER_STAGE_GEOMETRY_BIT:
sfricke-samsung0065ce02020-12-03 22:46:37 -0800668 skip |= RequireFeature(enabled_features.core.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700669 "VUID-RuntimeSpirv-NonWritable-06341");
Chris Forbes349b3132018-03-07 11:38:08 -0800670 break;
sfricke-samsunged00aa42022-01-27 19:03:01 -0800671 default:
672 // No feature requirements for writes and atomics for other stages
673 break;
Chris Forbes349b3132018-03-07 11:38:08 -0800674 }
675 }
676
Chris Forbes47567b72017-06-09 12:09:45 -0700677 return skip;
678}
679
sjfricke4f600c82022-06-09 14:21:32 +0900680bool CoreChecks::ValidateShaderStageGroupNonUniform(const SHADER_MODULE_STATE &module_state, VkShaderStageFlagBits stage,
sfricke-samsung94167ca2021-02-26 04:14:59 -0800681 spirv_inst_iter &insn) const {
Jeff Bolzee743412019-06-20 22:24:32 -0500682 bool skip = false;
683
sfricke-samsung94167ca2021-02-26 04:14:59 -0800684 // Check anything using a group operation (which currently is only OpGroupNonUnifrom* operations)
685 if (GroupOperation(insn.opcode()) == true) {
686 // Check the quad operations.
687 if ((insn.opcode() == spv::OpGroupNonUniformQuadBroadcast) || (insn.opcode() == spv::OpGroupNonUniformQuadSwap)) {
688 if ((stage != VK_SHADER_STAGE_FRAGMENT_BIT) && (stage != VK_SHADER_STAGE_COMPUTE_BIT)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700689 skip |=
690 RequireFeature(phys_dev_props_core11.subgroupQuadOperationsInAllStages,
691 "VkPhysicalDeviceSubgroupProperties::quadOperationsInAllStages", "VUID-RuntimeSpirv-None-06342");
sfricke-samsung0065ce02020-12-03 22:46:37 -0800692 }
sfricke-samsung94167ca2021-02-26 04:14:59 -0800693 }
Jeff Bolz526f2d52019-09-18 13:18:08 -0500694
sfricke-samsung94167ca2021-02-26 04:14:59 -0800695 uint32_t scope_type = spv::ScopeMax;
696 if (insn.opcode() == spv::OpGroupNonUniformPartitionNV) {
697 // OpGroupNonUniformPartitionNV always assumed subgroup as missing operand
698 scope_type = spv::ScopeSubgroup;
699 } else {
700 // "All <id> used for Scope <id> must be of an OpConstant"
sjfricke4f600c82022-06-09 14:21:32 +0900701 auto scope_id = module_state.get_def(insn.word(3));
sfricke-samsung94167ca2021-02-26 04:14:59 -0800702 scope_type = scope_id.word(3);
703 }
sfricke-samsung0065ce02020-12-03 22:46:37 -0800704
sfricke-samsung94167ca2021-02-26 04:14:59 -0800705 if (scope_type == spv::ScopeSubgroup) {
706 // "Group operations with subgroup scope" must have stage support
707 const VkSubgroupFeatureFlags supported_stages = phys_dev_props_core11.subgroupSupportedStages;
708 skip |= RequirePropertyFlag(supported_stages & stage, string_VkShaderStageFlagBits(stage),
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700709 "VkPhysicalDeviceSubgroupProperties::supportedStages", "VUID-RuntimeSpirv-None-06343");
sfricke-samsung94167ca2021-02-26 04:14:59 -0800710 }
711
712 if (!enabled_features.core12.shaderSubgroupExtendedTypes) {
sjfricke4f600c82022-06-09 14:21:32 +0900713 auto type = module_state.get_def(insn.word(1));
sfricke-samsung94167ca2021-02-26 04:14:59 -0800714
715 if (type.opcode() == spv::OpTypeVector) {
716 // Get the element type
sjfricke4f600c82022-06-09 14:21:32 +0900717 type = module_state.get_def(type.word(2));
sfricke-samsung0065ce02020-12-03 22:46:37 -0800718 }
719
sfricke-samsung94167ca2021-02-26 04:14:59 -0800720 if (type.opcode() != spv::OpTypeBool) {
sfricke-samsung0065ce02020-12-03 22:46:37 -0800721 // Both OpTypeInt and OpTypeFloat the width is in the 2nd word.
722 const uint32_t width = type.word(2);
Jeff Bolz526f2d52019-09-18 13:18:08 -0500723
sfricke-samsung0065ce02020-12-03 22:46:37 -0800724 if ((type.opcode() == spv::OpTypeFloat && width == 16) ||
725 (type.opcode() == spv::OpTypeInt && (width == 8 || width == 16 || width == 64))) {
726 skip |= RequireFeature(enabled_features.core12.shaderSubgroupExtendedTypes,
727 "VkPhysicalDeviceShaderSubgroupExtendedTypesFeatures::shaderSubgroupExtendedTypes",
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700728 "VUID-RuntimeSpirv-None-06275");
Jeff Bolz526f2d52019-09-18 13:18:08 -0500729 }
730 }
731 }
Jeff Bolzee743412019-06-20 22:24:32 -0500732 }
733
734 return skip;
735}
736
sjfricke4f600c82022-06-09 14:21:32 +0900737bool CoreChecks::ValidateMemoryScope(const SHADER_MODULE_STATE &module_state, const spirv_inst_iter &insn) const {
ziga-lunarg70651522021-10-11 17:23:30 +0200738 bool skip = false;
739
sfricke-samsung3a25ed52022-01-20 02:24:36 -0800740 const auto &entry = OpcodeMemoryScopePosition(insn.opcode());
ziga-lunarg70651522021-10-11 17:23:30 +0200741 if (entry > 0) {
742 const uint32_t scope_id = insn.word(entry);
sjfricke4f600c82022-06-09 14:21:32 +0900743 const auto &scope_def = module_state.GetConstantDef(scope_id);
744 if (scope_def != module_state.end()) {
sjfricke3b0cb102022-08-10 16:27:45 +0900745 const auto scope_type = module_state.GetConstantValue(scope_def);
sfricke-samsunged00aa42022-01-27 19:03:01 -0800746 if (enabled_features.core12.vulkanMemoryModel && !enabled_features.core12.vulkanMemoryModelDeviceScope &&
747 scope_type == spv::Scope::ScopeDevice) {
748 skip |= LogError(device, "VUID-RuntimeSpirv-vulkanMemoryModel-06265",
749 "VkPhysicalDeviceVulkan12Features::vulkanMemoryModel is enabled and "
750 "VkPhysicalDeviceVulkan12Features::vulkanMemoryModelDeviceScope is disabled, but\n%s\nuses "
751 "Device memory scope.",
sjfricke4f600c82022-06-09 14:21:32 +0900752 module_state.DescribeInstruction(insn).c_str());
sfricke-samsunged00aa42022-01-27 19:03:01 -0800753 } else if (!enabled_features.core12.vulkanMemoryModel && scope_type == spv::Scope::ScopeQueueFamily) {
754 skip |= LogError(device, "VUID-RuntimeSpirv-vulkanMemoryModel-06266",
755 "VkPhysicalDeviceVulkan12Features::vulkanMemoryModel is not enabled, but\n%s\nuses "
756 "QueueFamily memory scope.",
sjfricke4f600c82022-06-09 14:21:32 +0900757 module_state.DescribeInstruction(insn).c_str());
ziga-lunarg70651522021-10-11 17:23:30 +0200758 }
759 }
760 }
761
762 return skip;
763}
764
sjfricke4f600c82022-06-09 14:21:32 +0900765bool CoreChecks::ValidateShaderStageInputOutputLimits(const SHADER_MODULE_STATE &module_state,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -0700766 safe_VkPipelineShaderStageCreateInfo const *pStage,
767 const PIPELINE_STATE *pipeline, spirv_inst_iter entrypoint) const {
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200768 if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT || pStage->stage == VK_SHADER_STAGE_ALL_GRAPHICS ||
769 pStage->stage == VK_SHADER_STAGE_ALL) {
770 return false;
771 }
772
773 bool skip = false;
Mark Lobodzinski518eadc2019-03-09 12:07:30 -0700774 auto const &limits = phys_dev_props.limits;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200775
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700776 std::set<uint32_t> patch_i_ds;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200777 struct Variable {
778 uint32_t baseTypePtrID;
779 uint32_t ID;
780 uint32_t storageClass;
781 };
782 std::vector<Variable> variables;
783
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700784 uint32_t num_vertices = 0;
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700785 bool is_iso_lines = false;
786 bool is_point_mode = false;
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500787
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700788 auto entrypoint_variables = FindEntrypointInterfaces(entrypoint);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600789
sjfricke4f600c82022-06-09 14:21:32 +0900790 for (auto insn : module_state) {
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200791 switch (insn.opcode()) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500792 // Find all Patch decorations
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200793 case spv::OpDecorate:
794 switch (insn.word(2)) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500795 case spv::DecorationPatch: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700796 patch_i_ds.insert(insn.word(1));
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200797 break;
798 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200799 default:
800 break;
801 }
802 break;
803 // Find all input and output variables
804 case spv::OpVariable: {
805 Variable var = {};
806 var.storageClass = insn.word(3);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600807 if ((var.storageClass == spv::StorageClassInput || var.storageClass == spv::StorageClassOutput) &&
808 // Only include variables in the entrypoint's interface
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700809 find(entrypoint_variables.begin(), entrypoint_variables.end(), insn.word(2)) != entrypoint_variables.end()) {
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200810 var.baseTypePtrID = insn.word(1);
811 var.ID = insn.word(2);
812 variables.push_back(var);
813 }
814 break;
815 }
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500816 case spv::OpExecutionMode:
sfricke-samsung61d50ec2022-02-13 17:01:25 -0800817 case spv::OpExecutionModeId:
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500818 if (insn.word(1) == entrypoint.word(2)) {
819 switch (insn.word(2)) {
820 default:
821 break;
822 case spv::ExecutionModeOutputVertices:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700823 num_vertices = insn.word(3);
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500824 break;
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700825 case spv::ExecutionModeIsolines:
826 is_iso_lines = true;
827 break;
828 case spv::ExecutionModePointMode:
829 is_point_mode = true;
830 break;
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500831 }
832 }
833 break;
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200834 default:
835 break;
836 }
837 }
838
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500839 bool strip_output_array_level =
840 (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT || pStage->stage == VK_SHADER_STAGE_MESH_BIT_NV);
841 bool strip_input_array_level =
842 (pStage->stage == VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT ||
843 pStage->stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || pStage->stage == VK_SHADER_STAGE_GEOMETRY_BIT);
844
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700845 uint32_t num_comp_in = 0, num_comp_out = 0;
846 int max_comp_in = 0, max_comp_out = 0;
Jeff Bolzf234bf82019-11-04 14:07:15 -0600847
sjfricke4f600c82022-06-09 14:21:32 +0900848 auto inputs = module_state.CollectInterfaceByLocation(entrypoint, spv::StorageClassInput, strip_input_array_level);
849 auto outputs = module_state.CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, strip_output_array_level);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600850
851 // Find max component location used for input variables.
852 for (auto &var : inputs) {
853 int location = var.first.first;
854 int component = var.first.second;
855 interface_var &iv = var.second;
856
857 // Only need to look at the first location, since we use the type's whole size
858 if (iv.offset != 0) {
859 continue;
860 }
861
862 if (iv.is_patch) {
863 continue;
864 }
865
sjfricke4f600c82022-06-09 14:21:32 +0900866 int num_components = module_state.GetComponentsConsumedByType(iv.type_id, strip_input_array_level);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700867 max_comp_in = std::max(max_comp_in, location * 4 + component + num_components);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600868 }
869
870 // Find max component location used for output variables.
871 for (auto &var : outputs) {
872 int location = var.first.first;
873 int component = var.first.second;
874 interface_var &iv = var.second;
875
876 // Only need to look at the first location, since we use the type's whole size
877 if (iv.offset != 0) {
878 continue;
879 }
880
881 if (iv.is_patch) {
882 continue;
883 }
884
sjfricke4f600c82022-06-09 14:21:32 +0900885 int num_components = module_state.GetComponentsConsumedByType(iv.type_id, strip_output_array_level);
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700886 max_comp_out = std::max(max_comp_out, location * 4 + component + num_components);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600887 }
888
889 // XXX TODO: Would be nice to rewrite this to use CollectInterfaceByLocation (or something similar),
890 // but that doesn't include builtins.
sfricke-samsung406766a2021-07-02 12:04:09 -0700891 // When rewritten, using the CreatePipelineExceedVertexMaxComponentsWithBuiltins test it would be nice to also let the user know
892 // how many components were from builtins as it might not be obvious
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200893 for (auto &var : variables) {
Jeff Bolze9ee3d82019-05-29 13:45:13 -0500894 // Check if the variable is a patch. Patches can also be members of blocks,
895 // but if they are then the top-level arrayness has already been stripped
896 // by the time GetComponentsConsumedByType gets to it.
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700897 bool is_patch = patch_i_ds.find(var.ID) != patch_i_ds.end();
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200898
899 if (var.storageClass == spv::StorageClassInput) {
sjfricke4f600c82022-06-09 14:21:32 +0900900 num_comp_in += module_state.GetComponentsConsumedByType(var.baseTypePtrID, strip_input_array_level && !is_patch);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200901 } else { // var.storageClass == spv::StorageClassOutput
sjfricke4f600c82022-06-09 14:21:32 +0900902 num_comp_out += module_state.GetComponentsConsumedByType(var.baseTypePtrID, strip_output_array_level && !is_patch);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200903 }
904 }
905
906 switch (pStage->stage) {
907 case VK_SHADER_STAGE_VERTEX_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700908 if (num_comp_out > limits.maxVertexOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700909 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700910 "Invalid Pipeline CreateInfo State: Vertex shader exceeds "
911 "VkPhysicalDeviceLimits::maxVertexOutputComponents of %u "
912 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700913 limits.maxVertexOutputComponents, num_comp_out - limits.maxVertexOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200914 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700915 if (max_comp_out > static_cast<int>(limits.maxVertexOutputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700916 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700917 "Invalid Pipeline CreateInfo State: Vertex shader output variable uses location that "
918 "exceeds component limit VkPhysicalDeviceLimits::maxVertexOutputComponents (%u)",
919 limits.maxVertexOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600920 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200921 break;
922
923 case VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700924 if (num_comp_in > limits.maxTessellationControlPerVertexInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700925 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700926 "Invalid Pipeline CreateInfo State: Tessellation control shader exceeds "
927 "VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents of %u "
928 "components by %u components",
929 limits.maxTessellationControlPerVertexInputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700930 num_comp_in - limits.maxTessellationControlPerVertexInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200931 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700932 if (max_comp_in > static_cast<int>(limits.maxTessellationControlPerVertexInputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600933 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700934 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700935 "Invalid Pipeline CreateInfo State: Tessellation control shader input variable uses location that "
936 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexInputComponents (%u)",
937 limits.maxTessellationControlPerVertexInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600938 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700939 if (num_comp_out > limits.maxTessellationControlPerVertexOutputComponents) {
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: Tessellation control shader exceeds "
942 "VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents of %u "
943 "components by %u components",
944 limits.maxTessellationControlPerVertexOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700945 num_comp_out - limits.maxTessellationControlPerVertexOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200946 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700947 if (max_comp_out > static_cast<int>(limits.maxTessellationControlPerVertexOutputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600948 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700949 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700950 "Invalid Pipeline CreateInfo State: Tessellation control shader output variable uses location that "
951 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationControlPerVertexOutputComponents (%u)",
952 limits.maxTessellationControlPerVertexOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600953 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200954 break;
955
956 case VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700957 if (num_comp_in > limits.maxTessellationEvaluationInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700958 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700959 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds "
960 "VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents of %u "
961 "components by %u components",
962 limits.maxTessellationEvaluationInputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700963 num_comp_in - limits.maxTessellationEvaluationInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200964 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700965 if (max_comp_in > static_cast<int>(limits.maxTessellationEvaluationInputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600966 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700967 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700968 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader input variable uses location that "
969 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationInputComponents (%u)",
970 limits.maxTessellationEvaluationInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600971 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700972 if (num_comp_out > limits.maxTessellationEvaluationOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700973 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700974 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader exceeds "
975 "VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents of %u "
976 "components by %u components",
977 limits.maxTessellationEvaluationOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700978 num_comp_out - limits.maxTessellationEvaluationOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +0200979 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -0700980 if (max_comp_out > static_cast<int>(limits.maxTessellationEvaluationOutputComponents)) {
Jeff Bolzf234bf82019-11-04 14:07:15 -0600981 skip |=
sfricke-samsung782b9cb2021-09-16 23:53:32 -0700982 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -0700983 "Invalid Pipeline CreateInfo State: Tessellation evaluation shader output variable uses location that "
984 "exceeds component limit VkPhysicalDeviceLimits::maxTessellationEvaluationOutputComponents (%u)",
985 limits.maxTessellationEvaluationOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -0600986 }
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700987 // Portability validation
988 if (IsExtEnabled(device_extensions.vk_khr_portability_subset)) {
989 if (is_iso_lines && (VK_FALSE == enabled_features.portability_subset_features.tessellationIsolines)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700990 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-tessellationShader-06326",
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700991 "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader"
992 " is using abstract patch type IsoLines, but this is not supported on this platform");
993 }
994 if (is_point_mode && (VK_FALSE == enabled_features.portability_subset_features.tessellationPointMode)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -0700995 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-tessellationShader-06327",
Nathaniel Cesario75fb7222020-12-07 10:54:53 -0700996 "Invalid Pipeline CreateInfo state (portability error): Tessellation evaluation shader"
997 " is using abstract patch type PointMode, but this is not supported on this platform");
998 }
999 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001000 break;
1001
1002 case VK_SHADER_STAGE_GEOMETRY_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001003 if (num_comp_in > limits.maxGeometryInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001004 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001005 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
1006 "VkPhysicalDeviceLimits::maxGeometryInputComponents of %u "
1007 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001008 limits.maxGeometryInputComponents, num_comp_in - limits.maxGeometryInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001009 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001010 if (max_comp_in > static_cast<int>(limits.maxGeometryInputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001011 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001012 "Invalid Pipeline CreateInfo State: Geometry shader input variable uses location that "
1013 "exceeds component limit VkPhysicalDeviceLimits::maxGeometryInputComponents (%u)",
1014 limits.maxGeometryInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -06001015 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001016 if (num_comp_out > limits.maxGeometryOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001017 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001018 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
1019 "VkPhysicalDeviceLimits::maxGeometryOutputComponents of %u "
1020 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001021 limits.maxGeometryOutputComponents, num_comp_out - limits.maxGeometryOutputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001022 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001023 if (max_comp_out > static_cast<int>(limits.maxGeometryOutputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001024 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001025 "Invalid Pipeline CreateInfo State: Geometry shader output variable uses location that "
1026 "exceeds component limit VkPhysicalDeviceLimits::maxGeometryOutputComponents (%u)",
1027 limits.maxGeometryOutputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -06001028 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001029 if (num_comp_out * num_vertices > limits.maxGeometryTotalOutputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001030 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001031 "Invalid Pipeline CreateInfo State: Geometry shader exceeds "
1032 "VkPhysicalDeviceLimits::maxGeometryTotalOutputComponents of %u "
1033 "components by %u components",
1034 limits.maxGeometryTotalOutputComponents,
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001035 num_comp_out * num_vertices - limits.maxGeometryTotalOutputComponents);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001036 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001037 break;
1038
1039 case VK_SHADER_STAGE_FRAGMENT_BIT:
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001040 if (num_comp_in > limits.maxFragmentInputComponents) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001041 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001042 "Invalid Pipeline CreateInfo State: Fragment shader exceeds "
1043 "VkPhysicalDeviceLimits::maxFragmentInputComponents of %u "
1044 "components by %u components",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001045 limits.maxFragmentInputComponents, num_comp_in - limits.maxFragmentInputComponents);
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001046 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001047 if (max_comp_in > static_cast<int>(limits.maxFragmentInputComponents)) {
sfricke-samsung782b9cb2021-09-16 23:53:32 -07001048 skip |= LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-Location-06272",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001049 "Invalid Pipeline CreateInfo State: Fragment shader input variable uses location that "
1050 "exceeds component limit VkPhysicalDeviceLimits::maxFragmentInputComponents (%u)",
1051 limits.maxFragmentInputComponents);
Jeff Bolzf234bf82019-11-04 14:07:15 -06001052 }
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001053 break;
1054
sjfricke62366d32022-08-01 21:04:10 +09001055 case VK_SHADER_STAGE_RAYGEN_BIT_KHR:
1056 case VK_SHADER_STAGE_ANY_HIT_BIT_KHR:
1057 case VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR:
1058 case VK_SHADER_STAGE_MISS_BIT_KHR:
1059 case VK_SHADER_STAGE_INTERSECTION_BIT_KHR:
1060 case VK_SHADER_STAGE_CALLABLE_BIT_KHR:
Jeff Bolz148d94e2018-12-13 21:25:56 -06001061 case VK_SHADER_STAGE_TASK_BIT_NV:
1062 case VK_SHADER_STAGE_MESH_BIT_NV:
1063 break;
1064
Daniel Fedai Larsenc939abc2018-08-07 10:01:58 +02001065 default:
1066 assert(false); // This should never happen
1067 }
1068 return skip;
1069}
1070
sjfricke29ca0762022-08-24 14:26:33 +09001071bool CoreChecks::ValidateShaderStorageImageFormatsVariables(const SHADER_MODULE_STATE &module_state,
1072 const spirv_inst_iter &insn) const {
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001073 bool skip = false;
sjfricke29ca0762022-08-24 14:26:33 +09001074 // Go through all variables for images and check decorations
1075 assert(insn.opcode() == spv::OpVariable);
1076 // spirv-val validates this is an OpTypePointer
1077 const spirv_inst_iter pointer_def = module_state.get_def(insn.word(1));
1078 if (pointer_def.word(2) != spv::StorageClassUniformConstant) {
1079 return skip; // Vulkan Spec says storage image must be UniformConstant
1080 }
1081 spirv_inst_iter type_def = module_state.get_def(pointer_def.word(3));
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001082
sjfricke29ca0762022-08-24 14:26:33 +09001083 // Unpack an optional level of arraying
1084 if (type_def.opcode() == spv::OpTypeArray || type_def.opcode() == spv::OpTypeRuntimeArray) {
1085 type_def = module_state.get_def(type_def.word(2));
1086 }
Lionel Landwerlin6a9f89c2021-12-07 15:46:46 +02001087
sjfricke29ca0762022-08-24 14:26:33 +09001088 if (type_def != module_state.end() && type_def.opcode() == spv::OpTypeImage) {
1089 // Only check if the Image Dim operand is not SubpassData
1090 const uint32_t dim = type_def.word(3);
1091 // Only check storage images
1092 const uint32_t sampled = type_def.word(7);
1093 const uint32_t image_format = type_def.word(8);
1094 if ((dim == spv::DimSubpassData) || (sampled != 2) || (image_format != spv::ImageFormatUnknown)) {
1095 return skip;
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001096 }
1097
sjfricke29ca0762022-08-24 14:26:33 +09001098 const uint32_t var_id = insn.word(2);
1099 decoration_set img_decorations = module_state.get_decorations(var_id);
sfricke-samsunga6c1ddc2022-01-23 14:15:40 -08001100
sjfricke29ca0762022-08-24 14:26:33 +09001101 if (!enabled_features.core.shaderStorageImageReadWithoutFormat &&
1102 !(img_decorations.flags & decoration_set::nonreadable_bit)) {
1103 skip |= LogError(device, "VUID-RuntimeSpirv-OpTypeImage-06270",
1104 "shaderStorageImageReadWithoutFormat is not supported but\n%s\nhas an Image\n%s\nwith Unknown "
1105 "format and is not decorated with NonReadable",
1106 module_state.DescribeInstruction(module_state.get_def(var_id)).c_str(),
1107 module_state.DescribeInstruction(type_def).c_str());
1108 }
sfricke-samsunga6c1ddc2022-01-23 14:15:40 -08001109
sjfricke29ca0762022-08-24 14:26:33 +09001110 if (!enabled_features.core.shaderStorageImageWriteWithoutFormat &&
1111 !(img_decorations.flags & decoration_set::nonwritable_bit)) {
1112 skip |= LogError(device, "VUID-RuntimeSpirv-OpTypeImage-06269",
1113 "shaderStorageImageWriteWithoutFormat is not supported but\n%s\nhas an Image\n%s\nwith "
1114 "Unknown format and is not decorated with NonWritable",
1115 module_state.DescribeInstruction(module_state.get_def(var_id)).c_str(),
1116 module_state.DescribeInstruction(type_def).c_str());
Lionel Landwerlin38d2e122021-07-21 14:21:47 +03001117 }
1118 }
1119
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001120 return skip;
1121}
1122
sfricke-samsungdc96f302020-03-18 20:42:10 -07001123bool CoreChecks::ValidateShaderStageMaxResources(VkShaderStageFlagBits stage, const PIPELINE_STATE *pipeline) const {
1124 bool skip = false;
1125 uint32_t total_resources = 0;
1126
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001127 const auto &rp_state = pipeline->RenderPassState();
1128 if ((stage == VK_SHADER_STAGE_FRAGMENT_BIT) && rp_state) {
Jeremy Gebbenb5dda542022-08-02 14:26:20 -06001129 if (rp_state->UsesDynamicRendering()) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001130 total_resources += rp_state->dynamic_rendering_pipeline_create_info.colorAttachmentCount;
amhagana448ea52021-11-02 14:09:14 -04001131 } else {
1132 // "For the fragment shader stage the framebuffer color attachments also count against this limit"
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001133 total_resources += rp_state->createInfo.pSubpasses[pipeline->Subpass()].colorAttachmentCount;
amhagana448ea52021-11-02 14:09:14 -04001134 }
sfricke-samsungdc96f302020-03-18 20:42:10 -07001135 }
1136
1137 // TODO: This reuses a lot of GetDescriptorCountMaxPerStage but currently would need to make it agnostic in a way to handle
1138 // input from CreatePipeline and CreatePipelineLayout level
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001139 const auto &layout_state = pipeline->PipelineLayoutState();
1140 if (layout_state) {
1141 for (auto set_layout : layout_state->set_layouts) {
1142 if ((set_layout->GetCreateFlags() & VK_DESCRIPTOR_SET_LAYOUT_CREATE_UPDATE_AFTER_BIND_POOL_BIT) != 0) {
1143 continue;
1144 }
sfricke-samsungdc96f302020-03-18 20:42:10 -07001145
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001146 for (uint32_t binding_idx = 0; binding_idx < set_layout->GetBindingCount(); binding_idx++) {
1147 const VkDescriptorSetLayoutBinding *binding = set_layout->GetDescriptorSetLayoutBindingPtrFromIndex(binding_idx);
1148 // Bindings with a descriptorCount of 0 are "reserved" and should be skipped
1149 if (((stage & binding->stageFlags) != 0) && (binding->descriptorCount > 0)) {
1150 // Check only descriptor types listed in maxPerStageResources description in spec
1151 switch (binding->descriptorType) {
1152 case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
1153 case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
1154 case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
1155 case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
1156 case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
1157 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
1158 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
1159 case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
1160 case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC:
1161 case VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT:
1162 total_resources += binding->descriptorCount;
1163 break;
1164 default:
1165 break;
1166 }
sfricke-samsungdc96f302020-03-18 20:42:10 -07001167 }
1168 }
1169 }
1170 }
1171
1172 if (total_resources > phys_dev_props.limits.maxPerStageResources) {
ziga-lunarg7d53c822022-05-08 23:06:10 +02001173 const char *vuid = nullptr;
1174 if (stage == VK_SHADER_STAGE_COMPUTE_BIT) {
1175 vuid = "VUID-VkComputePipelineCreateInfo-layout-01687";
1176 } else if ((stage & VK_SHADER_STAGE_ALL_GRAPHICS) == 0) {
1177 vuid = "VUID-VkRayTracingPipelineCreateInfoKHR-layout-03428";
1178 } else {
1179 vuid = "VUID-VkGraphicsPipelineCreateInfo-layout-01688";
1180 }
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001181 skip |= LogError(pipeline->pipeline(), vuid,
sfricke-samsungdc96f302020-03-18 20:42:10 -07001182 "Invalid Pipeline CreateInfo State: Shader Stage %s exceeds component limit "
1183 "VkPhysicalDeviceLimits::maxPerStageResources (%u)",
1184 string_VkShaderStageFlagBits(stage), phys_dev_props.limits.maxPerStageResources);
1185 }
1186
1187 return skip;
1188}
1189
Jeff Bolze4356752019-03-07 11:23:46 -06001190// copy the specialization constant value into buf, if it is present
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001191template <typename StageCreateInfo>
1192void GetSpecConstantValue(StageCreateInfo const *pStage, uint32_t spec_id, void *buf) {
1193 const auto *spec = pStage->pSpecializationInfo;
Jeff Bolze4356752019-03-07 11:23:46 -06001194
1195 if (spec && spec_id < spec->mapEntryCount) {
1196 memcpy(buf, (uint8_t *)spec->pData + spec->pMapEntries[spec_id].offset, spec->pMapEntries[spec_id].size);
1197 }
1198}
1199
1200// Fill in value with the constant or specialization constant value, if available.
1201// Returns true if the value has been accurately filled out.
sjfricke4f600c82022-06-09 14:21:32 +09001202static bool GetIntConstantValue(spirv_inst_iter insn, const SHADER_MODULE_STATE &module_state,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001203 safe_VkPipelineShaderStageCreateInfo const *pStage,
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001204 const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id, uint32_t *value) {
sjfricke4f600c82022-06-09 14:21:32 +09001205 auto type_id = module_state.get_def(insn.word(1));
Jeff Bolze4356752019-03-07 11:23:46 -06001206 if (type_id.opcode() != spv::OpTypeInt || type_id.word(2) != 32) {
1207 return false;
1208 }
1209 switch (insn.opcode()) {
1210 case spv::OpSpecConstant:
1211 *value = insn.word(3);
1212 GetSpecConstantValue(pStage, id_to_spec_id.at(insn.word(2)), value);
1213 return true;
1214 case spv::OpConstant:
1215 *value = insn.word(3);
1216 return true;
1217 default:
1218 return false;
1219 }
1220}
1221
1222// Map SPIR-V type to VK_COMPONENT_TYPE enum
sjfricke4f600c82022-06-09 14:21:32 +09001223VkComponentTypeNV GetComponentType(spirv_inst_iter insn) {
Jeff Bolze4356752019-03-07 11:23:46 -06001224 switch (insn.opcode()) {
1225 case spv::OpTypeInt:
1226 switch (insn.word(2)) {
1227 case 8:
1228 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT8_NV : VK_COMPONENT_TYPE_UINT8_NV;
1229 case 16:
1230 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT16_NV : VK_COMPONENT_TYPE_UINT16_NV;
1231 case 32:
1232 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT32_NV : VK_COMPONENT_TYPE_UINT32_NV;
1233 case 64:
1234 return insn.word(3) != 0 ? VK_COMPONENT_TYPE_SINT64_NV : VK_COMPONENT_TYPE_UINT64_NV;
1235 default:
1236 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1237 }
1238 case spv::OpTypeFloat:
1239 switch (insn.word(2)) {
1240 case 16:
1241 return VK_COMPONENT_TYPE_FLOAT16_NV;
1242 case 32:
1243 return VK_COMPONENT_TYPE_FLOAT32_NV;
1244 case 64:
1245 return VK_COMPONENT_TYPE_FLOAT64_NV;
1246 default:
1247 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1248 }
1249 default:
1250 return VK_COMPONENT_TYPE_MAX_ENUM_NV;
1251 }
1252}
1253
1254// Validate SPV_NV_cooperative_matrix behavior that can't be statically validated
1255// in SPIRV-Tools (e.g. due to specialization constant usage).
sjfricke4f600c82022-06-09 14:21:32 +09001256bool CoreChecks::ValidateCooperativeMatrix(const SHADER_MODULE_STATE &module_state,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001257 safe_VkPipelineShaderStageCreateInfo const *pStage,
John Zulaufac4c6e12019-07-01 16:05:58 -06001258 const PIPELINE_STATE *pipeline) const {
Jeff Bolze4356752019-03-07 11:23:46 -06001259 bool skip = false;
1260
1261 // Map SPIR-V result ID to specialization constant id (SpecId decoration value)
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001262 layer_data::unordered_map<uint32_t, uint32_t> id_to_spec_id;
Jeff Bolze4356752019-03-07 11:23:46 -06001263 // Map SPIR-V result ID to the ID of its type.
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001264 layer_data::unordered_map<uint32_t, uint32_t> id_to_type_id;
Jeff Bolze4356752019-03-07 11:23:46 -06001265
1266 struct CoopMatType {
1267 uint32_t scope, rows, cols;
1268 VkComponentTypeNV component_type;
1269 bool all_constant;
1270
1271 CoopMatType() : scope(0), rows(0), cols(0), component_type(VK_COMPONENT_TYPE_MAX_ENUM_NV), all_constant(false) {}
1272
sjfricke4f600c82022-06-09 14:21:32 +09001273 void Init(uint32_t id, const SHADER_MODULE_STATE &module_state, safe_VkPipelineShaderStageCreateInfo const *pStage,
Jeremy Gebbencbf22862021-03-03 12:01:22 -07001274 const layer_data::unordered_map<uint32_t, uint32_t> &id_to_spec_id) {
sjfricke4f600c82022-06-09 14:21:32 +09001275 spirv_inst_iter insn = module_state.get_def(id);
Jeff Bolze4356752019-03-07 11:23:46 -06001276 uint32_t component_type_id = insn.word(2);
1277 uint32_t scope_id = insn.word(3);
1278 uint32_t rows_id = insn.word(4);
1279 uint32_t cols_id = insn.word(5);
sjfricke4f600c82022-06-09 14:21:32 +09001280 auto component_type_iter = module_state.get_def(component_type_id);
1281 auto scope_iter = module_state.get_def(scope_id);
1282 auto rows_iter = module_state.get_def(rows_id);
1283 auto cols_iter = module_state.get_def(cols_id);
Jeff Bolze4356752019-03-07 11:23:46 -06001284
1285 all_constant = true;
sfricke-samsungef15e482022-01-26 11:32:49 -08001286 if (!GetIntConstantValue(scope_iter, module_state, pStage, id_to_spec_id, &scope)) {
Jeff Bolze4356752019-03-07 11:23:46 -06001287 all_constant = false;
1288 }
sfricke-samsungef15e482022-01-26 11:32:49 -08001289 if (!GetIntConstantValue(rows_iter, module_state, pStage, id_to_spec_id, &rows)) {
Jeff Bolze4356752019-03-07 11:23:46 -06001290 all_constant = false;
1291 }
sfricke-samsungef15e482022-01-26 11:32:49 -08001292 if (!GetIntConstantValue(cols_iter, module_state, pStage, id_to_spec_id, &cols)) {
Jeff Bolze4356752019-03-07 11:23:46 -06001293 all_constant = false;
1294 }
sjfricke4f600c82022-06-09 14:21:32 +09001295 component_type = GetComponentType(component_type_iter);
Jeff Bolze4356752019-03-07 11:23:46 -06001296 }
1297 };
1298
1299 bool seen_coopmat_capability = false;
1300
sjfricke4f600c82022-06-09 14:21:32 +09001301 for (auto insn : module_state) {
sjfrickeb0943832022-08-18 16:06:54 +09001302 if (OpcodeHasType(insn.opcode()) && OpcodeHasResult(insn.opcode())) {
1303 id_to_type_id[insn.word(2)] = insn.word(1);
Jeff Bolze4356752019-03-07 11:23:46 -06001304 }
1305
1306 switch (insn.opcode()) {
1307 case spv::OpDecorate:
1308 if (insn.word(2) == spv::DecorationSpecId) {
1309 id_to_spec_id[insn.word(1)] = insn.word(3);
1310 }
1311 break;
1312 case spv::OpCapability:
1313 if (insn.word(1) == spv::CapabilityCooperativeMatrixNV) {
1314 seen_coopmat_capability = true;
1315
1316 if (!(pStage->stage & phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001317 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001318 pipeline->pipeline(), "VUID-RuntimeSpirv-OpTypeCooperativeMatrixNV-06322",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001319 "OpTypeCooperativeMatrixNV used in shader stage not in cooperativeMatrixSupportedStages (= %u)",
1320 phys_dev_ext_props.cooperative_matrix_props.cooperativeMatrixSupportedStages);
Jeff Bolze4356752019-03-07 11:23:46 -06001321 }
1322 }
1323 break;
1324 case spv::OpMemoryModel:
1325 // If the capability isn't enabled, don't bother with the rest of this function.
1326 // OpMemoryModel is the first required instruction after all OpCapability instructions.
1327 if (!seen_coopmat_capability) {
1328 return skip;
1329 }
1330 break;
1331 case spv::OpTypeCooperativeMatrixNV: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001332 CoopMatType m;
sfricke-samsungef15e482022-01-26 11:32:49 -08001333 m.Init(insn.word(1), module_state, pStage, id_to_spec_id);
Jeff Bolze4356752019-03-07 11:23:46 -06001334
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001335 if (m.all_constant) {
Jeff Bolze4356752019-03-07 11:23:46 -06001336 // Validate that the type parameters are all supported for one of the
1337 // operands of a cooperative matrix property.
1338 bool valid = false;
sfricke-samsung7fac88a2022-01-26 11:44:22 -08001339 for (uint32_t i = 0; i < cooperative_matrix_properties.size(); ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001340 if (cooperative_matrix_properties[i].AType == m.component_type &&
1341 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].KSize == m.cols &&
1342 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001343 valid = true;
1344 break;
1345 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001346 if (cooperative_matrix_properties[i].BType == m.component_type &&
1347 cooperative_matrix_properties[i].KSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1348 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001349 valid = true;
1350 break;
1351 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001352 if (cooperative_matrix_properties[i].CType == m.component_type &&
1353 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1354 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001355 valid = true;
1356 break;
1357 }
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001358 if (cooperative_matrix_properties[i].DType == m.component_type &&
1359 cooperative_matrix_properties[i].MSize == m.rows && cooperative_matrix_properties[i].NSize == m.cols &&
1360 cooperative_matrix_properties[i].scope == m.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001361 valid = true;
1362 break;
1363 }
1364 }
1365 if (!valid) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001366 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixType,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001367 "OpTypeCooperativeMatrixNV (result id = %u) operands don't match a supported matrix type",
1368 insn.word(1));
Jeff Bolze4356752019-03-07 11:23:46 -06001369 }
1370 }
1371 break;
1372 }
1373 case spv::OpCooperativeMatrixMulAddNV: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001374 CoopMatType a, b, c, d;
Jeff Bolze4356752019-03-07 11:23:46 -06001375 if (id_to_type_id.find(insn.word(2)) == id_to_type_id.end() ||
1376 id_to_type_id.find(insn.word(3)) == id_to_type_id.end() ||
1377 id_to_type_id.find(insn.word(4)) == id_to_type_id.end() ||
1378 id_to_type_id.find(insn.word(5)) == id_to_type_id.end()) {
Mike Schuchardte48dc142019-04-18 09:12:03 -07001379 // Couldn't find type of matrix
1380 assert(false);
Jeff Bolze4356752019-03-07 11:23:46 -06001381 break;
1382 }
sfricke-samsungef15e482022-01-26 11:32:49 -08001383 d.Init(id_to_type_id[insn.word(2)], module_state, pStage, id_to_spec_id);
1384 a.Init(id_to_type_id[insn.word(3)], module_state, pStage, id_to_spec_id);
1385 b.Init(id_to_type_id[insn.word(4)], module_state, pStage, id_to_spec_id);
1386 c.Init(id_to_type_id[insn.word(5)], module_state, pStage, id_to_spec_id);
Jeff Bolze4356752019-03-07 11:23:46 -06001387
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001388 if (a.all_constant && b.all_constant && c.all_constant && d.all_constant) {
Jeff Bolze4356752019-03-07 11:23:46 -06001389 // Validate that the type parameters are all supported for the same
1390 // cooperative matrix property.
1391 bool valid = false;
sfricke-samsung7fac88a2022-01-26 11:44:22 -08001392 for (uint32_t i = 0; i < cooperative_matrix_properties.size(); ++i) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001393 if (cooperative_matrix_properties[i].AType == a.component_type &&
1394 cooperative_matrix_properties[i].MSize == a.rows && cooperative_matrix_properties[i].KSize == a.cols &&
1395 cooperative_matrix_properties[i].scope == a.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001396
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001397 cooperative_matrix_properties[i].BType == b.component_type &&
1398 cooperative_matrix_properties[i].KSize == b.rows && cooperative_matrix_properties[i].NSize == b.cols &&
1399 cooperative_matrix_properties[i].scope == b.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001400
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001401 cooperative_matrix_properties[i].CType == c.component_type &&
1402 cooperative_matrix_properties[i].MSize == c.rows && cooperative_matrix_properties[i].NSize == c.cols &&
1403 cooperative_matrix_properties[i].scope == c.scope &&
Jeff Bolze4356752019-03-07 11:23:46 -06001404
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001405 cooperative_matrix_properties[i].DType == d.component_type &&
1406 cooperative_matrix_properties[i].MSize == d.rows && cooperative_matrix_properties[i].NSize == d.cols &&
1407 cooperative_matrix_properties[i].scope == d.scope) {
Jeff Bolze4356752019-03-07 11:23:46 -06001408 valid = true;
1409 break;
1410 }
1411 }
1412 if (!valid) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06001413 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_CooperativeMatrixMulAdd,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001414 "OpCooperativeMatrixMulAddNV (result id = %u) operands don't match a supported matrix "
1415 "VkCooperativeMatrixPropertiesNV",
1416 insn.word(2));
Jeff Bolze4356752019-03-07 11:23:46 -06001417 }
1418 }
1419 break;
1420 }
1421 default:
1422 break;
1423 }
1424 }
1425
1426 return skip;
1427}
1428
sjfricke4f600c82022-06-09 14:21:32 +09001429bool CoreChecks::ValidateShaderResolveQCOM(const SHADER_MODULE_STATE &module_state,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001430 safe_VkPipelineShaderStageCreateInfo const *pStage,
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001431 const PIPELINE_STATE *pipeline) const {
1432 bool skip = false;
1433
1434 // If the pipeline's subpass description contains flag VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM,
1435 // then the fragment shader must not enable the SPIRV SampleRateShading capability.
1436 if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
sjfricke4f600c82022-06-09 14:21:32 +09001437 for (auto insn : module_state) {
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001438 switch (insn.opcode()) {
1439 case spv::OpCapability:
1440 if (insn.word(1) == spv::CapabilitySampleRateShading) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001441 const auto &rp_state = pipeline->RenderPassState();
1442 auto subpass_flags = (!rp_state) ? 0 : rp_state->createInfo.pSubpasses[pipeline->Subpass()].flags;
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001443 if ((subpass_flags & VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM) != 0) {
1444 skip |=
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001445 LogError(pipeline->pipeline(), "VUID-RuntimeSpirv-SampleRateShading-06378",
Jeff Leger9b3dcff2021-05-27 15:40:20 -04001446 "Invalid Pipeline CreateInfo State: fragment shader enables SampleRateShading capability "
1447 "and the subpass flags includes VK_SUBPASS_DESCRIPTION_FRAGMENT_REGION_BIT_QCOM.");
1448 }
1449 }
1450 break;
1451 default:
1452 break;
1453 }
1454 }
1455 }
1456
1457 return skip;
1458}
1459
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07001460bool CoreChecks::ValidateShaderSubgroupSizeControl(safe_VkPipelineShaderStageCreateInfo const *pStage) const {
ziga-lunarg73163742021-08-25 13:15:29 +02001461 bool skip = false;
1462
1463 if ((pStage->flags & VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) != 0 &&
Tony-LunarG273f32f2021-09-28 08:56:30 -06001464 !enabled_features.core13.subgroupSizeControl) {
ziga-lunarg73163742021-08-25 13:15:29 +02001465 skip |= LogError(
1466 device, "VUID-VkPipelineShaderStageCreateInfo-flags-02784",
1467 "VkPipelineShaderStageCreateInfo flags contain VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT, "
1468 "but the VkPhysicalDeviceSubgroupSizeControlFeaturesEXT::subgroupSizeControl feature is not enabled.");
1469 }
1470
1471 if ((pStage->flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) != 0 &&
Tony-LunarG273f32f2021-09-28 08:56:30 -06001472 !enabled_features.core13.computeFullSubgroups) {
ziga-lunarg73163742021-08-25 13:15:29 +02001473 skip |= LogError(
1474 device, "VUID-VkPipelineShaderStageCreateInfo-flags-02785",
1475 "VkPipelineShaderStageCreateInfo flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT, but the "
1476 "VkPhysicalDeviceSubgroupSizeControlFeaturesEXT::computeFullSubgroups feature is not enabled");
1477 }
1478
1479 return skip;
1480}
1481
sjfricke4f600c82022-06-09 14:21:32 +09001482bool CoreChecks::ValidateAtomicsTypes(const SHADER_MODULE_STATE &module_state) const {
sfricke-samsung58b84352021-07-31 21:41:04 -07001483 bool skip = false;
1484
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001485 // "If sparseImageInt64Atomics is enabled, shaderImageInt64Atomics must be enabled"
sfricke-samsung828e59d2021-08-22 23:20:49 -07001486 const bool valid_image_64_int = enabled_features.shader_image_atomic_int64_features.shaderImageInt64Atomics == VK_TRUE;
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001487
sfricke-samsungf5042b12021-08-05 01:09:40 -07001488 const VkPhysicalDeviceShaderAtomicFloatFeaturesEXT &float_features = enabled_features.shader_atomic_float_features;
1489 const VkPhysicalDeviceShaderAtomicFloat2FeaturesEXT &float2_features = enabled_features.shader_atomic_float2_features;
1490
1491 const bool valid_storage_buffer_float = (
1492 (float_features.shaderBufferFloat32Atomics == VK_TRUE) ||
1493 (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) ||
1494 (float_features.shaderBufferFloat64Atomics == VK_TRUE) ||
1495 (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) ||
1496 (float2_features.shaderBufferFloat16Atomics == VK_TRUE) ||
1497 (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) ||
1498 (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) ||
1499 (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) ||
1500 (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE));
1501
1502 const bool valid_workgroup_float = (
1503 (float_features.shaderSharedFloat32Atomics == VK_TRUE) ||
1504 (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) ||
1505 (float_features.shaderSharedFloat64Atomics == VK_TRUE) ||
1506 (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) ||
1507 (float2_features.shaderSharedFloat16Atomics == VK_TRUE) ||
1508 (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) ||
1509 (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE) ||
1510 (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) ||
1511 (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE));
1512
1513 const bool valid_image_float = (
1514 (float_features.shaderImageFloat32Atomics == VK_TRUE) ||
1515 (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) ||
1516 (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE));
1517
1518 const bool valid_16_float = (
1519 (float2_features.shaderBufferFloat16Atomics == VK_TRUE) ||
1520 (float2_features.shaderBufferFloat16AtomicAdd == VK_TRUE) ||
1521 (float2_features.shaderBufferFloat16AtomicMinMax == VK_TRUE) ||
1522 (float2_features.shaderSharedFloat16Atomics == VK_TRUE) ||
1523 (float2_features.shaderSharedFloat16AtomicAdd == VK_TRUE) ||
1524 (float2_features.shaderSharedFloat16AtomicMinMax == VK_TRUE));
1525
1526 const bool valid_32_float = (
1527 (float_features.shaderBufferFloat32Atomics == VK_TRUE) ||
1528 (float_features.shaderBufferFloat32AtomicAdd == VK_TRUE) ||
1529 (float_features.shaderSharedFloat32Atomics == VK_TRUE) ||
1530 (float_features.shaderSharedFloat32AtomicAdd == VK_TRUE) ||
1531 (float_features.shaderImageFloat32Atomics == VK_TRUE) ||
1532 (float_features.shaderImageFloat32AtomicAdd == VK_TRUE) ||
1533 (float2_features.shaderBufferFloat32AtomicMinMax == VK_TRUE) ||
1534 (float2_features.shaderSharedFloat32AtomicMinMax == VK_TRUE) ||
1535 (float2_features.shaderImageFloat32AtomicMinMax == VK_TRUE));
1536
1537 const bool valid_64_float = (
1538 (float_features.shaderBufferFloat64Atomics == VK_TRUE) ||
1539 (float_features.shaderBufferFloat64AtomicAdd == VK_TRUE) ||
1540 (float_features.shaderSharedFloat64Atomics == VK_TRUE) ||
1541 (float_features.shaderSharedFloat64AtomicAdd == VK_TRUE) ||
1542 (float2_features.shaderBufferFloat64AtomicMinMax == VK_TRUE) ||
1543 (float2_features.shaderSharedFloat64AtomicMinMax == VK_TRUE));
1544 // clang-format on
1545
sjfricke4f600c82022-06-09 14:21:32 +09001546 for (const auto &atomic_inst : module_state.GetAtomicInstructions()) {
sfricke-samsung58b84352021-07-31 21:41:04 -07001547 const atomic_instruction &atomic = atomic_inst.second;
sjfricke4f600c82022-06-09 14:21:32 +09001548 const spirv_inst_iter atomic_def = module_state.at(atomic_inst.first);
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001549 const uint32_t opcode = atomic_def.opcode();
sfricke-samsung58b84352021-07-31 21:41:04 -07001550
1551 if ((atomic.bit_width == 64) && (atomic.type == spv::OpTypeInt)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001552 // Validate 64-bit image atomics
sfricke-samsung58b84352021-07-31 21:41:04 -07001553 if (((atomic.storage_class == spv::StorageClassStorageBuffer) || (atomic.storage_class == spv::StorageClassUniform)) &&
1554 (enabled_features.core12.shaderBufferInt64Atomics == VK_FALSE)) {
sjfricke657dfdc2022-08-25 23:40:32 +09001555 skip |=
1556 LogError(device, "VUID-RuntimeSpirv-None-06278",
1557 "%s: Can't use 64-bit int atomics operations\n%s\nwith %s storage class without "
1558 "shaderBufferInt64Atomics enabled.",
1559 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1560 module_state.DescribeInstruction(atomic_def).c_str(), string_SpvStorageClass(atomic.storage_class));
sfricke-samsung58b84352021-07-31 21:41:04 -07001561 } else if ((atomic.storage_class == spv::StorageClassWorkgroup) &&
1562 (enabled_features.core12.shaderSharedInt64Atomics == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001563 skip |= LogError(device, "VUID-RuntimeSpirv-None-06279",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001564 "%s: Can't use 64-bit int atomics operations\n%s\nwith Workgroup storage class without "
sfricke-samsung58b84352021-07-31 21:41:04 -07001565 "shaderSharedInt64Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001566 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1567 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001568 } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_64_int == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001569 skip |= LogError(device, "VUID-RuntimeSpirv-None-06288",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001570 "%s: Can't use 64-bit int atomics operations\n%s\nwith Image storage class without "
sfricke-samsung6c9eb712021-08-04 09:38:54 -07001571 "shaderImageInt64Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001572 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1573 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsung58b84352021-07-31 21:41:04 -07001574 }
sfricke-samsungf5042b12021-08-05 01:09:40 -07001575 } else if (atomic.type == spv::OpTypeFloat) {
1576 // Validate Floats
1577 if (atomic.storage_class == spv::StorageClassStorageBuffer) {
1578 if (valid_storage_buffer_float == false) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001579 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06284"
1580 : "VUID-RuntimeSpirv-None-06280";
1581 skip |= LogError(device, vuid,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001582 "%s: Can't use float atomics operations\n%s\nwith StorageBuffer storage class without "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001583 "shaderBufferFloat32Atomics or shaderBufferFloat32AtomicAdd or shaderBufferFloat64Atomics or "
1584 "shaderBufferFloat64AtomicAdd or shaderBufferFloat16Atomics or shaderBufferFloat16AtomicAdd "
1585 "or shaderBufferFloat16AtomicMinMax or shaderBufferFloat32AtomicMinMax or "
1586 "shaderBufferFloat64AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001587 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1588 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001589 } else if (opcode == spv::OpAtomicFAddEXT) {
1590 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicAdd == VK_FALSE)) {
1591 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001592 "%s: Can't use 16-bit float atomics for add operations\n%s\nwith "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001593 "StorageBuffer storage class without shaderBufferFloat16AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001594 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1595 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001596 } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32AtomicAdd == VK_FALSE)) {
1597 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001598 "%s: Can't use 32-bit float atomics for add operations\n%s\nwith "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001599 "StorageBuffer storage class without shaderBufferFloat32AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001600 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1601 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001602 } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64AtomicAdd == VK_FALSE)) {
1603 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001604 "%s: Can't use 64-bit float atomics for add operations\n%s\nwith "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001605 "StorageBuffer storage class without shaderBufferFloat64AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001606 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1607 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001608 }
1609 } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) {
1610 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001611 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1612 "%s: Can't use 16-bit float atomics for min/max operations\n%s\nwith "
1613 "StorageBuffer storage class without shaderBufferFloat16AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001614 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1615 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001616 } else if ((atomic.bit_width == 32) && (float2_features.shaderBufferFloat32AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001617 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1618 "%s: Can't use 32-bit float atomics for min/max operations\n%s\nwith "
1619 "StorageBuffer storage class without shaderBufferFloat32AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001620 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1621 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001622 } else if ((atomic.bit_width == 64) && (float2_features.shaderBufferFloat64AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001623 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1624 "%s: Can't use 64-bit float atomics for min/max operations\n%s\nwith "
1625 "StorageBuffer storage class without shaderBufferFloat64AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001626 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1627 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001628 }
1629 } else {
1630 // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch
1631 if ((atomic.bit_width == 16) && (float2_features.shaderBufferFloat16Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001632 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1633 "%s: Can't use 16-bit float atomics for load/store/exhange operations\n%s\nwith "
1634 "StorageBuffer storage class without shaderBufferFloat16Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001635 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1636 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001637 } else if ((atomic.bit_width == 32) && (float_features.shaderBufferFloat32Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001638 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1639 "%s: Can't use 32-bit float atomics for load/store/exhange operations\n%s\nwith "
1640 "StorageBuffer storage class without shaderBufferFloat32Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001641 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1642 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001643 } else if ((atomic.bit_width == 64) && (float_features.shaderBufferFloat64Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001644 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1645 "%s: Can't use 64-bit float atomics for load/store/exhange operations\n%s\nwith "
1646 "StorageBuffer storage class without shaderBufferFloat64Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001647 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1648 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001649 }
1650 }
1651 } else if (atomic.storage_class == spv::StorageClassWorkgroup) {
1652 if (valid_workgroup_float == false) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001653 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06285"
1654 : "VUID-RuntimeSpirv-None-06281";
sfricke-samsungef15e482022-01-26 11:32:49 -08001655 skip |=
1656 LogError(device, vuid,
1657 "%s: Can't use float atomics operations\n%s\nwith Workgroup storage class without "
1658 "shaderSharedFloat32Atomics or "
1659 "shaderSharedFloat32AtomicAdd or shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd or "
1660 "shaderSharedFloat16Atomics or shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax or "
1661 "shaderSharedFloat32AtomicMinMax or shaderSharedFloat64AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001662 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1663 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001664 } else if (opcode == spv::OpAtomicFAddEXT) {
1665 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicAdd == VK_FALSE)) {
1666 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001667 "%s: Can't use 16-bit float atomics for add operations\n%s\nwith Workgroup "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001668 "storage class without shaderSharedFloat16AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001669 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1670 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001671 } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32AtomicAdd == VK_FALSE)) {
1672 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001673 "%s: Can't use 32-bit float atomics for add operations\n%s\nwith Workgroup "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001674 "storage class without shaderSharedFloat32AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001675 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1676 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001677 } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64AtomicAdd == VK_FALSE)) {
1678 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001679 "%s: Can't use 64-bit float atomics for add operations\n%s\nwith Workgroup "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001680 "storage class without shaderSharedFloat64AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001681 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1682 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001683 }
1684 } else if (opcode == spv::OpAtomicFMinEXT || opcode == spv::OpAtomicFMaxEXT) {
1685 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001686 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1687 "%s: Can't use 16-bit float atomics for min/max operations\n%s\nwith "
1688 "Workgroup storage class without shaderSharedFloat16AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001689 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1690 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001691 } else if ((atomic.bit_width == 32) && (float2_features.shaderSharedFloat32AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001692 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1693 "%s: Can't use 32-bit float atomics for min/max operations\n%s\nwith "
1694 "Workgroup storage class without shaderSharedFloat32AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001695 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1696 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001697 } else if ((atomic.bit_width == 64) && (float2_features.shaderSharedFloat64AtomicMinMax == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001698 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1699 "%s: Can't use 64-bit float atomics for min/max operations\n%s\nwith "
1700 "Workgroup storage class without shaderSharedFloat64AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001701 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1702 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001703 }
1704 } else {
1705 // Assume is valid load/store/exchange (rest of supported atomic operations) or else spirv-val will catch
1706 if ((atomic.bit_width == 16) && (float2_features.shaderSharedFloat16Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001707 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1708 "%s: Can't use 16-bit float atomics for load/store/exhange operations\n%s\nwith Workgroup "
1709 "storage class without shaderSharedFloat16Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001710 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1711 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001712 } else if ((atomic.bit_width == 32) && (float_features.shaderSharedFloat32Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001713 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1714 "%s: Can't use 32-bit float atomics for load/store/exhange operations\n%s\nwith Workgroup "
1715 "storage class without shaderSharedFloat32Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001716 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1717 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001718 } else if ((atomic.bit_width == 64) && (float_features.shaderSharedFloat64Atomics == VK_FALSE)) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001719 skip |= LogError(device, kVUID_Core_Shader_AtomicFeature,
1720 "%s: Can't use 64-bit float atomics for load/store/exhange operations\n%s\nwith Workgroup "
1721 "storage class without shaderSharedFloat64Atomics enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001722 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1723 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001724 }
1725 }
1726 } else if ((atomic.storage_class == spv::StorageClassImage) && (valid_image_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001727 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06286"
1728 : "VUID-RuntimeSpirv-None-06282";
sfricke-samsung73f1a0f2021-10-28 23:27:25 -07001729 skip |= LogError(
1730 device, vuid,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001731 "%s: Can't use float atomics operations\n%s\nwith Image storage class without shaderImageFloat32Atomics or "
sfricke-samsung73f1a0f2021-10-28 23:27:25 -07001732 "shaderImageFloat32AtomicAdd or shaderImageFloat32AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001733 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1734 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001735 } else if ((atomic.bit_width == 16) && (valid_16_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001736 skip |= LogError(device, "VUID-RuntimeSpirv-None-06337",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001737 "%s: Can't use 16-bit float atomics operations\n%s\nwithout shaderBufferFloat16Atomics, "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001738 "shaderBufferFloat16AtomicAdd, shaderBufferFloat16AtomicMinMax, shaderSharedFloat16Atomics, "
1739 "shaderSharedFloat16AtomicAdd or shaderSharedFloat16AtomicMinMax enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001740 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1741 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001742 } else if ((atomic.bit_width == 32) && (valid_32_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001743 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06338"
1744 : "VUID-RuntimeSpirv-None-06335";
1745 skip |= LogError(device, vuid,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001746 "%s: Can't use 32-bit float atomics operations\n%s\nwithout shaderBufferFloat32AtomicMinMax, "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001747 "shaderSharedFloat32AtomicMinMax, shaderImageFloat32AtomicMinMax, sparseImageFloat32AtomicMinMax, "
1748 "shaderBufferFloat32Atomics, shaderBufferFloat32AtomicAdd, shaderSharedFloat32Atomics, "
1749 "shaderSharedFloat32AtomicAdd, shaderImageFloat32Atomics, shaderImageFloat32AtomicAdd, "
1750 "sparseImageFloat32Atomics or sparseImageFloat32AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001751 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1752 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001753 } else if ((atomic.bit_width == 64) && (valid_64_float == false)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001754 const char *vuid = IsExtEnabled(device_extensions.vk_ext_shader_atomic_float2) ? "VUID-RuntimeSpirv-None-06339"
1755 : "VUID-RuntimeSpirv-None-06336";
1756 skip |= LogError(device, vuid,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08001757 "%s: Can't use 64-bit float atomics operations\n%s\nwithout shaderBufferFloat64AtomicMinMax, "
sfricke-samsungf5042b12021-08-05 01:09:40 -07001758 "shaderSharedFloat64AtomicMinMax, shaderBufferFloat64Atomics, shaderBufferFloat64AtomicAdd, "
1759 "shaderSharedFloat64Atomics or shaderSharedFloat64AtomicAdd enabled.",
sjfricke4f600c82022-06-09 14:21:32 +09001760 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
1761 module_state.DescribeInstruction(atomic_def).c_str());
sfricke-samsungf5042b12021-08-05 01:09:40 -07001762 }
sfricke-samsung58b84352021-07-31 21:41:04 -07001763 }
1764 }
sfricke-samsung58b84352021-07-31 21:41:04 -07001765 return skip;
1766}
1767
sjfricke4f600c82022-06-09 14:21:32 +09001768bool CoreChecks::ValidateExecutionModes(const SHADER_MODULE_STATE &module_state, spirv_inst_iter entrypoint,
sfricke-samsungef15e482022-01-26 11:32:49 -08001769 VkShaderStageFlagBits stage, const PIPELINE_STATE *pipeline) const {
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001770 auto entrypoint_id = entrypoint.word(2);
1771
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001772 // The first denorm execution mode encountered, along with its bit width.
1773 // Used to check if SeparateDenormSettings is respected.
1774 std::pair<spv::ExecutionMode, uint32_t> first_denorm_execution_mode = std::make_pair(spv::ExecutionModeMax, 0);
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001775
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001776 // The first rounding mode encountered, along with its bit width.
1777 // Used to check if SeparateRoundingModeSettings is respected.
1778 std::pair<spv::ExecutionMode, uint32_t> first_rounding_mode = std::make_pair(spv::ExecutionModeMax, 0);
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001779
1780 bool skip = false;
1781
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07001782 uint32_t vertices_out = 0;
Jeff Bolze9ee3d82019-05-29 13:45:13 -05001783 uint32_t invocations = 0;
1784
sjfricke4f600c82022-06-09 14:21:32 +09001785 const auto &execution_mode_inst = module_state.GetExecutionModeInstructions();
Nathaniel Cesario77cd59b2021-10-11 23:52:24 -06001786 auto it = execution_mode_inst.find(entrypoint_id);
1787 if (it != execution_mode_inst.end()) {
sfricke-samsung8a7341a2021-02-28 07:30:21 -08001788 for (auto insn : it->second) {
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001789 auto mode = insn.word(2);
1790 switch (mode) {
1791 case spv::ExecutionModeSignedZeroInfNanPreserve: {
1792 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001793 if (bit_width == 16 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat16) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001794 skip |= LogError(
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001795 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat16-06293",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001796 "Shader requires SignedZeroInfNanPreserve for bit width 16 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001797 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001798 } else if (bit_width == 32 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat32) {
1799 skip |= LogError(
1800 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat32-06294",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001801 "Shader requires SignedZeroInfNanPreserve for bit width 32 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001802 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001803 } else if (bit_width == 64 && !phys_dev_props_core12.shaderSignedZeroInfNanPreserveFloat64) {
1804 skip |= LogError(
1805 device, "VUID-RuntimeSpirv-shaderSignedZeroInfNanPreserveFloat64-06295",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001806 "Shader requires SignedZeroInfNanPreserve for bit width 64 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001807 module_state.DescribeInstruction(insn).c_str());
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001808 }
1809 break;
1810 }
1811
1812 case spv::ExecutionModeDenormPreserve: {
1813 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001814 if (bit_width == 16 && !phys_dev_props_core12.shaderDenormPreserveFloat16) {
1815 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat16-06296",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001816 "Shader requires DenormPreserve for bit width 16 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001817 module_state.DescribeInstruction(insn).c_str());
sfricke-samsunged00aa42022-01-27 19:03:01 -08001818 ;
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001819 } else if (bit_width == 32 && !phys_dev_props_core12.shaderDenormPreserveFloat32) {
1820 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat32-06297",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001821 "Shader requires DenormPreserve for bit width 32 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001822 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001823 } else if (bit_width == 64 && !phys_dev_props_core12.shaderDenormPreserveFloat64) {
1824 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDenormPreserveFloat64-06298",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001825 "Shader requires DenormPreserve for bit width 64 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001826 module_state.DescribeInstruction(insn).c_str());
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001827 }
1828
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001829 if (first_denorm_execution_mode.first == spv::ExecutionModeMax) {
1830 // Register the first denorm execution mode found
1831 first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001832 } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001833 switch (phys_dev_props_core12.denormBehaviorIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001834 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001835 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001836 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06289",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001837 "Shader uses different denorm execution modes for 16 and 64-bit but "
1838 "denormBehaviorIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001839 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001840 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001841 }
1842 break;
1843
Mike Schuchardt2df08912020-12-15 16:28:09 -08001844 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001845 break;
1846
Mike Schuchardt2df08912020-12-15 16:28:09 -08001847 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001848 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06290",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001849 "Shader uses different denorm execution modes for different bit widths but "
1850 "denormBehaviorIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001851 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001852 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001853 break;
1854
1855 default:
1856 break;
1857 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001858 }
1859 break;
1860 }
1861
1862 case spv::ExecutionModeDenormFlushToZero: {
1863 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001864 if (bit_width == 16 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat16) {
sfricke-samsunged00aa42022-01-27 19:03:01 -08001865 skip |=
1866 LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat16-06299",
1867 "Shader requires DenormFlushToZero for bit width 16 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001868 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001869 } else if (bit_width == 32 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat32) {
sfricke-samsunged00aa42022-01-27 19:03:01 -08001870 skip |=
1871 LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat32-06300",
1872 "Shader requires DenormFlushToZero for bit width 32 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001873 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001874 } else if (bit_width == 64 && !phys_dev_props_core12.shaderDenormFlushToZeroFloat64) {
sfricke-samsunged00aa42022-01-27 19:03:01 -08001875 skip |=
1876 LogError(device, "VUID-RuntimeSpirv-shaderDenormFlushToZeroFloat64-06301",
1877 "Shader requires DenormFlushToZero for bit width 64 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001878 module_state.DescribeInstruction(insn).c_str());
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001879 }
1880
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001881 if (first_denorm_execution_mode.first == spv::ExecutionModeMax) {
1882 // Register the first denorm execution mode found
1883 first_denorm_execution_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001884 } else if (first_denorm_execution_mode.first != mode && first_denorm_execution_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001885 switch (phys_dev_props_core12.denormBehaviorIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001886 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001887 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001888 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06289",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001889 "Shader uses different denorm execution modes for 16 and 64-bit but "
1890 "denormBehaviorIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001891 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001892 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001893 }
1894 break;
1895
Mike Schuchardt2df08912020-12-15 16:28:09 -08001896 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001897 break;
1898
Mike Schuchardt2df08912020-12-15 16:28:09 -08001899 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001900 skip |= LogError(device, "VUID-RuntimeSpirv-denormBehaviorIndependence-06290",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001901 "Shader uses different denorm execution modes for different bit widths but "
1902 "denormBehaviorIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001903 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001904 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001905 break;
1906
1907 default:
1908 break;
1909 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001910 }
1911 break;
1912 }
1913
1914 case spv::ExecutionModeRoundingModeRTE: {
1915 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001916 if (bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTEFloat16) {
1917 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat16-06302",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001918 "Shader requires RoundingModeRTE for bit width 16 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001919 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001920 } else if (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTEFloat32) {
1921 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat32-06303",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001922 "Shader requires RoundingModeRTE for bit width 32 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001923 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001924 } else if (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTEFloat64) {
1925 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTEFloat64-06304",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001926 "Shader requires RoundingModeRTE for bit width 64 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001927 module_state.DescribeInstruction(insn).c_str());
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001928 }
1929
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001930 if (first_rounding_mode.first == spv::ExecutionModeMax) {
1931 // Register the first rounding mode found
1932 first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001933 } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001934 switch (phys_dev_props_core12.roundingModeIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001935 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001936 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001937 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06291",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001938 "Shader uses different rounding modes for 16 and 64-bit but "
1939 "roundingModeIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001940 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001941 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001942 }
1943 break;
1944
Mike Schuchardt2df08912020-12-15 16:28:09 -08001945 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001946 break;
1947
Mike Schuchardt2df08912020-12-15 16:28:09 -08001948 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001949 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06292",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001950 "Shader uses different rounding modes for different bit widths but "
1951 "roundingModeIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001952 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001953 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001954 break;
1955
1956 default:
1957 break;
1958 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001959 }
1960 break;
1961 }
1962
1963 case spv::ExecutionModeRoundingModeRTZ: {
1964 auto bit_width = insn.word(3);
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001965 if (bit_width == 16 && !phys_dev_props_core12.shaderRoundingModeRTZFloat16) {
1966 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat16-06305",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001967 "Shader requires RoundingModeRTZ for bit width 16 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001968 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001969 } else if (bit_width == 32 && !phys_dev_props_core12.shaderRoundingModeRTZFloat32) {
1970 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat32-06306",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001971 "Shader requires RoundingModeRTZ for bit width 32 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001972 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001973 } else if (bit_width == 64 && !phys_dev_props_core12.shaderRoundingModeRTZFloat64) {
1974 skip |= LogError(device, "VUID-RuntimeSpirv-shaderRoundingModeRTZFloat64-06307",
sfricke-samsunged00aa42022-01-27 19:03:01 -08001975 "Shader requires RoundingModeRTZ for bit width 64 but it is not enabled on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001976 module_state.DescribeInstruction(insn).c_str());
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00001977 }
1978
Attilio Provenzanof6c0e852019-04-09 11:01:18 +01001979 if (first_rounding_mode.first == spv::ExecutionModeMax) {
1980 // Register the first rounding mode found
1981 first_rounding_mode = std::make_pair(static_cast<spv::ExecutionMode>(mode), bit_width);
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001982 } else if (first_rounding_mode.first != mode && first_rounding_mode.second != bit_width) {
Piers Daniell41b8c5d2020-01-10 15:42:00 -07001983 switch (phys_dev_props_core12.roundingModeIndependence) {
Mike Schuchardt2df08912020-12-15 16:28:09 -08001984 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001985 if (first_rounding_mode.second != 32 && bit_width != 32) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001986 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06291",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001987 "Shader uses different rounding modes for 16 and 64-bit but "
1988 "roundingModeIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08001989 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_32_BIT_ONLY on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09001990 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001991 }
1992 break;
1993
Mike Schuchardt2df08912020-12-15 16:28:09 -08001994 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_ALL:
Jason Ekstrande1e06de2019-08-05 11:43:43 -05001995 break;
1996
Mike Schuchardt2df08912020-12-15 16:28:09 -08001997 case VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE:
sfricke-samsung1ff329f2021-09-16 10:06:47 -07001998 skip |= LogError(device, "VUID-RuntimeSpirv-roundingModeIndependence-06292",
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07001999 "Shader uses different rounding modes for different bit widths but "
2000 "roundingModeIndependence is "
sfricke-samsunged00aa42022-01-27 19:03:01 -08002001 "VK_SHADER_FLOAT_CONTROLS_INDEPENDENCE_NONE on the device\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09002002 module_state.DescribeInstruction(insn).c_str());
Jason Ekstrande1e06de2019-08-05 11:43:43 -05002003 break;
2004
2005 default:
2006 break;
2007 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00002008 }
2009 break;
2010 }
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002011
2012 case spv::ExecutionModeOutputVertices: {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002013 vertices_out = insn.word(3);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002014 break;
2015 }
2016
2017 case spv::ExecutionModeInvocations: {
2018 invocations = insn.word(3);
2019 break;
2020 }
Piers Daniella7f93b62021-11-20 12:32:04 -07002021
2022 case spv::ExecutionModeLocalSizeId: {
Tony-LunarG273f32f2021-09-28 08:56:30 -06002023 if (!enabled_features.core13.maintenance4) {
Piers Daniella7f93b62021-11-20 12:32:04 -07002024 skip |= LogError(device, "VUID-RuntimeSpirv-LocalSizeId-06434",
2025 "LocalSizeId execution mode used but maintenance4 feature not enabled");
2026 }
ziga-lunargf2aa8152022-04-17 13:03:29 +02002027 if (!IsExtEnabled(device_extensions.vk_khr_maintenance4)) {
2028 skip |= LogError(device, "VUID-RuntimeSpirv-LocalSizeId-06433",
2029 "LocalSizeId execution mode used but maintenance4 extension is not enabled and used Vulkan api version is 1.2 or less");
2030 }
Piers Daniella7f93b62021-11-20 12:32:04 -07002031 break;
2032 }
Younggwan Kim26b9abd2021-12-07 21:22:03 +00002033
2034 case spv::ExecutionModeEarlyFragmentTests: {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002035 const auto *ds_state = (pipeline) ? pipeline->DepthStencilState() : nullptr;
Younggwan Kim26b9abd2021-12-07 21:22:03 +00002036 if ((stage == VK_SHADER_STAGE_FRAGMENT_BIT) &&
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002037 (ds_state &&
2038 (ds_state->flags &
Younggwan Kim26b9abd2021-12-07 21:22:03 +00002039 (VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_DEPTH_ACCESS_BIT_ARM |
2040 VK_PIPELINE_DEPTH_STENCIL_STATE_CREATE_RASTERIZATION_ORDER_ATTACHMENT_STENCIL_ACCESS_BIT_ARM)) != 0)) {
2041 skip |= LogError(
Nathaniel Cesario6a0ce2f2022-04-02 21:47:54 -06002042 device, "VUID-VkGraphicsPipelineCreateInfo-flags-06591",
Younggwan Kim26b9abd2021-12-07 21:22:03 +00002043 "The fragment shader enables early fragment tests, but VkPipelineDepthStencilStateCreateInfo::flags == "
2044 "%s",
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002045 string_VkPipelineDepthStencilStateCreateFlags(ds_state->flags).c_str());
Younggwan Kim26b9abd2021-12-07 21:22:03 +00002046 }
2047 break;
2048 }
ziga-lunarge25f5f02022-04-16 15:07:35 +02002049 case spv::ExecutionModeSubgroupUniformControlFlowKHR: {
2050 if (!enabled_features.shader_subgroup_uniform_control_flow_features.shaderSubgroupUniformControlFlow ||
2051 (phys_dev_ext_props.subgroup_properties.supportedStages & stage) == 0 ||
sjfricke4f600c82022-06-09 14:21:32 +09002052 module_state.static_data_.has_invocation_repack_instruction) {
ziga-lunarge25f5f02022-04-16 15:07:35 +02002053 std::stringstream msg;
2054 if (!enabled_features.shader_subgroup_uniform_control_flow_features.shaderSubgroupUniformControlFlow) {
2055 msg << "shaderSubgroupUniformControlFlow feature must be enabled";
2056 } else if ((phys_dev_ext_props.subgroup_properties.supportedStages & stage) == 0) {
2057 msg << "stage" << string_VkShaderStageFlagBits(stage)
2058 << " must be in VkPhysicalDeviceSubgroupProperties::supportedStages("
2059 << string_VkShaderStageFlags(phys_dev_ext_props.subgroup_properties.supportedStages) << ")";
2060 } else {
2061 msg << "the shader must not use any invocation repack instructions";
2062 }
2063 skip |= LogError(device, "VUID-RuntimeSpirv-SubgroupUniformControlFlowKHR-06379",
2064 "If ExecutionModeSubgroupUniformControlFlowKHR is used %s.", msg.str().c_str());
2065 }
2066 } break;
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00002067 }
2068 }
2069 }
2070
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002071 if (entrypoint.word(1) == spv::ExecutionModelGeometry) {
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002072 if (vertices_out == 0 || vertices_out > phys_dev_props.limits.maxGeometryOutputVertices) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002073 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00714",
2074 "Geometry shader entry point must have an OpExecutionMode instruction that "
2075 "specifies a maximum output vertex count that is greater than 0 and less "
2076 "than or equal to maxGeometryOutputVertices. "
2077 "OutputVertices=%d, maxGeometryOutputVertices=%d",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07002078 vertices_out, phys_dev_props.limits.maxGeometryOutputVertices);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002079 }
2080
2081 if (invocations == 0 || invocations > phys_dev_props.limits.maxGeometryShaderInvocations) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002082 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-stage-00715",
2083 "Geometry shader entry point must have an OpExecutionMode instruction that "
2084 "specifies an invocation count that is greater than 0 and less "
2085 "than or equal to maxGeometryShaderInvocations. "
2086 "Invocations=%d, maxGeometryShaderInvocations=%d",
2087 invocations, phys_dev_props.limits.maxGeometryShaderInvocations);
Jeff Bolze9ee3d82019-05-29 13:45:13 -05002088 }
2089 }
Attilio Provenzanoc5d50102019-03-25 17:40:37 +00002090 return skip;
2091}
2092
Chris Forbes47567b72017-06-09 12:09:45 -07002093// For given pipelineLayout verify that the set_layout_node at slot.first
2094// has the requested binding at slot.second and return ptr to that binding
Mark Lobodzinskica6ebe32019-04-25 11:43:37 -06002095static VkDescriptorSetLayoutBinding const *GetDescriptorBinding(PIPELINE_LAYOUT_STATE const *pipelineLayout,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002096 DescriptorSlot slot) {
Chris Forbes47567b72017-06-09 12:09:45 -07002097 if (!pipelineLayout) return nullptr;
2098
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002099 if (slot.set >= pipelineLayout->set_layouts.size()) return nullptr;
Chris Forbes47567b72017-06-09 12:09:45 -07002100
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06002101 return pipelineLayout->set_layouts[slot.set]->GetDescriptorSetLayoutBindingPtrFromBinding(slot.binding);
Chris Forbes47567b72017-06-09 12:09:45 -07002102}
2103
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002104// If PointList topology is specified in the pipeline, verify that a shader geometry stage writes PointSize
2105// o If there is only a vertex shader : gl_PointSize must be written when using points
2106// o If there is a geometry or tessellation shader:
2107// - If shaderTessellationAndGeometryPointSize feature is enabled:
2108// * gl_PointSize must be written in the final geometry stage
2109// - If shaderTessellationAndGeometryPointSize feature is disabled:
2110// * gl_PointSize must NOT be written and a default of 1.0 is assumed
sjfricke4f600c82022-06-09 14:21:32 +09002111bool CoreChecks::ValidatePointListShaderState(const PIPELINE_STATE *pipeline, const SHADER_MODULE_STATE &module_state,
John Zulaufac4c6e12019-07-01 16:05:58 -06002112 spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002113 if (pipeline->topology_at_rasterizer != VK_PRIMITIVE_TOPOLOGY_POINT_LIST) {
2114 return false;
2115 }
2116
2117 bool pointsize_written = false;
2118 bool skip = false;
2119
2120 // Search for PointSize built-in decorations
sjfricke4f600c82022-06-09 14:21:32 +09002121 for (const auto &set : module_state.GetBuiltinDecorationList()) {
2122 auto insn = module_state.at(set.offset);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002123 if (set.builtin == spv::BuiltInPointSize) {
sjfricke4f600c82022-06-09 14:21:32 +09002124 pointsize_written = module_state.IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002125 if (pointsize_written) {
2126 break;
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002127 }
2128 }
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002129 }
2130
2131 if ((stage == VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT || stage == VK_SHADER_STAGE_GEOMETRY_BIT) &&
Mark Lobodzinskid7b03cc2019-04-19 14:23:10 -06002132 !enabled_features.core.shaderTessellationAndGeometryPointSize) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002133 if (pointsize_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002134 skip |= LogError(pipeline->pipeline(), kVUID_Core_Shader_PointSizeBuiltInOverSpecified,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002135 "Pipeline topology is set to POINT_LIST and geometry or tessellation shaders write PointSize which "
2136 "is prohibited when the shaderTessellationAndGeometryPointSize feature is not enabled.");
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002137 }
2138 } else if (!pointsize_written) {
2139 skip |=
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002140 LogError(pipeline->pipeline(), kVUID_Core_Shader_MissingPointSizeBuiltIn,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002141 "Pipeline topology is set to POINT_LIST, but PointSize is not written to in the shader corresponding to %s.",
2142 string_VkShaderStageFlagBits(stage));
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002143 }
2144 return skip;
2145}
John Zulauf14c355b2019-06-27 16:09:37 -06002146
sjfricke4f600c82022-06-09 14:21:32 +09002147bool CoreChecks::ValidatePrimitiveRateShaderState(const PIPELINE_STATE *pipeline, const SHADER_MODULE_STATE &module_state,
Tobias Hector6663c9b2020-11-05 10:18:02 +00002148 spirv_inst_iter entrypoint, VkShaderStageFlagBits stage) const {
2149 bool primitiverate_written = false;
2150 bool viewportindex_written = false;
2151 bool viewportmask_written = false;
2152 bool skip = false;
2153
2154 // Check if the primitive shading rate is written
sjfricke4f600c82022-06-09 14:21:32 +09002155 for (const auto &set : module_state.GetBuiltinDecorationList()) {
2156 auto insn = module_state.at(set.offset);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002157 if (set.builtin == spv::BuiltInPrimitiveShadingRateKHR) {
sjfricke4f600c82022-06-09 14:21:32 +09002158 primitiverate_written = module_state.IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002159 } else if (set.builtin == spv::BuiltInViewportIndex) {
sjfricke4f600c82022-06-09 14:21:32 +09002160 viewportindex_written = module_state.IsBuiltInWritten(insn, entrypoint);
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002161 } else if (set.builtin == spv::BuiltInViewportMaskNV) {
sjfricke4f600c82022-06-09 14:21:32 +09002162 viewportmask_written = module_state.IsBuiltInWritten(insn, entrypoint);
Tobias Hector6663c9b2020-11-05 10:18:02 +00002163 }
sfricke-samsungc0eb5282021-02-28 23:05:55 -08002164 if (primitiverate_written && viewportindex_written && viewportmask_written) {
2165 break;
2166 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00002167 }
2168
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002169 const auto viewport_state = pipeline->ViewportState();
Tony-LunarGd44844c2021-01-22 13:24:37 -07002170 if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports &&
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002171 (pipeline->GetPipelineType() == VK_PIPELINE_BIND_POINT_GRAPHICS) && viewport_state) {
2172 if (!IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) && viewport_state->viewportCount > 1 &&
2173 primitiverate_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002174 skip |= LogError(pipeline->pipeline(),
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07002175 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04503",
2176 "vkCreateGraphicsPipelines: %s shader statically writes to PrimitiveShadingRateKHR built-in, but "
2177 "multiple viewports "
2178 "are used and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2179 string_VkShaderStageFlagBits(stage));
Tobias Hector6663c9b2020-11-05 10:18:02 +00002180 }
2181
2182 if (primitiverate_written && viewportindex_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002183 skip |= LogError(pipeline->pipeline(),
Tobias Hector6663c9b2020-11-05 10:18:02 +00002184 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04504",
2185 "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and "
2186 "ViewportIndex built-ins,"
2187 "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2188 string_VkShaderStageFlagBits(stage));
2189 }
2190
2191 if (primitiverate_written && viewportmask_written) {
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06002192 skip |= LogError(pipeline->pipeline(),
Tobias Hector6663c9b2020-11-05 10:18:02 +00002193 "VUID-VkGraphicsPipelineCreateInfo-primitiveFragmentShadingRateWithMultipleViewports-04505",
2194 "vkCreateGraphicsPipelines: %s shader statically writes to both PrimitiveShadingRateKHR and "
2195 "ViewportMaskNV built-ins,"
2196 "but the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
2197 string_VkShaderStageFlagBits(stage));
2198 }
2199 }
2200 return skip;
2201}
2202
sjfricke4f600c82022-06-09 14:21:32 +09002203bool CoreChecks::ValidateDecorations(const SHADER_MODULE_STATE &module_state) const {
ziga-lunargce66e542021-09-19 00:11:14 +02002204 bool skip = false;
2205
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002206 std::vector<spirv_inst_iter> xfb_streams;
2207 std::vector<spirv_inst_iter> xfb_buffers;
ziga-lunargef2c3172021-11-07 10:35:29 +01002208 std::vector<spirv_inst_iter> xfb_offsets;
2209
sjfricke4f600c82022-06-09 14:21:32 +09002210 for (const auto &op_decorate : module_state.GetDecorationInstructions()) {
ziga-lunargce66e542021-09-19 00:11:14 +02002211 uint32_t decoration = op_decorate.word(2);
2212 if (decoration == spv::DecorationXfbStride) {
2213 uint32_t stride = op_decorate.word(3);
2214 if (stride > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride) {
2215 skip |= LogError(
2216 device, "VUID-RuntimeSpirv-XfbStride-06313",
2217 "vkCreateGraphicsPipelines(): shader uses transform feedback with xfb_stride (%" PRIu32
2218 ") greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBufferDataStride (%" PRIu32
2219 ").",
2220 stride, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataStride);
2221 }
2222 }
ziga-lunarg423cf212021-11-07 00:00:27 +01002223 if (decoration == spv::DecorationStream) {
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002224 xfb_streams.push_back(op_decorate);
ziga-lunarg423cf212021-11-07 00:00:27 +01002225 uint32_t stream = op_decorate.word(3);
2226 if (stream >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams) {
2227 skip |= LogError(
2228 device, "VUID-RuntimeSpirv-Stream-06312",
2229 "vkCreateGraphicsPipelines(): shader uses transform feedback with stream (%" PRIu32
2230 ") not less than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackStreams (%" PRIu32 ").",
2231 stream, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams);
2232 }
2233 }
ziga-lunargef2c3172021-11-07 10:35:29 +01002234 if (decoration == spv::DecorationXfbBuffer) {
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002235 xfb_buffers.push_back(op_decorate);
ziga-lunargef2c3172021-11-07 10:35:29 +01002236 }
2237 if (decoration == spv::DecorationOffset) {
2238 xfb_offsets.push_back(op_decorate);
2239 }
2240 }
2241
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002242 // XfbBuffer, buffer data size
2243 std::vector<std::pair<uint32_t, uint32_t>> buffer_data_sizes;
ziga-lunargef2c3172021-11-07 10:35:29 +01002244 for (const auto &op_decorate : xfb_offsets) {
2245 for (const auto xfb_buffer : xfb_buffers) {
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002246 if (xfb_buffer.word(1) == op_decorate.word(1)) {
ziga-lunargef2c3172021-11-07 10:35:29 +01002247 const auto offset = op_decorate.word(3);
sjfricke4f600c82022-06-09 14:21:32 +09002248 const auto def = module_state.get_def(xfb_buffer.word(1));
2249 const auto size = module_state.GetTypeBytesSize(def);
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002250 const uint32_t buffer_data_size = offset + size;
2251 if (buffer_data_size > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataSize) {
ziga-lunargef2c3172021-11-07 10:35:29 +01002252 skip |= LogError(
2253 device, "VUID-RuntimeSpirv-Offset-06308",
2254 "vkCreateGraphicsPipelines(): shader uses transform feedback with xfb_offset (%" PRIu32
2255 ") + size of variable (%" PRIu32 ") greater than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBufferDataSize "
2256 "(%" PRIu32 ").",
2257 offset, size, phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataSize);
2258 }
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002259
2260 bool found = false;
2261 for (auto &bds : buffer_data_sizes) {
2262 if (bds.first == xfb_buffer.word(1)) {
2263 bds.second = std::max(bds.second, buffer_data_size);
2264 found = true;
2265 break;
2266 }
2267 }
2268 if (!found) {
2269 buffer_data_sizes.emplace_back(xfb_buffer.word(1), buffer_data_size);
2270 }
2271
ziga-lunargef2c3172021-11-07 10:35:29 +01002272 break;
2273 }
2274 }
ziga-lunargce66e542021-09-19 00:11:14 +02002275 }
2276
ziga-lunargfe45a7c2021-11-10 15:37:04 +01002277 std::unordered_map<uint32_t, uint32_t> stream_data_size;
2278 for (const auto &xfb_stream : xfb_streams) {
2279 for (const auto& bds : buffer_data_sizes) {
2280 if (xfb_stream.word(1) == bds.first) {
2281 uint32_t stream = xfb_stream.word(3);
2282 const auto itr = stream_data_size.find(stream);
2283 if (itr != stream_data_size.end()) {
2284 itr->second += bds.second;
2285 } else {
2286 stream_data_size.insert({stream, bds.second});
2287 }
2288 }
2289 }
2290 }
2291
2292 for (const auto& stream : stream_data_size) {
2293 if (stream.second > phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreamDataSize) {
2294 skip |= LogError(device, "VUID-RuntimeSpirv-XfbBuffer-06309",
2295 "vkCreateGraphicsPipelines(): shader uses transform feedback with stream (%" PRIu32
2296 ") having the sum of buffer data sizes (%" PRIu32
2297 ") not less than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackBufferDataSize "
2298 "(%" PRIu32 ").",
2299 stream.first, stream.second,
2300 phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackBufferDataSize);
2301 }
2302 }
2303
ziga-lunargce66e542021-09-19 00:11:14 +02002304 return skip;
2305}
2306
sjfrickede734312022-07-14 19:22:43 +09002307bool CoreChecks::ValidateComputeSharedMemory(const SHADER_MODULE_STATE &module_state, uint32_t total_shared_size) const {
sjfricke44d663c2022-06-01 06:42:58 +09002308 bool skip = false;
sjfrickede734312022-07-14 19:22:43 +09002309
2310 // If not found before with spec constants, find here
2311 if (total_shared_size == 0) {
2312 // when using WorkgroupMemoryExplicitLayoutKHR
2313 // either all or none the structs are decorated with Block,
2314 // if using block, all must decorated with Aliased.
2315 // In this case we want to find the MAX not ADD the block sizes
2316 bool find_max_block = false;
2317
sjfricke44d663c2022-06-01 06:42:58 +09002318 for (auto insn : module_state.static_data_.variable_inst) {
sjfrickede734312022-07-14 19:22:43 +09002319 // StorageClass Workgroup is shared memory
2320 if (insn.word(3) == spv::StorageClassWorkgroup) {
2321 if (module_state.get_decorations(insn.word(2)).flags & decoration_set::aliased_bit) {
2322 find_max_block = true;
2323 }
2324
sjfricke44d663c2022-06-01 06:42:58 +09002325 const uint32_t result_type_id = insn.word(1);
2326 const auto result_type = module_state.get_def(result_type_id);
2327 const auto type = module_state.get_def(result_type.word(3));
sjfrickede734312022-07-14 19:22:43 +09002328 const uint32_t variable_shared_size = module_state.GetTypeBytesSize(type);
2329
2330 if (find_max_block) {
2331 total_shared_size = std::max(total_shared_size, variable_shared_size);
2332 } else {
2333 total_shared_size += variable_shared_size;
2334 }
sjfricke44d663c2022-06-01 06:42:58 +09002335 }
2336 }
sjfrickede734312022-07-14 19:22:43 +09002337 }
2338
2339 if (total_shared_size > phys_dev_props.limits.maxComputeSharedMemorySize) {
2340 skip |=
2341 LogError(device, "VUID-RuntimeSpirv-Workgroup-06530",
2342 "Shader uses %" PRIu32
2343 " bytes of shared memory, more than allowed by physicalDeviceLimits::maxComputeSharedMemorySize (%" PRIu32 ")",
2344 total_shared_size, phys_dev_props.limits.maxComputeSharedMemorySize);
sjfricke44d663c2022-06-01 06:42:58 +09002345 }
2346 return skip;
2347}
2348
Tony-LunarG1672d002022-08-03 14:35:34 -06002349bool CoreChecks::ValidateShaderModuleId(const SHADER_MODULE_STATE &module_state, const PipelineStageState &stage_state,
2350 const safe_VkPipelineShaderStageCreateInfo *pStage, const VkPipelineCreateFlags flags) const {
2351 bool skip = false;
2352 const auto module_identifier = LvlFindInChain<VkPipelineShaderStageModuleIdentifierCreateInfoEXT>(pStage->pNext);
2353 const auto module_create_info = LvlFindInChain<VkShaderModuleCreateInfo>(pStage->pNext);
2354 if (module_identifier && (module_identifier->identifierSize > 0)) {
2355 if (!(enabled_features.shader_module_identifier_features.shaderModuleIdentifier)) {
2356 skip |= LogError(
2357 device, "VUID-VkPipelineShaderStageModuleIdentifierCreateInfoEXT-pNext-06850",
2358 "%s module (stage %s) VkPipelineShaderStageCreateInfo has a VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2359 "struct in the pNext chain but the shaderModuleIdentifier feature is not enabled",
2360 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2361 string_VkShaderStageFlagBits(stage_state.stage_flag));
2362 }
2363 if (!(flags & VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT)) {
2364 skip |= LogError(
2365 device, "VUID-VkPipelineShaderStageModuleIdentifierCreateInfoEXT-pNext-06851",
2366 "%s module (stage %s) VkPipelineShaderStageCreateInfo has a VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2367 "struct in the pNext chain whose identifierSize is > 0 (%" PRIu32
2368 "), but the "
2369 "VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT bit is not set in the pipeline create flags",
2370 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2371 string_VkShaderStageFlagBits(stage_state.stage_flag), module_identifier->identifierSize);
2372 }
2373 if (module_identifier->identifierSize > VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT) {
2374 skip |= LogError(
2375 device, "VUID-VkPipelineShaderStageModuleIdentifierCreateInfoEXT-identifierSize-06852",
2376 "%s module (stage %s) VkPipelineShaderStageCreateInfo has a VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2377 "struct in the pNext chain whose identifierSize (%" PRIu32
2378 ") is > VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT (%" PRIu32 ")",
2379 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2380 string_VkShaderStageFlagBits(stage_state.stage_flag), module_identifier->identifierSize,
2381 VK_MAX_SHADER_MODULE_IDENTIFIER_SIZE_EXT);
2382 }
2383 }
2384 if (module_identifier && module_create_info) {
2385 skip |= LogError(
2386 device, "VUID-VkPipelineShaderStageCreateInfo-stage-06844",
2387 "%s module (stage %s) VkPipelineShaderStageCreateInfo has both a VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2388 "struct and a VkShaderModuleCreateInfo struct in the pNext chain",
2389 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2390 string_VkShaderStageFlagBits(stage_state.stage_flag));
2391 }
2392 if (enabled_features.graphics_pipeline_library_features.graphicsPipelineLibrary) {
2393 if (!module_identifier && pStage->module == VK_NULL_HANDLE && !module_create_info) {
2394 skip |= LogError(
2395 device, "VUID-VkPipelineShaderStageCreateInfo-stage-06845",
2396 "%s module (stage %s) VkPipelineShaderStageCreateInfo has no VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2397 "struct and no VkShaderModuleCreateInfo struct in the pNext chain, and module is not a valid VkShaderModule",
2398 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2399 string_VkShaderStageFlagBits(stage_state.stage_flag));
2400 }
2401 } else {
2402 if (!module_identifier && pStage->module == VK_NULL_HANDLE) {
2403 const char *vuid = IsExtEnabled(device_extensions.vk_khr_pipeline_library)
2404 ? "VUID-VkPipelineShaderStageCreateInfo-stage-06846"
2405 : "VUID-VkPipelineShaderStageCreateInfo-stage-06847";
2406 skip |= LogError(
2407 device, vuid,
2408 "%s module (stage %s) VkPipelineShaderStageCreateInfo has no VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2409 "struct in the pNext chain, the graphicsPipelineLibrary feature is not enabled, and module is not a valid "
2410 "VkShaderModule",
2411 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2412 string_VkShaderStageFlagBits(stage_state.stage_flag));
2413 }
2414 }
2415 if (module_identifier && pStage->module != VK_NULL_HANDLE) {
2416 skip |= LogError(
2417 device, "VUID-VkPipelineShaderStageCreateInfo-stage-06848",
2418 "%s module (stage %s) VkPipelineShaderStageCreateInfo has a VkPipelineShaderStageModuleIdentifierCreateInfoEXT "
2419 "struct in the pNext chain, and module is not VK_NULL_HANDLE",
2420 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2421 string_VkShaderStageFlagBits(stage_state.stage_flag));
2422 }
2423 return skip;
2424}
2425
sjfricke6a03e012022-06-23 17:54:11 +09002426// Temporary data of a OpVariable when validating it.
2427// If found useful in another location, can move out to the header
2428struct VariableInstInfo {
2429 bool has_8bit = false;
2430 bool has_16bit = false;
2431};
2432
2433// easier to use recursion to traverse the OpTypeStruct
2434static void GetVariableInfo(const SHADER_MODULE_STATE &module_state, const spirv_inst_iter &insn, VariableInstInfo &info) {
sjfricke6086f792022-08-25 16:38:15 +09002435 if (insn == module_state.end()) {
2436 return;
2437 } else if (insn.opcode() == spv::OpTypeFloat || insn.opcode() == spv::OpTypeInt) {
2438 const uint32_t bit_width = insn.word(2);
2439 info.has_8bit |= (bit_width == 8);
2440 info.has_16bit |= (bit_width == 16);
sjfricke6a03e012022-06-23 17:54:11 +09002441 } else if (insn.opcode() == spv::OpTypeStruct) {
2442 for (uint32_t i = 2; i < insn.len(); i++) {
2443 const auto &base_insn = GetBaseTypeIter(module_state, insn.word(i));
2444 GetVariableInfo(module_state, base_insn, info);
2445 }
2446 }
2447}
2448
sjfricke44d663c2022-06-01 06:42:58 +09002449bool CoreChecks::ValidateVariables(const SHADER_MODULE_STATE &module_state) const {
2450 bool skip = false;
2451
2452 for (auto insn : module_state.static_data_.variable_inst) {
2453 const uint32_t storage_class = insn.word(3);
2454
2455 if (storage_class == spv::StorageClassWorkgroup) {
2456 // If Workgroup variable is initalized, make sure the feature is enabled
2457 if (insn.len() > 4 &&
2458 !enabled_features.zero_initialize_work_group_memory_features.shaderZeroInitializeWorkgroupMemory) {
2459 const char *vuid = IsExtEnabled(device_extensions.vk_khr_zero_initialize_workgroup_memory)
2460 ? "VUID-RuntimeSpirv-shaderZeroInitializeWorkgroupMemory-06372"
2461 : "VUID-RuntimeSpirv-OpVariable-06373";
2462 skip |= LogError(
2463 device, vuid,
2464 "vkCreateShaderModule(): "
2465 "VkPhysicalDeviceZeroInitializeWorkgroupMemoryFeaturesKHR::shaderZeroInitializeWorkgroupMemory is not enabled, "
2466 "but shader contains an OpVariable with Workgroup Storage Class with an Initializer operand.\n%s",
2467 module_state.DescribeInstruction(insn).c_str());
2468 }
2469 }
sjfricke6a03e012022-06-23 17:54:11 +09002470
2471 const auto type_pointer = module_state.get_def(insn.word(1));
2472 const auto type = module_state.get_def(type_pointer.word(3));
2473 // type will either be a float, int, or struct and if struct need to traverse it
2474 VariableInstInfo info;
2475 GetVariableInfo(module_state, type, info);
2476
2477 if (info.has_8bit) {
2478 if (!enabled_features.core12.storageBuffer8BitAccess &&
2479 (storage_class == spv::StorageClassStorageBuffer || storage_class == spv::StorageClassShaderRecordBufferKHR || storage_class == spv::StorageClassPhysicalStorageBuffer)) {
2480 skip |= LogError(device, "VUID-RuntimeSpirv-storageBuffer8BitAccess-06328",
2481 "vkCreateShaderModule(): storageBuffer8BitAccess is not enabled, but shader contains an 8-bit "
2482 "OpVariable with %s Storage Class.\n%s",
sjfricke657dfdc2022-08-25 23:40:32 +09002483 string_SpvStorageClass(storage_class), module_state.DescribeInstruction(insn).c_str());
sjfricke6a03e012022-06-23 17:54:11 +09002484 }
2485 if (!enabled_features.core12.uniformAndStorageBuffer8BitAccess && storage_class == spv::StorageClassUniform) {
2486 skip |= LogError(device, "VUID-RuntimeSpirv-uniformAndStorageBuffer8BitAccess-06329",
2487 "vkCreateShaderModule(): uniformAndStorageBuffer8BitAccess is not enabled, but shader contains an "
2488 "8-bit OpVariable with Uniform Storage Class.\n%s",
2489 module_state.DescribeInstruction(insn).c_str());
2490 }
2491 if (!enabled_features.core12.storagePushConstant8 && storage_class == spv::StorageClassPushConstant) {
2492 skip |= LogError(device, "VUID-RuntimeSpirv-storagePushConstant8-06330",
2493 "vkCreateShaderModule(): storagePushConstant8 is not enabled, but shader contains an 8-bit "
2494 "OpVariable with PushConstant Storage Class.\n%s",
2495 module_state.DescribeInstruction(insn).c_str());
2496 }
2497 }
2498
2499 if (info.has_16bit) {
2500 if (!enabled_features.core11.storageBuffer16BitAccess &&
2501 (storage_class == spv::StorageClassStorageBuffer || storage_class == spv::StorageClassShaderRecordBufferKHR || storage_class == spv::StorageClassPhysicalStorageBuffer)) {
2502 skip |= LogError(device, "VUID-RuntimeSpirv-storageBuffer16BitAccess-06331",
2503 "vkCreateShaderModule(): storageBuffer16BitAccess is not enabled, but shader contains an 16-bit "
2504 "OpVariable with %s Storage Class.\n%s",
sjfricke657dfdc2022-08-25 23:40:32 +09002505 string_SpvStorageClass(storage_class), module_state.DescribeInstruction(insn).c_str());
sjfricke6a03e012022-06-23 17:54:11 +09002506 }
2507 if (!enabled_features.core11.uniformAndStorageBuffer16BitAccess && storage_class == spv::StorageClassUniform) {
2508 skip |= LogError(device, "VUID-RuntimeSpirv-uniformAndStorageBuffer16BitAccess-06332",
2509 "vkCreateShaderModule(): uniformAndStorageBuffer16BitAccess is not enabled, but shader contains an "
2510 "16-bit OpVariable with Uniform Storage Class.\n%s",
2511 module_state.DescribeInstruction(insn).c_str());
2512 }
2513 if (!enabled_features.core11.storagePushConstant16 && storage_class == spv::StorageClassPushConstant) {
2514 skip |= LogError(device, "VUID-RuntimeSpirv-storagePushConstant16-06333",
2515 "vkCreateShaderModule(): storagePushConstant16 is not enabled, but shader contains an 16-bit "
2516 "OpVariable with PushConstant Storage Class.\n%s",
2517 module_state.DescribeInstruction(insn).c_str());
2518 }
2519 if (!enabled_features.core11.storageInputOutput16 &&
2520 (storage_class == spv::StorageClassInput || storage_class == spv::StorageClassOutput)) {
2521 skip |= LogError(device, "VUID-RuntimeSpirv-storageInputOutput16-06334",
2522 "vkCreateShaderModule(): storageInputOutput16 is not enabled, but shader contains an 16-bit "
2523 "OpVariable with %s Storage Class.\n%s",
sjfricke657dfdc2022-08-25 23:40:32 +09002524 string_SpvStorageClass(storage_class), module_state.DescribeInstruction(insn).c_str());
sjfricke6a03e012022-06-23 17:54:11 +09002525 }
2526 }
sjfricke29ca0762022-08-24 14:26:33 +09002527
2528 // Checks based off shaderStorageImage(Read|Write)WithoutFormat are
2529 // disabled if VK_KHR_format_feature_flags2 is supported.
2530 //
2531 // https://github.com/KhronosGroup/Vulkan-Docs/blob/6177645341afc/appendices/spirvenv.txt#L553
2532 //
2533 // The other checks need to take into account the format features and so
2534 // we apply that in the descriptor set matching validation code (see
2535 // descriptor_sets.cpp).
2536 if (!has_format_feature2) {
2537 skip |= ValidateShaderStorageImageFormatsVariables(module_state, insn);
2538 }
sjfricke44d663c2022-06-01 06:42:58 +09002539 }
2540
2541 return skip;
2542}
2543
sjfricke4f600c82022-06-09 14:21:32 +09002544bool CoreChecks::ValidateTransformFeedback(const SHADER_MODULE_STATE &module_state) const {
ziga-lunargce66e542021-09-19 00:11:14 +02002545 bool skip = false;
2546
ziga-lunarg28d08792021-10-13 15:42:59 +02002547 // Temp workaround to prevent false positive errors
2548 // https://github.com/KhronosGroup/Vulkan-ValidationLayers/issues/2450
sjfricke4f600c82022-06-09 14:21:32 +09002549 if (module_state.HasMultipleEntryPoints()) {
ziga-lunarg28d08792021-10-13 15:42:59 +02002550 return skip;
2551 }
2552
2553 layer_data::unordered_set<uint32_t> emitted_streams;
2554 bool output_points = false;
sjfricke4f600c82022-06-09 14:21:32 +09002555 for (const auto &insn : module_state) {
ziga-lunarg28d08792021-10-13 15:42:59 +02002556 const uint32_t opcode = insn.opcode();
2557 if (opcode == spv::OpEmitStreamVertex) {
sjfricke4f600c82022-06-09 14:21:32 +09002558 emitted_streams.emplace(static_cast<uint32_t>(module_state.GetConstantValueById(insn.word(1))));
ziga-lunargce66e542021-09-19 00:11:14 +02002559 }
ziga-lunarg28d08792021-10-13 15:42:59 +02002560 if (opcode == spv::OpEmitStreamVertex || opcode == spv::OpEndStreamPrimitive) {
sjfricke4f600c82022-06-09 14:21:32 +09002561 uint32_t stream = static_cast<uint32_t>(module_state.GetConstantValueById(insn.word(1)));
ziga-lunarg28d08792021-10-13 15:42:59 +02002562 if (stream >= phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams) {
2563 skip |= LogError(
2564 device, "VUID-RuntimeSpirv-OpEmitStreamVertex-06310",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002565 "vkCreateGraphicsPipelines(): shader uses transform feedback stream\n%s\nwith index %" PRIu32
ziga-lunarg28d08792021-10-13 15:42:59 +02002566 ", which is not less than VkPhysicalDeviceTransformFeedbackPropertiesEXT::maxTransformFeedbackStreams (%" PRIu32
2567 ").",
sjfricke4f600c82022-06-09 14:21:32 +09002568 module_state.DescribeInstruction(insn).c_str(), stream,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002569 phys_dev_ext_props.transform_feedback_props.maxTransformFeedbackStreams);
ziga-lunarg28d08792021-10-13 15:42:59 +02002570 }
2571 }
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002572 if ((opcode == spv::OpExecutionMode || opcode == spv::OpExecutionModeId) &&
2573 insn.word(2) == spv::ExecutionModeOutputPoints) {
ziga-lunarg28d08792021-10-13 15:42:59 +02002574 output_points = true;
2575 }
2576 }
2577
2578 const uint32_t emitted_streams_size = static_cast<uint32_t>(emitted_streams.size());
2579 if (emitted_streams_size > 1 && !output_points &&
2580 phys_dev_ext_props.transform_feedback_props.transformFeedbackStreamsLinesTriangles == VK_FALSE) {
2581 skip |= LogError(
2582 device, "VUID-RuntimeSpirv-transformFeedbackStreamsLinesTriangles-06311",
2583 "vkCreateGraphicsPipelines(): shader emits to %" PRIu32 " vertex streams and VkPhysicalDeviceTransformFeedbackPropertiesEXT::transformFeedbackStreamsLinesTriangles is VK_FALSE, but execution mode is not OutputPoints.",
2584 emitted_streams_size);
ziga-lunargce66e542021-09-19 00:11:14 +02002585 }
2586
2587 return skip;
2588}
2589
sfricke-samsung864162a2021-11-01 21:58:01 -07002590// Checks for both TexelOffset and TexelGatherOffset limits
sjfricke4f600c82022-06-09 14:21:32 +09002591bool CoreChecks::ValidateTexelOffsetLimits(const SHADER_MODULE_STATE &module_state, spirv_inst_iter &insn) const {
ziga-lunarga12c75a2021-09-16 16:36:16 +02002592 bool skip = false;
2593
2594 const uint32_t opcode = insn.opcode();
sfricke-samsung864162a2021-11-01 21:58:01 -07002595 if (ImageGatherOperation(opcode) || ImageSampleOperation(opcode) || ImageFetchOperation(opcode)) {
sfricke-samsung3a25ed52022-01-20 02:24:36 -08002596 uint32_t image_operand_position = OpcodeImageOperandsPosition(opcode);
sfricke-samsung864162a2021-11-01 21:58:01 -07002597 // Image operands can be optional
sfricke-samsung73f1a0f2021-10-28 23:27:25 -07002598 if (image_operand_position != 0 && insn.len() > image_operand_position) {
2599 auto image_operand = insn.word(image_operand_position);
sfricke-samsung864162a2021-11-01 21:58:01 -07002600 // Bits we are validating (sample/fetch only check ConstOffset)
ziga-lunarga12c75a2021-09-16 16:36:16 +02002601 uint32_t offset_bits =
sfricke-samsung864162a2021-11-01 21:58:01 -07002602 ImageGatherOperation(opcode)
2603 ? (spv::ImageOperandsOffsetMask | spv::ImageOperandsConstOffsetMask | spv::ImageOperandsConstOffsetsMask)
2604 : (spv::ImageOperandsConstOffsetMask);
ziga-lunarga12c75a2021-09-16 16:36:16 +02002605 if (image_operand & (offset_bits)) {
sfricke-samsung73f1a0f2021-10-28 23:27:25 -07002606 // Operand values follow
2607 uint32_t index = image_operand_position + 1;
ziga-lunarga12c75a2021-09-16 16:36:16 +02002608 // Each bit has it's own operand, starts with the smallest set bit and loop to the highest bit among
2609 // ImageOperandsOffsetMask, ImageOperandsConstOffsetMask and ImageOperandsConstOffsetsMask
2610 for (uint32_t i = 1; i < spv::ImageOperandsConstOffsetsMask; i <<= 1) {
2611 if (image_operand & i) { // If the bit is set, consume operand
2612 if (insn.len() > index && (i & offset_bits)) {
2613 uint32_t constant_id = insn.word(index);
sjfricke4f600c82022-06-09 14:21:32 +09002614 const auto &constant = module_state.get_def(constant_id);
2615 const bool is_dynamic_offset = constant == module_state.end();
Shahbaz Youssefi7a6a5272021-10-06 15:07:10 -04002616 if (!is_dynamic_offset && constant.opcode() == spv::OpConstantComposite) {
ziga-lunarga12c75a2021-09-16 16:36:16 +02002617 for (uint32_t j = 3; j < constant.len(); ++j) {
2618 uint32_t comp_id = constant.word(j);
sjfricke4f600c82022-06-09 14:21:32 +09002619 const auto &comp = module_state.get_def(comp_id);
2620 const auto &comp_type = module_state.get_def(comp.word(1));
ziga-lunarga12c75a2021-09-16 16:36:16 +02002621 // Get operand value
sfricke-samsungef3fe742021-10-06 10:51:34 -07002622 const uint32_t offset = comp.word(3);
sfricke-samsung864162a2021-11-01 21:58:01 -07002623 // spec requires minTexelGatherOffset/minTexelOffset to be -8 or less so never can compare if
2624 // unsigned spec requires maxTexelGatherOffset/maxTexelOffset to be 7 or greater so never can
2625 // compare if signed is less then zero
sfricke-samsungef3fe742021-10-06 10:51:34 -07002626 const int32_t signed_offset = static_cast<int32_t>(offset);
2627 const bool use_signed = (comp_type.opcode() == spv::OpTypeInt && comp_type.word(3) != 0);
2628
sfricke-samsung864162a2021-11-01 21:58:01 -07002629 // There are 2 sets of VU being covered where the only main difference is the opcode
2630 if (ImageGatherOperation(opcode)) {
2631 // min/maxTexelGatherOffset
2632 if (use_signed && (signed_offset < phys_dev_props.limits.minTexelGatherOffset)) {
2633 skip |=
2634 LogError(device, "VUID-RuntimeSpirv-OpImage-06376",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002635 "vkCreateShaderModule(): Shader uses\n%s\nwith offset (%" PRIi32
sfricke-samsungef3fe742021-10-06 10:51:34 -07002636 ") less than VkPhysicalDeviceLimits::minTexelGatherOffset (%" PRIi32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09002637 module_state.DescribeInstruction(insn).c_str(), signed_offset,
sfricke-samsung73f1a0f2021-10-28 23:27:25 -07002638 phys_dev_props.limits.minTexelGatherOffset);
sfricke-samsung864162a2021-11-01 21:58:01 -07002639 } else if ((offset > phys_dev_props.limits.maxTexelGatherOffset) &&
2640 (!use_signed || (use_signed && signed_offset > 0))) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002641 skip |= LogError(device, "VUID-RuntimeSpirv-OpImage-06377",
2642 "vkCreateShaderModule(): Shader uses\n%s\nwith offset (%" PRIu32
2643 ") greater than VkPhysicalDeviceLimits::maxTexelGatherOffset (%" PRIu32
2644 ").",
sjfricke4f600c82022-06-09 14:21:32 +09002645 module_state.DescribeInstruction(insn).c_str(), offset,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002646 phys_dev_props.limits.maxTexelGatherOffset);
sfricke-samsung864162a2021-11-01 21:58:01 -07002647 }
2648 } else {
2649 // min/maxTexelOffset
2650 if (use_signed && (signed_offset < phys_dev_props.limits.minTexelOffset)) {
2651 skip |= LogError(device, "VUID-RuntimeSpirv-OpImageSample-06435",
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002652 "vkCreateShaderModule(): Shader uses\n%s\nwith offset (%" PRIi32
sfricke-samsung864162a2021-11-01 21:58:01 -07002653 ") less than VkPhysicalDeviceLimits::minTexelOffset (%" PRIi32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09002654 module_state.DescribeInstruction(insn).c_str(), signed_offset,
sfricke-samsung864162a2021-11-01 21:58:01 -07002655 phys_dev_props.limits.minTexelOffset);
2656 } else if ((offset > phys_dev_props.limits.maxTexelOffset) &&
2657 (!use_signed || (use_signed && signed_offset > 0))) {
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002658 skip |= LogError(device, "VUID-RuntimeSpirv-OpImageSample-06436",
2659 "vkCreateShaderModule(): Shader uses\n%s\nwith offset (%" PRIu32
2660 ") greater than VkPhysicalDeviceLimits::maxTexelOffset (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09002661 module_state.DescribeInstruction(insn).c_str(), offset,
sfricke-samsung7a9bdca2022-01-24 14:38:03 -08002662 phys_dev_props.limits.maxTexelOffset);
sfricke-samsung864162a2021-11-01 21:58:01 -07002663 }
ziga-lunarga12c75a2021-09-16 16:36:16 +02002664 }
2665 }
2666 }
2667 }
sfricke-samsung3511e312021-11-04 21:14:31 -07002668 index += ImageOperandsParamCount(i);
ziga-lunarga12c75a2021-09-16 16:36:16 +02002669 }
2670 }
2671 }
2672 }
2673 }
2674
2675 return skip;
2676}
2677
sjfricke4f600c82022-06-09 14:21:32 +09002678bool CoreChecks::ValidateShaderClock(const SHADER_MODULE_STATE &module_state, spirv_inst_iter &insn) const {
sfricke-samsung486a51e2021-01-02 00:10:15 -08002679 bool skip = false;
2680
sfricke-samsung94167ca2021-02-26 04:14:59 -08002681 switch (insn.opcode()) {
2682 case spv::OpReadClockKHR: {
sjfricke4f600c82022-06-09 14:21:32 +09002683 auto scope_id = module_state.get_def(insn.word(3));
sfricke-samsung94167ca2021-02-26 04:14:59 -08002684 auto scope_type = scope_id.word(3);
2685 // if scope isn't Subgroup or Device, spirv-val will catch
sfricke-samsung828e59d2021-08-22 23:20:49 -07002686 if ((scope_type == spv::ScopeSubgroup) && (enabled_features.shader_clock_features.shaderSubgroupClock == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07002687 skip |= LogError(device, "VUID-RuntimeSpirv-shaderSubgroupClock-06267",
sfricke-samsunged00aa42022-01-27 19:03:01 -08002688 "%s: OpReadClockKHR is used with a Subgroup scope but shaderSubgroupClock was not enabled.\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09002689 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2690 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung828e59d2021-08-22 23:20:49 -07002691 } else if ((scope_type == spv::ScopeDevice) && (enabled_features.shader_clock_features.shaderDeviceClock == VK_FALSE)) {
sfricke-samsung1ff329f2021-09-16 10:06:47 -07002692 skip |= LogError(device, "VUID-RuntimeSpirv-shaderDeviceClock-06268",
sfricke-samsunged00aa42022-01-27 19:03:01 -08002693 "%s: OpReadClockKHR is used with a Device scope but shaderDeviceClock was not enabled.\n%s",
sjfricke4f600c82022-06-09 14:21:32 +09002694 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
2695 module_state.DescribeInstruction(insn).c_str());
sfricke-samsung486a51e2021-01-02 00:10:15 -08002696 }
sfricke-samsung94167ca2021-02-26 04:14:59 -08002697 break;
sfricke-samsung486a51e2021-01-02 00:10:15 -08002698 }
2699 }
2700 return skip;
2701}
2702
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002703bool CoreChecks::ValidatePipelineShaderStage(const PIPELINE_STATE *pipeline, const PipelineStageState &stage_state,
2704 bool check_point_size) const {
John Zulauf14c355b2019-06-27 16:09:37 -06002705 bool skip = false;
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002706 const auto *pStage = stage_state.create_info;
sjfricke4f600c82022-06-09 14:21:32 +09002707 const SHADER_MODULE_STATE &module_state = *stage_state.module_state.get();
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002708 const auto &entrypoint = stage_state.entrypoint;
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002709
Tony-LunarG1672d002022-08-03 14:35:34 -06002710 skip |= ValidateShaderModuleId(module_state, stage_state, pStage, pipeline->GetPipelineCreateFlags());
2711
Tony-LunarGcab5d812022-08-04 14:07:32 -06002712 if (module_state.vk_shader_module() == VK_NULL_HANDLE) return skip; // No real shader for further validation
2713
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002714 // to prevent const_cast on pipeline object, just store here as not needed outside function anyway
2715 uint32_t local_size_x = 0;
2716 uint32_t local_size_y = 0;
2717 uint32_t local_size_z = 0;
sjfrickede734312022-07-14 19:22:43 +09002718 uint32_t total_shared_size = 0;
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002719
John Zulauf14c355b2019-06-27 16:09:37 -06002720 // Check the module
sjfricke4f600c82022-06-09 14:21:32 +09002721 if (!module_state.has_valid_spirv) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002722 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter",
2723 "%s does not contain valid spirv for stage %s.",
sjfricke4f600c82022-06-09 14:21:32 +09002724 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
sfricke-samsungef15e482022-01-26 11:32:49 -08002725 string_VkShaderStageFlagBits(stage_state.stage_flag));
John Zulauf14c355b2019-06-27 16:09:37 -06002726 }
2727
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002728 // If specialization-constant instructions are present in the shader, the specializations should be applied.
sjfricke4f600c82022-06-09 14:21:32 +09002729 if (module_state.HasSpecConstants()) {
sfricke-samsung5628f982021-10-19 09:21:59 -07002730 // both spirv-opt and spirv-val will use the same flags
2731 spvtools::ValidatorOptions options;
2732 AdjustValidatorOptions(device_extensions, enabled_features, options);
2733
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002734 // setup the call back if the optimizer fails
sfricke-samsung45996a42021-09-16 13:45:27 -07002735 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002736 spvtools::Optimizer optimizer(spirv_environment);
sfricke-samsungef15e482022-01-26 11:32:49 -08002737 spvtools::MessageConsumer consumer = [&skip, &module_state, &stage_state, this](
2738 spv_message_level_t level, const char *source, const spv_position_t &position,
2739 const char *message) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002740 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-module-parameter",
2741 "%s does not contain valid spirv for stage %s. %s",
sjfricke4f600c82022-06-09 14:21:32 +09002742 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002743 string_VkShaderStageFlagBits(stage_state.stage_flag), message);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002744 };
2745 optimizer.SetMessageConsumer(consumer);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002746
2747 // The app might be using the default spec constant values, but if they pass values at runtime to the pipeline then need to
2748 // use those values to apply to the spec constants
2749 if (pStage->pSpecializationInfo != nullptr && pStage->pSpecializationInfo->mapEntryCount > 0 &&
2750 pStage->pSpecializationInfo->pMapEntries != nullptr) {
2751 // Gather the specialization-constant values.
2752 auto const &specialization_info = pStage->pSpecializationInfo;
2753 auto const &specialization_data = reinterpret_cast<uint8_t const *>(specialization_info->pData);
2754 std::unordered_map<uint32_t, std::vector<uint32_t>> id_value_map; // note: this must be std:: to work with spvtools
2755 id_value_map.reserve(specialization_info->mapEntryCount);
2756 for (auto i = 0u; i < specialization_info->mapEntryCount; ++i) {
2757 auto const &map_entry = specialization_info->pMapEntries[i];
sjfricke4f600c82022-06-09 14:21:32 +09002758 const auto itr = module_state.GetSpecConstMap().find(map_entry.constantID);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002759 // "If a constantID value is not a specialization constant ID used in the shader, that map entry does not affect the
2760 // behavior of the pipeline."
sjfricke4f600c82022-06-09 14:21:32 +09002761 if (itr != module_state.GetSpecConstMap().cend()) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002762 // Make sure map_entry.size matches the spec constant's size
2763 uint32_t spec_const_size = decoration_set::kInvalidValue;
sjfricke4f600c82022-06-09 14:21:32 +09002764 const auto def_ins = module_state.get_def(itr->second);
2765 const auto type_ins = module_state.get_def(def_ins.word(1));
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002766 // Specialization constants can only be of type bool, scalar integer, or scalar floating point
2767 switch (type_ins.opcode()) {
2768 case spv::OpTypeBool:
2769 // "If the specialization constant is of type boolean, size must be the byte size of VkBool32"
2770 spec_const_size = sizeof(VkBool32);
2771 break;
2772 case spv::OpTypeInt:
2773 case spv::OpTypeFloat:
2774 spec_const_size = type_ins.word(2) / 8;
2775 break;
2776 default:
2777 // spirv-val should catch if SpecId is not used on a
2778 // OpSpecConstantTrue/OpSpecConstantFalse/OpSpecConstant and OpSpecConstant is validated to be a
2779 // OpTypeInt or OpTypeFloat
2780 break;
2781 }
2782
2783 if (map_entry.size != spec_const_size) {
2784 skip |= LogError(device, "VUID-VkSpecializationMapEntry-constantID-00776",
2785 "Specialization constant (ID = %" PRIu32 ", entry = %" PRIu32
2786 ") has invalid size %zu in shader module %s. Expected size is %" PRIu32
2787 " from shader definition.",
2788 map_entry.constantID, i, map_entry.size,
sjfricke4f600c82022-06-09 14:21:32 +09002789 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), spec_const_size);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002790 }
2791 }
2792
2793 if ((map_entry.offset + map_entry.size) <= specialization_info->dataSize) {
2794 // Allocate enough room for ceil(map_entry.size / 4) to store entries
2795 std::vector<uint32_t> entry_data((map_entry.size + 4 - 1) / 4, 0);
2796 uint8_t *out_p = reinterpret_cast<uint8_t *>(entry_data.data());
2797 const uint8_t *const start_in_p = specialization_data + map_entry.offset;
2798 const uint8_t *const end_in_p = start_in_p + map_entry.size;
2799
2800 std::copy(start_in_p, end_in_p, out_p);
2801 id_value_map.emplace(map_entry.constantID, std::move(entry_data));
2802 }
2803 }
2804
2805 // This pass takes the runtime spec const values and applies it into the SPIR-V
2806 // will turn a spec constant like
2807 // OpSpecConstant %uint 1
2808 // to a use the value passed in instead (for example if the value is 32) so now it looks like
2809 // OpSpecConstant %uint 32
2810 optimizer.RegisterPass(spvtools::CreateSetSpecConstantDefaultValuePass(id_value_map));
2811 }
2812
2813 // This pass will turn OpSpecConstant into a OpConstant (also OpSpecConstantTrue/OpSpecConstantFalse)
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002814 optimizer.RegisterPass(spvtools::CreateFreezeSpecConstantValuePass());
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002815 // Using the new frozen OpConstant all OpSpecConstantComposite can be resolved turning them into OpConstantComposite
2816 // This is need incase a shdaer looks like:
2817 //
2818 // layout(constant_id = 0) const uint x = 64;
2819 // shared uint arr[x > 64 ? 64 : x];
2820 //
2821 // this will generate branch/switch statements that we want to leverage spirv-opt to apply to make parsing easier
2822 optimizer.RegisterPass(spvtools::CreateFoldSpecConstantOpAndCompositePass());
sjfricke284a13f2022-08-16 15:34:31 +09002823 // Currently need to re-run the pass as spirv-opt has a bug and not folding everything sometimes
2824 // https://github.com/KhronosGroup/Vulkan-ValidationLayers/pull/4399#issuecomment-1216203563
2825 optimizer.RegisterPass(spvtools::CreateFoldSpecConstantOpAndCompositePass());
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002826
2827 // Apply the specialization-constant values and revalidate the shader module is valid.
Tony-LunarG1672d002022-08-03 14:35:34 -06002828 const char *pSpecializationInfo_vuid = IsExtEnabled(device_extensions.vk_ext_shader_module_identifier)
2829 ? "VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06849"
2830 : "VUID-VkPipelineShaderStageCreateInfo-pSpecializationInfo-06719";
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002831 std::vector<uint32_t> specialized_spirv;
sfricke-samsungef15e482022-01-26 11:32:49 -08002832 auto const optimized =
sjfricke4f600c82022-06-09 14:21:32 +09002833 optimizer.Run(module_state.words.data(), module_state.words.size(), &specialized_spirv, options, false);
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002834 if (optimized) {
2835 spv_context ctx = spvContextCreate(spirv_environment);
2836 spv_const_binary_t binary{specialized_spirv.data(), specialized_spirv.size()};
2837 spv_diagnostic diag = nullptr;
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002838 auto const spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag);
2839 if (spv_valid != SPV_SUCCESS) {
Tony-LunarG1672d002022-08-03 14:35:34 -06002840 skip |= LogError(device, pSpecializationInfo_vuid,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07002841 "After specialization was applied, %s does not contain valid spirv for stage %s.",
sjfricke4f600c82022-06-09 14:21:32 +09002842 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002843 string_VkShaderStageFlagBits(stage_state.stage_flag));
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002844 }
2845
sjfrickea11e42e2022-07-20 14:27:01 +09002846 // The new optimized SPIR-V will NOT match the original SHADER_MODULE_STATE object parsing, so a new SHADER_MODULE_STATE
2847 // object is needed. This an issue due to each pipeline being able to reuse the same shader module but with different
2848 // spec constant values.
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002849 SHADER_MODULE_STATE spec_mod(specialized_spirv);
2850
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002851 // According to https://github.com/KhronosGroup/Vulkan-Docs/issues/1671 anything labeled as "static use" (such as if an
2852 // input is used or not) don't have to be checked post spec constants freezing since the device compiler is not
2853 // guaranteed to run things such as dead-code elimination. The following checks are things that don't follow under
2854 // "static use" rules and need to be validated still.
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002855 auto specialized_it = spec_mod.begin();
sjfrickede734312022-07-14 19:22:43 +09002856
2857 // see ValidateComputeSharedMemory() for details why we might track max block size
2858 layer_data::unordered_set<uint32_t> aliased_id;
2859 bool find_max_block = false;
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002860
2861 uint32_t workgroup_size_id = 0; // result id can't be zero
2862 uint32_t local_size_id_x = 0;
2863 uint32_t local_size_id_y = 0;
2864 uint32_t local_size_id_z = 0;
2865
2866 // make single interation through new shader
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002867 while (specialized_it != spec_mod.end()) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002868 const uint32_t opcode = specialized_it.opcode();
2869
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002870 if (opcode == spv::OpExecutionModeId && specialized_it.word(2) == spv::ExecutionModeLocalSizeId) {
2871 local_size_id_x = specialized_it.word(3);
2872 local_size_id_y = specialized_it.word(4);
2873 local_size_id_z = specialized_it.word(5);
2874 }
2875
sjfrickede734312022-07-14 19:22:43 +09002876 if (opcode == spv::OpDecorate) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002877 // Validate applied WorkgroupSize is still below maxComputeWorkGroupSize limit
sjfrickede734312022-07-14 19:22:43 +09002878 if (specialized_it.word(2) == spv::DecorationBuiltIn && specialized_it.word(3) == spv::BuiltInWorkgroupSize) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002879 // Will be a OpConstantComposite and always have the OpDecorate section
2880 workgroup_size_id = specialized_it.word(1);
2881 }
sjfrickede734312022-07-14 19:22:43 +09002882 if (specialized_it.word(2) == spv::DecorationAliased) {
2883 aliased_id.emplace(specialized_it.word(1));
2884 }
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002885 }
2886
2887 if (opcode == spv::OpConstantComposite && workgroup_size_id == specialized_it.word(2)) {
2888 // VUID-WorkgroupSize-WorkgroupSize-04427 makes sure this is a OpTypeVector of int32 so this can be assuemd
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002889 local_size_x = spec_mod.get_def(specialized_it.word(3)).word(3);
2890 local_size_y = spec_mod.get_def(specialized_it.word(4)).word(3);
2891 local_size_z = spec_mod.get_def(specialized_it.word(5)).word(3);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002892 }
sjfrickede734312022-07-14 19:22:43 +09002893
2894 if (opcode == spv::OpVariable && specialized_it.word(3) == spv::StorageClassWorkgroup) {
2895 if (aliased_id.find(specialized_it.word(2)) != aliased_id.end()) {
2896 find_max_block = true;
2897 }
2898
2899 const uint32_t result_type_id = specialized_it.word(1);
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002900 const auto result_type = spec_mod.get_def(result_type_id);
2901 const auto type = spec_mod.get_def(result_type.word(3));
2902 const uint32_t variable_shared_size = spec_mod.GetTypeBitsSize(type) / 8;
sjfrickede734312022-07-14 19:22:43 +09002903
2904 if (find_max_block) {
2905 total_shared_size = std::max(total_shared_size, variable_shared_size);
2906 } else {
2907 total_shared_size += variable_shared_size;
2908 }
2909 }
2910
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002911 ++specialized_it;
2912 }
2913
2914 // if after no WorkgroupSize is found, then can apply any possible LocalSizeId due to precedence order
2915 if (local_size_x == 0 && local_size_id_x != 0) {
Nathaniel Cesarioea997aa2022-07-19 10:43:57 -06002916 local_size_x = spec_mod.get_def(local_size_id_x).word(3);
2917 local_size_y = spec_mod.get_def(local_size_id_y).word(3);
2918 local_size_z = spec_mod.get_def(local_size_id_z).word(3);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002919 }
2920
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002921 spvDiagnosticDestroy(diag);
2922 spvContextDestroy(ctx);
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002923 } else {
2924 // Should never get here, but better then asserting
Tony-LunarG1672d002022-08-03 14:35:34 -06002925 skip |= LogError(device, pSpecializationInfo_vuid,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002926 "%s module (stage %s) attempted to apply specialization constants with spirv-opt but failed.",
sjfricke4f600c82022-06-09 14:21:32 +09002927 report_data->FormatHandle(module_state.vk_shader_module()).c_str(),
sfricke-samsung61d50ec2022-02-13 17:01:25 -08002928 string_VkShaderStageFlagBits(stage_state.stage_flag));
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06002929 }
2930 }
2931
John Zulauf14c355b2019-06-27 16:09:37 -06002932 // Check the entrypoint
sjfricke4f600c82022-06-09 14:21:32 +09002933 if (entrypoint == module_state.end()) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002934 skip |= LogError(device, "VUID-VkPipelineShaderStageCreateInfo-pName-00707", "No entrypoint found named `%s` for stage %s.",
2935 pStage->pName, string_VkShaderStageFlagBits(stage_state.stage_flag));
John Zulauf14c355b2019-06-27 16:09:37 -06002936 }
2937 if (skip) return true; // no point continuing beyond here, any analysis is just going to be garbage.
2938
2939 // Mark accessible ids
2940 auto &accessible_ids = stage_state.accessible_ids;
2941
Chris Forbes47567b72017-06-09 12:09:45 -07002942 // Validate descriptor set layout against what the entrypoint actually uses
Chris Forbes47567b72017-06-09 12:09:45 -07002943
sfricke-samsung94167ca2021-02-26 04:14:59 -08002944 // The following tries to limit the number of passes through the shader module. The validation passes in here are "stateless"
2945 // and mainly only checking the instruction in detail for a single operation
sjfricke4f600c82022-06-09 14:21:32 +09002946 for (auto insn : module_state) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002947 skip |= ValidateTexelOffsetLimits(module_state, insn);
2948 skip |= ValidateShaderCapabilitiesAndExtensions(insn);
2949 skip |= ValidateShaderClock(module_state, insn);
2950 skip |= ValidateShaderStageGroupNonUniform(module_state, pStage->stage, insn);
2951 skip |= ValidateMemoryScope(module_state, insn);
ziga-lunarga26b3602021-08-08 15:53:00 +02002952 }
2953
sfricke-samsungef15e482022-01-26 11:32:49 -08002954 skip |= ValidateTransformFeedback(module_state);
Jeremy Gebben84b838b2021-08-23 08:41:39 -06002955 skip |= ValidateShaderStageWritableOrAtomicDescriptor(pStage->stage, stage_state.has_writable_descriptor,
2956 stage_state.has_atomic_descriptor);
sfricke-samsungef15e482022-01-26 11:32:49 -08002957 skip |= ValidateShaderStageInputOutputLimits(module_state, pStage, pipeline, entrypoint);
sfricke-samsungdc96f302020-03-18 20:42:10 -07002958 skip |= ValidateShaderStageMaxResources(pStage->stage, pipeline);
sfricke-samsungef15e482022-01-26 11:32:49 -08002959 skip |= ValidateAtomicsTypes(module_state);
2960 skip |= ValidateExecutionModes(module_state, entrypoint, pStage->stage, pipeline);
ziga-lunargae2a5c42021-07-23 16:18:09 +02002961 skip |= ValidateSpecializations(pStage);
sfricke-samsungef15e482022-01-26 11:32:49 -08002962 skip |= ValidateDecorations(module_state);
sjfricke4f600c82022-06-09 14:21:32 +09002963 skip |= ValidateVariables(module_state);
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07002964 const auto *raster_state = pipeline->RasterizationState();
Nathaniel Cesario81257cb2022-02-16 17:15:58 -07002965 if (check_point_size && raster_state && !raster_state->rasterizerDiscardEnable) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002966 skip |= ValidatePointListShaderState(pipeline, module_state, entrypoint, pStage->stage);
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06002967 }
sfricke-samsungef15e482022-01-26 11:32:49 -08002968 skip |= ValidateBuiltinLimits(module_state, entrypoint);
sfricke-samsungd093e522021-02-26 04:17:45 -08002969 if (enabled_features.cooperative_matrix_features.cooperativeMatrix) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002970 skip |= ValidateCooperativeMatrix(module_state, pStage, pipeline);
sfricke-samsungd093e522021-02-26 04:17:45 -08002971 }
Tobias Hector6663c9b2020-11-05 10:18:02 +00002972 if (enabled_features.fragment_shading_rate_features.primitiveFragmentShadingRate) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002973 skip |= ValidatePrimitiveRateShaderState(pipeline, module_state, entrypoint, pStage->stage);
Tobias Hector6663c9b2020-11-05 10:18:02 +00002974 }
sfricke-samsung45996a42021-09-16 13:45:27 -07002975 if (IsExtEnabled(device_extensions.vk_qcom_render_pass_shader_resolve)) {
sfricke-samsungef15e482022-01-26 11:32:49 -08002976 skip |= ValidateShaderResolveQCOM(module_state, pStage, pipeline);
Jeff Leger9b3dcff2021-05-27 15:40:20 -04002977 }
ziga-lunarg73163742021-08-25 13:15:29 +02002978 if (IsExtEnabled(device_extensions.vk_ext_subgroup_size_control)) {
2979 skip |= ValidateShaderSubgroupSizeControl(pStage);
2980 }
Chris Forbes47567b72017-06-09 12:09:45 -07002981
sfricke-samsung7699b912021-04-12 23:01:51 -07002982 // "layout must be consistent with the layout of the * shader"
2983 // 'consistent' -> #descriptorsets-pipelinelayout-consistency
locke-lunarg9a16ebb2020-07-30 16:56:33 -06002984 std::string vuid_layout_mismatch;
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06002985 switch (pipeline->GetCreateInfoSType()) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06002986 case VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO:
2987 vuid_layout_mismatch = "VUID-VkGraphicsPipelineCreateInfo-layout-00756";
2988 break;
2989 case VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO:
2990 vuid_layout_mismatch = "VUID-VkComputePipelineCreateInfo-layout-00703";
2991 break;
2992 case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_KHR:
2993 vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoKHR-layout-03427";
2994 break;
2995 case VK_STRUCTURE_TYPE_RAY_TRACING_PIPELINE_CREATE_INFO_NV:
2996 vuid_layout_mismatch = "VUID-VkRayTracingPipelineCreateInfoNV-layout-03427";
2997 break;
2998 default:
2999 assert(false);
3000 break;
locke-lunarg9a16ebb2020-07-30 16:56:33 -06003001 }
3002
sfricke-samsung7699b912021-04-12 23:01:51 -07003003 // Validate Push Constants use
sfricke-samsungef15e482022-01-26 11:32:49 -08003004 skip |= ValidatePushConstantUsage(*pipeline, module_state, pStage, vuid_layout_mismatch);
sfricke-samsung7699b912021-04-12 23:01:51 -07003005
Chris Forbes47567b72017-06-09 12:09:45 -07003006 // Validate descriptor use
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003007 for (auto use : stage_state.descriptor_uses) {
Chris Forbes47567b72017-06-09 12:09:45 -07003008 // Verify given pipelineLayout has requested setLayout with requested binding
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003009 // const auto& layout_state = (stage_state.stage_flag == VK_SHADER_STAGE_VERTEX_BIT) ?
3010 // pipeline->PreRasterPipelineLayoutState() : pipeline->FragmentShaderPipelineLayoutState();
3011 const auto &binding = GetDescriptorBinding(pipeline->PipelineLayoutState().get(), use.first);
3012 unsigned required_descriptor_count;
sourav parmarcd5fb182020-07-17 12:58:44 -07003013 bool is_khr = binding && binding->descriptorType == VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR;
3014 std::set<uint32_t> descriptor_types =
sfricke-samsungef15e482022-01-26 11:32:49 -08003015 TypeToDescriptorTypeSet(module_state, use.second.type_id, required_descriptor_count, is_khr);
Chris Forbes47567b72017-06-09 12:09:45 -07003016
3017 if (!binding) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06003018 skip |= LogError(device, vuid_layout_mismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003019 "Shader uses descriptor slot %u.%u (expected `%s`) but not declared in pipeline layout",
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06003020 use.first.set, use.first.binding, string_descriptorTypes(descriptor_types).c_str());
Chris Forbes47567b72017-06-09 12:09:45 -07003021 } else if (~binding->stageFlags & pStage->stage) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06003022 skip |= LogError(device, vuid_layout_mismatch,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06003023 "Shader uses descriptor slot %u.%u but descriptor not accessible from stage %s", use.first.set,
3024 use.first.binding, string_VkShaderStageFlagBits(pStage->stage));
Tony-LunarGf563b362021-03-18 16:13:18 -06003025 } else if ((binding->descriptorType != VK_DESCRIPTOR_TYPE_MUTABLE_VALVE) &&
3026 (descriptor_types.find(binding->descriptorType) == descriptor_types.end())) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06003027 skip |= LogError(device, vuid_layout_mismatch,
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06003028 "Type mismatch on descriptor slot %u.%u (expected `%s`) but descriptor of type %s", use.first.set,
3029 use.first.binding, string_descriptorTypes(descriptor_types).c_str(),
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003030 string_VkDescriptorType(binding->descriptorType));
Chris Forbes47567b72017-06-09 12:09:45 -07003031 } else if (binding->descriptorCount < required_descriptor_count) {
locke-lunarg9a16ebb2020-07-30 16:56:33 -06003032 skip |= LogError(device, vuid_layout_mismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003033 "Shader expects at least %u descriptors for binding %u.%u but only %u provided",
Jeremy Gebben7fc88a22021-08-25 13:30:45 -06003034 required_descriptor_count, use.first.set, use.first.binding, binding->descriptorCount);
Chris Forbes47567b72017-06-09 12:09:45 -07003035 }
3036 }
3037
3038 // Validate use of input attachments against subpass structure
3039 if (pStage->stage == VK_SHADER_STAGE_FRAGMENT_BIT) {
sjfricke4f600c82022-06-09 14:21:32 +09003040 auto input_attachment_uses = module_state.CollectInterfaceByInputAttachmentIndex(accessible_ids);
Chris Forbes47567b72017-06-09 12:09:45 -07003041
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003042 const auto &rp_state = pipeline->RenderPassState();
Jeremy Gebbenb5dda542022-08-02 14:26:20 -06003043 if (rp_state && !rp_state->UsesDynamicRendering()) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003044 auto rpci = rp_state->createInfo.ptr();
3045 auto subpass = pipeline->Subpass();
amhagana448ea52021-11-02 14:09:14 -04003046 for (auto use : input_attachment_uses) {
3047 auto input_attachments = rpci->pSubpasses[subpass].pInputAttachments;
3048 auto index = (input_attachments && use.first < rpci->pSubpasses[subpass].inputAttachmentCount)
3049 ? input_attachments[use.first].attachment
3050 : VK_ATTACHMENT_UNUSED;
Chris Forbes47567b72017-06-09 12:09:45 -07003051
amhagana448ea52021-11-02 14:09:14 -04003052 if (index == VK_ATTACHMENT_UNUSED) {
3053 skip |= LogError(device, kVUID_Core_Shader_MissingInputAttachment,
3054 "Shader consumes input attachment index %d but not provided in subpass", use.first);
sfricke-samsungef15e482022-01-26 11:32:49 -08003055 } else if (!(GetFormatType(rpci->pAttachments[index].format) &
sjfricke4f600c82022-06-09 14:21:32 +09003056 module_state.GetFundamentalType(use.second.type_id))) {
sfricke-samsungef15e482022-01-26 11:32:49 -08003057 skip |= LogError(device, kVUID_Core_Shader_InputAttachmentTypeMismatch,
3058 "Subpass input attachment %u format of %s does not match type used in shader `%s`", use.first,
3059 string_VkFormat(rpci->pAttachments[index].format),
sjfricke4f600c82022-06-09 14:21:32 +09003060 module_state.DescribeType(use.second.type_id).c_str());
amhagana448ea52021-11-02 14:09:14 -04003061 }
Chris Forbes47567b72017-06-09 12:09:45 -07003062 }
3063 }
3064 }
Lockeaa8fdc02019-04-02 11:59:20 -06003065 if (pStage->stage == VK_SHADER_STAGE_COMPUTE_BIT) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003066 skip |= ValidateComputeWorkGroupSizes(module_state, entrypoint, stage_state, local_size_x, local_size_y, local_size_z);
sjfrickede734312022-07-14 19:22:43 +09003067 skip |= ValidateComputeSharedMemory(module_state, total_shared_size);
Lockeaa8fdc02019-04-02 11:59:20 -06003068 }
ziga-lunarg73163742021-08-25 13:15:29 +02003069
Chris Forbes47567b72017-06-09 12:09:45 -07003070 return skip;
3071}
3072
sjfricke4f600c82022-06-09 14:21:32 +09003073bool CoreChecks::ValidateInterfaceBetweenStages(const SHADER_MODULE_STATE &producer, spirv_inst_iter producer_entrypoint,
3074 shader_stage_attributes const *producer_stage, const SHADER_MODULE_STATE &consumer,
Mark Lobodzinskid8d658e2020-01-30 15:05:51 -07003075 spirv_inst_iter consumer_entrypoint,
3076 shader_stage_attributes const *consumer_stage) const {
Chris Forbes47567b72017-06-09 12:09:45 -07003077 bool skip = false;
3078
3079 auto outputs =
sjfricke4f600c82022-06-09 14:21:32 +09003080 producer.CollectInterfaceByLocation(producer_entrypoint, spv::StorageClassOutput, producer_stage->arrayed_output);
3081 auto inputs = consumer.CollectInterfaceByLocation(consumer_entrypoint, spv::StorageClassInput, consumer_stage->arrayed_input);
Chris Forbes47567b72017-06-09 12:09:45 -07003082
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003083 auto output_it = outputs.begin();
3084 auto input_it = inputs.begin();
Chris Forbes47567b72017-06-09 12:09:45 -07003085
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003086 uint32_t output_component = 0;
3087 uint32_t input_component = 0;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003088
Chris Forbes47567b72017-06-09 12:09:45 -07003089 // Maps sorted by key (location); walk them together to find mismatches
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003090 while ((outputs.size() > 0 && output_it != outputs.end()) || (inputs.size() && input_it != inputs.end())) {
3091 bool output_at_end = outputs.size() == 0 || output_it == outputs.end();
3092 bool input_at_end = inputs.size() == 0 || input_it == inputs.end();
3093 auto output_first = output_at_end ? std::make_pair(0u, 0u) : output_it->first;
3094 auto input_first = input_at_end ? std::make_pair(0u, 0u) : input_it->first;
Chris Forbes47567b72017-06-09 12:09:45 -07003095
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003096 output_first.second += output_component;
3097 input_first.second += input_component;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003098
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003099 const auto output_length =
3100 output_at_end ? 0 : producer.GetNumComponentsInBaseType(producer.get_def(output_it->second.type_id));
3101 const auto input_length =
3102 input_at_end ? 0 : consumer.GetNumComponentsInBaseType(consumer.get_def(input_it->second.type_id));
3103 assert(output_at_end || output_component < output_length);
3104 assert(input_at_end || input_component < input_length);
ziga-lunarg8346fe82021-08-22 17:30:50 +02003105
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003106 if (input_at_end || ((!output_at_end) && (output_first < input_first))) {
Stefan Dobrica43c84ca2022-05-30 16:22:36 +02003107 if (!enabled_features.core13.maintenance4) {
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003108 const std::string msg = std::string{producer_stage->name} + " writes to output location " +
3109 std::to_string(output_first.first) + "." + std::to_string(output_first.second) +
3110 " which is not consumed by " + consumer_stage->name +
Nathaniel Cesario09fbe8a2022-08-03 16:24:25 -06003111 ". "
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003112 "Enable VK_KHR_maintenance4 device extension to allow relaxed interface matching between "
3113 "input and output vectors.";
Nathaniel Cesario09fbe8a2022-08-03 16:24:25 -06003114 // It is not an error if a stage does not consume all outputs from the previous stage
3115 skip |= LogPerformanceWarning(producer.vk_shader_module(), kVUID_Core_Shader_OutputNotConsumed, "%s", msg.c_str());
Stefan Dobrica43c84ca2022-05-30 16:22:36 +02003116 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003117 if ((input_first.first > output_first.first) || input_at_end || (output_component + 1 == output_length)) {
3118 output_it++;
3119 output_component = 0;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003120 } else {
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003121 output_component++;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003122 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003123 } else if (output_at_end || output_first > input_first) {
sjfricke4f600c82022-06-09 14:21:32 +09003124 skip |= LogError(consumer.vk_shader_module(), kVUID_Core_Shader_InputNotProduced,
ziga-lunarg8346fe82021-08-22 17:30:50 +02003125 "%s consumes input location %" PRIu32 ".%" PRIu32 " which is not written by %s", consumer_stage->name,
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003126 input_first.first, input_first.second, producer_stage->name);
3127 if ((output_first.first > input_first.first) || output_at_end || (input_component + 1 == input_length)) {
3128 input_it++;
3129 input_component = 0;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003130 } else {
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003131 input_component++;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003132 }
Chris Forbes47567b72017-06-09 12:09:45 -07003133 } else {
3134 // subtleties of arrayed interfaces:
3135 // - if is_patch, then the member is not arrayed, even though the interface may be.
3136 // - if is_block_member, then the extra array level of an arrayed interface is not
3137 // expressed in the member type -- it's expressed in the block type.
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003138 if (!TypesMatch(producer, consumer, output_it->second.type_id, input_it->second.type_id)) {
sjfricke4f600c82022-06-09 14:21:32 +09003139 skip |= LogError(producer.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
ziga-lunarge640e802022-04-04 21:36:53 +02003140 "Type mismatch on location %" PRIu32 ".%" PRIu32 ", between %s and %s: '%s' vs '%s'",
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003141 output_first.first, output_first.second, producer_stage->name, consumer_stage->name,
3142 producer.DescribeType(output_it->second.type_id).c_str(),
3143 consumer.DescribeType(input_it->second.type_id).c_str());
3144 output_it++;
3145 input_it++;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003146 continue;
Chris Forbes47567b72017-06-09 12:09:45 -07003147 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003148 if (output_it->second.is_patch != input_it->second.is_patch) {
sjfricke4f600c82022-06-09 14:21:32 +09003149 skip |= LogError(producer.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
3150 "Decoration mismatch on location %" PRIu32 ".%" PRIu32
3151 ": is per-%s in %s stage but per-%s in %s stage",
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003152 output_first.first, output_first.second, output_it->second.is_patch ? "patch" : "vertex",
3153 producer_stage->name, input_it->second.is_patch ? "patch" : "vertex", consumer_stage->name);
Chris Forbes47567b72017-06-09 12:09:45 -07003154 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003155 uint32_t output_remaining = output_length - output_component;
3156 uint32_t input_remaining = input_length - input_component;
3157 if (output_remaining == input_remaining) { // Sizes match so we can advance both output_it and input_it
3158 output_it++;
3159 input_it++;
3160 output_component = 0;
3161 input_component = 0;
3162 } else if (output_remaining > input_remaining) { // a has more components remaining
3163 output_component += input_remaining;
3164 input_component = 0;
3165 input_it++;
3166 } else if (input_remaining > output_remaining) { // b has more components remaining
3167 input_component += output_remaining;
3168 output_component = 0;
3169 output_it++;
ziga-lunarg8346fe82021-08-22 17:30:50 +02003170 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003171 if (output_component == 4) {
3172 output_component = 0;
3173 output_it++;
ziga-lunargb9fa0eb2022-04-01 23:31:06 +02003174 }
Nathaniel Cesario54acc5c2022-07-28 14:44:20 -06003175 if (input_component == 4) {
3176 input_component = 0;
3177 input_it++;
ziga-lunargb9fa0eb2022-04-01 23:31:06 +02003178 }
Chris Forbes47567b72017-06-09 12:09:45 -07003179 }
3180 }
3181
Ari Suonpaa696b3432019-03-11 14:02:57 +02003182 if (consumer_stage->stage != VK_SHADER_STAGE_FRAGMENT_BIT) {
sjfricke4f600c82022-06-09 14:21:32 +09003183 auto builtins_producer = producer.CollectBuiltinBlockMembers(producer_entrypoint, spv::StorageClassOutput);
3184 auto builtins_consumer = consumer.CollectBuiltinBlockMembers(consumer_entrypoint, spv::StorageClassInput);
Ari Suonpaa696b3432019-03-11 14:02:57 +02003185
3186 if (!builtins_producer.empty() && !builtins_consumer.empty()) {
3187 if (builtins_producer.size() != builtins_consumer.size()) {
sjfricke4f600c82022-06-09 14:21:32 +09003188 skip |= LogError(producer.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003189 "Number of elements inside builtin block differ between stages (%s %d vs %s %d).",
Nathaniel Cesarioce9b4812020-12-17 08:55:28 -07003190 producer_stage->name, static_cast<int>(builtins_producer.size()), consumer_stage->name,
3191 static_cast<int>(builtins_consumer.size()));
Ari Suonpaa696b3432019-03-11 14:02:57 +02003192 } else {
3193 auto it_producer = builtins_producer.begin();
3194 auto it_consumer = builtins_consumer.begin();
3195 while (it_producer != builtins_producer.end() && it_consumer != builtins_consumer.end()) {
3196 if (*it_producer != *it_consumer) {
sjfricke4f600c82022-06-09 14:21:32 +09003197 skip |= LogError(producer.vk_shader_module(), kVUID_Core_Shader_InterfaceTypeMismatch,
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003198 "Builtin variable inside block doesn't match between %s and %s.", producer_stage->name,
3199 consumer_stage->name);
Ari Suonpaa696b3432019-03-11 14:02:57 +02003200 break;
3201 }
3202 it_producer++;
3203 it_consumer++;
3204 }
3205 }
3206 }
3207 }
3208
Chris Forbes47567b72017-06-09 12:09:45 -07003209 return skip;
3210}
3211
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003212static inline uint32_t DetermineFinalGeomStage(const PIPELINE_STATE &pipeline) {
3213 uint32_t stage_mask = pipeline.active_shaders;
3214 if (pipeline.topology_at_rasterizer == VK_PRIMITIVE_TOPOLOGY_POINT_LIST) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06003215 // Determine which shader in which PointSize should be written (the final geometry stage)
Jeff Bolz105d6492018-09-29 15:46:44 -05003216 if (stage_mask & VK_SHADER_STAGE_MESH_BIT_NV) {
3217 stage_mask = VK_SHADER_STAGE_MESH_BIT_NV;
3218 } else if (stage_mask & VK_SHADER_STAGE_GEOMETRY_BIT) {
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06003219 stage_mask = VK_SHADER_STAGE_GEOMETRY_BIT;
3220 } else if (stage_mask & VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT) {
3221 stage_mask = VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
3222 } else if (stage_mask & VK_SHADER_STAGE_VERTEX_BIT) {
3223 stage_mask = VK_SHADER_STAGE_VERTEX_BIT;
Mark Lobodzinski2c984cc2018-07-31 09:57:46 -06003224 }
3225 }
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06003226 return stage_mask;
Mark Lobodzinski2c984cc2018-07-31 09:57:46 -06003227}
3228
Chris Forbes47567b72017-06-09 12:09:45 -07003229// Validate that the shaders used by the given pipeline and store the active_slots
3230// that are actually used by the pipeline into pPipeline->active_slots
John Zulaufac4c6e12019-07-01 16:05:58 -06003231bool CoreChecks::ValidateGraphicsPipelineShaderState(const PIPELINE_STATE *pipeline) const {
Chris Forbes47567b72017-06-09 12:09:45 -07003232 bool skip = false;
3233
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003234 if (pipeline->IsGraphicsLibrary()) {
3235 // Only validate stages in an executable pipeline, not a graphics library
3236 // TODO This currently makes executing executable pipeline more expensive than they need to be since we could be validating
3237 // more per library.
3238 return skip;
3239 }
3240
3241 uint32_t pointlist_stage_mask = DetermineFinalGeomStage(*pipeline);
Mark Lobodzinski1b4a8ed2018-08-07 08:47:05 -06003242
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003243 const PipelineStageState *vertex_stage = nullptr, *fragment_stage = nullptr;
3244 for (auto &stage : pipeline->stage_state) {
3245 skip |= ValidatePipelineShaderStage(pipeline, stage, (pointlist_stage_mask == stage.stage_flag));
3246 if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT) {
3247 vertex_stage = &stage;
3248 }
3249 if (stage.stage_flag == VK_SHADER_STAGE_FRAGMENT_BIT) {
3250 fragment_stage = &stage;
3251 }
Chris Forbes47567b72017-06-09 12:09:45 -07003252 }
3253
3254 // if the shader stages are no good individually, cross-stage validation is pointless.
3255 if (skip) return true;
3256
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003257 auto vi_state = pipeline->InputState();
Chris Forbes47567b72017-06-09 12:09:45 -07003258
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003259 if (vi_state) {
3260 skip |= ValidateViConsistency(vi_state);
Chris Forbes47567b72017-06-09 12:09:45 -07003261 }
3262
sfricke-samsungef15e482022-01-26 11:32:49 -08003263 if (vertex_stage && vertex_stage->module_state->has_valid_spirv && !IsDynamic(pipeline, VK_DYNAMIC_STATE_VERTEX_INPUT_EXT)) {
sjfricke4f600c82022-06-09 14:21:32 +09003264 skip |= ValidateViAgainstVsInputs(vi_state, *vertex_stage->module_state.get(), vertex_stage->entrypoint);
Chris Forbes47567b72017-06-09 12:09:45 -07003265 }
3266
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003267 for (size_t i = 1; i < pipeline->stage_state.size(); i++) {
3268 const auto &producer = pipeline->stage_state[i - 1];
3269 const auto &consumer = pipeline->stage_state[i];
sfricke-samsungef15e482022-01-26 11:32:49 -08003270 assert(producer.module_state);
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003271 if (&producer == fragment_stage) {
3272 break;
3273 }
sfricke-samsungef15e482022-01-26 11:32:49 -08003274 if (consumer.module_state) {
3275 if (consumer.module_state->has_valid_spirv && producer.module_state->has_valid_spirv) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003276 auto producer_id = GetShaderStageId(producer.stage_flag);
3277 auto consumer_id = GetShaderStageId(consumer.stage_flag);
sjfricke4f600c82022-06-09 14:21:32 +09003278 skip |= ValidateInterfaceBetweenStages(*producer.module_state.get(), producer.entrypoint,
3279 &shader_stage_attribs[producer_id], *consumer.module_state.get(),
sfricke-samsungef15e482022-01-26 11:32:49 -08003280 consumer.entrypoint, &shader_stage_attribs[consumer_id]);
Chris Forbesdbb43fc2018-02-16 16:59:23 -08003281 }
Chris Forbes47567b72017-06-09 12:09:45 -07003282 }
3283 }
3284
sfricke-samsungef15e482022-01-26 11:32:49 -08003285 if (fragment_stage && fragment_stage->module_state->has_valid_spirv) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003286 const auto &rp_state = pipeline->RenderPassState();
Jeremy Gebbenb5dda542022-08-02 14:26:20 -06003287 if (rp_state && rp_state->UsesDynamicRendering()) {
sjfricke4f600c82022-06-09 14:21:32 +09003288 skip |= ValidateFsOutputsAgainstDynamicRenderingRenderPass(*fragment_stage->module_state.get(),
sfricke-samsungef15e482022-01-26 11:32:49 -08003289 fragment_stage->entrypoint, pipeline);
Aaron Hagan1209c782021-11-22 19:37:14 -05003290 } else {
sjfricke4f600c82022-06-09 14:21:32 +09003291 skip |= ValidateFsOutputsAgainstRenderPass(*fragment_stage->module_state.get(), fragment_stage->entrypoint, pipeline,
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003292 pipeline->Subpass());
Aaron Hagan1209c782021-11-22 19:37:14 -05003293 }
Chris Forbes47567b72017-06-09 12:09:45 -07003294 }
3295
3296 return skip;
3297}
3298
Tony-LunarGb2ded512021-02-02 16:03:30 -07003299bool CoreChecks::ValidateGraphicsPipelineShaderDynamicState(const PIPELINE_STATE *pipeline, const CMD_BUFFER_STATE *pCB,
3300 const char *caller, const DrawDispatchVuid &vuid) const {
Tony-LunarGb2ded512021-02-02 16:03:30 -07003301 bool skip = false;
3302
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003303 for (auto &stage : pipeline->stage_state) {
3304 if (stage.stage_flag == VK_SHADER_STAGE_VERTEX_BIT || stage.stage_flag == VK_SHADER_STAGE_GEOMETRY_BIT ||
3305 stage.stage_flag == VK_SHADER_STAGE_MESH_BIT_NV) {
Tony-LunarGb2ded512021-02-02 16:03:30 -07003306 if (!phys_dev_ext_props.fragment_shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports &&
3307 IsDynamic(pipeline, VK_DYNAMIC_STATE_VIEWPORT_WITH_COUNT_EXT) && pCB->viewportWithCountCount != 1) {
Jeremy Gebben3dfeacf2021-12-02 08:46:39 -07003308 if (stage.wrote_primitive_shading_rate) {
Tobias Hector6663c9b2020-11-05 10:18:02 +00003309 skip |=
Jeremy Gebben14b0d1a2021-05-15 20:15:41 -06003310 LogError(pipeline->pipeline(), vuid.viewport_count_primitive_shading_rate,
Tobias Hector6663c9b2020-11-05 10:18:02 +00003311 "%s: %s shader of currently bound pipeline statically writes to PrimitiveShadingRateKHR built-in"
3312 "but multiple viewports are set by the last call to vkCmdSetViewportWithCountEXT,"
3313 "and the primitiveFragmentShadingRateWithMultipleViewports limit is not supported.",
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003314 caller, string_VkShaderStageFlagBits(stage.stage_flag));
Tobias Hector6663c9b2020-11-05 10:18:02 +00003315 }
3316 }
3317 }
3318 }
3319
3320 return skip;
3321}
3322
sfricke-samsunge72a85e2020-02-29 21:48:37 -08003323bool CoreChecks::ValidateComputePipelineShaderState(PIPELINE_STATE *pipeline) const {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003324 return ValidatePipelineShaderStage(pipeline, pipeline->stage_state[0], false);
Chris Forbes47567b72017-06-09 12:09:45 -07003325}
Chris Forbes4ae55b32017-06-09 14:42:56 -07003326
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003327uint32_t CoreChecks::CalcShaderStageCount(const PIPELINE_STATE &pipeline, VkShaderStageFlagBits stageBit) const {
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003328 uint32_t total = 0;
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003329 const auto stages = pipeline.GetShaderStages();
3330 for (const auto &stage : stages) {
3331 if (stage.stage == stageBit) {
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003332 total++;
3333 }
3334 }
3335
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003336 const auto rt_lib_info = pipeline.GetRayTracingLibraryCreateInfo();
3337 if (rt_lib_info) {
3338 for (uint32_t i = 0; i < rt_lib_info->libraryCount; ++i) {
3339 auto library_pipeline = Get<PIPELINE_STATE>(rt_lib_info->pLibraries[i]);
3340 total += CalcShaderStageCount(*library_pipeline, stageBit);
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003341 }
3342 }
3343
3344 return total;
3345}
3346
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003347bool CoreChecks::GroupHasValidIndex(const PIPELINE_STATE &pipeline, uint32_t group, uint32_t stage) const {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003348 if (group == VK_SHADER_UNUSED_NV) {
3349 return true;
3350 }
3351
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003352 const auto stages = pipeline.GetShaderStages();
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003353
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003354 const auto num_stages = static_cast<uint32_t>(stages.size());
3355 if (group < num_stages) {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003356 return (stages[group].stage & stage) != 0;
3357 }
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003358 group -= num_stages;
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003359
3360 // Search libraries
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003361 const auto rt_lib_info = pipeline.GetRayTracingLibraryCreateInfo();
3362 if (rt_lib_info) {
3363 for (uint32_t i = 0; i < rt_lib_info->libraryCount; ++i) {
3364 auto library_pipeline = Get<PIPELINE_STATE>(rt_lib_info->pLibraries[i]);
3365 const auto lib_stages = library_pipeline->GetShaderStages();
3366 const uint32_t stage_count = static_cast<uint32_t>(lib_stages.size());
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003367 if (group < stage_count) {
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003368 return (stages[group].stage & stage) != 0;
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003369 }
3370 group -= stage_count;
3371 }
3372 }
3373
3374 // group index too large
3375 return false;
3376}
3377
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003378bool CoreChecks::ValidateRayTracingPipeline(PIPELINE_STATE *pipeline, const safe_VkRayTracingPipelineCreateInfoCommon &create_info,
3379 VkPipelineCreateFlags flags, bool isKHR) const {
John Zulaufe4474e72019-07-01 17:28:27 -06003380 bool skip = false;
Jason Macnak15f95e82019-08-21 21:52:02 -04003381
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003382 if (isKHR) {
Jeremy Gebben11af9792021-08-20 10:20:09 -06003383 if (create_info.maxPipelineRayRecursionDepth > phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth) {
3384 skip |=
3385 LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-maxPipelineRayRecursionDepth-03589",
3386 "vkCreateRayTracingPipelinesKHR: maxPipelineRayRecursionDepth (%d ) must be less than or equal to "
3387 "VkPhysicalDeviceRayTracingPipelinePropertiesKHR::maxRayRecursionDepth %d",
3388 create_info.maxPipelineRayRecursionDepth, phys_dev_ext_props.ray_tracing_propsKHR.maxRayRecursionDepth);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003389 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06003390 if (create_info.pLibraryInfo) {
3391 for (uint32_t i = 0; i < create_info.pLibraryInfo->libraryCount; ++i) {
Nathaniel Cesario3fd4f762022-02-16 16:07:06 -07003392 const auto library_pipelinestate = Get<PIPELINE_STATE>(create_info.pLibraryInfo->pLibraries[i]);
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003393 const auto &library_create_info = library_pipelinestate->GetCreateInfo<VkRayTracingPipelineCreateInfoKHR>();
Jeremy Gebben11af9792021-08-20 10:20:09 -06003394 if (library_create_info.maxPipelineRayRecursionDepth != create_info.maxPipelineRayRecursionDepth) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003395 skip |= LogError(
3396 device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraries-03591",
3397 "vkCreateRayTracingPipelinesKHR: Each element (%d) of the pLibraries member of libraries must have been"
3398 "created with the value of maxPipelineRayRecursionDepth (%d) equal to that in this pipeline (%d) .",
Jeremy Gebben11af9792021-08-20 10:20:09 -06003399 i, library_create_info.maxPipelineRayRecursionDepth, create_info.maxPipelineRayRecursionDepth);
sourav parmarcd5fb182020-07-17 12:58:44 -07003400 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06003401 if (library_create_info.pLibraryInfo && (library_create_info.pLibraryInterface->maxPipelineRayHitAttributeSize !=
3402 create_info.pLibraryInterface->maxPipelineRayHitAttributeSize ||
3403 library_create_info.pLibraryInterface->maxPipelineRayPayloadSize !=
3404 create_info.pLibraryInterface->maxPipelineRayPayloadSize)) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003405 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-pLibraryInfo-03593",
3406 "vkCreateRayTracingPipelinesKHR: If pLibraryInfo is not NULL, each element of its pLibraries "
3407 "member must have been created with values of the maxPipelineRayPayloadSize and "
3408 "maxPipelineRayHitAttributeSize members of pLibraryInterface equal to those in this pipeline");
3409 }
3410 if ((flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR) &&
Jeremy Gebben11af9792021-08-20 10:20:09 -06003411 !(library_create_info.flags & VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR)) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003412 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-03594",
3413 "vkCreateRayTracingPipelinesKHR: If flags includes "
3414 "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR, each element of "
3415 "the pLibraries member of libraries must have been created with the "
3416 "VK_PIPELINE_CREATE_RAY_TRACING_SHADER_GROUP_HANDLE_CAPTURE_REPLAY_BIT_KHR bit set");
3417 }
sourav parmar83c31b12020-05-06 12:30:54 -07003418 }
3419 }
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003420 } else {
Jeremy Gebben11af9792021-08-20 10:20:09 -06003421 if (create_info.maxRecursionDepth > phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth) {
sourav parmarcd5fb182020-07-17 12:58:44 -07003422 skip |= LogError(device, "VUID-VkRayTracingPipelineCreateInfoNV-maxRecursionDepth-03457",
3423 "vkCreateRayTracingPipelinesNV: maxRecursionDepth (%d) must be less than or equal to "
3424 "VkPhysicalDeviceRayTracingPropertiesNV::maxRecursionDepth (%d)",
Jeremy Gebben11af9792021-08-20 10:20:09 -06003425 create_info.maxRecursionDepth, phys_dev_ext_props.ray_tracing_propsNV.maxRecursionDepth);
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003426 }
Jason Macnak15f95e82019-08-21 21:52:02 -04003427 }
Jeremy Gebben11af9792021-08-20 10:20:09 -06003428 const auto *groups = create_info.ptr()->pGroups;
Jason Macnak15f95e82019-08-21 21:52:02 -04003429
Jeremy Gebben11af9792021-08-20 10:20:09 -06003430 for (uint32_t stage_index = 0; stage_index < create_info.stageCount; stage_index++) {
Jeremy Gebben84b838b2021-08-23 08:41:39 -06003431 skip |= ValidatePipelineShaderStage(pipeline, pipeline->stage_state[stage_index], false);
Jason Macnak15f95e82019-08-21 21:52:02 -04003432 }
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003433
Jeremy Gebben11af9792021-08-20 10:20:09 -06003434 if ((create_info.flags & VK_PIPELINE_CREATE_LIBRARY_BIT_KHR) == 0) {
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003435 const uint32_t raygen_stages_count = CalcShaderStageCount(*pipeline, VK_SHADER_STAGE_RAYGEN_BIT_KHR);
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003436 if (raygen_stages_count == 0) {
3437 skip |= LogError(
3438 device,
Mike Schuchardt7b152fa2021-08-03 16:30:27 -07003439 isKHR ? "VUID-VkRayTracingPipelineCreateInfoKHR-stage-03425" : "VUID-VkRayTracingPipelineCreateInfoNV-stage-06232",
Ricardo Garcia6f3477e2020-10-21 10:58:53 +02003440 " : The stage member of at least one element of pStages must be VK_SHADER_STAGE_RAYGEN_BIT_KHR.");
3441 }
Jason Macnak15f95e82019-08-21 21:52:02 -04003442 }
ziga-lunarg22f96832022-05-08 22:20:15 +02003443 if ((flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR) != 0 &&
3444 (flags & VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR) != 0) {
3445 skip |= LogError(
3446 device, "VUID-VkRayTracingPipelineCreateInfoKHR-flags-06546",
3447 "vkCreateRayTracingPipelinesKHR: flags (%s) contains both VK_PIPELINE_CREATE_RAY_TRACING_SKIP_TRIANGLES_BIT_KHR and "
3448 "VK_PIPELINE_CREATE_RAY_TRACING_SKIP_AABBS_BIT_KHR bits.",
3449 string_VkPipelineCreateFlags(flags).c_str());
3450 }
Jason Macnak15f95e82019-08-21 21:52:02 -04003451
Jeremy Gebben11af9792021-08-20 10:20:09 -06003452 for (uint32_t group_index = 0; group_index < create_info.groupCount; group_index++) {
Jason Macnak15f95e82019-08-21 21:52:02 -04003453 const auto &group = groups[group_index];
3454
3455 if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_GENERAL_NV) {
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003456 if (!GroupHasValidIndex(
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003457 *pipeline, group.generalShader,
Sebastian Neubauer7c826172021-10-04 12:05:51 +02003458 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 -05003459 skip |= LogError(device,
3460 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03474"
3461 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02413",
3462 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003463 }
3464 if (group.anyHitShader != VK_SHADER_UNUSED_NV || group.closestHitShader != VK_SHADER_UNUSED_NV ||
3465 group.intersectionShader != VK_SHADER_UNUSED_NV) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003466 skip |= LogError(device,
3467 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03475"
3468 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02414",
3469 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003470 }
3471 } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV) {
Nathaniel Cesariod4d8fce2022-05-06 15:01:10 -06003472 if (!GroupHasValidIndex(*pipeline, group.intersectionShader, VK_SHADER_STAGE_INTERSECTION_BIT_NV)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003473 skip |= LogError(device,
3474 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03476"
3475 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02415",
3476 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003477 }
3478 } else if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) {
3479 if (group.intersectionShader != VK_SHADER_UNUSED_NV) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003480 skip |= LogError(device,
3481 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-type-03477"
3482 : "VUID-VkRayTracingShaderGroupCreateInfoNV-type-02416",
3483 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003484 }
3485 }
3486
3487 if (group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_PROCEDURAL_HIT_GROUP_NV ||
3488 group.type == VK_RAY_TRACING_SHADER_GROUP_TYPE_TRIANGLES_HIT_GROUP_NV) {
sjfricke62366d32022-08-01 21:04:10 +09003489 if (!GroupHasValidIndex(*pipeline, group.anyHitShader, VK_SHADER_STAGE_ANY_HIT_BIT_KHR)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003490 skip |= LogError(device,
3491 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-anyHitShader-03479"
3492 : "VUID-VkRayTracingShaderGroupCreateInfoNV-anyHitShader-02418",
3493 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003494 }
sjfricke62366d32022-08-01 21:04:10 +09003495 if (!GroupHasValidIndex(*pipeline, group.closestHitShader, VK_SHADER_STAGE_CLOSEST_HIT_BIT_KHR)) {
Jeff Bolz443c2ca2020-03-19 12:11:51 -05003496 skip |= LogError(device,
3497 isKHR ? "VUID-VkRayTracingShaderGroupCreateInfoKHR-closestHitShader-03478"
3498 : "VUID-VkRayTracingShaderGroupCreateInfoNV-closestHitShader-02417",
3499 ": pGroups[%d]", group_index);
Jason Macnak15f95e82019-08-21 21:52:02 -04003500 }
3501 }
John Zulaufe4474e72019-07-01 17:28:27 -06003502 }
3503 return skip;
Jeff Bolzfbe51582018-09-13 10:01:35 -05003504}
3505
Dave Houltona9df0ce2018-02-07 10:51:23 -07003506uint32_t ValidationCache::MakeShaderHash(VkShaderModuleCreateInfo const *smci) { return XXH32(smci->pCode, smci->codeSize, 0); }
Chris Forbes9a61e082017-07-24 15:35:29 -07003507
Dave Houltona9df0ce2018-02-07 10:51:23 -07003508static ValidationCache *GetValidationCacheInfo(VkShaderModuleCreateInfo const *pCreateInfo) {
Mark Lobodzinski1f887d32020-12-30 15:31:33 -07003509 const auto validation_cache_ci = LvlFindInChain<VkShaderModuleValidationCacheCreateInfoEXT>(pCreateInfo->pNext);
John Zulauf25ea2432019-04-05 10:07:38 -06003510 if (validation_cache_ci) {
John Zulauf146ee802019-04-05 15:31:06 -06003511 return CastFromHandle<ValidationCache *>(validation_cache_ci->validationCache);
Chris Forbes9a61e082017-07-24 15:35:29 -07003512 }
Chris Forbes9a61e082017-07-24 15:35:29 -07003513 return nullptr;
3514}
3515
Mark Lobodzinskib56bbb92019-02-18 11:49:59 -07003516bool CoreChecks::PreCallValidateCreateShaderModule(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
Jeff Bolz5c801d12019-10-09 10:38:45 -05003517 const VkAllocationCallbacks *pAllocator, VkShaderModule *pShaderModule) const {
Chris Forbes4ae55b32017-06-09 14:42:56 -07003518 bool skip = false;
3519 spv_result_t spv_valid = SPV_SUCCESS;
Chris Forbes4ae55b32017-06-09 14:42:56 -07003520
Mark Lobodzinski90eea5b2020-05-15 12:54:00 -06003521 if (disabled[shader_validation]) {
Chris Forbes4ae55b32017-06-09 14:42:56 -07003522 return false;
3523 }
3524
sfricke-samsung45996a42021-09-16 13:45:27 -07003525 auto have_glsl_shader = IsExtEnabled(device_extensions.vk_nv_glsl_shader);
Chris Forbes4ae55b32017-06-09 14:42:56 -07003526
3527 if (!have_glsl_shader && (pCreateInfo->codeSize % 4)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003528 skip |= LogError(device, "VUID-VkShaderModuleCreateInfo-pCode-01376",
3529 "SPIR-V module not valid: Codesize must be a multiple of 4 but is " PRINTF_SIZE_T_SPECIFIER ".",
3530 pCreateInfo->codeSize);
Chris Forbes4ae55b32017-06-09 14:42:56 -07003531 } else {
Chris Forbes9a61e082017-07-24 15:35:29 -07003532 auto cache = GetValidationCacheInfo(pCreateInfo);
3533 uint32_t hash = 0;
Tony-LunarG55fdf1e2021-01-13 14:32:56 -07003534 // If app isn't using a shader validation cache, use the default one from CoreChecks
3535 if (!cache) cache = CastFromHandle<ValidationCache *>(core_validation_cache);
Chris Forbes9a61e082017-07-24 15:35:29 -07003536 if (cache) {
3537 hash = ValidationCache::MakeShaderHash(pCreateInfo);
Dave Houltona9df0ce2018-02-07 10:51:23 -07003538 if (cache->Contains(hash)) return false;
Chris Forbes9a61e082017-07-24 15:35:29 -07003539 }
3540
Jeremy Hayesb3e4d532019-08-16 10:08:49 -06003541 // Use SPIRV-Tools validator to try and catch any issues with the module itself. If specialization constants are present,
3542 // the default values will be used during validation.
sfricke-samsung45996a42021-09-16 13:45:27 -07003543 spv_target_env spirv_environment = PickSpirvEnv(api_version, IsExtEnabled(device_extensions.vk_khr_spirv_1_4));
Dave Houlton0ea2d012018-06-21 14:00:26 -06003544 spv_context ctx = spvContextCreate(spirv_environment);
Dave Houltona9df0ce2018-02-07 10:51:23 -07003545 spv_const_binary_t binary{pCreateInfo->pCode, pCreateInfo->codeSize / sizeof(uint32_t)};
Chris Forbes4ae55b32017-06-09 14:42:56 -07003546 spv_diagnostic diag = nullptr;
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003547 spvtools::ValidatorOptions options;
3548 AdjustValidatorOptions(device_extensions, enabled_features, options);
Karl Schultzfda1b382018-08-08 18:56:11 -06003549 spv_valid = spvValidateWithOptions(ctx, options, &binary, &diag);
Chris Forbes4ae55b32017-06-09 14:42:56 -07003550 if (spv_valid != SPV_SUCCESS) {
3551 if (!have_glsl_shader || (pCreateInfo->pCode[0] == spv::MagicNumber)) {
Mark Lobodzinski12b9be92020-01-30 15:25:55 -07003552 if (spv_valid == SPV_WARNING) {
3553 skip |= LogWarning(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s",
3554 diag && diag->error ? diag->error : "(no error text)");
3555 } else {
3556 skip |= LogError(device, kVUID_Core_Shader_InconsistentSpirv, "SPIR-V module not valid: %s",
3557 diag && diag->error ? diag->error : "(no error text)");
3558 }
Chris Forbes4ae55b32017-06-09 14:42:56 -07003559 }
Chris Forbes9a61e082017-07-24 15:35:29 -07003560 } else {
3561 if (cache) {
3562 cache->Insert(hash);
3563 }
Chris Forbes4ae55b32017-06-09 14:42:56 -07003564 }
3565
3566 spvDiagnosticDestroy(diag);
3567 spvContextDestroy(ctx);
3568 }
3569
Chris Forbes4ae55b32017-06-09 14:42:56 -07003570 return skip;
Mark Lobodzinski01734072019-02-13 17:39:15 -07003571}
3572
Tony-LunarG1672d002022-08-03 14:35:34 -06003573bool CoreChecks::PreCallValidateGetShaderModuleIdentifierEXT(VkDevice device, VkShaderModule shaderModule,
3574 VkShaderModuleIdentifierEXT *pIdentifier) const {
3575 bool skip = false;
3576 if (!(enabled_features.shader_module_identifier_features.shaderModuleIdentifier)) {
3577 skip |= LogError(device, "VUID-vkGetShaderModuleIdentifierEXT-shaderModuleIdentifier-06884",
3578 "vkGetShaderModuleIdentifierEXT() was called when the shaderModuleIdentifier feature was not enabled");
3579 }
3580 return skip;
3581}
3582
3583bool CoreChecks::PreCallValidateGetShaderModuleCreateInfoIdentifierEXT(VkDevice device, const VkShaderModuleCreateInfo *pCreateInfo,
3584 VkShaderModuleIdentifierEXT *pIdentifier) const {
3585 bool skip = false;
3586 if (!(enabled_features.shader_module_identifier_features.shaderModuleIdentifier)) {
3587 skip |= LogError(
3588 device, "VUID-vkGetShaderModuleCreateInfoIdentifierEXT-shaderModuleIdentifier-06885",
3589 "vkGetShaderModuleCreateInfoIdentifierEXT() was called when the shaderModuleIdentifier feature was not enabled");
3590 }
3591 return skip;
3592}
3593
sjfricke4f600c82022-06-09 14:21:32 +09003594bool CoreChecks::ValidateComputeWorkGroupSizes(const SHADER_MODULE_STATE &module_state, const spirv_inst_iter &entrypoint,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003595 const PipelineStageState &stage_state, uint32_t local_size_x, uint32_t local_size_y,
3596 uint32_t local_size_z) const {
Lockeaa8fdc02019-04-02 11:59:20 -06003597 bool skip = false;
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003598 // If spec constants were used then the local size are already found if possible
3599 if (local_size_x == 0) {
sjfricke4f600c82022-06-09 14:21:32 +09003600 if (!module_state.FindLocalSize(entrypoint, local_size_x, local_size_y, local_size_z)) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003601 return skip; // no local size found
Lockeaa8fdc02019-04-02 11:59:20 -06003602 }
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003603 }
Lockeaa8fdc02019-04-02 11:59:20 -06003604
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003605 if (local_size_x > phys_dev_props.limits.maxComputeWorkGroupSize[0]) {
sjfricke4f600c82022-06-09 14:21:32 +09003606 skip |= LogError(module_state.vk_shader_module(), "VUID-RuntimeSpirv-x-06429",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003607 "%s local_size_x (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[0] (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003608 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003609 phys_dev_props.limits.maxComputeWorkGroupSize[0]);
3610 }
3611 if (local_size_y > phys_dev_props.limits.maxComputeWorkGroupSize[1]) {
sjfricke4f600c82022-06-09 14:21:32 +09003612 skip |= LogError(module_state.vk_shader_module(), "VUID-RuntimeSpirv-y-06430",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003613 "%s local_size_y (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[1] (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003614 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003615 phys_dev_props.limits.maxComputeWorkGroupSize[1]);
3616 }
3617 if (local_size_z > phys_dev_props.limits.maxComputeWorkGroupSize[2]) {
sjfricke4f600c82022-06-09 14:21:32 +09003618 skip |= LogError(module_state.vk_shader_module(), "VUID-RuntimeSpirv-z-06431",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003619 "%s local_size_z (%" PRIu32 ") exceeds device limit maxComputeWorkGroupSize[2] (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003620 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003621 phys_dev_props.limits.maxComputeWorkGroupSize[2]);
3622 }
3623
3624 uint32_t limit = phys_dev_props.limits.maxComputeWorkGroupInvocations;
3625 uint64_t invocations = local_size_x * local_size_y;
3626 // Prevent overflow.
3627 bool fail = false;
3628 if (invocations > UINT32_MAX || invocations > limit) {
3629 fail = true;
3630 }
3631 if (!fail) {
3632 invocations *= local_size_z;
Lockeaa8fdc02019-04-02 11:59:20 -06003633 if (invocations > UINT32_MAX || invocations > limit) {
3634 fail = true;
3635 }
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003636 }
3637 if (fail) {
sjfricke4f600c82022-06-09 14:21:32 +09003638 skip |= LogError(module_state.vk_shader_module(), "VUID-RuntimeSpirv-x-06432",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003639 "%s local_size (%" PRIu32 ", %" PRIu32 ", %" PRIu32
3640 ") exceeds device limit maxComputeWorkGroupInvocations (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003641 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x, local_size_y,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003642 local_size_z, limit);
3643 }
ziga-lunarg11fecb92021-09-20 16:48:06 +02003644
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003645 const auto subgroup_flags = VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT |
3646 VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT;
ziga-lunargd46c7af2022-04-16 14:05:38 +02003647 const auto *required_subgroup_size_features =
3648 LvlFindInChain<VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT>(stage_state.create_info->pNext);
ziga-lunarg561d7222022-05-08 20:07:02 +02003649 if (required_subgroup_size_features) {
sjfrickef05418b2022-08-01 18:57:20 +09003650 const uint32_t requiredSubgroupSize = required_subgroup_size_features->requiredSubgroupSize;
ziga-lunarg561d7222022-05-08 20:07:02 +02003651 skip |= RequireFeature(enabled_features.core13.subgroupSizeControl, "subgroupSizeControl",
3652 "VUID-VkPipelineShaderStageCreateInfo-pNext-02755");
3653 if ((phys_dev_ext_props.subgroup_size_control_props.requiredSubgroupSizeStages & stage_state.stage_flag) == 0) {
3654 skip |= LogError(
sjfricke4f600c82022-06-09 14:21:32 +09003655 module_state.vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-pNext-02755",
ziga-lunarg561d7222022-05-08 20:07:02 +02003656 "Stage %s is not in VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::requiredSubgroupSizeStages (%s).",
3657 string_VkShaderStageFlagBits(stage_state.stage_flag),
3658 string_VkShaderStageFlags(phys_dev_ext_props.subgroup_size_control_props.requiredSubgroupSizeStages).c_str());
3659 }
sjfrickef05418b2022-08-01 18:57:20 +09003660 if ((invocations > requiredSubgroupSize * phys_dev_ext_props.subgroup_size_control_props.maxComputeWorkgroupSubgroups)) {
ziga-lunarg561d7222022-05-08 20:07:02 +02003661 skip |=
sjfricke4f600c82022-06-09 14:21:32 +09003662 LogError(module_state.vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-pNext-02756",
ziga-lunargd46c7af2022-04-16 14:05:38 +02003663 "Local workgroup size (%" PRIu32 ", %" PRIu32 ", %" PRIu32
3664 ") is greater than VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT::requiredSubgroupSize (%" PRIu32
3665 ") * maxComputeWorkgroupSubgroups (%" PRIu32 ").",
sjfrickef05418b2022-08-01 18:57:20 +09003666 local_size_x, local_size_y, local_size_z, requiredSubgroupSize,
ziga-lunargd46c7af2022-04-16 14:05:38 +02003667 phys_dev_ext_props.subgroup_size_control_props.maxComputeWorkgroupSubgroups);
ziga-lunarg561d7222022-05-08 20:07:02 +02003668 }
3669 if ((stage_state.create_info->flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT) > 0) {
sjfrickef05418b2022-08-01 18:57:20 +09003670 if (SafeModulo(local_size_x, requiredSubgroupSize) != 0) {
ziga-lunarg561d7222022-05-08 20:07:02 +02003671 skip |= LogError(
sjfricke4f600c82022-06-09 14:21:32 +09003672 module_state.vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-pNext-02757",
ziga-lunarg561d7222022-05-08 20:07:02 +02003673 "Local workgroup size x (%" PRIu32
3674 ") is not a multiple of VkPipelineShaderStageRequiredSubgroupSizeCreateInfoEXT::requiredSubgroupSize (%" PRIu32
3675 ").",
sjfrickef05418b2022-08-01 18:57:20 +09003676 local_size_x, requiredSubgroupSize);
ziga-lunarg561d7222022-05-08 20:07:02 +02003677 }
ziga-lunargd46c7af2022-04-16 14:05:38 +02003678 }
sjfrickef05418b2022-08-01 18:57:20 +09003679 if (!IsPowerOfTwo(requiredSubgroupSize)) {
3680 skip |= LogError(module_state.vk_shader_module(),
sjfrickebf1244c2022-08-01 18:57:28 +09003681 "VUID-VkPipelineShaderStageRequiredSubgroupSizeCreateInfo-requiredSubgroupSize-02760",
sjfrickef05418b2022-08-01 18:57:20 +09003682 "VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::requiredSubgroupSizeStages (%" PRIu32
3683 ") is not a power of 2.",
3684 requiredSubgroupSize);
3685 }
3686 if (requiredSubgroupSize < phys_dev_ext_props.subgroup_size_control_props.minSubgroupSize) {
3687 skip |= LogError(module_state.vk_shader_module(),
sjfrickebf1244c2022-08-01 18:57:28 +09003688 "VUID-VkPipelineShaderStageRequiredSubgroupSizeCreateInfo-requiredSubgroupSize-02761",
sjfrickef05418b2022-08-01 18:57:20 +09003689 "VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::requiredSubgroupSizeStages (%" PRIu32
3690 ") is less than minSubgroupSize (%" PRIu32 ").",
3691 requiredSubgroupSize, phys_dev_ext_props.subgroup_size_control_props.minSubgroupSize);
3692 }
3693 if (requiredSubgroupSize > phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize) {
3694 skip |= LogError(module_state.vk_shader_module(),
sjfrickebf1244c2022-08-01 18:57:28 +09003695 "VUID-VkPipelineShaderStageRequiredSubgroupSizeCreateInfo-requiredSubgroupSize-02762",
sjfrickef05418b2022-08-01 18:57:20 +09003696 "VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::requiredSubgroupSizeStages (%" PRIu32
3697 ") is greater than maxSubgroupSize (%" PRIu32 ").",
3698 requiredSubgroupSize, phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize);
3699 }
ziga-lunargd46c7af2022-04-16 14:05:38 +02003700 }
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003701 if ((stage_state.create_info->flags & subgroup_flags) == subgroup_flags) {
3702 if (SafeModulo(local_size_x, phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize) != 0) {
3703 skip |= LogError(
sjfricke4f600c82022-06-09 14:21:32 +09003704 module_state.vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-flags-02758",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003705 "%s flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT and "
3706 "VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT bits, but local workgroup size in the X "
3707 "dimension (%" PRIu32
3708 ") is not a multiple of VkPhysicalDeviceSubgroupSizeControlPropertiesEXT::maxSubgroupSize (%" PRIu32 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003709 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003710 phys_dev_ext_props.subgroup_size_control_props.maxSubgroupSize);
3711 }
3712 } else if ((stage_state.create_info->flags & VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT) &&
3713 (stage_state.create_info->flags & VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT) == 0) {
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003714 if (!required_subgroup_size_features) {
3715 if (SafeModulo(local_size_x, phys_dev_props_core11.subgroupSize) != 0) {
ziga-lunarg11fecb92021-09-20 16:48:06 +02003716 skip |= LogError(
sjfricke4f600c82022-06-09 14:21:32 +09003717 module_state.vk_shader_module(), "VUID-VkPipelineShaderStageCreateInfo-flags-02759",
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003718 "%s flags contain VK_PIPELINE_SHADER_STAGE_CREATE_REQUIRE_FULL_SUBGROUPS_BIT_EXT bit, and not the"
3719 "VK_PIPELINE_SHADER_STAGE_CREATE_ALLOW_VARYING_SUBGROUP_SIZE_BIT_EXT bit, but local workgroup size in the "
3720 "X dimension (%" PRIu32 ") is not a multiple of VkPhysicalDeviceVulkan11Properties::subgroupSize (%" PRIu32
3721 ").",
sjfricke4f600c82022-06-09 14:21:32 +09003722 report_data->FormatHandle(module_state.vk_shader_module()).c_str(), local_size_x,
sfricke-samsung61d50ec2022-02-13 17:01:25 -08003723 phys_dev_props_core11.subgroupSize);
ziga-lunarg11fecb92021-09-20 16:48:06 +02003724 }
3725 }
Lockeaa8fdc02019-04-02 11:59:20 -06003726 }
3727 return skip;
3728}
Tony-LunarG8a51b7d2020-07-01 15:57:23 -06003729
3730spv_target_env PickSpirvEnv(uint32_t api_version, bool spirv_1_4) {
Tony-LunarGe67fcc22022-01-03 16:40:53 -07003731 if (api_version >= VK_API_VERSION_1_3) {
3732 return SPV_ENV_VULKAN_1_3;
3733 } else if (api_version >= VK_API_VERSION_1_2) {
Tony-LunarG8a51b7d2020-07-01 15:57:23 -06003734 return SPV_ENV_VULKAN_1_2;
3735 } else if (api_version >= VK_API_VERSION_1_1) {
3736 if (spirv_1_4) {
3737 return SPV_ENV_VULKAN_1_1_SPIRV_1_4;
3738 } else {
3739 return SPV_ENV_VULKAN_1_1;
3740 }
3741 }
3742 return SPV_ENV_VULKAN_1_0;
3743}
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003744
sfricke-samsungecc112a2021-09-03 05:32:17 -07003745// Some Vulkan extensions/features are just all done in spirv-val behind optional settings
Jeremy Gebben5d970742021-05-31 16:04:14 -06003746void AdjustValidatorOptions(const DeviceExtensions &device_extensions, const DeviceFeatures &enabled_features,
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003747 spvtools::ValidatorOptions &options) {
sfricke-samsungecc112a2021-09-03 05:32:17 -07003748 // VK_KHR_relaxed_block_layout never had a feature bit so just enabling the extension allows relaxed layout
3749 // Was promotoed in Vulkan 1.1 so anyone using Vulkan 1.1 also gets this for free
sfricke-samsung45996a42021-09-16 13:45:27 -07003750 if (IsExtEnabled(device_extensions.vk_khr_relaxed_block_layout)) {
sfricke-samsungecc112a2021-09-03 05:32:17 -07003751 // --relax-block-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003752 options.SetRelaxBlockLayout(true);
3753 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003754
3755 // The rest of the settings are controlled from a feature bit, which are set correctly in the state tracking. Regardless of
3756 // Vulkan version used, the feature bit is needed (also described in the spec).
3757
3758 if (enabled_features.core12.uniformBufferStandardLayout == VK_TRUE) {
3759 // --uniform-buffer-standard-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003760 options.SetUniformBufferStandardLayout(true);
3761 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003762 if (enabled_features.core12.scalarBlockLayout == VK_TRUE) {
3763 // --scalar-block-layout
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003764 options.SetScalarBlockLayout(true);
3765 }
sfricke-samsungecc112a2021-09-03 05:32:17 -07003766 if (enabled_features.workgroup_memory_explicit_layout_features.workgroupMemoryExplicitLayoutScalarBlockLayout) {
3767 // --workgroup-scalar-block-layout
Caio Marcelo de Oliveira Filhod1bfbcd2021-01-27 01:44:04 -08003768 options.SetWorkgroupScalarBlockLayout(true);
3769 }
Tony-LunarG273f32f2021-09-28 08:56:30 -06003770 if (enabled_features.core13.maintenance4) {
sfricke-samsungd3c917b2021-10-19 08:24:57 -07003771 // --allow-localsizeid
3772 options.SetAllowLocalSizeId(true);
3773 }
Tony-LunarG9fe69a42020-07-23 15:09:37 -06003774}