|
23 | 23 | #include "clang/AST/RecursiveASTVisitor.h"
|
24 | 24 | #include "clang/AST/Type.h"
|
25 | 25 | #include "clang/Basic/TargetOptions.h"
|
26 |
| -#include "clang/Frontend/FrontendDiagnostic.h" |
27 | 26 | #include "llvm/ADT/SmallString.h"
|
28 | 27 | #include "llvm/ADT/SmallVector.h"
|
29 | 28 | #include "llvm/Frontend/HLSL/RootSignatureMetadata.h"
|
@@ -566,78 +565,47 @@ static llvm::Value *createSPIRVBuiltinLoad(IRBuilder<> &B, llvm::Module &M,
|
566 | 565 | return B.CreateLoad(Ty, GV);
|
567 | 566 | }
|
568 | 567 |
|
569 |
| -llvm::Value * |
570 |
| -CGHLSLRuntime::emitSystemSemanticLoad(IRBuilder<> &B, llvm::Type *Type, |
571 |
| - const clang::DeclaratorDecl *Decl, |
572 |
| - SemanticInfo &ActiveSemantic) { |
573 |
| - if (isa<HLSLSV_GroupIndexAttr>(ActiveSemantic.Semantic)) { |
| 568 | +llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, |
| 569 | + const ParmVarDecl &D, |
| 570 | + llvm::Type *Ty) { |
| 571 | + assert(D.hasAttrs() && "Entry parameter missing annotation attribute!"); |
| 572 | + if (D.hasAttr<HLSLSV_GroupIndexAttr>()) { |
574 | 573 | llvm::Function *GroupIndex =
|
575 | 574 | CGM.getIntrinsic(getFlattenedThreadIdInGroupIntrinsic());
|
576 | 575 | return B.CreateCall(FunctionCallee(GroupIndex));
|
577 | 576 | }
|
578 |
| - |
579 |
| - if (isa<HLSLSV_DispatchThreadIDAttr>(ActiveSemantic.Semantic)) { |
| 577 | + if (D.hasAttr<HLSLSV_DispatchThreadIDAttr>()) { |
580 | 578 | llvm::Intrinsic::ID IntrinID = getThreadIdIntrinsic();
|
581 | 579 | llvm::Function *ThreadIDIntrinsic =
|
582 | 580 | llvm::Intrinsic::isOverloaded(IntrinID)
|
583 | 581 | ? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
|
584 | 582 | : CGM.getIntrinsic(IntrinID);
|
585 |
| - return buildVectorInput(B, ThreadIDIntrinsic, Type); |
| 583 | + return buildVectorInput(B, ThreadIDIntrinsic, Ty); |
586 | 584 | }
|
587 |
| - |
588 |
| - if (isa<HLSLSV_GroupThreadIDAttr>(ActiveSemantic.Semantic)) { |
| 585 | + if (D.hasAttr<HLSLSV_GroupThreadIDAttr>()) { |
589 | 586 | llvm::Intrinsic::ID IntrinID = getGroupThreadIdIntrinsic();
|
590 | 587 | llvm::Function *GroupThreadIDIntrinsic =
|
591 | 588 | llvm::Intrinsic::isOverloaded(IntrinID)
|
592 | 589 | ? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
|
593 | 590 | : CGM.getIntrinsic(IntrinID);
|
594 |
| - return buildVectorInput(B, GroupThreadIDIntrinsic, Type); |
| 591 | + return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); |
595 | 592 | }
|
596 |
| - |
597 |
| - if (isa<HLSLSV_GroupIDAttr>(ActiveSemantic.Semantic)) { |
| 593 | + if (D.hasAttr<HLSLSV_GroupIDAttr>()) { |
598 | 594 | llvm::Intrinsic::ID IntrinID = getGroupIdIntrinsic();
|
599 | 595 | llvm::Function *GroupIDIntrinsic =
|
600 | 596 | llvm::Intrinsic::isOverloaded(IntrinID)
|
601 | 597 | ? CGM.getIntrinsic(IntrinID, {CGM.Int32Ty})
|
602 | 598 | : CGM.getIntrinsic(IntrinID);
|
603 |
| - return buildVectorInput(B, GroupIDIntrinsic, Type); |
604 |
| - } |
605 |
| - |
606 |
| - if (HLSLSV_PositionAttr *S = |
607 |
| - dyn_cast<HLSLSV_PositionAttr>(ActiveSemantic.Semantic)) { |
608 |
| - if (CGM.getTriple().getEnvironment() == Triple::EnvironmentType::Pixel) |
609 |
| - return createSPIRVBuiltinLoad(B, CGM.getModule(), Type, |
610 |
| - S->getAttrName()->getName(), |
611 |
| - /* BuiltIn::FragCoord */ 15); |
| 599 | + return buildVectorInput(B, GroupIDIntrinsic, Ty); |
612 | 600 | }
|
613 |
| - |
614 |
| - llvm_unreachable("non-handled system semantic. FIXME."); |
615 |
| -} |
616 |
| - |
617 |
| -llvm::Value * |
618 |
| -CGHLSLRuntime::handleScalarSemanticLoad(IRBuilder<> &B, llvm::Type *Type, |
619 |
| - const clang::DeclaratorDecl *Decl, |
620 |
| - SemanticInfo &ActiveSemantic) { |
621 |
| - |
622 |
| - if (!ActiveSemantic.Semantic) { |
623 |
| - ActiveSemantic.Semantic = Decl->getAttr<HLSLSemanticAttr>(); |
624 |
| - if (!ActiveSemantic.Semantic) { |
625 |
| - CGM.getDiags().Report(Decl->getInnerLocStart(), |
626 |
| - diag::err_hlsl_semantic_missing); |
627 |
| - return nullptr; |
628 |
| - } |
629 |
| - ActiveSemantic.Index = ActiveSemantic.Semantic->getSemanticIndex(); |
| 601 | + if (D.hasAttr<HLSLSV_PositionAttr>()) { |
| 602 | + if (getArch() == llvm::Triple::spirv) |
| 603 | + return createSPIRVBuiltinLoad(B, CGM.getModule(), Ty, "sv_position", |
| 604 | + /* BuiltIn::Position */ 0); |
| 605 | + llvm_unreachable("SV_Position semantic not implemented for this target."); |
630 | 606 | }
|
631 |
| - |
632 |
| - return emitSystemSemanticLoad(B, Type, Decl, ActiveSemantic); |
633 |
| -} |
634 |
| - |
635 |
| -llvm::Value * |
636 |
| -CGHLSLRuntime::handleSemanticLoad(IRBuilder<> &B, llvm::Type *Type, |
637 |
| - const clang::DeclaratorDecl *Decl, |
638 |
| - SemanticInfo &ActiveSemantic) { |
639 |
| - assert(!Type->isStructTy()); |
640 |
| - return handleScalarSemanticLoad(B, Type, Decl, ActiveSemantic); |
| 607 | + assert(false && "Unhandled parameter attribute"); |
| 608 | + return nullptr; |
641 | 609 | }
|
642 | 610 |
|
643 | 611 | void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
|
@@ -682,10 +650,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
|
682 | 650 | Args.emplace_back(PoisonValue::get(Param.getType()));
|
683 | 651 | continue;
|
684 | 652 | }
|
685 |
| - |
686 | 653 | const ParmVarDecl *PD = FD->getParamDecl(Param.getArgNo() - SRetOffset);
|
687 |
| - SemanticInfo ActiveSemantic = {nullptr, 0}; |
688 |
| - Args.push_back(handleSemanticLoad(B, Param.getType(), PD, ActiveSemantic)); |
| 654 | + Args.push_back(emitInputSemantic(B, *PD, Param.getType())); |
689 | 655 | }
|
690 | 656 |
|
691 | 657 | CallInst *CI = B.CreateCall(FunctionCallee(Fn), Args, OB);
|
|
0 commit comments