Skip to content

Commit

Permalink
vk namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jaebaek authored and jiaolu committed Nov 24, 2021
1 parent 374b714 commit 1fb3fd3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
3 changes: 3 additions & 0 deletions tools/clang/include/clang/AST/HlslTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ clang::CXXRecordDecl* DeclareTemplateTypeWithHandle(

clang::CXXRecordDecl* DeclareUIntTemplatedTypeWithHandle(
clang::ASTContext& context, llvm::StringRef typeName, llvm::StringRef templateParamName);
clang::CXXRecordDecl *DeclareUIntTemplatedTypeWithHandleInDeclContext(
clang::ASTContext &context, clang::DeclContext *declContext,
llvm::StringRef typeName, llvm::StringRef templateParamName);
clang::CXXRecordDecl *DeclareConstantBufferViewType(clang::ASTContext& context, bool bTBuf);
clang::CXXRecordDecl* DeclareRayQueryType(clang::ASTContext& context);
clang::CXXRecordDecl *DeclareResourceType(clang::ASTContext &context,
Expand Down
9 changes: 8 additions & 1 deletion tools/clang/lib/AST/ASTContextHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,15 @@ CXXMethodDecl* hlsl::CreateObjectFunctionDeclarationWithParams(

CXXRecordDecl* hlsl::DeclareUIntTemplatedTypeWithHandle(
ASTContext& context, StringRef typeName, StringRef templateParamName) {
return DeclareUIntTemplatedTypeWithHandleInDeclContext(
context, context.getTranslationUnitDecl(), typeName, templateParamName);
}

CXXRecordDecl *hlsl::DeclareUIntTemplatedTypeWithHandleInDeclContext(
ASTContext &context, DeclContext *declContext, StringRef typeName,
StringRef templateParamName) {
// template<uint kind> FeedbackTexture2D[Array] { ... }
BuiltinTypeDeclBuilder typeDeclBuilder(context.getTranslationUnitDecl(), typeName);
BuiltinTypeDeclBuilder typeDeclBuilder(declContext, typeName);
typeDeclBuilder.addIntegerTemplateParam(templateParamName, context.UnsignedIntTy);
typeDeclBuilder.startDefinition();
typeDeclBuilder.addField("h", context.UnsignedIntTy); // Add an 'h' field to hold the handle.
Expand Down
20 changes: 13 additions & 7 deletions tools/clang/lib/Sema/SemaHLSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3596,7 +3596,9 @@ class HLSLExternalSource : public ExternalSemaSource {
}
#ifdef ENABLE_SPIRV_CODEGEN
else if (kind == AR_OBJECT_VK_SPV_INTRINSIC_TYPE) {
recordDecl = DeclareUIntTemplatedTypeWithHandle(*m_context, "ext_type", "id");
recordDecl = DeclareUIntTemplatedTypeWithHandleInDeclContext(
*m_context, m_vkNSDecl, typeName, "id");
recordDecl->setImplicit(true);
}
#endif
else if (templateArgCount == 0) {
Expand Down Expand Up @@ -3721,12 +3723,6 @@ class HLSLExternalSource : public ExternalSemaSource {
m_sema = &S;
S.addExternalSource(this);

AddObjectTypes();
AddStdIsEqualImplementation(context, S);
for (auto && intrinsic : m_intrinsicTables) {
AddIntrinsicTableMethods(intrinsic);
}

#ifdef ENABLE_SPIRV_CODEGEN
if (m_sema->getLangOpts().SPIRV) {
// Create the "vk" namespace which contains Vulkan-specific intrinsics.
Expand All @@ -3736,7 +3732,17 @@ class HLSLExternalSource : public ExternalSemaSource {
SourceLocation(), &context.Idents.get("vk"),
/*PrevDecl*/ nullptr);
context.getTranslationUnitDecl()->addDecl(m_vkNSDecl);
}
#endif // ENABLE_SPIRV_CODEGEN

AddObjectTypes();
AddStdIsEqualImplementation(context, S);
for (auto &&intrinsic : m_intrinsicTables) {
AddIntrinsicTableMethods(intrinsic);
}

#ifdef ENABLE_SPIRV_CODEGEN
if (m_sema->getLangOpts().SPIRV) {
// Add Vulkan-specific intrinsics.
AddVkIntrinsicFunctions();
AddVkIntrinsicConstants();
Expand Down
6 changes: 3 additions & 3 deletions tools/clang/test/CodeGenSPIRV/spv.intrinsicTypeInteger.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ void createTypeInt([[vk::ext_literal]] int sizeInBits,
[[vk::ext_literal]] int signedness);

[[vk::ext_type_def(1, 23)]]
void createTypeVector([[vk::ext_reference]] ext_type<0> typeInt,
void createTypeVector([[vk::ext_reference]] vk::ext_type<0> typeInt,
[[vk::ext_literal]] int componentCount);

//CHECK: %spirvIntrinsicType = OpTypeInt 32 0
//CHECK: %spirvIntrinsicType_0 = OpTypeVector %spirvIntrinsicType 4

ext_type<0> foo1;
ext_type<1> foo2;
vk::ext_type<0> foo1;
vk::ext_type<1> foo2;
float main() : SV_Target
{
createTypeInt(32, 0);
Expand Down

0 comments on commit 1fb3fd3

Please sign in to comment.