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 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360
|
/*========================== begin_copyright_notice ============================
Copyright (C) 2017-2021 Intel Corporation
SPDX-License-Identifier: MIT
============================= end_copyright_notice ===========================*/
#ifndef IGC_COMMON_TYPES_H
#define IGC_COMMON_TYPES_H
#include "IGC/common/StringMacros.hpp"
#include "3d/common/iStdLib/types.h"
#include "AdaptorCommon/API/igc.h"
#include "common/debug/Debug.hpp"
#include "IGC/common/LLVMWarningsPush.hpp"
#include "llvm/Config/llvm-config.h"
#if LLVM_VERSION_MAJOR >= 10
#include "llvm/Support/TypeSize.h"
#endif
#include "IGC/common/LLVMWarningsPop.hpp"
#include "Probe/Assertion.h"
#include "IGC/common/shaderHash.hpp"
#include "EmUtils.h"
namespace USC
{
struct ShaderD3D;
}
namespace IGC
{
enum PrecisionType : uint8_t
{
PRECISION_UNUSED, U8, U4, U2, S8, S4, S2,
BF8,
TF32,
BF16, FP16
};
inline uint32_t getPrecisionInBits(PrecisionType P)
{
switch (P)
{
default:
break;
case BF16:
case FP16:
return 16;
case U8:
case S8:
return 8;
case U4:
case S4:
return 4;
case U2:
case S2:
return 2;
// PVC
case TF32:
return 32;
}
return 0;
}
}
enum class SIMDMode : unsigned char
{
UNKNOWN,
SIMD1,
SIMD2,
SIMD4,
SIMD8,
SIMD16,
SIMD32,
END,
BEGIN = 0
};
enum class SIMDStatus : unsigned char
{
SIMD_BEGIN = 0,
SIMD_PASS,
SIMD_FUNC_FAIL,
SIMD_PERF_FAIL,
SIMD_END
};
inline uint16_t numLanes(SIMDMode width)
{
switch(width)
{
case SIMDMode::SIMD1 : return 1;
case SIMDMode::SIMD2 : return 2;
case SIMDMode::SIMD4 : return 4;
case SIMDMode::SIMD8 : return 8;
case SIMDMode::SIMD16 : return 16;
case SIMDMode::SIMD32 : return 32;
case SIMDMode::UNKNOWN :
default:
IGC_ASSERT_MESSAGE(0, "unreachable");
return 1;
}
}
inline SIMDMode lanesToSIMDMode(unsigned lanes) {
switch (lanes) {
case 1: return SIMDMode::SIMD1;
case 2: return SIMDMode::SIMD2;
case 4: return SIMDMode::SIMD4;
case 8: return SIMDMode::SIMD8;
case 16: return SIMDMode::SIMD16;
case 32: return SIMDMode::SIMD32;
default:
IGC_ASSERT_MESSAGE(0, "Unexpected number of lanes!");
return SIMDMode::UNKNOWN;
}
}
enum class ShaderType
{
UNKNOWN,
VERTEX_SHADER,
HULL_SHADER,
DOMAIN_SHADER,
GEOMETRY_SHADER,
TASK_SHADER,
MESH_SHADER,
PIXEL_SHADER,
COMPUTE_SHADER,
OPENCL_SHADER,
RAYTRACING_SHADER,
BINDLESS_SHADER,
END,
BEGIN = 0
};
enum class ShaderDispatchMode
{
NOT_APPLICABLE,
SINGLE_PATCH,
DUAL_PATCH,
EIGHT_PATCH,
DUAL_SIMD8,
END,
BEGIN = 0
};
static const char *ShaderTypeString[] = {
"ERROR",
"VS",
"HS",
"DS",
"GS",
"TASK",
"MESH",
"PS",
"CS",
"OCL",
"RAYDISPATCH",
"BINDLESS",
"ERROR"
};
static_assert(sizeof(ShaderTypeString) / sizeof(*ShaderTypeString) == static_cast<size_t>(ShaderType::END) + 1,
"Update the array");
template <typename TIter>
class RangeWrapper
{
public:
TIter& begin() { return m_first; }
TIter& end() { return m_last; }
private:
RangeWrapper( TIter first, TIter last )
: m_first(first)
, m_last(last)
{ }
TIter m_first;
TIter m_last;
template <typename T>
friend inline RangeWrapper<T> range( const T& first, const T& last );
};
/**
* \brief Create a proxy to iterate over a container's nonstandard iterator pairs via c++11 range-for
*
* This is to be used for containers that provide multiple sets of iterators
* such as llvm::Function, which has begin()/end() and arg_begin()/arg_end().
* In the latter case, range-for cannot be used without such a proxy.
*
* \example
* for ( auto arg : range( pFunc->arg_begin(), pFunc->arg_end() ) )
* {
* ...
* }
*/
template <typename TIter>
inline RangeWrapper<TIter> range( const TIter& first, const TIter& last )
{
return RangeWrapper<TIter>(first, last);
}
template <typename TEnum>
class EnumIter
{
public:
EnumIter operator++(/* prefix */)
{
increment_me();
return *this;
}
EnumIter operator++(int /* postfix */)
{
TEnum old(m_val);
increment_me();
return old;
}
TEnum operator*() const
{
return m_val;
}
bool operator!=(EnumIter const& other) const
{
return !is_equal(other);
}
bool operator==(EnumIter const& other) const
{
return is_equal(other);
}
private:
EnumIter(TEnum init)
: m_val(init)
{}
bool is_equal(EnumIter const& other) const
{
return m_val == other.m_val;
}
void increment_me()
{
m_val = static_cast<TEnum>( static_cast<unsigned int>(m_val) + 1 );
}
template <typename T>
friend inline RangeWrapper<EnumIter<T>> eRange(T, T);
TEnum m_val;
};
/**
* \brief Create a proxy to iterate over every element of an enumeration
*
* Assumes that TEnum follows this pattern, with no gaps between the enumerated values:
* enum class EFoo {
* E1,
* E2,
* END,
* BEGIN = 0
* };
*/
template <typename TEnum>
inline RangeWrapper<EnumIter<TEnum>> eRange( TEnum begin = TEnum::BEGIN, TEnum end = TEnum::END)
{
return range( EnumIter<TEnum>(begin), EnumIter<TEnum>(end) );
}
/// Template that should be used when a static_cast of a larger integer
/// type to a smaller one is required.
/// In debug, this will check if the source argument doesn't exceed the target type range.
/// In release, it is just static_cast with no check.
///
/// Note that the cases where one needs to typecast integer types should be infrequent.
/// Could be necessary when dealing with other interfaces, otherwise think twice before
/// using it - maybe changing types or modifying the code design would be better.
template <typename TDst, typename TSrc>
inline typename std::enable_if<
std::is_signed<TDst>::value && std::is_signed<TSrc>::value,
TDst>::type int_cast(TSrc value)
{
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(std::numeric_limits<TDst>::min() <= value);
IGC_ASSERT(value <= std::numeric_limits<TDst>::max());
return static_cast<TDst>(value);
}
template <typename TDst, typename TSrc>
inline typename std::enable_if<
std::is_signed<TDst>::value && std::is_unsigned<TSrc>::value,
TDst>::type int_cast(TSrc value)
{
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(value <= static_cast<typename std::make_unsigned<TDst>::type>(std::numeric_limits<TDst>::max()));
return static_cast<TDst>(value);
}
template <typename TDst, typename TSrc>
inline typename std::enable_if<
std::is_unsigned<TDst>::value && std::is_signed<TSrc>::value,
TDst>::type int_cast(TSrc value)
{
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(0 <= value);
IGC_ASSERT(static_cast<typename std::make_unsigned<TSrc>::type>(value) <= std::numeric_limits<TDst>::max());
return static_cast<TDst>(value);
}
template <typename TDst, typename TSrc>
inline typename std::enable_if<
std::is_unsigned<TDst>::value && std::is_unsigned<TSrc>::value,
TDst>::type int_cast(TSrc value)
{
static_assert(std::is_integral<TDst>::value && std::is_integral<TSrc>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(value <= std::numeric_limits<TDst>::max());
return static_cast<TDst>(value);
}
#if LLVM_VERSION_MAJOR >= 10
template <typename TDst>
inline typename std::enable_if<
std::is_unsigned<TDst>::value,
TDst>::type int_cast(llvm::TypeSize value)
{
static_assert(std::is_integral<TDst>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(value.getFixedSize() <= std::numeric_limits<TDst>::max());
return static_cast<TDst>(value.getFixedSize());
}
template <typename TDst>
inline typename std::enable_if<
std::is_signed<TDst>::value,
TDst>::type int_cast(llvm::TypeSize value)
{
static_assert(std::is_integral<TDst>::value,
"int_cast<>() should be used only for conversions between integer types.");
IGC_ASSERT(value.getFixedSize() <= static_cast<typename std::make_unsigned<TDst>::type>(std::numeric_limits<TDst>::max()));
return static_cast<TDst>(value.getFixedSize());
}
#endif
#endif //IGC_COMMON_TYPES_H
|