summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngineD3DBase
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-10-21 22:15:55 +0000
committerazhirnov <zh1dron@gmail.com>2020-10-25 10:50:53 +0000
commit42217cc1ec7f81c028dcc5c1f845a2fc3b3da497 (patch)
tree2efcb7c0fdeae582ecb5c8d13c7bedd593ab9a3c /Graphics/GraphicsEngineD3DBase
parentFixed Mac/iOS build (diff)
parentUpdated Metal testing environment (diff)
downloadDiligentCore-42217cc1ec7f81c028dcc5c1f845a2fc3b3da497.tar.gz
DiligentCore-42217cc1ec7f81c028dcc5c1f845a2fc3b3da497.zip
Merge branch 'master' into ray_tracing
# Conflicts: # Graphics/GraphicsEngine/interface/PipelineState.h # Graphics/GraphicsEngineVulkan/include/VulkanTypeConversions.hpp # Graphics/GraphicsEngineVulkan/src/PipelineLayout.cpp # Graphics/GraphicsEngineVulkan/src/VulkanTypeConversions.cpp
Diffstat (limited to 'Graphics/GraphicsEngineD3DBase')
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp1
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp14
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp49
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp95
4 files changed, 123 insertions, 36 deletions
diff --git a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
index 104533c9..ea4a43bb 100644
--- a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
@@ -160,6 +160,7 @@ public:
auto& Features = this->m_DeviceCaps.Features;
Features.SeparablePrograms = DEVICE_FEATURE_STATE_ENABLED;
+ Features.ShaderResourceQueries = DEVICE_FEATURE_STATE_ENABLED;
Features.IndirectRendering = DEVICE_FEATURE_STATE_ENABLED;
Features.WireframeFill = DEVICE_FEATURE_STATE_ENABLED;
Features.MultithreadedResourceCreation = DEVICE_FEATURE_STATE_ENABLED;
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp
index b5446ec3..efbff703 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp
@@ -192,6 +192,10 @@ public:
return static_cast<D3D_SRV_DIMENSION>(SRVDimension);
}
+ RESOURCE_DIMENSION GetResourceDimension() const;
+
+ bool IsMultisample() const;
+
bool IsCombinedWithSampler() const
{
return GetCombinedSamplerId() != InvalidSamplerId;
@@ -368,20 +372,20 @@ public:
SHADER_RESOURCE_VARIABLE_TYPE FindVariableType(const D3DShaderResourceAttribs& ResourceAttribs,
const PipelineResourceLayoutDesc& ResourceLayout) const;
- Int32 FindStaticSampler(const D3DShaderResourceAttribs& ResourceAttribs,
- const PipelineResourceLayoutDesc& ResourceLayoutDesc,
- bool LogStaticSamplerArrayError) const;
+ Int32 FindImmutableSampler(const D3DShaderResourceAttribs& ResourceAttribs,
+ const PipelineResourceLayoutDesc& ResourceLayoutDesc,
+ bool LogImmutableSamplerArrayError) const;
D3DShaderResourceCounters CountResources(const PipelineResourceLayoutDesc& ResourceLayout,
const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
Uint32 NumAllowedTypes,
- bool CountStaticSamplers) const noexcept;
+ bool CountImmutableSamplers) const noexcept;
#ifdef DILIGENT_DEVELOPMENT
static void DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& ResourceLayout,
const ShaderResources* const pShaderResources[],
Uint32 NumShaders,
bool VerifyVariables,
- bool VerifyStaticSamplers);
+ bool VerifyImmutableSamplers) noexcept;
#endif
void GetShaderModel(Uint32& Major, Uint32& Minor) const
diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
index 0ea6e397..2497b17d 100644
--- a/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/ShaderVariableD3DBase.hpp
@@ -86,4 +86,53 @@ protected:
const SHADER_RESOURCE_VARIABLE_TYPE m_VariableType;
};
+
+template <typename BufferViewImplType>
+bool VerifyBufferViewModeD3D(BufferViewImplType* pViewD3D11, const D3DShaderResourceAttribs& Attribs, const char* ShaderName)
+{
+ if (pViewD3D11 == nullptr)
+ return true;
+
+ const auto& ViewDesc = pViewD3D11->GetDesc();
+ const auto& BuffDesc = pViewD3D11->GetBuffer()->GetDesc();
+
+ auto LogBufferBindingError = [&](const char* Msg) //
+ {
+ LOG_ERROR_MESSAGE("Error binding buffer view '", ViewDesc.Name, "' of buffer '", BuffDesc.Name,
+ "' to shader variable '", Attribs.Name, "' in shader '", ShaderName, "': ", Msg);
+ };
+
+ switch (Attribs.GetInputType())
+ {
+ case D3D_SIT_TEXTURE:
+ case D3D_SIT_UAV_RWTYPED:
+ if (BuffDesc.Mode != BUFFER_MODE_FORMATTED || ViewDesc.Format.ValueType == VT_UNDEFINED)
+ {
+ LogBufferBindingError("formatted buffer view is expected.");
+ return false;
+ }
+ break;
+
+ case D3D_SIT_STRUCTURED:
+ case D3D_SIT_UAV_RWSTRUCTURED:
+ if (BuffDesc.Mode != BUFFER_MODE_STRUCTURED)
+ {
+ LogBufferBindingError("structured buffer view is expected.");
+ return false;
+ }
+ break;
+
+ case D3D_SIT_BYTEADDRESS:
+ case D3D_SIT_UAV_RWBYTEADDRESS:
+ if (BuffDesc.Mode != BUFFER_MODE_RAW)
+ {
+ LogBufferBindingError("raw buffer view is expected.");
+ return false;
+ }
+ break;
+ }
+
+ return true;
+}
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
index 75ec17ea..b975b506 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp
@@ -122,44 +122,44 @@ SHADER_RESOURCE_VARIABLE_TYPE ShaderResources::FindVariableType(const D3DShaderR
}
}
-Int32 ShaderResources::FindStaticSampler(const D3DShaderResourceAttribs& ResourceAttribs,
- const PipelineResourceLayoutDesc& ResourceLayoutDesc,
- bool LogStaticSamplerArrayError) const
+Int32 ShaderResources::FindImmutableSampler(const D3DShaderResourceAttribs& ResourceAttribs,
+ const PipelineResourceLayoutDesc& ResourceLayoutDesc,
+ bool LogImmutableSamplerArrayError) const
{
VERIFY(ResourceAttribs.GetInputType() == D3D_SIT_SAMPLER, "Sampler is expected");
- auto StaticSamplerInd =
- Diligent::FindStaticSampler(ResourceLayoutDesc.StaticSamplers,
- ResourceLayoutDesc.NumStaticSamplers,
- m_ShaderType,
- ResourceAttribs.Name,
- m_SamplerSuffix);
+ auto ImtblSamplerInd =
+ Diligent::FindImmutableSampler(ResourceLayoutDesc.ImmutableSamplers,
+ ResourceLayoutDesc.NumImmutableSamplers,
+ m_ShaderType,
+ ResourceAttribs.Name,
+ m_SamplerSuffix);
- if (StaticSamplerInd >= 0 && ResourceAttribs.BindCount > 1)
+ if (ImtblSamplerInd >= 0 && ResourceAttribs.BindCount > 1)
{
Uint32 ShaderMajorVersion = 0;
Uint32 ShaderMinorVersion = 0;
GetShaderModel(ShaderMajorVersion, ShaderMinorVersion);
if (ShaderMajorVersion >= 6 || ShaderMajorVersion >= 5 && ShaderMinorVersion >= 1)
{
- if (LogStaticSamplerArrayError)
+ if (LogImmutableSamplerArrayError)
{
- LOG_ERROR_MESSAGE("Static sampler '", ResourceAttribs.Name, '[', ResourceAttribs.BindCount,
+ LOG_ERROR_MESSAGE("Immutable sampler '", ResourceAttribs.Name, '[', ResourceAttribs.BindCount,
"]' will be ignored because static sampler arrays are not allowed in shader model 5.1 and above. "
"Compile the shader using shader model 5.0 or use non-array sampler variable.");
}
- StaticSamplerInd = -1;
+ ImtblSamplerInd = -1;
}
}
- return StaticSamplerInd;
+ return ImtblSamplerInd;
}
D3DShaderResourceCounters ShaderResources::CountResources(const PipelineResourceLayoutDesc& ResourceLayout,
const SHADER_RESOURCE_VARIABLE_TYPE* AllowedVarTypes,
Uint32 NumAllowedTypes,
- bool CountStaticSamplers) const noexcept
+ bool CountImmutableSamplers) const noexcept
{
auto AllowedTypeBits = GetAllowedTypeBits(AllowedVarTypes, NumAllowedTypes);
@@ -176,11 +176,11 @@ D3DShaderResourceCounters ShaderResources::CountResources(const PipelineResource
auto VarType = FindVariableType(Sam, ResourceLayout);
if (IsAllowedType(VarType, AllowedTypeBits))
{
- if (!CountStaticSamplers)
+ if (!CountImmutableSamplers)
{
- constexpr bool LogStaticSamplerArrayError = false;
- if (FindStaticSampler(Sam, ResourceLayout, LogStaticSamplerArrayError) >= 0)
- return; // Skip static sampler if requested
+ constexpr bool LogImtblSamplerArrayError = false;
+ if (FindImmutableSampler(Sam, ResourceLayout, LogImtblSamplerArrayError) >= 0)
+ return; // Skip immutable sampler if requested
}
++Counters.NumSamplers;
}
@@ -219,7 +219,7 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc&
const ShaderResources* const pShaderResources[],
Uint32 NumShaders,
bool VerifyVariables,
- bool VerifyStaticSamplers)
+ bool VerifyImmutableSamplers) noexcept
{
auto GetAllowedShadersString = [&](SHADER_TYPE ShaderStages) //
{
@@ -300,40 +300,40 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc&
}
}
- if (VerifyStaticSamplers)
+ if (VerifyImmutableSamplers)
{
- for (Uint32 sam = 0; sam < ResourceLayout.NumStaticSamplers; ++sam)
+ for (Uint32 sam = 0; sam < ResourceLayout.NumImmutableSamplers; ++sam)
{
- const auto& StSamDesc = ResourceLayout.StaticSamplers[sam];
+ const auto& StSamDesc = ResourceLayout.ImmutableSamplers[sam];
if (StSamDesc.ShaderStages == SHADER_TYPE_UNKNOWN)
{
- LOG_WARNING_MESSAGE("No allowed shader stages are specified for static sampler '", StSamDesc.SamplerOrTextureName, "'.");
+ LOG_WARNING_MESSAGE("No allowed shader stages are specified for immutable sampler '", StSamDesc.SamplerOrTextureName, "'.");
continue;
}
const auto* TexOrSamName = StSamDesc.SamplerOrTextureName;
- bool StaticSamplerFound = false;
- for (Uint32 s = 0; s < NumShaders && !StaticSamplerFound; ++s)
+ bool ImtblSamplerFound = false;
+ for (Uint32 s = 0; s < NumShaders && !ImtblSamplerFound; ++s)
{
const auto& Resources = *pShaderResources[s];
if ((StSamDesc.ShaderStages & Resources.GetShaderType()) == 0)
continue;
- // Look for static sampler.
+ // Look for immutable sampler.
// In case HLSL-style combined image samplers are used, the condition is Sampler.Name == "g_Texture" + "_sampler".
// Otherwise the condition is Sampler.Name == "g_Texture_sampler" + "".
const auto* CombinedSamplerSuffix = Resources.GetCombinedSamplerSuffix();
- for (Uint32 n = 0; n < Resources.GetNumSamplers() && !StaticSamplerFound; ++n)
+ for (Uint32 n = 0; n < Resources.GetNumSamplers() && !ImtblSamplerFound; ++n)
{
const auto& Sampler = Resources.GetSampler(n);
- StaticSamplerFound = StreqSuff(Sampler.Name, TexOrSamName, CombinedSamplerSuffix);
+ ImtblSamplerFound = StreqSuff(Sampler.Name, TexOrSamName, CombinedSamplerSuffix);
}
}
- if (!StaticSamplerFound)
+ if (!ImtblSamplerFound)
{
- LOG_WARNING_MESSAGE("Static sampler '", TexOrSamName, "' is not found in any of the designated shader stages: ",
+ LOG_WARNING_MESSAGE("Immutable sampler '", TexOrSamName, "' is not found in any of the designated shader stages: ",
GetAllowedShadersString(StSamDesc.ShaderStages));
}
}
@@ -454,6 +454,39 @@ HLSLShaderResourceDesc D3DShaderResourceAttribs::GetHLSLResourceDesc() const
return ResourceDesc;
}
+RESOURCE_DIMENSION D3DShaderResourceAttribs::GetResourceDimension() const
+{
+ switch (GetSRVDimension())
+ {
+ // clang-format off
+ case D3D_SRV_DIMENSION_BUFFER: return RESOURCE_DIM_BUFFER;
+ case D3D_SRV_DIMENSION_TEXTURE1D: return RESOURCE_DIM_TEX_1D;
+ case D3D_SRV_DIMENSION_TEXTURE1DARRAY: return RESOURCE_DIM_TEX_1D_ARRAY;
+ case D3D_SRV_DIMENSION_TEXTURE2D: return RESOURCE_DIM_TEX_2D;
+ case D3D_SRV_DIMENSION_TEXTURE2DARRAY: return RESOURCE_DIM_TEX_2D_ARRAY;
+ case D3D_SRV_DIMENSION_TEXTURE2DMS: return RESOURCE_DIM_TEX_2D;
+ case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY: return RESOURCE_DIM_TEX_2D_ARRAY;
+ case D3D_SRV_DIMENSION_TEXTURE3D: return RESOURCE_DIM_TEX_3D;
+ case D3D_SRV_DIMENSION_TEXTURECUBE: return RESOURCE_DIM_TEX_CUBE;
+ case D3D_SRV_DIMENSION_TEXTURECUBEARRAY: return RESOURCE_DIM_TEX_CUBE_ARRAY;
+ // clang-format on
+ default:
+ return RESOURCE_DIM_BUFFER;
+ }
+}
+
+bool D3DShaderResourceAttribs::IsMultisample() const
+{
+ switch (GetSRVDimension())
+ {
+ case D3D_SRV_DIMENSION_TEXTURE2DMS:
+ case D3D_SRV_DIMENSION_TEXTURE2DMSARRAY:
+ return true;
+ default:
+ return false;
+ }
+}
+
HLSLShaderResourceDesc ShaderResources::GetHLSLShaderResourceDesc(Uint32 Index) const
{
DEV_CHECK_ERR(Index < m_TotalResources, "Resource index (", Index, ") is out of range");