From 1fb3fd3b7d53e4a5149f332dd79a6aedf304d1e5 Mon Sep 17 00:00:00 2001 From: Jaebaek Seo Date: Wed, 17 Nov 2021 17:24:03 -0500 Subject: [PATCH] vk namespace --- tools/clang/include/clang/AST/HlslTypes.h | 3 +++ tools/clang/lib/AST/ASTContextHLSL.cpp | 9 ++++++++- tools/clang/lib/Sema/SemaHLSL.cpp | 20 ++++++++++++------- .../spv.intrinsicTypeInteger.hlsl | 6 +++--- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tools/clang/include/clang/AST/HlslTypes.h b/tools/clang/include/clang/AST/HlslTypes.h index 73fd883d0c..9f01dd6183 100644 --- a/tools/clang/include/clang/AST/HlslTypes.h +++ b/tools/clang/include/clang/AST/HlslTypes.h @@ -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, diff --git a/tools/clang/lib/AST/ASTContextHLSL.cpp b/tools/clang/lib/AST/ASTContextHLSL.cpp index 6a6e9a8ded..f849e8ae63 100644 --- a/tools/clang/lib/AST/ASTContextHLSL.cpp +++ b/tools/clang/lib/AST/ASTContextHLSL.cpp @@ -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 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. diff --git a/tools/clang/lib/Sema/SemaHLSL.cpp b/tools/clang/lib/Sema/SemaHLSL.cpp index 8569667da6..a3387173cf 100644 --- a/tools/clang/lib/Sema/SemaHLSL.cpp +++ b/tools/clang/lib/Sema/SemaHLSL.cpp @@ -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) { @@ -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. @@ -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(); diff --git a/tools/clang/test/CodeGenSPIRV/spv.intrinsicTypeInteger.hlsl b/tools/clang/test/CodeGenSPIRV/spv.intrinsicTypeInteger.hlsl index 247f188baf..8f0c5d5431 100644 --- a/tools/clang/test/CodeGenSPIRV/spv.intrinsicTypeInteger.hlsl +++ b/tools/clang/test/CodeGenSPIRV/spv.intrinsicTypeInteger.hlsl @@ -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);