forked from shader-slang/slang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SPIRV: Fix performance issue when handling large arrays. (shader-slan…
…g#4064) * SPIRV: Fix performance issue when handling large arrays. * Add test for packing. * Fix clang.
- Loading branch information
Showing
8 changed files
with
160 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -profile glsl_460 | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute | ||
|
||
// Check that when generating spirv directly, we use a loop | ||
// to copy large arrays in a local variable to a buffer, instead of emitting | ||
// unrolled code that reads each element of the array individually. | ||
|
||
struct WorkData | ||
{ | ||
int B[1024]; | ||
}; | ||
|
||
//TEST_INPUT:set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4, count=1024) | ||
RWStructuredBuffer<WorkData> resultBuffer; | ||
|
||
// CHECK: OpLoopMerge | ||
// CHECK: OpLoopMerge | ||
|
||
// BUF: 0 | ||
// BUF: 1 | ||
[numthreads(1, 1, 1)] | ||
void computeMain(uint3 tid: SV_DispatchThreadID) | ||
{ | ||
WorkData wd; | ||
for (int i = 0; i < 1024; i++) | ||
wd.B[i] = i; | ||
resultBuffer[0] = wd; | ||
} |
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,20 @@ | ||
//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -profile glsl_460 | ||
|
||
struct WorkData { | ||
float A[2048 * 2048]; | ||
float B[2048 * 2048]; | ||
}; | ||
struct PushData { | ||
WorkData* Input; | ||
float* Dest; | ||
}; | ||
|
||
[vk::push_constant] ConstantBuffer<PushData> cb; | ||
|
||
// CHECK: OpEntryPoint | ||
|
||
[numthreads(64, 1, 1)] | ||
void ComputeMain(uint tid: SV_DispatchThreadID) | ||
{ | ||
cb.Dest[tid] = cb.Input->A[tid] * cb.Input->B[tid]; | ||
} |
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,32 @@ | ||
//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -profile glsl_460 | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -output-using-type | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-d3d12 -compute -output-using-type | ||
//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -output-using-type | ||
|
||
// Check that when generating spirv directly, we use a loop | ||
// to copy large arrays in input data out into a local variable, instead of emitting | ||
// unrolled code that reads each element of the array individually. | ||
|
||
struct WorkData | ||
{ | ||
float A[2*2]; | ||
float B[1024]; | ||
|
||
float Foo(uint i) { return A[i] * B[i]; } | ||
}; | ||
|
||
//TEST_INPUT:set input = new WorkData{[1.0, 2.0, 3.0, 4.0], [10.0, 20.0, 30.0, 40.0]} | ||
ConstantBuffer<WorkData> input; | ||
|
||
//TEST_INPUT:set resultBuffer = out ubuffer(data=[0 0 0 0], stride=4) | ||
RWStructuredBuffer<float> resultBuffer; | ||
|
||
// CHECK: OpLoopMerge | ||
|
||
[numthreads(2, 1, 1)] | ||
void computeMain(uint3 tid: SV_DispatchThreadID) | ||
{ | ||
// BUF: 10.0 | ||
// BUF: 40.0 | ||
resultBuffer[tid.x] = input.Foo(tid.x); | ||
} |
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