@@ -458,8 +458,9 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
458458 return ret;
459459 }
460460
461- ID3D12PipelineState* GetOrCreatePipelineState (DXGI_FORMAT swapchainFormat) {
462- auto iter = m_pipelineStates.find (swapchainFormat);
461+ ID3D12PipelineState* GetOrCreatePipelineState (DXGI_FORMAT colorSwapchainFormat, DXGI_FORMAT depthSwapchainFormat) {
462+ auto swapchainFormats = std::make_pair (colorSwapchainFormat, depthSwapchainFormat);
463+ auto iter = m_pipelineStates.find (swapchainFormats);
463464 if (iter != m_pipelineStates.end ()) {
464465 return iter->second .Get ();
465466 }
@@ -525,8 +526,8 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
525526 pipelineStateDesc.IBStripCutValue = D3D12_INDEX_BUFFER_STRIP_CUT_VALUE_0xFFFF;
526527 pipelineStateDesc.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE;
527528 pipelineStateDesc.NumRenderTargets = 1 ;
528- pipelineStateDesc.RTVFormats [0 ] = swapchainFormat ;
529- pipelineStateDesc.DSVFormat = DXGI_FORMAT_D32_FLOAT ;
529+ pipelineStateDesc.RTVFormats [0 ] = colorSwapchainFormat ;
530+ pipelineStateDesc.DSVFormat = depthSwapchainFormat ;
530531 pipelineStateDesc.SampleDesc = {1 , 0 };
531532 pipelineStateDesc.NodeMask = 0 ;
532533 pipelineStateDesc.CachedPSO = {nullptr , 0 };
@@ -537,13 +538,13 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
537538 reinterpret_cast <void **>(pipelineState.ReleaseAndGetAddressOf ())));
538539 ID3D12PipelineState* pipelineStateRaw = pipelineState.Get ();
539540
540- m_pipelineStates.emplace (swapchainFormat , std::move (pipelineState));
541+ m_pipelineStates.emplace (swapchainFormats , std::move (pipelineState));
541542
542543 return pipelineStateRaw;
543544 }
544545
545546 void RenderView (const XrCompositionLayerProjectionView& layerView, const XrSwapchainImageBaseHeader* swapchainImage,
546- int64_t swapchainFormat , const std::vector<Cube>& cubes) override {
547+ int64_t colorSwapchainFormat, int64_t depthSwapchainFormat , const std::vector<Cube>& cubes) override {
547548 CHECK (layerView.subImage .imageArrayIndex == 0 ); // Texture arrays not supported.
548549
549550 D3D12SwapchainImageData* swapchainData;
@@ -561,7 +562,8 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
561562 0 , D3D12_COMMAND_LIST_TYPE_DIRECT, swapchainData->GetCommandAllocator (), nullptr , __uuidof (ID3D12GraphicsCommandList),
562563 reinterpret_cast <void **>(cmdList.ReleaseAndGetAddressOf ())));
563564
564- ID3D12PipelineState* pipelineState = GetOrCreatePipelineState ((DXGI_FORMAT)swapchainFormat);
565+ ID3D12PipelineState* pipelineState =
566+ GetOrCreatePipelineState ((DXGI_FORMAT)colorSwapchainFormat, (DXGI_FORMAT)depthSwapchainFormat);
565567 cmdList->SetPipelineState (pipelineState);
566568 cmdList->SetGraphicsRootSignature (m_rootSignature.Get ());
567569
@@ -584,7 +586,7 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
584586 // Create RenderTargetView with original swapchain format (swapchain is typeless).
585587 D3D12_CPU_DESCRIPTOR_HANDLE renderTargetView = m_rtvHeap->GetCPUDescriptorHandleForHeapStart ();
586588 D3D12_RENDER_TARGET_VIEW_DESC renderTargetViewDesc{};
587- renderTargetViewDesc.Format = (DXGI_FORMAT)swapchainFormat ;
589+ renderTargetViewDesc.Format = (DXGI_FORMAT)colorSwapchainFormat ;
588590 if (colorTextureDesc.DepthOrArraySize > 1 ) {
589591 if (colorTextureDesc.SampleDesc .Count > 1 ) {
590592 renderTargetViewDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2DMSARRAY;
@@ -606,7 +608,7 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
606608 const D3D12_RESOURCE_DESC depthStencilTextureDesc = depthStencilTexture->GetDesc ();
607609 D3D12_CPU_DESCRIPTOR_HANDLE depthStencilView = m_dsvHeap->GetCPUDescriptorHandleForHeapStart ();
608610 D3D12_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc{};
609- depthStencilViewDesc.Format = DXGI_FORMAT_D32_FLOAT ;
611+ depthStencilViewDesc.Format = (DXGI_FORMAT)depthSwapchainFormat ;
610612 if (depthStencilTextureDesc.DepthOrArraySize > 1 ) {
611613 if (depthStencilTextureDesc.SampleDesc .Count > 1 ) {
612614 depthStencilViewDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2DMSARRAY;
@@ -730,7 +732,7 @@ struct D3D12GraphicsPlugin : public IGraphicsPlugin {
730732 SwapchainImageDataMap<D3D12SwapchainImageData> m_swapchainImageDataMap;
731733 XrGraphicsBindingD3D12KHR m_graphicsBinding{XR_TYPE_GRAPHICS_BINDING_D3D12_KHR};
732734 ComPtr<ID3D12RootSignature> m_rootSignature;
733- std::map<DXGI_FORMAT, ComPtr<ID3D12PipelineState>> m_pipelineStates;
735+ std::map<std::pair< DXGI_FORMAT, DXGI_FORMAT> , ComPtr<ID3D12PipelineState>> m_pipelineStates;
734736 ComPtr<ID3D12Resource> m_cubeVertexBuffer;
735737 ComPtr<ID3D12Resource> m_cubeIndexBuffer;
736738 ComPtr<ID3D12DescriptorHeap> m_rtvHeap;
0 commit comments