I got this error while adding code to build and render shadows.
D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: The specified sample count or quality is not supported with the render target format in slot 1 [ STATE_CREATION ERROR #685: CREATEGRAPHICSPIPELINESTATE_INVALID_SAMPLE_DESC]
D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: The specified sample count or quality is not supported with the render target format in slot 2 [ STATE_CREATION ERROR #685: CREATEGRAPHICSPIPELINESTATE_INVALID_SAMPLE_DESC]
D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: The specified sample count or quality is not supported with the render target format in slot 3 [ STATE_CREATION ERROR #685: CREATEGRAPHICSPIPELINESTATE_INVALID_SAMPLE_DESC]
D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: The specified sample count or quality is not supported with the render target format in slot 4 [ STATE_CREATION ERROR #685: CREATEGRAPHICSPIPELINESTATE_INVALID_SAMPLE_DESC]
This is the code for creating shader inside Stage::BuildObjects
m_ppShaders[0] = pBoxShader;
m_pDepthRenderShader = new CDepthRenderShader(pBoxShader, m_pLights);
DXGI_FORMAT RtvFormats[1] = { DXGI_FORMAT_R32_FLOAT };
m_pDepthRenderShader->CreateShader(pd3dDevice, m_pd3dGraphicsRootSignature, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, 5, RtvFormats, DXGI_FORMAT_D32_FLOAT);
m_pDepthRenderShader->BuildObjects(pd3dDevice, pd3dCommandList, NULL);
m_pShadowShader = new CShadowMapShader(pBoxShader);
m_pShadowShader->CreateShader(pd3dDevice, m_pd3dGraphicsRootSignature, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, 5, NULL, DXGI_FORMAT_D24_UNORM_S8_UINT);//pipelinestate null
m_pShadowShader->BuildObjects(pd3dDevice, pd3dCommandList, m_pDepthRenderShader->GetDepthTexture());
m_pShadowMapToViewport = new CTextureToViewportShader();
m_pShadowMapToViewport->CreateShader(pd3dDevice, m_pd3dGraphicsRootSignature, D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE, 5, NULL, DXGI_FORMAT_D24_UNORM_S8_UINT);
m_pShadowMapToViewport->BuildObjects(pd3dDevice, pd3dCommandList, m_pDepthRenderShader->GetDepthTexture());
This is the code for the CreateShader function.
void CShader::CreateShader(ID3D12Device* pd3dDevice, ID3D12RootSignature* pd3dGraphicsRootSignature,
D3D12_PRIMITIVE_TOPOLOGY_TYPE d3dPrimitiveTopology, UINT nRenderTargets, DXGI_FORMAT* pdxgiRtvFormats, DXGI_FORMAT dxgiDsvFormat)
{
::ZeroMemory(&m_d3dPipelineStateDesc, sizeof(D3D12_GRAPHICS_PIPELINE_STATE_DESC));
m_d3dPipelineStateDesc.pRootSignature = pd3dGraphicsRootSignature;
m_d3dPipelineStateDesc.VS = CreateVertexShader();
m_d3dPipelineStateDesc.PS = CreatePixelShader();
m_d3dPipelineStateDesc.RasterizerState = CreateRasterizerState();
m_d3dPipelineStateDesc.BlendState = CreateBlendState();
m_d3dPipelineStateDesc.DepthStencilState = CreateDepthStencilState();
m_d3dPipelineStateDesc.InputLayout = CreateInputLayout();
m_d3dPipelineStateDesc.SampleMask = UINT_MAX;
m_d3dPipelineStateDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
m_d3dPipelineStateDesc.NumRenderTargets = nRenderTargets;
for (UINT i = 0; i < nRenderTargets; i++)
m_d3dPipelineStateDesc.RTVFormats[i] = (pdxgiRtvFormats) ? pdxgiRtvFormats[i] : DXGI_FORMAT_R8G8B8A8_UNORM;
m_d3dPipelineStateDesc.DSVFormat = dxgiDsvFormat;
m_d3dPipelineStateDesc.SampleDesc.Count = 1;
m_d3dPipelineStateDesc.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
//HRESULT hResult = pd3dDevice->CreateGraphicsPipelineState(&m_d3dPipelineStateDesc, IID_PPV_ARGS( & m_pd3dPipelineState));
HRESULT hResult = pd3dDevice->CreateGraphicsPipelineState(&m_d3dPipelineStateDesc, __uuidof(ID3D12PipelineState), (void**)&m_pd3dPipelineState);//0312 m_pd3dPipelineState가 null
int a = 0;
if (m_pd3dVertexShaderBlob)
m_pd3dVertexShaderBlob->Release();
if (m_pd3dPixelShaderBlob)
m_pd3dPixelShaderBlob->Release();
if (m_d3dPipelineStateDesc.InputLayout.pInputElementDescs)
delete[] m_d3dPipelineStateDesc.InputLayout.pInputElementDescs;
}
And this is the m_pDepthRenderShader->BuildObjects function code.
void CDepthRenderShader::BuildObjects(ID3D12Device* pd3dDevice, ID3D12GraphicsCommandList* pd3dCommandList, void* pContext)
{
D3D12_DESCRIPTOR_HEAP_DESC d3dDescriptorHeapDesc;
::ZeroMemory(&d3dDescriptorHeapDesc, sizeof(D3D12_DESCRIPTOR_HEAP_DESC));
d3dDescriptorHeapDesc.NumDescriptors = MAX_DEPTH_TEXTURES;
d3dDescriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
d3dDescriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
d3dDescriptorHeapDesc.NodeMask = 0;
HRESULT hResult = pd3dDevice->CreateDescriptorHeap(&d3dDescriptorHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&m_pd3dRtvDescriptorHeap);
m_pDepthTexture = new CTexture(MAX_DEPTH_TEXTURES, RESOURCE_TEXTURE2D_ARRAY, 0, 1);
D3D12_CLEAR_VALUE d3dClearValue = { DXGI_FORMAT_R32_FLOAT, { 1.0f, 1.0f, 1.0f, 1.0f } };
for (UINT i = 0; i < MAX_DEPTH_TEXTURES; i++)
m_pDepthTexture->CreateTexture(pd3dDevice, pd3dCommandList,i, RESOURCE_TEXTURE2D,_DEPTH_BUFFER_WIDTH, _DEPTH_BUFFER_HEIGHT,1,0, DXGI_FORMAT_R32_FLOAT, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET, D3D12_RESOURCE_STATE_COMMON, &d3dClearValue);
D3D12_RENDER_TARGET_VIEW_DESC d3dRenderTargetViewDesc;
d3dRenderTargetViewDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
d3dRenderTargetViewDesc.Texture2D.MipSlice = 0;
d3dRenderTargetViewDesc.Texture2D.PlaneSlice = 0;
d3dRenderTargetViewDesc.Format = DXGI_FORMAT_R32_FLOAT;
D3D12_CPU_DESCRIPTOR_HANDLE d3dRtvCPUDescriptorHandle = m_pd3dRtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
for (UINT i = 0; i < MAX_DEPTH_TEXTURES; i++)
{
ID3D12Resource* pd3dTextureResource = m_pDepthTexture->GetResource(i);
pd3dDevice->CreateRenderTargetView(pd3dTextureResource, &d3dRenderTargetViewDesc, d3dRtvCPUDescriptorHandle);
m_pd3dRtvCPUDescriptorHandles[i] = d3dRtvCPUDescriptorHandle;
d3dRtvCPUDescriptorHandle.ptr += ::gnRtvDescriptorIncrementSize;
}
d3dDescriptorHeapDesc.NumDescriptors = 1;
d3dDescriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
hResult = pd3dDevice->CreateDescriptorHeap(&d3dDescriptorHeapDesc, __uuidof(ID3D12DescriptorHeap), (void**)&m_pd3dDsvDescriptorHeap);
D3D12_RESOURCE_DESC d3dResourceDesc;
d3dResourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
d3dResourceDesc.Alignment = 0;
d3dResourceDesc.Width = _DEPTH_BUFFER_WIDTH;
d3dResourceDesc.Height = _DEPTH_BUFFER_HEIGHT;
d3dResourceDesc.DepthOrArraySize = 1;
d3dResourceDesc.MipLevels = 1;
d3dResourceDesc.Format = DXGI_FORMAT_D32_FLOAT;
d3dResourceDesc.SampleDesc.Count = 1;
d3dResourceDesc.SampleDesc.Quality = 0;
d3dResourceDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
d3dResourceDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
D3D12_HEAP_PROPERTIES d3dHeapProperties;
::ZeroMemory(&d3dHeapProperties, sizeof(D3D12_HEAP_PROPERTIES));
d3dHeapProperties.Type = D3D12_HEAP_TYPE_DEFAULT;
d3dHeapProperties.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
d3dHeapProperties.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
d3dHeapProperties.CreationNodeMask = 1;
d3dHeapProperties.VisibleNodeMask = 1;
d3dClearValue.Format = DXGI_FORMAT_D32_FLOAT;
d3dClearValue.DepthStencil.Depth = 1.0f;
d3dClearValue.DepthStencil.Stencil = 0;
pd3dDevice->CreateCommittedResource(&d3dHeapProperties, D3D12_HEAP_FLAG_NONE, &d3dResourceDesc, D3D12_RESOURCE_STATE_DEPTH_WRITE, &d3dClearValue, __uuidof(ID3D12Resource), (void**)&m_pd3dDepthBuffer);
D3D12_DEPTH_STENCIL_VIEW_DESC d3dDepthStencilViewDesc;
::ZeroMemory(&d3dDepthStencilViewDesc, sizeof(D3D12_DEPTH_STENCIL_VIEW_DESC));
d3dDepthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT;
d3dDepthStencilViewDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
d3dDepthStencilViewDesc.Flags = D3D12_DSV_FLAG_NONE;
m_d3dDsvDescriptorCPUHandle = m_pd3dDsvDescriptorHeap->GetCPUDescriptorHandleForHeapStart();
pd3dDevice->CreateDepthStencilView(m_pd3dDepthBuffer, &d3dDepthStencilViewDesc, m_d3dDsvDescriptorCPUHandle);
for (int i = 0; i < MAX_DEPTH_TEXTURES; i++)
{
m_ppDepthRenderCameras[i] = new CCamera();
m_ppDepthRenderCameras[i]->SetViewport(0, 0, _DEPTH_BUFFER_WIDTH, _DEPTH_BUFFER_HEIGHT, 0.0f, 1.0f);
m_ppDepthRenderCameras[i]->SetScissorRect(0, 0, _DEPTH_BUFFER_WIDTH, _DEPTH_BUFFER_HEIGHT);
m_ppDepthRenderCameras[i]->CreateShaderVariables(pd3dDevice, pd3dCommandList);
}
CreateShaderVariables(pd3dDevice, pd3dCommandList);
}
And this is the m_pShadowShader->BuildObjects function code.
void CShadowMapShader::BuildObjects(ID3D12Device* pd3dDevice, ID3D12GraphicsCommandList* pd3dCommandList, void* pContext)
{
m_pDepthTexture = (CTexture*)pContext;
m_pDepthTexture->AddRef();
//CreateCbvSrvDescriptorHeaps(pd3dDevice, 0, m_pDepthTexture->GetTextures());
//CreateShaderResourceViews(pd3dDevice, m_pDepthTexture, 0, 10);
CStage::CreateShaderResourceViews(pd3dDevice, m_pDepthTexture, 0, 10);
CreateShaderVariables(pd3dDevice, pd3dCommandList);
}
This is my github address.
https://github.com/yoon-0012/stackOverflow.git
And I have attached the project. Please check it once while you are busy.
D3D12 ERROR: ID3D12Device::CreateGraphicsPipelineState: The specified sample count or quality is not supported with the render target format in slot 1 [ STATE_CREATION ERROR #685: CREATEGRAPHICSPIPELINESTATE_INVALID_SAMPLE_DESC]
I would like to resolve this error.