@@ -968,6 +968,15 @@ SpirvInstruction *DeclResultIdMapper::getDeclEvalInfo(const ValueDecl *decl,
968968 /* spvArgs */ {}, /* isInst */ false ,
969969 loc);
970970 }
971+
972+ if (auto *builtinAttr = decl->getAttr <VKExtBuiltinInputAttr>()) {
973+ return getBuiltinVar (spv::BuiltIn (builtinAttr->getBuiltInID ()),
974+ decl->getType (), spv::StorageClass::Input, loc);
975+ } else if (auto *builtinAttr = decl->getAttr <VKExtBuiltinOutputAttr>()) {
976+ return getBuiltinVar (spv::BuiltIn (builtinAttr->getBuiltInID ()),
977+ decl->getType (), spv::StorageClass::Output, loc);
978+ }
979+
971980 if (hlsl::IsHLSLDynamicResourceType (decl->getType ()) ||
972981 hlsl::IsHLSLDynamicSamplerType (decl->getType ())) {
973982 emitError (" HLSL object %0 not yet supported with -spirv" ,
@@ -3808,23 +3817,60 @@ void DeclResultIdMapper::decorateInterpolationMode(
38083817
38093818SpirvVariable *DeclResultIdMapper::getBuiltinVar (spv::BuiltIn builtIn,
38103819 QualType type,
3820+ spv::StorageClass sc,
38113821 SourceLocation loc) {
38123822 // Guarantee uniqueness
38133823 uint32_t spvBuiltinId = static_cast <uint32_t >(builtIn);
38143824 const auto builtInVar = builtinToVarMap.find (spvBuiltinId);
38153825 if (builtInVar != builtinToVarMap.end ()) {
38163826 return builtInVar->second ;
38173827 }
3818- bool mayNeedFlatDecoration = false ;
3828+ switch (builtIn) {
3829+ case spv::BuiltIn::HelperInvocation:
3830+ case spv::BuiltIn::SubgroupSize:
3831+ case spv::BuiltIn::SubgroupLocalInvocationId:
3832+ needsLegalization = true ;
3833+ break ;
3834+ }
3835+
3836+ // Create a dummy StageVar for this builtin variable
3837+ auto var = spvBuilder.addStageBuiltinVar (type, sc, builtIn,
3838+ /* isPrecise*/ false , loc);
3839+
3840+ if (spvContext.isPS () && sc == spv::StorageClass::Input) {
3841+ if (isUintOrVecMatOfUintType (type) || isSintOrVecMatOfSintType (type) ||
3842+ isBoolOrVecMatOfBoolType (type)) {
3843+ spvBuilder.decorateFlat (var, loc);
3844+ }
3845+ }
3846+
3847+ const hlsl::SigPoint *sigPoint =
3848+ hlsl::SigPoint::GetSigPoint (hlsl::SigPointFromInputQual (
3849+ hlsl::DxilParamInputQual::In, spvContext.getCurrentShaderModelKind (),
3850+ /* isPatchConstant=*/ false ));
3851+
3852+ StageVar stageVar (sigPoint, /* semaInfo=*/ {}, /* builtinAttr=*/ nullptr , type,
3853+ /* locAndComponentCount=*/ {0 , 0 , false });
3854+
3855+ stageVar.setIsSpirvBuiltin ();
3856+ stageVar.setSpirvInstr (var);
3857+ stageVars.push_back (stageVar);
3858+
3859+ // Store in map for re-use
3860+ builtinToVarMap[spvBuiltinId] = var;
3861+ return var;
3862+ }
3863+
3864+ SpirvVariable *DeclResultIdMapper::getBuiltinVar (spv::BuiltIn builtIn,
3865+ QualType type,
3866+ SourceLocation loc) {
38193867 spv::StorageClass sc = spv::StorageClass::Max;
3868+
38203869 // Valid builtins supported
38213870 switch (builtIn) {
38223871 case spv::BuiltIn::HelperInvocation:
38233872 case spv::BuiltIn::SubgroupSize:
38243873 case spv::BuiltIn::SubgroupLocalInvocationId:
3825- needsLegalization = true ;
3826- mayNeedFlatDecoration = true ;
3827- LLVM_FALLTHROUGH;
38283874 case spv::BuiltIn::HitTNV:
38293875 case spv::BuiltIn::RayTmaxNV:
38303876 case spv::BuiltIn::RayTminNV:
@@ -3857,32 +3903,11 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
38573903 sc = spv::StorageClass::Output;
38583904 break ;
38593905 default :
3860- assert (false && " unsupported SPIR-V builtin" );
3861- return nullptr ;
3862- }
3863-
3864- // Create a dummy StageVar for this builtin variable
3865- auto var = spvBuilder.addStageBuiltinVar (type, sc, builtIn,
3866- /* isPrecise*/ false , loc);
3867- if (mayNeedFlatDecoration && spvContext.isPS ()) {
3868- spvBuilder.decorateFlat (var, loc);
3906+ assert (false && " cannot infer storage class for SPIR-V builtin" );
3907+ break ;
38693908 }
38703909
3871- const hlsl::SigPoint *sigPoint =
3872- hlsl::SigPoint::GetSigPoint (hlsl::SigPointFromInputQual (
3873- hlsl::DxilParamInputQual::In, spvContext.getCurrentShaderModelKind (),
3874- /* isPatchConstant=*/ false ));
3875-
3876- StageVar stageVar (sigPoint, /* semaInfo=*/ {}, /* builtinAttr=*/ nullptr , type,
3877- /* locAndComponentCount=*/ {0 , 0 , false });
3878-
3879- stageVar.setIsSpirvBuiltin ();
3880- stageVar.setSpirvInstr (var);
3881- stageVars.push_back (stageVar);
3882-
3883- // Store in map for re-use
3884- builtinToVarMap[spvBuiltinId] = var;
3885- return var;
3910+ return getBuiltinVar (builtIn, type, sc, loc);
38863911}
38873912
38883913SpirvVariable *DeclResultIdMapper::createSpirvStageVar (
0 commit comments