diff options
| author | azhirnov <zh1dron@gmail.com> | 2020-12-08 14:56:12 +0000 |
|---|---|---|
| committer | azhirnov <zh1dron@gmail.com> | 2020-12-09 15:49:14 +0000 |
| commit | 1f9e0a4cd484687c13999d4a6686e104e0a93470 (patch) | |
| tree | d8851006fcedaa7b1db632873f85a9953d9c57a5 /Graphics/GraphicsEngine | |
| parent | Disable validation layers if they are not compatible with headers, fixed comp... (diff) | |
| download | DiligentCore-1f9e0a4cd484687c13999d4a6686e104e0a93470.tar.gz DiligentCore-1f9e0a4cd484687c13999d4a6686e104e0a93470.zip | |
some improvements for ray tracing
Diffstat (limited to 'Graphics/GraphicsEngine')
7 files changed, 46 insertions, 6 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index ced32db5..76cc51c0 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -1644,6 +1644,19 @@ bool DeviceContextBase<BaseInterface, ImplementationTraits>::TraceRays(const Tra if (!VerifyTraceRaysAttribs(Attribs)) return false; + + if (m_pPipelineState.RawPtr() != Attribs.pSBT->GetDesc().pPSO) + { + LOG_ERROR_MESSAGE("IDeviceContext::TraceRays command arguments are invalid: currently bound pipeline ", m_pPipelineState->GetDesc().Name, + "doesn't match the pipeline ", Attribs.pSBT->GetDesc().pPSO->GetDesc().Name, " that was used in ShaderBindingTable"); + return false; + } + + if ((Attribs.DimensionX * Attribs.DimensionY * Attribs.DimensionZ) > m_pDevice->GetProperties().MaxRayGenThreads) + { + LOG_ERROR_MESSAGE("IDeviceContext::TraceRays command arguments are invalid: the dimension must not exceed the ", m_pDevice->GetProperties().MaxRayGenThreads, " threads"); + return false; + } #endif return true; diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp index 5e8293a1..54b9ba0c 100644 --- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp +++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp @@ -48,7 +48,7 @@ namespace Diligent void ValidateGraphicsPipelineCreateInfo(const GraphicsPipelineStateCreateInfo& CreateInfo) noexcept(false); void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& CreateInfo) noexcept(false); -void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false); +void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecursion, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false); void CopyRayTracingShaderGroups(std::unordered_map<HashMapStringKey, Uint32, HashMapStringKey::Hasher>& NameToGroupIndex, const RayTracingPipelineStateCreateInfo& CreateInfo, @@ -128,7 +128,7 @@ public: bool bIsDeviceInternal = false) : PipelineStateBase{pRefCounters, pDevice, RayTracingPipelineCI.PSODesc, bIsDeviceInternal} { - ValidateRayTracingPipelineCreateInfo(pDevice, RayTracingPipelineCI); + ValidateRayTracingPipelineCreateInfo(pDevice, pDevice->GetProperties().MaxRayTracingRecursionDepth, RayTracingPipelineCI); } diff --git a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp index 82d5049b..cff25a92 100644 --- a/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp +++ b/Graphics/GraphicsEngine/include/RenderDeviceBase.hpp @@ -273,7 +273,8 @@ public: m_FramebufferAllocator {RawMemAllocator, ObjectSizes.FramebufferObjSize, 16 }, m_BLASAllocator {RawMemAllocator, ObjectSizes.BLASObjSize, 16 }, m_TLASAllocator {RawMemAllocator, ObjectSizes.TLASObjSize, 16 }, - m_SBTAllocator {RawMemAllocator, ObjectSizes.SBTObjSize, 16 } + m_SBTAllocator {RawMemAllocator, ObjectSizes.SBTObjSize, 16 }, + m_DeviceProperties {} // clang-format on { // Initialize texture format info @@ -347,6 +348,12 @@ public: return m_DeviceCaps; } + /// Implementation of IRenderDevice::GetDeviceProperties(). + virtual const DeviceProperties& DILIGENT_CALL_TYPE GetDeviceProperties() const override final + { + return m_DeviceProperties; + } + /// Implementation of IRenderDevice::GetTextureFormatInfo(). virtual const TextureFormatInfo& DILIGENT_CALL_TYPE GetTextureFormatInfo(TEXTURE_FORMAT TexFormat) override final { @@ -418,7 +425,8 @@ protected: RefCntAutoPtr<IEngineFactory> m_pEngineFactory; - DeviceCaps m_DeviceCaps; + DeviceCaps m_DeviceCaps; + DeviceProperties m_DeviceProperties; // All state object registries hold raw pointers. // This is safe because every object unregisters itself diff --git a/Graphics/GraphicsEngine/interface/GraphicsTypes.h b/Graphics/GraphicsEngine/interface/GraphicsTypes.h index 3ec5ee3f..73569a7a 100644 --- a/Graphics/GraphicsEngine/interface/GraphicsTypes.h +++ b/Graphics/GraphicsEngine/interface/GraphicsTypes.h @@ -1855,6 +1855,15 @@ struct DeviceCaps typedef struct DeviceCaps DeviceCaps; +/// Device properties +struct DeviceProperties +{ + /// Maximum supported value for RayTracingPipelineDesc::MaxRecursionDepth. + Uint32 MaxRayTracingRecursionDepth; +}; +typedef struct DeviceProperties DeviceProperties; + + /// Engine creation attibutes struct EngineCreateInfo { diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h index b43ee206..875c6a21 100644 --- a/Graphics/GraphicsEngine/interface/PipelineState.h +++ b/Graphics/GraphicsEngine/interface/PipelineState.h @@ -310,7 +310,9 @@ struct RayTracingPipelineDesc Uint16 ShaderRecordSize DEFAULT_INITIALIZER(0); /// Number of recursive calls of TraceRay() in HLSL or traceRay() in GLSL. - Uint8 MaxRecursionDepth DEFAULT_INITIALIZER(0); // must be 0..31 (check current device limits) + /// Zero means no tracing of rays at all, only ray-gen shader will be executed. + /// See DeviceProperties::MaxRayTracingRecursionDepth. + Uint8 MaxRecursionDepth DEFAULT_INITIALIZER(0); }; typedef struct RayTracingPipelineDesc RayTracingPipelineDesc; diff --git a/Graphics/GraphicsEngine/interface/RenderDevice.h b/Graphics/GraphicsEngine/interface/RenderDevice.h index ac30d615..deaaab71 100644 --- a/Graphics/GraphicsEngine/interface/RenderDevice.h +++ b/Graphics/GraphicsEngine/interface/RenderDevice.h @@ -276,6 +276,9 @@ DILIGENT_BEGIN_INTERFACE(IRenderDevice, IObject) /// Gets the device capabilities, see Diligent::DeviceCaps for details VIRTUAL const DeviceCaps REF METHOD(GetDeviceCaps)(THIS) CONST PURE; + + /// Gets the device properties, see Diligent::DeviceProperties for details + VIRTUAL const DeviceProperties REF METHOD(GetDeviceProperties)(THIS) CONST PURE; /// Returns the basic texture format information. diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp index 009f5468..5adc101d 100644 --- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp +++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp @@ -248,7 +248,7 @@ void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& Cre VALIDATE_SHADER_TYPE(CreateInfo.pCS, SHADER_TYPE_COMPUTE, "compute"); } -void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false) +void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, Uint32 MaxRecursion, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false) { const auto& PSODesc = CreateInfo.PSODesc; if (PSODesc.PipelineType != PIPELINE_TYPE_RAY_TRACING) @@ -260,6 +260,11 @@ void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, const RayTraci LOG_PSO_ERROR_AND_THROW("pShaderRecordName must not be null if RayTracingPipeline.ShaderRecordSize is not zero"); } + if (CreateInfo.RayTracingPipeline.MaxRecursionDepth > MaxRecursion) + { + LOG_PSO_ERROR_AND_THROW("MaxRecursionDepth must not exceed the ", MaxRecursion); + } + for (Uint32 i = 0; i < CreateInfo.GeneralShaderCount; ++i) { const auto& Group = CreateInfo.pGeneralShaders[i]; |
