diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-12-05 16:26:06 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-12-05 16:26:06 +0000 |
| commit | afbab2b5335815aac5507d564a747d32f5ae31be (patch) | |
| tree | 467b972a596310090227e18edb1d8268bf30210b /Graphics/GraphicsEngineD3D12 | |
| parent | Added ITextureD3D12::GetD3D12ResourceState(), IBufferD3D12::GetD3D12ResourceS... (diff) | |
| download | DiligentCore-afbab2b5335815aac5507d564a747d32f5ae31be.tar.gz DiligentCore-afbab2b5335815aac5507d564a747d32f5ae31be.zip | |
Minor code improvements
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp | 18 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp | 6 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/RootSignature.cpp | 50 |
3 files changed, 57 insertions, 17 deletions
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 61456e50..09776c42 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -200,7 +200,7 @@ namespace Diligent auto& CmdCtx = GetCmdContext(); - auto *pd3d12PSO = pPipelineStateD3D12->GetD3D12PipelineState(); + auto* pd3d12PSO = pPipelineStateD3D12->GetD3D12PipelineState(); if (PSODesc.IsComputePipeline) { CmdCtx.AsComputeContext().SetPipelineState(pd3d12PSO); @@ -467,7 +467,7 @@ namespace Diligent } #endif - if( DispatchAttrs.pIndirectDispatchAttribs ) + if (DispatchAttrs.pIndirectDispatchAttribs != nullptr) { auto* pBufferD3D12 = ValidatedCast<BufferD3D12Impl>(DispatchAttrs.pIndirectDispatchAttribs); @@ -477,7 +477,7 @@ namespace Diligent #endif TransitionOrVerifyBufferState(ComputeCtx, *pBufferD3D12, DispatchAttrs.IndirectAttribsBufferStateTransitionMode, - RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect dispatch (DeviceContextD3D12Impl::DispatchCompute)"); + RESOURCE_STATE_INDIRECT_ARGUMENT, "Indirect dispatch (DeviceContextD3D12Impl::DispatchCompute)"); size_t BuffDataStartByteOffset; ID3D12Resource *pd3d12ArgsBuff = pBufferD3D12->GetD3D12Buffer(BuffDataStartByteOffset, this); @@ -495,7 +495,7 @@ namespace Diligent RESOURCE_STATE_TRANSITION_MODE StateTransitionMode) { ITextureViewD3D12* pViewD3D12 = nullptr; - if( pView != nullptr ) + if (pView != nullptr) { pViewD3D12 = ValidatedCast<ITextureViewD3D12>(pView); #ifdef _DEBUG @@ -533,7 +533,7 @@ namespace Diligent void DeviceContextD3D12Impl::ClearRenderTarget( ITextureView* pView, const float* RGBA, RESOURCE_STATE_TRANSITION_MODE StateTransitionMode ) { ITextureViewD3D12* pViewD3D12 = nullptr; - if( pView != nullptr ) + if (pView != nullptr) { #ifdef _DEBUG const auto& ViewDesc = pView->GetDesc(); @@ -651,7 +651,7 @@ namespace Diligent TDeviceContextBase::SetVertexBuffers( StartSlot, NumBuffersSet, ppBuffers, pOffsets, StateTransitionMode, Flags ); auto& CmdCtx = GetCmdContext(); - for( Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff ) + for (Uint32 Buff = 0; Buff < m_NumVertexStreams; ++Buff) { auto& CurrStream = m_VertexStreams[Buff]; if (auto* pBufferD3D12 = CurrStream.pBuffer.RawPtr()) @@ -790,7 +790,7 @@ namespace Diligent ITextureViewD3D12* ppRTVs[MaxD3D12RTs]; // Do not initialize with zeroes! ITextureViewD3D12* pDSV = nullptr; - if( m_IsDefaultFramebufferBound ) + if (m_IsDefaultFramebufferBound) { if (m_pSwapChain) { @@ -817,7 +817,7 @@ namespace Diligent D3D12_CPU_DESCRIPTOR_HANDLE DSVHandle = {}; for (UINT i = 0; i < NumRenderTargets; ++i) { - if( auto* pRTV = ppRTVs[i] ) + if (auto* pRTV = ppRTVs[i]) { auto* pTexture = ValidatedCast<TextureD3D12Impl>( pRTV->GetTexture() ); TransitionOrVerifyTextureState(CmdCtx, *pTexture, StateTransitionMode, RESOURCE_STATE_RENDER_TARGET, "Setting render targets (DeviceContextD3D12Impl::CommitRenderTargets)"); @@ -876,7 +876,7 @@ namespace Diligent VERIFY_EXPR( static_cast<size_t>(NumBytes) == NumBytes ); TransitionOrVerifyBufferState(CmdCtx, *pBuffD3D12, StateTransitionMode, RESOURCE_STATE_COPY_DEST, "Updating buffer (DeviceContextD3D12Impl::UpdateBufferRegion)"); size_t DstBuffDataStartByteOffset; - auto *pd3d12Buff = pBuffD3D12->GetD3D12Buffer(DstBuffDataStartByteOffset, this); + auto* pd3d12Buff = pBuffD3D12->GetD3D12Buffer(DstBuffDataStartByteOffset, this); VERIFY(DstBuffDataStartByteOffset == 0, "Dst buffer must not be suballocated"); CmdCtx.FlushResourceBarriers(); CmdCtx.GetCommandList()->CopyBufferRegion( pd3d12Buff, DstOffset + DstBuffDataStartByteOffset, Allocation.pBuffer, Allocation.Offset, NumBytes); diff --git a/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp b/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp index c07b07b8..623a3b70 100644 --- a/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp +++ b/Graphics/GraphicsEngineD3D12/src/GenerateMips.cpp @@ -112,6 +112,12 @@ namespace Diligent auto& TexDesc = pTexture->GetDesc(); auto SRVDescriptorHandle = pTexD3D12->GetTexArraySRV(); + if (!pTexD3D12->IsInKnownState()) + { + LOG_ERROR_MESSAGE("Unable to generate mips for texture '", TexDesc.Name, "' because the texture state is unknown"); + return; + } + if (pTexD3D12->IsInKnownState() && !pTexD3D12->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) Ctx.TransitionResource(pTexD3D12, RESOURCE_STATE_UNORDERED_ACCESS); auto* pd3d12Device = pRenderDeviceD3D12->GetD3D12Device(); diff --git a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp index 8278a4e2..82480da5 100644 --- a/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp +++ b/Graphics/GraphicsEngineD3D12/src/RootSignature.cpp @@ -753,7 +753,11 @@ void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res, // Not using QueryInterface() for the sake of efficiency const auto* pBufferD3D12 = Res.pObject.RawPtr<const BufferD3D12Impl>(); if (pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_CONSTANT_BUFFER)) - LOG_ERROR_MESSAGE("Resource '", pBufferD3D12->GetDesc().Name, "' is not in RESOURCE_STATE_CONSTANT_BUFFER state. Did you forget to call TransitionShaderResources() or specify RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode in a call to CommitShaderResources()?" ); + LOG_ERROR_MESSAGE("Buffer '", pBufferD3D12->GetDesc().Name, "' must be in RESOURCE_STATE_CONSTANT_BUFFER state. Actual state: ", + GetResourceStateString(pBufferD3D12->GetState()), + ". Call IDeviceContext::TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION " + "when calling IDeviceContext::CommitShaderResources() or explicitly transition the buffer state " + "with IDeviceContext::TransitionResourceStates()." ); } break; @@ -763,7 +767,11 @@ void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res, const auto* pBuffViewD3D12 = Res.pObject.RawPtr<const BufferViewD3D12Impl>(); const auto* pBufferD3D12 = pBuffViewD3D12->GetBuffer<const BufferD3D12Impl>(); if (pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) - LOG_ERROR_MESSAGE("Resource '", pBufferD3D12->GetDesc().Name, "' is not in RESOURCE_STATE_SHADER_RESOURCE state. Did you forget to call TransitionShaderResources() or specify RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode in a call to CommitShaderResources()?" ); + LOG_ERROR_MESSAGE("Buffer '", pBufferD3D12->GetDesc().Name, "' must be in RESOURCE_STATE_SHADER_RESOURCE state. Actual state: ", + GetResourceStateString(pBufferD3D12->GetState()), + ". Call IDeviceContext::TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION " + "when calling IDeviceContext::CommitShaderResources() or explicitly transition the buffer state " + "with IDeviceContext::TransitionResourceStates()." ); } break; @@ -773,7 +781,11 @@ void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res, const auto* pBuffViewD3D12 = Res.pObject.RawPtr<const BufferViewD3D12Impl>(); const auto* pBufferD3D12 = pBuffViewD3D12->GetBuffer<const BufferD3D12Impl>(); if (pBufferD3D12->IsInKnownState() && !pBufferD3D12->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - LOG_ERROR_MESSAGE("Resource '", pBufferD3D12->GetDesc().Name, "' is not in RESOURCE_STATE_UNORDERED_ACCESS state. Did you forget to call TransitionShaderResources() or specify RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode in a call to CommitShaderResources()?" ); + LOG_ERROR_MESSAGE("Buffer '", pBufferD3D12->GetDesc().Name, "' must be in RESOURCE_STATE_UNORDERED_ACCESS state. Actual state: ", + GetResourceStateString(pBufferD3D12->GetState()), + ". Call IDeviceContext::TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION " + "when calling IDeviceContext::CommitShaderResources() or explicitly transition the buffer state " + "with IDeviceContext::TransitionResourceStates()." ); } break; @@ -783,7 +795,11 @@ void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res, const auto* pTexViewD3D12 = Res.pObject.RawPtr<const TextureViewD3D12Impl>(); const auto* pTexD3D12 = pTexViewD3D12->GetTexture<TextureD3D12Impl>(); if (pTexD3D12->IsInKnownState() && !pTexD3D12->CheckState(RESOURCE_STATE_SHADER_RESOURCE)) - LOG_ERROR_MESSAGE("Resource '", pTexD3D12->GetDesc().Name, "' is not in RESOURCE_STATE_SHADER_RESOURCE state. Did you forget to call TransitionShaderResources() or specify RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode in a call to CommitShaderResources()?" ); + LOG_ERROR_MESSAGE("Texture '", pTexD3D12->GetDesc().Name, "' must be in RESOURCE_STATE_SHADER_RESOURCE state. Actual state: ", + GetResourceStateString(pTexD3D12->GetState()), + ". Call IDeviceContext::TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION " + "when calling IDeviceContext::CommitShaderResources() or explicitly transition the texture state " + "with IDeviceContext::TransitionResourceStates()." ); } break; @@ -793,7 +809,11 @@ void DvpVerifyResourceState(const ShaderResourceCacheD3D12::Resource& Res, const auto* pTexViewD3D12 = Res.pObject.RawPtr<const TextureViewD3D12Impl>(); const auto* pTexD3D12 = pTexViewD3D12->GetTexture<const TextureD3D12Impl>(); if (pTexD3D12->IsInKnownState() && !pTexD3D12->CheckState(RESOURCE_STATE_UNORDERED_ACCESS)) - LOG_ERROR_MESSAGE("Resource '", pTexD3D12->GetDesc().Name, "' is not in RESOURCE_STATE_UNORDERED_ACCESS state. Did you forget to call TransitionShaderResources() or specify RESOURCE_STATE_TRANSITION_MODE_TRANSITION mode in a call to CommitShaderResources()?" ); + LOG_ERROR_MESSAGE("Texture '", pTexD3D12->GetDesc().Name, "' must be in RESOURCE_STATE_UNORDERED_ACCESS state. Actual state: ", + GetResourceStateString(pTexD3D12->GetState()), + ". Call IDeviceContext::TransitionShaderResources(), use RESOURCE_STATE_TRANSITION_MODE_TRANSITION " + "when calling IDeviceContext::CommitShaderResources() or explicitly transition the texture state " + "with IDeviceContext::TransitionResourceStates()." ); } break; @@ -942,9 +962,15 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* VERIFY( DynamicCbvSrvUavTblOffset < NumDynamicCbvSrvUavDescriptors, "Not enough space in the descriptor heap allocation"); if (Res.CPUDescriptorHandle.ptr != 0) + { pd3d12Device->CopyDescriptorsSimple(1, DynamicCbvSrvUavDescriptors.GetCpuHandle(DynamicCbvSrvUavTblOffset), Res.CPUDescriptorHandle, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + } +#ifdef DEVELOPMENT else + { LOG_ERROR_MESSAGE("No valid CbvSrvUav descriptor handle found for root parameter ", RootInd, ", descriptor slot ", OffsetFromTableStart); + } +#endif ++DynamicCbvSrvUavTblOffset; } @@ -953,9 +979,15 @@ void RootSignature::CommitDescriptorHandlesInternal_SMD(RenderDeviceD3D12Impl* VERIFY( DynamicSamplerTblOffset < NumDynamicSamplerDescriptors, "Not enough space in the descriptor heap allocation"); if (Res.CPUDescriptorHandle.ptr != 0) + { pd3d12Device->CopyDescriptorsSimple(1, DynamicSamplerDescriptors.GetCpuHandle(DynamicSamplerTblOffset), Res.CPUDescriptorHandle, D3D12_DESCRIPTOR_HEAP_TYPE_SAMPLER); + } +#ifdef DEVELOPMENT else + { LOG_ERROR_MESSAGE("No valid sampler descriptor handle found for root parameter ", RootInd, ", descriptor slot ", OffsetFromTableStart); + } +#endif ++DynamicSamplerTblOffset; } @@ -1051,9 +1083,11 @@ void RootSignature::CommitRootViews(ShaderResourceCacheD3D12& ResourceCache, SHADER_TYPE dbgShaderType = SHADER_TYPE_UNKNOWN; #ifdef _DEBUG - auto& Param = static_cast<const D3D12_ROOT_PARAMETER&>( RootView ); - VERIFY_EXPR(Param.ParameterType == D3D12_ROOT_PARAMETER_TYPE_CBV); - dbgShaderType = ShaderTypeFromShaderVisibility(Param.ShaderVisibility); + { + auto& Param = static_cast<const D3D12_ROOT_PARAMETER&>( RootView ); + VERIFY_EXPR(Param.ParameterType == D3D12_ROOT_PARAMETER_TYPE_CBV); + dbgShaderType = ShaderTypeFromShaderVisibility(Param.ShaderVisibility); + } #endif auto& Res = ResourceCache.GetRootTable(RootInd).GetResource(0, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, dbgShaderType); |
