• Advertisement
Sign in to follow this  

[D3D12] SV_ClipDistance shader compile error

This topic is 655 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello!

 

I would like to understand how to use programmable clipping using SV_ClipDistance.

I have created a sample drawing rectangle with specifying custom clipping plane distance in the vertex shader.

For some reason it will not compile: error X4502: invalid output semantic 'SV_ClipDistance2': Legal indices are in [0,1]

Tried both on vs_4_0 and vs_5_0.

struct VSInput
{
	float4 position			: POSITION;
	float4 color			: COLOR;
};

struct VSOutput
{
	float4 clipSpacePos		: SV_Position;
	float4 color			: COLOR;
	float leftClipPlaneDist	: SV_ClipDistance0;
	float rightClipPlaneDist : SV_ClipDistance1;
	float topClipPlaneDist : SV_ClipDistance2;
};

VSOutput Main(VSInput input)
{
	VSOutput output;
	output.clipSpacePos = input.position;
	output.color = input.color;
	
	float rightClipPlane = 0.25f;
	float leftClipPlane = -0.75f;
	float topClipPlane = 0.25f;

	output.leftClipPlaneDist = input.position.x - leftClipPlane;
	output.rightClipPlaneDist = rightClipPlane - input.position.x;
	output.topClipPlaneDist = topClipPlane - input.position.y;

	return output;
}

I do not understand why the compiler does not like SV_ClipDistance2. The maximum number for SV_ClipDistance[n] attributes is equal to D3D12_CLIP_OR_CULL_DISTANCE_COUNT, which 8. Also, I do not buy why the compiler complains about the index here. I am using just one float value. Should not index be 0?

 

Thanks!

Edited by _void_

Share this post


Link to post
Share on other sites
Advertisement

MSDN says

The combined clip and cull distance values are at most D3D#_CLIP_OR_CULL_DISTANCE_COUNT components in at most D3D#_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT registers

Share this post


Link to post
Share on other sites

D3D12_CLIP_OR_CULL_DISTANCE_COUNT 8

D3D12_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT 2

 

Mona2000, does it mean the following then?

 

float clipDistances[8] : SV_ClipDistance0;

float clipDistances[8] : SV_ClipDistance1;

 

Because the following code: float clipDistances[3] : SV_ClipDistance0;

will not compile either: error X4502: invalid output semantic 'SV_ClipDistance0': Legal indices are in [0,1] 

Edited by _void_

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement