Skip to content

add test for asint #276

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 1 commit into
base: main
Choose a base branch
from
Open
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
141 changes: 141 additions & 0 deletions test/Feature/HLSLLib/asint.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#--- source.hlsl

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

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

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

// float
Out3[0] = asint(In3[0]);
int4 Tmp3 = {asint(In3[0].xyz), asint(In3[0].w)};
Out3[1] = Tmp3;
Out3[2].xy = asint(In3[0].xy);

}

//--- 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: [0xffffffff, 0, 0x80000000, 0x7FFFFFFF]
- Name: In3
Format: Float32
Stride: 16
Data: [-nan, 0, -0, nan]
- 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]
- Name: Out2
Format: Int32
Stride: 16
ZeroInitSize: 48
- Name: ExpectedOut2 # The result we expect
Format: Int32
Stride: 16
Data: [-1, 0, -2147483648, 2147483647, -1, 0, -2147483648, 2147483647, -1, 0, 0, 0]
- Name: Out3
Format: Int32
Stride: 16
ZeroInitSize: 48
- Name: ExpectedOut3 # The result we expect
Format: Int32
Stride: 16
Data: [-1, 0, -2147483648, 2147483647, -1, 0, -2147483648, 2147483647, -1, 0, 0, 0]
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem correct to me. Shouldn't it be the following?

Suggested change
Data: [-1, 0, -2147483648, 2147483647, -1, 0, -2147483648, 2147483647, -1, 0, 0, 0]
Data: [-4194304, 0, -2147483648, 2143289344, -4194304, 0, -2147483648, 2143289344, -4194304, 0, 0, 0]

Because Out3 should be:

[asint(-nan), asint(0), asint(-0), asint(nan), asint(-nan), asint(0), asint(-0), asint(nan), asint(-nan), asint(0), 0, 0]

which should be the same as interpreting these hex values as int32s

[0xffc00000, 0x0, 0x80000000, 0x7fc00000, 0xffc00000, 0x0, 0x80000000, 0x7fc00000, 0xffc00000, 0x0, 0x0, 0x0]

Results:
- Result: Test1
Rule: BufferExact
Actual: Out1
Expected: ExpectedOut1
- Result: Test2
Rule: BufferExact
Actual: Out2
Expected: ExpectedOut2
- Result: Test3
Rule: BufferExact
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/llvm/llvm-project/issues/146942
# XFAIL: 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
Loading