Jump to content

  • Log In with Google      Sign In   
  • Create Account


[SlimDX] Compile shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 hannesnisula   Members   -  Reputation: 917

Like
0Likes
Like

Posted 08 October 2011 - 11:09 AM

Hello I've been trying to compile shaders with SlimDX and ShaderBytecode.CompileShader() but I always get the exception that says unexpected 'something' and that something is always the first character in the shader. I've also tried with different shader profiles as "vs_1_0", "vs_3_0" etc so I guess that's not the problem. I set the entry point to the name of the function, for my testing I put it as "vertexShaderEntry" am I supposed to specify parameters or something in that string in the CompileShader() call as well?

From what I've tried I believe there's something wrong with my byte array made from the string containing my whole shader code.


byte[] byteArray = new byte[currentShader.shaderData.Length * 2];
byte[] tempBytes = null;

for(int i = 0; i < currentShader.shaderData.Length; ++i)
{
	tempBytes = BitConverter.GetBytes(currentShader.shaderData.ToCharArray()[i]);
	byteArray[i * 2] = tempBytes[0];
	byteArray[i * 2 + 1] = tempBytes[1];
}

This is the code where I take the shaderData string, consisting of the full shader code, and turn it into a byte array. The string is taken from a multiline textbox control.

I can't seem to find any errors so I'd appreciate if anyone else finds any.

Sponsor:

#2 Martins Mozeiko   Crossbones+   -  Reputation: 1413

Like
0Likes
Like

Posted 08 October 2011 - 11:11 AM

To get byte array from string just use Encoding class:
byte[] sourceBytes = System.Text.Encoding.UTF8.GetBytes(sourceString);

And afaik ShaderBytecode.CompileShader can accept string as shader source - there is no need to convert it to byte array:
http://slimdx.mdxinfo.com/latestdocs/help/html/M_SlimDX_D3DCompiler_ShaderBytecode_Compile_2_f3570541.htm

#3 hannesnisula   Members   -  Reputation: 917

Like
0Likes
Like

Posted 08 October 2011 - 01:11 PM

To get byte array from string just use Encoding class:

byte[] sourceBytes = System.Text.Encoding.UTF8.GetBytes(sourceString);

And afaik ShaderBytecode.CompileShader can accept string as shader source - there is no need to convert it to byte array:
http://slimdx.mdxinf..._2_f3570541.htm


Oh man, so embarrassing to have missed that one. Thanks a ton, it works like a charm now!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS