summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-11-05 16:58:57 +0000
committerazhirnov <zh1dron@gmail.com>2020-11-05 16:58:57 +0000
commit8e0218168e2f63812f658298b3571c53879a5780 (patch)
treeb07a48fcca9fb9440493ed00b67dd2b28872c327 /Graphics/GraphicsEngine
parentAdded AS copy with compacting. (diff)
downloadDiligentCore-8e0218168e2f63812f658298b3571c53879a5780.tar.gz
DiligentCore-8e0218168e2f63812f658298b3571c53879a5780.zip
Added support for local root signature & shader record.
Bug fix for ray tracing.
Diffstat (limited to 'Graphics/GraphicsEngine')
-rw-r--r--Graphics/GraphicsEngine/include/BottomLevelASBase.hpp1
-rw-r--r--Graphics/GraphicsEngine/include/DeviceContextBase.hpp14
-rw-r--r--Graphics/GraphicsEngine/include/PipelineStateBase.hpp8
-rw-r--r--Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp11
-rw-r--r--Graphics/GraphicsEngine/include/TopLevelASBase.hpp5
-rw-r--r--Graphics/GraphicsEngine/interface/DeviceContext.h24
-rw-r--r--Graphics/GraphicsEngine/interface/PipelineState.h8
-rw-r--r--Graphics/GraphicsEngine/src/PipelineStateBase.cpp8
8 files changed, 50 insertions, 29 deletions
diff --git a/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp b/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp
index 5a6db4bd..08fc4243 100644
--- a/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp
+++ b/Graphics/GraphicsEngine/include/BottomLevelASBase.hpp
@@ -166,6 +166,7 @@ public:
bool ValidateContent() const
{
+ // AZ TODO
return true;
}
#endif // DILIGENT_DEVELOPMENT
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
index f7abedb8..8200012b 100644
--- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
+++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp
@@ -279,8 +279,8 @@ protected:
// clang-format on
#endif
- bool BuildBLAS(const BLASBuildAttribs& Attribs, int) const;
- bool BuildTLAS(const TLASBuildAttribs& Attribs, int) const;
+ bool BuildBLAS(const BuildBLASAttribs& Attribs, int) const;
+ bool BuildTLAS(const BuildTLASAttribs& Attribs, int) const;
bool CopyBLAS(const CopyBLASAttribs& Attribs, int) const;
bool CopyTLAS(const CopyTLASAttribs& Attribs, int) const;
bool WriteBLASCompactedSize(const WriteBLASCompactedSizeAttribs& Attribs, int) const;
@@ -1970,7 +1970,7 @@ bool DeviceContextBase<BaseInterface, ImplementationTraits>::
#endif // DILIGENT_DEVELOPMENT
template <typename BaseInterface, typename ImplementationTraits>
-bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildBLAS(const BLASBuildAttribs& Attribs, int) const
+bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildBLAS(const BuildBLASAttribs& Attribs, int) const
{
if (m_pDevice->GetDeviceCaps().Features.RayTracing != DEVICE_FEATURE_STATE_ENABLED)
{
@@ -2211,7 +2211,7 @@ bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildBLAS(const BLA
}
template <typename BaseInterface, typename ImplementationTraits>
-bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildTLAS(const TLASBuildAttribs& Attribs, int) const
+bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildTLAS(const BuildTLASAttribs& Attribs, int) const
{
if (m_pDevice->GetDeviceCaps().Features.RayTracing != DEVICE_FEATURE_STATE_ENABLED)
{
@@ -2290,6 +2290,12 @@ bool DeviceContextBase<BaseInterface, ImplementationTraits>::BuildTLAS(const TLA
return false;
}
+ if (!ValidatedCast<BottomLevelASType>(Attribs.pInstances[i].pBLAS)->ValidateContent())
+ {
+ LOG_ERROR_MESSAGE("IDeviceContext::BuildTLAS: pInstances[", i, "].pBLAS is not valid");
+ return false;
+ }
+
if (Attribs.pInstances[i].ContributionToHitGroupIndex == TLAS_INSTANCE_OFFSET_AUTO)
++AutoOffsetCounter;
diff --git a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
index 5a2db2f8..d0685e4e 100644
--- a/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
+++ b/Graphics/GraphicsEngine/include/PipelineStateBase.hpp
@@ -46,7 +46,7 @@ namespace Diligent
void ValidateGraphicsPipelineCreateInfo(const GraphicsPipelineStateCreateInfo& CreateInfo) noexcept(false);
void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& CreateInfo) noexcept(false);
-void ValidateRayTracingPipelineCreateInfo(const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false);
+void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false);
void CorrectGraphicsPipelineDesc(GraphicsPipelineDesc& GraphicsPipeline) noexcept;
@@ -122,7 +122,7 @@ public:
bool bIsDeviceInternal = false) :
PipelineStateBase{pRefCounters, pDevice, RayTracingPipelineCI.PSODesc, bIsDeviceInternal}
{
- ValidateRayTracingPipelineCreateInfo(RayTracingPipelineCI);
+ ValidateRayTracingPipelineCreateInfo(pDevice, RayTracingPipelineCI);
}
@@ -344,8 +344,6 @@ protected:
void ReserveSpaceForPipelineDesc(const RayTracingPipelineStateCreateInfo& CreateInfo,
LinearAllocator& MemPool) const noexcept
{
- ReserveResourceLayout(CreateInfo.PSODesc.ResourceLayout, MemPool);
-
for (Uint32 i = 0; i < CreateInfo.GeneralShaderCount; ++i)
{
MemPool.AddSpaceForString(CreateInfo.pGeneralShaders[i].Name);
@@ -359,6 +357,8 @@ protected:
MemPool.AddSpaceForString(CreateInfo.pProceduralHitShaders[i].Name);
}
+ ReserveResourceLayout(CreateInfo.PSODesc.ResourceLayout, MemPool);
+
size_t RTDataSize = sizeof(RayTracingPipelineData);
// reserve size for shader handles
const auto ShaderHandleSize = this->m_pDevice->GetShaderGroupHandleSize();
diff --git a/Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp b/Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp
index 04870876..ce4e0e4c 100644
--- a/Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp
+++ b/Graphics/GraphicsEngine/include/ShaderBindingTableBase.hpp
@@ -281,7 +281,7 @@ public:
BindingTable& HitShaderBindingTable,
BindingTable& CallableShaderBindingTable)
{
- const auto ShaderGroupBaseAlignment = GetDevice()->GetShaderGroupBaseAlignment();
+ const auto ShaderGroupBaseAlignment = this->m_pDevice->GetShaderGroupBaseAlignment();
const auto AlignToLarger = [ShaderGroupBaseAlignment](size_t offset) -> Uint32 {
return Align(static_cast<Uint32>(offset), ShaderGroupBaseAlignment);
@@ -298,14 +298,14 @@ public:
{
this->m_pBuffer = nullptr;
- String BuffName = String{GetDesc().Name} + " - internal buffer";
+ String BuffName = String{this->m_Desc.Name} + " - internal buffer";
BufferDesc BuffDesc;
BuffDesc.Name = BuffName.c_str();
BuffDesc.Usage = USAGE_DEFAULT;
BuffDesc.BindFlags = BIND_RAY_TRACING;
BuffDesc.uiSizeInBytes = BufSize;
- GetDevice()->CreateBuffer(BuffDesc, nullptr, &this->m_pBuffer);
+ this->m_pDevice->CreateBuffer(BuffDesc, nullptr, &this->m_pBuffer);
VERIFY_EXPR(this->m_pBuffer != nullptr);
}
@@ -399,7 +399,10 @@ protected:
Uint32 m_ShaderRecordStride = 0;
bool m_Changed = true;
- static const Uint8 EmptyElem = 0xA7;
+ static const Uint8 EmptyElem;
};
+template <class BaseInterface, class PipelineStateImplType, class RenderDeviceImplType>
+const Uint8 ShaderBindingTableBase<BaseInterface, PipelineStateImplType, RenderDeviceImplType>::EmptyElem = 0xA7;
+
} // namespace Diligent
diff --git a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
index a8896abb..47cf50dd 100644
--- a/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
+++ b/Graphics/GraphicsEngine/include/TopLevelASBase.hpp
@@ -33,7 +33,6 @@
#include <unordered_map>
#include "TopLevelAS.h"
-#include "BottomLevelAS.h"
#include "DeviceObjectBase.hpp"
#include "RenderDeviceBase.hpp"
#include "StringPool.hpp"
@@ -158,7 +157,7 @@ public:
if (iter != this->m_Instances.end())
{
Result.ContributionToHitGroupIndex = iter->second.ContributionToHitGroupIndex;
- Result.pBLAS = iter->second.pBLAS.RawPtr<IBottomLevelAS>();
+ Result.pBLAS = iter->second.pBLAS.template RawPtr<IBottomLevelAS>();
}
else
{
@@ -199,7 +198,7 @@ public:
if (m_Instances.empty())
{
- LOG_ERROR_MESSAGE("TLAS with name ('", GetDesc().Name, "') doesn't have instances, use IDeviceContext::BuildTLAS() or IDeviceContext::CopyTLAS() to initialize TLAS content");
+ LOG_ERROR_MESSAGE("TLAS with name ('", this->m_Desc.Name, "') doesn't have instances, use IDeviceContext::BuildTLAS() or IDeviceContext::CopyTLAS() to initialize TLAS content");
result = false;
}
diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h
index 6c035ded..1e9bb188 100644
--- a/Graphics/GraphicsEngine/interface/DeviceContext.h
+++ b/Graphics/GraphicsEngine/interface/DeviceContext.h
@@ -876,7 +876,7 @@ typedef struct BLASBuildBoundingBoxData BLASBuildBoundingBoxData;
/// This structure is used by IDeviceContext::BuildBLAS().
-struct BLASBuildAttribs
+struct BuildBLASAttribs
{
/// Target bottom-level AS.
IBottomLevelAS* pBLAS DEFAULT_INITIALIZER(nullptr);
@@ -913,10 +913,10 @@ struct BLASBuildAttribs
RESOURCE_STATE_TRANSITION_MODE ScratchBufferTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
#if DILIGENT_CPP_INTERFACE
- BLASBuildAttribs() noexcept {}
+ BuildBLASAttribs() noexcept {}
#endif
};
-typedef struct BLASBuildAttribs BLASBuildAttribs;
+typedef struct BuildBLASAttribs BuildBLASAttribs;
/// Can be used in TLASBuildInstanceData::ContributionToHitGroupIndex to calculate index
@@ -973,7 +973,7 @@ struct InstanceMatrix
typedef struct InstanceMatrix InstanceMatrix;
-/// This structure is used by TLASBuildAttribs.
+/// This structure is used by BuildTLASAttribs.
struct TLASBuildInstanceData
{
/// Instance name that used to map instance to hit group in shader binding table.
@@ -1009,12 +1009,12 @@ typedef struct TLASBuildInstanceData TLASBuildInstanceData;
/// Instance size in GPU side.
-/// Used to calculate size of TLASBuildAttribs::pInstanceBuffer.
+/// Used to calculate size of BuildTLASAttribs::pInstanceBuffer.
static const Uint32 TLAS_INSTANCE_DATA_SIZE = 64;
/// This structure is used by IDeviceContext::BuildTLAS().
-struct TLASBuildAttribs
+struct BuildTLASAttribs
{
/// Target top-level AS.
ITopLevelAS* pTLAS DEFAULT_INITIALIZER(nullptr);
@@ -1058,10 +1058,10 @@ struct TLASBuildAttribs
RESOURCE_STATE_TRANSITION_MODE ScratchBufferTransitionMode DEFAULT_INITIALIZER(RESOURCE_STATE_TRANSITION_MODE_NONE);
#if DILIGENT_CPP_INTERFACE
- TLASBuildAttribs() noexcept {}
+ BuildTLASAttribs() noexcept {}
#endif
};
-typedef struct TLASBuildAttribs TLASBuildAttribs;
+typedef struct BuildTLASAttribs BuildTLASAttribs;
/// This structure is used by IDeviceContext::CopyBLAS().
@@ -2085,16 +2085,16 @@ DILIGENT_BEGIN_INTERFACE(IDeviceContext, IObject)
/// Build Bottom-level acceleration structure with the specified geometries.
- /// \param [in] Attribs - Structure describing build BLAS command attributes, see Diligent::BLASBuildAttribs for details.
+ /// \param [in] Attribs - Structure describing build BLAS command attributes, see Diligent::BuildBLASAttribs for details.
VIRTUAL void METHOD(BuildBLAS)(THIS_
- const BLASBuildAttribs REF Attribs) PURE;
+ const BuildBLASAttribs REF Attribs) PURE;
/// Build Top-level acceleration structure with the specified instances.
- /// \param [in] Attribs - Structure describing build TLAS command attributes, see Diligent::TLASBuildAttribs for details.
+ /// \param [in] Attribs - Structure describing build TLAS command attributes, see Diligent::BuildTLASAttribs for details.
VIRTUAL void METHOD(BuildTLAS)(THIS_
- const TLASBuildAttribs REF Attribs) PURE;
+ const BuildTLASAttribs REF Attribs) PURE;
/// Copies data from one acceleration structure to another.
diff --git a/Graphics/GraphicsEngine/interface/PipelineState.h b/Graphics/GraphicsEngine/interface/PipelineState.h
index a630b1f1..6c46fd27 100644
--- a/Graphics/GraphicsEngine/interface/PipelineState.h
+++ b/Graphics/GraphicsEngine/interface/PipelineState.h
@@ -472,7 +472,13 @@ struct RayTracingPipelineStateCreateInfo DILIGENT_DERIVE(PipelineStateCreateInfo
/// Direct3D12 only: set name of constant buffer that will be used by local root signature.
/// Ignored if RayTracingPipelineDesc::ShaderRecordSize is zero.
- const char* ShaderRecordName DEFAULT_INITIALIZER(nullptr);
+ const char* pShaderRecordName DEFAULT_INITIALIZER(nullptr);
+
+ /// Direct3D12 only: set max hit shader attribute size in bytes.
+ Uint32 MaxAttributeSize DEFAULT_INITIALIZER(0);
+
+ /// Direct3D12 only: set max payload size in bytes.
+ Uint32 MaxPayloadSize DEFAULT_INITIALIZER(0);
};
typedef struct RayTracingPipelineStateCreateInfo RayTracingPipelineStateCreateInfo;
diff --git a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp
index 29624b2f..6491d15e 100644
--- a/Graphics/GraphicsEngine/src/PipelineStateBase.cpp
+++ b/Graphics/GraphicsEngine/src/PipelineStateBase.cpp
@@ -249,12 +249,18 @@ void ValidateComputePipelineCreateInfo(const ComputePipelineStateCreateInfo& Cre
VALIDATE_SHADER_TYPE(CreateInfo.pCS, SHADER_TYPE_COMPUTE, "compute");
}
-void ValidateRayTracingPipelineCreateInfo(const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false)
+void ValidateRayTracingPipelineCreateInfo(IRenderDevice* pDevice, const RayTracingPipelineStateCreateInfo& CreateInfo) noexcept(false)
{
const auto& PSODesc = CreateInfo.PSODesc;
if (PSODesc.PipelineType != PIPELINE_TYPE_RAY_TRACING)
LOG_PSO_ERROR_AND_THROW("Pipeline type must be RAY_TRACING");
+ if (pDevice->GetDeviceCaps().DevType == RENDER_DEVICE_TYPE_D3D12)
+ {
+ if ((CreateInfo.pShaderRecordName != nullptr) != (CreateInfo.RayTracingPipeline.ShaderRecordSize > 0))
+ LOG_PSO_ERROR_AND_THROW("pShaderRecordName must not be null if RayTracingPipeline.ShaderRecordSize is not zero");
+ }
+
for (Uint32 i = 0; i < CreateInfo.GeneralShaderCount; ++i)
{
const auto& Group = CreateInfo.pGeneralShaders[i];