[D3D12] FXC shader model 5.1 crash

Started by
4 comments, last by loreStefani 8 years ago

Hello everyone,

I'm having problem compiling the following HLSL pixel shader with shader model 5.1:


struct VShaderOutput
{
	float4 clipPos : SV_POSITION;
	float3 position : POSITION;
	float3 normal : NORMAL;
	float2 textCoord : TEXTCOORD;
};

struct DirectionalLight
{
	float3 color;
	float pad;
	float3 direction;
	float pad1;
};

#define DIR_LIGHTS_COUNT 10

ConstantBuffer<DirectionalLight> directionalLights[DIR_LIGHTS_COUNT] : register(b0);

struct SceneState
{
	float3 eyePosition;
};

ConstantBuffer<SceneState> sceneState : register(b0, space1);


float4 main(VShaderOutput input) : SV_TARGET
{
	float3 normal = normalize(input.normal);
	float3 position = input.position;
	float3 toEye = normalize(sceneState.eyePosition - position);
	float3 color = float3(0.05f, 0.05f, 0.05f);

	float3 diffuseColor = float3(0.5f, 0.5f, 0.5f);

	for (int i = 0; i < DIR_LIGHTS_COUNT; i++)
	{
		float3 toLight = -directionalLights[i].direction;
		float3 lightColor = directionalLights[i].color;

		float cosThetaL = dot(normal, toLight);
		float3 incidentRadiance = max(cosThetaL, 0.0f)* lightColor;
		color += diffuseColor*incidentRadiance;
	}

	return float4(color, 1.0f);
}

FXC crashes and the function D3DCompileFromFile triggers an access violation reading exception. This only happens when optimizations are enabled (in the first case with the "Disable Optimizations" option set to "No" in the Visual Studio property page, and using any D3DCOMPILE_OPTIMIZATION_LEVELi flag in the second one).

The error message generated in the first case is the following:

Severity Code Description Project File Line Suppression State
Error MSB6006 "fxc.exe" exited with code -1073741819. FXCBug C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets 1231
Where FXCBug is the project name.
Any help/suggestion is really really appreciated.
Advertisement

This still crashes on the latest internal builds of the compiler, so I'll pass this shader on for the team to take a look at.

In the meantime, it's probably unlikely that you actually wanted 10 constant buffers for your 10 directional lights? Is there a reason you didn't have a single constant buffer with an array of 10 directional lights inside?

This works fine, but will need a small adjustment to your CPU-side code:


//ConstantBuffer<DirectionalLight> directionalLights[DIR_LIGHTS_COUNT] : register(b0);  // 10 constant buffers, crash.

cbuffer DirectionalLights : register(b0)
{
	DirectionalLight directionalLights[DIR_LIGHTS_COUNT];   // 1 constant buffer, with 10 structures inside.
}

Thanks!

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

Thank you very much for your attention.

For the 10 directional lights thing, I was experimenting with unbounded descriptor tables and dynamic indexing, and the shader was a bit different. But I started removing pieces trying to find the crash cause.

My goal was to specify the number of lights dynamically through another constant buffer in order to compile just one version of the shader. I can't do it with one constant buffer, am I right?

Since we're here, I have another case in which the compiler fails:


struct VertexOut
{
	float4 positionH : SV_POSITION;
	float2 textCoord : TEXTCOORD;
};

struct TextureIndex
{
	uint index;
};

ConstantBuffer<TextureIndex> textureIndex : register(b0);

#define TEXTURES_COUNT 10

Texture2D<float4> textures[TEXTURES_COUNT] : register(t0);

SamplerState textureSampler : register(s0);

float4 main(VertexOut pin) : SV_TARGET
{
	return textures.Sample(textureSampler, pin.textCoord); //should be textures[textureIndex.index].Sample(...)
}

The compiler crashes regardless any optimization setting.

I understand you are in contact with the team, can you pass this too or teach me how to report a bug, please?

If you want threads to dynamically index into a data structure containing lots of lights then you probably just want a StructuredBuffer<DirectionalLight>. Dynamically indexing into a StructuredBuffer is far faster than dynamically indexing into an unbounded (or bounded) array of Constant Buffers, each containing a DirectionalLight.

You're right that you can't compile a shader with a single Constant Buffer containing an unbounded array of Directional Lights, but the solution is not an array of Constant Buffers.

The second shader you've provided doesn't crash the newest version of the compiler, so the bug has already been fixed and will be available when the next version of the Windows SDK is made available.


C:\Users\amile\Desktop\crash.txt(22,9-54): error X3087: const Texture2D<float4>[1] object does not have methods

compilation failed; no code produced

I believe the right way to file bugs against the Windows SDK is to file it on http://connect.microsoft.com/VisualStudio, however if I find that's not the case I'll update this post.

Adam Miles - Principal Software Development Engineer - Microsoft Xbox Advanced Technology Group

I don't know StructuredBuffer very well, I'm a student and I'm still learning. I will investigate in that direction then.

Thank you very much for your help!

This topic is closed to new replies.

Advertisement