Skip to content

Commit d326ece

Browse files
committed
[HLSL][SPIR-V] Implement vk::push_constant
TODO: - get the wg-hlsl proposal accepted. - fill this description. - add tests
1 parent c08644c commit d326ece

26 files changed

+85
-22
lines changed

clang/include/clang/Basic/AddressSpaces.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ enum class LangAS : unsigned {
6262
hlsl_private,
6363
hlsl_device,
6464
hlsl_input,
65+
hlsl_push_constant,
6566

6667
// Wasm specific address spaces.
6768
wasm_funcref,

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5154,6 +5154,14 @@ def HLSLVkExtBuiltinInput : InheritableAttr {
51545154
let Documentation = [HLSLVkExtBuiltinInputDocs];
51555155
}
51565156

5157+
def HLSLVkPushConstant : InheritableAttr {
5158+
let Spellings = [CXX11<"vk", "push_constant">];
5159+
let Args = [];
5160+
let Subjects = SubjectList<[GlobalVar], ErrorDiag>;
5161+
let LangOpts = [HLSL];
5162+
let Documentation = [HLSLVkPushConstantDocs];
5163+
}
5164+
51575165
def HLSLVkConstantId : InheritableAttr {
51585166
let Spellings = [CXX11<"vk", "constant_id">];
51595167
let Args = [IntArgument<"Id">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8838,6 +8838,11 @@ https://github.com/microsoft/hlsl-specs/blob/main/proposals/0011-inline-spirv.md
88388838
}];
88398839
}
88408840

8841+
def HLSLVkPushConstantDocs : Documentation {
8842+
let Category = DocCatVariable;
8843+
let Content = [{ FIXME }];
8844+
}
8845+
88418846
def AnnotateTypeDocs : Documentation {
88428847
let Category = DocCatType;
88438848
let Heading = "annotate_type";

clang/include/clang/Basic/HLSLRuntime.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef CLANG_BASIC_HLSLRUNTIME_H
1515
#define CLANG_BASIC_HLSLRUNTIME_H
1616

17+
#include "clang/Basic/AddressSpaces.h"
1718
#include "clang/Basic/LangOptions.h"
1819
#include <cstdint>
1920

@@ -30,6 +31,10 @@ getStageFromEnvironment(const llvm::Triple::EnvironmentType &E) {
3031
return static_cast<ShaderStage>(Pipeline);
3132
}
3233

34+
constexpr bool isInitializedByPipeline(LangAS AS) {
35+
return AS == LangAS::hlsl_input || AS == LangAS::hlsl_push_constant;
36+
}
37+
3338
#define ENUM_COMPARE_ASSERT(Value) \
3439
static_assert( \
3540
getStageFromEnvironment(llvm::Triple::Value) == ShaderStage::Value, \

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ class SemaHLSL : public SemaBase {
197197
void handleSemanticAttr(Decl *D, const ParsedAttr &AL);
198198

199199
void handleVkExtBuiltinInputAttr(Decl *D, const ParsedAttr &AL);
200+
void handleVkPushConstantAttr(Decl *D, const ParsedAttr &AL);
200201

201202
bool CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall);
202203
QualType ProcessResourceTypeAttributes(QualType Wrapped);

clang/lib/AST/Type.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ bool Qualifiers::isTargetAddressSpaceSupersetOf(LangAS A, LangAS B,
101101
(A == LangAS::Default && B == LangAS::hlsl_private) ||
102102
(A == LangAS::Default && B == LangAS::hlsl_device) ||
103103
(A == LangAS::Default && B == LangAS::hlsl_input) ||
104+
(A == LangAS::Default && B == LangAS::hlsl_push_constant) ||
104105
// Conversions from target specific address spaces may be legal
105106
// depending on the target information.
106107
Ctx.getTargetInfo().isAddressSpaceSupersetOf(A, B);

clang/lib/AST/TypePrinter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2749,6 +2749,8 @@ std::string Qualifiers::getAddrSpaceAsString(LangAS AS) {
27492749
return "hlsl_device";
27502750
case LangAS::hlsl_input:
27512751
return "hlsl_input";
2752+
case LangAS::hlsl_push_constant:
2753+
return "hlsl_push_constant";
27522754
case LangAS::wasm_funcref:
27532755
return "__funcref";
27542756
default:

clang/lib/Basic/TargetInfo.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static const LangASMap FakeAddrSpaceMap = {
5252
15, // hlsl_private
5353
16, // hlsl_device
5454
17, // hlsl_input
55+
18, // hlsl_push_constant
5556
20, // wasm_funcref
5657
};
5758

clang/lib/Basic/Targets/AArch64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static const unsigned ARM64AddrSpaceMap[] = {
4848
0, // hlsl_private
4949
0, // hlsl_device
5050
0, // hlsl_input
51+
0, // hlsl_push_constant
5152
// Wasm address space values for this target are dummy values,
5253
// as it is only enabled for Wasm targets.
5354
20, // wasm_funcref

clang/lib/Basic/Targets/AMDGPU.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsGenMap = {
6363
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_private
6464
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_device
6565
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_input
66+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_push_constant
6667
};
6768

6869
const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
@@ -91,6 +92,7 @@ const LangASMap AMDGPUTargetInfo::AMDGPUDefIsPrivMap = {
9192
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_private
9293
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_device
9394
llvm::AMDGPUAS::PRIVATE_ADDRESS, // hlsl_input
95+
llvm::AMDGPUAS::GLOBAL_ADDRESS, // hlsl_push_constant
9496
};
9597
} // namespace targets
9698
} // namespace clang

0 commit comments

Comments
 (0)