How do I use Shader Model 5.0 compiled shaders in Visual Studio 11?

3k views Asked by At

I am trying to have the .hlsl files in my project pre-/ offline/ buildtime compiled for my C++ DirectX 11 project. Visual Studio compiles the .hlsl files into .cso files. I am now having trouble reading .cso files of SM 5.0 into my program to create a shader.

Here is the code I have to create a Pixel Shader from a precompiled .cso file:

ID3D11VertexShader* PS;
ID3DBlob* PS_Buffer;

D3DReadFileToBlob(L"PixelShader.cso", &PS_Buffer);
d3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);
d3d11DevCon->PSSetShader(PS, 0, 0);

The pixel shader is simply supposed to return blue pixels. It has been compiled to Shader Model 5.0 by changing its compile settings in Visual Studio 11. However upon running the program the triangle I am trying to render doesn't show up despite their being no build or runtime error messages.

When compiling at runtime using:

D3DCompileFromFile(L"PixelSHader.hlsl", 0, 0, "main", "ps_5_0", 0, 0, &PS_Buffer, 0);

instead of D3DReadFileToBlob(..), there is still no triangle rendered.

However when using Shader Model 4.0, whether buildtime or runtime compiled, a blue triangle does show signifying that it works.

Here is the code in my PixelShader.hlsl file. By any chance could it be too outdated for Shader Model 5.0 and be the root of my problem?

float4 main() : SV_TARGET
{
    return float4(0.0f, 0.0f, 1.0f, 1.0f);
}

I am using the Windows SDK libraries and not the June 2010 DirectX SDK. My Graphics Card is a nVidia 8800 GTS.

1

There are 1 answers

0
Patrick Lafferty On BEST ANSWER

Shader model 5 is supported by the GeForce 400 series and newer for nVidia cards, and the Radeon 5000 series and newer for AMD cards. Your GeForce 8800 only supports shader model 4, which is why the shader doesn't run. To get around this you can use the reference device (by using D3D_DRIVER_TYPE_REFERENCE) but this will be quite slow. Additionally you can use the WARP device if you have the Windows 8 preview (which adds WARP support for D3D_FEATURE_LEVEL_11_0), which will perform better than the reference device but still nowhere near running on the hardware device.