yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Yong HeRewriting the lower-buffer-element-type pass to avoid unnecessary packing/unpacking. (#8526)a6deb5ed8

master
1.1 KiB44 linesraw
1// geometry-shader-sub-func.slang
2
3//TEST:SIMPLE(filecheck=SPIRV): -target spirv -emit-spirv-directly -O0
4
5struct CoarseVertex
6{
7    float4 position     : POSITION;
8    float3 color        : COLOR;
9    uint   id           : ID;
10}
11
12struct RasterVertex
13{
14    float4 position : POSITION;
15    float3 color    : COLOR;
16    uint   id       : SV_RenderTargetArrayIndex;
17}
18
19// SPIRV: OpEntryPoint
20// SPIRV: OpStore %outputStream_position
21// SPIRV: OpEmitVertex
22void appendVertex(TriangleStream<RasterVertex> outputStream, RasterVertex vert)
23{
24    outputStream.Append(vert);
25}
26
27[shader("geometry")]
28[maxvertexcount(3)]
29void main(
30    triangle CoarseVertex coarseVertices[3],
31    inout TriangleStream<RasterVertex> outputStream,
32    uint primitiveID : SV_PrimitiveID)
33{
34    [ForceUnroll]
35    for(int ii = 0; ii < 3; ++ii)
36    {
37        CoarseVertex coarseVertex = coarseVertices[ii];
38        RasterVertex rasterVertex;
39        rasterVertex.position = coarseVertex.position;
40        rasterVertex.color      = coarseVertex.color;
41        rasterVertex.id         = coarseVertex.id + primitiveID;
42        appendVertex(outputStream, rasterVertex);
43    }
44}