-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HLSL] Generate buffer subscript operators
In HLSL buffer types support array subscripting syntax for loads and stores. This change fleshes out the subscript operators to become array accesses on the underlying handle pointer. This will allow LLVM optimization passes to optimize resource accesses the same way any other memory access would be optimized. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131268
- Loading branch information
1 parent
055721f
commit 00ecacc
Showing
4 changed files
with
158 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s | ||
|
||
const RWBuffer<float> In; | ||
RWBuffer<float> Out; | ||
|
||
void fn(int Idx) { | ||
Out[Idx] = In[Idx]; | ||
} | ||
|
||
// This test is intended to verify reasonable code generation of the subscript | ||
// operator. In this test case we should be generating both the const and | ||
// non-const operators so we verify both cases. | ||
|
||
// Non-const comes first. | ||
// CHECK: ptr @"??A?$RWBuffer@M@hlsl@@QBAAAMI@Z" | ||
// CHECK: %this1 = load ptr, ptr %this.addr, align 4 | ||
// CHECK-NEXT: %h = getelementptr inbounds %"class.hlsl::RWBuffer", ptr %this1, i32 0, i32 0 | ||
// CHECK-NEXT: %0 = load ptr, ptr %h, align 4 | ||
// CHECK-NEXT: %1 = load i32, ptr %Idx.addr, align 4 | ||
// CHECK-NEXT: %arrayidx = getelementptr inbounds float, ptr %0, i32 %1 | ||
// CHECK-NEXT: ret ptr %arrayidx | ||
|
||
// Const comes next, and returns the pointer instead of the value. | ||
// CHECK: ptr @"??A?$RWBuffer@M@hlsl@@QAAAAMI@Z" | ||
// CHECK: %this1 = load ptr, ptr %this.addr, align 4 | ||
// CHECK-NEXT: %h = getelementptr inbounds %"class.hlsl::RWBuffer", ptr %this1, i32 0, i32 0 | ||
// CHECK-NEXT: %0 = load ptr, ptr %h, align 4 | ||
// CHECK-NEXT: %1 = load i32, ptr %Idx.addr, align 4 | ||
// CHECK-NEXT: %arrayidx = getelementptr inbounds float, ptr %0, i32 %1 | ||
// CHECK-NEXT: ret ptr %arrayidx |