Skip to content
Merged
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
191 changes: 191 additions & 0 deletions test/Feature/HLSLLib/reflect.16.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#--- source.hlsl

// This test tests three different reflection scenarios
// One in 2D, 3D, and 4D

StructuredBuffer<half2> IncidentRay2D : register(t0);
StructuredBuffer<half4> IncidentRay3D : register(t1);
StructuredBuffer<half4> IncidentRay4D : register(t2);
StructuredBuffer<half2> Wall2D : register(t3);
StructuredBuffer<half4> Wall3D : register(t4);
StructuredBuffer<half4> Wall4D : register(t5);
RWStructuredBuffer<half2> Result2D : register(u6);
RWStructuredBuffer<half4> Result3D : register(u7);
RWStructuredBuffer<half4> Result4D : register(u8);

[numthreads(1,1,1)]
void main() {
// 2D case
half2 result2D = reflect(IncidentRay2D[0].xy, normalize(Wall2D[0].xy));
Result2D[0] = result2D;
half2 result2D_constant = reflect(half2(0.75, -0.5), half2(0.70710677, 0.70710677));
Result2D[1] = result2D_constant;

// 3D case, using half4 for alignment
half4 result3D = half4(reflect(IncidentRay3D[0].xyz, normalize(Wall3D[0].xyz)), 0.0);
Result3D[0] = result3D;
half4 result3D_constant = half4(reflect(half3(0.5, -0.25, 0.75), half3(0.5, 0.5, 0.70710677)), 0.0);
Result3D[1] = result3D_constant;

// 4D case
half4 result4D = reflect(IncidentRay4D[0].xyzw, normalize(Wall4D[0].xyzw));
Result4D[0] = result4D;
half4 result4D_constant = reflect(half4(0.5, -0.25, 0.75, -0.5), half4(0.5, 0.5, 0.5, 0.5));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all the values that are used in this test (and all others) are exactly representable in IEE 754. Should we have an extra test that uses values that will be rounded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.70710677 gets rounded to 0.70703125 in the 3D test. Does that resolve your concern?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that works

Result4D[1] = result4D_constant;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:

- Name: IncidentRay2D
Format: Float16
Stride: 4
Data: [ 0x3a00, 0xb800 ]
# 0.75, -0.5
- Name: IncidentRay3D
Format: Float16
Stride: 8
Data: [ 0x3800, 0xb400, 0x3a00, 0x0000 ]
# 0.5, -0.25, 0.75, 0.0
- Name: IncidentRay4D
Format: Float16
Stride: 8
Data: [ 0x3800, 0xb400, 0x3a00, 0xb800 ]
# 0.5, -0.25, 0.75, 0.0
- Name: Wall2D
Format: Float16
Stride: 4
Data: [ 0x39a8, 0x39a8 ]
# 0.70703125, 0.70703125
- Name: Wall3D
Format: Float16
Stride: 8
Data: [ 0x3800, 0x3800, 0x39a8, 0x0000 ]
# 0.5, 0.5, 0.70703125, 0.0
- Name: Wall4D
Format: Float16
Stride: 8
Data: [ 0x3800, 0x3800, 0x3800, 0x3800 ]
# 0.5, 0.5, 0.5, 0.5
- Name: Result2D
Format: Float16
Stride: 4
ZeroInitSize: 8
- Name: ExpectedResult2D
Format: Float16
Stride: 4
Data: [ 0x3800, 0xba00, 0x3800, 0xba00 ]
# 0.5, -0.75, 0.5, -0.75
- Name: Result3D
Format: Float16
Stride: 8
ZeroInitSize: 16
- Name: ExpectedResult3D
Format: Float16
Stride: 8
Data: [ 0xb0f8, 0xbb3e, 0xb1a8, 0x0000, 0xb0f8, 0xbb3e, 0xb1a8, 0x0000 ]
# -0.15527344, -0.90527344, -0.17675781, 0.0, -0.15527344, -0.90527344, -0.17675781, 0.0
- Name: Result4D
Format: Float16
Stride: 8
ZeroInitSize: 16
- Name: ExpectedResult4D
Format: Float16
Stride: 8
Data: [ 0x3400, 0xb800, 0x3800, 0xba00, 0x3400, 0xb800, 0x3800, 0xba00 ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we annotate what the decimal values are for these (and elsewhere)

# 0.25, -0.5, 0.5, -0.75, 0.25, -0.5, 0.5, -0.75
Results:
- Result: CheckResult2D
Rule: BufferFloatULP
ULPT: 1
Actual: Result2D
Expected: ExpectedResult2D
- Result: CheckResult3D
Rule: BufferFloatULP
ULPT: 1
Actual: Result3D
Expected: ExpectedResult3D
- Result: CheckResult4D
Rule: BufferFloatULP
ULPT: 1
Actual: Result4D
Expected: ExpectedResult4D

DescriptorSets:
- Resources:
- Name: IncidentRay2D
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: IncidentRay3D
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: IncidentRay4D
Kind: StructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Wall2D
Kind: StructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
- Name: Wall3D
Kind: StructuredBuffer
DirectXBinding:
Register: 4
Space: 0
VulkanBinding:
Binding: 4
- Name: Wall4D
Kind: StructuredBuffer
DirectXBinding:
Register: 5
Space: 0
VulkanBinding:
Binding: 5
- Name: Result2D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 6
Space: 0
VulkanBinding:
Binding: 6
- Name: Result3D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 7
Space: 0
VulkanBinding:
Binding: 7
- Name: Result4D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 8
Space: 0
VulkanBinding:
Binding: 8
...
#--- end
# UNSUPPORTED: Clang-Vulkan

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

// This test tests three different reflection scenarios
// One in 2D, 3D, and 4D

StructuredBuffer<float2> IncidentRay2D : register(t0);
StructuredBuffer<float4> IncidentRay3D : register(t1);
StructuredBuffer<float4> IncidentRay4D : register(t2);
StructuredBuffer<float2> Wall2D : register(t3);
StructuredBuffer<float4> Wall3D : register(t4);
StructuredBuffer<float4> Wall4D : register(t5);
RWStructuredBuffer<float2> Result2D : register(u6);
RWStructuredBuffer<float4> Result3D : register(u7);
RWStructuredBuffer<float4> Result4D : register(u8);

[numthreads(1,1,1)]
void main() {
// 2D case
float2 result2D = reflect(IncidentRay2D[0].xy, normalize(Wall2D[0].xy));
Result2D[0] = result2D;
float2 result2D_constant = reflect(float2(0.75, -0.5), float2(0.70710677, 0.70710677));
Result2D[1] = result2D_constant;

// 3D case, using float4 for alignment
float4 result3D = float4(reflect(IncidentRay3D[0].xyz, normalize(Wall3D[0].xyz)), 0.0);
Result3D[0] = result3D;
float4 result3D_constant = float4(reflect(float3(0.5, -0.25, 0.75), float3(0.5, 0.5, 0.70710677)), 0.0);
Result3D[1] = result3D_constant;

// 4D case
float4 result4D = reflect(IncidentRay4D[0].xyzw, normalize(Wall4D[0].xyzw));
Result4D[0] = result4D;
float4 result4D_constant = reflect(float4(0.5, -0.25, 0.75, -0.5), float4(0.5, 0.5, 0.5, 0.5));
Result4D[1] = result4D_constant;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:

- Name: IncidentRay2D
Format: Float32
Stride: 8
Data: [ 0.75, -0.5 ]
- Name: IncidentRay3D
Format: Float32
Stride: 16
Data: [ 0.5, -0.25, 0.75, 0.0 ]
- Name: IncidentRay4D
Format: Float32
Stride: 16
Data: [ 0.5, -0.25, 0.75, -0.5 ]

- Name: Wall2D
Format: Float32
Stride: 8
Data: [ 0.70710677, 0.70710677 ]
- Name: Wall3D
Format: Float32
Stride: 16
Data: [ 0.5, 0.5, 0.70710677, 0.0 ]
- Name: Wall4D
Format: Float32
Stride: 16
Data: [ 0.5, 0.5, 0.5, 0.5 ]

- Name: Result2D
Format: Float32
Stride: 8
ZeroInitSize: 16
- Name: ExpectedResult2D
Format: Float32
Stride: 8
Data: [ 0.5, -0.75, 0.5, -0.75 ]

- Name: Result3D
Format: Float32
Stride: 16
ZeroInitSize: 32
- Name: ExpectedResult3D
Format: Float32
Stride: 16
Data: [ -0.15533, -0.90533, -0.176777, 0.0, -0.15533, -0.90533, -0.176777, 0.0 ]

- Name: Result4D
Format: Float32
Stride: 16
ZeroInitSize: 32
- Name: ExpectedResult4D
Format: Float32
Stride: 16
Data: [ 0.25, -0.5, 0.5, -0.75, 0.25, -0.5, 0.5, -0.75 ]

Results:
- Result: CheckResult2D
Rule: BufferFloatEpsilon
Epsilon: 0.000002
Actual: Result2D
Expected: ExpectedResult2D
- Result: CheckResult3D
Rule: BufferFloatEpsilon
Epsilon: 0.000002
Actual: Result3D
Expected: ExpectedResult3D
- Result: CheckResult4D
Rule: BufferFloatEpsilon
Epsilon: 0.000002
Actual: Result4D
Expected: ExpectedResult4D

DescriptorSets:
- Resources:
- Name: IncidentRay2D
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: IncidentRay3D
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: IncidentRay4D
Kind: StructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Wall2D
Kind: StructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
- Name: Wall3D
Kind: StructuredBuffer
DirectXBinding:
Register: 4
Space: 0
VulkanBinding:
Binding: 4
- Name: Wall4D
Kind: StructuredBuffer
DirectXBinding:
Register: 5
Space: 0
VulkanBinding:
Binding: 5
- Name: Result2D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 6
Space: 0
VulkanBinding:
Binding: 6
- Name: Result3D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 7
Space: 0
VulkanBinding:
Binding: 7
- Name: Result4D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 8
Space: 0
VulkanBinding:
Binding: 8
...
#--- end
# UNSUPPORTED: Clang-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