summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorassiduous <assiduous@diligentgraphics.com>2020-09-16 23:11:56 +0000
committerassiduous <assiduous@diligentgraphics.com>2020-09-16 23:11:56 +0000
commit0cc841bc76eda21793f2a158b0ededad5a5ae3bf (patch)
tree39e1f2bee602263336754d990eaab557f16b98d6 /Graphics
parentAnother improvement to texture format tests in OpenGL (diff)
downloadDiligentCore-0cc841bc76eda21793f2a158b0ededad5a5ae3bf.tar.gz
DiligentCore-0cc841bc76eda21793f2a158b0ededad5a5ae3bf.zip
Added GPU vendor and memory size detection (API 240071), closed https://github.com/DiligentGraphics/DiligentCore/issues/144.
Fixed shader model selection in D3D12 backend
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp2
-rw-r--r--Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp17
-rw-r--r--Graphics/GraphicsEngine/interface/GraphicsTypes.h56
-rw-r--r--Graphics/GraphicsEngine/interface/Shader.h5
-rw-r--r--Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp12
-rw-r--r--Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp12
-rw-r--r--Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp25
-rw-r--r--Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp2
-rw-r--r--Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp18
-rw-r--r--Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp60
-rw-r--r--Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp39
-rw-r--r--Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp2
-rw-r--r--Graphics/ShaderTools/include/DXCompiler.hpp1
-rw-r--r--Graphics/ShaderTools/src/DXCompiler.cpp25
14 files changed, 219 insertions, 57 deletions
diff --git a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp
index 3ea1be72..a97118e2 100644
--- a/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp
+++ b/Graphics/GraphicsAccessories/interface/GraphicsAccessories.hpp
@@ -419,4 +419,6 @@ struct MipLevelProperties
MipLevelProperties GetMipLevelProperties(const TextureDesc& TexDesc, Uint32 MipLevel);
+ADAPTER_VENDOR VendorIdToAdapterVendor(Uint32 VendorId);
+
} // namespace Diligent
diff --git a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
index c3bd820e..2dfda2a8 100644
--- a/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
+++ b/Graphics/GraphicsAccessories/src/GraphicsAccessories.cpp
@@ -1269,4 +1269,21 @@ MipLevelProperties GetMipLevelProperties(const TextureDesc& TexDesc, Uint32 MipL
return MipProps;
}
+ADAPTER_VENDOR VendorIdToAdapterVendor(Uint32 VendorId)
+{
+ switch (VendorId)
+ {
+ case 0x01002: return ADAPTER_VENDOR_AMD;
+ case 0x010DE: return ADAPTER_VENDOR_NVIDIA;
+ case 0x08086: return ADAPTER_VENDOR_INTEL;
+ case 0x013B5: return ADAPTER_VENDOR_ARM;
+ case 0x05143: return ADAPTER_VENDOR_QUALCOMM;
+ case 0x01010: return ADAPTER_VENDOR_IMGTECH;
+ case 0x01414: return ADAPTER_VENDOR_MSFT;
+
+ default:
+ return ADAPTER_VENDOR_UNKNOWN;
+ }
+}
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h
index cc5b95ba..c3f454d5 100644
--- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h
+++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h
@@ -1652,6 +1652,58 @@ struct DeviceFeatures
typedef struct DeviceFeatures DeviceFeatures;
+/// Graphics adapter vendor
+enum ADAPTER_VENDOR
+{
+ /// Adapter vendor is unknown
+ ADAPTER_VENDOR_UNKNOWN = 0,
+
+ /// Adapter vendor is NVidia
+ ADAPTER_VENDOR_NVIDIA,
+
+ /// Adapter vendor is AMD
+ ADAPTER_VENDOR_AMD,
+
+ /// Adapter vendor is Intel
+ ADAPTER_VENDOR_INTEL,
+
+ /// Adapter vendor is ARM
+ ADAPTER_VENDOR_ARM,
+
+ /// Adapter vendor is Qualcomm
+ ADAPTER_VENDOR_QUALCOMM,
+
+ /// Adapter vendor is Imagination Technologies
+ ADAPTER_VENDOR_IMGTECH,
+
+ /// Adapter vendor is Microsoft (software rasterizer)
+ ADAPTER_VENDOR_MSFT
+};
+
+/// Graphics adapter properties
+struct GraphicsAdapterInfo
+{
+ /// Adapter type, see Diligent::ADAPTER_TYPE.
+ enum ADAPTER_TYPE Type DEFAULT_INITIALIZER(ADAPTER_TYPE_UNKNOWN);
+
+ /// Adapter vendor, see Diligent::ADAPTER_VENDOR.
+ enum ADAPTER_VENDOR Vendor DEFAULT_INITIALIZER(ADAPTER_VENDOR_UNKNOWN);
+
+ /// The amount of local video memory, in bytes, that is not accessible by CPU.
+
+ /// \note On some devices it may not be possible to query the memory size,
+ /// in which case all memory sizes will be zero.
+ Uint64 DeviceLocalMemory DEFAULT_INITIALIZER(0);
+
+ /// The amount of host-visible memory, in bytes, that can be accessed by CPU.
+ Uint64 HostVisibileMemory DEFAULT_INITIALIZER(0);
+
+ /// The amount of unified memory, in bytes, that can be directly accessed by both CPU and GPU.
+ Uint64 UnifiedMemory DEFAULT_INITIALIZER(0);
+};
+typedef struct GraphicsAdapterInfo GraphicsAdapterInfo;
+
+
/// Device capabilities
struct DeviceCaps
{
@@ -1668,8 +1720,8 @@ struct DeviceCaps
/// Similar to MajorVersion, this value indicates the maximum supported feature level.
Int32 MinorVersion DEFAULT_INITIALIZER(0);
- /// Adapter type. See Diligent::ADAPTER_TYPE.
- ADAPTER_TYPE AdaterType DEFAULT_INITIALIZER(ADAPTER_TYPE_UNKNOWN);
+ /// Adapter info, see Diligent::GraphicsAdapterInfo.
+ GraphicsAdapterInfo AdapterInfo;
/// Texture sampling capabilities. See Diligent::SamplerCaps.
SamplerCaps SamCaps;
diff --git a/Graphics/GraphicsEngine/interface/Shader.h b/Graphics/GraphicsEngine/interface/Shader.h
index d961b962..63633db4 100644
--- a/Graphics/GraphicsEngine/interface/Shader.h
+++ b/Graphics/GraphicsEngine/interface/Shader.h
@@ -200,6 +200,11 @@ struct ShaderVersion
Major{_Major},
Minor{_Minor}
{}
+
+ bool operator==(const ShaderVersion& rhs) const
+ {
+ return Major == rhs.Major && Minor == rhs.Minor;
+ }
#endif
};
typedef struct ShaderVersion ShaderVersion;
diff --git a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp
index 420b2035..338ea5a9 100644
--- a/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp
+++ b/Graphics/GraphicsEngineD3D11/src/RenderDeviceD3D11Impl.cpp
@@ -130,17 +130,7 @@ RenderDeviceD3D11Impl::RenderDeviceD3D11Impl(IReferenceCounters* pRefCo
if (auto pDXGIAdapter1 = DXGIAdapterFromD3D11Device(pd3d11Device))
{
- DXGI_ADAPTER_DESC1 AdapterDesc = {};
-
- auto hr = pDXGIAdapter1->GetDesc1(&AdapterDesc);
- if (SUCCEEDED(hr))
- {
- m_DeviceCaps.AdaterType = (AdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) ? ADAPTER_TYPE_SOFTWARE : ADAPTER_TYPE_HARDWARE;
- }
- else
- {
- LOG_ERROR_MESSAGE("Failed to get DXGIDevice adapter desc. Adapter type will be unknown.");
- }
+ ReadAdapterInfo(pDXGIAdapter1);
}
#define UNSUPPORTED_FEATURE(Feature, Name) \
diff --git a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
index 41327332..127abdfc 100644
--- a/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/RenderDeviceD3D12Impl.cpp
@@ -184,17 +184,7 @@ RenderDeviceD3D12Impl::RenderDeviceD3D12Impl(IReferenceCounters* pRefCo
if (auto pDXGIAdapter1 = DXGIAdapterFromD3D12Device(pd3d12Device))
{
- DXGI_ADAPTER_DESC1 AdapterDesc = {};
-
- auto hr = pDXGIAdapter1->GetDesc1(&AdapterDesc);
- if (SUCCEEDED(hr))
- {
- m_DeviceCaps.AdaterType = (AdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) ? ADAPTER_TYPE_SOFTWARE : ADAPTER_TYPE_HARDWARE;
- }
- else
- {
- LOG_ERROR_MESSAGE("Failed to get DXGIDevice adapter desc. Adapter type will be unknown.");
- }
+ ReadAdapterInfo(pDXGIAdapter1);
}
// Direct3D12 supports shader model 5.1 on all feature levels (even on 11.0),
diff --git a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
index 61e5fb12..738a8efe 100644
--- a/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
+++ b/Graphics/GraphicsEngineD3DBase/include/RenderDeviceD3DBase.hpp
@@ -30,7 +30,10 @@
/// \file
/// Implementation of the Diligent::RenderDeviceBase template class and related structures
+#include <dxgi.h>
+
#include "RenderDeviceBase.hpp"
+#include "GraphicsAccessories.hpp"
namespace Diligent
{
@@ -178,6 +181,28 @@ public:
Features.PixelUAVWritesAndAtomics = DEVICE_FEATURE_STATE_ENABLED;
Features.TextureUAVExtendedFormats = DEVICE_FEATURE_STATE_ENABLED;
}
+
+protected:
+ void ReadAdapterInfo(IDXGIAdapter1* pdxgiAdapter)
+ {
+ DXGI_ADAPTER_DESC1 dxgiAdapterDesc = {};
+
+ auto hr = pdxgiAdapter->GetDesc1(&dxgiAdapterDesc);
+ if (SUCCEEDED(hr))
+ {
+ auto& AdapterInfo = m_DeviceCaps.AdapterInfo;
+
+ AdapterInfo.Type = (dxgiAdapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) ? ADAPTER_TYPE_SOFTWARE : ADAPTER_TYPE_HARDWARE;
+ AdapterInfo.Vendor = VendorIdToAdapterVendor(dxgiAdapterDesc.VendorId);
+ AdapterInfo.DeviceLocalMemory = dxgiAdapterDesc.DedicatedVideoMemory;
+ AdapterInfo.HostVisibileMemory = dxgiAdapterDesc.SharedSystemMemory;
+ AdapterInfo.UnifiedMemory = 0;
+ }
+ else
+ {
+ LOG_ERROR_MESSAGE("Failed to get DXGIDevice adapter desc. Adapter properties will be unknown.");
+ }
+ }
};
} // namespace Diligent
diff --git a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
index 4ac72599..14ceb576 100644
--- a/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
+++ b/Graphics/GraphicsEngineD3DBase/src/ShaderD3DBase.cpp
@@ -142,7 +142,7 @@ ShaderD3DBase::ShaderD3DBase(const ShaderCreateInfo& ShaderCI, const ShaderVersi
if (UseDXC)
{
VERIFY_EXPR(__uuidof(ID3DBlob) == __uuidof(IDxcBlob));
- DxCompiler->Compile(ShaderCI, nullptr, reinterpret_cast<IDxcBlob**>(&m_pShaderByteCode), nullptr, ShaderCI.ppCompilerOutput);
+ DxCompiler->Compile(ShaderCI, ShaderModel, nullptr, reinterpret_cast<IDxcBlob**>(&m_pShaderByteCode), nullptr, ShaderCI.ppCompilerOutput);
}
else
{
diff --git a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp
index 946ef34b..afb46edb 100644
--- a/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp
+++ b/Graphics/GraphicsEngineOpenGL/include/RenderDeviceGLImpl.hpp
@@ -35,20 +35,6 @@
#include "FBOCache.hpp"
#include "TexRegionRender.hpp"
-enum class GPU_VENDOR
-{
- UNKNOWN,
- INTEL,
- ATI,
- NVIDIA,
- QUALCOMM
-};
-
-struct GPUInfo
-{
- GPU_VENDOR Vendor = GPU_VENDOR::UNKNOWN;
-};
-
namespace Diligent
{
@@ -145,8 +131,6 @@ public:
/// Implementation of IRenderDevice::IdleGPU() in OpenGL backend.
virtual void DILIGENT_CALL_TYPE IdleGPU() override final;
- const GPUInfo& GetGPUInfo() { return m_GPUInfo; }
-
FBOCache& GetFBOCache(GLContext::NativeGLContextType Context);
void OnReleaseTexture(ITexture* pTexture);
@@ -180,8 +164,6 @@ protected:
ThreadingTools::LockFlag m_FBOCacheLockFlag;
std::unordered_map<GLContext::NativeGLContextType, FBOCache> m_FBOCache;
- GPUInfo m_GPUInfo;
-
std::unique_ptr<TexRegionRender> m_pTexRegionRender;
private:
diff --git a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
index 970dc49e..ed6c3705 100644
--- a/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
+++ b/Graphics/GraphicsEngineOpenGL/src/RenderDeviceGLImpl.cpp
@@ -196,17 +196,65 @@ RenderDeviceGLImpl::RenderDeviceGLImpl(IReferenceCounters* pRefCounters,
std::string Vendor = StrToLower(std::string(glstrVendor.begin(), glstrVendor.end()));
LOG_INFO_MESSAGE("GPU Vendor: ", Vendor);
+ auto& AdapterInfo = m_DeviceCaps.AdapterInfo;
+
+ AdapterInfo.Type = ADAPTER_TYPE_HARDWARE;
+ AdapterInfo.DeviceLocalMemory = 0;
+ AdapterInfo.HostVisibileMemory = 0;
+ AdapterInfo.UnifiedMemory = 0;
+
if (Vendor.find("intel") != std::string::npos)
- m_GPUInfo.Vendor = GPU_VENDOR::INTEL;
+ AdapterInfo.Vendor = ADAPTER_VENDOR_INTEL;
else if (Vendor.find("nvidia") != std::string::npos)
- m_GPUInfo.Vendor = GPU_VENDOR::NVIDIA;
+ {
+ AdapterInfo.Vendor = ADAPTER_VENDOR_NVIDIA;
+
+#ifndef GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX
+ static constexpr GLenum GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX = 0x9048;
+#endif
+
+ GLint AvailableMemoryKb = 0;
+ glGetIntegerv(GL_GPU_MEM_INFO_TOTAL_AVAILABLE_MEM_NVX, &AvailableMemoryKb);
+ if (glGetError() == GL_NO_ERROR)
+ {
+ AdapterInfo.DeviceLocalMemory = static_cast<Uint64>(AvailableMemoryKb) * Uint64{1024};
+ }
+ else
+ {
+ LOG_WARNING_MESSAGE("Unable to read available memory size for NVidia GPU");
+ }
+ }
else if (Vendor.find("ati") != std::string::npos ||
Vendor.find("amd") != std::string::npos)
- m_GPUInfo.Vendor = GPU_VENDOR::ATI;
- else if (Vendor.find("qualcomm"))
- m_GPUInfo.Vendor = GPU_VENDOR::QUALCOMM;
+ {
+ AdapterInfo.Vendor = ADAPTER_VENDOR_AMD;
- m_DeviceCaps.AdaterType = ADAPTER_TYPE_HARDWARE;
+#ifndef GL_TEXTURE_FREE_MEMORY_ATI
+ static constexpr GLenum GL_TEXTURE_FREE_MEMORY_ATI = 0x87FC;
+#endif
+ // https://www.khronos.org/registry/OpenGL/extensions/ATI/ATI_meminfo.txt
+ // param[0] - total memory free in the pool
+ // param[1] - largest available free block in the pool
+ // param[2] - total auxiliary memory free
+ // param[3] - largest auxiliary free block
+ GLint MemoryParamsKb[4] = {};
+
+ glGetIntegerv(GL_TEXTURE_FREE_MEMORY_ATI, MemoryParamsKb);
+ if (glGetError() == GL_NO_ERROR)
+ {
+ AdapterInfo.DeviceLocalMemory = static_cast<Uint64>(MemoryParamsKb[0]) * Uint64{1024};
+ }
+ else
+ {
+ LOG_WARNING_MESSAGE("Unable to read free memory size for AMD GPU");
+ }
+ }
+ else if (Vendor.find("qualcomm"))
+ AdapterInfo.Vendor = ADAPTER_VENDOR_QUALCOMM;
+ else if (Vendor.find("arm"))
+ AdapterInfo.Vendor = ADAPTER_VENDOR_ARM;
+ else
+ AdapterInfo.Vendor = ADAPTER_VENDOR_UNKNOWN;
auto MajorVersion = m_DeviceCaps.MajorVersion;
auto MinorVersion = m_DeviceCaps.MinorVersion;
diff --git a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
index ccbc8e5f..87bb60e2 100644
--- a/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/RenderDeviceVkImpl.cpp
@@ -155,7 +155,44 @@ RenderDeviceVkImpl::RenderDeviceVkImpl(IReferenceCounters*
m_DeviceCaps.DevType = RENDER_DEVICE_TYPE_VULKAN;
m_DeviceCaps.MajorVersion = 1;
m_DeviceCaps.MinorVersion = 0;
- m_DeviceCaps.AdaterType = ADAPTER_TYPE_HARDWARE;
+
+ auto& AdapterInfo = m_DeviceCaps.AdapterInfo;
+
+ const auto& DeviceProps = m_PhysicalDevice->GetProperties();
+
+ AdapterInfo.Vendor = VendorIdToAdapterVendor(DeviceProps.vendorID);
+ AdapterInfo.Type = ADAPTER_TYPE_HARDWARE;
+ AdapterInfo.DeviceLocalMemory = 0;
+ AdapterInfo.HostVisibileMemory = 0;
+ AdapterInfo.UnifiedMemory = 0;
+
+ const auto& MemoryProps = m_PhysicalDevice->GetMemoryProperties();
+ for (uint32_t heap = 0; heap < MemoryProps.memoryHeapCount; ++heap)
+ {
+ const auto& HeapInfo = MemoryProps.memoryHeaps[heap];
+ if (HeapInfo.flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT)
+ {
+ bool IsUnified = false;
+ for (uint32_t type = 0; type < MemoryProps.memoryTypeCount; ++type)
+ {
+ const auto& MemTypeInfo = MemoryProps.memoryTypes[type];
+ if (MemTypeInfo.heapIndex != heap)
+ continue;
+ constexpr auto UnifiedMemoryFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT | VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+ if ((MemTypeInfo.propertyFlags & UnifiedMemoryFlags) == UnifiedMemoryFlags)
+ {
+ IsUnified = true;
+ break;
+ }
+ }
+ (IsUnified ? AdapterInfo.UnifiedMemory : AdapterInfo.DeviceLocalMemory) += static_cast<Uint64>(HeapInfo.size);
+ }
+ else
+ {
+ AdapterInfo.HostVisibileMemory += static_cast<Uint64>(HeapInfo.size);
+ }
+ }
+
for (Uint32 fmt = 1; fmt < m_TextureFormatsInfo.size(); ++fmt)
m_TextureFormatsInfo[fmt].Supported = true; // We will test every format on a specific hardware device
diff --git a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
index c16010d8..a094f014 100644
--- a/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/ShaderVkImpl.cpp
@@ -81,7 +81,7 @@ ShaderVkImpl::ShaderVkImpl(IReferenceCounters* pRefCounters,
{
auto* pDXComiler = pRenderDeviceVk->GetDxCompiler();
VERIFY_EXPR(pDXComiler != nullptr && pDXComiler->IsLoaded());
- pDXComiler->Compile(CreationAttribs, VulkanDefine, nullptr, &m_SPIRV, CreationAttribs.ppCompilerOutput);
+ pDXComiler->Compile(CreationAttribs, ShaderVersion{}, VulkanDefine, nullptr, &m_SPIRV, CreationAttribs.ppCompilerOutput);
}
break;
diff --git a/Graphics/ShaderTools/include/DXCompiler.hpp b/Graphics/ShaderTools/include/DXCompiler.hpp
index 32655a78..6345ad7a 100644
--- a/Graphics/ShaderTools/include/DXCompiler.hpp
+++ b/Graphics/ShaderTools/include/DXCompiler.hpp
@@ -74,6 +74,7 @@ public:
virtual bool Compile(const CompileAttribs& Attribs) = 0;
virtual void Compile(const ShaderCreateInfo& ShaderCI,
+ ShaderVersion ShaderModel,
const char* ExtraDefinitions,
IDxcBlob** ppByteCodeBlob,
std::vector<uint32_t>* pByteCode,
diff --git a/Graphics/ShaderTools/src/DXCompiler.cpp b/Graphics/ShaderTools/src/DXCompiler.cpp
index 50042df4..b35bfefa 100644
--- a/Graphics/ShaderTools/src/DXCompiler.cpp
+++ b/Graphics/ShaderTools/src/DXCompiler.cpp
@@ -83,6 +83,7 @@ public:
bool Compile(const CompileAttribs& Attribs) override final;
virtual void Compile(const ShaderCreateInfo& ShaderCI,
+ ShaderVersion ShaderModel,
const char* ExtraDefinitions,
IDxcBlob** ppByteCodeBlob,
std::vector<uint32_t>* pByteCode,
@@ -412,6 +413,7 @@ void DXCompilerImpl::GetD3D12ShaderReflection(IDxcBlob* pShaderBy
void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
+ ShaderVersion ShaderModel,
const char* ExtraDefinitions,
IDxcBlob** ppByteCodeBlob,
std::vector<uint32_t>* pByteCode,
@@ -423,15 +425,26 @@ void DXCompilerImpl::Compile(const ShaderCreateInfo& ShaderCI,
return;
}
- // validate shader version
- ShaderVersion ShaderModel = ShaderCI.HLSLVersion;
- ShaderVersion MaxSM = GetMaxShaderModel();
+ ShaderVersion MaxSM = GetMaxShaderModel();
- if (ShaderModel.Major < 6 || ShaderModel.Major > MaxSM.Major)
+ // validate shader version
+ if (ShaderModel == ShaderVersion{})
+ {
ShaderModel = MaxSM;
-
- if (ShaderModel.Major == MaxSM.Major && ShaderModel.Minor > MaxSM.Minor)
+ }
+ else if (ShaderModel.Major < 6)
+ {
+ LOG_INFO_MESSAGE("DXC only supports shader model 6.0+. Upgrading the specified shader model ",
+ Uint32{ShaderModel.Major}, '_', Uint32{ShaderModel.Minor}, " to 6_0");
+ ShaderModel = ShaderVersion{6, 0};
+ }
+ else if ((ShaderModel.Major > MaxSM.Major) ||
+ (ShaderModel.Major == MaxSM.Major && ShaderModel.Minor > MaxSM.Minor))
+ {
+ LOG_WARNING_MESSAGE("The maximum supported shader model by DXC is ", Uint32{MaxSM.Major}, '_', Uint32{MaxSM.Minor},
+ ". The specified shader model ", Uint32{ShaderModel.Major}, '_', Uint32{ShaderModel.Minor}, " will be downgraded.");
ShaderModel = MaxSM;
+ }
const auto Profile = GetHLSLProfileString(ShaderCI.Desc.ShaderType, ShaderModel);
const std::wstring wstrProfile{Profile.begin(), Profile.end()};