blob: 6b5bbab8e0a0531c153d320a1568f7d6addf52a4 [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
432 default:
433 // We don't care about any other defs for now.
434 break;
435 }
436 }
437}
438
439std::vector<uint32_t> SHADER_MODULE_STATE::PreprocessShaderBinary(uint32_t *src_binary, size_t binary_size, spv_target_env env) {
440 std::vector<uint32_t> src(src_binary, src_binary + binary_size / sizeof(uint32_t));
441
442 // Check if there are any group decoration instructions, and flatten them if found.
443 bool has_group_decoration = false;
444 bool done = false;
445
446 // Walk through the first part of the SPIR-V module, looking for group decoration and specialization constant instructions.
447 // Skip the header (5 words).
448 auto itr = spirv_inst_iter(src.begin(), src.begin() + 5);
449 auto itrend = spirv_inst_iter(src.begin(), src.end());
450 while (itr != itrend && !done) {
451 spv::Op opcode = (spv::Op)itr.opcode();
452 switch (opcode) {
453 case spv::OpDecorationGroup:
454 case spv::OpGroupDecorate:
455 case spv::OpGroupMemberDecorate:
456 has_group_decoration = true;
457 break;
458 case spv::OpSpecConstantTrue:
459 case spv::OpSpecConstantFalse:
460 case spv::OpSpecConstant:
461 case spv::OpSpecConstantComposite:
462 case spv::OpSpecConstantOp:
463 has_specialization_constants = true;
464 break;
465 case spv::OpFunction:
466 // An OpFunction indicates there are no more decorations
467 done = true;
468 break;
469 default:
470 break;
471 }
472 itr++;
473 }
474
475 if (has_group_decoration) {
476 spvtools::Optimizer optimizer(env);
477 optimizer.RegisterPass(spvtools::CreateFlattenDecorationPass());
478 std::vector<uint32_t> optimized_binary;
479 // Run optimizer to flatten decorations only, set skip_validation so as to not re-run validator
480 auto result =
481 optimizer.Run(src_binary, binary_size / sizeof(uint32_t), &optimized_binary, spvtools::ValidatorOptions(), true);
482 if (result) {
483 return optimized_binary;
484 }
485 }
486 // Return the original module.
487 return src;
488}
489
490static char const *StorageClassName(unsigned sc) {
491 switch (sc) {
492 case spv::StorageClassInput:
493 return "input";
494 case spv::StorageClassOutput:
495 return "output";
496 case spv::StorageClassUniformConstant:
497 return "const uniform";
498 case spv::StorageClassUniform:
499 return "uniform";
500 case spv::StorageClassWorkgroup:
501 return "workgroup local";
502 case spv::StorageClassCrossWorkgroup:
503 return "workgroup global";
504 case spv::StorageClassPrivate:
505 return "private global";
506 case spv::StorageClassFunction:
507 return "function";
508 case spv::StorageClassGeneric:
509 return "generic";
510 case spv::StorageClassAtomicCounter:
511 return "atomic counter";
512 case spv::StorageClassImage:
513 return "image";
514 case spv::StorageClassPushConstant:
515 return "push constant";
516 case spv::StorageClassStorageBuffer:
517 return "storage buffer";
518 default:
519 return "unknown";
520 }
521}
522
523void SHADER_MODULE_STATE::DescribeTypeInner(std::ostringstream &ss, unsigned type) const {
524 auto insn = get_def(type);
525 assert(insn != end());
526
527 switch (insn.opcode()) {
528 case spv::OpTypeBool:
529 ss << "bool";
530 break;
531 case spv::OpTypeInt:
532 ss << (insn.word(3) ? 's' : 'u') << "int" << insn.word(2);
533 break;
534 case spv::OpTypeFloat:
535 ss << "float" << insn.word(2);
536 break;
537 case spv::OpTypeVector:
538 ss << "vec" << insn.word(3) << " of ";
539 DescribeTypeInner(ss, insn.word(2));
540 break;
541 case spv::OpTypeMatrix:
542 ss << "mat" << insn.word(3) << " of ";
543 DescribeTypeInner(ss, insn.word(2));
544 break;
545 case spv::OpTypeArray:
546 ss << "arr[" << GetConstantValueById(insn.word(3)) << "] of ";
547 DescribeTypeInner(ss, insn.word(2));
548 break;
549 case spv::OpTypeRuntimeArray:
550 ss << "runtime arr[] of ";
551 DescribeTypeInner(ss, insn.word(2));
552 break;
553 case spv::OpTypePointer:
554 ss << "ptr to " << StorageClassName(insn.word(2)) << " ";
555 DescribeTypeInner(ss, insn.word(3));
556 break;
557 case spv::OpTypeStruct: {
558 ss << "struct of (";
559 for (unsigned i = 2; i < insn.len(); i++) {
560 DescribeTypeInner(ss, insn.word(i));
561 if (i == insn.len() - 1) {
562 ss << ")";
563 } else {
564 ss << ", ";
565 }
566 }
567 break;
568 }
569 case spv::OpTypeSampler:
570 ss << "sampler";
571 break;
572 case spv::OpTypeSampledImage:
573 ss << "sampler+";
574 DescribeTypeInner(ss, insn.word(2));
575 break;
576 case spv::OpTypeImage:
577 ss << "image(dim=" << insn.word(3) << ", sampled=" << insn.word(7) << ")";
578 break;
579 case spv::OpTypeAccelerationStructureNV:
580 ss << "accelerationStruture";
581 break;
582 default:
583 ss << "oddtype";
584 break;
585 }
586}
587
588std::string SHADER_MODULE_STATE::DescribeType(unsigned type) const {
589 std::ostringstream ss;
590 DescribeTypeInner(ss, type);
591 return ss.str();
592}
593
594const SHADER_MODULE_STATE::EntryPoint *SHADER_MODULE_STATE::FindEntrypointStruct(char const *name,
595 VkShaderStageFlagBits stageBits) const {
596 auto range = entry_points.equal_range(name);
597 for (auto it = range.first; it != range.second; ++it) {
598 if (it->second.stage == stageBits) {
599 return &(it->second);
600 }
601 }
602 return nullptr;
603}
604
605spirv_inst_iter SHADER_MODULE_STATE::FindEntrypoint(char const *name, VkShaderStageFlagBits stageBits) const {
606 auto range = entry_points.equal_range(name);
607 for (auto it = range.first; it != range.second; ++it) {
608 if (it->second.stage == stageBits) {
609 return at(it->second.offset);
610 }
611 }
612 return end();
613}
614
615// Because the following is legal, need the entry point
616// OpEntryPoint GLCompute %main "name_a"
617// OpEntryPoint GLCompute %main "name_b"
618bool SHADER_MODULE_STATE::FindLocalSize(const spirv_inst_iter &entrypoint, uint32_t &local_size_x, uint32_t &local_size_y,
619 uint32_t &local_size_z) const {
620 auto entrypoint_id = entrypoint.word(2);
621 auto it = execution_mode_inst.find(entrypoint_id);
622 if (it != execution_mode_inst.end()) {
623 for (auto insn : it->second) {
624 // Future Note: For now, Vulkan doesn't have a valid mode that can makes use of OpExecutionModeId
625 // In the future if something like LocalSizeId is supported, the <id> will need to be checked also
626 assert(insn.opcode() == spv::OpExecutionMode);
627 if (insn.word(2) == spv::ExecutionModeLocalSize) {
628 local_size_x = insn.word(3);
629 local_size_y = insn.word(4);
630 local_size_z = insn.word(5);
631 return true;
632 }
633 }
634 }
635 return false;
636}
637
638// If the instruction at id is a constant or copy of a constant, returns a valid iterator pointing to that instruction.
639// Otherwise, returns src->end().
640spirv_inst_iter SHADER_MODULE_STATE::GetConstantDef(unsigned id) const {
641 auto value = get_def(id);
642
643 // If id is a copy, see where it was copied from
644 if ((end() != value) && ((value.opcode() == spv::OpCopyObject) || (value.opcode() == spv::OpCopyLogical))) {
645 id = value.word(3);
646 value = get_def(id);
647 }
648
649 if ((end() != value) && (value.opcode() == spv::OpConstant)) {
650 return value;
651 }
652 return end();
653}
654
655// Either returns the constant value described by the instruction at id, or 1
656uint32_t SHADER_MODULE_STATE::GetConstantValueById(unsigned id) const {
657 auto value = GetConstantDef(id);
658
659 if (end() == value) {
660 // TODO: Either ensure that the specialization transform is already performed on a module we're
661 // considering here, OR -- specialize on the fly now.
662 return 1;
663 }
664 return GetConstantValue(value);
665}
666
667// Returns an int32_t corresponding to the spv::Dim of the given resource, when positive, and corresponding to an unknown type, when
668// negative.
669int32_t SHADER_MODULE_STATE::GetShaderResourceDimensionality(const interface_var &resource) const {
670 auto type = get_def(resource.type_id);
671 while (true) {
672 switch (type.opcode()) {
673 case spv::OpTypeSampledImage:
674 type = get_def(type.word(2));
675 break;
676 case spv::OpTypePointer:
677 type = get_def(type.word(3));
678 break;
679 case spv::OpTypeImage:
680 return type.word(3);
681 default:
682 return -1;
683 }
684 }
685}
686
687unsigned SHADER_MODULE_STATE::GetLocationsConsumedByType(unsigned type, bool strip_array_level) const {
688 auto insn = get_def(type);
689 assert(insn != end());
690
691 switch (insn.opcode()) {
692 case spv::OpTypePointer:
693 // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing
694 // pointers around.
695 return GetLocationsConsumedByType(insn.word(3), strip_array_level);
696 case spv::OpTypeArray:
697 if (strip_array_level) {
698 return GetLocationsConsumedByType(insn.word(2), false);
699 } else {
700 return GetConstantValueById(insn.word(3)) * GetLocationsConsumedByType(insn.word(2), false);
701 }
702 case spv::OpTypeMatrix:
703 // Num locations is the dimension * element size
704 return insn.word(3) * GetLocationsConsumedByType(insn.word(2), false);
705 case spv::OpTypeVector: {
706 auto scalar_type = get_def(insn.word(2));
707 auto bit_width =
708 (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32;
709
710 // Locations are 128-bit wide; 3- and 4-component vectors of 64 bit types require two.
711 return (bit_width * insn.word(3) + 127) / 128;
712 }
713 default:
714 // Everything else is just 1.
715 return 1;
716
717 // TODO: extend to handle 64bit scalar types, whose vectors may need multiple locations.
718 }
719}
720
721unsigned SHADER_MODULE_STATE::GetComponentsConsumedByType(unsigned type, bool strip_array_level) const {
722 auto insn = get_def(type);
723 assert(insn != end());
724
725 switch (insn.opcode()) {
726 case spv::OpTypePointer:
727 // See through the ptr -- this is only ever at the toplevel for graphics shaders we're never actually passing
728 // pointers around.
729 return GetComponentsConsumedByType(insn.word(3), strip_array_level);
730 case spv::OpTypeStruct: {
731 uint32_t sum = 0;
732 for (uint32_t i = 2; i < insn.len(); i++) { // i=2 to skip word(0) and word(1)=ID of struct
733 sum += GetComponentsConsumedByType(insn.word(i), false);
734 }
735 return sum;
736 }
737 case spv::OpTypeArray:
738 if (strip_array_level) {
739 return GetComponentsConsumedByType(insn.word(2), false);
740 } else {
741 return GetConstantValueById(insn.word(3)) * GetComponentsConsumedByType(insn.word(2), false);
742 }
743 case spv::OpTypeMatrix:
744 // Num locations is the dimension * element size
745 return insn.word(3) * GetComponentsConsumedByType(insn.word(2), false);
746 case spv::OpTypeVector: {
747 auto scalar_type = get_def(insn.word(2));
748 auto bit_width =
749 (scalar_type.opcode() == spv::OpTypeInt || scalar_type.opcode() == spv::OpTypeFloat) ? scalar_type.word(2) : 32;
750 // One component is 32-bit
751 return (bit_width * insn.word(3) + 31) / 32;
752 }
753 case spv::OpTypeFloat: {
754 auto bit_width = insn.word(2);
755 return (bit_width + 31) / 32;
756 }
757 case spv::OpTypeInt: {
758 auto bit_width = insn.word(2);
759 return (bit_width + 31) / 32;
760 }
761 case spv::OpConstant:
762 return GetComponentsConsumedByType(insn.word(1), false);
763 default:
764 return 0;
765 }
766}
767
768// characterizes a SPIR-V type appearing in an interface to a FF stage, for comparison to a VkFormat's characterization above.
769// also used for input attachments, as we statically know their format.
770unsigned SHADER_MODULE_STATE::GetFundamentalType(unsigned type) const {
771 auto insn = get_def(type);
772 assert(insn != end());
773
774 switch (insn.opcode()) {
775 case spv::OpTypeInt:
776 return insn.word(3) ? FORMAT_TYPE_SINT : FORMAT_TYPE_UINT;
777 case spv::OpTypeFloat:
778 return FORMAT_TYPE_FLOAT;
779 case spv::OpTypeVector:
780 case spv::OpTypeMatrix:
781 case spv::OpTypeArray:
782 case spv::OpTypeRuntimeArray:
783 case spv::OpTypeImage:
784 return GetFundamentalType(insn.word(2));
785 case spv::OpTypePointer:
786 return GetFundamentalType(insn.word(3));
787
788 default:
789 return 0;
790 }
791}
792
793spirv_inst_iter SHADER_MODULE_STATE::GetStructType(spirv_inst_iter def, bool is_array_of_verts) const {
794 while (true) {
795 if (def.opcode() == spv::OpTypePointer) {
796 def = get_def(def.word(3));
797 } else if (def.opcode() == spv::OpTypeArray && is_array_of_verts) {
798 def = get_def(def.word(2));
799 is_array_of_verts = false;
800 } else if (def.opcode() == spv::OpTypeStruct) {
801 return def;
802 } else {
803 return end();
804 }
805 }
806}
807
808void SHADER_MODULE_STATE::DefineStructMember(const spirv_inst_iter &it, const std::vector<uint32_t> &memberDecorate_offsets,
809 shader_struct_member &data) const {
810 const auto struct_it = GetStructType(it, false);
811 assert(struct_it != end());
812 data.size = 0;
813
814 shader_struct_member data1;
815 uint32_t i = 2;
816 uint32_t local_offset = 0;
817 std::vector<uint32_t> offsets;
818 offsets.resize(struct_it.len() - i);
819
820 // The members of struct in SPRIV_R aren't always sort, so we need to know their order.
821 for (const auto offset : memberDecorate_offsets) {
822 const auto member_decorate = at(offset);
823 if (member_decorate.word(1) != struct_it.word(1)) {
824 continue;
825 }
826
827 offsets[member_decorate.word(2)] = member_decorate.word(4);
828 }
829
830 for (const auto offset : offsets) {
831 local_offset = offset;
832 data1 = {};
833 data1.root = data.root;
834 data1.offset = local_offset;
835 auto def_member = get_def(struct_it.word(i));
836
837 // Array could be multi-dimensional
838 while (def_member.opcode() == spv::OpTypeArray) {
839 const auto len_id = def_member.word(3);
840 const auto def_len = get_def(len_id);
841 data1.array_length_hierarchy.emplace_back(def_len.word(3)); // array length
842 def_member = get_def(def_member.word(2));
843 }
844
845 if (def_member.opcode() == spv::OpTypeStruct) {
846 DefineStructMember(def_member, memberDecorate_offsets, data1);
847 } else if (def_member.opcode() == spv::OpTypePointer) {
848 if (def_member.word(2) == spv::StorageClassPhysicalStorageBuffer) {
849 // If it's a pointer with PhysicalStorageBuffer class, this member is essentially a uint64_t containing an address
850 // that "points to something."
851 data1.size = 8;
852 } else {
853 // If it's OpTypePointer. it means the member is a buffer, the type will be TypePointer, and then struct
854 DefineStructMember(def_member, memberDecorate_offsets, data1);
855 }
856 } else {
857 if (def_member.opcode() == spv::OpTypeMatrix) {
858 data1.array_length_hierarchy.emplace_back(def_member.word(3)); // matrix's columns. matrix's row is vector.
859 def_member = get_def(def_member.word(2));
860 }
861
862 if (def_member.opcode() == spv::OpTypeVector) {
863 data1.array_length_hierarchy.emplace_back(def_member.word(3)); // vector length
864 def_member = get_def(def_member.word(2));
865 }
866
867 // Get scalar type size. The value in SPRV-R is bit. It needs to translate to byte.
868 data1.size = (def_member.word(2) / 8);
869 }
870 const auto array_length_hierarchy_szie = data1.array_length_hierarchy.size();
871 if (array_length_hierarchy_szie > 0) {
872 data1.array_block_size.resize(array_length_hierarchy_szie, 1);
873
874 for (int i2 = static_cast<int>(array_length_hierarchy_szie - 1); i2 > 0; --i2) {
875 data1.array_block_size[i2 - 1] = data1.array_length_hierarchy[i2] * data1.array_block_size[i2];
876 }
877 }
878 data.struct_members.emplace_back(data1);
879 ++i;
880 }
881 uint32_t total_array_length = 1;
882 for (const auto length : data1.array_length_hierarchy) {
883 total_array_length *= length;
884 }
885 data.size = local_offset + data1.size * total_array_length;
886}
887
888static uint32_t UpdateOffset(uint32_t offset, const std::vector<uint32_t> &array_indices, const shader_struct_member &data) {
889 int array_indices_size = static_cast<int>(array_indices.size());
890 if (array_indices_size) {
891 uint32_t array_index = 0;
892 uint32_t i = 0;
893 for (const auto index : array_indices) {
894 array_index += (data.array_block_size[i] * index);
895 ++i;
896 }
897 offset += (array_index * data.size);
898 }
899 return offset;
900}
901
902static void SetUsedBytes(uint32_t offset, const std::vector<uint32_t> &array_indices, const shader_struct_member &data) {
903 int array_indices_size = static_cast<int>(array_indices.size());
904 uint32_t block_memory_size = data.size;
905 for (uint32_t i = static_cast<int>(array_indices_size); i < data.array_length_hierarchy.size(); ++i) {
906 block_memory_size *= data.array_length_hierarchy[i];
907 }
908
909 offset = UpdateOffset(offset, array_indices, data);
910
911 uint32_t end = offset + block_memory_size;
912 auto used_bytes = data.GetUsedbytes();
913 if (used_bytes->size() < end) {
914 used_bytes->resize(end, 0);
915 }
916 std::memset(used_bytes->data() + offset, true, static_cast<std::size_t>(block_memory_size));
917}
918
919void SHADER_MODULE_STATE::RunUsedArray(uint32_t offset, std::vector<uint32_t> array_indices, uint32_t access_chain_word_index,
920 spirv_inst_iter &access_chain_it, const shader_struct_member &data) const {
921 if (access_chain_word_index < access_chain_it.len()) {
922 if (data.array_length_hierarchy.size() > array_indices.size()) {
923 auto def_it = get_def(access_chain_it.word(access_chain_word_index));
924 ++access_chain_word_index;
925
926 if (def_it != end() && def_it.opcode() == spv::OpConstant) {
927 array_indices.emplace_back(def_it.word(3));
928 RunUsedArray(offset, array_indices, access_chain_word_index, access_chain_it, data);
929 } else {
930 // If it is a variable, set the all array is used.
931 if (access_chain_word_index < access_chain_it.len()) {
932 uint32_t array_length = data.array_length_hierarchy[array_indices.size()];
933 for (uint32_t i = 0; i < array_length; ++i) {
934 auto array_indices2 = array_indices;
935 array_indices2.emplace_back(i);
936 RunUsedArray(offset, array_indices2, access_chain_word_index, access_chain_it, data);
937 }
938 } else {
939 SetUsedBytes(offset, array_indices, data);
940 }
941 }
942 } else {
943 offset = UpdateOffset(offset, array_indices, data);
944 RunUsedStruct(offset, access_chain_word_index, access_chain_it, data);
945 }
946 } else {
947 SetUsedBytes(offset, array_indices, data);
948 }
949}
950
951void SHADER_MODULE_STATE::RunUsedStruct(uint32_t offset, uint32_t access_chain_word_index, spirv_inst_iter &access_chain_it,
952 const shader_struct_member &data) const {
953 std::vector<uint32_t> array_indices_emptry;
954
955 if (access_chain_word_index < access_chain_it.len()) {
956 auto strcut_member_index = GetConstantValueById(access_chain_it.word(access_chain_word_index));
957 ++access_chain_word_index;
958
959 auto data1 = data.struct_members[strcut_member_index];
960 RunUsedArray(offset + data1.offset, array_indices_emptry, access_chain_word_index, access_chain_it, data1);
961 }
962}
963
964void SHADER_MODULE_STATE::SetUsedStructMember(const uint32_t variable_id, const std::vector<function_set> &function_set_list,
965 const shader_struct_member &data) const {
966 for (const auto &func_set : function_set_list) {
967 auto range = func_set.op_lists.equal_range(spv::OpAccessChain);
968 for (auto it = range.first; it != range.second; ++it) {
969 auto access_chain = at(it->second);
970 if (access_chain.word(3) == variable_id) {
971 RunUsedStruct(0, 4, access_chain, data);
972 }
973 }
974 }
975}
976
977void SHADER_MODULE_STATE::SetPushConstantUsedInShader() {
978 for (auto &entrypoint : entry_points) {
979 auto range = entrypoint.second.decorate_list.equal_range(spv::OpVariable);
980 for (auto it = range.first; it != range.second; ++it) {
981 const auto def_insn = at(it->second);
982
983 if (def_insn.word(3) == spv::StorageClassPushConstant) {
984 spirv_inst_iter type = get_def(def_insn.word(1));
985 const auto range2 = entrypoint.second.decorate_list.equal_range(spv::OpMemberDecorate);
986 std::vector<uint32_t> offsets;
987
988 for (auto it2 = range2.first; it2 != range2.second; ++it2) {
989 auto member_decorate = at(it2->second);
990 if (member_decorate.len() == 5 && member_decorate.word(3) == spv::DecorationOffset) {
991 offsets.emplace_back(member_decorate.offset());
992 }
993 }
994 entrypoint.second.push_constant_used_in_shader.root = &entrypoint.second.push_constant_used_in_shader;
995 DefineStructMember(type, offsets, entrypoint.second.push_constant_used_in_shader);
996 SetUsedStructMember(def_insn.word(2), entrypoint.second.function_set_list,
997 entrypoint.second.push_constant_used_in_shader);
998 }
999 }
1000 }
1001}
1002
1003uint32_t SHADER_MODULE_STATE::DescriptorTypeToReqs(uint32_t type_id) const {
1004 auto type = get_def(type_id);
1005
1006 while (true) {
1007 switch (type.opcode()) {
1008 case spv::OpTypeArray:
1009 case spv::OpTypeRuntimeArray:
1010 case spv::OpTypeSampledImage:
1011 type = get_def(type.word(2));
1012 break;
1013 case spv::OpTypePointer:
1014 type = get_def(type.word(3));
1015 break;
1016 case spv::OpTypeImage: {
1017 auto dim = type.word(3);
1018 auto arrayed = type.word(5);
1019 auto msaa = type.word(6);
1020
1021 uint32_t bits = 0;
1022 switch (GetFundamentalType(type.word(2))) {
1023 case FORMAT_TYPE_FLOAT:
1024 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_FLOAT;
1025 break;
1026 case FORMAT_TYPE_UINT:
1027 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_UINT;
1028 break;
1029 case FORMAT_TYPE_SINT:
1030 bits = DESCRIPTOR_REQ_COMPONENT_TYPE_SINT;
1031 break;
1032 default:
1033 break;
1034 }
1035
1036 switch (dim) {
1037 case spv::Dim1D:
1038 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_1D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_1D;
1039 return bits;
1040 case spv::Dim2D:
1041 bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE;
1042 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_2D_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_2D;
1043 return bits;
1044 case spv::Dim3D:
1045 bits |= DESCRIPTOR_REQ_VIEW_TYPE_3D;
1046 return bits;
1047 case spv::DimCube:
1048 bits |= arrayed ? DESCRIPTOR_REQ_VIEW_TYPE_CUBE_ARRAY : DESCRIPTOR_REQ_VIEW_TYPE_CUBE;
1049 return bits;
1050 case spv::DimSubpassData:
1051 bits |= msaa ? DESCRIPTOR_REQ_MULTI_SAMPLE : DESCRIPTOR_REQ_SINGLE_SAMPLE;
1052 return bits;
1053 default: // buffer, etc.
1054 return bits;
1055 }
1056 }
1057 default:
1058 return 0;
1059 }
1060 }
1061}
1062
1063// For some built-in analysis we need to know if the variable decorated with as the built-in was actually written to.
1064// This function examines instructions in the static call tree for a write to this variable.
1065bool SHADER_MODULE_STATE::IsBuiltInWritten(spirv_inst_iter builtin_instr, spirv_inst_iter entrypoint) const {
1066 auto type = builtin_instr.opcode();
1067 uint32_t target_id = builtin_instr.word(1);
1068 bool init_complete = false;
1069
1070 if (type == spv::OpMemberDecorate) {
1071 // Built-in is part of a structure -- examine instructions up to first function body to get initial IDs
1072 auto insn = entrypoint;
1073 while (!init_complete && (insn.opcode() != spv::OpFunction)) {
1074 switch (insn.opcode()) {
1075 case spv::OpTypePointer:
1076 if ((insn.word(3) == target_id) && (insn.word(2) == spv::StorageClassOutput)) {
1077 target_id = insn.word(1);
1078 }
1079 break;
1080 case spv::OpVariable:
1081 if (insn.word(1) == target_id) {
1082 target_id = insn.word(2);
1083 init_complete = true;
1084 }
1085 break;
1086 }
1087 insn++;
1088 }
1089 }
1090
1091 if (!init_complete && (type == spv::OpMemberDecorate)) return false;
1092
1093 bool found_write = false;
1094 layer_data::unordered_set<uint32_t> worklist;
1095 worklist.insert(entrypoint.word(2));
1096
1097 // Follow instructions in call graph looking for writes to target
1098 while (!worklist.empty() && !found_write) {
1099 auto id_iter = worklist.begin();
1100 auto id = *id_iter;
1101 worklist.erase(id_iter);
1102
1103 auto insn = get_def(id);
1104 if (insn == end()) {
1105 continue;
1106 }
1107
1108 if (insn.opcode() == spv::OpFunction) {
1109 // Scan body of function looking for other function calls or items in our ID chain
1110 while (++insn, insn.opcode() != spv::OpFunctionEnd) {
1111 switch (insn.opcode()) {
1112 case spv::OpAccessChain:
1113 if (insn.word(3) == target_id) {
1114 if (type == spv::OpMemberDecorate) {
1115 auto value = GetConstantValueById(insn.word(4));
1116 if (value == builtin_instr.word(2)) {
1117 target_id = insn.word(2);
1118 }
1119 } else {
1120 target_id = insn.word(2);
1121 }
1122 }
1123 break;
1124 case spv::OpStore:
1125 if (insn.word(1) == target_id) {
1126 found_write = true;
1127 }
1128 break;
1129 case spv::OpFunctionCall:
1130 worklist.insert(insn.word(3));
1131 break;
1132 }
1133 }
1134 }
1135 }
1136 return found_write;
1137}
1138
1139// Used by the collection functions to help aid in state tracking
1140struct shader_module_used_operators {
1141 bool updated;
1142 std::vector<unsigned> imagwrite_members;
1143 std::vector<unsigned> atomic_members;
1144 std::vector<unsigned> store_members;
1145 std::vector<unsigned> atomic_store_members;
1146 std::vector<unsigned> sampler_implicitLod_dref_proj_members; // sampler Load id
1147 std::vector<unsigned> sampler_bias_offset_members; // sampler Load id
1148 std::vector<std::pair<unsigned, unsigned>> sampledImage_members; // <image,sampler> Load id
1149 layer_data::unordered_map<unsigned, unsigned> load_members;
1150 layer_data::unordered_map<unsigned, std::pair<unsigned, unsigned>> accesschain_members;
1151 layer_data::unordered_map<unsigned, unsigned> image_texel_pointer_members;
1152
1153 shader_module_used_operators() : updated(false) {}
1154
1155 bool CheckImageOperandsBiasOffset(uint32_t type) {
1156 return type & (spv::ImageOperandsBiasMask | spv::ImageOperandsConstOffsetMask | spv::ImageOperandsOffsetMask |
1157 spv::ImageOperandsConstOffsetsMask)
1158 ? true
1159 : false;
1160 }
1161
1162 void update(SHADER_MODULE_STATE const *module) {
1163 if (updated) return;
1164 updated = true;
1165
1166 for (auto insn : *module) {
1167 switch (insn.opcode()) {
1168 case spv::OpImageSampleImplicitLod:
1169 case spv::OpImageSampleProjImplicitLod:
1170 case spv::OpImageSampleProjExplicitLod:
1171 case spv::OpImageSparseSampleImplicitLod:
1172 case spv::OpImageSparseSampleProjImplicitLod:
1173 case spv::OpImageSparseSampleProjExplicitLod: {
1174 sampler_implicitLod_dref_proj_members.emplace_back(insn.word(3)); // Load id
1175 // ImageOperands in index: 5
1176 if (insn.len() > 5 && CheckImageOperandsBiasOffset(insn.word(5))) {
1177 sampler_bias_offset_members.emplace_back(insn.word(3));
1178 }
1179 break;
1180 }
1181 case spv::OpImageSampleDrefImplicitLod:
1182 case spv::OpImageSampleDrefExplicitLod:
1183 case spv::OpImageSampleProjDrefImplicitLod:
1184 case spv::OpImageSampleProjDrefExplicitLod:
1185 case spv::OpImageSparseSampleDrefImplicitLod:
1186 case spv::OpImageSparseSampleDrefExplicitLod:
1187 case spv::OpImageSparseSampleProjDrefImplicitLod:
1188 case spv::OpImageSparseSampleProjDrefExplicitLod: {
1189 sampler_implicitLod_dref_proj_members.emplace_back(insn.word(3)); // Load id
1190 // ImageOperands in index: 6
1191 if (insn.len() > 6 && CheckImageOperandsBiasOffset(insn.word(6))) {
1192 sampler_bias_offset_members.emplace_back(insn.word(3));
1193 }
1194 break;
1195 }
1196 case spv::OpImageSampleExplicitLod:
1197 case spv::OpImageSparseSampleExplicitLod: {
1198 // ImageOperands in index: 5
1199 if (insn.len() > 5 && CheckImageOperandsBiasOffset(insn.word(5))) {
1200 sampler_bias_offset_members.emplace_back(insn.word(3));
1201 }
1202 break;
1203 }
1204 case spv::OpStore: {
1205 store_members.emplace_back(insn.word(1)); // object id or AccessChain id
1206 break;
1207 }
1208 case spv::OpImageWrite: {
1209 imagwrite_members.emplace_back(insn.word(1)); // Load id
1210 break;
1211 }
1212 case spv::OpSampledImage: {
1213 // 3: image load id, 4: sampler load id
1214 sampledImage_members.emplace_back(std::pair<unsigned, unsigned>(insn.word(3), insn.word(4)));
1215 break;
1216 }
1217 case spv::OpLoad: {
1218 // 2: Load id, 3: object id or AccessChain id
1219 load_members.emplace(insn.word(2), insn.word(3));
1220 break;
1221 }
1222 case spv::OpAccessChain: {
1223 if (insn.len() == 4) {
1224 // If it is for struct, the length is only 4.
1225 // 2: AccessChain id, 3: object id
1226 accesschain_members.emplace(insn.word(2), std::pair<unsigned, unsigned>(insn.word(3), 0));
1227 } else {
1228 // 2: AccessChain id, 3: object id, 4: object id of array index
1229 accesschain_members.emplace(insn.word(2), std::pair<unsigned, unsigned>(insn.word(3), insn.word(4)));
1230 }
1231 break;
1232 }
1233 case spv::OpImageTexelPointer: {
1234 // 2: ImageTexelPointer id, 3: object id
1235 image_texel_pointer_members.emplace(insn.word(2), insn.word(3));
1236 break;
1237 }
1238 default: {
1239 if (AtomicOperation(insn.opcode())) {
1240 if (insn.opcode() == spv::OpAtomicStore) {
1241 atomic_store_members.emplace_back(insn.word(1)); // ImageTexelPointer id
1242 } else {
1243 atomic_members.emplace_back(insn.word(3)); // ImageTexelPointer id
1244 }
1245 }
1246 break;
1247 }
1248 }
1249 }
1250 }
1251};
1252
1253static bool CheckObjectIDFromOpLoad(uint32_t object_id, const std::vector<unsigned> &operator_members,
1254 const layer_data::unordered_map<unsigned, unsigned> &load_members,
1255 const layer_data::unordered_map<unsigned, std::pair<unsigned, unsigned>> &accesschain_members) {
1256 for (auto load_id : operator_members) {
1257 if (object_id == load_id) return true;
1258 auto load_it = load_members.find(load_id);
1259 if (load_it == load_members.end()) {
1260 continue;
1261 }
1262 if (load_it->second == object_id) {
1263 return true;
1264 }
1265
1266 auto accesschain_it = accesschain_members.find(load_it->second);
1267 if (accesschain_it == accesschain_members.end()) {
1268 continue;
1269 }
1270 if (accesschain_it->second.first == object_id) {
1271 return true;
1272 }
1273 }
1274 return false;
1275}
1276
1277// Takes a OpVariable and looks at the the descriptor type it uses. This will find things such as if the variable is writable, image
1278// atomic operation, matching images to samplers, etc
1279void SHADER_MODULE_STATE::IsSpecificDescriptorType(const spirv_inst_iter &id_it, bool is_storage_buffer, bool is_check_writable,
1280 interface_var &out_interface_var,
1281 shader_module_used_operators &used_operators) const {
1282 uint32_t type_id = id_it.word(1);
1283 unsigned int id = id_it.word(2);
1284
1285 auto type = get_def(type_id);
1286
1287 // Strip off any array or ptrs. Where we remove array levels, adjust the descriptor count for each dimension.
1288 while (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypePointer || type.opcode() == spv::OpTypeRuntimeArray ||
1289 type.opcode() == spv::OpTypeSampledImage) {
1290 if (type.opcode() == spv::OpTypeArray || type.opcode() == spv::OpTypeRuntimeArray ||
1291 type.opcode() == spv::OpTypeSampledImage) {
1292 type = get_def(type.word(2)); // Element type
1293 } else {
1294 type = get_def(type.word(3)); // Pointer type
1295 }
1296 }
1297 switch (type.opcode()) {
1298 case spv::OpTypeImage: {
1299 auto dim = type.word(3);
1300 if (dim != spv::DimSubpassData) {
1301 used_operators.update(this);
1302
1303 if (CheckObjectIDFromOpLoad(id, used_operators.imagwrite_members, used_operators.load_members,
1304 used_operators.accesschain_members)) {
1305 out_interface_var.is_writable = true;
1306 }
1307 if (CheckObjectIDFromOpLoad(id, used_operators.sampler_implicitLod_dref_proj_members, used_operators.load_members,
1308 used_operators.accesschain_members)) {
1309 out_interface_var.is_sampler_implicitLod_dref_proj = true;
1310 }
1311 if (CheckObjectIDFromOpLoad(id, used_operators.sampler_bias_offset_members, used_operators.load_members,
1312 used_operators.accesschain_members)) {
1313 out_interface_var.is_sampler_bias_offset = true;
1314 }
1315 if (CheckObjectIDFromOpLoad(id, used_operators.atomic_members, used_operators.image_texel_pointer_members,
1316 used_operators.accesschain_members) ||
1317 CheckObjectIDFromOpLoad(id, used_operators.atomic_store_members, used_operators.image_texel_pointer_members,
1318 used_operators.accesschain_members)) {
1319 out_interface_var.is_atomic_operation = true;
1320 }
1321
1322 for (auto &itp_id : used_operators.sampledImage_members) {
1323 // Find if image id match.
1324 uint32_t image_index = 0;
1325 auto load_it = used_operators.load_members.find(itp_id.first);
1326 if (load_it == used_operators.load_members.end()) {
1327 continue;
1328 } else {
1329 if (load_it->second != id) {
1330 auto accesschain_it = used_operators.accesschain_members.find(load_it->second);
1331 if (accesschain_it == used_operators.accesschain_members.end()) {
1332 continue;
1333 } else {
1334 if (accesschain_it->second.first != id) {
1335 continue;
1336 }
1337
1338 const auto const_itr = GetConstantDef(accesschain_it->second.second);
1339 if (const_itr == end()) {
1340 // access chain index not a constant, skip.
1341 break;
1342 }
1343 image_index = GetConstantValue(const_itr);
1344 }
1345 }
1346 }
1347 // Find sampler's set binding.
1348 load_it = used_operators.load_members.find(itp_id.second);
1349 if (load_it == used_operators.load_members.end()) {
1350 continue;
1351 } else {
1352 uint32_t sampler_id = load_it->second;
1353 uint32_t sampler_index = 0;
1354 auto accesschain_it = used_operators.accesschain_members.find(load_it->second);
1355
1356 if (accesschain_it != used_operators.accesschain_members.end()) {
1357 const auto const_itr = GetConstantDef(accesschain_it->second.second);
1358 if (const_itr == end()) {
1359 // access chain index representing sampler index is not a constant, skip.
1360 break;
1361 }
1362 sampler_id = const_itr.offset();
1363 sampler_index = GetConstantValue(const_itr);
1364 }
1365 auto sampler_dec = get_decorations(sampler_id);
1366 if (image_index >= out_interface_var.samplers_used_by_image.size()) {
1367 out_interface_var.samplers_used_by_image.resize(image_index + 1);
1368 }
1369 out_interface_var.samplers_used_by_image[image_index].emplace(
1370 SamplerUsedByImage{descriptor_slot_t{sampler_dec.descriptor_set, sampler_dec.binding}, sampler_index});
1371 }
1372 }
1373 }
1374 return;
1375 }
1376
1377 case spv::OpTypeStruct: {
1378 layer_data::unordered_set<unsigned> nonwritable_members;
1379 if (get_decorations(type.word(1)).flags & decoration_set::buffer_block_bit) is_storage_buffer = true;
1380 for (auto insn : member_decoration_inst) {
1381 if (insn.word(1) == type.word(1) && insn.word(3) == spv::DecorationNonWritable) {
1382 nonwritable_members.insert(insn.word(2));
1383 }
1384 }
1385
1386 // A buffer is writable if it's either flavor of storage buffer, and has any member not decorated
1387 // as nonwritable.
1388 if (is_storage_buffer && nonwritable_members.size() != type.len() - 2) {
1389 used_operators.update(this);
1390
1391 for (auto oid : used_operators.store_members) {
1392 if (id == oid) {
1393 out_interface_var.is_writable = true;
1394 return;
1395 }
1396 auto accesschain_it = used_operators.accesschain_members.find(oid);
1397 if (accesschain_it == used_operators.accesschain_members.end()) {
1398 continue;
1399 }
1400 if (accesschain_it->second.first == id) {
1401 out_interface_var.is_writable = true;
1402 return;
1403 }
1404 }
1405 if (CheckObjectIDFromOpLoad(id, used_operators.atomic_store_members, used_operators.image_texel_pointer_members,
1406 used_operators.accesschain_members)) {
1407 out_interface_var.is_writable = true;
1408 return;
1409 }
1410 }
1411 }
1412 }
1413}
1414
1415std::vector<std::pair<descriptor_slot_t, interface_var>> SHADER_MODULE_STATE::CollectInterfaceByDescriptorSlot(
1416 layer_data::unordered_set<uint32_t> const &accessible_ids, bool *has_writable_descriptor, bool *has_atomic_descriptor) const {
1417 std::vector<std::pair<descriptor_slot_t, interface_var>> out;
1418 shader_module_used_operators operators;
1419
1420 for (auto id : accessible_ids) {
1421 auto insn = get_def(id);
1422 assert(insn != end());
1423
1424 if (insn.opcode() == spv::OpVariable &&
1425 (insn.word(3) == spv::StorageClassUniform || insn.word(3) == spv::StorageClassUniformConstant ||
1426 insn.word(3) == spv::StorageClassStorageBuffer)) {
1427 auto d = get_decorations(insn.word(2));
1428 unsigned set = d.descriptor_set;
1429 unsigned binding = d.binding;
1430
1431 interface_var v = {};
1432 v.id = insn.word(2);
1433 v.type_id = insn.word(1);
1434
1435 IsSpecificDescriptorType(insn, insn.word(3) == spv::StorageClassStorageBuffer,
1436 !(d.flags & decoration_set::nonwritable_bit), v, operators);
1437 if (v.is_writable) *has_writable_descriptor = true;
1438 if (v.is_atomic_operation) *has_atomic_descriptor = true;
1439 out.emplace_back(std::make_pair(set, binding), v);
1440 }
1441 }
1442
1443 return out;
1444}
1445
1446layer_data::unordered_set<uint32_t> SHADER_MODULE_STATE::CollectWritableOutputLocationinFS(
1447 const VkPipelineShaderStageCreateInfo &stage_info) const {
1448 layer_data::unordered_set<uint32_t> location_list;
1449 if (stage_info.stage != VK_SHADER_STAGE_FRAGMENT_BIT) return location_list;
1450 const auto entrypoint = FindEntrypoint(stage_info.pName, stage_info.stage);
1451 const auto outputs = CollectInterfaceByLocation(entrypoint, spv::StorageClassOutput, false);
1452 layer_data::unordered_set<unsigned> store_members;
1453 layer_data::unordered_map<unsigned, unsigned> accesschain_members;
1454
1455 for (auto insn : *this) {
1456 switch (insn.opcode()) {
1457 case spv::OpStore:
1458 case spv::OpAtomicStore: {
1459 store_members.insert(insn.word(1)); // object id or AccessChain id
1460 break;
1461 }
1462 case spv::OpAccessChain: {
1463 // 2: AccessChain id, 3: object id
1464 if (insn.word(3)) accesschain_members.emplace(insn.word(2), insn.word(3));
1465 break;
1466 }
1467 default:
1468 break;
1469 }
1470 }
1471 if (store_members.empty()) {
1472 return location_list;
1473 }
1474 for (auto output : outputs) {
1475 auto store_it = store_members.find(output.second.id);
1476 if (store_it != store_members.end()) {
1477 location_list.insert(output.first.first);
1478 store_members.erase(store_it);
1479 continue;
1480 }
1481 store_it = store_members.begin();
1482 while (store_it != store_members.end()) {
1483 auto accesschain_it = accesschain_members.find(*store_it);
1484 if (accesschain_it == accesschain_members.end()) {
1485 ++store_it;
1486 continue;
1487 }
1488 if (accesschain_it->second == output.second.id) {
1489 location_list.insert(output.first.first);
1490 store_members.erase(store_it);
1491 accesschain_members.erase(accesschain_it);
1492 break;
1493 }
1494 ++store_it;
1495 }
1496 }
1497 return location_list;
1498}
1499
1500bool SHADER_MODULE_STATE::CollectInterfaceBlockMembers(std::map<location_t, interface_var> *out, bool is_array_of_verts,
1501 uint32_t id, uint32_t type_id, bool is_patch, int /*first_location*/) const {
1502 // Walk down the type_id presented, trying to determine whether it's actually an interface block.
1503 auto type = GetStructType(get_def(type_id), is_array_of_verts && !is_patch);
1504 if (type == end() || !(get_decorations(type.word(1)).flags & decoration_set::block_bit)) {
1505 // This isn't an interface block.
1506 return false;
1507 }
1508
1509 layer_data::unordered_map<unsigned, unsigned> member_components;
1510 layer_data::unordered_map<unsigned, unsigned> member_relaxed_precision;
1511 layer_data::unordered_map<unsigned, unsigned> member_patch;
1512
1513 // Walk all the OpMemberDecorate for type's result id -- first pass, collect components.
1514 for (auto insn : member_decoration_inst) {
1515 if (insn.word(1) == type.word(1)) {
1516 unsigned member_index = insn.word(2);
1517
1518 if (insn.word(3) == spv::DecorationComponent) {
1519 unsigned component = insn.word(4);
1520 member_components[member_index] = component;
1521 }
1522
1523 if (insn.word(3) == spv::DecorationRelaxedPrecision) {
1524 member_relaxed_precision[member_index] = 1;
1525 }
1526
1527 if (insn.word(3) == spv::DecorationPatch) {
1528 member_patch[member_index] = 1;
1529 }
1530 }
1531 }
1532
1533 // TODO: correctly handle location assignment from outside
1534
1535 // Second pass -- produce the output, from Location decorations
1536 for (auto insn : member_decoration_inst) {
1537 if (insn.word(1) == type.word(1)) {
1538 unsigned member_index = insn.word(2);
1539 unsigned member_type_id = type.word(2 + member_index);
1540
1541 if (insn.word(3) == spv::DecorationLocation) {
1542 unsigned location = insn.word(4);
1543 unsigned num_locations = GetLocationsConsumedByType(member_type_id, false);
1544 auto component_it = member_components.find(member_index);
1545 unsigned component = component_it == member_components.end() ? 0 : component_it->second;
1546 bool is_relaxed_precision = member_relaxed_precision.find(member_index) != member_relaxed_precision.end();
1547 bool member_is_patch = is_patch || member_patch.count(member_index) > 0;
1548
1549 for (unsigned int offset = 0; offset < num_locations; offset++) {
1550 interface_var v = {};
1551 v.id = id;
1552 // TODO: member index in interface_var too?
1553 v.type_id = member_type_id;
1554 v.offset = offset;
1555 v.is_patch = member_is_patch;
1556 v.is_block_member = true;
1557 v.is_relaxed_precision = is_relaxed_precision;
1558 (*out)[std::make_pair(location + offset, component)] = v;
1559 }
1560 }
1561 }
1562 }
1563
1564 return true;
1565}
1566
1567std::map<location_t, interface_var> SHADER_MODULE_STATE::CollectInterfaceByLocation(spirv_inst_iter entrypoint,
1568 spv::StorageClass sinterface,
1569 bool is_array_of_verts) const {
1570 // TODO: handle index=1 dual source outputs from FS -- two vars will have the same location, and we DON'T want to clobber.
1571
1572 std::map<location_t, interface_var> out;
1573
1574 for (uint32_t iid : FindEntrypointInterfaces(entrypoint)) {
1575 auto insn = get_def(iid);
1576 assert(insn != end());
1577 assert(insn.opcode() == spv::OpVariable);
1578
1579 if (insn.word(3) == static_cast<uint32_t>(sinterface)) {
1580 auto d = get_decorations(iid);
1581 unsigned id = insn.word(2);
1582 unsigned type = insn.word(1);
1583
1584 int location = d.location;
1585 int builtin = d.builtin;
1586 unsigned component = d.component;
1587 bool is_patch = (d.flags & decoration_set::patch_bit) != 0;
1588 bool is_relaxed_precision = (d.flags & decoration_set::relaxed_precision_bit) != 0;
1589
1590 if (builtin != -1) {
1591 continue;
1592 } else if (!CollectInterfaceBlockMembers(&out, is_array_of_verts, id, type, is_patch, location)) {
1593 // A user-defined interface variable, with a location. Where a variable occupied multiple locations, emit
1594 // one result for each.
1595 unsigned num_locations = GetLocationsConsumedByType(type, is_array_of_verts && !is_patch);
1596 for (unsigned int offset = 0; offset < num_locations; offset++) {
1597 interface_var v = {};
1598 v.id = id;
1599 v.type_id = type;
1600 v.offset = offset;
1601 v.is_patch = is_patch;
1602 v.is_relaxed_precision = is_relaxed_precision;
1603 out[std::make_pair(location + offset, component)] = v;
1604 }
1605 }
1606 }
1607 }
1608
1609 return out;
1610}
1611
1612std::vector<uint32_t> SHADER_MODULE_STATE::CollectBuiltinBlockMembers(spirv_inst_iter entrypoint, uint32_t storageClass) const {
1613 std::vector<uint32_t> variables;
1614 std::vector<uint32_t> builtin_struct_members;
1615 std::vector<uint32_t> builtin_decorations;
1616
1617 for (auto insn : member_decoration_inst) {
1618 if (insn.word(3) == spv::DecorationBuiltIn) {
1619 builtin_struct_members.push_back(insn.word(1));
1620 }
1621 }
1622 for (auto insn : decoration_inst) {
1623 switch (insn.word(2)) {
1624 case spv::DecorationBlock: {
1625 uint32_t block_id = insn.word(1);
1626 for (auto builtin_block_id : builtin_struct_members) {
1627 // Check if one of the members of the block are built-in -> the block is built-in
1628 if (block_id == builtin_block_id) {
1629 builtin_decorations.push_back(block_id);
1630 break;
1631 }
1632 }
1633 break;
1634 }
1635 case spv::DecorationBuiltIn:
1636 builtin_decorations.push_back(insn.word(1));
1637 break;
1638 default:
1639 break;
1640 }
1641 }
1642
1643 // Find all interface variables belonging to the entrypoint and matching the storage class
1644 for (uint32_t id : FindEntrypointInterfaces(entrypoint)) {
1645 auto def = get_def(id);
1646 assert(def != end());
1647 assert(def.opcode() == spv::OpVariable);
1648
1649 if (def.word(3) == storageClass) variables.push_back(def.word(1));
1650 }
1651
1652 // Find all members belonging to the builtin block selected
1653 std::vector<uint32_t> builtin_block_members;
1654 for (auto &var : variables) {
1655 auto def = get_def(get_def(var).word(3));
1656
1657 // It could be an array of IO blocks. The element type should be the struct defining the block contents
1658 if (def.opcode() == spv::OpTypeArray) def = get_def(def.word(2));
1659
1660 // Now find all members belonging to the struct defining the IO block
1661 if (def.opcode() == spv::OpTypeStruct) {
1662 for (auto builtin_id : builtin_decorations) {
1663 if (builtin_id == def.word(1)) {
1664 for (int i = 2; i < static_cast<int>(def.len()); i++) {
1665 builtin_block_members.push_back(spv::BuiltInMax); // Start with undefined builtin for each struct member.
1666 }
1667 // These shouldn't be left after replacing.
1668 for (auto insn : member_decoration_inst) {
1669 if (insn.word(1) == builtin_id && insn.word(3) == spv::DecorationBuiltIn) {
1670 auto struct_index = insn.word(2);
1671 assert(struct_index < builtin_block_members.size());
1672 builtin_block_members[struct_index] = insn.word(4);
1673 }
1674 }
1675 }
1676 }
1677 }
1678 }
1679
1680 return builtin_block_members;
1681}
1682
1683std::vector<std::pair<uint32_t, interface_var>> SHADER_MODULE_STATE::CollectInterfaceByInputAttachmentIndex(
1684 layer_data::unordered_set<uint32_t> const &accessible_ids) const {
1685 std::vector<std::pair<uint32_t, interface_var>> out;
1686
1687 for (auto insn : decoration_inst) {
1688 if (insn.word(2) == spv::DecorationInputAttachmentIndex) {
1689 auto attachment_index = insn.word(3);
1690 auto id = insn.word(1);
1691
1692 if (accessible_ids.count(id)) {
1693 auto def = get_def(id);
1694 assert(def != end());
1695 if (def.opcode() == spv::OpVariable && def.word(3) == spv::StorageClassUniformConstant) {
1696 auto num_locations = GetLocationsConsumedByType(def.word(1), false);
1697 for (unsigned int offset = 0; offset < num_locations; offset++) {
1698 interface_var v = {};
1699 v.id = id;
1700 v.type_id = def.word(1);
1701 v.offset = offset;
1702 out.emplace_back(attachment_index + offset, v);
1703 }
1704 }
1705 }
1706 }
1707 }
1708
1709 return out;
1710}
1711
Lionel Landwerlin892d6c32021-05-05 12:56:19 +03001712spirv_inst_iter SHADER_MODULE_STATE::GetImageFormatInst(const std::map<uint32_t, uint32_t>& loads, uint32_t id) const
1713{
1714 do {
1715 const auto iter = loads.find(id);
1716 if (iter != loads.end()) {
1717 id = iter->second;
1718 continue;
1719 }
1720
1721 auto def = get_def(id);
1722 switch (def.opcode()) {
1723 case spv::OpLoad:
1724 return end();
1725
1726 case spv::OpAccessChain:
1727 case spv::OpCompositeConstruct:
1728 case spv::OpVariable: {
1729 id = def.word(1);
1730 break;
1731 }
1732
1733 case spv::OpTypeArray:
1734 case spv::OpTypeRuntimeArray:
1735 id = def.word(2);
1736 break;
1737
1738 case spv::OpTypePointer:
1739 id = def.word(3);
1740 break;
1741
1742 case spv::OpTypeImage:
1743 return def;
1744
1745 default:
1746 return end();
1747 }
1748 } while (true);
1749}
1750
sfricke-samsung962cad92021-04-13 00:46:29 -07001751// Assumes itr points to an OpConstant instruction
1752uint32_t GetConstantValue(const spirv_inst_iter &itr) { return itr.word(3); }
1753
1754std::vector<uint32_t> FindEntrypointInterfaces(const spirv_inst_iter &entrypoint) {
1755 assert(entrypoint.opcode() == spv::OpEntryPoint);
1756
1757 std::vector<uint32_t> interfaces;
1758 // Find the end of the entrypoint's name string. additional zero bytes follow the actual null terminator, to fill out the
1759 // rest of the word - so we only need to look at the last byte in the word to determine which word contains the terminator.
1760 uint32_t word = 3;
1761 while (entrypoint.word(word) & 0xff000000u) {
1762 ++word;
1763 }
1764 ++word;
1765
1766 for (; word < entrypoint.len(); word++) interfaces.push_back(entrypoint.word(word));
1767
1768 return interfaces;
1769}
1770
1771bool AtomicOperation(uint32_t opcode) {
1772 switch (opcode) {
1773 case spv::OpAtomicLoad:
1774 case spv::OpAtomicStore:
1775 case spv::OpAtomicExchange:
1776 case spv::OpAtomicCompareExchange:
1777 case spv::OpAtomicCompareExchangeWeak:
1778 case spv::OpAtomicIIncrement:
1779 case spv::OpAtomicIDecrement:
1780 case spv::OpAtomicIAdd:
1781 case spv::OpAtomicISub:
1782 case spv::OpAtomicSMin:
1783 case spv::OpAtomicUMin:
1784 case spv::OpAtomicSMax:
1785 case spv::OpAtomicUMax:
1786 case spv::OpAtomicAnd:
1787 case spv::OpAtomicOr:
1788 case spv::OpAtomicXor:
1789 case spv::OpAtomicFAddEXT:
1790 return true;
1791 default:
1792 return false;
1793 }
1794 return false;
1795}
1796
1797// Only includes valid group operations used in Vulkan (for now thats only subgroup ops) and any non supported operation will be
1798// covered with VUID 01090
1799bool GroupOperation(uint32_t opcode) {
1800 switch (opcode) {
1801 case spv::OpGroupNonUniformElect:
1802 case spv::OpGroupNonUniformAll:
1803 case spv::OpGroupNonUniformAny:
1804 case spv::OpGroupNonUniformAllEqual:
1805 case spv::OpGroupNonUniformBroadcast:
1806 case spv::OpGroupNonUniformBroadcastFirst:
1807 case spv::OpGroupNonUniformBallot:
1808 case spv::OpGroupNonUniformInverseBallot:
1809 case spv::OpGroupNonUniformBallotBitExtract:
1810 case spv::OpGroupNonUniformBallotBitCount:
1811 case spv::OpGroupNonUniformBallotFindLSB:
1812 case spv::OpGroupNonUniformBallotFindMSB:
1813 case spv::OpGroupNonUniformShuffle:
1814 case spv::OpGroupNonUniformShuffleXor:
1815 case spv::OpGroupNonUniformShuffleUp:
1816 case spv::OpGroupNonUniformShuffleDown:
1817 case spv::OpGroupNonUniformIAdd:
1818 case spv::OpGroupNonUniformFAdd:
1819 case spv::OpGroupNonUniformIMul:
1820 case spv::OpGroupNonUniformFMul:
1821 case spv::OpGroupNonUniformSMin:
1822 case spv::OpGroupNonUniformUMin:
1823 case spv::OpGroupNonUniformFMin:
1824 case spv::OpGroupNonUniformSMax:
1825 case spv::OpGroupNonUniformUMax:
1826 case spv::OpGroupNonUniformFMax:
1827 case spv::OpGroupNonUniformBitwiseAnd:
1828 case spv::OpGroupNonUniformBitwiseOr:
1829 case spv::OpGroupNonUniformBitwiseXor:
1830 case spv::OpGroupNonUniformLogicalAnd:
1831 case spv::OpGroupNonUniformLogicalOr:
1832 case spv::OpGroupNonUniformLogicalXor:
1833 case spv::OpGroupNonUniformQuadBroadcast:
1834 case spv::OpGroupNonUniformQuadSwap:
1835 case spv::OpGroupNonUniformPartitionNV:
1836 return true;
1837 default:
1838 return false;
1839 }
1840 return false;
Jeremy Gebben5d970742021-05-31 16:04:14 -06001841}