diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-10-20 01:54:45 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-10-20 01:54:45 +0000 |
| commit | 7d27dcd7dc3d6a990a106e95e254009176e7ee53 (patch) | |
| tree | 39e2df8b4f0a25a0c4b3238de6672cf769db2818 /Graphics | |
| parent | D3D backends: properly handling the issue with static sampler arrays in shade... (diff) | |
| download | DiligentCore-7d27dcd7dc3d6a990a106e95e254009176e7ee53.tar.gz DiligentCore-7d27dcd7dc3d6a990a106e95e254009176e7ee53.zip | |
Added HLSLVersion, GLSLVersion and GLESSLVersion to ShaderCreateInfo struct (API Version 240035)
Diffstat (limited to 'Graphics')
| -rw-r--r-- | Graphics/GraphicsEngine/interface/APIInfo.h | 2 | ||||
| -rw-r--r-- | Graphics/GraphicsEngine/interface/Shader.h | 36 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp | 29 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp | 19 |
4 files changed, 74 insertions, 12 deletions
diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index 0979a824..36cb5c36 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 240034 +#define DILIGENT_API_VERSION 240035 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h index d6eca935..257ff4fe 100644 --- a/Graphics/GraphicsEngine/interface/Shader.h +++ b/Graphics/GraphicsEngine/interface/Shader.h @@ -174,6 +174,42 @@ struct ShaderCreateInfo /// Shader source language. See Diligent::SHADER_SOURCE_LANGUAGE. SHADER_SOURCE_LANGUAGE SourceLanguage = SHADER_SOURCE_LANGUAGE_DEFAULT; + + /// Shader version + struct ShaderVersion + { + /// Major revision + Uint8 Major = 0; + + /// Minor revision + Uint8 Minor = 0; + + ShaderVersion()noexcept{} + ShaderVersion(Uint8 _Major, Uint8 _Minor)noexcept : + Major {_Major}, + Minor {_Minor} + {} + }; + + /// HLSL shader model to use when compiling the shader. When default value + /// is given (0, 0), the engine will attempt to use the highest HLSL shader model + /// supported by the device. If the shader is created from the byte code, this value + /// has no effect. + /// + /// \note When HLSL source is converted to GLSL, corresponding GLSL/GLESSL version will be used. + ShaderVersion HLSLVersion = ShaderVersion{}; + + /// GLSL version to use when creating the shader. When default value + /// is given (0, 0), the engine will attempt to use the highest GLSL version + /// supported by the device. + ShaderVersion GLSLVersion = ShaderVersion{}; + + /// GLES shading language version to use when creating the shader. When default value + /// is given (0, 0), the engine will attempt to use the highest GLESSL version + /// supported by the device. + ShaderVersion GLESSLVersion = ShaderVersion{}; + + /// Memory address where pointer to the compiler messages data blob will be written /// The buffer contains two null-terminated strings. The first one is the compiler diff --git a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp index 996b2af5..18d8b8bc 100644 --- a/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/ShaderD3D11Impl.cpp @@ -30,7 +30,23 @@ namespace Diligent { -static const char* GetD3D11ShaderModel(ID3D11Device* pd3d11Device) +static const std::string HLSLVersionToShaderModelString(const ShaderCreateInfo::ShaderVersion& Version, Uint8 MaxMajorRevision, Uint8 MaxMinorRevision) +{ + std::string ModelStr; + if (Version.Major > MaxMajorRevision || Version.Major == MaxMajorRevision && Version.Minor > MaxMinorRevision) + { + ModelStr = std::to_string(Uint32{MaxMajorRevision}) + '_' + std::to_string(Uint32{MaxMinorRevision}); + LOG_ERROR_MESSAGE("Shader model ", Uint32{Version.Major}, "_", Uint32{Version.Minor}, " is not supported by this device. " + "Maximum supported model: ", ModelStr, ". Attempting to use ", ModelStr, '.'); + } + else + { + ModelStr = std::to_string(Uint32{Version.Major}) + '_' + std::to_string(Uint32{Version.Minor}); + } + return ModelStr; +} + +static const std::string GetD3D11ShaderModel(ID3D11Device* pd3d11Device, const ShaderCreateInfo::ShaderVersion& HLSLVersion) { auto d3dDeviceFeatureLevel = pd3d11Device->GetFeatureLevel(); switch(d3dDeviceFeatureLevel) @@ -44,13 +60,16 @@ static const char* GetD3D11ShaderModel(ID3D11Device* pd3d11Device) #endif case D3D_FEATURE_LEVEL_11_1: case D3D_FEATURE_LEVEL_11_0: - return "5_0"; + return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? + std::string{"5_0"} : HLSLVersionToShaderModelString(HLSLVersion, 5, 0); case D3D_FEATURE_LEVEL_10_1: - return "4_1"; + return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? + std::string{"4_1"} : HLSLVersionToShaderModelString(HLSLVersion, 4, 1); case D3D_FEATURE_LEVEL_10_0: - return "4_0"; + return (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) ? + std::string{"4_0"} : HLSLVersionToShaderModelString(HLSLVersion, 4, 0); default: UNEXPECTED("Unexpected D3D feature level ", static_cast<Uint32>(d3dDeviceFeatureLevel)); @@ -67,7 +86,7 @@ ShaderD3D11Impl::ShaderD3D11Impl(IReferenceCounters* pRefCounters, pRenderDeviceD3D11, ShaderCI.Desc }, - ShaderD3DBase{ShaderCI, GetD3D11ShaderModel(pRenderDeviceD3D11->GetD3D11Device())} + ShaderD3DBase{ShaderCI, GetD3D11ShaderModel(pRenderDeviceD3D11->GetD3D11Device(), ShaderCI.HLSLVersion).c_str()} { auto *pDeviceD3D11 = pRenderDeviceD3D11->GetD3D11Device(); switch (ShaderCI.Desc.ShaderType) diff --git a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp index f6dfb74d..42325bf5 100644 --- a/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/ShaderD3D12Impl.cpp @@ -32,13 +32,20 @@ namespace Diligent { -static const char* GetD3D12ShaderModel(RenderDeviceD3D12Impl* /*pDevice*/) +static const std::string GetD3D12ShaderModel(RenderDeviceD3D12Impl* /*pDevice*/, const ShaderCreateInfo::ShaderVersion& HLSLVersion) { - //auto d3dDeviceFeatureLevel = pDevice->GetD3DFeatureLevel(); + if (HLSLVersion.Major == 0 && HLSLVersion.Minor == 0) + { + //auto d3dDeviceFeatureLevel = pDevice->GetD3DFeatureLevel(); - // Direct3D12 supports shader model 5.1 on all feature levels. - // https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support - return "5_1"; + // Direct3D12 supports shader model 5.1 on all feature levels. + // https://docs.microsoft.com/en-us/windows/win32/direct3d12/hardware-feature-levels#feature-level-support + return "5_1"; + } + else + { + return std::to_string(Uint32{HLSLVersion.Major}) + '_' + std::to_string(Uint32{HLSLVersion.Minor}); + } } ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, @@ -50,7 +57,7 @@ ShaderD3D12Impl::ShaderD3D12Impl(IReferenceCounters* pRefCounters, pRenderDeviceD3D12, ShaderCI.Desc }, - ShaderD3DBase{ShaderCI, GetD3D12ShaderModel(pRenderDeviceD3D12)} + ShaderD3DBase{ShaderCI, GetD3D12ShaderModel(pRenderDeviceD3D12, ShaderCI.HLSLVersion).c_str()} { // Load shader resources auto& Allocator = GetRawAllocator(); |
