Hello everyone
I ran into this issue when creating pipeline state objects using pixel and vertex shaders compiled with dxc.
I get an error stating the my shader version is invalid however the version of my shader is listed as an acceptable shader.
D3D12 ERROR: ID3D12Device::CreateVertexShader: Shader must be vs_6_5, vs_6_4, vs_6_3, vs_6_2, vs_6_1, vs_6_0, vs_5_1, vs_5_0, vs_4_1, vs_4_0. Shader version provided: vs_6_1. [ STATE_CREATION ERROR #68: CREATEVERTEXSHADER_INVALIDSHADERTYPE]
D3D12 ERROR: ID3D12Device::CreatePixelShader: Shader must be ps_6_5, ps_6_4, ps_6_3, ps_6_2, ps_6_1, ps_6_0, ps_5_1, ps_5_0, ps_4_1, ps_4_0. Shader version provided: ps_6_1. [ STATE_CREATION ERROR #94: CREATEPIXELSHADER_INVALIDSHADERTYPE]
I compiled the shaders using the commands:
dxc -WX -Od -Zi -Qembed_debug -nologo -T vs_6_1 -E VSMain -Fo $(OutDir)shaders\general_0_vs.cso general.hlsl
dxc -WX -Od -Zi -Qembed_debug -nologo -T ps_6_1 -E PSMain -Fo $(OutDir)shaders\general_0_ps.cso general.hlsl
PSO Creation:
D3D12_GRAPHICS_PIPELINE_STATE_DESC psoDesc;
ZeroMemory(&psoDesc, sizeof(D3D12_GRAPHICS_PIPELINE_STATE_DESC));
psoDesc.InputLayout = { inputLayout.data(), (UINT) inputLayout.size() };
psoDesc.pRootSignature = generalRootSignature.Get();
psoDesc.VS = CD3DX12_SHADER_BYTECODE(vertexShader.Get());
psoDesc.PS = CD3DX12_SHADER_BYTECODE(pixelShader.Get());
psoDesc.RasterizerState = CD3DX12_RASTERIZER_DESC(D3D12_DEFAULT);
psoDesc.BlendState = CD3DX12_BLEND_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState = CD3DX12_DEPTH_STENCIL_DESC(D3D12_DEFAULT);
psoDesc.DepthStencilState.DepthWriteMask = D3D12_DEPTH_WRITE_MASK_ZERO; // Disable writes to the depth buffer since we already know the depth information from the normals pass
psoDesc.SampleMask = UINT_MAX;
psoDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
psoDesc.NumRenderTargets = 1;
psoDesc.RTVFormats[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
psoDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT;
psoDesc.SampleDesc.Count = 4;
generalStates.push_back(ComPtr <ID3D12PipelineState>{}); // generalStates has type std::vector<ComPtr<ID3D12PipelineState>>
ThrowIfFailed(m_device->CreateGraphicsPipelineState(&psoDesc, IID_PPV_ARGS(&generalStates[info.shaderIndex])));
NAME_D3D12_OBJECT_INDEXED(generalStates, info.shaderIndex);
Shaders: (general.hlsl)
#include "lighting.hlsli"
StructuredBuffer<Light> g_light_data : register(t1);
Texture2D g_ssao : register(t3); // Screen space ambient occlusion
struct VSInput
{
float3 position : POSITION;
#ifdef lighting
#ifdef normalmap
float2 normalTex : TEXCOORD1;
float3 tangent : TANGENT;
#else
float3 normal : NORMAL;
#endif
#endif
// Color data
#ifdef textured
float2 tex : TEXCOORD0;
#else
#ifdef transparency
float4 color : COLOR;
#else
float3 color : COLOR;
#endif
#endif
};
struct PSInput
{
float4 position : SV_Position;
float3 worldPosition : POSITION;
#ifdef lighting
float4 lightingProjection[7] : TEXCOORD2;
#ifdef normalmap
float2 normalTex : TEXCOORD1;
float3 tangent : TANGENT;
#else
float3 normal : NORMAL;
#endif
#endif
// Color data
#ifdef textured
float2 tex : TEXCOORD0;
#else
#ifdef transparency
float4 color : COLOR;
#else
float3 color : COLOR;
#endif
#endif
};
PSInput VSMain(VSInput vin, uint instance : SV_InstanceID)
{
PSInput vout;
InstanceData instData = g_instance_data[instance];
float4 worldPosition = mul(instData.model_matrix, float4(vin.position, 1.f));
vout.worldPosition = worldPosition.xyz;
vout.position = mul(g_view_proj_matrix, worldPosition);
#ifdef textured
MaterialData matData = g_material_data[instData.material_index];
float4 texCoord = mul(instData.texture_transform, float4(vin.tex, 0.f, 1.f));
vout.tex = mul(matData.material_transform, texCoord).xy;
#else
vout.color = vin.color;
#endif
#ifdef lighting
vout.normal = mul(instData.normal_matrix, float4(vin.normal, 0.f)).xyz;
for (uint i = 0; i < 6; ++i){
if (instData.light_indices[i] >= g_number_of_point_lights){
vout.lightingProjection[i] = mul(g_light_data[instData.light_indices[i]].projected_texture_matrix, float4(vin.position, 1.f));
}
}
#endif
return vout;
}
// Temporary simple pixel shader whilst I debug this issue
float4 PSMain() : SV_Target
{
return float4(1.f, 0.f, 0.f, 1.f);
}
Any help would be greatly appreciated, Thank you in advance.