Skip to content

Commit 42d3b14

Browse files
azhirnovTheMostDiligent
authored andcommitted
Check alignment for VertexOffset and IndexOffset BLAS build attribs
1 parent 9cb1d74 commit 42d3b14

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Graphics/GraphicsEngine/include/DeviceContextBase.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool VerifyStateTransitionDesc(const IRenderDevice* pDevice,
8282
DeviceContextIndex ExecutionCtxId,
8383
const DeviceContextDesc& CtxDesc);
8484

85-
bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs);
85+
bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs& Attribs);
8686
bool VerifyBuildTLASAttribs(const BuildTLASAttribs& Attribs);
8787
bool VerifyCopyBLASAttribs(const IRenderDevice* pDevice, const CopyBLASAttribs& Attribs);
8888
bool VerifyCopyTLASAttribs(const CopyTLASAttribs& Attribs);
@@ -1727,7 +1727,7 @@ void DeviceContextBase<ImplementationTraits>::BuildBLAS(const BuildBLASAttribs&
17271727
DVP_CHECK_QUEUE_TYPE_COMPATIBILITY(COMMAND_QUEUE_TYPE_COMPUTE, "BuildBLAS");
17281728
DEV_CHECK_ERR(m_pDevice->GetFeatures().RayTracing, "IDeviceContext::BuildBLAS: ray tracing is not supported by this device");
17291729
DEV_CHECK_ERR(m_pActiveRenderPass == nullptr, "IDeviceContext::BuildBLAS command must be performed outside of render pass");
1730-
DEV_CHECK_ERR(VerifyBuildBLASAttribs(Attribs), "BuildBLASAttribs are invalid");
1730+
DEV_CHECK_ERR(VerifyBuildBLASAttribs(m_pDevice, Attribs), "BuildBLASAttribs are invalid");
17311731
}
17321732

17331733
template <typename ImplementationTraits>

Graphics/GraphicsEngine/src/DeviceContextBase.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ bool VerifyStateTransitionDesc(const IRenderDevice* pDevice,
433433
}
434434

435435

436-
bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs)
436+
bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs& Attribs)
437437
{
438438
#define CHECK_BUILD_BLAS_ATTRIBS(Expr, ...) CHECK_PARAMETER(Expr, "Build BLAS attribs are invalid: ", __VA_ARGS__)
439439

@@ -443,7 +443,8 @@ bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs)
443443
CHECK_BUILD_BLAS_ATTRIBS(Attribs.pBoxData != nullptr || Attribs.BoxDataCount == 0, "BoxDataCount is ", Attribs.BoxDataCount, ", but pBoxData is null.");
444444
CHECK_BUILD_BLAS_ATTRIBS(Attribs.pTriangleData != nullptr || Attribs.TriangleDataCount == 0, "TriangleDataCount is ", Attribs.TriangleDataCount, ", but pTriangleData is null.");
445445

446-
const auto& BLASDesc = Attribs.pBLAS->GetDesc();
446+
const auto& BLASDesc = Attribs.pBLAS->GetDesc();
447+
const auto DeviceType = pDevice->GetDeviceInfo().Type;
447448

448449
CHECK_BUILD_BLAS_ATTRIBS(Attribs.BoxDataCount <= BLASDesc.BoxCount, "BoxDataCount (", Attribs.BoxDataCount, ") must be less than or equal to pBLAS->GetDesc().BoxCount (", BLASDesc.BoxCount, ").");
449450
CHECK_BUILD_BLAS_ATTRIBS(Attribs.TriangleDataCount <= BLASDesc.TriangleCount, "TriangleDataCount (", Attribs.TriangleDataCount, ") must be less than or equal to pBLAS->GetDesc().TriangleCount (", BLASDesc.TriangleCount, ").");
@@ -491,6 +492,10 @@ bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs)
491492
CHECK_BUILD_BLAS_ATTRIBS((VertBufDesc.BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
492493
"pTriangleData[", i, "].pVertexBuffer was not created with BIND_RAY_TRACING flag.");
493494

495+
CHECK_BUILD_BLAS_ATTRIBS(tri.VertexOffset % tri.VertexStride == 0,
496+
"pTriangleData[", i, "].VertexOffset (", tri.VertexOffset, ") must be a multiple of VertexStride (",
497+
tri.VertexStride, ").");
498+
494499
CHECK_BUILD_BLAS_ATTRIBS(tri.VertexOffset + VertexDataSize <= VertBufDesc.uiSizeInBytes,
495500
"pTriangleData[", i, "].pVertexBuffer is too small for the specified VertexStride (", tri.VertexStride, ") and VertexCount (",
496501
tri.VertexCount, "): at least ", tri.VertexOffset + VertexDataSize, " bytes are required.");
@@ -516,6 +521,17 @@ bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs)
516521
CHECK_BUILD_BLAS_ATTRIBS(tri.IndexOffset + IndexDataSize <= InstBufDesc.uiSizeInBytes,
517522
"pTriangleData[", i, "].pIndexBuffer is too small for specified IndexType and IndexCount: at least",
518523
tri.IndexOffset + IndexDataSize, " bytes are required.");
524+
525+
CHECK_BUILD_BLAS_ATTRIBS(tri.IndexOffset % GetValueSize(TriDesc.IndexType) == 0,
526+
"pTriangleData[", i, "].IndexOffset (", tri.IndexOffset, ") must be a multiple of (", GetValueSize(TriDesc.IndexType), ") bytes.");
527+
528+
if (DeviceType == RENDER_DEVICE_TYPE_METAL)
529+
{
530+
const Uint32 MtlIndexOffsetAlignment = 32;
531+
CHECK_BUILD_BLAS_ATTRIBS(tri.IndexOffset % MtlIndexOffsetAlignment == 0,
532+
"pTriangleData[", i, "].IndexOffset (", tri.IndexOffset,
533+
") must be a multiple of the platform buffer offset alignment (", MtlIndexOffsetAlignment, ").");
534+
}
519535
}
520536
else
521537
{

0 commit comments

Comments
 (0)