Vertex Shader Output

Started by
14 comments, last by Nathan Drake 8 years, 3 months ago

previously when i use .fx files, i could use my errorMessage:


hr = D3DX11CompileFromFile(L"Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &PS_Buffer, &errorMessage, 0);

but now, when when i use .hlsl files, this is the method i use for create shaders:


std::vector<unsigned char> VSFile = ReadFile("VertexShader.cso");
d3d11Device->CreateVertexShader(VSFile.data(), VSFile.size(), NULL, &VS);

and this is my function for ReadFile:


std::vector<unsigned char> ReadFile(std::string path)
{
	std::vector<unsigned char> FileData;

	// open the file
	std::ifstream VertexFile(path, std::ios::in | std::ios::binary | std::ios::ate);

	// if open was successful
	if (VertexFile.is_open())
	{
		// find the length of the file
		int Length = (int)VertexFile.tellg();

		// collect the file data
		FileData.resize(Length);
		//FileData = new std::vector<unsigned char>(Length);
		VertexFile.seekg(0, std::ios::beg);
		VertexFile.read(reinterpret_cast<char*>(FileData.data()), Length);
		VertexFile.close();
	}
	else
	{
		MessageBox(hwnd, L"New Vertex shader system error", L"Error", MB_OK);
	}

	return FileData;
}

do you know how can i use those error messages like before ?

because it doesn't show anything in Visual Studio error list

Advertisement

Hmmm that still compiles individual shaders, not effects. Compiling effects (fx_5_0 profile and technique11 entries in the shader file) will fail compilation and report mismatches. No, I was talking about the D3D debug layer (D3D11_CREATE_DEVICE_DEBUG at device creation). Then a error will be reported when issuing a draw call. I don't think you can check this earlier, unless you use shader reflection.

You seem too happy about changing the order of input into your vertex shader. The effects of changing this should not excite you, it should tell you your vertex declaration does not match and is the underlying problem.

Hmmm that still compiles individual shaders, not effects. Compiling effects (fx_5_0 profile and technique11 entries in the shader file) will fail compilation and report mismatches. No, I was talking about the D3D debug layer (D3D11_CREATE_DEVICE_DEBUG at device creation). Then a error will be reported when issuing a draw call. I don't think you can check this earlier, unless you use shader reflection.

You seem too happy about changing the order of input into your vertex shader. The effects of changing this should not excite you, it should tell you your vertex declaration does not match and is the underlying problem.

since there are no guide or anything that mention the importance of shader reflection in our code, sometimes we have to facing to this kind of issues to find out what are the solutions and how we can prevent this kind of errors or bugs in our future codes.

based on what I've found about Shader reflection, This article described very well but i still didn't get where i have to exactly use it in my code. is it should be declared after compile my shader ? and is there any sample that shows how to use it ? because i still didn't get how to use that pointer to check the orders and compatibility of two shader files.

moreover, the VS_OUTPUT is the output of my vertex shader not the input. so why their order matters ?

Thank you

Given how the order that works is the one with lightVP at the end, I think the value might be getting optimized out when you compile the pixel shader (but not when you compile the vertex shader, since it uses it) leading to a layout mismatch. I'm pretty sure the compiler is not supposed to do that so I might be wrong here.

guys i still didn't get what layout mismatch you are talking about, since VS_OUTPUT struct was the same in both vertex and pixel shader huh.png

This topic is closed to new replies.

Advertisement