summaryrefslogtreecommitdiffstats
path: root/Graphics
diff options
context:
space:
mode:
authorazhirnov <zh1dron@gmail.com>2020-11-12 15:23:43 +0000
committerazhirnov <zh1dron@gmail.com>2020-11-12 15:23:43 +0000
commit53572161c4ee39ff7d66b84e4a9f4979da2f8f0b (patch)
tree91b5d2df5003d15321d67d28b0cbe0ece1e0ca6e /Graphics
parentremap resource binding for DirectX 12 (diff)
downloadDiligentCore-53572161c4ee39ff7d66b84e4a9f4979da2f8f0b.tar.gz
DiligentCore-53572161c4ee39ff7d66b84e4a9f4979da2f8f0b.zip
added address alignment checks
Diffstat (limited to 'Graphics')
-rw-r--r--Graphics/GraphicsEngine/src/DeviceContextBase.cpp2
-rw-r--r--Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp8
-rw-r--r--Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp4
3 files changed, 13 insertions, 1 deletions
diff --git a/Graphics/GraphicsEngine/src/DeviceContextBase.cpp b/Graphics/GraphicsEngine/src/DeviceContextBase.cpp
index 9a4f137f..bccd0cc2 100644
--- a/Graphics/GraphicsEngine/src/DeviceContextBase.cpp
+++ b/Graphics/GraphicsEngine/src/DeviceContextBase.cpp
@@ -452,6 +452,8 @@ bool VerifyBuildBLASAttribs(const BuildBLASAttribs& Attribs)
CHECK_BUILD_BLAS_ATTRIBS(box.BoxStride >= BoxSize,
"pBoxData[", i, "].BoxStride (", box.BoxStride, ") must be at least ", BoxSize, " bytes");
+ CHECK_BUILD_BLAS_ATTRIBS(box.BoxStride % 8 == 0,
+ "pBoxData[", i, "].BoxStride (", box.BoxStride, ") must be aligned to 8 bytes");
CHECK_BUILD_BLAS_ATTRIBS(box.pBoxBuffer != nullptr, "pBoxData[", i, "].pBoxBuffer must not be null");
diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
index 8496181a..d5db05e9 100644
--- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
+++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp
@@ -2323,6 +2323,9 @@ void DeviceContextD3D12Impl::BuildBLAS(const BuildBLASAttribs& Attribs)
d3d12Tris.VertexFormat = TypeToRayTracingVertexFormat(TriDesc.VertexValueType, TriDesc.VertexComponentCount);
VERIFY(d3d12Tris.VertexFormat != DXGI_FORMAT_UNKNOWN, "Unsupported combination of vertex value type and component count");
+ VERIFY(d3d12Tris.VertexBuffer.StartAddress % GetValueSize(TriDesc.VertexValueType) == 0, "Vertex start address is not properly aligned");
+ VERIFY(d3d12Tris.VertexBuffer.StrideInBytes % GetValueSize(TriDesc.VertexValueType) == 0, "Vertex stride is not properly aligned");
+
TransitionOrVerifyBufferState(CmdCtx, *pVB, Attribs.GeometryTransitionMode, RESOURCE_STATE_BUILD_AS_READ, OpName);
if (SrcTris.pIndexBuffer)
@@ -2334,6 +2337,8 @@ void DeviceContextD3D12Impl::BuildBLAS(const BuildBLASAttribs& Attribs)
d3d12Tris.IndexBuffer = pIB->GetGPUAddress() + SrcTris.IndexOffset;
d3d12Tris.IndexCount = SrcTris.PrimitiveCount * 3;
+ VERIFY(d3d12Tris.IndexBuffer % GetValueSize(TriDesc.IndexType) == 0, "Index start address is not properly aligned");
+
TransitionOrVerifyBufferState(CmdCtx, *pIB, Attribs.GeometryTransitionMode, RESOURCE_STATE_BUILD_AS_READ, OpName);
}
else
@@ -2347,7 +2352,7 @@ void DeviceContextD3D12Impl::BuildBLAS(const BuildBLASAttribs& Attribs)
auto* const pTB = ValidatedCast<BufferD3D12Impl>(SrcTris.pTransformBuffer);
d3d12Tris.Transform3x4 = pTB->GetGPUAddress() + SrcTris.TransformBufferOffset;
- VERIFY_EXPR(d3d12Tris.Transform3x4 % D3D12_RAYTRACING_TRANSFORM3X4_BYTE_ALIGNMENT == 0);
+ VERIFY(d3d12Tris.Transform3x4 % D3D12_RAYTRACING_TRANSFORM3X4_BYTE_ALIGNMENT == 0, "Transform start address is not properly aligned");
TransitionOrVerifyBufferState(CmdCtx, *pTB, Attribs.GeometryTransitionMode, RESOURCE_STATE_BUILD_AS_READ, OpName);
}
@@ -2386,6 +2391,7 @@ void DeviceContextD3D12Impl::BuildBLAS(const BuildBLASAttribs& Attribs)
d3d12AABs.AABBs.StrideInBytes = SrcBoxes.BoxStride;
DEV_CHECK_ERR(d3d12AABs.AABBs.StartAddress % D3D12_RAYTRACING_AABB_BYTE_ALIGNMENT == 0, "AABB start address is not properly aligned");
+ DEV_CHECK_ERR(d3d12AABs.AABBs.StrideInBytes % D3D12_RAYTRACING_AABB_BYTE_ALIGNMENT == 0, "AABB stride is not properly aligned");
TransitionOrVerifyBufferState(CmdCtx, *pBB, Attribs.GeometryTransitionMode, RESOURCE_STATE_BUILD_AS_READ, OpName);
}
diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
index 0dd00e6c..d7a0ccb5 100644
--- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
+++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp
@@ -2917,6 +2917,8 @@ void DeviceContextVkImpl::BuildBLAS(const BuildBLASAttribs& Attribs)
vkAABBs.stride = SrcBoxes.BoxStride;
vkAABBs.data.deviceAddress = pBB->GetVkDeviceAddress() + SrcBoxes.BoxOffset;
+ VERIFY(vkAABBs.data.deviceAddress % 8 == 0, "AABB start address is not properly aligned");
+
TransitionOrVerifyBufferState(*pBB, Attribs.GeometryTransitionMode, RESOURCE_STATE_BUILD_AS_READ, VK_ACCESS_ACCELERATION_STRUCTURE_READ_BIT_KHR, OpName);
off.firstVertex = 0;
@@ -3036,6 +3038,8 @@ void DeviceContextVkImpl::BuildTLAS(const BuildTLASAttribs& Attribs)
vkASInst.arrayOfPointers = VK_FALSE;
vkASInst.data.deviceAddress = pInstancesVk->GetVkDeviceAddress() + Attribs.InstanceBufferOffset;
+ VERIFY(vkASInst.data.deviceAddress % 16 == 0, "Instance data address is not properly aligned");
+
vkASBuildInfo.sType = VK_STRUCTURE_TYPE_ACCELERATION_STRUCTURE_BUILD_GEOMETRY_INFO_KHR;
vkASBuildInfo.type = VK_ACCELERATION_STRUCTURE_TYPE_TOP_LEVEL_KHR; // type must be compatible with create info
vkASBuildInfo.flags = BuildASFlagsToVkBuildAccelerationStructureFlags(TLASDesc.Flags); // flags must be compatible with create info