shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Support Geometry Shaders written in GLSL. #3363

Open csyonghe opened 7 months ago

csyonghe commented 7 months ago

This include support for geometry shader specific builtin input/outputs, and related intrinsics like EmitVertex.

ArielG-NV commented 3 months ago

Section 8.13. Geometry Shader Functions void EmitStreamVertex(int stream) void EndStreamPrimitive(int stream) void EmitVertex() void EndPrimitive()

ArielG-NV commented 3 months ago

the associated code (was already written, but removed since scope of original task changed)

/// Section 8.13. Geometry Shader Functions

__glsl_version(430) [require(glsl)]
__spirv_version(1.0) [require(spirv)]
[ForceInline]
public void EmitStreamVertex(int stream)
{
    __target_switch
    {
    case glsl: __intrinsic_asm "EmitStreamVertex($0)";
    case spirv:
    {
        spirv_asm
        {
            OpCapability GeometryStreams;
            OpEmitStreamVertex $stream
        };
    }
    }
}
__glsl_version(430) [require(glsl)]
__spirv_version(1.0) [require(spirv)]
[ForceInline]
public void EndStreamPrimitive(int stream)
{
    __target_switch
    {
    case glsl: __intrinsic_asm "EndStreamPrimitive($0)";
    case spirv:
    {
        spirv_asm
        {
            OpCapability GeometryStreams;
            OpEndStreamPrimitive $stream
        };
    }
    }
}
__glsl_version(430) [require(glsl)]
__spirv_version(1.0) [require(spirv)]
[ForceInline]
public void EmitVertex()
{
    __target_switch
    {
    case glsl: __intrinsic_asm "EmitVertex($0)";
    case spirv:
    {
        spirv_asm
        {
            OpCapability Geometry;
            OpEmitVertex
        };
    }
    }
}
__glsl_version(430) [require(glsl)]
__spirv_version(1.0) [require(spirv)]
[ForceInline]
public void EndPrimitive()
{
    __target_switch
    {
    case glsl: __intrinsic_asm "EndPrimitive($0)";
    case spirv:
    {
        spirv_asm
        {
            OpCapability Geometry;
            OpEndPrimitive
        };
    }
    }
}
csyonghe commented 3 months ago

The intrinsics is half of the work, the other half is making sure stores to the builtin variables like gl_Position does indeed take effect. If there is not much work other than include them in the stdlib to get geometry shaders to work, let's do it. If it is more involved and takes time, then let's deprioritize.

csyonghe commented 3 months ago

I don’t see any issues of us committing these changes.


From: ArielG-NV @.> Sent: Tuesday, March 19, 2024 4:44:35 PM To: shader-slang/slang @.> Cc: Yong He @.>; Author @.> Subject: Re: [shader-slang/slang] Support Geometry Shaders written in GLSL. (Issue #3363)

the associated code (was already written, but removed since scope of original task changed)

/// Section 8.13. Geometry Shader Functions

glsl_version(430) [require(glsl)] __spirv_version(1.0) [require(spirv)] [ForceInline] public void EmitStreamVertex(int stream) { target_switch { case glsl: intrinsic_asm "EmitStreamVertex($0)"; case spirv: { spirv_asm { OpCapability GeometryStreams; OpEmitStreamVertex $stream }; } } } glsl_version(430) [require(glsl)] spirv_version(1.0) [require(spirv)] [ForceInline] public void EndStreamPrimitive(int stream) { __target_switch { case glsl: intrinsic_asm "EndStreamPrimitive($0)"; case spirv: { spirv_asm { OpCapability GeometryStreams; OpEndStreamPrimitive $stream }; } } } glsl_version(430) [require(glsl)] __spirv_version(1.0) [require(spirv)] [ForceInline] public void EmitVertex() { target_switch { case glsl: intrinsic_asm "EmitVertex($0)"; case spirv: { spirv_asm { OpCapability Geometry; OpEmitVertex }; } } } glsl_version(430) [require(glsl)] spirv_version(1.0) [require(spirv)] [ForceInline] public void EndPrimitive() { __target_switch { case glsl: intrinsic_asm "EndPrimitive($0)"; case spirv: { spirv_asm { OpCapability Geometry; OpEndPrimitive }; } } }

— Reply to this email directly, view it on GitHubhttps://github.com/shader-slang/slang/issues/3363#issuecomment-2008353136, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAUHRBJDVK4U7VO7RLZNKLLYZDEWHAVCNFSM6AAAAAA76IJAJWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMBYGM2TGMJTGY. You are receiving this because you authored the thread.Message ID: @.***>