-
Notifications
You must be signed in to change notification settings - Fork 851
Expand file tree
/
Copy pathCapabilityVisitor.h
More file actions
101 lines (82 loc) · 3.99 KB
/
CapabilityVisitor.h
File metadata and controls
101 lines (82 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//===--- CapabilityVisitor.h - Capability Visitor ----------------*- C++ -*-==//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_LIB_SPIRV_CAPABILITYVISITOR_H
#define LLVM_CLANG_LIB_SPIRV_CAPABILITYVISITOR_H
#include "clang/SPIRV/FeatureManager.h"
#include "clang/SPIRV/SpirvContext.h"
#include "clang/SPIRV/SpirvVisitor.h"
namespace clang {
namespace spirv {
class SpirvBuilder;
class CapabilityVisitor : public Visitor {
public:
CapabilityVisitor(ASTContext &astCtx, SpirvContext &spvCtx,
const SpirvCodeGenOptions &opts, SpirvBuilder &builder,
FeatureManager &featureMgr)
: Visitor(opts, spvCtx), spvBuilder(builder),
shaderModel(spv::ExecutionModel::Max), featureManager(featureMgr) {}
bool visit(SpirvModule *, Phase) override;
bool visit(SpirvDecoration *decor) override;
bool visit(SpirvEntryPoint *) override;
bool visit(SpirvExecutionModeBase *execMode) override;
bool visit(SpirvImageQuery *) override;
bool visit(SpirvImageOp *) override;
bool visit(SpirvImageSparseTexelsResident *) override;
bool visit(SpirvExtInstImport *) override;
bool visit(SpirvAtomic *) override;
bool visit(SpirvDemoteToHelperInvocation *) override;
bool visit(SpirvIsHelperInvocationEXT *) override;
bool visit(SpirvReadClock *) override;
using Visitor::visit;
/// The "sink" visit function for all instructions.
///
/// By default, all other visit instructions redirect to this visit function.
/// So that you want override this visit function to handle all instructions,
/// regardless of their polymorphism.
bool visitInstruction(SpirvInstruction *instr) override;
private:
/// Adds necessary capabilities for using the given type.
/// The called may also provide the storage class for variable types, because
/// in the case of variable types, the storage class may affect the capability
/// that is used.
void addCapabilityForType(const SpirvType *, SourceLocation loc,
spv::StorageClass sc);
/// Checks that the given extension is a valid extension for the target
/// environment (e.g. Vulkan 1.0). And if so, utilizes the SpirvBuilder to add
/// the given extension to the SPIR-V module in memory.
void addExtension(Extension ext, llvm::StringRef target, SourceLocation loc);
/// Checks that the given extension is enabled based on command line arguments
/// before calling addExtension and addCapability.
/// Returns `true` if the extension was enabled, `false` otherwise.
bool addExtensionAndCapabilitiesIfEnabled(
Extension ext, llvm::ArrayRef<spv::Capability> capabilities);
/// Checks that the given capability is a valid capability. And if so,
/// utilizes the SpirvBuilder to add the given capability to the SPIR-V module
/// in memory.
void addCapability(spv::Capability, SourceLocation loc = {});
/// Returns the capability required to non-uniformly index into the given
/// type.
spv::Capability getNonUniformCapability(const SpirvType *);
/// Returns whether the shader model is one of the ray tracing execution
/// models.
bool IsShaderModelForRayTracing();
/// Adds VulkanMemoryModel capability if decoration needs Volatile semantics
/// for OpLoad instructions. For Vulkan 1.3 or above, we can simply add
/// Volatile decoration for the variable. Therefore, in that case, we do not
/// need VulkanMemoryModel capability.
void AddVulkanMemoryModelForVolatile(SpirvDecoration *decor,
SourceLocation loc);
private:
SpirvBuilder &spvBuilder; ///< SPIR-V builder
spv::ExecutionModel shaderModel; ///< Execution model
FeatureManager featureManager; ///< SPIR-V version/extension manager.
};
} // end namespace spirv
} // end namespace clang
#endif // LLVM_CLANG_LIB_SPIRV_CAPABILITYVISITOR_H