-
Notifications
You must be signed in to change notification settings - Fork 33
Add GraphicsSystemValues.test for graphics-stage system-value semantics
#1142
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
EmilioLaiso
wants to merge
2
commits into
llvm:main
Choose a base branch
from
Traverse-Research:graphics-semantics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,171 @@ | ||
| #--- vertex.hlsl | ||
| struct VSInput { | ||
| float4 pos : POSITION; | ||
| uint vid : SV_VertexID; | ||
| }; | ||
|
|
||
| struct VSOutput { | ||
| float4 position : SV_POSITION; | ||
| nointerpolation uint vid : VID; | ||
| }; | ||
|
|
||
| VSOutput main(VSInput input) { | ||
| VSOutput o; | ||
| o.position = input.pos; | ||
| o.vid = input.vid; | ||
| return o; | ||
| } | ||
|
|
||
| #--- pixel.hlsl | ||
| struct PSInput { | ||
| float4 position : SV_POSITION; | ||
| nointerpolation uint vid : VID; | ||
| }; | ||
|
|
||
| struct Record { | ||
| uint VertexID; | ||
| uint PrimitiveID; | ||
| uint IsFrontFace; | ||
| float PosX; | ||
| float PosY; | ||
| float PosZ; | ||
| float PosW; | ||
| }; | ||
|
|
||
| RWStructuredBuffer<Record> Output : register(u0); | ||
|
|
||
| float4 main(PSInput input, | ||
| uint primID : SV_PrimitiveID, | ||
| bool isFront : SV_IsFrontFace) : SV_TARGET { | ||
| uint pixelX = (uint)input.position.x; | ||
|
|
||
| Record r; | ||
| r.VertexID = input.vid; | ||
| r.PrimitiveID = primID; | ||
| r.IsFrontFace = isFront ? 1u : 0u; | ||
| r.PosX = input.position.x; | ||
| r.PosY = input.position.y; | ||
| r.PosZ = input.position.z; | ||
| r.PosW = input.position.w; | ||
| Output[pixelX] = r; | ||
|
|
||
| return float4(1.0, 0.0, 0.0, 1.0); | ||
| } | ||
|
|
||
| #--- pipeline.yaml | ||
| --- | ||
| Shaders: | ||
| - Stage: Vertex | ||
| Entry: main | ||
| - Stage: Pixel | ||
| Entry: main | ||
| Buffers: | ||
| # Geometry: 4 triangles, each covering exactly one pixel of a 4x1 render target. | ||
| # Pixel-center NDC coordinates are (-0.75, 0), (-0.25, 0), (+0.25, 0), (+0.75, 0). | ||
| # The shared edges fall at NDC x in {-0.5, 0, +0.5}, none of which coincide with | ||
| # a pixel center, so rasterization tie-breaking does not affect coverage. | ||
| # | ||
| # Triangles 0,1 are CCW (front-facing under our CCW=front convention). | ||
| # Triangles 2,3 are CW (back-facing). | ||
| # | ||
| # Provoking-vertex (= first vertex) convention is the default on D3D12, Vulkan, | ||
| # and Metal, so the `nointerpolation` VID varying carries the first vertex's | ||
| # SV_VertexID into the pixel shader. | ||
| - Name: VertexData | ||
| Format: Float32 | ||
| Stride: 16 | ||
| Data: [ | ||
| # Triangle 0 (CCW, pixel 0, provoking VID=0): | ||
| -1.0, -1.0, 0.0, 1.0, | ||
| 0.0, -1.0, 0.0, 1.0, | ||
| -1.0, 1.0, 0.0, 1.0, | ||
| # Triangle 1 (CCW, pixel 1, provoking VID=3): | ||
| 0.0, -1.0, 0.0, 1.0, | ||
| 0.0, 1.0, 0.0, 1.0, | ||
| -1.0, 1.0, 0.0, 1.0, | ||
| # Triangle 2 (CW, pixel 2, provoking VID=6): | ||
| 0.0, -1.0, 0.0, 1.0, | ||
| 0.0, 1.0, 0.0, 1.0, | ||
| 1.0, -1.0, 0.0, 1.0, | ||
| # Triangle 3 (CW, pixel 3, provoking VID=9): | ||
| 0.0, 1.0, 0.0, 1.0, | ||
| 1.0, 1.0, 0.0, 1.0, | ||
| 1.0, -1.0, 0.0, 1.0, | ||
| ] | ||
| - Name: RenderTarget | ||
| Format: Float32 | ||
| Channels: 4 | ||
| FillSize: 64 # 4x1 @ 16 bytes per pixel | ||
| OutputProps: | ||
| Height: 1 | ||
| Width: 4 | ||
| Depth: 1 | ||
| - Name: ResultBuffer | ||
| Format: Hex32 | ||
| Stride: 28 # sizeof(Record): 3 uint + 4 float | ||
| FillSize: 112 # 4 records * 28 bytes | ||
| FillValue: 0 | ||
| - Name: ResultBuffer_Expected | ||
| Format: Hex32 | ||
| Stride: 28 | ||
| # Per-pixel expected records: VID, PrimID, IsFront, PosX, PosY, PosZ, PosW | ||
| # Floats are encoded as IEEE-754 bits: | ||
| # 0.5 -> 0x3F000000 1.5 -> 0x3FC00000 | ||
| # 1.0 -> 0x3F800000 2.5 -> 0x40200000 3.5 -> 0x40600000 | ||
| Data: [ | ||
| # Pixel 0: VID=0, PrimID=0, IsFront=1, Pos=(0.5, 0.5, 0, 1) | ||
| 0x0, 0x0, 0x1, 0x3F000000, 0x3F000000, 0x0, 0x3F800000, | ||
| # Pixel 1: VID=3, PrimID=1, IsFront=1, Pos=(1.5, 0.5, 0, 1) | ||
| 0x3, 0x1, 0x1, 0x3FC00000, 0x3F000000, 0x0, 0x3F800000, | ||
| # Pixel 2: VID=6, PrimID=2, IsFront=0, Pos=(2.5, 0.5, 0, 1) | ||
| 0x6, 0x2, 0x0, 0x40200000, 0x3F000000, 0x0, 0x3F800000, | ||
| # Pixel 3: VID=9, PrimID=3, IsFront=0, Pos=(3.5, 0.5, 0, 1) | ||
| 0x9, 0x3, 0x0, 0x40600000, 0x3F000000, 0x0, 0x3F800000, | ||
| ] | ||
| Bindings: | ||
| VertexBuffer: VertexData | ||
| VertexAttributes: | ||
| - Format: Float32 | ||
| Channels: 4 | ||
| Offset: 0 | ||
| Name: POSITION | ||
| RenderTarget: RenderTarget | ||
| DescriptorSets: | ||
| - Resources: | ||
| - Name: ResultBuffer | ||
| Kind: RWStructuredBuffer | ||
| DirectXBinding: | ||
| Register: 0 | ||
| Space: 0 | ||
| VulkanBinding: | ||
| Binding: 0 | ||
| Results: | ||
| - Result: SystemValues | ||
| Rule: BufferExact | ||
| Actual: ResultBuffer | ||
| Expected: ResultBuffer_Expected | ||
| ... | ||
| #--- end | ||
|
|
||
| # This test exercises: | ||
| # * SV_VertexID - VS input, forwarded via a `nointerpolation` varying | ||
| # * SV_PrimitiveID - PS input | ||
| # * SV_IsFrontFace - PS input | ||
| # * SV_POSITION - VS output / PS input, asserted at pixel center | ||
| # | ||
| # SV_VertexID: https://github.com/llvm/wg-hlsl/issues/151 | ||
| # SV_PrimitiveID: https://github.com/llvm/wg-hlsl/issues/160 | ||
| # SV_IsFrontFace: https://github.com/llvm/wg-hlsl/issues/162 | ||
| # SV_POSITION: https://github.com/llvm/wg-hlsl/issues/141 | ||
| # Clang's HLSL -> DXIL lowering does not yet implement these graphics-stage SVs. | ||
| # | ||
| # Also indirectly exercises the `nointerpolation` modifier, which Clang's HLSL | ||
| # frontend does not yet parse. | ||
| # https://github.com/llvm/wg-hlsl/issues/303 | ||
|
|
||
| # XFAIL: Clang | ||
|
|
||
| # RUN: split-file %s %t | ||
| # RUN: %dxc_target -T vs_6_0 -Fo %t-vertex.o %t/vertex.hlsl | ||
| # RUN: %dxc_target -T ps_6_0 -Fo %t-pixel.o %t/pixel.hlsl | ||
| # RUN: %offloader %t/pipeline.yaml %t-vertex.o %t-pixel.o | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to put these test explanations at the top of the file so that it's the first thing you see when opening the file?