2
votes

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
8800GTS only supports shader model 4. The 400 series supports SM5.Patrick Lafferty
Thanks that was the answer. For anyone looking to test SM 5.0 on an old card any ways, try setting the D3D_DRIVER_TYPE to D3D_DRIVER_TYPE_REFERENCE when creating the Device and Swapchain. However it will be extremely slow: D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, D3D_FEATURE_LEVEL_11_1, 1, D3D11_SDK_VERSION, &swapchaindesc, &swapchain_, &device_, NULL, &devicecontext_);gundamb2

1 Answers

2
votes

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.