xref: /aosp_15_r20/external/angle/third_party/glslang/src/Test/spv.debuginfo.hlsl.geom (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1/*
2The MIT License (MIT)
3
4Copyright (c) 2022 Google LLC
5Copyright (c) 2022 Sascha Willems
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24*/
25
26struct UBO
27{
28	float4x4 projection[2];
29	float4x4 modelview[2];
30	float4 lightPos;
31};
32
33cbuffer ubo : register(b0) { UBO ubo; }
34
35struct VSOutput
36{
37	float4 Pos : SV_POSITION;
38[[vk::location(0)]] float3 Normal : NORMAL0;
39[[vk::location(1)]] float3 Color : COLOR0;
40};
41
42struct GSOutput
43{
44	float4 Pos : SV_POSITION;
45	uint ViewportIndex : SV_ViewportArrayIndex;
46	uint PrimitiveID : SV_PrimitiveID;
47[[vk::location(0)]] float3 Normal : NORMAL0;
48[[vk::location(1)]] float3 Color : COLOR0;
49[[vk::location(2)]] float3 ViewVec : TEXCOOR1;
50[[vk::location(3)]] float3 LightVec : TEXCOOR2;
51};
52
53[maxvertexcount(3)]
54[instance(2)]
55void main(triangle VSOutput input[3], inout TriangleStream<GSOutput> outStream, uint InvocationID : SV_GSInstanceID, uint PrimitiveID : SV_PrimitiveID)
56{
57	for(int i = 0; i < 3; i++)
58	{
59		GSOutput output = (GSOutput)0;
60		output.Normal = mul((float3x3)ubo.modelview[InvocationID], input[i].Normal);
61		output.Color = input[i].Color;
62
63		float4 pos = input[i].Pos;
64		float4 worldPos = mul(ubo.modelview[InvocationID], pos);
65
66		float3 lPos = mul(ubo.modelview[InvocationID], ubo.lightPos).xyz;
67		output.LightVec = lPos - worldPos.xyz;
68		output.ViewVec = -worldPos.xyz;
69
70		output.Pos = mul(ubo.projection[InvocationID], worldPos);
71
72		// Set the viewport index that the vertex will be emitted to
73		output.ViewportIndex = InvocationID;
74      	output.PrimitiveID = PrimitiveID;
75		outStream.Append( output );
76	}
77
78	outStream.RestartStrip();
79}
80