Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLSL] CodeGen hlsl cbuffer/tbuffer.
cbuffer A { float a; float b; } will be translated to a global variable. Something like struct CB_Ty { float a; float b; }; CB_Ty A; And all use of a and b will be replaced with A.a and A.b. Only support none-legacy cbuffer layout now. CodeGen for Resource binding will be in separate patch. In the separate patch, resource binding will map the resource information to the global variable. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D130131
- Loading branch information
1 parent
e231a58
commit ebe9c7f
Showing
7 changed files
with
236 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
||
// CHECK: @[[CB:.+]] = external constant { float, double } | ||
cbuffer A : register(b0, space1) { | ||
float a; | ||
double b; | ||
} | ||
|
||
// CHECK: @[[TB:.+]] = external constant { float, double } | ||
tbuffer A : register(t2, space1) { | ||
float c; | ||
double d; | ||
} | ||
|
||
float foo() { | ||
// CHECK: load float, ptr @[[CB]], align 4 | ||
// CHECK: load double, ptr getelementptr inbounds ({ float, double }, ptr @[[CB]], i32 0, i32 1), align 8 | ||
// CHECK: load float, ptr @[[TB]], align 4 | ||
// CHECK: load double, ptr getelementptr inbounds ({ float, double }, ptr @[[TB]], i32 0, i32 1), align 8 | ||
return a + b + c*d; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
||
// Make sure cbuffer inside namespace works. | ||
// CHECK: @[[CB:.+]] = external constant { float } | ||
// CHECK: @[[TB:.+]] = external constant { float } | ||
namespace n0 { | ||
namespace n1 { | ||
cbuffer A { | ||
float a; | ||
} | ||
} | ||
tbuffer B { | ||
float b; | ||
} | ||
} | ||
|
||
float foo() { | ||
// CHECK: load float, ptr @[[CB]], align 4 | ||
// CHECK: load float, ptr @[[TB]], align 4 | ||
return n0::n1::a + n0::b; | ||
} |
18 changes: 18 additions & 0 deletions
18
clang/test/CodeGenHLSL/static_global_and_function_in_cb.hlsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ | ||
// RUN: dxil-pc-shadermodel6.3-library %s \ | ||
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
||
// CHECK-DAG: @[[CB:.+]] = external constant { float } | ||
|
||
cbuffer A { | ||
float a; | ||
// CHECK-DAG:@b = internal global float 3.000000e+00, align 4 | ||
static float b = 3; | ||
// CHECK:load float, ptr @[[CB]], align 4 | ||
// CHECK:load float, ptr @b, align 4 | ||
float foo() { return a + b; } | ||
} | ||
|
||
float bar() { | ||
return foo(); | ||
} |