[llvm-branch-commits] [clang] [llvm] [HLSL] Add GetDimensions to Texture2D. (PR #189991)

Helena Kotas via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Apr 2 10:02:51 PDT 2026


================
@@ -475,6 +475,37 @@ static Value *emitHlslClamp(CodeGenFunction &CGF, const CallExpr *E,
   return Clamp;
 }
 
+static Value *emitGetDimensions(CodeGenFunction &CGF, const CallExpr *E,
+                                unsigned IntrinsicID, unsigned NumRetComps,
+                                bool HasLod) {
+  Value *Handle = CGF.EmitScalarExpr(E->getArg(0));
+
+  SmallVector<Value *> Args{Handle};
+  if (HasLod)
+    Args.push_back(CGF.EmitScalarExpr(E->getArg(1)));
+
+  Value *DimValue =
+      CGF.Builder.CreateIntrinsic(IntrinsicID, {Handle->getType()}, Args);
+
+  Value *LastStore = nullptr;
+  unsigned ArgIndex = HasLod ? 2 : 1;
+  for (unsigned i = 0; i < NumRetComps; ++i) {
+    LValue DimOut = CGF.EmitLValue(E->getArg(ArgIndex++));
+    Value *Elem = DimValue;
+    if (NumRetComps > 1)
+      Elem = CGF.Builder.CreateExtractElement(DimValue, i);
+
+    // Handle float casting if needed
+    QualType OutTy = E->getArg(ArgIndex - 1)->getType();
+    if (OutTy->isFloatingType())
----------------
hekota wrote:

Not a fan of `E->getArg(ArgIndex++)` followed by `E->getArg(ArgIndex - 1)`. Consider storing the arg in a local var:
```suggestion
    Expr *Arg = E->getArg(ArgIndex++);
    LValue DimOut = CGF.EmitLValue(Arg);
    Value *Elem = DimValue;
    if (NumRetComps > 1)
      Elem = CGF.Builder.CreateExtractElement(DimValue, i);

    // Handle float casting if needed
    if (Arg->getType()->isFloatingType())
```

https://github.com/llvm/llvm-project/pull/189991


More information about the llvm-branch-commits mailing list