From d27d09a9a8b776391c3dbc8c1008809b7382fef5 Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Wed, 13 Nov 2019 15:27:38 -0800 Subject: Added HLSLSemantic member to LayoutElement struct (API Version 240042) --- .../GraphicsEngine/include/PipelineStateBase.h | 24 +++++- Graphics/GraphicsEngine/interface/APIInfo.h | 2 +- Graphics/GraphicsEngine/interface/InputLayout.h | 86 +++++++++++++++------- 3 files changed, 79 insertions(+), 33 deletions(-) (limited to 'Graphics/GraphicsEngine') diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.h b/Graphics/GraphicsEngine/include/PipelineStateBase.h index 00fed7e3..f4a7a9bf 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.h +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.h @@ -62,8 +62,8 @@ public: RenderDeviceImplType* pDevice, const PipelineStateDesc& PSODesc, bool bIsDeviceInternal = false ) : - TDeviceObjectBase (pRefCounters, pDevice, PSODesc, bIsDeviceInternal), - m_NumShaders(0) + TDeviceObjectBase {pRefCounters, pDevice, PSODesc, bIsDeviceInternal}, + m_NumShaders{0} { const auto& SrcLayout = PSODesc.ResourceLayout; size_t StringPoolSize = 0; @@ -78,6 +78,18 @@ public: for (Uint32 i=0; i < SrcLayout.NumStaticSamplers; ++i) StringPoolSize += strlen(SrcLayout.StaticSamplers[i].SamplerOrTextureName) + 1; } + + if (!PSODesc.IsComputePipeline) + { + const auto& InputLayout = PSODesc.GraphicsPipeline.InputLayout; + for (Uint32 i=0; i < InputLayout.NumElements; ++i) + StringPoolSize += strlen(InputLayout.LayoutElements[i].HLSLSemantic) + 1; + } + else + { + DEV_CHECK_ERR(PSODesc.GraphicsPipeline.InputLayout.NumElements == 0, "Compute pipelines must not have input layout elements"); + } + m_StringPool.Reserve(StringPoolSize, GetRawAllocator()); auto& DstLayout = this->m_Desc.ResourceLayout; @@ -118,7 +130,6 @@ public: StaticSamplers[i].SamplerOrTextureName = m_StringPool.CopyString(SrcLayout.StaticSamplers[i].SamplerOrTextureName); } } - VERIFY_EXPR(m_StringPool.GetRemainingSize() == 0); if (this->m_Desc.IsComputePipeline) @@ -183,7 +194,10 @@ public: } this->m_Desc.GraphicsPipeline.InputLayout.LayoutElements = pLayoutElements; for (size_t Elem = 0; Elem < InputLayout.NumElements; ++Elem) - pLayoutElements[Elem] = InputLayout.LayoutElements[Elem]; + { + pLayoutElements[Elem] = InputLayout.LayoutElements[Elem]; + pLayoutElements[Elem].HLSLSemantic = m_StringPool.CopyString(InputLayout.LayoutElements[Elem].HLSLSemantic); + } // Correct description and compute offsets and tight strides @@ -266,6 +280,8 @@ public: } } + VERIFY_EXPR(m_StringPool.GetRemainingSize() == 0); + Uint64 DeviceQueuesMask = pDevice->GetCommandQueueMask(); DEV_CHECK_ERR( (this->m_Desc.CommandQueueMask & DeviceQueuesMask) != 0, "No bits in the command queue mask (0x", std::hex, this->m_Desc.CommandQueueMask, ") correspond to one of ", pDevice->GetCommandQueueCount(), " available device command queues"); this->m_Desc.CommandQueueMask &= DeviceQueuesMask; diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index cdfcf2ac..70f487e4 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -26,7 +26,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240041 +#define DILIGENT_API_VERSION 240042 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/InputLayout.h b/Graphics/GraphicsEngine/interface/InputLayout.h index 125ef985..82bcb985 100644 --- a/Graphics/GraphicsEngine/interface/InputLayout.h +++ b/Graphics/GraphicsEngine/interface/InputLayout.h @@ -39,36 +39,43 @@ struct LayoutElement static constexpr Uint32 AutoOffset = static_cast(-1); static constexpr Uint32 AutoStride = static_cast(-1); - /// Input index of the element, which is specified in the vertex shader. - Uint32 InputIndex = 0; + /// HLSL semantic. Default value ("ATTRIB") allows HLSL shaders to be converted + /// to GLSL and used in OpenGL backend as well as compiled to SPIRV and used + /// in Vulkan backend. + /// Any value other than default will only work in Direct3D11 and Direct3D12 backends. + const char* HLSLSemantic = "ATTRIB"; + + /// Input index of the element that is specified in the vertex shader. + /// In Direct3D11 and Direct3D12 backends this is the semantic index. + Uint32 InputIndex = 0; /// Buffer slot index that this element is read from. - Uint32 BufferSlot = 0; + Uint32 BufferSlot = 0; /// Number of components in the element. Allowed values are 1, 2, 3, and 4. - Uint32 NumComponents = 0; + Uint32 NumComponents = 0; /// Type of the element components, see Diligent::VALUE_TYPE for details. - VALUE_TYPE ValueType = VT_FLOAT32; + VALUE_TYPE ValueType = VT_FLOAT32; /// For signed and unsigned integer value types /// (VT_INT8, VT_INT16, VT_INT32, VT_UINT8, VT_UINT16, VT_UINT32) /// indicates if the value should be normalized to [-1,+1] or /// [0, 1] range respectively. For floating point types /// (VT_FLOAT16 and VT_FLOAT32), this member is ignored. - Bool IsNormalized = True; + Bool IsNormalized = True; /// Relative offset, in bytes, to the element bits. /// If this value is set to LayoutElement::AutoOffset (default value), the offset will /// be computed automatically by placing the element right after the previous one. - Uint32 RelativeOffset = AutoOffset; + Uint32 RelativeOffset = AutoOffset; /// Stride, in bytes, between two elements, for this buffer slot. /// If this value is set to LayoutElement::AutoStride, the stride will be /// computed automatically assuming that all elements in the same buffer slot are /// packed one after another. If the buffer slot contains multiple layout elements, /// they all must specify the same stride or use AutoStride value. - Uint32 Stride = AutoStride; + Uint32 Stride = AutoStride; /// Input frequency enum FREQUENCY : Int32 @@ -103,15 +110,38 @@ struct LayoutElement Uint32 _Stride = LayoutElement{}.Stride, FREQUENCY _Frequency = LayoutElement{}.Frequency, Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept : - InputIndex (_InputIndex), - BufferSlot (_BufferSlot), - NumComponents (_NumComponents), - ValueType (_ValueType), - IsNormalized (_IsNormalized), - RelativeOffset (_RelativeOffset), - Stride (_Stride), - Frequency (_Frequency), - InstanceDataStepRate(_InstanceDataStepRate) + InputIndex {_InputIndex }, + BufferSlot {_BufferSlot }, + NumComponents {_NumComponents }, + ValueType {_ValueType }, + IsNormalized {_IsNormalized }, + RelativeOffset {_RelativeOffset }, + Stride {_Stride }, + Frequency {_Frequency }, + InstanceDataStepRate{_InstanceDataStepRate} + {} + + /// Initializes the structure + LayoutElement(const char* _HLSLSemantic, + Uint32 _InputIndex, + Uint32 _BufferSlot, + Uint32 _NumComponents, + VALUE_TYPE _ValueType, + Bool _IsNormalized = LayoutElement{}.IsNormalized, + Uint32 _RelativeOffset = LayoutElement{}.RelativeOffset, + Uint32 _Stride = LayoutElement{}.Stride, + FREQUENCY _Frequency = LayoutElement{}.Frequency, + Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept : + HLSLSemantic {_HLSLSemantic }, + InputIndex {_InputIndex }, + BufferSlot {_BufferSlot }, + NumComponents {_NumComponents }, + ValueType {_ValueType }, + IsNormalized {_IsNormalized }, + RelativeOffset {_RelativeOffset }, + Stride {_Stride }, + Frequency {_Frequency }, + InstanceDataStepRate{_InstanceDataStepRate} {} /// Initializes the structure @@ -122,15 +152,15 @@ struct LayoutElement Bool _IsNormalized, FREQUENCY _Frequency, Uint32 _InstanceDataStepRate = LayoutElement{}.InstanceDataStepRate)noexcept : - InputIndex (_InputIndex), - BufferSlot (_BufferSlot), - NumComponents (_NumComponents), - ValueType (_ValueType), - IsNormalized (_IsNormalized), - RelativeOffset (LayoutElement{}.RelativeOffset), - Stride (LayoutElement{}.Stride), - Frequency (_Frequency), - InstanceDataStepRate(_InstanceDataStepRate) + InputIndex {_InputIndex }, + BufferSlot {_BufferSlot }, + NumComponents {_NumComponents }, + ValueType {_ValueType }, + IsNormalized {_IsNormalized }, + RelativeOffset {LayoutElement{}.RelativeOffset}, + Stride {LayoutElement{}.Stride }, + Frequency {_Frequency }, + InstanceDataStepRate{_InstanceDataStepRate } {} }; @@ -148,8 +178,8 @@ struct InputLayoutDesc InputLayoutDesc(const LayoutElement* _LayoutElements, Uint32 _NumElements)noexcept : - LayoutElements(_LayoutElements), - NumElements (_NumElements) + LayoutElements{_LayoutElements}, + NumElements {_NumElements } {} }; -- cgit v1.2.3