blob: b1fbef287cfa2cdc046596a41e13293d2daf1347 [file] [log] [blame]
sfricke-samsung962cad92021-04-13 00:46:29 -07001/* Copyright (c) 2021 The Khronos Group Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * Author: Spencer Fricke <s.fricke@samsung.com>
16 */
17
18#include "shader_module.h"
19
20#include <sstream>
21#include <string>
22
23#include "vk_layer_data.h"
24#include "vk_layer_utils.h"
Jeremy Gebben5d970742021-05-31 16:04:14 -060025#include "pipeline_state.h"
26#include "descriptor_sets.h"
sfricke-samsung962cad92021-04-13 00:46:29 -070027
28void decoration_set::merge(decoration_set const &other) {
29 if (other.flags & location_bit) location = other.location;
30 if (other.flags & component_bit) component = other.component;
31 if (other.flags & input_attachment_index_bit) input_attachment_index = other.input_attachment_index;
32 if (other.flags & descriptor_set_bit) descriptor_set = other.descriptor_set;
33 if (other.flags & binding_bit) binding = other.binding;
34 if (other.flags & builtin_bit) builtin = other.builtin;
35 flags |= other.flags;
36}
37
38void decoration_set::add(uint32_t decoration, uint32_t value) {
39 switch (decoration) {
40 case spv::DecorationLocation:
41 flags |= location_bit;
42 location = value;
43 break;
44 case spv::DecorationPatch:
45 flags |= patch_bit;
46 break;
47 case spv::DecorationRelaxedPrecision:
48 flags |= relaxed_precision_bit;
49 break;
50 case spv::DecorationBlock:
51 flags |= block_bit;
52 break;
53 case spv::DecorationBufferBlock:
54 flags |= buffer_block_bit;
55 break;
56 case spv::DecorationComponent:
57 flags |= component_bit;
58 component = value;
59 break;
60 case spv::DecorationInputAttachmentIndex:
61 flags |= input_attachment_index_bit;
62 input_attachment_index = value;
63 break;
64 case spv::DecorationDescriptorSet:
65 flags |= descriptor_set_bit;
66 descriptor_set = value;
67 break;
68 case spv::DecorationBinding:
69 flags |= binding_bit;
70 binding = value;
71 break;
72 case spv::DecorationNonWritable:
73 flags |= nonwritable_bit;
74 break;
75 case spv::DecorationBuiltIn:
76 flags |= builtin_bit;
77 builtin = value;
78 break;
Lionel Landwerlin38d2e122021-07-21 14:21:47 +030079 case spv::DecorationNonReadable:
80 flags |= nonreadable_bit;
81 break;
sfricke-samsung962cad92021-04-13 00:46:29 -070082 }
83}
84
85std::string shader_struct_member::GetLocationDesc(uint32_t index_used_bytes) const {
86 std::string desc = "";
87 if (array_length_hierarchy.size() > 0) {
88 desc += " index:";
89 for (const auto block_size : array_block_size) {
90 desc += "[";
91 desc += std::to_string(index_used_bytes / (block_size * size));
92 desc += "]";
93 index_used_bytes = index_used_bytes % (block_size * size);
94 }
95 }
96 const int struct_members_size = static_cast<int>(struct_members.size());
97 if (struct_members_size > 0) {
98 desc += " member:";
99 for (int i = struct_members_size - 1; i >= 0; --i) {
100 if (index_used_bytes > struct_members[i].offset) {
101 desc += std::to_string(i);
102 desc += struct_members[i].GetLocationDesc(index_used_bytes - struct_members[i].offset);
103 break;
104 }
105 }
106 } else {
107 desc += " offset:";
108 desc += std::to_string(index_used_bytes);
109 }
110 return desc;
111}
112
113static unsigned ExecutionModelToShaderStageFlagBits(unsigned mode) {
114 switch (mode) {
115 case spv::ExecutionModelVertex:
116 return VK_SHADER_STAGE_VERTEX_BIT;
117 case spv::ExecutionModelTessellationControl:
118 return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
119 case spv::ExecutionModelTessellationEvaluation:
120 return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
121 case spv::ExecutionModelGeometry:
122 return VK_SHADER_STAGE_GEOMETRY_BIT;
123 case spv::ExecutionModelFragment:
124 return VK_SHADER_STAGE_FRAGMENT_BIT;
125 case spv::ExecutionModelGLCompute:
126 return VK_SHADER_STAGE_COMPUTE_BIT;
127 case spv::ExecutionModelRayGenerationNV:
128 return VK_SHADER_STAGE_RAYGEN_BIT_NV;
129 case spv::ExecutionModelAnyHitNV:
130 return VK_SHADER_STAGE_ANY_HIT_BIT_NV;
131 case spv::ExecutionModelClosestHitNV:
132 return VK_SHADER_STAGE_CLOSEST_HIT_BIT_NV;
133 case spv::ExecutionModelMissNV:
134 return VK_SHADER_STAGE_MISS_BIT_NV;
135 case spv::ExecutionModelIntersectionNV:
136 return VK_SHADER_STAGE_INTERSECTION_BIT_NV;
137 case spv::ExecutionModelCallableNV:
138 return VK_SHADER_STAGE_CALLABLE_BIT_NV;
139 case spv::ExecutionModelTaskNV:
140 return VK_SHADER_STAGE_TASK_BIT_NV;
141 case spv::ExecutionModelMeshNV:
142 return VK_SHADER_STAGE_MESH_BIT_NV;
143 default:
144 return 0;
145 }
146}
147
148// For some analyses, we need to know about all ids referenced by the static call tree of a particular entrypoint. This is
149// important for identifying the set of shader resources actually used by an entrypoint, for example.
150// Note: we only explore parts of the image which might actually contain ids we care about for the above analyses.
151// - NOT the shader input/output interfaces.
152//
153// TODO: The set of interesting opcodes here was determined by eyeballing the SPIRV spec. It might be worth
154// converting parts of this to be generated from the machine-readable spec instead.
155layer_data::unordered_set<uint32_t> SHADER_MODULE_STATE::MarkAccessibleIds(spirv_inst_iter entrypoint) const {
156 layer_data::unordered_set<uint32_t> ids;
157 layer_data::unordered_set<uint32_t> worklist;
158 worklist.insert(entrypoint.word(2));
159
160 while (!worklist.empty()) {
161 auto id_iter = worklist.begin();
162 auto id = *id_iter;
163 worklist.erase(id_iter);
164
165 auto insn = get_def(id);
166 if (insn == end()) {
167 // ID is something we didn't collect in BuildDefIndex. that's OK -- we'll stumble across all kinds of things here
168 // that we may not care about.
169 continue;
170 }
171
172 // Try to add to the output set
173 if (!ids.insert(id).second) {
174 continue; // If we already saw this id, we don't want to walk it again.
175 }
176
177 switch (insn.opcode()) {
178 case spv::OpFunction:
179 // Scan whole body of the function, enlisting anything interesting
180 while (++insn, insn.opcode() != spv::OpFunctionEnd) {
181 switch (insn.opcode()) {
182 case spv::OpLoad:
183 worklist.insert(insn.word(3)); // ptr
184 break;
185 case spv::OpStore:
186 worklist.insert(insn.word(1)); // ptr
187 break;
188 case spv::OpAccessChain:
189 case spv::OpInBoundsAccessChain:
190 worklist.insert(insn.word(3)); // base ptr
191 break;
192 case spv::OpSampledImage:
193 case spv::OpImageSampleImplicitLod:
194 case spv::OpImageSampleExplicitLod:
195 case spv::OpImageSampleDrefImplicitLod:
196 case spv::OpImageSampleDrefExplicitLod:
197 case spv::OpImageSampleProjImplicitLod:
198 case spv::OpImageSampleProjExplicitLod:
199 case spv::OpImageSampleProjDrefImplicitLod:
200 case spv::OpImageSampleProjDrefExplicitLod:
201 case spv::OpImageFetch:
202 case spv::OpImageGather:
203 case spv::OpImageDrefGather:
204 case spv::OpImageRead:
205 case spv::OpImage:
206 case spv::OpImageQueryFormat:
207 case spv::OpImageQueryOrder:
208 case spv::OpImageQuerySizeLod:
209 case spv::OpImageQuerySize:
210 case spv::OpImageQueryLod:
211 case spv::OpImageQueryLevels:
212 case spv::OpImageQuerySamples:
213 case spv::OpImageSparseSampleImplicitLod:
214 case spv::OpImageSparseSampleExplicitLod:
215 case spv::OpImageSparseSampleDrefImplicitLod:
216 case spv::OpImageSparseSampleDrefExplicitLod:
217 case spv::OpImageSparseSampleProjImplicitLod:
218 case spv::OpImageSparseSampleProjExplicitLod:
219 case spv::OpImageSparseSampleProjDrefImplicitLod:
220 case spv::OpImageSparseSampleProjDrefExplicitLod:
221 case spv::OpImageSparseFetch:
222 case spv::OpImageSparseGather:
223 case spv::OpImageSparseDrefGather:
224 case spv::OpImageTexelPointer:
225 worklist.insert(insn.word(3)); // Image or sampled image
226 break;
227 case spv::OpImageWrite:
228 worklist.insert(insn.word(1)); // Image -- different operand order to above
229 break;
230 case spv::OpFunctionCall:
231 for (uint32_t i = 3; i < insn.len(); i++) {
232 worklist.insert(insn.word(i)); // fn itself, and all args
233 }
234 break;
235
236 case spv::OpExtInst:
237 for (uint32_t i = 5; i < insn.len(); i++) {
238 worklist.insert(insn.word(i)); // Operands to ext inst
239 }
240 break;
241
242 default: {
243 if (AtomicOperation(insn.opcode())) {
244 if (insn.opcode() == spv::OpAtomicStore) {
245 worklist.insert(insn.word(1)); // ptr
246 } else {
247 worklist.insert(insn.word(3)); // ptr
248 }
249 }
250 break;
251 }
252 }
253 }
254 break;
255 }
256 }
257
258 return ids;
259}
260
261void SHADER_MODULE_STATE::ProcessExecutionModes(const spirv_inst_iter &entrypoint, PIPELINE_STATE *pipeline) const {
262 auto entrypoint_id = entrypoint.word(2);
263 bool is_point_mode = false;
264
265 auto it = execution_mode_inst.find(entrypoint_id);
266 if (it != execution_mode_inst.end()) {
267 for (auto insn : it->second) {
268 switch (insn.word(2)) {
269 case spv::ExecutionModePointMode:
270 // In tessellation shaders, PointMode is separate and trumps the tessellation topology.
271 is_point_mode = true;
272 break;
273
274 case spv::ExecutionModeOutputPoints:
275 pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
276 break;
277
278 case spv::ExecutionModeIsolines:
279 case spv::ExecutionModeOutputLineStrip:
280 pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_LINE_STRIP;
281 break;
282
283 case spv::ExecutionModeTriangles:
284 case spv::ExecutionModeQuads:
285 case spv::ExecutionModeOutputTriangleStrip:
286 case spv::ExecutionModeOutputTrianglesNV:
287 pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP;
288 break;
289 }
290 }
291 }
292
293 if (is_point_mode) pipeline->topology_at_rasterizer = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
294}
295
296void SHADER_MODULE_STATE::BuildDefIndex() {
297 function_set func_set = {};
298 EntryPoint *entry_point = nullptr;
299
300 for (auto insn : *this) {
301 // offset is not 0, it means it's updated and the offset is in a Function.
302 if (func_set.offset) {
303 func_set.op_lists.emplace(insn.opcode(), insn.offset());
304 } else if (entry_point) {
305 entry_point->decorate_list.emplace(insn.opcode(), insn.offset());
306 }
307
308 switch (insn.opcode()) {
309 // Types
310 case spv::OpTypeVoid:
311 case spv::OpTypeBool:
312 case spv::OpTypeInt:
313 case spv::OpTypeFloat:
314 case spv::OpTypeVector:
315 case spv::OpTypeMatrix:
316 case spv::OpTypeImage:
317 case spv::OpTypeSampler:
318 case spv::OpTypeSampledImage:
319 case spv::OpTypeArray:
320 case spv::OpTypeRuntimeArray:
321 case spv::OpTypeStruct:
322 case spv::OpTypeOpaque:
323 case spv::OpTypePointer:
324 case spv::OpTypeFunction:
325 case spv::OpTypeEvent:
326 case spv::OpTypeDeviceEvent:
327 case spv::OpTypeReserveId:
328 case spv::OpTypeQueue:
329 case spv::OpTypePipe:
330 case spv::OpTypeAccelerationStructureNV:
331 case spv::OpTypeCooperativeMatrixNV:
332 def_index[insn.word(1)] = insn.offset();
333 break;
334
335 // Fixed constants
336 case spv::OpConstantTrue:
337 case spv::OpConstantFalse:
338 case spv::OpConstant:
339 case spv::OpConstantComposite:
340 case spv::OpConstantSampler:
341 case spv::OpConstantNull:
342 def_index[insn.word(2)] = insn.offset();
343 break;
344
345 // Specialization constants
346 case spv::OpSpecConstantTrue:
347 case spv::OpSpecConstantFalse:
348 case spv::OpSpecConstant:
349 case spv::OpSpecConstantComposite:
350 case spv::OpSpecConstantOp:
351 def_index[insn.word(2)] = insn.offset();
352 break;
353
354 // Variables
355 case spv::OpVariable:
356 def_index[insn.word(2)] = insn.offset();
357 break;
358
359 // Functions
360 case spv::OpFunction:
361 def_index[insn.word(2)] = insn.offset();
362 func_set.id = insn.word(2);
363 func_set.offset = insn.offset();
364 func_set.op_lists.clear();
365 break;
366
367 // Decorations
368 case spv::OpDecorate: {
369 auto target_id = insn.word(1);
370 decorations[target_id].add(insn.word(2), insn.len() > 3u ? insn.word(3) : 0u);
371 decoration_inst.push_back(insn);
372 if (insn.word(2) == spv::DecorationBuiltIn) {
373 builtin_decoration_list.emplace_back(insn.offset(), static_cast<spv::BuiltIn>(insn.word(3)));
Nathaniel Cesariocf69bda2021-06-22 13:23:42 -0600374 } else if (insn.word(2) == spv::DecorationSpecId) {
375 spec_const_map[insn.word(3)] = target_id;
sfricke-samsung962cad92021-04-13 00:46:29 -0700376 }
377
378 } break;
379 case spv::OpGroupDecorate: {
380 auto const &src = decorations[insn.word(1)];
381 for (auto i = 2u; i < insn.len(); i++) decorations[insn.word(i)].merge(src);
382 } break;
383 case spv::OpMemberDecorate: {
384 member_decoration_inst.push_back(insn);
385 if (insn.word(3) == spv::DecorationBuiltIn) {
386 builtin_decoration_list.emplace_back(insn.offset(), static_cast<spv::BuiltIn>(insn.word(4)));
387 }
388 } break;
389
390 // Entry points ... add to the entrypoint table
391 case spv::OpEntryPoint: {
392 if (entry_point != nullptr) {
393 multiple_entry_points = true;
394 }
395
396 // Entry points do not have an id (the id is the function id) and thus need their own table
397 auto entrypoint_name = reinterpret_cast<char const *>(&insn.word(3));
398 auto execution_model = insn.word(1);
399 auto entrypoint_stage = ExecutionModelToShaderStageFlagBits(execution_model);
400 entry_points.emplace(entrypoint_name,
401 EntryPoint{insn.offset(), static_cast<VkShaderStageFlagBits>(entrypoint_stage)});
402
403 auto range = entry_points.equal_range(entrypoint_name);
404 for (auto it = range.first; it != range.second; ++it) {
405 if (it->second.offset == insn.offset()) {
406 entry_point = &(it->second);
407 break;
408 }
409 }
410 assert(entry_point != nullptr);
411 break;
412 }
413 case spv::OpFunctionEnd: {
414 assert(entry_point != nullptr);
415 func_set.length = insn.offset() - func_set.offset;
416 entry_point->function_set_list.emplace_back(func_set);
417 break;
418 }
419
420 // Copy operations
421 case spv::OpCopyLogical:
422 case spv::OpCopyObject: {
423 def_index[insn.word(2)] = insn.offset();
424 break;
425 }
426
427 // Execution Mode
428 case spv::OpExecutionMode: {
429 execution_mode_inst[insn.word(1)].push_back(insn);
430 } break;
431
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +0300432 case spv::OpLoad: {
433 def_index[insn.word(2)] = insn.offset();
434 } break;
435
sfricke-samsung962cad92021-04-13 00:46:29 -0700436 default:
437 // We don't care about any other defs for now.
438 break;
439 }
440 }
441}
442
443std::vector<uint32_t> SHADER_MODULE_STATE::PreprocessShaderBinary(uint32_t *src_binary, size_t binary_size, spv_target_env env) {
444 std::vector<uint32_t> src(src_binary, src_binary + binary_size / sizeof(uint32_t));
445
446 // Check if there are any group decoration instructions, and flatten them if found.
447 bool has_group_decoration = false;
448 bool done = false;
449
450 // Walk through the first part of the SPIR-V module, looking for group decoration and specialization constant instructions.
451 // Skip the header (5 words).
452 auto itr = spirv_inst_iter(src.begin(), src.begin() + 5);
453 auto itrend = spirv_inst_iter(src.begin(), src.end());
454 while (itr != itrend && !done) {
455 spv::Op opcode = (spv::Op)itr.opcode();
456 switch (opcode) {
457 case spv::OpDecorationGroup:
458 case spv::OpGroupDecorate:
459 case spv::OpGroupMemberDecorate:
460 has_group_decoration = true;
461 break;
462 case spv::OpSpecConstantTrue:
463 case spv::OpSpecConstantFalse:
464 case spv::OpSpecConstant:
465 case spv::OpSpecConstantComposite:
466 case spv::OpSpecConstantOp:
467 has_specialization_constants = true;
468 break;
469 case spv::OpFunction:
470 // An OpFunction indicates there are no more decorations
471 done = true;
472 break;
473 default:
474 break;
475 }
476 itr++;
477 }
478
479 if (has_group_decoration) {
480 spvtools::Optimizer optimizer(env);
481 optimizer.RegisterPass(spvtools::CreateFlattenDecorationPass());
482 std::vector<uint32_t> optimized_binary;
483 // Run optimizer to flatten decorations only, set skip_validation so as to not re-run validator
484 auto result =
485 optimizer.Run(src_binary, binary_size / sizeof(uint32_t), &optimized_binary, spvtools::ValidatorOptions(), true);
486 if (result) {
487 return optimized_binary;
488 }
489 }
490 // Return the original module.
491 return src;
492}
493
494static char const *StorageClassName(unsigned sc) {
495 switch (sc) {
496 case spv::StorageClassInput:
497 return "input";
498 case spv::StorageClassOutput:
499 return "output";
500 case spv::StorageClassUniformConstant:
501 return "const uniform";
502 case spv::StorageClassUniform:
503 return "uniform";
504 case spv::StorageClassWorkgroup:
505 return "workgroup local";
506 case spv::StorageClassCrossWorkgroup:
507 return "workgroup global";
508 case spv::StorageClassPrivate:
509 return "private global";
510 case spv::StorageClassFunction:
511 return "function";
512 case spv::StorageClassGeneric:
513 return "generic";
514 case spv::StorageClassAtomicCounter:
515 return "atomic counter";
516 case spv::StorageClassImage:
517 return "image";
518 case spv::StorageClassPushConstant:
519 return "push constant";
520 case spv::StorageClassStorageBuffer:
521 return "storage buffer";
522 default:
523 return "unknown";
524 }
525}
526
527void SHADER_MODULE_STATE::DescribeTypeInner(std::ostringstream &ss, unsigned type) const {
528 auto insn = get_def(type);
529 assert(insn != end());
530
531 switch (insn.opcode()) {
532 case spv::OpTypeBool:
533 ss << "bool";
534 break;
535 case spv::OpTypeInt:
536 ss << (insn.word(3) ? 's' : 'u') << "int" << insn.word(2);
537 break;
538 case spv::OpTypeFloat:
539 ss << "float" << insn.word(2);
540 break;
541 case spv::OpTypeVector:
542 ss << "vec" << insn.word(3) << " of ";
543 DescribeTypeInner(ss, insn.word(2));
544 break;
545 case spv::OpTypeMatrix:
546 ss << "mat" << insn.word(3) << " of ";
547 DescribeTypeInner(ss, insn.word(2));
548 break;
549 case spv::OpTypeArray:
550 ss << "arr[" << GetConstantValueById(insn.word(3)) << "] of ";
551 DescribeTypeInner(ss, insn.word(2));
552 break;
553 case spv::OpTypeRuntimeArray:
554 ss << "runtime arr[] of ";
555 DescribeTypeInner(ss, insn.word(2));
556 break;
557 case spv::OpTypePointer:
558 ss << "ptr to " << StorageClassName(insn.word(2)) << " ";
559 DescribeTypeInner(ss, insn.word(3));
560 break;
561 case spv::OpTypeStruct: {
562 ss << "struct of (";
563 for (unsigned i = 2; i < insn.len(); i++) {
564 DescribeTypeInner(ss, insn.word(i));
565 if (i == insn.len() - 1) {
566 ss << ")";
567 } else {
568 ss << ", ";
569 }
570 }
571 break;
572 }
573 case spv::OpTypeSampler:
574 ss << "sampler";
575 break;
576 case spv::OpTypeSampledImage:
577 ss << "sampler+";
578 DescribeTypeInner(ss, insn.word(2));
579 break;
580 case spv::OpTypeImage:
581 ss << "image(dim=" << insn.word(3) << ", sampled=" << insn.word(7) << ")";
582 break;
583 case spv::OpTypeAccelerationStructureNV:
584 ss << "accelerationStruture";
585 break;
586 default:
587 ss << "oddtype";
588 break;
589 }
590}
591
592std::string SHADER_MODULE_STATE::DescribeType(unsigned type) const {
593 std::ostringstream ss;
594 DescribeTypeInner(ss, type);
595 return ss.str();
596}
597
598const SHADER_MODULE_STATE::EntryPoint *SHADER_MODULE_STATE::FindEntrypointStruct(char const *name,
599 VkShaderStageFlagBits stageBits) const {
600 auto range = entry_points.equal_range(name);
601 for (auto it = range.first; it != range.second; ++it) {
602 if (it->second.stage == stageBits) {
603 return &(it->second);
604 }
605 }
606 return nullptr;
607}
608
609spirv_inst_iter SHADER_MODULE_STATE::FindEntrypoint(char const *name, VkShaderStageFlagBits stageBits) const {
610 auto range = entry_points.equal_range(name);
611 for (auto it = range.first; it != range.second; ++it) {
612 if (it->second.stage == stageBits) {
613 return at(it->second.offset);
614 }
615 }
616 return end();
617}
618
619// Because the following is legal, need the entry point
620// OpEntryPoint GLCompute %main "name_a"
621// OpEntryPoint GLCompute %main "name_b"
622bool SHADER_MODULE_STATE::FindLocalSize(const spirv_inst_iter &entrypoint, uint32_t &local_size_x, uint32_t &local_size_y,
623 uint32_t &local_size_z) const {
624 auto entrypoint_id = entrypoint.word(2);
625 auto it = execution_mode_inst.find(entrypoint_id);
626 if (it != execution_mode_inst.end()) {
627 for (auto insn : it->second) {
628 // Future Note: For now, Vulkan doesn't have a valid mode that can makes use of OpExecutionModeId
629 // In the future if something like LocalSizeId is supported, the <id> will need to be checked also
630 assert(insn.opcode() == spv::OpExecutionMode);
631 if (insn.word(2) == spv::ExecutionModeLocalSize) {
632 local_size_x = insn.word(3);
633 local_size_y = insn.word(4);
634 local_size_z = insn.word(5);
635 return true;
636 }
637 }
638 }
639 return false;
640}
641
642// If the instruction at id is a constant or copy of a constant, returns a valid iterator pointing to that instruction.
643// Otherwise, returns src->end().
644spirv_inst_iter SHADER_MODULE_STATE::GetConstantDef(unsigned id) const {
645 auto value = get_def(id);
646
647 // If id is a copy, see where it was copied from
648 if ((end() != value) && ((value.opcode() == spv::OpCopyObject) || (value.opcode() == spv::OpCopyLogical))) {
649 id = value.word(3);
650 value = get_def(id);
651 }
652
653 if ((end() != value) && (value.opcode() == spv::OpConstant)) {
654 return value;
655 }
656 return end();
657}
658
659// Either returns the constant value described by the instruction at id, or 1
660uint32_t SHADER_MODULE_STATE::GetConstantValueById(unsigned id) const {
661 auto value = GetConstantDef(id);
662
663 if (end() == value) {
664 // TODO: Either ensure that the specialization transform is already performed on a module we're
665 // considering here, OR -- specialize on the fly now.
666 return 1;
667 }
668 return GetConstantValue(value);
669}
670
671// Returns an int32_t corresponding to the spv::Dim of the given resource, when positive, and corresponding to an unknown type, when
672// negative.
673int32_t SHADER_MODULE_STATE::GetShaderResourceDimensionality(const interface_var &resource) const {
674 auto type = get_def(resource.type_id);
675 while (true) {
676 switch (type.opcode()) {
677 case spv::OpTypeSampledImage:
678 type = get_def(type.word(2));
679 break;
680 case spv::OpTypePointer:
681 type = get_def(type.word(3));
682 break;
683 case spv::OpTypeImage:
684 return type.word(3);
685 default:
686 return -1;
687 }
688 }
689}
690
691unsigned SHADER_MODULE_STATE::GetLocationsConsumedByType(unsigned type, bool strip_array_level) const {
692 auto insn = get_def(type);
693 assert(insn != end());
694
695 switch (insn.opcode()) {
696 case spv::OpTypePointer:
697 // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing
698 // pointers around.
699 return GetLocationsConsumedByType(insn.word(3), strip_array_level);
700 case spv::OpTypeArray:
701 if (strip_array_level) {
702 return GetLocationsConsumedByType(insn.word(2), false);
703 } else {
704 return GetConstantValueById(insn.word(3)) * GetLocationsConsumedByType(insn.word(2), false);
705 }
706 case spv::OpTypeMatrix:
707 // Num locations is the dimension * element size
708 return insn.word(3) * GetLocationsConsumedByType(insn.word(2), false);
709 case spv::OpTypeVector: {
710 auto scalar_type = get_def(insn.word(2));
711 auto bit_width =
712 (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32;
713
714 // Locations are 128-bit wide; 3- and 4-component vectors of 64 bit types require two.
715 return (bit_width * insn.word(3) + 127) / 128;
716 }
717 default:
718 // Everything else is just 1.
719 return 1;
720
721 // TODO: extend to handle 64bit scalar types, whose vectors may need multiple locations.
722 }
723}
724
725unsigned SHADER_MODULE_STATE::GetComponentsConsumedByType(unsigned type, bool strip_array_level) const {
726 auto insn = get_def(type);
727 assert(insn != end());
728
729 switch (insn.opcode()) {
730 case spv::OpTypePointer:
731 // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing
732 // pointers around.
733 return GetComponentsConsumedByType(insn.word(3), strip_array_level);
734 case spv::OpTypeStruct: {
735 uint32_t sum = 0;
736 for (uint32_t i = 2; i < insn.len(); i++) { // i=2 to skip word(0) and word(1)=ID of struct
737 sum += GetComponentsConsumedByType(insn.word(i), false);
738 }
739 return sum;
740 }
741 case spv::OpTypeArray:
742 if (strip_array_level) {
743 return GetComponentsConsumedByType(insn.word(2), false);
744 } else {
745 return GetConstantValueById(insn.word(3)) * GetComponentsConsumedByType(insn.word(2), false);
746 }
747 case spv::OpTypeMatrix:
748 // Num locations is the dimension * element size
749 return insn.word(3) * GetComponentsConsumedByType(insn.word(2), false);
750 case spv::OpTypeVector: {
751 auto scalar_type = get_def(insn.word(2));
752 auto bit_width =
753 (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32;
754 // One component is 32-bit
755 return (bit_width * insn.word(3) + 31) / 32;
756 }
757 case spv::OpTypeFloat: {
758 auto bit_width = insn.word(2);
759 return (bit_width + 31) / 32;
760 }
761 case spv::OpTypeInt: {
762 auto bit_width = insn.word(2);
763 return (bit_width + 31) / 32;
764 }
765 case spv::OpConstant:
766 return GetComponentsConsumedByType(insn.word(1), false);
767 default:
768 return 0;
769 }
770}
771
772// characterizes a SPIR-V type appearing in an interface to a FF stage, for comparison to a VkFormat's characterization above.
773// also used for input attachments, as we statically know their format.
774unsigned SHADER_MODULE_STATE::GetFundamentalType(unsigned type) const {
775 auto insn = get_def(type);
776 assert(insn != end());
777
778 switch (insn.opcode()) {
779 case spv::OpTypeInt:
780 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
781 case spv::OpTypeFloat:
782 return FORMAT_TYPE_FLOAT;
783 case spv::OpTypeVector:
784 case spv::OpTypeMatrix:
785 case spv::OpTypeArray:
786 case spv::OpTypeRuntimeArray:
787 case spv::OpTypeImage:
788 return GetFundamentalType(insn.word(2));
789 case spv::OpTypePointer:
790 return GetFundamentalType(insn.word(3));
791
792 default:
793 return 0;
794 }
795}
796
797spirv_inst_iter SHADER_MODULE_STATE::GetStructType(spirv_inst_iter def, bool is_array_of_verts) const {
798 while (true) {
799 if (def.opcode() == spv::OpTypePointer) {
800 def = get_def(def.word(3));
801 } else if (def.opcode() == spv::OpTypeArray && is_array_of_verts) {
802 def = get_def(def.word(2));
803 is_array_of_verts = false;
804 } else if (def.opcode() == spv::OpTypeStruct) {
805 return def;
806 } else {
807 return end();
808 }
809 }
810}
811
812void SHADER_MODULE_STATE::DefineStructMember(const spirv_inst_iter &it, const std::vector<uint32_t> &memberDecorate_offsets,
813 shader_struct_member &data) const {
814 const auto struct_it = GetStructType(it, false);
815 assert(struct_it != end());
816 data.size = 0;
817
818 shader_struct_member data1;
819 uint32_t i = 2;
820 uint32_t local_offset = 0;
821 std::vector<uint32_t> offsets;
822 offsets.resize(struct_it.len() - i);
823
824 // The members of struct in SPRIV_R aren't always sort, so we need to know their order.
825 for (const auto offset : memberDecorate_offsets) {
826 const auto member_decorate = at(offset);
827 if (member_decorate.word(1) != struct_it.word(1)) {
828 continue;
829 }
830
831 offsets[member_decorate.word(2)] = member_decorate.word(4);
832 }
833
834 for (const auto offset : offsets) {
835 local_offset = offset;
836 data1 = {};
837 data1.root = data.root;
838 data1.offset = local_offset;
839 auto def_member = get_def(struct_it.word(i));
840
841 // Array could be multi-dimensional
842 while (def_member.opcode() == spv::OpTypeArray) {
843 const auto len_id = def_member.word(3);
844 const auto def_len = get_def(len_id);
845 data1.array_length_hierarchy.emplace_back(def_len.word(3)); // array length
846 def_member = get_def(def_member.word(2));
847 }
848
849 if (def_member.opcode() == spv::OpTypeStruct) {
850 DefineStructMember(def_member, memberDecorate_offsets, data1);
851 } else if (def_member.opcode() == spv::OpTypePointer) {
852 if (def_member.word(2) == spv::StorageClassPhysicalStorageBuffer) {
853 // If it's a pointer with PhysicalStorageBuffer class, this member is essentially a uint64_t containing an address
854 // that "points to something."
855 data1.size = 8;
856 } else {
857 // If it's OpTypePointer. it means the member is a buffer, the type will be TypePointer, and then struct
858 DefineStructMember(def_member, memberDecorate_offsets, data1);
859 }
860 } else {
861 if (def_member.opcode() == spv::OpTypeMatrix) {
862 data1.array_length_hierarchy.emplace_back(def_member.word(3)); // matrix's columns. matrix's row is vector.
863 def_member = get_def(def_member.word(2));
864 }
865
866 if (def_member.opcode() == spv::OpTypeVector) {
867 data1.array_length_hierarchy.emplace_back(def_member.word(3)); // vector length
868 def_member = get_def(def_member.word(2));
869 }
870
871 // Get scalar type size. The value in SPRV-R is bit. It needs to translate to byte.
872 data1.size = (def_member.word(2) / 8);
873 }
874 const auto array_length_hierarchy_szie = data1.array_length_hierarchy.size();
875 if (array_length_hierarchy_szie > 0) {
876 data1.array_block_size.resize(array_length_hierarchy_szie, 1);
877
878 for (int i2 = static_cast<int>(array_length_hierarchy_szie - 1); i2 > 0; --i2) {
879 data1.array_block_size[i2 - 1] = data1.array_length_hierarchy[i2] * data1.array_block_size[i2];
880 }
881 }
882 data.struct_members.emplace_back(data1);
883 ++i;
884 }
885 uint32_t total_array_length = 1;
886 for (const auto length : data1.array_length_hierarchy) {
887 total_array_length *= length;
888 }
889 data.size = local_offset + data1.size * total_array_length;
890}
891
892static uint32_t UpdateOffset(uint32_t offset, const std::vector<uint32_t> &array_indices, const shader_struct_member &data) {
893 int array_indices_size = static_cast<int>(array_indices.size());
894 if (array_indices_size) {
895 uint32_t array_index = 0;
896 uint32_t i = 0;
897 for (const auto index : array_indices) {
898 array_index += (data.array_block_size[i] * index);
899 ++i;
900 }
901 offset += (array_index * data.size);
902 }
903 return offset;
904}
905
906static void SetUsedBytes(uint32_t offset, const std::vector<uint32_t> &array_indices, const shader_struct_member &data) {
907 int array_indices_size = static_cast<int>(array_indices.size());
908 uint32_t block_memory_size = data.size;
909 for (uint32_t i = static_cast<int>(array_indices_size); i < data.array_length_hierarchy.size(); ++i) {
910 block_memory_size *= data.array_length_hierarchy[i];
911 }
912
913 offset = UpdateOffset(offset, array_indices, data);
914
915 uint32_t end = offset + block_memory_size;
916 auto used_bytes = data.GetUsedbytes();
917 if (used_bytes->size() < end) {
918 used_bytes->resize(end, 0);
919 }
920 std::memset(used_bytes->data() + offset, true, static_cast<std::size_t>(block_memory_size));
921}
922
923void SHADER_MODULE_STATE::RunUsedArray(uint32_t offset, std::vector<uint32_t> array_indices, uint32_t access_chain_word_index,
924 spirv_inst_iter &access_chain_it, const shader_struct_member &data) const {
925 if (access_chain_word_index < access_chain_it.len()) {
926 if (data.array_length_hierarchy.size() > array_indices.size()) {
927 auto def_it = get_def(access_chain_it.word(access_chain_word_index));
928 ++access_chain_word_index;
929
930 if (def_it != end() && def_it.opcode() == spv::OpConstant) {
931 array_indices.emplace_back(def_it.word(3));
932 RunUsedArray(offset, array_indices, access_chain_word_index, access_chain_it, data);
933 } else {
934 // If it is a variable, set the all array is used.
935 if (access_chain_word_index < access_chain_it.len()) {
936 uint32_t array_length = data.array_length_hierarchy[array_indices.size()];
937 for (uint32_t i = 0; i < array_length; ++i) {
938 auto array_indices2 = array_indices;
939 array_indices2.emplace_back(i);
940 RunUsedArray(offset, array_indices2, access_chain_word_index, access_chain_it, data);
941 }
942 } else {
943 SetUsedBytes(offset, array_indices, data);
944 }
945 }
946 } else {
947 offset = UpdateOffset(offset, array_indices, data);
948 RunUsedStruct(offset, access_chain_word_index, access_chain_it, data);
949 }
950 } else {
951 SetUsedBytes(offset, array_indices, data);
952 }
953}
954
955void SHADER_MODULE_STATE::RunUsedStruct(uint32_t offset, uint32_t access_chain_word_index, spirv_inst_iter &access_chain_it,
956 const shader_struct_member &data) const {
957 std::vector<uint32_t> array_indices_emptry;
958
959 if (access_chain_word_index < access_chain_it.len()) {
960 auto strcut_member_index = GetConstantValueById(access_chain_it.word(access_chain_word_index));
961 ++access_chain_word_index;
962
963 auto data1 = data.struct_members[strcut_member_index];
964 RunUsedArray(offset + data1.offset, array_indices_emptry, access_chain_word_index, access_chain_it, data1);
965 }
966}
967
968void SHADER_MODULE_STATE::SetUsedStructMember(const uint32_t variable_id, const std::vector<function_set> &function_set_list,
969 const shader_struct_member &data) const {
970 for (const auto &func_set : function_set_list) {
971 auto range = func_set.op_lists.equal_range(spv::OpAccessChain);
972 for (auto it = range.first; it != range.second; ++it) {
973 auto access_chain = at(it->second);
974 if (access_chain.word(3) == variable_id) {
975 RunUsedStruct(0, 4, access_chain, data);
976 }
977 }
978 }
979}
980
981void SHADER_MODULE_STATE::SetPushConstantUsedInShader() {
982 for (auto &entrypoint : entry_points) {
983 auto range = entrypoint.second.decorate_list.equal_range(spv::OpVariable);
984 for (auto it = range.first; it != range.second; ++it) {
985 const auto def_insn = at(it->second);
986
987 if (def_insn.word(3) == spv::StorageClassPushConstant) {
988 spirv_inst_iter type = get_def(def_insn.word(1));
989 const auto range2 = entrypoint.second.decorate_list.equal_range(spv::OpMemberDecorate);
990 std::vector<uint32_t> offsets;
991
992 for (auto it2 = range2.first; it2 != range2.second; ++it2) {
993 auto member_decorate = at(it2->second);
994 if (member_decorate.len() == 5 && member_decorate.word(3) == spv::DecorationOffset) {
995 offsets.emplace_back(member_decorate.offset());
996 }
997 }
998 entrypoint.second.push_constant_used_in_shader.root = &entrypoint.second.push_constant_used_in_shader;
999 DefineStructMember(type, offsets, entrypoint.second.push_constant_used_in_shader);
1000 SetUsedStructMember(def_insn.word(2), entrypoint.second.function_set_list,
1001 entrypoint.second.push_constant_used_in_shader);
1002 }
1003 }
1004 }
1005}
1006
1007uint32_t SHADER_MODULE_STATE::DescriptorTypeToReqs(uint32_t type_id) const {
1008 auto type = get_def(type_id);
1009
1010 while (true) {
1011 switch (type.opcode()) {
1012 case spv::OpTypeArray:
1013 case spv::OpTypeRuntimeArray:
1014 case spv::OpTypeSampledImage:
1015 type = get_def(type.word(2));
1016 break;
1017 case spv::OpTypePointer:
1018 type = get_def(type.word(3));
1019 break;
1020 case spv::OpTypeImage: {
1021 auto dim = type.word(3);
1022 auto arrayed = type.word(5);
1023 auto msaa = type.word(6);
1024
1025 uint32_t bits = 0;
1026 switch (GetFundamentalType(type.word(2))) {
1027 case FORMAT_TYPE_FLOAT:
1028 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
1029 break;
1030 case FORMAT_TYPE_UINT:
1031 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
1032 break;
1033 case FORMAT_TYPE_SINT:
1034 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
1035 break;
1036 default:
1037 break;
1038 }
1039
1040 switch (dim) {
1041 case spv::Dim1D:
1042 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_1D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_1D;
1043 return bits;
1044 case spv::Dim2D:
1045 bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE;
1046 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_2D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_2D;
1047 return bits;
1048 case spv::Dim3D:
1049 bits |= DESCRIPTOR_REQ_VIEW_TYPE_3D;
1050 return bits;
1051 case spv::DimCube:
1052 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_CUBE_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_CUBE;
1053 return bits;
1054 case spv::DimSubpassData:
1055 bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE;
1056 return bits;
1057 default: // buffer, etc.
1058 return bits;
1059 }
1060 }
1061 default:
1062 return 0;
1063 }
1064 }
1065}
1066
1067// For some built-in analysis we need to know if the variable decorated with as the built-in was actually written to.
1068// This function examines instructions in the static call tree for a write to this variable.
1069bool SHADER_MODULE_STATE::IsBuiltInWritten(spirv_inst_iter builtin_instr, spirv_inst_iter entrypoint) const {
1070 auto type = builtin_instr.opcode();
1071 uint32_t target_id = builtin_instr.word(1);
1072 bool init_complete = false;
1073
1074 if (type == spv::OpMemberDecorate) {
1075 // Built-in is part of a structure -- examine instructions up to first function body to get initial IDs
1076 auto insn = entrypoint;
1077 while (!init_complete && (insn.opcode() != spv::OpFunction)) {
1078 switch (insn.opcode()) {
1079 case spv::OpTypePointer:
1080 if ((insn.word(3) == target_id) && (insn.word(2) == spv::StorageClassOutput)) {
1081 target_id = insn.word(1);
1082 }
1083 break;
1084 case spv::OpVariable:
1085 if (insn.word(1) == target_id) {
1086 target_id = insn.word(2);
1087 init_complete = true;
1088 }
1089 break;
1090 }
1091 insn++;
1092 }
1093 }
1094
1095 if (!init_complete && (type == spv::OpMemberDecorate)) return false;
1096
1097 bool found_write = false;
1098 layer_data::unordered_set<uint32_t> worklist;
1099 worklist.insert(entrypoint.word(2));
1100
1101 // Follow instructions in call graph looking for writes to target
1102 while (!worklist.empty() && !found_write) {
1103 auto id_iter = worklist.begin();
1104 auto id = *id_iter;
1105 worklist.erase(id_iter);
1106
1107 auto insn = get_def(id);
1108 if (insn == end()) {
1109 continue;
1110 }
1111
1112 if (insn.opcode() == spv::OpFunction) {
1113 // Scan body of function looking for other function calls or items in our ID chain
1114 while (++insn, insn.opcode() != spv::OpFunctionEnd) {
1115 switch (insn.opcode()) {
1116 case spv::OpAccessChain:
1117 if (insn.word(3) == target_id) {
1118 if (type == spv::OpMemberDecorate) {
1119 auto value = GetConstantValueById(insn.word(4));
1120 if (value == builtin_instr.word(2)) {
1121 target_id = insn.word(2);
1122 }
1123 } else {
1124 target_id = insn.word(2);
1125 }
1126 }
1127 break;
1128 case spv::OpStore:
1129 if (insn.word(1) == target_id) {
1130 found_write = true;
1131 }
1132 break;
1133 case spv::OpFunctionCall:
1134 worklist.insert(insn.word(3));
1135 break;
1136 }
1137 }
1138 }
1139 }
1140 return found_write;
1141}
1142
1143// Used by the collection functions to help aid in state tracking
1144struct shader_module_used_operators {
1145 bool updated;
1146 std::vector<unsigned> imagwrite_members;
1147 std::vector<unsigned> atomic_members;
1148 std::vector<unsigned> store_members;
1149 std::vector<unsigned> atomic_store_members;
1150 std::vector<unsigned> sampler_implicitLod_dref_proj_members; // sampler Load id
1151 std::vector<unsigned> sampler_bias_offset_members; // sampler Load id
1152 std::vector<std::pair<unsigned, unsigned>> sampledImage_members; // <image,sampler> Load id
1153 layer_data::unordered_map<unsigned, unsigned> load_members;
1154 layer_data::unordered_map<unsigned, std::pair<unsigned, unsigned>> accesschain_members;
1155 layer_data::unordered_map<unsigned, unsigned> image_texel_pointer_members;
1156
1157 shader_module_used_operators() : updated(false) {}
1158
1159 bool CheckImageOperandsBiasOffset(uint32_t type) {
1160 return type & (spv::ImageOperandsBiasMask | spv::ImageOperandsConstOffsetMask | spv::ImageOperandsOffsetMask |
1161 spv::ImageOperandsConstOffsetsMask)
1162 ? true
1163 : false;
1164 }
1165
1166 void update(SHADER_MODULE_STATE const *module) {
1167 if (updated) return;
1168 updated = true;
1169
1170 for (auto insn : *module) {
1171 switch (insn.opcode()) {
1172 case spv::OpImageSampleImplicitLod:
1173 case spv::OpImageSampleProjImplicitLod:
1174 case spv::OpImageSampleProjExplicitLod:
1175 case spv::OpImageSparseSampleImplicitLod:
1176 case spv::OpImageSparseSampleProjImplicitLod:
1177 case spv::OpImageSparseSampleProjExplicitLod: {
1178 sampler_implicitLod_dref_proj_members.emplace_back(insn.word(3)); // Load id
1179 // ImageOperands in index: 5
1180 if (insn.len() > 5 && CheckImageOperandsBiasOffset(insn.word(5))) {
1181 sampler_bias_offset_members.emplace_back(insn.word(3));
1182 }
1183 break;
1184 }
1185 case spv::OpImageSampleDrefImplicitLod:
1186 case spv::OpImageSampleDrefExplicitLod:
1187 case spv::OpImageSampleProjDrefImplicitLod:
1188 case spv::OpImageSampleProjDrefExplicitLod:
1189 case spv::OpImageSparseSampleDrefImplicitLod:
1190 case spv::OpImageSparseSampleDrefExplicitLod:
1191 case spv::OpImageSparseSampleProjDrefImplicitLod:
1192 case spv::OpImageSparseSampleProjDrefExplicitLod: {
1193 sampler_implicitLod_dref_proj_members.emplace_back(insn.word(3)); // Load id
1194 // ImageOperands in index: 6
1195 if (insn.len() > 6 && CheckImageOperandsBiasOffset(insn.word(6))) {
1196 sampler_bias_offset_members.emplace_back(insn.word(3));
1197 }
1198 break;
1199 }
1200 case spv::OpImageSampleExplicitLod:
1201 case spv::OpImageSparseSampleExplicitLod: {
1202 // ImageOperands in index: 5
1203 if (insn.len() > 5 && CheckImageOperandsBiasOffset(insn.word(5))) {
1204 sampler_bias_offset_members.emplace_back(insn.word(3));
1205 }
1206 break;
1207 }
1208 case spv::OpStore: {
1209 store_members.emplace_back(insn.word(1)); // object id or AccessChain id
1210 break;
1211 }
1212 case spv::OpImageWrite: {
1213 imagwrite_members.emplace_back(insn.word(1)); // Load id
1214 break;
1215 }
1216 case spv::OpSampledImage: {
1217 // 3: image load id, 4: sampler load id
1218 sampledImage_members.emplace_back(std::pair<unsigned, unsigned>(insn.word(3), insn.word(4)));
1219 break;
1220 }
1221 case spv::OpLoad: {
1222 // 2: Load id, 3: object id or AccessChain id
1223 load_members.emplace(insn.word(2), insn.word(3));
1224 break;
1225 }
1226 case spv::OpAccessChain: {
1227 if (insn.len() == 4) {
1228 // If it is for struct, the length is only 4.
1229 // 2: AccessChain id, 3: object id
1230 accesschain_members.emplace(insn.word(2), std::pair<unsigned, unsigned>(insn.word(3), 0));
1231 } else {
1232 // 2: AccessChain id, 3: object id, 4: object id of array index
1233 accesschain_members.emplace(insn.word(2), std::pair<unsigned, unsigned>(insn.word(3), insn.word(4)));
1234 }
1235 break;
1236 }
1237 case spv::OpImageTexelPointer: {
1238 // 2: ImageTexelPointer id, 3: object id
1239 image_texel_pointer_members.emplace(insn.word(2), insn.word(3));
1240 break;
1241 }
1242 default: {
1243 if (AtomicOperation(insn.opcode())) {
1244 if (insn.opcode() == spv::OpAtomicStore) {
1245 atomic_store_members.emplace_back(insn.word(1)); // ImageTexelPointer id
1246 } else {
1247 atomic_members.emplace_back(insn.word(3)); // ImageTexelPointer id
1248 }
1249 }
1250 break;
1251 }
1252 }
1253 }
1254 }
1255};
1256
1257static bool CheckObjectIDFromOpLoad(uint32_t object_id, const std::vector<unsigned> &operator_members,
1258 const layer_data::unordered_map<unsigned, unsigned> &load_members,
1259 const layer_data::unordered_map<unsigned, std::pair<unsigned, unsigned>> &accesschain_members) {
1260 for (auto load_id : operator_members) {
1261 if (object_id == load_id) return true;
1262 auto load_it = load_members.find(load_id);
1263 if (load_it == load_members.end()) {
1264 continue;
1265 }
1266 if (load_it->second == object_id) {
1267 return true;
1268 }
1269
1270 auto accesschain_it = accesschain_members.find(load_it->second);
1271 if (accesschain_it == accesschain_members.end()) {
1272 continue;
1273 }
1274 if (accesschain_it->second.first == object_id) {
1275 return true;
1276 }
1277 }
1278 return false;
1279}
1280
1281// Takes a OpVariable and looks at the the descriptor type it uses. This will find things such as if the variable is writable, image
1282// atomic operation, matching images to samplers, etc
1283void SHADER_MODULE_STATE::IsSpecificDescriptorType(const spirv_inst_iter &id_it, bool is_storage_buffer, bool is_check_writable,
1284 interface_var &out_interface_var,
1285 shader_module_used_operators &used_operators) const {
1286 uint32_t type_id = id_it.word(1);
1287 unsigned int id = id_it.word(2);
1288
1289 auto type = get_def(type_id);
1290
1291 // Strip off any array or ptrs. Where we remove array levels, adjust the descriptor count for each dimension.
1292 while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray ||
1293 type.opcode() == spv::OpTypeSampledImage) {
1294 if (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypeRuntimeArray ||
1295 type.opcode() == spv::OpTypeSampledImage) {
1296 type = get_def(type.word(2)); // Element type
1297 } else {
1298 type = get_def(type.word(3)); // Pointer type
1299 }
1300 }
1301 switch (type.opcode()) {
1302 case spv::OpTypeImage: {
1303 auto dim = type.word(3);
1304 if (dim != spv::DimSubpassData) {
1305 used_operators.update(this);
1306
1307 if (CheckObjectIDFromOpLoad(id, used_operators.imagwrite_members, used_operators.load_members,
1308 used_operators.accesschain_members)) {
1309 out_interface_var.is_writable = true;
1310 }
1311 if (CheckObjectIDFromOpLoad(id, used_operators.sampler_implicitLod_dref_proj_members, used_operators.load_members,
1312 used_operators.accesschain_members)) {
1313 out_interface_var.is_sampler_implicitLod_dref_proj = true;
1314 }
1315 if (CheckObjectIDFromOpLoad(id, used_operators.sampler_bias_offset_members, used_operators.load_members,
1316 used_operators.accesschain_members)) {
1317 out_interface_var.is_sampler_bias_offset = true;
1318 }
1319 if (CheckObjectIDFromOpLoad(id, used_operators.atomic_members, used_operators.image_texel_pointer_members,
1320 used_operators.accesschain_members) ||
1321 CheckObjectIDFromOpLoad(id, used_operators.atomic_store_members, used_operators.image_texel_pointer_members,
1322 used_operators.accesschain_members)) {
1323 out_interface_var.is_atomic_operation = true;
1324 }
1325
1326 for (auto &itp_id : used_operators.sampledImage_members) {
1327 // Find if image id match.
1328 uint32_t image_index = 0;
1329 auto load_it = used_operators.load_members.find(itp_id.first);
1330 if (load_it == used_operators.load_members.end()) {
1331 continue;
1332 } else {
1333 if (load_it->second != id) {
1334 auto accesschain_it = used_operators.accesschain_members.find(load_it->second);
1335 if (accesschain_it == used_operators.accesschain_members.end()) {
1336 continue;
1337 } else {
1338 if (accesschain_it->second.first != id) {
1339 continue;
1340 }
1341
1342 const auto const_itr = GetConstantDef(accesschain_it->second.second);
1343 if (const_itr == end()) {
1344 // access chain index not a constant, skip.
1345 break;
1346 }
1347 image_index = GetConstantValue(const_itr);
1348 }
1349 }
1350 }
1351 // Find sampler's set binding.
1352 load_it = used_operators.load_members.find(itp_id.second);
1353 if (load_it == used_operators.load_members.end()) {
1354 continue;
1355 } else {
1356 uint32_t sampler_id = load_it->second;
1357 uint32_t sampler_index = 0;
1358 auto accesschain_it = used_operators.accesschain_members.find(load_it->second);
1359
1360 if (accesschain_it != used_operators.accesschain_members.end()) {
1361 const auto const_itr = GetConstantDef(accesschain_it->second.second);
1362 if (const_itr == end()) {
1363 // access chain index representing sampler index is not a constant, skip.
1364 break;
1365 }
1366 sampler_id = const_itr.offset();
1367 sampler_index = GetConstantValue(const_itr);
1368 }
1369 auto sampler_dec = get_decorations(sampler_id);
1370 if (image_index >= out_interface_var.samplers_used_by_image.size()) {
1371 out_interface_var.samplers_used_by_image.resize(image_index + 1);
1372 }
1373 out_interface_var.samplers_used_by_image[image_index].emplace(
1374 SamplerUsedByImage{descriptor_slot_t{sampler_dec.descriptor_set, sampler_dec.binding}, sampler_index});
1375 }
1376 }
1377 }
1378 return;
1379 }
1380
1381 case spv::OpTypeStruct: {
1382 layer_data::unordered_set<unsigned> nonwritable_members;
1383 if (get_decorations(type.word(1)).flags & decoration_set::buffer_block_bit) is_storage_buffer = true;
1384 for (auto insn : member_decoration_inst) {
1385 if (insn.word(1) == type.word(1) && insn.word(3) == spv::DecorationNonWritable) {
1386 nonwritable_members.insert(insn.word(2));
1387 }
1388 }
1389
1390 // A buffer is writable if it's either flavor of storage buffer, and has any member not decorated
1391 // as nonwritable.
1392 if (is_storage_buffer && nonwritable_members.size() != type.len() - 2) {
1393 used_operators.update(this);
1394
1395 for (auto oid : used_operators.store_members) {
1396 if (id == oid) {
1397 out_interface_var.is_writable = true;
1398 return;
1399 }
1400 auto accesschain_it = used_operators.accesschain_members.find(oid);
1401 if (accesschain_it == used_operators.accesschain_members.end()) {
1402 continue;
1403 }
1404 if (accesschain_it->second.first == id) {
1405 out_interface_var.is_writable = true;
1406 return;
1407 }
1408 }
1409 if (CheckObjectIDFromOpLoad(id, used_operators.atomic_store_members, used_operators.image_texel_pointer_members,
1410 used_operators.accesschain_members)) {
1411 out_interface_var.is_writable = true;
1412 return;
1413 }
1414 }
1415 }
1416 }
1417}
1418
1419std::vector<std::pair<descriptor_slot_t, interface_var>> SHADER_MODULE_STATE::CollectInterfaceByDescriptorSlot(
1420 layer_data::unordered_set<uint32_t> const &accessible_ids, bool *has_writable_descriptor, bool *has_atomic_descriptor) const {
1421 std::vector<std::pair<descriptor_slot_t, interface_var>> out;
1422 shader_module_used_operators operators;
1423
1424 for (auto id : accessible_ids) {
1425 auto insn = get_def(id);
1426 assert(insn != end());
1427
1428 if (insn.opcode() == spv::OpVariable &&
1429 (insn.word(3) == spv::StorageClassUniform || insn.word(3) == spv::StorageClassUniformConstant ||
1430 insn.word(3) == spv::StorageClassStorageBuffer)) {
1431 auto d = get_decorations(insn.word(2));
1432 unsigned set = d.descriptor_set;
1433 unsigned binding = d.binding;
1434
1435 interface_var v = {};
1436 v.id = insn.word(2);
1437 v.type_id = insn.word(1);
1438
1439 IsSpecificDescriptorType(insn, insn.word(3) == spv::StorageClassStorageBuffer,
1440 !(d.flags & decoration_set::nonwritable_bit), v, operators);
1441 if (v.is_writable) *has_writable_descriptor = true;
1442 if (v.is_atomic_operation) *has_atomic_descriptor = true;
1443 out.emplace_back(std::make_pair(set, binding), v);
1444 }
1445 }
1446
1447 return out;
1448}
1449
1450layer_data::unordered_set<uint32_t> SHADER_MODULE_STATE::CollectWritableOutputLocationinFS(
1451 const VkPipelineShaderStageCreateInfo &stage_info) const {
1452 layer_data::unordered_set<uint32_t> location_list;
1453 if (stage_info.stage != VK_SHADER_STAGE_FRAGMENT_BIT) return location_list;
1454 const auto entrypoint = FindEntrypoint(stage_info.pName, stage_info.stage);
1455 const auto outputs = CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false);
1456 layer_data::unordered_set<unsigned> store_members;
1457 layer_data::unordered_map<unsigned, unsigned> accesschain_members;
1458
1459 for (auto insn : *this) {
1460 switch (insn.opcode()) {
1461 case spv::OpStore:
1462 case spv::OpAtomicStore: {
1463 store_members.insert(insn.word(1)); // object id or AccessChain id
1464 break;
1465 }
1466 case spv::OpAccessChain: {
1467 // 2: AccessChain id, 3: object id
1468 if (insn.word(3)) accesschain_members.emplace(insn.word(2), insn.word(3));
1469 break;
1470 }
1471 default:
1472 break;
1473 }
1474 }
1475 if (store_members.empty()) {
1476 return location_list;
1477 }
1478 for (auto output : outputs) {
1479 auto store_it = store_members.find(output.second.id);
1480 if (store_it != store_members.end()) {
1481 location_list.insert(output.first.first);
1482 store_members.erase(store_it);
1483 continue;
1484 }
1485 store_it = store_members.begin();
1486 while (store_it != store_members.end()) {
1487 auto accesschain_it = accesschain_members.find(*store_it);
1488 if (accesschain_it == accesschain_members.end()) {
1489 ++store_it;
1490 continue;
1491 }
1492 if (accesschain_it->second == output.second.id) {
1493 location_list.insert(output.first.first);
1494 store_members.erase(store_it);
1495 accesschain_members.erase(accesschain_it);
1496 break;
1497 }
1498 ++store_it;
1499 }
1500 }
1501 return location_list;
1502}
1503
1504bool SHADER_MODULE_STATE::CollectInterfaceBlockMembers(std::map<location_t, interface_var> *out, bool is_array_of_verts,
1505 uint32_t id, uint32_t type_id, bool is_patch, int /*first_location*/) const {
1506 // Walk down the type_id presented, trying to determine whether it's actually an interface block.
1507 auto type = GetStructType(get_def(type_id), is_array_of_verts && !is_patch);
1508 if (type == end() || !(get_decorations(type.word(1)).flags & decoration_set::block_bit)) {
1509 // This isn't an interface block.
1510 return false;
1511 }
1512
1513 layer_data::unordered_map<unsigned, unsigned> member_components;
1514 layer_data::unordered_map<unsigned, unsigned> member_relaxed_precision;
1515 layer_data::unordered_map<unsigned, unsigned> member_patch;
1516
1517 // Walk all the OpMemberDecorate for type's result id -- first pass, collect components.
1518 for (auto insn : member_decoration_inst) {
1519 if (insn.word(1) == type.word(1)) {
1520 unsigned member_index = insn.word(2);
1521
1522 if (insn.word(3) == spv::DecorationComponent) {
1523 unsigned component = insn.word(4);
1524 member_components[member_index] = component;
1525 }
1526
1527 if (insn.word(3) == spv::DecorationRelaxedPrecision) {
1528 member_relaxed_precision[member_index] = 1;
1529 }
1530
1531 if (insn.word(3) == spv::DecorationPatch) {
1532 member_patch[member_index] = 1;
1533 }
1534 }
1535 }
1536
1537 // TODO: correctly handle location assignment from outside
1538
1539 // Second pass -- produce the output, from Location decorations
1540 for (auto insn : member_decoration_inst) {
1541 if (insn.word(1) == type.word(1)) {
1542 unsigned member_index = insn.word(2);
1543 unsigned member_type_id = type.word(2 + member_index);
1544
1545 if (insn.word(3) == spv::DecorationLocation) {
1546 unsigned location = insn.word(4);
1547 unsigned num_locations = GetLocationsConsumedByType(member_type_id, false);
1548 auto component_it = member_components.find(member_index);
1549 unsigned component = component_it == member_components.end() ? 0 : component_it->second;
1550 bool is_relaxed_precision = member_relaxed_precision.find(member_index) != member_relaxed_precision.end();
1551 bool member_is_patch = is_patch || member_patch.count(member_index) > 0;
1552
1553 for (unsigned int offset = 0; offset < num_locations; offset++) {
1554 interface_var v = {};
1555 v.id = id;
1556 // TODO: member index in interface_var too?
1557 v.type_id = member_type_id;
1558 v.offset = offset;
1559 v.is_patch = member_is_patch;
1560 v.is_block_member = true;
1561 v.is_relaxed_precision = is_relaxed_precision;
1562 (*out)[std::make_pair(location + offset, component)] = v;
1563 }
1564 }
1565 }
1566 }
1567
1568 return true;
1569}
1570
1571std::map<location_t, interface_var> SHADER_MODULE_STATE::CollectInterfaceByLocation(spirv_inst_iter entrypoint,
1572 spv::StorageClass sinterface,
1573 bool is_array_of_verts) const {
1574 // TODO: handle index=1 dual source outputs from FS -- two vars will have the same location, and we DON'T want to clobber.
1575
1576 std::map<location_t, interface_var> out;
1577
1578 for (uint32_t iid : FindEntrypointInterfaces(entrypoint)) {
1579 auto insn = get_def(iid);
1580 assert(insn != end());
1581 assert(insn.opcode() == spv::OpVariable);
1582
1583 if (insn.word(3) == static_cast<uint32_t>(sinterface)) {
1584 auto d = get_decorations(iid);
1585 unsigned id = insn.word(2);
1586 unsigned type = insn.word(1);
1587
1588 int location = d.location;
1589 int builtin = d.builtin;
1590 unsigned component = d.component;
1591 bool is_patch = (d.flags & decoration_set::patch_bit) != 0;
1592 bool is_relaxed_precision = (d.flags & decoration_set::relaxed_precision_bit) != 0;
1593
1594 if (builtin != -1) {
1595 continue;
1596 } else if (!CollectInterfaceBlockMembers(&out, is_array_of_verts, id, type, is_patch, location)) {
1597 // A user-defined interface variable, with a location. Where a variable occupied multiple locations, emit
1598 // one result for each.
1599 unsigned num_locations = GetLocationsConsumedByType(type, is_array_of_verts && !is_patch);
1600 for (unsigned int offset = 0; offset < num_locations; offset++) {
1601 interface_var v = {};
1602 v.id = id;
1603 v.type_id = type;
1604 v.offset = offset;
1605 v.is_patch = is_patch;
1606 v.is_relaxed_precision = is_relaxed_precision;
1607 out[std::make_pair(location + offset, component)] = v;
1608 }
1609 }
1610 }
1611 }
1612
1613 return out;
1614}
1615
1616std::vector<uint32_t> SHADER_MODULE_STATE::CollectBuiltinBlockMembers(spirv_inst_iter entrypoint, uint32_t storageClass) const {
1617 std::vector<uint32_t> variables;
1618 std::vector<uint32_t> builtin_struct_members;
1619 std::vector<uint32_t> builtin_decorations;
1620
1621 for (auto insn : member_decoration_inst) {
1622 if (insn.word(3) == spv::DecorationBuiltIn) {
1623 builtin_struct_members.push_back(insn.word(1));
1624 }
1625 }
1626 for (auto insn : decoration_inst) {
1627 switch (insn.word(2)) {
1628 case spv::DecorationBlock: {
1629 uint32_t block_id = insn.word(1);
1630 for (auto builtin_block_id : builtin_struct_members) {
1631 // Check if one of the members of the block are built-in -> the block is built-in
1632 if (block_id == builtin_block_id) {
1633 builtin_decorations.push_back(block_id);
1634 break;
1635 }
1636 }
1637 break;
1638 }
1639 case spv::DecorationBuiltIn:
1640 builtin_decorations.push_back(insn.word(1));
1641 break;
1642 default:
1643 break;
1644 }
1645 }
1646
1647 // Find all interface variables belonging to the entrypoint and matching the storage class
1648 for (uint32_t id : FindEntrypointInterfaces(entrypoint)) {
1649 auto def = get_def(id);
1650 assert(def != end());
1651 assert(def.opcode() == spv::OpVariable);
1652
1653 if (def.word(3) == storageClass) variables.push_back(def.word(1));
1654 }
1655
1656 // Find all members belonging to the builtin block selected
1657 std::vector<uint32_t> builtin_block_members;
1658 for (auto &var : variables) {
1659 auto def = get_def(get_def(var).word(3));
1660
1661 // It could be an array of IO blocks. The element type should be the struct defining the block contents
1662 if (def.opcode() == spv::OpTypeArray) def = get_def(def.word(2));
1663
1664 // Now find all members belonging to the struct defining the IO block
1665 if (def.opcode() == spv::OpTypeStruct) {
1666 for (auto builtin_id : builtin_decorations) {
1667 if (builtin_id == def.word(1)) {
1668 for (int i = 2; i < static_cast<int>(def.len()); i++) {
1669 builtin_block_members.push_back(spv::BuiltInMax); // Start with undefined builtin for each struct member.
1670 }
1671 // These shouldn't be left after replacing.
1672 for (auto insn : member_decoration_inst) {
1673 if (insn.word(1) == builtin_id && insn.word(3) == spv::DecorationBuiltIn) {
1674 auto struct_index = insn.word(2);
1675 assert(struct_index < builtin_block_members.size());
1676 builtin_block_members[struct_index] = insn.word(4);
1677 }
1678 }
1679 }
1680 }
1681 }
1682 }
1683
1684 return builtin_block_members;
1685}
1686
1687std::vector<std::pair<uint32_t, interface_var>> SHADER_MODULE_STATE::CollectInterfaceByInputAttachmentIndex(
1688 layer_data::unordered_set<uint32_t> const &accessible_ids) const {
1689 std::vector<std::pair<uint32_t, interface_var>> out;
1690
1691 for (auto insn : decoration_inst) {
1692 if (insn.word(2) == spv::DecorationInputAttachmentIndex) {
1693 auto attachment_index = insn.word(3);
1694 auto id = insn.word(1);
1695
1696 if (accessible_ids.count(id)) {
1697 auto def = get_def(id);
1698 assert(def != end());
1699 if (def.opcode() == spv::OpVariable && def.word(3) == spv::StorageClassUniformConstant) {
1700 auto num_locations = GetLocationsConsumedByType(def.word(1), false);
1701 for (unsigned int offset = 0; offset < num_locations; offset++) {
1702 interface_var v = {};
1703 v.id = id;
1704 v.type_id = def.word(1);
1705 v.offset = offset;
1706 out.emplace_back(attachment_index + offset, v);
1707 }
1708 }
1709 }
1710 }
1711 }
1712
1713 return out;
1714}
1715
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +03001716spirv_inst_iter SHADER_MODULE_STATE::GetImageFormatInst(uint32_t id) const
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001717{
1718 do {
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001719 auto def = get_def(id);
Lionel Landwerlin5f2065a2021-07-23 11:51:28 +03001720 if (def == end())
1721 return def;
1722
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001723 switch (def.opcode()) {
1724 case spv::OpLoad:
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001725 case spv::OpAccessChain:
1726 case spv::OpCompositeConstruct:
1727 case spv::OpVariable: {
1728 id = def.word(1);
1729 break;
1730 }
1731
1732 case spv::OpTypeArray:
1733 case spv::OpTypeRuntimeArray:
1734 id = def.word(2);
1735 break;
1736
1737 case spv::OpTypePointer:
1738 id = def.word(3);
1739 break;
1740
1741 case spv::OpTypeImage:
1742 return def;
1743
1744 default:
1745 return end();
1746 }
1747 } while (true);
1748}
1749
sfricke-samsung962cad92021-04-13 00:46:29 -07001750// Assumes itr points to an OpConstant instruction
1751uint32_t GetConstantValue(const spirv_inst_iter &itr) { return itr.word(3); }
1752
1753std::vector<uint32_t> FindEntrypointInterfaces(const spirv_inst_iter &entrypoint) {
1754 assert(entrypoint.opcode() == spv::OpEntryPoint);
1755
1756 std::vector<uint32_t> interfaces;
1757 // Find the end of the entrypoint's name string. additional zero bytes follow the actual null terminator, to fill out the
1758 // rest of the word - so we only need to look at the last byte in the word to determine which word contains the terminator.
1759 uint32_t word = 3;
1760 while (entrypoint.word(word) & 0xff000000u) {
1761 ++word;
1762 }
1763 ++word;
1764
1765 for (; word < entrypoint.len(); word++) interfaces.push_back(entrypoint.word(word));
1766
1767 return interfaces;
1768}
1769
1770bool AtomicOperation(uint32_t opcode) {
1771 switch (opcode) {
1772 case spv::OpAtomicLoad:
1773 case spv::OpAtomicStore:
1774 case spv::OpAtomicExchange:
1775 case spv::OpAtomicCompareExchange:
1776 case spv::OpAtomicCompareExchangeWeak:
1777 case spv::OpAtomicIIncrement:
1778 case spv::OpAtomicIDecrement:
1779 case spv::OpAtomicIAdd:
1780 case spv::OpAtomicISub:
1781 case spv::OpAtomicSMin:
1782 case spv::OpAtomicUMin:
1783 case spv::OpAtomicSMax:
1784 case spv::OpAtomicUMax:
1785 case spv::OpAtomicAnd:
1786 case spv::OpAtomicOr:
1787 case spv::OpAtomicXor:
1788 case spv::OpAtomicFAddEXT:
1789 return true;
1790 default:
1791 return false;
1792 }
1793 return false;
1794}
1795
1796// Only includes valid group operations used in Vulkan (for now thats only subgroup ops) and any non supported operation will be
1797// covered with VUID 01090
1798bool GroupOperation(uint32_t opcode) {
1799 switch (opcode) {
1800 case spv::OpGroupNonUniformElect:
1801 case spv::OpGroupNonUniformAll:
1802 case spv::OpGroupNonUniformAny:
1803 case spv::OpGroupNonUniformAllEqual:
1804 case spv::OpGroupNonUniformBroadcast:
1805 case spv::OpGroupNonUniformBroadcastFirst:
1806 case spv::OpGroupNonUniformBallot:
1807 case spv::OpGroupNonUniformInverseBallot:
1808 case spv::OpGroupNonUniformBallotBitExtract:
1809 case spv::OpGroupNonUniformBallotBitCount:
1810 case spv::OpGroupNonUniformBallotFindLSB:
1811 case spv::OpGroupNonUniformBallotFindMSB:
1812 case spv::OpGroupNonUniformShuffle:
1813 case spv::OpGroupNonUniformShuffleXor:
1814 case spv::OpGroupNonUniformShuffleUp:
1815 case spv::OpGroupNonUniformShuffleDown:
1816 case spv::OpGroupNonUniformIAdd:
1817 case spv::OpGroupNonUniformFAdd:
1818 case spv::OpGroupNonUniformIMul:
1819 case spv::OpGroupNonUniformFMul:
1820 case spv::OpGroupNonUniformSMin:
1821 case spv::OpGroupNonUniformUMin:
1822 case spv::OpGroupNonUniformFMin:
1823 case spv::OpGroupNonUniformSMax:
1824 case spv::OpGroupNonUniformUMax:
1825 case spv::OpGroupNonUniformFMax:
1826 case spv::OpGroupNonUniformBitwiseAnd:
1827 case spv::OpGroupNonUniformBitwiseOr:
1828 case spv::OpGroupNonUniformBitwiseXor:
1829 case spv::OpGroupNonUniformLogicalAnd:
1830 case spv::OpGroupNonUniformLogicalOr:
1831 case spv::OpGroupNonUniformLogicalXor:
1832 case spv::OpGroupNonUniformQuadBroadcast:
1833 case spv::OpGroupNonUniformQuadSwap:
1834 case spv::OpGroupNonUniformPartitionNV:
1835 return true;
1836 default:
1837 return false;
1838 }
1839 return false;
Jeremy Gebben5d970742021-05-31 16:04:14 -06001840}