SDSL: unable to access custom streams after VS

hi all,

I want to sample from texture array with vertex id. I can access them in VS but not in PS or GS. Do I have to pass the streams on manually each stage, or am I missing the correct shader base? I thougt streams would take care of that themselves.

Here is a stripped down version with everything stream related.
Everything works, except accessing VId and IId in PS

[Summary("")]
shader A_DrawFX : VS_PS_Base, ColorBase, ShaderUtils
{
	stream float4 PosW : POSITION1;
	stream float2 TexCd : TEXCOORD0;
	stream uint VId : SV_VertexID;
	stream uint IId : SV_InstanceID;
	
    override stage void VSMain(){ 

    	uint vid = streams.VId;  
    	uint iid = streams.IId;    	

        streams.ShadingPosition = mul(p, World);
    }

    [maxvertexcount(4)]
    void GSMain(point Input input[1], inout TriangleStream<Output> pointStream)
    {
    	streams = input[0];
        for(int i=0; i<4; i++)
        {                     
        	streams.ShadingPosition = mul(float4(quadP, 1), ViewProjection);
        	streams.TexCd.xy = QuadUV[i];
        	pointStream.Append(streams);
        }
        pointStream.RestartStrip();
    }

    override stage void PSMain(){    	
    	//uint vid = streams.VId;
    	float2 uv = streams.TexCd;
        streams.ColorTarget = glyphs.Sample(sLw, float3(uv, 0) ,0 );
    }
};

not sure how stride handles special semantics names like SV_VertexID which are only allowed (in HLSL) as inputs for certain stages.~~

you could definitely work around the problem, by using another stream variable to pass that data to the next stage.
so your input for VS is still ‘SV_VertexID’ but you pass it along as another stream with name ‘VertexID’

edit: didn’t read your example properly…
in case of a GS you probably need to access the data through your first input parameter (in your case point Input input[1]) and copy that to your <Output>pointStream

edit 2: you do copy input/output to stream, so first answer actually applies.
at least that’s the way i got it working in a TS/DS shader

Yes, that is the correct answer, SV_VertexID can only be used as input for the vertex shader. for that reason we have this shader in VL.Stride:

Just inherit from it and use

AssignVertexID();

in the vertex shader and then you can use streams.VertexID in all following stages.

thanks, I solved it like that.

imo it would make sense that the shader base for draw shaders would automatically include streams for vid and iid.

Yes, good point.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.