summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3D11
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2016-08-25 03:20:56 +0000
committerEgor Yusov <egor.yusov@gmail.com>2016-08-25 03:20:56 +0000
commit8acffab86d2bb95ebf349b64675e86fcd2f9f044 (patch)
treecd3fcd69e8b6f298a44e101afd056d5663275424 /Graphics/GraphicsEngineD3D11
parentUpdated to Diligent Engine 2.0 (diff)
downloadDiligentCore-8acffab86d2bb95ebf349b64675e86fcd2f9f044.tar.gz
DiligentCore-8acffab86d2bb95ebf349b64675e86fcd2f9f044.zip
Merged updates from dev branch
Diffstat (limited to 'Graphics/GraphicsEngineD3D11')
-rw-r--r--Graphics/GraphicsEngineD3D11/include/ShaderResourceCacheD3D11.h39
-rw-r--r--Graphics/GraphicsEngineD3D11/src/ShaderResourceLayoutD3D11.cpp55
2 files changed, 92 insertions, 2 deletions
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." )
}
}