From b3fec8bd40e80115086281bce74774617aa95e23 Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 14 Oct 2020 01:04:05 -0700 Subject: Added buffer mode validation when binding buffer views --- .../include/ShaderVariableD3DBase.hpp | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'Graphics/GraphicsEngineD3DBase') 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 +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 -- cgit v1.2.3 From e7b18160a758b30dd6b701b4aa6f43c9c2061ccf Mon Sep 17 00:00:00 2001 From: assiduous Date: Sat, 17 Oct 2020 09:56:34 -0700 Subject: All backends: added resource dimension validation when setting shader variables --- .../include/ShaderResources.hpp | 4 +++ .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 33 ++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index b5446ec3..2843f9f0 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp @@ -192,6 +192,10 @@ public: return static_cast(SRVDimension); } + RESOURCE_DIMENSION GetResourceDimension() const; + + bool IsMultisample() const; + bool IsCombinedWithSampler() const { return GetCombinedSamplerId() != InvalidSamplerId; diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 75ec17ea..498e31a2 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -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"); -- cgit v1.2.3 From a520bf4f9748d20e432bcf7994be3148d0b75d54 Mon Sep 17 00:00:00 2001 From: assiduous Date: Mon, 19 Oct 2020 10:21:30 -0700 Subject: Renamed static sampler to immutable sampler (API240076) --- .../include/ShaderResources.hpp | 10 ++-- .../GraphicsEngineD3DBase/src/ShaderResources.cpp | 62 +++++++++++----------- 2 files changed, 36 insertions(+), 36 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index 2843f9f0..f15d2e74 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp @@ -372,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); #endif void GetShaderModel(Uint32& Major, Uint32& Minor) const diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 498e31a2..86a7fc35 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) { 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)); } } -- cgit v1.2.3 From 13b0b54987db2684e46e337d2e5be5b81366083b Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 20 Oct 2020 13:26:21 -0700 Subject: Improved exception safety of pipeline state object construction --- Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp | 2 +- Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'Graphics/GraphicsEngineD3DBase') diff --git a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp index f15d2e74..efbff703 100644 --- a/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp +++ b/Graphics/GraphicsEngineD3DBase/include/ShaderResources.hpp @@ -385,7 +385,7 @@ public: const ShaderResources* const pShaderResources[], Uint32 NumShaders, bool VerifyVariables, - bool VerifyImmutableSamplers); + bool VerifyImmutableSamplers) noexcept; #endif void GetShaderModel(Uint32& Major, Uint32& Minor) const diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp index 86a7fc35..b975b506 100644 --- a/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp +++ b/Graphics/GraphicsEngineD3DBase/src/ShaderResources.cpp @@ -219,7 +219,7 @@ void ShaderResources::DvpVerifyResourceLayout(const PipelineResourceLayoutDesc& const ShaderResources* const pShaderResources[], Uint32 NumShaders, bool VerifyVariables, - bool VerifyImmutableSamplers) + bool VerifyImmutableSamplers) noexcept { auto GetAllowedShadersString = [&](SHADER_TYPE ShaderStages) // { -- cgit v1.2.3 From b9d1a84943f61d1b48ffb1847cd0b3f7b8c60fb2 Mon Sep 17 00:00:00 2001 From: assiduous Date: Tue, 20 Oct 2020 18:05:02 -0700 Subject: Added ShaderResourceQueries device feature and EngineGLCreateInfo::ForceNonSeparablePrograms parameter (API 240078) --- Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp | 1 + 1 file changed, 1 insertion(+) (limited to 'Graphics/GraphicsEngineD3DBase') 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; -- cgit v1.2.3