| 891 | } |
| 892 | |
| 893 | uint32_t IRContext::GetBuiltinInputVarId(uint32_t builtin) { |
| 894 | if (!AreAnalysesValid(kAnalysisBuiltinVarId)) ResetBuiltinAnalysis(); |
| 895 | // If cached, return it. |
| 896 | std::unordered_map<uint32_t, uint32_t>::iterator it = |
| 897 | builtin_var_id_map_.find(builtin); |
| 898 | if (it != builtin_var_id_map_.end()) return it->second; |
| 899 | // Look for one in shader |
| 900 | uint32_t var_id = FindBuiltinInputVar(builtin); |
| 901 | if (var_id == 0) { |
| 902 | // If not found, create it |
| 903 | // TODO(greg-lunarg): Add support for all builtins |
| 904 | analysis::TypeManager* type_mgr = get_type_mgr(); |
| 905 | analysis::Type* reg_type; |
| 906 | switch (spv::BuiltIn(builtin)) { |
| 907 | case spv::BuiltIn::FragCoord: { |
| 908 | analysis::Float float_ty(32); |
| 909 | analysis::Type* reg_float_ty = type_mgr->GetRegisteredType(&float_ty); |
| 910 | analysis::Vector v4float_ty(reg_float_ty, 4); |
| 911 | reg_type = type_mgr->GetRegisteredType(&v4float_ty); |
| 912 | break; |
| 913 | } |
| 914 | case spv::BuiltIn::VertexIndex: |
| 915 | case spv::BuiltIn::InstanceIndex: |
| 916 | case spv::BuiltIn::PrimitiveId: |
| 917 | case spv::BuiltIn::InvocationId: |
| 918 | case spv::BuiltIn::SubgroupLocalInvocationId: { |
| 919 | analysis::Integer uint_ty(32, false); |
| 920 | reg_type = type_mgr->GetRegisteredType(&uint_ty); |
| 921 | break; |
| 922 | } |
| 923 | case spv::BuiltIn::GlobalInvocationId: |
| 924 | case spv::BuiltIn::LaunchIdNV: { |
| 925 | analysis::Integer uint_ty(32, false); |
| 926 | analysis::Type* reg_uint_ty = type_mgr->GetRegisteredType(&uint_ty); |
| 927 | analysis::Vector v3uint_ty(reg_uint_ty, 3); |
| 928 | reg_type = type_mgr->GetRegisteredType(&v3uint_ty); |
| 929 | break; |
| 930 | } |
| 931 | case spv::BuiltIn::TessCoord: { |
| 932 | analysis::Float float_ty(32); |
| 933 | analysis::Type* reg_float_ty = type_mgr->GetRegisteredType(&float_ty); |
| 934 | analysis::Vector v3float_ty(reg_float_ty, 3); |
| 935 | reg_type = type_mgr->GetRegisteredType(&v3float_ty); |
| 936 | break; |
| 937 | } |
| 938 | case spv::BuiltIn::SubgroupLtMask: { |
| 939 | analysis::Integer uint_ty(32, false); |
| 940 | analysis::Type* reg_uint_ty = type_mgr->GetRegisteredType(&uint_ty); |
| 941 | analysis::Vector v4uint_ty(reg_uint_ty, 4); |
| 942 | reg_type = type_mgr->GetRegisteredType(&v4uint_ty); |
| 943 | break; |
| 944 | } |
| 945 | default: { |
| 946 | assert(false && "unhandled builtin"); |
| 947 | return 0; |
| 948 | } |
| 949 | } |
| 950 | if (reg_type == nullptr) return 0; // Error |
no test coverage detected