0
\$\begingroup\$

I'm using a variant of the D3D12 UWP template that comes with VS2017 Community Edition and I have two related questions:

When I add this italicized and bolded code to the vertex shader signature, I get an X4016 error:

PixelShaderInput main(VertexShaderInput input, uint instanceID : SV_InstanceID)

The full text of the error is:
error X4016: SV_InstanceID semantic cannot be used with 10Level9 targets

I don't understand what this means because when the template calls D3D12CreateDevice, it sets D3D_FEATURE_LEVEL_11_0.

Per this post, I'm thinking SV_InstanceID is supported in DX11 and above: https://stackoverflow.com/questions/21241207/dx11-c-shader-cant-receive-instance-buffer-content

If I'm using a D3D12 template that is setting D3D_FEATURE_LEVEL_11_0 in the D3D12CreateDeveice call, why does the template think I have 10Level9 target?

Where can I go to change the template so that it uses a target that is compatible with the SV_InstanceID semantic in the vertex shader?

NOTE: I'm trying to loosely follow the example on Page 561 of Frank Luna's "3D Game Programming with DirectX 12" Text where he passes instanceID into the vertex shader.

\$\endgroup\$
3
\$\begingroup\$

TL;DR: Edit your shader compilation to use Shader Model 5.1 or later.

With the DirectX 12 API, there is no supported device to date that supports anything less than Direct3D Feature Level 11.0. Therefore, there is no point in using any of the down-level profiles lower than 5.1. See Microsoft Docs

The default in most UWP templates if you don't set an explicit shader model is 4_0_level_9_3 which is a 10level9 feature level.

There are two solutions here:

  1. Right-click on each .hlsl file in your project, make sure you are set to All Configurations and All Platforms, then under HLSL Compiler -> General -> Shader Model set it to "Shader Model 5.1 /5_1"

  2. A better solution is to open the .vcxproj in notepad and add the following lines:

    • Search for Label="UserMacros"
    • In each of the ItemDefinitionGroup blocks that follow for each configuration/platform combination, add a section just after the </CLCompile>:
<FXCompile>
     <ShaderModel>5.1</ShaderModel>
</FXCompile>

This will look something like:

  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>

    <PackageCertificateKeyFile>App1_TemporaryKey.pfx</PackageCertificateKeyFile>

  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\arm; $(VCInstallDir)\lib\arm</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\arm; $(VCInstallDir)\lib\arm</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\arm64; $(VCInstallDir)\lib\arm64</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\arm64; $(VCInstallDir)\lib\arm64</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store; $(VCInstallDir)\lib</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store; $(VCInstallDir)\lib</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\amd64; $(VCInstallDir)\lib\amd64</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Link>
      <AdditionalDependencies>d3d12.lib;dxgi.lib;dxguid.lib;%(AdditionalDependencies)</AdditionalDependencies>
      <AdditionalLibraryDirectories>%(AdditionalLibraryDirectories); $(VCInstallDir)\lib\store\amd64; $(VCInstallDir)\lib\amd64</AdditionalLibraryDirectories>
    </Link>
    <ClCompile>
      <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
      <PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
      <AdditionalIncludeDirectories>$(ProjectDir);$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>/bigobj %(AdditionalOptions)</AdditionalOptions>
      <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <FXCompile>
      <ShaderModel>5.1</ShaderModel>
    </FXCompile>
  </ItemDefinitionGroup>

This will make all your shader compilation default to 5.1 unless you set something else.

I use the second solution in my various Direct3D Game VS templates on GitHub.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.