9 #include <spirv/unified1/spirv.h>
34 assert(
false &&
"Not an aggregate type");
66 const std::map<uint32_t, uint32_t> &
123 Stream <<
"<unknown>";
131 case SpvImageFormat##X: \
176 Stream <<
"<unknown>";
197 Stream <<
"struct {";
224 Stream <<
"<unhandled type>";
231 uint32_t ElementCount,
232 uint32_t ArrayStride)
234 assert(ArrayStride >= ElemType->
getSize());
235 std::unique_ptr<Type> T(
new Type(
ARRAY, ElementCount * ArrayStride));
236 T->ElementType = ElemType;
244 return std::unique_ptr<Type>(
new Type(
BOOL, 1));
249 std::unique_ptr<Type> T(
new Type(
FLOAT, Width / 8));
256 std::unique_ptr<Type> T(
new Type(
INT, Width / 8));
261 std::unique_ptr<Type>
263 const std::vector<const Type *> &ArgTypes)
267 T->ArgumentTypes = ArgTypes;
272 uint32_t Depth,
bool Arrayed,
bool MS,
273 uint32_t Sampled, uint32_t Format)
276 T->ElementType = SampledType;
277 T->Dimensionality = Dim;
280 T->Multisampled = MS;
290 T->ElementType = ColumnType;
291 T->ElementCount = NumColumns;
296 const Type *ElemType,
297 uint32_t ArrayStride)
299 std::unique_ptr<Type> T(
new Type(
POINTER,
sizeof(uint64_t)));
301 T->ElementType = ElemType;
307 uint32_t ArrayStride)
309 assert(ArrayStride >= ElemType->
getSize());
311 T->ElementType = ElemType;
319 T->ElementType = ImageType;
325 return std::unique_ptr<Type>(
new Type(
SAMPLER,
sizeof(uint64_t)));
331 size_t CurrentOffset = 0;
332 std::vector<size_t> Offsets(ElemTypes.size());
333 for (
size_t i = 0; i < ElemTypes.size(); i++)
335 if (ElemTypes[i].second.count(SpvDecorationOffset))
336 Offsets[i] = ElemTypes[i].second.at(SpvDecorationOffset);
338 Offsets[i] = CurrentOffset;
341 if (ElemTypes[i].first->isMatrix() &&
342 ElemTypes[i].second.count(SpvDecorationMatrixStride))
344 const Type *MatrixType = ElemTypes[i].first;
346 uint32_t MatrixStride = ElemTypes[i].second.at(SpvDecorationMatrixStride);
350 if (ElemTypes[i].second.count(SpvDecorationColMajor))
355 CurrentOffset = Offsets[i] + MatrixSize;
358 CurrentOffset = Offsets[i] + ElemTypes[i].first->getSize();
361 std::unique_ptr<Type> T(
new Type(
STRUCT, CurrentOffset));
362 T->ElementTypes = ElemTypes;
363 T->ElementOffsets = Offsets;
364 T->ElementCount = (uint32_t)ElemTypes.size();
372 T->ElementType = ElemType;
379 return std::unique_ptr<Type>(
new Type(
VOID, 0));
static std::unique_ptr< Type > getVector(const Type *ElemType, uint32_t ElemCount)
Create a vector type.
static std::unique_ptr< Type > getVoid()
Create a void type.
bool isScalar() const
Returns true if this is a scalar type.
uint32_t Depth
Valid for image types.
bool isFloat() const
Returns true if this is a floating point type.
uint32_t Sampled
Valid for image types.
bool Arrayed
Valid for image types.
static std::unique_ptr< Type > getPointer(uint32_t StorageClass, const Type *ElemType, uint32_t ArrayStride)
Create a pointer type.
size_t getSize() const
Returns the size of this type in bytes.
uint32_t StorageClass
Valid for pointer types.
std::vector< size_t > ElementOffsets
Valid for struct types.
A combination of an image and a sampler used to access it.
static std::unique_ptr< Type > getSampledImage(const Type *ImageType)
Create a sampled image type.
std::vector< std::pair< const Type *, std::map< uint32_t, uint32_t > > > StructElementTypeList
A list of types used for structure members.
uint32_t BitWidth
Valid for integer and floating point types.
static std::unique_ptr< Type > getBool()
Create a boolean type.
size_t getElementOffset(uint64_t Index) const
Returns the byte offset of the element at Index.
const Type * getElementType(uint64_t Index=0) const
Returns the type of the element at Index.
const Type * getScalarType() const
Returns the element type for vector types, or this for scalar types.
bool isInt() const
Returns true if this is an integer type.
static std::unique_ptr< Type > getSampler()
Create a sampler type.
static std::unique_ptr< Type > getImage(const Type *SampledType, uint32_t Dim, uint32_t Depth, bool Arrayed, bool MS, uint32_t Sampled, uint32_t Format)
Create an image type.
This class represents a view into a range of image subresources.
Type(TypeId Id, size_t ByteSize)
Create a new type.
const Type * ReturnType
Valid for function types.
const std::map< uint32_t, uint32_t > & getStructMemberDecorations(uint32_t Index) const
Returns the decoration map for the structure member at Index.
uint32_t Dimensionality
Valid for image types.
uint32_t getElementCount() const
Returns the number of elements in this array, struct, or vector type.
std::vector< const Type * > ArgumentTypes
Valid for function types.
This file declares the Type class.
uint32_t ArrayStride
Valid for array and pointer types.
bool isComposite() const
Returns true if this is an array, struct, or vector type.
static std::unique_ptr< Type > getInt(uint32_t Width)
Create an integer type.
This file declares data structures and functions for handling images.
uint32_t getBitWidth() const
Returns the bit-width of this type.
uint32_t getStorageClass() const
Returns the storage class of this type.
std::ostream & operator<<(std::ostream &Stream, const Dim3 &D)
static std::unique_ptr< Type > getRuntimeArray(const Type *ElemType, uint32_t ArrayStride)
Create a runtime array type.
uint32_t Format
Valid for image types.
static std::unique_ptr< Type > getStruct(const StructElementTypeList &ElemTypes)
Create a structure type.
uint32_t ElementCount
Valid for composite types.
This class represents a SPIR-V type.
static std::unique_ptr< Type > getFunction(const Type *ReturnType, const std::vector< const Type * > &ArgTypes)
Create a function type.
TypeId Id
The ID of this type.
const Type * ElementType
Valid for pointer and composite types.
static std::unique_ptr< Type > getFloat(uint32_t Width)
Create a floating point type.
static std::unique_ptr< Type > getArray(const Type *ElemType, uint32_t ElementCount, uint32_t ArrayStride)
Create an array type.
static std::unique_ptr< Type > getMatrix(const Type *ColumnType, uint32_t NumColumns)
Create a matrix type.
StructElementTypeList ElementTypes
Valid for struct types.