[llvm-branch-commits] [DXIL][Analysis] Replace #include with forward declaration. NFC (PR #100622)

2024-07-25 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/100622
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Make the DXILResource binding optional. NFC (PR #100623)

2024-07-25 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.

LGTM, makes sense. Weird how github highlights `UniqueID`, maybe it's some sort 
of special keyword? It might be worth renaming, but very small nit.

https://github.com/llvm/llvm-project/pull/100623
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Remove new-pm versions of DXILResource passes. NFC (PR #100698)

2024-07-26 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/100698
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers (PR #100699)

2024-07-26 Thread Joshua Batista via llvm-branch-commits


@@ -331,6 +336,249 @@ std::pair 
ResourceInfo::getAnnotateProps() const {
   return {Word0, Word1};
 }
 
+void ResourceInfo::print(raw_ostream &OS) const {
+  OS << "  Symbol: ";
+  Symbol->printAsOperand(OS);
+  OS << "\n";
+
+  OS << "  Name: \"" << Name << "\"\n"
+ << "  Binding:\n"
+ << "Unique ID: " << Binding.UniqueID << "\n"
+ << "Space: " << Binding.Space << "\n"
+ << "Lower Bound: " << Binding.LowerBound << "\n"
+ << "Size: " << Binding.Size << "\n"
+ << "  Class: " << static_cast(RC) << "\n"
+ << "  Kind: " << static_cast(Kind) << "\n";
+
+  if (isCBuffer()) {
+OS << "  CBuffer size: " << CBufferSize << "\n";
+  } else if (isSampler()) {
+OS << "  Sampler Type: " << static_cast(SamplerTy) << "\n";
+  } else {
+if (isUAV()) {
+  OS << "  Globally Coherent: " << UAVFlags.GloballyCoherent << "\n"
+ << "  HasCounter: " << UAVFlags.HasCounter << "\n"
+ << "  IsROV: " << UAVFlags.IsROV << "\n";
+}
+if (isMultiSample())
+  OS << "  Sample Count: " << MultiSample.Count << "\n";
+
+if (isStruct()) {
+  OS << "  Buffer Stride: " << Struct.Stride << "\n";
+  uint32_t AlignLog2 = Struct.Alignment ? Log2(*Struct.Alignment) : 0;
+  OS << "  Alignment: " << AlignLog2 << "\n";
+} else if (isTyped()) {
+  OS << "  Element Type: " << static_cast(Typed.ElementTy) << 
"\n"
+ << "  Element Count: " << static_cast(Typed.ElementCount)
+ << "\n";
+} else if (isFeedback())
+  OS << "  Feedback Type: " << static_cast(Feedback.Type) << 
"\n";
+  }
+}
+
+//===--===//
+// ResourceMapper
+
+static dxil::ElementType toDXILElementType(Type *Ty, bool IsSigned) {
+  // TODO: Handle unorm, snorm, and packed.
+  Ty = Ty->getScalarType();

bob80905 wrote:

Could this return a nullptr?

https://github.com/llvm/llvm-project/pull/100699
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [DirectX] Lower `@llvm.dx.handle.fromBinding` to DXIL ops (PR #104251)

2024-08-21 Thread Joshua Batista via llvm-branch-commits


@@ -117,6 +119,10 @@ class ResourceInfo {
 
   MSInfo MultiSample;
 
+  // We need a default constructor if we want to insert this in a MapVector.
+  ResourceInfo() {}
+  friend class MapVector;

bob80905 wrote:

Where is this being inserted in a MapVector? Is it DRM?

https://github.com/llvm/llvm-project/pull/104251
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] a3490e3 - add floor library function

2022-12-05 Thread Joshua Batista via llvm-branch-commits

Author: Joshua Batista
Date: 2022-12-01T12:36:14-08:00
New Revision: a3490e31eb3a56cef42c8179caecfe031f0432d1

URL: 
https://github.com/llvm/llvm-project/commit/a3490e31eb3a56cef42c8179caecfe031f0432d1
DIFF: 
https://github.com/llvm/llvm-project/commit/a3490e31eb3a56cef42c8179caecfe031f0432d1.diff

LOG: add floor library function

This change exposes the floor library function for HLSL,
excluding long, int, and long long doubles.
Floor is supported for all scalar, vector, and matrix types.

Long and long long double support is missing in this patch because those types
don't exist in HLSL. Int is missing because the floor function only works on 
floating type arguments.

The full documentation of the HLSL floor function is available here:
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-floor

Differential Revision: https://reviews.llvm.org/D139137

Added: 
clang/test/CodeGenHLSL/builtins/floor.hlsl

Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index 35891d80d5953..d48f12b472054 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -101,6 +101,35 @@ double3 ceil(double3);
 __attribute__((clang_builtin_alias(__builtin_elementwise_ceil)))
 double4 ceil(double4);
 
+// floor builtins
+#ifdef __HLSL_ENABLE_16_BIT
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) half 
floor(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half2 floor(half2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half3 floor(half3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half4 floor(half4);
+#endif
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) float
+floor(float);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float2 floor(float2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float3 floor(float3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+float4 floor(float4);
+
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) double
+floor(double);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double2 floor(double2);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double3 floor(double3);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+double4 floor(double4);
+
 // cos builtins
 #ifdef __HLSL_ENABLE_16_BIT
 __attribute__((clang_builtin_alias(__builtin_elementwise_cos))) half cos(half);

diff  --git a/clang/test/CodeGenHLSL/builtins/floor.hlsl 
b/clang/test/CodeGenHLSL/builtins/floor.hlsl
new file mode 100644
index 0..38834a146206f
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/floor.hlsl
@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -fnative-half-type \
+// RUN:   -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \
+// RUN:   -D__HLSL_ENABLE_16_BIT -o - | FileCheck %s --check-prefix=NO_HALF
+
+using hlsl::floor;
+
+// CHECK: define noundef half @
+// CHECK: call half @llvm.floor.f16(
+// NO_HALF: define noundef float @"?test_floor_half@@YA$halff@$halff@@Z"(
+// NO_HALF: call float @llvm.floor.f32(float %0)
+half test_floor_half ( half p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <2 x half> @
+// CHECK: call <2 x half> @llvm.floor.v2f16(
+// NO_HALF: define noundef <2 x float> 
@"?test_floor_half2@@YAT?$__vector@$halff@$01@__clang@@T12@@Z"(
+// NO_HALF: call <2 x float> @llvm.floor.v2f32(
+half2 test_floor_half2 ( half2 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <3 x half> @
+// CHECK: call <3 x half> @llvm.floor.v3f16(
+// NO_HALF: define noundef <3 x float> 
@"?test_floor_half3@@YAT?$__vector@$halff@$02@__clang@@T12@@Z"(
+// NO_HALF: call <3 x float> @llvm.floor.v3f32(
+half3 test_floor_half3 ( half3 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <4 x half> @
+// CHECK: call <4 x half> @llvm.floor.v4f16(
+// NO_HALF: define noundef <4 x float> 
@"?test_floor_half4@@YAT?$__vector@$halff@$03@__clang@@T12@@Z"(
+// NO_HALF: call <4 x float> @llvm.floor.v4f32(
+half4 test_floor_half4 ( half4 p0 ) {
+  return floor ( p0 );
+}
+
+// CHECK: define noundef float @
+// CHECK: call float @llvm.floor.f32(
+float test_floor_float ( float p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <2 x float> @
+// CHECK: call <2 x float> @llvm.floor.v2f32(
+float2 test_floor_float2 ( float2 p0 ) {
+  return floor ( p0 );
+}
+// CHECK: define noundef <3 x float> @
+// CHECK: call <3 x float> @llvm.floor.v3f32(

[llvm-branch-commits] [clang] d1d10c0 - update with clang format

2022-12-05 Thread Joshua Batista via llvm-branch-commits

Author: Joshua Batista
Date: 2022-12-05T13:06:18-08:00
New Revision: d1d10c03116766fcd983d42f8d1275b0bc4b8508

URL: 
https://github.com/llvm/llvm-project/commit/d1d10c03116766fcd983d42f8d1275b0bc4b8508
DIFF: 
https://github.com/llvm/llvm-project/commit/d1d10c03116766fcd983d42f8d1275b0bc4b8508.diff

LOG: update with clang format

Added: 


Modified: 
clang/lib/Headers/hlsl/hlsl_intrinsics.h

Removed: 




diff  --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index d48f12b472054..e5a6869e625ab 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -103,7 +103,8 @@ double4 ceil(double4);
 
 // floor builtins
 #ifdef __HLSL_ENABLE_16_BIT
-__attribute__((clang_builtin_alias(__builtin_elementwise_floor))) half 
floor(half);
+__attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
+half floor(half);
 __attribute__((clang_builtin_alias(__builtin_elementwise_floor)))
 half2 floor(half2);
 __attribute__((clang_builtin_alias(__builtin_elementwise_floor)))



___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

2025-03-07 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/130338
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

2025-03-07 Thread Joshua Batista via llvm-branch-commits


@@ -125,15 +125,6 @@ class CGHLSLRuntime {
   // End of reserved area for HLSL intrinsic getters.
   
//===--===//
 
-  struct BufferResBinding {

bob80905 wrote:

May I ask how the buffer register number `2` is being stored when this goes 
away? 

https://github.com/llvm/llvm-project/pull/130338
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL] Remove old resource annotations (PR #130338)

2025-03-07 Thread Joshua Batista via llvm-branch-commits


@@ -11,59 +11,9 @@
 
//===--===//
 
 #include "llvm/Frontend/HLSL/HLSLResource.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/Metadata.h"
 
 using namespace llvm;
 using namespace llvm::hlsl;
 
-GlobalVariable *FrontendResource::getGlobalVariable() {
-  return cast(
-  cast(Entry->getOperand(0))->getValue());
-}
-
-ResourceKind FrontendResource::getResourceKind() {
-  return static_cast(
-  cast(
-  cast(Entry->getOperand(1))->getValue())
-  ->getLimitedValue());
-}
-ElementType FrontendResource::getElementType() {
-  return static_cast(
-  cast(
-  cast(Entry->getOperand(2))->getValue())
-  ->getLimitedValue());
-}
-bool FrontendResource::getIsROV() {
-  return cast(
- cast(Entry->getOperand(3))->getValue())
-  ->getLimitedValue();
-}
-uint32_t FrontendResource::getResourceIndex() {
-  return cast(
- cast(Entry->getOperand(4))->getValue())
-  ->getLimitedValue();
-}
-uint32_t FrontendResource::getSpace() {
-  return cast(
- cast(Entry->getOperand(5))->getValue())
-  ->getLimitedValue();
-}
-
-FrontendResource::FrontendResource(MDNode *E) : Entry(E) {
-  assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");
-}
-
-FrontendResource::FrontendResource(GlobalVariable *GV, ResourceKind RK,
-   ElementType ElTy, bool IsROV,
-   uint32_t ResIndex, uint32_t Space) {
-  auto &Ctx = GV->getContext();
-  IRBuilder<> B(Ctx);
-  Entry = MDNode::get(
-  Ctx, {ValueAsMetadata::get(GV),
-ConstantAsMetadata::get(B.getInt32(static_cast(RK))),
-ConstantAsMetadata::get(B.getInt32(static_cast(ElTy))),
-ConstantAsMetadata::get(B.getInt1(IsROV)),
-ConstantAsMetadata::get(B.getInt32(ResIndex)),
-ConstantAsMetadata::get(B.getInt32(Space))});
-}
+// Intentionally empty; this file can be removed when more cpp files are added

bob80905 wrote:

Would you mind explaining why more cpp files being added later justifies the 
removal of this file later instead of now?
Is it because it's more convenient to unlink this file from the cmakelists when 
adding new cpp files and the cmakelists needs to be updated anyways?

https://github.com/llvm/llvm-project/pull/130338
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Remove DXILResourceMDAnalysis (PR #130323)

2025-03-07 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 commented:

LGTM. I'll leave the approval to someone with more expertise.

https://github.com/llvm/llvm-project/pull/130323
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Joshua Batista via llvm-branch-commits


@@ -0,0 +1,108 @@
+//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects
+//--===//
+//
+// 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
+//
+//===--===//
+///
+/// \file This file contains helpers for working with HLSL Root Signatures.
+///
+//===--===//
+
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+namespace llvm {
+namespace hlsl {
+namespace rootsig {
+
+// Static helper functions
+
+static MDString *ClauseTypeToName(LLVMContext &Ctx, ClauseType Type) {
+  StringRef Name;
+  switch (Type) {
+  case ClauseType::CBuffer:
+Name = "CBV";
+break;
+  case ClauseType::SRV:
+Name = "SRV";
+break;
+  case ClauseType::UAV:
+Name = "UAV";
+break;
+  case ClauseType::Sampler:
+Name = "Sampler";
+break;
+  }
+  return MDString::get(Ctx, Name);
+}
+
+// Helper struct so that we can use the overloaded notation of std::visit
+template  struct OverloadBuilds : Ts... {
+  using Ts::operator()...;
+};
+template  OverloadBuilds(Ts...) -> OverloadBuilds;
+
+MDNode *MetadataBuilder::BuildRootSignature() {
+  for (const RootElement &Element : Elements) {
+MDNode *ElementMD =
+std::visit(OverloadBuilds{
+   [&](DescriptorTable Table) -> MDNode * {
+ return BuildDescriptorTable(Table);
+   },
+   [&](DescriptorTableClause Clause) -> MDNode * {
+ return BuildDescriptorTableClause(Clause);
+   },
+   },
+   Element);
+GeneratedMetadata.push_back(ElementMD);
+  }
+
+  return MDNode::get(Ctx, GeneratedMetadata);
+}
+
+MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
+  IRBuilder<> B(Ctx);
+  SmallVector TableOperands;
+  // Set the mandatory arguments
+  TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
+  TableOperands.push_back(ConstantAsMetadata::get(
+  B.getInt32(llvm::to_underlying(Table.Visibility;
+
+  // Remaining operands are references to the table's clauses. The in-memory

bob80905 wrote:

Very helpful 👍

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.

Just a nit but this looks good to me

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-03-05 Thread Joshua Batista via llvm-branch-commits


@@ -0,0 +1,108 @@
+//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects
+//--===//
+//
+// 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
+//
+//===--===//
+///
+/// \file This file contains helpers for working with HLSL Root Signatures.
+///
+//===--===//
+
+#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
+#include "llvm/IR/IRBuilder.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+namespace llvm {
+namespace hlsl {
+namespace rootsig {
+
+// Static helper functions
+
+static MDString *ClauseTypeToName(LLVMContext &Ctx, ClauseType Type) {
+  StringRef Name;
+  switch (Type) {
+  case ClauseType::CBuffer:
+Name = "CBV";
+break;
+  case ClauseType::SRV:
+Name = "SRV";
+break;
+  case ClauseType::UAV:
+Name = "UAV";
+break;
+  case ClauseType::Sampler:
+Name = "Sampler";
+break;
+  }
+  return MDString::get(Ctx, Name);
+}
+
+// Helper struct so that we can use the overloaded notation of std::visit
+template  struct OverloadBuilds : Ts... {
+  using Ts::operator()...;
+};
+template  OverloadBuilds(Ts...) -> OverloadBuilds;
+
+MDNode *MetadataBuilder::BuildRootSignature() {
+  for (const RootElement &Element : Elements) {
+MDNode *ElementMD =
+std::visit(OverloadBuilds{

bob80905 wrote:

Could you add a comment here for clarity?
Something like "for each element, if it's a desctable, run this, if its a 
desctableclause, run this"
Had to look up what std::visit does to understand this.

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)

2025-02-26 Thread Joshua Batista via llvm-branch-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -emit-llvm -o - %s | 
FileCheck %s
+
+// CHECK-DAG: ![[#EMPTY:]] = !{}
+[shader("compute"), RootSignature("")]
+[numthreads(1,1,1)]
+void FirstEntry() {}
+
+// CHECK-DAG: ![[#CBV:]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4}

bob80905 wrote:

Are these guaranteed to be differently ordered in each execution? Are these 
stored in a map? Any way to get these checks to not use DAG?

https://github.com/llvm/llvm-project/pull/125131
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Gather resource names in DXIL resource analysis (PR #140633)

2025-05-19 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.


https://github.com/llvm/llvm-project/pull/140633
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [llvm] [DirectX] Use resource names when generating DXIL metadata (PR #140635)

2025-05-19 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/140635
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 edited 
https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits

https://github.com/bob80905 commented:

I see your test case for UAV, and if I understand correctly, the second test 
file you added might be testing the Constants32Bit.
Is there an existing test for the Descriptor table overlapping case?

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits


@@ -312,21 +399,22 @@ static void reportErrors(Module &M, DXILResourceMap &DRM,
"DXILResourceImplicitBinding pass");
 
   if (auto RSD = getRootSignature(RSBI, MMI)) {
-
-llvm::hlsl::rootsig::RootSignatureBindingValidation Validation =
-initRSBindingValidation(*RSD, tripleToVisibility(MMI.ShaderProfile));
-
-reportUnboundRegisters(M, Validation, ResourceClass::CBuffer,
-   DRM.cbuffers());
-reportUnboundRegisters(M, Validation, ResourceClass::UAV, DRM.uavs());
-reportUnboundRegisters(M, Validation, ResourceClass::Sampler,
-   DRM.samplers());
-reportUnboundRegisters(M, Validation, ResourceClass::SRV, DRM.srvs());
-
-reportInvalidHandleTy(M, DRM.cbuffers());
-reportInvalidHandleTy(M, DRM.srvs());
-reportInvalidHandleTy(M, DRM.uavs());
-reportInvalidHandleTy(M, DRM.samplers());
+if (!reportOverlappingRanges(M, *RSD)) {

bob80905 wrote:

Why do the subsequent checks depend on this condition? Is it possible to report 
this and then unconditionally report the rest of the possible errors?

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits


@@ -13,7 +13,7 @@
 define void @CSMain() "hlsl.shader"="compute" {
 entry:
 
-  %TB =  tail call target("dx.Texture", float, 1, 0, 0) 
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0_0t(i32 0, i32 0, 
i32 1, i32 0, i1 false, ptr nonnull @TB.str)
+  %TB =  tail call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.resource.handlefrombinding.tdx.TypedBuffer_f32_1_0_0t(i32 0, i32 0, 
i32 1, i32 0, i1 false, ptr nonnull @TB.str)

bob80905 wrote:

Why did this change?

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits


@@ -260,6 +260,93 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
   return RootSigDesc;
 }
 
+static void
+reportOverlappingRegisters(Module &M,
+   llvm::hlsl::rootsig::OverlappingRanges Overlap) {
+  const llvm::hlsl::rootsig::RangeInfo *Info = Overlap.A;
+  const llvm::hlsl::rootsig::RangeInfo *OInfo = Overlap.B;
+  SmallString<128> Message;
+  raw_svector_ostream OS(Message);
+  OS << "register " << ResourceClassToString(Info->Class)
+ << " (space=" << Info->Space << ", register=" << Info->LowerBound << ")"
+ << " is overlapping with"
+ << " register " << ResourceClassToString(OInfo->Class)
+ << " (space=" << OInfo->Space << ", register=" << OInfo->LowerBound << ")"
+ << ", verify your root signature definition";
+
+  M.getContext().diagnose(DiagnosticInfoGeneric(Message));
+}
+
+static bool reportOverlappingRanges(Module &M,
+const mcdxbc::RootSignatureDesc &RSD) {
+  using namespace llvm::hlsl::rootsig;
+
+  llvm::SmallVector Infos;
+
+  for (size_t I = 0; I < RSD.ParametersContainer.size(); I++) {
+const auto &[Type, Loc] =
+RSD.ParametersContainer.getTypeAndLocForParameter(I);
+const auto &Header = RSD.ParametersContainer.getHeader(I);
+switch (Type) {
+case llvm::to_underlying(dxbc::RootParameterType::Constants32Bit): {
+  dxbc::RTS0::v1::RootConstants Const =
+  RSD.ParametersContainer.getConstant(Loc);
+
+  RangeInfo Info;
+  Info.Space = Const.RegisterSpace;
+  Info.LowerBound = Const.ShaderRegister;
+  Info.UpperBound = Info.LowerBound;
+  Info.Class = ParameterToResourceClass(Type);
+  Info.Visibility = (dxbc::ShaderVisibility)Header.ShaderVisibility;
+
+  Infos.push_back(Info);
+  break;
+}
+case llvm::to_underlying(dxbc::RootParameterType::SRV):
+case llvm::to_underlying(dxbc::RootParameterType::UAV):
+case llvm::to_underlying(dxbc::RootParameterType::CBV): {
+  dxbc::RTS0::v2::RootDescriptor Desc =
+  RSD.ParametersContainer.getRootDescriptor(Loc);
+
+  RangeInfo Info;
+  Info.Space = Desc.RegisterSpace;
+  Info.LowerBound = Desc.ShaderRegister;
+  Info.UpperBound = Info.LowerBound;
+  Info.Class = ParameterToResourceClass(Type);
+  Info.Visibility = (dxbc::ShaderVisibility)Header.ShaderVisibility;
+
+  Infos.push_back(Info);
+  break;
+}
+case llvm::to_underlying(dxbc::RootParameterType::DescriptorTable): {
+  const mcdxbc::DescriptorTable &Table =
+  RSD.ParametersContainer.getDescriptorTable(Loc);
+
+  for (const dxbc::RTS0::v2::DescriptorRange &Range : Table.Ranges) {
+RangeInfo Info;
+Info.Space = Range.RegisterSpace;
+Info.LowerBound = Range.BaseShaderRegister;
+Info.UpperBound = Info.LowerBound + ((Range.NumDescriptors == ~0U)
+ ? Range.NumDescriptors
+ : Range.NumDescriptors - 1);
+Info.Visibility = (dxbc::ShaderVisibility)Header.ShaderVisibility;
+Info.Class = RangeToResourceClass(Range.RangeType);

bob80905 wrote:

Nit: it looks like class should be assigned before visibility for consistency

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits


@@ -260,6 +260,93 @@ getRootSignature(RootSignatureBindingInfo &RSBI,
   return RootSigDesc;
 }
 
+static void
+reportOverlappingRegisters(Module &M,
+   llvm::hlsl::rootsig::OverlappingRanges Overlap) {
+  const llvm::hlsl::rootsig::RangeInfo *Info = Overlap.A;
+  const llvm::hlsl::rootsig::RangeInfo *OInfo = Overlap.B;
+  SmallString<128> Message;
+  raw_svector_ostream OS(Message);
+  OS << "register " << ResourceClassToString(Info->Class)
+ << " (space=" << Info->Space << ", register=" << Info->LowerBound << ")"
+ << " is overlapping with"
+ << " register " << ResourceClassToString(OInfo->Class)
+ << " (space=" << OInfo->Space << ", register=" << OInfo->LowerBound << ")"
+ << ", verify your root signature definition";

bob80905 wrote:

Nit: you might reference other diagnostics, but I think diagnostics should end 
with punctuation

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [llvm] [DirectX] Add Range Overlap validation to `DXILPostOptimizationValidation.cpp` (PR #148919)

2025-07-17 Thread Joshua Batista via llvm-branch-commits


@@ -0,0 +1,15 @@
+; RUN: not opt -S -passes='dxil-post-optimization-validation' 
-mtriple=dxil-pc-shadermodel6.6-compute %s 2>&1 | FileCheck %s
+; CHECK: error: register CBuffer (space=0, register=0) is overlapping with 
register CBuffer (space=0, register=2), verify your root signature definition
+
+define void @CSMain() "hlsl.shader"="compute" {
+entry:
+  ret void
+}
+
+; RootConstants(num32BitConstants=4, b2), DescriptorTable(CBV(b10, 
numDescriptors=3))

bob80905 wrote:

Is this comment correct? I don't see the conflict that is happening based on 
this root signature

https://github.com/llvm/llvm-project/pull/148919
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits