diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-10-30 16:18:54 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-10-30 16:18:54 +0000 |
| commit | c632ec4bacef631b0357dadcdd5d6bacb652c585 (patch) | |
| tree | 381c2d77bdcabbb09ee63450d2f9cdfd78f1604c /Graphics/GraphicsEngineVulkan | |
| parent | Redefined frexp in HLSL2GLSL converter to match HLSL signature (float frexp(f... (diff) | |
| download | DiligentCore-c632ec4bacef631b0357dadcdd5d6bacb652c585.tar.gz DiligentCore-c632ec4bacef631b0357dadcdd5d6bacb652c585.zip | |
Implemented HLSL vertex shader inputs mapping in Vulkan backend using SPV_GOOGLE_hlsl_functionality1 (causes validation layer errors for now)
Diffstat (limited to 'Graphics/GraphicsEngineVulkan')
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp | 40 |
2 files changed, 41 insertions, 1 deletions
diff --git a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h index 144581bf..adcc6a31 100644 --- a/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h +++ b/Graphics/GraphicsEngineVulkan/include/ShaderVkImpl.h @@ -87,6 +87,8 @@ public: #endif private: + void MapHLSLVertexShaderInputs(); + // ShaderResources class instance must be referenced through the shared pointer, because // it is referenced by ShaderResourceLayoutVk class instances std::shared_ptr<const SPIRVShaderResources> m_pShaderResources; diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp index 23d2123d..56e32ed1 100644 --- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp @@ -22,6 +22,7 @@ */ #include <array> +#include <cctype> #include "pch.h" #include "ShaderVkImpl.h" @@ -78,14 +79,51 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters, RenderDeviceVkImpl* // Load shader resources auto& Allocator = GetRawAllocator(); auto* pRawMem = ALLOCATE(Allocator, "Allocator for ShaderResources", sizeof(SPIRVShaderResources)); - auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr); + bool IsHLSLVertexShader = CreationAttribs.SourceLanguage == SHADER_SOURCE_LANGUAGE_HLSL && m_Desc.ShaderType == SHADER_TYPE_VERTEX; + auto* pResources = new (pRawMem) SPIRVShaderResources(Allocator, pRenderDeviceVk, m_SPIRV, m_Desc, CreationAttribs.UseCombinedTextureSamplers ? CreationAttribs.CombinedSamplerSuffix : nullptr, IsHLSLVertexShader); m_pShaderResources.reset(pResources, STDDeleterRawMem<SPIRVShaderResources>(Allocator)); + + if (IsHLSLVertexShader) + { + MapHLSLVertexShaderInputs(); + } m_StaticResLayout.InitializeStaticResourceLayout(m_pShaderResources, GetRawAllocator(), m_StaticResCache); // m_StaticResLayout only contains static resources, so reference all of them m_StaticVarsMgr.Initialize(m_StaticResLayout, GetRawAllocator(), nullptr, 0, m_StaticResCache); } +void ShaderVkImpl::MapHLSLVertexShaderInputs() +{ + for (Uint32 i = 0; i < m_pShaderResources->GetNumShaderStageInputs(); ++i) + { + const auto& Input = m_pShaderResources->GetShaderStageInputAttribs(i); + const char* s = Input.Semantic; + static const char* Prefix = "attrib"; + const char* p = Prefix; + while(*s != 0 && *p != 0 && *p == std::tolower(static_cast<unsigned char>(*s)) ) + { + ++p; + ++s; + } + + if (*p != 0) + { + LOG_ERROR_MESSAGE("Unable to map semantic '", Input.Semantic, "' to input location: semantics must have 'ATTRIBx' format."); + continue; + } + + char* EndPtr = nullptr; + auto Location = strtol(s, &EndPtr, 10); + if (*EndPtr != 0) + { + LOG_ERROR_MESSAGE("Unable to map semantic '", Input.Semantic, "' to input location: semantics must have 'ATTRIBx' format."); + continue; + } + m_SPIRV[Input.LocationDecorationOffset] = Location; + } +} + ShaderVkImpl::~ShaderVkImpl() { m_StaticVarsMgr.Destroy(GetRawAllocator()); |
