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

// This test tests three different reflection scenarios:
// -----> |
// -----> /
// -----> -
// each test case will cycle through 1-4 dimensions.

StructuredBuffer<half4> IncidentRay : register(t0);
StructuredBuffer<half4> Wall1 : register(t1);
StructuredBuffer<half4> Wall2 : register(t2);
StructuredBuffer<half4> Wall3 : register(t3);
Copy link

Choose a reason for hiding this comment

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

You're using StructuredBuffers, which means you can define everything you need in one buffer for simplicity, right? Same with the output buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right, but I personally find it more readable / maintainable to separate things out.
Won't need to worry as much about padding / alignment this way.


RWStructuredBuffer<half> Result1D : register(u4);
RWStructuredBuffer<half2> Result2D : register(u5);
// half4 for simplification in memory alignment
RWStructuredBuffer<half4> Result3D : register(u6);
RWStructuredBuffer<half4> Result4D : register(u7);

[numthreads(1,1,1)]
void main() {
// scenario 1: -----> |

half Wall1_1D = reflect(IncidentRay[0].x, Wall1[0].x);
Result1D[0] = Wall1_1D;
half2 Wall1_2D = reflect(IncidentRay[0].xy, normalize(Wall1[0].xy));
Result2D[0] = Wall1_2D;
half3 Wall1_3D = reflect(IncidentRay[0].xyz, normalize(Wall1[0].xyz));
Result3D[0] = half4(Wall1_3D, 0.0);
half4 Wall1_4D = reflect(IncidentRay[0].xyzw, normalize(Wall1[0].xyzw));
Result4D[0] = Wall1_4D;

// scenario 2: -----> /

// The 1D scenario isn't applicable because there is no slanted
// wall that can be normalized in 1 dimensional space, since a slant
// requires at least 2 dimensions.
Result1D[1] = 0.0;

half2 Wall2_2D = reflect(IncidentRay[0].xy, normalize(Wall2[0].xy));
Result2D[1] = Wall2_2D;
half3 Wall2_3D = reflect(IncidentRay[0].xyz, normalize(Wall2[0].xyz));
Result3D[1] = half4(Wall2_3D, 0.0);
half4 Wall2_4D = reflect(IncidentRay[0].xyzw, normalize(Wall2[0].xyzw));
Result4D[1] = Wall2_4D;

// scenario 3: -----> -

// The 1D scenario isn't applicable because there is no horizontal
// wall that can be normalized in 1 dimensional space, since the x
// component must be 0.
half Wall3_1D = 0.0;
Result1D[2] = Wall3_1D;
half2 Wall3_2D = reflect(IncidentRay[0].xy, normalize(Wall3[0].xy));
Result2D[2] = Wall3_2D;
half3 Wall3_3D = reflect(IncidentRay[0].xyz, normalize(Wall3[0].xyz));
Result3D[2] = half4(Wall3_3D, 0.0);
half4 Wall3_4D = reflect(IncidentRay[0].xyzw, normalize(Wall3[0].xyzw));
Result4D[2] = Wall3_4D;
}

//--- pipeline.yaml

---
Shaders:
- Stage: Compute
Entry: main
DispatchSize: [1, 1, 1]
Buffers:
- Name: IncidentRay
Format: Float16
Stride: 8
Data: [ 0x4100, 0x8000, 0x0000, 0x0000 ]
- Name: Wall1
Format: Float16
Stride: 8
Data: [ 0xbc00, 0x0000, 0x0000, 0x0000 ]
Copy link

Choose a reason for hiding this comment

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

Why are most of the components for all of the inputs zeros? Axis aligned edge cases are probably the least interesting. A few random number inputs in a reasonable range should be sufficient to test the math expansion, and would be better than leaving z and w dimensions zeroed for all inputs (in my opinion).

- Name: Wall2
Format: Float16
Stride: 8
Data: [ 0xbc00, 0x3c00, 0x0000, 0x0000 ]
- Name: Wall3
Format: Float16
Stride: 8
Data: [ 0x0000, 0x3c00, 0x0000, 0x0000 ]

- Name: Result1D
Format: Float16
Stride: 2
ZeroInitSize: 8
- Name: ExpectedResult1D
Format: Float16
Stride: 2
Data: [ 0xc100, 0x0000, 0x0000, 0x0000 ]

- Name: Result2D
Format: Float16
Stride: 4
ZeroInitSize: 16
- Name: ExpectedResult2D
Format: Float16
Stride: 4
Data: [ 0xc100, 0x0000, 0x0000, 0x4100, 0x4100, 0x0000, 0x0000, 0x0000 ]

- Name: Result3D
Format: Float16
Stride: 8
ZeroInitSize: 24
- Name: ExpectedResult3D
Format: Float16
Stride: 8
Data: [ 0xc100, 0x0000, 0x0000, 0x0000, 0x0000, 0x4100, 0x0000, 0x0000, 0x4100, 0x0000, 0x0000, 0x0000 ]

- Name: Result4D
Format: Float16
Stride: 8
ZeroInitSize: 24
- Name: ExpectedResult4D
Format: Float16
Stride: 8
Data: [ 0xc100, 0x0000, 0x0000, 0x0000, 0x0000, 0x4100, 0x0000, 0x0000, 0x4100, 0x0000, 0x0000, 0x0000 ]

Results:
- Result: CheckResult1D
Rule: BufferFloatEpsilon
Epsilon: 0.0006
Actual: Result1D
Expected: ExpectedResult1D
- Result: CheckResult2D
Rule: BufferFloatEpsilon
Epsilon: 0.0006
Actual: Result2D
Expected: ExpectedResult2D
- Result: CheckResult3D
Rule: BufferFloatEpsilon
Epsilon: 0.0006
Actual: Result3D
Expected: ExpectedResult3D
- Result: CheckResult4D
Rule: BufferFloatEpsilon
Epsilon: 0.0006
Actual: Result4D
Expected: ExpectedResult4D

DescriptorSets:
- Resources:
- Name: IncidentRay
Kind: StructuredBuffer
DirectXBinding:
Register: 0
Space: 0
VulkanBinding:
Binding: 0
- Name: Wall1
Kind: StructuredBuffer
DirectXBinding:
Register: 1
Space: 0
VulkanBinding:
Binding: 1
- Name: Wall2
Kind: StructuredBuffer
DirectXBinding:
Register: 2
Space: 0
VulkanBinding:
Binding: 2
- Name: Wall3
Kind: StructuredBuffer
DirectXBinding:
Register: 3
Space: 0
VulkanBinding:
Binding: 3
- Name: Result1D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 4
Space: 0
VulkanBinding:
Binding: 4
- Name: Result2D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 5
Space: 0
VulkanBinding:
Binding: 5
- Name: Result3D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 6
Space: 0
VulkanBinding:
Binding: 6
- Name: Result4D
Kind: RWStructuredBuffer
DirectXBinding:
Register: 7
Space: 0
VulkanBinding:
Binding: 7
...
#--- end
# UNSUPPORTED: Clang-Vulkan

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