Merge pull request #3031 from rg3igalia/sub-group-size-arb-flat-fix
[platform/upstream/glslang.git] / Test / spv.debuginfo.hlsl.tese
1 /*
2 The MIT License (MIT)
3
4 Copyright (c) 2022 Google LLC
5 Copyright (c) 2022 Sascha Willems
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 */
25
26 struct UBO
27 {
28         float4x4 projection;
29         float4x4 modelview;
30         float4 lightPos;
31         float4 frustumPlanes[6];
32         float displacementFactor;
33         float tessellationFactor;
34         float2 viewportDim;
35         float tessellatedEdgeSize;
36 };
37 cbuffer ubo : register(b0) { UBO ubo; };
38
39 Texture2D displacementMapTexture : register(t1);
40 SamplerState displacementMapSampler : register(s1);
41
42 struct HSOutput
43 {
44 [[vk::location(2)]]     float4 Pos : SV_POSITION;
45 [[vk::location(0)]] float3 Normal : NORMAL0;
46 [[vk::location(1)]] float2 UV : TEXCOORD0;
47 };
48
49 struct ConstantsHSOutput
50 {
51     float TessLevelOuter[4] : SV_TessFactor;
52     float TessLevelInner[2] : SV_InsideTessFactor;
53 };
54
55 struct DSOutput
56 {
57         float4 Pos : SV_POSITION;
58 [[vk::location(0)]] float3 Normal : NORMAL0;
59 [[vk::location(1)]] float2 UV : TEXCOORD0;
60 [[vk::location(2)]] float3 ViewVec : TEXCOORD1;
61 [[vk::location(3)]] float3 LightVec : TEXCOORD2;
62 [[vk::location(4)]] float3 EyePos : POSITION1;
63 [[vk::location(5)]] float3 WorldPos : POSITION0;
64 };
65
66 [domain("quad")]
67 DSOutput main(ConstantsHSOutput input, float2 TessCoord : SV_DomainLocation, const OutputPatch<HSOutput, 4> patch)
68 {
69         // Interpolate UV coordinates
70         DSOutput output = (DSOutput)0;
71         float2 uv1 = lerp(patch[0].UV, patch[1].UV, TessCoord.x);
72         float2 uv2 = lerp(patch[3].UV, patch[2].UV, TessCoord.x);
73         output.UV = lerp(uv1, uv2, TessCoord.y);
74
75         float3 n1 = lerp(patch[0].Normal, patch[1].Normal, TessCoord.x);
76         float3 n2 = lerp(patch[3].Normal, patch[2].Normal, TessCoord.x);
77         output.Normal = lerp(n1, n2, TessCoord.y);
78
79         // Interpolate positions
80         float4 pos1 = lerp(patch[0].Pos, patch[1].Pos, TessCoord.x);
81         float4 pos2 = lerp(patch[3].Pos, patch[2].Pos, TessCoord.x);
82         float4 pos = lerp(pos1, pos2, TessCoord.y);
83         // Displace
84         pos.y -= displacementMapTexture.SampleLevel(displacementMapSampler, output.UV, 0.0).r * ubo.displacementFactor;
85         // Perspective projection
86         output.Pos = mul(ubo.projection, mul(ubo.modelview, pos));
87
88         // Calculate vectors for lighting based on tessellated position
89         output.ViewVec = -pos.xyz;
90         output.LightVec = normalize(ubo.lightPos.xyz + output.ViewVec);
91         output.WorldPos = pos.xyz;
92         output.EyePos = mul(ubo.modelview, pos).xyz;
93         return output;
94 }