diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2016-08-25 03:20:56 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2016-08-25 03:20:56 +0000 |
| commit | 8acffab86d2bb95ebf349b64675e86fcd2f9f044 (patch) | |
| tree | cd3fcd69e8b6f298a44e101afd056d5663275424 /Graphics | |
| parent | Updated to Diligent Engine 2.0 (diff) | |
| download | DiligentCore-8acffab86d2bb95ebf349b64675e86fcd2f9f044.tar.gz DiligentCore-8acffab86d2bb95ebf349b64675e86fcd2f9f044.zip | |
Merged updates from dev branch
Diffstat (limited to 'Graphics')
4 files changed, 103 insertions, 4 deletions
diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index 15d81342..47641ce6 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -246,6 +246,15 @@ public: /// be assigned to a constant buffer variable. virtual void Set(IDeviceObject *pObject) = 0; + /// Sets the variable array + + /// \param [in] ppObjects - pointer to the array of objects + /// \param [in] FirstElement - first array element to set + /// \param [in] NumElements - number of objects in ppObjects array + /// + /// \remark The method performs run-time correctness checks. + /// For instance, shader resource view cannot + /// be assigned to a constant buffer variable. virtual void SetArray(IDeviceObject* const* ppObjects, Uint32 FirstElement, Uint32 NumElements) = 0; }; diff --git a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h index 0964ba9c..f0d4c982 100644 --- a/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h +++ b/Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h @@ -154,6 +154,45 @@ public: SetD3D11ResourceInternal<CachedSampler>(Slot, GetSamplerCount(), &ShaderResourceCacheD3D11::GetSamplerArrays, pSampler, pd3d11Sampler); } + + + __forceinline CachedCB& GetCB(Uint32 Slot) + { + VERIFY(Slot < GetCBCount(), "CB slot is out of range" ); + ShaderResourceCacheD3D11::CachedCB *CBs; + ID3D11Buffer **pd3d11CBs; + GetCBArrays(CBs, pd3d11CBs); + return CBs[Slot]; + } + + __forceinline CachedResource& GetSRV(Uint32 Slot) + { + VERIFY(Slot < GetSRVCount(), "SRV slot is out of range" ); + ShaderResourceCacheD3D11::CachedResource *SRVResources; + ID3D11ShaderResourceView **pd3d11SRVs; + GetSRVArrays(SRVResources, pd3d11SRVs); + return SRVResources[Slot]; + } + + __forceinline CachedResource& GetUAV(Uint32 Slot) + { + VERIFY(Slot < GetUAVCount(), "UAV slot is out of range" ); + ShaderResourceCacheD3D11::CachedResource *UAVResources; + ID3D11UnorderedAccessView **pd3d11UAVs; + GetUAVArrays(UAVResources, pd3d11UAVs); + return UAVResources[Slot]; + } + + __forceinline CachedSampler& GetSampler(Uint32 Slot) + { + VERIFY(Slot < GetSamplerCount(), "Sampler slot is out of range" ); + ShaderResourceCacheD3D11::CachedSampler *Samplers; + ID3D11SamplerState **pd3d11Samplers; + GetSamplerArrays(Samplers, pd3d11Samplers); + return Samplers[Slot]; + } + + __forceinline bool IsCBBound(Uint32 Slot)const { CachedCB* CBs = nullptr; diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp index 00fb3549..d7c8eb1a 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp @@ -363,6 +363,17 @@ void ShaderResourceLayoutD3D11::ConstBuffBindInfo::BindResource(IDeviceObject *p } } +#ifdef VERIFY_SHADER_BINDINGS + if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto &CachedCB = pResourceCache->GetCB(Attribs.BindPoint + ArrayIndex); + if( CachedCB.pBuff != nullptr && CachedCB.pBuff != pBuffD3D11Impl) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null constant buffer is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + } + } +#endif pResourceCache->SetCB(Attribs.BindPoint + ArrayIndex, std::move(pBuffD3D11Impl) ); } @@ -421,6 +432,16 @@ void ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::BindResource( IDeviceObje LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: texture view is expected.") if(pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); + + if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto &CachedSRV = pResourceCache->GetSRV(Attribs.BindPoint + ArrayIndex); + if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null texture SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + } + } #endif if( SamplerAttribs.IsValidBindPoint() ) @@ -452,7 +473,7 @@ void ShaderResourceLayoutD3D11::TexAndSamplerBindInfo::BindResource( IDeviceObje VERIFY( pResourceCache->IsSamplerBound(SamplerBindPoint), "Static samplers must be bound once when shader cache is created" ); } } - + pResourceCache->SetTexSRV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11)); } @@ -472,6 +493,16 @@ void ShaderResourceLayoutD3D11::BuffSRVBindInfo::BindResource( IDeviceObject *pV LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: buffer view is expected.") if(pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_SHADER_RESOURCE, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); + + if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto &CachedSRV = pResourceCache->GetSRV(Attribs.BindPoint + ArrayIndex); + if( CachedSRV.pView != nullptr && CachedSRV.pView != pViewD3D11) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null buffer SRV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + } + } #endif pResourceCache->SetBufSRV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11)); @@ -493,6 +524,16 @@ void ShaderResourceLayoutD3D11::TexUAVBindInfo::BindResource( IDeviceObject *pVi LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: texture view is expected.") if(pViewD3D11 && !dbgVerifyViewType("texture view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, TEXTURE_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName())) pViewD3D11.Release(); + + if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto &CachedUAV = pResourceCache->GetUAV(Attribs.BindPoint + ArrayIndex); + if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null texture UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + } + } #endif pResourceCache->SetTexUAV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11)); @@ -514,6 +555,16 @@ void ShaderResourceLayoutD3D11::BuffUAVBindInfo::BindResource( IDeviceObject *pV LOG_RESOURCE_BINDING_ERROR("resource", pView, Attribs, ArrayIndex, "", "Incorect resource type: buffer view is expected.") if(pViewD3D11 && !dbgVerifyViewType("buffer view", pViewD3D11.RawPtr(), Attribs, ArrayIndex, BUFFER_VIEW_UNORDERED_ACCESS, m_ParentResLayout.GetShaderName()) ) pViewD3D11.Release(); + + if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC) + { + auto &CachedUAV = pResourceCache->GetUAV(Attribs.BindPoint + ArrayIndex); + if( CachedUAV.pView != nullptr && CachedUAV.pView != pViewD3D11) + { + auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); + LOG_ERROR_MESSAGE( "Non-null buffer UAV is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + } + } #endif pResourceCache->SetBufUAV(Attribs.BindPoint + ArrayIndex, std::move(pViewD3D11)); @@ -741,7 +792,7 @@ void ShaderResourceLayoutD3D11::dbgVerifyBindings()const { auto *pTexView = ValidatedCast<ITextureView>(CachedResource.pView.RawPtr()); auto *pSampler = pTexView->GetSampler(); - if(pSampler != Sampler.pSampler.RawPtr()) + if(pSampler != nullptr && pSampler != Sampler.pSampler.RawPtr()) LOG_ERROR_MESSAGE( "All elements of texture array \"", ts.Attribs.Name, "\" in shader \"", GetShaderName(), "\" share the same sampler. However, the sampler set in view for element ", BindPoint - ts.Attribs.BindPoint, " does not match bound sampler. This may cause incorrect behavior on GL platform." ) } } diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp index e0121db7..924131e4 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderResourceLayoutD3D12.cpp @@ -480,7 +480,7 @@ void ShaderResourceLayoutD3D12::SRV_CBV_UAV::CacheResourceView(IDeviceObject *pV if( Attribs.GetVariableType() != SHADER_VARIABLE_TYPE_DYNAMIC && DstRes.pObject != nullptr && DstRes.pObject != pViewD3D12) { auto VarTypeStr = GetShaderVariableTypeLiteralName(Attribs.GetVariableType()); - LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); + LOG_ERROR_MESSAGE( "Non-null resource is already bound to ", VarTypeStr, " shader variable \"", Attribs.GetPrintName(ArrayIndex), "\" in shader \"", m_ParentResLayout.GetShaderName(), "\". Attempting to bind another resource or null is an error and may cause unpredicted behavior. Use another shader resource binding instance or mark shader variable as dynamic." ); } DstRes.Type = GetResType(); @@ -907,7 +907,7 @@ void ShaderResourceLayoutD3D12::dbgVerifyBindings()const if( auto *pTexView = ValidatedCast<const ITextureView>(CachedRes.pObject.RawPtr()) ) { auto *pSampler = const_cast<ITextureView*>(pTexView)->GetSampler(); - if (CachedSampler.pObject != pSampler) + if (pSampler != nullptr && CachedSampler.pObject != pSampler) LOG_ERROR_MESSAGE( "All elements of texture array \"", res.Attribs.Name, "\" in shader \"", GetShaderName(), "\" share the same sampler. However, the sampler set in view for element ", ArrInd, " does not match bound sampler. This may cause incorrect behavior on GL platform." ) } } |
