From d66b30729029bdb43892e05c9c80fd56ac95a24f Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 24 Feb 2021 08:21:37 -0800 Subject: Add support for GetAttributeAtVertex for D3D (#1725) This operation was added along with the `SV_Barycentrics` system-value input, and allows for a `nointerpolation` varying input to a fragment shader to be fetched at a specific vertex index within the primitive that is causing the fragment shader to be invoked. This change adds support for the new operations in the standard library, and also includes a test case to make sure that we emit it correctly when producing HLSL/DXIL. This change also includes a small bug fix to our emission logic for function parameters so that we properly emit layout-related attributes for varying parameters declared directly on an entry point. (Note that most attribute end up being declared in `struct` types in existing HLSL shaders, and our IR passes produce only global variables for attributes on GLSL; the only case this affects is inidividual scalar/vector attributes declared declared as entry-point parameters, when outputting HLSL) Note that this change only adds support for the new function on the HLSL/DXIL path, and doesn't yet add any cross-compilation support for GLSL/SPIR-V. The reason for this is that the equivalent GLSL feature(s) appear to use a different model to the HLSL version, and we need to invent a suitable approach to align them to make portable code possible. --- .../pipeline/rasterization/get-attribute-at-vertex.slang | 16 ++++++++++++++++ .../rasterization/get-attribute-at-vertex.slang.hlsl | 14 ++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/pipeline/rasterization/get-attribute-at-vertex.slang create mode 100644 tests/pipeline/rasterization/get-attribute-at-vertex.slang.hlsl (limited to 'tests') diff --git a/tests/pipeline/rasterization/get-attribute-at-vertex.slang b/tests/pipeline/rasterization/get-attribute-at-vertex.slang new file mode 100644 index 000000000..56fbcce78 --- /dev/null +++ b/tests/pipeline/rasterization/get-attribute-at-vertex.slang @@ -0,0 +1,16 @@ +// get-attribute-at-vertex.slang + +// Basic test for `GetAttributeAtVertex` function + +//TEST:CROSS_COMPILE:-target dxil -entry main -stage fragment -profile sm_6_1 + +[shader("fragment")] +void main( + nointerpolation float4 color : COLOR, + float3 bary : SV_Barycentrics, + out float4 result : SV_Target) +{ + result = bary.x * GetAttributeAtVertex(color, 0) + + bary.y * GetAttributeAtVertex(color, 1) + + bary.z * GetAttributeAtVertex(color, 2); +} diff --git a/tests/pipeline/rasterization/get-attribute-at-vertex.slang.hlsl b/tests/pipeline/rasterization/get-attribute-at-vertex.slang.hlsl new file mode 100644 index 000000000..257b334bf --- /dev/null +++ b/tests/pipeline/rasterization/get-attribute-at-vertex.slang.hlsl @@ -0,0 +1,14 @@ +// get-attribute-at-vertex.slang.hlsl + +//TEST_IGNORE_FILE: + +[shader("pixel")] +void main( + nointerpolation vector color_0 : COLOR, + vector bary_0 : SV_BARYCENTRICS, + out vector result_0 : SV_TARGET) +{ + result_0 = bary_0.x * GetAttributeAtVertex(color_0, (uint) int(0)) + + bary_0.y * GetAttributeAtVertex(color_0, (uint) int(1)) + + bary_0.z * GetAttributeAtVertex(color_0, (uint) int(2)); +} -- cgit v1.2.3