@@ -433,7 +433,7 @@ bool VerifyStateTransitionDesc(const IRenderDevice* pDevice,
433433}
434434
435435
436- bool VerifyBuildBLASAttribs (const IRenderDevice* pDevice , const BuildBLASAttribs& Attribs )
436+ bool VerifyBuildBLASAttribs (const BuildBLASAttribs& Attribs , const RayTracingProperties& RTProps )
437437{
438438#define CHECK_BUILD_BLAS_ATTRIBS (Expr, ...) CHECK_PARAMETER(Expr, " Build BLAS attribs are invalid: " , __VA_ARGS__)
439439
@@ -443,8 +443,7 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
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 ();
447- const auto DeviceType = pDevice->GetDeviceInfo ().Type ;
446+ const auto & BLASDesc = Attribs.pBLAS ->GetDesc ();
448447
449448 CHECK_BUILD_BLAS_ATTRIBS (Attribs.BoxDataCount <= BLASDesc.BoxCount , " BoxDataCount (" , Attribs.BoxDataCount , " ) must be less than or equal to pBLAS->GetDesc().BoxCount (" , BLASDesc.BoxCount , " )." );
450449 CHECK_BUILD_BLAS_ATTRIBS (Attribs.TriangleDataCount <= BLASDesc.TriangleCount , " TriangleDataCount (" , Attribs.TriangleDataCount , " ) must be less than or equal to pBLAS->GetDesc().TriangleCount (" , BLASDesc.TriangleCount , " )." );
@@ -496,6 +495,10 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
496495 " pTriangleData[" , i, " ].VertexOffset (" , tri.VertexOffset , " ) must be a multiple of VertexStride (" ,
497496 tri.VertexStride , " )." );
498497
498+ CHECK_BUILD_BLAS_ATTRIBS (tri.VertexOffset % RTProps.VertexBufferAlignmnent == 0 ,
499+ " pTriangleData[" , i, " ].VertexOffset (" , tri.VertexOffset , " ) must be aligned by " , RTProps.VertexBufferAlignmnent ,
500+ " (RayTracingProperties::VertexBufferAlignmnent)" );
501+
499502 CHECK_BUILD_BLAS_ATTRIBS (tri.VertexOffset + VertexDataSize <= VertBufDesc.uiSizeInBytes ,
500503 " pTriangleData[" , i, " ].pVertexBuffer is too small for the specified VertexStride (" , tri.VertexStride , " ) and VertexCount (" ,
501504 tri.VertexCount , " ): at least " , tri.VertexOffset + VertexDataSize, " bytes are required." );
@@ -519,19 +522,15 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
519522 " pTriangleData[" , i, " ].pIndexBuffer was not created with BIND_RAY_TRACING flag." );
520523
521524 CHECK_BUILD_BLAS_ATTRIBS (tri.IndexOffset + IndexDataSize <= InstBufDesc.uiSizeInBytes ,
522- " pTriangleData[" , i, " ].pIndexBuffer is too small for specified IndexType and IndexCount: at least" ,
525+ " pTriangleData[" , i, " ].pIndexBuffer is too small for specified IndexType and IndexCount: at least " ,
523526 tri.IndexOffset + IndexDataSize, " bytes are required." );
524527
525528 CHECK_BUILD_BLAS_ATTRIBS (tri.IndexOffset % GetValueSize (TriDesc.IndexType ) == 0 ,
526529 " pTriangleData[" , i, " ].IndexOffset (" , tri.IndexOffset , " ) must be a multiple of (" , GetValueSize (TriDesc.IndexType ), " ) bytes." );
527530
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- }
531+ CHECK_BUILD_BLAS_ATTRIBS (tri.IndexOffset % RTProps.IndexBufferAlignment == 0 ,
532+ " pTriangleData[" , i, " ].IndexOffset (" , tri.IndexOffset , " ) must be aligned by " , RTProps.IndexBufferAlignment ,
533+ " (RayTracingProperties::IndexBufferAlignment)." );
535534 }
536535 else
537536 {
@@ -544,18 +543,28 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
544543
545544 if (tri.pTransformBuffer != nullptr )
546545 {
547- CHECK_BUILD_BLAS_ATTRIBS ((tri.pTransformBuffer ->GetDesc ().BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
546+ const auto & TrfrmBufDesc = tri.pTransformBuffer ->GetDesc ();
547+
548+ CHECK_BUILD_BLAS_ATTRIBS ((TrfrmBufDesc.BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
548549 " pTriangleData[" , i, " ].pTransformBuffer was not created with BIND_RAY_TRACING flag." );
549550
550551 CHECK_BUILD_BLAS_ATTRIBS (TriDesc.AllowsTransforms , " pTriangleData[" , i, " ] uses transform buffer, but AllowsTransforms is false." );
552+
553+ CHECK_BUILD_BLAS_ATTRIBS (tri.TransformBufferOffset + sizeof (InstanceMatrix) <= TrfrmBufDesc.uiSizeInBytes ,
554+ " pTriangleData[" , i, " ].pTransformBuffer is too small: at least " , tri.TransformBufferOffset + sizeof (InstanceMatrix), " bytes are required." );
555+
556+ CHECK_BUILD_BLAS_ATTRIBS (tri.TransformBufferOffset % RTProps.TransformBufferAlignment == 0 ,
557+ " pTriangleData[" , i, " ].TransformBufferOffset (" , tri.TransformBufferOffset , " ) must be aligned by " , RTProps.TransformBufferAlignment ,
558+ " (RayTracingProperties::TransformBufferAlignment)." );
551559 }
552560 }
553561
554562 for (Uint32 i = 0 ; i < Attribs.BoxDataCount ; ++i)
555563 {
556- const auto & box = Attribs.pBoxData [i];
557- const Uint32 BoxSize = sizeof (float ) * 6 ;
558- const Uint32 GeomIndex = Attribs.pBLAS ->GetGeometryDescIndex (box.GeometryName );
564+ const auto & box = Attribs.pBoxData [i];
565+ const Uint32 BoxSize = sizeof (float ) * 6 ;
566+ const Uint32 BoxBufferSize = box.BoxCount * box.BoxStride ;
567+ const Uint32 GeomIndex = Attribs.pBLAS ->GetGeometryDescIndex (box.GeometryName );
559568
560569 CHECK_BUILD_BLAS_ATTRIBS (GeomIndex != INVALID_INDEX,
561570 " pBoxData[" , i, " ].GeometryName (" , box.GeometryName , " ) is not found in BLAS description." );
@@ -567,12 +576,24 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
567576
568577 CHECK_BUILD_BLAS_ATTRIBS (box.BoxStride >= BoxSize,
569578 " pBoxData[" , i, " ].BoxStride (" , box.BoxStride , " ) must be at least " , BoxSize, " bytes." );
570- CHECK_BUILD_BLAS_ATTRIBS (box.BoxStride % 8 == 0 ,
571- " pBoxData[" , i, " ].BoxStride (" , box.BoxStride , " ) must be aligned to 8 bytes." );
579+
580+ const Uint32 BoxStrideAlignment = 8 ;
581+ CHECK_BUILD_BLAS_ATTRIBS (box.BoxStride % BoxStrideAlignment == 0 ,
582+ " pBoxData[" , i, " ].BoxStride (" , box.BoxStride , " ) must be aligned by " , BoxStrideAlignment, " ." );
583+
584+ CHECK_BUILD_BLAS_ATTRIBS (box.BoxOffset % RTProps.BoxBufferAlignment == 0 ,
585+ " pBoxData[" , i, " ].BoxOffset (" , box.BoxOffset , " ) must be aligned by " , RTProps.BoxBufferAlignment ,
586+ " (RayTracingProperties::BoxBufferAlignment)." );
572587
573588 CHECK_BUILD_BLAS_ATTRIBS (box.pBoxBuffer != nullptr , " pBoxData[" , i, " ].pBoxBuffer must not be null." );
574589
575- CHECK_BUILD_BLAS_ATTRIBS ((box.pBoxBuffer ->GetDesc ().BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
590+ const auto & BoxBufDesc = box.pBoxBuffer ->GetDesc ();
591+
592+ CHECK_BUILD_BLAS_ATTRIBS (box.BoxOffset + BoxBufferSize <= BoxBufDesc.uiSizeInBytes ,
593+ " pBoxData[" , i, " ].pBoxBuffer is too small for the specified BoxStride (" , box.BoxStride ,
594+ " ) and BoxCount (" , box.BoxCount , " ): at least" , box.BoxOffset + BoxBufferSize, " bytes are required." );
595+
596+ CHECK_BUILD_BLAS_ATTRIBS ((BoxBufDesc.BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
576597 " pBoxData[" , i, " ].pBoxBuffer was not created with BIND_RAY_TRACING flag." );
577598 }
578599
@@ -581,6 +602,10 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
581602 CHECK_BUILD_BLAS_ATTRIBS (Attribs.ScratchBufferOffset <= ScratchDesc.uiSizeInBytes ,
582603 " ScratchBufferOffset (" , Attribs.ScratchBufferOffset , " ) is greater than the buffer size (" , ScratchDesc.uiSizeInBytes , " )." );
583604
605+ CHECK_BUILD_BLAS_ATTRIBS (Attribs.ScratchBufferOffset % RTProps.ScratchBufferAlignment == 0 ,
606+ " ScratchBufferOffset (" , Attribs.ScratchBufferOffset , " ) must be aligned by " , RTProps.ScratchBufferAlignment ,
607+ " (RayTracingProperties::ScratchBufferAlignment)." );
608+
584609 if (Attribs.Update )
585610 {
586611 CHECK_BUILD_BLAS_ATTRIBS (ScratchDesc.uiSizeInBytes - Attribs.ScratchBufferOffset >= Attribs.pBLAS ->GetScratchBufferSizes ().Update ,
@@ -601,7 +626,7 @@ bool VerifyBuildBLASAttribs(const IRenderDevice* pDevice, const BuildBLASAttribs
601626}
602627
603628
604- bool VerifyBuildTLASAttribs (const BuildTLASAttribs& Attribs)
629+ bool VerifyBuildTLASAttribs (const BuildTLASAttribs& Attribs, const RayTracingProperties& RTProps )
605630{
606631#define CHECK_BUILD_TLAS_ATTRIBS (Expr, ...) CHECK_PARAMETER(Expr, " Build TLAS attribs are invalid: " , __VA_ARGS__)
607632
@@ -673,6 +698,10 @@ bool VerifyBuildTLASAttribs(const BuildTLASAttribs& Attribs)
673698 " pInstanceBuffer size (" , InstDesc.uiSizeInBytes , " ) is too small: at least " ,
674699 InstDataSize + Attribs.InstanceBufferOffset , " bytes are required." );
675700
701+ CHECK_BUILD_TLAS_ATTRIBS (Attribs.InstanceBufferOffset % RTProps.InstanceBufferAlignment == 0 ,
702+ " InstanceBufferOffset (" , Attribs.InstanceBufferOffset , " ) must be aligned by " , RTProps.InstanceBufferAlignment ,
703+ " (RayTracingProperties::InstanceBufferAlignment)." );
704+
676705 CHECK_BUILD_TLAS_ATTRIBS ((InstDesc.BindFlags & BIND_RAY_TRACING) == BIND_RAY_TRACING,
677706 " pInstanceBuffer was not created with BIND_RAY_TRACING flag." );
678707
@@ -681,6 +710,10 @@ bool VerifyBuildTLASAttribs(const BuildTLASAttribs& Attribs)
681710 CHECK_BUILD_TLAS_ATTRIBS (Attribs.ScratchBufferOffset <= ScratchDesc.uiSizeInBytes ,
682711 " ScratchBufferOffset (" , Attribs.ScratchBufferOffset , " ) is greater than the buffer size (" , ScratchDesc.uiSizeInBytes , " )." );
683712
713+ CHECK_BUILD_TLAS_ATTRIBS (Attribs.ScratchBufferOffset % RTProps.ScratchBufferAlignment == 0 ,
714+ " ScratchBufferOffset (" , Attribs.ScratchBufferOffset , " ) must be aligned by " , RTProps.ScratchBufferAlignment ,
715+ " (RayTracingProperties::ScratchBufferAlignment)." );
716+
684717 if (Attribs.Update )
685718 {
686719 CHECK_BUILD_TLAS_ATTRIBS (ScratchDesc.uiSizeInBytes - Attribs.ScratchBufferOffset >= Attribs.pTLAS ->GetScratchBufferSizes ().Update ,
0 commit comments