Gabriel Ortega
Gabriel Ortega

Reputation: 481

Running Shaders in DXIL

I'm trying to run a DirectX 12 app using the Dxc compiler located here. The shader source compiles successfully, however the D3D api fails to read the shader byte code.

I'm using the D3DCompiler DXC Bridge. According to the docs I need to rename it to d3dcompiler_47.dll and place the dxcompiler.dll, and dxil.dll next to the executable for proper validation and signing which I've done. I'm running in experimental mode so signing shouldn't matter. I'm also running windows version 1703 which is supposed to support dxil.

When the application runs I can see d3dcompiler_47, dxcompiler, and dxil all being loaded into memory, so it just seems to be that the D3D runtime fails to recognize DXIR as a valid byte code format. HALP!

Upvotes: 1

Views: 2091

Answers (2)

Chuck Walbourn
Chuck Walbourn

Reputation: 41057

Does your video driver support Shader Model 6 and more specifically whatever Shader Model you are trying to use?

Detection is a little tricky, but try this:

D3D12_FEATURE_DATA_SHADER_MODEL shaderModel = {};

#if defined(NTDDI_WIN10_VB) && (NTDDI_VERSION >= NTDDI_WIN10_VB)
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_6;
#elif defined(NTDDI_WIN10_19H1) && (NTDDI_VERSION >= NTDDI_WIN10_19H1)
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_5;
#elif defined(NTDDI_WIN10_RS5) && (NTDDI_VERSION >= NTDDI_WIN10_RS5)
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_4;
#elif defined(NTDDI_WIN10_RS4) && (NTDDI_VERSION >= NTDDI_WIN10_RS4)
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_2;
#else
shaderModel.HighestShaderModel = D3D_SHADER_MODEL_6_0;
#endif

HRESULT hr = device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel));
while (hr == E_INVALIDARG && shaderModel.HighestShaderModel > D3D_SHADER_MODEL_6_0)
{
    shaderModel.HighestShaderModel = static_cast<D3D_SHADER_MODEL>(static_cast<int>(shaderModel.HighestShaderModel) - 1);
    hr = device->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &shaderModel, sizeof(shaderModel));
}

if (FAILED(hr))
{
    shaderModel.HighestShaderModel = D3D_SHADER_MODEL_5_1;
}

I noticed for example that on my systems, the drivers provided by Windows Update did not support Shader Model 6 but if I downloaded them directly from the vendor website those did support it.

If you have the Windows 10 SDK (17134) or later, then you have a build of the DXC compiler already available as part of the Visual Studio 2017 or 2019 Developer Command Prompt.

You can also try the latest DxCapsViewer.

Upvotes: 1

Gabriel Ortega
Gabriel Ortega

Reputation: 481

In order to get this working I actually required Windows 10 Creators Update SDK (1809). I also needed to enable experimental mode explicitly via D3D12EnableExperimentalFeatures. I found this on the DirectX 12 sample for Wave Intrinsics. I initially thought that enabling experimental mode was specifically required for using shader model 6+ features but perhaps it's required to interpret DXIL/DXIR as well.

I suppose compilation with DXC requires Windows 10 (1703). Running shaders compiled with DXC requires Windows 10 (1809) along with any harware vendor driver support. However, I'm not certain that is absolutely correct.

Upvotes: 1

Related Questions