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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
// slang-target.h
#pragma once
//
// This file declares the `TargetRequest` class, which is
// the primary way that the Slang compiler groups together
// a compilation target and options that affect output
// code generation and/or layout for that target.
//
#include "../core/slang-string.h"
#include "slang-ast-base.h"
#include "slang-compiler-fwd.h"
#include "slang-compiler-options.h"
#include "slang-hlsl-to-vulkan-layout-options.h"
#include <slang.h>
namespace Slang
{
enum class CodeGenTarget : SlangCompileTargetIntegral
{
Unknown = SLANG_TARGET_UNKNOWN,
None = SLANG_TARGET_NONE,
GLSL = SLANG_GLSL,
HLSL = SLANG_HLSL,
SPIRV = SLANG_SPIRV,
SPIRVAssembly = SLANG_SPIRV_ASM,
DXBytecode = SLANG_DXBC,
DXBytecodeAssembly = SLANG_DXBC_ASM,
DXIL = SLANG_DXIL,
DXILAssembly = SLANG_DXIL_ASM,
CSource = SLANG_C_SOURCE,
CPPSource = SLANG_CPP_SOURCE,
PyTorchCppBinding = SLANG_CPP_PYTORCH_BINDING,
HostCPPSource = SLANG_HOST_CPP_SOURCE,
HostExecutable = SLANG_HOST_EXECUTABLE,
HostSharedLibrary = SLANG_HOST_SHARED_LIBRARY,
ShaderSharedLibrary = SLANG_SHADER_SHARED_LIBRARY,
ShaderHostCallable = SLANG_SHADER_HOST_CALLABLE,
CUDASource = SLANG_CUDA_SOURCE,
PTX = SLANG_PTX,
CUDAObjectCode = SLANG_CUDA_OBJECT_CODE,
ObjectCode = SLANG_OBJECT_CODE,
HostHostCallable = SLANG_HOST_HOST_CALLABLE,
Metal = SLANG_METAL,
MetalLib = SLANG_METAL_LIB,
MetalLibAssembly = SLANG_METAL_LIB_ASM,
WGSL = SLANG_WGSL,
WGSLSPIRVAssembly = SLANG_WGSL_SPIRV_ASM,
WGSLSPIRV = SLANG_WGSL_SPIRV,
HostVM = SLANG_HOST_VM,
CountOf = SLANG_TARGET_COUNT_OF,
};
bool isHeterogeneousTarget(CodeGenTarget target);
void printDiagnosticArg(StringBuilder& sb, CodeGenTarget val);
class TargetRequest;
/// Are we generating code for a D3D API?
bool isD3DTarget(TargetRequest* targetReq);
// Are we generating code for Metal?
bool isMetalTarget(TargetRequest* targetReq);
/// Are we generating code for a Khronos API (OpenGL or Vulkan)?
bool isKhronosTarget(TargetRequest* targetReq);
bool isKhronosTarget(CodeGenTarget target);
/// Are we generating code where SPIRV is the target?
bool isSPIRV(CodeGenTarget codeGenTarget);
/// Are we generating code for a CUDA API (CUDA / OptiX)?
bool isCUDATarget(TargetRequest* targetReq);
// Are we generating code for a CPU target
bool isCPUTarget(TargetRequest* targetReq);
/// Are we generating code for the WebGPU API?
bool isWGPUTarget(TargetRequest* targetReq);
bool isWGPUTarget(CodeGenTarget target);
/// A request to generate output in some target format.
class TargetRequest : public RefObject
{
public:
TargetRequest(Linkage* linkage, CodeGenTarget format);
TargetRequest(const TargetRequest& other);
Linkage* getLinkage() { return linkage; }
Session* getSession();
CodeGenTarget getTarget()
{
return optionSet.getEnumOption<CodeGenTarget>(CompilerOptionName::Target);
}
// TypeLayouts created on the fly by reflection API
struct TypeLayoutKey
{
Type* type;
slang::LayoutRules rules;
HashCode getHashCode() const
{
Hasher hasher;
hasher.hashValue(type);
hasher.hashValue(rules);
return hasher.getResult();
}
bool operator==(TypeLayoutKey other) const
{
return type == other.type && rules == other.rules;
}
};
Dictionary<TypeLayoutKey, RefPtr<TypeLayout>> typeLayouts;
Dictionary<TypeLayoutKey, RefPtr<TypeLayout>>& getTypeLayouts() { return typeLayouts; }
TypeLayout* getTypeLayout(Type* type, slang::LayoutRules rules);
CompilerOptionSet& getOptionSet() { return optionSet; }
CapabilitySet getTargetCaps();
void setTargetCaps(CapabilitySet capSet);
HLSLToVulkanLayoutOptions* getHLSLToVulkanLayoutOptions();
private:
Linkage* linkage = nullptr;
CompilerOptionSet optionSet;
CapabilitySet cookedCapabilities;
RefPtr<HLSLToVulkanLayoutOptions> hlslToVulkanOptions;
};
/// Are resource types "bindless" (implemented as ordinary data) on the given `target`?
bool areResourceTypesBindlessOnTarget(TargetRequest* target);
} // namespace Slang
|