Skip to content

Add test for abs #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions test/Feature/HLSLLib/abs.32.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#--- source.hlsl

StructuredBuffer<int4> In1 : register(t0);
StructuredBuffer<uint4> In2 : register(t1);
StructuredBuffer<float4> In3 : register(t2);
RWStructuredBuffer<int4> Out1 : register(u3);
RWStructuredBuffer<uint4> Out2 : register(u4);
RWStructuredBuffer<float4> Out3 : register(u5);

[numthreads(1,1,1)]
void main() {
// int
Out1[0] = abs(In1[0]);
int4 Tmp = {abs(In1[0].xyz), abs(In1[0].w)};
Out1[1] = Tmp;
Out1[2].xy = abs(In1[0].xy);

// uint
Out2[0] = abs(In2[0]);
uint4 Tmp2 = {abs(In2[0].xyz), abs(In2[0].w)};
Out2[1] = Tmp2;
Out2[2].xy = abs(In2[0].xy);

// float
Out3[0] = abs(In3[0]);
float4 Tmp3 = {abs(In3[1].xyz), abs(In3[1].w)};
Out3[1] = Tmp3;
float4 Tmp4 = {abs(In3[2].xy), abs(In3[2].zw)};
Out3[2] = Tmp4;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In1
Format: Int32
Stride: 16
Data: [-1, 0, -2147483648, 2147483647]
- Name: In2
Format: UInt32
Stride: 16
Data: [1, 0xffffffff, 0, 10]
- Name: In3
Format: Float32
Stride: 16
Data: [nan, -nan, 0, -0, -1.3, inf, -inf, 0x1.e7d42cp-127, -0x1.e7d42cp-127, -0.5, -0.05, -19]
- Name: Out1
Format: Int32
Stride: 16
ZeroInitSize: 48
- Name: ExpectedOut1 # The result we expect
Format: Int32
Stride: 16
Data: [1, 0, -2147483648, 2147483647, 1, 0, -2147483648, 2147483647, 1, 0, 0, 0] # Last two are filler
- Name: Out2
Format: UInt32
Stride: 16
ZeroInitSize: 48
- Name: ExpectedOut2 # The result we expect
Format: UInt32
Stride: 16
Data: [1, 4294967295, 0, 10, 1, 4294967295, 0, 10, 1, 4294967295, 0, 0] # Last two are filler
- Name: Out3
Format: Float32
Stride: 16
ZeroInitSize: 48
- Name: ExpectedOut3 # The result we expect
Format: Float32
Stride: 16
Data: [nan, nan, 0, 0, 1.3, inf, inf, 0x1.e7d42cp-127, 0x1.e7d42cp-127, 0.5, 0.05, 19]
Results:
- Result: Test1
Rule: BufferExact
Actual: Out1
Expected: ExpectedOut1
- Result: Test2
Rule: BufferExact
Actual: Out2
Expected: ExpectedOut2
- Result: Test3
Rule: BufferFloatULP
ULPT: 0
Actual: Out3
Expected: ExpectedOut3
DescriptorSets:
- Resources:
- Name: In1
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: In2
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: In3
Kind: StructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Out1
Kind: RWStructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
- Name: Out2
Kind: RWStructuredBuffer
DirectXBinding:
Register: 4
Space: 0
VulkanBinding:
Binding: 4
- Name: Out3
Kind: RWStructuredBuffer
DirectXBinding:
Register: 5
Space: 0
VulkanBinding:
Binding: 5
...
#--- end

# https://github.com/microsoft/DirectXShaderCompiler/issues/7512
# XFAIL: DXC-Vulkan

# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
64 changes: 64 additions & 0 deletions test/Feature/HLSLLib/abs.fp16.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#--- source.hlsl

StructuredBuffer<half4> In1 : register(t0);
RWStructuredBuffer<half4> Out1 : register(u1);

[numthreads(1,1,1)]
void main() {
Out1[0] = abs(In1[0]);
half4 Tmp = {abs(In1[1].xyz), abs(In1[1].w)};
Out1[1] = Tmp;
half4 Tmp2 = {abs(In1[2].xy), abs(In1[2].zw)};
Out1[2] = Tmp2;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In1
Format: Float16
Stride: 8
Data: [0x7e00, 0xfe00, 0x0000, 0x8000, 0xbd33, 0x7c00, 0xfc00, 0x0001, 0x8001, 0xb800, 0xaa66, 0xccc0]
# nan, -nan, 0, -0, -1.3, inf, -inf, denorm, -denorm, -0.5, -0.05, -19
- Name: Out1
Format: Float16
Stride: 8
ZeroInitSize: 24
- Name: ExpectedOut1 # The result we expect
Format: Float16
Stride: 8
Data: [0x7e00, 0x7e00, 0x0000, 0x0000, 0x3d33, 0x7c00, 0x7c00, 0x0001, 0x0001, 0x3800, 0x2a66, 0x4cc0]
Results:
- Result: Test1
Rule: BufferFloatULP
ULPT: 0
Actual: Out1
Expected: ExpectedOut1
DescriptorSets:
- Resources:
- Name: In1
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Out1
Kind: RWStructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
...
#--- end

# REQUIRES: Half
# RUN: split-file %s %t
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
63 changes: 63 additions & 0 deletions test/Feature/HLSLLib/abs.fp64.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#--- source.hlsl

StructuredBuffer<double4> In1 : register(t0);
RWStructuredBuffer<double4> Out1 : register(u1);

[numthreads(1,1,1)]
void main() {
Out1[0] = abs(In1[0]);
double4 Tmp = {abs(In1[1].xyz), abs(In1[1].w)};
Out1[1] = Tmp;
double4 Tmp2 = {abs(In1[2].xy), abs(In1[2].zw)};
Out1[2] = Tmp2;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In1
Format: Float64
Stride: 32
Data: [nan, -nan, 0, -0, -1.3, inf, -inf, 0x0.fffffffffffffp-1022, -0x0.fffffffffffffp-1022, -0.5, -0.05, -19]
- Name: Out1
Format: Float64
Stride: 32
ZeroInitSize: 96
- Name: ExpectedOut1 # The result we expect
Format: Float64
Stride: 32
Data: [nan, nan, 0, 0, 1.3, inf, inf, 0x0.fffffffffffffp-1022, 0x0.fffffffffffffp-1022, 0.5, 0.05, 19]
Results:
- Result: Test1
Rule: BufferFloatULP
ULPT: 0
Actual: Out1
Expected: ExpectedOut1
DescriptorSets:
- Resources:
- Name: In1
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Out1
Kind: RWStructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
...
#--- end

# REQUIRES: Double
# RUN: split-file %s %t
# RUN: %dxc_target -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
103 changes: 103 additions & 0 deletions test/Feature/HLSLLib/abs.int16.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#--- source.hlsl

StructuredBuffer<int16_t4> In1 : register(t0);
StructuredBuffer<uint16_t4> In2 : register(t1);
RWStructuredBuffer<int16_t4> Out1 : register(u2);
RWStructuredBuffer<uint16_t4> Out2 : register(u3);

[numthreads(1,1,1)]
void main() {
// int16_t
Out1[0] = abs(In1[0]);
int16_t4 Tmp = {abs(In1[0].xyz), abs(In1[0].w)};
Out1[1] = Tmp;
Out1[2].xy = abs(In1[0].xy);

// uint16_t
Out2[0] = abs(In2[0]);
uint16_t4 Tmp2 = {abs(In2[0].xyz), abs(In2[0].w)};
Out2[1] = Tmp2;
Out2[2].xy = abs(In2[0].xy);
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: In1
Format: Int16
Stride: 8
Data: [-1, 0, -32768, 32767]
- Name: In2
Format: UInt16
Stride: 8
Data: [1, 65535, 0, 10]
- Name: Out1
Format: Int16
Stride: 8
ZeroInitSize: 24
- Name: ExpectedOut1 # The result we expect
Format: Int16
Stride: 8
Data: [1, 0, -32768, 32767, 1, 0, -32768, 32767, 1, 0, 0, 0] # Last two are filler
- Name: Out2
Format: UInt16
Stride: 8
ZeroInitSize: 24
- Name: ExpectedOut2 # The result we expect
Format: UInt16
Stride: 8
Data: [1, 65535, 0, 10, 1, 65535, 0, 10, 1, 65535, 0, 0] # Last two are filler
Results:
- Result: Test1
Rule: BufferExact
Actual: Out1
Expected: ExpectedOut1
- Result: Test2
Rule: BufferExact
Actual: Out2
Expected: ExpectedOut2
DescriptorSets:
- Resources:
- Name: In1
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: In2
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: Out1
Kind: RWStructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Out2
Kind: RWStructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
...
#--- end

# https://github.com/microsoft/DirectXShaderCompiler/issues/7512
# XFAIL: DXC-Vulkan

# REQUIRES: Int16
# RUN: split-file %s %t
# RUN: %dxc_target -enable-16bit-types -T cs_6_5 -Fo %t.o %t/source.hlsl
# RUN: %offloader %t/pipeline.yaml %t.o
Loading
Loading