| 1 | //===- HLSLResource.cpp - HLSL Resource helper objects --------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// |
| 9 | /// \file This file contains helper objects for working with HLSL Resources. |
| 10 | /// |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/Frontend/HLSL/HLSLResource.h" |
| 14 | #include "llvm/IR/DerivedTypes.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace llvm::hlsl; |
| 18 | |
| 19 | dxil::ElementType hlsl::getDXILElementType(Type *Ty, bool IsSigned) { |
| 20 | // TODO: Handle unorm, snorm, and packed. |
| 21 | Ty = Ty->getScalarType(); |
| 22 | |
| 23 | if (Ty->isIntegerTy()) { |
| 24 | switch (Ty->getIntegerBitWidth()) { |
| 25 | case 16: |
| 26 | return IsSigned ? dxil::ElementType::I16 : dxil::ElementType::U16; |
| 27 | case 32: |
| 28 | return IsSigned ? dxil::ElementType::I32 : dxil::ElementType::U32; |
| 29 | case 64: |
| 30 | return IsSigned ? dxil::ElementType::I64 : dxil::ElementType::U64; |
| 31 | case 1: |
| 32 | default: |
| 33 | return dxil::ElementType::Invalid; |
| 34 | } |
| 35 | } else if (Ty->isFloatTy()) { |
| 36 | return dxil::ElementType::F32; |
| 37 | } else if (Ty->isDoubleTy()) { |
| 38 | return dxil::ElementType::F64; |
| 39 | } else if (Ty->isHalfTy()) { |
| 40 | return dxil::ElementType::F16; |
| 41 | } |
| 42 | |
| 43 | return dxil::ElementType::Invalid; |
| 44 | } |
| 45 | |