[D3D12] SV_ClipDistance shader compile error

Started by
3 comments, last by _void_ 7 years, 9 months ago

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!

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

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]

It means that the maximum is


float4 clipplanes0 : SV_ClipDistance0;
float4 clipplanes1 : SV_ClipDistance1;

This is it. Thanks!

This topic is closed to new replies.

Advertisement