Jump to content
  • Advertisement
Sign in to follow this  
Dom_152

D3DCompile fails where fxc.exe succeeds

This topic is 2952 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

I'm trying to compile a hull and domain shader to start figuring out the Direct3D 11 tessellation stuff. The way I've been loading the vertex and pixel shaders is to load up the HLSL from a file and use the D3DCompile function to compile at runtime and get the bytecode to create the shader from.

For some reason this doesn't seem to work for hull or domain shaders as I get the error: 'Unexpected token "'. So I figured I'd try compiling it with the compiler that comes with the SDK and it works fine and I get no errors. Any ideas as to why this is happening?

Here is the shader loading code:


shaderFile = CreateFile("Terrain.hsh", FILE_GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
shaderFileSize = GetFileSize(shaderFile, 0);
shaderHLSL = new char[shaderFileSize];
bytesRead;
if(!ReadFile(shaderFile, shaderHLSL, shaderFileSize, (LPDWORD)&bytesRead, 0))
{
AppStatus::ErrorMessage = "Could not read hull shader file: Terrain.hsh";
return false;
}

shaderHLSL[shaderFileSize - 1] = '\0';

D3DCompile(shaderHLSL, shaderFileSize, "Terrain.hsh", 0, 0, "TerrainHullShader", "hs_5_0", 0, 0,
&shaderCode, &shaderErrors);

delete [] shaderHLSL;

if(shaderErrors != 0)
{
AppStatus::ErrorMessage = (char *)shaderErrors->GetBufferPointer();
return false;
}

ID3D11HullShader *hullShader;
mGraphicsDevice->CreateHullShader(shaderCode->GetBufferPointer(), shaderCode->GetBufferSize(), 0, &hullShader);
mGraphicsContext->HSSetShader(hullShader, 0, 0);

hullShader->Release();
shaderCode->Release();





This is the same code I'm using for the vertex and pixel shaders and they load fine so what's up?

Also here is the hull shader code:


struct HS_INPUT
{
float3 Position : WORLDPOS;
float3 Normal : NORMAL0;
float2 TextureCoords : TEXCOORD0;
};

struct HS_OUTPUT
{
float3 Position : WORLDPOS;
float3 Normal : NORMAL0;
float2 TextureCoords : TEXCOORD0;
};

struct HS_CONSTANT_DATA_OUTPUT
{
float Edges[3] : SV_TessFactor;
float Inside : SV_InsideTessFactor;
};

HS_CONSTANT_DATA_OUTPUT TerrainPatchConstantData(InputPatch<HS_INPUT, 3> p, uint PatchID : SV_PrimitiveID)
{
HS_CONSTANT_DATA_OUTPUT output = (HS_CONSTANT_DATA_OUTPUT)0;

output.Edges[0] = 1;
output.Edges[1] = 1;
output.Edges[2] = 1;
output.Inside = 1;

return output;
}

[domain("tri")]
[partitioning("fractional_odd")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("TerrainPatchConstantData")]
[maxtessfactor(15.0)]
HS_OUTPUT TerrainHullShader(InputPatch<HS_INPUT, 3> inputPatch, uint uCPID : SV_OutputControlPointID)
{
HS_OUTPUT output = (HS_OUTPUT)0;

// Copy inputs to outputs
output.Position = inputPatch[uCPID].Position;
output.Normal = inputPatch[uCPID].Normal;
output.TextureCoords = inputPatch[uCPID].TextureCoords;
return output;
}





Nothing complex, just passing through some triangle vertices as controls points.

It's not a massive issue as I can just load up the compiled binary file and use that to create the shader but I'm still curious as to why this is failing.

[Edited by - Dom_152 on August 23, 2010 8:13:23 AM]

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!