summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorEgor Yusov <egor.yusov@gmail.com>2019-03-03 06:31:12 +0000
committerEgor Yusov <egor.yusov@gmail.com>2019-03-03 06:31:12 +0000
commitc1470ef074418b5b238e0a461242f4c24b660ba2 (patch)
treeab37f797bf9765c622879a4f68c675bcb95c9688 /Graphics/GraphicsEngineD3DBase
parentA bunch of updates to ShaderResourceLayoutVk (diff)
downloadDiligentCore-c1470ef074418b5b238e0a461242f4c24b660ba2.tar.gz
DiligentCore-c1470ef074418b5b238e0a461242f4c24b660ba2.zip
Reworked ShaderD3DBase to comply with the updated API
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h95
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h3
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.h110
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h8
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp70
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp54
6 files changed, 66 insertions, 274 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h
index 511f436e..c2c6e402 100644
--- a/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h
+++ b/Graphics/GraphicsEngineD3DBase/include/D3DShaderResourceLoader.h
@@ -57,17 +57,13 @@ namespace Diligent
typename TOnNewSampler,
typename TOnNewTexSRV>
void LoadD3DShaderResources(ID3DBlob* pShaderByteCode,
-
TOnResourcesCounted OnResourcesCounted,
TOnNewCB OnNewCB,
TOnNewTexUAV OnNewTexUAV,
TOnNewBuffUAV OnNewBuffUAV,
TOnNewBuffSRV OnNewBuffSRV,
TOnNewSampler OnNewSampler,
- TOnNewTexSRV OnNewTexSRV,
-
- const ShaderDesc& ShdrDesc,
- const Char* SamplerSuffix)
+ TOnNewTexSRV OnNewTexSRV)
{
CComPtr<TShaderReflection> pShaderReflection;
auto hr = D3DReflect( pShaderByteCode->GetBufferPointer(), pShaderByteCode->GetBufferSize(), __uuidof(pShaderReflection), reinterpret_cast<void**>(static_cast<TShaderReflection**>(&pShaderReflection)));
@@ -80,13 +76,11 @@ namespace Diligent
Resources.reserve(shaderDesc.BoundResources);
std::unordered_set<std::string> ResourceNamesTmpPool;
- const bool UseCombinedTextureSamplers = SamplerSuffix != nullptr;
-
D3DShaderResourceCounters RC;
size_t ResourceNamesPoolSize = 0;
// Number of resources to skip (used for array resources)
UINT SkipCount = 1;
- for( UINT Res = 0; Res < shaderDesc.BoundResources; Res += SkipCount )
+ for (UINT Res = 0; Res < shaderDesc.BoundResources; Res += SkipCount)
{
D3D_SHADER_INPUT_BIND_DESC BindingDesc = {};
pShaderReflection->GetResourceBindingDesc( Res, &BindingDesc );
@@ -128,7 +122,7 @@ namespace Diligent
VERIFY(Name.compare(ExistingRes.Name) != 0, "Resource with the same name has already been enumerated. All array elements are expected to be enumerated one after another");
}
#endif
- for( UINT ArrElem = Res+1; ArrElem < shaderDesc.BoundResources; ++ArrElem)
+ for (UINT ArrElem = Res+1; ArrElem < shaderDesc.BoundResources; ++ArrElem)
{
D3D_SHADER_INPUT_BIND_DESC ArrElemBindingDesc = {};
pShaderReflection->GetResourceBindingDesc( ArrElem, &ArrElemBindingDesc );
@@ -156,32 +150,6 @@ namespace Diligent
}
}
-
- SHADER_VARIABLE_TYPE VarType = SHADER_VARIABLE_TYPE_NUM_TYPES;
- bool IsStaticSampler = false;
- if (BindingDesc.Type == D3D_SIT_SAMPLER)
- {
- for (Uint32 s = 0; s < ShdrDesc.NumStaticSamplers; ++s)
- {
- if (StreqSuff(Name.c_str(), ShdrDesc.StaticSamplers[s].SamplerOrTextureName, SamplerSuffix))
- {
- IsStaticSampler = true;
- break;
- }
- }
- // Use texture or sampler name to derive sampler type
- VarType = GetShaderVariableType(ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables,
- [&](const char* VarName)
- {
- return StreqSuff(Name.c_str(), VarName, SamplerSuffix);
- });
- }
- else
- {
- VarType = GetShaderVariableType(Name, ShdrDesc.DefaultVariableType, ShdrDesc.VariableDesc, ShdrDesc.NumVariables);
- }
-
-
switch( BindingDesc.Type )
{
case D3D_SIT_CBUFFER: ++RC.NumCBs; break;
@@ -205,68 +173,17 @@ namespace Diligent
BindingDesc.BindPoint,
BindCount,
BindingDesc.Type,
- VarType,
BindingDesc.Dimension,
- D3DShaderResourceAttribs::InvalidSamplerId,
- IsStaticSampler
+ D3DShaderResourceAttribs::InvalidSamplerId
);
}
-
-#ifdef DEVELOPMENT
- for (Uint32 v = 0; v < ShdrDesc.NumVariables; ++v)
- {
- bool VariableFound = false;
- const auto* VarName = ShdrDesc.VariableDesc[v].Name;
-
- for (const auto& Res : Resources)
- {
- // Skip samplers if combined texture samplers are used as
- // in this case they are not treated as independent variables
- if (UseCombinedTextureSamplers && Res.GetInputType() == D3D_SIT_SAMPLER)
- continue;
-
- VariableFound = (strcmp(Res.Name, VarName) == 0);
- if (VariableFound)
- break;
- }
- if(!VariableFound)
- {
- LOG_WARNING_MESSAGE("Variable '", VarName, "' is not found in shader '", ShdrDesc.Name, '\'');
- }
- }
-
- for (Uint32 s = 0; s < ShdrDesc.NumStaticSamplers; ++s)
- {
- const auto* TexOrSamName = ShdrDesc.StaticSamplers[s].SamplerOrTextureName;
-
- bool TextureOrSamplerFound = false;
- for (const auto& Res : Resources)
- {
- if( UseCombinedTextureSamplers && Res.GetInputType() == D3D_SIT_TEXTURE && Res.GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER ||
- !UseCombinedTextureSamplers && Res.GetInputType() == D3D_SIT_SAMPLER)
- {
- TextureOrSamplerFound = (strcmp(Res.Name, TexOrSamName) == 0);
- if (TextureOrSamplerFound)
- break;
- }
- }
- if (!TextureOrSamplerFound)
- {
- if (UseCombinedTextureSamplers)
- LOG_WARNING_MESSAGE("Static sampler specifies a texture '", TexOrSamName, "' that is not found in shader '", ShdrDesc.Name, '\'');
- else
- LOG_WARNING_MESSAGE("Static sampler '", TexOrSamName, "' is not found in shader '", ShdrDesc.Name, '\'');
- }
- }
-#endif
-
OnResourcesCounted(RC, ResourceNamesPoolSize);
std::vector<size_t, STDAllocatorRawMem<size_t> > TexSRVInds( STD_ALLOCATOR_RAW_MEM(size_t, GetRawAllocator(), "Allocator for vector<size_t>") );
TexSRVInds.reserve(RC.NumTexSRVs);
- for(size_t ResInd = 0; ResInd < Resources.size(); ++ResInd)
+ for (size_t ResInd = 0; ResInd < Resources.size(); ++ResInd)
{
const auto& Res = Resources[ResInd];
switch (Res.GetInputType())
@@ -368,7 +285,7 @@ namespace Diligent
// Process texture SRVs. We need to do this after all samplers are initialized
for (auto TexSRVInd : TexSRVInds)
{
- OnNewTexSRV( Resources[TexSRVInd] );
+ OnNewTexSRV(Resources[TexSRVInd]);
}
}
}
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h
index e7b1d10f..7f2eda96 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderD3DBase.h
@@ -36,10 +36,9 @@ namespace Diligent
class ShaderD3DBase
{
public:
- ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs);
+ ShaderD3DBase(const ShaderCreateInfo& ShaderCI);
protected:
-
CComPtr<ID3DBlob> m_pShaderByteCode;
};
}
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
index 3cc19fa7..aa3867f3 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.h
@@ -66,23 +66,6 @@
namespace Diligent
{
-inline bool IsAllowedType(SHADER_VARIABLE_TYPE VarType, Uint32 AllowedTypeBits)noexcept
-{
- return ((1 << VarType) & AllowedTypeBits) != 0;
-}
-
-inline Uint32 GetAllowedTypeBits(const SHADER_VARIABLE_TYPE* AllowedVarTypes, Uint32 NumAllowedTypes)noexcept
-{
- if (AllowedVarTypes == nullptr)
- return 0xFFFFFFFF;
-
- Uint32 AllowedTypeBits = 0;
- for (Uint32 i=0; i < NumAllowedTypes; ++i)
- AllowedTypeBits |= 1 << AllowedVarTypes[i];
- return AllowedTypeBits;
-}
-
-
struct D3DShaderResourceAttribs
{
const char* const Name;
@@ -91,19 +74,16 @@ struct D3DShaderResourceAttribs
const Uint16 BindCount;
private:
- // 4 3 4 20 1
- // bit | 0 1 2 3 | 4 5 6 | 7 8 9 10 | 11 12 13 ... 30 | 31 |
- // | | | | | |
- // | InputType | VariableType | SRV Dim | SamplerOrTexSRVIdBits | StaticSamplerFlag |
+ // 4 4 24
+ // bit | 0 1 2 3 | 4 5 6 7 | 8 9 10 ... 31 |
+ // | | | |
+ // | InputType | SRV Dim | SamplerOrTexSRVIdBits |
static constexpr const Uint32 ShaderInputTypeBits = 4;
- static constexpr const Uint32 VariableTypeBits = 3;
static constexpr const Uint32 SRVDimBits = 4;
- static constexpr const Uint32 SamplerOrTexSRVIdBits = 20;
- static constexpr const Uint32 StaticSamplerFlagBits = 1;
- static_assert(ShaderInputTypeBits + VariableTypeBits + SRVDimBits + SamplerOrTexSRVIdBits + StaticSamplerFlagBits == 32, "Attributes are better be packed into 32 bits");
+ static constexpr const Uint32 SamplerOrTexSRVIdBits = 24;
+ static_assert(ShaderInputTypeBits + SRVDimBits + SamplerOrTexSRVIdBits == 32, "Attributes are better be packed into 32 bits");
static_assert(D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER < (1 << ShaderInputTypeBits), "Not enough bits to represent D3D_SHADER_INPUT_TYPE");
- static_assert(SHADER_VARIABLE_TYPE_NUM_TYPES < (1 << VariableTypeBits), "Not enough bits to represent SHADER_VARIABLE_TYPE");
static_assert(D3D_SRV_DIMENSION_BUFFEREX < (1 << SRVDimBits), "Not enough bits to represent D3D_SRV_DIMENSION");
// We need to use Uint32 instead of the actual type for reliability and correctness.
@@ -111,11 +91,8 @@ private:
// the value of D3D_SIT_UAV_RWBYTEADDRESS (8) was interpreted as -8 (as the underlying enum type
// is signed) causing errors
const Uint32 InputType : ShaderInputTypeBits; // Max value: D3D_SIT_UAV_RWSTRUCTURED_WITH_COUNTER == 11
- const Uint32 VariableType : VariableTypeBits; // Max value: SHADER_VARIABLE_TYPE_DYNAMIC == 2
const Uint32 SRVDimension : SRVDimBits; // Max value: D3D_SRV_DIMENSION_BUFFEREX == 11
Uint32 SamplerOrTexSRVId : SamplerOrTexSRVIdBits; // Max value: 1048575
- const Uint32 StaticSamplerFlag : StaticSamplerFlagBits; // Needs to be Uint32, otherwise sizeof(D3DShaderResourceAttribs)==24
- // (https://stackoverflow.com/questions/308364/c-bitfield-packing-with-bools)
public:
static constexpr const Uint32 InvalidSamplerId = (1 << SamplerOrTexSRVIdBits) - 1;
@@ -129,39 +106,26 @@ public:
UINT _BindPoint,
UINT _BindCount,
D3D_SHADER_INPUT_TYPE _InputType,
- SHADER_VARIABLE_TYPE _VariableType,
D3D_SRV_DIMENSION _SRVDimension,
- Uint32 _SamplerId,
- bool _IsStaticSampler)noexcept :
+ Uint32 _SamplerId)noexcept :
Name (_Name),
BindPoint (static_cast<decltype(BindPoint)> (_BindPoint)),
BindCount (static_cast<decltype(BindCount)> (_BindCount)),
InputType (static_cast<decltype(InputType)> (_InputType)),
- VariableType (static_cast<decltype(VariableType)>(_VariableType)),
SRVDimension (static_cast<decltype(SRVDimension)>(_SRVDimension)),
- SamplerOrTexSRVId (_SamplerId),
- StaticSamplerFlag (_IsStaticSampler ? 1 : 0)
+ SamplerOrTexSRVId (_SamplerId)
{
#ifdef _DEBUG
VERIFY(_BindPoint <= MaxBindPoint || _BindPoint == InvalidBindPoint, "Bind Point is out of allowed range");
VERIFY(_BindCount <= MaxBindCount, "Bind Count is out of allowed range");
VERIFY(_InputType < (1 << ShaderInputTypeBits), "Shader input type is out of expected range");
- VERIFY(_VariableType < (1 << VariableTypeBits), "Variable type is out of expected range");
VERIFY(_SRVDimension < (1 << SRVDimBits), "SRV dimensions is out of expected range");
VERIFY(_SamplerId < (1 << SamplerOrTexSRVIdBits), "SamplerOrTexSRVId is out of representable range");
- if (_InputType==D3D_SIT_SAMPLER)
- VERIFY_EXPR(IsStaticSampler() == _IsStaticSampler);
- else
- VERIFY(!_IsStaticSampler, "Only samplers can be labeled as static");
-
if (_InputType == D3D_SIT_TEXTURE && _SRVDimension != D3D_SRV_DIMENSION_BUFFER)
VERIFY_EXPR(GetSamplerId() == _SamplerId);
else
VERIFY(_SamplerId == InvalidSamplerId, "Only texture SRV can be assigned a valid texture sampler");
-
- if (_IsStaticSampler)
- VERIFY( _InputType == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" );
#endif
}
@@ -172,10 +136,8 @@ public:
rhs.BindPoint,
rhs.BindCount,
rhs.GetInputType(),
- rhs.GetVariableType(),
rhs.GetSRVDimension(),
- SamplerId,
- false
+ SamplerId
}
{
VERIFY(GetInputType() == D3D_SIT_TEXTURE && GetSRVDimension() != D3D_SRV_DIMENSION_BUFFER, "Only texture SRV can be assigned a texture sampler");
@@ -188,10 +150,8 @@ public:
rhs.BindPoint,
rhs.BindCount,
rhs.GetInputType(),
- rhs.GetVariableType(),
rhs.GetSRVDimension(),
- rhs.SamplerOrTexSRVId,
- rhs.StaticSamplerFlag !=0 ? true : false
+ rhs.SamplerOrTexSRVId
}
{
}
@@ -206,11 +166,6 @@ public:
return static_cast<D3D_SHADER_INPUT_TYPE>(InputType);
}
- SHADER_VARIABLE_TYPE GetVariableType()const
- {
- return static_cast<SHADER_VARIABLE_TYPE>(VariableType);
- }
-
D3D_SRV_DIMENSION GetSRVDimension()const
{
return static_cast<D3D_SRV_DIMENSION>(SRVDimension);
@@ -235,12 +190,6 @@ public:
return SamplerOrTexSRVId;
}
- bool IsStaticSampler()const
- {
- VERIFY(GetInputType() == D3D_SIT_SAMPLER, "Invalid input type: D3D_SIT_SAMPLER is expected" );
- return StaticSamplerFlag != 0;
- }
-
bool ValidSamplerAssigned()const
{
return GetSamplerId() != InvalidSamplerId;
@@ -270,20 +219,13 @@ public:
return BindPoint == Attribs.BindPoint &&
BindCount == Attribs.BindCount &&
InputType == Attribs.InputType &&
- VariableType == Attribs.VariableType &&
SRVDimension == Attribs.SRVDimension &&
- SamplerOrTexSRVId == Attribs.SamplerOrTexSRVId &&
- StaticSamplerFlag == Attribs.StaticSamplerFlag;
+ SamplerOrTexSRVId == Attribs.SamplerOrTexSRVId;
}
size_t GetHash()const
{
- return ComputeHash(BindPoint, BindCount, InputType, VariableType, SRVDimension, SamplerOrTexSRVId, StaticSamplerFlag);
- }
-
- bool IsAllowedType(Uint32 AllowedTypeBits)const
- {
- return Diligent::IsAllowedType(GetVariableType(), AllowedTypeBits);
+ return ComputeHash(BindPoint, BindCount, InputType, SRVDimension, SamplerOrTexSRVId);
}
};
static_assert(sizeof(D3DShaderResourceAttribs) == sizeof(void*) + sizeof(Uint32)*2, "Unexpected sizeof(D3DShaderResourceAttribs)");
@@ -317,9 +259,6 @@ public:
const D3DShaderResourceAttribs& GetBufUAV (Uint32 n)const noexcept{ return GetResAttribs(n, GetNumBufUAV(), m_BufUAVOffset); }
const D3DShaderResourceAttribs& GetSampler(Uint32 n)const noexcept{ return GetResAttribs(n, GetNumSamplers(), m_SamplersOffset); }
- D3DShaderResourceCounters CountResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes)const noexcept;
-
SHADER_TYPE GetShaderType()const noexcept{return m_ShaderType;}
// Processes only resources listed in AllowedVarTypes
@@ -329,57 +268,47 @@ public:
typename THandleTexUAV,
typename THandleBufSRV,
typename THandleBufUAV>
- void ProcessResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes,
- THandleCB HandleCB,
+ void ProcessResources(THandleCB HandleCB,
THandleSampler HandleSampler,
THandleTexSRV HandleTexSRV,
THandleTexUAV HandleTexUAV,
THandleBufSRV HandleBufSRV,
THandleBufUAV HandleBufUAV)const
{
- Uint32 AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
for(Uint32 n=0; n < GetNumCBs(); ++n)
{
const auto& CB = GetCB(n);
- if( CB.IsAllowedType(AllowedTypeBits) )
- HandleCB(CB, n);
+ HandleCB(CB, n);
}
for(Uint32 n=0; n < GetNumSamplers(); ++n)
{
const auto& Sampler = GetSampler(n);
- if( Sampler.IsAllowedType(AllowedTypeBits) )
- HandleSampler(Sampler, n);
+ HandleSampler(Sampler, n);
}
for(Uint32 n=0; n < GetNumTexSRV(); ++n)
{
const auto& TexSRV = GetTexSRV(n);
- if( TexSRV.IsAllowedType(AllowedTypeBits) )
- HandleTexSRV(TexSRV, n);
+ HandleTexSRV(TexSRV, n);
}
for(Uint32 n=0; n < GetNumTexUAV(); ++n)
{
const auto& TexUAV = GetTexUAV(n);
- if( TexUAV.IsAllowedType(AllowedTypeBits) )
- HandleTexUAV(TexUAV, n);
+ HandleTexUAV(TexUAV, n);
}
for(Uint32 n=0; n < GetNumBufSRV(); ++n)
{
const auto& BufSRV = GetBufSRV(n);
- if( BufSRV.IsAllowedType(AllowedTypeBits) )
- HandleBufSRV(BufSRV, n);
+ HandleBufSRV(BufSRV, n);
}
for(Uint32 n=0; n < GetNumBufUAV(); ++n)
{
const auto& BufUAV = GetBufUAV(n);
- if( BufUAV.IsAllowedType(AllowedTypeBits) )
- HandleBufUAV(BufUAV, n);
+ HandleBufUAV(BufUAV, n);
}
}
@@ -567,3 +496,4 @@ namespace std
}
};
}
+
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h
index 6c683aa2..48748a6c 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.h
@@ -23,7 +23,7 @@
#pragma once
-#include "Shader.h"
+#include "ShaderResourceVariable.h"
/// \file
/// Declaration of Diligent::ShaderVariableD3DBase class
@@ -31,7 +31,7 @@
namespace Diligent
{
template<typename TShaderResourceLayout>
- struct ShaderVariableD3DBase : public IShaderVariable
+ struct ShaderVariableD3DBase : public IShaderResourceVariable
{
ShaderVariableD3DBase(TShaderResourceLayout& ParentResLayout, const D3DShaderResourceAttribs& ResourcesAttribs) :
m_ParentResLayout(ParentResLayout),
@@ -54,7 +54,7 @@ namespace Diligent
return m_ParentResLayout.GetOwner().Release();
}
- void QueryInterface( const INTERFACE_ID &IID, IObject **ppInterface )override final
+ void QueryInterface( const INTERFACE_ID& IID, IObject** ppInterface )override final
{
if( ppInterface == nullptr )
return;
@@ -67,7 +67,7 @@ namespace Diligent
}
}
- virtual SHADER_VARIABLE_TYPE GetType()const override final
+ virtual SHADER_RESOURCE_VARIABLE_TYPE GetType()const override final
{
return Attribs.GetVariableType();
}
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
index c1fbda20..e9f1144b 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
@@ -41,13 +41,13 @@ static const Char* g_HLSLDefinitions =
class D3DIncludeImpl : public ID3DInclude
{
public:
- D3DIncludeImpl(IShaderSourceInputStreamFactory *pStreamFactory) :
+ D3DIncludeImpl(IShaderSourceInputStreamFactory* pStreamFactory) :
m_pStreamFactory(pStreamFactory)
{
}
- STDMETHOD( Open )(THIS_ D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID *ppData, UINT *pBytes)
+ STDMETHOD( Open )(THIS_ D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes)
{
RefCntAutoPtr<IFileStream> pSourceStream;
m_pStreamFactory->CreateInputStream( pFileName, &pSourceStream );
@@ -78,13 +78,13 @@ private:
std::unordered_map< LPCVOID, RefCntAutoPtr<IDataBlob> > m_DataBlobs;
};
-HRESULT CompileShader( const char* Source,
- LPCSTR strFunctionName,
- const D3D_SHADER_MACRO* pDefines,
- IShaderSourceInputStreamFactory *pIncludeStreamFactory,
- LPCSTR profile,
- ID3DBlob **ppBlobOut,
- ID3DBlob **ppCompilerOutput)
+static HRESULT CompileShader(const char* Source,
+ LPCSTR strFunctionName,
+ const D3D_SHADER_MACRO* pDefines,
+ IShaderSourceInputStreamFactory* pIncludeStreamFactory,
+ LPCSTR profile,
+ ID3DBlob** ppBlobOut,
+ ID3DBlob** ppCompilerOutput)
{
DWORD dwShaderFlags = D3DCOMPILE_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
@@ -133,15 +133,15 @@ const char* DXShaderProfileToString(SHADER_PROFILE DXProfile)
}
}
-ShaderD3DBase::ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs)
+ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI)
{
- if (CreationAttribs.Source || CreationAttribs.FilePath)
+ if (ShaderCI.Source || ShaderCI.FilePath)
{
- DEV_CHECK_ERR(CreationAttribs.ByteCode == nullptr, "'ByteCode' must be null when shader is created from the source code or a file");
- DEV_CHECK_ERR(CreationAttribs.ByteCodeSize == 0, "'ByteCodeSize' must be 0 when shader is created from the source code or a file");
+ DEV_CHECK_ERR(ShaderCI.ByteCode == nullptr, "'ByteCode' must be null when shader is created from the source code or a file");
+ DEV_CHECK_ERR(ShaderCI.ByteCodeSize == 0, "'ByteCodeSize' must be 0 when shader is created from the source code or a file");
std::string strShaderProfile;
- switch(CreationAttribs.Desc.ShaderType)
+ switch (ShaderCI.Desc.ShaderType)
{
case SHADER_TYPE_VERTEX: strShaderProfile="vs"; break;
case SHADER_TYPE_PIXEL: strShaderProfile="ps"; break;
@@ -153,20 +153,20 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs)
default: UNEXPECTED( "Unknown shader type" );
}
strShaderProfile += "_";
- auto *pProfileSuffix = DXShaderProfileToString(CreationAttribs.Desc.TargetProfile);
+ auto *pProfileSuffix = DXShaderProfileToString(ShaderCI.Desc.TargetProfile);
strShaderProfile += pProfileSuffix;
String ShaderSource(g_HLSLDefinitions);
- if (CreationAttribs.Source)
+ if (ShaderCI.Source)
{
- DEV_CHECK_ERR(CreationAttribs.FilePath == nullptr, "'FilePath' is expected to be null when shader source code is provided");
- ShaderSource.append(CreationAttribs.Source);
+ DEV_CHECK_ERR(ShaderCI.FilePath == nullptr, "'FilePath' is expected to be null when shader source code is provided");
+ ShaderSource.append(ShaderCI.Source);
}
else
{
- DEV_CHECK_ERR(CreationAttribs.pShaderSourceStreamFactory, "Input stream factory is null");
+ DEV_CHECK_ERR(ShaderCI.pShaderSourceStreamFactory, "Input stream factory is null");
RefCntAutoPtr<IFileStream> pSourceStream;
- CreationAttribs.pShaderSourceStreamFactory->CreateInputStream(CreationAttribs.FilePath, &pSourceStream);
+ ShaderCI.pShaderSourceStreamFactory->CreateInputStream(ShaderCI.FilePath, &pSourceStream);
RefCntAutoPtr<IDataBlob> pFileData(MakeNewRCObj<DataBlobImpl>()(0));
if (pSourceStream == nullptr)
LOG_ERROR_AND_THROW("Failed to open shader source file");
@@ -179,9 +179,9 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs)
const D3D_SHADER_MACRO *pDefines = nullptr;
std::vector<D3D_SHADER_MACRO> D3DMacros;
- if (CreationAttribs.Macros)
+ if (ShaderCI.Macros)
{
- for (auto* pCurrMacro = CreationAttribs.Macros; pCurrMacro->Name && pCurrMacro->Definition; ++pCurrMacro)
+ for (auto* pCurrMacro = ShaderCI.Macros; pCurrMacro->Name && pCurrMacro->Definition; ++pCurrMacro)
{
D3DMacros.push_back({ pCurrMacro->Name, pCurrMacro->Definition });
}
@@ -189,39 +189,39 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreationAttribs &CreationAttribs)
pDefines = D3DMacros.data();
}
- DEV_CHECK_ERR(CreationAttribs.EntryPoint != nullptr, "Entry point must not be null");
+ DEV_CHECK_ERR(ShaderCI.EntryPoint != nullptr, "Entry point must not be null");
CComPtr<ID3DBlob> errors;
- auto hr = CompileShader(ShaderSource.c_str(), CreationAttribs.EntryPoint, pDefines, CreationAttribs.pShaderSourceStreamFactory, strShaderProfile.c_str(), &m_pShaderByteCode, &errors);
+ auto hr = CompileShader(ShaderSource.c_str(), ShaderCI.EntryPoint, pDefines, ShaderCI.pShaderSourceStreamFactory, strShaderProfile.c_str(), &m_pShaderByteCode, &errors);
- const char *CompilerMsg = errors ? reinterpret_cast<const char*>(errors->GetBufferPointer()) : nullptr;
- if(CompilerMsg != nullptr && CreationAttribs.ppCompilerOutput != nullptr)
+ const char* CompilerMsg = errors ? reinterpret_cast<const char*>(errors->GetBufferPointer()) : nullptr;
+ if (CompilerMsg != nullptr && ShaderCI.ppCompilerOutput != nullptr)
{
auto ErrorMsgLen = strlen(CompilerMsg);
auto *pOutputDataBlob = MakeNewRCObj<DataBlobImpl>()(ErrorMsgLen + 1 + ShaderSource.length() + 1);
char* DataPtr = reinterpret_cast<char*>(pOutputDataBlob->GetDataPtr());
memcpy(DataPtr, CompilerMsg, ErrorMsgLen+1);
memcpy(DataPtr + ErrorMsgLen + 1, ShaderSource.data(), ShaderSource.length() + 1);
- pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(CreationAttribs.ppCompilerOutput));
+ pOutputDataBlob->QueryInterface(IID_DataBlob, reinterpret_cast<IObject**>(ShaderCI.ppCompilerOutput));
}
- if(FAILED(hr))
+ if (FAILED(hr))
{
ComErrorDesc ErrDesc(hr);
- if(CreationAttribs.ppCompilerOutput != nullptr)
+ if(ShaderCI.ppCompilerOutput != nullptr)
{
- LOG_ERROR_AND_THROW("Failed to compile D3D shader \"", (CreationAttribs.Desc.Name != nullptr ? CreationAttribs.Desc.Name : ""), "\" (", ErrDesc.Get(), ").");
+ LOG_ERROR_AND_THROW("Failed to compile D3D shader \"", (ShaderCI.Desc.Name != nullptr ? ShaderCI.Desc.Name : ""), "\" (", ErrDesc.Get(), ").");
}
else
{
- LOG_ERROR_AND_THROW("Failed to compile D3D shader \"", (CreationAttribs.Desc.Name != nullptr ? CreationAttribs.Desc.Name : ""), "\" (", ErrDesc.Get(), "):\n", (CompilerMsg != nullptr ? CompilerMsg : "<no compiler log available>") );
+ LOG_ERROR_AND_THROW("Failed to compile D3D shader \"", (ShaderCI.Desc.Name != nullptr ? ShaderCI.Desc.Name : ""), "\" (", ErrDesc.Get(), "):\n", (CompilerMsg != nullptr ? CompilerMsg : "<no compiler log available>") );
}
}
}
- else if (CreationAttribs.ByteCode)
+ else if (ShaderCI.ByteCode)
{
- DEV_CHECK_ERR(CreationAttribs.ByteCodeSize != 0, "ByteCode size must be greater than 0");
- CHECK_D3D_RESULT_THROW(D3DCreateBlob(CreationAttribs.ByteCodeSize, &m_pShaderByteCode), "Failed to create D3D blob");
- memcpy(m_pShaderByteCode->GetBufferPointer(), CreationAttribs.ByteCode, CreationAttribs.ByteCodeSize);
+ DEV_CHECK_ERR(ShaderCI.ByteCodeSize != 0, "ByteCode size must be greater than 0");
+ CHECK_D3D_RESULT_THROW(D3DCreateBlob(ShaderCI.ByteCodeSize, &m_pShaderByteCode), "Failed to create D3D blob");
+ memcpy(m_pShaderByteCode->GetBufferPointer(), ShaderCI.ByteCode, ShaderCI.ByteCodeSize);
}
else
{
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
index 90b85286..847e2675 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -96,53 +96,6 @@ ShaderResources::ShaderResources(SHADER_TYPE ShaderType):
{
}
-D3DShaderResourceCounters ShaderResources::CountResources(const SHADER_VARIABLE_TYPE* AllowedVarTypes,
- Uint32 NumAllowedTypes)const noexcept
-{
- auto AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
-
- D3DShaderResourceCounters Counters;
- ProcessResources(
- AllowedVarTypes, NumAllowedTypes,
-
- [&](const D3DShaderResourceAttribs& CB, Uint32)
- {
- VERIFY_EXPR(CB.IsAllowedType(AllowedTypeBits));
- ++Counters.NumCBs;
- },
- [&](const D3DShaderResourceAttribs& Sam, Uint32)
- {
- VERIFY_EXPR(Sam.IsAllowedType(AllowedTypeBits));
- // Skip static samplers
- if (!Sam.IsStaticSampler())
- ++Counters.NumSamplers;
- },
- [&](const D3DShaderResourceAttribs& TexSRV, Uint32)
- {
- VERIFY_EXPR(TexSRV.IsAllowedType(AllowedTypeBits));
- ++Counters.NumTexSRVs;
- },
- [&](const D3DShaderResourceAttribs& TexUAV, Uint32)
- {
- VERIFY_EXPR(TexUAV.IsAllowedType(AllowedTypeBits));
- ++Counters.NumTexUAVs;
- },
- [&](const D3DShaderResourceAttribs& BufSRV, Uint32)
- {
- VERIFY_EXPR(BufSRV.IsAllowedType(AllowedTypeBits));
- ++Counters.NumBufSRVs;
- },
- [&](const D3DShaderResourceAttribs& BufUAV, Uint32)
- {
- VERIFY_EXPR(BufUAV.IsAllowedType(AllowedTypeBits));
- ++Counters.NumBufUAVs;
- }
- );
-
- return Counters;
-}
-
-
Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& TexSRV, const char* SamplerSuffix)const
{
VERIFY_EXPR(SamplerSuffix != nullptr && *SamplerSuffix != 0);
@@ -153,10 +106,6 @@ Uint32 ShaderResources::FindAssignedSamplerId(const D3DShaderResourceAttribs& Te
const auto& Sampler = GetSampler(s);
if ( StreqSuff(Sampler.Name, TexSRV.Name, SamplerSuffix) )
{
- DEV_CHECK_ERR(Sampler.GetVariableType() == TexSRV.GetVariableType(),
- "The type (", GetShaderVariableTypeLiteralName(TexSRV.GetVariableType()),") of texture SRV variable '", TexSRV.Name,
- "' is not consistent with the type (", GetShaderVariableTypeLiteralName(Sampler.GetVariableType()),
- ") of the sampler '", Sampler.Name, "' that is assigned to it");
DEV_CHECK_ERR(Sampler.BindCount == TexSRV.BindCount || Sampler.BindCount == 1, "Sampler '", Sampler.Name, "' assigned to texture '", TexSRV.Name, "' must be scalar or have the same array dimension (", TexSRV.BindCount, "). Actual sampler array dimension : ", Sampler.BindCount);
return s;
}
@@ -176,8 +125,6 @@ bool ShaderResources::IsCompatibleWith(const ShaderResources &Res)const
bool IsCompatible = true;
ProcessResources(
- nullptr, 0,
-
[&](const D3DShaderResourceAttribs& CB, Uint32 n)
{
if (!CB.IsCompatibleWith(Res.GetCB(n)))
@@ -216,7 +163,6 @@ size_t ShaderResources::GetHash()const
{
size_t hash = ComputeHash(GetNumCBs(), GetNumTexSRV(), GetNumTexUAV(), GetNumBufSRV(), GetNumBufUAV(), GetNumSamplers());
ProcessResources(
- nullptr, 0,
[&](const D3DShaderResourceAttribs& CB, Uint32)
{
HashCombine(hash, CB);