[clang] [HLSL][NFC] Add helper struct to simplify dealing with resource binding attributes (PR #161254)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 30 14:24:15 PDT 2025
================
@@ -0,0 +1,75 @@
+//===- HLSLResource.h - Routines for HLSL resources and bindings ----------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file provides shared routines to help analyze HLSL resources and
+// theirs bindings during Sema and CodeGen.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_AST_HLSLRESOURCE_H
+#define LLVM_CLANG_AST_HLSLRESOURCE_H
+
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Attrs.inc"
+#include "clang/AST/DeclBase.h"
+#include "clang/Basic/TargetInfo.h"
+
+namespace clang {
+
+class HLSLResourceBindingAttr;
+class HLSLRVkBindingAttr;
+
+namespace hlsl {
+
+struct ResourceBindingAttrs {
+ HLSLResourceBindingAttr *RegBinding;
+ HLSLVkBindingAttr *VkBinding;
+
+ ResourceBindingAttrs(const Decl *D) {
+ RegBinding = D->getAttr<HLSLResourceBindingAttr>();
+ bool IsSpirv = D->getASTContext().getTargetInfo().getTriple().isSPIRV();
+ VkBinding = IsSpirv ? D->getAttr<HLSLVkBindingAttr>() : nullptr;
----------------
hekota wrote:
There can still be `[[vk::binding]]` attribute in HLSL that is compiled for DirectX and we need to handle that.
BTW SemaHLSL currently does not add the parsed attribute to the AST if the target is DirectX, which is not correct. The attribute needs to be preserved in the AST as is even if it is not used for rewriter scenarios. I will fix that in a follow-up PR.
https://github.com/llvm/llvm-project/pull/161254
More information about the cfe-commits
mailing list